|
|
|
@ -323,7 +323,8 @@ void APP_BLE_Init( void ) |
|
|
|
|
|
|
|
/*Radio mask Activity*/ |
|
|
|
#if (OOB_DEMO != 0) |
|
|
|
aci_hal_set_radio_activity_mask(0x0020); |
|
|
|
aci_hal_set_radio_activity_mask(0x0020); // connection event master
|
|
|
|
log_debug("APP_BLE_Init", "aci_hal_set_radio_activity_mask=0x0020 (connection event master)", 0); |
|
|
|
#endif |
|
|
|
/**
|
|
|
|
* Initialize P2P Client Application |
|
|
|
@ -339,6 +340,7 @@ void APP_BLE_Init( void ) |
|
|
|
* Start scanning |
|
|
|
*/ |
|
|
|
UTIL_SEQ_SetTask(1 << CFG_TASK_START_SCAN_ID, CFG_SCH_PRIO_0); |
|
|
|
log_debug("APP_BLE_Init", "trigger scanning task", 0); |
|
|
|
#endif |
|
|
|
/* USER CODE BEGIN APP_BLE_Init_2 */ |
|
|
|
log_debug("APP_BLE_Init", "done", 0); |
|
|
|
@ -391,12 +393,12 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) |
|
|
|
{ |
|
|
|
/* USER CODE BEGIN GAP_GENERAL_DISCOVERY_PROC */ |
|
|
|
|
|
|
|
log_debug("SVCCTL_App_Notification", "-- GAP GENERAL DISCOVERY PROCEDURE_COMPLETED", 0); |
|
|
|
/* USER CODE END GAP_GENERAL_DISCOVERY_PROC */ |
|
|
|
APP_DBG_MSG("-- GAP GENERAL DISCOVERY PROCEDURE_COMPLETED\n"); |
|
|
|
log_debug("SVCCTL_App_Notification", "-- GAP GENERAL DISCOVERY PROCEDURE_COMPLETED", 0); |
|
|
|
/*if a device found, connect to it, device 1 being chosen first if both found*/ |
|
|
|
if (BleApplicationContext.DeviceServerFound == 0x01 && BleApplicationContext.Device_Connection_Status != APP_BLE_CONNECTED_CLIENT) |
|
|
|
{ |
|
|
|
log_debug("SVCCTL_App_Notification", "Set task: CFG_TASK_CONN_DEV_1_ID", 0); |
|
|
|
UTIL_SEQ_SetTask(1 << CFG_TASK_CONN_DEV_1_ID, CFG_SCH_PRIO_0); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -407,6 +409,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) |
|
|
|
{ |
|
|
|
/* USER CODE BEGIN EVT_BLUE_L2CAP_CONNECTION_UPDATE_REQ */ |
|
|
|
|
|
|
|
log_debug("SVCCTL_App_Notification", "Event: ACI_L2CAP_CONNECTION_UPDATE_REQ_VSEVT_CODE", 0); |
|
|
|
/* USER CODE END EVT_BLUE_L2CAP_CONNECTION_UPDATE_REQ */ |
|
|
|
aci_l2cap_connection_update_req_event_rp0 *pr = (aci_l2cap_connection_update_req_event_rp0 *) blecore_evt->data; |
|
|
|
aci_hal_set_radio_activity_mask(0x0000); |
|
|
|
@ -504,7 +507,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) |
|
|
|
BleApplicationContext.Device_Connection_Status = APP_BLE_CONNECTED_CLIENT; |
|
|
|
|
|
|
|
/* CONNECTION WITH CLIENT */ |
|
|
|
APP_DBG_MSG("\r\n\r** CONNECTION EVENT WITH SERVER \n"); |
|
|
|
log_debug("SVCCTL_App_Notification", "** CONNECTION EVENT WITH SERVER", 0); |
|
|
|
handleNotification.P2P_Evt_Opcode = PEER_CONN_HANDLE_EVT; |
|
|
|
handleNotification.ConnectionHandle = BleApplicationContext.BleApplicationContext_legacy.connectionHandle; |
|
|
|
P2PC_APP_Notification(&handleNotification); |
|
|
|
@ -512,12 +515,12 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt ) |
|
|
|
result = aci_gatt_disc_all_primary_services(BleApplicationContext.BleApplicationContext_legacy.connectionHandle); |
|
|
|
if (result == BLE_STATUS_SUCCESS) |
|
|
|
{ |
|
|
|
APP_DBG_MSG("\r\n\r** GATT SERVICES & CHARACTERISTICS DISCOVERY \n"); |
|
|
|
APP_DBG_MSG("* GATT : Start Searching Primary Services \r\n\r"); |
|
|
|
log_debug("SVCCTL_App_Notification", "** GATT SERVICES & CHARACTERISTICS DISCOVERY", 0); |
|
|
|
log_debug("SVCCTL_App_Notification", "* GATT : Start Searching Primary Services", 0); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
APP_DBG_MSG("BLE_CTRL_App_Notification(), All services discovery Failed \r\n\r"); |
|
|
|
log_error("SVCCTL_App_Notification", "All services discovery Failed", 0); |
|
|
|
} |
|
|
|
|
|
|
|
break; /* HCI_LE_CONNECTION_COMPLETE_SUBEVT_CODE */ |
|
|
|
@ -672,17 +675,20 @@ void APP_BLE_Key_Button1_Action(void) |
|
|
|
*************************************************************/ |
|
|
|
static void Ble_Tl_Init( void ) |
|
|
|
{ |
|
|
|
log_debug("Ble_Tl_Init", "start", 0); |
|
|
|
HCI_TL_HciInitConf_t Hci_Tl_Init_Conf; |
|
|
|
|
|
|
|
Hci_Tl_Init_Conf.p_cmdbuffer = (uint8_t*)&BleCmdBuffer; |
|
|
|
Hci_Tl_Init_Conf.StatusNotCallBack = BLE_StatusNot; |
|
|
|
hci_init(BLE_UserEvtRx, (void*) &Hci_Tl_Init_Conf); |
|
|
|
|
|
|
|
log_debug("Ble_Tl_Init", "end", 0); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
static void Ble_Hci_Gap_Gatt_Init(void){ |
|
|
|
static void Ble_Hci_Gap_Gatt_Init(void){ |
|
|
|
|
|
|
|
log_debug("Ble_Hci_Gap_Gatt_Init", "start", 0); |
|
|
|
uint8_t role; |
|
|
|
uint16_t gap_service_handle, gap_dev_name_char_handle, gap_appearance_char_handle; |
|
|
|
const uint8_t *bd_addr; |
|
|
|
@ -751,6 +757,7 @@ static void Ble_Tl_Init( void ) |
|
|
|
{ |
|
|
|
const char *name = "Monsun1"; |
|
|
|
|
|
|
|
log_debug("Ble_Hci_Gap_Gatt_Init", "aci_gap_init()", 0); |
|
|
|
aci_gap_init(role, 0, |
|
|
|
APPBLE_GAP_DEVICE_NAME_LENGTH, |
|
|
|
&gap_service_handle, &gap_dev_name_char_handle, &gap_appearance_char_handle); |
|
|
|
@ -761,14 +768,15 @@ static void Ble_Tl_Init( void ) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(aci_gatt_update_char_value(gap_service_handle, |
|
|
|
gap_appearance_char_handle, |
|
|
|
0, |
|
|
|
2, |
|
|
|
(uint8_t *)&appearance)) |
|
|
|
{ |
|
|
|
BLE_DBG_SVCCTL_MSG("Appearance aci_gatt_update_char_value failed.\n"); |
|
|
|
} |
|
|
|
log_debug("Ble_Hci_Gap_Gatt_Init", "aci_gatt_update_char_value()", 0); |
|
|
|
if(aci_gatt_update_char_value(gap_service_handle, |
|
|
|
gap_appearance_char_handle, |
|
|
|
0, |
|
|
|
2, |
|
|
|
(uint8_t *)&appearance)) |
|
|
|
{ |
|
|
|
BLE_DBG_SVCCTL_MSG("Appearance aci_gatt_update_char_value failed.\n"); |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize IO capability |
|
|
|
@ -786,6 +794,7 @@ static void Ble_Tl_Init( void ) |
|
|
|
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.Fixed_Pin = CFG_FIXED_PIN; |
|
|
|
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.bonding_mode = CFG_BONDING_MODE; |
|
|
|
|
|
|
|
log_debug("Ble_Hci_Gap_Gatt_Init", "aci_gap_set_authentication_requirement()", 0); |
|
|
|
aci_gap_set_authentication_requirement(BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.bonding_mode, |
|
|
|
BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.mitm_mode, |
|
|
|
CFG_SC_SUPPORT, |
|
|
|
@ -802,16 +811,18 @@ static void Ble_Tl_Init( void ) |
|
|
|
*/ |
|
|
|
if (BleApplicationContext.BleApplicationContext_legacy.bleSecurityParam.bonding_mode) |
|
|
|
{ |
|
|
|
log_debug("Ble_Hci_Gap_Gatt_Init", "aci_gap_configure_whitelist()", 0); |
|
|
|
aci_gap_configure_whitelist(); |
|
|
|
} |
|
|
|
|
|
|
|
log_debug("Ble_Hci_Gap_Gatt_Init", "end", 0); |
|
|
|
} |
|
|
|
|
|
|
|
static void Scan_Request( void ) |
|
|
|
{ |
|
|
|
/* USER CODE BEGIN Scan_Request_1 */ |
|
|
|
|
|
|
|
log_debug("Scan_Request", "enter", 0); |
|
|
|
log_debug("Scan_Request", "start", 0); |
|
|
|
/* USER CODE END Scan_Request_1 */ |
|
|
|
tBleStatus result; |
|
|
|
if (BleApplicationContext.Device_Connection_Status != APP_BLE_CONNECTED_CLIENT) |
|
|
|
@ -819,22 +830,21 @@ static void Scan_Request( void ) |
|
|
|
/* USER CODE BEGIN APP_BLE_CONNECTED_CLIENT */ |
|
|
|
|
|
|
|
/* USER CODE END APP_BLE_CONNECTED_CLIENT */ |
|
|
|
log_debug("Scan_Request", "aci_gap_start_general_discovery_proc()", 0); |
|
|
|
result = aci_gap_start_general_discovery_proc(SCAN_P, SCAN_L, PUBLIC_ADDR, 1); |
|
|
|
if (result == BLE_STATUS_SUCCESS) |
|
|
|
{ |
|
|
|
/* USER CODE BEGIN BLE_SCAN_SUCCESS */ |
|
|
|
|
|
|
|
log_debug("Scan_Request", "START GENERAL DISCOVERY (SCAN)", 0); |
|
|
|
/* USER CODE END BLE_SCAN_SUCCESS */ |
|
|
|
APP_DBG_MSG(" \r\n\r** START GENERAL DISCOVERY (SCAN) ** \r\n\r"); |
|
|
|
log_debug("Scan_Request", "** START GENERAL DISCOVERY (SCAN) **", 0); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
/* USER CODE BEGIN BLE_SCAN_FAILED */ |
|
|
|
|
|
|
|
log_debug("Scan_Request", "BLE_App_Start_Limited_Disc_Req, Failed", 0); |
|
|
|
/* USER CODE END BLE_SCAN_FAILED */ |
|
|
|
APP_DBG_MSG("-- BLE_App_Start_Limited_Disc_Req, Failed \r\n\r"); |
|
|
|
log_debug("Scan_Request", "-- BLE_App_Start_Limited_Disc_Req, Failed ", 0); |
|
|
|
} |
|
|
|
} |
|
|
|
/* USER CODE BEGIN Scan_Request_2 */ |
|
|
|
@ -847,14 +857,15 @@ static void Connect_Request( void ) |
|
|
|
{ |
|
|
|
/* USER CODE BEGIN Connect_Request_1 */ |
|
|
|
|
|
|
|
log_debug("Scan_Request", "enter", 0); |
|
|
|
log_debug("Connect_Request", "start", 0); |
|
|
|
/* USER CODE END Connect_Request_1 */ |
|
|
|
tBleStatus result; |
|
|
|
|
|
|
|
APP_DBG_MSG("\r\n\r** CREATE CONNECTION TO SERVER ** \r\n\r"); |
|
|
|
log_debug("Connect_Request", "** CREATE CONNECTION TO SERVER **", 0); |
|
|
|
|
|
|
|
if (BleApplicationContext.Device_Connection_Status != APP_BLE_CONNECTED_CLIENT) |
|
|
|
{ |
|
|
|
log_debug("Connect_Request", "aci_gap_create_connection()", 0); |
|
|
|
result = aci_gap_create_connection(SCAN_P, |
|
|
|
SCAN_L, |
|
|
|
PUBLIC_ADDR, SERVER_REMOTE_BDADDR, |
|
|
|
@ -871,6 +882,7 @@ static void Connect_Request( void ) |
|
|
|
/* USER CODE BEGIN BLE_CONNECT_SUCCESS */ |
|
|
|
|
|
|
|
/* USER CODE END BLE_CONNECT_SUCCESS */ |
|
|
|
log_debug("Device_Connection_Status", "APP_BLE_LP_CONNECTING", 0); |
|
|
|
BleApplicationContext.Device_Connection_Status = APP_BLE_LP_CONNECTING; |
|
|
|
|
|
|
|
} |
|
|
|
@ -879,6 +891,8 @@ static void Connect_Request( void ) |
|
|
|
/* USER CODE BEGIN BLE_CONNECT_FAILED */ |
|
|
|
|
|
|
|
/* USER CODE END BLE_CONNECT_FAILED */ |
|
|
|
log_error("Connect_Request", "Connection failed", 0); |
|
|
|
log_debug("Device_Connection_Status", "APP_BLE_IDLE", 0); |
|
|
|
BleApplicationContext.Device_Connection_Status = APP_BLE_IDLE; |
|
|
|
|
|
|
|
} |
|
|
|
@ -892,11 +906,13 @@ static void Connect_Request( void ) |
|
|
|
static void Switch_OFF_GPIO(){ |
|
|
|
/* USER CODE BEGIN Switch_OFF_GPIO */ |
|
|
|
|
|
|
|
log_debug("Switch_OFF_GPIO", "start/end", 0); |
|
|
|
/* USER CODE END Switch_OFF_GPIO */ |
|
|
|
} |
|
|
|
|
|
|
|
const uint8_t* BleGetBdAddress( void ) |
|
|
|
{ |
|
|
|
log_debug("BleGetBdAddress", "start", 0); |
|
|
|
uint8_t *otp_addr; |
|
|
|
const uint8_t *bd_addr; |
|
|
|
uint32_t udn; |
|
|
|
@ -940,6 +956,7 @@ const uint8_t* BleGetBdAddress( void ) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log_debug("BleGetBdAddress", "end", 0); |
|
|
|
return bd_addr; |
|
|
|
} |
|
|
|
/* USER CODE BEGIN FD_LOCAL_FUNCTIONS */ |
|
|
|
@ -970,6 +987,7 @@ void hci_cmd_resp_wait(uint32_t timeout) |
|
|
|
|
|
|
|
static void BLE_UserEvtRx( void * pPayload ) |
|
|
|
{ |
|
|
|
// log_debug("BLE_UserEvtRx", "start", 0);
|
|
|
|
SVCCTL_UserEvtFlowStatus_t svctl_return_status; |
|
|
|
tHCI_UserEvtRxParam *pParam; |
|
|
|
|
|
|
|
@ -984,10 +1002,12 @@ static void BLE_UserEvtRx( void * pPayload ) |
|
|
|
{ |
|
|
|
pParam->status = HCI_TL_UserEventFlow_Disable; |
|
|
|
} |
|
|
|
// log_debug("BLE_UserEvtRx", "end", 0);
|
|
|
|
} |
|
|
|
|
|
|
|
static void BLE_StatusNot( HCI_TL_CmdStatus_t status ) |
|
|
|
{ |
|
|
|
// log_debug("BLE_StatusNot", "start", 0);
|
|
|
|
uint32_t task_id_list; |
|
|
|
switch (status) |
|
|
|
{ |
|
|
|
@ -1014,6 +1034,7 @@ static void BLE_StatusNot( HCI_TL_CmdStatus_t status ) |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
// log_debug("BLE_StatusNot", "end", 0);
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|