0
votes

I have an app that communicates with a bluetooth device, and I'm trying to replace that app with some code.

I tried using C# InTheHand nuget, Microsoft's Bluetooth LE Explorer, python's sockets and others to send data and see what happens.

But there's something I still don't understand - in each way using different libraries I saw in wireshark a different protocol: ATT, RFCOMM, L2CAP...

When I sniffed my bluetooth traffic from my phone using the app mentioned before, I saw mostly HCI_CMD protocol traffic.

How can I choose the protocol I want to send? Is there a simple package for that? something to read?

Do I need to build the packet myself? including headers and such?

Thank you!

Update: Using Microsoft's Bluetooth LE Explorer I was able to send a packet that lit up my lamp, starting with 02010e10000c00040012(data)
Using bleak I was able to send a packet starting with 02010e10000c00040052(data)
the difference makes the lamp not ligh up and I'm not sure if I can change it via bleak as it's not part of the data I send

1
Does your device use Bluetooth Classic or Bluetooth Low Energy? For BLE have a look at this: docs.microsoft.com/en-us/windows/uwp/devices-sensors/…Michael Kotzjan
I used nRF Connect and saw services and attributes and such (does it mean it's BLE?). Why dont I need low level protocls like HCI_CMD? that's what I see pass in the traffic how do I send something that will translate to HCI_CMD then? thanks!123456
Ok so I tried using bleak and it sends the exact same packet as Microsoft's Bluetooth LE Explorer apart from one bit that says the packet is command and not request. With Microsoft's Bluetooth LE Explorer I did manage to ligh up the BLE lamp with this command (just with that bit off- request). is there a way to send request and not command?123456
bleak: 02010e10000c000400520c0055aa030802ff00fff5 await client.write_gatt_char(LIGHT_CHARACTERISTIC, b"\x55\xaa\x03\x08\x02\xff\x00\xff\xf5") Microsoft: 02010e10000c000400120c0055aa030802ff00fff5123456

1 Answers

1
votes

I think what you are showing is that bleak does a write without response while MS BLE Explorer does a write_with_response.

Looking at the Bleak documentation for write_gatt_char that seems to be consistent as response is False by default

write_gatt_char Parameters:

  • char_specifier (BleakGATTCharacteristic, int, str or UUID). The characteristic to write to, specified by either integer handle, UUID or directly by the BleakGATTCharacteristic object representing it.

  • data (bytes or bytearray) – The data to send.

  • response (bool) – If write-with-response operation should be done. Defaults to False.

I would expect the following to have the desired effect:

await   client.write_gatt_char(LIGHT_CHARACTERISTIC, b"\x55\xaa\x03\x08\x02\xff\x00\xff\xf5", True)