3 * Copyright (c) 2020 Project CHIP Authors
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <platform/CHIPDeviceLayer.h>
23 #include <core/CHIPError.h>
24 #include <support/CHIPArgParser.hpp>
27 using namespace chip::ArgParser;
30 LinuxDeviceOptions gDeviceOptions;
32 // Follow the code style of command line arguments in case we need to add more options in the future.
35 kDeviceOption_BleDevice = 0x1000,
36 kDeviceOption_WiFi = 0x1001,
37 kDeviceOption_Thread = 0x1002,
40 OptionDef sDeviceOptionDefs[] = { { "ble-device", kArgumentRequired, kDeviceOption_BleDevice },
41 #if CHIP_DEVICE_CONFIG_ENABLE_WPA
42 { "wifi", kNoArgument, kDeviceOption_WiFi },
43 #endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
44 #if CHIP_ENABLE_OPENTHREAD
45 { "thread", kNoArgument, kDeviceOption_Thread },
46 #endif // CHIP_ENABLE_OPENTHREAD
49 const char * sDeviceOptionHelp = " --ble-device <number>\n"
50 " The device number for CHIPoBLE, without 'hci' prefix, can be found by hciconfig.\n"
51 #if CHIP_DEVICE_CONFIG_ENABLE_WPA
54 " Enable WiFi management via wpa_supplicant.\n"
55 #endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
56 #if CHIP_ENABLE_OPENTHREAD
59 " Enable Thread management via ot-agent.\n"
60 #endif // CHIP_ENABLE_OPENTHREAD
63 bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue)
70 case kDeviceOption_BleDevice:
71 if (!ParseInt(aValue, LinuxDeviceOptions::GetInstance().mBleDevice))
73 PrintArgError("%s: invalid value specified for ble device number: %s\n", aProgram, aValue);
78 case kDeviceOption_WiFi:
79 LinuxDeviceOptions::GetInstance().mWiFi = true;
82 case kDeviceOption_Thread:
83 LinuxDeviceOptions::GetInstance().mThread = true;
87 PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
95 OptionSet sDeviceOptions = { HandleOption, sDeviceOptionDefs, "GENERAL OPTIONS", sDeviceOptionHelp };
97 OptionSet * sLinuxDeviceOptionSets[] = { &sDeviceOptions, nullptr };
100 CHIP_ERROR ParseArguments(int argc, char * argv[])
102 if (!ParseArgs(argv[0], argc, argv, sLinuxDeviceOptionSets))
104 return CHIP_ERROR_INVALID_ARGUMENT;
106 return CHIP_NO_ERROR;
109 LinuxDeviceOptions & LinuxDeviceOptions::GetInstance()
111 return gDeviceOptions;