This is an automated email from the ASF dual-hosted git repository. rymek pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 3a1a6d3d13b893ff2f7d2af5de5b5ee72342c5d3 Author: Ćukasz Rymanowski <[email protected]> AuthorDate: Tue Jan 28 15:11:30 2020 +0100 nimble/l2cap: Change API to retrieve L2CAP channel info Remove helpers which where used only by the test code (hopefully) with nicer helper which gives us more info. --- apps/blestress/src/rx_stress.c | 11 ++++++---- apps/blestress/src/tx_stress.c | 11 ++++++---- apps/btshell/src/main.c | 18 ++++++++-------- apps/bttester/src/l2cap.c | 12 +++++++---- nimble/host/include/host/ble_l2cap.h | 16 +++++++++++---- nimble/host/src/ble_l2cap.c | 25 +++++++++++++++++++++- nimble/host/src/ble_l2cap_coc.c | 40 ------------------------------------ 7 files changed, 68 insertions(+), 65 deletions(-) diff --git a/apps/blestress/src/rx_stress.c b/apps/blestress/src/rx_stress.c index dcb64bd..a4253ce 100644 --- a/apps/blestress/src/rx_stress.c +++ b/apps/blestress/src/rx_stress.c @@ -754,6 +754,7 @@ rx_stress_10_l2cap_event(struct ble_l2cap_event *event, void *arg) static int data_len = 1000; static int send_cnt = 0; static bool stalled = false; + struct ble_l2cap_chan_info chan_info; switch (event->type) { case BLE_L2CAP_EVENT_COC_CONNECTED: @@ -762,15 +763,17 @@ rx_stress_10_l2cap_event(struct ble_l2cap_event *event, void *arg) return 0; } + ble_l2cap_get_chan_info(event->connect.chan, &chan_info); + MODLOG_DFLT(INFO, "LE COC connected, conn: %d, chan: 0x%08lx, scid: 0x%04x, " "dcid: 0x%04x, our_mtu: 0x%04x, peer_mtu: 0x%04x\n", event->connect.conn_handle, (uint32_t) event->connect.chan, - ble_l2cap_get_scid(event->connect.chan), - ble_l2cap_get_dcid(event->connect.chan), - ble_l2cap_get_our_mtu(event->connect.chan), - ble_l2cap_get_peer_mtu(event->connect.chan)); + chan_info.scid, + chan_info.dcid, + chan_info.our_l2cap_mtu, + chan_info.peer_l2cap_mtu); struct ble_l2cap_sig_update_params params = { .itvl_min = 0x0006,//BLE_GAP_INITIAL_CONN_ITVL_MIN diff --git a/apps/blestress/src/tx_stress.c b/apps/blestress/src/tx_stress.c index 6ae6407..b73adc8 100644 --- a/apps/blestress/src/tx_stress.c +++ b/apps/blestress/src/tx_stress.c @@ -1020,6 +1020,7 @@ tx_stress_10_l2cap_event(struct ble_l2cap_event *event, void *arg) { static int i = 0; int64_t us = 0; + struct ble_l2cap_chan_info chan_info; switch (event->type) { case BLE_L2CAP_EVENT_COC_CONNECTED: @@ -1028,15 +1029,17 @@ tx_stress_10_l2cap_event(struct ble_l2cap_event *event, void *arg) MODLOG_DFLT(INFO, "Established L2CAP connection\n"); tx_stress_ctx->chan = event->connect.chan; + ble_l2cap_get_chan_info(event->connect.chan, &chan_info); + MODLOG_DFLT(INFO, "LE COC connected, conn: %d, chan: 0x%08lx, scid: 0x%04x, " "dcid: 0x%04x, our_mtu: 0x%04x, peer_mtu: 0x%04x\n", event->connect.conn_handle, (uint32_t) event->connect.chan, - ble_l2cap_get_scid(event->connect.chan), - ble_l2cap_get_dcid(event->connect.chan), - ble_l2cap_get_our_mtu(event->connect.chan), - ble_l2cap_get_peer_mtu(event->connect.chan)); + chan_info.scid, + chan_info.dcid, + chan_info.our_l2cap_mtu, + chan_info.peer_l2cap_mtu); tx_stress_10_l2cap_send_req(); } diff --git a/apps/btshell/src/main.c b/apps/btshell/src/main.c index 26ade44..56a17f1 100644 --- a/apps/btshell/src/main.c +++ b/apps/btshell/src/main.c @@ -2213,6 +2213,7 @@ static int btshell_l2cap_event(struct ble_l2cap_event *event, void *arg) { int accept_response; + struct ble_l2cap_chan_info chan_info; switch(event->type) { case BLE_L2CAP_EVENT_COC_CONNECTED: @@ -2221,14 +2222,15 @@ btshell_l2cap_event(struct ble_l2cap_event *event, void *arg) return 0; } - console_printf("LE COC connected, conn: %d, chan: 0x%08lx, scid: 0x%04x, " - "dcid: 0x%04x, our_mtu: 0x%04x, peer_mtu: 0x%04x\n", - event->connect.conn_handle, - (uint32_t) event->connect.chan, - ble_l2cap_get_scid(event->connect.chan), - ble_l2cap_get_dcid(event->connect.chan), - ble_l2cap_get_our_mtu(event->connect.chan), - ble_l2cap_get_peer_mtu(event->connect.chan)); + if (ble_l2cap_get_chan_info(event->connect.chan, &chan_info)) { + assert(0); + } + + console_printf("LE COC connected, conn: %d, chan: 0x%08lx, psm: 0x%02x, scid: 0x%04x, " + "dcid: 0x%04x, our_mps: %d, our_mtu: %d, peer_mps: 0x%d, peer_mtu: %d\n", + event->connect.conn_handle, (uint32_t) event->connect.chan, + chan_info.psm, chan_info.scid, chan_info.dcid, + chan_info.our_l2cap_mtu, chan_info.our_coc_mtu, chan_info.peer_l2cap_mtu, chan_info.peer_coc_mtu); btshell_l2cap_coc_add(event->connect.conn_handle, event->connect.chan); diff --git a/apps/bttester/src/l2cap.c b/apps/bttester/src/l2cap.c index e30ef79..45b904a 100644 --- a/apps/bttester/src/l2cap.c +++ b/apps/bttester/src/l2cap.c @@ -207,6 +207,8 @@ static int accept_cb(uint16_t conn_handle, uint16_t peer_mtu, static int tester_l2cap_event(struct ble_l2cap_event *event, void *arg) { + struct ble_l2cap_chan_info chan_info; + switch (event->type) { case BLE_L2CAP_EVENT_COC_CONNECTED: if (event->connect.status) { @@ -216,14 +218,16 @@ tester_l2cap_event(struct ble_l2cap_event *event, void *arg) return 0; } + ble_l2cap_get_chan_info(event->connect.chan, &chan_info); + console_printf("LE COC connected, conn: %d, chan: 0x%08lx, scid: 0x%04x, " "dcid: 0x%04x, our_mtu: 0x%04x, peer_mtu: 0x%04x\n", event->connect.conn_handle, (uint32_t) event->connect.chan, - ble_l2cap_get_scid(event->connect.chan), - ble_l2cap_get_dcid(event->connect.chan), - ble_l2cap_get_our_mtu(event->connect.chan), - ble_l2cap_get_peer_mtu(event->connect.chan)); + chan_info.scid, + chan_info.dcid, + chan_info.our_l2cap_mtu, + chan_info.peer_l2cap_mtu); connected_cb(event->connect.conn_handle, event->connect.chan, arg); diff --git a/nimble/host/include/host/ble_l2cap.h b/nimble/host/include/host/ble_l2cap.h index 644bd9d..b77ef25 100644 --- a/nimble/host/include/host/ble_l2cap.h +++ b/nimble/host/include/host/ble_l2cap.h @@ -199,8 +199,19 @@ struct ble_l2cap_event { }; }; +struct ble_l2cap_chan_info { + uint16_t scid; + uint16_t dcid; + uint16_t our_l2cap_mtu; + uint16_t peer_l2cap_mtu; + uint16_t psm; + uint16_t our_coc_mtu; + uint16_t peer_coc_mtu; +}; + typedef int ble_l2cap_event_fn(struct ble_l2cap_event *event, void *arg); + uint16_t ble_l2cap_get_conn_handle(struct ble_l2cap_chan *chan); int ble_l2cap_create_server(uint16_t psm, uint16_t mtu, ble_l2cap_event_fn *cb, void *cb_arg); @@ -211,10 +222,7 @@ int ble_l2cap_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu, int ble_l2cap_disconnect(struct ble_l2cap_chan *chan); int ble_l2cap_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_tx); int ble_l2cap_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx); -int ble_l2cap_get_scid(struct ble_l2cap_chan *chan); -int ble_l2cap_get_dcid(struct ble_l2cap_chan *chan); -int ble_l2cap_get_our_mtu(struct ble_l2cap_chan *chan); -int ble_l2cap_get_peer_mtu(struct ble_l2cap_chan *chan); +int ble_l2cap_get_chan_info(struct ble_l2cap_chan *chan, struct ble_l2cap_chan_info *chan_info); #ifdef __cplusplus } diff --git a/nimble/host/src/ble_l2cap.c b/nimble/host/src/ble_l2cap.c index b36bc92..19cf8c7 100644 --- a/nimble/host/src/ble_l2cap.c +++ b/nimble/host/src/ble_l2cap.c @@ -155,7 +155,30 @@ ble_l2cap_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu, return ble_l2cap_sig_coc_connect(conn_handle, psm, mtu, sdu_rx, cb, cb_arg); } -int ble_l2cap_disconnect(struct ble_l2cap_chan *chan) +int +ble_l2cap_get_chan_info(struct ble_l2cap_chan *chan, struct ble_l2cap_chan_info *chan_info) +{ + if (!chan || !chan_info) { + return BLE_HS_EINVAL; + } + + memset(chan_info, 0, sizeof(*chan_info)); + chan_info->dcid = chan->dcid; + chan_info->scid = chan->scid; + chan_info->our_l2cap_mtu = chan->my_mtu; + chan_info->peer_l2cap_mtu = chan->peer_mtu; + +#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) + chan_info->psm = chan->psm; + chan_info->our_coc_mtu = chan->coc_rx.mtu; + chan_info->peer_coc_mtu = chan->coc_tx.mtu; +#endif + + return 0; +} + +int +ble_l2cap_disconnect(struct ble_l2cap_chan *chan) { return ble_l2cap_sig_disconnect(chan); } diff --git a/nimble/host/src/ble_l2cap_coc.c b/nimble/host/src/ble_l2cap_coc.c index 329c87c..c656ea1 100644 --- a/nimble/host/src/ble_l2cap_coc.c +++ b/nimble/host/src/ble_l2cap_coc.c @@ -589,46 +589,6 @@ ble_l2cap_coc_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_tx) } int -ble_l2cap_get_scid(struct ble_l2cap_chan *chan) -{ - if (!chan) { - return 0; - } - - return chan->scid; -} - -int -ble_l2cap_get_dcid(struct ble_l2cap_chan *chan) -{ - if (!chan) { - return 0; - } - - return chan->dcid; -} - -int -ble_l2cap_get_our_mtu(struct ble_l2cap_chan *chan) -{ - if (!chan) { - return 0; - } - - return chan->my_mtu; -} - -int -ble_l2cap_get_peer_mtu(struct ble_l2cap_chan *chan) -{ - if (!chan) { - return 0; - } - - return chan->peer_mtu; -} - -int ble_l2cap_coc_init(void) { STAILQ_INIT(&ble_l2cap_coc_srvs);
