on 2021-12-20 12:56 AM
app_ble.c (client) | |
Code Modification | Comment |
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 |
p2p_client_app.c | |
Code Modification | Comment |
/* 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. |
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. |