×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    1

    bluetooth passkey, i need help , pls help me , thank u

    i need to write a code which can search bluetooth devices. my code can search the devices but cant connect , i think that is because i dont define passkey in my code. i m new to C++ and bluetooth,this code is i combine some different codes together. may any one tell me how to continue for my code to make it workable ??? thank u.

    Code:
    //// pairing2.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <winsock2.h>
    #include <ws2bth.h>
    #include<iostream>
    int _tmain(int argc, _TCHAR* argv[])
    {
    	// setup windows sockets
    const int size=15;
    char line[size];
    WORD wVersionRequested ;
    WSADATA wsaData ;
    wVersionRequested = MAKEWORD(2,0);
    if( WSAStartup( wVersionRequested, &wsaData ) != 0 ) {
    fprintf(stderr , "uh oh... windows sockets barfed\n" ) ;
    ExitProcess ( 2 ) ;
    }
    // prepare the inquiry data structure
    DWORD qs_len = sizeof( WSAQUERYSET ) ;
    WSAQUERYSET*qs=(WSAQUERYSET* )malloc( qs_len ) ;
    ZeroMemory(qs,qs_len) ;
    qs->dwSize=sizeof(WSAQUERYSET);
    qs->dwNameSpace=NS_BTH ;
    qs->dwNumberOfCsAddrs=0;
    
    qs->lpServiceClassId =&PublicBrowseGroupServiceClass_UUID;
    DWORD flags = LUP_CONTAINERS ;
    flags |= LUP_FLUSHCACHE | LUP_RETURN_NAME | LUP_RETURN_ADDR ;
    HANDLE h ;
    // start the device inquiry
    if( SOCKET_ERROR == WSALookupServiceBegin (qs,flags,&h) ) {
    ExitProcess ( 2 ) ;
    }
    bool done = false ;
    while (!done) {
    if(NO_ERROR == WSALookupServiceNext (h,flags,&qs_len,qs) ) {
    char buf[40]={0};
    
    SOCKADDR_BTH *sa =
    (SOCKADDR_BTH* )qs->lpcsaBuffer->RemoteAddr.lpSockaddr ;
    BTH_ADDR result = sa->btAddr ;
    DWORD bufsize = sizeof(buf) ;
    WSAAddressToString(qs->lpcsaBuffer->RemoteAddr.lpSockaddr ,sizeof(SOCKADDR_BTH),NULL,buf,&bufsize );
    printf( "found: %s - %s\n" ,
    buf,qs->lpszServiceInstanceName ) ;
    
    } else {
    int error = WSAGetLastError ( ) ;
    if( error == WSAEFAULT ) {
    free( qs ) ;
    qs = (WSAQUERYSET* ) malloc( qs_len ) ;
    } else if( error == WSA_E_NO_MORE ) {
    
    SOCKET s = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); 
    
    if (s == INVALID_SOCKET)
    {
    printf("error");
    exit(1);
    }
    printf("key in address u want:\n");
    std::cin.getline(line,size);
    printf("%s\n",line);
    
    SOCKADDR_BTH bthSockAddr;
    bthSockAddr.addressFamily=AF_BTH;
    bthSockAddr.btAddr=(BTH_ADDR)0x00165307f276;
    bthSockAddr.port=BT_PORT_ANY;
    bthSockAddr.serviceClassId=SerialPortServiceClass_UUID;
    if(0==connect(s,(sockaddr*)&bthSockAddr,sizeof(bthSockAddr)))
    printf( "inquiry complete\n" ) ;
    done = true ;
    } else {
    printf( "uh oh. error code %d\n" , error ) ;
    done = true ;
    }
    }
    }
    WSALookupServiceEnd(h) ;
    free(qs) ;
    WSACleanup();
    return 0;
    }

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,740

    Re: bluetooth passkey, i need help , pls help me , thank u

    This code is for Windows Mobile, while this board focuses on Symbian C++. You should search for WM developer sites, or check MSDN.

Similar Threads

  1. Bluetooth OBEX operations, help me pls
    By siddhartha84 in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-04-12, 06:12
  2. Bluetooth GPS simulator for j2me phone
    By vgps in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2007-02-09, 04:30
  3. Anbody who found a supported bluetooth card, pls give a hand!
    By aluckybird in forum Bluetooth Technology
    Replies: 0
    Last Post: 2004-11-24, 20:13
  4. Nokia 7650 support Bluetooth audo?
    By ovjo12 in forum Bluetooth Technology
    Replies: 5
    Last Post: 2003-07-17, 18:50
  5. Nokia 6310 with Socket Bluetooth CF (need the passkey)
    By JBelartM in forum Bluetooth Technology
    Replies: 3
    Last Post: 2002-12-31, 08:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×