Recent

Author Topic: Bluetooth in Windows: service discovery SDP  (Read 1497 times)

Graham1

  • New Member
  • *
  • Posts: 32
Bluetooth in Windows: service discovery SDP
« on: October 13, 2021, 12:51:45 am »
In an earlier post I found how to look up BT devices using BluetoothAPIs.dll and Winsock2, and then how to connect, read and write to a specific port on a found device:

https://forum.lazarus.freepascal.org/index.php/topic,53862.msg401002.html#msg401002

Now I'm trying to find how to discover what ports and services are available for the devices rather than just connecting to a hardcoded one. In the Python library BlueZ they have a function find_service that does what I want but I can't find the equivalent in the Windows API:

https://pybluez.readthedocs.io/en/latest/api/find_service.html

I couldn't find anything about it in the BT API documents at:

https://docs.microsoft.com/en-us/windows/win32/api/bluetoothapis/

For Winsock I think it might be related to the lpafpProtocols in the WSAQuerySet but I'm not sure how to set and access it:

https://docs.microsoft.com/en-us/windows/win32/api/winsock2/

I tried looking in the JWA source in C:\Pascal\fpc\3.2.0\source\packages\winunits-jedi\src but wasn't sure what to look for.

Does anybody have an example of how to do this, or a Pascal version of the Python function mentioned above?

Thanks!

Windows 10 Home 64-bit
Lazarus 2.0.12 / FPC 3.2.0

Graham1

  • New Member
  • *
  • Posts: 32
Re: Bluetooth in Windows: service discovery SDP
« Reply #1 on: October 14, 2021, 06:20:58 am »
I'm making some progress. I've found that for each device I locate in the initial loop of WSALookupServiceBegin and WSALookupServiceNext I need to perform a secondary Lookup loop for the RFCOMM_Protocol_UUID and the device's BT address. So I can now list the RFCOMM services for the devices and I can see the 'Serial Port' service line I'm after.

But how to I get to the channel number?

My flags include LUP_RETURN_ADDR OR LUP_RETURN_BLOB but the port number in the address just shows 0. I think that is intended as the COM port number for the connecting device rather than the channel for the BT device itself.

I think it must be in the Blob data but I'm not sure how to access that. Can anyone point me in the right direction?

Thanks!
Windows 10 Home 64-bit
Lazarus 2.0.12 / FPC 3.2.0

 

TinyPortal © 2005-2018