Skip to content

Commit

Permalink
Make port command line arguments be conditional on ifdefs (#25227)
Browse files Browse the repository at this point in the history
* Ifguard usage of port options depending on availability, otherwise it looks odd when a port option is not available

* Also place help text on a conditional

* Enable port params for light app

* Restyle

* Normalize securedCommissioner port - make command line argument mean what it says

* Also update help

* Restyle

---------

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
andy31415 and andreilitvin authored Feb 22, 2023
1 parent 7c8d602 commit c2c032f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 31 deletions.
2 changes: 2 additions & 0 deletions examples/lighting-app/linux/include/CHIPProjectAppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@

#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_NAME 1

#define CHIP_DEVICE_ENABLE_PORT_PARAMS 1

#define CHIP_DEVICE_CONFIG_DEVICE_NAME "Test Bulb"
2 changes: 1 addition & 1 deletion examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)

#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
ChipLogProgress(AppServer, "Starting commissioner");
VerifyOrReturn(InitCommissioner(LinuxDeviceOptions::GetInstance().securedCommissionerPort + 10,
VerifyOrReturn(InitCommissioner(LinuxDeviceOptions::GetInstance().securedCommissionerPort,
LinuxDeviceOptions::GetInstance().unsecuredCommissionerPort,
LinuxDeviceOptions::GetInstance().commissionerFabricId) == CHIP_NO_ERROR);
ChipLogProgress(AppServer, "Started commissioner");
Expand Down
61 changes: 39 additions & 22 deletions examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,23 @@ LinuxDeviceOptions gDeviceOptions;
// Follow the code style of command line arguments in case we need to add more options in the future.
enum
{
kDeviceOption_BleDevice = 0x1000,
kDeviceOption_WiFi = 0x1001,
kDeviceOption_Thread = 0x1002,
kDeviceOption_Version = 0x1003,
kDeviceOption_VendorID = 0x1004,
kDeviceOption_ProductID = 0x1005,
kDeviceOption_CustomFlow = 0x1006,
kDeviceOption_Capabilities = 0x1007,
kDeviceOption_Discriminator = 0x1008,
kDeviceOption_Passcode = 0x1009,
kDeviceOption_SecuredDevicePort = 0x100a,
kDeviceOption_SecuredCommissionerPort = 0x100b,
kDeviceOption_UnsecuredCommissionerPort = 0x100c,
kDeviceOption_BleDevice = 0x1000,
kDeviceOption_WiFi = 0x1001,
kDeviceOption_Thread = 0x1002,
kDeviceOption_Version = 0x1003,
kDeviceOption_VendorID = 0x1004,
kDeviceOption_ProductID = 0x1005,
kDeviceOption_CustomFlow = 0x1006,
kDeviceOption_Capabilities = 0x1007,
kDeviceOption_Discriminator = 0x1008,
kDeviceOption_Passcode = 0x1009,
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS
kDeviceOption_SecuredDevicePort = 0x100a,
kDeviceOption_UnsecuredCommissionerPort = 0x100b,
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
kDeviceOption_SecuredCommissionerPort = 0x100c,
#endif
kDeviceOption_Command = 0x100d,
kDeviceOption_PICS = 0x100e,
kDeviceOption_KVS = 0x100f,
Expand Down Expand Up @@ -98,9 +102,13 @@ OptionDef sDeviceOptionDefs[] = {
{ "spake2p-verifier-base64", kArgumentRequired, kDeviceOption_Spake2pVerifierBase64 },
{ "spake2p-salt-base64", kArgumentRequired, kDeviceOption_Spake2pSaltBase64 },
{ "spake2p-iterations", kArgumentRequired, kDeviceOption_Spake2pIterations },
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS
{ "secured-device-port", kArgumentRequired, kDeviceOption_SecuredDevicePort },
{ "secured-commissioner-port", kArgumentRequired, kDeviceOption_SecuredCommissionerPort },
{ "unsecured-commissioner-port", kArgumentRequired, kDeviceOption_UnsecuredCommissionerPort },
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
{ "secured-commissioner-port", kArgumentRequired, kDeviceOption_SecuredCommissionerPort },
#endif
{ "command", kArgumentRequired, kDeviceOption_Command },
{ "PICS", kArgumentRequired, kDeviceOption_PICS },
{ "KVS", kArgumentRequired, kDeviceOption_KVS },
Expand Down Expand Up @@ -175,16 +183,20 @@ const char * sDeviceOptionHelp =
" passed, the iteration counts must match that used to generate the verifier otherwise failure will\n"
" arise.\n"
"\n"
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS
" --secured-device-port <port>\n"
" A 16-bit unsigned integer specifying the listen port to use for secure device messages (default is 5540).\n"
"\n"
" --secured-commissioner-port <port>\n"
" A 16-bit unsigned integer specifying the listen port to use for secure commissioner messages (default is 5542). Only "
"valid when app is both device and commissioner\n"
"\n"
" --unsecured-commissioner-port <port>\n"
" A 16-bit unsigned integer specifying the port to use for unsecured commissioner messages (default is 5550).\n"
"\n"
#endif
#if CHIP_DEVICE_ENABLE_PORT_PARAMS
" --secured-commissioner-port <port>\n"
" A 16-bit unsigned integer specifying the listen port to use for secure commissioner messages (default is 5552). Only "
"valid when app is both device and commissioner\n"
"\n"
#endif
" --commissioner-fabric-id <fabricid>\n"
" The fabric ID to be used when this device is a commissioner (default in code is 1).\n"
"\n"
Expand Down Expand Up @@ -377,18 +389,23 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
break;
}

#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS
case kDeviceOption_SecuredDevicePort:
LinuxDeviceOptions::GetInstance().securedDevicePort = static_cast<uint16_t>(atoi(aValue));
break;

case kDeviceOption_SecuredCommissionerPort:
LinuxDeviceOptions::GetInstance().securedCommissionerPort = static_cast<uint16_t>(atoi(aValue));
break;

case kDeviceOption_UnsecuredCommissionerPort:
LinuxDeviceOptions::GetInstance().unsecuredCommissionerPort = static_cast<uint16_t>(atoi(aValue));
break;

#endif

#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
case kDeviceOption_SecuredCommissionerPort:
LinuxDeviceOptions::GetInstance().securedCommissionerPort = static_cast<uint16_t>(atoi(aValue));
break;
#endif

case kDeviceOption_Command:
LinuxDeviceOptions::GetInstance().command = aValue;
break;
Expand Down
18 changes: 11 additions & 7 deletions examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ struct LinuxDeviceOptions
chip::Optional<uint16_t> discriminator;
chip::Optional<std::vector<uint8_t>> spake2pVerifier;
chip::Optional<std::vector<uint8_t>> spake2pSalt;
uint32_t spake2pIterations = 0; // When not provided (0), will default elsewhere
uint32_t mBleDevice = 0;
bool mWiFi = false;
bool mThread = false;
uint32_t securedDevicePort = CHIP_PORT;
uint32_t securedCommissionerPort = CHIP_PORT + 2;
uint32_t unsecuredCommissionerPort = CHIP_UDC_PORT;
uint32_t spake2pIterations = 0; // When not provided (0), will default elsewhere
uint32_t mBleDevice = 0;
bool mWiFi = false;
bool mThread = false;
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS
uint32_t securedDevicePort = CHIP_PORT;
uint32_t unsecuredCommissionerPort = CHIP_UDC_PORT;
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
uint32_t securedCommissionerPort = CHIP_PORT + 12; // TODO: why + 12?
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
const char * command = nullptr;
const char * PICS = nullptr;
const char * KVS = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/nxp/se05x/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)

#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
ChipLogProgress(AppServer, "Starting commissioner");
VerifyOrReturn(InitCommissioner(LinuxDeviceOptions::GetInstance().securedCommissionerPort + 10,
VerifyOrReturn(InitCommissioner(LinuxDeviceOptions::GetInstance().securedCommissionerPort,
LinuxDeviceOptions::GetInstance().unsecuredCommissionerPort) == CHIP_NO_ERROR);
ChipLogProgress(AppServer, "Started commissioner");
#if defined(ENABLE_CHIP_SHELL)
Expand Down

0 comments on commit c2c032f

Please sign in to comment.