Processing an Extended Inquiry Response

This tutorial shows you how to retrieve and process the data from a Bluetooth Extended Inquiry Response (EIR).

Introduction

This tutorial shows you how to retrieve the EIR data and how to access the various types of data within it.

Basic Procedure

The high level steps to access the EIR are shown here:

  1. Create the EIR object and during construction fill it with the data from the Extended Inquiry Response

  2. Use access functions to retrieve the different types of data.

Environment

This tutorial assumes that you have your device correctly configured, active and with Bluetooth enabled and the Bluetooth Stack initialised. iResult is in scope and contains a TNameEntry object as the result of a successful Inquiry request. See Inquiring About Remote Devices.

Note: When the Inquiry Request is made, set the aDoEIR flag to specify that Extended Inquire Response data is required. The Bluetooth Stack will set the aDoEIR flag if an older version of the API (non-EIR) is used.

Tutorial

Create an object to hold the Extended Inquiry Response data

  • TBluetoothNameRecordWrapper eir(iResult());

Use access functions to retrieve the various kinds of data

  1. Get the Bluetooth device local name

    Note: The device local name may be truncated if it is too long to fit in the EIR data packet. If the name is not truncated then the isNameComplete flag will be set to TRUE.

    
    TBool isNameComplete;
    TInt error = KErrNone;
    TInt length = 0;
                
    // Get name
    // This length could be used to create the TBuf to be passed into GetDeviceName()
    length = eir.GetDeviceNameLength();
    TBuf<255> name;
    if(length >= 0)
     {
     // name will contain a Unicode encoded 16-bit string
        error = eir.GetDeviceName(name, isNameComplete);
        }
     else
        {
            error = length;
        }
    if(error == KErrNone)
    // we have name here
        {
        if(isNameComplete == EFalse)
            {
            iHROutputConsole->Printf(_L("%d Bytes [Partial] Name: "), length);
            }
        else
            {
            iHROutputConsole->Printf(_L("%d Bytes [Complete] Name: "), length);
            }
            iHROutputConsole->Printf(_L("%S \n"),&name);
        }
    
  2. Get the Transmission Power level

    // Get TxPowerLevel
    TInt8 txPowerLevel;
    error = eir.GetTxPowerLevel(txPowerLevel);
    if(error == KErrNone)
        // TxPowerLevel present
        {
        iHROutputConsole->Printf(_L("TxPowerLevel: %ddBm\n"), txPowerLevel);
        }
  3. Get the Service Class UUIDs.

    // Get UUIDs
    RExtendedInquiryResponseUUIDContainer uuidContainer;
    error = eir.GetServiceClassUuids(uuidContainer);
    if(error >= KErrNone)
        {
        RArray<TUUID> uuids;
        TInt uuidCount = uuidContainer.UUIDs().Count();
        if(uuidCount > 0)
         {
            iHROutputConsole->Printf(_L("*** UUID Count: %d\n"), uuidCount);
            TInt i;
            for(i=0;i<uuidCount;i++)
                {
                TInt j;
                TPtrC8 uuid(uuidContainer.UUIDs()[i].ShortestForm());
                // Treat it as a big endian
                for(j=0;j<uuid.Length();j++)
                    {
                    iHROutputConsole->Printf(_L("%02X"), uuid[j]);
                    }
                    
                iHROutputConsole->Printf(_L(" \n"));
                }
            }
        }
  4. Get Manufacturer Specific data.

    Note: This data is entirely defined by the individual Manufacturer.

    // Get Manufacturer Specific Data
    length = eir.GetVendorSpecificDataLength();
    TBuf8<255> msd;
    if(length > 0)
        {
        error = eir.GetVendorSpecificData(msd);
        }
    else
        {
        error = length;
     }
    if(error == KErrNone)
    // we have Manufacturer Specific Data here
        {
        // This conversion is for display reason, in a real world this may not be necessary as 
        // Manufacturer specific data can be just raw 8-bit data, however GetDeviceName() is
        // different as it always return Unicode encoded 16-bit string
        error = CnvUtfConverter::ConvertToUnicodeFromUtf8(name, msd);
        if(error >= KErrNone && length > 0)
            {
            iHROutputConsole->Printf(_L("%d Bytes Manufacturer Specific Data: %S\n"), length, &name);
            }
        }
    }

Related information