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

sd_ble_gap_address_set works for normal mode only?

Hi,

I have learned that you can change the MAC address on a device by using sd_ble_gap_address_set. However, when I press the sw2 button on the beacon (running a modified version of the ble_app_beacon app), the beacon switches back to its original MAC address. I don't understand why this is happening. How can I set the MAC address so that it will stay the same for both normal and config modes?

Thanks!

Parents
  • Yes, I realized that I was calling the function even before flash init. Moving it down the main function helped get rid of it. I also observe another similar problem. I programmatically switch between config and and normal modes in my app and try to update the MAC address after there is a change in one of the characteristics in one of the services. For that I try to update the MAC address in beacon_write_handler function. However, I do not observe this change. What am I doing wrong? The following is how I updated the beacon_write_handler function.

    			case beacon_mac_data:
    			memcpy(&tmp.data.mac_address, data, BCS_DATA_MAC_LEN); 
    			//Also can change the beacons MAC address
    			change_mac_address(tmp.data.mac_address);
    			break;
    

    //Manually change the MAC address to the desired value void change_mac_address(uint8_t my_random_addr[BLE_GAP_ADDR_LEN]){ ble_gap_addr_t gap_addr; uint8_t err_code;

    	// "my_random_addr" must be random generated.
    	//const uint8_t my_random_addr[BLE_GAP_ADDR_LEN] = {6,5,4,3,2,1}; // random address
    	
    	gap_addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
    	memcpy(&gap_addr.addr, my_random_addr, sizeof(gap_addr.addr));
    	gap_addr.addr[5] |= 0xc0; // 2 MSBit must be '11' for RANDOM_STATIC address, see v4.0, Vol 3, Part C, chapter 10.8
    	err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &gap_addr);
    	APP_ERROR_CHECK(err_code);
    

    }

Reply
  • Yes, I realized that I was calling the function even before flash init. Moving it down the main function helped get rid of it. I also observe another similar problem. I programmatically switch between config and and normal modes in my app and try to update the MAC address after there is a change in one of the characteristics in one of the services. For that I try to update the MAC address in beacon_write_handler function. However, I do not observe this change. What am I doing wrong? The following is how I updated the beacon_write_handler function.

    			case beacon_mac_data:
    			memcpy(&tmp.data.mac_address, data, BCS_DATA_MAC_LEN); 
    			//Also can change the beacons MAC address
    			change_mac_address(tmp.data.mac_address);
    			break;
    

    //Manually change the MAC address to the desired value void change_mac_address(uint8_t my_random_addr[BLE_GAP_ADDR_LEN]){ ble_gap_addr_t gap_addr; uint8_t err_code;

    	// "my_random_addr" must be random generated.
    	//const uint8_t my_random_addr[BLE_GAP_ADDR_LEN] = {6,5,4,3,2,1}; // random address
    	
    	gap_addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
    	memcpy(&gap_addr.addr, my_random_addr, sizeof(gap_addr.addr));
    	gap_addr.addr[5] |= 0xc0; // 2 MSBit must be '11' for RANDOM_STATIC address, see v4.0, Vol 3, Part C, chapter 10.8
    	err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &gap_addr);
    	APP_ERROR_CHECK(err_code);
    

    }

Children
No Data
Related