hci.c (a98592bc68752f97644fe016fd3d13da7711f733) | hci.c (d6b06661159f27ddc0293fa2a7eaba2d8924e39f) |
---|---|
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 --- 73 unchanged lines hidden (view full) --- 82static void hci_state_reset(void); 83 84#ifdef ENABLE_BLE 85// called from test/ble_client/advertising_data_parser.c 86void le_handle_advertisement_report(uint8_t *packet, int size); 87static void hci_remove_from_whitelist(bd_addr_type_t address_type, bd_addr_t address); 88#endif 89 | 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 --- 73 unchanged lines hidden (view full) --- 82static void hci_state_reset(void); 83 84#ifdef ENABLE_BLE 85// called from test/ble_client/advertising_data_parser.c 86void le_handle_advertisement_report(uint8_t *packet, int size); 87static void hci_remove_from_whitelist(bd_addr_type_t address_type, bd_addr_t address); 88#endif 89 |
90// prototypes 91static void hci_emit_event(uint8_t * event, uint16_t size, int dump); 92static void hci_emit_acl_packet(uint8_t * packet, uint16_t size); 93 |
|
90// the STACK is here 91#ifndef HAVE_MALLOC 92static hci_stack_t hci_stack_static; 93#endif 94static hci_stack_t * hci_stack = NULL; 95 96// test helper 97static uint8_t disable_l2cap_timeouts = 0; --- 406 unchanged lines hidden (view full) --- 504 hci_stack->acl_fragmentation_pos = 0; 505 hci_stack->acl_fragmentation_total_size = 0; 506 507 // release buffer now for synchronous transport 508 if (hci_transport_synchronous()){ 509 hci_release_packet_buffer(); 510 // notify upper stack that iit might be possible to send again 511 uint8_t event[] = { DAEMON_EVENT_HCI_PACKET_SENT, 0}; | 94// the STACK is here 95#ifndef HAVE_MALLOC 96static hci_stack_t hci_stack_static; 97#endif 98static hci_stack_t * hci_stack = NULL; 99 100// test helper 101static uint8_t disable_l2cap_timeouts = 0; --- 406 unchanged lines hidden (view full) --- 508 hci_stack->acl_fragmentation_pos = 0; 509 hci_stack->acl_fragmentation_total_size = 0; 510 511 // release buffer now for synchronous transport 512 if (hci_transport_synchronous()){ 513 hci_release_packet_buffer(); 514 // notify upper stack that iit might be possible to send again 515 uint8_t event[] = { DAEMON_EVENT_HCI_PACKET_SENT, 0}; |
512 hci_stack->packet_handler(HCI_EVENT_PACKET, &event[0], sizeof(event)); | 516 hci_emit_event(&event[0], sizeof(event), 0); // don't dump |
513 } 514 515 return err; 516} 517 518// pre: caller has reserved the packet buffer 519int hci_send_acl_packet_buffer(int size){ 520 --- 66 unchanged lines hidden (view full) --- 587 588 hci_dump_packet( HCI_SCO_DATA_PACKET, 0, packet, size); 589 int err = hci_stack->hci_transport->send_packet(HCI_SCO_DATA_PACKET, packet, size); 590 591 if (hci_transport_synchronous()){ 592 hci_release_packet_buffer(); 593 // notify upper stack that iit might be possible to send again 594 uint8_t event[] = { DAEMON_EVENT_HCI_PACKET_SENT, 0}; | 517 } 518 519 return err; 520} 521 522// pre: caller has reserved the packet buffer 523int hci_send_acl_packet_buffer(int size){ 524 --- 66 unchanged lines hidden (view full) --- 591 592 hci_dump_packet( HCI_SCO_DATA_PACKET, 0, packet, size); 593 int err = hci_stack->hci_transport->send_packet(HCI_SCO_DATA_PACKET, packet, size); 594 595 if (hci_transport_synchronous()){ 596 hci_release_packet_buffer(); 597 // notify upper stack that iit might be possible to send again 598 uint8_t event[] = { DAEMON_EVENT_HCI_PACKET_SENT, 0}; |
595 hci_stack->packet_handler(HCI_EVENT_PACKET, &event[0], sizeof(event)); | 599 hci_emit_event(&event[0], sizeof(event), 0); // don't dump |
596 } 597 598 return err; 599} 600 601static void acl_handler(uint8_t *packet, int size){ 602 603 // log_info("acl_handler: size %u", size); --- 40 unchanged lines hidden (view full) --- 644 memcpy(&conn->acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + conn->acl_recombination_pos], &packet[4], acl_length ); 645 conn->acl_recombination_pos += acl_length; 646 647 // log_error( "ACL Cont Fragment: acl_len %u, combined_len %u, l2cap_len %u", acl_length, 648 // conn->acl_recombination_pos, conn->acl_recombination_length); 649 650 // forward complete L2CAP packet if complete. 651 if (conn->acl_recombination_pos >= conn->acl_recombination_length + 4 + 4){ // pos already incl. ACL header | 600 } 601 602 return err; 603} 604 605static void acl_handler(uint8_t *packet, int size){ 606 607 // log_info("acl_handler: size %u", size); --- 40 unchanged lines hidden (view full) --- 648 memcpy(&conn->acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + conn->acl_recombination_pos], &packet[4], acl_length ); 649 conn->acl_recombination_pos += acl_length; 650 651 // log_error( "ACL Cont Fragment: acl_len %u, combined_len %u, l2cap_len %u", acl_length, 652 // conn->acl_recombination_pos, conn->acl_recombination_length); 653 654 // forward complete L2CAP packet if complete. 655 if (conn->acl_recombination_pos >= conn->acl_recombination_length + 4 + 4){ // pos already incl. ACL header |
652 653 hci_stack->packet_handler(HCI_ACL_DATA_PACKET, &conn->acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE], conn->acl_recombination_pos); | 656 hci_emit_acl_packet(&conn->acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE], conn->acl_recombination_pos); |
654 // reset recombination buffer 655 conn->acl_recombination_length = 0; 656 conn->acl_recombination_pos = 0; 657 } 658 break; 659 660 case 0x02: { // first fragment 661 --- 5 unchanged lines hidden (view full) --- 667 668 // peek into L2CAP packet! 669 uint16_t l2cap_length = READ_L2CAP_LENGTH( packet ); 670 671 // log_info( "ACL First Fragment: acl_len %u, l2cap_len %u", acl_length, l2cap_length); 672 673 // compare fragment size to L2CAP packet size 674 if (acl_length >= l2cap_length + 4){ | 657 // reset recombination buffer 658 conn->acl_recombination_length = 0; 659 conn->acl_recombination_pos = 0; 660 } 661 break; 662 663 case 0x02: { // first fragment 664 --- 5 unchanged lines hidden (view full) --- 670 671 // peek into L2CAP packet! 672 uint16_t l2cap_length = READ_L2CAP_LENGTH( packet ); 673 674 // log_info( "ACL First Fragment: acl_len %u, l2cap_len %u", acl_length, l2cap_length); 675 676 // compare fragment size to L2CAP packet size 677 if (acl_length >= l2cap_length + 4){ |
675 | |
676 // forward fragment as L2CAP packet | 678 // forward fragment as L2CAP packet |
677 hci_stack->packet_handler(HCI_ACL_DATA_PACKET, packet, acl_length + 4); 678 | 679 hci_emit_acl_packet(packet, acl_length + 4); |
679 } else { 680 681 if (acl_length > HCI_ACL_BUFFER_SIZE){ 682 log_error( "ACL First Fragment to large: fragment %u > buffer size %u for handle 0x%02x", 683 4 + acl_length, 4 + HCI_ACL_BUFFER_SIZE, con_handle); 684 return; 685 } 686 --- 138 unchanged lines hidden (view full) --- 825 memcpy(&event[pos], &packet[offset], 1+1+6); // event type + address type + address 826 offset += 8; 827 pos += 8; 828 event[pos++] = packet[offset + 1 + data_length]; // rssi 829 event[pos++] = packet[offset++]; //data_length; 830 memcpy(&event[pos], &packet[offset], data_length); 831 pos += data_length; 832 offset += data_length + 1; // rssi | 680 } else { 681 682 if (acl_length > HCI_ACL_BUFFER_SIZE){ 683 log_error( "ACL First Fragment to large: fragment %u > buffer size %u for handle 0x%02x", 684 4 + acl_length, 4 + HCI_ACL_BUFFER_SIZE, con_handle); 685 return; 686 } 687 --- 138 unchanged lines hidden (view full) --- 826 memcpy(&event[pos], &packet[offset], 1+1+6); // event type + address type + address 827 offset += 8; 828 pos += 8; 829 event[pos++] = packet[offset + 1 + data_length]; // rssi 830 event[pos++] = packet[offset++]; //data_length; 831 memcpy(&event[pos], &packet[offset], data_length); 832 pos += data_length; 833 offset += data_length + 1; // rssi |
833 hci_dump_packet( HCI_EVENT_PACKET, 0, event, pos); 834 hci_stack->packet_handler(HCI_EVENT_PACKET, event, pos); | 834 hci_emit_event(event, pos, 1); |
835 } 836} 837#endif 838 839static uint32_t hci_transport_uart_get_main_baud_rate(void){ 840 if (!hci_stack->config) return 0; 841 uint32_t baud_rate = ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main; 842 // Limit baud rate for Broadcom chipsets to 3 mbps --- 911 unchanged lines hidden (view full) --- 1754 // help with BT sleep 1755 if (hci_stack->state == HCI_STATE_FALLING_ASLEEP 1756 && hci_stack->substate == HCI_FALLING_ASLEEP_W4_WRITE_SCAN_ENABLE 1757 && COMMAND_COMPLETE_EVENT(packet, hci_write_scan_enable)){ 1758 hci_initializing_next_state(); 1759 } 1760 1761 // notify upper stack | 835 } 836} 837#endif 838 839static uint32_t hci_transport_uart_get_main_baud_rate(void){ 840 if (!hci_stack->config) return 0; 841 uint32_t baud_rate = ((hci_transport_config_uart_t *)hci_stack->config)->baudrate_main; 842 // Limit baud rate for Broadcom chipsets to 3 mbps --- 911 unchanged lines hidden (view full) --- 1754 // help with BT sleep 1755 if (hci_stack->state == HCI_STATE_FALLING_ASLEEP 1756 && hci_stack->substate == HCI_FALLING_ASLEEP_W4_WRITE_SCAN_ENABLE 1757 && COMMAND_COMPLETE_EVENT(packet, hci_write_scan_enable)){ 1758 hci_initializing_next_state(); 1759 } 1760 1761 // notify upper stack |
1762 hci_stack->packet_handler(HCI_EVENT_PACKET, packet, size); 1763 | 1762 hci_emit_event(packet, size, 0); // don't dump, already happened in packet handler 1763 |
1764 // moved here to give upper stack a chance to close down everything with hci_connection_t intact 1765 if (packet[0] == HCI_EVENT_DISCONNECTION_COMPLETE){ 1766 if (!packet[2]){ 1767 handle = little_endian_read_16(packet, 3); 1768 hci_connection_t * aConn = hci_connection_for_handle(handle); 1769 if (aConn) { 1770 uint8_t status = aConn->bonding_status; 1771 uint16_t flags = aConn->bonding_flags; --- 28 unchanged lines hidden (view full) --- 1800 break; 1801 case HCI_SCO_DATA_PACKET: 1802 sco_handler(packet, size); 1803 default: 1804 break; 1805 } 1806} 1807 | 1764 // moved here to give upper stack a chance to close down everything with hci_connection_t intact 1765 if (packet[0] == HCI_EVENT_DISCONNECTION_COMPLETE){ 1766 if (!packet[2]){ 1767 handle = little_endian_read_16(packet, 3); 1768 hci_connection_t * aConn = hci_connection_for_handle(handle); 1769 if (aConn) { 1770 uint8_t status = aConn->bonding_status; 1771 uint16_t flags = aConn->bonding_flags; --- 28 unchanged lines hidden (view full) --- 1800 break; 1801 case HCI_SCO_DATA_PACKET: 1802 sco_handler(packet, size); 1803 default: 1804 break; 1805 } 1806} 1807 |
1808/** 1809 * @brief Add event packet handler. 1810 */ 1811void hci_add_event_handler(btstack_packet_callback_registration_t * callback_handler){ 1812 btstack_linked_list_add_tail(&hci_stack->event_handlers, (btstack_linked_item_t*) callback_handler); 1813} 1814 1815 |
|
1808/** Register HCI packet handlers */ 1809void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){ 1810 hci_stack->packet_handler = handler; 1811} 1812 1813/** 1814 * @brief Registers a packet handler for SCO data. Used for HSP and HFP profiles. 1815 */ --- 1049 unchanged lines hidden (view full) --- 2865 va_end(argptr); 2866 2867 return hci_send_cmd_packet(packet, size); 2868} 2869 2870// Create various non-HCI events. 2871// TODO: generalize, use table similar to hci_create_command 2872 | 1816/** Register HCI packet handlers */ 1817void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){ 1818 hci_stack->packet_handler = handler; 1819} 1820 1821/** 1822 * @brief Registers a packet handler for SCO data. Used for HSP and HFP profiles. 1823 */ --- 1049 unchanged lines hidden (view full) --- 2873 va_end(argptr); 2874 2875 return hci_send_cmd_packet(packet, size); 2876} 2877 2878// Create various non-HCI events. 2879// TODO: generalize, use table similar to hci_create_command 2880 |
2881static void hci_emit_event(uint8_t * event, uint16_t size, int dump){ 2882 if (dump) { 2883 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 2884 } 2885 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); 2886} 2887 2888static void hci_emit_acl_packet(uint8_t * packet, uint16_t size){ 2889 hci_stack->packet_handler(HCI_ACL_DATA_PACKET, packet, size); 2890} 2891 |
|
2873void hci_emit_state(void){ 2874 log_info("BTSTACK_EVENT_STATE %u", hci_stack->state); 2875 uint8_t event[3]; 2876 event[0] = BTSTACK_EVENT_STATE; 2877 event[1] = sizeof(event) - 2; 2878 event[2] = hci_stack->state; | 2892void hci_emit_state(void){ 2893 log_info("BTSTACK_EVENT_STATE %u", hci_stack->state); 2894 uint8_t event[3]; 2895 event[0] = BTSTACK_EVENT_STATE; 2896 event[1] = sizeof(event) - 2; 2897 event[2] = hci_stack->state; |
2879 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 2880 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); | 2898 hci_emit_event(event, sizeof(event), 1); |
2881} 2882 2883void hci_emit_connection_complete(hci_connection_t *conn, uint8_t status){ 2884 uint8_t event[13]; 2885 event[0] = HCI_EVENT_CONNECTION_COMPLETE; 2886 event[1] = sizeof(event) - 2; 2887 event[2] = status; 2888 little_endian_store_16(event, 3, conn->con_handle); 2889 bt_flip_addr(&event[5], conn->address); 2890 event[11] = 1; // ACL connection 2891 event[12] = 0; // encryption disabled | 2899} 2900 2901void hci_emit_connection_complete(hci_connection_t *conn, uint8_t status){ 2902 uint8_t event[13]; 2903 event[0] = HCI_EVENT_CONNECTION_COMPLETE; 2904 event[1] = sizeof(event) - 2; 2905 event[2] = status; 2906 little_endian_store_16(event, 3, conn->con_handle); 2907 bt_flip_addr(&event[5], conn->address); 2908 event[11] = 1; // ACL connection 2909 event[12] = 0; // encryption disabled |
2892 hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event)); 2893 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); | 2910 hci_emit_event(event, sizeof(event), 1); |
2894} 2895 2896static void hci_emit_le_connection_complete(uint8_t address_type, bd_addr_t address, uint16_t conn_handle, uint8_t status){ 2897 uint8_t event[21]; 2898 event[0] = HCI_EVENT_LE_META; 2899 event[1] = sizeof(event) - 2; 2900 event[2] = HCI_SUBEVENT_LE_CONNECTION_COMPLETE; 2901 event[3] = status; 2902 little_endian_store_16(event, 4, conn_handle); 2903 event[6] = 0; // TODO: role 2904 event[7] = address_type; 2905 bt_flip_addr(&event[8], address); 2906 little_endian_store_16(event, 14, 0); // interval 2907 little_endian_store_16(event, 16, 0); // latency 2908 little_endian_store_16(event, 18, 0); // supervision timeout 2909 event[20] = 0; // master clock accuracy | 2911} 2912 2913static void hci_emit_le_connection_complete(uint8_t address_type, bd_addr_t address, uint16_t conn_handle, uint8_t status){ 2914 uint8_t event[21]; 2915 event[0] = HCI_EVENT_LE_META; 2916 event[1] = sizeof(event) - 2; 2917 event[2] = HCI_SUBEVENT_LE_CONNECTION_COMPLETE; 2918 event[3] = status; 2919 little_endian_store_16(event, 4, conn_handle); 2920 event[6] = 0; // TODO: role 2921 event[7] = address_type; 2922 bt_flip_addr(&event[8], address); 2923 little_endian_store_16(event, 14, 0); // interval 2924 little_endian_store_16(event, 16, 0); // latency 2925 little_endian_store_16(event, 18, 0); // supervision timeout 2926 event[20] = 0; // master clock accuracy |
2910 hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event)); 2911 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); | 2927 hci_emit_event(event, sizeof(event), 1); |
2912} 2913 2914void hci_emit_disconnection_complete(uint16_t handle, uint8_t reason){ 2915 uint8_t event[6]; 2916 event[0] = HCI_EVENT_DISCONNECTION_COMPLETE; 2917 event[1] = sizeof(event) - 2; 2918 event[2] = 0; // status = OK 2919 little_endian_store_16(event, 3, handle); 2920 event[5] = reason; | 2928} 2929 2930void hci_emit_disconnection_complete(uint16_t handle, uint8_t reason){ 2931 uint8_t event[6]; 2932 event[0] = HCI_EVENT_DISCONNECTION_COMPLETE; 2933 event[1] = sizeof(event) - 2; 2934 event[2] = 0; // status = OK 2935 little_endian_store_16(event, 3, handle); 2936 event[5] = reason; |
2921 hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event)); 2922 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); | 2937 hci_emit_event(event, sizeof(event), 1); |
2923} 2924 2925void hci_emit_l2cap_check_timeout(hci_connection_t *conn){ 2926 if (disable_l2cap_timeouts) return; 2927 log_info("L2CAP_EVENT_TIMEOUT_CHECK"); 2928 uint8_t event[4]; 2929 event[0] = L2CAP_EVENT_TIMEOUT_CHECK; 2930 event[1] = sizeof(event) - 2; 2931 little_endian_store_16(event, 2, conn->con_handle); | 2938} 2939 2940void hci_emit_l2cap_check_timeout(hci_connection_t *conn){ 2941 if (disable_l2cap_timeouts) return; 2942 log_info("L2CAP_EVENT_TIMEOUT_CHECK"); 2943 uint8_t event[4]; 2944 event[0] = L2CAP_EVENT_TIMEOUT_CHECK; 2945 event[1] = sizeof(event) - 2; 2946 little_endian_store_16(event, 2, conn->con_handle); |
2932 hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event)); 2933 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); | 2947 hci_emit_event(event, sizeof(event), 1); |
2934} 2935 2936void hci_emit_nr_connections_changed(void){ 2937 log_info("BTSTACK_EVENT_NR_CONNECTIONS_CHANGED %u", nr_hci_connections()); 2938 uint8_t event[3]; 2939 event[0] = BTSTACK_EVENT_NR_CONNECTIONS_CHANGED; 2940 event[1] = sizeof(event) - 2; 2941 event[2] = nr_hci_connections(); | 2948} 2949 2950void hci_emit_nr_connections_changed(void){ 2951 log_info("BTSTACK_EVENT_NR_CONNECTIONS_CHANGED %u", nr_hci_connections()); 2952 uint8_t event[3]; 2953 event[0] = BTSTACK_EVENT_NR_CONNECTIONS_CHANGED; 2954 event[1] = sizeof(event) - 2; 2955 event[2] = nr_hci_connections(); |
2942 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 2943 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); | 2956 hci_emit_event(event, sizeof(event), 1); |
2944} 2945 2946void hci_emit_hci_open_failed(void){ 2947 log_info("BTSTACK_EVENT_POWERON_FAILED"); 2948 uint8_t event[2]; 2949 event[0] = BTSTACK_EVENT_POWERON_FAILED; 2950 event[1] = sizeof(event) - 2; | 2957} 2958 2959void hci_emit_hci_open_failed(void){ 2960 log_info("BTSTACK_EVENT_POWERON_FAILED"); 2961 uint8_t event[2]; 2962 event[0] = BTSTACK_EVENT_POWERON_FAILED; 2963 event[1] = sizeof(event) - 2; |
2951 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 2952 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); | 2964 hci_emit_event(event, sizeof(event), 1); |
2953} 2954 2955void hci_emit_system_bluetooth_enabled(uint8_t enabled){ 2956 log_info("BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED %u", enabled); 2957 uint8_t event[3]; 2958 event[0] = BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED; 2959 event[1] = sizeof(event) - 2; 2960 event[2] = enabled; | 2965} 2966 2967void hci_emit_system_bluetooth_enabled(uint8_t enabled){ 2968 log_info("BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED %u", enabled); 2969 uint8_t event[3]; 2970 event[0] = BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED; 2971 event[1] = sizeof(event) - 2; 2972 event[2] = enabled; |
2961 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 2962 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); | 2973 hci_emit_event(event, sizeof(event), 1); |
2963} 2964 2965void hci_emit_remote_name_cached(bd_addr_t addr, device_name_t *name){ 2966 uint8_t event[2+1+6+248+1]; // +1 for \0 in log_info 2967 event[0] = BTSTACK_EVENT_REMOTE_NAME_CACHED; 2968 event[1] = sizeof(event) - 2 - 1; 2969 event[2] = 0; // just to be compatible with HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE 2970 bt_flip_addr(&event[3], addr); 2971 memcpy(&event[9], name, 248); 2972 2973 event[9+248] = 0; // assert \0 for log_info 2974 log_info("BTSTACK_EVENT_REMOTE_NAME_CACHED %s = '%s'", bd_addr_to_str(addr), &event[9]); 2975 | 2974} 2975 2976void hci_emit_remote_name_cached(bd_addr_t addr, device_name_t *name){ 2977 uint8_t event[2+1+6+248+1]; // +1 for \0 in log_info 2978 event[0] = BTSTACK_EVENT_REMOTE_NAME_CACHED; 2979 event[1] = sizeof(event) - 2 - 1; 2980 event[2] = 0; // just to be compatible with HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE 2981 bt_flip_addr(&event[3], addr); 2982 memcpy(&event[9], name, 248); 2983 2984 event[9+248] = 0; // assert \0 for log_info 2985 log_info("BTSTACK_EVENT_REMOTE_NAME_CACHED %s = '%s'", bd_addr_to_str(addr), &event[9]); 2986 |
2976 hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event)-1); 2977 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)-1); | 2987 hci_emit_event(event, sizeof(event), 1); |
2978} 2979 2980void hci_emit_discoverable_enabled(uint8_t enabled){ 2981 log_info("BTSTACK_EVENT_DISCOVERABLE_ENABLED %u", enabled); 2982 uint8_t event[3]; 2983 event[0] = BTSTACK_EVENT_DISCOVERABLE_ENABLED; 2984 event[1] = sizeof(event) - 2; 2985 event[2] = enabled; | 2988} 2989 2990void hci_emit_discoverable_enabled(uint8_t enabled){ 2991 log_info("BTSTACK_EVENT_DISCOVERABLE_ENABLED %u", enabled); 2992 uint8_t event[3]; 2993 event[0] = BTSTACK_EVENT_DISCOVERABLE_ENABLED; 2994 event[1] = sizeof(event) - 2; 2995 event[2] = enabled; |
2986 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 2987 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); | 2996 hci_emit_event(event, sizeof(event), 1); |
2988} 2989 2990void hci_emit_security_level(hci_con_handle_t con_handle, gap_security_level_t level){ 2991 log_info("hci_emit_security_level %u for handle %x", level, con_handle); 2992 uint8_t event[5]; 2993 int pos = 0; 2994 event[pos++] = GAP_EVENT_SECURITY_LEVEL; 2995 event[pos++] = sizeof(event) - 2; 2996 little_endian_store_16(event, 2, con_handle); 2997 pos += 2; 2998 event[pos++] = level; | 2997} 2998 2999void hci_emit_security_level(hci_con_handle_t con_handle, gap_security_level_t level){ 3000 log_info("hci_emit_security_level %u for handle %x", level, con_handle); 3001 uint8_t event[5]; 3002 int pos = 0; 3003 event[pos++] = GAP_EVENT_SECURITY_LEVEL; 3004 event[pos++] = sizeof(event) - 2; 3005 little_endian_store_16(event, 2, con_handle); 3006 pos += 2; 3007 event[pos++] = level; |
2999 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 3000 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); | 3008 hci_emit_event(event, sizeof(event), 1); |
3001} 3002 3003void hci_emit_dedicated_bonding_result(bd_addr_t address, uint8_t status){ 3004 log_info("hci_emit_dedicated_bonding_result %u ", status); 3005 uint8_t event[9]; 3006 int pos = 0; 3007 event[pos++] = GAP_EVENT_DEDICATED_BONDING_COMPLETED; 3008 event[pos++] = sizeof(event) - 2; 3009 event[pos++] = status; 3010 bt_flip_addr( &event[pos], address); 3011 pos += 6; | 3009} 3010 3011void hci_emit_dedicated_bonding_result(bd_addr_t address, uint8_t status){ 3012 log_info("hci_emit_dedicated_bonding_result %u ", status); 3013 uint8_t event[9]; 3014 int pos = 0; 3015 event[pos++] = GAP_EVENT_DEDICATED_BONDING_COMPLETED; 3016 event[pos++] = sizeof(event) - 2; 3017 event[pos++] = status; 3018 bt_flip_addr( &event[pos], address); 3019 pos += 6; |
3012 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 3013 hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); | 3020 hci_emit_event(event, sizeof(event), 1); |
3014} 3015 3016// query if remote side supports eSCO 3017int hci_remote_eSCO_supported(hci_con_handle_t con_handle){ 3018 hci_connection_t * connection = hci_connection_for_handle(con_handle); 3019 if (!connection) return 0; 3020 return connection->remote_supported_feature_eSCO; 3021} --- 503 unchanged lines hidden --- | 3021} 3022 3023// query if remote side supports eSCO 3024int hci_remote_eSCO_supported(hci_con_handle_t con_handle){ 3025 hci_connection_t * connection = hci_connection_for_handle(con_handle); 3026 if (!connection) return 0; 3027 return connection->remote_supported_feature_eSCO; 3028} --- 503 unchanged lines hidden --- |