2 * Dissector for AT Commands
4 * Copyright 2011, Tyson Key <tyson.key@gmail.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <epan/packet.h>
36 static int proto_at = -1;
37 static int hf_at_command = -1;
39 /* Forward-declare the dissector functions */
40 static void dissect_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
42 /* Subtree handles: set by register_subtree_array */
43 static gint ett_at = -1;
45 static gboolean allowed_chars(tvbuff_t *tvb)
50 len = tvb_length(tvb);
51 for (offset = 0; offset < len; offset++) {
52 val = tvb_get_guint8(tvb, offset);
53 if (!(isprint(val) || (val == 0x0a) || (val == 0x0d)))
59 /* Experimental approach based upon the one used for PPP */
60 static gboolean heur_dissect_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
62 const gchar at_magic1[2] = {0x0d, 0x0a};
63 const gchar at_magic2[3] = {0x0d, 0x0d, 0x0a};
64 const gchar at_magic3[2] = {'A', 'T'};
66 if (((tvb_memeql(tvb, 0, at_magic1, sizeof(at_magic1)) == 0) ||
67 (tvb_memeql(tvb, 0, at_magic2, sizeof(at_magic2)) == 0) ||
68 (tvb_memeql(tvb, 0, at_magic3, sizeof(at_magic3)) == 0)) &&
70 dissect_at(tvb, pinfo, tree);
76 /* The dissector itself */
77 static void dissect_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
83 len = tvb_reported_length(tvb);
84 col_append_str(pinfo->cinfo, COL_PROTOCOL, "/AT");
85 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "AT Command: %s",
86 tvb_format_text_wsp(tvb, 0, len));
89 /* Start with a top-level item to add everything else to */
90 item = proto_tree_add_item(tree, proto_at, tvb, 0, -1, ENC_NA);
91 at_tree = proto_item_add_subtree(item, ett_at);
94 proto_tree_add_item(at_tree, hf_at_command, tvb, 0, len, ENC_ASCII|ENC_NA);
95 proto_item_append_text(item, ": %s", tvb_format_text_wsp(tvb, 0, len));
100 proto_register_at_command(void)
102 static hf_register_info hf[] = {
104 { "AT Command", "at.command", FT_STRING, BASE_NONE,
105 NULL, 0x0, NULL, HFILL }}
108 static gint *ett[] = {
112 proto_at = proto_register_protocol("AT Command", "AT", "at");
113 proto_register_field_array(proto_at, hf, array_length(hf));
114 proto_register_subtree_array(ett, array_length(ett));
115 register_dissector("at", dissect_at, proto_at);
118 /* Handler registration */
120 proto_reg_handoff_at_command(void)
122 heur_dissector_add("usb.bulk", heur_dissect_at, proto_at);
123 heur_dissector_add("usb.control", heur_dissect_at, proto_at);