Skip to content

Commit

Permalink
feat: add profile download activation code parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
septs committed May 4, 2024
1 parent d85537a commit 68c32b6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,11 @@ There is no secondary confirmation for deleting a Profile, so please perform it
##### Download requires connection to SM-DP+ server and the following additional parameters:

- `-s`: SM-DP+ server, optional, if not provided, it will try to read the defaultsmdp attribute.
- `-s`: SM-DP+ server, optional, if not provided, it will try to read the default sm-dp+ attribute.
- `-m`: Matching ID, activation code. optional.
- `-c`: Confirmation Code, optional.
- `-i`: The IMEI of the device to which Profile is to be downloaded, optional.
- `-a`: LPA qrcode activation code string, e.g: `LPA:1$<sm-dp+ domain>$<matching id>`, if provided this option takes precedence over the `-s` and `-m` options, optional.

<details>

Expand Down
56 changes: 55 additions & 1 deletion 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,20 +45,73 @@ 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)
{
activation_code += 4; // ignore uri scheme
}
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:
break;
}
opt = getopt(argc, argv, opt_string);
}

if (activation_code != NULL)
{
// SGP.22 v2.2.2; Page 111
// Section: 4.1 (Activation Code)

char *token = NULL;
int index = 0;

token = strtok(activation_code, "$");
while (token != NULL)
{
switch (index)
{
case 0: // Activation Code Format
if (strncmp(token, "1", strlen(token)) != 0)
{
jprint_error("invalid activation code format", NULL);
goto err;
}
break;
case 1: // SM-DP+ Address
smdp = strdup(token);
break;
case 2: // AC_Token or Matching ID
matchingId = strdup(token);
break;
case 3: // SM-DP+ OID
// ignored; this function is not implemented
break;
case 4: // Confirmation Code Required Flag
if (strncmp(token, "1", strlen(token)) == 0 && confirmation_code == NULL)
{
jprint_error("confirmation code required", NULL);
goto err;
}
break;
default:
break;
}
index++;
token = strtok(NULL, "$");
}
}

if (smdp == NULL)
{
jprint_progress("es10a_get_euicc_configured_addresses");
Expand Down

0 comments on commit 68c32b6

Please sign in to comment.