//-------------------------------------------------------------------------------------------------- void TestSim_SimCardInformation ( void ) { char iccid[PA_SIM_CARDID_MAX_LEN+1]; char imsi[PA_SIM_IMSI_MAX_LEN+1]; char phoneNumber[LE_MDMDEFS_PHONE_NUM_MAX_BYTES]; // Start in ABSENT state CurrentSimState = LE_SIM_ABSENT; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Try to get information: error are expected as there's no SIM LE_ASSERT( le_sim_GetICCID(CurrentSimId, iccid, PA_SIM_CARDID_MAX_LEN) == LE_FAULT ); LE_ASSERT( le_sim_GetIMSI(CurrentSimId, imsi, PA_SIM_IMSI_MAX_LEN) == LE_FAULT ); LE_ASSERT( le_sim_GetSubscriberPhoneNumber( CurrentSimId, phoneNumber, LE_MDMDEFS_PHONE_NUM_MAX_BYTES ) == LE_FAULT ); // SIM is now ready CurrentSimState = LE_SIM_READY; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Try to get informations, check values (OK expected) LE_ASSERT( le_sim_GetICCID(CurrentSimId, iccid, PA_SIM_CARDID_MAX_LEN+1) == LE_OK ); LE_ASSERT( strncmp(iccid,Iccid,PA_SIM_CARDID_MAX_LEN) == 0 ); LE_ASSERT( le_sim_GetIMSI(CurrentSimId, imsi, PA_SIM_IMSI_MAX_LEN+1) == LE_OK ); LE_ASSERT( strncmp(imsi,Imsi,PA_SIM_IMSI_MAX_LEN) == 0 ); LE_ASSERT( le_sim_GetSubscriberPhoneNumber( CurrentSimId, phoneNumber, LE_MDMDEFS_PHONE_NUM_MAX_BYTES ) == LE_OK ); LE_ASSERT( strncmp(phoneNumber,PhoneNum,LE_MDMDEFS_PHONE_NUM_MAX_BYTES) == 0 ); // Try to get infomartions with a too small buffer (error expected) LE_ASSERT( le_sim_GetICCID(CurrentSimId, iccid, PA_SIM_CARDID_MAX_LEN) == LE_OVERFLOW ); LE_ASSERT( le_sim_GetIMSI(CurrentSimId, imsi, PA_SIM_IMSI_MAX_LEN) == LE_OVERFLOW ); // Check that all handlers have been called as expected LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); }
//-------------------------------------------------------------------------------------------------- void TestSim_LockUnlockChange ( void ) { // Go into ABSENT state CurrentSimState = LE_SIM_ABSENT; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Check the states CheckSimStates(); // Try to lock/unlock/change PIN w/o SIN inserted: errors are expected LE_ASSERT(le_sim_Unlock(CurrentSimId,Pin) == LE_NOT_FOUND); LE_ASSERT(le_sim_Lock(CurrentSimId,Pin) == LE_NOT_FOUND); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,Pin,NewPin) == LE_NOT_FOUND); // Go in READY state CurrentSimState = LE_SIM_READY; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Try to lock/unclock/Change PIN with bad PIN: errors are expected LE_ASSERT(le_sim_Lock(CurrentSimId, BadPin) == LE_FAULT); LE_ASSERT(le_sim_Unlock(CurrentSimId, BadPin) == LE_FAULT); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,ShortPin,NewPin) == LE_UNDERFLOW); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,Pin,ShortPin) == LE_UNDERFLOW); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,ShortPin,ShortPin) == LE_UNDERFLOW); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,BadPin,NewPin) == LE_FAULT); // Lock/unlock/change PIN with correct values: OK is expected LE_ASSERT(le_sim_Lock(CurrentSimId,Pin) == LE_OK); LE_ASSERT(le_sim_Unlock(CurrentSimId,Pin) == LE_OK); LE_ASSERT(le_sim_ChangePIN(CurrentSimId,Pin,NewPin) == LE_OK); // Check that all handlers have been called as expected LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); }
//-------------------------------------------------------------------------------------------------- void TestSim_HomeNetwork ( void ) { char mcc[LE_MRC_MCC_BYTES]; char mnc[LE_MRC_MNC_BYTES]; char homeNetwork[20]; // Start in ABSENT state CurrentSimState = LE_SIM_ABSENT; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Try to get home network: error are expected as there's no SIM LE_ASSERT(le_sim_GetHomeNetworkMccMnc(CurrentSimId,mcc,LE_MRC_MCC_BYTES,mnc,LE_MRC_MNC_BYTES) == LE_FAULT); LE_ASSERT(le_sim_GetHomeNetworkOperator(CurrentSimId,homeNetwork,20) == LE_FAULT); // SIM is now ready CurrentSimState = LE_SIM_READY; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Try to get home network, check values (OK expected) LE_ASSERT(le_sim_GetHomeNetworkMccMnc(CurrentSimId,mcc,LE_MRC_MCC_BYTES,mnc,LE_MRC_MNC_BYTES) == LE_OK); LE_ASSERT(strcmp(mcc,Mcc)==0); LE_ASSERT(strcmp(mnc,Mnc)==0); LE_ASSERT(le_sim_GetHomeNetworkOperator(CurrentSimId,homeNetwork,20) == LE_OK); LE_ASSERT(strcmp(homeNetwork,Operator)==0); // Check that all handlers have been called as expected LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); }
//-------------------------------------------------------------------------------------------------- void TestSim_AddHandlers ( void ) { int i; // Create a semaphore to coordinate the test ThreadSemaphore = le_sem_Create("HandlerSem",0); // int app context memset(AppCtx, 0, NB_CLIENT*sizeof(AppContext_t)); // Start tasks: simulate multi-user of le_sim // each thread subcribes to state handler using le_sim_AddNewStateHandler for (i=0; i < NB_CLIENT; i++) { char string[20]={0}; snprintf(string,20,"app%dhandler", i); AppCtx[i].appId = i; AppCtx[i].appThreadRef = le_thread_Create(string, AppHandler, &AppCtx[i]); le_thread_Start(AppCtx[i].appThreadRef); } // Wait that the tasks have started before continuing the test SynchTest(); // Sim is absent in this test CurrentSimState = LE_SIM_ABSENT; pa_simSimu_SetSelectCard(CurrentSimId); le_sim_SelectCard(CurrentSimId); pa_simSimu_ReportSimState(CurrentSimState); // The tasks have subscribe to state event handler: // wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Check that we are in the expected states (sim absent) CheckSimStates(); // Check that no more call of the semaphore LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); }
//-------------------------------------------------------------------------------------------------- static void SimulateAndCheckState ( le_ecall_State_t state ) { CurrentEcallState = state; LE_INFO("Simulate state.%d", CurrentEcallState); pa_ecallSimu_ReportEcallState(CurrentEcallState); // The tasks have subscribe to state event handler: // wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); }
//-------------------------------------------------------------------------------------------------- void TestSim_PinPuk ( void ) { // Check the states CheckSimStates(); // The test is started with no sim inserted (end of the previous test) // Sim absent, test Pin and Puk (error expected as no sim inserted) LE_ASSERT(le_sim_EnterPIN(CurrentSimId, BadPin) == LE_NOT_FOUND); LE_ASSERT(le_sim_Unblock(CurrentSimId, Puk, BadPin) == LE_NOT_FOUND); LE_ASSERT(le_sim_GetRemainingPINTries(CurrentSimId) == LE_NOT_FOUND); // Insert SIM (busy state) CurrentSimState = LE_SIM_BUSY; pa_simSimu_ReportSimState(CurrentSimState); // Note that in LE_SIM_BUSY state, no handlers are called // Check that we are in the expected states (sim busy) CheckSimStates(); // test pin and puk: error is expected as sim in BUSY state LE_ASSERT(le_sim_EnterPIN(CurrentSimId, BadPin) == LE_FAULT); LE_ASSERT(le_sim_Unblock(CurrentSimId, Puk, BadPin) == LE_FAULT); LE_ASSERT(le_sim_GetRemainingPINTries(CurrentSimId) == LE_FAULT); // SIM is inserted CurrentSimState = LE_SIM_INSERTED; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Check that we are in the expected states (sim busy) CheckSimStates(); // block the pin int i=3; for (;i!=0;i--) { // Test the remaining PIN tries LE_ASSERT(le_sim_GetRemainingPINTries(CurrentSimId) == i); if (i==1) { // Update CurrentSimState for handlers' checks CurrentSimState = LE_SIM_BLOCKED; } // Try to enter the PIN: the PIN is wrong, an error is expected LE_ASSERT(le_sim_EnterPIN(CurrentSimId, BadPin) == LE_FAULT); // Don't try to unlock the SIM in the last failed PIN, PUK tests are done behind if (i != 1) { // Try to unblock the SIM whereas the sim is not in PUK state (error expected) LE_ASSERT(le_sim_Unblock(CurrentSimId, Puk, BadPin) == LE_FAULT); } else { // The last time, check that handlers have been called (the SIM is in BLOCKED state, // handers have been called to warn the state modification) SynchTest(); } // Get the remaining PIN tries LE_ASSERT(le_sim_GetRemainingPINTries(CurrentSimId) == i-1); // Check that we are in the expected states CheckSimStates(); } // Try the puk (bad puk or bad pin, errors are expected) LE_ASSERT(le_sim_Unblock(CurrentSimId, ShortPuk, BadPin) == LE_OUT_OF_RANGE); LE_ASSERT(le_sim_Unblock(CurrentSimId, LongPuk, BadPin) == LE_OUT_OF_RANGE); LE_ASSERT(le_sim_Unblock(CurrentSimId, Puk, ShortPin) == LE_UNDERFLOW); // The next operation unblocks the pin: we change the gloabal variable here to be ready when the // handlers will be called CurrentSimState = LE_SIM_READY; // Unblock the SIM (OK expected) LE_ASSERT(le_sim_Unblock(CurrentSimId, Puk,Pin) == LE_OK); // Get the remaining PIN tries LE_ASSERT(le_sim_GetRemainingPINTries(CurrentSimId) == 3); // Wait the handlers' calls (SIM is supposed to be in READY state now) SynchTest(); // Return into INSERTED state: check PIN CurrentSimState = LE_SIM_INSERTED; pa_simSimu_ReportSimState(CurrentSimState); // Wait the handlers' calls SynchTest(); // Check state handler result CheckStateHandlerResult(); // Now, try to enter the PIN (bad pin code, error expected) LE_ASSERT(le_sim_EnterPIN(CurrentSimId, ShortPin) == LE_UNDERFLOW); // Enter the correct PIN (OK expected) CurrentSimState = LE_SIM_READY; LE_ASSERT(le_sim_EnterPIN(CurrentSimId, Pin) == LE_OK); // Wait the handlers' calls SynchTest(); // Check that we are in the expected states CheckSimStates(); LE_ASSERT(le_sem_GetValue(ThreadSemaphore) == 0); }