Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-bjnp.c
blob17b2d4171bd4c7d36910b881873fb2e8a38076cc
1 /* packet-bjnp.c
2 * Routines for Canon BJNP packet disassembly.
4 * Copyright 2009, Stig Bjorlykke <stig@bjorlykke.org>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <epan/packet.h>
16 #define PNAME "Canon BJNP"
17 #define PSNAME "BJNP"
18 #define PFNAME "bjnp"
20 #define BJNP_PORT_RANGE "8611-8614"
22 /* dev_type */
23 #define PRINTER_COMMAND 0x01
24 #define SCANNER_COMMAND 0x02
25 #define PRINTER_RESPONSE 0x81
26 #define SCANNER_RESPONSE 0x82
28 /* cmd_code */
29 #define CMD_DISCOVER 0x01
30 #define CMD_PRINT_JOB_DET 0x10
31 #define CMD_CLOSE 0x11
32 #define CMD_GET_STATUS 0x20
33 #define CMD_PRINT 0x21
34 #define CMD_GET_ID 0x30
35 #define CMD_SCAN_JOB 0x32
37 void proto_register_bjnp(void);
38 void proto_reg_handoff_bjnp(void);
40 static int proto_bjnp;
42 static int hf_bjnp_id;
43 static int hf_dev_type;
44 static int hf_cmd_code;
45 static int hf_seq_no;
46 static int hf_session_id;
47 static int hf_payload_len;
48 static int hf_payload;
50 static int ett_bjnp;
52 static dissector_handle_t bjnp_handle;
54 static const value_string dev_type_vals[] = {
55 { PRINTER_COMMAND, "Printer Command" },
56 { SCANNER_COMMAND, "Scanner Command" },
57 { PRINTER_RESPONSE, "Printer Response" },
58 { SCANNER_RESPONSE, "Scanner Response" },
59 { 0, NULL }
62 static const value_string cmd_code_vals[] = {
63 { CMD_DISCOVER, "Discover" },
64 { CMD_PRINT_JOB_DET, "Print Job Details" },
65 { CMD_CLOSE, "Request Closure" },
66 { CMD_GET_STATUS, "Get Printer Status" },
67 { CMD_PRINT, "Print" },
68 { CMD_GET_ID, "Get Printer Identity" },
69 { CMD_SCAN_JOB, "Scan Job Details" },
70 { 0, NULL }
73 static int dissect_bjnp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
75 proto_tree *bjnp_tree;
76 proto_item *ti;
77 int offset = 0;
78 uint32_t payload_len;
79 uint8_t dev_type, cmd_code;
80 char *info;
82 /* If it does not start with a printable character it's not BJNP */
83 if(!g_ascii_isprint(tvb_get_uint8(tvb, 0)))
84 return 0;
86 col_set_str (pinfo->cinfo, COL_PROTOCOL, PSNAME);
87 col_clear (pinfo->cinfo, COL_INFO);
89 ti = proto_tree_add_item (tree, proto_bjnp, tvb, offset, -1, ENC_NA);
90 bjnp_tree = proto_item_add_subtree (ti, ett_bjnp);
92 proto_tree_add_item (bjnp_tree, hf_bjnp_id, tvb, offset, 4, ENC_ASCII);
93 offset += 4;
95 dev_type = tvb_get_uint8 (tvb, offset);
96 proto_tree_add_item (bjnp_tree, hf_dev_type, tvb, offset, 1, ENC_BIG_ENDIAN);
97 offset++;
99 cmd_code = tvb_get_uint8 (tvb, offset);
100 proto_tree_add_item (bjnp_tree, hf_cmd_code, tvb, offset, 1, ENC_BIG_ENDIAN);
101 offset++;
103 info = wmem_strdup_printf(pinfo->pool, "%s: %s",
104 val_to_str (dev_type, dev_type_vals, "Unknown type (%d)"),
105 val_to_str (cmd_code, cmd_code_vals, "Unknown code (%d)"));
107 proto_item_append_text (ti, ", %s", info);
108 col_add_str (pinfo->cinfo, COL_INFO, info);
110 proto_tree_add_item (bjnp_tree, hf_seq_no, tvb, offset, 4, ENC_BIG_ENDIAN);
111 offset += 4;
113 proto_tree_add_item (bjnp_tree, hf_session_id, tvb, offset, 2, ENC_BIG_ENDIAN);
114 offset += 2;
116 payload_len = tvb_get_ntohl (tvb, offset);
117 proto_tree_add_item (bjnp_tree, hf_payload_len, tvb, offset, 4, ENC_BIG_ENDIAN);
118 offset += 4;
120 if (payload_len > 0) {
121 /* TBD: Dissect various commands */
122 proto_tree_add_item (bjnp_tree, hf_payload, tvb, offset, payload_len, ENC_NA);
123 offset += payload_len;
125 return offset;
128 void proto_register_bjnp (void)
130 static hf_register_info hf[] = {
131 { &hf_bjnp_id,
132 { "Id", "bjnp.id", FT_STRING, BASE_NONE,
133 NULL, 0x0, NULL, HFILL } },
134 { &hf_dev_type,
135 { "Type", "bjnp.type", FT_UINT8, BASE_DEC,
136 VALS(dev_type_vals), 0x0, NULL, HFILL } },
137 { &hf_cmd_code,
138 { "Code", "bjnp.code", FT_UINT8, BASE_DEC,
139 VALS(cmd_code_vals), 0x0, NULL, HFILL } },
140 { &hf_seq_no,
141 { "Sequence Number", "bjnp.seq_no", FT_UINT32, BASE_DEC,
142 NULL, 0x0, NULL, HFILL } },
143 { &hf_session_id,
144 { "Session Id", "bjnp.session_id", FT_UINT16, BASE_DEC,
145 NULL, 0x0, NULL, HFILL } },
146 { &hf_payload_len,
147 { "Payload Length", "bjnp.payload_len", FT_UINT32, BASE_DEC,
148 NULL, 0x0, NULL, HFILL } },
149 { &hf_payload,
150 { "Payload", "bjnp.payload", FT_BYTES, BASE_NONE,
151 NULL, 0x0, NULL, HFILL } },
154 static int *ett[] = {
155 &ett_bjnp
158 proto_bjnp = proto_register_protocol (PNAME, PSNAME, PFNAME);
160 bjnp_handle = register_dissector (PFNAME, dissect_bjnp, proto_bjnp);
162 proto_register_field_array (proto_bjnp, hf, array_length (hf));
163 proto_register_subtree_array (ett, array_length (ett));
166 void proto_reg_handoff_bjnp (void)
168 dissector_add_uint_range_with_preference("udp.port", BJNP_PORT_RANGE, bjnp_handle);
172 * Editor modelines
174 * Local Variables:
175 * c-basic-offset: 2
176 * tab-width: 8
177 * indent-tabs-mode: nil
178 * End:
180 * ex: set shiftwidth=2 tabstop=8 expandtab:
181 * :indentSize=2:tabSize=8:noTabs=true: