1 /*
2  * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __BTC_BLUFI_PRF_H__
8 #define __BTC_BLUFI_PRF_H__
9 
10 #include "blufi_int.h"
11 #include "btc/btc_task.h"
12 #include "esp_blufi_api.h"
13 #include "esp_err.h"
14 
15 #ifdef CONFIG_BT_BLUEDROID_ENABLED
16 #include "stack/gatt_api.h"
17 #define ESP_BLUFI_ERROR GATT_ERROR
18 #define ESP_BLUFI_SUCCESS GATT_SUCCESS
19 #else
20 #define ESP_BLUFI_ERROR 0x85
21 #define ESP_BLUFI_SUCCESS 0x00
22 #endif
23 
24 #define BT_BD_ADDR_STR         "%02x:%02x:%02x:%02x:%02x:%02x"
25 #define BT_BD_ADDR_HEX(addr)   addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
26 
27 #define GATT_UUID_CHAR_CLIENT_CONFIG    0x2902      /*  Client Characteristic Configuration */
28 //define the blufi serivce uuid
29 #define BLUFI_SERVICE_UUID  0xFFFF
30 //define the blufi Char uuid (PHONE to ESP32)
31 #define BLUFI_CHAR_P2E_UUID 0xFF01
32 //define the blufi Char uuid (ESP32 to PHONE)
33 #define BLUFI_CHAR_E2P_UUID 0xFF02
34 //define the blufi Descriptor uuid (ESP32 to PHONE)
35 #define BLUFI_DESCR_E2P_UUID GATT_UUID_CHAR_CLIENT_CONFIG
36 //define the blufi APP ID
37 #define BLUFI_APP_UUID      0xFFFF
38 
39 #define BLUFI_HDL_NUM   6
40 
41 struct pkt_info{
42    uint8_t *pkt;
43    int pkt_len;
44 };
45 
46 static  const  tBT_UUID blufi_srvc_uuid = {LEN_UUID_16, {BLUFI_SERVICE_UUID}};
47 static  const  tBT_UUID blufi_char_uuid_p2e = {LEN_UUID_16, {BLUFI_CHAR_P2E_UUID}};
48 static  const  tBT_UUID blufi_char_uuid_e2p = {LEN_UUID_16, {BLUFI_CHAR_E2P_UUID}};
49 static  const  tBT_UUID blufi_descr_uuid_e2p = {LEN_UUID_16, {BLUFI_DESCR_E2P_UUID}};
50 static  const  tBT_UUID blufi_app_uuid = {LEN_UUID_16, {BLUFI_APP_UUID}};
51 
52 typedef enum {
53     BTC_BLUFI_ACT_INIT = 0,
54     BTC_BLUFI_ACT_DEINIT,
55     BTC_BLUFI_ACT_SEND_CFG_REPORT,
56     BTC_BLUFI_ACT_SEND_WIFI_LIST,
57     BTC_BLUFI_ACT_SEND_ERR_INFO,
58     BTC_BLUFI_ACT_SEND_CUSTOM_DATA,
59 } btc_blufi_act_t;
60 
61 typedef union {
62     struct blufi_cfg_report {
63         wifi_mode_t opmode;
64         esp_blufi_sta_conn_state_t sta_conn_state;
65         uint8_t softap_conn_num;
66         esp_blufi_extra_info_t *extra_info;
67         int extra_info_len;
68     } wifi_conn_report;
69     /*
70         BTC_BLUFI_ACT_SEND_WIFI_LIST
71     */
72     struct blufi_wifi_list {
73         uint16_t apCount;
74         esp_blufi_ap_record_t *list;
75     } wifi_list;
76     /*
77         BTC_BLUFI_ACT_SEND_ERR_INFO
78     */
79     struct blufi_error_infor {
80         esp_blufi_error_state_t state;
81     } blufi_err_infor;
82     /*
83         BTC_BLUFI_ACT_SEND_CUSTOM_DATA
84     */
85     struct blufi_custom_data {
86          uint8_t *data;
87          uint32_t data_len;
88     } custom_data;
89 } btc_blufi_args_t;
90 
91 void btc_blufi_cb_to_app(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param);
92 void btc_blufi_cb_handler(btc_msg_t *msg);
93 void btc_blufi_call_handler(btc_msg_t *msg);
94 void btc_blufi_set_callbacks(esp_blufi_callbacks_t *callbacks);
95 
96 void btc_blufi_recv_handler(uint8_t *data, int len);
97 void btc_blufi_send_notify(uint8_t *pkt, int pkt_len);
98 void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
99 void btc_blufi_call_deep_free(btc_msg_t *msg);
100 
101 uint16_t btc_blufi_get_version(void);
102 
103 #endif /* __BTC_BLUFI_PRF_H__ */
104