Merge branch 'bugfix/id9562_unregistered_callback' into 'master'

component/bt: check for registration status of callback function before using it

Add checking of NULL function pointers when calling bluetooth callbacks, especially before the callback functions are registered

See merge request !406
This commit is contained in:
Jiang Jiang Jian 2017-01-11 15:57:03 +08:00
commit 0c01ef68f1
4 changed files with 101 additions and 78 deletions

View File

@ -35,8 +35,6 @@
#include "esp_blufi_api.h"
#define BTC_BLUFI_CB_TO_APP(event, param) ((esp_blufi_event_cb_t)btc_profile_cb_get(BTC_PID_BLUFI))((event), (param))
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
@ -66,6 +64,14 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data);
static void btc_blufi_recv_handler(uint8_t *data, int len);
static void btc_blufi_send_ack(uint8_t seq);
static inline void btc_blufi_cb_to_app(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param)
{
esp_blufi_event_cb_t btc_blufi_cb = (esp_blufi_event_cb_t)btc_profile_cb_get(BTC_PID_BLUFI);
if (btc_blufi_cb) {
btc_blufi_cb(event, param);
}
}
static void blufi_create_service(void)
{
if (!blufi_env.enabled) {
@ -677,75 +683,75 @@ void btc_blufi_cb_handler(btc_msg_t *msg)
switch (msg->act) {
case ESP_BLUFI_EVENT_INIT_FINISH: {
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_INIT_FINISH, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_INIT_FINISH, param);
break;
}
case ESP_BLUFI_EVENT_DEINIT_FINISH: {
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_DEINIT_FINISH, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_DEINIT_FINISH, param);
break;
}
case ESP_BLUFI_EVENT_BLE_CONNECT:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_BLE_CONNECT, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_BLE_CONNECT, param);
break;
case ESP_BLUFI_EVENT_BLE_DISCONNECT:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_BLE_DISCONNECT, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_BLE_DISCONNECT, param);
break;
case ESP_BLUFI_EVENT_SET_WIFI_OPMODE:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_SET_WIFI_OPMODE, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_SET_WIFI_OPMODE, param);
break;
case ESP_BLUFI_EVENT_REQ_CONNECT_TO_AP:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_REQ_CONNECT_TO_AP, NULL);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_REQ_CONNECT_TO_AP, NULL);
break;
case ESP_BLUFI_EVENT_REQ_DISCONNECT_FROM_AP:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_REQ_DISCONNECT_FROM_AP, NULL);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_REQ_DISCONNECT_FROM_AP, NULL);
break;
case ESP_BLUFI_EVENT_GET_WIFI_STATUS:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_GET_WIFI_STATUS, NULL);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_GET_WIFI_STATUS, NULL);
break;
case ESP_BLUFI_EVENT_DEAUTHENTICATE_STA:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_DEAUTHENTICATE_STA, NULL);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_DEAUTHENTICATE_STA, NULL);
break;
case ESP_BLUFI_EVENT_RECV_STA_BSSID:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_STA_BSSID, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_STA_BSSID, param);
break;
case ESP_BLUFI_EVENT_RECV_STA_SSID:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_STA_SSID, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_STA_SSID, param);
break;
case ESP_BLUFI_EVENT_RECV_STA_PASSWD:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_STA_PASSWD, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_STA_PASSWD, param);
break;
case ESP_BLUFI_EVENT_RECV_SOFTAP_SSID:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_SOFTAP_SSID, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_SOFTAP_SSID, param);
break;
case ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_SOFTAP_PASSWD, param);
break;
case ESP_BLUFI_EVENT_RECV_SOFTAP_MAX_CONN_NUM:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_SOFTAP_MAX_CONN_NUM, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_SOFTAP_MAX_CONN_NUM, param);
break;
case ESP_BLUFI_EVENT_RECV_SOFTAP_AUTH_MODE:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_SOFTAP_AUTH_MODE, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_SOFTAP_AUTH_MODE, param);
break;
case ESP_BLUFI_EVENT_RECV_SOFTAP_CHANNEL:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_SOFTAP_CHANNEL, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_SOFTAP_CHANNEL, param);
break;
case ESP_BLUFI_EVENT_RECV_USERNAME:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_USERNAME, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_USERNAME, param);
break;
case ESP_BLUFI_EVENT_RECV_CA_CERT:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_CA_CERT, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_CA_CERT, param);
break;
case ESP_BLUFI_EVENT_RECV_CLIENT_CERT:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_CLIENT_CERT, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_CLIENT_CERT, param);
break;
case ESP_BLUFI_EVENT_RECV_SERVER_CERT:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_SERVER_CERT, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_SERVER_CERT, param);
break;
case ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_CLIENT_PRIV_KEY, param);
break;
case ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY:
BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY, param);
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY, param);
break;
default:
LOG_ERROR("%s UNKNOWN %d\n", __func__, msg->act);

