I can't find anything that says the service UUID can also be a company
UUID (though the UUID number ranges don't overlap, so it could be
possible). Maybe I'm wrong, considering the size of the Bluetooth
specification I could easily have missed something.
* gap: fix comment
* gap: expose ServiceData() in AdvertisementFields
* macos: include ServiceData in AdvertisementFields
* gap/linux: include ServiceData in AdvertisementFields
* gap: add unimplemented ServiceData() to raw advertisement
* added ServiceData advertising element also to the sending pieces
* more explicitly use the ad element type ids
* added a test case for ServiceData
* linux: added ServiceData advertising element
* sd: fix: handle no servicedata present
* linux: bluez uses string uuids for service data
* linux: fix: correct datatype for advertise with ServiceData
* uuid: add 32-Bit functions
* ServiceData now also uses a slice instead of a map as in #244
* Revert unnessesary changes
* formatting
* remove extra check
---------
Co-authored-by: William Johansson <radar@radhuset.org>
This is a breaking change, but I believe it is necessary for
correctness. Because maps have an undefined iteration order, the actual
advertised packet could change each time which I think is a bad thing.
In addition to that, using a slice should be much more lightweight than
using a map.
I've also added some tests (that should have been there in the first
place) and added some manufacturer data to the advertisement example.
Furthermore, I've optimized the code that constructs manufacturer data
for raw advertisement payloads, it should now be entirely free of heap
allocations.
This allows changing the connection latency, slave latency, and
connection timeout of an active connection - whether in the central or
peripheral role. This is especially helpful on battery operated BLE
devices that don't have a lot of power and need to lower the connection
latency for improved speed. It might also be useful for devices that
need high speed, as the defaults might be too low.
Without it, these calls are a no-op.
Fixes: https://github.com/tinygo-org/bluetooth/issues/144
In particular, this fixes a problem where IsRandom() would always return
false on Linux. With this fix, it correctly returns whether the address
is a random address.
Remove the Addresser type. It isn't really necessary (the Address type
can change between OSes) and makes it difficult to fix a heap allocation
in interrupts (on the Nordic SoftDevices).
This is a backwards incompatible change, but only programs that use
SetConnectHandler should notice this.
The memory from the advertisement payload must be kept alive until the
advertisement is stopped. Therefore, it is not allowed to use a local
variable for it. Instead, it is now part of the defaultAdvertisement
global which of course is alive as long as the program runs.
Unlike what I previously thought, BlueZ does expose it. Unfortunately it
doesn't seem to respect it: the bit is not included in D-Bus paths.
Windows also supports the bit, which I hope to fix in a future commit.
Like BlueZ, it appears to ignore it when connecting to a device.
Use a new Duration type, which is used throughout the BLE stack for
durations. The resolutions are sometimes different (connection
parameters have half the resolution) but overall it should improve the
ease of use of this type.
This commit also provides a default advertisement interval that is
recommended by Apple (which I think is as good as any recommendation).
This might help to speed up discovery by Apple (and Android?) phones.
I have intentionally chosen to implement HasServiceUUID() and not
ServiceUUIDs() because returning a slice of UUIDs will likely cause a
heap allocation. And perhaps the most common use may be checking whether
a packet has a particular UUID, so no list is necessary. Getting the
full list can of course be implemented in the future, if needed.
This is necessary when connecting to a device when using the SoftDevice.
The information is not set on Linux and Windows and is ignored on those
platform when connecting.
There used to be GAP events (connect/disconnect). The main purpose for
these events was to allow applications to re-start advertisement when a
connection was lost - on nrf. Unfortunately things work differently on
Linux, which already has this behavior and for which I haven't yet
implemented these events. Therefore I have removed these events and
instead added code to automatically restart advertisement on connection
loss.
Supporting multiple (incoming) connections as a peripheral would be
useful, but is not currently supported.
This changes the previous raw advertisement packets to structured
advertisement configuration. That means you can set the local name not
with a raw byte array but with a normal string.
While this departs a bit from the original low-level interface as is
often used on microcontroller BLE stacks, it is certainly easier to use
and better matches higher level APIs that are commonly provided by
general-purpose operating systems. If there is a need for raw BLE
packets (for baremetal systems only), this can easily be added in the
future.