diff --git a/pkg/nimble/Makefile b/pkg/nimble/Makefile index 147437c6d4..69c8072862 100644 --- a/pkg/nimble/Makefile +++ b/pkg/nimble/Makefile @@ -1,6 +1,6 @@ PKG_NAME = nimble PKG_URL = https://github.com/apache/mynewt-nimble.git -PKG_VERSION = 7d3f3cc6afce62a628404856fe4f90e27e04350a +PKG_VERSION = cddb7c4ccee72e718c8b1a57166e702917e02c13 PKG_LICENSE = Apache-2.0 include $(RIOTBASE)/pkg/pkg.mk diff --git a/pkg/nimble/netif/include/nimble_netif.h b/pkg/nimble/netif/include/nimble_netif.h index 9b019ddd40..3abff75ece 100644 --- a/pkg/nimble/netif/include/nimble_netif.h +++ b/pkg/nimble/netif/include/nimble_netif.h @@ -288,6 +288,24 @@ int nimble_netif_update(int handle, */ int nimble_netif_used_chanmap(int handle, uint8_t map[5]); +/** + * @brief Trigger a L2CAP ping procedure for the specified connection + * + * This is a convenience wrapper around the NimBLE ble_l2cap_ping() function. + * + * @param[in] handle connection handle + * @param[in] cb callback triggered when the PING_RSP is received, + * executed in the NimBLE host thread context + * @param[in] data payload included in the PING_REQ and PING_RSP + * messages + * @param[in] data_len length of @p data in bytes + * + * @return 0 on success + * @return <0 on error + */ +int nimble_netif_l2cap_ping(int handle, ble_l2cap_ping_fn cb, + const void *data, uint16_t data_len); + #ifdef __cplusplus } #endif diff --git a/pkg/nimble/netif/nimble_netif.c b/pkg/nimble/netif/nimble_netif.c index 18bfb642db..e6a6937920 100644 --- a/pkg/nimble/netif/nimble_netif.c +++ b/pkg/nimble/netif/nimble_netif.c @@ -736,3 +736,13 @@ int nimble_netif_used_chanmap(int handle, uint8_t map[5]) return 0; } + +int nimble_netif_l2cap_ping(int handle, ble_l2cap_ping_fn cb, + const void *data, uint16_t data_len) +{ + nimble_netif_conn_t *conn = nimble_netif_conn_get(handle); + if (conn == NULL) { + return -1; + } + return ble_l2cap_ping(conn->gaphandle, cb, data, data_len); +} diff --git a/sys/shell/commands/sc_nimble_netif.c b/sys/shell/commands/sc_nimble_netif.c index 14674a79db..423baeea04 100644 --- a/sys/shell/commands/sc_nimble_netif.c +++ b/sys/shell/commands/sc_nimble_netif.c @@ -398,6 +398,13 @@ static void _cmd_update(int handle, int itvl, int timeout) } } +static void _on_echo_rsp(uint16_t gap_handle, uint32_t rtt, struct os_mbuf *om) +{ + int handle = nimble_netif_conn_get_by_gaphandle(gap_handle); + printf("ECHO_RSP handle:%i rtt:%u size:%u\n", + handle, (unsigned)rtt, (unsigned)OS_MBUF_PKTLEN(om)); +} + static int _ishelp(char *argv) { return memcmp(argv, "help", 4) == 0; @@ -418,9 +425,9 @@ int _nimble_netif_handler(int argc, char **argv) { if ((argc == 1) || _ishelp(argv[1])) { #if !IS_USED(MODULE_NIMBLE_AUTOCONN) && !IS_USED(MODULE_NIMBLE_STATCONN) - printf("usage: %s [help|info|adv|scan|connect|close|update|chanmap]\n", argv[0]); + printf("usage: %s [help|info|adv|scan|connect|close|update|chanmap|ping]\n", argv[0]); #else - printf("usage: %s [help|info|close|update|chanmap]\n", argv[0]); + printf("usage: %s [help|info|close|update|chanmap|ping]\n", argv[0]); #endif return 0; } @@ -543,7 +550,21 @@ int _nimble_netif_handler(int argc, char **argv) } return 0; } + else if ((memcmp(argv[1], "ping", 4) == 0)) { + if ((argc < 3) || _ishelp(argv[2])) { + printf("usage: %s %s \n", argv[0], argv[1]); + return 0; + } + int handle = atoi(argv[2]); + char *data = (argc > 3) ? argv[3] : NULL; + uint16_t data_len = (data != NULL) ? (uint16_t)strlen(data) : 0; + + int res = nimble_netif_l2cap_ping(handle, _on_echo_rsp, data, data_len); + if (res != 0) { + printf("err: unable to send ping (%i)\n", res); + } + } else { printf("unable to parse the command. Use '%s help' for more help\n", argv[0]);