in modules/hl7802/cellular_hl7802_urc_handler.c [185:277]
static void _cellular_UrcProcessKtcpNotif( CellularContext_t * pContext,
char * pInputLine )
{
CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
char * pLocalInputLine = pInputLine;
char * pToken = NULL;
CellularSocketContext_t * pSocketData = NULL;
uint8_t sessionId = 0;
tcpConnectionFailure_t tcpNotif = TCP_NOTIF_OK;
uint32_t socketIndex = 0;
int32_t tempValue = 0;
if( ( pContext != NULL ) && ( pInputLine != NULL ) )
{
/* The inputline is in this format +KTCP_NOTIF: <session_id>, <tcp_notif>
* This URC indicate connection problem. */
/* Remove leading space. */
atCoreStatus = Cellular_ATRemoveLeadingWhiteSpaces( &pLocalInputLine );
/* Parse the session ID. */
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
atCoreStatus = Cellular_ATGetNextTok( &pLocalInputLine, &pToken );
}
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
atCoreStatus = Cellular_ATStrtoi( pToken, 10, &tempValue );
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
if( ( tempValue >= MIN_TCP_SESSION_ID ) && ( tempValue <= MAX_TCP_SESSION_ID ) )
{
sessionId = ( uint8_t ) tempValue;
socketIndex = _Cellular_GetSocketId( pContext, sessionId );
}
else
{
LogError( ( "error parsing _cellular_UrcProcessKtcpInd session ID" ) );
atCoreStatus = CELLULAR_AT_ERROR;
}
}
}
/* Parse the tcp notif. */
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
atCoreStatus = Cellular_ATGetNextTok( &pLocalInputLine, &pToken );
}
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
atCoreStatus = Cellular_ATStrtoi( pToken, 10, &tempValue );
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
if( ( tempValue >= TCP_NOTIF_OK ) && ( tempValue <= TCP_NOTIF_MAX ) )
{
tcpNotif = ( tcpConnectionFailure_t ) tempValue;
}
else
{
LogError( ( "error parsing _cellular_UrcProcessKtcpInd session ID" ) );
atCoreStatus = CELLULAR_AT_ERROR;
}
}
}
/* Call the callback function of this session. */
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
if( socketIndex == INVALID_SOCKET_INDEX )
{
LogWarn( ( "_cellular_UrcProcessKtcpNotif : unknown session data received. "
"The session %u may not be closed properly in previous execution.", sessionId ) );
}
else
{
pSocketData = _Cellular_GetSocketData( pContext, socketIndex );
if( pSocketData == NULL )
{
LogError( ( "_cellular_UrcProcessKtcpNotif : invalid socket index %u", socketIndex ) );
}
else
{
handleTcpNotif( pSocketData, tcpNotif, sessionId );
}
}
}
}
}