/*! * \brief The Bluetooth Pairing Agent class * \details The implementation of the interface for the generated DBus interface * from the org.bluez.Agent1.xml. * * Interface Reference: * https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/agent-api.txt */ #include "BluetoothPairingAgent.h" // Qt #include // std #include // namespace using namespace Bluetooth; /*! * \brief BluetoothPairingAgent::BluetoothPairingAgent * \details Constructor * \param parent - QObject parent owner object. * Qt handles the children destruction by their parent objects life-cycle. */ BluetoothPairingAgent::BluetoothPairingAgent(QObject *parent) : QObject(parent) { } /*! * \brief BluetoothPairingAgent::Release * \details This method gets called when the service daemon * unregisters the agent. An agent can use it to do * cleanup tasks. There is no need to unregister the * agent, because when this method gets called it has * already been unregistered. */ void BluetoothPairingAgent::Release() const { //NOTE: Not needed yet, but must be here as it is expected by bluez. // This call is for unregistering agents, which we never do. } /*! * \brief BluetoothPairingAgent::RequestPinCode * \details This method gets called when the service daemon * needs to get the passkey for an authentication. * * \returns The return value should be a string of 1-16 characters * length. The string can be alphanumeric. */ QString BluetoothPairingAgent::RequestPinCode(const QDBusObjectPath &device) const { Q_UNUSED(device) return "1234"; } /*! * \brief BluetoothPairingAgent::DisplayPinCode * \details This method gets called when the service daemon * needs to display a pincode for an authentication. * * This is used during the pairing process of keyboards * that don't support Bluetooth 2.1 Secure Simple Pairing, * in contrast to DisplayPasskey which is used for those * that do. * * This method will only ever be called once since * older keyboards do not support typing notification. * * Note that the PIN will always be a 6-digit number, * zero-padded to 6 digits. This is for harmony with * the later specification. * * An empty reply should be returned. When the pincode * needs no longer to be displayed, the Cancel method * of the agent will be called. */ void BluetoothPairingAgent::DisplayPinCode(const QDBusObjectPath &device, const QString &pincode) { Q_UNUSED(device) emit showPinCode(pincode); } /*! * \brief BluetoothPairingAgent::RequestPasskey * \details This method gets called when the service daemon * needs to get the passkey for an authentication. * * \returns The return value should a numeric value between * 0-999999 */ uint BluetoothPairingAgent::RequestPasskey(const QDBusObjectPath &device) const { Q_UNUSED(device) return 1234; } /*! * \brief BluetoothPairingAgent::DisplayPasskey * \details This method gets called when the service daemon * needs to display a passkey for an authentication. * * The entered parameter indicates the number of already * typed keys on the remote side. * * An empty reply should be returned. When the passkey * needs no longer to be displayed, the Cancel method * of the agent will be called. * * During the pairing process this method might be * called multiple times to update the entered value. * * Note that the passkey will always be a 6-digit number, * so the display should be zero-padded at the start if * the value contains less than 6 digits. */ void BluetoothPairingAgent::DisplayPasskey(const QDBusObjectPath &device, uint passkey, ushort entered) { Q_UNUSED(device) emit showCode(passkey, entered); } /*! * \brief BluetoothPairingAgent::RequestConfirmation * \details This method gets called when the service daemon * needs to confirm a passkey for an authentication. * * To confirm the value it should return an empty reply * or an error in case the passkey is invalid. * * Note that the passkey will always be a 6-digit number, * so the display should be zero-padded at the start if * the value contains less than 6 digits. */ void BluetoothPairingAgent::RequestConfirmation(const QDBusObjectPath &device, uint passkey) { Q_UNUSED(device) emit showVerificationCode(passkey); } /*! * \brief BluetoothPairingAgent::RequestAuthorization * \details This method gets called to request the user to * authorize an incoming pairing attempt which * would in other circumstances trigger the just-works * model, or when the user plugged in a device that * implements cable pairing. In the latter case, the * device would not be connected to the adapter via * Bluetooth yet. */ void BluetoothPairingAgent::RequestAuthorization(const QDBusObjectPath &device) const { Q_UNUSED(device) //NOTE: Not needed yet, but must be here as it is expected by bluez } /*! * \brief BluetoothPairingAgent::AuthorizeService * \details This method gets called when the service daemon * needs to authorize a connection/service request. */ void BluetoothPairingAgent::AuthorizeService(const QDBusObjectPath &device, const QString &uuid) const { Q_UNUSED(device) Q_UNUSED(uuid) //NOTE: Not needed yet, but must be here as it is expected by bluez } /*! * \brief BluetoothPairingAgent::Cancel * \details This method gets called to indicate that the agent * request failed before a reply was returned. */ void BluetoothPairingAgent::Cancel() const { //NOTE: Not needed, but must be here as it is expected by bluez }