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