mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 05:34:32 +02:00
Merge branch 'feat/NimBLE-Blufi-custom-use' into 'master'
Nimble: Add support to expose blufi handler for external BLE application See merge request espressif/esp-idf!20424
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||||
#include "nimble/ble.h"
|
#include "nimble/ble.h"
|
||||||
|
#include "host/ble_gap.h"
|
||||||
#include "modlog/modlog.h"
|
#include "modlog/modlog.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -81,4 +82,18 @@ void esp_blufi_adv_start(void);
|
|||||||
|
|
||||||
void esp_blufi_send_encap(void *arg);
|
void esp_blufi_send_encap(void *arg);
|
||||||
|
|
||||||
|
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||||
|
/**
|
||||||
|
* @brief Handle gap event for BluFi.
|
||||||
|
* This function can be called inside custom use gap event handler.
|
||||||
|
* It provide minimal event management for BluFi purpose.
|
||||||
|
*
|
||||||
|
* @param[in] event The type of event being signalled.
|
||||||
|
* @param[in] arg Application-specified argument. Currently unused
|
||||||
|
* @return int 0 in case of success.
|
||||||
|
* Other in case of failure.
|
||||||
|
*/
|
||||||
|
int esp_blufi_handle_gap_events(struct ble_gap_event *event, void *arg);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif/* _ESP_BLUFI_ */
|
#endif/* _ESP_BLUFI_ */
|
||||||
|
@@ -33,7 +33,6 @@
|
|||||||
#if (BLUFI_INCLUDED == TRUE)
|
#if (BLUFI_INCLUDED == TRUE)
|
||||||
|
|
||||||
static uint8_t own_addr_type;
|
static uint8_t own_addr_type;
|
||||||
static uint16_t conn_handle;
|
|
||||||
|
|
||||||
struct gatt_value gatt_values[SERVER_MAX_VALUES];
|
struct gatt_value gatt_values[SERVER_MAX_VALUES];
|
||||||
const static char *TAG = "BLUFI_EXAMPLE";
|
const static char *TAG = "BLUFI_EXAMPLE";
|
||||||
@@ -265,7 +264,7 @@ esp_blufi_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
|
|
||||||
param.connect.conn_id = event->connect.conn_handle;
|
param.connect.conn_id = event->connect.conn_handle;
|
||||||
/* save connection handle */
|
/* save connection handle */
|
||||||
conn_handle = event->connect.conn_handle;
|
blufi_env.conn_id = event->connect.conn_handle;
|
||||||
btc_transfer_context(&msg, ¶m, sizeof(esp_blufi_cb_param_t), NULL);
|
btc_transfer_context(&msg, ¶m, sizeof(esp_blufi_cb_param_t), NULL);
|
||||||
}
|
}
|
||||||
if (event->connect.status != 0) {
|
if (event->connect.status != 0) {
|
||||||
@@ -433,13 +432,13 @@ void esp_blufi_send_notify(void *arg)
|
|||||||
struct os_mbuf *om;
|
struct os_mbuf *om;
|
||||||
om = ble_hs_mbuf_from_flat(pkts->pkt, pkts->pkt_len);
|
om = ble_hs_mbuf_from_flat(pkts->pkt, pkts->pkt_len);
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
rc = ble_gattc_notify_custom(conn_handle, gatt_values[1].val_handle, om);
|
rc = ble_gattc_notify_custom(blufi_env.conn_id, gatt_values[1].val_handle, om);
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void esp_blufi_disconnect(void)
|
void esp_blufi_disconnect(void)
|
||||||
{
|
{
|
||||||
ble_gap_terminate(conn_handle, BLE_ERR_REM_USER_CONN_TERM);
|
ble_gap_terminate(blufi_env.conn_id, BLE_ERR_REM_USER_CONN_TERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
void esp_blufi_adv_stop(void) {}
|
void esp_blufi_adv_stop(void) {}
|
||||||
@@ -470,4 +469,71 @@ void esp_blufi_btc_deinit(void)
|
|||||||
{
|
{
|
||||||
btc_deinit();
|
btc_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int esp_blufi_handle_gap_events(struct ble_gap_event *event, void *arg)
|
||||||
|
{
|
||||||
|
struct ble_gap_conn_desc desc;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (event != NULL) {
|
||||||
|
switch (event->type) {
|
||||||
|
case BLE_GAP_EVENT_CONNECT:
|
||||||
|
if (event->connect.status == 0) {
|
||||||
|
btc_msg_t msg;
|
||||||
|
esp_blufi_cb_param_t param;
|
||||||
|
|
||||||
|
blufi_env.is_connected = true;
|
||||||
|
blufi_env.recv_seq = blufi_env.send_seq = 0;
|
||||||
|
blufi_env.conn_id = event->connect.conn_handle;
|
||||||
|
|
||||||
|
msg.sig = BTC_SIG_API_CB;
|
||||||
|
msg.pid = BTC_PID_BLUFI;
|
||||||
|
msg.act = ESP_BLUFI_EVENT_BLE_CONNECT;
|
||||||
|
|
||||||
|
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
|
||||||
|
assert(rc == 0);
|
||||||
|
memcpy(param.connect.remote_bda, desc.peer_id_addr.val, sizeof(esp_bd_addr_t));
|
||||||
|
|
||||||
|
param.connect.conn_id = event->connect.conn_handle;
|
||||||
|
btc_transfer_context(&msg, ¶m, sizeof(esp_blufi_cb_param_t), NULL);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
case BLE_GAP_EVENT_DISCONNECT: {
|
||||||
|
btc_msg_t msg;
|
||||||
|
esp_blufi_cb_param_t param;
|
||||||
|
|
||||||
|
blufi_env.is_connected = false;
|
||||||
|
blufi_env.recv_seq = blufi_env.send_seq = 0;
|
||||||
|
blufi_env.sec_mode = 0x0;
|
||||||
|
blufi_env.offset = 0;
|
||||||
|
|
||||||
|
memcpy(blufi_env.remote_bda,
|
||||||
|
event->disconnect.conn.peer_id_addr.val,
|
||||||
|
sizeof(esp_bd_addr_t));
|
||||||
|
|
||||||
|
if (blufi_env.aggr_buf != NULL) {
|
||||||
|
osi_free(blufi_env.aggr_buf);
|
||||||
|
blufi_env.aggr_buf = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.sig = BTC_SIG_API_CB;
|
||||||
|
msg.pid = BTC_PID_BLUFI;
|
||||||
|
msg.act = ESP_BLUFI_EVENT_BLE_DISCONNECT;
|
||||||
|
memcpy(param.disconnect.remote_bda,
|
||||||
|
event->disconnect.conn.peer_id_addr.val,
|
||||||
|
sizeof(esp_bd_addr_t));
|
||||||
|
btc_transfer_context(&msg, ¶m, sizeof(esp_blufi_cb_param_t), NULL);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case BLE_GAP_EVENT_MTU:
|
||||||
|
blufi_env.frag_size = (event->mtu.value < BLUFI_MAX_DATA_LEN ? event->mtu.value :
|
||||||
|
BLUFI_MAX_DATA_LEN) - BLUFI_MTU_RESERVED_SIZE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user