hci.c (3251a10887e6e0a8d4015b375a0ab472839b09e5) hci.c (6e058d3f5181cea543a79b46dc4044bb0d0cfa8e)
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

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

2017 if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_supported_commands)){
2018 hci_stack->local_supported_commands[0] =
2019 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+14] & 0x80) >> 7) | // bit 0 = Octet 14, bit 7 / Read Buffer Size
2020 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+24] & 0x40) >> 5) | // bit 1 = Octet 24, bit 6 / Write Le Host Supported
2021 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+10] & 0x10) >> 2) | // bit 2 = Octet 10, bit 4 / Write Synchronous Flow Control Enable
2022 (packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+18] & 0x08) | // bit 3 = Octet 18, bit 3 / Write Default Erroneous Data Reporting
2023 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+34] & 0x01) << 4) | // bit 4 = Octet 34, bit 0 / LE Write Suggested Default Data Length
2024 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+35] & 0x08) << 2) | // bit 5 = Octet 35, bit 3 / LE Read Maximum Data Length
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

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

2017 if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_supported_commands)){
2018 hci_stack->local_supported_commands[0] =
2019 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+14] & 0x80) >> 7) | // bit 0 = Octet 14, bit 7 / Read Buffer Size
2020 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+24] & 0x40) >> 5) | // bit 1 = Octet 24, bit 6 / Write Le Host Supported
2021 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+10] & 0x10) >> 2) | // bit 2 = Octet 10, bit 4 / Write Synchronous Flow Control Enable
2022 (packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+18] & 0x08) | // bit 3 = Octet 18, bit 3 / Write Default Erroneous Data Reporting
2023 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+34] & 0x01) << 4) | // bit 4 = Octet 34, bit 0 / LE Write Suggested Default Data Length
2024 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+35] & 0x08) << 2) | // bit 5 = Octet 35, bit 3 / LE Read Maximum Data Length
2025 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+35] & 0x20) << 1); // bit 6 = Octet 35, bit 5 / LE Set Default PHY
2026 log_info("Local supported commands summary 0x%02x", hci_stack->local_supported_commands[0]);
2025 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+35] & 0x20) << 1) | // bit 6 = Octet 35, bit 5 / LE Set Default PHY
2026 ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+20] & 0x10) << 3); // bit 7 = Octet 20, bit 4 / Read Encryption Key Size
2027 log_info("Local supported commands summary 0x%02x", hci_stack->local_supported_commands[0]);
2027 }
2028#ifdef ENABLE_CLASSIC
2029 if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_write_synchronous_flow_control_enable)){
2030 if (packet[5] == 0){
2031 hci_stack->synchronous_flow_control_enabled = 1;
2032 }
2033 }
2034 if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_encryption_key_size)){

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

2311 handle = little_endian_read_16(packet, 3);
2312 conn = hci_connection_for_handle(handle);
2313 if (!conn) break;
2314 if (packet[2] == 0) {
2315 if (packet[5]){
2316 if (hci_is_le_connection(conn)){
2317 // For LE, we accept connection as encrypted
2318 conn->authentication_flags |= CONNECTION_ENCRYPTED;
2028 }
2029#ifdef ENABLE_CLASSIC
2030 if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_write_synchronous_flow_control_enable)){
2031 if (packet[5] == 0){
2032 hci_stack->synchronous_flow_control_enabled = 1;
2033 }
2034 }
2035 if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_encryption_key_size)){

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

2312 handle = little_endian_read_16(packet, 3);
2313 conn = hci_connection_for_handle(handle);
2314 if (!conn) break;
2315 if (packet[2] == 0) {
2316 if (packet[5]){
2317 if (hci_is_le_connection(conn)){
2318 // For LE, we accept connection as encrypted
2319 conn->authentication_flags |= CONNECTION_ENCRYPTED;
2320 hci_emit_security_level(handle, gap_security_level_for_connection(conn));
2319 }
2320#ifdef ENABLE_CLASSIC
2321 else {
2321 }
2322#ifdef ENABLE_CLASSIC
2323 else {
2322 // For Classic, we need to validate encryption key size first
2323 conn->bonding_flags |= BONDING_SEND_READ_ENCRYPTION_KEY_SIZE;
2324 if ((hci_stack->local_supported_commands[0] & 0x80) != 0){
2325 // For Classic, we need to validate encryption key size first, if possible (== supported by Controller)
2326 conn->bonding_flags |= BONDING_SEND_READ_ENCRYPTION_KEY_SIZE;
2327 } else {
2328 // if not, pretend everything is perfect
2329 conn->encryption_key_size = 16;
2330 conn->authentication_flags |= CONNECTION_ENCRYPTED;
2331 hci_emit_security_level(handle, gap_security_level_for_connection(conn));
2332 }
2324 }
2325#endif
2326 } else {
2327 conn->authentication_flags &= ~CONNECTION_ENCRYPTED;
2328 }
2329 }
2330
2331 break;

--- 3069 unchanged lines hidden ---
2333 }
2334#endif
2335 } else {
2336 conn->authentication_flags &= ~CONNECTION_ENCRYPTED;
2337 }
2338 }
2339
2340 break;

--- 3069 unchanged lines hidden ---