hci.c (ceecb9d95af3568dc69d06a9255b87392ca1dd19) | hci.c (6fab74db98118d4d08e575fb4b432de22e5f4849) |
---|---|
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 --- 1640 unchanged lines hidden (view full) --- 1649 // skip write le host if not supported (e.g. on LE only EM9301) 1650 if (hci_stack->local_supported_commands[0] & 0x02) break; 1651 hci_stack->substate = HCI_INIT_LE_SET_EVENT_MASK; 1652 return; 1653 1654 1655#ifdef ENABLE_LE_DATA_LENGTH_EXTENSION 1656 case HCI_INIT_W4_WRITE_LE_HOST_SUPPORTED: | 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 --- 1640 unchanged lines hidden (view full) --- 1649 // skip write le host if not supported (e.g. on LE only EM9301) 1650 if (hci_stack->local_supported_commands[0] & 0x02) break; 1651 hci_stack->substate = HCI_INIT_LE_SET_EVENT_MASK; 1652 return; 1653 1654 1655#ifdef ENABLE_LE_DATA_LENGTH_EXTENSION 1656 case HCI_INIT_W4_WRITE_LE_HOST_SUPPORTED: |
1657 log_info("Supported commands %x", hci_stack->local_supported_commands[0] & 0x30); |
|
1657 if ((hci_stack->local_supported_commands[0] & 0x30) == 0x30){ 1658 hci_stack->substate = HCI_INIT_LE_SET_EVENT_MASK; 1659 return; 1660 } 1661 // explicit fall through to reduce repetitions 1662#endif 1663 1664#ifdef ENABLE_LE_CENTRAL --- 541 unchanged lines hidden (view full) --- 2206#endif 2207 2208#ifdef ENABLE_BLE 2209 case HCI_EVENT_LE_META: 2210 switch (packet[2]){ 2211#ifdef ENABLE_LE_CENTRAL 2212 case HCI_SUBEVENT_LE_ADVERTISING_REPORT: 2213 // log_info("advertising report received"); | 1658 if ((hci_stack->local_supported_commands[0] & 0x30) == 0x30){ 1659 hci_stack->substate = HCI_INIT_LE_SET_EVENT_MASK; 1660 return; 1661 } 1662 // explicit fall through to reduce repetitions 1663#endif 1664 1665#ifdef ENABLE_LE_CENTRAL --- 541 unchanged lines hidden (view full) --- 2207#endif 2208 2209#ifdef ENABLE_BLE 2210 case HCI_EVENT_LE_META: 2211 switch (packet[2]){ 2212#ifdef ENABLE_LE_CENTRAL 2213 case HCI_SUBEVENT_LE_ADVERTISING_REPORT: 2214 // log_info("advertising report received"); |
2214 if (hci_stack->le_scanning_state != LE_SCANNING) break; | 2215 if (!hci_stack->le_scanning_enabled) break; |
2215 le_handle_advertisement_report(packet, size); 2216 break; 2217#endif 2218 case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: 2219 // Connection management 2220 reverse_bd_addr(&packet[8], addr); 2221 addr_type = (bd_addr_type_t)packet[7]; 2222 log_info("LE Connection_complete (status=%u) type %u, %s", packet[3], addr_type, bd_addr_to_str(addr)); --- 187 unchanged lines hidden (view full) --- 2410 hci_stack->new_scan_enable_value = 0xff; 2411 2412 // LE 2413#ifdef ENABLE_BLE 2414 memset(hci_stack->le_random_address, 0, 6); 2415 hci_stack->le_random_address_set = 0; 2416#endif 2417#ifdef ENABLE_LE_CENTRAL | 2216 le_handle_advertisement_report(packet, size); 2217 break; 2218#endif 2219 case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: 2220 // Connection management 2221 reverse_bd_addr(&packet[8], addr); 2222 addr_type = (bd_addr_type_t)packet[7]; 2223 log_info("LE Connection_complete (status=%u) type %u, %s", packet[3], addr_type, bd_addr_to_str(addr)); --- 187 unchanged lines hidden (view full) --- 2411 hci_stack->new_scan_enable_value = 0xff; 2412 2413 // LE 2414#ifdef ENABLE_BLE 2415 memset(hci_stack->le_random_address, 0, 6); 2416 hci_stack->le_random_address_set = 0; 2417#endif 2418#ifdef ENABLE_LE_CENTRAL |
2418 hci_stack->le_scanning_state = LE_SCAN_IDLE; | 2419 hci_stack->le_scanning_active = 0; |
2419 hci_stack->le_scan_type = 0xff; 2420 hci_stack->le_connecting_state = LE_CONNECTING_IDLE; 2421 hci_stack->le_whitelist = 0; 2422 hci_stack->le_whitelist_capacity = 0; 2423#endif 2424} 2425 2426#ifdef ENABLE_CLASSIC --- 577 unchanged lines hidden (view full) --- 3004 3005#ifdef ENABLE_BLE 3006 // advertisements, active scanning, and creating connections requires randaom address to be set if using private address 3007 if ((hci_stack->state == HCI_STATE_WORKING) 3008 && (hci_stack->le_own_addr_type == BD_ADDR_TYPE_LE_PUBLIC || hci_stack->le_random_address_set)){ 3009 3010#ifdef ENABLE_LE_CENTRAL 3011 // handle le scan | 2420 hci_stack->le_scan_type = 0xff; 2421 hci_stack->le_connecting_state = LE_CONNECTING_IDLE; 2422 hci_stack->le_whitelist = 0; 2423 hci_stack->le_whitelist_capacity = 0; 2424#endif 2425} 2426 2427#ifdef ENABLE_CLASSIC --- 577 unchanged lines hidden (view full) --- 3005 3006#ifdef ENABLE_BLE 3007 // advertisements, active scanning, and creating connections requires randaom address to be set if using private address 3008 if ((hci_stack->state == HCI_STATE_WORKING) 3009 && (hci_stack->le_own_addr_type == BD_ADDR_TYPE_LE_PUBLIC || hci_stack->le_random_address_set)){ 3010 3011#ifdef ENABLE_LE_CENTRAL 3012 // handle le scan |
3012 switch(hci_stack->le_scanning_state){ 3013 case LE_START_SCAN: 3014 hci_stack->le_scanning_state = LE_SCANNING; 3015 hci_send_cmd(&hci_le_set_scan_enable, 1, 0); 3016 return; 3017 3018 case LE_STOP_SCAN: 3019 hci_stack->le_scanning_state = LE_SCAN_IDLE; 3020 hci_send_cmd(&hci_le_set_scan_enable, 0, 0); 3021 return; 3022 default: 3023 break; | 3013 if ((hci_stack->le_scanning_enabled != hci_stack->le_scanning_active)){ 3014 hci_stack->le_scanning_active = hci_stack->le_scanning_enabled; 3015 hci_send_cmd(&hci_le_set_scan_enable, hci_stack->le_scanning_enabled, 0); 3016 return; |
3024 } 3025 if (hci_stack->le_scan_type != 0xff){ 3026 // defaults: active scanning, accept all advertisement packets 3027 int scan_type = hci_stack->le_scan_type; 3028 hci_stack->le_scan_type = 0xff; 3029 hci_send_cmd(&hci_le_set_scan_parameters, scan_type, hci_stack->le_scan_interval, hci_stack->le_scan_window, hci_stack->le_own_addr_type, 0); 3030 return; 3031 } --- 980 unchanged lines hidden (view full) --- 4012 hci_stack->local_name = local_name; 4013} 4014 4015 4016#ifdef ENABLE_BLE 4017 4018#ifdef ENABLE_LE_CENTRAL 4019void gap_start_scan(void){ | 3017 } 3018 if (hci_stack->le_scan_type != 0xff){ 3019 // defaults: active scanning, accept all advertisement packets 3020 int scan_type = hci_stack->le_scan_type; 3021 hci_stack->le_scan_type = 0xff; 3022 hci_send_cmd(&hci_le_set_scan_parameters, scan_type, hci_stack->le_scan_interval, hci_stack->le_scan_window, hci_stack->le_own_addr_type, 0); 3023 return; 3024 } --- 980 unchanged lines hidden (view full) --- 4005 hci_stack->local_name = local_name; 4006} 4007 4008 4009#ifdef ENABLE_BLE 4010 4011#ifdef ENABLE_LE_CENTRAL 4012void gap_start_scan(void){ |
4020 if (hci_stack->le_scanning_state == LE_SCANNING) return; 4021 hci_stack->le_scanning_state = LE_START_SCAN; | 4013 hci_stack->le_scanning_enabled = 1; |
4022 hci_run(); 4023} 4024 4025void gap_stop_scan(void){ | 4014 hci_run(); 4015} 4016 4017void gap_stop_scan(void){ |
4026 if ( hci_stack->le_scanning_state == LE_SCAN_IDLE) return; 4027 hci_stack->le_scanning_state = LE_STOP_SCAN; | 4018 hci_stack->le_scanning_enabled = 0; |
4028 hci_run(); 4029} 4030 4031void gap_set_scan_parameters(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window){ 4032 hci_stack->le_scan_type = scan_type; 4033 hci_stack->le_scan_interval = scan_interval; 4034 hci_stack->le_scan_window = scan_window; 4035 hci_run(); --- 589 unchanged lines hidden --- | 4019 hci_run(); 4020} 4021 4022void gap_set_scan_parameters(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window){ 4023 hci_stack->le_scan_type = scan_type; 4024 hci_stack->le_scan_interval = scan_interval; 4025 hci_stack->le_scan_window = scan_window; 4026 hci_run(); --- 589 unchanged lines hidden --- |