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