commonDef.h 10.3 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
 */

22
/*
Cedric Roux's avatar
Cedric Roux committed
23

24
Source      commonDef.h
Cedric Roux's avatar
Cedric Roux committed
25

26
Version     0.1
Cedric Roux's avatar
Cedric Roux committed
27

28
Date        2012/02/27
Cedric Roux's avatar
Cedric Roux committed
29

30
Product     NAS stack
Cedric Roux's avatar
Cedric Roux committed
31

32
Subsystem   include
Cedric Roux's avatar
Cedric Roux committed
33

34
Author      Frederic Maurel
Cedric Roux's avatar
Cedric Roux committed
35

36
Description Contains global common definitions
Cedric Roux's avatar
Cedric Roux committed
37 38 39 40 41 42 43

*****************************************************************************/
#ifndef __COMMONDEF_H__
#define __COMMONDEF_H__

#include <stdint.h>
#include <stddef.h>
44
#include <stdbool.h>
Cedric Roux's avatar
Cedric Roux committed
45

46 47 48 49 50 51 52 53 54 55 56
typedef signed char        boolean_t;

#if !defined(TRUE)
#define TRUE               (boolean_t)0x01
#endif

#if !defined(FALSE)
#define FALSE              (boolean_t)0x00
#endif

#define BOOL_NOT(b) (b^TRUE)
57 58 59

#define NAS_UE_ID_FMT "0x%06x"

Cedric Roux's avatar
Cedric Roux committed
60 61 62 63
/****************************************************************************/
/*********************  G L O B A L    C O N S T A N T S  *******************/
/****************************************************************************/

64 65
#define RETURNok        (0)
#define RETURNerror     (-1)
Cedric Roux's avatar
Cedric Roux committed
66 67 68 69 70 71

/*
 * Name of the environment variable which defines the default directory
 * where the NAS application is executed and where are located files
 * where non-volatile data are stored
 */
72
#define DEFAULT_NAS_PATH    "PWD"
Cedric Roux's avatar
Cedric Roux committed
73 74 75 76 77 78 79

/****************************************************************************/
/************************  G L O B A L    T Y P E S  ************************/
/****************************************************************************/

/*
-----------------------------------------------------------------------------
80
            Standard data type definitions
Cedric Roux's avatar
Cedric Roux committed
81 82
-----------------------------------------------------------------------------
*/
83
typedef int8_t      SByte_t;    /* 8 bit  signed integer     */
84
typedef uint8_t     Byte_t;     /* 8 bit unsigned integer   */
85

Cedric Roux's avatar
Cedric Roux committed
86 87 88

/*
-----------------------------------------------------------------------------
89
            Common NAS data type definitions
Cedric Roux's avatar
Cedric Roux committed
90 91 92
-----------------------------------------------------------------------------
*/

93 94 95 96 97 98
typedef uint8_t     Stat_t;     /* Registration status  */
typedef uint16_t    lac_t;      /* Location Area Code   */
typedef uint8_t     rac_t;      /* Routing Area Code    */
typedef uint16_t    tac_t;      /* Tracking Area Code   */
typedef uint32_t    ci_t;       /* Cell Identifier  */
typedef uint8_t     AcT_t;      /* Access Technology    */
Cedric Roux's avatar
Cedric Roux committed
99 100 101 102 103

/*
 * International Mobile Subscriber Identity
 */
typedef struct {
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
  Byte_t length;
  union {
    struct {
      Byte_t digit2:4;
      Byte_t digit1:4;
      Byte_t digit4:4;
      Byte_t digit3:4;
      Byte_t digit6:4;
      Byte_t digit5:4;
      Byte_t digit8:4;
      Byte_t digit7:4;
      Byte_t digit10:4;
      Byte_t digit9:4;
      Byte_t digit12:4;
      Byte_t digit11:4;
      Byte_t digit14:4;
      Byte_t digit13:4;
121
#define EVEN_PARITY 0
122
#define ODD_PARITY  0xf
123 124 125
      Byte_t parity:4;
      Byte_t digit15:4;
    } num;
126
#define IMSI_SIZE   8
127 128
    Byte_t value[IMSI_SIZE];
  } u;
Cedric Roux's avatar
Cedric Roux committed
129 130
} imsi_t;

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
#define NAS_IMSI2STR(iMsI_t_PtR,iMsI_sTr, MaXlEn) \
        {\
          int l_offset = 0;\
          int l_ret    = 0;\
          l_ret = snprintf(iMsI_sTr + l_offset, MaXlEn - l_offset, "%u%u%u%u%u",\
	    		  iMsI_t_PtR->u.num.digit1, iMsI_t_PtR->u.num.digit2,\
	    		  iMsI_t_PtR->u.num.digit3, iMsI_t_PtR->u.num.digit4,\
	    		  iMsI_t_PtR->u.num.digit5);\
	      if ((iMsI_t_PtR->u.num.digit6 != 0xf)  && (l_ret > 0)) {\
	    	l_offset += l_ret;\
	    	l_ret = snprintf(iMsI_sTr + l_offset, MaXlEn - l_offset,  "%u", iMsI_t_PtR->u.num.digit6);\
	      }\
	      if (l_ret > 0) {\
	    	l_offset += l_ret;\
	    	l_ret = snprintf(iMsI_sTr + l_offset, MaXlEn - l_offset, "%u%u%u%u%u%u%u%u",\
	    		  iMsI_t_PtR->u.num.digit7, iMsI_t_PtR->u.num.digit8,\
	    		  iMsI_t_PtR->u.num.digit9, iMsI_t_PtR->u.num.digit10,\
	    		  iMsI_t_PtR->u.num.digit11, iMsI_t_PtR->u.num.digit12,\
	    		  iMsI_t_PtR->u.num.digit13, iMsI_t_PtR->u.num.digit14);\
	      }\
	      if ((iMsI_t_PtR->u.num.digit15 != 0xf)   && (l_ret > 0)) {\
	    	l_offset += l_ret;\
	    	l_ret = snprintf(iMsI_sTr + l_offset, MaXlEn - l_offset, "%u", iMsI_t_PtR->u.num.digit15);\
	      }\
	    }

