This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-EM-CC2340R5: Scan request for advertisers from central device

Part Number: LP-EM-CC2340R5
Other Parts Discussed in Thread: CC2340R5, SYSCONFIG

Tool/software:

Hi, I am using CC2340R5 and the ble sdk version: simplelink_lowpower_f3_sdk_8_40_02_01. 

I want my central to scan for all nearby advertisers but only send a scan request to the advertiser which I dynamically add to the allowlist. 

Is there any filter policy for scanning in this particular way ? 

  • Hello,

    Thank you for reaching out! To do this, you will need to set the filter policy to SCAN_FLT_POLICY_AL. I've also included a link to the filter policy options below.

    https://dev.ti.com/tirex/explore/content/simplelink_lowpower_f3_sdk_8_40_02_01/docs/ble5stack/ble_user_guide/doxygen/ble/html/group___gap_scan___structs.html#ga5be84ddb41dcf5fd6ba2e5e1fda1b2b3

    I hope this helps!

    Best Regards,

    Tarek

  •  Hi Tarek, 

    Thanks for your quick response.

    I actually am aware of the accept list scan filter, but what I am looking for is: 

    The central will be scanning for all the advertisers, but only send scan request to the device that are part of accept list. 

    Accept only advertising packets from devices where the advertiser's address is in the acceptlist. Directed advertising packets which are not addressed to this device shall be ignored.

    As the above statement clearly states that only the device that are part of accept list will be scanned by the central, but what I am looking for is that the central should listen to all the advertisers but only send scan request to the one which are part of accept list.

    I hope my query is clear to you now. 

  • Hello,

    Thanks for clarifying! From what you're describing, it seems like you would like the central to passively scan, until it scans an advertisement from the accept list. Unfortunately, the BLE stack does not have a conditional active scanning option (It is not specified in the BLE spec).

    One way to achieve your desired behavior is to initially set the central to passively scan, then, upon scanning the advertisement of the desired device, add the device's address to the acceptlist. Afterwards, dynamically set the device to perform active scanning using filter policy: SCAN_FLT_POLICY_AL

    To do this:

    1. Go to the Sysconfig file of the project
    2. Inside the BLE menu, scroll down and select Observer Configuration
    3. Set "Scan Type" to Passive
    4. Go to app_central.c file
    5. Add the following event to the centralScanHandler event handler:
      BLEAppUtil_EventHandler_t centralScanHandler =
      {
          .handlerType    = BLEAPPUTIL_GAP_SCAN_TYPE,
          .pEventHandler  = Central_ScanEventHandler,
          .eventMask      = BLEAPPUTIL_SCAN_ENABLED |
                            BLEAPPUTIL_SCAN_DISABLED |
                            BLEAPPUTIL_ADV_REPORT // ADD THIS
      };
    6. Scroll down to the Central_ScanEventHandler() and add a case for the BLEAPUTIL_ADV_REPORT as follows:
      case BLEAPPUTIL_ADV_REPORT:
      {
          bleStk_GapScan_Evt_AdvRpt_t *pScanRpt = &scanMsg->pBuf->pAdvReport;
          if (pScanRpt->pData != NULL)
          {
              uint8_t indx = 0;
              for (; indx < pScanRpt->dataLen; indx++)
              {
                  MenuModule_printf(APP_MENU_SCAN_EVENT + indx, 0, "Data: %d", pScanRpt->pData[indx]);
              }
          }
          break;
      }
    7. Process pScanRpt->addr (which is the address of each advertiser that was scanned) as you wish, and when you find the device address that you would like to add to the accept list, use the function HCI_LE_AddAcceptListCmd() to dynamically add the address to the accept list.
    8. Set the filter policy to SCAN_FLT_POLICY_AL using GapScan_SetParams()
    9. Set the scanning type to active by using GapScan_setPhyParams()

    For more info on our Scanning and Advertising, please check out our SimpleLink Academy Trainings found in the link below:
    dev.ti.com/.../node

    I hope this answers you question!

    Best Regards,

    Tarek

  • First of all thanks Tarek D for such a detailed explanation. 

    I do completely get the approach you are suggesting, but the problem here is my application wherein all the devices on the first hand would be central and they will switch the mode to advertiser as a fallback mechanism, which is completely random i.e it can happen at any certain moment in real time. 

    Now keeping my central in passive scan and making the desired advertiser added in the accept list, and then manually changing the scanning filter to scan only for the advertiser in accept list, will not be a suited workaround for me. 

    As there is a possibility that there can be any other central which did fallback to advertiser, and now cannot be scanned by the central as the central is scanning only for the device that are part of the accept list.

    Please do let me know if you do have a workaround for this. It would be really helpful. 

    The only possible approach is to make my central scan for all the advertisers, which would in turn cause my central to send scan request to all the advertisers, even the ones which are not of my interest at all. 

    The main agenda here is to, make my central send scan request only to the devices which are of my interest as it would definitely help me in not getting bombarded with multiple scan response.

  • Hello,

    Thank you for clarifying! Unfortunately, there isn't a specific process described by the BLE spec to achieve this behavior. One thing that you can possibly attempt to do is to follow the procedure I included above, then, upon establishing a connection with the device that you have added to the accept list, dynamically change the filter policy back to SCAN_FLT_POLICY_ALL, and change the scanning type back to passive, until you see another address you'd like to add to the accept list.

    I hope this helps!

    Best Regards,

    Tarek

  • Hi Tarek! 

    First of all thanks for your support. I do have an architecture in mind keeping all the BLE specifications in mind, before which I want one small confirmation. 

    For a scan request, there will be a scan response which will be sent by the peripheral. The event which will be triggered for the peripheral for the scan request would be BLEAPPUTIL_SCAN_REQ_RECEIVED.

    Now my query would be that whether I can customize my scan response for each scan request, as there will be multiple scan request for the devices in the vicinity I would like to customize scan response for each particular device. Will that be possible ? 

  • Hello Sushant,

    The BLE spec does not specifically include a process that would allow the user to customize the scan response based on the scan request. According to the BLE spec:

    "The Payload consists of AdvA and ScanRspData fields. The AdvA field shall contain the advertiser’s public or random device address as indicated by TxAdd. The ScanRspData field may contain any data from the advertiser’s Host." BLE spec v.54, Volume 6, Part B, Section 2.3.2.2

    Though not specifically mentioned, the scan response can contain specific information regarding the host of the advertiser, without the ability to customize.

    One option I would recommend trying is using extended advertisements, as they allow for a bigger payload, so you can send the information you would like, then parse that data as you please on the central side. 

    I hope this answers your question!

    Best Regards,

    Tarek