emm_recv.c 19.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

gauthier's avatar
 
gauthier committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*****************************************************************************

Source      emm_recv.c

Version     0.1

Date        2013/01/30

Product     NAS stack

Subsystem   EPS Mobility Management

Author      Frederic Maurel

Description Defines functions executed at the EMMAS Service Access
        Point upon receiving EPS Mobility Management messages
        from the Access Stratum sublayer.

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

#include "emm_recv.h"
#include "commonDef.h"
#include "nas_log.h"

#include "emm_msgDef.h"
#include "emm_cause.h"
#include "emm_proc.h"

#include <string.h> // memcpy

/****************************************************************************/
/****************  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  ******************/
/****************************************************************************/

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

/*
 * --------------------------------------------------------------------------
 * Functions executed by both the UE and the MME upon receiving EMM messages
 * --------------------------------------------------------------------------
 */
/****************************************************************************
 **                                                                        **
 ** Name:    emm_recv_status()                                         **
 **                                                                        **
 ** Description: Processes EMM status message                              **
 **                                                                        **
 ** Inputs:  ueid:      UE lower layer identifier                  **
 **          msg:       The received EMM message                   **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
int emm_recv_status(unsigned int ueid, emm_status_msg *msg, int *emm_cause)
{
  LOG_FUNC_IN;

  int rc;

  LOG_TRACE(INFO, "EMMAS-SAP - Received EMM Status message (cause=%d)",
            msg->emmcause);

  /*
   * Message checking
   */
  *emm_cause = EMM_CAUSE_SUCCESS;
  /*
   * Message processing
   */
  rc = emm_proc_status_ind(ueid, msg->emmcause);

  LOG_FUNC_RETURN (rc);
}

/*
 * --------------------------------------------------------------------------
 * Functions executed by the UE upon receiving EMM message from the network
 * --------------------------------------------------------------------------
 */
/****************************************************************************
 **                                                                        **
 ** Name:    emm_recv_attach_accept()                                  **
 **                                                                        **
 ** Description: Processes Attach Accept message                           **
 **                                                                        **
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
int emm_recv_attach_accept(attach_accept_msg *msg, int *emm_cause)
{
  LOG_FUNC_IN;

  int rc;
  int i;

  LOG_TRACE(INFO, "EMMAS-SAP - Received Attach Accept message");

  /*
   * Message checking
   */
