diff --git a/openair3/NAS/UE/API/USER/user_api.c b/openair3/NAS/UE/API/USER/user_api.c index c71b59b4439d1c235c9b9ba7edf64ed95801a060..21e4eacf9d866ddba429f1cfef7e12c118f154ba 100644 --- a/openair3/NAS/UE/API/USER/user_api.c +++ b/openair3/NAS/UE/API/USER/user_api.c @@ -75,20 +75,6 @@ static int _user_api_pdn_connection_handler(user_api_id_t *user_api_id, unsigned static int _user_api_send(user_api_id_t *user_api_id, at_response_t* data); -/* - * The buffer used to receive data from the user application layer - */ -#define USER_API_RECV_BUFFER_SIZE 4096 -// FIXME not reentrant -static char _user_api_recv_buffer[USER_API_RECV_BUFFER_SIZE]; - -/* - * The buffer used to send data to the user application layer - */ -#define USER_API_SEND_BUFFER_SIZE USER_API_RECV_BUFFER_SIZE -// FIXME not reentrant -static char _user_api_send_buffer[USER_API_SEND_BUFFER_SIZE]; - /****************************************************************************/ /****************** E X P O R T E D F U N C T I O N S ******************/ /****************************************************************************/ @@ -115,7 +101,7 @@ int user_api_initialize(user_api_id_t *user_api_id, const char* host, const char { LOG_FUNC_IN; - gethostname(_user_api_send_buffer, USER_API_SEND_BUFFER_SIZE); + gethostname(user_api_id->send_buffer, USER_API_SEND_BUFFER_SIZE); if (devname != NULL) { /* Initialize device handlers */ @@ -135,7 +121,7 @@ int user_api_initialize(user_api_id_t *user_api_id, const char* host, const char } LOG_TRACE(INFO, "USR-API - User's communication device %d is OPENED " - "on %s/%s", user_api_get_fd(user_api_id), _user_api_send_buffer, devname); + "on %s/%s", user_api_get_fd(user_api_id), user_api_id->send_buffer, devname); } else { /* Initialize network socket handlers */ user_api_id->open = socket_udp_open; @@ -156,7 +142,7 @@ int user_api_initialize(user_api_id_t *user_api_id, const char* host, const char } LOG_TRACE(INFO, "USR-API - User's UDP socket %d is BOUND to %s/%s", - user_api_get_fd(user_api_id), _user_api_send_buffer, port); + user_api_get_fd(user_api_id), user_api_id->send_buffer, port); } /* Register the asynchronous notification handlers */ @@ -245,7 +231,7 @@ const void* user_api_get_data(user_at_commands_t *commands, int index) ** ** ** Outputs: Return: The number of bytes read when success; ** ** RETURNerror Otherwise ** - ** Others: _user_api_recv_buffer, _user_api_id ** + ** Others: user_api_id->recv_buffer, _user_api_id ** ** ** ***************************************************************************/ int user_api_read_data(user_api_id_t *user_api_id, int fd) @@ -262,10 +248,10 @@ int user_api_read_data(user_api_id_t *user_api_id, int fd) LOG_FUNC_RETURN (RETURNerror); } - memset(_user_api_recv_buffer, 0, USER_API_RECV_BUFFER_SIZE); + memset(user_api_id->recv_buffer, 0, USER_API_RECV_BUFFER_SIZE); /* Receive data from the user application layer */ - rbytes = user_api_id->recv(user_api_id->endpoint, _user_api_recv_buffer, USER_API_RECV_BUFFER_SIZE); + rbytes = user_api_id->recv(user_api_id->endpoint, user_api_id->recv_buffer, USER_API_RECV_BUFFER_SIZE); if (rbytes == RETURNerror) { LOG_TRACE(ERROR, "USR-API - recv() failed, %s", strerror(errno)); @@ -275,7 +261,7 @@ int user_api_read_data(user_api_id_t *user_api_id, int fd) } else { LOG_TRACE(INFO, "USR-API - %d bytes received " "from the user application layer", rbytes); - LOG_DUMP(_user_api_recv_buffer, rbytes); + LOG_DUMP(user_api_id->recv_buffer, rbytes); } LOG_FUNC_RETURN (rbytes); @@ -291,22 +277,22 @@ int user_api_read_data(user_api_id_t *user_api_id, int fd) ** ** ** Outputs: Return: The number of bytes write when success; ** ** RETURNerror Otherwise ** - ** Others: _user_api_recv_buffer ** + ** Others: user_api_id->recv_buffer ** ** ** ***************************************************************************/ -int user_api_set_data(char *message) +int user_api_set_data(user_api_id_t *user_api_id, char *message) { LOG_FUNC_IN; int rbytes; - memset(_user_api_recv_buffer, 0, USER_API_RECV_BUFFER_SIZE); + memset(user_api_id->recv_buffer, 0, USER_API_RECV_BUFFER_SIZE); - strncpy(_user_api_recv_buffer, message, USER_API_RECV_BUFFER_SIZE); - rbytes = strlen(_user_api_recv_buffer); + strncpy(user_api_id->recv_buffer, message, USER_API_RECV_BUFFER_SIZE); + rbytes = strlen(user_api_id->recv_buffer); LOG_TRACE(INFO, "USR-API - %d bytes write", rbytes); - LOG_DUMP(_user_api_recv_buffer, rbytes); + LOG_DUMP(user_api_id->recv_buffer, rbytes); LOG_FUNC_RETURN (rbytes); } @@ -320,7 +306,6 @@ int user_api_set_data(char *message) ** Inputs: fd: File descriptor of the connection endpoint ** ** to which data have to be sent ** ** length: Number of bytes to send ** - ** Others: _user_api_send_buffer, _user_api_id ** ** ** ** Outputs: Return: The number of bytes sent when success; ** ** RETURNerror Otherwise ** @@ -329,7 +314,7 @@ int user_api_set_data(char *message) ***************************************************************************/ static int _user_api_send_data(user_api_id_t *user_api_id, int length) { - int sbytes = user_api_id->send(user_api_id->endpoint, _user_api_send_buffer, length); + int sbytes = user_api_id->send(user_api_id->endpoint, user_api_id->send_buffer, length); if (sbytes == RETURNerror) { LOG_TRACE(ERROR, "USR-API - send() failed, %s", strerror(errno)); @@ -339,7 +324,7 @@ static int _user_api_send_data(user_api_id_t *user_api_id, int length) } else { LOG_TRACE(INFO, "USR-API - %d bytes sent " "to the user application layer", sbytes); - LOG_DUMP(_user_api_send_buffer, sbytes); + LOG_DUMP(user_api_id->send_buffer, sbytes); } return sbytes; @@ -379,7 +364,6 @@ int user_api_send_data(user_api_id_t *user_api_id, int fd, int length) ** Others: None ** ** ** ** Outputs: Return: None ** - ** Others: _user_api_id ** ** ** ***************************************************************************/ void user_api_close(user_api_id_t *user_api_id, int fd) @@ -412,11 +396,9 @@ void user_api_close(user_api_id_t *user_api_id, int fd) ** layer when the AT command failed to be decoded. ** ** ** ** Inputs: length: Number of bytes to decode ** - ** Others: _user_api_recv_buffer ** ** ** ** Outputs: Return: The number of AT commands succeessfully ** ** decoded ** - ** Others: _user_api_send_buffer, _user_data ** ** ** ***************************************************************************/ int user_api_decode_data(user_api_id_t *user_api_id, user_at_commands_t *commands, int length) @@ -424,8 +406,8 @@ int user_api_decode_data(user_api_id_t *user_api_id, user_at_commands_t *command LOG_FUNC_IN; /* Parse the AT command line */ - LOG_TRACE(INFO, "USR-API - Decode user data: %s", _user_api_recv_buffer); - commands->n_cmd = at_command_decode(_user_api_recv_buffer, length, + LOG_TRACE(INFO, "USR-API - Decode user data: %s", user_api_id->recv_buffer); + commands->n_cmd = at_command_decode(user_api_id->recv_buffer, length, commands->cmd); if (commands->n_cmd > 0) { @@ -441,10 +423,10 @@ int user_api_decode_data(user_api_id_t *user_api_id, user_at_commands_t *command /* Failed to decode AT command data received from the user * application layer; Return syntax error code message */ LOG_TRACE(ERROR, "USR-API - Syntax error: Failed to decode " - "AT command data %s", _user_api_recv_buffer); + "AT command data %s", user_api_id->recv_buffer); /* Encode the syntax error code message */ - bytes = at_error_encode(_user_api_send_buffer, AT_ERROR_SYNTAX, + bytes = at_error_encode(user_api_id->send_buffer, AT_ERROR_SYNTAX, AT_ERROR_OPERATION_NOT_SUPPORTED); // FIXME move _user_data call @@ -471,10 +453,9 @@ int user_api_decode_data(user_api_id_t *user_api_id, user_at_commands_t *command ** Outputs: Return: The number of characters that have been ** ** successfully encoded; ** ** RETURNerror otherwise. ** - ** Others: _user_api_send_buffer ** ** ** ***************************************************************************/ -int user_api_encode_data(const void* data, int success_code) +int user_api_encode_data(user_api_id_t *user_api_id, const void* data, int success_code) { LOG_FUNC_IN; @@ -483,16 +464,16 @@ int user_api_encode_data(const void* data, int success_code) /* Encode AT command error message */ if (user_data->cause_code != AT_ERROR_SUCCESS) { - bytes = at_error_encode(_user_api_send_buffer, AT_ERROR_CME, + bytes = at_error_encode(user_api_id->send_buffer, AT_ERROR_CME, user_data->cause_code); } /* Encode AT command response message */ else { - bytes = at_response_encode(_user_api_send_buffer, user_data); + bytes = at_response_encode(user_api_id->send_buffer, user_data); /* Add success result code */ if ( (success_code) && (bytes != RETURNerror) ) { - bytes += at_error_encode(&_user_api_send_buffer[bytes], + bytes += at_error_encode(&user_api_id->send_buffer[bytes], AT_ERROR_OK, 0); } } @@ -613,7 +594,6 @@ int user_api_esm_callback(user_api_id_t *user_api_id, int cid, network_pdn_state ** Description: Encodes and sends data to the user application layer ** ** ** ** Inputs: data: The data to send ** - ** Others: _user_api_send_buffer, _user_api_id ** ** ** ** Outputs: Return: The number of bytes sent when success; ** ** RETURNerror Otherwise ** @@ -625,7 +605,7 @@ static int _user_api_send(user_api_id_t *user_api_id, at_response_t* data) LOG_FUNC_IN; /* Encode AT command response message */ - int bytes = at_response_encode(_user_api_send_buffer, data); + int bytes = at_response_encode(user_api_id->send_buffer, data); /* Send the AT command response message to the user application */ if (bytes != RETURNerror) { diff --git a/openair3/NAS/UE/API/USER/user_api.h b/openair3/NAS/UE/API/USER/user_api.h index 06e489b2bfb781df747871737f038b9a5a7dadf9..513a44e4fb05822f55eb1a434a1a2ed4e07459ec 100644 --- a/openair3/NAS/UE/API/USER/user_api.h +++ b/openair3/NAS/UE/API/USER/user_api.h @@ -67,11 +67,11 @@ int user_api_get_fd(user_api_id_t *user_api_id); const void* user_api_get_data(user_at_commands_t *commands, int index); int user_api_read_data(user_api_id_t *user_api_id, int fd); -int user_api_set_data(char *message); +int user_api_set_data(user_api_id_t *user_api_id, char *message); int user_api_send_data(user_api_id_t *user_api_id, int fd, int length); void user_api_close(user_api_id_t *user_api_id, int fd); int user_api_decode_data(user_api_id_t *user_api_id, user_at_commands_t *commands, int length); -int user_api_encode_data(const void* data, int add_success_code); +int user_api_encode_data(user_api_id_t *user_api_id, const void* data, int add_success_code); #endif /* __USER_API_H__ */ diff --git a/openair3/NAS/UE/API/USER/user_api_defs.h b/openair3/NAS/UE/API/USER/user_api_defs.h index 9c43bf36f39f54f946a4c21b85c56d2bcb136e8a..ef4d8cd383b93d49fad48011d87ac1531886578d 100644 --- a/openair3/NAS/UE/API/USER/user_api_defs.h +++ b/openair3/NAS/UE/API/USER/user_api_defs.h @@ -8,12 +8,15 @@ /************************ G L O B A L T Y P E S ************************/ /****************************************************************************/ +#define USER_API_RECV_BUFFER_SIZE 4096 +#define USER_API_SEND_BUFFER_SIZE USER_API_RECV_BUFFER_SIZE +#define USER_DATA_MAX 10 + /* * The decoded data received from the user application layer */ typedef struct { int n_cmd; /* number of user data to be processed */ -#define USER_DATA_MAX 10 at_command_t cmd[USER_DATA_MAX]; /* user data to be processed */ } user_at_commands_t; @@ -39,6 +42,8 @@ typedef struct { ssize_t (*recv) (void*, char*, size_t); ssize_t (*send) (const void*, const char*, size_t); void (*close)(void*); + char recv_buffer[USER_API_RECV_BUFFER_SIZE]; + char send_buffer[USER_API_SEND_BUFFER_SIZE]; } user_api_id_t; diff --git a/openair3/NAS/UE/nas_user.c b/openair3/NAS/UE/nas_user.c index da55b3bbf1591e613deada31580f026713691033..065bbca17d592c38290f0c731c4818e5d9f2dd29 100644 --- a/openair3/NAS/UE/nas_user.c +++ b/openair3/NAS/UE/nas_user.c @@ -220,7 +220,7 @@ int nas_user_receive_and_process(nas_user_t *user, char *message) if (message != NULL) { /* Set the message in receive buffer (Use to simulate reception of data from UserProcess) */ - bytes = user_api_set_data(message); + bytes = user_api_set_data(user_api_id, message); } else { /* Read the user data message */ bytes = user_api_read_data (user_api_id, user->fd); @@ -270,7 +270,7 @@ int nas_user_receive_and_process(nas_user_t *user, char *message) /* Send response to UserProcess (If not in simulated reception) */ if (message == NULL) { /* Encode the user data message */ - bytes = user_api_encode_data (nas_user_get_data (user), i == nb_command - 1); + bytes = user_api_encode_data (user->user_api_id, nas_user_get_data (user), i == nb_command - 1); if (bytes == RETURNerror) { /* Failed to encode the user data message;