"hf_sna_rh_csi" is now an FT_UINT8 field, so add it with
[obnox/wireshark/wip.git] / packet-sna.c
1 /* packet-sna.c
2  * Routines for SNA
3  * Gilbert Ramirez <gram@xiexie.org>
4  *
5  * $Id: packet-sna.c,v 1.22 2001/01/03 21:52:40 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@zing.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * 
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  * 
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  * 
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
35 #include <glib.h>
36 #include "packet.h"
37 #include "llcsaps.h"
38 #include "packet-sna.h"
39
40 /*
41  * http://www.wanresources.com/snacell.html
42  *
43  */
44
45 static int proto_sna = -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
89 static int hf_sna_rh = -1;
90 static int hf_sna_rh_0 = -1;
91 static int hf_sna_rh_1 = -1;
92 static int hf_sna_rh_2 = -1;
93 static int hf_sna_rh_rri = -1;
94 static int hf_sna_rh_ru_category = -1;
95 static int hf_sna_rh_fi = -1;
96 static int hf_sna_rh_sdi = -1;
97 static int hf_sna_rh_bci = -1;
98 static int hf_sna_rh_eci = -1;
99 static int hf_sna_rh_dr1 = -1;
100 static int hf_sna_rh_lcci = -1;
101 static int hf_sna_rh_dr2 = -1;
102 static int hf_sna_rh_eri = -1;
103 static int hf_sna_rh_rti = -1;
104 static int hf_sna_rh_rlwi = -1;
105 static int hf_sna_rh_qri = -1;
106 static int hf_sna_rh_pi = -1;
107 static int hf_sna_rh_bbi = -1;
108 static int hf_sna_rh_ebi = -1;
109 static int hf_sna_rh_cdi = -1;
110 static int hf_sna_rh_csi = -1;
111 static int hf_sna_rh_edi = -1;
112 static int hf_sna_rh_pdi = -1;
113 static int hf_sna_rh_cebi = -1;
114 /*static int hf_sna_ru = -1;*/
115
116 static gint ett_sna = -1;
117 static gint ett_sna_th = -1;
118 static gint ett_sna_th_fid = -1;
119 static gint ett_sna_rh = -1;
120 static gint ett_sna_rh_0 = -1;
121 static gint ett_sna_rh_1 = -1;
122 static gint ett_sna_rh_2 = -1;
123
124 /* Format Identifier */
125 static const value_string sna_th_fid_vals[] = {
126         { 0x0,  "SNA device <--> Non-SNA Device" },
127         { 0x1,  "Subarea Nodes, without ER or VR" },
128         { 0x2,  "Subarea Node <--> PU2" },
129         { 0x3,  "Subarea Node or SNA host <--> Subarea Node" },
130         { 0x4,  "Subarea Nodes, supporting ER and VR" },
131         { 0x5,  "HPR RTP endpoint nodes" },
132         { 0xf,  "Adjaced Subarea Nodes, supporting ER and VR" },
133         { 0x0,  NULL }
134 };
135
136 /* Mapping Field */
137 static const value_string sna_th_mpf_vals[] = {
138         { 0, "Middle segment of a BIU" },
139         { 1, "Last segment of a BIU" },
140         { 2, "First segment of a BIU" },
141         { 3 , "Whole BIU" },
142         { 0,   NULL }
143 };
144
145 /* Expedited Flow Indicator */
146 static const value_string sna_th_efi_vals[] = {
147         { 0, "Normal Flow" },
148         { 1, "Expedited Flow" },
149         { 0x0,  NULL }
150 };
151
152 /* Request/Response Indicator */
153 static const value_string sna_rh_rri_vals[] = {
154         { 0, "Request" },
155         { 1, "Response" },
156         { 0x0,  NULL }
157 };
158
159 /* Request/Response Unit Category */
160 static const value_string sna_rh_ru_category_vals[] = {
161         { 0x00, "Function Management Data (FMD)" },
162         { 0x01, "Network Control (NC)" },
163         { 0x10, "Data Flow Control (DFC)" },
164         { 0x11, "Session Control (SC)" },
165         { 0x0,  NULL }
166 };
167
168 /* Format Indicator */
169 static const true_false_string sna_rh_fi_truth =
170         { "FM Header", "No FM Header" };
171
172 /* Sense Data Included */
173 static const true_false_string sna_rh_sdi_truth =
174         { "Included", "Not Included" };
175
176 /* Begin Chain Indicator */
177 static const true_false_string sna_rh_bci_truth =
178         { "First in Chain", "Not First in Chain" };
179
180 /* End Chain Indicator */
181 static const true_false_string sna_rh_eci_truth =
182         { "Last in Chain", "Not Last in Chain" };
183
184 /* Lengith-Checked Compression Indicator */
185 static const true_false_string sna_rh_lcci_truth =
186         { "Compressed", "Not Compressed" };
187
188 /* Response Type Indicator */
189 static const true_false_string sna_rh_rti_truth =
190         { "Negative", "Positive" };
191
192 /* Exception Response Indicator */
193 static const true_false_string sna_rh_eri_truth =
194         { "Exception", "Definite" };
195
196 /* Queued Response Indicator */
197 static const true_false_string sna_rh_qri_truth =
198         { "Enqueue response in TC queues", "Response bypasses TC queues" };
199
200 /* Code Selection Indicator */
201 static const value_string sna_rh_csi_vals[] = {
202         { 0, "EBCDIC" },
203         { 1, "ASCII" },
204         { 0x0,  NULL }
205 };
206
207 /* TG Sweep */
208 static const value_string sna_th_tg_sweep_vals[] = {
209         { 0, "This PIU may overtake any PU ahead of it." },
210         { 1, "This PIU does not ovetake any PIU ahead of it." },
211         { 0x0,  NULL }
212 };
213
214 /* ER_VR_SUPP_IND */
215 static const value_string sna_th_er_vr_supp_ind_vals[] = {
216         { 0, "Each node supports ER and VR protocols" },
217         { 1, "Includes at least one node that does not support ER and VR protocols"  },
218         { 0x0,  NULL }
219 };
220
221 /* VR_PAC_CNT_IND */
222 static const value_string sna_th_vr_pac_cnt_ind_vals[] = {
223         { 0, "Pacing count on the VR has not reached 0" },
224         { 1, "Pacing count on the VR has reached 0" },
225         { 0x0,  NULL }
226 };
227
228 /* NTWK_PRTY */
229 static const value_string sna_th_ntwk_prty_vals[] = {
230         { 0, "PIU flows at a lower priority" },
231         { 1, "PIU flows at network priority (highest transmission priority)" },
232         { 0x0,  NULL }
233 };
234
235 /* TGSF */
236 static const value_string sna_th_tgsf_vals[] = {
237         { 0x00, "Not segmented" },
238         { 0x01, "Last segment" },
239         { 0x10, "First segment" },
240         { 0x11, "Middle segment" },
241         { 0x0,  NULL }
242 };
243
244 /* PIUBF */
245 static const value_string sna_th_piubf_vals[] = {
246         { 0x00, "Single PIU frame" },
247         { 0x01, "Last PIU of a multiple PIU frame" },
248         { 0x10, "First PIU of a multiple PIU frame" },
249         { 0x11, "Middle PIU of a multiple PIU frame" },
250         { 0x0,  NULL }
251 };
252
253 /* NLPOI */
254 static const value_string sna_th_nlpoi_vals[] = {
255         { 0x0, "NLP starts within this FID4 TH" },
256         { 0x1, "NLP byte 0 starts after RH byte 0 following NLP C/P pad" },
257         { 0x0,  NULL }
258 };
259
260 /* TPF */
261 static const value_string sna_th_tpf_vals[] = {
262         { 0x00, "Low Priority" },
263         { 0x01, "Medium Priority" },
264         { 0x10, "High Priority" },
265         { 0x0,  NULL }
266 };
267
268 /* VR_CWI */
269 static const value_string sna_th_vr_cwi_vals[] = {
270         { 0x0, "Increment window size" },
271         { 0x1, "Decrement window size" },
272         { 0x0,  NULL }
273 };
274
275 /* TG_NONFIFO_IND */
276 static const true_false_string sna_th_tg_nonfifo_ind_truth =
277         { "TG FIFO is not required", "TG FIFO is required" };
278
279 /* VR_SQTI */
280 static const value_string sna_th_vr_sqti_vals[] = {
281         { 0x00, "Non-sequenced, Non-supervisory" },
282         { 0x01, "Non-sequenced, Supervisory" },
283         { 0x10, "Singly-sequenced" },
284         { 0x0,  NULL }
285 };
286
287 /* VRPRQ */
288 static const true_false_string sna_th_vrprq_truth = {
289         "VR pacing request is sent asking for a VR pacing response",
290         "No VR pacing response is requested",
291 };
292
293 /* VRPRS */
294 static const true_false_string sna_th_vrprs_truth = {
295         "VR pacing response is sent in response to a VRPRQ bit set",
296         "No pacing response sent",
297 };
298
299 /* VR_CWRI */
300 static const value_string sna_th_vr_cwri_vals[] = {
301         { 0, "Increment window size by 1" },
302         { 1, "Decrement window size by 1" },
303         { 0x0,  NULL }
304 };
305
306 /* VR_RWI */
307 static const true_false_string sna_th_vr_rwi_truth = {
308         "Reset window size to the minimum specified in NC_ACTVR",
309         "Do not reset window size",
310 };
311
312 static int  dissect_fid0_1 (const u_char*, int, frame_data*, proto_tree*);
313 static int  dissect_fid2 (const u_char*, int, frame_data*, proto_tree*);
314 static int  dissect_fid3 (const u_char*, int, frame_data*, proto_tree*);
315 static int  dissect_fid4 (const u_char*, int, frame_data*, proto_tree*);
316 static int  dissect_fid5 (const u_char*, int, frame_data*, proto_tree*);
317 static int  dissect_fidf (const u_char*, int, frame_data*, proto_tree*);
318 static void dissect_rh (const u_char*, int, frame_data*, proto_tree*);
319
320 static void
321 dissect_sna(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
322
323         proto_tree      *sna_tree = NULL, *th_tree = NULL, *rh_tree = NULL;
324         proto_item      *sna_ti = NULL, *th_ti = NULL, *rh_ti = NULL;
325         guint8          th_fid;
326         int             sna_header_len = 0, th_header_len = 0;
327
328         OLD_CHECK_DISPLAY_AS_DATA(proto_sna, pd, offset, fd, tree);
329
330         /* SNA data should be printed in EBCDIC, not ASCII */
331         fd->flags.encoding = CHAR_EBCDIC;
332
333         if (IS_DATA_IN_FRAME(offset)) {
334                 /* Transmission Header Format Identifier */
335                 th_fid = hi_nibble(pd[offset]);
336         }
337         else {
338                 /* If our first byte isn't here, stop dissecting */
339                 return;
340         }
341
342         /* Summary information */
343         if (check_col(fd, COL_PROTOCOL))
344                 col_set_str(fd, COL_PROTOCOL, "SNA");
345         if (check_col(fd, COL_INFO))
346                 col_add_str(fd, COL_INFO, val_to_str(th_fid, sna_th_fid_vals, "Unknown FID: %01x"));
347
348         if (tree) {
349
350                 /* Don't bother setting length. We'll set it later after we find
351                  * the lengths of TH/RH/RU */
352                 sna_ti = proto_tree_add_item(tree, proto_sna, NullTVB, offset, 0, FALSE);
353                 sna_tree = proto_item_add_subtree(sna_ti, ett_sna);
354
355                 /* --- TH --- */
356                 /* Don't bother setting length. We'll set it later after we find
357                  * the length of TH */
358                 th_ti = proto_tree_add_item(sna_tree, hf_sna_th, NullTVB,  offset, 0, FALSE);
359                 th_tree = proto_item_add_subtree(th_ti, ett_sna_th);
360         }
361
362         /* Get size of TH */
363         switch(th_fid) {
364                 case 0x0:
365                 case 0x1:
366                         th_header_len = dissect_fid0_1(pd, offset, fd, th_tree);
367                         break;
368                 case 0x2:
369                         th_header_len = dissect_fid2(pd, offset, fd, th_tree);
370                         break;
371                 case 0x3:
372                         th_header_len = dissect_fid3(pd, offset, fd, th_tree);
373                         break;
374                 case 0x4:
375                         th_header_len = dissect_fid4(pd, offset, fd, th_tree);
376                         break;
377                 case 0x5:
378                         th_header_len = dissect_fid5(pd, offset, fd, th_tree);
379                         break;
380                 case 0xf:
381                         th_header_len = dissect_fidf(pd, offset, fd, th_tree);
382                         break;
383                 default:
384                         old_dissect_data(pd, offset+1, fd, tree);
385         }
386
387         sna_header_len += th_header_len;
388         offset += th_header_len;
389
390         if (tree) {
391                 proto_item_set_len(th_ti, th_header_len);
392
393                 /* --- RH --- */
394                 if (BYTES_ARE_IN_FRAME(offset, 3)) {
395                         rh_ti = proto_tree_add_item(sna_tree, hf_sna_rh, NullTVB, offset, 3, FALSE);
396                         rh_tree = proto_item_add_subtree(rh_ti, ett_sna_rh);
397                         dissect_rh(pd, offset, fd, rh_tree);
398                         sna_header_len += 3;
399                         offset += 3;
400                 }
401                 else {
402                         /* If our first byte isn't here, stop dissecting */
403                         return;
404                 }
405
406                 proto_item_set_len(sna_ti, sna_header_len);
407         }
408         else {
409                 if (BYTES_ARE_IN_FRAME(offset, 3)) {
410                         sna_header_len += 3;
411                         offset += 3;
412                 }
413
414         }
415
416         if (IS_DATA_IN_FRAME(offset+1)) {
417                 old_dissect_data(pd, offset, fd, tree);
418         }
419 }
420
421 /* FID Types 0 and 1 */
422 static int
423 dissect_fid0_1 (const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
424
425         proto_tree      *bf_tree;
426         proto_item      *bf_item;
427         guint8          th_0;
428         guint16         daf, oaf, snf, dcf;
429
430         static int bytes_in_header = 10;
431
432         if (!BYTES_ARE_IN_FRAME(offset, bytes_in_header)) {
433                 return 0;
434         }
435
436         th_0 = pd[offset+0];
437         daf = pntohs(&pd[offset+2]);
438         oaf = pntohs(&pd[offset+4]);
439         snf = pntohs(&pd[offset+6]);
440         dcf = pntohs(&pd[offset+8]);
441
442         SET_ADDRESS(&pi.net_src, AT_SNA, 2, &pd[offset+4]);
443         SET_ADDRESS(&pi.src, AT_SNA, 2, &pd[offset+4]);
444         SET_ADDRESS(&pi.net_dst, AT_SNA, 2, &pd[offset+2]);
445         SET_ADDRESS(&pi.dst, AT_SNA, 2, &pd[offset+2]);
446
447         if (!tree) {
448                 return bytes_in_header;
449         }
450
451         /* Create the bitfield tree */
452         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, NullTVB, offset, 1, th_0);
453         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
454
455         proto_tree_add_uint(bf_tree, hf_sna_th_fid, NullTVB, offset, 1, th_0);
456         proto_tree_add_uint(bf_tree, hf_sna_th_mpf, NullTVB, offset, 1, th_0);
457         proto_tree_add_uint(bf_tree, hf_sna_th_efi , NullTVB,offset, 1, th_0);
458
459         proto_tree_add_text(tree, NullTVB, offset+1, 1, "Reserved");
460         proto_tree_add_uint(tree, hf_sna_th_daf , NullTVB,offset+2, 1, daf);
461         proto_tree_add_uint(tree, hf_sna_th_oaf , NullTVB,offset+4, 1, oaf);
462         proto_tree_add_uint(tree, hf_sna_th_snf , NullTVB,offset+6, 2, snf);
463         proto_tree_add_uint(tree, hf_sna_th_dcf , NullTVB,offset+8, 2, dcf);
464
465         return bytes_in_header;
466
467 }
468
469
470 /* FID Type 2 */
471 static int
472 dissect_fid2 (const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
473
474         proto_tree      *bf_tree;
475         proto_item      *bf_item;
476         guint8          th_0, daf, oaf;
477         guint16         snf;
478
479         static int bytes_in_header = 6;
480
481         if (!BYTES_ARE_IN_FRAME(offset, bytes_in_header)) {
482                 return 0;
483         }
484
485         th_0 = pd[offset+0];
486         daf = pd[offset+2];
487         oaf = pd[offset+3];
488
489         /* Addresses in FID 2 are FT_UINT8 */
490         SET_ADDRESS(&pi.net_src, AT_SNA, 1, &pd[offset+3]);
491         SET_ADDRESS(&pi.src, AT_SNA, 1, &pd[offset+3]);
492         SET_ADDRESS(&pi.net_dst, AT_SNA, 1, &pd[offset+2]);
493         SET_ADDRESS(&pi.dst, AT_SNA, 1, &pd[offset+2]);
494
495         if (!tree) {
496                 return bytes_in_header;
497         }
498
499         snf = pntohs(&pd[offset+4]);
500
501         /* Create the bitfield tree */
502         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, NullTVB, offset, 1, th_0);
503         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
504
505         proto_tree_add_uint(bf_tree, hf_sna_th_fid, NullTVB, offset, 1, th_0);
506         proto_tree_add_uint(bf_tree, hf_sna_th_mpf, NullTVB, offset, 1, th_0);
507         proto_tree_add_uint(bf_tree, hf_sna_th_odai , NullTVB,offset, 1, th_0);
508         proto_tree_add_uint(bf_tree, hf_sna_th_efi , NullTVB,offset, 1, th_0);
509
510         /* Addresses in FID 2 are FT_UINT8 */
511         proto_tree_add_text(tree, NullTVB, offset+1, 1, "Reserved");
512         proto_tree_add_uint_format(tree, hf_sna_th_daf , NullTVB,offset+2, 1, daf,
513                         "Destination Address Field: 0x%02x", daf);
514         proto_tree_add_uint_format(tree, hf_sna_th_oaf , NullTVB,offset+3, 1, oaf,
515                         "Origin Address Field: 0x%02x", oaf);
516         proto_tree_add_uint(tree, hf_sna_th_snf , NullTVB,offset+4, 2, snf);
517
518         return bytes_in_header;
519 }
520
521 /* FID Type 3 */
522 static int
523 dissect_fid3 (const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
524
525         proto_tree      *bf_tree;
526         proto_item      *bf_item;
527         guint8          th_0;
528         guint8          lsid;
529
530         static int bytes_in_header = 2;
531
532         if (!BYTES_ARE_IN_FRAME(offset, bytes_in_header)) {
533                 return 0;
534         }
535
536         if (!tree) {
537                 return bytes_in_header;
538         }
539
540         th_0 = pd[offset+0];
541         lsid = pd[offset+1];
542
543         /* Create the bitfield tree */
544         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, NullTVB, offset, 1, th_0);
545         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
546
547         proto_tree_add_uint(bf_tree, hf_sna_th_fid, NullTVB, offset, 1, th_0);
548         proto_tree_add_uint(bf_tree, hf_sna_th_mpf, NullTVB, offset, 1, th_0);
549         proto_tree_add_uint(bf_tree, hf_sna_th_efi , NullTVB,offset, 1, th_0);
550
551         proto_tree_add_uint(tree, hf_sna_th_lsid , NullTVB,offset+1, 1, lsid);
552
553         return bytes_in_header;
554 }
555
556 /* FID Type 4 */
557
558 gchar *
559 sna_fid_type_4_addr_to_str(const struct sna_fid_type_4_addr *addrp)
560 {
561   static gchar  str[3][14];
562   static gchar  *cur;
563
564   if (cur == &str[0][0]) {
565     cur = &str[1][0];
566   } else if (cur == &str[1][0]) {
567     cur = &str[2][0];
568   } else {
569     cur = &str[0][0];
570   }
571
572   sprintf(cur, "%08X.%04X", addrp->saf, addrp->ef);
573   return cur;
574 }
575
576 static int
577 dissect_fid4 (const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
578
579         proto_tree      *bf_tree;
580         proto_item      *bf_item;
581         guint8          th_byte, mft;
582         guint16         th_word;
583         guint16         def, oef, snf, dcf;
584         guint32         dsaf, osaf;
585         static struct sna_fid_type_4_addr src, dst;
586
587         static int bytes_in_header = 26;
588
589         if (!BYTES_ARE_IN_FRAME(offset, bytes_in_header)) {
590                 return 0;
591         }
592
593         dsaf = pntohl(&pd[offset+8]);
594         osaf = pntohl(&pd[offset+12]);
595         def = pntohs(&pd[offset+18]);
596         oef = pntohs(&pd[offset+20]);
597         snf = pntohs(&pd[offset+22]);
598         dcf = pntohs(&pd[offset+24]);
599
600         /* Addresses in FID 4 are discontiguous, sigh */
601         src.saf = osaf;
602         src.ef = oef;
603         dst.saf = dsaf;
604         dst.ef = def;
605         SET_ADDRESS(&pi.net_src, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
606             (guint8 *)&src);
607         SET_ADDRESS(&pi.src, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
608             (guint8 *)&src);
609         SET_ADDRESS(&pi.net_dst, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
610             (guint8 *)&dst);
611         SET_ADDRESS(&pi.dst, AT_SNA, SNA_FID_TYPE_4_ADDR_LEN,
612             (guint8 *)&dst);
613
614         if (!tree) {
615                 return bytes_in_header;
616         }
617
618         th_byte = pd[offset];
619
620         /* Create the bitfield tree */
621         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, NullTVB, offset, 1, th_byte);
622         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
623
624         /* Byte 0 */
625         proto_tree_add_uint(bf_tree, hf_sna_th_fid, NullTVB, offset, 1, th_byte);
626         proto_tree_add_uint(bf_tree, hf_sna_th_tg_sweep, NullTVB, offset, 1, th_byte);
627         proto_tree_add_uint(bf_tree, hf_sna_th_er_vr_supp_ind, NullTVB, offset, 1, th_byte);
628         proto_tree_add_uint(bf_tree, hf_sna_th_vr_pac_cnt_ind, NullTVB, offset, 1, th_byte);
629         proto_tree_add_uint(bf_tree, hf_sna_th_ntwk_prty, NullTVB, offset, 1, th_byte);
630
631         offset += 1;
632         th_byte = pd[offset];
633
634         /* Create the bitfield tree */
635         bf_item = proto_tree_add_text(tree, NullTVB, offset, 1, "Transmision Header Byte 1");
636         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
637
638         /* Byte 1 */
639         proto_tree_add_uint(bf_tree, hf_sna_th_tgsf, NullTVB, offset, 1, th_byte);
640         proto_tree_add_boolean(bf_tree, hf_sna_th_mft, NullTVB, offset, 1, th_byte);
641         proto_tree_add_uint(bf_tree, hf_sna_th_piubf, NullTVB, offset, 1, th_byte);
642
643         mft = th_byte & 0x04;
644         offset += 1;
645         th_byte = pd[offset];
646
647         /* Create the bitfield tree */
648         bf_item = proto_tree_add_text(tree, NullTVB, offset, 1, "Transmision Header Byte 2");
649         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
650
651         /* Byte 2 */
652         if (mft) {
653                 proto_tree_add_uint(bf_tree, hf_sna_th_nlpoi, NullTVB, offset, 1, th_byte);
654                 proto_tree_add_uint(bf_tree, hf_sna_th_nlp_cp, NullTVB, offset, 1, th_byte);
655         }
656         else {
657                 proto_tree_add_uint(bf_tree, hf_sna_th_iern, NullTVB, offset, 1, th_byte);
658         }
659         proto_tree_add_uint(bf_tree, hf_sna_th_ern, NullTVB, offset, 1, th_byte);
660
661         offset += 1;
662         th_byte = pd[offset];
663
664         /* Create the bitfield tree */
665         bf_item = proto_tree_add_text(tree, NullTVB, offset, 1, "Transmision Header Byte 3");
666         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
667
668         /* Byte 3 */
669         proto_tree_add_uint(bf_tree, hf_sna_th_vrn, NullTVB, offset, 1, th_byte);
670         proto_tree_add_uint(bf_tree, hf_sna_th_tpf, NullTVB, offset, 1, th_byte);
671
672         offset += 1;
673         th_word = pntohs(&pd[offset]);
674
675         /* Create the bitfield tree */
676         bf_item = proto_tree_add_text(tree, NullTVB, offset, 2, "Transmision Header Bytes 4-5");
677         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
678
679         /* Bytes 4-5 */
680         proto_tree_add_uint(bf_tree, hf_sna_th_vr_cwi, NullTVB, offset, 2, th_word);
681         proto_tree_add_boolean(bf_tree, hf_sna_th_tg_nonfifo_ind, NullTVB, offset, 2, th_word);
682         proto_tree_add_uint(bf_tree, hf_sna_th_vr_sqti, NullTVB, offset, 2, th_word);
683
684         /* I'm not sure about byte-order on this one... */
685         proto_tree_add_uint(bf_tree, hf_sna_th_tg_snf, NullTVB, offset, 2, th_word);
686
687         offset += 2;
688         th_word = pntohs(&pd[offset]);
689
690         /* Create the bitfield tree */
691         bf_item = proto_tree_add_text(tree, NullTVB, offset, 2, "Transmision Header Bytes 6-7");
692         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
693
694         /* Bytes 6-7 */
695         proto_tree_add_boolean(bf_tree, hf_sna_th_vrprq, NullTVB, offset, 2, th_word);
696         proto_tree_add_boolean(bf_tree, hf_sna_th_vrprs, NullTVB, offset, 2, th_word);
697         proto_tree_add_uint(bf_tree, hf_sna_th_vr_cwri, NullTVB, offset, 2, th_word);
698         proto_tree_add_boolean(bf_tree, hf_sna_th_vr_rwi, NullTVB, offset, 2, th_word);
699
700         /* I'm not sure about byte-order on this one... */
701         proto_tree_add_uint(bf_tree, hf_sna_th_vr_snf_send, NullTVB, offset, 2, th_word);
702
703         offset += 2;
704
705         /* Bytes 8-11 */
706         proto_tree_add_uint(tree, hf_sna_th_dsaf, NullTVB, offset, 4, dsaf);
707
708         offset += 4;
709
710         /* Bytes 12-15 */
711         proto_tree_add_uint(tree, hf_sna_th_osaf, NullTVB, offset, 4, osaf);
712
713         offset += 4;
714         th_byte = pd[offset];
715
716         /* Create the bitfield tree */
717         bf_item = proto_tree_add_text(tree, NullTVB, offset, 2, "Transmision Header Byte 16");
718         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
719
720         /* Byte 16 */
721         proto_tree_add_boolean(tree, hf_sna_th_snai, NullTVB, offset, 1, th_byte);
722
723         /* We luck out here because in their infinite wisdom the SNA
724          * architects placed the MPF and EFI fields in the same bitfield
725          * locations, even though for FID4 they're not in byte 0.
726          * Thank you IBM! */
727         proto_tree_add_uint(tree, hf_sna_th_mpf, NullTVB, offset, 1, th_byte);
728         proto_tree_add_uint(tree, hf_sna_th_efi, NullTVB, offset, 1, th_byte);
729
730         offset += 2; /* 1 for byte 16, 1 for byte 17 which is reserved */
731
732         /* Bytes 18-25 */
733         proto_tree_add_uint(tree, hf_sna_th_def, NullTVB, offset+0, 2, def);
734         proto_tree_add_uint(tree, hf_sna_th_oef, NullTVB, offset+2, 2, oef);
735         proto_tree_add_uint(tree, hf_sna_th_snf, NullTVB, offset+4, 2, snf);
736         proto_tree_add_uint(tree, hf_sna_th_snf, NullTVB, offset+6, 2, dcf);
737
738         return bytes_in_header;
739 }
740
741 /* FID Type 5 */
742 static int
743 dissect_fid5 (const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
744
745         proto_tree      *bf_tree;
746         proto_item      *bf_item;
747         guint8          th_0;
748         guint16         snf;
749
750         static int bytes_in_header = 12;
751
752         if (!BYTES_ARE_IN_FRAME(offset, bytes_in_header)) {
753                 return 0;
754         }
755
756         th_0 = pd[offset+0];
757         snf = pntohs(&pd[offset+2]);
758
759         if (!tree) {
760                 return bytes_in_header;
761         }
762
763         /* Create the bitfield tree */
764         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, NullTVB, offset, 1, th_0);
765         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
766
767         proto_tree_add_uint(bf_tree, hf_sna_th_fid, NullTVB, offset, 1, th_0);
768         proto_tree_add_uint(bf_tree, hf_sna_th_mpf, NullTVB, offset, 1, th_0);
769         proto_tree_add_uint(bf_tree, hf_sna_th_efi, NullTVB, offset, 1, th_0);
770
771         proto_tree_add_text(tree, NullTVB, offset+1, 1, "Reserved");
772         proto_tree_add_uint(tree, hf_sna_th_snf, NullTVB, offset+2, 2, snf);
773
774         proto_tree_add_bytes(tree, hf_sna_th_sa, NullTVB, offset+4, 8, &pd[offset+4]);
775
776         return bytes_in_header;
777
778 }
779
780 /* FID Type f */
781 static int
782 dissect_fidf (const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
783
784         proto_tree      *bf_tree;
785         proto_item      *bf_item;
786         guint8          th_0, cmd_fmt, cmd_type;
787         guint16         cmd_sn, dcf;
788         
789         static int bytes_in_header = 26;
790
791         if (!BYTES_ARE_IN_FRAME(offset, bytes_in_header)) {
792                 return 0;
793         }
794
795         th_0 = pd[offset+0];
796         cmd_fmt = pd[offset+2];
797         cmd_type = pd[offset+3];
798         cmd_sn = pntohs(&pd[offset+4]);
799
800         /* Yup, bytes 6-23 are reserved! */
801         dcf = pntohs(&pd[offset+24]);
802
803         if (!tree) {
804                 return bytes_in_header;
805         }
806
807         /* Create the bitfield tree */
808         bf_item = proto_tree_add_uint(tree, hf_sna_th_0, NullTVB, offset, 1, th_0);
809         bf_tree = proto_item_add_subtree(bf_item, ett_sna_th_fid);
810
811         proto_tree_add_uint(bf_tree, hf_sna_th_fid, NullTVB, offset, 1, th_0);
812         proto_tree_add_text(tree, NullTVB, offset+1, 1, "Reserved");
813
814         proto_tree_add_uint(tree, hf_sna_th_cmd_fmt, NullTVB,  offset+2, 1, cmd_fmt);
815         proto_tree_add_uint(tree, hf_sna_th_cmd_type, NullTVB, offset+3, 1, cmd_type);
816         proto_tree_add_uint(tree, hf_sna_th_cmd_sn, NullTVB,   offset+4, 2, cmd_sn);
817
818         proto_tree_add_text(tree, NullTVB, offset+6, 18, "Reserved");
819
820         proto_tree_add_uint(tree, hf_sna_th_dcf, NullTVB, offset+24, 8, dcf);
821
822         return bytes_in_header;
823 }
824
825
826 /* RH */
827 static void
828 dissect_rh (const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
829
830         proto_tree      *bf_tree;
831         proto_item      *bf_item;
832         gboolean        is_response;
833         guint8          rh_0, rh_1, rh_2;
834
835         rh_0 = pd[offset+0];
836         rh_1 = pd[offset+1];
837         rh_2 = pd[offset+2];
838
839         is_response = (rh_0 & 0x80);
840
841         /* Create the bitfield tree for byte 0*/
842         bf_item = proto_tree_add_uint(tree, hf_sna_rh_0, NullTVB, offset, 1, rh_0);
843         bf_tree = proto_item_add_subtree(bf_item, ett_sna_rh_0);
844
845         proto_tree_add_uint(bf_tree, hf_sna_rh_rri, NullTVB, offset, 1, rh_0);
846         proto_tree_add_uint(bf_tree, hf_sna_rh_ru_category, NullTVB, offset, 1, rh_0);
847         proto_tree_add_boolean(bf_tree, hf_sna_rh_fi, NullTVB, offset, 1, rh_0);
848         proto_tree_add_boolean(bf_tree, hf_sna_rh_sdi, NullTVB, offset, 1, rh_0);
849         proto_tree_add_boolean(bf_tree, hf_sna_rh_bci, NullTVB, offset, 1, rh_0);
850         proto_tree_add_boolean(bf_tree, hf_sna_rh_eci, NullTVB, offset, 1, rh_0);
851
852         offset += 1;
853
854         /* Create the bitfield tree for byte 1*/
855         bf_item = proto_tree_add_uint(tree, hf_sna_rh_1, NullTVB, offset, 1, rh_1);
856         bf_tree = proto_item_add_subtree(bf_item, ett_sna_rh_1);
857
858         proto_tree_add_boolean(bf_tree, hf_sna_rh_dr1, NullTVB,  offset, 1, rh_1);
859
860         if (!is_response) {
861                 proto_tree_add_boolean(bf_tree, hf_sna_rh_lcci, NullTVB, offset, 1, rh_1);
862         }
863
864         proto_tree_add_boolean(bf_tree, hf_sna_rh_dr2, NullTVB,  offset, 1, rh_1);
865
866         if (is_response) {
867                 proto_tree_add_boolean(bf_tree, hf_sna_rh_rti, NullTVB,  offset, 1, rh_1);
868         }
869         else {
870                 proto_tree_add_boolean(bf_tree, hf_sna_rh_eri, NullTVB,  offset, 1, rh_1);
871                 proto_tree_add_boolean(bf_tree, hf_sna_rh_rlwi, NullTVB, offset, 1, rh_1);
872         }
873
874         proto_tree_add_boolean(bf_tree, hf_sna_rh_qri, NullTVB, offset, 1, rh_1);
875         proto_tree_add_boolean(bf_tree, hf_sna_rh_pi, NullTVB,  offset, 1, rh_1);
876
877         offset += 1;
878
879         /* Create the bitfield tree for byte 2*/
880         bf_item = proto_tree_add_uint(tree, hf_sna_rh_2, NullTVB, offset, 1, rh_2);
881
882         if (!is_response) {
883                 bf_tree = proto_item_add_subtree(bf_item, ett_sna_rh_2);
884
885                 proto_tree_add_boolean(bf_tree, hf_sna_rh_bbi, NullTVB,  offset, 1, rh_2);
886                 proto_tree_add_boolean(bf_tree, hf_sna_rh_ebi, NullTVB,  offset, 1, rh_2);
887                 proto_tree_add_boolean(bf_tree, hf_sna_rh_cdi, NullTVB,  offset, 1, rh_2);
888                 proto_tree_add_uint(bf_tree, hf_sna_rh_csi, NullTVB,  offset, 1, rh_2);
889                 proto_tree_add_boolean(bf_tree, hf_sna_rh_edi, NullTVB,  offset, 1, rh_2);
890                 proto_tree_add_boolean(bf_tree, hf_sna_rh_pdi, NullTVB,  offset, 1, rh_2);
891                 proto_tree_add_boolean(bf_tree, hf_sna_rh_cebi, NullTVB, offset, 1, rh_2);
892         }
893
894         /* XXX - check for sdi. If TRUE, the next 4 bytes will be sense data */
895 }
896
897 void
898 proto_register_sna(void)
899 {
900         static hf_register_info hf[] = {
901                 { &hf_sna_th,
902                 { "Transmission Header",        "sna.th", FT_NONE, BASE_NONE, NULL, 0x0,
903                         "" }},
904
905                 { &hf_sna_th_0,
906                 { "Transmission Header Byte 0", "sna.th.0", FT_UINT8, BASE_HEX, NULL, 0x0,
907                         "Byte 0 of Tranmission Header contains FID, MPF, ODAI,"
908                         " and EFI as bitfields." }},
909
910                 { &hf_sna_th_fid,
911                 { "Format Identifer",           "sna.th.fid", FT_UINT8, BASE_HEX, VALS(sna_th_fid_vals), 0xf0,
912                         "Format Identification" }},
913
914                 { &hf_sna_th_mpf,
915                 { "Mapping Field",              "sna.th.mpf", FT_UINT8, BASE_NONE, VALS(sna_th_mpf_vals), 0x0c,
916                         "The Mapping Field specifies whether the information field"
917                         " associated with the TH is a complete or partial BIU." }},
918
919                 { &hf_sna_th_odai,
920                 { "ODAI Assignment Indicator",  "sna.th.odai", FT_UINT8, BASE_DEC, NULL, 0x02,
921                         "The ODAI indicates which node assigned the OAF'-DAF' values"
922                         " carried in the TH." }},
923
924                 { &hf_sna_th_efi,
925                 { "Expedited Flow Indicator",   "sna.th.efi", FT_UINT8, BASE_DEC, VALS(sna_th_efi_vals), 0x01,
926                         "The EFI designates whether the PIU belongs to the normal"
927                         " or expedited flow." }},
928
929                 { &hf_sna_th_daf,
930                 { "Destination Address Field",  "sna.th.daf", FT_UINT16, BASE_HEX, NULL, 0x0,
931                         "" }},
932
933                 { &hf_sna_th_oaf,
934                 { "Origin Address Field",       "sna.th.oaf", FT_UINT16, BASE_HEX, NULL, 0x0,
935                         "" }},
936
937                 { &hf_sna_th_snf,
938                 { "Sequence Number Field",      "sna.th.snf", FT_UINT16, BASE_NONE, NULL, 0x0,
939                         "The Sequence Number Field contains a numerical identifier for"
940                         " the associated BIU."}},
941
942                 { &hf_sna_th_dcf,
943                 { "Data Count Field",   "sna.th.dcf", FT_UINT16, BASE_DEC, NULL, 0x0,
944                         "A binary count of the number of bytes in the BIU or BIU segment associated "
945                         "with the tranmission header. The count does not include any of the bytes "
946                         "in the transmission header."}},
947
948                 { &hf_sna_th_lsid,
949                 { "Local Session Identification",       "sna.th.lsid", FT_UINT8, BASE_HEX, NULL, 0x0,
950                         "" }},
951
952                 { &hf_sna_th_tg_sweep,
953                 { "Transmission Group Sweep",           "sna.th.tg_sweep", FT_UINT8, BASE_DEC,
954                         VALS(sna_th_tg_sweep_vals), 0x08,
955                         "" }},
956
957                 { &hf_sna_th_er_vr_supp_ind,
958                 { "ER and VR Support Indicator",        "sna.th.er_vr_supp_ind", FT_UINT8, BASE_DEC,
959                         VALS(sna_th_er_vr_supp_ind_vals), 0x04,
960                         "" }},
961
962                 { &hf_sna_th_vr_pac_cnt_ind,
963                 { "Virtual Route Pacing Count Indicator",       "sna.th.vr_pac_cnt_ind",
964                         FT_UINT8, BASE_DEC, VALS(sna_th_vr_pac_cnt_ind_vals), 0x02,
965                         "" }},
966
967                 { &hf_sna_th_ntwk_prty,
968                 { "Network Priority",   "sna.th.ntwk_prty",
969                         FT_UINT8, BASE_DEC, VALS(sna_th_ntwk_prty_vals), 0x01,
970                         "" }},
971
972                 { &hf_sna_th_tgsf,
973                 { "Transmission Group Segmenting Field",        "sna.th.tgsf",
974                         FT_UINT8, BASE_HEX, VALS(sna_th_tgsf_vals), 0xc0,
975                         "" }},
976
977                 { &hf_sna_th_mft,
978                 { "MPR FID4 Type",      "sna.th.mft", FT_BOOLEAN, BASE_NONE, NULL, 0x04,
979                         "" }},
980
981                 { &hf_sna_th_piubf,
982                 { "PIU Blocking Field", "sna.th.piubf", FT_UINT8, BASE_HEX,
983                         VALS(sna_th_piubf_vals), 0x03,
984                         "Specifies whether this frame contains a single PIU or multiple PIUs." }},
985
986                 { &hf_sna_th_iern,
987                 { "Initial Explicit Route Number",      "sna.th.iern", FT_UINT8, BASE_DEC, NULL, 0xf0,
988                         "" }},
989
990                 { &hf_sna_th_nlpoi,
991                 { "NLP Offset Indicator",       "sna.th.nlpoi", FT_UINT8, BASE_DEC,
992                         VALS(sna_th_nlpoi_vals), 0x80,
993                         "" }},
994
995                 { &hf_sna_th_nlp_cp,
996                 { "NLP Count or Padding",       "sna.th.nlp_cp", FT_UINT8, BASE_DEC, NULL, 0x70,
997                         "" }},
998
999                 { &hf_sna_th_ern,
1000                 { "Explicit Route Number",      "sna.th.ern", FT_UINT8, BASE_DEC, NULL, 0x0f,
1001                         "The ERN in a TH identifies an explicit route direction of flow." }},
1002
1003                 { &hf_sna_th_vrn,
1004                 { "Virtual Route Number",       "sna.th.vrn", FT_UINT8, BASE_DEC, NULL, 0xf0,
1005                         "" }},
1006
1007                 { &hf_sna_th_tpf,
1008                 { "Transmission Priority Field",        "sna.th.tpf", FT_UINT8, BASE_HEX,
1009                         VALS(sna_th_tpf_vals), 0x03,
1010                         "" }},
1011
1012                 { &hf_sna_th_vr_cwi,
1013                 { "Virtual Route Change Window Indicator",      "sna.th.vr_cwi", FT_UINT16, BASE_DEC,
1014                         VALS(sna_th_vr_cwi_vals), 0x8000,
1015                         "Used to change the window size of the virtual route by 1." }},
1016
1017                 { &hf_sna_th_tg_nonfifo_ind,
1018                 { "Transmission Group Non-FIFO Indicator",      "sna.th.tg_nonfifo_ind", FT_BOOLEAN, 16,
1019                         TFS(&sna_th_tg_nonfifo_ind_truth), 0x4000,
1020                         "Indicates whether or not FIFO discipline is to enforced in "
1021                         "transmitting PIUs through the tranmission groups to prevent the PIUs "
1022                         "getting out of sequence during transmission over the TGs." }},
1023
1024                 { &hf_sna_th_vr_sqti,
1025                 { "Virtual Route Sequence and Type Indicator",  "sna.th.vr_sqti", FT_UINT16, BASE_HEX,
1026                         VALS(sna_th_vr_sqti_vals), 0x3000,
1027                         "Specifies the PIU type." }},
1028
1029                 { &hf_sna_th_tg_snf,
1030                 { "Transmission Group Sequence Number Field",   "sna.th.tg_snf", FT_UINT16, BASE_DEC,
1031                         NULL, 0x0fff,
1032                         "" }},
1033
1034                 { &hf_sna_th_vrprq,
1035                 { "Virtual Route Pacing Request",       "sna.th.vrprq", FT_BOOLEAN, 16,
1036                         TFS(&sna_th_vrprq_truth), 0x8000,
1037                         "" }},
1038
1039                 { &hf_sna_th_vrprs,
1040                 { "Virtual Route Pacing Response",      "sna.th.vrprs", FT_BOOLEAN, 16,
1041                         TFS(&sna_th_vrprs_truth), 0x4000,
1042                         "" }},
1043
1044                 { &hf_sna_th_vr_cwri,
1045                 { "Virtual Route Change Window Reply Indicator",        "sna.th.vr_cwri", FT_UINT16, BASE_DEC,
1046                         VALS(sna_th_vr_cwri_vals), 0x2000,
1047                         "Permits changing of the window size by 1 for PIUs received by the "
1048                         "sender of this bit." }},
1049
1050                 { &hf_sna_th_vr_rwi,
1051                 { "Virtual Route Reset Window Indicator",       "sna.th.vr_rwi", FT_BOOLEAN, 16,
1052                         TFS(&sna_th_vr_rwi_truth), 0x1000,
1053                         "Indicates severe congestion in a node on the virtual route." }},
1054
1055                 { &hf_sna_th_vr_snf_send,
1056                 { "Virtual Route Send Sequence Number Field",   "sna.th.vr_snf_send", FT_UINT16, BASE_DEC,
1057                         NULL, 0x0fff,
1058                         "" }},
1059
1060                 { &hf_sna_th_dsaf,
1061                 { "Destination Subarea Address Field",  "sna.th.dsaf", FT_UINT32, BASE_HEX, NULL, 0x0,
1062                         "" }},
1063
1064                 { &hf_sna_th_osaf,
1065                 { "Origin Subarea Address Field",       "sna.th.osaf", FT_UINT32, BASE_HEX, NULL, 0x0,
1066                         "" }},
1067
1068                 { &hf_sna_th_snai,
1069                 { "SNA Indicator",      "sna.th.snai", FT_BOOLEAN, 8, NULL, 0x10,
1070                         "Used to identify whether the PIU originated or is destined for "
1071                         "an SNA or non-SNA device." }},
1072
1073                 { &hf_sna_th_def,
1074                 { "Destination Element Field",  "sna.th.def", FT_UINT16, BASE_HEX, NULL, 0x0,
1075                         "" }},
1076
1077                 { &hf_sna_th_oef,
1078                 { "Origin Element Field",       "sna.th.oef", FT_UINT16, BASE_HEX, NULL, 0x0,
1079                         "" }},
1080
1081                 { &hf_sna_th_sa,
1082                 { "Session Address",    "sna.th.sa", FT_BYTES, BASE_HEX, NULL, 0x0,
1083                         "" }},
1084
1085                 { &hf_sna_th_cmd_fmt,
1086                 { "Command Format",     "sna.th.cmd_fmt", FT_UINT8, BASE_HEX, NULL, 0x0,
1087                         "" }},
1088
1089                 { &hf_sna_th_cmd_type,
1090                 { "Command Type",       "sna.th.cmd_type", FT_UINT8, BASE_HEX, NULL, 0x0,
1091                         "" }},
1092
1093                 { &hf_sna_th_cmd_sn,
1094                 { "Command Sequence Number",    "sna.th.cmd_sn", FT_UINT16, BASE_DEC, NULL, 0x0,
1095                         "" }},
1096
1097
1098                 { &hf_sna_rh,
1099                 { "Request/Response Header",    "sna.rh", FT_NONE, BASE_NONE, NULL, 0x0,
1100                         "" }},
1101
1102                 { &hf_sna_rh_0,
1103                 { "Request/Response Header Byte 0",     "sna.rh.0", FT_UINT8, BASE_HEX, NULL, 0x0,
1104                         "" }},
1105
1106                 { &hf_sna_rh_1,
1107                 { "Request/Response Header Byte 1",     "sna.rh.1", FT_UINT8, BASE_HEX, NULL, 0x0,
1108                         "" }},
1109
1110                 { &hf_sna_rh_2,
1111                 { "Request/Response Header Byte 2",     "sna.rh.2", FT_UINT8, BASE_HEX, NULL, 0x0,
1112                         "" }},
1113
1114                 { &hf_sna_rh_rri,
1115                 { "Request/Response Indicator", "sna.rh.rri", FT_UINT8, BASE_DEC, VALS(sna_rh_rri_vals), 0x80,
1116                         "Denotes whether this is a request or a response." }},
1117
1118                 { &hf_sna_rh_ru_category,
1119                 { "Request/Response Unit Category",     "sna.rh.ru_category", FT_UINT8, BASE_HEX,
1120                         VALS(sna_rh_ru_category_vals), 0x60,
1121                         "" }},
1122
1123                 { &hf_sna_rh_fi,
1124                 { "Format Indicator",           "sna.rh.fi", FT_BOOLEAN, 8, TFS(&sna_rh_fi_truth), 0x08,
1125                         "" }},
1126
1127                 { &hf_sna_rh_sdi,
1128                 { "Sense Data Included",        "sna.rh.sdi", FT_BOOLEAN, 8, TFS(&sna_rh_sdi_truth), 0x04,
1129                         "Indicates that a 4-byte sense data field is included in the associated RU." }},
1130
1131                 { &hf_sna_rh_bci,
1132                 { "Begin Chain Indicator",      "sna.rh.bci", FT_BOOLEAN, 8, TFS(&sna_rh_bci_truth), 0x02,
1133                         "" }},
1134
1135                 { &hf_sna_rh_eci,
1136                 { "End Chain Indicator",        "sna.rh.eci", FT_BOOLEAN, 8, TFS(&sna_rh_eci_truth), 0x01,
1137                         "" }},
1138
1139                 { &hf_sna_rh_dr1,
1140                 { "Definite Response 1 Indicator",      "sna.rh.dr1", FT_BOOLEAN, 8, NULL, 0x80,
1141                         "" }},
1142
1143                 { &hf_sna_rh_lcci,
1144                 { "Length-Checked Compression Indicator",       "sna.rh.lcci", FT_BOOLEAN, 8,
1145                         TFS(&sna_rh_lcci_truth), 0x40,
1146                         "" }},
1147
1148                 { &hf_sna_rh_dr2,
1149                 { "Definite Response 2 Indicator",      "sna.rh.dr2", FT_BOOLEAN, 8, NULL, 0x20,
1150                         "" }},
1151
1152                 { &hf_sna_rh_eri,
1153                 { "Exception Response Indicator",       "sna.rh.eri", FT_BOOLEAN, 8, NULL, 0x10,
1154                         "Used in conjunction with DR1I and DR2I to indicate, in a request, "
1155                         "the form of response requested." }},
1156
1157                 { &hf_sna_rh_rti,
1158                 { "Response Type Indicator",    "sna.rh.rti", FT_BOOLEAN, 8, TFS(&sna_rh_rti_truth), 0x10,
1159                         "" }},
1160
1161                 { &hf_sna_rh_rlwi,
1162                 { "Request Larger Window Indicator",    "sna.rh.rlwi", FT_BOOLEAN, 8, NULL, 0x04,
1163                         "Indicates whether a larger pacing window was requested." }},
1164
1165                 { &hf_sna_rh_qri,
1166                 { "Queued Response Indicator",  "sna.rh.qri", FT_BOOLEAN, 8, TFS(&sna_rh_qri_truth), 0x02,
1167                         "" }},
1168
1169                 { &hf_sna_rh_pi,
1170                 { "Pacing Indicator",   "sna.rh.pi", FT_BOOLEAN, 8, NULL, 0x01,
1171                         "" }},
1172
1173                 { &hf_sna_rh_bbi,
1174                 { "Begin Bracket Indicator",    "sna.rh.bbi", FT_BOOLEAN, 8, NULL, 0x80,
1175                         "" }},
1176
1177                 { &hf_sna_rh_ebi,
1178                 { "End Bracket Indicator",      "sna.rh.ebi", FT_BOOLEAN, 8, NULL, 0x40,
1179                         "" }},
1180
1181                 { &hf_sna_rh_cdi,
1182                 { "Change Direction Indicator", "sna.rh.cdi", FT_BOOLEAN, 8, NULL, 0x20,
1183                         "" }},
1184
1185                 { &hf_sna_rh_csi,
1186                 { "Code Selection Indicator",   "sna.rh.csi", FT_UINT8, BASE_DEC, VALS(sna_rh_csi_vals), 0x08,
1187                         "Specifies the encoding used for the associated FMD RU." }},
1188
1189                 { &hf_sna_rh_edi,
1190                 { "Enciphered Data Indicator",  "sna.rh.edi", FT_BOOLEAN, 8, NULL, 0x04,
1191                         "Indicates that information in the associated RU is enciphered under "
1192                         "session-level cryptography protocols." }},
1193
1194                 { &hf_sna_rh_pdi,
1195                 { "Padded Data Indicator",      "sna.rh.pdi", FT_BOOLEAN, 8, NULL, 0x02,
1196                         "Indicates that the RU was padded at the end, before encipherment, to the next "
1197                         "integral multiple of 8 bytes." }},
1198
1199                 { &hf_sna_rh_cebi,
1200                 { "Conditional End Bracket Indicator",  "sna.rh.cebi", FT_BOOLEAN, 8, NULL, 0x01,
1201                         "Used to indicate the beginning or end of a group of exchanged "
1202                         "requests and responses called a bracket. Only used on LU-LU sessions." }},
1203
1204 /*                { &hf_sna_ru,
1205                 { "Request/Response Unit",      "sna.ru", FT_NONE, BASE_NONE, NULL, 0x0,
1206                         ""}},*/
1207         };
1208         static gint *ett[] = {
1209                 &ett_sna,
1210                 &ett_sna_th,
1211                 &ett_sna_th_fid,
1212                 &ett_sna_rh,
1213                 &ett_sna_rh_0,
1214                 &ett_sna_rh_1,
1215                 &ett_sna_rh_2,
1216         };
1217
1218         proto_sna = proto_register_protocol("Systems Network Architecture",
1219             "SNA", "sna");
1220         proto_register_field_array(proto_sna, hf, array_length(hf));
1221         proto_register_subtree_array(ett, array_length(ett));
1222 }
1223
1224 void
1225 proto_reg_handoff_sna(void)
1226 {
1227         old_dissector_add("llc.dsap", SAP_SNA_PATHCTRL, dissect_sna);
1228 }