nas_network.c 9.72 KB
Newer Older
Cedric Roux's avatar
 
Cedric Roux committed
1
/*****************************************************************************
2 3
            Eurecom OpenAirInterface 3
            Copyright(c) 2012 Eurecom
Cedric Roux's avatar
 
Cedric Roux committed
4

5
Source      nas_network.h
Cedric Roux's avatar
 
Cedric Roux committed
6

7
Version     0.1
Cedric Roux's avatar
 
Cedric Roux committed
8

9
Date        2012/09/20
Cedric Roux's avatar
 
Cedric Roux committed
10

11
Product     NAS stack
Cedric Roux's avatar
 
Cedric Roux committed
12

13
Subsystem   NAS main process
Cedric Roux's avatar
 
Cedric Roux committed
14

15
Author      Frederic Maurel
Cedric Roux's avatar
 
Cedric Roux committed
16

17
Description NAS procedure functions triggered by the network
Cedric Roux's avatar
 
Cedric Roux committed
18 19 20 21 22 23

*****************************************************************************/

#include "nas_network.h"
#include "commonDef.h"
#include "nas_log.h"
24
#include "nas_timer.h"
Cedric Roux's avatar
 
Cedric Roux committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

#include "as_message.h"
#include "nas_proc.h"

/****************************************************************************/
/****************  E X T E R N A L    D E F I N I T I O N S  ****************/
/****************************************************************************/

/****************************************************************************/
/*******************  L O C A L    D E F I N I T I O N S  *******************/
/****************************************************************************/

/****************************************************************************/
/******************  E X P O R T E D    F U N C T I O N S  ******************/
/****************************************************************************/

/****************************************************************************
 **                                                                        **
43
 ** Name:    nas_network_initialize()                                  **
Cedric Roux's avatar
 
Cedric Roux committed
44 45 46
 **                                                                        **
 ** Description: Initializes network internal data                         **
 **                                                                        **
47 48
 ** Inputs:  None                                                      **
 **          Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
49
 **                                                                        **
50 51 52
 ** Outputs:     None                                                      **
 **      Return:    None                                       **
 **          Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
53 54
 **                                                                        **
 ***************************************************************************/
55 56 57
#if defined(EPC_BUILD) && defined(NAS_MME)
void nas_network_initialize(mme_config_t *mme_config_p)
#else
Cedric Roux's avatar
 
Cedric Roux committed
58
void nas_network_initialize(void)
59
#endif
Cedric Roux's avatar
 
Cedric Roux committed
60 61 62 63 64
{
    LOG_FUNC_IN;

#ifdef NAS_MME
    /* Initialize the internal NAS processing data */
65
# if defined(EPC_BUILD)
66
    nas_timer_init();
67 68
    nas_proc_initialize(mme_config_p);
# else
Cedric Roux's avatar
 
Cedric Roux committed
69
    nas_proc_initialize();
70
# endif
Cedric Roux's avatar
 
Cedric Roux committed
71 72 73 74 75 76 77
#endif

    LOG_FUNC_OUT;
}

/****************************************************************************
 **                                                                        **
78
 ** Name:    nas_network_cleanup()                                     **
Cedric Roux's avatar
 
Cedric Roux committed
79 80 81
 **                                                                        **
 ** Description: Performs clean up procedure before the system is shutdown **
 **                                                                        **
82 83
 ** Inputs:  None                                                      **
 **          Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
84
 **                                                                        **
85 86 87
 ** Outputs:     None                                                      **
 **          Return:    None                                       **
 **          Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
88 89 90 91 92 93 94 95 96 97 98 99 100
 **                                                                        **
 ***************************************************************************/
void nas_network_cleanup(void)
{
    LOG_FUNC_IN;

    nas_proc_cleanup();

    LOG_FUNC_OUT;
}

/****************************************************************************
 **                                                                        **
101
 ** Name:    nas_network_process_data()                                **
Cedric Roux's avatar
 
Cedric Roux committed
102 103
 **                                                                        **
 ** Description: Process Access Stratum messages received from the network **
104
 **      and call applicable NAS procedure function.               **
Cedric Roux's avatar
 
Cedric Roux committed
105
 **                                                                        **
106 107 108 109
 ** Inputs:  msg_id:    AS message identifier                      **
 **          data:      Generic pointer to data structure that has **
 **             to be processed                            **
 **          Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
110
 **                                                                        **
111 112 113 114
 ** Outputs:     None                                                      **
 **      Return:    RETURNok if the message has been success-  **
 **             fully processed; RETURNerror otherwise     **
 **          Others:    None                                       **
Cedric Roux's avatar
 
Cedric Roux committed
115 116
 **                                                                        **
 ***************************************************************************/
117
int nas_network_process_data(int msg_id, const void *data)
Cedric Roux's avatar
 
