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