hci.c (de0df0137148fc6d110f2344458f87addc4c2da6) hci.c (76ccfb2aa2bc03b4a7f429e15246c8f49d04aaf8)
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 1893 unchanged lines hidden (view full) ---

1902 if (status == ERROR_CODE_AUTHENTICATION_FAILURE) {
1903 gap_drop_link_key_for_bd_addr(bd_address);
1904 }
1905#endif
1906}
1907
1908static void hci_handle_remote_features_received(hci_connection_t * conn){
1909 conn->bonding_flags |= BONDING_RECEIVED_REMOTE_FEATURES;
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 1893 unchanged lines hidden (view full) ---

1902 if (status == ERROR_CODE_AUTHENTICATION_FAILURE) {
1903 gap_drop_link_key_for_bd_addr(bd_address);
1904 }
1905#endif
1906}
1907
1908static void hci_handle_remote_features_received(hci_connection_t * conn){
1909 conn->bonding_flags |= BONDING_RECEIVED_REMOTE_FEATURES;
1910 log_info("Remote features received, bonding flags %x, eSCO %u", conn->bonding_flags, conn->remote_supported_feature_eSCO);
1910 log_info("Remote features received, bonding flags %x, eSCO %u", conn->bonding_flags, conn->remote_supported_features[0] & 1);
1911 if (conn->bonding_flags & BONDING_DEDICATED){
1912 conn->bonding_flags |= BONDING_SEND_AUTHENTICATE_REQUEST;
1913 }
1914}
1915
1916static void handle_event_for_current_stack_state(const uint8_t * packet, uint16_t size) {
1917 // handle BT initialization
1918 if (hci_stack->state == HCI_STATE_INITIALIZING) {

--- 288 unchanged lines hidden (view full) ---

2207 hci_stack->decline_reason = ERROR_CODE_CONNECTION_REJECTED_DUE_TO_LIMITED_RESOURCES;
2208 bd_addr_copy(hci_stack->decline_addr, addr);
2209 break;
2210 }
2211 conn->role = HCI_ROLE_SLAVE;
2212 conn->state = RECEIVED_CONNECTION_REQUEST;
2213 // store info about eSCO
2214 if (link_type == 0x02){
1911 if (conn->bonding_flags & BONDING_DEDICATED){
1912 conn->bonding_flags |= BONDING_SEND_AUTHENTICATE_REQUEST;
1913 }
1914}
1915
1916static void handle_event_for_current_stack_state(const uint8_t * packet, uint16_t size) {
1917 // handle BT initialization
1918 if (hci_stack->state == HCI_STATE_INITIALIZING) {

--- 288 unchanged lines hidden (view full) ---

2207 hci_stack->decline_reason = ERROR_CODE_CONNECTION_REJECTED_DUE_TO_LIMITED_RESOURCES;
2208 bd_addr_copy(hci_stack->decline_addr, addr);
2209 break;
2210 }
2211 conn->role = HCI_ROLE_SLAVE;
2212 conn->state = RECEIVED_CONNECTION_REQUEST;
2213 // store info about eSCO
2214 if (link_type == 0x02){
2215 conn->remote_supported_feature_eSCO = 1;
2215 conn->remote_supported_features[0] |= 1;
2216 }
2217 hci_run();
2218 break;
2219
2220 case HCI_EVENT_CONNECTION_COMPLETE:
2221 // Connection management
2222 reverse_bd_addr(&packet[5], addr);
2223 log_info("Connection_complete (status=%u) %s", packet[2], bd_addr_to_str(addr));

--- 60 unchanged lines hidden (view full) ---

2284 conn = hci_connection_for_handle(handle);
2285 if (!conn) break;
2286 if (!packet[2]){
2287 uint8_t * features = &packet[5];
2288 if (features[6] & (1 << 3)){
2289 conn->bonding_flags |= BONDING_REMOTE_SUPPORTS_SSP_CONTROLLER;
2290 }
2291 if (features[3] & (1<<7)){
2216 }
2217 hci_run();
2218 break;
2219
2220 case HCI_EVENT_CONNECTION_COMPLETE:
2221 // Connection management
2222 reverse_bd_addr(&packet[5], addr);
2223 log_info("Connection_complete (status=%u) %s", packet[2], bd_addr_to_str(addr));

--- 60 unchanged lines hidden (view full) ---

2284 conn = hci_connection_for_handle(handle);
2285 if (!conn) break;
2286 if (!packet[2]){
2287 uint8_t * features = &packet[5];
2288 if (features[6] & (1 << 3)){
2289 conn->bonding_flags |= BONDING_REMOTE_SUPPORTS_SSP_CONTROLLER;
2290 }
2291 if (features[3] & (1<<7)){
2292 conn->remote_supported_feature_eSCO = 1;
2292 conn->remote_supported_features[0] |= 1;
2293 }
2294 }
2295 hci_handle_remote_features_received(conn);
2296 break;
2297
2298 case HCI_EVENT_LINK_KEY_REQUEST:
2299 log_info("HCI_EVENT_LINK_KEY_REQUEST");
2300 hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_LINK_KEY_REQUEST);

--- 1380 unchanged lines hidden (view full) ---

3681 break;
3682 }
3683 return true;
3684
3685#ifdef ENABLE_CLASSIC
3686 case RECEIVED_CONNECTION_REQUEST:
3687 connection->role = HCI_ROLE_SLAVE;
3688 if (connection->address_type == BD_ADDR_TYPE_ACL){
2293 }
2294 }
2295 hci_handle_remote_features_received(conn);
2296 break;
2297
2298 case HCI_EVENT_LINK_KEY_REQUEST:
2299 log_info("HCI_EVENT_LINK_KEY_REQUEST");
2300 hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_LINK_KEY_REQUEST);