View File

@ -26,8 +26,13 @@
static tBTA_BLE_ADV_DATA gl_bta_adv_data;
static tBTA_BLE_ADV_DATA gl_bta_scan_rsp_data;
#define BTC_GAP_BLE_CB_TO_APP(event, param) ((esp_gap_ble_cb_t)btc_profile_cb_get(BTC_PID_GAP_BLE))((event), (param))
static inline void btc_gap_ble_cb_to_app(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
{
esp_gap_ble_cb_t btc_gap_ble_cb = (esp_gap_ble_cb_t)btc_profile_cb_get(BTC_PID_GAP_BLE);
if (btc_gap_ble_cb) {
btc_gap_ble_cb(event, param);
}
}
static void btc_gap_adv_point_cleanup(void **buf)
{
@ -504,16 +509,16 @@ void btc_gap_ble_cb_handler(btc_msg_t *msg)
switch (msg->act) {
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT, param);
btc_gap_ble_cb_to_app(ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT :
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT, param);
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT:
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, param);
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, param);
break;
case ESP_GAP_BLE_SCAN_RESULT_EVT:
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_SCAN_RESULT_EVT, param);
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SCAN_RESULT_EVT, param);
break;
default:
break;

View File

@ -22,7 +22,13 @@
#include "bt_trace.h"
#include "esp_gattc_api.h"
#define BTC_GATTC_CB_TO_APP(event, gattc_if, param) ((esp_gattc_cb_t )btc_profile_cb_get(BTC_PID_GATTC))((event), (gattc_if), (param))
static inline void btc_gattc_cb_to_app(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
{
esp_gattc_cb_t btc_gattc_cb = (esp_gattc_cb_t )btc_profile_cb_get(BTC_PID_GATTC);
if (btc_gattc_cb) {
btc_gattc_cb(event, gattc_if, param);
}
}
void btc_gattc_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
@ -197,7 +203,7 @@ static void btc_gattc_get_first_char(btc_ble_gattc_args_t *arg)
memcpy(&param.get_char.srvc_id, &arg->get_first_char.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_char.char_id, &char_id, sizeof(esp_gatt_id_t));
param.get_char.char_prop = out_char_prop;
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_CHAR_EVT, gattc_if, &param);
}
static void btc_gattc_get_next_char(btc_ble_gattc_args_t *arg)
@ -227,7 +233,7 @@ static void btc_gattc_get_next_char(btc_ble_gattc_args_t *arg)
memcpy(&param.get_char.srvc_id, &arg->get_next_char.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_char.char_id, &char_id, sizeof(esp_gatt_id_t));
param.get_char.char_prop = out_char_prop;
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_CHAR_EVT, gattc_if, &param);
}
static void btc_gattc_get_first_descr(btc_ble_gattc_args_t *arg)
@ -256,7 +262,7 @@ static void btc_gattc_get_first_descr(btc_ble_gattc_args_t *arg)
memcpy(&param.get_descr.srvc_id, &arg->get_first_descr.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_descr.char_id, &arg->get_first_descr.char_id, sizeof(esp_gatt_id_t));
memcpy(&param.get_descr.descr_id, &descr_id, sizeof(esp_gatt_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_DESCR_EVT, gattc_if, &param);
}
static void btc_gattc_get_next_descr(btc_ble_gattc_args_t *arg)
@ -285,7 +291,7 @@ static void btc_gattc_get_next_descr(btc_ble_gattc_args_t *arg)
memcpy(&param.get_descr.srvc_id, &arg->get_next_descr.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_descr.char_id, &arg->get_next_descr.char_id, sizeof(esp_gatt_id_t));
memcpy(&param.get_descr.descr_id, &descr_id, sizeof(esp_gatt_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_DESCR_EVT, gattc_if, &param);
}
static void btc_gattc_get_first_incl_service(btc_ble_gattc_args_t *arg)
@ -310,7 +316,7 @@ static void btc_gattc_get_first_incl_service(btc_ble_gattc_args_t *arg)
param.get_incl_srvc.status = status;
memcpy(&param.get_incl_srvc.srvc_id, &arg->get_first_incl_srvc.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_incl_srvc.incl_srvc_id, &incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_INCL_SRVC_EVT, gattc_if, &param);
}
static void btc_gattc_get_next_incl_service(btc_ble_gattc_args_t *arg)
@ -336,7 +342,7 @@ static void btc_gattc_get_next_incl_service(btc_ble_gattc_args_t *arg)
param.get_incl_srvc.status = status;
memcpy(&param.get_incl_srvc.srvc_id, &arg->get_next_incl_srvc.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.get_incl_srvc.incl_srvc_id, &incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_GET_INCL_SRVC_EVT, gattc_if, &param);
}
static void btc_gattc_read_char(btc_ble_gattc_args_t *arg)
@ -423,7 +429,7 @@ static void btc_gattc_reg_for_notify(btc_ble_gattc_args_t *arg)
param.reg_for_notify.status = status;
memcpy(&param.reg_for_notify.srvc_id, &arg->reg_for_notify.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.reg_for_notify.char_id, &arg->reg_for_notify.char_id, sizeof(esp_gatt_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_FOR_NOTIFY_EVT, arg->reg_for_notify.gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_REG_FOR_NOTIFY_EVT, arg->reg_for_notify.gattc_if, &param);
}
static void btc_gattc_unreg_for_notify(btc_ble_gattc_args_t *arg)
@ -443,7 +449,7 @@ static void btc_gattc_unreg_for_notify(btc_ble_gattc_args_t *arg)
param.unreg_for_notify.status = status;
memcpy(&param.unreg_for_notify.srvc_id, &arg->unreg_for_notify.service_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&param.unreg_for_notify.char_id, &arg->unreg_for_notify.service_id, sizeof(esp_gatt_id_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_UNREG_FOR_NOTIFY_EVT, arg->unreg_for_notify.gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_UNREG_FOR_NOTIFY_EVT, arg->unreg_for_notify.gattc_if, &param);
}
void btc_gattc_call_handler(btc_msg_t *msg)
@ -533,19 +539,19 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
gattc_if = reg_oper->client_if;
param.reg.status = reg_oper->status;
param.reg.app_id = reg_oper->app_uuid.uu.uuid16;
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_REG_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_DEREG_EVT: {
tBTA_GATTC_REG *reg_oper = &arg->reg_oper;
gattc_if = reg_oper->client_if;
BTC_GATTC_CB_TO_APP(ESP_GATTC_UNREG_EVT, gattc_if, NULL);
btc_gattc_cb_to_app(ESP_GATTC_UNREG_EVT, gattc_if, NULL);
break;
}
case BTA_GATTC_READ_CHAR_EVT: {
set_read_value(&gattc_if, &param, &arg->read);
BTC_GATTC_CB_TO_APP(ESP_GATTC_READ_CHAR_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_READ_CHAR_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_WRITE_CHAR_EVT:
@ -559,7 +565,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
param.write.status = write->status;
bta_to_btc_srvc_id(&param.write.srvc_id, &write->srvc_id);
bta_to_btc_gatt_id(&param.write.char_id, &write->char_id);
BTC_GATTC_CB_TO_APP(ret_evt, gattc_if, &param);
btc_gattc_cb_to_app(ret_evt, gattc_if, &param);
break;
}
@ -569,7 +575,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
gattc_if = BTC_GATT_GET_GATT_IF(exec_cmpl->conn_id);
param.exec_cmpl.conn_id = BTC_GATT_GET_CONN_ID(exec_cmpl->conn_id);
param.exec_cmpl.status = exec_cmpl->status;
BTC_GATTC_CB_TO_APP(ESP_GATTC_EXEC_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_EXEC_EVT, gattc_if, &param);
break;
}
@ -579,7 +585,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
gattc_if = BTC_GATT_GET_GATT_IF(search_cmpl->conn_id);
param.search_cmpl.conn_id = BTC_GATT_GET_CONN_ID(search_cmpl->conn_id);
param.search_cmpl.status = search_cmpl->status;
BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_CMPL_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_SEARCH_CMPL_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_SEARCH_RES_EVT: {
@ -588,12 +594,12 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
gattc_if = BTC_GATT_GET_GATT_IF(srvc_res->conn_id);
param.search_res.conn_id = BTC_GATT_GET_CONN_ID(srvc_res->conn_id);
bta_to_btc_srvc_id(&param.search_res.srvc_id, &srvc_res->service_uuid);
BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_RES_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_SEARCH_RES_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_READ_DESCR_EVT: {
set_read_value(&gattc_if, &param, &arg->read);
BTC_GATTC_CB_TO_APP(ESP_GATTC_READ_DESCR_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_READ_DESCR_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_WRITE_DESCR_EVT: {
@ -605,7 +611,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
bta_to_btc_srvc_id(&param.write.srvc_id, &write->srvc_id);
bta_to_btc_gatt_id(&param.write.char_id, &write->char_id);
bta_to_btc_gatt_id(&param.write.descr_id, &write->descr_type);
BTC_GATTC_CB_TO_APP(ESP_GATTC_WRITE_DESCR_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_WRITE_DESCR_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_NOTIF_EVT: {
@ -626,7 +632,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
BTA_GATTC_SendIndConfirm(notify->conn_id, &notify->char_id);
}
BTC_GATTC_CB_TO_APP(ESP_GATTC_NOTIFY_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_NOTIFY_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_OPEN_EVT: {
@ -637,7 +643,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
param.open.conn_id = BTC_GATT_GET_CONN_ID(open->conn_id);
memcpy(param.open.remote_bda, open->remote_bda, sizeof(esp_bd_addr_t));
param.open.mtu = open->mtu;
BTC_GATTC_CB_TO_APP(ESP_GATTC_OPEN_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_OPEN_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_CLOSE_EVT: {
@ -648,7 +654,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
param.close.conn_id = BTC_GATT_GET_CONN_ID(close->conn_id);
memcpy(param.close.remote_bda, close->remote_bda, sizeof(esp_bd_addr_t));
param.close.reason = close->reason;
BTC_GATTC_CB_TO_APP(ESP_GATTC_CLOSE_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_CLOSE_EVT, gattc_if, &param);
break;
}
@ -659,7 +665,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
param.cfg_mtu.conn_id = BTC_GATT_GET_CONN_ID(cfg_mtu->conn_id);
param.cfg_mtu.status = cfg_mtu->status;
param.cfg_mtu.mtu = cfg_mtu->mtu;
BTC_GATTC_CB_TO_APP(ESP_GATTC_CFG_MTU_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_CFG_MTU_EVT, gattc_if, &param);
break;
}
@ -677,12 +683,12 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
gattc_if = BTC_GATT_GET_GATT_IF(congest->conn_id);
param.congest.conn_id = BTC_GATT_GET_CONN_ID(congest->conn_id);
param.congest.congested = (congest->congested == TRUE) ? true : false;
BTC_GATTC_CB_TO_APP(ESP_GATTC_CONGEST_EVT, gattc_if, &param);
btc_gattc_cb_to_app(ESP_GATTC_CONGEST_EVT, gattc_if, &param);
break;
}
case BTA_GATTC_SRVC_CHG_EVT: {
memcpy(param.srvc_chg.remote_bda, arg->remote_bda, sizeof(esp_bd_addr_t));
BTC_GATTC_CB_TO_APP(ESP_GATTC_SRVC_CHG_EVT, ESP_GATT_IF_NONE, &param);
btc_gattc_cb_to_app(ESP_GATTC_SRVC_CHG_EVT, ESP_GATT_IF_NONE, &param);
break;
}
default:

View File

@ -23,11 +23,17 @@
#include "esp_gatts_api.h"
#define BTC_GATTS_CB_TO_APP(event, gatts_if, param) ((esp_gatts_cb_t)btc_profile_cb_get(BTC_PID_GATTS))((event), (gatts_if), (param))
#define A2C_GATTS_EVT(_bta_event) (_bta_event) //BTA TO BTC EVT
#define C2A_GATTS_EVT(_btc_event) (_btc_event) //BTC TO BTA EVT
static inline void btc_gatts_cb_to_app(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
{
esp_gatts_cb_t btc_gatts_cb = (esp_gatts_cb_t)btc_profile_cb_get(BTC_PID_GATTS);
if (btc_gatts_cb) {
btc_gatts_cb(event, gatts_if, param);
}
}
void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
{
btc_ble_gatts_args_t *dst = (btc_ble_gatts_args_t *) p_dest;
@ -227,7 +233,7 @@ void btc_gatts_call_handler(btc_msg_t *msg)
}
param.rsp.status = 0;
BTC_GATTS_CB_TO_APP(ESP_GATTS_RESPONSE_EVT, BTC_GATT_GET_GATT_IF(arg->send_rsp.conn_id), &param);
btc_gatts_cb_to_app(ESP_GATTS_RESPONSE_EVT, BTC_GATT_GET_GATT_IF(arg->send_rsp.conn_id), &param);
break;
}
case BTC_GATTS_ACT_OPEN: {
@ -286,12 +292,12 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.reg.status = p_data->reg_oper.status;
param.reg.app_id = p_data->reg_oper.uuid.uu.uuid16;
BTC_GATTS_CB_TO_APP(ESP_GATTS_REG_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_REG_EVT, gatts_if, &param);
break;
}
case BTA_GATTS_DEREG_EVT: {
gatts_if = p_data->reg_oper.server_if;
BTC_GATTS_CB_TO_APP(ESP_GATTS_UNREG_EVT, gatts_if, NULL);
btc_gatts_cb_to_app(ESP_GATTS_UNREG_EVT, gatts_if, NULL);
break;
}
case BTA_GATTS_READ_EVT: {
@ -299,11 +305,11 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.read.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
param.read.trans_id = p_data->req_data.trans_id;
memcpy(param.read.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
param.read.handle = p_data->req_data.p_data->read_req.handle,
param.read.offset = p_data->req_data.p_data->read_req.offset,
param.read.is_long = p_data->req_data.p_data->read_req.is_long,
param.read.handle = p_data->req_data.p_data->read_req.handle;
param.read.offset = p_data->req_data.p_data->read_req.offset;
param.read.is_long = p_data->req_data.p_data->read_req.is_long;
BTC_GATTS_CB_TO_APP(ESP_GATTS_READ_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_READ_EVT, gatts_if, &param);
break;
}
case BTA_GATTS_WRITE_EVT: {
@ -318,7 +324,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.write.len = p_data->req_data.p_data->write_req.len;
param.write.value = p_data->req_data.p_data->write_req.value;
BTC_GATTS_CB_TO_APP(ESP_GATTS_WRITE_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_WRITE_EVT, gatts_if, &param);
break;
}
@ -329,7 +335,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
memcpy(param.exec_write.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
param.exec_write.exec_write_flag = p_data->req_data.p_data->exec_write;
BTC_GATTS_CB_TO_APP(ESP_GATTS_EXEC_WRITE_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_EXEC_WRITE_EVT, gatts_if, &param);
break;
}
case BTA_GATTS_MTU_EVT:
@ -337,14 +343,14 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.mtu.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
param.mtu.mtu = p_data->req_data.p_data->mtu;
BTC_GATTS_CB_TO_APP(ESP_GATTS_MTU_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_MTU_EVT, gatts_if, &param);
break;
case BTA_GATTS_CONF_EVT:
gatts_if = BTC_GATT_GET_GATT_IF(p_data->req_data.conn_id);
param.conf.conn_id = BTC_GATT_GET_CONN_ID(p_data->req_data.conn_id);
param.conf.status = p_data->req_data.status;
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONF_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_CONF_EVT, gatts_if, &param);
break;
case BTA_GATTS_CREATE_EVT:
gatts_if = p_data->create.server_if;
@ -353,7 +359,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.create.service_id.is_primary = p_data->create.is_primary;
param.create.service_id.id.inst_id = p_data->create.svc_instance;
bta_to_btc_uuid(&param.create.service_id.id.uuid, &p_data->create.uuid);
BTC_GATTS_CB_TO_APP(ESP_GATTS_CREATE_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_CREATE_EVT, gatts_if, &param);
break;
case BTA_GATTS_ADD_INCL_SRVC_EVT:
gatts_if = p_data->add_result.server_if;
@ -361,7 +367,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.add_incl_srvc.attr_handle = p_data->add_result.attr_id;
param.add_incl_srvc.service_handle = p_data->add_result.service_id;
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_INCL_SRVC_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_ADD_INCL_SRVC_EVT, gatts_if, &param);
break;
case BTA_GATTS_ADD_CHAR_EVT:
gatts_if = p_data->add_result.server_if;
@ -370,7 +376,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.add_char.service_handle = p_data->add_result.service_id;
bta_to_btc_uuid(&param.add_char.char_uuid, &p_data->add_result.char_uuid);
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_ADD_CHAR_EVT, gatts_if, &param);
break;
case BTA_GATTS_ADD_CHAR_DESCR_EVT:
gatts_if = p_data->add_result.server_if;
@ -379,27 +385,27 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.add_char_descr.service_handle = p_data->add_result.service_id;
bta_to_btc_uuid(&param.add_char_descr.char_uuid, &p_data->add_result.char_uuid);
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_DESCR_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_ADD_CHAR_DESCR_EVT, gatts_if, &param);
break;
case BTA_GATTS_DELELTE_EVT:
gatts_if = p_data->srvc_oper.server_if;
param.del.status = p_data->srvc_oper.status;
param.del.service_handle = p_data->srvc_oper.service_id;
BTC_GATTS_CB_TO_APP(ESP_GATTS_DELETE_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_DELETE_EVT, gatts_if, &param);
break;
case BTA_GATTS_START_EVT:
gatts_if = p_data->srvc_oper.server_if;
param.start.status = p_data->srvc_oper.status;
param.start.service_handle = p_data->srvc_oper.service_id;
BTC_GATTS_CB_TO_APP(ESP_GATTS_START_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_START_EVT, gatts_if, &param);
break;
case BTA_GATTS_STOP_EVT:
gatts_if = p_data->srvc_oper.server_if;
param.stop.status = p_data->srvc_oper.status;
param.stop.service_handle = p_data->srvc_oper.service_id;
BTC_GATTS_CB_TO_APP(ESP_GATTS_STOP_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_STOP_EVT, gatts_if, &param);
break;
case BTA_GATTS_CONNECT_EVT:
gatts_if = p_data->conn.server_if;
@ -407,7 +413,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.connect.is_connected = true;
memcpy(param.connect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONNECT_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_CONNECT_EVT, gatts_if, &param);
break;
case BTA_GATTS_DISCONNECT_EVT:
gatts_if = p_data->conn.server_if;
@ -415,7 +421,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
param.disconnect.is_connected = false;
memcpy(param.disconnect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
BTC_GATTS_CB_TO_APP(ESP_GATTS_DISCONNECT_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_DISCONNECT_EVT, gatts_if, &param);
break;
case BTA_GATTS_OPEN_EVT:
// do nothing
@ -430,7 +436,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
gatts_if = BTC_GATT_GET_GATT_IF(p_data->congest.conn_id);
param.congest.conn_id = BTC_GATT_GET_CONN_ID(p_data->congest.conn_id);
param.congest.congested = p_data->congest.congested;
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONGEST_EVT, gatts_if, &param);
btc_gatts_cb_to_app(ESP_GATTS_CONGEST_EVT, gatts_if, &param);
break;
default:
// do nothing