mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-09 21:45:54 +00:00
hfp disconnect on Bluetooth off
This commit is contained in:
parent
8240f3cf00
commit
8e5b880140
26
src/hfp.c
26
src/hfp.c
@ -174,6 +174,18 @@ static hfp_connection_t * get_hfp_connection_context_for_bd_addr(bd_addr_t bd_ad
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hfp_connection_t * get_hfp_connection_context_for_handle(uint16_t handle){
|
||||||
|
linked_list_iterator_t it;
|
||||||
|
linked_list_iterator_init(&it, hfp_get_connections());
|
||||||
|
while (linked_list_iterator_has_next(&it)){
|
||||||
|
hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it);
|
||||||
|
if (connection->con_handle == handle){
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static hfp_connection_t * create_hfp_connection_context(){
|
static hfp_connection_t * create_hfp_connection_context(){
|
||||||
hfp_connection_t * context = btstack_memory_hfp_connection_get();
|
hfp_connection_t * context = btstack_memory_hfp_connection_get();
|
||||||
if (!context) return NULL;
|
if (!context) return NULL;
|
||||||
@ -326,9 +338,9 @@ static void handle_query_rfcomm_event(sdp_query_event_t * event, void * context)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hfp_handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
void hfp_handle_hci_event(hfp_callback_t callback, uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
bd_addr_t event_addr;
|
bd_addr_t event_addr;
|
||||||
uint16_t rfcomm_cid = 0;
|
uint16_t rfcomm_cid, handle;
|
||||||
hfp_connection_t * context = NULL;
|
hfp_connection_t * context = NULL;
|
||||||
|
|
||||||
switch (packet[0]) {
|
switch (packet[0]) {
|
||||||
@ -367,6 +379,7 @@ void hfp_handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
|||||||
if (!context || context->state != HFP_W4_RFCOMM_CONNECTED) return;
|
if (!context || context->state != HFP_W4_RFCOMM_CONNECTED) return;
|
||||||
|
|
||||||
if (packet[2]) {
|
if (packet[2]) {
|
||||||
|
hfp_emit_event(callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, packet[2]);
|
||||||
remove_hfp_connection_context(context);
|
remove_hfp_connection_context(context);
|
||||||
} else {
|
} else {
|
||||||
context->con_handle = READ_BT_16(packet, 9);
|
context->con_handle = READ_BT_16(packet, 9);
|
||||||
@ -393,6 +406,15 @@ void hfp_handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
|||||||
context = get_hfp_connection_context_for_rfcomm_cid(rfcomm_cid);
|
context = get_hfp_connection_context_for_rfcomm_cid(rfcomm_cid);
|
||||||
if (!context) break;
|
if (!context) break;
|
||||||
remove_hfp_connection_context(context);
|
remove_hfp_connection_context(context);
|
||||||
|
hfp_emit_event(callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||||
|
handle = READ_BT_16(packet,3);
|
||||||
|
context = get_hfp_connection_context_for_handle(handle);
|
||||||
|
if (!context) break;
|
||||||
|
hfp_emit_event(callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED, packet[2]);
|
||||||
|
remove_hfp_connection_context(context);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -219,7 +219,7 @@ typedef struct hfp_connection {
|
|||||||
|
|
||||||
|
|
||||||
void hfp_create_service(uint8_t * service, uint16_t service_uuid, int rfcomm_channel_nr, const char * name, uint16_t supported_features);
|
void hfp_create_service(uint8_t * service, uint16_t service_uuid, int rfcomm_channel_nr, const char * name, uint16_t supported_features);
|
||||||
void hfp_handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
void hfp_handle_hci_event(hfp_callback_t callback, uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
void hfp_emit_event(hfp_callback_t callback, uint8_t event_subtype, uint8_t value);
|
void hfp_emit_event(hfp_callback_t callback, uint8_t event_subtype, uint8_t value);
|
||||||
|
|
||||||
void hfp_init(uint16_t rfcomm_channel_nr);
|
void hfp_init(uint16_t rfcomm_channel_nr);
|
||||||
|
14
src/hfp_ag.c
14
src/hfp_ag.c
@ -458,19 +458,7 @@ static void packet_handler(void * connection, uint8_t packet_type, uint16_t chan
|
|||||||
hfp_handle_rfcomm_event(packet_type, channel, packet, size);
|
hfp_handle_rfcomm_event(packet_type, channel, packet, size);
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_PACKET:
|
case HCI_EVENT_PACKET:
|
||||||
hfp_handle_hci_event(packet_type, packet, size);
|
hfp_handle_hci_event(hfp_callback, packet_type, packet, size);
|
||||||
switch(packet[0]){
|
|
||||||
case RFCOMM_EVENT_CHANNEL_CLOSED:
|
|
||||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED, 0);
|
|
||||||
break;
|
|
||||||
case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
|
|
||||||
if (packet[2]){
|
|
||||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, packet[2]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
16
src/hfp_hf.c
16
src/hfp_hf.c
@ -386,22 +386,8 @@ static void packet_handler(void * connection, uint8_t packet_type, uint16_t chan
|
|||||||
hfp_handle_rfcomm_event(packet_type, channel, packet, size);
|
hfp_handle_rfcomm_event(packet_type, channel, packet, size);
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_PACKET:
|
case HCI_EVENT_PACKET:
|
||||||
hfp_handle_hci_event(packet_type, packet, size);
|
hfp_handle_hci_event(hfp_callback, packet_type, packet, size);
|
||||||
switch(packet[0]){
|
|
||||||
case RFCOMM_EVENT_CHANNEL_CLOSED:
|
|
||||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED, 0);
|
|
||||||
break;
|
|
||||||
case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
|
|
||||||
if (packet[2]){
|
|
||||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, packet[2]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
printf(" hf packet handler\n");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
hfp_run();
|
hfp_run();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user