net: add Skald, a BLE advertising stack#8884
Conversation
cpu/nrf5x_common/include/nrfble.h
Outdated
| * | ||
| * @note This driver is not thread safe (as of now) | ||
| * | ||
|
|
cpu/nrf5x_common/include/nrfble.h
Outdated
| * @note This driver is not thread safe (as of now) | ||
| * | ||
|
|
||
| * @todo add support for netdev_ble_pkt_ext_t |
There was a problem hiding this comment.
Given that this will show up in the documentation, maybe some more detailed elaboration on what this means would be great.
There was a problem hiding this comment.
its outdated, removed.
cpu/nrf5x_common/include/nrfble.h
Outdated
| /** | ||
| * @brief Reference to the netdev driver interface | ||
| */ | ||
| extern const netdev_driver_t nrfble_netdev; |
There was a problem hiding this comment.
Does this actually need to be exposed? This is set by nrfble_setup() inside _nrfble_dev, and used nowhere else. Also, the name is confusing. How about nrfble_driver (even when you internalize it)?
cpu/nrf5x_common/include/nrfble.h
Outdated
| /** | ||
| * @brief Export the netdev device descriptor | ||
| */ | ||
| extern netdev_t nrfble_dev; |
There was a problem hiding this comment.
This doesn't have a corresponding internal definition. Also is this required to be public? nrfble_setup() returns a pointer to _nrfble_dev (which I assume to be the fragment this used to expose earlier (?))
| @@ -0,0 +1,357 @@ | |||
| /* | |||
| * Copyright (C) 2017 Freie Universität Berlin | |||
There was a problem hiding this comment.
nope, 2017-2018 :-)
| * | ||
| * # About | ||
| * This Skald module supports the creation and advertisement of BLE iBeacons as | ||
| * defined by Apple (see https://developer.apple.com/ibeacon/). |
There was a problem hiding this comment.
Same proposal here:
This Skald module supports the creation and advertisement of BLE [iBeacons](https://developer.apple.com/ibeacon/) as defined by Apple.There was a problem hiding this comment.
Actually I like the visibly printed link better, so I will leave it.
There was a problem hiding this comment.
the NACK was superfluous, github interface didn't show my first comment....
sys/net/skald/skald.c
Outdated
| /* advertise on the next adv channel - or skip this event if the radio is | ||
| * busy */ | ||
| if (_radio->context != NULL) { | ||
|
|
There was a problem hiding this comment.
Is there something missing here? Otherwise: the if is redundant.
There was a problem hiding this comment.
debugging leftover, removed.
| { | ||
| assert(buf); | ||
|
|
||
| luid_get(buf, BLE_ADDR_LEN); |
There was a problem hiding this comment.
AFAIK, BLE addresses are MAC addresses as defined in IEEE 802. Please at least set the universal/local bit to local and the individual/group bit to individual after calling this:
buf[0] &= 0x01;
buf[0] |= 0x02;| * | ||
| * @param[out] buf the generated address is written to this buffer | ||
| */ | ||
| void skald_generate_random_addr(uint8_t *buf); |
There was a problem hiding this comment.
random might not be a good term here, since the result of get_luid() is not random, but pretty predeterminable.
There was a problem hiding this comment.
but the bluetooth standard calls this type of address random.
sys/net/skald/skald_eddystone.c
Outdated
| pre_t pre; | ||
| uint8_t tx_pwr; | ||
| uint8_t scheme; | ||
| uint8_t url; |
There was a problem hiding this comment.
The URL is only one byte long? oO
There was a problem hiding this comment.
Nope, but this field is only used for its address.
There was a problem hiding this comment.
Maybe use url[] instead then to make this clearer. (additional benefit, you don't need the address operator & to get the pointer ;-)).
miri64
left a comment
There was a problem hiding this comment.
Some more doc stuff I noticed when browsing through the rendered doc.
cpu/nrf5x_common/include/nrfble.h
Outdated
| */ | ||
|
|
||
| /** | ||
| * @defgroup drivers_nrf5x_nrfble nRF BLE radio driver |
| uint32_t u32; /**< compact access */ | ||
| } aa; /**< access address */ | ||
| uint32_t crc; /**< CRC: 3 LSB for CRC, most | ||
| * significant bit for RX state*/ |
There was a problem hiding this comment.
Maybe use a top comment for that and while doing so, you can make a graphic (but don't have to):
/**
* @brief CRC and RX state
*
* 3 LSB for CRC, most significant bit for RX state (R, marks if the CRC is
* correct):
*
* 3 2 1 0
* 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |R| reserved | CRC |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
sys/include/net/ble.h
Outdated
| */ | ||
|
|
||
| /** | ||
| * @defgroup net_ble General BLE defines |
There was a problem hiding this comment.
I think "Bluetooth Low Energy (BLE)" is easier to find in the list of modules. At least I wouldn't search under "G" for the Bluetooth definitions ;-)
There was a problem hiding this comment.
I don't use the word 'bluetooth' anywhere on purpose, as I am not clear on the copyright/usage rights on that word and I have the dimm memory that there was trouble for others in the past using that word without the ok of the bluetooth SIG
| #endif | ||
|
|
||
| /** | ||
| * @name BT version constants |
sys/include/net/eddystone.h
Outdated
| */ | ||
|
|
||
| /** | ||
| * @defgroup net_eddystone Eddystone Constants |
There was a problem hiding this comment.
Drop the "Constants" for the group name.
sys/include/net/eddystone.h
Outdated
| * @name URL scheme prefix values | ||
| * @{ | ||
| */ | ||
| #define EDDYSTONE_URL_HTTP_WWW (0x00) /**< http://www.URL */ |
There was a problem hiding this comment.
use ` around these URLs here and below:
/**< `http://www.URL` */Doxygen interprets these as valid URLs (which leads to nowhere of course) with the current usage.
sys/include/net/skald.h
Outdated
| * @brief Generate a random public address | ||
| * | ||
| * @todo Make sure resulting address does not conflict with and assigned | ||
| * vendor prefix (however we will do that..) |
There was a problem hiding this comment.
That is guaranteed, when you set the universal/local bit to local ;-).
sys/include/net/skald/eddystone.h
Outdated
| */ | ||
|
|
||
| /** | ||
| * @defgroup net_skald_ Skald meets Eddy |
sys/include/net/skald/eddystone.h
Outdated
| */ | ||
|
|
||
| /** | ||
| * @defgroup net_skald_ Skald meets Eddy |
There was a problem hiding this comment.
(but maybe I missed the joke here ;-))
|
Noticed during testing: README (can be an adjusted copy of what you wrote in OP IMHO) for the examples is missing. |
|
General comment (sorry): I am very happy with this BLE initiative but I don't like the skald name. It think that it doesn't means anything regarding ble. Why not simply using ble_advertising ? The name is longer but way more explicit. Actually, we have the same problem with If those 2 projects (skald and emcute) were external libraries imported as packages, it would have been perfectly fine but since they are designed as implementation of standard protocols within RIOT (and with respect to highly constrained devices), they should use the standard names. |
|
I completely disagree regarding the name(s)! Naming an implementation after the protocol it implements is IMHO not a good idea - especially in the field of contrained devices where there is a tendency to have multiple implementations with different scopes! And who says that And in the end I am the author, and I insist on this name :-) |
Then they should be provided as external libraries. Implementation contributed into RIOT should use standard names and try to implement in a standard (whatever this means).
Indeed, but the problem is that they hide the underlying features instead of advertising them. I think I already said to someone asking if RIOT has support for MQTT that the example application was called emcute. Reply: "Ah ok, I missed it" |
|
Tested on |
I think this is more a matter of documentation than of naming. |
|
But why is |
|
@miri64 are you sufficiently happy with the doc now? I know its not perfect (yet), but considering this being a completely new feature (with a high probability of significant structural changes), I tend to rather let this module settle a bit before detailing out the doc to a 'perfect' state... |
+1 |
miri64
left a comment
There was a problem hiding this comment.
One minor thing left that I think can be improved code-wise (see last comment in this review). Otherwise, I think you can squash.
| uint8_t flags; /**< header flags */ | ||
| uint8_t len; /**< actual length of PDU */ | ||
| uint8_t pdu[NETDEV_BLE_PDU_MAXLEN]; /**< protocol data unit (PDU) */ | ||
| } netdev_ble_pkt_t; |
There was a problem hiding this comment.
Fine then let's keep it here for now. But when we finalize this API, I think it would still be better to move it somewhere else.
| uint32_t crc; /**< CRC: 3 LSB for CRC, most | ||
| * significant bit for RX state*/ | ||
| uint8_t chan; /**< channel to use/used */ | ||
| } netdev_ble_ctx_t; |
| #endif | ||
|
|
||
| /** | ||
| * @name BT version constants |
| * | ||
| * @param[out] buf the generated address is written to this buffer | ||
| */ | ||
| void skald_generate_random_addr(uint8_t *buf); |
sys/net/skald/skald_eddystone.c
Outdated
| pre_t pre; | ||
| uint8_t tx_pwr; | ||
| uint8_t scheme; | ||
| uint8_t url; |
There was a problem hiding this comment.
Maybe use url[] instead then to make this clearer. (additional benefit, you don't need the address operator & to get the pointer ;-)).
Just give the application a meaningful name, e.g. mqtt-sn, ble-eddystone, ble-ibeacon and everything will be fine. Personally (and I'm sure I'm not the only one), I will be very difficult to convince with the name skald. This name inspires nothing related to ble, even |
Very subjective... I guess we agree to not agree on the naming thing, but as the original author I think I have the right to chose a name to my liking :-) |
|
@miri64 for some reason I don't seem to be allowed to comment on your last review comments...
fixed. |
|
my pleasure :-) |
|
Ah, the |
Skald is a very small and simple, TX-only BLE stack that supports sending advertisements only. It is useful for building all kinds of BLE beacons with very minimal memory footprints.
fixed and squashed right in |
|
And go. |
|
Thanks for the quick review! This makes is much easier to continue the actual BLE work :-) |
Documentation of the option types was clarified in RIOT-OS#8655. I only noticed after merging RIOT-OS#8884, that `NETOPT_BLE_CTX` was not documented using that new style. So I deliver the change myself to make it quicker.
| */ | ||
| NETOPT_TX_RETRIES_NEEDED, | ||
|
|
||
| NETOPT_BLE_CTX, /**< set radio context (channel, CRC, AA) */ |
|
awesome ;) |
Documentation of the option types was clarified in RIOT-OS#8655. I only noticed after merging RIOT-OS#8884, that `NETOPT_BLE_CTX` was not documented using that new style. So I deliver the change myself to make it quicker.
Documentation of the option types was clarified in RIOT-OS#8655. I only noticed after merging RIOT-OS#8884, that `NETOPT_BLE_CTX` was not documented using that new style. So I deliver the change myself to make it quicker.
Documentation of the option types was clarified in RIOT-OS#8655. I only noticed after merging RIOT-OS#8884, that `NETOPT_BLE_CTX` was not documented using that new style. So I deliver the change myself to make it quicker.
Documentation of the option types was clarified in RIOT-OS#8655. I only noticed after merging RIOT-OS#8884, that `NETOPT_BLE_CTX` was not documented using that new style. So I deliver the change myself to make it quicker.


Contribution description
This PR adds
Skaldto RIOT, a BLE advertising stack written from scratch.Skaldis focused on the BLE broadcaster role only, but for this he is extremely small, allowing for very memory efficient implementation of all kind of BLE beacons (e.g. a iBeacon takes ~5k ROM with everything).Currently,
Skaldsupports Apple'siBeacons, Google'sEddystonebeacons, and sending out customGAPpayloads.This PR also contains a
netdevtailoring for using BLE radios, as well as a BLE radio driver implementation for thenrf5xfamily of devices.Note: currently only the
nrf52dkis supported (and tested), other platforms will be added step-by-stepTesting
iBeaconor theEddystoneexample on anrf52dknRF ConnectApp (for Android or iOS). Alternatively you can use a Bluetooth 4.0 capable Linux and use Bluezhcitools... Or something else...Issues/PRs references
Skaldis a spin-off of my current BLE implementation efforts, a full BLE stack will follow soon...