hfp disconnect on Bluetooth off

This commit is contained in:
Milanka Ringwald 2015-08-05 17:23:23 +02:00
parent 8240f3cf00
commit 8e5b880140
4 changed files with 27 additions and 31 deletions

View File

@ -174,6 +174,18 @@ static hfp_connection_t * get_hfp_connection_context_for_bd_addr(bd_addr_t bd_ad
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(){
hfp_connection_t * context = btstack_memory_hfp_connection_get();
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;
uint16_t rfcomm_cid = 0;
uint16_t rfcomm_cid, handle;
hfp_connection_t * context = NULL;
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 (packet[2]) {
hfp_emit_event(callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, packet[2]);
remove_hfp_connection_context(context);
} else {
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);
if (!context) break;
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;
default:

View File

@ -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_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_init(uint16_t rfcomm_channel_nr);

View File

@ -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);
break;
case HCI_EVENT_PACKET:
hfp_handle_hci_event(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;
}
hfp_handle_hci_event(hfp_callback, packet_type, packet, size);
break;
default:
break;

View File

@ -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);
break;
case HCI_EVENT_PACKET:
hfp_handle_hci_event(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;
hfp_handle_hci_event(hfp_callback, packet_type, packet, size);
default:
printf(" hf packet handler\n");
break;
}
hfp_run();