2 * Routines for IPP packet disassembly
4 * Guy Harris <guy@netapp.com>
6 * $Id: packet-ipp.c,v 1.2 1999/09/17 06:25:41 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
44 static int proto_ipp = -1;
46 #define PRINT_JOB 0x0002
47 #define PRINT_URI 0x0003
48 #define VALIDATE_JOB 0x0004
49 #define CREATE_JOB 0x0005
50 #define SEND_DOCUMENT 0x0006
51 #define SEND_URI 0x0007
52 #define CANCEL_JOB 0x0008
53 #define GET_JOB_ATTRIBUTES 0x0009
54 #define GET_JOBS 0x000A
55 #define GET_PRINTER_ATTRIBUTES 0x000B
57 static const value_string operation_vals[] = {
58 { PRINT_JOB, "Print-Job" },
59 { PRINT_URI, "Print-URI" },
60 { VALIDATE_JOB, "Validate-Job" },
61 { CREATE_JOB, "Create-Job" },
62 { SEND_DOCUMENT, "Send-Document" },
63 { SEND_URI, "Send-URI" },
64 { CANCEL_JOB, "Cancel-Job" },
65 { GET_JOB_ATTRIBUTES, "Get-Job-Attributes" },
66 { GET_JOBS, "Get-Jobs" },
67 { GET_PRINTER_ATTRIBUTES, "Get-Printer-Attributes" },
71 #define STATUS_SUCCESSFUL 0x0000
72 #define STATUS_INFORMATIONAL 0x0100
73 #define STATUS_REDIRECTION 0x0200
74 #define STATUS_CLIENT_ERROR 0x0400
75 #define STATUS_SERVER_ERROR 0x0500
77 #define STATUS_TYPE_MASK 0xFF00
79 #define SUCCESSFUL_OK 0x0000
80 #define SUCCESSFUL_OK_IGN_OR_SUB_ATTR 0x0001
81 #define SUCCESSFUL_OK_CONFLICTING_ATTR 0x0002
83 #define CLIENT_ERROR_BAD_REQUEST 0x0400
84 #define CLIENT_ERROR_FORBIDDEN 0x0401
85 #define CLIENT_ERROR_NOT_AUTHENTICATED 0x0402
86 #define CLIENT_ERROR_NOT_AUTHORIZED 0x0403
87 #define CLIENT_ERROR_NOT_POSSIBLE 0x0404
88 #define CLIENT_ERROR_TIMEOUT 0x0405
89 #define CLIENT_ERROR_NOT_FOUND 0x0406
90 #define CLIENT_ERROR_GONE 0x0407
91 #define CLIENT_ERROR_REQ_ENTITY_TOO_LRG 0x0408
92 #define CLIENT_ERROR_REQ_VALUE_TOO_LONG 0x0409
93 #define CLIENT_ERROR_DOC_FMT_NOT_SUPP 0x040A
94 #define CLIENT_ERROR_ATTR_OR_VAL_NOT_SUPP 0x040B
95 #define CLIENT_ERROR_URI_SCHEME_NOT_SUPP 0x040C
96 #define CLIENT_ERROR_CHARSET_NOT_SUPP 0x040D
97 #define CLIENT_ERROR_CONFLICTING_ATTRS 0x040E
99 #define SERVER_ERROR_INTERNAL_ERROR 0x0500
100 #define SERVER_ERROR_OPERATION_NOT_SUPP 0x0501
101 #define SERVER_ERROR_SERVICE_UNAVAIL 0x0502
102 #define SERVER_ERROR_VERSION_NOT_SUPP 0x0503
103 #define SERVER_ERROR_DEVICE_ERROR 0x0504
104 #define SERVER_ERROR_TEMPORARY_ERROR 0x0505
105 #define SERVER_ERROR_NOT_ACCEPTING_JOBS 0x0506
106 #define SERVER_ERROR_BUSY 0x0507
107 #define SERVER_ERROR_JOB_CANCELED 0x0508
109 static const value_string status_vals[] = {
110 { SUCCESSFUL_OK, "Successful-OK" },
111 { SUCCESSFUL_OK_IGN_OR_SUB_ATTR, "Successful-OK-Ignored-Or-Substituted-Attributes" },
112 { SUCCESSFUL_OK_CONFLICTING_ATTR, "Successful-OK-Conflicting-Attributes" },
113 { CLIENT_ERROR_BAD_REQUEST, "Client-Error-Bad-Request" },
114 { CLIENT_ERROR_FORBIDDEN, "Client-Error-Forbidden" },
115 { CLIENT_ERROR_NOT_AUTHENTICATED, "Client-Error-Not-Authenticated" },
116 { CLIENT_ERROR_NOT_AUTHORIZED, "Client-Error-Not-Authorized" },
117 { CLIENT_ERROR_NOT_POSSIBLE, "Client-Error-Not-Possible" },
118 { CLIENT_ERROR_TIMEOUT, "Client-Error-Timeout" },
119 { CLIENT_ERROR_NOT_FOUND, "Client-Error-Not-Found" },
120 { CLIENT_ERROR_GONE, "Client-Error-Gone" },
121 { CLIENT_ERROR_REQ_ENTITY_TOO_LRG, "Client-Error-Request-Entity-Too-Large" },
122 { CLIENT_ERROR_REQ_VALUE_TOO_LONG, "Client-Error-Request-Value-Too-Long" },
123 { CLIENT_ERROR_DOC_FMT_NOT_SUPP, "Client-Error-Document-Format-Not-Supported" },
124 { CLIENT_ERROR_ATTR_OR_VAL_NOT_SUPP, "Client-Error-Attributes-Or-Values-Not-Supported" },
125 { CLIENT_ERROR_URI_SCHEME_NOT_SUPP, "Client-Error-URI-Scheme-Not-Supported" },
126 { CLIENT_ERROR_CHARSET_NOT_SUPP, "Client-Error-Charset-Not-Supported" },
127 { CLIENT_ERROR_CONFLICTING_ATTRS, "Client-Error-Conflicting-Attributes" },
128 { SERVER_ERROR_INTERNAL_ERROR, "Server-Error-Internal-Error" },
129 { SERVER_ERROR_OPERATION_NOT_SUPP, "Server-Error-Operation-Not-Supported" },
130 { SERVER_ERROR_SERVICE_UNAVAIL, "Server-Error-Service-Unavailable" },
131 { SERVER_ERROR_VERSION_NOT_SUPP, "Server-Error-Version-Not-Supported" },
132 { SERVER_ERROR_DEVICE_ERROR, "Server-Error-Device-Error" },
133 { SERVER_ERROR_TEMPORARY_ERROR, "Server-Error-Temporary-Error" },
134 { SERVER_ERROR_NOT_ACCEPTING_JOBS, "Server-Error-Not-Accepting-Jobs" },
135 { SERVER_ERROR_BUSY, "Server-Error-Busy" },
136 { SERVER_ERROR_JOB_CANCELED, "Server-Error-Job-Canceled" },
140 static int parse_attributes(const u_char *pd, int offset, frame_data *fd,
142 static proto_tree *add_integer_tree(proto_tree *tree, const u_char *pd,
143 int offset, guint name_length, guint value_length);
144 static void add_integer_value(guint tag, gchar *tag_desc, proto_tree *tree,
145 const u_char *pd, int offset, guint name_length, guint value_length);
146 static proto_tree *add_octetstring_tree(proto_tree *tree, const u_char *pd,
147 int offset, guint name_length, guint value_length);
148 static void add_octetstring_value(guint tag, gchar *tag_desc, proto_tree *tree,
149 const u_char *pd, int offset, guint name_length, guint value_length);
150 static proto_tree *add_charstring_tree(proto_tree *tree, const u_char *pd,
151 int offset, guint name_length, guint value_length);
152 static void add_charstring_value(guint tag, gchar *tag_desc, proto_tree *tree,
153 const u_char *pd, int offset, guint name_length, guint value_length);
154 static int add_value_head(guint tag, gchar *tag_desc, proto_tree *tree,
155 const u_char *pd, int offset, guint name_length, guint value_length);
157 void dissect_ipp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
159 proto_tree *ipp_tree;
161 gboolean is_request = (pi.destport == 631);
165 if (check_col(fd, COL_PROTOCOL))
166 col_add_str(fd, COL_PROTOCOL, "IPP");
167 if (check_col(fd, COL_INFO)) {
169 col_add_str(fd, COL_INFO, "IPP request");
171 col_add_str(fd, COL_INFO, "IPP response");
175 ti = proto_tree_add_item(tree, proto_ipp, offset, END_OF_FRAME, NULL);
176 ipp_tree = proto_item_add_subtree(ti, ETT_IPP);
178 proto_tree_add_text(ipp_tree, offset, 2, "Version: %u.%u",
179 pd[offset], pd[offset + 1]);
183 proto_tree_add_text(ipp_tree, offset, 2, "Operation-id: %s",
184 val_to_str(pntohs(&pd[offset]), operation_vals,
185 "Unknown (0x%04x)"));
187 status_code = pntohs(&pd[offset]);
188 switch (status_code & STATUS_TYPE_MASK) {
190 case STATUS_SUCCESSFUL:
191 status_fmt = "Successful (0x%04x)";
194 case STATUS_INFORMATIONAL:
195 status_fmt = "Informational (0x%04x)";
198 case STATUS_REDIRECTION:
199 status_fmt = "Redirection (0x%04x)";
202 case STATUS_CLIENT_ERROR:
203 status_fmt = "Client error (0x%04x)";
206 case STATUS_SERVER_ERROR:
207 status_fmt = "Server error (0x%04x)";
211 status_fmt = "Unknown (0x%04x)";
214 proto_tree_add_text(ipp_tree, offset, 2, "Status-code: %s",
215 val_to_str(status_code, status_vals, status_fmt));
219 proto_tree_add_text(ipp_tree, offset, 4, "Request ID: %u",
220 pntohl(&pd[offset]));
223 offset = parse_attributes(pd, offset, fd, ipp_tree);
225 if (IS_DATA_IN_FRAME(offset))
226 dissect_data(pd, offset, fd, ipp_tree);
230 #define TAG_TYPE(tag) ((tag) & 0xF0)
231 #define TAG_TYPE_DELIMITER 0x00
232 #define TAG_TYPE_INTEGER 0x20
233 #define TAG_TYPE_OCTETSTRING 0x30
234 #define TAG_TYPE_CHARSTRING 0x40
236 #define TAG_END_OF_ATTRIBUTES 0x03
238 #define TAG_INTEGER 0x21
239 #define TAG_BOOLEAN 0x22
240 #define TAG_ENUM 0x23
242 #define TAG_OCTETSTRING 0x30
243 #define TAG_DATETIME 0x31
244 #define TAG_RESOLUTION 0x32
245 #define TAG_RANGEOFINTEGER 0x33
246 #define TAG_TEXTWITHLANGUAGE 0x35
247 #define TAG_NAMEWITHLANGUAGE 0x36
249 #define TAG_TEXTWITHOUTLANGUAGE 0x41
250 #define TAG_NAMEWITHOUTLANGUAGE 0x42
251 #define TAG_KEYWORD 0x44
253 #define TAG_URISCHEME 0x46
254 #define TAG_CHARSET 0x47
255 #define TAG_NATURALLANGUAGE 0x48
256 #define TAG_MIMEMEDIATYPE 0x49
258 static const value_string tag_vals[] = {
260 { 0x01, "Operation attributes" },
261 { 0x02, "Job attributes" },
262 { TAG_END_OF_ATTRIBUTES, "End of attributes" },
263 { 0x04, "Printer attributes" },
264 { 0x05, "Unsupported attributes" },
267 { 0x10, "Unsupported" },
269 { 0x13, "No value" },
270 { TAG_INTEGER, "Integer" },
271 { TAG_BOOLEAN, "Boolean" },
272 { TAG_ENUM, "Enum" },
273 { TAG_OCTETSTRING, "Octet string" },
274 { TAG_DATETIME, "Date/Time" },
275 { TAG_RESOLUTION, "Resolution" },
276 { TAG_RANGEOFINTEGER, "Range of integer" },
277 { TAG_TEXTWITHLANGUAGE, "Text with language" },
278 { TAG_NAMEWITHLANGUAGE, "Name with language" },
279 { TAG_TEXTWITHOUTLANGUAGE, "Text without language" },
280 { TAG_NAMEWITHOUTLANGUAGE, "Name without language" },
281 { TAG_KEYWORD, "Keyword" },
283 { TAG_URISCHEME, "URI scheme" },
284 { TAG_CHARSET, "Character set" },
285 { TAG_NATURALLANGUAGE, "Natural language" },
286 { TAG_MIMEMEDIATYPE, "MIME media type" },
291 parse_attributes(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
295 guint16 name_length, value_length;
296 proto_tree *as_tree = tree;
297 proto_item *tas = NULL;
298 int start_offset = offset;
299 proto_tree *attr_tree = tree;
301 while (IS_DATA_IN_FRAME(offset)) {
303 tag_desc = val_to_str(tag, tag_vals, "Reserved (0x%02x)");
304 if (TAG_TYPE(tag) == TAG_TYPE_DELIMITER) {
306 * If we had an attribute sequence we were
307 * working on, we're done with it; set its
308 * length to the length of all the stuff
312 proto_item_set_len(tas, offset - start_offset);
315 * This tag starts a new attribute sequence;
316 * create a new tree under this tag when we see
317 * a non-delimiter tag, under which to put
324 * Remember the offset at which this attribute
325 * sequence started, so we can use it to compute
326 * its length when it's finished.
328 start_offset = offset;
331 * Now create a new item for this tag.
333 tas = proto_tree_add_text(tree, offset, 1,
336 if (tag == TAG_END_OF_ATTRIBUTES) {
338 * No more attributes.
344 * Value tag - get the name length.
346 if (!BYTES_ARE_IN_FRAME(offset + 1, 2)) {
348 * We ran past the end of the frame.
349 * Quit (we need to be able to handle
350 * stuff that crosses frames to do more)
354 name_length = pntohs(&pd[offset + 1]);
357 * OK, get the value length.
359 if (!BYTES_ARE_IN_FRAME(offset + 1 + 2, name_length)) {
361 * We ran past the end of the frame.
362 * Quit (we need to be able to handle
363 * stuff that crosses frames to do more)
367 value_length = pntohs(&pd[offset + 1 + 2 + name_length]);
370 * OK, does the value run past the end of the
373 if (!BYTES_ARE_IN_FRAME(offset + 1 + 2 + name_length + 2,
376 * We ran past the end of the frame.
377 * Quit (we need to be able to handle
378 * stuff that crosses frames to do more)
382 if (as_tree == NULL) {
384 * OK, there's an attribute to hang
385 * under a delimiter tag, but we don't
386 * have a tree for that tag yet; create
389 as_tree = proto_item_add_subtree(tas,
394 switch (TAG_TYPE(tag)) {
396 case TAG_TYPE_INTEGER:
397 if (name_length != 0) {
399 * This is an attribute, not
400 * an additional value, so
401 * start a tree for it.
403 attr_tree = add_integer_tree(as_tree,
404 pd, offset, name_length,
407 add_integer_value(tag, tag_desc, attr_tree, pd,
408 offset, name_length, value_length);
411 case TAG_TYPE_OCTETSTRING:
412 if (name_length != 0) {
414 * This is an attribute, not
415 * an additional value, so
416 * start a tree for it.
418 attr_tree = add_octetstring_tree(as_tree,
419 pd, offset, name_length,
422 add_octetstring_value(tag, tag_desc,
423 attr_tree, pd, offset, name_length,
427 case TAG_TYPE_CHARSTRING:
428 if (name_length != 0) {
430 * This is an attribute, not
431 * an additional value, so
432 * start a tree for it.
434 attr_tree = add_charstring_tree(as_tree,
435 pd, offset, name_length,
438 add_charstring_value(tag, tag_desc,
439 attr_tree, pd, offset, name_length,
443 offset += 1 + 2 + name_length + 2 + value_length;
451 add_integer_tree(proto_tree *tree, const u_char *pd, int offset,
452 guint name_length, guint value_length)
456 if (value_length != 4) {
457 ti = proto_tree_add_text(tree, offset,
458 1 + 2 + name_length + 2 + value_length,
459 "%.*s: Invalid integer (length is %u, should be 4)",
460 name_length, &pd[offset + 1 + 2],
463 ti = proto_tree_add_text(tree, offset,
464 1 + 2 + name_length + 2 + value_length,
466 name_length, &pd[offset + 1 + 2],
467 pntohl(&pd[1 + 2 + name_length + 2]));
469 return proto_item_add_subtree(ti, ETT_IPP_ATTR);
473 add_integer_value(guint tag, gchar *tag_desc, proto_tree *tree,
474 const u_char *pd, int offset, guint name_length, guint value_length)
476 offset = add_value_head(tag, tag_desc, tree, pd, offset,
477 name_length, value_length);
478 if (value_length == 4) {
479 proto_tree_add_text(tree, offset, value_length,
480 "Value: %u", pntohl(&pd[1 + 2 + name_length + 2]));
485 add_octetstring_tree(proto_tree *tree, const u_char *pd, int offset,
486 guint name_length, guint value_length)
490 ti = proto_tree_add_text(tree, offset,
491 1 + 2 + name_length + 2 + value_length,
494 &pd[offset + 1 + 2]);
495 bytes_to_str(&pd[offset + 1 + 2 + name_length + 2], value_length);
496 return proto_item_add_subtree(ti, ETT_IPP_ATTR);
500 add_octetstring_value(guint tag, gchar *tag_desc, proto_tree *tree,
501 const u_char *pd, int offset, guint name_length, guint value_length)
503 offset = add_value_head(tag, tag_desc, tree, pd, offset,
504 name_length, value_length);
505 proto_tree_add_text(tree, offset, value_length,
506 "Value: %s", bytes_to_str(&pd[offset], value_length));
510 add_charstring_tree(proto_tree *tree, const u_char *pd, int offset,
511 guint name_length, guint value_length)
515 ti = proto_tree_add_text(tree, offset,
516 1 + 2 + name_length + 2 + value_length,
518 name_length, &pd[offset + 1 + 2],
519 value_length, &pd[offset + 1 + 2 + name_length + 2]);
520 return proto_item_add_subtree(ti, ETT_IPP_ATTR);
524 add_charstring_value(guint tag, gchar *tag_desc, proto_tree *tree,
525 const u_char *pd, int offset, guint name_length, guint value_length)
527 offset = add_value_head(tag, tag_desc, tree, pd, offset,
528 name_length, value_length);
529 proto_tree_add_text(tree, offset, value_length,
530 "Value: %.*s", value_length, &pd[offset]);
534 add_value_head(guint tag, gchar *tag_desc, proto_tree *tree,
535 const u_char *pd, int offset, guint name_length, guint value_length)
537 proto_tree_add_text(tree, offset, 1, "Tag: %s", tag_desc);
539 proto_tree_add_text(tree, offset, 2, "Name length: %u",
542 if (name_length != 0) {
543 proto_tree_add_text(tree, offset, name_length,
544 "Name: %.*s", name_length, &pd[offset]);
546 offset += name_length;
547 proto_tree_add_text(tree, offset, 2, "Value length: %u",
554 proto_register_ipp(void)
556 /* static hf_register_info hf[] = {
558 { "Name", "ipp.abbreviation", TYPE, VALS_POINTER }},
561 proto_ipp = proto_register_protocol("Internet Printing Protocol", "ipp");
562 /* proto_register_field_array(proto_ipp, hf, array_length(hf));*/