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