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