UE/API/USER: remove fd from nas_user_t

This commit is contained in:
Frédéric Leroy
2017-01-25 13:24:30 +01:00
parent 38d7adc7e3
commit 64e296ed67
6 changed files with 25 additions and 54 deletions
+8 -35
View File
@@ -225,8 +225,6 @@ const void* user_api_get_data(user_at_commands_t *commands, int index)
** **
** Description: Read data received from the user application layer **
** **
** Inputs: fd: File descriptor of the connection endpoint **
** from which data have been received **
** Others: _user_api_id **
** **
** Outputs: Return: The number of bytes read when success; **
@@ -234,20 +232,12 @@ const void* user_api_get_data(user_at_commands_t *commands, int index)
** Others: user_api_id->recv_buffer, _user_api_id **
** **
***************************************************************************/
int user_api_read_data(user_api_id_t *user_api_id, int fd)
int user_api_read_data(user_api_id_t *user_api_id)
{
LOG_FUNC_IN;
int rbytes;
/* Sanity check */
int sfd = user_api_get_fd(user_api_id);
if (fd != sfd) {
LOG_TRACE(ERROR, "USR-API - Endpoint %d is not the one created for communication with the user application layer (%d)", fd, sfd);
LOG_FUNC_RETURN (RETURNerror);
}
memset(user_api_id->recv_buffer, 0, USER_API_RECV_BUFFER_SIZE);
/* Receive data from the user application layer */
@@ -303,8 +293,6 @@ int user_api_set_data(user_api_id_t *user_api_id, char *message)
** **
** Description: Send data to the user application layer **
** **
** Inputs: fd: File descriptor of the connection endpoint **
** to which data have to be sent **
** length: Number of bytes to send **
** **
** Outputs: Return: The number of bytes sent when success; **
@@ -329,18 +317,15 @@ static int _user_api_send_data(user_api_id_t *user_api_id, int length)
return sbytes;
}
int user_api_send_data(user_api_id_t *user_api_id, int fd, int length)
/****************************************************************************
** **
** Name: user_api_close() **
***************************************************************************/
int user_api_send_data(user_api_id_t *user_api_id, int length)
{
LOG_FUNC_IN;
/* Sanity check */
int sfd = user_api_get_fd(user_api_id);
if (fd != sfd) {
LOG_TRACE(ERROR, "USR-API - Endpoint %d is not the one created for communication with the user application layer (%d)", fd, sfd);
LOG_FUNC_RETURN (RETURNerror);
}
/* Send data to the user application layer */
int sbytes = 0;
@@ -358,27 +343,15 @@ int user_api_send_data(user_api_id_t *user_api_id, int fd, int length)
** Description: Close the user API from which the NAS layer sent/received **
** messages to/from the user application layer **
** **
** Inputs: fd: File descriptor of the connection endpoint **
** allocated by the system to communicate **
** with the user application layer **
** Others: None **
** **
** Outputs: Return: None **
** **
***************************************************************************/
void user_api_close(user_api_id_t *user_api_id, int fd)
void user_api_close(user_api_id_t *user_api_id)
{
LOG_FUNC_IN;
/* Sanity check */
int sfd = user_api_get_fd(user_api_id);
if (fd != sfd) {
LOG_TRACE(ERROR, "USR-API - Endpoint %d is not the one created for communication with the user application layer (%d)", fd, sfd);
LOG_FUNC_OUT;
return;
}
/* Cleanup the connection endpoint */
user_api_id->close(user_api_id->endpoint) ;
user_api_id->endpoint = NULL;
+3 -3
View File
@@ -66,10 +66,10 @@ int user_api_esm_callback(user_api_id_t *user_api_id, int cid, network_pdn_state
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_read_data(user_api_id_t *user_api_id);
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_send_data(user_api_id_t *user_api_id, int length);
void user_api_close(user_api_id_t *user_api_id);
int user_api_decode_data(user_api_id_t *user_api_id, user_at_commands_t *commands, int length);
int user_api_encode_data(user_api_id_t *user_api_id, const void* data, int add_success_code);
+10 -10
View File
@@ -70,7 +70,7 @@ static void *_nas_network_mngr(void *);
static int _nas_set_signal_handler(int signal, void (handler)(int));
static void _nas_signal_handler(int signal);
static void _nas_clean(user_api_id_t *user_api_id, int usr_fd, int net_fd);
static void _nas_clean(user_api_id_t *user_api_id, int net_fd);
uint8_t usim_test = 0;
// FIXME user must be set up with right itti message instance
@@ -126,7 +126,7 @@ int main(int argc, const char *argv[])
*/
if (network_api_initialize (nhost, nport) != RETURNok) {
LOG_TRACE (ERROR, "UE-MAIN - network_api_initialize() failed");
user_api_close (user_api_id, user_fd);
user_api_close (user_api_id);
exit (EXIT_FAILURE);
}
@@ -163,7 +163,7 @@ int main(int argc, const char *argv[])
if (pthread_create (&user_mngr, &attr, _nas_user_mngr, &user_fd) != 0) {
LOG_TRACE (ERROR, "UE-MAIN - "
"Failed to create the user management thread");
user_api_close (user_api_id, user_fd);
user_api_close (user_api_id);
network_api_close (network_fd);
exit (EXIT_FAILURE);
}
@@ -177,7 +177,7 @@ int main(int argc, const char *argv[])
&network_fd) != 0) {
LOG_TRACE (ERROR, "UE-MAIN - "
"Failed to create the network management thread");
user_api_close (user_api_id, user_fd);
user_api_close (user_api_id);
network_api_close (network_fd);
exit (EXIT_FAILURE);
}
@@ -195,7 +195,7 @@ int main(int argc, const char *argv[])
}
/* Termination cleanup */
_nas_clean (user_api_id, user_fd, network_fd);
_nas_clean (user_api_id, network_fd);
LOG_TRACE
(WARNING, "UE-MAIN - NAS main process exited");
@@ -236,7 +236,7 @@ static void *_nas_user_mngr(void *args)
}
/* Close the connection to the user application layer */
user_api_close (user->user_api_id, *fd);
user_api_close (user->user_api_id);
LOG_TRACE (WARNING, "UE-MAIN - "
"The user connection endpoint manager exited");
@@ -386,7 +386,7 @@ static void _nas_signal_handler(int signal)
LOG_TRACE (WARNING, "UE-MAIN - Signal %d received", signal);
// FIXME acces to global
_nas_clean (user->user_api_id, user_api_get_fd (user->user_api_id), network_api_get_fd ());
_nas_clean (user->user_api_id, network_api_get_fd ());
exit (EXIT_SUCCESS);
LOG_FUNC_OUT
@@ -407,7 +407,7 @@ static void _nas_signal_handler(int signal)
** Others: None **
** **
***************************************************************************/
static void _nas_clean(user_api_id_t *user_api_id, int usr_fd, int net_fd)
static void _nas_clean(user_api_id_t *user_api_id, int net_fd)
{
LOG_FUNC_IN;
@@ -418,8 +418,8 @@ static void _nas_clean(user_api_id_t *user_api_id, int usr_fd, int net_fd)
LOG_TRACE (INFO, "UE-MAIN - "
"Closing user connection %d and network connection %d",
usr_fd, net_fd);
user_api_close (user_api_id, usr_fd);
user_api_get_fd (user_api_id), net_fd);
user_api_close (user_api_id);
network_api_close (net_fd);
LOG_FUNC_OUT
+2 -3
View File
@@ -48,7 +48,7 @@ static int nas_ue_process_events(nas_user_t *user, struct epoll_event *events, i
for (event = 0; event < nb_events; event++) {
if (events[event].events != 0) {
/* If the event has not been yet been processed (not an itti message) */
if (events[event].data.fd == user->fd) {
if (events[event].data.fd == user_api_get_fd(user->user_api_id)) {
exit_loop = nas_user_receive_and_process(user, NULL);
} else {
LOG_E(NAS, "[UE] Received an event from an unknown fd %d!\n", events[event].data.fd);
@@ -94,8 +94,7 @@ void *nas_ue_task(void *args_p)
exit (EXIT_FAILURE);
}
user->fd = user_api_get_fd (user_api_id);
itti_subscribe_event_fd (TASK_NAS_UE, user->fd);
itti_subscribe_event_fd (TASK_NAS_UE, user_api_get_fd(user_api_id));
}
user->user_at_commands = calloc(1, sizeof(user_at_commands_t));
+2 -2
View File
@@ -223,7 +223,7 @@ int nas_user_receive_and_process(nas_user_t *user, char *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);
bytes = user_api_read_data (user_api_id);
if (bytes == RETURNerror) {
/* Failed to read data from the user application layer;
@@ -279,7 +279,7 @@ int nas_user_receive_and_process(nas_user_t *user, char *message)
}
/* Send the data message to the user */
bytes = user_api_send_data (user_api_id, user->fd, bytes);
bytes = user_api_send_data (user_api_id, bytes);
if (bytes == RETURNerror) {
/* Failed to send data to the user application layer;
-1
View File
@@ -60,7 +60,6 @@ Description NAS type definition to manage a user equipment
typedef struct {
int ueid; /* UE lower layer identifier */
int fd;
proc_data_t proc;
// Eps Session Management
esm_data_t *esm_data; // ESM internal data (used within ESM only)