jolly has uploaded this change for review.

View Change

Introduce 'operation' option to main file

Instead of having several command line flags to trigger various
operations, a single command line option '-o <operation>' is used.
Because an operation runs exclusively, it makes no sense to allow
multiple command line flags at the same time.

New operations are added in later patches, so they can use the '-o'
option as well and do not need to introduce new command line flags.

Revert from getopt_long() back to getopt(), because long options are not
required anymore.

Change-Id: I6b960f840820990de40fb07332669ddbfcdf1e7d
---
M src/ipa/main.c
1 file changed, 27 insertions(+), 21 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/onomondo-ipa refs/changes/02/43202/1
diff --git a/src/ipa/main.c b/src/ipa/main.c
index fae8476..bcdc1d9 100644
--- a/src/ipa/main.c
+++ b/src/ipa/main.c
@@ -47,9 +47,10 @@
printf(" -e eimId ................... set preferred eIM (in case the eUICC has multiple)\n");
printf(" -r N ....................... set reader number (default: %d)\n", DEFAULT_READER_NUMBER);
printf(" -c N ....................... set logical channel number (default: %d)\n", DEFAULT_CHANNEL_NUMBER);
- printf(" -f PATH .................... set initial eIM configuration\n");
- printf(" -m ......................... reset eUICC memory\n");
- printf(" --refresh-flag.............. Make eUICC send a CAT refresh after switching profile\n");
+ printf(" -o get-eim-package ..... Ask eIM for eIM package and process it (default operation)\n");
+ printf(" -o add-initial-eim PATH..... set initial eIM configuration from given file\n");
+ printf(" -o euicc-memory-reset....... reset eUICC memory\n");
+ printf(" -R.......................... Make eUICC send a CAT refresh after switching profile\n");
printf(" -n PATH .................... path to nvstate file (default: %s)\n", DEFAULT_NVSTATE_PATH);
printf(" -y NUM ..................... number of retries for ESipa requests (default: %u)\n",
DEFAULT_ESIPA_REQ_RETRIES);
@@ -147,7 +148,6 @@
struct ipa_buf *nvstate_load = NULL;
struct ipa_buf *nvstate_save = NULL;
bool getopt_one_euicc_pkg_only = false;
- int option_index = 0;

signal(SIGUSR1, sig_usr1);

@@ -159,18 +159,9 @@
ipa_binary_from_hexstr(cfg.tac, sizeof(cfg.tac), DEFAULT_TAC);
cfg.esipa_req_retries = DEFAULT_ESIPA_REQ_RETRIES;

- enum {
- OPT_REFRESHFLAG = 256,
- };
-
- struct option long_options[] = {
- { "refresh-flag", no_argument, NULL, OPT_REFRESHFLAG},
- { NULL, 0, NULL, 0}
- };
-
/* Overwrite configuration values with user defined parameters */
while (1) {
- opt = getopt_long(argc, argv, "ht:e:r:c:f:mn:C:SIEy:a1", long_options, &option_index);
+ opt = getopt(argc, argv, "ht:e:r:c:o:Rn:C:SIEy:a1");
if (opt == -1)
break;

@@ -191,13 +182,25 @@
case 'c':
cfg.euicc_channel = atoi(optarg);
break;
- case 'f':
- getopt_initial_eim_cfg_file = optarg;
+ case 'o':
+ printf("argv[optind]=%s\n", argv[optind]);
+ printf("optind=%d, argc=%d\n", optind, argc);
+ if (!strcmp(optarg, "get-eim-package")) {
+ } else if (!strcmp(optarg, "add-initial-eim")) {
+ if (optind >= argc || argv[optind][0] == '-') {
+ printf("option requires two parameters: -%c %s PATH\n", opt, optarg);
+ opt = -1;
+ break;
+ }
+ getopt_initial_eim_cfg_file = argv[optind++];
+ } else if (!strcmp(optarg, "euicc-memory-reset")) {
+ getopt_euicc_memory_reset = true;
+ } else {
+ printf("unhandled option: -%c %s\n", opt, optarg);
+ opt = -1;
+ }
break;
- case 'm':
- getopt_euicc_memory_reset = true;
- break;
- case OPT_REFRESHFLAG:
+ case 'R':
cfg.refresh_flag = true;
break;
case 'n':
@@ -226,8 +229,11 @@
break;
default:
printf("unhandled option: %c!\n", opt);
+ opt = -1;
break;
- };
+ }
+ if (opt == -1)
+ exit(opt);
}

/* Display current config */

To view, visit change 43202. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: onomondo-ipa
Gerrit-Branch: master
Gerrit-Change-Id: I6b960f840820990de40fb07332669ddbfcdf1e7d
Gerrit-Change-Number: 43202
Gerrit-PatchSet: 1
Gerrit-Owner: jolly <andreas@eversberg.eu>