Cedric Roux's avatar
Cedric Roux committed
157 158 159 160
/*
 * Mobile subscriber dialing number
 */
typedef struct {
161 162
  Byte_t ext:1;
  /* Type Of Number           */
163 164 165 166 167 168 169
#define MSISDN_TON_UNKNOWKN     0b000
#define MSISDN_TON_INTERNATIONAL    0b001
#define MSISDN_TON_NATIONAL     0b010
#define MSISDN_TON_NETWORK      0b011
#define MSISDN_TON_SUBCRIBER        0b100
#define MSISDN_TON_ABBREVIATED      0b110
#define MSISDN_TON_RESERVED     0b111
170 171
  Byte_t ton:3;
  /* Numbering Plan Identification    */
172 173 174 175 176 177 178 179 180 181
#define MSISDN_NPI_UNKNOWN      0b0000
#define MSISDN_NPI_ISDN_TELEPHONY   0b0001
#define MSISDN_NPI_GENERIC      0b0010
#define MSISDN_NPI_DATA         0b0011
#define MSISDN_NPI_TELEX        0b0100
#define MSISDN_NPI_MARITIME_MOBILE  0b0101
#define MSISDN_NPI_LAND_MOBILE      0b0110
#define MSISDN_NPI_ISDN_MOBILE      0b0111
#define MSISDN_NPI_PRIVATE      0b1110
#define MSISDN_NPI_RESERVED     0b1111
182 183 184 185 186
  Byte_t npi:4;
  /* Dialing Number           */
  struct {
    Byte_t lsb:4;
    Byte_t msb:4;
187
#define MSISDN_DIGIT_SIZE   10
188
  } digit[MSISDN_DIGIT_SIZE];
Cedric Roux's avatar
Cedric Roux committed
189 190 191 192 193 194 195 196 197 198 199 200
} msisdn_t;

/*
 * International Mobile Equipment Identity
 */
typedef imsi_t imei_t;

/*
 * Public Land Mobile Network identifier
 * PLMN = BCD encoding (Mobile Country Code + Mobile Network Code)
 */
typedef struct {
201 202 203 204 205 206
  Byte_t MCCdigit2:4;
  Byte_t MCCdigit1:4;
  Byte_t MNCdigit3:4;
  Byte_t MCCdigit3:4;
  Byte_t MNCdigit2:4;
  Byte_t MNCdigit1:4;
Cedric Roux's avatar
Cedric Roux committed
207 208 209 210 211 212
} plmn_t;

/*
 * Location Area Identification
 */
typedef struct {
213 214
  plmn_t plmn;    /* <MCC> + <MNC>    */
  lac_t lac;      /* Location Area Code   */
Cedric Roux's avatar
Cedric Roux committed
215 216 217 218 219 220
} lai_t;

/*
 * GPRS Routing Area Identification
 */
typedef struct {
221 222 223
  plmn_t plmn;    /* <MCC> + <MNC>    */
  lac_t lac;      /* Location Area Code   */
  rac_t rac;      /* Routing Area Code    */
Cedric Roux's avatar
Cedric Roux committed
224 225 226 227 228 229
} RAI_t;

/*
 * EPS Tracking Area Identification
 */
typedef struct {
230 231
  plmn_t plmn;    /* <MCC> + <MNC>    */
  tac_t tac;      /* Tracking Area Code   */
Cedric Roux's avatar
Cedric Roux committed
232 233 234 235 236 237
} tai_t;

/*
 * EPS Globally Unique MME Identity
 */
typedef struct {
238
  plmn_t plmn;    /* <MCC> + <MNC>    */
239 240
  uint16_t MMEgid;    /* MME group identifier */
  uint8_t MMEcode;    /* MME code     */
Cedric Roux's avatar
Cedric Roux committed
241 242 243 244 245 246
} gummei_t;

