diff --git a/dom/bluetooth2/BluetoothInterface.h b/dom/bluetooth2/BluetoothInterface.h index 9cc8a768f409..2ea7f51c477c 100644 --- a/dom/bluetooth2/BluetoothInterface.h +++ b/dom/bluetooth2/BluetoothInterface.h @@ -953,7 +953,7 @@ public: const nsAString& aPinCode, BluetoothResultHandler* aRes) = 0; - virtual void SspReply(const nsAString& aBdAddr, const nsAString& aVariant, + virtual void SspReply(const nsAString& aBdAddr, BluetoothSspVariant aVariant, bool aAccept, uint32_t aPasskey, BluetoothResultHandler* aRes) = 0; diff --git a/dom/bluetooth2/BluetoothPairingHandle.cpp b/dom/bluetooth2/BluetoothPairingHandle.cpp index de4f75a80cf9..33fbb0c90685 100644 --- a/dom/bluetooth2/BluetoothPairingHandle.cpp +++ b/dom/bluetooth2/BluetoothPairingHandle.cpp @@ -75,7 +75,7 @@ BluetoothPairingHandle::SetPinCode(const nsAString& aPinCode, ErrorResult& aRv) nsRefPtr promise = Promise::Create(global, aRv); NS_ENSURE_TRUE(!aRv.Failed(), nullptr); - BT_ENSURE_TRUE_REJECT(mType.EqualsLiteral("enterpincodereq"), + BT_ENSURE_TRUE_REJECT(mType.EqualsLiteral(PAIRING_REQ_TYPE_ENTERPINCODE), NS_ERROR_DOM_INVALID_STATE_ERR); BluetoothService* bs = BluetoothService::Get(); @@ -85,13 +85,13 @@ BluetoothPairingHandle::SetPinCode(const nsAString& aPinCode, ErrorResult& aRv) new BluetoothVoidReplyRunnable(nullptr /* DOMRequest */, promise, NS_LITERAL_STRING("SetPinCode")); - bs->SetPinCodeInternal(mDeviceAddress, aPinCode, result); + bs->PinReplyInternal(mDeviceAddress, true /* accept */, aPinCode, result); return promise.forget(); } already_AddRefed -BluetoothPairingHandle::SetPairingConfirmation(bool aConfirm, ErrorResult& aRv) +BluetoothPairingHandle::Accept(ErrorResult& aRv) { nsCOMPtr global = do_QueryInterface(GetParentObject()); if (!global) { @@ -102,24 +102,79 @@ BluetoothPairingHandle::SetPairingConfirmation(bool aConfirm, ErrorResult& aRv) nsRefPtr promise = Promise::Create(global, aRv); NS_ENSURE_TRUE(!aRv.Failed(), nullptr); - BT_ENSURE_TRUE_REJECT(mType.EqualsLiteral("pairingconfirmationreq"), + BT_ENSURE_TRUE_REJECT(mType.EqualsLiteral(PAIRING_REQ_TYPE_CONFIRMATION) || + mType.EqualsLiteral(PAIRING_REQ_TYPE_CONSENT), NS_ERROR_DOM_INVALID_STATE_ERR); BluetoothService* bs = BluetoothService::Get(); BT_ENSURE_TRUE_REJECT(bs, NS_ERROR_NOT_AVAILABLE); + BluetoothSspVariant variant; + BT_ENSURE_TRUE_REJECT(GetSspVariant(variant), NS_ERROR_DOM_OPERATION_ERR); + + nsRefPtr result = + new BluetoothVoidReplyRunnable(nullptr /* DOMRequest */, + promise, + NS_LITERAL_STRING("Accept")); + bs->SspReplyInternal( + mDeviceAddress, variant, true /* aAccept */, result); + + return promise.forget(); +} + +already_AddRefed +BluetoothPairingHandle::Reject(ErrorResult& aRv) +{ + nsCOMPtr global = do_QueryInterface(GetParentObject()); + if (!global) { + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } + + nsRefPtr promise = Promise::Create(global, aRv); + NS_ENSURE_TRUE(!aRv.Failed(), nullptr); + + BluetoothService* bs = BluetoothService::Get(); + BT_ENSURE_TRUE_REJECT(bs, NS_ERROR_NOT_AVAILABLE); + nsRefPtr result = new BluetoothVoidReplyRunnable(nullptr /* DOMRequest */, promise, - NS_LITERAL_STRING( - "SetPairingConfirmation")); + NS_LITERAL_STRING("Reject")); + + if (mType.EqualsLiteral(PAIRING_REQ_TYPE_ENTERPINCODE)) { // Pin request + bs->PinReplyInternal( + mDeviceAddress, false /* aAccept */, EmptyString(), result); + } else { // Ssp request + BluetoothSspVariant variant; + BT_ENSURE_TRUE_REJECT(GetSspVariant(variant), NS_ERROR_DOM_OPERATION_ERR); + + bs->SspReplyInternal( + mDeviceAddress, variant, false /* aAccept */, result); + } - bs->SetPairingConfirmationInternal(mDeviceAddress, - aConfirm, - result); return promise.forget(); } +bool +BluetoothPairingHandle::GetSspVariant(BluetoothSspVariant& aVariant) +{ + if (mType.EqualsLiteral(PAIRING_REQ_TYPE_DISPLAYPASSKEY)) { + aVariant = BluetoothSspVariant::SSP_VARIANT_PASSKEY_NOTIFICATION; + } else if (mType.EqualsLiteral(PAIRING_REQ_TYPE_CONFIRMATION)) { + aVariant = BluetoothSspVariant::SSP_VARIANT_PASSKEY_CONFIRMATION; + } else if (mType.EqualsLiteral(PAIRING_REQ_TYPE_CONSENT)) { + aVariant = BluetoothSspVariant::SSP_VARIANT_CONSENT; + } else { + BT_LOGR("Invalid SSP variant name: %s", + NS_ConvertUTF16toUTF8(mType).get()); + aVariant = SSP_VARIANT_PASSKEY_CONFIRMATION; // silences compiler warning + return false; + } + + return true; +} + JSObject* BluetoothPairingHandle::WrapObject(JSContext* aCx, JS::Handle aGivenProto) diff --git a/dom/bluetooth2/BluetoothPairingHandle.h b/dom/bluetooth2/BluetoothPairingHandle.h index 92434c3f035f..0584f9e8f05f 100644 --- a/dom/bluetooth2/BluetoothPairingHandle.h +++ b/dom/bluetooth2/BluetoothPairingHandle.h @@ -47,11 +47,15 @@ public: aPasskey = mPasskey; } + // Reply to the enterpincodereq pairing request already_AddRefed SetPinCode(const nsAString& aPinCode, ErrorResult& aRv); - already_AddRefed - SetPairingConfirmation(bool aConfirm, ErrorResult& aRv); + // Accept the pairingconfirmationreq or pairingconsentreq pairing request + already_AddRefed Accept(ErrorResult& aRv); + + // Reject the pairing request + already_AddRefed Reject(ErrorResult& aRv); private: BluetoothPairingHandle(nsPIDOMWindow* aOwner, @@ -60,6 +64,15 @@ private: const nsAString& aPasskey); ~BluetoothPairingHandle(); + /** + * Map mType into a BluetoothSspVariant enum value. + * + * @param aVariant [out] BluetoothSspVariant value mapped from mType. + * @return a boolean value to indicate whether mType can map into a + * BluetoothSspVariant value. + */ + bool GetSspVariant(BluetoothSspVariant& aVariant); + nsCOMPtr mOwner; nsString mDeviceAddress; nsString mType; diff --git a/dom/bluetooth2/BluetoothService.h b/dom/bluetooth2/BluetoothService.h index c12659c4f0b0..dd6fb6783f89 100644 --- a/dom/bluetooth2/BluetoothService.h +++ b/dom/bluetooth2/BluetoothService.h @@ -236,13 +236,35 @@ public: BluetoothProfileManagerBase* aManager) = 0; virtual void - SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode, + PinReplyInternal(const nsAString& aDeviceAddress, + bool aAccept, + const nsAString& aPinCode, + BluetoothReplyRunnable* aRunnable) = 0; + + virtual void + SspReplyInternal(const nsAString& aDeviceAddress, + BluetoothSspVariant aVariant, + bool aAccept, + BluetoothReplyRunnable* aRunnable) = 0; + + /** + * Legacy method used by bluez only to reply pincode request. + */ + virtual void + SetPinCodeInternal(const nsAString& aDeviceAddress, + const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable) = 0; + /** + * Legacy method used by bluez only to reply passkey entry request. + */ virtual void SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey, BluetoothReplyRunnable* aRunnable) = 0; + /** + * Legacy method used by bluez only to reply pairing confirmation request. + */ virtual void SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm, BluetoothReplyRunnable* aRunnable) = 0; diff --git a/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.cpp b/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.cpp index 540985f05f14..cbb83abf3c43 100644 --- a/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.cpp @@ -583,25 +583,6 @@ Convert(const nsAString& aIn, BluetoothServiceName& aOut) return NS_OK; } -nsresult -Convert(const nsAString& aIn, BluetoothSspVariant& aOut) -{ - if (aIn.EqualsLiteral("PasskeyConfirmation")) { - aOut = SSP_VARIANT_PASSKEY_CONFIRMATION; - } else if (aIn.EqualsLiteral("PasskeyEntry")) { - aOut = SSP_VARIANT_PASSKEY_ENTRY; - } else if (aIn.EqualsLiteral("Consent")) { - aOut = SSP_VARIANT_CONSENT; - } else if (aIn.EqualsLiteral("PasskeyNotification")) { - aOut = SSP_VARIANT_PASSKEY_NOTIFICATION; - } else { - BT_LOGR("Invalid SSP variant name: %s", NS_ConvertUTF16toUTF8(aIn).get()); - aOut = SSP_VARIANT_PASSKEY_CONFIRMATION; // silences compiler warning - return NS_ERROR_ILLEGAL_VALUE; - } - return NS_OK; -} - nsresult Convert(BluetoothAclState aIn, bool& aOut) { diff --git a/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.h b/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.h index a34fba81ec4b..533835caf12e 100644 --- a/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.h +++ b/dom/bluetooth2/bluedroid/BluetoothDaemonHelpers.h @@ -221,9 +221,6 @@ Convert(const nsAString& aIn, BluetoothPropertyType& aOut); nsresult Convert(const nsAString& aIn, BluetoothServiceName& aOut); -nsresult -Convert(const nsAString& aIn, BluetoothSspVariant& aOut); - nsresult Convert(BluetoothAclState aIn, bool& aOut); diff --git a/dom/bluetooth2/bluedroid/BluetoothDaemonInterface.cpp b/dom/bluetooth2/bluedroid/BluetoothDaemonInterface.cpp index 48d32364c8d7..aded08ac9b48 100644 --- a/dom/bluetooth2/bluedroid/BluetoothDaemonInterface.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothDaemonInterface.cpp @@ -569,7 +569,7 @@ public: return rv; } - nsresult SspReplyCmd(const nsAString& aBdAddr, const nsAString& aVariant, + nsresult SspReplyCmd(const nsAString& aBdAddr, BluetoothSspVariant aVariant, bool aAccept, uint32_t aPasskey, BluetoothResultHandler* aRes) { @@ -580,8 +580,7 @@ public: nsresult rv = PackPDU( PackConversion(aBdAddr), - PackConversion(aVariant), - aAccept, aPasskey, *pdu); + aVariant, aAccept, aPasskey, *pdu); if (NS_FAILED(rv)) { return rv; } @@ -2420,7 +2419,7 @@ BluetoothDaemonInterface::PinReply(const nsAString& aBdAddr, bool aAccept, void BluetoothDaemonInterface::SspReply(const nsAString& aBdAddr, - const nsAString& aVariant, + BluetoothSspVariant aVariant, bool aAccept, uint32_t aPasskey, BluetoothResultHandler* aRes) { diff --git a/dom/bluetooth2/bluedroid/BluetoothDaemonInterface.h b/dom/bluetooth2/bluedroid/BluetoothDaemonInterface.h index 805056bbc72e..13c28fa02574 100644 --- a/dom/bluetooth2/bluedroid/BluetoothDaemonInterface.h +++ b/dom/bluetooth2/bluedroid/BluetoothDaemonInterface.h @@ -83,7 +83,7 @@ public: const nsAString& aPinCode, BluetoothResultHandler* aRes); - void SspReply(const nsAString& aBdAddr, const nsAString& aVariant, + void SspReply(const nsAString& aBdAddr, BluetoothSspVariant aVariant, bool aAccept, uint32_t aPasskey, BluetoothResultHandler* aRes); diff --git a/dom/bluetooth2/bluedroid/BluetoothHALHelpers.cpp b/dom/bluetooth2/bluedroid/BluetoothHALHelpers.cpp index 6b6d4132c28a..8fa9150f8b68 100644 --- a/dom/bluetooth2/bluedroid/BluetoothHALHelpers.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothHALHelpers.cpp @@ -80,25 +80,6 @@ Convert(const nsAString& aIn, bt_bdaddr_t& aOut) return NS_OK; } -nsresult -Convert(const nsAString& aIn, bt_ssp_variant_t& aOut) -{ - if (aIn.EqualsLiteral("PasskeyConfirmation")) { - aOut = BT_SSP_VARIANT_PASSKEY_CONFIRMATION; - } else if (aIn.EqualsLiteral("PasskeyEntry")) { - aOut = BT_SSP_VARIANT_PASSKEY_ENTRY; - } else if (aIn.EqualsLiteral("Consent")) { - aOut = BT_SSP_VARIANT_CONSENT; - } else if (aIn.EqualsLiteral("PasskeyNotification")) { - aOut = BT_SSP_VARIANT_PASSKEY_NOTIFICATION; - } else { - BT_LOGR("Invalid SSP variant name: %s", NS_ConvertUTF16toUTF8(aIn).get()); - aOut = BT_SSP_VARIANT_PASSKEY_CONFIRMATION; // silences compiler warning - return NS_ERROR_ILLEGAL_VALUE; - } - return NS_OK; -} - nsresult Convert(const uint8_t aIn[16], bt_uuid_t& aOut) { diff --git a/dom/bluetooth2/bluedroid/BluetoothHALHelpers.h b/dom/bluetooth2/bluedroid/BluetoothHALHelpers.h index ebeb3fbcc8a2..af250e9dcb62 100644 --- a/dom/bluetooth2/bluedroid/BluetoothHALHelpers.h +++ b/dom/bluetooth2/bluedroid/BluetoothHALHelpers.h @@ -110,9 +110,6 @@ Convert(ConvertNamedValue& aIn, bt_property_t& aOut); nsresult Convert(const nsAString& aIn, bt_bdaddr_t& aOut); -nsresult -Convert(const nsAString& aIn, bt_ssp_variant_t& aOut); - inline nsresult Convert(const bt_ssp_variant_t& aIn, BluetoothSspVariant& aOut) { @@ -131,6 +128,24 @@ Convert(const bt_ssp_variant_t& aIn, BluetoothSspVariant& aOut) return NS_OK; } +inline nsresult +Convert(const BluetoothSspVariant& aIn, bt_ssp_variant_t& aOut) +{ + static const bt_ssp_variant_t sSspVariant[] = { + CONVERT(SSP_VARIANT_PASSKEY_CONFIRMATION, + BT_SSP_VARIANT_PASSKEY_CONFIRMATION), + CONVERT(SSP_VARIANT_PASSKEY_ENTRY, BT_SSP_VARIANT_PASSKEY_ENTRY), + CONVERT(SSP_VARIANT_CONSENT, BT_SSP_VARIANT_CONSENT), + CONVERT(SSP_VARIANT_PASSKEY_NOTIFICATION, + BT_SSP_VARIANT_PASSKEY_NOTIFICATION) + }; + if (aIn >= MOZ_ARRAY_LENGTH(sSspVariant)) { + return NS_ERROR_ILLEGAL_VALUE; + } + aOut = sSspVariant[aIn]; + return NS_OK; +} + inline nsresult Convert(const bool& aIn, uint8_t& aOut) { diff --git a/dom/bluetooth2/bluedroid/BluetoothHALInterface.cpp b/dom/bluetooth2/bluedroid/BluetoothHALInterface.cpp index 5ca1ddc5cd70..af72801b93c1 100644 --- a/dom/bluetooth2/bluedroid/BluetoothHALInterface.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothHALInterface.cpp @@ -769,7 +769,7 @@ BluetoothHALInterface::PinReply(const nsAString& aBdAddr, bool aAccept, void BluetoothHALInterface::SspReply(const nsAString& aBdAddr, - const nsAString& aVariant, + BluetoothSspVariant aVariant, bool aAccept, uint32_t aPasskey, BluetoothResultHandler* aRes) { diff --git a/dom/bluetooth2/bluedroid/BluetoothHALInterface.h b/dom/bluetooth2/bluedroid/BluetoothHALInterface.h index 4d43a73bb309..59679bc65742 100644 --- a/dom/bluetooth2/bluedroid/BluetoothHALInterface.h +++ b/dom/bluetooth2/bluedroid/BluetoothHALInterface.h @@ -69,7 +69,7 @@ public: const nsAString& aPinCode, BluetoothResultHandler* aRes); - void SspReply(const nsAString& aBdAddr, const nsAString& aVariant, + void SspReply(const nsAString& aBdAddr, BluetoothSspVariant aVariant, bool aAccept, uint32_t aPasskey, BluetoothResultHandler* aRes); diff --git a/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp b/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp index 6dbdfe564584..bc1731791b85 100644 --- a/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.cpp @@ -768,25 +768,18 @@ private: }; void -BluetoothServiceBluedroid::SetPinCodeInternal( - const nsAString& aDeviceAddress, const nsAString& aPinCode, - BluetoothReplyRunnable* aRunnable) +BluetoothServiceBluedroid::PinReplyInternal( + const nsAString& aDeviceAddress, bool aAccept, + const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable) { MOZ_ASSERT(NS_IsMainThread()); ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable); - sBtInterface->PinReply(aDeviceAddress, true, aPinCode, - new PinReplyResultHandler(aRunnable)); + sBtInterface->PinReply(aDeviceAddress, aAccept, aPinCode, + new PinReplyResultHandler(aRunnable)); } -void -BluetoothServiceBluedroid::SetPasskeyInternal( - const nsAString& aDeviceAddress, uint32_t aPasskey, - BluetoothReplyRunnable* aRunnable) -{ - return; -} class BluetoothServiceBluedroid::SspReplyResultHandler final : public BluetoothResultHandler @@ -811,19 +804,43 @@ private: }; void -BluetoothServiceBluedroid::SetPairingConfirmationInternal( - const nsAString& aDeviceAddress, bool aConfirm, - BluetoothReplyRunnable* aRunnable) +BluetoothServiceBluedroid::SspReplyInternal( + const nsAString& aDeviceAddress, BluetoothSspVariant aVariant, + bool aAccept, BluetoothReplyRunnable* aRunnable) { MOZ_ASSERT(NS_IsMainThread()); ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable); - sBtInterface->SspReply(aDeviceAddress, - NS_ConvertUTF8toUTF16("PasskeyConfirmation"), - aConfirm, 0, new SspReplyResultHandler(aRunnable)); + sBtInterface->SspReply(aDeviceAddress, aVariant, aAccept, 0 /* passkey */, + new SspReplyResultHandler(aRunnable)); } +void +BluetoothServiceBluedroid::SetPinCodeInternal( + const nsAString& aDeviceAddress, const nsAString& aPinCode, + BluetoothReplyRunnable* aRunnable) +{ + // Legacy method used by bluez only. +} + +void +BluetoothServiceBluedroid::SetPasskeyInternal( + const nsAString& aDeviceAddress, uint32_t aPasskey, + BluetoothReplyRunnable* aRunnable) +{ + // Legacy method used by bluez only. +} + +void +BluetoothServiceBluedroid::SetPairingConfirmationInternal( + const nsAString& aDeviceAddress, bool aConfirm, + BluetoothReplyRunnable* aRunnable) +{ + // Legacy method used by bluez only. +} + + void BluetoothServiceBluedroid::NextBluetoothProfileController() { diff --git a/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.h b/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.h index b7791b9c7b31..0e317fdbb44e 100644 --- a/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.h +++ b/dom/bluetooth2/bluedroid/BluetoothServiceBluedroid.h @@ -81,15 +81,30 @@ public: BluetoothReplyRunnable* aRunnable); virtual void - SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode, + PinReplyInternal(const nsAString& aDeviceAddress, + bool aAccept, + const nsAString& aPinCode, + BluetoothReplyRunnable* aRunnable); + + virtual void + SspReplyInternal(const nsAString& aDeviceAddress, + BluetoothSspVariant aVariant, + bool aAccept, + BluetoothReplyRunnable* aRunnable); + + virtual void + SetPinCodeInternal(const nsAString& aDeviceAddress, + const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable); virtual void - SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey, + SetPasskeyInternal(const nsAString& aDeviceAddress, + uint32_t aPasskey, BluetoothReplyRunnable* aRunnable); virtual void - SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm, + SetPairingConfirmationInternal(const nsAString& aDeviceAddress, + bool aConfirm, BluetoothReplyRunnable* aRunnable); virtual void diff --git a/dom/bluetooth2/bluez/BluetoothDBusService.cpp b/dom/bluetooth2/bluez/BluetoothDBusService.cpp index 4979f1c71308..2a022a6bc2ba 100644 --- a/dom/bluetooth2/bluez/BluetoothDBusService.cpp +++ b/dom/bluetooth2/bluez/BluetoothDBusService.cpp @@ -4277,6 +4277,10 @@ BluetoothDBusService::UpdateNotification(ControlEventId aEventId, DispatchToDBusThread(task); } +// +// Methods for BT APIv2 implementation which currently only supports bluedroid +// + void BluetoothDBusService::ConnectGattClientInternal( const nsAString& aAppUuid, const nsAString& aDeviceAddress, @@ -4309,3 +4313,17 @@ BluetoothDBusService::GattClientReadRemoteRssiInternal( BluetoothReplyRunnable* aRunnable) { } + +void +BluetoothDBusService::PinReplyInternal( + const nsAString& aDeviceAddress, bool aAccept, + const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable) +{ +} + +void +BluetoothDBusService::SspReplyInternal( + const nsAString& aDeviceAddress, BluetoothSspVariant aVariant, + bool aAccept, BluetoothReplyRunnable* aRunnable) +{ +} diff --git a/dom/bluetooth2/bluez/BluetoothDBusService.h b/dom/bluetooth2/bluez/BluetoothDBusService.h index 48b89eb75af5..e7af51539bb7 100644 --- a/dom/bluetooth2/bluez/BluetoothDBusService.h +++ b/dom/bluetooth2/bluez/BluetoothDBusService.h @@ -94,7 +94,20 @@ public: BluetoothReplyRunnable* aRunnable) override; virtual void - SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode, + PinReplyInternal(const nsAString& aDeviceAddress, + bool aAccept, + const nsAString& aPinCode, + BluetoothReplyRunnable* aRunnable) + + virtual void + SspReplyInternal(const nsAString& aDeviceAddress, + BluetoothSspVariant aVariant, + bool aAccept, + BluetoothReplyRunnable* aRunnable) + + virtual void + SetPinCodeInternal(const nsAString& aDeviceAddress, + const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable) override; virtual void @@ -102,7 +115,8 @@ public: BluetoothReplyRunnable* aRunnable) override; virtual void - SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm, + SetPairingConfirmationInternal(const nsAString& aDeviceAddress, + bool aConfirm, BluetoothReplyRunnable* aRunnable) override; virtual void diff --git a/dom/bluetooth2/ipc/BluetoothMessageUtils.h b/dom/bluetooth2/ipc/BluetoothMessageUtils.h index 85ddf4a72454..03395ce7832b 100644 --- a/dom/bluetooth2/ipc/BluetoothMessageUtils.h +++ b/dom/bluetooth2/ipc/BluetoothMessageUtils.h @@ -20,6 +20,14 @@ struct ParamTraits mozilla::dom::bluetooth::TYPE_INVALID> { }; +template <> +struct ParamTraits + : public ContiguousEnumSerializer< + mozilla::dom::bluetooth::BluetoothSspVariant, + mozilla::dom::bluetooth::SSP_VARIANT_PASSKEY_CONFIRMATION, + mozilla::dom::bluetooth::SSP_VARIANT_PASSKEY_NOTIFICATION> +{ }; + template <> struct ParamTraits : public ContiguousEnumSerializer< diff --git a/dom/bluetooth2/ipc/BluetoothParent.cpp b/dom/bluetooth2/ipc/BluetoothParent.cpp index 5f14904cb7aa..84f49bd16c2e 100644 --- a/dom/bluetooth2/ipc/BluetoothParent.cpp +++ b/dom/bluetooth2/ipc/BluetoothParent.cpp @@ -212,6 +212,10 @@ BluetoothParent::RecvPBluetoothRequestConstructor( return actor->DoRequest(aRequest.get_ConnectedDevicePropertiesRequest()); case Request::TFetchUuidsRequest: return actor->DoRequest(aRequest.get_FetchUuidsRequest()); + case Request::TPinReplyRequest: + return actor->DoRequest(aRequest.get_PinReplyRequest()); + case Request::TSspReplyRequest: + return actor->DoRequest(aRequest.get_SspReplyRequest()); case Request::TSetPinCodeRequest: return actor->DoRequest(aRequest.get_SetPinCodeRequest()); case Request::TSetPasskeyRequest: @@ -470,6 +474,34 @@ BluetoothRequestParent::DoRequest(const FetchUuidsRequest& aRequest) return true; } +bool +BluetoothRequestParent::DoRequest(const PinReplyRequest& aRequest) +{ + MOZ_ASSERT(mService); + MOZ_ASSERT(mRequestType == Request::TPinReplyRequest); + + mService->PinReplyInternal(aRequest.address(), + aRequest.accept(), + aRequest.pinCode(), + mReplyRunnable.get()); + + return true; +} + +bool +BluetoothRequestParent::DoRequest(const SspReplyRequest& aRequest) +{ + MOZ_ASSERT(mService); + MOZ_ASSERT(mRequestType == Request::TSspReplyRequest); + + mService->SspReplyInternal(aRequest.address(), + aRequest.variant(), + aRequest.accept(), + mReplyRunnable.get()); + + return true; +} + bool BluetoothRequestParent::DoRequest(const SetPinCodeRequest& aRequest) { diff --git a/dom/bluetooth2/ipc/BluetoothParent.h b/dom/bluetooth2/ipc/BluetoothParent.h index 07a1973e8271..9f94bb18cf65 100644 --- a/dom/bluetooth2/ipc/BluetoothParent.h +++ b/dom/bluetooth2/ipc/BluetoothParent.h @@ -173,6 +173,12 @@ protected: bool DoRequest(const DenyPairingConfirmationRequest& aRequest); + bool + DoRequest(const PinReplyRequest& aRequest); + + bool + DoRequest(const SspReplyRequest& aRequest); + bool DoRequest(const ConnectRequest& aRequest); diff --git a/dom/bluetooth2/ipc/BluetoothServiceChildProcess.cpp b/dom/bluetooth2/ipc/BluetoothServiceChildProcess.cpp index 6347061bf94e..73cb8a7d60b9 100644 --- a/dom/bluetooth2/ipc/BluetoothServiceChildProcess.cpp +++ b/dom/bluetooth2/ipc/BluetoothServiceChildProcess.cpp @@ -208,6 +208,28 @@ BluetoothServiceChildProcess::UpdateSdpRecords(const nsAString& aDeviceAddress, MOZ_CRASH("This should never be called!"); } +void +BluetoothServiceChildProcess::PinReplyInternal( + const nsAString& aDeviceAddress, bool aAccept, + const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable) +{ + SendRequest(aRunnable, + PinReplyRequest(nsString(aDeviceAddress), + aAccept, + nsString(aPinCode))); +} + +void +BluetoothServiceChildProcess::SspReplyInternal( + const nsAString& aDeviceAddress, BluetoothSspVariant aVariant, + bool aAccept, BluetoothReplyRunnable* aRunnable) +{ + SendRequest(aRunnable, + SspReplyRequest(nsString(aDeviceAddress), + aVariant, + aAccept)); +} + void BluetoothServiceChildProcess::SetPinCodeInternal( const nsAString& aDeviceAddress, diff --git a/dom/bluetooth2/ipc/BluetoothServiceChildProcess.h b/dom/bluetooth2/ipc/BluetoothServiceChildProcess.h index 5fd814b17910..c88b0ba746b1 100644 --- a/dom/bluetooth2/ipc/BluetoothServiceChildProcess.h +++ b/dom/bluetooth2/ipc/BluetoothServiceChildProcess.h @@ -110,6 +110,18 @@ public: BluetoothReplyRunnable* aRunnable) override; + virtual void + PinReplyInternal(const nsAString& aDeviceAddress, + bool aAccept, + const nsAString& aPinCode, + BluetoothReplyRunnable* aRunnable) override; + + virtual void + SspReplyInternal(const nsAString& aDeviceAddress, + BluetoothSspVariant aVariant, + bool aAccept, + BluetoothReplyRunnable* aRunnable) override; + virtual void Connect(const nsAString& aDeviceAddress, uint32_t aCod, diff --git a/dom/bluetooth2/ipc/BluetoothTypes.ipdlh b/dom/bluetooth2/ipc/BluetoothTypes.ipdlh index 958c59508f70..a3d71dab9e43 100644 --- a/dom/bluetooth2/ipc/BluetoothTypes.ipdlh +++ b/dom/bluetooth2/ipc/BluetoothTypes.ipdlh @@ -8,6 +8,8 @@ using mozilla::dom::bluetooth::BluetoothGattId from "mozilla/dom/bluetooth/BluetoothCommon.h"; using mozilla::dom::bluetooth::BluetoothGattServiceId from "mozilla/dom/bluetooth/BluetoothCommon.h"; +using mozilla::dom::bluetooth::BluetoothSspVariant + from "mozilla/dom/bluetooth/BluetoothCommon.h"; using mozilla::dom::bluetooth::BluetoothStatus from "mozilla/dom/bluetooth/BluetoothCommon.h"; diff --git a/dom/bluetooth2/ipc/PBluetooth.ipdl b/dom/bluetooth2/ipc/PBluetooth.ipdl index 8582e2d236f8..3285e64bc57c 100644 --- a/dom/bluetooth2/ipc/PBluetooth.ipdl +++ b/dom/bluetooth2/ipc/PBluetooth.ipdl @@ -64,6 +64,20 @@ struct UnpairRequest nsString address; }; +struct PinReplyRequest +{ + nsString address; + bool accept; + nsString pinCode; +}; + +struct SspReplyRequest +{ + nsString address; + BluetoothSspVariant variant; + bool accept; +}; + struct SetPinCodeRequest { nsString path; @@ -215,6 +229,8 @@ union Request StopDiscoveryRequest; PairRequest; UnpairRequest; + PinReplyRequest; + SspReplyRequest; SetPinCodeRequest; SetPasskeyRequest; ConfirmPairingConfirmationRequest; diff --git a/dom/webidl/BluetoothPairingHandle.webidl b/dom/webidl/BluetoothPairingHandle.webidl index ad75fdcddc93..0159fdb0cb7a 100644 --- a/dom/webidl/BluetoothPairingHandle.webidl +++ b/dom/webidl/BluetoothPairingHandle.webidl @@ -13,8 +13,22 @@ interface BluetoothPairingHandle */ readonly attribute DOMString passkey; + /** + * Reply pin code for enterpincodereq. The promise will be rejected if the + * pairing request type is not enterpincodereq or operation fails. + */ [NewObject] Promise setPinCode(DOMString aPinCode); + + /** + * Accept pairing requests. The promise will be rejected if the pairing + * request type is not pairingconfirmationreq or pairingconsentreq or + * operation fails. + */ [NewObject] - Promise setPairingConfirmation(boolean aConfirm); + Promise accept(); + + // Reject pairing requests. The promise will be rejected if operation fails. + [NewObject] + Promise reject(); };