nimble_netif_conn.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-2019 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
22 #ifndef NIMBLE_NETIF_CONN_H
23 #define NIMBLE_NETIF_CONN_H
24 
25 #include <stdint.h>
26 #include <stdbool.h>
27 
28 #include "nimble_netif.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
37 #define NIMBLE_NETIF_CONN_INVALID (-1)
38 
42 typedef struct {
43  struct ble_l2cap_chan *coc;
44  uint16_t gaphandle;
45  uint16_t itvl;
46  uint16_t state;
47  uint8_t addr[BLE_ADDR_LEN];
50 
62  int handle, void *arg);
63 
70 
80 
88 
96 
105 int nimble_netif_conn_get_by_addr(const uint8_t *addr);
106 
115 int nimble_netif_conn_get_by_gaphandle(uint16_t gaphandle);
116 
127 void nimble_netif_conn_foreach(uint16_t filter,
128  nimble_netif_conn_iter_t cb, void *arg);
129 
142 int nimble_netif_conn_get_next(int handle, uint16_t filter);
143 
153 unsigned nimble_netif_conn_count(uint16_t filter);
154 
163 int nimble_netif_conn_start_connection(const uint8_t *addr);
164 
174 
178 void nimble_netif_conn_free(int handle, uint8_t *addr);
179 
188 uint16_t nimble_netif_conn_get_itvl_ms(int handle);
189 
202 bool nimble_netif_conn_itvl_used(uint16_t itvl, int skip_handle);
203 
218 uint16_t nimble_netif_conn_gen_itvl(uint16_t min, uint16_t max);
219 
229 static inline
231 {
233 }
234 
242 static inline int nimble_netif_conn_connecting(void)
243 {
245 }
246 
256 static inline int nimble_netif_conn_connected(const uint8_t *addr)
257 {
259 }
260 
269 static inline int nimble_netif_conn_is_open(const nimble_netif_conn_t *conn)
270 {
271  return (conn->coc != NULL);
272 }
273 
281 static inline int nimble_netif_conn_is_adv(void)
282 {
284 }
285 
286 #ifdef __cplusplus
287 }
288 #endif
289 
290 #endif /* NIMBLE_NETIF_CONN_H */
#define BLE_ADDR_LEN
link layer address length
Definition: ble.h:43
void nimble_netif_conn_foreach(uint16_t filter, nimble_netif_conn_iter_t cb, void *arg)
Iterate over all connection contexts that match the filter condition.
int nimble_netif_conn_start_adv(void)
Reserve a unused context for the purpose of accepting a new connection.
#define NIMBLE_NETIF_CONN_INVALID
Value for marking a handle invalid.
bool nimble_netif_conn_itvl_used(uint16_t itvl, int skip_handle)
Check if the given connection interval is used, taking the minimal spacing as defined by NIMBLE_NETIF...
static nimble_netif_conn_t * nimble_netif_conn_from_gaphandle(uint16_t gh)
Find the connection context with a given GAP handle and return a pointer to it.
static int nimble_netif_conn_is_adv(void)
Convenience function to check if any context is currently in the advertising state (NIMBLE_NETIF_ADV)
uint16_t nimble_netif_conn_get_itvl_ms(int handle)
Get the used connection interval for the given connection handle.
int nimble_netif_conn_get_adv(void)
Get the handle to the context that is currently advertising.
int nimble_netif_conn_get_connecting(void)
Get the handle to the context that is busy connecting.
nimble_netif_conn_t * nimble_netif_conn_get(int handle)
Get the connection context corresponding to the given handle.
void nimble_netif_conn_free(int handle, uint8_t *addr)
Free the connection context with the given handle.
int nimble_netif_conn_get_by_addr(const uint8_t *addr)
Find the connection to the peer with the given BLE address.
int nimble_netif_conn_start_connection(const uint8_t *addr)
Allocate an unused context for starting a connection.
unsigned nimble_netif_conn_count(uint16_t filter)
Count the number of connections contexts for which the given filter applies.
static int nimble_netif_conn_connecting(void)
Convenience function to check if any context is currently in the connecting state (NIMBLE_NETIF_CONNE...
uint16_t nimble_netif_conn_gen_itvl(uint16_t min, uint16_t max)
Generate a pseudorandom connection interval from the given range.
static int nimble_netif_conn_connected(const uint8_t *addr)
Convenience function to check if we are currently connected to a peer with the given address.
int nimble_netif_conn_get_next(int handle, uint16_t filter)
Find the next context that matches the filter condition.
int nimble_netif_conn_get_by_gaphandle(uint16_t gaphandle)
Find the connection using the given NimBLE GAP handle.
static int nimble_netif_conn_is_open(const nimble_netif_conn_t *conn)
Test if the given connection is (still) open.
int(* nimble_netif_conn_iter_t)(nimble_netif_conn_t *conn, int handle, void *arg)
Iterator function signature used by nimble_netif_conn_foreach()
void nimble_netif_conn_init(void)
Initialize the connection state manager.
GNRC netif implementation for NimBLE.
Memory layout for holding the relevant connection information.
uint16_t state
the current state of the context
struct ble_l2cap_chan * coc
l2cap context as exposed by NimBLE
uint16_t itvl
currently used connection interval
uint16_t gaphandle
GAP handle exposed by NimBLE.