diff --git a/openair-cn/NAS/EURECOM-NAS/src/UEprocess.c b/openair-cn/NAS/EURECOM-NAS/src/UEprocess.c index 225032c83ab564ed49cc7b9dc8dd94038f184907..dc8c58389929c98a226c22e8ce3217a77ccc905f 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/UEprocess.c +++ b/openair-cn/NAS/EURECOM-NAS/src/UEprocess.c @@ -201,7 +201,7 @@ static void *_nas_user_mngr(void *args) /* User receiving loop */ while (!exit_loop) { - exit_loop = user_api_receive_and_process(fd); + exit_loop = nas_user_receive_and_process(fd); } /* Close the connection to the user application layer */ diff --git a/openair-cn/NAS/EURECOM-NAS/src/api/user/user_api.c b/openair-cn/NAS/EURECOM-NAS/src/api/user/user_api.c index 78f7910f1bba8417363ca7cf553c1f3fb54ae9e4..8618d25824d58c31034bb33063369a50dce07336 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/api/user/user_api.c +++ b/openair-cn/NAS/EURECOM-NAS/src/api/user/user_api.c @@ -209,90 +209,6 @@ int user_api_initialize(const char* host, const char* port, LOG_FUNC_RETURN (RETURNok); } -/**************************************************************************** - ** ** - ** Name: user_api_receive_and_process() ** - ** ** - ** Description: Receives and process messages from user application ** - ** ** - ** Inputs: fd: File descriptor of the connection endpoint ** - ** from which data have been received ** - ** Others: None ** - ** ** - ** Outputs: Return: FALSE, TRUE ** - ** ** - ***************************************************************************/ -int user_api_receive_and_process(int * fd) -{ - LOG_FUNC_IN; - - int ret_code; - int nb_command; - int bytes; - int i; - - /* Read the user data message */ - bytes = user_api_read_data (*fd); - if (bytes == RETURNerror) { - /* Failed to read data from the user application layer; - * exit from the receiving loop */ - LOG_TRACE (ERROR, "UE-MAIN - " - "Failed to read data from the user application layer"); - LOG_FUNC_RETURN(TRUE); - } - - if (bytes == 0) { - /* A signal was caught before any data were available */ - LOG_FUNC_RETURN(FALSE); - } - - /* Decode the user data message */ - nb_command = user_api_decode_data (bytes); - for (i = 0; i < nb_command; i++) { - /* Get the user data to be processed */ - const void *data = user_api_get_data (i); - if (data == NULL) { - /* Failed to get user data at the given index; - * go ahead and process the next user data */ - LOG_TRACE (ERROR, "UE-MAIN - " - "Failed to get user data at index %d", - i); - continue; - } - - /* Process the user data message */ - ret_code = nas_user_process_data (data); - if (ret_code != RETURNok) { - /* The user data message has not been successfully - * processed; cause code will be encoded and sent back - * to the user */ - LOG_TRACE - (WARNING, "UE-MAIN - " - "The user procedure call failed"); - } - - /* Encode the user data message */ - bytes = user_api_encode_data (nas_user_get_data (), i == nb_command - 1); - if (bytes == RETURNerror) { - /* Failed to encode the user data message; - * go ahead and process the next user data */ - continue; - } - - /* Send the data message to the user */ - bytes = user_api_send_data (*fd, bytes); - if (bytes == RETURNerror) { - /* Failed to send data to the user application layer; - * exit from the receiving loop */ - LOG_TRACE (ERROR, "UE-MAIN - " - "Failed to send data to the user application layer"); - LOG_FUNC_RETURN(TRUE); - } - } - - LOG_FUNC_RETURN(FALSE); -} - /**************************************************************************** ** ** ** Name: user_api_get_fd() ** diff --git a/openair-cn/NAS/EURECOM-NAS/src/api/user/user_api.h b/openair-cn/NAS/EURECOM-NAS/src/api/user/user_api.h index 686430a5be2f4247d09baa8ce65daf53b81596a9..b1d83cc043a22fd4385f7f08597938073056e779 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/api/user/user_api.h +++ b/openair-cn/NAS/EURECOM-NAS/src/api/user/user_api.h @@ -42,8 +42,6 @@ Description Implements the API used by the NAS layer running in the UE int user_api_initialize(const char* host, const char* port, const char* devname, const char* devparams); -int user_api_receive_and_process(int * fd); - int user_api_emm_callback(Stat_t stat, tac_t tac, ci_t ci, AcT_t AcT, const char* data, size_t size); int user_api_esm_callback(int cid, network_pdn_state_t state); diff --git a/openair-cn/NAS/EURECOM-NAS/src/nas_user.c b/openair-cn/NAS/EURECOM-NAS/src/nas_user.c index 642f5b58b6573d05c65ee9eb3f7a7dfeb323b073..65eaf4430c2b40224f591c812ab7c8f4b5818536 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/nas_user.c +++ b/openair-cn/NAS/EURECOM-NAS/src/nas_user.c @@ -30,6 +30,7 @@ Description NAS procedure functions triggered by the user #include "at_error.h" #include "user_indication.h" #include "nas_proc.h" +#include "user_api.h" #include <string.h> // memset, strncpy, strncmp #include <stdlib.h> // free @@ -198,6 +199,90 @@ void nas_user_initialize(emm_indication_callback_t emm_cb, LOG_FUNC_OUT; } +/**************************************************************************** + ** ** + ** Name: nas_user_receive_and_process() ** + ** ** + ** Description: Receives and process messages from user application ** + ** ** + ** Inputs: fd: File descriptor of the connection endpoint ** + ** from which data have been received ** + ** Others: None ** + ** ** + ** Outputs: Return: FALSE, TRUE ** + ** ** + ***************************************************************************/ +int nas_user_receive_and_process(int * fd) +{ + LOG_FUNC_IN; + + int ret_code; + int nb_command; + int bytes; + int i; + + /* Read the user data message */ + bytes = user_api_read_data (*fd); + if (bytes == RETURNerror) { + /* Failed to read data from the user application layer; + * exit from the receiving loop */ + LOG_TRACE (ERROR, "UE-MAIN - " + "Failed to read data from the user application layer"); + LOG_FUNC_RETURN(TRUE); + } + + if (bytes == 0) { + /* A signal was caught before any data were available */ + LOG_FUNC_RETURN(FALSE); + } + + /* Decode the user data message */ + nb_command = user_api_decode_data (bytes); + for (i = 0; i < nb_command; i++) { + /* Get the user data to be processed */ + const void *data = user_api_get_data (i); + if (data == NULL) { + /* Failed to get user data at the given index; + * go ahead and process the next user data */ + LOG_TRACE (ERROR, "UE-MAIN - " + "Failed to get user data at index %d", + i); + continue; + } + + /* Process the user data message */ + ret_code = nas_user_process_data (data); + if (ret_code != RETURNok) { + /* The user data message has not been successfully + * processed; cause code will be encoded and sent back + * to the user */ + LOG_TRACE + (WARNING, "UE-MAIN - " + "The user procedure call failed"); + } + + /* Encode the user data message */ + bytes = user_api_encode_data (nas_user_get_data (), i == nb_command - 1); + if (bytes == RETURNerror) { + /* Failed to encode the user data message; + * go ahead and process the next user data */ + continue; + } + + /* Send the data message to the user */ + bytes = user_api_send_data (*fd, bytes); + if (bytes == RETURNerror) { + /* Failed to send data to the user application layer; + * exit from the receiving loop */ + LOG_TRACE (ERROR, "UE-MAIN - " + "Failed to send data to the user application layer"); + LOG_FUNC_RETURN(TRUE); + } + } + + LOG_FUNC_RETURN(FALSE); +} + /**************************************************************************** ** ** ** Name: nas_user_process_data() ** diff --git a/openair-cn/NAS/EURECOM-NAS/src/nas_user.h b/openair-cn/NAS/EURECOM-NAS/src/nas_user.h index 1249eeee914d8dc328da5aab8b2ec506377e12f1..ded7156423fa17770d9a839bbdcc884ba6ab9b07 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/nas_user.h +++ b/openair-cn/NAS/EURECOM-NAS/src/nas_user.h @@ -40,6 +40,8 @@ Description NAS procedure functions triggered by the user void nas_user_initialize(emm_indication_callback_t emm_cb, esm_indication_callback_t esm_cb, const char *version); +int nas_user_receive_and_process(int * fd); + int nas_user_process_data(const void *data); const void *nas_user_get_data(void); diff --git a/openair-cn/NAS/nas_ue_task.c b/openair-cn/NAS/nas_ue_task.c index 44c544c432688ef962af625ae1cf8709e26de4b4..a5fa023b8bc97f21e312942d5dfddc9d0ecb6ce6 100644 --- a/openair-cn/NAS/nas_ue_task.c +++ b/openair-cn/NAS/nas_ue_task.c @@ -55,7 +55,7 @@ static int nas_ue_process_events(struct epoll_event *events, int nb_events, unsi { /* If the event has not been yet been processed (not an itti message) */ if (events[event].data.fd == user_fd) { - exit_loop = user_api_receive_and_process(&user_fd); + exit_loop = nas_user_process_data(&user_fd); } else { LOG_E(NAS, "[UE %d] Received an event from an unknown fd %d!\n", Mod_id, events[event].data.fd); }