int gapc_connection_req_ind_handler(ke_msg_id_t msgid, struct gapc_connection_req_ind *param, ke_task_id_t dest_id, ke_task_id_t src_id) { start_pair = 1; if (app_env.state == APP_IDLE) { // We are now connected app_env.state = APP_CONNECTED; // Retrieve the connection info from the parameters app_env.peer_device.device.conhdl = param->conhdl; // Retrieve the connection index from the src_id app_env.peer_device.device.conidx = KE_IDX_GET(src_id); // On Reconnection check if device is bonded and send pairing request. Otherwise it is not bonded. if (bdaddr_compare(&app_env.peer_device.device.adv_addr, ¶m->peer_addr)) { if (app_env.peer_device.bonded) start_pair = 0; } memcpy(app_env.peer_device.device.adv_addr.addr, param->peer_addr.addr, sizeof(struct bd_addr)); app_connect_confirm(GAP_AUTH_REQ_NO_MITM_NO_BOND); app_security_enable(); } return 0; }
void app_connection_func(struct gapc_connection_req_ind const *param) { if (app_env.conidx != GAP_INVALID_CONIDX) { #if (BLE_DIS_SERVER) app_dis_enable_prf(app_env.conhdl); #endif #if (BLE_SAMPLE128) app_sample128_enable(); #endif //这个timer 是10ms的时基100*10ms=1S //ke_timer_set(APP_SAMPLE128_TIMER,TASK_APP,Sample_LED_Blink); /************************************************** Handle connection request event. Enable required profiles i.e. *****************************************************/ //ke_timer_set(TASK_APP,TASK_APP,50); ke_state_set(TASK_APP, APP_CONNECTED); // Retrieve the connection info from the parameters app_env.conhdl = param->conhdl; app_env.peer_addr_type = param->peer_addr_type; memcpy(app_env.peer_addr.addr, param->peer_addr.addr, BD_ADDR_LEN); # if (BLE_APP_SEC) // send connection confirmation app_connect_confirm(app_sec_env.auth); # else // (BLE_APP_SEC) // send connection confirmation app_connect_confirm(GAP_AUTH_REQ_NO_MITM_NO_BOND); # endif // (BLE_APP_SEC) } else { // No connection has been establish, restart advertising //app_adv_start(); } return; }
/** **************************************************************************************** * @brief Handles connection complete event from the GAP. Will enable profile. * * @param[in] msgid Id of the message received. * @param[in] param Pointer to the parameters of the message. * @param[in] dest_id ID of the receiving task instance (TASK_GAP). * @param[in] src_id ID of the sending task instance. * * @return If the message was consumed or not. **************************************************************************************** */ int gapc_connection_req_ind_handler(ke_msg_id_t const msgid, struct gapc_connection_req_ind const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { // Connection Index if (ke_state_get(dest_id) == APP_CONNECTABLE) { app_env.conidx = KE_IDX_GET(src_id); if (app_env.conidx != GAP_INVALID_CONIDX) { //Disable timer of the establishment of the connection ke_timer_clear(APP_CONN_TIMER, TASK_APP); ke_state_set(dest_id, APP_CONNECTED); app_connection_func(param); // Retrieve the connection info from the parameters app_env.conhdl = param->conhdl; app_env.peer_addr_type = param->peer_addr_type; memcpy(app_env.peer_addr.addr, param->peer_addr.addr, BD_ADDR_LEN); // send connection confirmation // 发送连接确认aiwesky 20151004 app_connect_confirm(GAP_AUTH_REQ_NO_MITM_NO_BOND); // Start param update app_param_update_start(); // 此时,就可以进行profile读取了 aiwesky 20151004 } else { // No connection has been establish, restart advertising app_adv_start(); // 如果没有连接,则继续进行广播 aiwesky 20151005 } } else { // APP_CONNECTABLE state is used to wait the GAP_LE_CREATE_CONN_REQ_CMP_EVT message ASSERT_ERR(0); } return (KE_MSG_CONSUMED); }
/** **************************************************************************************** * @brief Handles reception of encrypt request command * * @param[in] msgid Id of the message received. * @param[in] param Pointer to the parameters of the message. * @param[in] dest_id ID of the receiving task instance (TASK_GAP). * @param[in] src_id ID of the sending task instance. * * @return If the message was consumed or not. **************************************************************************************** */ int gapc_encrypt_req_ind_handler(ke_msg_id_t const msgid, struct gapc_encrypt_req_ind *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { struct gapc_encrypt_cfm* cfm = KE_MSG_ALLOC(GAPC_ENCRYPT_CFM, src_id, dest_id, gapc_encrypt_cfm); if (!app_validate_encrypt_req_func(param)) { cfm->found = false; } else { if(((app_sec_env.auth & GAP_AUTH_BOND) != 0) && (memcmp(&(app_sec_env.rand_nb), &(param->rand_nb), RAND_NB_LEN) == 0) && (app_sec_env.ediv == param->ediv)) { cfm->found = true; cfm->key_size = app_sec_env.key_size; memcpy(&(cfm->ltk), &(app_sec_env.ltk), KEY_LEN); // update connection auth app_connect_confirm(app_sec_env.auth); app_sec_encrypt_complete_func(); } else { cfm->found = false; } } ke_msg_send(cfm); if (cfm->found == false) app_disconnect(); return (KE_MSG_CONSUMED); }