Commit graph

32 commits

Author SHA1 Message Date
dnlwgnd
e0d5fd4c3a
add ServiceData advertising element (#243)
* 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>
2024-03-18 22:15:09 +01:00
Ayke van Laethem
0087e0549b all: change ManufacturerData from a map to a slice
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.
2024-02-21 12:39:24 +01:00
Ayke van Laethem
d74f6a1009 all: add RequestConnectionParams to request new connection parameters
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.
2024-01-11 15:53:20 +01:00
Ayke van Laethem
5d805a929c all: use Device instead of Address in SetConnectHandler
This makes it possible to discover services on a connected central while
in peripheral mode, for example.
2024-01-11 15:53:20 +01:00
Ayke van Laethem
c9eafaff20 all: make Device a value instead of a pointer
This is a refactor that is necessary to make it easier to work with
connected central devices on a SoftDevice.
2024-01-11 15:53:20 +01:00
Ayke van Laethem
d77521461d linux: rewrite everything to use DBus directly
This is a big rewrite to use DBus calls directly instead of going
through go-bluetooth first.

This is a big change, but I believe it is an improvement. While the
go-bluetooth works for many cases, it's a layer in between that I
believe hurts more than it helps. Without it, we can just program
directly against the BlueZ D-Bus API. The end result is about 10% more
code.

With this rewrite, I fixed the following issues:

  * All MapToStruct warnings are gone, like in
    https://github.com/tinygo-org/bluetooth/issues/193.
  * Advertisements can be restarted after they were stopped. Previously
    this resulted in a panic.
  * Looking at the source code of go-bluetooth, it appears that it
    includes devices from a different Bluetooth adapter than the one
    that's currently scanning. This is fixed with the rewrite.
  * Fix a bug in Adapter.AddService where it would only allow adding a
    single service. Multiple services can now be added.
    This was actually the motivating bug that led me down to rewrite the
    whole thing because I couldn't figure out where the bug was in
    go-bluetooth (it's many layers deep).
  * The `WriteEvent` callback in a characteristic now also gets the
    'offset' parameter which wasn't provided by go-bluetooth.

This rewrite also avoids go-bluetooth specific workarounds like
https://github.com/tinygo-org/bluetooth/pull/74 and
https://github.com/tinygo-org/bluetooth/pull/121.

I have tested all examples in the smoketest-linux Makefile target. They
all still work with this rewrite.
2024-01-03 20:40:48 +01:00
Binozo
da2032de42 Added option to add ManufacturerData to Advertisement 2023-08-11 11:52:12 +02:00
Yurii Soldak
f9436906c1 all: go 1.18 and remove old-style build tags 2023-07-31 15:54:58 +02:00
Baden Parr
51dff6faa7 linux: implement disconnect handeling
linux: remove unnecessary sending of nil prop change  

linux: first pass at watching connection events


linux: remove unneeded debug prints


linux: fix spelling

linux: fix pointer address references
2023-05-04 14:02:39 +02:00
Ayke van Laethem
b06d666dbf all: remove Addresser
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.
2023-04-26 23:37:36 +02:00
deadprogram
79bbc2ed6d gap/linux: add helpful comment
Signed-off-by: deadprogram <ron@hybridgroup.com>
2022-09-29 10:49:08 +02:00
deadprogram
57f82b6241 gap/linux: workaround for https://github.com/muka/go-bluetooth/issues/163
Signed-off-by: deadprogram <ron@hybridgroup.com>
2022-09-29 10:49:08 +02:00
Jagoba Gascón
9b9512fbc9 advertising: add manufacturer data field to advertisement payload 2022-05-22 14:36:27 +02:00
Yurii Soldak
20f0ce6119 gap: stop advertising 2022-05-22 08:59:22 +02:00
Ayke van Laethem
96a2be1571 Add //go:build lines for Go 1.18
This will be needed eventually, so add them now already.
2022-04-19 11:00:08 +02:00
Linus Wallgren
c27b1cb3be Document async Disconnect behaviour
This was mentioned by @aykevl in https://github.com/tinygo-org/bluetooth/pull/32#issuecomment-698313299
2020-10-07 07:32:17 +02:00
deadprogram
a2662956b8 gap/all: add Disconnect() to Driver
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-09-24 14:30:13 +02:00
Ron Evans
6dc1dff711
gap: add connection handler to be called on adapter connect/disconnect
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-09-10 17:17:45 +02:00
deadprogram
ad6f45a730 linux: correct use of Addresser when scanning
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-09-03 15:26:43 +02:00
deadprogram
8bb26c24e6 gap: correct use of Address on Linux platform
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
ea7ed874af gap: switch to use MACAddress struct when possible for shared implementation
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ron Evans
c1114ad708 all: use Addresser interface to handle fact that macOS uses UUID instead of MAC as the BLE address for a peripheral
Signed-off-by: Ron Evans <ron@hybridgroup.com>
2020-09-02 08:37:04 +02:00
Ayke van Laethem
54cb2b25bb
linux: add GATT client support 2020-06-28 00:22:19 +02:00
Ayke van Laethem
602e656a6b
linux: improve scanning
By using the D-Bus APIs directly, I managed to avoid a deadlock that I
somehow couldn't work around with the go-bluetooth package.
2020-06-28 00:21:47 +02:00
Ayke van Laethem
8129f7e092
linux: include IsRandom bit in Address type
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.
2020-06-11 15:53:36 +02:00
Ayke van Laethem
e0314251c9
all: support HasServiceUUID on advertisement payloads
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.
2020-06-04 19:23:25 +02:00
Ayke van Laethem
d07cf38d66
all: distinguish between public and random addresses
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.
2020-06-04 14:12:14 +02:00
Ayke van Laethem
21100ebc19
all: add service UUIDs to advertisement packets
Support both 16-bit and 128-bit UUIDs on both Linux and Nordic chips.
2020-06-02 14:00:32 +02:00
Ayke van Laethem
c034fbca54
all: change NewAdvertisement to DefaultAdvertisement
Instead of attempting to allocate multiple advertisement instances, only
use one by default. If needed, a NewAdvertisement method could be added
in the future for devices that actually do support multiple
advertisements at a time.

The motivation for this change is fix an inconsistency with the nrf51
(which already had the behavior of DefaultAdvertisement) and the
discovery that nrf52 devices also don't seem to support more than one
advertisement instance, even though their API does allow for multiple
instances. But the primary motivation is that for consistency with
hosted systems, it would be best if the nrf port would automatically
re-enable advertisement when a connection is lost (or made).

While BlueZ does support more than one instance, it is implemented by
simply iterating through the active advertisement instances so could
also be implemented by doing that manually. I haven't checked the
behavior of Windows and MacOS - but as always, the API is not yet stable
and can be changed if needed.
2020-06-01 18:09:44 +02:00
Ayke van Laethem
086c797e0f
all: simplify advertisement configuration
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.
2020-06-01 14:20:34 +02:00
Ayke van Laethem
7a11ef8562
Add support for scanning for devices
There are some limitations, but it basically works (on both Linux and
nrf).
2020-05-28 11:57:02 +02:00
Ayke van Laethem
e453c4d3f9
Add Linux support
Very much experimental, no BLE service support yet and BLE LocalName in
advertisement packet doesn't seem to work. So rather useless at the
moment.
2019-11-09 17:55:19 +01:00