/*
 * EPS Globally Unique Temporary UE Identity
 */
typedef struct {
247
  gummei_t gummei;    /* Globally Unique MME Identity         */
248
  uint32_t m_tmsi;    /* M-Temporary Mobile Subscriber Identity   */
Cedric Roux's avatar
Cedric Roux committed
249
} GUTI_t;
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
#define GUTI2STR(GuTi_PtR, GuTi_StR, MaXlEn) \
        {\
          int l_offset = 0;\
          int l_ret    = 0;\
          l_ret += snprintf(GuTi_StR + l_offset,MaXlEn-l_offset, "%03u.",\
	    		  GuTi_PtR->gummei.plmn.MCCdigit3 * 100 +\
                  GuTi_PtR->gummei.plmn.MCCdigit2 * 10 +\
                  GuTi_PtR->gummei.plmn.MCCdigit1);\
          if (l_ret > 0) {\
        	l_offset += l_ret;\
          }  else {\
        	l_offset = MaXlEn;\
          }\
          if (GuTi_PtR->gummei.plmn.MNCdigit1 != 0xf) {\
              l_ret += snprintf(GuTi_StR + l_offset,MaXlEn-l_offset, "%03u|%04x|%02x|%08x",\
    	    		  GuTi_PtR->gummei.plmn.MNCdigit3 * 100 +\
                      GuTi_PtR->gummei.plmn.MNCdigit2 * 10 +\
                      GuTi_PtR->gummei.plmn.MNCdigit1,\
                      GuTi_PtR->gummei.MMEgid,\
                      GuTi_PtR->gummei.MMEcode,\
                      GuTi_PtR->m_tmsi);\
          } else {\
              l_ret += snprintf(GuTi_StR + l_offset,MaXlEn-l_offset, "%02u|%04x|%02x|%08x",\
                      GuTi_PtR->gummei.plmn.MNCdigit2 * 10 +\
                      GuTi_PtR->gummei.plmn.MNCdigit1,\
                      GuTi_PtR->gummei.MMEgid,\
                      GuTi_PtR->gummei.MMEcode,\
                      GuTi_PtR->m_tmsi);\
gauthier's avatar
gauthier committed
278
          }\
279 280 281
	    }


gauthier's avatar
gauthier committed
282 283


Cedric Roux's avatar
Cedric Roux committed
284
/* Checks PLMN validity */
285 286 287
#define PLMN_IS_VALID(plmn) (((plmn).MCCdigit1 &    \
                              (plmn).MCCdigit2 &    \
                              (plmn).MCCdigit3) != 0x0F)
Cedric Roux's avatar
Cedric Roux committed
288 289

/* Checks TAC validity */
290
#define TAC_IS_VALID(tac)   (((tac) != 0x0000) && ((tac) != 0xFFF0))
Cedric Roux's avatar
Cedric Roux committed
291 292

/* Checks TAI validity */
293 294
#define TAI_IS_VALID(tai)   (PLMN_IS_VALID((tai).plmn) &&   \
                             TAC_IS_VALID((tai).tac))
Cedric Roux's avatar
Cedric Roux committed
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
/*
 * A list of PLMNs
 */
#define PLMN_LIST_T(SIZE) struct {Byte_t n_plmns; plmn_t plmn[SIZE];}

/*
 * A list of TACs
 */
#define TAC_LIST_T(SIZE) struct {Byte_t n_tacs; TAC_t tac[SIZE];}

/*
 * A list of TAIs
 */
#define TAI_LIST_T(SIZE) struct {Byte_t n_tais; tai_t tai[SIZE];}

/*
 * User notification callback, executed whenever a change of data with
 * respect of network information (e.g. network registration and/or
 * location change, new PLMN becomes available) is notified by the
 * EPS Mobility Management sublayer
 */
316
typedef int (*emm_indication_callback_t) (Stat_t, tac_t, ci_t, AcT_t,
317
    const char*, size_t);
Cedric Roux's avatar
Cedric Roux committed
318

winckel's avatar
winckel committed
319
typedef enum eps_protocol_discriminator_e {
320 321
  /* Protocol discriminator identifier for EPS Mobility Management */
  EPS_MOBILITY_MANAGEMENT_MESSAGE =   0x7,
winckel's avatar
winckel committed
322

323 324
  /* Protocol discriminator identifier for EPS Session Management */
  EPS_SESSION_MANAGEMENT_MESSAGE =    0x2,
winckel's avatar
winckel committed
325 326
} eps_protocol_discriminator_t;

Cedric Roux's avatar
Cedric Roux committed
327 328 329 330 331 332 333 334 335
/****************************************************************************/
/********************  G L O B A L    V A R I A B L E S  ********************/
/****************************************************************************/

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

#endif /* __COMMONDEF_H__*/