From: zhiweijian Date: Tue, 6 Mar 2018 08:18:38 +0000 (+0800) Subject: Component/bt: blufi add custom data cmd X-Git-Tag: v3.1-beta1~369^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1d8ea84c3a318831414862214f4b50e43e3e9da;p=esp-idf Component/bt: blufi add custom data cmd --- diff --git a/components/bt/bluedroid/api/esp_blufi_api.c b/components/bt/bluedroid/api/esp_blufi_api.c index 833228a4dc..4ecb6f0061 100644 --- a/components/bt/bluedroid/api/esp_blufi_api.c +++ b/components/bt/bluedroid/api/esp_blufi_api.c @@ -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); +} diff --git a/components/bt/bluedroid/api/include/esp_blufi_api.h b/components/bt/bluedroid/api/include/esp_blufi_api.h index a826ddfb41..6905187485 100644 --- a/components/bt/bluedroid/api/include/esp_blufi_api.h +++ b/components/bt/bluedroid/api/include/esp_blufi_api.h @@ -52,6 +52,7 @@ typedef enum { ESP_BLUFI_EVENT_RECV_SLAVE_DISCONNECT_BLE, /*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; diff --git a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_protocol.c b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_protocol.c index 23dcdfc01c..50e8d275ef 100644 --- a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_protocol.c +++ b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_protocol.c @@ -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: diff --git a/components/bt/bluedroid/btc/profile/esp/blufi/include/blufi_int.h b/components/bt/bluedroid/btc/profile/esp/blufi/include/blufi_int.h index 102142979d..eab51ad85c 100644 --- a/components/bt/bluedroid/btc/profile/esp/blufi/include/blufi_int.h +++ b/components/bt/bluedroid/btc/profile/esp/blufi/include/blufi_int.h @@ -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) diff --git a/components/bt/bluedroid/btc/profile/esp/include/btc_blufi_prf.h b/components/bt/bluedroid/btc/profile/esp/include/btc_blufi_prf.h index 9cb27da272..06154673a8 100644 --- a/components/bt/bluedroid/btc/profile/esp/include/btc_blufi_prf.h +++ b/components/bt/bluedroid/btc/profile/esp/include/btc_blufi_prf.h @@ -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); diff --git a/examples/bluetooth/blufi/main/blufi_example_main.c b/examples/bluetooth/blufi/main/blufi_example_main.c index afe6fb6bc7..c16aa38d6e 100644 --- a/examples/bluetooth/blufi/main/blufi_example_main.c +++ b/examples/bluetooth/blufi/main/blufi_example_main.c @@ -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;