#include "legato.h"
#include "interfaces.h"
static le_sim_SimToolkitEventHandlerRef_t StkHandlerRef = NULL;
static le_sim_NewStateHandlerRef_t HandlerRef = NULL;
static le_sim_Id_t SimIdSelect = LE_SIM_EXTERNAL_SLOT_1;
static le_sim_Manufacturer_t Manufacturer = LE_SIM_GEMALTO;
static const char* Profile = NULL;
static void TestSimToolkitHandler
(
le_sim_Id_t simId,
le_sim_StkEvent_t stkEvent,
void* contextPtr
)
{
switch(stkEvent)
{
case LE_SIM_OPEN_CHANNEL:
LE_INFO(
"-TEST- OPEN_CHANNEL SIM Toolkit event for SIM card.%d", simId);
break;
case LE_SIM_REFRESH:
LE_INFO(
"-TEST- REFRESH SIM Toolkit event for SIM card.%d", simId);
"Accept SIM Toolkit failure!");
break;
case LE_SIM_STK_EVENT_MAX:
default:
LE_INFO(
"-TEST- Unknown SIM Toolkit event %d for SIM card.%d", stkEvent, simId);
break;
}
}
static void TestSimStateHandler
(
le_sim_Id_t simId,
le_sim_States_t simState,
void* contextPtr
)
{
switch(simState)
{
case LE_SIM_INSERTED:
LE_INFO(
"-TEST- New state LE_SIM_INSERTED for SIM card.%d", simId);
break;
case LE_SIM_ABSENT:
LE_INFO(
"-TEST- New state LE_SIM_ABSENT for SIM card.%d", simId);
break;
case LE_SIM_READY:
LE_INFO(
"-TEST- New state LE_SIM_READY for SIM card.%d", simId);
break;
case LE_SIM_BLOCKED:
LE_INFO(
"-TEST- New state LE_SIM_BLOCKED for SIM card.%d", simId);
break;
case LE_SIM_BUSY:
LE_INFO(
"-TEST- New state LE_SIM_BUSY for SIM card.%d", simId);
break;
case LE_SIM_POWER_DOWN:
LE_INFO(
"-TEST- New state LE_SIM_POWER_DOWN for SIM card.%d", simId);
break;
case LE_SIM_STATE_UNKNOWN:
LE_INFO(
"-TEST- New state LE_SIM_STATE_UNKNOWN for SIM card.%d", simId);
break;
default:
LE_INFO(
"-TEST- New state %d for SIM card.%d", simState, simId);
break;
}
}
void Testle_sim_GetCurrentSubscription
(
void
)
{
bool isEcs;
{
LE_INFO(
"Cannot determine current subscription");
}
{
LE_INFO(
"Current subscription is %s", (isEcs ?
"ECS":
"Commercial"));
}
}
void Testle_sim_SwapToEcs
(
void
)
{
bool isEcs;
LE_INFO(
"Start Testle_sim_SwapToEcs SimId %d, Manufacture %d", SimIdSelect, Manufacturer);
}
void Testle_sim_SwapToCommercial
(
void
)
{
bool isEcs;
LE_INFO(
"Start Testle_sim_SwapToCommercial SimId %d, Manufacture %d",
SimIdSelect, Manufacturer);
}
static void SigHandler
(
int sigNum
)
{
LE_INFO(
"EXIT SIM local Profile Swap Test");
exit(EXIT_SUCCESS);
}
static void PrintUsage
(
void
)
{
int idx;
bool sandboxed = (getuid() != 0);
const char * usagePtr[] =
{
"Usage of the simProfileSwap app is:",
" app runProc simProfileSwap --exe=bin/simProfileSwap -- <ext/esim>"
" <gemalto/oberthur/gd/morpho/valid> <ecs/commercial>",
};
{
if(sandboxed)
{
}
else
{
fprintf(stderr, "%s\n", usagePtr[idx]);
}
}
}
static void GetArgs
(
void
)
{
const char* arg;
if (NULL == arg)
{
exit(EXIT_FAILURE);
}
if( 0 == strncmp(arg, "ext", strlen("ext")))
{
LE_INFO(
"external SIM is selected.");
SimIdSelect = LE_SIM_EXTERNAL_SLOT_1;
}
else if( 0 == strncmp(arg, "esim", strlen("esim")))
{
LE_INFO(
"embedded SIM is selected.");
SimIdSelect = LE_SIM_EMBEDDED;
}
else
{
PrintUsage();
LE_INFO(
"EXIT SIM local Profile Swap Test");
exit(EXIT_FAILURE);
}
if (NULL == arg)
{
exit(EXIT_FAILURE);
}
if( 0 == strncmp(arg, "gemalto", strlen("gemalto")))
{
LE_INFO(
"Card manufacturer is Gemalto.");
Manufacturer = LE_SIM_GEMALTO;
}
else if( 0 == strncmp(arg, "oberthur", strlen("oberthur")))
{
LE_INFO(
"Card manufacturer is Oberthur.");
Manufacturer = LE_SIM_OBERTHUR;
}
else if( 0 == strncmp(arg, "gd", strlen("gd")))
{
LE_INFO(
"Card manufacturer is G&D.");
Manufacturer = LE_SIM_G_AND_D;
}
else if( 0 == strncmp(arg, "morpho", strlen("morpho")))
{
LE_INFO(
"Card manufacturer is Morpho.");
Manufacturer = LE_SIM_MORPHO;
}
else if( 0 == strncmp(arg, "valid", strlen("valid")))
{
LE_INFO(
"Card manufacturer is VALID.");
Manufacturer = LE_SIM_VALID;
}
else
{
PrintUsage();
LE_INFO(
"EXIT SIM local Profile Swap Test");
exit(EXIT_FAILURE);
}
}
{
{
signal(SIGINT, SigHandler);
GetArgs();
if (NULL == Profile)
{
exit(EXIT_FAILURE);
}
LE_INFO(
"======== Start SIM local Profile Swap Test with Profile.%s========", Profile);
if( strncmp(Profile, "ecs", strlen("ecs")) == 0 )
{
LE_INFO(
"======== SwapToEcs Test ========");
Testle_sim_GetCurrentSubscription();
Testle_sim_SwapToEcs();
}
else if( strncmp(Profile, "commercial", strlen("commercial")) == 0 )
{
LE_INFO(
"======== SwapToCommercial Test ========");
Testle_sim_GetCurrentSubscription();
Testle_sim_SwapToCommercial();
}
else
{
PrintUsage();
LE_INFO(
"EXIT SIM local Profile Swap Test");
exit(EXIT_FAILURE);
}
LE_INFO(
"======== Test SIM local Profile Swap Test SUCCESS ========");
exit(EXIT_SUCCESS);
}
else
{
PrintUsage();
LE_INFO(
"EXIT SIM local Profile Swap Test");
exit(EXIT_FAILURE);
}
}