Exemplo n.º 1
0
//--------------------------------------------------------------------------------------------------
static void CGEVUnsolHandler
(
    void* reportPtr
)
{
    atmgr_UnsolResponse_t* unsolPtr = reportPtr;
    uint32_t  numParam=0;
    pa_mdc_SessionStateData_t *sessionStatePtr=NULL;

    LE_DEBUG("Handler received -%s-",unsolPtr->line);

    if ( ( FIND_STRING("+CGEV: NW DEACT", unsolPtr->line) )
        ||
         ( FIND_STRING("+CGEV: ME DEACT", unsolPtr->line) )
       )
    {
        numParam = atcmd_CountLineParameter(unsolPtr->line);

        if (numParam == 4) {
            sessionStatePtr = le_mem_ForceAlloc(NewSessionStatePool);
            sessionStatePtr->profileIndex = atoi(atcmd_GetLineParameter(unsolPtr->line,4));
            sessionStatePtr->newState = LE_MDC_DISCONNECTED;

            SetCurrentDataSessionIndex(INVALID_PROFILE_INDEX);

            LE_DEBUG("Send Event for %d with state %d",
                        sessionStatePtr->profileIndex,sessionStatePtr->newState);
            le_event_ReportWithRefCounting(NewSessionStateEvent,sessionStatePtr);
        } else {
            LE_WARN("this Response pattern is not expected -%s-",unsolPtr->line);
        }
    }
}
Exemplo n.º 2
0
//--------------------------------------------------------------------------------------------------
static bool CheckStatus
(
    const char      *lineStr, ///< [IN] line to parse
    le_sim_States_t *statePtr ///< [OUT] SIM state
)
{
    *statePtr = LE_SIM_STATE_UNKNOWN;
    le_result_t result = true;
#define MAXLINE     18
    char line[MAXLINE+1];

    memcpy(line,lineStr,MAXLINE);
    line[MAXLINE] = '\0';

    atcmd_CountLineParameter(line);

    if (FIND_STRING("OK",atcmd_GetLineParameter(line,1)))
    {
        *statePtr = LE_SIM_READY;
    }
    else if (FIND_STRING("+CME ERROR:",atcmd_GetLineParameter(line,1)))
    {
        CheckStatus_CmeErrorCode(atcmd_GetLineParameter(line,2),statePtr);
    }
    else if (FIND_STRING("+CMS ERROR:",atcmd_GetLineParameter(line,1)))
    {
        CheckStatus_CmsErrorCode(atcmd_GetLineParameter(line,2),statePtr);
    }
    else if (FIND_STRING("+CPIN:",atcmd_GetLineParameter(line,1)))
    {
        CheckStatus_CpinCode(atcmd_GetLineParameter(line,2),statePtr);
    }
    else if (FIND_STRING("+WIND:",atcmd_GetLineParameter(line,1)))
    {
        CheckStatus_WindCode(atcmd_GetLineParameter(line,2),statePtr);
    }
    else
    {
        LE_DEBUG("this pattern is not expected -%s-",line);
        *statePtr = LE_SIM_STATE_UNKNOWN;
        result = false;
    }

    LE_DEBUG("SIM Card Status %d",*statePtr);

    return result;
}
Exemplo n.º 3
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_sim_GetSelectedCard
(
    uint32_t*  cardNumPtr     ///< [OUT] The card number selected.
)
{
    le_result_t result=LE_OK;
    atcmdsync_ResultRef_t  resRef = NULL;
    const char* interRespPtr[] = {"+WHCNF: 4",NULL};

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    "at+whcnf?",
                                    &resRef,
                                    interRespPtr,
                                    30000);

    if ( result != LE_OK ) {
        le_mem_Release(resRef); // release pa_at_SendSyncDefaultExt
        return result;
    }

    // If there is more than one line then it mean that the command is OK so the first line is
    // the intermediate one
    if (atcmdsync_GetNumLines(resRef) == 2)
    {
        char* line = atcmdsync_GetLine(resRef,0);
        if (FIND_STRING("+WHCNF: 4,1",line))
        {
            *cardNumPtr = 1;
        }
        else if (FIND_STRING("+WHCNF: 4,2",line))
        {
            *cardNumPtr = 2;
        }
        else
        {
            LE_WARN("this pattern is not expected");
            result =  LE_NOT_POSSIBLE;
        }
    }

    le_mem_Release(resRef);     // Release pa_at_SendSyncDefaultExt

    return result;
}
Exemplo n.º 4
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_mrc_GetRadioPower
(
     le_onoff_t*    powerPtr   ///< [OUT] The power state.
)
{
    int32_t result=LE_NOT_POSSIBLE;
    atcmdsync_ResultRef_t  resRef = NULL;
    const char* interRespPtr[] = {"+CFUN:",NULL};

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    "at+cfun?",
                                    &resRef,
                                    interRespPtr,
                                    30000);

    if ( result != LE_OK ) {
        le_mem_Release(resRef); // release atcmdsync_SendCommandDefaultExt
        return result;
    }
    // If there is more than one line then it mean that the command is OK so the first line is
    // the intermediate one
    if (atcmdsync_GetNumLines(resRef) == 2)
    {
        // it parse just the first line because of '\0'
        char* line = atcmdsync_GetLine(resRef,0);
        // it parse just the first line because of '\0'
        uint32_t numParam = atcmd_CountLineParameter(line);

        // Check is the +CREG intermediate response is in good format
        if (FIND_STRING("+CFUN:",atcmd_GetLineParameter(line,1)))
        {
            if (numParam==2)
            {
                if(atoi(atcmd_GetLineParameter(line,2)) != 0)
                {
                    *powerPtr = LE_ON;
                }
                else
                {
                    *powerPtr = LE_OFF;
                }
                result = LE_OK;
            } else {
                LE_WARN("this pattern is not expected");
                result=LE_NOT_POSSIBLE;
            }
        } else {
            LE_WARN("this pattern is not expected");
            result=LE_NOT_POSSIBLE;
        }
    }

    le_mem_Release(resRef);     // Release atcmdsync_SendCommand

    return result;
}
Exemplo n.º 5
0
//--------------------------------------------------------------------------------------------------
static le_result_t pa_sim_GetRemainingAttempts
(
    uint32_t  idx,      ///< [IN] idx to read
    uint32_t* attemptsPtr  ///< [OUT] The number of attempts still possible
)
{
    le_result_t result=LE_NOT_POSSIBLE;
    atcmdsync_ResultRef_t  resRef = NULL;
    const char* interRespPtr[] = {"+CPINC:",NULL};

    if (!attemptsPtr)
    {
        LE_DEBUG("One parameter is NULL");
        return LE_BAD_PARAMETER;
    }

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    "at+cpinc",
                                    &resRef,
                                    interRespPtr,
                                    30000);

    if ( result != LE_OK ) {
        le_mem_Release(resRef); // release atcmdsync_SendCommandDefaultExt
        return result;
    }

    // If there is more than one line then it mean that the command is OK so the first line is
    // the intermediate one
    if (atcmdsync_GetNumLines(resRef) == 2)
    {
        // it parse just the first line because of '\0'
        char* line = atcmdsync_GetLine(resRef,0);
        uint32_t numParam = atcmd_CountLineParameter(line);
        // it parse just the first line because of '\0'
        if ((numParam==5) && (FIND_STRING("+CPINC:",atcmd_GetLineParameter(line,1))))
        {
            *attemptsPtr = atoi(atcmd_GetLineParameter(line,idx));

            result = LE_OK;
        } else {
            LE_WARN("this pattern is not expected");
            result=LE_NOT_POSSIBLE;
        }

    } else {
        LE_WARN("this pattern is not expected");
        result=LE_NOT_POSSIBLE;
    }

    le_mem_Release(resRef);     // Release atcmdsync_SendCommandDefaultExt

    return result;
}
Exemplo n.º 6
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_sim_GetState
(
    le_sim_States_t* statePtr    ///< [OUT] SIM state
)
{
    int32_t result=LE_NOT_POSSIBLE;
    atcmd_Ref_t atReqRef;
    atcmdsync_ResultRef_t  resRef = NULL;

    const char* finalRespOkPtr[] = {"OK","+CPIN:",NULL};
    const char* finalRespKoPtr[] = {"ERROR","+CME ERROR:","+CMS ERROR:","TIMEOUT",NULL};

    if (!statePtr)
    {
        LE_DEBUG("One parameter is NULL");
        return LE_BAD_PARAMETER;
    }

    *statePtr=LE_SIM_STATE_UNKNOWN;

    atReqRef = atcmd_Create();
    atcmd_AddCommand(atReqRef,"at+cpin?",false);
    atcmd_AddData(atReqRef,NULL,0);
    atcmd_SetTimer(atReqRef,30000,atcmdsync_GetTimerExpiryHandler());
    atcmd_AddIntermediateResp    (atReqRef,atcmdsync_GetIntermediateEventId(),NULL);
    atcmd_AddFinalResp(atReqRef,atcmdsync_GetFinalEventId(),finalRespOkPtr);
    atcmd_AddFinalResp(atReqRef,atcmdsync_GetFinalEventId(),finalRespKoPtr);

    resRef    = atcmdsync_SendCommand(atports_GetInterface(ATPORT_COMMAND),atReqRef);

    char* line = atcmdsync_GetFinalLine(resRef);

    // Check timeout
    if (FIND_STRING("TIMEOUT",line)) {
        LE_WARN("Modem failed");
        le_mem_Release(atReqRef); le_mem_Release(resRef);
        return LE_TIMEOUT;
    }

    if (CheckStatus(line,statePtr))
    {
        ReportStatus(NumCard,*statePtr);
        result = LE_OK;
    }

    le_mem_Release(atReqRef);  // Release atcmdsync_SetCommand
    le_mem_Release(resRef);     // Release atcmdsync_SendCommand

    return result;
}
Exemplo n.º 7
0
//--------------------------------------------------------------------------------------------------
static void MDCInternalHandler
(
    void* reportPtr
)
{
    atmgr_UnsolResponse_t* unsolPtr = reportPtr;

    LE_DEBUG("Handler received -%s-",unsolPtr->line);

    if ( FIND_STRING("NO CARRIER", unsolPtr->line) )
    {
        SetCurrentDataSessionIndex(INVALID_PROFILE_INDEX);
        atmgr_UnSubscribeUnsolReq(atports_GetInterface(ATPORT_COMMAND),InternalEventCall,"NO CARRIER");
    }
}
Exemplo n.º 8
0
//--------------------------------------------------------------------------------------------------
uint32_t pa_sim_CountSlots
(
    void
)
{
    atcmdsync_ResultRef_t  resRef = NULL;
    const char* interRespPtr[] = {"+WHCNF: 4",NULL};
    uint32_t numberOfSim=1;

    le_result_t result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                                "at+whcnf=?",
                                                &resRef,
                                                interRespPtr,
                                                30000);

    if ( result != LE_OK ) {
        le_mem_Release(resRef); // release pa_at_SendSyncDefaultExt
        return result;
    }

    // If there is more than one line then it mean that the command is OK so the first line is
    if (atcmdsync_GetNumLines(resRef) == 2)
    {
        char* line = atcmdsync_GetLine(resRef,0);
        if (FIND_STRING("+WHCNF: 4,(0-3)",line))
        {
            numberOfSim = 2;
        }
        else
        {
            LE_WARN("this pattern is not expected");
            numberOfSim = 1;
        }
    } else {
        numberOfSim = 1;
    }

    le_mem_Release(resRef);     // Release pa_at_SendSyncDefaultExt

    return numberOfSim;
}
Exemplo n.º 9
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_mdc_GetGatewayAddress
(
    uint32_t profileIndex,                  ///< [IN] The profile to use
    le_mdmDefs_IpVersion_t ipVersion,               ///< [IN] IP Version
    char*  gatewayAddrStr,                  ///< [OUT] The gateway IP address in dotted format
    size_t gatewayAddrStrSize               ///< [IN] The size in bytes of the address buffer
)
{
    le_result_t result = LE_FAULT;
    char atcommand[ATCOMMAND_SIZE] ;
    char atintermediate[ATCOMMAND_SIZE];

    atcmdsync_PrepareString(atintermediate,ATCOMMAND_SIZE,"+CGPADDR: %d,",profileIndex);

    const char* interRespPtr[] = {atintermediate,NULL};
    atcmdsync_ResultRef_t  atRespPtr = NULL;

    atcmdsync_PrepareString(atcommand,ATCOMMAND_SIZE,"at+cgpaddr=%d",profileIndex);

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    atcommand,
                                    &atRespPtr,
                                    interRespPtr,
                                    30000);

    if ( result != LE_OK ) {
        le_mem_Release(atRespPtr);
        return result;
    }
    // If there is more than one line then it mean that the command is OK so the first line is
    // the intermediate one
    if (atcmdsync_GetNumLines(atRespPtr) == 2)
    {
        // it parse just the first line because of '\0'
        char* line = atcmdsync_GetLine(atRespPtr,0);
        uint32_t  numParam = atcmd_CountLineParameter(line);
        // it parse just the first line because of '\0'

        if (FIND_STRING("+CGPADDR:",atcmd_GetLineParameter(line,1)))
        {
            if (numParam==3)
            {
                if(atoi(atcmd_GetLineParameter(line,2)) == profileIndex)
                {
                    const char* pAddr = atcmd_GetLineParameter(line,3);
                    size_t length = strlen(pAddr);
                    if (length-2 < gatewayAddrStrSize) {
                        atcmd_CopyStringWithoutQuote(gatewayAddrStr,pAddr,gatewayAddrStrSize);
                        result = LE_OK;
                    } else {
                        result = LE_OVERFLOW;
                    }
                } else
                {
                    LE_WARN("This is not the good profile %d",
                            atoi(atcmd_GetLineParameter(line,2)));
                    result = LE_FAULT;
                }
            } else {
                LE_WARN("this pattern is not expected");
                result = LE_FAULT;
            }
        } else {
            LE_WARN("this pattern is not expected");
            result = LE_FAULT;
        }
    }

    le_mem_Release(atRespPtr);     // Release atcmdsync_SendCommandDefaultExt

    return result;
}
Exemplo n.º 10
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_mdc_ReadProfile
(
    uint32_t profileIndex,                    ///< [IN] The profile to read
    pa_mdc_ProfileData_t* profileDataPtr    ///< [OUT] The profile data
)
{
    le_result_t result = LE_FAULT;
    char atintermediate[ATCOMMAND_SIZE];

    atcmdsync_PrepareString(atintermediate,ATCOMMAND_SIZE,"+CGDCONT: %d,",profileIndex);

    const char* interRespPtr[] = {atintermediate,NULL};
    atcmdsync_ResultRef_t  atRespPtr = NULL;

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    "at+cgdcont?",
                                    &atRespPtr,
                                    interRespPtr,
                                    30000);

    if ( result != LE_OK )
    {
        le_mem_Release(atRespPtr);     // Release atcmdsync_SendCommandDefaultExt
        return result;
    }

    // If there is more than one line then it mean that the command is OK so the first line is
    // the intermediate one
    if (atcmdsync_GetNumLines(atRespPtr) == 2)
    {
        // it parse just the first line because of '\0'
        char* line = atcmdsync_GetLine(atRespPtr,0);
        uint32_t numParam = atcmd_CountLineParameter(line);
        // it parse just the first line because of '\0'

        if ( FIND_STRING("+CGDCONT:",atcmd_GetLineParameter(line,1)))
        {
            if (numParam==7)
            {
                if(atoi(atcmd_GetLineParameter(line,2)) == profileIndex)
                {
                    strncpy(profileDataPtr->apn,
                            atcmd_GetLineParameter(line,4),
                            PA_MDC_APN_MAX_BYTES);
                    result = LE_OK;
                } else
                {
                    LE_WARN("This is not the good profile %d",
                            atoi(atcmd_GetLineParameter(line,2)));
                    result = LE_FAULT;
                }
            } else {
                LE_WARN("this pattern is not expected");
                result=LE_FAULT;
            }
        } else {
            LE_WARN("this pattern is not expected");
            result=LE_FAULT;
        }
    }

    le_mem_Release(atRespPtr);     // Release atcmdsync_SendCommandDefaultExt

    return result;
}
Exemplo n.º 11
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_sim_GetCardIdentification
(
    pa_sim_CardId_t iccid     ///< [OUT] CCID value
)
{
    le_result_t result=LE_OK;
    atcmdsync_ResultRef_t  resRef = NULL;
    const char* interRespPtr[] = {"+CCID:",NULL};

    if (!iccid)
    {
        LE_DEBUG("One parameter is NULL");
        return LE_BAD_PARAMETER;
    }

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    "at+ccid",
                                    &resRef,
                                    interRespPtr,
                                    30000);

    if ( result != LE_OK ) {
        le_mem_Release(resRef);
        return result;
    }

    le_sim_States_t simState=LE_SIM_STATE_UNKNOWN;
    char* line = atcmdsync_GetLine(resRef,0);
    if (CheckStatus(line,&simState))
    {
        ReportStatus(NumCard,simState);
    }

    // check error
    if (atcmdsync_GetNumLines(resRef) == 2)
    {

        line = atcmdsync_GetLine(resRef,0);
        uint32_t numParam = atcmd_CountLineParameter(line);
        // it parse just the first line because of '\0'

        if (FIND_STRING("+CCID:",atcmd_GetLineParameter(line,1)))
        {
            if (numParam==2)
            {
                atcmd_CopyStringWithoutQuote(iccid,
                                            atcmd_GetLineParameter(line,2),
                                            strlen(atcmd_GetLineParameter(line,2)));
                result = LE_OK;
            } else {
                LE_WARN("this pattern is not expected");
                result=LE_NOT_POSSIBLE;
            }
        } else {
            LE_WARN("this pattern is not expected");
            result=LE_NOT_POSSIBLE;
        }
    }

    le_mem_Release(resRef);     // Release atcmdsync_SendCommandDefaultExt
    return result;
}
Exemplo n.º 12
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_mrc_GetSignalStrength
(
    int32_t*          rssiPtr    ///< [OUT] The received signal strength (in dBm).
)
{
    int32_t result=LE_NOT_POSSIBLE;
    atcmdsync_ResultRef_t  resRef = NULL;
    const char* interRespPtr[] = {"+CSQ:",NULL};

    if (!rssiPtr)
    {
        LE_WARN("One parameter is NULL");
        return LE_BAD_PARAMETER;
    }

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    "at+csq",
                                    &resRef,
                                    interRespPtr,
                                    30000);

    if ( result != LE_OK ) {
        le_mem_Release(resRef);     // Release atcmdsync_SendCommandDefaultExt
        return result;
    }

    // If there is more than one line then it mean that the command is OK so the first line is
    if (atcmdsync_GetNumLines(resRef) == 2)
    {
        // it parse just the first line because of '\0'
        char* line = atcmdsync_GetLine(resRef,0);
        uint32_t numParam = atcmd_CountLineParameter(line);
        // it parse just the first line because of '\0'

        if (FIND_STRING("+CSQ:",atcmd_GetLineParameter(line,1)))
        {
            if (numParam==3)
            {
                uint32_t val2 = atoi(atcmd_GetLineParameter(line,2));
                if (val2==99)
                {
                    LE_WARN("Quality signal not detectable");
                    result = LE_OUT_OF_RANGE;
                }
                else
                {
                    *rssiPtr = (-113+(2*val2));
                    result = LE_OK;
                }
            } else {
                LE_WARN("this pattern is not expected");
                result=LE_NOT_POSSIBLE;
            }
        } else {
            LE_WARN("this pattern is not expected");
            result=LE_NOT_POSSIBLE;
        }
    }

    le_mem_Release(resRef);     // Release atcmdsync_SendCommand

    return result;
}
Exemplo n.º 13
0
//--------------------------------------------------------------------------------------------------
static le_result_t GetNetworkReg
(
    bool        first,      ///< true -> mode, false -> state
    int32_t*    valuePtr    ///< value that will be return
)
{
    int32_t result=LE_NOT_POSSIBLE;
    atcmdsync_ResultRef_t  resRef = NULL;
    const char* interRespPtr[] = {"+CREG:",NULL};

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    "at+creg?",
                                    &resRef,
                                    interRespPtr,
                                    30000);

    if ( result != LE_OK ) {
        le_mem_Release(resRef);     // release atcmdsync_SendCommandDefaultExt
        return result;
    }

    // If there is more than one line then it mean that the command is OK so the first line is
    // the intermediate one
    if (atcmdsync_GetNumLines(resRef) == 2)
    {
        // it parse just the first line because of '\0'
        char* line = atcmdsync_GetLine(resRef,0);
        uint32_t numParam = atcmd_CountLineParameter(line);
        // it parse just the first line because of '\0'

        if (FIND_STRING("+CREG:",atcmd_GetLineParameter(line,1)))
        {
            if ((numParam>2) && (numParam<7))
            {
                int32_t val;
                if (first) {
                    val=(int32_t)atoi(atcmd_GetLineParameter(line,2));
                } else {
                    val=(int32_t)atoi(atcmd_GetLineParameter(line,3));
                }
                switch(val)
                {
                    case 0:
                        *valuePtr = LE_MRC_REG_NONE;
                        break;
                    case 1:
                        *valuePtr = LE_MRC_REG_HOME;
                        break;
                    case 2:
                        *valuePtr = LE_MRC_REG_SEARCHING;
                        break;
                    case 3:
                        *valuePtr = LE_MRC_REG_DENIED;
                        break;
                    case 4:
                        *valuePtr = LE_MRC_REG_UNKNOWN;
                        break;
                    case 5:
                        *valuePtr = LE_MRC_REG_ROAMING;
                        break;
                    default:
                        *valuePtr = LE_MRC_REG_UNKNOWN;
                        break;
                }
                result = LE_OK;
            } else {
                LE_WARN("this pattern is not expected");
                result=LE_NOT_POSSIBLE;
            }
        } else {
            LE_WARN("this pattern is not expected");
            result=LE_NOT_POSSIBLE;
        }
    }

    le_mem_Release(resRef);     // Release atcmdsync_SendCommand

    return result;
}