Example #1
0
//--------------------------------------------------------------------------------------------------
void simTest_SimAbsent
(
    le_sim_Id_t simId
)
{
    int32_t         initTries = 0;
    le_result_t     res;
    bool            ready = false;

    // Get the remaining PIN entries (error expected as no SIM)
    initTries = le_sim_GetRemainingPINTries(simId);
    LE_ASSERT((initTries == LE_NOT_FOUND) || (initTries == LE_FAULT));

    // Enter PIN code (error expected as no SIM)
    res = le_sim_EnterPIN(simId, PIN_TEMP);
    LE_ASSERT((res == LE_NOT_FOUND) || (res == LE_FAULT));

    // Check that the SIM is not ready
    ready = le_sim_IsReady(simId);
    LE_ASSERT(!ready);

    // Change PIN (error expected as no SIM)
    res = le_sim_ChangePIN(simId, PIN_TEMP, NEW_PIN_TEST);
    LE_ASSERT((res == LE_NOT_FOUND) || (res == LE_FAULT));

    // Unblock PIN  (error expected as no SIM)
    res = le_sim_Unblock(simId, (char*)PUK_TEST1, PIN_TEMP);
    LE_ASSERT((res == LE_NOT_FOUND) || (res == LE_FAULT));

    // Unlock PIN  (error expected as no SIM)
    res = le_sim_Unlock(simId, PIN_TEMP);
    LE_ASSERT((res == LE_NOT_FOUND) || (res == LE_FAULT));
}
Example #2
0
//--------------------------------------------------------------------------------------------------
void simTest_Authentication
(
    le_sim_Id_t simId,
    const char* pinPtr,
    const char* pukPtr
)
{
    le_result_t     res;
    bool            ready = false;
    int32_t         remainingPinTries = 0;
    int32_t         tries = 0;
    uint32_t        remainingPukTries = 0;
    uint32_t        pukTries = 0;
    char            string[100];

    memset(string, 0, 100);

    // Get the remaining PIN entries
    remainingPinTries = le_sim_GetRemainingPINTries(simId);

    // Enter PIN code
    res = le_sim_EnterPIN(simId, FAIL_PIN_TEST);
    LE_ASSERT(res == LE_FAULT);

    // Get the remaining PIN entries
    tries = le_sim_GetRemainingPINTries(simId);
    LE_ASSERT((remainingPinTries-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);
    LE_ASSERT(res == LE_FAULT);

    // 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((remainingPinTries = le_sim_GetRemainingPINTries(simId)) > 0)
    {
        // Enter PIN code
        res = le_sim_EnterPIN(simId, FAIL_PIN_TEST);
    }

    if(remainingPinTries < 0)
    {
        sprintf(string, "\nle_sim_GetRemainingPINTries error, res.%d (should be >=0)\n",
                remainingPinTries);
        Print(string);
    }

    // Get the remaining PUK entries
    LE_ASSERT_OK(le_sim_GetRemainingPUKTries(simId, &remainingPukTries));

    // Unblock the SIM using a wrong PUK code (error expected)
    res = le_sim_Unblock(simId, FAIL_PUK_TEST, NEW_PIN_TEST);
    LE_ASSERT(res == LE_FAULT);

    // Get the remaining PUK entries
    LE_ASSERT_OK(le_sim_GetRemainingPUKTries(simId, &pukTries));
    LE_ASSERT(1 == (remainingPukTries-pukTries));

    // Unblock the SIM using the correct PUK code
    res = le_sim_Unblock(simId, pukPtr, NEW_PIN_TEST);
    LE_ASSERT(LE_OK == res);

    // Get the remaining PUK entries
    LE_ASSERT_OK(le_sim_GetRemainingPUKTries(simId, &pukTries));
    LE_ASSERT((0 == remainingPukTries-pukTries));

    Print("End simTest_Authentication");
}
Example #3
0
//--------------------------------------------------------------------------------------------------
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);
}
Example #4
0
//--------------------------------------------------------------------------------------------------
void TestInteractivele_sim_Authentication()
{
    le_result_t     res;
    bool            ready=false;
    int32_t         initTries=0;
    int32_t         tries=0;
    le_sim_ObjRef_t simRef;
    uint32_t        i=1;
    bool            pinReq=true;
    char            internalPin[2][16];
    le_sim_States_t state;

    getCodes();

    do
    {
        fprintf(stderr, "\nTake off, then insert SIM card.%d, wait for +WIND:1 (approx. 2s) and then press enter \n", i);
        while ( getchar() != '\n' );

        simRef = le_sim_Create(i);
        CU_ASSERT_PTR_NOT_NULL(simRef);

        state = le_sim_GetState(simRef);
        displaySIMState(state, i);
        fprintf(stderr, "\nPress enter to continue...\n");
        while ( getchar() != '\n' );

        strcpy((char*)&internalPin[i-1][0], (char*)&PIN_TEST[i-1][0]);

        // Enter PIN
        if(state == LE_SIM_READY)
        {
            pinReq=false;
            // Lock PIN
            res = le_sim_Lock(simRef, PIN_TOO_LONG_TEST);
            CU_ASSERT_EQUAL(res, LE_OVERFLOW);
            res = le_sim_Lock(simRef, PIN_TOO_SHORT_TEST);
            CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
            res = le_sim_Lock(simRef, FAIL_PIN_TEST);
            CU_ASSERT_EQUAL(res, LE_NOT_POSSIBLE);
            res = le_sim_Lock(simRef, (char*)&internalPin[i-1][0]);
            CU_ASSERT_EQUAL(res, LE_OK);
            fprintf(stderr, "\nle_sim_Lock, res.%d  (should be LE_OK=0)\n", res);
            fprintf(stderr, "\nTake off, then insert SIM card.%d, wait for +WIND:1 (approx. 2s) and then press enter \n", i);
            while ( getchar() != '\n' );
        }

        initTries=le_sim_GetRemainingPINTries(simRef);
        res = le_sim_EnterPIN(simRef, PIN_TOO_LONG_TEST);
        CU_ASSERT_EQUAL(res, LE_OVERFLOW);
        res = le_sim_EnterPIN(simRef, PIN_TOO_SHORT_TEST);
        CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
        res = le_sim_EnterPIN(simRef, FAIL_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_NOT_POSSIBLE);

        tries=le_sim_GetRemainingPINTries(simRef);
        CU_ASSERT_TRUE((initTries-tries == 1));

        ready=le_sim_IsReady(simRef);
        CU_ASSERT_FALSE(ready);

        res = le_sim_EnterPIN(simRef, (char*)&internalPin[i-1][0]);
        CU_ASSERT_EQUAL(res, LE_OK);

        ready=le_sim_IsReady(simRef);
        CU_ASSERT_TRUE(ready);
#if 0
        if (ready != true)
        {
            LE_FATAL("SIM card.%d NOT READY ! check it, test exits !", i);
        }
#endif
        fprintf(stderr, "\nle_sim_EnterPIN, res.%d (should be LE_OK=0) \n", res);
        fprintf(stderr, "\nWait for SIM card.%d answer (+CREG: 1, approx. 2s) and then press enter \n", i);
        while ( getchar() != '\n' );

        // Change PIN
        res = le_sim_ChangePIN(simRef, PIN_TOO_LONG_TEST, NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_OVERFLOW);
        res = le_sim_ChangePIN(simRef, (char*)&internalPin[i-1][0], PIN_TOO_LONG_TEST);
        CU_ASSERT_EQUAL(res, LE_OVERFLOW);
        res = le_sim_ChangePIN(simRef, PIN_TOO_SHORT_TEST, NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
        res = le_sim_ChangePIN(simRef, (char*)&internalPin[i-1][0], PIN_TOO_SHORT_TEST);
        CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
        res = le_sim_ChangePIN(simRef, FAIL_PIN_TEST, NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_NOT_POSSIBLE);
        res = le_sim_ChangePIN(simRef, (char*)&internalPin[i-1][0], NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_OK);

        fprintf(stderr, "\nle_sim_ChangePIN, res.%d (should be LE_OK=0)\n", res);
        fprintf(stderr, "\nTake off, then insert SIM card.%d, wait for +WIND:1 (approx. 2s) and then press enter \n", i);
        while ( getchar() != '\n' );

        // Unblock PIN
        while((initTries=le_sim_GetRemainingPINTries(simRef))>0)
        {
            res = le_sim_EnterPIN(simRef, FAIL_PIN_TEST);
        }

        if(initTries < 0)
        {
            fprintf(stderr, "\nle_sim_GetRemainingPINTries error, res.%d (should be >=0)\n", initTries);
        }

        res = le_sim_Unblock(simRef, (char*)&PUK_TEST[i-1][0], PIN_TOO_LONG_TEST);
        CU_ASSERT_EQUAL(res, LE_OVERFLOW);
        res = le_sim_Unblock(simRef, (char*)&PUK_TEST[i-1][0], PIN_TOO_SHORT_TEST);
        CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
        res = le_sim_Unblock(simRef, PUK_BAD_LENGTH_TEST, NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_OUT_OF_RANGE);
        res = le_sim_Unblock(simRef, FAIL_PUK_TEST, NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_NOT_POSSIBLE);
        res = le_sim_Unblock(simRef, (char*)&PUK_TEST[i-1][0], (char*)&internalPin[i-1][0]);
        CU_ASSERT_EQUAL(res, LE_OK);

        fprintf(stderr, "\nle_sim_Unblock, res.%d  (should be LE_OK=0), press enter to continue \n", res);
        while ( getchar() != '\n' );

        // Unlock PIN
        res = le_sim_Unlock(simRef, PIN_TOO_LONG_TEST);
        CU_ASSERT_EQUAL(res, LE_OVERFLOW);
        res = le_sim_Unlock(simRef, PIN_TOO_SHORT_TEST);
        CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
        res = le_sim_Unlock(simRef, FAIL_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_NOT_POSSIBLE);
        res = le_sim_Unlock(simRef, (char*)&internalPin[i-1][0]);
        CU_ASSERT_EQUAL(res, LE_OK);

        fprintf(stderr, "\nle_sim_Unlock, res.%d  (should be LE_OK=0), press enter to continue  \n", res);
        while ( getchar() != '\n' );

        // Re-lock the SIM card
        if (pinReq)
        {
            res = le_sim_Lock(simRef, (char*)&internalPin[i-1][0]);
            CU_ASSERT_EQUAL(res, LE_OK);
        }

        le_sim_Delete(simRef);
        i++;
    } while (i<=le_sim_CountSlots());

    // Test case for SIM card absent: executed only on first slot
    simRef = le_sim_Create(1);
    CU_ASSERT_PTR_NOT_NULL(simRef);

    fprintf(stderr, "Take off SIM card.1 and then press enter \n");
    while ( getchar() != '\n' );

    // Enter PIN
    initTries=le_sim_GetRemainingPINTries(simRef);
    CU_ASSERT_TRUE((initTries == LE_NOT_FOUND) || (initTries == LE_NOT_POSSIBLE));

    res = le_sim_EnterPIN(simRef, PIN_TEMP);
    CU_ASSERT_TRUE((res == LE_NOT_FOUND) || (res == LE_NOT_POSSIBLE));

    ready=le_sim_IsReady(simRef);
    CU_ASSERT_FALSE(ready);

    // Change PIN
    res = le_sim_ChangePIN(simRef, PIN_TEMP, NEW_PIN_TEST);
    CU_ASSERT_TRUE((res == LE_NOT_FOUND) || (res == LE_NOT_POSSIBLE));

    // Unblock PIN
    res = le_sim_Unblock(simRef, (char*)&PUK_TEST[0][0], PIN_TEMP);
    CU_ASSERT_TRUE((res == LE_NOT_FOUND) || (res == LE_NOT_POSSIBLE));

    // Unlock PIN
    res = le_sim_Unlock(simRef, PIN_TEMP);
    CU_ASSERT_TRUE((res == LE_NOT_FOUND) || (res == LE_NOT_POSSIBLE));

    le_sim_Delete(simRef);

    fprintf(stderr, "Insert SIM card.1, wait for +WIND:1 (approx. 2s) and then press enter \n");
    while ( getchar() != '\n' );
}