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