ble.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017-2018 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 
77 #ifndef NET_NETDEV_BLE_H
78 #define NET_NETDEV_BLE_H
79 
80 #include "net/netdev.h"
81 
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
85 
89 #define NETDEV_BLE_PDU_MAXLEN (37U)
90 
94 #define NETDEV_BLE_CRC_MASK (0x00ffffff)
95 
99 #define NETDEV_BLE_CRC_OK (0x80000000)
100 
104 typedef struct __attribute__((packed)) {
105  uint8_t flags;
106  uint8_t len;
107  uint8_t pdu[NETDEV_BLE_PDU_MAXLEN];
109 
113 typedef struct {
114  union {
115  uint8_t raw[4];
116  uint32_t u32;
117  } aa;
118  uint32_t crc;
120  uint8_t chan;
122 
141 static inline int netdev_ble_send(netdev_t *dev, netdev_ble_pkt_t *pkt)
142 {
143  struct iolist data = { NULL, pkt, sizeof(netdev_ble_pkt_t) };
144  return dev->driver->send(dev, &data);
145 }
146 
166 static inline int netdev_ble_recv(netdev_t *dev, netdev_ble_pkt_t *pkt)
167 {
168  return dev->driver->recv(dev, pkt, sizeof(netdev_ble_pkt_t), NULL);
169 }
170 
177 static inline void netdev_ble_set_ctx(netdev_t *dev, netdev_ble_ctx_t *ctx)
178 {
179  dev->driver->set(dev, NETOPT_BLE_CTX, ctx, sizeof(netdev_ble_ctx_t));
180 }
181 
190 static inline void netdev_ble_stop(netdev_t *dev)
191 {
192  dev->driver->set(dev, NETOPT_BLE_CTX, NULL, 0);
193 }
194 
195 #ifdef __cplusplus
196 }
197 #endif
198 
199 #endif /* NET_NETDEV_BLE_H */
200 
netdev_driver::send
int(* send)(netdev_t *dev, const iolist_t *iolist)
Send frame.
Definition: netdev.h:360
netdev::driver
const struct netdev_driver * driver
ptr to that driver's interface.
Definition: netdev.h:303
netdev_ble_pkt_t::len
uint8_t len
actual length of PDU
Definition: ble.h:106
netdev_ble_set_ctx
static void netdev_ble_set_ctx(netdev_t *dev, netdev_ble_ctx_t *ctx)
Set the radio context for the given radio device.
Definition: ble.h:177
netdev_ble_recv
static int netdev_ble_recv(netdev_t *dev, netdev_ble_pkt_t *pkt)
Start listening for an incoming packet and write it into pkt.
Definition: ble.h:166
netdev_driver::set
int(* set)(netdev_t *dev, netopt_t opt, const void *value, size_t value_len)
Set an option value for a given network device.
Definition: netdev.h:476
netdev_driver::recv
int(* recv)(netdev_t *dev, void *buf, size_t len, void *info)
Drop a received frame, OR get the length of a received frame, OR get a received frame.
Definition: netdev.h:397
netdev_ble_ctx_t::chan
uint8_t chan
channel to use/used
Definition: ble.h:120
netdev_ble_ctx_t::crc
uint32_t crc
CRC: 3 LSB for CRC, most significant bit for RX state.
Definition: ble.h:118
netdev_ble_pkt_t::flags
uint8_t flags
header flags
Definition: ble.h:105
netdev.h
Definitions low-level network driver interface.
iolist
iolist structure definition
Definition: iolist.h:39
NETOPT_BLE_CTX
@ NETOPT_BLE_CTX
(netdev_ble_ctx_t) set BLE radio context (channel, CRC, AA)
Definition: netopt.h:575
netdev
Structure to hold driver state.
Definition: netdev.h:302
netdev_ble_stop
static void netdev_ble_stop(netdev_t *dev)
Stop the ongoing RX/TX sequence.
Definition: ble.h:190
netdev_ble_ctx_t::u32
uint32_t u32
compact access
Definition: ble.h:116
NETDEV_BLE_PDU_MAXLEN
#define NETDEV_BLE_PDU_MAXLEN
Maximum payload length of a standard BLE packet.
Definition: ble.h:89
netdev_ble_send
static int netdev_ble_send(netdev_t *dev, netdev_ble_pkt_t *pkt)
Send the given packet on the next occasion.
Definition: ble.h:141
netdev_ble_pkt_t
BLE packet structure (as defined by the BLE standard)
Definition: ble.h:104
netdev_ble_ctx_t
Radio context.
Definition: ble.h:113