0

I've been studing the bluetooth echo server example from windows wdf samples. I want to understand the l2cap bt driver implementation, but I'm still a bit confused.

Below I listed the code from the example.

Here we have a GUID and a name of a service published by the bt server dev. A client has to know that information if it wants to connect to the server.

    //
    // Service GUID and name for the service published by our bth server device
    //
    
    /* c07508f2-b970-43ca-b5dd-cc4f2391bef4 */
    DEFINE_GUID(BTHECHOSAMPLE_SVC_GUID, 0xc07508f2, 0xb970, 0x43ca, 0xb5, 0xdd, 0xcc, 0x4f, 0x23, 0x91, 0xbe, 0xf4);
    
    extern __declspec(selectany) const PWSTR BthEchoSampleSvcName =L"BthEchoSampleSrv";
    
    //
    // Device interface exposed by our bth client device
    //
    
    /* fc71b33d-d528-4763-a86c-78777c7bcd7b */
    DEFINE_GUID(BTHECHOSAMPLE_DEVICE_INTERFACE, 0xfc71b33d, 0xd528, 0x4763, 0xa8, 0x6c, 0x78, 0x77, 0x7c, 0x7b, 0xcd, 0x7b);

Here is how the client can connect to the server:

DWORD err = GetDevicePath((LPGUID)&BTHECHOSAMPLE_DEVICE_INTERFACE, &devicePath);

if (ERROR_SUCCESS != err) {
    printf("Failed to find the BTHECHO device\n");
    exit(1);
}

hDevice = CreateFile(devicePath,
                     GENERIC_READ|GENERIC_WRITE,
                     FILE_SHARE_READ | FILE_SHARE_WRITE,
                     NULL,
                     OPEN_EXISTING,
                     0,
                     NULL );

My question is: what if I have a mobile phone or a tablet and can choose it from my bt list device using WSALookupServiceXXXX. How can I still use or connect to the l2cap driver? How can I get the GUID of an external server device if I'm a client? and the other way around how does the client get to know the GUID server of the server? the GUID and a service class ID (bt profiles) are two different things, aren't they?

Best,

user
  • 95
  • 1
  • 9
  • Service class is actually the BT profile. Service UUID should unique identifies the profile. Service name - just a readable name. Does nothing usefull. Few services may have same UUID if thay uses same BT profile. For exaple, device may have 2 SPP based services (with identical UUID). But with different RFCOMM channel number. Or, if we are talking about L2CAP, with different PSM. Now answering your questions: no, you can not connect to L2CAP from user mode app on Windows. You should know service's UUID (or RFCOMM channel or PSM). – Mike Petrichenko Mar 22 '21 at 12:28
  • Thank you. So If i understand you correct, i can get a service device name and the use uuid of a profile, combine them together in a form of DEFINE_GUID(server name, uuid for a service like PhoneBook profile) and then go as the example shows with createfile(...)? – user Mar 22 '21 at 12:42
  • If we are talking about L2CAP then it knowns nothing about UUIDs. The GUID you use in your code is just a Windows device interface GUID. It is there just to give your application a way to find and open device handle. If we are talking about RFCOMM based services then yes, you have to use service's UUID to connect to connect one. Internally Windows queries SDP and resolves RFCOMM channel to execute connection. Of course you can do it in your application as well (in case if there are 2 identical services). – Mike Petrichenko Mar 22 '21 at 15:46
  • it's getting clearer. Let's talk only about L2CAP. So let's say I have a L2CAP server driver (as it is done in the wdf example) and a simple app which sends A/V control commands to a paired cell phone. I have a cell phone and I want to control my music player. How that will work? How to connect these two from the applicatin level? – user Mar 23 '21 at 09:16
  • There are 2 ways: 1. Implement AVRCP profile (in fact it is supported by Windows 10) or 2. Use own protocol. AVRCP uses weel-known PSM and defines commands. Your own server should use your custom PSM and define your own commands. In any case you develop L2CAP driver. You can use well-known device class GUID for your driver (let say HID one) or your own class GUID. Once it is installed you then can find your device using Win API (Setup API of CFGMGR API) and open its handle (CreateFile). Then you can communicate with driver using File functions or DeviceIoControl function. – Mike Petrichenko Mar 23 '21 at 11:56

0 Answers0