Merge pull request #16539 from haukepetersen/add_nimble_scnetifping
sys/shell/sc_nimble_netif: add ping subcommand
This commit is contained in:
commit
21ed0d2326
@ -1,6 +1,6 @@
|
|||||||
PKG_NAME = nimble
|
PKG_NAME = nimble
|
||||||
PKG_URL = https://github.com/apache/mynewt-nimble.git
|
PKG_URL = https://github.com/apache/mynewt-nimble.git
|
||||||
PKG_VERSION = 7d3f3cc6afce62a628404856fe4f90e27e04350a
|
PKG_VERSION = cddb7c4ccee72e718c8b1a57166e702917e02c13
|
||||||
PKG_LICENSE = Apache-2.0
|
PKG_LICENSE = Apache-2.0
|
||||||
|
|
||||||
include $(RIOTBASE)/pkg/pkg.mk
|
include $(RIOTBASE)/pkg/pkg.mk
|
||||||
|
|||||||
@ -288,6 +288,24 @@ int nimble_netif_update(int handle,
|
|||||||
*/
|
*/
|
||||||
int nimble_netif_used_chanmap(int handle, uint8_t map[5]);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -736,3 +736,13 @@ int nimble_netif_used_chanmap(int handle, uint8_t map[5])
|
|||||||
|
|
||||||
return 0;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@ -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)
|
static int _ishelp(char *argv)
|
||||||
{
|
{
|
||||||
return memcmp(argv, "help", 4) == 0;
|
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 ((argc == 1) || _ishelp(argv[1])) {
|
||||||
#if !IS_USED(MODULE_NIMBLE_AUTOCONN) && !IS_USED(MODULE_NIMBLE_STATCONN)
|
#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
|
#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
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -543,7 +550,21 @@ int _nimble_netif_handler(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else if ((memcmp(argv[1], "ping", 4) == 0)) {
|
||||||
|
if ((argc < 3) || _ishelp(argv[2])) {
|
||||||
|
printf("usage: %s %s <handle>\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 {
|
else {
|
||||||
printf("unable to parse the command. Use '%s help' for more help\n",
|
printf("unable to parse the command. Use '%s help' for more help\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user