Esempio n. 1
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);
}
Esempio n. 2
0
//--------------------------------------------------------------------------------------------------
void simTest_Lock
(
    le_sim_Id_t simId,
    const char* pinPtr
)
{
    le_sim_States_t state;
    bool doLock = false;
    uint8_t loop = 0;
    le_result_t     res;

    // Get SIM state
    state = le_sim_GetState(simId);
    DisplaySimState(state, simId);
    LE_ASSERT((state == LE_SIM_READY)||(state == LE_SIM_INSERTED));

    if (LE_SIM_READY == state)
    {
        doLock = true;
    }
    else if (LE_SIM_INSERTED == state)
    {
        // Enter PIN code
        res = le_sim_EnterPIN(simId, pinPtr);
        LE_ASSERT(res == LE_OK);
        doLock = false;
    }

    // Try to lock/unlock the SIM
    while (loop<2)
    {
        LE_INFO("loop %d doLock %d", loop, doLock);

        if (doLock)
        {
            LE_INFO("lock the SIM");

            // Lock PIN using a wrong PIN code (error code expected)
            res = le_sim_Lock(simId, FAIL_PIN_TEST);
            LE_ASSERT(res == LE_FAULT);

            // Lock PIN using the correct PIN code
            res = le_sim_Lock(simId, pinPtr);
            LE_ASSERT(res == LE_OK);

            // Enter PIN code
            res = le_sim_EnterPIN(simId, pinPtr);
            LE_ASSERT(res == LE_OK);
            doLock = false;
        }
        else
        {
            LE_INFO("unlock the SIM");

            // Unlock the SIM using a wrong PIN code (error code expected)
            res = le_sim_Unlock(simId, FAIL_PIN_TEST);
            LE_ASSERT(res == LE_FAULT);

            // Lock PIN using the correct PIN code
            res = le_sim_Unlock(simId, pinPtr);
            LE_ASSERT(res == LE_OK);
            doLock = true;
        }

        loop++;
    }
}
Esempio n. 3
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' );
}