cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure the STM32WB LE Central(Client) or Peripheral(Server) for Whitelist Operation "Part 3"

MCU Support Center --
ST Employee
Continuation of Part 1, Part 2 

3.2 Client Configuration and Settings


It is now necessary to open and edit the client application.  The following modifications are required to be implemented.
Table 5 shows the modifications required to the SW 1 functionality.
Table 5: Client Switch Function Modifications
app_ble.c   (client)
Code ModificationComment
void APP_BLE_Key_Button1_Action(void)
{
#if OOB_DEMO == 0
      P2PC_APP_SW1_Button_Action();
#else
      if(P2P_Client_APP_Get_State () != APP_BLE_CONNECTED_CLIENT)
      {
        UTIL_SEQ_SetTask(1 << CFG_TASK_START_SCAN_ID, CFG_SCH_PRIO_0);
      }
      else
      {
        P2PC_APP_SW1_Button_Action();
      }  
#endif
}
In app_ble.c  SW 1 is used twice.

The first time it is pressed, a scan
and connection will occur as normal in
response to the advertising server.

The second time it is pressed, the
connection will be terminated via
ACI_GAP_Terminate command.

The client will begin a new scan, searching
for the Whitelist device
 

Table 6: Client Modifications
p2p_client_app.c
Code ModificationComment
/* USER CODE BEGIN FD */
void P2PC_APP_SW1_Button_Action(void)
{
  /* second time SW 1 is pushed, procedure to aci_gap_terminate*/

  /* this should complete the bond and save the whitelist on both client and server */

  APP_DBG_MSG("-- SW1 Pushed Terminate Connection without reset \n");

  APP_DBG_MSG("\n");
  aci_gap_terminate(P2P_Client_App_Context.ConnectionHandle, 0x13);
/*  UTIL_SEQ_SetTask(1<<CFG_TASK_SW1_BUTTON_PUSHED_ID, CFG_SCH_PRIO_0);*/
 
      
}
/* USER CODE END FD */
When SW1 is pushed the
first time, the command
Aci_gap_terminate() is
sent to the server.

This will disconnect the client
from server.

When the server restarts advertising with its whitelist advertising setting, the client scans with its whitelist settings and filter policy.

 

In the final phase of the connection process, the client functionality is summarized.  As previously mentioned, it was much more efficient to define a Pass 1, Pass 2 state in order to demonstrate the normal connection process followed by the whitelist connection process.
Table 7 breaks up the states into two segments as shown.
Table 7: Reconnection States
static void Connect_Request( void )
{
  /* USER CODE BEGIN Connect_Request_1 */
 
  /* USER CODE END Connect_Request_1 */
  tBleStatus result;
  APP_DBG_MSG("\r\n\r** CREATE CONNECTION TO SERVER **  \r\n\r");
 
 
  if (BleApplicationContext.Device_Connection_Status != APP_BLE_CONNECTED_CLIENT)
  {
     if (pass == 1)
     {
    result = aci_gap_create_connection(SCAN_P,
                                       SCAN_L,
                                       PUBLIC_ADDR, SERVER_REMOTE_BDADDR,
                                       PUBLIC_ADDR,
                                       CONN_P1,
                                       CONN_P2,
                                       0,
                                       SUPERV_TIMEOUT,
                                       CONN_L1,
                                       CONN_L2);
    
     }
Standard Connect Request














Define Pass 1 = initial no whitelist connect
Initiate a create connection in response to non whitelist initial advertising received from the server
if (pass == 2)
    {
           
    aci_gap_start_general_connection_establish_proc( 0x01,
                                                      SCAN_P,
                                                      SCAN_L,
                                                      PUBLIC_ADDR,
                                                      1,
                                                      1 );
    result = aci_gap_create_connection(SCAN_P,
                                       SCAN_L,
                                       PUBLIC_ADDR, SERVER_REMOTE_BDADDR,
                                       PUBLIC_ADDR,
                                       CONN_P1,
                                       CONN_P2,
                                       0,
                                       SUPERV_TIMEOUT,
                                       CONN_L1,
                                       CONN_L2);
    }
    if (result == BLE_STATUS_SUCCESS)
    {
    /* USER CODE BEGIN BLE_CONNECT_SUCCESS */
    /* USER CODE END BLE_CONNECT_SUCCESS */
    BleApplicationContext.Device_Connection_Status = APP_BLE_LP_CONNECTING;
    }
 
Once the disconnect command is sent, the client begins a new advertising with the setting as shown

The PUBLIC_ADDR must match that of the whitelisted server and the scanning filter policies, as set to 1, 1 direct the client for connection.  (see explanation below)



The scan_rsp is verified versus the internal whitelist and bonding information to ensure the connection to the correct device, server or peripheral.

The function call,
tBleStatus aci_gap_start_general_connection_establish_proc( uint8_t LE_Scan_Type,
                                                            uint16_t LE_Scan_Interval,
                                                            uint16_t LE_Scan_Window,
                                                            uint8_t Own_Address_Type,
                                                            uint8_t Scanning_Filter_Policy,
                                                            uint8_t Filter_Duplicates );
Sets the following critical parameters:
LE_Scan_Type  = active scanning (0x01)
Own_Address_Type = Public Address
Scanning_Filter_Policy = Ignore devices not in the White List (0x01)
Other values do not affect the connection mechanism.
 

3.3 Other Methods of Connection:


It is important to note that the Whitelist is not the only method that can be used by a client to connect to a specific device.  The function call,
tBleStatus aci_gap_start_auto_connection_establish_proc( uint16_t LE_Scan_Interval,
                                                         uint16_t LE_Scan_Window,
                                                         uint8_t Own_Address_Type,
                                                         uint16_t Conn_Interval_Min,
                                                         uint16_t Conn_Interval_Max,
                                                         uint16_t Conn_Latency,
                                                         uint16_t Supervision_Timeout,
                                                         uint16_t Minimum_CE_Length,
                                                         uint16_t Maximum_CE_Length,
                                                         uint8_t Num_of_Whitelist_Entries,
                                                         const Whitelist_Entry_t* Whitelist_Entry );
may be used by the client to directly establish a connection with a device that it sees after or during a scan, it may be searching a connection for a whitelist device that may or may not be advertising and it may initiate a connection with a device which is not in the whitelist but the client is aware of the server public address.
Article Part 1
Article Part 2
Article Part 4
 
Version history
Last update:
‎2021-12-20 12:56 AM
Updated by: