You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2020/03/05 08:54:32 UTC

[GitHub] [mynewt-nimble] sjanc commented on a change in pull request #765: nimble/host: Fix check for valid static random address

sjanc commented on a change in pull request #765: nimble/host: Fix check for valid static random address
URL: https://github.com/apache/mynewt-nimble/pull/765#discussion_r388152582
 
 

 ##########
 File path: nimble/host/src/ble_hs_id.c
 ##########
 @@ -58,14 +58,20 @@ ble_hs_id_set_rnd(const uint8_t *rnd_addr)
 {
     uint8_t addr_type_byte;
     int rc;
-    uint8_t all_zeros[BLE_DEV_ADDR_LEN] = {0}, all_ones[BLE_DEV_ADDR_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+    int i, rnd_part_sum = 0;
 
 
 Review comment:
   I'd make those checks explicit so that it obvious what is being check.
   Something like this maybe?
   
   int
   ble_hs_id_set_rnd(const uint8_t *rnd_addr)
   {
       uint8_t addr_type_byte;
       int ones;
       int rc;
   
       /* Make sure random part of rnd_addr is not all ones or zeros */
       addr_type_byte = rnd_addr[5] & 0xc0;
   
       /* count bits set to 1 in address */
       ones = __builtin_popcount(rnd_addr[0]);
       ones += __builtin_popcount(rnd_addr[1]);
       ones += __builtin_popcount(rnd_addr[2]);
       ones += __builtin_popcount(rnd_addr[3]);
       ones += __builtin_popcount(rnd_addr[4]);
       ones += __builtin_popcount(rnd_addr[5] & 0x3f);
   
       if ((addr_type_byte != 0x00 && addr_type_byte != 0xc0) ||
               (ones == 0 || ones == 46)) {
           return BLE_HS_EINVAL;
       }
   
       ble_hs_lock();
       rc = ble_hs_hci_util_set_random_addr(rnd_addr);
       if (rc == 0) {
           memcpy(ble_hs_id_rnd, rnd_addr, 6);
       }
       ble_hs_unlock();
   
       return rc;
   }
   
   
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services