📄 packet-gryphon.c
字号:
/* packet-gryphon.c * Routines for Gryphon protocol packet disassembly * By Steve Limkemann <stevelim@dgtech.com> * Copyright 1998 Steve Limkemann * * $Id: packet-gryphon.c,v 1.27 2002/01/21 07:37:48 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> * Copyright 1998 * * 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 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "plugins/plugin_api.h"#include "moduleinfo.h"#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif#include <string.h>#include <ctype.h>#include <time.h>#include <gmodule.h>#ifdef HAVE_NETINET_IN_H# include <netinet/in.h>#endif#include <epan/packet.h>#include "packet-gryphon.h"#include "plugins/plugin_api_defs.h"#ifndef __ETHEREAL_STATIC__G_MODULE_EXPORT const gchar version[] = VERSION;#endif#ifndef G_HAVE_GINT64#error "Sorry, this won't compile without 64-bit integer support"#endif /* * See * * http://www.dgtech.com/gryphon/docs/html/ */static int proto_gryphon = -1;static int hf_gryph_src = -1;static int hf_gryph_srcchan = -1;static int hf_gryph_dest = -1;static int hf_gryph_destchan= -1;static int hf_gryph_type = -1;static int hf_gryph_cmd = -1;static gint ett_gryphon = -1;static gint ett_gryphon_header = -1;static gint ett_gryphon_body = -1;static gint ett_gryphon_command_data = -1;static gint ett_gryphon_response_data = -1;static gint ett_gryphon_data_header = -1;static gint ett_gryphon_flags = -1;static gint ett_gryphon_data_body = -1;static gint ett_gryphon_cmd_filter_block = -1;static gint ett_gryphon_cmd_events_data = -1;static gint ett_gryphon_cmd_config_device = -1;static gint ett_gryphon_cmd_sched_data = -1;static gint ett_gryphon_cmd_sched_cmd = -1;static gint ett_gryphon_cmd_response_block = -1;static gint ett_gryphon_pgm_list = -1;static gint ett_gryphon_pgm_status = -1;static gint ett_gryphon_pgm_options = -1;static int dissect_gryphon_message(tvbuff_t *tvb, int offset, proto_tree *tree, gboolean is_msgresp_add);static int decode_command(tvbuff_t*, int, int, int, proto_tree*);static int decode_response(tvbuff_t*, int, int, int, proto_tree*);static int decode_data(tvbuff_t*, int, int, int, proto_tree*);static int decode_event(tvbuff_t*, int, int, int, proto_tree*);static int cmd_init(tvbuff_t*, int, int, int, proto_tree*);static int resp_time(tvbuff_t*, int, int, int, proto_tree*);static int cmd_setfilt(tvbuff_t*, int, int, int, proto_tree*);static int cmd_ioctl(tvbuff_t*, int, int, int, proto_tree*);static int cmd_addfilt(tvbuff_t*, int, int, int, proto_tree*);static int resp_addfilt(tvbuff_t*, int, int, int, proto_tree*);static int cmd_modfilt(tvbuff_t*, int, int, int, proto_tree*);static int resp_filthan(tvbuff_t*, int, int, int, proto_tree*);static int dfiltmode(tvbuff_t*, int, int, int, proto_tree*);static int filtmode(tvbuff_t*, int, int, int, proto_tree*);static int resp_events(tvbuff_t*, int, int, int, proto_tree*);static int cmd_register(tvbuff_t*, int, int, int, proto_tree*);static int resp_register(tvbuff_t*, int, int, int, proto_tree*);static int resp_getspeeds(tvbuff_t*, int, int, int, proto_tree*);static int cmd_sort(tvbuff_t*, int, int, int, proto_tree*);static int cmd_optimize(tvbuff_t*, int, int, int, proto_tree*);static int resp_config(tvbuff_t*, int, int, int, proto_tree*);static int cmd_sched(tvbuff_t*, int, int, int, proto_tree*);static int resp_blm_data(tvbuff_t*, int, int, int, proto_tree*);static int resp_blm_stat(tvbuff_t*, int, int, int, proto_tree*);static int cmd_addresp(tvbuff_t*, int, int, int, proto_tree*);static int resp_addresp(tvbuff_t*, int, int, int, proto_tree*);static int cmd_modresp(tvbuff_t*, int, int, int, proto_tree*);static int resp_resphan(tvbuff_t*, int, int, int, proto_tree*);static int resp_sched(tvbuff_t*, int, int, int, proto_tree*);static int cmd_desc(tvbuff_t*, int, int, int, proto_tree*);static int resp_desc(tvbuff_t*, int, int, int, proto_tree*);static int cmd_upload(tvbuff_t*, int, int, int, proto_tree*);static int cmd_delete(tvbuff_t*, int, int, int, proto_tree*);static int cmd_list(tvbuff_t*, int, int, int, proto_tree*);static int resp_list(tvbuff_t*, int, int, int, proto_tree*);static int cmd_start(tvbuff_t*, int, int, int, proto_tree*);static int resp_start(tvbuff_t*, int, int, int, proto_tree*);static int resp_status(tvbuff_t*, int, int, int, proto_tree*);static int cmd_options(tvbuff_t*, int, int, int, proto_tree*);static int cmd_files(tvbuff_t*, int, int, int, proto_tree*);static int resp_files(tvbuff_t*, int, int, int, proto_tree*);static int eventnum(tvbuff_t*, int, int, int, proto_tree*);static int speed(tvbuff_t*, int, int, int, proto_tree*);static int filter_block(tvbuff_t*, int, int, int, proto_tree*);static int blm_mode(tvbuff_t*, int, int, int, proto_tree*);static int cmd_usdt(tvbuff_t*, int, int, int, proto_tree*);static char *frame_type[] = { "", "Command request", "Command response", "Network (vehicle) data", "Event", "Miscellaneous", "Text string"};static voiddissect_gryphon(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree){ int offset; proto_item *ti; proto_tree *gryphon_tree; guint8 frmtyp; if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_set_str(pinfo->cinfo, COL_PROTOCOL, "Gryphon"); if (check_col(pinfo->cinfo, COL_INFO)) col_clear(pinfo->cinfo, COL_INFO); ti = proto_tree_add_item(tree, proto_gryphon, tvb, 0, tvb_length(tvb), FALSE); gryphon_tree = proto_item_add_subtree(ti, ett_gryphon); if (check_col(pinfo->cinfo, COL_INFO)) { /* * Indicate what kind of message the first message is. */ frmtyp = tvb_get_guint8(tvb, 6) & ~RESPONSE_FLAGS; if (frmtyp >= SIZEOF (frame_type)) col_set_str(pinfo->cinfo, COL_INFO, "- Invalid -"); else col_set_str(pinfo->cinfo, COL_INFO, frame_type[frmtyp]); } if (tree) { offset = 0; while (tvb_reported_length_remaining(tvb, offset) > 0) offset = dissect_gryphon_message(tvb, offset, gryphon_tree, FALSE); }}static intdissect_gryphon_message(tvbuff_t *tvb, int offset, proto_tree *tree, gboolean is_msgresp_add){ proto_tree *header_tree, *body_tree, *localTree; proto_item *header_item, *body_item, *localItem; int start_offset, msgend; int msglen, msgpad; unsigned int src, dest, i, frmtyp; guint8 flags; static const value_string src_dest[] = { {SD_CARD, "Card"}, {SD_SERVER, "Server"}, {SD_CLIENT, "Client"}, {SD_SCHED, "Scheduler"}, {SD_SCRIPT, "Script Processor"}, {SD_PGM, "Program Loader"}, {SD_USDT, "USDT Server"}, {SD_BLM, "Bus Load Monitoring"}, {SD_FLIGHT, "Flight Recorder"}, {SD_RESP, "Message Responder"}, {-1, "- unknown -"}, }; src = tvb_get_guint8(tvb, offset + 0); dest = tvb_get_guint8(tvb, offset + 2); msglen = tvb_get_ntohs(tvb, offset + 4); flags = tvb_get_guint8(tvb, offset + 6); frmtyp = flags & ~RESPONSE_FLAGS; if (frmtyp >= SIZEOF (frame_type)) { /* * Unknown message type. */ proto_tree_add_text(tree, tvb, offset, msglen, "Data"); offset += msglen; return offset; } header_item = proto_tree_add_text(tree, tvb, offset, MSG_HDR_SZ, "Header"); header_tree = proto_item_add_subtree(header_item, ett_gryphon_header); for (i = 0; i < SIZEOF(src_dest); i++) { if (src_dest[i].value == src) break; } if (i >= SIZEOF(src_dest)) i = SIZEOF(src_dest) - 1; proto_tree_add_text(header_tree, tvb, offset, 2, "Source: %s, channel %u", src_dest[i].strptr, tvb_get_guint8(tvb, offset + 1)); proto_tree_add_uint_hidden(header_tree, hf_gryph_src, tvb, offset, 1, src); proto_tree_add_uint_hidden(header_tree, hf_gryph_srcchan, tvb, offset+1, 1, tvb_get_guint8(tvb, offset + 1)); for (i = 0; i < SIZEOF(src_dest); i++) { if (src_dest[i].value == dest) break; } if (i >= SIZEOF(src_dest)) i = SIZEOF(src_dest) - 1; proto_tree_add_text(header_tree, tvb, offset+2, 2, "Destination: %s, channel %u", src_dest[i].strptr, tvb_get_guint8(tvb, offset + 3)); proto_tree_add_uint_hidden(header_tree, hf_gryph_dest, tvb, offset+2, 1, dest); proto_tree_add_uint_hidden(header_tree, hf_gryph_destchan, tvb, offset+3, 1, tvb_get_guint8(tvb, offset + 3)); proto_tree_add_text(header_tree, tvb, offset+4, 2, "Data length: %u bytes", msglen); proto_tree_add_text(header_tree, tvb, offset+6, 1, "Frame type: %s", frame_type[frmtyp]); if (is_msgresp_add) { localItem = proto_tree_add_text(header_tree, tvb, offset+6, 1, "Flags"); localTree = proto_item_add_subtree (localItem, ett_gryphon_flags); if (flags & DONT_WAIT_FOR_RESP) { proto_tree_add_text(localTree, tvb, offset+6, 1, "1... .... = Don't wait for response"); } else { proto_tree_add_text(localTree, tvb, offset+6, 1, "0... .... = Wait for response"); } if (flags & WAIT_FOR_PREV_RESP) { proto_tree_add_text(localTree, tvb, offset+6, 1, ".1.. .... = Wait for previous responses"); } else { proto_tree_add_text(localTree, tvb, offset+6, 1, ".0.. .... = Don't wait for previous responses"); } } proto_tree_add_text(header_tree, tvb, offset+7, 1, "reserved"); proto_tree_add_uint_hidden(header_tree, hf_gryph_type, tvb, offset+6, 1, frmtyp); msgpad = 3 - (msglen + 3) % 4; msgend = offset + msglen + msgpad + MSG_HDR_SZ; body_item = proto_tree_add_text(tree, tvb, offset + MSG_HDR_SZ, msglen + msgpad, "Body"); body_tree = proto_item_add_subtree(body_item, ett_gryphon_body); start_offset = offset; offset += MSG_HDR_SZ; switch (frmtyp) { case GY_FT_CMD: offset = decode_command(tvb, offset, dest, msglen, body_tree); break; case GY_FT_RESP: offset = decode_response(tvb, offset, src, msglen, body_tree); break; case GY_FT_DATA: offset = decode_data(tvb, offset, src, msglen, body_tree); break; case GY_FT_EVENT: offset = decode_event(tvb, offset, src, msglen, body_tree); break; case GY_FT_MISC: break; case GY_FT_TEXT: break; default: break; } if (offset < msgend - msgpad) { i = msgend - msgpad - offset; proto_tree_add_text(tree, tvb, offset, i, "Data"); offset += i; } if (offset < msgend) { i = msgend - offset; proto_tree_add_text(tree, tvb, offset, i, "padding"); offset += i; } return offset;}static const val_str_dsp cmds[] = { {CMD_INIT, "Initialize", cmd_init, NULL}, {CMD_GET_STAT, "Get status", NULL, NULL}, {CMD_GET_CONFIG, "Get configuration", NULL, resp_config}, {CMD_EVENT_ENABLE, "Enable event", eventnum, NULL}, {CMD_EVENT_DISABLE, "Disable event", eventnum, NULL}, {CMD_GET_TIME, "Get time", NULL, resp_time}, {CMD_GET_RXDROP, "Get number of dropped RX messages", NULL, NULL}, {CMD_RESET_RXDROP, "Clear number of dropped RX messages", NULL, NULL}, {CMD_BCAST_ON, "Set broadcasts on", NULL, NULL}, {CMD_BCAST_OFF, "Set broadcasts off", NULL, NULL}, {CMD_CARD_SET_SPEED, "Set channel baud rate", speed, NULL}, {CMD_CARD_GET_SPEED, "Get channel baud rate", NULL, speed}, {CMD_CARD_SET_FILTER, "Set filter (deprecated)", cmd_setfilt, NULL}, {CMD_CARD_GET_FILTER, "Get filter", resp_addfilt, cmd_addfilt}, {CMD_CARD_TX, "Transmit message", decode_data, NULL}, {CMD_CARD_TX_LOOP_ON, "Set transmit loopback on", NULL, NULL}, {CMD_CARD_TX_LOOP_OFF, "Set transmit loopback off", NULL, NULL}, {CMD_CARD_IOCTL, "IOCTL pass-through", cmd_ioctl, NULL}, {CMD_CARD_ADD_FILTER, "Add a filter", cmd_addfilt, resp_addfilt}, {CMD_CARD_MODIFY_FILTER, "Modify a filter", cmd_modfilt, NULL}, {CMD_CARD_GET_FILTER_HANDLES, "Get filter handles", NULL, resp_filthan}, {CMD_CARD_SET_DEFAULT_FILTER, "Set default filter", dfiltmode, NULL}, {CMD_CARD_GET_DEFAULT_FILTER, "Get default filter mode", NULL, dfiltmode}, {CMD_CARD_SET_FILTER_MODE, "Set filter mode", filtmode, NULL}, {CMD_CARD_GET_FILTER_MODE, "Get filter mode", NULL, filtmode}, {CMD_CARD_GET_EVNAMES, "Get event names", NULL, resp_events}, {CMD_CARD_GET_SPEEDS, "Get defined speeds", NULL, resp_getspeeds}, {CMD_SERVER_REG, "Register with server", cmd_register, resp_register}, {CMD_SERVER_SET_SORT, "Set the sorting behavior", cmd_sort, NULL}, {CMD_SERVER_SET_OPT, "Set the type of optimization", cmd_optimize, NULL}, {CMD_BLM_SET_MODE, "Set Bus Load Monitoring mode", blm_mode, NULL}, {CMD_BLM_GET_MODE, "Get Bus Load Monitoring mode", NULL, blm_mode}, {CMD_BLM_GET_DATA, "Get Bus Load data", NULL, resp_blm_data}, {CMD_BLM_GET_STATS, "Get Bus Load statistics", NULL, resp_blm_stat}, {CMD_FLIGHT_GET_CONFIG, "Get flight recorder channel info", NULL, NULL}, {CMD_FLIGHT_START_MON, "Start flight recorder monitoring", NULL, NULL}, {CMD_FLIGHT_STOP_MON, "Stop flight recorder monitoring", NULL, NULL}, {CMD_MSGRESP_ADD, "Add response message", cmd_addresp, resp_addresp}, {CMD_MSGRESP_GET, "Get response message", resp_addresp, cmd_addresp}, {CMD_MSGRESP_MODIFY, "Modify response message state", cmd_modresp, NULL}, {CMD_MSGRESP_GET_HANDLES, "Get response message handles", NULL, resp_resphan}, {CMD_PGM_DESC, "Describe program to to uploaded", cmd_desc, resp_desc}, {CMD_PGM_UPLOAD, "Upload a program to the Gryphon", cmd_upload, NULL}, {CMD_PGM_DELETE, "Delete an uploaded program", cmd_delete, NULL}, {CMD_PGM_LIST, "Get a list of uploaded programs", cmd_list, resp_list}, {CMD_PGM_START, "Start an uploaded program", cmd_start, resp_start}, {CMD_PGM_STOP, "Stop an uploaded program", resp_start, NULL}, {CMD_PGM_STATUS, "Get status of an uploaded program", cmd_delete, resp_status}, {CMD_PGM_OPTIONS, "Set program upload options", cmd_options, resp_status}, {CMD_PGM_FILES, "Get a list of files & directories", cmd_files, resp_files}, {CMD_SCHED_TX, "Schedule transmission of messages", cmd_sched, resp_sched}, {CMD_SCHED_KILL_TX, "Stop and destroy a message transmission", NULL, NULL}, {CMD_SCHED_STOP_TX, "Kill a message transmission (deprecated)", NULL, NULL}, {CMD_USDT_IOCTL, "Register/Unregister with USDT server", cmd_usdt, NULL}, {-1, "- unknown -", NULL, NULL}, };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -