Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. I'm trying to get bluetooth to do Simple Secure Pairing. Trying....
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 2 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • WalterWhiteW Offline
    WalterWhiteW Offline
    WalterWhite
    wrote on last edited by WalterWhite
    #1

    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);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • WalterWhiteW Offline
        WalterWhiteW Offline
        WalterWhite
        wrote on last edited by
        #3

        Using QT 5.6.2

        1 Reply Last reply
        0
        • WalterWhiteW Offline
          WalterWhiteW Offline
          WalterWhite
          wrote on last edited by
          #4

          Oh, and under ubuntu. (on embedded platform)

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • WalterWhiteW Offline
              WalterWhiteW Offline
              WalterWhite
              wrote on last edited by
              #6

              5.10.1 does same thing.

              1 Reply Last reply
              0
              • WalterWhiteW Offline
                WalterWhiteW Offline
                WalterWhite
                wrote on last edited by
                #7

                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)

                1 Reply Last reply
                0
                • WalterWhiteW Offline
                  WalterWhiteW Offline
                  WalterWhite
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved