As suggested by Evan Huus, use extended value_strings
[metze/wireshark/wip.git] / epan / dissectors / packet-nas_eps.c
1 /* packet-nas_eps.c
2  * Routines for Non-Access-Stratum (NAS) protocol for Evolved Packet System (EPS) dissection
3  *
4  * Copyright 2008 - 2010, Anders Broman <anders.broman@ericsson.com>
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * References: 3GPP TS 24.301 V11.5.0 (2012-12)
27  */
28
29 #include "config.h"
30
31 #include <glib.h>
32 #include <epan/packet.h>
33 #include <epan/asn1.h>
34 #include <epan/prefs.h>
35
36 #include "packet-gsm_map.h"
37 #include "packet-gsm_a_common.h"
38 #include "packet-e212.h"
39 #include "packet-lcsap.h"
40
41 #define PNAME  "Non-Access-Stratum (NAS)PDU"
42 #define PSNAME "NAS-EPS"
43 #define PFNAME "nas-eps"
44
45 /* Initialize the protocol and registered fields */
46 static int proto_nas_eps = -1;
47
48 /* Dissector handles */
49 static dissector_handle_t gsm_a_dtap_handle;
50 static dissector_handle_t lpp_handle;
51
52 /* Forward declaration */
53 static void disect_nas_eps_esm_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset);
54
55 static int hf_nas_eps_msg_emm_type = -1;
56 int hf_nas_eps_common_elem_id = -1;
57 int hf_nas_eps_emm_elem_id = -1;
58 static int hf_nas_eps_bearer_id = -1;
59 static int hf_nas_eps_spare_bits = -1;
60 static int hf_nas_eps_security_header_type = -1;
61 static int hf_nas_eps_msg_auth_code = -1;
62 static int hf_nas_eps_seq_no = -1;
63 static int hf_nas_eps_seq_no_short = -1;
64 static int hf_nas_eps_emm_ebi0 = -1;
65 static int hf_nas_eps_emm_ebi1 = -1;
66 static int hf_nas_eps_emm_ebi2 = -1;
67 static int hf_nas_eps_emm_ebi3 = -1;
68 static int hf_nas_eps_emm_ebi4 = -1;
69 static int hf_nas_eps_emm_ebi5 = -1;
70 static int hf_nas_eps_emm_ebi6 = -1;
71 static int hf_nas_eps_emm_ebi7 = -1;
72 static int hf_nas_eps_emm_ebi8 = -1;
73 static int hf_nas_eps_emm_ebi9 = -1;
74 static int hf_nas_eps_emm_ebi10 = -1;
75 static int hf_nas_eps_emm_ebi11 = -1;
76 static int hf_nas_eps_emm_ebi12 = -1;
77 static int hf_nas_eps_emm_ebi13 = -1;
78 static int hf_nas_eps_emm_ebi14 = -1;
79 static int hf_nas_eps_emm_ebi15 = -1;
80 static int hf_nas_eps_emm_dl_nas_cnt = -1;
81 static int hf_nas_eps_emm_nonce_mme = -1;
82 static int hf_nas_eps_emm_nonce = -1;
83 static int hf_nas_eps_emm_paging_id = -1;
84 static int hf_nas_eps_emm_eps_att_type = -1;
85 static int hf_nas_eps_emm_esr_ps = -1;
86 static int hf_nas_eps_emm_cs_lcs = -1;
87 static int hf_nas_eps_emm_epc_lcs = -1;
88 static int hf_nas_eps_emm_emc_bs = -1;
89 static int hf_nas_eps_emm_ims_vops = -1;
90 static int hf_nas_eps_emm_nas_key_set_id = -1;
91 static int hf_nas_eps_tsc = -1;
92 static int hf_nas_eps_emm_odd_even = -1;
93 static int hf_nas_eps_emm_type_of_id = -1;
94 static int hf_nas_eps_emm_mme_grp_id = -1;
95 static int hf_nas_eps_emm_imsi = -1;
96 static int hf_nas_eps_emm_imei = -1;
97 static int hf_nas_eps_emm_mme_code = -1;
98 static int hf_nas_eps_emm_m_tmsi = -1;
99 static int hf_nas_eps_esm_msg_cont = -1;
100 static int hf_nas_eps_esm_imeisv_req = -1;
101 static int hf_nas_eps_emm_toi = -1;
102 static int hf_nas_eps_emm_toc = -1;
103 static int hf_nas_eps_emm_EPS_attach_result = -1;
104 static int hf_nas_eps_emm_spare_half_octet = -1;
105 static int hf_nas_eps_emm_add_upd_res = -1;
106 static int hf_nas_eps_emm_add_upd_type = -1;
107 static int hf_nas_eps_emm_res = -1;
108 static int hf_nas_eps_emm_csfb_resp = -1;
109 static int hf_nas_eps_emm_cause = -1;
110 static int hf_nas_eps_emm_id_type2 = -1;
111 static int hf_nas_eps_emm_short_mac = -1;
112 static int hf_nas_eps_emm_tai_tol = -1;
113 static int hf_nas_eps_emm_tai_n_elem = -1;
114 static int hf_nas_eps_emm_tai_tac = -1;
115 static int hf_nas_eps_emm_eea0 = -1;
116 static int hf_nas_eps_emm_128eea1 = -1;
117 static int hf_nas_eps_emm_128eea2 = -1;
118 static int hf_nas_eps_emm_eea3 = -1;
119 static int hf_nas_eps_emm_eea4 = -1;
120 static int hf_nas_eps_emm_eea5 = -1;
121 static int hf_nas_eps_emm_eea6 = -1;
122 static int hf_nas_eps_emm_eea7 = -1;
123 static int hf_nas_eps_emm_eia0 = -1;
124 static int hf_nas_eps_emm_128eia1 = -1;
125 static int hf_nas_eps_emm_128eia2 = -1;
126 static int hf_nas_eps_emm_eia3 = -1;
127 static int hf_nas_eps_emm_eia4 = -1;
128 static int hf_nas_eps_emm_eia5 = -1;
129 static int hf_nas_eps_emm_eia6 = -1;
130 static int hf_nas_eps_emm_eia7 = -1;
131 static int hf_nas_eps_emm_uea0 = -1;
132 static int hf_nas_eps_emm_uea1 = -1;
133 static int hf_nas_eps_emm_uea2 = -1;
134 static int hf_nas_eps_emm_uea3 = -1;
135 static int hf_nas_eps_emm_uea4 = -1;
136 static int hf_nas_eps_emm_uea5 = -1;
137 static int hf_nas_eps_emm_uea6 = -1;
138 static int hf_nas_eps_emm_uea7 = -1;
139 static int hf_nas_eps_emm_ucs2_supp = -1;
140 static int hf_nas_eps_emm_uia1 = -1;
141 static int hf_nas_eps_emm_uia2 = -1;
142 static int hf_nas_eps_emm_uia3 = -1;
143 static int hf_nas_eps_emm_uia4 = -1;
144 static int hf_nas_eps_emm_uia5 = -1;
145 static int hf_nas_eps_emm_uia6 = -1;
146 static int hf_nas_eps_emm_uia7 = -1;
147 static int hf_nas_eps_emm_gea1 = -1;
148 static int hf_nas_eps_emm_gea2 = -1;
149 static int hf_nas_eps_emm_gea3 = -1;
150 static int hf_nas_eps_emm_gea4 = -1;
151 static int hf_nas_eps_emm_gea5 = -1;
152 static int hf_nas_eps_emm_gea6 = -1;
153 static int hf_nas_eps_emm_gea7 = -1;
154 static int hf_nas_eps_emm_h245_ash_cap = -1;
155 static int hf_nas_eps_emm_acc_csfb_cap = -1;
156 static int hf_nas_eps_emm_lpp_cap = -1;
157 static int hf_nas_eps_emm_lcs_cap = -1;
158 static int hf_nas_eps_emm_1xsrvcc_cap = -1;
159 static int hf_nas_eps_emm_nf_cap = -1;
160 static int hf_nas_eps_emm_ue_ra_cap_inf_upd_need_flg = -1;
161 static int hf_nas_eps_emm_ss_code = -1;
162 static int hf_nas_eps_emm_lcs_ind = -1;
163 static int hf_nas_eps_emm_gen_msg_cont_type = -1;
164 static int hf_nas_eps_emm_apn_ambr_ul = -1;
165 static int hf_nas_eps_emm_apn_ambr_dl = -1;
166 static int hf_nas_eps_emm_apn_ambr_ul_ext = -1;
167 static int hf_nas_eps_emm_apn_ambr_dl_ext = -1;
168 static int hf_nas_eps_emm_apn_ambr_ul_ext2 = -1;
169 static int hf_nas_eps_emm_apn_ambr_dl_ext2 = -1;
170 static int hf_nas_eps_emm_guti_type = -1;
171 static int hf_nas_eps_emm_switch_off = -1;
172 static int hf_nas_eps_emm_detach_type_UL = -1;
173 static int hf_nas_eps_emm_detach_type_DL = -1;
174
175 static int hf_nas_eps_qci = -1;
176 static int hf_nas_eps_mbr_ul = -1;
177 static int hf_nas_eps_mbr_dl = -1;
178 static int hf_nas_eps_gbr_ul = -1;
179 static int hf_nas_eps_gbr_dl = -1;
180 static int hf_nas_eps_embr_ul = -1;
181 static int hf_nas_eps_embr_dl = -1;
182 static int hf_nas_eps_egbr_ul = -1;
183 static int hf_nas_eps_egbr_dl = -1;
184
185 static int hf_nas_eps_esm_cause = -1;
186 static int hf_nas_eps_esm_eit = -1;
187 static int hf_nas_eps_esm_notif_ind = -1;
188 static int hf_nas_eps_esm_pdn_type = -1;
189 static int hf_nas_eps_esm_pdn_ipv4 = -1;
190 static int hf_nas_eps_esm_pdn_ipv6_if_id = -1;
191
192 static int hf_nas_eps_esm_linked_bearer_id = -1;
193
194 static int hf_nas_eps_active_flg = -1;
195 static int hf_nas_eps_eps_update_result_value = -1;
196 static int hf_nas_eps_eps_update_type_value = -1;
197 static int hf_nas_eps_service_type = -1;
198
199 static int hf_nas_eps_nas_msg_cont = -1;
200 static int hf_nas_eps_gen_msg_cont = -1;
201
202 static int hf_nas_eps_cmn_add_info = -1;
203 static int hf_nas_eps_esm_request_type = -1;
204
205 /* ESM */
206 static int hf_nas_eps_msg_esm_type = -1;
207 int hf_nas_eps_esm_elem_id = -1;
208 static int hf_nas_eps_esm_proc_trans_id = -1;
209
210 /* Initialize the subtree pointers */
211 static int ett_nas_eps = -1;
212 static int ett_nas_eps_esm_msg_cont = -1;
213 static int ett_nas_eps_nas_msg_cont = -1;
214 static int ett_nas_eps_gen_msg_cont = -1;
215 static int ett_nas_eps_cmn_add_info = -1;
216
217 /* Global variables */
218 static packet_info *gpinfo;
219 static gboolean g_nas_eps_dissect_plain = FALSE;
220
221 guint8 eps_nas_gen_msg_cont_type = 0;
222
223 /* Table 9.8.1: Message types for EPS mobility management
224  *  0   1   -   -   -   -   -   -       EPS mobility management messages
225  */
226 static const value_string nas_msg_emm_strings[] = {
227     { 0x41, "Attach request"},
228     { 0x42, "Attach accept"},
229     { 0x43, "Attach complete"},
230     { 0x44, "Attach reject"},
231     { 0x45, "Detach request"},
232     { 0x46, "Detach accept"},
233
234     { 0x48, "Tracking area update request"},
235     { 0x49, "Tracking area update accept"},
236     { 0x4a, "Tracking area update complete"},
237     { 0x4b, "Tracking area update reject"},
238
239     { 0x4c, "Extended service request"},
240     { 0x4e, "Service reject"},
241
242     { 0x50, "GUTI reallocation command"},
243     { 0x51, "GUTI reallocation complete"},
244     { 0x52, "Authentication request"},
245     { 0x53, "Authentication response"},
246     { 0x54, "Authentication reject"},
247     { 0x55, "Identity request"},
248     { 0x56, "Identity response"},
249     { 0x5c, "Authentication failure"},
250     { 0x5d, "Security mode command"},
251     { 0x5e, "Security mode complete"},
252     { 0x5f, "Security mode reject"},
253
254     { 0x60, "EMM status"},
255     { 0x61, "EMM information"},
256     { 0x62, "Downlink NAS transport"},
257     { 0x63, "Uplink NAS transport"},
258     { 0x64, "CS Service notification"},
259     { 0x68, "Downlink generic NAS transport"},
260     { 0x69, "Uplink generic NAS transport"},
261     { 0,    NULL }
262 };
263 static value_string_ext nas_msg_emm_strings_ext = VALUE_STRING_EXT_INIT(nas_msg_emm_strings);
264
265 /* Table 9.8.2: Message types for EPS session management */
266
267 static const value_string nas_msg_esm_strings[] = {
268     { 0xc1, "Activate default EPS bearer context request"},
269     { 0xc2, "Activate default EPS bearer context accept"},
270     { 0xc3, "Activate default EPS bearer context reject"},
271     { 0xc5, "Activate dedicated EPS bearer context request"},
272     { 0xc6, "Activate dedicated EPS bearer context accept"},
273     { 0xc7, "Activate dedicated EPS bearer context reject"},
274     { 0xc9, "Modify EPS bearer context request"},
275     { 0xca, "Modify EPS bearer context accept"},
276     { 0xcb, "Modify EPS bearer context reject"},
277     { 0xcd, "Deactivate EPS bearer context request"},
278     { 0xce, "Deactivate EPS bearer context accept"},
279     { 0xd0, "PDN connectivity request"},
280     { 0xd1, "PDN connectivity reject"},
281     { 0xd2, "PDN disconnect request"},
282     { 0xd3, "PDN disconnect reject"},
283     { 0xd4, "Bearer resource allocation request"},
284     { 0xd5, "Bearer resource allocation reject"},
285     { 0xd6, "Bearer resource modification request"},
286     { 0xd7, "Bearer resource modification reject"},
287     { 0xd9, "ESM information request"},
288     { 0xda, "ESM information response"},
289     { 0xdb, "Notification"},
290     { 0xe8, "ESM status"},
291     { 0,    NULL }
292 };
293 static value_string_ext nas_msg_esm_strings_ext = VALUE_STRING_EXT_INIT(nas_msg_esm_strings);
294
295 static const value_string security_header_type_vals[] = {
296     { 0,    "Plain NAS message, not security protected"},
297     { 1,    "Integrity protected"},
298     { 2,    "Integrity protected and ciphered"},
299     { 3,    "Integrity protected with new EPS security context"},
300     { 4,    "Integrity protected and ciphered with new EPS security context"},
301     { 5,    "Reserved"},
302     { 6,    "Reserved"},
303     { 7,    "Reserved"},
304     { 8,    "Reserved"},
305     { 9,    "Reserved"},
306     { 10,   "Reserved"},
307     { 11,   "Reserved"},
308     { 12,   "Security header for the SERVICE REQUEST message"},
309     { 13,   "These values are not used in this version of the protocol."
310              " If received they shall be interpreted as security header for the SERVICE REQUEST message"},
311     { 14,   "These values are not used in this version of the protocol."
312              " If received they shall be interpreted as Security header for the SERVICE REQUEST message"},
313     { 15,   "These values are not used in this version of the protocol."
314              " If received they shall be interpreted as Security header for the SERVICE REQUEST message"},
315     { 0,    NULL }
316 };
317 static value_string_ext security_header_type_vals_ext = VALUE_STRING_EXT_INIT(security_header_type_vals);
318
319 typedef enum
320 {
321     DE_EPS_CMN_ADD_INFO,                        /* 9.9.2.0  Additional information */
322     DE_EPS_CMN_DEVICE_PROPERTIES,               /* 9.9.2.0A Device properties */
323     DE_EPS_CMN_EPS_BE_CTX_STATUS,               /* 9.9.2.1  EPS bearer context status */
324     DE_EPS_CMN_LOC_AREA_ID,                     /* 9.9.2.2  Location area identification */
325     DE_EPS_CMN_MOB_ID,                          /* 9.9.2.3  Mobile identity */
326     DE_EPS_MS_CM_2,                             /* 9.9.2.4  Mobile station classmark 2 */
327     DE_EPS_MS_CM_3,                             /* 9.9.2.5  Mobile station classmark 3 */
328     DE_EPS_NAS_SEC_PAR_FROM_EUTRA,              /* 9.9.2.6  NAS security parameters from E-UTRA */
329     DE_EPS_NAS_SEC_PAR_TO_EUTRA,                /* 9.9.2.7  NAS security parameters to E-UTRA */
330
331     DE_EPS_CMN_PLM_LST,                         /* 9.9.2.8  PLMN list */
332     DE_EPS_CMN_SUP_CODEC_LST,                   /* 9.9.2.6  9.9.2.10    Supported codec list */
333     DE_EPS_COMMON_NONE                          /* NONE */
334 }
335 nas_eps_common_elem_idx_t;
336
337 static const value_string nas_eps_common_elem_strings[] = {
338     { DE_EPS_CMN_ADD_INFO, "Additional information" },                       /* 9.9.2.0  Additional information */
339     { DE_EPS_CMN_DEVICE_PROPERTIES, "Device properties" },                   /* 9.9.2.0A Device properties */
340     { DE_EPS_CMN_EPS_BE_CTX_STATUS, "EPS bearer context status" },           /* 9.9.2.1  EPS bearer context status */
341     { DE_EPS_CMN_LOC_AREA_ID, "Location area identification" },              /* 9.9.2.2  Location area identification */
342     { DE_EPS_CMN_MOB_ID, "Mobile identity" },                                /* 9.9.2.3  Mobile identity */
343     { DE_EPS_MS_CM_2, "Mobile station classmark 2" },                        /* 9.9.2.4  Mobile station classmark 2 */
344     { DE_EPS_MS_CM_3, "Mobile station classmark 3" },                        /* 9.9.2.5  Mobile station classmark 3 */
345     { DE_EPS_NAS_SEC_PAR_FROM_EUTRA, "NAS security parameters from E-UTRA" },/* 9.9.2.6  NAS security parameters from E-UTRA */
346     { DE_EPS_NAS_SEC_PAR_TO_EUTRA, "NAS security parameters to E-UTRA" },    /* 9.9.2.7  NAS security parameters to E-UTRA */
347     { DE_EPS_CMN_PLM_LST, "PLMN list" },                                     /* 9.9.2.8  PLMN list   */
348                                                                              /* 9.9.2.9  Spare half octet */
349     { DE_EPS_CMN_SUP_CODEC_LST, "Supported codec list" },                    /* 9.9.2.10 Supported codec list */
350     { 0, NULL }
351 };
352 value_string_ext nas_eps_common_elem_strings_ext = VALUE_STRING_EXT_INIT(nas_eps_common_elem_strings);
353
354 /* Utility functions */
355 static guint16
356 calc_bitrate(guint8 value) {
357     guint16 return_value = value;
358
359     if ((value > 63) && (value <= 127)) {
360         return_value = 64 + (value - 64) * 8;
361     }
362     else if ((value > 127) && (value <= 254)) {
363         return_value = 576 + (value - 128) * 64;
364     }
365     else if (value == 0xff) {
366         return_value = 0;
367     }
368     return return_value;
369 }
370 static guint32
371 calc_bitrate_ext(guint8 value) {
372     guint32 return_value = 0;
373
374     if ((value > 0) && (value <= 0x4a)) {
375         return_value = 8600 + value * 100;
376     }
377     else if ((value > 0x4a) && (value <= 0xba)) {
378         return_value = 16 + (value-0x4a);
379     }
380     else if ((value > 0xba) && (value <= 0xfa)) {
381         return_value = 128 + (value-0xba)*2;
382     }
383     else {
384         return_value = 256;
385     }
386
387     return return_value;
388 }
389 static guint32
390 calc_bitrate_ext2(guint8 value) {
391     guint32 return_value = 0;
392
393     if ((value > 0) && (value <= 0x3d)) {
394         return_value = 256 + value * 4;
395     }
396     else if ((value > 0x3d) && (value <= 0xa1)) {
397         return_value = 500 + (value-0x3d) * 10;
398     }
399     else if ((value > 0xa1) && (value <= 0xf6)) {
400         return_value = 1500 + (value-0xa1) * 100;
401     }
402     else {
403         return_value = 10000;
404     }
405
406     return return_value;
407 }
408
409 #define NUM_NAS_EPS_COMMON_ELEM (sizeof(nas_eps_common_elem_strings)/sizeof(value_string))
410 gint ett_nas_eps_common_elem[NUM_NAS_EPS_COMMON_ELEM];
411
412 /*
413  * 9.9.2    Common information elements
414  */
415
416 /* 9.9.2.0 Additional information */
417 static guint16
418 de_eps_cmn_add_info(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo,
419                     guint32 offset, guint len,
420                     gchar *add_string _U_, int string_len _U_)
421 {
422     proto_item *item;
423     proto_tree *sub_tree;
424     tvbuff_t   *new_tvb;
425
426     item     = proto_tree_add_item(tree, hf_nas_eps_cmn_add_info, tvb, offset, len, ENC_NA);
427     sub_tree = proto_item_add_subtree(item, ett_nas_eps_cmn_add_info);
428
429     new_tvb = tvb_new_subset(tvb, offset, len, len);
430
431     switch (eps_nas_gen_msg_cont_type) {
432         case 1:
433             /* LPP */
434             dissect_lcsap_Correlation_ID_PDU(new_tvb, pinfo, sub_tree, NULL);
435             break;
436         default:
437             break;
438     }
439
440     return(len);
441 }
442
443 /*
444  * 9.9.2.1  EPS bearer context status
445  */
446 static const true_false_string  nas_eps_emm_ebi_vals = {
447     "BEARER CONTEXT-ACTIVE",
448     "BEARER CONTEXT-INACTIVE"
449 };
450
451 static guint16
452 de_eps_cmn_eps_be_ctx_status(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
453                              guint32 offset, guint len _U_,
454                              gchar *add_string _U_, int string_len _U_)
455 {
456     guint32 curr_offset;
457
458     curr_offset = offset;
459
460     /* EBI(7)  EBI(6)  EBI(5)  EBI(4)  EBI(3)  EBI(2)  EBI(1) EBI(0) octet 3 */
461     proto_tree_add_item(tree, hf_nas_eps_emm_ebi7,  tvb, curr_offset, 1, ENC_BIG_ENDIAN);
462     proto_tree_add_item(tree, hf_nas_eps_emm_ebi6,  tvb, curr_offset, 1, ENC_BIG_ENDIAN);
463     proto_tree_add_item(tree, hf_nas_eps_emm_ebi5,  tvb, curr_offset, 1, ENC_BIG_ENDIAN);
464     /* EBI(0) - EBI(4): Bits 0 to 4 of octet 3 are spare and shall be coded as zero. */
465     proto_tree_add_item(tree, hf_nas_eps_emm_ebi4,  tvb, curr_offset, 1, ENC_BIG_ENDIAN);
466     proto_tree_add_item(tree, hf_nas_eps_emm_ebi3,  tvb, curr_offset, 1, ENC_BIG_ENDIAN);
467     proto_tree_add_item(tree, hf_nas_eps_emm_ebi2,  tvb, curr_offset, 1, ENC_BIG_ENDIAN);
468     proto_tree_add_item(tree, hf_nas_eps_emm_ebi1,  tvb, curr_offset, 1, ENC_BIG_ENDIAN);
469     proto_tree_add_item(tree, hf_nas_eps_emm_ebi0,  tvb, curr_offset, 1, ENC_BIG_ENDIAN);
470     curr_offset++;
471     /* EBI(15) EBI(14) EBI(13) EBI(12) EBI(11) EBI(10) EBI(9) EBI(8) octet 4 */
472     proto_tree_add_item(tree, hf_nas_eps_emm_ebi15, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
473     proto_tree_add_item(tree, hf_nas_eps_emm_ebi14, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
474     proto_tree_add_item(tree, hf_nas_eps_emm_ebi13, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
475     proto_tree_add_item(tree, hf_nas_eps_emm_ebi12, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
476     proto_tree_add_item(tree, hf_nas_eps_emm_ebi11, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
477     proto_tree_add_item(tree, hf_nas_eps_emm_ebi10, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
478     proto_tree_add_item(tree, hf_nas_eps_emm_ebi9,  tvb, curr_offset, 1, ENC_BIG_ENDIAN);
479     proto_tree_add_item(tree, hf_nas_eps_emm_ebi8,  tvb, curr_offset, 1, ENC_BIG_ENDIAN);
480
481     return len;
482 }
483 /*
484  * 9.9.2.2  Location area identification
485  * See subclause 10.5.1.3 in 3GPP TS 24.008 [6].
486  */
487 /*
488  * 9.9.2.3  Mobile identity
489  * See subclause 10.5.1.4 in 3GPP TS 24.008 [6].
490  * exported from gsm_a_common
491  */
492
493 /*
494  * 9.9.2.4  Mobile station classmark 2
495  * See subclause 10.5.1.6 in 3GPP TS 24.008 [13].
496  */
497 /*
498  * 9.9.2.5  Mobile station classmark 3
499  * See subclause 10.5.1.7 in 3GPP TS 24.008 [13].
500  */
501
502 /*
503  * 9.9.2.6  NAS security parameters from E-UTRA
504  */
505 guint16
506 de_emm_sec_par_from_eutra(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
507                           guint32 offset, guint len _U_,
508                           gchar *add_string _U_, int string_len _U_)
509 {
510     guint32 curr_offset;
511
512     curr_offset = offset;
513
514     /* DL NAS COUNT value (short) (octet 2, bit 1 to 4)
515      * This field contains the 4 least significant bits of the binary representation of the downlink
516      * NAS COUNT value applicable when this information element is sent.
517      */
518     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, curr_offset<<3, 4, ENC_BIG_ENDIAN);
519     proto_tree_add_item(tree, hf_nas_eps_emm_dl_nas_cnt, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
520
521     return len;
522 }
523
524 /*
525  * 9.9.2.7  NAS security parameters to E-UTRA
526  */
527 guint16
528 de_emm_sec_par_to_eutra(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
529                         guint32 offset, guint len _U_,
530                         gchar *add_string _U_, int string_len _U_)
531 {
532     guint32 curr_offset;
533
534     curr_offset = offset;
535     /* NonceMME value (octet 1 to 5)
536      * This field is coded as the nonce value in the Nonce information element (see subclause 9.9.3.25).
537      */
538     proto_tree_add_item(tree, hf_nas_eps_emm_nonce_mme, tvb, curr_offset, 4, ENC_BIG_ENDIAN);
539     curr_offset+=4;
540     /* type of ciphering algorithm (octet 6, bit 5 to 7)
541      * These fields are coded as the type of integrity protection algorithm and type of ciphering algorithm
542      * in the NAS security algorithms information element (see subclause 9.9.3.23).
543      * Bit 4 and 8 of octet 6 are spare and shall be coded as zero.
544      */
545     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, curr_offset<<3, 1, ENC_BIG_ENDIAN);
546     proto_tree_add_item(tree, hf_nas_eps_emm_toc, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
547     /* Type of integrity protection algorithm (octet 6, bit 1 to 3)*/
548     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, (curr_offset<<3)+4, 1, ENC_BIG_ENDIAN);
549     proto_tree_add_item(tree, hf_nas_eps_emm_toi, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
550     curr_offset++;
551     /*
552      * NAS key set identifier (octet 7, bit 1 to 3) and
553      * type of security context flag (TSC) (octet 7, bit 4)
554      * These fields are coded as the NAS key set identifier and type of security context flag in the
555      * NAS key set identifier information element (see subclause 9.9.3.21).
556      * Bit 5 to 8 of octet 7 are spare and shall be coded as zero.
557      */
558     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, curr_offset<<3, 4, ENC_BIG_ENDIAN);
559     /* Type of security context flag (TSC)  V   1/2 */
560     proto_tree_add_bits_item(tree, hf_nas_eps_tsc, tvb, (curr_offset<<3)+4, 1, ENC_BIG_ENDIAN);
561     /* NAS key set identifier */
562     proto_tree_add_bits_item(tree, hf_nas_eps_emm_nas_key_set_id, tvb, (curr_offset<<3)+5, 3, ENC_BIG_ENDIAN);
563     curr_offset++;
564     return len;
565 }
566
567 /*
568  * 9.9.2.8  PLMN list
569  * See subclause 10.5.1.13 in 3GPP TS 24.008 [6].
570  */
571 /*
572  * 9.9.2.9  Spare half octet
573  * This element is used in the description of EMM and ESM messages when an odd number of
574  * half octet type 1 information elements are used. This element is filled with spare bits
575  * set to zero and is placed in bits 5 to 8 of the octet unless otherwise specified.
576  * Coded Inline
577  */
578
579 /*
580  * 9.9.2.10 Supported codec list
581  * See subclause 10.5.4.32 in 3GPP TS 24.008 [13].
582  * Dissected in packet-gsm_a_dtap.c
583  */
584
585 guint16 (*nas_eps_common_elem_fcn[])(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
586                                      guint32 offset, guint len,
587                                      gchar *add_string, int string_len) = {
588     /* 9.9.2    Common information elements */
589     de_eps_cmn_add_info,            /* 9.9.2.0  Additional information */
590     NULL,                           /* 9.9.2.0A Device properties */
591     de_eps_cmn_eps_be_ctx_status,   /* 9.9.2.1  EPS bearer context status */
592     de_lai,                         /* 9.9.2.2  Location area identification */
593     de_mid,                         /* 9.9.2.3  Mobile identity See subclause 10.5.1.4 in 3GPP TS 24.008*/
594     de_ms_cm_2,                     /* 9.9.2.4  Mobile station classmark 2 */
595     de_ms_cm_3,                     /* 9.9.2.5  Mobile station classmark 3 */
596     de_emm_sec_par_from_eutra,      /* 9.9.2.6  NAS security parameters from E-UTRA */
597     de_emm_sec_par_to_eutra,        /* 9.9.2.7  NAS security parameters to E-UTRA */
598
599     de_plmn_list,                   /* 9.9.2.8  PLMN list */
600     NULL,                           /* 9.9.2.10 Supported codec list (packet-gsm_a_dtap.c) */
601     NULL,   /* NONE */
602 };
603
604 static const value_string nas_emm_elem_strings[] = {
605     /* 9.9.3    EPS Mobility Management (EMM) information elements */
606     { DE_EMM_ADD_UPD_RES, "Additional update result" },                        /* 9.9.3.0A Additional update result */
607     { DE_EMM_ADD_UPD_TYPE, "Additional update type" },                         /* 9.9.3.0B Additional update type */
608     { DE_EMM_AUTH_FAIL_PAR, "Authentication failure parameter" },              /* 9.9.3.1  Authentication failure parameter */
609     { DE_EMM_AUTN, "Authentication parameter AUTN" },                          /* 9.9.3.2  Authentication parameter AUTN */
610     { DE_EMM_AUTH_PAR_RAND, "Authentication parameter RAND" },                 /* 9.9.3.3  Authentication parameter RAND */
611     { DE_EMM_AUTH_RESP_PAR, "Authentication response parameter" },             /* 9.9.3.4  Authentication response parameter */
612     { DE_EMM_CSFB_RESP, "CSFB response" },                                     /* 9.9.3.5  CSFB response */
613     { DE_EMM_DAYL_SAV_T, "Daylight saving time" },                             /* 9.9.3.6  Daylight saving time */
614     { DE_EMM_DET_TYPE, "Detach type" },                                        /* 9.9.3.7  Detach type */
615     { DE_EMM_DRX_PAR, "DRX parameter" },                                       /* 9.9.3.8  DRX parameter */
616     { DE_EMM_CAUSE, "EMM cause" },                                             /* 9.9.3.9  EMM cause */
617     { DE_EMM_ATT_RES, "EPS attach result" },                                   /* 9.9.3.10 EPS attach result */
618     { DE_EMM_ATT_TYPE, "EPS attach type" },                                    /* 9.9.3.11 EPS attach type */
619     { DE_EMM_EPS_MID, "EPS mobile identity" },                                 /* 9.9.3.12 EPS mobile identity */
620     { DE_EMM_EPS_NET_FEATURE_SUP, "EPS network feature support" },             /* 9.9.3.12A EPS network feature support */
621     { DE_EMM_EPS_UPD_RES, "EPS update result" },                               /* 9.9.3.13 EPS update result */
622     { DE_EMM_EPS_UPD_TYPE, "EPS update type" },                                /* 9.9.3.14 EPS update type */
623     { DE_EMM_ESM_MSG_CONT, "ESM message container" },                          /* 9.9.3.15 ESM message conta */
624     { DE_EMM_GPRS_TIMER, "GPRS timer" },                                       /* 9.9.3.16 GPRS timer ,See subclause 10.5.7.3 in 3GPP TS 24.008 [6]. */
625     { DE_EMM_GPRS_TIMER_2, "GPRS timer 2" },                                   /* 9.9.3.16A GPRS timer 2, See subclause 10.5.7.4 in 3GPP TS 24.008. */
626     { DE_EMM_GPRS_TIMER_3, "GPRS timer 3" },                                   /* 9.9.3.16B GPRS timer 3, See subclause 10.5.7.4a in 3GPP TS 24.008. */
627     { DE_EMM_ID_TYPE_2, "Identity type 2" },                                   /* 9.9.3.17 Identity type 2 ,See subclause 10.5.5.9 in 3GPP TS 24.008 [6]. */
628     { DE_EMM_IMEISV_REQ, "IMEISV request" },                                   /* 9.9.3.18 IMEISV request ,See subclause 10.5.5.10 in 3GPP TS 24.008 [6]. */
629     { DE_EMM_KSI_AND_SEQ_NO, "KSI and sequence number" },                      /* 9.9.3.19 KSI and sequence number */
630     { DE_EMM_MS_NET_CAP, "MS network capability" },                            /* 9.9.3.20 MS network capability ,See subclause 10.5.5.12 in 3GPP TS 24.008 [6]. */
631     { DE_EMM_MS_NET_FEAT_SUP, "MS network feature support" },                  /* 9.9.3.20A MS network feature support, See subclause 10.5.1.15 in 3GPP TS 24.008. */
632     { DE_EMM_NAS_KEY_SET_ID, "NAS key set identifier" },                       /* 9.9.3.21 NAS key set identifier */
633     { DE_EMM_NAS_MSG_CONT, "NAS message container" },                          /* 9.9.3.22 NAS message container */
634     { DE_EMM_NAS_SEC_ALGS, "NAS security algorithms" },                        /* 9.9.3.23 NAS security algorithms */
635     { DE_EMM_NET_NAME, "Network name" },                                       /* 9.9.3.24 Network name, See subclause 10.5.3.5a in 3GPP TS 24.008 [6]. */
636     { DE_EMM_NONCE, "Nonce" },                                                 /* 9.9.3.25 Nonce */
637     { DE_EMM_PAGING_ID, "Paging identity" },                                   /* 9.9.3.25A Paging identity */
638     { DE_EMM_P_TMSI_SIGN, "P-TMSI signature" },                                /* 9.9.3.26 P-TMSI signature, See subclause 10.5.5.8 in 3GPP TS 24.008 [6]. */
639     { DE_EMM_SERV_TYPE, "Service type" },                                      /* 9.9.3.27 Service type ,See subclause 10.5.5.15 in 3GPP TS 24.008 [6]. */
640     { DE_EMM_SHORT_MAC, "Short MAC" },                                         /* 9.9.3.28 Short MAC */
641     { DE_EMM_TZ, "Time zone" },                                                /* 9.9.3.29 Time zone, See subclause 10.5.3.8 in 3GPP TS 24.008 [6]. */
642     { DE_EMM_TZ_AND_T, "Time zone and time" },                                 /* 9.9.3.30 Time zone and time, See subclause 10.5.3.9 in 3GPP TS 24.008 [6]. */
643     { DE_EMM_TMSI_STAT, "TMSI status" },                                       /* 9.9.3.31 TMSI status, See subclause 10.5.5.4 in 3GPP TS 24.008 [6]. */
644     { DE_EMM_TRAC_AREA_ID, "Tracking area identity" },                         /* 9.9.3.32 Tracking area identity */
645     { DE_EMM_TRAC_AREA_ID_LST, "Tracking area identity list" },                /* 9.9.3.33 Tracking area identity list */
646     { DE_EMM_UE_NET_CAP, "UE network capability" },                            /* 9.9.3.34 UE network capability */
647     { DE_EMM_UE_RA_CAP_INF_UPD_NEED, "UE radio capability information update needed" },/* 9.9.3.35 UE radio capability information update needed */
648     { DE_EMM_UE_SEC_CAP, "UE security capability" },                           /* 9.9.3.36 UE security capability */
649     { DE_EMM_EMERG_NUM_LST, "Emergency Number List" },                         /* 9.9.3.37 Emergency Number List */
650     { DE_EMM_CLI, "CLI" },                                                     /* 9.9.3.38 CLI */
651     { DE_EMM_SS_CODE, "SS Code" },                                             /* 9.9.3.39 SS Code */
652     { DE_EMM_LCS_IND, "LCS indicator" },                                       /* 9.9.3.40 LCS indicator */
653     { DE_EMM_LCS_CLIENT_ID, "LCS client identity" },                           /* 9.9.3.41 LCS client identity */
654     { DE_EMM_GEN_MSG_CONT_TYPE, "Generic message container type" },            /* 9.9.3.42 Generic message container type */
655     { DE_EMM_GEN_MSG_CONT, "Generic message container" },                      /* 9.9.3.43 Generic message container */
656     { DE_EMM_VOICE_DMN_PREF, "Voice domain preference and UEs usage setting" },/* 9.9.3.44 Voice domain preference and UEs usage setting */
657     { DE_EMM_GUTI_TYPE, "GUTI type" },                                         /* 9.9.3.45 GUTI type */
658     { 0, NULL }
659 };
660 value_string_ext nas_emm_elem_strings_ext = VALUE_STRING_EXT_INIT(nas_emm_elem_strings);
661
662 #define NUM_NAS_EMM_ELEM (sizeof(nas_emm_elem_strings)/sizeof(value_string))
663 gint ett_nas_eps_emm_elem[NUM_NAS_EMM_ELEM];
664
665 #if 0
666 /* This enum has been moved to packet-gsm_a_common to
667 make it possible to use element dissection from this dissector
668 in other dissectors.
669 It is left here as a comment for easier reference.
670 */
671 /*
672 Note this enum must be of the same size as the element decoding list
673 */
674 typedef enum
675 {
676     /* 9.9.3    EPS Mobility Management (EMM) information elements */
677     DE_EMM_ADD_UPD_RES,         /* 9.9.3.0A Additional update result */
678     DE_EMM_ADD_UPD_TYPE,        /* 9.9.3.0B Additional update type */
679     DE_EMM_AUTH_FAIL_PAR,       /* 9.9.3.1  Authentication failure parameter (dissected in packet-gsm_a_dtap.c)*/
680     DE_EMM_AUTN,                /* 9.9.3.2  Authentication parameter AUTN */
681     DE_EMM_AUTH_PAR_RAND,       /* 9.9.3.3  Authentication parameter RAND */
682     DE_EMM_AUTH_RESP_PAR,       /* 9.9.3.4  Authentication response parameter */
683     DE_EMM_CSFB_RESP,           /* 9.9.3.5  CSFB response */
684     DE_EMM_DAYL_SAV_T,          /* 9.9.3.6  Daylight saving time */
685     DE_EMM_DET_TYPE,            /* 9.9.3.7  Detach type */
686     DE_EMM_DRX_PAR,             /* 9.9.3.8  DRX parameter (dissected in packet-gsm_a_gm.c)*/
687     DE_EMM_CAUSE,               /* 9.9.3.9  EMM cause */
688     DE_EMM_ATT_RES,             /* 9.9.3.10 EPS attach result (Coded inline */
689     DE_EMM_ATT_TYPE,            /* 9.9.3.11 EPS attach type (Coded Inline)*/
690     DE_EMM_EPS_MID,             /* 9.9.3.12 EPS mobile identity */
691     DE_EMM_EPS_NET_FEATURE_SUP, /* 9.9.3.12A EPS network feature support */
692     DE_EMM_EPS_UPD_RES,         /* 9.9.3.13 EPS update result ( Coded inline)*/
693     DE_EMM_EPS_UPD_TYPE,        /* 9.9.3.14 EPS update type */
694     DE_EMM_ESM_MSG_CONT,        /* 9.9.3.15 ESM message conta */
695     DE_EMM_GPRS_TIMER,          /* 9.9.3.16 GPRS timer ,See subclause 10.5.7.3 in 3GPP TS 24.008 [6]. */
696     DE_EMM_GPRS_TIMER_2,        /* 9.9.3.16A GPRS timer 2, See subclause 10.5.7.4 in 3GPP TS 24.008. */
697     DE_EMM_GPRS_TIMER_3,        /* 9.9.3.16B GPRS timer 3, See subclause 10.5.7.4a in 3GPP TS 24.008. */
698     DE_EMM_ID_TYPE_2,           /* 9.9.3.17 Identity type 2 ,See subclause 10.5.5.9 in 3GPP TS 24.008 [6]. */
699     DE_EMM_IMEISV_REQ,          /* 9.9.3.18 IMEISV request ,See subclause 10.5.5.10 in 3GPP TS 24.008 [6]. */
700     DE_EMM_KSI_AND_SEQ_NO,      /* 9.9.3.19 KSI and sequence number */
701     DE_EMM_MS_NET_CAP,          /* 9.9.3.20 MS network capability ,See subclause 10.5.5.12 in 3GPP TS 24.008 [6]. */
702     DE_EMM_MS_NET_FEAT_SUP,     /* 9.9.3.20A MS network feature support, See subclause 10.5.1.15 in 3GPP TS 24.008. */
703     DE_EMM_NAS_KEY_SET_ID,      /* 9.9.3.21 NAS key set identifier (coded inline)*/
704     DE_EMM_NAS_MSG_CONT,        /* 9.9.3.22 NAS message container */
705     DE_EMM_NAS_SEC_ALGS,        /* 9.9.3.23 NAS security algorithms */
706     DE_EMM_NET_NAME,            /* 9.9.3.24 Network name, See subclause 10.5.3.5a in 3GPP TS 24.008 [6]. */
707     DE_EMM_NONCE,               /* 9.9.3.25 Nonce */
708     DE_EMM_PAGING_ID,           /* 9.9.3.25A Paging identity */
709     DE_EMM_P_TMSI_SIGN,         /* 9.9.3.26 P-TMSI signature, See subclause 10.5.5.8 in 3GPP TS 24.008 [6]. */
710     DE_EMM_SERV_TYPE,           /* 9.9.3.27 Service type */
711     DE_EMM_SHORT_MAC,           /* 9.9.3.28 Short MAC */
712     DE_EMM_TZ,                  /* 9.9.3.29 Time zone, See subclause 10.5.3.8 in 3GPP TS 24.008 [6]. */
713     DE_EMM_TZ_AND_T,            /* 9.9.3.30 Time zone and time, See subclause 10.5.3.9 in 3GPP TS 24.008 [6]. */
714     DE_EMM_TMSI_STAT,           /* 9.9.3.31 TMSI status, See subclause 10.5.5.4 in 3GPP TS 24.008 [6]. */
715     DE_EMM_TRAC_AREA_ID,        /* 9.9.3.32 Tracking area identity */
716     DE_EMM_TRAC_AREA_ID_LST,    /* 9.9.3.33 Tracking area identity list */
717     DE_EMM_UE_NET_CAP,          /* 9.9.3.34 UE network capability */
718     DE_EMM_UE_RA_CAP_INF_UPD_NEED,  /* 9.9.3.35 UE radio capability information update needed */
719     DE_EMM_UE_SEC_CAP,          /* 9.9.3.36 UE security capability */
720     DE_EMM_EMERG_NUM_LST,       /* 9.9.3.37 Emergency Number List */
721     DE_EMM_CLI,                 /* 9.9.3.38 CLI */
722     DE_EMM_SS_CODE,             /* 9.9.3.39 SS Code */
723     DE_EMM_LCS_IND,             /* 9.9.3.40 LCS indicator */
724     DE_EMM_LCS_CLIENT_ID,       /* 9.9.3.41 LCS client identity */
725     DE_EMM_GEN_MSG_CONT_TYPE,   /* 9.9.3.42 Generic message container type */
726     DE_EMM_GEN_MSG_CONT,        /* 9.9.3.43 Generic message container */
727     DE_EMM_VOICE_DMN_PREF,      /* 9.9.3.44 Voice domain preference and UEs usage setting */
728     DE_EMM_GUTI_TYPE,           /* 9.9.3.45 GUTI type */
729     DE_EMM_NONE                 /* NONE */
730 }
731 nas_emm_elem_idx_t;
732 #endif
733
734 /* TODO: Update to latest spec */
735 /* 9.9.3    EPS Mobility Management (EMM) information elements
736  */
737 /*
738  * 9.9.3.0A  Additional update result
739  */
740 static const value_string nas_eps_emm_add_upd_res_vals[] = {
741     { 0x0, "no additional information"},
742     { 0x1, "CS Fallback not preferred"},
743     { 0x2, "SMS only"},
744     { 0x3, "reserved"},
745     { 0, NULL }
746 };
747 static guint16
748 de_emm_add_upd_res(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
749                    guint32 offset, guint len _U_,
750                    gchar *add_string _U_, int string_len _U_)
751 {
752     guint32 curr_offset, bit_offset;
753
754     curr_offset = offset;
755     bit_offset  = (curr_offset<<3)+4;
756
757     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 2, ENC_BIG_ENDIAN);
758     bit_offset += 2;
759     proto_tree_add_bits_item(tree, hf_nas_eps_emm_add_upd_res, tvb, bit_offset, 2, ENC_BIG_ENDIAN);
760     curr_offset++;
761
762     return (curr_offset - offset);
763 }
764 /*
765  * 9.9.3.0B  Additional update type
766  */
767 static const value_string nas_eps_emm_add_upd_type_vals[] = {
768     { 0x0, "no additional information (shall be interpreted as request for"
769             " combined attach or combined tracking area updating)"},
770     { 0x1, "SMS only"},
771     { 0, NULL }
772 };
773 static guint16
774 de_emm_add_upd_type(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
775                     guint32 offset, guint len _U_,
776                     gchar *add_string _U_, int string_len _U_)
777 {
778     guint32 curr_offset, bit_offset;
779
780     curr_offset = offset;
781     bit_offset  = (curr_offset<<3)+4;
782
783     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
784     bit_offset += 3;
785     proto_tree_add_bits_item(tree, hf_nas_eps_emm_add_upd_type, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
786     curr_offset++;
787
788     return (curr_offset - offset);
789 }
790 /*
791  * 9.9.3.1  Authentication failure parameter
792  * See subclause 10.5.3.2.2 in 3GPP TS 24.008 [6].
793  * (dissected in packet-gsm_a_dtap.c)
794  */
795 /*
796  * 9.9.3.2  Authentication parameter AUTN
797  * See subclause 10.5.3.1.1 in 3GPP TS 24.008 [6].
798  */
799 /*
800  * 9.9.3.3  Authentication parameter RAND
801  * See subclause 10.5.3.1 in 3GPP TS 24.008 [6].
802  */
803 /*
804  * 9.9.3.4  Authentication response parameter
805  */
806 static guint16
807 de_emm_auth_resp_par(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
808                      guint32 offset, guint len _U_,
809                      gchar *add_string _U_, int string_len _U_)
810 {
811     guint32 curr_offset;
812
813     curr_offset = offset;
814
815     proto_tree_add_item(tree, hf_nas_eps_emm_res, tvb, curr_offset, len, ENC_NA);
816
817     return len;
818 }
819 /*
820  * 9.9.3.4A Ciphering key sequence number
821  * See subclause 9.9.3.19 in 3GPP TS 24.008 [13].
822  */
823
824 /*
825  * 9.9.3.5  CSFB response
826  */
827
828 /*
829  * CSFB response value (octet 1)
830  */
831
832 static const value_string nas_eps_emm_csfb_resp_vals[] = {
833     { 0x0,  "CS fallback rejected by the UE"},
834     { 0x1,  "CS fallback accepted by the UE"},
835     { 0, NULL }
836 };
837
838 static guint16
839 de_emm_csfb_resp(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
840                  guint32 offset, guint len _U_,
841                  gchar *add_string _U_, int string_len _U_)
842 {
843     guint32 curr_offset, bit_offset;
844
845     curr_offset = offset;
846
847     /* bit 4 Spare */
848     bit_offset = curr_offset<<3;
849     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset+4, 1, ENC_BIG_ENDIAN);
850
851     proto_tree_add_item(tree, hf_nas_eps_emm_csfb_resp, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
852     curr_offset++;
853
854     return(curr_offset-offset);
855 }
856 /*
857  * 9.9.3.6  Daylight saving time
858  * See subclause 10.5.3.12 in 3GPP TS 24.008 [6].
859  */
860 /*
861  * 9.9.3.7  Detach type
862  * Coded inline
863  */
864 static const value_string nas_eps_emm_switch_off_vals[] = {
865     { 0x0,  "Normal detach"},
866     { 0x1,  "Switch off"},
867     { 0x2,  "Reserved"},
868     { 0x3,  "Reserved"},
869     { 0x4,  "Reserved"},
870     { 0x5,  "Reserved"},
871     { 0x6,  "Reserved"},
872     { 0x7,  "Reserved"},
873     { 0, NULL }
874 };
875 /* Type of detach (octet 1)
876  * In the UE to network direction:
877  */
878 static const value_string nas_eps_emm_type_of_dtatch_UL_vals[] = {
879     { 0x1,  "EPS detach"},
880     { 0x2,  "IMSI detach"},
881     { 0x3,  "Combined EPS/IMSI detach"},
882     { 0x4,  "Combined EPS/IMSI detach"}, /* All other values are interpreted as
883                                              "combined EPS/IMSI detach" in this version of the protocol.*/
884     { 0x5,  "Combined EPS/IMSI detach"}, /* -"- */
885     { 0x6,  "Reserved"},
886     { 0x7,  "Reserved"},
887     { 0, NULL }
888 };
889
890 /*
891  * In the network to UE direction:
892  */
893
894 static const value_string nas_eps_emm_type_of_dtatch_DL_vals[] = {
895     { 0x1,  "Re-attach required"},
896     { 0x2,  "Re-attach not required"},
897     { 0x3,  "IMSI detach"},
898     { 0x4,  "Re-attach not required"}, /* All other values are interpreted as
899                                            "re-attach not required" in this version of the protocol.*/
900     { 0x5,  "Re-attach not required"}, /* -"- */
901     { 0x6,  "Reserved"},
902     { 0x7,  "Reserved"},
903     { 0, NULL }
904 };
905
906 /*
907  * 9.9.3.8  DRX parameter
908  * See subclause 10.5.5.6 in 3GPP TS 24.008 [13].
909  */
910 /*
911  * 9.9.3.9  EMM cause
912  */
913 static const value_string nas_eps_emm_cause_values[] = {
914     { 0x2,  "IMSI unknown in HSS"},
915     { 0x3,  "Illegal UE"},
916     { 0x5,  "IMEI not accepted"},
917     { 0x6,  "Illegal ME"},
918     { 0x7,  "EPS services not allowed"},
919     { 0x8,  "EPS services and non-EPS services not allowed"},
920     { 0x9,  "UE identity cannot be derived by the network"},
921     { 0xa,  "Implicitly detached"},
922     { 0xb,  "PLMN not allowed"},
923     { 0xc,  "Tracking Area not allowed"},
924     { 0xd,  "Roaming not allowed in this tracking area"},
925     { 0xe,  "EPS services not allowed in this PLMN"},
926     { 0xf,  "No Suitable Cells In tracking area"},
927     { 0x10, "MSC temporarily not reachable"},
928     { 0x11, "Network failure"},
929     { 0x12, "CS domain not available"},
930     { 0x13, "ESM failure"},
931     { 0x14, "MAC failure"},
932     { 0x15, "Synch failure"},
933     { 0x16, "Congestion"},
934     { 0x17, "UE security capabilities mismatch"},
935     { 0x18, "Security mode rejected, unspecified"},
936     { 0x19, "Not authorized for this CSG"},
937     { 0x1a, "Non-EPS authentication unacceptable"},
938     { 0x23, "Requested service option not authorized in this PLMN"},
939     { 0x27, "CS service temporarily not available"},
940     { 0x28, "No EPS bearer context activated"},
941     { 0x2a, "Severe network failure"},
942     { 0x5f, "Semantically incorrect message"},
943     { 0x60, "Invalid mandatory information"},
944     { 0x61, "Message type non-existent or not implemented"},
945     { 0x62, "Message type not compatible with the protocol state"},
946     { 0x63, "Information element non-existent or not implemented"},
947     { 0x64, "Conditional IE error"},
948     { 0x65, "Message not compatible with the protocol state"},
949     { 0x6f, "Protocol error, unspecified"},
950     { 0, NULL }
951 };
952 static value_string_ext nas_eps_emm_cause_values_ext = VALUE_STRING_EXT_INIT(nas_eps_emm_cause_values);
953
954 static guint16
955 de_emm_cause(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
956              guint32 offset, guint len _U_,
957              gchar *add_string _U_, int string_len _U_)
958 {
959     guint32 curr_offset;
960
961     curr_offset = offset;
962
963     proto_tree_add_item(tree, hf_nas_eps_emm_cause, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
964     curr_offset++;
965
966     return curr_offset-offset;}
967 /*
968  * 9.9.3.10 EPS attach result
969  */
970
971 static const value_string nas_eps_emm_EPS_attach_result_values[] = {
972     { 0,    "reserved"},
973     { 1,    "EPS only"},
974     { 2,    "Combined EPS/IMSI attach"},
975     { 3,    "reserved"},
976     { 4,    "reserved"},
977     { 5,    "reserved"},
978     { 6,    "reserved"},
979     { 7,    "reserved"},
980     { 0, NULL }
981 };
982 /* Coded inline */
983
984 /*
985  * 9.9.3.11 EPS attach type
986  */
987
988 static const value_string nas_eps_emm_eps_att_type_vals[] = {
989     { 0,    "EPS attach(unused)"},
990     { 1,    "EPS attach"},
991     { 2,    "Combined EPS/IMSI attach"},
992     { 3,    "EPS attach(unused)"},
993     { 4,    "EPS attach(unused)"},
994     { 5,    "EPS attach(unused)"},
995     { 6,    "EPS emergency attach"},
996     { 7,    "Reserved"},
997     { 0, NULL }
998 };
999 /* Coded inline */
1000
1001 /*
1002  * 9.9.3.12 EPS mobile identity
1003  */
1004 static char *
1005 unpack_eps_mid_digits(tvbuff_t *tvb) {
1006
1007     int     length;
1008     guint8  octet;
1009     int     i      = 0;
1010     int     offset = 0;
1011     char   *digit_str;
1012
1013     length = tvb_length(tvb);
1014
1015     digit_str = ep_alloc(length*2);
1016
1017     /* Get identity digit 1 */
1018     octet = tvb_get_guint8(tvb,offset);
1019     digit_str[i++] = (((octet>>4) & 0x0f) + '0');
1020     offset++;
1021
1022     /* Loop on following octets to retrieve other identity digits */
1023     while ( offset < length ) {
1024
1025         octet = tvb_get_guint8(tvb,offset);
1026         digit_str[i] = ((octet & 0x0f) + '0');
1027         i++;
1028
1029         /*
1030          * unpack second value in byte
1031          */
1032         octet = octet >> 4;
1033
1034         if (octet == 0x0f)  /* odd number bytes - hit filler */
1035             break;
1036
1037         digit_str[i] = ((octet & 0x0f) + '0');
1038         i++;
1039         offset++;
1040
1041     }
1042     digit_str[i]= '\0';
1043     return digit_str;
1044 }
1045
1046 static const value_string nas_eps_emm_type_of_id_vals[] = {
1047     { 0,    "reserved"},
1048     { 1,    "IMSI"},
1049     { 2,    "reserved"},
1050     { 3,    "IMEI"},
1051     { 4,    "reserved"},
1052     { 5,    "reserved"},
1053     { 6,    "GUTI"},
1054     { 7,    "reserved"},
1055     { 0, NULL }
1056 };
1057 static guint16
1058 de_emm_eps_mid(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1059                guint32 offset, guint len _U_,
1060                gchar *add_string _U_, int string_len _U_)
1061 {
1062     guint32   curr_offset;
1063     guint8    octet;
1064     char     *digit_str;
1065     tvbuff_t *new_tvb;
1066
1067     curr_offset = offset;
1068
1069     octet = tvb_get_guint8(tvb,offset);
1070     /* Type of identity (octet 3) */
1071     proto_tree_add_item(tree, hf_nas_eps_emm_odd_even, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1072     proto_tree_add_item(tree, hf_nas_eps_emm_type_of_id, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1073     switch (octet&0x7) {
1074         case 1:
1075             /* IMSI */
1076             new_tvb = tvb_new_subset(tvb, curr_offset, len, len );
1077             digit_str = unpack_eps_mid_digits(new_tvb);
1078             proto_tree_add_string(tree, hf_nas_eps_emm_imsi, new_tvb, 0, -1, digit_str);
1079             break;
1080         case 3:
1081             /* IMEI */
1082             new_tvb = tvb_new_subset(tvb, curr_offset, len, len );
1083             digit_str = unpack_eps_mid_digits(new_tvb);
1084             proto_tree_add_string(tree, hf_nas_eps_emm_imei, new_tvb, 0, -1, digit_str);
1085             break;
1086         case 6:
1087             /* GUTI */
1088             curr_offset++;
1089             curr_offset = dissect_e212_mcc_mnc(tvb, gpinfo, tree, curr_offset, TRUE);
1090             /* MME Group ID octet 7 - 8 */
1091             proto_tree_add_item(tree, hf_nas_eps_emm_mme_grp_id, tvb, curr_offset, 2, ENC_BIG_ENDIAN);
1092             curr_offset+=2;
1093             /* MME Code Octet 9 */
1094             proto_tree_add_item(tree, hf_nas_eps_emm_mme_code, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1095             curr_offset++;
1096             /* M-TMSI Octet 10 - 13 */
1097             proto_tree_add_item(tree, hf_nas_eps_emm_m_tmsi, tvb, curr_offset, 4, ENC_BIG_ENDIAN);
1098             /*curr_offset+=4;*/
1099             break;
1100         default:
1101             proto_tree_add_text(tree, tvb, curr_offset, len - 1, "Type of identity not known");
1102             break;
1103     }
1104
1105     return(len);
1106 }
1107
1108 /*
1109  * 9.9.3.12A    EPS network feature support
1110  */
1111 static const true_false_string nas_eps_emm_esr_ps_value = {
1112     "network supports use of EXTENDED SERVICE REQUEST to request for packet services",
1113     "network does not support use of EXTENDED SERVICE REQUEST to request for packet services"
1114 };
1115 static const value_string nas_eps_emm_cs_lcs_vals[] = {
1116     { 0,    "no information about support of location services via CS domain is available"},
1117     { 1,    "location services via CS domain not supported"},
1118     { 2,    "location services via CS domain supported"},
1119     { 3,    "reserved"},
1120     { 0, NULL }
1121 };
1122 static const true_false_string nas_eps_emm_epc_lcs_value = {
1123     "location services via EPC supported",
1124     "location services via EPC not supported"
1125 };
1126 static const true_false_string nas_eps_emm_emc_bs_value = {
1127     "emergency bearer services in S1 mode supported",
1128     "emergency bearer services in S1 mode not supported"
1129 };
1130 static const true_false_string nas_eps_emm_ims_vops_value = {
1131     "IMS voice over PS session in S1 mode supported",
1132     "IMS voice over PS session in S1 mode not supported"
1133 };
1134
1135 static guint16
1136 de_emm_eps_net_feature_sup(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1137                            guint32 offset, guint len _U_,
1138                            gchar *add_string _U_, int string_len _U_)
1139 {
1140     guint32 curr_offset, bit_offset;
1141
1142     curr_offset = offset;
1143     bit_offset = curr_offset << 3;
1144     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 2, ENC_BIG_ENDIAN);
1145     bit_offset += 2;
1146     proto_tree_add_bits_item(tree, hf_nas_eps_emm_esr_ps, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1147     bit_offset += 1;
1148     proto_tree_add_bits_item(tree, hf_nas_eps_emm_cs_lcs, tvb, bit_offset, 2, ENC_BIG_ENDIAN);
1149     bit_offset += 2;
1150     proto_tree_add_bits_item(tree, hf_nas_eps_emm_epc_lcs, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1151     bit_offset += 1;
1152     proto_tree_add_bits_item(tree, hf_nas_eps_emm_emc_bs, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1153     bit_offset += 1;
1154     proto_tree_add_bits_item(tree, hf_nas_eps_emm_ims_vops, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1155     /*bit_offset += 1;*/
1156
1157     return len;
1158 }
1159 /*
1160  * 9.9.3.13 EPS update result
1161  */
1162 static const value_string nas_eps_emm_eps_update_result_vals[] = {
1163     { 0,    "TA updated"},
1164     { 1,    "Combined TA/LA updated"},
1165     { 2,    "Reserved"},
1166     { 3,    "Reserved"},
1167     { 4,    "TA updated and ISR activated"},
1168     { 5,    "Combined TA/LA updated and ISR activated"},
1169     { 6,    "Reserved"},
1170     { 7,    "Reserved"},
1171     { 0, NULL }
1172 };
1173
1174 /*
1175  * 9.9.3.14 EPS update type
1176  */
1177 static const true_false_string  nas_eps_emm_active_flg_value = {
1178     "Bearer establishment requested",
1179     "No bearer establishment requested"
1180 };
1181
1182 static const value_string nas_eps_emm_eps_update_type_vals[] = {
1183     { 0,    "TA updating"},
1184     { 1,    "Combined TA/LA updating"},
1185     { 2,    "Combined TA/LA updating with IMSI attach"},
1186     { 3,    "Periodic updating"},
1187     { 4,    "Unused; shall be interpreted as 'TA updating', if received by the network"},
1188     { 5,    "Unused; shall be interpreted as 'TA updating', if received by the network"},
1189     { 6,    "Reserved"},
1190     { 7,    "Reserved"},
1191     { 0, NULL }
1192 };
1193
1194 /*
1195  * 9.9.3.15 ESM message container
1196  */
1197 static guint16
1198 de_emm_esm_msg_cont(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1199                     guint32 offset, guint len,
1200                     gchar *add_string _U_, int string_len _U_)
1201 {
1202     proto_item *item;
1203     proto_tree *sub_tree;
1204     tvbuff_t   *new_tvb;
1205     guint32     curr_offset;
1206
1207     curr_offset = offset;
1208
1209
1210     item = proto_tree_add_item(tree, hf_nas_eps_esm_msg_cont, tvb, curr_offset, len, ENC_NA);
1211     sub_tree = proto_item_add_subtree(item, ett_nas_eps_esm_msg_cont);
1212
1213     /* This IE can contain any ESM PDU as defined in subclause 8.3. */
1214     new_tvb = tvb_new_subset(tvb, curr_offset, len, len );
1215     /* Plain NAS message */
1216     disect_nas_eps_esm_msg(new_tvb, gpinfo, sub_tree, 0/* offset */);
1217
1218     return(len);
1219 }
1220 /*
1221  * 9.9.3.16 GPRS timer
1222  * See subclause 10.5.7.3 in 3GPP TS 24.008 [6].
1223  * packet-gsm_a_gm.c
1224  */
1225 /*
1226  * 9.9.3.16A GPRS timer 2
1227  * See subclause 10.5.7.4 in 3GPP TS 24.008.
1228  * packet-gsm_a_gm.c
1229  */
1230 /*
1231  * 9.9.3.16B GPRS timer 3
1232  * See subclause 10.5.7.4a in 3GPP TS 24.008.
1233  * packet-gsm_a_gm.c
1234  */
1235 /*
1236  * 9.9.3.17 Identity type 2
1237  * See subclause 10.5.5.9 in 3GPP TS 24.008 [6].
1238  */
1239 static const value_string nas_eps_emm_id_type2_vals[] = {
1240     { 1,    "IMSI"},
1241     { 2,    "IMEI"},
1242     { 3,    "IMEISV"},
1243     { 4,    "TMSI"},
1244     { 0, NULL }
1245 };
1246
1247 /*
1248  * 9.9.3.18 IMEISV request
1249  * See subclause 10.5.5.10 in 3GPP TS 24.008 [6].
1250  */
1251 /* IMEISV request value (octet 1) */
1252 static const value_string nas_eps_emm_imeisv_req_vals[] = {
1253     { 0,    "IMEISV not requested"},
1254     { 1,    "IMEISV requested"},
1255     { 2,    "IMEISV not requested"},
1256     { 3,    "IMEISV not requested"},
1257     { 4,    "IMEISV not requested"},
1258     { 5,    "IMEISV not requested"},
1259     { 6,    "IMEISV not requested"},
1260     { 7,    "IMEISV not requested"},
1261     { 0, NULL }
1262 };
1263 static guint16
1264 de_emm_nas_imeisv_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1265                       guint32 offset, guint len _U_,
1266                       gchar *add_string _U_, int string_len _U_)
1267 {
1268     guint32 curr_offset;
1269     int     bit_offset;
1270
1271     curr_offset = offset;
1272
1273     bit_offset = curr_offset<<3;
1274     bit_offset+=4;
1275     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1276     proto_tree_add_item(tree, hf_nas_eps_esm_imeisv_req, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1277     curr_offset++;
1278
1279     return(curr_offset - offset);
1280 }
1281 /*
1282  * 9.9.3.19 KSI and sequence number
1283  */
1284 static guint16
1285 de_emm_nas_ksi_and_seq_no(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1286                           guint32 offset, guint len _U_,
1287                           gchar *add_string _U_, int string_len _U_)
1288 {
1289     guint32 curr_offset;
1290     int     bit_offset;
1291
1292     curr_offset = offset;
1293     bit_offset = curr_offset<<3;
1294
1295     proto_tree_add_bits_item(tree, hf_nas_eps_emm_nas_key_set_id, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
1296     bit_offset += 3;
1297     proto_tree_add_bits_item(tree, hf_nas_eps_seq_no_short, tvb, bit_offset, 5, ENC_BIG_ENDIAN);
1298     curr_offset++;
1299
1300     return(curr_offset - offset);
1301 }
1302
1303 /*
1304  * 9.9.3.20 MS network capability
1305  * See subclause 10.5.5.12 in 3GPP TS 24.008 [6].
1306  * packet-gsm_a_gm.c
1307  */
1308 /*
1309  * 9.9.3.20A MS network feature support
1310  * See subclause 10.5.1.15 in 3GPP TS 24.008.
1311  * packet-gsm_a_gm.c
1312  */
1313 /*
1314  * 9.9.3.21 NAS key set identifier
1315  */
1316 /*
1317  * Type of security context flag (TSC) (octet 1)
1318  */
1319 static const true_false_string nas_eps_tsc_value = {
1320     "Mapped security context (for KSIsgsn)",
1321     "Native security context (for KSIasme)"
1322 };
1323
1324 /* NAS key set identifier (octet 1) Bits 3  2   1 */
1325
1326 static const value_string nas_eps_emm_NAS_key_set_identifier_vals[] = {
1327     { 0,    ""},
1328     { 1,    ""},
1329     { 2,    ""},
1330     { 3,    ""},
1331     { 4,    ""},
1332     { 5,    ""},
1333     { 6,    ""},
1334     { 7,    "No key is available"},
1335     { 0, NULL }
1336 };
1337
1338 /* Takes bit offset as input and consumes 4 bits */
1339 static void
1340 de_emm_nas_key_set_id_bits(tvbuff_t *tvb, proto_tree *tree, guint32 bit_offset, const gchar *add_string)
1341 {
1342     proto_item *item;
1343
1344     /* Type of security context flag (TSC) (octet 1)    V   1/2 */
1345     proto_tree_add_bits_item(tree, hf_nas_eps_tsc, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1346     bit_offset++;
1347     /* NAS key set identifier (octet 1) */
1348     item = proto_tree_add_bits_item(tree, hf_nas_eps_emm_nas_key_set_id, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
1349     if (add_string) {
1350         proto_item_append_text(item, "%s", add_string);
1351     }
1352     /*bit_offset+=3;*/
1353 }
1354 /*
1355  * Note used for TV Short
1356  */
1357 static guint16
1358 de_emm_nas_key_set_id(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1359                       guint32 offset, guint len _U_,
1360                       gchar *add_string _U_, int string_len _U_)
1361 {
1362     guint32 curr_offset, bit_offset;
1363
1364     curr_offset = offset;
1365
1366     /* Get the bit offset of the lover half of the octet bits 4 - 1 */
1367     bit_offset = curr_offset<<3;
1368     bit_offset+=4;
1369
1370     /* Type of security context flag (TSC) (octet 1)    V   1/2 */
1371     proto_tree_add_bits_item(tree, hf_nas_eps_tsc, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1372     bit_offset++;
1373     /* NAS key set identifier (octet 1) */
1374     proto_tree_add_bits_item(tree, hf_nas_eps_emm_nas_key_set_id, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
1375     /*bit_offset+=3;*/
1376     curr_offset++;
1377
1378     return(curr_offset - offset);
1379 }
1380
1381 /*
1382  * 9.9.3.22 NAS message container
1383  */
1384 static guint16
1385 de_emm_nas_msg_cont(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1386                     guint32 offset, guint len _U_,
1387                     gchar *add_string _U_, int string_len _U_)
1388 {
1389     proto_item *item;
1390     proto_tree *sub_tree;
1391     tvbuff_t   *new_tvb;
1392     guint32     curr_offset;
1393
1394     curr_offset = offset;
1395
1396     /* NAS message container contents (octet 3 to octet n)
1397      * This IE can contain an SMS message (i.e. CP-DATA, CP-ACK or CP-ERROR)
1398      * as defined in subclause 7.2 in 3GPP TS 24.011 [13A].
1399      */
1400
1401     item = proto_tree_add_item(tree, hf_nas_eps_nas_msg_cont, tvb, curr_offset, len, ENC_NA);
1402     sub_tree = proto_item_add_subtree(item, ett_nas_eps_nas_msg_cont);
1403
1404     new_tvb = tvb_new_subset(tvb, curr_offset, len, len );
1405     if (gsm_a_dtap_handle)
1406         call_dissector(gsm_a_dtap_handle, new_tvb, gpinfo, sub_tree);
1407
1408     return(len);
1409 }
1410 /*
1411  * 9.9.3.23 NAS security algorithms
1412  */
1413 /* Type of integrity protection algorithm (octet 2, bit 1 to 3) */
1414 static const value_string nas_eps_emm_toi_vals[] = {
1415     { 0,    "EPS integrity algorithm EIA0 (null integrity protection algorithm)"},
1416     { 1,    "EPS integrity algorithm 128-EIA1"},
1417     { 2,    "EPS integrity algorithm 128-EIA2"},
1418     { 3,    "EPS integrity algorithm 128-EIA3"},
1419     { 4,    "EPS integrity algorithm EIA4"},
1420     { 5,    "EPS integrity algorithm EIA5"},
1421     { 6,    "EPS integrity algorithm EIA6"},
1422     { 7,    "EPS integrity algorithm EIA7"},
1423     { 0, NULL }
1424 };
1425
1426 /* Type of ciphering algorithm (octet 2, bit 5 to 7) */
1427
1428 static const value_string nas_eps_emm_toc_vals[] = {
1429     { 0,    "EPS encryption algorithm EEA0 (null ciphering algorithm)"},
1430     { 1,    "EPS encryption algorithm 128-EEA1"},
1431     { 2,    "EPS encryption algorithm 128-EEA2"},
1432     { 3,    "EPS encryption algorithm 128-EEA3"},
1433     { 4,    "EPS encryption algorithm EEA4"},
1434     { 5,    "EPS encryption algorithm EEA5"},
1435     { 6,    "EPS encryption algorithm EEA6"},
1436     { 7,    "EPS encryption algorithm EEA7"},
1437     { 0, NULL }
1438 };
1439 static guint16
1440 de_emm_nas_sec_alsgs(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1441                      guint32 offset, guint len _U_,
1442                      gchar *add_string _U_, int string_len _U_)
1443 {
1444     int     bit_offset;
1445     guint32 curr_offset;
1446
1447     curr_offset = offset;
1448
1449     bit_offset = offset<<3;
1450     /* Bit 4 and 8 of octet 2 are spare and shall be coded as zero. */
1451     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1452     /* Type of ciphering algorithm (octet 2, bit 5 to 7) */
1453     proto_tree_add_item(tree, hf_nas_eps_emm_toc, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1454     bit_offset+=4;
1455     /* Bit 4 and 8 of octet 2 are spare and shall be coded as zero. */
1456     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
1457     /* Type of integrity protection algorithm (octet 2, bit 1 to 3) */
1458     proto_tree_add_item(tree, hf_nas_eps_emm_toi, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1459
1460     curr_offset++;
1461
1462     return(curr_offset-offset);
1463 }
1464 /*
1465  * 9.9.3.24 Network name
1466  * See subclause 10.5.3.5a in 3GPP TS 24.008 [6].
1467  */
1468 /*
1469  * 9.9.3.25 Nonce
1470  */
1471 static guint16
1472 de_emm_nonce(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1473              guint32 offset, guint len _U_,
1474              gchar *add_string _U_, int string_len _U_)
1475 {
1476     guint32 curr_offset;
1477
1478     curr_offset = offset;
1479
1480     proto_tree_add_item(tree, hf_nas_eps_emm_nonce, tvb, curr_offset, 4, ENC_BIG_ENDIAN);
1481     curr_offset+=4;
1482
1483     return(curr_offset-offset);
1484 }
1485 /*
1486  * 9.9.3.25A Paging identity
1487  */
1488  static const true_false_string nas_eps_emm_paging_id_vals = {
1489     "TMSI",
1490     "IMSI"
1491 };
1492
1493 static guint16
1494 de_emm_paging_id(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1495                  guint32 offset, guint len _U_,
1496                  gchar *add_string _U_, int string_len _U_)
1497 {
1498     guint32 curr_offset;
1499
1500     curr_offset = offset;
1501
1502     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, curr_offset<<3, 7, ENC_BIG_ENDIAN);
1503     proto_tree_add_bits_item(tree, hf_nas_eps_emm_paging_id, tvb, (curr_offset<<3)+7, 1, ENC_BIG_ENDIAN);
1504     /*curr_offset+=len;*/
1505
1506     return(len);
1507 }
1508 /*
1509  * 9.9.3.26 P-TMSI signature
1510  * See subclause 10.5.5.8 in 3GPP TS 24.008 [6].
1511  */
1512 /*
1513  * 9.9.3.27 Service type
1514  */
1515 static const range_string nas_eps_service_type_vals[] = {
1516     { 0,  0, "Mobile originating CS fallback or 1xCS fallback"},
1517     { 1,  1, "Mobile terminating CS fallback or 1xCS fallback"},
1518     { 2,  2, "Mobile originating CS fallback emergency call or 1xCS fallback emergency call"},
1519     { 3,  4, "Mobile originating CS fallback or 1xCS fallback"},
1520     { 8, 11, "packet services via S1"},
1521     { 0, 0, NULL }
1522 };
1523
1524 /*
1525  * 9.9.3.28 Short MAC
1526  */
1527 static guint16
1528 de_emm_nas_short_mac(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1529                      guint32 offset, guint len _U_,
1530                      gchar *add_string _U_, int string_len _U_)
1531 {
1532     guint32 curr_offset;
1533
1534     curr_offset = offset;
1535
1536
1537     proto_tree_add_item(tree, hf_nas_eps_emm_short_mac, tvb, curr_offset, 2, ENC_BIG_ENDIAN);
1538     curr_offset+=2;
1539
1540     return(curr_offset-offset);
1541 }
1542 /*
1543  * 9.9.3.29 Time zone
1544  * See subclause 10.5.3.8 in 3GPP TS 24.008 [6].
1545  */
1546 /*
1547  * 9.9.3.30 Time zone and time
1548  * See subclause 10.5.3.9 in 3GPP TS 24.008 [6].
1549  */
1550 /*
1551  * 9.9.3.31 TMSI status
1552  * See subclause 10.5.5.4 in 3GPP TS 24.008 [6].
1553  */
1554 /*
1555  * 9.9.3.32 Tracking area identity
1556  */
1557
1558 guint16
1559 de_emm_trac_area_id(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1560                     guint32 offset, guint len _U_,
1561                     gchar *add_string _U_, int string_len _U_)
1562 {
1563     guint32 curr_offset;
1564
1565     curr_offset = offset;
1566
1567     curr_offset = dissect_e212_mcc_mnc(tvb, gpinfo, tree, curr_offset, TRUE);
1568     proto_tree_add_item(tree, hf_nas_eps_emm_tai_tac, tvb, curr_offset, 2, ENC_BIG_ENDIAN);
1569     curr_offset+=2;
1570
1571     return(curr_offset-offset);
1572 }
1573 /*
1574  * 9.9.3.33 Tracking area identity list
1575  */
1576 /* Type of list (octet 1)
1577  * Bits 7 6
1578  */
1579 static const value_string nas_eps_emm_tai_tol_vals[] = {
1580     { 0,    "list of TACs belonging to one PLMN, with non-consecutive TAC values"},
1581     { 1,    "list of TACs belonging to one PLMN, with consecutive TAC values"},
1582     { 2,    "list of TAIs belonging to different PLMNs"},
1583     { 0, NULL }
1584 };
1585
1586 static guint16
1587 de_emm_trac_area_id_lst(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1588                         guint32 offset, guint len _U_,
1589                         gchar *add_string _U_, int string_len _U_)
1590 {
1591     proto_item *item;
1592     guint32 curr_offset;
1593     guint8 octet, tol, n_elem;
1594     int i;
1595
1596     curr_offset = offset;
1597
1598     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, curr_offset<<3, 1, ENC_BIG_ENDIAN);
1599     /* Type of list (octet 1) Bits 7 6 */
1600     proto_tree_add_item(tree, hf_nas_eps_emm_tai_tol, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1601     /* Number of elements (octet 1) Bits 5 4 3 2 1 */
1602     octet = tvb_get_guint8(tvb,curr_offset)& 0x7f;
1603     tol = octet >> 5;
1604     n_elem = (octet & 0x1f)+1;
1605     item = proto_tree_add_item(tree, hf_nas_eps_emm_tai_n_elem, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1606     if (n_elem<16)
1607         proto_item_append_text(item, " [+1 = %u element(s)]", n_elem);
1608
1609     curr_offset++;
1610     if (tol>2) {
1611         proto_tree_add_text(tree, tvb, curr_offset, len-(curr_offset-offset) , "Unknown type of list ( Not in 3GPP TS 24.301 version 8.1.0 Release 8 )");
1612         return len;
1613     }
1614
1615     switch (tol) {
1616         case 0:
1617             /* MCC digit 2 MCC digit 1 octet 2
1618              * MNC digit 3 MCC digit 3 octet 3
1619              * MNC digit 2 MNC digit 1 octet 4
1620              */
1621             curr_offset = dissect_e212_mcc_mnc(tvb, gpinfo, tree, curr_offset, TRUE);
1622             /* type of list = "000" */
1623             /* TAC 1             octet 5
1624              * TAC 1 (continued) octet 6
1625              * ...
1626              * ...
1627              * TAC k             octet 2k+3*
1628              * TAC k (continued) octet 2k+4*
1629              */
1630             if (len < (guint)(4+(n_elem*2))) {
1631                 proto_tree_add_text(tree, tvb, curr_offset, len-1 , "[Wrong number of elements?]");
1632                 return len;
1633             }
1634             for (i=0; i < n_elem; i++, curr_offset+=2)
1635                 proto_tree_add_item(tree, hf_nas_eps_emm_tai_tac, tvb, curr_offset, 2, ENC_BIG_ENDIAN);
1636             break;
1637         case 1:
1638
1639             /* type of list = "010" */
1640             /* MCC digit 2 MCC digit 1 octet 2
1641              * MNC digit 3 MCC digit 3 octet 3
1642              * MNC digit 2 MNC digit 1 octet 4
1643              */
1644             curr_offset = dissect_e212_mcc_mnc(tvb, gpinfo, tree, curr_offset, TRUE);
1645             proto_tree_add_item(tree, hf_nas_eps_emm_tai_tac, tvb, curr_offset, 2, ENC_BIG_ENDIAN);
1646             curr_offset+=2;
1647             break;
1648         case 2:
1649             if (len< (guint)(1+(n_elem*5))) {
1650                 proto_tree_add_text(tree, tvb, curr_offset, len-1 , "[Wrong number of elements?]");
1651                 return len;
1652             }
1653
1654             for (i=0; i < n_elem; i++) {
1655                 /* type of list = "001" */
1656                 /* MCC digit 2 MCC digit 1 octet 2
1657                  * MNC digit 3 MCC digit 3 octet 3
1658                  * MNC digit 2 MNC digit 1 octet 4
1659                  */
1660                 curr_offset = dissect_e212_mcc_mnc(tvb, gpinfo, tree, curr_offset, TRUE);
1661                 proto_tree_add_item(tree, hf_nas_eps_emm_tai_tac, tvb, curr_offset, 2, ENC_BIG_ENDIAN);
1662                 curr_offset+=2;
1663             }
1664             break;
1665         default:
1666             /* Unknown ( Not in 3GPP TS 24.301 version 8.1.0 Release 8 ) */
1667             break;
1668     }
1669     EXTRANEOUS_DATA_CHECK(len, curr_offset - offset);
1670
1671     return(curr_offset-offset);
1672 }
1673 /*
1674  * 9.9.3.34 UE network capability
1675  */
1676
1677 static const true_false_string  nas_eps_emm_supported_flg_value = {
1678     "Supported",
1679     "Not Supported"
1680 };
1681 static const true_false_string  nas_eps_emm_ucs2_supp_flg_value = {
1682     "The UE has no preference between the use of the default alphabet and the use of UCS2",
1683     "The UE has a preference for the default alphabet"
1684 };
1685 /* H.245-ASH capability (octet 7, bit 6) */
1686 static const true_false_string nas_eps_emm_h245_ash_cap_flg = {
1687     "H.245 after SRVCC handover capability supported",
1688     "H.245 after SRVCC handover capability not supported"
1689 };
1690 /* ACC-CSFB capability (octet 7, bit 5) */
1691 static const true_false_string nas_eps_emm_acc_csfb_cap_flg = {
1692     "eNodeB-based access class control for CSFB supported",
1693     "eNodeB-based access class control for CSFB not supported"
1694 };
1695 /* LPP capability (octet 7, bit 4) */
1696 static const true_false_string nas_eps_emm_lpp_cap_flg = {
1697     "LTE Positioning Protocol supported",
1698     "LTE Positioning Protocol not supported"
1699 };
1700 /* LCS capability (octet 7, bit 3) */
1701 static const true_false_string nas_eps_emm_lcs_cap_flg = {
1702     "Location services notification mechanisms supported",
1703     "Location services notification mechanisms not supported"
1704 };
1705 /* 1xSRVCC capability (octet 7, bit 2) */
1706 static const true_false_string  nas_eps_emm_1xsrvcc_cap_flg = {
1707     "SRVCC from E-UTRAN to cdma2000 1xCS supported",
1708     "SRVCC from E-UTRAN to cdma2000 1x CS not supported"
1709 };
1710 /* NF capability (octet 7, bit 1) */
1711 static const true_false_string  nas_eps_emm_nf_cap_flg = {
1712     "Notification procedure supported",
1713     "Notification procedure not supported"
1714 };
1715
1716 guint16
1717 de_emm_ue_net_cap(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1718                   guint32 offset, guint len,
1719                   gchar *add_string _U_, int string_len _U_)
1720 {
1721     guint32 curr_offset;
1722
1723     curr_offset = offset;
1724
1725
1726     /* EPS encryption algorithms supported (octet 3) */
1727     /* EPS encryption algorithm EEA0 supported (octet 3, bit 8) */
1728     proto_tree_add_item(tree, hf_nas_eps_emm_eea0, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1729     /* EPS encryption algorithm 128-EEA1 supported (octet 3, bit 7) */
1730     proto_tree_add_item(tree, hf_nas_eps_emm_128eea1, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1731     /* EPS encryption algorithm 128-EEA2 supported (octet 3, bit 6) */
1732     proto_tree_add_item(tree, hf_nas_eps_emm_128eea2, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1733     /* EPS encryption algorithm 128-EEA3 supported (octet 3, bit 5) */
1734     proto_tree_add_item(tree, hf_nas_eps_emm_eea3, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1735     /* EPS encryption algorithm EEA4 supported (octet 3, bit 4) */
1736     proto_tree_add_item(tree, hf_nas_eps_emm_eea4, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1737     /* EPS encryption algorithm EEA5 supported (octet 3, bit 3) */
1738     proto_tree_add_item(tree, hf_nas_eps_emm_eea5, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1739     /* EPS encryption algorithm EEA6 supported (octet 3, bit 2) */
1740     proto_tree_add_item(tree, hf_nas_eps_emm_eea6, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1741     /* EPS encryption algorithm EEA7 supported (octet 3, bit 1) */
1742     proto_tree_add_item(tree, hf_nas_eps_emm_eea7, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1743     curr_offset++;
1744
1745
1746     /* EPS integrity algorithms supported (octet 4) */
1747     /* EPS integrity algorithm EIA0 supported (octet 4, bit 8) */
1748     proto_tree_add_item(tree, hf_nas_eps_emm_eia0, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1749     /* EPS integrity algorithm 128-EIA1 supported (octet 4, bit 7) */
1750     proto_tree_add_item(tree, hf_nas_eps_emm_128eia1, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1751     /* EPS integrity algorithm 128-EIA2 supported (octet 4, bit 6) */
1752     proto_tree_add_item(tree, hf_nas_eps_emm_128eia2, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1753     /* EPS integrity algorithm 128-EIA3 supported (octet 4, bit 5) */
1754     proto_tree_add_item(tree, hf_nas_eps_emm_eia3, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1755     /* EPS integrity algorithm EIA4 supported (octet 4, bit 4) */
1756     proto_tree_add_item(tree, hf_nas_eps_emm_eia4, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1757     /* EPS integrity algorithm EIA5 supported (octet 4, bit 3) */
1758     proto_tree_add_item(tree, hf_nas_eps_emm_eia5, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1759     /* EPS integrity algorithm EIA6 supported (octet 4, bit 2) */
1760     proto_tree_add_item(tree, hf_nas_eps_emm_eia6, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1761     /* EPS integrity algorithm EIA7 supported (octet 4, bit 1) */
1762     proto_tree_add_item(tree, hf_nas_eps_emm_eia7, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1763     curr_offset++;
1764
1765
1766     /* Following octets are optional */
1767     if ((curr_offset - offset) >= len)
1768         return (len);
1769
1770     /* UMTS encryption algorithms supported (octet 5)
1771      * UMTS encryption algorithm UEA0 supported (octet 5, bit 8)
1772      */
1773     /* UMTS encryption algorithm 128-UEA0 supported (octet 5, bit 8) */
1774     proto_tree_add_item(tree, hf_nas_eps_emm_uea0, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1775     /* UMTS encryption algorithm 128-UEA1 supported (octet 5, bit 7) */
1776     proto_tree_add_item(tree, hf_nas_eps_emm_uea1, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1777     /* UMTS encryption algorithm 128-UEA2 supported (octet 5, bit 6) */
1778     proto_tree_add_item(tree, hf_nas_eps_emm_uea2, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1779     /* UMTS encryption algorithm 128-UEA3 supported (octet 5, bit 5) */
1780     proto_tree_add_item(tree, hf_nas_eps_emm_uea3, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1781     /* UMTS encryption algorithm 128-UEA4 supported (octet 5, bit 4) */
1782     proto_tree_add_item(tree, hf_nas_eps_emm_uea4, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1783     /* UMTS encryption algorithm 128-UEA5 supported (octet 5, bit 3) */
1784     proto_tree_add_item(tree, hf_nas_eps_emm_uea5, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1785     /* UMTS encryption algorithm 128-UEA6 supported (octet 5, bit 2) */
1786     proto_tree_add_item(tree, hf_nas_eps_emm_uea6, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1787     /* UMTS encryption algorithm 128-UEA7 supported (octet 5, bit 1) */
1788     proto_tree_add_item(tree, hf_nas_eps_emm_uea7, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1789     curr_offset++;
1790
1791     if ((curr_offset - offset) >= len)
1792         return (len);
1793
1794     /* UCS2 support (UCS2) (octet 6, bit 8)
1795      * This information field indicates the likely treatment of UCS2 encoded character strings
1796      * by the UE.
1797      */
1798     proto_tree_add_item(tree, hf_nas_eps_emm_ucs2_supp, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1799     /* UMTS integrity algorithms supported (octet 6) */
1800     /* UMTS integrity algorithm UIA1 supported (octet 6, bit 7) */
1801     proto_tree_add_item(tree, hf_nas_eps_emm_uia1, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1802     /* UMTS integrity algorithm UIA2 supported (octet 6, bit 6) */
1803     proto_tree_add_item(tree, hf_nas_eps_emm_uia2, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1804     /* UMTS integrity algorithm UIA3 supported (octet 6, bit 5) */
1805     proto_tree_add_item(tree, hf_nas_eps_emm_uia3, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1806     /* UMTS integrity algorithm UIA4 supported (octet 6, bit 4) */
1807     proto_tree_add_item(tree, hf_nas_eps_emm_uia4, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1808     /* UMTS integrity algorithm UIA5 supported (octet 6, bit 3) */
1809     proto_tree_add_item(tree, hf_nas_eps_emm_uia5, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1810     /* UMTS integrity algorithm UIA6 supported (octet 6, bit 2) */
1811     proto_tree_add_item(tree, hf_nas_eps_emm_uia6, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1812     /* UMTS integrity algorithm UIA7 supported (octet 6, bit 1) */
1813     proto_tree_add_item(tree, hf_nas_eps_emm_uia7, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1814     curr_offset++;
1815
1816     if ((curr_offset - offset) >= len)
1817         return (len);
1818
1819     /* Bits 8 to 7 of octet 7 are spare and shall be coded as zero. */
1820     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, (curr_offset<<3), 2, ENC_BIG_ENDIAN);
1821     /* H.245-ASH capability (octet 7, bit 6) */
1822     proto_tree_add_item(tree, hf_nas_eps_emm_h245_ash_cap, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1823     /* ACC-CSFB capability (octet 7, bit 5) */
1824     proto_tree_add_item(tree, hf_nas_eps_emm_acc_csfb_cap, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1825     /* LPP capability (octet 7, bit 4) */
1826     proto_tree_add_item(tree, hf_nas_eps_emm_lpp_cap, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1827     /* LCS capability (octet 7, bit 3) */
1828     proto_tree_add_item(tree, hf_nas_eps_emm_lcs_cap, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1829     /* 1xSRVCC capability (octet 7, bit 2) */
1830     proto_tree_add_item(tree, hf_nas_eps_emm_1xsrvcc_cap, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1831     /* NF capability (octet 7, bit 1) */
1832     proto_tree_add_item(tree, hf_nas_eps_emm_nf_cap, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1833     curr_offset++;
1834     
1835     while ((curr_offset - offset) < len) {
1836         proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, (curr_offset<<3), 8, ENC_BIG_ENDIAN);
1837         curr_offset++;
1838     }
1839
1840     return(len);
1841 }
1842 /* UE radio capability information update needed flag (URC upd) (octet 1) */
1843 static const true_false_string  nas_eps_emm_ue_ra_cap_inf_upd_need_flg = {
1844     "UE radio capability information update needed",
1845     "UE radio capability information update not needed"
1846 };
1847
1848 /*
1849  * 9.9.3.35 UE radio capability information update needed
1850  */
1851
1852 static guint16
1853 de_emm_ue_ra_cap_inf_upd_need(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1854                               guint32 offset, guint len _U_,
1855                               gchar *add_string _U_, int string_len _U_)
1856 {
1857     guint32 curr_offset;
1858
1859     curr_offset = offset;
1860
1861     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, (curr_offset<<3)+4, 3, ENC_BIG_ENDIAN);
1862     proto_tree_add_item(tree, hf_nas_eps_emm_ue_ra_cap_inf_upd_need_flg, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1863
1864     return(len);
1865 }
1866 /*
1867  * 9.9.3.36 UE security capability
1868  */
1869
1870 static guint16
1871 de_emm_ue_sec_cap(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
1872                   guint32 offset, guint len _U_,
1873                   gchar *add_string _U_, int string_len _U_)
1874 {
1875     guint32 curr_offset;
1876
1877     curr_offset = offset;
1878
1879     /* EPS encryption algorithms supported (octet 3) */
1880     /* EPS encryption algorithm EEA0 supported (octet 3, bit 8) */
1881     proto_tree_add_item(tree, hf_nas_eps_emm_eea0, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1882     /* EPS encryption algorithm 128-EEA1 supported (octet 3, bit 7) */
1883     proto_tree_add_item(tree, hf_nas_eps_emm_128eea1, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1884     /* EPS encryption algorithm 128-EEA2 supported (octet 3, bit 6) */
1885     proto_tree_add_item(tree, hf_nas_eps_emm_128eea2, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1886     /* EPS encryption algorithm 128-EEA3 supported (octet 3, bit 5) */
1887     proto_tree_add_item(tree, hf_nas_eps_emm_eea3, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1888     /* EPS encryption algorithm EEA4 supported (octet 3, bit 4) */
1889     proto_tree_add_item(tree, hf_nas_eps_emm_eea4, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1890     /* EPS encryption algorithm EEA5 supported (octet 3, bit 3) */
1891     proto_tree_add_item(tree, hf_nas_eps_emm_eea5, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1892     /* EPS encryption algorithm EEA6 supported (octet 3, bit 2) */
1893     proto_tree_add_item(tree, hf_nas_eps_emm_eea6, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1894     /* EPS encryption algorithm EEA7 supported (octet 3, bit 1) */
1895     proto_tree_add_item(tree, hf_nas_eps_emm_eea7, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1896     curr_offset++;
1897
1898
1899     /* EPS integrity algorithms supported (octet 4) */
1900     /* EPS integrity algorithm EIA0 supported (octet 4, bit 8) */
1901     proto_tree_add_item(tree, hf_nas_eps_emm_eia0, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1902     /* EPS integrity algorithm 128-EIA1 supported (octet 4, bit 7) */
1903     proto_tree_add_item(tree, hf_nas_eps_emm_128eia1, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1904     /* EPS integrity algorithm 128-EIA2 supported (octet 4, bit 6) */
1905     proto_tree_add_item(tree, hf_nas_eps_emm_128eia2, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1906     /* EPS integrity algorithm 128-EIA3 supported (octet 4, bit 5) */
1907     proto_tree_add_item(tree, hf_nas_eps_emm_eia3, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1908     /* EPS integrity algorithm EIA4 supported (octet 4, bit 4) */
1909     proto_tree_add_item(tree, hf_nas_eps_emm_eia4, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1910     /* EPS integrity algorithm EIA5 supported (octet 4, bit 3) */
1911     proto_tree_add_item(tree, hf_nas_eps_emm_eia5, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1912     /* EPS integrity algorithm EIA6 supported (octet 4, bit 2) */
1913     proto_tree_add_item(tree, hf_nas_eps_emm_eia6, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1914     /* EPS integrity algorithm EIA7 supported (octet 4, bit 1) */
1915     proto_tree_add_item(tree, hf_nas_eps_emm_eia7, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1916     curr_offset++;
1917
1918
1919     /* Octets 5, 6, and 7 are optional. If octet 5 is included,
1920      * then also octet 6 shall be included and octet 7 may be included.
1921      */
1922     if (len == 2)
1923         return(len);
1924
1925     /* UMTS encryption algorithms supported (octet 5) */
1926     /* UMTS encryption algorithm UEA0 supported (octet 5, bit 8) */
1927     proto_tree_add_item(tree, hf_nas_eps_emm_uea0, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1928     /* UMTS encryption algorithm UEA1 supported (octet 5, bit 7) */
1929     proto_tree_add_item(tree, hf_nas_eps_emm_uea1, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1930     /* UMTS encryption algorithm UEA2 supported (octet 5, bit 6) */
1931     proto_tree_add_item(tree, hf_nas_eps_emm_uea2, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1932     /* UMTS encryption algorithm UEA3 supported (octet 5, bit 5) */
1933     proto_tree_add_item(tree, hf_nas_eps_emm_uea3, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1934     /* UMTS encryption algorithm UEA4 supported (octet 5, bit 4) */
1935     proto_tree_add_item(tree, hf_nas_eps_emm_uea4, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1936     /* UMTS encryption algorithm UEA5 supported (octet 5, bit 3) */
1937     proto_tree_add_item(tree, hf_nas_eps_emm_uea5, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1938     /* UMTS encryption algorithm UEA6 supported (octet 5, bit 2) */
1939     proto_tree_add_item(tree, hf_nas_eps_emm_uea6, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1940     /* UMTS encryption algorithm UEA7 supported (octet 5, bit 1) */
1941     proto_tree_add_item(tree, hf_nas_eps_emm_uea7, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1942     curr_offset++;
1943
1944     /* UMTS integrity algorithms supported (octet 6) */
1945     /* Bit 8 of octet 6 is spare and shall be coded as zero. */
1946     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, (curr_offset<<3), 1, ENC_BIG_ENDIAN);
1947     /* UMTS integrity algorithm UIA1 supported (octet 6, bit 7) */
1948     proto_tree_add_item(tree, hf_nas_eps_emm_uia1, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1949     /* UMTS integrity algorithm UIA2 supported (octet 6, bit 6) */
1950     proto_tree_add_item(tree, hf_nas_eps_emm_uia2, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1951     /* UMTS integrity algorithm UIA3 supported (octet 6, bit 5) */
1952     proto_tree_add_item(tree, hf_nas_eps_emm_uia3, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1953     /* UMTS integrity algorithm UIA4 supported (octet 6, bit 4) */
1954     proto_tree_add_item(tree, hf_nas_eps_emm_uia4, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1955     /* UMTS integrity algorithm UIA5 supported (octet 6, bit 3) */
1956     proto_tree_add_item(tree, hf_nas_eps_emm_uia5, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1957     /* UMTS integrity algorithm UIA6 supported (octet 6, bit 2) */
1958     proto_tree_add_item(tree, hf_nas_eps_emm_uia6, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1959     /* UMTS integrity algorithm UIA7 supported (octet 6, bit 1) */
1960     proto_tree_add_item(tree, hf_nas_eps_emm_uia7, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1961     curr_offset++;
1962
1963     if (len == 4)
1964         return(len);
1965
1966     /* Bit 8 of octet 7 is spare and shall be coded as zero. */
1967     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, (curr_offset<<3), 1, ENC_BIG_ENDIAN);
1968     /* GPRS encryption algorithm GEA1 supported (octet 7, bit 7) */
1969     proto_tree_add_item(tree, hf_nas_eps_emm_gea1, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1970     /* GPRS encryption algorithm GEA2 supported (octet 7, bit 6) */
1971     proto_tree_add_item(tree, hf_nas_eps_emm_gea2, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1972     /* GPRS encryption algorithm GEA3 supported (octet 7, bit 5) */
1973     proto_tree_add_item(tree, hf_nas_eps_emm_gea3, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1974     /* GPRS encryption algorithm GEA4 supported (octet 7, bit 4) */
1975     proto_tree_add_item(tree, hf_nas_eps_emm_gea4, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1976     /* GPRS encryption algorithm GEA5 supported (octet 7, bit 3) */
1977     proto_tree_add_item(tree, hf_nas_eps_emm_gea5, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1978     /* GPRS encryption algorithm GEA6 supported (octet 7, bit 2) */
1979     proto_tree_add_item(tree, hf_nas_eps_emm_gea6, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1980     /* GPRS encryption algorithm GEA7 supported (octet 7, bit 1) */
1981     proto_tree_add_item(tree, hf_nas_eps_emm_gea7, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
1982     curr_offset++;
1983
1984     return(len);
1985 }
1986 /*
1987  * 9.9.3.37 Emergency Number List
1988  * See subclause 10.5.3.13 in 3GPP TS 24.008 [13].
1989  * packet-gsm_a_dtap.c
1990  */
1991
1992 /*
1993  * 9.9.3.38 CLI
1994  */
1995
1996 /*
1997  * The coding of the CLI value part is the same as for octets 3 to 14
1998  * of the Calling party BCD number information element defined in
1999  * subclause 10.5.4.9 of 3GPP TS 24.008
2000  */
2001
2002 /*
2003  * 9.9.3.39 SS Code
2004  */
2005 static guint16
2006 de_emm_ss_code(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
2007                guint32 offset, guint len _U_,
2008                gchar *add_string _U_, int string_len _U_)
2009 {
2010     guint32 curr_offset;
2011
2012     curr_offset = offset;
2013
2014     /*
2015      * SS Code value
2016      * The coding of the SS Code value is given in subclause 17.7.5 of 3GPP TS 29.002 [15B].
2017      * value string imported from gsm map
2018      */
2019     proto_tree_add_item(tree, hf_nas_eps_emm_ss_code, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
2020
2021     return(len);
2022 }
2023
2024 /*
2025  * 9.9.3.40 LCS indicator
2026  */
2027 /* LCS indicator value */
2028 static const value_string nas_eps_emm_lcs_ind_vals[] = {
2029     { 0,    "Normal, unspecified"},
2030     { 1,    "MT-LR"},
2031     { 0, NULL }
2032 };
2033
2034
2035 static guint16
2036 de_emm_lcs_ind(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
2037                guint32 offset, guint len _U_,
2038                gchar *add_string _U_, int string_len _U_)
2039 {
2040     guint32 curr_offset;
2041
2042     curr_offset = offset;
2043
2044
2045     proto_tree_add_item(tree, hf_nas_eps_emm_lcs_ind, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
2046
2047     return(len);
2048 }
2049 /*
2050  * 9.9.3.41 LCS client identity
2051  */
2052 static guint16
2053 de_emm_lcs_client_id(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
2054                      guint32 offset, guint len _U_,
2055                      gchar *add_string _U_, int string_len _U_)
2056 {
2057     guint32   curr_offset;
2058     tvbuff_t *new_tvb;
2059
2060     curr_offset = offset;
2061
2062     /* LCS client identity (value part)
2063      * The coding of the value part of the LCS client identity is given
2064      * in subclause 17.7.13 of 3GPP TS 29.002 [15B](GSM MAP).
2065      */
2066     new_tvb = tvb_new_subset(tvb, curr_offset, len, len );
2067     dissect_gsm_map_lcs_LCS_ClientID_PDU( new_tvb, gpinfo, tree, NULL );
2068
2069     return(len);
2070 }
2071
2072 /*
2073  * 9.9.3.42 Generic message container type
2074  */
2075 static const range_string nas_eps_emm_gen_msg_cont_type_vals[] = {
2076     {   0,   0, "Reserved"},
2077     {   1,   1, "LTE Positioning Protocol (LPP) message container"},
2078     {   2,   2, "Location services message container"},
2079     {   3, 127, "Unused"},
2080     { 128, 255, "Reserved"},
2081     { 0, 0, NULL }
2082 };
2083
2084 static guint16
2085 de_emm_gen_msg_cont_type(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
2086                          guint32 offset, guint len _U_,
2087                          gchar *add_string _U_, int string_len _U_)
2088 {
2089     guint32 curr_offset;
2090
2091     curr_offset = offset;
2092
2093     eps_nas_gen_msg_cont_type = tvb_get_guint8(tvb, curr_offset);
2094     proto_tree_add_item(tree, hf_nas_eps_emm_gen_msg_cont_type, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
2095     curr_offset++;
2096
2097     return(curr_offset - offset);
2098 }
2099 /*
2100  * 9.9.3.43 Generic message container
2101  */
2102 static guint16
2103 de_emm_gen_msg_cont(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo,
2104                     guint32 offset, guint len,
2105                     gchar *add_string _U_, int string_len _U_)
2106 {
2107     proto_item *item;
2108     proto_tree *sub_tree;
2109     tvbuff_t   *new_tvb;
2110
2111     item = proto_tree_add_item(tree, hf_nas_eps_gen_msg_cont, tvb, offset, len, ENC_NA);
2112     sub_tree = proto_item_add_subtree(item, ett_nas_eps_gen_msg_cont);
2113
2114     new_tvb = tvb_new_subset(tvb, offset, len, len);
2115
2116     switch (eps_nas_gen_msg_cont_type) {
2117         case 1:
2118             /* LPP */
2119             if (lpp_handle) {
2120                 call_dissector(lpp_handle, new_tvb, pinfo, sub_tree);
2121             }
2122             break;
2123         case 2:
2124             /* Location services */
2125             if (gsm_a_dtap_handle) {
2126                 call_dissector(gsm_a_dtap_handle, new_tvb, pinfo, sub_tree);
2127             }
2128             break;
2129         default:
2130             break;
2131     }
2132
2133     return(len);
2134 }
2135 /*
2136  * 9.9.3.44 Voice domain preference and UE's usage setting
2137  * See subclause 10.5.5.28 in 3GPP TS 24.008 [13].
2138  * packet-gsm_a_dtap.c
2139  */
2140 /*
2141  * 9.9.3.45 GUTI type
2142  */
2143 static const true_false_string nas_eps_emm_guti_type_value = {
2144     "Mapped GUTI",
2145     "Native GUTI"
2146 };
2147
2148 static guint16
2149 de_emm_guti_type(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
2150                  guint32 offset, guint len _U_,
2151                  gchar *add_string _U_, int string_len _U_)
2152 {
2153     guint32 curr_offset, bit_offset;
2154
2155     curr_offset = offset;
2156     bit_offset  = (curr_offset<<3)+4;
2157
2158     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
2159     bit_offset += 3;
2160     proto_tree_add_bits_item(tree, hf_nas_eps_emm_guti_type, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
2161     curr_offset++;
2162
2163     return (curr_offset - offset);
2164 }
2165
2166  /*
2167  * 9.9.4    EPS Session Management (ESM) information elements
2168  */
2169
2170 /*
2171  * 9.9.4.1 Access point name
2172  * See subclause 10.5.6.1 in 3GPP TS 24.008 [6].
2173  */
2174 /*
2175  * 9.9.4.2 APN aggregate maximum bit rate
2176  */
2177
2178 static guint16
2179 de_esm_apn_aggr_max_br(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
2180                        guint32 offset, guint len _U_,
2181                        gchar *add_string _U_, int string_len _U_)
2182 {
2183     guint32 curr_offset;
2184     guint8  octet;
2185     guint32 dl_total = 0;
2186     guint32 ul_total = 0;
2187     guint32 bitrate  = 0;
2188
2189     curr_offset = offset;
2190     /* APN-AMBR for downlink    octet 3 */
2191     octet = tvb_get_guint8(tvb,curr_offset);
2192     if (octet == 0) {
2193         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_dl, tvb, curr_offset, 1, octet,
2194                        "Reserved");
2195     } else {
2196         bitrate = calc_bitrate(octet);
2197         dl_total += bitrate;
2198         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_dl, tvb, curr_offset, 1, octet,
2199                        "APN-AMBR for downlink : %u kbps", bitrate);
2200     }
2201     curr_offset++;
2202
2203     /* APN-AMBR for uplink  octet 4 */
2204     octet = tvb_get_guint8(tvb,curr_offset);
2205     if (octet == 0) {
2206         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_ul, tvb, curr_offset, 1, octet,
2207                        "Reserved");
2208     } else {
2209         bitrate = calc_bitrate(octet);
2210         ul_total += bitrate;
2211         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_ul, tvb, curr_offset, 1, octet,
2212                        "APN-AMBR for uplink : %u kbps", bitrate);
2213     }
2214     curr_offset++;
2215     if ((curr_offset - offset) >= len)
2216         return(len);
2217     /* APN-AMBR for downlink (extended) octet 5 */
2218     octet = tvb_get_guint8(tvb,curr_offset);
2219     if (octet == 0) {
2220         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_dl_ext, tvb, curr_offset, 1, octet,
2221                        "Use the value indicated by the APN-AMBR for downlink");
2222     } else {
2223         bitrate = calc_bitrate_ext(octet);
2224         dl_total += (octet > 0x4a) ? bitrate*1000 : bitrate;
2225         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_dl_ext, tvb, curr_offset, 1, octet,
2226                        "APN-AMBR for downlink (extended) : %u %s",
2227                        bitrate,
2228                        (octet > 0x4a) ? "Mbps" : "kbps");
2229     }
2230     if (len < 5) {
2231         /* APN-AMBR for downlink (extended-2) is not present; display total now */
2232         if (octet != 0) {
2233             /* Ignore value indicated by the APN-AMBR for downlink */
2234             dl_total = (octet > 0x4a) ? bitrate*1000 : bitrate;
2235         }
2236         if (dl_total >= 1000) {
2237             proto_tree_add_text(tree, tvb, curr_offset, 1,"Total APN-AMBR for downlink : %.3f Mbps", (gfloat)dl_total / 1000);
2238             } else {
2239             proto_tree_add_text(tree, tvb, curr_offset, 1,"Total APN-AMBR for downlink : %u kbps", dl_total);
2240         }
2241     }
2242     curr_offset++;
2243     if ((curr_offset - offset) >= len)
2244         return(len);
2245     /* APN-AMBR for uplink (extended)   octet 6 */
2246     octet = tvb_get_guint8(tvb,curr_offset);
2247     if (octet == 0) {
2248         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_ul_ext, tvb, curr_offset, 1, octet,
2249                        "Use the value indicated by the APN-AMBR for uplink");
2250     } else {
2251         bitrate = calc_bitrate_ext(octet);
2252         ul_total += (octet > 0x4a) ? bitrate*1000 : bitrate;
2253         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_ul_ext, tvb, curr_offset, 1, octet,
2254                        "APN-AMBR for uplink (extended) : %u %s",
2255                        bitrate,
2256                        (octet > 0x4a) ? "Mbps" : "kbps");
2257     }
2258     if (len < 6) {
2259         /* APN-AMBR for uplink (extended-2) is not present; display total now */
2260         if (octet != 0) {
2261             /* Ignore value indicated by the APN-AMBR for uplink */
2262             ul_total = (octet > 0x4a) ? bitrate*1000 : bitrate;
2263         }
2264         if (ul_total >= 1000) {
2265             proto_tree_add_text(tree, tvb, curr_offset, 1,"Total APN-AMBR for uplink : %.3f Mbps", (gfloat)ul_total / 1000);
2266             } else {
2267             proto_tree_add_text(tree, tvb, curr_offset, 1,"Total APN-AMBR for uplink : %u kbps", ul_total);
2268         }
2269     }
2270     curr_offset++;
2271     if ((curr_offset - offset) >= len)
2272         return(len);
2273     /* APN-AMBR for downlink (extended-2)   octet 7 */
2274     octet = tvb_get_guint8(tvb,curr_offset);
2275     if ((octet == 0)||(octet == 0xff)) {
2276         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_dl_ext2, tvb, curr_offset, 1, octet,
2277                        "Use the value indicated by the APN-AMBR for downlink and APN-AMBR for downlink (extended)");
2278     } else {
2279         dl_total += octet*256*1000;
2280         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_dl_ext2, tvb, curr_offset, 1, octet,
2281                        "APN-AMBR for downlink (extended-2) : %u Mbps",
2282                        (octet* 256));
2283     }
2284     proto_tree_add_text(tree, tvb, curr_offset, 1,"Total APN-AMBR for downlink : %.3f Mbps", (gfloat)dl_total / 1000);
2285     curr_offset++;
2286     if ((curr_offset - offset) >= len)
2287         return(len);
2288     /* APN-AMBR for uplink (extended-2) octet 8 */
2289     octet = tvb_get_guint8(tvb,curr_offset);
2290     if ((octet == 0)||(octet == 0xff)) {
2291         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_ul_ext2, tvb, curr_offset, 1, octet,
2292                        "Use the value indicated by the APN-AMBR for uplink and APN-AMBR for uplink (extended)");
2293     } else {
2294         ul_total += octet*256*1000;
2295         proto_tree_add_uint_format(tree, hf_nas_eps_emm_apn_ambr_ul_ext2, tvb, curr_offset, 1, octet,
2296                        "APN-AMBR for uplink (extended-2) : %u Mbps",
2297                        (octet* 256));
2298     }
2299     proto_tree_add_text(tree, tvb, curr_offset, 1,"Total APN-AMBR for uplink : %.3f Mbps", (gfloat)ul_total / 1000);
2300     curr_offset++;
2301
2302     return(len);
2303 }
2304 /*
2305  * 9.9.4.2A Connectivity type
2306  * See subclause 10.5.6.19 in 3GPP TS 24.008.
2307  * packet-gsm_a_gm.c
2308  */
2309 /*
2310  * 9.9.4.3 EPS quality of service
2311  */
2312
2313 /* Quality of Service Class Identifier (QCI), octet 3 (see 3GPP TS 23.203 [7]) */
2314 static const range_string nas_eps_qci_vals[] = {
2315     { 0x00, 0x00, "UE -> NW Network selects the QCI / NW -> UE Reserved"},
2316     { 0x01, 0x01, "QCI 1"},
2317     { 0x02, 0x02, "QCI 2"},
2318     { 0x03, 0x03, "QCI 3"},
2319     { 0x04, 0x04, "QCI 4"},
2320     { 0x05, 0x05, "QCI 5"},
2321     { 0x06, 0x06, "QCI 6"},
2322     { 0x07, 0x07, "QCI 7"},
2323     { 0x08, 0x08, "QCI 8"},
2324     { 0x09, 0x09, "QCI 9"},
2325     { 0x0A, 0x7F, "Reserved"},
2326     { 0x80, 0xFE, "Operator-specific QCI"},
2327     { 0xFF, 0xFF, "Reserved"},
2328     { 0,    0,    NULL }
2329 };
2330
2331
2332
2333 guint16
2334 de_esm_qos(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
2335            guint32 offset, guint len,
2336            gchar *add_string _U_, int string_len _U_)
2337 {
2338     guint32 curr_offset;
2339     guint8  octet;
2340
2341     curr_offset = offset;
2342
2343     /* QCI octet 3 */
2344     proto_tree_add_item(tree, hf_nas_eps_qci, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
2345     curr_offset++;
2346     if ((curr_offset - offset) >= len)
2347         return(len);
2348     /* Maximum bit rate for uplink octet 4 */
2349     octet = tvb_get_guint8(tvb,curr_offset);
2350     if (octet == 0) {
2351         proto_tree_add_uint_format(tree, hf_nas_eps_mbr_ul, tvb, curr_offset, 1, octet,
2352                        "UE->NW Subscribed maximum bit rate for uplink/ NW->UE Reserved");
2353     } else {
2354         proto_tree_add_uint_format(tree, hf_nas_eps_mbr_ul, tvb, curr_offset, 1, octet,
2355                        "Maximum bit rate for uplink : %u kbps", calc_bitrate(octet));
2356     }
2357     curr_offset++;
2358     if ((curr_offset - offset) >= len)
2359         return(len);
2360     /* Maximum bit rate for downlink octet 5 */
2361     octet = tvb_get_guint8(tvb,curr_offset);
2362     if (octet == 0) {
2363         proto_tree_add_uint_format(tree, hf_nas_eps_mbr_dl, tvb, curr_offset, 1, octet,
2364                        "UE->NW Subscribed maximum bit rate for downlink/ NW->UE Reserved");
2365     } else {
2366         proto_tree_add_uint_format(tree, hf_nas_eps_mbr_dl, tvb, curr_offset, 1, octet,
2367                        "Maximum bit rate for downlink : %u kbps", calc_bitrate(octet));
2368     }
2369     curr_offset++;
2370     if ((curr_offset - offset) >= len)
2371         return(len);
2372     /* Guaranteed bit rate for uplink octet 6 */
2373     octet = tvb_get_guint8(tvb,curr_offset);
2374     proto_tree_add_uint_format(tree, hf_nas_eps_gbr_ul, tvb, curr_offset, 1, octet,
2375                    "Guaranteed bit rate for uplink : %u kbps", calc_bitrate(octet));
2376
2377     curr_offset++;
2378     if ((curr_offset - offset) >= len)
2379         return(len);
2380     /* Guaranteed bit rate for downlink octet 7 */
2381     octet = tvb_get_guint8(tvb,curr_offset);
2382     proto_tree_add_uint_format(tree, hf_nas_eps_gbr_dl, tvb, curr_offset, 1, octet,
2383                    "Guaranteed bit rate for downlink : %u kbps", calc_bitrate(octet));
2384
2385     curr_offset++;
2386     if ((curr_offset - offset) >= len)
2387         return(len);
2388     /* Maximum bit rate for uplink (extended) octet 8 */
2389     octet = tvb_get_guint8(tvb,curr_offset);
2390     if (octet == 0) {
2391         proto_tree_add_uint_format(tree, hf_nas_eps_embr_ul, tvb, curr_offset, 1, octet,
2392                        "Use the value indicated by the maximum bit rate for uplink in octet 4");
2393     } else {
2394         proto_tree_add_uint_format(tree, hf_nas_eps_embr_ul, tvb, curr_offset, 1, octet,
2395                        "Maximum bit rate for uplink (extended) : %u %s",
2396                        calc_bitrate_ext(octet),
2397                        (octet > 0x4a) ? "Mbps" : "kbps");
2398     }
2399     curr_offset++;
2400     if ((curr_offset - offset) >= len)
2401         return(len);
2402     /* Maximum bit rate for downlink (extended) octet 9 */
2403     octet = tvb_get_guint8(tvb,curr_offset);
2404     if (octet == 0) {
2405         proto_tree_add_uint_format(tree, hf_nas_eps_embr_dl, tvb, curr_offset, 1, octet,
2406                        "Use the value indicated by the maximum bit rate for downlink in octet 5");
2407     } else {
2408         proto_tree_add_uint_format(tree, hf_nas_eps_embr_dl, tvb, curr_offset, 1, octet,
2409                        "Maximum bit rate for downlink (extended) : %u %s",
2410                        calc_bitrate_ext(octet),
2411                        (octet > 0x4a) ? "Mbps" : "kbps");
2412     }
2413     curr_offset++;
2414     if ((curr_offset - offset) >= len)
2415         return(len);
2416     /* Guaranteed bit rate for uplink (extended) octet 10 */
2417     octet = tvb_get_guint8(tvb,curr_offset);
2418     if (octet == 0) {
2419         proto_tree_add_uint_format(tree, hf_nas_eps_egbr_ul, tvb, curr_offset, 1, octet,
2420                        "Use the value indicated by the guaranteed bit rate for uplink in octet 6");
2421     } else {
2422         proto_tree_add_uint_format(tree, hf_nas_eps_egbr_ul, tvb, curr_offset, 1, octet,
2423                        "Guaranteed bit rate for uplink (extended) : %u %s",
2424                        calc_bitrate_ext(octet),
2425                        (octet > 0x4a) ? "Mbps" : "kbps");
2426     }
2427     curr_offset++;
2428     if ((curr_offset - offset) >= len)
2429         return(len);
2430     /* Guaranteed bit rate for downlink (extended) octet 11 */
2431     octet = tvb_get_guint8(tvb,curr_offset);
2432     if (octet == 0) {
2433         proto_tree_add_uint_format(tree, hf_nas_eps_egbr_dl, tvb, curr_offset, 1, octet,
2434                        "Use the value indicated by the guaranteed bit rate for downlink in octet 7");
2435     } else {
2436         proto_tree_add_uint_format(tree, hf_nas_eps_egbr_dl, tvb, curr_offset, 1, octet,
2437                        "Guaranteed bit rate for downlink (extended) : %u %s",
2438                        calc_bitrate_ext(octet),
2439                        (octet > 0x4a) ? "Mbps" : "kbps");
2440     }
2441     curr_offset++;
2442     if ((curr_offset - offset) >= len)
2443         return(len);
2444     /* Maximum bit rate for uplink (extended-2) octet 12 */
2445     octet = tvb_get_guint8(tvb,curr_offset);
2446     if (octet == 0) {
2447         proto_tree_add_uint_format(tree, hf_nas_eps_embr_ul, tvb, curr_offset, 1, octet,
2448                        "Use the value indicated by the maximum bit rate for uplink in octet 4 and octet 8");
2449     } else {
2450         proto_tree_add_uint_format(tree, hf_nas_eps_embr_ul, tvb, curr_offset, 1, octet,
2451                        "Maximum bit rate for uplink (extended-2) : %u Mbps",
2452                        calc_bitrate_ext2(octet));
2453     }
2454     curr_offset++;
2455     /* Maximum bit rate for downlink (extended-2) octet 13 */
2456     octet = tvb_get_guint8(tvb,curr_offset);
2457     if (octet == 0) {
2458         proto_tree_add_uint_format(tree, hf_nas_eps_embr_dl, tvb, curr_offset, 1, octet,
2459                        "Use the value indicated by the maximum bit rate for downlink in octet 5 and octet 9");
2460     } else {
2461         proto_tree_add_uint_format(tree, hf_nas_eps_embr_dl, tvb, curr_offset, 1, octet,
2462                        "Maximum bit rate for downlink (extended-2) : %u Mbps",
2463                        calc_bitrate_ext2(octet));
2464     }
2465     curr_offset++;
2466     /* Guaranteed bit rate for uplink (extended-2) octet 14 */
2467     octet = tvb_get_guint8(tvb,curr_offset);
2468     if (octet == 0) {
2469         proto_tree_add_uint_format(tree, hf_nas_eps_egbr_ul, tvb, curr_offset, 1, octet,
2470                        "Use the value indicated by the guaranted bit rate for uplink in octet 6 and octet 10");
2471     } else {
2472         proto_tree_add_uint_format(tree, hf_nas_eps_egbr_ul, tvb, curr_offset, 1, octet,
2473                        "Guaranteed bit rate for uplink (extended-2) : %u Mbps",
2474                        calc_bitrate_ext2(octet));
2475     }
2476     curr_offset++;
2477     /* Guaranted bit rate for downlink (extended-2) octet 15 */
2478     octet = tvb_get_guint8(tvb,curr_offset);
2479     if (octet == 0) {
2480         proto_tree_add_uint_format(tree, hf_nas_eps_egbr_dl, tvb, curr_offset, 1, octet,
2481                        "Use the value indicated by the guaranteed bit rate for downlink in octet 7 and octet 11");
2482     } else {
2483         proto_tree_add_uint_format(tree, hf_nas_eps_egbr_dl, tvb, curr_offset, 1, octet,
2484                        "Guaranteed bit rate for downlink (extended-2) : %u Mbps",
2485                        calc_bitrate_ext2(octet));
2486     }
2487
2488     return(len);
2489 }
2490 /*
2491  * 9.9.4.4 ESM cause
2492  */
2493
2494 static const value_string nas_eps_esm_cause_vals[] = {
2495     { 0x08, "Operator Determined Barring"},
2496     { 0x1a, "Insufficient resources"},
2497     { 0x1b, "Missing or unknown APN"},
2498     { 0x1c, "Unknown PDN type"},
2499     { 0x1d, "User authentication failed"},
2500     { 0x1e, "Request rejected by Serving GW or PDN GW"},
2501     { 0x1f, "Request rejected, unspecified"},
2502     { 0x20, "Service option not supported"},
2503     { 0x21, "Requested service option not subscribed"},
2504     { 0x22, "Service option temporarily out of order"},
2505     { 0x23, "PTI already in use"},
2506     { 0x24, "Regular deactivation"},
2507     { 0x25, "EPS QoS not accepted"},
2508     { 0x26, "Network failure"},
2509     { 0x27, "Reactivation requested"},
2510     { 0x29, "Semantic error in the TFT operation"},
2511     { 0x2a, "Syntactical error in the TFT operation"},
2512     { 0x2b, "Invalid EPS bearer identity"},
2513     { 0x2c, "Semantic errors in packet filter(s)"},
2514     { 0x2d, "Syntactical errors in packet filter(s)"},
2515     { 0x2e, "Unused"},
2516     { 0x2f, "PTI mismatch"},
2517     { 0x31, "Last PDN disconnection not allowed"},
2518     { 0x32, "PDN type IPv4 only allowed"},
2519     { 0x33, "PDN type IPv6 only allowed"},
2520     { 0x34, "Single address bearers only allowed"},
2521     { 0x35, "ESM information not received"},
2522     { 0x36, "PDN connection does not exist"},
2523     { 0x37, "Multiple PDN connections for a given APN not allowed"},
2524     { 0x38, "Collision with network initiated request"},
2525     { 0x3b, "Unsupported QCI value"},
2526     { 0x3c, "Bearer handling not supported"},
2527     { 0x41, "Maximum number of EPS bearers reached"},
2528     { 0x42, "Requested APN not supported in current RAT and PLMN combination"},
2529     { 0x51, "Invalid PTI value"},
2530     { 0x5f, "Semantically incorrect message"},
2531     { 0x60, "Invalid mandatory information"},
2532     { 0x61, "Message type non-existent or not implemented"},
2533     { 0x62, "Message type not compatible with the protocol state"},
2534     { 0x63, "Information element non-existent or not implemented"},
2535     { 0x64, "Conditional IE error"},
2536     { 0x65, "Message not compatible with the protocol state"},
2537     { 0x6f, "Protocol error, unspecified"},
2538     { 0x70, "APN restriction value incompatible with active EPS bearer context"},
2539     { 0, NULL }
2540 };
2541 static value_string_ext nas_eps_esm_cause_vals_ext = VALUE_STRING_EXT_INIT(nas_eps_esm_cause_vals);
2542
2543 static guint16
2544 de_esm_cause(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
2545              guint32 offset, guint len _U_,
2546              gchar *add_string _U_, int string_len _U_)
2547 {
2548     guint32 curr_offset;
2549
2550     curr_offset = offset;
2551
2552     proto_tree_add_item(tree, hf_nas_eps_esm_cause, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
2553     curr_offset++;
2554
2555     return(curr_offset - offset);
2556 }
2557 /*
2558  * 9.9.4.5 ESM information transfer flag
2559  */
2560 /* EIT (ESM information transfer) */
2561 static const true_false_string  nas_eps_emm_eit_vals = {
2562     "Security protected ESM information transfer required",
2563     "Security protected ESM information transfer not required"
2564 };
2565 static guint16
2566 de_esm_inf_trf_flg(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
2567                    guint32 offset, guint len _U_,
2568                    gchar *add_string _U_, int string_len _U_)
2569 {
2570     guint32 curr_offset;
2571
2572     curr_offset = offset;
2573
2574
2575     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, (curr_offset<<3)+4, 3, ENC_BIG_ENDIAN);
2576     proto_tree_add_item(tree, hf_nas_eps_esm_eit, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
2577     curr_offset++;
2578     return(curr_offset-offset);
2579 }
2580 /*
2581  * 9.9.4.6 Linked EPS bearer identity
2582  */
2583 /*
2584  * Linked EPS bearer identity (bits 1-4)
2585  */
2586
2587 static const value_string nas_eps_esm_linked_bearer_id_vals[] = {
2588     { 0x0,  "Reserved"},
2589     { 0x1,  "Reserved"},
2590     { 0x2,  "Reserved"},
2591     { 0x3,  "Reserved"},
2592     { 0x4,  "Reserved"},
2593     { 0x5,  "EPS bearer identity value 5"},
2594     { 0x6,  "EPS bearer identity value 6"},
2595     { 0x7,  "EPS bearer identity value 7"},
2596     { 0x8,  "EPS bearer identity value 8"},
2597     { 0x9,  "EPS bearer identity value 9"},
2598     { 0xa,  "EPS bearer identity value 10"},
2599     { 0xb,  "EPS bearer identity value 11"},
2600     { 0xc,  "EPS bearer identity value 12"},
2601     { 0xd,  "EPS bearer identity value 13"},
2602     { 0xe,  "EPS bearer identity value 14"},
2603     { 0xf,  "EPS bearer identity value 15"},
2604     { 0, NULL }
2605 };
2606
2607 /*
2608  * 9.9.4.7 LLC service access point identifier
2609  * See subclause 10.5.6.9 in 3GPP TS 24.008
2610  */
2611
2612 /*
2613  * 9.9.4.7a Notification indicator
2614  */
2615 static const value_string nas_eps_esm_notif_ind_vals[] = {
2616     { 0x0,  "Reserved"},
2617     { 0x1,  "SRVCC handover cancelled, IMS session re-establishment required"},
2618     { 0, NULL }
2619 };
2620
2621 static guint16
2622 de_esm_notif_ind(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
2623                  guint32 offset, guint len _U_,
2624                  gchar *add_string _U_, int string_len _U_)
2625 {
2626     guint32 curr_offset;
2627
2628     curr_offset = offset;
2629
2630     proto_tree_add_item(tree, hf_nas_eps_esm_notif_ind, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
2631
2632     return(len);
2633 }
2634
2635 /*
2636  * 9.9.4.8 Packet flow identifier
2637  * See subclause 10.5.6.11 in 3GPP TS 24.008
2638  */
2639 /*
2640  * 9.9.4.9 PDN address
2641  */
2642 static guint16
2643 de_esm_pdn_addr(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
2644                 guint32 offset, guint len _U_,
2645                 gchar *add_string _U_, int string_len _U_)
2646 {
2647     guint32 curr_offset;
2648     guint8  pdn_type;
2649
2650     curr_offset = offset;
2651
2652
2653     pdn_type  = tvb_get_guint8(tvb, offset) & 0x7;
2654     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, curr_offset<<3, 5, ENC_BIG_ENDIAN);
2655     proto_tree_add_item(tree, hf_nas_eps_esm_pdn_type, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
2656     curr_offset++;
2657
2658     switch (pdn_type) {
2659         case 1:
2660             /* IPv4 */
2661             proto_tree_add_item(tree, hf_nas_eps_esm_pdn_ipv4, tvb, curr_offset, 4, ENC_BIG_ENDIAN);
2662             curr_offset+=4;
2663             break;
2664         case 2:
2665             /* IPv6 3GPP TS 24.301 version 9.4.0 Release 9
2666              * If PDN type value indicates IPv6, the PDN address information in octet 4 to octet 11
2667              * contains an IPv6 interface identifier. Bit 8 of octet 4 represents the most significant bit
2668              * of the IPv6 interface identifier and bit 1 of octet 11 the least significant bit.
2669              */
2670             proto_tree_add_item(tree, hf_nas_eps_esm_pdn_ipv6_if_id, tvb, curr_offset, 8, ENC_NA);
2671             curr_offset+=8;
2672             break;
2673         case 3:
2674             /* IPv4/IPv6 3GPP TS 24.301 version 9.4.0 Release 9
2675              * If PDN type value indicates IPv4v6, the PDN address information in octet 4 to octet 15
2676              * contains an IPv6 interface identifier and an IPv4 address. Bit 8 of octet 4 represents
2677              * the most significant bit of the IPv6 interface identifier and bit 1 of octet 11 the least
2678              * significant bit. Bit 8 of octet 12 represents the most significant bit of the IPv4 address
2679              * and bit 1 of octet 15 the least significant bit.
2680              */
2681             proto_tree_add_item(tree, hf_nas_eps_esm_pdn_ipv6_if_id, tvb, curr_offset, 8, ENC_NA);
2682             curr_offset+=8;
2683             proto_tree_add_item(tree, hf_nas_eps_esm_pdn_ipv4, tvb, curr_offset, 4, ENC_BIG_ENDIAN);
2684             curr_offset+=4;
2685             break;
2686         default:
2687             break;
2688     }
2689
2690     return(curr_offset-offset);
2691 }
2692
2693 /*
2694  * 9.9.4.10 PDN type
2695  * Coded inline 1/2 octet
2696  */
2697 static const value_string nas_eps_esm_pdn_type_values[] = {
2698     { 0x1,  "IPv4" },
2699     { 0x2,  "IPv6" },
2700     { 0x3,  "IPv4v6" },
2701     { 0x4,  "Unused; shall be interpreted as IPv6 if received by the network" },
2702     { 0, NULL }
2703 };
2704
2705 /*
2706  * 9.9.4.11 Protocol configuration options
2707  * See subclause 10.5.6.3 in 3GPP TS 24.008
2708  */
2709 /*
2710  * 9.9.4.12 Quality of service
2711  * See subclause 10.5.6.5 in 3GPP TS 24.008
2712  * Coded inline 1/2 octet
2713  */
2714 /*
2715  * 9.9.4.13 Radio priority
2716  * See subclause 10.5.7.2 in 3GPP TS 24.008
2717  */
2718 /*
2719  * 9.9.4.14 Request type
2720  * See subclause 10.5.6.17 in 3GPP TS 24.008
2721  */
2722 static const value_string nas_eps_esm_request_type_values[] = {
2723     { 0x1,      "initial request" },
2724     { 0x2,      "Handover" },
2725     { 0x3,      "Unused; shall be interpreted as initial request if received by the network" },
2726     { 0x4,      "emergency" },
2727     { 0, NULL }
2728  };
2729
2730 /*
2731  * 9.9.4.15 Traffic flow aggregate description
2732  * The Traffic flow aggregate description information element is encoded using the same format as the Traffic flow
2733  * template information element (see subclause 10.5.6.12 in 3GPP TS 24.008 [13]). When sending this IE, the UE shall
2734  * assign the packet filter identifier values so that they are unique across all packet filters for the PDN connection.
2735  */
2736 /*
2737  * 9.9.4.16 Traffic flow template
2738  * See subclause 10.5.6.12 in 3GPP TS 24.008
2739  * packet-gsm_a_gm.c
2740  */
2741 /*
2742  * 9.9.4.17 Transaction identifier
2743  * The Transaction identifier information element is coded as the Linked TI information element in 3GPP TS 24.008 [13],
2744  * subclause 10.5.6.7.
2745  * The coding of the TI flag, the TI value and the EXT bit is defined in 3GPP TS 24.007[20].
2746  */
2747
2748 guint16 (*emm_elem_fcn[])(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len, gchar *add_string, int string_len) = {
2749     /* 9.9.3    EPS Mobility Management (EMM) information elements */
2750     de_emm_add_upd_res,         /* 9.9.3.0A Additional update result */
2751     de_emm_add_upd_type,        /* 9.9.3.0B Additional update type */
2752     NULL,                       /* 9.9.3.1  Authentication failure parameter(dissected in packet-gsm_a_dtap.c) */
2753     NULL,                       /* 9.9.3.2  Authentication parameter AUTN(packet-gsm_a_dtap.c) */
2754     NULL,                       /* 9.9.3.3  Authentication parameter RAND */
2755     de_emm_auth_resp_par,       /* 9.9.3.4  Authentication response parameter */
2756     de_emm_csfb_resp,           /* 9.9.3.5  CSFB response */
2757     NULL,                       /* 9.9.3.6  Daylight saving time (packet-gsm_a_dtap.c)*/
2758     NULL,                       /* 9.9.3.7  Detach type */
2759     NULL,                       /* 9.9.3.8  DRX parameter */
2760     de_emm_cause,               /* 9.9.3.9  EMM cause */
2761     NULL,                       /* 9.9.3.10 EPS attach result (coded inline) */
2762     NULL,                       /* 9.9.3.11 EPS attach type(Coded Inline) */
2763     de_emm_eps_mid,             /* 9.9.3.12 EPS mobile identity */
2764     de_emm_eps_net_feature_sup, /* 9.9.3.12A EPS network feature support */
2765     NULL,                       /* 9.9.3.13 EPS update result (Coded Inline)*/
2766     NULL,                       /* 9.9.3.14 EPS update type (Inline)*/
2767     de_emm_esm_msg_cont,        /* 9.9.3.15 ESM message conta */
2768     NULL,                       /* 9.9.3.16 GPRS timer ,See subclause 10.5.7.3 in 3GPP TS 24.008 [6]. (packet-gsm_a_gm.c)*/
2769     NULL,                       /* 9.9.3.16A GPRS timer 2, See subclause 10.5.7.4 in 3GPP TS 24.008. (packet-gsm_a_gm.c)*/
2770     NULL,                       /* 9.9.3.16B GPRS timer 3, See subclause 10.5.7.4a in 3GPP TS 24.008. (packet-gsm_a_gm.c)*/
2771     NULL,                       /* 9.9.3.17 Identity type 2 ,See subclause 10.5.5.9 in 3GPP TS 24.008 [6]. */
2772     de_emm_nas_imeisv_req,      /* 9.9.3.18 IMEISV request ,See subclause 10.5.5.10 in 3GPP TS 24.008 [6]. */
2773     de_emm_nas_ksi_and_seq_no,  /* 9.9.3.19 KSI and sequence number */
2774     NULL,                       /* 9.9.3.20 MS network capability ,See subclause 10.5.5.12 in 3GPP TS 24.008 [6].(packet-gsm_a_gm.c) */
2775     NULL,                       /* 9.9.3.20A MS network feature support, See subclause 10.5.1.15 in 3GPP TS 24.008.(packet-gsm_a_gm.c) */
2776     de_emm_nas_key_set_id,      /* 9.9.3.21 NAS key set identifier (Coded Inline) */
2777     de_emm_nas_msg_cont,        /* 9.9.3.22 NAS message container */
2778     de_emm_nas_sec_alsgs,       /* 9.9.3.23 NAS security algorithms */
2779     NULL,                       /* 9.9.3.24 Network name, See subclause 10.5.3.5a in 3GPP TS 24.008 [6]. (packet-gsm_a_dtap.c)*/
2780     de_emm_nonce,               /* 9.9.3.25 Nonce */
2781     de_emm_paging_id,           /* 9.9.3.25A Paging identity */
2782     NULL,                       /* 9.9.3.26 P-TMSI signature, See subclause 10.5.5.8 in 3GPP TS 24.008 [6]. (packet-gsm_a_gm.c)*/
2783     NULL,                       /* 9.9.3.27 Service type  */
2784     de_emm_nas_short_mac,       /* 9.9.3.28 Short MAC */
2785     NULL,                       /* 9.9.3.29 Time zone, See subclause 10.5.3.8 in 3GPP TS 24.008 [6]. (packet-gsm_a_dtap.c)*/
2786     NULL,                       /* 9.9.3.30 Time zone and time, See subclause 10.5.3.9 in 3GPP TS 24.008 [6]. (packet-gsm_a_dtap.c)*/
2787     NULL,                       /* 9.9.3.31 TMSI status, See subclause 10.5.5.4 in 3GPP TS 24.008 [6]. (packet-gsm_a_gm.c)*/
2788     de_emm_trac_area_id,        /* 9.9.3.32 Tracking area identity */
2789     de_emm_trac_area_id_lst,    /* 9.9.3.33 Tracking area identity list */
2790     de_emm_ue_net_cap,          /* 9.9.3.34 UE network capability */
2791     de_emm_ue_ra_cap_inf_upd_need, /* 9.9.3.35  UE radio capability information update needed */
2792     de_emm_ue_sec_cap,          /* 9.9.3.36 UE security capability */
2793     NULL,                       /* 9.9.3.37 Emergency Number List (packet-gsm_A_dtap.c) */
2794     NULL,                       /* 9.9.3.38 CLI */
2795     de_emm_ss_code,             /* 9.9.3.39 SS Code */
2796     de_emm_lcs_ind,             /* 9.9.3.40 LCS indicator */
2797     de_emm_lcs_client_id,       /* 9.9.3.41 LCS client identity */
2798     de_emm_gen_msg_cont_type,   /* 9.9.3.42 Generic message container type */
2799     de_emm_gen_msg_cont,        /* 9.9.3.43 Generic message container */
2800     NULL,                       /* 9.9.3.44 Voice domain preference and UE's usage setting */
2801     de_emm_guti_type,           /* 9.9.3.45 GUTI type */
2802     NULL,   /* NONE */
2803 };
2804
2805 /* 9.9.4 EPS Session Management (ESM) information elements */
2806 typedef enum
2807 {
2808     DE_ESM_APN,                     /* 9.9.4.1 Access point name */
2809     DE_ESM_APN_AGR_MAX_BR,          /* 9.9.4.2 APN aggregate maximum bit rate */
2810     DE_ESM_CONNECTIVITY_TYPE,       /* 9.9.4.2A Connectivity type */
2811     DE_ESM_EPS_QOS,                 /* 9.9.4.3 EPS quality of service */
2812     DE_ESM_CAUSE,                   /* 9.9.4.4 ESM cause */
2813     DE_ESM_INF_TRF_FLG,             /* 9.9.4.5 ESM information transfer flag */
2814     DE_ESM_LNKED_EPS_B_ID,          /* 9.9.4.6 Linked EPS bearer identity  */
2815     DE_ESM_LLC_SAPI,                /* 9.9.4.7 LLC service access point identifier */
2816     DE_ESM_NOTIF_IND,               /* 9.9.4.7a Notification indicator */
2817     DE_ESM_P_FLW_ID,                /* 9.9.4.8 Packet flow identifier  */
2818     DE_ESM_PDN_ADDR,                /* 9.9.4.9 PDN address */
2819     DE_ESM_PDN_TYPE,                /* 9.9.4.10 PDN type */
2820     DE_ESM_PROT_CONF_OPT,           /* 9.9.4.11 Protocol configuration options */
2821     DE_ESM_QOS,                     /* 9.9.4.12 Quality of service */
2822     DE_ESM_RA_PRI,                  /* 9.9.4.13 Radio priority  */
2823     DE_ESM_REQ_TYPE,                /* 9.9.4.14 Request type */
2824     DE_ESM_TRAF_FLOW_AGR_DESC,      /* 9.9.4.15 Traffic flow aggregate description */
2825     DE_ESM_TRAF_FLOW_TEMPL,         /* 9.9.4.16 Traffic flow template */
2826     DE_ESM_TID,                     /* 9.9.4.17 Transaction identifier  */
2827     DE_ESM_NONE                     /* NONE */
2828 }
2829 nas_esm_elem_idx_t;
2830
2831 static const value_string nas_esm_elem_strings[] = {
2832     { DE_ESM_APN, "Access point name" },                                /* 9.9.4.1 Access point name */
2833     { DE_ESM_APN_AGR_MAX_BR, "APN aggregate maximum bit rate" },        /* 9.9.4.2 APN aggregate maximum bit rate */
2834     { DE_ESM_CONNECTIVITY_TYPE, "Connectivity type" },                  /* 9.9.4.2A Connectivity type */
2835     { DE_ESM_EPS_QOS, "EPS quality of service" },                       /* 9.9.4.3 EPS quality of service */
2836     { DE_ESM_CAUSE, "ESM cause" },                                      /* 9.9.4.4 ESM cause */
2837     { DE_ESM_INF_TRF_FLG, "ESM information transfer flag" },            /* 9.9.4.5 ESM information transfer flag */
2838     { DE_ESM_LNKED_EPS_B_ID, "Linked EPS bearer identity" },            /* 9.9.4.6 Linked EPS bearer identity */
2839     { DE_ESM_LLC_SAPI, "LLC service access point identifier" },         /* 9.9.4.7 LLC service access point identifier */
2840     { DE_ESM_NOTIF_IND, "Notification indicator" },                     /* 9.9.4.7a Notification indicator */
2841     { DE_ESM_P_FLW_ID, "Packet flow identifier" },                      /* 9.9.4.8 Packet flow identifier */
2842     { DE_ESM_PDN_ADDR, "PDN address" },                                 /* 9.9.4.9 PDN address */
2843     { DE_ESM_PDN_TYPE, "PDN type" },                                    /* 9.9.4.10 PDN type */
2844     { DE_ESM_PROT_CONF_OPT, "Protocol configuration options" },         /* 9.9.4.11 Protocol configuration options */
2845     { DE_ESM_QOS, "Quality of service" },                               /* 9.9.4.12 Quality of service */
2846     { DE_ESM_RA_PRI, "Radio priority" },                                /* 9.9.4.13 Radio priority */
2847     { DE_ESM_REQ_TYPE, "Request type" },                                /* 9.9.4.14 Request type */
2848     { DE_ESM_TRAF_FLOW_AGR_DESC, "Traffic flow aggregate description" },/* 9.9.4.15 Traffic flow aggregate description */
2849     { DE_ESM_TRAF_FLOW_TEMPL, "Traffic flow template" },                /* 9.9.4.16 Traffic flow template */
2850     { DE_ESM_TID, "Transaction identifier" },                           /* 9.9.4.17 Transaction identifier */
2851     { 0, NULL }
2852 };
2853 value_string_ext nas_esm_elem_strings_ext = VALUE_STRING_EXT_INIT(nas_esm_elem_strings);
2854
2855 #define NUM_NAS_ESM_ELEM (sizeof(nas_esm_elem_strings)/sizeof(value_string))
2856 gint ett_nas_eps_esm_elem[NUM_NAS_ESM_ELEM];
2857
2858 guint16 (*esm_elem_fcn[])(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len, gchar *add_string, int string_len) = {
2859     NULL,                           /* 9.9.4.1 Access point name */
2860     de_esm_apn_aggr_max_br,         /* 9.9.4.2 APN aggregate maximum bit rate */
2861     NULL,                           /* 9.9.4.2A Connectivity type */
2862     de_esm_qos,                     /* 9.9.4.3 EPS quality of service */
2863     de_esm_cause,                   /* 9.9.4.4 ESM cause */
2864     de_esm_inf_trf_flg,             /* 9.9.4.5 ESM information transfer flag */
2865     NULL,                           /* 9.9.4.6 Linked EPS bearer identity  */
2866     NULL,                           /* 9.9.4.7 LLC service access point identifier */
2867     de_esm_notif_ind,               /* 9.9.4.7a Notification indicator */
2868     NULL,                           /* 9.9.4.8 Packet flow identifier  */
2869     de_esm_pdn_addr,                /* 9.9.4.9 PDN address */
2870     NULL,                           /* 9.9.4.10 PDN type */
2871     NULL,                           /* 9.9.4.11 Protocol configuration options */
2872     NULL,                           /* 9.9.4.12 Quality of service */
2873     NULL,                           /* 9.9.4.13 Radio priority  */
2874     NULL,                           /* 9.9.4.14 Request type */
2875     NULL,                           /* 9.9.4.15 Traffic flow aggregate description */
2876     NULL,                           /* 9.9.4.16 Traffic flow template */
2877     NULL,                           /* 9.9.4.17 Transaction identifier  */
2878     NULL,   /* NONE */
2879 };
2880
2881 /* MESSAGE FUNCTIONS */
2882
2883 /*
2884  * 8.2.1    Attach accept
2885  */
2886
2887 static void
2888 nas_emm_attach_acc(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
2889 {
2890     guint32 curr_offset, bit_offset;
2891     guint32 consumed;
2892     guint   curr_len;
2893
2894     curr_offset = offset;
2895     curr_len    = len;
2896
2897     /*  Spare half octet    Spare half octet 9.9.2.7    M   V   1/2 */
2898     bit_offset = curr_offset<<3;
2899     proto_tree_add_bits_item(tree, hf_nas_eps_emm_spare_half_octet, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
2900     bit_offset+=4;
2901     /*  EPS attach result   EPS attach result 9.9.3.10  M   V   1/2 */
2902     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
2903     bit_offset++;
2904     proto_tree_add_bits_item(tree, hf_nas_eps_emm_EPS_attach_result, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
2905     /*bit_offset+=3;*/
2906     /* Fix up the lengths */
2907     curr_len--;
2908     curr_offset++;
2909     /*  T3412 value GPRS timer 9.9.3.16 M   V   1 */
2910     ELEM_MAND_V(GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER, " - T3412 value");
2911     /*  Tracking area identity list 9.9.3.33    M   LV  7-97 */
2912     ELEM_MAND_LV(NAS_PDU_TYPE_EMM, DE_EMM_TRAC_AREA_ID_LST, " - TAI list");
2913     /*  ESM message container 9.9.3.15  M   LV-E    2-n */
2914     ELEM_MAND_LV_E(NAS_PDU_TYPE_EMM, DE_EMM_ESM_MSG_CONT, NULL);
2915     /* 50   GUTI    EPS mobile identity 9.9.3.12    O   TLV 13 */
2916     ELEM_OPT_TLV(0x50, NAS_PDU_TYPE_EMM, DE_EMM_EPS_MID, " - GUTI");
2917     /* 13   Location area identification    Location area identification 9.9.2.2    O   TV  6 */
2918     ELEM_OPT_TV(0x13, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_LOC_AREA_ID, NULL);
2919     /* 23   MS identity     Mobile identity 9.9.2.3 O   TLV 7-10 */
2920     ELEM_OPT_TLV(0x23, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_MOB_ID, " - MS identity");
2921     /* 53   EMM cause   EMM cause 9.9.3.9   O   TV  2 */
2922     ELEM_OPT_TV(0x53, NAS_PDU_TYPE_EMM, DE_EMM_CAUSE, NULL);
2923     /* 17   T3402 value GPRS timer 9.9.3.16 O   TV  2 */
2924     ELEM_OPT_TV(0x17, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER, " - T3402 value");
2925     /* 59   T3423 value GPRS timer 9.9.3.16 O   TV  2 */
2926     ELEM_OPT_TV(0x59, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER, " - T3423 value");
2927     /* 4A   Equivalent PLMNs    PLMN list 9.9.2.8   O   TLV 5-47 */
2928     ELEM_OPT_TLV(0x4a, GSM_A_PDU_TYPE_COMMON, DE_PLMN_LIST, " - Equivalent PLMNs");
2929     /* 34   Emergency Number List 9.9.3.37  O   TLV 5-50 */
2930     ELEM_OPT_TLV(0x34, GSM_A_PDU_TYPE_DTAP, DE_EMERGENCY_NUM_LIST, NULL);
2931     /* 64   EPS network feature support EPS network feature support 9.9.3.12A   O   TLV 3 */
2932     ELEM_OPT_TLV(0x64, NAS_PDU_TYPE_EMM, DE_EMM_EPS_NET_FEATURE_SUP, NULL);
2933     /* F-   Additional update result    Additional update result 9.9.3.0A   O   TV  1 */
2934     ELEM_OPT_TV_SHORT( 0xF0 , NAS_PDU_TYPE_EMM, DE_EMM_ADD_UPD_RES, NULL );
2935     /* 5E   T3412 extended value GPRS timer 3 9.9.3.16B O   TLV  3 */
2936     ELEM_OPT_TLV(0x5E, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_3, " - T3412 extended value");
2937
2938     EXTRANEOUS_DATA_CHECK(curr_len, 0);
2939 }
2940 /*
2941  * 8.2.2    Attach complete
2942  */
2943 static void
2944 nas_emm_attach_comp(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
2945 {
2946     guint32 curr_offset;
2947     guint32 consumed;
2948     guint   curr_len;
2949
2950     curr_offset = offset;
2951     curr_len    = len;
2952
2953     /* ESM message container    ESM message container 9.9.3.15  M   LV-E    2-n */
2954     ELEM_MAND_LV_E(NAS_PDU_TYPE_EMM, DE_EMM_ESM_MSG_CONT, NULL);
2955
2956     EXTRANEOUS_DATA_CHECK(curr_len, 0);
2957
2958 }
2959
2960 /*
2961  * 8.2.3    Attach reject
2962  */
2963 static void
2964 nas_emm_attach_rej(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
2965 {
2966     guint32 curr_offset;
2967     guint32 consumed;
2968     guint   curr_len;
2969
2970     curr_offset = offset;
2971     curr_len    = len;
2972
2973     /* * EMM cause  EMM cause 9.9.3.9   M   V   1 */
2974     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_CAUSE, NULL);
2975     /* 78 ESM message container ESM message container 9.9.3.15  O   TLV-E   4-n */
2976     ELEM_OPT_TLV_E(0x78, NAS_PDU_TYPE_EMM, DE_EMM_ESM_MSG_CONT, NULL);
2977     /* 5F   T3346 value GPRS timer 2 9.9.3.16A O   TLV  3 */
2978     ELEM_OPT_TLV(0x5F, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_2, " - T3346 value");
2979     /* 16   T3402 value GPRS timer 2 9.9.3.16A O   TLV  3 */
2980     ELEM_OPT_TLV(0x16, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_2, " - T3402 value");
2981
2982     EXTRANEOUS_DATA_CHECK(curr_len, 0);
2983
2984 }
2985 /*
2986  * 8.2.4    Attach request
2987  */
2988 static void
2989 nas_emm_attach_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
2990 {
2991     guint32 curr_offset, bit_offset;
2992     guint32 consumed;
2993     guint   curr_len;
2994
2995     curr_offset = offset;
2996     curr_len    = len;
2997
2998     bit_offset = curr_offset<<3;
2999
3000     /* NAS key set identifier   NAS key set identifier 9.9.3.21 M   V   1/2 */
3001     de_emm_nas_key_set_id_bits(tvb, tree, bit_offset, NULL);
3002     bit_offset+=4;
3003
3004     /* EPS attach type  EPS attach type 9.9.3.11    M   V   1/2
3005      * Inline:
3006      */
3007     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
3008     bit_offset++;
3009     proto_tree_add_bits_item(tree, hf_nas_eps_emm_eps_att_type, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
3010     /*bit_offset+=3;*/
3011
3012     /* Fix the lengths */
3013     curr_len--;
3014     curr_offset++;
3015     /* Old GUTI or IMSI EPS mobile identity 9.9.3.12    M   LV  5-12 */
3016     ELEM_MAND_LV(NAS_PDU_TYPE_EMM, DE_EMM_EPS_MID, NULL);
3017     /* UE network capability    UE network capability 9.9.3.34  M   LV  3-14 */
3018     ELEM_MAND_LV(NAS_PDU_TYPE_EMM, DE_EMM_UE_NET_CAP, NULL);
3019     /* ESM message container    ESM message container 9.9.3.15  M   LV-E    2-n */
3020     ELEM_MAND_LV_E(NAS_PDU_TYPE_EMM, DE_EMM_ESM_MSG_CONT, NULL);
3021     /* 19   Old P-TMSI signature    P-TMSI signature 10.5.5.8   O   TV  4 */
3022     ELEM_OPT_TV( 0x19 , GSM_A_PDU_TYPE_GM, DE_P_TMSI_SIG, " - Old P-TMSI Signature");
3023     /* 50   Additional GUTI EPS mobile identity 9.9.3.12    O   TLV 13 */
3024     ELEM_OPT_TLV( 0x50 , NAS_PDU_TYPE_EMM, DE_EMM_EPS_MID, " - Additional GUTI");
3025     /* 52 Last visited registered TAI   Tracking area identity 9.9.3.32 O   TV  6 */
3026     ELEM_OPT_TV(0x52, NAS_PDU_TYPE_EMM, DE_EMM_TRAC_AREA_ID, " - Last visited registered TAI");
3027     /* 5c DRX parameter DRX parameter 9.9.3.8   O   TV  3 */
3028     ELEM_OPT_TV(0x5c, GSM_A_PDU_TYPE_GM, DE_DRX_PARAM, NULL );
3029     /* 31 MS network capability MS network capability 9.9.3.20  M   LV  3-9 */
3030     ELEM_OPT_TLV( 0x31, GSM_A_PDU_TYPE_GM, DE_MS_NET_CAP , NULL );
3031     /* 13 Old location area identification  Location area identification 9.9.2.2    O   TV  6 */
3032     ELEM_OPT_TV(0x13, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_LOC_AREA_ID, " - Old location area identification");
3033     /* 9- TMSI status   TMSI status 9.9.3.31    O   TV  1 */
3034     ELEM_OPT_TV_SHORT( 0x90 , GSM_A_PDU_TYPE_GM, DE_TMSI_STAT , NULL );
3035     /* 11   Mobile station classmark 2  Mobile station classmark 2 9.9.2.5  O   TLV 5 */
3036     ELEM_OPT_TLV( 0x11, NAS_PDU_TYPE_COMMON, DE_EPS_MS_CM_2 , NULL );
3037     /* 20   Mobile station classmark 3  Mobile station classmark 3 9.9.2.5  O   TLV 2-34 */
3038     ELEM_OPT_TLV( 0x20, NAS_PDU_TYPE_COMMON, DE_EPS_MS_CM_3 , NULL );
3039     /* 40   Supported Codecs    Supported Codec List 9.9.2.10   O   TLV 5-n */
3040     ELEM_OPT_TLV(0x40, GSM_A_PDU_TYPE_DTAP, DE_SUP_CODEC_LIST, " - Supported Codecs");
3041     /* F-   Additional update type  Additional update type 9.9.3.0B O   TV  1 */
3042     ELEM_OPT_TV_SHORT( 0xF0 , NAS_PDU_TYPE_EMM, DE_EMM_ADD_UPD_TYPE, NULL );
3043     /* 5D   Voice domain preference and UE's usage setting  Voice domain preference and UE's usage setting 9.9.3.44 O   TLV 3 */
3044     ELEM_OPT_TLV(0x5D, GSM_A_PDU_TYPE_GM, DE_VOICE_DOMAIN_PREF, NULL);
3045     /* D-   Device properties  Device properties 9.9.2.0A O   TV  1 */
3046     ELEM_OPT_TV_SHORT(0xD0 , GSM_A_PDU_TYPE_GM, DE_DEVICE_PROPERTIES, NULL);
3047     /* E-   Old GUTI type  GUTI type 9.9.3.45 O   TV  1 */
3048     ELEM_OPT_TV_SHORT(0xE0 , NAS_PDU_TYPE_EMM, DE_EMM_GUTI_TYPE, " - Old GUTI type");
3049     /* C-   MS network feature support  MS network feature support 9.9.3.20A 0  TV 1 */
3050     ELEM_OPT_TV_SHORT(0xC0 , GSM_A_PDU_TYPE_COMMON, DE_MS_NET_FEAT_SUP, NULL);
3051     /* 10   TMSI based NRI container  Network resource identifier container 9.9.3.24A 0  TLV 4 */
3052     ELEM_OPT_TLV(0x10, GSM_A_PDU_TYPE_GM, DE_NET_RES_ID_CONT, " - TMSI based NRI container");
3053
3054     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3055 }
3056 /*
3057  * 8.2.5    Authentication failure
3058  */
3059 static void
3060 nas_emm_auth_fail(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3061 {
3062     guint32 curr_offset;
3063     guint32 consumed;
3064     guint   curr_len;
3065
3066     curr_offset = offset;
3067     curr_len    = len;
3068
3069      /* EMM cause   EMM cause 9.9.3.9   M   V   1 */
3070     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_CAUSE, NULL);
3071     /* 30 Authentication failure parameter  Authentication failure parameter 9.9.3.1    O   TLV 1 */
3072     ELEM_OPT_TLV(0x30, GSM_A_PDU_TYPE_DTAP, DE_AUTH_FAIL_PARAM, NULL);
3073
3074     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3075 }
3076 /*
3077  * 8.2.6    Authentication reject
3078  * No IE:s
3079  */
3080 /*
3081  * 8.2.7    Authentication request
3082  */
3083
3084 static void
3085 nas_emm_auth_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3086 {
3087     guint32 curr_offset, bit_offset;
3088     guint32 consumed;
3089     guint   curr_len;
3090
3091     curr_offset = offset;
3092     curr_len    = len;
3093
3094     bit_offset = curr_offset<<3;
3095     /* H1 */
3096     /*  Spare half octet    Spare half octet 9.9.2.7    M   V   1/2 */
3097     proto_tree_add_bits_item(tree, hf_nas_eps_emm_spare_half_octet, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
3098     bit_offset+=4;
3099     /* H0 */
3100     /*
3101      * NAS key set identifierASME   NAS key set identifier 9.9.3.21 M   V   1/2
3102      */
3103     de_emm_nas_key_set_id_bits(tvb, tree, bit_offset, " ASME");
3104     /*bit_offset+=4;*/
3105
3106     /* Fix the lengths */
3107     curr_len--;
3108     curr_offset++;
3109
3110     /*
3111      * Authentication parameter RAND (EPS challenge) 9.9.3.3    M   V   16
3112      */
3113     ELEM_MAND_V(GSM_A_PDU_TYPE_DTAP, DE_AUTH_PARAM_RAND, " - EPS challenge");
3114     /*
3115      * Authentication parameter AUTN (EPS challenge) 9.9.3.2    M   LV  17
3116      */
3117     ELEM_MAND_LV(GSM_A_PDU_TYPE_DTAP, DE_AUTH_PARAM_AUTN, " - EPS challenge");
3118
3119     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3120
3121 }
3122 /*
3123  * 8.2.8    Authentication response
3124  */
3125 static void
3126 nas_emm_auth_resp(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3127 {
3128     guint32 curr_offset;
3129     guint32 consumed;
3130     guint   curr_len;
3131
3132     curr_offset = offset;
3133     curr_len    = len;
3134
3135     /*
3136      * Authentication response parameter 9.9.3.4    M   LV  5-17
3137      */
3138     ELEM_MAND_LV(NAS_PDU_TYPE_EMM, DE_EMM_AUTH_RESP_PAR, NULL);
3139
3140     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3141 }
3142
3143 /*
3144  * 8.2.9    CS service notification
3145  */
3146
3147 static void
3148 nas_emm_cs_serv_not(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3149 {
3150     guint32 curr_offset;
3151     guint32 consumed;
3152     guint   curr_len;
3153
3154     curr_offset = offset;
3155     curr_len    = len;
3156
3157     /* Paging identity  Paging identity 9.9.3.25A   M   V   1 */
3158     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_PAGING_ID, NULL);
3159     /* 60   CLI CLI 9.9.3.38    O   TLV 3-12 */
3160     ELEM_OPT_TLV(0x60, GSM_A_PDU_TYPE_DTAP, DE_CLD_PARTY_BCD_NUM, " - CLI");
3161     /* 61   SS Code SS Code 9.9.3.39    O   TV  2 */
3162     ELEM_OPT_TV(0x61, NAS_PDU_TYPE_EMM, DE_EMM_SS_CODE, NULL);
3163     /* 62   LCS indicator   LCS indicator 9.9.3.40  O   TV  2 */
3164     ELEM_OPT_TV(0x62, NAS_PDU_TYPE_EMM, DE_EMM_LCS_IND, NULL);
3165     /* 63   LCS client identity LCS client identity 9.9.3.41    O   TLV 3-257 */
3166     ELEM_OPT_TLV(0x63, NAS_PDU_TYPE_EMM, DE_EMM_LCS_CLIENT_ID, NULL);
3167
3168     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3169 }
3170 /*
3171  * 8.2.10   Detach accept
3172  * 8.2.10.1 Detach accept (UE originating detach)
3173  * No further IE's
3174  * 8.2.10.2 Detach accept (UE terminated detach)
3175  * No further IE's
3176  */
3177 /*
3178  * 8.2.11   Detach request
3179  * 8.2.11.1 Detach request (UE originating detach)
3180  */
3181
3182 static void
3183 nas_emm_detach_req_UL(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3184 {
3185     guint32 curr_offset,bit_offset;
3186     guint32 consumed;
3187     guint   curr_len;
3188
3189     curr_offset = offset;
3190     curr_len    = len;
3191
3192     proto_tree_add_text(tree, tvb, curr_offset, len, "Uplink");
3193     /* NAS key set identifier   NAS key set identifier 9.9.3.21 M   V   1/2 */
3194     bit_offset = curr_offset<<3;
3195     de_emm_nas_key_set_id_bits(tvb, tree, bit_offset, NULL);
3196     bit_offset+=4;
3197     /* Detach type  Detach type 9.9.3.6 M   V   1/2 */
3198     proto_tree_add_bits_item(tree, hf_nas_eps_emm_switch_off, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
3199     bit_offset++;
3200     proto_tree_add_bits_item(tree, hf_nas_eps_emm_detach_type_UL, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
3201    /* bit_offset+=3;*/
3202
3203     /* Fix the lengths */
3204     curr_len--;
3205     curr_offset++;
3206
3207     /* GUTI or IMSI EPS mobile identity 9.9.3.12    M   LV  5-12 */
3208     ELEM_MAND_LV(NAS_PDU_TYPE_EMM, DE_EMM_EPS_MID, NULL);
3209
3210     return;
3211 }
3212 /*
3213  * 8.2.11.2 Detach request (UE terminated detach)
3214  */
3215 static void
3216 nas_emm_detach_req_DL(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3217 {
3218     guint32 curr_offset, bit_offset;
3219     guint32 consumed;
3220     guint   curr_len;
3221
3222     curr_offset = offset;
3223     curr_len    = len;
3224
3225     proto_tree_add_text(tree, tvb, curr_offset, len, "Downlink");
3226     /* Spare half octet Spare half octet 9.9.2.7    M   V   1/2 */
3227     bit_offset = curr_offset<<3;
3228     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
3229     bit_offset+=4;
3230     /* Detach type  Detach type 9.9.3.6 M   V   1/2 */
3231     /* In the network to UE direction bit 4 is spare. The network shall set this bit to zero. */
3232     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
3233     bit_offset++;
3234     proto_tree_add_bits_item(tree, hf_nas_eps_emm_detach_type_DL, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
3235     /*bit_offset+=3;*/
3236
3237     /* Fix the lengths */
3238     curr_len--;
3239     curr_offset++;
3240
3241     /* No more mandatory elements */
3242     if (curr_len == 0)
3243         return;
3244
3245     /* EMM cause    EMM cause 9.9.3.9   O   TV  2 */
3246     ELEM_OPT_TV(0x53, NAS_PDU_TYPE_EMM, DE_EMM_CAUSE, NULL);
3247
3248     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3249
3250     return;
3251 }
3252 static void
3253 nas_emm_detach_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
3254 {
3255 #if 0
3256     guint32 curr_offset;
3257 #endif
3258     /*guint curr_len;*/
3259
3260 #if 0
3261     curr_offset = offset;
3262 #endif
3263     /*curr_len = len;*/
3264
3265     if (pinfo) {
3266         if (pinfo->link_dir == P2P_DIR_UL) {
3267             nas_emm_detach_req_UL(tvb, tree, pinfo, offset, len);
3268             return;
3269         }else if (pinfo->link_dir == P2P_DIR_DL) {
3270             nas_emm_detach_req_DL(tvb, tree, pinfo, offset, len);
3271             return;
3272         }
3273     }
3274 #if 0
3275     proto_tree_add_text(tree, tvb, curr_offset, len,"UL/DL not known, can't properly dissect");
3276     proto_tree_add_text(tree, tvb, curr_offset, len,"Trying to dissect as UE terminated detach");
3277     nas_emm_detach_req_DL(tvb, tree, pinfo, offset, len);
3278     proto_tree_add_text(tree, tvb, curr_offset, len,"Trying to dissect as UE originating detach");
3279     nas_emm_detach_req_UL(tvb, tree, pinfo, offset, len);
3280 #else
3281     if (len >= 8) {
3282         nas_emm_detach_req_UL(tvb, tree, pinfo, offset, len);
3283     } else {
3284         nas_emm_detach_req_DL(tvb, tree, pinfo, offset, len);
3285     }
3286 #endif
3287
3288     return;
3289 }
3290
3291 /*
3292  * 8.2.12   Downlink NAS Transport
3293  */
3294 static void
3295 nas_emm_dl_nas_trans(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3296 {
3297     guint32 curr_offset;
3298     guint32 consumed;
3299     guint   curr_len;
3300
3301     curr_offset = offset;
3302     curr_len    = len;
3303
3304     pinfo->link_dir = P2P_DIR_DL;
3305
3306     /* NAS message container    NAS message container 9.9.3.22  M   LV  3-252 */
3307     ELEM_MAND_LV(NAS_PDU_TYPE_EMM, DE_EMM_NAS_MSG_CONT, NULL);
3308
3309     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3310 }
3311 /*
3312  * 8.2.13   EMM information
3313  */
3314 static void
3315 nas_emm_emm_inf(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3316 {
3317     guint32 curr_offset;
3318     guint32 consumed;
3319     guint   curr_len;
3320
3321     curr_offset = offset;
3322     curr_len    = len;
3323
3324     /* 43   Full name for network   Network name 9.9.3.24   O   TLV 3-? */
3325     ELEM_OPT_TLV(0x43, GSM_A_PDU_TYPE_DTAP, DE_NETWORK_NAME, " - Full name for network");
3326     /* 45   Short name for network  Network name 9.9.3.24   O   TLV 3-? */
3327     ELEM_OPT_TLV(0x45, GSM_A_PDU_TYPE_DTAP, DE_NETWORK_NAME, " - Short Name");
3328     /* 46   Local time zone Time zone 9.9.3.29  O   TV  2 */
3329     ELEM_OPT_TV(0x46, GSM_A_PDU_TYPE_DTAP, DE_TIME_ZONE, " - Local");
3330     /* 47   Universal time and local time zone  Time zone and time 9.9.3.30 O   TV  8 */
3331     ELEM_OPT_TV(0x47, GSM_A_PDU_TYPE_DTAP, DE_TIME_ZONE_TIME, " - Universal Time and Local Time Zone");
3332     /* 49   Network daylight saving time    Daylight saving time 9.9.3.6    O   TLV 3 */
3333     ELEM_OPT_TLV(0x49, GSM_A_PDU_TYPE_DTAP, DE_DAY_SAVING_TIME, NULL);
3334
3335     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3336 }
3337
3338
3339 /*
3340  * 8.2.14   EMM status
3341  */
3342 static void
3343 nas_emm_emm_status(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3344 {
3345     guint32 curr_offset;
3346     guint32 consumed;
3347     guint   curr_len;
3348
3349     curr_offset = offset;
3350     curr_len    = len;
3351
3352     /* EMM cause    EMM cause 9.9.3.9   M   V   1 */
3353     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_CAUSE, NULL);
3354
3355     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3356 }
3357
3358 /*
3359  * 8.2.15   Extended service request
3360  */
3361 static void
3362 nas_emm_ext_serv_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3363 {
3364     guint32 curr_offset,bit_offset;
3365     guint32 consumed;
3366     guint   curr_len;
3367
3368     curr_offset = offset;
3369     curr_len    = len;
3370
3371     bit_offset = curr_offset<<3;
3372
3373     /* NAS key set identifier   NAS key set identifier 9.9.3.21 M   V   1/2 */
3374     de_emm_nas_key_set_id_bits(tvb, tree, bit_offset, NULL);
3375     bit_offset+=4;
3376     /* Service type Service type 9.9.3.27   M   V   1/2 Service type*/
3377     proto_tree_add_bits_item(tree, hf_nas_eps_service_type, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
3378     /*bit_offset+=4;*/
3379     /* Fix up the lengths */
3380     curr_len--;
3381     curr_offset++;
3382
3383     /* M-TMSI   Mobile identity 9.9.2.3 M   LV  6 */
3384     ELEM_MAND_LV(NAS_PDU_TYPE_COMMON, DE_EPS_CMN_MOB_ID, " - M-TMSI");
3385     /* B-   CSFB response   CSFB response 9.9.3.5   C   TV  1 */
3386     ELEM_OPT_TV_SHORT(0xb0, NAS_PDU_TYPE_EMM, DE_EMM_CSFB_RESP, NULL);
3387     /* 57   EPS bearer context status   EPS bearer context status 9.9.2.1   O   TLV 4 */
3388     ELEM_OPT_TLV(0x57, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_EPS_BE_CTX_STATUS, NULL);
3389     /* D-   Device properties  Device properties 9.9.2.0A O   TV  1 */
3390     ELEM_OPT_TV_SHORT(0xD0 , GSM_A_PDU_TYPE_GM, DE_DEVICE_PROPERTIES, NULL);
3391
3392     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3393 }
3394 /*
3395  * 8.2.16   GUTI reallocation command
3396  */
3397 static void
3398 nas_emm_guti_realloc_cmd(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3399 {
3400     guint32 curr_offset;
3401     guint32 consumed;
3402     guint   curr_len;
3403
3404     curr_offset = offset;
3405     curr_len    = len;
3406
3407     /* GUTI EPS mobile identity 9.9.3.12    M   LV  12 */
3408     ELEM_MAND_LV(NAS_PDU_TYPE_EMM, DE_EMM_EPS_MID, " - GUTI");
3409
3410     /* 54   TAI list    Tracking area identity list 9.9.3.33    O   TLV 8-98 */
3411     ELEM_OPT_TLV(0x54, NAS_PDU_TYPE_EMM, DE_EMM_TRAC_AREA_ID_LST, NULL);
3412
3413     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3414 }
3415
3416 /*
3417  * 8.2.17   GUTI reallocation complete
3418  * No more IE's
3419  */
3420 /*
3421  * 8.2.18   Identity request
3422  */
3423
3424 static void
3425 nas_emm_id_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3426 {
3427     guint32 curr_offset, bit_offset;
3428     /*guint32   consumed;*/
3429     guint   curr_len;
3430
3431     curr_offset = offset;
3432     curr_len    = len;
3433
3434
3435     bit_offset=curr_offset<<3;
3436
3437     /* Spare half octet Spare half octet 9.9.2.7    M   V   1/2 */
3438     proto_tree_add_bits_item(tree, hf_nas_eps_emm_spare_half_octet, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
3439     bit_offset+=4;
3440
3441     /* Identity type    Identity type 2 9.9.3.17    M   V   1/2 */
3442     proto_tree_add_bits_item(tree, hf_nas_eps_emm_id_type2, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
3443     /*bit_offset+=4;*/
3444     /*consumed = 1;*/
3445
3446
3447     /* Fix up the lengths */
3448     curr_len--;
3449     curr_offset++;
3450
3451     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3452 }
3453 /*
3454  * 8.2.19   Identity response
3455  */
3456 static void
3457 nas_emm_id_res(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3458 {
3459     guint32 curr_offset;
3460     guint32 consumed;
3461     guint   curr_len;
3462
3463     curr_offset = offset;
3464     curr_len    = len;
3465
3466     /* Mobile identity  Mobile identity 9.9.2.3 M   LV  4-10 */
3467     ELEM_MAND_LV(NAS_PDU_TYPE_COMMON, DE_EPS_CMN_MOB_ID, NULL);
3468
3469     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3470 }
3471
3472
3473
3474 /*
3475  * 8.2.20   Security mode command
3476  */
3477 static void
3478 nas_emm_sec_mode_cmd(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3479 {
3480     guint32 curr_offset, bit_offset;
3481     guint32 consumed;
3482     guint   curr_len;
3483
3484     curr_offset = offset;
3485     curr_len    = len;
3486
3487     /*  Selected NAS security algorithms    NAS security algorithms 9.9.3.23    M   V   1  */
3488     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_NAS_SEC_ALGS, " - Selected NAS security algorithms");
3489
3490     bit_offset = curr_offset<<3;
3491     /* Spare half octet Spare half octet 9.9.2.7    M   V   1/2 */
3492     proto_tree_add_bits_item(tree, hf_nas_eps_emm_spare_half_octet, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
3493     bit_offset+=4;
3494     /*  NAS key set identifierASME  NAS key set identifier 9.9.3.21 M   V   1/2 */
3495     de_emm_nas_key_set_id_bits(tvb, tree, bit_offset, " ASME");
3496     /*bit_offset+=4;*/
3497
3498     /* Fix up the lengths */
3499     curr_len--;
3500     curr_offset++;
3501
3502     /*  Replayed UE security capabilities   UE security capability 9.9.3.36 M   LV  3-6 */
3503     ELEM_MAND_LV(NAS_PDU_TYPE_EMM, DE_EMM_UE_SEC_CAP, " - Replayed UE security capabilities");
3504     /* C-   IMEISV request  IMEISV request 9.9.3.18 O   TV  1 */
3505     ELEM_OPT_TV_SHORT( 0xC0 , NAS_PDU_TYPE_EMM, DE_EMM_IMEISV_REQ , NULL );
3506     /* 55   Replayed NonceUE    Nonce 9.9.3.25  O   TV  5 */
3507     ELEM_OPT_TV(0x55, NAS_PDU_TYPE_EMM, DE_EMM_NONCE, " - Replayed NonceUE");
3508     /* 56   NonceMME    Nonce 9.9.3.25  O   TV  5 */
3509     ELEM_OPT_TV(0x56, NAS_PDU_TYPE_EMM, DE_EMM_NONCE, " - NonceMME");
3510
3511     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3512 }
3513 /*
3514  * 8.2.21   Security mode complete
3515  */
3516 static void
3517 nas_emm_sec_mode_comp(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3518 {
3519     guint32 curr_offset;
3520     guint32 consumed;
3521     guint   curr_len;
3522
3523     curr_offset = offset;
3524     curr_len    = len;
3525
3526     if (curr_len == 0)
3527         return;
3528
3529     /* 23   IMEISV  Mobile identity 9.9.2.3 O   TLV 11 */
3530     ELEM_OPT_TLV(0x23, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_MOB_ID, " - IMEISV");
3531
3532     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3533 }
3534 /*
3535  * 8.2.22   Security mode reject
3536  */
3537 static void
3538 nas_emm_sec_mode_rej(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3539 {
3540     guint32 curr_offset;
3541     guint32 consumed;
3542     guint   curr_len;
3543
3544     curr_offset = offset;
3545     curr_len    = len;
3546
3547     /* EMM cause    EMM cause 9.9.3.9   M   V   1 */
3548     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_CAUSE, NULL);
3549
3550     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3551 }
3552 /*
3553  * 8.2.23   Security protected NAS message
3554  */
3555 #if 0
3556 static int
3557 nas_emm_sec_prot_msg(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3558 {
3559     guint32 curr_offset;
3560     guint   curr_len;
3561     guint8 security_header_type;
3562
3563     curr_offset = offset;
3564     curr_len    = len;
3565
3566     /* Security header type Security header type 9.3.1 M V 1/2 */
3567     security_header_type = tvb_get_guint8(tvb,offset)>>4;
3568     proto_tree_add_item(tree, hf_nas_eps_security_header_type, tvb, 0, 1, ENC_BIG_ENDIAN);
3569     /* Protocol discriminator Protocol discriminator 9.2 M V 1/2 */
3570     proto_tree_add_item(tree, hf_gsm_a_L3_protocol_discriminator, tvb, 0, 1, ENC_BIG_ENDIAN);
3571     offset++;
3572     /* Message authentication code  Message authentication code 9.5 M   V   4 */
3573     if (security_header_type != 0) {
3574         /* Message authentication code */
3575         proto_tree_add_item(tree, hf_nas_eps_msg_auth_code, tvb, offset, 4, ENC_BIG_ENDIAN);
3576         offset+=4;
3577         if ((security_header_type == 2)||(security_header_type == 4)) {
3578             /* Integrity protected and ciphered = 2, Integrity protected and ciphered with new EPS security context = 4 */
3579             proto_tree_add_text(tree, tvb, offset, len-5,"Ciphered message");
3580             return offset;
3581         }
3582     } else {
3583         proto_tree_add_text(tree, tvb, offset, len,"Not a security protected message");
3584         return offset;
3585     }
3586     /* Sequence number  Sequence number 9.6 M   V   1 */
3587     proto_tree_add_item(tree, hf_nas_eps_seq_no, tvb, offset, 1, ENC_BIG_ENDIAN);
3588     offset++;
3589     /* NAS message  NAS message 9.7 M   V   1-n  */
3590     return offset;
3591 }
3592 #endif
3593 /*
3594  * 8.2.24   Service reject
3595  */
3596 static void
3597 nas_emm_serv_rej(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3598 {
3599     guint32 curr_offset;
3600     guint32 consumed;
3601     guint   curr_len;
3602
3603     curr_offset = offset;
3604     curr_len    = len;
3605
3606     /* EMM cause    EMM cause 9.9.3.9   M   V   1 */
3607     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_CAUSE, NULL);
3608     /* 5B   T3442 value GPRS timer 9.9.3.16 C   TV  2 */
3609     ELEM_OPT_TV(0x5b, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER, " - T3442 value");
3610     /* 5F   T3346 value GPRS timer 2 9.9.3.16A O   TLV  3 */
3611     ELEM_OPT_TLV(0x5F, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_2, " - T3346 value");
3612
3613     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3614 }
3615 /*
3616  * 8.2.25   Service request
3617  * This message is sent by the UE to the network to request the establishment
3618  * of a NAS signalling connection and of the radio and S1 bearers.
3619  * Its structure does not follow the structure of a standard layer 3 message. See table 8.2.25.1.
3620  */
3621 /* Table 8.2.25.1
3622  * Protocol discriminator Protocol discriminator 9.2 M V 1/2
3623  * Security header type Security header type 9.3.1 M V 1/2
3624  * KSI and sequence number KSI and sequence number 9.9.3.19 M V 1
3625  * Message authentication code (short) Short MAC 9.9.3.28 M V 2
3626  */
3627 static void
3628 nas_emm_service_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3629 {
3630     guint32 curr_offset;
3631     guint32 consumed;
3632     guint   curr_len;
3633
3634     curr_offset = offset;
3635     curr_len    = len;
3636
3637     /* KSI and sequence number 9.9.3.19 M V 1   */
3638     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_KSI_AND_SEQ_NO, NULL);
3639
3640     /* Short MAC 9.9.3.28 M V 2 */
3641     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_SHORT_MAC, " - Message authentication code (short)");
3642
3643     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3644 }
3645
3646 /*
3647  * 8.2.26   Tracking area update accept
3648  */
3649 static void
3650 nas_emm_trac_area_upd_acc(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3651 {
3652     guint32 curr_offset, bit_offset;
3653     guint32 consumed;
3654     guint   curr_len;
3655
3656     curr_offset = offset;
3657     curr_len    = len;
3658
3659     /*  Spare half octet    Spare half octet 9.9.2.7    M   V   1/2 */
3660     bit_offset = curr_offset<<3;
3661     proto_tree_add_bits_item(tree, hf_nas_eps_emm_spare_half_octet, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
3662     bit_offset+=4;
3663     /*  EPS update result   EPS update result 9.9.3.13  M   V   1/2 */
3664     proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
3665     bit_offset++;
3666     proto_tree_add_bits_item(tree, hf_nas_eps_eps_update_result_value, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
3667     /*bit_offset+=3;*/
3668     /* Fix up the lengths */
3669     curr_len--;
3670     curr_offset++;
3671     /* No more mandatory elements */
3672     if (curr_len == 0)
3673         return;
3674     /* 5A   T3412 value GPRS timer 9.9.3.16 O   TV  2 */
3675     ELEM_OPT_TV(0x5a, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER, " - T3412 value");
3676     /* 50   GUTI    EPS mobile identity 9.9.3.12    O   TLV 13 */
3677     ELEM_OPT_TLV(0x50, NAS_PDU_TYPE_EMM, DE_EMM_EPS_MID, " - GUTI");
3678     /* 54   TAI list    Tracking area identity list 9.9.3.33    O   TLV 8-98 */
3679     ELEM_OPT_TLV(0x54, NAS_PDU_TYPE_EMM, DE_EMM_TRAC_AREA_ID_LST, NULL);
3680     /* 57   EPS bearer context status   EPS bearer context status 9.9.2.1   O   TLV 4 */
3681     ELEM_OPT_TLV(0x57, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_EPS_BE_CTX_STATUS, NULL);
3682     /* 13   Location area identification    Location area identification 9.9.2.2    O   TV  6 */
3683     ELEM_OPT_TV(0x13, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_LOC_AREA_ID, NULL);
3684     /* 23   MS identity Mobile identity 9.9.2.3 O   TLV 7-10  */
3685     ELEM_OPT_TLV(0x23, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_MOB_ID, " - MS identity");
3686     /* 53   EMM cause   EMM cause 9.9.3.9   O   TV  2  */
3687     ELEM_OPT_TV(0x53, NAS_PDU_TYPE_EMM, DE_EMM_CAUSE, NULL);
3688     /* 17   T3402 value GPRS timer 9.9.3.16 O   TV  2  */
3689     ELEM_OPT_TV(0x17, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER, " - T3402 value");
3690     /* 59   T3423 value GPRS timer 9.9.3.16 O   TV  2 */
3691     ELEM_OPT_TV(0x59, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER, " - T3423 value");
3692     /* 4A   Equivalent PLMNs    PLMN list 9.9.2.8   O   TLV 5-47 */
3693     ELEM_OPT_TLV(0x4a, GSM_A_PDU_TYPE_COMMON, DE_PLMN_LIST, " - PLMN list");
3694     /* 34   Emergency Number List   Emergency Number List 9.9.3.37  O   TLV 5-50 */
3695     ELEM_OPT_TLV(0x34, GSM_A_PDU_TYPE_DTAP, DE_EMERGENCY_NUM_LIST, NULL);
3696     /* 64   EPS network feature support EPS network feature support 9.9.3.12A   O   TLV 3 */
3697     ELEM_OPT_TLV(0x64, NAS_PDU_TYPE_EMM, DE_EMM_EPS_NET_FEATURE_SUP, NULL);
3698     /* F-   Additional update result    Additional update result 9.9.3.0A   O   TV  1 */
3699     ELEM_OPT_TV_SHORT( 0xF0 , NAS_PDU_TYPE_EMM, DE_EMM_ADD_UPD_RES, NULL );
3700     /* 5E   T3412 extended value GPRS timer 3 9.9.3.16B O   TLV  3 */
3701     ELEM_OPT_TLV(0x5E, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_3, " - T3412 extended value");
3702
3703     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3704 }
3705 /*
3706  * 8.2.27   Tracking area update complete
3707  * No more IE's
3708  */
3709 /*
3710  * 8.2.28   Tracking area update reject
3711  */
3712 static void
3713 nas_emm_trac_area_upd_rej(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3714 {
3715     guint32 curr_offset;
3716     guint32 consumed;
3717     guint   curr_len;
3718
3719     curr_offset = offset;
3720     curr_len    = len;
3721
3722     /* EMM cause    EMM cause 9.9.3.9   M   V   1 */
3723     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_CAUSE, NULL);
3724     /* 5F   T3346 value GPRS timer 2 9.9.3.16A O   TLV  3 */
3725     ELEM_OPT_TLV(0x5F, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_2, " - T3346 value");
3726
3727     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3728 }
3729 /*
3730  * 8.2.29   Tracking area update request
3731  */
3732 static void
3733 nas_emm_trac_area_upd_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3734 {
3735
3736     guint32 curr_offset, bit_offset;
3737     guint32 consumed;
3738     guint   curr_len;
3739
3740     curr_offset = offset;
3741     curr_len    = len;
3742
3743     bit_offset = curr_offset<<3;
3744
3745     /*  NAS key set identifierASME  NAS key set identifier 9.9.3.21 M   V   1/2 */
3746     de_emm_nas_key_set_id_bits(tvb, tree, bit_offset, " ASME");
3747     bit_offset+=4;
3748
3749     /*  EPS update type EPS update type 9.9.3.14    M   V   1/2 */
3750     proto_tree_add_bits_item(tree, hf_nas_eps_active_flg, tvb, bit_offset, 1, ENC_BIG_ENDIAN);
3751     bit_offset++;
3752     proto_tree_add_bits_item(tree, hf_nas_eps_eps_update_type_value, tvb, bit_offset, 3, ENC_BIG_ENDIAN);
3753     /*bit_offset+=3;*/
3754
3755     /* Fix the lengths */
3756     curr_len--;
3757     curr_offset++;
3758     /*  Old GUTI    EPS mobile identity 9.9.3.12    M   LV  12 */
3759     ELEM_MAND_LV(NAS_PDU_TYPE_EMM, DE_EMM_EPS_MID, " - Old GUTI");
3760     /* No more Mandatory elements */
3761
3762     /*  B-  NAS key set identifier  Non-current native NAS key set identifier 9.9.3.21  O   TV  1 */
3763     ELEM_OPT_TV_SHORT( 0xb0 , NAS_PDU_TYPE_EMM, DE_EMM_NAS_KEY_SET_ID , " - Non-current native NAS key set identifier" );
3764     /* 8-   GPRS ciphering key sequence number  Ciphering key sequence number 9.9.3.4a  O   TV  1  */
3765     ELEM_OPT_TV_SHORT(0x80, GSM_A_PDU_TYPE_COMMON, DE_CIPH_KEY_SEQ_NUM, " - GPRS ciphering key sequence number");
3766     /* 19   Old P-TMSI signature    P-TMSI signature 9.9.3.26   O   TV  4 */
3767     ELEM_OPT_TV( 0x19 , GSM_A_PDU_TYPE_GM, DE_P_TMSI_SIG, " - Old P-TMSI Signature");
3768     /* 50   Additional GUTI EPS mobile identity 9.9.3.12    O   TLV 13 */
3769     ELEM_OPT_TLV(0x50, NAS_PDU_TYPE_EMM, DE_EMM_EPS_MID, " - Additional GUTI");
3770     /* 55   NonceUE Nonce 9.9.3.25  O   TV  5 */
3771     ELEM_OPT_TV(0x55, NAS_PDU_TYPE_EMM, DE_EMM_NONCE, " - NonceUE");
3772     /* 58   UE network capability   UE network capability 9.9.3.34  O   TLV 4-15 */
3773     ELEM_OPT_TLV(0x58, NAS_PDU_TYPE_EMM, DE_EMM_UE_NET_CAP, NULL);
3774     /* 52   Last visited registered TAI Tracking area identity 9.9.3.32 O   TV  6 */
3775     ELEM_OPT_TV(0x52, NAS_PDU_TYPE_EMM, DE_EMM_TRAC_AREA_ID, " - Last visited registered TAI");
3776     /* 5C   DRX parameter   DRX parameter 9.9.3.8   O   TV  3 */
3777     ELEM_OPT_TV(0x5c, GSM_A_PDU_TYPE_GM, DE_DRX_PARAM, NULL );
3778     /* A-   UE radio capability information update needed   UE radio capability information update needed 9.9.3.35  O   TV  1 */
3779     ELEM_OPT_TV_SHORT( 0xA0 , NAS_PDU_TYPE_EMM, DE_EMM_UE_RA_CAP_INF_UPD_NEED , NULL );
3780     /* 57   EPS bearer context status   EPS bearer context status 9.9.2.1   O   TLV 4 */
3781     ELEM_OPT_TLV(0x57, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_EPS_BE_CTX_STATUS, NULL);
3782     /* 31   MS network capability   MS network capability 9.9.3.20  O   TLV 4-10 */
3783     ELEM_OPT_TLV( 0x31 , GSM_A_PDU_TYPE_GM, DE_MS_NET_CAP , NULL );
3784     /* 13   Old location area identification    Location area identification 9.9.2.2    O   TV  6 */
3785     ELEM_OPT_TV(0x13, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_LOC_AREA_ID, " - Old location area identification");
3786     /* 9-   TMSI status TMSI status 9.9.3.31    O   TV  1  */
3787     ELEM_OPT_TV_SHORT( 0x90 , GSM_A_PDU_TYPE_GM, DE_TMSI_STAT , NULL );
3788     /* 11   Mobile station classmark 2  Mobile station classmark 2 9.9.2.5  O   TLV 5 */
3789     ELEM_OPT_TLV( 0x11, NAS_PDU_TYPE_COMMON, DE_EPS_MS_CM_2 , NULL );
3790     /* 20   Mobile station classmark 3  Mobile station classmark 3 9.9.2.5  O   TLV 2-34 */
3791     ELEM_OPT_TLV( 0x20, NAS_PDU_TYPE_COMMON, DE_EPS_MS_CM_3 , NULL );
3792     /* 40   Supported Codecs    Supported Codec List 9.9.2.10   O   TLV 5-n */
3793     ELEM_OPT_TLV(0x40, GSM_A_PDU_TYPE_DTAP, DE_SUP_CODEC_LIST, " - Supported Codecs");
3794     /* F-   Additional update type  Additional update type 9.9.3.0B O   TV  1 */
3795     ELEM_OPT_TV_SHORT( 0xF0 , NAS_PDU_TYPE_EMM, DE_EMM_ADD_UPD_TYPE, NULL );
3796     /* 5D   Voice domain preference and UE's usage setting  Voice domain preference and UE's usage setting 9.9.3.44 O   TLV 3 */
3797     ELEM_OPT_TLV(0x5D, GSM_A_PDU_TYPE_GM, DE_VOICE_DOMAIN_PREF, NULL);
3798     /* E-   Old GUTI type  GUTI type 9.9.3.45 O   TV  1 */
3799     ELEM_OPT_TV_SHORT(0xE0 , NAS_PDU_TYPE_EMM, DE_EMM_GUTI_TYPE, " - Old GUTI type");
3800     /* D-   Device properties  Device properties 9.9.2.0A O   TV  1 */
3801     ELEM_OPT_TV_SHORT(0xD0 , GSM_A_PDU_TYPE_GM, DE_DEVICE_PROPERTIES, NULL);
3802     /* C-   MS network feature support  MS network feature support 9.9.3.20A 0  TV 1 */
3803     ELEM_OPT_TV_SHORT(0xC0 , GSM_A_PDU_TYPE_COMMON, DE_MS_NET_FEAT_SUP, NULL);
3804     /* 10   TMSI based NRI container  Network resource identifier container 9.9.3.24A 0  TLV 4 */
3805     ELEM_OPT_TLV(0x10, GSM_A_PDU_TYPE_GM, DE_NET_RES_ID_CONT, " - TMSI based NRI container");
3806
3807     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3808 }
3809
3810 /*
3811  * 8.2.30   Uplink NAS Transport
3812  */
3813 static void
3814 nas_emm_ul_nas_trans(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3815 {
3816     guint32 curr_offset;
3817     guint32 consumed;
3818     guint   curr_len;
3819
3820     curr_offset = offset;
3821     curr_len    = len;
3822
3823     pinfo->link_dir = P2P_DIR_UL;
3824
3825     /* NAS message container    NAS message container 9.9.3.22  M   LV  3-252*/
3826     ELEM_MAND_LV(NAS_PDU_TYPE_EMM, DE_EMM_NAS_MSG_CONT, NULL);
3827
3828     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3829 }
3830
3831 /*
3832  * 8.2.31   Downlink generic NAS transport
3833  */
3834 static void
3835 nas_emm_dl_gen_nas_trans(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3836 {
3837     guint32 curr_offset;
3838     guint32 consumed;
3839     guint   curr_len;
3840
3841     curr_offset = offset;
3842     curr_len    = len;
3843
3844     pinfo->link_dir = P2P_DIR_DL;
3845
3846     /* Generic message container type Generic message container type 9.9.3.42 M V 1 */
3847     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_GEN_MSG_CONT_TYPE, NULL);
3848     /* Generic message container Generic message container 9.9.3.43 M LV-E 3-n */
3849     ELEM_MAND_LV_E(NAS_PDU_TYPE_EMM, DE_EMM_GEN_MSG_CONT, NULL)
3850     /* 65 Additional information Additional information 9.9.2.0 O TLV 3-n */
3851     ELEM_OPT_TLV(0x65, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_ADD_INFO, NULL);
3852
3853     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3854
3855     eps_nas_gen_msg_cont_type = 0;
3856 }
3857
3858 /*
3859  * 8.2.32   Uplink generic NAS transport
3860  */
3861 static void
3862 nas_emm_ul_gen_nas_trans(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
3863 {
3864     guint32 curr_offset;
3865     guint32 consumed;
3866     guint   curr_len;
3867
3868     curr_offset = offset;
3869     curr_len    = len;
3870
3871     pinfo->link_dir = P2P_DIR_UL;
3872
3873     /* Generic message container type Generic message container type 9.9.3.42 M V 1 */
3874     ELEM_MAND_V(NAS_PDU_TYPE_EMM, DE_EMM_GEN_MSG_CONT_TYPE, NULL);
3875     /* Generic message container Generic message container 9.9.3.43 M LV-E 3-n */
3876     ELEM_MAND_LV_E(NAS_PDU_TYPE_EMM, DE_EMM_GEN_MSG_CONT, NULL)
3877     /* 65 Additional information Additional information 9.9.2.0 O TLV 3-n */
3878     ELEM_OPT_TLV(0x65, NAS_PDU_TYPE_COMMON, DE_EPS_CMN_ADD_INFO, NULL);
3879
3880     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3881
3882     eps_nas_gen_msg_cont_type = 0;
3883 }
3884
3885 /*
3886  * 8.3  EPS session management messages
3887  */
3888
3889 /*
3890  * 8.3.1    Activate dedicated EPS bearer context accept
3891  */
3892 static void
3893 nas_esm_act_ded_eps_bearer_ctx_acc(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
3894 {
3895     guint32 curr_offset;
3896     guint32 consumed;
3897     guint   curr_len;
3898
3899     if (len == 0)
3900         return;
3901
3902     curr_offset = offset;
3903     curr_len = len;
3904
3905     /* This message is sent by the UE to the network */
3906     pinfo->link_dir = P2P_DIR_UL;
3907
3908     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
3909     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
3910
3911     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3912 }
3913
3914 /*
3915  * 8.3.2    Activate dedicated EPS bearer context reject
3916  */
3917 static void
3918 nas_esm_act_ded_eps_bearer_ctx_rej(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
3919 {
3920     guint32 curr_offset;
3921     guint32 consumed;
3922     guint   curr_len;
3923
3924     curr_offset = offset;
3925     curr_len    = len;
3926
3927     /* This message is sent by UE to the network to reject activation of a dedicated EPS bearer context */
3928     pinfo->link_dir = P2P_DIR_UL;
3929
3930     /* ESM cause    ESM cause 9.9.4.2   M   V   1 */
3931     ELEM_MAND_V(NAS_PDU_TYPE_ESM, DE_ESM_CAUSE, NULL);
3932     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
3933     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
3934
3935     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3936 }
3937 /*
3938  * 8.3.3    Activate dedicated EPS bearer context request
3939  */
3940 static void
3941 nas_esm_act_ded_eps_bearer_ctx_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
3942 {
3943     guint32 curr_offset, bit_offset;
3944     guint32 consumed;
3945     guint   curr_len;
3946
3947     curr_offset = offset;
3948     curr_len    = len;
3949
3950     /* This message is sent by the network to the UE to request activation of a dedicated EPS bearer context... */
3951     pinfo->link_dir = P2P_DIR_DL;
3952
3953
3954     /* Spare half octet Spare half octet 9.9.2.9    M   V   1/2 */
3955     bit_offset = curr_offset<<3;
3956     proto_tree_add_bits_item(tree, hf_nas_eps_emm_spare_half_octet, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
3957     bit_offset+=4;
3958     /* Linked EPS bearer identity   Linked EPS bearer identity 9.9.4.6  M   V   1/2 */
3959     proto_tree_add_bits_item(tree, hf_nas_eps_esm_linked_bearer_id, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
3960     /*bit_offset+=4;*/
3961     /* Fix the lengths */
3962     curr_len--;
3963     curr_offset++;
3964
3965     /* EPS QoS  EPS quality of service 9.9.4.3  M   LV  2-10 */
3966     ELEM_MAND_LV(NAS_PDU_TYPE_ESM, DE_ESM_EPS_QOS, NULL);
3967     /* TFT  Traffic flow template 9.9.4.16  M   LV  2-256 */
3968     ELEM_MAND_LV( GSM_A_PDU_TYPE_GM, DE_TRAFFIC_FLOW_TEMPLATE , NULL );
3969     /* 5D   Transaction identifier  Transaction identifier 9.9.4.17 O   TLV 3-4 */
3970     ELEM_OPT_TLV( 0x5d , GSM_A_PDU_TYPE_GM, DE_LINKED_TI , " - Transaction identifier" );
3971     /* 30   Negotiated QoS  Quality of service 9.9.4.12 O   TLV 14-18 */
3972     ELEM_OPT_TLV( 0x30 , GSM_A_PDU_TYPE_GM, DE_QOS , " - Negotiated QoS" );
3973     /* 32   Negotiated LLC SAPI LLC service access point identifier 9.9.4.7 O   TV  2 */
3974     ELEM_OPT_TV( 0x32 , GSM_A_PDU_TYPE_GM, DE_LLC_SAPI , " - Negotiated LLC SAPI" );
3975     /* 8-   Radio priority  Radio priority 9.9.4.13 O   TV  1 */
3976     ELEM_OPT_TV_SHORT ( 0x80 , GSM_A_PDU_TYPE_GM , DE_RAD_PRIO , NULL );
3977     /* 34   Packet flow Identifier  Packet flow Identifier 9.9.4.8  O   TLV 3 */
3978     ELEM_OPT_TLV( 0x34 , GSM_A_PDU_TYPE_GM, DE_PACKET_FLOW_ID , NULL );
3979     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
3980     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
3981
3982     EXTRANEOUS_DATA_CHECK(curr_len, 0);
3983 }
3984
3985 /*
3986  * 8.3.4    Activate default EPS bearer context accept
3987  */
3988 static void
3989 nas_esm_act_def_eps_bearer_ctx_acc(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
3990 {
3991     guint32 curr_offset;
3992     guint32 consumed;
3993     guint   curr_len;
3994
3995     curr_offset = offset;
3996     curr_len    = len;
3997
3998     if (len == 0)
3999         return;
4000
4001     /* This message is sent by the UE to the network to acknowledge activation of a default EPS bearer context */
4002     pinfo->link_dir = P2P_DIR_UL;
4003
4004     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253  */
4005     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4006
4007     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4008 }
4009
4010 /*
4011  * 8.3.5    Activate default EPS bearer context reject
4012  */
4013 static void
4014 nas_esm_act_def_eps_bearer_ctx_rej(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4015 {
4016     guint32 curr_offset;
4017     guint32 consumed;
4018     guint   curr_len;
4019
4020     curr_offset = offset;
4021     curr_len    = len;
4022
4023     /* This message is sent by UE to the network to reject activation of a default EPS bearer context. */
4024     pinfo->link_dir = P2P_DIR_UL;
4025
4026     /*  ESM cause   ESM cause 9.9.4.4   M   V   1 */
4027     ELEM_MAND_V(NAS_PDU_TYPE_ESM, DE_ESM_CAUSE, NULL);
4028     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4029     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4030
4031     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4032 }
4033
4034 /*
4035  * 8.3.6 Activate default EPS bearer context request
4036  */
4037 static void
4038 nas_esm_act_def_eps_bearer_ctx_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4039 {
4040     guint32 curr_offset;
4041     guint32 consumed;
4042     guint   curr_len;
4043
4044     curr_offset = offset;
4045     curr_len    = len;
4046
4047     /* This message is sent by the network to the UE to request activation of a default EPS bearer context. */
4048     pinfo->link_dir = P2P_DIR_DL;
4049
4050     /*  EPS QoS EPS quality of service 9.9.4.3  M   LV  2-10 */
4051     ELEM_MAND_LV(NAS_PDU_TYPE_ESM, DE_ESM_EPS_QOS, NULL);
4052     /*  Access point name   Access point name 9.9.4.1   M   LV  2-101 */
4053     ELEM_MAND_LV( GSM_A_PDU_TYPE_GM, DE_ACC_POINT_NAME , NULL );
4054     /*  PDN address PDN address 9.9.4.9 M   LV  6-14 DE_ESM_PDN_ADDR*/
4055     ELEM_MAND_LV( NAS_PDU_TYPE_ESM, DE_ESM_PDN_ADDR , NULL );
4056     /* 5D   Transaction identifier  Transaction identifier 9.9.4.17 O   TLV 3-4 */
4057     ELEM_OPT_TLV( 0x5d , GSM_A_PDU_TYPE_GM, DE_LINKED_TI , " - Transaction identifier" );
4058     /* 30   Negotiated QoS  Quality of service 9.9.4.12 O   TLV 14-18 */
4059     ELEM_OPT_TLV( 0x30 , GSM_A_PDU_TYPE_GM, DE_QOS , " - Negotiated QoS" );
4060     /* 32   Negotiated LLC SAPI LLC service access point identifier 9.9.4.7 O   TV  2 */
4061     ELEM_OPT_TV( 0x32 , GSM_A_PDU_TYPE_GM, DE_LLC_SAPI , " - Negotiated LLC SAPI" );
4062     /* 8-   Radio priority  Radio priority 9.9.4.13 O   TV  1 */
4063     ELEM_OPT_TV_SHORT ( 0x80 , GSM_A_PDU_TYPE_GM , DE_RAD_PRIO , NULL );
4064     /* 34   Packet flow Identifier  Packet flow Identifier 9.9.4.8  O   TLV 3 */
4065     ELEM_OPT_TLV( 0x34 , GSM_A_PDU_TYPE_GM, DE_PACKET_FLOW_ID , NULL );
4066     /* 5E   APN-AMBR    APN aggregate maximum bit rate 9.9.4.2  O   TLV 4-8 DE_ESM_APN_AGR_MAX_BR*/
4067     ELEM_OPT_TLV( 0x5e , NAS_PDU_TYPE_ESM, DE_ESM_APN_AGR_MAX_BR , NULL );
4068     /* 58   ESM cause   ESM cause 9.9.4.4   O   TV  2 */
4069     ELEM_OPT_TV( 0x58 , NAS_PDU_TYPE_ESM, DE_ESM_CAUSE , NULL );
4070     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4071     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4072     /* B-   Connectivity type  Connectivity type 9.9.4.2A 0  TV 1 */
4073     ELEM_OPT_TV_SHORT(0xB0 , GSM_A_PDU_TYPE_GM, DE_SM_CONNECTIVITY_TYPE, NULL);
4074
4075     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4076 }
4077
4078 /*
4079  * 8.3.7    Bearer resource allocation reject
4080  */
4081 static void
4082 nas_esm_bearer_res_all_rej(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4083 {
4084     guint32 curr_offset;
4085     guint32 consumed;
4086     guint   curr_len;
4087
4088     curr_offset = offset;
4089     curr_len    = len;
4090
4091     /* This message is sent by the network to the UE to reject the allocation of a dedicated bearer resource. */
4092     pinfo->link_dir = P2P_DIR_DL;
4093
4094     /*  ESM cause   ESM cause 9.9.4.4   M   V   1 */
4095     ELEM_MAND_V(NAS_PDU_TYPE_ESM, DE_ESM_CAUSE, NULL);
4096     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4097     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4098     /* 37   T3396 value GPRS timer 3 9.9.3.16B O   TLV  3 */
4099     ELEM_OPT_TLV(0x37, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_3, " - T3396 value");
4100
4101     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4102 }
4103
4104 /*
4105  * 8.3.8    Bearer resource allocation request
4106  */
4107 static void
4108 nas_esm_bearer_res_all_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4109 {
4110     guint32 curr_offset, bit_offset;
4111     guint32 consumed;
4112     guint   curr_len;
4113
4114     curr_offset = offset;
4115     curr_len    = len;
4116
4117     /* This message is sent by the UE to the network to request the allocation of a dedicated bearer resource. */
4118     pinfo->link_dir = P2P_DIR_UL;
4119
4120     /*  Spare half octet    Spare half octet 9.9.2.9    M   V   1/2 */
4121     bit_offset = curr_offset<<3;
4122     proto_tree_add_bits_item(tree, hf_nas_eps_emm_spare_half_octet, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
4123     bit_offset+=4;
4124     /*  Linked EPS bearer identity  Linked EPS bearer identity 9.9.4.6  M   V   1/2 */
4125     proto_tree_add_bits_item(tree, hf_nas_eps_esm_linked_bearer_id, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
4126     /*bit_offset+=4;*/
4127     /* Fix the lengths */
4128     curr_len--;
4129     curr_offset++;
4130
4131     /*  Traffic flow aggregate  Traffic flow aggregate description 9.9.4.15 M   LV  2-256 */
4132     ELEM_MAND_LV( GSM_A_PDU_TYPE_GM, DE_TRAFFIC_FLOW_TEMPLATE , " - Traffic flow aggregate" );
4133     /*  Required traffic flow QoS   EPS quality of service 9.9.4.3  M   LV  2-10 */
4134     ELEM_MAND_LV(NAS_PDU_TYPE_ESM, DE_ESM_EPS_QOS, " - Required traffic flow QoS");
4135     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4136     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4137     /* C-   Device properties  Device properties 9.9.2.0A O   TV  1 */
4138     ELEM_OPT_TV_SHORT(0xC0 , GSM_A_PDU_TYPE_GM, DE_DEVICE_PROPERTIES, NULL);
4139
4140     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4141 }
4142 /*
4143  * 8.3.9    Bearer resource modification reject
4144  */
4145 static void
4146 nas_esm_bearer_res_mod_rej(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4147 {
4148     guint32 curr_offset;
4149     guint32 consumed;
4150     guint   curr_len;
4151
4152     curr_offset = offset;
4153     curr_len    = len;
4154
4155     /* This message is sent by the network to the UE to reject the modification of a dedicated bearer resource. */
4156     pinfo->link_dir = P2P_DIR_DL;
4157
4158     /*  ESM cause   ESM cause 9.9.4.4   M   V   1 */
4159     ELEM_MAND_V(NAS_PDU_TYPE_ESM, DE_ESM_CAUSE, NULL);
4160     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4161     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4162     /* 37   T3396 value GPRS timer 3 9.9.3.16B O   TLV  3 */
4163     ELEM_OPT_TLV(0x37, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_3, " - T3396 value");
4164
4165     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4166 }
4167 /*
4168  * 8.3.10   Bearer resource modification request
4169  */
4170 static void
4171 nas_esm_bearer_res_mod_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4172 {
4173     guint32 curr_offset, bit_offset;
4174     guint32 consumed;
4175     guint   curr_len;
4176
4177     curr_offset = offset;
4178     curr_len    = len;
4179
4180     /* This message is sent by the UE to the network to request the modification of a dedicated bearer resource. */
4181     pinfo->link_dir = P2P_DIR_UL;
4182
4183     /*  Spare half octet    Spare half octet 9.9.2.9    M   V   1/2 */
4184     bit_offset = curr_offset<<3;
4185     proto_tree_add_bits_item(tree, hf_nas_eps_emm_spare_half_octet, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
4186     bit_offset+=4;
4187     /* EPS bearer identity for packet filter    Linked EPS bearer identity 9.9.4.6  M   V   1/2 */
4188     proto_tree_add_bits_item(tree, hf_nas_eps_esm_linked_bearer_id, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
4189     /*bit_offset+=4;*/
4190     /* Fix the lengths */
4191     curr_len--;
4192     curr_offset++;
4193     /* Traffic flow aggregate   Traffic flow aggregate description 9.9.4.15 M   LV  2-256 */
4194     ELEM_MAND_LV( GSM_A_PDU_TYPE_GM, DE_TRAFFIC_FLOW_TEMPLATE , " - Traffic flow aggregate" );
4195     /* 5B   Required traffic flow QoS   EPS quality of service 9.9.4.3  O   TLV 3-11 */
4196     ELEM_OPT_TLV( 0x5B , NAS_PDU_TYPE_ESM, DE_ESM_EPS_QOS , " - Required traffic flow QoS" );
4197     /* 58   ESM cause   ESM cause 9.9.4.4   O   TV  2 */
4198     ELEM_OPT_TV( 0x58 , NAS_PDU_TYPE_ESM, DE_ESM_CAUSE , NULL );
4199     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253  */
4200     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4201     /* C-   Device properties  Device properties 9.9.2.0A O   TV  1 */
4202     ELEM_OPT_TV_SHORT(0xC0 , GSM_A_PDU_TYPE_GM, DE_DEVICE_PROPERTIES, NULL);
4203
4204     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4205 }
4206 /*
4207  * 8.3.11 Deactivate EPS bearer context accept
4208  */
4209 static void
4210 nas_esm_deact_eps_bearer_ctx_acc(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4211 {
4212     guint32 curr_offset;
4213     guint32 consumed;
4214     guint   curr_len;
4215
4216     curr_offset = offset;
4217     curr_len    = len;
4218
4219     if (len == 0)
4220         return;
4221
4222     /* This message is sent by the UE to acknowledge deactivation of the EPS bearer context... */
4223     pinfo->link_dir = P2P_DIR_UL;
4224
4225     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV */
4226     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4227
4228     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4229 }
4230 /*
4231  * 8.3.12 Deactivate EPS bearer context request
4232  */
4233 static void
4234 nas_esm_deact_eps_bearer_ctx_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4235 {
4236     guint32 curr_offset;
4237     guint32 consumed;
4238     guint   curr_len;
4239
4240     curr_offset = offset;
4241     curr_len    = len;
4242
4243     /* This message is sent by the network to request deactivation of an active EPS bearer context. */
4244     pinfo->link_dir = P2P_DIR_DL;
4245
4246     /*  ESM cause   ESM cause 9.9.4.4   M   V   1 */
4247     ELEM_MAND_V(NAS_PDU_TYPE_ESM, DE_ESM_CAUSE, NULL);
4248     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV */
4249     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4250     /* 37   T3396 value GPRS timer 3 9.9.3.16B O   TLV  3 */
4251     ELEM_OPT_TLV(0x37, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_3, " - T3396 value");
4252
4253     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4254 }
4255
4256 /*
4257  * 8.3.13 ESM information request
4258  * No IE:s
4259  */
4260 static void
4261 nas_esm_inf_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
4262 {
4263     guint32 curr_offset;
4264     guint   curr_len;
4265
4266     curr_offset = offset;
4267     curr_len    = len;
4268
4269     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4270 }
4271 /*
4272  * 8.3.14 ESM information response
4273  */
4274 static void
4275 nas_esm_inf_resp(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4276 {
4277     guint32 curr_offset;
4278     guint32 consumed;
4279     guint   curr_len;
4280
4281     curr_offset = offset;
4282     curr_len    = len;
4283
4284     if (len == 0)
4285         return;
4286
4287     /* This message is sent by the UE to the network in response to an ESM INFORMATION REQUEST... */
4288     pinfo->link_dir = P2P_DIR_UL;
4289
4290     /* 28   Access point name   Access point name 9.9.4.1   O   TLV 3-102 */
4291     ELEM_OPT_TLV( 0x28 , GSM_A_PDU_TYPE_GM, DE_ACC_POINT_NAME , NULL );
4292     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4293     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4294
4295     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4296 }
4297 /*
4298  * 8.3.15 ESM status
4299  */
4300 static void
4301 nas_esm_status(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
4302 {
4303     guint32 curr_offset;
4304     guint32 consumed;
4305     guint   curr_len;
4306
4307     curr_offset = offset;
4308     curr_len    = len;
4309
4310     /* ESM cause    ESM cause 9.9.4.4   M   V   1 */
4311     ELEM_MAND_V(NAS_PDU_TYPE_ESM, DE_ESM_CAUSE, NULL);
4312
4313     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4314 }
4315 /*
4316  * 8.3.16 Modify EPS bearer context accept
4317  */
4318 static void
4319 nas_esm_mod_eps_bearer_ctx_acc(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4320 {
4321     guint32 curr_offset;
4322     guint32 consumed;
4323     guint   curr_len;
4324
4325     curr_offset = offset;
4326     curr_len    = len;
4327
4328     if (len == 0)
4329         return;
4330
4331     /* This message is sent by the UE to the network to acknowledge the modification of an active EPS bearer context. */
4332     pinfo->link_dir = P2P_DIR_UL;
4333
4334     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4335     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4336
4337     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4338 }
4339 /*
4340  * 8.3.17 Modify EPS bearer context reject
4341  */
4342 static void
4343 nas_esm_mod_eps_bearer_ctx_rej(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4344 {
4345     guint32 curr_offset;
4346     guint32 consumed;
4347     guint   curr_len;
4348
4349     curr_offset = offset;
4350     curr_len    = len;
4351
4352     /* This message is sent by the UE or the network to reject a modification of an active EPS bearer context. */
4353     pinfo->link_dir = P2P_DIR_UL;
4354
4355     /* ESM cause    ESM cause 9.9.4.4   M   V   1 */
4356     ELEM_MAND_V(NAS_PDU_TYPE_ESM, DE_ESM_CAUSE, NULL);
4357     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4358     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4359
4360     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4361 }
4362 /*
4363  * 8.3.18 Modify EPS bearer context request
4364  */
4365 static void
4366 nas_esm_mod_eps_bearer_ctx_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4367 {
4368     guint32 curr_offset;
4369     guint32 consumed;
4370     guint   curr_len;
4371
4372     curr_offset = offset;
4373     curr_len    = len;
4374
4375     if (len == 0)
4376         return;
4377
4378     /*This message is sent by the network to inform the UE about events which are relevant for the upper layer... */
4379     pinfo->link_dir = P2P_DIR_DL;
4380
4381     /* 5B   New EPS QoS EPS quality of service 9.9.4.3  O   TLV 3-11 */
4382     ELEM_OPT_TLV( 0x5B , NAS_PDU_TYPE_ESM, DE_ESM_EPS_QOS , " - New EPS QoS" );
4383     /* 36   TFT Traffic flow template 9.9.4.16  O   TLV 3-257 */
4384     ELEM_OPT_TLV( 0x36 , GSM_A_PDU_TYPE_GM, DE_TRAFFIC_FLOW_TEMPLATE , NULL );
4385     /* 30   New QoS Quality of service 9.9.4.12 O   TLV 14-18 */
4386     ELEM_OPT_TLV( 0x30 , GSM_A_PDU_TYPE_GM, DE_QOS , " - New QoS" );
4387     /* 32   Negotiated LLC SAPI LLC service access point identifier 9.9.4.7 O   TV  2 */
4388     ELEM_OPT_TV( 0x32 , GSM_A_PDU_TYPE_GM, DE_LLC_SAPI , " - Negotiated LLC SAPI" );
4389     /* 8-   Radio priority  Radio priority 9.9.4.13 O   TV  1 */
4390     ELEM_OPT_TV_SHORT ( 0x80 , GSM_A_PDU_TYPE_GM , DE_RAD_PRIO , NULL );
4391     /* 34   Packet flow Identifier  Packet flow Identifier 9.9.4.8  O   TLV 3 */
4392     ELEM_OPT_TLV( 0x34 , GSM_A_PDU_TYPE_GM, DE_PACKET_FLOW_ID , NULL );
4393     /* 5E   APN-AMBR    APN aggregate maximum bit rate 9.9.4.2  O   TLV 4-8 */
4394     ELEM_OPT_TLV( 0x5E , NAS_PDU_TYPE_ESM, DE_ESM_APN_AGR_MAX_BR , NULL );
4395     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4396     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4397
4398     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4399 }
4400 /*
4401  * 8.3.18A Notification
4402  */
4403 static void
4404 nas_esm_notification(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len)
4405 {
4406     guint32 curr_offset;
4407     guint32 consumed;
4408     guint   curr_len;
4409
4410     curr_offset = offset;
4411     curr_len    = len;
4412
4413     /* Notification indicator Notification indicator 9.9.4.7A M LV 2 */
4414     ELEM_MAND_LV(NAS_PDU_TYPE_ESM, DE_ESM_NOTIF_IND, NULL);
4415
4416     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4417 }
4418
4419 /*
4420  * 8.3.19 PDN connectivity reject
4421  */
4422 static void
4423 nas_esm_pdn_con_rej(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4424 {
4425     guint32 curr_offset;
4426     guint32 consumed;
4427     guint   curr_len;
4428
4429     curr_offset = offset;
4430     curr_len    = len;
4431
4432     /*This message is sent by the network to the UE to reject establishment of a PDN connection. */
4433     pinfo->link_dir = P2P_DIR_DL;
4434
4435     /* ESM cause    ESM cause 9.9.4.4   M   V   1 */
4436     ELEM_MAND_V(NAS_PDU_TYPE_ESM, DE_ESM_CAUSE, NULL);
4437     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4438     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4439     /* 37   T3396 value GPRS timer 3 9.9.3.16B O   TLV  3 */
4440     ELEM_OPT_TLV(0x37, GSM_A_PDU_TYPE_GM, DE_GPRS_TIMER_3, " - T3396 value");
4441
4442     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4443 }
4444
4445 /*
4446  * 8.3.20 PDN connectivity request
4447  */
4448 static void
4449 nas_esm_pdn_con_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4450 {
4451     guint32 curr_offset;
4452     guint32 consumed;
4453     guint   curr_len;
4454     int     bit_offset;
4455
4456     curr_offset = offset;
4457     curr_len    = len;
4458
4459     /*This message is sent by the UE to the network to initiate establishment of a PDN connection. */
4460     pinfo->link_dir = P2P_DIR_UL;
4461
4462     /* PDN type PDN type 9.9.4.10 M V 1/2 */
4463     bit_offset = curr_offset<<3;
4464     proto_tree_add_bits_item(tree, hf_nas_eps_esm_pdn_type, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
4465     bit_offset+=4;
4466
4467     /* Request type 9.9.4.14 M V 1/2 */
4468     proto_tree_add_bits_item(tree, hf_nas_eps_esm_request_type, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
4469     /*bit_offset+=4;*/
4470     /* Fix the lengths */
4471     curr_len--;
4472     curr_offset++;
4473     if (curr_len == 0)
4474         return;
4475
4476     /* D- ESM information transfer flag 9.9.4.5 O TV 1 */
4477     ELEM_OPT_TV_SHORT( 0xd0 , NAS_PDU_TYPE_ESM, DE_ESM_INF_TRF_FLG , NULL );
4478     /* 28 Access point name 9.9.4.1 O TLV 3-102 */
4479     ELEM_OPT_TLV( 0x28 , GSM_A_PDU_TYPE_GM, DE_ACC_POINT_NAME , NULL );
4480     /* 27 Protocol configuration options 9.9.4.11 O TLV 3-253 */
4481     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4482     /* C-   Device properties  Device properties 9.9.2.0A O   TV  1 */
4483     ELEM_OPT_TV_SHORT(0xC0 , GSM_A_PDU_TYPE_GM, DE_DEVICE_PROPERTIES, NULL);
4484
4485     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4486 }
4487 /*
4488  * 8.3.20 PDN disconnect reject
4489  */
4490 static void
4491 nas_esm_pdn_disc_rej(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4492 {
4493     guint32 curr_offset;
4494     guint32 consumed;
4495     guint   curr_len;
4496
4497     curr_offset = offset;
4498     curr_len    = len;
4499
4500     /*This message is sent by the UE to the network to initiate establishment of a PDN connection. */
4501     pinfo->link_dir = P2P_DIR_UL;
4502
4503     /* ESM cause    ESM cause 9.9.4.4   M   V   1 */
4504     ELEM_MAND_V(NAS_PDU_TYPE_ESM, DE_ESM_CAUSE, NULL);
4505     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4506     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4507
4508     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4509 }
4510 /*
4511  * 8.3.21 PDN disconnect request
4512  */
4513 static void
4514 nas_esm_pdn_disc_req(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len)
4515 {
4516     guint32 curr_offset, bit_offset;
4517     guint32 consumed;
4518     guint   curr_len;
4519
4520     curr_offset = offset;
4521     curr_len    = len;
4522
4523     /* This message is sent by the network to the UE to reject release of a PDN connection. */
4524     pinfo->link_dir = P2P_DIR_DL;
4525
4526     /*  Spare half octet    Spare half octet 9.9.2.9    M   V   1/2 */
4527     bit_offset = curr_offset<<3;
4528     proto_tree_add_bits_item(tree, hf_nas_eps_emm_spare_half_octet, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
4529     bit_offset+=4;
4530     /* Linked EPS bearer identity   Linked EPS bearer identity 9.9.4.6  M   V   1/2 */
4531     proto_tree_add_bits_item(tree, hf_nas_eps_esm_linked_bearer_id, tvb, bit_offset, 4, ENC_BIG_ENDIAN);
4532     /*bit_offset+=4;*/
4533     /* Fix the lengths */
4534     curr_len--;
4535     curr_offset++;
4536     if (curr_len == 0)
4537         return;
4538     /* 27   Protocol configuration options  Protocol configuration options 9.9.4.11 O   TLV 3-253 */
4539     ELEM_OPT_TLV( 0x27 , GSM_A_PDU_TYPE_GM, DE_PRO_CONF_OPT , NULL );
4540
4541     EXTRANEOUS_DATA_CHECK(curr_len, 0);
4542 }
4543
4544
4545 #define NUM_NAS_MSG_ESM (sizeof(nas_msg_esm_strings)/sizeof(value_string))
4546 static gint ett_nas_msg_esm[NUM_NAS_MSG_ESM];
4547 static void (*nas_msg_esm_fcn[])(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len) = {
4548     nas_esm_act_def_eps_bearer_ctx_req, /* Activate default EPS bearer context request*/
4549     nas_esm_act_def_eps_bearer_ctx_acc, /* Activate default EPS bearer context accept*/
4550     nas_esm_act_def_eps_bearer_ctx_rej, /* Activate default EPS bearer context reject*/
4551     nas_esm_act_ded_eps_bearer_ctx_req, /* Activate dedicated EPS bearer context request*/
4552     nas_esm_act_ded_eps_bearer_ctx_acc, /* Activate dedicated EPS bearer context accept*/
4553     nas_esm_act_ded_eps_bearer_ctx_rej, /* Activate dedicated EPS bearer context reject*/
4554     nas_esm_mod_eps_bearer_ctx_req,     /* Modify EPS bearer context request*/
4555     nas_esm_mod_eps_bearer_ctx_acc,     /* Modify EPS bearer context accept*/
4556     nas_esm_mod_eps_bearer_ctx_rej,     /* Modify EPS bearer context reject*/
4557     nas_esm_deact_eps_bearer_ctx_req,   /* Deactivate EPS bearer context request*/
4558     nas_esm_deact_eps_bearer_ctx_acc,   /* Deactivate EPS bearer context accept*/
4559     nas_esm_pdn_con_req,                /* 8.3.18 PDN connectivity request */
4560     nas_esm_pdn_con_rej,                /* PDN connectivity reject*/
4561     nas_esm_pdn_disc_req,               /* PDN disconnect request*/
4562     nas_esm_pdn_disc_rej,               /* PDN disconnect reject*/
4563     nas_esm_bearer_res_all_req,         /* Bearer resource allocation request*/
4564     nas_esm_bearer_res_all_rej,         /* Bearer resource allocation reject*/
4565     nas_esm_bearer_res_mod_req,         /* Bearer resource modification request*/
4566     nas_esm_bearer_res_mod_rej,         /* Bearer resource modification reject*/
4567     nas_esm_inf_req,                    /* ESM information request, No IE:s*/
4568     nas_esm_inf_resp,                   /* ESM information response*/
4569     nas_esm_notification,               /* Notification */
4570     nas_esm_status,                     /* ESM status */
4571
4572     NULL,   /* NONE */
4573 };
4574
4575 static void
4576 get_nas_esm_msg_params(guint8 oct, const gchar **msg_str, int *ett_tree, int *hf_idx, msg_fcn *msg_fcn_p)
4577 {
4578     gint            idx;
4579
4580     *msg_str   = match_strval_idx_ext((guint32) (oct & 0xff), &nas_msg_esm_strings_ext, &idx);
4581     *ett_tree  = ett_nas_msg_esm[idx];
4582     *hf_idx    = hf_nas_eps_msg_esm_type;
4583     *msg_fcn_p = nas_msg_esm_fcn[idx];
4584
4585     return;
4586 }
4587
4588
4589
4590 #define NUM_NAS_MSG_EMM (sizeof(nas_msg_emm_strings)/sizeof(value_string))
4591 static gint ett_nas_msg_emm[NUM_NAS_MSG_EMM];
4592 static void (*nas_msg_emm_fcn[])(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_, guint32 offset, guint len) = {
4593     nas_emm_attach_req,         /* Attach request */
4594     nas_emm_attach_acc,         /* Attach accept */
4595     nas_emm_attach_comp,        /* Attach complete */
4596     nas_emm_attach_rej,         /* Attach reject */
4597     nas_emm_detach_req,         /* Detach request */
4598     NULL,                       /* 8.2.10   Detach accept */
4599
4600     nas_emm_trac_area_upd_req,  /* Tracking area update request */
4601     nas_emm_trac_area_upd_acc,  /* Tracking area update accept */
4602     NULL,                       /* Tracking area update complete (No IE's)*/
4603     nas_emm_trac_area_upd_rej,  /* Tracking area update reject */
4604
4605     nas_emm_ext_serv_req,       /* Extended service request */
4606     nas_emm_serv_rej,           /* Service reject */
4607
4608     nas_emm_guti_realloc_cmd,   /* GUTI reallocation command */
4609     NULL,                       /* GUTI reallocation complete (No IE's) */
4610     nas_emm_auth_req,           /* Authentication request */
4611     nas_emm_auth_resp,          /* Authentication response */
4612     NULL,                       /* Authentication reject (No IE:s)*/
4613     nas_emm_id_req,             /* Identity request */
4614     nas_emm_id_res,             /* Identity response */
4615     nas_emm_auth_fail,          /* Authentication failure */
4616     nas_emm_sec_mode_cmd,       /* Security mode command */
4617     nas_emm_sec_mode_comp,      /* Security mode complete */
4618     nas_emm_sec_mode_rej,       /* Security mode reject */
4619
4620     nas_emm_emm_status,         /* EMM status */
4621     nas_emm_emm_inf,            /* EMM information */
4622     nas_emm_dl_nas_trans,       /* Downlink NAS transport */
4623     nas_emm_ul_nas_trans,       /* Uplink NAS transport */
4624     nas_emm_cs_serv_not,        /* 8.2.9    CS service notification */
4625     nas_emm_dl_gen_nas_trans,   /* Downlink generic NAS transport */
4626     nas_emm_ul_gen_nas_trans,   /* Uplink generic NAS transport */
4627     NULL,   /* NONE */
4628
4629 };
4630
4631 static void
4632 get_nas_emm_msg_params(guint8 oct, const gchar **msg_str, int *ett_tree, int *hf_idx, msg_fcn *msg_fcn_p)
4633 {
4634     gint            idx;
4635
4636     *msg_str   = match_strval_idx_ext((guint32) (oct & 0xff), &nas_msg_emm_strings_ext, &idx);
4637     *ett_tree  = ett_nas_msg_emm[idx];
4638     *hf_idx    = hf_nas_eps_msg_emm_type;
4639     *msg_fcn_p = nas_msg_emm_fcn[idx];
4640
4641     return;
4642 }
4643
4644 static const value_string nas_eps_esm_bearer_id_vals[] = {
4645     { 0x0,  "No EPS bearer identity assigned"},
4646     { 0x1,  "Reserved"},
4647     { 0x2,  "Reserved"},
4648     { 0x3,  "Reserved"},
4649     { 0x4,  "Reserved"},
4650     { 0x5,  "EPS bearer identity value 5"},
4651     { 0x6,  "EPS bearer identity value 6"},
4652     { 0x7,  "EPS bearer identity value 7"},
4653     { 0x8,  "EPS bearer identity value 8"},
4654     { 0x9,  "EPS bearer identity value 9"},
4655     { 0xa,  "EPS bearer identity value 10"},
4656     { 0xb,  "EPS bearer identity value 11"},
4657     { 0xc,  "EPS bearer identity value 12"},
4658     { 0xd,  "EPS bearer identity value 13"},
4659     { 0xe,  "EPS bearer identity value 14"},
4660     { 0xf,  "EPS bearer identity value 15"},
4661     { 0, NULL }
4662 };
4663
4664 /*
4665  * EPS session management messages.
4666  * A plain NAS message is pased to this function
4667  */
4668 static void
4669 disect_nas_eps_esm_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
4670 {
4671     const gchar *msg_str;
4672     guint32      len;
4673     gint         ett_tree;
4674     int          hf_idx;
4675     void       (*msg_fcn_p)(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len);
4676     guint8       oct;
4677
4678     len = tvb_length(tvb);
4679     /*
4680      * EPS bearer identity 9.3.2
4681      */
4682     proto_tree_add_item(tree, hf_nas_eps_bearer_id, tvb, offset, 1, ENC_BIG_ENDIAN);
4683     /* Protocol discriminator 9.2 */
4684     proto_tree_add_item(tree, hf_gsm_a_L3_protocol_discriminator, tvb, offset, 1, ENC_BIG_ENDIAN);
4685     offset++;
4686
4687     /* Procedure transaction identity 9.4
4688      * The procedure transaction identity and its use are defined in 3GPP TS 24.007
4689      */
4690     proto_tree_add_item(tree, hf_nas_eps_esm_proc_trans_id, tvb, offset, 1, ENC_BIG_ENDIAN);
4691     offset++;
4692
4693     /*messge type IE*/
4694     oct = tvb_get_guint8(tvb,offset);
4695     msg_fcn_p = NULL;
4696     ett_tree = -1;
4697     hf_idx = -1;
4698     msg_str = NULL;
4699
4700     get_nas_esm_msg_params(oct, &msg_str, &ett_tree, &hf_idx, &msg_fcn_p);
4701
4702     if (msg_str) {
4703         col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, msg_str);
4704     } else {
4705         proto_tree_add_text(tree, tvb, offset, 1,"Unknown message 0x%x",oct);
4706         return;
4707     }
4708
4709     /*
4710      * Add NAS message name
4711      */
4712     proto_tree_add_item(tree, hf_idx, tvb, offset, 1, ENC_BIG_ENDIAN);
4713     offset++;
4714
4715
4716     /*
4717      * decode elements
4718      */
4719     if (msg_fcn_p == NULL)
4720     {
4721         proto_tree_add_text(tree, tvb, offset, len - offset,
4722             "Message Elements");
4723     }
4724     else
4725     {
4726         (*msg_fcn_p)(tvb, tree, pinfo, offset, len - offset);
4727     }
4728
4729 }
4730 /*
4731  * The "real" security header has been dissected or if dissect_header = TRUE
4732  */
4733 static void
4734 dissect_nas_eps_emm_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gboolean second_header)
4735 {
4736     const gchar *msg_str;
4737     guint32      len;
4738     gint         ett_tree;
4739     int          hf_idx;
4740     void       (*msg_fcn_p)(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len);
4741     guint8       security_header_type, oct;
4742
4743     len = tvb_length(tvb);
4744
4745     /* 9.3.1    Security header type */
4746     if (second_header) {
4747         security_header_type = tvb_get_guint8(tvb,offset)>>4;
4748         proto_tree_add_item(tree, hf_nas_eps_security_header_type, tvb, offset, 1, ENC_BIG_ENDIAN);
4749         proto_tree_add_item(tree, hf_gsm_a_L3_protocol_discriminator, tvb, offset, 1, ENC_BIG_ENDIAN);
4750         offset++;
4751         if (security_header_type != 0) {
4752             /* Message authentication code */
4753             proto_tree_add_item(tree, hf_nas_eps_msg_auth_code, tvb, offset, 4, ENC_BIG_ENDIAN);
4754             offset+=4;
4755             /* Sequence number */
4756             proto_tree_add_item(tree, hf_nas_eps_seq_no, tvb, offset, 1, ENC_BIG_ENDIAN);
4757             offset++;
4758             if ((security_header_type == 2)||(security_header_type == 4))
4759                 /* Integrity protected and ciphered = 2, Integrity protected and ciphered with new EPS security context = 4 */
4760                 return;
4761             proto_tree_add_item(tree, hf_nas_eps_security_header_type, tvb, offset, 1, ENC_BIG_ENDIAN);
4762             proto_tree_add_item(tree, hf_gsm_a_L3_protocol_discriminator, tvb, offset, 1, ENC_BIG_ENDIAN);
4763             offset++;
4764         }
4765     }
4766     /* Messge type IE*/
4767     oct = tvb_get_guint8(tvb,offset);
4768     msg_fcn_p = NULL;
4769     ett_tree = -1;
4770     hf_idx = -1;
4771     msg_str = NULL;
4772
4773     get_nas_emm_msg_params(oct, &msg_str, &ett_tree, &hf_idx, &msg_fcn_p);
4774
4775     if (msg_str) {
4776         col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, msg_str);
4777     } else {
4778         proto_tree_add_text(tree, tvb, offset, 1,"Unknown message 0x%x",oct);
4779         return;
4780     }
4781
4782     /*
4783      * Add NAS message name
4784      */
4785     proto_tree_add_item(tree, hf_idx, tvb, offset, 1, ENC_BIG_ENDIAN);
4786     offset++;
4787
4788
4789     /*
4790      * decode elements
4791      */
4792     if (msg_fcn_p == NULL)
4793     {
4794         proto_tree_add_text(tree, tvb, offset, len - offset,
4795             "Message Elements");
4796     }
4797     else
4798     {
4799         (*msg_fcn_p)(tvb, tree, pinfo, offset, len - offset);
4800     }
4801
4802 }
4803
4804 static void
4805 dissect_nas_eps_plain(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
4806 {
4807     proto_item *item;
4808     proto_tree *nas_eps_tree;
4809     guint8      pd;
4810     int         offset = 0;
4811
4812     /* Save pinfo */
4813     gpinfo = pinfo;
4814
4815     /* make entry in the Protocol column on summary display */
4816     col_append_sep_str(pinfo->cinfo, COL_PROTOCOL, "/", "NAS-EPS");
4817
4818     item = proto_tree_add_item(tree, proto_nas_eps, tvb, 0, -1, ENC_NA);
4819     nas_eps_tree = proto_item_add_subtree(item, ett_nas_eps);
4820
4821     /* SERVICE REQUEST (security header type equal to 12 or greater) is not a plain NAS message */
4822     pd = tvb_get_guint8(tvb,offset);
4823     if (((pd&0x0f) == 0x07) && ((pd&0xf0) >= 0xc0)) {
4824         col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "Service request");
4825         /* Security header type Security header type 9.3.1 M V 1/2 */
4826         proto_tree_add_item(nas_eps_tree, hf_nas_eps_security_header_type, tvb, 0, 1, ENC_BIG_ENDIAN);
4827         /* Protocol discriminator Protocol discriminator 9.2 M V 1/2 */
4828         proto_tree_add_item(nas_eps_tree, hf_gsm_a_L3_protocol_discriminator, tvb, 0, 1, ENC_BIG_ENDIAN);
4829         offset++;
4830         nas_emm_service_req(tvb, nas_eps_tree, pinfo, offset, tvb_length(tvb)-offset);
4831         return;
4832     }
4833
4834     pd &= 0x0f;
4835     switch (pd) {
4836         case 2:
4837             /* EPS session management messages.
4838              * Ref 3GPP TS 24.007 version 8.0.0 Release 8, Table 11.2: Protocol discriminator values
4839              */
4840             disect_nas_eps_esm_msg(tvb, pinfo, nas_eps_tree, offset);
4841             break;
4842         case 7:
4843             /* EPS mobility management messages.
4844              * Ref 3GPP TS 24.007 version 8.0.0 Release 8, Table 11.2: Protocol discriminator values
4845              */
4846             dissect_nas_eps_emm_msg(tvb, pinfo, nas_eps_tree, offset, TRUE);
4847             break;
4848         case 15:
4849             /* Special conformance testing functions for User Equipment messages.
4850              * Ref 3GPP TS 24.007 version 8.0.0 Release 8, Table 11.2: Protocol discriminator values
4851              */
4852             if (gsm_a_dtap_handle) {
4853                 tvbuff_t *new_tvb = tvb_new_subset_remaining(tvb, offset);
4854                 call_dissector(gsm_a_dtap_handle, new_tvb,pinfo, nas_eps_tree);
4855                 break;
4856             } /* else fall through default */
4857         default:
4858             proto_tree_add_text(nas_eps_tree, tvb, offset, -1, "Not a NAS EPS PD %u(%s)",
4859                                 pd,
4860                                 val_to_str_const(pd, protocol_discriminator_vals, "unknown"));
4861             break;
4862     }
4863
4864 }
4865
4866 /* TS 24.301 8.2.1
4867  * 9    General message format and information elements coding
4868  * 9.1  Overview
4869  * Within the protocols defined in the present document, every message, except the SERVICE REQUEST message,
4870  * is a standard L3 message as defined in 3GPP TS 24.007 [12]. This means that the message consists of the following parts:
4871  * 1)   if the message is a plain NAS message:
4872  *  a)  protocol discriminator;
4873  *  b)  EPS bearer identity or security header type;
4874  *  c)  procedure transaction identity;
4875  *  d)  message type;
4876  *  e)  other information elements, as required.
4877  * 2)   if the message is a security protected NAS message:
4878  *  a)  protocol discriminator;
4879  *  b)  security header type;
4880  *  c)  message authentication code;
4881  *  d)  sequence number;
4882  *  e)  plain NAS message, as defined in item 1.
4883  *
4884  * The EPS bearer identity and the procedure transaction identity are only used in messages
4885  * with protocol discriminator EPS session management. Octet 1a with the procedure transaction
4886  * identity shall only be included in these messages.
4887  */
4888
4889 /*
4890  * All messages recived here will have the security header:
4891  *  Figure 9.1.2: General message organization example for a security protected NAS message
4892  *      9.3.1 Bits 5 to 8 of the first octet of every EPS Mobility Management (EMM)
4893  *            message contain the Security header type IE.
4894  *      4.4.4.2 All ESM messages are integrity protected.
4895  */
4896
4897 static void
4898 dissect_nas_eps(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
4899 {
4900     proto_item *item;
4901     proto_tree *nas_eps_tree;
4902     guint8      pd, security_header_type;
4903     int         offset = 0;
4904     guint32     len;
4905     guint32     msg_auth_code;
4906
4907     len = tvb_length(tvb);
4908     /* The protected NAS message header is 6 octets long, and the NAS message header is at least 2 octets long. */
4909     /* If the length of the tvbuffer is less than 8 octets, we can safely conclude the message is not protected. */
4910     if (len < 8) {
4911         dissect_nas_eps_plain(tvb, pinfo, tree);
4912         return;
4913     }
4914
4915     if (g_nas_eps_dissect_plain) {
4916         dissect_nas_eps_plain(tvb, pinfo, tree);
4917         return;
4918     }
4919
4920     /* Save pinfo */
4921     gpinfo = pinfo;
4922
4923     /* make entry in the Protocol column on summary display */
4924     col_append_sep_str(pinfo->cinfo, COL_PROTOCOL, "/", "NAS-EPS");
4925
4926     item = proto_tree_add_item(tree, proto_nas_eps, tvb, 0, -1, ENC_NA);
4927     nas_eps_tree = proto_item_add_subtree(item, ett_nas_eps);
4928
4929     /* Security header type Security header type 9.3.1 M V 1/2 */
4930     security_header_type = tvb_get_guint8(tvb,offset)>>4;
4931     proto_tree_add_item(nas_eps_tree, hf_nas_eps_security_header_type, tvb, 0, 1, ENC_BIG_ENDIAN);
4932     /* Protocol discriminator Protocol discriminator 9.2 M V 1/2 */
4933     proto_tree_add_item(nas_eps_tree, hf_gsm_a_L3_protocol_discriminator, tvb, 0, 1, ENC_BIG_ENDIAN);
4934     pd = tvb_get_guint8(tvb,offset)&0x0f;
4935     offset++;
4936     /* Message authentication code  Message authentication code 9.5 M   V   4 */
4937     if (security_header_type == 0) {
4938         if (pd == 7) {
4939             /* Plain EPS mobility management messages. */
4940             dissect_nas_eps_emm_msg(tvb, pinfo, nas_eps_tree, offset, FALSE);
4941             return;
4942         } else {
4943             proto_tree_add_text(nas_eps_tree, tvb, offset, len, "All ESM / Test Procedures messages should be integrity protected");
4944             return;
4945         }
4946     } else {
4947         /* SERVICE REQUEST (12 or greater) is not a plain NAS message treat separately */
4948         if (security_header_type >= 12) {
4949             col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "Service request");
4950             nas_emm_service_req(tvb, nas_eps_tree, pinfo, offset, len-offset);
4951             return;
4952         }
4953         /* Message authentication code */
4954         proto_tree_add_item(nas_eps_tree, hf_nas_eps_msg_auth_code, tvb, offset, 4, ENC_BIG_ENDIAN);
4955         msg_auth_code = tvb_get_ntohl(tvb, offset);
4956         offset+=4;
4957         if ((security_header_type == 2)||(security_header_type == 4)) {
4958             /* Possible ciphered message */
4959             if (msg_auth_code != 0) {
4960                 /* Sequence number  Sequence number 9.6 M   V   1 */
4961                 proto_tree_add_item(nas_eps_tree, hf_nas_eps_seq_no, tvb, offset, 1, ENC_BIG_ENDIAN);
4962                 offset++;
4963                 /* Integrity protected and ciphered = 2, Integrity protected and ciphered with new EPS security context = 4 */
4964                 /* Read security_header_type / EPS bearer id AND pd */
4965                 pd = tvb_get_guint8(tvb,offset);
4966                 /* If pd is in plaintext this message probably isn't ciphered */
4967                 if ((pd != 7) && (pd != 15) &&
4968                     (((pd&0x0f) != 2) || (((pd&0x0f) == 2) && ((pd&0xf0) > 0) && ((pd&0xf0) < 0x50)))) {
4969                     proto_tree_add_text(nas_eps_tree, tvb, offset, len-6,"Ciphered message");
4970                     return;
4971                 }
4972             } else {
4973                 /* msg_auth_code == 0, probably not ciphered */
4974                 /* Sequence number  Sequence number 9.6 M   V   1 */
4975                 proto_tree_add_item(nas_eps_tree, hf_nas_eps_seq_no, tvb, offset, 1, ENC_BIG_ENDIAN);
4976                 offset++;
4977             }
4978         } else {
4979             /* Sequence number  Sequence number 9.6 M   V   1 */
4980             proto_tree_add_item(nas_eps_tree, hf_nas_eps_seq_no, tvb, offset, 1, ENC_BIG_ENDIAN);
4981             offset++;
4982         }
4983     }
4984     /* NAS message  NAS message 9.7 M   V   1-n  */
4985
4986     pd = tvb_get_guint8(tvb,offset)&0x0f;
4987     switch (pd) {
4988         case 2:
4989             /* EPS session management messages.
4990              * Ref 3GPP TS 24.007 version 8.0.0 Release 8, Table 11.2: Protocol discriminator values
4991              */
4992             disect_nas_eps_esm_msg(tvb, pinfo, nas_eps_tree, offset);
4993             break;
4994         case 7:
4995             /* EPS mobility management messages.
4996              * Ref 3GPP TS 24.007 version 8.0.0 Release 8, Table 11.2: Protocol discriminator values
4997              */
4998             dissect_nas_eps_emm_msg(tvb, pinfo, nas_eps_tree, offset, TRUE);
4999             break;
5000         case 15:
5001             /* Special conformance testing functions for User Equipment messages.
5002              * Ref 3GPP TS 24.007 version 8.0.0 Release 8, Table 11.2: Protocol discriminator values
5003              */
5004             if (gsm_a_dtap_handle) {
5005                 tvbuff_t *new_tvb = tvb_new_subset_remaining(tvb, offset);
5006                 call_dissector(gsm_a_dtap_handle, new_tvb, pinfo, nas_eps_tree);
5007                 break;
5008             } /* else fall through default */
5009         default:
5010             proto_tree_add_text(nas_eps_tree, tvb, offset, -1, "Not a NAS EPS PD %u(%s)",
5011                                 pd,
5012                                 val_to_str_const(pd, protocol_discriminator_vals, "unknown"));
5013             break;
5014     }
5015
5016 }
5017
5018 void
5019 proto_register_nas_eps(void) {
5020     guint     i;
5021     guint     last_offset;
5022     module_t *nas_eps_module;
5023
5024     /* List of fields */
5025
5026   static hf_register_info hf[] = {
5027     { &hf_nas_eps_msg_emm_type,
5028         { "NAS EPS Mobility Management Message Type",   "nas_eps.nas_msg_emm_type",
5029         FT_UINT8, BASE_HEX|BASE_EXT_STRING, &nas_msg_emm_strings_ext, 0x0,
5030         NULL, HFILL }
5031     },
5032     { &hf_nas_eps_common_elem_id,
5033         { "Element ID", "nas_eps.common.elem_id",
5034         FT_UINT8, BASE_HEX, NULL, 0,
5035         NULL, HFILL }
5036     },
5037     { &hf_nas_eps_emm_elem_id,
5038         { "Element ID", "nas_eps.emm.elem_id",
5039         FT_UINT8, BASE_HEX, NULL, 0,
5040         NULL, HFILL }
5041     },
5042     { &hf_nas_eps_bearer_id,
5043         { "EPS bearer identity",    "nas_eps.bearer_id",
5044         FT_UINT8, BASE_DEC, VALS(nas_eps_esm_bearer_id_vals), 0xf0,
5045         NULL, HFILL }
5046     },
5047     { &hf_nas_eps_spare_bits,
5048         { "Spare bit(s)", "nas_eps.spare_bits",
5049         FT_UINT8, BASE_HEX, NULL, 0x0,
5050         NULL, HFILL }
5051     },
5052     { &hf_nas_eps_security_header_type,
5053         { "Security header type","nas_eps.security_header_type",
5054         FT_UINT8,BASE_DEC|BASE_EXT_STRING, &security_header_type_vals_ext, 0xf0,
5055         NULL, HFILL }
5056     },
5057     { &hf_nas_eps_msg_auth_code,
5058         { "Message authentication code","nas_eps.msg_auth_code",
5059         FT_UINT32,BASE_HEX, NULL, 0x0,
5060         NULL, HFILL }
5061     },
5062     { &hf_nas_eps_seq_no,
5063         { "Sequence number","nas_eps.seq_no",
5064         FT_UINT8,BASE_DEC, NULL, 0x0,
5065         NULL, HFILL }
5066     },
5067     { &hf_nas_eps_seq_no_short,
5068         { "Sequence number (short)","nas_eps.seq_no_short",
5069         FT_UINT8,BASE_DEC, NULL, 0x0,
5070         NULL, HFILL }
5071     },
5072     { &hf_nas_eps_emm_ebi0,
5073         { "EBI(0) spare","nas_eps.emm.ebi0",
5074         FT_BOOLEAN, 8, NULL, 0x01,
5075         NULL, HFILL }
5076     },
5077     { &hf_nas_eps_emm_ebi1,
5078         { "EBI(1) spare","nas_eps.emm.ebi1",
5079         FT_BOOLEAN, 8, NULL, 0x02,
5080         NULL, HFILL }
5081     },
5082     { &hf_nas_eps_emm_ebi2,
5083         { "EBI(2) spare","nas_eps.emm.ebi2",
5084         FT_BOOLEAN, 8, NULL, 0x04,
5085         NULL, HFILL }
5086     },
5087     { &hf_nas_eps_emm_ebi3,
5088         { "EBI(3) spare","nas_eps.emm.ebi3",
5089         FT_BOOLEAN, 8, NULL, 0x08,
5090         NULL, HFILL }
5091     },
5092     { &hf_nas_eps_emm_ebi4,
5093         { "EBI(4) spare","nas_eps.emm.ebi4",
5094         FT_BOOLEAN, 8, NULL, 0x10,
5095         NULL, HFILL }
5096     },
5097     { &hf_nas_eps_emm_ebi5,
5098         { "EBI(5)","nas_eps.emm.ebi5",
5099         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ebi_vals), 0x20,
5100         NULL, HFILL }
5101     },
5102     { &hf_nas_eps_emm_ebi6,
5103         { "EBI(6)","nas_eps.emm.ebi6",
5104         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ebi_vals), 0x40,
5105         NULL, HFILL }
5106     },
5107     { &hf_nas_eps_emm_ebi7,
5108         { "EBI(7)","nas_eps.emm.ebi7",
5109         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ebi_vals), 0x80,
5110         NULL, HFILL }
5111     },
5112     { &hf_nas_eps_emm_ebi8,
5113         { "EBI(8)","nas_eps.emm.ebi8",
5114         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ebi_vals), 0x01,
5115         NULL, HFILL }
5116     },
5117     { &hf_nas_eps_emm_ebi9,
5118         { "EBI(9)","nas_eps.emm.ebi9",
5119         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ebi_vals), 0x02,
5120         NULL, HFILL }
5121     },
5122     { &hf_nas_eps_emm_ebi10,
5123         { "EBI(10)","nas_eps.emm.ebi10",
5124         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ebi_vals), 0x04,
5125         NULL, HFILL }
5126     },
5127     { &hf_nas_eps_emm_ebi11,
5128         { "EBI(11)","nas_eps.emm.ebi11",
5129         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ebi_vals), 0x08,
5130         NULL, HFILL }
5131     },
5132     { &hf_nas_eps_emm_ebi12,
5133         { "EBI(12)","nas_eps.emm.ebi12",
5134         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ebi_vals), 0x10,
5135         NULL, HFILL }
5136     },
5137     { &hf_nas_eps_emm_ebi13,
5138         { "EBI(13)","nas_eps.emm.ebi13",
5139         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ebi_vals), 0x20,
5140         NULL, HFILL }
5141     },
5142     { &hf_nas_eps_emm_ebi14,
5143         { "EBI(14)","nas_eps.emm.ebi14",
5144         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ebi_vals), 0x40,
5145         NULL, HFILL }
5146     },
5147     { &hf_nas_eps_emm_ebi15,
5148         { "EBI(15)","nas_eps.emm.ebi15",
5149         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ebi_vals), 0x80,
5150         NULL, HFILL }
5151     },
5152     { &hf_nas_eps_emm_dl_nas_cnt,
5153         { "DL NAS COUNT value","nas_eps.emm.dl_nas_cnt",
5154         FT_UINT8,BASE_DEC, NULL, 0x0f,
5155         NULL, HFILL }
5156     },
5157     {&hf_nas_eps_emm_nonce_mme,
5158         { "NonceMME","nas_eps.emm.nonce_mme",
5159         FT_UINT32,BASE_HEX, NULL, 0x0,
5160         NULL, HFILL }
5161     },
5162     {&hf_nas_eps_emm_nonce,
5163         { "Nonce","nas_eps.emm.nonce",
5164         FT_UINT32,BASE_HEX, NULL, 0x0,
5165         NULL, HFILL }
5166     },
5167     { &hf_nas_eps_emm_paging_id,
5168         { "Paging identity value","nas_eps.emm.paging_id",
5169         FT_BOOLEAN, BASE_NONE, TFS(&nas_eps_emm_paging_id_vals), 0x0,
5170         NULL, HFILL }
5171     },
5172     { &hf_nas_eps_emm_eps_att_type,
5173         { "EPS attach type","nas_eps.emm.eps_att_type",
5174         FT_UINT8,BASE_DEC, VALS(nas_eps_emm_eps_att_type_vals), 0x0,
5175         NULL, HFILL }
5176     },
5177     { &hf_nas_eps_emm_esr_ps,
5178         { "ESRPS","nas_eps.emm.esr_ps",
5179         FT_BOOLEAN ,BASE_NONE, TFS(&nas_eps_emm_esr_ps_value), 0x0,
5180         "Support of EXTENDED SERVICE REQUEST for packet services", HFILL }
5181     },
5182     { &hf_nas_eps_emm_cs_lcs,
5183         { "CS-LCS","nas_eps.emm.cs_lcs",
5184         FT_UINT8, BASE_DEC, VALS(nas_eps_emm_cs_lcs_vals), 0x0,
5185         "Location services indicator in CS", HFILL }
5186     },
5187     { &hf_nas_eps_emm_epc_lcs,
5188         { "EPC-LCS","nas_eps.emm.epc_lcs",
5189         FT_BOOLEAN ,BASE_NONE, TFS(&nas_eps_emm_epc_lcs_value), 0x0,
5190         "Location services indicator in EPC", HFILL }
5191     },
5192     { &hf_nas_eps_emm_emc_bs,
5193         { "EMC BS","nas_eps.emm.emc_bs",
5194         FT_BOOLEAN, BASE_NONE, TFS(&nas_eps_emm_emc_bs_value), 0x0,
5195         "Emergency bearer services indicator", HFILL }
5196     },
5197     { &hf_nas_eps_emm_ims_vops,
5198         { "IMS VoPS","nas_eps.emm.ims_vops",
5199         FT_BOOLEAN, BASE_NONE, TFS(&nas_eps_emm_ims_vops_value), 0x0,
5200         "IMS voice over PS session indicator", HFILL }
5201     },
5202     { &hf_nas_eps_tsc,
5203         { "Type of security context flag (TSC)","nas_eps.emm.tsc",
5204         FT_BOOLEAN,BASE_DEC, TFS(&nas_eps_tsc_value), 0x0,
5205         NULL, HFILL }
5206     },
5207     { &hf_nas_eps_emm_nas_key_set_id,
5208         { "NAS key set identifier","nas_eps.emm.nas_key_set_id",
5209         FT_UINT8,BASE_DEC, VALS(nas_eps_emm_NAS_key_set_identifier_vals), 0x0,
5210         NULL, HFILL }
5211     },
5212     { &hf_nas_eps_emm_odd_even,
5213         { "odd/even indic","nas_eps.emm.odd_even",
5214         FT_UINT8,BASE_DEC, NULL, 0x8,
5215         NULL, HFILL }
5216     },
5217     { &hf_nas_eps_emm_type_of_id,
5218         { "Type of identity","nas_eps.emm.type_of_id",
5219         FT_UINT8,BASE_DEC, VALS(nas_eps_emm_type_of_id_vals), 0x07,
5220         NULL, HFILL }
5221     },
5222     { &hf_nas_eps_emm_mme_grp_id,
5223         { "MME Group ID","nas_eps.emm.mme_grp_id",
5224         FT_UINT16, BASE_DEC, NULL, 0x0,
5225         NULL, HFILL }
5226     },
5227     { &hf_nas_eps_emm_imsi,
5228         { "IMSI", "nas_eps.emm.imsi",
5229           FT_STRING, BASE_NONE, NULL, 0,
5230           NULL, HFILL }
5231     },
5232     { &hf_nas_eps_emm_imei,
5233         { "IMEI", "nas_eps.emm.imei",
5234           FT_STRING, BASE_NONE, NULL, 0,
5235           NULL, HFILL }
5236     },
5237     { &hf_nas_eps_emm_mme_code,
5238         { "MME Code","nas_eps.emm.mme_code",
5239         FT_UINT8, BASE_DEC, NULL, 0x0,
5240         NULL, HFILL }
5241     },
5242     { &hf_nas_eps_emm_m_tmsi,
5243         { "M-TMSI","nas_eps.emm.m_tmsi",
5244         FT_UINT32, BASE_HEX, NULL, 0x0,
5245         NULL, HFILL }
5246     },
5247     { &hf_nas_eps_esm_msg_cont,
5248         { "ESM message container contents","nas_eps.emm.esm_msg_cont",
5249         FT_BYTES, BASE_NONE, NULL, 0x0,
5250         NULL, HFILL }
5251     },
5252     { &hf_nas_eps_esm_imeisv_req,
5253         { "IMEISV request","nas_eps.emm.imeisv_req",
5254         FT_UINT8, BASE_DEC, VALS(nas_eps_emm_imeisv_req_vals), 0x07,
5255         NULL, HFILL }
5256     },
5257     { &hf_nas_eps_emm_toi,
5258         { "Type of integrity protection algorithm","nas_eps.emm.toi",
5259         FT_UINT8, BASE_DEC, VALS(nas_eps_emm_toi_vals), 0x07,
5260         NULL, HFILL }
5261     },
5262     { &hf_nas_eps_emm_toc,
5263         { "Type of ciphering algorithm","nas_eps.emm.toc",
5264         FT_UINT8, BASE_DEC, VALS(nas_eps_emm_toc_vals), 0x70,
5265         NULL, HFILL }
5266     },
5267     { &hf_nas_eps_emm_EPS_attach_result,
5268         { "Attach result","nas_eps.emm.EPS_attach_result",
5269         FT_UINT8,BASE_DEC, VALS(nas_eps_emm_EPS_attach_result_values), 0x0,
5270         NULL, HFILL }
5271     },
5272     { &hf_nas_eps_emm_spare_half_octet,
5273         { "Spare half octet","nas_eps.emm.spare_half_octet",
5274         FT_UINT8,BASE_DEC, NULL, 0x0,
5275         NULL, HFILL }
5276     },
5277     { &hf_nas_eps_emm_add_upd_res,
5278         { "AURV","nas_eps.emm.add_upd_res",
5279         FT_UINT8, BASE_DEC, VALS(nas_eps_emm_add_upd_res_vals), 0x0,
5280         "Additional update result value", HFILL }
5281     },
5282     { &hf_nas_eps_emm_add_upd_type,
5283         { "AUTV","nas_eps.emm.add_upd_type",
5284         FT_UINT8, BASE_DEC, VALS(nas_eps_emm_add_upd_type_vals), 0x0,
5285         "Additional update type value", HFILL }
5286     },
5287     { &hf_nas_eps_emm_res,
5288         { "RES","nas_eps.emm.res",
5289         FT_BYTES, BASE_NONE, NULL, 0x0,
5290         NULL, HFILL }
5291     },
5292     { &hf_nas_eps_emm_csfb_resp,
5293         { "CSFB response","nas_eps.emm.csfb_resp",
5294         FT_UINT8, BASE_DEC, VALS(nas_eps_emm_csfb_resp_vals), 0x03,
5295         NULL, HFILL }
5296     },
5297     { &hf_nas_eps_emm_cause,
5298         { "Cause","nas_eps.emm.cause",
5299         FT_UINT8, BASE_DEC|BASE_EXT_STRING, &nas_eps_emm_cause_values_ext, 0x0,
5300         NULL, HFILL }
5301     },
5302     { &hf_nas_eps_emm_id_type2,
5303         { "Identity type 2","nas_eps.emm.id_type2",
5304         FT_UINT8, BASE_DEC, VALS(nas_eps_emm_id_type2_vals), 0x0,
5305         NULL, HFILL }
5306     },
5307     { &hf_nas_eps_emm_short_mac,
5308         { "Message authentication code (short)","nas_eps.emm.short_mac",
5309         FT_UINT16, BASE_HEX, NULL, 0x0,
5310         NULL, HFILL }
5311     },
5312     { &hf_nas_eps_emm_tai_tol,
5313         { "Type of list","nas_eps.emm.tai_tol",
5314         FT_UINT8, BASE_DEC, VALS(nas_eps_emm_tai_tol_vals), 0x60,
5315         NULL, HFILL }
5316     },
5317     { &hf_nas_eps_emm_tai_n_elem,
5318         { "Number of elements","nas_eps.emm.tai_n_elem",
5319         FT_UINT8, BASE_DEC,  NULL, 0x1f,
5320         NULL, HFILL }
5321     },
5322     { &hf_nas_eps_emm_tai_tac,
5323         { "Tracking area code(TAC)","nas_eps.emm.tai_tac",
5324         FT_UINT16, BASE_HEX,  NULL, 0x0,
5325         NULL, HFILL }
5326     },
5327     { &hf_nas_eps_emm_eea0,
5328         { "EEA0","nas_eps.emm.eea0",
5329         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x80,
5330         NULL, HFILL }
5331     },
5332     { &hf_nas_eps_emm_128eea1,
5333         { "128-EEA1","nas_eps.emm.128eea1",
5334         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x40,
5335         NULL, HFILL }
5336     },
5337     { &hf_nas_eps_emm_128eea2,
5338         { "128-EEA2","nas_eps.emm.128eea2",
5339         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x20,
5340         NULL, HFILL }
5341     },
5342     { &hf_nas_eps_emm_eea3,
5343         { "128-EEA3","nas_eps.emm.eea3",
5344         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x10,
5345         NULL, HFILL }
5346     },
5347     { &hf_nas_eps_emm_eea4,
5348         { "EEA4","nas_eps.emm.eea4",
5349         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x08,
5350         NULL, HFILL }
5351     },
5352     { &hf_nas_eps_emm_eea5,
5353         { "EEA5","nas_eps.emm.eea5",
5354         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x04,
5355         NULL, HFILL }
5356     },
5357     { &hf_nas_eps_emm_eea6,
5358         { "EEA6","nas_eps.emm.eea6",
5359         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x02,
5360         NULL, HFILL }
5361     },
5362     { &hf_nas_eps_emm_eea7,
5363         { "EEA7","nas_eps.emm.eea7",
5364         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x01,
5365         NULL, HFILL }
5366     },
5367     { &hf_nas_eps_emm_eia0,
5368         { "EIA0","nas_eps.emm.eia0",
5369         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x80,
5370         NULL, HFILL }
5371     },
5372     { &hf_nas_eps_emm_128eia1,
5373         { "128-EIA1","nas_eps.emm.128eia1",
5374         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x40,
5375         NULL, HFILL }
5376     },
5377     { &hf_nas_eps_emm_128eia2,
5378         { "128-EIA2","nas_eps.emm.128eia2",
5379         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x20,
5380         NULL, HFILL }
5381     },
5382     { &hf_nas_eps_emm_eia3,
5383         { "128-EIA3","nas_eps.emm.eia3",
5384         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x10,
5385         NULL, HFILL }
5386     },
5387     { &hf_nas_eps_emm_eia4,
5388         { "EIA4","nas_eps.emm.eia4",
5389         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x08,
5390         NULL, HFILL }
5391     },
5392     { &hf_nas_eps_emm_eia5,
5393         { "EIA5","nas_eps.emm.eia5",
5394         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x04,
5395         NULL, HFILL }
5396     },
5397     { &hf_nas_eps_emm_eia6,
5398         { "EIA6","nas_eps.emm.eia6",
5399         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x02,
5400         NULL, HFILL }
5401     },
5402     { &hf_nas_eps_emm_eia7,
5403         { "EIA7","nas_eps.emm.eia7",
5404         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x01,
5405         NULL, HFILL }
5406     },
5407
5408
5409     { &hf_nas_eps_emm_uea0,
5410         { "UEA0","nas_eps.emm.uea0",
5411         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x80,
5412         NULL, HFILL }
5413     },
5414     { &hf_nas_eps_emm_uea1,
5415         { "UEA1","nas_eps.emm.uea1",
5416         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x40,
5417         NULL, HFILL }
5418     },
5419     { &hf_nas_eps_emm_uea2,
5420         { "UEA2","nas_eps.emm.uea2",
5421         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x20,
5422         NULL, HFILL }
5423     },
5424     { &hf_nas_eps_emm_uea3,
5425         { "UEA3","nas_eps.emm.uea3",
5426         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x10,
5427         NULL, HFILL }
5428     },
5429     { &hf_nas_eps_emm_uea4,
5430         { "UEA4","nas_eps.emm.uea4",
5431         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x08,
5432         NULL, HFILL }
5433     },
5434     { &hf_nas_eps_emm_uea5,
5435         { "UEA5","nas_eps.emm.uea5",
5436         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x04,
5437         NULL, HFILL }
5438     },
5439     { &hf_nas_eps_emm_uea6,
5440         { "UEA6","nas_eps.emm.uea6",
5441         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x02,
5442         NULL, HFILL }
5443     },
5444     { &hf_nas_eps_emm_uea7,
5445         { "UEA7","nas_eps.emm.uea7",
5446         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x01,
5447         NULL, HFILL }
5448     },
5449     { &hf_nas_eps_emm_ucs2_supp,
5450         { "UCS2 support (UCS2)","nas_eps.emm.emm_ucs2_supp",
5451         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ucs2_supp_flg_value), 0x80,
5452         NULL, HFILL }
5453     },
5454     { &hf_nas_eps_emm_uia1,
5455         { "UMTS integrity algorithm UIA1","nas_eps.emm.uia1",
5456         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x40,
5457         NULL, HFILL }
5458     },
5459     { &hf_nas_eps_emm_uia2,
5460         { "UMTS integrity algorithm UIA2","nas_eps.emm.uia2",
5461         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x20,
5462         NULL, HFILL }
5463     },
5464     { &hf_nas_eps_emm_uia3,
5465         { "UMTS integrity algorithm UIA3","nas_eps.emm.uia3",
5466         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x10,
5467         NULL, HFILL }
5468     },
5469     { &hf_nas_eps_emm_uia4,
5470         { "UMTS integrity algorithm UIA4","nas_eps.emm.uia4",
5471         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x08,
5472         NULL, HFILL }
5473     },
5474     { &hf_nas_eps_emm_uia5,
5475         { "UMTS integrity algorithm UIA5","nas_eps.emm.uia5",
5476         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x04,
5477         NULL, HFILL }
5478     },
5479     { &hf_nas_eps_emm_uia6,
5480         { "UMTS integrity algorithm UIA6","nas_eps.emm.uia6",
5481         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x02,
5482         NULL, HFILL }
5483     },
5484     { &hf_nas_eps_emm_uia7,
5485         { "UMTS integrity algorithm UIA7","nas_eps.emm.uia7",
5486         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x01,
5487         NULL, HFILL }
5488     },
5489     { &hf_nas_eps_emm_gea1,
5490         { "GPRS encryption algorithm GEA1","nas_eps.emm.gea1",
5491         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x40,
5492         NULL, HFILL }
5493     },
5494     { &hf_nas_eps_emm_gea2,
5495         { "GPRS encryption algorithm GEA2","nas_eps.emm.gea2",
5496         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x20,
5497         NULL, HFILL }
5498     },
5499     { &hf_nas_eps_emm_gea3,
5500         { "GPRS encryption algorithm GEA3","nas_eps.emm.gea3",
5501         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x10,
5502         NULL, HFILL }
5503     },
5504     { &hf_nas_eps_emm_gea4,
5505         { "GPRS encryption algorithm GEA4","nas_eps.emm.gea4",
5506         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x08,
5507         NULL, HFILL }
5508     },
5509     { &hf_nas_eps_emm_gea5,
5510         { "GPRS encryption algorithm GEA5","nas_eps.emm.gea5",
5511         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x04,
5512         NULL, HFILL }
5513     },
5514     { &hf_nas_eps_emm_gea6,
5515         { "GPRS encryption algorithm GEA6","nas_eps.emm.gea6",
5516         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x02,
5517         NULL, HFILL }
5518     },
5519     { &hf_nas_eps_emm_gea7,
5520         { "GPRS encryption algorithm GEA7","nas_eps.emm.gea7",
5521         FT_BOOLEAN, 8, TFS(&nas_eps_emm_supported_flg_value), 0x01,
5522         NULL, HFILL }
5523     },
5524     { &hf_nas_eps_emm_h245_ash_cap,
5525         { "H.245-ASH capability","nas_eps.emm.h245_ash_cap",
5526         FT_BOOLEAN, 8, TFS(&nas_eps_emm_h245_ash_cap_flg), 0x20,
5527         "H.245 after SRVCC handover capability", HFILL }
5528     },
5529     { &hf_nas_eps_emm_acc_csfb_cap,
5530         { "ACC-CSFB capability","nas_eps.emm.acc_csfb_cap",
5531         FT_BOOLEAN, 8, TFS(&nas_eps_emm_acc_csfb_cap_flg), 0x10,
5532         "Access class control for CSFB capability", HFILL }
5533     },
5534     { &hf_nas_eps_emm_lpp_cap,
5535         { "LPP capability","nas_eps.emm.lpp_cap",
5536         FT_BOOLEAN, 8, TFS(&nas_eps_emm_lpp_cap_flg), 0x08,
5537         "LTE Positioning Protocol capability", HFILL }
5538     },
5539     { &hf_nas_eps_emm_lcs_cap,
5540         { "LCS capability","nas_eps.emm.lcs_cap",
5541         FT_BOOLEAN, 8, TFS(&nas_eps_emm_lcs_cap_flg), 0x04,
5542         "Location services notification mechanisms capability", HFILL }
5543     },
5544     { &hf_nas_eps_emm_1xsrvcc_cap,
5545         { "1xSRVCC capability","nas_eps.emm.1xsrvcc_cap",
5546         FT_BOOLEAN, 8, TFS(&nas_eps_emm_1xsrvcc_cap_flg), 0x02,
5547         NULL, HFILL }
5548     },
5549     { &hf_nas_eps_emm_nf_cap,
5550         { "NF capability","nas_eps.emm.nf_cap",
5551         FT_BOOLEAN, 8, TFS(&nas_eps_emm_nf_cap_flg), 0x01,
5552         NULL, HFILL }
5553     },
5554     { &hf_nas_eps_emm_ue_ra_cap_inf_upd_need_flg,
5555         { "URC upd","nas_eps.emm.ue_ra_cap_inf_upd_need_flg",
5556         FT_BOOLEAN, 8, TFS(&nas_eps_emm_ue_ra_cap_inf_upd_need_flg), 0x01,
5557         "UE radio capability information update needed flag", HFILL }
5558     },
5559     { &hf_nas_eps_emm_ss_code,
5560         { "SS Code","nas_eps.emm.ss_code",
5561         FT_UINT8,BASE_DEC, VALS(ssCode_vals), 0x0,
5562         NULL, HFILL }
5563     },
5564     { &hf_nas_eps_emm_lcs_ind,
5565         { "LCS indicator","nas_eps.emm.emm_lcs_ind",
5566         FT_UINT8,BASE_DEC, VALS(nas_eps_emm_lcs_ind_vals), 0x0,
5567         NULL, HFILL }
5568     },
5569     { &hf_nas_eps_emm_gen_msg_cont_type,
5570         { "Container type","nas_eps.emm.gen_msg_cont_type",
5571         FT_UINT8,BASE_DEC|BASE_RANGE_STRING, RVALS(nas_eps_emm_gen_msg_cont_type_vals), 0x0,
5572         NULL, HFILL }
5573     },
5574     { &hf_nas_eps_emm_apn_ambr_ul,
5575         { "APN-AMBR for uplink","nas_eps.emm.apn_ambr_ul",
5576         FT_UINT8,BASE_DEC, NULL, 0x0,
5577         NULL, HFILL }
5578     },
5579     { &hf_nas_eps_emm_apn_ambr_dl,
5580         { "APN-AMBR for downlink","nas_eps.emm.apn_ambr_dl",
5581         FT_UINT8,BASE_DEC, NULL, 0x0,
5582         NULL, HFILL }
5583     },
5584     { &hf_nas_eps_emm_apn_ambr_ul_ext,
5585         { "APN-AMBR for uplink(Extended)","nas_eps.emm.apn_ambr_ul_ext",
5586         FT_UINT8,BASE_DEC, NULL, 0x0,
5587         NULL, HFILL }
5588     },
5589     { &hf_nas_eps_emm_apn_ambr_dl_ext,
5590         { "APN-AMBR for downlink(Extended)","nas_eps.emm.apn_ambr_dl_ext",
5591         FT_UINT8,BASE_DEC, NULL, 0x0,
5592         NULL, HFILL }
5593     },
5594     { &hf_nas_eps_emm_apn_ambr_ul_ext2,
5595         { "APN-AMBR for uplink(Extended-2)","nas_eps.emm.apn_ambr_ul_ext2",
5596         FT_UINT8,BASE_DEC, NULL, 0x0,
5597         NULL, HFILL }
5598     },
5599     { &hf_nas_eps_emm_apn_ambr_dl_ext2,
5600         { "APN-AMBR for downlink(Extended-2)","nas_eps.emm.apn_ambr_dl_ext2",
5601         FT_UINT8,BASE_DEC, NULL, 0x0,
5602         NULL, HFILL }
5603     },
5604     { &hf_nas_eps_emm_guti_type,
5605         { "GUTI type", "nas_eps.emm.guti_type",
5606         FT_BOOLEAN, BASE_NONE, TFS(&nas_eps_emm_guti_type_value), 0x0,
5607         NULL, HFILL }
5608     },
5609     { &hf_nas_eps_emm_switch_off,
5610         { "Switch off","nas_eps.emm.switch_off",
5611         FT_UINT8,BASE_DEC, VALS(nas_eps_emm_switch_off_vals), 0x0,
5612         NULL, HFILL }
5613     },
5614     { &hf_nas_eps_emm_detach_type_UL,
5615         { "Detach Type","nas_eps.emm.detach_type_ul",
5616         FT_UINT8,BASE_DEC, VALS(nas_eps_emm_type_of_dtatch_UL_vals), 0x0,
5617         NULL, HFILL }
5618     },
5619     { &hf_nas_eps_emm_detach_type_DL,
5620         { "Detach Type","nas_eps.emm.detach_type_dl",
5621         FT_UINT8,BASE_DEC, VALS(nas_eps_emm_type_of_dtatch_DL_vals), 0x0,
5622         NULL, HFILL }
5623     },
5624     { &hf_nas_eps_qci,
5625         { "Quality of Service Class Identifier (QCI)","nas_eps.emm.qci",
5626         FT_UINT8,(BASE_DEC|BASE_RANGE_STRING), RVALS(nas_eps_qci_vals), 0x0,
5627         NULL, HFILL }
5628     },
5629     { &hf_nas_eps_mbr_ul,
5630         { "Maximum bit rate for uplink","nas_eps.emm.mbr_ul",
5631         FT_UINT8,BASE_DEC, NULL, 0x0,
5632         NULL, HFILL }
5633     },
5634     { &hf_nas_eps_mbr_dl,
5635         { "Maximum bit rate for downlink","nas_eps.emm.mbr_dl",
5636         FT_UINT8,BASE_DEC, NULL, 0x0,
5637         NULL, HFILL }
5638     },
5639     { &hf_nas_eps_gbr_ul,
5640         { "Guaranteed bit rate for uplink","nas_eps.emm.gbr_ul",
5641         FT_UINT8,BASE_DEC, NULL, 0x0,
5642         NULL, HFILL }
5643     },
5644     { &hf_nas_eps_gbr_dl,
5645         { "Guaranteed bit rate for downlink","nas_eps.emm.gbr_dl",
5646         FT_UINT8,BASE_DEC, NULL, 0x0,
5647         NULL, HFILL }
5648     },
5649     { &hf_nas_eps_embr_ul,
5650         { "Maximum bit rate for uplink(ext)","nas_eps.emm.embr_ul",
5651         FT_UINT8,BASE_DEC, NULL, 0x0,
5652         NULL, HFILL }
5653     },
5654     { &hf_nas_eps_embr_dl,
5655         { "Maximum bit rate for downlink(ext)","nas_eps.emm.embr_dl",
5656         FT_UINT8,BASE_DEC, NULL, 0x0,
5657         NULL, HFILL }
5658     },
5659     { &hf_nas_eps_egbr_ul,
5660         { "Guaranteed bit rate for uplink(ext)","nas_eps.emm.egbr_ul",
5661         FT_UINT8,BASE_DEC, NULL, 0x0,
5662         NULL, HFILL }
5663     },
5664     { &hf_nas_eps_egbr_dl,
5665         { "Guaranteed bit rate for downlink(ext)","nas_eps.emm.egbr_dl",
5666         FT_UINT8,BASE_DEC, NULL, 0x0,
5667         NULL, HFILL }
5668     },
5669     { &hf_nas_eps_esm_cause,
5670         { "Cause","nas_eps.esm.cause",
5671         FT_UINT8,BASE_DEC|BASE_EXT_STRING, &nas_eps_esm_cause_vals_ext, 0x0,
5672         NULL, HFILL }
5673     },
5674     { &hf_nas_eps_esm_eit,
5675         { "EIT (ESM information transfer)", "nas_eps.emm.eit",
5676         FT_BOOLEAN, 8, TFS(&nas_eps_emm_eit_vals), 0x01,
5677         NULL, HFILL }
5678     },
5679     { &hf_nas_eps_esm_notif_ind,
5680         { "Notification indicator value","nas_eps.esm.notif_ind",
5681         FT_UINT8,BASE_DEC, VALS(nas_eps_esm_notif_ind_vals), 0x0,
5682         NULL, HFILL }
5683     },
5684     { &hf_nas_eps_esm_pdn_ipv4,
5685         {"PDN IPv4", "nas_eps.esm.pdn_ipv4",
5686         FT_IPv4, BASE_NONE, NULL, 0x0,
5687         NULL, HFILL}
5688     },
5689     { &hf_nas_eps_esm_pdn_ipv6_if_id,
5690         {"PDN IPv6 if id", "nas_eps.esm.pdn_ipv6_if_id",
5691         FT_BYTES, BASE_NONE, NULL, 0x0,
5692         NULL, HFILL}
5693     },
5694     { &hf_nas_eps_esm_linked_bearer_id,
5695         { "Linked EPS bearer identity","nas_eps.esm.linked_bearer_id",
5696         FT_UINT8,BASE_DEC, VALS(nas_eps_esm_linked_bearer_id_vals), 0x0,
5697         NULL, HFILL }
5698     },
5699     { &hf_nas_eps_active_flg,
5700         { "Active flag", "nas_eps.emm.active_flg",
5701         FT_BOOLEAN, BASE_NONE, TFS(&nas_eps_emm_active_flg_value), 0x0,
5702         NULL, HFILL }
5703     },
5704     { &hf_nas_eps_eps_update_result_value,
5705         { "EPS update result value","nas_eps.emm.eps_update_result_value",
5706         FT_UINT8,BASE_DEC, VALS(nas_eps_emm_eps_update_result_vals), 0x0,
5707         NULL, HFILL }
5708     },
5709     { &hf_nas_eps_eps_update_type_value,
5710         { "EPS update type value", "nas_eps.emm.update_type_value",
5711         FT_UINT8,BASE_DEC, VALS(nas_eps_emm_eps_update_type_vals), 0x0,
5712         NULL, HFILL }
5713     },
5714     { &hf_nas_eps_service_type,
5715         { "Service type", "nas_eps.emm.service_type",
5716         FT_UINT8,BASE_DEC|BASE_RANGE_STRING, RVALS(nas_eps_service_type_vals), 0x0,
5717         NULL, HFILL }
5718     },
5719     { &hf_nas_eps_nas_msg_cont,
5720         { "NAS message container content", "nas_eps.emm.nas_msg_cont",
5721         FT_BYTES, BASE_NONE, NULL, 0x0,
5722         NULL, HFILL }
5723     },
5724     { &hf_nas_eps_gen_msg_cont,
5725         { "Generic message container content", "nas_eps.emm.gen_msg_cont",
5726         FT_BYTES, BASE_NONE, NULL, 0x0,
5727         NULL, HFILL }
5728     },
5729     { &hf_nas_eps_cmn_add_info,
5730         { "Additional information content", "nas_eps.cmn.add_info",
5731         FT_BYTES, BASE_NONE, NULL, 0x0,
5732         NULL, HFILL }
5733     },
5734     /* ESM hf cvariables */
5735     { &hf_nas_eps_msg_esm_type,
5736         { "NAS EPS session management messages",    "nas_eps.nas_msg_esm_type",
5737         FT_UINT8, BASE_HEX|BASE_EXT_STRING, &nas_msg_esm_strings_ext, 0x0,
5738         NULL, HFILL }
5739     },
5740     { &hf_nas_eps_esm_elem_id,
5741         { "Element ID", "nas_eps.esm.elem_id",
5742         FT_UINT8, BASE_HEX, NULL, 0,
5743         NULL, HFILL }
5744     },
5745     { &hf_nas_eps_esm_proc_trans_id,
5746         { "Procedure transaction identity", "nas_eps.esm.proc_trans_id",
5747         FT_UINT8, BASE_DEC, NULL, 0,
5748         NULL, HFILL }
5749     },
5750     { &hf_nas_eps_esm_pdn_type,
5751         { "PDN type",   "nas_eps.esm_pdn_type",
5752         FT_UINT8, BASE_DEC, VALS(nas_eps_esm_pdn_type_values), 0x0,
5753         NULL, HFILL }
5754     },
5755     { &hf_nas_eps_esm_request_type,
5756         { "Request type", "nas_eps.esm_request_type",
5757         FT_UINT8, BASE_DEC, VALS(nas_eps_esm_request_type_values), 0x0,
5758         NULL, HFILL }
5759     },
5760   };
5761
5762     /* Setup protocol subtree array */
5763 #define NUM_INDIVIDUAL_ELEMS    5
5764     gint *ett[NUM_INDIVIDUAL_ELEMS +
5765           NUM_NAS_EPS_COMMON_ELEM +
5766           NUM_NAS_MSG_EMM + NUM_NAS_EMM_ELEM+
5767           NUM_NAS_MSG_ESM + NUM_NAS_ESM_ELEM];
5768
5769     ett[0] = &ett_nas_eps;
5770     ett[1] = &ett_nas_eps_esm_msg_cont;
5771     ett[2] = &ett_nas_eps_nas_msg_cont;
5772     ett[3] = &ett_nas_eps_gen_msg_cont;
5773     ett[4] = &ett_nas_eps_cmn_add_info;
5774
5775     last_offset = NUM_INDIVIDUAL_ELEMS;
5776
5777     for (i=0; i < NUM_NAS_EPS_COMMON_ELEM; i++, last_offset++)
5778     {
5779         ett_nas_eps_common_elem[i] = -1;
5780         ett[last_offset] = &ett_nas_eps_common_elem[i];
5781     }
5782
5783     /* EMM */
5784     for (i=0; i < NUM_NAS_MSG_EMM; i++, last_offset++)
5785     {
5786         ett_nas_msg_emm[i] = -1;
5787         ett[last_offset] = &ett_nas_msg_emm[i];
5788     }
5789
5790     for (i=0; i < NUM_NAS_EMM_ELEM; i++, last_offset++)
5791     {
5792         ett_nas_eps_emm_elem[i] = -1;
5793         ett[last_offset] = &ett_nas_eps_emm_elem[i];
5794     }
5795     /* EPS */
5796     for (i=0; i < NUM_NAS_MSG_ESM; i++, last_offset++)
5797     {
5798         ett_nas_msg_esm[i] = -1;
5799         ett[last_offset] = &ett_nas_msg_esm[i];
5800     }
5801
5802     for (i=0; i < NUM_NAS_ESM_ELEM; i++, last_offset++)
5803     {
5804         ett_nas_eps_esm_elem[i] = -1;
5805         ett[last_offset] = &ett_nas_eps_esm_elem[i];
5806     }
5807
5808     /* Register protocol */
5809     proto_nas_eps = proto_register_protocol(PNAME, PSNAME, PFNAME);
5810     /* Register fields and subtrees */
5811     proto_register_field_array(proto_nas_eps, hf, array_length(hf));
5812     proto_register_subtree_array(ett, array_length(ett));
5813
5814     /* Register dissector */
5815     register_dissector(PFNAME, dissect_nas_eps, proto_nas_eps);
5816
5817     /* Register dissector */
5818     register_dissector("nas-eps_plain", dissect_nas_eps_plain, proto_nas_eps);
5819
5820     /* Register configuration options to always dissect as plain messages */
5821     nas_eps_module = prefs_register_protocol(proto_nas_eps, NULL);
5822
5823     prefs_register_bool_preference(nas_eps_module,
5824                                    "dissect_plain",
5825                                    "Force dissect as plain NAS EPS",
5826                                    "Always dissect NAS EPS messages as plain",
5827                                    &g_nas_eps_dissect_plain);
5828 }
5829
5830 void
5831 proto_reg_handoff_nas_eps(void)
5832 {
5833     gsm_a_dtap_handle = find_dissector("gsm_a_dtap");
5834     lpp_handle = find_dissector("lpp");
5835 }
5836