Move the GSM SMS dissection to a dedicated subdissector (currently still within
[obnox/wireshark/wip.git] / packet-ansi_683.c
1 /* packet-ansi_683.c
2  * Routines for ANSI IS-683-A (OTA (Mobile)) dissection
3  *
4  * Copyright 2003, Michael Lum <mlum [AT] telostech.com>
5  * In association with Telos Technology Inc.
6  *
7  * $Id: packet-ansi_683.c,v 1.4 2003/12/08 23:40:12 guy Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@ethereal.com>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <gmodule.h>
35
36 #ifdef HAVE_SYS_TYPES_H
37 # include <sys/types.h>
38 #endif
39
40 #ifdef HAVE_NETINET_IN_H
41 # include <netinet/in.h>
42 #endif
43
44 #include <string.h>
45
46 #include "epan/packet.h"
47
48
49 static char *ansi_proto_name = "ANSI IS-683-A (OTA (Mobile))";
50 static char *ansi_proto_name_short = "IS-683-A";
51
52 #define ANSI_683_FORWARD        0
53 #define ANSI_683_REVERSE        1
54
55
56 /* Initialize the subtree pointers */
57 static gint ett_ansi_683 = -1;
58 static gint ett_for_nam_block = -1;
59 static gint ett_for_sspr_block = -1;
60 static gint ett_rev_sspr_block = -1;
61 static gint ett_rev_nam_block = -1;
62 static gint ett_key_p = -1;
63 static gint ett_key_g = -1;
64 static gint ett_rev_feat = -1;
65 static gint ett_for_val_block = -1;
66 static gint ett_band_cap = -1;
67
68 /* Initialize the protocol and registered fields */
69 static int proto_ansi_683 = -1;
70 static int hf_ansi_683_none = -1;
71 static int hf_ansi_683_for_msg_type = -1;
72 static int hf_ansi_683_rev_msg_type = -1;
73 static int hf_ansi_683_length = -1;
74
75 static char bigbuf[1024];
76 static dissector_handle_t data_handle;
77 static packet_info *g_pinfo;
78 static proto_tree *g_tree;
79
80
81 /* FUNCTIONS */
82
83 static gchar *
84 my_match_strval(guint32 val, const value_string *vs, gint *idx)
85 {
86     gint i = 0;
87
88     while (vs[i].strptr)
89     {
90         if (vs[i].value == val)
91         {
92             *idx = i;
93             return(vs[i].strptr);
94         }
95
96         i++;
97     }
98
99     *idx = -1;
100     return(NULL);
101 }
102
103
104 /* PARAM FUNCTIONS */
105
106 #define EXTRANEOUS_DATA_CHECK(edc_len, edc_max_len) \
107     if ((edc_len) > (edc_max_len)) \
108     { \
109         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb, \
110             offset, (edc_len) - (edc_max_len), "Extraneous Data"); \
111     }
112
113 #define SHORT_DATA_CHECK(sdc_len, sdc_min_len) \
114     if ((sdc_len) < (sdc_min_len)) \
115     { \
116         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb, \
117             offset, (sdc_len), "Short Data (?)"); \
118         return; \
119     }
120
121 #define EXACT_DATA_CHECK(edc_len, edc_eq_len) \
122     if ((edc_len) != (edc_eq_len)) \
123     { \
124         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb, \
125             offset, (edc_len), "Unexpected Data Length"); \
126         return; \
127     }
128
129 static gchar *
130 rev_feat_id_type(guint8 feat_id)
131 {
132     gchar       *str;
133
134     switch (feat_id)
135     {
136     case 0: str = "NAM Download (DATA_P_REV)"; break;
137     case 1: str = "Key Exchange (A_KEY_P_REV)"; break;
138     case 2: str = "System Selection for Preferred Roaming (SSPR_P_REV)"; break;
139     case 3: str = "Service Programming Lock (SPL_P_REV)"; break;
140     case 4: str = "Over-The-Air Parameter Administration (OTAPA_P_REV)"; break;
141     default:
142         if ((feat_id >= 5) && (feat_id <= 191)) { str = "Reserved for future standardization"; break; }
143         else if ((feat_id >= 192) && (feat_id <= 254)) { str = "Available for manufacturer-specific features"; break; }
144         else { str = "Reserved"; break; }
145     }
146
147     return(str);
148 }
149
150 static gchar *
151 rev_res_code_type(guint8 res_code)
152 {
153     gchar       *str;
154
155     switch (res_code)
156     {
157     case 0: str = "Accepted - Operation successful"; break;
158     case 1: str = "Rejected - Unknown reason"; break;
159     case 2: str = "Rejected - Data size mismatch"; break;
160     case 3: str = "Rejected - Protocol version mismatch"; break;
161     case 4: str = "Rejected - Invalid parameter"; break;
162     case 5: str = "Rejected - SID/NID length mismatch"; break;
163     case 6: str = "Rejected - Message not expected in this mode"; break;
164     case 7: str = "Rejected - BLOCK_ID value not supported"; break;
165     case 8: str = "Rejected - Preferred roaming list length mismatch"; break;
166     case 9: str = "Rejected - CRC error"; break;
167     case 10: str = "Rejected - Mobile station locked"; break;
168     case 11: str = "Rejected - Invalid SPC"; break;
169     case 12: str = "Rejected - SPC change denied by the user"; break;
170     case 13: str = "Rejected - Invalid SPASM"; break;
171     case 14: str = "Rejected - BLOCK_ID not expected in this mode"; break;
172     default:
173         if ((res_code >= 15) && (res_code <= 127)) { str = "Reserved for future standardization"; break; }
174         else if ((res_code >= 128) && (res_code <= 254)) { str = "Available for manufacturer-specific Result Code definitions"; break; }
175         else { str = "Reserved"; break; }
176     }
177
178     return(str);
179 }
180
181 #define VERIFY_SPC_VAL_BLOCK            0
182 #define CHANGE_SPC_VAL_BLOCK            1
183 #define VALDATE_SPASM_VAL_BLOCK         2
184
185 static gchar *
186 for_val_param_block_type(guint8 block_type)
187 {
188     gchar       *str;
189
190     switch (block_type)
191     {
192     case 0: str = "Verify SPC"; break;
193     case 1: str = "Change SPC"; break;
194     case 2: str = "Validate SPASM"; break;
195     default:
196         if ((block_type >= 3) && (block_type <= 127)) { str = "Reserved for future standardization"; break; }
197         else if ((block_type >= 128) && (block_type <= 254)) { str = "Available for manufacturer-specific parameter block definitions"; break; }
198         else { str = "Reserved"; break; }
199     }
200
201     return(str);
202 }
203
204 static gchar *
205 rev_sspr_param_block_type(guint8 block_type)
206 {
207     gchar       *str;
208
209     switch (block_type)
210     {
211     case 0: str = "Preferred Roaming List Dimensions"; break;
212     case 1: str = "Preferred Roaming List"; break;
213     default:
214         if ((block_type >= 2) && (block_type <= 127)) { str = "Reserved for future standardization"; break; }
215         else if ((block_type >= 128) && (block_type <= 254)) { str = "Available for manufacturer-specific parameter block definitions"; break; }
216         else { str = "Reserved"; break; }
217     }
218
219     return(str);
220 }
221
222 static gchar *
223 for_sspr_param_block_type(guint8 block_type)
224 {
225     gchar       *str;
226
227     switch (block_type)
228     {
229     case 0: str = "Preferred Roaming List"; break;
230     default:
231         if ((block_type >= 1) && (block_type <= 127)) { str = "Reserved for future standardization"; break; }
232         else if ((block_type >= 128) && (block_type <= 254)) { str = "Available for manufacturer-specific parameter block definitions"; break; }
233         else { str = "Reserved"; break; }
234     }
235
236     return(str);
237 }
238
239 #define CDMA_ANALOG_NAM_BLOCK   0
240 #define MDN_NAM_BLOCK           1
241 #define CDMA_NAM_BLOCK          2
242 #define IMSI_T_NAM_BLOCK        3
243
244 static gchar *
245 rev_nam_param_block_type(guint8 block_type)
246 {
247     gchar       *str;
248
249     switch (block_type)
250     {
251     case 0: str = "CDMA/Analog NAM"; break;
252     case 1: str = "Mobile Directory Number"; break;
253     case 2: str = "CDMA NAM"; break;
254     case 3: str = "IMSI_T"; break;
255     default:
256         if ((block_type >= 4) && (block_type <= 127)) { str = "Reserved for future standardization"; break; }
257         else if ((block_type >= 128) && (block_type <= 254)) { str = "Available for manufacturer-specific parameter block definitions"; break; }
258         else { str = "Reserved"; break; }
259     }
260
261     return(str);
262 }
263
264 static gchar *
265 for_nam_param_block_type(guint8 block_type)
266 {
267     gchar       *str;
268
269     switch (block_type)
270     {
271     case 0: str = "CDMA/Analog NAM Download"; break;
272     case 1: str = "Mobile Directory Number"; break;
273     case 2: str = "CDMA NAM Download"; break;
274     case 3: str = "IMSI_T"; break;
275     default:
276         if ((block_type >= 4) && (block_type <= 127)) { str = "Reserved for future standardization"; break; }
277         else if ((block_type >= 128) && (block_type <= 254)) { str = "Available for manufacturer-specific parameter block definitions"; break; }
278         else { str = "Reserved"; break; }
279     }
280
281     return(str);
282 }
283
284 static void
285 param_verify_spc_val_block(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
286 {
287     guint32     saved_offset;
288     guint32     value;
289
290
291     EXACT_DATA_CHECK(len, 3);
292
293     saved_offset = offset;
294
295     value = tvb_get_ntoh24(tvb, offset);
296
297     proto_tree_add_none_format(tree, hf_ansi_683_none,
298         tvb, offset, len,
299         "Service programming code (%d)",
300         value);
301 }
302
303 static void
304 param_cdma_analog_nam_block(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
305 {
306     guint32     saved_offset;
307     guint32     value;
308     guint32     count;
309
310     saved_offset = offset;
311
312     value = tvb_get_ntohs(tvb, offset);
313
314     other_decode_bitfield_value(bigbuf, value, 0xffe0, 16);
315     proto_tree_add_none_format(tree, hf_ansi_683_none,
316         tvb, offset, 2,
317         "%s :  First paging channel (FIRSTCHP) used in the home system (%d)",
318         bigbuf,
319         (value & 0xffe0) >> 5);
320
321     offset++;
322
323     value = tvb_get_ntoh24(tvb, offset);
324
325     other_decode_bitfield_value(bigbuf, value, 0x1fffc0, 24);
326     proto_tree_add_none_format(tree, hf_ansi_683_none,
327         tvb, offset, 3,
328         "%s :  Home system identification (HOME_SID) (%d)",
329         bigbuf,
330         (value & 0x1fffc0) >> 6);
331
332     other_decode_bitfield_value(bigbuf, value, 0x20, 8);
333     proto_tree_add_none_format(tree, hf_ansi_683_none,
334         tvb, offset + 2, 1,
335         "%s :  Extended address indicator (EX)",
336         bigbuf);
337
338     offset += 2;
339
340     value = tvb_get_ntohs(tvb, offset);
341
342     other_decode_bitfield_value(bigbuf, value, 0x1fe0, 16);
343     proto_tree_add_none_format(tree, hf_ansi_683_none,
344         tvb, offset, 2,
345         "%s :  Station class mark (SCM) (%d)",
346         bigbuf,
347         (value & 0x1fe0) >> 5);
348
349     offset++;
350
351     value = tvb_get_ntohs(tvb, offset);
352
353     other_decode_bitfield_value(bigbuf, value, 0x1fe0, 16);
354     proto_tree_add_none_format(tree, hf_ansi_683_none,
355         tvb, offset, 2,
356         "%s :  Mobile station protocol revision number (MOB_P_REV) (%d)",
357         bigbuf,
358         (value & 0x1fe0) >> 5);
359
360     other_decode_bitfield_value(bigbuf, value, 0x10, 8);
361     proto_tree_add_none_format(tree, hf_ansi_683_none,
362         tvb, offset + 1, 1,
363         "%s :  IMSI_M Class assignment of the mobile station (IMSI_M_CLASS), Class %d",
364         bigbuf,
365         (value & 0x10) >> 4);
366
367     other_decode_bitfield_value(bigbuf, value, 0x0e, 8);
368     proto_tree_add_none_format(tree, hf_ansi_683_none,
369         tvb, offset + 1, 1,
370         "%s :  Number of IMSI_M address digits (IMSI_M_ADDR_NUM) (%d), %d digits in NMSI",
371         bigbuf,
372         (value & 0x0e) >> 1,
373         (value & 0x10) ? ((value & 0x0e) >> 1) + 4 : 0);
374
375     offset++;
376
377     value = tvb_get_ntoh24(tvb, offset);
378
379     other_decode_bitfield_value(bigbuf, value, 0x01ff80, 24);
380     proto_tree_add_none_format(tree, hf_ansi_683_none,
381         tvb, offset, 3,
382         "%s :  Mobile country code (MCC_M)",
383         bigbuf);
384
385     other_decode_bitfield_value(bigbuf, value, 0x7f, 8);
386     proto_tree_add_none_format(tree, hf_ansi_683_none,
387         tvb, offset + 2, 1,
388         "%s :  11th and 12th digits of the IMSI_M (IMSI__M_11_12)",
389         bigbuf);
390
391     offset += 3;
392
393     proto_tree_add_none_format(tree, hf_ansi_683_none,
394         tvb, offset, 5,
395         "The least significant 10 digits of the IMSI_M (IMSI_M_S) (34 bits)");
396
397     offset += 4;
398
399     value = tvb_get_guint8(tvb, offset);
400
401     other_decode_bitfield_value(bigbuf, value, 0x3c, 8);
402     proto_tree_add_none_format(tree, hf_ansi_683_none,
403         tvb, offset, 1,
404         "%s :  Access overload class (ACCOLC) (%d)",
405         bigbuf,
406         (value & 0x3c) >> 2);
407
408     other_decode_bitfield_value(bigbuf, value, 0x02, 8);
409     proto_tree_add_none_format(tree, hf_ansi_683_none,
410         tvb, offset, 1,
411         "%s :  Local control status (LOCAL_CONTROL)",
412         bigbuf);
413
414     other_decode_bitfield_value(bigbuf, value, 0x01, 8);
415     proto_tree_add_none_format(tree, hf_ansi_683_none,
416         tvb, offset, 1,
417         "%s :  Termination indicator for the home system (MOB_TERM_HOME)",
418         bigbuf);
419
420     offset++;
421
422     value = tvb_get_guint8(tvb, offset);
423
424     other_decode_bitfield_value(bigbuf, value, 0x80, 8);
425     proto_tree_add_none_format(tree, hf_ansi_683_none,
426         tvb, offset, 1,
427         "%s :  Termination indicator for SID roaming (MOB_TERM_FOR_SID)",
428         bigbuf);
429
430     other_decode_bitfield_value(bigbuf, value, 0x40, 8);
431     proto_tree_add_none_format(tree, hf_ansi_683_none,
432         tvb, offset, 1,
433         "%s :  Termination indicator for NID roaming (MOB_TERM_FOR_NID)",
434         bigbuf);
435
436     value = tvb_get_ntohs(tvb, offset);
437
438     other_decode_bitfield_value(bigbuf, value, 0x3fc0, 16);
439     proto_tree_add_none_format(tree, hf_ansi_683_none,
440         tvb, offset, 2,
441         "%s :  Maximum stored SID/NID pairs (MAX_SID_NID) (%d)",
442         bigbuf,
443         (value & 0x3fc0) >> 6);
444
445     offset++;
446
447     value = tvb_get_ntohs(tvb, offset);
448
449     count = (value & 0x3fc0) >> 6;
450
451     other_decode_bitfield_value(bigbuf, value, 0x3fc0, 16);
452     proto_tree_add_none_format(tree, hf_ansi_683_none,
453         tvb, offset, 2,
454         "%s :  Number of stored SID/NID pairs (STORED_SID_NID) (%d)",
455         bigbuf,
456         count);
457
458     other_decode_bitfield_value(bigbuf, value, 0x003f, 16);
459     proto_tree_add_none_format(tree, hf_ansi_683_none,
460         tvb, offset, 2,
461         "%s :  SID/NID pairs (MSB)",
462         bigbuf);
463
464     offset += 2;
465
466     proto_tree_add_none_format(tree, hf_ansi_683_none,
467         tvb, offset, len - (offset - saved_offset),
468         "SID/NID pairs, Reserved");
469 }
470
471 static void
472 param_mdn_nam_block(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
473 {
474     guint32     saved_offset;
475     guint32     value, count, i;
476
477     memset((void *) bigbuf, 0, sizeof(bigbuf));
478
479     saved_offset = offset;
480
481     value = tvb_get_guint8(tvb, offset);
482
483     count = (value & 0xf0) >> 4;
484
485     other_decode_bitfield_value(bigbuf, value, 0xf0, 8);
486     proto_tree_add_none_format(tree, hf_ansi_683_none,
487         tvb, offset, 1,
488         "%s :  Number of digits (N_DIGITS) (%d)",
489         bigbuf,
490         count);
491
492     for (i=0; i < count; i++)
493     {
494         bigbuf[i] = 0x30 + (value & 0x0f);
495
496         if ((i + 1) < count)
497         {
498             offset++;
499             value = tvb_get_guint8(tvb, offset);
500             bigbuf[i+1] = 0x30 + (value & 0xf0);
501             i++;
502         }
503     }
504
505     proto_tree_add_none_format(tree, hf_ansi_683_none,
506         tvb, saved_offset, len,
507         "Mobile directory number, %s",
508         bigbuf);
509
510     if (!(count & 0x01))
511     {
512         other_decode_bitfield_value(bigbuf, value, 0x0f, 8);
513         proto_tree_add_none_format(tree, hf_ansi_683_none,
514             tvb, offset, 1,
515             "%s :  Reserved",
516             bigbuf);
517     }
518 }
519
520 static void
521 param_cdma_nam_block(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
522 {
523     guint32     saved_offset;
524     guint32     value;
525     guint32     count;
526
527     saved_offset = offset;
528
529     value = tvb_get_guint8(tvb, offset);
530
531     other_decode_bitfield_value(bigbuf, value, 0xc0, 8);
532     proto_tree_add_none_format(tree, hf_ansi_683_none,
533         tvb, offset, 1,
534         "%s :  Reserved",
535         bigbuf);
536
537     other_decode_bitfield_value(bigbuf, value, 0x20, 8);
538     proto_tree_add_none_format(tree, hf_ansi_683_none,
539         tvb, offset, 1,
540         "%s :  Slotted Mode",
541         bigbuf);
542
543     other_decode_bitfield_value(bigbuf, value, 0x1f, 8);
544     proto_tree_add_none_format(tree, hf_ansi_683_none,
545         tvb, offset, 1,
546         "%s :  Reserved",
547         bigbuf);
548
549     offset++;
550
551     value = tvb_get_guint8(tvb, offset);
552
553     other_decode_bitfield_value(bigbuf, value, 0xff, 8);
554     proto_tree_add_none_format(tree, hf_ansi_683_none,
555         tvb, offset, 1,
556         "%s :  Mobile station protocol revision number (MOB_P_REV) (%d)",
557         bigbuf,
558         value);
559
560     offset++;
561
562     value = tvb_get_ntohs(tvb, offset);
563
564     other_decode_bitfield_value(bigbuf, value, 0x8000, 16);
565     proto_tree_add_none_format(tree, hf_ansi_683_none,
566         tvb, offset, 2,
567         "%s :  IMSI_M Class assignment of the mobile station (IMSI_M_CLASS), Class %d",
568         bigbuf,
569         (value & 0x8000) >> 15);
570
571     other_decode_bitfield_value(bigbuf, value, 0x7000, 16);
572     proto_tree_add_none_format(tree, hf_ansi_683_none,
573         tvb, offset, 2,
574         "%s :  Number of IMSI_M address digits (IMSI_M_ADDR_NUM) (%d), %d digits in NMSI",
575         bigbuf,
576         (value & 0x7000) >> 12,
577         (value & 0x8000) ? ((value & 0x7000) >> 12) + 4 : 0);
578
579     other_decode_bitfield_value(bigbuf, value, 0x0ffc, 16);
580     proto_tree_add_none_format(tree, hf_ansi_683_none,
581         tvb, offset, 2,
582         "%s :  Mobile country code (MCC_M)",
583         bigbuf);
584
585     offset++;
586
587     value = tvb_get_ntohs(tvb, offset);
588
589     other_decode_bitfield_value(bigbuf, value, 0x3f80, 16);
590     proto_tree_add_none_format(tree, hf_ansi_683_none,
591         tvb, offset, 2,
592         "%s :  11th and 12th digits of the IMSI_M (IMSI__M_11_12)",
593         bigbuf);
594
595     offset++;
596
597     proto_tree_add_none_format(tree, hf_ansi_683_none,
598         tvb, offset, 5,
599         "The least significant 10 digits of the IMSI_M (IMSI_M_S) (34 bits)");
600
601     offset += 4;
602
603     value = tvb_get_ntohs(tvb, offset);
604
605     other_decode_bitfield_value(bigbuf, value, 0x01e0, 16);
606     proto_tree_add_none_format(tree, hf_ansi_683_none,
607         tvb, offset, 2,
608         "%s :  Access overload class (ACCOLC) (%d)",
609         bigbuf,
610         (value & 0x01e0) >> 5);
611
612     other_decode_bitfield_value(bigbuf, value, 0x10, 8);
613     proto_tree_add_none_format(tree, hf_ansi_683_none,
614         tvb, offset+1, 1,
615         "%s :  Local control status (LOCAL_CONTROL)",
616         bigbuf);
617
618     other_decode_bitfield_value(bigbuf, value, 0x08, 8);
619     proto_tree_add_none_format(tree, hf_ansi_683_none,
620         tvb, offset+1, 1,
621         "%s :  Termination indicator for the home system (MOB_TERM_HOME)",
622         bigbuf);
623
624     other_decode_bitfield_value(bigbuf, value, 0x04, 8);
625     proto_tree_add_none_format(tree, hf_ansi_683_none,
626         tvb, offset+1, 1,
627         "%s :  Termination indicator for SID roaming (MOB_TERM_FOR_SID)",
628         bigbuf);
629
630     other_decode_bitfield_value(bigbuf, value, 0x02, 8);
631     proto_tree_add_none_format(tree, hf_ansi_683_none,
632         tvb, offset+1, 1,
633         "%s :  Termination indicator for NID roaming (MOB_TERM_FOR_NID)",
634         bigbuf);
635
636     offset++;
637
638     value = tvb_get_ntohs(tvb, offset);
639
640     other_decode_bitfield_value(bigbuf, value, 0x01fe, 16);
641     proto_tree_add_none_format(tree, hf_ansi_683_none,
642         tvb, offset, 2,
643         "%s :  Maximum stored SID/NID pairs (MAX_SID_NID) (%d)",
644         bigbuf,
645         (value & 0x01fe) >> 1);
646
647     offset++;
648
649     value = tvb_get_ntohs(tvb, offset);
650
651     count = (value & 0x01fe) >> 1;
652
653     other_decode_bitfield_value(bigbuf, value, 0x01fe, 16);
654     proto_tree_add_none_format(tree, hf_ansi_683_none,
655         tvb, offset, 2,
656         "%s :  Number of stored SID/NID pairs (STORED_SID_NID) (%d)",
657         bigbuf,
658         count);
659
660     other_decode_bitfield_value(bigbuf, value, 0x01, 8);
661     proto_tree_add_none_format(tree, hf_ansi_683_none,
662         tvb, offset+1, 1,
663         "%s :  SID/NID pairs (MSB)",
664         bigbuf);
665
666     offset += 2;
667
668     proto_tree_add_none_format(tree, hf_ansi_683_none,
669         tvb, offset, len - (offset - saved_offset),
670         "SID/NID pairs, Reserved");
671 }
672
673 static void
674 param_imsi_t_nam_block(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
675 {
676     guint32     saved_offset;
677     guint32     value;
678
679     /*
680      * XXX avoid warning for now, may use this variable
681      * for validation later
682      */
683     len = len;
684
685     saved_offset = offset;
686
687     value = tvb_get_guint8(tvb, offset);
688
689     other_decode_bitfield_value(bigbuf, value, 0x80, 8);
690     proto_tree_add_none_format(tree, hf_ansi_683_none,
691         tvb, offset, 1,
692         "%s :  IMSI_T Class assignment of the mobile station (IMSI_T_CLASS), Class %d",
693         bigbuf,
694         (value & 0x80) >> 7);
695
696     other_decode_bitfield_value(bigbuf, value, 0x70, 8);
697     proto_tree_add_none_format(tree, hf_ansi_683_none,
698         tvb, offset, 1,
699         "%s :  Number of IMSI_T address digits (IMSI_T_ADDR_NUM ) (%d), %d digits in NMSI",
700         bigbuf,
701         (value & 0x70) >> 4,
702         (value & 0x80) ? ((value & 0x70) >> 4) + 4 : 0);
703
704     value = tvb_get_ntohs(tvb, offset);
705
706     other_decode_bitfield_value(bigbuf, value, 0x0ffc, 16);
707     proto_tree_add_none_format(tree, hf_ansi_683_none,
708         tvb, offset, 2,
709         "%s :  Mobile country code (MCC_T)",
710         bigbuf);
711
712     offset++;
713
714     value = tvb_get_ntohs(tvb, offset);
715
716     other_decode_bitfield_value(bigbuf, value, 0x03f8, 16);
717     proto_tree_add_none_format(tree, hf_ansi_683_none,
718         tvb, offset, 2,
719         "%s :  11th and 12th digits of the IMSI_T (IMSI__T_11_12)",
720         bigbuf);
721
722     offset++;
723
724     proto_tree_add_none_format(tree, hf_ansi_683_none,
725         tvb, offset, 5,
726         "The least significant 10 digits of the IMSI_T (IMSI_T_S) (34 bits)");
727
728     offset += 4;
729
730     value = tvb_get_guint8(tvb, offset);
731
732     other_decode_bitfield_value(bigbuf, value, 0x01, 8);
733     proto_tree_add_none_format(tree, hf_ansi_683_none,
734         tvb, offset, 1,
735         "%s :  Reserved",
736         bigbuf);
737 }
738
739 static void
740 msg_config_req(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
741 {
742     guint8      oct, num_blocks;
743     gchar       *str = NULL;
744     guint32     i, saved_offset;
745
746     SHORT_DATA_CHECK(len, 1);
747
748     saved_offset = offset;
749
750     num_blocks = tvb_get_guint8(tvb, offset);
751
752     proto_tree_add_none_format(tree, hf_ansi_683_none,
753         tvb, offset, 1,
754         "Number of parameter blocks (%d)",
755         num_blocks);
756
757     offset++;
758
759     if (num_blocks > (len - (offset - saved_offset)))
760     {
761         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
762             offset, len - (offset - saved_offset), "Short Data (?)");
763         return;
764     }
765
766     for (i=0; i < num_blocks; i++)
767     {
768         oct = tvb_get_guint8(tvb, offset);
769
770         str = rev_nam_param_block_type(oct);
771
772         proto_tree_add_none_format(tree, hf_ansi_683_none,
773             tvb, offset, 1,
774             "%s (%d)",
775             str,
776             oct);
777
778         offset++;
779     }
780
781     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
782 }
783
784 static void
785 msg_download_req(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
786 {
787     guint8      oct, block_id, block_len;
788     gchar       *str = NULL;
789     proto_tree  *subtree;
790     proto_item  *item;
791     guint32     i, saved_offset;
792
793     SHORT_DATA_CHECK(len, 1);
794
795     saved_offset = offset;
796
797     oct = tvb_get_guint8(tvb, offset);
798
799     proto_tree_add_none_format(tree, hf_ansi_683_none,
800         tvb, offset, 1,
801         "Number of parameter blocks (%d)",
802         oct);
803
804     offset++;
805
806     for (i=0; i < oct; i++)
807     {
808         block_id = tvb_get_guint8(tvb, offset);
809
810         str = for_nam_param_block_type(block_id);
811
812         item =
813             proto_tree_add_none_format(tree, hf_ansi_683_none,
814                 tvb, offset, 1,
815                 "%s (%d)",
816                 str,
817                 block_id);
818
819         subtree = proto_item_add_subtree(item, ett_for_nam_block);
820         offset++;
821
822         block_len = tvb_get_guint8(tvb, offset);
823
824         proto_tree_add_uint(subtree, hf_ansi_683_length,
825             tvb, offset, 1, block_len);
826         offset++;
827
828         if (block_len > (len - (offset - saved_offset)))
829         {
830             proto_tree_add_none_format(subtree, hf_ansi_683_none, tvb,
831                 offset, len - (offset - saved_offset), "Short Data (?)");
832             return;
833         }
834
835         if (block_len > 0)
836         {
837             switch (block_id)
838             {
839             case CDMA_ANALOG_NAM_BLOCK:
840                 param_cdma_analog_nam_block(tvb, subtree, block_len, offset);
841                 break;
842
843             case MDN_NAM_BLOCK:
844                 param_mdn_nam_block(tvb, subtree, block_len, offset);
845                 break;
846
847             case CDMA_NAM_BLOCK:
848                 param_cdma_nam_block(tvb, subtree, block_len, offset);
849                 break;
850
851             case IMSI_T_NAM_BLOCK:
852                 param_imsi_t_nam_block(tvb, subtree, block_len, offset);
853                 break;
854
855             default:
856                 proto_tree_add_none_format(subtree, hf_ansi_683_none,
857                     tvb, offset, block_len, "Block Data");
858                 break;
859             }
860
861             offset += block_len;
862         }
863     }
864
865     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
866 }
867
868 static void
869 msg_ms_key_req(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
870 {
871     guint8      oct, param_len;
872     proto_tree  *subtree;
873     proto_item  *item;
874     guint32     saved_offset;
875
876     SHORT_DATA_CHECK(len, 3);
877
878     saved_offset = offset;
879
880     oct = tvb_get_guint8(tvb, offset);
881
882     proto_tree_add_none_format(tree, hf_ansi_683_none,
883         tvb, offset, 1,
884         "A-Key Protocol Revision (%d)",
885         oct);
886     offset++;
887
888     param_len = tvb_get_guint8(tvb, offset);
889
890     item =
891         proto_tree_add_none_format(tree, hf_ansi_683_none,
892             tvb, offset, param_len + 1,
893             "Key exchange parameter P");
894     subtree = proto_item_add_subtree(item, ett_key_p);
895
896     proto_tree_add_uint(subtree, hf_ansi_683_length,
897         tvb, offset, 1, param_len);
898     offset++;
899
900     if (param_len > 0)
901     {
902         proto_tree_add_none_format(subtree, hf_ansi_683_none,
903             tvb, offset, param_len,
904             "Parameter P");
905         offset += param_len;
906     }
907
908     param_len = tvb_get_guint8(tvb, offset);
909
910     item =
911         proto_tree_add_none_format(tree, hf_ansi_683_none,
912             tvb, offset, param_len + 1,
913             "Key exchange parameter G");
914     subtree = proto_item_add_subtree(item, ett_key_g);
915
916     proto_tree_add_uint(subtree, hf_ansi_683_length,
917         tvb, offset, 1, param_len);
918     offset++;
919
920     if (param_len > 0)
921     {
922         proto_tree_add_none_format(subtree, hf_ansi_683_none,
923             tvb, offset, param_len,
924             "Parameter G");
925         offset += param_len;
926     }
927
928     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
929 }
930
931 static void
932 msg_key_gen_req(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
933 {
934     guint8      param_len;
935     guint32     saved_offset;
936
937     SHORT_DATA_CHECK(len, 2);
938
939     saved_offset = offset;
940
941     param_len = tvb_get_guint8(tvb, offset);
942
943     proto_tree_add_uint(tree, hf_ansi_683_length,
944         tvb, offset, 1, param_len);
945     offset++;
946
947     if (param_len > (len - (offset - saved_offset)))
948     {
949         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
950             offset, len - (offset - saved_offset), "Short Data (?)");
951         return;
952     }
953
954     if (param_len > 0)
955     {
956         proto_tree_add_none_format(tree, hf_ansi_683_none,
957             tvb, offset, param_len,
958             "Calculation Result");
959         offset += param_len;
960     }
961
962     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
963 }
964
965 static void
966 msg_reauth_req(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
967 {
968
969     EXACT_DATA_CHECK(len, 4);
970
971     proto_tree_add_none_format(tree, hf_ansi_683_none,
972         tvb, offset, 4,
973         "Random Challenge value");
974 }
975
976 static void
977 msg_sspr_config_req(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
978 {
979     guint8      oct;
980     gchar       *str = NULL;
981     guint32     saved_offset;
982     guint32     value;
983     proto_tree  *subtree;
984     proto_item  *item;
985
986     SHORT_DATA_CHECK(len, 1);
987
988     saved_offset = offset;
989
990     oct = tvb_get_guint8(tvb, offset);
991
992     str = rev_sspr_param_block_type(oct);
993
994     item =
995         proto_tree_add_none_format(tree, hf_ansi_683_none,
996             tvb, offset, 1,
997             "%s (%d)",
998             str,
999             oct);
1000
1001     offset++;
1002
1003     if (oct == 0x01)
1004     {
1005         subtree = proto_item_add_subtree(item, ett_rev_sspr_block);
1006
1007         if ((len - (offset - saved_offset)) < 3)
1008         {
1009             proto_tree_add_none_format(subtree, hf_ansi_683_none, tvb,
1010                 offset, len - (offset - saved_offset), "Short Data (?)");
1011             return;
1012         }
1013
1014         value = tvb_get_ntohs(tvb, offset);
1015
1016         proto_tree_add_none_format(subtree, hf_ansi_683_none,
1017             tvb, offset, 2,
1018             "Segment offset (%d)",
1019             value);
1020         offset += 2;
1021
1022         oct = tvb_get_guint8(tvb, offset);
1023
1024         proto_tree_add_none_format(subtree, hf_ansi_683_none,
1025             tvb, offset, 1,
1026             "Maximum segment size (%d)",
1027             oct);
1028         offset++;
1029     }
1030
1031     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
1032 }
1033
1034 static void
1035 msg_sspr_download_req(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1036 {
1037     guint8      oct, block_len;
1038     gchar       *str = NULL;
1039     guint32     saved_offset;
1040     proto_tree  *subtree;
1041     proto_item  *item;
1042
1043     SHORT_DATA_CHECK(len, 2);
1044
1045     saved_offset = offset;
1046
1047     oct = tvb_get_guint8(tvb, offset);
1048
1049     str = for_sspr_param_block_type(oct);
1050
1051     item =
1052         proto_tree_add_none_format(tree, hf_ansi_683_none,
1053             tvb, offset, 1,
1054             "%s (%d)",
1055             str,
1056             oct);
1057
1058     subtree = proto_item_add_subtree(item, ett_for_sspr_block);
1059     offset++;
1060
1061     block_len = tvb_get_guint8(tvb, offset);
1062
1063     proto_tree_add_uint(subtree, hf_ansi_683_length,
1064         tvb, offset, 1, block_len);
1065     offset++;
1066
1067     if (block_len > (len - (offset - saved_offset)))
1068     {
1069         proto_tree_add_none_format(subtree, hf_ansi_683_none, tvb,
1070             offset, len - (offset - saved_offset), "Short Data (?)");
1071         return;
1072     }
1073
1074     if (block_len > 0)
1075     {
1076         proto_tree_add_none_format(subtree, hf_ansi_683_none,
1077             tvb, offset, block_len, "Block Data");
1078         offset += block_len;
1079     }
1080
1081     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
1082 }
1083
1084 static void
1085 msg_validate_req(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1086 {
1087     guint8      oct, block_id, block_len;
1088     gchar       *str = NULL;
1089     proto_tree  *subtree;
1090     proto_item  *item;
1091     guint32     i, saved_offset, block_offset;
1092
1093     SHORT_DATA_CHECK(len, 1);
1094
1095     saved_offset = offset;
1096
1097     oct = tvb_get_guint8(tvb, offset);
1098
1099     proto_tree_add_none_format(tree, hf_ansi_683_none,
1100         tvb, offset, 1,
1101         "Number of parameter blocks (%d)",
1102         oct);
1103
1104     offset++;
1105
1106     if ((guint32)(oct * 2) > (len - (offset - saved_offset)))
1107     {
1108         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
1109             offset, len - (offset - saved_offset), "Short Data (?)");
1110         return;
1111     }
1112
1113     for (i=0; i < oct; i++)
1114     {
1115         block_offset = offset;
1116         block_id = tvb_get_guint8(tvb, offset);
1117
1118         str = for_val_param_block_type(block_id);
1119
1120         item =
1121             proto_tree_add_none_format(tree, hf_ansi_683_none,
1122                 tvb, offset, -1,
1123                 str);
1124
1125         subtree = proto_item_add_subtree(item, ett_for_val_block);
1126
1127         proto_tree_add_none_format(subtree, hf_ansi_683_none,
1128             tvb, offset, 1,
1129             "Block ID (%d)",
1130             block_id);
1131
1132         offset++;
1133
1134         block_len = tvb_get_guint8(tvb, offset);
1135
1136         proto_tree_add_uint(subtree, hf_ansi_683_length,
1137             tvb, offset, 1, block_len);
1138
1139         offset++;
1140
1141         proto_item_set_len(item, (offset - block_offset) + block_len);
1142
1143         if (block_len > (len - (offset - saved_offset)))
1144         {
1145             proto_tree_add_none_format(subtree, hf_ansi_683_none, tvb,
1146                 offset, len - (offset - saved_offset), "Short Data (?)");
1147             return;
1148         }
1149
1150         if (block_len > 0)
1151         {
1152             switch (block_id)
1153             {
1154             case VERIFY_SPC_VAL_BLOCK:
1155                 param_verify_spc_val_block(tvb, subtree, block_len, offset);
1156                 break;
1157
1158             case CHANGE_SPC_VAL_BLOCK:
1159             case VALDATE_SPASM_VAL_BLOCK:
1160             default:
1161                 proto_tree_add_none_format(subtree, hf_ansi_683_none,
1162                     tvb, offset, block_len, "Block Data");
1163                 break;
1164             }
1165
1166             offset += block_len;
1167         }
1168     }
1169
1170     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
1171 }
1172
1173 static void
1174 msg_otapa_req(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1175 {
1176     guint8      oct;
1177     guint32     saved_offset;
1178
1179     EXACT_DATA_CHECK(len, 1);
1180
1181     saved_offset = offset;
1182
1183     oct = tvb_get_guint8(tvb, offset);
1184
1185     other_decode_bitfield_value(bigbuf, oct, 0x80, 8);
1186     proto_tree_add_none_format(tree, hf_ansi_683_none,
1187         tvb, offset, 1,
1188         "%s :  %s OTAPA session",
1189         bigbuf,
1190         (oct & 0x80) ? "Start" : "Stop");
1191
1192     other_decode_bitfield_value(bigbuf, oct, 0x7f, 8);
1193     proto_tree_add_none_format(tree, hf_ansi_683_none,
1194         tvb, offset, 1,
1195         "%s :  Reserved",
1196         bigbuf);
1197
1198     offset++;
1199 }
1200
1201 static void
1202 msg_config_rsp(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1203 {
1204     guint8      oct, num_blocks, block_len;
1205     gchar       *str = NULL;
1206     guint32     i, saved_offset;
1207     proto_tree  *subtree;
1208     proto_item  *item;
1209
1210     SHORT_DATA_CHECK(len, 1);
1211
1212     saved_offset = offset;
1213
1214     num_blocks = tvb_get_guint8(tvb, offset);
1215
1216     proto_tree_add_none_format(tree, hf_ansi_683_none,
1217         tvb, offset, 1,
1218         "Number of parameter blocks (%d)",
1219         num_blocks);
1220
1221     offset++;
1222
1223     if ((guint32)(num_blocks * 2) > (len - (offset - saved_offset)))
1224     {
1225         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
1226             offset, len - (offset - saved_offset), "Short Data (?)");
1227         return;
1228     }
1229
1230     for (i=0; i < num_blocks; i++)
1231     {
1232         oct = tvb_get_guint8(tvb, offset);
1233
1234         str = rev_nam_param_block_type(oct);
1235
1236         item =
1237             proto_tree_add_none_format(tree, hf_ansi_683_none,
1238                 tvb, offset, 1,
1239                 "%s (%d)",
1240                 str,
1241                 oct);
1242
1243         subtree = proto_item_add_subtree(item, ett_rev_nam_block);
1244         offset++;
1245
1246         block_len = tvb_get_guint8(tvb, offset);
1247
1248         proto_tree_add_uint(subtree, hf_ansi_683_length,
1249             tvb, offset, 1, block_len);
1250         offset++;
1251
1252         if (block_len > (len - (offset - saved_offset)))
1253         {
1254             proto_tree_add_none_format(subtree, hf_ansi_683_none, tvb,
1255                 offset, len - (offset - saved_offset), "Short Data (?)");
1256             return;
1257         }
1258
1259         if (block_len > 0)
1260         {
1261             proto_tree_add_none_format(subtree, hf_ansi_683_none,
1262                 tvb, offset, block_len, "Block Data");
1263             offset += block_len;
1264         }
1265     }
1266
1267     if (num_blocks > (len - (offset - saved_offset)))
1268     {
1269         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
1270             offset, len - (offset - saved_offset), "Short Data (?)");
1271         return;
1272     }
1273
1274     for (i=0; i < num_blocks; i++)
1275     {
1276         oct = tvb_get_guint8(tvb, offset);
1277
1278         str = rev_res_code_type(oct);
1279
1280         proto_tree_add_none_format(tree, hf_ansi_683_none,
1281             tvb, offset, 1,
1282             "%s (%d)",
1283             str,
1284             oct);
1285
1286         offset++;
1287     }
1288
1289     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
1290 }
1291
1292 static void
1293 msg_download_rsp(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1294 {
1295     guint8      oct, num_blocks;
1296     gchar       *str = NULL;
1297     guint32     i, saved_offset;
1298     proto_tree  *subtree;
1299     proto_item  *item;
1300
1301     SHORT_DATA_CHECK(len, 1);
1302
1303     saved_offset = offset;
1304
1305     num_blocks = tvb_get_guint8(tvb, offset);
1306
1307     proto_tree_add_none_format(tree, hf_ansi_683_none,
1308         tvb, offset, 1,
1309         "Number of parameter blocks (%d)",
1310         num_blocks);
1311
1312     offset++;
1313
1314     if ((guint32)(num_blocks * 2) > (len - (offset - saved_offset)))
1315     {
1316         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
1317             offset, len - (offset - saved_offset), "Short Data (?)");
1318         return;
1319     }
1320
1321     for (i=0; i < num_blocks; i++)
1322     {
1323         oct = tvb_get_guint8(tvb, offset);
1324
1325         str = for_nam_param_block_type(oct);
1326
1327         item =
1328             proto_tree_add_none_format(tree, hf_ansi_683_none,
1329                 tvb, offset, 1,
1330                 "%s (%d)",
1331                 str,
1332                 oct);
1333
1334         subtree = proto_item_add_subtree(item, ett_for_nam_block);
1335         offset++;
1336
1337         oct = tvb_get_guint8(tvb, offset);
1338
1339         str = rev_res_code_type(oct);
1340
1341         proto_tree_add_none_format(subtree, hf_ansi_683_none,
1342             tvb, offset, 1,
1343             "%s (%d)",
1344             str,
1345             oct);
1346
1347         offset++;
1348     }
1349
1350     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
1351 }
1352
1353 static void
1354 msg_ms_key_rsp(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1355 {
1356     guint8      oct;
1357     gchar       *str = NULL;
1358     guint32     saved_offset;
1359
1360     EXACT_DATA_CHECK(len, 1);
1361
1362     saved_offset = offset;
1363
1364     oct = tvb_get_guint8(tvb, offset);
1365
1366     str = rev_res_code_type(oct);
1367
1368     proto_tree_add_none_format(tree, hf_ansi_683_none,
1369         tvb, offset, 1,
1370         "Key exchange result code, %s (%d)",
1371         str,
1372         oct);
1373
1374     offset++;
1375 }
1376
1377 static void
1378 msg_key_gen_rsp(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1379 {
1380     guint8      oct, result_len;
1381     gchar       *str = NULL;
1382     guint32     saved_offset;
1383
1384     SHORT_DATA_CHECK(len, 2);
1385
1386     saved_offset = offset;
1387
1388     oct = tvb_get_guint8(tvb, offset);
1389
1390     str = rev_res_code_type(oct);
1391
1392     proto_tree_add_none_format(tree, hf_ansi_683_none,
1393         tvb, offset, 1,
1394         "Key exchange result code, %s (%d)",
1395         str,
1396         oct);
1397
1398     offset++;
1399
1400     result_len = tvb_get_guint8(tvb, offset);
1401
1402     proto_tree_add_uint(tree, hf_ansi_683_length,
1403         tvb, offset, 1, result_len);
1404     offset++;
1405
1406     if (result_len > (len - (offset - saved_offset)))
1407     {
1408         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
1409             offset, len - (offset - saved_offset), "Short Data (?)");
1410         return;
1411     }
1412
1413     if (result_len > 0)
1414     {
1415         proto_tree_add_none_format(tree, hf_ansi_683_none,
1416             tvb, offset, result_len, "Calculation Result");
1417         offset += result_len;
1418     }
1419
1420     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
1421 }
1422
1423 static void
1424 msg_reauth_rsp(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1425 {
1426     guint32     saved_offset;
1427     guint32     value;
1428
1429     EXACT_DATA_CHECK(len, 7);
1430
1431     saved_offset = offset;
1432
1433     value = tvb_get_ntoh24(tvb, offset);
1434
1435     other_decode_bitfield_value(bigbuf, value, 0xffffc0, 24);
1436     proto_tree_add_none_format(tree, hf_ansi_683_none,
1437         tvb, offset, 3,
1438         "%s :  Authentication signature data (AUTHR) (%d)",
1439         bigbuf,
1440         (value & 0xffffc0) >> 6);
1441
1442     offset += 2;
1443
1444     value = tvb_get_ntohs(tvb, offset);
1445
1446     other_decode_bitfield_value(bigbuf, value, 0x3fc0, 16);
1447     proto_tree_add_none_format(tree, hf_ansi_683_none,
1448         tvb, offset, 2,
1449         "%s :  Random challenge value (RANDC) (%d)",
1450         bigbuf,
1451         (value & 0x3fc0) >> 6);
1452
1453     other_decode_bitfield_value(bigbuf, value, 0x3f, 8);
1454     proto_tree_add_none_format(tree, hf_ansi_683_none,
1455         tvb, offset + 1, 1,
1456         "%s :  Call history parameter (COUNT) (%d)",
1457         bigbuf,
1458         value & 0x3f);
1459
1460     offset += 2;
1461
1462     value = tvb_get_ntoh24(tvb, offset);
1463
1464     other_decode_bitfield_value(bigbuf, value, 0xffffff, 24);
1465     proto_tree_add_none_format(tree, hf_ansi_683_none,
1466         tvb, offset, 3,
1467         "%s :  Authentication Data input parameter (AUTH_DATA) (%d)",
1468         bigbuf,
1469         value);
1470 }
1471
1472 static void
1473 msg_commit_rsp(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1474 {
1475     guint8      oct;
1476     gchar       *str = NULL;
1477     guint32     saved_offset;
1478
1479     EXACT_DATA_CHECK(len, 1);
1480
1481     saved_offset = offset;
1482
1483     oct = tvb_get_guint8(tvb, offset);
1484
1485     str = rev_res_code_type(oct);
1486
1487     proto_tree_add_none_format(tree, hf_ansi_683_none,
1488         tvb, offset, 1,
1489         "Data commit result code, %s (%d)",
1490         str,
1491         oct);
1492
1493     offset++;
1494 }
1495
1496 static void
1497 msg_protocap_rsp(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1498 {
1499     guint8      oct, num_feat, add_len;
1500     gchar       *str = NULL;
1501     guint32     i, saved_offset;
1502     guint32     value;
1503     proto_tree  *subtree;
1504     proto_item  *item;
1505
1506     SHORT_DATA_CHECK(len, 5);
1507
1508     saved_offset = offset;
1509
1510     value = tvb_get_ntohs(tvb, offset);
1511
1512     proto_tree_add_none_format(tree, hf_ansi_683_none,
1513         tvb, offset, 2,
1514         "Mobile station firmware revision number (%d)",
1515         value);
1516
1517     offset += 2;
1518
1519     oct = tvb_get_guint8(tvb, offset);
1520
1521     proto_tree_add_none_format(tree, hf_ansi_683_none,
1522         tvb, offset, 1,
1523         "Mobile station manufacturer\92s model number (%d)",
1524         oct);
1525
1526     offset++;
1527
1528     num_feat = tvb_get_guint8(tvb, offset);
1529
1530     proto_tree_add_none_format(tree, hf_ansi_683_none,
1531         tvb, offset, 1,
1532         "Number of features (%d)",
1533         num_feat);
1534
1535     offset++;
1536
1537     if ((guint32)(num_feat * 2) > (len - (offset - saved_offset)))
1538     {
1539         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
1540             offset, len - (offset - saved_offset), "Short Data (?)");
1541         return;
1542     }
1543
1544     for (i=0; i < num_feat; i++)
1545     {
1546         oct = tvb_get_guint8(tvb, offset);
1547
1548         str = rev_feat_id_type(oct);
1549
1550         item =
1551             proto_tree_add_none_format(tree, hf_ansi_683_none,
1552                 tvb, offset, 1,
1553                 "Feature ID, %s (%d)",
1554                 str,
1555                 oct);
1556
1557         subtree = proto_item_add_subtree(item, ett_rev_feat);
1558         offset++;
1559
1560         oct = tvb_get_guint8(tvb, offset);
1561
1562         proto_tree_add_none_format(subtree, hf_ansi_683_none,
1563             tvb, offset, 1,
1564             "Feature protocol version (%d)",
1565             oct);
1566
1567         offset++;
1568     }
1569
1570     add_len = tvb_get_guint8(tvb, offset);
1571
1572     proto_tree_add_uint(tree, hf_ansi_683_length,
1573         tvb, offset, 1, add_len);
1574     offset++;
1575
1576     if (add_len > (len - (offset - saved_offset)))
1577     {
1578         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
1579             offset, len - (offset - saved_offset), "Short Data (?)");
1580         return;
1581     }
1582
1583     if (add_len > 0)
1584     {
1585         oct = tvb_get_guint8(tvb, offset);
1586
1587         item =
1588             proto_tree_add_none_format(tree, hf_ansi_683_none,
1589                 tvb, offset, 1,
1590                 "Band/Mode Capability Information");
1591
1592         subtree = proto_item_add_subtree(item, ett_band_cap);
1593
1594         other_decode_bitfield_value(bigbuf, oct, 0x80, 8);
1595         proto_tree_add_none_format(subtree, hf_ansi_683_none,
1596             tvb, offset, 1,
1597             "%s :  Band Class 0 Analog",
1598             bigbuf);
1599
1600         other_decode_bitfield_value(bigbuf, oct, 0x40, 8);
1601         proto_tree_add_none_format(subtree, hf_ansi_683_none,
1602             tvb, offset, 1,
1603             "%s :  Band Class 0 CDMA",
1604             bigbuf);
1605
1606         other_decode_bitfield_value(bigbuf, oct, 0x20, 8);
1607         proto_tree_add_none_format(subtree, hf_ansi_683_none,
1608             tvb, offset, 1,
1609             "%s :  Band Class 1 CDMA",
1610             bigbuf);
1611
1612         other_decode_bitfield_value(bigbuf, oct, 0x1f, 8);
1613         proto_tree_add_none_format(subtree, hf_ansi_683_none,
1614             tvb, offset, 1,
1615             "%s :  Reserved",
1616             bigbuf);
1617
1618         offset++;
1619
1620         if (add_len > 1)
1621         {
1622             proto_tree_add_none_format(tree, hf_ansi_683_none,
1623                 tvb, offset, add_len - 1,
1624                 "More Additional Fields");
1625             offset += (add_len - 1);
1626         }
1627     }
1628
1629     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
1630 }
1631
1632 static void
1633 msg_sspr_config_rsp(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1634 {
1635     guint8      oct, block_len;
1636     gchar       *str = NULL;
1637     guint32     saved_offset;
1638
1639     SHORT_DATA_CHECK(len, 3);
1640
1641     saved_offset = offset;
1642
1643     oct = tvb_get_guint8(tvb, offset);
1644
1645     str = rev_sspr_param_block_type(oct);
1646
1647     proto_tree_add_none_format(tree, hf_ansi_683_none,
1648         tvb, offset, 1,
1649         "%s (%d)",
1650         str,
1651         oct);
1652
1653     offset++;
1654
1655     oct = tvb_get_guint8(tvb, offset);
1656
1657     str = rev_res_code_type(oct);
1658
1659     proto_tree_add_none_format(tree, hf_ansi_683_none,
1660         tvb, offset, 1,
1661         "SSPR Configuration result code, %s (%d)",
1662         str,
1663         oct);
1664
1665     offset++;
1666
1667     block_len = tvb_get_guint8(tvb, offset);
1668
1669     proto_tree_add_uint(tree, hf_ansi_683_length,
1670         tvb, offset, 1, block_len);
1671     offset++;
1672
1673     if (block_len > (len - (offset - saved_offset)))
1674     {
1675         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
1676             offset, len - (offset - saved_offset), "Short Data (?)");
1677         return;
1678     }
1679
1680     if (block_len > 0)
1681     {
1682         proto_tree_add_none_format(tree, hf_ansi_683_none,
1683             tvb, offset, block_len, "Block Data");
1684         offset += block_len;
1685     }
1686
1687     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
1688 }
1689
1690 static void
1691 msg_sspr_download_rsp(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1692 {
1693     guint8      oct;
1694     gchar       *str = NULL;
1695     guint32     saved_offset;
1696     guint32     value;
1697
1698     EXACT_DATA_CHECK(len, 5);
1699
1700     saved_offset = offset;
1701
1702     oct = tvb_get_guint8(tvb, offset);
1703
1704     str = for_sspr_param_block_type(oct);
1705
1706     proto_tree_add_none_format(tree, hf_ansi_683_none,
1707         tvb, offset, 1,
1708         "%s (%d)",
1709         str,
1710         oct);
1711
1712     offset++;
1713
1714     oct = tvb_get_guint8(tvb, offset);
1715
1716     str = rev_res_code_type(oct);
1717
1718     proto_tree_add_none_format(tree, hf_ansi_683_none,
1719         tvb, offset, 1,
1720         "SSPR Download result code, %s (%d)",
1721         str,
1722         oct);
1723
1724     offset++;
1725
1726     value = tvb_get_ntohs(tvb, offset);
1727
1728     proto_tree_add_none_format(tree, hf_ansi_683_none,
1729         tvb, offset, 2,
1730         "Segment offset (%d)",
1731         value);
1732     offset += 2;
1733
1734     oct = tvb_get_guint8(tvb, offset);
1735
1736     proto_tree_add_none_format(tree, hf_ansi_683_none,
1737         tvb, offset, 1,
1738         "Maximum segment size (%d)",
1739         oct);
1740     offset++;
1741 }
1742
1743 static void
1744 msg_validate_rsp(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1745 {
1746     guint8      oct, block_id, num_blocks;
1747     gchar       *str = NULL;
1748     guint32     i, saved_offset;
1749     proto_tree  *subtree;
1750     proto_item  *item;
1751
1752     SHORT_DATA_CHECK(len, 1);
1753
1754     saved_offset = offset;
1755
1756     num_blocks = tvb_get_guint8(tvb, offset);
1757
1758     proto_tree_add_none_format(tree, hf_ansi_683_none,
1759         tvb, offset, 1,
1760         "Number of parameter blocks (%d)",
1761         num_blocks);
1762
1763     offset++;
1764
1765     if ((guint32)(num_blocks * 2) > (len - (offset - saved_offset)))
1766     {
1767         proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
1768             offset, len - (offset - saved_offset), "Short Data (?)");
1769         return;
1770     }
1771
1772     for (i=0; i < num_blocks; i++)
1773     {
1774         block_id = tvb_get_guint8(tvb, offset);
1775
1776         str = for_val_param_block_type(block_id);
1777
1778         item =
1779             proto_tree_add_none_format(tree, hf_ansi_683_none,
1780                 tvb, offset, 1,
1781                 "%s (%d)",
1782                 str,
1783                 block_id);
1784
1785         subtree = proto_item_add_subtree(item, ett_for_val_block);
1786         offset++;
1787
1788         oct = tvb_get_guint8(tvb, offset);
1789
1790         str = rev_res_code_type(oct);
1791
1792         proto_tree_add_none_format(subtree, hf_ansi_683_none,
1793             tvb, offset, 1,
1794             "%s (%d)",
1795             str,
1796             oct);
1797
1798         offset++;
1799     }
1800
1801     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
1802 }
1803
1804 static void
1805 msg_otapa_rsp(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset)
1806 {
1807     guint8      oct;
1808     gchar       *str = NULL;
1809     guint32     saved_offset;
1810
1811     SHORT_DATA_CHECK(len, 2);
1812
1813     saved_offset = offset;
1814
1815     oct = tvb_get_guint8(tvb, offset);
1816
1817     str = rev_res_code_type(oct);
1818
1819     proto_tree_add_none_format(tree, hf_ansi_683_none,
1820         tvb, offset, 1,
1821         "%s (%d)",
1822         str,
1823         oct);
1824
1825     offset++;
1826
1827     oct = tvb_get_guint8(tvb, offset);
1828
1829     other_decode_bitfield_value(bigbuf, oct, 0xfe, 8);
1830     proto_tree_add_none_format(tree, hf_ansi_683_none,
1831         tvb, offset, 1,
1832         "%s :  Reserved",
1833         bigbuf);
1834
1835     other_decode_bitfield_value(bigbuf, oct, 0x01, 8);
1836     proto_tree_add_none_format(tree, hf_ansi_683_none,
1837         tvb, offset, 1,
1838         "%s :  NAM_LOCK indicator",
1839         bigbuf);
1840
1841     offset++;
1842
1843     if (oct & 0x01)
1844     {
1845         if (4 > (len - (offset - saved_offset)))
1846         {
1847             proto_tree_add_none_format(tree, hf_ansi_683_none, tvb,
1848                 offset, len - (offset - saved_offset), "Short Data (?)");
1849             return;
1850         }
1851
1852         proto_tree_add_none_format(tree, hf_ansi_683_none,
1853             tvb, offset, 4,
1854             "SPASM random challenge");
1855         offset += 4;
1856     }
1857
1858     EXTRANEOUS_DATA_CHECK(len, offset - saved_offset);
1859 }
1860
1861 static const value_string for_msg_type_strings[] = {
1862     { 0,        "Configuration Request" },
1863     { 1,        "Download Request" },
1864     { 2,        "MS Key Request" },
1865     { 3,        "Key Generation Request" },
1866     { 4,        "Re-Authenticate Request" },
1867     { 5,        "Commit Request" },
1868     { 6,        "Protocol Capability Request" },
1869     { 7,        "SSPR Configuration Request" },
1870     { 8,        "SSPR Download Request" },
1871     { 9,        "Validation Request" },
1872     { 10,       "OTAPA Request" },
1873     { 0, NULL },
1874 };
1875 #define NUM_FOR_MSGS (sizeof(for_msg_type_strings)/sizeof(value_string))
1876 static void (*ansi_683_for_msg_fcn[])(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset) = {
1877     msg_config_req,     /* Configuration Request */
1878     msg_download_req,   /* Download Request */
1879     msg_ms_key_req,     /* MS Key Request */
1880     msg_key_gen_req,    /* Key Generation Request */
1881     msg_reauth_req,     /* Re-Authenticate Request */
1882     NULL /* No data */, /* Commit Request */
1883     NULL /* No data */, /* Protocol Capability Request */
1884     msg_sspr_config_req,        /* SSPR Configuration Request */
1885     msg_sspr_download_req,      /* SSPR Download Request */
1886     msg_validate_req,   /* Validation Request */
1887     msg_otapa_req,      /* OTAPA Request */
1888     NULL,       /* NONE */
1889 };
1890
1891 static const value_string rev_msg_type_strings[] = {
1892     { 0,        "Configuration Response" },
1893     { 1,        "Download Response" },
1894     { 2,        "MS Key Response" },
1895     { 3,        "Key Generation Response" },
1896     { 4,        "Re-Authenticate Response" },
1897     { 5,        "Commit Response" },
1898     { 6,        "Protocol Capability Response" },
1899     { 7,        "SSPR Configuration Response" },
1900     { 8,        "SSPR Download Response" },
1901     { 9,        "Validation Response" },
1902     { 10,       "OTAPA Response" },
1903     { 0, NULL },
1904 };
1905 #define NUM_REV_MSGS (sizeof(rev_msg_type_strings)/sizeof(value_string))
1906 static void (*ansi_683_rev_msg_fcn[])(tvbuff_t *tvb, proto_tree *tree, guint len, guint32 offset) = {
1907     msg_config_rsp,     /* Configuration Response */
1908     msg_download_rsp,   /* Download Response */
1909     msg_ms_key_rsp,     /* MS Key Response */
1910     msg_key_gen_rsp,    /* Key Generation Response */
1911     msg_reauth_rsp,     /* Re-Authenticate Response */
1912     msg_commit_rsp,     /* Commit Response */
1913     msg_protocap_rsp,   /* Protocol Capability Response */
1914     msg_sspr_config_rsp,        /* SSPR Configuration Response */
1915     msg_sspr_download_rsp,      /* SSPR Download Response */
1916     msg_validate_rsp,   /* Validation Response */
1917     msg_otapa_rsp,      /* OTAPA Response */
1918     NULL,       /* NONE */
1919 };
1920
1921
1922 static void
1923 dissect_ansi_683_for_message(tvbuff_t *tvb, proto_tree *ansi_683_tree)
1924 {
1925     guint8      msg_type;
1926     gint        idx;
1927     gchar       *str = NULL;
1928
1929
1930     msg_type = tvb_get_guint8(tvb, 0);
1931
1932     str = my_match_strval(msg_type, for_msg_type_strings, &idx);
1933
1934     if (str == NULL)
1935     {
1936         return;
1937     }
1938
1939     /*
1940      * No Information column data
1941      */
1942
1943     proto_tree_add_uint(ansi_683_tree, hf_ansi_683_for_msg_type,
1944         tvb, 0, 1, msg_type);
1945
1946     if (ansi_683_for_msg_fcn[idx] != NULL)
1947     {
1948         (*ansi_683_for_msg_fcn[idx])(tvb, ansi_683_tree, tvb_length(tvb) - 1, 1);
1949     }
1950 }
1951
1952 static void
1953 dissect_ansi_683_rev_message(tvbuff_t *tvb, proto_tree *ansi_683_tree)
1954 {
1955     guint8      msg_type;
1956     gint        idx;
1957     gchar       *str = NULL;
1958
1959
1960     msg_type = tvb_get_guint8(tvb, 0);
1961
1962     str = my_match_strval(msg_type, rev_msg_type_strings, &idx);
1963
1964     if (str == NULL)
1965     {
1966         return;
1967     }
1968
1969     /*
1970      * No Information column data
1971      */
1972
1973     proto_tree_add_uint(ansi_683_tree, hf_ansi_683_rev_msg_type,
1974         tvb, 0, 1, msg_type);
1975
1976     (*ansi_683_rev_msg_fcn[idx])(tvb, ansi_683_tree, tvb_length(tvb) - 1, 1);
1977 }
1978
1979 static void
1980 dissect_ansi_683(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1981 {
1982     proto_item  *ansi_683_item;
1983     proto_tree  *ansi_683_tree = NULL;
1984
1985     g_pinfo = pinfo;
1986
1987     if (check_col(pinfo->cinfo, COL_PROTOCOL))
1988     {
1989         col_set_str(pinfo->cinfo, COL_PROTOCOL, ansi_proto_name_short);
1990     }
1991
1992     /* In the interest of speed, if "tree" is NULL, don't do any work not
1993      * necessary to generate protocol tree items.
1994      */
1995     if (tree)
1996     {
1997         g_tree = tree;
1998
1999         /*
2000          * create the ansi_683 protocol tree
2001          */
2002         ansi_683_item =
2003             proto_tree_add_protocol_format(tree, proto_ansi_683, tvb, 0, -1,
2004                 "%s %s Link",
2005                 ansi_proto_name,
2006                 (pinfo->match_port == ANSI_683_FORWARD) ? "Forward" : "Reverse");
2007
2008         ansi_683_tree =
2009             proto_item_add_subtree(ansi_683_item, ett_ansi_683);
2010
2011         if (pinfo->match_port == ANSI_683_FORWARD)
2012         {
2013             dissect_ansi_683_for_message(tvb, ansi_683_tree);
2014         }
2015         else
2016         {
2017             dissect_ansi_683_rev_message(tvb, ansi_683_tree);
2018         }
2019     }
2020 }
2021
2022
2023 /* Register the protocol with Ethereal */
2024 void
2025 proto_register_ansi_683(void)
2026 {
2027
2028     /* Setup list of header fields */
2029     static hf_register_info hf[] =
2030     {
2031         { &hf_ansi_683_for_msg_type,
2032           { "Forward Link Message Type",
2033             "ansi_683.for_msg_type",
2034             FT_UINT8, BASE_DEC, VALS(for_msg_type_strings), 0,
2035             "", HFILL }},
2036         { &hf_ansi_683_rev_msg_type,
2037           { "Reverse Link Message Type",
2038             "ansi_683.rev_msg_type",
2039             FT_UINT8, BASE_DEC, VALS(rev_msg_type_strings), 0,
2040             "", HFILL }},
2041         { &hf_ansi_683_length,
2042             { "Length",         "ansi_683.len",
2043             FT_UINT8, BASE_DEC, NULL, 0,
2044             "", HFILL }
2045         },
2046         { &hf_ansi_683_none,
2047             { "Sub tree",       "ansi_683.none",
2048             FT_NONE, 0, 0, 0,
2049             "", HFILL }
2050         },
2051     };
2052
2053     /* Setup protocol subtree array */
2054 #define NUM_INDIVIDUAL_PARAMS   10
2055     static gint *ett[NUM_INDIVIDUAL_PARAMS];
2056
2057     memset((void *) ett, 0, sizeof(ett));
2058
2059     ett[0] = &ett_ansi_683;
2060     ett[1] = &ett_for_nam_block;
2061     ett[2] = &ett_rev_nam_block;
2062     ett[3] = &ett_key_p;
2063     ett[4] = &ett_key_g;
2064     ett[5] = &ett_rev_feat;
2065     ett[6] = &ett_for_val_block;
2066     ett[7] = &ett_for_sspr_block;
2067     ett[8] = &ett_band_cap;
2068     ett[9] = &ett_rev_sspr_block;
2069
2070     /* Register the protocol name and description */
2071     proto_ansi_683 =
2072         proto_register_protocol(ansi_proto_name, "ANSI IS-683-A (OTA (Mobile))", "ansi_683");
2073
2074     /* Required function calls to register the header fields and subtrees used */
2075     proto_register_field_array(proto_ansi_683, hf, array_length(hf));
2076     proto_register_subtree_array(ett, array_length(ett));
2077 }
2078
2079
2080 void
2081 proto_reg_handoff_ansi_683(void)
2082 {
2083     dissector_handle_t  ansi_683_handle;
2084
2085     ansi_683_handle = create_dissector_handle(dissect_ansi_683, proto_ansi_683);
2086
2087     dissector_add("ansi_map.ota", ANSI_683_FORWARD, ansi_683_handle);
2088     dissector_add("ansi_map.ota", ANSI_683_REVERSE, ansi_683_handle);
2089     dissector_add("ansi_a.ota", ANSI_683_FORWARD, ansi_683_handle);
2090     dissector_add("ansi_a.ota", ANSI_683_REVERSE, ansi_683_handle);
2091
2092     data_handle = find_dissector("data");
2093 }