@@ -392,13 +392,15 @@ static void conn_complete_event_cb(BteBuffer *buffer)
392392 void * userdata = pc -> userdata ;
393393 _bte_hci_dev_free_command (pc );
394394
395- create_connection_cb (hci , & reply , userdata );
395+ if (create_connection_cb ) {
396+ create_connection_cb (hci , & reply , userdata );
397+ }
396398}
397399
398400static void create_connection_status_cb (
399401 BteHci * hci , uint8_t status , BteHciPendingCommand * pc )
400402{
401- if (status != 0 ) goto error ;
403+ if (status != 0 || ! hci ) goto error ;
402404
403405 struct _bte_hci_tmpdata_create_connection_t * tmpdata =
404406 & hci -> last_async_cmd_data .create_connection ;
@@ -590,11 +592,13 @@ void bte_hci_reject_connection(BteHci *hci,
590592 create_connection_status_cb , status_cb , userdata );
591593 if (UNLIKELY (!b )) return ;
592594
593- /* In the status callback we read this and setup the event matcher */
594- struct _bte_hci_tmpdata_create_connection_t * tmpdata =
595- & hci -> last_async_cmd_data .create_connection ;
596- memcpy (& tmpdata -> address , address , sizeof (* address ));
597- tmpdata -> client_cb = callback ;
595+ if (hci ) {
596+ /* In the status callback we read this and setup the event matcher */
597+ struct _bte_hci_tmpdata_create_connection_t * tmpdata =
598+ & hci -> last_async_cmd_data .create_connection ;
599+ memcpy (& tmpdata -> address , address , sizeof (* address ));
600+ tmpdata -> client_cb = callback ;
601+ }
598602
599603 uint8_t * data = b -> data + HCI_CMD_HDR_LEN ;
600604 memcpy (data , address , sizeof (* address ));
@@ -617,7 +621,13 @@ static bool client_handle_connection_request(BteHci *hci, void *cb_data)
617621static void connection_request_event_cb (BteBuffer * buffer )
618622{
619623 uint8_t * data = buffer -> data + HCI_CMD_EVENT_POS_DATA ;
620- _bte_hci_dev_foreach_hci_client (client_handle_connection_request , data );
624+ bool handled =
625+ _bte_hci_dev_foreach_hci_client (client_handle_connection_request , data );
626+ if (!handled ) {
627+ const BteBdAddr * address = (void * )data ;
628+ bte_hci_reject_connection (NULL , address , BTE_HCI_HOST_REJECTED_BD_ADDR ,
629+ NULL , NULL , NULL );
630+ }
621631}
622632
623633void bte_hci_on_connection_request (BteHci * hci , BteHciConnectionRequestCb callback )
0 commit comments