Cedric Roux committed
118 119 120
{
    LOG_FUNC_IN;

121
    const as_message_t *msg = (as_message_t *)(data);
Cedric Roux's avatar
 
Cedric Roux committed
122 123 124 125
    int rc = RETURNok;

    /* Sanity check */
    if (msg_id != msg->msgID) {
126 127 128 129
        LOG_TRACE(ERROR, "NET-MAIN  - Message identifier 0x%x to process "
                  "is different from that of the network data (0x%x)",
                  msg_id, msg->msgID);
        LOG_FUNC_RETURN (RETURNerror);
Cedric Roux's avatar
 
Cedric Roux committed
130 131
    }

132
    switch (msg_id) {
Cedric Roux's avatar
 
Cedric Roux committed
133
#ifdef NAS_UE
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
        case AS_BROADCAST_INFO_IND:
            break;

        case AS_CELL_INFO_CNF: {
            /* 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,
                                    info->cellID, info->rat,
                                    info->rsrp, info->rsrq);
            break;
        }

        case AS_CELL_INFO_IND:
            break;

        case AS_PAGING_IND:
            break;

        case AS_NAS_ESTABLISH_CNF: {
            /* Received NAS signalling connection establishment confirm */
            const nas_establish_cnf_t *confirm = &msg->msg.nas_establish_cnf;
            if ( (confirm->errCode == AS_SUCCESS) ||
                    (confirm->errCode == AS_TERMINATED_NAS) ) {
                rc = nas_proc_establish_cnf(confirm->nasMsg.data,
                                            confirm->nasMsg.length);
            } else {
                LOG_TRACE(WARNING, "NET-MAIN  - "
                          "Initial NAS message not delivered");
                rc = nas_proc_establish_rej();
            }
            break;
        }

        case AS_NAS_RELEASE_IND:
            /* Received NAS signalling connection releaase indication */
            rc = nas_proc_release_ind(msg->msg.nas_release_ind.cause);
            break;

        case AS_UL_INFO_TRANSFER_CNF:
            /* Received uplink data transfer confirm */
            if (msg->msg.ul_info_transfer_cnf.errCode != AS_SUCCESS) {
                LOG_TRACE(WARNING, "NET-MAIN  - "
                          "Uplink NAS message not delivered");
                rc = nas_proc_ul_transfer_rej();
            } else {
                rc = nas_proc_ul_transfer_cnf();
            }
            break;

        case AS_DL_INFO_TRANSFER_IND: {
            const dl_info_transfer_ind_t *info = &msg->msg.dl_info_transfer_ind;
            /* Received downlink data transfer indication */
            rc = nas_proc_dl_transfer_ind(info->nasMsg.data,
                                          info->nasMsg.length);
            break;
        }

        case AS_RAB_ESTABLISH_IND:
            break;

        case AS_RAB_RELEASE_IND:
            break;
Cedric Roux's avatar
 
Cedric Roux committed
197 198
#endif
#ifdef NAS_MME
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
        case AS_NAS_ESTABLISH_IND: {
            /* Received NAS signalling connection establishment indication */
            const nas_establish_ind_t *indication = &msg->msg.nas_establish_ind;
            rc = nas_proc_establish_ind(indication->UEid,
                                        indication->tac,
                                        indication->initialNasMsg.data,
                                        indication->initialNasMsg.length);
            break;
        }

        case AS_DL_INFO_TRANSFER_CNF: {
            const dl_info_transfer_cnf_t *info = &msg->msg.dl_info_transfer_cnf;
            /* Received downlink data transfer confirm */
            if (info->errCode != AS_SUCCESS) {
                LOG_TRACE(WARNING, "NET-MAIN  - "
                          "Downlink NAS message not delivered");
                rc = nas_proc_dl_transfer_rej(info->UEid);
            } else {
                rc = nas_proc_dl_transfer_cnf(info->UEid);
            }
            break;
        }

        case AS_UL_INFO_TRANSFER_IND: {
            const ul_info_transfer_ind_t *info = &msg->msg.ul_info_transfer_ind;
            /* Received uplink data transfer indication */
            rc = nas_proc_ul_transfer_ind(info->UEid,
                                          info->nasMsg.data,
                                          info->nasMsg.length);
            break;
        }

        case AS_RAB_ESTABLISH_CNF:
            break;
Cedric Roux's avatar
 
Cedric Roux committed
233 234
#endif

235
        default:
Cedric Roux's avatar
 
Cedric Roux committed
236
            LOG_TRACE(ERROR, "NET-MAIN  - Unexpected AS message type: 0x%x",
237 238 239
                      msg_id);
            rc = RETURNerror;
            break;
Cedric Roux's avatar
 
Cedric Roux committed
240 241 242 243 244 245 246 247 248
    }

    LOG_FUNC_RETURN (rc);
}

/****************************************************************************/
/*********************  L O C A L    F U N C T I O N S  *********************/
/****************************************************************************/