nimble/statconn: return errno values

This commit is contained in:
Hauke Petersen 2021-12-06 11:27:46 +01:00
parent 884f0e7a5b
commit d36879c6bc
2 changed files with 14 additions and 23 deletions

View File

@ -50,6 +50,7 @@
#ifndef NIMBLE_STATCONN_H #ifndef NIMBLE_STATCONN_H
#define NIMBLE_STATCONN_H #define NIMBLE_STATCONN_H
#include <errno.h>
#include <stdint.h> #include <stdint.h>
#include "nimble_netif.h" #include "nimble_netif.h"
@ -112,16 +113,6 @@ extern "C" {
#define NIMBLE_STATCONN_CONN_SUPERTO_MS (2500U) #define NIMBLE_STATCONN_CONN_SUPERTO_MS (2500U)
#endif #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 * @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 * @param[in] addr BLE address of the peer
* *
* @return NIMBLE_STATCONN_OK if peer was successfully added * @return 0 if peer was successfully added
* @return NIMBLE_STATCONN_INUSE if the peer address is already in use * @return -EALREADY if the peer address is already in use
* @return NIMBLE_STATCONN_NOSLOT if no empty connection slot is available * @return -ENOMEM if no empty connection slot is available
*/ */
int nimble_statconn_add_master(const uint8_t *addr); 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 * @param[in] addr BLE address of the peer
* *
* @return NIMBLE_STATCONN_OK if peer was successfully added * @return 0 if peer was successfully added
* @return NIMBLE_STATCONN_INUSE if the peer address is already in use * @return -EALREADY if the peer address is already in use
* @return NIMBLE_STATCONN_NOSLOT if no empty connection slot is available * @return -ENOMEM if no empty connection slot is available
*/ */
int nimble_statconn_add_slave(const uint8_t *addr); 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 * @param[in] addr BLE address of the peer
* *
* @return NIMBLE_STATCONN_OK if peer was successfully removed * @return 0 if peer was successfully removed
* @return NIMBLE_STATCONN_NOTCONN if given address is not managed * @return -ENOTCONN if given address is not managed
*/ */
int nimble_statconn_rm(const uint8_t *addr); int nimble_statconn_rm(const uint8_t *addr);

View File

@ -159,19 +159,19 @@ static int _be(uint8_t role, const uint8_t *addr)
slot_t *s = _get_addr(addr); slot_t *s = _get_addr(addr);
if (s != NULL) { if (s != NULL) {
mutex_unlock(&_lock); mutex_unlock(&_lock);
return NIMBLE_STATCONN_INUSE; return -EALREADY;
} }
s = _get_state(UNUSED); s = _get_state(UNUSED);
if (s == NULL) { if (s == NULL) {
mutex_unlock(&_lock); mutex_unlock(&_lock);
return NIMBLE_STATCONN_NOSLOT; return -ENOMEM;
} }
s->state = (role | PENDING); s->state = (role | PENDING);
memcpy(s->addr, addr, BLE_ADDR_LEN); memcpy(s->addr, addr, BLE_ADDR_LEN);
mutex_unlock(&_lock); mutex_unlock(&_lock);
_activate(role); _activate(role);
return NIMBLE_STATCONN_OK; return 0;
} }
void nimble_statconn_init(void) void nimble_statconn_init(void)
@ -226,7 +226,7 @@ int nimble_statconn_rm(const uint8_t *addr)
slot_t *s = _get_addr(addr); slot_t *s = _get_addr(addr);
if (s == NULL) { if (s == NULL) {
mutex_unlock(&_lock); mutex_unlock(&_lock);
return NIMBLE_STATCONN_NOTCONN; return -ENOTCONN;
} }
uint8_t role = (s->state & ROLE_M) ? ROLE_M : ROLE_S; 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); _activate(ROLE_S);
} }
return NIMBLE_STATCONN_OK; return 0;
} }