emulator/btdev: Add debug support
Luiz Augusto von Dentz
maintainerPATCH v2 1/11 emulator/btdev: Add debug support
From: Luiz Augusto von Dentz <[email protected]>
This adds btdev_set_debug which can be used to debug internals of btdev.
--- emulator/btdev.c | 99 +++++++++++++++++++++++++----------------------- emulator/btdev.h | 5 +++ 2 files changed, 57 insertions(+), 47 deletions(-)
emulator/btdev.c +52 -47
@@ -144,6 +144,10 @@ struct btdev {uint8_t sync_train_service_data;uint16_t le_ext_adv_type; + +btdev_debug_func_t debug_callback; +btdev_destroy_func_t debug_destroy; +void *debug_data; };struct inquiry_data {
@@ -257,45 +261,6 @@ static inline struct btdev *find_btdev_by_bdaddr_type(const uint8_t *bdaddr,return NULL ; } -static void hexdump (const unsigned char *buf,uint16_t len) -{ -static const char hexdigits[] ="0123456789abcdef" ; -char str[68 ]; -uint16_t i; - -if (!len) -return ; - -for (i =0 ; i < len; i++) { - str[((i %16 ) *3 ) +0 ] = hexdigits[buf[i] >>4 ]; - str[((i %16 ) *3 ) +1 ] = hexdigits[buf[i] &0xf ]; - str[((i %16 ) *3 ) +2 ] =' ' ; - str[(i %16 ) +49 ] =isprint (buf[i]) ? buf[i] :'.' ; - -if ((i +1 ) %16 ==0 ) { - str[47 ] =' ' ; - str[48 ] =' ' ; - str[65 ] ='\0' ; -printf ("%-12c%s\n" ,' ' , str); - str[0 ] =' ' ; - } - } - -if (i %16 >0 ) { -uint16_t j; -for (j = (i %16 ); j <16 ; j++) { - str[(j *3 ) +0 ] =' ' ; - str[(j *3 ) +1 ] =' ' ; - str[(j *3 ) +2 ] =' ' ; - str[j +49 ] =' ' ; - } - str[47 ] =' ' ; - str[48 ] =' ' ; - str[65 ] ='\0' ; -printf ("%-12c%s\n" ,' ' , str); - } -} -static void get_bdaddr (uint16_t id,uint8_t index,uint8_t *bdaddr) { bdaddr[0 ] = id &0xff ;
@@ -768,6 +733,22 @@ void btdev_destroy(struct btdev *btdev)free (btdev); } +bool btdev_set_debug (struct btdev *btdev,btdev_debug_func_t callback, +void *user_data,btdev_destroy_func_t destroy) +{ +if (!btdev) +return false; + +if (btdev->debug_destroy) + btdev->debug_destroy (btdev->debug_data); + + btdev->debug_callback = callback; + btdev->debug_destroy = destroy; + btdev->debug_data = user_data; + +return true; +} +const uint8_t *btdev_get_bdaddr (struct btdev *btdev) {return btdev->bdaddr;
@@ -824,9 +805,20 @@ void btdev_set_send_handler(struct btdev *btdev, btdev_send_func handler,static void send_packet (struct btdev *btdev,const struct iovec *iov,int iovlen) { +int i; +if (!btdev->send_handler)return ; +for (i =0 ; i < iovlen; i++) { +if (!i) +util_hexdump ('<' , iov[i].iov_base, iov[i].iov_len, + btdev->debug_callback, btdev->debug_data); +else +util_hexdump (' ' , iov[i].iov_base, iov[i].iov_len, + btdev->debug_callback, btdev->debug_data); + } + btdev->send_handler (iov, iovlen, btdev->send_data); }
@@ -837,6 +829,9 @@ static void send_event(struct btdev *btdev, uint8_t event,struct iovec iov[3 ];uint8_t pkt =BT_H4_EVT_PKT ; +util_debug (btdev->debug_callback, btdev->debug_data, +"event 0x%02x" , event); + iov[0 ].iov_base = &pkt; iov[0 ].iov_len =sizeof (pkt);
@@ -863,6 +858,9 @@ static void send_cmd(struct btdev *btdev, uint8_t evt, uint16_t opcode,uint8_t pkt =BT_H4_EVT_PKT ;int i; +util_debug (btdev->debug_callback, btdev->debug_data, +"event 0x%02x opcode 0x%04x" , evt, opcode); + iov2[0 ].iov_base = &pkt; iov2[0 ].iov_len =sizeof (pkt);
@@ -921,6 +919,9 @@ static void le_meta_event(struct btdev *btdev, uint8_t event, {void *pkt_data; +util_debug (btdev->debug_callback, btdev->debug_data, +"meta event 0x%02x" , event); + pkt_data =alloca (1 + len);if (!pkt_data)return ;
@@ -2089,7 +2090,6 @@ static void send_ext_adv(struct btdev *btdev, const struct btdev *remote, uint16_t type, bool is_scan_rsp) { struct __packed { - uint8_t subevent; uint8_t num_reports; union { struct bt_hci_le_ext_adv_report lear;
@@ -2097,8 +2097,6 @@ static void send_ext_adv(struct btdev *btdev, const struct btdev *remote, }; } meta_event; - meta_event.subevent =BT_HCI_EVT_LE_EXT_ADV_REPORT ; -memset (&meta_event.lear,0 ,sizeof (meta_event.lear)); meta_event.num_reports =1 ; meta_event.lear.event_type =cpu_to_le16 (type);
@@ -2121,8 +2119,8 @@ static void send_ext_adv(struct btdev *btdev, const struct btdev *remote, meta_event.lear.data_len); } -send_event (btdev,BT_HCI_EVT_LE_META_EVENT , &meta_event, -1 +1 +24 + meta_event.lear.data_len); +le_meta_event (btdev,BT_HCI_EVT_LE_EXT_ADV_REPORT , &meta_event, +1 +24 + meta_event.lear.data_len); }static uint8_t get_adv_report_type (uint8_t adv_type)
@@ -3952,8 +3950,8 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,return ; unsupported: -printf ("Unsupported command 0x%4.4x\n" , opcode); -hexdump (data, len); +util_debug (btdev->debug_callback, btdev->debug_data, +"Unsupported command 0x%4.4x\n" , opcode);cmd_status (btdev,BT_HCI_ERR_UNKNOWN_COMMAND , opcode); }
@@ -4267,6 +4265,9 @@ static void process_cmd(struct btdev *btdev, const void *data, uint16_t len) callback.data = data +sizeof (*hdr); callback.len = hdr->plen; +util_debug (btdev->debug_callback, btdev->debug_data, +"command 0x%04x" , callback.opcode); +if (btdev->command_handler) btdev->command_handler(callback.opcode, callback.data, callback.len,
@@ -4331,6 +4332,9 @@ void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len)if (len <1 )return ; +util_hexdump ('>' , data, len, btdev->debug_callback, + btdev->debug_data); + pkt_type = ((const uint8_t *) data)[0 ];switch (pkt_type) {
@@ -4348,7 +4352,8 @@ void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len)send_iso (btdev->conn, data, len);break ;default : -printf ("Unsupported packet 0x%2.2x\n" , pkt_type); +util_debug (btdev->debug_callback, btdev->debug_data, +"Unsupported packet 0x%2.2x\n" , pkt_type);break ; } }
emulator/btdev.h +5 -0
@@ -66,6 +66,11 @@ struct btdev;struct btdev *btdev_create (enum btdev_type type,uint16_t id);void btdev_destroy (struct btdev *btdev); +typedef void (*btdev_debug_func_t )(const char *str,void *user_data); +typedef void (*btdev_destroy_func_t )(void *user_data); +bool btdev_set_debug (struct btdev *btdev,btdev_debug_func_t callback, +void *user_data,btdev_destroy_func_t destroy); +const uint8_t *btdev_get_bdaddr (struct btdev *btdev);uint8_t *btdev_get_features (struct btdev *btdev);
Signature · 1 line
2.26.2
Luiz Augusto von Dentz
maintainerPATCH v2 2/11 emulator/bthost: Add debug support
From: Luiz Augusto von Dentz <[email protected]>
This adds bthost_set_debug which can be used to debug internals of bthost.
--- emulator/bthost.c | 73 ++++++++++++++++++++++++++++++++++++++++------- emulator/bthost.h | 5 ++++ 2 files changed, 68 insertions(+), 10 deletions(-)
emulator/bthost.c +63 -10
@@ -24,6 +24,7 @@#include "lib/bluetooth.h" #include "src/shared/util.h" +#include "src/shared/tester.h" #include "monitor/bt.h" #include "monitor/rfcomm.h" #include "bthost.h"
@@ -213,6 +214,10 @@ struct bthost {bool conn_init;bool le;bool sc; + +bthost_debug_func_t debug_callback; +bthost_destroy_func_t debug_destroy; +void *debug_data; };struct bthost *bthost_create (void )
@@ -487,9 +492,20 @@ static void queue_command(struct bthost *bthost, const struct iovec *iov,static void send_packet (struct bthost *bthost,const struct iovec *iov,int iovlen) { +int i; +if (!bthost->send_handler)return ; +for (i =0 ; i < iovlen; i++) { +if (!i) +util_hexdump ('<' , iov[i].iov_base, iov[i].iov_len, + bthost->debug_callback, bthost->debug_data); +else +util_hexdump (' ' , iov[i].iov_base, iov[i].iov_len, + bthost->debug_callback, bthost->debug_data); + } + bthost->send_handler (iov, iovlen, bthost->send_data); }
@@ -675,6 +691,9 @@ static void send_command(struct bthost *bthost, uint16_t opcode,uint8_t pkt =BT_H4_CMD_PKT ;struct iovec iov[3 ]; +util_debug (bthost->debug_callback, bthost->debug_data, +"command 0x%02x" , opcode); + iov[0 ].iov_base = &pkt; iov[0 ].iov_len =sizeof (pkt);
@@ -759,6 +778,22 @@ void bthost_notify_ready(struct bthost *bthost, bthost_ready_cb cb) bthost->ready_cb = cb; } +bool bthost_set_debug (struct bthost *bthost,bthost_debug_func_t callback, +void *user_data,bthost_destroy_func_t destroy) +{ +if (!bthost) +return false; + +if (bthost->debug_destroy) + bthost->debug_destroy (bthost->debug_data); + + bthost->debug_callback = callback; + bthost->debug_destroy = destroy; + bthost->debug_data = user_data; + +return true; +} +static void read_local_features_complete (struct bthost *bthost,const void *data,uint8_t len) {
@@ -835,7 +870,8 @@ static void evt_cmd_complete(struct bthost *bthost, const void *data,case BT_HCI_CMD_LE_SET_EXT_ADV_ENABLE :break ;default : -printf ("Unhandled cmd_complete opcode 0x%04x\n" , opcode); +util_debug (bthost->debug_callback, bthost->debug_data, +"Unhandled cmd_complete opcode 0x%04x" , opcode);break ; }
@@ -1242,6 +1278,9 @@ static void evt_le_meta_event(struct bthost *bthost, const void *data,if (len <1 )return ; +util_debug (bthost->debug_callback, bthost->debug_data, +"event 0x%02x" , *event); +switch (*event) {case BT_HCI_EVT_LE_CONN_COMPLETE :evt_le_conn_complete (bthost, evt_data, len -1 );
@@ -1259,7 +1298,8 @@ static void evt_le_meta_event(struct bthost *bthost, const void *data,evt_le_ext_conn_complete (bthost, evt_data, len -1 );break ;default : -printf ("Unsupported LE Meta event 0x%2.2x\n" , *event); +util_debug (bthost->debug_callback, bthost->debug_data, +"Unsupported LE Meta event 0x%2.2x" , *event);break ; } }
@@ -1277,6 +1317,9 @@ static void process_evt(struct bthost *bthost, const void *data, uint16_t len) param = data +sizeof (*hdr); +util_debug (bthost->debug_callback, bthost->debug_data, +"event 0x%02x" , hdr->evt); +switch (hdr->evt) {case BT_HCI_EVT_CMD_COMPLETE :evt_cmd_complete (bthost, param, hdr->plen);
@@ -1343,7 +1386,8 @@ static void process_evt(struct bthost *bthost, const void *data, uint16_t len)break ;default : -printf ("Unsupported event 0x%2.2x\n" , hdr->evt); +util_debug (bthost->debug_callback, bthost->debug_data, +"Unsupported event 0x%2.2x" , hdr->evt);break ; } }
@@ -1674,7 +1718,8 @@ static void l2cap_sig(struct bthost *bthost, struct btconn *conn,break ;default : -printf ("Unknown L2CAP code 0x%02x\n" , hdr->code); +util_debug (bthost->debug_callback, bthost->debug_data, +"Unknown L2CAP code 0x%02x" , hdr->code); ret = false; }
@@ -1892,7 +1937,8 @@ static void l2cap_le_sig(struct bthost *bthost, struct btconn *conn,break ;default : -printf ("Unknown L2CAP code 0x%02x\n" , hdr->code); +util_debug (bthost->debug_callback, bthost->debug_data, +"Unknown L2CAP code 0x%02x" , hdr->code); ret = false; }
@@ -2232,7 +2278,8 @@ static void process_rfcomm(struct bthost *bthost, struct btconn *conn,rfcomm_uih_recv (bthost, conn, l2conn, data, len);break ;default : -printf ("Unknown frame type\n" ); +util_debug (bthost->debug_callback, bthost->debug_data, +"Unknown frame type" );break ; } }
@@ -2257,7 +2304,8 @@ static void process_acl(struct bthost *bthost, const void *data, uint16_t len) handle =acl_handle (acl_hdr->handle); conn =bthost_find_conn (bthost, handle);if (!conn) { -printf ("ACL data for unknown handle 0x%04x\n" , handle); +util_debug (bthost->debug_callback, bthost->debug_data, +"ACL data for unknown handle 0x%04x" , handle);return ; }
@@ -2293,8 +2341,9 @@ static void process_acl(struct bthost *bthost, const void *data, uint16_t len)if (l2conn && l2conn->psm ==0x0003 )process_rfcomm (bthost, conn, l2conn, l2_data, l2_len);else -printf ("Packet for unknown CID 0x%04x (%u)\n" , cid, - cid); +util_debug (bthost->debug_callback, bthost->debug_data, +"Packet for unknown CID 0x%04x (%u)" , + cid, cid);break ; } }
@@ -2309,6 +2358,9 @@ void bthost_receive_h4(struct bthost *bthost, const void *data, uint16_t len)if (len <1 )return ; +util_hexdump ('>' , data, len, bthost->debug_callback, + bthost->debug_data); + pkt_type = ((const uint8_t *) data)[0 ];switch (pkt_type) {
@@ -2319,7 +2371,8 @@ void bthost_receive_h4(struct bthost *bthost, const void *data, uint16_t len)process_acl (bthost, data +1 , len -1 );break ;default : -printf ("Unsupported packet 0x%2.2x\n" , pkt_type); +util_debug (bthost->debug_callback, bthost->debug_data, +"Unsupported packet 0x%2.2x" , pkt_type);break ; } }
emulator/bthost.h +5 -0
@@ -23,6 +23,11 @@ void bthost_destroy(struct bthost *bthost);typedef void (*bthost_ready_cb ) (void );void bthost_notify_ready (struct bthost *bthost,bthost_ready_cb cb); +typedef void (*bthost_debug_func_t )(const char *str,void *user_data); +typedef void (*bthost_destroy_func_t )(void *user_data); +bool bthost_set_debug (struct bthost *bthost,bthost_debug_func_t callback, +void *user_data,bthost_destroy_func_t destroy); +void bthost_set_send_handler (struct bthost *bthost,bthost_send_func handler,void *user_data);
Signature · 1 line
2.26.2
Luiz Augusto von Dentz
maintainerPATCH v2 3/11 emulator/hciemu: Add debug support
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This adds bthost_set_debug which can be used to debug internals of hciemu.
--- emulator/hciemu.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ emulator/hciemu.h | 5 +++++ 2 files changed, 53 insertions(+)
emulator/hciemu.c +48 -0
@@ -45,6 +45,10 @@ struct hciemu {guint client_source;struct queue *post_command_hooks;char bdaddr_str[18 ]; + +hciemu_debug_func_t debug_callback; +hciemu_destroy_func_t debug_destroy; +void *debug_data; };struct hciemu_command_hook {
@@ -385,6 +389,50 @@ void hciemu_unref(struct hciemu *hciemu)free (hciemu); } +static void bthost_debug (const char *str,void *user_data) +{ +struct hciemu *hciemu = user_data; + +util_debug (hciemu->debug_callback, hciemu->debug_data, +"bthost: %s" , str); +} + +static void btdev_master_debug (const char *str,void *user_data) +{ +struct hciemu *hciemu = user_data; + +util_debug (hciemu->debug_callback, hciemu->debug_data, +"btdev: %s" , str); +} + +static void btdev_client_debug (const char *str,void *user_data) +{ +struct hciemu *hciemu = user_data; + +util_debug (hciemu->debug_callback, hciemu->debug_data, +"btdev[bthost]: %s" , str); +} + +bool hciemu_set_debug (struct hciemu *hciemu,hciemu_debug_func_t callback, +void *user_data,hciemu_destroy_func_t destroy) +{ +if (!hciemu) +return false; + +if (hciemu->debug_destroy) + hciemu->debug_destroy (hciemu->debug_data); + + hciemu->debug_callback = callback; + hciemu->debug_destroy = destroy; + hciemu->debug_data = user_data; + +btdev_set_debug (hciemu->master_dev, btdev_master_debug, hciemu,NULL ); +btdev_set_debug (hciemu->client_dev, btdev_client_debug, hciemu,NULL ); +bthost_set_debug (hciemu->host_stack, bthost_debug, hciemu,NULL ); + +return true; +} +const char *hciemu_get_address (struct hciemu *hciemu) {const uint8_t *addr;
emulator/hciemu.h +5 -0
@@ -34,6 +34,11 @@ struct hciemu *hciemu_new(enum hciemu_type type);struct hciemu *hciemu_ref (struct hciemu *hciemu);void hciemu_unref (struct hciemu *hciemu); +typedef void (*hciemu_debug_func_t )(const char *str,void *user_data); +typedef void (*hciemu_destroy_func_t )(void *user_data); +bool hciemu_set_debug (struct hciemu *hciemu,hciemu_debug_func_t callback, +void *user_data,hciemu_destroy_func_t destroy); +struct bthost *hciemu_client_get_host (struct hciemu *hciemu);const char *hciemu_get_address (struct hciemu *hciemu);
Signature · 1 line
2.26.2
Luiz Augusto von Dentz
maintainerPATCH v2 4/11 emulator: Fix not gerating proper advertisement
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
When a btdev instance advertise using the legacy command and the other instance uses the extended version to scan the report type are not actually setting the legacy PDU properly.
--- emulator/btdev.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
emulator/btdev.c +25 -0
@@ -2154,6 +2154,29 @@ static uint8_t get_ext_adv_type(uint8_t ext_adv_type)return ext_adv_type; } +static uint16_t ext_legacy_adv_type (uint8_t type) +{ +switch (type) { +case 0x00 : +/* Connectable undirected - ADV_IND" */ +return 0x0013 ; +case 0x01 : +/* Connectable directed - ADV_DIRECT_IND */ +return 0x0015 ; +case 0x02 : +/* Scannable undirected - ADV_SCAN_IND */ +return 0x0012 ; +case 0x03 : +/* Non connectable undirected - ADV_NONCONN_IND */ +return 0x0010 ; +case 0x04 : +/* Scan response - SCAN_RSP */ +return 0x0012 ; + } + +return 0x0000 ; +} +static void le_set_adv_enable_complete (struct btdev *btdev) {uint8_t report_type;
@@ -3413,6 +3436,8 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode, lsap = data; btdev->le_adv_type = lsap->type; +/* Use Legacy PDU if the remote is using EXT Scan */ + btdev->le_ext_adv_type =ext_legacy_adv_type (lsap->type); btdev->le_adv_own_addr = lsap->own_addr_type; btdev->le_adv_direct_addr_type = lsap->direct_addr_type;memcpy (btdev->le_adv_direct_addr, lsap->direct_addr,6 );
Signature · 1 line
2.26.2
Luiz Augusto von Dentz
maintainerPATCH v2 5/11 emulator/bthost: Add support for LE CIS Request
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This enables bthost to act as acceptor of LE CIS Request.
--- emulator/bthost.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
emulator/bthost.c +18 -0
@@ -1269,6 +1269,21 @@ static void evt_le_ltk_request(struct bthost *bthost, const void *data, sizeof(cp)); } +static void evt_le_cis_req (struct bthost *bthost,const void *data,uint8_t len) +{ +const struct bt_hci_evt_le_cis_req *ev = data; +struct bt_hci_cmd_le_accept_cis cmd; + +if (len <sizeof (*ev)) +return ; + +memset (&cmd,0 ,sizeof (cmd)); + + cmd.handle = ev->cis_handle; + +send_command (bthost,BT_HCI_CMD_LE_ACCEPT_CIS , &cmd,sizeof (cmd)); +} +static void evt_le_meta_event (struct bthost *bthost,const void *data,uint8_t len) {
@@ -1297,6 +1312,9 @@ static void evt_le_meta_event(struct bthost *bthost, const void *data,case BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE :evt_le_ext_conn_complete (bthost, evt_data, len -1 );break ; +case BT_HCI_EVT_LE_CIS_REQ : +evt_le_cis_req (bthost, evt_data, len -1 ); +break ;default :util_debug (bthost->debug_callback, bthost->debug_data,"Unsupported LE Meta event 0x%2.2x" , *event);
Signature · 1 line
2.26.2
Luiz Augusto von Dentz
maintainerPATCH v2 6/11 tools/l2cap-tester: Enable hciemu debug
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This enable hciemu debug when debug is enabled.
--- tools/l2cap-tester.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/l2cap-tester.c +5 -2
@@ -85,7 +85,7 @@ struct l2cap_data {bool shut_sock_wr; }; -static void mgmt_debug (const char *str,void *user_data) +static void print_debug (const char *str,void *user_data) {const char *prefix = user_data;
@@ -190,6 +190,9 @@ static void read_index_list_callback(uint8_t status, uint16_t length,tester_pre_setup_failed (); } +if (tester_use_debug ()) +hciemu_set_debug (data->hciemu, print_debug,"hciemu: " ,NULL ); +tester_print ("New hciemu instance created" ); }
@@ -205,7 +208,7 @@ static void test_pre_setup(const void *test_data) }if (tester_use_debug ()) -mgmt_set_debug (data->mgmt, mgmt_debug,"mgmt: " ,NULL ); +mgmt_set_debug (data->mgmt, print_debug,"mgmt: " ,NULL );mgmt_send (data->mgmt,MGMT_OP_READ_INDEX_LIST ,MGMT_INDEX_NONE ,0 ,NULL , read_index_list_callback,NULL ,NULL );
Signature · 1 line
2.26.2
Luiz Augusto von Dentz
maintainerPATCH v2 7/11 tools/mgmt-tester: Enable hciemu debug
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This enable hciemu debug when debug is enabled.
--- tools/mgmt-tester.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
tools/mgmt-tester.c +6 -3
@@ -57,7 +57,7 @@ struct test_data {int sk; }; -static void mgmt_debug (const char *str,void *user_data) +static void print_debug (const char *str,void *user_data) {const char *prefix = user_data;
@@ -285,6 +285,9 @@ static void read_index_list_callback(uint8_t status, uint16_t length,tester_pre_setup_failed (); } +if (tester_use_debug ()) +hciemu_set_debug (data->hciemu, print_debug,"hciemu: " ,NULL ); +if (test && test->setup_le_states)hciemu_set_master_le_states (data->hciemu, test->le_states); }
@@ -311,8 +314,8 @@ static void test_pre_setup(const void *test_data) }if (tester_use_debug ()) { -mgmt_set_debug (data->mgmt, mgmt_debug,"mgmt: " ,NULL ); -mgmt_set_debug (data->mgmt_alt, mgmt_debug,"mgmt-alt: " ,NULL ); +mgmt_set_debug (data->mgmt, print_debug,"mgmt: " ,NULL ); +mgmt_set_debug (data->mgmt_alt, print_debug,"mgmt-alt: " ,NULL ); } mgmt_send(data->mgmt, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL,
Signature · 1 line
2.26.2
Luiz Augusto von Dentz
maintainerPATCH v2 8/11 tools/bnep-tester: Enable hciemu debug
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This enable hciemu debug when debug is enabled.
--- tools/bnep-tester.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/bnep-tester.c +5 -2
@@ -59,7 +59,7 @@ struct rfcomm_server_data {uint16_t data_len; }; -static void mgmt_debug (const char *str,void *user_data) +static void print_debug (const char *str,void *user_data) {const char *prefix = user_data;
@@ -164,6 +164,9 @@ static void read_index_list_callback(uint8_t status, uint16_t length,tester_pre_setup_failed (); } +if (tester_use_debug ()) +hciemu_set_debug (data->hciemu, print_debug,"hciemu: " ,NULL ); +tester_print ("New hciemu instance created" ); }
@@ -179,7 +182,7 @@ static void test_pre_setup(const void *test_data) }if (tester_use_debug ()) -mgmt_set_debug (data->mgmt, mgmt_debug,"mgmt: " ,NULL ); +mgmt_set_debug (data->mgmt, print_debug,"mgmt: " ,NULL );mgmt_send (data->mgmt,MGMT_OP_READ_INDEX_LIST ,MGMT_INDEX_NONE ,0 ,NULL , read_index_list_callback,NULL ,NULL );
Signature · 1 line
2.26.2
Luiz Augusto von Dentz
maintainerPATCH v2 9/11 tools/rfcomm-tester: Enable hciemu debug
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This enable hciemu debug when debug is enabled.
--- tools/rfcomm-tester.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/rfcomm-tester.c +5 -2
@@ -59,7 +59,7 @@ struct rfcomm_server_data {uint16_t data_len; }; -static void mgmt_debug (const char *str,void *user_data) +static void print_debug (const char *str,void *user_data) {const char *prefix = user_data;
@@ -164,6 +164,9 @@ static void read_index_list_callback(uint8_t status, uint16_t length,tester_pre_setup_failed (); } +if (tester_use_debug ()) +hciemu_set_debug (data->hciemu, print_debug,"hciemu: " ,NULL ); +tester_print ("New hciemu instance created" ); }
@@ -179,7 +182,7 @@ static void test_pre_setup(const void *test_data) }if (tester_use_debug ()) -mgmt_set_debug (data->mgmt, mgmt_debug,"mgmt: " ,NULL ); +mgmt_set_debug (data->mgmt, print_debug,"mgmt: " ,NULL );mgmt_send (data->mgmt,MGMT_OP_READ_INDEX_LIST ,MGMT_INDEX_NONE ,0 ,NULL , read_index_list_callback,NULL ,NULL );
Signature · 1 line
2.26.2
Luiz Augusto von Dentz
maintainerPATCH v2 10/11 tools/sco-tester: Enable hciemu debug
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This enable hciemu debug when debug is enabled.
--- tools/sco-tester.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/sco-tester.c +5 -2
@@ -44,7 +44,7 @@ struct sco_client_data {int expect_err; }; -static void mgmt_debug (const char *str,void *user_data) +static void print_debug (const char *str,void *user_data) {const char *prefix = user_data;
@@ -150,6 +150,9 @@ static void read_index_list_callback(uint8_t status, uint16_t length,return ; } +if (tester_use_debug ()) +hciemu_set_debug (data->hciemu, print_debug,"hciemu: " ,NULL ); +tester_print ("New hciemu instance created" );if (data->disable_esco) {
@@ -175,7 +178,7 @@ static void test_pre_setup(const void *test_data) }if (tester_use_debug ()) -mgmt_set_debug (data->mgmt, mgmt_debug,"mgmt: " ,NULL ); +mgmt_set_debug (data->mgmt, print_debug,"mgmt: " ,NULL );mgmt_send (data->mgmt,MGMT_OP_READ_INDEX_LIST ,MGMT_INDEX_NONE ,0 ,NULL , read_index_list_callback,NULL ,NULL );
Signature · 1 line
2.26.2
Luiz Augusto von Dentz
maintainerPATCH v2 11/11 tools/smp-tester: Enable hciemu debug
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This enable hciemu debug when debug is enabled.
--- tools/smp-tester.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/smp-tester.c +5 -2
@@ -82,7 +82,7 @@ struct smp_data {bool sc; }; -static void mgmt_debug (const char *str,void *user_data) +static void print_debug (const char *str,void *user_data) {const char *prefix = user_data;
@@ -187,6 +187,9 @@ static void read_index_list_callback(uint8_t status, uint16_t length,tester_pre_setup_failed (); } +if (tester_use_debug ()) +hciemu_set_debug (data->hciemu, print_debug,"hciemu: " ,NULL ); +tester_print ("New hciemu instance created" ); }
@@ -210,7 +213,7 @@ static void test_pre_setup(const void *test_data) }if (tester_use_debug ()) -mgmt_set_debug (data->mgmt, mgmt_debug,"mgmt: " ,NULL ); +mgmt_set_debug (data->mgmt, print_debug,"mgmt: " ,NULL );mgmt_send (data->mgmt,MGMT_OP_READ_INDEX_LIST ,MGMT_INDEX_NONE ,0 ,NULL , read_index_list_callback,NULL ,NULL );
Signature · 1 line
2.26.2
Luiz Augusto von Dentz
maintainerHi,
Quoted 231 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This adds
btdev_set_debugwhich can be used to debug internals of btdev.--- emulator/btdev.c | 99 +++++++++++++++++++++++++----------------------- emulator/btdev.h | 5 +++ 2 files changed, 57 insertions(+), 47 deletions(-)emulator/btdev.c +52
-47@@ -144,6 +144,10 @@ struct btdev {uint8_t sync_train_service_data;uint16_t le_ext_adv_type; + +btdev_debug_func_t debug_callback; +btdev_destroy_func_t debug_destroy; +void *debug_data; };struct inquiry_data {@@ -257,45 +261,6 @@ static inline struct btdev *find_btdev_by_bdaddr_type(const uint8_t *bdaddr,return NULL ; } -static void hexdump (const unsigned char *buf,uint16_t len) -{ -static const char hexdigits[] ="0123456789abcdef" ; -char str[68 ]; -uint16_t i; - -if (!len) -return ; - -for (i =0 ; i < len; i++) { - str[((i %16 ) *3 ) +0 ] = hexdigits[buf[i] >>4 ]; - str[((i %16 ) *3 ) +1 ] = hexdigits[buf[i] &0xf ]; - str[((i %16 ) *3 ) +2 ] =' ' ; - str[(i %16 ) +49 ] =isprint (buf[i]) ? buf[i] :'.' ; - -if ((i +1 ) %16 ==0 ) { - str[47 ] =' ' ; - str[48 ] =' ' ; - str[65 ] ='\0' ; -printf ("%-12c%s\n" ,' ' , str); - str[0 ] =' ' ; - } - } - -if (i %16 >0 ) { -uint16_t j; -for (j = (i %16 ); j <16 ; j++) { - str[(j *3 ) +0 ] =' ' ; - str[(j *3 ) +1 ] =' ' ; - str[(j *3 ) +2 ] =' ' ; - str[j +49 ] =' ' ; - } - str[47 ] =' ' ; - str[48 ] =' ' ; - str[65 ] ='\0' ; -printf ("%-12c%s\n" ,' ' , str); - } -} -static void get_bdaddr (uint16_t id,uint8_t index,uint8_t *bdaddr) { bdaddr[0 ] = id &0xff ;@@ -768,6 +733,22 @@ void btdev_destroy(struct btdev *btdev)free (btdev); } +bool btdev_set_debug (struct btdev *btdev,btdev_debug_func_t callback, +void *user_data,btdev_destroy_func_t destroy) +{ +if (!btdev) +return false; + +if (btdev->debug_destroy) + btdev->debug_destroy (btdev->debug_data); + + btdev->debug_callback = callback; + btdev->debug_destroy = destroy; + btdev->debug_data = user_data; + +return true; +} +const uint8_t *btdev_get_bdaddr (struct btdev *btdev) {return btdev->bdaddr;@@ -824,9 +805,20 @@ void btdev_set_send_handler(struct btdev *btdev, btdev_send_func handler,static void send_packet (struct btdev *btdev,const struct iovec *iov,int iovlen) { +int i; +if (!btdev->send_handler)return ; +for (i =0 ; i < iovlen; i++) { +if (!i) +util_hexdump ('<' , iov[i].iov_base, iov[i].iov_len, + btdev->debug_callback, btdev->debug_data); +else +util_hexdump (' ' , iov[i].iov_base, iov[i].iov_len, + btdev->debug_callback, btdev->debug_data); + } + btdev->send_handler (iov, iovlen, btdev->send_data); }@@ -837,6 +829,9 @@ static void send_event(struct btdev *btdev, uint8_t event,struct iovec iov[3 ];uint8_t pkt =BT_H4_EVT_PKT ; +util_debug (btdev->debug_callback, btdev->debug_data, +"event 0x%02x" , event); + iov[0 ].iov_base = &pkt; iov[0 ].iov_len =sizeof (pkt);@@ -863,6 +858,9 @@ static void send_cmd(struct btdev *btdev, uint8_t evt, uint16_t opcode,uint8_t pkt =BT_H4_EVT_PKT ;int i; +util_debug (btdev->debug_callback, btdev->debug_data, +"event 0x%02x opcode 0x%04x" , evt, opcode); + iov2[0 ].iov_base = &pkt; iov2[0 ].iov_len =sizeof (pkt);@@ -921,6 +919,9 @@ static void le_meta_event(struct btdev *btdev, uint8_t event, {void *pkt_data; +util_debug (btdev->debug_callback, btdev->debug_data, +"meta event 0x%02x" , event); + pkt_data =alloca (1 + len);if (!pkt_data)return ;@@ -2089,7 +2090,6 @@ static void send_ext_adv(struct btdev *btdev, const struct btdev *remote, uint16_t type, bool is_scan_rsp) { struct __packed { - uint8_t subevent; uint8_t num_reports; union { struct bt_hci_le_ext_adv_report lear;@@ -2097,8 +2097,6 @@ static void send_ext_adv(struct btdev *btdev, const struct btdev *remote, }; } meta_event; - meta_event.subevent =BT_HCI_EVT_LE_EXT_ADV_REPORT ; -memset (&meta_event.lear,0 ,sizeof (meta_event.lear)); meta_event.num_reports =1 ; meta_event.lear.event_type =cpu_to_le16 (type);@@ -2121,8 +2119,8 @@ static void send_ext_adv(struct btdev *btdev, const struct btdev *remote, meta_event.lear.data_len); } -send_event (btdev,BT_HCI_EVT_LE_META_EVENT , &meta_event, -1 +1 +24 + meta_event.lear.data_len); +le_meta_event (btdev,BT_HCI_EVT_LE_EXT_ADV_REPORT , &meta_event, +1 +24 + meta_event.lear.data_len); }static uint8_t get_adv_report_type (uint8_t adv_type)@@ -3952,8 +3950,8 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,return ; unsupported: -printf ("Unsupported command 0x%4.4x\n" , opcode); -hexdump (data, len); +util_debug (btdev->debug_callback, btdev->debug_data, +"Unsupported command 0x%4.4x\n" , opcode);cmd_status (btdev,BT_HCI_ERR_UNKNOWN_COMMAND , opcode); }@@ -4267,6 +4265,9 @@ static void process_cmd(struct btdev *btdev, const void *data, uint16_t len) callback.data = data +sizeof (*hdr); callback.len = hdr->plen; +util_debug (btdev->debug_callback, btdev->debug_data, +"command 0x%04x" , callback.opcode); +if (btdev->command_handler) btdev->command_handler(callback.opcode, callback.data, callback.len,@@ -4331,6 +4332,9 @@ void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len)if (len <1 )return ; +util_hexdump ('>' , data, len, btdev->debug_callback, + btdev->debug_data); + pkt_type = ((const uint8_t *) data)[0 ];switch (pkt_type) {@@ -4348,7 +4352,8 @@ void btdev_receive_h4(struct btdev *btdev, const void *data, uint16_t len)send_iso (btdev->conn, data, len);break ;default : -printf ("Unsupported packet 0x%2.2x\n" , pkt_type); +util_debug (btdev->debug_callback, btdev->debug_data, +"Unsupported packet 0x%2.2x\n" , pkt_type);break ; } }emulator/btdev.h +5
-1@@ -66,6 +66,11 @@ struct btdev;struct btdev *btdev_create (enum btdev_type type,uint16_t id);void btdev_destroy (struct btdev *btdev); +typedef void (*btdev_debug_func_t )(const char *str,void *user_data); +typedef void (*btdev_destroy_func_t )(void *user_data); +bool btdev_set_debug (struct btdev *btdev,btdev_debug_func_t callback, +void *user_data,btdev_destroy_func_t destroy); +const uint8_t *btdev_get_bdaddr (struct btdev *btdev);uint8_t *btdev_get_features (struct btdev *btdev); --
Quoted 2 lines
2.26.2
Pushed.
Signature · 1 line
Luiz Augusto von Dentz
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=375773
---Test result---
##############################
Test: CheckPatch - PASS
##############################
Test: CheckGitLint - PASS
##############################
Test: CheckBuild - PASS
##############################
Test: MakeCheck - PASS
---
Regards,
Linux Bluetooth