Compartilhar via


Configuring WSAQUERYSET for Service Discovery

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

To perform a service discovery you must configure the WSAQUERYSET structure to specify the search criteria. This structure is then passed to the WSALookupServiceBegin function that initiates the query process. For more information about the service discover procedure, see Querying Service Capability on Remote Bluetooth Devices.

Before you configure WSAQUERYSET for service discovery, you must have the following information:

  • You must have the address of the a remote Bluetooth device to query, as a BT_ADDR type, as defined in Ws2bth.h:

    typedef ULONGLONG bt_addr, *pbt_addr, BT_ADDR, *PBT_ADDR;
    

To specify the search criteria in a WSAQUERYSET structure

  1. To specify SDP search parameters, configure the BTHNS_RESTRICTIONBLOB structure. This structure is referenced by the lpBlob member of WSAQUERYSET.

    The following table shows the values to set in the type member of the BTHNS_RESTRICTIONBLOB.

    Value Description

    SDP_SERVICE_SEARCH_REQUEST

    This value specifies a service query. For this value, you must also specify the service in uuids. The following code example shows how to set BTHNS_RESTRICTIONBLOB for a service query.

    RBlob.type = SDP_SERVICE_SEARCH_REQUEST;
    RBlob.uuids[0].uuidType = SDP_ST_UUID16;
    RBlob.uuids[0].u.uuid16 = SerialPortServiceClassID_UUID16;

    Ignore the other members of this structure.

    SDP_SERVICE_ATTRIBUTE_REQUEST

    This value specifies an attribute query. For this value you must also specify the number of attribute in the numRange member and pointer to these attributes in the pRange member. The following code example shows how to set the BTHNS_RESTRICTIONBLOB for an attribute query.

    RBlob.type = SDP_SERVICE_ATTRIBUTE_REQUEST;
    RBlob.numRange = 1;
    RBlob.pRange[0].minAttribute = SDP_ATTRIB_PROTOCOL_DESCRIPTOR_LIST;
    RBlob.pRange[0].maxAttribute = SDP_ATTRIB_PROTOCOL_DESCRIPTOR_LIST;

    Ignore the other members of this structure.

    SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST

    This value specifies both service and attribute search. For this value, you must specify service UUID and the attribute range members.

    Note

    The service identifiers are defined in the header file, bt_sdp.h, located in the %_WINCEROOT%\Public\Common\Sdk\Inc directory. For more information about UUIDs, see this Official Bluetooth Wireless Info Web site.

  2. To define a Bluetooth socket address, configure the SOCKADDR_BTH structure.

    • Set the addressFamily member to AF_BTH that specifies the Bluetooth address family.
    • Set the btAddr member to the address of the remote Bluetooth device.
  3. Configure the CSADDR_INFO to specify the Bluetooth socket address.

    1. Define a Bluetooth socket address by configuring the SOCKADDR_BTH structure. Set the addressFamily member to AF_BTH that specifies the Bluetooth address family. Also, set the btAddr member to the address of the remote Bluetooth device.
    2. Configure the RemoteAddr member of CSADDR_INFO to specify the socket address and the size of the address.

    The following code example shows the values to set for SOCKADDR and CSADDR_INFO.

    SOCKADDR_BTH sa;
    memset (&sa, 0, sizeof(sa));
    *(BT_ADDR *)(&sa.btAddr) = *pb;
    sa.addressFamily = AF_BT;
    CSADDR_INFO csai;
    memset (&csai, 0, sizeof(csai));
    csai.RemoteAddr.lpSockaddr = (sockaddr *)&sa;
    csai.RemoteAddr.iSockaddrLength = sizeof(sa);
    

    The lpcsaBuffer member of the WSAQUERYSET points to this CSADDR_INFO structure.

  4. To specify the search criteria, set the appropriate members of WSAQUERYSET.

    The following code example shows the values to set for the WSAQUERYSET members.

    WSAQUERYSET wsaq;
    memset (&wsaq, 0, sizeof(wsaq));
    wsaq.dwSize      = sizeof(wsaq);
    wsaq.dwNameSpace = NS_BTH;
    wsaq.lpBlob      = &blob;
    wsaq.lpcsaBuffer = &csai;
    
    • The lpBlob member must point to a BLOB structure that contains BTHNS_RESTRICTIONBLOB data, set in step 1. The following code example shows how to set this BLOB structure.

      BLOB blob;
      blob.cbSize = sizeof(RBlob);
      blob.pBlobData = (BYTE *)&Rblob
      
    • The lpcsaBuffer member points to CSADDR_INFO that stores the Bluetooth socket address, set in step 3.

See Also

Concepts

Querying Service Capability on Remote Bluetooth Devices

Other Resources

Bluetooth Application Development