hci.c (6fe16221fb0d65e50bb84b40acd30817d1e02884) hci.c (7eb5b27e6239f1b89355ae777fb2cefd64f9af71)
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

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

4595 // Secure Connections: enable (requires support from Controller)
4596 hci_stack->secure_connections_enable = true;
4597
4598 // voice setting - signed 16 bit pcm data with CVSD over the air
4599 hci_stack->sco_voice_setting = 0x60;
4600
4601#ifdef ENABLE_LE_CENTRAL
4602 // connection parameter to use for outgoing connections
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

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

4595 // Secure Connections: enable (requires support from Controller)
4596 hci_stack->secure_connections_enable = true;
4597
4598 // voice setting - signed 16 bit pcm data with CVSD over the air
4599 hci_stack->sco_voice_setting = 0x60;
4600
4601#ifdef ENABLE_LE_CENTRAL
4602 // connection parameter to use for outgoing connections
4603 hci_stack->le_connection_scan_interval = 0x0060; // 60ms
4604 hci_stack->le_connection_scan_window = 0x0030; // 30ms
4605 hci_stack->le_connection_interval_min = 0x0008; // 10 ms
4606 hci_stack->le_connection_interval_max = 0x0018; // 30 ms
4607 hci_stack->le_connection_latency = 4; // 4
4608 hci_stack->le_supervision_timeout = 0x0048; // 720 ms
4609 hci_stack->le_minimum_ce_length = 2; // 1.25 ms
4610 hci_stack->le_maximum_ce_length = 0x0030; // 30 ms
4603 hci_stack->le_connection_scan_interval = 0x0060; // 60 ms
4604 hci_stack->le_connection_scan_window = 0x0030; // 30 ms
4605 hci_stack->le_connection_interval_min = 0x0008; // 10 ms
4606 hci_stack->le_connection_interval_max = 0x0018; // 30 ms
4607 hci_stack->le_connection_latency = 4; // 4
4608 hci_stack->le_supervision_timeout = 0x0048; // 720 ms
4609 hci_stack->le_minimum_ce_length = 2; // 1.25 ms
4610 hci_stack->le_maximum_ce_length = 0x0030; // 30 ms
4611 hci_stack->le_connection_phys = 0x01; // LE 1M PHY
4611
4612 // default LE Scanning
4612
4613 // default LE Scanning
4613 hci_stack->le_scan_type = 0x1; // active
4614 hci_stack->le_scan_type = 0x01; // active
4614 hci_stack->le_scan_interval = 0x1e0; // 300 ms
4615 hci_stack->le_scan_window = 0x30; // 30 ms
4615 hci_stack->le_scan_interval = 0x1e0; // 300 ms
4616 hci_stack->le_scan_window = 0x30; // 30 ms
4617 hci_stack->le_scan_phys = 0x01; // LE 1M PHY
4616#endif
4617
4618#ifdef ENABLE_LE_PERIPHERAL
4619 hci_stack->le_max_number_peripheral_connections = 1; // only single connection as peripheral
4620
4621 // default advertising parameters from Core v5.4 -- needed to use random address without prior adv setup
4622 hci_stack->le_advertisements_interval_min = 0x0800;
4623 hci_stack->le_advertisements_interval_max = 0x0800;

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

5609 return true;
5610 }
5611 return false;
5612}
5613#endif
5614
5615#ifdef ENABLE_BLE
5616
4618#endif
4619
4620#ifdef ENABLE_LE_PERIPHERAL
4621 hci_stack->le_max_number_peripheral_connections = 1; // only single connection as peripheral
4622
4623 // default advertising parameters from Core v5.4 -- needed to use random address without prior adv setup
4624 hci_stack->le_advertisements_interval_min = 0x0800;
4625 hci_stack->le_advertisements_interval_max = 0x0800;

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

