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 2"

MCU Support Center --
ST Employee
Continuation of previous parts

3. Project Modifications

The project code modifications for both the client and server are provided.
 

3.1 Client and Server Common Modifications:

The key modifications common to both client and server are provided below.  Parameters of interest are highlighted.
Table 1:  Common Configurations to Both Client and Peripheral Files
app_conf.h
/**
* Define IO Authentication
*/
#define CFG_BONDING_MODE               (1)
#define CFG_FIXED_PIN                      (111111)
#define CFG_USED_FIXED_PIN               (0)
#define CFG_ENCRYPTION_KEY_SIZE_MAX      (16)
#define CFG_ENCRYPTION_KEY_SIZE_MIN      (8)

/**
/* Define IO capabilities
 */
#define CFG_IO_CAPABILITY_DISPLAY_ONLY       (0x00)
#define CFG_IO_CAPABILITY_DISPLAY_YES_NO     (0x01)
#define CFG_IO_CAPABILITY_KEYBOARD_ONLY      (0x02)
#define CFG_IO_CAPABILITY_NO_INPUT_NO_OUTPUT (0x03)
#define CFG_IO_CAPABILITY_KEYBOARD_DISPLAY   (0x04)

#define CFG_IO_CAPABILITY              CFG_IO_CAPABILITY_DISPLAY_YES_NO
                                                                           /**
 * Define MITM modes
 */
#define CFG_MITM_PROTECTION_NOT_REQUIRED      (0x00)
#define CFG_MITM_PROTECTION_REQUIRED          (0x01)

#define CFG_MITM_PROTECTION             CFG_MITM_PROTECTION_REQUIRED
 
/**
 * Define Keypress Notification Support
 */
#define CFG_KEYPRESS_NOT_SUPPORTED      (0x00)
#define CFG_KEYPRESS_SUPPORTED          (0x01)

#define CFG_KEYPRESS_NOTIFICATION_SUPPORT             CFG_KEYPRESS_NOT_SUPPORTED

/**
 * Numeric Comparison Answers
 */
#define YES (0x01)
#define NO  (0x00)

Table 2 :  Switch Button definitions, pairing request from server and security settings reset
app_entry.capp_ble.c
/* USER CODE BEGIN FD_WRAP_FUNCTIONS */
void HAL_GPIO_EXTI_Callback( uint16_t GPIO_Pin )
{
  switch (GPIO_Pin)
  {
    case BUTTON_SW1_PIN:
     APP_BLE_Key_Button1_Action();
/* SW1 begins connection process */
      break;

    case BUTTON_SW2_PIN:
      APP_BLE_Key_Button2_Action();
      break;

    case BUTTON_SW3_PIN:
      APP_BLE_Key_Button3_Action();
/*SW3 initiates pairing process */
      break;

    default:
      break;

  }
  return;
}
/* USER CODE BEGIN FD*/
void APP_BLE_Key_Button1_Action(void)
{
  P2PS_APP_SW1_Button_Action();
}

void APP_BLE_Key_Button2_Action(void)
{
#if (L2CAP_REQUEST_NEW_CONN_PARAM != 0 )   
  UTIL_SEQ_SetTask( 1<<CFG_TASK_CONN_UPDATE_REG_ID, CFG_SCH_PRIO_0);
#endif
 
  return;
}

void APP_BLE_Key_Button3_Action(void)
{
  /* Request Pairing */
  aci_gap_slave_security_req(BleApplicationContext.BleApplicationContext_legacy.connectionHandle);
}

/* USER CODE END FD*/
 /* USER CODE BEGIN APP_BLE_Init_2 */
   (void) aci_gap_clear_security_db();
/* clear all existing security settings each new reset */
/* USER CODE END APP_BLE_Init_2 */

The system will proceed through the equivalent of Pass 1 described in a previous section of this document.  Trace output are provided through a terminal interface guiding the user of the location within the process.
Table 3:  Key Events Occurring in Sequential Order
app_ble.c
case EVT_LE_CONN_COMPLETE:
case (EVT_BLUE_GAP_NUMERIC_COMPARISON_VALUE):
case (EVT_BLUE_GAP_PAIRING_CMPLT):

Once connected, the client will initiate an aci_ gap_terminate command, essentially disconnecting the client and server.  In this instance, the server will store all information and add the client information to the whitelist.  Table 4 displays the relevant steps once an EVT_DISCONN_COMPLETE is detected.   A description of the process is provided directly following the Table.
Table 4:  Disconnect and Whitelist Advertising Re-Start
app_ble.ccomment
case EVT_DISCONN_COMPLETE:
    {
      hci_disconnection_complete_event_rp0 *disconnection_complete_event;
      disconnection_complete_event = (hci_disconnection_complete_event_rp0 *) event_pckt->data;
      if (disconnection_complete_event->Connection_Handle == BleApplicationContext.BleApplicationContext_legacy.connectionHandle)
      {
        BleApplicationContext.BleApplicationContext_legacy.connectionHandle = 0;
        BleApplicationContext.Device_Connection_Status = APP_BLE_IDLE;
        APP_DBG_MSG("\r\n\r** DISCONNECTION EVENT WITH CLIENT \n");
      }
      /* restart advertising */
     
/*    Adv_Request(APP_BLE_FAST_ADV);*/  /*ST Do not restart advertising*/
      /**
       * SPECIFIC to P2P Server APP
       */
      handleNotification.P2P_Evt_Opcode = PEER_DISCON_HANDLE_EVT;
      handleNotification.ConnectionHandle = BleApplicationContext.BleApplicationContext_legacy.connectionHandle;
      P2PS_APP_Notification(&handleNotification);
      /* USER CODE BEGIN EVT_DISCONN_COMPLETE */
      aci_gap_configure_whitelist(); /* ST  store the whitelist on disconnect */
     /*Allow Scan Request from White List Only, Allow Connect Request from */
      /*  */
      /*White List Only*/
      APP_DBG_MSG("\r\n\r** WHITELIST Executed \n");
       aci_gap_set_undirected_connectable(CFG_FAST_CONN_ADV_INTERVAL_MIN,
                         CFG_FAST_CONN_ADV_INTERVAL_MAX,
                         PUBLIC_ADDR,
                         0x03);
       APP_DBG_MSG("\r\n\r** NEW ADVERTISING STARTED AFTER WHITELIST \n");
       /* 0x03 is the white list filter value */
     /* Adv_Request(APP_BLE_FAST_ADV);*/
Disconnect














A








B



C

D
  

A summary of the key elements defined in the preceding table is provided.  Once the disconnect event is detected, the system normally moves towards a re-connect status.  In “A” the standard advertising request has been commented out as it is desired to advertise with Whitelist.  In “B”, the whitelist is configured during the disconnection event.  In C, the debug message is written to the terminal for tracing purposes.  Finally, in “D”, a new advertising request is initiated with filter policy = 3.
The full call is repeated below for explanation purposes:
tBleStatus aci_gap_set_undirected_connectable( uint16_t Advertising_Interval_Min,
                                               uint16_t Advertising_Interval_Max,
                                               uint8_t Own_Address_Type,
                                               uint8_t Adv_Filter_Policy );
The Adv_Filter_Policy set to 0x03 defines the following connection:
- 0x03: Allow Scan Request from White List Only, Allow Connect Request from White List Only
The other key element is the Own_Address_Type which must be a Public Address.
As discussed earlier, the AD flag is disabled automatically with this setting and the server or peripheral is visible completely only to another device within the same whitelist setting.
Article Part 1
Article Part 3
Article Part 4

 
Version history
Last update:
‎2021-12-20 12:43 AM
Updated by: