Sample code for SIM Authentication
#define NEW_PIN_TEST "5678"#define FAIL_PIN_TEST "4321"#define FAIL_PUK_TEST "87654321"
//--------------------------------------------------------------------------------------------------/*** Print function.**///--------------------------------------------------------------------------------------------------void Print(char* string){bool sandboxed = (getuid() != 0);if(sandboxed){}else{fprintf(stderr, "%s\n", string);}}
//--------------------------------------------------------------------------------------------------/*** Test: Authentication (pin/puk).**///--------------------------------------------------------------------------------------------------void simTest_Authentication(le_sim_Id_t simId,const char* pinPtr,const char* pukPtr){le_result_t res;bool ready = false;int32_t initTries = 0;int32_t tries = 0;char string[100];memset(string, 0, 100);// Get the remaining PIN entriesinitTries = le_sim_GetRemainingPINTries(simId);// Enter PIN coderes = le_sim_EnterPIN(simId, FAIL_PIN_TEST);// Get the remaining PIN entriestries = le_sim_GetRemainingPINTries(simId);LE_ASSERT((initTries-tries) == 1);// Check that the SIM is not readyready = le_sim_IsReady(simId);LE_ASSERT(!ready);// Enter PIN coderes = le_sim_EnterPIN(simId, pinPtr);LE_ASSERT(res == LE_OK);// Check that the SIM is readyready = le_sim_IsReady(simId);LE_ASSERT(ready);// Change PINres = le_sim_ChangePIN(simId, FAIL_PIN_TEST, NEW_PIN_TEST);// Change the PIN coderes = 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 codewhile((initTries = le_sim_GetRemainingPINTries(simId)) > 0){// Enter PIN coderes = 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 coderes = le_sim_Unblock(simId, pukPtr, NEW_PIN_TEST);LE_ASSERT(res == LE_OK);Print("End simTest_Authentication");}