Loading...
Searching...
No Matches
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
83extern "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
104typedef struct __attribute__((packed)) {
105 uint8_t flags;
106 uint8_t len;
109
113typedef struct {
114 union {
115 uint8_t raw[4];
116 uint32_t u32;
117 } aa;
118 uint32_t crc;
120 uint8_t chan;
122
141static 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
166static 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
177static 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
190static 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 */
Definitions low-level network driver interface.
#define NETDEV_BLE_PDU_MAXLEN
Maximum payload length of a standard BLE packet.
Definition ble.h:89
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
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
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
static void netdev_ble_stop(netdev_t *dev)
Stop the ongoing RX/TX sequence.
Definition ble.h:190
@ NETOPT_BLE_CTX
(netdev_ble_ctx_t) set BLE radio context (channel, CRC, AA)
Definition netopt.h:580
iolist structure definition
Definition iolist.h:39
Radio context.
Definition ble.h:113
uint32_t u32
compact access
Definition ble.h:116
uint32_t crc
CRC: 3 LSB for CRC, most significant bit for RX state.
Definition ble.h:118
uint8_t chan
channel to use/used
Definition ble.h:120
BLE packet structure (as defined by the BLE standard)
Definition ble.h:104
uint8_t len
actual length of PDU
Definition ble.h:106
uint8_t flags
header flags
Definition ble.h:105
int(* send)(netdev_t *dev, const iolist_t *iolist)
Start transmission of the given frame and return directly.
Definition netdev.h:462
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:610
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:531
Structure to hold driver state.
Definition netdev.h:365
const struct netdev_driver * driver
ptr to that driver's interface.
Definition netdev.h:366