Sample code for SIM States

//--------------------------------------------------------------------------------------------------
/**
* Print function.
*
*/
//--------------------------------------------------------------------------------------------------
void Print
(
char* string
)
{
bool sandboxed = (getuid() != 0);
 
if(sandboxed)
{
LE_INFO("%s", string);
}
else
{
fprintf(stderr, "%s\n", string);
}
}
//--------------------------------------------------------------------------------------------------
/**
* This function display the SIM state.
*
*/
//--------------------------------------------------------------------------------------------------
static void DisplaySimState
(
)
{
char string[100];
 
memset(string,0,100);
 
switch(state)
{
sprintf(string, "\nSIM Card state LE_SIM_INSERTED for SIM card.%d \n", simId);
break;
sprintf(string, "\nSIM Card state LE_SIM_ABSENT for SIM card.%d \n", simId);
break;
sprintf(string, "\nSIM Card state LE_SIM_READY for SIM card.%d \n", simId);
break;
sprintf(string, "\nSIM Card state LE_SIM_BLOCKED for SIM card.%d \n", simId);
break;
sprintf(string, "\nSIM Card state LE_SIM_BUSY for SIM card.%d \n", simId);
break;
sprintf(string, "\nSIM Card state LE_SIM_STATE_UNKNOWN for SIM card.%d \n", simId);
break;
default:
sprintf(string, "\nSIM Card state %d for SIM card.%d \n", state, simId);
break;
}
 
Print(string);
}
//--------------------------------------------------------------------------------------------------
/**
* Handler function for SIM States Notifications.
*
*/
//--------------------------------------------------------------------------------------------------
static void TestSimStateHandler
(
le_sim_Id_t simId,
le_sim_States_t simState,
void* contextPtr
)
{
 
// Get SIM state
state = le_sim_GetState(simId);
 
switch(state)
{
LE_INFO("-TEST- New state LE_SIM_INSERTED for SIM card.%d", simId);
break;
LE_INFO("-TEST- New state LE_SIM_ABSENT for SIM card.%d", simId);
break;
LE_INFO("-TEST- New state LE_SIM_READY for SIM card.%d", simId);
break;
LE_INFO("-TEST- New state LE_SIM_BLOCKED for SIM card.%d", simId);
break;
LE_INFO("-TEST- New state LE_SIM_BUSY for SIM card.%d", simId);
break;
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", state, simId);
break;
}
if((state>=LE_SIM_INSERTED) && (state<=LE_SIM_STATE_UNKNOWN))
{
LE_INFO("-TEST- Check le_sim_GetState passed.");
}
else
{
LE_ERROR("-TEST- Check le_sim_GetState failure !");
}
}
//--------------------------------------------------------------------------------------------------
/**
* Test: SIM State.
*
*/
//--------------------------------------------------------------------------------------------------
void simTest_State
(
le_sim_Id_t simId,
const char* pinPtr
)
{
char string[100];
 
memset(string, 0, 100);
 
// Get SIM state
state = le_sim_GetState(simId);
 
LE_ASSERT((state >= LE_SIM_INSERTED) && (state <= LE_SIM_BUSY));
sprintf(string, "\nSIM Card.%d state:\n", simId);
Print(string);
 
DisplaySimState(state, simId);
 
if(state == LE_SIM_INSERTED)
{
// Enter PIN code
res = le_sim_EnterPIN(simId, pinPtr);
LE_ASSERT(res==LE_OK);
 
// Get SIM state
state = le_sim_GetState(simId);
LE_ASSERT((state>=LE_SIM_INSERTED) && (state<=LE_SIM_BUSY));
}
 
// Add the state handler
testHdlrRef = le_sim_AddNewStateHandler(TestSimStateHandler, NULL);
LE_ASSERT(testHdlrRef != NULL);
}