]> granicus.if.org Git - esp-idf/commitdiff
Component/bt: fixbug_set_rand_addr()
authorzhiweijian <zhiweijian@espressif.com>
Sun, 20 Aug 2017 09:52:57 +0000 (17:52 +0800)
committerzhiweijian <zhiweijian@espressif.com>
Tue, 22 Aug 2017 06:25:10 +0000 (14:25 +0800)
- The two most significant bits of the address shall be equal to 1
- All bits of the random part of the address shall not be equal to 1
- All bits of the random part of the address shall not be equal to 0

components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c

index 9fa28cc43e1dfe7dd3ae4f2a40a118a8175bdb4a..18e7c467e6d82dee2e6d507bf102e1fdb1233a48 100644 (file)
@@ -761,16 +761,27 @@ static void btc_ble_set_rand_addr (BD_ADDR rand_addr)
     param.set_rand_addr_cmpl.status = ESP_BT_STATUS_SUCCESS;
 
     if (rand_addr != NULL) {
-        if((rand_addr[BD_ADDR_LEN - 1] & BT_STATIC_RAND_ADDR_MASK)
-            == BT_STATIC_RAND_ADDR_MASK) {
+        /*
+        A static address is a 48-bit randomly generated address and shall meet the following requirements:
+        • The two most significant bits of the address shall be equal to 1
+        • All bits of the random part of the address shall not be equal to 1
+        • All bits of the random part of the address shall not be equal to 0
+        */
+        BD_ADDR invalid_rand_addr_a, invalid_rand_addr_b;
+        memset(invalid_rand_addr_a, 0xff, sizeof(BD_ADDR));
+        memset(invalid_rand_addr_b, 0x00, sizeof(BD_ADDR));
+        invalid_rand_addr_b[BD_ADDR_LEN - 1] = invalid_rand_addr_b[BD_ADDR_LEN - 1] | BT_STATIC_RAND_ADDR_MASK;
+        if((rand_addr[BD_ADDR_LEN - 1] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK
+            && memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0
+            && memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0){
             BTA_DmSetRandAddress(rand_addr);
         } else {
             param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
-            LOG_ERROR("Invalid randrom address, the high bit should be 0x11xx");
+            LOG_ERROR("Invalid random address, the high bit should be 0b11, the random part shall not be to 1 or 0");
         }
     } else {
         param.set_rand_addr_cmpl.status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
-        LOG_ERROR("Invalid randrom addressm, the address value is NULL");
+        LOG_ERROR("Invalid random addressm, the address value is NULL");
     }
 
     msg.sig = BTC_SIG_API_CB;