From 2e7f5cb42f2cbb3c36c929e1deffc4d40cc41a38 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Leroy?= <frederic.leroy@b-com.com>
Date: Mon, 4 Jul 2016 11:38:13 +0200
Subject: [PATCH] UE: move _nas_proc_data to nas_user_t struct

---
 openair3/NAS/UE/UEprocess.c     |  10 ++-
 openair3/NAS/UE/nas_network.c   |   5 +-
 openair3/NAS/UE/nas_network.h   |   4 +-
 openair3/NAS/UE/nas_proc.c      |  60 ++++++++---------
 openair3/NAS/UE/nas_proc.h      |  13 ++--
 openair3/NAS/UE/nas_proc_defs.h |  16 +++++
 openair3/NAS/UE/nas_ue_task.c   |   8 +--
 openair3/NAS/UE/nas_user.c      | 110 ++++++++++++++++----------------
 openair3/NAS/UE/nas_user.h      |   7 +-
 openair3/NAS/UE/user_defs.h     |   4 ++
 10 files changed, 128 insertions(+), 109 deletions(-)
 mode change 100755 => 100644 openair3/NAS/UE/nas_proc.c
 create mode 100644 openair3/NAS/UE/nas_proc_defs.h

diff --git a/openair3/NAS/UE/UEprocess.c b/openair3/NAS/UE/UEprocess.c
index 0f45697f1..df72012e3 100644
--- a/openair3/NAS/UE/UEprocess.c
+++ b/openair3/NAS/UE/UEprocess.c
@@ -53,6 +53,7 @@
 #include "nas_user.h"
 #include "nas_network.h"
 #include "nas_parser.h"
+#include "user_defs.h"
 
 #include <stdlib.h> // exit
 #include <poll.h>   // poll
@@ -78,6 +79,9 @@ static void _nas_signal_handler(int signal);
 
 static void _nas_clean(int usr_fd, int net_fd);
 
+// FIXME user must be set up with right itti message instance
+nas_user_t *user = NULL;
+
 /****************************************************************************/
 /******************  E X P O R T E D    F U N C T I O N S  ******************/
 /****************************************************************************/
@@ -134,7 +138,7 @@ int main(int argc, const char *argv[])
   /*
    * Initialize the NAS contexts
    */
-  nas_user_initialize (&user_api_emm_callback, &user_api_esm_callback,
+  nas_user_initialize (user, &user_api_emm_callback, &user_api_esm_callback,
                        FIRMWARE_VERSION);
   nas_network_initialize ();
 
@@ -231,7 +235,7 @@ static void *_nas_user_mngr(void *args)
 
   /* User receiving loop */
   while (!exit_loop) {
-    exit_loop = nas_user_receive_and_process(fd, NULL);
+    exit_loop = nas_user_receive_and_process(user, NULL);
   }
 
   /* Close the connection to the user application layer */
@@ -296,7 +300,7 @@ static void *_nas_network_mngr(void *args)
     }
 
     /* Process the network data message */
