From 29af07f3ba587d5b1f1bccb11c7d8156a7dbc2c1 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 16 Aug 2017 17:26:48 +0200 Subject: [PATCH] hci: replace '00:00:00:00:00:00' placeholder in EIR data with actual BD ADDR --- src/gap.h | 4 +++- src/hci.c | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/gap.h b/src/gap.h index bc97b86ea..cd0768286 100644 --- a/src/gap.h +++ b/src/gap.h @@ -126,13 +126,15 @@ gap_connection_type_t gap_get_connection_type(hci_con_handle_t connection_handle * @brief Sets local name. * @note has to be done before stack starts up * @param name is not copied, make sure memory is accessible during stack startup + * @note '00:00:00:00:00:00' in local_name will be replaced with actual name */ void gap_set_local_name(const char * local_name); /** * @brief Set Extended Inquiry Response data - * @param eir_data size 240 bytes, is not copied make sure memory is accessible during stack startup * @note has to be done before stack starts up + * @param eir_data size 240 bytes, is not copied make sure memory is accessible during stack startup + * @note '00:00:00:00:00:00' in local_name will be replaced with actual name */ void gap_set_extended_inquiry_response(const uint8_t * data); diff --git a/src/hci.c b/src/hci.c index ff6b01c62..45bb72b40 100644 --- a/src/hci.c +++ b/src/hci.c @@ -1277,10 +1277,23 @@ static void hci_initializing_run(void){ hci_send_cmd_packet(packet, HCI_CMD_HEADER_SIZE + DEVICE_NAME_LEN); break; } - case HCI_INIT_WRITE_EIR_DATA: + case HCI_INIT_WRITE_EIR_DATA: { hci_stack->substate = HCI_INIT_W4_WRITE_EIR_DATA; - hci_send_cmd(&hci_write_extended_inquiry_response, 0, hci_stack->eir_data); + hci_reserve_packet_buffer(); + uint8_t * packet = hci_stack->hci_packet_buffer; + // construct HCI Command and send + uint16_t opcode = hci_write_extended_inquiry_response.opcode; + hci_stack->last_cmd_opcode = opcode; + packet[0] = opcode & 0xff; + packet[1] = opcode >> 8; + packet[2] = 1 + 240; + packet[3] = 0; // FEC not required + memcpy(&packet[4], hci_stack->eir_data, 240); + // expand '00:00:00:00:00:00' in name with bd_addr + hci_replace_bd_addr_placeholder(&packet[4], 240); + hci_send_cmd_packet(packet, HCI_CMD_HEADER_SIZE + DEVICE_NAME_LEN); break; + } case HCI_INIT_WRITE_INQUIRY_MODE: hci_stack->substate = HCI_INIT_W4_WRITE_INQUIRY_MODE; hci_send_cmd(&hci_write_inquiry_mode, (int) hci_stack->inquiry_mode);