static CellularPktStatus_t _Cellular_RecvFuncGetPdpContextActState()

in modules/sara_r4/cellular_r4_api.c [1177:1308]


static CellularPktStatus_t _Cellular_RecvFuncGetPdpContextActState( CellularContext_t * pContext,
                                                                    const CellularATCommandResponse_t * pAtResp,
                                                                    void * pData,
                                                                    uint16_t dataLen )
{
    char * pRespLine = NULL;
    CellularPdnContextActInfo_t * pPDPContextsActInfo = ( CellularPdnContextActInfo_t * ) pData;
    CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
    CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
    const CellularATCommandLine_t * pCommnadItem = NULL;
    uint8_t tokenIndex = 0;
    uint8_t contextId = 0;
    int32_t tempValue = 0;
    char * pToken = NULL;

    if( pContext == NULL )
    {
        LogError( ( "_Cellular_RecvFuncGetPdpContextActState: invalid context" ) );
        pktStatus = CELLULAR_PKT_STATUS_FAILURE;
    }
    else if( ( pPDPContextsActInfo == NULL ) || ( dataLen != sizeof( CellularPdnContextActInfo_t ) ) )
    {
        pktStatus = CELLULAR_PKT_STATUS_BAD_PARAM;
    }
    else if( pAtResp == NULL )
    {
        LogError( ( "_Cellular_RecvFuncGetPdpContextActState: Response is invalid" ) );
        pktStatus = CELLULAR_PKT_STATUS_FAILURE;
    }
    else if( ( pAtResp->pItm == NULL ) || ( pAtResp->pItm->pLine == NULL ) )
    {
        LogError( ( "_Cellular_RecvFuncGetPdpContextActState: no PDN context available" ) );
        pktStatus = CELLULAR_PKT_STATUS_OK;
    }
    else
    {
        pRespLine = pAtResp->pItm->pLine;

        pCommnadItem = pAtResp->pItm;

        while( pCommnadItem != NULL )
        {
            pRespLine = pCommnadItem->pLine;
            LogDebug( ( "_Cellular_RecvFuncGetPdpContextActState: pRespLine [%s]", pRespLine ) );

            /* Removing all the Spaces in the AT Response. */
            atCoreStatus = Cellular_ATRemoveAllWhiteSpaces( pRespLine );

            if( atCoreStatus == CELLULAR_AT_SUCCESS )
            {
                atCoreStatus = Cellular_ATRemovePrefix( &pRespLine );

                if( atCoreStatus == CELLULAR_AT_SUCCESS )
                {
                    atCoreStatus = Cellular_ATRemoveAllDoubleQuote( pRespLine );
                }

                if( atCoreStatus == CELLULAR_AT_SUCCESS )
                {
                    atCoreStatus = Cellular_ATGetNextTok( &pRespLine, &pToken );
                }

                if( atCoreStatus == CELLULAR_AT_SUCCESS )
                {
                    tokenIndex = 0;

                    while( ( pToken != NULL ) && ( atCoreStatus == CELLULAR_AT_SUCCESS ) )
                    {
                        switch( tokenIndex )
                        {
                            case ( CELLULAR_PDN_ACT_STATUS_POS_CONTEXT_ID ):
                                LogDebug( ( "_Cellular_RecvFuncGetPdpContextActState: Context Id pToken: %s", pToken ) );
                                atCoreStatus = Cellular_ATStrtoi( pToken, 10, &tempValue );

                                if( atCoreStatus == CELLULAR_AT_SUCCESS )
                                {
                                    if( ( tempValue >= ( int32_t ) CELLULAR_PDN_CONTEXT_ID_MIN ) &&
                                        ( tempValue <= ( int32_t ) MAX_PDP_CONTEXTS ) )
                                    {
                                        contextId = ( uint8_t ) tempValue;
                                        pPDPContextsActInfo->contextsPresent[ contextId - 1 ] = true;
                                        LogDebug( ( "_Cellular_RecvFuncGetPdpContextActState: Context Id: %d", contextId ) );
                                    }
                                    else
                                    {
                                        LogError( ( "_Cellular_RecvFuncGetPdpContextActState: Invalid Context Id. Token %s", pToken ) );
                                        atCoreStatus = CELLULAR_AT_ERROR;
                                    }
                                }

                                break;

                            case ( CELLULAR_PDN_ACT_STATUS_POS_CONTEXT_STATE ):
                                LogDebug( ( "_Cellular_RecvFuncGetPdpContextActState: Context <Act> pToken: %s", pToken ) );
                                atCoreStatus = Cellular_ATStrtoi( pToken, 10, &tempValue );

                                if( atCoreStatus == CELLULAR_AT_SUCCESS )
                                {
                                    pPDPContextsActInfo->contextActState[ contextId - 1 ] = ( bool ) tempValue;
                                    LogDebug( ( "_Cellular_RecvFuncGetPdpContextActState: Context <Act>: %d", pPDPContextsActInfo->contextActState[ contextId - 1 ] ) );
                                }

                                break;

                            default:
                                break;
                        }

                        tokenIndex++;

                        if( Cellular_ATGetNextTok( &pRespLine, &pToken ) != CELLULAR_AT_SUCCESS )
                        {
                            break;
                        }
                    }
                }
            }

            pktStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus );

            if( pktStatus != CELLULAR_PKT_STATUS_OK )
            {
                LogError( ( "_Cellular_RecvFuncGetPdpContextActState: parse %s failed", pRespLine ) );
                break;
            }

            pCommnadItem = pCommnadItem->pNext;
        }
    }

    return pktStatus;
}