From 0f453238797a4d2d675ec8901aa883a89435f6fd Mon Sep 17 00:00:00 2001 From: Jiang Jiang Jian Date: Thu, 15 Mar 2018 14:14:47 +0800 Subject: [PATCH] Merge branch 'bugfix/btdm_string_to_bdaddr_error_when_opening_nano' into 'master' component/bt: Fix bug: string_to_bdaddr() error when opening nano See merge request idf/esp-idf!1981 (cherry picked from commit 047870fd8098ffb7b958f7c753fd25e3db5676df) 54320d5f component/bt: Fix bug: string_to_bdaddr() error when opening nano --- components/bt/bluedroid/btcore/bdaddr.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/components/bt/bluedroid/btcore/bdaddr.c b/components/bt/bluedroid/btcore/bdaddr.c index e69bb53e1f..e2466fa6bb 100644 --- a/components/bt/bluedroid/btcore/bdaddr.c +++ b/components/bt/bluedroid/btcore/bdaddr.c @@ -102,10 +102,13 @@ bool string_to_bdaddr(const char *string, bt_bdaddr_t *addr) bt_bdaddr_t new_addr; uint8_t *ptr = new_addr.address; - bool ret = sscanf(string, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", - &ptr[0], &ptr[1], &ptr[2], &ptr[3], &ptr[4], &ptr[5]) == 6; - + uint32_t ptr_32[6]; + bool ret = sscanf(string, "%02x:%02x:%02x:%02x:%02x:%02x", + &ptr_32[0], &ptr_32[1], &ptr_32[2], &ptr_32[3], &ptr_32[4], &ptr_32[5]) == 6; if (ret) { + for (uint8_t i = 0; i < 6; i++){ + ptr[i] = (uint8_t) ptr_32[i]; + } memcpy(addr, &new_addr, sizeof(bt_bdaddr_t)); }