×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Feb 2009
    Location
    Budapest, Hungary
    Posts
    7

    Exclamation bluetooth passkey problem

    Hi,

    I'm trying to connect to a bluetooth device which needs a simple passkey "1616". I would like to use RFCOMM and receive bytes. I can find my device through RNotifier so I have my TBTDeviceResponseParamsPckg containing the TBTDevAddr.

    At this point I thought that I was near to connect and receive the bytes. I could not find any solution to add my passkey and HandleConnectCompleteL gives me error code: -34 KErrCouldNotConnect. I think this is because a passkey problem.
    I tried to add my device to the bluetooth registry when I CAN set the passkey member but I don't know exactly how to connect this device. I hoped that if I use the Connect(TBTSockAddr) it will recognize that this MAC address is already in the device database and use the passkey but no success.

    I'm using the following code to
    • discover
    • delete from bluetooth registry
    • add to bluetooth registry with passkey
    • connect


    How can I connect to a remote bluetooth device which needs passkey (PIN code)? Can anybody give me any method?
    There are only solutions which are disabling the PIN code of the remote device.
    I'm sure there is a solution because connecting to a GPS device needs that and a lot of symbian programs uses it.

    Please check my code:

    Code:
    void CBluetoothEngine::SelectDeviceByDiscoveryL()
        {
    		TInt result;
        	RNotifier notifier;
        	TBTDeviceSelectionParams selectionFilter;	
        	TUUID targetServiceClass(0x10ff); // UUID: 0x10ff
        	TBTDeviceResponseParams response;
        	TBuf<255> name;
        	
        	// Connect to the notifier server
        	
        	result = notifier.Connect();
        	User::LeaveIfError(result);
        	
        	// Set up the parameters	
        	selectionFilter.SetUUID(targetServiceClass);	
        	TBTDeviceSelectionParamsPckg pckg(selectionFilter);	
        	TBTDeviceResponseParamsPckg responsePckg(response);
        	TRequestStatus status;
    
        	// Start up the notifier
        	notifier.StartNotifierAndGetResponse( status, KDeviceSelectionNotifierUid, pckg, responsePckg);
        	User::WaitForRequest(status);
        	
        	// Handle the notification
        	if(status.Int() == KErrNone)
        	{
    			
    			/*TBuf<128> msg;
    			responsePckg().BDAddr().GetReadable(msg);
    			iAppView->MessageL(msg);*/
    			// I get a valid MAC address of my remote device
        		if (response.IsValidDeviceName())
        		{
        		}
        	}
        	else
        		{
        		iAppView->MessageL(_L("No device"));
        		}
    
        	
        	TBTSockAddr BTAddr;
        	BTAddr.SetBTAddr(responsePckg().BDAddr());
        	//what port (channel) is used?
        	BTAddr.SetPort(3);
        	
        	
        	TBuf<128> msg;
        	BTAddr.BTAddr().GetReadable(msg);
        	
        	iAppView->MessageL(msg);
        	
     
        	
    		// Delete this device from the registry 
        	// Select the device by MAC address
    		
        	RBTRegServ regServ;
        	User::LeaveIfError(regServ.Connect());
        	RBTRegistry iViewReg;
        	User::LeaveIfError(iViewReg.Open(regServ));
        	TBTRegistrySearch search;
        	search.FindAddress( responsePckg().BDAddr() ); //THostAddress aDeviceAddr - the BT MAC
        	TRequestStatus iReqStatus;
        	iViewReg.CreateView( search, iReqStatus );
        	User::WaitForRequest( iReqStatus );
        	// Check the status returned
    		
        	iViewReg.DeleteAllInView( iReqStatus );
        	User::WaitForRequest( iReqStatus );
        	// Check the status returned
    		
        	//Add a new device with MAC and passkey
        	RBTRegServ serv;
        	TInt ret = serv.Connect();
        	RBTRegistry registry;
        	ret = registry.Open(serv);
    
        	CBTDevice* addDetails = CBTDevice::NewLC(responsePckg().BDAddr());
        	TBuf8<4> psd(_L8("1616")); 
        	addDetails->SetPaired(ETrue);
        	TPINCodeV10 pinCode10;
        	pinCode10.iLength = 4;
        	memcpy(pinCode10.iPIN,psd.Ptr(),4);
        	TBTPinCode pinCode(pinCode10);
        	addDetails->SetPassKey(pinCode);
        	TRequestStatus stat;
        	registry.AddDeviceL(*addDetails,stat);
        	User::WaitForRequest(stat);
        	TInt err = stat.Int();
        	
    		TBuf<32> msg1;
    		msg1.Format(_L("Error: %d"),err);
    		iAppView->MessageL(msg1);
        	registry.Close();
        	registry.CloseView();
        	//try to connect the BT socket
        	//HandleConnectCompleteL will be called when this request completes
        	
           	TBTServiceSecurity sec;
            sec.SetAuthentication(ETrue);
            sec.SetAuthorisation(ETrue);
            BTAddr.SetSecurity(sec);
        	
        	
        	iBTSocket->Connect(BTAddr);
        	
        	
        	
        	
        	//CBTMCMSettings* iBtSettings = CBTMCMSettings::NewL( this );
        	
        }
    Catch the "event"

    Code:
    void CBluetoothEngine::HandleConnectCompleteL(TInt aErr)
    {
    	
    	//check if the connection failed
    	if(aErr==KErrNone)
    	{
    		iState=EConnected;
    		iAppView->MessageL(_L("Connection ready!"));
    		receive();
    		
    	}else{
    		
    		
    		//iAppView->MessageL(_L("Connection failed."));
    		TBuf<32> msg;
    		msg.Format(_L("Error: %d"),aErr);
    		//iAppView->MessageL(msg);
    		iState=EDisconnected;
    		
    	}
    	
    }
    Another strange thing is if I go to my phones bluetooth menu I cannot see the paired device in the list. But if I remove from my code the pre-deletion from the registry and trying to add my remote device it will "say" it is already in the database.

    Thanks in advance.

    Lizard
    Last edited by Lizard_hun; 2009-02-13 at 13:24.

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

    Re: bluetooth passkey problem

    Hi, I have got your mail.
    Without any experience with BT with security, a thing to try could be using values instead of digits in the PIN code.
    Code:
    TBTPinCode pinCode;
    pinCode().iLength=4;
    pinCode().iPIN[0]=1;
    pinCode().iPIN[1]=6;
    pinCode().iPIN[2]=1;
    pinCode().iPIN[3]=6;

  3. #3
    Registered User
    Join Date
    Feb 2009
    Location
    Budapest, Hungary
    Posts
    7

    Thumbs up Re: bluetooth passkey problem

    Hi

    Thank you for your answer wizard_hu_.
    I have solved the problem.

    About the predefined bluetooth passkey, password, linkkey
    My first plan was to predefine the password used by my remote bluetooth device, so my phone would never ask for it. I think the solution for this is the bluetooth registry where I can define a passkey and a linkkey and save my remote device into the phone's BT registry. I can add my device to the registry with the proper name, address, SecuritySettings but the password was always asked. I have removed this BT registry modification part... later maybe I will try again, my application would be better with automatic pairing but now time is more important.

    About error -34 and conection failure with the remote bluetooth device with password
    I have figured out that I'm using the wrong port.
    Code:
            TBTSockAddr BTAddr;
        	BTAddr.SetBTAddr(responsePckg().BDAddr());
        	//what port (channel) is used?
        	BTAddr.SetPort(3); //WRONG PORT DOESN'T WORK
    If I change the port to ONE (1) than after the
    Code:
    iBTSocket->Connect(BTAddr);
    command, the password request UI automatically appears and ask me for the password. If it's OK then
    Code:
    HandleConnectCompleteL(TInt aErr)
    will indicate KErrNone.
    After this the my remote bt device will automatically written into the phone's BT registry and next time you can connect with the device without the password request window!

    Thats all folks!

    David

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    8

    Re: bluetooth passkey problem

    Quote Originally Posted by Lizard_hun View Post
    Hi

    Thank you for your answer wizard_hu_.
    I have solved the problem.

    About the predefined bluetooth passkey, password, linkkey
    My first plan was to predefine the password used by my remote bluetooth device, so my phone would never ask for it. I think the solution for this is the bluetooth registry where I can define a passkey and a linkkey and save my remote device into the phone's BT registry. I can add my device to the registry with the proper name, address, SecuritySettings but the password was always asked. I have removed this BT registry modification part... later maybe I will try again, my application would be better with automatic pairing but now time is more important.

    About error -34 and conection failure with the remote bluetooth device with password
    I have figured out that I'm using the wrong port.
    Code:
            TBTSockAddr BTAddr;
        	BTAddr.SetBTAddr(responsePckg().BDAddr());
        	//what port (channel) is used?
        	BTAddr.SetPort(3); //WRONG PORT DOESN'T WORK
    If I change the port to ONE (1) than after the
    Code:
    iBTSocket->Connect(BTAddr);
    command, the password request UI automatically appears and ask me for the password. If it's OK then
    Code:
    HandleConnectCompleteL(TInt aErr)
    will indicate KErrNone.
    After this the my remote bt device will automatically written into the phone's BT registry and next time you can connect with the device without the password request window!

    Thats all folks!

    David
    Hi,

    I am having similar problem. If I add a device to BT registry it does not show up on paired device list in my phones bluetooth menu but if do a FindAll I can find it. Maybe there is something more than just AddDeviceL and SetPaired(ETrue) to get a device add in the paired device list. Maybe something to do with sevice record, not sure.

    Did you get to the bottom of this issue?

    Thanks

Similar Threads

  1. Connection Bluetooth problem with Nokia
    By Wulfric in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2009-01-23, 14:00
  2. Q: Problem with Nokia PC Suite and Bluetooth
    By Juha_74 in forum General Development Questions
    Replies: 0
    Last Post: 2007-03-13, 13:32
  3. Strange Problem with Bluetooth Connection
    By bigbadwolf in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2006-12-06, 09:51
  4. Bluetooth serviceDiscover problem Device Not Reachable
    By kashifqazi in forum Bluetooth Technology
    Replies: 1
    Last Post: 2006-10-13, 12:31
  5. Nokia SDK Bluetooth service re-discovery problem, Help Me!:(
    By tomsonxu in forum Bluetooth Technology
    Replies: 0
    Last Post: 2005-11-08, 07:51

Posting Permissions

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