summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-bthsp.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:53 +0000
commita86c5f7cae7ec9a3398300555a0b644689d946a1 (patch)
tree39fe4b107c71174fd1e8a8ceb9a4d2aa14116248 /epan/dissectors/packet-bthsp.c
parentReleasing progress-linux version 4.2.6-1~progress7.99u1. (diff)
downloadwireshark-a86c5f7cae7ec9a3398300555a0b644689d946a1.tar.xz
wireshark-a86c5f7cae7ec9a3398300555a0b644689d946a1.zip
Merging upstream version 4.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--epan/dissectors/packet-bthsp.c298
1 files changed, 150 insertions, 148 deletions
diff --git a/epan/dissectors/packet-bthsp.c b/epan/dissectors/packet-bthsp.c
index c62f7017..6a64bd2f 100644
--- a/epan/dissectors/packet-bthsp.c
+++ b/epan/dissectors/packet-bthsp.c
@@ -16,43 +16,45 @@
#include <epan/prefs.h>
#include <epan/expert.h>
#include <epan/strutil.h>
+#include <epan/unit_strings.h>
+
#include "packet-btrfcomm.h"
#include "packet-btsdp.h"
-static int proto_bthsp = -1;
-
-static int hf_command = -1;
-static int hf_parameters = -1;
-static int hf_command_in = -1;
-static int hf_unsolicited = -1;
-static int hf_role = -1;
-static int hf_at_cmd = -1;
-static int hf_at_cmd_type = -1;
-static int hf_at_command_line_prefix = -1;
-static int hf_at_ignored = -1;
-static int hf_parameter = -1;
-static int hf_unknown_parameter = -1;
-static int hf_data = -1;
-static int hf_fragment = -1;
-static int hf_fragmented = -1;
-static int hf_vgs = -1;
-static int hf_vgm = -1;
-static int hf_ckpd = -1;
-
-static expert_field ei_non_mandatory_command = EI_INIT;
-static expert_field ei_invalid_usage = EI_INIT;
-static expert_field ei_unknown_parameter = EI_INIT;
-static expert_field ei_vgm_gain = EI_INIT;
-static expert_field ei_vgs_gain = EI_INIT;
-static expert_field ei_ckpd = EI_INIT;
-
-static gint ett_bthsp = -1;
-static gint ett_bthsp_command = -1;
-static gint ett_bthsp_parameters = -1;
+static int proto_bthsp;
+
+static int hf_command;
+static int hf_parameters;
+static int hf_command_in;
+static int hf_unsolicited;
+static int hf_role;
+static int hf_at_cmd;
+static int hf_at_cmd_type;
+static int hf_at_command_line_prefix;
+static int hf_at_ignored;
+static int hf_parameter;
+static int hf_unknown_parameter;
+static int hf_data;
+static int hf_fragment;
+static int hf_fragmented;
+static int hf_vgs;
+static int hf_vgm;
+static int hf_ckpd;
+
+static expert_field ei_non_mandatory_command;
+static expert_field ei_invalid_usage;
+static expert_field ei_unknown_parameter;
+static expert_field ei_vgm_gain;
+static expert_field ei_vgs_gain;
+static expert_field ei_ckpd;
+
+static int ett_bthsp;
+static int ett_bthsp_command;
+static int ett_bthsp_parameters;
static dissector_handle_t bthsp_handle;
-static wmem_tree_t *fragments = NULL;
+static wmem_tree_t *fragments;
#define ROLE_UNKNOWN 0
#define ROLE_AG 1
@@ -66,7 +68,7 @@ static wmem_tree_t *fragments = NULL;
#define TYPE_READ 0x003f
#define TYPE_TEST 0x3d3f
-static gint hsp_role = ROLE_UNKNOWN;
+static int hsp_role = ROLE_UNKNOWN;
enum reassemble_state_t {
REASSEMBLE_FRAGMENT,
@@ -75,19 +77,19 @@ enum reassemble_state_t {
};
typedef struct _fragment_t {
- guint32 interface_id;
- guint32 adapter_id;
- guint32 chandle;
- guint32 dlci;
- guint32 role;
-
- guint idx;
- guint length;
- guint8 *data;
+ uint32_t interface_id;
+ uint32_t adapter_id;
+ uint32_t chandle;
+ uint32_t dlci;
+ uint32_t role;
+
+ unsigned idx;
+ unsigned length;
+ uint8_t *data;
struct _fragment_t *previous_fragment;
- guint reassemble_start_offset;
- guint reassemble_end_offset;
+ unsigned reassemble_start_offset;
+ unsigned reassemble_end_offset;
enum reassemble_state_t reassemble_state;
} fragment_t;
@@ -95,11 +97,11 @@ typedef struct _at_cmd_t {
const char *name;
const char *long_name;
- gboolean (*check_command)(gint role, guint16 type);
- gboolean (*dissect_parameter)(tvbuff_t *tvb, packet_info *pinfo,
- proto_tree *tree, gint offset, gint role, guint16 type,
- guint8 *parameter_stream, guint parameter_number,
- gint parameter_length, void **data);
+ bool (*check_command)(int role, uint16_t type);
+ bool (*dissect_parameter)(tvbuff_t *tvb, packet_info *pinfo,
+ proto_tree *tree, int offset, int role, uint16_t type,
+ uint8_t *parameter_stream, unsigned parameter_number,
+ int parameter_length, void **data);
} at_cmd_t;
static const value_string role_vals[] = {
@@ -131,56 +133,56 @@ static const unit_name_string units_slash15 = { "/15", NULL };
void proto_register_bthsp(void);
void proto_reg_handoff_bthsp(void);
-static guint32 get_uint_parameter(guint8 *parameter_stream, gint parameter_length)
+static uint32_t get_uint_parameter(uint8_t *parameter_stream, int parameter_length)
{
- guint32 value;
- gchar *val;
+ uint32_t value;
+ char *val;
- val = (guint8 *) wmem_alloc(wmem_packet_scope(), parameter_length + 1);
+ val = (uint8_t *) wmem_alloc(wmem_packet_scope(), parameter_length + 1);
memcpy(val, parameter_stream, parameter_length);
val[parameter_length] = '\0';
- value = (guint32) g_ascii_strtoull(val, NULL, 10);
+ value = (uint32_t) g_ascii_strtoull(val, NULL, 10);
return value;
}
-static gboolean check_vgs(gint role, guint16 type) {
- if (role == ROLE_HS && type == TYPE_ACTION) return TRUE;
- if (role == ROLE_AG && type == TYPE_RESPONSE) return TRUE;
+static bool check_vgs(int role, uint16_t type) {
+ if (role == ROLE_HS && type == TYPE_ACTION) return true;
+ if (role == ROLE_AG && type == TYPE_RESPONSE) return true;
- return FALSE;
+ return false;
}
-static gboolean check_vgm(gint role, guint16 type) {
- if (role == ROLE_HS && type == TYPE_ACTION) return TRUE;
- if (role == ROLE_AG && type == TYPE_RESPONSE) return TRUE;
+static bool check_vgm(int role, uint16_t type) {
+ if (role == ROLE_HS && type == TYPE_ACTION) return true;
+ if (role == ROLE_AG && type == TYPE_RESPONSE) return true;
- return FALSE;
+ return false;
}
-static gboolean check_ckpd(gint role, guint16 type) {
- if (role == ROLE_HS && type == TYPE_ACTION) return TRUE;
+static bool check_ckpd(int role, uint16_t type) {
+ if (role == ROLE_HS && type == TYPE_ACTION) return true;
- return FALSE;
+ return false;
}
-static gboolean check_only_ag_role(gint role, guint16 type) {
- if (role == ROLE_AG && type == TYPE_RESPONSE_ACK) return TRUE;
+static bool check_only_ag_role(int role, uint16_t type) {
+ if (role == ROLE_AG && type == TYPE_RESPONSE_ACK) return true;
- return FALSE;
+ return false;
}
-static gint
+static bool
dissect_vgs_parameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
- gint offset, gint role, guint16 type, guint8 *parameter_stream,
- guint parameter_number, gint parameter_length, void **data _U_)
+ int offset, int role, uint16_t type, uint8_t *parameter_stream,
+ unsigned parameter_number, int parameter_length, void **data _U_)
{
proto_item *pitem;
- guint32 value;
+ uint32_t value;
- if (!check_vgs(role, type)) return FALSE;
+ if (!check_vgs(role, type)) return false;
- if (parameter_number > 0) return FALSE;
+ if (parameter_number > 0) return false;
value = get_uint_parameter(parameter_stream, parameter_length);
@@ -190,20 +192,20 @@ dissect_vgs_parameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
expert_add_info(pinfo, pitem, &ei_vgs_gain);
}
- return TRUE;
+ return true;
}
-static gint
+static bool
dissect_vgm_parameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
- gint offset, gint role, guint16 type, guint8 *parameter_stream,
- guint parameter_number, gint parameter_length, void **data _U_)
+ int offset, int role, uint16_t type, uint8_t *parameter_stream,
+ unsigned parameter_number, int parameter_length, void **data _U_)
{
proto_item *pitem;
- guint32 value;
+ uint32_t value;
- if (!check_vgm(role, type)) return FALSE;
+ if (!check_vgm(role, type)) return false;
- if (parameter_number > 0) return FALSE;
+ if (parameter_number > 0) return false;
value = get_uint_parameter(parameter_stream, parameter_length);
@@ -213,21 +215,21 @@ dissect_vgm_parameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
expert_add_info(pinfo, pitem, &ei_vgm_gain);
}
- return TRUE;
+ return true;
}
-static gint
+static bool
dissect_ckpd_parameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
- gint offset, gint role, guint16 type, guint8 *parameter_stream,
- guint parameter_number, gint parameter_length, void **data _U_)
+ int offset, int role, uint16_t type, uint8_t *parameter_stream,
+ unsigned parameter_number, int parameter_length, void **data _U_)
{
proto_item *pitem;
- guint32 value;
+ uint32_t value;
- if (!check_ckpd(role, type)) return FALSE;
+ if (!check_ckpd(role, type)) return false;
- if (parameter_number > 0) return FALSE;
+ if (parameter_number > 0) return false;
value = get_uint_parameter(parameter_stream, parameter_length);
@@ -237,15 +239,15 @@ dissect_ckpd_parameter(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
expert_add_info(pinfo, pitem, &ei_ckpd);
}
- return TRUE;
+ return true;
}
-static gint
+static bool
dissect_no_parameter(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_,
- gint offset _U_, gint role _U_, guint16 type _U_, guint8 *parameter_stream _U_,
- guint parameter_number _U_, gint parameter_length _U_, void **data _U_)
+ int offset _U_, int role _U_, uint16_t type _U_, uint8_t *parameter_stream _U_,
+ unsigned parameter_number _U_, int parameter_length _U_, void **data _U_)
{
- return FALSE;
+ return false;
}
static const at_cmd_t at_cmds[] = {
@@ -259,9 +261,9 @@ static const at_cmd_t at_cmds[] = {
};
-static gint
+static int
dissect_at_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
- gint offset, guint32 role, gint command_number)
+ int offset, uint32_t role, int command_number)
{
proto_item *pitem;
proto_tree *command_item;
@@ -271,18 +273,18 @@ dissect_at_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
char *col_str = NULL;
char *at_stream;
char *at_command = NULL;
- gint i_char = 0;
- guint i_char_fix = 0;
- gint length;
+ int i_char = 0;
+ unsigned i_char_fix = 0;
+ int length;
const at_cmd_t *i_at_cmd;
- gint parameter_length;
- guint parameter_number = 0;
- gint first_parameter_offset = offset;
- gint last_parameter_offset = offset;
- guint16 type = TYPE_UNKNOWN;
- guint32 brackets;
- gboolean quotation;
- gboolean next;
+ int parameter_length;
+ unsigned parameter_number = 0;
+ int first_parameter_offset = offset;
+ int last_parameter_offset = offset;
+ uint16_t type = TYPE_UNKNOWN;
+ uint32_t brackets;
+ bool quotation;
+ bool next;
void *data;
length = tvb_reported_length_remaining(tvb, offset);
@@ -291,12 +293,12 @@ dissect_at_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
if (!command_number) {
proto_tree_add_item(tree, hf_data, tvb, offset, length, ENC_NA | ENC_ASCII);
- col_str = (char *) wmem_alloc(wmem_packet_scope(), length + 1);
+ col_str = (char *) wmem_alloc(pinfo->pool, length + 1);
tvb_memcpy(tvb, col_str, offset, length);
col_str[length] = '\0';
}
- at_stream = (char *) wmem_alloc(wmem_packet_scope(), length + 1);
+ at_stream = (char *) wmem_alloc(pinfo->pool, length + 1);
tvb_memcpy(tvb, at_stream, offset, length);
at_stream[length] = '\0';
while (at_stream[i_char]) {
@@ -322,7 +324,7 @@ dissect_at_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
at_command = g_strstr_len(at_stream, length, "AT");
if (at_command) {
- i_char = (gint) (at_command - at_stream);
+ i_char = (int) (at_command - at_stream);
if (i_char) {
proto_tree_add_item(command_tree, hf_at_ignored, tvb, offset,
@@ -378,7 +380,7 @@ dissect_at_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
while (i_at_cmd->name) {
if (g_str_has_prefix(&at_command[0], i_at_cmd->name)) {
pitem = proto_tree_add_item(command_tree, hf_at_cmd, tvb, offset,
- (gint) strlen(i_at_cmd->name), ENC_NA | ENC_ASCII);
+ (int) strlen(i_at_cmd->name), ENC_NA | ENC_ASCII);
proto_item_append_text(pitem, " (%s)", i_at_cmd->long_name);
break;
}
@@ -395,7 +397,7 @@ dissect_at_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
if (i_at_cmd && i_at_cmd->name == NULL) {
char *name;
- name = format_text(wmem_packet_scope(), at_command, i_char + 1);
+ name = format_text(pinfo->pool, at_command, i_char + 1);
proto_item_append_text(command_item, ": %s (Unknown)", name);
proto_item_append_text(pitem, " (Unknown - Non-Standard HSP Command)");
expert_add_info(pinfo, pitem, &ei_non_mandatory_command);
@@ -448,23 +450,23 @@ dissect_at_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
parameter_length = 0;
brackets = 0;
- quotation = FALSE;
- next = FALSE;
+ quotation = false;
+ next = false;
if (at_command[i_char + parameter_length] != '\r') {
while (i_char + parameter_length < length &&
at_command[i_char + parameter_length] != '\r') {
if (at_command[i_char + parameter_length] == ';') {
- next = TRUE;
+ next = true;
break;
}
if (at_command[i_char + parameter_length] == '"') {
- quotation = quotation ? FALSE : TRUE;
+ quotation = quotation ? false : true;
}
- if (quotation == TRUE) {
+ if (quotation == true) {
parameter_length += 1;
continue;
}
@@ -597,7 +599,7 @@ dissect_at_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
proto_item_append_text(parameters_item, ": No");
if (role == ROLE_AG) {
- guint command_frame_number = 0;
+ unsigned command_frame_number = 0;
if (command_frame_number) {
pitem = proto_tree_add_uint(command_tree, hf_command_in, tvb, offset,
@@ -612,34 +614,34 @@ dissect_at_command(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
return offset;
}
-static gint
+static int
dissect_bthsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
proto_item *main_item;
proto_tree *main_tree;
proto_item *pitem;
- gint offset = 0;
- guint32 role = ROLE_UNKNOWN;
+ int offset = 0;
+ uint32_t role = ROLE_UNKNOWN;
wmem_tree_key_t key[10];
- guint32 interface_id;
- guint32 adapter_id;
- guint32 chandle;
- guint32 dlci;
- guint32 frame_number;
- guint32 direction;
- guint32 bd_addr_oui;
- guint32 bd_addr_id;
+ uint32_t interface_id;
+ uint32_t adapter_id;
+ uint32_t chandle;
+ uint32_t dlci;
+ uint32_t frame_number;
+ uint32_t direction;
+ uint32_t bd_addr_oui;
+ uint32_t bd_addr_id;
fragment_t *fragment;
fragment_t *previous_fragment;
fragment_t *i_fragment;
- guint8 *at_stream;
- gint length;
- gint command_number;
- gint i_length;
+ uint8_t *at_stream;
+ int length;
+ int command_number;
+ int i_length;
tvbuff_t *reassembled_tvb = NULL;
- guint reassemble_start_offset = 0;
- guint reassemble_end_offset = 0;
- gint previous_proto;
+ unsigned reassemble_start_offset = 0;
+ unsigned reassemble_end_offset = 0;
+ int previous_proto;
previous_proto = (GPOINTER_TO_INT(wmem_list_frame_data(wmem_list_frame_prev(wmem_list_tail(pinfo->layers)))));
if (data && previous_proto == proto_btrfcomm) {
@@ -696,9 +698,9 @@ dissect_bthsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
}
if (role == ROLE_UNKNOWN) {
- guint32 sdp_psm;
- guint32 service_type;
- guint32 service_channel;
+ uint32_t sdp_psm;
+ uint32_t service_type;
+ uint32_t service_channel;
service_info_t *service_info;
sdp_psm = SDP_PSM_DEFAULT;
@@ -816,7 +818,7 @@ dissect_bthsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
fragment->idx = previous_fragment ? previous_fragment->idx + previous_fragment->length : 0;
fragment->reassemble_state = REASSEMBLE_FRAGMENT;
fragment->length = tvb_reported_length(tvb);
- fragment->data = (guint8 *) wmem_alloc(wmem_file_scope(), fragment->length);
+ fragment->data = (uint8_t *) wmem_alloc(wmem_file_scope(), fragment->length);
fragment->previous_fragment = previous_fragment;
tvb_memcpy(tvb, fragment->data, offset, fragment->length);
@@ -824,7 +826,7 @@ dissect_bthsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
/* Detect reassemble end character: \r for HS or \n for AG */
length = tvb_reported_length(tvb);
- at_stream = tvb_get_string_enc(wmem_packet_scope(), tvb, 0, length, ENC_ASCII);
+ at_stream = tvb_get_string_enc(pinfo->pool, tvb, 0, length, ENC_ASCII);
reassemble_start_offset = 0;
@@ -929,11 +931,11 @@ dissect_bthsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
fragment->dlci == dlci &&
fragment->role == role &&
fragment->reassemble_state != REASSEMBLE_FRAGMENT) {
- guint8 *at_data;
- guint i_data_offset;
+ uint8_t *at_data;
+ unsigned i_data_offset;
i_data_offset = fragment->idx + fragment->length;
- at_data = (guint8 *) wmem_alloc(pinfo->pool, fragment->idx + fragment->length);
+ at_data = (uint8_t *) wmem_alloc(pinfo->pool, fragment->idx + fragment->length);
i_fragment = fragment;
@@ -970,7 +972,7 @@ dissect_bthsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
command_number = 0;
if (reassembled_tvb) {
- guint reassembled_offset = 0;
+ unsigned reassembled_offset = 0;
while (tvb_reported_length(reassembled_tvb) > reassembled_offset) {
reassembled_offset = dissect_at_command(reassembled_tvb,
@@ -979,7 +981,7 @@ dissect_bthsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
}
offset = tvb_captured_length(tvb);
} else {
- while (tvb_reported_length(tvb) > (guint) offset) {
+ while (tvb_reported_length(tvb) > (unsigned) offset) {
offset = dissect_at_command(tvb, pinfo, main_tree, offset, role, command_number);
command_number += 1;
}
@@ -1075,12 +1077,12 @@ proto_register_bthsp(void)
},
{ &hf_vgs,
{ "Gain", "bthsp.vgs",
- FT_UINT8, BASE_DEC|BASE_UNIT_STRING, &units_slash15, 0,
+ FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_slash15), 0,
NULL, HFILL}
},
{ &hf_vgm,
{ "Gain", "bthsp.vgm",
- FT_UINT8, BASE_DEC|BASE_UNIT_STRING, &units_slash15, 0,
+ FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_slash15), 0,
NULL, HFILL}
},
{ &hf_ckpd,
@@ -1098,7 +1100,7 @@ proto_register_bthsp(void)
{ &ei_vgs_gain, { "bthsp.expert.vgs", PI_PROTOCOL, PI_WARN, "Gain of speaker exceeds range 0-15", EXPFILL }},
{ &ei_ckpd, { "bthsp.expert.ckpd", PI_PROTOCOL, PI_WARN, "Only key 200 is covered in HSP", EXPFILL }} };
- static gint *ett[] = {
+ static int *ett[] = {
&ett_bthsp,
&ett_bthsp_command,
&ett_bthsp_parameters
@@ -1120,7 +1122,7 @@ proto_register_bthsp(void)
prefs_register_enum_preference(module, "hsp.hsp_role",
"Force treat packets as AG or HS role",
"Force treat packets as AG or HS role",
- &hsp_role, pref_hsp_role, TRUE);
+ &hsp_role, pref_hsp_role, true);
expert_bthsp = expert_register_protocol(proto_bthsp);
expert_register_field_array(expert_bthsp, ei, array_length(ei));