hfp: extract hfp_emit_event_for_role

This commit is contained in:
Matthias Ringwald 2022-01-27 11:39:11 +01:00
parent 6c0d5426fc
commit 293fae36ed
2 changed files with 76 additions and 12 deletions

View File

@ -315,21 +315,23 @@ int join_bitmap(char * buffer, int buffer_size, uint32_t values, int values_nr){
}
return offset;
}
static void hfp_emit_event_for_role(hfp_role_t local_role, uint8_t * packet, uint16_t size){
switch (local_role){
case HFP_ROLE_HF:
(*hfp_hf_callback)(HCI_EVENT_PACKET, 0, packet, size);
break;
case HFP_ROLE_AG:
(*hfp_ag_callback)(HCI_EVENT_PACKET, 0, packet, size);
break;
default:
btstack_unreachable();
break;
}
}
static void hfp_emit_event_for_context(hfp_connection_t * hfp_connection, uint8_t * packet, uint16_t size){
if (!hfp_connection) return;
btstack_packet_handler_t callback = NULL;
switch (hfp_connection->local_role){
case HFP_ROLE_HF:
callback = hfp_hf_callback;
break;
case HFP_ROLE_AG:
callback = hfp_ag_callback;
break;
default:
return;
}
(*callback)(HCI_EVENT_PACKET, 0, packet, size);
hfp_emit_event_for_role(hfp_connection->local_role, packet, size);
}
void hfp_emit_simple_event(hfp_connection_t * hfp_connection, uint8_t event_subtype){

62
tool/dump_h4.py Executable file
View File

@ -0,0 +1,62 @@
#!/usr/bin/env python3
# BlueKitchen GmbH (c) 2014
# primitive dump for PacketLogger format
# APPLE PacketLogger
# typedef struct {
# uint32_t len;
# uint32_t ts_sec;
# uint32_t ts_usec;
# uint8_t type; // 0xfc for note
# }
import sys
import datetime
import struct
packet_types = [ "CMD =>", "EVT <=", "ACL =>", "ACL <="]
def read_header(f):
bytes_read = f.read(13)
if bytes_read:
return struct.unpack(">IIIB", bytes_read)
else:
return (-1, 0, 0, 0)
def as_hex(data):
str_list = []
for byte in data:
str_list.append("{0:02x} ".format(byte))
return ''.join(str_list)
if len(sys.argv) == 1:
print ('Dump PacketLogger file')
print ('Copyright 2014, BlueKitchen GmbH')
print ('')
print ('Usage: ', sys.argv[0], 'hci_dump.pklg')
exit(0)
infile = sys.argv[1]
with open (infile, 'rb') as fin:
pos = 0
try:
while True:
(len, ts_sec, ts_usec, type) = read_header(fin)
if len < 0:
break
packet_len = len - 9;
if (packet_len > 66000):
print ("Error parsing pklg at offset %u (%x)." % (pos, pos))
break
packet = fin.read(packet_len)
pos = pos + 4 + len
time = "[%s.%03u]" % (datetime.datetime.fromtimestamp(ts_sec).strftime("%Y-%m-%d %H:%M:%S"), ts_usec / 1000)
if type == 0xfc:
print (time, "LOG", packet.decode('ascii'))
continue
if type <= 0x03:
print (time, packet_types[type], as_hex(packet))
except TypeError:
print ("Error parsing pklg at offset %u (%x)." % (pos, pos))