Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NUS Central and Peripheral MAC Filter and Whitelist

Hello everyone,

I developed an application that makes it possible to scan devices and retransmit your advertisements. In addition to enabling the connection with peripheral devices, it also allows the connection to a central device, retransmitting data via the NUS service from the central to the peripherals.

Currently, I filter the devices that I want to retransmit the advertising through the following code in the scan_evt_handler() function.

case NRF_BLE_SCAN_EVT_NOT_FOUND:
            if(memcmp("\xac\x31\x38",&p_scan_evt->params.p_not_found->peer_addr.addr[3],3) == 0){
            ...
            }

As I understand it, I'm actually receiving all the advertising but I only perform the retransmission if the condition of the device starting with MAC 38:31:AC is satisfied, correct? For performance reasons would it be better to use a MAC filter so that this filtering is done in Softdevice or would there be no difference? If there is a difference, I want to carry out this implementation, but I haven't seen any example that the implementation is carried out from a MAC range.

In the filter implementations I found, I see that the filter is applied to a specific MAC, but what I want is to listen to all devices that start with MAC 38:31:AC, is it possible to do this? If yes, could you provide me with an example?

My other doubt would be in relation to retransmission through NUS. Is it possible when retransmitting data from the peripheral or central, choose the device I'm going to connect to and send the data through the MAC of this device? I saw some examples doing this by the connection identifier, but I would like to know who to direct the data to according to the MAC, as I will not maintain a connection with peripherals, I just connect to send data. In short, I would like to establish a connection and send data only if the device has a specific MAC. 

How to do this, can you give me an example?

I'm open to suggestions, I'd like to do this with the best possible performance, either with a whitelist or filters. Thank you very much.

I'm using nRF 52840, Softdevice S140, nRF5 SDK 17.0.2 and my application has a  nus central + nus + beacon.

  • Hi,

    In the filter implementations I found, I see that the filter is applied to a specific MAC, but what I want is to listen to all devices that start with MAC 38:31:AC, is it possible to do this? If yes, could you provide me with an example?

    That is not possible with the SoftDevice whitelisting, and also whitelisting is about controlling connections, so it does not do what you want in any case. So you need to continue to parse the Bluetooth address on your own, as you are doing.

    In short, I would like to establish a connection and send data only if the device has a specific MAC. 

    Here it sounds like you only want to establish connections with devices with a specific address? If so, that is precisely what whitelisting is for. If you just want to filter a specific address, then I suggest you look at this post. Whitelisting is similar both in central and peripheral roles.

  • Thanks for the reply Einar. 

    I chose to use filters instead of whitelist, as I mentioned in my application I have the combination of peripheral uart, central uart, and beacon. The beacon is always advertising, and within its function I stop the scan every 0.5 seconds because I change the address of the beacon. 

    I noticed that whenever I connect to a peripheral, I get error 8, NRF_ERROR_INVALID_STATE, when calling the stop scan function inside the beacon function. Is there any way to get around this problem or will I have to stop the beacon ads when I'm connected to some peripheral?

    If it's not possible to work around this problem, and I really shouldn't call scan stop when connected, is there any flag, variable, that I can always check for connection before calling scan stop? Or do I need to create a flag myself and set 1 when connecting, and set 0 when disconnected?

  • Einar, as I said the filter was working, but the filter applied previously was related to the UUID, I tried to add a filter referring to the address, and I'm not successful! I've checked it several times, I've also tried using examples and I can't get the address filter to work!

    Could you take a look at my code to see what's going on? I don't get any error, I find the mac searched for filter through the scan but I never get a match. I've tried running examples and I can never get connection using the address filter, I found several cases with the same problem... is this a bug in sdk 17.0.2?

  • Hi,

    There is in fact a bug in the scan filter module which was fixed in SDK 17.1.0, which prevented filtering on some public Bluetooth addresses (where the two most significant bits were incorrectly assumes to indicate address type). You can work around this by using  nrf_ble_scan.c and  nrf_ble_scan.h from SDK 17.1.0 in your 17.0.2 based application.

    Another typical issue is to mix up endianness if yo manually add address, so if the above does not help that is also worth checking.

  • I made the recommendation, replace nrf_ble_scan.c and nrf_ble_scan.h from SDK 17.1.0 in SDK 17.0.2, not successful, still not getting address match, in relation to address byte order, I can guarantee that it is correct, because using the same filter settings and address identification using an example from SDK 17.1.0 get success.

    Could you try to identify in my code what is happening? I can send you in private!

Related