31 #include <epan/packet.h>
32 #include <epan/prefs.h>
33 #include <epan/ptvcursor.h>
38 static guint global_op_uavtalk_port = 9000;
40 static int proto_op_uavtalk = -1;
42 static gint ett_op_uavtalk = -1;
44 static dissector_handle_t data_handle;
45 static dissector_table_t uavtalk_subdissector_table;
47 static int hf_op_uavtalk_sync = -1;
48 static int hf_op_uavtalk_version = -1;
49 static int hf_op_uavtalk_type = -1;
50 static int hf_op_uavtalk_len = -1;
51 static int hf_op_uavtalk_objid = -1;
52 static int hf_op_uavtalk_crc8 = -1;
54 #define UAVTALK_SYNC_VAL 0x3C
56 static const value_string uavtalk_packet_types[]={
67 #define UAVTALK_HEADER_SIZE 8
68 #define UAVTALK_TRAILER_SIZE 1
69 static int dissect_op_uavtalk(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
void *
data _U_)
73 guint8 packet_type = tvb_get_guint8(tvb, 1) & 0x7;
74 guint32 objid = tvb_get_letohl(tvb, 4);
75 guint32 payload_length = tvb_get_letohs(tvb, 2) - UAVTALK_HEADER_SIZE - UAVTALK_TRAILER_SIZE;
76 guint32 reported_length = tvb_reported_length(tvb);
78 col_set_str(pinfo->cinfo, COL_PROTOCOL,
"UAVTALK");
80 col_clear(pinfo->cinfo, COL_INFO);
82 col_append_fstr(pinfo->cinfo, COL_INFO,
"%s: 0x%08x", val_to_str_const(packet_type, uavtalk_packet_types,
""), objid);
84 col_append_str(pinfo->cinfo, COL_INFO,
"(META)");
89 proto_tree *op_uavtalk_tree = NULL;
91 proto_item *ti = NULL;
94 ti = proto_tree_add_item(tree, proto_op_uavtalk, tvb, 0, -1, ENC_NA);
97 op_uavtalk_tree = proto_item_add_subtree(ti, ett_op_uavtalk);
100 cursor = ptvcursor_new(op_uavtalk_tree, tvb, 0);
103 ptvcursor_add(cursor, hf_op_uavtalk_sync, 1, ENC_LITTLE_ENDIAN);
104 ptvcursor_add_no_advance(cursor, hf_op_uavtalk_version, 1, ENC_LITTLE_ENDIAN);
105 ptvcursor_add(cursor, hf_op_uavtalk_type, 1, ENC_LITTLE_ENDIAN);
106 ptvcursor_add(cursor, hf_op_uavtalk_len, 2, ENC_LITTLE_ENDIAN);
107 ptvcursor_add(cursor, hf_op_uavtalk_objid, 4, ENC_LITTLE_ENDIAN);
109 offset = ptvcursor_current_offset(cursor);
111 ptvcursor_free(cursor);
113 proto_tree_add_item(op_uavtalk_tree, hf_op_uavtalk_crc8, tvb, reported_length - UAVTALK_TRAILER_SIZE, UAVTALK_TRAILER_SIZE, ENC_LITTLE_ENDIAN);
115 offset = UAVTALK_HEADER_SIZE;
119 tvbuff_t * next_tvb = tvb_new_subset(tvb, offset,
120 reported_length - UAVTALK_HEADER_SIZE - UAVTALK_TRAILER_SIZE,
124 if ((packet_type == 0) || (packet_type == 2)) {
126 if (!dissector_try_uint(uavtalk_subdissector_table, objid, next_tvb, pinfo, tree)) {
128 call_dissector(data_handle, next_tvb, pinfo, tree);
132 call_dissector(data_handle, next_tvb, pinfo, tree);
136 return UAVTALK_HEADER_SIZE + UAVTALK_TRAILER_SIZE;
141 module_t * op_uavtalk_module;
143 static hf_register_info hf[] = {
144 { &hf_op_uavtalk_sync,
145 {
"Sync Byte",
"uavtalk.sync", FT_UINT8,
146 BASE_HEX, NULL, 0x0, NULL, HFILL }
148 { &hf_op_uavtalk_version,
149 {
"Version",
"uavtalk.ver", FT_UINT8,
150 BASE_DEC, NULL, 0xf8, NULL, HFILL }
152 { &hf_op_uavtalk_type,
153 {
"Type",
"uavtalk.type", FT_UINT8,
154 BASE_HEX, VALS(uavtalk_packet_types), 0x07, NULL, HFILL }
156 { &hf_op_uavtalk_len,
157 {
"Length",
"uavtalk.len", FT_UINT16,
158 BASE_DEC, NULL, 0x0, NULL, HFILL }
160 { &hf_op_uavtalk_objid,
161 {
"ObjID",
"uavtalk.objid", FT_UINT32,
162 BASE_HEX, NULL, 0x0, NULL, HFILL }
164 { &hf_op_uavtalk_crc8,
165 {
"Crc8",
"uavtalk.crc8", FT_UINT8,
166 BASE_HEX, NULL, 0x0, NULL, HFILL }
172 static gint *ett[] = {
176 proto_op_uavtalk = proto_register_protocol(
"OpenPilot UAVTalk Protocol",
181 uavtalk_subdissector_table = register_dissector_table(
"uavtalk.objid",
"UAVObject ID", FT_UINT32, BASE_HEX);
183 proto_register_subtree_array(ett, array_length(ett));
184 proto_register_field_array(proto_op_uavtalk, hf, array_length(hf));
188 prefs_register_uint_preference(op_uavtalk_module,
"udp.port",
"UAVTALK UDP port",
189 "UAVTALK port (default 9000)", 10, &global_op_uavtalk_port);
194 dissector_handle_t op_uavtalk_handle;
196 op_uavtalk_handle = new_create_dissector_handle(dissect_op_uavtalk, proto_op_uavtalk);
197 dissector_add_handle(
"udp.port", op_uavtalk_handle);
199 if (global_op_uavtalk_port != 0) {
200 dissector_add_uint(
"udp.port", global_op_uavtalk_port, op_uavtalk_handle);
204 data_handle = find_dissector(
"data");
void proto_register_op_uavtalk(void)
void proto_reg_handoff_op_uavtalk(void)