summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp126
1 files changed, 83 insertions, 43 deletions
diff --git a/main.cpp b/main.cpp
index b74c9c6..5a01aea 100644
--- a/main.cpp
+++ b/main.cpp
@@ -66,6 +66,7 @@ std::string g_sRxDiversity;
std::string g_sActiveFirmware;
std::string g_sConfigFile;
Json::Value g_jData;
+std::string g_sRadioMode;
MTS::AutoPtr<MTS::IO::ICellularRadio> g_apRadio;
@@ -102,6 +103,8 @@ const uint32_t OPT_MSID = 0x00800000;
const uint32_t OPT_SETRXDIVERSITY = 0x01000000;
const uint32_t OPT_SETACTIVEFIRMWARE = 0x02000000;
const uint32_t OPT_CONFIG_FILE = 0x04000000;
+const uint32_t OPT_GET_RADIOMODE = 0x08000000;
+const uint32_t OPT_SET_RADIOMODE = 0x10000000;
void handle_sigterm(int signum);
void printHelp(const std::string& sApp);
@@ -110,39 +113,44 @@ void initializeCache();
void shutdown();
const char *code2str(MTS::IO::ICellularRadio::CODE code);
std::string loadImeiFromDeviceInfo();
-
-
- int iOption = 0;
- static struct option long_options[] =
- { { "help", no_argument, 0, '?' },
- { "version", no_argument, 0, 'v' },
- { "printlvl", required_argument, 0, 'p' },
- { "device", required_argument, 0, 'd' },
- { "config-file", required_argument, 0, 'c' },
- { "set-mdn", required_argument, 0, 'n' },
- { "set-msl", required_argument, 0, 'm' },
- { "set-msid", required_argument, 0, 's' },
- { "msl", required_argument, 0, 'l' },
- { "mdn", required_argument, 0, 'k' },
- { "msid", required_argument, 0, 'j' },
- { "set-active-firmware" , required_argument, 0, 'f' },
- { "set-rx-diversity", required_argument, 0, 'r' },
- { "set-mip-active-profile", required_argument, 0, '0' },
- { "set-mip-nai", required_argument, 0, '1' },
- { "set-mip-home-ip", required_argument, 0, '2' },
- { "set-mip-primary-ha", required_argument, 0, '3' },
- { "set-mip-secondary-ha", required_argument, 0, '4' },
- { "set-mip-mn-aaa-spi", required_argument, 0, '5' },
- { "set-mip-mn-ha-spi", required_argument, 0, '6' },
- { "set-mip-rev-tun", required_argument, 0, '7' },
- { "set-mip-mn-aaa-ss", required_argument, 0, '8' },
- { "set-mip-mn-ha-ss", required_argument, 0, '9' },
- { "init-dc", no_argument, &iOption, OPT_INIT_DC },
- { "init-fumo", no_argument, &iOption, OPT_INIT_FUMO },
- { "init-prl", no_argument, &iOption, OPT_INIT_PRL },
- { "init-activation", no_argument, &iOption, OPT_INIT_ACTIVATION },
- { "factory-default", no_argument, &iOption, OPT_INIT_RTN },
- { 0, 0, 0, 0 } };
+MTS::IO::ICellularRadio::RADIOMODE radioModeEnum(const std::string &mode);
+const char* radioModeStr(MTS::IO::ICellularRadio::RADIOMODE mode);
+
+
+static int iOption = 0;
+static struct option long_options[] = {
+ { "help", no_argument, 0, '?' },
+ { "version", no_argument, 0, 'v' },
+ { "printlvl", required_argument, 0, 'p' },
+ { "device", required_argument, 0, 'd' },
+ { "config-file", required_argument, 0, 'c' },
+ { "set-mdn", required_argument, 0, 'n' },
+ { "set-msl", required_argument, 0, 'm' },
+ { "set-msid", required_argument, 0, 's' },
+ { "msl", required_argument, 0, 'l' },
+ { "mdn", required_argument, 0, 'k' },
+ { "msid", required_argument, 0, 'j' },
+ { "set-active-firmware" , required_argument, 0, 'f' },
+ { "set-rx-diversity", required_argument, 0, 'r' },
+ { "set-mip-active-profile", required_argument, 0, '0' },
+ { "set-mip-nai", required_argument, 0, '1' },
+ { "set-mip-home-ip", required_argument, 0, '2' },
+ { "set-mip-primary-ha", required_argument, 0, '3' },
+ { "set-mip-secondary-ha", required_argument, 0, '4' },
+ { "set-mip-mn-aaa-spi", required_argument, 0, '5' },
+ { "set-mip-mn-ha-spi", required_argument, 0, '6' },
+ { "set-mip-rev-tun", required_argument, 0, '7' },
+ { "set-mip-mn-aaa-ss", required_argument, 0, '8' },
+ { "set-mip-mn-ha-ss", required_argument, 0, '9' },
+ { "get-radio-mode", no_argument, &iOption, OPT_GET_RADIOMODE },
+ { "set-radio-mode", required_argument, 0, OPT_SET_RADIOMODE },
+ { "init-dc", no_argument, &iOption, OPT_INIT_DC },
+ { "init-fumo", no_argument, &iOption, OPT_INIT_FUMO },
+ { "init-prl", no_argument, &iOption, OPT_INIT_PRL },
+ { "init-activation", no_argument, &iOption, OPT_INIT_ACTIVATION },
+ { "factory-default", no_argument, &iOption, OPT_INIT_RTN },
+ { 0, 0, 0, 0 }
+};
Json::Value getStaticData();
Json::Value getNetworkData();
@@ -358,6 +366,13 @@ int main(int argc, char** argv) {
jArgs["fwid"] = g_sActiveFirmware;
result = g_apRadio->setActiveFirmware(jArgs);
printf("%s\n", code2str(result));
+ } else if(g_iOptions & OPT_GET_RADIOMODE) {
+ ICellularRadio::RADIOMODE mode;
+ g_apRadio->getRadioMode(mode);
+ printf("%s\n", radioModeStr(mode));
+ } else if(g_iOptions & OPT_SET_RADIOMODE) {
+ ICellularRadio::CODE res = g_apRadio->setRadioMode(radioModeEnum(g_sRadioMode));
+ printf("%s\n", code2str(res));
}
shutdown();
@@ -378,21 +393,15 @@ void shutdown() {
}
}
-void parseOptions(int argc, char** argv) {
- int c;
- //int iOption = 0;
-
+void parseOptions(int argc, char** argv)
+{
if(argc == 1) {
printHelp(argv[0]);
exit(0);
}
- while (1) {
-
- /* getopt_long stores the option index here. */
- int option_index = 0;
-
- c = getopt_long(argc, argv, "t:d:p:r:?v", long_options, &option_index);
+ while (true) {
+ int c = getopt_long(argc, argv, "t:d:p:r:?v", long_options, nullptr);
/* Detect the end of the options. */
if(c == -1) {
@@ -571,6 +580,12 @@ void parseOptions(int argc, char** argv) {
g_iOptions |= OPT_SETMIPMNHASS;
break;
+ case OPT_SET_RADIOMODE:
+ if (optarg)
+ g_sRadioMode = optarg;
+ g_iOptions |= OPT_SET_RADIOMODE;
+ break;
+
default:
printf("OPTION: [%d] ABORTING!!\n", c);
abort();
@@ -644,3 +659,28 @@ const char *code2str(MTS::IO::ICellularRadio::CODE code) {
}
return "Unknown";
}
+
+MTS::IO::ICellularRadio::RADIOMODE radioModeEnum(const std::string &mode)
+{
+ using namespace MTS::IO;
+ if (mode == "auto")
+ return ICellularRadio::RADIOMODE_AUTO;
+ else if (mode == "gsm")
+ return ICellularRadio::RADIOMODE_GSM_ONLY;
+ else if (mode == "umts")
+ return ICellularRadio::RADIOMODE_UMTS_ONLY;
+ else
+ return ICellularRadio::RADIOMODE_UNKNOWN;
+
+}
+
+const char* radioModeStr(MTS::IO::ICellularRadio::RADIOMODE mode)
+{
+ using namespace MTS::IO;
+ switch (mode) {
+ case ICellularRadio::RADIOMODE_GSM_ONLY : return "gsm";
+ case ICellularRadio::RADIOMODE_UMTS_ONLY: return "umts";
+ case ICellularRadio::RADIOMODE_AUTO : return "auto";
+ default : return "";
+ }
+}