Lines Matching refs:hci_stack
274 static hci_stack_t * hci_stack = NULL; variable
339 btstack_linked_list_add(&hci_stack->connections, (btstack_linked_item_t *) conn); in create_connection_for_bd_addr_and_type()
351 *range = hci_stack->le_connection_parameter_range; in gap_get_connection_parameter_range()
360 hci_stack->le_connection_parameter_range = *range; in gap_set_connection_parameter_range()
391 hci_stack->le_max_number_peripheral_connections = max_peripheral_connections; in gap_set_max_number_peripheral_connections()
402 btstack_linked_list_iterator_init(it, &hci_stack->connections); in hci_connections_get_iterator()
412 btstack_linked_list_iterator_init(&it, &hci_stack->connections); in hci_connection_for_handle()
429 btstack_linked_list_iterator_init(&it, &hci_stack->connections); in hci_connection_for_bd_addr_and_type()
453 btstack_linked_list_iterator_init(&it, &hci_stack->connections); in hci_number_sco_connections()
517 …ack_max((uint32_t) hci_connection->requested_security_level, (uint32_t) hci_stack->gap_minimal_ser… in hci_pairing_started()
567 if (!hci_stack->link_key_db) return; in gap_drop_link_key_for_bd_addr()
569 hci_stack->link_key_db->delete_link_key(addr); in gap_drop_link_key_for_bd_addr()
573 if (!hci_stack->link_key_db) return; in gap_store_link_key_for_bd_addr()
575 hci_stack->link_key_db->put_link_key(addr, link_key, type); in gap_store_link_key_for_bd_addr()
579 if (!hci_stack->link_key_db) return false; in gap_get_link_key_for_bd_addr()
580 int result = hci_stack->link_key_db->get_link_key(addr, link_key, type) != 0; in gap_get_link_key_for_bd_addr()
602 if (!hci_stack->link_key_db) return 0; in gap_link_key_iterator_init()
603 if (!hci_stack->link_key_db->iterator_init) return 0; in gap_link_key_iterator_init()
604 return hci_stack->link_key_db->iterator_init(it); in gap_link_key_iterator_init()
607 if (!hci_stack->link_key_db) return 0; in gap_link_key_iterator_get_next()
608 return hci_stack->link_key_db->iterator_get_next(it, bd_addr, link_key, type); in gap_link_key_iterator_get_next()
611 if (!hci_stack->link_key_db) return; in gap_link_key_iterator_done()
612 hci_stack->link_key_db->iterator_done(it); in gap_link_key_iterator_done()
648 for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL ; it = it->next){ in nr_hci_connections()
660 for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL; it = it->next){ in hci_number_free_acl_slots_for_connection_type()
669 btstack_assert(hci_stack->acl_packets_total_num >= num_packets_sent_classic); in hci_number_free_acl_slots_for_connection_type()
670 int free_slots_classic = hci_stack->acl_packets_total_num - num_packets_sent_classic; in hci_number_free_acl_slots_for_connection_type()
673 if (hci_stack->le_acl_packets_total_num){ in hci_number_free_acl_slots_for_connection_type()
675 btstack_assert( hci_stack->le_acl_packets_total_num >= num_packets_sent_le); in hci_number_free_acl_slots_for_connection_type()
676 free_slots_le = hci_stack->le_acl_packets_total_num - num_packets_sent_le; in hci_number_free_acl_slots_for_connection_type()
692 if (hci_stack->le_acl_packets_total_num > 0){ in hci_number_free_acl_slots_for_connection_type()
713 if (hci_stack->synchronous_flow_control_enabled){ in hci_number_free_sco_slots()
715 for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){ in hci_number_free_sco_slots()
720 if (num_sco_packets_sent > hci_stack->sco_packets_total_num){ in hci_number_free_sco_slots()
721 …ree_sco_slots:packets (%u) > total packets (%u)", num_sco_packets_sent, hci_stack->sco_packets_tot… in hci_number_free_sco_slots()
724 return hci_stack->sco_packets_total_num - num_sco_packets_sent; in hci_number_free_sco_slots()
728 for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){ in hci_number_free_sco_slots()
741 if (hci_stack->hci_packet_buffer_reserved) return 0; in hci_can_send_command_packet_transport()
744 if (hci_stack->hci_transport->can_send_packet_now){ in hci_can_send_command_packet_transport()
745 if (!hci_stack->hci_transport->can_send_packet_now(HCI_COMMAND_DATA_PACKET)){ in hci_can_send_command_packet_transport()
755 return hci_stack->num_cmd_packets > 0u; in hci_can_send_command_packet_now()
760 if (!hci_stack->hci_transport->can_send_packet_now) return true; in hci_transport_can_send_prepared_packet_now()
761 return hci_stack->hci_transport->can_send_packet_now(packet_type); in hci_transport_can_send_prepared_packet_now()
770 if (hci_stack->hci_packet_buffer_reserved) return false; in hci_can_send_acl_le_packet_now()
780 if (hci_stack->hci_packet_buffer_reserved) return false; in hci_can_send_acl_packet_now()
786 if (hci_stack->hci_packet_buffer_reserved) return false; in hci_can_send_acl_classic_packet_now()
793 return hci_stack->sco_can_send_now; in hci_can_send_prepared_sco_packet_now()
800 if (hci_stack->hci_packet_buffer_reserved) return false; in hci_can_send_sco_packet_now()
805 hci_stack->sco_waiting_for_can_send_now = 1; in hci_request_sco_can_send_now_event()
812 return hci_stack->hci_packet_buffer_reserved; in hci_is_packet_buffer_reserved()
816 btstack_assert(hci_stack->hci_packet_buffer_reserved == false); in hci_reserve_packet_buffer()
817 hci_stack->hci_packet_buffer_reserved = true; in hci_reserve_packet_buffer()
821 btstack_assert(hci_stack->hci_packet_buffer_reserved); in hci_release_packet_buffer()
822 hci_stack->hci_packet_buffer_reserved = false; in hci_release_packet_buffer()
828 return hci_stack->hci_transport->can_send_packet_now == NULL; in hci_transport_synchronous()
843 for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL; it = it->next){ in hci_controller_dump_packets()
876 uint16_t max_acl_data_packet_length = hci_stack->acl_data_packet_length; in hci_send_acl_packet_fragments()
877 if (hci_is_le_connection(connection) && (hci_stack->le_data_packets_length > 0u)){ in hci_send_acl_packet_fragments()
878 max_acl_data_packet_length = hci_stack->le_data_packets_length; in hci_send_acl_packet_fragments()
896 const uint16_t acl_header_pos = hci_stack->acl_fragmentation_pos - 4u; in hci_send_acl_packet_fragments()
897 …int current_acl_data_packet_length = hci_stack->acl_fragmentation_total_size - hci_stack->acl_frag… in hci_send_acl_packet_fragments()
908 uint16_t handle_and_flags = little_endian_read_16(hci_stack->hci_packet_buffer, 0); in hci_send_acl_packet_fragments()
910 little_endian_store_16(hci_stack->hci_packet_buffer, acl_header_pos, handle_and_flags); in hci_send_acl_packet_fragments()
914 …little_endian_store_16(hci_stack->hci_packet_buffer, acl_header_pos + 2u, current_acl_data_packet_… in hci_send_acl_packet_fragments()
923 hci_stack->acl_fragmentation_pos += current_acl_data_packet_length; in hci_send_acl_packet_fragments()
926 hci_stack->acl_fragmentation_pos = 0; in hci_send_acl_packet_fragments()
927 hci_stack->acl_fragmentation_total_size = 0; in hci_send_acl_packet_fragments()
931 uint8_t * packet = &hci_stack->hci_packet_buffer[acl_header_pos]; in hci_send_acl_packet_fragments()
934 hci_stack->acl_fragmentation_tx_active = 1; in hci_send_acl_packet_fragments()
935 int err = hci_stack->hci_transport->send_packet(HCI_ACL_DATA_PACKET, packet, size); in hci_send_acl_packet_fragments()
959 hci_stack->acl_fragmentation_tx_active = 0; in hci_send_acl_packet_fragments()
968 btstack_assert(hci_stack->hci_packet_buffer_reserved); in hci_send_acl_packet_buffer()
970 uint8_t * packet = hci_stack->hci_packet_buffer; in hci_send_acl_packet_buffer()
994 hci_stack->acl_fragmentation_total_size = size; in hci_send_acl_packet_buffer()
995 hci_stack->acl_fragmentation_pos = 4; // start of L2CAP packet in hci_send_acl_packet_buffer()
1003 btstack_assert(hci_stack->hci_packet_buffer_reserved); in hci_send_sco_packet_buffer()
1005 uint8_t * packet = hci_stack->hci_packet_buffer; in hci_send_sco_packet_buffer()
1008 if (!hci_stack->loopback_mode){ in hci_send_sco_packet_buffer()
1028 hci_stack->sco_can_send_now = false; in hci_send_sco_packet_buffer()
1030 if (hci_stack->synchronous_flow_control_enabled){ in hci_send_sco_packet_buffer()
1041 hci_stack->sco_transport->send_packet(packet, size); in hci_send_sco_packet_buffer()
1047 int err = hci_stack->hci_transport->send_packet(HCI_SCO_DATA_PACKET, packet, size); in hci_send_sco_packet_buffer()
1065 uint16_t max_iso_data_packet_length = hci_stack->le_iso_packets_length; in hci_send_iso_packet_fragments()
1071 const uint16_t iso_header_pos = hci_stack->iso_fragmentation_pos - 4u; in hci_send_iso_packet_fragments()
1072 …int current_iso_data_packet_length = hci_stack->iso_fragmentation_total_size - hci_stack->iso_frag… in hci_send_iso_packet_fragments()
1082 uint16_t handle_and_flags = little_endian_read_16(hci_stack->hci_packet_buffer, 0); in hci_send_iso_packet_fragments()
1093 little_endian_store_16(hci_stack->hci_packet_buffer, iso_header_pos, handle_and_flags); in hci_send_iso_packet_fragments()
1096 …little_endian_store_16(hci_stack->hci_packet_buffer, iso_header_pos + 2u, current_iso_data_packet_… in hci_send_iso_packet_fragments()
1101 hci_stack->iso_fragmentation_pos += current_iso_data_packet_length; in hci_send_iso_packet_fragments()
1104 hci_stack->iso_fragmentation_pos = 0; in hci_send_iso_packet_fragments()
1105 hci_stack->iso_fragmentation_total_size = 0; in hci_send_iso_packet_fragments()
1109 uint8_t * packet = &hci_stack->hci_packet_buffer[iso_header_pos]; in hci_send_iso_packet_fragments()
1112 hci_stack->iso_fragmentation_tx_active = true; in hci_send_iso_packet_fragments()
1113 int err = hci_stack->hci_transport->send_packet(HCI_ISO_DATA_PACKET, packet, size); in hci_send_iso_packet_fragments()
1128 hci_stack->iso_fragmentation_tx_active = false; in hci_send_iso_packet_fragments()
1137 btstack_assert(hci_stack->hci_packet_buffer_reserved); in hci_send_iso_packet_buffer()
1139 …hci_con_handle_t con_handle = (hci_con_handle_t) little_endian_read_16(hci_stack->hci_packet_buffe… in hci_send_iso_packet_buffer()
1163 hci_stack->iso_fragmentation_total_size = size; in hci_send_iso_packet_buffer()
1164 hci_stack->iso_fragmentation_pos = 4; // start of L2CAP packet in hci_send_iso_packet_buffer()
1196 hci_stack->host_completed_packets = 1; in acl_handler()
1297 btstack_linked_list_remove(&hci_stack->connections, (btstack_linked_item_t *) conn); in hci_shutdown_connection()
1306 …if ((addr_type == BD_ADDR_TYPE_SCO) && (hci_stack->hci_transport != NULL) && (hci_stack->hci_trans… in hci_shutdown_connection()
1307 …hci_stack->hci_transport->set_sco_config(hci_stack->sco_voice_setting_active, hci_number_sco_conne… in hci_shutdown_connection()
1311 if ((addr_type == BD_ADDR_TYPE_SCO) && (hci_stack->sco_transport != NULL)){ in hci_shutdown_connection()
1312 hci_stack->sco_transport->close(con_handle); in hci_shutdown_connection()
1365 …uint16_t active_packet_types = (hci_stack->usable_packet_types_acl & hci_stack->enabled_packet_ty… in hci_usable_acl_packet_types()
1371 hci_stack->enabled_packet_types_acl = packet_types; in hci_enable_acl_packet_types()
1419 return hci_stack->usable_packet_types_sco; in hci_usable_sco_packet_types()
1436 return hci_stack->hci_packet_buffer; in hci_get_outgoing_packet_buffer()
1440 return hci_stack->acl_data_packet_length; in hci_max_acl_data_packet_length()
1446 return (hci_stack->local_supported_features[3] & (1 << 7)) != 0; in hci_extended_sco_link_supported()
1452 return (hci_stack->local_supported_features[6u] & (1u << 6u)) != 0u; in hci_non_flushable_packet_boundary_flag_supported()
1458 return (hci_stack->local_supported_features[6u] & (1u << 3u)) != 0u; in gap_ssp_supported()
1465 return (hci_stack->local_supported_features[4] & (1 << 5)) == 0; in hci_classic_supported()
1474 return (hci_stack->local_supported_features[4u] & (1u << 6u)) != 0u; in hci_le_supported()
1481 return (hci_stack->local_supported_commands & (1LU << command_index)) != 0; in hci_command_supported()
1494 (void)memcpy(own_addr, hci_stack->local_bd_addr, 6); in hci_get_own_address_for_addr_type()
1496 (void)memcpy(own_addr, hci_stack->le_random_address, 6); in hci_get_own_address_for_addr_type()
1501 *addr_type = hci_stack->le_own_addr_type; in gap_le_get_own_address()
1502 hci_get_own_address_for_addr_type(hci_stack->le_own_addr_type, addr); in gap_le_get_own_address()
1507 *addr_type = hci_stack->le_advertisements_own_addr_type; in gap_le_get_own_advertisements_address()
1508 hci_get_own_address_for_addr_type(hci_stack->le_advertisements_own_addr_type, addr); in gap_le_get_own_advertisements_address()
1520 memcpy(addr, hci_stack->local_bd_addr, 6); in gap_le_get_own_advertising_set_address()
1545 *addr_type = hci_stack->le_connection_own_addr_type; in gap_le_get_own_connection_address()
1546 hci_get_own_address_for_addr_type(hci_stack->le_connection_own_addr_type, addr); in gap_le_get_own_connection_address()
1660 if ((hci_stack->le_advertisements_state & LE_ADVERTISEMENT_STATE_ENABLED) != 0){ in hci_update_advertisements_enabled_for_current_roles()
1664 btstack_linked_list_iterator_init(&it, &hci_stack->connections); in hci_update_advertisements_enabled_for_current_roles()
1673 …log_info("Num LE Peripheral roles: %u of %u", num_slave_connections, hci_stack->le_max_number_peri… in hci_update_advertisements_enabled_for_current_roles()
1674 …hci_stack->le_advertisements_enabled_for_current_roles = num_slave_connections < hci_stack->le_max… in hci_update_advertisements_enabled_for_current_roles()
1676 hci_stack->le_advertisements_enabled_for_current_roles = false; in hci_update_advertisements_enabled_for_current_roles()
1685 uint8_t * packet = hci_stack->hci_packet_buffer; in gap_run_set_local_name()
1692 uint16_t name_len = (uint16_t) strlen(hci_stack->local_name); in gap_run_set_local_name()
1695 (void)memcpy(&packet[3], hci_stack->local_name, bytes_to_copy); in gap_run_set_local_name()
1697 btstack_replace_bd_addr_placeholder(&packet[3], bytes_to_copy, hci_stack->local_bd_addr); in gap_run_set_local_name()
1703 uint8_t * packet = hci_stack->hci_packet_buffer; in gap_run_set_eir_data()
1712 if (hci_stack->eir_data){ in gap_run_set_eir_data()
1715 …for (ad_iterator_init(&context, EXTENDED_INQUIRY_RESPONSE_DATA_LEN, hci_stack->eir_data) ; ad_iter… in gap_run_set_eir_data()
1725 … btstack_replace_bd_addr_placeholder(&packet[offset], size, hci_stack->local_bd_addr); in gap_run_set_eir_data()
1730 uint16_t name_len = (uint16_t) strlen(hci_stack->local_name); in gap_run_set_eir_data()
1734 (void)memcpy(&packet[6], hci_stack->local_name, bytes_to_copy); in gap_run_set_eir_data()
1736 … btstack_replace_bd_addr_placeholder(&packet[offset], bytes_to_copy, hci_stack->local_bd_addr); in gap_run_set_eir_data()
1742 if ((hci_stack->gap_tasks_classic & GAP_TASK_SET_CLASS_OF_DEVICE) != 0) { in hci_run_gap_tasks_classic()
1743 hci_stack->gap_tasks_classic &= ~GAP_TASK_SET_CLASS_OF_DEVICE; in hci_run_gap_tasks_classic()
1744 hci_send_cmd(&hci_write_class_of_device, hci_stack->class_of_device); in hci_run_gap_tasks_classic()
1747 if ((hci_stack->gap_tasks_classic & GAP_TASK_SET_LOCAL_NAME) != 0) { in hci_run_gap_tasks_classic()
1748 hci_stack->gap_tasks_classic &= ~GAP_TASK_SET_LOCAL_NAME; in hci_run_gap_tasks_classic()
1752 if ((hci_stack->gap_tasks_classic & GAP_TASK_SET_EIR_DATA) != 0) { in hci_run_gap_tasks_classic()
1753 hci_stack->gap_tasks_classic &= ~GAP_TASK_SET_EIR_DATA; in hci_run_gap_tasks_classic()
1757 if ((hci_stack->gap_tasks_classic & GAP_TASK_SET_DEFAULT_LINK_POLICY) != 0) { in hci_run_gap_tasks_classic()
1758 hci_stack->gap_tasks_classic &= ~GAP_TASK_SET_DEFAULT_LINK_POLICY; in hci_run_gap_tasks_classic()
1759 … hci_send_cmd(&hci_write_default_link_policy_setting, hci_stack->default_link_policy_settings); in hci_run_gap_tasks_classic()
1763 if ((hci_stack->gap_tasks_classic & GAP_TASK_WRITE_PAGE_SCAN_ACTIVITY) != 0) { in hci_run_gap_tasks_classic()
1764 hci_stack->gap_tasks_classic &= ~GAP_TASK_WRITE_PAGE_SCAN_ACTIVITY; in hci_run_gap_tasks_classic()
1765 …hci_send_cmd(&hci_write_page_scan_activity, hci_stack->new_page_scan_interval, hci_stack->new_page… in hci_run_gap_tasks_classic()
1769 if ((hci_stack->gap_tasks_classic & GAP_TASK_WRITE_PAGE_SCAN_TYPE) != 0) { in hci_run_gap_tasks_classic()
1770 hci_stack->gap_tasks_classic &= ~GAP_TASK_WRITE_PAGE_SCAN_TYPE; in hci_run_gap_tasks_classic()
1771 hci_send_cmd(&hci_write_page_scan_type, hci_stack->new_page_scan_type); in hci_run_gap_tasks_classic()
1775 if ((hci_stack->gap_tasks_classic & GAP_TASK_WRITE_PAGE_TIMEOUT) != 0) { in hci_run_gap_tasks_classic()
1776 hci_stack->gap_tasks_classic &= ~GAP_TASK_WRITE_PAGE_TIMEOUT; in hci_run_gap_tasks_classic()
1777 hci_send_cmd(&hci_write_page_timeout, hci_stack->page_timeout); in hci_run_gap_tasks_classic()
1781 if ((hci_stack->gap_tasks_classic & GAP_TASK_WRITE_SCAN_ENABLE) != 0) { in hci_run_gap_tasks_classic()
1782 hci_stack->gap_tasks_classic &= ~GAP_TASK_WRITE_SCAN_ENABLE; in hci_run_gap_tasks_classic()
1783 hci_send_cmd(&hci_write_scan_enable, hci_stack->new_scan_enable_value); in hci_run_gap_tasks_classic()
1787 if ((hci_stack->gap_tasks_classic & GAP_TASK_WRITE_INQUIRY_SCAN_ACTIVITY) != 0) { in hci_run_gap_tasks_classic()
1788 hci_stack->gap_tasks_classic &= ~GAP_TASK_WRITE_INQUIRY_SCAN_ACTIVITY; in hci_run_gap_tasks_classic()
1789 …hci_send_cmd(&hci_write_inquiry_scan_activity, hci_stack->inquiry_scan_interval, hci_stack->inquir… in hci_run_gap_tasks_classic()
1793 if ((hci_stack->gap_tasks_classic & GAP_TASK_WRITE_INQUIRY_TX_POWER_LEVEL) != 0) { in hci_run_gap_tasks_classic()
1794 hci_stack->gap_tasks_classic &= ~GAP_TASK_WRITE_INQUIRY_TX_POWER_LEVEL; in hci_run_gap_tasks_classic()
1795 hci_send_cmd(&hci_write_inquiry_transmit_power_level, hci_stack->inquiry_tx_power_level); in hci_run_gap_tasks_classic()
1804 if (!hci_stack->config) return 0; in hci_transport_uart_get_main_baud_rate()
1805 uint32_t baud_rate = ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main; in hci_transport_uart_get_main_baud_rate()
1812 switch (hci_stack->substate){ in hci_initialization_timeout_handler()
1815 hci_stack->substate = HCI_INIT_SEND_RESET; in hci_initialization_timeout_handler()
1816 hci_stack->num_cmd_packets = 1; in hci_initialization_timeout_handler()
1821 if (hci_stack->hci_transport->reset_link){ in hci_initialization_timeout_handler()
1822 hci_stack->hci_transport->reset_link(); in hci_initialization_timeout_handler()
1829 hci_stack->substate = HCI_INIT_SEND_RESET_CSR_WARM_BOOT; in hci_initialization_timeout_handler()
1830 hci_stack->num_cmd_packets = 1; in hci_initialization_timeout_handler()
1834 if (hci_stack->hci_transport->set_baudrate){ in hci_initialization_timeout_handler()
1837 hci_stack->hci_transport->set_baudrate(baud_rate); in hci_initialization_timeout_handler()
1840 if (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_CAMBRIDGE_SILICON_RADIO){ in hci_initialization_timeout_handler()
1841 if (hci_stack->hci_transport->reset_link){ in hci_initialization_timeout_handler()
1843 hci_stack->hci_transport->reset_link(); in hci_initialization_timeout_handler()
1845 hci_stack->substate = HCI_INIT_SEND_RESET_CSR_WARM_BOOT; in hci_initialization_timeout_handler()
1851 hci_stack->substate = HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS; in hci_initialization_timeout_handler()
1861 hci_stack->substate = (hci_substate_t )( ((int) hci_stack->substate) + 1); in hci_initializing_next_state()
1867 hci_stack->state = HCI_STATE_WORKING; in hci_init_done()
1873 …log_debug("hci_initializing_run: substate %u, can send %u", hci_stack->substate, hci_can_send_comm… in hci_initializing_run()
1878 bool need_baud_change = hci_stack->config in hci_initializing_run()
1879 && hci_stack->chipset in hci_initializing_run()
1880 && hci_stack->chipset->set_baudrate_command in hci_initializing_run()
1881 && hci_stack->hci_transport->set_baudrate in hci_initializing_run()
1882 && ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main; in hci_initializing_run()
1885 switch (hci_stack->substate){ in hci_initializing_run()
1891 btstack_run_loop_set_timer(&hci_stack->timeout, HCI_RESET_RESEND_TIMEOUT_MS); in hci_initializing_run()
1892 … btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_initialization_timeout_handler); in hci_initializing_run()
1893 btstack_run_loop_add_timer(&hci_stack->timeout); in hci_initializing_run()
1896 hci_stack->substate = HCI_INIT_W4_SEND_RESET; in hci_initializing_run()
1901 hci_stack->substate = HCI_INIT_W4_SEND_READ_LOCAL_VERSION_INFORMATION; in hci_initializing_run()
1908 btstack_run_loop_set_timer(&hci_stack->timeout, HCI_RESET_RESEND_TIMEOUT_MS); in hci_initializing_run()
1909 … btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_initialization_timeout_handler); in hci_initializing_run()
1910 btstack_run_loop_add_timer(&hci_stack->timeout); in hci_initializing_run()
1912 hci_stack->substate = HCI_INIT_W4_CUSTOM_INIT_CSR_WARM_BOOT; in hci_initializing_run()
1917 hci_stack->substate = HCI_INIT_W4_SEND_RESET_ST_WARM_BOOT; in hci_initializing_run()
1923 hci_stack->chipset->set_baudrate_command(baud_rate, hci_stack->hci_packet_buffer); in hci_initializing_run()
1924 hci_stack->substate = HCI_INIT_W4_SEND_BAUD_CHANGE_BCM; in hci_initializing_run()
1930 log_info("Set Public BD ADDR to %s", bd_addr_to_str(hci_stack->custom_bd_addr)); in hci_initializing_run()
1931 … hci_stack->chipset->set_bd_addr_command(hci_stack->custom_bd_addr, hci_stack->hci_packet_buffer); in hci_initializing_run()
1932 hci_stack->substate = HCI_INIT_W4_SET_BD_ADDR; in hci_initializing_run()
1938 hci_stack->substate = HCI_INIT_W4_SEND_READ_LOCAL_NAME; in hci_initializing_run()
1947 hci_stack->chipset->set_baudrate_command(baud_rate, hci_stack->hci_packet_buffer); in hci_initializing_run()
1948 hci_stack->substate = HCI_INIT_W4_SEND_BAUD_CHANGE; in hci_initializing_run()
1952 if (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_ST_MICROELECTRONICS){ in hci_initializing_run()
1953 btstack_run_loop_set_timer(&hci_stack->timeout, HCI_RESET_RESEND_TIMEOUT_MS); in hci_initializing_run()
1954 btstack_run_loop_add_timer(&hci_stack->timeout); in hci_initializing_run()
1958 hci_stack->substate = HCI_INIT_CUSTOM_INIT; in hci_initializing_run()
1965 if (hci_stack->chipset && hci_stack->chipset->next_command){ in hci_initializing_run()
1967 … hci_stack->chipset_result = (*hci_stack->chipset->next_command)(hci_stack->hci_packet_buffer); in hci_initializing_run()
1969 switch (hci_stack->chipset_result){ in hci_initializing_run()
1972 switch (hci_stack->substate){ in hci_initializing_run()
1974 hci_stack->substate = HCI_INIT_W4_CUSTOM_INIT; in hci_initializing_run()
1977 hci_stack->substate = HCI_INIT_W4_CUSTOM_PRE_INIT; in hci_initializing_run()
1988 … btstack_run_loop_set_timer(&hci_stack->timeout, HCI_RESET_RESEND_TIMEOUT_MS); in hci_initializing_run()
1989 … btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_initialization_timeout_handler); in hci_initializing_run()
1990 btstack_run_loop_add_timer(&hci_stack->timeout); in hci_initializing_run()
1991 … if ((hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_CAMBRIDGE_SILICON_RADIO) in hci_initializing_run()
1992 && hci_stack->config in hci_initializing_run()
1993 && hci_stack->chipset in hci_initializing_run()
1995 && hci_stack->hci_transport->set_baudrate in hci_initializing_run()
1997 hci_stack->substate = HCI_INIT_W4_SEND_BAUD_CHANGE; in hci_initializing_run()
1999 hci_stack->substate = HCI_INIT_W4_CUSTOM_INIT_CSR_WARM_BOOT_LINK_RESET; in hci_initializing_run()
2015 if (hci_stack->substate == HCI_INIT_CUSTOM_PRE_INIT){ in hci_initializing_run()
2016 hci_stack->substate = HCI_INIT_W4_SEND_RESET; in hci_initializing_run()
2022 if ( (hci_stack->chipset_result != BTSTACK_CHIPSET_NO_INIT_SCRIPT) && in hci_initializing_run()
2023 ( (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_BROADCOM_CORPORATION) in hci_initializing_run()
2024 … || (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_EM_MICROELECTRONIC_MARIN_SA)) ){ in hci_initializing_run()
2028 … uint32_t baud_rate = ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_init; in hci_initializing_run()
2030 hci_stack->hci_transport->set_baudrate(baud_rate); in hci_initializing_run()
2037 hci_stack->substate = HCI_INIT_W4_CUSTOM_INIT_BCM_DELAY; in hci_initializing_run()
2038 btstack_run_loop_set_timer(&hci_stack->timeout, bcm_delay_ms); in hci_initializing_run()
2039 … btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_initialization_timeout_handler); in hci_initializing_run()
2040 btstack_run_loop_add_timer(&hci_stack->timeout); in hci_initializing_run()
2048 hci_stack->substate = HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS; in hci_initializing_run()
2052 hci_stack->substate = HCI_INIT_W4_READ_BD_ADDR; in hci_initializing_run()
2058 hci_stack->substate = HCI_INIT_W4_READ_BUFFER_SIZE; in hci_initializing_run()
2066 hci_stack->substate = HCI_INIT_W4_READ_LOCAL_SUPPORTED_FEATURES; in hci_initializing_run()
2072 hci_stack->substate = HCI_INIT_W4_SET_CONTROLLER_TO_HOST_FLOW_CONTROL; in hci_initializing_run()
2076 hci_stack->substate = HCI_INIT_W4_HOST_BUFFER_SIZE; in hci_initializing_run()
2083 hci_stack->substate = HCI_INIT_W4_SET_EVENT_MASK; in hci_initializing_run()
2096 && (hci_stack->manufacturer != BLUETOOTH_COMPANY_ID_PACKETCRAFT_INC)){ in hci_initializing_run()
2097 hci_stack->substate = HCI_INIT_W4_SET_EVENT_MASK_2; in hci_initializing_run()
2108 hci_stack->substate = HCI_INIT_W4_WRITE_SIMPLE_PAIRING_MODE; in hci_initializing_run()
2109 hci_send_cmd(&hci_write_simple_pairing_mode, hci_stack->ssp_enable); in hci_initializing_run()
2117 hci_stack->substate = HCI_INIT_W4_WRITE_INQUIRY_MODE; in hci_initializing_run()
2118 hci_send_cmd(&hci_write_inquiry_mode, (int) hci_stack->inquiry_mode); in hci_initializing_run()
2126 if (hci_classic_supported() && hci_stack->secure_connections_enable in hci_initializing_run()
2128 hci_stack->secure_connections_active = true; in hci_initializing_run()
2129 hci_stack->substate = HCI_INIT_W4_WRITE_SECURE_CONNECTIONS_HOST_ENABLE; in hci_initializing_run()
2139 hci_stack->substate = HCI_INIT_W4_SET_MIN_ENCRYPTION_KEY_SIZE; in hci_initializing_run()
2140 … hci_send_cmd(&hci_set_min_encryption_key_size, hci_stack->gap_required_encyrption_key_size); in hci_initializing_run()
2152 hci_stack->substate = HCI_INIT_W4_WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE; in hci_initializing_run()
2162 hci_stack->substate = HCI_INIT_W4_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING; in hci_initializing_run()
2173 …if (hci_classic_supported() && (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_BROADCOM_CORPORATI… in hci_initializing_run()
2174 hci_stack->substate = HCI_INIT_W4_BCM_WRITE_SCO_PCM_INT; in hci_initializing_run()
2197 …if (hci_classic_supported() && (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_BROADCOM_CORPORATI… in hci_initializing_run()
2198 hci_stack->substate = HCI_INIT_W4_BCM_WRITE_I2SPCM_INTERFACE_PARAM; in hci_initializing_run()
2210 …if (hci_classic_supported() && (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_BROADCOM_CORPORATI… in hci_initializing_run()
2211 hci_stack->substate = HCI_INIT_W4_BCM_WRITE_PCM_DATA_FORMAT_PARAM; in hci_initializing_run()
2219 …if (hci_classic_supported() && (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_BROADCOM_CORPORATI… in hci_initializing_run()
2220 hci_stack->substate = HCI_INIT_W4_BCM_PCM2_SETUP; in hci_initializing_run()
2271 hci_stack->substate = HCI_INIT_W4_LE_READ_BUFFER_SIZE; in hci_initializing_run()
2287 hci_stack->substate = HCI_INIT_W4_WRITE_LE_HOST_SUPPORTED; in hci_initializing_run()
2296 hci_stack->substate = HCI_INIT_W4_LE_SET_EVENT_MASK; in hci_initializing_run()
2312 hci_stack->substate = HCI_INIT_W4_LE_READ_MAX_DATA_LENGTH; in hci_initializing_run()
2322 hci_stack->substate = HCI_INIT_W4_LE_WRITE_SUGGESTED_DATA_LENGTH; in hci_initializing_run()
2323 …nd_cmd(&hci_le_write_suggested_default_data_length, hci_stack->le_supported_max_tx_octets, hci_sta… in hci_initializing_run()
2333 hci_stack->substate = HCI_INIT_W4_READ_WHITE_LIST_SIZE; in hci_initializing_run()
2346 hci_stack->substate = HCI_INIT_W4_LE_READ_MAX_ADV_DATA_LEN; in hci_initializing_run()
2358 hci_stack->substate = HCI_INIT_W4_LE_SET_HOST_FEATURE_CONNECTED_ISO_STREAMS; in hci_initializing_run()
2368 hci_stack->substate = HCI_INIT_W4_LE_SET_HOST_FEATURE_CONNECTION_SUBRATING; in hci_initializing_run()
2376 hci_stack->substate = HCI_INIT_DONE; in hci_initializing_run()
2380 if (hci_classic_supported() && (hci_stack->gap_tasks_classic != 0)) { in hci_initializing_run()
2388 if (hci_le_supported() && hci_stack->le_scanning_param_update) { in hci_initializing_run()
2406 if (opcode == hci_stack->last_cmd_opcode){ in hci_initializing_event_handler_command_completed()
2408 …log_debug("Command complete for expected opcode %04x at substate %u", opcode, hci_stack->substate); in hci_initializing_event_handler_command_completed()
2410 …rent opcode %04x, expected %04x, at substate %u", opcode, hci_stack->last_cmd_opcode, hci_stack->s… in hci_initializing_event_handler_command_completed()
2417 if (opcode == hci_stack->last_cmd_opcode){ in hci_initializing_event_handler_command_completed()
2420 …status error 0x%02x for expected opcode %04x at substate %u", status, opcode, hci_stack->substate); in hci_initializing_event_handler_command_completed()
2425 … log_debug("Command status for opcode %04x, expected %04x", opcode, hci_stack->last_cmd_opcode); in hci_initializing_event_handler_command_completed()
2430 …if ((hci_stack->substate == HCI_INIT_W4_CUSTOM_INIT) && (hci_event_packet_get_type(packet) == HCI_… in hci_initializing_event_handler_command_completed()
2436 …if ((hci_stack->substate == HCI_INIT_W4_SEND_BAUD_CHANGE) && (hci_event_packet_get_type(packet) ==… in hci_initializing_event_handler_command_completed()
2440 hci_stack->num_cmd_packets = 1; in hci_initializing_event_handler_command_completed()
2469 && (hci_stack->substate == HCI_INIT_W4_SEND_READ_LOCAL_VERSION_INFORMATION)){ in hci_initializing_event_handler()
2473 hci_stack->substate = HCI_INIT_SEND_READ_LOCAL_VERSION_INFORMATION; in hci_initializing_event_handler()
2482 && (hci_stack->substate == HCI_INIT_W4_READ_LOCAL_SUPPORTED_COMMANDS)){ in hci_initializing_event_handler()
2486 hci_stack->substate = HCI_INIT_READ_LOCAL_SUPPORTED_COMMANDS; in hci_initializing_event_handler()
2494 switch (hci_stack->substate){ in hci_initializing_event_handler()
2496 hci_stack->substate = HCI_INIT_W4_SEND_RESET; in hci_initializing_event_handler()
2499 hci_stack->substate = HCI_INIT_W4_CUSTOM_INIT_CSR_WARM_BOOT; in hci_initializing_event_handler()
2514 need_baud_change = hci_stack->config in hci_initializing_event_handler()
2515 && hci_stack->chipset in hci_initializing_event_handler()
2516 && hci_stack->chipset->set_baudrate_command in hci_initializing_event_handler()
2517 && hci_stack->hci_transport->set_baudrate in hci_initializing_event_handler()
2518 && ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main; in hci_initializing_event_handler()
2520 need_addr_change = hci_stack->custom_bd_addr_set in hci_initializing_event_handler()
2521 && hci_stack->chipset in hci_initializing_event_handler()
2522 && hci_stack->chipset->set_bd_addr_command; in hci_initializing_event_handler()
2525 switch(hci_stack->substate){ in hci_initializing_event_handler()
2536 btstack_run_loop_remove_timer(&hci_stack->timeout); in hci_initializing_event_handler()
2537 hci_stack->substate = HCI_INIT_SEND_READ_LOCAL_VERSION_INFORMATION; in hci_initializing_event_handler()
2544 … if ((hci_stack->manufacturer != BLUETOOTH_COMPANY_ID_ST_MICROELECTRONICS) && need_baud_change){ in hci_initializing_event_handler()
2547 hci_stack->hci_transport->set_baudrate(baud_rate); in hci_initializing_event_handler()
2549 hci_stack->substate = HCI_INIT_CUSTOM_INIT; in hci_initializing_event_handler()
2552 btstack_run_loop_remove_timer(&hci_stack->timeout); in hci_initializing_event_handler()
2553 hci_stack->substate = HCI_INIT_CUSTOM_INIT; in hci_initializing_event_handler()
2557 hci_stack->substate = HCI_INIT_CUSTOM_INIT; in hci_initializing_event_handler()
2561 hci_stack->substate = HCI_INIT_CUSTOM_PRE_INIT; in hci_initializing_event_handler()
2566 if (need_baud_change && (hci_stack->chipset_result != BTSTACK_CHIPSET_NO_INIT_SCRIPT) && in hci_initializing_event_handler()
2567 ((hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_BROADCOM_CORPORATION) || in hci_initializing_event_handler()
2568 (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_EM_MICROELECTRONIC_MARIN_SA))) { in hci_initializing_event_handler()
2569 hci_stack->substate = HCI_INIT_SEND_BAUD_CHANGE_BCM; in hci_initializing_event_handler()
2573 hci_stack->substate = HCI_INIT_SET_BD_ADDR; in hci_initializing_event_handler()
2576 hci_stack->substate = HCI_INIT_READ_BD_ADDR; in hci_initializing_event_handler()
2583 hci_stack->hci_transport->set_baudrate(baud_rate); in hci_initializing_event_handler()
2586 hci_stack->substate = HCI_INIT_SET_BD_ADDR; in hci_initializing_event_handler()
2589 hci_stack->substate = HCI_INIT_READ_BD_ADDR; in hci_initializing_event_handler()
2593 if ((hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_ST_MICROELECTRONICS) in hci_initializing_event_handler()
2594 || (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_ATMEL_CORPORATION)){ in hci_initializing_event_handler()
2595 hci_stack->substate = HCI_INIT_SEND_RESET_ST_WARM_BOOT; in hci_initializing_event_handler()
2599 hci_stack->substate = HCI_INIT_READ_BD_ADDR; in hci_initializing_event_handler()
2602 hci_stack->substate = HCI_INIT_READ_BD_ADDR; in hci_initializing_event_handler()
2608 hci_stack->substate = HCI_INIT_DONE; in hci_initializing_event_handler()
2641 btstack_linked_list_remove(&hci_stack->connections, (btstack_linked_item_t *) conn); in hci_handle_connection_failed()
2715 if (hci_stack->state == HCI_STATE_INITIALIZING) { in handle_event_for_current_stack_state()
2720 if ((hci_stack->state == HCI_STATE_FALLING_ASLEEP) in handle_event_for_current_stack_state()
2721 && (hci_stack->substate == HCI_FALLING_ASLEEP_W4_WRITE_SCAN_ENABLE) in handle_event_for_current_stack_state()
2786 hci_stack->local_supported_commands = 0; in hci_store_local_supported_commands()
2796 hci_stack->local_supported_commands |= (1LU << i); in hci_store_local_supported_commands()
2799 log_info("Local supported commands summary %08" PRIx32, hci_stack->local_supported_commands); in hci_store_local_supported_commands()
2820 hci_stack->hci_command_con_handle = HCI_CON_HANDLE_INVALID; in handle_command_complete_event()
2824 hci_stack->num_cmd_packets = packet[2] ? 1 : 0; in handle_command_complete_event()
2836 if (hci_stack->state == HCI_STATE_INITIALIZING) { in handle_command_complete_event()
2841 hci_stack->acl_data_packet_length = btstack_min(acl_len, HCI_ACL_PAYLOAD_SIZE); in handle_command_complete_event()
2842 hci_stack->sco_data_packet_length = btstack_min(sco_len, HCI_ACL_PAYLOAD_SIZE); in handle_command_complete_event()
2844 …hci_stack->acl_packets_total_num = (uint8_t) btstack_min(little_endian_read_16(packet, 9), MAX_NR… in handle_command_complete_event()
2845 …hci_stack->sco_packets_total_num = (uint8_t) btstack_min(little_endian_read_16(packet, 11), MAX_NR… in handle_command_complete_event()
2848 … acl_len, hci_stack->acl_data_packet_length, hci_stack->acl_packets_total_num, in handle_command_complete_event()
2849 hci_stack->sco_data_packet_length, hci_stack->sco_packets_total_num); in handle_command_complete_event()
2863 hci_stack->le_iso_packets_length = little_endian_read_16(packet, 9); in handle_command_complete_event()
2864 hci_stack->le_iso_packets_total_num = packet[11]; in handle_command_complete_event()
2866 hci_stack->le_iso_packets_length, hci_stack->le_iso_packets_total_num); in handle_command_complete_event()
2871 hci_stack->le_data_packets_length = little_endian_read_16(packet, 6); in handle_command_complete_event()
2872 hci_stack->le_acl_packets_total_num = packet[8]; in handle_command_complete_event()
2874 if (HCI_ACL_PAYLOAD_SIZE < hci_stack->le_data_packets_length){ in handle_command_complete_event()
2875 hci_stack->le_data_packets_length = HCI_ACL_PAYLOAD_SIZE; in handle_command_complete_event()
2877 …"hci_le_read_buffer_size: acl size %u, acl count %u", hci_stack->le_data_packets_length, hci_stack… in handle_command_complete_event()
2882 hci_stack->le_supported_max_tx_octets = little_endian_read_16(packet, 6); in handle_command_complete_event()
2883 hci_stack->le_supported_max_tx_time = little_endian_read_16(packet, 8); in handle_command_complete_event()
2884 …_maximum_data_length: tx octets %u, tx time %u us", hci_stack->le_supported_max_tx_octets, hci_sta… in handle_command_complete_event()
2889 hci_stack->le_whitelist_capacity = packet[6]; in handle_command_complete_event()
2890 log_info("hci_le_read_white_list_size: size %u", hci_stack->le_whitelist_capacity); in handle_command_complete_event()
2896 hci_stack->le_maximum_advertising_data_length = little_endian_read_16(packet, 6); in handle_command_complete_event()
2899 if (hci_stack->le_advertising_set_in_current_command != 0) { in handle_command_complete_event()
2900 …le_advertising_set_t * advertising_set = hci_advertising_set_for_handle(hci_stack->le_advertising_… in handle_command_complete_event()
2901 hci_stack->le_advertising_set_in_current_command = 0; in handle_command_complete_event()
2905 …nt[] = { HCI_EVENT_META_GAP, 4, GAP_SUBEVENT_ADVERTISING_SET_INSTALLED, hci_stack->le_advertising_… in handle_command_complete_event()
2913 if (hci_stack->le_advertising_set_in_current_command != 0) { in handle_command_complete_event()
2914 …le_advertising_set_t * advertising_set = hci_advertising_set_for_handle(hci_stack->le_advertising_… in handle_command_complete_event()
2915 hci_stack->le_advertising_set_in_current_command = 0; in handle_command_complete_event()
2917 …vent[] = { HCI_EVENT_META_GAP, 3, GAP_SUBEVENT_ADVERTISING_SET_REMOVED, hci_stack->le_advertising_… in handle_command_complete_event()
2919 …btstack_linked_list_remove(&hci_stack->le_advertising_sets, (btstack_linked_item_t *) advertising_… in handle_command_complete_event()
2927 … reverse_bd_addr(&packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE + 1], hci_stack->local_bd_addr); in handle_command_complete_event()
2928 …log_info("Local Address, Status: 0x%02x: Addr: %s", status, bd_addr_to_str(hci_stack->local_bd_add… in handle_command_complete_event()
2930 if (hci_stack->link_key_db){ in handle_command_complete_event()
2931 hci_stack->link_key_db->set_local_bd_addr(hci_stack->local_bd_addr); in handle_command_complete_event()
2937 hci_emit_scan_mode_changed(hci_stack->discoverable, hci_stack->connectable); in handle_command_complete_event()
2941 hci_stack->inquiry_state = GAP_INQUIRY_STATE_PERIODIC; in handle_command_complete_event()
2943 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; in handle_command_complete_event()
2948 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_W4_CANCELLED){ in handle_command_complete_event()
2949 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; in handle_command_complete_event()
2956 …(void)memcpy(hci_stack->local_supported_features, &packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE + 1],… in handle_command_complete_event()
2960 …hci_stack->usable_packet_types_acl = hci_acl_packet_types_for_buffer_size_and_local_features(HCI_A… in handle_command_complete_event()
2961 log_info("ACL Packet types %04x", hci_stack->usable_packet_types_acl); in handle_command_complete_event()
2963 hci_stack->usable_packet_types_sco = hci_sco_packet_types_for_features( in handle_command_complete_event()
2964 &hci_stack->local_supported_features[0]); in handle_command_complete_event()
2965 …log_info("SCO Packet types %04x - eSCO %u", hci_stack->usable_packet_types_sco, hci_extended_sco_l… in handle_command_complete_event()
2983 hci_stack->manufacturer = manufacturer; in handle_command_complete_event()
2984 log_info("Manufacturer: 0x%04x", hci_stack->manufacturer); in handle_command_complete_event()
2992 hci_stack->synchronous_flow_control_enabled = 1; in handle_command_complete_event()
3014 hci_stack->gap_pairing_state = GAP_PAIRING_STATE_IDLE; in handle_command_complete_event()
3016 … conn = hci_connection_for_bd_addr_and_type(hci_stack->gap_pairing_addr, BD_ADDR_TYPE_ACL); in handle_command_complete_event()
3043 conn = hci_connection_for_handle(hci_stack->classic_oob_con_handle); in handle_command_complete_event()
3044 hci_stack->classic_oob_con_handle = HCI_CON_HANDLE_INVALID; in handle_command_complete_event()
3054 cig = hci_cig_for_id(hci_stack->iso_active_operation_group_id); in handle_command_complete_event()
3062 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in handle_command_complete_event()
3065 … if ((iso_stream->group_id == hci_stack->iso_active_operation_group_id) && in handle_command_complete_event()
3079 … btstack_linked_list_remove(&hci_stack->le_audio_cigs, (btstack_linked_item_t *) cig); in handle_command_complete_event()
3082 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in handle_command_complete_event()
3097 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_bigs); in handle_command_complete_event()
3116 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_big_syncs); in handle_command_complete_event()
3136 if (hci_stack->iso_active_operation_type == HCI_ISO_TYPE_CIS){ in handle_command_complete_event()
3137 if (hci_stack->iso_active_operation_group_id == HCI_ISO_GROUP_ID_SINGLE_CIS){ in handle_command_complete_event()
3138 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in handle_command_complete_event()
3141 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in handle_command_complete_event()
3169 cig = hci_cig_for_id(hci_stack->iso_active_operation_group_id); in handle_command_complete_event()
3170 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in handle_command_complete_event()
3181 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in handle_command_complete_event()
3200 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_big_syncs); in handle_command_complete_event()
3228 btstack_linked_list_remove(&hci_stack->le_audio_bigs, (btstack_linked_item_t *) big); in hci_iso_create_big_failed()
3237 btstack_linked_list_remove(&hci_stack->le_audio_big_syncs, (btstack_linked_item_t *) big_sync); in hci_iso_big_sync_failed()
3250 hci_stack->num_cmd_packets = packet[3] ? 1 : 0; in handle_command_status_event()
3265 hci_stack->hci_command_con_handle = HCI_CON_HANDLE_INVALID; in handle_command_status_event()
3278 addr_type = hci_stack->outgoing_addr_type; in handle_command_status_event()
3279 memcpy(addr, hci_stack->outgoing_addr, 6); in handle_command_status_event()
3282 memset(hci_stack->outgoing_addr, 0, 6); in handle_command_status_event()
3283 hci_stack->outgoing_addr_type = BD_ADDR_TYPE_UNKNOWN; in handle_command_status_event()
3288 hci_stack->le_connecting_state = LE_CONNECTING_IDLE; in handle_command_status_event()
3289 hci_stack->le_connecting_request = LE_CONNECTING_IDLE; in handle_command_status_event()
3302 hci_stack->inquiry_state = GAP_INQUIRY_STATE_ACTIVE; in handle_command_status_event()
3304 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; in handle_command_status_event()
3319 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in handle_command_status_event()
3321 le_audio_big_t * big = hci_big_for_handle(hci_stack->iso_active_operation_group_id); in handle_command_status_event()
3329 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in handle_command_status_event()
3331 …le_audio_big_sync_t * big_sync = hci_big_sync_for_handle(hci_stack->iso_active_operation_group_id); in handle_command_status_event()
3402 hci_stack->le_connecting_state = LE_CONNECTING_IDLE; in hci_handle_le_connection_complete_event()
3406 if (hci_stack->le_connecting_request == LE_CONNECTING_DIRECT){ in hci_handle_le_connection_complete_event()
3412 bool cancelled_by_user = hci_stack->le_connecting_request == LE_CONNECTING_IDLE; in hci_handle_le_connection_complete_event()
3415 btstack_linked_list_remove(&hci_stack->connections, (btstack_linked_item_t *) conn); in hci_handle_le_connection_complete_event()
3454 hci_stack->le_connecting_state = LE_CONNECTING_IDLE; in hci_handle_le_connection_complete_event()
3455 hci_stack->le_connecting_request = LE_CONNECTING_IDLE; in hci_handle_le_connection_complete_event()
3475 hci_stack->le_advertisements_state &= ~LE_ADVERTISEMENT_STATE_ACTIVE; in hci_handle_le_connection_complete_event()
3553 if (hci_stack->gap_secure_connections_only_mode){ in hci_ssp_assess_security_on_io_cap_request()
3575 if (hci_stack->bondable == false){ in hci_ssp_assess_security_on_io_cap_request()
3590 … = hci_ssp_security_level_possible_for_io_cap(requested_security_level, hci_stack->ssp_io_capabili… in hci_ssp_assess_security_on_io_cap_request()
3624 …if ((conn->requested_security_level >= LEVEL_3) && (hci_stack->ssp_io_capability >= SSP_IO_CAPABIL… in hci_ssp_assess_security_on_io_cap_request()
3635 if (hci_stack->ssp_io_capability != SSP_IO_CAPABILITY_UNKNOWN){ in hci_ssp_assess_security_on_io_cap_request()
3776 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_ACTIVE){ in event_handler()
3777 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; in event_handler()
3783 if (hci_stack->remote_name_state == GAP_REMOTE_NAME_STATE_W4_COMPLETE){ in event_handler()
3784 hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_IDLE; in event_handler()
3792 if (memcmp(hci_stack->local_bd_addr, addr, 6) == 0){ in event_handler()
3793 … hci_stack->decline_reason = ERROR_CODE_CONNECTION_REJECTED_DUE_TO_UNACCEPTABLE_BD_ADDR; in event_handler()
3794 bd_addr_copy(hci_stack->decline_addr, addr); in event_handler()
3798 if (hci_stack->gap_classic_accept_callback != NULL){ in event_handler()
3799 if ((*hci_stack->gap_classic_accept_callback)(addr, link_type) == 0){ in event_handler()
3800 … hci_stack->decline_reason = ERROR_CODE_CONNECTION_REJECTED_DUE_TO_SECURITY_REASONS; in event_handler()
3801 bd_addr_copy(hci_stack->decline_addr, addr); in event_handler()
3815 hci_stack->decline_reason = ERROR_CODE_CONNECTION_REJECTED_DUE_TO_LIMITED_RESOURCES; in event_handler()
3816 bd_addr_copy(hci_stack->decline_addr, addr); in event_handler()
3859 …if ((hci_stack->link_supervision_timeout != HCI_LINK_SUPERVISION_TIMEOUT_DEFAULT) && (conn->role =… in event_handler()
3864 if (hci_stack->automatic_flush_timeout != 0){ in event_handler()
3912 …if (conn->address_type == BD_ADDR_TYPE_SCO && hci_stack->hci_transport && hci_stack->hci_transport… in event_handler()
3913 …hci_stack->hci_transport->set_sco_config(hci_stack->sco_voice_setting_active, hci_number_sco_conne… in event_handler()
3917 hci_stack->sco_can_send_now = true; in event_handler()
3928 if (hci_stack->sco_transport != NULL){ in event_handler()
3929 …sco_format_t sco_format = ((hci_stack->sco_voice_setting_active & 0x03) == 0x03) ? SCO_FORMAT_8_BI… in event_handler()
3930 hci_stack->sco_transport->open(conn->con_handle, sco_format); in event_handler()
3996 if ((conn->link_key_type == INVALID_LINK_KEY) && (hci_stack->link_key_db != NULL)){ in event_handler()
3997 … hci_stack->link_key_db->get_link_key(conn->address, conn->link_key, &conn->link_key_type); in event_handler()
4027 if (hci_stack->bondable == false) break; in event_handler()
4048 if (!hci_stack->bondable ){ in event_handler()
4055 … if ((hci_stack->gap_secure_connections_only_mode) || (conn->requested_security_level == LEVEL_4)){ in event_handler()
4106 …_ssp_security_level_possible_for_io_cap(conn->requested_security_level, hci_stack->ssp_io_capabili… in event_handler()
4107 if (hci_stack->ssp_auto_accept){ in event_handler()
4121 if (hci_stack->ssp_auto_accept){ in event_handler()
4153 … if (hci_stack->secure_connections_active && sc_used_during_pairing && !connected_uses_aes_ccm){ in event_handler()
4270 if (hci_stack->acl_fragmentation_total_size > 0u) { in event_handler()
4271 if (handle == READ_ACL_CONNECTION_HANDLE(hci_stack->hci_packet_buffer)){ in event_handler()
4272 int release_buffer = hci_stack->acl_fragmentation_tx_active == 0u; in event_handler()
4274 hci_stack->acl_fragmentation_total_size = 0; in event_handler()
4275 hci_stack->acl_fragmentation_pos = 0; in event_handler()
4284 if (hci_stack->iso_fragmentation_total_size > 0u) { in event_handler()
4285 if (handle == READ_ISO_CONNECTION_HANDLE(hci_stack->hci_packet_buffer)){ in event_handler()
4286 int release_buffer = hci_stack->iso_fragmentation_tx_active == 0u; in event_handler()
4288 hci_stack->iso_fragmentation_total_size = 0; in event_handler()
4289 hci_stack->iso_fragmentation_pos = 0; in event_handler()
4305 … if ((handle != HCI_CON_HANDLE_INVALID) && (handle == hci_stack->hci_command_con_handle)){ in event_handler()
4310 hci_stack->hci_command_con_handle = HCI_CON_HANDLE_INVALID; in event_handler()
4311 hci_stack->num_cmd_packets = 1; in event_handler()
4344 if (hci_stack->hardware_error_callback){ in event_handler()
4345 (*hci_stack->hardware_error_callback)(packet[2]); in event_handler()
4370 hci_stack->acl_fragmentation_tx_active = 0; in event_handler()
4372 hci_stack->iso_fragmentation_tx_active = 0; in event_handler()
4373 if (hci_stack->iso_fragmentation_total_size) break; in event_handler()
4375 if (hci_stack->acl_fragmentation_total_size) break; in event_handler()
4378 hci_stack->hci_packet_buffer_reserved = false; in event_handler()
4394 hci_stack->sco_can_send_now = true; in event_handler()
4411 if (!hci_stack->le_scanning_enabled) break; in event_handler()
4416 if (!hci_stack->le_scanning_enabled) break; in event_handler()
4420 hci_stack->le_periodic_sync_request = LE_CONNECTING_IDLE; in event_handler()
4421 hci_stack->le_periodic_sync_state = LE_CONNECTING_IDLE; in event_handler()
4427 hci_stack->le_advertisements_state &= ~LE_ADVERTISEMENT_STATE_ACTIVE; in event_handler()
4430 btstack_linked_list_iterator_init(&it, &hci_stack->le_advertising_sets); in event_handler()
4518 if (hci_stack->iso_active_operation_type == HCI_ISO_TYPE_CIS){ in event_handler()
4532 … if (hci_stack->iso_active_operation_group_id == HCI_ISO_GROUP_ID_SINGLE_CIS){ in event_handler()
4545 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in event_handler()
4548 … le_audio_cig_t * cig = hci_cig_for_id(hci_stack->iso_active_operation_group_id); in event_handler()
4576 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in event_handler()
4582 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in event_handler()
4594 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in event_handler()
4616 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in event_handler()
4621 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in event_handler()
4630 … btstack_linked_list_remove(&hci_stack->le_audio_bigs, (btstack_linked_item_t *) big); in event_handler()
4642 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in event_handler()
4653 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in event_handler()
4676 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in event_handler()
4680 … btstack_linked_list_remove(&hci_stack->le_audio_big_syncs, (btstack_linked_item_t *) big_sync); in event_handler()
4693 switch (hci_stack->manufacturer){ in event_handler()
4695 hci_stack->num_cmd_packets = 1; in event_handler()
4737 if (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_CAMBRIDGE_SILICON_RADIO){ in sco_handler()
4738 if ((size == 83) && ((hci_stack->sco_voice_setting_active & 0x03) == 0x03)){ in sco_handler()
4749 if (hci_stack->synchronous_flow_control_enabled == 0){ in sco_handler()
4751 …(uint8_t) btstack_min(2 * HCI_SCO_2EV3_SIZE / conn->sco_payload_length, hci_stack->sco_packets_tot… in sco_handler()
4770 if (hci_stack->sco_packet_handler) { in sco_handler()
4771 hci_stack->sco_packet_handler(HCI_SCO_DATA_PACKET, 0, packet, size); in sco_handler()
4782 hci_stack->host_completed_packets = 1; in sco_handler()
4841 …btstack_linked_list_add_tail(&hci_stack->event_handlers, (btstack_linked_item_t*) callback_handler… in hci_add_event_handler()
4848 … btstack_linked_list_remove(&hci_stack->event_handlers, (btstack_linked_item_t*) callback_handler); in hci_remove_event_handler()
4853 hci_stack->acl_packet_handler = handler; in hci_register_acl_packet_handler()
4861 hci_stack->sco_packet_handler = handler; in hci_register_sco_packet_handler()
4867 hci_stack->iso_packet_handler = handler; in hci_register_iso_packet_handler()
4873 hci_stack->connections = NULL; in hci_state_reset()
4882 hci_stack->hci_packet_buffer_reserved = false; in hci_state_reset()
4885 hci_stack->decline_reason = 0; in hci_state_reset()
4887 hci_stack->secure_connections_active = false; in hci_state_reset()
4890 hci_stack->inquiry_lap = GAP_IAC_GENERAL_INQUIRY; in hci_state_reset()
4892 hci_stack->gap_tasks_classic = in hci_state_reset()
4902 hci_stack->classic_read_local_oob_data = false; in hci_state_reset()
4903 hci_stack->classic_oob_con_handle = HCI_CON_HANDLE_INVALID; in hci_state_reset()
4908 memset(hci_stack->le_random_address, 0, 6); in hci_state_reset()
4909 hci_stack->le_random_address_set = 0; in hci_state_reset()
4912 hci_stack->le_scanning_active = false; in hci_state_reset()
4913 hci_stack->le_scanning_param_update = true; in hci_state_reset()
4914 hci_stack->le_connecting_state = LE_CONNECTING_IDLE; in hci_state_reset()
4915 hci_stack->le_connecting_request = LE_CONNECTING_IDLE; in hci_state_reset()
4916 hci_stack->le_whitelist_capacity = 0; in hci_state_reset()
4918 hci_stack->le_periodic_terminate_sync_handle = HCI_CON_HANDLE_INVALID; in hci_state_reset()
4922 hci_stack->le_advertisements_state &= ~LE_ADVERTISEMENT_STATE_ACTIVE; in hci_state_reset()
4923 if ((hci_stack->le_advertisements_state & LE_ADVERTISEMENT_STATE_PARAMS_SET) != 0){ in hci_state_reset()
4924 hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_PARAMS; in hci_state_reset()
4926 if (hci_stack->le_advertisements_data != NULL){ in hci_state_reset()
4927 hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_ADV_DATA; in hci_state_reset()
4931 hci_stack->le_resolving_list_state = LE_RESOLVING_LIST_SEND_ENABLE_ADDRESS_RESOLUTION; in hci_state_reset()
4934 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID; in hci_state_reset()
4935 hci_stack->iso_active_operation_group_id = HCI_ISO_GROUP_ID_INVALID; in hci_state_reset()
4938 hci_stack->hci_command_con_handle = HCI_CON_HANDLE_INVALID; in hci_state_reset()
4948 hci_stack->link_key_db = link_key_db; in hci_set_link_key_db()
4949 if (hci_stack->link_key_db) { in hci_set_link_key_db()
4950 hci_stack->link_key_db->open(); in hci_set_link_key_db()
4958 if (!hci_stack) { in hci_init()
4959 hci_stack = (hci_stack_t*) malloc(sizeof(hci_stack_t)); in hci_init()
4961 btstack_assert(hci_stack != NULL); in hci_init()
4963 hci_stack = &hci_stack_static; in hci_init()
4965 memset(hci_stack, 0, sizeof(hci_stack_t)); in hci_init()
4968 hci_stack->hci_transport = transport; in hci_init()
4971 hci_stack->config = config; in hci_init()
4974 hci_stack->hci_packet_buffer = &hci_stack->hci_packet_buffer_data[HCI_OUTGOING_PRE_BUFFER_SIZE]; in hci_init()
4977 hci_stack->acl_data_packet_length = HCI_ACL_PAYLOAD_SIZE; in hci_init()
4982 hci_stack->state = HCI_STATE_OFF; in hci_init()
4985 hci_stack->class_of_device = 0x007a020c; // Smartphone in hci_init()
4988 hci_stack->bondable = 1; in hci_init()
4992 hci_stack->local_name = default_classic_name; in hci_init()
4995 hci_stack->master_slave_policy = 1; in hci_init()
4998 hci_stack->allow_role_switch = 1; in hci_init()
5001 hci_stack->gap_security_level = LEVEL_2; in hci_init()
5004 hci_stack->gap_security_mode = GAP_SECURITY_MODE_4; in hci_init()
5007 hci_stack->gap_required_encyrption_key_size = 7; in hci_init()
5010 hci_stack->link_supervision_timeout = HCI_LINK_SUPERVISION_TIMEOUT_DEFAULT; in hci_init()
5013 hci_stack->page_timeout = 0x6000; // ca. 15 sec in hci_init()
5016 hci_stack->enabled_packet_types_acl = ACL_PACKET_TYPES_ALL; in hci_init()
5020 hci_stack->ssp_enable = 1; in hci_init()
5021 hci_stack->ssp_io_capability = SSP_IO_CAPABILITY_NO_INPUT_NO_OUTPUT; in hci_init()
5022 …hci_stack->ssp_authentication_requirement = SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_GENERAL_BO… in hci_init()
5023 hci_stack->ssp_auto_accept = 1; in hci_init()
5026 hci_stack->secure_connections_enable = true; in hci_init()
5029 hci_stack->sco_voice_setting = 0x60; in hci_init()
5032 hci_stack->le_connection_scan_interval = 0x0060; // 60 ms in hci_init()
5033 hci_stack->le_connection_scan_window = 0x0030; // 30 ms in hci_init()
5034 hci_stack->le_connection_interval_min = 0x0008; // 10 ms in hci_init()
5035 hci_stack->le_connection_interval_max = 0x0018; // 30 ms in hci_init()
5036 hci_stack->le_connection_latency = 4; // 4 in hci_init()
5037 hci_stack->le_supervision_timeout = 0x0048; // 720 ms in hci_init()
5038 hci_stack->le_minimum_ce_length = 0; // 0 ms in hci_init()
5039 hci_stack->le_maximum_ce_length = 0; // 0 ms in hci_init()
5043 hci_stack->le_connection_phys = 0x01; // LE 1M PHY in hci_init()
5046 hci_stack->le_scan_type = 0x01; // active in hci_init()
5047 hci_stack->le_scan_interval = 0x1e0; // 300 ms in hci_init()
5048 hci_stack->le_scan_window = 0x30; // 30 ms in hci_init()
5049 hci_stack->le_scan_phys = 0x01; // LE 1M PHY in hci_init()
5053 hci_stack->le_max_number_peripheral_connections = 1; // only single connection as peripheral in hci_init()
5056 hci_stack->le_advertisements_interval_min = 0x0800; in hci_init()
5057 hci_stack->le_advertisements_interval_max = 0x0800; in hci_init()
5058 hci_stack->le_advertisements_type = 0; in hci_init()
5059 hci_stack->le_own_addr_type = BD_ADDR_TYPE_LE_PUBLIC; in hci_init()
5060 hci_stack->le_advertisements_direct_address_type = BD_ADDR_TYPE_LE_PUBLIC; in hci_init()
5061 hci_stack->le_advertisements_channel_map = 0x07; in hci_init()
5062 hci_stack->le_advertisements_filter_policy = 0; in hci_init()
5066 hci_stack->le_connection_parameter_range.le_conn_interval_min = 6; in hci_init()
5067 hci_stack->le_connection_parameter_range.le_conn_interval_max = 3200; in hci_init()
5068 hci_stack->le_connection_parameter_range.le_conn_latency_min = 0; in hci_init()
5069 hci_stack->le_connection_parameter_range.le_conn_latency_max = 500; in hci_init()
5070 hci_stack->le_connection_parameter_range.le_supervision_timeout_min = 10; in hci_init()
5071 hci_stack->le_connection_parameter_range.le_supervision_timeout_max = 3200; in hci_init()
5074 hci_stack->iso_packets_to_queue = 1; in hci_init()
5078 hci_stack->le_privacy_mode = LE_PRIVACY_MODE_DEVICE; in hci_init()
5085 btstack_run_loop_remove_timer(&hci_stack->timeout); in hci_deinit()
5087 if (hci_stack) { in hci_deinit()
5088 free(hci_stack); in hci_deinit()
5091 hci_stack = NULL; in hci_deinit()
5102 hci_stack->chipset = chipset_driver; in hci_set_chipset()
5105 if (hci_stack->chipset && hci_stack->chipset->init){ in hci_set_chipset()
5106 hci_stack->chipset->init(hci_stack->config); in hci_set_chipset()
5111 hci_stack->chipset_pre_init = true; in hci_enable_custom_pre_init()
5119 hci_stack->control = hardware_control; in hci_set_control()
5121 hardware_control->init(hci_stack->config); in hci_set_control()
5126 btstack_linked_list_iterator_init(&it, &hci_stack->connections); in hci_discard_connections()
5134 while (hci_stack->iso_streams != NULL){ in hci_discard_connections()
5135 hci_iso_stream_finalize((hci_iso_stream_t *) hci_stack->iso_streams); in hci_discard_connections()
5144 if (hci_stack->link_key_db) { in hci_close()
5145 hci_stack->link_key_db->close(); in hci_close()
5154 free(hci_stack); in hci_close()
5156 hci_stack = NULL; in hci_close()
5161 hci_stack->sco_transport = sco_transport; in hci_set_sco_transport()
5171 hci_stack->gap_required_encyrption_key_size = encryption_key_size; in gap_set_required_encryption_key_size()
5176 hci_stack->gap_security_mode = security_mode; in gap_set_security_mode()
5184 return hci_stack->gap_security_mode; in gap_get_security_mode()
5188 hci_stack->gap_security_level = security_level; in gap_set_security_level()
5192 if (hci_stack->gap_secure_connections_only_mode){ in gap_get_security_level()
5195 return hci_stack->gap_security_level; in gap_get_security_level()
5199 hci_stack->gap_minimal_service_security_level = security_level; in gap_set_minimal_service_security_level()
5203 hci_stack->gap_secure_connections_only_mode = enable; in gap_set_secure_connections_only_mode()
5207 return hci_stack->gap_secure_connections_only_mode; in gap_get_secure_connections_only_mode()
5213 hci_stack->class_of_device = class_of_device; in gap_set_class_of_device()
5214 hci_stack->gap_tasks_classic |= GAP_TASK_SET_CLASS_OF_DEVICE; in gap_set_class_of_device()
5219 hci_stack->default_link_policy_settings = default_link_policy_settings; in gap_set_default_link_policy_settings()
5220 hci_stack->gap_tasks_classic |= GAP_TASK_SET_DEFAULT_LINK_POLICY; in gap_set_default_link_policy_settings()
5225 hci_stack->allow_role_switch = allow_role_switch ? 1 : 0; in gap_set_allow_role_switch()
5229 return hci_stack->allow_role_switch; in hci_get_allow_role_switch()
5233 hci_stack->link_supervision_timeout = link_supervision_timeout; in gap_set_link_supervision_timeout()
5237 hci_stack->automatic_flush_timeout = btstack_min(timeout_ms, 1280) * 8 / 5; // divide by 0.625 in gap_enable_link_watchdog()
5241 return hci_stack->automatic_flush_timeout; in hci_automatic_flush_timeout()
5252 (void)memcpy(hci_stack->custom_bd_addr, addr, 6); in hci_set_bd_addr()
5253 hci_stack->custom_bd_addr_set = 1; in hci_set_bd_addr()
5270 if (hci_stack->control && hci_stack->control->on){ in hci_power_control_on()
5271 err = (*hci_stack->control->on)(); in hci_power_control_on()
5280 if (hci_stack->chipset && hci_stack->chipset->init){ in hci_power_control_on()
5281 hci_stack->chipset->init(hci_stack->config); in hci_power_control_on()
5285 if (hci_stack->hci_transport->init){ in hci_power_control_on()
5286 hci_stack->hci_transport->init(hci_stack->config); in hci_power_control_on()
5290 err = hci_stack->hci_transport->open(); in hci_power_control_on()
5293 if (hci_stack->control && hci_stack->control->off){ in hci_power_control_on()
5294 (*hci_stack->control->off)(); in hci_power_control_on()
5307 hci_stack->hci_transport->close(); in hci_power_control_off()
5312 if (hci_stack->control && hci_stack->control->off){ in hci_power_control_off()
5313 (*hci_stack->control->off)(); in hci_power_control_off()
5318 hci_stack->state = HCI_STATE_OFF; in hci_power_control_off()
5329 hci_stack->hci_transport->close(hci_stack->config); in hci_power_control_sleep()
5333 if (hci_stack->control && hci_stack->control->sleep){ in hci_power_control_sleep()
5334 (*hci_stack->control->sleep)(); in hci_power_control_sleep()
5337 hci_stack->state = HCI_STATE_SLEEPING; in hci_power_control_sleep()
5345 if (hci_stack->control && hci_stack->control->wake){ in hci_power_control_wake()
5346 (*hci_stack->control->wake)(); in hci_power_control_wake()
5351 int err = hci_stack->hci_transport->open(hci_stack->config); in hci_power_control_wake()
5354 if (hci_stack->control && hci_stack->control->off){ in hci_power_control_wake()
5355 (*hci_stack->control->off)(); in hci_power_control_wake()
5367 hci_stack->num_cmd_packets = 1; // assume that one cmd can be sent in hci_power_enter_initializing_state()
5368 hci_stack->hci_packet_buffer_reserved = false; in hci_power_enter_initializing_state()
5369 hci_stack->state = HCI_STATE_INITIALIZING; in hci_power_enter_initializing_state()
5372 if (hci_stack->chipset_pre_init) { in hci_power_enter_initializing_state()
5373 hci_stack->substate = HCI_INIT_CUSTOM_PRE_INIT; in hci_power_enter_initializing_state()
5377 hci_stack->substate = HCI_INIT_SEND_RESET; in hci_power_enter_initializing_state()
5385 btstack_linked_list_iterator_init(&it, &hci_stack->le_whitelist); in hci_power_enter_halting_state()
5397 btstack_linked_list_iterator_init(&it, &hci_stack->le_periodic_advertiser_list); in hci_power_enter_halting_state()
5413 hci_stack->state = HCI_STATE_HALTING; in hci_power_enter_halting_state()
5414 hci_stack->substate = HCI_HALTING_CLASSIC_STOP; in hci_power_enter_halting_state()
5416 btstack_run_loop_set_timer(&hci_stack->timeout, 1000); in hci_power_enter_halting_state()
5417 btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_halting_timeout_handler); in hci_power_enter_halting_state()
5418 btstack_run_loop_add_timer(&hci_stack->timeout); in hci_power_enter_halting_state()
5476 hci_stack->state = HCI_STATE_FALLING_ASLEEP; in hci_power_control_state_working()
5477 hci_stack->substate = HCI_FALLING_ASLEEP_DISCONNECT; in hci_power_control_state_working()
5496 hci_stack->state = HCI_STATE_FALLING_ASLEEP; in hci_power_control_state_halting()
5497 hci_stack->substate = HCI_FALLING_ASLEEP_DISCONNECT; in hci_power_control_state_halting()
5546 log_info("hci_power_control: %d, current mode %u", power_mode, hci_stack->state); in hci_power_control()
5547 btstack_run_loop_remove_timer(&hci_stack->timeout); in hci_power_control()
5549 switch (hci_stack->state){ in hci_power_control()
5588 log_info("HCI_STATE_HALTING, substate %x\n", hci_stack->substate); in hci_halting_run()
5597 switch (hci_stack->substate) { in hci_halting_run()
5602 if (hci_stack->connectable || hci_stack->discoverable){ in hci_halting_run()
5603 hci_stack->substate = HCI_HALTING_LE_ADV_STOP; in hci_halting_run()
5611 hci_stack->substate = HCI_HALTING_LE_ADV_STOP; in hci_halting_run()
5617 … stop_advertisements = (hci_stack->le_advertisements_state & LE_ADVERTISEMENT_STATE_ACTIVE) != 0; in hci_halting_run()
5623 btstack_linked_list_iterator_init(&it, &hci_stack->le_advertising_sets); in hci_halting_run()
5639 hci_stack->le_advertisements_state &= ~LE_ADVERTISEMENT_STATE_ACTIVE; in hci_halting_run()
5647 hci_stack->le_advertisements_state &= ~LE_ADVERTISEMENT_STATE_ACTIVE; in hci_halting_run()
5659 hci_stack->substate = HCI_HALTING_LE_SCAN_STOP; in hci_halting_run()
5664 if (hci_stack->le_scanning_active){ in hci_halting_run()
5666 hci_stack->substate = HCI_HALTING_DISCONNECT_ALL; in hci_halting_run()
5675 hci_stack->substate = HCI_HALTING_DISCONNECT_ALL; in hci_halting_run()
5679 connection = (hci_connection_t *) hci_stack->connections; in hci_halting_run()
5703 if (hci_stack->le_audio_bigs != NULL){ in hci_halting_run()
5704 le_audio_big_t * big = (le_audio_big_t*) hci_stack->le_audio_bigs; in hci_halting_run()
5710 if (hci_stack->le_audio_big_syncs != NULL){ in hci_halting_run()
5711 … le_audio_big_sync_t * big_sync = (le_audio_big_sync_t*) hci_stack->le_audio_big_syncs; in hci_halting_run()
5719 btstack_run_loop_remove_timer(&hci_stack->timeout); in hci_halting_run()
5723 hci_stack->substate = HCI_HALTING_W4_CLOSE_TIMER; in hci_halting_run()
5724 btstack_run_loop_set_timer(&hci_stack->timeout, 50); in hci_halting_run()
5725 btstack_run_loop_set_timer_handler(&hci_stack->timeout, hci_halting_timeout_handler); in hci_halting_run()
5726 btstack_run_loop_add_timer(&hci_stack->timeout); in hci_halting_run()
5735 hci_stack->substate = HCI_HALTING_CLOSE_DISCARDING_CONNECTIONS; in hci_halting_run()
5755 switch(hci_stack->substate) { in hci_falling_asleep_run()
5759 connection = (hci_connection_t *) hci_stack->connections; in hci_falling_asleep_run()
5778 …hci_send_cmd(&hci_write_scan_enable, hci_stack->connectable << 1); // drop inquiry scan but keep p… in hci_falling_asleep_run()
5781 hci_stack->substate = HCI_FALLING_ASLEEP_W4_WRITE_SCAN_ENABLE; in hci_falling_asleep_run()
5803 hci_stack->new_scan_enable_value = (hci_stack->connectable << 1) | hci_stack->discoverable; in hci_update_scan_enable()
5804 hci_stack->gap_tasks_classic |= GAP_TASK_WRITE_SCAN_ENABLE; in hci_update_scan_enable()
5811 if (hci_stack->discoverable == enable){ in gap_discoverable_control()
5812 hci_emit_scan_mode_changed(hci_stack->discoverable, hci_stack->connectable); in gap_discoverable_control()
5816 hci_stack->discoverable = enable; in gap_discoverable_control()
5824 if (hci_stack->connectable == enable) return; in gap_connectable_control()
5826 hci_stack->connectable = enable; in gap_connectable_control()
5832 (void)memcpy(address_buffer, hci_stack->local_bd_addr, 6); in gap_local_bd_addr()
5851 for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){ in hci_host_num_completed_packets()
5867 hci_stack->host_completed_packets = 0; in hci_host_num_completed_packets()
5870 hci_stack->hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, packet, size); in hci_host_num_completed_packets()
5882 hci_stack->substate = HCI_HALTING_CLOSE; in hci_halting_timeout_handler()
5887 if (hci_stack->acl_fragmentation_total_size > 0u) { in hci_run_acl_fragments()
5888 hci_con_handle_t con_handle = READ_ACL_CONNECTION_HANDLE(hci_stack->hci_packet_buffer); in hci_run_acl_fragments()
5898 hci_stack->acl_fragmentation_total_size = 0; in hci_run_acl_fragments()
5899 hci_stack->acl_fragmentation_pos = 0; in hci_run_acl_fragments()
5907 if (hci_stack->iso_fragmentation_total_size > 0u) { in hci_run_iso_fragments()
5922 if (hci_stack->inquiry_state >= GAP_INQUIRY_STATE_W4_ACTIVE){ in hci_classic_operation_active()
5925 if (hci_stack->remote_name_state == GAP_REMOTE_NAME_STATE_W4_COMPLETE){ in hci_classic_operation_active()
5929 for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL; it = it->next) { in hci_classic_operation_active()
5948 if (hci_stack->state != HCI_STATE_WORKING) return false; in hci_run_general_gap_classic()
5951 if (hci_stack->decline_reason){ in hci_run_general_gap_classic()
5952 uint8_t reason = hci_stack->decline_reason; in hci_run_general_gap_classic()
5953 hci_stack->decline_reason = 0; in hci_run_general_gap_classic()
5954 hci_send_cmd(&hci_reject_connection_request, hci_stack->decline_addr, reason); in hci_run_general_gap_classic()
5958 if (hci_stack->gap_tasks_classic != 0){ in hci_run_general_gap_classic()
5964 …if ((hci_stack->inquiry_state >= GAP_INQUIRY_DURATION_MIN) && (hci_stack->inquiry_state <= GAP_INQ… in hci_run_general_gap_classic()
5969 uint8_t duration = hci_stack->inquiry_state; in hci_run_general_gap_classic()
5970 hci_stack->inquiry_state = GAP_INQUIRY_STATE_W4_ACTIVE; in hci_run_general_gap_classic()
5971 if (hci_stack->inquiry_max_period_length != 0){ in hci_run_general_gap_classic()
5972 …d_cmd(&hci_periodic_inquiry_mode, hci_stack->inquiry_max_period_length, hci_stack->inquiry_min_per… in hci_run_general_gap_classic()
5974 hci_send_cmd(&hci_inquiry, hci_stack->inquiry_lap, duration, 0); in hci_run_general_gap_classic()
5979 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_W2_CANCEL){ in hci_run_general_gap_classic()
5980 hci_stack->inquiry_state = GAP_INQUIRY_STATE_W4_CANCELLED; in hci_run_general_gap_classic()
5985 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_W2_EXIT_PERIODIC){ in hci_run_general_gap_classic()
5986 hci_stack->inquiry_state = GAP_INQUIRY_STATE_W4_CANCELLED; in hci_run_general_gap_classic()
5992 if (hci_stack->remote_name_state == GAP_REMOTE_NAME_STATE_W2_SEND){ in hci_run_general_gap_classic()
5997 hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_W4_COMPLETE; in hci_run_general_gap_classic()
5998 hci_send_cmd(&hci_remote_name_request, hci_stack->remote_name_addr, in hci_run_general_gap_classic()
5999 … hci_stack->remote_name_page_scan_repetition_mode, 0, hci_stack->remote_name_clock_offset); in hci_run_general_gap_classic()
6005 if (hci_stack->classic_read_local_oob_data){ in hci_run_general_gap_classic()
6006 hci_stack->classic_read_local_oob_data = false; in hci_run_general_gap_classic()
6015 if (hci_stack->gap_pairing_state != GAP_PAIRING_STATE_IDLE){ in hci_run_general_gap_classic()
6016 uint8_t state = hci_stack->gap_pairing_state; in hci_run_general_gap_classic()
6020 hci_stack->gap_pairing_state = GAP_PAIRING_STATE_IDLE; in hci_run_general_gap_classic()
6022 … memcpy(pin_code, hci_stack->gap_pairing_input.gap_pairing_pin, hci_stack->gap_pairing_pin_len); in hci_run_general_gap_classic()
6023 …hci_send_cmd(&hci_pin_code_request_reply, hci_stack->gap_pairing_addr, hci_stack->gap_pairing_pin_… in hci_run_general_gap_classic()
6026 hci_stack->gap_pairing_state = GAP_PAIRING_STATE_WAIT_FOR_COMMAND_COMPLETE; in hci_run_general_gap_classic()
6027 hci_send_cmd(&hci_pin_code_request_negative_reply, hci_stack->gap_pairing_addr); in hci_run_general_gap_classic()
6030 hci_stack->gap_pairing_state = GAP_PAIRING_STATE_IDLE; in hci_run_general_gap_classic()
6031 …hci_send_cmd(&hci_user_passkey_request_reply, hci_stack->gap_pairing_addr, hci_stack->gap_pairing_… in hci_run_general_gap_classic()
6034 hci_stack->gap_pairing_state = GAP_PAIRING_STATE_WAIT_FOR_COMMAND_COMPLETE; in hci_run_general_gap_classic()
6035 hci_send_cmd(&hci_user_passkey_request_negative_reply, hci_stack->gap_pairing_addr); in hci_run_general_gap_classic()
6038 hci_stack->gap_pairing_state = GAP_PAIRING_STATE_IDLE; in hci_run_general_gap_classic()
6039 hci_send_cmd(&hci_user_confirmation_request_reply, hci_stack->gap_pairing_addr); in hci_run_general_gap_classic()
6042 hci_stack->gap_pairing_state = GAP_PAIRING_STATE_WAIT_FOR_COMMAND_COMPLETE; in hci_run_general_gap_classic()
6043 … hci_send_cmd(&hci_user_confirmation_request_negative_reply, hci_stack->gap_pairing_addr); in hci_run_general_gap_classic()
6091 uint8_t num_phys = hci_le_num_phys(hci_stack->le_connection_phys); in hci_send_le_create_connection()
6093 le_connection_scan_interval[i] = hci_stack->le_connection_scan_interval; in hci_send_le_create_connection()
6094 le_connection_scan_window[i] = hci_stack->le_connection_scan_window; in hci_send_le_create_connection()
6095 le_connection_interval_min[i] = hci_stack->le_connection_interval_min; in hci_send_le_create_connection()
6096 le_connection_interval_max[i] = hci_stack->le_connection_interval_max; in hci_send_le_create_connection()
6097 le_connection_latency[i] = hci_stack->le_connection_latency; in hci_send_le_create_connection()
6098 le_supervision_timeout[i] = hci_stack->le_supervision_timeout; in hci_send_le_create_connection()
6099 le_minimum_ce_length[i] = hci_stack->le_minimum_ce_length; in hci_send_le_create_connection()
6100 le_maximum_ce_length[i] = hci_stack->le_maximum_ce_length; in hci_send_le_create_connection()
6104 hci_stack->le_connection_own_addr_type, // our addr type: in hci_send_le_create_connection()
6107 hci_stack->le_connection_phys, // initiating PHY in hci_send_le_create_connection()
6121 hci_stack->le_connection_scan_interval, // conn scan interval in hci_send_le_create_connection()
6122 hci_stack->le_connection_scan_window, // conn scan windows in hci_send_le_create_connection()
6126 hci_stack->le_connection_own_addr_type, // our addr type: in hci_send_le_create_connection()
6127 hci_stack->le_connection_interval_min, // conn interval min in hci_send_le_create_connection()
6128 hci_stack->le_connection_interval_max, // conn interval max in hci_send_le_create_connection()
6129 hci_stack->le_connection_latency, // conn latency in hci_send_le_create_connection()
6130 hci_stack->le_supervision_timeout, // conn latency in hci_send_le_create_connection()
6131 hci_stack->le_minimum_ce_length, // min ce length in hci_send_le_create_connection()
6132 hci_stack->le_maximum_ce_length // max ce length in hci_send_le_create_connection()
6157 btstack_linked_list_iterator_init(&it, &hci_stack->le_whitelist); in hci_whitelist_modification_pending()
6170 btstack_linked_list_iterator_init(&it, &hci_stack->le_whitelist); in hci_whitelist_modification_process()
6181 … btstack_linked_list_remove(&hci_stack->le_whitelist, (btstack_linked_item_t *) entry); in hci_whitelist_modification_process()
6204 if (hci_stack->le_resolvable_private_address_update_s > 0){ in hci_run_general_gap_le()
6205 uint16_t update_s = hci_stack->le_resolvable_private_address_update_s; in hci_run_general_gap_le()
6206 hci_stack->le_resolvable_private_address_update_s = 0; in hci_run_general_gap_le()
6236 bool random_address_change = (hci_stack->le_advertisements_todo & address_change_mask) != 0; in hci_run_general_gap_le()
6245 if (resolving_list_supported && hci_stack->le_resolving_list_state != LE_RESOLVING_LIST_DONE){ in hci_run_general_gap_le()
6255 btstack_linked_list_iterator_init(&lit, &hci_stack->le_periodic_advertiser_list); in hci_run_general_gap_le()
6266 if (hci_stack->le_scanning_active) { in hci_run_general_gap_le()
6273 bool scanning_uses_whitelist = (hci_stack->le_scan_filter_policy & 1) == 1; in hci_run_general_gap_le()
6274 if ((hci_stack->le_scanning_param_update) || in hci_run_general_gap_le()
6275 !hci_stack->le_scanning_enabled || in hci_run_general_gap_le()
6286 switch (hci_stack->le_connecting_state){ in hci_run_general_gap_le()
6294 connecting_with_whitelist = hci_stack->le_connecting_state == LE_CONNECTING_WHITELIST; in hci_run_general_gap_le()
6296 (hci_stack->le_connecting_request == LE_CONNECTING_IDLE) || in hci_run_general_gap_le()
6311 switch(hci_stack->le_periodic_sync_state){ in hci_run_general_gap_le()
6317 … sync_with_advertiser_list = hci_stack->le_periodic_sync_state == LE_CONNECTING_WHITELIST; in hci_run_general_gap_le()
6319 (hci_stack->le_periodic_sync_request == LE_CONNECTING_IDLE)){ in hci_run_general_gap_le()
6333 if ((hci_stack->le_advertisements_state & LE_ADVERTISEMENT_STATE_ACTIVE) != 0){ in hci_run_general_gap_le()
6341 bool advertising_uses_whitelist = hci_stack->le_advertisements_filter_policy != 0; in hci_run_general_gap_le()
6342 … bool advertising_uses_random_address = hci_stack->le_own_addr_type != BD_ADDR_TYPE_LE_PUBLIC; in hci_run_general_gap_le()
6343 …bool advertising_change = (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_PARAM… in hci_run_general_gap_le()
6346 (hci_stack->le_advertisements_enabled_for_current_roles == 0) || in hci_run_general_gap_le()
6358 btstack_linked_list_iterator_init(&it, &hci_stack->le_advertising_sets); in hci_run_general_gap_le()
6427 hci_stack->le_scanning_active = false; in hci_run_general_gap_le()
6434 if (hci_stack->le_periodic_terminate_sync_handle != HCI_CON_HANDLE_INVALID){ in hci_run_general_gap_le()
6435 uint16_t sync_handle = hci_stack->le_periodic_terminate_sync_handle; in hci_run_general_gap_le()
6436 hci_stack->le_periodic_terminate_sync_handle = HCI_CON_HANDLE_INVALID; in hci_run_general_gap_le()
6442 hci_stack->le_periodic_sync_state = LE_CONNECTING_CANCEL; in hci_run_general_gap_le()
6461 hci_stack->le_advertisements_state &= ~LE_ADVERTISEMENT_STATE_ACTIVE; in hci_run_general_gap_le()
6470 hci_stack->le_advertisements_state &= ~LE_ADVERTISEMENT_STATE_ACTIVE; in hci_run_general_gap_le()
6489 if (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_PRIVACY_NOTIFY) { in hci_run_general_gap_le()
6490 hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_PRIVACY_NOTIFY; in hci_run_general_gap_le()
6492 hci_stack->le_advertisements_state |= LE_ADVERTISEMENT_STATE_PRIVACY_PENDING; in hci_run_general_gap_le()
6494 gap_privacy_clients_notify(hci_stack->le_random_address); in hci_run_general_gap_le()
6501 if ((hci_stack->le_advertisements_state & LE_ADVERTISEMENT_STATE_PRIVACY_PENDING) != 0){ in hci_run_general_gap_le()
6505 if (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_ADDRESS){ in hci_run_general_gap_le()
6506 hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_ADDRESS; in hci_run_general_gap_le()
6507 hci_send_cmd(&hci_le_set_random_address, hci_stack->le_random_address); in hci_run_general_gap_le()
6510 hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_PARAMS; in hci_run_general_gap_le()
6516 if (hci_stack->le_scanning_param_update){ in hci_run_general_gap_le()
6517 hci_stack->le_scanning_param_update = false; in hci_run_general_gap_le()
6526 uint8_t num_phys = hci_le_num_phys(hci_stack->le_scan_phys); in hci_run_general_gap_le()
6528 scan_types[i] = hci_stack->le_scan_type; in hci_run_general_gap_le()
6529 scan_intervals[i] = hci_stack->le_scan_interval; in hci_run_general_gap_le()
6530 scan_windows[i] = hci_stack->le_scan_window; in hci_run_general_gap_le()
6532 hci_send_cmd(&hci_le_set_extended_scan_parameters, hci_stack->le_own_addr_type, in hci_run_general_gap_le()
6533 …hci_stack->le_scan_filter_policy, hci_stack->le_scan_phys, scan_types, scan_intervals, scan_window… in hci_run_general_gap_le()
6537 …hci_send_cmd(&hci_le_set_scan_parameters, hci_stack->le_scan_type, hci_stack->le_scan_interval, hc… in hci_run_general_gap_le()
6538 hci_stack->le_own_addr_type, hci_stack->le_scan_filter_policy); in hci_run_general_gap_le()
6545 if (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_PARAMS){ in hci_run_general_gap_le()
6546 hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_PARAMS; in hci_run_general_gap_le()
6547 hci_stack->le_advertisements_own_addr_type = hci_stack->le_own_addr_type; in hci_run_general_gap_le()
6554 if (hci_stack->le_advertisements_type < (sizeof(mapping)/sizeof(uint16_t))){ in hci_run_general_gap_le()
6555 adv_event_properties = mapping[hci_stack->le_advertisements_type]; in hci_run_general_gap_le()
6557 hci_stack->le_advertising_set_in_current_command = 0; in hci_run_general_gap_le()
6561 hci_stack->le_advertisements_interval_min, in hci_run_general_gap_le()
6562 hci_stack->le_advertisements_interval_max, in hci_run_general_gap_le()
6563 hci_stack->le_advertisements_channel_map, in hci_run_general_gap_le()
6564 hci_stack->le_advertisements_own_addr_type, in hci_run_general_gap_le()
6565 hci_stack->le_advertisements_direct_address_type, in hci_run_general_gap_le()
6566 hci_stack->le_advertisements_direct_address, in hci_run_general_gap_le()
6567 hci_stack->le_advertisements_filter_policy, in hci_run_general_gap_le()
6579 hci_stack->le_advertisements_interval_min, in hci_run_general_gap_le()
6580 hci_stack->le_advertisements_interval_max, in hci_run_general_gap_le()
6581 hci_stack->le_advertisements_type, in hci_run_general_gap_le()
6582 hci_stack->le_advertisements_own_addr_type, in hci_run_general_gap_le()
6583 hci_stack->le_advertisements_direct_address_type, in hci_run_general_gap_le()
6584 hci_stack->le_advertisements_direct_address, in hci_run_general_gap_le()
6585 hci_stack->le_advertisements_channel_map, in hci_run_general_gap_le()
6586 hci_stack->le_advertisements_filter_policy); in hci_run_general_gap_le()
6593 if ((hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_ADDRESS_SET_0) != 0){ in hci_run_general_gap_le()
6594 hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_ADDRESS_SET_0; in hci_run_general_gap_le()
6595 hci_send_cmd(&hci_le_set_advertising_set_random_address, 0, hci_stack->le_random_address); in hci_run_general_gap_le()
6600 if (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_ADV_DATA){ in hci_run_general_gap_le()
6601 hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_ADV_DATA; in hci_run_general_gap_le()
6604 (void)memcpy(adv_data_clean, hci_stack->le_advertisements_data, in hci_run_general_gap_le()
6605 hci_stack->le_advertisements_data_len); in hci_run_general_gap_le()
6606 …btstack_replace_bd_addr_placeholder(adv_data_clean, hci_stack->le_advertisements_data_len, hci_sta… in hci_run_general_gap_le()
6609 hci_stack->le_advertising_set_in_current_command = 0; in hci_run_general_gap_le()
6610 …hci_send_cmd(&hci_le_set_extended_advertising_data, 0, 0x03, 0x01, hci_stack->le_advertisements_da… in hci_run_general_gap_le()
6614 … hci_send_cmd(&hci_le_set_advertising_data, hci_stack->le_advertisements_data_len, adv_data_clean); in hci_run_general_gap_le()
6619 if (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_SCAN_DATA){ in hci_run_general_gap_le()
6620 hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_SCAN_DATA; in hci_run_general_gap_le()
6623 (void)memcpy(scan_data_clean, hci_stack->le_scan_response_data, in hci_run_general_gap_le()
6624 hci_stack->le_scan_response_data_len); in hci_run_general_gap_le()
6625 …btstack_replace_bd_addr_placeholder(scan_data_clean, hci_stack->le_scan_response_data_len, hci_sta… in hci_run_general_gap_le()
6628 hci_stack->le_advertising_set_in_current_command = 0; in hci_run_general_gap_le()
6629 …hci_send_cmd(&hci_le_set_extended_scan_response_data, 0, 0x03, 0x01, hci_stack->le_scan_response_d… in hci_run_general_gap_le()
6633 …hci_send_cmd(&hci_le_set_scan_response_data, hci_stack->le_scan_response_data_len, scan_data_clean… in hci_run_general_gap_le()
6641 btstack_linked_list_iterator_init(&it, &hci_stack->le_advertising_sets); in hci_run_general_gap_le()
6646 … hci_stack->le_advertising_set_in_current_command = advertising_set->advertising_handle; in hci_run_general_gap_le()
6652 … hci_stack->le_advertising_set_in_current_command = advertising_set->advertising_handle; in hci_run_general_gap_le()
6689 … hci_stack->le_advertising_set_in_current_command = advertising_set->advertising_handle; in hci_run_general_gap_le()
6703 … hci_stack->le_advertising_set_in_current_command = advertising_set->advertising_handle; in hci_run_general_gap_le()
6710 … hci_stack->le_advertising_set_in_current_command = advertising_set->advertising_handle; in hci_run_general_gap_le()
6730 … hci_stack->le_advertising_set_in_current_command = advertising_set->advertising_handle; in hci_run_general_gap_le()
6743 if (hci_stack->le_connecting_state == LE_CONNECTING_CANCEL) return false; in hci_run_general_gap_le()
6746 if (hci_stack->le_periodic_sync_state == LE_CONNECTING_CANCEL) return false; in hci_run_general_gap_le()
6763 switch (hci_stack->le_resolving_list_state) { in hci_run_general_gap_le()
6765 hci_stack->le_resolving_list_state = LE_RESOLVING_LIST_READ_SIZE; in hci_run_general_gap_le()
6769 hci_stack->le_resolving_list_state = LE_RESOLVING_LIST_SEND_CLEAR; in hci_run_general_gap_le()
6773 hci_stack->le_resolving_list_state = LE_RESOLVING_LIST_SET_IRK; in hci_run_general_gap_le()
6774 (void) memset(hci_stack->le_resolving_list_add_entries, 0xff, in hci_run_general_gap_le()
6775 sizeof(hci_stack->le_resolving_list_add_entries)); in hci_run_general_gap_le()
6776 (void) memset(hci_stack->le_resolving_list_set_privacy_mode, 0xff, in hci_run_general_gap_le()
6777 sizeof(hci_stack->le_resolving_list_set_privacy_mode)); in hci_run_general_gap_le()
6778 (void) memset(hci_stack->le_resolving_list_remove_entries, 0, in hci_run_general_gap_le()
6779 sizeof(hci_stack->le_resolving_list_remove_entries)); in hci_run_general_gap_le()
6784 hci_stack->le_resolving_list_state = LE_RESOLVING_LIST_UPDATES_ENTRIES; in hci_run_general_gap_le()
6796 if ((hci_stack->le_resolving_list_remove_entries[offset] & mask) == 0) continue; in hci_run_general_gap_le()
6797 hci_stack->le_resolving_list_remove_entries[offset] &= ~mask; in hci_run_general_gap_le()
6806 btstack_linked_list_iterator_init(&lit, &hci_stack->le_whitelist); in hci_run_general_gap_le()
6825 if ((hci_stack->le_resolving_list_add_entries[offset] & mask) == 0) continue; in hci_run_general_gap_le()
6826 hci_stack->le_resolving_list_add_entries[offset] &= ~mask; in hci_run_general_gap_le()
6847 … if ((hci_stack->le_resolving_list_set_privacy_mode[offset] & mask) == 0) continue; in hci_run_general_gap_le()
6848 hci_stack->le_resolving_list_set_privacy_mode[offset] &= ~mask; in hci_run_general_gap_le()
6849 if (hci_stack->le_privacy_mode == LE_PRIVACY_MODE_NETWORK) { in hci_run_general_gap_le()
6862 …ci_le_set_privacy_mode, peer_identity_addr_type, peer_identity_address, hci_stack->le_privacy_mode… in hci_run_general_gap_le()
6870 hci_stack->le_resolving_list_state = LE_RESOLVING_LIST_DONE; in hci_run_general_gap_le()
6879 btstack_linked_list_iterator_init(&lit, &hci_stack->le_periodic_advertiser_list); in hci_run_general_gap_le()
6894 …btstack_linked_list_remove(&hci_stack->le_periodic_advertiser_list, (btstack_linked_item_t *) entr… in hci_run_general_gap_le()
6905 if (hci_stack->le_past_set_default_params){ in hci_run_general_gap_le()
6906 hci_stack->le_past_set_default_params = false; in hci_run_general_gap_le()
6908 hci_stack->le_past_mode, in hci_run_general_gap_le()
6909 hci_stack->le_past_skip, in hci_run_general_gap_le()
6910 hci_stack->le_past_sync_timeout, in hci_run_general_gap_le()
6911 hci_stack->le_past_cte_type); in hci_run_general_gap_le()
6919 if (hci_stack->state != HCI_STATE_WORKING) return false; in hci_run_general_gap_le()
6922 …if ( (hci_stack->le_own_addr_type != BD_ADDR_TYPE_LE_PUBLIC) && (hci_stack->le_random_address_set … in hci_run_general_gap_le()
6928 if ((hci_stack->le_scanning_enabled && !hci_stack->le_scanning_active)){ in hci_run_general_gap_le()
6929 hci_stack->le_scanning_active = true; in hci_run_general_gap_le()
6932 … hci_send_cmd(&hci_le_set_extended_scan_enable, 1, hci_stack->le_scan_filter_duplicates, 0, 0); in hci_run_general_gap_le()
6936 hci_send_cmd(&hci_le_set_scan_enable, 1, hci_stack->le_scan_filter_duplicates); in hci_run_general_gap_le()
6944 …if ( (hci_stack->le_connecting_state == LE_CONNECTING_IDLE) && (hci_stack->le_connecting_request =… in hci_run_general_gap_le()
6947 hci_stack->le_connection_own_addr_type = hci_stack->le_own_addr_type; in hci_run_general_gap_le()
6948 …hci_get_own_address_for_addr_type(hci_stack->le_connection_own_addr_type, hci_stack->le_connection… in hci_run_general_gap_le()
6953 if (hci_stack->le_periodic_sync_state == LE_CONNECTING_IDLE){ in hci_run_general_gap_le()
6954 switch(hci_stack->le_periodic_sync_request){ in hci_run_general_gap_le()
6957 …hci_stack->le_periodic_sync_state = ((hci_stack->le_periodic_sync_options & 1) != 0) ? LE_CONNECTI… in hci_run_general_gap_le()
6959 hci_stack->le_periodic_sync_options, in hci_run_general_gap_le()
6960 hci_stack->le_periodic_sync_advertising_sid, in hci_run_general_gap_le()
6961 hci_stack->le_periodic_sync_advertiser_address_type, in hci_run_general_gap_le()
6962 hci_stack->le_periodic_sync_advertiser_address, in hci_run_general_gap_le()
6963 hci_stack->le_periodic_sync_skip, in hci_run_general_gap_le()
6964 hci_stack->le_periodic_sync_timeout, in hci_run_general_gap_le()
6965 hci_stack->le_periodic_sync_cte_type); in hci_run_general_gap_le()
6976 …if (hci_stack->le_advertisements_enabled_for_current_roles && ((hci_stack->le_advertisements_state… in hci_run_general_gap_le()
6978 hci_stack->le_advertisements_state |= LE_ADVERTISEMENT_STATE_ACTIVE; in hci_run_general_gap_le()
6979 …hci_get_own_address_for_addr_type(hci_stack->le_advertisements_own_addr_type, hci_stack->le_advert… in hci_run_general_gap_le()
6998 btstack_linked_list_iterator_init(&it, &hci_stack->le_advertising_sets); in hci_run_general_gap_le()
7032 if (hci_stack->iso_active_operation_type != HCI_ISO_TYPE_INVALID) { in hci_run_iso_tasks()
7037 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_bigs); in hci_run_iso_tasks()
7042 hci_stack->iso_active_operation_group_id = big->params->big_handle; in hci_run_iso_tasks()
7043 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_BIS; in hci_run_iso_tasks()
7077 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_big_syncs); in hci_run_iso_tasks()
7082 hci_stack->iso_active_operation_group_id = big_sync->params->big_handle; in hci_run_iso_tasks()
7083 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_BIS; in hci_run_iso_tasks()
7114 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_cigs); in hci_run_iso_tasks()
7128 hci_stack->iso_active_operation_group_id = cig->params->cig_id; in hci_run_iso_tasks()
7129 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_CIS; in hci_run_iso_tasks()
7162 hci_stack->iso_active_operation_group_id = cig->params->cig_id; in hci_run_iso_tasks()
7163 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_CIS; in hci_run_iso_tasks()
7189 hci_stack->iso_active_operation_group_id = cig->params->cig_id; in hci_run_iso_tasks()
7190 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_CIS; in hci_run_iso_tasks()
7221 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in hci_run_iso_tasks()
7228 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_CIS; in hci_run_iso_tasks()
7229 hci_stack->iso_active_operation_group_id = HCI_ISO_GROUP_ID_SINGLE_CIS; in hci_run_iso_tasks()
7234 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_CIS; in hci_run_iso_tasks()
7235 hci_stack->iso_active_operation_group_id = HCI_ISO_GROUP_ID_SINGLE_CIS; in hci_run_iso_tasks()
7240 hci_stack->iso_active_operation_group_id = HCI_ISO_GROUP_ID_SINGLE_CIS; in hci_run_iso_tasks()
7241 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_CIS; in hci_run_iso_tasks()
7246 hci_stack->iso_active_operation_group_id = HCI_ISO_GROUP_ID_SINGLE_CIS; in hci_run_iso_tasks()
7247 hci_stack->iso_active_operation_type = HCI_ISO_TYPE_CIS; in hci_run_iso_tasks()
7267 for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL; it = it->next){ in hci_run_general_pending_commands()
7276 …onnection, connection->address, hci_usable_acl_packet_types(), 0, 0, 0, hci_stack->allow_role_swit… in hci_run_general_pending_commands()
7283 hci_stack->le_connection_own_addr_type = hci_stack->le_own_addr_type; in hci_run_general_pending_commands()
7284 …hci_get_own_address_for_addr_type(hci_stack->le_connection_own_addr_type, hci_stack->le_connection… in hci_run_general_pending_commands()
7298 … hci_send_cmd(&hci_accept_connection_request, connection->address, hci_stack->master_slave_policy); in hci_run_general_pending_commands()
7319 … log_info("responding to link key request, have link key db: %u", hci_stack->link_key_db != NULL); in hci_run_general_pending_commands()
7351 connection->io_cap_request_auth_req = hci_stack->ssp_authentication_requirement & 1; in hci_run_general_pending_commands()
7355 bool bonding = hci_stack->bondable; in hci_run_general_pending_commands()
7380 …hci_send_cmd(&hci_io_capability_request_reply, &connection->address, hci_stack->ssp_io_capability,… in hci_run_general_pending_commands()
7414 …bool need_level_4 = hci_stack->gap_secure_connections_only_mode || (connection->requested_security… in hci_run_general_pending_commands()
7430 hci_stack->classic_oob_con_handle = connection->con_handle; in hci_run_general_pending_commands()
7555 …hci_send_cmd(&hci_write_automatic_flush_timeout, connection->con_handle, hci_stack->automatic_flus… in hci_run_general_pending_commands()
7560 …hci_send_cmd(&hci_write_link_supervision_timeout, connection->con_handle, hci_stack->link_supervis… in hci_run_general_pending_commands()
7585 hci_stack->le_minimum_ce_length, hci_stack->le_maximum_ce_length); in hci_run_general_pending_commands()
7591 hci_stack->le_minimum_ce_length, hci_stack->le_maximum_ce_length); in hci_run_general_pending_commands()
7636 switch (hci_stack->state) { in hci_run()
7651 if (hci_stack->state != HCI_STATE_WORKING){ in hci_run()
7669 if (hci_stack->host_completed_packets){ in hci_run()
7708 … packet_types &= hci_connection->remote_supported_sco_packets & hci_stack->usable_packet_types_sco; in hci_set_sco_payload_length_for_flipped_packet_types()
7716 btstack_assert(hci_stack->hci_packet_buffer_reserved); in hci_send_prepared_cmd_packet()
7718 hci_stack->last_cmd_opcode = little_endian_read_16(hci_stack->hci_packet_buffer, 0); in hci_send_prepared_cmd_packet()
7720 uint16_t size = 3u + hci_stack->hci_packet_buffer[2u]; in hci_send_prepared_cmd_packet()
7722 uint8_t status = hci_send_cmd_packet(hci_stack->hci_packet_buffer, size); in hci_send_prepared_cmd_packet()
7744 hci_stack->loopback_mode = packet[3]; in hci_send_cmd_packet()
7753 if (memcmp(hci_stack->local_bd_addr, addr, 6) == 0) { in hci_send_cmd_packet()
7797 hci_stack->outgoing_addr_type = BD_ADDR_TYPE_ACL; in hci_send_cmd_packet()
7798 (void) memcpy(hci_stack->outgoing_addr, addr, 6); in hci_send_cmd_packet()
7838 hci_stack->outgoing_addr_type = BD_ADDR_TYPE_SCO; in hci_send_cmd_packet()
7839 (void) memcpy(hci_stack->outgoing_addr, conn->address, 6); in hci_send_cmd_packet()
7843 hci_stack->sco_voice_setting_active = little_endian_read_16(packet, 15); in hci_send_cmd_packet()
7860 hci_stack->outgoing_addr_type = BD_ADDR_TYPE_SCO; in hci_send_cmd_packet()
7861 (void) memcpy(hci_stack->outgoing_addr, addr, 6); in hci_send_cmd_packet()
7865 hci_stack->sco_voice_setting_active = little_endian_read_16(packet, 19); in hci_send_cmd_packet()
7880 hci_stack->le_connecting_state = LE_CONNECTING_DIRECT; in hci_send_cmd_packet()
7883 hci_stack->le_connecting_state = LE_CONNECTING_WHITELIST; in hci_send_cmd_packet()
7890 hci_stack->outgoing_addr_type = (bd_addr_type_t) packet[8]; // peer address type in hci_send_cmd_packet()
7891 reverse_bd_addr( &packet[9], hci_stack->outgoing_addr); // peer address in hci_send_cmd_packet()
7900 hci_stack->le_connecting_state = LE_CONNECTING_DIRECT; in hci_send_cmd_packet()
7903 hci_stack->le_connecting_state = LE_CONNECTING_WHITELIST; in hci_send_cmd_packet()
7910 hci_stack->outgoing_addr_type = (bd_addr_type_t) packet[5]; // peer address type in hci_send_cmd_packet()
7911 reverse_bd_addr( &packet[6], hci_stack->outgoing_addr); // peer address in hci_send_cmd_packet()
7915 hci_stack->le_connecting_state = LE_CONNECTING_CANCEL; in hci_send_cmd_packet()
7930 hci_stack->hci_command_con_handle = little_endian_read_16(packet, 3); in hci_send_cmd_packet()
7938 hci_stack->num_cmd_packets--; in hci_send_cmd_packet()
7941 int err = hci_stack->hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, packet, size); in hci_send_cmd_packet()
7965 hci_stack->ssp_enable = enable; in gap_ssp_set_enable()
7969 return gap_ssp_supported() && hci_stack->ssp_enable; in hci_local_ssp_activated()
7974 hci_stack->ssp_io_capability = io_capability; in gap_ssp_set_io_capability()
7977 hci_stack->ssp_authentication_requirement = authentication_requirement; in gap_ssp_set_authentication_requirement()
7982 hci_stack->ssp_auto_accept = auto_accept; in gap_ssp_set_auto_accept()
7986 hci_stack->secure_connections_enable = enable; in gap_secure_connections_enable()
7989 return hci_stack->secure_connections_active; in gap_secure_connections_active()
8002 hci_cmd_create_from_template(hci_stack->hci_packet_buffer, cmd, argptr); in hci_send_cmd_va_arg()
8027 btstack_linked_list_iterator_init(&it, &hci_stack->event_handlers); in hci_emit_event()
8042 if (!hci_stack->acl_packet_handler) return; in hci_emit_acl_packet()
8043 hci_stack->acl_packet_handler(HCI_ACL_DATA_PACKET, 0, packet, size); in hci_emit_acl_packet()
8049 if (!hci_stack->sco_waiting_for_can_send_now) return; in hci_notify_if_sco_can_send_now()
8051 hci_stack->sco_waiting_for_can_send_now = 0; in hci_notify_if_sco_can_send_now()
8054 hci_stack->sco_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event)); in hci_notify_if_sco_can_send_now()
8159 log_info("BTSTACK_EVENT_STATE %u", hci_stack->state); in hci_emit_state()
8163 event[2] = hci_stack->state; in hci_emit_state()
8279 … if (connection->encryption_key_size < hci_stack->gap_required_encyrption_key_size) return LEVEL_0; in gap_security_level_for_connection()
8358 hci_stack->bondable = enable ? 1 : 0; in gap_set_bondable_mode()
8365 return hci_stack->bondable; in gap_get_bondable_mode()
8438 if (hci_stack->gap_secure_connections_only_mode && (requested_level != LEVEL_0)){ in gap_request_security_level()
8518 hci_stack->local_name = local_name; in gap_set_local_name()
8519 hci_stack->gap_tasks_classic |= GAP_TASK_SET_LOCAL_NAME; in gap_set_local_name()
8521 if (hci_stack->eir_data == NULL){ in gap_set_local_name()
8522 hci_stack->gap_tasks_classic |= GAP_TASK_SET_EIR_DATA; in gap_set_local_name()
8533 hci_stack->le_scanning_enabled = true; in gap_start_scan()
8538 hci_stack->le_scanning_enabled = false; in gap_stop_scan()
8543 hci_stack->le_scan_type = scan_type; in gap_set_scan_params()
8544 hci_stack->le_scan_filter_policy = scanning_filter_policy; in gap_set_scan_params()
8545 hci_stack->le_scan_interval = scan_interval; in gap_set_scan_params()
8546 hci_stack->le_scan_window = scan_window; in gap_set_scan_params()
8547 hci_stack->le_scanning_param_update = true; in gap_set_scan_params()
8556 hci_stack->le_scan_filter_duplicates = enabled ? 1 : 0; in gap_set_scan_duplicate_filter()
8561 hci_stack->le_scan_phys = phys & 0x05; in gap_set_scan_phys()
8566 …if (hci_is_le_connection_type(addr_type) && hci_stack->le_connecting_request != LE_CONNECTING_IDLE… in gap_connect()
8592 hci_stack->le_connecting_request = LE_CONNECTING_DIRECT; in gap_connect()
8605 for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL; it = it->next){ in gap_get_outgoing_le_connection()
8622 switch (hci_stack->le_connecting_request){ in gap_connect_cancel()
8626 hci_stack->le_connecting_request = LE_CONNECTING_IDLE; in gap_connect_cancel()
8630 hci_stack->le_connecting_request = LE_CONNECTING_IDLE; in gap_connect_cancel()
8639 … btstack_linked_list_remove(&hci_stack->connections, (btstack_linked_item_t *) conn); in gap_connect_cancel()
8672 hci_stack->le_connection_phys = phys & 7; in gap_set_connection_phys()
8680 hci_stack->le_connection_scan_interval = conn_scan_interval; in gap_set_connection_parameters()
8681 hci_stack->le_connection_scan_window = conn_scan_window; in gap_set_connection_parameters()
8682 hci_stack->le_connection_interval_min = conn_interval_min; in gap_set_connection_parameters()
8683 hci_stack->le_connection_interval_max = conn_interval_max; in gap_set_connection_parameters()
8684 hci_stack->le_connection_latency = conn_latency; in gap_set_connection_parameters()
8685 hci_stack->le_supervision_timeout = supervision_timeout; in gap_set_connection_parameters()
8686 hci_stack->le_minimum_ce_length = min_ce_length; in gap_set_connection_parameters()
8687 hci_stack->le_maximum_ce_length = max_ce_length; in gap_set_connection_parameters()
8754 if ((hci_stack->le_advertisements_state & LE_ADVERTISEMENT_STATE_PARAMS_SET) == 0){ in hci_assert_advertisement_set_0_ready()
8755 hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_PARAMS; in hci_assert_advertisement_set_0_ready()
8767 hci_stack->le_advertisements_data_len = advertising_data_length; in gap_advertisements_set_data()
8768 hci_stack->le_advertisements_data = advertising_data; in gap_advertisements_set_data()
8769 hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_ADV_DATA; in gap_advertisements_set_data()
8783 hci_stack->le_scan_response_data_len = scan_response_data_length; in gap_scan_response_set_data()
8784 hci_stack->le_scan_response_data = scan_response_data; in gap_scan_response_set_data()
8785 hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_SCAN_DATA; in gap_scan_response_set_data()
8808 hci_stack->le_advertisements_interval_min = adv_int_min; in hci_le_advertisements_set_params()
8809 hci_stack->le_advertisements_interval_max = adv_int_max; in hci_le_advertisements_set_params()
8810 hci_stack->le_advertisements_type = adv_type; in hci_le_advertisements_set_params()
8811 hci_stack->le_advertisements_direct_address_type = direct_address_typ; in hci_le_advertisements_set_params()
8812 hci_stack->le_advertisements_channel_map = channel_map; in hci_le_advertisements_set_params()
8813 hci_stack->le_advertisements_filter_policy = filter_policy; in hci_le_advertisements_set_params()
8814 (void)memcpy(hci_stack->le_advertisements_direct_address, direct_address, in hci_le_advertisements_set_params()
8817 hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_PARAMS; in hci_le_advertisements_set_params()
8818 hci_stack->le_advertisements_state |= LE_ADVERTISEMENT_STATE_PARAMS_SET; in hci_le_advertisements_set_params()
8828 hci_stack->le_advertisements_state &= ~LE_ADVERTISEMENT_STATE_ENABLED; in gap_advertisements_enable()
8830 hci_stack->le_advertisements_state |= LE_ADVERTISEMENT_STATE_ENABLED; in gap_advertisements_enable()
8839 btstack_linked_list_iterator_init(&it, &hci_stack->le_advertising_sets); in hci_advertising_set_for_handle()
8850 hci_stack->le_resolvable_private_address_update_s = update_s; in gap_extended_advertising_set_resolvable_private_address_update()
8868 …bool add_ok = btstack_linked_list_add(&hci_stack->le_advertising_sets, (btstack_linked_item_t *) s… in gap_extended_advertising_setup()
9007 hci_stack->le_past_mode = mode; in gap_periodic_advertising_sync_transfer_set_default_parameters()
9008 hci_stack->le_past_skip = skip; in gap_periodic_advertising_sync_transfer_set_default_parameters()
9009 hci_stack->le_past_sync_timeout = sync_timeout; in gap_periodic_advertising_sync_transfer_set_default_parameters()
9010 hci_stack->le_past_cte_type = cte_type; in gap_periodic_advertising_sync_transfer_set_default_parameters()
9011 hci_stack->le_past_set_default_params = true; in gap_periodic_advertising_sync_transfer_set_default_parameters()
9046 …log_info("hci_le_set_own_address_type: old %u, new %u", hci_stack->le_own_addr_type, own_address_t… in hci_le_set_own_address_type()
9047 if (own_address_type == hci_stack->le_own_addr_type) return; in hci_le_set_own_address_type()
9048 hci_stack->le_own_addr_type = own_address_type; in hci_le_set_own_address_type()
9052 hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_PARAMS; in hci_le_set_own_address_type()
9062 memcpy(hci_stack->le_random_address, random_address, 6); in hci_le_random_address_set()
9063 hci_stack->le_random_address_set = true; in hci_le_random_address_set()
9064 …hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_ADDRESS | LE_ADVERTISEMENT_TASKS_P… in hci_le_random_address_set()
9068 hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_SET_ADDRESS_SET_0; in hci_le_random_address_set()
9176 btstack_linked_list_iterator_init(&it, &hci_stack->le_whitelist); in hci_whitelist_add()
9208 btstack_linked_list_add(&hci_stack->le_whitelist, (btstack_linked_item_t*) entry); in hci_whitelist_add()
9214 btstack_linked_list_iterator_init(&it, &hci_stack->le_whitelist); in hci_whitelist_remove()
9238 btstack_linked_list_iterator_init(&it, &hci_stack->le_whitelist); in hci_whitelist_clear()
9299 if (hci_stack->le_connecting_request != LE_CONNECTING_IDLE){ in gap_connect_with_whitelist()
9302 hci_stack->le_connecting_request = LE_CONNECTING_WHITELIST; in gap_connect_with_whitelist()
9314 if (hci_stack->le_connecting_request == LE_CONNECTING_DIRECT){ in gap_auto_connection_start()
9323 hci_stack->le_connecting_request = LE_CONNECTING_WHITELIST; in gap_auto_connection_start()
9336 if (hci_stack->le_connecting_request == LE_CONNECTING_DIRECT){ in gap_auto_connection_stop()
9341 if (btstack_linked_list_empty(&hci_stack->le_whitelist)){ in gap_auto_connection_stop()
9342 hci_stack->le_connecting_request = LE_CONNECTING_IDLE; in gap_auto_connection_stop()
9353 if (hci_stack->le_connecting_request == LE_CONNECTING_DIRECT) { in gap_auto_connection_stop_all()
9357 hci_stack->le_connecting_request = LE_CONNECTING_IDLE; in gap_auto_connection_stop_all()
9377 hci_stack->eir_data = data; in gap_set_extended_inquiry_response()
9378 hci_stack->gap_tasks_classic |= GAP_TASK_SET_EIR_DATA; in gap_set_extended_inquiry_response()
9389 if (hci_stack->state != HCI_STATE_WORKING) return ERROR_CODE_COMMAND_DISALLOWED; in gap_inquiry_start()
9390 if (hci_stack->inquiry_state != GAP_INQUIRY_STATE_IDLE) return ERROR_CODE_COMMAND_DISALLOWED; in gap_inquiry_start()
9394 hci_stack->inquiry_state = duration_in_1280ms_units; in gap_inquiry_start()
9395 hci_stack->inquiry_max_period_length = 0; in gap_inquiry_start()
9396 hci_stack->inquiry_min_period_length = 0; in gap_inquiry_start()
9402 if (hci_stack->state != HCI_STATE_WORKING) return ERROR_CODE_COMMAND_DISALLOWED; in gap_inquiry_periodic_start()
9403 if (hci_stack->inquiry_state != GAP_INQUIRY_STATE_IDLE) return ERROR_CODE_COMMAND_DISALLOWED; in gap_inquiry_periodic_start()
9409 hci_stack->inquiry_state = duration; in gap_inquiry_periodic_start()
9410 hci_stack->inquiry_max_period_length = max_period_length; in gap_inquiry_periodic_start()
9411 hci_stack->inquiry_min_period_length = min_period_length; in gap_inquiry_periodic_start()
9421 …if ((hci_stack->inquiry_state >= GAP_INQUIRY_DURATION_MIN) && (hci_stack->inquiry_state <= GAP_INQ… in gap_inquiry_stop()
9427 switch (hci_stack->inquiry_state){ in gap_inquiry_stop()
9429 hci_stack->inquiry_state = GAP_INQUIRY_STATE_W2_CANCEL; in gap_inquiry_stop()
9433 hci_stack->inquiry_state = GAP_INQUIRY_STATE_W2_EXIT_PERIODIC; in gap_inquiry_stop()
9442 hci_stack->inquiry_lap = lap; in gap_inquiry_set_lap()
9446 hci_stack->inquiry_scan_interval = inquiry_scan_interval; in gap_inquiry_set_scan_activity()
9447 hci_stack->inquiry_scan_window = inquiry_scan_window; in gap_inquiry_set_scan_activity()
9448 hci_stack->gap_tasks_classic |= GAP_TASK_WRITE_INQUIRY_SCAN_ACTIVITY; in gap_inquiry_set_scan_activity()
9454 hci_stack->inquiry_tx_power_level = tx_power; in gap_inquiry_set_transmit_power_level()
9455 hci_stack->gap_tasks_classic |= GAP_TASK_WRITE_INQUIRY_TX_POWER_LEVEL; in gap_inquiry_set_transmit_power_level()
9468 …if (hci_stack->remote_name_state != GAP_REMOTE_NAME_STATE_IDLE) return ERROR_CODE_COMMAND_DISALLOW… in gap_remote_name_request()
9469 (void)memcpy(hci_stack->remote_name_addr, addr, 6); in gap_remote_name_request()
9470 hci_stack->remote_name_page_scan_repetition_mode = page_scan_repetition_mode; in gap_remote_name_request()
9471 hci_stack->remote_name_clock_offset = clock_offset; in gap_remote_name_request()
9472 hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_W2_SEND; in gap_remote_name_request()
9478 hci_stack->gap_pairing_state = state; in gap_pairing_set_state_and_run()
9479 (void)memcpy(hci_stack->gap_pairing_addr, addr, 6); in gap_pairing_set_state_and_run()
9492 … if (hci_stack->gap_pairing_state != GAP_PAIRING_STATE_IDLE) return ERROR_CODE_COMMAND_DISALLOWED; in gap_pin_code_response_binary()
9494 hci_stack->gap_pairing_input.gap_pairing_pin = pin_data; in gap_pin_code_response_binary()
9495 hci_stack->gap_pairing_pin_len = pin_len; in gap_pin_code_response_binary()
9516 … if (hci_stack->gap_pairing_state != GAP_PAIRING_STATE_IDLE) return ERROR_CODE_COMMAND_DISALLOWED; in gap_pin_code_negative()
9527 … if (hci_stack->gap_pairing_state != GAP_PAIRING_STATE_IDLE) return ERROR_CODE_COMMAND_DISALLOWED; in gap_ssp_passkey_response()
9528 hci_stack->gap_pairing_input.gap_pairing_passkey = passkey; in gap_ssp_passkey_response()
9539 … if (hci_stack->gap_pairing_state != GAP_PAIRING_STATE_IDLE) return ERROR_CODE_COMMAND_DISALLOWED; in gap_ssp_passkey_negative()
9550 … if (hci_stack->gap_pairing_state != GAP_PAIRING_STATE_IDLE) return ERROR_CODE_COMMAND_DISALLOWED; in gap_ssp_confirmation_response()
9561 … if (hci_stack->gap_pairing_state != GAP_PAIRING_STATE_IDLE) return ERROR_CODE_COMMAND_DISALLOWED; in gap_ssp_confirmation_negative()
9603 if (hci_stack->secure_connections_active){ in gap_ssp_remote_oob_data()
9615 hci_stack->classic_read_local_oob_data = true; in gap_ssp_generate_oob_data()
9640 hci_stack->inquiry_mode = inquiry_mode; in hci_set_inquiry_mode()
9647 hci_stack->sco_voice_setting = voice_setting; in hci_set_sco_voice_setting()
9655 return hci_stack->sco_voice_setting; in hci_get_sco_voice_setting()
9659 if (!hci_stack->hci_transport) return 0; in hci_have_usb_transport()
9660 const char * transport_name = hci_stack->hci_transport->name; in hci_have_usb_transport()
9671 if (((hci_stack->sco_voice_setting_active & 0x03) != 0x03) && in hci_sco_packet_length_for_payload_length()
9672 ((hci_stack->sco_voice_setting_active & 0x20) == 0x20)) { in hci_sco_packet_length_for_payload_length()
9689 if (sco_packet_length > (hci_stack->sco_data_packet_length + 3)){ in hci_sco_packet_length_for_payload_length()
9690 sco_packet_length = 3 + hci_stack->sco_data_packet_length; in hci_sco_packet_length_for_payload_length()
9698 if (sco_packet_length > (hci_stack->sco_data_packet_length + 3)){ in hci_sco_packet_length_for_payload_length()
9699 sco_packet_length = 3 + hci_stack->sco_data_packet_length; in hci_sco_packet_length_for_payload_length()
9715 btstack_linked_list_iterator_init(&it, &hci_stack->connections); in hci_get_sco_packet_length()
9730 hci_stack->master_slave_policy = policy; in hci_set_master_slave_policy()
9736 return hci_stack->state; in hci_get_state()
9741 hci_stack->gap_classic_accept_callback = accept_callback; in gap_register_classic_connection_filter()
9749 hci_stack->hardware_error_callback = fn; in hci_set_hardware_error_callback()
9754 btstack_linked_list_iterator_init(&it, &hci_stack->connections); in hci_disconnect_all()
9764 return hci_stack->manufacturer; in hci_get_manufacturer()
9863 …return hci_stack->link_key_db && hci_stack->link_key_db->get_link_key(hci_connection->address, lin… in gap_bonded()
9928 hci_stack->new_page_scan_interval = page_scan_interval; in gap_set_page_scan_activity()
9929 hci_stack->new_page_scan_window = page_scan_window; in gap_set_page_scan_activity()
9930 hci_stack->gap_tasks_classic |= GAP_TASK_WRITE_PAGE_SCAN_ACTIVITY; in gap_set_page_scan_activity()
9935 hci_stack->new_page_scan_type = (uint8_t) page_scan_type; in gap_set_page_scan_type()
9936 hci_stack->gap_tasks_classic |= GAP_TASK_WRITE_PAGE_SCAN_TYPE; in gap_set_page_scan_type()
9941 hci_stack->page_timeout = page_timeout; in gap_set_page_timeout()
9942 hci_stack->gap_tasks_classic |= GAP_TASK_WRITE_PAGE_TIMEOUT; in gap_set_page_timeout()
9954 hci_stack->le_resolving_list_add_entries[offset] |= mask; in hci_load_le_device_db_entry_into_resolving_list()
9955 hci_stack->le_resolving_list_set_privacy_mode[offset] |= mask; in hci_load_le_device_db_entry_into_resolving_list()
9956 if (hci_stack->le_resolving_list_state == LE_RESOLVING_LIST_DONE){ in hci_load_le_device_db_entry_into_resolving_list()
9958 hci_stack->le_resolving_list_state = LE_RESOLVING_LIST_UPDATES_ENTRIES; in hci_load_le_device_db_entry_into_resolving_list()
9967 hci_stack->le_resolving_list_remove_entries[offset] |= mask; in hci_remove_le_device_db_entry_from_resolving_list()
9968 if (hci_stack->le_resolving_list_state == LE_RESOLVING_LIST_DONE){ in hci_remove_le_device_db_entry_from_resolving_list()
9969 hci_stack->le_resolving_list_state = LE_RESOLVING_LIST_UPDATES_ENTRIES; in hci_remove_le_device_db_entry_from_resolving_list()
9977 if (hci_stack->le_resolving_list_state != LE_RESOLVING_LIST_SEND_ENABLE_ADDRESS_RESOLUTION){ in gap_load_resolving_list_from_le_device_db()
9979 hci_stack->le_resolving_list_state = LE_RESOLVING_LIST_READ_SIZE; in gap_load_resolving_list_from_le_device_db()
9985 hci_stack->le_privacy_mode = privacy_mode; in gap_set_peer_privacy_mode()
10004 btstack_linked_list_iterator_init(&it, &hci_stack->le_periodic_advertiser_list); in hci_periodic_advertiser_list_add()
10031 … btstack_linked_list_add(&hci_stack->le_periodic_advertiser_list, (btstack_linked_item_t*) entry); in hci_periodic_advertiser_list_add()
10037 btstack_linked_list_iterator_init(&it, &hci_stack->le_periodic_advertiser_list); in hci_periodic_advertiser_list_remove()
10064 btstack_linked_list_iterator_init(&it, &hci_stack->le_periodic_advertiser_list); in hci_periodic_advertiser_list_clear()
10105 if (hci_stack->le_periodic_sync_request != LE_CONNECTING_IDLE) { in gap_periodic_advertising_create_sync()
10109 …hci_stack->le_periodic_sync_request = ((options & 0) != 0) ? LE_CONNECTING_WHITELIST : LE_CONNECTI… in gap_periodic_advertising_create_sync()
10110 hci_stack->le_periodic_sync_options = options; in gap_periodic_advertising_create_sync()
10111 hci_stack->le_periodic_sync_advertising_sid = advertising_sid; in gap_periodic_advertising_create_sync()
10112 hci_stack->le_periodic_sync_advertiser_address_type = advertiser_address_type; in gap_periodic_advertising_create_sync()
10113 memcpy(hci_stack->le_periodic_sync_advertiser_address, advertiser_address, 6); in gap_periodic_advertising_create_sync()
10114 hci_stack->le_periodic_sync_skip = skip; in gap_periodic_advertising_create_sync()
10115 hci_stack->le_periodic_sync_timeout = sync_timeout; in gap_periodic_advertising_create_sync()
10116 hci_stack->le_periodic_sync_cte_type = sync_cte_type; in gap_periodic_advertising_create_sync()
10124 if (hci_stack->le_periodic_sync_request == LE_CONNECTING_IDLE) { in gap_periodic_advertising_create_sync_cancel()
10127 hci_stack->le_periodic_sync_request = LE_CONNECTING_IDLE; in gap_periodic_advertising_create_sync_cancel()
10133 if (hci_stack->le_periodic_terminate_sync_handle != HCI_CON_HANDLE_INVALID){ in gap_periodic_advertising_terminate_sync()
10136 hci_stack->le_periodic_terminate_sync_handle = sync_handle; in gap_periodic_advertising_terminate_sync()
10154 btstack_linked_list_add(&hci_stack->iso_streams, (btstack_linked_item_t*) iso_stream); in hci_iso_stream_create()
10161 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in hci_iso_stream_for_con_handle()
10173 btstack_linked_list_remove(&hci_stack->iso_streams, (btstack_linked_item_t*) iso_stream); in hci_iso_stream_finalize()
10179 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in hci_iso_stream_finalize_by_type_and_group_id()
10192 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in hci_iso_stream_requested_finalize()
10207 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in hci_iso_stream_requested_confirm()
10229 if (hci_stack->iso_packet_handler == NULL) { in hci_iso_packet_handler()
10247 (hci_stack->iso_packet_handler)(HCI_ISO_DATA_PACKET, 0, packet, size); in hci_iso_packet_handler()
10283 …(hci_stack->iso_packet_handler)(HCI_ISO_DATA_PACKET, 0, iso_stream->reassembly_buffer, iso_stream-… in hci_iso_packet_handler()
10418 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_bigs); in hci_big_for_handle()
10430 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_big_syncs); in hci_big_sync_for_handle()
10441 hci_stack->iso_packets_to_queue = num_packets; in hci_set_num_iso_packets_to_queue()
10446 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_cigs); in hci_cig_for_id()
10461 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_bigs); in hci_iso_notify_can_send_now()
10505 …if ((iso_stream->num_packets_sent >= hci_stack->iso_packets_to_queue) || (iso_stream->emit_ready_… in hci_iso_notify_can_send_now()
10521 if (hci_stack->hci_packet_buffer_reserved) return; in hci_iso_notify_can_send_now()
10523 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_bigs); in hci_iso_notify_can_send_now()
10533 if (hci_stack->hci_packet_buffer_reserved) return; in hci_iso_notify_can_send_now()
10540 btstack_linked_list_iterator_init(&it, &hci_stack->iso_streams); in hci_iso_notify_can_send_now()
10544 (iso_stream->num_packets_sent < hci_stack->iso_packets_to_queue)){ in hci_iso_notify_can_send_now()
10547 if (hci_stack->hci_packet_buffer_reserved) return; in hci_iso_notify_can_send_now()
10597 btstack_linked_list_add(&hci_stack->le_audio_bigs, (btstack_linked_item_t *) big); in gap_big_create()
10615 btstack_linked_list_add(&hci_stack->le_audio_big_syncs, (btstack_linked_item_t *) big_sync); in gap_big_sync_create()
10629 btstack_linked_list_remove(&hci_stack->le_audio_bigs, (btstack_linked_item_t *) big); in gap_big_terminate()
10654 … btstack_linked_list_remove(&hci_stack->le_audio_big_syncs, (btstack_linked_item_t *) big_sync); in gap_big_sync_terminate()
10737 btstack_linked_list_add(&hci_stack->le_audio_cigs, (btstack_linked_item_t *) cig); in gap_cig_create()
10834 btstack_linked_list_iterator_init(&it, &hci_stack->gap_privacy_clients); in gap_privacy_client_all_ready()
10847 btstack_linked_list_iterator_init(&it, &hci_stack->gap_privacy_clients); in gap_privacy_clients_handle_ready()
10852 hci_stack->le_advertisements_state &= ~LE_ADVERTISEMENT_STATE_PRIVACY_PENDING; in gap_privacy_clients_handle_ready()
10858 btstack_linked_list_iterator_init(&it, &hci_stack->gap_privacy_clients); in gap_privacy_clients_notify()
10873 btstack_linked_list_add(&hci_stack->gap_privacy_clients, (btstack_linked_item_t *) client); in gap_privacy_client_register()
10884 btstack_linked_list_remove(&hci_stack->gap_privacy_clients, (btstack_linked_item_t *) client); in gap_privacy_client_unregister()
10897 hci_stack->num_cmd_packets = 255; in hci_setup_test_connections_fuzz()
10898 hci_stack->acl_packets_total_num = 255; in hci_setup_test_connections_fuzz()
10939 btstack_linked_list_iterator_init(&it, &hci_stack->connections); in hci_free_connections_fuzz()
10947 hci_stack->le_scanning_param_update = false; in hci_simulate_working_fuzz()
10949 hci_stack->num_cmd_packets = 255; in hci_simulate_working_fuzz()
10954 return hci_stack; in hci_get_stack()