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
15 #include <epan/packet.h>
16 #define PNAME "Canon BJNP"
20 #define BJNP_PORT_RANGE "8611-8614"
23 #define PRINTER_COMMAND 0x01
24 #define SCANNER_COMMAND 0x02
25 #define PRINTER_RESPONSE 0x81
26 #define SCANNER_RESPONSE 0x82
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
;
46 static int hf_session_id
;
47 static int hf_payload_len
;
48 static int hf_payload
;
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" },
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" },
73 static int dissect_bjnp (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
75 proto_tree
*bjnp_tree
;
79 uint8_t dev_type
, cmd_code
;
82 /* If it does not start with a printable character it's not BJNP */
83 if(!g_ascii_isprint(tvb_get_uint8(tvb
, 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
);
95 dev_type
= tvb_get_uint8 (tvb
, offset
);
96 proto_tree_add_item (bjnp_tree
, hf_dev_type
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
99 cmd_code
= tvb_get_uint8 (tvb
, offset
);
100 proto_tree_add_item (bjnp_tree
, hf_cmd_code
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
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
);
113 proto_tree_add_item (bjnp_tree
, hf_session_id
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
116 payload_len
= tvb_get_ntohl (tvb
, offset
);
117 proto_tree_add_item (bjnp_tree
, hf_payload_len
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
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
;
128 void proto_register_bjnp (void)
130 static hf_register_info hf
[] = {
132 { "Id", "bjnp.id", FT_STRING
, BASE_NONE
,
133 NULL
, 0x0, NULL
, HFILL
} },
135 { "Type", "bjnp.type", FT_UINT8
, BASE_DEC
,
136 VALS(dev_type_vals
), 0x0, NULL
, HFILL
} },
138 { "Code", "bjnp.code", FT_UINT8
, BASE_DEC
,
139 VALS(cmd_code_vals
), 0x0, NULL
, HFILL
} },
141 { "Sequence Number", "bjnp.seq_no", FT_UINT32
, BASE_DEC
,
142 NULL
, 0x0, NULL
, HFILL
} },
144 { "Session Id", "bjnp.session_id", FT_UINT16
, BASE_DEC
,
145 NULL
, 0x0, NULL
, HFILL
} },
147 { "Payload Length", "bjnp.payload_len", FT_UINT32
, BASE_DEC
,
148 NULL
, 0x0, NULL
, HFILL
} },
150 { "Payload", "bjnp.payload", FT_BYTES
, BASE_NONE
,
151 NULL
, 0x0, NULL
, HFILL
} },
154 static int *ett
[] = {
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
);
177 * indent-tabs-mode: nil
180 * ex: set shiftwidth=2 tabstop=8 expandtab:
181 * :indentSize=2:tabSize=8:noTabs=true: