Sample code for SIM Authentication
#define NEW_PIN_TEST "5678"
#define FAIL_PIN_TEST "4321"
#define FAIL_PUK_TEST "87654321"
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
void Print
(
char* string
)
{
bool sandboxed = (getuid() != 0);
if(sandboxed)
{
LE_INFO("%s", string);
}
else
{
fprintf(stderr, "%s\n", string);
}
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
void simTest_Authentication
(
le_sim_Id_t simId,
const char* pinPtr,
const char* pukPtr
)
{
bool ready = false;
int32_t initTries = 0;
int32_t tries = 0;
char string[100];
memset(string, 0, 100);
// Get the remaining PIN entries
initTries = le_sim_GetRemainingPINTries(simId);
// Enter PIN code
res = le_sim_EnterPIN(simId, FAIL_PIN_TEST);
// Get the remaining PIN entries
LE_ASSERT((initTries-tries) == 1);
// Check that the SIM is not ready
ready = le_sim_IsReady(simId);
LE_ASSERT(!ready);
// Enter PIN code
res = le_sim_EnterPIN(simId, pinPtr);
LE_ASSERT(res == LE_OK);
// Check that the SIM is ready
ready = le_sim_IsReady(simId);
LE_ASSERT(ready);
// Change PIN
res = le_sim_ChangePIN(simId, FAIL_PIN_TEST, NEW_PIN_TEST);
// Change the PIN code
res = le_sim_ChangePIN(simId, pinPtr, NEW_PIN_TEST);
LE_ASSERT(res == LE_OK);
// block the SIM:
// while remaining PIN entries not null, enter a wrong PIN code
while((initTries = le_sim_GetRemainingPINTries(simId)) > 0)
{
// Enter PIN code
res = le_sim_EnterPIN(simId, FAIL_PIN_TEST);
}
if(initTries < 0)
{
sprintf(string, "\nle_sim_GetRemainingPINTries error, res.%d (should be >=0)\n", initTries);
Print(string);
}
// Unblock the SIM using a wrong PUK code (error expected)
res = le_sim_Unblock(simId, FAIL_PUK_TEST, NEW_PIN_TEST);
// Unblock the SIM using the correct PUK code
res = le_sim_Unblock(simId, pukPtr, NEW_PIN_TEST);
LE_ASSERT(res == LE_OK);
Print("End simTest_Authentication");
}