Commit graph

28 commits

Author SHA1 Message Date
Ayke van Laethem
c26c9d5630 gap: fix ServiceDataElement.UUID comment
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.
2024-05-25 17:18:48 +02:00
Lars Gohr
abbb565ef0
Improve documentation of RSSI
Fixes https://github.com/tinygo-org/bluetooth/issues/272
2024-05-21 21:04:24 +02:00
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
Binozo
d5276e5aed added manufacturer data support on SoftDevices 2023-08-11 11:52:12 +02:00
Binozo
da2032de42 Added option to add ManufacturerData to Advertisement 2023-08-11 11:52:12 +02:00
Ayke van Laethem
71f17598be gap: Set and SetRandom methods should have a pointer receiver
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.
2023-04-29 22:13:00 +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
Jagoba Gascón
9b9512fbc9 advertising: add manufacturer data field to advertisement payload 2022-05-22 14:36:27 +02:00
deadprogram
281d195e75 gap: change signature for Addresser interface Set() function to accept string and then parse it as needed
Signed-off-by: deadprogram <ron@hybridgroup.com>
2020-09-20 14:56:48 +02:00
Ayke van Laethem
633d9b5aea nrf: keep advertisement payload alive
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.
2020-09-16 17:20:05 +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
15b3e8e3e2
nrf: add GATT client
This is not entirely complete (some errors are not handled properly) but
it's a start.
2020-06-28 00:21:40 +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
ccb9c84db8
all: change advertisement interval type
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.
2020-06-06 20:47:05 +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
e1e010d8ec
all: update NewAdvertisementInterval to accept time.Duration
This makes the API a bit more natural and (if needed) allows for a
slightly greater precision in specifying the advertisement interval.
2020-06-04 16:55:53 +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
49f8082e4b
all: replace GAP events with auto-restarting advertisements
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.
2020-06-01 23:29:31 +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
Ayke van Laethem
1d44126ac9
gap: implement basic event handling: connect/disconnect 2019-11-09 13:50:00 +01:00
Ayke van Laethem
0cabe28570
Initial commit 2019-11-08 10:58:02 +01:00