mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'feature/btdm_blufi_add_custom_data_cmd' into 'master'
Component/bt: blufi add custom data cmd See merge request idf/esp-idf!2017
This commit is contained in:
commit
d3d3a6fc39
@ -142,3 +142,23 @@ esp_err_t esp_blufi_send_error_info(esp_blufi_error_state_t state)
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_blufi_send_custom_data(uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_blufi_args_t arg;
|
||||
if(data == NULL || data_len == 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_BLUFI;
|
||||
msg.act = BTC_BLUFI_ACT_SEND_CUSTOM_DATA;
|
||||
arg.custom_data.data = data;
|
||||
arg.custom_data.data_len = data_len;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), btc_blufi_call_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ typedef enum {
|
||||
ESP_BLUFI_EVENT_RECV_SLAVE_DISCONNECT_BLE, /*<! When Phone send Disconnect key to ESP32, this event happen */
|
||||
ESP_BLUFI_EVENT_GET_WIFI_LIST, /*<! When Phone send get wifi list command to ESP32, this event happen */
|
||||
ESP_BLUFI_EVENT_REPORT_ERROR, /*<! When Blufi report error, this event happen */
|
||||
ESP_BLUFI_EVENT_RECV_CUSTOM_DATA, /*<! When Phone send custom data to ESP32, this event happen */
|
||||
} esp_blufi_cb_event_t;
|
||||
|
||||
/// BLUFI config status
|
||||
@ -273,8 +274,15 @@ typedef union {
|
||||
*/
|
||||
struct blufi_get_error_evt_param {
|
||||
esp_blufi_error_state_t state; /*!< Blufi error state */
|
||||
} report_error; /*!< Blufi callback param of ESP_BLUFI_EVENT_REPORT_ERROR */
|
||||
|
||||
} report_error; /*!< Blufi callback param of ESP_BLUFI_EVENT_REPORT_ERROR */
|
||||
/**
|
||||
* @brief
|
||||
* ESP_BLUFI_EVENT_RECV_CUSTOM_DATA
|
||||
*/
|
||||
struct blufi_recv_custom_data_evt_param {
|
||||
uint8_t *data; /*!< Custom data */
|
||||
uint32_t data_len; /*!< Custom data Length */
|
||||
} custom_data; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_CUSTOM_DATA */
|
||||
} esp_blufi_cb_param_t;
|
||||
|
||||
/**
|
||||
@ -416,6 +424,16 @@ esp_err_t esp_blufi_close(esp_gatt_if_t gatts_if, uint16_t conn_id);
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_send_error_info(esp_blufi_error_state_t state);
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to custom data
|
||||
* @param data : custom data value
|
||||
* @param data_len : the length of custom data
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_send_custom_data(uint8_t *data, uint32_t data_len);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -660,6 +660,23 @@ static void btc_blufi_send_error_info(uint8_t state)
|
||||
osi_free(data);
|
||||
}
|
||||
|
||||
static void btc_blufi_send_custom_data(uint8_t *value, uint32_t value_len)
|
||||
{
|
||||
if(value == NULL || value_len == 0) {
|
||||
LOG_ERROR("%s value or value len error", __func__);
|
||||
return;
|
||||
}
|
||||
uint8_t *data = osi_malloc(value_len);
|
||||
if (data == NULL) {
|
||||
LOG_ERROR("%s mem malloc error", __func__);
|
||||
return;
|
||||
}
|
||||
uint8_t type = BLUFI_BUILD_TYPE(BLUFI_TYPE_DATA, BLUFI_TYPE_DATA_SUBTYPE_CUSTOM_DATA);
|
||||
memcpy(data, value, value_len);
|
||||
btc_blufi_send_encap(type, data, value_len);
|
||||
osi_free(data);
|
||||
}
|
||||
|
||||
void btc_blufi_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_blufi_cb_param_t *dst = (esp_blufi_cb_param_t *) p_dest;
|
||||
@ -736,6 +753,14 @@ void btc_blufi_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
}
|
||||
memcpy(dst->server_pkey.pkey, src->server_pkey.pkey, src->server_pkey.pkey_len);
|
||||
break;
|
||||
case ESP_BLUFI_EVENT_RECV_CUSTOM_DATA:
|
||||
dst->custom_data.data = osi_malloc(src->custom_data.data_len);
|
||||
if (dst->custom_data.data == NULL) {
|
||||
LOG_ERROR("%s %d no mem\n", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
memcpy(dst->custom_data.data, src->custom_data.data, src->custom_data.data_len);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -776,6 +801,9 @@ void btc_blufi_cb_deep_free(btc_msg_t *msg)
|
||||
case ESP_BLUFI_EVENT_RECV_SERVER_PRIV_KEY:
|
||||
osi_free(param->server_pkey.pkey);
|
||||
break;
|
||||
case ESP_BLUFI_EVENT_RECV_CUSTOM_DATA:
|
||||
osi_free(param->custom_data.data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -866,6 +894,9 @@ void btc_blufi_cb_handler(btc_msg_t *msg)
|
||||
case ESP_BLUFI_EVENT_REPORT_ERROR:
|
||||
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_REPORT_ERROR, param);
|
||||
break;
|
||||
case ESP_BLUFI_EVENT_RECV_CUSTOM_DATA:
|
||||
btc_blufi_cb_to_app(ESP_BLUFI_EVENT_RECV_CUSTOM_DATA, param);
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s UNKNOWN %d\n", __func__, msg->act);
|
||||
break;
|
||||
@ -961,6 +992,20 @@ void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
memcpy(dst->wifi_list.list, list, sizeof(esp_blufi_ap_record_t) * src->wifi_list.apCount);
|
||||
break;
|
||||
}
|
||||
case BTC_BLUFI_ACT_SEND_CUSTOM_DATA:{
|
||||
uint8_t *data = src->custom_data.data;
|
||||
if(data == NULL) {
|
||||
LOG_ERROR("custom data is NULL\n");
|
||||
break;
|
||||
}
|
||||
dst->custom_data.data = osi_malloc(src->custom_data.data_len);
|
||||
if(dst->custom_data.data == NULL) {
|
||||
LOG_ERROR("custom data malloc error\n");
|
||||
break;
|
||||
}
|
||||
memcpy(dst->custom_data.data, src->custom_data.data, src->custom_data.data_len);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -999,6 +1044,13 @@ void btc_blufi_call_deep_free(btc_msg_t *msg)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLUFI_ACT_SEND_CUSTOM_DATA:{
|
||||
uint8_t *data = arg->custom_data.data;
|
||||
if(data) {
|
||||
osi_free(data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1029,6 +1081,9 @@ void btc_blufi_call_handler(btc_msg_t *msg)
|
||||
case BTC_BLUFI_ACT_SEND_ERR_INFO:
|
||||
btc_blufi_send_error_info(arg->blufi_err_infor.state);
|
||||
break;
|
||||
case BTC_BLUFI_ACT_SEND_CUSTOM_DATA:
|
||||
btc_blufi_send_custom_data(arg->custom_data.data, arg->custom_data.data_len);
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s UNKNOWN %d\n", __func__, msg->act);
|
||||
break;
|
||||
|
@ -249,6 +249,14 @@ void btc_blufi_protocol_handler(uint8_t type, uint8_t *data, int len)
|
||||
param.client_pkey.pkey = &data[0];
|
||||
param.client_pkey.pkey_len = len;
|
||||
|
||||
btc_transfer_context(&msg, ¶m, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
|
||||
break;
|
||||
case BLUFI_TYPE_DATA_SUBTYPE_CUSTOM_DATA:
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_BLUFI;
|
||||
msg.act = ESP_BLUFI_EVENT_RECV_CUSTOM_DATA;
|
||||
param.custom_data.data = &data[0];
|
||||
param.custom_data.data_len = len;
|
||||
btc_transfer_context(&msg, ¶m, sizeof(esp_blufi_cb_param_t), btc_blufi_cb_deep_copy);
|
||||
break;
|
||||
default:
|
||||
|
@ -16,7 +16,7 @@
|
||||
#define __BLUFI_INT_H__
|
||||
|
||||
#define BTC_BLUFI_GREAT_VER 0x01 //Version + Subversion
|
||||
#define BTC_BLUFI_SUB_VER 0x01 //Version + Subversion
|
||||
#define BTC_BLUFI_SUB_VER 0x02 //Version + Subversion
|
||||
#define BTC_BLUFI_VERSION ((BTC_BLUFI_GREAT_VER<<8)|BTC_BLUFI_SUB_VER) //Version + Subversion
|
||||
|
||||
/* service engine control block */
|
||||
@ -115,6 +115,7 @@ typedef struct blufi_frag_hdr blufi_frag_hdr_t;
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_REPLY_VERSION 0x10
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_WIFI_LIST 0x11
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_ERROR_INFO 0x12
|
||||
#define BLUFI_TYPE_DATA_SUBTYPE_CUSTOM_DATA 0x13
|
||||
#define BLUFI_TYPE_IS_CTRL(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_CTRL)
|
||||
#define BLUFI_TYPE_IS_DATA(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_DATA)
|
||||
|
||||
|
@ -25,6 +25,7 @@ typedef enum {
|
||||
BTC_BLUFI_ACT_SEND_CFG_REPORT,
|
||||
BTC_BLUFI_ACT_SEND_WIFI_LIST,
|
||||
BTC_BLUFI_ACT_SEND_ERR_INFO,
|
||||
BTC_BLUFI_ACT_SEND_CUSTOM_DATA,
|
||||
} btc_blufi_act_t;
|
||||
|
||||
typedef union {
|
||||
@ -48,6 +49,13 @@ typedef union {
|
||||
struct blufi_error_infor {
|
||||
esp_blufi_error_state_t state;
|
||||
} blufi_err_infor;
|
||||
/*
|
||||
BTC_BLUFI_ACT_SEND_CUSTOM_DATA
|
||||
*/
|
||||
struct blufi_custom_data {
|
||||
uint8_t *data;
|
||||
uint32_t data_len;
|
||||
} custom_data;
|
||||
} btc_blufi_args_t;
|
||||
|
||||
void btc_blufi_cb_handler(btc_msg_t *msg);
|
||||
|
@ -323,6 +323,10 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para
|
||||
ESP_ERROR_CHECK(esp_wifi_scan_start(&scanConf, true));
|
||||
break;
|
||||
}
|
||||
case ESP_BLUFI_EVENT_RECV_CUSTOM_DATA:
|
||||
BLUFI_INFO("Recv Custom Data %d\n", param->custom_data.data_len);
|
||||
esp_log_buffer_hex("Custom Data", param->custom_data.data, param->custom_data.data_len);
|
||||
break;
|
||||
case ESP_BLUFI_EVENT_RECV_USERNAME:
|
||||
/* Not handle currently */
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user