1 /*
2  * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __ESP_BLUFI_H__
8 #define __ESP_BLUFI_H__
9 
10 #include "esp_blufi_api.h"
11 #include "esp_err.h"
12 
13 #ifdef CONFIG_BT_NIMBLE_ENABLED
14 #include "nimble/ble.h"
15 #include "host/ble_gap.h"
16 #include "modlog/modlog.h"
17 #endif
18 
19 #ifdef CONFIG_BT_BLUEDROID_ENABLED
20 #include "esp_gap_ble_api.h"
21 #endif
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define BLUFI_APP_UUID      0xFFFF
28 #define BLUFI_DEVICE_NAME            "BLUFI_DEVICE"
29 
30 #ifdef CONFIG_BT_NIMBLE_ENABLED
31 struct ble_hs_cfg;
32 struct ble_gatt_register_ctxt;
33 struct gatt_value {
34     struct os_mbuf *buf;
35     uint16_t val_handle;
36     uint8_t type;
37     void *ptr;
38 };
39 #define SERVER_MAX_VALUES       3
40 #define MAX_VAL_SIZE            512
41 extern struct gatt_value gatt_values[SERVER_MAX_VALUES];
42 /* GATT server callback */
43 void esp_blufi_gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
44 
45 /* Initialise gatt server */
46 int esp_blufi_gatt_svr_init(void);
47 int esp_blufi_gatt_svr_deinit(void);
48 void esp_blufi_btc_init(void);
49 void esp_blufi_btc_deinit(void);
50 #endif
51 
52 #ifdef CONFIG_BT_BLUEDROID_ENABLED
53 /**
54  * @brief           Close a connection  a remote device.
55  *
56  * @param[in]       gatts_if: GATT server access interface
57  * @param[in]       conn_id: connection ID to be closed.
58  *
59  * @return
60  *                  - ESP_OK : success
61  *                  - other  : failed
62  *
63  */
64 esp_err_t esp_blufi_close(uint8_t gatts_if, uint16_t conn_id);
65 void esp_blufi_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
66 #endif
67 
68 /* Initialise blufi profile */
69 uint8_t esp_blufi_init(void);
70 
71 /* start advertising */
72 void bleprph_advertise(void);
73 
74 /* send notifications */
75 void esp_blufi_send_notify(void *arg);
76 
77 /* Deinitialise blufi */
78 void esp_blufi_deinit(void);
79 /* disconnect */
80 void esp_blufi_disconnect(void);
81 
82 /* Stop advertisement */
83 void esp_blufi_adv_stop(void);
84 
85 /* Start advertisement */
86 void esp_blufi_adv_start(void);
87 
88 void esp_blufi_send_encap(void *arg);
89 
90 #ifdef CONFIG_BT_NIMBLE_ENABLED
91 /**
92  * @brief Handle gap event for BluFi.
93  *        This function can be called inside custom use gap event handler.
94  *        It provide minimal event management for BluFi purpose.
95  *
96  * @param[in] event The type of event being signalled.
97  * @param[in] arg Application-specified argument. Currently unused
98  * @return int 0 in case of success.
99  *             Other in case of failure.
100  */
101 int esp_blufi_handle_gap_events(struct ble_gap_event *event, void *arg);
102 #endif
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 #endif/* _ESP_BLUFI_ */
108