hci.c (573897a04e80b358f96f61316c257740d709d797) | hci.c (170fafaee9eb5b65263bedc18252ad8ce06ca49f) |
---|---|
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 --- 2003 unchanged lines hidden (view full) --- 2012 uint8_t status = packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE]; 2013 handle = little_endian_read_16(packet, OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1); 2014 conn = hci_connection_for_handle(handle); 2015 if (!conn) break; 2016 if (status == 0){ 2017 uint8_t key_size = packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+3]; 2018 log_info("Handle %x04x key Size: %u", handle, key_size); 2019 conn->encryption_key_size = key_size; | 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 --- 2003 unchanged lines hidden (view full) --- 2012 uint8_t status = packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE]; 2013 handle = little_endian_read_16(packet, OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1); 2014 conn = hci_connection_for_handle(handle); 2015 if (!conn) break; 2016 if (status == 0){ 2017 uint8_t key_size = packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+3]; 2018 log_info("Handle %x04x key Size: %u", handle, key_size); 2019 conn->encryption_key_size = key_size; |
2020 } else { 2021 log_info("Read Encryption Key Size failed -> assuming insecure connection with key size of 1"); 2022 conn->encryption_key_size = 1; |
|
2020 } 2021 conn->authentication_flags |= CONNECTION_ENCRYPTED; 2022 hci_emit_security_level(handle, gap_security_level_for_connection(conn)); 2023 } 2024#endif 2025 break; 2026 2027 case HCI_EVENT_COMMAND_STATUS: --- 764 unchanged lines hidden (view full) --- 2792 hci_stack->bondable = 1; 2793 2794#ifdef ENABLE_CLASSIC 2795 // classic name 2796 hci_stack->local_name = default_classic_name; 2797 2798 // Master slave policy 2799 hci_stack->master_slave_policy = 1; | 2023 } 2024 conn->authentication_flags |= CONNECTION_ENCRYPTED; 2025 hci_emit_security_level(handle, gap_security_level_for_connection(conn)); 2026 } 2027#endif 2028 break; 2029 2030 case HCI_EVENT_COMMAND_STATUS: --- 764 unchanged lines hidden (view full) --- 2795 hci_stack->bondable = 1; 2796 2797#ifdef ENABLE_CLASSIC 2798 // classic name 2799 hci_stack->local_name = default_classic_name; 2800 2801 // Master slave policy 2802 hci_stack->master_slave_policy = 1; |
2803 2804 // Errata-11838 mandates 7 bytes for GAP Security Level 1-3, we use 16 as default 2805 hci_stack->gap_required_encyrption_key_size = 16; |
|
2800#endif 2801 2802 // Secure Simple Pairing default: enable, no I/O capabilities, general bonding, mitm not required, auto accept 2803 hci_stack->ssp_enable = 1; 2804 hci_stack->ssp_io_capability = SSP_IO_CAPABILITY_NO_INPUT_NO_OUTPUT; 2805 hci_stack->ssp_authentication_requirement = SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_GENERAL_BONDING; 2806 hci_stack->ssp_auto_accept = 1; 2807 --- 72 unchanged lines hidden (view full) --- 2880 2881#ifdef HAVE_MALLOC 2882 free(hci_stack); 2883#endif 2884 hci_stack = NULL; 2885} 2886 2887#ifdef ENABLE_CLASSIC | 2806#endif 2807 2808 // Secure Simple Pairing default: enable, no I/O capabilities, general bonding, mitm not required, auto accept 2809 hci_stack->ssp_enable = 1; 2810 hci_stack->ssp_io_capability = SSP_IO_CAPABILITY_NO_INPUT_NO_OUTPUT; 2811 hci_stack->ssp_authentication_requirement = SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_GENERAL_BONDING; 2812 hci_stack->ssp_auto_accept = 1; 2813 --- 72 unchanged lines hidden (view full) --- 2886 2887#ifdef HAVE_MALLOC 2888 free(hci_stack); 2889#endif 2890 hci_stack = NULL; 2891} 2892 2893#ifdef ENABLE_CLASSIC |
2894void gap_set_required_encryption_key_size(uint8_t encryption_key_size){ 2895 // validate ranage and set 2896 if (encryption_key_size < 7) return; 2897 if (encryption_key_size > 16) return; 2898 hci_stack->gap_required_encyrption_key_size = encryption_key_size; 2899} 2900#endif 2901 2902#ifdef ENABLE_CLASSIC |
|
2888void gap_set_class_of_device(uint32_t class_of_device){ 2889 hci_stack->class_of_device = class_of_device; 2890} 2891 2892void gap_set_default_link_policy_settings(uint16_t default_link_policy_settings){ 2893 hci_stack->default_link_policy_settings = default_link_policy_settings; 2894} 2895 --- 1374 unchanged lines hidden (view full) --- 4270 pos += 2; 4271 event[pos++] = level; 4272 hci_emit_event(event, sizeof(event), 1); 4273} 4274 4275static gap_security_level_t gap_security_level_for_connection(hci_connection_t * connection){ 4276 if (!connection) return LEVEL_0; 4277 if ((connection->authentication_flags & CONNECTION_ENCRYPTED) == 0) return LEVEL_0; | 2903void gap_set_class_of_device(uint32_t class_of_device){ 2904 hci_stack->class_of_device = class_of_device; 2905} 2906 2907void gap_set_default_link_policy_settings(uint16_t default_link_policy_settings){ 2908 hci_stack->default_link_policy_settings = default_link_policy_settings; 2909} 2910 --- 1374 unchanged lines hidden (view full) --- 4285 pos += 2; 4286 event[pos++] = level; 4287 hci_emit_event(event, sizeof(event), 1); 4288} 4289 4290static gap_security_level_t gap_security_level_for_connection(hci_connection_t * connection){ 4291 if (!connection) return LEVEL_0; 4292 if ((connection->authentication_flags & CONNECTION_ENCRYPTED) == 0) return LEVEL_0; |
4278 return gap_security_level_for_link_key_type(connection->link_key_type); | 4293 if (connection->encryption_key_size < hci_stack->gap_required_encyrption_key_size) return LEVEL_0; 4294 gap_security_level_t level_for_key_type = gap_security_level_for_link_key_type(connection->link_key_type); 4295 // LEVEL 4 always requires 128 bit encrytion key size 4296 if (security_level == LEVEL_4 && connection->encryption_key_size < 16){ 4297 security_level = LEVEL_3; 4298 } 4299 return security_level; |
4279} 4280 4281static void hci_emit_discoverable_enabled(uint8_t enabled){ 4282 log_info("BTSTACK_EVENT_DISCOVERABLE_ENABLED %u", enabled); 4283 uint8_t event[3]; 4284 event[0] = BTSTACK_EVENT_DISCOVERABLE_ENABLED; 4285 event[1] = sizeof(event) - 2; 4286 event[2] = enabled; --- 921 unchanged lines hidden --- | 4300} 4301 4302static void hci_emit_discoverable_enabled(uint8_t enabled){ 4303 log_info("BTSTACK_EVENT_DISCOVERABLE_ENABLED %u", enabled); 4304 uint8_t event[3]; 4305 event[0] = BTSTACK_EVENT_DISCOVERABLE_ENABLED; 4306 event[1] = sizeof(event) - 2; 4307 event[2] = enabled; --- 921 unchanged lines hidden --- |