From f277cd4736913f10722b4421cf910922ff54d411 Mon Sep 17 00:00:00 2001
From: winckel <winckel@eurecom.fr>
Date: Wed, 11 Dec 2013 17:26:54 +0000
Subject: [PATCH] Fixed an issue with stand alone EURECOM-NAS builds.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4672 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair-cn/NAS/EURECOM-NAS/src/UEprocess.c    |  2 +-
 .../NAS/EURECOM-NAS/src/api/user/user_api.c   | 84 ------------------
 .../NAS/EURECOM-NAS/src/api/user/user_api.h   |  2 -
 openair-cn/NAS/EURECOM-NAS/src/nas_user.c     | 85 +++++++++++++++++++
 openair-cn/NAS/EURECOM-NAS/src/nas_user.h     |  2 +
 openair-cn/NAS/nas_ue_task.c                  |  2 +-
 6 files changed, 89 insertions(+), 88 deletions(-)

diff --git a/openair-cn/NAS/EURECOM-NAS/src/UEprocess.c b/openair-cn/NAS/EURECOM-NAS/src/UEprocess.c
index 225032c83a..dc8c583899 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 78f7910f1b..8618d25824 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 686430a5be..b1d83cc043 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 642f5b58b6..65eaf4430c 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 1249eeee91..ded7156423 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 44c544c432..a5fa023b8b 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);
       }
-- 
GitLab