From ad0d11084a1c827f3dc7ac9a3037c803c439640e Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 17 Aug 2017 11:15:45 +0200 Subject: [PATCH] hci: create EIR data based on local name if not set --- src/gap.h | 6 ++++-- src/hci.c | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/gap.h b/src/gap.h index cd0768286..6949e1302 100644 --- a/src/gap.h +++ b/src/gap.h @@ -125,16 +125,18 @@ 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 Default name is 'BTstack 00:00:00:00:00:00' * @note '00:00:00:00:00:00' in local_name will be replaced with actual name + * @param name is not copied, make sure memory is accessible during stack startup */ void gap_set_local_name(const char * local_name); /** * @brief Set Extended Inquiry Response data * @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 If not set, local name will be used for EIR data (see gap_set_local_name) * @note '00:00:00:00:00:00' in local_name will be replaced with actual name + * @param eir_data size 240 bytes, is not copied make sure memory is accessible during stack startup */ void gap_set_extended_inquiry_response(const uint8_t * data); diff --git a/src/hci.c b/src/hci.c index d07ee8353..679f180c6 100644 --- a/src/hci.c +++ b/src/hci.c @@ -1290,7 +1290,15 @@ static void hci_initializing_run(void){ packet[1] = opcode >> 8; packet[2] = 1 + 240; packet[3] = 0; // FEC not required - memcpy(&packet[4], hci_stack->eir_data, 240); + if (hci_stack->eir_data){ + memcpy(&packet[4], hci_stack->eir_data, 240); + } else { + memset(&packet[4], 0, 240); + int name_len = strlen(hci_stack->local_name); + packet[4] = name_len + 1; + packet[5] = BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME; + memcpy(&packet[6], hci_stack->local_name, name_len); + } // 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); @@ -1616,12 +1624,6 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){ return; #endif - case HCI_INIT_W4_WRITE_LOCAL_NAME: - // skip write eir data if no eir data set - if (hci_stack->eir_data) break; - hci_stack->substate = HCI_INIT_WRITE_INQUIRY_MODE; - return; - #ifdef ENABLE_SCO_OVER_HCI case HCI_INIT_W4_WRITE_SCAN_ENABLE: // skip write synchronous flow control if not supported