2012-01-24 20:29:32 +00:00
|
|
|
/* packet-at.c
|
|
|
|
* Dissector for AT Commands
|
2011-05-10 17:04:05 +00:00
|
|
|
*
|
|
|
|
* Copyright 2011, Tyson Key <tyson.key@gmail.com>
|
|
|
|
*
|
2011-05-10 17:06:20 +00:00
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2011-05-10 17:04:05 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-05-10 17:04:05 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2013-03-14 07:37:13 +00:00
|
|
|
void proto_register_at_command(void);
|
|
|
|
void proto_reg_handoff_at_command(void);
|
2013-03-13 21:14:20 +00:00
|
|
|
|
2011-05-10 17:04:05 +00:00
|
|
|
static int proto_at = -1;
|
|
|
|
static int hf_at_command = -1;
|
|
|
|
|
|
|
|
/* Forward-declare the dissector functions */
|
|
|
|
static void dissect_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
|
|
|
|
|
|
|
|
/* Subtree handles: set by register_subtree_array */
|
|
|
|
static gint ett_at = -1;
|
|
|
|
|
|
|
|
static gboolean allowed_chars(tvbuff_t *tvb)
|
|
|
|
{
|
|
|
|
gint offset, len;
|
|
|
|
guint8 val;
|
|
|
|
|
2011-05-11 20:40:14 +00:00
|
|
|
len = tvb_length(tvb);
|
2011-05-10 17:04:05 +00:00
|
|
|
for (offset = 0; offset < len; offset++) {
|
|
|
|
val = tvb_get_guint8(tvb, offset);
|
|
|
|
if (!(isprint(val) || (val == 0x0a) || (val == 0x0d)))
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Experimental approach based upon the one used for PPP */
|
2012-09-10 21:40:21 +00:00
|
|
|
static gboolean heur_dissect_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
|
2011-05-10 17:04:05 +00:00
|
|
|
{
|
2011-05-14 14:57:58 +00:00
|
|
|
const gchar at_magic1[2] = {0x0d, 0x0a};
|
|
|
|
const gchar at_magic2[3] = {0x0d, 0x0d, 0x0a};
|
|
|
|
const gchar at_magic3[2] = {'A', 'T'};
|
2011-05-10 17:04:05 +00:00
|
|
|
|
2011-05-14 14:57:58 +00:00
|
|
|
if (((tvb_memeql(tvb, 0, at_magic1, sizeof(at_magic1)) == 0) ||
|
|
|
|
(tvb_memeql(tvb, 0, at_magic2, sizeof(at_magic2)) == 0) ||
|
|
|
|
(tvb_memeql(tvb, 0, at_magic3, sizeof(at_magic3)) == 0)) &&
|
2011-05-10 17:04:05 +00:00
|
|
|
allowed_chars(tvb)) {
|
|
|
|
dissect_at(tvb, pinfo, tree);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The dissector itself */
|
|
|
|
static void dissect_at(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
proto_item *item;
|
|
|
|
proto_tree *at_tree;
|
|
|
|
gint len;
|
|
|
|
|
|
|
|
len = tvb_reported_length(tvb);
|
|
|
|
col_append_str(pinfo->cinfo, COL_PROTOCOL, "/AT");
|
|
|
|
col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "AT Command: %s",
|
|
|
|
tvb_format_text_wsp(tvb, 0, len));
|
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
/* Start with a top-level item to add everything else to */
|
|
|
|
item = proto_tree_add_item(tree, proto_at, tvb, 0, -1, ENC_NA);
|
|
|
|
at_tree = proto_item_add_subtree(item, ett_at);
|
|
|
|
|
|
|
|
/* Command */
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item(at_tree, hf_at_command, tvb, 0, len, ENC_ASCII|ENC_NA);
|
2011-05-10 17:04:05 +00:00
|
|
|
proto_item_append_text(item, ": %s", tvb_format_text_wsp(tvb, 0, len));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_at_command(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_at_command,
|
|
|
|
{ "AT Command", "at.command", FT_STRING, BASE_NONE,
|
|
|
|
NULL, 0x0, NULL, HFILL }}
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_at
|
|
|
|
};
|
|
|
|
|
|
|
|
proto_at = proto_register_protocol("AT Command", "AT", "at");
|
|
|
|
proto_register_field_array(proto_at, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
register_dissector("at", dissect_at, proto_at);
|
|
|
|
}
|
|
|
|
|
2011-05-11 13:36:17 +00:00
|
|
|
/* Handler registration */
|
|
|
|
void
|
|
|
|
proto_reg_handoff_at_command(void)
|
|
|
|
{
|
2012-01-24 20:29:32 +00:00
|
|
|
heur_dissector_add("usb.bulk", heur_dissect_at, proto_at);
|
|
|
|
heur_dissector_add("usb.control", heur_dissect_at, proto_at);
|
2011-05-11 13:36:17 +00:00
|
|
|
}
|
|
|
|
|