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