AppOptions.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. *
  3. * Copyright (c) 2022 Project CHIP Authors
  4. * All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "AppOptions.h"
  19. #include <app/server/CommissioningWindowManager.h>
  20. #include <app/server/Server.h>
  21. using namespace chip::ArgParser;
  22. using chip::ArgParser::OptionDef;
  23. using chip::ArgParser::OptionSet;
  24. using chip::ArgParser::PrintArgError;
  25. constexpr uint16_t kOptionDacProviderFilePath = 0xFF01;
  26. constexpr uint16_t kOptionMinCommissioningTimeout = 0xFF02;
  27. static chip::Credentials::Examples::TestHarnessDACProvider mDacProvider;
  28. bool AppOptions::HandleOptions(const char * program, OptionSet * options, int identifier, const char * name, const char * value)
  29. {
  30. bool retval = true;
  31. switch (identifier)
  32. {
  33. case kOptionDacProviderFilePath:
  34. mDacProvider.Init(value);
  35. break;
  36. case kOptionMinCommissioningTimeout: {
  37. auto & commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager();
  38. commissionMgr.OverrideMinCommissioningTimeout(chip::System::Clock::Seconds16(static_cast<uint16_t>(atoi(value))));
  39. break;
  40. }
  41. default:
  42. PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", program, name);
  43. retval = false;
  44. break;
  45. }
  46. return retval;
  47. }
  48. OptionSet * AppOptions::GetOptions()
  49. {
  50. static OptionDef optionsDef[] = {
  51. { "dac_provider", kArgumentRequired, kOptionDacProviderFilePath },
  52. { "min_commissioning_timeout", kArgumentRequired, kOptionMinCommissioningTimeout },
  53. {},
  54. };
  55. static OptionSet options = {
  56. AppOptions::HandleOptions, optionsDef, "PROGRAM OPTIONS",
  57. " --dac_provider <filepath>\n"
  58. " A json file with data used by the example dac provider to validate device attestation procedure.\n"
  59. " --min_commissioning_timeout <value>\n"
  60. " The minimum time in seconds during which commissioning session establishment is allowed by the Node.\n"
  61. };
  62. return &options;
  63. }
  64. chip::Credentials::DeviceAttestationCredentialsProvider * AppOptions::GetDACProvider()
  65. {
  66. return &mDacProvider;
  67. }