-    ret_code = nas_network_process_data (network_message_id,
+    ret_code = nas_network_process_data (user, network_message_id,
                                          network_api_get_data ());
 
     if (ret_code != RETURNok) {
diff --git a/openair3/NAS/UE/nas_network.c b/openair3/NAS/UE/nas_network.c
index d6aa625b3..3aa1f6c26 100755
--- a/openair3/NAS/UE/nas_network.c
+++ b/openair3/NAS/UE/nas_network.c
@@ -50,6 +50,7 @@ Description NAS procedure functions triggered by the network
 
 #include "as_message.h"
 #include "nas_proc.h"
+#include "user_defs.h"
 
 /****************************************************************************/
 /****************  E X T E R N A L    D E F I N I T I O N S  ****************/
@@ -125,7 +126,7 @@ void nas_network_cleanup(void)
  **          Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_network_process_data(int msg_id, const void *data)
+int nas_network_process_data(nas_user_t *user, int msg_id, const void *data)
 {
   LOG_FUNC_IN;
 
@@ -149,7 +150,7 @@ int nas_network_process_data(int msg_id, const void *data)
     /* Received cell information confirm */
     const cell_info_cnf_t *info = &msg->msg.cell_info_cnf;
     int cell_found = (info->errCode == AS_SUCCESS);
-    rc = nas_proc_cell_info(cell_found, info->tac,
+    rc = nas_proc_cell_info(user, cell_found, info->tac,
                             info->cellID, info->rat,
                             info->rsrp, info->rsrq);
     break;
diff --git a/openair3/NAS/UE/nas_network.h b/openair3/NAS/UE/nas_network.h
index d56542ba4..ccbe391e9 100755
--- a/openair3/NAS/UE/nas_network.h
+++ b/openair3/NAS/UE/nas_network.h
@@ -47,6 +47,8 @@ Description NAS procedure functions triggered by the network
 #ifndef __NAS_NETWORK_H__
 #define __NAS_NETWORK_H__
 
+#include "user_defs.h"
+
 /****************************************************************************/
 /*********************  G L O B A L    C O N S T A N T S  *******************/
 /****************************************************************************/
@@ -68,7 +70,7 @@ void nas_network_initialize(void);
 
 void nas_network_cleanup(void);
 
-int nas_network_process_data(int command_id, const void *data);
+int nas_network_process_data(nas_user_t *user, int command_id, const void *data);
 
 const void *nas_network_get_data(void);
 
diff --git a/openair3/NAS/UE/nas_proc.c b/openair3/NAS/UE/nas_proc.c
old mode 100755
new mode 100644
index e9f61b9d8..2777659bd
--- a/openair3/NAS/UE/nas_proc.c
+++ b/openair3/NAS/UE/nas_proc.c
@@ -45,6 +45,7 @@ Description NAS procedure call manager
 
 #include "nas_proc.h"
 #include "nas_log.h"
+#include "nas_user.h"
 
 #include "emm_main.h"
 #include "emm_sap.h"
@@ -69,17 +70,6 @@ Description NAS procedure call manager
 #define NAS_PROC_RSRQ_UNKNOWN   255
 #define NAS_PROC_RSRP_UNKNOWN   255
 
-/*
- * Local NAS data
- */
-static struct {
-  /* EPS capibility status */
-  int EPS_capability_status;
-  /* Reference signal received quality    */
-  int rsrq;
-  /* Reference signal received power      */
-  int rsrp;
-} _nas_proc_data;
 
 static int _nas_proc_activate(int cid, int apply_to_all);
 static int _nas_proc_deactivate(int cid, int apply_to_all);
@@ -104,15 +94,15 @@ static int _nas_proc_deactivate(int cid, int apply_to_all);
  **      Others:    _nas_proc_data                             **
  **                                                                        **
  ***************************************************************************/
-void nas_proc_initialize(emm_indication_callback_t emm_cb,
+void nas_proc_initialize(nas_user_t *user, emm_indication_callback_t emm_cb,
                          esm_indication_callback_t esm_cb, const char *imei)
 {
   LOG_FUNC_IN;
 
   /* Initialize local NAS data */
-  _nas_proc_data.EPS_capability_status = FALSE;
-  _nas_proc_data.rsrq = NAS_PROC_RSRQ_UNKNOWN;
-  _nas_proc_data.rsrp = NAS_PROC_RSRP_UNKNOWN;
+  user->proc.EPS_capability_status = FALSE;
+  user->proc.rsrq = NAS_PROC_RSRQ_UNKNOWN;
+  user->proc.rsrp = NAS_PROC_RSRP_UNKNOWN;
 
   /* Initialize the EMM procedure manager */
   emm_main_initialize(emm_cb, imei);
@@ -138,7 +128,7 @@ void nas_proc_initialize(emm_indication_callback_t emm_cb,
  **          Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-void nas_proc_cleanup(void)
+void nas_proc_cleanup()
 {
   LOG_FUNC_IN;
 
@@ -179,7 +169,7 @@ void nas_proc_cleanup(void)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_enable_s1_mode(void)
+int nas_proc_enable_s1_mode(nas_user_t *user)
 {
   LOG_FUNC_IN;
 
@@ -190,7 +180,7 @@ int nas_proc_enable_s1_mode(void)
    * Notify the EMM procedure call manager that EPS capability
    * of the UE is enabled
    */
-  _nas_proc_data.EPS_capability_status = TRUE;
+  user->proc.EPS_capability_status = TRUE;
   emm_sap.primitive = EMMREG_S1_ENABLED;
   rc = emm_sap_send(&emm_sap);
 
@@ -212,7 +202,7 @@ int nas_proc_enable_s1_mode(void)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_disable_s1_mode(void)
+int nas_proc_disable_s1_mode(nas_user_t *user)
 {
   LOG_FUNC_IN;
 
@@ -223,7 +213,7 @@ int nas_proc_disable_s1_mode(void)
    * Notify the EMM procedure call manager that EPS capability
    * of the UE is disabled
    */
-  _nas_proc_data.EPS_capability_status = FALSE;
+  user->proc.EPS_capability_status = FALSE;
   emm_sap.primitive = EMMREG_S1_DISABLED;
   rc = emm_sap_send(&emm_sap);
 
@@ -245,11 +235,11 @@ int nas_proc_disable_s1_mode(void)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_get_eps(int *stat)
+int nas_proc_get_eps(nas_user_t *user, int *stat)
 {
   LOG_FUNC_IN;
 
-  *stat = _nas_proc_data.EPS_capability_status;
+  *stat = user->proc.EPS_capability_status;
 
   LOG_FUNC_RETURN (RETURNok);
 }
@@ -365,12 +355,12 @@ int nas_proc_get_msisdn(char *msisdn_str, int *ton_npi)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_get_signal_quality(int *rsrq, int *rsrp)
+int nas_proc_get_signal_quality(nas_user_t *user, int *rsrq, int *rsrp)
 {
   LOG_FUNC_IN;
 
-  *rsrq = _nas_proc_data.rsrq;
-  *rsrp = _nas_proc_data.rsrp;
+  *rsrq = user->proc.rsrq;
+  *rsrp = user->proc.rsrp;
 
   LOG_FUNC_RETURN (RETURNok);
 }
@@ -433,7 +423,7 @@ int nas_proc_register(int mode, int format, const network_plmn_t *oper, int AcT)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_deregister(void)
+int nas_proc_deregister()
 {
   LOG_FUNC_IN;
 
@@ -611,7 +601,7 @@ int nas_proc_detach(int switch_off)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_attach(void)
+int nas_proc_attach()
 {
   LOG_FUNC_IN;
 
@@ -643,7 +633,7 @@ int nas_proc_attach(void)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_get_attach_status(void)
+int nas_proc_get_attach_status()
 {
   LOG_FUNC_IN;
 
@@ -666,7 +656,7 @@ int nas_proc_get_attach_status(void)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_get_pdn_range(void)
+int nas_proc_get_pdn_range()
 {
   LOG_FUNC_IN;
 
@@ -1028,7 +1018,7 @@ int nas_proc_activate_pdn(int cid)
  **      Others:    _nas_proc_data                             **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_cell_info(int found, tac_t tac, ci_t ci, AcT_t AcT,
+int nas_proc_cell_info(nas_user_t *user, int found, tac_t tac, ci_t ci, AcT_t AcT,
                        uint8_t rsrq, uint8_t rsrp)
 {
   LOG_FUNC_IN;
@@ -1037,8 +1027,8 @@ int nas_proc_cell_info(int found, tac_t tac, ci_t ci, AcT_t AcT,
   int rc;
 
   /* Store LTE signal strength/quality measurement data */
-  _nas_proc_data.rsrq = rsrq;
-  _nas_proc_data.rsrp = rsrp;
+  user->proc.rsrq = rsrq;
+  user->proc.rsrp = rsrp;
 
   /*
    * Notify the EMM procedure call manager that cell information
@@ -1110,7 +1100,7 @@ int nas_proc_establish_cnf(const Byte_t *data, uint32_t len)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_establish_rej(void)
+int nas_proc_establish_rej()
 {
   LOG_FUNC_IN;
 
@@ -1177,7 +1167,7 @@ int nas_proc_release_ind(int cause)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_ul_transfer_cnf(void)
+int nas_proc_ul_transfer_cnf()
 {
   LOG_FUNC_IN;
 
@@ -1214,7 +1204,7 @@ int nas_proc_ul_transfer_cnf(void)
  **      Others:    None                                       **
  **                                                                        **
  ***************************************************************************/
-int nas_proc_ul_transfer_rej(void)
+int nas_proc_ul_transfer_rej()
 {
   LOG_FUNC_IN;
 
diff --git a/openair3/NAS/UE/nas_proc.h b/openair3/NAS/UE/nas_proc.h
index 8a06a878c..00246e6fd 100755
--- a/openair3/NAS/UE/nas_proc.h
+++ b/openair3/NAS/UE/nas_proc.h
@@ -47,6 +47,7 @@ Description NAS procedure call manager
 
 #include "commonDef.h"
 #include "networkDef.h"
+#include "user_defs.h"
 #include "emm_main.h"
 #include "esm_ebr.h"
 
@@ -66,7 +67,7 @@ Description NAS procedure call manager
 /******************  E X P O R T E D    F U N C T I O N S  ******************/
 /****************************************************************************/
 
-void nas_proc_initialize(emm_indication_callback_t emm_cb,
+void nas_proc_initialize(nas_user_t *user, emm_indication_callback_t emm_cb,
                          esm_indication_callback_t esm_cb, const char *imei);
 
 void nas_proc_cleanup(void);
@@ -77,14 +78,14 @@ void nas_proc_cleanup(void);
  * --------------------------------------------------------------------------
  */
 
-int nas_proc_enable_s1_mode(void);
-int nas_proc_disable_s1_mode(void);
-int nas_proc_get_eps(int *stat);
+int nas_proc_enable_s1_mode(nas_user_t *user);
+int nas_proc_disable_s1_mode(nas_user_t *user);
+int nas_proc_get_eps(nas_user_t *user, int *stat);
 
 int nas_proc_get_imsi(char *imsi_str);
 int nas_proc_get_msisdn(char *msisdn_str, int *ton_npi);
 
-int nas_proc_get_signal_quality(int *rsrq, int *rsrp);
+int nas_proc_get_signal_quality(nas_user_t *user, int *rsrq, int *rsrp);
 
 int nas_proc_register(int mode, int format, const network_plmn_t *oper, int AcT);
 int nas_proc_deregister(void);
@@ -117,7 +118,7 @@ int nas_proc_activate_pdn(int cid);
  * --------------------------------------------------------------------------
  */
 
-int nas_proc_cell_info(int found, tac_t tac, ci_t ci, AcT_t rat, uint8_t rsrp,
+int nas_proc_cell_info(nas_user_t *user, int found, tac_t tac, ci_t ci, AcT_t rat, uint8_t rsrp,
                        uint8_t rsrq);
 
 int nas_proc_establish_cnf(const Byte_t *data, uint32_t len);
diff --git a/openair3/NAS/UE/nas_proc_defs.h b/openair3/NAS/UE/nas_proc_defs.h
new file mode 100644
index 000000000..d3868526e
--- /dev/null
+++ b/openair3/NAS/UE/nas_proc_defs.h
@@ -0,0 +1,16 @@
+#ifndef _NAS_PROC_DEFS_H
+#define _NAS_PROC_DEFS_H
+
+/*
+ * Local NAS data
+ */
+typedef struct {
+  /* EPS capibility status */
+  int EPS_capability_status;
+  /* Reference signal received quality    */
+  int rsrq;
+  /* Reference signal received power      */
+  int rsrp;
+} proc_data_t;
+
+#endif
diff --git a/openair3/NAS/UE/nas_ue_task.c b/openair3/NAS/UE/nas_ue_task.c
index 2f3c8bdd0..844bbccf2 100644
--- a/openair3/NAS/UE/nas_ue_task.c
+++ b/openair3/NAS/UE/nas_ue_task.c
@@ -56,7 +56,7 @@ static int nas_ue_process_events(nas_user_t *user, struct epoll_event *events, i
     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) {
-        exit_loop = nas_user_receive_and_process(&user->fd, NULL);
+        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);
       }
@@ -96,7 +96,7 @@ void *nas_ue_task(void *args_p)
     }
 
     /* Initialize NAS user */
-    nas_user_initialize (&user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION);
+    nas_user_initialize (user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION);
   }
 
   /* Set UE activation state */
@@ -124,7 +124,7 @@ void *nas_ue_task(void *args_p)
           /* 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);
+          nas_user_receive_and_process (user, user_data);
         }
 #endif
         break;
@@ -144,7 +144,7 @@ void *nas_ue_task(void *args_p)
         {
           int cell_found = (NAS_CELL_SELECTION_CNF (msg_p).errCode == AS_SUCCESS);
 
-          nas_proc_cell_info (cell_found, NAS_CELL_SELECTION_CNF (msg_p).tac,
+          nas_proc_cell_info (user, cell_found, NAS_CELL_SELECTION_CNF (msg_p).tac,
                               NAS_CELL_SELECTION_CNF (msg_p).cellID, NAS_CELL_SELECTION_CNF (msg_p).rat,
                               NAS_CELL_SELECTION_CNF (msg_p).rsrq, NAS_CELL_SELECTION_CNF (msg_p).rsrp);
         }
diff --git a/openair3/NAS/UE/nas_user.c b/openair3/NAS/UE/nas_user.c
index 447198b89..3534cd80e 100644
--- a/openair3/NAS/UE/nas_user.c
+++ b/openair3/NAS/UE/nas_user.c
@@ -44,8 +44,7 @@ Description NAS procedure functions triggered by the user
 *****************************************************************************/
 
 
-#include "nas_user.h"
-#include "userDef.h"
+#include "user_defs.h"
 #include "nas_log.h"
 #include "memory.h"
 
@@ -54,6 +53,7 @@ Description NAS procedure functions triggered by the user
 #include "at_error.h"
 #include "user_indication.h"
 #include "nas_proc.h"
+#include "nas_user.h"
 #include "user_api.h"
 
 #include <string.h> // memset, strncpy, strncmp
@@ -72,30 +72,30 @@ Description NAS procedure functions triggered by the user
  *  Functions executed upon receiving AT command from the user
  * ---------------------------------------------------------------------
  */
-static int _nas_user_proc_cgsn    (const at_command_t *data);
-static int _nas_user_proc_cgmi    (const at_command_t *data);
-static int _nas_user_proc_cgmm    (const at_command_t *data);
-static int _nas_user_proc_cgmr    (const at_command_t *data);
-static int _nas_user_proc_cimi    (const at_command_t *data);
-static int _nas_user_proc_cfun    (const at_command_t *data);
-static int _nas_user_proc_cpin    (const at_command_t *data);
-static int _nas_user_proc_csq     (const at_command_t *data);
-static int _nas_user_proc_cesq    (const at_command_t *data);
-static int _nas_user_proc_cops    (const at_command_t *data);
-static int _nas_user_proc_cgatt   (const at_command_t *data);
-static int _nas_user_proc_creg    (const at_command_t *data);
-static int _nas_user_proc_cgreg   (const at_command_t *data);
-static int _nas_user_proc_cereg   (const at_command_t *data);
-static int _nas_user_proc_cgdcont (const at_command_t *data);
-static int _nas_user_proc_cgact   (const at_command_t *data);
-static int _nas_user_proc_cmee    (const at_command_t *data);
-static int _nas_user_proc_clck    (const at_command_t *data);
-static int _nas_user_proc_cgpaddr (const at_command_t *data);
-static int _nas_user_proc_cnum    (const at_command_t *data);
-static int _nas_user_proc_clac    (const at_command_t *data);
+static int _nas_user_proc_cgsn    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cgmi    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cgmm    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cgmr    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cimi    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cfun    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cpin    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_csq     (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cesq    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cops    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cgatt   (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_creg    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cgreg   (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cereg   (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cgdcont (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cgact   (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cmee    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_clck    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cgpaddr (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_cnum    (nas_user_t *user, const at_command_t *data);
+static int _nas_user_proc_clac    (nas_user_t *user, const at_command_t *data);
 
 /* NAS procedures applicable to AT commands */
-typedef int (*_nas_user_procedure_t) (const at_command_t *);
+typedef int (*_nas_user_procedure_t) (nas_user_t *, const at_command_t *);
 
 static _nas_user_procedure_t _nas_user_procedure[AT_COMMAND_ID_MAX] = {
   NULL,
@@ -193,7 +193,7 @@ static user_nvdata_t _nas_user_nvdata;
  **          Others:    _nas_user_nvdata, _nas_user_context        **
  **                                                                        **
  ***************************************************************************/
-void nas_user_initialize(emm_indication_callback_t emm_cb,
+void nas_user_initialize(nas_user_t *user, emm_indication_callback_t emm_cb,
                          esm_indication_callback_t esm_cb, const char *version)
 {
   LOG_FUNC_IN;
@@ -221,7 +221,7 @@ void nas_user_initialize(emm_indication_callback_t emm_cb,
   _nas_user_context.fun = AT_CFUN_FUN_DEFAULT;
 
   /* Initialize the internal NAS processing data */
-  nas_proc_initialize(emm_cb, esm_cb, _nas_user_nvdata.IMEI);
+  nas_proc_initialize(user, emm_cb, esm_cb, _nas_user_nvdata.IMEI);
 
   LOG_FUNC_OUT;
 }
@@ -239,7 +239,7 @@ void nas_user_initialize(emm_indication_callback_t emm_cb,
  ** Outputs:     Return:        FALSE, TRUE                                **
  **                                                                        **
  ***************************************************************************/
-int nas_user_receive_and_process(int *fd, char *message)
+int nas_user_receive_and_process(nas_user_t *user, char *message)
 {
   LOG_FUNC_IN;
 
@@ -253,7 +253,7 @@ int nas_user_receive_and_process(int *fd, char *message)
     bytes = user_api_set_data(message);
   } else {
     /* Read the user data message */
-    bytes = user_api_read_data (*fd);
+    bytes = user_api_read_data (user->fd);
 
     if (bytes == RETURNerror) {
       /* Failed to read data from the user application layer;
@@ -286,7 +286,7 @@ int nas_user_receive_and_process(int *fd, char *message)
     }
 
     /* Process the user data message */
-    ret_code = nas_user_process_data (data);
+    ret_code = nas_user_process_data (user, data);
 
     if (ret_code != RETURNok) {
       /* The user data message has not been successfully
@@ -309,7 +309,7 @@ int nas_user_receive_and_process(int *fd, char *message)
       }
 
       /* Send the data message to the user */
-      bytes = user_api_send_data (*fd, bytes);
+      bytes = user_api_send_data (user->fd, bytes);
 
       if (bytes == RETURNerror) {
         /* Failed to send data to the user application layer;
@@ -341,7 +341,7 @@ int nas_user_receive_and_process(int *fd, char *message)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-int nas_user_process_data(const void *data)
+int nas_user_process_data(nas_user_t *user, const void *data)
 {
   LOG_FUNC_IN;
 
@@ -362,7 +362,7 @@ int nas_user_process_data(const void *data)
     nas_procedure = _nas_user_procedure[user_data->id];
 
     if (nas_procedure != NULL) {
-      ret_code = (*nas_procedure)(user_data);
+      ret_code = (*nas_procedure)(user, user_data);
     } else {
       /* AT command related to result format only */
       _nas_user_data.id = user_data->id;
@@ -425,7 +425,7 @@ const void *nas_user_get_data(void)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cgsn(const at_command_t *data)
+static int _nas_user_proc_cgsn(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -477,7 +477,7 @@ static int _nas_user_proc_cgsn(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cgmi(const at_command_t *data)
+static int _nas_user_proc_cgmi(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -529,7 +529,7 @@ static int _nas_user_proc_cgmi(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cgmm(const at_command_t *data)
+static int _nas_user_proc_cgmm(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -582,7 +582,7 @@ static int _nas_user_proc_cgmm(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cgmr(const at_command_t *data)
+static int _nas_user_proc_cgmr(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -638,7 +638,7 @@ static int _nas_user_proc_cgmr(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cimi(const at_command_t *data)
+static int _nas_user_proc_cimi(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -699,7 +699,7 @@ static int _nas_user_proc_cimi(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cfun(const at_command_t *data)
+static int _nas_user_proc_cfun(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -758,7 +758,7 @@ static int _nas_user_proc_cfun(const at_command_t *data)
     case AT_CFUN_FULL:
       /* Notify the NAS procedure call manager that the UE is
        * operational */
-      ret_code = nas_proc_enable_s1_mode();
+      ret_code = nas_proc_enable_s1_mode(user);
       break;
 
     default:
@@ -812,7 +812,7 @@ static int _nas_user_proc_cfun(const at_command_t *data)
  **          Others:    _nas_user_context, _nas_user_data          **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cpin(const at_command_t *data)
+static int _nas_user_proc_cpin(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -898,7 +898,7 @@ static int _nas_user_proc_cpin(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_csq(const at_command_t *data)
+static int _nas_user_proc_csq(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -959,7 +959,7 @@ static int _nas_user_proc_csq(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cesq(const at_command_t *data)
+static int _nas_user_proc_cesq(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -986,7 +986,7 @@ static int _nas_user_proc_cesq(const at_command_t *data)
     cesq->ber  = AT_CESQ_BER_UNKNOWN;
     cesq->rscp = AT_CESQ_RSCP_UNKNOWN;
     cesq->ecno = AT_CESQ_ECNO_UNKNOWN;
-    ret_code = nas_proc_get_signal_quality(&cesq->rsrq, &cesq->rsrp);
+    ret_code = nas_proc_get_signal_quality(user, &cesq->rsrq, &cesq->rsrp);
     break;
 
   case AT_COMMAND_TST:
@@ -1024,7 +1024,7 @@ static int _nas_user_proc_cesq(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cops(const at_command_t *data)
+static int _nas_user_proc_cops(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -1273,7 +1273,7 @@ static int _nas_user_proc_cops(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cgatt(const at_command_t *data)
+static int _nas_user_proc_cgatt(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -1378,7 +1378,7 @@ static int _nas_user_proc_cgatt(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_creg(const at_command_t *data)
+static int _nas_user_proc_creg(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -1527,7 +1527,7 @@ static int _nas_user_proc_creg(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cgreg(const at_command_t *data)
+static int _nas_user_proc_cgreg(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -1676,7 +1676,7 @@ static int _nas_user_proc_cgreg(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cereg(const at_command_t *data)
+static int _nas_user_proc_cereg(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -1857,7 +1857,7 @@ static int _nas_user_proc_cereg(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cgdcont(const at_command_t *data)
+static int _nas_user_proc_cgdcont(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -2109,7 +2109,7 @@ static int _nas_user_proc_cgdcont(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cgact(const at_command_t *data)
+static int _nas_user_proc_cgact(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -2236,7 +2236,7 @@ static int _nas_user_proc_cgact(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cmee(const at_command_t *data)
+static int _nas_user_proc_cmee(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -2349,7 +2349,7 @@ static int _nas_user_proc_cmee(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_clck(const at_command_t *data)
+static int _nas_user_proc_clck(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -2481,7 +2481,7 @@ static int _nas_user_proc_clck(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cgpaddr(const at_command_t *data)
+static int _nas_user_proc_cgpaddr(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -2573,7 +2573,7 @@ static int _nas_user_proc_cgpaddr(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_cnum(const at_command_t *data)
+static int _nas_user_proc_cnum(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
@@ -2634,7 +2634,7 @@ static int _nas_user_proc_cnum(const at_command_t *data)
  **          Others:    _nas_user_data                             **
  **                                                                        **
  ***************************************************************************/
-static int _nas_user_proc_clac(const at_command_t *data)
+static int _nas_user_proc_clac(nas_user_t *user, const at_command_t *data)
 {
   LOG_FUNC_IN;
 
diff --git a/openair3/NAS/UE/nas_user.h b/openair3/NAS/UE/nas_user.h
index 5bd08a658..bd6fa91ed 100644
--- a/openair3/NAS/UE/nas_user.h
+++ b/openair3/NAS/UE/nas_user.h
@@ -49,6 +49,7 @@ Description NAS procedure functions triggered by the user
 #include "networkDef.h"
 #include "emm_main.h"
 #include "esm_ebr.h"
+#include "user_defs.h"
 
 /****************************************************************************/
 /*********************  G L O B A L    C O N S T A N T S  *******************/
@@ -66,12 +67,12 @@ Description NAS procedure functions triggered by the user
 /******************  E X P O R T E D    F U N C T I O N S  ******************/
 /****************************************************************************/
 
-void nas_user_initialize(emm_indication_callback_t emm_cb,
+void nas_user_initialize(nas_user_t *user, emm_indication_callback_t emm_cb,
                          esm_indication_callback_t esm_cb, const char *version);
 
-int nas_user_receive_and_process(int * fd, char *message);
+int nas_user_receive_and_process(nas_user_t *user, char *message);
 
-int nas_user_process_data(const void *data);
+int nas_user_process_data(nas_user_t *user, const void *data);
 
 const void *nas_user_get_data(void);
 
diff --git a/openair3/NAS/UE/user_defs.h b/openair3/NAS/UE/user_defs.h
index 80607124d..b448a38f7 100644
--- a/openair3/NAS/UE/user_defs.h
+++ b/openair3/NAS/UE/user_defs.h
@@ -45,7 +45,11 @@ Description NAS type definition to manage a user equipment
 #ifndef __USER_DEFS_H__
 #define __USER_DEFS_H__
 
+#include "nas_proc_defs.h"
+
 typedef struct {
+  int fd;
+  proc_data_t proc;
 } nas_user_t;
 
 #endif
-- 
GitLab