Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

darwin: properly handle 16-bit UUIDs for service and characteristics #50

Merged
merged 1 commit into from
Feb 1, 2021

Conversation

deadprogram
Copy link
Member

This PR properly handles the 16-bit UUIDs for service and characteristics in the unique format used by macOS.

…in the unique format used by macOS

Signed-off-by: Ron Evans <ron@hybridgroup.com>
@deadprogram
Copy link
Member Author

Tested on both Catalina and Big Sur, so this seems ready to merge.

Comment on lines -24 to +18
d.prph.DiscoverServices(cbuuids)
d.prph.DiscoverServices([]cbgo.UUID{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you no longer passing the uuids slice to DiscoverServices? See the documentation:

Note

If the servicesUUIDs parameter is nil, this method returns all of the peripheral’s available services. This is much slower than providing an array of service UUIDs to search for.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not actually working, it seems. Not sure if that is because of cbgo or something else. I tried a whole bunch of different things but could not get it to work as documented.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is unfortunate. What if you put in a literal nil instead of []cbgo.UUID{}? (That's in fact semantically different, []cbgo.UUID{} is not equal to nil).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the source of cbgo that is unlikely to have an effect. I'm working on a possible patch to cbgo.

Copy link
Member

@aykevl aykevl Feb 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I was confused.
This is indeed rather unfortunate. Maybe you can raise a bug at the cbgo repository?

Comment on lines +10 to +13
uuid[0] = 0x00000000
uuid[1] = 0x00000000
uuid[2] = 0x00000000
uuid[3] = uint32(shortUUID) << 16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If MacOS uses this nonstandard format, then 🤷
It's a bit weird though, as the Bluetooth specification has clearly specified how to encode 16-bit UUIDs in a 128-bit UUID. Other platforms use that standard.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what is returned by cbgo, hence why I had to make these changes.

macOS does some various other things with anonymizing BLE info, but beats me why this is the case.

@aykevl
Copy link
Member

aykevl commented Feb 1, 2021

One alternative to consider to the change to New16BitUUID: keeping the 16-bit UUID the same as any platform but adding a special (uuid UUID) darwinUUID() cbgo.UUID function that internally converts 16-bit UUIDs to the special format used by CoreBluetooth, and similarly for parsing UUIDs coming from CoreBluetooth. You can use Is16Bit for the check. This might help to keep the API slightly more cross platform (so that New16BitUUID(value).String() is the same everywhere).

@deadprogram
Copy link
Member Author

I have submitted an issue into the cbgo repo @aykevl

In the meantime, I would prefer to not make any further changes to this PR unless absolutely needed. We can work on macOS further in future iterations.

@deadprogram deadprogram merged commit b4b1254 into dev Feb 1, 2021
@deadprogram deadprogram deleted the darwin-16bit-uuid branch February 1, 2021 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants