コード例 #1
0
ファイル: simTest.c プロジェクト: tegoo/legato-af
//--------------------------------------------------------------------------------------------------
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));
}
コード例 #2
0
ファイル: main.c プロジェクト: tegoo/legato-af
//--------------------------------------------------------------------------------------------------
static void CheckSimStates
(
    void
)
{
    bool isPresent;
    bool isReady;

    switch (CurrentSimState)
    {
        case LE_SIM_INSERTED:
            isPresent = true;
            isReady = false;
        break;
        case LE_SIM_READY:
            isPresent = true;
            isReady = true;
        break;
        case LE_SIM_BLOCKED:
        case LE_SIM_BUSY:
            isPresent = true;
            isReady = false;
        break;
        case LE_SIM_ABSENT:
        case LE_SIM_STATE_UNKNOWN:
        default:
            isPresent = false;
            isReady = false;

    }

    LE_ASSERT( le_sim_IsPresent(CurrentSimId)==isPresent );
    LE_ASSERT( le_sim_IsReady(CurrentSimId)==isReady );
    LE_ASSERT( le_sim_GetState(CurrentSimId)==CurrentSimState );
}
コード例 #3
0
ファイル: simTest.c プロジェクト: legatoproject/legato-af
//--------------------------------------------------------------------------------------------------
void simTest_SimSelect
(
)
{
    // Select the embedded SIM
    LE_ASSERT_OK(le_sim_SelectCard(LE_SIM_EMBEDDED));

    // Get the selected card
    le_sim_Id_t simId = le_sim_GetSelectedCard();
    LE_ASSERT(LE_SIM_EMBEDDED == simId);

    // Select the LE_SIM_EXTERNAL_SLOT_1 SIM
    LE_ASSERT_OK(le_sim_SelectCard(LE_SIM_EXTERNAL_SLOT_1));

    // Get the selected card
    simId = le_sim_GetSelectedCard();
    LE_ASSERT(LE_SIM_EXTERNAL_SLOT_1 == simId);

    // Check if SIM present
    if (!le_sim_IsPresent(LE_SIM_EMBEDDED))
    {
        LE_INFO("SIM not present");
    }

    // Get the selected card by le_sim_GetSelectedCard()
    // Notice that the selected card received is the one used by the
    // last Legato API and not the one set by le_sim_SelectCard().
    simId = le_sim_GetSelectedCard();
    LE_ASSERT(LE_SIM_EMBEDDED == simId);

    // Check SIM ready
    if (!le_sim_IsReady(LE_SIM_EXTERNAL_SLOT_1))
    {
        LE_INFO("SIM not ready");
    }

    // Get the selected card by le_sim_GetSelectedCard()
    // Notice that the selected card received is the one used by the
    // last Legato API and not the one set by le_sim_SelectCard().
    simId = le_sim_GetSelectedCard();
    LE_ASSERT(LE_SIM_EXTERNAL_SLOT_1 == simId);


}
コード例 #4
0
ファイル: simTest.c プロジェクト: legatoproject/legato-af
//--------------------------------------------------------------------------------------------------
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");
}
コード例 #5
0
ファイル: le_simTest.c プロジェクト: andreasanna/legato-af
//--------------------------------------------------------------------------------------------------
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' );
}