--- /dev/null
+// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+
+#include "esp_blufi_api.h"
+#include "esp_bt_defs.h"
+#include "esp_bt_main.h"
+#include "btc_task.h"
+#include "btc_blufi_prf.h"
+#include "btc_manage.h"
+#include "btc_main.h"
+#include "future.h"
+
+esp_err_t esp_blufi_register_callback(esp_profile_cb_t callback)
+{
+ return (btc_profile_cb_set(BTC_PID_BLUFI, callback) == 0 ? ESP_OK : ESP_FAIL);
+}
+
+esp_err_t esp_blufi_send_config_state(esp_blufi_config_state_t state)
+{
+ btc_msg_t msg;
+ btc_blufi_args_t arg;
+
+ msg.sig = BTC_SIG_API_CALL;
+ msg.pid = BTC_PID_BLUFI;
+ msg.act = BTC_BLUFI_ACT_SEND_CFG_STATE;
+ arg.cfg_state.state = 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_profile_init(void)
+{
+ btc_msg_t msg;
+
+ msg.sig = BTC_SIG_API_CALL;
+ msg.pid = BTC_PID_BLUFI;
+ msg.act = BTC_BLUFI_ACT_INIT;
+
+ return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+}
+
+esp_err_t esp_blufi_profile_deinit(void)
+{
+ btc_msg_t msg;
+
+ msg.sig = BTC_SIG_API_CALL;
+ msg.pid = BTC_PID_BLUFI;
+ msg.act = BTC_BLUFI_ACT_DEINIT;
+
+ return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
+}
+
+
--- /dev/null
+#ifndef __ESP_BLUFI_API_H__
+#define __ESP_BLUFI_API_H__
+
+#include "bt_types.h"
+#include "esp_bt_defs.h"
+#include "esp_gatt_defs.h"
+#include "bta_gatt_api.h"
+#include "esp_err.h"
+
+#define ESP_BLUFI_RECV_DATA_LEN_MAX 128
+
+#define ESP_BLUFI_EVENT_INIT_FINISH 0
+#define ESP_BLUFI_EVENT_DEINIT_FINISH 1
+#define ESP_BLUFI_EVENT_RECV_DATA 2
+
+typedef enum {
+ ESP_BLUFI_CONFIG_OK = 0,
+ ESP_BLUFI_CONFIG_FAILED,
+} esp_blufi_config_state_t;
+
+typedef enum {
+ ESP_BLUFI_INIT_OK = 0,
+ ESP_BLUFI_INIT_FAILED = 0,
+} esp_blufi_init_state_t;
+
+typedef enum {
+ ESP_BLUFI_DEINIT_OK = 0,
+ ESP_BLUFI_DEINIT_FAILED = 0,
+} esp_blufi_deinit_state_t;
+
+typedef union {
+ //ESP_BLUFI_EVENT_INIT_FINISH
+ struct blufi_init_finish_evt_param {
+ esp_blufi_init_state_t state;
+ } init_finish;
+ //ESP_BLUFI_EVENT_DEINIT_FINISH
+ struct blufi_deinit_finish_evt_param {
+ esp_blufi_deinit_state_t state;
+ } deinit_finish;
+ //ESP_BLUFI_EVENT_RECV_DATA
+ struct blufi_recv_evt_param {
+ uint8_t data[ESP_BLUFI_RECV_DATA_LEN_MAX];
+ uint8_t data_len;
+ } recv_data;
+} esp_blufi_cb_param_t;
+
+/*******************************************************************************
+**
+** @function esp_blufi_register_callback
+**
+** @brief This function is called to receive blufi callback event
+**
+** @param[in] callback: callback function
+**
+** @return ESP_OK - success, other - failed
+**
+*******************************************************************************/
+esp_err_t esp_blufi_register_callback(esp_profile_cb_t callback);
+
+/*******************************************************************************
+**
+** @function esp_blufi_send_config_state
+**
+** @brief This function is called to send config state to phone
+**
+** @param[in] state: blufi config ok or not
+**
+** @return ESP_OK - success, other - failed
+**
+*******************************************************************************/
+esp_err_t esp_blufi_send_config_state(esp_blufi_config_state_t state);
+
+/*******************************************************************************
+**
+** @function esp_blufi_profile_init
+**
+** @brief This function is called to init blufi_profile
+**
+** @return ESP_OK - success, other - failed
+**
+*******************************************************************************/
+esp_err_t esp_blufi_profile_init(void);
+
+/*******************************************************************************
+**
+** @function esp_blufi_profile_deinit
+**
+** @brief This function is called to init blufi_profile
+**
+** @return ESP_OK - success, other - failed
+**
+*******************************************************************************/
+esp_err_t esp_blufi_profile_deinit(void);
+
+
+
+#endif /* _ESP_BLUFI_API_ */
// btla-specific --
if (first_unuse != 0xff)
{
- APPL_TRACE_ERROR("register application first_unuse rcb_idx = %d", first_unuse);
+ APPL_TRACE_VERBOSE("register application first_unuse rcb_idx = %d", first_unuse);
p_cb->rcb[first_unuse].in_use = TRUE;
p_cb->rcb[first_unuse].p_cback = p_msg->api_reg.p_cback;
rcb_idx = bta_gatts_find_app_rcb_idx_by_app_if(p_cb, p_msg->api_create_svc.server_if);
- APPL_TRACE_ERROR("create service rcb_idx = %d", rcb_idx);
+ APPL_TRACE_DEBUG("create service rcb_idx = %d", rcb_idx);
if (rcb_idx != BTA_GATTS_INVALID_APP)
{
break;
case BTA_GATTS_API_REG_EVT:
- LOG_ERROR("bta_gatts_register\n");
bta_gatts_register(p_cb, (tBTA_GATTS_DATA *) p_msg);
break;
void btc_main_call_handler(btc_msg_t *msg)
{
- LOG_ERROR("%s act %d\n", __func__, msg->act);
+ LOG_DEBUG("%s act %d\n", __func__, msg->act);
switch (msg->act) {
case BTC_MAIN_ACT_INIT:
#include "btc_gatts.h"
#include "btc_gattc.h"
#include "btc_gap_ble.h"
+#include "btc_blufi_prf.h"
static xTaskHandle xBtcTaskHandle = NULL;
static xQueueHandle xBtcQueue = 0;
[BTC_PID_BT_HID] = {NULL, NULL},
[BTC_PID_SPP] = {NULL, NULL},
[BTC_PID_SPPLIKE] = {NULL, NULL},
- [BTC_PID_BLUFI] = {NULL, NULL},
+ [BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler },
};
/*****************************************************************************
#include "bta_gatt_api.h"
#include "bta_gatts_int.h"
-#include "blufi_prf.h"
+#include "btc_blufi_prf.h"
+#include "btc_task.h"
+#include "btc_manage.h"
+
#include "blufi_adv.h"
+#include "blufi_int.h"
+
+static uint8_t *success_msg = "BLUFI_CONFIG_OK";
+static uint8_t *failed_msg = "BLUFI_CONFIG_FAILED";
+
+#define BTC_BLUFI_CB_TO_APP(_event, _param) ((esp_profile_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]
-void blufi_config_success(void);
-void blufi_config_failed(void);
UINT16 esp32_uuid = SVC_BLUFI_UUID;
UINT8 esp32_manu[17] = {0xff,0x20,0x14,0x07,0x22,0x00,0x02,0x5B,0x00,0x33,0x49,0x31,0x30,0x4a,0x30,0x30,0x31};
static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data);
+/*******************************************************************************
+**
+** Function blufi_create_service
+**
+** Description Create a Service for the blufi profile
+**
+** Returns NULL
+**
+*******************************************************************************/
+static void blufi_create_service(void)
+{
+ tBTA_GATTS_IF server_if ;
+ tBT_UUID uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
+ UINT16 num_handle = BLUFI_HDL_NUM;
+ UINT8 inst = 0x00;
+ server_if = blufi_cb_env.gatt_if;
+ blufi_cb_env.inst_id = inst;
+ if(!blufi_cb_env.enabled)
+ {
+ LOG_ERROR("blufi service added error.");
+ return;
+ }
+ BTA_GATTS_CreateService(server_if, &uuid, inst, num_handle, true);
+
+}
+
+
/*******************************************************************************
**
** Function blufi_profile_cb
{
tBTA_GATTS_RSP rsp;
tBT_UUID uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
- tBLUFI_INST *p_inst = &blufi_cb_env.blufi_inst;
- UINT8 net_event = 0xff;
UINT8 len = 0;
UINT8 *p_rec_data = NULL;
tBTA_GATT_STATUS status;
LOG_DEBUG("\n");
if (p_data->req_data.p_data->write_req.handle == blufi_cb_env.blufi_inst.blufi_hdl) {
+ btc_msg_t msg;
+ struct blufi_recv_evt_param recv_data;
+
+ memset(&recv_data, 0x00, sizeof(struct blufi_recv_evt_param));
p_rec_data = &p_data->req_data.p_data->write_req.value[0];
- if (p_inst && p_inst->blufi_cback)
- p_inst->blufi_cback(blufi_cb_env.blufi_inst.app_id, net_event, len, p_rec_data);
+ recv_data.data_len = p_data->req_data.p_data->write_req.len;
+ memcpy(recv_data.data, p_rec_data, recv_data.data_len);
+
+ msg.sig = BTC_SIG_API_CB;
+ msg.pid = BTC_PID_BLUFI;
+ msg.act = BTC_BLUFI_CB_ACT_RECV_DATA;
+
+ btc_transfer_context(&msg, &recv_data, sizeof(struct blufi_recv_evt_param), NULL);
}
break;
case BTA_GATTS_CONF_EVT:
break;
case BTA_GATTS_CREATE_EVT:
uuid.uu.uuid16 = CHAR_BLUFI_UUID;
- blufi_cb_env.clcb.cur_srvc_id = p_data->create.service_id;
+ blufi_cb_env.cur_srvc_id = p_data->create.service_id;
blufi_cb_env.is_primery = p_data->create.is_primary;
//start the blufi service after created
BTA_GATTS_StartService(p_data->create.service_id, BTA_GATT_TRANSPORT_LE);
//add the frist blufi characteristic --> write characteristic
- BTA_GATTS_AddCharacteristic(blufi_cb_env.clcb.cur_srvc_id, &uuid,
+ BTA_GATTS_AddCharacteristic(blufi_cb_env.cur_srvc_id, &uuid,
(GATT_PERM_WRITE | GATT_PERM_READ),
(GATT_CHAR_PROP_BIT_READ | GATT_CHAR_PROP_BIT_WRITE | GATT_CHAR_PROP_BIT_NOTIFY));
break;
blufi_cb_env.blufi_inst.blufi_hdl = p_data->add_result.attr_id;
uuid.uu.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG;
- BTA_GATTS_AddCharDescriptor (blufi_cb_env.clcb.cur_srvc_id,
+ BTA_GATTS_AddCharDescriptor (blufi_cb_env.cur_srvc_id,
(GATT_PERM_WRITE|GATT_PERM_WRITE),
&uuid);
}
break;
- case BTA_GATTS_ADD_CHAR_DESCR_EVT:
- /* Nothing */
+ case BTA_GATTS_ADD_CHAR_DESCR_EVT: {
+ /* call init finish */
+ btc_msg_t msg;
+
+ msg.sig = BTC_SIG_API_CB;
+ msg.pid = BTC_PID_BLUFI;
+ msg.act = BTC_BLUFI_CB_ACT_INIT_FINISH;
+ btc_transfer_context(&msg, NULL, 0, NULL);
break;
+ }
case BTA_GATTS_CONNECT_EVT:
//set the connection flag to true
- blufi_env_clcb_alloc(p_data->conn.conn_id, p_data->conn.remote_bda);
- LOG_DEBUG("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n",
+ LOG_ERROR("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n",
BT_BD_ADDR_HEX(p_data->conn.remote_bda), p_data->conn.server_if,
p_data->conn.reason, p_data->conn.conn_id);
+
+ blufi_cb_env.conn_id = p_data->conn.conn_id;
+
/*return whether the remote device is currently connected*/
int is_connected = BTA_DmGetConnectionState(p_data->conn.remote_bda);
LOG_DEBUG("is_connected=%d\n",is_connected);
break;
case BTA_GATTS_DISCONNECT_EVT:
//set the connection flag to true
- blufi_cb_env.clcb.connected = false;
+ blufi_cb_env.connected = false;
break;
case BTA_GATTS_OPEN_EVT:
break;
case BTA_GATTS_CLOSE_EVT:
- if(blufi_cb_env.clcb.connected && (blufi_cb_env.clcb.conn_id == p_data->conn.conn_id))
+ if(blufi_cb_env.connected && (blufi_cb_env.conn_id == p_data->conn.conn_id))
{
//set the connection channal congested flag to true
- blufi_cb_env.clcb.congest = p_data->congest.congested;
+ blufi_cb_env.congest = p_data->congest.congested;
}
break;
case BTA_GATTS_LISTEN_EVT:
}
}
-
-/*******************************************************************************
-**
-** Function blufi_create_service
-**
-** Description Create a Service for the blufi profile
-**
-** Returns NULL
-**
-*******************************************************************************/
-void blufi_create_service(void)
-{
- tBTA_GATTS_IF server_if ;
- tBT_UUID uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
- UINT16 num_handle = BLUFI_HDL_NUM;
- UINT8 inst = 0x00;
- server_if = blufi_cb_env.gatt_if;
- blufi_cb_env.inst_id = inst;
- if(!blufi_cb_env.enabled)
- {
- LOG_ERROR("blufi service added error.");
- return;
- }
- BTA_GATTS_CreateService(server_if, &uuid, inst, num_handle, true);
-
-}
-
-/*******************************************************************************
-**
-** Function blufi_env_clcb_alloc
-**
-** Description The function allocates a GATT profile connection link control block
-**
-** Returns NULL if not found. Otherwise pointer to the connection link block.
-**
-*******************************************************************************/
-tBLUFI_CLCB *blufi_env_clcb_alloc (UINT16 conn_id, BD_ADDR remote_bda)
-{
- tBLUFI_CLCB *p_clcb = NULL;
- p_clcb = &blufi_cb_env.clcb;
-
- if(!p_clcb->in_use)
- {
- p_clcb->in_use = TRUE;
- p_clcb->conn_id = conn_id;
- p_clcb->connected = TRUE;
- memcpy(p_clcb->remote_bda, remote_bda, BD_ADDR_LEN);
- LOG_ERROR("p_clcb->conn_id = %x\n", conn_id);
- }
-
- return p_clcb;
-}
-
-/*******************************************************************************
-**
-** Function blufi_env_find_conn_id_by_bd_adddr
-**
-** Description The function searches all LCB with macthing bd address
-**
-** Returns total number of clcb found.
-**
-*******************************************************************************/
-/*
-UINT16 blufi_env_find_conn_id_by_bd_adddr(BD_ADDR remote_bda)
-{
- UINT8 i_clcb;
- tBLUFI_CLCB *p_clcb = NULL;
-
- for(i_clcb = 0, p_clcb = &blufi_cb_env.clcb; i_clcb < BLUFIT_MAX_APPS; i_clcb++, p_clcb++)
- {
- if(p_clcb->in_use && p_clcb->connected && memcmp(p_clcb->remote_bda, remote_bda, BD_ADDR_LEN) == 0)
- {
- return p_clcb->conn_id;
- }
- }
-
- return GATT_INVALID_CONN_ID;
-}
-*/
-/*******************************************************************************
-**
-** Function blufi_env_clcb_dealloc
-**
-** Description The function deallocates a GATT profile connection link control block
-**
-** Returns True the deallocation is successful
-**
-*******************************************************************************/
-BOOLEAN blufi_env_clcb_dealloc(UINT16 conn_id)
-{
-// UINT8 i_clcb = 0;
-// tBLUFI_CLCB *p_clcb = NULL;
-
- return FALSE;
-}
-
-
-/*******************************************************************************
-**
-** Function blufi_init
-**
-** Description Initializa the GATT Service for blufi profiles.
-**
-*******************************************************************************/
-tGATT_STATUS blufi_profile_init (tBLUFI_CBACK *call_back)
+static tGATT_STATUS btc_blufi_profile_init(void)
{
tBT_UUID app_uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
memset(&blufi_cb_env,0,sizeof(tBLUFI_CB_ENV));
}
-
- if(call_back != NULL)
- {
- blufi_cb_env.blufi_inst.blufi_cback = call_back;
- }
-
/* register the blufi profile to the BTA_GATTS module*/
BTA_GATTS_AppRegister(&app_uuid, blufi_profile_cb);
return GATT_SUCCESS;
}
-void blufi_msg_notify(UINT8 *blufi_msg, UINT8 len)
+static void blufi_msg_notify(UINT8 *blufi_msg, UINT8 len)
{
- BOOLEAN conn_status = blufi_cb_env.clcb.connected;
- UINT16 conn_id = blufi_cb_env.clcb.conn_id;
+ BOOLEAN conn_status = blufi_cb_env.connected;
+ UINT16 conn_id = blufi_cb_env.conn_id;
UINT16 attr_id = blufi_cb_env.blufi_inst.blufi_hdl;
//notify rsp==false; indicate rsp==true.
BOOLEAN rsp = false;
- if(!conn_status && blufi_cb_env.clcb.congest)
+ if(!conn_status && blufi_cb_env.congest)
{
LOG_ERROR("the conneciton for blufi profile has been loss");
return;
blufi_msg, rsp);
}
-void blufi_config_success(void)
+static void btc_blufi_config_success(void)
{
- uint8_t *success_msg = "BLUFI_CONFIG_OK";
+ LOG_DEBUG("config success\n");
blufi_msg_notify(success_msg, strlen(success_msg));
}
-void blufi_config_failed(void)
+static void btc_blufi_config_failed(void)
{
- uint8_t *failed_msg = "BLUFI_CONFIG_FAILED";
+ LOG_DEBUG("config faield\n");
blufi_msg_notify(failed_msg, strlen(failed_msg));
}
+
+void btc_blufi_cb_handler(btc_msg_t *msg)
+{
+ esp_blufi_cb_param_t param;
+
+ switch (msg->act) {
+ case BTC_BLUFI_CB_ACT_INIT_FINISH:
+ param.init_finish.state = ESP_BLUFI_INIT_OK;
+ BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_INIT_FINISH, ¶m);
+ break;
+ case BTC_BLUFI_CB_ACT_DEINIT_FINISH:
+ /* TODO: but now nothing */
+ break;
+ case BTC_BLUFI_CB_ACT_RECV_DATA:
+ memcpy(¶m.recv_data, msg->arg, sizeof(struct blufi_recv_evt_param));
+
+ BTC_BLUFI_CB_TO_APP(ESP_BLUFI_EVENT_RECV_DATA, ¶m);
+ break;
+ default:
+ LOG_ERROR("%s UNKNOWN %d\n", msg->act);
+ break;
+ }
+}
+
+void btc_blufi_call_handler(btc_msg_t *msg)
+{
+ btc_blufi_args_t *arg = (btc_blufi_args_t *)msg->arg;
+
+ switch (msg->act) {
+ case BTC_BLUFI_ACT_INIT:
+ btc_blufi_profile_init();
+ break;
+ case BTC_BLUFI_ACT_DEINIT:
+ /* TODO: but now nothing */
+ break;
+ case BTC_BLUFI_ACT_SEND_CFG_STATE:
+ if (arg->cfg_state.state == ESP_BLUFI_CONFIG_OK) {
+ btc_blufi_config_success();
+ } else {
+ btc_blufi_config_failed();
+ }
+ break;
+ default:
+ LOG_ERROR("%s UNKNOWN %d\n", msg->act);
+ break;
+ }
+}
--- /dev/null
+#ifndef __BLUFI_INT_H__
+#define __BLUFI_INT_H__
+
+//define the blufi serivce uuid
+#define SVC_BLUFI_UUID 0xFFFF
+//define the blufi Char uuid
+#define CHAR_BLUFI_UUID 0xFF01
+
+#define BLUFI_HDL_NUM 4
+
+#define BLUFI_VAL_MAX_LEN (128)
+
+#define BLUFI_MAX_STRING_DATA 128
+
+
+typedef struct
+{
+ UINT8 app_id;
+ UINT16 blufi_hdl;
+}tBLUFI_INST;
+
+
+/* service engine control block */
+typedef struct
+{
+ BOOLEAN enabled;
+ BOOLEAN is_primery;
+ UINT8 inst_id;
+ tGATT_IF gatt_if;
+ tBLUFI_INST blufi_inst;
+ BOOLEAN in_use;
+ BOOLEAN congest;
+ UINT16 conn_id;
+ BOOLEAN connected;
+ BD_ADDR remote_bda;
+ UINT32 trans_id;
+ UINT8 cur_srvc_id;
+} tBLUFI_CB_ENV;
+
+#endif /* __BLUFI_INT_H__ */
+++ /dev/null
-#include "bt_target.h"
-#include "gatt_api.h"
-#include "gattdefs.h"
-
-//define the blufi serivce uuid
-#define SVC_BLUFI_UUID 0xFFFF
-//define the blufi Char uuid
-#define CHAR_BLUFI_UUID 0xFF01
-
-#define BLUFI_HDL_NUM 4
-
-#define BLUFI_VAL_MAX_LEN (20)
-
-#define BLUFI_MAX_STRING_DATA 33
-
-typedef void (tBLUFI_CBACK)(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *data);
-
-typedef enum
-{
- RECV_ACT_PASSWD = 0,
- RECV_ACT_SSID,
- RECV_ACT_MAX
-} RECV_ACTION;
-
-typedef struct
-{
- BD_ADDR remote_bda;
- BOOLEAN need_rsp;
- UINT16 clt_cfg;
-} tBLUFI_WRITE_DATA;
-
-typedef struct
-{
- BOOLEAN in_use;
- BOOLEAN congest;
- UINT16 conn_id;
- BOOLEAN connected;
- BD_ADDR remote_bda;
- UINT32 trans_id;
- UINT8 cur_srvc_id;
-
-} tBLUFI_CLCB;
-
-
-typedef struct
-{
- UINT8 app_id;
- UINT16 blufi_hdl;
- tBLUFI_CBACK* blufi_cback;
-
-}tBLUFI_INST;
-
-
-/* service engine control block */
-typedef struct
-{
- BOOLEAN enabled;
- BOOLEAN is_primery;
- UINT8 inst_id;
- tGATT_IF gatt_if;
- tBLUFI_CLCB clcb; /* connection link*/
- tBLUFI_INST blufi_inst;
-} tBLUFI_CB_ENV;
-
-void blufi_create_service(void);
-
-tBLUFI_CLCB *blufi_env_clcb_alloc(UINT16 conn_id, BD_ADDR bda);
-
-UINT16 blufi_env_find_conn_id_by_bd_adddr(BD_ADDR bda);
-
-BOOLEAN blufi_env_clcb_dealloc(UINT16 conn_id);
-
-tGATT_STATUS blufi_profile_init(tBLUFI_CBACK *call_back);
-
-void blufi_msg_notify(UINT8 *blufi_msg, UINT8 len);
-
--- /dev/null
+#ifndef __BTC_BLUFI_PRF_H__
+#define __BTC_BLUFI_PRF_H__
+
+#include "bt_target.h"
+#include "btc_task.h"
+#include "esp_blufi_api.h"
+
+typedef enum {
+ BTC_BLUFI_ACT_INIT = 0,
+ BTC_BLUFI_ACT_DEINIT,
+ BTC_BLUFI_ACT_SEND_CFG_STATE,
+} btc_blufi_act_t;
+
+typedef enum {
+ BTC_BLUFI_CB_ACT_INIT_FINISH = 0,
+ BTC_BLUFI_CB_ACT_DEINIT_FINISH,
+ BTC_BLUFI_CB_ACT_RECV_DATA,
+} btc_blufi_cb_act_t;
+
+typedef union {
+#if 0
+ //BTC_BLUFI_ACT_INIT = 0,
+ struct blufi_init_param {
+ } init;
+ //BTC_BLUFI_ACT_DEINIT,
+ struct blufi_deinit_param {
+ } deinit;
+#endif
+ //BTC_BLUFI_ACT_SEND_CFG_STATE,
+ struct blufi_send_cfg_state_pram {
+ esp_blufi_config_state_t state;
+ } cfg_state;
+} btc_blufi_args_t;
+
+void btc_blufi_cb_handler(btc_msg_t *msg);
+void btc_blufi_call_handler(btc_msg_t *msg);
+
+#endif /* __BTC_BLUFI_PRF_H__ */
cp_len = len - MIN_ADV_LENGTH;
else
cp_len = p_data->p_manu->len;
- LOG_ERROR("cp_len = %d\n,p_data->p_manu->len=%d\n",cp_len,p_data->p_manu->len);
+ LOG_DEBUG("cp_len = %d\n,p_data->p_manu->len=%d\n",cp_len,p_data->p_manu->len);
for(int i = 0; i < p_data->p_manu->len; i++)
{
LOG_DEBUG("p_data->p_manu->p_val[%d] = %x\n",i,p_data->p_manu->p_val[i]);
*p++ = cp_len + 1;
*p++ = BTM_BLE_AD_TYPE_MANU;
ARRAY_TO_STREAM(p, p_data->p_manu->p_val, cp_len);
- LOG_ERROR("p_addr = %p\n,p_data->p_manu->p_val = %p\n",p,p_data->p_manu->p_val);
+ LOG_DEBUG("p_addr = %p\n,p_data->p_manu->p_val = %p\n",p,p_data->p_manu->p_val);
len -= (cp_len + MIN_ADV_LENGTH);
data_mask &= ~BTM_BLE_AD_BIT_MANU;
}
#include <stdbool.h>
#include <stdio.h>
-#include "bta_api.h"
-#include "bta_gatt_api.h"
#include "controller.h"
-#include "gatt_int.h"
#include "bt_trace.h"
-#include "btm_api.h"
#include "bt_types.h"
-#include "blufi_prf.h"
-
#include "blufi.h"
-#include "blufi_adv.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
+#include "esp_blufi_api.h"
-static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data);
-
-struct dm_evt {
- tBTA_DM_SEC_EVT event;
- tBTA_DM_SEC* p_data;
-};
+extern void wifi_set_blue_config(char *ssid, char *passwd);
#define HEADER_SSID "ssid"
#define HEADER_PASSWD "passwd"
#define HEADER_CONFIRM "confirm"
-extern void wifi_set_blue_config(char *ssid, char *passwd);
-static char tmp_ssid[33];
-static char tmp_passwd[33];
-static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data)
+static char tmp_ssid[32 + 1];
+static char tmp_passwd[64 + 1];
+
+static void blufi_data_recv(uint8_t *data, int len)
{
char *p = NULL;
- LOG_DEBUG("the data is:%s\n", p_data);
-#if 0
- switch(event)
- {
- case RECEIVE_NET_PASSWD_EVT:
- LOG_ERROR("Received the network passwork");
- break;
- case RECEIVE_NET_SSD_EVT:
- LOG_ERROR("Received the network SSID");
- break;
- default:
- break;
- }
-#endif
- p = strstr(p_data, HEADER_SSID);
+ LOG_DEBUG("the data is:%s\n", data);
+
+ p = strstr(data, HEADER_SSID);
if (p) {
LOG_ERROR("SSID: %s\n", p+strlen(HEADER_SSID)+1);
strcpy(tmp_ssid, p+strlen(HEADER_SSID)+1);
}
- p = strstr(p_data, HEADER_PASSWD);
+ p = strstr(data, HEADER_PASSWD);
if (p) {
LOG_ERROR("PASSWORD: %s\n", p+strlen(HEADER_PASSWD)+1);
strcpy(tmp_passwd, p+strlen(HEADER_PASSWD)+1);
}
- p = strstr(p_data, HEADER_CONFIRM);
+ p = strstr(data, HEADER_CONFIRM);
if (p) {
LOG_ERROR("CONFIRM\n");
wifi_set_blue_config(tmp_ssid, tmp_passwd);
}
-static esp_err_t blufi_dm_upstreams_evt(void *arg)
+static void blufi_callback(uint32_t event, void *param)
+{
+ /* actually, should post to blufi_task handle the procedure,
+ * now, as a demo, we do simplely */
+ switch (event) {
+ case ESP_BLUFI_EVENT_INIT_FINISH:
+ LOG_ERROR("blufi init finish\n");
+ break;
+ case ESP_BLUFI_EVENT_RECV_DATA: {
+ LOG_DEBUG("blufi recv data\n");
+ esp_blufi_cb_param_t *blufi_param = (esp_blufi_cb_param_t *)param;
+ blufi_data_recv(blufi_param->recv_data.data, blufi_param->recv_data.data_len);
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+static esp_err_t blufi_startup_in_blufi_task(void *arg)
{
/*set connectable,discoverable, pairable and paired only modes of local device*/
tBTA_DM_DISC disc_mode = BTA_DM_BLE_GENERAL_DISCOVERABLE;
tBTA_DM_CONN conn_mode = BTA_DM_BLE_CONNECTABLE;
- BTA_DmSetVisibility(disc_mode, conn_mode, (uint8_t)BTA_DM_NON_PAIRABLE, (uint8_t)BTA_DM_CONN_ALL );
-
-#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
- /* Enable local privacy */
- //BTA_DmBleConfigLocalPrivacy(BLE_LOCAL_PRIVACY_ENABLED);
- do {
- const controller_t *controller = controller_get_interface();
- char bdstr[18];
- bdaddr_to_string(controller->get_address(), bdstr, sizeof(bdstr));
- LOG_DEBUG("BDA is: %s\n", bdstr);
- } while (0);
-#endif
- blufi_profile_init(BlufiDataCallBack);
+ BTA_DmSetVisibility(disc_mode, conn_mode, (uint8_t)BTA_DM_NON_PAIRABLE, (uint8_t)BTA_DM_CONN_ALL);
+
+ esp_blufi_register_callback(blufi_callback);
+ esp_blufi_profile_init();
return ESP_OK;
}
-void blufi_bte_dm_evt(void)
+static void blufi_startup(void)
{
- blufi_transfer_context(blufi_dm_upstreams_evt, NULL);
+ blufi_transfer_context(blufi_startup_in_blufi_task, NULL);
}
esp_err_t blufi_enable(void *arg)
LOG_ERROR("%s failed\n", __func__);
return err;
}
- blufi_bte_dm_evt();
+ blufi_startup();
vTaskDelay(1000 / portTICK_PERIOD_MS);
return err;
static void blufi_task_init(void)
{
- xBlufiTaskQueue = xQueueCreate(10, sizeof(BtTaskEvt_t));
- xTaskCreate(blufi_task, "BlUFI", 8192, NULL, configMAX_PRIORITIES - 3, xBlufiTaskHandle);
+ xBlufiTaskQueue = xQueueCreate(5, sizeof(BtTaskEvt_t));
+ xTaskCreate(blufi_task, "BlUFI", 4096, NULL, configMAX_PRIORITIES - 3, xBlufiTaskHandle);
}
void blufi_init(void) {
#include "bt.h"
#include "bta_api.h"
+#include "esp_blufi_api.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "blufi.h"
-static wifi_scan_config_t scan_config;
static wifi_config_t sta_config;
static char tmp_ssid[33];
LOG_DEBUG("confirm true\n");
}
-extern void blufi_config_failed(void);
-extern void blufi_config_success(void);
static esp_err_t event_handler(void *ctx, system_event_t *event)
{
switch(event->event_id) {
break;
case SYSTEM_EVENT_STA_GOT_IP:
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
- blufi_config_success();
+ esp_blufi_send_config_state(ESP_BLUFI_CONFIG_OK);
esp_disable_bluetooth(); //close bluetooth function
//esp_deinit_bluetooth(); //free bluetooth resource
break;
}
-static int loop = 0;
void wifiTestTask(void *pvParameters)
{
esp_err_t ret;
ret = esp_wifi_connect();
if (ret != ESP_OK) {
LOG_ERROR("esp_wifi connect failed\n");
- blufi_config_failed();
+ esp_blufi_send_config_state(ESP_BLUFI_CONFIG_FAILED);
}
}
}