Try to squeeze some bytes out of the frame_data structure.
[gd/wireshark/.git] / epan / dissectors / packet-tn3270.c
1 /* packet-tn3270.c
2  * Routines for tn3270.packet dissection
3  *
4  * References:
5  *  3270 Information Display System: Data Stream Programmer's Reference
6  *    GA23-0059-07
7  *    http://publib.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/CN7P4000
8  *    (Paragraph references in the comments in this file (e.g., 6.15) are to the above document)
9  *
10  *  3174 Establishment Controller Functional Description
11  *    GA23-0218-11
12  *    http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/cn7a7003
13  *
14  *
15  *  RFC 1041: Telnet 3270 Regime Option
16  *    http://tools.ietf.org/html/rfc1041
17  *
18  *  RFC 1576: TN3270 Current Practices
19  *    http://tools.ietf.org/html/rfc1576
20  *
21  *  RFC 2355: TN3270 Enhancements
22  *    http://tools.ietf.org/html/rfc2355
23  *
24  *
25  * Copyright 2009, Robert Hogan <robert@roberthogan.net>
26  *
27  * Wireshark - Network traffic analyzer
28  * By Gerald Combs <gerald@wireshark.org>
29  * Copyright 1998 Gerald Combs
30  *
31  * SPDX-License-Identifier: GPL-2.0-or-later
32  */
33
34 #include "config.h"
35
36
37 #include <epan/packet.h>
38 #include <epan/conversation.h>
39 #include <epan/expert.h>
40
41 #include "packet-tn3270.h"
42
43 void proto_register_tn3270(void);
44
45 /* Note well:
46  *  In the IBM "3270 Information Display System: Data Stream Programmer's Reference"
47  *  document, the references to bit numbers in the text and tables
48  *  are based upon the "MSB 0" bit numbering scheme.
49  *  That is: bits are numbered in a byte from left-to-right:
50  *    "Bit 0" is the MSB of the byte
51  *    "Bit 7" is the LSB of the byte
52  */
53
54 /*
55  ToDo:
56   - better tree display: e.g., separate tree for each order code ....
57   - review 'structured field grouping: 5.2
58   - Telnet uses 0xFF as IAC ["interpret as command"] and thus for
59      telnet: any actual 0xFF bytes in a 3270 data stream will be prefixed with
60      a 0xFF escape. The escapes should be removed from the TVB before the
61      buffer is passed to this dissector. See packet-telnet.c
62   - Show the 'as a fraction" display as  xx/yy ?
63 */
64
65 /* Dissection is for EBCDIC 3270 */
66
67 /* OUTBOUND DATA STREAM (MAINFRAME PROGRAM -> DISPLAY)
68
69    ________________ _____ __________________
70    | Command Code   |WCC  | Orders and Data  |
71    |________________|_____|__________________|
72
73    or
74    ______ ______________________
75    | WSF  | Structured Field(s)  |
76    |______|______________________|
77
78 */
79
80 /*--- 3270 Command Codes - "Local Attachment" ----- */
81 #define CC_LCL_W        0x01
82 #define CC_LCL_EW       0x05
83 #define CC_LCL_EWA      0x0D
84 #define CC_LCL_EAU      0x0F
85 #define CC_LCL_WSF      0x11
86
87 #define CC_LCL_RB       0x02
88 #define CC_LCL_RM       0x06
89 #define CC_LCL_RMA      0x0E  /* XXX Not valid ?? See 3174 Function Description 2.1.4 */
90
91 #if 0  /* ??? */
92 #define CC_NOP      0x03
93 #endif
94
95
96 /*--- 3.3 3270 Command Codes - "Remote Attachment" ----- */
97 #define CC_RMT_W    0xF1
98 #define CC_RMT_EW   0xF5
99 #define CC_RMT_EWA  0x7E
100 #define CC_RMT_EAU  0x6F
101 #define CC_RMT_WSF  0xF3
102
103 #define CC_RMT_RB   0xF2
104 #define CC_RMT_RM   0xF6
105 #define CC_RMT_RMA  0x6E
106
107 #define CC_SNA_BSC  0xF7   /* local copy in a BSC environment */
108
109 static const value_string vals_command_codes[] = {
110
111   { CC_LCL_W,   "Write (Local)" },
112   { CC_LCL_EW,  "Erase/Write (Local)" },
113   { CC_LCL_EWA, "Erase/Write Alternate (Local)" },
114   { CC_LCL_EAU, "Erase All Unprotected (Local)" },
115   { CC_LCL_WSF, "Write Structured Field (Local)" },
116   { CC_LCL_RB,  "Read Buffer (Local)" },
117   { CC_LCL_RM,  "Read Modified (Local)" },
118   { CC_LCL_RMA, "Read Modified All (Local)" },
119   { CC_RMT_W,   "Write" },
120   { CC_RMT_EW,  "Erase/Write" },
121   { CC_RMT_EWA, "Erase/Write Alternate" },
122   { CC_RMT_EAU, "Erase All Unprotected" },
123   { CC_RMT_WSF, "Write Structured Field" },
124   { CC_RMT_RB,  "Read Buffer" },
125   { CC_RMT_RM,  "Read Modified" },
126   { CC_RMT_RMA, "Read Modified All" },
127   { CC_SNA_BSC, "BSC Copy" },
128   { 0x00, NULL }
129 };
130
131 /*--- 3.4 WCC (Write Control Characters) ----- */
132 #define WCC_NOP               0x80 /* "Bit 0" */
133 #define WCC_RESET             0x40 /* "Bit 1" */
134 #define WCC_PRINTER1          0x20 /* "Bit 2" */
135 #define WCC_PRINTER2          0x10 /* "Bit 3" */
136 #define WCC_START_PRINTER     0x08 /* "Bit 4" */
137 #define WCC_SOUND_ALARM       0x04 /* "Bit 5" */
138 #define WCC_KEYBOARD_RESTORE  0x02 /* "Bit 6" */
139 #define WCC_RESET_MDT         0x01 /* "Bit 7" */
140
141 /*--- 4.3 Order Codes ----- */
142 #define OC_MAX  0x3F
143
144 #define OC_SF   0x1D
145 #define OC_SFE  0x29
146 #define OC_SBA  0x11
147 #define OC_SA   0x28
148 #define OC_MF   0x2C
149 #define OC_IC   0x13
150 #define OC_PT   0x05
151 #define OC_RA   0x3C
152 #define OC_EUA  0x12
153 #define OC_GE   0x08
154
155 static const value_string vals_order_codes[] = {
156   { OC_SF,  "Start Field (SF)" },
157   { OC_SFE, "Start Field Extended (SFE)" },
158   { OC_SBA, "Set Buffer Address (SBA)" },
159   { OC_SA,  "Set Attribute (SA)" },
160   { OC_MF,  "Modify Field (MF)" },
161   { OC_IC,  "Insert Cursor (IC)" },
162   { OC_PT,  "Program Tab (PT)" },
163   { OC_RA,  "Repeat to Address (RA)" },
164   { OC_EUA, "Erase Unprotected to Address (EUA)" },
165   { OC_GE,  "Graphic Escape (GE)" },
166   { 0x00, NULL }
167 };
168
169 #if 0  /* Not used */
170 /*--- 4.3.11 Format Control Orders ----- */
171 /*        Special treatment for display */
172 #define FCO_NUL  0x00
173 #define FCO_SUB  0x3F
174 #define FCO_DUP  0x1C
175 #define FCO_FM   0x1E
176 #define FCO_FF   0x0C
177 #define FCO_CR   0x0D
178 #define FCO_NL   0x15
179 #define FCO_EM   0x19
180 #define FCO_EO   0xFF
181
182 static const value_string vals_format_control_orders[] = {
183   { FCO_NUL, "Null" },
184   { FCO_SUB, "Substitute" },
185   { FCO_DUP, "Duplicate" },
186   { FCO_FM,  "Field Mark" },
187   { FCO_FF,  "Form Feed" },
188   { FCO_CR,  "Carriage Return" },
189   { FCO_NL,  "New Line" },
190   { FCO_EM,  "End of Medium" },
191   { FCO_EO,  "Eight Ones" },
192   { 0x00, NULL }
193 };
194 #endif
195
196 /*--- 8.7 Copy Control Code ----- */
197 /* Use for "local Copy" in a "BSC [BiSync] Environment" */
198
199 /* "Coding Bits" are those required such that the   */
200 /*   complete 8 bit CCC is a valid EBCDIC character */
201 #define CCC_GRAPHIC_CONVERT_MASK          0xC0
202
203 #define CCC_PRINT_BITS_MASK               0x30
204 #define  CCC_PRINT_BITS_POINT_LINE_LENGTH  0x00
205 #define  CCC_PRINT_BITS_PRINT_LINE_40      0x01
206 #define  CCC_PRINT_BITS_PRINT_LINE_64      0x02
207 #define  CCC_PRINT_BITS_PRINT_LINE_80      0x03
208
209 static const value_string ccc_vals_printout_format[] = {
210   { CCC_PRINT_BITS_POINT_LINE_LENGTH,
211     "The NL, EM, and CR orders in the data stream determine pointline length. "
212     "Provides a 132-print position line when the orders are not present." },
213   { CCC_PRINT_BITS_PRINT_LINE_40,
214     "Specifies a 40-character print line." },
215   { CCC_PRINT_BITS_PRINT_LINE_64,
216     "Specifies a 64-character print line." },
217   { CCC_PRINT_BITS_PRINT_LINE_80,
218     "Specifies an 80-character print line." },
219   { 0x00, NULL }
220 };
221
222 #define CCC_START_PRINT                                         0x08
223 #define CCC_SOUND_ALARM                                         0x04
224
225 #define CCC_ATTRIBUTE_BITS_MASK                                 0x03
226 #define  CCC_ATTRIBUTE_BITS_ONLY_ATTRIBUTE_CHARACTERS            0x00
227 #define  CCC_ATTRIBUTE_BITS_ATTRIBUTE_CHARACTERS_UNPROTECTED_AN  0x01
228 #define  CCC_ATTRIBUTE_BITS_ALL_ATTRIBUTE_PROTECTED              0x02
229 #define  CCC_ATTRIBUTE_BITS_ENTIRE_CONTENTS                      0x03
230
231 static const value_string ccc_vals_copytype[] = {
232   { CCC_ATTRIBUTE_BITS_ONLY_ATTRIBUTE_CHARACTERS,
233     "Only attribute characters are copied." },
234   { CCC_ATTRIBUTE_BITS_ATTRIBUTE_CHARACTERS_UNPROTECTED_AN,
235     "Attribute characters and unprotected alphanumeric fields"
236     " (including nulls) are copied. Nulls are transferred for"
237     " the alphanumeric characters not copied from the"
238     " protected fields." },
239   { CCC_ATTRIBUTE_BITS_ALL_ATTRIBUTE_PROTECTED,
240     "All attribute characters and protected alphanumeric fields"
241     " (including nulls) are copied. Nulls are transferred for the alphanumeric characters not"
242     " copied from the unprotected fields." },
243   { CCC_ATTRIBUTE_BITS_ENTIRE_CONTENTS,
244     "The entire contents of the storage buffer (including nulls) are copied." },
245   { 0x00, NULL }
246 };
247
248 /*--- 4.4.1 Field Attributes ----- */
249 #define FA_GRAPHIC_CONVERT_MASK 0xC0
250
251 #define FA_PROTECTED         0x20 /* "Bit 2" */
252 #define FA_NUMERIC           0x10 /* "Bit 3" */
253
254 #define FA_RESERVED          0x02 /* "Bit 6" */
255 #define FA_MODIFIED          0x01 /* "Bit 7" */
256
257 #define FA_DISPLAY_BITS_MASK                                          0x0C /* "Bits 4,5" */
258 #define  FA_DISPLAY_BITS_DISPLAY_NOT_SELECTOR_PEN_DETECTABLE           0x00
259 #define  FA_DISPLAY_BITS_DISPLAY_SELECTOR_PEN_DETECTABLE               0x01
260 #define  FA_DISPLAY_BITS_INTENSIFIED_DISPLAY_SELECTOR_PEN_DETECTABLE   0x02
261 #define  FA_DISPLAY_BITS_NON_DISPLAY_NON_DETECTABLE                    0x03
262
263 static const value_string vals_fa_display[] = {
264   { FA_DISPLAY_BITS_DISPLAY_NOT_SELECTOR_PEN_DETECTABLE,         "Display/Not Selector Pen Detectable" },
265   { FA_DISPLAY_BITS_DISPLAY_SELECTOR_PEN_DETECTABLE,             "Display/Selector Pen Detectable" },
266   { FA_DISPLAY_BITS_INTENSIFIED_DISPLAY_SELECTOR_PEN_DETECTABLE, "Intensified Display/Selector Pen Detectable" },
267   { FA_DISPLAY_BITS_NON_DISPLAY_NON_DETECTABLE,                  "Non Display, Non Detectable (not printable)" },
268   { 0x00, NULL }
269 };
270
271 /*--- 4.4.5 Attribute Types ----- */
272 #define AT_ALL_CHARACTER_ATTRIBUTES  0x00
273 #define AT_T3270_FIELD_ATTRIBUTE     0xC0
274 #define AT_FIELD_VALIDATION          0xC1
275 #define AT_FIELD_OUTLINING           0xC2
276 #define AT_EXTENDED_HIGHLIGHTING     0x41
277 #define AT_FOREGROUND_COLOR          0x42
278 #define AT_CHARACTER_SET             0x43
279 #define AT_BACKGROUND_COLOR          0x45
280 #define AT_TRANSPARENCY              0x46
281
282
283 static const value_string vals_attribute_types[] = {
284   { AT_ALL_CHARACTER_ATTRIBUTES, "All character attributes" },
285   { AT_T3270_FIELD_ATTRIBUTE,    "3270 Field attribute" },
286   { AT_FIELD_VALIDATION,         "Field validation" },
287   { AT_FIELD_OUTLINING,          "Field outlining" },
288   { AT_EXTENDED_HIGHLIGHTING,    "Extended highlighting" },
289   { AT_FOREGROUND_COLOR,         "Foreground color" },
290   { AT_CHARACTER_SET,            "Character set" },
291   { AT_BACKGROUND_COLOR,         "Background color" },
292   { AT_TRANSPARENCY,             "Transparency" },
293   { 0x00, NULL }
294 };
295
296 /*--- 4.4.6.3 Extended Highlighting ----- */
297 #define AT_EH_DEFAULT_HIGHLIGHTING  0x00
298 #define AT_EH_NORMAL                0xF0
299 #define AT_EH_BLINK                 0xF1
300 #define AT_EH_REVERSE_VIDEO         0xF2
301 #define AT_EH_UNDERSCORE            0xF4
302
303 static const value_string vals_at_extended_highlighting[] = {
304   { AT_EH_DEFAULT_HIGHLIGHTING, "Default" },
305   { AT_EH_NORMAL,               "Normal (as determined by the 3270 field attribute)" },
306   { AT_EH_BLINK,                "Blink" },
307   { AT_EH_REVERSE_VIDEO,        "Reverse video" },
308   { AT_EH_UNDERSCORE,           "Underscore." },
309   { 0x00, NULL }
310 };
311
312 /*--- 4.4.6.4 Color Identifications ----- */
313 #define AT_CI_ALL_PLANES      0x00
314 #define AT_CI_BLUE_PLANE      0x01
315 #define AT_CI_RED_PLANE       0x02
316 #define AT_CI_GREEN_PLANE     0x04
317 #define AT_CI_NEUTRAL1        0xF0
318 #define AT_CI_BLUE            0xF1
319 #define AT_CI_RED             0xF2
320 #define AT_CI_PINK            0xF3
321 #define AT_CI_GREEN           0xF4
322 #define AT_CI_TURQUOISE       0xF5
323 #define AT_CI_YELLOW          0xF6
324 #define AT_CI_NEUTRAL2        0xF7
325 #define AT_CI_BLACK           0xF8
326 #define AT_CI_DEEP_BLUE       0xF9
327 #define AT_CI_ORANGE          0xFA
328 #define AT_CI_PURPLE          0xFB
329 #define AT_CI_PALE_GREEN      0xFC
330 #define AT_CI_PALE_TURQUOISE  0xFD
331 #define AT_CI_GREY            0xFE
332 #define AT_CI_WHITE           0xFF
333
334
335 static const value_string vals_at_color_identifications[] = {
336   { AT_CI_ALL_PLANES,     "ALL PLANES" },
337   { AT_CI_BLUE_PLANE,     "BLUE PLANE" },
338   { AT_CI_RED_PLANE,      "RED PLANE" },
339   { AT_CI_GREEN_PLANE,    "GREEN PLANE" },
340   { AT_CI_NEUTRAL1,       "Neutral" },
341   { AT_CI_BLUE,           "Blue" },
342   { AT_CI_RED,            "Red" },
343   { AT_CI_PINK,           "Pink" },
344   { AT_CI_GREEN,          "Green" },
345   { AT_CI_TURQUOISE,      "Turquoise" },
346   { AT_CI_YELLOW,         "Yellow" },
347   { AT_CI_NEUTRAL2,       "Neutral" },
348   { AT_CI_BLACK,          "Black" },
349   { AT_CI_DEEP_BLUE,      "Deep Blue" },
350   { AT_CI_ORANGE,         "Orange" },
351   { AT_CI_PURPLE,         "Purple" },
352   { AT_CI_PALE_GREEN,     "Pale Green" },
353   { AT_CI_PALE_TURQUOISE, "Pale Turquoise" },
354   { AT_CI_GREY,           "Grey" },
355   { AT_CI_WHITE,          "White" },
356   { 0x00, NULL }
357 };
358
359 /*--- 4.4.6.5 Character Set ----- */
360 #define AT_CS_DEFAULT_CHARACTER_SET                           0x00
361 #define AT_CS_MIN_LOCAL_ID_FOR_LOADABLE_CHARACTER_SETS        0x40
362 #define AT_CS_MAX_LOCAL_ID_FOR_LOADABLE_CHARACTER_SETS        0xEF
363 #define AT_CS_MIN_LOCAL_ID_FOR_NONLOADABLE_CHARACTER_SETS     0xF0
364 #define AT_CS_MAX_LOCAL_ID_FOR_NONLOADABLE_CHARACTER_SETS     0xF7
365 #define AT_CS_MIN_LOCAL_ID_FOR_TWO_BYTE_CODED_CHARACTER_SETS  0xF8
366 #define AT_CS_MAX_LOCAL_ID_FOR_TWO_BYTE_CODED_CHARACTER_SETS  0xFE
367
368 static const range_string rvals_at_character_set[] = {
369   { AT_CS_DEFAULT_CHARACTER_SET,
370     AT_CS_DEFAULT_CHARACTER_SET,
371     "Default Character Set" },
372   { AT_CS_MIN_LOCAL_ID_FOR_LOADABLE_CHARACTER_SETS,
373     AT_CS_MAX_LOCAL_ID_FOR_LOADABLE_CHARACTER_SETS,
374     "Local Id For Loadable Character Sets" },
375   { AT_CS_MIN_LOCAL_ID_FOR_NONLOADABLE_CHARACTER_SETS,
376     AT_CS_MAX_LOCAL_ID_FOR_NONLOADABLE_CHARACTER_SETS,
377     "Local Id For Nonloadable Character Sets" },
378   { AT_CS_MIN_LOCAL_ID_FOR_TWO_BYTE_CODED_CHARACTER_SETS,
379     AT_CS_MAX_LOCAL_ID_FOR_TWO_BYTE_CODED_CHARACTER_SETS,
380     "Local Id For Two Byte Coded Character Sets" },
381   { 0,           0,          NULL                   }
382 };
383
384 /*--- 4.4.6.6 Field Outlining ----- */
385 #define AT_FO_NO_OUTLINING_LINES                   0X00
386 #define AT_FO_UNDERLINE_ONLY                       0X01
387 #define AT_FO_RIGHT_VERTICAL_LINE_ONLY             0X02
388 #define AT_FO_OVERLINE_ONLY                        0X04
389 #define AT_FO_LEFT_VERTICAL_LINE_ONLY              0X08
390 #define AT_FO_UNDERLINE_AND_RIGHT_VERTICAL_LINE    0X03
391 #define AT_FO_UNDERLINE_AND_OVERLINE               0X05
392 #define AT_FO_UNDERLINE_AND_LEFT_VERTICAL_LINE     0X09
393 #define AT_FO_RIGHT_VERTICAL_LINE_AND_OVERLINE     0X06
394 #define AT_FO_RIGHT_AND_LEFT_VERTICAL_LINES        0X0A
395 #define AT_FO_OVERLINE_AND_LEFT_VERTICAL_LINE      0X0C
396 #define AT_FO_RECTANGLE_MINUS_LEFT_VERTICAL_LINE   0X07
397 #define AT_FO_RECTANGLE_MINUS_OVERLINE             0X0B
398 #define AT_FO_RECTANGLE_MINUS_RIGHT_VERTICAL_LINE  0X0D
399 #define AT_FO_RECTANGLE_MINUS_UNDERLINE            0X0E
400 #define AT_FO_RECTANGLE                            0X0F
401
402 static const value_string vals_at_field_outlining[] = {
403   { AT_FO_NO_OUTLINING_LINES,                  "No outlining lines" },
404   { AT_FO_UNDERLINE_ONLY,                      "Underline only" },
405   { AT_FO_RIGHT_VERTICAL_LINE_ONLY,            "Right vertical line only" },
406   { AT_FO_OVERLINE_ONLY,                       "Overline only" },
407   { AT_FO_LEFT_VERTICAL_LINE_ONLY,             "Left vertical line only" },
408   { AT_FO_UNDERLINE_AND_RIGHT_VERTICAL_LINE,   "Underline and right vertical line" },
409   { AT_FO_UNDERLINE_AND_OVERLINE,              "Underline and overline" },
410   { AT_FO_UNDERLINE_AND_LEFT_VERTICAL_LINE,    "Underline and left vertical line" },
411   { AT_FO_RIGHT_VERTICAL_LINE_AND_OVERLINE,    "Right vertical line and overline" },
412   { AT_FO_RIGHT_AND_LEFT_VERTICAL_LINES,       "Right and left vertical lines" },
413   { AT_FO_OVERLINE_AND_LEFT_VERTICAL_LINE,     "Overline and left vertical line" },
414   { AT_FO_RECTANGLE_MINUS_LEFT_VERTICAL_LINE,  "Rectangle minus left vertical line" },
415   { AT_FO_RECTANGLE_MINUS_OVERLINE,            "Rectangle minus overline" },
416   { AT_FO_RECTANGLE_MINUS_RIGHT_VERTICAL_LINE, "Rectangle minus right vertical line" },
417   { AT_FO_RECTANGLE_MINUS_UNDERLINE,           "Rectangle minus underline" },
418   { AT_FO_RECTANGLE,                           "Rectangle" },
419   { 0x00, NULL }
420 };
421
422 /*--- 4.4.6.7 Transparency ----- */
423 #define AT_TR_DEFAULT_TRANSPARENCY           0X00
424 #define AT_TR_BACKGROUND_IS_TRANSPARENT_OR   0XF0
425 #define AT_TR_BACKGROUND_IS_TRANSPARENT_XOR  0XF1
426 #define AT_TR_BACKGROUND_IS_OPAQUE           0XFF
427
428 static const value_string vals_at_transparency[] = {
429   { AT_TR_DEFAULT_TRANSPARENCY,          "Default" },
430   { AT_TR_BACKGROUND_IS_TRANSPARENT_OR,  "Background is transparent (OR)" },
431   { AT_TR_BACKGROUND_IS_TRANSPARENT_XOR, "Background is transparent (XOR)" },
432   { AT_TR_BACKGROUND_IS_OPAQUE,          "Background is opaque (non-transparent)" },
433   { 0x00, NULL }
434 };
435
436 /*--- 4.4.6.8 Field Validation ----- */
437 #define AT_FV_MANDATORY_FILL         0x04 /* "Bit 5" */
438 #define AT_FV_MANDATORY_ENTRY        0x02 /* "Bit 6" */
439 #define AT_FV_TRIGGER                0x01 /* "Bit 7" */
440
441 static const struct true_false_string tn3270_field_validation_mandatory_fill = {
442   "Mandatory fill",
443   ""
444 };
445
446 static const struct true_false_string tn3270_field_validation_mandatory_entry = {
447   "Mandatory entry",
448   ""
449 };
450
451 static const struct true_false_string tn3270_field_validation_trigger = {
452   "Trigger",
453   ""
454 };
455
456 /*--- 5.1 Outbound Structured Fields ----- */
457 #define SF_OB_ACTIVATE_PARTITION             0x0E
458 #define SF_OB_BEGIN_OR_END_OF_FILE           0x0F85
459 #define SF_OB_CREATE_PARTITION               0x0C
460 #define SF_OB_DESTROY_PARTITION              0x0D
461 #define SF_OB_ERASE_OR_RESET                 0x03
462 #define SF_OB_LOAD_COLOR_TABLE               0x0F05
463 #define SF_OB_LOAD_FORMAT_STORAGE            0x0F24
464 #define SF_OB_LOAD_LINE_TYPE                 0x0F07
465 #define SF_OB_LOAD_PROGRAMMED_SYMBOLS        0x06
466 #define SF_OB_MODIFY_PARTITION               0x0F0A
467 #define SF_OB_OUTBOUND_TEXT_HEADER           0x0F71
468 #define SF_OB_OUTBOUND_3270DS                0x40
469 #define SF_OB_PRESENT_ABSOLUTE_FORMAT        0x4B
470 #define SF_OB_PRESENT_RELATIVE_FORMAT        0x4C
471 #define SF_OB_SET_PARTITION_CHARACTERISTICS  0x0F08
472 #define SF_OB_SET_REPLY_MODE                 0x09
473 #define SF_OB_TYPE_1_TEXT_OUTBOUND           0x0FC1
474 #define SF_OB_READ_PARTITION                 0x01
475 #define SF_OB_REQUEST_RECOVERY_DATA          0x1030
476 #define SF_OB_RESET_PARTITION                0x00
477 #define SF_OB_RESTART                        0x1033
478 #define SF_OB_SCS_DATA                       0x41
479 #define SF_OB_SELECT_COLOR_TABLE             0x0F04
480 #define SF_OB_SELECT_FORMAT_GROUP            0x4A
481 #define SF_OB_SET_CHECKPOINT_INTERVAL        0x1032
482 #define SF_OB_SET_MSR_CONTROL                0x0F01
483 #define SF_OB_SET_PRINTER_CHARACTERISTICS    0x0F84
484 #define SF_OB_SET_WINDOW_ORIGIN              0x0B
485
486
487 static const value_string vals_outbound_structured_fields[] = {
488   { SF_OB_ACTIVATE_PARTITION,            "Activate Partition" },
489   { SF_OB_BEGIN_OR_END_OF_FILE,          "Begin Or End Of File" },
490   { SF_OB_CREATE_PARTITION,              "Create Partition" },
491   { SF_OB_DESTROY_PARTITION,             "Destroy Partition" },
492   { SF_OB_ERASE_OR_RESET,                "Erase Or Reset" },
493   { SF_OB_LOAD_COLOR_TABLE,              "Load Color Table" },
494   { SF_OB_LOAD_FORMAT_STORAGE,           "Load Format Storage" },
495   { SF_OB_LOAD_LINE_TYPE,                "Load Line Type" },
496   { SF_OB_LOAD_PROGRAMMED_SYMBOLS,       "Load Programmed Symbols" },
497   { SF_OB_MODIFY_PARTITION,              "Modify Partition" },
498   { SF_OB_OUTBOUND_TEXT_HEADER,          "Outbound Text Header" },
499   { SF_OB_OUTBOUND_3270DS,               "Outbound 3270ds" },
500   { SF_OB_PRESENT_ABSOLUTE_FORMAT,       "Present Absolute Format" },
501   { SF_OB_PRESENT_RELATIVE_FORMAT,       "Present Relative Format" },
502   { SF_OB_SET_PARTITION_CHARACTERISTICS, "Set Partition Characteristics" },
503   { SF_OB_SET_REPLY_MODE,                "Set Reply Mode" },
504   { SF_OB_TYPE_1_TEXT_OUTBOUND,          "Type 1 Text Outbound" },
505   { SF_OB_READ_PARTITION,                "Read Partition" },
506   { SF_OB_REQUEST_RECOVERY_DATA,         "Request Recovery Data" },
507   { SF_OB_RESET_PARTITION,               "Reset Partition" },
508   { SF_OB_RESTART,                       "Restart" },
509   { SF_OB_SCS_DATA,                      "Scs Data" },
510   { SF_OB_SELECT_COLOR_TABLE,            "Select Color Table" },
511   { SF_OB_SELECT_FORMAT_GROUP,           "Select Format Group" },
512   { SF_OB_SET_CHECKPOINT_INTERVAL,       "Set Checkpoint Interval" },
513   { SF_OB_SET_MSR_CONTROL,               "Set Msr Control" },
514   { SF_OB_SET_PRINTER_CHARACTERISTICS,   "Set Printer Characteristics" },
515   { SF_OB_SET_WINDOW_ORIGIN,             "Set Window Origin" },
516   { 0x00, NULL }
517 };
518
519 /*--- 5.1 Outbound/Inbound Structured Fields ----- */
520 #define SF_OB_IB_DATA_CHAIN              0x0F21
521 #define SF_OB_IB_DESTINATION_OR_ORIGIN   0x0F02
522 #define SF_OB_IB_OBJECT_CONTROL          0x0F11
523 #define SF_OB_IB_OBJECT_DATA             0x0F0F
524 #define SF_OB_IB_OBJECT_PICTURE          0x0F10
525 #define SF_OB_IB_OEM_DATA                0x0F1F
526 #define SF_OB_IB_SAVE_OR_RESTORE_FORMAT  0x1034
527 #define SF_OB_IB_SELECT_IPDS_MODE        0x0F83
528
529 static const value_string vals_outbound_inbound_structured_fields[] = {
530   { SF_OB_IB_DATA_CHAIN,             "Data Chain" },
531   { SF_OB_IB_DESTINATION_OR_ORIGIN,  "Destination/Origin" },
532   { SF_OB_IB_OBJECT_CONTROL,         "Object Control" },
533   { SF_OB_IB_OBJECT_DATA,            "Object Data" },
534   { SF_OB_IB_OBJECT_PICTURE,         "Object Picture" },
535   { SF_OB_IB_OEM_DATA,               "OEM Data" },
536   { SF_OB_IB_SAVE_OR_RESTORE_FORMAT, "Save/Restore Format" },
537   { SF_OB_IB_SELECT_IPDS_MODE,       "Select IPDS Mode." },
538   { 0x00, NULL }
539 };
540
541 /*--- 5.11 Load Format Storage ----- */
542 #define LOAD_FORMAT_STORAGE_OPERAND_ADD                     0x01
543 #define LOAD_FORMAT_STORAGE_OPERAND_DELETE_FORMAT           0x02
544 #define LOAD_FORMAT_STORAGE_OPERAND_DELETE_GROUP            0x03
545 #define LOAD_FORMAT_STORAGE_OPERAND_RESET_ALL               0x04
546 #define LOAD_FORMAT_STORAGE_OPERAND_REQUEST_SUMMARY_STATUS  0x05
547 #define LOAD_FORMAT_STORAGE_OPERAND_REQUEST_GROUP_STATUS    0x06
548
549 static const value_string vals_load_storage_format_operand[] = {
550   { LOAD_FORMAT_STORAGE_OPERAND_ADD,                     "Add" },
551   { LOAD_FORMAT_STORAGE_OPERAND_DELETE_FORMAT,           "Delete Format" },
552   { LOAD_FORMAT_STORAGE_OPERAND_DELETE_GROUP,            "Delete Group" },
553   { LOAD_FORMAT_STORAGE_OPERAND_RESET_ALL,               "Reset All" },
554   { LOAD_FORMAT_STORAGE_OPERAND_REQUEST_SUMMARY_STATUS,  "Request Summary Status" },
555   { LOAD_FORMAT_STORAGE_OPERAND_REQUEST_GROUP_STATUS,    "Request Group Status" },
556   { 0x00, NULL }
557 };
558
559 /*--- 5.19 Read Partition ----- */
560 #define READ_PARTITION_OPTYPE_QUERY              0x02
561 #define READ_PARTITION_OPTYPE_QUERY_LIST         0x03
562 #define READ_PARTITION_OPTYPE_READ_MODIFIED_ALL  0x6E
563 #define READ_PARTITION_OPTYPE_READ_BUFFER        0xF2
564 #define READ_PARTITION_OPTYPE_READ_MODIFIED      0xF6
565
566 static const value_string vals_read_partition_operation_type[] = {
567   { READ_PARTITION_OPTYPE_QUERY,             "Read Partition Query" },
568   { READ_PARTITION_OPTYPE_QUERY_LIST,        "Read Partition Query List" },
569   { READ_PARTITION_OPTYPE_READ_MODIFIED_ALL, "Read Partition Read Modified All" },
570   { READ_PARTITION_OPTYPE_READ_BUFFER,       "Read Partition Read Buffer" },
571   { READ_PARTITION_OPTYPE_READ_MODIFIED,     "Read Partition Read Modified" },
572   { 0x00, NULL }
573 };
574
575 #define READ_PARTITION_REQTYPE_MASK 0xC0
576 static const value_string vals_read_partition_reqtype[] = {
577   { 0x00, "QCODE List" },
578   { 0x01, "Equivalent + QCODE List" },
579   { 0x02, "All" },
580   { 0x00, NULL }
581 };
582
583 /*--- 5.34 Data Chain ----- */
584 #define DATA_CHAIN_GROUP_MASK           0x60
585 #define DATA_CHAIN_INBOUND_CONTROL_MASK 0x18
586
587 static const value_string vals_data_chain_group[] = {
588   { 0x00, "Continue" },
589   { 0x01, "End" },
590   { 0x02, "Begin" },
591   { 0x03, "Only" },
592   { 0x00, NULL }
593 };
594
595 static const value_string vals_data_chain_inbound_control[] = {
596   { 0x00, "No Change" },
597   { 0x01, "Enable Inbound Data Chaining" },
598   { 0x02, "Disable Inbound Data Chaining" },
599   { 0x03, "Reserved" },
600   { 0x00, NULL }
601 };
602
603 /*--- 5.35 Destination or Origin ----- */
604 #define DESTINATION_OR_ORIGIN_FLAGS_INPUT_CONTROL_MASK 0xC0
605
606 static const value_string vals_destination_or_origin_flags_input_control[] = {
607   { 0x00, "Enable input" },
608   { 0x01, "No Change" },
609   { 0x02, "Disable Input" },
610   { 0x03, "Reserved" },
611   { 0x00, NULL }
612 };
613
614
615 /* INBOUND DATA STREAM (DISPLAY -> MAINFRAME PROGRAM) */
616
617 /*
618   ______ _______ ________ _______
619   |      |       |        |       |
620   | AID  | Cursor address | Data |
621   |      | (2 bytes)      |       |
622   |      |       |        |       |
623   |______|_______|________|_______|
624
625   An inbound data stream can also consist of an AID (X'88') followed by
626   structured fields as follows:
627   ______ __________________ ________ ___________________
628   |      |                  |        |                   |
629   | AID  | Structured Field | ...... | Structured Field  |
630   | 0x88 |                  |        |                   |
631   |______|__________________|________|___________________|
632
633 */
634
635
636 /*--- 3.5.6 Attention Identification Bytes (AID) ----- */
637 #define AID_NO_AID_GENERATED               0x60
638 #define AID_NO_AID_GENERATED_PRINTER_ONLY  0xE8
639 #define AID_STRUCTURED_FIELD               0x88
640 #define AID_READ_PARTITION_AID             0x61
641 #define AID_TRIGGER_ACTION                 0x7F
642 #define AID_TEST_REQ_AND_SYS_REQ           0xF0
643 #define AID_PF1_KEY                        0xF1
644 #define AID_PF2_KEY                        0xF2
645 #define AID_PF3_KEY                        0xF3
646 #define AID_PF4_KEY                        0xF4
647 #define AID_PF5_KEY                        0xF5
648 #define AID_PF6_KEY                        0xF6
649 #define AID_PF7_KEY                        0xF7
650 #define AID_PF8_KEY                        0xF8
651 #define AID_PF9_KEY                        0xF9
652 #define AID_PF10_KEY                       0x7A
653 #define AID_PF11_KEY                       0x7B
654 #define AID_PF12_KEY                       0x7C
655 #define AID_PF13_KEY                       0xC1
656 #define AID_PF14_KEY                       0xC2
657 #define AID_PF15_KEY                       0xC3
658 #define AID_PF16_KEY                       0xC4
659 #define AID_PF17_KEY                       0xC5
660 #define AID_PF18_KEY                       0xC6
661 #define AID_PF19_KEY                       0xC7
662 #define AID_PF20_KEY                       0xC8
663 #define AID_PF21_KEY                       0xC9
664 #define AID_PF22_KEY                       0x4A
665 #define AID_PF23_KEY                       0x4B
666 #define AID_PF24_KEY                       0x4C
667 #define AID_PA1_KEY                        0x6C
668 #define AID_PA2_KEY_CNCL                   0x6E
669 #define AID_PA3_KEY                        0x6B
670 #define AID_CLEAR_KEY                      0x6D
671 #define AID_CLEAR_PARTITION_KEY            0x6A
672 #define AID_ENTER_KEY                      0x7D
673 #define AID_SELECTOR_PEN_ATTENTION         0x7E
674 #define AID_OPERATOR_ID_READER             0xE6
675 #define AID_MAG_READER_NUMBER              0xE7
676
677 static const value_string vals_attention_identification_bytes[] = {
678   { AID_NO_AID_GENERATED,              "No AID generated" },
679   { AID_NO_AID_GENERATED_PRINTER_ONLY, "No AID generated (printer only)" },
680   { AID_STRUCTURED_FIELD,              "Structured field" },
681   { AID_READ_PARTITION_AID,            "Read partition" },
682   { AID_TRIGGER_ACTION,                "Trigger action" },
683   { AID_TEST_REQ_AND_SYS_REQ,          "Test Req and Sys Req" },
684   { AID_PF1_KEY,                       "PF1 key" },
685   { AID_PF2_KEY,                       "PF2 key" },
686   { AID_PF3_KEY,                       "PF3 key" },
687   { AID_PF4_KEY,                       "PF4 key" },
688   { AID_PF5_KEY,                       "PF5 key" },
689   { AID_PF6_KEY,                       "PF6 key" },
690   { AID_PF7_KEY,                       "PF7 key" },
691   { AID_PF8_KEY,                       "PF8 key" },
692   { AID_PF9_KEY,                       "PF9 key" },
693   { AID_PF10_KEY,                      "PF10 key" },
694   { AID_PF11_KEY,                      "PF11 key" },
695   { AID_PF12_KEY,                      "PF12 key" },
696   { AID_PF13_KEY,                      "PF13 key" },
697   { AID_PF14_KEY,                      "PF14 key" },
698   { AID_PF15_KEY,                      "PF15 key" },
699   { AID_PF16_KEY,                      "PF16 key" },
700   { AID_PF17_KEY,                      "PF17 key" },
701   { AID_PF18_KEY,                      "PF18 key" },
702   { AID_PF19_KEY,                      "PF19 key" },
703   { AID_PF20_KEY,                      "PF20 key" },
704   { AID_PF21_KEY,                      "PF21 key" },
705   { AID_PF22_KEY,                      "PF22 key" },
706   { AID_PF23_KEY,                      "PF23 key" },
707   { AID_PF24_KEY,                      "PF24 key" },
708   { AID_PA1_KEY,                       "PA1 key" },
709   { AID_PA2_KEY_CNCL,                  "PA2 key (Cncl)" },
710   { AID_PA3_KEY,                       "PA3 key" },
711   { AID_CLEAR_KEY,                     "Clear key" },
712   { AID_CLEAR_PARTITION_KEY,           "Clear Partition key" },
713   { AID_ENTER_KEY,                     "Enter key" },
714   { AID_SELECTOR_PEN_ATTENTION,        "Selector pen attention" },
715   { AID_OPERATOR_ID_READER,            "Operator ID reader" },
716   { AID_MAG_READER_NUMBER,             "Mag Reader Number" },
717   { 0x00, NULL }
718 };
719
720 /*--- 5.3.6 Object Control ----- */
721 #define OBJC_GRAPHICS  0x00
722 #define OBJC_IMAGE     0x01
723
724 static const value_string vals_oc_type[] = {
725   { OBJC_GRAPHICS, "Graphics" },
726   { OBJC_IMAGE,    "Image)" },
727   { 0x00, NULL }
728 };
729
730 /*--- 6.1 Inbound Structured Fields ----- */
731 #define SF_IB_EXCEPTION_OR_STATUS                            0x0F22
732 #define SF_IB_INBOUND_TEXT_HEADER                            0x0FB1
733 #define SF_IB_INBOUND_3270DS                                 0x0F80 /* TODO: Check */
734 #define SF_IB_RECOVERY_DATA                                  0x1031
735 #define SF_IB_TYPE_1_TEXT_INBOUND                            0x0FC1
736 #define SF_IB_QUERY_REPLY_ALPHANUMERIC_PARTITIONS            0x8184
737 #define SF_IB_QUERY_REPLY_AUXILIARY_DEVICE                   0x8199
738 #define SF_IB_QUERY_REPLY_BEGIN_OR_END_OF_FILE               0x819F
739 #define SF_IB_QUERY_REPLY_CHARACTER_SETS                     0x8185
740 #define SF_IB_QUERY_REPLY_COLOR                              0x8186
741 #define SF_IB_QUERY_REPLY_COOPERATIVE_PROCESSING_REQUESTOR   0x81AB
742 #define SF_IB_QUERY_REPLY_DATA_CHAINING                      0x8198
743 #define SF_IB_QUERY_REPLY_DATA_STREAMS                       0x81A2
744 #define SF_IB_QUERY_REPLY_DBCS_ASIA                          0x8191
745 #define SF_IB_QUERY_REPLY_DEVICE_CHARACTERISTICS             0x81A0
746 #define SF_IB_QUERY_REPLY_DISTRIBUTED_DATA_MANAGEMENT        0x8195
747 #define SF_IB_QUERY_REPLY_DOCUMENT_INTERCHANGE_ARCHITECTURE  0x8197
748 #define SF_IB_QUERY_REPLY_EXTENDED_DRAWING_ROUTINE           0x81B5
749 #define SF_IB_QUERY_REPLY_FIELD_OUTLINING                    0x818C
750 #define SF_IB_QUERY_REPLY_FIELD_VALIDATION                   0x818A
751 #define SF_IB_QUERY_REPLY_FORMAT_PRESENTATION                0x8190
752 #define SF_IB_QUERY_REPLY_FORMAT_STORAGE_AUXILIARY_DEVICE    0x8194
753 #define SF_IB_QUERY_REPLY_GRAPHIC_COLOR                      0x81B4
754 #define SF_IB_QUERY_REPLY_GRAPHIC_SYMBOL_SETS                0x81B6
755 #define SF_IB_QUERY_REPLY_HIGHLIGHTING                       0x8187
756 #define SF_IB_QUERY_REPLY_IBM_AUXILIARY_DEVICE               0x819E
757 #define SF_IB_QUERY_REPLY_IMAGE                              0x8182
758 #define SF_IB_QUERY_REPLY_IMPLICIT_PARTITION                 0x81A6
759 #define SF_IB_QUERY_REPLY_IOCA_AUXILIARY_DEVICE              0x81AA
760 #define SF_IB_QUERY_REPLY_LINE_TYPE                          0x81B2
761 #define SF_IB_QUERY_REPLY_MSR_CONTROL                        0x818B
762 #define SF_IB_QUERY_REPLY_NULL                               0x81FF
763 #define SF_IB_QUERY_REPLY_OEM_AUXILIARY_DEVICE               0x818F
764 #define SF_IB_QUERY_REPLY_PAPER_FEED_TECHNIQUES              0x81A7
765 #define SF_IB_QUERY_REPLY_PARTITION_CHARACTERISTICS          0x818E
766 #define SF_IB_QUERY_REPLY_PORT                               0x81B3
767 #define SF_IB_QUERY_REPLY_PROCEDURE                          0x81B1
768 #define SF_IB_QUERY_REPLY_PRODUCT_DEFINED_DATA_STREAM        0x819C
769 #define SF_IB_QUERY_REPLY_REPLY_MODES                        0x8188
770 #define SF_IB_QUERY_REPLY_RPQ_NAMES                          0x81A1
771 #define SF_IB_QUERY_REPLY_SAVE_OR_RESTORE_FORMAT             0x8192
772 #define SF_IB_QUERY_REPLY_SEGMENT                            0x81B0
773 #define SF_IB_QUERY_REPLY_SETTABLE_PRINTER_CHARACTERISTICS   0x81A9
774 #define SF_IB_QUERY_REPLY_STORAGE_POOLS                      0x8196
775 #define SF_IB_QUERY_REPLY_SUMMARY                            0x8180
776 #define SF_IB_QUERY_REPLY_TEXT_PARTITIONS                    0x8183
777 #define SF_IB_QUERY_REPLY_TRANSPARENCY                       0x81A8
778 #define SF_IB_QUERY_REPLY_USABLE_AREA                        0x8181
779 #define SF_IB_QUERY_REPLY_3270_IPDS                          0x819A
780
781 static const value_string vals_inbound_structured_fields[] = {
782   { SF_IB_EXCEPTION_OR_STATUS,                           "Exception/Status" },
783   { SF_IB_INBOUND_TEXT_HEADER,                           "Inbound Text Header" },
784   { SF_IB_INBOUND_3270DS,                                "Inbound 3270DS" },
785   { SF_IB_RECOVERY_DATA,                                 "Recovery Data" },
786   { SF_IB_TYPE_1_TEXT_INBOUND,                           "Type 1 Text Inbound" },
787   { SF_IB_QUERY_REPLY_ALPHANUMERIC_PARTITIONS,           "Query Reply (Alphanumeric Partitions)" },
788   { SF_IB_QUERY_REPLY_AUXILIARY_DEVICE,                  "Query Reply (Auxiliary Device)" },
789   { SF_IB_QUERY_REPLY_BEGIN_OR_END_OF_FILE,              "Query Reply (Begin/End of File)" },
790   { SF_IB_QUERY_REPLY_CHARACTER_SETS,                    "Query Reply (Character Sets)" },
791   { SF_IB_QUERY_REPLY_COLOR,                             "Query Reply (Color)" },
792   { SF_IB_QUERY_REPLY_COOPERATIVE_PROCESSING_REQUESTOR,  "Query Reply (Cooperative Processing Requestor)" },
793   { SF_IB_QUERY_REPLY_DATA_CHAINING,                     "Query Reply (Data Chaining)" },
794   { SF_IB_QUERY_REPLY_DATA_STREAMS,                      "Query Reply (Data Streams)" },
795   { SF_IB_QUERY_REPLY_DBCS_ASIA,                         "Query Reply (DBCS-Asia)" },
796   { SF_IB_QUERY_REPLY_DEVICE_CHARACTERISTICS,            "Query Reply (Device Characteristics)" },
797   { SF_IB_QUERY_REPLY_DISTRIBUTED_DATA_MANAGEMENT,       "Query Reply (Distributed Data Management)" },
798   { SF_IB_QUERY_REPLY_DOCUMENT_INTERCHANGE_ARCHITECTURE, "Query Reply (Document Interchange Architecture)" },
799   { SF_IB_QUERY_REPLY_EXTENDED_DRAWING_ROUTINE,          "Query Reply (Extended Drawing Routine)" },
800   { SF_IB_QUERY_REPLY_FIELD_OUTLINING,                   "Query Reply (Field Outlining)" },
801   { SF_IB_QUERY_REPLY_FIELD_VALIDATION,                  "Query Reply (Field Validation)" },
802   { SF_IB_QUERY_REPLY_FORMAT_PRESENTATION,               "Query Reply (Format Presentation)" },
803   { SF_IB_QUERY_REPLY_FORMAT_STORAGE_AUXILIARY_DEVICE,   "Query Reply (Format Storage Auxiliary Device)" },
804   { SF_IB_QUERY_REPLY_GRAPHIC_COLOR,                     "Query Reply (Graphic Color)" },
805   { SF_IB_QUERY_REPLY_GRAPHIC_SYMBOL_SETS,               "Query Reply (Graphic Symbol Sets)" },
806   { SF_IB_QUERY_REPLY_HIGHLIGHTING,                      "Query Reply (Highlighting)" },
807   { SF_IB_QUERY_REPLY_IBM_AUXILIARY_DEVICE,              "Query Reply (IBM Auxiliary Device)" },
808   { SF_IB_QUERY_REPLY_IMAGE,                             "Query Reply (Image)" },
809   { SF_IB_QUERY_REPLY_IMPLICIT_PARTITION,                "Query Reply (Implicit Partition)" },
810   { SF_IB_QUERY_REPLY_IOCA_AUXILIARY_DEVICE,             "Query Reply (IOCA Auxiliary Device)" },
811   { SF_IB_QUERY_REPLY_LINE_TYPE,                         "Query Reply (Line Type)" },
812   { SF_IB_QUERY_REPLY_MSR_CONTROL,                       "Query Reply (MSR Control)" },
813   { SF_IB_QUERY_REPLY_NULL,                              "Query Reply (Null)" },
814   { SF_IB_QUERY_REPLY_OEM_AUXILIARY_DEVICE,              "Query Reply (OEM Auxiliary Device)" },
815   { SF_IB_QUERY_REPLY_PAPER_FEED_TECHNIQUES,             "Query Reply (Paper Feed Techniques)" },
816   { SF_IB_QUERY_REPLY_PARTITION_CHARACTERISTICS,         "Query Reply (Partition Characteristics)" },
817   { SF_IB_QUERY_REPLY_PORT,                              "Query Reply (Port)" },
818   { SF_IB_QUERY_REPLY_PROCEDURE,                         "Query Reply (Procedure)" },
819   { SF_IB_QUERY_REPLY_PRODUCT_DEFINED_DATA_STREAM,       "Query Reply (Product Defined Data Stream)" },
820   { SF_IB_QUERY_REPLY_REPLY_MODES,                       "Query Reply (Reply Modes)" },
821   { SF_IB_QUERY_REPLY_RPQ_NAMES,                         "Query Reply (RPQ Names)" },
822   { SF_IB_QUERY_REPLY_SAVE_OR_RESTORE_FORMAT,            "Query Reply (Save/Restore Format)" },
823   { SF_IB_QUERY_REPLY_SEGMENT,                           "Query Reply (Segment)" },
824   { SF_IB_QUERY_REPLY_SETTABLE_PRINTER_CHARACTERISTICS,  "Query Reply (Settable Printer Characteristics)" },
825   { SF_IB_QUERY_REPLY_STORAGE_POOLS,                     "Query Reply (Storage Pools)" },
826   { SF_IB_QUERY_REPLY_SUMMARY,                           "Query Reply (Summary)" },
827   { SF_IB_QUERY_REPLY_TEXT_PARTITIONS,                   "Query Reply (Text Partitions)" },
828   { SF_IB_QUERY_REPLY_TRANSPARENCY,                      "Query Reply (Transparency)" },
829   { SF_IB_QUERY_REPLY_USABLE_AREA,                       "Query Reply (Usable Area)" },
830   { SF_IB_QUERY_REPLY_3270_IPDS,                         "Query Reply (3270 IPDS)." },
831   { 0x00, NULL }
832 };
833
834 /*--- 6.2 - Exception/Status ----- */
835 #define SDP_STATCODE_ACKNOWLEDGED     0x0000
836 #define SDP_STATCODE_AUXDEVICEAVAIL   0X0001
837
838 static const value_string vals_sdp_statcode[] = {
839   { SDP_STATCODE_ACKNOWLEDGED,   "Acknowledged. The formats were successfully loaded, and no exception occurred." },
840   { SDP_STATCODE_AUXDEVICEAVAIL, "Auxiliary device available" },
841   { 0x00, NULL }
842 };
843
844 #define SDP_EXCODE_INVALID_DOID    0x0801
845 #define SDP_EXCODE_DEVICENOTAVAIL  0X0802
846 #define SDP_EXCODE_RETIRED         0X0803
847 #define SDP_EXCODE_BUFFER_OVERRUN  0X0804
848 #define SDP_EXCODE_STORAGE         0X0805
849 #define SDP_EXCODE_FORMATNOTSPEC   0X0806
850 #define SDP_EXCODE_DATAERROR       0X0807
851 #define SDP_EXCODE_INSUFFRESOURCE  0X084B
852 #define SDP_EXCODE_EXCEEDSLIMIT    0X084C
853 #define SDP_EXCODE_FUNCTNOTSUPP    0X1003
854
855 static const value_string vals_sdp_excode[] = {
856   { SDP_EXCODE_INVALID_DOID,
857     "Invalid/unrecognized DOID in the Destination/Origin structured field."
858     " AVAILSTAT must be set to B'0'." },
859   { SDP_EXCODE_DEVICENOTAVAIL,
860     "DOID valid, but the auxiliary device is not available because of an"
861     " intervention required condition (for example, out of paper, power"
862     " off, or processing code not resident). Available status is sent"
863     " when the condition clears. AVAILSTAT must be set to B'1'." },
864   { SDP_EXCODE_RETIRED,
865     "Retired." },
866   { SDP_EXCODE_BUFFER_OVERRUN,
867     "Buffer overrun." },
868   { SDP_EXCODE_STORAGE,
869     "Insufficient storage. The loading of the formats could not be"
870     " completed because storage was exhausted." },
871   { SDP_EXCODE_FORMATNOTSPEC,
872     "The format or group name was not specified in the Load Format"
873     " Storage structured field." },
874   { SDP_EXCODE_DATAERROR,
875     "Data error." },
876   { SDP_EXCODE_INSUFFRESOURCE,
877     "Temporary insufficient resource. The application does not have"
878     " a buffer available or is busy. The device chooses whether to"
879     " set send status when the condition clears and set AVAILSTAT accordingly." },
880   { SDP_EXCODE_EXCEEDSLIMIT,
881     "The auxiliary device data in the transmission exceeds the limit specified"
882     " in the LIMOUT parameter of the Query Reply for the auxiliary device."
883     " AVAILSTAT must be set to B'0'." },
884   { SDP_EXCODE_FUNCTNOTSUPP,
885     "Function not supported." },
886   { 0x00, NULL }
887 };
888
889 /* Query Reply Types */
890 #define SF_QR_ALPHANUMERIC_PARTITIONS            0x84
891 #define SF_QR_AUXILIARY_DEVICE                   0x99
892 #define SF_QR_QBEGIN_OR_END_OF_FILE              0x9F
893 #define SF_QR_CHARACTER_SETS                     0x85
894 #define SF_QR_COLOR                              0x86
895 #define SF_QR_COOPERATIVE_PROCESSING_REQUESTOR   0xAB
896 #define SF_QR_DATA_CHAINING                      0x98
897 #define SF_QR_DATA_STREAMS                       0xA2
898 #define SF_QR_DBCS_ASIA                          0x91
899 #define SF_QR_DEVICE_CHARACTERISTICS             0xA0
900 #define SF_QR_DISTRIBUTED_DATA_MANAGEMENT        0x95
901 #define SF_QR_DOCUMENT_INTERCHANGE_ARCHITECTURE  0x97
902 #define SF_QR_EXTENDED_DRAWING_ROUTINE           0xB5
903 #define SF_QR_QFIELD_OUTLINING                   0x8C
904 #define SF_QR_QFIELD_VALIDATION                  0x8A
905 #define SF_QR_FORMAT_PRESENTATION                0x90
906 #define SF_QR_FORMAT_STORAGE_AUXILIARY_DEVICE    0x94
907 #define SF_QR_GRAPHIC_COLOR                      0xB4
908 #define SF_QR_GRAPHIC_SYMBOL_SETS                0xB6
909 #define SF_QR_HIGHLIGHTING                       0x87
910 #define SF_QR_IBM_AUXILIARY_DEVICE               0x9E
911 #define SF_QR_IMAGE                              0x82
912 #define SF_QR_IMPLICIT_PARTITION                 0xA6
913 #define SF_QR_IOCA_AUXILIARY_DEVICE              0xAA
914 #define SF_QR_LINE_TYPE                          0xB2
915 #define SF_QR_MSR_CONTROL                        0x8B
916 #define SF_QR_QNULL                              0xFF
917 #define SF_QR_OEM_AUXILIARY_DEVICE               0x8F
918 #define SF_QR_PAPER_FEED_TECHNIQUES              0xA7
919 #define SF_QR_PARTITION_CHARACTERISTICS          0x8E
920 #define SF_QR_PORT                               0xB3
921 #define SF_QR_PROCEDURE                          0xB1
922 #define SF_QR_PRODUCT_DEFINED_DATA_STREAM        0x9C
923 #define SF_QR_REPLY_MODES                        0x88
924 #define SF_QR_RPQ_NAMES                          0xA1
925 #define SF_QR_QSAVE_OR_RESTORE_FORMAT            0x92
926 #define SF_QR_SEGMENT                            0xB0
927 #define SF_QR_SETTABLE_PRINTER_CHARACTERISTICS   0xA9
928 #define SF_QR_STORAGE_POOLS                      0x96
929 #define SF_QR_SUMMARY                            0x80
930 #define SF_QR_TEXT_PARTITIONS                    0x83
931 #define SF_QR_QTRANSPARENCY                      0xA8
932 #define SF_QR_USABLE_AREA                        0x81
933 #define SF_QR_T3270_IPDS                         0x9A
934
935 static const value_string vals_sf_query_replies[] = {
936   { SF_QR_ALPHANUMERIC_PARTITIONS,           "Alphanumeric Partitions" },
937   { SF_QR_AUXILIARY_DEVICE,                  "Auxiliary Device" },
938   { SF_QR_QBEGIN_OR_END_OF_FILE,             "Begin/End of File" },
939   { SF_QR_CHARACTER_SETS,                    "Character Sets" },
940   { SF_QR_COLOR,                             "Color" },
941   { SF_QR_COOPERATIVE_PROCESSING_REQUESTOR,  "Cooperative Processing Requestor" },
942   { SF_QR_DATA_CHAINING,                     "Data Chaining" },
943   { SF_QR_DATA_STREAMS,                      "Data Streams" },
944   { SF_QR_DBCS_ASIA,                         "DBCS-Asia" },
945   { SF_QR_DEVICE_CHARACTERISTICS,            "Device Characteristics" },
946   { SF_QR_DISTRIBUTED_DATA_MANAGEMENT,       "Distributed Data Management" },
947   { SF_QR_DOCUMENT_INTERCHANGE_ARCHITECTURE, "Document Interchange Architecture" },
948   { SF_QR_EXTENDED_DRAWING_ROUTINE,          "Extended Drawing Routine" },
949   { SF_QR_QFIELD_OUTLINING,                  "Field Outlining" },
950   { SF_QR_QFIELD_VALIDATION,                 "Field Validation" },
951   { SF_QR_FORMAT_PRESENTATION,               "Format Presentation" },
952   { SF_QR_FORMAT_STORAGE_AUXILIARY_DEVICE,   "Format Storage Auxiliary Device" },
953   { SF_QR_GRAPHIC_COLOR,                     "Graphic Color" },
954   { SF_QR_GRAPHIC_SYMBOL_SETS,               "Graphic Symbol Sets" },
955   { SF_QR_HIGHLIGHTING,                      "Highlighting" },
956   { SF_QR_IBM_AUXILIARY_DEVICE,              "IBM Auxiliary Device" },
957   { SF_QR_IMAGE,                             "Image" },
958   { SF_QR_IMPLICIT_PARTITION,                "Implicit Partition" },
959   { SF_QR_IOCA_AUXILIARY_DEVICE,             "IOCA Auxiliary Device" },
960   { SF_QR_LINE_TYPE,                         "Line Type" },
961   { SF_QR_MSR_CONTROL,                       "MSR Control" },
962   { SF_QR_QNULL,                             "Null" },
963   { SF_QR_OEM_AUXILIARY_DEVICE,              "OEM Auxiliary Device" },
964   { SF_QR_PAPER_FEED_TECHNIQUES,             "Paper Feed Techniques" },
965   { SF_QR_PARTITION_CHARACTERISTICS,         "Partition Characteristics" },
966   { SF_QR_PORT,                              "Port" },
967   { SF_QR_PROCEDURE,                         "Procedure" },
968   { SF_QR_PRODUCT_DEFINED_DATA_STREAM,       "Product Defined Data Stream" },
969   { SF_QR_REPLY_MODES,                       "Reply Modes" },
970   { SF_QR_RPQ_NAMES,                         "RPQ Names" },
971   { SF_QR_QSAVE_OR_RESTORE_FORMAT,           "Save/Restore Format" },
972   { SF_QR_SEGMENT,                           "Segment" },
973   { SF_QR_SETTABLE_PRINTER_CHARACTERISTICS,  "Settable Printer Characteristics" },
974   { SF_QR_STORAGE_POOLS,                     "Storage Pools" },
975   { SF_QR_SUMMARY,                           "Summary" },
976   { SF_QR_TEXT_PARTITIONS,                   "Text Partitions" },
977   { SF_QR_QTRANSPARENCY,                     "Transparency" },
978   { SF_QR_USABLE_AREA,                       "Usable Area" },
979   { SF_QR_T3270_IPDS,                        "3270 IPDS." },
980   { 0x00, NULL }
981 };
982
983 /*--- 6.9 Query Reply Alphanumeric Partitions ----- */
984 #define QR_AP_VERTWIN  0x80
985 #define QR_AP_HORWIN   0x40
986 #define QR_AP_APRES1   0x20
987 #define QR_AP_APA_FLG  0x10
988 #define QR_AP_PROT     0x08
989 #define QR_AP_LCOPY    0x04
990 #define QR_AP_MODPART  0x02
991 #define QR_AP_APRES2   0x01
992
993 /*--- 6.12 - Query Reply (Character Sets) ----- */
994 #define QR_CS_ALT       0x80
995 #define QR_CS_MULTID    0x40
996 #define QR_CS_LOADABLE  0x20
997 #define QR_CS_EXT       0x10
998 #define QR_CS_MS        0x08
999 #define QR_CS_CH2       0x04
1000 #define QR_CS_GF        0x02
1001 #define QR_CS_CSRES     0x01
1002
1003 #define QR_CS_CSRES2    0x80
1004 #define QR_CS_PSCS      0x40
1005 #define QR_CS_CSRES3    0x20
1006 #define QR_CS_CF        0x10
1007 #define QR_CS_CSRES4    0x08
1008 #define QR_CS_CSRES5    0x04
1009 #define QR_CS_GCSRES6   0x02
1010 #define QR_CS_CSRES7    0x01
1011
1012
1013 /*--- 6.15 Query Reply (Data Chaining) ----- */
1014 static const value_string vals_data_chaining_dir[] = {
1015   { 0x00, "Both" },
1016   { 0x01, "From device only" },
1017   { 0x02, "To device only" },
1018   { 0x00, NULL }
1019 };
1020
1021 /*--- 6.16 Query Reply (Data Streams) ----- */
1022 #define QR_DS_SCS       0x00
1023 #define QR_DS_DCAL2     0x01
1024 #define QR_DS_IPDS      0x02
1025
1026 static const value_string vals_data_streams[] = {
1027   { QR_DS_SCS,
1028     "SCS Base Data Stream with extensions as specified in the BIND request"
1029     " and Device Characteristics Query Reply structured field" },
1030   { QR_DS_DCAL2,
1031     "Document Content Architecture Level 2" },
1032   { QR_DS_IPDS,
1033     "IPDS as defined in related documentation" },
1034   { 0x00, NULL }
1035 };
1036
1037 /*--- 6.51 Query Reply Usable Area ----- */
1038 #define QR_UA_RESERVED1                         0x80
1039 #define QR_UA_PAGE_PRINTER                      0x40
1040 #define QR_UA_RESERVED2                         0x20
1041 #define QR_UA_HARD_COPY                         0x10
1042
1043 #define QR_UA_ADDR_MODE_MASK                         0x0F
1044 #define  QR_UA_ADDR_MODE_RESERVED1                    0x00
1045 #define  QR_UA_ADDR_MODE_TWELVE_FOURTEEN_BIT_OK       0x01
1046 #define  QR_UA_ADDR_MODE_RESERVED2                    0x02
1047 #define  QR_UA_ADDR_MODE_TWELVE_FOURTEEN_SXTN_BIT_OK  0x03
1048 #define  QR_UA_ADDR_MODE_UNMAPPED                     0x0F
1049
1050 static const value_string vals_usable_area_addr_mode[] = {
1051   { QR_UA_ADDR_MODE_RESERVED1,                    "Reserved" },
1052   { QR_UA_ADDR_MODE_TWELVE_FOURTEEN_BIT_OK,       "Twelve/Fourteen Bit Addressing Allowed" },
1053   { QR_UA_ADDR_MODE_RESERVED2,                    "Reserved" },
1054   { QR_UA_ADDR_MODE_TWELVE_FOURTEEN_SXTN_BIT_OK , "Twelve/Fourteen/Sixteen Bit Addressing Allowed" },
1055   { QR_UA_ADDR_MODE_UNMAPPED,                     "Unmapped" },
1056   { 0x00, NULL }
1057 };
1058
1059 #define QR_UA_VARIABLE_CELLS  0x80
1060 #define QR_UA_CHARACTERS      0x40
1061 #define QR_UA_CELL_UNITS      0x20
1062
1063 static const struct true_false_string tn3270_tfs_ua_variable_cells = {
1064   "Supported",
1065   "Not supported"
1066 };
1067
1068 static const struct true_false_string tn3270_tfs_ua_characters = {
1069   "Non-matrix character",
1070   "Matrix character"
1071 };
1072
1073 static const struct true_false_string tn3270_tfs_ua_cell_units = {
1074   "Pels",
1075   "Cells"
1076 };
1077
1078
1079 #define QR_UA_UOM_INCHES       0x00
1080 #define QR_UA_UOM_MILLIMETERS  0x01
1081
1082 static const value_string vals_usable_area_uom[] = {
1083   { QR_UA_UOM_INCHES,      "Inches" },
1084   { QR_UA_UOM_MILLIMETERS, "Millimeters" },
1085   { 0x00, NULL }
1086 };
1087
1088 /*--- 6.42 - Query reply (Reply Modes) ----- */
1089 /* Also for: 5.30 - Set Reply Mode */
1090
1091 #define RM_REPLY_FIELD_MODE           0x00
1092 #define RM_REPLY_EXTENDED_FIELD_MODE  0x01
1093 #define RM_REPLY_CHARACTER_MODE       0x02
1094
1095 static const value_string vals_reply_modes[] = {
1096   { RM_REPLY_FIELD_MODE,          "Field Mode" },
1097   { RM_REPLY_EXTENDED_FIELD_MODE, "Extended Field Mode" },
1098   { RM_REPLY_CHARACTER_MODE,      "Character Mode" },
1099   { 0x00, NULL }
1100 };
1101
1102 /*--- 6.19 - Query Reply (Distributed Data Management) ----- */
1103 #define QR_DDM_COPY_SUBSET_1  0x01
1104
1105 static const value_string vals_qr_ddm[] = {
1106   { QR_DDM_COPY_SUBSET_1, "DDM Copy Subset 1" },
1107   { 0x00, NULL }
1108 };
1109
1110 /*--- 6.20 - Query Reply (Document Interchange Architecture) ----- */
1111 #define QR_DIA_FILE_SERVER      0x01
1112 #define QR_DIA_FILE_REQ         0x02
1113 #define QR_DIA_FILE_SERVER_REQ  0x03
1114
1115 static const value_string vals_qr_dia[] = {
1116   { QR_DIA_FILE_SERVER,     "File Server" },
1117   { QR_DIA_FILE_REQ,        "File Requestor" },
1118   { QR_DIA_FILE_SERVER_REQ, "Both File Server and File Requestor" },
1119   { 0x00, NULL }
1120 };
1121
1122 /*--- 6.31 - Query Reply (Implicit Partitions) ----- */
1123 #define QR_IP_SDP_DISPLAY    0x01
1124 #define QR_IP_SDP_PRINTER    0x02
1125 #define QR_IP_SDP_CHARACTER  0x03
1126
1127 #if 0
1128 static const value_string vals_qr_ip[] = {
1129   { QR_IP_SDP_DISPLAY,   "Display Devices" },
1130   { QR_IP_SDP_PRINTER,   "Printer Devices" },
1131   { QR_IP_SDP_CHARACTER, "Character Devices" },
1132   { 0x00, NULL }
1133 };
1134 #endif
1135
1136 /*--- 6.41 - Query Reply (Product Defined Data Streams) ----- */
1137 #define QR_PDDS_REFID_GRAPH5080  0x01
1138 #define QR_PDDS_REFID_WHIPAPI    0x02
1139
1140 static const value_string vals_qr_pdds_refid[] = {
1141   { QR_PDDS_REFID_GRAPH5080, "Supports the 5080 Graphics System" },
1142   { QR_PDDS_REFID_WHIPAPI,   "Supports the WHIP API data stream" },
1143   { 0x00, NULL }
1144 };
1145
1146 #define QR_PDDS_SSID_HFGD   0x01
1147 #define QR_PDDS_SSID_RS232  0x02
1148
1149 static const value_string vals_qr_pdds_ssid[] = {
1150   { QR_PDDS_SSID_HFGD , "5080 HFGD Graphics Subset" },
1151   { QR_PDDS_SSID_RS232, "5080 RS232 Ports Subset" },
1152   { 0x00, NULL }
1153 };
1154
1155 /*--- 6.47 - Query Reply (Storage Pools) ----- */
1156 #define QR_SP_OBJ_SEGMENT1          0x0001
1157 #define QR_SP_OBJ_PROCEDURE1        0x0002
1158 #define QR_SP_OBJ_EXTENDED_DRAWING  0x0003
1159 #define QR_SP_OBJ_DATA_UNIT         0x0004
1160 #define QR_SP_OBJ_TEMPORARY         0x0005
1161 #define QR_SP_OBJ_LINE_TYPE1        0x0006
1162 #define QR_SP_OBJ_SYMBOL_SET        0x0007
1163
1164 static const value_string vals_sp_objlist[] = {
1165   { QR_SP_OBJ_SEGMENT1,         "Segment" },
1166   { QR_SP_OBJ_PROCEDURE1,       "Procedure" },
1167   { QR_SP_OBJ_EXTENDED_DRAWING, "Extended drawing routine" },
1168   { QR_SP_OBJ_DATA_UNIT,        "Data unit" },
1169   { QR_SP_OBJ_TEMPORARY,        "Temporary" },
1170   { QR_SP_OBJ_LINE_TYPE1,       "Line type" },
1171   { QR_SP_OBJ_SYMBOL_SET,       "Symbol set" },
1172   { 0x00, NULL }
1173 };
1174
1175 /* TN3270E Header - Data Type */
1176 #define TN3270E_3270_DATA     0x00
1177 #define TN3270E_BIND_IMAGE    0x03
1178 #define TN3270E_NVT_DATA      0x05
1179 #define TN3270E_REQUEST       0x06
1180 #define TN3270E_RESPONSE      0x02
1181 #define TN3270E_SCS_DATA      0x01
1182 #define TN3270E_SSCP_LU_DATA  0x07
1183 #define TN3270E_UNBIND        0x04
1184
1185 static const value_string vals_tn3270_header_data_types[] = {
1186   { TN3270E_3270_DATA,    "3270_DATA" },
1187   { TN3270E_BIND_IMAGE,   "BIND_IMAGE" },
1188   { TN3270E_NVT_DATA,     "NVT_DATA" },
1189   { TN3270E_REQUEST,      "REQUEST" },
1190   { TN3270E_RESPONSE,     "RESPONSE" },
1191   { TN3270E_SCS_DATA,     "SCS_DATA" },
1192   { TN3270E_SSCP_LU_DATA, "SSCP_LU_DATA" },
1193   { TN3270E_UNBIND,       "UNBIND" },
1194   { 0x00, NULL }
1195 };
1196
1197
1198 /* TN3270E Header - Request Flags */
1199 #define TN3270E_COND_CLEARED        0x00
1200
1201 static const value_string vals_tn3270_header_request_flags[] = {
1202   { TN3270E_COND_CLEARED, "Condition Cleared" },
1203   { 0x00, NULL }
1204 };
1205
1206 /* TN3270E Header - Response Flags - Data Type 3270 and SCS */
1207 #define TN3270E_NO_RESPONSE      0x00
1208 #define TN3270E_ERROR_RESPONSE   0x01
1209 #define TN3270E_ALWAYS_RESPONSE  0x02
1210
1211 static const value_string vals_tn3270_header_response_flags_3270_SCS[] = {
1212   { TN3270E_NO_RESPONSE,     "No-Response" },
1213   { TN3270E_ERROR_RESPONSE,  "Error-Response" },
1214   { TN3270E_ALWAYS_RESPONSE, "Always-Response" },
1215   { 0x00, NULL }
1216 };
1217
1218 /* TN3270E Header _ Response Flags - Data Type Response */
1219 #define TN3270E_POSITIVE_RESPONSE  0x00
1220 #define TN3270E_NEGATIVE_RESPONSE  0x01
1221
1222 static const value_string vals_tn3270_header_response_flags_response[] = {
1223   { TN3270E_POSITIVE_RESPONSE, "Positive-Response" },
1224   { TN3270E_NEGATIVE_RESPONSE, "Negative-Response" },
1225   { 0x00, NULL }
1226 };
1227
1228 /*
1229  * Data structure attached to a conversation, giving session information.
1230  */
1231 typedef struct tn3270_conv_info_t {
1232   guint32 outbound_port;
1233   gint    extended;
1234   guint8  altrows;
1235   guint8  altcols;
1236   guint8  rows;
1237   guint8  cols;
1238 } tn3270_conv_info_t;
1239
1240
1241 static int proto_tn3270 = -1;
1242
1243 static int hf_tn3270_fa_display = -1;
1244 static int hf_tn3270_fa_graphic_convert = -1;
1245 static int hf_tn3270_fa_modified = -1;
1246 static int hf_tn3270_fa_numeric = -1;
1247 static int hf_tn3270_fa_protected = -1;
1248 static int hf_tn3270_fa_reserved = -1;
1249 static int hf_tn3270_field_attribute = -1;
1250 static int hf_tn3270_aid = -1;
1251 static int hf_tn3270_all_character_attributes = -1;
1252 static int hf_tn3270_attribute_type = -1;
1253 static int hf_tn3270_begin_end_flags1 = -1;
1254 static int hf_tn3270_begin_end_flags2 = -1;
1255 static int hf_tn3270_bsc = -1;
1256 static int hf_tn3270_buffer_address = -1;
1257 static int hf_tn3270_c_cav = -1;
1258 static int hf_tn3270_cc = -1;
1259 static int hf_tn3270_character_code = -1;
1260 static int hf_tn3270_character_set = -1;
1261 static int hf_tn3270_charset = -1;
1262 static int hf_tn3270_checkpoint = -1;
1263 static int hf_tn3270_c_ci = -1;
1264 static int hf_tn3270_c_offset = -1;
1265 static int hf_tn3270_color = -1;
1266 static int hf_tn3270_color_command = -1;
1267 static int hf_tn3270_color_flags = -1;
1268 static int hf_tn3270_command_code = -1;
1269 static int hf_tn3270_cro = -1;
1270 static int hf_tn3270_c_scsoff = -1;
1271 static int hf_tn3270_c_seqoff = -1;
1272 static int hf_tn3270_c_sequence = -1;
1273 static int hf_tn3270_cursor_address = -1;
1274 static int hf_tn3270_cw = -1;
1275 static int hf_tn3270_data_chain_fields = -1;
1276 static int hf_tn3270_data_chain_group = -1;
1277 static int hf_tn3270_data_chain_inbound_control = -1;
1278 static int hf_tn3270_destination_or_origin_flags_input_control = -1;
1279 static int hf_tn3270_destination_or_origin_doid = -1;
1280 static int hf_tn3270_erase_flags = -1;
1281 static int hf_tn3270_exception_or_status_flags = -1;
1282 static int hf_tn3270_extended_highlighting = -1;
1283 static int hf_tn3270_extended_ps_color = -1;
1284 static int hf_tn3270_extended_ps_echar = -1;
1285 static int hf_tn3270_extended_ps_flags = -1;
1286 static int hf_tn3270_extended_ps_length = -1;
1287 static int hf_tn3270_extended_ps_lw = -1;
1288 static int hf_tn3270_extended_ps_lh = -1;
1289 static int hf_tn3270_extended_ps_nh = -1;
1290 static int hf_tn3270_extended_ps_nw = -1;
1291 static int hf_tn3270_extended_ps_res = -1;
1292 static int hf_tn3270_extended_ps_stsubs = -1;
1293 static int hf_tn3270_extended_ps_subsn = -1;
1294 static int hf_tn3270_featl = -1;
1295 static int hf_tn3270_feats = -1;
1296 static int hf_tn3270_field_data = -1;
1297 static int hf_tn3270_field_outlining = -1;
1298 static int hf_tn3270_field_validation_mandatory_entry = -1;
1299 static int hf_tn3270_field_validation_mandatory_fill = -1;
1300 static int hf_tn3270_field_validation_trigger = -1;
1301 static int hf_tn3270_format_group = -1;
1302 static int hf_tn3270_format_name = -1;
1303 static int hf_tn3270_fov = -1;
1304 static int hf_tn3270_fpc = -1;
1305 static int hf_tn3270_hilite = -1;
1306 static int hf_tn3270_h_length = -1;
1307 static int hf_tn3270_h_offset = -1;
1308 static int hf_tn3270_horizon = -1;
1309 static int hf_tn3270_h_sequence = -1;
1310 static int hf_tn3270_hw = -1;
1311 static int hf_tn3270_interval = -1;
1312 static int hf_tn3270_limin = -1;
1313 static int hf_tn3270_limout = -1;
1314 static int hf_tn3270_lines = -1;
1315 static int hf_tn3270_load_color_command = -1;
1316 static int hf_tn3270_load_format_storage_flags1 = -1;
1317 static int hf_tn3270_load_format_storage_flags2 = -1;
1318 static int hf_tn3270_load_format_storage_format_data = -1;
1319 static int hf_tn3270_load_format_storage_localname = -1;
1320 static int hf_tn3270_load_format_storage_operand = -1;
1321 static int hf_tn3270_load_line_type_command = -1;
1322 static int hf_tn3270_lvl = -1;
1323 static int hf_tn3270_mode = -1;
1324 static int hf_tn3270_msr_ind_mask = -1;
1325 static int hf_tn3270_msr_ind_value = -1;
1326 static int hf_tn3270_msr_state_mask = -1;
1327 static int hf_tn3270_msr_state_value = -1;
1328 static int hf_tn3270_msr_type = -1;
1329 static int hf_tn3270_ap_na = -1;
1330 static int hf_tn3270_ap_m = -1;
1331 static int hf_tn3270_ap_vertical_scrolling = -1;
1332 static int hf_tn3270_ap_horizontal_scrolling = -1;
1333 static int hf_tn3270_ap_apres1 = -1;
1334 static int hf_tn3270_ap_apa = -1;
1335 static int hf_tn3270_ap_pp = -1;
1336 static int hf_tn3270_ap_lc = -1;
1337 static int hf_tn3270_ap_mp = -1;
1338 static int hf_tn3270_ap_apres2 = -1;
1339 static int hf_tn3270_c_np = -1;
1340 static int hf_tn3270_number_of_attributes = -1;
1341 static int hf_tn3270_object_control_flags = -1;
1342 static int hf_tn3270_object_type = -1;
1343 static int hf_tn3270_order_code = -1;
1344 static int hf_tn3270_outbound_text_header_operation_type = -1;
1345 static int hf_tn3270_outbound_text_header_hdr = -1;
1346 static int hf_tn3270_outbound_text_header_lhdr = -1;
1347 static int hf_tn3270_pages = -1;
1348 static int hf_tn3270_partition_command = -1;
1349 static int hf_tn3270_partition_cv = -1;
1350 static int hf_tn3270_partition_cw = -1;
1351 static int hf_tn3270_partition_flags = -1;
1352 static int hf_tn3270_partition_height = -1;
1353 static int hf_tn3270_partition_hv = -1;
1354 static int hf_tn3270_partition_id = -1;
1355 static int hf_tn3270_partition_ph = -1;
1356 static int hf_tn3270_partition_pw = -1;
1357 static int hf_tn3270_partition_res = -1;
1358 static int hf_tn3270_partition_rs = -1;
1359 static int hf_tn3270_partition_rv = -1;
1360 static int hf_tn3270_partition_rw = -1;
1361 static int hf_tn3270_partition_uom = -1;
1362 static int hf_tn3270_partition_width = -1;
1363 static int hf_tn3270_partition_wv = -1;
1364 static int hf_tn3270_prime = -1;
1365 static int hf_tn3270_printer_flags = -1;
1366 static int hf_tn3270_ps_char = -1;
1367 static int hf_tn3270_ps_flags = -1;
1368 static int hf_tn3270_ps_lcid = -1;
1369 static int hf_tn3270_ps_rws = -1;
1370 static int hf_tn3270_query_reply_alphanumeric_flags = -1;
1371 static int hf_tn3270_recovery_data_flags = -1;
1372 static int hf_tn3270_reply_mode_attr_list = -1;
1373 static int hf_tn3270_read_partition_operation_type = -1;
1374 static int hf_tn3270_read_partition_reqtyp = -1;
1375 static int hf_tn3270_resbyte = -1;
1376 static int hf_tn3270_resbytes = -1;
1377 static int hf_tn3270_res_twobytes = -1;
1378 static int hf_tn3270_rw = -1;
1379 static int hf_tn3270_save_or_restore_format_flags = -1;
1380 static int hf_tn3270_scs_data = -1;
1381 static int hf_tn3270_sf_single_byte_id = -1;
1382 static int hf_tn3270_sf_double_byte_id = -1;
1383 static int hf_tn3270_sf_length = -1;
1384 static int hf_tn3270_sf_query_reply = -1;
1385 static int hf_tn3270_sld = -1;
1386 static int hf_tn3270_spd = -1;
1387 static int hf_tn3270_start_line = -1;
1388 static int hf_tn3270_start_page = -1;
1389 static int hf_tn3270_stop_address = -1;
1390 static int hf_tn3270_transparency = -1;
1391 static int hf_tn3270_type_1_text_outbound_data = -1;
1392 static int hf_tn3270_vertical = -1;
1393 static int hf_tn3270_v_length = -1;
1394 static int hf_tn3270_v_offset = -1;
1395 static int hf_tn3270_v_sequence = -1;
1396 static int hf_tn3270_wcc_nop = -1;
1397 static int hf_tn3270_wcc_reset = -1;
1398 static int hf_tn3270_wcc_printer1 = -1;
1399 static int hf_tn3270_wcc_printer2 = -1;
1400 static int hf_tn3270_wcc_start_printer = -1;
1401 static int hf_tn3270_wcc_sound_alarm = -1;
1402 static int hf_tn3270_wcc_keyboard_restore = -1;
1403 static int hf_tn3270_wcc_reset_mdt = -1;
1404 static int hf_tn3270_ww = -1;
1405 static int hf_tn3270_tn3270e_data_type = -1;
1406 static int hf_tn3270_tn3270e_request_flag = -1;
1407 static int hf_tn3270_tn3270e_response_flag_3270_SCS = -1;
1408 static int hf_tn3270_tn3270e_response_flag_response = -1;
1409 static int hf_tn3270_tn3270e_response_flag_unused = -1;
1410 static int hf_tn3270_tn3270e_seq_number = -1;
1411 static int hf_tn3270_tn3270e_header_data = -1;
1412 static int hf_tn3270_ua_cell_units = -1;
1413 static int hf_tn3270_ua_characters = -1;
1414 static int hf_tn3270_ua_hard_copy = -1;
1415 static int hf_tn3270_ua_page_printer = -1;
1416 static int hf_tn3270_ua_reserved1 = -1;
1417 static int hf_tn3270_ua_reserved2 = -1;
1418 static int hf_tn3270_ua_variable_cells = -1;
1419 static int hf_tn3270_usable_area_flags1 = -1;
1420 static int hf_tn3270_usable_area_flags2 = -1;
1421 static int hf_tn3270_ua_addressing = -1;
1422 static int hf_tn3270_ua_width_cells_pels = -1;
1423 static int hf_tn3270_ua_height_cells_pels = -1;
1424 static int hf_tn3270_ua_uom_cells_pels = -1;
1425 static int hf_tn3270_ua_xr = -1;
1426 static int hf_tn3270_ua_yr = -1;
1427 static int hf_tn3270_ua_aw = -1;
1428 static int hf_tn3270_ua_ah = -1;
1429 static int hf_tn3270_ua_buffsz = -1;
1430 static int hf_tn3270_ua_xmin = -1;
1431 static int hf_tn3270_ua_ymin = -1;
1432 static int hf_tn3270_ua_xmax = -1;
1433 static int hf_tn3270_ua_ymax = -1;
1434 static int hf_tn3270_cs_ge = -1;
1435 static int hf_tn3270_cs_mi = -1;
1436 static int hf_tn3270_cs_lps = -1;
1437 static int hf_tn3270_cs_lpse = -1;
1438 static int hf_tn3270_cs_ms = -1;
1439 static int hf_tn3270_cs_ch2 = -1;
1440 static int hf_tn3270_cs_gf = -1;
1441 static int hf_tn3270_cs_res = -1;
1442 static int hf_tn3270_cs_res2 = -1;
1443 static int hf_tn3270_cs_pscs = -1;
1444 static int hf_tn3270_cs_res3 = -1;
1445 static int hf_tn3270_cs_cf = -1;
1446 static int hf_tn3270_cs_form_type1 = -1;
1447 static int hf_tn3270_cs_form_type2 = -1;
1448 static int hf_tn3270_cs_form_type3 = -1;
1449 static int hf_tn3270_cs_form_type4 = -1;
1450 static int hf_tn3270_cs_form_type5 = -1;
1451 static int hf_tn3270_cs_form_type6 = -1;
1452 static int hf_tn3270_cs_form_type8 = -1;
1453 static int hf_tn3270_cs_ds_load = -1;
1454 static int hf_tn3270_cs_ds_triple = -1;
1455 static int hf_tn3270_cs_ds_char = -1;
1456 static int hf_tn3270_cs_ds_cb = -1;
1457 static int hf_tn3270_character_sets_flags1 = -1;
1458 static int hf_tn3270_character_sets_flags2 = -1;
1459 static int hf_tn3270_sdw = -1;
1460 static int hf_tn3270_sdh = -1;
1461 static int hf_tn3270_form = -1;
1462 static int hf_tn3270_formres = -1;
1463 static int hf_tn3270_cs_dl = -1;
1464 static int hf_tn3270_cs_descriptor_set = -1;
1465 static int hf_tn3270_cs_descriptor_flags = -1;
1466 static int hf_tn3270_lcid = -1;
1467 static int hf_tn3270_sw = -1;
1468 static int hf_tn3270_sh = -1;
1469 static int hf_tn3270_ssubsn = -1;
1470 static int hf_tn3270_esubsn = -1;
1471 static int hf_tn3270_ccsgid = -1;
1472 static int hf_tn3270_ccsid = -1;
1473 static int hf_tn3270_c_prtblk = -1;
1474 static int hf_tn3270_h_np = -1;
1475 static int hf_tn3270_h_vi = -1;
1476 static int hf_tn3270_h_ai = -1;
1477 static int hf_tn3270_ddm_flags = -1;
1478 static int hf_tn3270_ddm_limin = -1;
1479 static int hf_tn3270_ddm_limout = -1;
1480 static int hf_tn3270_ddm_nss = -1;
1481 static int hf_tn3270_ddm_ddmss = -1;
1482 static int hf_tn3270_rpq_device = -1;
1483 static int hf_tn3270_rpq_mid = -1;
1484 static int hf_tn3270_rpq_rpql = -1;
1485 static int hf_tn3270_rpq_name = -1;
1486 static int hf_tn3270_ip_flags = -1;
1487 static int hf_tn3270_ipdd_wd = -1;
1488 static int hf_tn3270_ipdd_hd = -1;
1489 static int hf_tn3270_ipdd_wa = -1;
1490 static int hf_tn3270_ipdd_ha = -1;
1491 static int hf_tn3270_ippd_dpbs = -1;
1492 static int hf_tn3270_ippd_apbs = -1;
1493 static int hf_tn3270_ipccd_wcd = -1;
1494 static int hf_tn3270_ipccd_hcd = -1;
1495 static int hf_tn3270_ipccd_wca = -1;
1496 static int hf_tn3270_ipccd_hca = -1;
1497 static int hf_tn3270_dc_dir = -1;
1498 static int hf_tn3270_oem_dsref = -1;
1499 static int hf_tn3270_oem_dtype = -1;
1500 static int hf_tn3270_oem_uname = -1;
1501 static int hf_tn3270_sdp_daid = -1;
1502 static int hf_tn3270_oem_sdp_ll_limin = -1;
1503 static int hf_tn3270_oem_sdp_ll_limout = -1;
1504 static int hf_tn3270_oem_sdp_pclk_vers = -1;
1505 static int hf_tn3270_null = -1;
1506 static int hf_tn3270_unknown_data = -1;
1507 static int hf_tn3270_ds_default_sfid = -1;
1508 static int hf_tn3270_ds_sfid = -1;
1509 static int hf_tn3270_asia_sdp_sosi_soset = -1;
1510 static int hf_tn3270_asia_sdp_ic_func = -1;
1511 static int hf_tn3270_ccc = -1;
1512 static int hf_tn3270_ccc_coding = -1;
1513 static int hf_tn3270_ccc_printout = -1;
1514 static int hf_tn3270_ccc_start_print = -1;
1515 static int hf_tn3270_ccc_sound_alarm = -1;
1516 static int hf_tn3270_ccc_copytype = -1;
1517 static int hf_tn3270_msr_user = -1;
1518 static int hf_tn3270_msr_locked = -1;
1519 static int hf_tn3270_msr_auto = -1;
1520 static int hf_tn3270_msr_ind1 = -1;
1521 static int hf_tn3270_msr_ind2 = -1;
1522 static int hf_tn3270_spc_sdp_ot = -1;
1523 static int hf_tn3270_spc_sdp_ob = -1;
1524 static int hf_tn3270_spc_sdp_ol = -1;
1525 static int hf_tn3270_spc_sdp_or = -1;
1526 static int hf_tn3270_spc_sdp_eucflags = -1;
1527 static int hf_tn3270_spc_sdp_srepc = -1;
1528 static int hf_tn3270_srf_fpcb = -1;
1529 static int hf_tn3270_sdp_statcode = -1;
1530 static int hf_tn3270_sdp_excode = -1;
1531 static int hf_tn3270_sdp_ngl = -1;
1532 static int hf_tn3270_sdp_nml = -1;
1533 static int hf_tn3270_sdp_nlml = -1;
1534 static int hf_tn3270_sdp_stor = -1;
1535 static int hf_tn3270_ap_cm = -1;
1536 static int hf_tn3270_ap_ro = -1;
1537 static int hf_tn3270_ap_co = -1;
1538 static int hf_tn3270_ap_fo = -1;
1539 static int hf_tn3270_sdp_ln = -1;
1540 static int hf_tn3270_sdp_id = -1;
1541 static int hf_tn3270_db_cavdef = -1;
1542 static int hf_tn3270_db_cidef = -1;
1543 static int hf_tn3270_dia_flags = -1;
1544 static int hf_tn3270_dia_limin = -1;
1545 static int hf_tn3270_dia_limout = -1;
1546 static int hf_tn3270_dia_nfs = -1;
1547 static int hf_tn3270_dia_diafs = -1;
1548 static int hf_tn3270_dia_diafn = -1;
1549 static int hf_tn3270_fo_flags = -1;
1550 static int hf_tn3270_fo_vpos = -1;
1551 static int hf_tn3270_fo_hpos = -1;
1552 static int hf_tn3270_fo_hpos0 = -1;
1553 static int hf_tn3270_fo_hpos1 = -1;
1554 static int hf_tn3270_fsad_flags = -1;
1555 static int hf_tn3270_fsad_limin = -1;
1556 static int hf_tn3270_fsad_limout = -1;
1557 static int hf_tn3270_fsad_size = -1;
1558 static int hf_tn3270_ibm_flags = -1;
1559 static int hf_tn3270_ibm_limin = -1;
1560 static int hf_tn3270_ibm_limout = -1;
1561 static int hf_tn3270_ibm_type = -1;
1562 static int hf_tn3270_msr_nd = -1;
1563 static int hf_tn3270_pft_flags = -1;
1564 static int hf_tn3270_pft_tmo = -1;
1565 static int hf_tn3270_pft_bmo = -1;
1566 static int hf_tn3270_ioca_limin = -1;
1567 static int hf_tn3270_ioca_limout = -1;
1568 static int hf_tn3270_ioca_type = -1;
1569 static int hf_tn3270_pc_vo_thickness = -1;
1570 static int hf_tn3270_pdds_ssid = -1;
1571 static int hf_tn3270_pdds_refid = -1;
1572 static int hf_tn3270_srf_fpcbl = -1;
1573 static int hf_tn3270_spc_epc_flags = -1;
1574 static int hf_tn3270_sp_spid = -1;
1575 static int hf_tn3270_sp_size = -1;
1576 static int hf_tn3270_sp_space = -1;
1577 static int hf_tn3270_sp_objlist = -1;
1578 static int hf_tn3270_tp_nt = -1;
1579 static int hf_tn3270_tp_m = -1;
1580 static int hf_tn3270_tp_flags = -1;
1581 static int hf_tn3270_tp_ntt = -1;
1582 static int hf_tn3270_tp_tlist = -1;
1583 static int hf_tn3270_t_np = -1;
1584 static int hf_tn3270_t_vi = -1;
1585 static int hf_tn3270_t_ai = -1;
1586 static int hf_tn3270_3270_tranlim = -1;
1587
1588 static gint ett_tn3270 = -1;
1589 static gint ett_tn3270e_hdr = -1;
1590 static gint ett_sf = -1;
1591 static gint ett_tn3270_field_attribute = -1;
1592 static gint ett_tn3270_field_validation = -1;
1593 static gint ett_tn3270_wcc = -1;
1594 static gint ett_tn3270_usable_area_flags1 = -1;
1595 static gint ett_tn3270_usable_area_flags2 = -1;
1596 static gint ett_tn3270_query_reply_alphanumeric_flags = -1;
1597 static gint ett_tn3270_character_sets_flags1 = -1;
1598 static gint ett_tn3270_character_sets_flags2 = -1;
1599 static gint ett_tn3270_character_sets_form = -1;
1600 static gint ett_tn3270_cs_descriptor_flags = -1;
1601 static gint ett_tn3270_color_flags = -1;
1602 static gint ett_tn3270_ccc = -1;
1603 static gint ett_tn3270_msr_state_mask = -1;
1604 static gint ett_tn3270_data_chain_fields = -1;
1605 static gint ett_tn3270_query_list = -1;
1606
1607 static expert_field ei_tn3270_order_code = EI_INIT;
1608 static expert_field ei_tn3270_command_code = EI_INIT;
1609 static expert_field ei_tn3270_aid = EI_INIT;
1610
1611 static gint dissect_orders_and_data(proto_tree *tn3270_tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, tn3270_conv_info_t *tn3270_info);
1612 static gint dissect_buffer_address(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset, gint hf, tn3270_conv_info_t *tn3270_info);
1613
1614 typedef struct hf_items {
1615   int         *hf_idx_p;
1616   gint        *bitmask_ett_idx_p;
1617   gint         length;
1618   const gint **bitmask;
1619   const gint   encoding;
1620 } hf_items;
1621
1622 /* Utility Functions */
1623
1624 static gint
1625 tn3270_add_hf_items(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
1626                     const hf_items *fields)
1627 {
1628   gint start = offset;
1629   gint i;
1630
1631   for (i = 0; fields[i].hf_idx_p; i++) {
1632     if (fields[i].bitmask == 0) {
1633       proto_tree_add_item(tn3270_tree,
1634                           *fields[i].hf_idx_p,
1635                           tvb, offset,
1636                           fields[i].length,
1637                           fields[i].encoding);
1638     }
1639     else {
1640       proto_tree_add_bitmask(tn3270_tree, tvb, offset, *fields[i].hf_idx_p,
1641                              *fields[i].bitmask_ett_idx_p, fields[i].bitmask, ENC_BIG_ENDIAN);
1642     }
1643     offset += fields[i].length;
1644   }
1645
1646   return (offset - start);
1647 }
1648
1649 /*
1650  * offset;      tvb offset of next byte of data (first byte of unprocessed data);
1651  * start:       tvb offset of beginning of data;
1652  * data_length: total length of data;
1653  */
1654 static gint
1655 dissect_unknown_data(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset, gint start,
1656                      gint data_length)
1657 {
1658   gint len_left;
1659
1660   len_left = (data_length) - (offset - start);
1661
1662   if (len_left > 0) {
1663     proto_tree_add_item(tn3270_tree, hf_tn3270_unknown_data,
1664                         tvb, offset, len_left,
1665                         ENC_NA);
1666     return len_left;
1667   }
1668
1669   return 0;
1670 }
1671
1672 static gint
1673 add_data_until_next_order_code(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
1674 {
1675   gint datalen          = 0;
1676   gint length_remaining = tvb_reported_length_remaining(tvb, offset);
1677
1678   /* XXX: From 4.3:
1679    *  "All order codes have an EBCDIC value in the range of hexadecimal 00
1680    *   (X'00') through hexadecimal 3F (X'3F').  Order codes with values in this
1681    *   range but not defined in this chapter are rejected."
1682    *  However, the code (as originally committed) treats a '0' order code as data.
1683    */
1684
1685   while (datalen < length_remaining) {
1686     guint order_code;
1687     order_code = tvb_get_guint8(tvb, offset + datalen);
1688     if ((order_code > 0) && (order_code <= OC_MAX))
1689       break;
1690     datalen += 1;
1691   }
1692
1693   if (datalen > 0) {
1694     /* XXX: Need to handle "Format Control Orders" ??  */
1695     proto_tree_add_item(tn3270_tree, hf_tn3270_field_data, tvb, offset,
1696                         datalen, ENC_EBCDIC|ENC_NA);
1697   }
1698
1699   return datalen;
1700 }
1701
1702 static gint
1703 dissect_query_reply_resbytes(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
1704                              gint sf_body_length)
1705 {
1706   gint start = offset;
1707
1708   static const hf_items fields[] = {
1709     { &hf_tn3270_res_twobytes, NULL, 2, NULL, ENC_BIG_ENDIAN },
1710     { NULL, NULL, 0, NULL, 0 }
1711   };
1712
1713
1714   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
1715                                 fields);
1716
1717   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
1718
1719   return (offset - start);
1720 }
1721
1722 static gint
1723 dissect_wcc(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
1724 {
1725
1726   static const gint *wcc_fields[] = {
1727     &hf_tn3270_wcc_nop,
1728     &hf_tn3270_wcc_reset,
1729     &hf_tn3270_wcc_printer1,
1730     &hf_tn3270_wcc_printer2,
1731     &hf_tn3270_wcc_start_printer,
1732     &hf_tn3270_wcc_sound_alarm,
1733     &hf_tn3270_wcc_keyboard_restore,
1734     &hf_tn3270_wcc_reset_mdt,
1735     NULL
1736   };
1737
1738   /* Qualifier and DeviceType */
1739   proto_tree_add_bitmask_text(tn3270_tree, tvb, offset, 1, "Write Control Character: ", "None",
1740                               ett_tn3270_wcc, wcc_fields, ENC_BIG_ENDIAN, 0);
1741   return 1;
1742
1743 }
1744
1745 static gint
1746 dissect_3270_field_validation(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
1747 {
1748   gint start = offset;
1749
1750   static const gint *byte[] = {
1751     &hf_tn3270_field_validation_mandatory_fill,
1752     &hf_tn3270_field_validation_mandatory_entry,
1753     &hf_tn3270_field_validation_trigger,
1754     NULL
1755   };
1756
1757   proto_tree_add_bitmask_text(tn3270_tree, tvb, 1, 1, "Field Validation: ",
1758                               "None", ett_tn3270_field_validation, byte, ENC_BIG_ENDIAN, 0);
1759
1760   offset += 1;
1761
1762   return (offset - start);
1763 }
1764
1765
1766 static gint
1767 dissect_3270_field_attribute(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
1768 {
1769   gint start = offset;
1770
1771   static const gint *byte[] = {
1772     &hf_tn3270_fa_graphic_convert,
1773     &hf_tn3270_fa_protected,
1774     &hf_tn3270_fa_numeric,
1775     &hf_tn3270_fa_display,
1776     &hf_tn3270_fa_reserved,
1777     &hf_tn3270_fa_modified,
1778     NULL
1779   };
1780
1781
1782   proto_tree_add_bitmask(tn3270_tree, tvb, offset, hf_tn3270_field_attribute,
1783                          ett_tn3270_field_attribute, byte, ENC_BIG_ENDIAN);
1784
1785   offset += 1;
1786
1787   return (offset - start);
1788 }
1789
1790 /* 8.7 - Copy Control Code */
1791 static gint
1792 dissect_ccc(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
1793 {
1794   gint start = offset;
1795
1796   static const gint *byte[] = {
1797     &hf_tn3270_ccc_coding,
1798     &hf_tn3270_ccc_printout,
1799     &hf_tn3270_ccc_start_print,
1800     &hf_tn3270_ccc_sound_alarm,
1801     &hf_tn3270_ccc_copytype,
1802     NULL
1803   };
1804
1805   proto_tree_add_bitmask(tn3270_tree, tvb, offset, hf_tn3270_ccc,
1806                          ett_tn3270_ccc, byte, ENC_BIG_ENDIAN);
1807
1808   offset += 1;
1809
1810   return (offset - start);
1811 }
1812
1813 /* End - Utility Functions */
1814
1815 /* Start: Handle Structured Fields */
1816
1817 /* --------------------------------------------------- */
1818 /* 5.0 Outbound/Inbound and Outbound Structured Fields */
1819 /* --------------------------------------------------- */
1820
1821 /* 5.5 Activate Partition - Search for ACTIVATE_PARTITION */
1822 /* 5.6 Begin/End of File - Search for BEGIN_OR_END_OF_FILE */
1823 /* 5.7 Create Partition */
1824 static gint
1825 dissect_create_partition(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset, gint sf_body_length)
1826 {
1827   gint start = offset;
1828
1829   static const hf_items fields[] = {
1830     { &hf_tn3270_partition_id,     NULL, 1, NULL, ENC_BIG_ENDIAN },
1831     { &hf_tn3270_partition_uom,    NULL, 1, NULL, ENC_BIG_ENDIAN },
1832     { &hf_tn3270_partition_flags,  NULL, 1, NULL, ENC_BIG_ENDIAN },
1833     { &hf_tn3270_partition_height, NULL, 2, NULL, ENC_BIG_ENDIAN },
1834     { &hf_tn3270_partition_width,  NULL, 2, NULL, ENC_BIG_ENDIAN },
1835     { &hf_tn3270_partition_rv,     NULL, 2, NULL, ENC_BIG_ENDIAN },
1836     { &hf_tn3270_partition_cv,     NULL, 2, NULL, ENC_BIG_ENDIAN },
1837     { &hf_tn3270_partition_hv,     NULL, 2, NULL, ENC_BIG_ENDIAN },
1838     { &hf_tn3270_partition_wv,     NULL, 2, NULL, ENC_BIG_ENDIAN },
1839     { &hf_tn3270_partition_rw,     NULL, 2, NULL, ENC_BIG_ENDIAN },
1840     { &hf_tn3270_partition_cw,     NULL, 2, NULL, ENC_BIG_ENDIAN },
1841     { &hf_tn3270_partition_rs,     NULL, 2, NULL, ENC_BIG_ENDIAN },
1842     { &hf_tn3270_partition_res,    NULL, 2, NULL, ENC_BIG_ENDIAN },
1843     { &hf_tn3270_partition_pw,     NULL, 2, NULL, ENC_BIG_ENDIAN },
1844     { &hf_tn3270_partition_ph,     NULL, 2, NULL, ENC_BIG_ENDIAN },
1845     { NULL, NULL, 0, NULL, 0 }
1846   };
1847
1848
1849   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
1850                                 fields);
1851
1852   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
1853
1854   return (offset - start);
1855 }
1856
1857 /* 5.7 Create Partition  - Search for CREATE_PARTITION */
1858 /* 5.8 Destroy Partition - Search for DESTROY_PARTITION */
1859 /* 5.9 Erase/Reset       - Search for ERASE_OR_RESET */
1860 /* 5.10 Load Color Table - Search for LOAD_COLOR_TABLE */
1861
1862 /* 5.11 Load Format Storage */
1863 static gint
1864 dissect_load_format_storage(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset, gint sf_body_length)
1865 {
1866   gint start = offset;
1867   gint operand;
1868
1869   static const hf_items fields[] = {
1870     { &hf_tn3270_load_format_storage_flags1,    NULL,  1, NULL, ENC_BIG_ENDIAN },
1871     { &hf_tn3270_load_format_storage_flags2,    NULL,  1, NULL, ENC_BIG_ENDIAN },
1872     { &hf_tn3270_load_format_storage_operand,   NULL,  1, NULL, ENC_BIG_ENDIAN },
1873     { &hf_tn3270_load_format_storage_localname, NULL,  8, NULL, ENC_EBCDIC|ENC_NA },
1874     { &hf_tn3270_format_group,                  NULL,  6, NULL, ENC_EBCDIC|ENC_NA },
1875     { &hf_tn3270_format_name,                   NULL, 16, NULL, ENC_EBCDIC|ENC_NA },
1876     { NULL, NULL, 0, NULL, 0 }
1877   };
1878
1879   operand = tvb_get_guint8(tvb, offset+2);
1880
1881   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
1882                                 fields);
1883
1884   if (operand == LOAD_FORMAT_STORAGE_OPERAND_ADD) {
1885     gint fmtln = sf_body_length - (offset - start);
1886     proto_tree_add_item(tn3270_tree, hf_tn3270_load_format_storage_format_data,
1887                         tvb, offset, fmtln, ENC_EBCDIC|ENC_NA);
1888     offset += fmtln;
1889   }
1890
1891   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
1892
1893   return (offset - start);
1894 }
1895
1896 /* 5.12 Load Line Type - Search for LOAD_LINE_TYPE */
1897
1898 /* 5.13 Load Programmed Symbols (Load PS) */
1899 static gint
1900 dissect_load_programmed_symbols(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset, gint sf_body_length)
1901 {
1902   gint  start = offset, i;
1903   gint8 flags;
1904   gint8 extended_ps_length;
1905
1906   static const hf_items ps_fields[] = {
1907     { &hf_tn3270_ps_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
1908     { &hf_tn3270_ps_lcid,  NULL, 1, NULL, ENC_BIG_ENDIAN },
1909     { &hf_tn3270_ps_char,  NULL, 1, NULL, ENC_BIG_ENDIAN },
1910     { &hf_tn3270_ps_rws,   NULL, 1, NULL, ENC_BIG_ENDIAN },
1911     { NULL, NULL, 0, NULL, 0 }
1912   };
1913
1914   static const hf_items extended_ps_fields[] = {
1915     { &hf_tn3270_extended_ps_lw,     NULL, 1, NULL, ENC_BIG_ENDIAN },
1916     { &hf_tn3270_extended_ps_lh,     NULL, 1, NULL, ENC_BIG_ENDIAN },
1917     { &hf_tn3270_extended_ps_subsn,  NULL, 1, NULL, ENC_BIG_ENDIAN },
1918     { &hf_tn3270_extended_ps_color,  NULL, 1, NULL, ENC_BIG_ENDIAN },
1919     { &hf_tn3270_extended_ps_stsubs, NULL, 1, NULL, ENC_BIG_ENDIAN },
1920     { &hf_tn3270_extended_ps_echar,  NULL, 1, NULL, ENC_BIG_ENDIAN },
1921     { &hf_tn3270_extended_ps_nw,     NULL, 1, NULL, ENC_BIG_ENDIAN },
1922     { &hf_tn3270_extended_ps_nh,     NULL, 1, NULL, ENC_BIG_ENDIAN },
1923     { &hf_tn3270_extended_ps_res,    NULL, 1, NULL, ENC_BIG_ENDIAN },
1924     { NULL, NULL, 0, NULL, 0 }
1925   };
1926
1927   flags   = tvb_get_guint8(tvb, offset);
1928   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
1929                                 ps_fields);
1930
1931   /*If extended flag not set return */
1932   if (!(flags & 0x80)) {
1933     return (offset - start);
1934   }
1935
1936   extended_ps_length = tvb_get_guint8(tvb, offset);
1937   proto_tree_add_item(tn3270_tree, hf_tn3270_extended_ps_length,
1938                       tvb, offset, 1, ENC_BIG_ENDIAN);
1939   offset += 1;
1940   proto_tree_add_item(tn3270_tree, hf_tn3270_extended_ps_flags,
1941                       tvb, offset, 1, ENC_BIG_ENDIAN);
1942   offset += 1;
1943
1944   for (i = 0; i < extended_ps_length; ++i) {
1945     if (extended_ps_fields[i].hf_idx_p == NULL) {
1946       break;  /* Malformed (Bad value for extended_ps_length) ! ToDo: 'expert' */
1947     }
1948     proto_tree_add_item(tn3270_tree, *extended_ps_fields[i].hf_idx_p,
1949                         tvb, offset, extended_ps_fields[i].length,
1950                         extended_ps_fields[i].encoding);
1951     offset += extended_ps_fields[i].length;
1952   }
1953
1954
1955   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
1956
1957   return (offset - start);
1958 }
1959
1960 /* 5.14 Modify Partition) */
1961 static gint
1962 dissect_modify_partition(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset, gint sf_body_length)
1963 {
1964   gint start = offset;
1965
1966   static const hf_items fields[] = {
1967     { &hf_tn3270_resbyte,         NULL, 1, NULL, ENC_BIG_ENDIAN },
1968     { &hf_tn3270_partition_id,    NULL, 1, NULL, ENC_BIG_ENDIAN },
1969     { &hf_tn3270_resbyte,         NULL, 1, NULL, ENC_BIG_ENDIAN },
1970     { &hf_tn3270_partition_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
1971     { &hf_tn3270_resbyte,         NULL, 1, NULL, ENC_BIG_ENDIAN },
1972     { &hf_tn3270_resbytes,        NULL, 2, NULL, ENC_BIG_ENDIAN },
1973     { &hf_tn3270_partition_rv,    NULL, 2, NULL, ENC_BIG_ENDIAN },
1974     { &hf_tn3270_partition_cv,    NULL, 2, NULL, ENC_BIG_ENDIAN },
1975     { &hf_tn3270_partition_hv,    NULL, 2, NULL, ENC_BIG_ENDIAN },
1976     { &hf_tn3270_partition_wv,    NULL, 2, NULL, ENC_BIG_ENDIAN },
1977     { &hf_tn3270_partition_rw,    NULL, 2, NULL, ENC_BIG_ENDIAN },
1978     { &hf_tn3270_partition_cw,    NULL, 2, NULL, ENC_BIG_ENDIAN },
1979     { &hf_tn3270_partition_rs,    NULL, 2, NULL, ENC_BIG_ENDIAN },
1980     { &hf_tn3270_partition_res,   NULL, 2, NULL, ENC_BIG_ENDIAN },
1981     { &hf_tn3270_partition_pw,    NULL, 2, NULL, ENC_BIG_ENDIAN },
1982     { &hf_tn3270_partition_ph,    NULL, 2, NULL, ENC_BIG_ENDIAN },
1983     { NULL, NULL, 0, NULL, 0 }
1984   };
1985
1986
1987   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
1988                                 fields);
1989
1990   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
1991
1992   return (offset - start);
1993 }
1994
1995 /* 5.15 Outbound Text Header */
1996 static gint
1997 dissect_outbound_text_header(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
1998                              gint sf_body_length)
1999 {
2000   gint   start = offset;
2001   gint16 hdr_length;
2002
2003   static const hf_items outbound_text_header_fields1[] = {
2004     { &hf_tn3270_partition_id,                        NULL, 1, NULL, ENC_BIG_ENDIAN },
2005     { &hf_tn3270_outbound_text_header_operation_type, NULL, 1, NULL, ENC_BIG_ENDIAN },
2006     { NULL, NULL, 0, NULL, 0 }
2007   };
2008
2009   static const hf_items outbound_text_header_fields2[] = {
2010     { &hf_tn3270_resbyte, NULL, 1, NULL, ENC_BIG_ENDIAN },
2011     { &hf_tn3270_resbyte, NULL, 1, NULL, ENC_BIG_ENDIAN },
2012     { &hf_tn3270_lvl,     NULL, 1, NULL, ENC_BIG_ENDIAN },
2013     { &hf_tn3270_cro,     NULL, 2, NULL, ENC_BIG_ENDIAN },
2014     { &hf_tn3270_cc,      NULL, 2, NULL, ENC_BIG_ENDIAN },
2015     { NULL, NULL, 0, NULL, 0 }
2016   };
2017
2018   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2019                                 outbound_text_header_fields1);
2020   offset += dissect_wcc(tn3270_tree, tvb, offset);
2021   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2022                                 outbound_text_header_fields2);
2023
2024   hdr_length = tvb_get_ntohs(tvb, offset);
2025
2026   proto_tree_add_item(tn3270_tree, hf_tn3270_outbound_text_header_lhdr,
2027                       tvb, offset, 2, ENC_BIG_ENDIAN);
2028   offset += 2;
2029
2030   proto_tree_add_item(tn3270_tree, hf_tn3270_outbound_text_header_hdr,
2031                       tvb, offset, hdr_length, ENC_NA);
2032   offset += hdr_length;
2033
2034   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
2035
2036   return (offset - start);
2037 }
2038
2039 /* 5.16 Outbound 3270DS */
2040 static gint
2041 dissect_outbound_3270ds(proto_tree *tn3270_tree, packet_info *pinfo, tvbuff_t *tvb, gint offset,
2042                         tn3270_conv_info_t *tn3270_info, gint sf_body_length )
2043 {
2044   gint start = offset;
2045   gint cmd;
2046
2047   proto_tree_add_item(tn3270_tree,
2048                       hf_tn3270_partition_id,
2049                       tvb, offset,
2050                       1,
2051                       ENC_BIG_ENDIAN);
2052   offset += 1;
2053
2054   cmd = tvb_get_guint8(tvb, offset);
2055   proto_tree_add_item(tn3270_tree,
2056                       hf_tn3270_partition_command,
2057                       tvb, offset,
2058                       1,
2059                       ENC_BIG_ENDIAN);
2060   offset += 1;
2061
2062   switch (cmd) {
2063     case CC_SNA_BSC:
2064       /* FIXME: the spec is ambiguous at best about what to expect here,
2065          need a live sample to validate. */
2066       offset += dissect_ccc(tn3270_tree, tvb, offset);
2067       proto_tree_add_item(tn3270_tree,
2068                           hf_tn3270_bsc,
2069                           tvb, offset,
2070                           2,
2071                           ENC_BIG_ENDIAN);
2072       offset += 2;
2073       break;
2074       /* XXX: are "local" commands valid for Outbound 3270DS ? */
2075     case CC_LCL_W:
2076     case CC_LCL_EW:
2077     case CC_LCL_EWA:
2078     case CC_LCL_EAU:
2079     case CC_RMT_W:
2080     case CC_RMT_EW:
2081     case CC_RMT_EWA:
2082     case CC_RMT_EAU:
2083       /* WCC */
2084       if ((offset - start) < sf_body_length)
2085         offset += dissect_wcc(tn3270_tree, tvb, offset);
2086       if ((offset - start) < sf_body_length)
2087         offset += dissect_orders_and_data(tn3270_tree, pinfo, tvb, offset, tn3270_info);
2088       break;
2089     default:
2090       break;
2091   }
2092
2093   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
2094
2095   return (offset - start);
2096 }
2097
2098 /* 5.17 Present Absolute Format */
2099 static gint
2100 dissect_present_absolute_format(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2101                                 gint sf_body_length)
2102 {
2103   gint start = offset;
2104
2105   proto_tree_add_item(tn3270_tree,
2106                       hf_tn3270_partition_id,
2107                       tvb, offset,
2108                       1,
2109                       ENC_BIG_ENDIAN);
2110   offset += 1;
2111
2112   proto_tree_add_item(tn3270_tree,
2113                       hf_tn3270_fpc,
2114                       tvb, offset,
2115                       1,
2116                       ENC_BIG_ENDIAN);
2117   offset += 1;
2118
2119   offset += dissect_wcc(tn3270_tree, tvb, offset);
2120
2121   proto_tree_add_item(tn3270_tree,
2122                       hf_tn3270_format_name,
2123                       tvb, offset,
2124                       sf_body_length - (offset - start),
2125                       ENC_EBCDIC|ENC_NA);
2126   offset += (sf_body_length - (offset - start));
2127
2128   return (offset - start);
2129 }
2130
2131 /* 5.18 Present Relative Format */
2132 static gint
2133 dissect_present_relative_format(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2134                                 gint sf_body_length)
2135 {
2136   gint start = offset;
2137
2138   proto_tree_add_item(tn3270_tree,
2139                       hf_tn3270_partition_id,
2140                       tvb, offset,
2141                       1,
2142                       ENC_BIG_ENDIAN);
2143   offset += 1;
2144
2145   proto_tree_add_item(tn3270_tree,
2146                       hf_tn3270_fov,
2147                       tvb, offset,
2148                       2,
2149                       ENC_BIG_ENDIAN);
2150   offset += 2;
2151
2152   proto_tree_add_item(tn3270_tree,
2153                       hf_tn3270_fpc,
2154                       tvb, offset,
2155                       1,
2156                       ENC_BIG_ENDIAN);
2157   offset += 1;
2158
2159   offset += dissect_wcc(tn3270_tree, tvb, offset);
2160
2161   proto_tree_add_item(tn3270_tree,
2162                       hf_tn3270_format_name,
2163                       tvb, offset,
2164                       sf_body_length - (offset - start),
2165                       ENC_EBCDIC|ENC_NA);
2166   offset += (sf_body_length - (offset - start));
2167
2168   return (offset - start);
2169 }
2170
2171 /* 5.19 Read Partition */
2172 static gint
2173 dissect_read_partition(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2174                        gint sf_body_length)
2175 {
2176   gint        start = offset;
2177   gint        type;
2178   proto_tree *query_list_tree;
2179   gint        qcode_list_len, i;
2180
2181   proto_tree_add_item(tn3270_tree,
2182                       hf_tn3270_partition_id,
2183                       tvb, offset,
2184                       1,
2185                       ENC_BIG_ENDIAN);
2186   offset += 1;
2187
2188   type = tvb_get_guint8(tvb, offset);
2189   if (type == 0xFF) { /* Partition ID of 0xFF is escaped with another 0xFF */
2190                       /* XXX: removing tn3270 IAX escapes should be handled in the telnet dissector ! */
2191     offset += 1;
2192     type = tvb_get_guint8(tvb, offset);
2193   }
2194
2195   proto_tree_add_item(tn3270_tree,
2196                       hf_tn3270_read_partition_operation_type,
2197                       tvb, offset,
2198                       1,
2199                       ENC_BIG_ENDIAN);
2200   offset += 1;
2201
2202   if (type == READ_PARTITION_OPTYPE_QUERY_LIST) { /* 'Query List' */
2203     proto_tree_add_item(tn3270_tree,
2204                         hf_tn3270_read_partition_reqtyp,
2205                         tvb, offset,
2206                         1,
2207                         ENC_BIG_ENDIAN);
2208     offset += 1;
2209
2210     if (sf_body_length > (offset - start)) {
2211       qcode_list_len = sf_body_length - (offset - start);
2212       query_list_tree = proto_tree_add_subtree(tn3270_tree, tvb, offset, qcode_list_len,
2213                                ett_tn3270_query_list, NULL, "Query List");
2214       for (i = 0; i < qcode_list_len; i++) {
2215         proto_tree_add_item(query_list_tree,
2216                             hf_tn3270_sf_query_reply,
2217                             tvb, offset, 1, ENC_BIG_ENDIAN);
2218         offset += 1;
2219       }
2220     }
2221   }
2222
2223   return (offset - start);
2224 }
2225
2226 /*5.20 Request Recovery Data - Search for REQUEST_RECOVERY_DATA*/
2227 /*5.21 Reset Partition - Search for RESET_PARTITION */
2228
2229 /*5.22 Restart */
2230 static gint
2231 dissect_restart(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2232                 gint sf_body_length)
2233 {
2234   gint start = offset;
2235
2236   proto_tree_add_item(tn3270_tree,
2237                       hf_tn3270_resbyte,
2238                       tvb, offset,
2239                       1,
2240                       ENC_BIG_ENDIAN);
2241   offset += 1;
2242
2243   proto_tree_add_item(tn3270_tree,
2244                       hf_tn3270_start_page,
2245                       tvb, offset,
2246                       2,
2247                       ENC_BIG_ENDIAN);
2248   offset += 2;
2249
2250   proto_tree_add_item(tn3270_tree,
2251                       hf_tn3270_start_line,
2252                       tvb, offset,
2253                       2,
2254                       ENC_BIG_ENDIAN);
2255   offset += 2;
2256
2257
2258   proto_tree_add_item(tn3270_tree,
2259                       hf_tn3270_scs_data,
2260                       tvb, offset,
2261                       sf_body_length - (offset - start),
2262                       ENC_NA);
2263   offset += (sf_body_length - (offset - start));
2264
2265   return (offset - start);
2266 }
2267
2268 /* 5.23 SCS Data     - Search for SCS_DATA */
2269 /* 5.24 Color Table  - Search for COLOR_TABLE */
2270 /* 5.25 Format Group - Search for FORMAT_GROUP */
2271 /* 5.26 Set Checkpoint Interval - Search for CHECKPOINT_INTERVAL */
2272
2273 /* 5.27 Set MSR Control */
2274 static gint
2275 dissect_set_msr_control(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2276                         gint sf_body_length)
2277 {
2278   gint start = offset;
2279
2280   static const gint *byte[] = {
2281     &hf_tn3270_msr_user,
2282     &hf_tn3270_msr_locked,
2283     &hf_tn3270_msr_auto,
2284     &hf_tn3270_msr_ind1,
2285     &hf_tn3270_msr_ind2,
2286     NULL
2287   };
2288
2289   static const hf_items outbound_text_header_fields[] = {
2290     { &hf_tn3270_partition_id,    NULL, 1, NULL, ENC_BIG_ENDIAN },
2291     { &hf_tn3270_msr_type,        NULL, 1, NULL, ENC_BIG_ENDIAN },
2292     { &hf_tn3270_msr_state_mask, &ett_tn3270_msr_state_mask, 1, byte, 0 },
2293     { &hf_tn3270_msr_state_value, NULL, 1, NULL, ENC_BIG_ENDIAN },
2294     { &hf_tn3270_msr_ind_mask,    NULL, 1, NULL, ENC_BIG_ENDIAN },
2295     { &hf_tn3270_msr_ind_value,   NULL, 1, NULL, ENC_BIG_ENDIAN },
2296     { NULL, NULL, 0, NULL, 0 }
2297   };
2298
2299
2300   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2301                                 outbound_text_header_fields);
2302
2303   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
2304
2305   return (offset - start);
2306 }
2307
2308 /* 5.28 Set Partition Characteristics */
2309 static gint
2310 dissect_set_partition_characteristics_sd_parms(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
2311 {
2312
2313   gint    start = offset;
2314   guint16 sdp;
2315
2316   static const hf_items sdp1[] = {
2317     { &hf_tn3270_sdp_ln,     NULL, 1, NULL, ENC_BIG_ENDIAN },
2318     { &hf_tn3270_sdp_id,     NULL, 1, NULL, ENC_BIG_ENDIAN },
2319     { &hf_tn3270_spc_sdp_ot, NULL, 1, NULL, ENC_BIG_ENDIAN },
2320     { &hf_tn3270_spc_sdp_ob, NULL, 1, NULL, ENC_BIG_ENDIAN },
2321     { &hf_tn3270_spc_sdp_ol, NULL, 1, NULL, ENC_BIG_ENDIAN },
2322     { &hf_tn3270_spc_sdp_or, NULL, 1, NULL, ENC_BIG_ENDIAN },
2323     { NULL, NULL, 0, NULL, 0 }
2324   };
2325
2326   static const hf_items sdp2[] = {
2327     { &hf_tn3270_sdp_ln,           NULL, 1, NULL, ENC_BIG_ENDIAN },
2328     { &hf_tn3270_sdp_id,           NULL, 1, NULL, ENC_BIG_ENDIAN },
2329     { &hf_tn3270_spc_sdp_eucflags, NULL, 1, NULL, ENC_BIG_ENDIAN },
2330     { NULL, NULL, 0, NULL, 0 }
2331   };
2332
2333   static const hf_items sdp3[] = {
2334     { &hf_tn3270_sdp_ln,           NULL, 1, NULL, ENC_BIG_ENDIAN },
2335     { &hf_tn3270_sdp_id,           NULL, 1, NULL, ENC_BIG_ENDIAN },
2336     { &hf_tn3270_spc_sdp_eucflags, NULL, 1, NULL, ENC_BIG_ENDIAN },
2337     { &hf_tn3270_spc_sdp_eucflags, NULL, 1, NULL, ENC_BIG_ENDIAN },
2338     { NULL, NULL, 0, NULL, 0 }
2339   };
2340
2341
2342   sdp = tvb_get_ntohs(tvb, offset);
2343
2344   switch (sdp) {
2345     case 0x0601: /*View Outport*/
2346       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2347                                     sdp1);
2348       break;
2349     case 0x0304: /*Enable User Call Up*/
2350       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2351                                     sdp2);
2352       break;
2353     case 0x0405: /*Select Base Character Set*/
2354       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2355                                     sdp3);
2356       break;
2357     default:
2358       return 0;
2359   }
2360
2361   return (offset - start);
2362
2363 }
2364
2365 static gint
2366 dissect_set_partition_characteristics(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2367                                       gint sf_body_length)
2368 {
2369
2370   gint start = offset;
2371   gint i;
2372
2373   static const hf_items fields[] = {
2374     { &hf_tn3270_partition_id, NULL, 1, NULL, ENC_BIG_ENDIAN },
2375     { &hf_tn3270_resbytes,     NULL, 2, NULL, ENC_BIG_ENDIAN },
2376     { NULL, NULL, 0, NULL, 0 }
2377   };
2378
2379
2380   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2381                                 fields);
2382
2383   for (i = 0; i < 3; i++) {
2384     offset += dissect_set_partition_characteristics_sd_parms(tn3270_tree, tvb, offset);
2385     if (tvb_reported_length_remaining(tvb, offset) <= 0)
2386       break;
2387   }
2388
2389   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
2390
2391   return (offset - start);
2392 }
2393
2394 /* 5.29 Set Printer Characteristics */
2395 static gint
2396 dissect_set_printer_characteristics_sd_parms(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
2397 {
2398
2399   gint    start = offset;
2400   guint16 sdp;
2401
2402   static const hf_items sdp1[] = {
2403     { &hf_tn3270_sdp_ln,        NULL, 1, NULL, ENC_BIG_ENDIAN },
2404     { &hf_tn3270_sdp_id,        NULL, 1, NULL, ENC_BIG_ENDIAN },
2405     { &hf_tn3270_spc_sdp_srepc, NULL, 1, NULL, ENC_BIG_ENDIAN },
2406     { NULL, NULL, 0, NULL, 0 }
2407   };
2408
2409   sdp = tvb_get_ntohs(tvb, offset);
2410
2411   switch (sdp) {
2412     case 0x0301: /*Early Print Complete*/
2413       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2414                                     sdp1);
2415       break;
2416     default:
2417       return 0;
2418   }
2419
2420   return (offset - start);
2421
2422 }
2423
2424 static gint
2425 dissect_set_printer_characteristics(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2426                                     gint sf_body_length)
2427 {
2428
2429   gint start = offset;
2430   gint i;
2431
2432   static const hf_items fields[] = {
2433     { &hf_tn3270_printer_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
2434     { &hf_tn3270_resbyte,       NULL, 1, NULL, ENC_BIG_ENDIAN },
2435     { NULL, NULL, 0, NULL, 0 }
2436   };
2437
2438   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2439                                 fields);
2440
2441   for (i = 0; i < 3; i++) {
2442     offset += dissect_set_printer_characteristics_sd_parms(tn3270_tree, tvb, offset);
2443     if (tvb_reported_length_remaining(tvb, offset) <= 0)
2444       break;
2445   }
2446
2447   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
2448
2449   return (offset - start);
2450 }
2451
2452
2453 /* 5.30 Set Reply Mode */
2454 static gint
2455 dissect_set_reply_mode(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2456                        gint sf_body_length)
2457 {
2458   gint start = offset;
2459   gint type;
2460   gint i;
2461
2462   static const hf_items fields[] = {
2463     { &hf_tn3270_partition_id, NULL, 1, NULL, ENC_BIG_ENDIAN },
2464     { &hf_tn3270_mode,         NULL, 1, NULL, ENC_BIG_ENDIAN },
2465     { NULL, NULL, 0, NULL, 0 }
2466   };
2467
2468   type = tvb_get_guint8(tvb, offset+1);
2469
2470   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2471                                 fields);
2472
2473   if (type == 0x02) { /* 'Query List' */
2474     for (i = 0; i < (sf_body_length-(offset-start)); i++) {
2475       proto_tree_add_item(tn3270_tree,
2476                           hf_tn3270_reply_mode_attr_list,
2477                           tvb, offset, 1, ENC_BIG_ENDIAN);
2478       offset += 1;
2479     }
2480   }
2481
2482   return (offset - start);
2483 }
2484
2485 /* 5.31 Set Window Origin - Search for SET_WINDOW_ORIGIN */
2486 /* 6.6 Type 1 Text Inbound
2487    5.32 Type 1 Text Outbound */
2488 static gint
2489 dissect_type_1_text(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2490                     gint sf_body_length)
2491 {
2492   gint start = offset;
2493
2494   static const hf_items fields[] = {
2495     { &hf_tn3270_partition_id, NULL, 1, NULL, ENC_BIG_ENDIAN },
2496     { &hf_tn3270_resbytes,     NULL, 2, NULL, ENC_BIG_ENDIAN },
2497     { NULL, NULL, 0, NULL, 0 }
2498   };
2499
2500   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2501                                 fields);
2502   proto_tree_add_item(tn3270_tree,
2503                       hf_tn3270_field_data,
2504                       tvb, offset,
2505                       sf_body_length - (offset - start),
2506                       ENC_EBCDIC|ENC_NA);
2507   offset += (sf_body_length - (offset - start));
2508
2509   return (offset - start);
2510 }
2511
2512 /* 5.34 Data Chain */
2513 static guint
2514 dissect_data_chain(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2515                        gint sf_body_length)
2516 {
2517   gint start = offset;
2518
2519   static const gint *byte[] = {
2520     &hf_tn3270_data_chain_group,
2521     &hf_tn3270_data_chain_inbound_control,
2522     NULL
2523   };
2524
2525   static const hf_items data_chain_fields[] = {
2526     { &hf_tn3270_data_chain_fields, &ett_tn3270_data_chain_fields, 1, byte, 0 },
2527     { &hf_tn3270_resbyte, NULL, 1, NULL, ENC_BIG_ENDIAN },
2528     { NULL, NULL, 0, NULL, 0 }
2529   };
2530
2531   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2532                                 data_chain_fields);
2533
2534   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
2535
2536   return (offset - start);
2537 }
2538
2539 /* 5.35 Destination/Origin -  Search for DESTINATION_OR_ORIGIN*/
2540
2541 /* 5.36 Object Control */
2542 static gint
2543 dissect_object_control(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2544                        gint sf_body_length)
2545 {
2546   gint start = offset;
2547
2548   static const hf_items fields[] = {
2549     { &hf_tn3270_partition_id,         NULL, 1, NULL, ENC_BIG_ENDIAN },
2550     { &hf_tn3270_object_control_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
2551     { &hf_tn3270_object_type,          NULL, 1, NULL, ENC_BIG_ENDIAN },
2552     { NULL, NULL, 0, NULL, 0 }
2553   };
2554
2555   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2556                                 fields);
2557
2558   proto_tree_add_item(tn3270_tree,
2559                       hf_tn3270_type_1_text_outbound_data,
2560                       tvb, offset,
2561                       sf_body_length - (offset - start),
2562                       ENC_NA);
2563   offset += (sf_body_length - (offset - start));
2564
2565   return (offset - start);
2566 }
2567
2568 /* 5.37 Object Data - Search for OBJECT_DATA*/
2569 /* 5.38 Object Picture - Search for OBJECT_PICTURE */
2570 /* 5.39 OEM Data - Search for OEM_DATA */
2571
2572 /* 5.40 Save/Restore Format */
2573 static gint
2574 dissect_save_or_restore_format(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2575                                gint sf_body_length)
2576 {
2577   gint start = offset;
2578
2579   hf_items fields[] = {
2580     { &hf_tn3270_save_or_restore_format_flags, NULL, 1,                NULL, ENC_BIG_ENDIAN },
2581     { &hf_tn3270_srf_fpcb,                     NULL, sf_body_length-1, NULL, ENC_NA },
2582     { NULL, NULL, 0, NULL, 0 }
2583   };
2584
2585   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2586                                 fields);
2587
2588   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
2589
2590   return (offset - start);
2591 }
2592
2593 /* 5.41 Select Intelligent Printer Data Stream (IPDS) Mode -  Search for SELECT_IPDS_MODE*/
2594
2595 /* -----------------------------------------*/
2596 /* 6.0 CHAPTER 6. INBOUND STRUCTURED FIELDS */
2597 /* -----------------------------------------*/
2598
2599 /* 6.2 Exception/Status */
2600 static gint
2601 dissect_exception_or_status_sd_parms(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
2602 {
2603
2604   gint    start = offset;
2605   guint16 sdp;
2606
2607   static const hf_items sdp1[] = {
2608     { &hf_tn3270_sdp_ln,     NULL, 1, NULL, ENC_BIG_ENDIAN },
2609     { &hf_tn3270_sdp_id,     NULL, 1, NULL, ENC_BIG_ENDIAN },
2610     { &hf_tn3270_resbyte,    NULL, 1, NULL, ENC_BIG_ENDIAN },
2611     { &hf_tn3270_sdp_excode, NULL, 2, NULL, ENC_BIG_ENDIAN },
2612     { NULL, NULL, 0, NULL, 0 }
2613   };
2614
2615   static const hf_items sdp2[] = {
2616     { &hf_tn3270_sdp_ln,       NULL, 1, NULL, ENC_BIG_ENDIAN },
2617     { &hf_tn3270_sdp_id,       NULL, 1, NULL, ENC_BIG_ENDIAN },
2618     { &hf_tn3270_sdp_statcode, NULL, 2, NULL, ENC_BIG_ENDIAN },
2619     { NULL, NULL, 0, NULL, 0 }
2620   };
2621
2622   static const hf_items sdp3[] = {
2623     { &hf_tn3270_sdp_ln,       NULL,  1, NULL, ENC_BIG_ENDIAN },
2624     { &hf_tn3270_sdp_id,       NULL,  1, NULL, ENC_BIG_ENDIAN },
2625     { &hf_tn3270_format_group, NULL, 16, NULL, ENC_EBCDIC|ENC_NA },
2626     { &hf_tn3270_format_name,  NULL, 16, NULL, ENC_EBCDIC|ENC_NA },
2627     { NULL, NULL, 0, NULL, 0 }
2628   };
2629
2630   static const hf_items sdp4[] = {
2631     { &hf_tn3270_sdp_ln,   NULL, 1, NULL, ENC_BIG_ENDIAN },
2632     { &hf_tn3270_sdp_id,   NULL, 1, NULL, ENC_BIG_ENDIAN },
2633     { &hf_tn3270_sdp_ngl,  NULL, 2, NULL, ENC_BIG_ENDIAN },
2634     { &hf_tn3270_sdp_nml,  NULL, 2, NULL, ENC_BIG_ENDIAN },
2635     { &hf_tn3270_sdp_nlml, NULL, 2, NULL, ENC_BIG_ENDIAN },
2636     { &hf_tn3270_sdp_stor, NULL, 4, NULL, ENC_BIG_ENDIAN },
2637     { NULL, NULL, 0, NULL, 0 }
2638   };
2639
2640   static const hf_items sdp5[] = {
2641     { &hf_tn3270_sdp_ln,       NULL,  1, NULL, ENC_BIG_ENDIAN },
2642     { &hf_tn3270_sdp_id,       NULL,  1, NULL, ENC_BIG_ENDIAN },
2643     { &hf_tn3270_format_group, NULL, 16, NULL, ENC_EBCDIC|ENC_NA },
2644     { &hf_tn3270_sdp_nml,      NULL,  2, NULL, ENC_BIG_ENDIAN },
2645     { NULL, NULL, 0, NULL, 0 }
2646   };
2647
2648   sdp = tvb_get_ntohs(tvb, offset);
2649
2650   switch (sdp) {
2651     case 0x0601: /*Auxiliary Device Exception*/
2652       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2653                                     sdp1);
2654       break;
2655     case 0x0402: /*Auxiliary Device status*/
2656       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2657                                     sdp2);
2658       break;
2659     case 0x2203: /*Failing Format status*/
2660       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2661                                     sdp3);
2662       break;
2663     case 0x0C04: /*Format status*/
2664       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2665                                     sdp4);
2666       break;
2667     case 0x1405: /*Group status*/
2668       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2669                                     sdp5);
2670       break;
2671     default:
2672       return 0;
2673   }
2674
2675   return (offset - start);
2676
2677 }
2678
2679 static gint
2680 dissect_exception_or_status(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2681                             gint sf_body_length)
2682 {
2683   gint start = offset, i;
2684
2685   static const hf_items fields[] = {
2686     { &hf_tn3270_partition_id,              NULL, 1, NULL, ENC_BIG_ENDIAN },
2687     { &hf_tn3270_exception_or_status_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
2688     { &hf_tn3270_resbyte,                   NULL, 1, NULL, ENC_BIG_ENDIAN },
2689     { NULL, NULL, 0, NULL, 0 }
2690   };
2691
2692   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2693                                 fields);
2694
2695   for (i = 0; i < 5; i++) {
2696     offset += dissect_exception_or_status_sd_parms(tn3270_tree, tvb, offset);
2697     if (tvb_reported_length_remaining(tvb, offset) <= 0)
2698       break;
2699   }
2700
2701   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
2702
2703   return (offset - start);
2704 }
2705
2706 /* 6.3 Inbound Text Header */
2707 static gint
2708 dissect_inbound_text_header(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2709                             gint sf_body_length)
2710 {
2711   gint start = offset;
2712
2713   static const hf_items outbound_text_header_fields[] = {
2714     { &hf_tn3270_partition_id, NULL, 1, NULL, ENC_BIG_ENDIAN },
2715     { &hf_tn3270_aid,          NULL, 1, NULL, ENC_BIG_ENDIAN },
2716     { &hf_tn3270_resbyte,      NULL, 1, NULL, ENC_BIG_ENDIAN },
2717     { &hf_tn3270_resbyte,      NULL, 1, NULL, ENC_BIG_ENDIAN },
2718     { &hf_tn3270_resbyte,      NULL, 1, NULL, ENC_BIG_ENDIAN },
2719     { &hf_tn3270_lvl,          NULL, 1, NULL, ENC_BIG_ENDIAN },
2720     { &hf_tn3270_cro,          NULL, 2, NULL, ENC_BIG_ENDIAN },
2721     { &hf_tn3270_cc,           NULL, 2, NULL, ENC_BIG_ENDIAN },
2722     { &hf_tn3270_rw,           NULL, 2, NULL, ENC_BIG_ENDIAN },
2723     { &hf_tn3270_cw,           NULL, 2, NULL, ENC_BIG_ENDIAN },
2724     { &hf_tn3270_hw,           NULL, 2, NULL, ENC_BIG_ENDIAN },
2725     { &hf_tn3270_ww,           NULL, 2, NULL, ENC_BIG_ENDIAN },
2726     { NULL, NULL, 0, NULL, 0 }
2727   };
2728
2729
2730   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2731                                 outbound_text_header_fields);
2732
2733   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
2734
2735   return (offset - start);
2736 }
2737
2738 /* 6.4 Inbound 3270DS */
2739 static gint
2740 dissect_inbound_3270ds(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2741                        tn3270_conv_info_t *tn3270_info, gint sf_body_length)
2742 {
2743   gint start = offset;
2744
2745   static const hf_items fields1[] = {
2746     { &hf_tn3270_partition_id,   NULL, 1,                  NULL, ENC_BIG_ENDIAN },
2747     { &hf_tn3270_aid,            NULL, 1,                  NULL, ENC_BIG_ENDIAN },
2748     { NULL, NULL, 0, NULL, 0 }
2749   };
2750
2751   hf_items fields2[] = {
2752     { &hf_tn3270_field_data,     NULL, sf_body_length - 4, NULL, ENC_EBCDIC|ENC_NA },
2753     { NULL, NULL, 0, NULL, 0 }
2754   };
2755
2756   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset, fields1);
2757   offset += dissect_buffer_address(tn3270_tree, tvb, offset, hf_tn3270_cursor_address, tn3270_info);
2758   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset, fields2);
2759
2760   return (offset - start);
2761 }
2762
2763
2764
2765 /* 6.5 Recovery Data */
2766 static gint
2767 dissect_recovery_data(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2768                       gint sf_body_length)
2769 {
2770   gint start = offset;
2771
2772
2773   static const hf_items fields[] = {
2774     { &hf_tn3270_resbyte,             NULL, 1, NULL, ENC_BIG_ENDIAN },
2775     { &hf_tn3270_recovery_data_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
2776     { &hf_tn3270_sld,                 NULL, 1, NULL, ENC_BIG_ENDIAN },
2777     { &hf_tn3270_charset,             NULL, 1, NULL, ENC_BIG_ENDIAN },
2778     { &hf_tn3270_vertical,            NULL, 2, NULL, ENC_BIG_ENDIAN },
2779     { &hf_tn3270_v_offset,            NULL, 2, NULL, ENC_BIG_ENDIAN },
2780     { &hf_tn3270_v_sequence,          NULL, 2, NULL, ENC_BIG_ENDIAN },
2781     { &hf_tn3270_v_length,            NULL, 2, NULL, ENC_BIG_ENDIAN },
2782     { &hf_tn3270_spd,                 NULL, 2, NULL, ENC_BIG_ENDIAN },
2783     { &hf_tn3270_horizon,             NULL, 2, NULL, ENC_BIG_ENDIAN },
2784     { &hf_tn3270_h_offset,            NULL, 2, NULL, ENC_BIG_ENDIAN },
2785     { &hf_tn3270_h_sequence,          NULL, 2, NULL, ENC_BIG_ENDIAN },
2786     { &hf_tn3270_h_length,            NULL, 2, NULL, ENC_BIG_ENDIAN },
2787     { &hf_tn3270_color,               NULL, 1, NULL, ENC_BIG_ENDIAN },
2788     { &hf_tn3270_hilite,              NULL, 1, NULL, ENC_BIG_ENDIAN },
2789     { &hf_tn3270_pages,               NULL, 2, NULL, ENC_BIG_ENDIAN },
2790     { &hf_tn3270_lines,               NULL, 2, NULL, ENC_BIG_ENDIAN },
2791     { &hf_tn3270_checkpoint,          NULL, 2, NULL, ENC_BIG_ENDIAN },
2792     { &hf_tn3270_c_offset,            NULL, 2, NULL, ENC_BIG_ENDIAN },
2793     { &hf_tn3270_c_sequence,          NULL, 2, NULL, ENC_BIG_ENDIAN },
2794     { &hf_tn3270_c_seqoff,            NULL, 2, NULL, ENC_BIG_ENDIAN },
2795     { &hf_tn3270_c_scsoff,            NULL, 2, NULL, ENC_BIG_ENDIAN },
2796     { &hf_tn3270_prime,               NULL, 1, NULL, ENC_BIG_ENDIAN },
2797     { NULL, NULL, 0, NULL, 0 }
2798   };
2799
2800
2801   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2802                                 fields);
2803
2804   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
2805
2806   return (offset - start);
2807 }
2808
2809 /* 6.6 Query Reply (Type 1 Text Inbound) - See above*/
2810 /* 6.7 and 6.8 Query Reply - Introductory Matter */
2811
2812 /* 6.9 Query Reply (Alphanumeric Partitions) */
2813 static gint
2814 dissect_query_reply_alphanumeric_sd_parms(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
2815 {
2816
2817   gint    start = offset;
2818   guint16 sdp;
2819
2820   static const hf_items sdp1[] = {
2821     { &hf_tn3270_sdp_ln, NULL, 1, NULL, ENC_BIG_ENDIAN },
2822     { &hf_tn3270_sdp_id, NULL, 1, NULL, ENC_BIG_ENDIAN },
2823     { &hf_tn3270_ap_cm,  NULL, 1, NULL, ENC_BIG_ENDIAN },
2824     { &hf_tn3270_ap_ro,  NULL, 1, NULL, ENC_BIG_ENDIAN },
2825     { &hf_tn3270_ap_co,  NULL, 1, NULL, ENC_BIG_ENDIAN },
2826     { &hf_tn3270_ap_fo,  NULL, 2, NULL, ENC_BIG_ENDIAN },
2827     { NULL, NULL, 0, NULL, 0 }
2828   };
2829
2830
2831   sdp = tvb_get_ntohs(tvb, offset);
2832
2833   switch (sdp) {
2834     case 0x0702: /*Buffer Allocation*/
2835       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2836                                     sdp1);
2837       break;
2838     default:
2839       return 0;
2840   }
2841
2842   return (offset - start);
2843
2844 }
2845
2846 static gint
2847 dissect_query_reply_alphanumeric(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2848                                  gint sf_body_length)
2849 {
2850   gint start = offset;
2851
2852   static const gint *byte[] = {
2853     &hf_tn3270_ap_vertical_scrolling,
2854     &hf_tn3270_ap_horizontal_scrolling,
2855     &hf_tn3270_ap_apres1,
2856     &hf_tn3270_ap_apa,
2857     &hf_tn3270_ap_pp,
2858     &hf_tn3270_ap_lc,
2859     &hf_tn3270_ap_mp,
2860     &hf_tn3270_ap_apres2,
2861     NULL
2862   };
2863
2864   static const hf_items fields[] = {
2865     { &hf_tn3270_ap_na, NULL, 1, NULL, ENC_BIG_ENDIAN },
2866     { &hf_tn3270_ap_m,  NULL, 2, NULL, ENC_BIG_ENDIAN },
2867     { &hf_tn3270_query_reply_alphanumeric_flags, &ett_tn3270_query_reply_alphanumeric_flags, 1, byte, 0 },
2868     { NULL, NULL, 0, NULL, 0 }
2869   };
2870
2871   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2872                                 fields);
2873
2874   offset += dissect_query_reply_alphanumeric_sd_parms(tn3270_tree, tvb, offset);
2875
2876   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
2877
2878   return (offset - start);
2879 }
2880
2881 /* 6.10 Query Reply (Auxiliary Device) - Search for QUERY_REPLY_AUXILIARY_DEVICE */
2882 /* 6.11 Query Reply (BEGIN/End of File ) - Search for QUERY_REPLY_BEGIN_OR_END_OF_FILE */
2883
2884 /* 6.12 Query Reply (Character Sets) */
2885 static gint
2886 dissect_query_reply_character_sets(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
2887                                    gint sf_body_length)
2888 {
2889   gint start = offset;
2890   gint flagbyte1, flagbyte2;
2891
2892   static const gint *byte1[] = {
2893     &hf_tn3270_cs_ge,
2894     &hf_tn3270_cs_mi,
2895     &hf_tn3270_cs_lps,
2896     &hf_tn3270_cs_lpse,
2897     &hf_tn3270_cs_ms,
2898     &hf_tn3270_cs_ch2,
2899     &hf_tn3270_cs_gf,
2900     &hf_tn3270_cs_res,
2901     NULL
2902   };
2903
2904   static const gint *byte2[] = {
2905     &hf_tn3270_cs_res2,
2906     &hf_tn3270_cs_pscs,
2907     &hf_tn3270_cs_res3,
2908     &hf_tn3270_cs_cf,
2909     NULL
2910   };
2911
2912   static const gint *byte3[] = {
2913     &hf_tn3270_cs_form_type1,
2914     &hf_tn3270_cs_form_type2,
2915     &hf_tn3270_cs_form_type3,
2916     &hf_tn3270_cs_form_type4,
2917     &hf_tn3270_cs_form_type5,
2918     &hf_tn3270_cs_form_type6,
2919     &hf_tn3270_cs_form_type8,
2920     NULL
2921   };
2922
2923   static const gint *byte4[] = {
2924     &hf_tn3270_cs_ds_load,
2925     &hf_tn3270_cs_ds_triple,
2926     &hf_tn3270_cs_ds_char,
2927     &hf_tn3270_cs_ds_cb,
2928     NULL
2929   };
2930
2931
2932   static const hf_items fields[] = {
2933     { &hf_tn3270_character_sets_flags1, &ett_tn3270_character_sets_flags1, 1, byte1, 0 },
2934     { &hf_tn3270_character_sets_flags2, &ett_tn3270_character_sets_flags2, 1, byte2, 0 },
2935     { &hf_tn3270_sdw,     NULL, 1, NULL, ENC_BIG_ENDIAN },
2936     { &hf_tn3270_sdh,     NULL, 1, NULL, ENC_BIG_ENDIAN },
2937     { &hf_tn3270_form,                  &ett_tn3270_character_sets_form,   1, byte3, 0 },
2938     { &hf_tn3270_formres, NULL, 1, NULL, ENC_BIG_ENDIAN },
2939     { &hf_tn3270_formres, NULL, 1, NULL, ENC_BIG_ENDIAN },
2940     { &hf_tn3270_formres, NULL, 1, NULL, ENC_BIG_ENDIAN },
2941     { &hf_tn3270_cs_dl,   NULL, 1, NULL, ENC_BIG_ENDIAN },
2942     { NULL, NULL, 0, NULL, 0 }
2943   };
2944
2945   static const hf_items descriptors[] = {
2946     { &hf_tn3270_cs_descriptor_set,   NULL, 1, NULL, ENC_BIG_ENDIAN },
2947     { &hf_tn3270_cs_descriptor_flags, &ett_tn3270_cs_descriptor_flags, 1, byte4, 0 },
2948     { &hf_tn3270_lcid,                NULL, 1, NULL, ENC_BIG_ENDIAN },
2949     { NULL, NULL, 0, NULL, 0 }
2950   };
2951
2952   static const hf_items sw_sh[] = {
2953     { &hf_tn3270_sw, NULL, 1, NULL, ENC_BIG_ENDIAN },
2954     { &hf_tn3270_sh, NULL, 1, NULL, ENC_BIG_ENDIAN },
2955     { NULL, NULL, 0, NULL, 0 }
2956   };
2957
2958   static const hf_items subsn[] = {
2959     { &hf_tn3270_ssubsn, NULL, 1, NULL, ENC_BIG_ENDIAN },
2960     { &hf_tn3270_esubsn, NULL, 1, NULL, ENC_BIG_ENDIAN },
2961     { NULL, NULL, 0, NULL, 0 }
2962   };
2963
2964   static const hf_items gf[] = {
2965     { &hf_tn3270_ccsgid, NULL, 4, NULL, ENC_BIG_ENDIAN },
2966     { NULL, NULL, 0, NULL, 0 }
2967   };
2968
2969   static const hf_items cf[] = {
2970     { &hf_tn3270_ccsid,  NULL, 2, NULL, ENC_BIG_ENDIAN },
2971     { NULL, NULL, 0, NULL, 0 }
2972   };
2973
2974   flagbyte1 = tvb_get_guint8(tvb, offset);
2975   flagbyte2 = tvb_get_guint8(tvb, offset+1);
2976
2977   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2978                                 fields);
2979
2980   while ((offset - start) < sf_body_length) {
2981
2982     offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2983                                   descriptors);
2984
2985     if (flagbyte1 & QR_CS_MS) {
2986       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2987                                     sw_sh);
2988     }
2989
2990     if (flagbyte1 & QR_CS_CH2) {
2991       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2992                                     subsn);
2993     }
2994
2995     if (flagbyte1 & QR_CS_GF) {
2996       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
2997                                     gf);
2998     }
2999
3000     if (flagbyte2 & QR_CS_CF) {
3001       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3002                                     cf);
3003     }
3004   }
3005   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3006
3007   return (offset - start);
3008 }
3009
3010 /* 6.13 Query Reply (Color) */
3011 static gint
3012 dissect_query_reply_color_sd_parms(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
3013 {
3014
3015   gint    start = offset;
3016   guint16 sdp;
3017
3018   static const hf_items sdp1[] = {
3019     { &hf_tn3270_sdp_ln,    NULL, 1, NULL, ENC_BIG_ENDIAN },
3020     { &hf_tn3270_sdp_id,    NULL, 1, NULL, ENC_BIG_ENDIAN },
3021     { &hf_tn3270_db_cavdef, NULL, 1, NULL, ENC_BIG_ENDIAN },
3022     { &hf_tn3270_db_cidef,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3023     { NULL, NULL, 0, NULL, 0 }
3024   };
3025
3026
3027   sdp = tvb_get_ntohs(tvb, offset);
3028
3029   switch (sdp) {
3030     case 0x0402: /*Default Background Color*/
3031       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3032                                     sdp1);
3033       break;
3034     default:
3035       return 0;
3036   }
3037
3038   return (offset - start);
3039
3040 }
3041
3042 static gint
3043 dissect_query_reply_color(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3044                           gint sf_body_length)
3045 {
3046   gint start = offset;
3047   gint i;
3048   gint np;
3049
3050   static const gint *byte[] = {
3051     &hf_tn3270_c_prtblk,
3052     NULL
3053   };
3054
3055   static const hf_items fields[] = {
3056     { &hf_tn3270_color_flags, &ett_tn3270_color_flags, 1, byte, 0 },
3057     { &hf_tn3270_c_np, NULL, 1, NULL, ENC_BIG_ENDIAN },
3058     { NULL, NULL, 0, NULL, 0 }
3059   };
3060
3061
3062   np = tvb_get_guint8(tvb, offset +1);
3063   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3064                                 fields);
3065
3066   for (i=0; i < np; i++) {
3067     if (tvb_get_guint8(tvb, offset) == 0xFF) {
3068       offset += 1;
3069     }
3070     proto_tree_add_item(tn3270_tree,
3071                         hf_tn3270_c_cav,
3072                         tvb, offset,
3073                         1,
3074                         ENC_BIG_ENDIAN);
3075     offset += 1;
3076     if (tvb_get_guint8(tvb, offset) == 0xFF) {
3077       offset += 1;
3078     }
3079     proto_tree_add_item(tn3270_tree,
3080                         hf_tn3270_c_ci,
3081                         tvb, offset,
3082                         1,
3083                         ENC_BIG_ENDIAN);
3084     offset += 1;
3085   }
3086   offset += dissect_query_reply_color_sd_parms(tn3270_tree, tvb, offset);
3087
3088   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3089
3090   return (offset - start);
3091 }
3092
3093
3094 /* 6.36 - Query Reply (OEM Auxiliary Device) Self-Defining Parameters */
3095 static gint
3096 dissect_daid_sd_parm(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
3097 {
3098
3099   gint start = offset;
3100
3101   static const hf_items sdp1[] = {
3102     { &hf_tn3270_sdp_ln,   NULL, 1, NULL, ENC_BIG_ENDIAN },
3103     { &hf_tn3270_sdp_id,   NULL, 1, NULL, ENC_BIG_ENDIAN },
3104     { &hf_tn3270_sdp_daid, NULL, 2, NULL, ENC_BIG_ENDIAN },
3105     { NULL, NULL, 0, NULL, 0 }
3106   };
3107
3108   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3109                                 sdp1);
3110   return (offset - start);
3111
3112 }
3113
3114 static gint
3115 dissect_pclk_sd_parm(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
3116 {
3117
3118   gint start = offset;
3119
3120   static const hf_items sdp1[] = {
3121     { &hf_tn3270_sdp_ln,            NULL, 1, NULL, ENC_BIG_ENDIAN },
3122     { &hf_tn3270_sdp_id,            NULL, 1, NULL, ENC_BIG_ENDIAN },
3123     { &hf_tn3270_oem_sdp_pclk_vers, NULL, 2, NULL, ENC_BIG_ENDIAN },
3124     { NULL, NULL, 0, NULL, 0 }
3125   };
3126
3127   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3128                                 sdp1);
3129   return (offset - start);
3130
3131 }
3132
3133 static gint
3134 dissect_query_reply_oem_auxiliary_device_sd_parms(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
3135 {
3136
3137   gint start = offset;
3138   gint sdp_len;
3139   gint sdp;
3140
3141   static const hf_items sdp1[] = {
3142     { &hf_tn3270_sdp_ln,   NULL, 1, NULL, ENC_BIG_ENDIAN },
3143     { &hf_tn3270_sdp_id,   NULL, 1, NULL, ENC_BIG_ENDIAN },
3144     { &hf_tn3270_sdp_daid, NULL, 2, NULL, ENC_BIG_ENDIAN },
3145     { NULL, NULL, 0, NULL, 0 }
3146   };
3147
3148   static const hf_items sdp2[] = {
3149     { &hf_tn3270_sdp_ln,            NULL, 1, NULL, ENC_BIG_ENDIAN },
3150     { &hf_tn3270_sdp_id,            NULL, 1, NULL, ENC_BIG_ENDIAN },
3151     { &hf_tn3270_oem_sdp_ll_limin,  NULL, 2, NULL, ENC_BIG_ENDIAN },
3152     { &hf_tn3270_oem_sdp_ll_limout, NULL, 2, NULL, ENC_BIG_ENDIAN },
3153
3154     { NULL, NULL, 0, NULL, 0 }
3155   };
3156
3157   static const hf_items sdp3[] = {
3158     { &hf_tn3270_sdp_ln,            NULL, 1, NULL, ENC_BIG_ENDIAN },
3159     { &hf_tn3270_sdp_id,            NULL, 1, NULL, ENC_BIG_ENDIAN },
3160     { &hf_tn3270_oem_sdp_pclk_vers, NULL, 2, NULL, ENC_BIG_ENDIAN },
3161     { NULL, NULL, 0, NULL, 0 }
3162   };
3163
3164
3165   sdp_len = tvb_get_guint8(tvb, offset);
3166   if ((sdp_len != 0x04) && (sdp_len != 0x06)) {
3167     return 0;
3168   }
3169
3170   sdp = tvb_get_guint8(tvb, offset+1);
3171
3172   switch (sdp) {
3173     case 0x01:
3174       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3175                                     sdp1);
3176       break;
3177     case 0x02:
3178       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3179                                     sdp2);
3180       break;
3181     case 0x03:
3182       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3183                                     sdp3);
3184       break;
3185     default:
3186       return 0;
3187   }
3188
3189   return (offset - start);
3190
3191 }
3192
3193 /* 6.14 - Query Reply (Cooperative Processing Requestor) */
3194 static gint
3195 dissect_query_reply_cooperative(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3196                                 gint sf_body_length)
3197 {
3198   gint start = offset;
3199
3200   static const hf_items fields[] = {
3201     { &hf_tn3270_res_twobytes, NULL, 2, NULL, ENC_BIG_ENDIAN },
3202     { &hf_tn3270_limin,        NULL, 2, NULL, ENC_BIG_ENDIAN },
3203     { &hf_tn3270_limout,       NULL, 2, NULL, ENC_BIG_ENDIAN },
3204     { &hf_tn3270_featl,        NULL, 1, NULL, ENC_BIG_ENDIAN },
3205     { &hf_tn3270_feats,        NULL, 2, NULL, ENC_BIG_ENDIAN },
3206     { NULL, NULL, 0, NULL, 0 }
3207   };
3208
3209
3210   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3211                                 fields);
3212
3213 #if 0
3214   /*FIXME: Need to see this in action to dissect in detail */
3215   proto_tree_add_item(tn3270_tree,
3216                       hf_tn3270_field_data,
3217                       tvb, offset,
3218                       sf_body_length - (offset-start),
3219                       ENC_EBCDIC|ENC_NA);
3220   offset += (sf_body_length - (offset - start));
3221
3222   /* Uses same Self-Defining Parm as OEM Auxiliary Device */
3223   offset += dissect_query_reply_oem_auxiliary_device_sd_parms(tn3270_tree, tvb, offset);
3224 #endif
3225
3226   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3227
3228   return (offset - start);
3229 }
3230
3231 /* 6.15 - Query Reply (Data Chaining) */
3232 static gint
3233 dissect_query_reply_data_chaining(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3234                                   gint sf_body_length)
3235 {
3236   gint start = offset;
3237
3238   static const hf_items fields[] = {
3239     { &hf_tn3270_dc_dir,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3240     { &hf_tn3270_resbyte, NULL, 1, NULL, ENC_BIG_ENDIAN },
3241     { NULL, NULL, 0, NULL, 0 }
3242   };
3243
3244   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3245                                 fields);
3246
3247   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3248
3249   return (offset - start);
3250 }
3251
3252 /* 6.16 - Query Reply (Data Streams) */
3253
3254 static gint
3255 dissect_query_reply_data_streams(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3256                                  gint sf_body_length)
3257 {
3258   gint start = offset;
3259   gint i;
3260
3261   proto_tree_add_item(tn3270_tree, hf_tn3270_ds_default_sfid, tvb, offset, 1,
3262                       ENC_BIG_ENDIAN);
3263   offset += 1;
3264
3265   for (i=0; i < (sf_body_length-(offset-start)); i++) {
3266     proto_tree_add_item(tn3270_tree,
3267                         hf_tn3270_ds_sfid,
3268                         tvb, offset,
3269                         1,
3270                         ENC_BIG_ENDIAN);
3271     offset += 1;
3272   }
3273   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3274
3275   return (offset - start);
3276 }
3277
3278 /* 6.17 - Query Reply (DBCS Asia) */
3279
3280 static gint
3281 dissect_query_reply_dbcs_asia_sd_parms(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
3282 {
3283
3284   gint start = offset;
3285   gint sdp_len;
3286   gint sdp;
3287
3288   static const hf_items sdp1[] = {
3289     { &hf_tn3270_sdp_ln,              NULL, 1, NULL, ENC_BIG_ENDIAN },
3290     { &hf_tn3270_sdp_id,              NULL, 1, NULL, ENC_BIG_ENDIAN },
3291     { &hf_tn3270_asia_sdp_sosi_soset, NULL, 1, NULL, ENC_BIG_ENDIAN },
3292     { NULL, NULL, 0, NULL, 0 }
3293   };
3294
3295   static const hf_items sdp2[] = {
3296     { &hf_tn3270_sdp_ln,           NULL, 1, NULL, ENC_BIG_ENDIAN },
3297     { &hf_tn3270_sdp_id,           NULL, 1, NULL, ENC_BIG_ENDIAN },
3298     { &hf_tn3270_asia_sdp_ic_func, NULL, 1, NULL, ENC_BIG_ENDIAN },
3299     { NULL, NULL, 0, NULL, 0 }
3300   };
3301
3302   sdp_len = tvb_get_guint8(tvb, offset);
3303   if (sdp_len != 0x03) {
3304     return 0;
3305   }
3306
3307   sdp = tvb_get_guint8(tvb, offset+1);
3308
3309   switch (sdp) {
3310     case 0x01: /*SO/SI*/
3311       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3312                                     sdp1);
3313       break;
3314     case 0x02: /*Input Control*/
3315       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3316                                     sdp2);
3317       break;
3318     default:
3319       return 0;
3320   }
3321
3322   return (offset - start);
3323
3324 }
3325
3326 static gint
3327 dissect_query_reply_dbcs_asia(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3328                               gint sf_body_length)
3329 {
3330
3331   gint start = offset;
3332   gint i;
3333
3334   static const hf_items fields[] = {
3335     { &hf_tn3270_resbyte, NULL, 1, NULL, ENC_BIG_ENDIAN },
3336     { NULL, NULL, 0, NULL, 0 }
3337   };
3338
3339
3340   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3341                                 fields);
3342
3343   for (i = 0; i < 3; i++) {
3344     offset += dissect_query_reply_dbcs_asia_sd_parms(tn3270_tree, tvb, offset);
3345     if (tvb_reported_length_remaining(tvb, offset) <= 0)
3346       break;
3347   }
3348
3349   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3350
3351   return (offset - start);
3352 }
3353
3354 /* 6.18 - Query Reply (Device Characteristics) */
3355 static gint
3356 dissect_query_reply_device_characteristics(proto_tree *tn3270_tree, tvbuff_t *tvb,
3357                                            gint offset, gint sf_body_length)
3358 {
3359   gint start = offset;
3360
3361 #if 0 /* XXX: I don't think this is correct (i.e., this field is not part of this message) .... */
3362   proto_tree_add_item(tn3270_tree,
3363                       hf_tn3270_sf_outbound_id,
3364                       tvb, offset,
3365                       1,
3366                       ENC_BIG_ENDIAN);
3367   offset += 1;
3368 #endif
3369
3370   /* TODO: dissect descriptors */
3371   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3372
3373   return (offset - start);
3374 }
3375
3376 /* 6.19 - Query Reply (Distributed Data Management) */
3377 static gint
3378 dissect_query_reply_distributed_data_management(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3379                                                 gint sf_body_length)
3380 {
3381   gint     start = offset, i;
3382   gint     sdp;
3383   gboolean done  = FALSE;
3384
3385   static const hf_items fields[] = {
3386     { &hf_tn3270_ddm_flags,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3387     { &hf_tn3270_ddm_flags,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3388     { &hf_tn3270_ddm_limin,  NULL, 2, NULL, ENC_BIG_ENDIAN },
3389     { &hf_tn3270_ddm_limout, NULL, 2, NULL, ENC_BIG_ENDIAN },
3390     { &hf_tn3270_ddm_nss,    NULL, 1, NULL, ENC_BIG_ENDIAN },
3391     { &hf_tn3270_ddm_ddmss,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3392     { NULL, NULL, 0, NULL, 0 }
3393   };
3394
3395   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3396                                 fields);
3397
3398   for (i = 0; i < 3; i++) {
3399     sdp = tvb_get_guint8(tvb, offset+1);
3400     switch (sdp) {
3401       case 0x02: /*DDM*/
3402         /*TODO: DDM */
3403         offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, tvb_get_guint8(tvb,offset));
3404         break;
3405       case 0x01: /*DAID*/
3406         offset += dissect_daid_sd_parm(tn3270_tree, tvb, offset);
3407         break;
3408       case 0x03: /*PCLK*/
3409         offset += dissect_pclk_sd_parm(tn3270_tree, tvb, offset);
3410         break;
3411       default:
3412         done = TRUE;
3413         break;
3414     }
3415     if ((tvb_reported_length_remaining(tvb, offset) <= 0) || done)
3416       break;
3417   }
3418
3419   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3420
3421   return (offset - start);
3422 }
3423
3424 /* 6.20 - Query Reply (Document Interchange Architecture) */
3425 static gint
3426 dissect_query_reply_document_interchange_architecture(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3427                                                       gint sf_body_length)
3428 {
3429   gint start = offset, sdp, ln, i;
3430
3431   static const hf_items fields[] = {
3432     { &hf_tn3270_dia_flags,  NULL, 2, NULL, ENC_BIG_ENDIAN },
3433     { &hf_tn3270_dia_limin,  NULL, 2, NULL, ENC_BIG_ENDIAN },
3434     { &hf_tn3270_dia_limout, NULL, 2, NULL, ENC_BIG_ENDIAN },
3435     { NULL, NULL, 0, NULL, 0 }
3436   };
3437
3438   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3439                                 fields);
3440
3441   ln = tvb_get_guint8(tvb, offset);
3442   proto_tree_add_item(tn3270_tree, hf_tn3270_dia_nfs, tvb, offset, 1, ENC_BIG_ENDIAN);
3443
3444   for (i=0; i < ln; i++) {
3445     proto_tree_add_item(tn3270_tree, hf_tn3270_dia_diafs, tvb, offset, 1,
3446                         ENC_BIG_ENDIAN);
3447     offset += 1;
3448     proto_tree_add_item(tn3270_tree, hf_tn3270_dia_diafn, tvb, offset, 2,
3449                         ENC_BIG_ENDIAN);
3450     offset += 1;
3451   }
3452
3453   sdp = tvb_get_guint8(tvb, offset+1);
3454   if (sdp == 0x01) { /*DAID*/
3455     offset += dissect_daid_sd_parm(tn3270_tree, tvb, offset);
3456   }
3457
3458   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3459
3460   return (offset - start);
3461 }
3462
3463 /* 6.21 - Query Reply (Extended Drawing Routine) */
3464 static gint
3465 dissect_query_reply_extended_drawing_routine(proto_tree *tn3270_tree, tvbuff_t *tvb,
3466                                              gint offset, gint sf_body_length)
3467 {
3468   gint start = offset;
3469
3470   proto_tree_add_item(tn3270_tree, hf_tn3270_field_data ,tvb, offset,
3471                       sf_body_length, ENC_EBCDIC|ENC_NA);
3472
3473   offset += sf_body_length;
3474
3475   return (offset - start);
3476 }
3477
3478 /* 6.22 - Query Reply (Field Outlining) */
3479 static gint
3480 dissect_query_reply_field_outlining(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3481                                     gint sf_body_length)
3482 {
3483   gint start = offset;
3484
3485   static const hf_items fields[] = {
3486     { &hf_tn3270_resbyte,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3487     { &hf_tn3270_fo_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
3488     { &hf_tn3270_fo_vpos,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3489     { &hf_tn3270_fo_hpos,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3490     { &hf_tn3270_fo_hpos0, NULL, 1, NULL, ENC_BIG_ENDIAN },
3491     { &hf_tn3270_fo_hpos1, NULL, 1, NULL, ENC_BIG_ENDIAN },
3492     { NULL, NULL, 0, NULL, 0 }
3493   };
3494
3495   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3496                                 fields);
3497
3498   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3499
3500   return (offset - start);
3501 }
3502
3503 /* 6.23 - Query Reply (Field Validation) - Search for FIELD_VALIDATION*/
3504 /* 6.24 - Query Reply (Format Presentation) - Search for FORMAT_PRESENTATION*/
3505
3506 /* 6.25 - Query Reply (Format Storage Auxiliary Device)*/
3507 static gint
3508 dissect_query_reply_format_storage_aux_device(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3509                                               gint sf_body_length)
3510 {
3511   gint start = offset, sdp;
3512
3513   static const hf_items fields[] = {
3514     { &hf_tn3270_fsad_flags,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3515     { &hf_tn3270_resbyte,     NULL, 1, NULL, ENC_BIG_ENDIAN },
3516     { &hf_tn3270_fsad_limin,  NULL, 2, NULL, ENC_BIG_ENDIAN },
3517     { &hf_tn3270_fsad_limout, NULL, 2, NULL, ENC_BIG_ENDIAN },
3518     { NULL, NULL, 0, NULL, 0 }
3519   };
3520
3521   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3522                                 fields);
3523
3524   sdp = tvb_get_guint8(tvb, offset+1);
3525   if (sdp == 0x01) { /*DAID*/
3526     offset += dissect_daid_sd_parm(tn3270_tree, tvb, offset);
3527     proto_tree_add_item(tn3270_tree, hf_tn3270_fsad_size ,tvb, offset,
3528                         2, ENC_BIG_ENDIAN);
3529     offset += 2;
3530   }
3531
3532   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3533
3534   return (offset - start);
3535 }
3536
3537 /* 6.26 - Query Reply (Graphic Color) - Search for GRAPHIC_COLOR*/
3538 /* 6.27 - Query Reply (Graphic Symbol Sets) - Search for GRAPHIC_SYMBOL_SETS*/
3539
3540 /* 6.28 - Query Reply (Highlighting) */
3541 static gint
3542 dissect_query_reply_highlighting(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3543                                  gint sf_body_length)
3544 {
3545   gint start = offset;
3546   gint i;
3547   gint np;
3548
3549   static const hf_items fields[] = {
3550     { &hf_tn3270_h_np, NULL, 1, NULL, ENC_BIG_ENDIAN },
3551     { NULL, NULL, 0, NULL, 0 }
3552   };
3553
3554
3555   np = tvb_get_guint8(tvb, offset);
3556   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3557                                 fields);
3558
3559   for (i=0; i < np; i++) {
3560     if (tvb_get_guint8(tvb, offset) == 0xFF) {
3561       offset += 1;
3562     }
3563     proto_tree_add_item(tn3270_tree,
3564                         hf_tn3270_h_vi,
3565                         tvb, offset,
3566                         1,
3567                         ENC_BIG_ENDIAN);
3568     offset += 1;
3569     if (tvb_get_guint8(tvb, offset) == 0xFF) {
3570       offset += 1;
3571     }
3572     proto_tree_add_item(tn3270_tree,
3573                         hf_tn3270_h_ai,
3574                         tvb, offset,
3575                         1,
3576                         ENC_BIG_ENDIAN);
3577     offset += 1;
3578   }
3579
3580   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3581
3582   return (offset - start);
3583 }
3584
3585 /* 6.29 - Query Reply (IBM Auxiliary Device) */
3586 static gint
3587 dissect_query_reply_ibm_aux_device(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3588                                    gint sf_body_length)
3589 {
3590   gint     start = offset, i, sdp;
3591   gboolean done  = FALSE;
3592
3593   static const hf_items fields[] = {
3594     { &hf_tn3270_ibm_flags,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3595     { &hf_tn3270_resbyte,    NULL, 1, NULL, ENC_BIG_ENDIAN },
3596     { &hf_tn3270_ibm_limin,  NULL, 2, NULL, ENC_BIG_ENDIAN },
3597     { &hf_tn3270_ibm_limout, NULL, 2, NULL, ENC_BIG_ENDIAN },
3598     { &hf_tn3270_ibm_type,   NULL, 1, NULL, ENC_BIG_ENDIAN },
3599     { NULL, NULL, 0, NULL, 0 }
3600   };
3601
3602   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3603                                 fields);
3604
3605   for (i = 0; i < 3; i++) {
3606     sdp = tvb_get_guint8(tvb, offset+1);
3607     switch (sdp) {
3608       case 0x02: /*Printer Name*/
3609         /*TODO: Printer Name */
3610         offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, tvb_get_guint8(tvb,offset));
3611         break;
3612       case 0x01: /*DAID*/
3613         offset += dissect_daid_sd_parm(tn3270_tree, tvb, offset);
3614         break;
3615       case 0x03: /*PCLK*/
3616         offset += dissect_pclk_sd_parm(tn3270_tree, tvb, offset);
3617         break;
3618       default:
3619         done = TRUE;
3620         break;
3621     }
3622     if ((tvb_reported_length_remaining(tvb, offset) <= 0) || done)
3623       break;
3624   }
3625
3626   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3627
3628   return (offset - start);
3629 }
3630
3631 /* 6.30 - Query Reply (Image) */
3632
3633 /* 6.31 - Query Reply (Implicit Partitions) */
3634 static gint
3635 dissect_query_reply_implicit_partitions_sd_parms(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
3636 {
3637
3638   gint start = offset;
3639   gint sdp_len;
3640   gint sdp;
3641
3642   static const hf_items sdp1[] = {
3643     { &hf_tn3270_sdp_ln,   NULL, 1, NULL, ENC_BIG_ENDIAN },
3644     { &hf_tn3270_sdp_id,   NULL, 1, NULL, ENC_BIG_ENDIAN },
3645     { &hf_tn3270_ip_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
3646     { &hf_tn3270_ipdd_wd,  NULL, 2, NULL, ENC_BIG_ENDIAN },
3647     { &hf_tn3270_ipdd_hd,  NULL, 2, NULL, ENC_BIG_ENDIAN },
3648     { &hf_tn3270_ipdd_wa,  NULL, 2, NULL, ENC_BIG_ENDIAN },
3649     { &hf_tn3270_ipdd_ha,  NULL, 2, NULL, ENC_BIG_ENDIAN },
3650     { NULL, NULL, 0, NULL, 0 }
3651   };
3652
3653   static const hf_items sdp2[] = {
3654     { &hf_tn3270_sdp_ln,    NULL, 1, NULL, ENC_BIG_ENDIAN },
3655     { &hf_tn3270_sdp_id,    NULL, 1, NULL, ENC_BIG_ENDIAN },
3656     { &hf_tn3270_ip_flags,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3657     { &hf_tn3270_ippd_dpbs, NULL, 4, NULL, ENC_BIG_ENDIAN },
3658     { &hf_tn3270_ippd_apbs, NULL, 4, NULL, ENC_BIG_ENDIAN },
3659     { NULL, NULL, 0, NULL, 0 }
3660   };
3661
3662   static const hf_items sdp3[] = {
3663     { &hf_tn3270_sdp_ln,    NULL, 1, NULL, ENC_BIG_ENDIAN },
3664     { &hf_tn3270_sdp_id,    NULL, 1, NULL, ENC_BIG_ENDIAN },
3665     { &hf_tn3270_ip_flags,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3666     { &hf_tn3270_ipccd_wcd, NULL, 2, NULL, ENC_BIG_ENDIAN },
3667     { &hf_tn3270_ipccd_hcd, NULL, 2, NULL, ENC_BIG_ENDIAN },
3668     { &hf_tn3270_ipccd_wca, NULL, 2, NULL, ENC_BIG_ENDIAN },
3669     { &hf_tn3270_ipccd_hca, NULL, 2, NULL, ENC_BIG_ENDIAN },
3670     { NULL, NULL, 0, NULL, 0 }
3671   };
3672
3673   sdp_len = tvb_get_guint8(tvb, offset);
3674   if (sdp_len != 0x0B) {
3675     return 0;
3676   }
3677
3678   sdp = tvb_get_guint8(tvb, offset+1);
3679
3680   switch (sdp) {
3681     case QR_IP_SDP_DISPLAY:
3682       /* XXX: Save default and alternate screen size info as reported ? */
3683       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3684                                     sdp1);
3685       break;
3686     case QR_IP_SDP_PRINTER:
3687       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3688                                     sdp2);
3689       break;
3690     case QR_IP_SDP_CHARACTER:
3691       offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3692                                     sdp3);
3693       break;
3694     default:
3695       return 0;
3696   }
3697
3698   return (offset - start);
3699
3700 }
3701
3702 static gint
3703 dissect_query_reply_implicit_partitions(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3704                                         gint sf_body_length)
3705 {
3706   gint start = offset;
3707   gint i;
3708
3709   static const hf_items fields[] = {
3710     { &hf_tn3270_ip_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
3711     { &hf_tn3270_ip_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
3712     { NULL, NULL, 0, NULL, 0 }
3713   };
3714
3715   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3716                                 fields);
3717
3718   for (i = 0; i < 3; i++) {
3719     gint len;
3720     len = dissect_query_reply_implicit_partitions_sd_parms(tn3270_tree, tvb, offset);
3721     if ((len == 0) || (tvb_reported_length_remaining(tvb, offset) <= 0))
3722       break;
3723     offset += len;
3724   }
3725
3726   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3727
3728   return (offset - start);
3729 }
3730
3731 /* 6.32 - Query Reply (IOCA Auxiliary Device) */
3732 static gint
3733 dissect_query_reply_ioca_aux_device(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3734                                     gint sf_body_length)
3735 {
3736   gint start = offset;
3737
3738   static const hf_items fields[] = {
3739     { &hf_tn3270_resbyte,     NULL, 1, NULL, ENC_BIG_ENDIAN },
3740     { &hf_tn3270_resbyte,     NULL, 1, NULL, ENC_BIG_ENDIAN },
3741     { &hf_tn3270_ioca_limin,  NULL, 2, NULL, ENC_BIG_ENDIAN },
3742     { &hf_tn3270_ioca_limout, NULL, 2, NULL, ENC_BIG_ENDIAN },
3743     { &hf_tn3270_ioca_type,   NULL, 1, NULL, ENC_BIG_ENDIAN },
3744     { NULL, NULL, 0, NULL, 0 }
3745   };
3746
3747   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3748                                 fields);
3749
3750   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3751
3752   return (offset - start);
3753 }
3754
3755 /* 6.33 - Query Reply (Line Type) - Search for LINE_TYPE*/
3756
3757 /* 6.34 - Query Reply (MSR Control) */
3758 static gint
3759 dissect_query_reply_msr_control(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3760                                 gint sf_body_length)
3761 {
3762   gint start = offset;
3763
3764   static const hf_items fields[] = {
3765     { &hf_tn3270_resbyte,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3766     { &hf_tn3270_msr_nd,   NULL, 1, NULL, ENC_BIG_ENDIAN },
3767     { &hf_tn3270_msr_type, NULL, 1, NULL, ENC_BIG_ENDIAN },
3768     { NULL, NULL, 0, NULL, 0 }
3769   };
3770
3771   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3772                                 fields);
3773   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3774
3775   return (offset - start);
3776 }
3777
3778 /* 6.35 - Query Reply (Null) - Search for QUERY_REPLY_NULL */
3779
3780 /* 6.36 - Query Reply (OEM Auxiliary Device) */
3781 static gint
3782 dissect_query_reply_oem_auxiliary_device(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3783                                          gint sf_body_length)
3784 {
3785   gint start = offset;
3786   gint i;
3787
3788   static const hf_items fields[] = {
3789     { &hf_tn3270_resbyte,   NULL, 1, NULL, ENC_BIG_ENDIAN },
3790     { &hf_tn3270_oem_dsref, NULL, 1, NULL, ENC_BIG_ENDIAN },
3791     { &hf_tn3270_oem_dtype, NULL, 8, NULL, ENC_EBCDIC|ENC_NA },
3792     { &hf_tn3270_oem_uname, NULL, 8, NULL, ENC_EBCDIC|ENC_NA },
3793     { NULL, NULL, 0, NULL, 0 }
3794   };
3795
3796   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3797                                 fields);
3798
3799   for (i = 0; i < 3; i++) {
3800     offset += dissect_query_reply_oem_auxiliary_device_sd_parms(tn3270_tree, tvb, offset);
3801     if (tvb_reported_length_remaining(tvb, offset) <= 0)
3802       break;
3803   }
3804
3805   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3806
3807   return (offset - start);
3808 }
3809
3810 /* 6.37 - Query Reply (Paper Feed Techniques) */
3811 static gint
3812 dissect_query_reply_paper_feed_techniques(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3813                                           gint sf_body_length)
3814 {
3815   gint start = offset;
3816
3817   static const hf_items fields[] = {
3818     { &hf_tn3270_pft_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
3819     { &hf_tn3270_pft_tmo,   NULL, 2, NULL, ENC_BIG_ENDIAN },
3820     { &hf_tn3270_pft_bmo,   NULL, 2, NULL, ENC_BIG_ENDIAN },
3821     { NULL, NULL, 0, NULL, 0 }
3822   };
3823
3824   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3825                                 fields);
3826   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3827
3828   return (offset - start);
3829 }
3830
3831 /* 6.38 - Query Reply (Partition Characteristics) */
3832 static gint
3833 dissect_query_reply_partition_characteristics(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3834                                               gint sf_body_length)
3835 {
3836   gint     start = offset, i, sdp;
3837   gboolean done  = FALSE;
3838
3839   static const hf_items fields[] = {
3840     { &hf_tn3270_sdp_ln, NULL, 1, NULL, ENC_BIG_ENDIAN },
3841     { &hf_tn3270_sdp_id, NULL, 1, NULL, ENC_BIG_ENDIAN },
3842     { NULL, NULL, 0, NULL, 0 }
3843   };
3844
3845   for (i = 0; i < 2; i++) {
3846     sdp = tvb_get_guint8(tvb, offset+1);
3847     switch (sdp) {
3848       case 0x01: /*Viewport Outline*/
3849         offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3850                                       fields);
3851         proto_tree_add_item(tn3270_tree, hf_tn3270_pc_vo_thickness,
3852                             tvb, offset, 1, ENC_BIG_ENDIAN);
3853         offset += 1;
3854         break;
3855       case 0x03: /*Enable User Call-Up*/
3856         offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3857                                       fields);
3858         break;
3859       default:
3860         done = TRUE;
3861         break;
3862     }
3863     if ((tvb_reported_length_remaining(tvb, offset) <= 0) || done)
3864       break;
3865   }
3866
3867   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3868
3869   return (offset - start);
3870 }
3871
3872 /* 6.39 - Query Reply (Port) - Search for QUERY_REPLY_PORT */
3873 /* 6.40 - Query Reply (Procedure) - Search for QUERY_REPLY_PROCEDURE */
3874
3875 /* 6.41 - Query Reply ((Product Defined Data Stream) */
3876 static gint
3877 dissect_query_reply_product_defined_data_stream(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3878                                                 gint sf_body_length)
3879 {
3880   gint start = offset, sdp;
3881
3882   static const hf_items fields[] = {
3883     { &hf_tn3270_resbytes,   NULL, 2, NULL, ENC_BIG_ENDIAN },
3884     { &hf_tn3270_pdds_refid, NULL, 1, NULL, ENC_BIG_ENDIAN },
3885     { &hf_tn3270_pdds_ssid,  NULL, 1, NULL, ENC_BIG_ENDIAN },
3886     { NULL, NULL, 0, NULL, 0 }
3887   };
3888
3889   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3890                                 fields);
3891
3892   sdp = tvb_get_guint8(tvb, offset+1);
3893   if (sdp == 0x01) { /*DAID*/
3894     offset += dissect_daid_sd_parm(tn3270_tree, tvb, offset);
3895   }
3896
3897   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3898
3899   return (offset - start);
3900 }
3901
3902 /* 6.42 - Query Reply (Modes) */
3903 static gint
3904 dissect_query_reply_modes(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3905                           gint sf_body_length)
3906 {
3907   gint start = offset;
3908   gint i;
3909
3910   for (i=0; i < sf_body_length; i++) {
3911     proto_tree_add_item(tn3270_tree,
3912                         hf_tn3270_mode,
3913                         tvb, offset,
3914                         1,
3915                         ENC_BIG_ENDIAN);
3916     offset += 1;
3917   }
3918
3919   return (offset - start);
3920 }
3921
3922 /* 6.43 - Query Reply (RPQ Names) */
3923 static gint
3924 dissect_query_reply_rpq_names(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3925                               gint sf_body_length)
3926 {
3927   gint start = offset;
3928   gint rpql;
3929
3930   static const hf_items fields[] = {
3931     { &hf_tn3270_rpq_device, NULL, 4, NULL, ENC_EBCDIC|ENC_NA },
3932     { &hf_tn3270_rpq_mid,    NULL, 4, NULL, ENC_BIG_ENDIAN },
3933     { NULL, NULL, 0, NULL, 0 }
3934   };
3935
3936   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3937                                 fields);
3938
3939   rpql = tvb_get_guint8(tvb, offset);
3940
3941   proto_tree_add_item(tn3270_tree,
3942                       hf_tn3270_rpq_rpql,
3943                       tvb, offset,
3944                       1,
3945                       ENC_BIG_ENDIAN);
3946   offset += 1;
3947
3948   proto_tree_add_item(tn3270_tree,
3949                       hf_tn3270_rpq_name,
3950                       tvb, offset,
3951                       (rpql - 1),
3952                       ENC_EBCDIC|ENC_NA);
3953   offset += (rpql-1);
3954
3955   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3956
3957   return (offset - start);
3958 }
3959
3960 /* 6.44 - Query Reply (Save/Restore Format) */
3961 static gint
3962 dissect_query_reply_save_or_restore_format(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3963                                            gint sf_body_length)
3964 {
3965   gint start = offset;
3966
3967   static const hf_items fields[] = {
3968     { &hf_tn3270_srf_fpcbl, NULL, 1, NULL, ENC_NA },
3969     { NULL, NULL, 0, NULL, 0 }
3970   };
3971
3972   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
3973                                 fields);
3974
3975   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
3976
3977   return (offset - start);
3978 }
3979
3980 /* 6.45 - Query Reply (Segment) - Search for QUERY_REPLY_SEGMENT */
3981
3982 /* 6.46 - Query Reply ((Settable Printer Characteristics) */
3983 static gint
3984 dissect_query_reply_settable_printer_characteristics(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
3985                                                      gint sf_body_length)
3986 {
3987   gint start = offset, sdp;
3988
3989   static const hf_items fields[] = {
3990     { &hf_tn3270_resbytes, NULL, 2, NULL, ENC_BIG_ENDIAN },
3991     { NULL, NULL, 0, NULL, 0 }
3992   };
3993
3994   static const hf_items fields2[] = {
3995     { &hf_tn3270_sdp_ln, NULL, 1, NULL, ENC_BIG_ENDIAN },
3996     { &hf_tn3270_sdp_id, NULL, 1, NULL, ENC_BIG_ENDIAN },
3997     { NULL, NULL, 0, NULL, 0 }
3998   };
3999
4000   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
4001                                 fields);
4002
4003   sdp = tvb_get_guint8(tvb, offset+1);
4004   if (sdp == 0x01) { /*Early Print Complete*/
4005     offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
4006                                   fields2);
4007     proto_tree_add_item(tn3270_tree, hf_tn3270_spc_epc_flags, tvb, offset,
4008                         1, ENC_BIG_ENDIAN);
4009     offset += 1;
4010   }
4011
4012   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
4013
4014   return (offset - start);
4015 }
4016
4017 /* 6.47 - Query Reply (Storage Pools) */
4018 static gint
4019 dissect_query_reply_storage_pools(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
4020                                   gint sf_body_length)
4021 {
4022   gint start = offset, sdp, i;
4023
4024   static const hf_items fields2[] = {
4025     { &hf_tn3270_sdp_ln,   NULL, 1, NULL, ENC_BIG_ENDIAN },
4026     { &hf_tn3270_sdp_id,   NULL, 1, NULL, ENC_BIG_ENDIAN },
4027     { &hf_tn3270_sp_spid,  NULL, 1, NULL, ENC_BIG_ENDIAN },
4028     { &hf_tn3270_sp_size,  NULL, 4, NULL, ENC_BIG_ENDIAN },
4029     { &hf_tn3270_sp_space, NULL, 4, NULL, ENC_BIG_ENDIAN },
4030     { NULL, NULL, 0, NULL, 0 }
4031   };
4032
4033   sdp = tvb_get_guint8(tvb, offset+1);
4034   if (sdp == 0x01) { /* Storage Pool Characteristics */
4035     offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
4036                                   fields2);
4037     for (i=0; i < (sf_body_length-(offset-start)); i+=2) {
4038       proto_tree_add_item(tn3270_tree, hf_tn3270_sp_objlist,
4039                           tvb, offset, 2, ENC_BIG_ENDIAN);
4040       offset += 2;
4041     }
4042   }
4043
4044   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
4045
4046   return (offset - start);
4047 }
4048
4049 /* 6.48 - Query Reply (Summary) */
4050 static gint
4051 dissect_query_reply_summary(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
4052                             gint sf_body_length)
4053 {
4054   gint i;
4055   gint datalen          = 0;
4056   gint length_remaining = tvb_reported_length_remaining(tvb, offset);
4057
4058   for (i=0; i < sf_body_length; i++) {
4059     if (datalen >= length_remaining) {
4060       return (datalen);
4061     }
4062     proto_tree_add_item(tn3270_tree,
4063                         hf_tn3270_sf_query_reply,
4064                         tvb, offset + datalen,
4065                         1,
4066                         ENC_BIG_ENDIAN);
4067     datalen += 1;
4068   }
4069   datalen += dissect_unknown_data(tn3270_tree, tvb, offset+datalen, offset, sf_body_length);
4070
4071   return (datalen);
4072 }
4073
4074 /* 6.49 - Query Reply (Text Partitions) */
4075 static gint
4076 dissect_query_reply_text_partitions(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
4077                                     gint sf_body_length)
4078 {
4079   gint start = offset, len, i;
4080
4081   static const hf_items fields[] = {
4082     { &hf_tn3270_tp_nt,    NULL, 1, NULL, ENC_BIG_ENDIAN },
4083     { &hf_tn3270_tp_m,     NULL, 2, NULL, ENC_BIG_ENDIAN },
4084     { &hf_tn3270_tp_flags, NULL, 1, NULL, ENC_BIG_ENDIAN },
4085     { NULL, NULL, 0, NULL, 0 }
4086   };
4087
4088   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
4089                                 fields);
4090
4091   len = tvb_get_guint8(tvb, offset);
4092   proto_tree_add_item(tn3270_tree, hf_tn3270_tp_ntt, tvb, offset, 1, ENC_BIG_ENDIAN);
4093   offset += 1;
4094
4095   for (i=0; i < len; i++) {
4096     proto_tree_add_item(tn3270_tree, hf_tn3270_tp_tlist,
4097                         tvb, offset, 1, ENC_BIG_ENDIAN);
4098     offset += 1;
4099   }
4100
4101   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
4102
4103   return (offset - start);
4104 }
4105
4106 /* 6.50 - Query Reply (Transparency) */
4107 static gint
4108 dissect_query_reply_transparency(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
4109                                  gint sf_body_length)
4110 {
4111   gint start = offset, i, len;
4112
4113   len = tvb_get_guint8(tvb, offset);
4114   proto_tree_add_item(tn3270_tree, hf_tn3270_t_np, tvb, offset, 1, ENC_BIG_ENDIAN);
4115   offset += 1;
4116
4117   for (i=0; i < len; i+=2) {
4118     proto_tree_add_item(tn3270_tree, hf_tn3270_t_vi,
4119                         tvb, offset, 1, ENC_BIG_ENDIAN);
4120     offset += 1;
4121     proto_tree_add_item(tn3270_tree, hf_tn3270_t_ai,
4122                         tvb, offset, 1, ENC_BIG_ENDIAN);
4123     offset += 1;
4124   }
4125
4126   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
4127
4128   return (offset - start);
4129 }
4130
4131 /* 6.51 - Query Reply Usable Area */
4132 static gint
4133 dissect_query_reply_usable_area(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
4134                                 gint sf_body_length)
4135 {
4136   gint start = offset;
4137   gint vcp;
4138
4139   static const gint *byte1[] = {
4140     &hf_tn3270_ua_reserved1,
4141     &hf_tn3270_ua_page_printer,
4142     &hf_tn3270_ua_reserved2,
4143     &hf_tn3270_ua_hard_copy,
4144     &hf_tn3270_ua_addressing,
4145     NULL
4146   };
4147
4148   static const gint *byte2[] = {
4149     &hf_tn3270_ua_variable_cells,
4150     &hf_tn3270_ua_characters,
4151     &hf_tn3270_ua_cell_units,
4152     NULL
4153   };
4154
4155   static const hf_items fields[] = {
4156     { &hf_tn3270_usable_area_flags1,   &ett_tn3270_usable_area_flags1, 1, byte1, 0 },
4157     { &hf_tn3270_usable_area_flags2,   &ett_tn3270_usable_area_flags1, 1, byte2, 0 },
4158     { &hf_tn3270_ua_width_cells_pels,  NULL, 2, NULL, ENC_BIG_ENDIAN },
4159     { &hf_tn3270_ua_height_cells_pels, NULL, 2, NULL, ENC_BIG_ENDIAN },
4160     { &hf_tn3270_ua_uom_cells_pels,    NULL, 1, NULL, ENC_BIG_ENDIAN },
4161     { &hf_tn3270_ua_xr,                NULL, 4, NULL, ENC_BIG_ENDIAN },
4162     { &hf_tn3270_ua_yr,                NULL, 4, NULL, ENC_BIG_ENDIAN },
4163     { &hf_tn3270_ua_aw,                NULL, 1, NULL, ENC_BIG_ENDIAN },
4164     { &hf_tn3270_ua_ah,                NULL, 1, NULL, ENC_BIG_ENDIAN },
4165     { &hf_tn3270_ua_buffsz,            NULL, 2, NULL, ENC_BIG_ENDIAN },
4166     { NULL, NULL, 0, NULL, 0 }
4167   };
4168
4169   static const hf_items fields2[] = {
4170     { &hf_tn3270_ua_xmin, NULL, 1, NULL, ENC_BIG_ENDIAN },
4171     { &hf_tn3270_ua_ymin, NULL, 1, NULL, ENC_BIG_ENDIAN },
4172     { &hf_tn3270_ua_xmax, NULL, 1, NULL, ENC_BIG_ENDIAN },
4173     { &hf_tn3270_ua_ymax, NULL, 1, NULL, ENC_BIG_ENDIAN },
4174     { NULL, NULL, 0, NULL, 0 }
4175   };
4176
4177   vcp = tvb_get_guint8(tvb, offset+1);
4178
4179   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
4180                                 fields);
4181
4182   if ((vcp & QR_UA_VARIABLE_CELLS) != 0) {
4183     offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
4184                                   fields2);
4185   }
4186
4187   /*TODO: self defining parms */
4188   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
4189
4190   return (offset - start);
4191 }
4192
4193 /* 6.52 - Query Reply 3270 IPDS */
4194 static gint
4195 dissect_query_reply_3270_ipds(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
4196                               gint sf_body_length)
4197 {
4198   gint start = offset;
4199
4200   static const hf_items fields[] = {
4201     { &hf_tn3270_resbytes,     NULL, 2, NULL, ENC_BIG_ENDIAN },
4202     { &hf_tn3270_3270_tranlim, NULL, 2, NULL, ENC_BIG_ENDIAN },
4203     { NULL, NULL, 0, NULL, 0 }
4204   };
4205
4206   offset += tn3270_add_hf_items(tn3270_tree, tvb, offset,
4207                                 fields);
4208   offset += dissect_unknown_data(tn3270_tree, tvb, offset, start, sf_body_length);
4209
4210   return (offset - start);
4211 }
4212
4213 /* sf_body_length is the total length of the structured field including the sf_len and sf_id fields */
4214 /* call only with valid sf_id */
4215 static gint
4216 process_inbound_structured_field(proto_tree *sf_tree, tvbuff_t *tvb, gint offset,
4217                                  tn3270_conv_info_t *tn3270_info, guint sf_id,  gint sf_body_length)
4218 {
4219   gint start = offset;          /* start of structured field param(s) */
4220
4221   switch (sf_id) {
4222   case SF_IB_EXCEPTION_OR_STATUS:
4223     offset += dissect_exception_or_status(sf_tree, tvb, offset, sf_body_length);
4224     break;
4225   case SF_IB_INBOUND_TEXT_HEADER:
4226     offset += dissect_inbound_text_header(sf_tree, tvb, offset, sf_body_length);
4227     break;
4228   case SF_IB_INBOUND_3270DS:
4229     offset += dissect_inbound_3270ds(sf_tree, tvb, offset, tn3270_info, sf_body_length);
4230     break;
4231   case SF_IB_RECOVERY_DATA:
4232     offset += dissect_recovery_data(sf_tree, tvb, offset, sf_body_length);
4233     break;
4234   case SF_IB_TYPE_1_TEXT_INBOUND:
4235     offset += dissect_type_1_text(sf_tree, tvb, offset, sf_body_length);
4236     break;
4237   case SF_IB_QUERY_REPLY_ALPHANUMERIC_PARTITIONS:
4238     offset += dissect_query_reply_alphanumeric(sf_tree, tvb, offset, sf_body_length);
4239     break;
4240   case SF_IB_QUERY_REPLY_AUXILIARY_DEVICE:
4241   case SF_IB_QUERY_REPLY_BEGIN_OR_END_OF_FILE:
4242     offset += dissect_query_reply_resbytes(sf_tree, tvb, offset, sf_body_length);
4243     break;
4244   case SF_IB_QUERY_REPLY_CHARACTER_SETS:
4245     offset += dissect_query_reply_character_sets(sf_tree, tvb, offset, sf_body_length);
4246     break;
4247   case SF_IB_QUERY_REPLY_COLOR:
4248     offset += dissect_query_reply_color(sf_tree, tvb, offset, sf_body_length);
4249     break;
4250   case SF_IB_QUERY_REPLY_COOPERATIVE_PROCESSING_REQUESTOR:
4251     offset += dissect_query_reply_cooperative(sf_tree, tvb, offset, sf_body_length);
4252     break;
4253   case SF_IB_QUERY_REPLY_DATA_CHAINING:
4254     offset += dissect_query_reply_data_chaining(sf_tree, tvb, offset, sf_body_length);
4255     break;
4256   case SF_IB_QUERY_REPLY_DATA_STREAMS:
4257     offset += dissect_query_reply_data_streams(sf_tree, tvb, offset, sf_body_length);
4258     break;
4259   case SF_IB_QUERY_REPLY_DBCS_ASIA:
4260     offset += dissect_query_reply_dbcs_asia(sf_tree, tvb, offset, sf_body_length);
4261     break;
4262   case SF_IB_QUERY_REPLY_DEVICE_CHARACTERISTICS:
4263     /*TODO: implement this beast */
4264     offset += dissect_query_reply_device_characteristics(sf_tree, tvb, offset, sf_body_length);
4265     break;
4266   case SF_IB_QUERY_REPLY_SUMMARY:
4267     offset += dissect_query_reply_summary(sf_tree, tvb, offset, sf_body_length);
4268     break;
4269   case SF_IB_QUERY_REPLY_USABLE_AREA:
4270     offset += dissect_query_reply_usable_area(sf_tree, tvb, offset, sf_body_length);
4271     break;
4272   case SF_IB_QUERY_REPLY_HIGHLIGHTING:
4273     offset += dissect_query_reply_highlighting(sf_tree, tvb, offset, sf_body_length);
4274     break;
4275   case SF_IB_QUERY_REPLY_REPLY_MODES:
4276     offset += dissect_query_reply_modes(sf_tree, tvb, offset, sf_body_length);
4277     break;
4278   case SF_IB_QUERY_REPLY_DISTRIBUTED_DATA_MANAGEMENT:
4279     offset += dissect_query_reply_distributed_data_management(sf_tree, tvb, offset, sf_body_length);
4280     break;
4281   case SF_IB_QUERY_REPLY_RPQ_NAMES:
4282     offset += dissect_query_reply_rpq_names(sf_tree, tvb, offset, sf_body_length);
4283     break;
4284   case SF_IB_QUERY_REPLY_IMPLICIT_PARTITION:
4285     offset += dissect_query_reply_implicit_partitions(sf_tree, tvb, offset, sf_body_length);
4286     break;
4287   case SF_IB_QUERY_REPLY_OEM_AUXILIARY_DEVICE:
4288     offset += dissect_query_reply_oem_auxiliary_device(sf_tree, tvb, offset, sf_body_length);
4289     break;
4290   case SF_IB_QUERY_REPLY_DOCUMENT_INTERCHANGE_ARCHITECTURE:
4291     offset += dissect_query_reply_document_interchange_architecture(sf_tree, tvb, offset, sf_body_length);
4292     break;
4293   case SF_IB_QUERY_REPLY_EXTENDED_DRAWING_ROUTINE:
4294     offset += dissect_query_reply_extended_drawing_routine(sf_tree, tvb, offset, sf_body_length);
4295     break;
4296   case SF_IB_QUERY_REPLY_FIELD_OUTLINING:
4297     offset += dissect_query_reply_field_outlining(sf_tree, tvb, offset, sf_body_length);
4298     break;
4299   case SF_IB_QUERY_REPLY_FIELD_VALIDATION:
4300     offset += dissect_3270_field_validation(sf_tree, tvb, offset);
4301     break;
4302   case SF_IB_QUERY_REPLY_FORMAT_STORAGE_AUXILIARY_DEVICE:
4303     offset += dissect_query_reply_format_storage_aux_device(sf_tree, tvb, offset, sf_body_length);
4304     break;
4305   case SF_IB_QUERY_REPLY_GRAPHIC_COLOR:
4306   case SF_IB_QUERY_REPLY_GRAPHIC_SYMBOL_SETS:
4307   case SF_IB_QUERY_REPLY_IMAGE:
4308   case SF_IB_QUERY_REPLY_LINE_TYPE:
4309   case SF_IB_QUERY_REPLY_PROCEDURE:
4310   case SF_IB_QUERY_REPLY_SEGMENT:
4311     /* Not an error - just has a data field like 'extended drawing'*/
4312     offset += dissect_query_reply_extended_drawing_routine(sf_tree, tvb, offset, sf_body_length);
4313     break;
4314   case SF_IB_QUERY_REPLY_IBM_AUXILIARY_DEVICE:
4315     offset += dissect_query_reply_ibm_aux_device(sf_tree, tvb, offset, sf_body_length);
4316     break;
4317   case SF_IB_QUERY_REPLY_IOCA_AUXILIARY_DEVICE:
4318     offset += dissect_query_reply_ioca_aux_device(sf_tree, tvb, offset, sf_body_length);
4319     break;
4320   case SF_IB_QUERY_REPLY_MSR_CONTROL:
4321     offset += dissect_query_reply_msr_control(sf_tree, tvb, offset, sf_body_length);
4322     break;
4323   case SF_IB_QUERY_REPLY_FORMAT_PRESENTATION:
4324   case SF_IB_QUERY_REPLY_NULL:
4325   case SF_IB_QUERY_REPLY_PORT:
4326     /* This field is always empty */
4327     break;
4328   case SF_IB_QUERY_REPLY_PAPER_FEED_TECHNIQUES:
4329     offset += dissect_query_reply_paper_feed_techniques(sf_tree, tvb, offset, sf_body_length);
4330     break;
4331   case SF_IB_QUERY_REPLY_PARTITION_CHARACTERISTICS:
4332     offset += dissect_query_reply_partition_characteristics(sf_tree, tvb, offset, sf_body_length);
4333     break;
4334   case SF_IB_QUERY_REPLY_PRODUCT_DEFINED_DATA_STREAM:
4335     offset += dissect_query_reply_product_defined_data_stream(sf_tree, tvb, offset, sf_body_length);
4336     break;
4337   case SF_IB_QUERY_REPLY_SAVE_OR_RESTORE_FORMAT:
4338     offset += dissect_query_reply_save_or_restore_format(sf_tree, tvb, offset, sf_body_length);
4339     break;
4340   case SF_IB_QUERY_REPLY_SETTABLE_PRINTER_CHARACTERISTICS:
4341     offset += dissect_query_reply_settable_printer_characteristics(sf_tree, tvb, offset, sf_body_length);
4342     break;
4343   case SF_IB_QUERY_REPLY_STORAGE_POOLS:
4344     offset += dissect_query_reply_storage_pools(sf_tree, tvb, offset, sf_body_length);
4345     break;
4346   case SF_IB_QUERY_REPLY_TEXT_PARTITIONS:
4347     offset += dissect_query_reply_text_partitions(sf_tree, tvb, offset, sf_body_length);
4348     break;
4349   case SF_IB_QUERY_REPLY_TRANSPARENCY:
4350     offset += dissect_query_reply_transparency(sf_tree, tvb, offset, sf_body_length);
4351     break;
4352   case SF_IB_QUERY_REPLY_3270_IPDS:
4353     offset += dissect_query_reply_3270_ipds(sf_tree, tvb, offset, sf_body_length);
4354     break;
4355   default:
4356     DISSECTOR_ASSERT_NOT_REACHED();
4357     break;
4358   }
4359
4360   return (offset - start);
4361 }
4362
4363
4364 /* sf_body_length is the total length of the structured field including the sf_len and sf_id fields */
4365 /* call only with valid sf_id */
4366 static gint
4367 process_outbound_structured_field(proto_tree *sf_tree, packet_info *pinfo, tvbuff_t *tvb, gint offset,
4368                                   tn3270_conv_info_t *tn3270_info, guint sf_id, gint sf_body_length)
4369 {
4370   gint start = offset;          /* start of structured field param(s) */
4371
4372   switch (sf_id) {
4373     case SF_OB_READ_PARTITION:
4374       offset += dissect_read_partition(sf_tree, tvb, offset, sf_body_length);
4375       break;
4376     case SF_OB_ACTIVATE_PARTITION:
4377     case SF_OB_DESTROY_PARTITION:
4378     case SF_OB_RESET_PARTITION:
4379       proto_tree_add_item(sf_tree,
4380                           hf_tn3270_partition_id,
4381                           tvb, offset,
4382                           1,
4383                           ENC_BIG_ENDIAN);
4384       offset += 1;
4385       break;
4386     case SF_OB_CREATE_PARTITION:
4387       offset += dissect_create_partition(sf_tree, tvb, offset, sf_body_length);
4388       break;
4389     case SF_OB_ERASE_OR_RESET:
4390       /* Bit 0: 0= Use default screen size; 1= use alternate screen size     */
4391       /* XXX: Not really valid: See comment under dissect_outbound_stream(). */
4392       if ((tvb_get_guint8(tvb, offset) & 0x80) != 0) {
4393         tn3270_info->rows = tn3270_info->altrows;
4394         tn3270_info->cols = tn3270_info->altcols;
4395       }
4396       else {
4397         tn3270_info->rows = 24;
4398         tn3270_info->cols = 80;
4399       }
4400       proto_tree_add_bits_item(sf_tree,
4401                                hf_tn3270_erase_flags,
4402                                tvb, offset<<3,
4403                                1,
4404                                ENC_BIG_ENDIAN);
4405       offset += 1;
4406       break;
4407     case SF_OB_LOAD_PROGRAMMED_SYMBOLS:
4408       offset += dissect_load_programmed_symbols(sf_tree, tvb, offset, sf_body_length);
4409       break;
4410     case SF_OB_OUTBOUND_3270DS:
4411       offset += dissect_outbound_3270ds(sf_tree, pinfo, tvb, offset, tn3270_info, sf_body_length);
4412       break;
4413     case SF_OB_PRESENT_ABSOLUTE_FORMAT:
4414       offset += dissect_present_absolute_format(sf_tree, tvb, offset, sf_body_length);
4415       break;
4416     case SF_OB_PRESENT_RELATIVE_FORMAT:
4417       offset += dissect_present_relative_format(sf_tree, tvb, offset, sf_body_length);
4418       break;
4419     case SF_OB_SCS_DATA:
4420       proto_tree_add_item(sf_tree,
4421                           hf_tn3270_partition_id,
4422                           tvb, offset,
4423                           1,
4424                           ENC_BIG_ENDIAN);
4425       offset += 1;
4426       proto_tree_add_item(sf_tree,
4427                           hf_tn3270_scs_data,
4428                           tvb, offset,
4429                           (sf_body_length - (offset - start)),
4430                           ENC_NA);
4431       offset += (sf_body_length - (offset - start));
4432       break;
4433     case SF_OB_SET_REPLY_MODE:
4434       offset += dissect_set_reply_mode(sf_tree, tvb, offset, sf_body_length);
4435       break;
4436     case SF_OB_SELECT_FORMAT_GROUP:
4437       proto_tree_add_item(sf_tree,
4438                           hf_tn3270_partition_id,
4439                           tvb, offset,
4440                           1,
4441                           ENC_BIG_ENDIAN);
4442       offset += 1;
4443       proto_tree_add_item(sf_tree,
4444                           hf_tn3270_format_group,
4445                           tvb, offset,
4446                           (sf_body_length - (offset - start)),
4447                           ENC_EBCDIC|ENC_NA);
4448       offset += (sf_body_length - (offset - start));
4449       break;
4450     case SF_OB_SET_WINDOW_ORIGIN:
4451       proto_tree_add_item(sf_tree,
4452                           hf_tn3270_partition_id,
4453                           tvb, offset,
4454                           1,
4455                           ENC_BIG_ENDIAN);
4456       offset += 1;
4457       proto_tree_add_item(sf_tree,
4458                           hf_tn3270_partition_rw,
4459                           tvb, offset,
4460                           2,
4461                           ENC_BIG_ENDIAN);
4462       offset += 2;
4463       proto_tree_add_item(sf_tree,
4464                           hf_tn3270_partition_cw,
4465                           tvb, offset,
4466                           2,
4467                           ENC_BIG_ENDIAN);
4468       offset += 2;
4469       break;
4470     case SF_OB_BEGIN_OR_END_OF_FILE:
4471       proto_tree_add_item(sf_tree,
4472                           hf_tn3270_partition_id,
4473                           tvb, offset,
4474                           1,
4475                           ENC_BIG_ENDIAN);
4476       offset += 1;
4477       /*TODO: use bits_text */
4478       proto_tree_add_bits_item(sf_tree,
4479                                hf_tn3270_begin_end_flags1,
4480                                tvb, offset<<3,
4481                                2,
4482                                ENC_BIG_ENDIAN);
4483       offset += 1;
4484       proto_tree_add_item(sf_tree,
4485                           hf_tn3270_begin_end_flags2,
4486                           tvb, offset,
4487                           1,
4488                           ENC_BIG_ENDIAN);
4489       offset += 1;
4490       break;
4491     case SF_OB_LOAD_COLOR_TABLE:
4492       /* Refer to related graphics docs !*/
4493       proto_tree_add_item(sf_tree,
4494                           hf_tn3270_load_color_command,
4495                           tvb, offset,
4496                           sf_body_length,
4497                           ENC_NA);
4498       offset += sf_body_length;
4499       break;
4500     case SF_OB_LOAD_FORMAT_STORAGE:
4501       offset += dissect_load_format_storage(sf_tree, tvb, offset, sf_body_length);
4502       break;
4503     case SF_OB_LOAD_LINE_TYPE:
4504       /* Refer to related graphics docs !*/
4505       proto_tree_add_item(sf_tree,
4506                           hf_tn3270_load_line_type_command,
4507                           tvb, offset,
4508                           sf_body_length,
4509                           ENC_NA);
4510       offset += sf_body_length;
4511       break;
4512     case SF_OB_MODIFY_PARTITION:
4513       offset += dissect_modify_partition(sf_tree, tvb, offset, sf_body_length);
4514       break;
4515     case SF_OB_OUTBOUND_TEXT_HEADER:
4516       offset += dissect_outbound_text_header(sf_tree, tvb, offset, sf_body_length);
4517       break;
4518     case SF_OB_REQUEST_RECOVERY_DATA:
4519       proto_tree_add_item(sf_tree,
4520                           hf_tn3270_resbyte,
4521                           tvb, offset,
4522                           1,
4523                           ENC_BIG_ENDIAN);
4524       offset += 1;
4525       break;
4526     case SF_OB_RESTART:
4527       offset += dissect_restart(sf_tree, tvb, offset, sf_body_length);
4528       break;
4529     case SF_OB_SELECT_COLOR_TABLE:
4530       proto_tree_add_item(sf_tree,
4531                           hf_tn3270_color_command,
4532                           tvb, offset,
4533                           2,
4534                           ENC_BIG_ENDIAN);
4535       offset += 2;
4536       break;
4537     case SF_OB_SET_CHECKPOINT_INTERVAL:
4538       proto_tree_add_item(sf_tree,
4539                           hf_tn3270_resbyte,
4540                           tvb, offset,
4541                           1,
4542                           ENC_BIG_ENDIAN);
4543       offset += 1;
4544       proto_tree_add_item(sf_tree,
4545                           hf_tn3270_interval,
4546                           tvb, offset,
4547                           2,
4548                           ENC_BIG_ENDIAN);
4549       offset += 2;
4550       break;
4551     case SF_OB_SET_MSR_CONTROL:
4552       offset += dissect_set_msr_control(sf_tree, tvb, offset, sf_body_length);
4553       break;
4554     case SF_OB_SET_PARTITION_CHARACTERISTICS:
4555       offset += dissect_set_partition_characteristics(sf_tree, tvb, offset, sf_body_length);
4556       break;
4557     case SF_OB_SET_PRINTER_CHARACTERISTICS:
4558       offset += dissect_set_printer_characteristics(sf_tree, tvb, offset, sf_body_length);
4559       break;
4560     case SF_OB_TYPE_1_TEXT_OUTBOUND:
4561       offset += dissect_type_1_text(sf_tree, tvb, offset, sf_body_length);
4562       break;
4563     default:
4564       DISSECTOR_ASSERT_NOT_REACHED();
4565       break;
4566   }
4567
4568   return (offset - start);
4569 }
4570
4571 /* sf_body_length is the total length of the structured field including the sf_len and sf_id fields */
4572 /* call only with valid sf_id */
4573 static gint
4574 process_outbound_inbound_structured_field(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
4575                                            tn3270_conv_info_t *tn3270_info _U_, guint sf_id, gint sf_body_length)
4576 {
4577   gint start = offset;
4578
4579   switch (sf_id) {
4580     case SF_OB_IB_DATA_CHAIN:
4581       offset += dissect_data_chain(tn3270_tree, tvb, offset, sf_body_length);
4582       break;
4583     case SF_OB_IB_DESTINATION_OR_ORIGIN:
4584       proto_tree_add_item(tn3270_tree,
4585                                hf_tn3270_destination_or_origin_flags_input_control,
4586                                tvb, offset,
4587                                1,
4588                                ENC_BIG_ENDIAN);
4589       offset += 1;
4590       proto_tree_add_item(tn3270_tree,
4591                           hf_tn3270_resbyte,
4592                           tvb, offset,
4593                           1,
4594                           ENC_BIG_ENDIAN);
4595       offset += 1;
4596       proto_tree_add_item(tn3270_tree,
4597                           hf_tn3270_destination_or_origin_doid,
4598                           tvb, offset,
4599                           2,
4600                           ENC_BIG_ENDIAN);
4601       offset += 2;
4602       break;
4603     case SF_OB_IB_OBJECT_DATA:
4604     case SF_OB_IB_OBJECT_CONTROL:
4605     case SF_OB_IB_OBJECT_PICTURE:
4606     case SF_OB_IB_OEM_DATA: /* FIXME: Not really but same layout */
4607       offset += dissect_object_control(tn3270_tree, tvb, offset, sf_body_length);
4608       break;
4609     case SF_OB_IB_SAVE_OR_RESTORE_FORMAT:
4610       offset += dissect_save_or_restore_format(tn3270_tree, tvb, offset, sf_body_length);
4611       break;
4612     case SF_OB_IB_SELECT_IPDS_MODE:
4613       proto_tree_add_item(tn3270_tree,
4614                           hf_tn3270_resbytes,
4615                           tvb, offset,
4616                           2,
4617                           ENC_BIG_ENDIAN);
4618       offset += 2;
4619       break;
4620     default:
4621       DISSECTOR_ASSERT_NOT_REACHED();
4622       break;
4623   }
4624
4625   return (offset - start);
4626 }
4627
4628 static proto_tree *
4629 display_sf_hdr(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
4630                    gint sf_length, guint sf_id, guint sf_id_len, const gchar *sf_id_str)
4631 {
4632   proto_tree *sf_tree;
4633
4634   sf_tree = proto_tree_add_subtree_format(tn3270_tree, tvb, offset, sf_length,
4635                            ett_sf, NULL, "Structured Field: %s", sf_id_str);
4636
4637   proto_tree_add_item(sf_tree,
4638                       hf_tn3270_sf_length,
4639                       tvb, offset,
4640                       2,
4641                       ENC_BIG_ENDIAN);
4642
4643   proto_tree_add_uint_format_value(sf_tree,
4644                                    (sf_id_len == 1) ? hf_tn3270_sf_single_byte_id : hf_tn3270_sf_double_byte_id,
4645                                    tvb, offset+2, sf_id_len,
4646                                    sf_id, "%s (0x%0*x)", sf_id_str, sf_id_len*2, sf_id);
4647
4648   return sf_tree;
4649 }
4650
4651 static gint
4652 dissect_structured_fields(proto_tree *tn3270_tree, packet_info *pinfo, tvbuff_t *tvb, gint offset,
4653                           tn3270_conv_info_t *tn3270_info, gboolean direction_inbound)
4654 {
4655   proto_tree  *sf_tree;
4656   gint         start;
4657   gint         sf_length;
4658   guint        sf_id;
4659   guint        sf_id_len;
4660   const gchar *sf_id_str;
4661
4662   start = offset;
4663
4664   while (tvb_reported_length_remaining(tvb, offset) >= 2) {
4665
4666     /* Handle NULL bytes until we find a length value */
4667     /* XXX: An earlier version of the code for structured field    */
4668     /*      processing did this check only for inbound structured  */
4669     /*      fields. Should the same be done in this code which     */
4670     /*      combines handling for both inbound and outbound        */
4671     /*      structured fields ?                                    */
4672     if ((sf_length = tvb_get_ntohs(tvb, offset)) == 0) {
4673       proto_tree_add_item(tn3270_tree,
4674                           hf_tn3270_null,
4675                           tvb, offset,
4676                           1,
4677                           ENC_BIG_ENDIAN);
4678       offset += 1;
4679       continue;
4680     }
4681
4682     sf_id     = tvb_get_guint8(tvb, offset+2);
4683     sf_id_len = 1;
4684     if ((sf_id == 0x0F) ||
4685         (sf_id == 0x10) ||
4686         (sf_id == 0x81)) {
4687       sf_id = (sf_id << 8) + tvb_get_guint8(tvb, offset+3);
4688       sf_id_len = 2;
4689     }
4690
4691     sf_id_str = try_val_to_str(sf_id, direction_inbound ?
4692                              vals_inbound_structured_fields : vals_outbound_structured_fields);
4693     if (sf_id_str != NULL) {
4694       sf_tree = display_sf_hdr(tn3270_tree, tvb, offset,
4695                                sf_length, sf_id, sf_id_len, sf_id_str);
4696       offset += (sf_id_len + 2);
4697       if (direction_inbound) {
4698         offset += process_inbound_structured_field(sf_tree, tvb, offset, tn3270_info, sf_id, sf_length-2-sf_id_len);
4699       }
4700       else {
4701         offset += process_outbound_structured_field(sf_tree, pinfo, tvb, offset, tn3270_info, sf_id, sf_length-2-sf_id_len);
4702       }
4703       continue;
4704     }
4705
4706     /* Not found above: See if an "outbound-inbound" field */
4707     sf_id_str = try_val_to_str(sf_id, vals_outbound_inbound_structured_fields);
4708     if (sf_id_str != NULL) {
4709       sf_tree = display_sf_hdr(tn3270_tree, tvb, offset,
4710                                sf_length, sf_id, sf_id_len, sf_id_str);
4711       offset += (sf_id_len + 2);
4712       offset += process_outbound_inbound_structured_field(sf_tree, tvb, offset, tn3270_info, sf_id, sf_length-2-sf_id_len);
4713       continue;
4714     }
4715
4716     /* Not found */
4717     sf_id_str = wmem_strdup_printf(wmem_packet_scope(), "Unknown [%0*x]", sf_id_len*2, sf_id);
4718     display_sf_hdr(tn3270_tree, tvb, offset, sf_length,
4719                    sf_length, sf_id_len, sf_id_str);
4720     offset += sf_length;
4721   } /* while */
4722
4723   return (offset - start);
4724 }
4725
4726
4727 /* Start: Handle WCC, Orders and Data */
4728
4729 static gint
4730 dissect_stop_address(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
4731 {
4732   gint start = offset;
4733   gint is_oc_ge;
4734
4735   proto_tree_add_item(tn3270_tree,
4736                       hf_tn3270_stop_address,
4737                       tvb, offset,
4738                       2,
4739                       ENC_BIG_ENDIAN);
4740   offset += 1;
4741   is_oc_ge = tvb_get_guint8(tvb, offset);
4742   if (is_oc_ge != OC_GE) {
4743     proto_tree_add_item(tn3270_tree,
4744                         hf_tn3270_character_code,
4745                         tvb, offset,
4746                         1,
4747                         ENC_BIG_ENDIAN);
4748     offset += 1;
4749   }
4750
4751   return (offset - start);
4752 }
4753
4754 /*
4755  * From section "4.3.3 Set Buffer Address (SBA)" of the IBM document
4756  * cited above.
4757  */
4758
4759 /*
4760  * Address format.
4761  *
4762  * XXX - what about 16-bit addressing?
4763  */
4764 #define SBA_ADDRESS_FORMAT_MASK 0xC000
4765 #define SBA_ADDRESS_MASK_SHIFT  14
4766 #define SBA_ADDRESS_FORMAT(address)     (((address) & SBA_ADDRESS_FORMAT_MASK) >> SBA_ADDRESS_MASK_SHIFT)
4767
4768 #define SBA_ADDRESS_VALUE_MASK  0x3FFF
4769 #define SBA_ADDRESS_VALUE(address)      ((address) & SBA_ADDRESS_VALUE_MASK)
4770
4771 #define SBA_14_BIT_BINARY       0x0
4772 #define SBA_12_BIT_CODED_1      0x1
4773 #define SBA_RESERVED            0x2
4774 #define SBA_12_BIT_CODED_2      0x3
4775
4776 static gint
4777 dissect_buffer_address(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset, gint hf, tn3270_conv_info_t *tn3270_info)
4778 {
4779   gint    start = offset;
4780   guint16 buffer_addr;
4781   guint16 address_format, address_value;
4782   guint8  b1, b2;
4783   guint8  rowsx = tn3270_info->rows;
4784   guint8  colsx = tn3270_info->cols;
4785
4786   buffer_addr    = tvb_get_ntohs(tvb, offset);
4787   address_format = SBA_ADDRESS_FORMAT(buffer_addr);
4788   address_value  = SBA_ADDRESS_VALUE(buffer_addr);
4789
4790   /*
4791    * XXX - put the address format and address value into the protocol
4792    * tree as bitfields under these items?
4793    */
4794   switch (address_format) {
4795
4796     case SBA_14_BIT_BINARY:
4797       proto_tree_add_uint_format_value(tn3270_tree,
4798                                        hf,
4799                                        tvb, offset, 2,
4800                                        buffer_addr,
4801                                        "14-bit address, %u = row %u, column %u [assuming a %ux%u display] (0x%04x)",
4802                                        address_value,
4803                                        (address_value / colsx) + 1,
4804                                        (address_value % colsx) + 1,
4805                                        rowsx, colsx,
4806                                        buffer_addr);
4807       break;
4808
4809     case SBA_12_BIT_CODED_1:
4810     case SBA_12_BIT_CODED_2:
4811       /*
4812        * This is a wacky encoding.  At least as I read the IBM document
4813        * in question, the lower 6 bits of the first byte of the SBA
4814        * address, and the lower 6 bits of the second byte of the SBA
4815        * address, are combined into a 12-bit binary address.  The upper
4816        * 2 bits of the first byte are the address format; the upper 2
4817        * bits of the second byte are ignored.
4818        */
4819       b1 = (address_value >> 8) & 0x3F;
4820       b2 = (address_value >> 0) & 0x3F;
4821       address_value = (b1 << 6) | b2;
4822       proto_tree_add_uint_format_value(tn3270_tree,
4823                                        hf,
4824                                        tvb, offset, 2,
4825                                        buffer_addr,
4826                                        "12-bit address, %u = row %u, column %u [assuming a %ux%u display] (0x%04x)",
4827                                        address_value,
4828                                        (address_value / colsx) + 1,
4829                                        (address_value % colsx) + 1,
4830                                        rowsx, colsx,
4831                                        buffer_addr);
4832       break;
4833
4834     case SBA_RESERVED:
4835       proto_tree_add_uint_format_value(tn3270_tree,
4836                                        hf,
4837                                        tvb, offset, 2,
4838                                        buffer_addr,
4839                                        "Reserved (0x%04x)",
4840                                        buffer_addr);
4841       break;
4842   }
4843   offset += 2;
4844
4845   return (offset - start);
4846 }
4847
4848 static gint
4849 dissect_field_attribute_pair(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
4850 {
4851   gint start = offset;
4852   gint attribute_type;
4853
4854   attribute_type = tvb_get_guint8(tvb, offset);
4855   proto_tree_add_item(tn3270_tree,
4856                       hf_tn3270_attribute_type,
4857                       tvb, offset,
4858                       1,
4859                       ENC_BIG_ENDIAN);
4860   offset += 1;
4861   switch (attribute_type) {
4862     case AT_ALL_CHARACTER_ATTRIBUTES:
4863       proto_tree_add_item(tn3270_tree,
4864                           hf_tn3270_all_character_attributes,
4865                           tvb, offset,
4866                           1,
4867                           ENC_BIG_ENDIAN);
4868       offset += 1;
4869       break;
4870     case AT_T3270_FIELD_ATTRIBUTE:
4871       offset += dissect_3270_field_attribute(tn3270_tree, tvb, offset);
4872       break;
4873     case AT_EXTENDED_HIGHLIGHTING:
4874       proto_tree_add_item(tn3270_tree,
4875                           hf_tn3270_extended_highlighting,
4876                           tvb, offset,
4877                           1,
4878                           ENC_BIG_ENDIAN);
4879       offset += 1;
4880       break;
4881     case AT_FOREGROUND_COLOR:
4882     case AT_BACKGROUND_COLOR:
4883       proto_tree_add_item(tn3270_tree,
4884                           hf_tn3270_color,
4885                           tvb, offset,
4886                           1,
4887                           ENC_BIG_ENDIAN);
4888       offset += 1;
4889       break;
4890     case AT_CHARACTER_SET:
4891       proto_tree_add_item(tn3270_tree,
4892                           hf_tn3270_character_set,
4893                           tvb, offset,
4894                           1,
4895                           ENC_BIG_ENDIAN);
4896       offset += 1;
4897       break;
4898     case AT_FIELD_OUTLINING:
4899       proto_tree_add_item(tn3270_tree,
4900                           hf_tn3270_field_outlining,
4901                           tvb, offset,
4902                           1,
4903                           ENC_BIG_ENDIAN);
4904       offset += 1;
4905       break;
4906     case AT_TRANSPARENCY:
4907       proto_tree_add_item(tn3270_tree,
4908                           hf_tn3270_transparency,
4909                           tvb, offset,
4910                           1,
4911                           ENC_BIG_ENDIAN);
4912       offset += 1;
4913       break;
4914     case AT_FIELD_VALIDATION:
4915       offset += dissect_3270_field_validation(tn3270_tree, tvb, offset);
4916       break;
4917   }
4918
4919   return (offset - start);
4920 }
4921
4922 static gint
4923 dissect_field_attribute_pairs(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
4924 {
4925   gint start = offset;
4926   gint no_of_pairs;
4927   gint i;
4928
4929   no_of_pairs = tvb_get_guint8(tvb, offset);
4930   proto_tree_add_item(tn3270_tree,
4931                       hf_tn3270_number_of_attributes,
4932                       tvb, offset,
4933                       1,
4934                       ENC_BIG_ENDIAN);
4935   offset += 1;
4936
4937   for (i=0; i < no_of_pairs; i++) {
4938     offset += dissect_field_attribute_pair(tn3270_tree, tvb, offset);
4939   }
4940
4941   return (offset - start);
4942 }
4943
4944 static gint
4945 dissect_orders_and_data(proto_tree *tn3270_tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, tn3270_conv_info_t *tn3270_info)
4946 {
4947   gint start = offset;
4948   gint order_code;
4949   proto_item* item;
4950
4951   /* Order Code */
4952
4953   /* XXX: '0' is treated as data; See comment under add_data_until_next_order_code() */
4954   while (tvb_reported_length_remaining(tvb, offset) > 0) {
4955     order_code = tvb_get_guint8(tvb, offset);
4956     if ((order_code > 0) && (order_code <= OC_MAX)) {  /* XXX: also 0xFF ?? */
4957       item = proto_tree_add_item(tn3270_tree,
4958                           hf_tn3270_order_code,
4959                           tvb, offset,
4960                           1,
4961                           ENC_BIG_ENDIAN);
4962       offset += 1;
4963
4964       switch (order_code) {
4965         case OC_SF:
4966           offset += dissect_3270_field_attribute(tn3270_tree, tvb, offset);
4967           break;
4968         case OC_MF:
4969         case OC_SFE:
4970           offset += dissect_field_attribute_pairs(tn3270_tree, tvb, offset);
4971           break;
4972         case OC_SA:
4973           offset += dissect_field_attribute_pair(tn3270_tree, tvb, offset);
4974           break;
4975         case OC_EUA:
4976         case OC_RA:
4977           offset += dissect_stop_address(tn3270_tree, tvb, offset);
4978           break;
4979         case OC_GE:
4980           proto_tree_add_item(tn3270_tree,
4981                               hf_tn3270_character_code,
4982                               tvb, offset,
4983                               1,
4984                               ENC_BIG_ENDIAN);
4985           offset += 1;
4986           break;
4987         case OC_SBA:
4988           offset += dissect_buffer_address(tn3270_tree, tvb, offset, hf_tn3270_buffer_address, tn3270_info);
4989           break;
4990         case OC_PT:   /* XXX: This case was previously commented out; I don't know why */
4991         case OC_IC:
4992           break;
4993         default:
4994           expert_add_info(pinfo, item, &ei_tn3270_order_code);
4995           break;
4996       } /* switch */
4997     }
4998     else {
4999       offset += add_data_until_next_order_code(tn3270_tree, tvb, offset);
5000     }
5001   } /* while */
5002
5003   return (offset - start);
5004 }
5005
5006 /* End: Handle WCC, Orders and Data */
5007
5008
5009 static gint
5010 dissect_tn3270e_header(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
5011 {
5012   proto_item *pi;
5013   proto_tree *tn3270e_hdr_tree;
5014   gint        start = offset;
5015   gint        data_type;
5016
5017   static const hf_items fields[] = {
5018     { &hf_tn3270_tn3270e_data_type,              NULL, 1, NULL, ENC_BIG_ENDIAN },
5019     { &hf_tn3270_tn3270e_request_flag,           NULL, 1, NULL, ENC_BIG_ENDIAN },
5020     { NULL, NULL, 0, NULL, 0 }
5021   };
5022
5023   data_type = tvb_get_guint8(tvb, offset);
5024
5025   tn3270e_hdr_tree = proto_tree_add_subtree_format(tn3270_tree, tvb, offset, -1,
5026                            ett_tn3270e_hdr, &pi, "TN3270E Header (Data Type: %s)",
5027                            val_to_str_const(data_type, vals_tn3270_header_data_types, "Unknown"));
5028
5029   offset += tn3270_add_hf_items(tn3270e_hdr_tree, tvb, offset,
5030                                 fields);
5031   switch(data_type) {
5032     case TN3270E_3270_DATA:
5033     case TN3270E_SCS_DATA:
5034       proto_tree_add_item(tn3270e_hdr_tree, hf_tn3270_tn3270e_response_flag_3270_SCS, tvb, offset, 1, ENC_BIG_ENDIAN);
5035       break;
5036     case TN3270E_RESPONSE:
5037       proto_tree_add_item(tn3270e_hdr_tree, hf_tn3270_tn3270e_response_flag_response, tvb, offset, 1, ENC_BIG_ENDIAN);
5038       break;
5039     case TN3270E_BIND_IMAGE:
5040     case TN3270E_NVT_DATA:
5041     case TN3270E_REQUEST:
5042     case TN3270E_SSCP_LU_DATA:
5043     case TN3270E_UNBIND:
5044     default:
5045       proto_tree_add_item(tn3270e_hdr_tree, hf_tn3270_tn3270e_response_flag_unused, tvb, offset, 1, ENC_BIG_ENDIAN);
5046       break;
5047   }
5048   offset += 1;
5049
5050   proto_tree_add_item(tn3270e_hdr_tree, hf_tn3270_tn3270e_seq_number, tvb, offset, 2, ENC_BIG_ENDIAN);
5051   offset += 2;
5052
5053   switch (data_type) {
5054     case TN3270E_BIND_IMAGE:
5055     case TN3270E_NVT_DATA:
5056     case TN3270E_REQUEST:
5057     case TN3270E_RESPONSE:
5058     case TN3270E_SCS_DATA:
5059     case TN3270E_SSCP_LU_DATA:
5060     case TN3270E_UNBIND:
5061       proto_tree_add_item(tn3270e_hdr_tree, hf_tn3270_tn3270e_header_data, tvb, offset, -1, ENC_EBCDIC|ENC_NA);
5062       offset += tvb_reported_length_remaining(tvb, offset);
5063       break;
5064     default:
5065       break;
5066   }
5067
5068   proto_item_set_len(pi, offset - start);
5069
5070   return (offset - start);
5071 }
5072
5073 /* Detect and Handle Direction of Stream */
5074 static gint
5075 dissect_outbound_stream(proto_tree *tn3270_tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, tn3270_conv_info_t *tn3270_info)
5076 {
5077   gint command_code;
5078   gint start = offset;
5079   proto_item* item;
5080
5081   /* Command Code*/
5082   command_code = tvb_get_guint8(tvb, offset);
5083
5084   /* XXX: Storing rows/cols each time they change is not valid         */
5085   /*      since packets can (will be) randomly selected for dissection */
5086   /*      after the initial dissection pass. In actuality screen size  */
5087   /*      "state" needs to be associated in some manner with each      */
5088   /*      frame of a conversation.                                     */
5089   switch (command_code) {
5090     case CC_LCL_EW:
5091     case CC_RMT_EW:
5092       tn3270_info->rows = 24;
5093       tn3270_info->cols = 80;
5094       break;
5095     case CC_LCL_EWA:
5096     case CC_RMT_EWA:
5097       tn3270_info->rows = tn3270_info->altrows;
5098       tn3270_info->cols = tn3270_info->altcols;
5099       break;
5100     default:
5101       break;
5102   }
5103
5104   item = proto_tree_add_item(tn3270_tree,
5105                         hf_tn3270_command_code,
5106                         tvb, offset,
5107                         1,
5108                         ENC_BIG_ENDIAN);
5109   offset += 1;
5110
5111   switch (command_code) {
5112     case CC_LCL_W:
5113     case CC_LCL_EW:
5114     case CC_LCL_EWA:
5115     case CC_LCL_EAU:
5116     case CC_RMT_W:
5117     case CC_RMT_EW:
5118     case CC_RMT_EWA:
5119     case CC_RMT_EAU:
5120       /* WCC */
5121       offset += dissect_wcc(tn3270_tree, tvb, offset);
5122       offset += dissect_orders_and_data(tn3270_tree, pinfo, tvb, offset, tn3270_info);
5123       break;
5124     case CC_LCL_WSF:
5125     case CC_RMT_WSF:
5126       offset += dissect_structured_fields(tn3270_tree, pinfo, tvb, offset, tn3270_info, FALSE);
5127       break;
5128     case CC_LCL_RB:
5129     case CC_LCL_RM:
5130     case CC_LCL_RMA:
5131     case CC_RMT_RB:
5132     case CC_RMT_RM:
5133     case CC_RMT_RMA:
5134       break;
5135     default:
5136       expert_add_info(pinfo, item, &ei_tn3270_command_code);
5137       break;
5138   }
5139
5140   return (offset - start);
5141
5142 }
5143
5144 /* INBOUND DATA STREAM (DISPLAY -> MAINFRAME PROGRAM) */
5145 /* Dissect tvb as inbound */
5146 static gint
5147 dissect_inbound_stream(proto_tree *tn3270_tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, tn3270_conv_info_t *tn3270_info)
5148 {
5149   gint start = offset;
5150   gint aid;
5151   proto_item* item;
5152
5153   /* Command Code*/
5154   aid = tvb_get_guint8(tvb, offset);
5155   item = proto_tree_add_item(tn3270_tree,
5156                       hf_tn3270_aid,
5157                       tvb, offset,
5158                       1,
5159                       ENC_BIG_ENDIAN);
5160   offset += 1;
5161   switch (aid) {
5162     case  AID_STRUCTURED_FIELD:
5163       offset += dissect_structured_fields(tn3270_tree, pinfo, tvb, offset, tn3270_info, TRUE);
5164       break;
5165     case  AID_PA1_KEY:
5166     case  AID_PA2_KEY_CNCL:
5167     case  AID_PA3_KEY:
5168     case  AID_CLEAR_KEY:
5169       /* Certain AID bytes need not be followed by anything */
5170       /* XXX: Is this the correct/complete set of AID bytes for this case ? */
5171       if (tvb_reported_length_remaining(tvb, offset) <= 0)
5172         break;
5173       /* FALL THROUGH */
5174     case  AID_READ_PARTITION_AID:
5175     case  AID_NO_AID_GENERATED:
5176     case  AID_NO_AID_GENERATED_PRINTER_ONLY:
5177     case  AID_TRIGGER_ACTION:
5178     case  AID_TEST_REQ_AND_SYS_REQ:
5179     case  AID_PF1_KEY:
5180     case  AID_PF2_KEY:
5181     case  AID_PF3_KEY:
5182     case  AID_PF4_KEY:
5183     case  AID_PF5_KEY:
5184     case  AID_PF6_KEY:
5185     case  AID_PF7_KEY:
5186     case  AID_PF8_KEY:
5187     case  AID_PF9_KEY:
5188     case  AID_PF10_KEY:
5189     case  AID_PF11_KEY:
5190     case  AID_PF12_KEY:
5191     case  AID_PF13_KEY:
5192     case  AID_PF14_KEY:
5193     case  AID_PF15_KEY:
5194     case  AID_PF16_KEY:
5195     case  AID_PF17_KEY:
5196     case  AID_PF18_KEY:
5197     case  AID_PF19_KEY:
5198     case  AID_PF20_KEY:
5199     case  AID_PF21_KEY:
5200     case  AID_PF22_KEY:
5201     case  AID_PF23_KEY:
5202     case  AID_PF24_KEY:
5203     case  AID_CLEAR_PARTITION_KEY:
5204     case  AID_ENTER_KEY:
5205     case  AID_SELECTOR_PEN_ATTENTION:
5206     case  AID_OPERATOR_ID_READER:
5207     case  AID_MAG_READER_NUMBER:
5208       offset += dissect_buffer_address(tn3270_tree, tvb, offset, hf_tn3270_cursor_address, tn3270_info);
5209       offset += dissect_orders_and_data(tn3270_tree, pinfo, tvb, offset, tn3270_info);
5210       break;
5211     default:
5212       expert_add_info(pinfo, item, &ei_tn3270_aid);
5213       offset += 1;
5214       break;
5215   }
5216
5217   return (offset - start);
5218 }
5219
5220
5221 static int
5222 dissect_tn3270(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
5223 {
5224   proto_tree         *tn3270_tree;
5225   proto_item         *pi;
5226   gint                offset      = 0;
5227   conversation_t     *conversation;
5228   tn3270_conv_info_t *tn3270_info = NULL;
5229
5230   col_set_str(pinfo->cinfo, COL_PROTOCOL, "TN3270");
5231
5232   pinfo->fd->encoding = PACKET_CHAR_ENC_CHAR_EBCDIC;
5233
5234   /* Do we have a conversation for this connection? */
5235   conversation = find_conversation_pinfo(pinfo, 0);
5236   if (conversation != NULL) {
5237     /* Do we already have a type and mechanism? */
5238     tn3270_info = (tn3270_conv_info_t *)conversation_get_proto_data(conversation, proto_tn3270);
5239   }
5240
5241   if (tn3270_info == NULL)
5242     return 0;
5243
5244   pi = proto_tree_add_item(tree, proto_tn3270, tvb, offset, -1, ENC_NA);
5245   tn3270_tree = proto_item_add_subtree(pi, ett_tn3270);
5246   col_clear(pinfo->cinfo, COL_INFO);
5247
5248   if (tn3270_info->extended) {
5249     offset += dissect_tn3270e_header(tn3270_tree, tvb, offset);
5250   }
5251
5252   if (tvb_reported_length_remaining(tvb, offset) <= 0)
5253     return offset;
5254
5255   if (pinfo->srcport == tn3270_info->outbound_port) {
5256     col_set_str(pinfo->cinfo, COL_INFO, "TN3270 Data from Mainframe");
5257   }
5258   else {
5259     col_set_str(pinfo->cinfo, COL_INFO, "TN3270 Data to Mainframe");
5260   }
5261
5262   if(tree) {
5263     while (tvb_reported_length_remaining(tvb, offset) > 0) {
5264       if (pinfo->srcport == tn3270_info->outbound_port) {
5265         offset += dissect_outbound_stream(tn3270_tree, pinfo, tvb, offset, tn3270_info);
5266       }
5267       else {
5268         offset += dissect_inbound_stream(tn3270_tree, pinfo, tvb, offset, tn3270_info);
5269       }
5270     }
5271   }
5272
5273   return tvb_captured_length(tvb);
5274 }
5275
5276 void
5277 add_tn3270_conversation(packet_info *pinfo, int tn3270e, gint model)
5278 {
5279   conversation_t     *conversation;
5280   tn3270_conv_info_t *tn3270_info;
5281
5282   conversation = find_or_create_conversation(pinfo);
5283
5284   /*
5285    * Do we already have a type and mechanism?
5286    */
5287   tn3270_info = (tn3270_conv_info_t *)conversation_get_proto_data(conversation, proto_tn3270);
5288   if (tn3270_info == NULL) {
5289     /* No.  Attach that information to the conversation, and add
5290      * it to the list of information structures.
5291      */
5292     tn3270_info = wmem_new(wmem_file_scope(), tn3270_conv_info_t);
5293
5294     tn3270_info->outbound_port = pinfo->destport;
5295
5296     conversation_add_proto_data(conversation, proto_tn3270, tn3270_info);
5297   }
5298
5299   /* The maximum rows/cols is tied to the 3270 model number */
5300   switch (model) {
5301     default:
5302     case 2:
5303       tn3270_info->altrows = 24;
5304       tn3270_info->altcols = 80;
5305       break;
5306     case 3:
5307       tn3270_info->altrows = 32;
5308       tn3270_info->altcols = 80;
5309       break;
5310     case 4:
5311       tn3270_info->altrows = 43;
5312       tn3270_info->altcols = 80;
5313       break;
5314     case 5:
5315       tn3270_info->altrows = 27;
5316       tn3270_info->altcols = 132;
5317       break;
5318   }
5319   tn3270_info->rows = 24;
5320   tn3270_info->cols = 80;
5321
5322   tn3270_info->extended = tn3270e;
5323
5324 }
5325
5326 int
5327 find_tn3270_conversation(packet_info *pinfo)
5328 {
5329   conversation_t     *conversation = NULL;
5330   tn3270_conv_info_t *tn3270_info  = NULL;
5331
5332   /*
5333    * Do we have a conversation for this connection?
5334    */
5335   conversation = find_conversation_pinfo(pinfo, 0);
5336   if (conversation != NULL) {
5337     tn3270_info = (tn3270_conv_info_t *)conversation_get_proto_data(conversation, proto_tn3270);
5338     if (tn3270_info != NULL) {
5339       /*
5340        * Do we already have a type and mechanism?
5341        */
5342       return 1;
5343     }
5344   }
5345   return 0;
5346 }
5347
5348 void
5349 proto_register_tn3270(void)
5350 {
5351   static hf_register_info hf[] = {
5352     { &hf_tn3270_command_code,
5353       { "Command Code",
5354         "tn3270.command_code",
5355         FT_UINT8, BASE_HEX, VALS(vals_command_codes), 0x0,
5356         NULL, HFILL }
5357     },
5358     { &hf_tn3270_sf_length,
5359       { "Structured Field Length",
5360         "tn3270.sf_length",
5361         FT_UINT16, BASE_DEC, NULL, 0x0,
5362         NULL, HFILL }
5363     },
5364
5365     /* 3.4 Write Control Characters */
5366     { &hf_tn3270_wcc_nop,
5367       { "WCC NOP",
5368         "tn3270.wcc.nop",
5369         FT_BOOLEAN, 8, NULL, WCC_NOP,
5370         NULL, HFILL }
5371     },
5372     { &hf_tn3270_wcc_reset,
5373       { "WCC Reset",
5374         "tn3270.wcc.reset",
5375         FT_BOOLEAN, 8, NULL, WCC_RESET,
5376         NULL, HFILL }
5377     },
5378     { &hf_tn3270_wcc_printer1,
5379       { "WCC Printer1",
5380         "tn3270.wcc.printer1",
5381         FT_BOOLEAN, 8, NULL, WCC_PRINTER1,
5382         NULL, HFILL }
5383     },
5384     { &hf_tn3270_wcc_printer2,
5385       { "WCC Printer2",
5386         "tn3270.wcc.printer2",
5387         FT_BOOLEAN, 8, NULL, WCC_PRINTER2,
5388         NULL, HFILL }
5389     },
5390     { &hf_tn3270_wcc_start_printer,
5391       { "WCC Start Printer",
5392         "tn3270.wcc.start_printer",
5393         FT_BOOLEAN, 8, NULL, WCC_START_PRINTER,
5394         NULL, HFILL }
5395     },
5396     { &hf_tn3270_wcc_sound_alarm,
5397       { "WCC Sound Alarm",
5398         "tn3270.wcc.sound_alarm",
5399         FT_BOOLEAN, 8, NULL, WCC_SOUND_ALARM,
5400         NULL, HFILL }
5401     },
5402     { &hf_tn3270_wcc_keyboard_restore,
5403       { "WCC Keyboard Restore",
5404         "tn3270.wcc.keyboard_restore",
5405         FT_BOOLEAN, 8, NULL, WCC_KEYBOARD_RESTORE,
5406         NULL, HFILL }
5407     },
5408     { &hf_tn3270_wcc_reset_mdt,
5409       { "WCC Reset MDT",
5410         "tn3270.wcc.reset_mdt",
5411         FT_BOOLEAN, 8, NULL, WCC_RESET_MDT,
5412         NULL, HFILL }
5413     },
5414
5415     /* 8.7 Copy Control Codes (CCC) */
5416     { &hf_tn3270_ccc,
5417       { "Copy Control Code",
5418         "tn3270.ccc",
5419         FT_UINT8, BASE_HEX, NULL, 0,
5420         NULL, HFILL }
5421     },
5422     { &hf_tn3270_ccc_coding,
5423       { "Coding",
5424         "tn3270.ccc_coding",
5425         FT_UINT8, BASE_HEX, NULL, CCC_GRAPHIC_CONVERT_MASK,
5426         NULL, HFILL }
5427     },
5428     { &hf_tn3270_ccc_printout,
5429       { "Printout Format",
5430         "tn3270.ccc_printout",
5431         FT_UINT8, BASE_HEX, VALS(ccc_vals_printout_format), CCC_PRINT_BITS_MASK,
5432         NULL, HFILL }
5433     },
5434     { &hf_tn3270_ccc_start_print,
5435       { "The start-print bit",
5436         "tn3270.ccc_start_print",
5437         FT_BOOLEAN, 8, NULL, CCC_START_PRINT,
5438         NULL, HFILL }
5439     },
5440     { &hf_tn3270_ccc_sound_alarm,
5441       { "The sound-alarm bit",
5442         "tn3270.ccc_sound_alarm",
5443         FT_BOOLEAN, 8, NULL, CCC_SOUND_ALARM,
5444         NULL, HFILL }
5445     },
5446     { &hf_tn3270_ccc_copytype,
5447       { "Type of Data to be Copied",
5448         "tn3270.ccc_copytype",
5449         FT_UINT8, BASE_HEX, VALS(ccc_vals_copytype), CCC_ATTRIBUTE_BITS_MASK,
5450         NULL, HFILL }
5451     },
5452
5453     /* 4.4.1 Field Attributes */
5454     { &hf_tn3270_field_attribute,
5455       { "3270 Field Attribute",
5456         "tn3270.field_attribute",
5457         FT_UINT8, BASE_HEX, NULL, 0,
5458         NULL, HFILL }
5459     },
5460     { &hf_tn3270_fa_graphic_convert,
5461       { "Graphic Convert",
5462         "tn3270.fa.graphic_convert",
5463         FT_UINT8, BASE_HEX, NULL, FA_GRAPHIC_CONVERT_MASK,
5464         NULL, HFILL }
5465     },
5466     { &hf_tn3270_fa_protected,
5467       { "Protected",
5468         "tn3270.fa.protected",
5469         FT_BOOLEAN, 8, NULL, FA_PROTECTED,
5470         NULL, HFILL }
5471     },
5472     { &hf_tn3270_fa_numeric,
5473       { "Numeric",
5474         "tn3270.fa.numeric",
5475         FT_BOOLEAN, 8, NULL, FA_NUMERIC,
5476         NULL, HFILL }
5477     },
5478     { &hf_tn3270_fa_display,
5479       { "Display",
5480         "tn3270.fa.display",
5481         FT_UINT8, BASE_HEX, VALS(vals_fa_display), FA_DISPLAY_BITS_MASK,
5482         NULL, HFILL }
5483     },
5484     { &hf_tn3270_fa_reserved,
5485       { "Reserved",
5486         "tn3270.fa.reserved",
5487         FT_BOOLEAN, 8, NULL, FA_RESERVED,
5488         NULL, HFILL }
5489     },
5490     { &hf_tn3270_fa_modified,
5491       { "Modified",
5492         "tn3270.fa.modified",
5493         FT_BOOLEAN, 8, NULL, FA_MODIFIED,
5494         NULL, HFILL }
5495     },
5496
5497     /* Order Code */
5498     { &hf_tn3270_order_code,
5499       { "Order Code",
5500         "tn3270.order_code",
5501         FT_UINT8, BASE_HEX, VALS(vals_order_codes), 0x0,
5502         NULL, HFILL }
5503     },
5504     { &hf_tn3270_character_code,
5505       { "Character Code",
5506         "tn3270.character_code",
5507         FT_UINT8, BASE_HEX, NULL, 0x0,
5508         NULL, HFILL }
5509     },
5510     { &hf_tn3270_stop_address,
5511       { "Stop Address",
5512         "tn3270.stop_address",
5513         FT_UINT16, BASE_DEC, NULL, 0x0,
5514         NULL, HFILL }
5515     },
5516     { &hf_tn3270_attribute_type,
5517       { "Attribute Type",
5518         "tn3270.attribute_type",
5519         FT_UINT8, BASE_HEX, VALS(vals_attribute_types), 0x0,
5520         NULL, HFILL }
5521     },
5522     { &hf_tn3270_extended_highlighting,
5523       { "Extended Highlighting",
5524         "tn3270.extended_highlighting",
5525         FT_UINT8, BASE_HEX, VALS(vals_at_extended_highlighting), 0x0,
5526         NULL, HFILL }
5527     },
5528     { &hf_tn3270_color,
5529       { "Color",
5530         "tn3270.color",
5531         FT_UINT8, BASE_HEX, VALS(vals_at_color_identifications), 0x0,
5532         NULL, HFILL }
5533     },
5534     { &hf_tn3270_character_set,
5535       { "Character Set",
5536         "tn3270.character_set",
5537         FT_UINT8, BASE_RANGE_STRING|BASE_HEX, RVALS(rvals_at_character_set), 0x0,
5538         NULL, HFILL }
5539     },
5540     { &hf_tn3270_field_outlining,
5541       { "Field Outlining",
5542         "tn3270.field_outlining",
5543         FT_UINT8, BASE_HEX, VALS(vals_at_field_outlining), 0x0,
5544         NULL, HFILL }
5545     },
5546     { &hf_tn3270_transparency,
5547       { "Transparency",
5548         "tn3270.transparency",
5549         FT_UINT8, BASE_HEX, VALS(vals_at_transparency), 0x0,
5550         NULL, HFILL }
5551     },
5552
5553     { &hf_tn3270_field_validation_mandatory_fill,
5554       { "3270 Field validation_mandatory_fill",
5555         "tn3270.field_validation_mandatory_fill",
5556         FT_BOOLEAN, 8, TFS(&tn3270_field_validation_mandatory_fill), AT_FV_MANDATORY_FILL,
5557         NULL, HFILL }
5558     },
5559     { &hf_tn3270_field_validation_mandatory_entry,
5560       { "3270 Field validation_mandatory_entry",
5561         "tn3270.field_validation_mandatory_entry",
5562         FT_BOOLEAN, 8, TFS(&tn3270_field_validation_mandatory_entry), AT_FV_MANDATORY_ENTRY,
5563         NULL, HFILL }
5564     },
5565     { &hf_tn3270_field_validation_trigger,
5566       { "3270 Field validation_trigger",
5567         "tn3270.field_validation_trigger",
5568         FT_BOOLEAN, 8, TFS(&tn3270_field_validation_trigger), AT_FV_TRIGGER,
5569         NULL, HFILL }
5570     },
5571
5572     { &hf_tn3270_all_character_attributes,
5573       { "all_character_attributes",
5574         "tn3270.all_character_attributes",
5575         FT_UINT8, BASE_HEX, NULL, 0x0,
5576         NULL, HFILL }
5577     },
5578     { &hf_tn3270_aid,
5579       { "Attention Identification",
5580         "tn3270.aid",
5581         FT_UINT8, BASE_HEX, VALS(vals_attention_identification_bytes), 0x0,
5582         NULL, HFILL }
5583     },
5584
5585     { &hf_tn3270_buffer_address,
5586       { "Buffer Address",
5587         "tn3270.buffer_address",
5588         FT_UINT16, BASE_HEX, NULL, 0x0,
5589         NULL, HFILL }
5590     },
5591
5592     /* Self Defining Parameters */
5593     { &hf_tn3270_sdp_ln,
5594       {  "Length of this Self-Defining Parameter",
5595          "tn3270.sdp_ln",
5596          FT_UINT8, BASE_DEC, NULL, 0x0,
5597          NULL, HFILL }
5598     },
5599     { &hf_tn3270_sdp_id,
5600       {  "Self-Defining Parameter ID",
5601          "tn3270.sdp_id",
5602          FT_UINT8, BASE_HEX, NULL, 0x0,
5603          NULL, HFILL }
5604     },
5605     /* Self Defining Parameters */
5606
5607     /* 5.6 - Begin/End of File */
5608     { &hf_tn3270_begin_end_flags1,
5609       {  "Begin End Flags1",
5610          "tn3270.begin_end_flags1",
5611          FT_UINT8, BASE_HEX, NULL, 0x0,
5612          NULL, HFILL }
5613     },
5614     { &hf_tn3270_begin_end_flags2,
5615       {  "Begin End Flags2",
5616          "tn3270.begin_end_flags2",
5617          FT_UINT8, BASE_HEX, NULL, 0x0,
5618          NULL, HFILL }
5619     },
5620     /* END - 5.6 - Begin/End of File */
5621
5622     /* 5.7 - Create Partition */
5623     { &hf_tn3270_partition_id,
5624       {  "Partition ID",
5625          "tn3270.partition_id",
5626          FT_UINT8, BASE_HEX, NULL, 0x0,
5627          NULL, HFILL }
5628     },
5629     { &hf_tn3270_partition_uom,
5630       {  "The unit of measure and address mode",
5631          "tn3270.partition_uom",
5632          FT_UINT8, BASE_HEX, NULL, 0x0,
5633          NULL, HFILL }
5634     },
5635     { &hf_tn3270_partition_flags,
5636       {  "Flags",
5637          "tn3270.partition_flags",
5638          FT_UINT8, BASE_HEX, NULL, 0x0,
5639          NULL, HFILL }
5640     },
5641     { &hf_tn3270_partition_height,
5642       {  "The height of the presentation space",
5643          "tn3270.partition_height",
5644          FT_UINT16, BASE_DEC, NULL, 0x0,
5645          NULL, HFILL }
5646     },
5647     { &hf_tn3270_partition_width,
5648       {  "The width of the presentation space",
5649          "tn3270.partition_width",
5650          FT_UINT16, BASE_DEC, NULL, 0x0,
5651          NULL, HFILL }
5652     },
5653     { &hf_tn3270_partition_rv,
5654       {  "The y, or row, origin of the viewport relative to the top edge of the usable area",
5655          "tn3270.partition_rv",
5656          FT_UINT16, BASE_DEC, NULL, 0x0,
5657          NULL, HFILL }
5658     },
5659     { &hf_tn3270_partition_cv,
5660       {  "The x, or column, origin of the viewport relative to the left side of the usable area",
5661          "tn3270.partition_cv",
5662          FT_UINT16, BASE_DEC, NULL, 0x0,
5663          NULL, HFILL }
5664     },
5665     { &hf_tn3270_partition_hv,
5666       {  "The height of the viewport",
5667          "tn3270.partition_hv",
5668          FT_UINT16, BASE_DEC, NULL, 0x0,
5669          NULL, HFILL }
5670     },
5671     { &hf_tn3270_partition_wv,
5672       {  "The width of the viewport",
5673          "tn3270.partition_wv",
5674          FT_UINT16, BASE_DEC, NULL, 0x0,
5675          NULL, HFILL }
5676     },
5677     { &hf_tn3270_partition_rw,
5678       {  "The y, or row, origin of the window relative to the top edge of the presentation space",
5679          "tn3270.partition_rw",
5680          FT_UINT16, BASE_DEC, NULL, 0x0,
5681          NULL, HFILL }
5682     },
5683     { &hf_tn3270_partition_cw,
5684       {  "The x, or column, origin of the window relative to the left edge of the presentation  space",
5685          "tn3270.partition_cw",
5686          FT_UINT16, BASE_DEC, NULL, 0x0,
5687          NULL, HFILL }
5688     },
5689     { &hf_tn3270_partition_rs,
5690       {  "The number of units to be scrolled in a vertical multiple scroll",
5691          "tn3270.partition_rs",
5692          FT_UINT16, BASE_DEC, NULL, 0x0,
5693          NULL, HFILL }
5694     },
5695     { &hf_tn3270_partition_res,
5696       {  "Reserved",
5697          "tn3270.partition_res",
5698          FT_UINT16, BASE_DEC, NULL, 0x0,
5699          NULL, HFILL }
5700     },
5701     { &hf_tn3270_partition_pw,
5702       {  "The number of points in the horizontal direction in a character cell in this presentation space",
5703          "tn3270.partition_pw",
5704          FT_UINT8, BASE_HEX, NULL, 0x0,
5705          NULL, HFILL }
5706     },
5707     { &hf_tn3270_partition_ph,
5708       {  "The number of points in the vertical direction in a character cell in this presentation space",
5709          "tn3270.partition_ph",
5710          FT_UINT16, BASE_DEC, NULL, 0x0,
5711          NULL, HFILL }
5712     },
5713
5714     { &hf_tn3270_partition_command,
5715       {  "Partition Command",
5716          "tn3270.partition_command",
5717          FT_UINT8, BASE_HEX, VALS(vals_command_codes), 0x0,
5718          NULL, HFILL }
5719     },
5720     /* End - 5.7 - Create Partition */
5721
5722     /* 5.9 - Erase/Reset */
5723     { &hf_tn3270_erase_flags,
5724       {  "Erase Flags",
5725          "tn3270.erase_flags",
5726          FT_UINT8, BASE_HEX, NULL, 0x0,
5727          NULL, HFILL }
5728     },
5729     /* End - 5.9 - Erase/Reset */
5730
5731     /* 5.10 - Load Color Table */
5732     { &hf_tn3270_load_color_command,
5733       {  "Command",
5734          "tn3270.load_color_command",
5735          FT_BYTES, BASE_NONE, NULL, 0x0,
5736          NULL, HFILL }
5737     },
5738     /* End - 5.10 - Load Color Table */
5739
5740     /* 5.11 - Load Format Storage */
5741     { &hf_tn3270_load_format_storage_flags1,
5742       {  "Flags",
5743          "tn3270.load_format_storage_flags1",
5744          FT_UINT8, BASE_HEX, NULL, 0x0,
5745          NULL, HFILL }
5746     },
5747     { &hf_tn3270_load_format_storage_flags2,
5748       {  "Flags (Reserved)",
5749          "tn3270.load_format_storage_flags2",
5750          FT_UINT8, BASE_HEX, NULL, 0x0,
5751          NULL, HFILL }
5752     },
5753     { &hf_tn3270_load_format_storage_operand,
5754       {  "Operand:",
5755          "tn3270.load_format_storage_operand",
5756          FT_UINT8, BASE_HEX, VALS(vals_load_storage_format_operand), 0x0,
5757          NULL, HFILL }
5758     },
5759     { &hf_tn3270_load_format_storage_localname,
5760       {  "Local name for user selectable formats",
5761          "tn3270.load_format_storage_localname",
5762          FT_STRING, BASE_NONE, NULL, 0x0,
5763          NULL, HFILL }
5764     },
5765     { &hf_tn3270_format_group,
5766       {  "Format Group name",
5767          "tn3270.format_group_name",
5768          FT_STRING, BASE_NONE, NULL, 0x0,
5769          NULL, HFILL }
5770     },
5771     { &hf_tn3270_format_name,
5772       {  "Format name",
5773          "tn3270.format_name",
5774          FT_STRING, BASE_NONE, NULL, 0x0,
5775          NULL, HFILL }
5776     },
5777     { &hf_tn3270_load_format_storage_format_data,
5778       {  "Format data",
5779          "tn3270.load_format_storage_format_data",
5780          FT_STRING, BASE_NONE, NULL, 0x0,
5781          NULL, HFILL }},
5782     /* END - 5.11 - Load Format Storage */
5783
5784     /* 5.12 - Load Line Type */
5785     { &hf_tn3270_load_line_type_command,
5786       {  "Line Type Command",
5787          "tn3270.load_line_type_command",
5788          FT_BYTES, BASE_NONE, NULL, 0x0,
5789          NULL, HFILL }
5790     },
5791
5792     /* 5.13 - Load Programmed Symbols */
5793     { &hf_tn3270_ps_flags,
5794       {  "Flags",
5795          "tn3270.ps_flags",
5796          FT_UINT8, BASE_HEX, NULL, 0x0,
5797          NULL, HFILL }
5798     },
5799     { &hf_tn3270_ps_lcid,
5800       {  "Local character set ID",
5801          "tn3270.ps_lcid",
5802          FT_UINT8, BASE_HEX, NULL, 0x0,
5803          NULL, HFILL }
5804     },
5805     { &hf_tn3270_ps_char,
5806       {  "Beginning code point X'41' through X'FE'",
5807          "tn3270.ps_char",
5808          FT_UINT8, BASE_HEX, NULL, 0x0,
5809          NULL, HFILL }
5810     },
5811     { &hf_tn3270_ps_rws,
5812       {  "Loadable Character Set RWS Number",
5813          "tn3270.ps_rws",
5814          FT_UINT8, BASE_HEX, NULL, 0x0,
5815          NULL, HFILL }
5816     },
5817     { &hf_tn3270_extended_ps_length,
5818       {  "Length of parameters for extended form, including the length parameter",
5819          "tn3270.extended_ps_length",
5820          FT_UINT8, BASE_HEX, NULL, 0x0,
5821          NULL, HFILL }
5822     },
5823     { &hf_tn3270_extended_ps_flags,
5824       {  "Flags",
5825          "tn3270.extended_ps_flags",
5826          FT_UINT8, BASE_HEX, NULL, 0x0,
5827          NULL, HFILL }
5828     },
5829     { &hf_tn3270_extended_ps_lw,
5830       {  "Number of X-units in character cell (width of character matrixes)",
5831          "tn3270.extended_ps_lw",
5832          FT_UINT8, BASE_HEX, NULL, 0x0,
5833          NULL, HFILL }
5834     },
5835     { &hf_tn3270_extended_ps_lh,
5836       {  "Number of Y-units in character cell (depth ofcharacter matrixes)",
5837          "tn3270.extended_ps_lh",
5838          FT_UINT8, BASE_HEX, NULL, 0x0,
5839          NULL, HFILL }
5840     },
5841     { &hf_tn3270_extended_ps_subsn,
5842       {  "Subsection ID",
5843          "tn3270.extended_ps_subsn",
5844          FT_UINT8, BASE_HEX, NULL, 0x0,
5845          NULL, HFILL }
5846     },
5847     { &hf_tn3270_extended_ps_color,
5848       {  "Color planes",
5849          "tn3270.extended_ps_color",
5850          FT_UINT8, BASE_HEX, VALS(vals_at_color_identifications), 0x0,
5851          NULL, HFILL }
5852     },
5853     { &hf_tn3270_extended_ps_stsubs,
5854       {  "Starting Subsection Identifier",
5855          "tn3270.extended_ps_stsubs",
5856          FT_UINT8, BASE_HEX, NULL, 0x0,
5857          NULL, HFILL }
5858     },
5859     { &hf_tn3270_extended_ps_echar,
5860       {  "Ending code point",
5861          "tn3270.extended_ps_echar",
5862          FT_UINT8, BASE_HEX, NULL, 0x0,
5863          NULL, HFILL }
5864     },
5865     { &hf_tn3270_extended_ps_nw,
5866       {  "Number of width pairs",
5867          "tn3270.extended_ps_nw",
5868          FT_UINT8, BASE_HEX, NULL, 0x0,
5869          NULL, HFILL }
5870     },
5871     { &hf_tn3270_extended_ps_nh,
5872       {  "Number of height pairs",
5873          "tn3270.extended_ps_nh",
5874          FT_UINT8, BASE_HEX, NULL, 0x0,
5875          NULL, HFILL }
5876     },
5877     { &hf_tn3270_extended_ps_res,
5878       {  "Reserved",
5879          "tn3270.extended_ps_res",
5880          FT_UINT8, BASE_HEX, NULL, 0x0,
5881          NULL, HFILL }
5882     },
5883     /* END - 5.13 - Load Programmed Symbols */
5884
5885     /* 5.15 - Outbound Text Header */
5886     /*        Note: some of these entries multiply used */
5887     { &hf_tn3270_outbound_text_header_operation_type,
5888       {  "Outbound Text Operation Type",
5889          "tn3270.outbound_text_operation_type",
5890          FT_UINT8, BASE_HEX, VALS(vals_command_codes), 0x0,
5891          NULL, HFILL }
5892     },
5893     { &hf_tn3270_lvl,
5894       {  "Cursor level",
5895          "tn3270.lvl",
5896          FT_UINT8, BASE_HEX, NULL, 0x0,
5897          NULL, HFILL }
5898     },
5899     { &hf_tn3270_cro,
5900       {  "Cursor row offset",
5901          "tn3270.cro",
5902          FT_UINT16, BASE_DEC, NULL, 0x0,
5903          NULL, HFILL }
5904     },
5905     { &hf_tn3270_cc,
5906       {  "Cursor column offset",
5907          "tn3270.cc",
5908          FT_UINT16, BASE_DEC, NULL, 0x0,
5909          NULL, HFILL }
5910     },
5911     { &hf_tn3270_outbound_text_header_lhdr,
5912       {  "Header length includes itself",
5913          "tn3270.outbound_text_header_lhdr",
5914          FT_UINT16, BASE_DEC, NULL, 0x0,
5915          NULL, HFILL }
5916     },
5917     { &hf_tn3270_outbound_text_header_hdr,
5918       {  "Initial format controls",
5919          "tn3270.outbound_text_header_hdr",
5920          FT_BYTES, BASE_NONE, NULL, 0x0,
5921          NULL, HFILL }
5922     },
5923     /* END - 5.15 - Outbound Text Header */
5924
5925     /* 5.16 - Outbound 3270DS */
5926     { &hf_tn3270_bsc,
5927       {  "SNA BSC",
5928          "tn3270.bsc",
5929          FT_UINT8, BASE_HEX, NULL, 0x0,
5930          NULL, HFILL }
5931     },
5932     /* END - 5.16 - Outbound 3270DS */
5933
5934     /* 5.17 - Present Absolute Format */
5935     { &hf_tn3270_fpc,
5936       {  "Format Presentation Command",
5937          "tn3270.fpc",
5938          FT_UINT8, BASE_HEX, VALS(vals_command_codes), 0x0,
5939          NULL, HFILL }
5940     },
5941     /* END - 5.17 - Present Absolute Format */
5942
5943     /* 5.18 - Present Relative Format */
5944     { &hf_tn3270_fov,
5945       {  "Format Offset Value",
5946          "tn3270.fov",
5947          FT_UINT16, BASE_DEC, NULL, 0x0,
5948          NULL, HFILL }
5949     },
5950     /* End - 5.18 - Present Relative Format */
5951
5952     /* 5.19 - Read Partition */
5953     { &hf_tn3270_read_partition_operation_type,
5954       {  "Read Partition Operation Type",
5955          "tn3270.read_partition_reqtyp",
5956          FT_UINT8, BASE_HEX, VALS(vals_read_partition_operation_type), 0x0,
5957          NULL, HFILL }
5958     },
5959     { &hf_tn3270_read_partition_reqtyp,
5960       {  "Read Partition Request Type",
5961          "tn3270.read_partition_reqtyp",
5962          FT_UINT8, BASE_HEX, VALS(vals_read_partition_reqtype), READ_PARTITION_REQTYPE_MASK,
5963          NULL, HFILL }
5964     },
5965     /* End - 5.19 - Read Partition */
5966
5967     /* 5.22 - Restart */
5968     { &hf_tn3270_start_page,
5969       {  "Number of pages to skip on restart",
5970          "tn3270.start_page",
5971          FT_UINT16, BASE_DEC, NULL, 0x0,
5972          NULL, HFILL }
5973     },
5974     { &hf_tn3270_start_line,
5975       {  "Number of lines to skip on page for restart",
5976          "tn3270.start_line",
5977          FT_UINT16, BASE_DEC, NULL, 0x0,
5978          NULL, HFILL }
5979     },
5980     { &hf_tn3270_scs_data,
5981       {  "SCS data (noncompressed and noncompacted) to set up for restart",
5982          "tn3270.scs_data",
5983          FT_BYTES, BASE_NONE, NULL, 0x0,
5984          NULL, HFILL }
5985     },
5986     /* End - 5.22 - Restart */
5987
5988     /* 5.24 - Select Color Table */
5989     { &hf_tn3270_color_command,
5990       {  "Color Command",
5991          "tn3270.color_command",
5992          FT_UINT16, BASE_HEX, NULL, 0x0,
5993          NULL, HFILL }
5994     },
5995     /* 5.24 - Select Color Table */
5996
5997     /* 5.26 - Set Checkpoint Interval */
5998     { &hf_tn3270_interval,
5999       {  "Checkpoint interval",
6000          "tn3270.interval",
6001          FT_UINT8, BASE_HEX, NULL, 0x0,
6002          "Specifies the number of pages in the interval between terminal checkpoints", HFILL }
6003     },
6004     /* End - 5.26 - Set Checkpoint Interval */
6005
6006     /* 5.27 - Set MSR Interval */
6007     { &hf_tn3270_msr_type,
6008       {  "MSR type",
6009          "tn3270.msr_type",
6010          FT_UINT8, BASE_HEX, NULL, 0x0,
6011          NULL, HFILL }
6012     },
6013     { &hf_tn3270_msr_state_mask,
6014       {  "State Mask",
6015          "tn3270.msr_state_mask",
6016          FT_UINT8, BASE_HEX, NULL, 0x0,
6017          NULL, HFILL }
6018     },
6019     { &hf_tn3270_msr_user,
6020       { "User Mode",
6021         "tn3270.msr.user",
6022         FT_BOOLEAN, 8, NULL, 0x80,
6023         NULL, HFILL }
6024     },
6025     { &hf_tn3270_msr_locked,
6026       { "Locked",
6027         "tn3270.msr.locked",
6028         FT_BOOLEAN, 8, NULL, 0x40,
6029         NULL, HFILL }
6030     },
6031     { &hf_tn3270_msr_auto,
6032       { "Auto Enter",
6033         "tn3270.msr.auto",
6034         FT_BOOLEAN, 8, NULL, 0x20,
6035         NULL, HFILL }
6036     },
6037     { &hf_tn3270_msr_ind1,
6038       { "Audible Ind 1 Suppress",
6039         "tn3270.msr.ind1",
6040         FT_BOOLEAN, 8, NULL, 0x10,
6041         NULL, HFILL }
6042     },
6043     { &hf_tn3270_msr_ind2,
6044       { "Audible Ind 2 Suppress",
6045         "tn3270.msr.ind2",
6046         FT_BOOLEAN, 8, NULL, 0x08,
6047         NULL, HFILL }
6048     },
6049     { &hf_tn3270_msr_state_value,
6050       {  "State Value", "tn3270.msr_state_value",
6051          FT_UINT8, BASE_HEX, NULL, 0x0,
6052          NULL, HFILL }
6053     },
6054     { &hf_tn3270_msr_ind_mask,
6055       {  "Indicator Mask",
6056          "tn3270.msr_ind_mask",
6057          FT_UINT8, BASE_HEX, NULL, 0x0,
6058          NULL, HFILL }
6059     },
6060     { &hf_tn3270_msr_ind_value,
6061       {  "Indicator Value",
6062          "tn3270.msr_ind_value",
6063          FT_UINT8, BASE_HEX, NULL, 0x0,
6064          NULL, HFILL }
6065     },
6066     /* END -  5.27 - Set MSR Interval */
6067
6068     /* 5.28 - Set Partition Characteristics */
6069     { &hf_tn3270_spc_sdp_ot,
6070       {  "Top edge outline thickness",
6071          "tn3270.spc_sdp_ot",
6072          FT_UINT8, BASE_DEC, NULL, 0x0,
6073          NULL, HFILL }
6074     },
6075     { &hf_tn3270_spc_sdp_ob,
6076       {  "Bottom edge outline thickness",
6077          "tn3270.spc_sdp_ob",
6078          FT_UINT8, BASE_DEC, NULL, 0x0,
6079          NULL, HFILL }
6080     },
6081     { &hf_tn3270_spc_sdp_ol,
6082       {  "Left edge outline thickness",
6083          "tn3270.spc_sdp_ol",
6084          FT_UINT8, BASE_DEC, NULL, 0x0,
6085          NULL, HFILL }
6086     },
6087     { &hf_tn3270_spc_sdp_or,
6088       {  "Right edge outline thickness",
6089          "tn3270.spc_sdp_or",
6090          FT_UINT8, BASE_DEC, NULL, 0x0,
6091          NULL, HFILL }
6092     },
6093     { &hf_tn3270_spc_sdp_eucflags,
6094       {  "Flags",
6095          "tn3270.spc_sdp_eucflags",
6096          FT_UINT8, BASE_HEX, NULL, 0x0,
6097          NULL, HFILL }
6098     },
6099     /* END - 5.28 - Set Partition Characteristics */
6100
6101     /* 5.29 - Set Printer Characteristics */
6102     { &hf_tn3270_printer_flags,
6103       {  "Flags",
6104          "tn3270.printer_flags",
6105          FT_UINT8, BASE_HEX, NULL, 0x0,
6106          NULL, HFILL }
6107     },
6108     { &hf_tn3270_spc_sdp_srepc,
6109       {  "Set/Reset Early Print Complete",
6110          "tn3270.spc_sdp_srepc",
6111          FT_UINT8, BASE_HEX, NULL, 0x0,
6112          NULL, HFILL }
6113     },
6114     /* END - 5.29 - Set Printer Characteristics */
6115
6116     /* 5.30 - Set Reply Mode */
6117     /*  hf_tn3270_mode also used for 6.42: Query Reply (modes) */
6118     { &hf_tn3270_mode,
6119       {  "Mode",
6120          "tn3270.mode",
6121          FT_UINT8, BASE_HEX, VALS(vals_reply_modes), 0x0,
6122          NULL, HFILL }
6123     },
6124     { &hf_tn3270_reply_mode_attr_list,
6125       {  "Type codes for the attribute types",
6126          "tn3270.reply_mode_attr_list",
6127          FT_UINT8, BASE_HEX, VALS(vals_attribute_types), 0x0,
6128          NULL, HFILL }
6129     },
6130     /* END - 5.30 - Set Reply Mode */
6131
6132     /* 5.34 - Data Chain */
6133     { &hf_tn3270_data_chain_fields,
6134       {  "Data Chain Fields",
6135          "tn3270.data_chain_fields",
6136          FT_UINT8, BASE_HEX, NULL, 0x0,
6137          NULL, HFILL }
6138     },
6139     { &hf_tn3270_data_chain_group,
6140       {  "Data Chain Group",
6141          "tn3270.data_chain_group",
6142          FT_UINT8, BASE_HEX, VALS(vals_data_chain_group), DATA_CHAIN_GROUP_MASK,
6143          NULL, HFILL }
6144     },
6145     { &hf_tn3270_data_chain_inbound_control,
6146       {  "Data Chain Inbound Control",
6147          "tn3270.data_chain_inbound_control",
6148          FT_UINT8, BASE_HEX, VALS(vals_data_chain_inbound_control), DATA_CHAIN_INBOUND_CONTROL_MASK,
6149          NULL, HFILL }
6150     },
6151     /* END - 5.34 - Data Chain */
6152
6153     /* 5.35 - Destination/Origin */
6154     { &hf_tn3270_destination_or_origin_flags_input_control,
6155       {  "Input Control",
6156          "tn3270.destination_or_origin_flags_input_control",
6157          FT_UINT8, BASE_HEX, VALS(vals_destination_or_origin_flags_input_control), DESTINATION_OR_ORIGIN_FLAGS_INPUT_CONTROL_MASK,
6158          NULL, HFILL }
6159     },
6160     { &hf_tn3270_destination_or_origin_doid,
6161       {  "DOID",
6162          "tn3270.destination_or_origin_doid",
6163          FT_UINT16, BASE_HEX, NULL, 0x0,
6164          NULL, HFILL }
6165     },
6166     /* END - 5.35 - Destination/Origin */
6167
6168
6169     /* 5.36 - Object Control */
6170     { &hf_tn3270_object_control_flags,
6171       {  "Flags",
6172          "tn3270.object_control_flags",
6173          FT_UINT8, BASE_HEX, NULL, 0x0,
6174          NULL, HFILL }
6175     },
6176     { &hf_tn3270_object_type,
6177       {  "Object Type",
6178          "tn3270.object_type",
6179          FT_UINT8, BASE_HEX, VALS(vals_oc_type), 0x0,
6180          NULL, HFILL }
6181     },
6182     /* END - 5.36 - Object Control */
6183
6184     /* 5.40 - Save/Restore Format */
6185     { &hf_tn3270_save_or_restore_format_flags,
6186       {  "Flags",
6187          "tn3270.save_or_restore_format_flags",
6188          FT_UINT8, BASE_HEX, NULL, 0x0,
6189          NULL, HFILL }
6190     },
6191     { &hf_tn3270_srf_fpcb,
6192       {  "Contents of the FPCB that is to be saved or restored",
6193          "tn3270.srf_fpcb",
6194          FT_BYTES, BASE_NONE, NULL, 0x0,
6195          NULL, HFILL }
6196     },
6197
6198     /* 5.40 - Save/Restore Format */
6199     { &hf_tn3270_type_1_text_outbound_data,
6200       {  "Type 1 text outbound data",
6201          "tn3270.type_1_text_outbound_data",
6202          FT_BYTES, BASE_NONE, NULL, 0x0,
6203          NULL, HFILL }
6204     },
6205
6206     /* 6.2 - Exception/Status */
6207     { &hf_tn3270_exception_or_status_flags,
6208       {  "Flags",
6209          "tn3270.exception_or_status_flags",
6210          FT_UINT8, BASE_HEX, NULL, 0x0,
6211          NULL, HFILL }
6212     },
6213     { &hf_tn3270_sdp_excode,
6214       {  "Exception Code",
6215          "tn3270.sdp_excode",
6216          FT_UINT16, BASE_DEC, VALS(vals_sdp_excode), 0x0,
6217          NULL, HFILL }
6218     },
6219     { &hf_tn3270_sdp_statcode,
6220       {  "Status Code",
6221          "tn3270.sdp_statcode",
6222          FT_UINT16, BASE_DEC, VALS(vals_sdp_statcode), 0x0,
6223          NULL, HFILL }
6224     },
6225     { &hf_tn3270_sdp_ngl,
6226       {  "Number of groups currently assigned",
6227          "tn3270.sdp_ngl",
6228          FT_UINT16, BASE_DEC, NULL, 0x0,
6229          NULL, HFILL }
6230     },
6231     { &hf_tn3270_sdp_nml,
6232       {  "Number of formats currently loaded",
6233          "tn3270.sdp_nml",
6234          FT_UINT16, BASE_DEC, NULL, 0x0,
6235          NULL, HFILL }
6236     },
6237     { &hf_tn3270_sdp_nlml,
6238       {  "Number of local names used",
6239          "tn3270.sdp_nlml",
6240          FT_UINT16, BASE_DEC, NULL, 0x0,
6241          NULL, HFILL }
6242     },
6243     { &hf_tn3270_sdp_stor,
6244       {  "Amount of format storage space available (KB)",
6245          "tn3270.sdp_stor",
6246          FT_UINT32, BASE_DEC, NULL, 0x0,
6247          NULL, HFILL }
6248     },
6249     /* 6.2 - Exception/Status */
6250
6251     /* 6.3 - Inbound Text Header */
6252     { &hf_tn3270_hw,
6253       {  "Window height",
6254          "tn3270.hw",
6255          FT_UINT16, BASE_DEC, NULL, 0x0,
6256          NULL, HFILL }
6257     },
6258     { &hf_tn3270_rw,
6259       {  "Row offset of window origin",
6260          "tn3270.rw",
6261          FT_UINT16, BASE_DEC, NULL, 0x0,
6262          NULL, HFILL }
6263     },
6264     { &hf_tn3270_ww,
6265       {  "Window width",
6266          "tn3270.ww",
6267          FT_UINT16, BASE_DEC, NULL, 0x0,
6268          NULL, HFILL }
6269     },
6270     { &hf_tn3270_cw,
6271       {  "Column Offset of Window Origin",
6272          "tn3270.cw",
6273          FT_UINT16, BASE_DEC, NULL, 0x0,
6274          NULL, HFILL }
6275     },
6276     /* END - 6.3 - Inbound Text Header */
6277
6278     /* 6.4 Inbound 3270DS */
6279     { &hf_tn3270_cursor_address,
6280       { "Cursor Address",
6281         "tn3270.cursor_address",
6282         FT_UINT16, BASE_HEX, NULL, 0x0,
6283         NULL, HFILL }
6284     },
6285     /* END - 6.4 Inbound 3270DS */
6286
6287     /* 6.5 - Recovery Data */
6288     { &hf_tn3270_recovery_data_flags,
6289       {  "Flags",
6290          "tn3270.recovery_data_flags",
6291          FT_UINT8, BASE_HEX, NULL, 0x0,
6292          NULL, HFILL }
6293     },
6294     { &hf_tn3270_sld,
6295       {  "SLD -- Set line density parameter in effect at the checkpoint",
6296          "tn3270.sld",
6297          FT_UINT8, BASE_HEX, NULL, 0x0,
6298          NULL, HFILL }
6299     },
6300     { &hf_tn3270_charset,
6301       {  "Character set parameter of Set Attribute control in effect at the checkpoint",
6302          "tn3270.charset",
6303          FT_UINT8, BASE_HEX, NULL, 0x0,
6304          NULL, HFILL }
6305     },
6306     { &hf_tn3270_vertical,
6307       {  "Byte offset from Checkpoint Interval structured field to the Set Vertical Format control in effect for the checkpoint",
6308          "tn3270.vertical",
6309          FT_UINT32, BASE_DEC, NULL, 0x0,
6310          NULL, HFILL }
6311     },
6312     { &hf_tn3270_v_offset,
6313       {  "Byte offset within the string control byte string or the SVF character",
6314          "tn3270.v_offset",
6315          FT_UINT16, BASE_DEC, NULL, 0x0,
6316          NULL, HFILL }
6317     },
6318     { &hf_tn3270_v_sequence,
6319       {  "RU sequence number",
6320          "tn3270.v_sequence",
6321          FT_UINT16, BASE_DEC, NULL, 0x0,
6322          NULL, HFILL }
6323     },
6324     { &hf_tn3270_v_length,
6325       {  "Length of the SVF character string required for restart",
6326          "tn3270.v_length",
6327          FT_UINT16, BASE_DEC, NULL, 0x0,
6328          NULL, HFILL }
6329     },
6330     { &hf_tn3270_spd,
6331       {  "Set Primary Density parameter in effect at the checkpoint",
6332          "tn3270.spd",
6333          FT_UINT16, BASE_HEX, NULL, 0x0,
6334          NULL, HFILL }
6335     },
6336     { &hf_tn3270_horizon,
6337       {  "Byte offset from Checkpoint Interval structured field to the Set Horizontal Format control in effect for the checkpoint",
6338          "tn3270.horizon",
6339          FT_UINT32, BASE_DEC, NULL, 0x0,
6340          NULL, HFILL }
6341     },
6342     { &hf_tn3270_h_offset,
6343       {  "Byte offset from Checkpoint Interval structured field to the Set Horizontal Format control in effect for the checkpoint",
6344          "tn3270.h_offset",
6345          FT_UINT32, BASE_DEC, NULL, 0x0,
6346          NULL, HFILL }
6347     },
6348     { &hf_tn3270_h_sequence,
6349       {  "RU sequence number",
6350          "tn3270.h_sequence",
6351          FT_UINT16, BASE_DEC, NULL, 0x0,
6352          NULL, HFILL }
6353     },
6354     { &hf_tn3270_h_length,
6355       {  "Length of the SHF character string required for restart",
6356          "tn3270.h_length",
6357          FT_UINT16, BASE_DEC, NULL, 0x0,
6358          NULL, HFILL }
6359     },
6360     { &hf_tn3270_hilite,
6361       {  "Highlighting",
6362          "tn3270.hilite",
6363          FT_UINT8, BASE_HEX, VALS(vals_at_extended_highlighting), 0x0,
6364          NULL, HFILL }
6365     },
6366     { &hf_tn3270_pages,
6367       {  "Number of pages printed since the checkpoint",
6368          "tn3270.pages",
6369          FT_UINT16, BASE_DEC, NULL, 0x0,
6370          NULL, HFILL }
6371     },
6372     { &hf_tn3270_lines,
6373       {  "Number of lines printed since the checkpoint",
6374          "tn3270.lines",
6375          FT_UINT16, BASE_DEC, NULL, 0x0,
6376          NULL, HFILL }
6377     },
6378     { &hf_tn3270_checkpoint,
6379       {  "Byte offset from Set Checkpoint Interval structured field to the first"
6380          " character afterhe code point or character that caused an eject to the"
6381          " checkpointed page",
6382          "tn3270.checkpoint",
6383          FT_UINT32, BASE_DEC, NULL, 0x0,
6384          NULL, HFILL }
6385     },
6386     { &hf_tn3270_c_offset,
6387       {  "Byte offset within the String Control Byte string or structured field of"
6388          " the checkpointed character",
6389          "tn3270.c_offset",
6390          FT_UINT16, BASE_DEC, NULL, 0x0,
6391          NULL, HFILL }
6392     },
6393     { &hf_tn3270_c_sequence,
6394       {  "RU sequence number of the RU containing the checkpoint character",
6395          "tn3270.c_sequence",
6396          FT_UINT16, BASE_DEC, NULL, 0x0,
6397          NULL, HFILL }
6398     },
6399     { &hf_tn3270_c_seqoff,
6400       {  "Byte offset within the RU of the checkpointed character",
6401          "tn3270.c_seqoff",
6402          FT_UINT16, BASE_DEC, NULL, 0x0,
6403          NULL, HFILL }
6404     },
6405     { &hf_tn3270_c_scsoff,
6406       {  "Byte offset within the parameterized SCS control code (for example, TRN) of the checkpointed character.",
6407          "tn3270.c_scsoff",
6408          FT_UINT16, BASE_DEC, NULL, 0x0,
6409          NULL, HFILL }
6410     },
6411     { &hf_tn3270_prime,
6412       {  "Prime compression character",
6413          "tn3270.prime",
6414          FT_UINT8, BASE_HEX, NULL, 0x0,
6415          NULL, HFILL }
6416     },
6417     /* END - 6.5 - Recovery Data */
6418
6419     /* 6.9 - Query Reply (Alphanumeric Partitions) */
6420     { &hf_tn3270_ap_na,
6421       {  "Max number of alphanumeric partitions",
6422          "tn3270.ap_na",
6423          FT_UINT8, BASE_DEC, NULL, 0x0,
6424          NULL, HFILL }
6425     },
6426     { &hf_tn3270_ap_m,
6427       {  "Total available partition storage",
6428          "tn3270.ap_m",
6429          FT_UINT16, BASE_DEC, NULL, 0x0,
6430          NULL, HFILL }
6431     },
6432     { &hf_tn3270_query_reply_alphanumeric_flags,
6433       {  "Flags",
6434          "tn3270.ap_flags",
6435          FT_UINT8, BASE_HEX, NULL, 0x0,
6436          NULL, HFILL }
6437     },
6438     { &hf_tn3270_ap_vertical_scrolling,
6439       { "Vertical Scrolling Supported",
6440         "tn3270.ap_vertical_scrolling",
6441         FT_BOOLEAN, 8, NULL, QR_AP_VERTWIN,
6442         NULL, HFILL }
6443     },
6444     { &hf_tn3270_ap_horizontal_scrolling,
6445       { "Horizontal Scrolling Supported",
6446         "tn3270.ap_horizontal_scrolling",
6447         FT_BOOLEAN, 8, NULL, QR_AP_HORWIN,
6448         NULL, HFILL }
6449     },
6450     { &hf_tn3270_ap_apres1,
6451       { "Reserved",
6452         "tn3270.ap_apres1",
6453         FT_BOOLEAN, 8, NULL, QR_AP_APRES1,
6454         NULL, HFILL }
6455     },
6456     { &hf_tn3270_ap_apa,
6457       { "All Points addressability supported",
6458         "tn3270.ap_apa",
6459         FT_BOOLEAN, 8, NULL, QR_AP_APA_FLG,
6460         NULL, HFILL }
6461     },
6462     { &hf_tn3270_ap_pp,
6463       { "Partition protection supported",
6464         "tn3270.ap_pp",
6465         FT_BOOLEAN, 8, NULL, QR_AP_PROT,
6466         NULL, HFILL }
6467     },
6468     { &hf_tn3270_ap_lc,
6469       { "Presentation space local copy supported",
6470         "tn3270.ap_lc",
6471         FT_BOOLEAN, 8, NULL, QR_AP_LCOPY,
6472         NULL, HFILL }
6473     },
6474     { &hf_tn3270_ap_mp,
6475       { "Modify Partition supported",
6476         "tn3270.ap_mp",
6477         FT_BOOLEAN, 8, NULL, QR_AP_MODPART,
6478         NULL, HFILL }
6479     },
6480     { &hf_tn3270_ap_apres2,
6481       { "Reserved",
6482         "tn3270.ap_apres2",
6483         FT_BOOLEAN, 8, NULL, QR_AP_APRES2,
6484         NULL, HFILL }
6485     },
6486
6487     { &hf_tn3270_ap_cm,
6488       {  "Character multiplier",
6489          "tn3270.ap_cm",
6490          FT_UINT8, BASE_DEC, NULL, 0x0,
6491          NULL, HFILL }
6492     },
6493     { &hf_tn3270_ap_ro,
6494       {  "Row overhead",
6495          "tn3270.ap_ro",
6496          FT_UINT8, BASE_DEC, NULL, 0x0,
6497          NULL, HFILL }
6498     },
6499     { &hf_tn3270_ap_co,
6500       {  "Column overhead",
6501          "tn3270.ap_co",
6502          FT_UINT8, BASE_DEC, NULL, 0x0,
6503          NULL, HFILL }
6504     },
6505     { &hf_tn3270_ap_fo,
6506       {  "Fixed overhead",
6507          "tn3270.ap_fo",
6508          FT_UINT16, BASE_DEC, NULL, 0x0,
6509          NULL, HFILL }
6510     },
6511     /* END - 6.9 - Query Reply (Alphanumeric Partitions) */
6512
6513     /* 6.12 - Query Reply (Character Sets) */
6514     { &hf_tn3270_character_sets_flags1,
6515       {  "Flags (1)",
6516          "tn3270.character_sets_flags1",
6517          FT_UINT8, BASE_HEX, NULL, 0x0,
6518          NULL, HFILL }
6519     },
6520     { &hf_tn3270_cs_ge,
6521       { "Graphic Escape supported",
6522         "tn3270.cs_ge",
6523         FT_BOOLEAN, 8, NULL, QR_CS_ALT,
6524         NULL, HFILL }
6525     },
6526     { &hf_tn3270_cs_mi,
6527       { "Multiple LCIDs are supported",
6528         "tn3270.cs_mi",
6529         FT_BOOLEAN, 8, NULL, QR_CS_MULTID,
6530         NULL, HFILL }
6531     },
6532     { &hf_tn3270_cs_lps,
6533       { "Load PSSF is supported",
6534         "tn3270.cs_lps",
6535         FT_BOOLEAN, 8, NULL, QR_CS_LOADABLE,
6536         NULL, HFILL }
6537     },
6538     { &hf_tn3270_cs_lpse,
6539       { "Load PS EXTENDED is supported",
6540         "tn3270.cs_lpse",
6541         FT_BOOLEAN, 8, NULL, QR_CS_EXT,
6542         NULL, HFILL }
6543     },
6544     { &hf_tn3270_cs_ms,
6545       { "More than one size of character slot is supported",
6546         "tn3270.cs_ms",
6547         FT_BOOLEAN, 8, NULL, QR_CS_MS,
6548         NULL, HFILL }
6549     },
6550     { &hf_tn3270_cs_ch2,
6551       { "Two-byte coded character sets are supported",
6552         "tn3270.cs_ch2",
6553         FT_BOOLEAN, 8, NULL, QR_CS_CH2,
6554         NULL, HFILL }
6555     },
6556     { &hf_tn3270_cs_gf,
6557       { "CGCSGID is present",
6558         "tn3270.cs_gf",
6559         FT_BOOLEAN, 8, NULL, QR_CS_GF,
6560         NULL, HFILL }
6561     },
6562     { &hf_tn3270_cs_res,
6563       { "Reserved",
6564         "tn3270.cs_res",
6565         FT_BOOLEAN, 8, NULL, QR_CS_CSRES,
6566         NULL, HFILL }
6567     },
6568
6569     { &hf_tn3270_character_sets_flags2,
6570       {  "Flags (2)",
6571          "tn3270.character_sets_flags2",
6572          FT_UINT8, BASE_HEX, NULL, 0x0,
6573          NULL, HFILL }
6574     },
6575     { &hf_tn3270_cs_res2,
6576       { "Reserved",
6577         "tn3270.cs_res2",
6578         FT_BOOLEAN, 8, NULL, QR_CS_CSRES2,
6579         NULL, HFILL }
6580     },
6581     { &hf_tn3270_cs_pscs,
6582       { "Load PS slot size match not required",
6583         "tn3270.cs_pscs",
6584         FT_BOOLEAN, 8, NULL, QR_CS_PSCS,
6585         NULL, HFILL }
6586     },
6587     { &hf_tn3270_cs_res3,
6588       { "Reserved",
6589         "tn3270.cs_res3",
6590         FT_BOOLEAN, 8, NULL, QR_CS_CSRES3,
6591         NULL, HFILL }
6592     },
6593     { &hf_tn3270_cs_cf,
6594       { "CCSID present",
6595         "tn3270.cs_cf",
6596         FT_BOOLEAN, 8, NULL, QR_CS_CF,
6597         NULL, HFILL }
6598     },
6599
6600     { &hf_tn3270_sdw,
6601       {  "Default character slot width",
6602          "tn3270.cs_sdw",
6603          FT_UINT8, BASE_HEX, NULL, 0x0,
6604          NULL, HFILL }
6605     },
6606     { &hf_tn3270_sdh,
6607       {  "Default character slot height",
6608          "tn3270.cs_sdh",
6609          FT_UINT8, BASE_HEX, NULL, 0x0,
6610          NULL, HFILL }
6611     },
6612     { &hf_tn3270_form,
6613       {  "Form Types",
6614          "tn3270.form",
6615          FT_UINT8, BASE_HEX, NULL, 0x0,
6616          NULL, HFILL }
6617     },
6618     { &hf_tn3270_formres,
6619       {  "Form Types (Reserved)",
6620          "tn3270.formres",
6621          FT_UINT8, BASE_HEX, NULL, 0x0,
6622          NULL, HFILL }
6623     },
6624     { &hf_tn3270_cs_form_type1,
6625       { "18-byte form",
6626         "tn3270.cs_form_type1",
6627         FT_BOOLEAN, 8, NULL, 0x80,
6628         "the first 2 bytes contain a 16-bit vertical slice,"
6629         " the following 16 bytes contain 8-bit horizontal slices. For a 9"
6630         " x 12 character matrix the last 4 bytes contain binary zero.", HFILL }
6631     },
6632     { &hf_tn3270_cs_form_type2,
6633       { "18-byte form (COMPRESSED)",
6634         "tn3270.cs_form_type2",
6635         FT_BOOLEAN, 8, NULL, 0x40,
6636         "the first 2 bytes contain a 16-bit vertical slice,"
6637         " the following 16 bytes contain 8-bit horizontal slices. For a 9"
6638         " x 12 character matrix the last 4 bytes contain binary zero. (COMPRESSED)", HFILL }
6639     },
6640     { &hf_tn3270_cs_form_type3,
6641       { "Row loading (from top to bottom)",
6642         "tn3270.cs_form_type3",
6643         FT_BOOLEAN, 8, NULL, 0x20,
6644         NULL, HFILL }
6645     },
6646     { &hf_tn3270_cs_form_type4,
6647       { "Row loading (from top to bottom) (Compressed)",
6648         "tn3270.cs_form_type4",
6649         FT_BOOLEAN, 8, NULL, 0x10,
6650         NULL, HFILL }
6651     },
6652     { &hf_tn3270_cs_form_type5,
6653       { "Column loading (from left to right)",
6654         "tn3270.cs_form_type5",
6655         FT_BOOLEAN, 8, NULL, 0x08,
6656         NULL, HFILL }
6657     },
6658     { &hf_tn3270_cs_form_type6,
6659       { "Column loading (from left to right) (Compressed)",
6660         "tn3270.cs_form_type6",
6661         FT_BOOLEAN, 8, NULL, 0x04,
6662         NULL, HFILL }
6663     },
6664     { &hf_tn3270_cs_form_type8,
6665       { "Vector",
6666         "tn3270.cs_form_type8",
6667         FT_BOOLEAN, 8, NULL, 0x02,
6668         NULL, HFILL }
6669     },
6670     { &hf_tn3270_cs_dl,
6671       {  "Length of each descriptor",
6672          "tn3270.cs_dl",
6673          FT_UINT8, BASE_DEC, NULL, 0x0,
6674          NULL, HFILL }
6675     },
6676
6677     { &hf_tn3270_cs_descriptor_set,
6678       {  "Device Specific Character Set ID (PS store No.)",
6679          "tn3270.cs_descriptor_set",
6680          FT_UINT8, BASE_DEC, NULL, 0x0,
6681          NULL, HFILL }
6682     },
6683     { &hf_tn3270_cs_descriptor_flags,
6684       {  "Flags",
6685          "tn3270.cs_descriptor_flags",
6686          FT_UINT8, BASE_HEX, NULL, 0x0,
6687          NULL, HFILL }
6688     },
6689     { &hf_tn3270_cs_ds_load,
6690       { "Loadable character set",
6691         "tn3270.cs_ds_load",
6692         FT_BOOLEAN, 8, NULL, 0x80,
6693         NULL, HFILL }
6694     },
6695     { &hf_tn3270_cs_ds_triple,
6696       { "Triple-plane character set",
6697         "tn3270.cs_ds_triple",
6698         FT_BOOLEAN, 8, NULL, 0x40,
6699         NULL, HFILL }
6700     },
6701     { &hf_tn3270_cs_ds_char,
6702       { "Double-Byte coded character set",
6703         "tn3270.cs_ds_char",
6704         FT_BOOLEAN, 8, NULL, 0x20,
6705         NULL, HFILL }
6706     },
6707     { &hf_tn3270_cs_ds_cb,
6708       { "No LCID compare",
6709         "tn3270.cs_ds_cb",
6710         FT_BOOLEAN, 8, NULL, 0x10,
6711         NULL, HFILL }
6712     },
6713
6714     { &hf_tn3270_lcid,
6715       {  "Local character set ID (alias)",
6716          "tn3270.lcid",
6717          FT_UINT8, BASE_HEX, NULL, 0x0,
6718          NULL, HFILL }
6719     },
6720     { &hf_tn3270_sw,
6721       {  "Width of the character slots in this characterset.",
6722          "tn3270.sw",
6723          FT_UINT8, BASE_HEX, NULL, 0x0,
6724          NULL, HFILL }
6725     },
6726     { &hf_tn3270_sh,
6727       {  "Height of the character slots in this character set.",
6728          "tn3270.sh",
6729          FT_UINT8, BASE_HEX, NULL, 0x0,
6730          NULL, HFILL }
6731     },
6732     { &hf_tn3270_ssubsn,
6733       {  "Starting subsection.",
6734          "tn3270.ssubsn",
6735          FT_UINT8, BASE_HEX, NULL, 0x0,
6736          NULL, HFILL }
6737     },
6738     { &hf_tn3270_esubsn,
6739       {  "Ending subsection.",
6740          "tn3270.esubsn",
6741          FT_UINT8, BASE_HEX, NULL, 0x0,
6742          NULL, HFILL }
6743     },
6744     { &hf_tn3270_ccsgid,
6745       {  "Coded Graphic Character Set Identifier.",
6746          "tn3270.ccsgid",
6747          FT_UINT64, BASE_HEX, NULL, 0x0,
6748          NULL, HFILL }
6749     },
6750     { &hf_tn3270_ccsid,
6751       {  "Coded Character Set Identifier.",
6752          "tn3270.ccsid",
6753          FT_UINT64, BASE_HEX, NULL, 0x0,
6754          NULL, HFILL }
6755     },
6756     /* END - 6.12 - Query Reply (Character Sets) */
6757
6758     /* 6.13 - Query Reply (Color) */
6759     { &hf_tn3270_color_flags,
6760       {  "Flags",
6761          "tn3270.color_flags",
6762          FT_UINT8, BASE_HEX, NULL, 0x0,
6763          NULL, HFILL }
6764     },
6765     { &hf_tn3270_c_prtblk,
6766       { "Printer only - black ribbon is loaded",
6767         "tn3270.cc_prtblk",
6768         FT_BOOLEAN, 8, NULL, 0x40,
6769         NULL, HFILL }
6770     },
6771     { &hf_tn3270_c_np,
6772       {  "Length of color attribute list",
6773          "tn3270.np",
6774          FT_UINT8, BASE_DEC, NULL, 0x0,
6775          NULL, HFILL }
6776     },
6777     { &hf_tn3270_c_cav,
6778       {  "Color attribute value accepted by the device",
6779          "tn3270.c_cav",
6780          FT_UINT8, BASE_HEX, VALS(vals_at_color_identifications), 0x0,
6781          NULL, HFILL }
6782     },
6783     { &hf_tn3270_c_ci,
6784       {  "Color identifier",
6785          "tn3270.c_ci",
6786          FT_UINT8, BASE_HEX, VALS(vals_at_color_identifications), 0x0,
6787          NULL, HFILL }
6788     },
6789     { &hf_tn3270_db_cavdef,
6790       {  "Default color attribute value",
6791          "tn3270.db_cavdef",
6792          FT_UINT8, BASE_HEX, VALS(vals_at_color_identifications), 0x0,
6793          NULL, HFILL }
6794     },
6795     { &hf_tn3270_db_cidef,
6796       {  "Default background color identifier",
6797          "tn3270.db_cidef",
6798          FT_UINT8, BASE_HEX, VALS(vals_at_color_identifications), 0x0,
6799          NULL, HFILL }
6800     },
6801     /* END - 6.13 - Query Reply (Color) */
6802
6803     /* 6.14 - Query Reply (Cooperative Processing Requestor) */
6804     { &hf_tn3270_limin,
6805       {  "Maximum CPR bytes/transmission allowed inbound",
6806          "tn3270.limin",
6807          FT_UINT16, BASE_DEC, NULL, 0x0,
6808          NULL, HFILL }
6809     },
6810     { &hf_tn3270_limout,
6811       {  "Maximum CPR bytes/transmission allowed outbound",
6812          "tn3270.limout",
6813          FT_UINT16, BASE_DEC, NULL, 0x0,
6814          NULL, HFILL }
6815     },
6816     { &hf_tn3270_featl,
6817       {  "Length (in bytes) of feature information that follows",
6818          "tn3270.featl",
6819          FT_UINT8, BASE_DEC, NULL, 0x0,
6820          NULL, HFILL }
6821     },
6822     { &hf_tn3270_feats,
6823       {  "CPR length and feature flags",
6824          "tn3270.feats",
6825          FT_UINT16, BASE_DEC, NULL, 0x0,
6826          NULL, HFILL }
6827     },
6828     /* END - 6.14 - Query Reply (Cooperative Processing Requestor) */
6829
6830     /* 6.15 - Query Reply (Data Chaining) */
6831     { &hf_tn3270_dc_dir,
6832       {  "Indicates which direction can use the Data Chain structured field.",
6833          "tn3270.dc_dir",
6834          FT_UINT8, BASE_HEX, VALS(vals_data_chaining_dir), 0xC0,
6835          NULL, HFILL }
6836     },
6837     /* END - 6.15 - Query Reply (Data Chaining) */
6838
6839     /* 6.16 - Query Reply (Data Streams) */
6840     { &hf_tn3270_ds_default_sfid,
6841       {  "Default Data Stream",
6842          "tn3270.ds_default_sfid",
6843          FT_UINT8, BASE_HEX, VALS(vals_data_streams), 0x0,
6844          NULL, HFILL }
6845     },
6846     { &hf_tn3270_ds_sfid,
6847       {  "Supported Data Stream",
6848          "tn3270.ds_sfid",
6849          FT_UINT8, BASE_HEX, VALS(vals_data_streams), 0x0,
6850          NULL, HFILL }
6851     },
6852     /* END - 6.16 - Query Reply (Data Streams) */
6853
6854     /* 6.17 - Query Reply (DBCS Asia) */
6855     { &hf_tn3270_asia_sdp_sosi_soset,
6856       {  "Set ID of the Shift Out (SO) character set",
6857          "tn3270.asia_sdp_sosi_soset",
6858          FT_UINT8, BASE_HEX, NULL, 0x0,
6859          NULL, HFILL }
6860     },
6861     { &hf_tn3270_asia_sdp_ic_func,
6862       { "SO/SI Creation supported",
6863         "tn3270.asia_sdp_ic_func",
6864         FT_BOOLEAN, 8, NULL, 0x01,
6865         NULL, HFILL }
6866     },
6867     /* END - 6.17 - Query Reply (DBCS Asia) */
6868
6869     /* 6.19 - Query Reply (Distributed Data Management) */
6870     { &hf_tn3270_ddm_flags,
6871       {  "Flags (Reserved)",
6872          "tn3270.ddm_flags",
6873          FT_UINT8, BASE_HEX, NULL, 0x0,
6874          NULL, HFILL }
6875     },
6876     { &hf_tn3270_ddm_limin,
6877       {  "Maximum DDM bytes/transmission allowed inbound",
6878          "tn3270.ddm_limin",
6879          FT_UINT16, BASE_DEC, NULL, 0x0,
6880          NULL, HFILL }
6881     },
6882     { &hf_tn3270_ddm_limout,
6883       {  "Maximum DDM bytes/transmission allowed outbound",
6884          "tn3270.ddm_limout",
6885          FT_UINT16, BASE_DEC, NULL, 0x0,
6886          NULL, HFILL }
6887     },
6888     { &hf_tn3270_ddm_nss,
6889       {  "Number of subsets supported",
6890          "tn3270.ddm_nss",
6891          FT_UINT8, BASE_HEX, NULL, 0x0,
6892          NULL, HFILL }
6893     },
6894     { &hf_tn3270_ddm_ddmss,
6895       {  "DDM subset identifier",
6896          "tn3270.ddm_ddmss",
6897          FT_UINT8, BASE_HEX, VALS(vals_qr_ddm), 0x0,
6898          NULL, HFILL }
6899     },
6900     /* END - 6.19 - Query Reply (Distributed Data Management) */
6901
6902     /* 6.20 - Query Reply (Document Interchange Architecture) */
6903     { &hf_tn3270_dia_flags,
6904       {  "Flags (Reserved)",
6905          "tn3270.dia_flags",
6906          FT_UINT16, BASE_HEX, NULL, 0x0,
6907          NULL, HFILL }
6908     },
6909     { &hf_tn3270_dia_limin,
6910       {  "Maximum DIA bytes/transmission allowed inbound",
6911          "tn3270.dia_limin",
6912          FT_UINT16, BASE_DEC, NULL, 0x0,
6913          NULL, HFILL }
6914     },
6915     { &hf_tn3270_dia_limout,
6916       {  "Maximum DIA bytes/transmission allowed outbound",
6917          "tn3270.dia_limout",
6918          FT_UINT16, BASE_DEC, NULL, 0x0,
6919          NULL, HFILL }
6920     },
6921     { &hf_tn3270_dia_nfs,
6922       {  "Number of subsets supported",
6923          "tn3270.dia_nfs",
6924          FT_UINT8, BASE_HEX, NULL, 0x0,
6925          NULL, HFILL }
6926     },
6927     { &hf_tn3270_dia_diafs,
6928       {  "DIA function set identifier",
6929          "tn3270.dia_diafs",
6930          FT_UINT8, BASE_HEX, VALS(vals_qr_dia), 0x0,
6931          NULL, HFILL }
6932     },
6933     { &hf_tn3270_dia_diafn,
6934       {  "DIA function set number",
6935          "tn3270.dia_diafn",
6936          FT_UINT16, BASE_DEC, NULL, 0x0,
6937          NULL, HFILL }
6938     },
6939     /* END - 6.20 - Query Reply (Document Interchange Architecture) */
6940
6941     /* 6.22 - Query Reply (Field Outlining) */
6942     { &hf_tn3270_fo_flags,
6943       {  "Flags",
6944          "tn3270.fo_flags",
6945          FT_UINT8, BASE_HEX, NULL, 0x0,
6946          NULL, HFILL }
6947     },
6948     { &hf_tn3270_fo_vpos,
6949       {  "Location of vertical line",
6950          "tn3270.fo_vpos",
6951          FT_UINT8, BASE_DEC, NULL, 0x0,
6952          NULL, HFILL }
6953     },
6954     { &hf_tn3270_fo_hpos,
6955       {  "Location of overline/underline",
6956          "tn3270.fo_hpos",
6957          FT_UINT8, BASE_DEC, NULL, 0x0,
6958          NULL, HFILL }
6959     },
6960     { &hf_tn3270_fo_hpos0,
6961       {  "Location of overline in case of separation",
6962          "tn3270.fo_hpos0",
6963          FT_UINT8, BASE_DEC, NULL, 0x0,
6964          NULL, HFILL }
6965     },
6966     { &hf_tn3270_fo_hpos1,
6967       {  "Location of underline in case of separation",
6968          "tn3270.fo_hpos1",
6969          FT_UINT8, BASE_DEC, NULL, 0x0,
6970          NULL, HFILL }
6971     },
6972     /* END - 6.22 - Query Reply (Field Outlining) */
6973
6974     /* 6.25 - Query Reply (Format Storage Auxiliary Device) */
6975     { &hf_tn3270_fsad_flags,
6976       {  "Flags",
6977          "tn3270.fsad_flags",
6978          FT_UINT8, BASE_HEX, NULL, 0x0,
6979          NULL, HFILL }
6980     },
6981     { &hf_tn3270_fsad_limin,
6982       {  "Reserved for LIMIN parameter. Must be set to zeros.",
6983          "tn3270.fsad_limin",
6984          FT_UINT16, BASE_DEC, NULL, 0x0,
6985          NULL, HFILL }
6986     },
6987     { &hf_tn3270_fsad_limout,
6988       {  "Maximum bytes of format storage data per transmission allowed outbound.",
6989          "tn3270.fsad_limout",
6990          FT_UINT16, BASE_DEC, NULL, 0x0,
6991          NULL, HFILL }
6992     },
6993     { &hf_tn3270_fsad_size,
6994       {  "Size of the format storage space",
6995          "tn3270.fsad_size",
6996          FT_UINT16, BASE_DEC, NULL, 0x0,
6997          NULL, HFILL }
6998     },
6999     /* END - 6.25 - Query Reply (Format Storage Auxiliary Device) */
7000
7001     /* 6.28 - Query Reply (Highlighting) */
7002     { &hf_tn3270_h_np,
7003       {  "Number of attribute-value/action pairs",
7004          "tn3270.h_np",
7005          FT_UINT8, BASE_DEC, NULL, 0x0,
7006          NULL, HFILL }
7007     },
7008     { &hf_tn3270_h_vi,
7009       {  "Data stream attribute value accepted",
7010          "tn3270.h_vi",
7011          FT_UINT8, BASE_HEX, VALS(vals_at_extended_highlighting), 0x0,
7012          NULL, HFILL }
7013     },
7014     { &hf_tn3270_h_ai,
7015       {  "Data stream action",
7016          "tn3270.h_ai",
7017          FT_UINT8, BASE_HEX, VALS(vals_at_extended_highlighting), 0x0,
7018          NULL, HFILL }
7019     },
7020     /* END - Query Reply (Highlighting) */
7021
7022     /* 6.29 - Query Reply (IBM Auxiliary Device) */
7023     { &hf_tn3270_ibm_flags,
7024       {  "Flags",
7025          "tn3270.ibm_flags",
7026          FT_UINT8, BASE_HEX, NULL, 0x0,
7027          NULL, HFILL }
7028     },
7029     { &hf_tn3270_ibm_limin,
7030       {  "Inbound message size limit",
7031          "tn3270.ibm_limin",
7032          FT_UINT16, BASE_DEC, NULL, 0x0,
7033          NULL, HFILL }
7034     },
7035     { &hf_tn3270_ibm_limout,
7036       {  "Outbound message size limit",
7037          "tn3270.ibm_limout",
7038          FT_UINT16, BASE_DEC, NULL, 0x0,
7039          NULL, HFILL }
7040     },
7041     { &hf_tn3270_ibm_type,
7042       {  "Type of IBM Auxiliary Device",
7043          "tn3270.ibm_type",
7044          FT_UINT16, BASE_DEC, NULL, 0x0,
7045          NULL, HFILL }
7046     },
7047     /* END - 6.29 - Query Reply (IBM Auxiliary Device) */
7048
7049     /* 6.31 - Query Reply (Implicit Partitions) */
7050     { &hf_tn3270_ip_flags,
7051       {  "Flags (Reserved)",
7052          "tn3270.ip_flags",
7053          FT_UINT8, BASE_HEX, NULL, 0x0,
7054          NULL, HFILL }
7055     },
7056     { &hf_tn3270_ipdd_wd,
7057       {  "Width of the Implicit Partition default screen size (in character cells)",
7058          "tn3270.ipdd_wd",
7059          FT_UINT16, BASE_DEC, NULL, 0x0,
7060          NULL, HFILL }
7061     },
7062     { &hf_tn3270_ipdd_hd,
7063       {  "Height of the Implicit Partition default screen size",
7064          "tn3270.ipdd_hd",
7065          FT_UINT16, BASE_DEC, NULL, 0x0,
7066          NULL, HFILL }
7067     },
7068     { &hf_tn3270_ipdd_wa,
7069       {  "Width of the Implicit Partition alternate screen size",
7070          "tn3270.ipdd_wa",
7071          FT_UINT16, BASE_DEC, NULL, 0x0,
7072          NULL, HFILL }
7073     },
7074     { &hf_tn3270_ipdd_ha,
7075       {  "Height of the Implicit Partition alternate screen size",
7076          "tn3270.ipdd_ha",
7077          FT_UINT16, BASE_DEC, NULL, 0x0,
7078          NULL, HFILL }
7079     },
7080     { &hf_tn3270_ippd_dpbs,
7081       {  "Default printer buffer size (in character cells)",
7082          "tn3270.ippd_dpbs",
7083          FT_UINT64, BASE_DEC, NULL, 0x0,
7084          NULL, HFILL }
7085     },
7086     { &hf_tn3270_ippd_apbs,
7087       {  "Default printer buffer size (in character cells)",
7088          "tn3270.ippd_apbs",
7089          FT_UINT64, BASE_DEC, NULL, 0x0,
7090          NULL, HFILL }
7091     },
7092     { &hf_tn3270_ipccd_wcd,
7093       {  "Width of the character cell for the Implicit Partition default screen size",
7094          "tn3270.ipccd_wcd",
7095          FT_UINT16, BASE_DEC, NULL, 0x0,
7096          NULL, HFILL }
7097     },
7098     { &hf_tn3270_ipccd_hcd,
7099       {  "Height of the character cell for the Implicit Partition default screen size",
7100          "tn3270.ipccd_hcd",
7101          FT_UINT16, BASE_DEC, NULL, 0x0,
7102          NULL, HFILL }
7103     },
7104     { &hf_tn3270_ipccd_wca,
7105       {  "Width of the character cell for the Implicit Partition alternate screen size",
7106          "tn3270.ipccd_wca",
7107          FT_UINT16, BASE_DEC, NULL, 0x0,
7108          NULL, HFILL }
7109     },
7110     { &hf_tn3270_ipccd_hca,
7111       {  "Height of the character cell for the Implicit Partition alternate screen size",
7112          "tn3270.ipccd_hca",
7113          FT_UINT16, BASE_DEC, NULL, 0x0,
7114          NULL, HFILL }
7115     },
7116     /* END - Query Reply (Implicit Partitions) */
7117
7118     /* 6.32 - Query Reply (IOCA Auxiliary Device) */
7119     { &hf_tn3270_ioca_limin,
7120       {  "Max IOCA bytes/inbound transmission",
7121          "tn3270.ioca_limin",
7122          FT_UINT16, BASE_DEC, NULL, 0x0,
7123          NULL, HFILL }
7124     },
7125     { &hf_tn3270_ioca_limout,
7126       {  "Max IOCA bytes/outbound transmission",
7127          "tn3270.ioca_limout",
7128          FT_UINT16, BASE_DEC, NULL, 0x0,
7129          NULL, HFILL }
7130     },
7131     { &hf_tn3270_ioca_type,
7132       {  "Type of IOCA Auxiliary Device",
7133          "tn3270.ioca_type",
7134          FT_UINT16, BASE_DEC, NULL, 0x0,
7135          NULL, HFILL }
7136     },
7137     /* END - 6.32 - Query Reply (IOCA Auxiliary Device) */
7138
7139     /* 6.34 - Query Reply (MSR Control) */
7140     { &hf_tn3270_msr_nd,
7141       {  "Number of MSR device types",
7142          "tn3270.msr_nd",
7143          FT_UINT8, BASE_DEC, NULL, 0x0,
7144          NULL, HFILL }
7145     },
7146     /* END - 6.34 - Query Reply (MSR Control) */
7147
7148     /* 6.36 - Query Reply (OEM Auxiliary Device) */
7149     { &hf_tn3270_oem_dsref,
7150       {  "Data stream reference identifier",
7151          "tn3270.oem_dsref",
7152          FT_UINT8, BASE_HEX, NULL, 0x0,
7153          NULL, HFILL }
7154     },
7155     { &hf_tn3270_oem_dtype,
7156       {  "Device type",
7157          "tn3270.oem_dtype",
7158          FT_STRING, BASE_NONE, NULL, 0x0,
7159          NULL, HFILL }
7160     },
7161     { &hf_tn3270_oem_uname,
7162       {  "User assigned name",
7163          "tn3270.oem_uname",
7164          FT_STRING, BASE_NONE, NULL, 0x0,
7165          NULL, HFILL }
7166     },
7167     { &hf_tn3270_sdp_daid,
7168       {  "Destination/Origin ID",
7169          "tn3270.oem_sdp_daid_doid",
7170          FT_UINT16, BASE_DEC, NULL, 0x0,
7171          NULL, HFILL }
7172     },
7173     { &hf_tn3270_oem_sdp_ll_limin,
7174       {  "Maximum OEM dsf bytes/transmission allowed inbound",
7175          "tn3270.oem_sdp_ll_limin",
7176          FT_UINT16, BASE_DEC, NULL, 0x0,
7177          NULL, HFILL }
7178     },
7179     { &hf_tn3270_oem_sdp_ll_limout,
7180       {  "Maximum OEM dsf bytes/transmission allowed outbound",
7181          "tn3270.oem_sdp_ll_limout",
7182          FT_UINT16, BASE_DEC, NULL, 0x0,
7183          NULL, HFILL }
7184     },
7185     { &hf_tn3270_oem_sdp_pclk_vers,
7186       {  "Protocol version",
7187          "tn3270.oem_sdp_pclk_vers",
7188          FT_UINT16, BASE_DEC, NULL, 0x0,
7189          NULL, HFILL }
7190     },
7191     /* END - 6.36 - Query Reply (OEM Auxiliary Device) */
7192
7193     /* 6.37 - Query Reply (Paper Feed Techniques) */
7194     { &hf_tn3270_pft_flags,
7195       {  "Flags",
7196          "tn3270.pft_flags",
7197          FT_UINT8, BASE_HEX, NULL, 0x0,
7198          NULL, HFILL }
7199     },
7200     { &hf_tn3270_pft_tmo,
7201       {  "Top margin offset in 1/1440ths of an inch",
7202          "tn3270.pft_tmo",
7203          FT_UINT16, BASE_DEC, NULL, 0x0,
7204          NULL, HFILL }
7205     },
7206     { &hf_tn3270_pft_bmo,
7207       {  "Bottom margin offset in 1/1440ths of an inch",
7208          "tn3270.pft_bmo",
7209          FT_UINT16, BASE_DEC, NULL, 0x0,
7210          NULL, HFILL }
7211     },
7212     /* END - 6.37 - Query Reply (Paper Feed Techniques) */
7213
7214     /* 6.38 - Query Reply (Partition Characteristics) */
7215     { &hf_tn3270_pc_vo_thickness,
7216       {  "Thickness",
7217          "tn3270.pc_vo_thickness",
7218          FT_UINT8, BASE_DEC, NULL, 0x0,
7219          NULL, HFILL }
7220     },
7221     /* END- 6.38 - Query Reply (Partition Characteristics) */
7222
7223     /* 6.41 - Query Reply (Product Defined Data Stream) */
7224     { &hf_tn3270_pdds_refid,
7225       {  "Reference identifier",
7226          "tn3270.pdds_refid",
7227          FT_UINT8, BASE_HEX, VALS(vals_qr_pdds_refid), 0x0,
7228          NULL, HFILL }
7229     },
7230     { &hf_tn3270_pdds_ssid,
7231       {  "Subset identifier",
7232          "tn3270.pdds_ssid",
7233          FT_UINT8, BASE_HEX, VALS(vals_qr_pdds_ssid), 0x0,
7234          NULL, HFILL }
7235     },
7236     /* END - 6.41 - Query Reply (Product Defined Data Stream) */
7237
7238     /* 6.43 - Query Reply (RPQ Names) */
7239     { &hf_tn3270_rpq_device,
7240       {  "Device type identifier",
7241          "tn3270.rpq_device",
7242          FT_STRING, BASE_NONE, NULL, 0x0,
7243          NULL, HFILL }
7244     },
7245     { &hf_tn3270_rpq_mid,
7246       {  "Model type identifier",
7247          "tn3270.rpq_mid",
7248          FT_UINT64, BASE_DEC, NULL, 0x0,
7249          NULL, HFILL }
7250     },
7251     { &hf_tn3270_rpq_rpql,
7252       {  "Length of RPQ name (including this byte)",
7253          "tn3270.rpq_rpql",
7254          FT_UINT8, BASE_DEC, NULL, 0x0,
7255          NULL, HFILL }
7256     },
7257     { &hf_tn3270_rpq_name,
7258       {  "RPQ name",
7259          "tn3270.rpq_name",
7260          FT_STRING, BASE_NONE, NULL, 0x0,
7261          NULL, HFILL }
7262     },
7263     /* END - Query Reply (Names) */
7264
7265     /* 6.44 - Query Reply (Save or Restore Format) */
7266     { &hf_tn3270_srf_fpcbl,
7267       {  "Format parameter control block length",
7268          "tn3270.srf_fpcbl",
7269          FT_UINT16, BASE_DEC, NULL, 0x0,
7270          NULL, HFILL }
7271     },
7272     /* END - 6.44 - Query Reply (Save or Restore Format) */
7273
7274     /* 6.45 - Query Reply (Settable Printer Characteristics) */
7275     { &hf_tn3270_spc_epc_flags,
7276       {  "Flags",
7277          "tn3270.spc_epc_flags",
7278          FT_UINT8, BASE_HEX, NULL, 0x0,
7279          NULL, HFILL }
7280     },
7281     /* END - 6.45 - Query Reply (Settable Printer Characteristics) */
7282
7283     /* 6.47 - Query Reply (Storage Pools) */
7284     { &hf_tn3270_sp_spid,
7285       {  "Storage pool identity",
7286          "tn3270.sp_spid",
7287          FT_UINT8, BASE_HEX, NULL, 0x0,
7288          NULL, HFILL }
7289     },
7290     { &hf_tn3270_sp_size,
7291       {  "Size of this storage pool when empty",
7292          "tn3270.sp_size",
7293          FT_UINT32, BASE_DEC, NULL, 0x0,
7294          NULL, HFILL }
7295     },
7296     { &hf_tn3270_sp_space,
7297       {  "Space available in this storage pool",
7298          "tn3270.sp_space",
7299          FT_UINT32, BASE_DEC, NULL, 0x0,
7300          NULL, HFILL }
7301     },
7302     { &hf_tn3270_sp_objlist,
7303       {  "Identifiers of objects housed in this storage pool",
7304          "tn3270.sp_objlist",
7305          FT_UINT16, BASE_HEX, VALS(vals_sp_objlist), 0x0,
7306          NULL, HFILL }
7307     },
7308     /* END - 6.47 - Query Reply (Storage Pools) */
7309
7310     /* 6.49 - Query Reply (Text Partitions) */
7311     { &hf_tn3270_tp_nt,
7312       {  "Maximum number of text partitions",
7313          "tn3270.tp_nt",
7314          FT_UINT8, BASE_DEC, NULL, 0x0,
7315          NULL, HFILL }
7316     },
7317     { &hf_tn3270_tp_m,
7318       {  "Maximum partition size",
7319          "tn3270.tp_m",
7320          FT_UINT16, BASE_DEC, NULL, 0x0,
7321          NULL, HFILL }
7322     },
7323     { &hf_tn3270_tp_flags,
7324       {  "Flags",
7325          "tn3270.tp_flags",
7326          FT_UINT8, BASE_HEX, NULL, 0x0,
7327          NULL, HFILL }
7328     },
7329     { &hf_tn3270_tp_ntt,
7330       {  "Number of text types supported",
7331          "tn3270.tp_ntt",
7332          FT_UINT8, BASE_DEC, NULL, 0x0,
7333          NULL, HFILL }
7334     },
7335     { &hf_tn3270_tp_tlist,
7336       {  "List of types supported",
7337          "tn3270.tp_tlist",
7338          FT_UINT8, BASE_HEX, NULL, 0x0,
7339          NULL, HFILL }
7340     },
7341     /* END - 6.49 - Query Reply (Text Partitions) */
7342
7343     /* 6.50 - Query Reply (Transparency) */
7344     { &hf_tn3270_t_np,
7345       {  "Number of pairs",
7346          "tn3270.t_np",
7347          FT_UINT8, BASE_DEC, NULL, 0x0,
7348          NULL, HFILL }
7349     },
7350     { &hf_tn3270_t_vi,
7351       {  "Data stream attribute value accepted",
7352          "tn3270.t_vi",
7353          FT_UINT8, BASE_HEX, NULL, 0x0,
7354          NULL, HFILL }
7355     },
7356     { &hf_tn3270_t_ai,
7357       {  "Associated action value",
7358          "tn3270.t_ai",
7359          FT_UINT8, BASE_HEX, NULL, 0x0,
7360          NULL, HFILL }
7361     },
7362     /* END - 6.50 - Query Reply (Transparency) */
7363
7364     /* 6.51 Query Reply Usable Area */
7365     { &hf_tn3270_usable_area_flags1,
7366       {"Usable Area Flags",
7367        "tn3270.query_reply_usable_area_flags1",
7368        FT_UINT8, BASE_HEX, NULL, 0,
7369        NULL, HFILL}
7370     },
7371     { &hf_tn3270_ua_reserved1,
7372       { "Reserved",
7373         "tn3270.reserved",
7374         FT_BOOLEAN, 8, NULL, QR_UA_RESERVED1,
7375         NULL, HFILL }
7376     },
7377     { &hf_tn3270_ua_page_printer,
7378       { "Page Printer",
7379         "tn3270.ua_page_printer",
7380         FT_BOOLEAN, 8, NULL, QR_UA_PAGE_PRINTER,
7381         NULL, HFILL }
7382     },
7383     { &hf_tn3270_ua_reserved2,
7384       { "Reserved",
7385         "tn3270.reserved",
7386         FT_BOOLEAN, 8, NULL, QR_UA_RESERVED2,
7387         NULL, HFILL }
7388     },
7389     { &hf_tn3270_ua_hard_copy,
7390       { "Hard Copy",
7391         "tn3270.ua_hard_copy",
7392         FT_BOOLEAN, 8, NULL, QR_UA_HARD_COPY,
7393         NULL, HFILL }
7394     },
7395     { &hf_tn3270_ua_addressing,
7396       { "Usable Area Addressing",
7397         "tn3270.ua_addressing",
7398         FT_UINT8, BASE_HEX, VALS(vals_usable_area_addr_mode), QR_UA_ADDR_MODE_MASK,
7399         NULL, HFILL}
7400     },
7401     { &hf_tn3270_usable_area_flags2,
7402       { "Usable Area Flags",
7403         "tn3270.query_reply_usable_area_flags2",
7404         FT_UINT8, BASE_HEX, NULL, 0x0,
7405         NULL, HFILL}
7406     },
7407     { &hf_tn3270_ua_variable_cells,
7408       { "Variable Cells",
7409         "tn3270.ua_variable_cells",
7410         FT_BOOLEAN, 8, TFS(&tn3270_tfs_ua_variable_cells), QR_UA_VARIABLE_CELLS,
7411         NULL, HFILL }
7412     },
7413     { &hf_tn3270_ua_characters,
7414       { "Characters",
7415         "tn3270.ua_characters",
7416         FT_BOOLEAN, 8, TFS(&tn3270_tfs_ua_characters), QR_UA_CHARACTERS,
7417         NULL, HFILL }
7418     },
7419     { &hf_tn3270_ua_cell_units,
7420       { "Cell Units",
7421         "tn3270.ua_cell_units",
7422         FT_BOOLEAN, 8, TFS(&tn3270_tfs_ua_cell_units), QR_UA_CELL_UNITS,
7423         NULL, HFILL }
7424     },
7425     { &hf_tn3270_ua_width_cells_pels,
7426       {  "Width of usable area in cells/pels",
7427          "tn3270.ua_width_cells_pels",
7428          FT_UINT16, BASE_DEC, NULL, 0x0,
7429          NULL, HFILL }
7430     },
7431     { &hf_tn3270_ua_height_cells_pels,
7432       {  "Height of usable area in cells/pels",
7433          "tn3270.ua_height_cells_pels",
7434          FT_UINT16, BASE_DEC, NULL, 0x0,
7435          NULL, HFILL }
7436     },
7437     { &hf_tn3270_ua_uom_cells_pels,
7438       {  "Units of measure for cells/pels",
7439          "tn3270.ua_uom_cells_pels",
7440          FT_UINT8, BASE_HEX, VALS(vals_usable_area_uom), 0x0,
7441          NULL, HFILL }
7442     },
7443     { &hf_tn3270_ua_xr,
7444       {  "Distance between points in X direction as a fraction",
7445          "tn3270.ua_xr",
7446          FT_UINT32, BASE_HEX, NULL, 0x0,
7447          "measured in UNITS, with 2-byte numerator and 2-byte denominator", HFILL }
7448     },
7449     { &hf_tn3270_ua_yr,
7450       {  "Distance between points in Y direction as a fraction",
7451          "tn3270.ua_xr",
7452          FT_UINT32, BASE_HEX, NULL, 0x0,
7453          "measured in UNITS, with 2-byte numerator and 2-byte denominator", HFILL }
7454     },
7455     { &hf_tn3270_ua_aw,
7456       {  "Number of X units in default cell",
7457          "tn3270.ua_aw",
7458          FT_UINT8, BASE_DEC, NULL, 0x0,
7459          NULL, HFILL }
7460     },
7461     { &hf_tn3270_ua_ah,
7462       {  "Number of Y units in default cell",
7463          "tn3270.ua_ah",
7464          FT_UINT8, BASE_DEC, NULL, 0x0,
7465          NULL, HFILL }
7466     },
7467     { &hf_tn3270_ua_buffsz,
7468       {  "Character buffer size (bytes)",
7469          "tn3270.ua_buffsz",
7470          FT_UINT16, BASE_DEC, NULL, 0x0,
7471          NULL, HFILL }
7472     },
7473     { &hf_tn3270_ua_xmin,
7474       {  "Minimum number of X units in variable cell",
7475          "tn3270.ua_xmin",
7476          FT_UINT8, BASE_DEC, NULL, 0x0,
7477          NULL, HFILL }
7478     },
7479     { &hf_tn3270_ua_ymin,
7480       {  "Minimum number of Y units in variable cell",
7481          "tn3270.ua_ymin",
7482          FT_UINT8, BASE_DEC, NULL, 0x0,
7483          NULL, HFILL }
7484     },
7485     { &hf_tn3270_ua_xmax,
7486       {  "Maximum number of X units in variable cell",
7487          "tn3270.ua_xmax",
7488          FT_UINT8, BASE_DEC, NULL, 0x0,
7489          NULL, HFILL }
7490     },
7491     { &hf_tn3270_ua_ymax,
7492       {  "Maximum number of Y units in variable cell",
7493          "tn3270.ua_ymax",
7494          FT_UINT8, BASE_DEC, NULL, 0x0,
7495          NULL, HFILL }
7496     },
7497     /* End - 6.51 Query Reply Usable Area */
7498
7499     /* 6.52 - Query Reply (3270 IPDS) */
7500     { &hf_tn3270_3270_tranlim,
7501       {  "Maximum transmission size allowed outbound",
7502          "tn3270.3270_tranlim",
7503          FT_UINT16, BASE_DEC, NULL, 0x0,
7504          NULL, HFILL }
7505     },
7506     /* END - 6.52 - Query Reply (3270 IPDS) */
7507
7508     /* Miscellaneous */
7509     { &hf_tn3270_field_data,
7510       {  "Field Data",
7511          "tn3270.field_data",
7512          FT_STRING, BASE_NONE, NULL, 0x0,
7513          "tn3270.field_data", HFILL }
7514     },
7515     { &hf_tn3270_number_of_attributes,
7516       {  "Number of Attributes",
7517          "tn3270.number_of_attributes",
7518          FT_UINT8, BASE_HEX, NULL, 0x0,
7519          NULL, HFILL }
7520     },
7521     { &hf_tn3270_resbyte,
7522       {  "Flags (Reserved)",
7523          "tn3270.resbyte",
7524          FT_UINT8, BASE_HEX, NULL, 0x0,
7525          NULL, HFILL }
7526     },
7527     { &hf_tn3270_resbytes,
7528       {  "Flags (Reserved)",
7529          "tn3270.resbytes",
7530          FT_UINT8, BASE_HEX, NULL, 0x0,
7531          NULL, HFILL }
7532     },
7533     { &hf_tn3270_res_twobytes,
7534       {  "Flags (Reserved)",
7535          "tn3270.res_twobytes",
7536          FT_UINT16, BASE_HEX, NULL, 0x0,
7537          NULL, HFILL }
7538     },
7539     { &hf_tn3270_sf_single_byte_id,
7540       {  "Structured Field",
7541          "tn3270.sf_id",
7542          FT_UINT8, BASE_HEX, NULL, 0x0,
7543          NULL, HFILL }
7544     },
7545     { &hf_tn3270_sf_double_byte_id,
7546       {  "Structured Field",
7547          "tn3270.sf_id",
7548          FT_UINT16, BASE_HEX, NULL, 0x0,
7549          NULL, HFILL }
7550     },
7551     { &hf_tn3270_sf_query_reply,
7552       {  "Query Reply",
7553          "tn3270.sf_query_reply",
7554          FT_UINT8, BASE_HEX, VALS(vals_sf_query_replies), 0x0,
7555          NULL, HFILL }
7556     },
7557     { &hf_tn3270_null,
7558       {  "Trailing Null (Possible Mainframe/Emulator Bug)",
7559          "tn3270.null",
7560          FT_UINT8, BASE_HEX, NULL, 0x0,
7561          NULL, HFILL }
7562     },
7563     { &hf_tn3270_unknown_data,
7564       {  "Unknown Data (Possible Mainframe/Emulator Bug)",
7565          "tn3270.unknown_data",
7566          FT_BYTES, BASE_NONE, NULL, 0x0,
7567          NULL, HFILL }
7568     },
7569
7570     /* TN3270E - Header Fields */
7571     { &hf_tn3270_tn3270e_data_type,
7572       {  "TN3270E Data Type",
7573          "tn3270.tn3270e_data_type",
7574          FT_UINT8, BASE_HEX, VALS(vals_tn3270_header_data_types), 0x0,
7575          NULL, HFILL }
7576     },
7577     { &hf_tn3270_tn3270e_request_flag,
7578       {  "TN3270E Request Flag",
7579          "tn3270.tn3270e_request_flag",
7580          FT_UINT8, BASE_HEX, VALS(vals_tn3270_header_request_flags), 0x0,
7581          NULL, HFILL }
7582     },
7583     { &hf_tn3270_tn3270e_response_flag_3270_SCS,
7584       {  "TN3270E Response Flag",
7585          "tn3270.tn3270e_response_flag",
7586          FT_UINT8, BASE_HEX, VALS(vals_tn3270_header_response_flags_3270_SCS), 0x0,
7587          NULL, HFILL }
7588     },
7589     { &hf_tn3270_tn3270e_response_flag_response,
7590       {  "TN3270E Response Flag",
7591          "tn3270.tn3270e_response_flag",
7592          FT_UINT8, BASE_HEX, VALS(vals_tn3270_header_response_flags_response), 0x0,
7593          NULL, HFILL }
7594     },
7595     { &hf_tn3270_tn3270e_response_flag_unused,
7596       {  "TN3270E Response Flag",
7597          "tn3270.tn3270e_response_flag",
7598          FT_UINT8, BASE_HEX, NULL, 0x0,
7599          NULL, HFILL }
7600     },
7601     { &hf_tn3270_tn3270e_seq_number,
7602       {  "TN3270E Seq Number",
7603          "tn3270.tn3270e_seq_number",
7604          FT_UINT16, BASE_DEC, NULL, 0x0,
7605          NULL, HFILL }
7606     },
7607     { &hf_tn3270_tn3270e_header_data,
7608       {  "TN3270E Header Data",
7609          "tn3270.tn3270e_header_data",
7610          FT_STRING, BASE_NONE, NULL, 0x0,
7611          NULL, HFILL }
7612     }
7613   };
7614
7615   static gint *ett[] = {
7616     &ett_tn3270,
7617     &ett_tn3270e_hdr,
7618     &ett_sf,
7619     &ett_tn3270_field_attribute,
7620     &ett_tn3270_field_validation,
7621     &ett_tn3270_usable_area_flags1,
7622     &ett_tn3270_usable_area_flags2,
7623     &ett_tn3270_query_reply_alphanumeric_flags,
7624     &ett_tn3270_character_sets_flags1,
7625     &ett_tn3270_character_sets_flags2,
7626     &ett_tn3270_character_sets_form,
7627     &ett_tn3270_cs_descriptor_flags,
7628     &ett_tn3270_color_flags,
7629     &ett_tn3270_wcc,
7630     &ett_tn3270_ccc,
7631     &ett_tn3270_msr_state_mask,
7632     &ett_tn3270_data_chain_fields,
7633     &ett_tn3270_query_list
7634   };
7635
7636   static ei_register_info ei[] = {
7637     { &ei_tn3270_order_code, { "tn3270.order_code.bogus", PI_PROTOCOL, PI_WARN, "Bogus value", EXPFILL }},
7638     { &ei_tn3270_command_code, { "tn3270.command_code.bogus", PI_PROTOCOL, PI_WARN, "Bogus value", EXPFILL }},
7639     { &ei_tn3270_aid, { "tn3270.aid.bogus", PI_PROTOCOL, PI_WARN, "Bogus value", EXPFILL }},
7640   };
7641
7642   expert_module_t* expert_tn3270;
7643
7644   proto_tn3270 = proto_register_protocol("TN3270 Protocol", "TN3270", "tn3270");
7645   register_dissector("tn3270", dissect_tn3270, proto_tn3270);
7646   proto_register_field_array(proto_tn3270, hf, array_length(hf));
7647   proto_register_subtree_array(ett, array_length(ett));
7648   expert_tn3270 = expert_register_protocol(proto_tn3270);
7649   expert_register_field_array(expert_tn3270, ei, array_length(ei));
7650
7651 }
7652
7653 /*
7654  * Editor modelines
7655  *
7656  * Local Variables:
7657  * c-basic-offset: 2
7658  * tab-width: 8
7659  * indent-tabs-mode: nil
7660  * End:
7661  *
7662  * ex: set shiftwidth=2 tabstop=8 expandtab:
7663  * :indentSize=2:tabSize=8:noTabs=true:
7664  */