| 1 | // ************************************************************************* |
| 2 | // * GSM TA/ME library |
| 3 | // * |
| 4 | // * File: gsmsiectl.cc |
| 5 | // * |
| 6 | // * Purpose: GSM Siemens mobile phone control program |
| 7 | // * |
| 8 | // * Author: Christian W. Zuckschwerdt <[email protected]> |
| 9 | // * |
| 10 | // * Created: 2001-12-15 |
| 11 | // ************************************************************************* |
| 12 | |
| 13 | #ifdef HAVE_CONFIG_H |
| 14 | #include <gsm_config.h> |
| 15 | #endif |
| 16 | #include <gsmlib/gsm_nls.h> |
| 17 | #include <string> |
| 18 | #if defined(HAVE_GETOPT_LONG) || defined(WIN32) |
| 19 | #include <getopt.h> |
| 20 | #endif |
| 21 | #include <sstream> |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <errno.h> |
| 25 | #include <gsmlib/gsm_me_ta.h> |
| 26 | #include <gsm_sie_me.h> |
| 27 | #include <gsmlib/gsm_util.h> |
| 28 | #include <gsmlib/gsm_sysdep.h> |
| 29 | #ifdef WIN32 |
| 30 | #include <gsmlib/gsm_win32_serial.h> |
| 31 | #else |
| 32 | #include <gsmlib/gsm_unix_serial.h> |
| 33 | #include <unistd.h> |
| 34 | #endif |
| 35 | #include <iostream> |
| 36 | |
| 37 | using namespace std; |
| 38 | using namespace gsmlib; |
| 39 | |
| 40 | // my ME |
| 41 | |
| 42 | static SieMe *m; |
| 43 | |
| 44 | // information parameters |
| 45 | |
| 46 | enum InfoParameter {AllInfo, // print all info |
| 47 | MeInfo, // MeInfo must be first! |
| 48 | OperatorInfo, |
| 49 | CurrentOperatorInfo, |
| 50 | FacilityLockStateInfo, |
| 51 | FacilityLockCapabilityInfo, |
| 52 | PasswordInfo, |
| 53 | CLIPInfo, |
| 54 | CallForwardingInfo, |
| 55 | BatteryInfo, |
| 56 | BitErrorInfo, |
| 57 | SCAInfo, |
| 58 | CharSetInfo, |
| 59 | PhonebookInfo, // extended Siemens info |
| 60 | SignalToneInfo, |
| 61 | RingingToneInfo, |
| 62 | BinaryInfo, |
| 63 | SignalInfo}; // SignalInfo must be last! |
| 64 | |
| 65 | // operation parameters |
| 66 | |
| 67 | // FIXME operations not implemented yet |
| 68 | |
| 69 | // options |
| 70 | |
| 71 | #ifdef HAVE_GETOPT_LONG |
| 72 | static struct option longOpts[] = |
| 73 | { |
| 74 | {"xonxoff", no_argument, (int*)NULL, 'X'}, |
| 75 | {"operation", required_argument, (int*)NULL, 'o'}, |
| 76 | {"device", required_argument, (int*)NULL, 'd'}, |
| 77 | {"baudrate", required_argument, (int*)NULL, 'b'}, |
| 78 | {"init", required_argument, (int*)NULL, 'I'}, |
| 79 | {"help", no_argument, (int*)NULL, 'h'}, |
| 80 | {"version", no_argument, (int*)NULL, 'v'}, |
| 81 | {(char*)NULL, 0, (int*)NULL, 0} |
| 82 | }; |
| 83 | #else |
| 84 | #define getopt_long(argc, argv, options, longopts, indexptr) \ |
| 85 | getopt(argc, argv, options) |
| 86 | #endif |
| 87 | |
| 88 | // helper function, prints forwarding info |
| 89 | |
| 90 | void printForwardReason(string s, ForwardInfo &info) |
| 91 | { |
| 92 | cout << s << " " |
| 93 | << (info._active ? _("active ") : _("inactive ")) |
| 94 | << _("number: ") << info._number |
| 95 | << _(" subaddr: ") << info._subAddr |
| 96 | << _(" time: ") << info._time << endl; |
| 97 | } |
| 98 | |
| 99 | // helper function, prints integer range |
| 100 | |
| 101 | void printIntRange(IntRange ir) |
| 102 | { |
| 103 | cout << "(" << ir._low; |
| 104 | if (ir._high != NOT_SET) |
| 105 | cout << "-" << ir._high; |
| 106 | cout << ")"; |
| 107 | } |
| 108 | |
| 109 | // helper function, prints parameter range |
| 110 | |
| 111 | void printParameterRange(ParameterRange pr) |
| 112 | { |
| 113 | cout << "(\"" << pr._parameter << "\","; |
| 114 | printIntRange(pr._range); |
| 115 | cout << ")"; |
| 116 | } |
| 117 | |
| 118 | // print information |
| 119 | |
| 120 | static void printInfo(InfoParameter ip) |
| 121 | { |
| 122 | switch (ip) |
| 123 | { |
| 124 | case MeInfo: |
| 125 | { |
| 126 | MEInfo mei = m->getMEInfo(); |
| 127 | cout << _("<ME0> Manufacturer: ") << mei._manufacturer << endl |
| 128 | << _("<ME1> Model: ") << mei._model << endl |
| 129 | << _("<ME2> Revision: ") << mei._revision << endl |
| 130 | << _("<ME3> Serial Number: ") << mei._serialNumber << endl; |
| 131 | break; |
| 132 | } |
| 133 | case OperatorInfo: |
| 134 | { |
| 135 | int count = 0; |
| 136 | vector<OPInfo> opis = m->getAvailableOPInfo(); |
| 137 | for (vector<OPInfo>::iterator i = opis.begin(); i != opis.end(); ++i) |
| 138 | { |
| 139 | cout << "<OP" << count << _("> Status: "); |
| 140 | switch (i->_status) |
| 141 | { |
| 142 | case UnknownOPStatus: cout << _("unknown"); break; |
| 143 | case CurrentOPStatus: cout << _("current"); break; |
| 144 | case AvailableOPStatus: cout << _("available"); break; |
| 145 | case ForbiddenOPStatus: cout << _("forbidden"); break; |
| 146 | } |
| 147 | cout << _(" Long name: '") << i->_longName << "' " |
| 148 | << _(" Short name: '") << i->_shortName << "' " |
| 149 | << _(" Numeric name: ") << i->_numericName << endl; |
| 150 | ++count; |
| 151 | } |
| 152 | break; |
| 153 | } |
| 154 | case CurrentOperatorInfo: |
| 155 | { |
| 156 | OPInfo opi = m->getCurrentOPInfo(); |
| 157 | cout << "<CURROP0>" |
| 158 | << _(" Long name: '") << opi._longName << "' " |
| 159 | << _(" Short name: '") << opi._shortName << "' " |
| 160 | << _(" Numeric name: ") << opi._numericName |
| 161 | << _(" Mode: "); |
| 162 | switch (opi._mode) |
| 163 | { |
| 164 | case AutomaticOPMode: cout << _("automatic"); break; |
| 165 | case ManualOPMode: cout << _("manual"); break; |
| 166 | case DeregisterOPMode: cout << _("deregister"); break; |
| 167 | case ManualAutomaticOPMode: cout << _("manual/automatic"); break; |
| 168 | } |
| 169 | cout << endl; |
| 170 | break; |
| 171 | } |
| 172 | case FacilityLockStateInfo: |
| 173 | { |
| 174 | int count = 0; |
| 175 | vector<string> fclc = m->getFacilityLockCapabilities(); |
| 176 | for (vector<string>::iterator i = fclc.begin(); i != fclc.end(); ++i) |
| 177 | if (*i != "AB" && *i != "AG" && *i != "AC") |
| 178 | { |
| 179 | cout << "<FLSTAT" << count << "> '" << *i << "'"; |
| 180 | try |
| 181 | { |
| 182 | if (m->getFacilityLockStatus(*i, VoiceFacility)) |
| 183 | cout << _(" Voice"); |
| 184 | } |
| 185 | catch (GsmException &e) |
| 186 | { |
| 187 | cout << _(" unknown"); |
| 188 | } |
| 189 | try |
| 190 | { |
| 191 | if (m->getFacilityLockStatus(*i, DataFacility)) |
| 192 | cout << _(" Data"); |
| 193 | } |
| 194 | catch (GsmException &e) |
| 195 | { |
| 196 | cout << _(" unknown"); |
| 197 | } |
| 198 | try |
| 199 | { |
| 200 | if (m->getFacilityLockStatus(*i, FaxFacility)) |
| 201 | cout << _(" Fax"); |
| 202 | } |
| 203 | catch (GsmException &e) |
| 204 | { |
| 205 | cout << _(" unknown"); |
| 206 | } |
| 207 | cout << endl; |
| 208 | ++count; |
| 209 | } |
| 210 | break; |
| 211 | } |
| 212 | case FacilityLockCapabilityInfo: |
| 213 | { |
| 214 | cout << "<FLCAP0> "; |
| 215 | vector<string> fclc = m->getFacilityLockCapabilities(); |
| 216 | for (vector<string>::iterator i = fclc.begin(); i != fclc.end(); ++i) |
| 217 | cout << "'" << *i << "' "; |
| 218 | cout << endl; |
| 219 | break; |
| 220 | } |
| 221 | case PasswordInfo: |
| 222 | { |
| 223 | vector<PWInfo> pwi = m->getPasswords(); |
| 224 | int count = 0; |
| 225 | for (vector<PWInfo>::iterator i = pwi.begin(); i != pwi.end(); ++i) |
| 226 | { |
| 227 | cout << "<PW" << count << "> '" |
| 228 | << i->_facility << "' " << i->_maxPasswdLen << endl; |
| 229 | ++count; |
| 230 | } |
| 231 | break; |
| 232 | } |
| 233 | case CLIPInfo: |
| 234 | { |
| 235 | cout << "<CLIP0> " << (m->getNetworkCLIP() ? _("on") : _("off")) << endl; |
| 236 | break; |
| 237 | } |
| 238 | case CallForwardingInfo: |
| 239 | { |
| 240 | for (int r = 0; r < 4; ++r) |
| 241 | { |
| 242 | string text; |
| 243 | switch (r) |
| 244 | { |
| 245 | case 0: text = _("UnconditionalReason"); break; |
| 246 | case 1: text = _("MobileBusyReason"); break; |
| 247 | case 2: text = _("NoReplyReason"); break; |
| 248 | case 3: text = _("NotReachableReason"); break; |
| 249 | } |
| 250 | ForwardInfo voice, fax, data; |
| 251 | m->getCallForwardInfo((ForwardReason)r, voice, fax, data); |
| 252 | cout << "<FORW" << r << "."; |
| 253 | printForwardReason("0> " + text + _(" Voice"), voice); |
| 254 | cout << "<FORW" << r << "."; |
| 255 | printForwardReason("1> " + text + _(" Data"), data); |
| 256 | cout << "<FORW" << r << "."; |
| 257 | printForwardReason("2> " + text + _(" Fax"), fax); |
| 258 | } |
| 259 | break; |
| 260 | } |
| 261 | case BatteryInfo: |
| 262 | { |
| 263 | cout << "<BATT0> "; |
| 264 | int bcs = m->getBatteryChargeStatus(); |
| 265 | switch (bcs) |
| 266 | { |
| 267 | case 0: cout << _("0 ME is powered by the battery") << endl; break; |
| 268 | case 1: cout << _("1 ME has a battery connected, but is not powered by it") |
| 269 | << endl; break; |
| 270 | case 2: cout << _("2 ME does not have a battery connected") << endl; break; |
| 271 | case 3: |
| 272 | cout << _("3 Recognized power fault, calls inhibited") << endl; |
| 273 | break; |
| 274 | } |
| 275 | cout << "<BATT1> " << m->getBatteryCharge() << endl; |
| 276 | break; |
| 277 | } |
| 278 | case BitErrorInfo: |
| 279 | { |
| 280 | cout << "<BITERR0> " << m->getBitErrorRate() << endl; |
| 281 | break; |
| 282 | } |
| 283 | case SCAInfo: |
| 284 | { |
| 285 | cout << "<SCA0> " << m->getServiceCentreAddress() << endl; |
| 286 | break; |
| 287 | } |
| 288 | case CharSetInfo: |
| 289 | { |
| 290 | cout << "<CSET0> "; |
| 291 | vector<string> cs = m->getSupportedCharSets(); |
| 292 | for (vector<string>::iterator i = cs.begin(); i != cs.end(); ++i) |
| 293 | cout << "'" << *i << "' "; |
| 294 | cout << endl; |
| 295 | cout << "<CSET1> '" << m->getCurrentCharSet() << "'" << endl; |
| 296 | break; |
| 297 | } |
| 298 | case SignalInfo: |
| 299 | { |
| 300 | cout << "<SIG0> " << m->getSignalStrength() << endl; |
| 301 | break; |
| 302 | } |
| 303 | case PhonebookInfo: |
| 304 | { |
| 305 | cout << "<PBOOK0> "; |
| 306 | vector<string> pb = m->getSupportedPhonebooks(); |
| 307 | for (vector<string>::iterator i = pb.begin(); i != pb.end(); ++i) |
| 308 | cout << "'" << *i << "' "; |
| 309 | cout << endl; |
| 310 | cout << "<PBOOK1> '" << m->getCurrentPhonebook() << "'" << endl; |
| 311 | break; |
| 312 | } |
| 313 | case SignalToneInfo: |
| 314 | { |
| 315 | cout << "<SIGNAL0> "; |
| 316 | IntRange st = m->getSupportedSignalTones(); |
| 317 | printIntRange(st); |
| 318 | cout << endl; |
| 319 | // cout << "<SIGT1> '" << m->getCurrentSignalTone() << "'" << endl; |
| 320 | break; |
| 321 | } |
| 322 | case RingingToneInfo: |
| 323 | { |
| 324 | cout << "<RING0> "; |
| 325 | IntRange rt = m->getSupportedRingingTones(); |
| 326 | printIntRange(rt); |
| 327 | cout << endl; |
| 328 | cout << "<RING1> " << m->getCurrentRingingTone() << endl; |
| 329 | break; |
| 330 | } |
| 331 | case BinaryInfo: |
| 332 | { |
| 333 | cout << "<BIN0> "; |
| 334 | vector<ParameterRange> bnr = m->getSupportedBinaryReads(); |
| 335 | for (vector<ParameterRange>::iterator i = bnr.begin(); i != bnr.end(); ++i) |
| 336 | { |
| 337 | printParameterRange(*i); |
| 338 | cout << " "; |
| 339 | } |
| 340 | cout << endl; |
| 341 | cout << "<BIN1> "; |
| 342 | vector<ParameterRange> bnw = m->getSupportedBinaryWrites(); |
| 343 | for (vector<ParameterRange>::iterator i = bnw.begin(); i != bnw.end(); ++i) |
| 344 | { |
| 345 | printParameterRange(*i); |
| 346 | cout << " "; |
| 347 | } |
| 348 | cout << endl; |
| 349 | break; |
| 350 | } |
| 351 | default: |
| 352 | assert(0); |
| 353 | break; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | // convert facility class string of the form "", "all", or any combination |
| 358 | // of "v" (voice), "d" (data), or "f" (fax) to numeric form |
| 359 | |
| 360 | FacilityClass strToFacilityClass(string facilityClassS) |
| 361 | { |
| 362 | facilityClassS = lowercase(facilityClassS); |
| 363 | FacilityClass facilityClass = (FacilityClass)0; |
| 364 | if (facilityClassS == "all" || facilityClassS == "") |
| 365 | return (FacilityClass)ALL_FACILITIES; |
| 366 | |
| 367 | // OR in facility class bits |
| 368 | for (unsigned int i = 0; i < facilityClassS.length(); ++i) |
| 369 | if (facilityClassS[i] == 'v') |
| 370 | facilityClass = (FacilityClass)(facilityClass | VoiceFacility); |
| 371 | else if (facilityClassS[i] == 'd') |
| 372 | facilityClass = (FacilityClass)(facilityClass | DataFacility); |
| 373 | else if (facilityClassS[i] == 'f') |
| 374 | facilityClass = (FacilityClass)(facilityClass | FaxFacility); |
| 375 | else |
| 376 | throw GsmException( |
| 377 | stringPrintf(_("unknown facility class parameter '%c'"), |
| 378 | facilityClassS[i]), ParameterError); |
| 379 | |
| 380 | return facilityClass; |
| 381 | } |
| 382 | |
| 383 | // check if argc - optind is in range min..max |
| 384 | // throw exception otherwise |
| 385 | |
| 386 | void checkParamCount(int optind, int argc, int min, int max) |
| 387 | { |
| 388 | int paramCount = argc - optind; |
| 389 | if (paramCount < min) |
| 390 | throw GsmException(stringPrintf(_("not enough parameters, minimum number " |
| 391 | "of parameters is %d"), min), |
| 392 | ParameterError); |
| 393 | else if (paramCount > max) |
| 394 | throw GsmException(stringPrintf(_("too many parameters, maximum number " |
| 395 | "of parameters is %d"), max), |
| 396 | ParameterError); |
| 397 | } |
| 398 | |
| 399 | // *** main program |
| 400 | |
| 401 | int main(int argc, char *argv[]) |
| 402 | { |
| 403 | try |
| 404 | { |
| 405 | // handle command line options |
| 406 | string device = "/dev/mobilephone"; |
| 407 | string operation; |
| 408 | string baudrate; |
| 409 | string initString = DEFAULT_INIT_STRING; |
| 410 | bool swHandshake = false; |
| 411 | |
| 412 | int opt; |
| 413 | int dummy; |
| 414 | while((opt = getopt_long(argc, argv, "I:o:d:b:hvX", longOpts, &dummy)) |
| 415 | != -1) |
| 416 | switch (opt) |
| 417 | { |
| 418 | case 'X': |
| 419 | swHandshake = true; |
| 420 | break; |
| 421 | case 'I': |
| 422 | initString = optarg; |
| 423 | break; |
| 424 | case 'd': |
| 425 | device = optarg; |
| 426 | break; |
| 427 | case 'o': |
| 428 | operation = optarg; |
| 429 | break; |
| 430 | case 'b': |
| 431 | baudrate = optarg; |
| 432 | break; |
| 433 | case 'v': |
| 434 | cerr << argv[0] << stringPrintf(_(": version %s [compiled %s]"), |
| 435 | VERSION, __DATE__) << endl; |
| 436 | exit(0); |
| 437 | break; |
| 438 | case 'h': |
| 439 | cerr << argv[0] << _(": [-b baudrate][-d device][-h]" |
| 440 | "[-I init string][-o operation]\n" |
| 441 | " [-v][-X]{parameters}") << endl |
| 442 | << endl |
| 443 | << _(" -b, --baudrate baudrate to use for device " |
| 444 | "(default: 38400)") |
| 445 | << endl |
| 446 | << _(" -d, --device sets the destination device to " |
| 447 | "connect to") << endl |
| 448 | << _(" -h, --help prints this message") << endl |
| 449 | << _(" -I, --init device AT init sequence") << endl |
| 450 | << _(" -o, --operation operation to perform on the mobile \n" |
| 451 | " phone with the specified parameters") |
| 452 | << endl |
| 453 | << _(" -v, --version prints version and exits") << endl |
| 454 | << _(" -X, --xonxoff switch on software handshake") << endl |
| 455 | << endl |
| 456 | << _(" parameters parameters to use for the operation\n" |
| 457 | " (if an operation is given) or\n" |
| 458 | " a specification which kind of\n" |
| 459 | " information to read from the mobile " |
| 460 | "phone") |
| 461 | << endl << endl |
| 462 | << _("Refer to gsmctl(1) for details on the available parameters" |
| 463 | " and operations.") |
| 464 | << endl << endl; |
| 465 | exit(0); |
| 466 | break; |
| 467 | case '?': |
| 468 | throw GsmException(_("unknown option"), ParameterError); |
| 469 | break; |
| 470 | } |
| 471 | |
| 472 | // open the port and ME/TA |
| 473 | m = new SieMe(new |
| 474 | #ifdef WIN32 |
| 475 | Win32SerialPort |
| 476 | #else |
| 477 | UnixSerialPort |
| 478 | #endif |
| 479 | (device, |
| 480 | baudrate == "" ? |
| 481 | DEFAULT_BAUD_RATE : |
| 482 | baudRateStrToSpeed(baudrate), |
| 483 | initString, swHandshake)); |
| 484 | |
| 485 | if (operation == "") |
| 486 | { // process info parameters |
| 487 | for (int i = optind; i < argc; ++i) |
| 488 | { |
| 489 | string param = lowercase(argv[i]); |
| 490 | if (param == "all") |
| 491 | for (int ip = MeInfo; ip <= SignalInfo; ++ip) |
| 492 | printInfo((InfoParameter)ip); |
| 493 | else if (param == "me") |
| 494 | printInfo(MeInfo); |
| 495 | else if (param == "op") |
| 496 | printInfo(OperatorInfo); |
| 497 | else if (param == "currop") |
| 498 | printInfo(CurrentOperatorInfo); |
| 499 | else if (param == "flstat") |
| 500 | printInfo(FacilityLockStateInfo); |
| 501 | else if (param == "flcap") |
| 502 | printInfo(FacilityLockCapabilityInfo); |
| 503 | else if (param == "pw") |
| 504 | printInfo(PasswordInfo); |
| 505 | else if (param == "clip") |
| 506 | printInfo(CLIPInfo); |
| 507 | else if (param == "forw") |
| 508 | printInfo(CallForwardingInfo); |
| 509 | else if (param == "batt") |
| 510 | printInfo(BatteryInfo); |
| 511 | else if (param == "biterr") |
| 512 | printInfo(BitErrorInfo); |
| 513 | else if (param == "sig") |
| 514 | printInfo(SignalInfo); |
| 515 | else if (param == "sca") |
| 516 | printInfo(SCAInfo); |
| 517 | else if (param == "cset") |
| 518 | printInfo(CharSetInfo); |
| 519 | else if (param == "pbook") |
| 520 | printInfo(PhonebookInfo); |
| 521 | else if (param == "signal") |
| 522 | printInfo(SignalToneInfo); |
| 523 | else if (param == "ring") |
| 524 | printInfo(RingingToneInfo); |
| 525 | else if (param == "binary") |
| 526 | printInfo(BinaryInfo); |
| 527 | else |
| 528 | throw GsmException( |
| 529 | stringPrintf(_("unknown information parameter '%s'"), |
| 530 | param.c_str()), |
| 531 | ParameterError); |
| 532 | } |
| 533 | } |
| 534 | else |
| 535 | { // process operation |
| 536 | operation = lowercase(operation); |
| 537 | if (operation == "dial") |
| 538 | { |
| 539 | // dial: number |
| 540 | checkParamCount(optind, argc, 1, 1); |
| 541 | |
| 542 | m->dial(argv[optind]); |
| 543 | |
| 544 | // wait for keypress from stdin |
| 545 | char c; |
| 546 | read(1, &c, 1); |
| 547 | } |
| 548 | else if (operation == "setop") |
| 549 | { |
| 550 | // setop: opmode numeric FIXME allow long and numeric too |
| 551 | checkParamCount(optind, argc, 2, 2); |
| 552 | string opmodeS = lowercase(argv[optind]); |
| 553 | OPModes opmode; |
| 554 | if (opmodeS == "automatic") |
| 555 | opmode = AutomaticOPMode; |
| 556 | else if (opmodeS == "manual") |
| 557 | opmode = ManualOPMode; |
| 558 | else if (opmodeS == "deregister") |
| 559 | opmode = DeregisterOPMode; |
| 560 | else if (opmodeS == "manualautomatic") |
| 561 | opmode = ManualAutomaticOPMode; |
| 562 | else |
| 563 | throw GsmException(stringPrintf(_("unknown opmode parameter '%s'"), |
| 564 | opmodeS.c_str()), ParameterError); |
| 565 | |
| 566 | m->setCurrentOPInfo(opmode, "" , "", checkNumber(argv[optind + 1])); |
| 567 | } |
| 568 | else if (operation == "lock") |
| 569 | { |
| 570 | // lock: facility [facilityclass] [passwd] |
| 571 | checkParamCount(optind, argc, 1, 3); |
| 572 | string passwd = (argc - optind == 3) ? |
| 573 | (string)argv[optind + 2] : (string)""; |
| 574 | |
| 575 | m->lockFacility(argv[optind], |
| 576 | (argc - optind >= 2) ? |
| 577 | strToFacilityClass(argv[optind + 1]) : |
| 578 | (FacilityClass)ALL_FACILITIES, |
| 579 | passwd); |
| 580 | } |
| 581 | else if (operation == "unlock") |
| 582 | { |
| 583 | // unlock: facility [facilityclass] [passwd] |
| 584 | checkParamCount(optind, argc, 1, 3); |
| 585 | string passwd = argc - optind == 3 ? argv[optind + 2] : ""; |
| 586 | |
| 587 | m->unlockFacility(argv[optind], |
| 588 | (argc - optind >= 2) ? |
| 589 | strToFacilityClass(argv[optind + 1]) : |
| 590 | (FacilityClass)ALL_FACILITIES, |
| 591 | passwd); |
| 592 | } |
| 593 | else if (operation == "setpw") |
| 594 | { |
| 595 | // set password: facility oldpasswd newpasswd |
| 596 | checkParamCount(optind, argc, 1, 3); |
| 597 | string oldPasswd = argc - optind >= 2 ? argv[optind + 1] : ""; |
| 598 | string newPasswd = argc - optind == 3 ? argv[optind + 2] : ""; |
| 599 | |
| 600 | m->setPassword(argv[optind], oldPasswd, newPasswd); |
| 601 | } |
| 602 | else if (operation == "forw") |
| 603 | { |
| 604 | // call forwarding: mode reason number [facilityclass] [forwardtime] |
| 605 | checkParamCount(optind, argc, 2, 5); |
| 606 | |
| 607 | // get optional parameters facility class and forwardtime |
| 608 | int forwardTime = argc - optind == 5 ? checkNumber(argv[optind + 4]) : |
| 609 | NOT_SET; |
| 610 | FacilityClass facilityClass = |
| 611 | argc - optind >= 4 ? strToFacilityClass(argv[optind + 3]) : |
| 612 | (FacilityClass)ALL_FACILITIES; |
| 613 | |
| 614 | // get forward reason |
| 615 | string reasonS = lowercase(argv[optind + 1]); |
| 616 | ForwardReason reason; |
| 617 | if (reasonS == "unconditional") |
| 618 | reason = UnconditionalReason; |
| 619 | else if (reasonS == "mobilebusy") |
| 620 | reason = MobileBusyReason; |
| 621 | else if (reasonS == "noreply") |
| 622 | reason = NoReplyReason; |
| 623 | else if (reasonS == "notreachable") |
| 624 | reason = NotReachableReason; |
| 625 | else if (reasonS == "all") |
| 626 | reason = AllReasons; |
| 627 | else if (reasonS == "allconditional") |
| 628 | reason = AllConditionalReasons; |
| 629 | else |
| 630 | throw GsmException( |
| 631 | stringPrintf(_("unknown forward reason parameter '%s'"), |
| 632 | reasonS.c_str()), ParameterError); |
| 633 | |
| 634 | // get mode |
| 635 | string modeS = lowercase(argv[optind]); |
| 636 | ForwardMode mode; |
| 637 | if (modeS == "disable") |
| 638 | mode = DisableMode; |
| 639 | else if (modeS == "enable") |
| 640 | mode = EnableMode; |
| 641 | else if (modeS == "register") |
| 642 | mode = RegistrationMode; |
| 643 | else if (modeS == "erase") |
| 644 | mode = ErasureMode; |
| 645 | else |
| 646 | throw GsmException( |
| 647 | stringPrintf(_("unknown forward mode parameter '%s'"), |
| 648 | modeS.c_str()), ParameterError); |
| 649 | |
| 650 | m->setCallForwarding(reason, mode, |
| 651 | (argc - optind >= 3) ? argv[optind + 2] : "", |
| 652 | "", // subaddr |
| 653 | facilityClass, forwardTime); |
| 654 | } |
| 655 | else if (operation == "setsca") |
| 656 | { |
| 657 | // set sca: number |
| 658 | checkParamCount(optind, argc, 1, 1); |
| 659 | m->setServiceCentreAddress(argv[optind]); |
| 660 | } |
| 661 | else if (operation == "cset") |
| 662 | { |
| 663 | // set charset: string |
| 664 | checkParamCount(optind, argc, 1, 1); |
| 665 | m->setCharSet(argv[optind]); |
| 666 | } |
| 667 | else if (operation == "signal") |
| 668 | { |
| 669 | // play signal tone: int |
| 670 | checkParamCount(optind, argc, 1, 1); |
| 671 | int tone = atoi(argv[optind]); |
| 672 | m->playSignalTone(tone); |
| 673 | } |
| 674 | else if (operation == "setrt") |
| 675 | { |
| 676 | // set ringing tone: int int |
| 677 | checkParamCount(optind, argc, 2, 2); |
| 678 | int tone = atoi(argv[optind]); |
| 679 | int volume = atoi(argv[optind + 1]); |
| 680 | m->setRingingTone(tone, volume); |
| 681 | } |
| 682 | else if (operation == "playrt") |
| 683 | { |
| 684 | // play/stop ringing tone |
| 685 | m->toggleRingingTone(); |
| 686 | } |
| 687 | else |
| 688 | throw GsmException(stringPrintf(_("unknown operation '%s'"), |
| 689 | operation.c_str()), ParameterError); |
| 690 | } |
| 691 | } |
| 692 | catch (GsmException &ge) |
| 693 | { |
| 694 | cerr << argv[0] << _("[ERROR]: ") << ge.what() << endl; |
| 695 | return 1; |
| 696 | } |
| 697 | return 0; |
| 698 | } |