5611 return true;
5612 }
5613 return false;
5614}
5615#endif
5616
5617#ifdef ENABLE_BLE
5618
5619#ifdef ENABLE_LE_EXTENDED_ADVERTISING
5620static uint8_t hci_le_num_phys(uint8_t phys){
5621 const uint8_t num_bits_set[] = { 0, 1, 1, 2, 1, 2, 2, 3 };
5622 btstack_assert(phys);
5623 return num_bits_set[phys];
5624}
5625#endif
5626
5617#ifdef ENABLE_LE_CENTRAL
5618static void hci_le_scan_stop(void){
5619#ifdef ENABLE_LE_EXTENDED_ADVERTISING
5620 if (hci_extended_advertising_supported()) {
5621 hci_send_cmd(&hci_le_set_extended_scan_enable, 0, 0, 0, 0);
5622 } else
5623#endif
5624 {
5625 hci_send_cmd(&hci_le_set_scan_enable, 0, 0);
5626 }
5627}
5628
5629static void
5630hci_send_le_create_connection(uint8_t initiator_filter_policy, bd_addr_type_t address_type, uint8_t *address) {
5631#ifdef ENABLE_LE_EXTENDED_ADVERTISING
5632 if (hci_extended_advertising_supported()) {
5627#ifdef ENABLE_LE_CENTRAL
5628static void hci_le_scan_stop(void){
5629#ifdef ENABLE_LE_EXTENDED_ADVERTISING
5630 if (hci_extended_advertising_supported()) {
5631 hci_send_cmd(&hci_le_set_extended_scan_enable, 0, 0, 0, 0);
5632 } else
5633#endif
5634 {
5635 hci_send_cmd(&hci_le_set_scan_enable, 0, 0);
5636 }
5637}
5638
5639static void
5640hci_send_le_create_connection(uint8_t initiator_filter_policy, bd_addr_type_t address_type, uint8_t *address) {
5641#ifdef ENABLE_LE_EXTENDED_ADVERTISING
5642 if (hci_extended_advertising_supported()) {
5633 uint16_t le_connection_scan_interval[1] = { hci_stack->le_connection_scan_interval };
5634 uint16_t le_connection_scan_window[1] = { hci_stack->le_connection_scan_window };
5635 uint16_t le_connection_interval_min[1] = { hci_stack->le_connection_interval_min };
5636 uint16_t le_connection_interval_max[1] = { hci_stack->le_connection_interval_max };
5637 uint16_t le_connection_latency[1] = { hci_stack->le_connection_latency };
5638 uint16_t le_supervision_timeout[1] = { hci_stack->le_supervision_timeout };
5639 uint16_t le_minimum_ce_length[1] = { hci_stack->le_minimum_ce_length };
5640 uint16_t le_maximum_ce_length[1] = { hci_stack->le_maximum_ce_length };
5643 // prepare arrays for all phys (LE Coded, LE 1M, LE 2M PHY)
5644 uint16_t le_connection_scan_interval[3];
5645 uint16_t le_connection_scan_window[3];
5646 uint16_t le_connection_interval_min[3];
5647 uint16_t le_connection_interval_max[3];
5648 uint16_t le_connection_latency[3];
5649 uint16_t le_supervision_timeout[3];
5650 uint16_t le_minimum_ce_length[3];
5651 uint16_t le_maximum_ce_length[3];
5652
5653 uint8_t i;
5654 uint8_t num_phys = hci_le_num_phys(hci_stack->le_connection_phys);
5655 for (i=0;i<num_phys;i++){
5656 le_connection_scan_interval[i] = hci_stack->le_connection_scan_interval;
5657 le_connection_scan_window[i] = hci_stack->le_connection_scan_window;
5658 le_connection_interval_min[i] = hci_stack->le_connection_interval_min;
5659 le_connection_interval_max[i] = hci_stack->le_connection_interval_max;
5660 le_connection_latency[i] = hci_stack->le_connection_latency;
5661 le_supervision_timeout[i] = hci_stack->le_supervision_timeout;
5662 le_minimum_ce_length[i] = hci_stack->le_minimum_ce_length;
5663 le_maximum_ce_length[i] = hci_stack->le_maximum_ce_length;
5664 }
5641 hci_send_cmd(&hci_le_extended_create_connection,
5642 initiator_filter_policy,
5643 hci_stack->le_connection_own_addr_type, // our addr type:
5644 address_type, // peer address type
5645 address, // peer bd addr
5665 hci_send_cmd(&hci_le_extended_create_connection,
5666 initiator_filter_policy,
5667 hci_stack->le_connection_own_addr_type, // our addr type:
5668 address_type, // peer address type
5669 address, // peer bd addr
5646 1, // initiating PHY - 1M
5670 hci_stack->le_connection_phys, // initiating PHY
5647 le_connection_scan_interval, // conn scan interval
5648 le_connection_scan_window, // conn scan windows
5649 le_connection_interval_min, // conn interval min
5650 le_connection_interval_max, // conn interval max
5651 le_connection_latency, // conn latency
5652 le_supervision_timeout, // conn latency
5653 le_minimum_ce_length, // min ce length
5654 le_maximum_ce_length // max ce length

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

5990 return true;
5991 }
5992
5993#ifdef ENABLE_LE_CENTRAL
5994 if (hci_stack->le_scanning_param_update){
5995 hci_stack->le_scanning_param_update = false;
5996#ifdef ENABLE_LE_EXTENDED_ADVERTISING
5997 if (hci_extended_advertising_supported()){
5671 le_connection_scan_interval, // conn scan interval
5672 le_connection_scan_window, // conn scan windows
5673 le_connection_interval_min, // conn interval min
5674 le_connection_interval_max, // conn interval max
5675 le_connection_latency, // conn latency
5676 le_supervision_timeout, // conn latency
5677 le_minimum_ce_length, // min ce length
5678 le_maximum_ce_length // max ce length

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

6014 return true;
6015 }
6016
6017#ifdef ENABLE_LE_CENTRAL
6018 if (hci_stack->le_scanning_param_update){
6019 hci_stack->le_scanning_param_update = false;
6020#ifdef ENABLE_LE_EXTENDED_ADVERTISING
6021 if (hci_extended_advertising_supported()){
5998 // prepare arrays for all PHYs
5999 uint8_t scan_types[1] = { hci_stack->le_scan_type };
6000 uint16_t scan_intervals[1] = { hci_stack->le_scan_interval };
6001 uint16_t scan_windows[1] = { hci_stack->le_scan_window };
6002 uint8_t scanning_phys = 1; // LE 1M PHY
6022 // prepare arrays for all phys (LE Coded and LE 1M PHY)
6023 uint8_t scan_types[2];
6024 uint16_t scan_intervals[2];
6025 uint16_t scan_windows[2];
6026
6027 uint8_t i;
6028 uint8_t num_phys = hci_le_num_phys(hci_stack->le_scan_phys);
6029 for (i=0;i<num_phys;i++){
6030 scan_types[i] = hci_stack->le_scan_type;
6031 scan_intervals[i] = hci_stack->le_scan_interval;
6032 scan_windows[i] = hci_stack->le_scan_window;
6033 }
6003 hci_send_cmd(&hci_le_set_extended_scan_parameters, hci_stack->le_own_addr_type,
6034 hci_send_cmd(&hci_le_set_extended_scan_parameters, hci_stack->le_own_addr_type,
6004 hci_stack->le_scan_filter_policy, scanning_phys, scan_types, scan_intervals, scan_windows);
6035 hci_stack->le_scan_filter_policy, hci_stack->le_scan_phys, scan_types, scan_intervals, scan_windows);
6005 } else
6006#endif
6007 {
6008 hci_send_cmd(&hci_le_set_scan_parameters, hci_stack->le_scan_type, hci_stack->le_scan_interval, hci_stack->le_scan_window,
6009 hci_stack->le_own_addr_type, hci_stack->le_scan_filter_policy);
6010 }
6011 return true;
6012 }

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

7930void gap_set_scan_parameters(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window){
7931 gap_set_scan_params(scan_type, scan_interval, scan_window, 0);
7932}
7933
7934void gap_set_scan_duplicate_filter(bool enabled){
7935 hci_stack->le_scan_filter_duplicates = enabled ? 1 : 0;
7936}
7937
6036 } else
6037#endif
6038 {
6039 hci_send_cmd(&hci_le_set_scan_parameters, hci_stack->le_scan_type, hci_stack->le_scan_interval, hci_stack->le_scan_window,
6040 hci_stack->le_own_addr_type, hci_stack->le_scan_filter_policy);
6041 }
6042 return true;
6043 }

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

7961void gap_set_scan_parameters(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window){
7962 gap_set_scan_params(scan_type, scan_interval, scan_window, 0);
7963}
7964
7965void gap_set_scan_duplicate_filter(bool enabled){
7966 hci_stack->le_scan_filter_duplicates = enabled ? 1 : 0;
7967}
7968
7969void gap_set_scan_phys(uint8_t phys){
7970 // LE Coded and LE 1M PHY
7971 hci_stack->le_scan_phys = phys & 0x05;
7972}
7973
7938uint8_t gap_connect(const bd_addr_t addr, bd_addr_type_t addr_type){
7939 hci_connection_t * conn = hci_connection_for_bd_addr_and_type(addr, addr_type);
7940 if (!conn){
7941 // disallow if le connection is already outgoing
7942 if (hci_is_le_connection_type(addr_type) && hci_stack->le_connecting_request != LE_CONNECTING_IDLE){
7943 log_error("le connection already active");
7944 return ERROR_CODE_COMMAND_DISALLOWED;
7945 }

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

8060 hci_stack->le_connection_scan_window = conn_scan_window;
8061 hci_stack->le_connection_interval_min = conn_interval_min;
8062 hci_stack->le_connection_interval_max = conn_interval_max;
8063 hci_stack->le_connection_latency = conn_latency;
8064 hci_stack->le_supervision_timeout = supervision_timeout;
8065 hci_stack->le_minimum_ce_length = min_ce_length;
8066 hci_stack->le_maximum_ce_length = max_ce_length;
8067}
7974uint8_t gap_connect(const bd_addr_t addr, bd_addr_type_t addr_type){
7975 hci_connection_t * conn = hci_connection_for_bd_addr_and_type(addr, addr_type);
7976 if (!conn){
7977 // disallow if le connection is already outgoing
7978 if (hci_is_le_connection_type(addr_type) && hci_stack->le_connecting_request != LE_CONNECTING_IDLE){
7979 log_error("le connection already active");
7980 return ERROR_CODE_COMMAND_DISALLOWED;
7981 }

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

8096 hci_stack->le_connection_scan_window = conn_scan_window;
8097 hci_stack->le_connection_interval_min = conn_interval_min;
8098 hci_stack->le_connection_interval_max = conn_interval_max;
8099 hci_stack->le_connection_latency = conn_latency;
8100 hci_stack->le_supervision_timeout = supervision_timeout;
8101 hci_stack->le_minimum_ce_length = min_ce_length;
8102 hci_stack->le_maximum_ce_length = max_ce_length;
8103}
8104
8105void gap_set_connection_phys(uint8_t phys){
8106 // LE Coded, LE 1M, LE 2M PHY
8107 hci_stack->le_connection_phys = phys & 7;
8108}
8109
8068#endif
8069
8070/**
8071 * @brief Updates the connection parameters for a given LE connection
8072 * @param handle
8073 * @param conn_interval_min (unit: 1.25ms)
8074 * @param conn_interval_max (unit: 1.25ms)
8075 * @param conn_latency

--- 2026 unchanged lines hidden ---
8110#endif
8111
8112/**
8113 * @brief Updates the connection parameters for a given LE connection
8114 * @param handle
8115 * @param conn_interval_min (unit: 1.25ms)
8116 * @param conn_interval_max (unit: 1.25ms)
8117 * @param conn_latency

--- 2026 unchanged lines hidden ---