hci.c (f5875de52c2368de57990d41b456c83e57f8f0ee) | hci.c (b7f1ee76fc01b4587d4b3491e7884299bad22f99) |
---|---|
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 --- 95 unchanged lines hidden (view full) --- 104// GAP inquiry state: 0 = off, 0x01 - 0x30 = requested duration, 0xfe = active, 0xff = stop requested 105#define GAP_INQUIRY_DURATION_MIN 0x01 106#define GAP_INQUIRY_DURATION_MAX 0x30 107#define GAP_INQUIRY_STATE_ACTIVE 0x80 108#define GAP_INQUIRY_STATE_IDLE 0 109#define GAP_INQUIRY_STATE_W2_CANCEL 0x81 110#define GAP_INQUIRY_STATE_W4_CANCELLED 0x82 111 | 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 --- 95 unchanged lines hidden (view full) --- 104// GAP inquiry state: 0 = off, 0x01 - 0x30 = requested duration, 0xfe = active, 0xff = stop requested 105#define GAP_INQUIRY_DURATION_MIN 0x01 106#define GAP_INQUIRY_DURATION_MAX 0x30 107#define GAP_INQUIRY_STATE_ACTIVE 0x80 108#define GAP_INQUIRY_STATE_IDLE 0 109#define GAP_INQUIRY_STATE_W2_CANCEL 0x81 110#define GAP_INQUIRY_STATE_W4_CANCELLED 0x82 111 |
112// GAP Remote Name Request 113#define GAP_REMOTE_NAME_STATE_IDLE 0 114#define GAP_REMOTE_NAME_STATE_W2_SEND 1 115#define GAP_REMOTE_NAME_STATE_W4_COMPLETE 2 116 |
|
112// prototypes 113#ifdef ENABLE_CLASSIC 114static void hci_update_scan_enable(void); 115static void hci_emit_discoverable_enabled(uint8_t enabled); 116static int hci_local_ssp_activated(void); 117static int hci_remote_ssp_supported(hci_con_handle_t con_handle); 118static void hci_notify_if_sco_can_send_now(void); 119static void hci_emit_connection_complete(bd_addr_t address, hci_con_handle_t con_handle, uint8_t status); --- 1653 unchanged lines hidden (view full) --- 1773#ifdef ENABLE_CLASSIC 1774 case HCI_EVENT_INQUIRY_COMPLETE: 1775 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_ACTIVE){ 1776 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; 1777 uint8_t event[] = { GAP_EVENT_INQUIRY_COMPLETE, 1, 0}; 1778 hci_emit_event(event, sizeof(event), 1); 1779 } 1780 break; | 117// prototypes 118#ifdef ENABLE_CLASSIC 119static void hci_update_scan_enable(void); 120static void hci_emit_discoverable_enabled(uint8_t enabled); 121static int hci_local_ssp_activated(void); 122static int hci_remote_ssp_supported(hci_con_handle_t con_handle); 123static void hci_notify_if_sco_can_send_now(void); 124static void hci_emit_connection_complete(bd_addr_t address, hci_con_handle_t con_handle, uint8_t status); --- 1653 unchanged lines hidden (view full) --- 1778#ifdef ENABLE_CLASSIC 1779 case HCI_EVENT_INQUIRY_COMPLETE: 1780 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_ACTIVE){ 1781 hci_stack->inquiry_state = GAP_INQUIRY_STATE_IDLE; 1782 uint8_t event[] = { GAP_EVENT_INQUIRY_COMPLETE, 1, 0}; 1783 hci_emit_event(event, sizeof(event), 1); 1784 } 1785 break; |
1786 case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE: 1787 if (hci_stack->remote_name_state == GAP_REMOTE_NAME_STATE_W4_COMPLETE){ 1788 hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_IDLE; 1789 } 1790 break; |
|
1781 case HCI_EVENT_CONNECTION_REQUEST: 1782 reverse_bd_addr(&packet[2], addr); 1783 // TODO: eval COD 8-10 1784 link_type = packet[11]; 1785 log_info("Connection_incoming: %s, type %u", bd_addr_to_str(addr), link_type); 1786 addr_type = link_type == 1 ? BD_ADDR_TYPE_CLASSIC : BD_ADDR_TYPE_SCO; 1787 conn = hci_connection_for_bd_addr_and_type(addr, addr_type); 1788 if (!conn) { --- 1003 unchanged lines hidden (view full) --- 2792 hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, duration, 0); 2793 return; 2794 } 2795 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_W2_CANCEL){ 2796 hci_stack->inquiry_state = GAP_INQUIRY_STATE_W4_CANCELLED; 2797 hci_send_cmd(&hci_inquiry_cancel); 2798 return; 2799 } | 1791 case HCI_EVENT_CONNECTION_REQUEST: 1792 reverse_bd_addr(&packet[2], addr); 1793 // TODO: eval COD 8-10 1794 link_type = packet[11]; 1795 log_info("Connection_incoming: %s, type %u", bd_addr_to_str(addr), link_type); 1796 addr_type = link_type == 1 ? BD_ADDR_TYPE_CLASSIC : BD_ADDR_TYPE_SCO; 1797 conn = hci_connection_for_bd_addr_and_type(addr, addr_type); 1798 if (!conn) { --- 1003 unchanged lines hidden (view full) --- 2802 hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, duration, 0); 2803 return; 2804 } 2805 if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_W2_CANCEL){ 2806 hci_stack->inquiry_state = GAP_INQUIRY_STATE_W4_CANCELLED; 2807 hci_send_cmd(&hci_inquiry_cancel); 2808 return; 2809 } |
2810 // remote name request 2811 if (hci_stack->remote_name_state == GAP_REMOTE_NAME_STATE_W2_SEND){ 2812 hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_W4_COMPLETE; 2813 hci_send_cmd(&hci_remote_name_request, hci_stack->remote_name_addr, 2814 hci_stack->remote_name_page_scan_repetition_mode, hci_stack->remote_name_clock_offset); 2815 } |
|
2800#endif 2801 2802#ifdef ENABLE_BLE 2803 // advertisements, active scanning, and creating connections requires randaom address to be set if using private address 2804 if ((hci_stack->state == HCI_STATE_WORKING) 2805 && (hci_stack->le_own_addr_type == BD_ADDR_TYPE_LE_PUBLIC || hci_stack->le_random_address_set)){ 2806 2807#ifdef ENABLE_LE_CENTRAL --- 1372 unchanged lines hidden (view full) --- 4180 return 0; 4181 } 4182 if (hci_stack->inquiry_state != GAP_INQUIRY_STATE_ACTIVE) return ERROR_CODE_COMMAND_DISALLOWED; 4183 hci_stack->inquiry_state = GAP_INQUIRY_STATE_W2_CANCEL; 4184 hci_run(); 4185 return 0; 4186} 4187 | 2816#endif 2817 2818#ifdef ENABLE_BLE 2819 // advertisements, active scanning, and creating connections requires randaom address to be set if using private address 2820 if ((hci_stack->state == HCI_STATE_WORKING) 2821 && (hci_stack->le_own_addr_type == BD_ADDR_TYPE_LE_PUBLIC || hci_stack->le_random_address_set)){ 2822 2823#ifdef ENABLE_LE_CENTRAL --- 1372 unchanged lines hidden (view full) --- 4196 return 0; 4197 } 4198 if (hci_stack->inquiry_state != GAP_INQUIRY_STATE_ACTIVE) return ERROR_CODE_COMMAND_DISALLOWED; 4199 hci_stack->inquiry_state = GAP_INQUIRY_STATE_W2_CANCEL; 4200 hci_run(); 4201 return 0; 4202} 4203 |
4204 |
|
4188/** | 4205/** |
4206 * @brief Remote Name Request 4207 * @param addr 4208 * @param page_scan_repetition_mode 4209 * @param clock_offset only used when bit 15 is set 4210 * @events: HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE 4211 */ 4212int gap_remote_name_request(bd_addr_t addr, uint8_t page_scan_repetition_mode, uint16_t clock_offset){ 4213 if (hci_stack->remote_name_state != GAP_REMOTE_NAME_STATE_IDLE) return ERROR_CODE_COMMAND_DISALLOWED; 4214 memcpy(hci_stack->remote_name_addr, addr, 6); 4215 hci_stack->remote_name_page_scan_repetition_mode = page_scan_repetition_mode; 4216 hci_stack->remote_name_clock_offset = clock_offset; 4217 hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_W2_SEND; 4218 hci_run(); 4219 return 0; 4220} 4221 4222/** |
|
4189 * @brief Set inquiry mode: standard, with RSSI, with RSSI + Extended Inquiry Results. Has to be called before power on. 4190 * @param inquiry_mode see bluetooth_defines.h 4191 */ 4192void hci_set_inquiry_mode(inquiry_mode_t mode){ 4193 hci_stack->inquiry_mode = mode; 4194} 4195 4196/** --- 46 unchanged lines hidden --- | 4223 * @brief Set inquiry mode: standard, with RSSI, with RSSI + Extended Inquiry Results. Has to be called before power on. 4224 * @param inquiry_mode see bluetooth_defines.h 4225 */ 4226void hci_set_inquiry_mode(inquiry_mode_t mode){ 4227 hci_stack->inquiry_mode = mode; 4228} 4229 4230/** --- 46 unchanged lines hidden --- |