I'm trying to get bluetooth to do Simple Secure Pairing. Trying....



  • When I run this code on my embedded system, it give me a dialog on android
    Enter 0000 or 1234
    Both of course don't work.

    Any clues to what I might be doing wrong?
    (Been trying different things for about 4 days. :( )

    My StartServer function:
    m_pBluetoothDevice = new QBluetoothLocalDevice();

        m_pBluetoothDevice->setHostMode(QBluetoothLocalDevice::HostConnectable);
    
    
        QObject::connect(m_pBluetoothDevice, &QBluetoothLocalDevice::deviceConnected, this, &CTAKLrfGpsBluetoothServer::deviceConnected, Qt::QueuedConnection);
        QObject::connect(m_pBluetoothDevice, SIGNAL(pairingDisplayPinCode(QBluetoothAddress,QString)), this, SLOT(pairingDisplayPinCode(QBluetoothAddress,QString)));
        QObject::connect(m_pBluetoothDevice, SIGNAL(pairingDisplayConfirmation(QBluetoothAddress,QString)), this, SLOT(pairingDisplayConfirmation(QBluetoothAddress,QString)));
        QObject::connect(m_pBluetoothDevice, SIGNAL(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)), this, SLOT(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)));
        QObject::connect(m_pBluetoothDevice, SIGNAL(error(QBluetoothLocalDevice::Error)), this, SLOT(pairingError(QBluetoothLocalDevice::Error)));
    
    
        const QBluetoothAddress &localAdapter = QBluetoothAddress();
    
        m_pRfcommServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this);
        QObject::connect(m_pRfcommServer, &QBluetoothServer::newConnection, this, &CTAKLrfGpsBluetoothServer::newConnection, Qt::QueuedConnection);
    
        m_pRfcommServer->setSecurityFlags(QBluetooth::Authentication);
    
        bool result = m_pRfcommServer->listen(localAdapter);
        if (!result) {
            qWarning() << "**************** ERROR ERROR ERROR  **************************";
            qWarning() << "             Cannot bind TAK server to" << localAdapter.toString();
            qWarning() << "**************** ERROR ERROR ERROR  **************************";
            return;
        }
    
    
        //! [Class Uuuid must contain at least 1 entry]
        QBluetoothServiceInfo::Sequence classId;
    
        classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
        serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList,
                                 classId);
    
        classId.prepend(QVariant::fromValue(QBluetoothUuid(serviceUuid)));
    
        serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);
        serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList,classId);
        //! [Class Uuuid must contain at least 1 entry]
    
    
        //! [Service name, description and provider]
        serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, tr("Server"));
        serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceDescription,
                                 tr("Server"));
        serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, tr("company.com"));
        //! [Service name, description and provider]
    
        //! [Service UUID set]
        serviceInfo.setServiceUuid(QBluetoothUuid(serviceUuid));
        //! [Service UUID set]
    
        //! [Service Discoverability]
        QBluetoothServiceInfo::Sequence publicBrowse;
        publicBrowse << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
        serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList,
                                 publicBrowse);
        //! [Service Discoverability]
    
        //! [Protocol descriptor list]
        QBluetoothServiceInfo::Sequence protocolDescriptorList;
        QBluetoothServiceInfo::Sequence protocol;
        protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap));
        protocolDescriptorList.append(QVariant::fromValue(protocol));
        protocol.clear();
        protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
                 << QVariant::fromValue(quint8(m_pRfcommServer->serverPort()));
        protocolDescriptorList.append(QVariant::fromValue(protocol));
        serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
                                 protocolDescriptorList);
        //! [Protocol descriptor list]
    
        //! [Register service]
        serviceInfo.registerService(localAdapter);
        //! [Register service]
    
    
        m_pBluetoothDevice->setHostMode(QBluetoothLocalDevice::HostDiscoverable);

  • Lifetime Qt Champion

    Hi,

    What version of Qt are you using ?
    On what platform(s) ?



  • Using QT 5.6.2



  • Oh, and under ubuntu. (on embedded platform)


  • Lifetime Qt Champion

    Qt 5.6.2 is a bit outdated, any chance of testing against a more recent version of Qt ? 5.12 is the current and LTS release.



  • 5.10.1 does same thing.



  • Even though I specify secure in security call, I see a pin dialog pop up on android saying enter 0000 or 1234 (both don't work)



  • I found the solution.
    I needed to turn on SSP by using a call to the system
    system("hciconfig hci0 sspmode 1");


Log in to reply