Beispiel #1
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);


}
Beispiel #2
0
//--------------------------------------------------------------------------------------------------
void simTest_SimSelect
(
)
{
    // Select the embedded SIM
    le_result_t res = le_sim_SelectCard(LE_SIM_EMBEDDED);
    LE_ASSERT(res == LE_OK);

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

    // Select the embedded SIM
    res = le_sim_SelectCard(LE_SIM_EXTERNAL_SLOT_1);
    LE_ASSERT(res == LE_OK);

    // Get the selected card
    simId = le_sim_GetSelectedCard();
    LE_ASSERT(simId == LE_SIM_EXTERNAL_SLOT_1);
}
//--------------------------------------------------------------------------------------------------
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 #4
0
//--------------------------------------------------------------------------------------------------
void simTest_SimPowerUpDown
(
    void
)
{
    le_sim_States_t  state;
    le_sim_Id_t simId;
    le_result_t res;
    le_clk_Time_t timeOut;

    //set timeout seconds for waiting for asynchronous power down event.
    timeOut.sec = 5;
    timeOut.usec = 0;

    SimPowerCycleSemaphore = le_sem_Create("HandlerSimPowerCycle", 0);

    SimPowerCycleThreadRef= le_thread_Create("ThreadSimPowerCycle", SimPowerCycleIndThread, NULL);

    le_thread_Start(SimPowerCycleThreadRef);

    // get blocked here until our event handler is registered and powerCycle thread is running
    res = le_sem_WaitWithTimeOut(SimPowerCycleSemaphore, timeOut);
    LE_ASSERT_OK(res);

    // Power down cases
    simId = le_sim_GetSelectedCard();
    state = le_sim_GetState(simId);
    LE_INFO("test: SIM state %d", state);
    LE_ASSERT(LE_SIM_READY == state);
    LE_ASSERT_OK(le_sim_SetPower(simId, LE_OFF));

    // Wait for complete asynchronous event of powered down (LE_SIM_POWER_DOWN)
    res = le_sem_WaitWithTimeOut(SimPowerCycleSemaphore, timeOut);
    LE_ASSERT_OK(res);
    LE_INFO("Powers Down current SIM: success");

    // Power up cases
    LE_ASSERT_OK(le_sim_SetPower(simId, LE_ON));
    // Wait for complete asynchronous event of powered up  (LE_SIM_READY)
    res = le_sem_WaitWithTimeOut(SimPowerCycleSemaphore, timeOut);
    LE_ASSERT_OK(res);
    LE_INFO("Powers On current SIM: success");

    // Remove the handler
    le_sim_RemoveNewStateHandler(SimPowerCycleHdlrRef);

    // cancel the power cycle test thread
    le_thread_Cancel(SimPowerCycleThreadRef);
}
//--------------------------------------------------------------------------------------------------
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
        }
    }
}
Beispiel #7
0
// -------------------------------------------------------------------------------------------------
static bool ProcessCommand
(
    const char* textPtr,      ///< [IN] Check this text to see if it's a valid command.
    const char* requesterPtr  ///< [IN] If not NULL, then any response text is SMSed to this target.
)
{
    char buffer[10240];

    // Start looking for a match...
    if (strcmp(textPtr, "Crash") == 0)
    {
        // As the name implies, we are going to be crashing the application.  So simply append to
        // the output log and crash the app.  This is done to allow demonstration of the supervisor
        // policies.
        int x = 10;
        int y = 0;

        LE_ERROR("Something wicked this way comes...");
        LE_ERROR("Data result: %d", x / y);
    }
    else if (strcmp(textPtr, "Status") == 0)
    {
        // The status command allows the caller to query the current state of the modem.  A friendly
        // version of this status is constructed and returned to the caller.
        le_onoff_t radioStatus;
        const char * radioStatusPtr;
        le_mrc_NetRegState_t netRegState;
        uint32_t signalQuality;

        if(le_mrc_GetRadioPower(&radioStatus) != LE_OK)
        {
            radioStatusPtr = "in an unknown state";
        }
        else
        {
            radioStatusPtr = (radioStatus == LE_OFF) ? "off" : "on";
        }

        if(le_mrc_GetNetRegState(&netRegState) != LE_OK)
        {
            netRegState = LE_MRC_REG_UNKNOWN;
        }

        if(le_mrc_GetSignalQual(&signalQuality) != LE_OK)
        {
            signalQuality = 0;
        }

        sprintf(buffer, "The radio is %s and is %s. The signal strength is %s.",
                radioStatusPtr,
                GetNetStateString(netRegState),
                GetSignalString(signalQuality));
    }
    else if (strcmp(textPtr, "Sim") == 0)
    {
        // Like the status command, this command queries the underling hardware for information.
        // This information is turned into a string that can then be returned to the caller.
        le_sim_Id_t simId;
        le_sim_States_t simState;

        char iccid[100];
        char imsi[100];
        int pos = 0;

        simId = le_sim_GetSelectedCard();
        simState = le_sim_GetState(simId);

        pos += snprintf(buffer + pos, sizeof(buffer) - pos,
                "SIM %u is %s.",
                simId,
                GetSimStateString(simState));

        if(le_sim_GetICCID(simId, iccid, sizeof(iccid)) == LE_OK)
        {
            pos += snprintf(buffer + pos, sizeof(buffer) - pos,
                    " ICCID=%s", iccid);
        }

        if(le_sim_GetIMSI(simId, imsi, sizeof(imsi)) == LE_OK)
        {
            pos += snprintf(buffer + pos, sizeof(buffer) - pos,
                    " IMSI=%s", imsi);
        }

    }
    else if (strcmp(textPtr, "Online") == 0)
    {
        le_utf8_Copy(buffer, "Requesting data connection.", sizeof(buffer), NULL);
        GoOnline();
    }
    else if (strcmp(textPtr, "Offline") == 0)
    {
        le_utf8_Copy(buffer, "Releasing data connection.", sizeof(buffer), NULL);
        GoOffline(buffer);
    }
    else if (strcmp(textPtr, "TestDataConnectionV4") == 0)
    {
        TestDataConnectionV4(buffer);
    }
    else if (strcmp(textPtr, "TestDataConnectionV6") == 0)
    {
        TestDataConnectionV6(buffer);
    }
    else if (strcmp(textPtr, "Netinfo") == 0)
    {
        Netinfo(buffer);
    }
    else if (strcmp(textPtr, "DataInfo") == 0)
    {
        Datainfo(buffer);
    }
    else if (strcmp(textPtr, "DataReset") == 0)
    {
        DataReset(buffer);
    }
    else if (strcmp(textPtr, "Scan") == 0)
    {
        PerformScan(buffer, sizeof(buffer), requesterPtr);
    }
    else
    {
        return false;
    }

    // Check to see if any processing has occurred.  If so, check to see if the request came from a
    // local or remote requester.
    // If the requester was local, (requesterPtr == NULL) then simply log our response to the SMS log.
    // Otherwise, attempt to SMS the response string to the original caller.
    if (requesterPtr != NULL)
    {
        SendMessage(requesterPtr, buffer);
    }
    else if (OutputFilePtr != NULL)
    {
        fprintf(OutputFilePtr, "## %s ##\n", buffer);
        fflush(OutputFilePtr);
    }

    // Let the calling function know if we did any processing or not.
    return true;
}