in modules/sara_r4/cellular_r4_api.c [2383:2523]
static CellularPktStatus_t _Cellular_RecvFuncGetPdpContextSettings( CellularContext_t * pContext,
const CellularATCommandResponse_t * pAtResp,
void * pData,
uint16_t dataLen )
{
char * pRespLine = NULL;
CellularPdnContextInfo_t * pPDPContextsInfo = ( CellularPdnContextInfo_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_RecvFuncGetPdpContextSettings: invalid context" ) );
pktStatus = CELLULAR_PKT_STATUS_FAILURE;
}
else if( ( pPDPContextsInfo == NULL ) || ( dataLen != sizeof( CellularPdnContextInfo_t ) ) )
{
pktStatus = CELLULAR_PKT_STATUS_BAD_PARAM;
}
else if( pAtResp == NULL )
{
LogError( ( "_Cellular_RecvFuncGetPdpContextSettings: Response is invalid" ) );
pktStatus = CELLULAR_PKT_STATUS_FAILURE;
}
else if( ( pAtResp->pItm == NULL ) || ( pAtResp->pItm->pLine == NULL ) )
{
LogError( ( "_Cellular_RecvFuncGetPdpContextSettings: 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_RecvFuncGetPdpContextSettings: 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_STATUS_POS_CONTEXT_ID ):
LogDebug( ( "_Cellular_RecvFuncGetPdpContextSettings: 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;
pPDPContextsInfo->contextsPresent[ contextId - 1 ] = true;
LogDebug( ( "_Cellular_RecvFuncGetPdpContextSettings: Context Id: %d", contextId ) );
}
else
{
LogError( ( "_Cellular_RecvFuncGetPdpContextSettings: Invalid Context Id. Token %s", pToken ) );
atCoreStatus = CELLULAR_AT_ERROR;
}
}
break;
case ( CELLULAR_PDN_STATUS_POS_CONTEXT_TYPE ):
LogDebug( ( "_Cellular_RecvFuncGetPdpContextSettings: Context Type pToken: %s", pToken ) );
( void ) memcpy( ( void * ) pPDPContextsInfo->ipType[ contextId - 1 ],
( void * ) pToken, CELULAR_PDN_CONTEXT_TYPE_MAX_SIZE + 1U );
break;
case ( CELLULAR_PDN_STATUS_POS_APN_NAME ):
LogDebug( ( "_Cellular_RecvFuncGetPdpContextSettings: Context APN name pToken: %s", pToken ) );
( void ) memcpy( ( void * ) pPDPContextsInfo->apnName[ contextId - 1 ],
( void * ) pToken, CELLULAR_APN_MAX_SIZE + 1U );
break;
case ( CELLULAR_PDN_STATUS_POS_IP_ADDRESS ):
LogDebug( ( "_Cellular_RecvFuncGetPdpContextSettings: Context IP address pToken: %s", pToken ) );
( void ) memcpy( ( void * ) pPDPContextsInfo->ipAddress[ contextId - 1 ],
( void * ) pToken, CELLULAR_IP_ADDRESS_MAX_SIZE + 1U );
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_RecvFuncGetPdpContextSettings: parse %s failed", pRespLine ) );
break;
}
pCommnadItem = pCommnadItem->pNext;
}
}
return pktStatus;
}