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.

CC2340R5: CC2340R5

Part Number: CC2340R5
Other Parts Discussed in Thread: SYSCONFIG,

Tool/software:

Hi,

I have a BLE peripheral device which will pair to a given central. After it is paired with the given central, it should reject connection request from any other central device. 

While a central is sending connection request I want to see which device is sending connection request. If it is some other device other than the paired device , I will reject the connection process from peripheral. Please help me as I am not able to find any relevant way to do this.

  • Hello Satakshi,

    Thanks for reaching out. I would suggest to take a look at this section of the user guide: Privacy and the Filter Accept List. Therefore the following might be helpful:

    1. Add the devices address to the Accept List (AL) right after pairing and bonding.
    2. Enable the Filter option to process conn req from all devices and only scan req from devices in AL.

    Hope this helps.

    David.

  • Hi David,

    Thanks a lot for this information. Modifying the sysconfig is sufficient right and there is nothing I need to add manually in the code correct?

  • Hi David,

    My usecase is slightly different. First time, the peripheral will accept scan and connection request from any central so I am using "Process requests from all devices". Once it is paired to a given central, then from next time onwards it will connect only to that central and not to any other device so I will use Process requests only from devices in WL. So, how to achieve this. For the first time, I do not know the address of my peer device. I will only know after pairing. So, after pairing how to get the address of my central device and make sure from next time I connect only to that and reject connection request from any other central? 

  • Hello Satakshi,

    Thank you for clarifying! You can initially set the filter policy to "Process Requests from all devices" in the advertisement parameters in Sysconfig. This will allow the peripheral to connect to any centrals.

    To identify the central device's address and add it to the AL (Accept List), go to the app_connection.c file located inside the app folder, and direct your attention to the Connection_ConnEventHandler function. Inside the function, you'll notice that upon adding a connection, the example automatically extracts the device's address. All you'll have to do is the following:

    HCI_LE_ClearAcceptListCmd(""); //Ensure the accept list is clear
    HCI_LE_AddAcceptListCmd (gapEstMsg->devAddrType, gapEstMsg->devAddr); //Add a accept list entry

    Now that you've added the device address to the accept list, all you have to do is reconfigure the advertisement settings to make it only possible to connect to that central device. To do so, advertising needs to be temporarily stopped. This can be achieved using the BLEAppUtil_advStop(peripheralAdvHandle_1) function. Once advertising is stopped, you can now change the advertisement parameters using the following code snippet:

    uint8_t advPolicy = GAP_ADV_AL_POLICY_AL_ALL_REQ;
    GapAdv_setParam(peripheralAdvHandle_1, GAP_ADV_PARAM_FITLER_POLICY, &advPolicy);

    You can find the complete list of filter policies here: https://software-dl.ti.com/simplelink/esd/simplelink_lowpower_f3_sdk/7.40.00.64/exports/docs/ble5stack/ble_user_guide/doxygen/ble/html/group___gap_adv___constants.html#gab808d7d2d87b7ca5f358959986f85112

    After you've changed the parameters, you can now restart advertising:

    status = BLEAppUtil_advStart(peripheralAdvHandle_1, &advSetStartParamsSet_1)


    You can also refer to the GAP section in the user guide for more information: BLE5-Stack User's Guide

    Best Regards,

    Tarek

  • Hi David,

    Currently I have not implemented pairing but whatever method you suggested above, I implemented that only with normal connection (no pairing or bonding). So, first time my peripheral is connecting to all devices. But after I connect to a given central it is storing the device address of the central. But next time when the central is sending connection request, I cannot see any link getting established on my peripheral through log but on the central it is showing device connected however it is getting disconnected after few seconds with disconnection status as 0x3E. I have used TI CC2340R5 as the central also.

    Code for my peripheral:

    void Peripheral_GAPConnEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {

    switch (event)
    {
    case BLEAPPUTIL_LINK_ESTABLISHED_EVENT:
    {
    if(firstTime == 0){
    static volatile char status = 0xff;
    static volatile gapEstLinkReqEvent_t *gapEstMsg = NULL;
    gapEstMsg = (gapEstLinkReqEvent_t*) pMsgData;
    HCI_LE_ClearAcceptListCmd(""); //Ensure the accept list is clear
    status = HCI_LE_AddAcceptListCmd(gapEstMsg->devAddrType,
    gapEstMsg->devAddr); //Add a accept list entry
    Log_printf(LogModule0,Log_INFO,"%d",status);
    }
    Log_message(LOG_INFO, "device is connected");
    break;
    }
    case BLEAPPUTIL_LINK_TERMINATED_EVENT:
    {
    gapTerminateLinkEvent_t *term = (gapTerminateLinkEvent_t *)pMsgData;
    if(firstTime==0){
    BLEAppUtil_advStop(peripheralAdvHandle_1);
    uint8_t advPolicy = GAP_ADV_AL_POLICY_AL_ALL_REQ;
    GapAdv_setParam(peripheralAdvHandle_1, GAP_ADV_PARAM_FILTER_POLICY,
    &advPolicy);
    firstTime = 1;
    }
    Log_printf(LogModule0,Log_ERROR, "disconn reason:%d", term->reason);
    HCI_LE_ReadAcceptListSizeCmd();

    BLEAppUtil_advStart(peripheralAdvHandle_1, &advSetStartParamsSet_1);
    break;
    }
    default:
    {
    break;
    }
    }
    }

    Code for my central:

    case BLEAPPUTIL_LINK_ESTABLISHED_EVENT:
    {
    gapEstLinkReqEvent_t *gapEstMsg = (gapEstLinkReqEvent_t *)pMsgData;

    // Add the connection to the connected device list
    Connection_addConnInfo(gapEstMsg->connectionHandle, gapEstMsg->devAddr);

    /*! Print the peer address and connection handle number */
    MenuModule_printf(APP_MENU_CONN_EVENT, 0, "Conn status: Established - "
    "Connected to " MENU_MODULE_COLOR_YELLOW "%s " MENU_MODULE_COLOR_RESET
    "connectionHandle = " MENU_MODULE_COLOR_YELLOW "%d" MENU_MODULE_COLOR_RESET,
    BLEAppUtil_convertBdAddr2Str(gapEstMsg->devAddr), gapEstMsg->connectionHandle);

    /*! Print the number of current connections */
    MenuModule_printf(APP_MENU_NUM_CONNS, 0, "Connections number: "
    MENU_MODULE_COLOR_YELLOW "%d " MENU_MODULE_COLOR_RESET,
    linkDB_NumActive());
    Log_printf(LogModule_App1, Log_INFO, "DEV Connected");

    break;
    }

    case BLEAPPUTIL_LINK_TERMINATED_EVENT:
    {
    gapTerminateLinkEvent_t *gapTermMsg = (gapTerminateLinkEvent_t *)pMsgData;

    // Remove the connection from the conneted device list
    Connection_removeConnInfo(gapTermMsg->connectionHandle);

    /*! Print the peer address and connection handle number */
    MenuModule_printf(APP_MENU_CONN_EVENT, 0, "Conn status: Terminated - "
    "connectionHandle = " MENU_MODULE_COLOR_YELLOW "%d " MENU_MODULE_COLOR_RESET
    "reason = " MENU_MODULE_COLOR_YELLOW "%d" MENU_MODULE_COLOR_RESET,
    gapTermMsg->connectionHandle, gapTermMsg->reason);

    /*! Print the number of current connections */
    MenuModule_printf(APP_MENU_NUM_CONNS, 0, "Connections number: "
    MENU_MODULE_COLOR_YELLOW "%d " MENU_MODULE_COLOR_RESET,
    linkDB_NumActive());
    Log_printf(LogModule_App1, Log_INFO, "DEV DisConnected:%x", gapTermMsg->reason);

    break;
    }

    However, if I use the filter policy as GAP_ADV_AL_POLICY_AL_SCAN_REQ, then no disconnection is happening and my peripheral remains connected to the central. But I want my peripheral to scan and connect from only AL devices from second time. 

    Please help me to find out what is going wrong?

    In sysconfig, filter policy is set to process requests from all device. After first time connection only, I am changing the filter policy to process requests only from AL.

    Also, can you please highlight the difference between directed advertisement and filter policy "scan and connect only from device in AL"?

  • Hi Satakshi,

    The 0x3E error is a "failed to establish" error that occurs if the master is unable to receive a packet from the slave within the first 6 connection events after sending a connection request. We simulated the project on our end and it worked. Here are the changes we made:

    1- The devices are connecting but not pairing, therefore, the device address is not being added to the accept list. To fix this, using a phone, connect to the device using the SimpleLink app, then you could simply read characteristic 5, which prompts the device to pair to the launchpad. Another way is editing the peripheral's sysconfig file. As seen in the screenshot below, you can change the "Pairing Mode" parameter to "Initiate a pairing request", to pair the devices once connected, as well as check the "Sync Acceptlist with Bonded Devices" option that David mentioned earlier. You could also uncheck MITM protection to bypass the authentication check. Make sure that the peripheral displays "Bond Saved", before disconnecting from it.

    2- To simulate this prompt, we added our changes to the app_pairing.c file, inside the Pairing_pairStateHandler function, specifically in the BLEAPPUTIL_PAIRING_STATE_COMPLETE case. I've attached a code snippet below. Please make sure to extern the peripheral advertisement handler by writing: extern uint8 peripheralAdvHandle_1.

    // The pairing is completed, so update the entry in connection list
    // to the ID address instead of the RP address
    linkDBInfo_t linkInfo;
    // Get the list of connected devices
    App_connInfo* connList = Connection_getConnList();
    
    uint8_t advPolicy = GAP_ADV_AL_POLICY_AL_ALL_REQ;
    GapAdv_setParam(peripheralAdvHandle_1, GAP_ADV_PARAM_FILTER_POLICY, &advPolicy);
    


    I hope this solves your problem!

    Regards,
    Tarek

  • Hi,

    Currently I do not want to implement pairing. I want to do the whitelisting only by normal connection. But I am not able to do it.

    This is the code for my peripheral:

    void Peripheral_GAPConnEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {

    switch (event)
    {
    case BLEAPPUTIL_LINK_ESTABLISHED_EVENT:
    {
    if(firstTime == 0){
    static volatile char status = 0xff;
    static volatile gapEstLinkReqEvent_t *gapEstMsg = NULL;
    gapEstMsg = (gapEstLinkReqEvent_t*) pMsgData;
    HCI_LE_ClearAcceptListCmd(""); //Ensure the accept list is clear
    status = HCI_LE_AddAcceptListCmd(gapEstMsg->devAddrType,
    gapEstMsg->devAddr); //Add a accept list entry
    Log_printf(LogModule0,Log_INFO,"%d",status);
    }
    Log_message(LOG_INFO, "device is connected");
    break;
    }
    case BLEAPPUTIL_LINK_TERMINATED_EVENT:
    {
    gapTerminateLinkEvent_t *term = (gapTerminateLinkEvent_t *)pMsgData;
    if(firstTime==0){
    BLEAppUtil_advStop(peripheralAdvHandle_1);
    uint8_t advPolicy = GAP_ADV_AL_POLICY_AL_ALL_REQ;
    GapAdv_setParam(peripheralAdvHandle_1, GAP_ADV_PARAM_FILTER_POLICY,
    &advPolicy);
    firstTime = 1;
    }
    Log_printf(LogModule0,Log_ERROR, "disconn reason:%d", term->reason);
    HCI_LE_ReadAcceptListSizeCmd();

    BLEAppUtil_advStart(peripheralAdvHandle_1, &advSetStartParamsSet_1);
    break;
    }
    default:
    {
    break;
    }
    }
    }

    First the peripheral can connect to any device as I have set the filter policy as process request to any device.

    Based on David's recommendation, I have implemented the above code. So, first time I am able to connect to a given central and I am able to store the MAC ID also in AL. Next time onwards, it is not connecting to the given central. What could be the issue? This whitelisting required pairing to be implemented mandatorily or how?

    When I modify the filter policy in my code, at the same time do I have to modify my advertisement parameters with the whitelisted central's MAC ID or what to do? Please help me

  • Hello Satakshi,

    With the way you've structured your code, can you confirm that you've unchecked the "Sync Acceptlist with bonded devices" setting in sysconfig? If you haven't, please uncheck it and try testing again.

    I hope this helps!

    Regards,
    Tarek

  • Hi

    It's unchecked already . Can you please share the detailed steps on how to do it. I cannot figure out.

    In my sysconfig, I have disabled pairing. All others are default parameters only. Filter policy is set to process requests from all devices and then I am running the given code.

    void Peripheral_GAPConnEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
    {

    switch (event)
    {
    case BLEAPPUTIL_LINK_ESTABLISHED_EVENT:
    {
    if(firstTime == 0){
    static volatile char status = 0xff;
    static volatile gapEstLinkReqEvent_t *gapEstMsg = NULL;
    gapEstMsg = (gapEstLinkReqEvent_t*) pMsgData;
    HCI_LE_ClearAcceptListCmd(""); //Ensure the accept list is clear
    status = HCI_LE_AddAcceptListCmd(gapEstMsg->devAddrType,
    gapEstMsg->devAddr); //Add a accept list entry
    Log_printf(LogModule0,Log_INFO,"%d",status);
    }
    Log_message(LOG_INFO, "device is connected");
    break;
    }
    case BLEAPPUTIL_LINK_TERMINATED_EVENT:
    {
    gapTerminateLinkEvent_t *term = (gapTerminateLinkEvent_t *)pMsgData;
    if(firstTime==0){
    BLEAppUtil_advStop(peripheralAdvHandle_1);
    uint8_t advPolicy = GAP_ADV_AL_POLICY_AL_ALL_REQ;
    GapAdv_setParam(peripheralAdvHandle_1, GAP_ADV_PARAM_FILTER_POLICY,
    &advPolicy);
    firstTime = 1;
    }
    Log_printf(LogModule0,Log_ERROR, "disconn reason:%d", term->reason);
    HCI_LE_ReadAcceptListSizeCmd();

    BLEAppUtil_advStart(peripheralAdvHandle_1, &advSetStartParamsSet_1);
    break;
    }
    default:
    {
    break;
    }
    }
    }

    Will this filter policy work only when I do pairing? Can you please help me with this information

  • Hello Satakshi,

    I just tested your code, and it should work, as long as the central device's address mode is set as "Public Address", as this will make it advertise with it's BLE identity address. Please find attached a screenshot of the sysconfig file in the central project.

    Please let me know if this works for you.

    Best Regards,
    Tarek

  • Hi Tarek,

    Its working now properly. 

    Since, I was not using pairing so, I commented the below line in bold. By commenting the gapBondParams call, it is not working. If I uncomment it, then it is properly working,

    BLEAppUtil_PeriCentParams_t appMainPeriCentParams =
    {
    #if defined( HOST_CONFIG ) && ( HOST_CONFIG & ( PERIPHERAL_CFG ) )
    .connParamUpdateDecision = DEFAULT_PARAM_UPDATE_REQ_DECISION,
    #endif
    //.gapBondParams = &gapBondParams
    };

    Can you please explain if  accept list filter policy uses any parameter from the gapBondParams structure by chance? So, when I comment it, it does not work and when I uncomment it back, it works properly 

    Basically I want to know the importance of initializing .gapBondParams = &gapBondParams even when I am not using pairing?

  • Hello Satakshi,

    I'm glad to hear it's working! Even though you are not using it in any of your scripts, it is used in the Bond Manager running in the background, therefore, commenting it out would cause unexpected behavior.

    Best Regards,
    Tarek