Bilel's avatar
Bilel committed
140
141
142
143
144
145
146
147
148
  // supported cases:
  // typeoflist = 1 Or
  // typeoflist = 0 and numberofelements = 1 (ie numberofelements equal to zero see 3gpp 24.301 9.9.3.33.1)
  LOG_D(NAS,"attach accept type of list: %d, number of element: %d\n",msg->tailist.typeoflist, msg->tailist.numberofelements);
  if (!( (msg->tailist.typeoflist == TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_CONSECUTIVE_TACS) ||
         ((msg->tailist.typeoflist == 0) && ( (msg->tailist.numberofelements + 1) == 1))
       )
     )
  {
gauthier's avatar
 
gauthier committed
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
197
198
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
    /* Only list of TACs belonging to one PLMN with consecutive
     * TAC values is supported */
    *emm_cause = EMM_CAUSE_IE_NOT_IMPLEMENTED;
  } else if ( (msg->presencemask & ATTACH_ACCEPT_GUTI_PRESENT) &&
              (msg->guti.guti.typeofidentity != EPS_MOBILE_IDENTITY_GUTI) ) {
    /* The only supported type of EPS mobile identity is GUTI */
    *emm_cause = EMM_CAUSE_IE_NOT_IMPLEMENTED;
  }

  /* Handle message checking error */
  if (*emm_cause != EMM_CAUSE_SUCCESS) {
    LOG_FUNC_RETURN (RETURNerror);
  }

  /*
   * Message processing
   */
  /* Compute timers value */
  long T3412, T3402 = -1, T3423 = -1;
  T3412 = gprs_timer_value(&msg->t3412value);

  if (msg->presencemask & ATTACH_ACCEPT_T3402_VALUE_PRESENT) {
    T3402 = gprs_timer_value(&msg->t3402value);
  }

  if (msg->presencemask & ATTACH_ACCEPT_T3423_VALUE_PRESENT) {
    T3423 = gprs_timer_value(&msg->t3423value);
  }

  /* Get the tracking area list the UE is registered to */

  /* LW: number of elements is coded as N-1 (0 -> 1 element, 1 -> 2 elements...),
   *  see 3GPP TS 24.301, section 9.9.3.33.1 */
  int n_tais = msg->tailist.numberofelements + 1;
  tai_t tai[n_tais];

  for (i = 0; i < n_tais; i++) {
    tai[i].plmn.MCCdigit1 = msg->tailist.mccdigit1;
    tai[i].plmn.MCCdigit2 = msg->tailist.mccdigit2;
    tai[i].plmn.MCCdigit3 = msg->tailist.mccdigit3;
    tai[i].plmn.MNCdigit1 = msg->tailist.mncdigit1;
    tai[i].plmn.MNCdigit2 = msg->tailist.mncdigit2;
    tai[i].plmn.MNCdigit3 = msg->tailist.mncdigit3;
    tai[i].tac = msg->tailist.tac + i;
  }

  /* Get the GUTI */
  GUTI_t *pguti = NULL;
  GUTI_t guti;

  if (msg->presencemask & ATTACH_ACCEPT_GUTI_PRESENT) {
    pguti = &guti;
    guti.gummei.plmn.MCCdigit1 = msg->guti.guti.mccdigit1;
    guti.gummei.plmn.MCCdigit2 = msg->guti.guti.mccdigit2;
    guti.gummei.plmn.MCCdigit3 = msg->guti.guti.mccdigit3;
    guti.gummei.plmn.MNCdigit1 = msg->guti.guti.mncdigit1;
    guti.gummei.plmn.MNCdigit2 = msg->guti.guti.mncdigit2;
    guti.gummei.plmn.MNCdigit3 = msg->guti.guti.mncdigit3;
    guti.gummei.MMEgid = msg->guti.guti.mmegroupid;
    guti.gummei.MMEcode = msg->guti.guti.mmecode;
    guti.m_tmsi = msg->guti.guti.mtmsi;
  }

  /* Get the list of equivalent PLMNs */
  int n_eplmns = 0;
  plmn_t eplmn;

  if (msg->presencemask & ATTACH_ACCEPT_EQUIVALENT_PLMNS_PRESENT) {
    n_eplmns = 1;
    eplmn.MCCdigit1 = msg->equivalentplmns.mccdigit1;
    eplmn.MCCdigit2 = msg->equivalentplmns.mccdigit2;
    eplmn.MCCdigit3 = msg->equivalentplmns.mccdigit3;
    eplmn.MNCdigit1 = msg->equivalentplmns.mncdigit1;
    eplmn.MNCdigit2 = msg->equivalentplmns.mncdigit2;
    eplmn.MNCdigit3 = msg->equivalentplmns.mncdigit3;
  }

  /* Execute attach procedure accepted by the network */
  rc = emm_proc_attach_accept(T3412, T3402, T3423, n_tais, tai, pguti,
                              n_eplmns, &eplmn,
                              &msg->esmmessagecontainer.esmmessagecontainercontents);

  LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_recv_attach_reject()                                  **
 **                                                                        **
 ** Description: Processes Attach Reject message                           **
 **                                                                        **
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
int emm_recv_attach_reject(attach_reject_msg *msg, int *emm_cause)
{
  LOG_FUNC_IN;

  int rc;

  LOG_TRACE(INFO, "EMMAS-SAP - Received Attach Reject message (cause=%d)",
            msg->emmcause);

  /*
   * Message checking
   */
  if ( (msg->emmcause == EMM_CAUSE_ESM_FAILURE) &&
       !(msg->presencemask & ATTACH_REJECT_ESM_MESSAGE_CONTAINER_PRESENT) ) {
    /* The ATTACH REJECT message shall be combined with a PDN
     * CONNECTIVITY REJECT message contained in the ESM message
     * container information element */
    *emm_cause = EMM_CAUSE_INVALID_MANDATORY_INFO;
  }

  /* Handle message checking error */
  if (*emm_cause != EMM_CAUSE_SUCCESS) {
    LOG_FUNC_RETURN (RETURNerror);
  }

  /*
   * Message processing
   */
  if (msg->presencemask & ATTACH_REJECT_ESM_MESSAGE_CONTAINER_PRESENT) {
    /* Execute attach procedure rejected by the network */
    rc = emm_proc_attach_reject(msg->emmcause,
                                &msg->esmmessagecontainer.esmmessagecontainercontents);
  } else {
    /* Execute attach procedure rejected by the network */
    rc = emm_proc_attach_reject(msg->emmcause, NULL);
  }

  LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_recv_detach_accept()                                  **
 **                                                                        **
 ** Description: Processes Detach Accept message                           **
 **                                                                        **
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
int emm_recv_detach_accept(detach_accept_msg *msg, int *emm_cause)
{
  LOG_FUNC_IN;

  int rc;

  LOG_TRACE(INFO, "EMMAS-SAP - Received Detach Accept message");

  /*
   * Message processing
   */
  /* Execute the UE initiated detach procedure completion by the UE */
  rc = emm_proc_detach_accept();

  LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_recv_identity_request()                               **
 **                                                                        **
 ** Description: Processes Identity Request message                        **
 **                                                                        **
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
int emm_recv_identity_request(identity_request_msg *msg, int *emm_cause)
{
  LOG_FUNC_IN;

  int rc;

  LOG_TRACE(INFO, "EMMAS-SAP - Received Identity Request message");

  /*
   * Message processing
   */
  /* Get the requested identity type */
  emm_proc_identity_type_t type;

  if (msg->identitytype == IDENTITY_TYPE_2_IMSI) {
    type = EMM_IDENT_TYPE_IMSI;
  } else if (msg->identitytype == IDENTITY_TYPE_2_IMEI) {
    type = EMM_IDENT_TYPE_IMEI;
  } else if (msg->identitytype == IDENTITY_TYPE_2_IMEISV) {
    type = EMM_IDENT_TYPE_IMEISV;
  } else if (msg->identitytype == IDENTITY_TYPE_2_TMSI) {
    type = EMM_IDENT_TYPE_TMSI;
  } else {
    /* All other values are interpreted as IMSI */
    type = EMM_IDENT_TYPE_IMSI;
  }

  /* Execute the identification procedure initiated by the network */
  rc = emm_proc_identification_request(type);

  LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_recv_authentication_request()                         **
 **                                                                        **
 ** Description: Processes Authentication Request message                  **
 **                                                                        **
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
int emm_recv_authentication_request(authentication_request_msg *msg,
                                    int *emm_cause)
{
  LOG_FUNC_IN;

  int rc;

  LOG_TRACE(INFO, "EMMAS-SAP - Received Authentication Request message");

  /*
   * Message checking
   */
  if ( (msg->authenticationparameterrand.rand.length == 0) ||
       (msg->authenticationparameterautn.autn.length == 0) ) {
    /* RAND and AUTN parameters shall not be null */
    *emm_cause = EMM_CAUSE_INVALID_MANDATORY_INFO;
  }

  /* Handle message checking error */
  if (*emm_cause != EMM_CAUSE_SUCCESS) {
    LOG_FUNC_RETURN (RETURNerror);
  }

  /*
   * Message processing
   */
  /* Execute the authentication procedure initiated by the network */
  rc = emm_proc_authentication_request(
         msg->naskeysetidentifierasme.tsc != NAS_KEY_SET_IDENTIFIER_MAPPED,
         msg->naskeysetidentifierasme.naskeysetidentifier,
         &msg->authenticationparameterrand.rand,
         &msg->authenticationparameterautn.autn);

  LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_recv_authentication_reject()                          **
 **                                                                        **
 ** Description: Processes Authentication Reject message                   **
 **                                                                        **
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
int emm_recv_authentication_reject(authentication_reject_msg *msg,
                                   int *emm_cause)
{
  LOG_FUNC_IN;

  int rc;

  LOG_TRACE(INFO, "EMMAS-SAP - Received Authentication Reject message");

  /*
   * Message processing
   */
  /* Execute the authentication procedure not accepted by the network */
  rc = emm_proc_authentication_reject();

  LOG_FUNC_RETURN (rc);
}

/****************************************************************************
 **                                                                        **
 ** Name:    emm_recv_security_mode_command()                          **
 **                                                                        **
 ** Description: Processes Security Mode Command message                   **
 **                                                                        **
 ** Inputs:  msg:       The received EMM message                   **
 **      Others:    None                                       **
 **                                                                        **
 ** Outputs:     emm_cause: EMM cause code                             **
 **      Return:    RETURNok, RETURNerror                      **
 **      Others:    None                                       **
 **                                                                        **
 ***************************************************************************/
int emm_recv_security_mode_command(security_mode_command_msg *msg,
                                   int *emm_cause)
{
  LOG_FUNC_IN;

  int rc;

  LOG_TRACE(INFO, "EMMAS-SAP - Received Security Mode Command message");

  /*
   * Message processing
   */
  /* Execute the security mode control procedure initiated by the network */
  rc = emm_proc_security_mode_command(
         msg->naskeysetidentifier.tsc != NAS_KEY_SET_IDENTIFIER_MAPPED,
         msg->naskeysetidentifier.naskeysetidentifier,
         msg->selectednassecurityalgorithms.typeofcipheringalgorithm,
         msg->selectednassecurityalgorithms.typeofintegrityalgorithm,
         msg->replayeduesecuritycapabilities.eea,
         msg->replayeduesecuritycapabilities.eia);

  LOG_FUNC_RETURN (rc);
}