Symbian Developer Library



[Index] [Previous] [Next]

Creating a Personal Area Network (PAN)

We are looking at a two device PAN in this tutorial. So if you want to run the example it must be installed on both devices. One device will initiate a connection and the other will listen for a connection. We will refer to the listener as D1 and the initiator as D2 when necessary.

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 create a PAN are:


Configuring CommDB PAN IAP

The PAN IAP (PANServiceExtensions table) will need to be configured for both devices. D1 will need to start a PAN listening connection. D2 will look for a listening device (D1) and connect to that device.

To configure CommDB tables for PAN do the following:

  1. Open CommDB.

    CCommsDatabase* db = CCommsDatabase::NewL();
  2. Open a view on the PANServiceExtensionsTable1 table.

    CCommsDbTableView* tableView =
    TBuf<KMaxBufferSize> tableName;
    tableView->ReadTextL(TPtrC(COMMDB_NAME), tableName);

    Check that we are looking at the correct table.

    if(tableName == TPtrC(_S("PANServiceExtensionsTable1")))

    The above simply ensures that the table name is what was expected.

  3. Open the table for editing.

  4. Set the device to listen for incoming PAN connection requests if necessary.


    The value of aIsListening is ETrue for D1, the listening device.

  5. Decide if the device will prompt for remote devices.


    The value of aUsePANNotifier is EFalse when you do not want the user to be prompted for a device. As with step 4 above this is the configuration for D1, the listening device, which will be accepting incoming connections instead of seeking other devices.

  6. Set the PeerMacAddress to the Bluetooth device address of the device joining the PAN if known or to NULL if not known.

    D2 will prompt for a Bluetooth device address (aDevAddr) when making the connection. So if aDevAddr exists then the device is trying to initiate a PAN with D1, the listening device. The Peer Mac Address of the listener will be returned by the notifier (see "Finding the Bluetooth Device Address") and added to the CommDB table as shown.

     TBuf<KMaxBufferSize> buf;
     tableView->WriteTextL(TPtrC(PAN_PEER_MAC_ADDRESSES), buf);

    D1 is the listener and so will not need a Bluetooth device address when creating the listening connection.

     tableView->WriteTextL(TPtrC(PAN_PEER_MAC_ADDRESSES), _L(""));
  7. Commit the CommDB PANServiceExtensionsTable changes.

    User::LeaveIfError(tableView->PutRecordChanges());// Finish update

The code above comes from CPanConnections::ConfigureIAPL() in "exampleroot/src/panconnection.cpp".

ConfigureIAPL(TBool aIsListening,TBTDevAddr* aDevAddr,TBool aUsePANNotifier)

The function is called when a connection is started. This function is called with three values: aIsListening, aDevAddr, and aUsePANNotifier.

Attribute Value


when called from CPanConnections::StartConnection():

  • ETrue if the device is listening for an incoming connection.

  • EFalse if the device is not listening for an incoming connection.


The Bluetooth device address.


when called from CActiveConsole::ProcessKeyPressL():

  • ETrue if the PAN notifier is needed.

  • EFalse if the PAN notifier is not needed.

Finding the Bluetooth Device Address

The following code shows how to get and manipulate the Bluetooth device address:

TBTDevAddr devAddr; // Bluetooth device address.
TMenuMode = iMode; // from console.h
iMode = EPan; //Ask user which device address we should connect to...
RNotifier notify; // get a notifier
User::LeaveIfError(notify.Connect()); // connect to the notifier
TBTDeviceSelectionParamsPckg pckg; // Bluetooth device parameters package
TBTDeviceResponseParamsPckg resPckg; // Response parameters package
TRequestStatus stat;
 // Start the notifier.
 // Wait for the notifier results.
 // Close the notifier now that we have the device details.
 // extract the Bluetooth device address from the notifier results.
devAddr = resPckg().BDAddr();
 // start the PAN connection request, send the Bluetooth device address.
iPanConnection->StartConnection(&devAddr, EFalse, EFalse);

Note: this fragment taken from CActiveConsole::ProcessKeyPressL() in "exampleroot/src/console.cpp".


Loading the Bluetooth Stack

The Bluetooth stack will need to be loaded before a PAN is created.

 _LIT(KPDDName, "EUART1");      
 _LIT(KLDDName, "ECOMM");   
 TInt rerr = KErrNone;
 rerr = StartC32();// For any Serial comms
 // Load required drivers
 TProtocolDesc iProtocolInfo;
 TRequestStatus status;
 iSockSvr.FindProtocol(_L("L2CAP"), iProtocolInfo);
 // After Socket server is connected, start L2CAP protocol
 iProtocolInfo.iSockType,iProtocolInfo.iProtocol, status);

The code above shows how to load the Bluetooth Stack using standard sockets.


Starting the PAN Connection

Now that you have loaded the Bluetooth stack and configured the PAN service extensions table a PAN connection can be opened.

  1. Define the connection preferences.

     // EGeneralIAP = 1
    PanProfileIAPs iap(EGeneralIAP); // panconnection.h
    TInt rerr = iSockSvr.Connect();
    if(rerr == KErrNone)
  2. Load the Bluetooth stack.


    Covered in the previous section.

  3. Open the connection

    rerr = iConnection.Open(iSockSvr);
  4. Start the session if the connection opened correctly:

    if(rerr == KErrNone)

The code above is derived from CPanConnections::StartIAP() in "exampleroot/src/panconnection.cpp".

That's all there is to creating a PAN.


What's next?

Having created a PAN you will need to add and remove devices and close the PAN. The following will help: