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