gap: provide gap_remote_name_request

This commit is contained in:
Matthias Ringwald 2017-05-21 22:44:47 +02:00
parent f5875de52c
commit b7f1ee76fc
4 changed files with 50 additions and 3 deletions

View File

@ -106,8 +106,7 @@ static void do_next_remote_name_request(void){
if (devices[i].state == REMOTE_NAME_REQUEST){
devices[i].state = REMOTE_NAME_INQUIRED;
printf("Get remote name of %s...\n", bd_addr_to_str(devices[i].address));
hci_send_cmd(&hci_remote_name_request, devices[i].address,
devices[i].pageScanRepetitionMode, 0, devices[i].clockOffset | 0x8000);
gap_remote_name_request( devices[i].address, devices[i].pageScanRepetitionMode, devices[i].clockOffset | 0x8000);
return;
}
}
@ -182,7 +181,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
printf("Device found: %s ", bd_addr_to_str(addr));
printf("with COD: 0x%06x, ", (unsigned int) gap_event_inquiry_result_get_class_of_device(packet));
printf("pageScan %d, ", devices[deviceCount].pageScanRepetitionMode);
printf("clock offset 0x%04x",devices[deviceCount].clockOffset);
printf("clock offset 0x%04x",devices[deviceCount].clockOffset & 0x7fff);
if (gap_event_inquiry_result_get_rssi_availabe(packet)){
printf(", rssi %d dBm", (int8_t) gap_event_inquiry_result_get_rssi(packet));
}

View File

@ -389,6 +389,15 @@ int gap_inquiry_start(uint8_t duration_in_1280ms_units);
*/
int gap_inquiry_stop(void);
/**
* @brief Remote Name Request
* @param addr
* @param page_scan_repetition_mode
* @param clock_offset only used when bit 15 is set - pass 0 if not known
* @events: HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE
*/
int gap_remote_name_request(bd_addr_t addr, uint8_t page_scan_repetition_mode, uint16_t clock_offset);
// LE
/**

View File

@ -109,6 +109,11 @@
#define GAP_INQUIRY_STATE_W2_CANCEL 0x81
#define GAP_INQUIRY_STATE_W4_CANCELLED 0x82
// GAP Remote Name Request
#define GAP_REMOTE_NAME_STATE_IDLE 0
#define GAP_REMOTE_NAME_STATE_W2_SEND 1
#define GAP_REMOTE_NAME_STATE_W4_COMPLETE 2
// prototypes
#ifdef ENABLE_CLASSIC
static void hci_update_scan_enable(void);
@ -1778,6 +1783,11 @@ static void event_handler(uint8_t *packet, int size){
hci_emit_event(event, sizeof(event), 1);
}
break;
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
if (hci_stack->remote_name_state == GAP_REMOTE_NAME_STATE_W4_COMPLETE){
hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_IDLE;
}
break;
case HCI_EVENT_CONNECTION_REQUEST:
reverse_bd_addr(&packet[2], addr);
// TODO: eval COD 8-10
@ -2797,6 +2807,12 @@ static void hci_run(void){
hci_send_cmd(&hci_inquiry_cancel);
return;
}
// remote name request
if (hci_stack->remote_name_state == GAP_REMOTE_NAME_STATE_W2_SEND){
hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_W4_COMPLETE;
hci_send_cmd(&hci_remote_name_request, hci_stack->remote_name_addr,
hci_stack->remote_name_page_scan_repetition_mode, hci_stack->remote_name_clock_offset);
}
#endif
#ifdef ENABLE_BLE
@ -4185,6 +4201,24 @@ int gap_inquiry_stop(void){
return 0;
}
/**
* @brief Remote Name Request
* @param addr
* @param page_scan_repetition_mode
* @param clock_offset only used when bit 15 is set
* @events: HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE
*/
int gap_remote_name_request(bd_addr_t addr, uint8_t page_scan_repetition_mode, uint16_t clock_offset){
if (hci_stack->remote_name_state != GAP_REMOTE_NAME_STATE_IDLE) return ERROR_CODE_COMMAND_DISALLOWED;
memcpy(hci_stack->remote_name_addr, addr, 6);
hci_stack->remote_name_page_scan_repetition_mode = page_scan_repetition_mode;
hci_stack->remote_name_clock_offset = clock_offset;
hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_W2_SEND;
hci_run();
return 0;
}
/**
* @brief Set inquiry mode: standard, with RSSI, with RSSI + Extended Inquiry Results. Has to be called before power on.
* @param inquiry_mode see bluetooth_defines.h

View File

@ -731,6 +731,11 @@ typedef struct {
uint8_t cmds_ready;
uint8_t inquiry_state; // see hci.c for state defines
bd_addr_t remote_name_addr;
uint16_t remote_name_clock_offset;
uint8_t remote_name_page_scan_repetition_mode;
uint8_t remote_name_state; // see hci.c for state defines
uint8_t discoverable;
uint8_t connectable;
uint8_t bondable;