Skip to content

Commit

Permalink
chore: use getopt option
Browse files Browse the repository at this point in the history
  • Loading branch information
septs committed May 3, 2024
1 parent cb9958a commit 4d81855
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/applet/profile/download.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <euicc/es9p.h>
#include <euicc/tostr.h>

static const char *opt_string = "s:m:i:c:h?";
static const char *opt_string = "s:m:i:c:a:h?";

static int applet_main(int argc, char **argv)
{
Expand All @@ -23,6 +23,7 @@ static int applet_main(int argc, char **argv)
char *matchingId = NULL;
char *imei = NULL;
char *confirmation_code = NULL;
char *activation_code = NULL;

struct es10a_euicc_configured_addresses configured_addresses = {0};
struct es10b_load_bound_profile_package_result download_result = {0};
Expand All @@ -44,13 +45,23 @@ static int applet_main(int argc, char **argv)
case 'c':
confirmation_code = strdup(optarg);
break;
case 'a':
activation_code = strdup(optarg);
if (strncmp(activation_code, "LPA:", 4) != 0)
{
jprint_error("invalid activation code format", NULL);
goto err;
}
activation_code += 4; // skip "LPA:" prefix
break;
case 'h':
case '?':
printf("Usage: %s [OPTIONS]\r\n", argv[0]);
printf("\t -s SM-DP+ Domain\r\n");
printf("\t -m Matching ID\r\n");
printf("\t -i IMEI\r\n");
printf("\t -c Confirmation Code (Password)\r\n");
printf("\t -a Activation Code (e.g: 'LPA:***')\r\n");
printf("\t -h This help info\r\n");
return -1;
default:
Expand All @@ -59,18 +70,18 @@ static int applet_main(int argc, char **argv)
opt = getopt(argc, argv, opt_string);
}

if (argc > 1 && strncmp(argv[1], "LPA:", 4) == 0)
if (activation_code != NULL)
{
// SGP.22 v2.2.2; Page 111
// Section: 4.1 (Activation Code)

char *activation = argv[1] + 4;
char *offset = NULL;
char *token = NULL;
int index = 0;

while ((token = strtok_r(activation, "$", &offset)) != NULL)
token = strtok(activation_code, "$");
while (token != NULL)
{
printf("%d %s\n", index, token);
switch (index)
{
case 0: // Activation Code Format
Expand Down Expand Up @@ -100,6 +111,7 @@ static int applet_main(int argc, char **argv)
break;
}
index++;
token = strtok(NULL, "$");
}
}

Expand Down

0 comments on commit 4d81855

Please sign in to comment.