mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-19 15:40:52 +00:00
gap: support reading RSSI for Classic+LE using gap_read_rssi. Emits GAP_EVENT_RSSI_MEASUREMENT
This commit is contained in:
parent
6268fbfe8d
commit
891b9fc269
@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
### Fixed
|
||||
|
||||
### Added
|
||||
- gap: allow to reject GAP classic connection via gap_register_classic_connection_filter
|
||||
- GAP: allow to reject GAP classic connection via gap_register_classic_connection_filter
|
||||
- GAP: support reading RSSI for Classic+LE using gap_read_rssi. Emits GAP_EVENT_RSSI_MEASUREMENT
|
||||
|
||||
## Changed
|
||||
|
||||
|
@ -1046,6 +1046,14 @@ typedef uint8_t sm_key_t[16];
|
||||
*/
|
||||
#define GAP_EVENT_INQUIRY_COMPLETE 0xE4
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param con_handle
|
||||
* @param rssi (signed integer -127..127)
|
||||
* @note Classic: rssi is in dB relative to Golden Receive Power Range
|
||||
* @note LE: rssi is absolute dBm
|
||||
*/
|
||||
#define GAP_EVENT_RSSI_MEASUREMENT 0xE5
|
||||
|
||||
// Meta Events, see below for sub events
|
||||
#define HCI_EVENT_HSP_META 0xE8
|
||||
|
@ -3258,6 +3258,25 @@ static inline uint8_t gap_event_inquiry_complete_get_status(const uint8_t * even
|
||||
return event[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get field con_handle from event GAP_EVENT_RSSI_MEASUREMENT
|
||||
* @param event packet
|
||||
* @return con_handle
|
||||
* @note: btstack_type H
|
||||
*/
|
||||
static inline hci_con_handle_t gap_event_rssi_measurement_get_con_handle(const uint8_t * event){
|
||||
return little_endian_read_16(event, 2);
|
||||
}
|
||||
/**
|
||||
* @brief Get field rssi from event GAP_EVENT_RSSI_MEASUREMENT
|
||||
* @param event packet
|
||||
* @return rssi
|
||||
* @note: btstack_type 1
|
||||
*/
|
||||
static inline uint8_t gap_event_rssi_measurement_get_rssi(const uint8_t * event){
|
||||
return event[4];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get field status from event HCI_SUBEVENT_LE_CONNECTION_COMPLETE
|
||||
* @param event packet
|
||||
|
@ -553,6 +553,13 @@ int gap_inquiry_stop(void);
|
||||
*/
|
||||
int gap_remote_name_request(bd_addr_t addr, uint8_t page_scan_repetition_mode, uint16_t clock_offset);
|
||||
|
||||
/**
|
||||
* @brief Read RSSI
|
||||
* @param con_handle
|
||||
* @events: GAP_EVENT_RSSI_MEASUREMENT
|
||||
*/
|
||||
int gap_read_rssi(hci_con_handle_t con_handle);
|
||||
|
||||
/**
|
||||
* @brief Legacy Pairing Pin Code Response
|
||||
* @param addr
|
||||
|
23
src/hci.c
23
src/hci.c
@ -1916,6 +1916,15 @@ static void event_handler(uint8_t *packet, int size){
|
||||
hci_stack->sco_data_packet_length, hci_stack->sco_packets_total_num);
|
||||
}
|
||||
}
|
||||
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_rssi)){
|
||||
if (packet[5] == 0){
|
||||
uint8_t event[5];
|
||||
event[0] = GAP_EVENT_RSSI_MEASUREMENT;
|
||||
event[1] = 3;
|
||||
memcpy(&event[2], &packet[6], 3);
|
||||
hci_emit_event(event, sizeof(event), 1);
|
||||
}
|
||||
}
|
||||
#ifdef ENABLE_BLE
|
||||
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_le_read_buffer_size)){
|
||||
hci_stack->le_data_packets_length = little_endian_read_16(packet, 6);
|
||||
@ -3581,6 +3590,12 @@ static void hci_run(void){
|
||||
// no further commands if connection is about to get shut down
|
||||
if (connection->state == SENT_DISCONNECT) continue;
|
||||
|
||||
if (connection->authentication_flags & READ_RSSI){
|
||||
connectionClearAuthenticationFlags(connection, READ_RSSI);
|
||||
hci_send_cmd(&hci_read_rssi, connection->con_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLASSIC
|
||||
if (connection->authentication_flags & HANDLE_LINK_KEY_REQUEST){
|
||||
log_info("responding to link key request");
|
||||
@ -4957,6 +4972,14 @@ int gap_remote_name_request(bd_addr_t addr, uint8_t page_scan_repetition_mode, u
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gap_read_rssi(hci_con_handle_t con_handle){
|
||||
hci_connection_t * hci_connection = hci_connection_for_handle(con_handle);
|
||||
if (hci_connection == NULL) return 0;
|
||||
connectionSetAuthenticationFlags(hci_connection, READ_RSSI);
|
||||
hci_run();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int gap_pairing_set_state_and_run(bd_addr_t addr, uint8_t state){
|
||||
hci_stack->gap_pairing_state = state;
|
||||
memcpy(hci_stack->gap_pairing_addr, addr, 6);
|
||||
|
@ -197,6 +197,9 @@ typedef enum {
|
||||
|
||||
// connection status
|
||||
CONNECTION_ENCRYPTED = 0x8000,
|
||||
|
||||
// errands
|
||||
READ_RSSI = 0x10000,
|
||||
} hci_authentication_flags_t;
|
||||
|
||||
/**
|
||||
@ -512,11 +515,11 @@ typedef struct {
|
||||
btstack_timer_source_t timeout_sco;
|
||||
#endif /* ENABLE_CLASSIC */
|
||||
|
||||
// errands
|
||||
// authentication and other errands
|
||||
uint32_t authentication_flags;
|
||||
|
||||
btstack_timer_source_t timeout;
|
||||
|
||||
|
||||
// timeout in system ticks (HAVE_EMBEDDED_TICK) or milliseconds (HAVE_EMBEDDED_TIME_MS)
|
||||
uint32_t timestamp;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user