disconnect all connections when last client disconnects from daemon

This commit is contained in:
matthias.ringwald 2014-06-19 10:33:11 +00:00
parent 24698a3ff3
commit 04a6ef8c3b
3 changed files with 19 additions and 2 deletions

View File

@ -211,7 +211,7 @@ static void send_gatt_query_complete(connection_t * connection, uint16_t handle,
gatt_client_t * daemon_prepare_gatt_client_context(connection_t *connection, uint8_t *packet) {
hci_con_handle_t handle = READ_BT_16(packet, 3);
hci_connection_t hci_con = hci_connection_for_handle(handle);
hci_connection_t * hci_con = hci_connection_for_handle(handle);
if (hci_con->state != OPEN){
send_gatt_query_complete(connection, handle, GATT_CLIENT_NOT_CONNECTED);
return NULL;
@ -757,6 +757,11 @@ static int daemon_client_handler(connection_t *connection, uint16_t packet_type,
// NOTE: experimental - disconnect all LE connections where GATT Client was used
gatt_client_disconnect_connection(connection);
#endif
// no clients -> no HCI connections
if (!clients){
hci_disconnect_all();
}
client = client_for_connection(connection);
if (!client) break;
linked_list_remove(&clients, (linked_item_t *) client);

View File

@ -2313,3 +2313,13 @@ le_command_status_t gap_disconnect(hci_con_handle_t handle){
hci_run();
return BLE_PERIPHERAL_OK;
}
void hci_disconnect_all(){
linked_list_iterator_t it;
linked_list_iterator_init(&it, &hci_stack->connections);
while (linked_list_iterator_has_next(&it)){
hci_connection_t * con = (hci_connection_t*) linked_list_iterator_next(&it);
if (con->state == SENT_DISCONNECT) continue;
con->state = SEND_DISCONNECT;
}
}

View File

@ -473,7 +473,9 @@ int hci_authentication_active_for_handle(hci_con_handle_t handle);
uint16_t hci_max_acl_data_packet_length(void);
uint16_t hci_usable_acl_packet_types(void);
int hci_non_flushable_packet_boundary_flag_supported(void);
//
void hci_disconnect_all();
void hci_emit_state(void);
void hci_emit_connection_complete(hci_connection_t *conn, uint8_t status);
void hci_emit_l2cap_check_timeout(hci_connection_t *conn);