From ef4cecae25f5bc4acafe7a9d00676d2ec40a1e5a Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 3 Feb 2021 12:11:26 +0100 Subject: [PATCH] pkg/nimble/netif: add function to get used channels --- pkg/nimble/netif/include/nimble_netif.h | 15 +++++++++++++++ pkg/nimble/netif/nimble_netif.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pkg/nimble/netif/include/nimble_netif.h b/pkg/nimble/netif/include/nimble_netif.h index 1859115b20..bb033e500c 100644 --- a/pkg/nimble/netif/include/nimble_netif.h +++ b/pkg/nimble/netif/include/nimble_netif.h @@ -241,6 +241,21 @@ int nimble_netif_accept_stop(void); int nimble_netif_update(int handle, const struct ble_gap_upd_params *conn_params); +/** + * @brief Get the currently used channel map for the given connection as + * bitmap + * + * @param[in] handle connection handle + * @param[out] map used channel map, map[0] denotes channels 0 to 7, + * map[1] chan 8-15, ..., map[5] channels 33 to 36. + * **must** be able to hold 5 bytes. + * + * @return NIMBLE_NETIF_OK on success + * @return NIMBLE_NETIF_NOTCONN if handle dos not point to a connection + * @return NIMBLE_NETIF_DEVERR if reading the channel map failed otherwise + */ +int nimble_netif_used_chanmap(int handle, uint8_t map[5]); + #ifdef __cplusplus } #endif diff --git a/pkg/nimble/netif/nimble_netif.c b/pkg/nimble/netif/nimble_netif.c index 9485cad1f8..eb7b5d5e76 100644 --- a/pkg/nimble/netif/nimble_netif.c +++ b/pkg/nimble/netif/nimble_netif.c @@ -660,3 +660,18 @@ int nimble_netif_update(int handle, return NIMBLE_NETIF_OK; } + +int nimble_netif_used_chanmap(int handle, uint8_t map[5]) +{ + nimble_netif_conn_t *conn = nimble_netif_conn_get(handle); + if (conn == NULL) { + return NIMBLE_NETIF_NOTCONN; + } + + int res = ble_hs_hci_read_chan_map(conn->gaphandle, map); + if (res != 0) { + return NIMBLE_NETIF_DEVERR; + } + + return NIMBLE_NETIF_OK; +}