From d36879c6bca70c30d73ffbd4c865e3e47add37ee Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 6 Dec 2021 11:27:46 +0100 Subject: [PATCH 1/2] nimble/statconn: return errno values --- pkg/nimble/statconn/include/nimble_statconn.h | 27 +++++++------------ pkg/nimble/statconn/nimble_statconn.c | 10 +++---- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/pkg/nimble/statconn/include/nimble_statconn.h b/pkg/nimble/statconn/include/nimble_statconn.h index 8a579113e9..da39800701 100644 --- a/pkg/nimble/statconn/include/nimble_statconn.h +++ b/pkg/nimble/statconn/include/nimble_statconn.h @@ -50,6 +50,7 @@ #ifndef NIMBLE_STATCONN_H #define NIMBLE_STATCONN_H +#include #include #include "nimble_netif.h" @@ -112,16 +113,6 @@ extern "C" { #define NIMBLE_STATCONN_CONN_SUPERTO_MS (2500U) #endif -/** - * @brief Return codes used by the statconn module - */ -enum { - NIMBLE_STATCONN_OK = 0, /**< all groovy */ - NIMBLE_STATCONN_NOSLOT = -1, /**< no more connection slot available */ - NIMBLE_STATCONN_NOTCONN = -2, /**< given address is not managed */ - NIMBLE_STATCONN_INUSE = -3, /**< given peer is already managed */ -}; - /** * @brief Initialize the statconn module * @@ -148,9 +139,9 @@ void nimble_statconn_eventcb(nimble_netif_eventcb_t cb); * * @param[in] addr BLE address of the peer * - * @return NIMBLE_STATCONN_OK if peer was successfully added - * @return NIMBLE_STATCONN_INUSE if the peer address is already in use - * @return NIMBLE_STATCONN_NOSLOT if no empty connection slot is available + * @return 0 if peer was successfully added + * @return -EALREADY if the peer address is already in use + * @return -ENOMEM if no empty connection slot is available */ int nimble_statconn_add_master(const uint8_t *addr); @@ -159,9 +150,9 @@ int nimble_statconn_add_master(const uint8_t *addr); * * @param[in] addr BLE address of the peer * - * @return NIMBLE_STATCONN_OK if peer was successfully added - * @return NIMBLE_STATCONN_INUSE if the peer address is already in use - * @return NIMBLE_STATCONN_NOSLOT if no empty connection slot is available + * @return 0 if peer was successfully added + * @return -EALREADY if the peer address is already in use + * @return -ENOMEM if no empty connection slot is available */ int nimble_statconn_add_slave(const uint8_t *addr); @@ -170,8 +161,8 @@ int nimble_statconn_add_slave(const uint8_t *addr); * * @param[in] addr BLE address of the peer * - * @return NIMBLE_STATCONN_OK if peer was successfully removed - * @return NIMBLE_STATCONN_NOTCONN if given address is not managed + * @return 0 if peer was successfully removed + * @return -ENOTCONN if given address is not managed */ int nimble_statconn_rm(const uint8_t *addr); diff --git a/pkg/nimble/statconn/nimble_statconn.c b/pkg/nimble/statconn/nimble_statconn.c index 1826e0a2f3..bd99309572 100644 --- a/pkg/nimble/statconn/nimble_statconn.c +++ b/pkg/nimble/statconn/nimble_statconn.c @@ -159,19 +159,19 @@ static int _be(uint8_t role, const uint8_t *addr) slot_t *s = _get_addr(addr); if (s != NULL) { mutex_unlock(&_lock); - return NIMBLE_STATCONN_INUSE; + return -EALREADY; } s = _get_state(UNUSED); if (s == NULL) { mutex_unlock(&_lock); - return NIMBLE_STATCONN_NOSLOT; + return -ENOMEM; } s->state = (role | PENDING); memcpy(s->addr, addr, BLE_ADDR_LEN); mutex_unlock(&_lock); _activate(role); - return NIMBLE_STATCONN_OK; + return 0; } void nimble_statconn_init(void) @@ -226,7 +226,7 @@ int nimble_statconn_rm(const uint8_t *addr) slot_t *s = _get_addr(addr); if (s == NULL) { mutex_unlock(&_lock); - return NIMBLE_STATCONN_NOTCONN; + return -ENOTCONN; } uint8_t role = (s->state & ROLE_M) ? ROLE_M : ROLE_S; @@ -242,5 +242,5 @@ int nimble_statconn_rm(const uint8_t *addr) _activate(ROLE_S); } - return NIMBLE_STATCONN_OK; + return 0; } From c7e11d5904d51c46db1138e86c90c2180a9f2fb6 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 6 Dec 2021 11:21:37 +0100 Subject: [PATCH 2/2] shell/sc_nimble_statconn: adapt to new return vals --- sys/shell/commands/sc_nimble_statconn.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/shell/commands/sc_nimble_statconn.c b/sys/shell/commands/sc_nimble_statconn.c index dc4c746018..26726c42a9 100644 --- a/sys/shell/commands/sc_nimble_statconn.c +++ b/sys/shell/commands/sc_nimble_statconn.c @@ -39,7 +39,7 @@ int _nimble_statconn_handler(int argc, char **argv) } if (strncmp(argv[1], "addm", 4) == 0) { - if (nimble_statconn_add_master(addr) == NIMBLE_STATCONN_OK) { + if (nimble_statconn_add_master(addr) == 0) { puts("success: connecting to peer as slave"); } else { @@ -47,7 +47,7 @@ int _nimble_statconn_handler(int argc, char **argv) } } else if (strncmp(argv[1], "adds", 4) == 0) { - if (nimble_statconn_add_slave(addr) == NIMBLE_STATCONN_OK) { + if (nimble_statconn_add_slave(addr) == 0) { puts("success: connecting to peer as master"); } else { @@ -55,7 +55,7 @@ int _nimble_statconn_handler(int argc, char **argv) } } else if (strncmp(argv[1], "rm", 2) == 0) { - if (nimble_statconn_rm(addr) == NIMBLE_STATCONN_OK) { + if (nimble_statconn_rm(addr) == 0) { puts("success: closed connection to peer"); } else {