WSASetService() is returning 10022

Discussion in 'Wireless Networking' started by Dandi, Apr 22, 2009.

  1. Dandi

    Dandi Guest

    hi all,

    I am trying to publish the OBEX object push Service record using
    WSASetService(). But the function is failing with the error code 10022.
    Without service record i could able to register. But my PDA device is not
    dectecting my bluetooth for OPP service.

    Could anybody tell me what is wrong in the below code,

    /// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    if ( SOCKET_ERROR == ( ulRetCode = getsockname(LocalSocket, (struct
    sockaddr *)&SockAddrBthLocal, &iAddrLen) ) )
    {
    printf("getsockname() call failed w/socket = [0x%X].
    WSAGetLastError=[%d]\n", LocalSocket, WSAGetLastError());
    goto CleanupAndExit;
    }

    BYTE jPortNo = *((BYTE *)&SockAddrBthLocal.port);

    //
    // CSADDR_INFO
    //
    lpCSAddrInfo[0].LocalAddr.iSockaddrLength = sizeof( SOCKADDR_BTH );
    lpCSAddrInfo[0].LocalAddr.lpSockaddr = (LPSOCKADDR)&SockAddrBthLocal;
    lpCSAddrInfo[0].RemoteAddr.iSockaddrLength = sizeof( SOCKADDR_BTH );
    lpCSAddrInfo[0].RemoteAddr.lpSockaddr = (LPSOCKADDR)&SockAddrBthLocal;
    lpCSAddrInfo[0].iSocketType = SOCK_STREAM;
    lpCSAddrInfo[0].iProtocol = BTHPROTO_RFCOMM;

    //
    // If we got an address, go ahead and advertise it.
    //
    ZeroMemory(&wsaQuerySet, sizeof(WSAQUERYSET));

    wsaQuerySet.dwSize = sizeof(WSAQUERYSET);
    wsaQuerySet.lpszServiceInstanceName = L"Object Push Profile";
    wsaQuerySet.lpServiceClassId = (LPGUID) &g_guidServiceClass;
    // wsaQuerySet.lpszComment = L"Example Service instance registered in the
    directory service through RnR";
    wsaQuerySet.dwNameSpace = NS_BTH;
    wsaQuerySet.dwNumberOfCsAddrs = 1; // Must be 1.
    wsaQuerySet.lpcsaBuffer = lpCSAddrInfo; // Req'd.

    /*
    * Note: 0x35
    => Type descriptor is DataElement Sequeunce
    => Size is mentioned in the following 1 byte
    */

    static BYTE rgbSdpRecord[] = {
    // SDP size
    0x35, 0x00, // Note: The size is filled below.

    0x09,


    // ServiceClassIDList
    0x00, 0x01,

    // Service Classes
    0x35, 0x03, // 3 bytes

    // OBEXObjectPush 0x1105
    0x19, 0x11, 0x05,

    0x09,


    // ProtocolDescriptorList
    0x00, 0x04,

    // Protocol ID List
    0x35, 0x11, // 17 bytes


    // L2CAP (0x0100)
    0x35, 0x03, // 3 bytes
    0x19, 0x01, 0x00,

    // RFCOMM (0x0003)
    0x35, 0x05, // 5 bytes
    0x19, 0x00, 0x03, // ID
    0x08, jPortNo,

    //0x05, // Channel Number is (5)

    // OBEX (0x0008)
    0x35, 0x03, // 3 bytes
    0x19, 0x00, 0x08,
    0x09,


    // BluetoothProfileDescriptorList
    0x00, 0x09,

    0x35, 0x08, // 8 bytes
    0x35, 0x06, // 6 bytes
    0x19, 0x11, 0x05, // OBEXObjectPush
    0x09, 0x01, 0x00, // Version

    0x09,

    // Service Name
    0x01, 0x00,

    0x25, 0x13, // Type - String, size - 19 bytes (Object Push Profile)

    0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x50, 0x75, 0x73, 0x68, 0x20,
    0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,

    0x09,

    // Supported Format List
    0x03, 0x03,

    0x35, 0x0e, // 14 bytes

    0x08, 0x01, // vCard 2.1
    0x08, 0x02, // vCard 3.0
    0x08, 0x03, // vCard 1.0
    0x08, 0x04, // iCal 2.0
    0x08, 0x05, // vNote
    0x08, 0x06, // vMessage
    0x08, 0xff // Any type of object
    };

    const size_t iRecSize = sizeof(rgbSdpRecord) / sizeof(BYTE);

    rgbSdpRecord[1] = iRecSize - 2; // -2 for excluding first 2 bytes

    BTH_SET_SERVICE *pbthSetService;
    HANDLE recordHandle = NULL;
    ULONG ulSdpVersion = BTH_SDP_VERSION;

    pbthSetService = (BTH_SET_SERVICE *) calloc(sizeof(BTH_SET_SERVICE) +
    iRecSize, sizeof(BYTE));

    pbthSetService->pRecordHandle = &recordHandle;
    pbthSetService->pSdpVersion = &ulSdpVersion;

    SET_COD_MAJOR((pbthSetService->fCodService), COD_MAJOR_COMPUTER);
    SET_COD_MINOR((pbthSetService->fCodService), COD_COMPUTER_MINOR_DESKTOP);
    SET_COD_SERVICE((pbthSetService->fCodService), COD_SERVICE_OBJECT_XFER);

    pbthSetService->fCodService = 0x100104;

    pbthSetService->ulRecordLength = iRecSize;
    memcpy(pbthSetService->pRecord, rgbSdpRecord, iRecSize);

    BLOB blob;
    blob.cbSize = sizeof(BTH_SET_SERVICE) + iRecSize - 1;
    blob.pBlobData = (PBYTE) pbthSetService;

    wsaQuerySet.lpBlob = &blob;

    //
    // As long as we use a blocking accept(), we will have a race
    // between advertising the service and actually being ready to
    // accept connections. If we use non-blocking accept, advertise
    // the service after accept has been called.
    //
    if ( SOCKET_ERROR == WSASetService(&wsaQuerySet, RNRSERVICE_REGISTER, 0))
    {
    printf("WSASetService() call failed. WSAGetLastError=[%d]\n",
    WSAGetLastError());
    goto CleanupAndExit;
    }

    /// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    Regards,
    Dandi
     
    Dandi, Apr 22, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?REJI?=

    cannot access Internet after returning from standby

    =?Utf-8?B?REJI?=, Oct 31, 2005, in forum: Wireless Networking
    Replies:
    0
    Views:
    658
    =?Utf-8?B?REJI?=
    Oct 31, 2005
  2. Bobster123

    IT Jobs Returning to the U.S.?

    Bobster123, Oct 22, 2003, in forum: MCSE
    Replies:
    60
    Views:
    1,586
    billyw
    Oct 23, 2003
  3. =?Utf-8?B?Q2hhcmxpZQ==?=

    Returning After Many Years

    =?Utf-8?B?Q2hhcmxpZQ==?=, Feb 21, 2006, in forum: MCSE
    Replies:
    2
    Views:
    439
  4. phrogee

    returning waves

    phrogee, Dec 7, 2003, in forum: Computer Support
    Replies:
    15
    Views:
    779
  5. Deforce

    Email Keeps Returning Sent Emails! Help!!

    Deforce, Jan 11, 2004, in forum: Computer Support
    Replies:
    2
    Views:
    646
    Sultan
    Jan 11, 2004
Loading...

Share This Page