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 
9 #pragma once
10 
79 #include "net/netdev.h"
80 
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84 
88 #define NETDEV_BLE_PDU_MAXLEN (37U)
89 
93 #define NETDEV_BLE_CRC_MASK (0x00ffffff)
94 
98 #define NETDEV_BLE_CRC_OK (0x80000000)
99 
103 typedef struct __attribute__((packed)) {
104  uint8_t flags;
105  uint8_t len;
106  uint8_t pdu[NETDEV_BLE_PDU_MAXLEN];
108 
112 typedef struct {
113  union {
114  uint8_t raw[4];
115  uint32_t u32;
116  } aa;
117  uint32_t crc;
119  uint8_t chan;
121 
140 static inline int netdev_ble_send(netdev_t *dev, netdev_ble_pkt_t *pkt)
141 {
142  struct iolist data = { NULL, pkt, sizeof(netdev_ble_pkt_t) };
143  return dev->driver->send(dev, &data);
144 }
145 
165 static inline int netdev_ble_recv(netdev_t *dev, netdev_ble_pkt_t *pkt)
166 {
167  return dev->driver->recv(dev, pkt, sizeof(netdev_ble_pkt_t), NULL);
168 }
169 
176 static inline void netdev_ble_set_ctx(netdev_t *dev, netdev_ble_ctx_t *ctx)
177 {
178  dev->driver->set(dev, NETOPT_BLE_CTX, ctx, sizeof(netdev_ble_ctx_t));
179 }
180 
189 static inline void netdev_ble_stop(netdev_t *dev)
190 {
191  dev->driver->set(dev, NETOPT_BLE_CTX, NULL, 0);
192 }
193 
194 #ifdef __cplusplus
195 }
196 #endif
197 
Definitions low-level network driver interface.
#define NETDEV_BLE_PDU_MAXLEN
Maximum payload length of a standard BLE packet.
Definition: ble.h:88
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:165
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:176
static int netdev_ble_send(netdev_t *dev, netdev_ble_pkt_t *pkt)
Send the given packet on the next occasion.
Definition: ble.h:140
static void netdev_ble_stop(netdev_t *dev)
Stop the ongoing RX/TX sequence.
Definition: ble.h:189
@ NETOPT_BLE_CTX
(netdev_ble_ctx_t) set BLE radio context (channel, CRC, AA)
Definition: netopt.h:579
iolist structure definition
Definition: iolist.h:38
Radio context.
Definition: ble.h:112
uint32_t u32
compact access
Definition: ble.h:115
uint32_t crc
CRC: 3 LSB for CRC, most significant bit for RX state.
Definition: ble.h:117
uint8_t chan
channel to use/used
Definition: ble.h:119
BLE packet structure (as defined by the BLE standard)
Definition: ble.h:103
uint8_t len
actual length of PDU
Definition: ble.h:105
uint8_t flags
header flags
Definition: ble.h:104
int(* send)(netdev_t *dev, const iolist_t *iolist)
Start transmission of the given frame and return directly.
Definition: netdev.h:461
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:609
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:530
Structure to hold driver state.
Definition: netdev.h:364
const struct netdev_driver * driver
ptr to that driver's interface.
Definition: netdev.h:365