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);
+}
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
*/
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;
/**
*
*/
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
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;
}
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;
}
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;
}
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;
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;
}
}
break;
}
+ case BTC_BLUFI_ACT_SEND_CUSTOM_DATA:{
+ uint8_t *data = arg->custom_data.data;
+ if(data) {
+ osi_free(data);
+ }
+ break;
+ }
default:
break;
}
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;
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:
#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 */
#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)
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 {
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);
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;