LTE and NR NFAPI integration
This commit is contained in:
@@ -38,8 +38,9 @@ typedef struct {
|
||||
|
||||
int pnf_connect(pnf_t *pnf);
|
||||
int pnf_message_pump(pnf_t *pnf);
|
||||
int pnf_nr_message_pump(pnf_t *pnf);
|
||||
|
||||
//int pnf_nr_pack_and_send_p5_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len);
|
||||
int pnf_nr_pack_and_send_p5_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len);
|
||||
int pnf_pack_and_send_p5_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len);
|
||||
int pnf_pack_and_send_p4_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len);
|
||||
int pnf_send_message(pnf_t* pnf, uint8_t* msg, uint32_t msg_len, uint16_t stream_id);
|
||||
|
||||
@@ -146,7 +146,7 @@ typedef struct {
|
||||
} pnf_p7_t;
|
||||
|
||||
int pnf_p7_message_pump(pnf_p7_t* pnf_p7);
|
||||
|
||||
int pnf_nr_p7_message_pump(pnf_p7_t* pnf_p7);
|
||||
int pnf_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_p7_message_header_t* msg, uint32_t msg_len);
|
||||
int pnf_p7_send_message(pnf_p7_t* pnf_p7, uint8_t* msg, uint32_t msg_len);
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ typedef struct nfapi_pnf_config
|
||||
* The client is expected to send the PNF_PARAM.response after receiving the
|
||||
* PNF_PARAM.request. This can be done in the call back.
|
||||
*/
|
||||
//int (*pnf_nr_param_req)(nfapi_pnf_config_t* config, nfapi_nr_pnf_param_request_t* req);
|
||||
int (*pnf_nr_param_req)(nfapi_pnf_config_t* config, nfapi_nr_pnf_param_request_t* req);
|
||||
int (*pnf_param_req)(nfapi_pnf_config_t* config, nfapi_pnf_param_request_t* req);
|
||||
|
||||
/*! A callback for the PNF_CONFIG.request
|
||||
@@ -140,7 +140,8 @@ typedef struct nfapi_pnf_config
|
||||
* PNF_CONFIG.request. This can be done in the call back.
|
||||
*/
|
||||
int (*pnf_config_req)(nfapi_pnf_config_t* config, nfapi_pnf_config_request_t* req);
|
||||
|
||||
int (*pnf_nr_config_req)(nfapi_pnf_config_t* config, nfapi_nr_pnf_config_request_t* req);
|
||||
|
||||
/*! A callback for the PNF_START.request
|
||||
* \param config A pointer to the pnf configuration
|
||||
* \param req A data structure for the decoded PNF_CONFIG.request. This will have
|
||||
@@ -151,7 +152,8 @@ typedef struct nfapi_pnf_config
|
||||
* PNF_START.request. This can be done in the call back.
|
||||
*/
|
||||
int (*pnf_start_req)(nfapi_pnf_config_t* config, nfapi_pnf_start_request_t* req);
|
||||
|
||||
int (*pnf_nr_start_req)(nfapi_pnf_config_t* config, nfapi_nr_pnf_start_request_t* req);
|
||||
|
||||
/*! A callback for the PNF_STOP.request
|
||||
* \param config A pointer to the pnf configuration
|
||||
* \param req A data structure for the decoded PNF_STOP.request. This will have
|
||||
@@ -173,8 +175,9 @@ typedef struct nfapi_pnf_config
|
||||
* The client is expected to send the PARAM.response after receiving the
|
||||
* PARAM.request. This can be done in the call back.
|
||||
*/
|
||||
int (*param_req)(nfapi_pnf_config_t* config, nfapi_pnf_phy_config_t* phy, nfapi_nr_param_request_scf_t* req);
|
||||
|
||||
int (*param_req)(nfapi_pnf_config_t* config, nfapi_pnf_phy_config_t* phy, nfapi_param_request_t* req);
|
||||
int (*nr_param_req)(nfapi_pnf_config_t* config, nfapi_pnf_phy_config_t* phy, nfapi_nr_param_request_scf_t* req);
|
||||
|
||||
/*! A callback for the CONFIG.request
|
||||
* \param config A pointer to the pnf configuration
|
||||
* \param phy A pointer to the pnf phy configuration
|
||||
@@ -185,7 +188,8 @@ typedef struct nfapi_pnf_config
|
||||
* The client is expected to send the CONFIG.response after receiving the
|
||||
* CONFIG.request. This can be done in the call back.
|
||||
*/
|
||||
int (*config_req)(nfapi_pnf_config_t* config, nfapi_pnf_phy_config_t* phy, nfapi_nr_config_request_scf_t* req);
|
||||
int (*config_req)(nfapi_pnf_config_t* config, nfapi_pnf_phy_config_t* phy, nfapi_config_request_t* req);
|
||||
int (*nr_config_req)(nfapi_pnf_config_t* config, nfapi_pnf_phy_config_t* phy, nfapi_nr_config_request_scf_t* req);
|
||||
|
||||
/*! A callback for the START.request
|
||||
* \param config A pointer to the pnf configuration
|
||||
@@ -197,8 +201,8 @@ typedef struct nfapi_pnf_config
|
||||
* The client is expected to send the START.response after the client has received the
|
||||
* first subframe indication from FAPI.
|
||||
*/
|
||||
int (*start_req)(nfapi_pnf_config_t* config, nfapi_pnf_phy_config_t* phy, nfapi_nr_start_request_scf_t* req);
|
||||
|
||||
int (*start_req)(nfapi_pnf_config_t* config, nfapi_pnf_phy_config_t* phy, nfapi_start_request_t* req);
|
||||
int (*nr_start_req)(nfapi_pnf_config_t* config, nfapi_pnf_phy_config_t* phy, nfapi_nr_start_request_scf_t* req);
|
||||
/*! A callback for the STOP.request
|
||||
* \param config A pointer to the pnf configuration
|
||||
* \param phy A pointer to the pnf phy configuration
|
||||
@@ -362,6 +366,7 @@ int nfapi_pnf_config_destroy(nfapi_pnf_config_t* config);
|
||||
* \endcode
|
||||
*/
|
||||
int nfapi_pnf_start(nfapi_pnf_config_t* config);
|
||||
int nfapi_nr_pnf_start(nfapi_pnf_config_t* config);
|
||||
|
||||
/*! Stop the PNF library.
|
||||
* \param config A pointer to the pnf configuration
|
||||
@@ -378,6 +383,8 @@ int nfapi_pnf_stop(nfapi_pnf_config_t* config);
|
||||
*
|
||||
*/
|
||||
int nfapi_pnf_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_pnf_param_response_t* resp);
|
||||
int nfapi_nr_pnf_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_pnf_param_response_t* resp);
|
||||
|
||||
|
||||
/*! Send the PNF_CONFIG.response
|
||||
* \param config A pointer to a pnf configuraiton
|
||||
@@ -386,6 +393,7 @@ int nfapi_pnf_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_pnf_param_respons
|
||||
*
|
||||
*/
|
||||
int nfapi_pnf_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_pnf_config_response_t* resp);
|
||||
int nfapi_nr_pnf_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_nr_pnf_config_response_t* resp);
|
||||
|
||||
/*! Send the PNF_START.response
|
||||
* \param config A pointer to a pnf configuraiton
|
||||
@@ -394,7 +402,7 @@ int nfapi_pnf_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_pnf_config_respo
|
||||
*
|
||||
*/
|
||||
int nfapi_pnf_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_pnf_start_response_t* resp);
|
||||
|
||||
int nfapi_nr_pnf_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_nr_pnf_start_response_t* resp);
|
||||
/*! Send the PNF_STOP.response
|
||||
* \param config A pointer to a pnf configuraiton
|
||||
* \param resp A pointer to the message structure
|
||||
@@ -409,7 +417,8 @@ int nfapi_pnf_pnf_stop_resp(nfapi_pnf_config_t* config, nfapi_pnf_stop_response_
|
||||
* \return 0 for success, -1 for failure
|
||||
*
|
||||
*/
|
||||
int nfapi_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_param_response_scf_t* resp);
|
||||
int nfapi_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_param_response_t* resp);
|
||||
int nfapi_nr_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_param_response_scf_t* resp);
|
||||
|
||||
/*! Send the CONFIG.response
|
||||
* \param config A pointer to a pnf configuraiton
|
||||
@@ -417,15 +426,16 @@ int nfapi_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_param_response_scf
|
||||
* \return 0 for success, -1 for failure
|
||||
*
|
||||
*/
|
||||
int nfapi_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_nr_config_response_scf_t* resp);
|
||||
|
||||
int nfapi_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_config_response_t* resp);
|
||||
int nfapi_nr_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_nr_config_response_scf_t* resp);
|
||||
/*! Send the START.response
|
||||
* \param config A pointer to a pnf configuraiton
|
||||
* \param resp A pointer to the message structure
|
||||
* \return 0 for success, -1 for failure
|
||||
*
|
||||
*/
|
||||
int nfapi_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_nr_start_response_scf_t* resp);
|
||||
int nfapi_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_start_response_t* resp);
|
||||
int nfapi_nr_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_nr_start_response_scf_t* resp);
|
||||
|
||||
/*! Send the STOP.response
|
||||
* \param config A pointer to a pnf configuraiton
|
||||
@@ -738,6 +748,7 @@ int nfapi_pnf_p7_config_destroy(nfapi_pnf_p7_config_t* config);
|
||||
* This function will not return until nfapi_pnf_p7_stop is called.
|
||||
*/
|
||||
int nfapi_pnf_p7_start(nfapi_pnf_p7_config_t* config);
|
||||
int nfapi_nr_pnf_p7_start(nfapi_pnf_p7_config_t* config);
|
||||
|
||||
/*! Stop the PNF P7 library.
|
||||
* \param config A pointer to a PNF P7 config
|
||||
|
||||
+670
-45
@@ -82,7 +82,7 @@ nfapi_pnf_phy_config_t* nfapi_pnf_phy_config_find(nfapi_pnf_config_t* config, ui
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
|
||||
void pnf_nr_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -110,11 +110,11 @@ void pnf_nr_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: PNF not in IDLE state\n", __FUNCTION__);
|
||||
|
||||
nfapi_pnf_param_response_t resp;
|
||||
nfapi_nr_pnf_param_response_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_PNF_PARAM_RESPONSE;
|
||||
resp.header.message_id = NFAPI_NR_PHY_MSG_TYPE_PNF_PARAM_RESPONSE;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_pnf_pnf_param_resp(&pnf->_public, &resp);
|
||||
nfapi_nr_pnf_pnf_param_resp(&pnf->_public, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -126,7 +126,7 @@ void pnf_nr_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
pnf->_public.codec_config.deallocate(req.vendor_extension);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void pnf_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -237,6 +237,72 @@ void pnf_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_nr_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
|
||||
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || pnf == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_pnf_config_request_t req;
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_CONFIG.request received\n");
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config) >= 0)
|
||||
{
|
||||
// ensure correct state
|
||||
if(pnf->_public.state != NFAPI_PNF_RUNNING)
|
||||
{
|
||||
// delete the phy records
|
||||
nfapi_pnf_phy_config_delete_all(&pnf->_public);
|
||||
|
||||
// create the phy records
|
||||
if (req.pnf_phy_rf_config.tl.tag == NFAPI_PNF_PHY_RF_TAG)
|
||||
{
|
||||
int i = 0;
|
||||
for(i = 0; i < req.pnf_phy_rf_config.number_phy_rf_config_info; ++i)
|
||||
{
|
||||
nfapi_pnf_phy_config_t* phy = (nfapi_pnf_phy_config_t*)malloc(sizeof(nfapi_pnf_phy_config_t));
|
||||
memset(phy, 0, sizeof(nfapi_pnf_phy_config_t));
|
||||
|
||||
phy->state = NFAPI_PNF_PHY_IDLE;
|
||||
phy->phy_id = req.pnf_phy_rf_config.phy_rf_config[i].phy_id;
|
||||
|
||||
nfapi_pnf_phy_config_add(&(pnf->_public), phy);
|
||||
}
|
||||
}
|
||||
|
||||
if(pnf->_public.pnf_nr_config_req)
|
||||
{
|
||||
(pnf->_public.pnf_nr_config_req)(&(pnf->_public), &req);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: PNF not in correct state: %d\n", __FUNCTION__, pnf->_public.state);
|
||||
|
||||
nfapi_nr_pnf_config_response_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_PNF_CONFIG_RESPONSE;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_nr_pnf_pnf_config_resp(&(pnf->_public), &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
if(req.vendor_extension)
|
||||
pnf->_public.codec_config.deallocate(req.vendor_extension);
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_handle_pnf_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -279,6 +345,48 @@ void pnf_handle_pnf_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_nr_handle_pnf_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || pnf == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_pnf_start_request_t req;
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_START.request Received\n");
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config) >= 0)
|
||||
{
|
||||
if(pnf->_public.state == NFAPI_PNF_CONFIGURED)
|
||||
{
|
||||
if(pnf->_public.pnf_nr_start_req)
|
||||
{
|
||||
(pnf->_public.pnf_nr_start_req)(&(pnf->_public), &req);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_pnf_start_response_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_PNF_START_RESPONSE;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_nr_pnf_pnf_start_resp(&(pnf->_public), &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
if(req.vendor_extension)
|
||||
pnf->_public.codec_config.deallocate(req.vendor_extension);
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_handle_pnf_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -322,6 +430,49 @@ void pnf_handle_pnf_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_nr_handle_pnf_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || pnf == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_pnf_stop_request_t req;
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_STOP.request Received\n");
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config) >= 0)
|
||||
{
|
||||
if(pnf->_public.state == NFAPI_PNF_RUNNING)
|
||||
{
|
||||
if(pnf->_public.pnf_stop_req)
|
||||
{
|
||||
(pnf->_public.pnf_stop_req)(&(pnf->_public), &req);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_pnf_stop_response_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_PNF_STOP_RESPONSE;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_pnf_pnf_stop_resp(&(pnf->_public), &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
|
||||
if(req.vendor_extension)
|
||||
pnf->_public.codec_config.deallocate(req.vendor_extension);
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -331,7 +482,7 @@ void pnf_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_param_request_scf_t req;
|
||||
nfapi_param_request_t req;
|
||||
|
||||
nfapi_pnf_config_t* config = &(pnf->_public);
|
||||
|
||||
@@ -394,6 +545,78 @@ void pnf_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_nr_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || pnf == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_param_request_scf_t req;
|
||||
|
||||
nfapi_pnf_config_t* config = &(pnf->_public);
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PARAM.request received\n");
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
|
||||
{
|
||||
if(config->state == NFAPI_PNF_RUNNING)
|
||||
{
|
||||
nfapi_pnf_phy_config_t* phy = nfapi_pnf_phy_config_find(config, req.header.phy_id);
|
||||
if(phy)
|
||||
{
|
||||
if(phy->state == NFAPI_PNF_PHY_IDLE)
|
||||
{
|
||||
if(config->nr_param_req)
|
||||
{
|
||||
(config->nr_param_req)(config, phy, &req);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_param_response_scf_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_NR_PHY_MSG_TYPE_PARAM_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_nr_pnf_param_resp(config, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_param_response_scf_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_NR_PHY_MSG_TYPE_PARAM_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_CONFIG;
|
||||
nfapi_nr_pnf_param_resp(config, &resp);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_param_response_scf_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_NR_PHY_MSG_TYPE_PARAM_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_nr_pnf_param_resp(config, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
if(req.vendor_extension)
|
||||
pnf->_public.codec_config.deallocate(req.vendor_extension);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
|
||||
@@ -404,7 +627,7 @@ void pnf_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_config_request_scf_t req;
|
||||
nfapi_config_request_t req;
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "CONFIG.request received\n");
|
||||
|
||||
@@ -416,11 +639,6 @@ void pnf_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
if(config->state == NFAPI_PNF_RUNNING)
|
||||
{
|
||||
nfapi_pnf_phy_config_t* phy = nfapi_pnf_phy_config_find(config, req.header.phy_id);
|
||||
|
||||
#if 0 // emulate set_config TLV reception (hard-code)
|
||||
int tdd_return = set_tdd_config_nr(&req, 1, 7, 6, 2, 4);
|
||||
#endif
|
||||
|
||||
if(phy)
|
||||
{
|
||||
if(phy->state != NFAPI_PNF_PHY_RUNNING)
|
||||
@@ -428,8 +646,6 @@ void pnf_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
if(config->config_req)
|
||||
{
|
||||
(config->config_req)(config, phy, &req);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -472,6 +688,85 @@ void pnf_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void pnf_nr_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || pnf == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_config_request_scf_t req;
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "CONFIG.request received\n");
|
||||
|
||||
nfapi_pnf_config_t* config = &(pnf->_public);
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
|
||||
{
|
||||
if(config->state == NFAPI_PNF_RUNNING)
|
||||
{
|
||||
nfapi_pnf_phy_config_t* phy = nfapi_pnf_phy_config_find(config, req.header.phy_id);
|
||||
|
||||
#if 0 // emulate set_config TLV reception (hard-code)
|
||||
int tdd_return = set_tdd_config_nr(&req, 1, 7, 6, 2, 4);
|
||||
#endif
|
||||
|
||||
if(phy)
|
||||
{
|
||||
if(phy->state != NFAPI_PNF_PHY_RUNNING)
|
||||
{
|
||||
if(config->nr_config_req)
|
||||
{
|
||||
(config->nr_config_req)(config, phy, &req);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_config_response_scf_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_CONFIG_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_nr_pnf_config_resp(config, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_config_response_scf_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_CONFIG_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_CONFIG;
|
||||
nfapi_nr_pnf_config_resp(config, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_config_response_scf_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_CONFIG_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_nr_pnf_config_resp(config, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
if(req.vendor_extension)
|
||||
pnf->_public.codec_config.deallocate(req.vendor_extension);
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_handle_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -481,7 +776,7 @@ void pnf_handle_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_start_request_scf_t req;
|
||||
nfapi_start_request_t req;
|
||||
|
||||
nfapi_pnf_config_t* config = &(pnf->_public);
|
||||
|
||||
@@ -543,6 +838,77 @@ void pnf_handle_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_nr_handle_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || pnf == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_start_request_scf_t req;
|
||||
|
||||
nfapi_pnf_config_t* config = &(pnf->_public);
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() START.request received state:%d\n", __FUNCTION__, config->state);
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
|
||||
{
|
||||
if(config->state == NFAPI_PNF_RUNNING)
|
||||
{
|
||||
nfapi_pnf_phy_config_t* phy = nfapi_pnf_phy_config_find(config, req.header.phy_id);
|
||||
if(phy)
|
||||
{
|
||||
if(phy->state != NFAPI_PNF_PHY_RUNNING)
|
||||
{
|
||||
if(config->nr_start_req)
|
||||
{
|
||||
(config->nr_start_req)(config, phy, &req);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_start_response_scf_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_START_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_nr_pnf_start_resp(config, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_start_response_scf_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_START_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_CONFIG;
|
||||
nfapi_nr_pnf_start_resp(config, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_start_response_scf_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_START_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_nr_pnf_start_resp(config, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
if(req.vendor_extension)
|
||||
pnf->_public.codec_config.deallocate(req.vendor_extension);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_handle_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -614,6 +980,77 @@ void pnf_handle_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_nr_handle_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || pnf == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_nr_stop_request_t req;
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "STOP.request received\n");
|
||||
|
||||
nfapi_pnf_config_t* config = &(pnf->_public);
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
|
||||
{
|
||||
if(config->state == NFAPI_PNF_RUNNING)
|
||||
{
|
||||
nfapi_pnf_phy_config_t* phy = nfapi_pnf_phy_config_find(config, req.header.phy_id);
|
||||
if(phy)
|
||||
{
|
||||
if(phy->state != NFAPI_PNF_PHY_RUNNING)
|
||||
{
|
||||
if(config->stop_req)
|
||||
{
|
||||
(config->stop_req)(config, phy, &req);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_stop_response_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_STOP_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_pnf_stop_resp(config, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_stop_response_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_STOP_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_CONFIG;
|
||||
nfapi_pnf_stop_resp(config, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nfapi_stop_response_t resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
resp.header.message_id = NFAPI_STOP_RESPONSE;
|
||||
resp.header.phy_id = req.header.phy_id;
|
||||
resp.error_code = NFAPI_MSG_INVALID_STATE;
|
||||
nfapi_pnf_stop_resp(config, &resp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
if(req.vendor_extension)
|
||||
pnf->_public.codec_config.deallocate(req.vendor_extension);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_handle_measurement_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -1142,7 +1579,6 @@ void pnf_handle_vendor_extension(void* pRecvMsg, int recvMsgLen, pnf_t* pnf, uin
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void pnf_nr_handle_p5_message(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
nfapi_p4_p5_message_header_t messageHeader;
|
||||
@@ -1167,32 +1603,32 @@ void pnf_nr_handle_p5_message(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
pnf_nr_handle_pnf_param_request(pnf, pRecvMsg, recvMsgLen);
|
||||
break;
|
||||
|
||||
case NFAPI_PNF_CONFIG_REQUEST:
|
||||
pnf_handle_pnf_config_request(pnf, pRecvMsg, recvMsgLen);
|
||||
case NFAPI_NR_PHY_MSG_TYPE_PNF_CONFIG_REQUEST:
|
||||
pnf_nr_handle_pnf_config_request(pnf, pRecvMsg, recvMsgLen);
|
||||
break;
|
||||
|
||||
case NFAPI_PNF_START_REQUEST:
|
||||
pnf_handle_pnf_start_request(pnf, pRecvMsg, recvMsgLen);
|
||||
case NFAPI_NR_PHY_MSG_TYPE_PNF_START_REQUEST:
|
||||
pnf_nr_handle_pnf_start_request(pnf, pRecvMsg, recvMsgLen);
|
||||
break;
|
||||
|
||||
case NFAPI_PNF_STOP_REQUEST:
|
||||
pnf_handle_pnf_stop_request(pnf, pRecvMsg, recvMsgLen);
|
||||
case NFAPI_NR_PHY_MSG_TYPE_PNF_STOP_REQUEST:
|
||||
pnf_nr_handle_pnf_stop_request(pnf, pRecvMsg, recvMsgLen);
|
||||
break;
|
||||
|
||||
case NFAPI_PARAM_REQUEST:
|
||||
pnf_handle_param_request(pnf, pRecvMsg, recvMsgLen);
|
||||
case NFAPI_NR_PHY_MSG_TYPE_PARAM_REQUEST:
|
||||
pnf_nr_handle_param_request(pnf, pRecvMsg, recvMsgLen);
|
||||
break;
|
||||
|
||||
case NFAPI_CONFIG_REQUEST:
|
||||
pnf_handle_config_request(pnf, pRecvMsg, recvMsgLen);
|
||||
case NFAPI_NR_PHY_MSG_TYPE_CONFIG_REQUEST:
|
||||
pnf_nr_handle_config_request(pnf, pRecvMsg, recvMsgLen);
|
||||
break;
|
||||
|
||||
case NFAPI_START_REQUEST:
|
||||
pnf_handle_start_request(pnf, pRecvMsg, recvMsgLen);
|
||||
case NFAPI_NR_PHY_MSG_TYPE_START_REQUEST:
|
||||
pnf_nr_handle_start_request(pnf, pRecvMsg, recvMsgLen);
|
||||
break;
|
||||
|
||||
case NFAPI_STOP_REQUEST:
|
||||
pnf_handle_stop_request(pnf, pRecvMsg, recvMsgLen);
|
||||
case NFAPI_NR_PHY_MSG_TYPE_STOP_REQUEST:
|
||||
pnf_nr_handle_stop_request(pnf, pRecvMsg, recvMsgLen);
|
||||
break;
|
||||
|
||||
case NFAPI_MEASUREMENT_REQUEST:
|
||||
@@ -1238,7 +1674,7 @@ void pnf_nr_handle_p5_message(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void pnf_handle_p5_message(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
{
|
||||
nfapi_p4_p5_message_header_t messageHeader;
|
||||
@@ -1336,21 +1772,21 @@ void pnf_handle_p5_message(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
|
||||
}
|
||||
|
||||
|
||||
// int pnf_nr_pack_and_send_p5_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len)
|
||||
// {
|
||||
// int packed_len = nfapi_nr_p5_message_pack(msg, msg_len,
|
||||
// pnf->tx_message_buffer,
|
||||
// sizeof(pnf->tx_message_buffer),
|
||||
// &pnf->_public.codec_config);
|
||||
int pnf_nr_pack_and_send_p5_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len)
|
||||
{
|
||||
int packed_len = nfapi_nr_p5_message_pack(msg, msg_len,
|
||||
pnf->tx_message_buffer,
|
||||
sizeof(pnf->tx_message_buffer),
|
||||
&pnf->_public.codec_config);
|
||||
|
||||
// if (packed_len < 0)
|
||||
// {
|
||||
// NFAPI_TRACE(NFAPI_TRACE_ERROR, "nfapi_p5_message_pack failed (%d)\n", packed_len);
|
||||
// return -1;
|
||||
// }
|
||||
if (packed_len < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "nfapi_p5_message_pack failed (%d)\n", packed_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// return pnf_send_message(pnf, pnf->tx_message_buffer, packed_len, 0/*msg->stream_id*/);
|
||||
// }
|
||||
return pnf_send_message(pnf, pnf->tx_message_buffer, packed_len, 0/*msg->stream_id*/);
|
||||
}
|
||||
|
||||
|
||||
int pnf_pack_and_send_p5_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len)
|
||||
@@ -1603,7 +2039,6 @@ int pnf_send_message(pnf_t* pnf, uint8_t *msg, uint32_t len, uint16_t stream)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int pnf_read_dispatch_message(pnf_t* pnf)
|
||||
{
|
||||
int socket_connected = 1;
|
||||
@@ -1731,6 +2166,135 @@ int pnf_read_dispatch_message(pnf_t* pnf)
|
||||
return socket_connected;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int pnf_nr_read_dispatch_message(pnf_t* pnf)
|
||||
{
|
||||
int socket_connected = 1;
|
||||
|
||||
// 1. Peek the message header
|
||||
// 2. If the message is larger than the stack buffer then create a dynamic buffer
|
||||
// 3. Read the buffer
|
||||
// 4. Handle the p5 message
|
||||
|
||||
uint32_t header_buffer_size = NFAPI_HEADER_LENGTH;
|
||||
uint8_t header_buffer[header_buffer_size];
|
||||
|
||||
uint32_t stack_buffer_size = 32; //should it be the size of then sctp_notificatoin structure
|
||||
uint8_t stack_buffer[stack_buffer_size];
|
||||
|
||||
uint8_t* dynamic_buffer = 0;
|
||||
|
||||
uint8_t* read_buffer = &stack_buffer[0];
|
||||
uint32_t message_size = 0;
|
||||
|
||||
struct sockaddr_in addr;
|
||||
socklen_t addr_len = sizeof(addr);
|
||||
|
||||
struct sctp_sndrcvinfo sndrcvinfo;
|
||||
(void)memset(&sndrcvinfo, 0, sizeof(struct sctp_sndrcvinfo));
|
||||
|
||||
{
|
||||
int flags = MSG_PEEK;
|
||||
message_size = sctp_recvmsg(pnf->p5_sock, header_buffer, header_buffer_size, /*(struct sockaddr*)&addr, &addr_len*/ 0, 0, &sndrcvinfo, &flags);
|
||||
|
||||
if(message_size == -1)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF Failed to peek sctp message size errno:%d\n", errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
nfapi_p4_p5_message_header_t header;
|
||||
int unpack_result = nfapi_p5_message_header_unpack(header_buffer, header_buffer_size, &header, sizeof(header), 0);
|
||||
if(unpack_result < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF Failed to unpack p5 message header\n");
|
||||
return 0;
|
||||
}
|
||||
message_size = header.message_length;
|
||||
|
||||
// now have the size of the mesage
|
||||
}
|
||||
|
||||
if(message_size > stack_buffer_size)
|
||||
{
|
||||
dynamic_buffer = (uint8_t*)malloc(message_size);
|
||||
|
||||
if(dynamic_buffer == NULL)
|
||||
{
|
||||
// todo : add error mesage
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF Failed to allocate dynamic buffer for sctp_recvmsg size:%d\n", message_size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
read_buffer = dynamic_buffer;
|
||||
}
|
||||
|
||||
{
|
||||
int flags = 0;
|
||||
(void)memset(&sndrcvinfo, 0, sizeof(struct sctp_sndrcvinfo));
|
||||
|
||||
int recvmsg_result = sctp_recvmsg(pnf->p5_sock, read_buffer, message_size, (struct sockaddr*)&addr, &addr_len, &sndrcvinfo, &flags);
|
||||
if(recvmsg_result == -1)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Failed to read sctp message size errno:%d\n", errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
// print the received message
|
||||
printf("\n MESSAGE RECEIVED: \n");
|
||||
for(int i=0; i<message_size; i++){
|
||||
printf("%d", read_buffer[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if (flags & MSG_NOTIFICATION)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Notification received from %s:%u\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
|
||||
|
||||
// todo - handle the events
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Received message fd:%d from %s:%u assoc:%d on stream %d, PPID %d, length %d, flags 0x%x\n",
|
||||
pnf->p5_sock,
|
||||
inet_ntoa(addr.sin_addr),
|
||||
ntohs(addr.sin_port),
|
||||
sndrcvinfo.sinfo_assoc_id,
|
||||
sndrcvinfo.sinfo_stream,
|
||||
ntohl(sndrcvinfo.sinfo_ppid),
|
||||
message_size,
|
||||
flags);
|
||||
*/
|
||||
|
||||
// handle now if complete message in one or more segments
|
||||
if ((flags & 0x80) == 0x80)
|
||||
{
|
||||
pnf_nr_handle_p5_message(pnf, read_buffer, message_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "sctp_recvmsg: unhandled mode with flags 0x%x\n", flags);
|
||||
|
||||
// assume socket disconnected
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "Disconnected socket\n");
|
||||
socket_connected = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(dynamic_buffer)
|
||||
{
|
||||
free(dynamic_buffer);
|
||||
}
|
||||
|
||||
return socket_connected;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1795,3 +2359,64 @@ int pnf_message_pump(pnf_t* pnf)
|
||||
|
||||
}
|
||||
|
||||
int pnf_nr_message_pump(pnf_t* pnf)
|
||||
{
|
||||
uint8_t socketConnected = 1;
|
||||
|
||||
while(socketConnected && pnf->terminate == 0)
|
||||
{
|
||||
fd_set rfds;
|
||||
int selectRetval = 0;
|
||||
|
||||
// select on a timeout and then get the message
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(pnf->p5_sock, &rfds);
|
||||
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
selectRetval = select(pnf->p5_sock+1, &rfds, NULL, NULL, &timeout);
|
||||
|
||||
if(selectRetval == 0)
|
||||
{
|
||||
// timeout
|
||||
continue;
|
||||
}
|
||||
else if (selectRetval == -1 && (errno == EINTR))
|
||||
{
|
||||
// interrupted by signal
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "P5 Signal Interrupt %d\n", errno);
|
||||
continue;
|
||||
}
|
||||
else if (selectRetval == -1)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "P5 select() failed\n");
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(FD_ISSET(pnf->p5_sock, &rfds))
|
||||
{
|
||||
socketConnected = pnf_nr_read_dispatch_message(pnf);
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "Why are we here\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Drop back to idle if we have lost connection
|
||||
pnf->_public.state = NFAPI_PNF_PHY_IDLE;
|
||||
|
||||
|
||||
// close the connection and socket
|
||||
if (close(pnf->p5_sock) < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "close(sctpSock) failed errno: %d\n", errno);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,40 @@ int nfapi_pnf_start(nfapi_pnf_config_t* config)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nfapi_nr_pnf_start(nfapi_pnf_config_t* config)
|
||||
{
|
||||
// Verify that config is not null
|
||||
if(config == 0)
|
||||
return -1;
|
||||
|
||||
// Make sure to set the defined trace function before using NFAPI_TRACE
|
||||
if(config->trace)
|
||||
nfapi_trace_g = config->trace;
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
|
||||
|
||||
pnf_t* _this = (pnf_t*)(config);
|
||||
|
||||
while (_this->terminate == 0)
|
||||
{
|
||||
int connect_result = pnf_connect(_this);
|
||||
|
||||
if(connect_result > 0)
|
||||
{
|
||||
pnf_nr_message_pump(_this);
|
||||
}
|
||||
else if(connect_result < 0)
|
||||
{
|
||||
return connect_result;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() terminate=1 - EXITTING............\n", __FUNCTION__);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nfapi_pnf_stop(nfapi_pnf_config_t* config)
|
||||
{
|
||||
// Verify that config is not null
|
||||
@@ -98,7 +132,7 @@ int nfapi_pnf_stop(nfapi_pnf_config_t* config)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
int nfapi_nr_pnf_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_pnf_param_response_t* resp)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -112,7 +146,7 @@ int nfapi_nr_pnf_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_pnf_param_r
|
||||
|
||||
return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_pnf_param_response_t));
|
||||
}
|
||||
*/
|
||||
|
||||
int nfapi_pnf_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_pnf_param_response_t* resp)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -146,6 +180,27 @@ int nfapi_pnf_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_pnf_config_respo
|
||||
return pnf_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_pnf_config_response_t));
|
||||
}
|
||||
|
||||
|
||||
int nfapi_nr_pnf_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_nr_pnf_config_response_t* resp)
|
||||
{
|
||||
// ensure it's valid
|
||||
if (config == NULL || resp == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(resp->error_code == NFAPI_MSG_OK)
|
||||
{
|
||||
config->state = NFAPI_PNF_CONFIGURED;
|
||||
}
|
||||
|
||||
pnf_t* _this = (pnf_t*)(config);
|
||||
|
||||
return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_pnf_config_response_t));
|
||||
}
|
||||
|
||||
|
||||
int nfapi_pnf_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_pnf_start_response_t* resp)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -165,6 +220,26 @@ int nfapi_pnf_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_pnf_start_respons
|
||||
return pnf_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_pnf_start_response_t));
|
||||
}
|
||||
|
||||
int nfapi_nr_pnf_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_nr_pnf_start_response_t* resp)
|
||||
{
|
||||
// ensure it's valid
|
||||
if (config == NULL || resp == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(resp->error_code == NFAPI_MSG_OK)
|
||||
{
|
||||
config->state = NFAPI_PNF_RUNNING;
|
||||
}
|
||||
|
||||
pnf_t* _this = (pnf_t*)(config);
|
||||
|
||||
return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_pnf_start_response_t));
|
||||
}
|
||||
|
||||
|
||||
int nfapi_pnf_pnf_stop_resp(nfapi_pnf_config_t* config, nfapi_pnf_stop_response_t* resp)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -183,8 +258,7 @@ int nfapi_pnf_pnf_stop_resp(nfapi_pnf_config_t* config, nfapi_pnf_stop_response_
|
||||
|
||||
return pnf_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_pnf_stop_response_t));
|
||||
}
|
||||
|
||||
int nfapi_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_param_response_scf_t* resp)
|
||||
int nfapi_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_param_response_t* resp)
|
||||
{
|
||||
if (config == NULL || resp == NULL)
|
||||
{
|
||||
@@ -194,10 +268,24 @@ int nfapi_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_param_response_scf
|
||||
|
||||
pnf_t* _this = (pnf_t*)(config);
|
||||
|
||||
return pnf_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_param_response_scf_t));
|
||||
return pnf_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_param_response_t));
|
||||
}
|
||||
|
||||
int nfapi_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_nr_config_response_scf_t* resp)
|
||||
|
||||
int nfapi_nr_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_param_response_scf_t* resp)
|
||||
{
|
||||
if (config == NULL || resp == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pnf_t* _this = (pnf_t*)(config);
|
||||
|
||||
return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_param_response_scf_t));
|
||||
}
|
||||
|
||||
int nfapi_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_config_response_t* resp)
|
||||
{
|
||||
if (config == NULL || resp == NULL)
|
||||
{
|
||||
@@ -222,10 +310,39 @@ int nfapi_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_nr_config_response_s
|
||||
return -1;
|
||||
}
|
||||
|
||||
return pnf_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_config_response_scf_t));
|
||||
return pnf_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_config_response_t));
|
||||
}
|
||||
|
||||
int nfapi_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_nr_start_response_scf_t* resp)
|
||||
int nfapi_nr_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_nr_config_response_scf_t* resp)
|
||||
{
|
||||
if (config == NULL || resp == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pnf_t* _this = (pnf_t*)(config);
|
||||
|
||||
nfapi_pnf_phy_config_t* phy = nfapi_pnf_phy_config_find(config, resp->header.phy_id);
|
||||
|
||||
if(phy)
|
||||
{
|
||||
if(resp->error_code == NFAPI_MSG_OK)
|
||||
{
|
||||
phy->state = NFAPI_PNF_PHY_CONFIGURED;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: unknow phy id %d\n", __FUNCTION__, resp->header.phy_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_config_response_scf_t));
|
||||
}
|
||||
|
||||
|
||||
int nfapi_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_start_response_t* resp)
|
||||
{
|
||||
if (config == NULL || resp == NULL)
|
||||
{
|
||||
@@ -249,9 +366,37 @@ int nfapi_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_nr_start_response_scf
|
||||
return -1;
|
||||
}
|
||||
|
||||
return pnf_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_start_response_scf_t));
|
||||
return pnf_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_start_response_t));
|
||||
}
|
||||
|
||||
int nfapi_nr_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_nr_start_response_scf_t* resp)
|
||||
{
|
||||
if (config == NULL || resp == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pnf_t* _this = (pnf_t*)(config);
|
||||
|
||||
nfapi_pnf_phy_config_t* phy = nfapi_pnf_phy_config_find(config, resp->header.phy_id);
|
||||
if(phy)
|
||||
{
|
||||
if(resp->error_code == NFAPI_MSG_OK)
|
||||
{
|
||||
phy->state = NFAPI_PNF_PHY_RUNNING;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: unknown phy id %d\n", __FUNCTION__, resp->header.phy_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_start_response_scf_t));
|
||||
}
|
||||
|
||||
|
||||
int nfapi_pnf_stop_resp(nfapi_pnf_config_t* config, nfapi_stop_response_t* resp)
|
||||
{
|
||||
if (config == NULL || resp == NULL)
|
||||
|
||||
@@ -521,6 +521,30 @@ static uint32_t get_slot_time(uint32_t now_hr, uint32_t slot_start_hr)
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t get_sf_time(uint32_t now_hr, uint32_t sf_start_hr)
|
||||
{
|
||||
if(now_hr < sf_start_hr)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "now is earlier than start of subframe\n");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t now_us = TIMEHR_USEC(now_hr);
|
||||
uint32_t sf_start_us = TIMEHR_USEC(sf_start_hr);
|
||||
|
||||
// if the us have wrapped adjust for it
|
||||
if(now_hr < sf_start_us)
|
||||
{
|
||||
now_us += 1000000;
|
||||
}
|
||||
|
||||
return now_us - sf_start_us;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int pnf_p7_send_message(pnf_p7_t* pnf_p7, uint8_t* msg, uint32_t len)
|
||||
{
|
||||
// todo : consider how to do this only once
|
||||
@@ -645,6 +669,97 @@ int pnf_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_p7_message_header_t*
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int pnf_nr_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_p7_message_header_t* header, uint32_t msg_len)
|
||||
{
|
||||
header->m_segment_sequence = NFAPI_P7_SET_MSS(0, 0, pnf_p7->sequence_number);
|
||||
|
||||
// Need to guard against different threads calling the encode function at the same time
|
||||
if(pthread_mutex_lock(&(pnf_p7->pack_mutex)) != 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to lock mutex\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int len = nfapi_nr_p7_message_pack(header, pnf_p7->tx_message_buffer, sizeof(pnf_p7->tx_message_buffer), &pnf_p7->_public.codec_config);
|
||||
|
||||
if (len < 0)
|
||||
{
|
||||
if(pthread_mutex_unlock(&(pnf_p7->pack_mutex)) != 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to unlock mutex\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "nfapi_p7_message_pack failed with return %d\n", len );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(len > pnf_p7->_public.segment_size)
|
||||
{
|
||||
int msg_body_len = len - NFAPI_P7_HEADER_LENGTH ;
|
||||
int seg_body_len = pnf_p7->_public.segment_size - NFAPI_P7_HEADER_LENGTH ;
|
||||
int segment_count = (msg_body_len / (seg_body_len)) + ((msg_body_len % seg_body_len) ? 1 : 0);
|
||||
|
||||
int segment = 0;
|
||||
int offset = NFAPI_P7_HEADER_LENGTH;
|
||||
uint8_t buffer[pnf_p7->_public.segment_size];
|
||||
for(segment = 0; segment < segment_count; ++segment)
|
||||
{
|
||||
uint8_t last = 0;
|
||||
uint16_t size = pnf_p7->_public.segment_size - NFAPI_P7_HEADER_LENGTH;
|
||||
if(segment + 1 == segment_count)
|
||||
{
|
||||
last = 1;
|
||||
size = (msg_body_len) - (seg_body_len * segment);
|
||||
}
|
||||
|
||||
uint16_t segment_size = size + NFAPI_P7_HEADER_LENGTH;
|
||||
|
||||
// Update the header with the m and segement
|
||||
memcpy(&buffer[0], pnf_p7->tx_message_buffer, NFAPI_P7_HEADER_LENGTH);
|
||||
|
||||
// set the segment length
|
||||
buffer[4] = (segment_size & 0xFF00) >> 8;
|
||||
buffer[5] = (segment_size & 0xFF);
|
||||
|
||||
// set the m & segment number
|
||||
buffer[6] = ((!last) << 7) + segment;
|
||||
|
||||
memcpy(&buffer[NFAPI_P7_HEADER_LENGTH], pnf_p7->tx_message_buffer + offset, size);
|
||||
offset += size;
|
||||
|
||||
if(pnf_p7->_public.checksum_enabled)
|
||||
{
|
||||
nfapi_p7_update_checksum(buffer, segment_size);
|
||||
}
|
||||
|
||||
|
||||
pnf_p7_send_message(pnf_p7, &buffer[0], segment_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pnf_p7->_public.checksum_enabled)
|
||||
{
|
||||
nfapi_p7_update_checksum(pnf_p7->tx_message_buffer, len);
|
||||
}
|
||||
|
||||
// simple case that the message fits in a single segment
|
||||
pnf_p7_send_message(pnf_p7, pnf_p7->tx_message_buffer, len);
|
||||
}
|
||||
|
||||
pnf_p7->sequence_number++;
|
||||
|
||||
if(pthread_mutex_unlock(&(pnf_p7->pack_mutex)) != 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to unlock mutex\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pnf_pack_and_send_timing_info(pnf_p7_t* pnf_p7)
|
||||
{
|
||||
nfapi_timing_info_t timing_info;
|
||||
@@ -652,7 +767,6 @@ void pnf_pack_and_send_timing_info(pnf_p7_t* pnf_p7)
|
||||
timing_info.header.message_id = NFAPI_TIMING_INFO;
|
||||
timing_info.header.phy_id = pnf_p7->_public.phy_id;
|
||||
|
||||
#if 0
|
||||
timing_info.last_sfn_sf = pnf_p7->sfn_sf;
|
||||
timing_info.time_since_last_timing_info = pnf_p7->timing_info_ms_counter;
|
||||
|
||||
@@ -670,7 +784,20 @@ void pnf_pack_and_send_timing_info(pnf_p7_t* pnf_p7)
|
||||
timing_info.tx_request_earliest_arrival = 0;
|
||||
timing_info.ul_config_earliest_arrival = 0;
|
||||
timing_info.hi_dci0_earliest_arrival = 0;
|
||||
#endif
|
||||
|
||||
|
||||
pnf_p7_pack_and_send_p7_message(pnf_p7, &(timing_info.header), sizeof(timing_info));
|
||||
|
||||
pnf_p7->timing_info_ms_counter = 0;
|
||||
}
|
||||
|
||||
|
||||
void pnf_nr_pack_and_send_timing_info(pnf_p7_t* pnf_p7)
|
||||
{
|
||||
nfapi_nr_timing_info_t timing_info;
|
||||
memset(&timing_info, 0, sizeof(timing_info));
|
||||
timing_info.header.message_id = NFAPI_TIMING_INFO;
|
||||
timing_info.header.phy_id = pnf_p7->_public.phy_id;
|
||||
|
||||
timing_info.last_sfn = pnf_p7->sfn;
|
||||
timing_info.last_slot = pnf_p7->slot;
|
||||
@@ -692,7 +819,7 @@ void pnf_pack_and_send_timing_info(pnf_p7_t* pnf_p7)
|
||||
timing_info.ul_dci_earliest_arrival = 0;
|
||||
|
||||
|
||||
pnf_p7_pack_and_send_p7_message(pnf_p7, &(timing_info.header), sizeof(timing_info));
|
||||
pnf_nr_p7_pack_and_send_p7_message(pnf_p7, &(timing_info.header), sizeof(timing_info));
|
||||
|
||||
pnf_p7->timing_info_ms_counter = 0;
|
||||
}
|
||||
@@ -1074,13 +1201,13 @@ int pnf_p7_slot_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn, uint16_t sl
|
||||
// send the periodic timing info if configured
|
||||
if(pnf_p7->_public.timing_info_mode_periodic && (pnf_p7->timing_info_period_counter++) == pnf_p7->_public.timing_info_period)
|
||||
{
|
||||
pnf_pack_and_send_timing_info(pnf_p7);
|
||||
pnf_nr_pack_and_send_timing_info(pnf_p7);
|
||||
|
||||
pnf_p7->timing_info_period_counter = 0;
|
||||
}
|
||||
else if(pnf_p7->_public.timing_info_mode_aperiodic && pnf_p7->timing_info_aperiodic_send)
|
||||
{
|
||||
pnf_pack_and_send_timing_info(pnf_p7);
|
||||
pnf_nr_pack_and_send_timing_info(pnf_p7);
|
||||
|
||||
pnf_p7->timing_info_aperiodic_send = 0;
|
||||
}
|
||||
@@ -1552,7 +1679,7 @@ void pnf_handle_dl_tti_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7)
|
||||
return;
|
||||
}
|
||||
|
||||
int unpack_result = nfapi_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(nfapi_nr_dl_tti_request_t), &(pnf_p7->_public.codec_config));
|
||||
int unpack_result = nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(nfapi_nr_dl_tti_request_t), &(pnf_p7->_public.codec_config));
|
||||
|
||||
if(unpack_result == 0)
|
||||
{
|
||||
@@ -1734,7 +1861,7 @@ void pnf_handle_ul_tti_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7)
|
||||
return;
|
||||
}
|
||||
|
||||
int unpack_result = nfapi_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(nfapi_nr_ul_tti_request_t), &(pnf_p7->_public.codec_config));
|
||||
int unpack_result = nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(nfapi_nr_ul_tti_request_t), &(pnf_p7->_public.codec_config));
|
||||
|
||||
if(unpack_result == 0)
|
||||
{
|
||||
@@ -1880,7 +2007,7 @@ void pnf_handle_ul_dci_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7)
|
||||
return;
|
||||
}
|
||||
|
||||
int unpack_result = nfapi_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(nfapi_nr_ul_dci_request_t), &pnf_p7->_public.codec_config);
|
||||
int unpack_result = nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(nfapi_nr_ul_dci_request_t), &pnf_p7->_public.codec_config);
|
||||
|
||||
if(unpack_result == 0)
|
||||
{
|
||||
@@ -2020,7 +2147,7 @@ void pnf_handle_tx_data_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7
|
||||
return;
|
||||
}
|
||||
|
||||
int unpack_result = nfapi_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(nfapi_nr_tx_data_request_t), &pnf_p7->_public.codec_config);
|
||||
int unpack_result = nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(nfapi_nr_tx_data_request_t), &pnf_p7->_public.codec_config);
|
||||
if(unpack_result == 0)
|
||||
{
|
||||
if(pthread_mutex_lock(&(pnf_p7->mutex)) != 0)
|
||||
@@ -2326,8 +2453,7 @@ void pnf_handle_ue_release_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf
|
||||
deallocate_nfapi_ue_release_request(req, pnf_p7);
|
||||
}
|
||||
}
|
||||
/*
|
||||
#if 0
|
||||
|
||||
uint32_t calculate_t2(uint32_t now_time_hr, uint16_t sfn_sf, uint32_t sf_start_time_hr)
|
||||
{
|
||||
uint32_t sf_time_us = get_sf_time(now_time_hr, sf_start_time_hr);
|
||||
@@ -2350,9 +2476,8 @@ uint32_t calculate_t2(uint32_t now_time_hr, uint16_t sfn_sf, uint32_t sf_start_t
|
||||
|
||||
return t2;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
uint32_t calculate_t2(uint32_t now_time_hr, uint16_t sfn,uint16_t slot, uint32_t slot_start_time_hr)
|
||||
|
||||
uint32_t calculate_nr_t2(uint32_t now_time_hr, uint16_t sfn,uint16_t slot, uint32_t slot_start_time_hr)
|
||||
{
|
||||
uint32_t slot_time_us = get_slot_time(now_time_hr, slot_start_time_hr);
|
||||
uint32_t t2 = (NFAPI_SFNSLOT2DEC(sfn, slot) * 500) + slot_time_us;
|
||||
@@ -2375,7 +2500,18 @@ uint32_t calculate_t2(uint32_t now_time_hr, uint16_t sfn,uint16_t slot, uint32_t
|
||||
return t2;
|
||||
}
|
||||
|
||||
uint32_t calculate_t3(uint16_t sfn, uint16_t slot, uint32_t slot_start_time_hr)
|
||||
uint32_t calculate_t3(uint16_t sfn_sf, uint32_t sf_start_time_hr)
|
||||
{
|
||||
uint32_t now_time_hr = pnf_get_current_time_hr();
|
||||
|
||||
uint32_t sf_time_us = get_sf_time(now_time_hr, sf_start_time_hr);
|
||||
|
||||
uint32_t t3 = (NFAPI_SFNSF2DEC(sfn_sf) * 1000) + sf_time_us;
|
||||
|
||||
return t3;
|
||||
}
|
||||
|
||||
uint32_t calculate_nr_t3(uint16_t sfn, uint16_t slot, uint32_t slot_start_time_hr)
|
||||
{
|
||||
uint32_t now_time_hr = pnf_get_current_time_hr();
|
||||
|
||||
@@ -2387,9 +2523,7 @@ uint32_t calculate_t3(uint16_t sfn, uint16_t slot, uint32_t slot_start_time_hr)
|
||||
}
|
||||
|
||||
void pnf_handle_dl_node_sync(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7, uint32_t rx_hr_time)
|
||||
{
|
||||
//printf("Received DL node sync");
|
||||
|
||||
{
|
||||
nfapi_dl_node_sync_t dl_node_sync;
|
||||
|
||||
//NFAPI_TRACE(NFAPI_TRACE_INFO, "DL_NODE_SYNC Received\n");
|
||||
@@ -2414,11 +2548,11 @@ void pnf_handle_dl_node_sync(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7, u
|
||||
}
|
||||
|
||||
|
||||
if (dl_node_sync.delta_sfn_slot != 0)
|
||||
if (dl_node_sync.delta_sfn_sf != 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Will shift Slot timing by %d on next slot\n", dl_node_sync.delta_sfn_slot);
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Will shift SF timing by %d on next subframe\n", dl_node_sync.delta_sfn_sf);
|
||||
|
||||
pnf_p7->slot_shift = dl_node_sync.delta_sfn_slot;
|
||||
pnf_p7->sfn_sf_shift = dl_node_sync.delta_sfn_sf;
|
||||
}
|
||||
|
||||
nfapi_ul_node_sync_t ul_node_sync;
|
||||
@@ -2426,8 +2560,61 @@ void pnf_handle_dl_node_sync(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7, u
|
||||
ul_node_sync.header.message_id = NFAPI_UL_NODE_SYNC;
|
||||
ul_node_sync.header.phy_id = dl_node_sync.header.phy_id;
|
||||
ul_node_sync.t1 = dl_node_sync.t1;
|
||||
ul_node_sync.t2 = calculate_t2(rx_hr_time, pnf_p7->sfn,pnf_p7->slot, pnf_p7->slot_start_time_hr);
|
||||
ul_node_sync.t3 = calculate_t3(pnf_p7->sfn,pnf_p7->slot, pnf_p7->slot_start_time_hr);
|
||||
ul_node_sync.t2 = calculate_t2(rx_hr_time, pnf_p7->sfn_sf, pnf_p7->sf_start_time_hr);
|
||||
ul_node_sync.t3 = calculate_t3(pnf_p7->sfn_sf, pnf_p7->sf_start_time_hr);
|
||||
|
||||
if(pthread_mutex_unlock(&(pnf_p7->mutex)) != 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to unlock mutex\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pnf_p7_pack_and_send_p7_message(pnf_p7, &(ul_node_sync.header), sizeof(ul_node_sync));
|
||||
}
|
||||
|
||||
|
||||
void pnf_nr_handle_dl_node_sync(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7, uint32_t rx_hr_time)
|
||||
{
|
||||
//printf("Received DL node sync");
|
||||
|
||||
nfapi_nr_dl_node_sync_t dl_node_sync;
|
||||
|
||||
//NFAPI_TRACE(NFAPI_TRACE_INFO, "DL_NODE_SYNC Received\n");
|
||||
|
||||
if (pRecvMsg == NULL || pnf_p7 == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, &dl_node_sync, sizeof(dl_node_sync), &pnf_p7->_public.codec_config) < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
if(pthread_mutex_lock(&(pnf_p7->mutex)) != 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to lock mutex\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (dl_node_sync.delta_sfn_slot != 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Will shift Slot timing by %d on next slot\n", dl_node_sync.delta_sfn_slot);
|
||||
|
||||
pnf_p7->slot_shift = dl_node_sync.delta_sfn_slot;
|
||||
}
|
||||
|
||||
nfapi_nr_ul_node_sync_t ul_node_sync;
|
||||
memset(&ul_node_sync, 0, sizeof(ul_node_sync));
|
||||
ul_node_sync.header.message_id = NFAPI_NR_PHY_MSG_TYPE_UL_NODE_SYNC;
|
||||
ul_node_sync.header.phy_id = dl_node_sync.header.phy_id;
|
||||
ul_node_sync.t1 = dl_node_sync.t1;
|
||||
ul_node_sync.t2 = calculate_nr_t2(rx_hr_time, pnf_p7->sfn,pnf_p7->slot, pnf_p7->slot_start_time_hr);
|
||||
ul_node_sync.t3 = calculate_nr_t3(pnf_p7->sfn,pnf_p7->slot, pnf_p7->slot_start_time_hr);
|
||||
// ul_node_sync.t2 = ul_node_sync.t1 + 10;
|
||||
// ul_node_sync.t3 = ul_node_sync.t2 + 10; // hardcoded - gokul
|
||||
|
||||
@@ -2437,7 +2624,7 @@ void pnf_handle_dl_node_sync(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7, u
|
||||
return;
|
||||
}
|
||||
|
||||
pnf_p7_pack_and_send_p7_message(pnf_p7, &(ul_node_sync.header), sizeof(ul_node_sync));
|
||||
pnf_nr_p7_pack_and_send_p7_message(pnf_p7, &(ul_node_sync.header), sizeof(ul_node_sync));
|
||||
//printf("\nSSent UL Node Sync sfn:%d,slot:%d\n",pnf_p7->sfn,pnf_p7->slot);
|
||||
}
|
||||
|
||||
@@ -2471,6 +2658,76 @@ void pnf_dispatch_p7_message(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7,
|
||||
case NFAPI_DL_NODE_SYNC:
|
||||
pnf_handle_dl_node_sync(pRecvMsg, recvMsgLen, pnf_p7, rx_hr_time);
|
||||
break;
|
||||
case NFAPI_DL_CONFIG_REQUEST:
|
||||
pnf_handle_dl_config_request(pRecvMsg, recvMsgLen, pnf_p7);
|
||||
break;
|
||||
|
||||
case NFAPI_UL_CONFIG_REQUEST:
|
||||
pnf_handle_ul_config_request(pRecvMsg, recvMsgLen, pnf_p7);
|
||||
break;
|
||||
|
||||
case NFAPI_HI_DCI0_REQUEST:
|
||||
pnf_handle_hi_dci0_request(pRecvMsg, recvMsgLen, pnf_p7);
|
||||
break;
|
||||
|
||||
case NFAPI_TX_REQUEST:
|
||||
pnf_handle_tx_request(pRecvMsg, recvMsgLen, pnf_p7);
|
||||
break;
|
||||
|
||||
case NFAPI_LBT_DL_CONFIG_REQUEST:
|
||||
pnf_handle_lbt_dl_config_request(pRecvMsg, recvMsgLen, pnf_p7);
|
||||
break;
|
||||
|
||||
case NFAPI_UE_RELEASE_REQUEST:
|
||||
pnf_handle_ue_release_request(pRecvMsg, recvMsgLen, pnf_p7);
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
if(header.message_id >= NFAPI_VENDOR_EXT_MSG_MIN &&
|
||||
header.message_id <= NFAPI_VENDOR_EXT_MSG_MAX)
|
||||
{
|
||||
pnf_handle_p7_vendor_extension(pRecvMsg, recvMsgLen, pnf_p7, header.message_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s P7 Unknown message ID %d\n", __FUNCTION__, header.message_id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void pnf_nr_dispatch_p7_message(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7, uint32_t rx_hr_time)
|
||||
{
|
||||
nfapi_p7_message_header_t header;
|
||||
|
||||
// validate the input params
|
||||
if(pRecvMsg == NULL || recvMsgLen < 4 || pnf_p7 == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: invalid input params\n", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
// unpack the message header
|
||||
if (nfapi_p7_message_header_unpack(pRecvMsg, recvMsgLen, &header, sizeof(header), &pnf_p7->_public.codec_config) < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unpack message header failed, ignoring\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// ensure the message is sensible
|
||||
if (recvMsgLen < 8 || pRecvMsg == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "Invalid message size: %d, ignoring\n", recvMsgLen);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (header.message_id)
|
||||
{
|
||||
case NFAPI_NR_PHY_MSG_TYPE_DL_NODE_SYNC:
|
||||
pnf_nr_handle_dl_node_sync(pRecvMsg, recvMsgLen, pnf_p7, rx_hr_time);
|
||||
break;
|
||||
|
||||
case NFAPI_NR_PHY_MSG_TYPE_DL_TTI_REQUEST:
|
||||
//printf("\nEntering pnf_handle_dl_tti_request sfn=%d,slot=%d \n",pnf_p7->sfn,pnf_p7->slot);
|
||||
@@ -2631,6 +2888,114 @@ void pnf_handle_p7_message(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7, ui
|
||||
pnf_p7_rx_reassembly_queue_remove_old_msgs(pnf_p7, &(pnf_p7->reassembly_queue), rx_hr_time, 1000);
|
||||
|
||||
}
|
||||
|
||||
void pnf_nr_handle_p7_message(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7, uint32_t rx_hr_time)
|
||||
{
|
||||
nfapi_p7_message_header_t messageHeader;
|
||||
|
||||
// validate the input params
|
||||
if(pRecvMsg == NULL || recvMsgLen < 4 || pnf_p7 == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "pnf_handle_p7_message: invalid input params (%d %d %d)\n", pRecvMsg, recvMsgLen, pnf_p7);
|
||||
return;
|
||||
}
|
||||
|
||||
// unpack the message header
|
||||
if (nfapi_p7_message_header_unpack(pRecvMsg, recvMsgLen, &messageHeader, sizeof(nfapi_p7_message_header_t), &pnf_p7->_public.codec_config) < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unpack message header failed, ignoring\n");
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t m = NFAPI_P7_GET_MORE(messageHeader.m_segment_sequence);
|
||||
uint8_t sequence_num = NFAPI_P7_GET_SEQUENCE(messageHeader.m_segment_sequence);
|
||||
uint8_t segment_num = NFAPI_P7_GET_SEGMENT(messageHeader.m_segment_sequence);
|
||||
|
||||
if(pnf_p7->_public.checksum_enabled)
|
||||
{
|
||||
uint32_t checksum = nfapi_p7_calculate_checksum(pRecvMsg, recvMsgLen);
|
||||
if(checksum != messageHeader.checksum)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Checksum verification failed %d %d\n", checksum, messageHeader.checksum);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(m == 0 && segment_num == 0)
|
||||
{
|
||||
// we have a complete message
|
||||
// ensure the message is sensible
|
||||
if (recvMsgLen < 8 || pRecvMsg == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "Invalid message size: %d, ignoring\n", recvMsgLen);
|
||||
return;
|
||||
}
|
||||
|
||||
pnf_nr_dispatch_p7_message(pRecvMsg, recvMsgLen, pnf_p7, rx_hr_time);
|
||||
}
|
||||
else
|
||||
{
|
||||
pnf_p7_rx_message_t* rx_msg = pnf_p7_rx_reassembly_queue_add_segment(pnf_p7, &(pnf_p7->reassembly_queue), rx_hr_time, sequence_num, segment_num, m, pRecvMsg, recvMsgLen);
|
||||
|
||||
if(rx_msg->num_segments_received == rx_msg->num_segments_expected)
|
||||
{
|
||||
// send the buffer on
|
||||
uint16_t i = 0;
|
||||
uint16_t length = 0;
|
||||
for(i = 0; i < rx_msg->num_segments_expected; ++i)
|
||||
{
|
||||
length += rx_msg->segments[i].length - (i > 0 ? NFAPI_P7_HEADER_LENGTH : 0);
|
||||
}
|
||||
|
||||
if(pnf_p7->reassemby_buffer_size < length)
|
||||
{
|
||||
pnf_p7_free(pnf_p7, pnf_p7->reassemby_buffer);
|
||||
pnf_p7->reassemby_buffer = 0;
|
||||
}
|
||||
|
||||
if(pnf_p7->reassemby_buffer == 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_NOTE, "Resizing PNF_P7 Reassembly buffer %d->%d\n", pnf_p7->reassemby_buffer_size, length);
|
||||
pnf_p7->reassemby_buffer = (uint8_t*)pnf_p7_malloc(pnf_p7, length);
|
||||
|
||||
if(pnf_p7->reassemby_buffer == 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_NOTE, "Failed to allocate PNF_P7 reassemby buffer len:%d\n", length);
|
||||
return;
|
||||
}
|
||||
memset(pnf_p7->reassemby_buffer, 0, length);
|
||||
pnf_p7->reassemby_buffer_size = length;
|
||||
}
|
||||
|
||||
uint16_t offset = 0;
|
||||
for(i = 0; i < rx_msg->num_segments_expected; ++i)
|
||||
{
|
||||
if(i == 0)
|
||||
{
|
||||
memcpy(pnf_p7->reassemby_buffer, rx_msg->segments[i].buffer, rx_msg->segments[i].length);
|
||||
offset += rx_msg->segments[i].length;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(pnf_p7->reassemby_buffer + offset, rx_msg->segments[i].buffer + NFAPI_P7_HEADER_LENGTH, rx_msg->segments[i].length - NFAPI_P7_HEADER_LENGTH);
|
||||
offset += rx_msg->segments[i].length - NFAPI_P7_HEADER_LENGTH;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pnf_nr_dispatch_p7_message(pnf_p7->reassemby_buffer, length, pnf_p7, rx_msg->rx_hr_time);
|
||||
|
||||
|
||||
// delete the structure
|
||||
pnf_p7_rx_reassembly_queue_remove_msg(pnf_p7, &(pnf_p7->reassembly_queue), rx_msg);
|
||||
}
|
||||
}
|
||||
|
||||
pnf_p7_rx_reassembly_queue_remove_old_msgs(pnf_p7, &(pnf_p7->reassembly_queue), rx_hr_time, 1000);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void pnf_nfapi_p7_read_dispatch_message(pnf_p7_t* pnf_p7, uint32_t now_hr_time)
|
||||
{
|
||||
int recvfrom_result = 0;
|
||||
@@ -2694,6 +3059,70 @@ void pnf_nfapi_p7_read_dispatch_message(pnf_p7_t* pnf_p7, uint32_t now_hr_time)
|
||||
while(recvfrom_result > 0);
|
||||
}
|
||||
|
||||
void pnf_nr_nfapi_p7_read_dispatch_message(pnf_p7_t* pnf_p7, uint32_t now_hr_time)
|
||||
{
|
||||
int recvfrom_result = 0;
|
||||
struct sockaddr_in remote_addr;
|
||||
socklen_t remote_addr_size = sizeof(remote_addr);
|
||||
remote_addr.sin_family = 2; // Gokul - hardcoded
|
||||
|
||||
do
|
||||
{
|
||||
// peek the header
|
||||
uint8_t header_buffer[NFAPI_P7_HEADER_LENGTH];
|
||||
recvfrom_result = recvfrom(pnf_p7->p7_sock, header_buffer, NFAPI_P7_HEADER_LENGTH, MSG_DONTWAIT | MSG_PEEK, (struct sockaddr*)&remote_addr, &remote_addr_size);
|
||||
|
||||
if(recvfrom_result > 0)
|
||||
{
|
||||
// get the segment size
|
||||
nfapi_p7_message_header_t header;
|
||||
nfapi_p7_message_header_unpack(header_buffer, NFAPI_P7_HEADER_LENGTH, &header, 34, 0);
|
||||
|
||||
// resize the buffer if we have a large segment
|
||||
if(header.message_length > pnf_p7->rx_message_buffer_size)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_NOTE, "reallocing rx buffer %d\n", header.message_length);
|
||||
pnf_p7->rx_message_buffer = realloc(pnf_p7->rx_message_buffer, header.message_length);
|
||||
pnf_p7->rx_message_buffer_size = header.message_length;
|
||||
}
|
||||
|
||||
// read the segment
|
||||
recvfrom_result = recvfrom(pnf_p7->p7_sock, pnf_p7->rx_message_buffer, header.message_length, MSG_DONTWAIT, (struct sockaddr*)&remote_addr, &remote_addr_size);
|
||||
|
||||
now_hr_time = pnf_get_current_time_hr(); //DJP - moved to here - get closer timestamp???
|
||||
|
||||
if(recvfrom_result > 0)
|
||||
{
|
||||
pnf_nr_handle_p7_message(pnf_p7->rx_message_buffer, recvfrom_result, pnf_p7, now_hr_time);
|
||||
//printf("\npnf_handle_p7_message sfn=%d,slot=%d\n",pnf_p7->sfn,pnf_p7->slot);
|
||||
}
|
||||
}
|
||||
else if(recvfrom_result == 0)
|
||||
{
|
||||
// recv zero length message
|
||||
recvfrom_result = recvfrom(pnf_p7->p7_sock, header_buffer, 0, MSG_DONTWAIT, (struct sockaddr*)&remote_addr, &remote_addr_size);
|
||||
}
|
||||
|
||||
if(recvfrom_result == -1)
|
||||
{
|
||||
if(errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
{
|
||||
// return to the select
|
||||
//NFAPI_TRACE(NFAPI_TRACE_WARN, "%s recvfrom would block :%d\n", __FUNCTION__, errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "%s recvfrom failed errno:%d\n", __FUNCTION__, errno);
|
||||
}
|
||||
}
|
||||
|
||||
// need to update the time as we would only use the value from the
|
||||
// select
|
||||
}
|
||||
while(recvfrom_result > 0);
|
||||
}
|
||||
|
||||
|
||||
int pnf_p7_message_pump(pnf_p7_t* pnf_p7)
|
||||
{
|
||||
|
||||
@@ -2834,3 +3263,144 @@ int pnf_p7_message_pump(pnf_p7_t* pnf_p7)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pnf_nr_p7_message_pump(pnf_p7_t* pnf_p7)
|
||||
{
|
||||
|
||||
// initialize the mutex lock
|
||||
if(pthread_mutex_init(&(pnf_p7->mutex), NULL) != 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "After P7 mutex init: %d\n", errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(pthread_mutex_init(&(pnf_p7->pack_mutex), NULL) != 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "After P7 mutex init: %d\n", errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// create the pnf p7 socket
|
||||
if ((pnf_p7->p7_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "After P7 socket errno: %d\n", errno);
|
||||
return -1;
|
||||
}
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF P7 socket created (%d)...\n", pnf_p7->p7_sock);
|
||||
|
||||
// configure the UDP socket options
|
||||
int reuseaddr_enable = 1;
|
||||
if (setsockopt(pnf_p7->p7_sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr_enable, sizeof(int)) < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "PNF P7 setsockopt (SOL_SOCKET, SO_REUSEADDR) failed errno: %d\n", errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
int reuseport_enable = 1;
|
||||
if (setsockopt(pnf_p7->p7_sock, SOL_SOCKET, SO_REUSEPORT, &reuseport_enable, sizeof(int)) < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "PNF P7 setsockopt (SOL_SOCKET, SO_REUSEPORT) failed errno: %d\n", errno);
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
|
||||
int iptos_value = FAPI2_IP_DSCP << 2;
|
||||
if (setsockopt(pnf_p7->p7_sock, IPPROTO_IP, IP_TOS, &iptos_value, sizeof(iptos_value)) < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "PNF P7 setsockopt (IPPROTO_IP, IP_TOS) failed errno: %d\n", errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct sockaddr_in addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
//addr.sin_port = htons(pnf_p7->_public.local_p7_port); Gokul
|
||||
addr.sin_port = pnf_p7->_public.local_p7_port;
|
||||
|
||||
if(pnf_p7->_public.local_p7_addr == 0)
|
||||
{
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
}
|
||||
else
|
||||
{
|
||||
//addr.sin_addr.s_addr = inet_addr(pnf_p7->_public.local_p7_addr);
|
||||
if(inet_aton(pnf_p7->_public.local_p7_addr, &addr.sin_addr) == -1)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "inet_aton failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF P7 binding %d too %s:%d\n", pnf_p7->p7_sock, inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
|
||||
if (bind(pnf_p7->p7_sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "PNF_P7 bind error fd:%d errno: %d\n", pnf_p7->p7_sock, errno);
|
||||
return -1;
|
||||
}
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF P7 bind succeeded...\n");
|
||||
|
||||
while(pnf_p7->terminate == 0)
|
||||
{
|
||||
fd_set rfds;
|
||||
int selectRetval = 0;
|
||||
|
||||
// select on a timeout and then get the message
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(pnf_p7->p7_sock, &rfds);
|
||||
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
selectRetval = select(pnf_p7->p7_sock+1, &rfds, NULL, NULL, &timeout);
|
||||
|
||||
uint32_t now_hr_time = pnf_get_current_time_hr();
|
||||
|
||||
|
||||
|
||||
|
||||
if(selectRetval == 0)
|
||||
{
|
||||
// timeout
|
||||
continue;
|
||||
}
|
||||
else if (selectRetval == -1 && (errno == EINTR))
|
||||
{
|
||||
// interrupted by signal
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "PNF P7 Signal Interrupt %d\n", errno);
|
||||
continue;
|
||||
}
|
||||
else if (selectRetval == -1)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "PNF P7 select() failed\n");
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(FD_ISSET(pnf_p7->p7_sock, &rfds))
|
||||
|
||||
{
|
||||
pnf_nr_nfapi_p7_read_dispatch_message(pnf_p7, now_hr_time);
|
||||
}
|
||||
}
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "PNF_P7 Terminating..\n");
|
||||
|
||||
// close the connection and socket
|
||||
if (close(pnf_p7->p7_sock) < 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "close failed errno: %d\n", errno);
|
||||
}
|
||||
|
||||
if(pthread_mutex_destroy(&(pnf_p7->pack_mutex)) != 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "mutex destroy failed errno: %d\n", errno);
|
||||
}
|
||||
|
||||
if(pthread_mutex_destroy(&(pnf_p7->mutex)) != 0)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "mutex destroy failed errno: %d\n", errno);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -76,6 +76,26 @@ int nfapi_pnf_p7_start(nfapi_pnf_p7_config_t* config)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nfapi_nr_pnf_p7_start(nfapi_pnf_p7_config_t* config)
|
||||
{
|
||||
// Verify that config is not null
|
||||
if(config == 0)
|
||||
return -1;
|
||||
|
||||
// Make sure to set the defined trace function before using NFAPI_TRACE
|
||||
if(config->trace)
|
||||
nfapi_trace_g = config->trace;
|
||||
|
||||
pnf_p7_t* _this = (pnf_p7_t*)(config);
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
|
||||
|
||||
pnf_nr_p7_message_pump(_this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int nfapi_pnf_p7_stop(nfapi_pnf_p7_config_t* config)
|
||||
{
|
||||
// Verify that config is not null
|
||||
|
||||
Reference in New Issue
Block a user