From df2134026a1324e28648a024dc7eb3e49b0ed16c Mon Sep 17 00:00:00 2001 From: Andrew Burger Date: Sat, 30 May 2020 12:50:27 -0700 Subject: [PATCH] OAI UE receive dl_config_request and call memcpy additions --- openair2/PHY_INTERFACE/phy_stub_UE.c | 69 +++++++++++++++++++++++++--- openair2/PHY_INTERFACE/phy_stub_UE.h | 3 ++ targets/RT/USER/lte-softmodem.h | 1 + targets/RT/USER/lte-ue.c | 7 +++ targets/RT/USER/lte-uesoftmodem.c | 21 ++------- 5 files changed, 76 insertions(+), 25 deletions(-) diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index cb7f543950..8cd93a0e60 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -1056,25 +1056,80 @@ int ue_init_standalone_socket(const char *addr, int port) int sd = socket(server_address.sin_family, SOCK_STREAM, IPPROTO_SCTP); if (sd < 0) { - LOG_E(MAC, "Socket creation error standalone PNF"); + LOG_E(MAC, "Socket creation error standalone PNF\n"); return -1; } if (inet_pton(server_address.sin_family, addr, &server_address.sin_addr) <= 0) { - LOG_E(MAC, "Invalid standalone PNF Address"); + LOG_E(MAC, "Invalid standalone PNF Address\n"); close(sd); return -1; } - if (connect(sd, (struct sockaddr *)&server_address, addr_len) < 0) { - LOG_E(MAC, "Connection to standalone PNF failed"); - close(sd); - return -1; + while (connect(sd, (struct sockaddr *)&server_address, addr_len) < 0) { + LOG_E(MAC, "Connection to standalone PNF failed: %s\n", strerror(errno)); + sleep(1); } - + LOG_I(MAC, "Succeeded Now\n"); return sd; } +void *ue_standalone_pnf_task(void *context) +{ + const char *standalone_addr = "127.0.0.1"; + int standalone_port = 3289; + char buffer[1024]; + + int sd = ue_init_standalone_socket(standalone_addr, standalone_port); + + while (true) + { + ssize_t len = read(sd, buffer, sizeof(buffer)); + if (len == -1) + { + LOG_E(MAC, "reading from standalone pnf sctp socket failed \n"); + continue; + } + + nfapi_p7_message_header_t header; + if (nfapi_p7_message_header_unpack((void *)buffer, len, &header, sizeof(header), NULL) < 0) + { + LOG_E(MAC, "Header unpack failed for standalone pnf\n"); + continue; + } + + LOG_I(MAC, "Bruins header_t.message_id: %u\n", header.message_id); + + switch (header.message_id) + { + case NFAPI_DL_CONFIG_REQUEST: + { + nfapi_dl_config_request_t dl_config_req; + if (nfapi_p7_message_unpack((void *)buffer, len, &dl_config_req, + sizeof(dl_config_req), NULL) < 0) + { + LOG_E(MAC, "Message dl_config_req failed to unpack\n"); + } + else + { + LOG_I(MAC, "Sending dl_config_req to memcpy function\n"); + memcpy_dl_config_req(NULL, NULL, &dl_config_req); + } + break; + } + case NFAPI_TX_REQUEST: + break; + + case NFAPI_HI_DCI0_REQUEST: + break; + + default: + LOG_E(MAC, "Case Statement has no corresponding nfapi message\n"); + break; + } + } +} + /* Dummy functions*/ void handle_nfapi_hi_dci0_dci_pdu( diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.h b/openair2/PHY_INTERFACE/phy_stub_UE.h index b8a1b56938..0ca39f1123 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.h +++ b/openair2/PHY_INTERFACE/phy_stub_UE.h @@ -134,6 +134,9 @@ void UE_config_stub_pnf(void); // This function is used to open an SCTP socket with a standalone PNF module int ue_init_standalone_socket(const char *addr, int port); +// This function is used to read from standalone pnf socket call corresponding memcpy functions +void *ue_standalone_pnf_task(void *context); + #endif /* PHY_STUB_UE_H_ */ diff --git a/targets/RT/USER/lte-softmodem.h b/targets/RT/USER/lte-softmodem.h index c5fdb5f546..4539004385 100644 --- a/targets/RT/USER/lte-softmodem.h +++ b/targets/RT/USER/lte-softmodem.h @@ -206,6 +206,7 @@ extern int stop_L1L2(module_id_t enb_id); extern int restart_L1L2(module_id_t enb_id); extern void init_UE_stub_single_thread(int nb_inst, int eMBMS_active, int uecap_xer_in, char *emul_iface); +extern void init_UE_standalone_thread(void); extern PHY_VARS_UE *init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms, uint8_t UE_id, uint8_t abstraction_flag); diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c index 35beb9b584..d7f5c48fd5 100644 --- a/targets/RT/USER/lte-ue.c +++ b/targets/RT/USER/lte-ue.c @@ -422,6 +422,13 @@ void init_UE_stub_single_thread(int nb_inst, multicast_link_start(ue_stub_rx_handler,0,emul_iface); } +void init_UE_standalone_thread() +{ + pthread_t thread; + if (pthread_create(&thread, NULL, ue_standalone_pnf_task, NULL) != 0) { + LOG_E(MAC, "pthread_create failed for calling ue_standalone_pnf_task"); + } +} void init_UE_stub(int nb_inst, int eMBMS_active, diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index ee751fe048..e76c810237 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -711,26 +711,11 @@ int main( int argc, char **argv ) { } // hard-coding address and port for now fix later - int sd = -1; + // beggining of test if (NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) { - const char *standalone_addr = "127.0.0.1"; - int standalone_port = 3289; - char buffy[1024]; - - sd = ue_init_standalone_socket(standalone_addr, standalone_port); - ssize_t len = read(sd, buffy, sizeof(buffy)); - if (len == -1) { - printf("reading from standalone pnf sctp socket failed \n"); - return EXIT_FAILURE; - } - - nfapi_p7_message_header_t header_t; - if (nfapi_p7_message_header_unpack((void *)buffy, len, &header_t, sizeof(header_t), NULL) != 0) { - printf("unpacking p7 message failed from standalone pnf\n"); - printf("Bruins header_t.message_id: %u", header_t.message_id); - } + init_UE_standalone_thread(); } - + // end of test printf("ITTI tasks created\n"); mlockall(MCL_CURRENT | MCL_FUTURE); rt_sleep_ns(10*100000000ULL);