nimble_netif.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-2021 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 
66 #ifndef NIMBLE_NETIF_H
67 #define NIMBLE_NETIF_H
68 
69 #include <stdint.h>
70 #include <errno.h>
71 
72 #include "net/ble.h"
73 #include "nimble_riot.h"
74 
75 #include "host/ble_hs.h"
76 
77 #ifdef __cplusplus
78 extern "C" {
79 #endif
80 
86 #ifndef NIMBLE_NETIF_MAX_CONN
87 #define NIMBLE_NETIF_MAX_CONN (MYNEWT_VAL_BLE_MAX_CONNECTIONS)
88 #endif
89 
93 #ifndef NIMBLE_NETIF_CID
94 #define NIMBLE_NETIF_CID (BLE_L2CAP_CID_IPSP)
95 #endif
96 
100 /* NOTE: We do not use the @ref IPV6_MIN_MTU define here, as the iov6.h header
101  pulls in some other RIOT headers that clash with NimBLE header (e.g.
102  * byteorder.h vs. endian.h) */
103 #ifndef NIMBLE_NETIF_MTU
104 #define NIMBLE_NETIF_MTU (1280U)
105 #endif
106 
111 enum {
115 };
116 
120 typedef struct {
121  uint8_t flags;
122  uint8_t channel_map;
123  uint8_t own_addr_type;
124  int8_t tx_power;
125  uint32_t adv_itvl_ms;
126  uint32_t timeout_ms;
130 
134 typedef struct {
135  uint16_t scan_itvl_ms;
136  uint16_t scan_window_ms;
137  uint16_t conn_itvl_min_ms;
138  uint16_t conn_itvl_max_ms;
141  uint32_t timeout_ms;
143  uint8_t phy_mode;
144  uint8_t own_addr_type;
146 
169 #ifndef NIMBLE_NETIF_CONN_ITVL_SPACING
170 #define NIMBLE_NETIF_CONN_ITVL_SPACING 0
171 #endif
172 
176 typedef enum {
189 
193 enum {
200  NIMBLE_NETIF_ADV = 0x0100,
203  NIMBLE_NETIF_ANY = 0xffff,
204 };
205 
215 typedef void(*nimble_netif_eventcb_t)(int handle,
217  const uint8_t *addr);
218 
225 void nimble_netif_init(void);
226 
235 
251 int nimble_netif_connect(const ble_addr_t *addr,
252  const nimble_netif_connect_cfg_t *cfg);
253 
264 int nimble_netif_close(int handle);
265 
279 int nimble_netif_accept(const uint8_t *ad, size_t ad_len,
280  const nimble_netif_accept_cfg_t *cfg);
281 
295 int nimble_netif_accept_direct(const ble_addr_t *addr,
296  const nimble_netif_accept_cfg_t *cfg);
297 
306 
317 int nimble_netif_update(int handle,
318  const struct ble_gap_upd_params *conn_params);
319 
333 int nimble_netif_used_chanmap(int handle, uint8_t map[5]);
334 
335 #ifdef __cplusplus
336 }
337 #endif
338 
339 #endif /* NIMBLE_NETIF_H */
nimble_phy_t
BLE PHY modes.
Definition: nimble_riot.h:75
int nimble_netif_accept_direct(const ble_addr_t *addr, const nimble_netif_accept_cfg_t *cfg)
Wait for an incoming connection from a specific peer, sending directed advertisements.
int nimble_netif_update(int handle, const struct ble_gap_upd_params *conn_params)
Update the connection parameters for the given connection.
void nimble_netif_init(void)
Initialize the netif implementation, spawns the netif thread.
int nimble_netif_accept(const uint8_t *ad, size_t ad_len, const nimble_netif_accept_cfg_t *cfg)
Accept incoming connections by starting to advertise this node.
void nimble_netif_eventcb(nimble_netif_eventcb_t cb)
Register a global event callback, servicing all NimBLE connections.
int nimble_netif_accept_stop(void)
Stop accepting incoming connections (stop advertising) *.
int nimble_netif_close(int handle)
Close the connection with the given handle.
int nimble_netif_used_chanmap(int handle, uint8_t map[5])
Get the currently used channel map for the given connection as bitmap.
void(* nimble_netif_eventcb_t)(int handle, nimble_netif_event_t event, const uint8_t *addr)
Event callback signature used for asynchronous event signaling.
Definition: nimble_netif.h:215
int nimble_netif_connect(const ble_addr_t *addr, const nimble_netif_connect_cfg_t *cfg)
Open a BLE connection as BLE master.
nimble_netif_event_t
Event types triggered by the NimBLE netif module.
Definition: nimble_netif.h:176
@ NIMBLE_NETIF_ADV
currently advertising
Definition: nimble_netif.h:200
@ NIMBLE_NETIF_L2CAP_CLIENT
L2CAP client.
Definition: nimble_netif.h:194
@ NIMBLE_NETIF_ANY
match any state
Definition: nimble_netif.h:203
@ NIMBLE_NETIF_L2CAP_CONNECTED
L2CAP is connected.
Definition: nimble_netif.h:196
@ NIMBLE_NETIF_GAP_SLAVE
GAP slave.
Definition: nimble_netif.h:198
@ NIMBLE_NETIF_GAP_MASTER
GAP master.
Definition: nimble_netif.h:197
@ NIMBLE_NETIF_CONNECTING
connection in progress
Definition: nimble_netif.h:201
@ NIMBLE_NETIF_UNUSED
context unused
Definition: nimble_netif.h:202
@ NIMBLE_NETIF_GAP_CONNECTED
GAP is connected.
Definition: nimble_netif.h:199
@ NIMBLE_NETIF_L2CAP_SERVER
L2CAP server.
Definition: nimble_netif.h:195
@ NIMBLE_NETIF_CONNECTED_MASTER
connection established as master
Definition: nimble_netif.h:181
@ NIMBLE_NETIF_ACCEPT_STOP
stop accepting incoming connections
Definition: nimble_netif.h:178
@ NIMBLE_NETIF_INIT_MASTER
conn.
Definition: nimble_netif.h:179
@ NIMBLE_NETIF_CONN_UPDATED
connection parameter update done
Definition: nimble_netif.h:187
@ NIMBLE_NETIF_CONNECTED_SLAVE
connection established as slave
Definition: nimble_netif.h:182
@ NIMBLE_NETIF_ABORT_MASTER
connection est.
Definition: nimble_netif.h:185
@ NIMBLE_NETIF_ACCEPTING
accepting incoming connections
Definition: nimble_netif.h:177
@ NIMBLE_NETIF_CLOSED_MASTER
connection closed (we were master)
Definition: nimble_netif.h:183
@ NIMBLE_NETIF_INIT_SLAVE
conn.
Definition: nimble_netif.h:180
@ NIMBLE_NETIF_CLOSED_SLAVE
connection closed (we were slave)
Definition: nimble_netif.h:184
@ NIMBLE_NETIF_ABORT_SLAVE
connection est.
Definition: nimble_netif.h:186
@ NIMBLE_NETIF_FLAG_HD_MODE
use high duty cycle mode, only valid for direct advertising
Definition: nimble_netif.h:113
@ NIMBLE_NETIF_FLAG_LEGACY
use legacy advertising mode
Definition: nimble_netif.h:112
RIOT specific glue functions for integrating NimBLE.
event structure
Definition: event.h:148
Parameter set used to configure accepting connections (advertising)
Definition: nimble_netif.h:120
uint32_t adv_itvl_ms
advertising interval [ms]
Definition: nimble_netif.h:125
uint32_t timeout_ms
stop accepting after this time [ms]
Definition: nimble_netif.h:126
nimble_phy_t primary_phy
primary PHY mode
Definition: nimble_netif.h:127
uint8_t channel_map
specify custom channel map
Definition: nimble_netif.h:122
int8_t tx_power
specify TX power to be used
Definition: nimble_netif.h:124
nimble_phy_t secondary_phy
secondary PHY mode
Definition: nimble_netif.h:128
uint8_t own_addr_type
specify our own address type to use
Definition: nimble_netif.h:123
Parameter set used to configure connection initiation.
Definition: nimble_netif.h:134
uint16_t conn_slave_latency
slave latency
Definition: nimble_netif.h:140
uint16_t scan_window_ms
scan window [ms]
Definition: nimble_netif.h:136
uint8_t own_addr_type
specify our own address type to use
Definition: nimble_netif.h:144
uint16_t conn_itvl_min_ms
connection interval, lower bound [ms]
Definition: nimble_netif.h:137
uint16_t conn_itvl_max_ms
connection interval, upper bound [ms]
Definition: nimble_netif.h:138
uint8_t phy_mode
PHY mode used for the connection.
Definition: nimble_netif.h:143
uint32_t timeout_ms
abort connection initiation after this time [ms]
Definition: nimble_netif.h:141
uint16_t conn_supervision_timeout_ms
supervision timeout [ms]
Definition: nimble_netif.h:139
uint16_t scan_itvl_ms
scan interval [ms]
Definition: nimble_netif.h:135
General BLE values as defined by the BT standard.