Disconnecting a PAN member

So far in this tutorial series we have looked at the steps involved in creating a Personal Area Network and adding devices to that PAN. Now we will look at disconnecting devices from the PAN.

Using the Tutorial

The code fragments in this tutorial are derived from the Bluetooth Example application available in /src/COMMON/DEVELOPERLIBRARY/examples/Bluetooth/BTExample1 . Although the code has been reformatted to the requirements of the tutorial there is always enough information included with the code to find the actual example code.

Intended Audience:

This tutorial is designed for Symbian licensees only. Several APIs mentioned ad used throughout this tutorial series are only available in a device creators kit environment.

Basic procedure:

The high level steps to remove a device from a PAN are:

  • Request the connection be closed.

  • Extract the device address for the connection being closed.

  • Disconnect the device from the PAN.

Request the disconnection

The user will select the option to 'Remove current active device' from the PAN. This will cause to prompt the user to select a device. The result of this operation is that the Bluetooth device address is known. See " Finding the Bluetooth Device Address " for more.

Identify the device being removed

As the device being removed is the currently active device the following will get its Bluetooth address:

       
        
       
       ...
else if(iActivePanConn != KErrNotFound)
{
    TPtr8 ptr = iActiveConnections[iActivePanConn].Des();
      

It is also possible that instead of a device removing itself from the PAN the host can eject a member. The user of the PAN host device would need to be presented with a list of the active members where selecting the member would pass the device address details to the disconnect function.

Disconnect from PAN

Regardless of how the disconnect function has been called you have a Bluetooth device address that has been added to the ptr pointer (above). The following will remove the device from the PAN:

       
        
       
       ...
 rerr = iConnection.Control(KCOLAgent, KCOAgentPanDisconnectDevice, ptr);
 ...
}
return rerr;
      

The RConnection::Control() function contains three parameters. They are explained here:

Attribute Description

KCOLAgent

Sets the scope of the Control() function to the agent.

KCOAgentPanDisconnectDevice

The actual command being passed to the RConnection . In this case the connection is being told to disconnect the device identified by ptr .

ptr

The pointer to the Bluetooth device address.

What's next?

Having created a PAN and added and removed devices from the PAN you will need learn about closing the PAN. The following will help: