hci.c (f24eac89332f9d272f1528a9b6ca0fcd8fdd822c) | hci.c (9da9850b83fde69f1dc00ad3fb029803b8844b54) |
---|---|
1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 200 unchanged lines hidden (view full) --- 209static void hci_state_reset(void); 210static void hci_halting_timeout_handler(btstack_timer_source_t * ds); 211static void hci_emit_transport_packet_sent(void); 212static void hci_emit_disconnection_complete(hci_con_handle_t con_handle, uint8_t reason); 213static void hci_emit_nr_connections_changed(void); 214static void hci_emit_hci_open_failed(void); 215static void hci_emit_dedicated_bonding_result(bd_addr_t address, uint8_t status); 216static void hci_emit_event(uint8_t * event, uint16_t size, int dump); | 1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 200 unchanged lines hidden (view full) --- 209static void hci_state_reset(void); 210static void hci_halting_timeout_handler(btstack_timer_source_t * ds); 211static void hci_emit_transport_packet_sent(void); 212static void hci_emit_disconnection_complete(hci_con_handle_t con_handle, uint8_t reason); 213static void hci_emit_nr_connections_changed(void); 214static void hci_emit_hci_open_failed(void); 215static void hci_emit_dedicated_bonding_result(bd_addr_t address, uint8_t status); 216static void hci_emit_event(uint8_t * event, uint16_t size, int dump); |
217static void hci_emit_btstack_event(uint8_t * event, uint16_t size, int dump); |
|
217static void hci_emit_acl_packet(uint8_t * packet, uint16_t size); 218static void hci_run(void); 219static bool hci_is_le_connection(hci_connection_t * connection); 220static uint8_t hci_send_prepared_cmd_packet(void); 221 222#ifdef ENABLE_CLASSIC 223static int hci_have_usb_transport(void); 224static void hci_trigger_remote_features_for_connection(hci_connection_t * connection); --- 292 unchanged lines hidden (view full) --- 517 518 uint8_t event[12]; 519 event[0] = GAP_EVENT_PAIRING_STARTED; 520 event[1] = 10; 521 little_endian_store_16(event, 2, (uint16_t) hci_connection->con_handle); 522 reverse_bd_addr(hci_connection->address, &event[4]); 523 event[10] = (uint8_t) ssp; 524 event[11] = (uint8_t) initiator; | 218static void hci_emit_acl_packet(uint8_t * packet, uint16_t size); 219static void hci_run(void); 220static bool hci_is_le_connection(hci_connection_t * connection); 221static uint8_t hci_send_prepared_cmd_packet(void); 222 223#ifdef ENABLE_CLASSIC 224static int hci_have_usb_transport(void); 225static void hci_trigger_remote_features_for_connection(hci_connection_t * connection); --- 292 unchanged lines hidden (view full) --- 518 519 uint8_t event[12]; 520 event[0] = GAP_EVENT_PAIRING_STARTED; 521 event[1] = 10; 522 little_endian_store_16(event, 2, (uint16_t) hci_connection->con_handle); 523 reverse_bd_addr(hci_connection->address, &event[4]); 524 event[10] = (uint8_t) ssp; 525 event[11] = (uint8_t) initiator; |
525 hci_emit_event(event, sizeof(event), 1); | 526 hci_emit_btstack_event(event, sizeof(event), 1); |
526} 527 528static void hci_pairing_complete(hci_connection_t * hci_connection, uint8_t status){ 529 hci_connection->requested_security_level = LEVEL_0; 530 if (!hci_pairing_active(hci_connection)) return; 531 hci_connection->authentication_flags &= ~AUTH_FLAG_PAIRING_ACTIVE_MASK; 532#ifdef ENABLE_CLASSIC_PAIRING_OOB 533 hci_connection->classic_oob_c_192 = NULL; --- 4 unchanged lines hidden (view full) --- 538 log_info("pairing complete, status %02x", status); 539 540 uint8_t event[11]; 541 event[0] = GAP_EVENT_PAIRING_COMPLETE; 542 event[1] = 9; 543 little_endian_store_16(event, 2, (uint16_t) hci_connection->con_handle); 544 reverse_bd_addr(hci_connection->address, &event[4]); 545 event[10] = status; | 527} 528 529static void hci_pairing_complete(hci_connection_t * hci_connection, uint8_t status){ 530 hci_connection->requested_security_level = LEVEL_0; 531 if (!hci_pairing_active(hci_connection)) return; 532 hci_connection->authentication_flags &= ~AUTH_FLAG_PAIRING_ACTIVE_MASK; 533#ifdef ENABLE_CLASSIC_PAIRING_OOB 534 hci_connection->classic_oob_c_192 = NULL; --- 4 unchanged lines hidden (view full) --- 539 log_info("pairing complete, status %02x", status); 540 541 uint8_t event[11]; 542 event[0] = GAP_EVENT_PAIRING_COMPLETE; 543 event[1] = 9; 544 little_endian_store_16(event, 2, (uint16_t) hci_connection->con_handle); 545 reverse_bd_addr(hci_connection->address, &event[4]); 546 event[10] = status; |
546 hci_emit_event(event, sizeof(event), 1); | 547 hci_emit_btstack_event(event, sizeof(event), 1); |
547 548 // emit dedicated bonding done on failure, otherwise verify that connection can be encrypted 549 if ((status != ERROR_CODE_SUCCESS) && ((hci_connection->bonding_flags & BONDING_DEDICATED) != 0)){ 550 hci_connection->bonding_flags &= ~BONDING_DEDICATED; 551 hci_connection->bonding_flags |= BONDING_DISCONNECT_DEDICATED_DONE; 552 hci_connection->bonding_status = status; 553 } 554} --- 1020 unchanged lines hidden (view full) --- 1575 offset += 8; 1576 pos += 8; 1577 event[pos++] = packet[offset + 1 + data_length]; // rssi 1578 event[pos++] = data_length; 1579 offset++; 1580 (void)memcpy(&event[pos], &packet[offset], data_length); 1581 pos += data_length; 1582 offset += data_length + 1u; // rssi | 548 549 // emit dedicated bonding done on failure, otherwise verify that connection can be encrypted 550 if ((status != ERROR_CODE_SUCCESS) && ((hci_connection->bonding_flags & BONDING_DEDICATED) != 0)){ 551 hci_connection->bonding_flags &= ~BONDING_DEDICATED; 552 hci_connection->bonding_flags |= BONDING_DISCONNECT_DEDICATED_DONE; 553 hci_connection->bonding_status = status; 554 } 555} --- 1020 unchanged lines hidden (view full) --- 1576 offset += 8; 1577 pos += 8; 1578 event[pos++] = packet[offset + 1 + data_length]; // rssi 1579 event[pos++] = data_length; 1580 offset++; 1581 (void)memcpy(&event[pos], &packet[offset], data_length); 1582 pos += data_length; 1583 offset += data_length + 1u; // rssi |
1583 hci_emit_event(event, pos, 1); | 1584 hci_emit_btstack_event(event, pos, 1); |
1584 } 1585} 1586 1587#ifdef ENABLE_LE_EXTENDED_ADVERTISING 1588static void le_handle_extended_advertisement_report(uint8_t *packet, uint16_t size) { 1589 uint16_t offset = 3; 1590 uint8_t num_reports = packet[offset++]; 1591 uint8_t event[2 + 255]; // use upper bound to avoid var size automatic var --- 47 unchanged lines hidden (view full) --- 1639 // copy rssi 1640 event[pos++] = packet[offset++]; 1641 // skip periodic advertising interval and direct address 1642 offset += 9; 1643 // copy data len + data; 1644 (void) memcpy(&event[pos], &packet[offset], 1 + data_length); 1645 pos += 1 +data_length; 1646 offset += 1+ data_length; | 1585 } 1586} 1587 1588#ifdef ENABLE_LE_EXTENDED_ADVERTISING 1589static void le_handle_extended_advertisement_report(uint8_t *packet, uint16_t size) { 1590 uint16_t offset = 3; 1591 uint8_t num_reports = packet[offset++]; 1592 uint8_t event[2 + 255]; // use upper bound to avoid var size automatic var --- 47 unchanged lines hidden (view full) --- 1640 // copy rssi 1641 event[pos++] = packet[offset++]; 1642 // skip periodic advertising interval and direct address 1643 offset += 9; 1644 // copy data len + data; 1645 (void) memcpy(&event[pos], &packet[offset], 1 + data_length); 1646 pos += 1 +data_length; 1647 offset += 1+ data_length; |
1647 hci_emit_event(event, pos, 1); | 1648 hci_emit_btstack_event(event, pos, 1); |
1648 } else { 1649 event[0] = GAP_EVENT_EXTENDED_ADVERTISING_REPORT; 1650 uint8_t report_len = 24 + data_length; 1651 event[1] = report_len; 1652 little_endian_store_16(event, 2, event_type); 1653 memcpy(&event[4], &packet[offset], report_len); 1654 offset += report_len; | 1649 } else { 1650 event[0] = GAP_EVENT_EXTENDED_ADVERTISING_REPORT; 1651 uint8_t report_len = 24 + data_length; 1652 event[1] = report_len; 1653 little_endian_store_16(event, 2, event_type); 1654 memcpy(&event[4], &packet[offset], report_len); 1655 offset += report_len; |
1655 hci_emit_event(event, 2 + report_len, 1); | 1656 hci_emit_btstack_event(event, 2 + report_len, 1); |
1656 } 1657 } 1658} 1659#endif 1660 1661#endif 1662#endif 1663 --- 1184 unchanged lines hidden (view full) --- 2848 } 2849 break; 2850 case HCI_OPCODE_HCI_READ_RSSI: 2851 if (status == ERROR_CODE_SUCCESS){ 2852 uint8_t event[5]; 2853 event[0] = GAP_EVENT_RSSI_MEASUREMENT; 2854 event[1] = 3; 2855 (void)memcpy(&event[2], &packet[6], 3); | 1657 } 1658 } 1659} 1660#endif 1661 1662#endif 1663#endif 1664 --- 1184 unchanged lines hidden (view full) --- 2849 } 2850 break; 2851 case HCI_OPCODE_HCI_READ_RSSI: 2852 if (status == ERROR_CODE_SUCCESS){ 2853 uint8_t event[5]; 2854 event[0] = GAP_EVENT_RSSI_MEASUREMENT; 2855 event[1] = 3; 2856 (void)memcpy(&event[2], &packet[6], 3); |
2856 hci_emit_event(event, sizeof(event), 1); | 2857 hci_emit_btstack_event(event, sizeof(event), 1); |
2857 } 2858 break; 2859#ifdef ENABLE_BLE 2860 case HCI_OPCODE_HCI_LE_READ_BUFFER_SIZE_V2: 2861 hci_stack->le_iso_packets_length = little_endian_read_16(packet, 9); 2862 hci_stack->le_iso_packets_total_num = packet[11]; 2863 log_info("hci_le_read_buffer_size_v2: iso size %u, iso count %u", 2864 hci_stack->le_iso_packets_length, hci_stack->le_iso_packets_total_num); --- 34 unchanged lines hidden (view full) --- 2899 hci_stack->le_advertising_set_in_current_command = 0; 2900 if (advertising_set == NULL) break; 2901 uint8_t adv_status = packet[6]; 2902 uint8_t tx_power = packet[7]; 2903 uint8_t event[] = { HCI_EVENT_META_GAP, 4, GAP_SUBEVENT_ADVERTISING_SET_INSTALLED, hci_stack->le_advertising_set_in_current_command, adv_status, tx_power }; 2904 if (adv_status == 0){ 2905 advertising_set->state |= LE_ADVERTISEMENT_STATE_PARAMS_SET; 2906 } | 2858 } 2859 break; 2860#ifdef ENABLE_BLE 2861 case HCI_OPCODE_HCI_LE_READ_BUFFER_SIZE_V2: 2862 hci_stack->le_iso_packets_length = little_endian_read_16(packet, 9); 2863 hci_stack->le_iso_packets_total_num = packet[11]; 2864 log_info("hci_le_read_buffer_size_v2: iso size %u, iso count %u", 2865 hci_stack->le_iso_packets_length, hci_stack->le_iso_packets_total_num); --- 34 unchanged lines hidden (view full) --- 2900 hci_stack->le_advertising_set_in_current_command = 0; 2901 if (advertising_set == NULL) break; 2902 uint8_t adv_status = packet[6]; 2903 uint8_t tx_power = packet[7]; 2904 uint8_t event[] = { HCI_EVENT_META_GAP, 4, GAP_SUBEVENT_ADVERTISING_SET_INSTALLED, hci_stack->le_advertising_set_in_current_command, adv_status, tx_power }; 2905 if (adv_status == 0){ 2906 advertising_set->state |= LE_ADVERTISEMENT_STATE_PARAMS_SET; 2907 } |
2907 hci_emit_event(event, sizeof(event), 1); | 2908 hci_emit_btstack_event(event, sizeof(event), 1); |
2908 } 2909 break; 2910 case HCI_OPCODE_HCI_LE_REMOVE_ADVERTISING_SET: 2911 if (hci_stack->le_advertising_set_in_current_command != 0) { 2912 le_advertising_set_t * advertising_set = hci_advertising_set_for_handle(hci_stack->le_advertising_set_in_current_command); 2913 hci_stack->le_advertising_set_in_current_command = 0; 2914 if (advertising_set == NULL) break; 2915 uint8_t event[] = { HCI_EVENT_META_GAP, 3, GAP_SUBEVENT_ADVERTISING_SET_REMOVED, hci_stack->le_advertising_set_in_current_command, status }; 2916 if (status == 0){ 2917 btstack_linked_list_remove(&hci_stack->le_advertising_sets, (btstack_linked_item_t *) advertising_set); 2918 } | 2909 } 2910 break; 2911 case HCI_OPCODE_HCI_LE_REMOVE_ADVERTISING_SET: 2912 if (hci_stack->le_advertising_set_in_current_command != 0) { 2913 le_advertising_set_t * advertising_set = hci_advertising_set_for_handle(hci_stack->le_advertising_set_in_current_command); 2914 hci_stack->le_advertising_set_in_current_command = 0; 2915 if (advertising_set == NULL) break; 2916 uint8_t event[] = { HCI_EVENT_META_GAP, 3, GAP_SUBEVENT_ADVERTISING_SET_REMOVED, hci_stack->le_advertising_set_in_current_command, status }; 2917 if (status == 0){ 2918 btstack_linked_list_remove(&hci_stack->le_advertising_sets, (btstack_linked_item_t *) advertising_set); 2919 } |
2919 hci_emit_event(event, sizeof(event), 1); | 2920 hci_emit_btstack_event(event, sizeof(event), 1); |
2920 } 2921 break; 2922#endif 2923#endif 2924 case HCI_OPCODE_HCI_READ_BD_ADDR: 2925 reverse_bd_addr(&packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE + 1], hci_stack->local_bd_addr); 2926 log_info("Local Address, Status: 0x%02x: Addr: %s", status, bd_addr_to_str(hci_stack->local_bd_addr)); 2927#ifdef ENABLE_CLASSIC --- 13 unchanged lines hidden (view full) --- 2941 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; 2942 } 2943 break; 2944 case HCI_OPCODE_HCI_INQUIRY_CANCEL: 2945 case HCI_OPCODE_HCI_EXIT_PERIODIC_INQUIRY_MODE: 2946 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_W4_CANCELLED){ 2947 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; 2948 uint8_t event[] = { GAP_EVENT_INQUIRY_COMPLETE, 1, 0}; | 2921 } 2922 break; 2923#endif 2924#endif 2925 case HCI_OPCODE_HCI_READ_BD_ADDR: 2926 reverse_bd_addr(&packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE + 1], hci_stack->local_bd_addr); 2927 log_info("Local Address, Status: 0x%02x: Addr: %s", status, bd_addr_to_str(hci_stack->local_bd_addr)); 2928#ifdef ENABLE_CLASSIC --- 13 unchanged lines hidden (view full) --- 2942 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; 2943 } 2944 break; 2945 case HCI_OPCODE_HCI_INQUIRY_CANCEL: 2946 case HCI_OPCODE_HCI_EXIT_PERIODIC_INQUIRY_MODE: 2947 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_W4_CANCELLED){ 2948 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; 2949 uint8_t event[] = { GAP_EVENT_INQUIRY_COMPLETE, 1, 0}; |
2949 hci_emit_event(event, sizeof(event), 1); | 2950 hci_emit_btstack_event(event, sizeof(event), 1); |
2950 } 2951 break; 2952#endif 2953 case HCI_OPCODE_HCI_READ_LOCAL_SUPPORTED_FEATURES: 2954 (void)memcpy(hci_stack->local_supported_features, &packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE + 1], 8); 2955 2956#ifdef ENABLE_CLASSIC 2957 // determine usable ACL packet types based on host buffer size and supported features --- 69 unchanged lines hidden (view full) --- 3027 (void)memcpy(&event[3], &packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1], 32); 3028 if (opcode == HCI_OPCODE_HCI_READ_LOCAL_EXTENDED_OOB_DATA){ 3029 event[2] = 3; 3030 (void)memcpy(&event[35], &packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+33], 32); 3031 } else { 3032 event[2] = 1; 3033 } 3034 } | 2951 } 2952 break; 2953#endif 2954 case HCI_OPCODE_HCI_READ_LOCAL_SUPPORTED_FEATURES: 2955 (void)memcpy(hci_stack->local_supported_features, &packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE + 1], 8); 2956 2957#ifdef ENABLE_CLASSIC 2958 // determine usable ACL packet types based on host buffer size and supported features --- 69 unchanged lines hidden (view full) --- 3028 (void)memcpy(&event[3], &packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1], 32); 3029 if (opcode == HCI_OPCODE_HCI_READ_LOCAL_EXTENDED_OOB_DATA){ 3030 event[2] = 3; 3031 (void)memcpy(&event[35], &packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+33], 32); 3032 } else { 3033 event[2] = 1; 3034 } 3035 } |
3035 hci_emit_event(event, sizeof(event), 0); | 3036 hci_emit_btstack_event(event, sizeof(event), 0); |
3036 break; 3037 } 3038 3039 // note: only needed if user does not provide OOB data 3040 case HCI_OPCODE_HCI_REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY: 3041 conn = hci_connection_for_handle(hci_stack->classic_oob_con_handle); 3042 hci_stack->classic_oob_con_handle = HCI_CON_HANDLE_INVALID; 3043 if (conn == NULL) break; --- 402 unchanged lines hidden (view full) --- 3446 3447 // restart timer 3448 // btstack_run_loop_set_timer(&conn->timeout, HCI_CONNECTION_TIMEOUT_MS); 3449 // btstack_run_loop_add_timer(&conn->timeout); 3450 3451 log_info("New connection: handle %u, %s", conn->con_handle, bd_addr_to_str(conn->address)); 3452 3453 // emit GAP_SUBEVENT_LE_CONNECTION_COMPLETE | 3037 break; 3038 } 3039 3040 // note: only needed if user does not provide OOB data 3041 case HCI_OPCODE_HCI_REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY: 3042 conn = hci_connection_for_handle(hci_stack->classic_oob_con_handle); 3043 hci_stack->classic_oob_con_handle = HCI_CON_HANDLE_INVALID; 3044 if (conn == NULL) break; --- 402 unchanged lines hidden (view full) --- 3447 3448 // restart timer 3449 // btstack_run_loop_set_timer(&conn->timeout, HCI_CONNECTION_TIMEOUT_MS); 3450 // btstack_run_loop_add_timer(&conn->timeout); 3451 3452 log_info("New connection: handle %u, %s", conn->con_handle, bd_addr_to_str(conn->address)); 3453 3454 // emit GAP_SUBEVENT_LE_CONNECTION_COMPLETE |
3454 hci_emit_event(gap_event, sizeof(gap_event), 1); | 3455 hci_emit_btstack_event(gap_event, sizeof(gap_event), 1); |
3455 3456 // emit BTSTACK_EVENT_NR_CONNECTIONS_CHANGED; 3457 hci_emit_nr_connections_changed(); 3458} 3459#endif 3460 3461#ifdef ENABLE_CLASSIC 3462static bool hci_ssp_security_level_possible_for_io_cap(gap_security_level_t level, uint8_t io_cap_local, uint8_t io_cap_remote){ --- 242 unchanged lines hidden (view full) --- 3705 conn->state = SEND_DISCONNECT; 3706 } 3707 break; 3708 3709 case HCI_EVENT_INQUIRY_COMPLETE: 3710 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_ACTIVE){ 3711 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; 3712 uint8_t event[] = { GAP_EVENT_INQUIRY_COMPLETE, 1, 0}; | 3456 3457 // emit BTSTACK_EVENT_NR_CONNECTIONS_CHANGED; 3458 hci_emit_nr_connections_changed(); 3459} 3460#endif 3461 3462#ifdef ENABLE_CLASSIC 3463static bool hci_ssp_security_level_possible_for_io_cap(gap_security_level_t level, uint8_t io_cap_local, uint8_t io_cap_remote){ --- 242 unchanged lines hidden (view full) --- 3706 conn->state = SEND_DISCONNECT; 3707 } 3708 break; 3709 3710 case HCI_EVENT_INQUIRY_COMPLETE: 3711 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_ACTIVE){ 3712 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; 3713 uint8_t event[] = { GAP_EVENT_INQUIRY_COMPLETE, 1, 0}; |
3713 hci_emit_event(event, sizeof(event), 1); | 3714 hci_emit_btstack_event(event, sizeof(event), 1); |
3714 } 3715 break; 3716 case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE: 3717 if (hci_stack->remote_name_state == GAP_REMOTE_NAME_STATE_W4_COMPLETE){ 3718 hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_IDLE; 3719 } 3720 break; 3721 case HCI_EVENT_CONNECTION_REQUEST: --- 4189 unchanged lines hidden (view full) --- 7911uint8_t hci_send_cmd(const hci_cmd_t * cmd, ...){ 7912 va_list argptr; 7913 va_start(argptr, cmd); 7914 uint8_t status = hci_send_cmd_va_arg(cmd, argptr); 7915 va_end(argptr); 7916 return status; 7917} 7918 | 3715 } 3716 break; 3717 case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE: 3718 if (hci_stack->remote_name_state == GAP_REMOTE_NAME_STATE_W4_COMPLETE){ 3719 hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_IDLE; 3720 } 3721 break; 3722 case HCI_EVENT_CONNECTION_REQUEST: --- 4189 unchanged lines hidden (view full) --- 7912uint8_t hci_send_cmd(const hci_cmd_t * cmd, ...){ 7913 va_list argptr; 7914 va_start(argptr, cmd); 7915 uint8_t status = hci_send_cmd_va_arg(cmd, argptr); 7916 va_end(argptr); 7917 return status; 7918} 7919 |
7919// Create various non-HCI events. 7920// TODO: generalize, use table similar to hci_create_command | 7920// Forward HCI events and create non-HCI events |
7921 7922static void hci_emit_event(uint8_t * event, uint16_t size, int dump){ 7923 // dump packet 7924 if (dump) { 7925 hci_dump_packet( HCI_EVENT_PACKET, 1, event, size); 7926 } 7927 7928 // dispatch to all event handlers 7929 btstack_linked_list_iterator_t it; 7930 btstack_linked_list_iterator_init(&it, &hci_stack->event_handlers); 7931 while (btstack_linked_list_iterator_has_next(&it)){ 7932 btstack_packet_callback_registration_t * entry = (btstack_packet_callback_registration_t*) btstack_linked_list_iterator_next(&it); 7933 entry->callback(HCI_EVENT_PACKET, 0, event, size); 7934 } 7935} 7936 | 7921 7922static void hci_emit_event(uint8_t * event, uint16_t size, int dump){ 7923 // dump packet 7924 if (dump) { 7925 hci_dump_packet( HCI_EVENT_PACKET, 1, event, size); 7926 } 7927 7928 // dispatch to all event handlers 7929 btstack_linked_list_iterator_t it; 7930 btstack_linked_list_iterator_init(&it, &hci_stack->event_handlers); 7931 while (btstack_linked_list_iterator_has_next(&it)){ 7932 btstack_packet_callback_registration_t * entry = (btstack_packet_callback_registration_t*) btstack_linked_list_iterator_next(&it); 7933 entry->callback(HCI_EVENT_PACKET, 0, event, size); 7934 } 7935} 7936 |
7937static void hci_emit_btstack_event(uint8_t * event, uint16_t size, int dump){ 7938#ifndef ENABLE_LOG_BTSTACK_EVENTS 7939 dump = 0; 7940#endif 7941 hci_emit_event(event, size, dump); 7942} 7943 |
|
7937static void hci_emit_acl_packet(uint8_t * packet, uint16_t size){ 7938 if (!hci_stack->acl_packet_handler) return; 7939 hci_stack->acl_packet_handler(HCI_ACL_DATA_PACKET, 0, packet, size); 7940} 7941 7942#ifdef ENABLE_CLASSIC 7943static void hci_notify_if_sco_can_send_now(void){ 7944 // notify SCO sender if waiting 7945 if (!hci_stack->sco_waiting_for_can_send_now) return; 7946 if (hci_can_send_sco_packet_now()){ 7947 hci_stack->sco_waiting_for_can_send_now = 0; 7948 uint8_t event[2] = { HCI_EVENT_SCO_CAN_SEND_NOW, 0 }; | 7944static void hci_emit_acl_packet(uint8_t * packet, uint16_t size){ 7945 if (!hci_stack->acl_packet_handler) return; 7946 hci_stack->acl_packet_handler(HCI_ACL_DATA_PACKET, 0, packet, size); 7947} 7948 7949#ifdef ENABLE_CLASSIC 7950static void hci_notify_if_sco_can_send_now(void){ 7951 // notify SCO sender if waiting 7952 if (!hci_stack->sco_waiting_for_can_send_now) return; 7953 if (hci_can_send_sco_packet_now()){ 7954 hci_stack->sco_waiting_for_can_send_now = 0; 7955 uint8_t event[2] = { HCI_EVENT_SCO_CAN_SEND_NOW, 0 }; |
7949 hci_dump_packet(HCI_EVENT_PACKET, 1, event, sizeof(event)); | 7956 hci_dump_btstack_event(event, sizeof(event)); |
7950 hci_stack->sco_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event)); 7951 } 7952} 7953 7954// parsing end emitting has been merged to reduce code size 7955static void gap_inquiry_explode(uint8_t *packet, uint16_t size) { 7956 uint8_t event[28+GAP_INQUIRY_MAX_NAME_LEN]; 7957 --- 83 unchanged lines hidden (view full) --- 8041 (void)memcpy(&event[27], name, len); 8042 event_size += len; 8043 } 8044 break; 8045 default: 8046 return; 8047 } 8048 event[1] = event_size - 2; | 7957 hci_stack->sco_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event)); 7958 } 7959} 7960 7961// parsing end emitting has been merged to reduce code size 7962static void gap_inquiry_explode(uint8_t *packet, uint16_t size) { 7963 uint8_t event[28+GAP_INQUIRY_MAX_NAME_LEN]; 7964 --- 83 unchanged lines hidden (view full) --- 8048 (void)memcpy(&event[27], name, len); 8049 event_size += len; 8050 } 8051 break; 8052 default: 8053 return; 8054 } 8055 event[1] = event_size - 2; |
8049 hci_emit_event(event, event_size, 1); | 8056 hci_emit_btstack_event(event, event_size, 1); |
8050 } 8051} 8052#endif 8053 8054void hci_emit_state(void){ 8055 log_info("BTSTACK_EVENT_STATE %u", hci_stack->state); 8056 uint8_t event[3]; 8057 event[0] = BTSTACK_EVENT_STATE; 8058 event[1] = sizeof(event) - 2u; 8059 event[2] = hci_stack->state; | 8057 } 8058} 8059#endif 8060 8061void hci_emit_state(void){ 8062 log_info("BTSTACK_EVENT_STATE %u", hci_stack->state); 8063 uint8_t event[3]; 8064 event[0] = BTSTACK_EVENT_STATE; 8065 event[1] = sizeof(event) - 2u; 8066 event[2] = hci_stack->state; |
8060 hci_emit_event(event, sizeof(event), 1); | 8067 hci_emit_btstack_event(event, sizeof(event), 1); |
8061} 8062 8063#ifdef ENABLE_CLASSIC 8064static void hci_emit_connection_complete(bd_addr_t address, hci_con_handle_t con_handle, uint8_t status){ 8065 uint8_t event[13]; 8066 event[0] = HCI_EVENT_CONNECTION_COMPLETE; 8067 event[1] = sizeof(event) - 2; 8068 event[2] = status; 8069 little_endian_store_16(event, 3, con_handle); 8070 reverse_bd_addr(address, &event[5]); 8071 event[11] = 1; // ACL connection 8072 event[12] = 0; // encryption disabled | 8068} 8069 8070#ifdef ENABLE_CLASSIC 8071static void hci_emit_connection_complete(bd_addr_t address, hci_con_handle_t con_handle, uint8_t status){ 8072 uint8_t event[13]; 8073 event[0] = HCI_EVENT_CONNECTION_COMPLETE; 8074 event[1] = sizeof(event) - 2; 8075 event[2] = status; 8076 little_endian_store_16(event, 3, con_handle); 8077 reverse_bd_addr(address, &event[5]); 8078 event[11] = 1; // ACL connection 8079 event[12] = 0; // encryption disabled |
8073 hci_emit_event(event, sizeof(event), 1); | 8080 hci_emit_btstack_event(event, sizeof(event), 1); |
8074} 8075static void hci_emit_l2cap_check_timeout(hci_connection_t *conn){ 8076 if (disable_l2cap_timeouts) return; 8077 log_info("L2CAP_EVENT_TIMEOUT_CHECK"); 8078 uint8_t event[4]; 8079 event[0] = L2CAP_EVENT_TIMEOUT_CHECK; 8080 event[1] = sizeof(event) - 2; 8081 little_endian_store_16(event, 2, conn->con_handle); | 8081} 8082static void hci_emit_l2cap_check_timeout(hci_connection_t *conn){ 8083 if (disable_l2cap_timeouts) return; 8084 log_info("L2CAP_EVENT_TIMEOUT_CHECK"); 8085 uint8_t event[4]; 8086 event[0] = L2CAP_EVENT_TIMEOUT_CHECK; 8087 event[1] = sizeof(event) - 2; 8088 little_endian_store_16(event, 2, conn->con_handle); |
8082 hci_emit_event(event, sizeof(event), 1); | 8089 hci_emit_btstack_event(event, sizeof(event), 1); |
8083} 8084#endif 8085 8086#ifdef ENABLE_BLE 8087#ifdef ENABLE_LE_CENTRAL 8088static void hci_emit_le_connection_complete(uint8_t address_type, const bd_addr_t address, hci_con_handle_t con_handle, uint8_t status){ 8089 uint8_t hci_event[21]; 8090 hci_event[0] = HCI_EVENT_LE_META; 8091 hci_event[1] = sizeof(hci_event) - 2u; 8092 hci_event[2] = HCI_SUBEVENT_LE_CONNECTION_COMPLETE; 8093 hci_event[3] = status; 8094 little_endian_store_16(hci_event, 4, con_handle); 8095 hci_event[6] = 0; // TODO: role 8096 hci_event[7] = address_type; 8097 reverse_bd_addr(address, &hci_event[8]); 8098 little_endian_store_16(hci_event, 14, 0); // interval 8099 little_endian_store_16(hci_event, 16, 0); // latency 8100 little_endian_store_16(hci_event, 18, 0); // supervision timeout 8101 hci_event[20] = 0; // master clock accuracy | 8090} 8091#endif 8092 8093#ifdef ENABLE_BLE 8094#ifdef ENABLE_LE_CENTRAL 8095static void hci_emit_le_connection_complete(uint8_t address_type, const bd_addr_t address, hci_con_handle_t con_handle, uint8_t status){ 8096 uint8_t hci_event[21]; 8097 hci_event[0] = HCI_EVENT_LE_META; 8098 hci_event[1] = sizeof(hci_event) - 2u; 8099 hci_event[2] = HCI_SUBEVENT_LE_CONNECTION_COMPLETE; 8100 hci_event[3] = status; 8101 little_endian_store_16(hci_event, 4, con_handle); 8102 hci_event[6] = 0; // TODO: role 8103 hci_event[7] = address_type; 8104 reverse_bd_addr(address, &hci_event[8]); 8105 little_endian_store_16(hci_event, 14, 0); // interval 8106 little_endian_store_16(hci_event, 16, 0); // latency 8107 little_endian_store_16(hci_event, 18, 0); // supervision timeout 8108 hci_event[20] = 0; // master clock accuracy |
8102 hci_emit_event(hci_event, sizeof(hci_event), 1); | 8109 hci_emit_btstack_event(hci_event, sizeof(hci_event), 1); |
8103 // emit GAP event, too 8104 uint8_t gap_event[36]; 8105 hci_create_gap_connection_complete_event(hci_event, gap_event); | 8110 // emit GAP event, too 8111 uint8_t gap_event[36]; 8112 hci_create_gap_connection_complete_event(hci_event, gap_event); |
8106 hci_emit_event(gap_event, sizeof(gap_event), 1); | 8113 hci_emit_btstack_event(gap_event, sizeof(gap_event), 1); |
8107} 8108#endif 8109#endif 8110 8111static void hci_emit_transport_packet_sent(void){ 8112 // notify upper stack that it might be possible to send again 8113 uint8_t event[] = { HCI_EVENT_TRANSPORT_PACKET_SENT, 0}; | 8114} 8115#endif 8116#endif 8117 8118static void hci_emit_transport_packet_sent(void){ 8119 // notify upper stack that it might be possible to send again 8120 uint8_t event[] = { HCI_EVENT_TRANSPORT_PACKET_SENT, 0}; |
8114 hci_emit_event(&event[0], sizeof(event), 0); // don't dump | 8121 hci_emit_btstack_event(&event[0], sizeof(event), 0); // don't dump |
8115} 8116 8117static void hci_emit_disconnection_complete(hci_con_handle_t con_handle, uint8_t reason){ 8118 uint8_t event[6]; 8119 event[0] = HCI_EVENT_DISCONNECTION_COMPLETE; 8120 event[1] = sizeof(event) - 2u; 8121 event[2] = 0; // status = OK 8122 little_endian_store_16(event, 3, con_handle); 8123 event[5] = reason; | 8122} 8123 8124static void hci_emit_disconnection_complete(hci_con_handle_t con_handle, uint8_t reason){ 8125 uint8_t event[6]; 8126 event[0] = HCI_EVENT_DISCONNECTION_COMPLETE; 8127 event[1] = sizeof(event) - 2u; 8128 event[2] = 0; // status = OK 8129 little_endian_store_16(event, 3, con_handle); 8130 event[5] = reason; |
8124 hci_emit_event(event, sizeof(event), 1); | 8131 hci_emit_btstack_event(event, sizeof(event), 1); |
8125} 8126 8127static void hci_emit_nr_connections_changed(void){ 8128 log_info("BTSTACK_EVENT_NR_CONNECTIONS_CHANGED %u", nr_hci_connections()); 8129 uint8_t event[3]; 8130 event[0] = BTSTACK_EVENT_NR_CONNECTIONS_CHANGED; 8131 event[1] = sizeof(event) - 2u; 8132 event[2] = nr_hci_connections(); | 8132} 8133 8134static void hci_emit_nr_connections_changed(void){ 8135 log_info("BTSTACK_EVENT_NR_CONNECTIONS_CHANGED %u", nr_hci_connections()); 8136 uint8_t event[3]; 8137 event[0] = BTSTACK_EVENT_NR_CONNECTIONS_CHANGED; 8138 event[1] = sizeof(event) - 2u; 8139 event[2] = nr_hci_connections(); |
8133 hci_emit_event(event, sizeof(event), 1); | 8140 hci_emit_btstack_event(event, sizeof(event), 1); |
8134} 8135 8136static void hci_emit_hci_open_failed(void){ 8137 log_info("BTSTACK_EVENT_POWERON_FAILED"); 8138 uint8_t event[2]; 8139 event[0] = BTSTACK_EVENT_POWERON_FAILED; 8140 event[1] = sizeof(event) - 2u; | 8141} 8142 8143static void hci_emit_hci_open_failed(void){ 8144 log_info("BTSTACK_EVENT_POWERON_FAILED"); 8145 uint8_t event[2]; 8146 event[0] = BTSTACK_EVENT_POWERON_FAILED; 8147 event[1] = sizeof(event) - 2u; |
8141 hci_emit_event(event, sizeof(event), 1); | 8148 hci_emit_btstack_event(event, sizeof(event), 1); |
8142} 8143 8144static void hci_emit_dedicated_bonding_result(bd_addr_t address, uint8_t status){ 8145 log_info("hci_emit_dedicated_bonding_result %u ", status); 8146 uint8_t event[9]; 8147 int pos = 0; 8148 event[pos++] = GAP_EVENT_DEDICATED_BONDING_COMPLETED; 8149 event[pos++] = sizeof(event) - 2u; 8150 event[pos++] = status; 8151 reverse_bd_addr(address, &event[pos]); | 8149} 8150 8151static void hci_emit_dedicated_bonding_result(bd_addr_t address, uint8_t status){ 8152 log_info("hci_emit_dedicated_bonding_result %u ", status); 8153 uint8_t event[9]; 8154 int pos = 0; 8155 event[pos++] = GAP_EVENT_DEDICATED_BONDING_COMPLETED; 8156 event[pos++] = sizeof(event) - 2u; 8157 event[pos++] = status; 8158 reverse_bd_addr(address, &event[pos]); |
8152 hci_emit_event(event, sizeof(event), 1); | 8159 hci_emit_btstack_event(event, sizeof(event), 1); |
8153} 8154 8155 8156#ifdef ENABLE_CLASSIC 8157 8158static void hci_emit_security_level(hci_con_handle_t con_handle, gap_security_level_t level){ 8159 log_info("hci_emit_security_level %u for handle %x", level, con_handle); 8160 uint8_t event[5]; 8161 int pos = 0; 8162 event[pos++] = GAP_EVENT_SECURITY_LEVEL; 8163 event[pos++] = sizeof(event) - 2; 8164 little_endian_store_16(event, 2, con_handle); 8165 pos += 2; 8166 event[pos++] = level; | 8160} 8161 8162 8163#ifdef ENABLE_CLASSIC 8164 8165static void hci_emit_security_level(hci_con_handle_t con_handle, gap_security_level_t level){ 8166 log_info("hci_emit_security_level %u for handle %x", level, con_handle); 8167 uint8_t event[5]; 8168 int pos = 0; 8169 event[pos++] = GAP_EVENT_SECURITY_LEVEL; 8170 event[pos++] = sizeof(event) - 2; 8171 little_endian_store_16(event, 2, con_handle); 8172 pos += 2; 8173 event[pos++] = level; |
8167 hci_emit_event(event, sizeof(event), 1); | 8174 hci_emit_btstack_event(event, sizeof(event), 1); |
8168} 8169 8170static gap_security_level_t gap_security_level_for_connection(hci_connection_t * connection){ 8171 if (!connection) return LEVEL_0; 8172 if ((connection->authentication_flags & AUTH_FLAG_CONNECTION_ENCRYPTED) == 0) return LEVEL_0; 8173 // BIAS: we only consider Authenticated if the connection is already encrypted, which requires that both sides have link key 8174 if ((connection->authentication_flags & AUTH_FLAG_CONNECTION_AUTHENTICATED) == 0) return LEVEL_0; 8175 if (connection->encryption_key_size < hci_stack->gap_required_encyrption_key_size) return LEVEL_0; --- 6 unchanged lines hidden (view full) --- 8182} 8183 8184static void hci_emit_scan_mode_changed(uint8_t discoverable, uint8_t connectable){ 8185 uint8_t event[4]; 8186 event[0] = BTSTACK_EVENT_SCAN_MODE_CHANGED; 8187 event[1] = sizeof(event) - 2; 8188 event[2] = discoverable; 8189 event[3] = connectable; | 8175} 8176 8177static gap_security_level_t gap_security_level_for_connection(hci_connection_t * connection){ 8178 if (!connection) return LEVEL_0; 8179 if ((connection->authentication_flags & AUTH_FLAG_CONNECTION_ENCRYPTED) == 0) return LEVEL_0; 8180 // BIAS: we only consider Authenticated if the connection is already encrypted, which requires that both sides have link key 8181 if ((connection->authentication_flags & AUTH_FLAG_CONNECTION_AUTHENTICATED) == 0) return LEVEL_0; 8182 if (connection->encryption_key_size < hci_stack->gap_required_encyrption_key_size) return LEVEL_0; --- 6 unchanged lines hidden (view full) --- 8189} 8190 8191static void hci_emit_scan_mode_changed(uint8_t discoverable, uint8_t connectable){ 8192 uint8_t event[4]; 8193 event[0] = BTSTACK_EVENT_SCAN_MODE_CHANGED; 8194 event[1] = sizeof(event) - 2; 8195 event[2] = discoverable; 8196 event[3] = connectable; |
8190 hci_emit_event(event, sizeof(event), 1); | 8197 hci_emit_btstack_event(event, sizeof(event), 1); |
8191} 8192 8193// query if remote side supports eSCO 8194bool hci_remote_esco_supported(hci_con_handle_t con_handle){ 8195 hci_connection_t * connection = hci_connection_for_handle(con_handle); 8196 if (!connection) return false; 8197 return (connection->remote_supported_features[0] & 1) != 0; 8198} --- 420 unchanged lines hidden (view full) --- 8619 hci_connection_t * connection = hci_connection_for_handle(con_handle); 8620 if (!connection) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; 8621 connection->le_conn_interval_min = conn_interval_min; 8622 connection->le_conn_interval_max = conn_interval_max; 8623 connection->le_conn_latency = conn_latency; 8624 connection->le_supervision_timeout = supervision_timeout; 8625 connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_SEND_REQUEST; 8626 uint8_t l2cap_trigger_run_event[2] = { L2CAP_EVENT_TRIGGER_RUN, 0}; | 8198} 8199 8200// query if remote side supports eSCO 8201bool hci_remote_esco_supported(hci_con_handle_t con_handle){ 8202 hci_connection_t * connection = hci_connection_for_handle(con_handle); 8203 if (!connection) return false; 8204 return (connection->remote_supported_features[0] & 1) != 0; 8205} --- 420 unchanged lines hidden (view full) --- 8626 hci_connection_t * connection = hci_connection_for_handle(con_handle); 8627 if (!connection) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; 8628 connection->le_conn_interval_min = conn_interval_min; 8629 connection->le_conn_interval_max = conn_interval_max; 8630 connection->le_conn_latency = conn_latency; 8631 connection->le_supervision_timeout = supervision_timeout; 8632 connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_SEND_REQUEST; 8633 uint8_t l2cap_trigger_run_event[2] = { L2CAP_EVENT_TRIGGER_RUN, 0}; |
8627 hci_emit_event(l2cap_trigger_run_event, sizeof(l2cap_trigger_run_event), 0); | 8634 hci_emit_btstack_event(l2cap_trigger_run_event, sizeof(l2cap_trigger_run_event), 0); |
8628 return 0; 8629} 8630 8631#ifdef ENABLE_LE_PERIPHERAL 8632 8633#ifdef ENABLE_LE_EXTENDED_ADVERTISING 8634static void hci_assert_advertisement_set_0_ready(void){ 8635 // force advertising set creation for legacy LE Advertising --- 650 unchanged lines hidden (view full) --- 9286/** 9287 * @brief Stop GAP Classic Inquiry 9288 * @return 0 if ok 9289 */ 9290int gap_inquiry_stop(void){ 9291 if ((hci_stack->inquiry_state >= GAP_INQUIRY_DURATION_MIN) && (hci_stack->inquiry_state <= GAP_INQUIRY_DURATION_MAX)) { 9292 // emit inquiry complete event, before it even started 9293 uint8_t event[] = { GAP_EVENT_INQUIRY_COMPLETE, 1, 0}; | 8635 return 0; 8636} 8637 8638#ifdef ENABLE_LE_PERIPHERAL 8639 8640#ifdef ENABLE_LE_EXTENDED_ADVERTISING 8641static void hci_assert_advertisement_set_0_ready(void){ 8642 // force advertising set creation for legacy LE Advertising --- 650 unchanged lines hidden (view full) --- 9293/** 9294 * @brief Stop GAP Classic Inquiry 9295 * @return 0 if ok 9296 */ 9297int gap_inquiry_stop(void){ 9298 if ((hci_stack->inquiry_state >= GAP_INQUIRY_DURATION_MIN) && (hci_stack->inquiry_state <= GAP_INQUIRY_DURATION_MAX)) { 9299 // emit inquiry complete event, before it even started 9300 uint8_t event[] = { GAP_EVENT_INQUIRY_COMPLETE, 1, 0}; |
9294 hci_emit_event(event, sizeof(event), 1); | 9301 hci_emit_btstack_event(event, sizeof(event), 1); |
9295 return 0; 9296 } 9297 switch (hci_stack->inquiry_state){ 9298 case GAP_INQUIRY_STATE_ACTIVE: 9299 hci_stack->inquiry_state = GAP_INQUIRY_STATE_W2_CANCEL; 9300 hci_run(); 9301 return ERROR_CODE_SUCCESS; 9302 case GAP_INQUIRY_STATE_PERIODIC: --- 861 unchanged lines hidden (view full) --- 10164 event[pos++] = status; 10165 event[pos++] = big->big_handle; 10166 event[pos++] = big->num_bis; 10167 uint8_t i; 10168 for (i=0;i<big->num_bis;i++){ 10169 little_endian_store_16(event, pos, big->bis_con_handles[i]); 10170 pos += 2; 10171 } | 9302 return 0; 9303 } 9304 switch (hci_stack->inquiry_state){ 9305 case GAP_INQUIRY_STATE_ACTIVE: 9306 hci_stack->inquiry_state = GAP_INQUIRY_STATE_W2_CANCEL; 9307 hci_run(); 9308 return ERROR_CODE_SUCCESS; 9309 case GAP_INQUIRY_STATE_PERIODIC: --- 861 unchanged lines hidden (view full) --- 10171 event[pos++] = status; 10172 event[pos++] = big->big_handle; 10173 event[pos++] = big->num_bis; 10174 uint8_t i; 10175 for (i=0;i<big->num_bis;i++){ 10176 little_endian_store_16(event, pos, big->bis_con_handles[i]); 10177 pos += 2; 10178 } |
10172 hci_emit_event(event, pos, 0); | 10179 hci_emit_btstack_event(event, pos, 0); |
10173} 10174 10175static void hci_emit_cig_created(const le_audio_cig_t * cig, uint8_t status){ 10176 uint8_t event [6 + (MAX_NR_CIS * 2)]; 10177 uint16_t pos = 0; 10178 event[pos++] = HCI_EVENT_META_GAP; 10179 event[pos++] = 4 + (2 * cig->num_cis); 10180 event[pos++] = GAP_SUBEVENT_CIG_CREATED; 10181 event[pos++] = status; 10182 event[pos++] = cig->cig_id; 10183 event[pos++] = cig->num_cis; 10184 uint8_t i; 10185 for (i=0;i<cig->num_cis;i++){ 10186 little_endian_store_16(event, pos, cig->cis_con_handles[i]); 10187 pos += 2; 10188 } | 10180} 10181 10182static void hci_emit_cig_created(const le_audio_cig_t * cig, uint8_t status){ 10183 uint8_t event [6 + (MAX_NR_CIS * 2)]; 10184 uint16_t pos = 0; 10185 event[pos++] = HCI_EVENT_META_GAP; 10186 event[pos++] = 4 + (2 * cig->num_cis); 10187 event[pos++] = GAP_SUBEVENT_CIG_CREATED; 10188 event[pos++] = status; 10189 event[pos++] = cig->cig_id; 10190 event[pos++] = cig->num_cis; 10191 uint8_t i; 10192 for (i=0;i<cig->num_cis;i++){ 10193 little_endian_store_16(event, pos, cig->cis_con_handles[i]); 10194 pos += 2; 10195 } |
10189 hci_emit_event(event, pos, 0); | 10196 hci_emit_btstack_event(event, pos, 0); |
10190} 10191 10192static uint16_t hci_setup_cis_created(uint8_t * event, hci_iso_stream_t * iso_stream, uint8_t status) { 10193 uint16_t pos = 0; 10194 event[pos++] = HCI_EVENT_META_GAP; 10195 event[pos++] = 8; 10196 event[pos++] = GAP_SUBEVENT_CIS_CREATED; 10197 event[pos++] = status; --- 17 unchanged lines hidden (view full) --- 10215static void hci_cis_handle_created(hci_iso_stream_t * iso_stream, uint8_t status){ 10216 // cache data before finalizing struct 10217 uint8_t event [17]; 10218 uint16_t pos = hci_setup_cis_created(event, iso_stream, status); 10219 btstack_assert(pos <= sizeof(event)); 10220 if (status != ERROR_CODE_SUCCESS){ 10221 hci_iso_stream_finalize(iso_stream); 10222 } | 10197} 10198 10199static uint16_t hci_setup_cis_created(uint8_t * event, hci_iso_stream_t * iso_stream, uint8_t status) { 10200 uint16_t pos = 0; 10201 event[pos++] = HCI_EVENT_META_GAP; 10202 event[pos++] = 8; 10203 event[pos++] = GAP_SUBEVENT_CIS_CREATED; 10204 event[pos++] = status; --- 17 unchanged lines hidden (view full) --- 10222static void hci_cis_handle_created(hci_iso_stream_t * iso_stream, uint8_t status){ 10223 // cache data before finalizing struct 10224 uint8_t event [17]; 10225 uint16_t pos = hci_setup_cis_created(event, iso_stream, status); 10226 btstack_assert(pos <= sizeof(event)); 10227 if (status != ERROR_CODE_SUCCESS){ 10228 hci_iso_stream_finalize(iso_stream); 10229 } |
10223 hci_emit_event(event, pos, 0); | 10230 hci_emit_btstack_event(event, pos, 0); |
10224} 10225 10226static void hci_emit_big_terminated(const le_audio_big_t * big){ 10227 uint8_t event [4]; 10228 uint16_t pos = 0; 10229 event[pos++] = HCI_EVENT_META_GAP; 10230 event[pos++] = 2; 10231 event[pos++] = GAP_SUBEVENT_BIG_TERMINATED; 10232 event[pos++] = big->big_handle; | 10231} 10232 10233static void hci_emit_big_terminated(const le_audio_big_t * big){ 10234 uint8_t event [4]; 10235 uint16_t pos = 0; 10236 event[pos++] = HCI_EVENT_META_GAP; 10237 event[pos++] = 2; 10238 event[pos++] = GAP_SUBEVENT_BIG_TERMINATED; 10239 event[pos++] = big->big_handle; |
10233 hci_emit_event(event, pos, 0); | 10240 hci_emit_btstack_event(event, pos, 0); |
10234} 10235 10236static void hci_emit_big_sync_created(const le_audio_big_sync_t * big_sync, uint8_t status){ 10237 uint8_t event [6 + (MAX_NR_BIS * 2)]; 10238 uint16_t pos = 0; 10239 event[pos++] = HCI_EVENT_META_GAP; 10240 event[pos++] = 4; 10241 event[pos++] = GAP_SUBEVENT_BIG_SYNC_CREATED; 10242 event[pos++] = status; 10243 event[pos++] = big_sync->big_handle; 10244 event[pos++] = big_sync->num_bis; 10245 uint8_t i; 10246 for (i=0;i<big_sync->num_bis;i++){ 10247 little_endian_store_16(event, pos, big_sync->bis_con_handles[i]); 10248 pos += 2; 10249 } | 10241} 10242 10243static void hci_emit_big_sync_created(const le_audio_big_sync_t * big_sync, uint8_t status){ 10244 uint8_t event [6 + (MAX_NR_BIS * 2)]; 10245 uint16_t pos = 0; 10246 event[pos++] = HCI_EVENT_META_GAP; 10247 event[pos++] = 4; 10248 event[pos++] = GAP_SUBEVENT_BIG_SYNC_CREATED; 10249 event[pos++] = status; 10250 event[pos++] = big_sync->big_handle; 10251 event[pos++] = big_sync->num_bis; 10252 uint8_t i; 10253 for (i=0;i<big_sync->num_bis;i++){ 10254 little_endian_store_16(event, pos, big_sync->bis_con_handles[i]); 10255 pos += 2; 10256 } |
10250 hci_emit_event(event, pos, 0); | 10257 hci_emit_btstack_event(event, pos, 0); |
10251} 10252 10253static void hci_emit_big_sync_stopped(uint8_t big_handle){ 10254 uint8_t event [4]; 10255 uint16_t pos = 0; 10256 event[pos++] = HCI_EVENT_META_GAP; 10257 event[pos++] = 2; 10258 event[pos++] = GAP_SUBEVENT_BIG_SYNC_STOPPED; 10259 event[pos++] = big_handle; | 10258} 10259 10260static void hci_emit_big_sync_stopped(uint8_t big_handle){ 10261 uint8_t event [4]; 10262 uint16_t pos = 0; 10263 event[pos++] = HCI_EVENT_META_GAP; 10264 event[pos++] = 2; 10265 event[pos++] = GAP_SUBEVENT_BIG_SYNC_STOPPED; 10266 event[pos++] = big_handle; |
10260 hci_emit_event(event, pos, 0); | 10267 hci_emit_btstack_event(event, pos, 0); |
10261} 10262 10263static void hci_emit_bis_can_send_now(const le_audio_big_t *big, uint8_t bis_index) { 10264 uint8_t event[6]; 10265 uint16_t pos = 0; 10266 event[pos++] = HCI_EVENT_BIS_CAN_SEND_NOW; 10267 event[pos++] = sizeof(event) - 2; 10268 event[pos++] = big->big_handle; 10269 event[pos++] = bis_index; 10270 little_endian_store_16(event, pos, big->bis_con_handles[bis_index]); | 10268} 10269 10270static void hci_emit_bis_can_send_now(const le_audio_big_t *big, uint8_t bis_index) { 10271 uint8_t event[6]; 10272 uint16_t pos = 0; 10273 event[pos++] = HCI_EVENT_BIS_CAN_SEND_NOW; 10274 event[pos++] = sizeof(event) - 2; 10275 event[pos++] = big->big_handle; 10276 event[pos++] = bis_index; 10277 little_endian_store_16(event, pos, big->bis_con_handles[bis_index]); |
10271 hci_emit_event(&event[0], sizeof(event), 0); // don't dump | 10278 hci_emit_btstack_event(&event[0], sizeof(event), 0); // don't dump |
10272} 10273 10274static void hci_emit_cis_can_send_now(hci_con_handle_t cis_con_handle) { 10275 uint8_t event[4]; 10276 uint16_t pos = 0; 10277 event[pos++] = HCI_EVENT_CIS_CAN_SEND_NOW; 10278 event[pos++] = sizeof(event) - 2; 10279 little_endian_store_16(event, pos, cis_con_handle); | 10279} 10280 10281static void hci_emit_cis_can_send_now(hci_con_handle_t cis_con_handle) { 10282 uint8_t event[4]; 10283 uint16_t pos = 0; 10284 event[pos++] = HCI_EVENT_CIS_CAN_SEND_NOW; 10285 event[pos++] = sizeof(event) - 2; 10286 little_endian_store_16(event, pos, cis_con_handle); |
10280 hci_emit_event(&event[0], sizeof(event), 0); // don't dump | 10287 hci_emit_btstack_event(&event[0], sizeof(event), 0); // don't dump |
10281} 10282 10283static le_audio_big_t * hci_big_for_handle(uint8_t big_handle){ 10284 btstack_linked_list_iterator_t it; 10285 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_bigs); 10286 while (btstack_linked_list_iterator_has_next(&it)){ 10287 le_audio_big_t * big = (le_audio_big_t *) btstack_linked_list_iterator_next(&it); 10288 if ( big->big_handle == big_handle ) { --- 528 unchanged lines hidden --- | 10288} 10289 10290static le_audio_big_t * hci_big_for_handle(uint8_t big_handle){ 10291 btstack_linked_list_iterator_t it; 10292 btstack_linked_list_iterator_init(&it, &hci_stack->le_audio_bigs); 10293 while (btstack_linked_list_iterator_has_next(&it)){ 10294 le_audio_big_t * big = (le_audio_big_t *) btstack_linked_list_iterator_next(&it); 10295 if ( big->big_handle == big_handle ) { --- 528 unchanged lines hidden --- |