ec6f18153bf6e96a71b2bf02a20f370262d0b433
[obnox/wireshark/wip.git] / 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: packet-sna.c,v 1.48 2003/07/18 05:12:13 guy Exp $
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 "llcsaps.h"
34 #include "ppptypes.h"
35 #include <epan/sna-utils.h>
36 #include "prefs.h"
37 #include "reassemble.h"
38 #include "util.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*, 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_new_subset(tvb, offset, len, -1),
853                             tree, 1, LT);
854                         pad = (len+3) & 0xfffc;
855                         if (pad > len)
856                                 proto_tree_add_text(tree, tvb, offset+len,
857                                     pad-len, "Padding");
858                         offset += pad;
859                 } else {
860                         /* Avoid endless loop */
861                         return;
862                 }
863         }
864 }
865
866 static void
867 dissect_optional_0e(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
868 {
869         int             bits, offset;
870         proto_tree      *sub_tree;
871         proto_item      *sub_ti = NULL;
872
873         bits = tvb_get_guint8(tvb, 2);
874         offset = 20;
875
876         if (tree) {
877                 sub_ti = proto_tree_add_item(tree, hf_sna_nlp_opti_0e_stat,
878                     tvb, 2, 1, FALSE);
879                 sub_tree = proto_item_add_subtree(sub_ti, 
880                     ett_sna_nlp_opti_0e_stat);
881
882                 proto_tree_add_boolean(sub_tree, hf_sna_nlp_opti_0e_gap,
883                     tvb, 2, 1, bits);
884                 proto_tree_add_boolean(sub_tree, hf_sna_nlp_opti_0e_idle,
885                     tvb, 2, 1, bits);
886                 proto_tree_add_item(tree, hf_sna_nlp_opti_0e_nabsp,
887                     tvb, 3, 1, FALSE);
888                 proto_tree_add_item(tree, hf_sna_nlp_opti_0e_sync,
889                     tvb, 4, 2, FALSE);
890                 proto_tree_add_item(tree, hf_sna_nlp_opti_0e_echo,
891                     tvb, 6, 2, FALSE);
892                 proto_tree_add_item(tree, hf_sna_nlp_opti_0e_rseq,
893                     tvb, 8, 4, FALSE);
894                 proto_tree_add_text(tree, tvb, 12, 8, "Reserved");
895
896                 if (tvb_offset_exists(tvb, offset))
897                         call_dissector(data_handle,
898                             tvb_new_subset(tvb, 4, -1, -1), pinfo, tree);
899         }
900         if (bits & 0x40) {
901                 if (check_col(pinfo->cinfo, COL_INFO))
902                         col_add_str(pinfo->cinfo, COL_INFO,
903                             "HPR Idle Message");
904         } else {
905                 if (check_col(pinfo->cinfo, COL_INFO))
906                         col_add_str(pinfo->cinfo, COL_INFO,
907                             "HPR Status Message");
908         }
909 }
910
911 static void
912 dissect_optional_0f(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
913 {
914         if (!tree)
915                 return;
916
917         proto_tree_add_item(tree, hf_sna_nlp_opti_0f_bits, tvb, 2, 2, FALSE);
918         if (tvb_offset_exists(tvb, 4))
919                 call_dissector(data_handle,
920                     tvb_new_subset(tvb, 4, -1, -1), pinfo, tree);
921 }
922
923 static void
924 dissect_optional_10(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
925 {
926         if (!tree)
927                 return;
928
929         proto_tree_add_text(tree, tvb, 2, 2, "Reserved");
930         proto_tree_add_item(tree, hf_sna_nlp_opti_10_tcid, tvb, 4, 8, FALSE);
931         if (tvb_offset_exists(tvb, 12))
932                 call_dissector(data_handle,
933                     tvb_new_subset(tvb, 12, -1, -1), pinfo, tree);
934 }
935
936 static void
937 dissect_optional_12(tvbuff_t *tvb, proto_tree *tree)
938 {
939         if (!tree)
940                 return;
941
942         proto_tree_add_text(tree, tvb, 2, 2, "Reserved");
943         proto_tree_add_item(tree, hf_sna_nlp_opti_12_sense, tvb, 4, -1, FALSE);
944 }
945
946 static void
947 dissect_optional_14(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
948 {
949         proto_tree      *sub_tree, *bf_tree;
950         proto_item      *sub_item, *bf_item;
951         int             len, pad, type, bits, offset, num, sublen;
952
953         if (!tree)
954                 return;
955
956         proto_tree_add_text(tree, tvb, 2, 2, "Reserved");
957
958         offset = 4;
959
960         len = tvb_get_guint8(tvb, offset);
961         type = tvb_get_guint8(tvb, offset+1);
962
963         if ((type != 0x83) || (len <= 16)) {
964                 /* Invalid */
965                 call_dissector(data_handle,
966                     tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
967                 return;
968         }
969         sub_item = proto_tree_add_text(tree, tvb, offset, len,
970             "Switching Information Control Vector");
971         sub_tree = proto_item_add_subtree(sub_item, ett_sna_nlp_opti_14_si);
972
973         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_si_len,
974             tvb, offset, 1, len);
975         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_si_key,
976             tvb, offset+1, 1, type);
977         
978         bits = tvb_get_guint8(tvb, offset+2);
979         bf_item = proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_si_2,
980             tvb, offset+2, 1, bits);
981         bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_opti_14_si_2);
982
983         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_refifo,
984             tvb, offset+2, 1, bits);
985         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_mobility,
986             tvb, offset+2, 1, bits);
987         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_dirsearch,
988             tvb, offset+2, 1, bits);
989         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_limitres,
990             tvb, offset+2, 1, bits);
991         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_ncescope,
992             tvb, offset+2, 1, bits);
993         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_si_mnpsrscv,
994             tvb, offset+2, 1, bits);
995
996         proto_tree_add_text(sub_tree, tvb, offset+3, 1, "Reserved");
997         proto_tree_add_item(sub_tree, hf_sna_nlp_opti_14_si_maxpsize,
998             tvb, offset+4, 4, FALSE);
999         proto_tree_add_item(sub_tree, hf_sna_nlp_opti_14_si_switch,
1000             tvb, offset+8, 4, FALSE);
1001         proto_tree_add_item(sub_tree, hf_sna_nlp_opti_14_si_alive,
1002             tvb, offset+12, 4, FALSE);
1003
1004         dissect_control(tvb_new_subset(tvb, offset+16,
1005                             len-16, -1), sub_tree, 1, LT);
1006
1007         pad = (len+3) & 0xfffc;
1008         if (pad > len)
1009                 proto_tree_add_text(sub_tree, tvb, offset+len, pad-len,
1010                     "Padding");
1011         offset += pad;
1012
1013         len = tvb_get_guint8(tvb, offset);
1014         type = tvb_get_guint8(tvb, offset+1);
1015
1016         if ((type != 0x85) || ( len < 4))  {
1017                 /* Invalid */
1018                 call_dissector(data_handle,
1019                     tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
1020                 return;
1021         }
1022         sub_item = proto_tree_add_text(tree, tvb, offset, len,
1023             "Return Route TG Descriptor Control Vector");
1024         sub_tree = proto_item_add_subtree(sub_item, ett_sna_nlp_opti_14_rr);
1025
1026         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_rr_len,
1027             tvb, offset, 1, len);
1028         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_rr_key,
1029             tvb, offset+1, 1, type);
1030         
1031         bits = tvb_get_guint8(tvb, offset+2);
1032         bf_item = proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_rr_2,
1033             tvb, offset+2, 1, bits);
1034         bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_opti_14_rr_2);
1035
1036         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_14_rr_bfe,
1037             tvb, offset+2, 1, bits);
1038
1039         num = tvb_get_guint8(tvb, offset+3);
1040
1041         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_14_rr_num,
1042             tvb, offset+3, 1, num);
1043
1044         offset += 4;
1045
1046         while (num) {
1047                 sublen = tvb_get_guint8(tvb, offset);
1048                 if (sublen) {
1049                         dissect_control(tvb_new_subset(tvb, offset,
1050                             sublen, -1), sub_tree, 1, LT);
1051                 } else {
1052                         /* Invalid */
1053                         call_dissector(data_handle,
1054                             tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
1055                         return;
1056                 }
1057                 /* No padding here */
1058                 offset += sublen;
1059                 num--;
1060         }
1061 }
1062
1063 static void
1064 dissect_optional_22(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1065 {
1066         proto_tree      *bf_tree;
1067         proto_item      *bf_item;
1068         int             bits, type;
1069
1070         if (!tree)
1071                 return;
1072
1073         bits = tvb_get_guint8(tvb, 2);
1074         type = (bits & 0xc0) >> 6;
1075
1076         bf_item = proto_tree_add_uint(tree, hf_sna_nlp_opti_22_2,
1077             tvb, 2, 1, bits);
1078         bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_opti_22_2);
1079
1080         proto_tree_add_uint(bf_tree, hf_sna_nlp_opti_22_type,
1081             tvb, 2, 1, bits);
1082         proto_tree_add_uint(bf_tree, hf_sna_nlp_opti_22_raa,
1083             tvb, 2, 1, bits);
1084         proto_tree_add_boolean(bf_tree, hf_sna_nlp_opti_22_parity,
1085             tvb, 2, 1, bits);
1086         proto_tree_add_uint(bf_tree, hf_sna_nlp_opti_22_arb,
1087             tvb, 2, 1, bits);
1088
1089         bits = tvb_get_guint8(tvb, 3);
1090
1091         bf_item = proto_tree_add_uint(tree, hf_sna_nlp_opti_22_3,
1092             tvb, 3, 1, bits);
1093         bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_opti_22_3);
1094
1095         proto_tree_add_uint(bf_tree, hf_sna_nlp_opti_22_ratereq,
1096             tvb, 3, 1, bits);
1097         proto_tree_add_uint(bf_tree, hf_sna_nlp_opti_22_raterep,
1098             tvb, 3, 1, bits);
1099
1100         proto_tree_add_item(tree, hf_sna_nlp_opti_22_field1,
1101             tvb, 4, 4, FALSE);
1102         proto_tree_add_item(tree, hf_sna_nlp_opti_22_field2,
1103             tvb, 8, 4, FALSE);
1104
1105         if (type == 0) {
1106                 proto_tree_add_item(tree, hf_sna_nlp_opti_22_field3,
1107                     tvb, 12, 4, FALSE);
1108                 proto_tree_add_item(tree, hf_sna_nlp_opti_22_field4,
1109                     tvb, 16, 4, FALSE);
1110
1111                 if (tvb_offset_exists(tvb, 20))
1112                         call_dissector(data_handle,
1113                             tvb_new_subset(tvb, 20, -1, -1), pinfo, tree);
1114         } else {
1115                 if (tvb_offset_exists(tvb, 12))
1116                         call_dissector(data_handle,
1117                             tvb_new_subset(tvb, 12, -1, -1), pinfo, tree);
1118         }
1119 }
1120
1121 static void
1122 dissect_optional(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1123 {
1124         proto_tree      *sub_tree;
1125         proto_item      *sub_item;
1126         int             offset, type, len;
1127         gint            ett;
1128
1129         sub_tree = NULL;
1130
1131         offset = 0;
1132
1133         while (tvb_offset_exists(tvb, offset)) {
1134                 len = tvb_get_guint8(tvb, offset);
1135                 type = tvb_get_guint8(tvb, offset+1);
1136
1137                 /* Prevent loop for invalid crap in packet */
1138                 if (len == 0) {
1139                         if (tree)
1140                                 call_dissector(data_handle,
1141                                     tvb_new_subset(tvb, offset,
1142                                     -1, -1), pinfo, tree);
1143                         return;
1144                 }
1145                         
1146                 ett = ett_sna_nlp_opti_un;
1147                 if(type == 0x0d) ett = ett_sna_nlp_opti_0d;
1148                 if(type == 0x0e) ett = ett_sna_nlp_opti_0e;
1149                 if(type == 0x0f) ett = ett_sna_nlp_opti_0f;
1150                 if(type == 0x10) ett = ett_sna_nlp_opti_10;
1151                 if(type == 0x12) ett = ett_sna_nlp_opti_12;
1152                 if(type == 0x14) ett = ett_sna_nlp_opti_14;
1153                 if(type == 0x22) ett = ett_sna_nlp_opti_22;
1154                 if (tree) {
1155                         sub_item = proto_tree_add_text(tree, tvb,
1156                             offset, len << 2,
1157                             val_to_str(type, sna_nlp_opti_vals,
1158                             "Unknown Segment Type"));
1159                         sub_tree = proto_item_add_subtree(sub_item, ett);
1160                         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_len,
1161                             tvb, offset, 1, len);
1162                         proto_tree_add_uint(sub_tree, hf_sna_nlp_opti_type,
1163                             tvb, offset+1, 1, type);
1164                 }
1165                 switch(type) {
1166                         case 0x0d:
1167                                 dissect_optional_0d(tvb_new_subset(tvb, offset,
1168                                     len << 2, -1), sub_tree);
1169                                 break;
1170                         case 0x0e:
1171                                 dissect_optional_0e(tvb_new_subset(tvb, offset,
1172                                     len << 2, -1), pinfo, sub_tree);
1173                                 break;
1174                         case 0x0f:
1175                                 dissect_optional_0f(tvb_new_subset(tvb, offset,
1176                                     len << 2, -1), pinfo, sub_tree);
1177                                 break;
1178                         case 0x10:
1179                                 dissect_optional_10(tvb_new_subset(tvb, offset,
1180                                     len << 2, -1), pinfo, sub_tree);
1181                                 break;
1182                         case 0x12:
1183                                 dissect_optional_12(tvb_new_subset(tvb, offset,
1184                                     len << 2, -1), sub_tree);
1185                                 break;
1186                         case 0x14:
1187                                 dissect_optional_14(tvb_new_subset(tvb, offset,
1188                                     len << 2, -1), pinfo, sub_tree);
1189                                 break;
1190                         case 0x22:
1191                                 dissect_optional_22(tvb_new_subset(tvb, offset,
1192                                     len << 2, -1), pinfo, sub_tree);
1193                                 break;
1194                         default:
1195                                 call_dissector(data_handle,
1196                                     tvb_new_subset(tvb, offset,
1197                                     len << 2, -1), pinfo, sub_tree);
1198                 }
1199                 offset += (len << 2);
1200         }
1201 }
1202
1203 static void
1204 dissect_nlp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
1205     proto_tree *parent_tree)
1206 {
1207         proto_tree      *nlp_tree, *bf_tree;
1208         proto_item      *nlp_item, *bf_item, *h_item;
1209         guint8          nhdr_0, nhdr_1, nhdr_x, thdr_8, thdr_9, fid;
1210         guint32         thdr_len, thdr_dlf;
1211         guint16         subindex;
1212
1213         int index = 0, counter = 0;
1214
1215         nlp_tree = NULL;
1216         nlp_item = NULL;
1217
1218         nhdr_0 = tvb_get_guint8(tvb, index);
1219         nhdr_1 = tvb_get_guint8(tvb, index+1);
1220
1221         if (check_col(pinfo->cinfo, COL_INFO))
1222                 col_add_str(pinfo->cinfo, COL_INFO, "HPR NLP Packet");
1223
1224         if (tree) {
1225                 /* Don't bother setting length. We'll set it later after we
1226                  * find the lengths of NHDR */
1227                 nlp_item = proto_tree_add_item(tree, hf_sna_nlp_nhdr, tvb,
1228                     index, -1, FALSE);
1229                 nlp_tree = proto_item_add_subtree(nlp_item, ett_sna_nlp_nhdr);
1230
1231                 bf_item = proto_tree_add_uint(nlp_tree, hf_sna_nlp_nhdr_0, tvb,
1232                     index, 1, nhdr_0);
1233                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_nhdr_0);
1234
1235                 proto_tree_add_uint(bf_tree, hf_sna_nlp_sm, tvb, index, 1,
1236                     nhdr_0);
1237                 proto_tree_add_uint(bf_tree, hf_sna_nlp_tpf, tvb, index, 1,
1238                     nhdr_0);
1239
1240                 bf_item = proto_tree_add_uint(nlp_tree, hf_sna_nlp_nhdr_1, tvb,
1241                     index+1, 1, nhdr_1);
1242                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_nhdr_1);
1243
1244                 proto_tree_add_uint(bf_tree, hf_sna_nlp_ft, tvb,
1245                     index+1, 1, nhdr_1);
1246                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_tspi, tvb,
1247                     index+1, 1, nhdr_1);
1248                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_slowdn1, tvb,
1249                     index+1, 1, nhdr_1);
1250                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_slowdn2, tvb,
1251                     index+1, 1, nhdr_1);
1252         }
1253         /* ANR or FR lists */
1254
1255         index += 2;
1256         counter = 0;
1257
1258         if ((nhdr_0 & 0xe0) == 0xa0) {
1259                 do {
1260                         nhdr_x = tvb_get_guint8(tvb, index + counter);
1261                         counter ++;
1262                 } while (nhdr_x != 0xff);
1263                 if (tree)
1264                         h_item = proto_tree_add_item(nlp_tree, 
1265                             hf_sna_nlp_fra, tvb, index, counter, FALSE);
1266                 index += counter;
1267                 if (tree)
1268                         proto_tree_add_text(nlp_tree, tvb, index, 1,
1269                             "Reserved");
1270                 index++;
1271
1272                 if (tree)
1273                         proto_item_set_len(nlp_item, index);
1274
1275                 if ((nhdr_1 & 0xf0) == 0x10) {
1276                         nhdr_x = tvb_get_guint8(tvb, index);
1277                         if (tree)
1278                                 proto_tree_add_uint(tree, hf_sna_nlp_frh, 
1279                                     tvb, index, 1, nhdr_x);
1280                         index ++;
1281
1282                         if (tvb_offset_exists(tvb, index))
1283                                 call_dissector(data_handle,
1284                                         tvb_new_subset(tvb, index, -1, -1),
1285                                         pinfo, parent_tree);
1286                         return;
1287                 }
1288         }
1289         if ((nhdr_0 & 0xe0) == 0xc0) {
1290                 do {
1291                         nhdr_x = tvb_get_guint8(tvb, index + counter);
1292                         counter ++;
1293                 } while (nhdr_x != 0xff);
1294                 if (tree)
1295                         h_item = proto_tree_add_item(nlp_tree, hf_sna_nlp_anr, 
1296                             tvb, index, counter, FALSE);
1297                 index += counter;
1298
1299                 if (tree)
1300                         proto_tree_add_text(nlp_tree, tvb, index, 1,
1301                             "Reserved");
1302                 index++;
1303
1304                 if (tree)
1305                         proto_item_set_len(nlp_item, index);
1306         }
1307
1308         thdr_8 = tvb_get_guint8(tvb, index+8);
1309         thdr_9 = tvb_get_guint8(tvb, index+9);
1310         thdr_len = tvb_get_ntohs(tvb, index+10);
1311         thdr_dlf = tvb_get_ntohl(tvb, index+12);
1312
1313         if (tree) {
1314                 nlp_item = proto_tree_add_item(tree, hf_sna_nlp_thdr, tvb, 
1315                     index, thdr_len << 2, FALSE);
1316                 nlp_tree = proto_item_add_subtree(nlp_item, ett_sna_nlp_thdr);
1317
1318                 proto_tree_add_item(nlp_tree, hf_sna_nlp_tcid, tvb,
1319                     index, 8, FALSE);
1320                 bf_item = proto_tree_add_uint(nlp_tree, hf_sna_nlp_thdr_8, tvb,
1321                     index+8, 1, thdr_8);
1322                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_thdr_8);
1323
1324                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_setupi, tvb,
1325                     index+8, 1, thdr_8);
1326                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_somi, tvb, index+8,
1327                     1, thdr_8);
1328                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_eomi, tvb, index+8,
1329                     1, thdr_8);
1330                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_sri, tvb, index+8,
1331                     1, thdr_8);
1332                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_rasapi, tvb,
1333                     index+8, 1, thdr_8);
1334                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_retryi, tvb,
1335                     index+8, 1, thdr_8);
1336
1337                 bf_item = proto_tree_add_uint(nlp_tree, hf_sna_nlp_thdr_9, tvb,
1338                     index+9, 1, thdr_9);
1339                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_nlp_thdr_9);
1340
1341                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_lmi, tvb, index+9,
1342                     1, thdr_9);
1343                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_cqfi, tvb, index+9,
1344                     1, thdr_9);
1345                 proto_tree_add_boolean(bf_tree, hf_sna_nlp_osi, tvb, index+9,
1346                     1, thdr_9);
1347
1348                 proto_tree_add_uint(nlp_tree, hf_sna_nlp_offset, tvb, index+10,
1349                     2, thdr_len);
1350                 proto_tree_add_uint(nlp_tree, hf_sna_nlp_dlf, tvb, index+12,
1351                     4, thdr_dlf);
1352                 proto_tree_add_item(nlp_tree, hf_sna_nlp_bsn, tvb, index+16,
1353                     4, FALSE);
1354         }
1355         subindex = 20;
1356
1357         if (((thdr_9 & 0x18) == 0x08) && ((thdr_len << 2) > subindex)) {
1358                 counter = tvb_get_guint8(tvb, index + subindex);
1359                 if (tvb_get_guint8(tvb, index+subindex+1) == 5)
1360                         dissect_control(
1361                             tvb_new_subset(tvb, index + subindex,
1362                             counter+2, -1), nlp_tree, 1, LT);
1363                 else
1364                         call_dissector(data_handle,
1365                             tvb_new_subset(tvb, index + subindex, counter+2,
1366                             -1), pinfo, nlp_tree);
1367
1368                 subindex += (counter+2);
1369         }
1370         if ((thdr_9 & 0x04) && ((thdr_len << 2) > subindex))
1371                 dissect_optional(
1372                     tvb_new_subset(tvb, index + subindex,
1373                     (thdr_len << 2) - subindex, -1),
1374                     pinfo, nlp_tree);
1375
1376         index += (thdr_len << 2);
1377         if (((thdr_8 & 0x20) == 0) && thdr_dlf) {
1378                 if (check_col(pinfo->cinfo, COL_INFO))
1379                         col_add_str(pinfo->cinfo, COL_INFO, "HPR Fragment");
1380                 if (tvb_offset_exists(tvb, index)) {
1381                         call_dissector(data_handle,
1382                             tvb_new_subset(tvb, index, -1, -1), pinfo,
1383                             parent_tree);
1384                 }
1385                 return;
1386         }
1387         if (tvb_offset_exists(tvb, index)) {
1388                 /* Transmission Header Format Identifier */
1389                 fid = hi_nibble(tvb_get_guint8(tvb, index));
1390                 if (fid == 5) /* Only FID5 allowed for HPR */
1391                         dissect_fid(tvb_new_subset(tvb, index, -1, -1), pinfo,
1392                             tree, parent_tree);
1393                 else {
1394                         if (tvb_get_ntohs(tvb, index+2) == 0x12ce) {
1395                                 /* Route Setup */
1396                                 if (check_col(pinfo->cinfo, COL_INFO))
1397                                         col_add_str(pinfo->cinfo, COL_INFO,
1398                                             "HPR Route Setup");
1399                                 dissect_gds(tvb_new_subset(tvb, index, -1, -1),
1400                                     pinfo, tree, parent_tree);
1401                         } else
1402                                 call_dissector(data_handle, 
1403                                     tvb_new_subset(tvb, index, -1, -1),
1404                                     pinfo, parent_tree);
1405                 }
1406         }
1407 }
1408
1409 /* --------------------------------------------------------------------
1410  * Chapter 3 Exchange Identification (XID) Information Fields
1411  * --------------------------------------------------------------------
1412  */
1413
1414 static void
1415 dissect_xid1(tvbuff_t *tvb, proto_tree *tree)
1416 {
1417         if (!tree)
1418                 return;
1419
1420         proto_tree_add_text(tree, tvb, 0, 2, "Reserved");
1421
1422 }
1423
1424 static void
1425 dissect_xid2(tvbuff_t *tvb, proto_tree *tree)
1426 {
1427         guint           dlen, offset;
1428
1429         if (!tree)
1430                 return;
1431
1432         dlen = tvb_get_guint8(tvb, 0);
1433
1434         offset = dlen;
1435
1436         while (tvb_offset_exists(tvb, offset)) {
1437                 dlen = tvb_get_guint8(tvb, offset+1);
1438                 dissect_control(tvb_new_subset(tvb, offset, dlen+2, -1),
1439                     tree, 0, KL);
1440                 offset += (dlen + 2);
1441         }
1442 }
1443
1444 static void
1445 dissect_xid3(tvbuff_t *tvb, proto_tree *tree)
1446 {
1447         proto_tree      *sub_tree;
1448         proto_item      *sub_ti = NULL;
1449         guint           val, dlen, offset;
1450
1451         if (!tree)
1452                 return;
1453
1454         proto_tree_add_text(tree, tvb, 0, 2, "Reserved");
1455
1456         val = tvb_get_ntohs(tvb, 2);
1457
1458         sub_ti = proto_tree_add_uint(tree, hf_sna_xid_3_8, tvb,
1459             2, 2, val);
1460         sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_3_8);
1461
1462         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_init_self, tvb, 2, 2,
1463             val);
1464         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_stand_bind, tvb, 2, 2,
1465             val);
1466         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_gener_bind, tvb, 2, 2,
1467             val);
1468         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_recve_bind, tvb, 2, 2,
1469             val);
1470         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_actpu, tvb, 2, 2, val);
1471         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_nwnode, tvb, 2, 2, val);
1472         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_cp, tvb, 2, 2, val);
1473         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_cpcp, tvb, 2, 2, val);
1474         proto_tree_add_uint(sub_tree, hf_sna_xid_3_state, tvb, 2, 2, val);
1475         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_nonact, tvb, 2, 2, val);
1476         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_cpchange, tvb, 2, 2,
1477             val);
1478
1479         val = tvb_get_guint8(tvb, 4);
1480
1481         sub_ti = proto_tree_add_uint(tree, hf_sna_xid_3_10, tvb,
1482             4, 1, val);
1483         sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_3_10);
1484
1485         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_asend_bind, tvb, 4, 1,
1486             val);
1487         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_arecv_bind, tvb, 4, 1,
1488             val);
1489         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_quiesce, tvb, 4, 1, val);
1490         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_pucap, tvb, 4, 1, val);
1491         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_pbn, tvb, 4, 1, val);
1492         proto_tree_add_uint(sub_tree, hf_sna_xid_3_pacing, tvb, 4, 1, val);
1493
1494         val = tvb_get_guint8(tvb, 5);
1495
1496         sub_ti = proto_tree_add_uint(tree, hf_sna_xid_3_11, tvb,
1497             5, 1, val);
1498         sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_3_11);
1499
1500         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_tgshare, tvb, 5, 1, val);
1501         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_dedsvc, tvb, 5, 1, val);
1502
1503         val = tvb_get_guint8(tvb, 6);
1504
1505         sub_ti = proto_tree_add_item(tree, hf_sna_xid_3_12, tvb,
1506             6, 1, FALSE);
1507         sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_3_12);
1508
1509         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_negcsup, tvb, 6, 1, val);
1510         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_negcomp, tvb, 6, 1, val);
1511
1512         proto_tree_add_text(tree, tvb, 7, 2, "Reserved");
1513
1514         val = tvb_get_guint8(tvb, 9);
1515
1516         sub_ti = proto_tree_add_item(tree, hf_sna_xid_3_15, tvb,
1517             9, 1, FALSE);
1518         sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_3_15);
1519
1520         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_partg, tvb, 9, 1, val);
1521         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_dlur, tvb, 9, 1, val);
1522         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_dlus, tvb, 9, 1, val);
1523         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_exbn, tvb, 9, 1, val);
1524         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_genodai, tvb, 9, 1, val);
1525         proto_tree_add_uint(sub_tree, hf_sna_xid_3_branch, tvb, 9, 1, val);
1526         proto_tree_add_boolean(sub_tree, hf_sna_xid_3_brnn, tvb, 9, 1, val);
1527
1528         proto_tree_add_item(tree, hf_sna_xid_3_tg, tvb, 10, 1, FALSE);
1529         proto_tree_add_item(tree, hf_sna_xid_3_dlc, tvb, 11, 1, FALSE);
1530
1531         dlen = tvb_get_guint8(tvb, 12);
1532
1533         proto_tree_add_uint(tree, hf_sna_xid_3_dlen, tvb, 12, 1, dlen);
1534
1535         /* FIXME: DLC Dependent Data Go Here */
1536
1537         offset = 12 + dlen;
1538
1539         while (tvb_offset_exists(tvb, offset)) {
1540                 dlen = tvb_get_guint8(tvb, offset+1);
1541                 dissect_control(tvb_new_subset(tvb, offset, dlen+2, -1),
1542                     tree, 0, KL);
1543                 offset += (dlen+2);
1544         }
1545 }
1546
1547 static void
1548 dissect_xid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
1549     proto_tree *parent_tree)
1550 {
1551         proto_tree      *sub_tree;
1552         proto_item      *sub_ti = NULL;
1553         int             format, type, len;
1554         guint32         id;
1555
1556         len = tvb_get_guint8(tvb, 1);
1557         type = tvb_get_guint8(tvb, 0);
1558         id = tvb_get_ntohl(tvb, 2);
1559         format = hi_nibble(type);
1560
1561         /* Summary information */
1562         if (check_col(pinfo->cinfo, COL_INFO))
1563                 col_add_fstr(pinfo->cinfo, COL_INFO,
1564                     "SNA XID Format:%d Type:%s", format,
1565                     val_to_str(lo_nibble(type), sna_xid_type_vals,
1566                     "Unknown Type"));
1567
1568         if (tree) {
1569                 sub_ti = proto_tree_add_item(tree, hf_sna_xid_0, tvb,
1570                     0, 1, FALSE);
1571                 sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_0);
1572
1573                 proto_tree_add_uint(sub_tree, hf_sna_xid_format, tvb, 0, 1,
1574                     type);
1575                 proto_tree_add_uint(sub_tree, hf_sna_xid_type, tvb, 0, 1,
1576                     type);
1577
1578                 proto_tree_add_uint(tree, hf_sna_xid_len, tvb, 1, 1, len);
1579
1580                 sub_ti = proto_tree_add_item(tree, hf_sna_xid_id, tvb,
1581                     2, 4, FALSE);
1582                 sub_tree = proto_item_add_subtree(sub_ti, ett_sna_xid_id);
1583
1584                 proto_tree_add_uint(sub_tree, hf_sna_xid_idblock, tvb, 2, 4,
1585                     id);
1586                 proto_tree_add_uint(sub_tree, hf_sna_xid_idnum, tvb, 2, 4,
1587                     id);
1588
1589                 switch(format) {
1590                         case 0:
1591                                 break;
1592                         case 1:
1593                                 dissect_xid1(tvb_new_subset(tvb, 6, len-6, -1),
1594                                     tree);
1595                                 break;
1596                         case 2:
1597                                 dissect_xid2(tvb_new_subset(tvb, 6, len-6, -1),
1598                                     tree);
1599                                 break;
1600                         case 3:
1601                                 dissect_xid3(tvb_new_subset(tvb, 6, len-6, -1),
1602                                     tree);
1603                                 break;
1604                         default:
1605                                 /* external standards organizations */
1606                                 call_dissector(data_handle,
1607                                     tvb_new_subset(tvb, 6, len-6, -1),
1608                                     pinfo, tree);
1609                 }
1610         }
1611
1612         if (format == 0)
1613                 len = 6;
1614
1615         if (tvb_offset_exists(tvb, len))
1616                 call_dissector(data_handle,
1617                     tvb_new_subset(tvb, len, -1, -1), pinfo, parent_tree);
1618 }
1619
1620 /* --------------------------------------------------------------------
1621  * Chapter 4 Transmission Headers (THs)
1622  * --------------------------------------------------------------------
1623  */
1624
1625 #define RH_LEN  3
1626
1627 static unsigned int
1628 mpf_value(guint8 th_byte)
1629 {
1630         return (th_byte & 0x0c) >> 2;
1631 }
1632
1633 #define FIRST_FRAG_NUMBER       0
1634 #define MIDDLE_FRAG_NUMBER      1
1635 #define LAST_FRAG_NUMBER        2
1636
1637 /* FID2 is defragged by sequence. The weird thing is that we have neither
1638  * absolute sequence numbers, nor byte offets. Other FIDs have byte offsets
1639  * (the DCF field), but not FID2. The only thing we have to go with is "FIRST",
1640  * "MIDDLE", or "LAST". If the BIU is split into 3 frames, then everything is
1641  * fine, * "FIRST", "MIDDLE", and "LAST" map nicely onto frag-number 0, 1,
1642  * and 2. However, if the BIU is split into 2 frames, then we only have
1643  * "FIRST" and "LAST", and the mapping *should* be frag-number 0 and 1,
1644  * *NOT* 0 and 2.
1645  *
1646  * The SNA docs say "FID2 PIUs cannot be blocked because there is no DCF in the
1647  * TH format for deblocking" (note on Figure 4-2 in the IBM SNA documention,
1648  * see the FTP URL in the comment near the top of this file). I *think*
1649  * this means that the fragmented frames cannot arrive out of order.
1650  * Well, I *want* it to mean this, because w/o this limitation, if you
1651  * get a "FIRST" frame and a "LAST" frame, how long should you wait to
1652  * see if a "MIDDLE" frame every arrives????? Thus, if frames *have* to
1653  * arrive in order, then we're saved.
1654  *
1655  * The problem then boils down to figuring out if "LAST" means frag-number 1
1656  * (in the case of a BIU split into 2 frames) or frag-number 2
1657  * (in the case of a BIU split into 3 frames).
1658  *
1659  * Assuming fragmented FID2 BIU frames *do* arrive in order, the obvious
1660  * way to handle the mapping of "LAST" to either frag-number 1 or
1661  * frag-number 2 is to keep a hash which tracks the frames seen, etc.
1662  * This consumes resources. A trickier way, but a way which works, is to
1663  * always map the "LAST" BIU segment to frag-number 2. Here's the trickery:
1664  * if we add frag-number 2, which we know to be the "LAST" BIU segment,
1665  * and the reassembly code tells us that the the BIU is still not reassmebled,
1666  * then, owing to the, ahem, /fact/, that fragmented BIU segments arrive
1667  * in order :), we know that 1) "FIRST" did come, and 2) there's no "MIDDLE",
1668  * because this BIU was fragmented into 2 frames, not 3. So, we'll be
1669  * tricky and add a zero-length "MIDDLE" BIU frame (i.e, frag-number 1)
1670  * to complete the reassembly.
1671  */
1672 static tvbuff_t*
1673 defragment_by_sequence(packet_info *pinfo, tvbuff_t *tvb, int offset, int mpf,
1674     int id)
1675 {
1676         fragment_data *fd_head;
1677         int frag_number = -1;
1678         int more_frags = TRUE;
1679         tvbuff_t *rh_tvb = NULL;
1680         gint frag_len;
1681
1682         /* Determine frag_number and more_frags */
1683         switch(mpf) {
1684                 case MPF_WHOLE_BIU:
1685                         /* nothing */
1686                         break;
1687                 case MPF_FIRST_SEGMENT:
1688                         frag_number = FIRST_FRAG_NUMBER;
1689                         break;
1690                 case MPF_MIDDLE_SEGMENT:
1691                         frag_number = MIDDLE_FRAG_NUMBER;
1692                         break;
1693                 case MPF_LAST_SEGMENT:
1694                         frag_number = LAST_FRAG_NUMBER;
1695                         more_frags = FALSE;
1696                         break;
1697                 default:
1698                         g_assert_not_reached();
1699         }
1700
1701         /* If sna_defragment is on, and this is a fragment.. */
1702         if (frag_number > -1) {
1703                 /* XXX - check length ??? */
1704                 frag_len = tvb_reported_length_remaining(tvb, offset);
1705                 if (tvb_bytes_exist(tvb, offset, frag_len)) {
1706                         fd_head = fragment_add_seq(tvb, offset, pinfo, id,
1707                             sna_fragment_table, frag_number, frag_len,
1708                             more_frags);
1709
1710                         /* We added the LAST segment and reassembly didn't
1711                          * complete. Insert a zero-length MIDDLE segment to
1712                          * turn a 2-frame BIU-fragmentation into a 3-frame
1713                          * BIU-fragmentation (empty middle frag).
1714                          * See above long comment about this trickery. */
1715
1716                         if (mpf == MPF_LAST_SEGMENT && !fd_head) {
1717                                 fd_head = fragment_add_seq(tvb, offset, pinfo,
1718                                     id, sna_fragment_table,
1719                                     MIDDLE_FRAG_NUMBER, 0, TRUE);
1720                         }
1721
1722                         if (fd_head != NULL) {
1723                                 /* We have the complete reassembled payload. */
1724                                 rh_tvb = tvb_new_real_data(fd_head->data,
1725                                     fd_head->len, fd_head->len);
1726
1727                                 /* Add the tvbuff to the chain of tvbuffs
1728                                  * so that it will get cleaned up too. */
1729                                 tvb_set_child_real_data_tvbuff(tvb, rh_tvb);
1730
1731                                 /* Add the defragmented data to the data
1732                                  * source list. */
1733                                 add_new_data_source(pinfo, rh_tvb,
1734                                     "Reassembled SNA BIU");
1735                         }
1736                 }
1737         }
1738         return rh_tvb;
1739 }
1740
1741 #define SNA_FID01_ADDR_LEN      2
1742
1743 /* FID Types 0 and 1 */
1744 static int
1745 dissect_fid0_1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1746 {
1747         proto_tree      *bf_tree;
1748         proto_item      *bf_item;
1749         guint8          th_0;
1750         const guint8    *ptr;
1751
1752         const int bytes_in_header = 10;
1753
1754         if (tree) {
1755                 /* Byte 0 */
1756                 th_0 = tvb_get_guint8(tvb, 0);
1757                 bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, 0, 1,
1758                     th_0);
1759                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1760
1761                 proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb, 0, 1, th_0);
1762                 proto_tree_add_uint(bf_tree, hf_sna_th_mpf, tvb, 0, 1, th_0);
1763                 proto_tree_add_uint(bf_tree, hf_sna_th_efi, tvb, 0, 1, th_0);
1764
1765                 /* Byte 1 */
1766                 proto_tree_add_text(tree, tvb, 1, 1, "Reserved");
1767
1768                 /* Bytes 2-3 */
1769                 proto_tree_add_item(tree, hf_sna_th_daf, tvb, 2, 2, FALSE);
1770         }
1771
1772         /* Set DST addr */
1773         ptr = tvb_get_ptr(tvb, 2, SNA_FID01_ADDR_LEN);
1774         SET_ADDRESS(&pinfo->net_dst, AT_SNA, SNA_FID01_ADDR_LEN, ptr);
1775         SET_ADDRESS(&pinfo->dst, AT_SNA, SNA_FID01_ADDR_LEN, ptr);
1776
1777         if (tree)
1778                 proto_tree_add_item(tree, hf_sna_th_oaf, tvb, 4, 2, FALSE);
1779
1780         /* Set SRC addr */
1781         ptr = tvb_get_ptr(tvb, 4, SNA_FID01_ADDR_LEN);
1782         SET_ADDRESS(&pinfo->net_src, AT_SNA, SNA_FID01_ADDR_LEN, ptr);
1783         SET_ADDRESS(&pinfo->src, AT_SNA, SNA_FID01_ADDR_LEN, ptr);
1784
1785         /* If we're not filling a proto_tree, return now */
1786         if (tree)
1787                 return bytes_in_header;
1788
1789         proto_tree_add_item(tree, hf_sna_th_snf, tvb, 6, 2, FALSE);
1790         proto_tree_add_item(tree, hf_sna_th_dcf, tvb, 8, 2, FALSE);
1791
1792         return bytes_in_header;
1793 }
1794
1795 #define SNA_FID2_ADDR_LEN       1
1796
1797 /* FID Type 2 */
1798 static int
1799 dissect_fid2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
1800         tvbuff_t **rh_tvb_ptr, next_dissection_t *continue_dissecting)
1801 {
1802         proto_tree      *bf_tree;
1803         proto_item      *bf_item;
1804         guint8          th_0=0, daf=0, oaf=0;
1805         const guint8    *ptr;
1806         unsigned int    mpf, id;
1807
1808         const int bytes_in_header = 6;
1809
1810         th_0 = tvb_get_guint8(tvb, 0);
1811         mpf = mpf_value(th_0);
1812
1813         if (tree) {
1814                 daf = tvb_get_guint8(tvb, 2);
1815                 oaf = tvb_get_guint8(tvb, 3);
1816
1817                 /* Byte 0 */
1818                 bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, 0, 1,
1819                     th_0);
1820                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1821
1822                 proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb, 0, 1, th_0);
1823                 proto_tree_add_uint(bf_tree, hf_sna_th_mpf, tvb, 0, 1, th_0);
1824                 proto_tree_add_uint(bf_tree, hf_sna_th_odai,tvb, 0, 1, th_0);
1825                 proto_tree_add_uint(bf_tree, hf_sna_th_efi, tvb, 0, 1, th_0);
1826
1827
1828                 /* Byte 1 */
1829                 proto_tree_add_text(tree, tvb, 1, 1, "Reserved");
1830
1831                 /* Byte 2 */
1832                 proto_tree_add_uint_format(tree, hf_sna_th_daf, tvb, 2, 1, daf,
1833                     "Destination Address Field: 0x%02x", daf);
1834         }
1835
1836         /* Set DST addr */
1837         ptr = tvb_get_ptr(tvb, 2, SNA_FID2_ADDR_LEN);
1838         SET_ADDRESS(&pinfo->net_dst, AT_SNA, SNA_FID2_ADDR_LEN, ptr);
1839         SET_ADDRESS(&pinfo->dst, AT_SNA, SNA_FID2_ADDR_LEN, ptr);
1840
1841         if (tree) {
1842                 /* Byte 3 */
1843                 proto_tree_add_uint_format(tree, hf_sna_th_oaf, tvb, 3, 1, oaf,
1844                     "Origin Address Field: 0x%02x", oaf);
1845         }
1846
1847         /* Set SRC addr */
1848         ptr = tvb_get_ptr(tvb, 3, SNA_FID2_ADDR_LEN);
1849         SET_ADDRESS(&pinfo->net_src, AT_SNA, SNA_FID2_ADDR_LEN, ptr);
1850         SET_ADDRESS(&pinfo->src, AT_SNA, SNA_FID2_ADDR_LEN, ptr);
1851
1852         id = tvb_get_ntohs(tvb, 4);
1853         if (tree)
1854                 proto_tree_add_uint(tree, hf_sna_th_snf, tvb, 4, 2, id);
1855
1856         if (mpf != MPF_WHOLE_BIU && !sna_defragment) {
1857                 if (mpf == MPF_FIRST_SEGMENT) {
1858                         *continue_dissecting = rh_only;
1859                 } else {
1860                         *continue_dissecting = stop_here;
1861                 }
1862
1863         }
1864         else if (sna_defragment) {
1865                 *rh_tvb_ptr = defragment_by_sequence(pinfo, tvb,
1866                     bytes_in_header, mpf, id);
1867         }
1868
1869         return bytes_in_header;
1870 }
1871
1872 /* FID Type 3 */
1873 static int
1874 dissect_fid3(tvbuff_t *tvb, proto_tree *tree)
1875 {
1876         proto_tree      *bf_tree;
1877         proto_item      *bf_item;
1878         guint8          th_0;
1879
1880         const int bytes_in_header = 2;
1881
1882         /* If we're not filling a proto_tree, return now */
1883         if (!tree)
1884                 return bytes_in_header;
1885
1886         th_0 = tvb_get_guint8(tvb, 0);
1887
1888         /* Create the bitfield tree */
1889         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, 0, 1, th_0);
1890         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1891
1892         proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb, 0, 1, th_0);
1893         proto_tree_add_uint(bf_tree, hf_sna_th_mpf, tvb, 0, 1, th_0);
1894         proto_tree_add_uint(bf_tree, hf_sna_th_efi, tvb, 0, 1, th_0);
1895
1896         proto_tree_add_item(tree, hf_sna_th_lsid, tvb, 1, 1, FALSE);
1897
1898         return bytes_in_header;
1899 }
1900
1901 static int
1902 dissect_fid4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1903 {
1904         proto_tree      *bf_tree;
1905         proto_item      *bf_item;
1906         int             offset = 0;
1907         guint8          th_byte, mft;
1908         guint16         th_word;
1909         guint16         def, oef;
1910         guint32         dsaf, osaf;
1911         static struct sna_fid_type_4_addr src, dst;
1912
1913         const int bytes_in_header = 26;
1914
1915         /* If we're not filling a proto_tree, return now */
1916         if (!tree)
1917                 return bytes_in_header;
1918
1919         th_byte = tvb_get_guint8(tvb, offset);
1920
1921         /* Create the bitfield tree */
1922         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, offset,
1923             1, th_byte);
1924         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1925
1926         /* Byte 0 */
1927         proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb,
1928             offset, 1, th_byte);
1929         proto_tree_add_uint(bf_tree, hf_sna_th_tg_sweep, tvb,
1930             offset, 1, th_byte);
1931         proto_tree_add_uint(bf_tree, hf_sna_th_er_vr_supp_ind, tvb,
1932             offset, 1, th_byte);
1933         proto_tree_add_uint(bf_tree, hf_sna_th_vr_pac_cnt_ind, tvb,
1934             offset, 1, th_byte);
1935         proto_tree_add_uint(bf_tree, hf_sna_th_ntwk_prty, tvb,
1936             offset, 1, th_byte);
1937
1938         offset += 1;
1939         th_byte = tvb_get_guint8(tvb, offset);
1940
1941         /* Create the bitfield tree */
1942         bf_item = proto_tree_add_text(tree, tvb, offset, 1,
1943             "Transmision Header Byte 1");
1944         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1945
1946         /* Byte 1 */
1947         proto_tree_add_uint(bf_tree, hf_sna_th_tgsf, tvb, offset, 1,
1948             th_byte);
1949         proto_tree_add_boolean(bf_tree, hf_sna_th_mft, tvb, offset, 1,
1950             th_byte);
1951         proto_tree_add_uint(bf_tree, hf_sna_th_piubf, tvb, offset, 1,
1952             th_byte);
1953
1954         mft = th_byte & 0x04;
1955         offset += 1;
1956         th_byte = tvb_get_guint8(tvb, offset);
1957
1958         /* Create the bitfield tree */
1959         bf_item = proto_tree_add_text(tree, tvb, offset, 1,
1960             "Transmision Header Byte 2");
1961         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1962
1963         /* Byte 2 */
1964         if (mft) {
1965                 proto_tree_add_uint(bf_tree, hf_sna_th_nlpoi, tvb,
1966                     offset, 1, th_byte);
1967                 proto_tree_add_uint(bf_tree, hf_sna_th_nlp_cp, tvb,
1968                     offset, 1, th_byte);
1969         } else {
1970                 proto_tree_add_uint(bf_tree, hf_sna_th_iern, tvb,
1971                     offset, 1, th_byte);
1972         }
1973         proto_tree_add_uint(bf_tree, hf_sna_th_ern, tvb, offset, 1,
1974             th_byte);
1975
1976         offset += 1;
1977         th_byte = tvb_get_guint8(tvb, offset);
1978
1979         /* Create the bitfield tree */
1980         bf_item = proto_tree_add_text(tree, tvb, offset, 1,
1981             "Transmision Header Byte 3");
1982         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1983
1984         /* Byte 3 */
1985         proto_tree_add_uint(bf_tree, hf_sna_th_vrn, tvb, offset, 1,
1986             th_byte);
1987         proto_tree_add_uint(bf_tree, hf_sna_th_tpf, tvb, offset, 1,
1988             th_byte);
1989
1990         offset += 1;
1991         th_word = tvb_get_ntohs(tvb, offset);
1992
1993         /* Create the bitfield tree */
1994         bf_item = proto_tree_add_text(tree, tvb, offset, 2,
1995             "Transmision Header Bytes 4-5");
1996         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
1997
1998         /* Bytes 4-5 */
1999         proto_tree_add_uint(bf_tree, hf_sna_th_vr_cwi, tvb,
2000             offset, 2, th_word);
2001         proto_tree_add_boolean(bf_tree, hf_sna_th_tg_nonfifo_ind, tvb,
2002             offset, 2, th_word);
2003         proto_tree_add_uint(bf_tree, hf_sna_th_vr_sqti, tvb,
2004             offset, 2, th_word);
2005
2006         /* I'm not sure about byte-order on this one... */
2007         proto_tree_add_uint(bf_tree, hf_sna_th_tg_snf, tvb,
2008             offset, 2, th_word);
2009
2010         offset += 2;
2011         th_word = tvb_get_ntohs(tvb, offset);
2012
2013         /* Create the bitfield tree */
2014         bf_item = proto_tree_add_text(tree, tvb, offset, 2,
2015             "Transmision Header Bytes 6-7");
2016         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
2017
2018         /* Bytes 6-7 */
2019         proto_tree_add_boolean(bf_tree, hf_sna_th_vrprq, tvb, offset,
2020             2, th_word);
2021         proto_tree_add_boolean(bf_tree, hf_sna_th_vrprs, tvb, offset,
2022             2, th_word);
2023         proto_tree_add_uint(bf_tree, hf_sna_th_vr_cwri, tvb, offset,
2024             2, th_word);
2025         proto_tree_add_boolean(bf_tree, hf_sna_th_vr_rwi, tvb, offset,
2026             2, th_word);
2027
2028         /* I'm not sure about byte-order on this one... */
2029         proto_tree_add_uint(bf_tree, hf_sna_th_vr_snf_send, tvb,
2030             offset, 2, th_word);
2031
2032         offset += 2;
2033
2034         dsaf = tvb_get_ntohl(tvb, 8);
2035         /* Bytes 8-11 */
2036         proto_tree_add_uint(tree, hf_sna_th_dsaf, tvb, offset, 4, dsaf);
2037
2038         offset += 4;
2039
2040         osaf = tvb_get_ntohl(tvb, 12);
2041         /* Bytes 12-15 */
2042         proto_tree_add_uint(tree, hf_sna_th_osaf, tvb, offset, 4, osaf);
2043
2044         offset += 4;
2045         th_byte = tvb_get_guint8(tvb, offset);
2046
2047         /* Create the bitfield tree */
2048         bf_item = proto_tree_add_text(tree, tvb, offset, 2,
2049             "Transmision Header Byte 16");
2050         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
2051
2052         /* Byte 16 */
2053         proto_tree_add_boolean(tree, hf_sna_th_snai, tvb, offset, 1, th_byte);
2054
2055         /* We luck out here because in their infinite wisdom the SNA
2056          * architects placed the MPF and EFI fields in the same bitfield
2057          * locations, even though for FID4 they're not in byte 0.
2058          * Thank you IBM! */
2059         proto_tree_add_uint(tree, hf_sna_th_mpf, tvb, offset, 1, th_byte);
2060         proto_tree_add_uint(tree, hf_sna_th_efi, tvb, offset, 1, th_byte);
2061
2062         offset += 2;
2063         /* 1 for byte 16, 1 for byte 17 which is reserved */
2064
2065         def = tvb_get_ntohs(tvb, 18);
2066         /* Bytes 18-25 */
2067         proto_tree_add_uint(tree, hf_sna_th_def, tvb, offset, 2, def);
2068
2069         /* Addresses in FID 4 are discontiguous, sigh */
2070         dst.saf = dsaf;
2071         dst.ef = def;
2072         SET_ADDRESS(&pinfo->net_dst, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
2073             (guint8* )&dst);
2074         SET_ADDRESS(&pinfo->dst, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
2075             (guint8 *)&dst);
2076
2077         oef = tvb_get_ntohs(tvb, 20);
2078         proto_tree_add_uint(tree, hf_sna_th_oef, tvb, offset+2, 2, oef);
2079
2080         /* Addresses in FID 4 are discontiguous, sigh */
2081         src.saf = osaf;
2082         src.ef = oef;
2083         SET_ADDRESS(&pinfo->net_src, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
2084             (guint8 *)&src);
2085         SET_ADDRESS(&pinfo->src, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
2086             (guint8 *)&src);
2087
2088         proto_tree_add_item(tree, hf_sna_th_snf, tvb, offset+4, 2, FALSE);
2089         proto_tree_add_item(tree, hf_sna_th_dcf, tvb, offset+6, 2, FALSE);
2090
2091         return bytes_in_header;
2092 }
2093
2094 /* FID Type 5 */
2095 static int
2096 dissect_fid5(tvbuff_t *tvb, proto_tree *tree)
2097 {
2098         proto_tree      *bf_tree;
2099         proto_item      *bf_item;
2100         guint8          th_0;
2101
2102         const int bytes_in_header = 12;
2103
2104         /* If we're not filling a proto_tree, return now */
2105         if (!tree)
2106                 return bytes_in_header;
2107
2108         th_0 = tvb_get_guint8(tvb, 0);
2109
2110         /* Create the bitfield tree */
2111         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, 0, 1, th_0);
2112         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
2113
2114         proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb, 0, 1, th_0);
2115         proto_tree_add_uint(bf_tree, hf_sna_th_mpf, tvb, 0, 1, th_0);
2116         proto_tree_add_uint(bf_tree, hf_sna_th_efi, tvb, 0, 1, th_0);
2117
2118         proto_tree_add_text(tree, tvb, 1, 1, "Reserved");
2119         proto_tree_add_item(tree, hf_sna_th_snf, tvb, 2, 2, FALSE);
2120
2121         proto_tree_add_item(tree, hf_sna_th_sa, tvb, 4, 8, FALSE);
2122
2123         return bytes_in_header;
2124
2125 }
2126
2127 /* FID Type f */
2128 static int
2129 dissect_fidf(tvbuff_t *tvb, proto_tree *tree)
2130 {
2131         proto_tree      *bf_tree;
2132         proto_item      *bf_item;
2133         guint8          th_0;
2134
2135         const int bytes_in_header = 26;
2136
2137         /* If we're not filling a proto_tree, return now */
2138         if (!tree)
2139                 return bytes_in_header;
2140
2141         th_0 = tvb_get_guint8(tvb, 0);
2142
2143         /* Create the bitfield tree */
2144         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, tvb, 0, 1, th_0);
2145         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
2146
2147         proto_tree_add_uint(bf_tree, hf_sna_th_fid, tvb, 0, 1, th_0);
2148         proto_tree_add_text(tree, tvb, 1, 1, "Reserved");
2149
2150         proto_tree_add_item(tree, hf_sna_th_cmd_fmt, tvb,  2, 1, FALSE);
2151         proto_tree_add_item(tree, hf_sna_th_cmd_type, tvb, 3, 1, FALSE);
2152         proto_tree_add_item(tree, hf_sna_th_cmd_sn, tvb,   4, 2, FALSE);
2153
2154         /* Yup, bytes 6-23 are reserved! */
2155         proto_tree_add_text(tree, tvb, 6, 18, "Reserved");
2156
2157         proto_tree_add_item(tree, hf_sna_th_dcf, tvb, 24, 2, FALSE);
2158
2159         return bytes_in_header;
2160 }
2161
2162 static void
2163 dissect_fid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
2164     proto_tree *parent_tree)
2165 {
2166
2167         proto_tree      *th_tree = NULL, *rh_tree = NULL;
2168         proto_item      *th_ti = NULL, *rh_ti = NULL;
2169         guint8          th_fid;
2170         int             th_header_len = 0;
2171         int             offset, rh_offset;
2172         tvbuff_t        *rh_tvb = NULL;
2173         next_dissection_t continue_dissecting = everything;
2174
2175         /* Transmission Header Format Identifier */
2176         th_fid = hi_nibble(tvb_get_guint8(tvb, 0));
2177
2178         /* Summary information */
2179         if (check_col(pinfo->cinfo, COL_INFO))
2180                 col_add_str(pinfo->cinfo, COL_INFO,
2181                     val_to_str(th_fid, sna_th_fid_vals, "Unknown FID: %01x"));
2182
2183         if (tree) {
2184                 /* --- TH --- */
2185                 /* Don't bother setting length. We'll set it later after we
2186                  * find the length of TH */
2187                 th_ti = proto_tree_add_item(tree, hf_sna_th, tvb,  0, -1,
2188                     FALSE);
2189                 th_tree = proto_item_add_subtree(th_ti, ett_sna_th);
2190         }
2191
2192         /* Get size of TH */
2193         switch(th_fid) {
2194                 case 0x0:
2195                 case 0x1:
2196                         th_header_len = dissect_fid0_1(tvb, pinfo, th_tree);
2197                         break;
2198                 case 0x2:
2199                         th_header_len = dissect_fid2(tvb, pinfo, th_tree,
2200                             &rh_tvb, &continue_dissecting);
2201                         break;
2202                 case 0x3:
2203                         th_header_len = dissect_fid3(tvb, th_tree);
2204                         break;
2205                 case 0x4:
2206                         th_header_len = dissect_fid4(tvb, pinfo, th_tree);
2207                         break;
2208                 case 0x5:
2209                         th_header_len = dissect_fid5(tvb, th_tree);
2210                         break;
2211                 case 0xf:
2212                         th_header_len = dissect_fidf(tvb, th_tree);
2213                         break;
2214                 default:
2215                         call_dissector(data_handle,
2216                             tvb_new_subset(tvb, 1, -1, -1), pinfo, parent_tree);
2217                         return;
2218         }
2219
2220         offset = th_header_len;
2221
2222         /* Short-circuit ? */
2223         if (continue_dissecting == stop_here) {
2224                 if (tree) {
2225                         proto_tree_add_text(tree, tvb, offset, -1,
2226                             "BIU segment data");
2227                 }
2228                 return;
2229         }
2230
2231         /* If the FID dissector function didn't create an rh_tvb, then we just
2232          * use the rest of our tvbuff as the rh_tvb. */
2233         if (!rh_tvb)
2234                 rh_tvb = tvb_new_subset(tvb, offset, -1, -1);
2235         rh_offset = 0;
2236
2237         /* Process the rest of the SNA packet, starting with RH */
2238         if (tree) {
2239                 proto_item_set_len(th_ti, th_header_len);
2240
2241                 /* --- RH --- */
2242                 rh_ti = proto_tree_add_item(tree, hf_sna_rh, rh_tvb, rh_offset,
2243                     RH_LEN, FALSE);
2244                 rh_tree = proto_item_add_subtree(rh_ti, ett_sna_rh);
2245                 dissect_rh(rh_tvb, rh_offset, rh_tree);
2246         }
2247
2248         rh_offset += RH_LEN;
2249
2250         if (tvb_offset_exists(rh_tvb, rh_offset)) {
2251                 /* Short-circuit ? */
2252                 if (continue_dissecting == rh_only) {
2253                         if (tree)
2254                                 proto_tree_add_text(tree, rh_tvb, rh_offset, -1,
2255                                     "BIU segment data");
2256                         return;
2257                 }
2258
2259                 call_dissector(data_handle, 
2260                     tvb_new_subset(rh_tvb, rh_offset, -1, -1), 
2261                     pinfo, parent_tree);
2262         }
2263 }
2264
2265 /* --------------------------------------------------------------------
2266  * Chapter 5 Request/Response Headers (RHs)
2267  * --------------------------------------------------------------------
2268  */
2269
2270 static void
2271 dissect_rh(tvbuff_t *tvb, int offset, proto_tree *tree)
2272 {
2273         proto_tree      *bf_tree;
2274         proto_item      *bf_item;
2275         gboolean        is_response;
2276         guint8          rh_0, rh_1, rh_2;
2277
2278         if (!tree)
2279                 return;
2280
2281         /* Create the bitfield tree for byte 0*/
2282         rh_0 = tvb_get_guint8(tvb, offset);
2283         is_response = (rh_0 & 0x80);
2284
2285         bf_item = proto_tree_add_uint(tree, hf_sna_rh_0, tvb, offset, 1, rh_0);
2286         bf_tree = proto_item_add_subtree(bf_item, ett_sna_rh_0);
2287
2288         proto_tree_add_uint(bf_tree, hf_sna_rh_rri, tvb, offset, 1, rh_0);
2289         proto_tree_add_uint(bf_tree, hf_sna_rh_ru_category, tvb, offset, 1,
2290             rh_0);
2291         proto_tree_add_boolean(bf_tree, hf_sna_rh_fi, tvb, offset, 1, rh_0);
2292         proto_tree_add_boolean(bf_tree, hf_sna_rh_sdi, tvb, offset, 1, rh_0);
2293         proto_tree_add_boolean(bf_tree, hf_sna_rh_bci, tvb, offset, 1, rh_0);
2294         proto_tree_add_boolean(bf_tree, hf_sna_rh_eci, tvb, offset, 1, rh_0);
2295
2296         offset += 1;
2297         rh_1 = tvb_get_guint8(tvb, offset);
2298
2299         /* Create the bitfield tree for byte 1*/
2300         bf_item = proto_tree_add_uint(tree, hf_sna_rh_1, tvb, offset, 1, rh_1);
2301         bf_tree = proto_item_add_subtree(bf_item, ett_sna_rh_1);
2302
2303         proto_tree_add_boolean(bf_tree, hf_sna_rh_dr1, tvb,  offset, 1, rh_1);
2304
2305         if (!is_response)
2306                 proto_tree_add_boolean(bf_tree, hf_sna_rh_lcci, tvb, offset, 1,
2307                     rh_1);
2308
2309         proto_tree_add_boolean(bf_tree, hf_sna_rh_dr2, tvb,  offset, 1, rh_1);
2310
2311         if (is_response) {
2312                 proto_tree_add_boolean(bf_tree, hf_sna_rh_rti, tvb,  offset, 1,
2313                     rh_1);
2314         } else {
2315                 proto_tree_add_boolean(bf_tree, hf_sna_rh_eri, tvb,  offset, 1,
2316                     rh_1);
2317                 proto_tree_add_boolean(bf_tree, hf_sna_rh_rlwi, tvb, offset, 1,
2318                     rh_1);
2319         }
2320
2321         proto_tree_add_boolean(bf_tree, hf_sna_rh_qri, tvb, offset, 1, rh_1);
2322         proto_tree_add_boolean(bf_tree, hf_sna_rh_pi, tvb,  offset, 1, rh_1);
2323
2324         offset += 1;
2325         rh_2 = tvb_get_guint8(tvb, offset);
2326
2327         /* Create the bitfield tree for byte 2*/
2328         bf_item = proto_tree_add_uint(tree, hf_sna_rh_2, tvb, offset, 1, rh_2);
2329
2330         if (!is_response) {
2331                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_rh_2);
2332
2333                 proto_tree_add_boolean(bf_tree, hf_sna_rh_bbi, tvb,  offset, 1,
2334                     rh_2);
2335                 proto_tree_add_boolean(bf_tree, hf_sna_rh_ebi, tvb,  offset, 1,
2336                     rh_2);
2337                 proto_tree_add_boolean(bf_tree, hf_sna_rh_cdi, tvb,  offset, 1,
2338                     rh_2);
2339                 proto_tree_add_uint(bf_tree, hf_sna_rh_csi, tvb,  offset, 1,
2340                     rh_2);
2341                 proto_tree_add_boolean(bf_tree, hf_sna_rh_edi, tvb,  offset, 1,
2342                     rh_2);
2343                 proto_tree_add_boolean(bf_tree, hf_sna_rh_pdi, tvb,  offset, 1,
2344                     rh_2);
2345                 proto_tree_add_boolean(bf_tree, hf_sna_rh_cebi, tvb, offset, 1,
2346                     rh_2);
2347         }
2348
2349         /* XXX - check for sdi. If TRUE, the next 4 bytes will be sense data */
2350 }
2351
2352 /* --------------------------------------------------------------------
2353  * Chapter 6 Request/Response Units (RUs)
2354  * --------------------------------------------------------------------
2355  */
2356
2357 /* --------------------------------------------------------------------
2358  * Chapter 9 Common Fields
2359  * --------------------------------------------------------------------
2360  */
2361
2362 static void
2363 dissect_control_05hpr(tvbuff_t *tvb, proto_tree *tree, int hpr,
2364     enum parse parse)
2365 {
2366         proto_tree      *bf_tree;
2367         proto_item      *bf_item;
2368         guint8          type;
2369         guint16         offset, len, pad;
2370
2371         if (!tree)
2372                 return;
2373
2374         type = tvb_get_guint8(tvb, 2);
2375
2376         bf_item = proto_tree_add_uint(tree, hf_sna_control_05_type, tvb,
2377             2, 1, type);
2378         bf_tree = proto_item_add_subtree(bf_item, ett_sna_control_05hpr_type);
2379
2380         proto_tree_add_boolean(bf_tree, hf_sna_control_05_ptp, tvb, 2, 1, type);
2381         proto_tree_add_text(tree, tvb, 3, 1, "Reserved");
2382
2383         offset = 4;
2384
2385         while (tvb_offset_exists(tvb, offset)) {
2386                 if (parse == LT) {
2387                         len = tvb_get_guint8(tvb, offset+0);
2388                 } else {
2389                         len = tvb_get_guint8(tvb, offset+1);
2390                 }
2391                 if (len) {
2392                         dissect_control(tvb_new_subset(tvb, offset, len, -1),
2393                             tree, hpr, parse);
2394                         pad = (len+3) & 0xfffc;
2395                         if (pad > len)
2396                                 proto_tree_add_text(tree, tvb, offset+len,
2397                                     pad-len, "Padding");
2398                         offset += pad;
2399                 } else {
2400                         return;
2401                 }
2402         }
2403 }
2404
2405 static void
2406 dissect_control_05(tvbuff_t *tvb, proto_tree *tree)
2407 {
2408         if(!tree)
2409                 return;
2410
2411         proto_tree_add_item(tree, hf_sna_control_05_delay, tvb, 2, 2, FALSE);
2412 }
2413
2414 static void
2415 dissect_control_0e(tvbuff_t *tvb, proto_tree *tree)
2416 {
2417         guint   len;
2418         guint8  *buf;
2419
2420         if (!tree)
2421                 return;
2422
2423         proto_tree_add_item(tree, hf_sna_control_0e_type, tvb, 2, 1, FALSE);
2424
2425         len = tvb_length(tvb) - 3;
2426         if (len <= 0)
2427                 return;
2428
2429         buf = g_malloc(len+1);
2430         tvb_memcpy (tvb, buf, 3, len);
2431         EBCDIC_to_ASCII(buf, len);
2432         buf[len] = 0;
2433         proto_tree_add_string(tree, hf_sna_control_0e_value, tvb, 3, len, buf);
2434         g_free(buf);
2435 }
2436
2437 static void
2438 dissect_control(tvbuff_t *tvb, proto_tree *tree, int hpr, enum parse parse)
2439 {
2440         proto_tree      *sub_tree;
2441         proto_item      *sub_item;
2442         int             len, key;
2443         gint            ett;
2444
2445         sub_tree = NULL;
2446
2447         if (parse == LT) {
2448                 len = tvb_get_guint8(tvb, 0);
2449                 key = tvb_get_guint8(tvb, 1);
2450         } else {
2451                 key = tvb_get_guint8(tvb, 0);
2452                 len = tvb_get_guint8(tvb, 1);
2453         }
2454         ett = ett_sna_control_un;
2455
2456         if (tree) {
2457                 if (key == 5) {
2458                          if (hpr) ett = ett_sna_control_05hpr;
2459                          else ett = ett_sna_control_05;
2460                 }
2461                 if (key == 0x0e) ett = ett_sna_control_0e;
2462
2463                 if (((key == 0) || (key == 3) || (key == 5)) && hpr)
2464                         sub_item = proto_tree_add_text(tree, tvb, 0, -1,
2465                             val_to_str(key, sna_control_hpr_vals,
2466                             "Unknown Control Vector"));
2467                 else
2468                         sub_item = proto_tree_add_text(tree, tvb, 0, -1,
2469                             val_to_str(key, sna_control_vals,
2470                             "Unknown Control Vector"));
2471                 sub_tree = proto_item_add_subtree(sub_item, ett);
2472                 if (parse == LT) {
2473                         proto_tree_add_uint(sub_tree, hf_sna_control_len,
2474                             tvb, 0, 1, len);
2475                         if (((key == 0) || (key == 3) || (key == 5)) && hpr)
2476                                 proto_tree_add_uint(sub_tree,
2477                                     hf_sna_control_hprkey, tvb, 1, 1, key);
2478                         else
2479                                 proto_tree_add_uint(sub_tree,
2480                                     hf_sna_control_key, tvb, 1, 1, key);
2481                 } else {
2482                         if (((key == 0) || (key == 3) || (key == 5)) && hpr)
2483                                 proto_tree_add_uint(sub_tree,
2484                                     hf_sna_control_hprkey, tvb, 0, 1, key);
2485                         else
2486                                 proto_tree_add_uint(sub_tree,
2487                                     hf_sna_control_key, tvb, 0, 1, key);
2488                         proto_tree_add_uint(sub_tree, hf_sna_control_len,
2489                             tvb, 1, 1, len);
2490                 }
2491         }
2492         switch(key) {
2493                 case 0x05:
2494                         if (hpr)
2495                                 dissect_control_05hpr(tvb, sub_tree, hpr,
2496                                     parse);
2497                         else
2498                                 dissect_control_05(tvb, sub_tree);
2499                         break;
2500                 case 0x0e:
2501                         dissect_control_0e(tvb, sub_tree);
2502                         break;
2503         }
2504 }
2505
2506 /* --------------------------------------------------------------------
2507  * Chapter 11 Function Management (FM) Headers
2508  * --------------------------------------------------------------------
2509  */
2510
2511 /* --------------------------------------------------------------------
2512  * Chapter 12 Presentation Services (PS) Headers
2513  * --------------------------------------------------------------------
2514  */
2515
2516 /* --------------------------------------------------------------------
2517  * Chapter 13 GDS Variables
2518  * --------------------------------------------------------------------
2519  */
2520
2521 static void
2522 dissect_gds(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, 
2523     proto_tree *parent_tree)
2524 {
2525         guint16         length;
2526         guint16         type;
2527         int             cont;
2528         int             offset;
2529         proto_tree      *gds_tree;
2530         proto_item      *gds_item;
2531
2532         offset = 0;
2533         cont   = 1;
2534         type   = tvb_get_ntohs(tvb, offset+2);
2535
2536         while (cont) {
2537                 length = tvb_get_ntohs(tvb, offset) & 0x7fff;
2538                 cont   = (tvb_get_ntohs(tvb, offset) & 0x8000) ? 1 : 0;
2539                 type   = tvb_get_ntohs(tvb, offset+2);
2540
2541                 if (length < 2 ) /* escape sequence ? */
2542                         return;
2543                 if (tree) {
2544                         gds_item = proto_tree_add_item(tree, hf_sna_gds, tvb,
2545                             offset, length, FALSE);
2546                         gds_tree = proto_item_add_subtree(gds_item,
2547                             ett_sna_gds);
2548
2549                         proto_tree_add_uint(gds_tree, hf_sna_gds_len, tvb,
2550                             offset, 2, length);
2551                         proto_tree_add_boolean(gds_tree, hf_sna_gds_cont, tvb,
2552                             offset, 2, cont);
2553                         proto_tree_add_uint(gds_tree, hf_sna_gds_type, tvb,
2554                             offset+2, 2, type);
2555                 }
2556                 offset += length;
2557         }
2558         if (tvb_offset_exists(tvb, offset))
2559                 call_dissector(data_handle,
2560                     tvb_new_subset(tvb, offset, -1, -1), pinfo, parent_tree);
2561 };
2562
2563 /* --------------------------------------------------------------------
2564  * General stuff
2565  * --------------------------------------------------------------------
2566  */
2567
2568 static void
2569 dissect_sna(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2570 {
2571         guint8          fid;
2572         proto_tree      *sna_tree = NULL;
2573         proto_item      *sna_ti = NULL;
2574
2575         if (check_col(pinfo->cinfo, COL_PROTOCOL))
2576                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SNA");
2577         if (check_col(pinfo->cinfo, COL_INFO))
2578                 col_clear(pinfo->cinfo, COL_INFO);
2579
2580         /* SNA data should be printed in EBCDIC, not ASCII */
2581         pinfo->fd->flags.encoding = CHAR_EBCDIC;
2582
2583         if (tree) {
2584
2585                 /* Don't bother setting length. We'll set it later after we find
2586                  * the lengths of TH/RH/RU */
2587                 sna_ti = proto_tree_add_item(tree, proto_sna, tvb, 0, -1,
2588                     FALSE);
2589                 sna_tree = proto_item_add_subtree(sna_ti, ett_sna);
2590         }
2591
2592         /* Transmission Header Format Identifier */
2593         fid = hi_nibble(tvb_get_guint8(tvb, 0));
2594         switch(fid) {
2595                 case 0xa:       /* HPR Network Layer Packet */
2596                 case 0xb:
2597                 case 0xc:
2598                 case 0xd:
2599                         dissect_nlp(tvb, pinfo, sna_tree, tree);
2600                         break;
2601                 default:
2602                         dissect_fid(tvb, pinfo, sna_tree, tree);
2603         }
2604 }
2605
2606 static void
2607 dissect_sna_xid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2608 {
2609         proto_tree      *sna_tree = NULL;
2610         proto_item      *sna_ti = NULL;
2611
2612         if (check_col(pinfo->cinfo, COL_PROTOCOL))
2613                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SNA");
2614         if (check_col(pinfo->cinfo, COL_INFO))
2615                 col_clear(pinfo->cinfo, COL_INFO);
2616
2617         /* SNA data should be printed in EBCDIC, not ASCII */
2618         pinfo->fd->flags.encoding = CHAR_EBCDIC;
2619
2620         if (tree) {
2621
2622                 /* Don't bother setting length. We'll set it later after we find
2623                  * the lengths of XID */
2624                 sna_ti = proto_tree_add_item(tree, proto_sna_xid, tvb, 0, -1,
2625                     FALSE);
2626                 sna_tree = proto_item_add_subtree(sna_ti, ett_sna);
2627         }
2628         dissect_xid(tvb, pinfo, sna_tree, tree);
2629 }
2630
2631 static void
2632 sna_init(void)
2633 {
2634         fragment_table_init(&sna_fragment_table);
2635         reassembled_table_init(&sna_reassembled_table);
2636 }
2637
2638
2639 void
2640 proto_register_sna(void)
2641 {
2642         static hf_register_info hf[] = {
2643                 { &hf_sna_th,
2644                 { "Transmission Header", "sna.th", FT_NONE, BASE_NONE,
2645                      NULL, 0x0, "", HFILL }},
2646
2647                 { &hf_sna_th_0,
2648                 { "Transmission Header Byte 0", "sna.th.0", FT_UINT8, BASE_HEX,
2649                     NULL, 0x0,
2650                     "TH Byte 0", HFILL }},
2651
2652                 { &hf_sna_th_fid,
2653                 { "Format Identifer", "sna.th.fid", FT_UINT8, BASE_HEX,
2654                     VALS(sna_th_fid_vals), 0xf0, "", HFILL }},
2655
2656                 { &hf_sna_th_mpf,
2657                 { "Mapping Field", "sna.th.mpf", FT_UINT8,
2658                     BASE_DEC, VALS(sna_th_mpf_vals), 0x0c, "", HFILL }},
2659
2660                 { &hf_sna_th_odai,
2661                 { "ODAI Assignment Indicator", "sna.th.odai", FT_UINT8,
2662                     BASE_DEC, NULL, 0x02, "", HFILL }},
2663
2664                 { &hf_sna_th_efi,
2665                 { "Expedited Flow Indicator", "sna.th.efi", FT_UINT8,
2666                     BASE_DEC, VALS(sna_th_efi_vals), 0x01, "", HFILL }},
2667
2668                 { &hf_sna_th_daf,
2669                 { "Destination Address Field", "sna.th.daf", FT_UINT16,
2670                     BASE_HEX, NULL, 0x0, "", HFILL }},
2671
2672                 { &hf_sna_th_oaf,
2673                 { "Origin Address Field", "sna.th.oaf", FT_UINT16, BASE_HEX,
2674                     NULL, 0x0, "", HFILL }},
2675
2676                 { &hf_sna_th_snf,
2677                 { "Sequence Number Field", "sna.th.snf", FT_UINT16, BASE_DEC,
2678                     NULL, 0x0, "", HFILL }},
2679
2680                 { &hf_sna_th_dcf,
2681                 { "Data Count Field", "sna.th.dcf", FT_UINT16, BASE_DEC,
2682                     NULL, 0x0, "", HFILL }},
2683
2684                 { &hf_sna_th_lsid,
2685                 { "Local Session Identification", "sna.th.lsid", FT_UINT8,
2686                     BASE_HEX, NULL, 0x0, "", HFILL }},
2687
2688                 { &hf_sna_th_tg_sweep,
2689                 { "Transmission Group Sweep", "sna.th.tg_sweep", FT_UINT8,
2690                     BASE_DEC, VALS(sna_th_tg_sweep_vals), 0x08, "", HFILL }},
2691
2692                 { &hf_sna_th_er_vr_supp_ind,
2693                 { "ER and VR Support Indicator", "sna.th.er_vr_supp_ind",
2694                     FT_UINT8, BASE_DEC, VALS(sna_th_er_vr_supp_ind_vals),
2695                     0x04, "", HFILL }},
2696
2697                 { &hf_sna_th_vr_pac_cnt_ind,
2698                 { "Virtual Route Pacing Count Indicator",
2699                     "sna.th.vr_pac_cnt_ind", FT_UINT8, BASE_DEC,
2700                     VALS(sna_th_vr_pac_cnt_ind_vals), 0x02, "", HFILL }},
2701
2702                 { &hf_sna_th_ntwk_prty,
2703                 { "Network Priority", "sna.th.ntwk_prty", FT_UINT8, BASE_DEC,
2704                     VALS(sna_th_ntwk_prty_vals), 0x01, "", HFILL }},
2705
2706                 { &hf_sna_th_tgsf,
2707                 { "Transmission Group Segmenting Field", "sna.th.tgsf",
2708                     FT_UINT8, BASE_HEX, VALS(sna_th_tgsf_vals), 0xc0,
2709                     "", HFILL }},
2710
2711                 { &hf_sna_th_mft,
2712                 { "MPR FID4 Type", "sna.th.mft", FT_BOOLEAN, BASE_NONE,
2713                     NULL, 0x04, "", HFILL }},
2714
2715                 { &hf_sna_th_piubf,
2716                 { "PIU Blocking Field", "sna.th.piubf", FT_UINT8, BASE_HEX,
2717                     VALS(sna_th_piubf_vals), 0x03, "", HFILL }},
2718
2719                 { &hf_sna_th_iern,
2720                 { "Initial Explicit Route Number", "sna.th.iern", FT_UINT8,
2721                     BASE_DEC, NULL, 0xf0, "", HFILL }},
2722
2723                 { &hf_sna_th_nlpoi,
2724                 { "NLP Offset Indicator", "sna.th.nlpoi", FT_UINT8, BASE_DEC,
2725                     VALS(sna_th_nlpoi_vals), 0x80, "", HFILL }},
2726
2727                 { &hf_sna_th_nlp_cp,
2728                 { "NLP Count or Padding", "sna.th.nlp_cp", FT_UINT8, BASE_DEC,
2729                     NULL, 0x70, "", HFILL }},
2730
2731                 { &hf_sna_th_ern,
2732                 { "Explicit Route Number", "sna.th.ern", FT_UINT8, BASE_DEC,
2733                     NULL, 0x0f, "", HFILL }},
2734
2735                 { &hf_sna_th_vrn,
2736                 { "Virtual Route Number", "sna.th.vrn", FT_UINT8, BASE_DEC,
2737                     NULL, 0xf0, "", HFILL }},
2738
2739                 { &hf_sna_th_tpf,
2740                 { "Transmission Priority Field", "sna.th.tpf", FT_UINT8,
2741                     BASE_HEX, VALS(sna_th_tpf_vals), 0x03, "", HFILL }},
2742
2743                 { &hf_sna_th_vr_cwi,
2744                 { "Virtual Route Change Window Indicator", "sna.th.vr_cwi",
2745                     FT_UINT16, BASE_DEC, VALS(sna_th_vr_cwi_vals), 0x8000,
2746                     "Change Window Indicator", HFILL }},
2747
2748                 { &hf_sna_th_tg_nonfifo_ind,
2749                 { "Transmission Group Non-FIFO Indicator",
2750                     "sna.th.tg_nonfifo_ind", FT_BOOLEAN, 16,
2751                     TFS(&sna_th_tg_nonfifo_ind_truth), 0x4000, "", HFILL }},
2752
2753                 { &hf_sna_th_vr_sqti,
2754                 { "Virtual Route Sequence and Type Indicator", "sna.th.vr_sqti",
2755                     FT_UINT16, BASE_HEX, VALS(sna_th_vr_sqti_vals), 0x3000,
2756                     "Route Sequence and Type", HFILL }},
2757
2758                 { &hf_sna_th_tg_snf,
2759                 { "Transmission Group Sequence Number Field", "sna.th.tg_snf",
2760                     FT_UINT16, BASE_DEC, NULL, 0x0fff, "", HFILL }},
2761
2762                 { &hf_sna_th_vrprq,
2763                 { "Virtual Route Pacing Request", "sna.th.vrprq", FT_BOOLEAN,
2764                     16, TFS(&sna_th_vrprq_truth), 0x8000, "", HFILL }},
2765
2766                 { &hf_sna_th_vrprs,
2767                 { "Virtual Route Pacing Response", "sna.th.vrprs", FT_BOOLEAN,
2768                     16, TFS(&sna_th_vrprs_truth), 0x4000, "", HFILL }},
2769
2770                 { &hf_sna_th_vr_cwri,
2771                 { "Virtual Route Change Window Reply Indicator",
2772                     "sna.th.vr_cwri", FT_UINT16, BASE_DEC,
2773                     VALS(sna_th_vr_cwri_vals), 0x2000, "", HFILL }},
2774
2775                 { &hf_sna_th_vr_rwi,
2776                 { "Virtual Route Reset Window Indicator", "sna.th.vr_rwi",
2777                     FT_BOOLEAN, 16, TFS(&sna_th_vr_rwi_truth), 0x1000,
2778                     "", HFILL }},
2779
2780                 { &hf_sna_th_vr_snf_send,
2781                 { "Virtual Route Send Sequence Number Field",
2782                     "sna.th.vr_snf_send", FT_UINT16, BASE_DEC, NULL, 0x0fff,
2783                     "Send Sequence Number Field", HFILL }},
2784
2785                 { &hf_sna_th_dsaf,
2786                 { "Destination Subarea Address Field", "sna.th.dsaf",
2787                     FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
2788
2789                 { &hf_sna_th_osaf,
2790                 { "Origin Subarea Address Field", "sna.th.osaf", FT_UINT32,
2791                     BASE_HEX, NULL, 0x0, "", HFILL }},
2792
2793                 { &hf_sna_th_snai,
2794                 { "SNA Indicator", "sna.th.snai", FT_BOOLEAN, 8, NULL, 0x10,
2795                     "Used to identify whether the PIU originated or is destined"
2796                     " for an SNA or non-SNA device.", HFILL }},
2797
2798                 { &hf_sna_th_def,
2799                 { "Destination Element Field", "sna.th.def", FT_UINT16,
2800                     BASE_HEX, NULL, 0x0, "", HFILL }},
2801
2802                 { &hf_sna_th_oef,
2803                 { "Origin Element Field", "sna.th.oef", FT_UINT16, BASE_HEX,
2804                     NULL, 0x0, "", HFILL }},
2805
2806                 { &hf_sna_th_sa,
2807                 { "Session Address", "sna.th.sa", FT_BYTES, BASE_HEX,
2808                     NULL, 0x0, "", HFILL }},
2809
2810                 { &hf_sna_th_cmd_fmt,
2811                 { "Command Format", "sna.th.cmd_fmt", FT_UINT8, BASE_HEX,
2812                     NULL, 0x0, "", HFILL }},
2813
2814                 { &hf_sna_th_cmd_type,
2815                 { "Command Type", "sna.th.cmd_type", FT_UINT8, BASE_HEX,
2816                     NULL, 0x0, "", HFILL }},
2817
2818                 { &hf_sna_th_cmd_sn,
2819                 { "Command Sequence Number", "sna.th.cmd_sn", FT_UINT16,
2820                     BASE_DEC, NULL, 0x0, "", HFILL }},
2821
2822                 { &hf_sna_nlp_nhdr,
2823                 { "Network Layer Packet Header", "sna.nlp.nhdr", FT_NONE,
2824                     BASE_NONE, NULL, 0x0, "NHDR", HFILL }},
2825
2826                 { &hf_sna_nlp_nhdr_0,
2827                 { "Network Layer Packet Header Byte 0", "sna.nlp.nhdr.0",
2828                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
2829
2830                 { &hf_sna_nlp_nhdr_1,
2831                 { "Network Layer Packet Header Byte 1", "sna.nlp.nhdr.1",
2832                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
2833
2834                 { &hf_sna_nlp_sm,
2835                 { "Switching Mode Field", "sna.nlp.nhdr.sm", FT_UINT8,
2836                     BASE_HEX, VALS(sna_nlp_sm_vals), 0xe0, "", HFILL }},
2837
2838                 { &hf_sna_nlp_tpf,
2839                 { "Transmission Priority Field", "sna.nlp.nhdr.tpf", FT_UINT8,
2840                     BASE_HEX, VALS(sna_th_tpf_vals), 0x06, "", HFILL }},
2841
2842                 { &hf_sna_nlp_ft,
2843                 { "Function Type", "sna.nlp.nhdr.ft", FT_UINT8, BASE_HEX,
2844                     VALS(sna_nlp_ft_vals), 0xF0, "", HFILL }},
2845
2846                 { &hf_sna_nlp_tspi,
2847                 { "Time Sensitive Packet Indicator", "sna.nlp.nhdr.tspi",
2848                     FT_BOOLEAN, 8, TFS(&sna_nlp_tspi_truth), 0x08, "", HFILL }},
2849
2850                 { &hf_sna_nlp_slowdn1,
2851                 { "Slowdown 1", "sna.nlp.nhdr.slowdn1", FT_BOOLEAN, 8,
2852                     TFS(&sna_nlp_slowdn1_truth), 0x04, "", HFILL }},
2853
2854                 { &hf_sna_nlp_slowdn2,
2855                 { "Slowdown 2", "sna.nlp.nhdr.slowdn2", FT_BOOLEAN, 8,
2856                     TFS(&sna_nlp_slowdn2_truth), 0x02, "", HFILL }},
2857
2858                 { &hf_sna_nlp_fra,
2859                 { "Function Routing Address Entry", "sna.nlp.nhdr.fra",
2860                     FT_BYTES, BASE_NONE, NULL, 0, "", HFILL }},
2861
2862                 { &hf_sna_nlp_anr,
2863                 { "Automatic Network Routing Entry", "sna.nlp.nhdr.anr",
2864                     FT_BYTES, BASE_HEX, NULL, 0, "", HFILL }},
2865
2866                 { &hf_sna_nlp_frh,
2867                 { "Transmission Priority Field", "sna.nlp.frh", FT_UINT8,
2868                     BASE_HEX, VALS(sna_nlp_frh_vals), 0, "", HFILL }},
2869
2870                 { &hf_sna_nlp_thdr,
2871                 { "RTP Transport Header", "sna.nlp.thdr", FT_NONE, BASE_NONE,
2872                     NULL, 0x0, "THDR", HFILL }},
2873
2874                 { &hf_sna_nlp_tcid,
2875                 { "Transport Connection Identifier", "sna.nlp.thdr.tcid",
2876                     FT_BYTES, BASE_HEX, NULL, 0x0, "TCID", HFILL }},
2877
2878                 { &hf_sna_nlp_thdr_8,
2879                 { "RTP Transport Packet Header Byte 8", "sna.nlp.thdr.8",
2880                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
2881
2882                 { &hf_sna_nlp_setupi,
2883                 { "Setup Indicator", "sna.nlp.thdr.setupi", FT_BOOLEAN, 8,
2884                     TFS(&sna_nlp_setupi_truth), 0x40, "", HFILL }},
2885
2886                 { &hf_sna_nlp_somi,
2887                 { "Start Of Message Indicator", "sna.nlp.thdr.somi",
2888                     FT_BOOLEAN, 8, TFS(&sna_nlp_somi_truth), 0x20, "", HFILL }},
2889
2890                 { &hf_sna_nlp_eomi,
2891                 { "End Of Message Indicator", "sna.nlp.thdr.eomi", FT_BOOLEAN,
2892                     8, TFS(&sna_nlp_eomi_truth), 0x10, "", HFILL }},
2893
2894                 { &hf_sna_nlp_sri,
2895                 { "Session Request Indicator", "sna.nlp.thdr.sri", FT_BOOLEAN,
2896                     8, TFS(&sna_nlp_sri_truth), 0x08, "", HFILL }},
2897
2898                 { &hf_sna_nlp_rasapi,
2899                 { "Reply ASAP Indicator", "sna.nlp.thdr.rasapi", FT_BOOLEAN,
2900                     8, TFS(&sna_nlp_rasapi_truth), 0x04, "", HFILL }},
2901
2902                 { &hf_sna_nlp_retryi,
2903                 { "Retry Indicator", "sna.nlp.thdr.retryi", FT_BOOLEAN,
2904                     8, TFS(&sna_nlp_retryi_truth), 0x02, "", HFILL }},
2905
2906                 { &hf_sna_nlp_thdr_9,
2907                 { "RTP Transport Packet Header Byte 9", "sna.nlp.thdr.9",
2908                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
2909
2910                 { &hf_sna_nlp_lmi,
2911                 { "Last Message Indicator", "sna.nlp.thdr.lmi", FT_BOOLEAN,
2912                     8, TFS(&sna_nlp_lmi_truth), 0x80, "", HFILL }},
2913
2914                 { &hf_sna_nlp_cqfi,
2915                 { "Connection Qualifyer Field Indicator", "sna.nlp.thdr.cqfi",
2916                     FT_BOOLEAN, 8, TFS(&sna_nlp_cqfi_truth), 0x08, "", HFILL }},
2917
2918                 { &hf_sna_nlp_osi,
2919                 { "Optional Segments Present Indicator", "sna.nlp.thdr.osi",
2920                     FT_BOOLEAN, 8, TFS(&sna_nlp_osi_truth), 0x04, "", HFILL }},
2921
2922                 { &hf_sna_nlp_offset,
2923                 { "Data Offset/4", "sna.nlp.thdr.offset", FT_UINT16, BASE_HEX,
2924                     NULL, 0x0, "Data Offset in Words", HFILL }},
2925
2926                 { &hf_sna_nlp_dlf,
2927                 { "Data Length Field", "sna.nlp.thdr.dlf", FT_UINT32, BASE_HEX,
2928                     NULL, 0x0, "", HFILL }},
2929
2930                 { &hf_sna_nlp_bsn,
2931                 { "Byte Sequence Number", "sna.nlp.thdr.bsn", FT_UINT32,
2932                     BASE_HEX, NULL, 0x0, "", HFILL }},
2933
2934                 { &hf_sna_nlp_opti_len,
2935                 { "Optional Segment Length/4", "sna.nlp.thdr.optional.len",
2936                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
2937
2938                 { &hf_sna_nlp_opti_type,
2939                 { "Optional Segment Type", "sna.nlp.thdr.optional.type",
2940                     FT_UINT8, BASE_HEX, VALS(sna_nlp_opti_vals), 0x0, "",
2941                     HFILL }},
2942
2943                 { &hf_sna_nlp_opti_0d_version,
2944                 { "Version", "sna.nlp.thdr.optional.0d.version",
2945                     FT_UINT16, BASE_HEX, VALS(sna_nlp_opti_0d_version_vals),
2946                     0, "", HFILL }},
2947
2948                 { &hf_sna_nlp_opti_0d_4,
2949                 { "Connection Setup Byte 4", "sna.nlp.thdr.optional.0e.4",
2950                     FT_UINT8, BASE_HEX, NULL, 0, "", HFILL }},
2951
2952                 { &hf_sna_nlp_opti_0d_target,
2953                 { "Target Resource ID Present",
2954                     "sna.nlp.thdr.optional.0d.target",
2955                     FT_BOOLEAN, 8, NULL, 0x80, "", HFILL }},
2956
2957                 { &hf_sna_nlp_opti_0d_arb,
2958                 { "ARB Flow Control", "sna.nlp.thdr.optional.0d.arb",
2959                     FT_BOOLEAN, 8, NULL, 0x10, "", HFILL }},
2960
2961                 { &hf_sna_nlp_opti_0d_reliable,
2962                 { "Reliable Connection", "sna.nlp.thdr.optional.0d.reliable",
2963                     FT_BOOLEAN, 8, NULL, 0x08, "", HFILL }},
2964
2965                 { &hf_sna_nlp_opti_0d_dedicated,
2966                 { "Dedicated RTP Connection",
2967                     "sna.nlp.thdr.optional.0d.dedicated",
2968                     FT_BOOLEAN, 8, NULL, 0x04, "", HFILL }},
2969
2970                 { &hf_sna_nlp_opti_0e_stat,
2971                 { "Status", "sna.nlp.thdr.optional.0e.stat",
2972                     FT_UINT8, BASE_HEX, NULL, 0, "", HFILL }},
2973
2974                 { &hf_sna_nlp_opti_0e_gap,
2975                 { "Gap Detected", "sna.nlp.thdr.optional.0e.gap",
2976                     FT_BOOLEAN, 8, NULL, 0x80, "", HFILL }},
2977
2978                 { &hf_sna_nlp_opti_0e_idle,
2979                 { "RTP Idle Packet", "sna.nlp.thdr.optional.0e.idle",
2980                     FT_BOOLEAN, 8, NULL, 0x40, "", HFILL }},
2981
2982                 { &hf_sna_nlp_opti_0e_nabsp,
2983                 { "Number Of ABSP", "sna.nlp.thdr.optional.0e.nabsp",
2984                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
2985
2986                 { &hf_sna_nlp_opti_0e_sync,
2987                 { "Status Report Number", "sna.nlp.thdr.optional.0e.sync",
2988                     FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
2989
2990                 { &hf_sna_nlp_opti_0e_echo,
2991                 { "Status Acknowledge Number", "sna.nlp.thdr.optional.0e.echo",
2992                     FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
2993
2994                 { &hf_sna_nlp_opti_0e_rseq,
2995                 { "Received Sequence Number", "sna.nlp.thdr.optional.0e.rseq",
2996                     FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
2997
2998                 { &hf_sna_nlp_opti_0e_abspbeg,
2999                 { "ABSP Begin", "sna.nlp.thdr.optional.0e.abspbeg",
3000                     FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
3001
3002                 { &hf_sna_nlp_opti_0e_abspend,
3003                 { "ABSP End", "sna.nlp.thdr.optional.0e.abspend",
3004                     FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
3005
3006                 { &hf_sna_nlp_opti_0f_bits,
3007                 { "Client Bits", "sna.nlp.thdr.optional.0f.bits",
3008                     FT_UINT8, BASE_HEX, VALS(sna_nlp_opti_0f_bits_vals),
3009                     0x0, "", HFILL }},
3010
3011                 { &hf_sna_nlp_opti_10_tcid,
3012                 { "Transport Connection Identifier",
3013                     "sna.nlp.thdr.optional.10.tcid",
3014                     FT_BYTES, BASE_HEX, NULL, 0x0, "TCID", HFILL }},
3015
3016                 { &hf_sna_nlp_opti_12_sense,
3017                 { "Sense Data", "sna.nlp.thdr.optional.12.sense",
3018                     FT_BYTES, BASE_HEX, NULL, 0x0, "", HFILL }},
3019
3020                 { &hf_sna_nlp_opti_14_si_len,
3021                 { "Length", "sna.nlp.thdr.optional.14.si.len",
3022                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3023
3024                 { &hf_sna_nlp_opti_14_si_key,
3025                 { "Key", "sna.nlp.thdr.optional.14.si.key",
3026                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3027
3028                 { &hf_sna_nlp_opti_14_si_2,
3029                 { "Switching Information Byte 2",
3030                     "sna.nlp.thdr.optional.14.si.2",
3031                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3032
3033                 { &hf_sna_nlp_opti_14_si_refifo,
3034                 { "Resequencing (REFIFO) Indicator",
3035                     "sna.nlp.thdr.optional.14.si.refifo",
3036                     FT_BOOLEAN, 8, NULL, 0x80, "", HFILL }},
3037
3038                 { &hf_sna_nlp_opti_14_si_mobility,
3039                 { "Mobility Indicator",
3040                     "sna.nlp.thdr.optional.14.si.mobility",
3041                     FT_BOOLEAN, 8, NULL, 0x40, "", HFILL }},
3042
3043                 { &hf_sna_nlp_opti_14_si_dirsearch,
3044                 { "Directory Search Required on Path Switch Indicator",
3045                     "sna.nlp.thdr.optional.14.si.dirsearch",
3046                     FT_BOOLEAN, 8, NULL, 0x20, "", HFILL }},
3047
3048                 { &hf_sna_nlp_opti_14_si_limitres,
3049                 { "Limited Resource Link Indicator",
3050                     "sna.nlp.thdr.optional.14.si.limitres",
3051                     FT_BOOLEAN, 8, NULL, 0x10, "", HFILL }},
3052
3053                 { &hf_sna_nlp_opti_14_si_ncescope,
3054                 { "NCE Scope Indicator",
3055                     "sna.nlp.thdr.optional.14.si.ncescope",
3056                     FT_BOOLEAN, 8, NULL, 0x08, "", HFILL }},
3057
3058                 { &hf_sna_nlp_opti_14_si_mnpsrscv,
3059                 { "MNPS RSCV Retention Indicator",
3060                     "sna.nlp.thdr.optional.14.si.mnpsrscv",
3061                     FT_BOOLEAN, 8, NULL, 0x04, "", HFILL }},
3062
3063                 { &hf_sna_nlp_opti_14_si_maxpsize,
3064                 { "Maximum Packet Size On Return Path",
3065                     "sna.nlp.thdr.optional.14.si.maxpsize",
3066                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3067
3068                 { &hf_sna_nlp_opti_14_si_switch,
3069                 { "Path Switch Time", "sna.nlp.thdr.optional.14.si.switch",
3070                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3071
3072                 { &hf_sna_nlp_opti_14_si_alive,
3073                 { "RTP Alive Timer", "sna.nlp.thdr.optional.14.si.alive",
3074                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3075
3076                 { &hf_sna_nlp_opti_14_rr_len,
3077                 { "Length", "sna.nlp.thdr.optional.14.rr.len",
3078                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3079
3080                 { &hf_sna_nlp_opti_14_rr_key,
3081                 { "Key", "sna.nlp.thdr.optional.14.rr.key",
3082                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3083
3084                 { &hf_sna_nlp_opti_14_rr_2,
3085                 { "Return Route TG Descriptor Byte 2",
3086                     "sna.nlp.thdr.optional.14.rr.2",
3087                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3088
3089                 { &hf_sna_nlp_opti_14_rr_bfe,
3090                 { "BF Entry Indicator",
3091                     "sna.nlp.thdr.optional.14.rr.bfe",
3092                     FT_BOOLEAN, 8, NULL, 0x80, "", HFILL }},
3093
3094                 { &hf_sna_nlp_opti_14_rr_num,
3095                 { "Number Of TG Control Vectors",
3096                     "sna.nlp.thdr.optional.14.rr.num",
3097                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3098
3099                 { &hf_sna_nlp_opti_22_2,
3100                 { "Adaptive Rate Based Segment Byte 2",
3101                     "sna.nlp.thdr.optional.22.2",
3102                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3103
3104                 { &hf_sna_nlp_opti_22_type,
3105                 { "Message Type",
3106                     "sna.nlp.thdr.optional.22.type",
3107                     FT_UINT8, BASE_HEX,
3108                     VALS(sna_nlp_opti_22_type_vals), 0xc0, "", HFILL }},
3109
3110                 { &hf_sna_nlp_opti_22_raa,
3111                 { "Rate Adjustment Action",
3112                     "sna.nlp.thdr.optional.22.raa",
3113                     FT_UINT8, BASE_HEX,
3114                     VALS(sna_nlp_opti_22_raa_vals), 0x38, "", HFILL }},
3115
3116                 { &hf_sna_nlp_opti_22_parity,
3117                 { "Parity Indicator",
3118                     "sna.nlp.thdr.optional.22.parity",
3119                     FT_BOOLEAN, 8, NULL, 0x04, "", HFILL }},
3120
3121                 { &hf_sna_nlp_opti_22_arb,
3122                 { "ARB Mode",
3123                     "sna.nlp.thdr.optional.22.arb",
3124                     FT_UINT8, BASE_HEX,
3125                     VALS(sna_nlp_opti_22_arb_vals), 0x03, "", HFILL }},
3126
3127                 { &hf_sna_nlp_opti_22_3,
3128                 { "Adaptive Rate Based Segment Byte 3",
3129                     "sna.nlp.thdr.optional.22.3",
3130                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3131
3132                 { &hf_sna_nlp_opti_22_ratereq,
3133                 { "Rate Request Correlator",
3134                     "sna.nlp.thdr.optional.22.ratereq",
3135                     FT_UINT8, BASE_DEC, NULL, 0xf0, "", HFILL }},
3136
3137                 { &hf_sna_nlp_opti_22_raterep,
3138                 { "Rate Reply Correlator",
3139                     "sna.nlp.thdr.optional.22.raterep",
3140                     FT_UINT8, BASE_DEC, NULL, 0x0f, "", HFILL }},
3141
3142                 { &hf_sna_nlp_opti_22_field1,
3143                 { "Field 1", "sna.nlp.thdr.optional.22.field1",
3144                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3145
3146                 { &hf_sna_nlp_opti_22_field2,
3147                 { "Field 2", "sna.nlp.thdr.optional.22.field2",
3148                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3149
3150                 { &hf_sna_nlp_opti_22_field3,
3151                 { "Field 3", "sna.nlp.thdr.optional.22.field3",
3152                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3153
3154                 { &hf_sna_nlp_opti_22_field4,
3155                 { "Field 4", "sna.nlp.thdr.optional.22.field4",
3156                     FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
3157
3158                 { &hf_sna_rh,
3159                 { "Request/Response Header", "sna.rh", FT_NONE, BASE_NONE,
3160                     NULL, 0x0, "", HFILL }},
3161
3162                 { &hf_sna_rh_0,
3163                 { "Request/Response Header Byte 0", "sna.rh.0", FT_UINT8,
3164                     BASE_HEX, NULL, 0x0, "", HFILL }},
3165
3166                 { &hf_sna_rh_1,
3167                 { "Request/Response Header Byte 1", "sna.rh.1", FT_UINT8,
3168                     BASE_HEX, NULL, 0x0, "", HFILL }},
3169
3170                 { &hf_sna_rh_2,
3171                 { "Request/Response Header Byte 2", "sna.rh.2", FT_UINT8,
3172                     BASE_HEX, NULL, 0x0, "", HFILL }},
3173
3174                 { &hf_sna_rh_rri,
3175                 { "Request/Response Indicator", "sna.rh.rri", FT_UINT8,
3176                     BASE_DEC, VALS(sna_rh_rri_vals), 0x80, "", HFILL }},
3177
3178                 { &hf_sna_rh_ru_category,
3179                 { "Request/Response Unit Category", "sna.rh.ru_category",
3180                     FT_UINT8, BASE_HEX, VALS(sna_rh_ru_category_vals), 0x60,
3181                     "", HFILL }},
3182
3183                 { &hf_sna_rh_fi,
3184                 { "Format Indicator", "sna.rh.fi", FT_BOOLEAN, 8,
3185                     TFS(&sna_rh_fi_truth), 0x08, "", HFILL }},
3186
3187                 { &hf_sna_rh_sdi,
3188                 { "Sense Data Included", "sna.rh.sdi", FT_BOOLEAN, 8,
3189                     TFS(&sna_rh_sdi_truth), 0x04, "", HFILL }},
3190
3191                 { &hf_sna_rh_bci,
3192                 { "Begin Chain Indicator", "sna.rh.bci", FT_BOOLEAN, 8,
3193                     TFS(&sna_rh_bci_truth), 0x02, "", HFILL }},
3194
3195                 { &hf_sna_rh_eci,
3196                 { "End Chain Indicator", "sna.rh.eci", FT_BOOLEAN, 8,
3197                     TFS(&sna_rh_eci_truth), 0x01, "", HFILL }},
3198
3199                 { &hf_sna_rh_dr1,
3200                 { "Definite Response 1 Indicator", "sna.rh.dr1", FT_BOOLEAN,
3201                     8, NULL, 0x80, "", HFILL }},
3202
3203                 { &hf_sna_rh_lcci,
3204                 { "Length-Checked Compression Indicator", "sna.rh.lcci",
3205                     FT_BOOLEAN, 8, TFS(&sna_rh_lcci_truth), 0x40, "", HFILL }},
3206
3207                 { &hf_sna_rh_dr2,
3208                 { "Definite Response 2 Indicator", "sna.rh.dr2", FT_BOOLEAN,
3209                     8, NULL, 0x20, "", HFILL }},
3210
3211                 { &hf_sna_rh_eri,
3212                 { "Exception Response Indicator", "sna.rh.eri", FT_BOOLEAN,
3213                     8, NULL, 0x10, "", HFILL }},
3214
3215                 { &hf_sna_rh_rti,
3216                 { "Response Type Indicator", "sna.rh.rti", FT_BOOLEAN,
3217                     8, TFS(&sna_rh_rti_truth), 0x10, "", HFILL }},
3218
3219                 { &hf_sna_rh_rlwi,
3220                 { "Request Larger Window Indicator", "sna.rh.rlwi", FT_BOOLEAN,
3221                     8, NULL, 0x04, "", HFILL }},
3222
3223                 { &hf_sna_rh_qri,
3224                 { "Queued Response Indicator", "sna.rh.qri", FT_BOOLEAN,
3225                     8, TFS(&sna_rh_qri_truth), 0x02, "", HFILL }},
3226
3227                 { &hf_sna_rh_pi,
3228                 { "Pacing Indicator", "sna.rh.pi", FT_BOOLEAN,
3229                     8, NULL, 0x01, "", HFILL }},
3230
3231                 { &hf_sna_rh_bbi,
3232                 { "Begin Bracket Indicator", "sna.rh.bbi", FT_BOOLEAN,
3233                     8, NULL, 0x80, "", HFILL }},
3234
3235                 { &hf_sna_rh_ebi,
3236                 { "End Bracket Indicator", "sna.rh.ebi", FT_BOOLEAN,
3237                     8, NULL, 0x40, "", HFILL }},
3238
3239                 { &hf_sna_rh_cdi,
3240                 { "Change Direction Indicator", "sna.rh.cdi", FT_BOOLEAN,
3241                     8, NULL, 0x20, "", HFILL }},
3242
3243                 { &hf_sna_rh_csi,
3244                 { "Code Selection Indicator", "sna.rh.csi", FT_UINT8, BASE_DEC,
3245                     VALS(sna_rh_csi_vals), 0x08, "", HFILL }},
3246
3247                 { &hf_sna_rh_edi,
3248                 { "Enciphered Data Indicator", "sna.rh.edi", FT_BOOLEAN, 8,
3249                     NULL, 0x04, "", HFILL }},
3250
3251                 { &hf_sna_rh_pdi,
3252                 { "Padded Data Indicator", "sna.rh.pdi", FT_BOOLEAN, 8, NULL,
3253                     0x02, "", HFILL }},
3254
3255                 { &hf_sna_rh_cebi,
3256                 { "Conditional End Bracket Indicator", "sna.rh.cebi",
3257                     FT_BOOLEAN, 8, NULL, 0x01, "", HFILL }},
3258
3259 /*              { &hf_sna_ru,
3260                 { "Request/Response Unit", "sna.ru", FT_NONE, BASE_NONE,
3261                     NULL, 0x0, "", HFILL }},*/
3262
3263                 { &hf_sna_gds,
3264                 { "GDS Variable", "sna.gds", FT_NONE, BASE_NONE, NULL, 0x0,
3265                     "", HFILL }},
3266
3267                 { &hf_sna_gds_len,
3268                 { "GDS Variable Length", "sna.gds.len", FT_UINT16, BASE_DEC,
3269                     NULL, 0x7fff, "", HFILL }},
3270
3271                 { &hf_sna_gds_cont,
3272                 { "Continuation Flag", "sna.gds.cont", FT_BOOLEAN, 16, NULL,
3273                     0x8000, "", HFILL }},
3274
3275                 { &hf_sna_gds_type,
3276                 { "Type of Variable", "sna.gds.type", FT_UINT16, BASE_HEX,
3277                     VALS(sna_gds_var_vals), 0x0, "", HFILL }},
3278
3279                 { &hf_sna_xid,
3280                 { "XID", "sna.xid", FT_NONE, BASE_NONE, NULL, 0x0,
3281                     "XID Frame", HFILL }},
3282
3283                 { &hf_sna_xid_0,
3284                 { "XID Byte 0", "sna.xid.0", FT_UINT8, BASE_HEX, NULL, 0x0,
3285                     "", HFILL }},
3286
3287                 { &hf_sna_xid_format,
3288                 { "XID Format", "sna.xid.format", FT_UINT8, BASE_DEC, NULL,
3289                     0xf0, "", HFILL }},
3290
3291                 { &hf_sna_xid_type,
3292                 { "XID Type", "sna.xid.type", FT_UINT8, BASE_DEC,
3293                     VALS(sna_xid_type_vals), 0x0f, "", HFILL }},
3294
3295                 { &hf_sna_xid_len,
3296                 { "XID Length", "sna.xid.len", FT_UINT8, BASE_DEC, NULL, 0x0,
3297                     "", HFILL }},
3298
3299                 { &hf_sna_xid_id,
3300                 { "Node Identification", "sna.xid.id", FT_UINT32, BASE_HEX,
3301                     NULL, 0x0, "", HFILL }},
3302
3303                 { &hf_sna_xid_idblock,
3304                 { "ID Block", "sna.xid.idblock", FT_UINT32, BASE_HEX, NULL, 
3305                     0xfff00000, "", HFILL }},
3306
3307                 { &hf_sna_xid_idnum,
3308                 { "ID Number", "sna.xid.idnum", FT_UINT32, BASE_HEX, NULL,
3309                     0x0fffff, "", HFILL }},
3310
3311                 { &hf_sna_xid_3_8,
3312                 { "Characteristics of XID sender", "sna.xid.type3.8", FT_UINT16,
3313                     BASE_HEX, NULL, 0x0, "", HFILL }},
3314
3315                 { &hf_sna_xid_3_init_self,
3316                 { "INIT-SELF support", "sna.xid.type3.initself",
3317                     FT_BOOLEAN, 16, NULL, 0x8000, "", HFILL }},
3318
3319                 { &hf_sna_xid_3_stand_bind,
3320                 { "Stand-Alone BIND Support", "sna.xid.type3.stand_bind",
3321                     FT_BOOLEAN, 16, NULL, 0x4000, "", HFILL }},
3322
3323                 { &hf_sna_xid_3_gener_bind,
3324                 { "Whole BIND PIU generated indicator",
3325                     "sna.xid.type3.gener_bind", FT_BOOLEAN, 16, NULL, 0x2000,
3326                     "Whole BIND PIU generated", HFILL }},
3327
3328                 { &hf_sna_xid_3_recve_bind,
3329                 { "Whole BIND PIU required indicator",
3330                     "sna.xid.type3.recve_bind", FT_BOOLEAN, 16, NULL, 0x1000,
3331                     "Whole BIND PIU required", HFILL }},
3332
3333                 { &hf_sna_xid_3_actpu,
3334                 { "ACTPU suppression indicator", "sna.xid.type3.actpu",
3335                     FT_BOOLEAN, 16, NULL, 0x0080, "", HFILL }},
3336
3337                 { &hf_sna_xid_3_nwnode,
3338                 { "Sender is network node", "sna.xid.type3.nwnode",
3339                     FT_BOOLEAN, 16, NULL, 0x0040, "", HFILL }},
3340
3341                 { &hf_sna_xid_3_cp,
3342                 { "Control Point Services", "sna.xid.type3.cp",
3343                     FT_BOOLEAN, 16, NULL, 0x0020, "", HFILL }},
3344
3345                 { &hf_sna_xid_3_cpcp,
3346                 { "CP-CP session support", "sna.xid.type3.cpcp",
3347                     FT_BOOLEAN, 16, NULL, 0x0010, "", HFILL }},
3348
3349                 { &hf_sna_xid_3_state,
3350                 { "XID exchange state indicator", "sna.xid.type3.state",
3351                     FT_UINT16, BASE_HEX, VALS(sna_xid_3_state_vals),
3352                     0x000c, "", HFILL }},
3353
3354                 { &hf_sna_xid_3_nonact,
3355                 { "Nonactivation Exchange", "sna.xid.type3.nonact",
3356                     FT_BOOLEAN, 16, NULL, 0x0002, "", HFILL }},
3357
3358                 { &hf_sna_xid_3_cpchange,
3359                 { "CP name change support", "sna.xid.type3.cpchange",
3360                     FT_BOOLEAN, 16, NULL, 0x0001, "", HFILL }},
3361
3362                 { &hf_sna_xid_3_10,
3363                 { "XID Type 3 Byte 10", "sna.xid.type3.10", FT_UINT8, BASE_HEX,
3364                     NULL, 0x0, "", HFILL }},
3365
3366                 { &hf_sna_xid_3_asend_bind,
3367                 { "Adaptive BIND pacing support as sender",
3368                     "sna.xid.type3.asend_bind", FT_BOOLEAN, 8, NULL, 0x80,
3369                     "Pacing support as sender", HFILL }},
3370
3371                 { &hf_sna_xid_3_arecv_bind,
3372                 { "Adaptive BIND pacing support as receiver",
3373                     "sna.xid.type3.asend_recv", FT_BOOLEAN, 8, NULL, 0x40,
3374                     "Pacing support as receive", HFILL }},
3375
3376                 { &hf_sna_xid_3_quiesce,
3377                 { "Quiesce TG Request",
3378                     "sna.xid.type3.quiesce", FT_BOOLEAN, 8, NULL, 0x20,
3379                     "", HFILL }},
3380
3381                 { &hf_sna_xid_3_pucap,
3382                 { "PU Capabilities",
3383                     "sna.xid.type3.pucap", FT_BOOLEAN, 8, NULL, 0x10,
3384                     "", HFILL }},
3385
3386                 { &hf_sna_xid_3_pbn,
3387                 { "Peripheral Border Node",
3388                     "sna.xid.type3.pbn", FT_BOOLEAN, 8, NULL, 0x08,
3389                     "", HFILL }},
3390
3391                 { &hf_sna_xid_3_pacing,
3392                 { "Qualifier for adaptive BIND pacing support",
3393                     "sna.xid.type3.pacing", FT_UINT8, BASE_HEX, NULL, 0x03,
3394                     "", HFILL }},
3395
3396                 { &hf_sna_xid_3_11,
3397                 { "XID Type 3 Byte 11", "sna.xid.type3.11", FT_UINT8, BASE_HEX,
3398                     NULL, 0x0, "", HFILL }},
3399
3400                 { &hf_sna_xid_3_tgshare,
3401                 { "TG Sharing Prohibited Indicator",
3402                     "sna.xid.type3.tgshare", FT_BOOLEAN, 8, NULL, 0x40,
3403                     "", HFILL }},
3404
3405                 { &hf_sna_xid_3_dedsvc,
3406                 { "Dedicated SVC Idicator",
3407                     "sna.xid.type3.dedsvc", FT_BOOLEAN, 8, NULL, 0x20,
3408                     "", HFILL }},
3409
3410                 { &hf_sna_xid_3_12,
3411                 { "XID Type 3 Byte 12", "sna.xid.type3.12", FT_UINT8, BASE_HEX,
3412                     NULL, 0x0, "", HFILL }},
3413
3414                 { &hf_sna_xid_3_negcsup,
3415                 { "Negotiation Complete Supported",
3416                     "sna.xid.type3.negcsup", FT_BOOLEAN, 8, NULL, 0x80,
3417                     "", HFILL }},
3418
3419                 { &hf_sna_xid_3_negcomp,
3420                 { "Negotiation Complete",
3421                     "sna.xid.type3.negcomp", FT_BOOLEAN, 8, NULL, 0x40,
3422                     "", HFILL }},
3423
3424                 { &hf_sna_xid_3_15,
3425                 { "XID Type 3 Byte 15", "sna.xid.type3.15", FT_UINT8, BASE_HEX,
3426                     NULL, 0x0, "", HFILL }},
3427
3428                 { &hf_sna_xid_3_partg,
3429                 { "Parallel TG Support",
3430                     "sna.xid.type3.partg", FT_BOOLEAN, 8, NULL, 0x80,
3431                     "", HFILL }},
3432
3433                 { &hf_sna_xid_3_dlur,
3434                 { "Dependent LU Requester Indicator",
3435                     "sna.xid.type3.dlur", FT_BOOLEAN, 8, NULL, 0x40,
3436                     "", HFILL }},
3437
3438                 { &hf_sna_xid_3_dlus,
3439                 { "DLUS Served LU Registration Indicator",
3440                     "sna.xid.type3.dlus", FT_BOOLEAN, 8, NULL, 0x20,
3441                     "", HFILL }},
3442
3443                 { &hf_sna_xid_3_exbn,
3444                 { "Extended HPR Border Node",
3445                     "sna.xid.type3.exbn", FT_BOOLEAN, 8, NULL, 0x10,
3446                     "", HFILL }},
3447
3448                 { &hf_sna_xid_3_genodai,
3449                 { "Generalized ODAI Usage Option",
3450                     "sna.xid.type3.genodai", FT_BOOLEAN, 8, NULL, 0x08,
3451                     "", HFILL }},
3452
3453                 { &hf_sna_xid_3_branch,
3454                 { "Branch Indicator", "sna.xid.type3.branch",
3455                     FT_UINT8, BASE_HEX, VALS(sna_xid_3_branch_vals),
3456                     0x06, "", HFILL }},
3457
3458                 { &hf_sna_xid_3_brnn,
3459                 { "Option Set 1123 Indicator",
3460                     "sna.xid.type3.brnn", FT_BOOLEAN, 8, NULL, 0x01,
3461                     "", HFILL }},
3462
3463                 { &hf_sna_xid_3_tg,
3464                 { "XID TG", "sna.xid.type3.tg", FT_UINT8, BASE_HEX, NULL, 0x0,
3465                     "", HFILL }},
3466
3467                 { &hf_sna_xid_3_dlc,
3468                 { "XID DLC", "sna.xid.type3.dlc", FT_UINT8, BASE_HEX, NULL, 0x0,
3469                     "", HFILL }},
3470
3471                 { &hf_sna_xid_3_dlen,
3472                 { "DLC Dependent Section Length", "sna.xid.type3.dlen",
3473                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3474
3475                 { &hf_sna_control_len,
3476                 { "Control Vector Length", "sna.control.len",
3477                     FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
3478
3479                 { &hf_sna_control_key,
3480                 { "Control Vector Key", "sna.control.key",
3481                     FT_UINT8, BASE_HEX, VALS(sna_control_vals), 0x0, "",
3482                     HFILL }},
3483
3484                 { &hf_sna_control_hprkey,
3485                 { "Control Vector HPR Key", "sna.control.hprkey",
3486                     FT_UINT8, BASE_HEX, VALS(sna_control_hpr_vals), 0x0, "",
3487                     HFILL }},
3488         
3489                 { &hf_sna_control_05_delay,
3490                 { "Channel Delay", "sna.control.05.delay",
3491                     FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
3492         
3493                 { &hf_sna_control_05_type,
3494                 { "Network Address Type", "sna.control.05.type",
3495                     FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
3496         
3497                 { &hf_sna_control_05_ptp,
3498                 { "Point-to-point", "sna.control.05.ptp",
3499                     FT_BOOLEAN, 8, NULL, 0x80, "", HFILL }},
3500         
3501                 { &hf_sna_control_0e_type,
3502                 { "Type", "sna.control.0e.type",
3503                     FT_UINT8, BASE_HEX, VALS(sna_control_0e_type_vals),
3504                     0, "", HFILL }},
3505         
3506                 { &hf_sna_control_0e_value,
3507                 { "Value", "sna.control.0e.value",
3508                     FT_STRING, BASE_NONE, NULL, 0, "", HFILL }},
3509         };
3510         static gint *ett[] = {
3511                 &ett_sna,
3512                 &ett_sna_th,
3513                 &ett_sna_th_fid,
3514                 &ett_sna_nlp_nhdr,
3515                 &ett_sna_nlp_nhdr_0,
3516                 &ett_sna_nlp_nhdr_1,
3517                 &ett_sna_nlp_thdr,
3518                 &ett_sna_nlp_thdr_8,
3519                 &ett_sna_nlp_thdr_9,
3520                 &ett_sna_nlp_opti_un,
3521                 &ett_sna_nlp_opti_0d,
3522                 &ett_sna_nlp_opti_0d_4,
3523                 &ett_sna_nlp_opti_0e,
3524                 &ett_sna_nlp_opti_0e_stat,
3525                 &ett_sna_nlp_opti_0e_absp,
3526                 &ett_sna_nlp_opti_0f,
3527                 &ett_sna_nlp_opti_10,
3528                 &ett_sna_nlp_opti_12,
3529                 &ett_sna_nlp_opti_14,
3530                 &ett_sna_nlp_opti_14_si,
3531                 &ett_sna_nlp_opti_14_si_2,
3532                 &ett_sna_nlp_opti_14_rr,
3533                 &ett_sna_nlp_opti_14_rr_2,
3534                 &ett_sna_nlp_opti_22,
3535                 &ett_sna_nlp_opti_22_2,
3536                 &ett_sna_nlp_opti_22_3,
3537                 &ett_sna_rh,
3538                 &ett_sna_rh_0,
3539                 &ett_sna_rh_1,
3540                 &ett_sna_rh_2,
3541                 &ett_sna_gds,
3542                 &ett_sna_xid_0,
3543                 &ett_sna_xid_id,
3544                 &ett_sna_xid_3_8,
3545                 &ett_sna_xid_3_10,
3546                 &ett_sna_xid_3_11,
3547                 &ett_sna_xid_3_12,
3548                 &ett_sna_xid_3_15,
3549                 &ett_sna_control_un,
3550                 &ett_sna_control_05,
3551                 &ett_sna_control_05hpr,
3552                 &ett_sna_control_05hpr_type,
3553                 &ett_sna_control_0e,
3554         };
3555         module_t *sna_module;
3556
3557         proto_sna = proto_register_protocol("Systems Network Architecture",
3558             "SNA", "sna");
3559         proto_register_field_array(proto_sna, hf, array_length(hf));
3560         proto_register_subtree_array(ett, array_length(ett));
3561         register_dissector("sna", dissect_sna, proto_sna);
3562
3563         proto_sna_xid = proto_register_protocol(
3564             "Systems Network Architecture XID", "SNA XID", "sna_xid");
3565         register_dissector("sna_xid", dissect_sna_xid, proto_sna_xid);
3566
3567         /* Register configuration options */
3568         sna_module = prefs_register_protocol(proto_sna, NULL);
3569         prefs_register_bool_preference(sna_module, "defragment",
3570                 "Reassemble fragmented BIUs",
3571                 "Whether fragmented BIUs should be reassembled",
3572                 &sna_defragment);
3573 }
3574
3575 void
3576 proto_reg_handoff_sna(void)
3577 {
3578         dissector_handle_t sna_handle;
3579         dissector_handle_t sna_xid_handle;
3580
3581         sna_handle = find_dissector("sna");
3582         sna_xid_handle = find_dissector("sna_xid");
3583         dissector_add("llc.dsap", SAP_SNA_PATHCTRL, sna_handle);
3584         dissector_add("llc.dsap", SAP_SNA1, sna_handle);
3585         dissector_add("llc.dsap", SAP_SNA2, sna_handle);
3586         dissector_add("llc.dsap", SAP_SNA3, sna_handle);
3587         dissector_add("llc.xid_dsap", SAP_SNA_PATHCTRL, sna_xid_handle);
3588         dissector_add("llc.xid_dsap", SAP_SNA1, sna_xid_handle);
3589         dissector_add("llc.xid_dsap", SAP_SNA2, sna_xid_handle);
3590         dissector_add("llc.xid_dsap", SAP_SNA3, sna_xid_handle);
3591         /* RFC 2043 */
3592         dissector_add("ppp.protocol", PPP_SNA, sna_handle);
3593         data_handle = find_dissector("data");
3594
3595         register_init_routine(sna_init);
3596 }