mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 19:24:33 +02:00
Nimble: Updated ble_l2cap_coc example
1. Corrected format 2. Fixed double free of memory issue in case of disconnection 3. Updated sdkconfig.default file to have correct value for COC_MAX_NUM configuration setting
This commit is contained in:
@@ -21,7 +21,7 @@ static uint8_t peer_addr[6];
|
|||||||
|
|
||||||
void ble_store_config_init(void);
|
void ble_store_config_init(void);
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM > 1
|
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM >= 1
|
||||||
|
|
||||||
#define COC_BUF_COUNT (3 * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM))
|
#define COC_BUF_COUNT (3 * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM))
|
||||||
#define L2CAP_COC_UUID 0x1812
|
#define L2CAP_COC_UUID 0x1812
|
||||||
@@ -55,9 +55,9 @@ blecent_l2cap_coc_send_data(struct ble_l2cap_chan *chan)
|
|||||||
|
|
||||||
rc = ble_l2cap_send(chan, sdu_rx_data);
|
rc = ble_l2cap_send(chan, sdu_rx_data);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
MODLOG_DFLT(INFO,"Data sent successfully");
|
MODLOG_DFLT(INFO, "Data sent successfully");
|
||||||
} else {
|
} else {
|
||||||
MODLOG_DFLT(INFO,"Data sending failed, rc = %d",rc);
|
MODLOG_DFLT(INFO, "Data sending failed, rc = %d", rc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +74,6 @@ blecent_l2cap_coc_on_disc_complete(const struct peer *peer, int status, void *ar
|
|||||||
sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
|
sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
|
||||||
ble_l2cap_connect(conn_handle_coc, psm, mtu, sdu_rx, blecent_l2cap_coc_event_cb,
|
ble_l2cap_connect(conn_handle_coc, psm, mtu, sdu_rx, blecent_l2cap_coc_event_cb,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
os_mbuf_free(sdu_rx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +95,7 @@ blecent_l2cap_coc_event_cb(struct ble_l2cap_event *event, void *arg)
|
|||||||
{
|
{
|
||||||
struct ble_l2cap_chan_info chan_info;
|
struct ble_l2cap_chan_info chan_info;
|
||||||
|
|
||||||
switch(event->type) {
|
switch (event->type) {
|
||||||
case BLE_L2CAP_EVENT_COC_CONNECTED:
|
case BLE_L2CAP_EVENT_COC_CONNECTED:
|
||||||
if (event->connect.status) {
|
if (event->connect.status) {
|
||||||
console_printf("LE COC error: %d\n", event->connect.status);
|
console_printf("LE COC error: %d\n", event->connect.status);
|
||||||
@@ -139,11 +137,12 @@ blecent_l2cap_coc_mem_init(void)
|
|||||||
COC_BUF_COUNT);
|
COC_BUF_COUNT);
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
}
|
}
|
||||||
#endif // #if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM > 1
|
#endif // #if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM >= 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when service discovery of the specified peer has completed.
|
* Called when service discovery of the specified peer has completed.
|
||||||
*/
|
*/
|
||||||
|
#if !CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM
|
||||||
static void
|
static void
|
||||||
blecent_on_disc_complete(const struct peer *peer, int status, void *arg)
|
blecent_on_disc_complete(const struct peer *peer, int status, void *arg)
|
||||||
{
|
{
|
||||||
@@ -167,6 +166,7 @@ blecent_on_disc_complete(const struct peer *peer, int status, void *arg)
|
|||||||
* write, and subscribe to notifications.
|
* write, and subscribe to notifications.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates the GAP general discovery procedure.
|
* Initiates the GAP general discovery procedure.
|
||||||
@@ -405,7 +405,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
print_conn_desc(&desc);
|
print_conn_desc(&desc);
|
||||||
MODLOG_DFLT(INFO, "\n");
|
MODLOG_DFLT(INFO, "\n");
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM > 1
|
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM >= 1
|
||||||
conn_handle_coc = event->connect.conn_handle;
|
conn_handle_coc = event->connect.conn_handle;
|
||||||
disc_cb = blecent_l2cap_coc_on_disc_complete;
|
disc_cb = blecent_l2cap_coc_on_disc_complete;
|
||||||
#else
|
#else
|
||||||
@@ -512,7 +512,7 @@ app_main(void)
|
|||||||
ble_hs_cfg.sync_cb = blecent_on_sync;
|
ble_hs_cfg.sync_cb = blecent_on_sync;
|
||||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM > 1
|
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM >= 1
|
||||||
blecent_l2cap_coc_mem_init();
|
blecent_l2cap_coc_mem_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -10,3 +10,4 @@ CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
|||||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||||
CONFIG_BT_NIMBLE_ENABLED=y
|
CONFIG_BT_NIMBLE_ENABLED=y
|
||||||
|
CONFIG_NIMBLE_L2CAP_COC_MAX_NUM=1
|
||||||
|
@@ -30,7 +30,7 @@ static uint8_t own_addr_type;
|
|||||||
|
|
||||||
void ble_store_config_init(void);
|
void ble_store_config_init(void);
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM > 1
|
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM >= 1
|
||||||
|
|
||||||
#define COC_BUF_COUNT (3 * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM))
|
#define COC_BUF_COUNT (3 * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM))
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ bleprph_advertise(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM > 1
|
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM >= 1
|
||||||
static int
|
static int
|
||||||
bleprph_l2cap_coc_accept(uint16_t conn_handle, uint16_t peer_mtu,
|
bleprph_l2cap_coc_accept(uint16_t conn_handle, uint16_t peer_mtu,
|
||||||
struct ble_l2cap_chan *chan)
|
struct ble_l2cap_chan *chan)
|
||||||
@@ -228,7 +228,7 @@ bleprph_l2cap_coc_event_cb(struct ble_l2cap_event *event, void *arg)
|
|||||||
{
|
{
|
||||||
struct ble_l2cap_chan_info chan_info;
|
struct ble_l2cap_chan_info chan_info;
|
||||||
|
|
||||||
switch(event->type) {
|
switch (event->type) {
|
||||||
case BLE_L2CAP_EVENT_COC_CONNECTED:
|
case BLE_L2CAP_EVENT_COC_CONNECTED:
|
||||||
if (event->connect.status) {
|
if (event->connect.status) {
|
||||||
console_printf("LE COC error: %d\n", event->connect.status);
|
console_printf("LE COC error: %d\n", event->connect.status);
|
||||||
@@ -334,7 +334,7 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
|
|||||||
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
|
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
bleprph_print_conn_desc(&desc);
|
bleprph_print_conn_desc(&desc);
|
||||||
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM > 1
|
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM >= 1
|
||||||
rc = ble_l2cap_create_server(psm, mtu, bleprph_l2cap_coc_event_cb, NULL);
|
rc = ble_l2cap_create_server(psm, mtu, bleprph_l2cap_coc_event_cb, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -460,7 +460,7 @@ app_main(void)
|
|||||||
ble_hs_cfg.sm_their_key_dist = 1;
|
ble_hs_cfg.sm_their_key_dist = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM > 1
|
#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM >= 1
|
||||||
bleprph_l2cap_coc_mem_init();
|
bleprph_l2cap_coc_mem_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -10,3 +10,4 @@ CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
|||||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||||
CONFIG_BT_NIMBLE_ENABLED=y
|
CONFIG_BT_NIMBLE_ENABLED=y
|
||||||
|
CONFIG_NIMBLE_L2CAP_COC_MAX_NUM=1
|
||||||
|
Reference in New Issue
Block a user