This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Direct advertising to any device

Hello everyone.

There have a scenario, nrf52832 starts a direct advertising , but the dest ble device is not bonded(it could be any other central device), when the dest ble device receive the direct advertising it should initiate the connection to advertiser.

Can it work?

Parents Reply Children
  • Simon,I think if the central device is Android device,to edit the whitelist manually also need the IRK.Am I right?

  • Yes, you need the IRK in order to convert the random address into the real address and identify the device.

  • //Global var
    ble_gap_id_key_t oneplus3_key = {
        .id_addr_info={
            0,
            BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
            {0x76,0x53,0xd6,0xfb,0xee,0xc0},          //one_plus3  android phone
        }
    };
    
    //........................
    //........................
    //........................
    //........................
    //........................
    //........................
    
    void init_advertising(void){
    ..................................................................
    ..................................................................
        uint8_t *oneplus3_irk_string = "076b01ad29fcbb56bda76d3c9adb0ec0";  // adb shell ,/data/misc/bluedroid/bt_config.config grep "LOCAL_IRK"
    
        uint8_t temp[2];
        uint8_t *ptr = NULL;
        unsigned long ret = 0;
    
        for (int i = 0,j=0; i < BLE_GAP_SEC_KEY_LEN;i++,j+=2)
        {
            memmove(temp,&oneplus3_irk_string[j],sizeof(uint8_t)*2);
            ret = strtoul(temp, &ptr, 16);
    
            oneplus3_key.id_info.irk[i] = (uint8_t)ret;
        }
        // The irk is right ,I have test it in fast advertising with pm_address_resolve();
    ..............................................................
    ..................................................................
    
    
    
    static void on_adv_evt(ble_adv_evt_t ble_adv_evt){
    ................................................
            case BLE_ADV_EVT_WHITELIST_REQUEST:
            {
                ble_gap_id_key_t* key_list[BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT];
                memset(key_list,0,BLE_GAP_DEVICE_IDENTITIES_MAX_COUNT*sizeof(int));
                key_list[0] =    &oneplus3_key;
                sd_ble_gap_device_identities_set(key_list,NULL,1);
    
                ble_gap_addr_t const* whitelist_addrs_gap[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
    
                ble_gap_addr_t whitelist_addrs[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
                ble_gap_irk_t  whitelist_irks[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
                uint32_t       addr_cnt = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;
                uint32_t       irk_cnt  = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;
    
                whitelist_addrs_gap[0] = &oneplus3_key.id_addr_info;
                memmove(&whitelist_addrs[0],&oneplus3_key.id_addr_info,sizeof(ble_gap_addr_t));
                memmove(&whitelist_irks[0],&oneplus3_key.id_info,sizeof(ble_gap_irk_t));
                addr_cnt = 1;
                irk_cnt = 1;
    
                err_code = sd_ble_gap_whitelist_set(whitelist_addrs_gap, 1);
                APP_ERROR_CHECK(err_code);
    
                // Apply the whitelist.
                err_code = ble_advertising_whitelist_reply(&m_advertising,
                                                           whitelist_addrs,
                                                           addr_cnt,
                                                           whitelist_irks,
                                                           irk_cnt);
                APP_ERROR_CHECK(err_code);
            }
            break;
    ......................................................

    Simon,Thank you for your reply.Could you check the my code snippets? I do the whitelist and nrfConnect can't establish the connection.

  • It seems like, in this post that you have solved the problem regarding whitelisting, is this correct?

Related