2 * Dissector for AT Commands
4 * Copyright 2011, Tyson Key <tyson.key@gmail.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <epan/packet.h>
30 void proto_register_at_command(void);
31 void proto_reg_handoff_at_command(void);
33 static int proto_at = -1;
34 static int hf_at_command = -1;
36 /* Subtree handles: set by register_subtree_array */
37 static gint ett_at = -1;
39 static gboolean allowed_chars(tvbuff_t *tvb)
44 len = tvb_reported_length(tvb);
45 for (offset = 0; offset < len; offset++) {
46 val = tvb_get_guint8(tvb, offset);
47 if (!(g_ascii_isprint(val) || (val == 0x0a) || (val == 0x0d)))
53 /* The dissector itself */
54 static int dissect_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
60 len = tvb_reported_length(tvb);
61 col_append_sep_str(pinfo->cinfo, COL_PROTOCOL, "/", "AT");
62 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "AT Command: %s",
63 tvb_format_text_wsp(tvb, 0, len));
66 /* Start with a top-level item to add everything else to */
67 item = proto_tree_add_item(tree, proto_at, tvb, 0, -1, ENC_NA);
68 at_tree = proto_item_add_subtree(item, ett_at);
71 proto_tree_add_item(at_tree, hf_at_command, tvb, 0, len, ENC_ASCII|ENC_NA);
72 proto_item_append_text(item, ": %s", tvb_format_text_wsp(tvb, 0, len));
74 return tvb_captured_length(tvb);
78 /* Experimental approach based upon the one used for PPP */
79 static gboolean heur_dissect_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
81 const gchar at_magic1[2] = {0x0d, 0x0a};
82 const gchar at_magic2[3] = {0x0d, 0x0d, 0x0a};
83 const gchar at_magic3[2] = {'A', 'T'};
85 if (((tvb_memeql(tvb, 0, at_magic1, sizeof(at_magic1)) == 0) ||
86 (tvb_memeql(tvb, 0, at_magic2, sizeof(at_magic2)) == 0) ||
87 (tvb_memeql(tvb, 0, at_magic3, sizeof(at_magic3)) == 0)) &&
89 dissect_at(tvb, pinfo, tree, data);
96 proto_register_at_command(void)
98 static hf_register_info hf[] = {
100 { "AT Command", "at.command", FT_STRING, BASE_NONE,
101 NULL, 0x0, NULL, HFILL }}
104 static gint *ett[] = {
108 proto_at = proto_register_protocol("AT Command", "AT", "at");
109 proto_register_field_array(proto_at, hf, array_length(hf));
110 proto_register_subtree_array(ett, array_length(ett));
111 register_dissector("at", dissect_at, proto_at);
114 /* Handler registration */
116 proto_reg_handoff_at_command(void)
118 heur_dissector_add("usb.bulk", heur_dissect_at, "AT Command USB bulk endpoint", "at_usb_bulk", proto_at, HEURISTIC_ENABLE);
119 heur_dissector_add("usb.control", heur_dissect_at, "AT Command USB control endpoint", "at_usb_control", proto_at, HEURISTIC_ENABLE);
123 * Editor modelines - http://www.wireshark.org/tools/modelines.html
128 * indent-tabs-mode: nil
131 * vi: set shiftwidth=4 tabstop=8 expandtab:
132 * :indentSize=4:tabSize=8:noTabs=true: