Move a pile of protocol-related headers from the top-level source
[metze/wireshark/wip.git] / epan / dissectors / packet-sna.c
1 /* packet-sna.c
2  * Routines for SNA
3  * Gilbert Ramirez <gram@alumni.rice.edu>
4  * Jochen Friedrich <jochen@scram.de>
5  *
6  * $Id$
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
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
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <glib.h>
32 #include <epan/packet.h>
33 #include <epan/llcsaps.h>
34 #include <epan/ppptypes.h>
35 #include <epan/sna-utils.h>
36 #include <epan/charsets.h>
37 #include <epan/prefs.h>
38 #include <epan/reassemble.h>
39
40 /*
41  * http://www.wanresources.com/snacell.html
42  * ftp://ftp.software.ibm.com/networking/pub/standards/aiw/formats/
43  *
44  */
45
46 static int proto_sna = -1;
47 static int proto_sna_xid = -1;
48 static int hf_sna_th = -1;
49 static int hf_sna_th_0 = -1;
50 static int hf_sna_th_fid = -1;
51 static int hf_sna_th_mpf = -1;
52 static int hf_sna_th_odai = -1;
53 static int hf_sna_th_efi = -1;
54 static int hf_sna_th_daf = -1;
55 static int hf_sna_th_oaf = -1;
56 static int hf_sna_th_snf = -1;
57 static int hf_sna_th_dcf = -1;
58 static int hf_sna_th_lsid = -1;
59 static int hf_sna_th_tg_sweep = -1;
60 static int hf_sna_th_er_vr_supp_ind = -1;
61 static int hf_sna_th_vr_pac_cnt_ind = -1;
62 static int hf_sna_th_ntwk_prty = -1;
63 static int hf_sna_th_tgsf = -1;
64 static int hf_sna_th_mft = -1;
65 static int hf_sna_th_piubf = -1;
66 static int hf_sna_th_iern = -1;
67 static int hf_sna_th_nlpoi = -1;
68 static int hf_sna_th_nlp_cp = -1;
69 static int hf_sna_th_ern = -1;
70 static int hf_sna_th_vrn = -1;
71 static int hf_sna_th_tpf = -1;
72 static int hf_sna_th_vr_cwi = -1;
73 static int hf_sna_th_tg_nonfifo_ind = -1;
74 static int hf_sna_th_vr_sqti = -1;
75 static int hf_sna_th_tg_snf = -1;
76 static int hf_sna_th_vrprq = -1;
77 static int hf_sna_th_vrprs = -1;
78 static int hf_sna_th_vr_cwri = -1;
79 static int hf_sna_th_vr_rwi = -1;
80 static int hf_sna_th_vr_snf_send = -1;
81 static int hf_sna_th_dsaf = -1;
82 static int hf_sna_th_osaf = -1;
83 static int hf_sna_th_snai = -1;
84 static int hf_sna_th_def = -1;
85 static int hf_sna_th_oef = -1;
86 static int hf_sna_th_sa = -1;
87 static int hf_sna_th_cmd_fmt = -1;
88 static int hf_sna_th_cmd_type = -1;
89 static int hf_sna_th_cmd_sn = -1;
90
91 static int hf_sna_nlp_nhdr = -1;
92 static int hf_sna_nlp_nhdr_0 = -1;
93 static int hf_sna_nlp_sm = -1;
94 static int hf_sna_nlp_tpf = -1;
95 static int hf_sna_nlp_nhdr_1 = -1;
96 static int hf_sna_nlp_ft = -1;
97 static int hf_sna_nlp_tspi = -1;
98 static int hf_sna_nlp_slowdn1 = -1;
99 static int hf_sna_nlp_slowdn2 = -1;
100 static int hf_sna_nlp_fra = -1;
101 static int hf_sna_nlp_anr = -1;
102 static int hf_sna_nlp_frh = -1;
103 static int hf_sna_nlp_thdr = -1;
104 static int hf_sna_nlp_tcid = -1;
105 static int hf_sna_nlp_thdr_8 = -1;
106 static int hf_sna_nlp_setupi = -1;
107 static int hf_sna_nlp_somi = -1;
108 static int hf_sna_nlp_eomi = -1;
109 static int hf_sna_nlp_sri = -1;
110 static int hf_sna_nlp_rasapi = -1;
111 static int hf_sna_nlp_retryi = -1;
112 static int hf_sna_nlp_thdr_9 = -1;
113 static int hf_sna_nlp_lmi = -1;
114 static int hf_sna_nlp_cqfi = -1;
115 static int hf_sna_nlp_osi = -1;
116 static int hf_sna_nlp_offset = -1;
117 static int hf_sna_nlp_dlf = -1;
118 static int hf_sna_nlp_bsn = -1;
119 static int hf_sna_nlp_opti_len = -1;
120 static int hf_sna_nlp_opti_type = -1;
121 static int hf_sna_nlp_opti_0d_version = -1;
122 static int hf_sna_nlp_opti_0d_4 = -1;
123 static int hf_sna_nlp_opti_0d_target = -1;
124 static int hf_sna_nlp_opti_0d_arb = -1;
125 static int hf_sna_nlp_opti_0d_reliable = -1;
126 static int hf_sna_nlp_opti_0d_dedicated = -1;
127 static int hf_sna_nlp_opti_0e_stat = -1;
128 static int hf_sna_nlp_opti_0e_gap = -1;
129 static int hf_sna_nlp_opti_0e_idle = -1;
130 static int hf_sna_nlp_opti_0e_nabsp = -1;
131 static int hf_sna_nlp_opti_0e_sync = -1;
132 static int hf_sna_nlp_opti_0e_echo = -1;
133 static int hf_sna_nlp_opti_0e_rseq = -1;
134 static int hf_sna_nlp_opti_0e_abspbeg = -1;
135 static int hf_sna_nlp_opti_0e_abspend = -1;
136 static int hf_sna_nlp_opti_0f_bits = -1;
137 static int hf_sna_nlp_opti_10_tcid = -1;
138 static int hf_sna_nlp_opti_12_sense = -1;
139 static int hf_sna_nlp_opti_14_si_len = -1;
140 static int hf_sna_nlp_opti_14_si_key = -1;
141 static int hf_sna_nlp_opti_14_si_2 = -1;
142 static int hf_sna_nlp_opti_14_si_refifo = -1;
143 static int hf_sna_nlp_opti_14_si_mobility = -1;
144 static int hf_sna_nlp_opti_14_si_dirsearch = -1;
145 static int hf_sna_nlp_opti_14_si_limitres = -1;
146 static int hf_sna_nlp_opti_14_si_ncescope = -1;
147 static int hf_sna_nlp_opti_14_si_mnpsrscv = -1;
148 static int hf_sna_nlp_opti_14_si_maxpsize = -1;
149 static int hf_sna_nlp_opti_14_si_switch = -1;
150 static int hf_sna_nlp_opti_14_si_alive = -1;
151 static int hf_sna_nlp_opti_14_rr_len = -1;
152 static int hf_sna_nlp_opti_14_rr_key = -1;
153 static int hf_sna_nlp_opti_14_rr_2 = -1;
154 static int hf_sna_nlp_opti_14_rr_bfe = -1;
155 static int hf_sna_nlp_opti_14_rr_num = -1;
156 static int hf_sna_nlp_opti_22_2 = -1;
157 static int hf_sna_nlp_opti_22_type = -1;
158 static int hf_sna_nlp_opti_22_raa = -1;
159 static int hf_sna_nlp_opti_22_parity = -1;
160 static int hf_sna_nlp_opti_22_arb = -1;
161 static int hf_sna_nlp_opti_22_3 = -1;
162 static int hf_sna_nlp_opti_22_ratereq = -1;
163 static int hf_sna_nlp_opti_22_raterep = -1;
164 static int hf_sna_nlp_opti_22_field1 = -1;
165 static int hf_sna_nlp_opti_22_field2 = -1;
166 static int hf_sna_nlp_opti_22_field3 = -1;
167 static int hf_sna_nlp_opti_22_field4 = -1;
168
169 static int hf_sna_rh = -1;
170 static int hf_sna_rh_0 = -1;
171 static int hf_sna_rh_1 = -1;
172 static int hf_sna_rh_2 = -1;
173 static int hf_sna_rh_rri = -1;
174 static int hf_sna_rh_ru_category = -1;
175 static int hf_sna_rh_fi = -1;
176 static int hf_sna_rh_sdi = -1;
177 static int hf_sna_rh_bci = -1;
178 static int hf_sna_rh_eci = -1;
179 static int hf_sna_rh_dr1 = -1;
180 static int hf_sna_rh_lcci = -1;
181 static int hf_sna_rh_dr2 = -1;
182 static int hf_sna_rh_eri = -1;
183 static int hf_sna_rh_rti = -1;
184 static int hf_sna_rh_rlwi = -1;
185 static int hf_sna_rh_qri = -1;
186 static int hf_sna_rh_pi = -1;
187 static int hf_sna_rh_bbi = -1;
188 static int hf_sna_rh_ebi = -1;
189 static int hf_sna_rh_cdi = -1;
190 static int hf_sna_rh_csi = -1;
191 static int hf_sna_rh_edi = -1;
192 static int hf_sna_rh_pdi = -1;
193 static int hf_sna_rh_cebi = -1;
194 /*static int hf_sna_ru = -1;*/
195
196 static int hf_sna_gds = -1;
197 static int hf_sna_gds_len = -1;
198 static int hf_sna_gds_type = -1;
199 static int hf_sna_gds_cont = -1;
200
201 static int hf_sna_xid = -1;
202 static int hf_sna_xid_0 = -1;
203 static int hf_sna_xid_id = -1;
204 static int hf_sna_xid_format = -1;
205 static int hf_sna_xid_type = -1;
206 static int hf_sna_xid_len = -1;
207 static int hf_sna_xid_idblock = -1;
208 static int hf_sna_xid_idnum = -1;
209 static int hf_sna_xid_3_8 = -1;
210 static int hf_sna_xid_3_init_self = -1;
211 static int hf_sna_xid_3_stand_bind = -1;
212 static int hf_sna_xid_3_gener_bind = -1;
213 static int hf_sna_xid_3_recve_bind = -1;
214 static int hf_sna_xid_3_actpu = -1;
215 static int hf_sna_xid_3_nwnode = -1;
216 static int hf_sna_xid_3_cp = -1;
217 static int hf_sna_xid_3_cpcp = -1;
218 static int hf_sna_xid_3_state = -1;
219 static int hf_sna_xid_3_nonact = -1;
220 static int hf_sna_xid_3_cpchange = -1;
221 static int hf_sna_xid_3_10 = -1;
222 static int hf_sna_xid_3_asend_bind = -1;
223 static int hf_sna_xid_3_arecv_bind = -1;
224 static int hf_sna_xid_3_quiesce = -1;
225 static int hf_sna_xid_3_pucap = -1;
226 static int hf_sna_xid_3_pbn = -1;
227 static int hf_sna_xid_3_pacing = -1;
228 static int hf_sna_xid_3_11 = -1;
229 static int hf_sna_xid_3_tgshare = -1;
230 static int hf_sna_xid_3_dedsvc = -1;
231 static int hf_sna_xid_3_12 = -1;
232 static int hf_sna_xid_3_negcsup = -1;
233 static int hf_sna_xid_3_negcomp = -1;
234 static int hf_sna_xid_3_15 = -1;
235 static int hf_sna_xid_3_partg = -1;
236 static int hf_sna_xid_3_dlur = -1;
237 static int hf_sna_xid_3_dlus = -1;
238 static int hf_sna_xid_3_exbn = -1;
239 static int hf_sna_xid_3_genodai = -1;
240 static int hf_sna_xid_3_branch = -1;
241 static int hf_sna_xid_3_brnn = -1;
242 static int hf_sna_xid_3_tg = -1;
243 static int hf_sna_xid_3_dlc = -1;
244 static int hf_sna_xid_3_dlen = -1;
245
246 static int hf_sna_control_len = -1;
247 static int hf_sna_control_key = -1;
248 static int hf_sna_control_hprkey = -1;
249 static int hf_sna_control_05_delay = -1;
250 static int hf_sna_control_05_type = -1;
251 static int hf_sna_control_05_ptp = -1;
252 static int hf_sna_control_0e_type = -1;
253 static int hf_sna_control_0e_value = -1;
254
255 static gint ett_sna = -1;
256 static gint ett_sna_th = -1;
257 static gint ett_sna_th_fid = -1;
258 static gint ett_sna_nlp_nhdr = -1;
259 static gint ett_sna_nlp_nhdr_0 = -1;
260 static gint ett_sna_nlp_nhdr_1 = -1;
261 static gint ett_sna_nlp_thdr = -1;
262 static gint ett_sna_nlp_thdr_8 = -1;
263 static gint ett_sna_nlp_thdr_9 = -1;
264 static gint ett_sna_nlp_opti_un = -1;
265 static gint ett_sna_nlp_opti_0d = -1;
266 static gint ett_sna_nlp_opti_0d_4 = -1;
267 static gint ett_sna_nlp_opti_0e = -1;
268 static gint ett_sna_nlp_opti_0e_stat = -1;
269 static gint ett_sna_nlp_opti_0e_absp = -1;
270 static gint ett_sna_nlp_opti_0f = -1;
271 static gint ett_sna_nlp_opti_10 = -1;
272 static gint ett_sna_nlp_opti_12 = -1;
273 static gint ett_sna_nlp_opti_14 = -1;
274 static gint ett_sna_nlp_opti_14_si = -1;
275 static gint ett_sna_nlp_opti_14_si_2 = -1;
276 static gint ett_sna_nlp_opti_14_rr = -1;
277 static gint ett_sna_nlp_opti_14_rr_2 = -1;
278 static gint ett_sna_nlp_opti_22 = -1;
279 static gint ett_sna_nlp_opti_22_2 = -1;
280 static gint ett_sna_nlp_opti_22_3 = -1;
281 static gint ett_sna_rh = -1;
282 static gint ett_sna_rh_0 = -1;
283 static gint ett_sna_rh_1 = -1;
284 static gint ett_sna_rh_2 = -1;
285 static gint ett_sna_gds = -1;
286 static gint ett_sna_xid_0 = -1;
287 static gint ett_sna_xid_id = -1;
288 static gint ett_sna_xid_3_8 = -1;
289 static gint ett_sna_xid_3_10 = -1;
290 static gint ett_sna_xid_3_11 = -1;
291 static gint ett_sna_xid_3_12 = -1;
292 static gint ett_sna_xid_3_15 = -1;
293 static gint ett_sna_control_un = -1;
294 static gint ett_sna_control_05 = -1;
295 static gint ett_sna_control_05hpr = -1;
296 static gint ett_sna_control_05hpr_type = -1;
297 static gint ett_sna_control_0e = -1;
298
299 static dissector_handle_t data_handle;
300
301 /* Defragment fragmented SNA BIUs*/
302 static gboolean sna_defragment = FALSE;
303 static GHashTable *sna_fragment_table = NULL;
304 static GHashTable *sna_reassembled_table = NULL;
305
306 /* Format Identifier */
307 static const value_string sna_th_fid_vals[] = {
308         { 0x0,  "SNA device <--> Non-SNA Device" },
309         { 0x1,  "Subarea Nodes, without ER or VR" },
310         { 0x2,  "Subarea Node <--> PU2" },
311         { 0x3,  "Subarea Node or SNA host <--> Subarea Node" },
312         { 0x4,  "Subarea Nodes, supporting ER and VR" },
313         { 0x5,  "HPR RTP endpoint nodes" },
314         { 0xa,  "HPR NLP Frame Routing" },
315         { 0xb,  "HPR NLP Frame Routing" },
316         { 0xc,  "HPR NLP Automatic Network Routing" },
317         { 0xd,  "HPR NLP Automatic Network Routing" },
318         { 0xf,  "Adjaced Subarea Nodes, supporting ER and VR" },
319         { 0x0,  NULL }
320 };
321
322 /* Mapping Field */
323 #define MPF_MIDDLE_SEGMENT  0
324 #define MPF_LAST_SEGMENT    1
325 #define MPF_FIRST_SEGMENT   2
326 #define MPF_WHOLE_BIU       3
327
328 static const value_string sna_th_mpf_vals[] = {
329         { MPF_MIDDLE_SEGMENT,   "Middle segment of a BIU" },
330         { MPF_LAST_SEGMENT,     "Last segment of a BIU" },
331         { MPF_FIRST_SEGMENT,    "First segment of a BIU" },
332         { MPF_WHOLE_BIU,        "Whole BIU" },
333         { 0,   NULL }
334 };
335
336 /* Expedited Flow Indicator */
337 static const value_string sna_th_efi_vals[] = {
338         { 0, "Normal Flow" },
339         { 1, "Expedited Flow" },
340         { 0x0,  NULL }
341 };
342
343 /* Request/Response Indicator */
344 static const value_string sna_rh_rri_vals[] = {
345         { 0, "Request" },
346         { 1, "Response" },
347         { 0x0,  NULL }
348 };
349
350 /* Request/Response Unit Category */
351 static const value_string sna_rh_ru_category_vals[] = {
352         { 0, "Function Management Data (FMD)" },
353         { 1, "Network Control (NC)" },
354         { 2, "Data Flow Control (DFC)" },
355         { 3, "Session Control (SC)" },
356         { 0x0,  NULL }
357 };
358
359 /* Format Indicator */
360 static const true_false_string sna_rh_fi_truth =
361         { "FM Header", "No FM Header" };
362
363 /* Sense Data Included */
364 static const true_false_string sna_rh_sdi_truth =
365         { "Included", "Not Included" };
366
367 /* Begin Chain Indicator */
368 static const true_false_string sna_rh_bci_truth =
369         { "First in Chain", "Not First in Chain" };
370
371 /* End Chain Indicator */
372 static const true_false_string sna_rh_eci_truth =
373         { "Last in Chain", "Not Last in Chain" };
374
375 /* Lengith-Checked Compression Indicator */
376 static const true_false_string sna_rh_lcci_truth =
377         { "Compressed", "Not Compressed" };
378
379 /* Response Type Indicator */
380 static const true_false_string sna_rh_rti_truth =
381         { "Negative", "Positive" };
382
383 /* Queued Response Indicator */
384 static const true_false_string sna_rh_qri_truth =
385         { "Enqueue response in TC queues", "Response bypasses TC queues" };
386
387 /* Code Selection Indicator */
388 static const value_string sna_rh_csi_vals[] = {
389         { 0, "EBCDIC" },
390         { 1, "ASCII" },
391         { 0x0,  NULL }
392 };
393
394 /* TG Sweep */
395 static const value_string sna_th_tg_sweep_vals[] = {
396         { 0, "This PIU may overtake any PU ahead of it." },
397         { 1, "This PIU does not ovetake any PIU ahead of it." },
398         { 0x0,  NULL }
399 };
400
401 /* ER_VR_SUPP_IND */
402 static const value_string sna_th_er_vr_supp_ind_vals[] = {
403         { 0, "Each node supports ER and VR protocols" },
404         { 1, "Includes at least one node that does not support ER and VR"
405             " protocols"  },
406         { 0x0,  NULL }
407 };
408
409 /* VR_PAC_CNT_IND */
410 static const value_string sna_th_vr_pac_cnt_ind_vals[] = {
411         { 0, "Pacing count on the VR has not reached 0" },
412         { 1, "Pacing count on the VR has reached 0" },
413         { 0x0,  NULL }
414 };
415
416 /* NTWK_PRTY */
417 static const value_string sna_th_ntwk_prty_vals[] = {
418         { 0, "PIU flows at a lower priority" },
419         { 1, "PIU flows at network priority (highest transmission priority)" },
420         { 0x0,  NULL }
421 };
422
423 /* TGSF */
424 static const value_string sna_th_tgsf_vals[] = {
425         { 0, "Not segmented" },
426         { 1, "Last segment" },
427         { 2, "First segment" },
428         { 3, "Middle segment" },
429         { 0x0,  NULL }
430 };
431
432 /* PIUBF */
433 static const value_string sna_th_piubf_vals[] = {
434         { 0, "Single PIU frame" },
435         { 1, "Last PIU of a multiple PIU frame" },
436         { 2, "First PIU of a multiple PIU frame" },
437         { 3, "Middle PIU of a multiple PIU frame" },
438         { 0x0,  NULL }
439 };
440
441 /* NLPOI */
442 static const value_string sna_th_nlpoi_vals[] = {
443         { 0, "NLP starts within this FID4 TH" },
444         { 1, "NLP byte 0 starts after RH byte 0 following NLP C/P pad" },
445         { 0x0,  NULL }
446 };
447
448 /* TPF */
449 static const value_string sna_th_tpf_vals[] = {
450         { 0, "Low Priority" },
451         { 1, "Medium Priority" },
452         { 2, "High Priority" },
453         { 3, "Network Priority" },
454         { 0x0,  NULL }
455 };
456
457 /* VR_CWI */
458 static const value_string sna_th_vr_cwi_vals[] = {
459         { 0, "Increment window size" },
460         { 1, "Decrement window size" },
461         { 0x0,  NULL }
462 };
463
464 /* TG_NONFIFO_IND */
465 static const true_false_string sna_th_tg_nonfifo_ind_truth =
466         { "TG FIFO is not required", "TG FIFO is required" };
467
468 /* VR_SQTI */
469 static const value_string sna_th_vr_sqti_vals[] = {
470         { 0, "Non-sequenced, Non-supervisory" },
471         { 1, "Non-sequenced, Supervisory" },
472         { 2, "Singly-sequenced" },
473         { 0x0,  NULL }
474 };
475
476 /* VRPRQ */
477 static const true_false_string sna_th_vrprq_truth = {
478         "VR pacing request is sent asking for a VR pacing response",
479         "No VR pacing response is requested",
480 };
481
482 /* VRPRS */
483 static const true_false_string sna_th_vrprs_truth = {
484         "VR pacing response is sent in response to a VRPRQ bit set",
485         "No pacing response sent",
486 };
487
488 /* VR_CWRI */
489 static const value_string sna_th_vr_cwri_vals[] = {
490         { 0, "Increment window size by 1" },
491         { 1, "Decrement window size by 1" },
492         { 0x0,  NULL }
493 };
494
495 /* VR_RWI */
496 static const true_false_string sna_th_vr_rwi_truth = {
497         "Reset window size to the minimum specified in NC_ACTVR",
498         "Do not reset window size",
499 };
500
501 /* Switching Mode */
502 static const value_string sna_nlp_sm_vals[] = {
503         { 5, "Function routing" },
504         { 6, "Automatic network routing" },
505         { 0x0,  NULL }
506 };
507
508 static const true_false_string sna_nlp_tspi_truth =
509         { "Time sensitive", "Not time sensitive" };
510
511 static const true_false_string sna_nlp_slowdn1_truth =
512         { "Minor congestion", "No minor congestion" };
513
514 static const true_false_string sna_nlp_slowdn2_truth =
515         { "Major congestion", "No major congestion" };
516
517 /* Function Type */
518 static const value_string sna_nlp_ft_vals[] = {
519         { 0x10, "LDLC" },
520         { 0x0,  NULL }
521 };
522
523 static const value_string sna_nlp_frh_vals[] = {
524         { 0x03, "XID complete request" },
525         { 0x04, "XID complete response" },
526         { 0x0,  NULL }
527 };
528
529 static const true_false_string sna_nlp_setupi_truth =
530         { "Connection setup segment present", "Connection setup segment not"
531             " present" };
532
533 static const true_false_string sna_nlp_somi_truth =
534         { "Start of message", "Not start of message" };
535
536 static const true_false_string sna_nlp_eomi_truth =
537         { "End of message", "Not end of message" };
538
539 static const true_false_string sna_nlp_sri_truth =
540         { "Status requested", "No status requested" };
541
542 static const true_false_string sna_nlp_rasapi_truth =
543         { "Reply as soon as possible", "No need to reply as soon as possible" };
544
545 static const true_false_string sna_nlp_retryi_truth =
546         { "Undefined", "Sender will retransmit" };
547
548 static const true_false_string sna_nlp_lmi_truth =
549         { "Last message", "Not last message" };
550
551 static const true_false_string sna_nlp_cqfi_truth =
552         { "CQFI included", "CQFI not included" };
553
554 static const true_false_string sna_nlp_osi_truth =
555         { "Optional segments present", "No optional segments present" };
556
557 static const value_string sna_xid_3_state_vals[] = {
558         { 0x00, "Exchange state indicators not supported" },
559         { 0x01, "Negotiation-proceeding exchange" },
560         { 0x02, "Prenegotiation exchange" },
561         { 0x03, "Nonactivation exchange" },
562         { 0x0, NULL }
563 };
564
565 static const value_string sna_xid_3_branch_vals[] = {
566         { 0x00, "Sender does not support branch extender" },
567         { 0x01, "TG is branch uplink" },
568         { 0x02, "TG is branch downlink" },
569         { 0x03, "TG is neither uplink nor downlink" },
570         { 0x0, NULL }
571 };
572
573 static const value_string sna_xid_type_vals[] = {
574         { 0x01, "T1 node" },
575         { 0x02, "T2.0 or T2.1 node" },
576         { 0x03, "Reserved" },
577         { 0x04, "T4 or T5 node" },
578         { 0x0, NULL }
579 };
580
581 static const value_string sna_nlp_opti_vals[] = {
582         { 0x0d, "Connection Setup Segment" },
583         { 0x0e, "Status Segment" },
584         { 0x0f, "Client Out Of Band Bits Segment" },
585         { 0x10, "Connection Identifier Exchange Segment" },
586         { 0x12, "Connection Fault Segment" },
587         { 0x14, "Switching Information Segment" },
588         { 0x22, "Adaptive Rate-Based Segment" },
589         { 0x0, NULL }
590 };
591
592 static const value_string sna_nlp_opti_0d_version_vals[] = {
593         { 0x0101, "Version 1.1" },
594         { 0x0, NULL }
595 };
596
597 static const value_string sna_nlp_opti_0f_bits_vals[] = {
598         { 0x0001, "Request Deactivation" },
599         { 0x8000, "Reply - OK" },
600         { 0x8004, "Reply - Reject" },
601         { 0x0, NULL }
602 };
603
604 static const value_string sna_nlp_opti_22_type_vals[] = {
605         { 0x00, "Setup" },
606         { 0x01, "Rate Reply" },
607         { 0x02, "Rate Request" },
608         { 0x03, "Rate Request/Rate Reply" },
609         { 0x0, NULL }
610 };
611
612 static const value_string sna_nlp_opti_22_raa_vals[] = {
613         { 0x00, "Normal" },
614         { 0x01, "Restraint" },
615         { 0x02, "Slowdown1" },
616         { 0x03, "Slowdown2" },
617         { 0x04, "Critical" },
618         { 0x0, NULL }
619 };
620
621 static const value_string sna_nlp_opti_22_arb_vals[] = {
622         { 0x00, "Base Mode ARB" },
623         { 0x01, "Responsive Mode ARB" },
624         { 0x0, NULL }
625 };
626
627 /* GDS Variable Type */
628 static const value_string sna_gds_var_vals[] = {
629         { 0x1210, "Change Number Of Sessions" },
630         { 0x1211, "Exchange Log Name" },
631         { 0x1212, "Control Point Management Services Unit" },
632         { 0x1213, "Compare States" },
633         { 0x1214, "LU Names Position" },
634         { 0x1215, "LU Name" },
635         { 0x1217, "Do Know" },
636         { 0x1218, "Partner Restart" },
637         { 0x1219, "Don't Know" },
638         { 0x1220, "Sign-Off" },
639         { 0x1221, "Sign-On" },
640         { 0x1222, "SNMP-over-SNA" },
641         { 0x1223, "Node Address Service" },
642         { 0x12C1, "CP Capabilities" },
643         { 0x12C2, "Topology Database Update" },
644         { 0x12C3, "Register Resource" },
645         { 0x12C4, "Locate" },
646         { 0x12C5, "Cross-Domain Initiate" },
647         { 0x12C9, "Delete Resource" },
648         { 0x12CA, "Find Resource" },
649         { 0x12CB, "Found Resource" },
650         { 0x12CC, "Notify" },
651         { 0x12CD, "Initiate-Other Cross-Domain" },
652         { 0x12CE, "Route Setup" },
653         { 0x12E1, "Error Log" },
654         { 0x12F1, "Null Data" },
655         { 0x12F2, "User Control Date" },
656         { 0x12F3, "Map Name" },
657         { 0x12F4, "Error Data" },
658         { 0x12F6, "Authentication Token Data" },
659         { 0x12F8, "Service Flow Authentication Token Data" },
660         { 0x12FF, "Application Data" },
661         { 0x1310, "MDS Message Unit" },
662         { 0x1311, "MDS Routing Information" },
663         { 0x1500, "FID2 Encapsulation" },
664         { 0x0,    NULL }
665 };
666
667 /* Control Vector Type */
668 static const value_string sna_control_vals[] = {
669         { 0x00,   "SSCP-LU Session Capabilities Control Vector" },
670         { 0x01,   "Date-Time Control Vector" },
671         { 0x02,   "Subarea Routing Control Vector" },
672         { 0x03,   "SDLC Secondary Station Control Vector" },
673         { 0x04,   "LU Control Vector" },
674         { 0x05,   "Channel Control Vector" },
675         { 0x06,   "Cross-Domain Resource Manager (CDRM) Control Vector" },
676         { 0x07,   "PU FMD-RU-Usage Control Vector" },
677         { 0x08,   "Intensive Mode Control Vector" },
678         { 0x09,   "Activation Request / Response Sequence Identifier Control"
679             " Vector" },
680         { 0x0a,   "User Request Correlator Control Vector" },
681         { 0x0b,   "SSCP-PU Session Capabilities Control Vector" },
682         { 0x0c,   "LU-LU Session Capabilities Control Vector" },
683         { 0x0d,   "Mode / Class-of-Service / Virtual-Route-Identifier List"
684             " Control Vector" },
685         { 0x0e,   "Network Name Control Vector" },
686         { 0x0f,   "Link Capabilities and Status Control Vector" },
687         { 0x10,   "Product Set ID Control Vector" },
688         { 0x11,   "Load Module Correlation Control Vector" },
689         { 0x12,   "Network Identifier Control Vector" },
690         { 0x13,   "Gateway Support Capabilities Control Vector" },
691         { 0x14,   "Session Initiation Control Vector" },
692         { 0x15,   "Network-Qualified Address Pair Control Vector" },
693         { 0x16,   "Names Substitution Control Vector" },
694         { 0x17,   "SSCP Identifier Control Vector" },
695         { 0x18,   "SSCP Name Control Vector" },
696         { 0x19,   "Resource Identifier Control Vector" },
697         { 0x1a,   "NAU Address Control Vector" },
698         { 0x1b,   "VRID List Control Vector" },
699         { 0x1c,   "Network-Qualified Name Pair Control Vector" },
700         { 0x1e,   "VR-ER Mapping Data Control Vector" },
701         { 0x1f,   "ER Configuration Control Vector" },
702         { 0x23,   "Local-Form Session Identifier Control Vector" },
703         { 0x24,   "IPL Load Module Request Control Vector" },
704         { 0x25,   "Security ID Control Control Vector" },
705         { 0x26,   "Network Connection Endpoint Identifier Control Vector" },
706         { 0x27,   "XRF Session Activation Control Vector" },
707         { 0x28,   "Related Session Identifier Control Vector" },
708         { 0x29,   "Session State Data Control Vector" },
709         { 0x2a,   "Session Information Control Vector" },
710         { 0x2b,   "Route Selection Control Vector" },
711         { 0x2c,   "COS/TPF Control Vector" },
712         { 0x2d,   "Mode Control Vector" },
713         { 0x2f,   "LU Definition Control Vector" },
714         { 0x30,   "Assign LU Characteristics Control Vector" },
715         { 0x31,   "BIND Image Control Vector" },
716         { 0x32,   "Short-Hold Mode Control Vector" },
717         { 0x33,   "ENCP Search Control Control Vector" },
718         { 0x34,   "LU Definition Override Control Vector" },
719         { 0x35,   "Extended Sense Data Control Vector" },
720         { 0x36,   "Directory Error Control Vector" },
721         { 0x37,   "Directory Entry Correlator Control Vector" },
722         { 0x38,   "Short-Hold Mode Emulation Control Vector" },
723         { 0x39,   "Network Connection Endpoint (NCE) Instance Identifier"
724             " Control Vector" },
725         { 0x3a,   "Route Status Data Control Vector" },
726         { 0x3b,   "VR Congestion Data Control Vector" },
727         { 0x3c,   "Associated Resource Entry Control Vector" },
728         { 0x3d,   "Directory Entry Control Vector" },
729         { 0x3e,   "Directory Entry Characteristic Control Vector" },
730         { 0x3f,   "SSCP (SLU) Capabilities Control Vector" },
731         { 0x40,   "Real Associated Resource Control Vector" },
732         { 0x41,   "Station Parameters Control Vector" },
733         { 0x42,   "Dynamic Path Update Data Control Vector" },
734         { 0x43,   "Extended SDLC Station Control Vector" },
735         { 0x44,   "Node Descriptor Control Vector" },
736         { 0x45,   "Node Characteristics Control Vector" },
737         { 0x46,   "TG Descriptor Control Vector" },
738         { 0x47,   "TG Characteristics Control Vector" },
739         { 0x48,   "Topology Resource Descriptor Control Vector" },
740         { 0x49,   "Multinode Persistent Sessions (MNPS) LU Names Control"
741             " Vector" },
742         { 0x4a,   "Real Owning Control Point Control Vector" },
743         { 0x4b,   "RTP Transport Connection Identifier Control Vector" },
744         { 0x51,   "DLUR/S Capabilities Control Vector" },
745         { 0x52,   "Primary Send Pacing Window Size Control Vector" },
746         { 0x56,   "Call Security Verification Control Vector" },
747         { 0x57,   "DLC Connection Data Control Vector" },
748         { 0x59,   "Installation-Defined CDINIT Data Control Vector" },
749         { 0x5a,   "Session Services Extension Support Control Vector" },
750         { 0x5b,   "Interchange Node Support Control Vector" },
751         { 0x5c,   "APPN Message Transport Control Vector" },
752         { 0x5d,   "Subarea Message Transport Control Vector" },
753         { 0x5e,   "Related Request Control Vector" },
754         { 0x5f,   "Extended Fully Qualified PCID Control Vector" },
755         { 0x60,   "Fully Qualified PCID Control Vector" },
756         { 0x61,   "HPR Capabilities Control Vector" },
757         { 0x62,   "Session Address Control Vector" },
758         { 0x63,   "Cryptographic Key Distribution Control Vector" },
759         { 0x64,   "TCP/IP Information Control Vector" },
760         { 0x65,   "Device Characteristics Control Vector" },
761         { 0x66,   "Length-Checked Compression Control Vector" },
762         { 0x67,   "Automatic Network Routing (ANR) Path Control Vector" },
763         { 0x68,   "XRF/Session Cryptography Control Vector" },
764         { 0x69,   "Switched Parameters Control Vector" },
765         { 0x6a,   "ER Congestion Data Control Vector" },
766         { 0x71,   "Triple DES Cryptography Key Continuation Control Vector" },
767         { 0xfe,   "Control Vector Keys Not Recognized" },
768         { 0x0,    NULL }
769 };
770
771 static const value_string sna_control_hpr_vals[] = {
772         { 0x00,   "Node Identifier Control Vector" },
773         { 0x03,   "Network ID Control Vector" },
774         { 0x05,   "Network Address Control Vector" },
775         { 0x0,    NULL }
776 };
777
778 static const value_string sna_control_0e_type_vals[] = {
779         { 0xF1,   "PU Name" },
780         { 0xF3,   "LU Name" },
781         { 0xF4,   "CP Name" },
782         { 0xF5,   "SSCP Name" },
783         { 0xF6,   "NNCP Name" },
784         { 0xF7,   "Link Station Name" },
785         { 0xF8,   "CP Name of CP(PLU)" },
786         { 0xF9,   "CP Name of CP(SLU)" },
787         { 0xFA,   "Generic Name" },
788         { 0x0,    NULL }
789 };
790
791 /* Values to direct the top-most dissector what to dissect
792  * after the TH. */
793 enum next_dissection_enum {
794     stop_here,
795     rh_only,
796     everything
797 };
798
799 enum parse {
800     LT,
801     KL
802 };
803
804 typedef enum next_dissection_enum next_dissection_t;
805
806 static void dissect_xid (tvbuff_t*, packet_info*, proto_tree*, proto_tree*);
807 static void dissect_fid (tvbuff_t*, packet_info*, proto_tree*, proto_tree*);
808 static void dissect_nlp (tvbuff_t*, packet_info*, proto_tree*, proto_tree*);
809 static void dissect_gds (tvbuff_t*, packet_info*, proto_tree*, proto_tree*);
810 static void dissect_rh (tvbuff_t*, int, proto_tree*);
811 static void dissect_control(tvbuff_t*, int, int, proto_tree*, int, enum parse);
812
813 /* --------------------------------------------------------------------
814  * Chapter 2 High-Performance Routing (HPR) Headers
815  * --------------------------------------------------------------------
816  */
817
818 static void
819 dissect_optional_0d(tvbuff_t *tvb, proto_tree *tree)
820 {
821         int             bits, offset, len, pad;
822         proto_tree      *sub_tree;
823         proto_item      *sub_ti = NULL;
824
825         if (!tree)
826                 return;
827
828         proto_tree_add_item(tree, hf_sna_nlp_opti_0d_version, tvb, 2, 2, FALSE);
829         bits = tvb_get_guint8(tvb, 4);
830
831         sub_ti = proto_tree_add_uint(tree, hf_sna_nlp_opti_0d_4,
832             tvb, 4, 1, bits);
833         sub_tree = proto_item_add_subtree(sub_ti, 
834             ett_sna_nlp_opti_0d_4);
835
836         proto_tree_add_boolean(sub_tree, hf_sna_nlp_opti_0d_target,
837             tvb, 4, 1, bits);
838         proto_tree_add_boolean(sub_tree, hf_sna_nlp_opti_0d_arb,
839             tvb, 4, 1, bits);
840         proto_tree_add_boolean(sub_tree, hf_sna_nlp_opti_0d_reliable,
841             tvb, 4, 1, bits);
842         proto_tree_add_boolean(sub_tree, hf_sna_nlp_opti_0d_dedicated,
843             tvb, 4, 1, bits);
844
845         proto_tree_add_text(tree, tvb, 5, 3, "Reserved");
846
847         offset = 8;
848
849         while (tvb_offset_exists(tvb, offset)) {
850                 len = tvb_get_guint8(tvb, offset+0);
851                 if (len) {
852                         dissect_control(tvb, offset, len, tree, 1, LT);
853                         pad = (len+3) & 0xfffc;
854                         if (pad > len)
855                                 proto_tree_add_text(tree, tvb, offset+len,
856                                     pad-len, "Padding");
857                         offset += pad;
858                 } else {
859                         /* Avoid endless loop */
860                         return;
861                 }
862         }
863 }
864
865 static void
866 dissect_optional_0e(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
867 {
868         int             bits, offset;
869         proto_tree      *sub_tree;
870         proto_item      *sub_ti = NULL;
871
872         bits = tvb_get_guint8(tvb, 2);
873         offset = 20;
874
875         if (tree) {
876                 sub_ti = proto_tree_add_item(tree, hf_sna_nlp_opti_0e_stat,
877                     tvb, 2, 1, FALSE);
878                 sub_tree = proto_item_add_subtree(sub_ti, 
879                     ett_sna_nlp_opti_0e_stat);
880
881                 proto_tree_add_boolean(sub_tree, hf_sna_nlp_opti_0e_gap,
882                     tvb, 2, 1, bits);
883                 proto_tree_add_boolean(sub_tree, hf_sna_nlp_opti_0e_idle,
884                     tvb, 2, 1, bits);
885                 proto_tree_add_item(tree, hf_sna_nlp_opti_0e_nabsp,
886                     tvb, 3, 1, FALSE);
887                 proto_tree_add_item(tree, hf_sna_nlp_opti_0e_sync,
888                     tvb, 4, 2, FALSE);
889                 proto_tree_add_item(tree, hf_sna_nlp_opti_0e_echo,
890                     tvb, 6, 2, FALSE);
891                 proto_tree_add_item(tree, hf_sna_nlp_opti_0e_rseq,
892                     tvb, 8, 4, FALSE);
893                 proto_tree_add_text(tree, tvb, 12, 8, "Reserved");
894
895                 if (tvb_offset_exists(tvb, offset))
896                         call_dissector(data_handle,
897                             tvb_new_subset(tvb, 4, -1, -1), pinfo, tree);
898         }
899         if (bits & 0x40) {
900                 if (check_col(pinfo->cinfo, COL_INFO))
901                         col_add_str(pinfo->cinfo, COL_INFO,
902                             "HPR Idle Message");
903         } else {
904                 if (check_col(pinfo->cinfo, COL_INFO))
905                         col_add_str(pinfo->cinfo, COL_INFO,
906                             "HPR Status Message");
907         }
908 }
909
910 static void
911 dissect_optional_0f(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
912 {
913         if (!tree)
914                 return;
915
916         proto_tree_add_item(tree, hf_sna_nlp_opti_0f_bits, tvb, 2, 2, FALSE);
917         if (tvb_offset_exists(tvb, 4))
918                 call_dissector(data_handle,
919                     tvb_new_subset(tvb, 4, -1, -1), pinfo, tree);
920 }
921
922 static void
923 dissect_optional_10(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
924 {
925         if (!tree)
926                 return;
927
928         proto_tree_add_text(tree, tvb, 2, 2, "Reserved");
929         proto_tree_add_item(tree, hf_sna_nlp_opti_10_tcid, tvb, 4, 8, FALSE);
930         if (tvb_offset_exists(tvb, 12))
931                 call_dissector(data_handle,
932                     tvb_new_subset(tvb, 12, -1, -1), pinfo, tree);
933 }
934
935 static void
936 dissect_optional_12(tvbuff_t *tvb, proto_tree *tree)
937 {
938         if (!tree)
939                 return;
940
941         proto_tree_add_text(tree, tvb, 2, 2, "Reserved");
942         proto_tree_add_item(tree, hf_sna_nlp_opti_12_sense, tvb, 4, -1, FALSE);
943 }
944
945 static void
946 dissect_optional_14(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
947 {
948         proto_tree      *sub_tree, *bf_tree;
949         proto_item      *sub_item, *bf_item;
950         int             len, pad, type, bits, offset, num, sublen;
951
952         if (!tree)
953                 return;
954
955         proto_tree_add_text(tree, tvb, 2, 2, "Reserved");
956
957         offset = 4;
958
959         len = tvb_get_guint8(tvb, offset);
960         type = tvb_get_guint8(tvb, offset+1);
961
962         if ((type != 0x83) || (len <= 16)) {
963                 /* Invalid */
964                 call_dissector(data_handle,
965                     tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
966                 return;
967         }
968         sub_item = proto_tree_add_text(tree, tvb, offset, len,
969             "Switching Information Control Vector");
970         sub_tree = proto_item_add_subtree(sub_item, ett_sna_nlp_opti_14_si);
971
972         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_si_len,
973             tvb, offset, 1, len);
974         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_si_key,
975             tvb, offset+1, 1, type);
976         
977         bits = tvb_get_guint8(tvb, offset+2);
978         bf_item = proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_si_2,
979             tvb, offset+2, 1, bits);
980         bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_opti_14_si_2);
981
982         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_refifo,
983             tvb, offset+2, 1, bits);
984         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_mobility,
985             tvb, offset+2, 1, bits);
986         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_dirsearch,
987             tvb, offset+2, 1, bits);
988         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_limitres,
989             tvb, offset+2, 1, bits);
990         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_ncescope,
991             tvb, offset+2, 1, bits);
992         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_mnpsrscv,
993             tvb, offset+2, 1, bits);
994
995         proto_tree_add_text(sub_tree, tvb, offset+3, 1, "Reserved");
996         proto_tree_add_item(sub_tree, hf_sna_nlp_opti_14_si_maxpsize,
997             tvb, offset+4, 4, FALSE);
998         proto_tree_add_item(sub_tree, hf_sna_nlp_opti_14_si_switch,
999             tvb, offset+8, 4, FALSE);
1000         proto_tree_add_item(sub_tree, hf_sna_nlp_opti_14_si_alive,
1001             tvb, offset+12, 4, FALSE);
1002
1003         dissect_control(tvb, offset+16, len-16, sub_tree, 1, LT);
1004
1005         pad = (len+3) & 0xfffc;
1006         if (pad > len)
1007                 proto_tree_add_text(sub_tree, tvb, offset+len, pad-len,
1008                     "Padding");
1009         offset += pad;
1010
1011         len = tvb_get_guint8(tvb, offset);
1012         type = tvb_get_guint8(tvb, offset+1);
1013
1014         if ((type != 0x85) || ( len < 4))  {
1015                 /* Invalid */
1016                 call_dissector(data_handle,
1017                     tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
1018                 return;
1019         }
1020         sub_item = proto_tree_add_text(tree, tvb, offset, len,
1021             "Return Route TG Descriptor Control Vector");
1022         sub_tree = proto_item_add_subtree(sub_item, ett_sna_nlp_opti_14_rr);
1023
1024         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_rr_len,
1025             tvb, offset, 1, len);
1026         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_rr_key,
1027             tvb, offset+1, 1, type);
1028         
1029         bits = tvb_get_guint8(tvb, offset+2);
1030         bf_item = proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_rr_2,
1031             tvb, offset+2, 1, bits);
1032         bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_opti_14_rr_2);
1033
1034         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_rr_bfe,
1035             tvb, offset+2, 1, bits);
1036
1037         num = tvb_get_guint8(tvb, offset+3);
1038
1039         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_rr_num,
1040             tvb, offset+3, 1, num);
1041
1042         offset += 4;
1043
1044         while (num) {
1045                 sublen = tvb_get_guint8(tvb, offset);
1046                 if (sublen) {
1047                         dissect_control(tvb, offset, sublen, sub_tree, 1, LT);
1048                 } else {
1049                         /* Invalid */
1050                         call_dissector(data_handle,
1051                             tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
1052                         return;
1053                 }
1054                 /* No padding here */
1055                 offset += sublen;
1056                 num--;
1057         }
1058 }
1059
1060 static void
1061 dissect_optional_22(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1062 {
1063         proto_tree      *bf_tree;
1064         proto_item      *bf_item;
1065         int             bits, type;
1066
1067         if (!tree)
1068                 return;
1069
1070         bits = tvb_get_guint8(tvb, 2);
1071         type = (bits & 0xc0) >> 6;
1072
1073         bf_item = proto_tree_add_uint(tree, hf_sna_nlp_opti_22_2,
1074             tvb, 2, 1, bits);
1075         bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_opti_22_2);
1076
1077         proto_tree_add_uint(bf_tree, hf_sna_nlp_opti_22_type,
1078             tvb, 2, 1, bits);
1079         proto_tree_add_uint(bf_tree, hf_sna_nlp_opti_22_raa,
1080             tvb, 2, 1, bits);
1081         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_22_parity,
1082             tvb, 2, 1, bits);
1083         proto_tree_add_uint(bf_tree, hf_sna_nlp_opti_22_arb,
1084             tvb, 2, 1, bits);
1085
1086         bits = tvb_get_guint8(tvb, 3);
1087
1088         bf_item = proto_tree_add_uint(tree, hf_sna_nlp_opti_22_3,
1089             tvb, 3, 1, bits);
1090         bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_opti_22_3);
1091
1092         proto_tree_add_uint(bf_tree, hf_sna_nlp_opti_22_ratereq,
1093             tvb, 3, 1, bits);
1094         proto_tree_add_uint(bf_tree, hf_sna_nlp_opti_22_raterep,
1095             tvb, 3, 1, bits);
1096
1097         proto_tree_add_item(tree, hf_sna_nlp_opti_22_field1,
1098             tvb, 4, 4, FALSE);
1099         proto_tree_add_item(tree, hf_sna_nlp_opti_22_field2,
1100             tvb, 8, 4, FALSE);
1101
1102         if (type == 0) {
1103                 proto_tree_add_item(tree, hf_sna_nlp_opti_22_field3,
1104                     tvb, 12, 4, FALSE);
1105                 proto_tree_add_item(tree, hf_sna_nlp_opti_22_field4,
1106                     tvb, 16, 4, FALSE);
1107
1108                 if (tvb_offset_exists(tvb, 20))
1109                         call_dissector(data_handle,
1110                             tvb_new_subset(tvb, 20, -1, -1), pinfo, tree);
1111         } else {
1112                 if (tvb_offset_exists(tvb, 12))
1113                         call_dissector(data_handle,
1114                             tvb_new_subset(tvb, 12, -1, -1), pinfo, tree);
1115         }
1116 }
1117
1118 static void
1119 dissect_optional(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1120 {
1121         proto_tree      *sub_tree;
1122         proto_item      *sub_item;
1123         int             offset, type, len;
1124         gint            ett;
1125
1126         sub_tree = NULL;
1127
1128         offset = 0;
1129
1130         while (tvb_offset_exists(tvb, offset)) {
1131                 len = tvb_get_guint8(tvb, offset);
1132                 type = tvb_get_guint8(tvb, offset+1);
1133
1134                 /* Prevent loop for invalid crap in packet */
1135                 if (len == 0) {
1136                         if (tree)
1137                                 call_dissector(data_handle,
1138                                     tvb_new_subset(tvb, offset,
1139                                     -1, -1), pinfo, tree);
1140                         return;
1141                 }
1142                         
1143                 ett = ett_sna_nlp_opti_un;
1144                 if(type == 0x0d) ett = ett_sna_nlp_opti_0d;
1145                 if(type == 0x0e) ett = ett_sna_nlp_opti_0e;
1146                 if(type == 0x0f) ett = ett_sna_nlp_opti_0f;
1147                 if(type == 0x10) ett = ett_sna_nlp_opti_10;
1148                 if(type == 0x12) ett = ett_sna_nlp_opti_12;
1149                 if(type == 0x14) ett = ett_sna_nlp_opti_14;
1150                 if(type == 0x22) ett = ett_sna_nlp_opti_22;
1151                 if (tree) {
1152                         sub_item = proto_tree_add_text(tree, tvb,
1153                             offset, len << 2,
1154                             val_to_str(type, sna_nlp_opti_vals,
1155                             "Unknown Segment Type"));
1156                         sub_tree = proto_item_add_subtree(sub_item, ett);
1157                         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_len,
1158                             tvb, offset, 1, len);
1159                         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_type,
1160                             tvb, offset+1, 1, type);
1161                 }
1162                 switch(type) {
1163                         case 0x0d:
1164                                 dissect_optional_0d(tvb_new_subset(tvb, offset,
1165                                     len << 2, -1), sub_tree);
1166                                 break;
1167                         case 0x0e:
1168                                 dissect_optional_0e(tvb_new_subset(tvb, offset,
1169                                     len << 2, -1), pinfo, sub_tree);
1170                                 break;
1171                         case 0x0f:
1172                                 dissect_optional_0f(tvb_new_subset(tvb, offset,
1173                                     len << 2, -1), pinfo, sub_tree);
1174                                 break;
1175                         case 0x10:
1176                                 dissect_optional_10(tvb_new_subset(tvb, offset,
1177                                     len << 2, -1), pinfo, sub_tree);
1178                                 break;
1179                         case 0x12:
1180                                 dissect_optional_12(tvb_new_subset(tvb, offset,
1181                                     len << 2, -1), sub_tree);
1182                                 break;
1183                         case 0x14:
1184                                 dissect_optional_14(tvb_new_subset(tvb, offset,
1185                                     len << 2, -1), pinfo, sub_tree);
1186                                 break;
1187                         case 0x22:
1188                                 dissect_optional_22(tvb_new_subset(tvb, offset,
1189                                     len << 2, -1), pinfo, sub_tree);
1190                                 break;
1191                         default:
1192                                 call_dissector(data_handle,
1193                                     tvb_new_subset(tvb, offset,
1194                                     len << 2, -1), pinfo, sub_tree);
1195                 }
1196                 offset += (len << 2);
1197         }
1198 }
1199
1200 static void
1201 dissect_nlp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
1202     proto_tree *parent_tree)
1203 {
1204         proto_tree      *nlp_tree, *bf_tree;
1205         proto_item      *nlp_item, *bf_item, *h_item;
1206         guint8          nhdr_0, nhdr_1, nhdr_x, thdr_8, thdr_9, fid;
1207         guint32         thdr_len, thdr_dlf;
1208         guint16         subindex;
1209
1210         int index = 0, counter = 0;
1211
1212         nlp_tree = NULL;
1213         nlp_item = NULL;
1214
1215         nhdr_0 = tvb_get_guint8(tvb, index);
1216         nhdr_1 = tvb_get_guint8(tvb, index+1);
1217
1218         if (check_col(pinfo->cinfo, COL_INFO))
1219                 col_add_str(pinfo->cinfo, COL_INFO, "HPR NLP Packet");
1220
1221         if (tree) {
1222                 /* Don't bother setting length. We'll set it later after we
1223                  * find the lengths of NHDR */
1224                 nlp_item = proto_tree_add_item(tree, hf_sna_nlp_nhdr, tvb,
1225                     index, -1, FALSE);
1226                 nlp_tree = proto_item_add_subtree(nlp_item, ett_sna_nlp_nhdr);
1227
1228                 bf_item = proto_tree_add_uint(nlp_tree, hf_sna_nlp_nhdr_0, tvb,
1229                     index, 1, nhdr_0);
1230                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_nhdr_0);
1231
1232                 proto_tree_add_uint(bf_tree, hf_sna_nlp_sm, tvb, index, 1,
1233                     nhdr_0);
1234                 proto_tree_add_uint(bf_tree, hf_sna_nlp_tpf, tvb, index, 1,
1235                     nhdr_0);
1236
1237                 bf_item = proto_tree_add_uint(nlp_tree, hf_sna_nlp_nhdr_1, tvb,
1238                     index+1, 1, nhdr_1);
1239                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_nhdr_1);
1240
1241                 proto_tree_add_uint(bf_tree, hf_sna_nlp_ft, tvb,
1242                     index+1, 1, nhdr_1);
1243                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_tspi, tvb,
1244                     index+1, 1, nhdr_1);
1245                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_slowdn1, tvb,
1246                     index+1, 1, nhdr_1);
1247                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_slowdn2, tvb,
1248                     index+1, 1, nhdr_1);
1249         }
1250         /* ANR or FR lists */
1251
1252         index += 2;
1253         counter = 0;
1254
1255         if ((nhdr_0 & 0xe0) == 0xa0) {
1256                 do {
1257                         nhdr_x = tvb_get_guint8(tvb, index + counter);
1258                         counter ++;
1259                 } while (nhdr_x != 0xff);
1260                 if (tree)
1261                         h_item = proto_tree_add_item(nlp_tree, 
1262                             hf_sna_nlp_fra, tvb, index, counter, FALSE);
1263                 index += counter;
1264                 if (tree)
1265                         proto_tree_add_text(nlp_tree, tvb, index, 1,
1266                             "Reserved");
1267                 index++;
1268
1269                 if (tree)
1270                         proto_item_set_len(nlp_item, index);
1271
1272                 if ((nhdr_1 & 0xf0) == 0x10) {
1273                         nhdr_x = tvb_get_guint8(tvb, index);
1274                         if (tree)
1275                                 proto_tree_add_uint(tree, hf_sna_nlp_frh, 
1276                                     tvb, index, 1, nhdr_x);
1277                         index ++;
1278
1279                         if (tvb_offset_exists(tvb, index))
1280                                 call_dissector(data_handle,
1281                                         tvb_new_subset(tvb, index, -1, -1),
1282                                         pinfo, parent_tree);
1283                         return;
1284                 }
1285         }
1286         if ((nhdr_0 & 0xe0) == 0xc0) {
1287                 do {
1288                         nhdr_x = tvb_get_guint8(tvb, index + counter);
1289                         counter ++;
1290                 } while (nhdr_x != 0xff);
1291                 if (tree)
1292                         h_item = proto_tree_add_item(nlp_tree, hf_sna_nlp_anr, 
1293                             tvb, index, counter, FALSE);
1294                 index += counter;
1295
1296                 if (tree)
1297                         proto_tree_add_text(nlp_tree, tvb, index, 1,
1298                             "Reserved");
1299                 index++;
1300
1301                 if (tree)
1302                         proto_item_set_len(nlp_item, index);
1303         }
1304
1305         thdr_8 = tvb_get_guint8(tvb, index+8);
1306         thdr_9 = tvb_get_guint8(tvb, index+9);
1307         thdr_len = tvb_get_ntohs(tvb, index+10);
1308         thdr_dlf = tvb_get_ntohl(tvb, index+12);
1309
1310         if (tree) {
1311                 nlp_item = proto_tree_add_item(tree, hf_sna_nlp_thdr, tvb, 
1312                     index, thdr_len << 2, FALSE);
1313                 nlp_tree = proto_item_add_subtree(nlp_item, ett_sna_nlp_thdr);
1314
1315                 proto_tree_add_item(nlp_tree, hf_sna_nlp_tcid, tvb,
1316                     index, 8, FALSE);
1317                 bf_item = proto_tree_add_uint(nlp_tree, hf_sna_nlp_thdr_8, tvb,
1318                     index+8, 1, thdr_8);
1319                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_thdr_8);
1320
1321                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_setupi, tvb,
1322                     index+8, 1, thdr_8);
1323                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_somi, tvb, index+8,
1324                     1, thdr_8);
1325                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_eomi, tvb, index+8,
1326                     1, thdr_8);
1327                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_sri, tvb, index+8,
1328                     1, thdr_8);
1329                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_rasapi, tvb,
1330                     index+8, 1, thdr_8);
1331                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_retryi, tvb,
1332                     index+8, 1, thdr_8);
1333
1334                 bf_item = proto_tree_add_uint(nlp_tree, hf_sna_nlp_thdr_9, tvb,
1335                     index+9, 1, thdr_9);
1336                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_thdr_9);
1337
1338                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_lmi, tvb, index+9,
1339                     1, thdr_9);
1340                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_cqfi, tvb, index+9,
1341                     1, thdr_9);
1342                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_osi, tvb, index+9,
1343                     1, thdr_9);
1344
1345                 proto_tree_add_uint(nlp_tree, hf_sna_nlp_offset, tvb, index+10,
1346                     2, thdr_len);
1347                 proto_tree_add_uint(nlp_tree, hf_sna_nlp_dlf, tvb, index+12,
1348                     4, thdr_dlf);
1349                 proto_tree_add_item(nlp_tree, hf_sna_nlp_bsn, tvb, index+16,
1350                     4, FALSE);
1351         }
1352         subindex = 20;
1353
1354         if (((thdr_9 & 0x18) == 0x08) && ((thdr_len << 2) > subindex)) {
1355                 counter = tvb_get_guint8(tvb, index + subindex);
1356                 if (tvb_get_guint8(tvb, index+subindex+1) == 5)
1357                         dissect_control(tvb, index + subindex, counter+2, nlp_tree, 1, LT);
1358                 else
1359                         call_dissector(data_handle,
1360                             tvb_new_subset(tvb, index + subindex, counter+2,
1361                             -1), pinfo, nlp_tree);
1362
1363                 subindex += (counter+2);
1364         }
1365         if ((thdr_9 & 0x04) && ((thdr_len << 2) > subindex))
1366                 dissect_optional(
1367                     tvb_new_subset(tvb, index + subindex,
1368                     (thdr_len << 2) - subindex, -1),
1369                     pinfo, nlp_tree);
1370
1371         index += (thdr_len << 2);
1372         if (((thdr_8 & 0x20) == 0) && thdr_dlf) {
1373                 if (check_col(pinfo->cinfo, COL_INFO))
1374                         col_add_str(pinfo->cinfo, COL_INFO, "HPR Fragment");
1375                 if (tvb_offset_exists(tvb, index)) {
1376                         call_dissector(data_handle,
1377                             tvb_new_subset(tvb, index, -1, -1), pinfo,
1378                             parent_tree);
1379                 }
1380                 return;
1381         }
1382         if (tvb_offset_exists(tvb, index)) {
1383                 /* Transmission Header Format Identifier */
1384                 fid = hi_nibble(tvb_get_guint8(tvb, index));
1385                 if (fid == 5) /* Only FID5 allowed for HPR */
1386                         dissect_fid(tvb_new_subset(tvb, index, -1, -1), pinfo,
1387                             tree, parent_tree);
1388                 else {
1389                         if (tvb_get_ntohs(tvb, index+2) == 0x12ce) {
1390                                 /* Route Setup */
1391                                 if (check_col(pinfo->cinfo, COL_INFO))
1392                                         col_add_str(pinfo->cinfo, COL_INFO,
1393                                             "HPR Route Setup");
1394                                 dissect_gds(tvb_new_subset(tvb, index, -1, -1),
1395                                     pinfo, tree, parent_tree);
1396                         } else
1397                                 call_dissector(data_handle, 
1398                                     tvb_new_subset(tvb, index, -1, -1),
1399                                     pinfo, parent_tree);
1400                 }
1401         }
1402 }
1403
1404 /* --------------------------------------------------------------------
1405  * Chapter 3 Exchange Identification (XID) Information Fields
1406  * --------------------------------------------------------------------
1407  */
1408
1409 static void
1410 dissect_xid1(tvbuff_t *tvb, proto_tree *tree)
1411 {
1412         if (!tree)
1413                 return;
1414
1415         proto_tree_add_text(tree, tvb, 0, 2, "Reserved");
1416
1417 }
1418
1419 static void
1420 dissect_xid2(tvbuff_t *tvb, proto_tree *tree)
1421 {
1422         guint           dlen, offset;
1423
1424         if (!tree)
1425                 return;
1426
1427         dlen = tvb_get_guint8(tvb, 0);
1428
1429         offset = dlen;
1430
1431         while (tvb_offset_exists(tvb, offset)) {
1432                 dlen = tvb_get_guint8(tvb, offset+1);
1433                 dissect_control(tvb, offset, dlen+2, tree, 0, KL);
1434                 offset += (dlen + 2);
1435         }
1436 }
1437
1438 static void
1439 dissect_xid3(tvbuff_t *tvb, proto_tree *tree)
1440 {
1441         proto_tree      *sub_tree;
1442         proto_item      *sub_ti = NULL;
1443         guint           val, dlen, offset;
1444
1445         if (!tree)
1446                 return;
1447
1448         proto_tree_add_text(tree, tvb, 0, 2, "Reserved");
1449
1450         val = tvb_get_ntohs(tvb, 2);
1451
1452         sub_ti = proto_tree_add_uint(tree, hf_sna_xid_3_8, tvb,
1453             2, 2, val);
1454         sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_3_8);
1455
1456         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_init_self, tvb, 2, 2,
1457             val);
1458         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_stand_bind, tvb, 2, 2,
1459             val);
1460         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_gener_bind, tvb, 2, 2,
1461             val);
1462         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_recve_bind, tvb, 2, 2,
1463             val);
1464         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_actpu, tvb, 2, 2, val);
1465         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_nwnode, tvb, 2, 2, val);
1466         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_cp, tvb, 2, 2, val);
1467         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_cpcp, tvb, 2, 2, val);
1468         proto_tree_add_uint(sub_tree, hf_sna_xid_3_state, tvb, 2, 2, val);
1469         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_nonact, tvb, 2, 2, val);
1470         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_cpchange, tvb, 2, 2,
1471             val);
1472
1473         val = tvb_get_guint8(tvb, 4);
1474
1475         sub_ti = proto_tree_add_uint(tree, hf_sna_xid_3_10, tvb,
1476             4, 1, val);
1477         sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_3_10);
1478
1479         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_asend_bind, tvb, 4, 1,
1480             val);
1481         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_arecv_bind, tvb, 4, 1,
1482             val);
1483         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_quiesce, tvb, 4, 1, val);
1484         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_pucap, tvb, 4, 1, val);
1485         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_pbn, tvb, 4, 1, val);
1486         proto_tree_add_uint(sub_tree, hf_sna_xid_3_pacing, tvb, 4, 1, val);
1487
1488         val = tvb_get_guint8(tvb, 5);
1489
1490         sub_ti = proto_tree_add_uint(tree, hf_sna_xid_3_11, tvb,
1491             5, 1, val);
1492         sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_3_11);
1493
1494         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_tgshare, tvb, 5, 1, val);
1495         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_dedsvc, tvb, 5, 1, val);
1496
1497         val = tvb_get_guint8(tvb, 6);
1498
1499         sub_ti = proto_tree_add_item(tree, hf_sna_xid_3_12, tvb,
1500             6, 1, FALSE);
1501         sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_3_12);
1502
1503         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_negcsup, tvb, 6, 1, val);
1504         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_negcomp, tvb, 6, 1, val);
1505
1506         proto_tree_add_text(tree, tvb, 7, 2, "Reserved");
1507
1508         val = tvb_get_guint8(tvb, 9);
1509
1510         sub_ti = proto_tree_add_item(tree, hf_sna_xid_3_15, tvb,
1511             9, 1, FALSE);
1512         sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_3_15);
1513
1514         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_partg, tvb, 9, 1, val);
1515         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_dlur, tvb, 9, 1, val);
1516         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_dlus, tvb, 9, 1, val);
1517         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_exbn, tvb, 9, 1, val);
1518         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_genodai, tvb, 9, 1, val);
1519         proto_tree_add_uint(sub_tree, hf_sna_xid_3_branch, tvb, 9, 1, val);
1520         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_brnn, tvb, 9, 1, val);
1521
1522         proto_tree_add_item(tree, hf_sna_xid_3_tg, tvb, 10, 1, FALSE);
1523         proto_tree_add_item(tree, hf_sna_xid_3_dlc, tvb, 11, 1, FALSE);
1524
1525         dlen = tvb_get_guint8(tvb, 12);
1526
1527         proto_tree_add_uint(tree, hf_sna_xid_3_dlen, tvb, 12, 1, dlen);
1528
1529         /* FIXME: DLC Dependent Data Go Here */
1530
1531         offset = 12 + dlen;
1532
1533         while (tvb_offset_exists(tvb, offset)) {
1534                 dlen = tvb_get_guint8(tvb, offset+1);
1535                 dissect_control(tvb, offset, dlen+2, tree, 0, KL);
1536                 offset += (dlen+2);
1537         }
1538 }
1539
1540 static void
1541 dissect_xid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
1542     proto_tree *parent_tree)
1543 {
1544         proto_tree      *sub_tree;
1545         proto_item      *sub_ti = NULL;
1546         int             format, type, len;
1547         guint32         id;
1548
1549         len = tvb_get_guint8(tvb, 1);
1550         type = tvb_get_guint8(tvb, 0);
1551         id = tvb_get_ntohl(tvb, 2);
1552         format = hi_nibble(type);
1553
1554         /* Summary information */
1555         if (check_col(pinfo->cinfo, COL_INFO))
1556                 col_add_fstr(pinfo->cinfo, COL_INFO,
1557                     "SNA XID Format:%d Type:%s", format,
1558                     val_to_str(lo_nibble(type), sna_xid_type_vals,
1559                     "Unknown Type"));
1560
1561         if (tree) {
1562                 sub_ti = proto_tree_add_item(tree, hf_sna_xid_0, tvb,
1563                     0, 1, FALSE);
1564                 sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_0);
1565
1566                 proto_tree_add_uint(sub_tree, hf_sna_xid_format, tvb, 0, 1,
1567                     type);
1568                 proto_tree_add_uint(sub_tree, hf_sna_xid_type, tvb, 0, 1,
1569                     type);
1570
1571                 proto_tree_add_uint(tree, hf_sna_xid_len, tvb, 1, 1, len);
1572
1573                 sub_ti = proto_tree_add_item(tree, hf_sna_xid_id, tvb,
1574                     2, 4, FALSE);
1575                 sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_id);
1576
1577                 proto_tree_add_uint(sub_tree, hf_sna_xid_idblock, tvb, 2, 4,
1578                     id);
1579                 proto_tree_add_uint(sub_tree, hf_sna_xid_idnum, tvb, 2, 4,
1580                     id);
1581
1582                 switch(format) {
1583                         case 0:
1584                                 break;
1585                         case 1:
1586                                 dissect_xid1(tvb_new_subset(tvb, 6, len-6, -1),
1587                                     tree);
1588                                 break;
1589                         case 2:
1590                                 dissect_xid2(tvb_new_subset(tvb, 6, len-6, -1),
1591                                     tree);
1592                                 break;
1593                         case 3:
1594                                 dissect_xid3(tvb_new_subset(tvb, 6, len-6, -1),
1595                                     tree);
1596                                 break;
1597                         default:
1598                                 /* external standards organizations */
1599                                 call_dissector(data_handle,
1600                                     tvb_new_subset(tvb, 6, len-6, -1),
1601                                     pinfo, tree);
1602                 }
1603         }
1604
1605         if (format == 0)
1606                 len = 6;
1607
1608         if (tvb_offset_exists(tvb, len))
1609                 call_dissector(data_handle,
1610                     tvb_new_subset(tvb, len, -1, -1), pinfo, parent_tree);
1611 }
1612
1613 /* --------------------------------------------------------------------
1614  * Chapter 4 Transmission Headers (THs)
1615  * --------------------------------------------------------------------
1616  */
1617
1618 #define RH_LEN  3
1619
1620 static unsigned int
1621 mpf_value(guint8 th_byte)
1622 {
1623         return (th_byte & 0x0c) >> 2;
1624 }
1625
1626 #define FIRST_FRAG_NUMBER       0
1627 #define MIDDLE_FRAG_NUMBER      1
1628 #define LAST_FRAG_NUMBER        2
1629
1630 /* FID2 is defragged by sequence. The weird thing is that we have neither
1631  * absolute sequence numbers, nor byte offets. Other FIDs have byte offsets
1632  * (the DCF field), but not FID2. The only thing we have to go with is "FIRST",
1633  * "MIDDLE", or "LAST". If the BIU is split into 3 frames, then everything is
1634  * fine, * "FIRST", "MIDDLE", and "LAST" map nicely onto frag-number 0, 1,
1635  * and 2. However, if the BIU is split into 2 frames, then we only have
1636  * "FIRST" and "LAST", and the mapping *should* be frag-number 0 and 1,
1637  * *NOT* 0 and 2.
1638  *
1639  * The SNA docs say "FID2 PIUs cannot be blocked because there is no DCF in the
1640  * TH format for deblocking" (note on Figure 4-2 in the IBM SNA documention,
1641  * see the FTP URL in the comment near the top of this file). I *think*
1642  * this means that the fragmented frames cannot arrive out of order.
1643  * Well, I *want* it to mean this, because w/o this limitation, if you
1644  * get a "FIRST" frame and a "LAST" frame, how long should you wait to
1645  * see if a "MIDDLE" frame every arrives????? Thus, if frames *have* to
1646  * arrive in order, then we're saved.
1647  *
1648  * The problem then boils down to figuring out if "LAST" means frag-number 1
1649  * (in the case of a BIU split into 2 frames) or frag-number 2
1650  * (in the case of a BIU split into 3 frames).
1651  *
1652  * Assuming fragmented FID2 BIU frames *do* arrive in order, the obvious
1653  * way to handle the mapping of "LAST" to either frag-number 1 or
1654  * frag-number 2 is to keep a hash which tracks the frames seen, etc.
1655  * This consumes resources. A trickier way, but a way which works, is to
1656  * always map the "LAST" BIU segment to frag-number 2. Here's the trickery:
1657  * if we add frag-number 2, which we know to be the "LAST" BIU segment,
1658  * and the reassembly code tells us that the the BIU is still not reassmebled,
1659  * then, owing to the, ahem, /fact/, that fragmented BIU segments arrive
1660  * in order :), we know that 1) "FIRST" did come, and 2) there's no "MIDDLE",
1661  * because this BIU was fragmented into 2 frames, not 3. So, we'll be
1662  * tricky and add a zero-length "MIDDLE" BIU frame (i.e, frag-number 1)
1663  * to complete the reassembly.
1664  */
1665 static tvbuff_t*
1666 defragment_by_sequence(packet_info *pinfo, tvbuff_t *tvb, int offset, int mpf,
1667     int id)
1668 {
1669         fragment_data *fd_head;
1670         int frag_number = -1;
1671         int more_frags = TRUE;
1672         tvbuff_t *rh_tvb = NULL;
1673         gint frag_len;
1674
1675         /* Determine frag_number and more_frags */
1676         switch(mpf) {
1677                 case MPF_WHOLE_BIU:
1678                         /* nothing */
1679                         break;
1680                 case MPF_FIRST_SEGMENT:
1681                         frag_number = FIRST_FRAG_NUMBER;
1682                         break;
1683                 case MPF_MIDDLE_SEGMENT:
1684                         frag_number = MIDDLE_FRAG_NUMBER;
1685                         break;
1686                 case MPF_LAST_SEGMENT:
1687                         frag_number = LAST_FRAG_NUMBER;
1688                         more_frags = FALSE;
1689                         break;
1690                 default:
1691                         DISSECTOR_ASSERT_NOT_REACHED();
1692         }
1693
1694         /* If sna_defragment is on, and this is a fragment.. */
1695         if (frag_number > -1) {
1696                 /* XXX - check length ??? */
1697                 frag_len = tvb_reported_length_remaining(tvb, offset);
1698                 if (tvb_bytes_exist(tvb, offset, frag_len)) {
1699                         fd_head = fragment_add_seq(tvb, offset, pinfo, id,
1700                             sna_fragment_table, frag_number, frag_len,
1701                             more_frags);
1702
1703                         /* We added the LAST segment and reassembly didn't
1704                          * complete. Insert a zero-length MIDDLE segment to
1705                          * turn a 2-frame BIU-fragmentation into a 3-frame
1706                          * BIU-fragmentation (empty middle frag).
1707                          * See above long comment about this trickery. */
1708
1709                         if (mpf == MPF_LAST_SEGMENT && !fd_head) {
1710                                 fd_head = fragment_add_seq(tvb, offset, pinfo,
1711                                     id, sna_fragment_table,
1712                                     MIDDLE_FRAG_NUMBER, 0, TRUE);
1713                         }
1714
1715                         if (fd_head != NULL) {
1716                                 /* We have the complete reassembled payload. */
1717                                 rh_tvb = tvb_new_real_data(fd_head->data,
1718                                     fd_head->len, fd_head->len);
1719
1720                                 /* Add the tvbuff to the chain of tvbuffs
1721                                  * so that it will get cleaned up too. */
1722                                 tvb_set_child_real_data_tvbuff(tvb, rh_tvb);
1723
1724                                 /* Add the defragmented data to the data
1725                                  * source list. */
1726                                 add_new_data_source(pinfo, rh_tvb,
1727                                     "Reassembled SNA BIU");
1728                         }
1729                 }
1730         }
1731         return rh_tvb;
1732 }
1733
1734 #define SNA_FID01_ADDR_LEN      2
1735
1736 /* FID Types 0 and 1 */
1737 static int
1738 dissect_fid0_1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1739 {
1740         proto_tree      *bf_tree;
1741         proto_item      *bf_item;
1742         guint8          th_0;
1743         const guint8    *ptr;
1744
1745         const int bytes_in_header = 10;
1746
1747         if (tree) {
1748                 /* Byte 0 */
1749                 th_0 = tvb_get_guint8(tvb, 0);
1750                 bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, 0, 1,
1751                     th_0);
1752                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1753
1754                 proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb, 0, 1, th_0);
1755                 proto_tree_add_uint(bf_tree, hf_sna_th_mpf, tvb, 0, 1, th_0);
1756                 proto_tree_add_uint(bf_tree, hf_sna_th_efi, tvb, 0, 1, th_0);
1757
1758                 /* Byte 1 */
1759                 proto_tree_add_text(tree, tvb, 1, 1, "Reserved");
1760
1761                 /* Bytes 2-3 */
1762                 proto_tree_add_item(tree, hf_sna_th_daf, tvb, 2, 2, FALSE);
1763         }
1764
1765         /* Set DST addr */
1766         ptr = tvb_get_ptr(tvb, 2, SNA_FID01_ADDR_LEN);
1767         SET_ADDRESS(&pinfo->net_dst, AT_SNA, SNA_FID01_ADDR_LEN, ptr);
1768         SET_ADDRESS(&pinfo->dst, AT_SNA, SNA_FID01_ADDR_LEN, ptr);
1769
1770         if (tree)
1771                 proto_tree_add_item(tree, hf_sna_th_oaf, tvb, 4, 2, FALSE);
1772
1773         /* Set SRC addr */
1774         ptr = tvb_get_ptr(tvb, 4, SNA_FID01_ADDR_LEN);
1775         SET_ADDRESS(&pinfo->net_src, AT_SNA, SNA_FID01_ADDR_LEN, ptr);
1776         SET_ADDRESS(&pinfo->src, AT_SNA, SNA_FID01_ADDR_LEN, ptr);
1777
1778         /* If we're not filling a proto_tree, return now */
1779         if (tree)
1780                 return bytes_in_header;
1781
1782         proto_tree_add_item(tree, hf_sna_th_snf, tvb, 6, 2, FALSE);
1783         proto_tree_add_item(tree, hf_sna_th_dcf, tvb, 8, 2, FALSE);
1784
1785         return bytes_in_header;
1786 }
1787
1788 #define SNA_FID2_ADDR_LEN       1
1789
1790 /* FID Type 2 */
1791 static int
1792 dissect_fid2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
1793         tvbuff_t **rh_tvb_ptr, next_dissection_t *continue_dissecting)
1794 {
1795         proto_tree      *bf_tree;
1796         proto_item      *bf_item;
1797         guint8          th_0=0, daf=0, oaf=0;
1798         const guint8    *ptr;
1799         unsigned int    mpf, id;
1800
1801         const int bytes_in_header = 6;
1802
1803         th_0 = tvb_get_guint8(tvb, 0);
1804         mpf = mpf_value(th_0);
1805
1806         if (tree) {
1807                 daf = tvb_get_guint8(tvb, 2);
1808                 oaf = tvb_get_guint8(tvb, 3);
1809
1810                 /* Byte 0 */
1811                 bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, 0, 1,
1812                     th_0);
1813                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1814
1815                 proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb, 0, 1, th_0);
1816                 proto_tree_add_uint(bf_tree, hf_sna_th_mpf, tvb, 0, 1, th_0);
1817                 proto_tree_add_uint(bf_tree, hf_sna_th_odai,tvb, 0, 1, th_0);
1818                 proto_tree_add_uint(bf_tree, hf_sna_th_efi, tvb, 0, 1, th_0);
1819
1820
1821                 /* Byte 1 */
1822                 proto_tree_add_text(tree, tvb, 1, 1, "Reserved");
1823
1824                 /* Byte 2 */
1825                 proto_tree_add_uint_format(tree, hf_sna_th_daf, tvb, 2, 1, daf,
1826                     "Destination Address Field: 0x%02x", daf);
1827         }
1828
1829         /* Set DST addr */
1830         ptr = tvb_get_ptr(tvb, 2, SNA_FID2_ADDR_LEN);
1831         SET_ADDRESS(&pinfo->net_dst, AT_SNA, SNA_FID2_ADDR_LEN, ptr);
1832         SET_ADDRESS(&pinfo->dst, AT_SNA, SNA_FID2_ADDR_LEN, ptr);
1833
1834         if (tree) {
1835                 /* Byte 3 */
1836                 proto_tree_add_uint_format(tree, hf_sna_th_oaf, tvb, 3, 1, oaf,
1837                     "Origin Address Field: 0x%02x", oaf);
1838         }
1839
1840         /* Set SRC addr */
1841         ptr = tvb_get_ptr(tvb, 3, SNA_FID2_ADDR_LEN);
1842         SET_ADDRESS(&pinfo->net_src, AT_SNA, SNA_FID2_ADDR_LEN, ptr);
1843         SET_ADDRESS(&pinfo->src, AT_SNA, SNA_FID2_ADDR_LEN, ptr);
1844
1845         id = tvb_get_ntohs(tvb, 4);
1846         if (tree)
1847                 proto_tree_add_uint(tree, hf_sna_th_snf, tvb, 4, 2, id);
1848
1849         if (mpf != MPF_WHOLE_BIU && !sna_defragment) {
1850                 if (mpf == MPF_FIRST_SEGMENT) {
1851                         *continue_dissecting = rh_only;
1852                 } else {
1853                         *continue_dissecting = stop_here;
1854                 }
1855
1856         }
1857         else if (sna_defragment) {
1858                 *rh_tvb_ptr = defragment_by_sequence(pinfo, tvb,
1859                     bytes_in_header, mpf, id);
1860         }
1861
1862         return bytes_in_header;
1863 }
1864
1865 /* FID Type 3 */
1866 static int
1867 dissect_fid3(tvbuff_t *tvb, proto_tree *tree)
1868 {
1869         proto_tree      *bf_tree;
1870         proto_item      *bf_item;
1871         guint8          th_0;
1872
1873         const int bytes_in_header = 2;
1874
1875         /* If we're not filling a proto_tree, return now */
1876         if (!tree)
1877                 return bytes_in_header;
1878
1879         th_0 = tvb_get_guint8(tvb, 0);
1880
1881         /* Create the bitfield tree */
1882         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, 0, 1, th_0);
1883         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1884
1885         proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb, 0, 1, th_0);
1886         proto_tree_add_uint(bf_tree, hf_sna_th_mpf, tvb, 0, 1, th_0);
1887         proto_tree_add_uint(bf_tree, hf_sna_th_efi, tvb, 0, 1, th_0);
1888
1889         proto_tree_add_item(tree, hf_sna_th_lsid, tvb, 1, 1, FALSE);
1890
1891         return bytes_in_header;
1892 }
1893
1894 static int
1895 dissect_fid4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1896 {
1897         proto_tree      *bf_tree;
1898         proto_item      *bf_item;
1899         int             offset = 0;
1900         guint8          th_byte, mft;
1901         guint16         th_word;
1902         guint16         def, oef;
1903         guint32         dsaf, osaf;
1904         static struct sna_fid_type_4_addr src, dst;
1905
1906         const int bytes_in_header = 26;
1907
1908         /* If we're not filling a proto_tree, return now */
1909         if (!tree)
1910                 return bytes_in_header;
1911
1912         th_byte = tvb_get_guint8(tvb, offset);
1913
1914         /* Create the bitfield tree */
1915         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, offset,
1916             1, th_byte);
1917         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1918
1919         /* Byte 0 */
1920         proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb,
1921             offset, 1, th_byte);
1922         proto_tree_add_uint(bf_tree, hf_sna_th_tg_sweep, tvb,
1923             offset, 1, th_byte);
1924         proto_tree_add_uint(bf_tree, hf_sna_th_er_vr_supp_ind, tvb,
1925             offset, 1, th_byte);
1926         proto_tree_add_uint(bf_tree, hf_sna_th_vr_pac_cnt_ind, tvb,
1927             offset, 1, th_byte);
1928         proto_tree_add_uint(bf_tree, hf_sna_th_ntwk_prty, tvb,
1929             offset, 1, th_byte);
1930
1931         offset += 1;
1932         th_byte = tvb_get_guint8(tvb, offset);
1933
1934         /* Create the bitfield tree */
1935         bf_item = proto_tree_add_text(tree, tvb, offset, 1,
1936             "Transmision Header Byte 1");
1937         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1938
1939         /* Byte 1 */
1940         proto_tree_add_uint(bf_tree, hf_sna_th_tgsf, tvb, offset, 1,
1941             th_byte);
1942         proto_tree_add_boolean(bf_tree, hf_sna_th_mft, tvb, offset, 1,
1943             th_byte);
1944         proto_tree_add_uint(bf_tree, hf_sna_th_piubf, tvb, offset, 1,
1945             th_byte);
1946
1947         mft = th_byte & 0x04;
1948         offset += 1;
1949         th_byte = tvb_get_guint8(tvb, offset);
1950
1951         /* Create the bitfield tree */
1952         bf_item = proto_tree_add_text(tree, tvb, offset, 1,
1953             "Transmision Header Byte 2");
1954         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1955
1956         /* Byte 2 */
1957         if (mft) {
1958                 proto_tree_add_uint(bf_tree, hf_sna_th_nlpoi, tvb,
1959                     offset, 1, th_byte);
1960                 proto_tree_add_uint(bf_tree, hf_sna_th_nlp_cp, tvb,
1961                     offset, 1, th_byte);
1962         } else {
1963                 proto_tree_add_uint(bf_tree, hf_sna_th_iern, tvb,
1964                     offset, 1, th_byte);
1965         }
1966         proto_tree_add_uint(bf_tree, hf_sna_th_ern, tvb, offset, 1,
1967             th_byte);
1968
1969         offset += 1;
1970         th_byte = tvb_get_guint8(tvb, offset);
1971
1972         /* Create the bitfield tree */
1973         bf_item = proto_tree_add_text(tree, tvb, offset, 1,
1974             "Transmision Header Byte 3");
1975         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1976
1977         /* Byte 3 */
1978         proto_tree_add_uint(bf_tree, hf_sna_th_vrn, tvb, offset, 1,
1979             th_byte);
1980         proto_tree_add_uint(bf_tree, hf_sna_th_tpf, tvb, offset, 1,
1981             th_byte);
1982
1983         offset += 1;
1984         th_word = tvb_get_ntohs(tvb, offset);
1985
1986         /* Create the bitfield tree */
1987         bf_item = proto_tree_add_text(tree, tvb, offset, 2,
1988             "Transmision Header Bytes 4-5");
1989         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1990
1991         /* Bytes 4-5 */
1992         proto_tree_add_uint(bf_tree, hf_sna_th_vr_cwi, tvb,
1993             offset, 2, th_word);
1994         proto_tree_add_boolean(bf_tree, hf_sna_th_tg_nonfifo_ind, tvb,
1995             offset, 2, th_word);
1996         proto_tree_add_uint(bf_tree, hf_sna_th_vr_sqti, tvb,
1997             offset, 2, th_word);
1998
1999         /* I'm not sure about byte-order on this one... */
2000         proto_tree_add_uint(bf_tree, hf_sna_th_tg_snf, tvb,
2001             offset, 2, th_word);
2002
2003         offset += 2;
2004         th_word = tvb_get_ntohs(tvb, offset);
2005
2006         /* Create the bitfield tree */
2007         bf_item = proto_tree_add_text(tree, tvb, offset, 2,
2008             "Transmision Header Bytes 6-7");
2009         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
2010
2011         /* Bytes 6-7 */
2012         proto_tree_add_boolean(bf_tree, hf_sna_th_vrprq, tvb, offset,
2013             2, th_word);
2014         proto_tree_add_boolean(bf_tree, hf_sna_th_vrprs, tvb, offset,
2015             2, th_word);
2016         proto_tree_add_uint(bf_tree, hf_sna_th_vr_cwri, tvb, offset,
2017             2, th_word);
2018         proto_tree_add_boolean(bf_tree, hf_sna_th_vr_rwi, tvb, offset,
2019             2, th_word);
2020
2021         /* I'm not sure about byte-order on this one... */
2022         proto_tree_add_uint(bf_tree, hf_sna_th_vr_snf_send, tvb,
2023             offset, 2, th_word);
2024
2025         offset += 2;
2026
2027         dsaf = tvb_get_ntohl(tvb, 8);
2028         /* Bytes 8-11 */
2029         proto_tree_add_uint(tree, hf_sna_th_dsaf, tvb, offset, 4, dsaf);
2030
2031         offset += 4;
2032
2033         osaf = tvb_get_ntohl(tvb, 12);
2034         /* Bytes 12-15 */
2035         proto_tree_add_uint(tree, hf_sna_th_osaf, tvb, offset, 4, osaf);
2036
2037         offset += 4;
2038         th_byte = tvb_get_guint8(tvb, offset);
2039
2040         /* Create the bitfield tree */
2041         bf_item = proto_tree_add_text(tree, tvb, offset, 2,
2042             "Transmision Header Byte 16");
2043         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
2044
2045         /* Byte 16 */
2046         proto_tree_add_boolean(tree, hf_sna_th_snai, tvb, offset, 1, th_byte);
2047
2048         /* We luck out here because in their infinite wisdom the SNA
2049          * architects placed the MPF and EFI fields in the same bitfield
2050          * locations, even though for FID4 they're not in byte 0.
2051          * Thank you IBM! */
2052         proto_tree_add_uint(tree, hf_sna_th_mpf, tvb, offset, 1, th_byte);
2053         proto_tree_add_uint(tree, hf_sna_th_efi, tvb, offset, 1, th_byte);
2054
2055         offset += 2;
2056         /* 1 for byte 16, 1 for byte 17 which is reserved */
2057
2058         def = tvb_get_ntohs(tvb, 18);
2059         /* Bytes 18-25 */
2060         proto_tree_add_uint(tree, hf_sna_th_def, tvb, offset, 2, def);
2061
2062         /* Addresses in FID 4 are discontiguous, sigh */
2063         dst.saf = dsaf;
2064         dst.ef = def;
2065         SET_ADDRESS(&pinfo->net_dst, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
2066             (guint8* )&dst);
2067         SET_ADDRESS(&pinfo->dst, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
2068             (guint8 *)&dst);
2069
2070         oef = tvb_get_ntohs(tvb, 20);
2071         proto_tree_add_uint(tree, hf_sna_th_oef, tvb, offset+2, 2, oef);
2072
2073         /* Addresses in FID 4 are discontiguous, sigh */
2074         src.saf = osaf;
2075         src.ef = oef;
2076         SET_ADDRESS(&pinfo->net_src, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
2077             (guint8 *)&src);
2078         SET_ADDRESS(&pinfo->src, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
2079             (guint8 *)&src);
2080
2081         proto_tree_add_item(tree, hf_sna_th_snf, tvb, offset+4, 2, FALSE);
2082         proto_tree_add_item(tree, hf_sna_th_dcf, tvb, offset+6, 2, FALSE);
2083
2084         return bytes_in_header;
2085 }
2086
2087 /* FID Type 5 */
2088 static int
2089 dissect_fid5(tvbuff_t *tvb, proto_tree *tree)
2090 {
2091         proto_tree      *bf_tree;
2092         proto_item      *bf_item;
2093         guint8          th_0;
2094
2095         const int bytes_in_header = 12;
2096
2097         /* If we're not filling a proto_tree, return now */
2098         if (!tree)
2099                 return bytes_in_header;
2100
2101         th_0 = tvb_get_guint8(tvb, 0);
2102
2103         /* Create the bitfield tree */
2104         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, 0, 1, th_0);
2105         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
2106
2107         proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb, 0, 1, th_0);
2108         proto_tree_add_uint(bf_tree, hf_sna_th_mpf, tvb, 0, 1, th_0);
2109         proto_tree_add_uint(bf_tree, hf_sna_th_efi, tvb, 0, 1, th_0);
2110
2111         proto_tree_add_text(tree, tvb, 1, 1, "Reserved");
2112         proto_tree_add_item(tree, hf_sna_th_snf, tvb, 2, 2, FALSE);
2113
2114         proto_tree_add_item(tree, hf_sna_th_sa, tvb, 4, 8, FALSE);
2115
2116         return bytes_in_header;
2117
2118 }
2119
2120 /* FID Type f */
2121 static int
2122 dissect_fidf(tvbuff_t *tvb, proto_tree *tree)
2123 {
2124         proto_tree      *bf_tree;
2125         proto_item      *bf_item;
2126         guint8          th_0;
2127
2128         const int bytes_in_header = 26;
2129
2130         /* If we're not filling a proto_tree, return now */
2131         if (!tree)
2132                 return bytes_in_header;
2133
2134         th_0 = tvb_get_guint8(tvb, 0);
2135
2136         /* Create the bitfield tree */
2137         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, 0, 1, th_0);
2138         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
2139
2140         proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb, 0, 1, th_0);
2141         proto_tree_add_text(tree, tvb, 1, 1, "Reserved");
2142
2143         proto_tree_add_item(tree, hf_sna_th_cmd_fmt, tvb,  2, 1, FALSE);
2144         proto_tree_add_item(tree, hf_sna_th_cmd_type, tvb, 3, 1, FALSE);
2145         proto_tree_add_item(tree, hf_sna_th_cmd_sn, tvb,   4, 2, FALSE);
2146
2147         /* Yup, bytes 6-23 are reserved! */
2148         proto_tree_add_text(tree, tvb, 6, 18, "Reserved");
2149
2150         proto_tree_add_item(tree, hf_sna_th_dcf, tvb, 24, 2, FALSE);
2151
2152         return bytes_in_header;
2153 }
2154
2155 static void
2156 dissect_fid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
2157     proto_tree *parent_tree)
2158 {
2159
2160         proto_tree      *th_tree = NULL, *rh_tree = NULL;
2161         proto_item      *th_ti = NULL, *rh_ti = NULL;
2162         guint8          th_fid;
2163         int             th_header_len = 0;
2164         int             offset, rh_offset;
2165         tvbuff_t        *rh_tvb = NULL;
2166         next_dissection_t continue_dissecting = everything;
2167
2168         /* Transmission Header Format Identifier */
2169         th_fid = hi_nibble(tvb_get_guint8(tvb, 0));
2170
2171         /* Summary information */
2172         if (check_col(pinfo->cinfo, COL_INFO))
2173                 col_add_str(pinfo->cinfo, COL_INFO,
2174                     val_to_str(th_fid, sna_th_fid_vals, "Unknown FID: %01x"));
2175
2176         if (tree) {
2177                 /* --- TH --- */
2178                 /* Don't bother setting length. We'll set it later after we
2179                  * find the length of TH */
2180                 th_ti = proto_tree_add_item(tree, hf_sna_th, tvb,  0, -1,
2181                     FALSE);
2182                 th_tree = proto_item_add_subtree(th_ti, ett_sna_th);
2183         }
2184
2185         /* Get size of TH */
2186         switch(th_fid) {
2187                 case 0x0:
2188                 case 0x1:
2189                         th_header_len = dissect_fid0_1(tvb, pinfo, th_tree);
2190                         break;
2191                 case 0x2:
2192                         th_header_len = dissect_fid2(tvb, pinfo, th_tree,
2193                             &rh_tvb, &continue_dissecting);
2194                         break;
2195                 case 0x3:
2196                         th_header_len = dissect_fid3(tvb, th_tree);
2197                         break;
2198                 case 0x4:
2199                         th_header_len = dissect_fid4(tvb, pinfo, th_tree);
2200                         break;
2201                 case 0x5:
2202                         th_header_len = dissect_fid5(tvb, th_tree);
2203                         break;
2204                 case 0xf:
2205                         th_header_len = dissect_fidf(tvb, th_tree);
2206                         break;
2207                 default:
2208                         call_dissector(data_handle,
2209                             tvb_new_subset(tvb, 1, -1, -1), pinfo, parent_tree);
2210                         return;
2211         }
2212
2213         offset = th_header_len;
2214
2215         /* Short-circuit ? */
2216         if (continue_dissecting == stop_here) {
2217                 if (tree) {
2218                         proto_tree_add_text(tree, tvb, offset, -1,
2219                             "BIU segment data");
2220                 }
2221                 return;
2222         }
2223
2224         /* If the FID dissector function didn't create an rh_tvb, then we just
2225          * use the rest of our tvbuff as the rh_tvb. */
2226         if (!rh_tvb)
2227                 rh_tvb = tvb_new_subset(tvb, offset, -1, -1);
2228         rh_offset = 0;
2229
2230         /* Process the rest of the SNA packet, starting with RH */
2231         if (tree) {
2232                 proto_item_set_len(th_ti, th_header_len);
2233
2234                 /* --- RH --- */
2235                 rh_ti = proto_tree_add_item(tree, hf_sna_rh, rh_tvb, rh_offset,
2236                     RH_LEN, FALSE);
2237                 rh_tree = proto_item_add_subtree(rh_ti, ett_sna_rh);
2238                 dissect_rh(rh_tvb, rh_offset, rh_tree);
2239         }
2240
2241         rh_offset += RH_LEN;
2242
2243         if (tvb_offset_exists(rh_tvb, rh_offset)) {
2244                 /* Short-circuit ? */
2245                 if (continue_dissecting == rh_only) {
2246                         if (tree)
2247                                 proto_tree_add_text(tree, rh_tvb, rh_offset, -1,
2248                                     "BIU segment data");
2249                         return;
2250                 }
2251
2252                 call_dissector(data_handle, 
2253                     tvb_new_subset(rh_tvb, rh_offset, -1, -1), 
2254                     pinfo, parent_tree);
2255         }
2256 }
2257
2258 /* --------------------------------------------------------------------
2259  * Chapter 5 Request/Response Headers (RHs)
2260  * --------------------------------------------------------------------
2261  */
2262
2263 static void
2264 dissect_rh(tvbuff_t *tvb, int offset, proto_tree *tree)
2265 {
2266         proto_tree      *bf_tree;
2267         proto_item      *bf_item;
2268         gboolean        is_response;
2269         guint8          rh_0, rh_1, rh_2;
2270
2271         if (!tree)
2272                 return;
2273
2274         /* Create the bitfield tree for byte 0*/
2275         rh_0 = tvb_get_guint8(tvb, offset);
2276         is_response = (rh_0 & 0x80);
2277
2278         bf_item = proto_tree_add_uint(tree, hf_sna_rh_0, tvb, offset, 1, rh_0);
2279         bf_tree = proto_item_add_subtree(bf_item, ett_sna_rh_0);
2280
2281         proto_tree_add_uint(bf_tree, hf_sna_rh_rri, tvb, offset, 1, rh_0);
2282         proto_tree_add_uint(bf_tree, hf_sna_rh_ru_category, tvb, offset, 1,
2283             rh_0);
2284         proto_tree_add_boolean(bf_tree, hf_sna_rh_fi, tvb, offset, 1, rh_0);
2285         proto_tree_add_boolean(bf_tree, hf_sna_rh_sdi, tvb, offset, 1, rh_0);
2286         proto_tree_add_boolean(bf_tree, hf_sna_rh_bci, tvb, offset, 1, rh_0);
2287         proto_tree_add_boolean(bf_tree, hf_sna_rh_eci, tvb, offset, 1, rh_0);
2288
2289         offset += 1;
2290         rh_1 = tvb_get_guint8(tvb, offset);
2291
2292         /* Create the bitfield tree for byte 1*/
2293         bf_item = proto_tree_add_uint(tree, hf_sna_rh_1, tvb, offset, 1, rh_1);
2294         bf_tree = proto_item_add_subtree(bf_item, ett_sna_rh_1);
2295
2296         proto_tree_add_boolean(bf_tree, hf_sna_rh_dr1, tvb,  offset, 1, rh_1);
2297
2298         if (!is_response)
2299                 proto_tree_add_boolean(bf_tree, hf_sna_rh_lcci, tvb, offset, 1,
2300                     rh_1);
2301
2302         proto_tree_add_boolean(bf_tree, hf_sna_rh_dr2, tvb,  offset, 1, rh_1);
2303
2304         if (is_response) {
2305                 proto_tree_add_boolean(bf_tree, hf_sna_rh_rti, tvb,  offset, 1,
2306                     rh_1);
2307         } else {
2308                 proto_tree_add_boolean(bf_tree, hf_sna_rh_eri, tvb,  offset, 1,
2309                     rh_1);
2310                 proto_tree_add_boolean(bf_tree, hf_sna_rh_rlwi, tvb, offset, 1,
2311                     rh_1);
2312         }
2313
2314         proto_tree_add_boolean(bf_tree, hf_sna_rh_qri, tvb, offset, 1, rh_1);
2315         proto_tree_add_boolean(bf_tree, hf_sna_rh_pi, tvb,  offset, 1, rh_1);
2316
2317         offset += 1;
2318         rh_2 = tvb_get_guint8(tvb, offset);
2319
2320         /* Create the bitfield tree for byte 2*/
2321         bf_item = proto_tree_add_uint(tree, hf_sna_rh_2, tvb, offset, 1, rh_2);
2322
2323         if (!is_response) {
2324                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_rh_2);
2325
2326                 proto_tree_add_boolean(bf_tree, hf_sna_rh_bbi, tvb,  offset, 1,
2327                     rh_2);
2328                 proto_tree_add_boolean(bf_tree, hf_sna_rh_ebi, tvb,  offset, 1,
2329                     rh_2);
2330                 proto_tree_add_boolean(bf_tree, hf_sna_rh_cdi, tvb,  offset, 1,
2331                     rh_2);
2332                 proto_tree_add_uint(bf_tree, hf_sna_rh_csi, tvb,  offset, 1,
2333                     rh_2);
2334                 proto_tree_add_boolean(bf_tree, hf_sna_rh_edi, tvb,  offset, 1,
2335                     rh_2);
2336                 proto_tree_add_boolean(bf_tree, hf_sna_rh_pdi, tvb,  offset, 1,
2337                     rh_2);
2338                 proto_tree_add_boolean(bf_tree, hf_sna_rh_cebi, tvb, offset, 1,
2339                     rh_2);
2340         }
2341
2342         /* XXX - check for sdi. If TRUE, the next 4 bytes will be sense data */
2343 }
2344
2345 /* --------------------------------------------------------------------
2346  * Chapter 6 Request/Response Units (RUs)
2347  * --------------------------------------------------------------------
2348  */
2349
2350 /* --------------------------------------------------------------------
2351  * Chapter 9 Common Fields
2352  * --------------------------------------------------------------------
2353  */
2354
2355 static void
2356 dissect_control_05hpr(tvbuff_t *tvb, proto_tree *tree, int hpr,
2357     enum parse parse)
2358 {
2359         proto_tree      *bf_tree;
2360         proto_item      *bf_item;
2361         guint8          type;
2362         guint16         offset, len, pad;
2363
2364         if (!tree)
2365                 return;
2366
2367         type = tvb_get_guint8(tvb, 2);
2368
2369         bf_item = proto_tree_add_uint(tree, hf_sna_control_05_type, tvb,
2370             2, 1, type);
2371         bf_tree = proto_item_add_subtree(bf_item, ett_sna_control_05hpr_type);
2372
2373         proto_tree_add_boolean(bf_tree, hf_sna_control_05_ptp, tvb, 2, 1, type);
2374         proto_tree_add_text(tree, tvb, 3, 1, "Reserved");
2375
2376         offset = 4;
2377
2378         while (tvb_offset_exists(tvb, offset)) {
2379                 if (parse == LT) {
2380                         len = tvb_get_guint8(tvb, offset+0);
2381                 } else {
2382                         len = tvb_get_guint8(tvb, offset+1);
2383                 }
2384                 if (len) {
2385                         dissect_control(tvb, offset, len, tree, hpr, parse);
2386                         pad = (len+3) & 0xfffc;
2387             if (pad > len) {
2388                 /* XXX - fix this, ensure tvb is large enough for pad */
2389                 tvb_ensure_bytes_exist(tvb, offset+len, pad-len);
2390                                 proto_tree_add_text(tree, tvb, offset+len,
2391                                     pad-len, "Padding");
2392             }
2393                         offset += pad;
2394                 } else {
2395                         return;
2396                 }
2397         }
2398 }
2399
2400 static void
2401 dissect_control_05(tvbuff_t *tvb, proto_tree *tree)
2402 {
2403         if(!tree)
2404                 return;
2405
2406         proto_tree_add_item(tree, hf_sna_control_05_delay, tvb, 2, 2, FALSE);
2407 }
2408
2409 static void
2410 dissect_control_0e(tvbuff_t *tvb, proto_tree *tree)
2411 {
2412         gint    len;
2413         guint8  *buf;
2414
2415         if (!tree)
2416                 return;
2417
2418         proto_tree_add_item(tree, hf_sna_control_0e_type, tvb, 2, 1, FALSE);
2419
2420         len = tvb_reported_length_remaining(tvb, 3);
2421         if (len <= 0)
2422                 return;
2423
2424         buf = tvb_get_ephemeral_string(tvb, 3, len);
2425         EBCDIC_to_ASCII(buf, len);
2426         proto_tree_add_string(tree, hf_sna_control_0e_value, tvb, 3, len, buf);
2427 }
2428
2429 static void
2430 dissect_control(tvbuff_t *parent_tvb, int offset, int control_len,
2431     proto_tree *tree, int hpr, enum parse parse)
2432 {
2433         tvbuff_t        *tvb;
2434         gint            length, reported_length;
2435         proto_tree      *sub_tree;
2436         proto_item      *sub_item;
2437         int             len, key;
2438         gint            ett;
2439
2440         length = tvb_length_remaining(parent_tvb, offset);
2441         reported_length = tvb_reported_length_remaining(parent_tvb, offset);
2442         if (control_len < length)
2443                 length = control_len;
2444         if (control_len < reported_length)
2445                 reported_length = control_len;
2446         tvb = tvb_new_subset(parent_tvb, offset, length, reported_length);
2447
2448         sub_tree = NULL;
2449
2450         if (parse == LT) {
2451                 len = tvb_get_guint8(tvb, 0);
2452                 key = tvb_get_guint8(tvb, 1);
2453         } else {
2454                 key = tvb_get_guint8(tvb, 0);
2455                 len = tvb_get_guint8(tvb, 1);
2456         }
2457         ett = ett_sna_control_un;
2458
2459         if (tree) {
2460                 if (key == 5) {
2461                          if (hpr) ett = ett_sna_control_05hpr;
2462                          else ett = ett_sna_control_05;
2463                 }
2464                 if (key == 0x0e) ett = ett_sna_control_0e;
2465
2466                 if (((key == 0) || (key == 3) || (key == 5)) && hpr)
2467                         sub_item = proto_tree_add_text(tree, tvb, 0, -1,
2468                             val_to_str(key, sna_control_hpr_vals,
2469                             "Unknown Control Vector"));
2470                 else
2471                         sub_item = proto_tree_add_text(tree, tvb, 0, -1,
2472                             val_to_str(key, sna_control_vals,
2473                             "Unknown Control Vector"));
2474                 sub_tree = proto_item_add_subtree(sub_item, ett);
2475                 if (parse == LT) {
2476                         proto_tree_add_uint(sub_tree, hf_sna_control_len,
2477                             tvb, 0, 1, len);
2478                         if (((key == 0) || (key == 3) || (key == 5)) && hpr)
2479                                 proto_tree_add_uint(sub_tree,
2480                                     hf_sna_control_hprkey, tvb, 1, 1, key);
2481                         else
2482                                 proto_tree_add_uint(sub_tree,
2483                                     hf_sna_control_key, tvb, 1, 1, key);
2484                 } else {
2485                         if (((key == 0) || (key == 3) || (key == 5)) && hpr)
2486                                 proto_tree_add_uint(sub_tree,
2487                                     hf_sna_control_hprkey, tvb, 0, 1, key);
2488                         else
2489                                 proto_tree_add_uint(sub_tree,
2490                                     hf_sna_control_key, tvb, 0, 1, key);
2491                         proto_tree_add_uint(sub_tree, hf_sna_control_len,
2492                             tvb, 1, 1, len);
2493                 }
2494         }
2495         switch(key) {
2496                 case 0x05:
2497                         if (hpr)
2498                                 dissect_control_05hpr(tvb, sub_tree, hpr,
2499                                     parse);
2500                         else
2501                                 dissect_control_05(tvb, sub_tree);
2502                         break;
2503                 case 0x0e:
2504                         dissect_control_0e(tvb, sub_tree);
2505                         break;
2506         }
2507 }
2508
2509 /* --------------------------------------------------------------------
2510  * Chapter 11 Function Management (FM) Headers
2511  * --------------------------------------------------------------------
2512  */
2513
2514 /* --------------------------------------------------------------------
2515  * Chapter 12 Presentation Services (PS) Headers
2516  * --------------------------------------------------------------------
2517  */
2518
2519 /* --------------------------------------------------------------------
2520  * Chapter 13 GDS Variables
2521  * --------------------------------------------------------------------
2522  */
2523
2524 static void
2525 dissect_gds(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, 
2526     proto_tree *parent_tree)
2527 {
2528         guint16         length;
2529         guint16         type;
2530         int             cont;
2531         int             offset;
2532         proto_tree      *gds_tree;
2533         proto_item      *gds_item;
2534
2535         offset = 0;
2536         cont   = 1;
2537         type   = tvb_get_ntohs(tvb, offset+2);
2538
2539         while (cont) {
2540                 length = tvb_get_ntohs(tvb, offset) & 0x7fff;
2541                 cont   = (tvb_get_ntohs(tvb, offset) & 0x8000) ? 1 : 0;
2542                 type   = tvb_get_ntohs(tvb, offset+2);
2543
2544                 if (length < 2 ) /* escape sequence ? */
2545                         return;
2546                 if (tree) {
2547                         gds_item = proto_tree_add_item(tree, hf_sna_gds, tvb,
2548                             offset, length, FALSE);
2549                         gds_tree = proto_item_add_subtree(gds_item,
2550                             ett_sna_gds);
2551
2552                         proto_tree_add_uint(gds_tree, hf_sna_gds_len, tvb,
2553                             offset, 2, length);
2554                         proto_tree_add_boolean(gds_tree, hf_sna_gds_cont, tvb,
2555                             offset, 2, cont);
2556                         proto_tree_add_uint(gds_tree, hf_sna_gds_type, tvb,
2557                             offset+2, 2, type);
2558                 }
2559                 offset += length;
2560         }
2561         if (tvb_offset_exists(tvb, offset))
2562                 call_dissector(data_handle,
2563                     tvb_new_subset(tvb, offset, -1, -1), pinfo, parent_tree);
2564 }
2565
2566 /* --------------------------------------------------------------------
2567  * General stuff
2568  * --------------------------------------------------------------------
2569  */
2570
2571 static void
2572 dissect_sna(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2573 {
2574         guint8          fid;
2575         proto_tree      *sna_tree = NULL;
2576         proto_item      *sna_ti = NULL;
2577
2578         if (check_col(pinfo->cinfo, COL_PROTOCOL))
2579                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SNA");
2580         if (check_col(pinfo->cinfo, COL_INFO))
2581                 col_clear(pinfo->cinfo, COL_INFO);
2582
2583         /* SNA data should be printed in EBCDIC, not ASCII */
2584         pinfo->fd->flags.encoding = CHAR_EBCDIC;
2585
2586         if (tree) {
2587
2588                 /* Don't bother setting length. We'll set it later after we find
2589                  * the lengths of TH/RH/RU */
2590                 sna_ti = proto_tree_add_item(tree, proto_sna, tvb, 0, -1,
2591                     FALSE);
2592                 sna_tree = proto_item_add_subtree(sna_ti, ett_sna);
2593         }
2594
2595         /* Transmission Header Format Identifier */
2596         fid = hi_nibble(tvb_get_guint8(tvb, 0));
2597         switch(fid) {
2598                 case 0xa:       /* HPR Network Layer Packet */
2599                 case 0xb:
2600                 case 0xc:
2601                 case 0xd:
2602                         dissect_nlp(tvb, pinfo, sna_tree, tree);
2603                         break;
2604                 default:
2605                         dissect_fid(tvb, pinfo, sna_tree, tree);
2606         }
2607 }
2608
2609 static void
2610 dissect_sna_xid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2611 {
2612         proto_tree      *sna_tree = NULL;
2613         proto_item      *sna_ti = NULL;
2614
2615         if (check_col(pinfo->cinfo, COL_PROTOCOL))
2616                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SNA");
2617         if (check_col(pinfo->cinfo, COL_INFO))
2618                 col_clear(pinfo->cinfo, COL_INFO);
2619
2620         /* SNA data should be printed in EBCDIC, not ASCII */
2621         pinfo->fd->flags.encoding = CHAR_EBCDIC;
2622
2623         if (tree) {
2624
2625                 /* Don't bother setting length. We'll set it later after we find
2626                  * the lengths of XID */
2627                 sna_ti = proto_tree_add_item(tree, proto_sna_xid, tvb, 0, -1,
2628                     FALSE);
2629                 sna_tree = proto_item_add_subtree(sna_ti, ett_sna);
2630         }
2631         dissect_xid(tvb, pinfo, sna_tree, tree);
2632 }
2633
2634 static void
2635 sna_init(void)
2636 {
2637         fragment_table_init(&sna_fragment_table);
2638         reassembled_table_init(&sna_reassembled_table);
2639 }
2640
2641
2642 void
2643 proto_register_sna(void)
2644 {
2645         static hf_register_info hf[] = {
2646                 { &hf_sna_th,
2647                 { "Transmission Header", "sna.th", FT_NONE, BASE_NONE,
2648                      NULL, 0x0, "", HFILL }},
2649
2650                 { &hf_sna_th_0,
2651                 { "Transmission Header Byte 0", "sna.th.0", FT_UINT8, BASE_HEX,
2652                     NULL, 0x0,
2653                     "TH Byte 0", HFILL }},
2654
2655                 { &hf_sna_th_fid,
2656                 { "Format Identifer", "sna.th.fid", FT_UINT8, BASE_HEX,
2657                     VALS(sna_th_fid_vals), 0xf0, "", HFILL }},
2658
2659                 { &hf_sna_th_mpf,
2660                 { "Mapping Field", "sna.th.mpf", FT_UINT8,
2661                     BASE_DEC, VALS(sna_th_mpf_vals), 0x0c, "", HFILL }},
2662
2663                 { &hf_sna_th_odai,
2664                 { "ODAI Assignment Indicator", "sna.th.odai", FT_UINT8,
2665                     BASE_DEC, NULL, 0x02, "", HFILL }},
2666
2667                 { &hf_sna_th_efi,
2668                 { "Expedited Flow Indicator", "sna.th.efi", FT_UINT8,
2669                     BASE_DEC, VALS(sna_th_efi_vals), 0x01, "", HFILL }},
2670
2671                 { &hf_sna_th_daf,
2672                 { "Destination Address Field", "sna.th.daf", FT_UINT16,
2673                     BASE_HEX, NULL, 0x0, "", HFILL }},
2674
2675                 { &hf_sna_th_oaf,
2676                 { "Origin Address Field", "sna.th.oaf", FT_UINT16, BASE_HEX,
2677                     NULL, 0x0, "", HFILL }},
2678
2679                 { &hf_sna_th_snf,
2680                 { "Sequence Number Field", "sna.th.snf", FT_UINT16, BASE_DEC,
2681                     NULL, 0x0, "", HFILL }},
2682
2683                 { &hf_sna_th_dcf,
2684                 { "Data Count Field", "sna.th.dcf", FT_UINT16, BASE_DEC,
2685                     NULL, 0x0, "", HFILL }},
2686
2687                 { &hf_sna_th_lsid,
2688                 { "Local Session Identification", "sna.th.lsid", FT_UINT8,
2689                     BASE_HEX, NULL, 0x0, "", HFILL }},
2690
2691                 { &hf_sna_th_tg_sweep,
2692                 { "Transmission Group Sweep", "sna.th.tg_sweep", FT_UINT8,
2693                     BASE_DEC, VALS(sna_th_tg_sweep_vals), 0x08, "", HFILL }},
2694
2695                 { &hf_sna_th_er_vr_supp_ind,
2696                 { "ER and VR Support Indicator", "sna.th.er_vr_supp_ind",
2697                     FT_UINT8, BASE_DEC, VALS(sna_th_er_vr_supp_ind_vals),
2698                     0x04, "", HFILL }},
2699
2700                 { &hf_sna_th_vr_pac_cnt_ind,
2701                 { "Virtual Route Pacing Count Indicator",
2702                     "sna.th.vr_pac_cnt_ind", FT_UINT8, BASE_DEC,
2703                     VALS(sna_th_vr_pac_cnt_ind_vals), 0x02, "", HFILL }},
2704
2705                 { &hf_sna_th_ntwk_prty,
2706                 { "Network Priority", "sna.th.ntwk_prty", FT_UINT8, BASE_DEC,
2707                     VALS(sna_th_ntwk_prty_vals), 0x01, "", HFILL }},
2708
2709                 { &hf_sna_th_tgsf,
2710                 { "Transmission Group Segmenting Field", "sna.th.tgsf",
2711                     FT_UINT8, BASE_HEX, VALS(sna_th_tgsf_vals), 0xc0,
2712                     "", HFILL }},
2713
2714                 { &hf_sna_th_mft,
2715                 { "MPR FID4 Type", "sna.th.mft", FT_BOOLEAN, BASE_NONE,
2716                     NULL, 0x04, "", HFILL }},
2717
2718                 { &hf_sna_th_piubf,
2719                 { "PIU Blocking Field", "sna.th.piubf", FT_UINT8, BASE_HEX,
2720                     VALS(sna_th_piubf_vals), 0x03, "", HFILL }},
2721
2722                 { &hf_sna_th_iern,
2723                 { "Initial Explicit Route Number", "sna.th.iern", FT_UINT8,
2724                     BASE_DEC, NULL, 0xf0, "", HFILL }},
2725
2726                 { &hf_sna_th_nlpoi,
2727                 { "NLP Offset Indicator", "sna.th.nlpoi", FT_UINT8, BASE_DEC,
2728                     VALS(sna_th_nlpoi_vals), 0x80, "", HFILL }},
2729
2730                 { &hf_sna_th_nlp_cp,
2731                 { "NLP Count or Padding", "sna.th.nlp_cp", FT_UINT8, BASE_DEC,
2732                     NULL, 0x70, "", HFILL }},
2733
2734                 { &hf_sna_th_ern,
2735                 { "Explicit Route Number", "sna.th.ern", FT_UINT8, BASE_DEC,
2736                     NULL, 0x0f, "", HFILL }},
2737
2738                 { &hf_sna_th_vrn,
2739                 { "Virtual Route Number", "sna.th.vrn", FT_UINT8, BASE_DEC,
2740                     NULL, 0xf0, "", HFILL }},
2741
2742                 { &hf_sna_th_tpf,
2743                 { "Transmission Priority Field", "sna.th.tpf", FT_UINT8,
2744                     BASE_HEX, VALS(sna_th_tpf_vals), 0x03, "", HFILL }},
2745
2746                 { &hf_sna_th_vr_cwi,
2747                 { "Virtual Route Change Window Indicator", "sna.th.vr_cwi",
2748                     FT_UINT16, BASE_DEC, VALS(sna_th_vr_cwi_vals), 0x8000,
2749                     "Change Window Indicator", HFILL }},
2750
2751                 { &hf_sna_th_tg_nonfifo_ind,
2752                 { "Transmission Group Non-FIFO Indicator",
2753                     "sna.th.tg_nonfifo_ind", FT_BOOLEAN, 16,
2754                     TFS(&sna_th_tg_nonfifo_ind_truth), 0x4000, "", HFILL }},
2755
2756                 { &hf_sna_th_vr_sqti,
2757                 { "Virtual Route Sequence and Type Indicator", "sna.th.vr_sqti",
2758                     FT_UINT16, BASE_HEX, VALS(sna_th_vr_sqti_vals), 0x3000,
2759                     "Route Sequence and Type", HFILL }},
2760
2761                 { &hf_sna_th_tg_snf,
2762                 { "Transmission Group Sequence Number Field", "sna.th.tg_snf",
2763                     FT_UINT16, BASE_DEC, NULL, 0x0fff, "", HFILL }},
2764
2765                 { &hf_sna_th_vrprq,
2766                 { "Virtual Route Pacing Request", "sna.th.vrprq", FT_BOOLEAN,
2767                     16, TFS(&sna_th_vrprq_truth), 0x8000, "", HFILL }},
2768
2769                 { &hf_sna_th_vrprs,
2770                 { "Virtual Route Pacing Response", "sna.th.vrprs", FT_BOOLEAN,
2771                     16, TFS(&sna_th_vrprs_truth), 0x4000, "", HFILL }},
2772
2773                 { &hf_sna_th_vr_cwri,
2774                 { "Virtual Route Change Window Reply Indicator",
2775                     "sna.th.vr_cwri", FT_UINT16, BASE_DEC,
2776                     VALS(sna_th_vr_cwri_vals), 0x2000, "", HFILL }},
2777
2778                 { &hf_sna_th_vr_rwi,
2779                 { "Virtual Route Reset Window Indicator", "sna.th.vr_rwi",
2780                     FT_BOOLEAN, 16, TFS(&sna_th_vr_rwi_truth), 0x1000,
2781                     "", HFILL }},
2782
2783                 { &hf_sna_th_vr_snf_send,
2784                 { "Virtual Route Send Sequence Number Field",
2785                     "sna.th.vr_snf_send", FT_UINT16, BASE_DEC, NULL, 0x0fff,
2786                     "Send Sequence Number Field", HFILL }},
2787
2788                 { &hf_sna_th_dsaf,
2789                 { "Destination Subarea Address Field", "sna.th.dsaf",
2790                     FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
2791
2792                 { &hf_sna_th_osaf,
2793                 { "Origin Subarea Address Field", "sna.th.osaf", FT_UINT32,
2794                     BASE_HEX, NULL, 0x0, "", HFILL }},
2795
2796                 { &hf_sna_th_snai,
2797                 { "SNA Indicator", "sna.th.snai", FT_BOOLEAN, 8, NULL, 0x10,
2798                     "Used to identify whether the PIU originated or is destined"
2799                     " for an SNA or non-SNA device.", HFILL }},
2800
2801                 { &hf_sna_th_def,
2802                 { "Destination Element Field", "sna.th.def", FT_UINT16,
2803                     BASE_HEX, NULL, 0x0, "", HFILL }},
2804
2805                 { &hf_sna_th_oef,
2806                 { "Origin Element Field", "sna.th.oef", FT_UINT16, BASE_HEX,
2807                     NULL, 0x0, "", HFILL }},
2808
2809                 { &hf_sna_th_sa,
2810                 { "Session Address", "sna.th.sa", FT_BYTES, BASE_HEX,
2811                     NULL, 0x0, "", HFILL }},
2812
2813                 { &hf_sna_th_cmd_fmt,
2814                 { "Command Format", "sna.th.cmd_fmt", FT_UINT8, BASE_HEX,
2815                     NULL, 0x0, "", HFILL }},
2816
2817                 { &hf_sna_th_cmd_type,
2818                 { "Command Type", "sna.th.cmd_type", FT_UINT8, BASE_HEX,
2819                     NULL, 0x0, "", HFILL }},
2820
2821                 { &hf_sna_th_cmd_sn,
2822                 { "Command Sequence Number", "sna.th.cmd_sn", FT_UINT16,
2823                     BASE_DEC, NULL, 0x0, "", HFILL }},
2824
2825                 { &hf_sna_nlp_nhdr,
2826                 { "Network Layer Packet Header", "sna.nlp.nhdr", FT_NONE,
2827                     BASE_NONE, NULL, 0x0, "NHDR", HFILL }},
2828
2829                 { &hf_sna_nlp_nhdr_0,
2830                 { "Network Layer Packet Header Byte 0", "sna.nlp.nhdr.0",
2831                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
2832
2833                 { &hf_sna_nlp_nhdr_1,
2834                 { "Network Layer Packet Header Byte 1", "sna.nlp.nhdr.1",
2835                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
2836
2837                 { &hf_sna_nlp_sm,
2838                 { "Switching Mode Field", "sna.nlp.nhdr.sm", FT_UINT8,
2839                     BASE_HEX, VALS(sna_nlp_sm_vals), 0xe0, "", HFILL }},
2840
2841                 { &hf_sna_nlp_tpf,
2842                 { "Transmission Priority Field", "sna.nlp.nhdr.tpf", FT_UINT8,
2843                     BASE_HEX, VALS(sna_th_tpf_vals), 0x06, "", HFILL }},
2844
2845                 { &hf_sna_nlp_ft,
2846                 { "Function Type", "sna.nlp.nhdr.ft", FT_UINT8, BASE_HEX,
2847                     VALS(sna_nlp_ft_vals), 0xF0, "", HFILL }},
2848
2849                 { &hf_sna_nlp_tspi,
2850                 { "Time Sensitive Packet Indicator", "sna.nlp.nhdr.tspi",
2851                     FT_BOOLEAN, 8, TFS(&sna_nlp_tspi_truth), 0x08, "", HFILL }},
2852
2853                 { &hf_sna_nlp_slowdn1,
2854                 { "Slowdown 1", "sna.nlp.nhdr.slowdn1", FT_BOOLEAN, 8,
2855                     TFS(&sna_nlp_slowdn1_truth), 0x04, "", HFILL }},
2856
2857                 { &hf_sna_nlp_slowdn2,
2858                 { "Slowdown 2", "sna.nlp.nhdr.slowdn2", FT_BOOLEAN, 8,
2859                     TFS(&sna_nlp_slowdn2_truth), 0x02, "", HFILL }},
2860
2861                 { &hf_sna_nlp_fra,
2862                 { "Function Routing Address Entry", "sna.nlp.nhdr.fra",
2863                     FT_BYTES, BASE_NONE, NULL, 0, "", HFILL }},
2864
2865                 { &hf_sna_nlp_anr,
2866                 { "Automatic Network Routing Entry", "sna.nlp.nhdr.anr",
2867                     FT_BYTES, BASE_HEX, NULL, 0, "", HFILL }},
2868
2869                 { &hf_sna_nlp_frh,
2870                 { "Transmission Priority Field", "sna.nlp.frh", FT_UINT8,
2871                     BASE_HEX, VALS(sna_nlp_frh_vals), 0, "", HFILL }},
2872
2873                 { &hf_sna_nlp_thdr,
2874                 { "RTP Transport Header", "sna.nlp.thdr", FT_NONE, BASE_NONE,
2875                     NULL, 0x0, "THDR", HFILL }},
2876
2877                 { &hf_sna_nlp_tcid,
2878                 { "Transport Connection Identifier", "sna.nlp.thdr.tcid",
2879                     FT_BYTES, BASE_HEX, NULL, 0x0, "TCID", HFILL }},
2880
2881                 { &hf_sna_nlp_thdr_8,
2882                 { "RTP Transport Packet Header Byte 8", "sna.nlp.thdr.8",
2883                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
2884
2885                 { &hf_sna_nlp_setupi,
2886                 { "Setup Indicator", "sna.nlp.thdr.setupi", FT_BOOLEAN, 8,
2887                     TFS(&sna_nlp_setupi_truth), 0x40, "", HFILL }},
2888
2889                 { &hf_sna_nlp_somi,
2890                 { "Start Of Message Indicator", "sna.nlp.thdr.somi",
2891                     FT_BOOLEAN, 8, TFS(&sna_nlp_somi_truth), 0x20, "", HFILL }},
2892
2893                 { &hf_sna_nlp_eomi,
2894                 { "End Of Message Indicator", "sna.nlp.thdr.eomi", FT_BOOLEAN,
2895                     8, TFS(&sna_nlp_eomi_truth), 0x10, "", HFILL }},
2896
2897                 { &hf_sna_nlp_sri,
2898                 { "Session Request Indicator", "sna.nlp.thdr.sri", FT_BOOLEAN,
2899                     8, TFS(&sna_nlp_sri_truth), 0x08, "", HFILL }},
2900
2901                 { &hf_sna_nlp_rasapi,
2902                 { "Reply ASAP Indicator", "sna.nlp.thdr.rasapi", FT_BOOLEAN,
2903                     8, TFS(&sna_nlp_rasapi_truth), 0x04, "", HFILL }},
2904
2905                 { &hf_sna_nlp_retryi,
2906                 { "Retry Indicator", "sna.nlp.thdr.retryi", FT_BOOLEAN,
2907                     8, TFS(&sna_nlp_retryi_truth), 0x02, "", HFILL }},
2908
2909                 { &hf_sna_nlp_thdr_9,
2910                 { "RTP Transport Packet Header Byte 9", "sna.nlp.thdr.9",
2911                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
2912
2913                 { &hf_sna_nlp_lmi,
2914                 { "Last Message Indicator", "sna.nlp.thdr.lmi", FT_BOOLEAN,
2915                     8, TFS(&sna_nlp_lmi_truth), 0x80, "", HFILL }},
2916
2917                 { &hf_sna_nlp_cqfi,
2918                 { "Connection Qualifyer Field Indicator", "sna.nlp.thdr.cqfi",
2919                     FT_BOOLEAN, 8, TFS(&sna_nlp_cqfi_truth), 0x08, "", HFILL }},
2920
2921                 { &hf_sna_nlp_osi,
2922                 { "Optional Segments Present Indicator", "sna.nlp.thdr.osi",
2923                     FT_BOOLEAN, 8, TFS(&sna_nlp_osi_truth), 0x04, "", HFILL }},
2924
2925                 { &hf_sna_nlp_offset,
2926                 { "Data Offset/4", "sna.nlp.thdr.offset", FT_UINT16, BASE_HEX,
2927                     NULL, 0x0, "Data Offset in Words", HFILL }},
2928
2929                 { &hf_sna_nlp_dlf,
2930                 { "Data Length Field", "sna.nlp.thdr.dlf", FT_UINT32, BASE_HEX,
2931                     NULL, 0x0, "", HFILL }},
2932
2933                 { &hf_sna_nlp_bsn,
2934                 { "Byte Sequence Number", "sna.nlp.thdr.bsn", FT_UINT32,
2935                     BASE_HEX, NULL, 0x0, "", HFILL }},
2936
2937                 { &hf_sna_nlp_opti_len,
2938                 { "Optional Segment Length/4", "sna.nlp.thdr.optional.len",
2939                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
2940
2941                 { &hf_sna_nlp_opti_type,
2942                 { "Optional Segment Type", "sna.nlp.thdr.optional.type",
2943                     FT_UINT8, BASE_HEX, VALS(sna_nlp_opti_vals), 0x0, "",
2944                     HFILL }},
2945
2946                 { &hf_sna_nlp_opti_0d_version,
2947                 { "Version", "sna.nlp.thdr.optional.0d.version",
2948                     FT_UINT16, BASE_HEX, VALS(sna_nlp_opti_0d_version_vals),
2949                     0, "", HFILL }},
2950
2951                 { &hf_sna_nlp_opti_0d_4,
2952                 { "Connection Setup Byte 4", "sna.nlp.thdr.optional.0e.4",
2953                     FT_UINT8, BASE_HEX, NULL, 0, "", HFILL }},
2954
2955                 { &hf_sna_nlp_opti_0d_target,
2956                 { "Target Resource ID Present",
2957                     "sna.nlp.thdr.optional.0d.target",
2958                     FT_BOOLEAN, 8, NULL, 0x80, "", HFILL }},
2959
2960                 { &hf_sna_nlp_opti_0d_arb,
2961                 { "ARB Flow Control", "sna.nlp.thdr.optional.0d.arb",
2962                     FT_BOOLEAN, 8, NULL, 0x10, "", HFILL }},
2963
2964                 { &hf_sna_nlp_opti_0d_reliable,
2965                 { "Reliable Connection", "sna.nlp.thdr.optional.0d.reliable",
2966                     FT_BOOLEAN, 8, NULL, 0x08, "", HFILL }},
2967
2968                 { &hf_sna_nlp_opti_0d_dedicated,
2969                 { "Dedicated RTP Connection",
2970                     "sna.nlp.thdr.optional.0d.dedicated",
2971                     FT_BOOLEAN, 8, NULL, 0x04, "", HFILL }},
2972
2973                 { &hf_sna_nlp_opti_0e_stat,
2974                 { "Status", "sna.nlp.thdr.optional.0e.stat",
2975                     FT_UINT8, BASE_HEX, NULL, 0, "", HFILL }},
2976
2977                 { &hf_sna_nlp_opti_0e_gap,
2978                 { "Gap Detected", "sna.nlp.thdr.optional.0e.gap",
2979                     FT_BOOLEAN, 8, NULL, 0x80, "", HFILL }},
2980
2981                 { &hf_sna_nlp_opti_0e_idle,
2982                 { "RTP Idle Packet", "sna.nlp.thdr.optional.0e.idle",
2983                     FT_BOOLEAN, 8, NULL, 0x40, "", HFILL }},
2984
2985                 { &hf_sna_nlp_opti_0e_nabsp,
2986                 { "Number Of ABSP", "sna.nlp.thdr.optional.0e.nabsp",
2987                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
2988
2989                 { &hf_sna_nlp_opti_0e_sync,
2990                 { "Status Report Number", "sna.nlp.thdr.optional.0e.sync",
2991                     FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
2992
2993                 { &hf_sna_nlp_opti_0e_echo,
2994                 { "Status Acknowledge Number", "sna.nlp.thdr.optional.0e.echo",
2995                     FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
2996
2997                 { &hf_sna_nlp_opti_0e_rseq,
2998                 { "Received Sequence Number", "sna.nlp.thdr.optional.0e.rseq",
2999                     FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
3000
3001                 { &hf_sna_nlp_opti_0e_abspbeg,
3002                 { "ABSP Begin", "sna.nlp.thdr.optional.0e.abspbeg",
3003                     FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
3004
3005                 { &hf_sna_nlp_opti_0e_abspend,
3006                 { "ABSP End", "sna.nlp.thdr.optional.0e.abspend",
3007                     FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
3008
3009                 { &hf_sna_nlp_opti_0f_bits,
3010                 { "Client Bits", "sna.nlp.thdr.optional.0f.bits",
3011                     FT_UINT8, BASE_HEX, VALS(sna_nlp_opti_0f_bits_vals),
3012                     0x0, "", HFILL }},
3013
3014                 { &hf_sna_nlp_opti_10_tcid,
3015                 { "Transport Connection Identifier",
3016                     "sna.nlp.thdr.optional.10.tcid",
3017                     FT_BYTES, BASE_HEX, NULL, 0x0, "TCID", HFILL }},
3018
3019                 { &hf_sna_nlp_opti_12_sense,
3020                 { "Sense Data", "sna.nlp.thdr.optional.12.sense",
3021                     FT_BYTES, BASE_HEX, NULL, 0x0, "", HFILL }},
3022
3023                 { &hf_sna_nlp_opti_14_si_len,
3024                 { "Length", "sna.nlp.thdr.optional.14.si.len",
3025                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3026
3027                 { &hf_sna_nlp_opti_14_si_key,
3028                 { "Key", "sna.nlp.thdr.optional.14.si.key",
3029                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3030
3031                 { &hf_sna_nlp_opti_14_si_2,
3032                 { "Switching Information Byte 2",
3033                     "sna.nlp.thdr.optional.14.si.2",
3034                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3035
3036                 { &hf_sna_nlp_opti_14_si_refifo,
3037                 { "Resequencing (REFIFO) Indicator",
3038                     "sna.nlp.thdr.optional.14.si.refifo",
3039                     FT_BOOLEAN, 8, NULL, 0x80, "", HFILL }},
3040
3041                 { &hf_sna_nlp_opti_14_si_mobility,
3042                 { "Mobility Indicator",
3043                     "sna.nlp.thdr.optional.14.si.mobility",
3044                     FT_BOOLEAN, 8, NULL, 0x40, "", HFILL }},
3045
3046                 { &hf_sna_nlp_opti_14_si_dirsearch,
3047                 { "Directory Search Required on Path Switch Indicator",
3048                     "sna.nlp.thdr.optional.14.si.dirsearch",
3049                     FT_BOOLEAN, 8, NULL, 0x20, "", HFILL }},
3050
3051                 { &hf_sna_nlp_opti_14_si_limitres,
3052                 { "Limited Resource Link Indicator",
3053                     "sna.nlp.thdr.optional.14.si.limitres",
3054                     FT_BOOLEAN, 8, NULL, 0x10, "", HFILL }},
3055
3056                 { &hf_sna_nlp_opti_14_si_ncescope,
3057                 { "NCE Scope Indicator",
3058                     "sna.nlp.thdr.optional.14.si.ncescope",
3059                     FT_BOOLEAN, 8, NULL, 0x08, "", HFILL }},
3060
3061                 { &hf_sna_nlp_opti_14_si_mnpsrscv,
3062                 { "MNPS RSCV Retention Indicator",
3063                     "sna.nlp.thdr.optional.14.si.mnpsrscv",
3064                     FT_BOOLEAN, 8, NULL, 0x04, "", HFILL }},
3065
3066                 { &hf_sna_nlp_opti_14_si_maxpsize,
3067                 { "Maximum Packet Size On Return Path",
3068                     "sna.nlp.thdr.optional.14.si.maxpsize",
3069                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3070
3071                 { &hf_sna_nlp_opti_14_si_switch,
3072                 { "Path Switch Time", "sna.nlp.thdr.optional.14.si.switch",
3073                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3074
3075                 { &hf_sna_nlp_opti_14_si_alive,
3076                 { "RTP Alive Timer", "sna.nlp.thdr.optional.14.si.alive",
3077                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3078
3079                 { &hf_sna_nlp_opti_14_rr_len,
3080                 { "Length", "sna.nlp.thdr.optional.14.rr.len",
3081                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3082
3083                 { &hf_sna_nlp_opti_14_rr_key,
3084                 { "Key", "sna.nlp.thdr.optional.14.rr.key",
3085                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3086
3087                 { &hf_sna_nlp_opti_14_rr_2,
3088                 { "Return Route TG Descriptor Byte 2",
3089                     "sna.nlp.thdr.optional.14.rr.2",
3090                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3091
3092                 { &hf_sna_nlp_opti_14_rr_bfe,
3093                 { "BF Entry Indicator",
3094                     "sna.nlp.thdr.optional.14.rr.bfe",
3095                     FT_BOOLEAN, 8, NULL, 0x80, "", HFILL }},
3096
3097                 { &hf_sna_nlp_opti_14_rr_num,
3098                 { "Number Of TG Control Vectors",
3099                     "sna.nlp.thdr.optional.14.rr.num",
3100                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3101
3102                 { &hf_sna_nlp_opti_22_2,
3103                 { "Adaptive Rate Based Segment Byte 2",
3104                     "sna.nlp.thdr.optional.22.2",
3105                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3106
3107                 { &hf_sna_nlp_opti_22_type,
3108                 { "Message Type",
3109                     "sna.nlp.thdr.optional.22.type",
3110                     FT_UINT8, BASE_HEX,
3111                     VALS(sna_nlp_opti_22_type_vals), 0xc0, "", HFILL }},
3112
3113                 { &hf_sna_nlp_opti_22_raa,
3114                 { "Rate Adjustment Action",
3115                     "sna.nlp.thdr.optional.22.raa",
3116                     FT_UINT8, BASE_HEX,
3117                     VALS(sna_nlp_opti_22_raa_vals), 0x38, "", HFILL }},
3118
3119                 { &hf_sna_nlp_opti_22_parity,
3120                 { "Parity Indicator",
3121                     "sna.nlp.thdr.optional.22.parity",
3122                     FT_BOOLEAN, 8, NULL, 0x04, "", HFILL }},
3123
3124                 { &hf_sna_nlp_opti_22_arb,
3125                 { "ARB Mode",
3126                     "sna.nlp.thdr.optional.22.arb",
3127                     FT_UINT8, BASE_HEX,
3128                     VALS(sna_nlp_opti_22_arb_vals), 0x03, "", HFILL }},
3129
3130                 { &hf_sna_nlp_opti_22_3,
3131                 { "Adaptive Rate Based Segment Byte 3",
3132                     "sna.nlp.thdr.optional.22.3",
3133                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3134
3135                 { &hf_sna_nlp_opti_22_ratereq,
3136                 { "Rate Request Correlator",
3137                     "sna.nlp.thdr.optional.22.ratereq",
3138                     FT_UINT8, BASE_DEC, NULL, 0xf0, "", HFILL }},
3139
3140                 { &hf_sna_nlp_opti_22_raterep,
3141                 { "Rate Reply Correlator",
3142                     "sna.nlp.thdr.optional.22.raterep",
3143                     FT_UINT8, BASE_DEC, NULL, 0x0f, "", HFILL }},
3144
3145                 { &hf_sna_nlp_opti_22_field1,
3146                 { "Field 1", "sna.nlp.thdr.optional.22.field1",
3147                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3148
3149                 { &hf_sna_nlp_opti_22_field2,
3150                 { "Field 2", "sna.nlp.thdr.optional.22.field2",
3151                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3152
3153                 { &hf_sna_nlp_opti_22_field3,
3154                 { "Field 3", "sna.nlp.thdr.optional.22.field3",
3155                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3156
3157                 { &hf_sna_nlp_opti_22_field4,
3158                 { "Field 4", "sna.nlp.thdr.optional.22.field4",
3159                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3160
3161                 { &hf_sna_rh,
3162                 { "Request/Response Header", "sna.rh", FT_NONE, BASE_NONE,
3163                     NULL, 0x0, "", HFILL }},
3164
3165                 { &hf_sna_rh_0,
3166                 { "Request/Response Header Byte 0", "sna.rh.0", FT_UINT8,
3167                     BASE_HEX, NULL, 0x0, "", HFILL }},
3168
3169                 { &hf_sna_rh_1,
3170                 { "Request/Response Header Byte 1", "sna.rh.1", FT_UINT8,
3171                     BASE_HEX, NULL, 0x0, "", HFILL }},
3172
3173                 { &hf_sna_rh_2,
3174                 { "Request/Response Header Byte 2", "sna.rh.2", FT_UINT8,
3175                     BASE_HEX, NULL, 0x0, "", HFILL }},
3176
3177                 { &hf_sna_rh_rri,
3178                 { "Request/Response Indicator", "sna.rh.rri", FT_UINT8,
3179                     BASE_DEC, VALS(sna_rh_rri_vals), 0x80, "", HFILL }},
3180
3181                 { &hf_sna_rh_ru_category,
3182                 { "Request/Response Unit Category", "sna.rh.ru_category",
3183                     FT_UINT8, BASE_HEX, VALS(sna_rh_ru_category_vals), 0x60,
3184                     "", HFILL }},
3185
3186                 { &hf_sna_rh_fi,
3187                 { "Format Indicator", "sna.rh.fi", FT_BOOLEAN, 8,
3188                     TFS(&sna_rh_fi_truth), 0x08, "", HFILL }},
3189
3190                 { &hf_sna_rh_sdi,
3191                 { "Sense Data Included", "sna.rh.sdi", FT_BOOLEAN, 8,
3192                     TFS(&sna_rh_sdi_truth), 0x04, "", HFILL }},
3193
3194                 { &hf_sna_rh_bci,
3195                 { "Begin Chain Indicator", "sna.rh.bci", FT_BOOLEAN, 8,
3196                     TFS(&sna_rh_bci_truth), 0x02, "", HFILL }},
3197
3198                 { &hf_sna_rh_eci,
3199                 { "End Chain Indicator", "sna.rh.eci", FT_BOOLEAN, 8,
3200                     TFS(&sna_rh_eci_truth), 0x01, "", HFILL }},
3201
3202                 { &hf_sna_rh_dr1,
3203                 { "Definite Response 1 Indicator", "sna.rh.dr1", FT_BOOLEAN,
3204                     8, NULL, 0x80, "", HFILL }},
3205
3206                 { &hf_sna_rh_lcci,
3207                 { "Length-Checked Compression Indicator", "sna.rh.lcci",
3208                     FT_BOOLEAN, 8, TFS(&sna_rh_lcci_truth), 0x40, "", HFILL }},
3209
3210                 { &hf_sna_rh_dr2,
3211                 { "Definite Response 2 Indicator", "sna.rh.dr2", FT_BOOLEAN,
3212                     8, NULL, 0x20, "", HFILL }},
3213
3214                 { &hf_sna_rh_eri,
3215                 { "Exception Response Indicator", "sna.rh.eri", FT_BOOLEAN,
3216                     8, NULL, 0x10, "", HFILL }},
3217
3218                 { &hf_sna_rh_rti,
3219                 { "Response Type Indicator", "sna.rh.rti", FT_BOOLEAN,
3220                     8, TFS(&sna_rh_rti_truth), 0x10, "", HFILL }},
3221
3222                 { &hf_sna_rh_rlwi,
3223                 { "Request Larger Window Indicator", "sna.rh.rlwi", FT_BOOLEAN,
3224                     8, NULL, 0x04, "", HFILL }},
3225
3226                 { &hf_sna_rh_qri,
3227                 { "Queued Response Indicator", "sna.rh.qri", FT_BOOLEAN,
3228                     8, TFS(&sna_rh_qri_truth), 0x02, "", HFILL }},
3229
3230                 { &hf_sna_rh_pi,
3231                 { "Pacing Indicator", "sna.rh.pi", FT_BOOLEAN,
3232                     8, NULL, 0x01, "", HFILL }},
3233
3234                 { &hf_sna_rh_bbi,
3235                 { "Begin Bracket Indicator", "sna.rh.bbi", FT_BOOLEAN,
3236                     8, NULL, 0x80, "", HFILL }},
3237
3238                 { &hf_sna_rh_ebi,
3239                 { "End Bracket Indicator", "sna.rh.ebi", FT_BOOLEAN,
3240                     8, NULL, 0x40, "", HFILL }},
3241
3242                 { &hf_sna_rh_cdi,
3243                 { "Change Direction Indicator", "sna.rh.cdi", FT_BOOLEAN,
3244                     8, NULL, 0x20, "", HFILL }},
3245
3246                 { &hf_sna_rh_csi,
3247                 { "Code Selection Indicator", "sna.rh.csi", FT_UINT8, BASE_DEC,
3248                     VALS(sna_rh_csi_vals), 0x08, "", HFILL }},
3249
3250                 { &hf_sna_rh_edi,
3251                 { "Enciphered Data Indicator", "sna.rh.edi", FT_BOOLEAN, 8,
3252                     NULL, 0x04, "", HFILL }},
3253
3254                 { &hf_sna_rh_pdi,
3255                 { "Padded Data Indicator", "sna.rh.pdi", FT_BOOLEAN, 8, NULL,
3256                     0x02, "", HFILL }},
3257
3258                 { &hf_sna_rh_cebi,
3259                 { "Conditional End Bracket Indicator", "sna.rh.cebi",
3260                     FT_BOOLEAN, 8, NULL, 0x01, "", HFILL }},
3261
3262 /*              { &hf_sna_ru,
3263                 { "Request/Response Unit", "sna.ru", FT_NONE, BASE_NONE,
3264                     NULL, 0x0, "", HFILL }},*/
3265
3266                 { &hf_sna_gds,
3267                 { "GDS Variable", "sna.gds", FT_NONE, BASE_NONE, NULL, 0x0,
3268                     "", HFILL }},
3269
3270                 { &hf_sna_gds_len,
3271                 { "GDS Variable Length", "sna.gds.len", FT_UINT16, BASE_DEC,
3272                     NULL, 0x7fff, "", HFILL }},
3273
3274                 { &hf_sna_gds_cont,
3275                 { "Continuation Flag", "sna.gds.cont", FT_BOOLEAN, 16, NULL,
3276                     0x8000, "", HFILL }},
3277
3278                 { &hf_sna_gds_type,
3279                 { "Type of Variable", "sna.gds.type", FT_UINT16, BASE_HEX,
3280                     VALS(sna_gds_var_vals), 0x0, "", HFILL }},
3281
3282                 { &hf_sna_xid,
3283                 { "XID", "sna.xid", FT_NONE, BASE_NONE, NULL, 0x0,
3284                     "XID Frame", HFILL }},
3285
3286                 { &hf_sna_xid_0,
3287                 { "XID Byte 0", "sna.xid.0", FT_UINT8, BASE_HEX, NULL, 0x0,
3288                     "", HFILL }},
3289
3290                 { &hf_sna_xid_format,
3291                 { "XID Format", "sna.xid.format", FT_UINT8, BASE_DEC, NULL,
3292                     0xf0, "", HFILL }},
3293
3294                 { &hf_sna_xid_type,
3295                 { "XID Type", "sna.xid.type", FT_UINT8, BASE_DEC,
3296                     VALS(sna_xid_type_vals), 0x0f, "", HFILL }},
3297
3298                 { &hf_sna_xid_len,
3299                 { "XID Length", "sna.xid.len", FT_UINT8, BASE_DEC, NULL, 0x0,
3300                     "", HFILL }},
3301
3302                 { &hf_sna_xid_id,
3303                 { "Node Identification", "sna.xid.id", FT_UINT32, BASE_HEX,
3304                     NULL, 0x0, "", HFILL }},
3305
3306                 { &hf_sna_xid_idblock,
3307                 { "ID Block", "sna.xid.idblock", FT_UINT32, BASE_HEX, NULL, 
3308                     0xfff00000, "", HFILL }},
3309
3310                 { &hf_sna_xid_idnum,
3311                 { "ID Number", "sna.xid.idnum", FT_UINT32, BASE_HEX, NULL,
3312                     0x0fffff, "", HFILL }},
3313
3314                 { &hf_sna_xid_3_8,
3315                 { "Characteristics of XID sender", "sna.xid.type3.8", FT_UINT16,
3316                     BASE_HEX, NULL, 0x0, "", HFILL }},
3317
3318                 { &hf_sna_xid_3_init_self,
3319                 { "INIT-SELF support", "sna.xid.type3.initself",
3320                     FT_BOOLEAN, 16, NULL, 0x8000, "", HFILL }},
3321
3322                 { &hf_sna_xid_3_stand_bind,
3323                 { "Stand-Alone BIND Support", "sna.xid.type3.stand_bind",
3324                     FT_BOOLEAN, 16, NULL, 0x4000, "", HFILL }},
3325
3326                 { &hf_sna_xid_3_gener_bind,
3327                 { "Whole BIND PIU generated indicator",
3328                     "sna.xid.type3.gener_bind", FT_BOOLEAN, 16, NULL, 0x2000,
3329                     "Whole BIND PIU generated", HFILL }},
3330
3331                 { &hf_sna_xid_3_recve_bind,
3332                 { "Whole BIND PIU required indicator",
3333                     "sna.xid.type3.recve_bind", FT_BOOLEAN, 16, NULL, 0x1000,
3334                     "Whole BIND PIU required", HFILL }},
3335
3336                 { &hf_sna_xid_3_actpu,
3337                 { "ACTPU suppression indicator", "sna.xid.type3.actpu",
3338                     FT_BOOLEAN, 16, NULL, 0x0080, "", HFILL }},
3339
3340                 { &hf_sna_xid_3_nwnode,
3341                 { "Sender is network node", "sna.xid.type3.nwnode",
3342                     FT_BOOLEAN, 16, NULL, 0x0040, "", HFILL }},
3343
3344                 { &hf_sna_xid_3_cp,
3345                 { "Control Point Services", "sna.xid.type3.cp",
3346                     FT_BOOLEAN, 16, NULL, 0x0020, "", HFILL }},
3347
3348                 { &hf_sna_xid_3_cpcp,
3349                 { "CP-CP session support", "sna.xid.type3.cpcp",
3350                     FT_BOOLEAN, 16, NULL, 0x0010, "", HFILL }},
3351
3352                 { &hf_sna_xid_3_state,
3353                 { "XID exchange state indicator", "sna.xid.type3.state",
3354                     FT_UINT16, BASE_HEX, VALS(sna_xid_3_state_vals),
3355                     0x000c, "", HFILL }},
3356
3357                 { &hf_sna_xid_3_nonact,
3358                 { "Nonactivation Exchange", "sna.xid.type3.nonact",
3359                     FT_BOOLEAN, 16, NULL, 0x0002, "", HFILL }},
3360
3361                 { &hf_sna_xid_3_cpchange,
3362                 { "CP name change support", "sna.xid.type3.cpchange",
3363                     FT_BOOLEAN, 16, NULL, 0x0001, "", HFILL }},
3364
3365                 { &hf_sna_xid_3_10,
3366                 { "XID Type 3 Byte 10", "sna.xid.type3.10", FT_UINT8, BASE_HEX,
3367                     NULL, 0x0, "", HFILL }},
3368
3369                 { &hf_sna_xid_3_asend_bind,
3370                 { "Adaptive BIND pacing support as sender",
3371                     "sna.xid.type3.asend_bind", FT_BOOLEAN, 8, NULL, 0x80,
3372                     "Pacing support as sender", HFILL }},
3373
3374                 { &hf_sna_xid_3_arecv_bind,
3375                 { "Adaptive BIND pacing support as receiver",
3376                     "sna.xid.type3.asend_recv", FT_BOOLEAN, 8, NULL, 0x40,
3377                     "Pacing support as receive", HFILL }},
3378
3379                 { &hf_sna_xid_3_quiesce,
3380                 { "Quiesce TG Request",
3381                     "sna.xid.type3.quiesce", FT_BOOLEAN, 8, NULL, 0x20,
3382                     "", HFILL }},
3383
3384                 { &hf_sna_xid_3_pucap,
3385                 { "PU Capabilities",
3386                     "sna.xid.type3.pucap", FT_BOOLEAN, 8, NULL, 0x10,
3387                     "", HFILL }},
3388
3389                 { &hf_sna_xid_3_pbn,
3390                 { "Peripheral Border Node",
3391                     "sna.xid.type3.pbn", FT_BOOLEAN, 8, NULL, 0x08,
3392                     "", HFILL }},
3393
3394                 { &hf_sna_xid_3_pacing,
3395                 { "Qualifier for adaptive BIND pacing support",
3396                     "sna.xid.type3.pacing", FT_UINT8, BASE_HEX, NULL, 0x03,
3397                     "", HFILL }},
3398
3399                 { &hf_sna_xid_3_11,
3400                 { "XID Type 3 Byte 11", "sna.xid.type3.11", FT_UINT8, BASE_HEX,
3401                     NULL, 0x0, "", HFILL }},
3402
3403                 { &hf_sna_xid_3_tgshare,
3404                 { "TG Sharing Prohibited Indicator",
3405                     "sna.xid.type3.tgshare", FT_BOOLEAN, 8, NULL, 0x40,
3406                     "", HFILL }},
3407
3408                 { &hf_sna_xid_3_dedsvc,
3409                 { "Dedicated SVC Idicator",
3410                     "sna.xid.type3.dedsvc", FT_BOOLEAN, 8, NULL, 0x20,
3411                     "", HFILL }},
3412
3413                 { &hf_sna_xid_3_12,
3414                 { "XID Type 3 Byte 12", "sna.xid.type3.12", FT_UINT8, BASE_HEX,
3415                     NULL, 0x0, "", HFILL }},
3416
3417                 { &hf_sna_xid_3_negcsup,
3418                 { "Negotiation Complete Supported",
3419                     "sna.xid.type3.negcsup", FT_BOOLEAN, 8, NULL, 0x80,
3420                     "", HFILL }},
3421
3422                 { &hf_sna_xid_3_negcomp,
3423                 { "Negotiation Complete",
3424                     "sna.xid.type3.negcomp", FT_BOOLEAN, 8, NULL, 0x40,
3425                     "", HFILL }},
3426
3427                 { &hf_sna_xid_3_15,
3428                 { "XID Type 3 Byte 15", "sna.xid.type3.15", FT_UINT8, BASE_HEX,
3429                     NULL, 0x0, "", HFILL }},
3430
3431                 { &hf_sna_xid_3_partg,
3432                 { "Parallel TG Support",
3433                     "sna.xid.type3.partg", FT_BOOLEAN, 8, NULL, 0x80,
3434                     "", HFILL }},
3435
3436                 { &hf_sna_xid_3_dlur,
3437                 { "Dependent LU Requester Indicator",
3438                     "sna.xid.type3.dlur", FT_BOOLEAN, 8, NULL, 0x40,
3439                     "", HFILL }},
3440
3441                 { &hf_sna_xid_3_dlus,
3442                 { "DLUS Served LU Registration Indicator",
3443                     "sna.xid.type3.dlus", FT_BOOLEAN, 8, NULL, 0x20,
3444                     "", HFILL }},
3445
3446                 { &hf_sna_xid_3_exbn,
3447                 { "Extended HPR Border Node",
3448                     "sna.xid.type3.exbn", FT_BOOLEAN, 8, NULL, 0x10,
3449                     "", HFILL }},
3450
3451                 { &hf_sna_xid_3_genodai,
3452                 { "Generalized ODAI Usage Option",
3453                     "sna.xid.type3.genodai", FT_BOOLEAN, 8, NULL, 0x08,
3454                     "", HFILL }},
3455
3456                 { &hf_sna_xid_3_branch,
3457                 { "Branch Indicator", "sna.xid.type3.branch",
3458                     FT_UINT8, BASE_HEX, VALS(sna_xid_3_branch_vals),
3459                     0x06, "", HFILL }},
3460
3461                 { &hf_sna_xid_3_brnn,
3462                 { "Option Set 1123 Indicator",
3463                     "sna.xid.type3.brnn", FT_BOOLEAN, 8, NULL, 0x01,
3464                     "", HFILL }},
3465
3466                 { &hf_sna_xid_3_tg,
3467                 { "XID TG", "sna.xid.type3.tg", FT_UINT8, BASE_HEX, NULL, 0x0,
3468                     "", HFILL }},
3469
3470                 { &hf_sna_xid_3_dlc,
3471                 { "XID DLC", "sna.xid.type3.dlc", FT_UINT8, BASE_HEX, NULL, 0x0,
3472                     "", HFILL }},
3473
3474                 { &hf_sna_xid_3_dlen,
3475                 { "DLC Dependent Section Length", "sna.xid.type3.dlen",
3476                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3477
3478                 { &hf_sna_control_len,
3479                 { "Control Vector Length", "sna.control.len",
3480                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3481
3482                 { &hf_sna_control_key,
3483                 { "Control Vector Key", "sna.control.key",
3484                     FT_UINT8, BASE_HEX, VALS(sna_control_vals), 0x0, "",
3485                     HFILL }},
3486
3487                 { &hf_sna_control_hprkey,
3488                 { "Control Vector HPR Key", "sna.control.hprkey",
3489                     FT_UINT8, BASE_HEX, VALS(sna_control_hpr_vals), 0x0, "",
3490                     HFILL }},
3491         
3492                 { &hf_sna_control_05_delay,
3493                 { "Channel Delay", "sna.control.05.delay",
3494                     FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3495         
3496                 { &hf_sna_control_05_type,
3497                 { "Network Address Type", "sna.control.05.type",
3498                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3499         
3500                 { &hf_sna_control_05_ptp,
3501                 { "Point-to-point", "sna.control.05.ptp",
3502                     FT_BOOLEAN, 8, NULL, 0x80, "", HFILL }},
3503         
3504                 { &hf_sna_control_0e_type,
3505                 { "Type", "sna.control.0e.type",
3506                     FT_UINT8, BASE_HEX, VALS(sna_control_0e_type_vals),
3507                     0, "", HFILL }},
3508         
3509                 { &hf_sna_control_0e_value,
3510                 { "Value", "sna.control.0e.value",
3511                     FT_STRING, BASE_NONE, NULL, 0, "", HFILL }},
3512         };
3513         static gint *ett[] = {
3514                 &ett_sna,
3515                 &ett_sna_th,
3516                 &ett_sna_th_fid,
3517                 &ett_sna_nlp_nhdr,
3518                 &ett_sna_nlp_nhdr_0,
3519                 &ett_sna_nlp_nhdr_1,
3520                 &ett_sna_nlp_thdr,
3521                 &ett_sna_nlp_thdr_8,
3522                 &ett_sna_nlp_thdr_9,
3523                 &ett_sna_nlp_opti_un,
3524                 &ett_sna_nlp_opti_0d,
3525                 &ett_sna_nlp_opti_0d_4,
3526                 &ett_sna_nlp_opti_0e,
3527                 &ett_sna_nlp_opti_0e_stat,
3528                 &ett_sna_nlp_opti_0e_absp,
3529                 &ett_sna_nlp_opti_0f,
3530                 &ett_sna_nlp_opti_10,
3531                 &ett_sna_nlp_opti_12,
3532                 &ett_sna_nlp_opti_14,
3533                 &ett_sna_nlp_opti_14_si,
3534                 &ett_sna_nlp_opti_14_si_2,
3535                 &ett_sna_nlp_opti_14_rr,
3536                 &ett_sna_nlp_opti_14_rr_2,
3537                 &ett_sna_nlp_opti_22,
3538                 &ett_sna_nlp_opti_22_2,
3539                 &ett_sna_nlp_opti_22_3,
3540                 &ett_sna_rh,
3541                 &ett_sna_rh_0,
3542                 &ett_sna_rh_1,
3543                 &ett_sna_rh_2,
3544                 &ett_sna_gds,
3545                 &ett_sna_xid_0,
3546                 &ett_sna_xid_id,
3547                 &ett_sna_xid_3_8,
3548                 &ett_sna_xid_3_10,
3549                 &ett_sna_xid_3_11,
3550                 &ett_sna_xid_3_12,
3551                 &ett_sna_xid_3_15,
3552                 &ett_sna_control_un,
3553                 &ett_sna_control_05,
3554                 &ett_sna_control_05hpr,
3555                 &ett_sna_control_05hpr_type,
3556                 &ett_sna_control_0e,
3557         };
3558         module_t *sna_module;
3559
3560         proto_sna = proto_register_protocol("Systems Network Architecture",
3561             "SNA", "sna");
3562         proto_register_field_array(proto_sna, hf, array_length(hf));
3563         proto_register_subtree_array(ett, array_length(ett));
3564         register_dissector("sna", dissect_sna, proto_sna);
3565
3566         proto_sna_xid = proto_register_protocol(
3567             "Systems Network Architecture XID", "SNA XID", "sna_xid");
3568         register_dissector("sna_xid", dissect_sna_xid, proto_sna_xid);
3569
3570         /* Register configuration options */
3571         sna_module = prefs_register_protocol(proto_sna, NULL);
3572         prefs_register_bool_preference(sna_module, "defragment",
3573                 "Reassemble fragmented BIUs",
3574                 "Whether fragmented BIUs should be reassembled",
3575                 &sna_defragment);
3576 }
3577
3578 void
3579 proto_reg_handoff_sna(void)
3580 {
3581         dissector_handle_t sna_handle;
3582         dissector_handle_t sna_xid_handle;
3583
3584         sna_handle = find_dissector("sna");
3585         sna_xid_handle = find_dissector("sna_xid");
3586         dissector_add("llc.dsap", SAP_SNA_PATHCTRL, sna_handle);
3587         dissector_add("llc.dsap", SAP_SNA1, sna_handle);
3588         dissector_add("llc.dsap", SAP_SNA2, sna_handle);
3589         dissector_add("llc.dsap", SAP_SNA3, sna_handle);
3590         dissector_add("llc.xid_dsap", SAP_SNA_PATHCTRL, sna_xid_handle);
3591         dissector_add("llc.xid_dsap", SAP_SNA1, sna_xid_handle);
3592         dissector_add("llc.xid_dsap", SAP_SNA2, sna_xid_handle);
3593         dissector_add("llc.xid_dsap", SAP_SNA3, sna_xid_handle);
3594         /* RFC 2043 */
3595         dissector_add("ppp.protocol", PPP_SNA, sna_handle);
3596         data_handle = find_dissector("data");
3597
3598         register_init_routine(sna_init);
3599 }