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

UDC handling and Commissioner Passcode TXT record #31432

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 92 additions & 3 deletions examples/platform/linux/CommissioneeShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace chip {
namespace Shell {

#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
static CHIP_ERROR SendUDC(bool printHeader, chip::Transport::PeerAddress commissioner)
static CHIP_ERROR SendUDC(bool printHeader, chip::Transport::PeerAddress commissioner,
Protocols::UserDirectedCommissioning::IdentificationDeclaration id)
{
streamer_t * sout = streamer_get();

Expand All @@ -46,7 +47,7 @@ static CHIP_ERROR SendUDC(bool printHeader, chip::Transport::PeerAddress commiss
streamer_printf(sout, "SendUDC: ");
}

Server::GetInstance().SendUserDirectedCommissioningRequest(commissioner);
Server::GetInstance().SendUserDirectedCommissioningRequest(commissioner, id);

streamer_printf(sout, "done\r\n");

Expand All @@ -60,6 +61,13 @@ static CHIP_ERROR PrintAllCommands()
streamer_printf(sout, " help Usage: commissionee <subcommand>\r\n");
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
streamer_printf(sout, " sendudc <address> <port> Send UDC message to address. Usage: commissionee sendudc ::1 5543\r\n");
streamer_printf(sout, " udccancel <address> <port> Send UDC cancel message to address. Usage: cast udccancel ::1 5543\r\n");
streamer_printf(sout,
" udccommissionerpasscode <address> <port> [CommissionerPasscodeReady] [PairingHint] [PairingInst] Send UDC "
"commissioner passcode message to address. Usage: udccommissionerpasscode ::1 5543 t 5 HelloWorld\r\n");
streamer_printf(sout,
" testudc <address> <port> [NoPasscode] [CdUponPasscodeDialog] [vid] [PairingHint] [PairingInst] Send UDC "
"message to address. Usage: cast testudc ::1 5543 t t 5 HelloWorld\r\n");
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
// TODO: Figure out whether setdiscoverytimeout is a reasonable thing to do
// at all, and if so what semantics it should have. Presumably it should
Expand Down Expand Up @@ -92,12 +100,93 @@ static CHIP_ERROR CommissioneeHandler(int argc, char ** argv)
}
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
if (strcmp(argv[0], "sendudc") == 0)
{
Protocols::UserDirectedCommissioning::IdentificationDeclaration id;

char * eptr;
chip::Inet::IPAddress commissioner;
chip::Inet::IPAddress::FromString(argv[1], commissioner);
uint16_t port = (uint16_t) strtol(argv[2], &eptr, 10);

return SendUDC(true, chip::Transport::PeerAddress::UDP(commissioner, port), id);
}
if (strcmp(argv[0], "udccancel") == 0)
{
char * eptr;
chip::Inet::IPAddress commissioner;
chip::Inet::IPAddress::FromString(argv[1], commissioner);
uint16_t port = (uint16_t) strtol(argv[2], &eptr, 10);

Protocols::UserDirectedCommissioning::IdentificationDeclaration id;
id.SetCancelPasscode(true);
return Server::GetInstance().SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress::UDP(commissioner, port),
id);
}
if (strcmp(argv[0], "udccommissionerpasscode") == 0)
{
char * eptr;
chip::Inet::IPAddress commissioner;
chip::Inet::IPAddress::FromString(argv[1], commissioner);
uint16_t port = (uint16_t) strtol(argv[2], &eptr, 10);
return SendUDC(true, chip::Transport::PeerAddress::UDP(commissioner, port));

// udccommissionerpasscode <address> <port> [CommissionerPasscodeReady] [PairingHint] [PairingInst]
// ex. udccommissionerpasscode <address> <port> t 5 'hello world'

Protocols::UserDirectedCommissioning::IdentificationDeclaration id;
id.SetCommissionerPasscode(true);
if (argc > 3)
{
id.SetCommissionerPasscodeReady(strcmp(argv[3], "t") == 0);
}
if (argc > 4)
{
uint16_t hint = (uint16_t) strtol(argv[4], &eptr, 10);
id.SetPairingHint(hint);
}
if (argc > 5)
{
id.SetPairingInst(argv[5]);
}
return Server::GetInstance().SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress::UDP(commissioner, port),
id);
}
if (strcmp(argv[0], "testudc") == 0)
{
char * eptr;
chip::Inet::IPAddress commissioner;
chip::Inet::IPAddress::FromString(argv[1], commissioner);
uint16_t port = (uint16_t) strtol(argv[2], &eptr, 10);

// sendudc <address> <port> [NoPasscode] [CdUponPasscodeDialog] [vid] [PairingHint] [PairingInst]
// ex. sendudc <address> <port> t t 111 5 'hello world'

Protocols::UserDirectedCommissioning::IdentificationDeclaration id;
if (argc > 3)
{
id.SetNoPasscode(strcmp(argv[3], "t") == 0);
}
if (argc > 4)
{
id.SetCdUponPasscodeDialog(strcmp(argv[4], "t") == 0);
}
if (argc > 5)
{
uint16_t vid = (uint16_t) strtol(argv[5], &eptr, 10);
Protocols::UserDirectedCommissioning::TargetAppInfo info;
info.vendorId = vid;
id.AddTargetAppInfo(info);
}
if (argc > 6)
{
uint16_t hint = (uint16_t) strtol(argv[6], &eptr, 10);
id.SetPairingHint(hint);
}
if (argc > 7)
{
id.SetPairingInst(argv[7]);
}
return Server::GetInstance().SendUserDirectedCommissioningRequest(chip::Transport::PeerAddress::UDP(commissioner, port),
id);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
// TODO: Figure out whether setdiscoverytimeout is a reasonable thing to do
Expand Down
12 changes: 6 additions & 6 deletions examples/platform/linux/ControllerShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ static CHIP_ERROR ControllerHandler(int argc, char ** argv)
{
if (argc >= 3)
{
uint32_t pincode = (uint32_t) strtol(argv[2], &eptr, 10);
GetCommissionerDiscoveryController()->CommissionWithPincode(pincode);
uint32_t passcode = (uint32_t) strtol(argv[2], &eptr, 10);
GetCommissionerDiscoveryController()->CommissionWithPasscode(passcode);
return CHIP_NO_ERROR;
}
GetCommissionerDiscoveryController()->Ok();
Expand All @@ -280,15 +280,15 @@ static CHIP_ERROR ControllerHandler(int argc, char ** argv)
}
else if (strcmp(argv[0], "udc-commission") == 0)
{
// udc-commission pincode index
// udc-commission passcode index
if (argc < 3)
{
return PrintAllCommands();
}
char * eptr;
uint32_t pincode = (uint32_t) strtol(argv[1], &eptr, 10);
size_t index = (size_t) strtol(argv[2], &eptr, 10);
return pairUDC(true, pincode, index);
uint32_t passcode = (uint32_t) strtol(argv[1], &eptr, 10);
size_t index = (size_t) strtol(argv[2], &eptr, 10);
return pairUDC(true, passcode, index);
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

Expand Down
47 changes: 46 additions & 1 deletion examples/tv-app/android/java/MyUserPrompter-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ void JNIMyUserPrompter::PromptForCommissionOKPermission(uint16_t vendorId, uint1
* If user responds with Cancel then implementor calls UserPrompterResolver.OnPinCodeDeclined();
*
*/
void JNIMyUserPrompter::PromptForCommissionPincode(uint16_t vendorId, uint16_t productId, const char * commissioneeName)
void JNIMyUserPrompter::PromptForCommissionPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName,
uint16_t pairingHint, const char * pairingInstruction)
{
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
Expand Down Expand Up @@ -148,6 +149,50 @@ void JNIMyUserPrompter::PromptForCommissionPincode(uint16_t vendorId, uint16_t p
}
}

/**
* Called to when CancelCommissioning is received via UDC.
* Indicates that commissioner can stop showing the passcode entry or display dialog.
* For example, can show text such as "Commissioning cancelled by client" before hiding dialog.
*/
void JNIMyUserPrompter::HidePromptsOnCancel(uint16_t vendorId, uint16_t productId, const char * commissioneeName)
{
// TODO
ChipLogError(Zcl, "JNIMyUserPrompter::HidePromptsOnCancel Needs Implementation");
}

/**
* Return true if this UserPrompter displays QR code along with passcode
* When PromptWithCommissionerPasscode is called during Commissioner Passcode functionality.
*/
bool JNIMyUserPrompter::DisplaysPasscodeAndQRCode()
{
// TODO
ChipLogError(Zcl, "JNIMyUserPrompter::DisplaysPasscodeAndQRCode Needs Implementation");
return false;
}

/**
* Called to display the given setup passcode to the user,
* for commissioning the given commissioneeName with the given vendorId and productId,
* and provide instructions for where to enter it in the commissionee (when pairingHint and pairingInstruction are provided).
* For example "Casting Passcode: [passcode]. For more instructions, click here."
*/
void JNIMyUserPrompter::PromptWithCommissionerPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName,
uint32_t passcode, uint16_t pairingHint, const char * pairingInstruction)
{
// TODO
ChipLogError(Zcl, "JNIMyUserPrompter::PromptWithCommissionerPasscode Needs Implementation");
}

/**
* Called to alert the user that commissioning has begun."
*/
void JNIMyUserPrompter::PromptCommissioningStarted(uint16_t vendorId, uint16_t productId, const char * commissioneeName)
{
// TODO
ChipLogError(Zcl, "JNIMyUserPrompter::PromptCommissioningStarted Needs Implementation");
}

/*
* Called to notify the user that commissioning succeeded. It can be in form of UI Notification.
*/
Expand Down
9 changes: 8 additions & 1 deletion examples/tv-app/android/java/MyUserPrompter-JNI.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@
class JNIMyUserPrompter : public UserPrompter
{
public:
// TODO
JNIMyUserPrompter(jobject prompter);
void PromptForCommissionOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override;
void PromptForCommissionPincode(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override;
void PromptForCommissionPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName, uint16_t pairingHint,
const char * pairingInstruction) override;
void HidePromptsOnCancel(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override;
bool DisplaysPasscodeAndQRCode() override;
void PromptWithCommissionerPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName, uint32_t passcode,
uint16_t pairingHint, const char * pairingInstruction) override;
void PromptCommissioningStarted(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override;
void PromptCommissioningSucceeded(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override;
void PromptCommissioningFailed(const char * commissioneeName, CHIP_ERROR error) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ JNI_METHOD(void, OnPinCodeEntered)(JNIEnv *, jobject, jint jPinCode)
chip::DeviceLayer::StackLock lock;
uint32_t pinCode = (uint32_t) jPinCode;
ChipLogProgress(Zcl, "OnPinCodeEntered %d", pinCode);
GetCommissionerDiscoveryController()->CommissionWithPincode(pinCode);
GetCommissionerDiscoveryController()->CommissionWithPasscode(pinCode);
#endif
}

Expand Down
20 changes: 16 additions & 4 deletions examples/tv-app/android/java/TVApp-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,23 @@ JNI_METHOD(void, setChipDeviceEventProvider)(JNIEnv *, jobject, jobject provider
}

#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
class MyPincodeService : public PincodeService
class MyPincodeService : public PasscodeService
{
uint32_t FetchCommissionPincodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override
bool HasTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId,
chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info, uint32_t & passcode) override
{
return ContentAppPlatform::GetInstance().GetPincodeFromContentApp(vendorId, productId, rotatingId);
return ContentAppPlatform::GetInstance().HasTargetContentApp(vendorId, productId, rotatingId, info, passcode);
}

uint32_t GetCommissionerPasscode(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId) override
{
// TODO: randomly generate this value
return 12345678;
}

uint32_t FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override
{
return ContentAppPlatform::GetInstance().GetPasscodeFromContentApp(vendorId, productId, rotatingId);
}
};
MyPincodeService gMyPincodeService;
Expand Down Expand Up @@ -329,7 +341,7 @@ void TvAppJNI::InitializeCommissioner(JNIMyUserPrompter * userPrompter)
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
if (cdc != nullptr && userPrompter != nullptr)
{
cdc->SetPincodeService(&gMyPincodeService);
cdc->SetPasscodeService(&gMyPincodeService);
cdc->SetUserPrompter(userPrompter);
cdc->SetPostCommissioningListener(&gMyPostCommissioningListener);
}
Expand Down
3 changes: 3 additions & 0 deletions examples/tv-app/tv-common/include/CHIPProjectAppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
// TVs need to be commissioners and likely want to be discoverable
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 1

// TVs will often enable this feature
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_PASSCODE 1

// TVs need to be both commissioners and commissionees
#define CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE 1

Expand Down
44 changes: 38 additions & 6 deletions examples/tv-app/tv-common/src/AppTv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,27 @@ class MyUserPrompter : public UserPrompter
}

// tv should override this with a dialog prompt
inline void PromptForCommissionPincode(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override
inline void PromptForCommissionPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName,
uint16_t pairingHint, const char * pairingInstruction) override
{
return;
}

// tv should override this with a dialog prompt
inline void HidePromptsOnCancel(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override { return; }

// set to true when TV displays both QR and Passcode during Commissioner Passcode display.
inline bool DisplaysPasscodeAndQRCode() override { return true; }

// tv should override this with a dialog prompt
inline void PromptWithCommissionerPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName,
uint32_t passcode, uint16_t pairingHint, const char * pairingInstruction) override
{
return;
}

// tv should override this with a dialog prompt
inline void PromptCommissioningStarted(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override
{
return;
}
Expand All @@ -79,14 +99,26 @@ class MyUserPrompter : public UserPrompter

MyUserPrompter gMyUserPrompter;

class MyPincodeService : public PincodeService
class MyPasscodeService : public PasscodeService
{
uint32_t FetchCommissionPincodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override
bool HasTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId,
chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info, uint32_t & passcode) override
{
return ContentAppPlatform::GetInstance().HasTargetContentApp(vendorId, productId, rotatingId, info, passcode);
}

uint32_t GetCommissionerPasscode(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId) override
{
// TODO: randomly generate this value
return 12345678;
}

uint32_t FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override
{
return ContentAppPlatform::GetInstance().GetPincodeFromContentApp(vendorId, productId, rotatingId);
return ContentAppPlatform::GetInstance().GetPasscodeFromContentApp(vendorId, productId, rotatingId);
}
};
MyPincodeService gMyPincodeService;
MyPasscodeService gMyPasscodeService;

class MyPostCommissioningListener : public PostCommissioningListener
{
Expand Down Expand Up @@ -558,7 +590,7 @@ CHIP_ERROR AppTvInit()
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
if (cdc != nullptr)
{
cdc->SetPincodeService(&gMyPincodeService);
cdc->SetPasscodeService(&gMyPasscodeService);
cdc->SetUserPrompter(&gMyUserPrompter);
cdc->SetPostCommissioningListener(&gMyPostCommissioningListener);
}
Expand Down
Loading
Loading