1. Actually, btc & api are the same module thing. So the type defined in api header file can be included by btc c/h files.
Besides, why btc & api should be separated, because that user may be aware of api and api refer defines/types, rather than other non-refer things.
All defines/types that user won't use should be put in btc directory (and define with prefix "btc_"), and which will be used by user should be defined with prefix "esp_" .
2. rename attribute value(all is value, not data)
*******************************************************************************/
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback)
{
- btc_msg_t msg;
- esp_ble_gattc_args_t arg;
-
if (callback == NULL) {
return ESP_FAIL;
}
esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_APP_REGISTER;
arg.app_id = app_id;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_APP_UNREGISTER;
arg.gatt_if = gatt_if;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
memcpy(arg.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
arg.is_direct = is_direct;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
esp_err_t esp_ble_gattc_close (uint16_t conn_id)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_CLOSE;
arg.conn_id = conn_id;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
if ((mtu < ESP_GATT_DEF_BLE_MTU_SIZE) || (mtu > ESP_GATT_MAX_MTU_SIZE)) {
return ESP_GATT_ILLEGAL_PARAMETER;
arg.conn_id = conn_id;
arg.mtu = mtu;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
arg.conn_id = conn_id;
memcpy(&arg.uuid, filter_uuid, sizeof(esp_bt_uuid_t));
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_id_t *start_char_id)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_GET_FIRST_CHAR;
}
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_id_t *start_descr_id)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_GET_FIRST_DESCR;
}
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_srvc_id_t *start_incl_srvc_id)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE;
}
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
esp_gatt_id_t *char_id, esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
memcpy(&arg.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.char_id, char_id, sizeof(esp_gatt_id_t));
arg.auth_req = auth_req;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
memcpy(&arg.char_id, char_id, sizeof(esp_gatt_id_t));
memcpy(&arg.descr_id, descr_id, sizeof(esp_gatt_id_t));
arg.auth_req = auth_req;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
** @param[in] conn_id - connection ID.
** @param[in] srvc_id - serivcie ID.
** @param[in] char_id - characteristic ID to write.
-** @param[in] len: length of the data to be written.
+** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
- uint16_t len,
+ uint16_t value_len,
uint8_t *value,
esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
arg.conn_id = (uint16_t) conn_id;
memcpy(&arg.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.char_id, char_id, sizeof(esp_gatt_id_t));
- arg.len = len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : len;
- memcpy(arg.value, value, arg.len);
+ arg.value_len = value_len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : value_len;
+ memcpy(arg.value, value, arg.value_len);
arg.auth_req = auth_req;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
** @param[in] srvc_id - serivcie ID.
** @param[in] char_id - characteristic ID.
** @param[in] descr_id - characteristic descriptor ID to write.
+** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *descr_id,
- uint16_t len,
+ uint16_t value_len,
uint8_t *value,
esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
memcpy(&arg.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.char_id, char_id, sizeof(esp_gatt_id_t));
memcpy(&arg.descr_id, descr_id, sizeof(esp_gatt_id_t));
- arg.len = len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : len;
- memcpy(arg.value, value, arg.len);
+ arg.value_len = value_len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : value_len;
+ memcpy(arg.value, value, arg.value_len);
arg.auth_req = auth_req;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
** @param[in] conn_id - connection ID.
** @param[in] char_id - GATT characteritic ID of the service.
** @param[in] offset - offset of the write value.
-** @param[in] len: length of the data to be written.
+** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
uint16_t offset,
- uint16_t len,
- uint8_t *data,
+ uint16_t value_len,
+ uint8_t *value,
esp_gatt_auth_req_t auth_req)
{
//TODO: Review this function
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
memcpy(&arg.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.char_id, char_id, sizeof(esp_gatt_id_t));
arg.offset = offset;
- arg.len = len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : len; // length check ?
- memcpy(arg.value, data, arg.len);
+ arg.value_len = value_len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : value_len; // length check ?
+ memcpy(arg.value, value, arg.value_len);
arg.auth_req = auth_req;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_EXECUTE_WRITE;
arg.conn_id = conn_id;
arg.is_execute = is_execute;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_id_t *char_id)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
memcpy(&arg.remote_bda, &server_bda, sizeof(esp_bd_addr_t));
memcpy(&arg.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.char_id, char_id, sizeof(esp_gatt_id_t));
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_id_t *char_id)
{
btc_msg_t msg;
- esp_ble_gattc_args_t arg;
+ btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
memcpy(&arg.remote_bda, &server_bda, sizeof(esp_bd_addr_t));
memcpy(&arg.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.char_id, char_id, sizeof(esp_gatt_id_t));
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_app_register(uint16_t app_id)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
uint16_t app_uuid;
if (app_id < APP_ID_MIN || app_id > APP_ID_MAX)
msg.act = BTC_GATTS_ACT_APP_REGISTER;
arg.app_uuid = app_id;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_APP_UNREGISTER;
arg.gatt_if = gatt_if;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
esp_gatt_srvc_id_t *service_id, uint16_t num_handle)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
arg.num_handle = num_handle;
memcpy(&arg.service_id, service_id, sizeof(esp_gatt_srvc_id_t));
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_add_include_service(uint16_t service_handle, uint16_t included_service_handle)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
arg.service_handle = service_handle;
arg.included_service_handle = included_service_handle;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_perm_t perm, esp_gatt_char_prop_t property)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
arg.property = property;
memcpy(&arg.uuid, char_uuid, sizeof(esp_bt_uuid_t));
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_perm_t perm)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
arg.perm = perm;
memcpy(&arg.descr_uuid, descr_uuid, sizeof(esp_bt_uuid_t));
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_DELETE_SERVICE;
arg.service_handle = service_handle;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_start_service(uint16_t service_handle)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_START_SERVICE;
arg.service_handle = service_handle;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_STOP_SERVICE;
arg.service_handle = service_handle;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
- uint16_t data_len, uint8_t *data, bool need_confirm)
+ uint16_t value_len, uint8_t *value, bool need_confirm)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_SEND_INDICATE;
arg.conn_id = conn_id;
arg.attr_handle = attr_handle;
- arg.data_len = data_len;
+ arg.value_len = value_len;
arg.need_confirm = need_confirm;
- memcpy(&arg.data, data, data_len);
+ memcpy(&arg.value, value, value_len);
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
esp_gatt_status_t status, esp_gatt_rsp_t *rsp)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
arg.status = status;
memcpy(&arg.rsp, rsp, sizeof(esp_gatt_rsp_t));
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
arg.is_direct = is_direct;
memcpy(&arg.remote_bda, remote_bda, sizeof(esp_bd_addr_t));
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_close(uint16_t conn_id)
{
btc_msg_t msg;
- esp_ble_gatts_args_t arg;
+ btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_CLOSE;
arg.conn_id = conn_id;
- return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+ return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#define ESP_GATT_DEF_BLE_MTU_SIZE 23
#define ESP_GATT_MAX_MTU_SIZE 517
-
-/* esp_ble_gattc_args_t */
-typedef struct {
- uint16_t app_id;
- uint16_t conn_id;
- uint16_t mtu;
- uint16_t len;
- uint16_t offset;
- esp_gatt_if_t gatt_if; /* internal is server_if or client_if */
- esp_gatt_srvc_id_t service_id;
- esp_gatt_srvc_id_t start_service_id;
- esp_gatt_id_t char_id;
- esp_gatt_id_t descr_id;
- esp_gatt_auth_req_t auth_req;
- esp_bd_addr_t remote_bda;
- esp_bt_uuid_t uuid;
- bool is_direct;
- bool is_execute;
- uint8_t value[ESP_GATT_MAX_ATTR_LEN];
-} esp_ble_gattc_args_t;
-
/* esp_ble_gattc_cb_param_t */
typedef union {
/*registration data for ESP_GATTC_REG_EVT */
** @param[in] conn_id - connection ID.
** @param[in] srvc_id - serivcie ID.
** @param[in] char_id - characteristic ID to write.
-** @param[in] len: length of the data to be written.
+** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
- uint16_t len,
+ uint16_t value_len,
uint8_t *value,
esp_gatt_auth_req_t auth_req);
** @param[in] srvc_id - serivcie ID.
** @param[in] char_id - characteristic ID.
** @param[in] descr_id - characteristic descriptor ID to write.
+** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *descr_id,
- uint16_t len,
+ uint16_t value_len,
uint8_t *value,
esp_gatt_auth_req_t auth_req);
** @param[in] conn_id - connection ID.
** @param[in] char_id - GATT characteritic ID of the service.
** @param[in] offset - offset of the write value.
-** @param[in] len: length of the data to be written.
+** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
uint16_t offset,
- uint16_t len,
- uint8_t *data,
+ uint16_t value_len,
+ uint8_t *value,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
/* following is extra event */
#define ESP_GATTS_RESPONSE_EVT 21
-/* esp_ble_gatts_args_t */
-typedef struct {
- esp_gatt_if_t gatt_if; /* internal is server_if or client_if */
- esp_gatt_srvc_id_t service_id;
- esp_gatt_id_t char_id;
- esp_gatt_id_t descr_uuid;
- esp_bt_uuid_t uuid;
- esp_gatt_rsp_t rsp;
- esp_gatt_perm_t perm;
- esp_gatt_char_prop_t property;
- esp_bd_addr_t remote_bda;
- esp_gatt_status_t status;
- uint16_t service_handle;
- uint16_t included_service_handle;
- uint16_t attr_handle;
- uint16_t num_handle;
- uint16_t conn_id;
- uint16_t trans_id;
- bool need_confirm;
- bool is_direct;
- uint16_t app_uuid;
- uint16_t data_len;
- uint8_t data[ESP_GATT_MAX_ATTR_LEN];
-} esp_ble_gatts_args_t;
-
-
/* esp_ble_gatts_cb_param_t */
typedef union {
//ESP_GATTS_REG_EVT
**
** @param[in] conn_id - connection id to indicate.
** @param[in] attribute_handle - attribute handle to indicate.
-** @param[in] data_len - indicate data length.
-** @param[in] data: data to indicate.
+** @param[in] value_len - indicate value length.
+** @param[in] value: value to indicate.
** @param[in] need_confirm - if this indication expects a confirmation or not.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
- uint16_t data_len, uint8_t *data, bool need_confirm);
+ uint16_t value_len, uint8_t *value, bool need_confirm);
/*******************************************************************************
LOG_ERROR("%s transfer failed\n", __func__);
}
-static void btc_gattc_app_register(esp_ble_gattc_args_t *arg)
+static void btc_gattc_app_register(btc_ble_gattc_args_t *arg)
{
tBT_UUID app_uuid;
app_uuid.len = 2;
BTA_GATTC_AppRegister(&app_uuid, btc_gattc_cback);
}
-static void btc_gattc_app_unregister(esp_ble_gattc_args_t *arg)
+static void btc_gattc_app_unregister(btc_ble_gattc_args_t *arg)
{
BTA_GATTC_AppDeregister(arg->gatt_if);
}
-static void btc_gattc_open(esp_ble_gattc_args_t *arg)
+static void btc_gattc_open(btc_ble_gattc_args_t *arg)
{
tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
BTA_GATTC_Open(arg->gatt_if, arg->remote_bda, arg->is_direct, transport);
}
-static void btc_gattc_close(esp_ble_gattc_args_t *arg)
+static void btc_gattc_close(btc_ble_gattc_args_t *arg)
{
// TODO; Review this call of BTA_API, check the usage of BTA_GATTC_CancelOpen
BTA_GATTC_Close(arg->conn_id);
}
-static void btc_gattc_cfg_mtu(esp_ble_gattc_args_t *arg)
+static void btc_gattc_cfg_mtu(btc_ble_gattc_args_t *arg)
{
BTA_GATTC_ConfigureMTU (arg->conn_id, arg->mtu);
}
-static void btc_gattc_search_service(esp_ble_gattc_args_t *arg)
+static void btc_gattc_search_service(btc_ble_gattc_args_t *arg)
{
tBT_UUID *srvc_uuid = (tBT_UUID *)(&arg->uuid);
BTA_GATTC_ServiceSearchRequest(arg->conn_id, srvc_uuid);
}
-static void btc_gattc_get_first_char(esp_ble_gattc_args_t *arg)
+static void btc_gattc_get_first_char(btc_ble_gattc_args_t *arg)
{
esp_gatt_id_t char_id;
tBTA_GATT_STATUS status;
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, ¶m);
}
-static void btc_gattc_get_next_char(esp_ble_gattc_args_t *arg)
+static void btc_gattc_get_next_char(btc_ble_gattc_args_t *arg)
{
esp_gatt_id_t char_id;
tBTA_GATT_STATUS status;
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, ¶m);
}
-static void btc_gattc_get_first_descr(esp_ble_gattc_args_t *arg)
+static void btc_gattc_get_first_descr(btc_ble_gattc_args_t *arg)
{
esp_gatt_id_t descr_id;
tBTA_GATT_STATUS status;
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, ¶m);
}
-static void btc_gattc_get_next_descr(esp_ble_gattc_args_t *arg)
+static void btc_gattc_get_next_descr(btc_ble_gattc_args_t *arg)
{
esp_gatt_id_t descr_id;
tBTA_GATT_STATUS status;
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, ¶m);
}
-static void btc_gattc_get_first_incl_service(esp_ble_gattc_args_t *arg)
+static void btc_gattc_get_first_incl_service(btc_ble_gattc_args_t *arg)
{
esp_gatt_srvc_id_t incl_srvc_id;
tBTA_GATT_STATUS status;
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, ¶m);
}
-static void btc_gattc_get_next_incl_service(esp_ble_gattc_args_t *arg)
+static void btc_gattc_get_next_incl_service(btc_ble_gattc_args_t *arg)
{
esp_gatt_srvc_id_t incl_srvc_id;
tBTA_GATT_STATUS status;
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, ¶m);
}
-static void btc_gattc_read_char(esp_ble_gattc_args_t *arg)
+static void btc_gattc_read_char(btc_ble_gattc_args_t *arg)
{
tBTA_GATTC_CHAR_ID in_char_id;
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->service_id);
BTA_GATTC_ReadCharacteristic(arg->conn_id, &in_char_id, arg->auth_req);
}
-static void btc_gattc_read_char_descr(esp_ble_gattc_args_t *arg)
+static void btc_gattc_read_char_descr(btc_ble_gattc_args_t *arg)
{
tBTA_GATTC_CHAR_DESCR_ID in_char_descr_id;
btc_to_bta_srvc_id(&in_char_descr_id.char_id.srvc_id, &arg->service_id);
BTA_GATTC_ReadCharDescr(arg->conn_id, &in_char_descr_id, arg->auth_req);
}
-static void btc_gattc_write_char(esp_ble_gattc_args_t *arg)
+static void btc_gattc_write_char(btc_ble_gattc_args_t *arg)
{
//TODO: check the write type
tBTA_GATTC_CHAR_ID in_char_id;
BTA_GATTC_WriteCharValue(arg->conn_id, &in_char_id,
write_type,
- arg->len,
+ arg->value_len,
arg->value,
arg->auth_req);
}
-static void btc_gattc_write_char_descr(esp_ble_gattc_args_t *arg)
+static void btc_gattc_write_char_descr(btc_ble_gattc_args_t *arg)
{
//TODO: check the write type
tBTA_GATTC_CHAR_DESCR_ID in_char_descr_id;
btc_to_bta_gatt_id(&in_char_descr_id.char_id.char_id, &arg->char_id);
btc_to_bta_gatt_id(&in_char_descr_id.descr_id, &arg->descr_id);
- descr_val.len = arg->len;
+ descr_val.len = arg->value_len;
descr_val.p_value = arg->value;
BTA_GATTC_WriteCharDescr(arg->conn_id, &in_char_descr_id,
arg->auth_req);
}
-static void btc_gattc_prepare_write(esp_ble_gattc_args_t *arg)
+static void btc_gattc_prepare_write(btc_ble_gattc_args_t *arg)
{
tBTA_GATTC_CHAR_ID in_char_id;
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->service_id);
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->char_id);
- BTA_GATTC_PrepareWrite(arg->conn_id, &in_char_id, arg->offset, arg->len,
+ BTA_GATTC_PrepareWrite(arg->conn_id, &in_char_id, arg->offset, arg->value_len,
arg->value, arg->auth_req);
}
-static void btc_gattc_execute_wrtie(esp_ble_gattc_args_t *arg)
+static void btc_gattc_execute_wrtie(btc_ble_gattc_args_t *arg)
{
BTA_GATTC_ExecuteWrite(arg->conn_id, arg->is_execute);
}
-static void btc_gattc_reg_for_notify(esp_ble_gattc_args_t *arg)
+static void btc_gattc_reg_for_notify(btc_ble_gattc_args_t *arg)
{
tBTA_GATT_STATUS status;
tBTA_GATTC_CHAR_ID in_char_id;
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_FOR_NOTIF_EVT, ¶m);
}
-static void btc_gattc_unreg_for_notify(esp_ble_gattc_args_t *arg)
+static void btc_gattc_unreg_for_notify(btc_ble_gattc_args_t *arg)
{
tBTA_GATT_STATUS status;
tBTA_GATTC_CHAR_ID in_char_id;
void btc_gattc_call_handler(btc_msg_t *msg)
{
- esp_ble_gattc_args_t *arg = (esp_ble_gattc_args_t *)(msg->arg);
+ btc_ble_gattc_args_t *arg = (btc_ble_gattc_args_t *)(msg->arg);
switch (msg->act) {
case BTC_GATTC_ACT_APP_REGISTER:
btc_gattc_app_register(arg);
void btc_gatts_call_handler(btc_msg_t *msg)
{
- esp_ble_gatts_args_t *arg = (esp_ble_gatts_args_t *)msg->arg;
+ btc_ble_gatts_args_t *arg = (btc_ble_gatts_args_t *)msg->arg;
switch (msg->act) {
case BTC_GATTS_ACT_APP_REGISTER: {
}
case BTC_GATTS_ACT_SEND_INDICATE:
BTA_GATTS_HandleValueIndication(arg->conn_id, arg->attr_handle,
- arg->data_len, arg->data, arg->need_confirm);
+ arg->value_len, arg->value, arg->need_confirm);
break;
case BTC_GATTS_ACT_SEND_RESPONSE: {
esp_ble_gatts_cb_param_t param;
#define __BTC_GATTC_H__
#include "btc_task.h"
+#include "esp_bt_defs.h"
+#include "esp_gatt_defs.h"
+#include "esp_gattc_api.h"
typedef enum {
BTC_GATTC_ACT_APP_REGISTER,
BTC_GATTC_ACT_UNREG_FOR_NOTIFY
} btc_gattc_act_t;
+/* btc_ble_gattc_args_t */
+typedef struct {
+ esp_gatt_if_t gatt_if; /* internal is server_if or client_if */
+ esp_gatt_srvc_id_t service_id;
+ esp_gatt_srvc_id_t start_service_id;
+ esp_gatt_id_t char_id;
+ esp_gatt_id_t descr_id;
+ esp_gatt_auth_req_t auth_req;
+ esp_bd_addr_t remote_bda;
+ esp_bt_uuid_t uuid;
+ uint16_t app_id;
+ uint16_t conn_id;
+ uint16_t mtu;
+ uint16_t offset;
+ bool is_direct;
+ bool is_execute;
+ uint16_t value_len;
+ uint8_t value[ESP_GATT_MAX_ATTR_LEN];
+} btc_ble_gattc_args_t;
+
void btc_gattc_call_handler(btc_msg_t *msg);
void btc_gattc_cb_handler(btc_msg_t *msg);
#ifndef __BTC_GATTS_H__
#define __BTC_GATTS_H__
+
#include "btc_task.h"
+#include "esp_bt_defs.h"
+#include "esp_gatt_defs.h"
+#include "esp_gatts_api.h"
typedef enum {
BTC_GATTS_ACT_APP_REGISTER = 0,
BTC_GATTS_ACT_CLOSE,
} btc_gatts_act_t;
+/* btc_ble_gatts_args_t */
+typedef struct {
+ esp_gatt_if_t gatt_if; /* internal is server_if or client_if */
+ esp_gatt_srvc_id_t service_id;
+ esp_gatt_id_t char_id;
+ esp_gatt_id_t descr_uuid;
+ esp_bt_uuid_t uuid;
+ esp_gatt_rsp_t rsp;
+ esp_gatt_perm_t perm;
+ esp_gatt_char_prop_t property;
+ esp_bd_addr_t remote_bda;
+ esp_gatt_status_t status;
+ uint16_t service_handle;
+ uint16_t included_service_handle;
+ uint16_t attr_handle;
+ uint16_t num_handle;
+ uint16_t conn_id;
+ uint16_t trans_id;
+ bool need_confirm;
+ bool is_direct;
+ uint16_t app_uuid;
+ uint16_t value_len;
+ uint8_t value[ESP_GATT_MAX_ATTR_LEN];
+} btc_ble_gatts_args_t;
void btc_gatts_call_handler(btc_msg_t *msg);