Symbian
Symbian OS Library

FAQ-1148 How do I get the list of active bluetooth connections?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: PAN (Bluetooth, USB, Irda)
Created: 09/30/2004 Modified: 11/12/2004
Number: FAQ-1148
Platform: Symbian OS v7.0, Symbian OS v7.0s

Question:
How do I get the list of active connections (actual connections, not discovery).
Is there any way to get notification if this list changes?


Answer:
Symbian OS v7.0
    Symbian OS v7.0, v7.0s have limited support for getting the connection information. There is a socket IOCTL command to get all the device addresses for connected ACL links (see KLMGetACLLinkArray in the Symbian Developer Library). Note that you can get the count of links first using KLMGetACLLinkCount. There is no way to get a notification when the set of links change.

    The example code below shows how you can query for the list of addresses:

    //Define buffer for the number of connected devices
    TPckgBuf theDevNo;

    // Get the number of ACL links
    TInt err = iSocket.GetOpt(KLMGetACLLinkCount, KSolBtLM, theDevNo);
    User::LeaveIfError(err);

    // Number of ACL connections
    TInt& noLinks = theDevNo();
    if(noLinks == 0)
    {
    return KErrNone; // If no links, no problem
    }

    // Allocate memory for the response of TBTDevAddr array
    TBTDevAddr* tmpAddrArray = new(ELeave) TBTDevAddr[noLinks];
    CleanupArrayDeletePushL(tmpAddrArray);

    TInt theArraySize = noLinks*sizeof(TBTDevAddr);
    TPtr8 ptr((TUint8*)tmpAddrArray, theArraySize, theArraySize);

    // Get an array of device addresses for the ACL links, into a Link Array
    err = iSocket.GetOpt(KLMGetACLLinkArray, KSolBtLM, ptr);
    User::LeaveIfError(err);

    // Make sure we iterate through the addresses that we did get back as
    // opposed to the maximum which we could
    noLinks = ptr.Length()/sizeof(TBTDevAddr);
    CleanupStack::PopAndDestroy(); //tmpAddrArray


    More information on Bluetooth sockets is available in the developer library:
      » Developer Library » Symbian OS Guide » C++ API guide » Bluetooth » Using Bluetooth Sockets

      Symbian OS v8.0

      Symbian OS v8 provides improved support for this functionality.

      The "publish & subscribe" (P&S) mechanism can be used to register for notification when the number of physical links changes.
      The relevent P&S key is KPropertyKeyBluetoothLocalDeviceAddress, which is described in the API reference documentation as "The key to observe the the number of Bluetooth physical links attached to the local device".

      Information on the Publish & Subscribe framework is available in the Symbian OS v8 SDKs on Symbian DevNet - see "Series 60 2nd Edition with Feature Pack 2 (Symbian OS v8.0)"
      » Developer Library » Symbian OS Guide » C++ API guide » Base » Publish & Subscribe » Publish and Subscribe Overview


      Code can then use the CBluetoothPhysicalLinks::Enumerate() method to get the addresses of the connected devices. API reference for the method is:

      //Enumerate members of the piconet
      EXPORT_C TInt CBluetoothPhysicalLinks::Enumerate(RBTDevAddrArray& aBTDevAddrArray, TUint aMaxNumber)
      • aBTDevAddrArray - Bluetooth device address array to be filled with bluetooth addresses of members of the piconet.
      • aMaxNumber - Upper limit on number of members to be returned.
      • Returns - Error code