From e90e30a56e0245c602b7308168e59dd3464606cf Mon Sep 17 00:00:00 2001
From: winckel <winckel@eurecom.fr>
Date: Sun, 22 Dec 2013 11:41:12 +0000
Subject: [PATCH] Modified NAS_UE_AUTOSTART option, an "at+cfun=1" message
 reception from UserProcess is simulated to start NAS Ue activities.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4809 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair-cn/NAS/EURECOM-NAS/src/UEprocess.c |  2 +-
 openair-cn/NAS/EURECOM-NAS/src/nas_user.c  | 56 ++++++++++++----------
 openair-cn/NAS/EURECOM-NAS/src/nas_user.h  |  2 +-
 openair-cn/NAS/nas_ue_task.c               | 12 +++--
 4 files changed, 41 insertions(+), 31 deletions(-)

diff --git a/openair-cn/NAS/EURECOM-NAS/src/UEprocess.c b/openair-cn/NAS/EURECOM-NAS/src/UEprocess.c
index dc8c583899..3783f0dc95 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 = nas_user_receive_and_process(fd);
+      exit_loop = nas_user_receive_and_process(fd, NULL);
     }
 
     /* Close the connection to the user application layer */
diff --git a/openair-cn/NAS/EURECOM-NAS/src/nas_user.c b/openair-cn/NAS/EURECOM-NAS/src/nas_user.c
index 65eaf4430c..7b85921108 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/nas_user.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/nas_user.c
@@ -212,7 +212,7 @@ void nas_user_initialize(emm_indication_callback_t emm_cb,
  ** Outputs:     Return:        FALSE, TRUE                                **
  **                                                                        **
  ***************************************************************************/
-int nas_user_receive_and_process(int * fd)
+int nas_user_receive_and_process(int *fd, char *message)
 {
     LOG_FUNC_IN;
 
@@ -221,14 +221,19 @@ int nas_user_receive_and_process(int * fd)
     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 (message != NULL) {
+        /* Set the message in receive buffer (Use to simulate reception of data from UserProcess) */
+        bytes = user_api_set_data(message);
+    } else {
+        /* 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) {
@@ -261,22 +266,25 @@ int nas_user_receive_and_process(int * fd)
              "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 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 (), 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);
+            /* 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);
+            }
         }
     }
 
diff --git a/openair-cn/NAS/EURECOM-NAS/src/nas_user.h b/openair-cn/NAS/EURECOM-NAS/src/nas_user.h
index ded7156423..51da3978ef 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/nas_user.h
+++ b/openair-cn/NAS/EURECOM-NAS/src/nas_user.h
@@ -40,7 +40,7 @@ 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_receive_and_process(int * fd, char *message);
 
 int nas_user_process_data(const void *data);
 
diff --git a/openair-cn/NAS/nas_ue_task.c b/openair-cn/NAS/nas_ue_task.c
index daf9b59ce9..5896712fd7 100644
--- a/openair-cn/NAS/nas_ue_task.c
+++ b/openair-cn/NAS/nas_ue_task.c
@@ -58,7 +58,7 @@ static int nas_ue_process_events(struct epoll_event *events, int nb_events)
     {
       /* If the event has not been yet been processed (not an itti message) */
       if (events[event].data.fd == user_fd) {
-        exit_loop = nas_user_receive_and_process(&user_fd);
+        exit_loop = nas_user_receive_and_process(&user_fd, NULL);
       } else {
         LOG_E(NAS, "[UE] Received an event from an unknown fd %d!\n", events[event].data.fd);
       }
@@ -101,11 +101,7 @@ void *nas_ue_task(void *args_p) {
   {
       MessageDef *message_p;
 
-#if (NAS_UE_AUTOSTART == 0)
       message_p = itti_alloc_new_message(TASK_NAS_UE, DEACTIVATE_MESSAGE);
-#else
-      message_p = itti_alloc_new_message(TASK_NAS_UE, ACTIVATE_MESSAGE);
-#endif
       itti_send_msg_to_task(TASK_L2L1, instance, message_p);
   }
 
@@ -122,6 +118,12 @@ void *nas_ue_task(void *args_p) {
         case INITIALIZE_MESSAGE:
           LOG_I(NAS, "[UE %d] Received %s\n", Mod_id, msg_name);
 #if (NAS_UE_AUTOSTART != 0)
+          {
+            /* Send an activate modem command to NAS like UserProcess should do it */
+            char *user_data = "at+cfun=1\r";
+
+            nas_user_receive_and_process (&user_fd, user_data);
+          }
 #endif
           break;
 
-- 
GitLab