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 
27 #include "nimble_netif.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
36 #define NIMBLE_NETIF_CONN_INVALID (-1)
37 
41 typedef struct {
42  struct ble_l2cap_chan *coc;
43  uint16_t gaphandle;
44  uint16_t state;
45  uint8_t addr[BLE_ADDR_LEN];
48 
60  int handle, void *arg);
61 
67 void nimble_netif_conn_init(void);
68 
78 
86 
94 
103 int nimble_netif_conn_get_by_addr(const uint8_t *addr);
104 
113 int nimble_netif_conn_get_by_gaphandle(uint16_t gaphandle);
114 
115 
126 void nimble_netif_conn_foreach(uint16_t filter,
127  nimble_netif_conn_iter_t cb, void *arg);
128 
141 int nimble_netif_conn_get_next(int handle, uint16_t filter);
142 
152 unsigned nimble_netif_conn_count(uint16_t filter);
153 
162 int nimble_netif_conn_start_connection(const uint8_t *addr);
163 
172 
176 void nimble_netif_conn_free(int handle, uint8_t *addr);
177 
187 static inline
189 {
191 }
192 
200 static inline int nimble_netif_conn_connecting(void)
201 {
203 }
204 
214 static inline int nimble_netif_conn_connected(const uint8_t *addr)
215 {
217 }
218 
227 static inline int nimble_netif_conn_is_open(const nimble_netif_conn_t *conn)
228 {
229  return (conn->coc != NULL);
230 }
231 
239 static inline int nimble_netif_conn_is_adv(void)
240 {
242 }
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 
248 #endif /* NIMBLE_NETIF_CONN_H */
249 
nimble_netif_conn_is_open
static int nimble_netif_conn_is_open(const nimble_netif_conn_t *conn)
Test if the given connection is (still) open.
Definition: nimble_netif_conn.h:227
nimble_netif_conn_is_adv
static int nimble_netif_conn_is_adv(void)
Convenience function to check if any context is currently in the advertising state (NIMBLE_NETIF_ADV)
Definition: nimble_netif_conn.h:239
nimble_netif_conn_t::coc
struct ble_l2cap_chan * coc
l2cap context as exposed by NimBLE
Definition: nimble_netif_conn.h:42
nimble_netif_conn_get_by_gaphandle
int nimble_netif_conn_get_by_gaphandle(uint16_t gaphandle)
Find the connection using the given NimBLE GAP handle.
nimble_netif_conn_start_adv
int nimble_netif_conn_start_adv(void)
Reserve a unused context for the purpose of accepting a new connection.
nimble_netif_conn_connected
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.
Definition: nimble_netif_conn.h:214
nimble_netif_conn_count
unsigned nimble_netif_conn_count(uint16_t filter)
Count the number of connections contexts for which the given filter applies.
nimble_netif_conn_free
void nimble_netif_conn_free(int handle, uint8_t *addr)
Free the connection context with the given handle.
nimble_netif_conn_connecting
static int nimble_netif_conn_connecting(void)
Convenience function to check if any context is currently in the connecting state (NIMBLE_NETIF_CONNE...
Definition: nimble_netif_conn.h:200
nimble_netif_conn_from_gaphandle
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.
Definition: nimble_netif_conn.h:188
nimble_netif.h
GNRC netif implementation for NimBLE.
nimble_netif_conn_init
void nimble_netif_conn_init(void)
Initialize the connection state manager.
nimble_netif_conn_t::state
uint16_t state
the current state of the context
Definition: nimble_netif_conn.h:44
nimble_netif_conn_get
nimble_netif_conn_t * nimble_netif_conn_get(int handle)
Get the connection context corresponding to the given handle.
nimble_netif_conn_iter_t
int(* nimble_netif_conn_iter_t)(nimble_netif_conn_t *conn, int handle, void *arg)
Iterator function signature used by nimble_netif_conn_foreach()
Definition: nimble_netif_conn.h:59
nimble_netif_conn_get_next
int nimble_netif_conn_get_next(int handle, uint16_t filter)
Find the next context that matches the filter condition.
nimble_netif_conn_get_adv
int nimble_netif_conn_get_adv(void)
Get the handle to the context that is currently advertising.
nimble_netif_conn_t::gaphandle
uint16_t gaphandle
GAP handle exposed by NimBLE.
Definition: nimble_netif_conn.h:43
NIMBLE_NETIF_CONN_INVALID
#define NIMBLE_NETIF_CONN_INVALID
Value for marking a handle invalid.
Definition: nimble_netif_conn.h:36
nimble_netif_conn_get_connecting
int nimble_netif_conn_get_connecting(void)
Get the handle to the context that is busy connecting.
nimble_netif_conn_get_by_addr
int nimble_netif_conn_get_by_addr(const uint8_t *addr)
Find the connection to the peer with the given BLE address.
BLE_ADDR_LEN
#define BLE_ADDR_LEN
link layer address length
Definition: ble.h:43
nimble_netif_conn_start_connection
int nimble_netif_conn_start_connection(const uint8_t *addr)
Allocate an unused context for starting a connection.
nimble_netif_conn_foreach
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.
nimble_netif_conn_t
Memory layout for holding the relevant connection information.
Definition: nimble_netif_conn.h:41