Loading...
Searching...
No Matches
ble.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017-2018 Freie Universität Berlin
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
75
76#include "net/netdev.h"
77
78#ifdef __cplusplus
79extern "C" {
80#endif
81
85#define NETDEV_BLE_PDU_MAXLEN (37U)
86
90#define NETDEV_BLE_CRC_MASK (0x00ffffff)
91
95#define NETDEV_BLE_CRC_OK (0x80000000)
96
100typedef struct __attribute__((packed)) {
101 uint8_t flags;
102 uint8_t len;
105
109typedef struct {
110 union {
111 uint8_t raw[4];
112 uint32_t u32;
113 } aa;
114 uint32_t crc;
116 uint8_t chan;
118
137static inline int netdev_ble_send(netdev_t *dev, netdev_ble_pkt_t *pkt)
138{
139 struct iolist data = { NULL, pkt, sizeof(netdev_ble_pkt_t) };
140 return dev->driver->send(dev, &data);
141}
142
162static inline int netdev_ble_recv(netdev_t *dev, netdev_ble_pkt_t *pkt)
163{
164 return dev->driver->recv(dev, pkt, sizeof(netdev_ble_pkt_t), NULL);
165}
166
173static inline void netdev_ble_set_ctx(netdev_t *dev, netdev_ble_ctx_t *ctx)
174{
175 dev->driver->set(dev, NETOPT_BLE_CTX, ctx, sizeof(netdev_ble_ctx_t));
176}
177
186static inline void netdev_ble_stop(netdev_t *dev)
187{
188 dev->driver->set(dev, NETOPT_BLE_CTX, NULL, 0);
189}
190
191#ifdef __cplusplus
192}
193#endif
194
Definitions low-level network driver interface.
struct netdev netdev_t
Forward declaration for netdev struct.
Definition netdev.h:285
#define NETDEV_BLE_PDU_MAXLEN
Maximum payload length of a standard BLE packet.
Definition ble.h:85
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:162
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:173
static int netdev_ble_send(netdev_t *dev, netdev_ble_pkt_t *pkt)
Send the given packet on the next occasion.
Definition ble.h:137
static void netdev_ble_stop(netdev_t *dev)
Stop the ongoing RX/TX sequence.
Definition ble.h:186
@ NETOPT_BLE_CTX
(netdev_ble_ctx_t) set BLE radio context (channel, CRC, AA)
Definition netopt.h:586
iolist structure definition
Definition iolist.h:38
Radio context.
Definition ble.h:109
uint32_t u32
compact access
Definition ble.h:112
uint32_t crc
CRC: 3 LSB for CRC, most significant bit for RX state.
Definition ble.h:114
uint8_t raw[4]
byte-wise access
Definition ble.h:111
uint8_t chan
channel to use/used
Definition ble.h:116
BLE packet structure (as defined by the BLE standard)
Definition ble.h:100
uint8_t len
actual length of PDU
Definition ble.h:102
uint8_t pdu[NETDEV_BLE_PDU_MAXLEN]
protocol data unit (PDU)
Definition ble.h:103
uint8_t flags
header flags
Definition ble.h:101
const struct netdev_driver * driver
ptr to that driver's interface.
Definition netdev.h:363