diff options
author | Evan Huus <eapache@gmail.com> | 2013-03-30 21:43:18 +0000 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2013-03-30 21:43:18 +0000 |
commit | 6d17f1153a0a25500ec64e64c57981d5e4217e12 (patch) | |
tree | f6b44da7616957c28ddd801ea6902c2b4d08ce0f | |
parent | 77c9d43ce42c19d7cf4815ceedeb8b4d55d7d040 (diff) |
From Michal Labedzki via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8509
Round 3 of Bluetooth SDP updates. Update the list of company IDs and fix
service recognition.
svn path=/trunk/; revision=48660
-rw-r--r-- | epan/dissectors/packet-bthci_acl.c | 5 | ||||
-rw-r--r-- | epan/dissectors/packet-bthci_acl.h | 3 | ||||
-rw-r--r-- | epan/dissectors/packet-bthci_evt.c | 24 | ||||
-rw-r--r-- | epan/dissectors/packet-btl2cap.c | 408 | ||||
-rw-r--r-- | epan/dissectors/packet-btl2cap.h | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-btrfcomm.c | 251 | ||||
-rw-r--r-- | epan/dissectors/packet-btsdp.c | 165 |
7 files changed, 450 insertions, 408 deletions
diff --git a/epan/dissectors/packet-bthci_acl.c b/epan/dissectors/packet-bthci_acl.c index f10d0bb7ae..4bbee16296 100644 --- a/epan/dissectors/packet-bthci_acl.c +++ b/epan/dissectors/packet-bthci_acl.c @@ -139,6 +139,8 @@ dissect_bthci_acl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) acl_data->interface_id = hci_data->interface_id; acl_data->adapter_id = hci_data->adapter_id; acl_data->chandle = flags & 0x0fff; + acl_data->remote_bd_addr_oui = 0; + acl_data->remote_bd_addr_id = 0; pd_save = pinfo->private_data; pinfo->private_data = acl_data; @@ -177,6 +179,9 @@ dissect_bthci_acl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) bd_addr_oui = remote_bdaddr->bd_addr[0] << 16 | remote_bdaddr->bd_addr[1] << 8 | remote_bdaddr->bd_addr[2]; bd_addr_id = remote_bdaddr->bd_addr[3] << 16 | remote_bdaddr->bd_addr[4] << 8 | remote_bdaddr->bd_addr[5]; + acl_data->remote_bd_addr_oui = bd_addr_oui; + acl_data->remote_bd_addr_id = bd_addr_id; + k_bd_addr_oui = bd_addr_oui; k_bd_addr_id = bd_addr_id; k_frame_number = pinfo->fd->num; diff --git a/epan/dissectors/packet-bthci_acl.h b/epan/dissectors/packet-bthci_acl.h index 5bb6de23c8..1c29f61097 100644 --- a/epan/dissectors/packet-bthci_acl.h +++ b/epan/dissectors/packet-bthci_acl.h @@ -28,6 +28,9 @@ typedef struct _bthci_acl_data_t { guint32 interface_id; guint32 adapter_id; guint16 chandle; /* only low 12 bits used */ + + guint32 remote_bd_addr_oui; + guint32 remote_bd_addr_id; } bthci_acl_data_t; #endif diff --git a/epan/dissectors/packet-bthci_evt.c b/epan/dissectors/packet-bthci_evt.c index e5bd5aed5d..a88208c5e5 100644 --- a/epan/dissectors/packet-bthci_evt.c +++ b/epan/dissectors/packet-bthci_evt.c @@ -644,6 +644,28 @@ static const value_string bthci_evt_comp_id[] = { {0x00A3, "Meta Watch Ltd."}, {0x00A4, "LINAK A/S"}, {0x00A5, "OTL Dynamics LLC"}, + {0x00A6, "Panda Ocean Inc."}, + {0x00A7, "Visteon Corporation"}, + {0x00A8, "ARP Devices Limited"}, + {0x00A9, "Magneti Marelli S.p.A."}, + {0x00AA, "CAEN RFID srl"}, + {0x00AB, "Ingenieur-Systemgruppe Zahn GmbH"}, + {0x00AC, "Green Throttle Games"}, + {0x00AD, "Peter Systemtechnik GmbH"}, + {0x00AE, "Omegawave Oy"}, + {0x00AF, "Cinetix"}, + {0x00B0, "Passif Semiconductor Corp"}, + {0x00B1, "Saris Cycling Group, Inc"}, + {0x00B2, "Bekey A/S"}, + {0x00B3, "Clarinox Technologies Pty. Ltd."}, + {0x00B4, "BDE Technology Co., Ltd."}, + {0x00B5, "Swirl Networks"}, + {0x00B6, "Meso international"}, + {0x00B7, "TreLab Ltd"}, + {0x00B8, "Qualcomm Innovation Center, Inc. (QuIC)"}, + {0x00B9, "Johnson Controls, Inc."}, + {0x00BA, "Starkey Laboratories Inc."}, + {0x00BB, "S-Power Electronics Limited"}, {0xFFFF, "For use in internal and interoperability tests."}, {0, NULL } }; @@ -2881,7 +2903,7 @@ dissect_bthci_evt_command_complete(tvbuff_t *tvb, int offset, packet_info *pinfo proto_tree_add_item(tree, hf_bthci_evt_physical_link_handle, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; break; - + case 0x1801: /* Read Loopback Mode */ proto_tree_add_item(tree, hf_bthci_evt_status, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset++; diff --git a/epan/dissectors/packet-btl2cap.c b/epan/dissectors/packet-btl2cap.c index e8f7a85ef2..cfb64f3bd5 100644 --- a/epan/dissectors/packet-btl2cap.c +++ b/epan/dissectors/packet-btl2cap.c @@ -134,7 +134,6 @@ static gint ett_btl2cap_extfeatures = -1; static gint ett_btl2cap_fixedchans = -1; static gint ett_btl2cap_control = -1; - /* Initialize dissector table */ static dissector_table_t l2cap_psm_dissector_table; static dissector_table_t l2cap_cid_dissector_table; @@ -144,8 +143,8 @@ static dissector_table_t l2cap_service_dissector_table; * The same table is used both for SCID and DCID. * For received CIDs we 'or' the cid with 0x80000000 in this table */ -static emem_tree_t *cid_to_psm_table = NULL; -static emem_tree_t *psm_to_service_table = NULL; +static emem_tree_t *cid_to_psm_table = NULL; +static emem_tree_t *sdp_service_infos = NULL; typedef struct _config_data_t { guint8 mode; @@ -178,15 +177,6 @@ typedef struct _psm_data_t { config_data_t out; } psm_data_t; -typedef struct _psm_service_t { - guint32 interface_id; - guint32 adapter_id; - guint32 chandle; - guint32 psm; - guint32 service; -} psm_service_t; - - static const value_string command_code_vals[] = { { 0x01, "Command Reject" }, { 0x02, "Connection Request" }, @@ -376,6 +366,90 @@ static const range_string cid_rvals[] = { void proto_register_btl2cap(void); void proto_reg_handoff_btl2cap(void); + +static guint16 +get_service_uuid(packet_info *pinfo, guint16 psm, gboolean is_local_psm) +{ + emem_tree_key_t key[10]; + guint32 k_interface_id; + guint32 k_adapter_id; + guint32 k_sdp_psm; + guint32 k_direction; + guint32 k_bd_addr_oui; + guint32 k_bd_addr_id; + guint32 k_service_type; + guint32 k_service_channel; + guint32 k_frame_number; + guint32 interface_id; + guint32 adapter_id; + guint32 remote_bd_addr_oui; + guint32 remote_bd_addr_id; + service_info_t *service_info; + btl2cap_data_t *l2cap_data; + + l2cap_data = (btl2cap_data_t *) pinfo->private_data; + + interface_id = l2cap_data->interface_id; + adapter_id = l2cap_data->adapter_id; + + k_interface_id = interface_id; + k_adapter_id = adapter_id; + k_sdp_psm = SDP_PSM_DEFAULT; + k_direction = (is_local_psm) ? P2P_DIR_SENT : P2P_DIR_RECV; + if (k_direction == P2P_DIR_RECV) { + k_bd_addr_oui = l2cap_data->remote_bd_addr_oui; + k_bd_addr_id = l2cap_data->remote_bd_addr_id; + } else { + k_bd_addr_oui = 0; + k_bd_addr_id = 0; + } + + remote_bd_addr_oui = k_bd_addr_oui; + remote_bd_addr_id = k_bd_addr_id; + + k_service_type = BTSDP_L2CAP_PROTOCOL_UUID; + k_service_channel = psm; + k_frame_number = pinfo->fd->num; + + key[0].length = 1; + key[0].key = &k_interface_id; + key[1].length = 1; + key[1].key = &k_adapter_id; + key[2].length = 1; + key[2].key = &k_sdp_psm; + key[3].length = 1; + key[3].key = &k_direction; + key[4].length = 1; + key[4].key = &k_bd_addr_oui; + key[5].length = 1; + key[5].key = &k_bd_addr_id; + key[6].length = 1; + key[6].key = &k_service_type; + key[7].length = 1; + key[7].key = &k_service_channel; + key[8].length = 1; + key[8].key = &k_frame_number; + key[9].length = 0; + key[9].key = NULL; + + service_info = (service_info_t *) se_tree_lookup32_array_le(sdp_service_infos, key); + if (service_info && service_info->interface_id == interface_id && + service_info->adapter_id == adapter_id && + service_info->sdp_psm == SDP_PSM_DEFAULT && + ((service_info->direction == P2P_DIR_RECV && + service_info->bd_addr_oui == remote_bd_addr_oui && + service_info->bd_addr_id == remote_bd_addr_id) || + (service_info->direction != P2P_DIR_RECV && + service_info->bd_addr_oui == 0 && + service_info->bd_addr_id == 0)) && + service_info->type == BTSDP_L2CAP_PROTOCOL_UUID && + service_info->channel == psm) { + return service_info->uuid; + } + + return 0; +} + static int dissect_comrej(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) { @@ -415,61 +489,22 @@ dissect_connrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *t { guint16 scid; guint16 psm; - emem_tree_key_t key[6]; - guint32 k_interface_id; - guint32 k_adapter_id; - guint32 k_chandle; - guint32 k_cid; - guint32 k_psm; - guint32 k_frame_number; - guint32 interface_id; - guint32 adapter_id; - guint32 chandle; - guint32 key_psm; - bthci_acl_data_t *acl_data = (bthci_acl_data_t *) pinfo->private_data; const gchar *psm_str = "<NONE>"; psm = tvb_get_letohs(tvb, offset); - interface_id = (acl_data) ? acl_data->interface_id : HCI_INTERFACE_AMP; - adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; - chandle = (acl_data) ? acl_data->chandle : 0; - key_psm = psm | ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x80000000 : 0x00000000); - if (psm < BTL2CAP_DYNAMIC_PSM_START) { proto_tree_add_item(tree, hf_btl2cap_psm, tvb, offset, 2, ENC_LITTLE_ENDIAN); psm_str = val_to_str_const(psm, psm_vals, "Unknown PSM"); } else { - psm_service_t *psm_service; - proto_item *item; + proto_item *item; + guint16 uuid; - item = proto_tree_add_item(tree, hf_btl2cap_psm_dynamic, tvb, offset, 2, ENC_LITTLE_ENDIAN); + item = proto_tree_add_item(tree, hf_btl2cap_psm_dynamic, tvb, offset, 2, ENC_LITTLE_ENDIAN); - k_interface_id = interface_id; - k_adapter_id = adapter_id; - k_chandle = chandle; - k_psm = key_psm; - k_frame_number = pinfo->fd->num; - - key[0].length = 1; - key[0].key = &k_interface_id; - key[1].length = 1; - key[1].key = &k_adapter_id; - key[2].length = 1; - key[2].key = &k_chandle; - key[3].length = 1; - key[3].key = &k_psm; - key[4].length = 1; - key[4].key = &k_frame_number; - key[5].length = 0; - key[5].key = NULL; - - psm_service = (psm_service_t *)se_tree_lookup32_array_le(psm_to_service_table, key); - if (psm_service && psm_service->interface_id == interface_id && - psm_service->adapter_id == adapter_id && - psm_service->chandle == chandle && - psm_service->psm == key_psm) { - psm_str = val_to_str_ext_const(psm_service->service, &vs_service_classes_ext, "Unknown PSM"); + uuid = get_service_uuid(pinfo, psm, (pinfo->p2p_dir == P2P_DIR_RECV) ? TRUE : FALSE); + if (uuid) { + psm_str = val_to_str_ext_const(uuid, &vs_service_classes_ext, "Unknown PSM"); proto_item_append_text(item, " (%s)", psm_str); } } @@ -479,10 +514,7 @@ dissect_connrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *t proto_tree_add_item(tree, hf_btl2cap_scid, tvb, offset, 2, ENC_LITTLE_ENDIAN); offset += 2; - if (psm_str) - col_append_fstr(pinfo->cinfo, COL_INFO, " (%s, SCID: 0x%04x)", psm_str, scid); - else - col_append_fstr(pinfo->cinfo, COL_INFO, " (SCID: 0x%04x)", scid); + col_append_fstr(pinfo->cinfo, COL_INFO, " (%s, SCID: 0x%04x)", psm_str, scid); if (is_ch_request) { proto_tree_add_item(tree, hf_btl2cap_controller, tvb, offset, 1, ENC_LITTLE_ENDIAN); @@ -490,8 +522,22 @@ dissect_connrequest(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *t } if (!pinfo->fd->flags.visited) { + emem_tree_key_t key[6]; + guint32 k_interface_id; + guint32 k_adapter_id; + guint32 k_chandle; + guint32 k_cid; + guint32 k_frame_number; + guint32 interface_id; + guint32 adapter_id; + guint32 chandle; + bthci_acl_data_t *acl_data = (bthci_acl_data_t *) pinfo->private_data; psm_data_t *psm_data; + interface_id = (acl_data) ? acl_data->interface_id : HCI_INTERFACE_AMP; + adapter_id = (acl_data) ? acl_data->adapter_id : HCI_ADAPTER_DEFAULT; + chandle = (acl_data) ? acl_data->chandle : 0; + k_interface_id = interface_id; k_adapter_id = adapter_id; k_chandle = chandle; @@ -1255,7 +1301,7 @@ dissect_disconnrequestresponse(tvbuff_t *tvb, int offset, packet_info *pinfo, pr static int dissect_b_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree *btl2cap_tree, - guint16 cid, guint16 psm, gboolean local_service, guint16 length, int offset) + guint16 cid, guint16 psm, gboolean is_local_psm, guint16 length, int offset) { tvbuff_t *next_tvb; @@ -1265,62 +1311,18 @@ dissect_b_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree if (psm) { proto_item *psm_item; - psm_service_t *psm_service; - emem_tree_key_t key[6]; - guint32 k_interface_id; - guint32 k_adapter_id; - guint32 k_chandle; - guint32 k_psm; - guint32 k_frame_number; - guint32 interface_id; - guint32 adapter_id; - guint32 chandle; - guint32 key_psm; - guint32 service = 0; - btl2cap_data_t *l2cap_data; + guint16 uuid; - l2cap_data = (btl2cap_data_t *) pinfo->private_data; - - interface_id = l2cap_data->interface_id; - adapter_id = l2cap_data->adapter_id; - chandle = l2cap_data->chandle; - key_psm = (local_service << 31) | psm; - - k_interface_id = interface_id; - k_adapter_id = adapter_id; - k_chandle = chandle; - k_psm = key_psm; - k_frame_number = pinfo->fd->num; - - key[0].length = 1; - key[0].key = &k_interface_id; - key[1].length = 1; - key[1].key = &k_adapter_id; - key[2].length = 1; - key[2].key = &k_chandle; - key[3].length = 1; - key[3].key = &k_psm; - key[4].length = 1; - key[4].key = &k_frame_number; - key[5].length = 0; - key[5].key = NULL; - - psm_service = (psm_service_t *)se_tree_lookup32_array_le(psm_to_service_table, key); - if (psm_service && psm_service->interface_id == interface_id && - psm_service->adapter_id == adapter_id && - psm_service->chandle == chandle && - psm_service->psm == key_psm) { - service = psm_service->service; - } + uuid = get_service_uuid(pinfo, psm, is_local_psm); if (psm < BTL2CAP_DYNAMIC_PSM_START) { psm_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm, tvb, offset, 0, psm); } else { psm_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm_dynamic, tvb, offset, 0, psm); - if (service) + if (uuid) proto_item_append_text(psm_item, ": %s", - val_to_str_ext_const(service, &vs_service_classes_ext, "Unknown service")); + val_to_str_ext_const(uuid, &vs_service_classes_ext, "Unknown service")); } PROTO_ITEM_SET_GENERATED(psm_item); @@ -1328,7 +1330,7 @@ dissect_b_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree if (!dissector_try_uint(l2cap_cid_dissector_table, (guint32) cid, next_tvb, pinfo, tree)) { if (!dissector_try_uint(l2cap_psm_dissector_table, (guint32) psm, next_tvb, pinfo, tree)) { /* not a known fixed PSM, try to find a registered service to a dynamic PSM */ - if (!dissector_try_uint(l2cap_service_dissector_table, service, next_tvb, pinfo, tree)) { + if (!dissector_try_uint(l2cap_service_dissector_table, uuid, next_tvb, pinfo, tree)) { /* unknown protocol. declare as data */ proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, ENC_NA); } @@ -1466,69 +1468,24 @@ dissect_i_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree if (next_tvb) { if (psm) { proto_item *psm_item; - psm_service_t *psm_service; - emem_tree_key_t key[6]; - guint32 k_interface_id; - guint32 k_adapter_id; - guint32 k_chandle; - guint32 k_psm; - guint32 k_frame_number; - guint32 interface_id; - guint32 adapter_id; - guint32 chandle; - guint32 key_psm; - guint32 service = 0; - btl2cap_data_t *l2cap_data; - - l2cap_data = (btl2cap_data_t *) pinfo->private_data; - - interface_id = l2cap_data->interface_id; - adapter_id = l2cap_data->adapter_id; - chandle = l2cap_data->chandle; - key_psm = ((psm_data ? psm_data->local_service : 0) << 31) | psm; + guint16 uuid; - k_interface_id = interface_id; - k_adapter_id = adapter_id; - k_chandle = chandle; - k_psm = key_psm; - k_frame_number = pinfo->fd->num; - - key[0].length = 1; - key[0].key = &k_interface_id; - key[1].length = 1; - key[1].key = &k_adapter_id; - key[2].length = 1; - key[2].key = &k_chandle; - key[3].length = 1; - key[3].key = &k_psm; - key[4].length = 1; - key[4].key = &k_frame_number; - key[5].length = 0; - key[5].key = NULL; - - psm_service = (psm_service_t *)se_tree_lookup32_array_le(psm_to_service_table, key); - if (psm_service && psm_service->interface_id == interface_id && - psm_service->adapter_id == adapter_id && - psm_service->chandle == chandle && - psm_service->psm == key_psm) { - service = psm_service->service; - } + uuid = get_service_uuid(pinfo, psm, psm_data->local_service); if (psm < BTL2CAP_DYNAMIC_PSM_START) { - psm_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm, tvb, offset, 0, psm); - } - else { + psm_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm, tvb, offset, 0, psm); + } else { psm_item = proto_tree_add_uint(btl2cap_tree, hf_btl2cap_psm_dynamic, tvb, offset, 0, psm); - if (service) + if (uuid) proto_item_append_text(psm_item, " (%s)", - val_to_str_ext_const(service, &vs_service_classes_ext, "Unknown service")); + val_to_str_ext_const(uuid, &vs_service_classes_ext, "Unknown service")); } PROTO_ITEM_SET_GENERATED(psm_item); /* call next dissector */ if (!dissector_try_uint(l2cap_psm_dissector_table, (guint32) psm, next_tvb, pinfo, tree)) { /* not a known fixed PSM, try to find a registered service to a dynamic PSM */ - if (!dissector_try_uint(l2cap_service_dissector_table, service, next_tvb, pinfo, tree)) { + if (!dissector_try_uint(l2cap_service_dissector_table, uuid, next_tvb, pinfo, tree)) { /* unknown protocol. declare as data */ proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, next_tvb, 0, tvb_length(next_tvb), ENC_NA); } @@ -1649,6 +1606,8 @@ dissect_btl2cap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) l2cap_data->cid = cid; l2cap_data->psm = 0; l2cap_data->first_scid_frame = 0; + l2cap_data->remote_bd_addr_oui = (acl_data) ? acl_data->remote_bd_addr_oui : 0; + l2cap_data->remote_bd_addr_id = (acl_data) ? acl_data->remote_bd_addr_id : 0; pd_save = pinfo->private_data; pinfo->private_data = l2cap_data; @@ -1781,48 +1740,11 @@ dissect_btl2cap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* call next dissector */ if (!dissector_try_uint(l2cap_psm_dissector_table, (guint32) psm, next_tvb, pinfo, tree)) { /* not a known fixed PSM, try to find a registered service to a dynamic PSM */ - psm_service_t *psm_service; - emem_tree_key_t key[6]; - guint32 k_interface_id; - guint32 k_adapter_id; - guint32 k_chandle; - guint32 k_psm; - guint32 k_frame_number; - guint32 interface_id; - guint32 adapter_id; - guint32 chandle; - guint32 key_psm; - - interface_id = l2cap_data->interface_id; - adapter_id = l2cap_data->adapter_id; - chandle = l2cap_data->chandle; - key_psm = ((pinfo->p2p_dir == P2P_DIR_RECV) ? 0x80000000 : 0x00000000) | psm; + guint16 uuid; - k_interface_id = interface_id; - k_adapter_id = adapter_id; - k_chandle = chandle; - k_psm = key_psm; - k_frame_number = pinfo->fd->num; + uuid = get_service_uuid(pinfo, psm, (pinfo->p2p_dir == P2P_DIR_RECV) ? TRUE : FALSE ); - key[0].length = 1; - key[0].key = &k_interface_id; - key[1].length = 1; - key[1].key = &k_adapter_id; - key[2].length = 1; - key[2].key = &k_chandle; - key[3].length = 1; - key[3].key = &k_psm; - key[4].length = 1; - key[4].key = &k_frame_number; - key[5].length = 0; - key[5].key = NULL; - - psm_service = (psm_service_t *)se_tree_lookup32_array_le(psm_to_service_table, key); - if (!(psm_service && psm_service->interface_id == interface_id && - psm_service->adapter_id == adapter_id && - psm_service->chandle == chandle && - psm_service->psm == key_psm && - dissector_try_uint(l2cap_service_dissector_table, psm_service->service, next_tvb, pinfo, tree))) { + if (!dissector_try_uint(l2cap_service_dissector_table, uuid, next_tvb, pinfo, tree)) { /* unknown protocol. declare as data */ proto_tree_add_item(btl2cap_tree, hf_btl2cap_payload, tvb, offset, length, ENC_NA); } @@ -1951,83 +1873,12 @@ dissect_btl2cap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) static int btl2cap_sdp_tap_packet(void *arg _U_, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *arg2) { - const btsdp_data_t *sdp_data = (const btsdp_data_t *) arg2; + const sdp_package_t *sdp_package = (const sdp_package_t *) arg2; - if (sdp_data->protocol == BTSDP_L2CAP_PROTOCOL_UUID) { - psm_service_t *psm_service; - emem_tree_key_t key[6]; - guint32 k_interface_id; - guint32 k_adapter_id; - guint32 k_chandle; - guint32 k_psm; - guint32 k_frame_number; - guint32 interface_id; - guint32 adapter_id; - guint32 chandle; - guint32 psm; - guint32 frame_number; - - interface_id = sdp_data->interface_id; - adapter_id = sdp_data->adapter_id; - chandle = sdp_data->chandle; - psm = sdp_data->channel | ((sdp_data->flags & BTSDP_LOCAL_SERVICE_FLAG_MASK) << 31); - frame_number = sdp_data->frame_number; - - k_interface_id = interface_id; - k_adapter_id = adapter_id; - k_chandle = chandle; - k_psm = psm; - k_frame_number = frame_number; - - key[0].length = 1; - key[0].key = &k_interface_id; - key[1].length = 1; - key[1].key = &k_adapter_id; - key[2].length = 1; - key[2].key = &k_chandle; - key[3].length = 1; - key[3].key = &k_psm; - key[4].length = 1; - key[4].key = &k_frame_number; - key[5].length = 0; - key[5].key = NULL; - - - psm_service = (psm_service_t *)se_tree_lookup32_array_le(psm_to_service_table, key); - if (!(psm_service && psm_service->interface_id == interface_id && - psm_service->adapter_id == adapter_id && - psm_service->chandle == chandle && - psm_service->psm == psm)) { - psm_service = wmem_new(wmem_file_scope(), psm_service_t); - psm_service->interface_id = interface_id; - psm_service->adapter_id = adapter_id; - psm_service->chandle = chandle; - psm_service->psm = psm; - psm_service->service = 0; - - k_interface_id = interface_id; - k_adapter_id = adapter_id; - k_chandle = chandle; - k_psm = psm; - k_frame_number = frame_number; - - key[0].length = 1; - key[0].key = &k_interface_id; - key[1].length = 1; - key[1].key = &k_adapter_id; - key[2].length = 1; - key[2].key = &k_chandle; - key[3].length = 1; - key[3].key = &k_psm; - key[4].length = 1; - key[4].key = &k_frame_number; - key[5].length = 0; - key[5].key = NULL; - - se_tree_insert32_array(psm_to_service_table, key, psm_service); - } - psm_service->service = sdp_data->service; + if (sdp_service_infos == NULL) { + sdp_service_infos = sdp_package->service_infos; } + return 0; } @@ -2486,7 +2337,6 @@ proto_register_btl2cap(void) proto_register_subtree_array(ett, array_length(ett)); cid_to_psm_table = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "btl2cap scid to psm"); - psm_to_service_table = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "btl2cap psm to service uuid"); } diff --git a/epan/dissectors/packet-btl2cap.h b/epan/dissectors/packet-btl2cap.h index e81411b6e4..9ed1da3ec1 100644 --- a/epan/dissectors/packet-btl2cap.h +++ b/epan/dissectors/packet-btl2cap.h @@ -58,6 +58,8 @@ typedef struct _btl2cap_data_t { guint16 psm; guint32 first_scid_frame; guint32 first_dcid_frame; + guint32 remote_bd_addr_oui; + guint32 remote_bd_addr_id; } btl2cap_data_t; #endif diff --git a/epan/dissectors/packet-btrfcomm.c b/epan/dissectors/packet-btrfcomm.c index 0275675209..523f5fd00e 100644 --- a/epan/dissectors/packet-btrfcomm.c +++ b/epan/dissectors/packet-btrfcomm.c @@ -105,16 +105,10 @@ static gint ett_mcc_dlci = -1; static gint ett_btdun = -1; static gint ett_btspp = -1; -static emem_tree_t *dlci_table; +static emem_tree_t *sdp_service_infos = NULL; -/* Initialize dissector table */ -dissector_table_t rfcomm_service_dissector_table; -dissector_table_t rfcomm_channel_dissector_table; - -typedef struct _dlci_state_t { - guint32 service; - char do_credit_fc; -} dlci_state_t; +static dissector_table_t rfcomm_service_dissector_table; +static dissector_table_t rfcomm_channel_dissector_table; typedef struct { guint channel; @@ -265,13 +259,13 @@ get_le_multi_byte_value(tvbuff_t *tvb, int offset, proto_tree *tree, guint32 *va do { byte = tvb_get_guint8(tvb, offset); offset += 1; - val |= ((byte>>1)&0xff) << (bc++ * 7); + val |= ((byte >> 1) & 0xff) << (bc++ * 7); } while ((byte & 0x1) == 0); *val_ptr = val; if (hf_index > 0) { - proto_tree_add_uint(tree, hf_index, tvb, start_offset, offset-start_offset, val); + proto_tree_add_uint(tree, hf_index, tvb, start_offset, offset - start_offset, val); } return offset; @@ -279,15 +273,13 @@ get_le_multi_byte_value(tvbuff_t *tvb, int offset, proto_tree *tree, guint32 *va static int -dissect_ctrl_pn(packet_info *pinfo, proto_tree *t, tvbuff_t *tvb, int offset, int cr_flag, guint8 *mcc_channel) +dissect_ctrl_pn(proto_tree *t, tvbuff_t *tvb, int offset, guint8 *mcc_channel) { proto_tree *st; proto_item *ti; proto_tree *dlci_tree; proto_item *dlci_item; int mcc_dlci; - int cl; - dlci_state_t *dlci_state; guint8 flags; proto_tree_add_item(t, hf_mcc_pn_zeros_padding, tvb, offset, 1, ENC_LITTLE_ENDIAN); @@ -304,11 +296,9 @@ dissect_ctrl_pn(packet_info *pinfo, proto_tree *t, tvbuff_t *tvb, int offset, in proto_tree_add_item(dlci_tree, hf_mcc_pn_direction, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset += 1; - /* cl */ flags = tvb_get_guint8(tvb, offset); - cl = flags&0xf0; - ti = proto_tree_add_text(t, tvb, offset, 1, "I1-I4: 0x%x, C1-C4: 0x%x", flags&0xf, (flags>>4)&0xf); + ti = proto_tree_add_text(t, tvb, offset, 1, "I1-I4: 0x%x, C1-C4: 0x%x", flags & 0xf, (flags >> 4) & 0xf); st = proto_item_add_subtree(ti, ett_ctrl_pn_ci); proto_tree_add_item(st, hf_pn_c14, tvb, offset, 1, ENC_LITTLE_ENDIAN); @@ -335,32 +325,6 @@ dissect_ctrl_pn(packet_info *pinfo, proto_tree *t, tvbuff_t *tvb, int offset, in proto_tree_add_item(t, hf_error_recovery_mode, tvb, offset, 1, ENC_LITTLE_ENDIAN); offset += 1; - if (!pinfo->fd->flags.visited) { - guint32 token; - - if (pinfo->p2p_dir == cr_flag) - token = mcc_dlci | 0x01; /* local service */ - else - token = mcc_dlci; - - dlci_state = (dlci_state_t *)se_tree_lookup32(dlci_table, token); - if (!dlci_state) { - dlci_state = wmem_new0(wmem_file_scope(), dlci_state_t); - se_tree_insert32(dlci_table, token, dlci_state); - } - - if (!cl) { - /* sender does not do credit based flow control */ - dlci_state->do_credit_fc = 0; - } else if (cr_flag && (cl == 0xf0)) { - /* sender requests to use credit based flow control */ - dlci_state->do_credit_fc |= 1; - } else if ((!cr_flag) && (cl == 0xe0)) { - /* receiver also knows how to handle credit based - flow control */ - dlci_state->do_credit_fc |= 2; - } - } return offset; } @@ -411,13 +375,13 @@ dissect_ctrl_msc(proto_tree *t, tvbuff_t *tvb, int offset, int length, guint8 *m offset += 1; } - proto_item_set_len(it, offset-start_offset); + proto_item_set_len(it, offset - start_offset); return offset; } static int -dissect_btrfcomm_Address(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 *ea_flagp, guint8 *cr_flagp, guint8 *dlcip) +dissect_btrfcomm_address(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 *ea_flagp, guint8 *cr_flagp, guint8 *dlcip) { proto_item *ti; proto_tree *addr_tree; @@ -427,17 +391,17 @@ dissect_btrfcomm_Address(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 *ea flags = tvb_get_guint8(tvb, offset); - ea_flag = flags&0x01; + ea_flag = flags & 0x01; if (ea_flagp) { *ea_flagp = ea_flag; } - cr_flag = (flags&0x02) ? 1 : 0; + cr_flag = (flags & 0x02) ? 1 : 0; if (cr_flagp) { *cr_flagp = cr_flag; } - dlci = flags>>2; + dlci = flags >> 2; if (dlcip) { *dlcip = dlci; } @@ -460,7 +424,7 @@ dissect_btrfcomm_Address(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 *ea } static int -dissect_btrfcomm_Control(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 *pf_flagp, guint8 *frame_typep) +dissect_btrfcomm_control(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 *pf_flagp, guint8 *frame_typep) { proto_item *ti; proto_tree *hctl_tree; @@ -468,12 +432,12 @@ dissect_btrfcomm_Control(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 *pf flags = tvb_get_guint8(tvb, offset); - pf_flag = (flags&0x10) ? 1 : 0; + pf_flag = (flags & 0x10) ? 1 : 0; if (pf_flagp) { *pf_flagp = pf_flag; } - frame_type = flags&0xef; + frame_type = flags & 0xef; if (frame_typep) { *frame_typep = frame_type; } @@ -492,7 +456,7 @@ dissect_btrfcomm_Control(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 *pf static int -dissect_btrfcomm_PayloadLen(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 *frame_lenp) +dissect_btrfcomm_payload_length(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 *frame_lenp) { guint16 frame_len; int start_offset = offset; @@ -500,7 +464,7 @@ dissect_btrfcomm_PayloadLen(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 frame_len = tvb_get_guint8(tvb, offset); offset += 1; - if (frame_len&0x01) { + if (frame_len & 0x01) { frame_len >>= 1; /* 0 - 127 */ } else { frame_len >>= 1; /* 128 - ... */ @@ -508,7 +472,7 @@ dissect_btrfcomm_PayloadLen(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 offset += 1; } - proto_tree_add_uint(tree, hf_len, tvb, start_offset, offset-start_offset, frame_len); + proto_tree_add_uint(tree, hf_len, tvb, start_offset, offset - start_offset, frame_len); if (frame_lenp) { *frame_lenp = frame_len; @@ -528,7 +492,7 @@ dissect_btrfcomm_MccType(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 *mc flags = tvb_get_guint8(tvb, offset); - mcc_cr_flag = (flags&0x2) ? 1 : 0; + mcc_cr_flag = (flags & 0x2) ? 1 : 0; if (mcc_cr_flagp) { *mcc_cr_flagp = mcc_cr_flag; } @@ -539,18 +503,18 @@ dissect_btrfcomm_MccType(tvbuff_t *tvb, int offset, proto_tree *tree, guint8 *mc } offset = get_le_multi_byte_value(tvb, offset, tree, &mcc_type, -1); - mcc_type = (mcc_type>>1) & 0x3f; /* shift c/r flag off */ + mcc_type = (mcc_type >> 1) & 0x3f; /* shift c/r flag off */ if (mcc_typep) { *mcc_typep = mcc_type; } - ti = proto_tree_add_text(tree, tvb, start_offset, offset-start_offset, + ti = proto_tree_add_text(tree, tvb, start_offset, offset - start_offset, "Type: %s (0x%x), C/R flag = %d, E/A flag = %d", val_to_str_const(mcc_type, vs_ctl, "Unknown"), mcc_type, mcc_cr_flag, mcc_ea_flag); mcc_tree = proto_item_add_subtree(ti, ett_mcc); - proto_tree_add_item(mcc_tree, hf_mcc_cmd, tvb, start_offset, offset-start_offset, ENC_LITTLE_ENDIAN); + proto_tree_add_item(mcc_tree, hf_mcc_cmd, tvb, start_offset, offset - start_offset, ENC_LITTLE_ENDIAN); proto_tree_add_item(mcc_tree, hf_mcc_cr, tvb, start_offset, 1, ENC_LITTLE_ENDIAN); proto_tree_add_item(mcc_tree, hf_mcc_ea, tvb, start_offset, 1, ENC_LITTLE_ENDIAN); @@ -572,12 +536,16 @@ dissect_btrfcomm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) guint8 dlci, cr_flag, ea_flag; guint8 frame_type, pf_flag; guint16 frame_len; - dlci_state_t *dlci_state = NULL; + btl2cap_data_t *l2cap_data; + service_info_t *service_info; ti = proto_tree_add_item(tree, proto_btrfcomm, tvb, offset, -1, ENC_NA); rfcomm_tree = proto_item_add_subtree(ti, ett_btrfcomm); col_set_str(pinfo->cinfo, COL_PROTOCOL, "RFCOMM"); + + l2cap_data = (btl2cap_data_t *) pinfo->private_data; + switch (pinfo->p2p_dir) { case P2P_DIR_SENT: @@ -600,24 +568,75 @@ dissect_btrfcomm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* flags and dlci */ - offset = dissect_btrfcomm_Address(tvb, offset, rfcomm_tree, &ea_flag, &cr_flag, &dlci); + offset = dissect_btrfcomm_address(tvb, offset, rfcomm_tree, &ea_flag, &cr_flag, &dlci); /* pf and frame type */ - offset = dissect_btrfcomm_Control(tvb, offset, rfcomm_tree, &pf_flag, &frame_type); + offset = dissect_btrfcomm_control(tvb, offset, rfcomm_tree, &pf_flag, &frame_type); /* payload length */ - offset = dissect_btrfcomm_PayloadLen(tvb, offset, rfcomm_tree, &frame_len); + offset = dissect_btrfcomm_payload_length(tvb, offset, rfcomm_tree, &frame_len); if (dlci && (frame_len || (frame_type == 0xef) || (frame_type == 0x2f))) { - guint32 token; - - if (pinfo->p2p_dir == cr_flag) - token = dlci | 0x01; /* local service */ - else - token = dlci; - - dlci_state = (dlci_state_t *)se_tree_lookup32(dlci_table, token); - if (!dlci_state) { - dlci_state = wmem_new0(wmem_file_scope(), dlci_state_t); - se_tree_insert32(dlci_table, token, dlci_state); + emem_tree_key_t key[10]; + guint32 k_interface_id; + guint32 k_adapter_id; + guint32 k_sdp_psm; + guint32 k_direction; + guint32 k_bd_addr_oui; + guint32 k_bd_addr_id; + guint32 k_service_type; + guint32 k_service_channel; + guint32 k_frame_number; + + k_interface_id = l2cap_data->interface_id; + k_adapter_id = l2cap_data->adapter_id; + k_sdp_psm = SDP_PSM_DEFAULT; + k_direction = (dlci & 0x01) ? P2P_DIR_SENT : P2P_DIR_RECV; + if (k_direction == P2P_DIR_RECV) { + k_bd_addr_oui = l2cap_data->remote_bd_addr_oui; + k_bd_addr_id = l2cap_data->remote_bd_addr_id; + } else { + k_bd_addr_oui = 0; + k_bd_addr_id = 0; + } + k_service_type = BTSDP_RFCOMM_PROTOCOL_UUID; + k_service_channel = dlci >> 1; + k_frame_number = pinfo->fd->num; + + key[0].length = 1; + key[0].key = &k_interface_id; + key[1].length = 1; + key[1].key = &k_adapter_id; + key[2].length = 1; + key[2].key = &k_sdp_psm; + key[3].length = 1; + key[3].key = &k_direction; + key[4].length = 1; + key[4].key = &k_bd_addr_oui; + key[5].length = 1; + key[5].key = &k_bd_addr_id; + key[6].length = 1; + key[6].key = &k_service_type; + key[7].length = 1; + key[7].key = &k_service_channel; + key[8].length = 1; + key[8].key = &k_frame_number; + key[9].length = 0; + key[9].key = NULL; + + service_info = (service_info_t *) se_tree_lookup32_array_le(sdp_service_infos, key); + if (service_info && service_info->interface_id == l2cap_data->interface_id && + service_info->adapter_id == l2cap_data->adapter_id && + service_info->sdp_psm == SDP_PSM_DEFAULT && + ((service_info->direction == P2P_DIR_RECV && + service_info->bd_addr_oui == l2cap_data->remote_bd_addr_oui && + service_info->bd_addr_id == l2cap_data->remote_bd_addr_id) || + (service_info->direction != P2P_DIR_RECV && + service_info->bd_addr_oui == 0 && + service_info->bd_addr_id == 0)) && + service_info->type == BTSDP_RFCOMM_PROTOCOL_UUID && + service_info->channel == (dlci >> 1)) { + + } else { + service_info = wmem_new0(wmem_packet_scope(), service_info_t); } } @@ -625,22 +644,19 @@ dissect_btrfcomm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) val_to_str_const(frame_type, vs_frame_type_short, "Unknown"), dlci >> 1); if (dlci && (frame_type == 0x2f)) col_append_fstr(pinfo->cinfo, COL_INFO, "(%s) ", - val_to_str_ext_const(dlci_state->service, &vs_service_classes_ext, "Unknown")); + val_to_str_ext_const(service_info->uuid, &vs_service_classes_ext, "Unknown")); /* UID frame */ if ((frame_type == 0xef) && dlci && pf_flag) { col_append_str(pinfo->cinfo, COL_INFO, "UID "); - if ((dlci_state->do_credit_fc & 0x03) == 0x03) { -/*QQQ use tvb_length_remaining() == 2 and !frame_len as heuristics to catch this as well? */ - /* add credit based flow control byte */ - proto_tree_add_item(rfcomm_tree, hf_fc_credits, tvb, offset, 1, ENC_LITTLE_ENDIAN); - offset += 1; - } - } + /* add credit based flow control byte */ + proto_tree_add_item(rfcomm_tree, hf_fc_credits, tvb, offset, 1, ENC_LITTLE_ENDIAN); + offset += 1; - fcs_offset = offset + frame_len; + } + fcs_offset = offset + frame_len; /* multiplexer control command */ if (!dlci && frame_len) { @@ -670,7 +686,7 @@ dissect_btrfcomm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) switch(mcc_type) { case 0x20: /* DLC Parameter Negotiation */ - dissect_ctrl_pn(pinfo, ctrl_tree, tvb, offset, mcc_cr_flag, &mcc_channel); + dissect_ctrl_pn(ctrl_tree, tvb, offset, &mcc_channel); break; case 0x24: /* Remote Port Negotiation */ mcc_dlci = tvb_get_guint8(tvb, offset) >> 2; @@ -706,39 +722,38 @@ dissect_btrfcomm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) offset += length; - proto_item_set_len(mcc_ti, offset-start_offset); + proto_item_set_len(mcc_ti, offset - start_offset); } - /* try to find a higher layer dissector that has registered to handle data * for this kind of service, if none is found dissect it as raw "data" */ if (dlci && frame_len) { dissector_handle_t decode_by_dissector; tvbuff_t *next_tvb; - btl2cap_data_t *l2cap_data; - btrfcomm_data_t rfcomm_data; + btrfcomm_data_t *rfcomm_data; next_tvb = tvb_new_subset(tvb, offset, frame_len, frame_len); - l2cap_data = (btl2cap_data_t *)pinfo->private_data; - pinfo->private_data = &rfcomm_data; - - rfcomm_data.interface_id = l2cap_data->interface_id; - rfcomm_data.adapter_id = l2cap_data->adapter_id; - rfcomm_data.chandle = l2cap_data->chandle; - rfcomm_data.cid = l2cap_data->cid; - rfcomm_data.dlci = dlci; + rfcomm_data = (btrfcomm_data_t *) wmem_new(wmem_packet_scope(), btrfcomm_data_t); + rfcomm_data->interface_id = l2cap_data->interface_id; + rfcomm_data->adapter_id = l2cap_data->adapter_id; + rfcomm_data->chandle = l2cap_data->chandle; + rfcomm_data->cid = l2cap_data->cid; + rfcomm_data->dlci = dlci; + pinfo->private_data = rfcomm_data; - decode_by_dissector = find_proto_by_channel(dlci >> 1); - if (rfcomm_channels_enabled && decode_by_dissector) { - call_dissector(decode_by_dissector, next_tvb, pinfo, tree); - } else if (!dissector_try_uint(rfcomm_channel_dissector_table, (guint32) dlci >> 1, + if (!dissector_try_uint(rfcomm_channel_dissector_table, (guint32) dlci >> 1, next_tvb, pinfo, tree)) { - if (!dissector_try_uint(rfcomm_service_dissector_table, dlci_state->service, + if (!dissector_try_uint(rfcomm_service_dissector_table, service_info->uuid, next_tvb, pinfo, tree)) { - /* unknown service, let the data dissector handle it */ - call_dissector(data_handle, next_tvb, pinfo, tree); + decode_by_dissector = find_proto_by_channel(dlci >> 1); + if (rfcomm_channels_enabled && decode_by_dissector) { + call_dissector(decode_by_dissector, next_tvb, pinfo, tree); + } else { + /* unknown service, let the data dissector handle it */ + call_dissector(data_handle, next_tvb, pinfo, tree); + } } } } @@ -951,8 +966,6 @@ proto_register_btrfcomm(void) rfcomm_service_dissector_table = register_dissector_table("btrfcomm.service", "RFCOMM SERVICE", FT_UINT16, BASE_HEX); rfcomm_channel_dissector_table = register_dissector_table("btrfcomm.channel", "RFCOMM Channel", FT_UINT16, BASE_DEC); - dlci_table = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "RFCOMM dlci table"); - module = prefs_register_protocol(proto_btrfcomm, NULL); prefs_register_static_text_preference(module, "rfcomm.version", "Bluetooth Protocol RFCOMM version: 1.1", "Version of protocol supported by this dissector."); @@ -985,22 +998,12 @@ proto_register_btrfcomm(void) static int btrfcomm_sdp_tap_packet(void *arg _U_, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *arg2) { - const btsdp_data_t *sdp_data = (const btsdp_data_t *) arg2; - - if (sdp_data->protocol == BTSDP_RFCOMM_PROTOCOL_UUID) { - guint32 token; - dlci_state_t *dlci_state; - - /* rfcomm channel * 2 = dlci */ - token = (sdp_data->channel<<1) | (sdp_data->flags & BTSDP_LOCAL_SERVICE_FLAG_MASK); + const sdp_package_t *sdp_package = (const sdp_package_t *) arg2; - dlci_state = (dlci_state_t *)se_tree_lookup32(dlci_table, token); - if (!dlci_state) { - dlci_state = wmem_new0(wmem_file_scope(), dlci_state_t); - se_tree_insert32(dlci_table, token, dlci_state); - } - dlci_state->service = sdp_data->service; + if (sdp_service_infos == NULL) { + sdp_service_infos = sdp_package->service_infos; } + return 0; } @@ -1038,7 +1041,7 @@ dissect_btdun(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) st = proto_item_add_subtree(ti, ett_btdun); is_at_cmd = TRUE; - for(i=0; i<length && is_at_cmd; i++) { + for(i = 0; i < length && is_at_cmd; i++) { is_at_cmd = tvb_get_guint8(tvb, i) < 0x7d; } @@ -1078,7 +1081,7 @@ proto_register_btdun(void) /* Setup protocol subtree array */ static gint *ett[] = { - &ett_btdun, + &ett_btdun }; proto_btdun = proto_register_protocol("Bluetooth DUN Packet", "BT DUN", "btdun"); @@ -1115,9 +1118,9 @@ dissect_btspp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) ti = proto_tree_add_item(tree, proto_btspp, tvb, 0, -1, ENC_NA); st = proto_item_add_subtree(ti, ett_btspp); - length = MIN(length,60); + length = MIN(length, 60); ascii_only = TRUE; - for(i=0; i<length && ascii_only; i++) { + for(i = 0; i < length && ascii_only; i++) { ascii_only = tvb_get_guint8(tvb, i) < 0x80; } @@ -1138,13 +1141,13 @@ proto_register_btspp(void) { &hf_data, { "Data", "btspp.data", FT_BYTES, BASE_NONE, NULL, 0, - NULL, HFILL} + NULL, HFILL } }, }; /* Setup protocol subtree array */ static gint *ett[] = { - &ett_btspp, + &ett_btspp }; proto_btspp = proto_register_protocol("Bluetooth SPP Packet", "BT SPP", "btspp"); diff --git a/epan/dissectors/packet-btsdp.c b/epan/dissectors/packet-btsdp.c index 875ea2dbd1..c2eccfb338 100644 --- a/epan/dissectors/packet-btsdp.c +++ b/epan/dissectors/packet-btsdp.c @@ -308,6 +308,8 @@ static gint btsdp_tap = -1; static emem_tree_t *tid_requests = NULL; static emem_tree_t *continuation_states = NULL; +static emem_tree_t *service_infos = NULL; + static sdp_package_t sdp_package; @@ -895,6 +897,73 @@ extern value_string_ext usb_langid_vals_ext; void proto_register_btsdp(void); void proto_reg_handoff_btsdp(void); +static void +save_channel(packet_info *pinfo, guint32 protocol, guint32 channel, gint protocol_order, service_info_t *parent_service_info) +{ + emem_tree_key_t key[10]; + guint32 k_interface_id; + guint32 k_adapter_id; + guint32 k_sdp_psm; + guint32 k_direction; + guint32 k_bd_addr_oui; + guint32 k_bd_addr_id; + guint32 k_service_type; + guint32 k_service_channel; + guint32 k_frame_number; + service_info_t *service_info; + + service_info = (service_info_t *) wmem_new(wmem_file_scope(), service_info_t); + service_info->interface_id = parent_service_info->interface_id; + service_info->adapter_id = parent_service_info->adapter_id; + service_info->sdp_psm = parent_service_info->sdp_psm; + service_info->direction = parent_service_info->direction; + service_info->bd_addr_oui = parent_service_info->bd_addr_oui; + service_info->bd_addr_id = parent_service_info->bd_addr_id; + + service_info->type = protocol; + service_info->channel = channel; + + service_info->uuid = parent_service_info->uuid; + + service_info->protocol_order = protocol_order; + service_info->parent_info = parent_service_info; + service_info->data = parent_service_info->data; + + + k_interface_id = service_info->interface_id; + k_adapter_id = service_info->adapter_id; + k_sdp_psm = service_info->sdp_psm; + k_direction = service_info->direction; + k_bd_addr_oui = service_info->bd_addr_oui; + k_bd_addr_id = service_info->bd_addr_id; + k_service_type = service_info->type; + k_service_channel = service_info->channel; + k_frame_number = pinfo->fd->num; + + key[0].length = 1; + key[0].key = &k_interface_id; + key[1].length = 1; + key[1].key = &k_adapter_id; + key[2].length = 1; + key[2].key = &k_sdp_psm; + key[3].length = 1; + key[3].key = &k_direction; + key[4].length = 1; + key[4].key = &k_bd_addr_oui; + key[5].length = 1; + key[5].key = &k_bd_addr_id; + key[6].length = 1; + key[6].key = &k_service_type; + key[7].length = 1; + key[7].key = &k_service_channel; + key[8].length = 1; + key[8].key = &k_frame_number; + key[9].length = 0; + key[9].key = NULL; + + se_tree_insert32_array(service_infos, key, service_info); +} + static gint get_type_length(tvbuff_t *tvb, gint offset, gint *length) { @@ -1556,7 +1625,7 @@ dissect_sdp_error_response(proto_tree *tree, tvbuff_t *tvb, gint offset) static gint dissect_protocol_descriptor_list(proto_tree *next_tree, tvbuff_t *tvb, packet_info *pinfo, gint offset, gint size, gchar *str, - gint start_strpos, gint *protocol_order) + gint start_strpos, service_info_t *service_info, gint *protocol_order) { proto_tree *feature_tree; proto_item *feature_item; @@ -1617,12 +1686,16 @@ dissect_protocol_descriptor_list(proto_tree *next_tree, tvbuff_t *tvb, proto_item_append_text(feature_item, ", PSM: %u", value); proto_item_append_text(entry_item, ", PSM: %u", value); proto_tree_add_item(sub_tree, hf_sdp_protocol_psm, tvb, entry_offset, 2, ENC_BIG_ENDIAN); + if (!pinfo->fd->flags.visited && service_info) + save_channel(pinfo, BTSDP_L2CAP_PROTOCOL_UUID, value, *protocol_order, service_info); *protocol_order += 1; } else if (uuid == BTSDP_RFCOMM_PROTOCOL_UUID) { strpos += g_snprintf(str + strpos, MAX_SDP_LEN - strpos, ":%u", value); proto_item_append_text(feature_item, ", RFCOMM Channel: %u", value); proto_item_append_text(entry_item, ", RFCOMM Channel: %u", value); proto_tree_add_item(sub_tree, hf_sdp_protocol_channel, tvb, entry_offset, 1, ENC_BIG_ENDIAN); + if (!pinfo->fd->flags.visited && service_info) + save_channel(pinfo, BTSDP_RFCOMM_PROTOCOL_UUID, value, *protocol_order, service_info); *protocol_order += 1; } else if (uuid == BTSDP_ATT_PROTOCOL_UUID) { proto_item_append_text(feature_item, ", GATT Handle Start: 0x%04x", value); @@ -1996,6 +2069,8 @@ dissect_sdp_type(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, proto_tree_add_item(next_tree, hf_ftp_goep_l2cap_psm, tvb, offset, 2, ENC_BIG_ENDIAN); psm = tvb_get_ntohs(tvb, offset); g_snprintf(str, MAX_SDP_LEN, "%u (0x%02x)", psm, psm); + if (!pinfo->fd->flags.visited && service_info) + save_channel(pinfo, BTSDP_L2CAP_PROTOCOL_UUID, psm, -1, service_info); break; default: found = FALSE; @@ -2245,6 +2320,8 @@ dissect_sdp_type(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, proto_tree_add_item(next_tree, hf_opp_goep_l2cap_psm, tvb, offset, 2, ENC_BIG_ENDIAN); psm = tvb_get_ntohs(tvb, offset); g_snprintf(str, MAX_SDP_LEN, "%u (0x%02x)", psm, psm); + if (!pinfo->fd->flags.visited && service_info) + save_channel(pinfo, BTSDP_L2CAP_PROTOCOL_UUID, psm, -1, service_info); break; case 0x303: list_offset = offset; @@ -2486,6 +2563,8 @@ dissect_sdp_type(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, proto_tree_add_item(next_tree, hf_bip_goep_l2cap_psm, tvb, offset, 2, ENC_BIG_ENDIAN); psm = tvb_get_ntohs(tvb, offset); g_snprintf(str, MAX_SDP_LEN, "%u (0x%02x)", psm, psm); + if (!pinfo->fd->flags.visited && service_info) + save_channel(pinfo, BTSDP_L2CAP_PROTOCOL_UUID, psm, -1, service_info); break; case 0x310: proto_tree_add_item(next_tree, hf_bip_supported_capabilities_reserved_4_7, tvb, offset, 1, ENC_BIG_ENDIAN); @@ -2579,6 +2658,8 @@ dissect_sdp_type(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, proto_tree_add_item(next_tree, hf_bip_goep_l2cap_psm, tvb, offset, 2, ENC_BIG_ENDIAN); psm = tvb_get_ntohs(tvb, offset); g_snprintf(str, MAX_SDP_LEN, "%u (0x%02x)", psm, psm); + if (!pinfo->fd->flags.visited && service_info) + save_channel(pinfo, BTSDP_L2CAP_PROTOCOL_UUID, psm, -1, service_info); break; case 0x312: proto_tree_add_item(next_tree, hf_bip_supported_functions_reserved_13_31, tvb, offset, 4, ENC_BIG_ENDIAN); @@ -2601,6 +2682,8 @@ dissect_sdp_type(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, proto_tree_add_item(next_tree, hf_bip_goep_l2cap_psm, tvb, offset, 2, ENC_BIG_ENDIAN); psm = tvb_get_ntohs(tvb, offset); g_snprintf(str, MAX_SDP_LEN, "%u (0x%02x)", psm, psm); + if (!pinfo->fd->flags.visited) + save_channel(pinfo, BTSDP_L2CAP_PROTOCOL_UUID, psm, -1, service_info); break; case 0x312: proto_tree_add_item(next_tree, hf_bip_supported_functions_reserved_11_31, tvb, offset, 4, ENC_BIG_ENDIAN); @@ -2793,7 +2876,7 @@ dissect_sdp_type(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, case 0x004: protocol_order = 0; strpos = dissect_protocol_descriptor_list(next_tree, tvb, pinfo, - offset, size, str, strpos, &protocol_order); + offset, size, str, strpos, service_info, &protocol_order); break; case 0x005: list_offset = offset; @@ -2937,7 +3020,7 @@ dissect_sdp_type(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, strpos += g_snprintf(str + strpos, MAX_SDP_LEN - strpos, "["); strpos = dissect_protocol_descriptor_list(entry_tree, tvb, pinfo, list_offset, list_length, str, strpos, - &protocol_order); + service_info, &protocol_order); list_offset += list_length; @@ -3348,6 +3431,18 @@ dissect_sdp_service_attribute_list(proto_tree *tree, tvbuff_t *tvb, gint offset, gint new_offset; guint16 service_uuid = 0; gint service_offset; + emem_tree_key_t key[10]; + guint32 k_interface_id; + guint32 k_adapter_id; + guint32 k_sdp_psm; + guint32 k_direction; + guint32 k_bd_addr_oui; + guint32 k_bd_addr_id; + guint32 k_service_type; + guint32 k_service_channel; + guint32 k_frame_number; + service_info_t *service_info; + btl2cap_data_t *l2cap_data = (btl2cap_data_t *) pinfo->private_data; offset = get_type_length(tvb, offset, &len); @@ -3384,10 +3479,69 @@ dissect_sdp_service_attribute_list(proto_tree *tree, tvbuff_t *tvb, gint offset, number_of_attributes += 1; } + if (!pinfo->fd->flags.visited) { + service_info = (service_info_t *) wmem_new(wmem_file_scope(), service_info_t); + service_info->interface_id = l2cap_data->interface_id; + service_info->adapter_id = l2cap_data->adapter_id; + service_info->sdp_psm = l2cap_data->psm; + service_info->direction = pinfo->p2p_dir; + if (service_info->direction == P2P_DIR_RECV) { + service_info->bd_addr_oui = l2cap_data->remote_bd_addr_oui; + service_info->bd_addr_id = l2cap_data->remote_bd_addr_id; + } else { + service_info->bd_addr_oui = 0; + service_info->bd_addr_id = 0; + } + + service_info->uuid = service_uuid; + + service_info->type = 0; + service_info->channel = 0; + service_info->protocol_order = 0; + service_info->parent_info = NULL; + } else { + service_info = NULL; + } + service_offset = offset; while ((offset - start_offset) < len) { offset = dissect_sdp_service_attribute(next_tree, tvb, offset, pinfo, - service_uuid, service_offset, NULL, number_of_attributes); + service_uuid, service_offset, service_info, number_of_attributes); + } + + if (!pinfo->fd->flags.visited) { + k_interface_id = l2cap_data->interface_id; + k_adapter_id = l2cap_data->adapter_id; + k_sdp_psm = l2cap_data->psm; + k_direction = service_info->direction; + k_bd_addr_oui = service_info->bd_addr_oui; + k_bd_addr_id = service_info->bd_addr_id; + k_service_type = service_info->type; + k_service_channel = service_info->channel; + k_frame_number = pinfo->fd->num; + + key[0].length = 1; + key[0].key = &k_interface_id; + key[1].length = 1; + key[1].key = &k_adapter_id; + key[2].length = 1; + key[2].key = &k_sdp_psm; + key[3].length = 1; + key[3].key = &k_direction; + key[4].length = 1; + key[4].key = &k_bd_addr_oui; + key[5].length = 1; + key[5].key = &k_bd_addr_id; + key[6].length = 1; + key[6].key = &k_service_type; + key[7].length = 1; + key[7].key = &k_service_channel; + key[8].length = 1; + key[8].key = &k_frame_number; + key[9].length = 0; + key[9].key = NULL; + + se_tree_insert32_array(service_infos, key, service_info); } proto_item_set_len(list_item, offset - start_offset); @@ -5016,6 +5170,9 @@ proto_register_btsdp(void) continuation_states = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "btsdp reassembling by continuation state"); + service_infos = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, + "btsdp service infos"); + sdp_package.service_infos = service_infos; btsdp_tap = register_tap("btsdp"); module = prefs_register_protocol(proto_btsdp, NULL); |