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 
9 #pragma once
10 
68 #include <stdint.h>
69 #include <errno.h>
70 
71 #include "net/ble.h"
72 #include "nimble_riot.h"
73 
74 #include "host/ble_hs.h"
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
85 #ifndef NIMBLE_NETIF_MAX_CONN
86 #define NIMBLE_NETIF_MAX_CONN (MYNEWT_VAL_BLE_MAX_CONNECTIONS)
87 #endif
88 
92 #ifndef NIMBLE_NETIF_CID
93 #define NIMBLE_NETIF_CID (BLE_L2CAP_CID_IPSP)
94 #endif
95 
99 /* NOTE: We do not use the @ref IPV6_MIN_MTU define here, as the iov6.h header
100  pulls in some other RIOT headers that clash with NimBLE header (e.g.
101  * byteorder.h vs. endian.h) */
102 #ifndef NIMBLE_NETIF_MTU
103 #define NIMBLE_NETIF_MTU (1280U)
104 #endif
105 
110 enum {
114 };
115 
119 typedef struct {
120  uint8_t flags;
121  uint8_t channel_map;
122  uint8_t own_addr_type;
123  int8_t tx_power;
124  uint32_t adv_itvl_ms;
125  uint32_t timeout_ms;
129 
133 typedef struct {
134  uint16_t scan_itvl_ms;
135  uint16_t scan_window_ms;
136  uint16_t conn_itvl_min_ms;
137  uint16_t conn_itvl_max_ms;
140  uint32_t timeout_ms;
142  uint8_t phy_mode;
143  uint8_t own_addr_type;
145 
168 #ifndef NIMBLE_NETIF_CONN_ITVL_SPACING
169 #define NIMBLE_NETIF_CONN_ITVL_SPACING 0
170 #endif
171 
175 typedef enum {
188 
192 enum {
199  NIMBLE_NETIF_ADV = 0x0100,
202  NIMBLE_NETIF_ANY = 0xffff,
203 };
204 
214 typedef void(*nimble_netif_eventcb_t)(int handle,
216  const uint8_t *addr);
217 
224 void nimble_netif_init(void);
225 
234 
250 int nimble_netif_connect(const ble_addr_t *addr,
251  const nimble_netif_connect_cfg_t *cfg);
252 
263 int nimble_netif_close(int handle);
264 
278 int nimble_netif_accept(const uint8_t *ad, size_t ad_len,
279  const nimble_netif_accept_cfg_t *cfg);
280 
294 int nimble_netif_accept_direct(const ble_addr_t *addr,
295  const nimble_netif_accept_cfg_t *cfg);
296 
305 
316 int nimble_netif_update(int handle,
317  const struct ble_gap_upd_params *conn_params);
318 
332 int nimble_netif_used_chanmap(int handle, uint8_t map[5]);
333 
334 #ifdef __cplusplus
335 }
336 #endif
337 
nimble_phy_t
BLE PHY modes.
Definition: nimble_riot.h:73
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:214
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:175
@ NIMBLE_NETIF_ADV
currently advertising
Definition: nimble_netif.h:199
@ NIMBLE_NETIF_L2CAP_CLIENT
L2CAP client.
Definition: nimble_netif.h:193
@ NIMBLE_NETIF_ANY
match any state
Definition: nimble_netif.h:202
@ NIMBLE_NETIF_L2CAP_CONNECTED
L2CAP is connected.
Definition: nimble_netif.h:195
@ NIMBLE_NETIF_GAP_SLAVE
GAP slave.
Definition: nimble_netif.h:197
@ NIMBLE_NETIF_GAP_MASTER
GAP master.
Definition: nimble_netif.h:196
@ NIMBLE_NETIF_CONNECTING
connection in progress
Definition: nimble_netif.h:200
@ NIMBLE_NETIF_UNUSED
context unused
Definition: nimble_netif.h:201
@ NIMBLE_NETIF_GAP_CONNECTED
GAP is connected.
Definition: nimble_netif.h:198
@ NIMBLE_NETIF_L2CAP_SERVER
L2CAP server.
Definition: nimble_netif.h:194
@ NIMBLE_NETIF_FLAG_HD_MODE
use high duty cycle mode, only valid for direct advertising
Definition: nimble_netif.h:112
@ NIMBLE_NETIF_FLAG_LEGACY
use legacy advertising mode
Definition: nimble_netif.h:111
@ NIMBLE_NETIF_CONNECTED_MASTER
connection established as master
Definition: nimble_netif.h:180
@ NIMBLE_NETIF_ACCEPT_STOP
stop accepting incoming connections
Definition: nimble_netif.h:177
@ NIMBLE_NETIF_INIT_MASTER
conn.
Definition: nimble_netif.h:178
@ NIMBLE_NETIF_CONN_UPDATED
connection parameter update done
Definition: nimble_netif.h:186
@ NIMBLE_NETIF_CONNECTED_SLAVE
connection established as slave
Definition: nimble_netif.h:181
@ NIMBLE_NETIF_ABORT_MASTER
connection est.
Definition: nimble_netif.h:184
@ NIMBLE_NETIF_ACCEPTING
accepting incoming connections
Definition: nimble_netif.h:176
@ NIMBLE_NETIF_CLOSED_MASTER
connection closed (we were master)
Definition: nimble_netif.h:182
@ NIMBLE_NETIF_INIT_SLAVE
conn.
Definition: nimble_netif.h:179
@ NIMBLE_NETIF_CLOSED_SLAVE
connection closed (we were slave)
Definition: nimble_netif.h:183
@ NIMBLE_NETIF_ABORT_SLAVE
connection est.
Definition: nimble_netif.h:185
RIOT specific glue functions for integrating NimBLE.
event structure
Definition: event.h:145
Parameter set used to configure accepting connections (advertising)
Definition: nimble_netif.h:119
uint32_t adv_itvl_ms
advertising interval [ms]
Definition: nimble_netif.h:124
uint32_t timeout_ms
stop accepting after this time [ms]
Definition: nimble_netif.h:125
nimble_phy_t primary_phy
primary PHY mode
Definition: nimble_netif.h:126
uint8_t channel_map
specify custom channel map
Definition: nimble_netif.h:121
int8_t tx_power
specify TX power to be used
Definition: nimble_netif.h:123
nimble_phy_t secondary_phy
secondary PHY mode
Definition: nimble_netif.h:127
uint8_t own_addr_type
specify our own address type to use
Definition: nimble_netif.h:122
Parameter set used to configure connection initiation.
Definition: nimble_netif.h:133
uint16_t conn_slave_latency
slave latency
Definition: nimble_netif.h:139
uint16_t scan_window_ms
scan window [ms]
Definition: nimble_netif.h:135
uint8_t own_addr_type
specify our own address type to use
Definition: nimble_netif.h:143
uint16_t conn_itvl_min_ms
connection interval, lower bound [ms]
Definition: nimble_netif.h:136
uint16_t conn_itvl_max_ms
connection interval, upper bound [ms]
Definition: nimble_netif.h:137
uint8_t phy_mode
PHY mode used for the connection.
Definition: nimble_netif.h:142
uint32_t timeout_ms
abort connection initiation after this time [ms]
Definition: nimble_netif.h:140
uint16_t conn_supervision_timeout_ms
supervision timeout [ms]
Definition: nimble_netif.h:138
uint16_t scan_itvl_ms
scan interval [ms]
Definition: nimble_netif.h:134
General BLE values as defined by the BT standard.