Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Platform] Failed encoding invalid payload with setupCommissioningSession #31129

Closed
law-ko opened this issue Dec 20, 2023 · 10 comments · Fixed by #31132
Closed

[Platform] Failed encoding invalid payload with setupCommissioningSession #31129

law-ko opened this issue Dec 20, 2023 · 10 comments · Fixed by #31132

Comments

@law-ko
Copy link

law-ko commented Dec 20, 2023

Reproduction steps

We are trying to commission a device without using QRcode, but Matter returns invalid payload, which we do not know what information is missing.

Setup:

self.setupPayload = MTRSetupPayload(setupPasscode: passcode, discriminator: NSNumber(value: 3840))
self.matterController!.setDeviceControllerDelegate(self, queue: self.queue)
let deviceId = MTRGetNextAvailableDeviceID()
MTRSetNextAvailableDeviceID(deviceId+1)
if self.setupPayload != nil
    && self.matterController != nil {
    try self.matterController!.setupCommissioningSession(
        with: self.setupPayload!,
        newNodeID: NSNumber(value: deviceId))
}

The log shows:

self.setupPayload.setupPasscode:  Optional(531748882)
self.setupPayload.discriminator:  Optional(3840)
self.setupPayload.productID:  Optional(0)
self.setupPayload.vendorID:  Optional(0)
★deviceId: 9
2023-12-20 17:17:25.235487+0800 Invis[45799:2887819] [SetupPayload] Failed encoding invalid payload
2023-12-20 17:17:25.235588+0800 Invis[45799:2887819] [Default] Error(/Library/Caches/com.apple.xbs/Sources/CHIPFramework/connectedhomeip/src/darwin/Framework/CHIP/MTRDeviceController.mm:394: CHIP Error 0x0000002F: Invalid argument): Generating Manual Pairing Code failed
Error Domain=MTRErrorDomain Code=4 "An argument is invalid." UserInfo={NSLocalizedDescription=An argument is invalid., underlyingError=<MTRErrorHolder: 0x28372dfe0>}

Why does generating the manual pairing code failed?

Thank you.

Platform

darwin

Platform Version(s)

16.4

Type

Manually tested with SDK

(Optional) If manually tested please explain why this is only manually tested

Tested on iPhone with 16.4.1

Anything else?

No response

@bzbarsky-apple
Copy link
Contributor

The payload cannot be represented as either a QR code (does not have a discovery capabilities bitmask set) or a numeric code (has a long discriminator), which is why it's considered invalid.

I'll change the init bits to not create an invalid payload, but in the meantime setting its discoveryCapabilities to the right thing should help your case.

bzbarsky-apple added a commit to bzbarsky-apple/connectedhomeip that referenced this issue Dec 20, 2023
…oads.

It's using a long discriminator, so has to have discovery capabilities
available.

Fixes project-chip#31129
@law-ko
Copy link
Author

law-ko commented Dec 20, 2023

@bzbarsky-apple We have two senarios:

  1. If the device is never being commissioned, then the user may enter pairing code instead of scanning.
  2. If the device is already being commissioned (which is currently connected to a Wi-Fi network), then the user may want to add the device onto our custom app, which uses the Turn on Pairing Mode or openCommissioningWindow code that generates the passcode.

We are unsure which function to use and how to pass in the pairing code/passcode.

@bzbarsky-apple
Copy link
Contributor

@law-ko For that first scenario, when a user enters a "pairing code" (I assume you mean a Matter numeric code), you can create a MTRSetupPayload directly from it, right? Something like:

self.setupPayload = MTRSetupPayload(onboardingPayload: whateverUserEntered)

That works for both QR codes and numeric codes.

For the second scenario... I am confused about what the question is. If you use the API you linked to, then the MTRSetupPayload you should for setting up the commissioning session use will be returned from the API, no?

We are unsure which function to use and how to pass in the pairing code/passcode.

Just so we are on the same page: those are not the same thing, right? A pairing code is either a QR code or numeric code that encodes the passcode and some other information (e.g. the discriminator).

@bzbarsky-apple
Copy link
Contributor

In general, you should probably not be using MTRSetupPayload(setupPasscode: ....) at all.

@law-ko
Copy link
Author

law-ko commented Dec 21, 2023

@bzbarsky-apple
For the second scenario (like in attached image), what MTR function should we use?
image

@law-ko
Copy link
Author

law-ko commented Dec 21, 2023

@bzbarsky-apple
For the second scenario (like in attached image), what MTR function should we use?
image

@bzbarsky-apple Same function MTRSetupPayload(onboardingPayload: self.payloadCode) would work. However, is there any way to know the device is already commissioned (connected to the Wi-Fi network) so the app can skip the entering Wi-Fi credentials?

@mergify mergify bot closed this as completed in #31132 Dec 22, 2023
mergify bot pushed a commit that referenced this issue Dec 22, 2023
…oads. (#31132)

It's using a long discriminator, so has to have discovery capabilities
available.

Fixes #31129
@law-ko
Copy link
Author

law-ko commented Dec 22, 2023

@bzbarsky-apple
For the second scenario (like in attached image), what MTR function should we use?
image

@bzbarsky-apple Same function MTRSetupPayload(onboardingPayload: self.payloadCode) would work. However, is there any way to know the device is already commissioned (connected to the Wi-Fi network) so the app can skip the entering Wi-Fi credentials?

@bzbarsky-apple I see this issue is closed, are you able to provide some information that I asked above?

@bzbarsky-apple
Copy link
Contributor

@law-ko If you know the device is on the network already, setting the discoveryCapabilities to on-network only should work, I would think...

@law-ko
Copy link
Author

law-ko commented Dec 22, 2023

@bzbarsky-apple Is there any chance to know if the device is on the network already based on any MTR commands or based on the payloadCode?

@bzbarsky-apple
Copy link
Contributor

If you have a QR code, then "maybe", since that can indicate how the device is discoverable.

With a numeric code, no.

I'm not sure what you mean by "MTR commands". Do you mean "Matter framework APIs that do not involve having a secure connection to the device"? If so, there are no such APIs that can tell you the device is on-network.

ksperling-apple added a commit to ksperling-apple/connectedhomeip that referenced this issue Apr 29, 2024
ksperling-apple added a commit to ksperling-apple/connectedhomeip that referenced this issue Apr 29, 2024
mergify bot pushed a commit that referenced this issue Apr 30, 2024
* Darwin Tests: Make MTRSetupPayload initialization test reliable

Also rename the tests to more conventional names.

* Add regression test for #31129

* Add regression test for #23357

* Add test for NSSecureCoding support

* Darwin: Tidy up MTRSetupPayload headers / includes

* Darwin: return nil on error in MTRSetupPayload getAllOptionalVendorData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
2 participants