Beispiel #1
0
//--------------------------------------------------------------------------------------------------
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 );
}
Beispiel #2
0
//--------------------------------------------------------------------------------------------------
void simTest_Create
(
    le_sim_Id_t simId,
    const char* pinPtr
)
{
    bool            presence = false;
    char            iccid[LE_SIM_ICCID_BYTES] = {0};
    char            imsi[LE_SIM_IMSI_BYTES] = {0};
    char            eid[LE_SIM_EID_BYTES] = {0};

    // Enter PIN code
    LE_ASSERT_OK(le_sim_EnterPIN(simId, pinPtr));

    // Get ICCID
    LE_ASSERT_OK(le_sim_GetICCID(simId, iccid, sizeof(iccid)));
    Print( iccid );

    // Get EID
    LE_ASSERT_OK(le_sim_GetEID(simId, eid, sizeof(eid)));
    Print( eid );

    // Get IMSI
    LE_ASSERT_OK(le_sim_GetIMSI(simId, imsi, sizeof(imsi)));
    Print( imsi );

    // Check if SIM present
    presence = le_sim_IsPresent(simId);
    LE_ASSERT(presence);
}
Beispiel #3
0
//--------------------------------------------------------------------------------------------------
void simTest_Create
(
    le_sim_Id_t simId,
    const char* pinPtr
)
{
    bool            presence = false;
    char            iccid[LE_SIM_ICCID_BYTES] = {0};
    char            imsi[LE_SIM_IMSI_BYTES] = {0};
    le_result_t     res;

    // Enter PIN code
    res = le_sim_EnterPIN(simId, pinPtr);
    LE_ASSERT(res==LE_OK);

    // Get ICCID
    res = le_sim_GetICCID(simId, iccid, sizeof(iccid));
    LE_ASSERT(res==LE_OK);
    Print( iccid );

    // Get IMSI
    res = le_sim_GetIMSI(simId, imsi, sizeof(imsi));
    LE_ASSERT(res==LE_OK);
    Print( imsi );

    // Check if SIM present
    presence = le_sim_IsPresent(simId);
    LE_ASSERT(presence);
}
Beispiel #4
0
//--------------------------------------------------------------------------------------------------
void Testle_sim_Create()
{
    bool            presence=false;
    le_sim_ObjRef_t simRef;
    char            iccid[LE_SIM_ICCID_BYTES] = {0};
    char            imsi[LE_SIM_IMSI_BYTES] = {0};
    uint32_t        i=1;
    le_result_t     res;

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

        res = le_sim_GetICCID(simRef, iccid, sizeof(iccid));
        CU_ASSERT_EQUAL(res, LE_OK);

        res = le_sim_GetIMSI(simRef, imsi, sizeof(imsi));
        CU_ASSERT_EQUAL(res, LE_OK);

        presence=le_sim_IsPresent(simRef);
        CU_ASSERT_TRUE(presence);

        le_sim_Delete(simRef);
        i++;
    } while (i<=le_sim_CountSlots());
}
//--------------------------------------------------------------------------------------------------
static le_cellnet_State_t TranslateToCellNetState
(
    le_mrc_NetRegState_t state
)
{
    le_sim_Id_t simSelected = le_sim_GetSelectedCard();

    // Check if the SIM card is present
    if (!le_sim_IsPresent(simSelected))
    {
        // SIM card absent
        return LE_CELLNET_SIM_ABSENT;
    }

    // SIM card present, translate the MRC network state
    switch(state)
    {
        case LE_MRC_REG_NONE:
        {
            le_onoff_t  radioState;
            le_result_t result;

            // In this state, the radio should be OFF.
            if ((result = le_mrc_GetRadioPower(&radioState)) != LE_OK)
            {
                LE_WARN("Failed to get the radio power. Result: %d", result);
                return LE_CELLNET_REG_UNKNOWN;
            }
            else
            {
                if (radioState == LE_OFF)
                {
                    // The radio is OFF
                    return LE_CELLNET_RADIO_OFF;
                }
                else
                {
                    // The radio is ON
                    return LE_CELLNET_REG_EMERGENCY;
                }
            }
        }
        case LE_MRC_REG_SEARCHING:
        case LE_MRC_REG_DENIED:
            return LE_CELLNET_REG_EMERGENCY;
        case LE_MRC_REG_HOME:
            return LE_CELLNET_REG_HOME;
        case LE_MRC_REG_ROAMING:
            return LE_CELLNET_REG_ROAMING;
        default:
            return LE_CELLNET_REG_UNKNOWN;
    }
}
Beispiel #6
0
//--------------------------------------------------------------------------------------------------
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);


}
//--------------------------------------------------------------------------------------------------
static void StartCellularNetwork
(
    void
)
{
    le_onoff_t  radioState;
    le_result_t result;

    result=le_mrc_GetRadioPower(&radioState);
    if ((result == LE_OK) && (radioState == LE_ON))
    {
        // Load SIM configuration from secure storage
        le_sim_Id_t simSelected = le_sim_GetSelectedCard();

        if (le_sim_IsPresent(simSelected))
        {
            LoadSimFromSecStore(simSelected);
        }

        // Notify the applications even if the SIM is absent
        GetAndSendCellNetStateEvent();
    }
    else
    {
        // Try to power ON the radio anyway
        le_mrc_SetRadioPower(LE_ON);

        // Set a timer that gets the current position.
        le_timer_Ref_t startCellNetTimer = le_timer_Create("StartCellNetTimer");
        le_clk_Time_t interval = {15, 0}; // 15 seconds

        if ( (le_timer_SetHandler(startCellNetTimer, StartCellNetTimerHandler) != LE_OK) ||
             (le_timer_SetRepeat(startCellNetTimer, 0) != LE_OK) ||
             (le_timer_SetInterval(startCellNetTimer, interval) != LE_OK) ||
             (le_timer_Start(startCellNetTimer) != LE_OK) )
        {
            LE_ERROR("Could not start the StartCellNet timer!");
        }
    }
}
//--------------------------------------------------------------------------------------------------
static void StartCellNetTimerHandler
(
    le_timer_Ref_t timerRef
)
{
    le_onoff_t  radioState;
    le_result_t result;

    if(RequestCount == 0)
    {
        // Release has been requested in the meantime, I must cancel the Request command process
        le_timer_Delete(timerRef);
    }
    else
    {
        result=le_mrc_GetRadioPower(&radioState);
        if ((result == LE_OK) && (radioState == LE_ON))
        {
            // The radio is ON, stop and delete the Timer.
            le_timer_Delete(timerRef);

            // Load SIM configuration from secure storage
            le_sim_Id_t simSelected = le_sim_GetSelectedCard();

            if (le_sim_IsPresent(simSelected))
            {
                LoadSimFromSecStore(simSelected);
            }

            // Notify the applications even if the SIM is absent
            GetAndSendCellNetStateEvent();
        }
        else
        {
            le_mrc_SetRadioPower(LE_ON);
            // TODO: find a solution to get off of this infinite loop
        }
    }
}