--- 1380 unchanged lines hidden (view full) ---

3681 break;
3682 }
3683 return true;
3684
3685#ifdef ENABLE_CLASSIC
3686 case RECEIVED_CONNECTION_REQUEST:
3687 connection->role = HCI_ROLE_SLAVE;
3688 if (connection->address_type == BD_ADDR_TYPE_ACL){
3689 log_info("sending hci_accept_connection_request, remote eSCO %u", connection->remote_supported_feature_eSCO);
3689 log_info("sending hci_accept_connection_request");
3690 connection->state = ACCEPTED_CONNECTION_REQUEST;
3691 hci_send_cmd(&hci_accept_connection_request, connection->address, hci_stack->master_slave_policy);
3692 }
3693 return true;
3694#endif
3695
3696#ifdef ENABLE_BLE
3697#ifdef ENABLE_LE_CENTRAL

--- 831 unchanged lines hidden (view full) ---

4529 event[2] = enabled;
4530 hci_emit_event(event, sizeof(event), 1);
4531}
4532
4533// query if remote side supports eSCO
4534int hci_remote_esco_supported(hci_con_handle_t con_handle){
4535 hci_connection_t * connection = hci_connection_for_handle(con_handle);
4536 if (!connection) return 0;
3690 connection->state = ACCEPTED_CONNECTION_REQUEST;
3691 hci_send_cmd(&hci_accept_connection_request, connection->address, hci_stack->master_slave_policy);
3692 }
3693 return true;
3694#endif
3695
3696#ifdef ENABLE_BLE
3697#ifdef ENABLE_LE_CENTRAL

--- 831 unchanged lines hidden (view full) ---

4529 event[2] = enabled;
4530 hci_emit_event(event, sizeof(event), 1);
4531}
4532
4533// query if remote side supports eSCO
4534int hci_remote_esco_supported(hci_con_handle_t con_handle){
4535 hci_connection_t * connection = hci_connection_for_handle(con_handle);
4536 if (!connection) return 0;
4537 return connection->remote_supported_feature_eSCO;
4537 return (connection->remote_supported_features[0] & 1) != 0;
4538}
4539
4540// query if remote side supports SSP
4541int hci_remote_ssp_supported(hci_con_handle_t con_handle){
4542 hci_connection_t * connection = hci_connection_for_handle(con_handle);
4543 if (!connection) return 0;
4544 return (connection->bonding_flags & BONDING_REMOTE_SUPPORTS_SSP_CONTROLLER) ? 1 : 0;
4545}

--- 1003 unchanged lines hidden ---
4538}
4539
4540// query if remote side supports SSP
4541int hci_remote_ssp_supported(hci_con_handle_t con_handle){
4542 hci_connection_t * connection = hci_connection_for_handle(con_handle);
4543 if (!connection) return 0;
4544 return (connection->bonding_flags & BONDING_REMOTE_SUPPORTS_SSP_CONTROLLER) ? 1 : 0;
4545}

--- 1003 unchanged lines hidden ---