summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp136
1 files changed, 89 insertions, 47 deletions
diff --git a/main.cpp b/main.cpp
index 52698fb..5bd4f83 100644
--- a/main.cpp
+++ b/main.cpp
@@ -65,8 +65,9 @@ std::string g_sMIPMnHaSs;
std::string g_sRxDiversity;
std::string g_sActiveFirmware;
std::string g_sConfigFile;
-std::string g_sSimPin;
Json::Value g_jData;
+std::string g_sRadioMode;
+std::string g_sSimPin;
MTS::AutoPtr<MTS::IO::ICellularRadio> g_apRadio;
@@ -103,7 +104,9 @@ 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_UNLOCK_SIM_CARD = 0x08000000;
+const uint32_t OPT_GET_RADIOMODE = 0x08000000;
+const uint32_t OPT_SET_RADIOMODE = 0x10000000;
+const uint32_t OPT_UNLOCK_SIM_CARD = 0x20000000;
void handle_sigterm(int signum);
void printHelp(const std::string& sApp);
@@ -112,40 +115,45 @@ 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' },
- { "unlock-sim-card", required_argument, 0, 'u' },
- { "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 },
+ { "unlock-sim-card", required_argument, 0, OPT_UNLOCK_SIM_CARD },
+ { "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();
@@ -361,6 +369,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));
} else if(g_iOptions & OPT_UNLOCK_SIM_CARD) {
Json::Value jArgs(Json::objectValue);
jArgs["pin"] = g_sSimPin;
@@ -386,21 +401,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) {
@@ -579,7 +588,13 @@ void parseOptions(int argc, char** argv) {
g_iOptions |= OPT_SETMIPMNHASS;
break;
- case 'u':
+ case OPT_SET_RADIOMODE:
+ if (optarg)
+ g_sRadioMode = optarg;
+ g_iOptions |= OPT_SET_RADIOMODE;
+ break;
+
+ case OPT_UNLOCK_SIM_CARD:
if(optarg != 0) {
g_sSimPin = optarg;
}
@@ -630,6 +645,8 @@ void printHelp(const std::string& sApp) {
printf("\t--set-mip-mn-aaa-ss <VAL> : set MIP MN AAA SS\n");
printf("\t--set-mip-mn-ha-ss <VAL> : set MIP MN HA SS\n");
printf("\t--set-rx-diversity <VAL> : set RX Diversity\n");
+ printf("\t--get-radio-mode : get selected cellular network\n");
+ printf("\t--set-radio-mode {auto|gsm|umts} : set cellular network\n");
// Applicable for LTE910-NA1 dual FW images only
// printf("\t--set-active-firmware <VAL> : switch to a specific firmware image\n");
printf("\t--factory-default [ --msl <MSL> ] : reset to factory defaults\n");
@@ -660,3 +677,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 "";
+ }
+}