[修改] 增加freeRTOS

1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
2023-05-06 16:43:01 +00:00
commit a345df017b
20944 changed files with 11094377 additions and 0 deletions

View File

@ -0,0 +1,703 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @brief FreeRTOS Cellular Library URC handler implemenation with 3GPP URC.
*/
#ifndef CELLULAR_DO_NOT_USE_CUSTOM_CONFIG
/* Include custom config file before other headers. */
#include "cellular_config.h"
#endif
#include "cellular_config_defaults.h"
/* Standard includes. */
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "cellular_platform.h"
#include "cellular_types.h"
#include "cellular_internal.h"
#include "cellular_common_internal.h"
#include "cellular_common_api.h"
/*-----------------------------------------------------------*/
#define CELLULAR_REG_POS_STAT ( 2U )
#define CELLULAR_REG_POS_LAC_TAC ( 3U )
#define CELLULAR_REG_POS_CELL_ID ( 4U )
#define CELLULAR_REG_POS_RAT ( 5U )
#define CELLULAR_REG_POS_REJ_TYPE ( 6U )
#define CELLULAR_REG_POS_REJ_CAUSE ( 7U )
/*-----------------------------------------------------------*/
static CellularPktStatus_t _parseRegStatusInRegStatusParsing( CellularContext_t * pContext,
CellularNetworkRegType_t regType,
const char * pToken,
cellularAtData_t * pLibAtData );
static CellularPktStatus_t _parseLacTacInRegStatus( CellularNetworkRegType_t regType,
const char * pToken,
cellularAtData_t * pLibAtData );
static CellularPktStatus_t _parseCellIdInRegStatus( const char * pToken,
cellularAtData_t * pLibAtData );
static CellularPktStatus_t _parseRatInfoInRegStatus( const char * pToken,
cellularAtData_t * pLibAtData );
static CellularPktStatus_t _parseRejectTypeInRegStatus( CellularNetworkRegType_t regType,
const char * pToken,
cellularAtData_t * pLibAtData );
static CellularPktStatus_t _parseRejectCauseInRegStatus( CellularNetworkRegType_t regType,
const char * pToken,
cellularAtData_t * pLibAtData );
static CellularPktStatus_t _regStatusSwitchParsingFunc( CellularContext_t * pContext,
uint8_t i,
CellularNetworkRegType_t regType,
const char * pToken,
cellularAtData_t * pLibAtData );
static void _regStatusGenerateLog( char * pRegPayload,
CellularNetworkRegType_t regType );
static void _regStatusGenerateEvent( const CellularContext_t * pContext,
CellularNetworkRegType_t regType,
const cellularAtData_t * pLibAtData );
static bool _Cellular_RegEventStatus( const cellularAtData_t * pLibAtData,
CellularNetworkRegType_t regType,
CellularNetworkRegistrationStatus_t prevCsRegStatus,
CellularNetworkRegistrationStatus_t prevPsRegStatus );
/*-----------------------------------------------------------*/
static CellularPktStatus_t _parseRegStatusInRegStatusParsing( CellularContext_t * pContext,
CellularNetworkRegType_t regType,
const char * pToken,
cellularAtData_t * pLibAtData )
{
int32_t tempValue = 0;
CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK;
CellularNetworkRegistrationStatus_t regStatus = REGISTRATION_STATUS_UNKNOWN;
if( ( regType != CELLULAR_REG_TYPE_CREG ) && ( regType != CELLULAR_REG_TYPE_CEREG ) &&
( regType != CELLULAR_REG_TYPE_CGREG ) )
{
packetStatus = CELLULAR_PKT_STATUS_BAD_PARAM;
}
else
{
atCoreStatus = Cellular_ATStrtoi( pToken, 10, &tempValue );
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
if( ( tempValue >= 0 ) && ( tempValue < ( int32_t ) REGISTRATION_STATUS_MAX ) )
{
/* MISRA Ref 10.5.1 [Essential type casting] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-105 */
/* coverity[misra_c_2012_rule_10_5_violation] */
regStatus = ( CellularNetworkRegistrationStatus_t ) tempValue;
}
else
{
atCoreStatus = CELLULAR_AT_ERROR;
}
}
packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus );
}
if( packetStatus == CELLULAR_PKT_STATUS_OK )
{
if( regType == CELLULAR_REG_TYPE_CREG )
{
pLibAtData->csRegStatus = regStatus;
}
else
{
pLibAtData->psRegStatus = regStatus;
}
if( regStatus == REGISTRATION_STATUS_REGISTERED_HOME )
{
LogDebug( ( "Netowrk registration : HOME" ) );
}
else if( regStatus == REGISTRATION_STATUS_ROAMING_REGISTERED )
{
LogDebug( ( "Netowrk registration : ROAMING" ) );
}
else if( regStatus == REGISTRATION_STATUS_REGISTRATION_DENIED )
{
/* clear the atlib data if the registration failed. */
LogDebug( ( "Netowrk registration : DEINED" ) );
_Cellular_InitAtData( pContext, 1 );
}
else
{
/* clear the atlib data if the registration failed. */
LogDebug( ( "Netowrk registration : OTHERS" ) );
_Cellular_InitAtData( pContext, 1 );
}
}
return packetStatus;
}
/*-----------------------------------------------------------*/
static CellularPktStatus_t _parseLacTacInRegStatus( CellularNetworkRegType_t regType,
const char * pToken,
cellularAtData_t * pLibAtData )
{
int32_t tempValue = 0;
uint16_t var = 0;
CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK;
atCoreStatus = Cellular_ATStrtoi( pToken, 16, &tempValue );
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
if( ( tempValue >= 0 ) && ( tempValue <= UINT16_MAX ) )
{
var = ( uint16_t ) tempValue;
}
else
{
atCoreStatus = CELLULAR_AT_ERROR;
}
}
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
/* Parsing Location area code for CREG or CGREG. */
if( ( regType == CELLULAR_REG_TYPE_CREG ) || ( regType == CELLULAR_REG_TYPE_CGREG ) )
{
pLibAtData->lac = ( uint16_t ) var;
}
/* Parsing Tracking area code for CEREG. */
else if( regType == CELLULAR_REG_TYPE_CEREG )
{
pLibAtData->tac = ( uint16_t ) var;
}
else
{
/* Empty else MISRA 15.7 */
}
}
packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus );
return packetStatus;
}
/*-----------------------------------------------------------*/
static CellularPktStatus_t _parseCellIdInRegStatus( const char * pToken,
cellularAtData_t * pLibAtData )
{
int32_t tempValue = 0;
CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK;
atCoreStatus = Cellular_ATStrtoi( pToken, 16, &tempValue );
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
if( tempValue >= 0 )
{
pLibAtData->cellId = ( uint32_t ) tempValue;
}
else
{
LogError( ( "Error in processing Cell Id. Token %s", pToken ) );
atCoreStatus = CELLULAR_AT_ERROR;
}
}
packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus );
return packetStatus;
}
/*-----------------------------------------------------------*/
static CellularPktStatus_t _parseRatInfoInRegStatus( const char * pToken,
cellularAtData_t * pLibAtData )
{
int32_t var = 0;
CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK;
atCoreStatus = Cellular_ATStrtoi( pToken, 10, &var );
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
if( var >= ( int32_t ) CELLULAR_RAT_MAX )
{
atCoreStatus = CELLULAR_AT_ERROR;
LogError( ( "Error in processing RAT. Token %s", pToken ) );
}
else if( ( var == ( int32_t ) CELLULAR_RAT_GSM ) || ( var == ( int32_t ) CELLULAR_RAT_EDGE ) ||
( var == ( int32_t ) CELLULAR_RAT_CATM1 ) || ( var == ( int32_t ) CELLULAR_RAT_NBIOT ) )
{
/* MISRA Ref 10.5.1 [Essential type casting] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-105 */
/* coverity[misra_c_2012_rule_10_5_violation] */
pLibAtData->rat = ( CellularRat_t ) var;
}
else if( var == ( int32_t ) CELLULAR_RAT_LTE )
{
/* Some cellular module use 7 : CELLULAR_RAT_LTE to indicate CAT-M1. */
pLibAtData->rat = ( CellularRat_t ) CELLULAR_RAT_LTE;
}
else
{
pLibAtData->rat = CELLULAR_RAT_INVALID;
}
}
packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus );
return packetStatus;
}
/*-----------------------------------------------------------*/
static CellularPktStatus_t _parseRejectTypeInRegStatus( CellularNetworkRegType_t regType,
const char * pToken,
cellularAtData_t * pLibAtData )
{
int32_t tempValue = 0;
uint8_t rejType = 0;
CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK;
atCoreStatus = Cellular_ATStrtoi( pToken, 10, &tempValue );
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
if( ( tempValue >= 0 ) && ( tempValue <= ( int32_t ) UINT8_MAX ) )
{
rejType = ( uint8_t ) tempValue;
}
else
{
atCoreStatus = CELLULAR_AT_ERROR;
}
}
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
if( regType == CELLULAR_REG_TYPE_CREG )
{
/* Reject Type is only stored if the registration status is denied. */
if( pLibAtData->csRegStatus == REGISTRATION_STATUS_REGISTRATION_DENIED )
{
pLibAtData->csRejectType = rejType;
}
}
else if( ( regType == CELLULAR_REG_TYPE_CGREG ) || ( regType == CELLULAR_REG_TYPE_CEREG ) )
{
if( pLibAtData->psRegStatus == REGISTRATION_STATUS_REGISTRATION_DENIED )
{
pLibAtData->psRejectType = rejType;
}
}
else
{
/* Empty else MISRA 15.7 */
}
}
packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus );
return packetStatus;
}
/*-----------------------------------------------------------*/
static CellularPktStatus_t _parseRejectCauseInRegStatus( CellularNetworkRegType_t regType,
const char * pToken,
cellularAtData_t * pLibAtData )
{
int32_t tempValue = 0;
uint8_t rejCause = 0;
CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK;
atCoreStatus = Cellular_ATStrtoi( pToken, 10, &tempValue );
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
if( ( tempValue >= 0 ) && ( tempValue <= ( int32_t ) UINT8_MAX ) )
{
rejCause = ( uint8_t ) tempValue;
}
else
{
atCoreStatus = CELLULAR_AT_ERROR;
}
}
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
if( regType == CELLULAR_REG_TYPE_CREG )
{
if( pLibAtData->csRegStatus == REGISTRATION_STATUS_REGISTRATION_DENIED )
{
pLibAtData->csRejCause = rejCause;
}
}
else if( ( regType == CELLULAR_REG_TYPE_CGREG ) || ( regType == CELLULAR_REG_TYPE_CEREG ) )
{
if( pLibAtData->psRegStatus == REGISTRATION_STATUS_REGISTRATION_DENIED )
{
pLibAtData->psRejCause = rejCause;
}
}
else
{
/* Empty else MISRA 15.7 */
}
}
packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus );
return packetStatus;
}
/*-----------------------------------------------------------*/
static CellularPktStatus_t _regStatusSwitchParsingFunc( CellularContext_t * pContext,
uint8_t i,
CellularNetworkRegType_t regType,
const char * pToken,
cellularAtData_t * pLibAtData )
{
CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK;
switch( i )
{
/* Parsing network Registration status in CREG or CGREG or CEREG response. */
case CELLULAR_REG_POS_STAT:
packetStatus = _parseRegStatusInRegStatusParsing( pContext, regType, pToken, pLibAtData );
break;
case CELLULAR_REG_POS_LAC_TAC:
packetStatus = _parseLacTacInRegStatus( regType, pToken, pLibAtData );
break;
/* Parsing Cell ID. */
case CELLULAR_REG_POS_CELL_ID:
packetStatus = _parseCellIdInRegStatus( pToken, pLibAtData );
break;
/* Parsing RAT Information. */
case CELLULAR_REG_POS_RAT:
packetStatus = _parseRatInfoInRegStatus( pToken, pLibAtData );
break;
/* Parsing Reject Type. */
case CELLULAR_REG_POS_REJ_TYPE:
packetStatus = _parseRejectTypeInRegStatus( regType, pToken, pLibAtData );
break;
/* Parsing the Reject Cause. */
case CELLULAR_REG_POS_REJ_CAUSE:
packetStatus = _parseRejectCauseInRegStatus( regType, pToken, pLibAtData );
break;
default:
LogDebug( ( "Unknown Parameter Position in Registration URC" ) );
break;
}
return packetStatus;
}
/*-----------------------------------------------------------*/
static void _regStatusGenerateLog( char * pRegPayload,
CellularNetworkRegType_t regType )
{
( void ) pRegPayload;
if( regType == CELLULAR_REG_TYPE_CREG )
{
LogDebug( ( "URC: CREG: %s", pRegPayload ) );
}
else if( regType == CELLULAR_REG_TYPE_CGREG )
{
LogDebug( ( "URC: CGREG: %s", pRegPayload ) );
}
else if( regType == CELLULAR_REG_TYPE_CEREG )
{
LogDebug( ( "URC: CEREG: %s", pRegPayload ) );
}
else
{
LogDebug( ( " URC: Unknown " ) );
}
}
/*-----------------------------------------------------------*/
static void _regStatusGenerateEvent( const CellularContext_t * pContext,
CellularNetworkRegType_t regType,
const cellularAtData_t * pLibAtData )
{
CellularServiceStatus_t serviceStatus;
( void ) memset( &serviceStatus, 0, sizeof( CellularServiceStatus_t ) );
serviceStatus.rat = pLibAtData->rat;
serviceStatus.csRegistrationStatus = pLibAtData->csRegStatus;
serviceStatus.psRegistrationStatus = pLibAtData->psRegStatus;
serviceStatus.csRejectionCause = pLibAtData->csRejCause;
serviceStatus.csRejectionType = pLibAtData->csRejectType;
serviceStatus.psRejectionCause = pLibAtData->psRejCause;
serviceStatus.psRejectionType = pLibAtData->psRejectType;
/* Data should be obtained from COPS commmand. User should obtain with APIs. */
( void ) strcpy( serviceStatus.plmnInfo.mcc, "FFF" );
( void ) strcpy( serviceStatus.plmnInfo.mnc, "FFF" );
( void ) strcpy( serviceStatus.operatorName, "FFF" );
serviceStatus.operatorNameFormat = OPERATOR_NAME_FORMAT_NOT_PRESENT;
serviceStatus.networkRegistrationMode = REGISTRATION_MODE_UNKNOWN;
if( pContext->cbEvents.networkRegistrationCallback != NULL )
{
if( regType == CELLULAR_REG_TYPE_CREG )
{
_Cellular_NetworkRegistrationCallback( pContext, CELLULAR_URC_EVENT_NETWORK_CS_REGISTRATION, &serviceStatus );
}
else
{
_Cellular_NetworkRegistrationCallback( pContext, CELLULAR_URC_EVENT_NETWORK_PS_REGISTRATION, &serviceStatus );
}
}
}
/*-----------------------------------------------------------*/
/* check registration event change to decide to generate event. */
static bool _Cellular_RegEventStatus( const cellularAtData_t * pLibAtData,
CellularNetworkRegType_t regType,
CellularNetworkRegistrationStatus_t prevCsRegStatus,
CellularNetworkRegistrationStatus_t prevPsRegStatus )
{
bool retEventChanged = false;
switch( regType )
{
case CELLULAR_REG_TYPE_CREG:
if( pLibAtData->csRegStatus != prevCsRegStatus )
{
retEventChanged = true;
}
break;
case CELLULAR_REG_TYPE_CGREG:
case CELLULAR_REG_TYPE_CEREG:
if( pLibAtData->psRegStatus != prevPsRegStatus )
{
retEventChanged = true;
}
break;
default:
LogInfo( ( "_Cellular_RegEventStatus : unknown reg type " ) );
break;
}
return retEventChanged;
}
/*-----------------------------------------------------------*/
CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext,
char * pRegPayload,
bool isUrc,
CellularNetworkRegType_t regType )
{
uint8_t i = 0;
char * pRegStr = NULL, * pToken = NULL;
cellularAtData_t * pLibAtData = NULL;
CellularPktStatus_t packetStatus = CELLULAR_PKT_STATUS_OK;
CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
CellularNetworkRegistrationStatus_t prevCsRegStatus = REGISTRATION_STATUS_UNKNOWN;
CellularNetworkRegistrationStatus_t prevPsRegStatus = REGISTRATION_STATUS_UNKNOWN;
if( pContext == NULL )
{
packetStatus = CELLULAR_PKT_STATUS_FAILURE;
}
else if( pRegPayload == NULL )
{
packetStatus = CELLULAR_PKT_STATUS_BAD_PARAM;
}
else
{
pLibAtData = &pContext->libAtData;
if( isUrc == true )
{
i++;
}
pRegStr = pRegPayload;
atCoreStatus = Cellular_ATRemoveAllDoubleQuote( pRegStr );
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
atCoreStatus = Cellular_ATRemoveAllWhiteSpaces( pRegStr );
}
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
atCoreStatus = Cellular_ATGetNextTok( &pRegStr, &pToken );
}
if( atCoreStatus == CELLULAR_AT_SUCCESS )
{
/* Backup the previous regStatus. */
prevCsRegStatus = pLibAtData->csRegStatus;
prevPsRegStatus = pLibAtData->psRegStatus;
while( pToken != NULL )
{
i++;
packetStatus = _regStatusSwitchParsingFunc( pContext, i, regType,
pToken, pLibAtData );
/* Getting next token to parse. */
if( Cellular_ATGetNextTok( &pRegStr, &pToken ) != CELLULAR_AT_SUCCESS )
{
break;
}
}
}
/* Generate logs. */
if( isUrc == true )
{
_regStatusGenerateLog( pRegPayload, regType );
}
/* If Registration Status changed, generate the event. */
if( ( _Cellular_RegEventStatus( pLibAtData, regType, prevCsRegStatus, prevPsRegStatus ) == true ) )
{
_regStatusGenerateEvent( pContext, regType, pLibAtData );
}
if( atCoreStatus != CELLULAR_AT_SUCCESS )
{
packetStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus );
}
}
return packetStatus;
}
/*-----------------------------------------------------------*/
CellularPktStatus_t Cellular_CommonUrcProcessCreg( CellularContext_t * pContext,
char * pInputLine )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
if( pContext != NULL )
{
_Cellular_LockAtDataMutex( pContext );
pktStatus = _Cellular_ParseRegStatus( pContext, pInputLine, true, CELLULAR_REG_TYPE_CREG );
if( pktStatus != CELLULAR_PKT_STATUS_OK )
{
LogDebug( ( "Creg Parse failure" ) );
}
_Cellular_UnlockAtDataMutex( pContext );
}
else
{
pktStatus = CELLULAR_PKT_STATUS_INVALID_HANDLE;
}
return pktStatus;
}
/*-----------------------------------------------------------*/
CellularPktStatus_t Cellular_CommonUrcProcessCgreg( CellularContext_t * pContext,
char * pInputLine )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
if( pContext != NULL )
{
_Cellular_LockAtDataMutex( pContext );
pktStatus = _Cellular_ParseRegStatus( pContext, pInputLine, true, CELLULAR_REG_TYPE_CGREG );
if( pktStatus != CELLULAR_PKT_STATUS_OK )
{
LogDebug( ( "Cgreg Parse failure" ) );
}
_Cellular_UnlockAtDataMutex( pContext );
}
else
{
pktStatus = CELLULAR_PKT_STATUS_INVALID_HANDLE;
}
return pktStatus;
}
/*-----------------------------------------------------------*/
CellularPktStatus_t Cellular_CommonUrcProcessCereg( CellularContext_t * pContext,
char * pInputLine )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
if( pContext != NULL )
{
_Cellular_LockAtDataMutex( pContext );
pktStatus = _Cellular_ParseRegStatus( pContext, pInputLine, true, CELLULAR_REG_TYPE_CEREG );
if( pktStatus != CELLULAR_PKT_STATUS_OK )
{
LogDebug( ( "Cereg Parse failure" ) );
}
_Cellular_UnlockAtDataMutex( pContext );
}
else
{
pktStatus = CELLULAR_PKT_STATUS_INVALID_HANDLE;
}
return pktStatus;
}
/*-----------------------------------------------------------*/

View File

@ -0,0 +1,863 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @brief FreeRTOS Cellular Library common AT command parsing functions.
*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifndef CELLULAR_DO_NOT_USE_CUSTOM_CONFIG
/* Include custom config file before other headers. */
#include "cellular_config.h"
#endif
#include "cellular_config_defaults.h"
#include "cellular_at_core.h"
#include "cellular_internal.h"
/*-----------------------------------------------------------*/
#ifndef CELLULAR_CHECK_IS_PREFIX_CHAR
#define CELLULAR_CHECK_IS_PREFIX_CHAR( inputChar ) \
( ( ( ( int32_t ) isalpha( ( ( int8_t ) ( inputChar ) ) ) ) == 0 ) && \
( ( ( int32_t ) isdigit( ( ( int8_t ) ( inputChar ) ) ) ) == 0 ) && \
( ( inputChar ) != '+' ) && ( ( inputChar ) != '_' ) )
#endif
/*-----------------------------------------------------------*/
/**
* @brief String validation results.
*/
typedef enum CellularATStringValidationResult
{
CELLULAR_AT_STRING_VALID, /**< String is valid. */
CELLULAR_AT_STRING_EMPTY, /**< String is empty. */
CELLULAR_AT_STRING_TOO_LARGE, /**< String is too large. */
CELLULAR_AT_STRING_UNKNOWN /**< Unknown String validation state. */
} CellularATStringValidationResult_t;
/*-----------------------------------------------------------*/
static void validateString( const char * pString,
CellularATStringValidationResult_t * pStringValidationResult );
static uint8_t _charToNibble( char c );
/*-----------------------------------------------------------*/
static void validateString( const char * pString,
CellularATStringValidationResult_t * pStringValidationResult )
{
const char * pNullCharacterLocation = NULL;
/* Validate the string length. If the string length is longer than expected, return
* error to stop further processing.
*
* CELLULAR_AT_MAX_STRING_SIZE defines the valid string length excluding NULL terminating
* character. The longest valid string has '\0' at ( CELLULAR_AT_MAX_STRING_SIZE + 1U )
*/
pNullCharacterLocation = memchr( pString, ( int32_t ) '\0', ( CELLULAR_AT_MAX_STRING_SIZE + 1U ) );
if( pNullCharacterLocation == pString )
{
*pStringValidationResult = CELLULAR_AT_STRING_EMPTY;
}
else if( pNullCharacterLocation == NULL )
{
*pStringValidationResult = CELLULAR_AT_STRING_TOO_LARGE;
}
else
{
*pStringValidationResult = CELLULAR_AT_STRING_VALID;
}
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATIsPrefixPresent( const char * pString,
bool * pResult )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
char * ptrPrefixChar = NULL;
char * ptrChar = NULL;
if( ( pResult == NULL ) || ( pString == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( pString, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
/* Find location of first ':'. */
if( atStatus == CELLULAR_AT_SUCCESS )
{
*pResult = true;
ptrPrefixChar = strchr( pString, ( int32_t ) ':' );
if( ptrPrefixChar == NULL )
{
*pResult = false;
}
else
{
/* There should be only '+', '_', characters or digit before seperator. */
for( ptrChar = ( char * ) pString; ptrChar < ptrPrefixChar; ptrChar++ )
{
/* It's caused by stanard api isalpha and isdigit. */
/* MISRA Ref 4.6.1 [Basic numerical type] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-46 */
/* MISRA Ref 10.4.1 [Same essential type] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-104 */
/* MISRA Ref 10.8.1 [Essential type casting] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-108 */
/* coverity[misra_c_2012_directive_4_6_violation] */
/* coverity[misra_c_2012_rule_10_4_violation] */
/* coverity[misra_c_2012_rule_10_8_violation] */
if( CELLULAR_CHECK_IS_PREFIX_CHAR( ( char ) ( *ptrChar ) ) )
{
*pResult = false;
break;
}
}
}
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATStrStartWith( const char * pString,
const char * pPrefix,
bool * pResult )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
const char * pTempString = pString;
const char * pTempPrefix = pPrefix;
if( ( pResult == NULL ) || ( pString == NULL ) || ( pPrefix == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( pTempString, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( pTempPrefix, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
*pResult = true;
while( *pTempPrefix != '\0' )
{
if( *pTempPrefix != *pTempString )
{
*pResult = false;
break;
}
pTempPrefix++;
pTempString++;
}
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATRemovePrefix( char ** ppString )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
if( ( ppString == NULL ) || ( *ppString == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( *ppString, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
/* The strchr() function returns a pointer to the first occurrence of
* the character in the string or NULL if the character is not found.
*
* In case of AT response, prefix is always followed by a colon (':'). */
*ppString = strchr( *ppString, ( int32_t ) ':' );
if( *ppString == NULL )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
else
{
/* Note that we remove both the prefix and the colon. */
( *ppString )++;
}
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATRemoveLeadingWhiteSpaces( char ** ppString )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
if( ( ppString == NULL ) || ( *ppString == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( *ppString, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
/* isspace is a standard library function and we cannot control it. */
/* MISRA Ref 4.6.1 [Basic numerical type] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-46 */
/* MISRA Ref 21.13.1 [Character representation] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-2113 */
/* coverity[misra_c_2012_rule_21_13_violation] */
/* coverity[misra_c_2012_directive_4_6_violation] */
while( ( **ppString != '\0' ) && ( isspace( ( ( int ) ( **ppString ) ) ) != 0U ) )
{
( *ppString )++;
}
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATRemoveTrailingWhiteSpaces( char * pString )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
char * p = NULL;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
uint32_t stringLen = 0;
if( pString == NULL )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( pString, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
stringLen = ( uint32_t ) strlen( pString );
/* This API intend to remove the trailing space, and this should be functional
* when the string length is greater than 2. */
if( stringLen > 2U )
{
p = &pString[ stringLen ];
do
{
--p;
/* isspace is a standard library function and we cannot control it. */
/* MISRA Ref 4.6.1 [Basic numerical type] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-46 */
/* MISRA Ref 21.13.1 [Character representation] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-2113 */
/* coverity[misra_c_2012_directive_4_6_violation] */
/* coverity[misra_c_2012_rule_21_13_violation] */
} while( ( p > pString ) && ( isspace( ( int ) ( *p ) ) != 0U ) );
p[ 1 ] = '\0';
}
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATRemoveAllWhiteSpaces( char * pString )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
char * p = NULL;
uint16_t ind = 0;
char * pTempString = pString;
if( pString == NULL )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( pTempString, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
p = pTempString;
while( ( *pTempString ) != '\0' )
{
/* isspace is a standard library function and we cannot control it. */
/* MISRA Ref 4.6.1 [Basic numerical type] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-46 */
/* MISRA Ref 21.13.1 [Character representation] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-2113 */
/* coverity[misra_c_2012_rule_21_13_violation] */
/* coverity[misra_c_2012_directive_4_6_violation] */
if( isspace( ( ( int ) ( *pTempString ) ) ) == 0U )
{
p[ ind ] = *pTempString;
ind++;
}
pTempString++;
}
p[ ind ] = '\0';
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATRemoveOutermostDoubleQuote( char ** ppString )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
char * p = NULL;
uint32_t stringLen = 0;
if( ( ppString == NULL ) || ( *ppString == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( *ppString, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
stringLen = ( uint32_t ) strlen( *ppString );
if( stringLen > 2U )
{
if( **ppString == '\"' )
{
( *ppString )++;
}
p = *ppString;
while( *p != '\0' )
{
p++;
}
if( *--p == '\"' )
{
*p = '\0';
}
}
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATRemoveAllDoubleQuote( char * pString )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
char * p = NULL;
uint16_t ind = 0;
char * pTempString = pString;
if( pString == NULL )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( pTempString, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
p = pTempString;
while( ( *pTempString ) != '\0' )
{
if( *pTempString != '\"' )
{
p[ ind ] = *pTempString;
ind++;
}
pTempString++;
}
p[ ind ] = '\0';
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATGetNextTok( char ** ppString,
char ** ppTokOutput )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
const char * pDelimiter = ",";
if( ( ppString == NULL ) || ( ppTokOutput == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
atStatus = Cellular_ATGetSpecificNextTok( ppString, pDelimiter, ppTokOutput );
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATGetSpecificNextTok( char ** ppString,
const char * pDelimiter,
char ** ppTokOutput )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
uint16_t tokStrLen = 0, dataStrlen = 0;
char * tok = NULL;
if( ( ppString == NULL ) || ( pDelimiter == NULL ) ||
( ppTokOutput == NULL ) || ( *ppString == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( *ppString, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
dataStrlen = ( uint16_t ) strlen( *ppString );
if( ( **ppString ) == ( *pDelimiter ) )
{
**ppString = '\0';
tok = *ppString;
}
else
{
tok = strtok( *ppString, pDelimiter );
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
tokStrLen = ( uint16_t ) strlen( tok );
if( ( tokStrLen < dataStrlen ) && ( ( *ppString )[ tokStrLen + 1U ] != '\0' ) )
{
*ppString = &tok[ strlen( tok ) + 1U ];
}
else
{
*ppString = &tok[ strlen( tok ) ];
}
*ppTokOutput = tok;
}
return atStatus;
}
/*-----------------------------------------------------------*/
static uint8_t _charToNibble( char c )
{
uint8_t ret = 0xFF;
if( ( c >= '0' ) && ( c <= '9' ) )
{
ret = ( uint8_t ) ( ( uint32_t ) c - ( uint32_t ) '0' );
}
else if( ( c >= 'a' ) && ( c <= 'f' ) )
{
ret = ( uint8_t ) ( ( uint32_t ) c - ( uint32_t ) 'a' + ( uint32_t ) 10 );
}
else
{
if( ( c >= 'A' ) && ( c <= 'F' ) )
{
ret = ( uint8_t ) ( ( uint32_t ) c - ( uint32_t ) 'A' + ( uint32_t ) 10 );
}
}
return ret;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATHexStrToHex( const char * pString,
uint8_t * pHexData,
uint16_t hexDataLen )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
uint16_t strHexLen = 0, i = 0;
const char * p;
uint8_t firstNibble = 0, secondNibble = 0;
if( ( pString == NULL ) || ( pHexData == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( pString, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
strHexLen = ( uint16_t ) ( strlen( pString ) / 2U );
if( strHexLen >= hexDataLen )
{
atStatus = CELLULAR_AT_NO_MEMORY;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
p = pString;
for( i = 0; i < strHexLen; i++ )
{
firstNibble = _charToNibble( *p );
secondNibble = _charToNibble( p[ 1 ] );
if( firstNibble == 0xFFU )
{
( pHexData )[ i ] = firstNibble;
}
else
{
firstNibble = firstNibble << 4;
( pHexData )[ i ] = firstNibble | secondNibble;
}
p = &p[ 2 ];
}
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATIsStrDigit( const char * pString,
bool * pResult )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
const char * pTempString = pString;
if( ( pResult == NULL ) || ( pString == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( pTempString, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
*pResult = true;
while( ( *pTempString != '\0' ) )
{
/* isdigit is a standard library function and we cannot control it. */
/* MISRA Ref 4.6.1 [Basic numerical type] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-46 */
/* coverity[misra_c_2012_directive_4_6_violation] */
if( isdigit( ( ( int ) ( *pTempString ) ) ) == 0U )
{
*pResult = false;
}
pTempString++;
}
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATcheckErrorCode( const char * pInputBuf,
const char * const * const ppKeyList,
size_t keyListLen,
bool * pResult )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
uint8_t i = 0;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
bool tmpResult;
if( ( pInputBuf == NULL ) || ( ppKeyList == NULL ) || ( pResult == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( pInputBuf, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
*pResult = false;
for( i = 0; i < keyListLen; i++ )
{
if( ( Cellular_ATStrStartWith( pInputBuf, ppKeyList[ i ], &tmpResult ) == CELLULAR_AT_SUCCESS ) && tmpResult )
{
*pResult = true;
break;
}
}
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATStrDup( char ** ppDst,
const char * pSrc )
{
char * p = NULL;
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
const char * pTempSrc = pSrc;
CellularATStringValidationResult_t stringValidationResult = CELLULAR_AT_STRING_UNKNOWN;
if( ( ppDst == NULL ) || ( pTempSrc == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
validateString( pTempSrc, &stringValidationResult );
if( stringValidationResult != CELLULAR_AT_STRING_VALID )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
}
if( atStatus == CELLULAR_AT_SUCCESS )
{
*ppDst = ( char * ) Platform_Malloc( sizeof( char ) * ( strlen( pTempSrc ) + 1U ) );
if( *ppDst != NULL )
{
p = *ppDst;
while( *pTempSrc != '\0' )
{
*p = *pTempSrc;
p++;
pTempSrc++;
}
*p = '\0';
}
else
{
atStatus = CELLULAR_AT_NO_MEMORY;
}
}
return atStatus;
}
/*-----------------------------------------------------------*/
CellularATError_t Cellular_ATStrtoi( const char * pStr,
int32_t base,
int32_t * pResult )
{
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
int32_t retStrtol = 0;
char * pEndStr = NULL;
if( ( pStr == NULL ) || ( pResult == NULL ) )
{
atStatus = CELLULAR_AT_BAD_PARAMETER;
}
else
{
/* MISRA Ref 22.8.1 [Initialize errno] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-228 */
/* coverity[misra_c_2012_rule_22_8_violation] */
retStrtol = ( int32_t ) strtol( pStr, &pEndStr, base );
/* The return value zero may stand for the failure of strtol. So if the return value
* is zero, need to check the address of pEndStr, if it's greater than the pStr, that
* means there is an real parsed zero before pEndStr.
*/
if( pEndStr == pStr )
{
atStatus = CELLULAR_AT_ERROR;
}
else
{
*pResult = retStrtol;
}
}
/* MISRA Ref 4.7.1 [Testing errno] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-47 */
/* MISRA Ref 22.9.1 [Testing errno] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-229 */
/* coverity[need_errno_test] */
/* coverity[return_without_test] */
return atStatus;
}
/*-----------------------------------------------------------*/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,543 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @brief FreeRTOS Cellular Library APIs implementation without AT commands.
*/
/* The config header is always included first. */
#ifndef CELLULAR_DO_NOT_USE_CUSTOM_CONFIG
/* Include custom config file before other headers. */
#include "cellular_config.h"
#endif
#include "cellular_config_defaults.h"
/* Standard includes. */
#include <stdio.h>
#include <string.h>
#include "cellular_platform.h"
#include "cellular_types.h"
#include "cellular_api.h"
#include "cellular_internal.h"
#include "cellular_common_internal.h"
#include "cellular_pkthandler_internal.h"
#include "cellular_pktio_internal.h"
#include "cellular_common_portable.h"
#include "cellular_common_api.h"
/*-----------------------------------------------------------*/
static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t option,
CellularSocketHandle_t socketHandle,
const uint8_t * pOptionValue,
uint32_t optionValueLength );
/*-----------------------------------------------------------*/
/* Internal function of Cellular_SocketSetSockOpt to reduce complexity. */
static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t option,
CellularSocketHandle_t socketHandle,
const uint8_t * pOptionValue,
uint32_t optionValueLength )
{
CellularError_t cellularStatus = CELLULAR_SUCCESS;
const uint32_t * pTimeoutMs = NULL;
if( option == CELLULAR_SOCKET_OPTION_SEND_TIMEOUT )
{
if( optionValueLength == sizeof( uint32_t ) )
{
/* MISRA Ref 11.3 [Misaligned access] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
pTimeoutMs = ( const uint32_t * ) pOptionValue;
socketHandle->sendTimeoutMs = *pTimeoutMs;
}
else
{
cellularStatus = CELLULAR_INTERNAL_FAILURE;
}
}
else if( option == CELLULAR_SOCKET_OPTION_RECV_TIMEOUT )
{
if( optionValueLength == sizeof( uint32_t ) )
{
/* MISRA Ref 11.3 [Misaligned access] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
pTimeoutMs = ( const uint32_t * ) pOptionValue;
socketHandle->recvTimeoutMs = *pTimeoutMs;
}
else
{
cellularStatus = CELLULAR_INTERNAL_FAILURE;
}
}
else if( option == CELLULAR_SOCKET_OPTION_PDN_CONTEXT_ID )
{
if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint8_t ) ) )
{
socketHandle->contextId = *pOptionValue;
}
else
{
LogError( ( "Cellular_SocketSetSockOpt: Cannot change the contextID in this state %d or length %d is invalid.",
socketHandle->socketState, optionValueLength ) );
cellularStatus = CELLULAR_INTERNAL_FAILURE;
}
}
else if( option == CELLULAR_SOCKET_OPTION_SET_LOCAL_PORT )
{
if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint16_t ) ) )
{
/* MISRA Ref 11.3 [Misaligned access] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-113 */
/* coverity[misra_c_2012_rule_11_3_violation] */
socketHandle->localPort = *( ( uint16_t * ) pOptionValue );
}
else
{
LogError( ( "Cellular_SocketSetSockOpt: Cannot change the localPort in this state %d or length %d is invalid.",
socketHandle->socketState, optionValueLength ) );
cellularStatus = CELLULAR_INTERNAL_FAILURE;
}
}
else
{
LogError( ( "Cellular_SocketSetSockOpt: Option not supported" ) );
cellularStatus = CELLULAR_UNSUPPORTED;
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonInit( CellularHandle_t * pCellularHandle,
const CellularCommInterface_t * pCommInterface,
const CellularTokenTable_t * pTokenTable )
{
CellularError_t cellularStatus = CELLULAR_SUCCESS;
CellularContext_t * pContext = NULL;
/* Init the common library. */
cellularStatus = _Cellular_LibInit( pCellularHandle, pCommInterface, pTokenTable );
/* Init the module. */
if( cellularStatus == CELLULAR_SUCCESS )
{
pContext = *pCellularHandle;
cellularStatus = Cellular_ModuleInit( pContext, &pContext->pModueContext );
}
/* Setup UE, URC and query register status. */
if( cellularStatus == CELLULAR_SUCCESS )
{
cellularStatus = Cellular_ModuleEnableUE( pContext );
}
if( cellularStatus == CELLULAR_SUCCESS )
{
cellularStatus = Cellular_ModuleEnableUrc( pContext );
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonCleanup( CellularHandle_t cellularHandle )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
if( pContext == NULL )
{
cellularStatus = CELLULAR_INVALID_HANDLE;
}
else
{
( void ) Cellular_ModuleCleanUp( pContext );
( void ) _Cellular_LibCleanup( cellularHandle );
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonRegisterUrcNetworkRegistrationEventCallback( CellularHandle_t cellularHandle,
CellularUrcNetworkRegistrationCallback_t networkRegistrationCallback,
void * pCallbackContext )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
if( cellularStatus != CELLULAR_SUCCESS )
{
LogDebug( ( "_Cellular_CheckLibraryStatus failed" ) );
}
else
{
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->cbEvents.networkRegistrationCallback = networkRegistrationCallback;
pContext->cbEvents.pNetworkRegistrationCallbackContext = pCallbackContext;
PlatformMutex_Unlock( &pContext->PktRespMutex );
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonRegisterUrcPdnEventCallback( CellularHandle_t cellularHandle,
CellularUrcPdnEventCallback_t pdnEventCallback,
void * pCallbackContext )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
if( cellularStatus != CELLULAR_SUCCESS )
{
LogDebug( ( "_Cellular_CheckLibraryStatus failed" ) );
}
else
{
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->cbEvents.pdnEventCallback = pdnEventCallback;
pContext->cbEvents.pPdnEventCallbackContext = pCallbackContext;
PlatformMutex_Unlock( &pContext->PktRespMutex );
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonRegisterUrcSignalStrengthChangedCallback( CellularHandle_t cellularHandle,
CellularUrcSignalStrengthChangedCallback_t signalStrengthChangedCallback,
void * pCallbackContext )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
if( cellularStatus != CELLULAR_SUCCESS )
{
LogDebug( ( "_Cellular_CheckLibraryStatus failed" ) );
}
else
{
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->cbEvents.signalStrengthChangedCallback = signalStrengthChangedCallback;
pContext->cbEvents.pSignalStrengthChangedCallbackContext = pCallbackContext;
PlatformMutex_Unlock( &pContext->PktRespMutex );
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonRegisterUrcGenericCallback( CellularHandle_t cellularHandle,
CellularUrcGenericCallback_t genericCallback,
void * pCallbackContext )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
if( cellularStatus != CELLULAR_SUCCESS )
{
LogDebug( ( "_Cellular_CheckLibraryStatus failed" ) );
}
else
{
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->cbEvents.genericCallback = genericCallback;
pContext->cbEvents.pGenericCallbackContext = pCallbackContext;
PlatformMutex_Unlock( &pContext->PktRespMutex );
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonRegisterModemEventCallback( CellularHandle_t cellularHandle,
CellularModemEventCallback_t modemEventCallback,
void * pCallbackContext )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
if( cellularStatus != CELLULAR_SUCCESS )
{
LogDebug( ( "_Cellular_CheckLibraryStatus failed" ) );
}
else
{
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->cbEvents.modemEventCallback = modemEventCallback;
pContext->cbEvents.pModemEventCallbackContext = pCallbackContext;
PlatformMutex_Unlock( &pContext->PktRespMutex );
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonATCommandRaw( CellularHandle_t cellularHandle,
const char * pATCommandPrefix,
const char * pATCommandPayload,
CellularATCommandType_t atCommandType,
CellularATCommandResponseReceivedCallback_t responseReceivedCallback,
void * pData,
uint16_t dataLen )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
CellularAtReq_t atReqGetResult = { 0 };
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
if( cellularStatus != CELLULAR_SUCCESS )
{
LogDebug( ( "_Cellular_CheckLibraryStatus failed" ) );
}
else if( pATCommandPayload == NULL )
{
LogError( ( "Cellular_ATCommandRaw: Input parameter is NULL" ) );
cellularStatus = CELLULAR_BAD_PARAMETER;
}
else
{
atReqGetResult.atCmdType = atCommandType;
atReqGetResult.pAtRspPrefix = ( const char * ) pATCommandPrefix;
atReqGetResult.pAtCmd = ( const char * ) pATCommandPayload;
atReqGetResult.pData = pData;
atReqGetResult.dataLen = dataLen;
atReqGetResult.respCallback = responseReceivedCallback;
pktStatus = _Cellular_TimeoutAtcmdRequestWithCallback( pContext,
atReqGetResult,
CELLULAR_AT_COMMAND_RAW_TIMEOUT_MS );
cellularStatus = _Cellular_TranslatePktStatus( pktStatus );
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonCreateSocket( CellularHandle_t cellularHandle,
uint8_t pdnContextId,
CellularSocketDomain_t socketDomain,
CellularSocketType_t socketType,
CellularSocketProtocol_t socketProtocol,
CellularSocketHandle_t * pSocketHandle )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
if( cellularStatus != CELLULAR_SUCCESS )
{
LogDebug( ( "_Cellular_CheckLibraryStatus failed" ) );
}
else if( pSocketHandle == NULL )
{
LogError( ( "pSocketHandle is NULL" ) );
cellularStatus = CELLULAR_BAD_PARAMETER;
}
else if( _Cellular_IsValidPdn( pdnContextId ) != CELLULAR_SUCCESS )
{
LogError( ( "_Cellular_IsValidPdn failed" ) );
cellularStatus = CELLULAR_INVALID_HANDLE;
}
else
{
cellularStatus = _Cellular_CreateSocketData( pContext, pdnContextId,
socketDomain, socketType, socketProtocol, pSocketHandle );
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonSocketSetSockOpt( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketOptionLevel_t optionLevel,
CellularSocketOption_t option,
const uint8_t * pOptionValue,
uint32_t optionValueLength )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
if( cellularStatus != CELLULAR_SUCCESS )
{
LogDebug( ( "_Cellular_CheckLibraryStatus failed" ) );
}
else if( socketHandle == NULL )
{
cellularStatus = CELLULAR_INVALID_HANDLE;
}
else if( ( pOptionValue == NULL ) || ( optionValueLength == 0U ) )
{
LogError( ( "Cellular_SocketSetSockOpt: Invalid parameter" ) );
cellularStatus = CELLULAR_BAD_PARAMETER;
}
else
{
if( optionLevel == CELLULAR_SOCKET_OPTION_LEVEL_IP )
{
LogError( ( "Cellular_SocketSetSockOpt: Option not supported" ) );
cellularStatus = CELLULAR_UNSUPPORTED;
}
else /* optionLevel CELLULAR_SOCKET_OPTION_LEVEL_TRANSPORT. */
{
cellularStatus = _socketSetSockOptLevelTransport( option, socketHandle, pOptionValue, optionValueLength );
}
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonSocketRegisterDataReadyCallback( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketDataReadyCallback_t dataReadyCallback,
void * pCallbackContext )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
if( cellularStatus != CELLULAR_SUCCESS )
{
LogDebug( ( "_Cellular_CheckLibraryStatus failed" ) );
}
else if( socketHandle == NULL )
{
cellularStatus = CELLULAR_INVALID_HANDLE;
}
else
{
socketHandle->dataReadyCallback = dataReadyCallback;
socketHandle->pDataReadyCallbackContext = pCallbackContext;
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonSocketRegisterSocketOpenCallback( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketOpenCallback_t socketOpenCallback,
void * pCallbackContext )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
if( cellularStatus != CELLULAR_SUCCESS )
{
LogDebug( ( "_Cellular_CheckLibraryStatus failed" ) );
}
else if( socketHandle == NULL )
{
cellularStatus = CELLULAR_INVALID_HANDLE;
}
else
{
socketHandle->openCallback = socketOpenCallback;
socketHandle->pOpenCallbackContext = pCallbackContext;
}
return cellularStatus;
}
/*-----------------------------------------------------------*/
CellularError_t Cellular_CommonSocketRegisterClosedCallback( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketClosedCallback_t closedCallback,
void * pCallbackContext )
{
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
if( cellularStatus != CELLULAR_SUCCESS )
{
LogDebug( ( "_Cellular_CheckLibraryStatus failed" ) );
}
else if( socketHandle == NULL )
{
cellularStatus = CELLULAR_INVALID_HANDLE;
}
else
{
socketHandle->closedCallback = closedCallback;
socketHandle->pClosedCallbackContext = pCallbackContext;
}
return cellularStatus;
}
/*-----------------------------------------------------------*/

View File

@ -0,0 +1,917 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @brief FreeRTOS Cellular Library common packet handler functions to dispatch packet.
*/
#ifndef CELLULAR_DO_NOT_USE_CUSTOM_CONFIG
/* Include custom config file before other headers. */
#include "cellular_config.h"
#endif
#include "cellular_config_defaults.h"
/* Standard includes. */
#include <stdlib.h>
#include <string.h>
#include "cellular_platform.h"
#include "cellular_internal.h"
#include "cellular_pkthandler_internal.h"
#include "cellular_pktio_internal.h"
#include "cellular_types.h"
#include "cellular_common_internal.h"
/*-----------------------------------------------------------*/
#ifndef MIN
#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
#endif
/* Windows simulator implementation. */
#if defined( _WIN32 ) || defined( _WIN64 )
#define strtok_r strtok_s
#endif
/*-----------------------------------------------------------*/
static CellularPktStatus_t _convertAndQueueRespPacket( CellularContext_t * pContext,
const void * pBuf );
static CellularPktStatus_t urcParseToken( CellularContext_t * pContext,
char * pInputLine );
static CellularPktStatus_t _processUrcPacket( CellularContext_t * pContext,
const char * pBuf );
static CellularPktStatus_t _Cellular_AtcmdRequestTimeoutWithCallbackRaw( CellularContext_t * pContext,
CellularAtReq_t atReq,
uint32_t timeoutMS );
static CellularPktStatus_t _Cellular_DataSendWithTimeoutDelayRaw( CellularContext_t * pContext,
CellularAtDataReq_t dataReq,
uint32_t timeoutMs,
uint32_t interDelayMS );
static void _Cellular_PktHandlerAcquirePktRequestMutex( CellularContext_t * pContext );
static void _Cellular_PktHandlerReleasePktRequestMutex( CellularContext_t * pContext );
static int _searchCompareFunc( const void * pInputToken,
const void * pBase );
static int32_t _sortCompareFunc( const void * pElem1Ptr,
const void * pElem2Ptr );
static void _Cellular_ProcessGenericUrc( const CellularContext_t * pContext,
const char * pInputLine );
static CellularPktStatus_t _atParseGetHandler( CellularContext_t * pContext,
const char * pTokenPtr,
char * pSavePtr );
static CellularPktStatus_t _handleUndefinedMessage( CellularContext_t * pContext,
const char * pLine );
/*-----------------------------------------------------------*/
static CellularPktStatus_t _convertAndQueueRespPacket( CellularContext_t * pContext,
const void * pBuf )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
const CellularATCommandResponse_t * pAtResp = NULL;
if( ( pBuf != NULL ) )
{
pAtResp = ( const CellularATCommandResponse_t * ) pBuf;
if( pAtResp->status == false )
{
/* The modem returns error code to indicate that the command failed. */
pktStatus = CELLULAR_PKT_STATUS_FAILURE;
}
if( ( pContext->pktRespCB != NULL ) && ( pktStatus == CELLULAR_PKT_STATUS_OK ) )
{
pktStatus = pContext->pktRespCB( pContext,
( const CellularATCommandResponse_t * ) pBuf,
pContext->pPktUsrData,
pContext->PktUsrDataLen );
}
/* Notify calling thread, Not blocking immediately comes back if the queue is full. */
if( xQueueSend( pContext->pktRespQueue, ( void * ) &pktStatus, ( TickType_t ) 0 ) != pdPASS )
{
pktStatus = CELLULAR_PKT_STATUS_FAILURE;
LogError( ( "_convertAndQueueRespPacket: Got a response when the Resp Q is full!!" ) );
}
}
else
{
pktStatus = CELLULAR_PKT_STATUS_BAD_PARAM;
}
return pktStatus;
}
/*-----------------------------------------------------------*/
static CellularPktStatus_t urcParseToken( CellularContext_t * pContext,
char * pInputLine )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
/* pInputLine = "+" pTokenPtr + ":" + pSavePtr.
* if string not start with "+", then pTokenPtr = pSavePtr = pInputPtr. */
char * pSavePtr = pInputLine, * pTokenPtr = pInputLine;
LogDebug( ( "Next URC token to parse [%s]", pInputLine ) );
/* First check for + at the beginning and advance to point to the next
* byte. Use that string to pass to strtok and retrieve the token. Once the
* token use is retrieved, get the function handler map and call that
* function. */
if( *pSavePtr == '+' )
{
pSavePtr++;
pTokenPtr = strtok_r( pSavePtr, ":", &pSavePtr );
if( pTokenPtr == NULL )
{
LogError( ( "_Cellular_AtParse : input string error, start with \"+\" but no token %s", pInputLine ) );
pktStatus = CELLULAR_PKT_STATUS_BAD_REQUEST;
}
}
if( pktStatus == CELLULAR_PKT_STATUS_OK )
{
/* Now get the handler function based on the token. */
pktStatus = _atParseGetHandler( pContext, pTokenPtr, pSavePtr );
}
return pktStatus;
}
/*-----------------------------------------------------------*/
/**
* @brief copy the URC log in the buffer to a heap memory and process it.
*/
static CellularPktStatus_t _processUrcPacket( CellularContext_t * pContext,
const char * pBuf )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
char * payload = NULL;
if( pBuf != NULL )
{
atStatus = Cellular_ATStrDup( &payload, pBuf );
if( atStatus == CELLULAR_AT_SUCCESS )
{
/* The payload is null terminated. */
pktStatus = urcParseToken( pContext, ( char * ) payload );
Platform_Free( payload );
}
else
{
pktStatus = CELLULAR_PKT_STATUS_FAILURE;
LogWarn( ( "Couldn't allocate memory of %u for urc", ( uint32_t ) strlen( pBuf ) ) );
}
}
else
{
pktStatus = CELLULAR_PKT_STATUS_BAD_PARAM;
}
return pktStatus;
}
/*-----------------------------------------------------------*/
static CellularPktStatus_t _Cellular_AtcmdRequestTimeoutWithCallbackRaw( CellularContext_t * pContext,
CellularAtReq_t atReq,
uint32_t timeoutMS )
{
CellularPktStatus_t respCode = CELLULAR_PKT_STATUS_OK;
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
BaseType_t qRet = pdFALSE;
if( atReq.pAtCmd == NULL )
{
LogError( ( "PKT_STATUS_BAD_REQUEST, null AT param" ) );
pktStatus = CELLULAR_PKT_STATUS_BAD_REQUEST;
}
else
{
LogDebug( ( ">>>>>Start sending [%s]<<<<<", atReq.pAtCmd ) );
/* Fill in request info structure. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->pktRespCB = atReq.respCallback;
pContext->pPktUsrData = atReq.pData;
pContext->PktUsrDataLen = ( uint16_t ) atReq.dataLen;
pContext->pCurrentCmd = atReq.pAtCmd;
PlatformMutex_Unlock( &pContext->PktRespMutex );
pktStatus = _Cellular_PktioSendAtCmd( pContext, atReq.pAtCmd, atReq.atCmdType, atReq.pAtRspPrefix );
if( pktStatus != CELLULAR_PKT_STATUS_OK )
{
LogError( ( "Can't send req packet" ) );
}
else
{
/* Wait for a response. */
qRet = xQueueReceive( pContext->pktRespQueue, &respCode, pdMS_TO_TICKS( timeoutMS ) );
if( qRet == pdTRUE )
{
pktStatus = ( CellularPktStatus_t ) respCode;
if( pktStatus != CELLULAR_PKT_STATUS_OK )
{
LogWarn( ( "Modem returns error in sending AT command %s, pktStatus %d.",
atReq.pAtCmd, pktStatus ) );
} /* Ignore errors from callbacks as they will be handled elsewhere. */
}
else
{
pktStatus = CELLULAR_PKT_STATUS_TIMED_OUT;
LogError( ( "pkt_recv status=%d, AT cmd %s timed out", pktStatus, atReq.pAtCmd ) );
}
}
/* No command is waiting response. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->PktioAtCmdType = CELLULAR_AT_NO_COMMAND;
pContext->pktRespCB = NULL;
pContext->pCurrentCmd = NULL;
PlatformMutex_Unlock( &pContext->PktRespMutex );
LogDebug( ( "<<<<<Exit sending [%s] status[%d]<<<<<", atReq.pAtCmd, pktStatus ) );
}
return pktStatus;
}
/*-----------------------------------------------------------*/
static CellularPktStatus_t _Cellular_DataSendWithTimeoutDelayRaw( CellularContext_t * pContext,
CellularAtDataReq_t dataReq,
uint32_t timeoutMs,
uint32_t interDelayMS )
{
CellularPktStatus_t respCode = CELLULAR_PKT_STATUS_OK;
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
BaseType_t qStatus = pdFALSE;
uint32_t sendEndPatternLen = 0U;
if( ( dataReq.pData == NULL ) || ( dataReq.pSentDataLength == NULL ) )
{
LogError( ( "_Cellular_DataSendWithTimeoutDelayRaw, null input" ) );
pktStatus = CELLULAR_PKT_STATUS_BAD_REQUEST;
}
else
{
LogDebug( ( ">>>>>Start sending Data <<<<<" ) );
/* Send the packet. Data send is regarded as CELLULAR_AT_NO_RESULT. Only
* success or error token is expected in the result. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->PktioAtCmdType = CELLULAR_AT_NO_RESULT;
PlatformMutex_Unlock( &pContext->PktRespMutex );
*dataReq.pSentDataLength = _Cellular_PktioSendData( pContext, dataReq.pData, dataReq.dataLen );
if( *dataReq.pSentDataLength != dataReq.dataLen )
{
LogError( ( "_Cellular_DataSendWithTimeoutDelayRaw, incomplete data transfer" ) );
pktStatus = CELLULAR_PKT_STATUS_SEND_ERROR;
}
}
/* Some driver required wait for a minimum of delay before sending data. */
Platform_Delay( interDelayMS );
/* End pattern for specific modem. */
if( ( pktStatus == CELLULAR_PKT_STATUS_OK ) && ( dataReq.pEndPattern != NULL ) )
{
sendEndPatternLen = _Cellular_PktioSendData( pContext, dataReq.pEndPattern, dataReq.endPatternLen );
if( sendEndPatternLen != dataReq.endPatternLen )
{
LogError( ( "_Cellular_DataSendWithTimeoutDelayRaw, incomplete endpattern transfer" ) );
pktStatus = CELLULAR_PKT_STATUS_SEND_ERROR;
}
}
/* Wait for a response. */
if( pktStatus == CELLULAR_PKT_STATUS_OK )
{
qStatus = xQueueReceive( pContext->pktRespQueue, &respCode, pdMS_TO_TICKS( timeoutMs ) );
if( qStatus == pdTRUE )
{
pktStatus = ( CellularPktStatus_t ) respCode;
if( pktStatus == CELLULAR_PKT_STATUS_OK )
{
LogDebug( ( "Data sent successfully!" ) );
}
else
{
LogWarn( ( "Modem returns error in sending data, pktStatus %d.", pktStatus ) );
}
}
else
{
pktStatus = CELLULAR_PKT_STATUS_TIMED_OUT;
LogError( ( "pkt_recv status=%d, data sending timed out", pktStatus ) );
}
/* Set AT command type to CELLULAR_AT_NO_COMMAND for timeout case here. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->PktioAtCmdType = CELLULAR_AT_NO_COMMAND;
PlatformMutex_Unlock( &pContext->PktRespMutex );
LogDebug( ( "<<<<<Exit sending data ret[%d]>>>>>", pktStatus ) );
}
return pktStatus;
}
/*-----------------------------------------------------------*/
static void _Cellular_PktHandlerAcquirePktRequestMutex( CellularContext_t * pContext )
{
PlatformMutex_Lock( &pContext->pktRequestMutex );
}
/*-----------------------------------------------------------*/
static void _Cellular_PktHandlerReleasePktRequestMutex( CellularContext_t * pContext )
{
PlatformMutex_Unlock( &pContext->pktRequestMutex );
}
/*-----------------------------------------------------------*/
static int _searchCompareFunc( const void * pInputToken,
const void * pBase )
{
int compareValue = 0;
const char * pToken = ( const char * ) pInputToken;
const CellularAtParseTokenMap_t * pBasePtr = ( const CellularAtParseTokenMap_t * ) pBase;
uint32_t tokenLen = ( uint32_t ) strlen( pInputToken );
uint32_t strLen = ( uint32_t ) strlen( pBasePtr->pStrValue );
compareValue = strncmp( pToken,
pBasePtr->pStrValue,
MIN( tokenLen, strLen ) );
/* To avoid undefined behavior, the table should not contain duplicated item and
* compareValue is 0 only if the string is exactly the same. */
if( ( compareValue == 0 ) && ( tokenLen != strLen ) )
{
if( tokenLen > strLen )
{
compareValue = 1;
}
else
{
compareValue = -1;
}
}
return compareValue;
}
/*-----------------------------------------------------------*/
static int32_t _sortCompareFunc( const void * pElem1Ptr,
const void * pElem2Ptr )
{
int32_t compareValue = 0;
const CellularAtParseTokenMap_t * pElement1Ptr = ( const CellularAtParseTokenMap_t * ) pElem1Ptr;
const CellularAtParseTokenMap_t * pElement2Ptr = ( const CellularAtParseTokenMap_t * ) pElem2Ptr;
uint32_t element1PtrLen = ( uint32_t ) strlen( pElement1Ptr->pStrValue );
uint32_t element2PtrLen = ( uint32_t ) strlen( pElement2Ptr->pStrValue );
compareValue = strncmp( pElement1Ptr->pStrValue,
pElement2Ptr->pStrValue,
MIN( element1PtrLen, element2PtrLen ) );
/* To avoid undefined behavior, the table should not contain duplicated item and
* compareValue is 0 only if the string is exactly the same. */
if( ( compareValue == 0 ) && ( element1PtrLen != element2PtrLen ) )
{
if( element1PtrLen > element2PtrLen )
{
compareValue = 1;
}
else
{
compareValue = -1;
}
}
return compareValue;
}
/*-----------------------------------------------------------*/
static void _Cellular_ProcessGenericUrc( const CellularContext_t * pContext,
const char * pInputLine )
{
_Cellular_GenericCallback( pContext, pInputLine );
}
/*-----------------------------------------------------------*/
static CellularPktStatus_t _atParseGetHandler( CellularContext_t * pContext,
const char * pTokenPtr,
char * pSavePtr )
{
/* Now get the handler function based on the token. */
const CellularAtParseTokenMap_t * pElementPtr = NULL;
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
const CellularAtParseTokenMap_t * pTokenMap = pContext->tokenTable.pCellularUrcHandlerTable;
uint32_t tokenMapSize = pContext->tokenTable.cellularPrefixToParserMapSize;
uint8_t decrementPointer = 0U;
/* MISRA Ref 21.9.1 [Use of bsearch] */
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-219 */
/* coverity[misra_c_2012_rule_21_9_violation] */
pElementPtr = ( CellularAtParseTokenMap_t * ) bsearch( ( const void * ) pTokenPtr,
( const void * ) pTokenMap,
tokenMapSize,
sizeof( CellularAtParseTokenMap_t ),
_searchCompareFunc );
if( pElementPtr != NULL )
{
if( pElementPtr->parserFunc != NULL )
{
pElementPtr->parserFunc( pContext, pSavePtr );
}
else
{
LogWarn( ( "No URC Callback func avail %s", pTokenPtr ) );
pktStatus = CELLULAR_PKT_STATUS_FAILURE;
}
}
else
{
/* No URC callback function available, check for generic call back. */
LogDebug( ( "No URC Callback func avail %s, now trying generic URC Callback", pTokenPtr ) );
if( pSavePtr != pTokenPtr )
{
/* pSavePtr != pTokenPtr means the string starts with '+'.
* Restore string to "+pTokenPtr:pSavePtr" for callback function. */
decrementPointer = 1U;
*( pSavePtr - 1 ) = ':';
}
_Cellular_ProcessGenericUrc( pContext, pTokenPtr - decrementPointer );
}
return pktStatus;
}
/*-----------------------------------------------------------*/
/*
* @brief Handle AT_UNDEFINED message type.
*/
static CellularPktStatus_t _handleUndefinedMessage( CellularContext_t * pContext,
const char * pLine )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
LogInfo( ( "AT_UNDEFINED message received %s\r\n", pLine ) );
/* undefined message received. Try to handle it with cellular module
* specific handler. */
if( pContext->undefinedRespCallback == NULL )
{
LogError( ( "No undefined callback for AT_UNDEFINED type message %s received.",
pLine ) );
pktStatus = CELLULAR_PKT_STATUS_INVALID_DATA;
}
else
{
pktStatus = pContext->undefinedRespCallback( pContext->pUndefinedRespCBContext, pLine );
if( pktStatus != CELLULAR_PKT_STATUS_OK )
{
LogError( ( "undefinedRespCallback returns error %d for AT_UNDEFINED type message %s received.",
pktStatus, pLine ) );
pktStatus = CELLULAR_PKT_STATUS_INVALID_DATA;
}
}
return pktStatus;
}
/*-----------------------------------------------------------*/
void _Cellular_PktHandlerCleanup( CellularContext_t * pContext )
{
if( ( pContext != NULL ) && ( pContext->pktRespQueue != NULL ) )
{
/* Wait for response to finish. */
_Cellular_PktHandlerAcquirePktRequestMutex( pContext );
/* This is platform dependent api. */
( void ) vQueueDelete( pContext->pktRespQueue );
pContext->pktRespQueue = NULL;
_Cellular_PktHandlerReleasePktRequestMutex( pContext );
}
}
/*-----------------------------------------------------------*/
CellularPktStatus_t _Cellular_HandlePacket( CellularContext_t * pContext,
_atRespType_t atRespType,
const void * pBuf )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
if( pContext != NULL )
{
switch( atRespType )
{
case AT_SOLICITED:
pktStatus = _convertAndQueueRespPacket( pContext, pBuf );
break;
case AT_UNSOLICITED:
pktStatus = _processUrcPacket( pContext, pBuf );
break;
case AT_UNDEFINED:
pktStatus = _handleUndefinedMessage( pContext, pBuf );
break;
default:
pktStatus = CELLULAR_PKT_STATUS_BAD_PARAM;
LogError( ( "_Cellular_HandlePacket Callback type (%d) error", atRespType ) );
break;
}
}
else
{
pktStatus = CELLULAR_PKT_STATUS_INVALID_HANDLE;
}
return pktStatus;
}
/*-----------------------------------------------------------*/
CellularPktStatus_t _Cellular_PktHandler_AtcmdRequestWithCallback( CellularContext_t * pContext,
CellularAtReq_t atReq,
uint32_t timeoutMS )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
if( pContext == NULL )
{
LogError( ( "_Cellular_TimeoutAtcmdRequestWithCallback : Invalid cellular context" ) );
pktStatus = CELLULAR_PKT_STATUS_INVALID_HANDLE;
}
else
{
_Cellular_PktHandlerAcquirePktRequestMutex( pContext );
pktStatus = _Cellular_AtcmdRequestTimeoutWithCallbackRaw( pContext, atReq, timeoutMS );
_Cellular_PktHandlerReleasePktRequestMutex( pContext );
}
return pktStatus;
}
/*-----------------------------------------------------------*/
CellularPktStatus_t _Cellular_AtcmdRequestSuccessToken( CellularContext_t * pContext,
CellularAtReq_t atReq,
uint32_t atTimeoutMS,
const char ** pCellularSrcTokenSuccessTable,
uint32_t cellularSrcTokenSuccessTableSize )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
if( pContext == NULL )
{
LogError( ( "_Cellular_AtcmdRequestSuccessToken : Invalid cellular context" ) );
pktStatus = CELLULAR_PKT_STATUS_INVALID_HANDLE;
}
else if( pCellularSrcTokenSuccessTable == NULL )
{
LogError( ( "_Cellular_AtcmdRequestSuccessToken : pCellularSrcTokenSuccessTable is NULL" ) );
pktStatus = CELLULAR_PKT_STATUS_BAD_PARAM;
}
else
{
_Cellular_PktHandlerAcquirePktRequestMutex( pContext );
/* Set the extra Token table for this AT command. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->tokenTable.pCellularSrcExtraTokenSuccessTable = pCellularSrcTokenSuccessTable;
pContext->tokenTable.cellularSrcExtraTokenSuccessTableSize = cellularSrcTokenSuccessTableSize;
PlatformMutex_Unlock( &pContext->PktRespMutex );
pktStatus = _Cellular_AtcmdRequestTimeoutWithCallbackRaw( pContext, atReq, atTimeoutMS );
/* Clear the extra Token table for this AT command. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->tokenTable.cellularSrcExtraTokenSuccessTableSize = 0;
pContext->tokenTable.pCellularSrcExtraTokenSuccessTable = NULL;
PlatformMutex_Unlock( &pContext->PktRespMutex );
_Cellular_PktHandlerReleasePktRequestMutex( pContext );
}
return pktStatus;
}
/*-----------------------------------------------------------*/
CellularPktStatus_t _Cellular_TimeoutAtcmdDataRecvRequestWithCallback( CellularContext_t * pContext,
CellularAtReq_t atReq,
uint32_t timeoutMS,
CellularATCommandDataPrefixCallback_t pktDataPrefixCallback,
void * pCallbackContext )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
if( pContext == NULL )
{
LogError( ( "_Cellular_TimeoutAtcmdDataRecvRequestWithCallback : Invalid cellular context" ) );
pktStatus = CELLULAR_PKT_STATUS_INVALID_HANDLE;
}
else
{
_Cellular_PktHandlerAcquirePktRequestMutex( pContext );
/* Set the data receive prefix. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->pktDataPrefixCB = pktDataPrefixCallback;
pContext->pDataPrefixCBContext = pCallbackContext;
PlatformMutex_Unlock( &pContext->PktRespMutex );
pktStatus = _Cellular_AtcmdRequestTimeoutWithCallbackRaw( pContext, atReq, timeoutMS );
/* Clear the data receive prefix. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->pktDataPrefixCB = NULL;
pContext->pDataPrefixCBContext = NULL;
PlatformMutex_Unlock( &pContext->PktRespMutex );
_Cellular_PktHandlerReleasePktRequestMutex( pContext );
}
return pktStatus;
}
/*-----------------------------------------------------------*/
CellularPktStatus_t _Cellular_AtcmdDataSend( CellularContext_t * pContext,
CellularAtReq_t atReq,
CellularAtDataReq_t dataReq,
CellularATCommandDataSendPrefixCallback_t pktDataSendPrefixCallback,
void * pCallbackContext,
uint32_t atTimeoutMS,
uint32_t dataTimeoutMS,
uint32_t interDelayMS )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
if( pContext == NULL )
{
LogError( ( "_Cellular_TimeoutAtcmdDataSendRequestWithCallback : Invalid cellular context" ) );
pktStatus = CELLULAR_PKT_STATUS_INVALID_HANDLE;
}
else
{
_Cellular_PktHandlerAcquirePktRequestMutex( pContext );
/* Set the data send prefix callback. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->pktDataSendPrefixCB = pktDataSendPrefixCallback;
pContext->pDataSendPrefixCBContext = pCallbackContext;
PlatformMutex_Unlock( &pContext->PktRespMutex );
pktStatus = _Cellular_AtcmdRequestTimeoutWithCallbackRaw( pContext, atReq, atTimeoutMS );
/* Clear the data send prefix callback. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->pDataSendPrefixCBContext = NULL;
pContext->pktDataSendPrefixCB = NULL;
PlatformMutex_Unlock( &pContext->PktRespMutex );
if( pktStatus == CELLULAR_PKT_STATUS_OK )
{
pktStatus = _Cellular_DataSendWithTimeoutDelayRaw( pContext, dataReq, dataTimeoutMS, interDelayMS );
}
_Cellular_PktHandlerReleasePktRequestMutex( pContext );
}
return pktStatus;
}
/*-----------------------------------------------------------*/
CellularPktStatus_t _Cellular_TimeoutAtcmdDataSendRequestWithCallback( CellularContext_t * pContext,
CellularAtReq_t atReq,
CellularAtDataReq_t dataReq,
uint32_t atTimeoutMS,
uint32_t dataTimeoutMS )
{
return _Cellular_AtcmdDataSend( pContext, atReq, dataReq, NULL, NULL, atTimeoutMS, dataTimeoutMS, 0U );
}
/*-----------------------------------------------------------*/
CellularPktStatus_t _Cellular_TimeoutAtcmdDataSendSuccessToken( CellularContext_t * pContext,
CellularAtReq_t atReq,
CellularAtDataReq_t dataReq,
uint32_t atTimeoutMS,
uint32_t dataTimeoutMS,
const char ** pCellularSrcTokenSuccessTable,
uint32_t cellularSrcTokenSuccessTableSize )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
if( pContext == NULL )
{
LogError( ( "_Cellular_TimeoutAtcmdDataSendSuccessToken : Invalid cellular context" ) );
pktStatus = CELLULAR_PKT_STATUS_INVALID_HANDLE;
}
else
{
_Cellular_PktHandlerAcquirePktRequestMutex( pContext );
/* Set the extra token table. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->tokenTable.pCellularSrcExtraTokenSuccessTable = pCellularSrcTokenSuccessTable;
pContext->tokenTable.cellularSrcExtraTokenSuccessTableSize = cellularSrcTokenSuccessTableSize;
PlatformMutex_Unlock( &pContext->PktRespMutex );
pktStatus = _Cellular_AtcmdRequestTimeoutWithCallbackRaw( pContext, atReq, atTimeoutMS );
/* Clear the extra token table. */
PlatformMutex_Lock( &pContext->PktRespMutex );
pContext->tokenTable.cellularSrcExtraTokenSuccessTableSize = 0;
pContext->tokenTable.pCellularSrcExtraTokenSuccessTable = NULL;
PlatformMutex_Unlock( &pContext->PktRespMutex );
if( pktStatus == CELLULAR_PKT_STATUS_OK )
{
pktStatus = _Cellular_DataSendWithTimeoutDelayRaw( pContext, dataReq, dataTimeoutMS, 0U );
}
_Cellular_PktHandlerReleasePktRequestMutex( pContext );
}
return pktStatus;
}
/*-----------------------------------------------------------*/
CellularPktStatus_t _Cellular_PktHandlerInit( CellularContext_t * pContext )
{
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
if( pContext != NULL )
{
/* Create the response queue which is used to post reponses to the sender. */
pContext->pktRespQueue = xQueueCreate( 1, ( uint32_t ) sizeof( CellularPktStatus_t ) );
if( pContext->pktRespQueue == NULL )
{
pktStatus = CELLULAR_PKT_STATUS_FAILURE;
}
}
else
{
pktStatus = CELLULAR_PKT_STATUS_FAILURE;
}
return pktStatus;
}
/*-----------------------------------------------------------*/
CellularPktStatus_t _Cellular_AtParseInit( const CellularContext_t * pContext )
{
uint32_t i = 0;
bool finit = true;
const CellularAtParseTokenMap_t * pTokenMap = NULL;
uint32_t tokenMapSize = 0;
int32_t result = 0;
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
if( ( pContext != NULL ) && ( pContext->tokenTable.pCellularUrcHandlerTable != NULL ) &&
( pContext->tokenTable.cellularPrefixToParserMapSize > 0U ) )
{
pTokenMap = pContext->tokenTable.pCellularUrcHandlerTable;
tokenMapSize = pContext->tokenTable.cellularPrefixToParserMapSize;
/* Check order of the sorted Map. */
for( i = 0; i < ( tokenMapSize - 1U ); i++ )
{
result = _sortCompareFunc( &pTokenMap[ i ], &pTokenMap[ i + 1U ] );
if( result >= 0 )
{
LogError( ( "AtParseFail for %u: %d %s %s", i, result,
pTokenMap[ i ].pStrValue, pTokenMap[ i + 1U ].pStrValue ) );
finit = false;
}
}
if( finit != true )
{
pktStatus = CELLULAR_PKT_STATUS_BAD_PARAM;
LogError( ( "AtParseFail URC token table is not sorted" ) );
}
configASSERT( finit == true );
for( i = 0; i < tokenMapSize; i++ )
{
LogDebug( ( "Callbacks setup for %u : %s", i, pTokenMap[ i ].pStrValue ) );
}
}
else
{
pktStatus = CELLULAR_PKT_STATUS_INVALID_HANDLE;
}
return pktStatus;
}
/*-----------------------------------------------------------*/
bool _Cellular_CreatePktRequestMutex( CellularContext_t * pContext )
{
bool status = false;
if( pContext != NULL )
{
status = PlatformMutex_Create( &pContext->pktRequestMutex, false );
}
return status;
}
/*-----------------------------------------------------------*/
bool _Cellular_CreatePktResponseMutex( CellularContext_t * pContext )
{
bool status = false;
if( pContext != NULL )
{
status = PlatformMutex_Create( &pContext->PktRespMutex, false );
}
return status;
}
/*-----------------------------------------------------------*/
void _Cellular_DestroyPktRequestMutex( CellularContext_t * pContext )
{
if( pContext != NULL )
{
PlatformMutex_Destroy( &pContext->pktRequestMutex );
}
}
/*-----------------------------------------------------------*/
void _Cellular_DestroyPktResponseMutex( CellularContext_t * pContext )
{
if( pContext != NULL )
{
PlatformMutex_Destroy( &pContext->PktRespMutex );
}
}
/*-----------------------------------------------------------*/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,646 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @file cellular_api.h
*/
#ifndef __CELLULAR_API_H__
#define __CELLULAR_API_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* IoT Cellular data types. */
#include "cellular_types.h"
/* Hardware interface. */
#include "cellular_comm_interface.h"
/**
* @brief One time initialization function.
*
* This function initializes and returns the supplied context. It must be called
* once (and only once) before calling any other function of this library.
*
* @param[in,out] pCellularHandle the handle pointer to store the cellular handle.
* @param[in] pCommInterface Comm interface for communicating with the module.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_Init( CellularHandle_t * pCellularHandle,
const CellularCommInterface_t * pCommInterface );
/**
* @brief One time deinitialization function.
*
* This function frees resources taken in Cellular_Init. After this function
* returns, Cellular_Init must be called again before calling any other function
* of this library.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_Cleanup( CellularHandle_t cellularHandle );
/**
* @brief Configure the priority order in which the networks are searched.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] pRatPriorities An array of RATs in priority order. For example, to
* search NB-IoT first, then Cat-M1 and then LTE, the array should contain:
* { CELLULAR_RAT_NBIOT, CELLULAR_RAT_CATM1, CELLULAR_RAT_LTE }.
* @param[in] ratPrioritiesLength Length of the pRatPriorities array.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SetRatPriority( CellularHandle_t cellularHandle,
const CellularRat_t * pRatPriorities,
uint8_t ratPrioritiesLength );
/**
* @brief Get the priority order in which the networks are searched.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pRatPriorities An array of current RATs in priority order.
* @param[in] ratPrioritiesLength Length of the pRatPriorities array.
* @param[out] pOutputRatPrioritiesLength Actual number of items filled into pRatPriorities
* by this function when it returns.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetRatPriority( CellularHandle_t cellularHandle,
CellularRat_t * pRatPriorities,
uint8_t ratPrioritiesLength,
uint8_t * pOutputRatPrioritiesLength );
/**
* @brief Turn on RF i.e. turn-off airplane mode.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_RfOn( CellularHandle_t cellularHandle );
/**
* @brief Turn off RF i.e. turn-on airplane mode.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_RfOff( CellularHandle_t cellularHandle );
/**
* @brief Get SIM card status (activated/Pin set etc.).
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pSimCardStatus Out parameter to provide the SIM card status.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetSimCardStatus( CellularHandle_t cellularHandle,
CellularSimCardStatus_t * pSimCardStatus );
/**
* @brief Get SIM card information (IMSI, SIM Card number etc.).
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pSimCardInfo Out parameter to provide the SIM card information.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetSimCardInfo( CellularHandle_t cellularHandle,
CellularSimCardInfo_t * pSimCardInfo );
/**
* @brief Get the information about the modem (HW version, FW version etc.).
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pModemInfo Out parameter to provide the modem information.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetModemInfo( CellularHandle_t cellularHandle,
CellularModemInfo_t * pModemInfo );
/**
* @brief Get the network on which SIM is currently registered/camped.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pNetworkInfo Out parameter to provide the network information.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetRegisteredNetwork( CellularHandle_t cellularHandle,
CellularPlmnInfo_t * pNetworkInfo );
/**
* @brief Get the network time.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pNetworkTime Out parameter to provide the network time.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetNetworkTime( CellularHandle_t cellularHandle,
CellularTime_t * pNetworkTime );
/**
* @brief Get signal information.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pSignalInfo Out parameter to provide the signal information.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetSignalInfo( CellularHandle_t cellularHandle,
CellularSignalInfo_t * pSignalInfo );
/**
* @brief Get network service status.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pServiceStatus Out parameter to provide the service status.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetServiceStatus( CellularHandle_t cellularHandle,
CellularServiceStatus_t * pServiceStatus );
/**
* @brief Set PDN config for a PDN context.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] contextId Context ID of the PDN to set the config for. Context ID value
* should be in range between CELLULAR_PDN_CONTEXT_ID_MIN and CELLULAR_PDN_CONTEXT_ID_MAX.
* The context ID with specified PDN config will be used with other CELLULAR APIs.
* @param[in] pPdnConfig PDN config to set.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SetPdnConfig( CellularHandle_t cellularHandle,
uint8_t contextId,
const CellularPdnConfig_t * pPdnConfig );
/**
* @brief Get status reports for all PDN contexts.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pPdnStatusBuffers Out parameter to provide array of PDN contexts.
* @param[in] numStatusBuffers Number of CellularPdnStatus_t buffers in the
* provided array pPdnStatusBuffers.
* @param[out] pNumStatus Out parameter to provide the number of PDN statuses
* returned.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetPdnStatus( CellularHandle_t cellularHandle,
CellularPdnStatus_t * pPdnStatusBuffers,
uint8_t numStatusBuffers,
uint8_t * pNumStatus );
/**
* @brief Activate a PDN context.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] contextId Context ID of the PDN context to activate. The same context ID
* should be used with Cellular_SetPdnConfig before calling this API.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_ActivatePdn( CellularHandle_t cellularHandle,
uint8_t contextId );
/**
* @brief Deactivate a PDN context.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] contextId Context ID of the PDN context to deactivate.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_DeactivatePdn( CellularHandle_t cellularHandle,
uint8_t contextId );
/**
* @brief Get the IP Address assigned to the module.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] contextId Context ID of the PDN context for which IP address is requested.
* @param[out] pBuffer the buffer to receive the IP address into. The returned pBuffer
* is a NULL terminated string.
* @param[in] bufferLength of the buffer pBuffer.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetIPAddress( CellularHandle_t cellularHandle,
uint8_t contextId,
char * pBuffer,
uint32_t bufferLength );
/**
* @brief Set the DNS server to use.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] contextId Context ID of the PDN context for which DNS needs to be set.
* @param[in] pDnsServerAddress The address of the DNS server to set.
* It should be a NULL terminated string.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SetDns( CellularHandle_t cellularHandle,
uint8_t contextId,
const char * pDnsServerAddress );
/**
* @brief Register/Remove callback for Network Registration URC events.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] networkRegistrationCallback The callback to register. Set to NULL
* to remove the existing callback.
* @param[in] pCallbackContext The context to be passed to callback function.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_RegisterUrcNetworkRegistrationEventCallback( CellularHandle_t cellularHandle,
CellularUrcNetworkRegistrationCallback_t networkRegistrationCallback,
void * pCallbackContext );
/**
* @brief Register/Remove callback for PDN related URC events.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] pdnEventCallback The callback to register. Set to NULL remove the
* existing callback.
* @param[in] pCallbackContext The context to be passed to callback function.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_RegisterUrcPdnEventCallback( CellularHandle_t cellularHandle,
CellularUrcPdnEventCallback_t pdnEventCallback,
void * pCallbackContext );
/**
* @brief Register callback for Signal Strength changed URC events.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] signalStrengthChangedCallback The callback to register. Set to
* NULL to remove the existing callback.
* @param[in] pCallbackContext The context to be passed to callback function.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_RegisterUrcSignalStrengthChangedCallback( CellularHandle_t cellularHandle,
CellularUrcSignalStrengthChangedCallback_t signalStrengthChangedCallback,
void * pCallbackContext );
/**
* @brief Register callback for all modem related events.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] modemEventCallback The callback to register. Set to NULL to remove
* the existing callback.
* @param[in] pCallbackContext The context to be passed to callback function.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_RegisterModemEventCallback( CellularHandle_t cellularHandle,
CellularModemEventCallback_t modemEventCallback,
void * pCallbackContext );
/**
* @brief Register generic callback for all other URC events than covered in
* above callbacks.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] genericCallback The callback to register. Set to NULL to remove
* the existing callback.
* @param[in] pCallbackContext The context to be passed to callback function.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_RegisterUrcGenericCallback( CellularHandle_t cellularHandle,
CellularUrcGenericCallback_t genericCallback,
void * pCallbackContext );
/**
* @brief Get current PSM settings.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pPsmSettings Out parameter to provide the PSM settings.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetPsmSettings( CellularHandle_t cellularHandle,
CellularPsmSettings_t * pPsmSettings );
/**
* @brief Set PSM settings.
*
* Enable/disable PSM by using CellularPsmSettings_t structure.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] pPsmSettings PSM settings to set.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SetPsmSettings( CellularHandle_t cellularHandle,
const CellularPsmSettings_t * pPsmSettings );
/**
* @brief Get current e-I-DRX settings.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pEidrxSettingsList Out parameter to provide the e-I-DRX settings.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetEidrxSettings( CellularHandle_t cellularHandle,
CellularEidrxSettingsList_t * pEidrxSettingsList );
/**
* @brief Set e-I-DRX settings.
*
* This API can be used to enable/disable e-I-DRX by using the mode member of
* CellularEidrxSettings_t.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] pEidrxSettings e-I-DRX settings to set.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SetEidrxSettings( CellularHandle_t cellularHandle,
const CellularEidrxSettings_t * pEidrxSettings );
/**
* @brief Send the raw AT command to the module.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] pATCommandPrefix The AT command response prefix. NULL if the response
* has no prefix.
* @param[in] pATCommandPayload The AT command to send. It should be a NULL terminated
* string.
* @param[in] atCommandType Type of AT command.
* @param[in] responseReceivedCallback Callback to be invoked when a response for the
* command is received.
* @param[in] pData The pData pointer will be passed in responseReceivedCallback.
* @param[in] dataLen The dataLen value will be passed in responseReceivedCallback.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_ATCommandRaw( CellularHandle_t cellularHandle,
const char * pATCommandPrefix,
const char * pATCommandPayload,
CellularATCommandType_t atCommandType,
CellularATCommandResponseReceivedCallback_t responseReceivedCallback,
void * pData,
uint16_t dataLen );
/**
* @brief Create a socket.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] pdnContextId pdn context id on which this socket needs to be created. The pdn
* context must be previously activated by Cellular_ActivatePdn function.
* @param[in] socketDomain Socket domain.
* @param[in] socketType Socket Type.
* @param[in] socketProtocol Socket Protocol.
* @param[out] pSocketHandle Out parameter to provide the created handle.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_CreateSocket( CellularHandle_t cellularHandle,
uint8_t pdnContextId,
CellularSocketDomain_t socketDomain,
CellularSocketType_t socketType,
CellularSocketProtocol_t socketProtocol,
CellularSocketHandle_t * pSocketHandle );
/**
* @brief Connect to a remote socket.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] socketHandle Socket handle returned from the Cellular_CreateSocket call.
* @param[in] dataAccessMode Data access mode of the socket. Buffer, Direct Push or Transparent.
* @param[in] pRemoteSocketAddress Address (IP and Port) of the remote socket to connect to.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SocketConnect( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketAccessMode_t dataAccessMode,
const CellularSocketAddress_t * pRemoteSocketAddress );
/**
* @brief Send data to the connected remote socket.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] socketHandle Socket handle returned from the Cellular_CreateSocket call.
* @param[in] pData The buffer containing that data to be sent.
* @param[in] dataLength Length of the data in the pData buffer.
* @param[out] pSentDataLength Out parameter to provide the length of the actual
* data sent. Note that it may be less than the dataLength in case complete data
* could not be sent.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SocketSend( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
const uint8_t * pData,
uint32_t dataLength,
uint32_t * pSentDataLength );
/**
* @brief Receive data on a connected socket.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] socketHandle Socket handle returned from the Cellular_CreateSocket call.
* @param[out] pBuffer The buffer to receive the data into.
* @param[in] bufferLength Length of the buffer pBuffer.
* @param[out] pReceivedDataLength Out parameter to provide the of the actual
* data received in the buffer pBuffer. Note that it may be less than
* bufferLength.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SocketRecv( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
uint8_t * pBuffer,
uint32_t bufferLength,
uint32_t * pReceivedDataLength );
/**
* @brief Close the socket.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] socketHandle Socket handle returned from the Cellular_CreateSocket call.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SocketClose( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle );
/**
* @brief Resolve a host name using Domain Name Service.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] contextId Context ID of the PDN context for which DNS is set.
* @param[in] pcHostName The host name to resolve.
* It should be a NULL terminated string.
* The length of the string should not exceed RFC1035 defined.
* @param[out] pResolvedAddress The output parameter to return the resolved
* address. The length of this buffer should be at least CELLULAR_IP_ADDRESS_MAX_SIZE.
* The returned buffer is a NULL terminated string.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_GetHostByName( CellularHandle_t cellularHandle,
uint8_t contextId,
const char * pcHostName,
char * pResolvedAddress );
/**
* @brief Set options for a socket.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] socketHandle Socket handle returned from the Cellular_CreateSocket call.
* @param[in] optionLevel Socket option level (IP or TCP/UDP).
* @param[in] option Socket option to set.
* @param[in] pOptionValue Buffer containing the socket option value.
* @param[in] optionValueLength Length of the value pointed to by pOptionValue.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SocketSetSockOpt( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketOptionLevel_t optionLevel,
CellularSocketOption_t option,
const uint8_t * pOptionValue,
uint32_t optionValueLength );
/**
* @brief Register Socket open callback on the socket.
*
* This callback is invoked when modem confirms that a socket is opened.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] socketHandle Socket handle returned from the Cellular_CreateSocket call.
* @param[in] socketOpenCallback The callback to register.
* @param[in] pCallbackContext The context to be passed to callback function.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SocketRegisterSocketOpenCallback( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketOpenCallback_t socketOpenCallback,
void * pCallbackContext );
/**
* @brief Register data ready callback on the socket.
*
* This callback is invoked whenever data is ready to be read from the socket.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] socketHandle Socket handle returned from the Cellular_CreateSocket call.
* @param[in] dataReadyCallback The callback to register.
* @param[in] pCallbackContext The context to be passed to callback function.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SocketRegisterDataReadyCallback( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketDataReadyCallback_t dataReadyCallback,
void * pCallbackContext );
/**
* @brief Register closed callback on the socket.
*
* This callback is invoked whenever remote end closes the connection on a
* connected socket.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] socketHandle Socket handle returned from the Cellular_CreateSocket call.
* @param[in] closedCallback The callback to register.
* @param[in] pCallbackContext The context to be passed to callback function.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_SocketRegisterClosedCallback( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketClosedCallback_t closedCallback,
void * pCallbackContext );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* __CELLULAR_API_H__ */

View File

@ -0,0 +1,480 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @file cellular_config_defaults.h
* @brief This represents the default values for the configuration macros
* for the Cellular library.
*
* @note This file SHOULD NOT be modified. If custom values are needed for
* any configuration macro, a cellular_config.h file should be provided to
* the Cellular library to override the default values defined in this file.
* To use the custom config file, the CELLULAR_DO_NOT_USE_CUSTOM_CONFIG preprocessor
* macro SHOULD NOT be set.
*/
#ifndef __CELLULAR_CONFIG_DEFAULTS_H__
#define __CELLULAR_CONFIG_DEFAULTS_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* The macro definition for CELLULAR_DO_NOT_USE_CUSTOM_CONFIG is for Doxygen
* documentation only. */
/**
* @brief Define this macro to build the Cellular library without the custom config
* file cellular_config.h.
*
* Without the custom config, the Cellular library builds with
* default values of config macros defined in cellular_config_defaults.h file.
*
* If a custom config is provided, then CELLULAR_DO_NOT_USE_CUSTOM_CONFIG should not
* be defined.
*/
#ifdef DOXYGEN
#define CELLULAR_DO_NOT_USE_CUSTOM_CONFIG
#endif
/**
* @brief Mobile country code max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 3
*/
#ifndef CELLULAR_MCC_MAX_SIZE
#define CELLULAR_MCC_MAX_SIZE ( 3U )
#endif
/**
* @brief Mobile network code max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 3
*/
#ifndef CELLULAR_MNC_MAX_SIZE
#define CELLULAR_MNC_MAX_SIZE ( 3U )
#endif
/**
* @brief Integrate circuit card identity max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 20
*/
#ifndef CELLULAR_ICCID_MAX_SIZE
#define CELLULAR_ICCID_MAX_SIZE ( 20U )
#endif
/**
* @brief International Mobile Subscriber Identity max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 15
*/
#ifndef CELLULAR_IMSI_MAX_SIZE
#define CELLULAR_IMSI_MAX_SIZE ( 15U )
#endif
/**
* @brief Cellular module firmware version max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 32
*/
#ifndef CELLULAR_FW_VERSION_MAX_SIZE
#define CELLULAR_FW_VERSION_MAX_SIZE ( 32U )
#endif
/**
* @brief Cellular module hardware version max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 12
*/
#ifndef CELLULAR_HW_VERSION_MAX_SIZE
#define CELLULAR_HW_VERSION_MAX_SIZE ( 12U )
#endif
/**
* @brief Cellular module serial number max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 12
*/
#ifndef CELLULAR_SERIAL_NUM_MAX_SIZE
#define CELLULAR_SERIAL_NUM_MAX_SIZE ( 12U )
#endif
/**
* @brief International Mobile Equipment Identity number max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 15
*/
#ifndef CELLULAR_IMEI_MAX_SIZE
#define CELLULAR_IMEI_MAX_SIZE ( 15U )
#endif
/**
* @brief Registered network operator name max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 32
*/
#ifndef CELLULAR_NETWORK_NAME_MAX_SIZE
#define CELLULAR_NETWORK_NAME_MAX_SIZE ( 32U )
#endif
/**
* @brief Access point name max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 32
*/
#ifndef CELLULAR_APN_MAX_SIZE
#define CELLULAR_APN_MAX_SIZE ( 64U )
#endif
/**
* @brief Packet data network username max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 32
*/
#ifndef CELLULAR_PDN_USERNAME_MAX_SIZE
#define CELLULAR_PDN_USERNAME_MAX_SIZE ( 32U )
#endif
/**
* @brief Packet data network password max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 32
*/
#ifndef CELLULAR_PDN_PASSWORD_MAX_SIZE
#define CELLULAR_PDN_PASSWORD_MAX_SIZE ( 32u )
#endif
/**
* @brief Cellular data network IP address max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 40
*/
#ifndef CELLULAR_IP_ADDRESS_MAX_SIZE
#define CELLULAR_IP_ADDRESS_MAX_SIZE ( 40U )
#endif
/**
* @brief Cellular AT command max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 200
*/
#ifndef CELLULAR_AT_CMD_MAX_SIZE
#define CELLULAR_AT_CMD_MAX_SIZE ( 200U )
#endif
/**
* @brief Cellular module number of socket max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 12
*/
#ifndef CELLULAR_NUM_SOCKET_MAX
#define CELLULAR_NUM_SOCKET_MAX ( 12U )
#endif
/**
* @brief Cellular module manufacture ID max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 20
*/
#ifndef CELLULAR_MANUFACTURE_ID_MAX_SIZE
#define CELLULAR_MANUFACTURE_ID_MAX_SIZE ( 20U )
#endif
/**
* @brief Cellular module ID max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 10
*/
#ifndef CELLULAR_MODEL_ID_MAX_SIZE
#define CELLULAR_MODEL_ID_MAX_SIZE ( 10U )
#endif
/**
* @brief Cellular EDRX list max size.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 4
*/
#ifndef CELLULAR_EDRX_LIST_MAX_SIZE
#define CELLULAR_EDRX_LIST_MAX_SIZE ( 4U )
#endif
/**
* @brief Cellular PDN context ID min value.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 1
*/
#ifndef CELLULAR_PDN_CONTEXT_ID_MIN
#define CELLULAR_PDN_CONTEXT_ID_MIN ( 1U )
#endif
/**
* @brief Cellular PDN context ID max value.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 1
*/
#ifndef CELLULAR_PDN_CONTEXT_ID_MAX
#define CELLULAR_PDN_CONTEXT_ID_MAX ( 16U )
#endif
/**
* @brief Cellular RAT ( radio access technology ) priority count.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 1
*/
#ifndef CELLULAR_MAX_RAT_PRIORITY_COUNT
#define CELLULAR_MAX_RAT_PRIORITY_COUNT ( 3U )
#endif
/**
* @brief Cellular socket max send data length.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 1460
*/
#ifndef CELLULAR_MAX_SEND_DATA_LEN
#define CELLULAR_MAX_SEND_DATA_LEN ( 1460U )
#endif
/**
* @brief Cellular socket max receive data length.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 1500
*/
#ifndef CELLULAR_MAX_RECV_DATA_LEN
#define CELLULAR_MAX_RECV_DATA_LEN ( 1500U )
#endif
/**
* @brief Cellular module support getHostByName.<br>
*
* <b>Possible values:</b>`0 or 1`<br>
* <b>Default value (if undefined):</b> 1
*/
#ifndef CELLULAR_SUPPORT_GETHOSTBYNAME
#define CELLULAR_SUPPORT_GETHOSTBYNAME ( 1U )
#endif
/**
* @brief Cellular comm interface send timeout in MS.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 1000
*/
#ifndef CELLULAR_COMM_IF_SEND_TIMEOUT_MS
#define CELLULAR_COMM_IF_SEND_TIMEOUT_MS ( 1000U )
#endif
/**
* @brief Cellular comm interface receive timeout in MS.<br>
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 1000
*/
#ifndef CELLULAR_COMM_IF_RECV_TIMEOUT_MS
#define CELLULAR_COMM_IF_RECV_TIMEOUT_MS ( 1000U )
#endif
/**
* @brief FreeRTOS Cellular Library use static context.<br>
*
* <b>Possible values:</b>`0 or 1`<br>
* <b>Default value (if undefined):</b> 0
*/
#ifndef CELLULAR_CONFIG_STATIC_ALLOCATION_CONTEXT
#define CELLULAR_CONFIG_STATIC_ALLOCATION_CONTEXT ( 0U )
#endif
/**
* @brief Cellular comm interface use static context.<br>
*
* <b>Possible values:</b>`0 or 1`<br>
* <b>Default value (if undefined):</b> 0
*/
#ifndef CELLULAR_CONFIG_STATIC_COMM_CONTEXT_ALLOCATION
#define CELLULAR_CONFIG_STATIC_COMM_CONTEXT_ALLOCATION ( 0U )
#endif
/**
* @brief Default radio access technoloyg.<br>
*
* <b>Possible values:</b>`Any value before CELLULAR_RAT_MAX` ( Reference : @ref CellularRat_t )<br>
* <b>Default value (if undefined):</b> CELLULAR_RAT_CATM1
*/
#ifndef CELLULAR_CONFIG_DEFAULT_RAT
#define CELLULAR_CONFIG_DEFAULT_RAT ( 8 ) /* Set default RAT to CELLULAR_RAT_CATM1 @ref CellularRat_t. */
#endif
/**
* @brief Cellular comm interface use static socket context.<br>
*
* <b>Possible values:</b>`0 or 1`<br>
* <b>Default value (if undefined):</b> 0
*/
#ifndef CELLULAR_CONFIG_STATIC_SOCKET_CONTEXT_ALLOCATION
#define CELLULAR_CONFIG_STATIC_SOCKET_CONTEXT_ALLOCATION ( 0 )
#endif
/**
* @brief Cellular common AT command timeout.<br>
*
* The timeout value for Cellular_Common prefix APIs. The timeout value should be
* set according to spec. It should be long enough for AT command used in cellular
* common APIs.
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 5000
*/
#ifndef CELLULAR_COMMON_AT_COMMAND_TIMEOUT_MS
#define CELLULAR_COMMON_AT_COMMAND_TIMEOUT_MS ( 5000U )
#endif
/**
* @brief Cellular AT command raw timeout.<br>
*
* The timeout value for Cellular_ATCommandRaw API.
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 5000
*/
#ifndef CELLULAR_AT_COMMAND_RAW_TIMEOUT_MS
#define CELLULAR_AT_COMMAND_RAW_TIMEOUT_MS ( 5000U )
#endif
/**
* @brief Cellular AT command response prefix string length.<br>
*
* The maximum length of AT command response prefix string.
*
* <b>Possible values:</b>`Any positive integer`<br>
* <b>Default value (if undefined):</b> 32
*/
#ifndef CELLULAR_CONFIG_MAX_PREFIX_STRING_LENGTH
#define CELLULAR_CONFIG_MAX_PREFIX_STRING_LENGTH ( 32U )
#endif
/**
* @brief Macro that is called in the cellular library for logging "Error" level
* messages.
*
* To enable error level logging in the cellular library, this macro should be mapped to the
* application-specific logging implementation that supports error logging.
*
* @note This logging macro is called in the cellular library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to cellular_config.h files.
*
* <b>Default value</b>: Error logging is turned off, and no code is generated for calls
* to the macro in the cellular library on compilation.
*/
#ifndef LogError
#define LogError( message )
#endif
/**
* @brief Macro that is called in the cellular library for logging "Warning" level
* messages.
*
* To enable warning level logging in the cellular library, this macro should be mapped to the
* application-specific logging implementation that supports warning logging.
*
* @note This logging macro is called in the cellular library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to cellular_config.h files.
*
* <b>Default value</b>: Warning logs are turned off, and no code is generated for calls
* to the macro in the cellular library on compilation.
*/
#ifndef LogWarn
#define LogWarn( message )
#endif
/**
* @brief Macro that is called in the cellular library for logging "Info" level
* messages.
*
* To enable info level logging in the cellular library, this macro should be mapped to the
* application-specific logging implementation that supports info logging.
*
* @note This logging macro is called in the cellular library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to cellular_config.h files.
*
* <b>Default value</b>: Info logging is turned off, and no code is generated for calls
* to the macro in the cellular library on compilation.
*/
#ifndef LogInfo
#define LogInfo( message )
#endif
/**
* @brief Macro that is called in the cellular library for logging "Debug" level
* messages.
*
* To enable debug level logging from cellular library, this macro should be mapped to the
* application-specific logging implementation that supports debug logging.
*
* @note This logging macro is called in the cellular library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to cellular_config.h files.
*
* <b>Default value</b>: Debug logging is turned off, and no code is generated for calls
* to the macro in the cellular library on compilation.
*/
#ifndef LogDebug
#define LogDebug( message )
#endif
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* __CELLULAR_CONFIG_DEFAULTS_H__ */

View File

@ -0,0 +1,831 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @file cellular_types.h
*/
#ifndef __CELLULAR_TYPES_H__
#define __CELLULAR_TYPES_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Includes for standard bool and int. */
#include <stdbool.h>
#include <stdint.h>
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Invalid signal value.
*/
#define CELLULAR_INVALID_SIGNAL_VALUE ( -32768 )
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Invalid signal bar value.
*/
#define CELLULAR_INVALID_SIGNAL_BAR_VALUE ( 0xFFU )
/**
* @ingroup cellular_datatypes_handles
* @brief Opaque Cellular context structure.
*/
struct CellularContext;
/**
* @ingroup cellular_datatypes_handles
* @brief Opaque Cellular context structure type.
*/
typedef struct CellularContext CellularContext_t;
/**
* @ingroup cellular_datatypes_handles
* @brief Opaque Cellular handle.
*/
typedef struct CellularContext * CellularHandle_t;
struct CellularSocketContext;
/**
* @ingroup cellular_datatypes_handles
* @brief Opaque socket handle.
*/
typedef struct CellularSocketContext * CellularSocketHandle_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Status code returns from APIs.
*/
typedef enum CellularError
{
CELLULAR_SUCCESS = 0, /**< The operation was successful. */
CELLULAR_INVALID_HANDLE, /**< Invalid handle. */
CELLULAR_MODEM_NOT_READY, /**< The modem is not ready yet. */
CELLULAR_LIBRARY_NOT_OPEN, /**< The cellular library is not open yet. */
CELLULAR_LIBRARY_ALREADY_OPEN, /**< The cellular library is already open. */
CELLULAR_BAD_PARAMETER, /**< One or more of the input parameters is not valid. */
CELLULAR_NO_MEMORY, /**< Memory allocation failure. */
CELLULAR_TIMEOUT, /**< The operation timed out. */
CELLULAR_SOCKET_CLOSED, /**< The supplied socket is already closed. */
CELLULAR_SOCKET_NOT_CONNECTED, /**< The supplied socket is not connected. */
CELLULAR_INTERNAL_FAILURE, /**< The Cellular library internal failure. */
CELLULAR_RESOURCE_CREATION_FAIL, /**< Resource creation for Cellular library failed. */
CELLULAR_UNSUPPORTED, /**< The operation is not supported. */
CELLULAR_NOT_ALLOWED, /**< The operation is not allowed. */
CELLULAR_UNKNOWN /**< Any other error other than the above mentioned ones. */
} CellularError_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Enums representing Radio Access Technologies (RATs). Reference 3GPP TS 27.007 PLMN selection +COPS.
*/
typedef enum CellularRat
{
CELLULAR_RAT_GSM = 0, /**< The GSM RATs network. */
CELLULAR_RAT_WCDMA = 2, /**< The WCDMA RATs network. */
CELLULAR_RAT_EDGE = 3, /**< The EDGE RATs network. */
CELLULAR_RAT_HSDPA = 4, /**< The HSDPA RATs network. */
CELLULAR_RAT_HSUPA = 5, /**< The HSUPA RATs network. */
CELLULAR_RAT_HSDPAHSUPA = 6, /**< The HSDPAHSUPA RATs network. */
CELLULAR_RAT_LTE = 7, /**< The LTE RATs network. */
CELLULAR_RAT_CATM1 = 8, /**< The CAT M1 RATs network. */
CELLULAR_RAT_NBIOT = 9, /**< The NBIOT RATs network. */
CELLULAR_RAT_MAX, /**< The max supported number for RATs network. */
CELLULAR_RAT_INVALID = 0xFF /**< Any other error other than the above mentioned ones. */
} CellularRat_t;
/**
* @ingroup cellular_datatypes_enums
* @brief SIM card state codes.
*/
typedef enum CellularSimCardState
{
CELLULAR_SIM_CARD_REMOVED = 0, /**< The state stands for cellular sim card removed. */
CELLULAR_SIM_CARD_INSERTED, /**< The state stands for cellular sim card inserted. */
CELLULAR_SIM_CARD_STATUS_MAX, /**< The number of supported sim card status. */
CELLULAR_SIM_CARD_UNKNOWN /**< The state stands for unknown cellular sim card. */
} CellularSimCardState_t;
/**
* @ingroup cellular_datatypes_enums
* @brief SIM card lock state codes. Reference 3GPP TS 27.007 Enter PIN +CPIN.
*/
typedef enum CellularSimCardLockState
{
CELLULAR_SIM_CARD_READY = 0, /**< The cellular sim card in a lock state of ready. */
CELLULAR_SIM_CARD_PIN, /**< The cellular sim card in a lock state of pin(personal identification number). */
CELLULAR_SIM_CARD_PUK, /**< The cellular sim card in a lock state of puk(personal unlocking key). */
CELLULAR_SIM_CARD_PIN2, /**< The cellular sim card in a lock state of pin2. */
CELLULAR_SIM_CARD_PUK2, /**< The cellular sim card in a lock state of puk2. */
CELLULAR_SIM_CARD_PH_NET_PIN, /**< The cellular sim card in a lock state of ph-net pin. */
CELLULAR_SIM_CARD_PH_NET_PUK, /**< The cellular sim card in a lock state of ph-net puk. */
CELLULAR_SIM_CARD_PH_NETSUB_PIN, /**< The cellular sim card in a lock state of ph-netsub pin. */
CELLULAR_SIM_CARD_PH_NETSUB_PUK, /**< The cellular sim card in a lock state of ph-netsub puk. */
CELLULAR_SIM_CARD_SP_PIN, /**< The cellular sim card in a lock state of ph-sp pin. */
CELLULAR_SIM_CARD_SP_PUK, /**< The cellular sim card in a lock state of ph-sp puk. */
CELLULAR_SIM_CARD_CORP_PIN, /**< The cellular sim card in a lock state of ph-corp pin. */
CELLULAR_SIM_CARD_CORP_PUK, /**< The cellular sim card in a lock state of ph-sp puk. */
CELLULAR_SIM_CARD_IMSI_PIN, /**< The cellular sim card in a lock state of imsi pin. */
CELLULAR_SIM_CARD_IMSI_PUK, /**< The cellular sim card in a lock state of imsi puk. */
CELLULAR_SIM_CARD_INVALID, /**< The cellular sim card in a lock state of invalid. */
CELLULAR_SIM_CARD_LOCK_UNKNOWN /**< The cellular sim card in a lock state of unknown. */
} CellularSimCardLockState_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents network registration mode. Reference 3GPP TS 27.007 PLMN selection +COPS.
*/
typedef enum CellularNetworkRegistrationMode
{
REGISTRATION_MODE_AUTO = 0, /**< Auto network registration mode. */
REGISTRATION_MODE_MANUAL = 1, /**< Manual network registration mode. */
REGISTRATION_MODE_DEREGISTER = 2, /**< Deregister network registration mode. */
REGISTRATION_MODE_MANUAL_THEN_AUTO = 4, /**< Manual then auto network registration mode. */
REGISTRATION_MODE_MAX, /**< The number of supported registration mode. */
REGISTRATION_MODE_UNKNOWN /**< Unknown network registration mode. */
} CellularNetworkRegistrationMode_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents network registration status. Reference 3GPP TS 27.007 network registration status.
*/
typedef enum CellularNetworkRegistrationStatus
{
REGISTRATION_STATUS_NO_REGISTERED_SEARCHING = 0, /**< No registered searching network registration status. */
REGISTRATION_STATUS_REGISTERED_HOME = 1, /**< Registered home network registration status. */
REGISTRATION_STATUS_NOT_REGISTERED_SEARCHING = 2, /**< Not registered searching network registration status. */
REGISTRATION_STATUS_REGISTRATION_DENIED = 3, /**< Registration denied network registration status. */
REGISTRATION_STATUS_UNKNOWN = 4, /**< Unknown network registration status. */
REGISTRATION_STATUS_ROAMING_REGISTERED = 5, /**< Roaming registered network registration status. */
REGISTRATION_STATUS_HOME_SMS_ONLY_REGISTERED = 6, /**< Home SMS only registered network registration status. */
REGISTRATION_STATUS_SMS_ONLY_ROAMING_REGISTERED = 7, /**< SMS only roaming registered network registration status. */
REGISTRATION_STATUS_ATTACHED_EMERG_SERVICES_ONLY = 8, /**< Attached emergency service only network registration status. */
REGISTRATION_STATUS_MAX /**< The max supported number for registration status. */
} CellularNetworkRegistrationStatus_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents operator name format.
*/
typedef enum CellularOperatorNameFormat
{
OPERATOR_NAME_FORMAT_LONG = 0, /**< Long operator name format. */
OPERATOR_NAME_FORMAT_SHORT = 1, /**< Short operator name format. */
OPERATOR_NAME_FORMAT_NUMERIC = 2, /**< Numeric operator name format. */
OPERATOR_NAME_FORMAT_NOT_PRESENT = 9, /**< Not present operator name format. */
OPERATOR_NAME_FORMAT_MAX /**< The max supported number for operator name format. */
} CellularOperatorNameFormat_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents URC events.
*/
typedef enum CellularUrcEvent
{
CELLULAR_URC_EVENT_NETWORK_CS_REGISTRATION, /**< Network CS registration URC event. */
CELLULAR_URC_EVENT_NETWORK_PS_REGISTRATION, /**< Network PS registration URC event. */
CELLULAR_URC_EVENT_PDN_ACTIVATED, /**< PDN activated registration URC event. */
CELLULAR_URC_EVENT_PDN_DEACTIVATED, /**< PDN deactivated registration URC event. */
CELLULAR_URC_EVENT_SIGNAL_CHANGED, /**< Signal changed registration URC event. */
CELLULAR_URC_SOCKET_OPENED, /**< Socket opened registration URC event. */
CELLULAR_URC_SOCKET_OPEN_FAILED, /**< Socket open failed registration URC event. */
CELLULAR_URC_EVENT_OTHER /**< Any URC event other than above. */
} CellularUrcEvent_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents Modem events.
*/
typedef enum CellularModemEvent
{
CELLULAR_MODEM_EVENT_BOOTUP_OR_REBOOT, /**< Bootup or reboot modem event. */
CELLULAR_MODEM_EVENT_POWERED_DOWN, /**< Power down modem event. */
CELLULAR_MODEM_EVENT_PSM_ENTER /**< PSM enter modem event. */
} CellularModemEvent_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents PDN context type.
*/
typedef enum CellularPdnContextType
{
CELLULAR_PDN_CONTEXT_IPV4 = 1, /**< IPV4 PDN CONTEXT. */
CELLULAR_PDN_CONTEXT_IPV6 = 2, /**< IPV6 PDN CONTEXT. */
CELLULAR_PDN_CONTEXT_IPV4V6 = 3, /**< IPV4V6 PDN CONTEXT. */
CELLULAR_PDN_CONTEXT_TYPE_MAX /**< The max number of supported PDN CONTEXT. */
} CellularPdnContextType_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents PDN authentication type.
*/
typedef enum CellularPdnAuthType
{
CELLULAR_PDN_AUTH_NONE = 0, /**< No authentication. */
CELLULAR_PDN_AUTH_PAP, /**< Password Authentication Protocol (PAP). */
CELLULAR_PDN_AUTH_CHAP, /**< Challenge Handshake Authentication Protocol (CHAP). */
CELLULAR_PDN_AUTH_PAP_OR_CHAP /**< PAP or CHAP. */
} CellularPdnAuthType_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents socket domain.
*/
typedef enum CellularSocketDomain
{
CELLULAR_SOCKET_DOMAIN_AF_INET, /**< IPv4 Internet Protocols. */
CELLULAR_SOCKET_DOMAIN_AF_INET6 /**< IPv6 Internet Protocols. */
} CellularSocketDomain_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents socket type.
*/
typedef enum CellularSocketType
{
CELLULAR_SOCKET_TYPE_DGRAM, /**< Datagram. */
CELLULAR_SOCKET_TYPE_STREAM /**< Byte-stream. */
} CellularSocketType_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents socket protocol.
*/
typedef enum CellularSocketProtocol
{
CELLULAR_SOCKET_PROTOCOL_UDP,
CELLULAR_SOCKET_PROTOCOL_TCP
} CellularSocketProtocol_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents data access modes.
*/
typedef enum CellularSocketAccessMode
{
CELLULAR_ACCESSMODE_BUFFER = 0, /* Data access buffer mode. */
CELLULAR_ACCESSMODE_DIRECT_PUSH, /* Data access direct push mode. */
CELLULAR_ACCESSMODE_TRANSPARENT, /* Data access transparent mode. */
CELLULAR_ACCESSMODE_NOT_SET /* Data access not set. */
} CellularSocketAccessMode_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents IP address.
*/
typedef enum CellularIPAddressType
{
CELLULAR_IP_ADDRESS_V4, /**< IP V4 IP address. */
CELLULAR_IP_ADDRESS_V6 /**< IP V6 IP address. */
} CellularIPAddressType_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents socket option level.
*/
typedef enum CellularSocketOptionLevel
{
CELLULAR_SOCKET_OPTION_LEVEL_IP, /**< IP layer options. */
CELLULAR_SOCKET_OPTION_LEVEL_TRANSPORT /**< Transport (TCP/UDP) layer options. */
} CellularSocketOptionLevel_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Socket option names.
*/
typedef enum CellularSocketOption
{
CELLULAR_SOCKET_OPTION_MAX_IP_PACKET_SIZE, /**< Set Max IP packet size. */
CELLULAR_SOCKET_OPTION_SEND_TIMEOUT, /**< Set send timeout (in milliseconds). */
CELLULAR_SOCKET_OPTION_RECV_TIMEOUT, /**< Set receive timeout (in milliseconds). */
CELLULAR_SOCKET_OPTION_PDN_CONTEXT_ID, /**< Set PDN Context ID to use for the socket. */
CELLULAR_SOCKET_OPTION_SET_LOCAL_PORT /**< Set local port. */
} CellularSocketOption_t;
/**
* @ingroup cellular_datatypes_enums
* @brief packet Status Names.
*/
typedef enum CellularPktStatus
{
CELLULAR_PKT_STATUS_OK = 0, /* The operation was successful. */
CELLULAR_PKT_STATUS_TIMED_OUT, /* The operation timed out. */
CELLULAR_PKT_STATUS_FAILURE, /* There was some internal failure. */
CELLULAR_PKT_STATUS_BAD_REQUEST, /* Request was not valid. */
CELLULAR_PKT_STATUS_BAD_RESPONSE, /* The response received was not valid. */
CELLULAR_PKT_STATUS_SIZE_MISMATCH, /* There is a size mismatch between the params. */
CELLULAR_PKT_STATUS_BAD_PARAM, /* One or more params is not valid. */
CELLULAR_PKT_STATUS_SEND_ERROR, /* Modem returned a send error. */
CELLULAR_PKT_STATUS_INVALID_HANDLE, /* Invalid context. */
CELLULAR_PKT_STATUS_CREATION_FAIL, /* Resource creation fail. */
CELLULAR_PKT_STATUS_PREFIX_MISMATCH, /* Invalid prefix from Modem resp. */
CELLULAR_PKT_STATUS_INVALID_DATA, /* Invalid data from Modem resp. */
CELLULAR_PKT_STATUS_PENDING_DATA, /* Pending data from Modem resp. */
CELLULAR_PKT_STATUS_PENDING_BUFFER /* Pending data from Modem resp. */
} CellularPktStatus_t;
/**
* @ingroup cellular_datatypes_enums
* @brief Represents AT Command type.
*/
typedef enum CellularATCommandType
{
CELLULAR_AT_NO_RESULT, /**< no response expected, only OK, ERROR etc. */
CELLULAR_AT_WO_PREFIX, /**< string response without a prefix. */
CELLULAR_AT_WITH_PREFIX, /**< string response with a prefix. */
CELLULAR_AT_MULTI_WITH_PREFIX, /**< multiple line response all start with a prefix. */
CELLULAR_AT_MULTI_WO_PREFIX, /**< multiple line response with or without a prefix. */
CELLULAR_AT_MULTI_DATA_WO_PREFIX, /**< multiple line data response with or without a prefix. */
CELLULAR_AT_NO_COMMAND /**< no command is waiting response. */
} CellularATCommandType_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief SIM Card status.
*/
typedef struct CellularSimCardStatus
{
CellularSimCardState_t simCardState; /**< Cellular sim card state. */
CellularSimCardLockState_t simCardLockState; /**< Cellular sim card lock state. */
} CellularSimCardStatus_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Public Land Mobile Network (PLMN) information.
*/
typedef struct CellularPlmnInfo
{
char mcc[ CELLULAR_MCC_MAX_SIZE + 1 ]; /**< Mobile Country Code (MCC). */
char mnc[ CELLULAR_MNC_MAX_SIZE + 1 ]; /**< Mobile Network Code (MNC). */
} CellularPlmnInfo_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief SIM Card information.
*/
typedef struct CellularSimCardInfo
{
char iccid[ CELLULAR_ICCID_MAX_SIZE + 1 ]; /**< Integrated Circuit Card Identifier aka SIM Card Number. */
char imsi[ CELLULAR_IMSI_MAX_SIZE + 1 ]; /**< International Mobile Subscriber Identity. */
CellularPlmnInfo_t plmn; /**< Public Land Mobile Network (PLMN) information. */
} CellularSimCardInfo_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Modem information.
*/
typedef struct CellularModemInfo
{
char hardwareVersion[ CELLULAR_HW_VERSION_MAX_SIZE + 1 ]; /**< Hardware version number. */
char firmwareVersion[ CELLULAR_FW_VERSION_MAX_SIZE + 1 ]; /**< Firmware version number. */
char serialNumber[ CELLULAR_SERIAL_NUM_MAX_SIZE + 1 ]; /**< Module serial number. */
char imei[ CELLULAR_IMEI_MAX_SIZE + 1 ]; /**< International Mobile Equipment Identity (IMEI). */
char manufactureId[ CELLULAR_MANUFACTURE_ID_MAX_SIZE + 1 ]; /**< Manufacture Identity. */
char modelId[ CELLULAR_MODEL_ID_MAX_SIZE + 1 ]; /**< Model Identity. */
} CellularModemInfo_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Represents time.
*/
typedef struct CellularTime
{
uint8_t month; /**< 1..12 (Jan = 1 .. Dec = 12). */
uint8_t day; /**< Day of the month 1..31. */
uint8_t hour; /**< Hour of the day 0..23. */
uint8_t minute; /**< Minute of the hour 0..59. */
uint8_t second; /**< Second of the minute 0..59. */
uint16_t year; /**< Year (like 2019). */
int32_t timeZone; /**< Timezone represented in 15 minute increments (UTC+1 will be 4 because 1 hour = 60 minutes = 4 * 15 minutes). */
uint8_t dst; /**< Daylight savings ( 0 = No adjustment for daylight savings
* 1 = +1 hour for daylight savings
* 2 = +2 hours for daylight savings ). */
} CellularTime_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Represents signal information.
*/
typedef struct CellularSignalInfo
{
int16_t rssi; /**< Received Signal Strength Indicator (RSSI) in dBm.*/
int16_t rsrp; /**< LTE Reference Signal Received Power (RSRP) in dBm. */
int16_t rsrq; /**< LTE Reference Signal Received Quality (RSRQ) in dB. */
int16_t sinr; /**< LTE Signal to Interference-Noise Ratio in dB. */
int16_t ber; /**< Bit Error Rate (BER) in 0.01%. */
uint8_t bars; /**< A number between 0 to 5 (both inclusive) indicating signal strength. */
} CellularSignalInfo_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Represents network service status.
*/
typedef struct CellularServiceStatus
{
CellularRat_t rat; /**< Radio Access Technology (RAT). */
CellularNetworkRegistrationMode_t networkRegistrationMode; /**< Network registration mode (auto/manual etc.) currently selected. */
CellularNetworkRegistrationStatus_t csRegistrationStatus; /**< CS (Circuit Switched) registration status (registered/searching/roaming etc.). */
CellularNetworkRegistrationStatus_t psRegistrationStatus; /**< PS (Packet Switched) registration status (registered/searching/roaming etc.). */
CellularPlmnInfo_t plmnInfo; /**< Registered MCC and MNC information. */
CellularOperatorNameFormat_t operatorNameFormat; /**< Format of registered network operator name. */
char operatorName[ CELLULAR_NETWORK_NAME_MAX_SIZE + 1 ]; /**< Registered network operator name. */
uint8_t csRejectionType; /**< CS Reject Type. 0 - 3GPP specific Reject Cause. 1 - Manufacture specific. */
uint8_t csRejectionCause; /**< Reason why the CS (Circuit Switched) registration attempt was rejected. */
uint8_t psRejectionType; /**< PS Reject Type. 0 - 3GPP specific Reject Cause. 1 - Manufacture specific. */
uint8_t psRejectionCause; /**< Reason why the PS (Packet Switched) registration attempt was rejected. */
} CellularServiceStatus_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Represents A singly-lined list of intermediate AT responses.
*/
typedef struct CellularATCommandLine
{
struct CellularATCommandLine * pNext; /**< The CellularATCommandLine structure pointer points to the next element of the liniked list. */
char * pLine; /**< The content of the at command. */
} CellularATCommandLine_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Represents AT Command response.
*/
typedef struct CellularATCommandResponse
{
bool status; /**< true: modem returns Success, false: Error. */
CellularATCommandLine_t * pItm; /**< Any intermediate responses. */
} CellularATCommandResponse_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Represents PSM settings.
*/
typedef struct CellularPsmSettings
{
/*
* 0 = PSM Disable
* 1 = PSM Enable.
*/
uint8_t mode; /**< PSM mode value (as shown above). */
/*
* Bits 5 to 1 represent the binary coded timer value
* Bits 6 to 8 define the timer value unit as follows:
* Bits
* 8 7 6
* 0 0 0 value is incremented in multiples of 10 minutes
* 0 0 1 value is incremented in multiples of 1 hour
* 0 1 0 value is incremented in multiples of 10 hours
* 0 1 1 value is incremented in multiples of 2 seconds
* 1 0 0 value is incremented in multiples of 30 seconds
* 1 0 1 value is incremented in multiples of 1 minute
*
* e.g. "00001010" equals to 100 minutes.
* first uint8_t is used for PSM set, whole uint32_t is used for PSM get.
*/
uint32_t periodicTauValue; /**< TAU (T3412) value encoded as per spec (as shown above). */
/*
* Bits 5 to 1 represent the binary coded timer value
* Bits 6 to 8 define the timer value unit as follows:
* Bits
* 8 7 6
* 0 0 0 value is incremented in multiples of 10 minutes
* 0 0 1 value is incremented in multiples of 1 hour
* 0 1 0 value is incremented in multiples of 10 hours
* 0 1 1 value is incremented in multiples of 2 seconds
* 1 0 0 value is incremented in multiples of 30 seconds
* 1 0 1 value is incremented in multiples of 1 minute
*
* e.g. "00001010" equals to 100 minutes.
* first uint8_t is used for PSM set, whole uint32_t is used for PSM get.
*/
uint32_t periodicRauValue; /**< RAU (T3312) value encoded as per Spec (as shown above). */
/*
* Bits 5 to 1 represent the binary coded timer value
* Bits 6 to 8 define the timer value unit as follows:
* Bits
* 8 7 6
* 0 0 0 value is incremented in multiples of 10 minutes
* 0 0 1 value is incremented in multiples of 1 hour
* 0 1 0 value is incremented in multiples of 10 hours
* 0 1 1 value is incremented in multiples of 2 seconds
* 1 0 0 value is incremented in multiples of 30 seconds
* 1 0 1 value is incremented in multiples of 1 minute
*
* e.g. "00001010" equals to 100 minutes.
* first uint8_t is used for PSM set, whole uint32_t is used for PSM get.
*/
uint32_t gprsReadyTimer; /**< GPRS Ready timer (T3314) value encoded as per Spec. */
/*
* Bits 5 to 1 represent the binary coded timer value.
* Bits 6 to 8 define the timer value unit as follows:
* Bits
* 8 7 6
* 0 0 0 value is incremented in multiples of 2 seconds
* 0 0 1 value is incremented in multiples of 1 minute
* 0 1 0 value is incremented in multiples of decihours
* 1 1 1 value indicates that the timer is deactivated.
*
* "00001111" equals to 30 seconds.
* first uint8_t is used for PSM set, whole uint32_t is used for PSM get.
*/
uint32_t activeTimeValue; /**< Active Time (T3324) value encoded as per spec (as shown above). */
} CellularPsmSettings_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Represents e-I-DRX settings.
*/
typedef struct CellularEidrxSettings
{
/*
* 0 Disable the use of e-I-DRX
* 1 Enable the use of e-I-DRX
* 2 Enable the use of e-I-DRX and enable the unsolicited result code
* 3 Disable the use of e-I-DRX and discard all parameters for e-I-DRX or,
* if available, reset to the manufacturer specific default values.
*/
uint8_t mode; /**< e-I-DRX mode (as shown above). */
/*
* 2 GSM
* 3 UTRAN
* 4 LTE Cat M1
* 5 LTE Cat NB1
*/
uint8_t rat; /**< Radio Access Technology (as shown above). */
/*
* String type. Half a byte in a 4 bit format.
* bit
* 4 3 2 1 E-UTRAN e-I-DRX cycle length duration
* 0 0 0 0 5.12 seconds
* 0 0 0 1 10.24 seconds
* 0 0 1 0 20.48 seconds
* 0 0 1 1 40.96 seconds
* 0 1 0 0 61.44 seconds
* 0 1 0 1 81.92 seconds
* 0 1 1 0 102.4 seconds
* 0 1 1 1 122.88 seconds
* 1 0 0 0 143.36 seconds
* 1 0 0 1 163.84 seconds
* 1 0 1 0 327.68 seconds
* 1 0 1 1 655,36 seconds
* 1 1 0 0 1310.72 seconds
* 1 1 0 1 2621.44 seconds
* 1 1 1 0 5242.88 seconds
* 1 1 1 1 10485.76 seconds
*/
uint8_t requestedEdrxVaue; /**< Requested eDRX value encoded as per spec (as shown above). */
uint8_t nwProvidedEdrxVaue; /**< Network provided eDRX value encoded as per spec (as shown above). Only applicable in URC. */
/*
* LTE Cat M1 mode
* bit
* 4 3 2 1 Paging Time Window length
* 0 0 0 0 1.28 seconds
* 0 0 0 1 2.56 seconds
* 0 0 1 0 3.84 seconds
* 0 0 1 1 5.12 seconds
* 0 1 0 0 6.4 seconds
* 0 1 0 1 7.68 seconds
* 0 1 1 0 8.96 seconds
* 0 1 1 1 10.24 seconds
* 1 0 0 0 11.52 seconds
* 1 0 0 1 12.8 seconds
* 1 0 1 0 14.08 seconds
* 1 0 1 1 15.36 seconds
* 1 1 0 0 16.64 seconds
* 1 1 0 1 17.92 seconds
* 1 1 1 0 19.20 seconds
* 1 1 1 1 20.48 seconds
*
* LTE Cat NB1 mode
* bit
* 4 3 2 1 Paging Time Window length
* 0 0 0 0 2.56 seconds
* 0 0 0 1 5.12 seconds
* 0 0 1 0 7.68 seconds
* 0 0 1 1 10.24 seconds
* 0 1 0 0 12.8 seconds
* 0 1 0 1 15.36 seconds
* 0 1 1 0 17.92 seconds
* 0 1 1 1 20.48 seconds
* 1 0 0 0 23.04 seconds
* 1 0 0 1 25.6 seconds
* 1 0 1 0 28.16 seconds
* 1 0 1 1 30.72 seconds
* 1 1 0 0 33.28 seconds
* 1 1 0 1 35.84 seconds
* 1 1 1 0 38.4 seconds
* 1 1 1 1 40.96 seconds
*/
uint8_t pagingTimeWindow; /**< Paging time window encoded as per spec (as shown above). Only applicable in URC. */
} CellularEidrxSettings_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Cellular Represents e-I-DRX settings Lists.
*/
typedef struct CellularEidrxSettingsList
{
CellularEidrxSettings_t eidrxList[ CELLULAR_EDRX_LIST_MAX_SIZE ]; /**< Cellular e-I-DRX settings list. */
uint8_t count; /**< Cellular e-I-DRX settings list number. */
} CellularEidrxSettingsList_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Represents IP Address.
*/
typedef struct CellularIPAddress
{
CellularIPAddressType_t ipAddressType; /**< Type of IP address (IPv4/IPv6). */
char ipAddress[ CELLULAR_IP_ADDRESS_MAX_SIZE + 1 ]; /**< IP Address. NULL terminated. */
} CellularIPAddress_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Represents a PDN config.
*/
typedef struct CellularPdnConfig
{
CellularPdnContextType_t pdnContextType; /**< PDN Context type. */
CellularPdnAuthType_t pdnAuthType; /**< PDN Authentication type. */
const char apnName[ CELLULAR_APN_MAX_SIZE + 1 ]; /**< APN name. */
const char username[ CELLULAR_PDN_USERNAME_MAX_SIZE + 1 ]; /**< Username. */
const char password[ CELLULAR_PDN_PASSWORD_MAX_SIZE + 1 ]; /**< Password. */
} CellularPdnConfig_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Represents status of a PDN context.
*/
typedef struct CellularPdnStatus
{
uint8_t contextId; /**< 1-16 are valid values. */
uint8_t state; /**< 0 = Deactivated, 1 = Activated. */
CellularPdnContextType_t pdnContextType; /**< PDN Context type. */
CellularIPAddress_t ipAddress; /**< Local IP address after the context is activated. */
} CellularPdnStatus_t;
/**
* @ingroup cellular_datatypes_paramstructs
* @brief Represents socket address.
*/
typedef struct CellularSocketAddress
{
CellularIPAddress_t ipAddress; /**< IP address. */
uint16_t port; /**< Port number. */
} CellularSocketAddress_t;
/**
* @ingroup cellular_datatypes_functionpointers
* @brief Callback used to inform about the response of an AT command sent
* using Cellular_ATCommandRaw API.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[in] pAtResp The response received for the AT command.
* @param[in] pData is pATCommandPayload pointer in Cellular_ATCommandRaw parameters.
* @param[in] dataLen is the string length of pATCommandPayloadin in Cellular_ATCommandRaw parameters.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
typedef CellularPktStatus_t ( * CellularATCommandResponseReceivedCallback_t ) ( CellularHandle_t cellularHandle,
const CellularATCommandResponse_t * pAtResp,
void * pData,
uint16_t dataLen );
/**
* @ingroup cellular_datatypes_functionpointers
* @brief Callback used to inform about a Network Registration URC event.
*
* @param[in] urcEvent URC Event that happened.
* @param[in] pServiceStatus The status of the network service.
* @param[in] pCallbackContext pCallbackContext parameter in
* Cellular_RegisterUrcNetworkRegistrationEventCallback function.
*/
typedef void ( * CellularUrcNetworkRegistrationCallback_t )( CellularUrcEvent_t urcEvent,
const CellularServiceStatus_t * pServiceStatus,
void * pCallbackContext );
/**
* @ingroup cellular_datatypes_functionpointers
* @brief Callback used to inform about PDN URC events.
*
* @param[in] urcEvent URC Event that happened.
* @param[in] contextId Context ID of the PDN context
* @param[in] pCallbackContext pCallbackContext parameter in
* Cellular_RegisterUrcPdnEventCallback function.
*/
typedef void ( * CellularUrcPdnEventCallback_t )( CellularUrcEvent_t urcEvent,
uint8_t contextId,
void * pCallbackContext );
/**
* @ingroup cellular_datatypes_functionpointers
* @brief Callback used to inform about signal strength changed URC event.
*
* @param[in] urcEvent URC Event that happened.
* @param[in] pSignalInfo The new signal information.
* @param[in] pCallbackContext pCallbackContext parameter in
* Cellular_RegisterUrcSignalStrengthChangedCallback function.
*/
typedef void ( * CellularUrcSignalStrengthChangedCallback_t )( CellularUrcEvent_t urcEvent,
const CellularSignalInfo_t * pSignalInfo,
void * pCallbackContext );
/**
* @ingroup cellular_datatypes_functionpointers
* @brief Generic callback used to inform all other URC events.
*
* @param[in] pRawData Raw data received in the URC event.
* @param[in] pCallbackContext pCallbackContext parameter in
* Cellular_RegisterUrcGenericCallback function.
*/
typedef void ( * CellularUrcGenericCallback_t )( const char * pRawData,
void * pCallbackContext );
/**
* @ingroup cellular_datatypes_functionpointers
* @brief Callback used to inform about modem events.
*
* @param[in] modemEvent The modem event.
* @param[in] pCallbackContext pCallbackContext parameter in
* Cellular_RegisterModemEventCallback function.
*/
typedef void ( * CellularModemEventCallback_t )( CellularModemEvent_t modemEvent,
void * pCallbackContext );
/**
* @ingroup cellular_datatypes_functionpointers
* @brief Callback used to inform about the status of socket open.
*
* @param[in] urcEvent URC Event that happened.
* @param[in] socketHandle Socket handle for which data is ready.
* @param[in] pCallbackContext pCallbackContext parameter in
* Cellular_SocketRegisterSocketOpenCallback function.
*/
typedef void ( * CellularSocketOpenCallback_t )( CellularUrcEvent_t urcEvent,
CellularSocketHandle_t socketHandle,
void * pCallbackContext );
/**
* @ingroup cellular_datatypes_functionpointers
* @brief Callback used to inform that data is ready for reading on a socket.
*
* @param[in] socketHandle Socket handle for which data is ready.
* @param[in] pCallbackContext pCallbackContext parameter in
* Cellular_SocketRegisterDataReadyCallback function.
*/
typedef void ( * CellularSocketDataReadyCallback_t )( CellularSocketHandle_t socketHandle,
void * pCallbackContext );
/**
* @ingroup cellular_datatypes_functionpointers
* @brief Callback used to inform that remote end closed the connection for a
* connected socket.
*
* @param[in] socketHandle Socket handle for which remote end closed the
* connection.
* @param[in] pCallbackContext pCallbackContext parameter in
* Cellular_SocketRegisterClosedCallback function.
*/
typedef void ( * CellularSocketClosedCallback_t )( CellularSocketHandle_t socketHandle,
void * pCallbackContext );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* __CELLULAR_TYPES_H__ */

View File

@ -0,0 +1,411 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @file cellular_at_core.h
*/
#ifndef __CELLULAR_AT_CORE_H__
#define __CELLULAR_AT_CORE_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Standard includes */
#include <stdbool.h>
#include <string.h>
/* Standard includes. */
#include <stdint.h>
/*-----------------------------------------------------------*/
/**
* @brief Maximum size of an AT string.
*/
#define CELLULAR_AT_MAX_STRING_SIZE ( 256U )
/**
* @brief Maximum size of an AT prefix.
*/
#define CELLULAR_AT_MAX_PREFIX_SIZE ( 32 )
/**
* @brief The array size of an array.
*/
#define ARRY_SIZE( x ) ( sizeof( x ) / sizeof( x[ 0 ] ) )
/*-----------------------------------------------------------*/
/**
* @brief Represents error codes returned from AT Core APIs.
*/
typedef enum CellularATError
{
CELLULAR_AT_SUCCESS = 0, /**< The operation was successful. */
CELLULAR_AT_BAD_PARAMETER, /**< One or more of the input parameters is not valid. */
CELLULAR_AT_NO_MEMORY, /**< Memory allocation failure. */
CELLULAR_AT_UNSUPPORTED, /**< The operation is not supported. */
CELLULAR_AT_MODEM_ERROR, /**< Error in modem response. */
CELLULAR_AT_ERROR, /**< Generic Error or boolean false. */
CELLULAR_AT_UNKNOWN /**< Any other error other than the above mentioned ones. */
} CellularATError_t;
/*-----------------------------------------------------------*/
/**
* @brief Remove prefix from a string
*
* Many AT responses contain prefix of the form +XXXX. This function removes the
* prefix by moving the pointer after the prefix. For example:
*
* Input:
* +---+---+---+---+---+---+---+---+---+---+---+
* | + | C | P | I | N | : | R | E | A | D | Y |
* +---+---+---+---+---+---+---+---+---+---+---+
* ^
* |
* *ppString
*
* Output:
* +---+---+---+---+---+---+---+---+---+---+---+
* | + | C | P | I | N | : | R | E | A | D | Y |
* +---+---+---+---+---+---+---+---+---+---+---+
* ^
* |
* *ppString
*
* Note that a prefix is always followed by colon (':') and this function
* removes colon as well.
*
* @param[in,out] ppString The AT response to remove the prefix from. In
* case of success, the pointer is updated to move past the prefix.
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATRemovePrefix( char ** ppString );
/**
* @brief Remove all leading white spaces from an AT response.
*
* Leading white spaces are removed by updating the pointer to the first
* non-white space character. For example:
*
* Input:
* +--+--+--+---+---+---+---+---+---+---+---+------+
* | | | | r | e | s | p | o | n | s | e | '\0' |
* +--+--+--+---+---+---+---+---+---+---+---+------+
* ^
* |
* *ppString
*
* Output:
* +--+--+--+---+---+---+---+---+---+---+---+------+
* | | | | r | e | s | p | o | n | s | e | '\0' |
* +--+--+--+---+---+---+---+---+---+---+---+------+
* ^
* |
* *ppString
*
* @param[in,out] ppString The AT response to remove the leading white spaces
* from. In case of success, the pointer is updated to the first non white space
* character.
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATRemoveLeadingWhiteSpaces( char ** ppString );
/**
* @brief Remove all trailing white spaces from an AT response.
*
* Trailing spaces are removed by making the character next to the last
* non white space character NULL ('\0'). For example:
*
* Input:
* +---+---+---+---+---+---+---+---+--+--+--+------+
* | r | e | s | p | o | n | s | e | | | | '\0' |
* +---+---+---+---+---+---+---+---+--+--+--+------+
*
* Output:
* +---+---+---+---+---+---+---+---+------+--+--+------+
* | r | e | s | p | o | n | s | e | '\0' | | | '\0' |
* +---+---+---+---+---+---+---+---+------+--+--+------+
*
* @param[in,out] pString The AT response to remove the trailing white
* spaces from.
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATRemoveTrailingWhiteSpaces( char * pString );
/**
* @brief Remove all white spaces from an AT response.
*
* White spaces are removed by copying the non-white space characters to the
* beginning. The character next to the last non-white space character is set
* to the null character ('\0'). For example:
*
* Input:
* +--+--+--+---+---+---+---+---+---+---+-- +---+------+
* | | | | r | e | s | p | | o | n | s | e | '\0' |
* +--+--+--+---+---+---+---+---+---+---+---+---+------+
*
* Output:
* +---+---+---+---+---+---+---+---+------+------+
* | r | e | s | p | o | n | s | e | '\0' | '\0' |
* +---+---+---+---+---+---+---+---+------+------+
*
* @param[in,out] pString The AT response to remove the white spaces from.
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATRemoveAllWhiteSpaces( char * pString );
/**
* @brief Remove outermost double quotes from an AT response.
*
* If the first character is double quote, it is removed by updating the pointer
* to point to the next character. If the last character is double quote, it
* is removed by making it the null character. Nothing else is done in any other
* case. For example:
*
* Input:
* +---+---+---+---+---+---+---+---+---+---+------+
* | " | r | e | s | p | o | n | s | e | " | '\0' |
* +---+---+---+---+---+---+---+---+---+---+------+
* ^
* |
* *ppString
*
* Output:
* +---+---+---+---+---+---+---+---+---+------+------+
* | " | r | e | s | p | o | n | s | e | '\0' | '\0' |
* +---+---+---+---+---+---+---+---+---+------+------+
* ^
* |
* *ppString
*
* @param[in,out] ppString The AT response to remove the double quotes
* from.
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATRemoveOutermostDoubleQuote( char ** ppString );
/**
* @brief Remove all double quotes from an AT response.
*
* Double quotes are removed by copying all the other characters to the
* beginning. The character next to the last character is set to the null
* character ('\0'). For example:
*
* Input:
* +---+---+---+---+---+---+---+---+---+---+---+---+------+
* | " | r | e | s | " | p | " | o | n | s | e | " | '\0' |
* +---+---+---+---+---+---+---+---+---+---+---+---+------+
*
* Output:
* +---+---+---+---+---+---+---+---+------+---+---+---+------+
* | r | e | s | p | o | n | s | e | '\0' | s | e | " | '\0' |
* +---+---+---+---+---+---+---+---+------+---+---+---+------+
*
* @param[in,out] pString The AT response to remove the double quotes
* from.
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATRemoveAllDoubleQuote( char * pString );
/**
* @brief Extract the next token based on comma (',') as delimiter.
*
* @param[in,out] ppString The AT response to extract the token from.
* @param[in,out] ppTokOutput The output parameter to return the location of the
* token.
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATGetNextTok( char ** ppString,
char ** ppTokOutput );
/**
* @brief Extract the next token based on the provided delimiter.
*
* This function uses *ppATResponse as the starting location to scan for tokens
* which are sequences of contiguous characters separated by delimiters. When it
* finds a token, *ppOutToken is updated to point to starting location of the
* token and *ppATResponse is updated to point to the next character after the
* token. This ensures that the next call to this function will extract the next
* occurrence of the token.
*
* @param[in,out] ppString The AT response to extract the token from.
* @param[in] pDelimiter The delimiter string.
* @param[in,out] ppTokOutput The output parameter to return the location of the
* token.
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATGetSpecificNextTok( char ** ppString,
const char * pDelimiter,
char ** ppTokOutput );
/**
* @brief Convert HEX string to HEX.
*
* This function requires the provided string to be of even length and returns
* CELLULAR_AT_BAD_PARAMETER if it is not. It also requires the output buffer to be
* of exactly half the length of the given hex string to ensure that it exactly
* fits the converted data.
*
* It reads two characters and constructs a HEX byte by treating them upper and
* lower nibble of the byte. For example:
*
* Input:
* +---+---+---+---+------+
* | 1 | 0 | A | B | '\0' |
* +---+---+---+---+------+
*
* Output:
* +----+-----+------+
* | 16 | 171 | '\0' |
* +----+-----+------+
*
* Decimal 16 is 0x10 and decimal 171 is 0xAB.
*
* @param[in] pString The hex string to convert to HEX.
* @param[out] pHexData The buffer to return the converted HEX data into.
* @param[in] hexDataLen The length of the buffer.
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATHexStrToHex( const char * pString,
uint8_t * pHexData,
uint16_t hexDataLen );
/**
* @brief Check if a string is numeric.
*
* A string is numeric if all the characters in it are digits. For example,
* "1234" is numeric but "123YD" is not because 'Y' and 'D' are not digits.
*
* @param[in] pString The input string to check.
* @param[out] pResult The bool output parameter to return whether or not the
* string is numeric.
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATIsStrDigit( const char * pString,
bool * pResult );
/**
* @brief check if a string as prefix present by determine present of ':'
*
* @param[in] pString input string
* @param[out] pResult The bool output parameter to return whether or not the
* string is numeric.
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATIsPrefixPresent( const char * pString,
bool * pResult );
/**
* @brief duplicate string from pSrc to ppDst, malloc is use to allocate mem space for ppDst
*
* @param[in] pSrc: input string to be copied
* @param[out] ppDst: destination pointer
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATStrDup( char ** ppDst,
const char * pSrc );
/**
* @brief check if a string starts with certain prefix
*
* @param[in] pString input string
* @param[in] pPrefix input prefix
* @param[out] pResult return true if prefix is at start of pString, else false
*
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATStrStartWith( const char * pString,
const char * pPrefix,
bool * pResult );
/**
* @brief check if certain success code/error code present in the input buffer
*
* @param[in] pInputBuf: the haystack buffer
* @param[in] ppKeyList: list of keys
* @param[in] keyListLen: size of the keyList array
* @param[out] pResult: return true if any of Keys in ppKeyList is found in is at start of pString, else false
* *
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATcheckErrorCode( const char * pInputBuf,
const char * const * const ppKeyList,
size_t keyListLen,
bool * pResult );
/**
* @brief Convert string to int32_t.
*
* @param[in] pStr: the input string buffer.
* @param[in] base: Numerical base (radix) of pStr.
* Input string should not contain leading space or zero.
* @param[out] pResult: converted int32_t result.
* *
* @return CELLULAR_AT_SUCCESS if the operation is successful, otherwise an
* error code indicating the cause of the error.
*/
CellularATError_t Cellular_ATStrtoi( const char * pStr,
int32_t base,
int32_t * pResult );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* __CELLULAR_AT_CORE_H__ */

View File

@ -0,0 +1,630 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @file cellular_common.h
*/
#ifndef __CELLULAR_COMMON_H__
#define __CELLULAR_COMMON_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Standard includes. */
#include <stdbool.h>
/* Cellular includes. */
#ifndef CELLULAR_DO_NOT_USE_CUSTOM_CONFIG
/* Include custom config file before other headers. */
#include "cellular_config.h"
#endif
#include "cellular_config_defaults.h"
#include "cellular_platform.h"
#include "cellular_comm_interface.h"
#include "cellular_types.h"
#include "cellular_at_core.h"
/*-----------------------------------------------------------*/
/**
* @ingroup cellular_common_datatypes_paramstructs
* @brief The AT command request structure.
*/
typedef struct CellularAtReq
{
const char * pAtCmd; /**< The At command string used for at command request. */
CellularATCommandType_t atCmdType; /**< The At command type. */
const char * pAtRspPrefix; /**< The prefix of at command response. */
CellularATCommandResponseReceivedCallback_t respCallback; /**< The callback function #CellularATCommandResponseReceivedCallback_t. */
void * pData; /**< The data pointer to the data. */
uint16_t dataLen; /**< The length of the data pointer . */
} CellularAtReq_t;
/**
* @ingroup cellular_common_datatypes_paramstructs
* @brief The data command request structure.
*/
typedef struct CellularAtDataReq
{
const uint8_t * pData; /**< Data to send. */
uint32_t dataLen; /**< Data length to send. */
uint32_t * pSentDataLength; /**< Data actually sent. */
const uint8_t * pEndPattern; /**< End pattern after pData is sent completely.
* Set NULL if not required. Cellular modem uses
* end pattern instead of length in AT command
* can make use of this variable. */
uint32_t endPatternLen; /**< End pattern length. */
} CellularAtDataReq_t;
/**
* @ingroup cellular_common_datatypes_functionpointers
* @brief URC handler function.
*
* @return Void.
*/
typedef void ( * CellularAtParseTokenHandler_t )( CellularContext_t * pContext,
char * pInputStr );
/**
* @ingroup cellular_common_datatypes_paramstructs
* @brief the URC token and URC handler mapping structure used by pkthanlder.
*/
typedef struct CellularAtParseTokenMap
{
const char * pStrValue; /**< The URC token string. */
CellularAtParseTokenHandler_t parserFunc; /**< The function pointer points to #CellularAtParseTokenHandler_t. */
} CellularAtParseTokenMap_t;
/**
* @ingroup cellular_common_datatypes_enums
* @brief enum representing different Socket State.
*/
typedef enum CellularSocketState
{
SOCKETSTATE_ALLOCATED = 0, /**< Socket is created. */
SOCKETSTATE_CONNECTING, /**< Socket is connecting in progress with remote peer. */
SOCKETSTATE_CONNECTED, /**< Socket is connected. */
SOCKETSTATE_DISCONNECTED /**< Socket is disconnected by remote peer or due to network error. */
} CellularSocketState_t;
/**
* @ingroup cellular_common_datatypes_paramstructs
* @brief Parameters involved in sending/receiving data through sockets.
*/
typedef struct CellularSocketContext
{
uint8_t contextId; /**< PDN context ID on which this socket exists. */
uint32_t socketId; /**< Socket ID of this socket. */
CellularSocketState_t socketState; /**< State of the socket, Allocated, Free etc. */
CellularSocketType_t socketType; /**< Type of socket, DGRAM or STREAM. */
CellularSocketDomain_t socketDomain; /**< Socket domain, IPV4 or V6. */
CellularSocketProtocol_t socketProtocol; /**< Socket transport protocol, TCP or UDP. */
CellularIPAddress_t localIpAddress; /**< IP address assigned to the device. */
uint16_t localPort; /**< Local Port. */
CellularSocketAccessMode_t dataMode; /**< Data Access mode enabled for this socket. */
/* Set using socket options. */
uint32_t sendTimeoutMs; /**< Send timeout value in milliseconds. */
uint32_t recvTimeoutMs; /**< Receive timeout value in milliseconds. */
/* Set during socket connect. */
CellularSocketAddress_t remoteSocketAddress; /**< Remote IP address and port. */
/* Callback functions. */
CellularSocketDataReadyCallback_t dataReadyCallback; /**< Informs data on this socket. */
void * pDataReadyCallbackContext; /**< Data ready callback context. */
CellularSocketOpenCallback_t openCallback; /**< Informs the socket open status. */
void * pOpenCallbackContext; /**< socket open callback context. */
CellularSocketClosedCallback_t closedCallback; /**< Informs the socket is closed. */
void * pClosedCallbackContext; /**< socket closed callback context. */
/* Modem data. */
void * pModemData; /**< Modem specific data. */
} CellularSocketContext_t;
/**
* @ingroup cellular_common_datatypes_paramstructs
* @brief Parameters to setup pktio and pkthandler token tables.
*/
typedef struct CellularTokenTable
{
/* URC handler mapping table. */
CellularAtParseTokenMap_t * pCellularUrcHandlerTable; /**< URC handler table. */
uint32_t cellularPrefixToParserMapSize; /**< URC handler table size. */
/* Table to decide AT command respone status. */
const char ** pCellularSrcTokenErrorTable; /**< Solicited error token table. */
uint32_t cellularSrcTokenErrorTableSize; /**< Solicited error token table size. */
const char ** pCellularSrcTokenSuccessTable; /**< Solicited success token table. */
uint32_t cellularSrcTokenSuccessTableSize; /**< Solicited success token table size. */
/* Table to URC with prefix Token. */
const char ** pCellularUrcTokenWoPrefixTable; /**< URC token without prefix table. */
uint32_t cellularUrcTokenWoPrefixTableSize; /**< URC token without prefix table size. */
/* Extra success token for specific AT command. */
const char ** pCellularSrcExtraTokenSuccessTable; /**< Extra token success table. */
uint32_t cellularSrcExtraTokenSuccessTableSize; /**< Extra token success table size. */
} CellularTokenTable_t;
/**
* @ingroup cellular_common_datatypes_functionpointers
* @brief Callback used to inform pktio the data start and the length of the data.
*
* @param[in] pCallbackContext The pCallbackContext in _Cellular_TimeoutAtcmdDataRecvRequestWithCallback.
* @param[in] pLine The input line form cellular modem.
* @param[in] lineLength The length of the input line from cellular modem.
* @param[out] pDataStart Is the start of of data in pLine.
* @param[out] pDataLength Is the data length.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful.
* CELLULAR_PKT_STATUS_SIZE_MISMATCH if more data is required.
* Otherwise an error code indicating the cause of the error.
*/
typedef CellularPktStatus_t ( * CellularATCommandDataPrefixCallback_t ) ( void * pCallbackContext,
char * pLine,
uint32_t lineLength,
char ** pDataStart,
uint32_t * pDataLength );
/**
* @ingroup cellular_common_datatypes_functionpointers
* @brief Callback used to fix the stream before the send data.
*
* @param[in] pCallbackContext The pCallbackContext in CellularATCommandDataSendPrefixCallback_t.
* @param[in,out] pLine The input line form cellular modem.
* @param[in,out] pBytesRead The length of the input line from cellular modem.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
typedef CellularPktStatus_t ( * CellularATCommandDataSendPrefixCallback_t ) ( void * pCallbackContext,
char * pLine,
uint32_t * pBytesRead );
/**
* @ingroup cellular_common_datatypes_functionpointers
* @brief Undefined response callback function.
*
* @param[in] pCallbackContext The pCallbackContext parameter in _Cellular_RegisterUndefinedRespCallback.
* @param[in] pLine The input line form cellular modem.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
typedef CellularPktStatus_t ( * CellularUndefinedRespCallback_t )( void * pCallbackContext,
const char * pLine );
/*-----------------------------------------------------------*/
/**
* @brief One time initialization function.
*
* This function initializes and returns the supplied context. It must be called
* once (and only once) before calling any other function of this library.
*
* @param[in,out] pCellularHandle The handle pointer to store the cellular handle.
* @param[in] pCommInterface Comm interface for communicating with the module.
* @param[in] pTokenTable Token tables for pkthandler and pktio.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t _Cellular_LibInit( CellularHandle_t * pCellularHandle,
const CellularCommInterface_t * pCommInterface,
const CellularTokenTable_t * pTokenTable );
/**
* @brief One time deinitialization function.
*
* This function frees resources taken in Cellular_Init. After this function
* returns, Cellular_Init must be called again before calling any other function
* of this library.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t _Cellular_LibCleanup( CellularHandle_t cellularHandle );
/**
* @brief Call the network registration callback if the callback is previously set by
* Cellular_CommonRegisterUrcNetworkRegistrationEventCallback.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] urcEvent URC Event that happened.
* @param[in] pServiceStatus The status of the network service.
*/
void _Cellular_NetworkRegistrationCallback( const CellularContext_t * pContext,
CellularUrcEvent_t urcEvent,
const CellularServiceStatus_t * pServiceStatus );
/**
* @brief Call the network registration callback if the callback is previously set by
* Cellular_RegisterUrcPdnEventCallback.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] urcEvent URC Event that happened.
* @param[in] contextId Context ID of the PDN context.
*/
void _Cellular_PdnEventCallback( const CellularContext_t * pContext,
CellularUrcEvent_t urcEvent,
uint8_t contextId );
/**
* @brief Call the network registration callback if the callback is previously set by
* Cellular_RegisterUrcSignalStrengthChangedCallback.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] urcEvent URC Event that happened.
* @param[in] pSignalInfo The new signal information.
*/
void _Cellular_SignalStrengthChangedCallback( const CellularContext_t * pContext,
CellularUrcEvent_t urcEvent,
const CellularSignalInfo_t * pSignalInfo );
/**
* @brief Call the network registration callback if the callback is previously set by
* Cellular_RegisterUrcGenericCallback.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] pRawData Raw data received in the URC event.
*/
void _Cellular_GenericCallback( const CellularContext_t * pContext,
const char * pRawData );
/**
* @brief Call the network registration callback if the callback is previously set by
* Cellular_RegisterModemEventCallback.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] modemEvent The modem event.
*/
void _Cellular_ModemEventCallback( const CellularContext_t * pContext,
CellularModemEvent_t modemEvent );
/**
* @brief Check Library Status.
*
* This Functions checks if the FreeRTOS Cellular Library is already opened and set up
* for cellular modem operation for control and data plane function.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*
* @return CELLULAR_SUCCESS if the operation is successful , otherwise return error code.
*/
CellularError_t _Cellular_CheckLibraryStatus( CellularContext_t * pContext );
/**
* @brief Translate error code packet status to cellular Status.
*
* This Functions translates packet status to cellular Status.
*
* @param[in] status The packet status to translate.
*
* @return The corresponding CellularError_t.
*/
CellularError_t _Cellular_TranslatePktStatus( CellularPktStatus_t status );
/**
* @brief Translate Error Code AT Core status to Packet Status.
*
* This Functions translates AT Core status to Packet Status.
*
* @param[in] status The AT Core status to translate.
*
* @return The corresponding CellularPktStatus_t.
*/
CellularPktStatus_t _Cellular_TranslateAtCoreStatus( CellularATError_t status );
/**
* @brief Create a socket.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] contextId Pdn context id on which this socket needs to be created.
* @param[in] socketDomain Socket domain.
* @param[in] socketType Socket Type.
* @param[in] socketProtocol Socket Protocol.
* @param[out] pSocketHandle Out parameter to provide the created handle.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t _Cellular_CreateSocketData( CellularContext_t * pContext,
uint8_t contextId,
CellularSocketDomain_t socketDomain,
CellularSocketType_t socketType,
CellularSocketProtocol_t socketProtocol,
CellularSocketHandle_t * pSocketHandle );
/**
* @brief Remove the socket.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] socketHandle Socket handle returned from the Cellular_CreateSocket call.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t _Cellular_RemoveSocketData( CellularContext_t * pContext,
CellularSocketHandle_t socketHandle );
/**
* @brief Check socket index validity.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] sockIndex Socket index returned from cellular modem.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t _Cellular_IsValidSocket( const CellularContext_t * pContext,
uint32_t sockIndex );
/**
* @brief Get the socket data structure with socket index.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] sockIndex Socket index returned from cellular modem.
*
* @return The socket data pointer if the socket index is valid, otherwise NULL is returned.
*/
CellularSocketContext_t * _Cellular_GetSocketData( const CellularContext_t * pContext,
uint32_t sockIndex );
/**
* @brief Check PDN context index validity.
*
* @param[in] contextId The PDN context index to check.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t _Cellular_IsValidPdn( uint8_t contextId );
/**
* @brief Convert CSQ command returned RSSI value.
*
* @param[in] csqRssi The CSQ command returned RSSI index.
* @param[out] pRssiValue The output parameter to return the converted
* RSSI value in dBm.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t _Cellular_ConvertCsqSignalRssi( int16_t csqRssi,
int16_t * pRssiValue );
/**
* @brief Convert CSQ command retruned BER value.
*
* @param[in] csqBer The CSQ command returned BER index.
* @param[out] pBerValue The output parameter to return the converted
* BER value in 0.01%.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t _Cellular_ConvertCsqSignalBer( int16_t csqBer,
int16_t * pBerValue );
/**
* @brief Get the socket data structure with socket index.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[out] ppModuleContext The module context set in Cellular_ModuleInit function.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t _Cellular_GetModuleContext( const CellularContext_t * pContext,
void ** ppModuleContext );
/**
* @brief Convert the signal to bar.
*
* @param[in] rat Current RAT of the registered network.
* @param[in,out] pSignalInfo The signal value of current RAT. The result bar
* value is assigned in this structure.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t _Cellular_ComputeSignalBars( CellularRat_t rat,
CellularSignalInfo_t * pSignalInfo );
/**
* @brief Return the current RAT if previously received with 3GPP AT command.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[out] pRat Current RAT of the registered network.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t _Cellular_GetCurrentRat( CellularContext_t * pContext,
CellularRat_t * pRat );
/**
* @brief Send the AT command to cellular modem with default timeout.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] atReq The AT command data structure with send command response callback.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_AtcmdRequestWithCallback( CellularContext_t * pContext,
CellularAtReq_t atReq );
/**
* @brief Send the AT command to cellular modem.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] atReq The AT command data structure with send command response callback.
* @param[in] timeoutMS The timeout value to wait for the response from cellular modem.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_TimeoutAtcmdRequestWithCallback( CellularContext_t * pContext,
CellularAtReq_t atReq,
uint32_t timeoutMS );
/**
* @brief Send the AT command to cellular modem with extra success token table.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] atReq The AT command data structure with send command response callback.
* @param[in] atTimeoutMS The timeout value to wait for the AT command response from cellular modem.
* @param[in] pCellularSrcTokenSuccessTable The extra success token table to indicate the send AT command success.
* @param[in] cellularSrcTokenSuccessTableSize The size of extra success token table.
*
* @note AT command request makes use of cellularSrcTokenSuccessTableSize to obtain
* the response status. Some AT commands don't have fixed success token. This function
* make use of a temporary table, pCellularSrcTokenSuccessTable, to obtain the response
* status.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_AtcmdRequestSuccessToken( CellularContext_t * pContext,
CellularAtReq_t atReq,
uint32_t atTimeoutMS,
const char ** pCellularSrcTokenSuccessTable,
uint32_t cellularSrcTokenSuccessTableSize );
/**
* @brief Send the AT command to cellular modem with data buffer response.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] atReq The AT command data structure with send command response callback.
* @param[in] timeoutMS The timeout value to wait for the response from cellular modem.
* @param[in] pktDataPrefixCallback The callback function to indicate the start of data and the length of data.
* @param[in] pCallbackContext The pCallbackContext passed to the pktDataPrefixCallback callback function.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_TimeoutAtcmdDataRecvRequestWithCallback( CellularContext_t * pContext,
CellularAtReq_t atReq,
uint32_t timeoutMS,
CellularATCommandDataPrefixCallback_t pktDataPrefixCallback,
void * pCallbackContext );
/**
* @brief Send the AT command to cellular modem with send data.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] atReq The AT command data structure with send command response callback.
* @param[in] dataReq The following data request after the at request.
* @param[in] atTimeoutMS The timeout value to wait for the AT command response from cellular modem.
* @param[in] dataTimeoutMS The timeout value to wait for the data command response from cellular modem.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_TimeoutAtcmdDataSendRequestWithCallback( CellularContext_t * pContext,
CellularAtReq_t atReq,
CellularAtDataReq_t dataReq,
uint32_t atTimeoutMS,
uint32_t dataTimeoutMS );
/**
* @brief Send the AT command to cellular modem with send data.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] atReq The AT command data structure with send command response callback.
* @param[in] dataReq The following data request after the at request.
* @param[in] pktDataSendPrefixCallback The callback function to inidcate the data sending start.
* @param[in] pCallbackContext The callback context pass to pktDataSendPrefixCallback function.
* @param[in] atTimeoutMS The timeout value to wait for the AT command response from cellular modem.
* @param[in] dataTimeoutMS The timeout value to wait for the data command response from cellular modem.
* @param[in] interDelayMS The delay between AT command and data send.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_AtcmdDataSend( CellularContext_t * pContext,
CellularAtReq_t atReq,
CellularAtDataReq_t dataReq,
CellularATCommandDataSendPrefixCallback_t pktDataSendPrefixCallback,
void * pCallbackContext,
uint32_t atTimeoutMS,
uint32_t dataTimeoutMS,
uint32_t interDelayMS );
/**
* @brief Send the AT command to cellular modem with send data and extra success token table
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] atReq The AT command data structure with send command response callback.
* @param[in] dataReq The following data request after the at request.
* @param[in] atTimeoutMS The timeout value to wait for the AT command response from cellular modem.
* @param[in] dataTimeoutMS The timeout value to wait for the data command response from cellular modem.
* @param[in] pCellularSrcTokenSuccessTable The extra success token table to indicate the send AT command success.
* @param[in] cellularSrcTokenSuccessTableSize The size of extra success token table.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_TimeoutAtcmdDataSendSuccessToken( CellularContext_t * pContext,
CellularAtReq_t atReq,
CellularAtDataReq_t dataReq,
uint32_t atTimeoutMS,
uint32_t dataTimeoutMS,
const char ** pCellularSrcTokenSuccessTable,
uint32_t cellularSrcTokenSuccessTableSize );
/**
* @brief Register undefined response callback.
*
* Cellular module can register the callback function to handle AT_UNDEFINED response
* through this function.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] undefinedRespCallback The callback function to handle the undefined response.
* @param[in] pCallbackContext The pCallbackContext passed to the undefinedRespCallback
* callback function if undefinedRespCallback is not NULL.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error code
* indicating the cause of the error.
*/
CellularError_t _Cellular_RegisterUndefinedRespCallback( CellularContext_t * pContext,
CellularUndefinedRespCallback_t undefinedRespCallback,
void * pCallbackContext );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* __CELLULAR_COMMON_H__ */

View File

@ -0,0 +1,312 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @file cellular_common_api.h
*/
#ifndef __CELLULAR_COMMON_API_H__
#define __CELLULAR_COMMON_API_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#include "cellular_types.h"
#include "cellular_common.h"
#include "cellular_comm_interface.h"
/*-----------------------------------------------------------*/
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_Init in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonInit( CellularHandle_t * pCellularHandle,
const CellularCommInterface_t * pCommInterface,
const CellularTokenTable_t * pTokenTable );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_Cleanup in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonCleanup( CellularHandle_t cellularHandle );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_RegisterUrcNetworkRegistrationEventCallback in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonRegisterUrcNetworkRegistrationEventCallback( CellularHandle_t cellularHandle,
CellularUrcNetworkRegistrationCallback_t networkRegistrationCallback,
void * pCallbackContext );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_RegisterUrcPdnEventCallback in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonRegisterUrcPdnEventCallback( CellularHandle_t cellularHandle,
CellularUrcPdnEventCallback_t pdnEventCallback,
void * pCallbackContext );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_RegisterUrcSignalStrengthChangedCallback in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonRegisterUrcSignalStrengthChangedCallback( CellularHandle_t cellularHandle,
CellularUrcSignalStrengthChangedCallback_t signalStrengthChangedCallback,
void * pCallbackContext );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_RegisterUrcGenericCallback in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonRegisterUrcGenericCallback( CellularHandle_t cellularHandle,
CellularUrcGenericCallback_t genericCallback,
void * pCallbackContext );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_RegisterModemEventCallback in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonRegisterModemEventCallback( CellularHandle_t cellularHandle,
CellularModemEventCallback_t modemEventCallback,
void * pCallbackContext );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_ATCommandRaw in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonATCommandRaw( CellularHandle_t cellularHandle,
const char * pATCommandPrefix,
const char * pATCommandPayload,
CellularATCommandType_t atCommandType,
CellularATCommandResponseReceivedCallback_t responseReceivedCallback,
void * pData,
uint16_t dataLen );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_CreateSocket in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonCreateSocket( CellularHandle_t cellularHandle,
uint8_t pdnContextId,
CellularSocketDomain_t socketDomain,
CellularSocketType_t socketType,
CellularSocketProtocol_t socketProtocol,
CellularSocketHandle_t * pSocketHandle );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_SocketSetSockOpt in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonSocketSetSockOpt( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketOptionLevel_t optionLevel,
CellularSocketOption_t option,
const uint8_t * pOptionValue,
uint32_t optionValueLength );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_SocketRegisterDataReadyCallback in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonSocketRegisterDataReadyCallback( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketDataReadyCallback_t dataReadyCallback,
void * pCallbackContext );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_SocketRegisterSocketOpenCallback in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonSocketRegisterSocketOpenCallback( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketOpenCallback_t socketOpenCallback,
void * pCallbackContext );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_SocketRegisterClosedCallback in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonSocketRegisterClosedCallback( CellularHandle_t cellularHandle,
CellularSocketHandle_t socketHandle,
CellularSocketClosedCallback_t closedCallback,
void * pCallbackContext );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_RfOn in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonRfOn( CellularHandle_t cellularHandle );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_RfOff in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonRfOff( CellularHandle_t cellularHandle );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_GetIPAddress in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonGetIPAddress( CellularHandle_t cellularHandle,
uint8_t contextId,
char * pBuffer,
uint32_t bufferLength );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_GetModemInfo in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonGetModemInfo( CellularHandle_t cellularHandle,
CellularModemInfo_t * pModemInfo );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_GetEidrxSettings in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonGetEidrxSettings( CellularHandle_t cellularHandle,
CellularEidrxSettingsList_t * pEidrxSettingsList );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_SetEidrxSettings in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonSetEidrxSettings( CellularHandle_t cellularHandle,
const CellularEidrxSettings_t * pEidrxSettings );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_GetRegisteredNetwork in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonGetRegisteredNetwork( CellularHandle_t cellularHandle,
CellularPlmnInfo_t * pNetworkInfo );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_GetNetworkTime in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonGetNetworkTime( CellularHandle_t cellularHandle,
CellularTime_t * pNetworkTime );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_GetServiceStatus in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonGetServiceStatus( CellularHandle_t cellularHandle,
CellularServiceStatus_t * pServiceStatus );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_GetServiceStatus in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonSetPdnConfig( CellularHandle_t cellularHandle,
uint8_t contextId,
const CellularPdnConfig_t * pPdnConfig );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_GetServiceStatus in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonGetPsmSettings( CellularHandle_t cellularHandle,
CellularPsmSettings_t * pPsmSettings );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_GetServiceStatus in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonSetPsmSettings( CellularHandle_t cellularHandle,
const CellularPsmSettings_t * pPsmSettings );
/**
* @brief This function is the common implementation of FreeRTOS Cellular Library API.
* Reference Cellular_GetServiceStatus in cellular_api.h for definition.
*/
CellularError_t Cellular_CommonGetSimCardInfo( CellularHandle_t cellularHandle,
CellularSimCardInfo_t * pSimCardInfo );
/**
* @brief Get SIM card lock status.
*
* @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init.
* @param[out] pSimCardStatus Out parameter to provide the SIM card status.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_CommonGetSimCardLockStatus( CellularHandle_t cellularHandle,
CellularSimCardStatus_t * pSimCardStatus );
/**
* @brief 3GPP URC AT+CEREG handler for FreeRTOS Cellular Library.
*
* This function handles the incoming URC and callback function.
*
* @param[in,out] pContext FreeRTOS Cellular Library context created in Cellular_Init.
* @param[in] pInputLine the input URC string.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t Cellular_CommonUrcProcessCereg( CellularContext_t * pContext,
char * pInputLine );
/**
* @brief 3GPP URC AT+CGREG handler for FreeRTOS Cellular Library.
*
* This function handles the incoming URC and callback function.
*
* @param[in,out] pContext FreeRTOS Cellular Library context created in Cellular_Init.
* @param[in] pInputLine the input URC string.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t Cellular_CommonUrcProcessCgreg( CellularContext_t * pContext,
char * pInputLine );
/**
* @brief 3GPP URC AT+CREG handler for FreeRTOS Cellular Library.
*
* This function handles the incoming URC and callback function.
*
* @param[in,out] pContext FreeRTOS Cellular Library context created in Cellular_Init.
* @param[in] pInputLine the input URC string.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t Cellular_CommonUrcProcessCreg( CellularContext_t * pContext,
char * pInputLine );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* __CELLULAR_COMMON_API_H__ */

View File

@ -0,0 +1,100 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @file cellular_common_portable.h
*/
#ifndef __CELLULAR_COMMON_PORTABLE_H__
#define __CELLULAR_COMMON_PORTABLE_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#include <stdint.h>
#include "cellular_common.h"
/*-----------------------------------------------------------*/
/**
* @brief Cellular module init function.
*
* This function is called in Cellular_CommonInit to setup cellular module context.
*
* @param[in,out] pContext FreeRTOS Cellular Library context created in Cellular_Init.
* @param[in] ppModuleContext Cellular module context can be obtained with _Cellular_GetModuleContext.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_ModuleInit( const CellularContext_t * pContext,
void ** ppModuleContext );
/**
* @brief Cellular module cleanup function.
*
* This function cleans up the module context.
*
* @param[in,out] pContext FreeRTOS Cellular Library context created in Cellular_Init.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_ModuleCleanUp( const CellularContext_t * pContext );
/**
* @brief Cellular module user equipment setup function.
*
* This function setups the user equipment of the cellular module.
*
* @param[in,out] pContext FreeRTOS Cellular Library context created in Cellular_Init.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_ModuleEnableUE( CellularContext_t * pContext );
/**
* @brief Cellular module URC enable function.
*
* This function enable the unsolicited result code of the cellular module.
*
* @param[in,out] pContext FreeRTOS Cellular Library context created in Cellular_Init.
*
* @return CELLULAR_SUCCESS if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularError_t Cellular_ModuleEnableUrc( CellularContext_t * pContext );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* End of __CELLULAR_COMMON_PORTABLE_H__. */

View File

@ -0,0 +1,234 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
#ifndef __CELLULAR_COMMON_INTERNAL_H__
#define __CELLULAR_COMMON_INTERNAL_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* Cellular includes. */
#include "cellular_platform.h"
#include "cellular_pkthandler_internal.h"
#include "cellular_at_core.h"
#include "cellular_pktio_internal.h"
/*-----------------------------------------------------------*/
#define PKTIO_READ_BUFFER_SIZE ( 1600U ) /* This should be larger than TCP packet size. */
#define PKTIO_WRITE_BUFFER_SIZE ( CELLULAR_AT_CMD_MAX_SIZE )
/*-----------------------------------------------------------*/
/**
* @brief Cellular network register URC type.
*/
typedef enum CellularNetworkRegType
{
CELLULAR_REG_TYPE_CREG = 0,
CELLULAR_REG_TYPE_CGREG,
CELLULAR_REG_TYPE_CEREG,
CELLULAR_REG_TYPE_MAX,
CELLULAR_REG_TYPE_UNKNOWN
} CellularNetworkRegType_t;
/**
* @brief Represents different URC event callback registration function.
*/
typedef struct _callbackEvents
{
CellularUrcNetworkRegistrationCallback_t networkRegistrationCallback;
void * pNetworkRegistrationCallbackContext;
CellularUrcPdnEventCallback_t pdnEventCallback;
void * pPdnEventCallbackContext;
CellularUrcSignalStrengthChangedCallback_t signalStrengthChangedCallback;
void * pSignalStrengthChangedCallbackContext;
CellularUrcGenericCallback_t genericCallback;
void * pGenericCallbackContext;
CellularModemEventCallback_t modemEventCallback;
void * pModemEventCallbackContext;
} _callbackEvents_t;
/**
* @brief Structure containing all the control plane parameters of Modem.
*/
typedef struct cellularAtData
{
CellularRat_t rat; /* Device registered Radio Access Technology (Cat-M, Cat-NB, GPRS etc). */
CellularNetworkRegistrationStatus_t csRegStatus; /* CS (Circuit Switched) registration status (registered/searching/roaming etc.). */
CellularNetworkRegistrationStatus_t psRegStatus; /* PS (Packet Switched) registration status (registered/searching/roaming etc.). */
uint8_t csRejectType; /* CS Reject Type. 0 - 3GPP specific Reject Cause. 1 - Manufacture specific. */
uint8_t csRejCause; /* Circuit Switch Reject cause. */
uint8_t psRejectType; /* PS Reject Type. 0 - 3GPP specific Reject Cause. 1 - Manufacture specific. */
uint8_t psRejCause; /* Packet Switch Reject cause. */
uint32_t cellId; /* Registered network operator cell Id. */
uint16_t lac; /* Registered network operator Location Area Code. */
uint16_t rac; /* Registered network operator Routing Area Code. */
uint16_t tac; /* Registered network operator Tracking Area Code. */
} cellularAtData_t;
/**
* @brief Parameters involved in maintaining the context for the modem.
*/
struct CellularContext
{
/* Communication interface for target specific. */
const CellularCommInterface_t * pCommIntf;
/* Common library. */
bool bLibOpened; /* CellularLib is currently open */
bool bLibShutdown; /* CellularLib prematurely shut down */
bool bLibClosing; /* Graceful shutdown in progress */
PlatformMutex_t libStatusMutex;
PlatformMutex_t libAtDataMutex;
_callbackEvents_t cbEvents; /* Call back functions registered to report events. */
cellularAtData_t libAtData; /* Global variables. */
/* Token table to config pkthandler and pktio. */
CellularTokenTable_t tokenTable;
/* Packet handler. */
PlatformMutex_t pktRequestMutex; /* The mutex for sending request. */
PlatformMutex_t PktRespMutex; /* The mutex for parsing the response from modem. */
QueueHandle_t pktRespQueue;
CellularATCommandResponseReceivedCallback_t pktRespCB;
CellularATCommandDataPrefixCallback_t pktDataPrefixCB; /* Data prefix callback function for socket receive function. */
void * pDataPrefixCBContext; /* The pCallbackContext passed to CellularATCommandDataPrefixCallback_t. */
CellularATCommandDataSendPrefixCallback_t pktDataSendPrefixCB; /* Data prefix callback function for socket send function. */
void * pDataSendPrefixCBContext; /* The pCallbackContext passed to CellularATCommandDataSendPrefixCallback_t. */
void * pPktUsrData; /* The pData passed to CellularATCommandResponseReceivedCallback_t. */
uint16_t PktUsrDataLen; /* The dataLen passed to CellularATCommandResponseReceivedCallback_t. */
const char * pCurrentCmd; /* Debug purpose. */
/* Packet IO. */
bool bPktioUp;
CellularCommInterfaceHandle_t hPktioCommIntf;
PlatformEventGroupHandle_t pPktioCommEvent;
_pPktioShutdownCallback_t pPktioShutdownCB;
_pPktioHandlePacketCallback_t pPktioHandlepktCB;
char pktioSendBuf[ PKTIO_WRITE_BUFFER_SIZE + 1 ];
char pktioReadBuf[ PKTIO_READ_BUFFER_SIZE + 1 ];
char * pPktioReadPtr;
const char * pRespPrefix;
char pktRespPrefixBuf[ CELLULAR_CONFIG_MAX_PREFIX_STRING_LENGTH ];
CellularATCommandType_t PktioAtCmdType;
_atRespType_t recvdMsgType;
CellularUndefinedRespCallback_t undefinedRespCallback;
void * pUndefinedRespCBContext;
/* PktIo data handling. */
uint32_t dataLength;
uint32_t partialDataRcvdLen;
/* Socket. */
CellularSocketContext_t * pSocketData[ CELLULAR_NUM_SOCKET_MAX ]; /* All socket related information. */
/* Module Context. */
void * pModueContext;
};
/*-----------------------------------------------------------*/
/**
* @brief Netwrok registration respone parsing function.
*
* Parse the network registration response from AT command response or URC.
* The result is stored in the pContext.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] pRegPayload The input string from AT command respnose or URC.
* @param[in] isUrc The input string source type.
* @param[in] regType The network registration type.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext,
char * pRegPayload,
bool isUrc,
CellularNetworkRegType_t regType );
/**
* @brief Initializes the AT data structures.
*
* Function is invokes to initialize the AT data structure during
* very first initialization, upon deregistration and upon receiving
* network reject during registration.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] mode Parameter that identifies which elements in Data Structure
* to be initialized.
*/
void _Cellular_InitAtData( CellularContext_t * pContext,
uint32_t mode );
/**
* @brief Create the AT data mutex.
*
* Create the mutex for AT data in cellular context.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*/
bool _Cellular_CreateAtDataMutex( CellularContext_t * pContext );
/**
* @brief Destroy the AT data mutex.
*
* Destroy the mutex for AT data in cellular context.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*
*/
void _Cellular_DestroyAtDataMutex( CellularContext_t * pContext );
/**
* @brief Lock the AT data mutex.
*
* Lock the mutex for AT data in cellular context.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*/
void _Cellular_LockAtDataMutex( CellularContext_t * pContext );
/**
* @brief Unlock the AT data mutex.
*
* Unlock the mutex for AT data in cellular context.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*/
void _Cellular_UnlockAtDataMutex( CellularContext_t * pContext );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* ifndef __CELLULAR_COMMON_INTERNAL_H__ */

View File

@ -0,0 +1,43 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
#ifndef __CELLULAR_INTERNAL_H__
#define __CELLULAR_INTERNAL_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#include "cellular_platform.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* __CELLULAR_INTERNAL_H__ */

View File

@ -0,0 +1,157 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
#ifndef __CELLULAR_PKTHANDLER_INTERNAL_H__
#define __CELLULAR_PKTHANDLER_INTERNAL_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#ifndef CELLULAR_DO_NOT_USE_CUSTOM_CONFIG
/* Include custom config file before other headers. */
#include "cellular_config.h"
#endif
#include "cellular_config_defaults.h"
#include "cellular_types.h"
#include "cellular_common.h"
#include "cellular_pktio_internal.h"
/*-----------------------------------------------------------*/
/* AT Command timeout for general AT commands. */
#define PACKET_REQ_TIMEOUT_MS CELLULAR_COMMON_AT_COMMAND_TIMEOUT_MS
/*-----------------------------------------------------------*/
/**
* @brief Create the packet request mutex.
*
* Create the mutex for packet rquest in cellular context.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*/
bool _Cellular_CreatePktRequestMutex( CellularContext_t * pContext );
/**
* @brief Destroy the packet request mutex.
*
* Destroy the mutex for packet rquest in cellular context.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*/
void _Cellular_DestroyPktRequestMutex( CellularContext_t * pContext );
/**
* @brief Create the packet response mutex.
*
* Create the mutex for packet response in cellular context.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*/
bool _Cellular_CreatePktResponseMutex( CellularContext_t * pContext );
/**
* @brief Destroy the packet response mutex.
*
* Destroy the mutex for packet response in cellular context.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*/
void _Cellular_DestroyPktResponseMutex( CellularContext_t * pContext );
/**
* @brief Packet handler init function.
*
* This function init the packet handler in FreeRTOS Cellular Library common.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_PktHandlerInit( CellularContext_t * pContext );
/**
* @brief Packet handler cleanup function.
*
* This function cleanup the pakcet handler in FreeRTOS Cellular Library common.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*/
void _Cellular_PktHandlerCleanup( CellularContext_t * pContext );
/**
* @brief Packet handler function.
*
* This function is the callback function of packet handler. It is called by packet IO thread.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] atRespType The AT response type from packet IO.
* @param[in] pBuf The input data buffer from packet IO.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_HandlePacket( CellularContext_t * pContext,
_atRespType_t atRespType,
const void * pBuf );
/**
* @brief The URC handler init function.
*
* This function setup the URC handler table query function.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_AtParseInit( const CellularContext_t * pContext );
/**
* @brief Wrapper for sending the AT command to cellular modem.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] atReq The AT command data structure with send command response callback.
* @param[in] timeoutMS The timeout value to wait for the response from cellular modem.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_PktHandler_AtcmdRequestWithCallback( CellularContext_t * pContext,
CellularAtReq_t atReq,
uint32_t timeoutMS );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* __CELLULAR_PKTHANDLER_INTERNAL_H__ */

View File

@ -0,0 +1,142 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
#ifndef __CELLULAR_PKTIO_INTERNAL_H__
#define __CELLULAR_PKTIO_INTERNAL_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#ifndef CELLULAR_DO_NOT_USE_CUSTOM_CONFIG
/* Include custom config file before other headers. */
#include "cellular_config.h"
#endif
#include "cellular_config_defaults.h"
#include "cellular_types.h"
/*-----------------------------------------------------------*/
/**
* @brief The received AT response type.
*/
typedef enum _atRespType
{
AT_SOLICITED = 0,
AT_UNSOLICITED,
AT_UNDEFINED
} _atRespType_t;
/**
* @brief Callback used to inform packet received.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] atRespType The received packet type.
* @param[in] pBuf The input data buffer from packet IO.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
typedef CellularPktStatus_t ( * _pPktioHandlePacketCallback_t ) ( CellularContext_t * pContext,
_atRespType_t atRespType,
const void * pBuffer );
/**
* @brief Callback used to inform packet IO thread shutdown.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*/
typedef void ( * _pPktioShutdownCallback_t ) ( CellularContext_t * pContext );
/*-----------------------------------------------------------*/
/**
* @brief Packet IO init function.
*
* This function init the packet IO in FreeRTOS Cellular Library common.
* Packet IO thread is created in this function.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] handlePacketCb The callback function to handle the packet received.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_PktioInit( CellularContext_t * pContext,
_pPktioHandlePacketCallback_t handlePacketCb );
/**
* @brief Packet IO shutdown function.
*
* This function shutdown the packet IO in FreeRTOS Cellular Library common.
* Packet IO thread is shutdown in this function.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
*/
void _Cellular_PktioShutdown( CellularContext_t * pContext );
/**
* @brief Send AT command function.
*
* This function setup the internal data of pktio and send the AT command through comm interface.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] pAtCmd The AT command to send.
* @param[in] atType The AT command type.
* @param[in] pAtRspPrefix The AT command response prefix.
*
* @return CELLULAR_PKT_STATUS_OK if the operation is successful, otherwise an error
* code indicating the cause of the error.
*/
CellularPktStatus_t _Cellular_PktioSendAtCmd( CellularContext_t * pContext,
const char * pAtCmd,
CellularATCommandType_t atType,
const char * pAtRspPrefix );
/**
* @brief Send data command function.
*
* This function setup the internal data of pktio and send the data through comm interface.
*
* @param[in] pContext The opaque cellular context pointer created by Cellular_Init.
* @param[in] pData The data to send.
* @param[in] dataLen The data length of pData.
*
* @return The data actually send to the comm interface.
*/
uint32_t _Cellular_PktioSendData( CellularContext_t * pContext,
const uint8_t * pData,
uint32_t dataLen );
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* __CELLULAR_PKTIO_INTERNAL_H__ */

View File

@ -0,0 +1,171 @@
/*
* FreeRTOS-Cellular-Interface v1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*/
/**
* @file cellular_comm_interface.h
*/
#ifndef __CELLULAR_COMM_INTERFACE_H__
#define __CELLULAR_COMM_INTERFACE_H__
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
#include "cellular_types.h"
/* Standard includes. */
#include <stdint.h>
/**
* @brief Return codes from various APIs.
*/
typedef enum CellularCommInterfaceError
{
IOT_COMM_INTERFACE_SUCCESS = 0, /**< Function successfully completed. */
IOT_COMM_INTERFACE_FAILURE, /**< Generic failure not covered by other values. */
IOT_COMM_INTERFACE_BAD_PARAMETER, /**< At least one parameter was invalid. */
IOT_COMM_INTERFACE_NO_MEMORY, /**< Memory allocation failed. */
IOT_COMM_INTERFACE_TIMEOUT, /**< Operation timed out. */
IOT_COMM_INTERFACE_DRIVER_ERROR, /**< An error occurred when calling a low level driver API. */
IOT_COMM_INTERFACE_BUSY /**< The interface is currently busy. */
} CellularCommInterfaceError_t;
struct CellularCommInterfaceContext;
/**
* @brief Opaque handle to comm interface.
*/
typedef struct CellularCommInterfaceContext * CellularCommInterfaceHandle_t;
/**
* @brief Provide an asynchronous notification of incoming data.
*
* A function of this signature is supplied in CellularCommInterfaceOpen_t and is
* used to notify whenever data is available for reading on the comm interface.
*
* @param[in] pUserData Userdata to be provided in the callback.
* @param[in] commInterfaceHandle Handle corresponding to the comm interface.
*
* @return IOT_COMM_INTERFACE_SUCCESS if the operation is successful, and need to yield from ISR
* IOT_COMM_INTERFACE_BUSY if the operation is successful,
* otherwise an error code indicating the cause of the error.
*/
typedef CellularCommInterfaceError_t ( * CellularCommInterfaceReceiveCallback_t )( void * pUserData,
CellularCommInterfaceHandle_t commInterfaceHandle );
/**
* @brief Open a connection to the comm interface.
*
* @param[in] receiveCallback Callback to be invoked whenever there is data
* available for reading from the comm interface.
* @param[in] pUserData Userdata to be provided in the callback.
* @param[out] pCommInterfaceHandle Out parameter to provide the comm interface
* handle.
*
* @return IOT_COMM_INTERFACE_SUCCESS if the operation is successful, otherwise
* an error code indicating the cause of the error.
*/
typedef CellularCommInterfaceError_t ( * CellularCommInterfaceOpen_t )( CellularCommInterfaceReceiveCallback_t receiveCallback,
void * pUserData,
CellularCommInterfaceHandle_t * pCommInterfaceHandle );
/**
* @brief Send data to the comm interface.
*
* @param[in] commInterfaceHandle Comm interface handle as returned from the
* CellularCommInterfaceOpen_t call.
* @param[in] pData The data to send.
* @param[in] dataLength Length of the data to send.
* @param[in] timeoutMilliseconds Timeout in milliseconds for the send operation.
* @param[out] pDataSentLength Out parameter to provide the length of the actual
* data sent. Note that it may be less than the dataLength in case complete data
* could not be sent.
*
* @return IOT_COMM_INTERFACE_SUCCESS if the operation is successful, otherwise
* an error code indicating the cause of the error.
*/
typedef CellularCommInterfaceError_t ( * CellularCommInterfaceSend_t )( CellularCommInterfaceHandle_t commInterfaceHandle,
const uint8_t * pData,
uint32_t dataLength,
uint32_t timeoutMilliseconds,
uint32_t * pDataSentLength );
/**
* @brief Receive data from the comm interface.
*
* @param[in] commInterfaceHandle Comm interface handle as returned from the
* CellularCommInterfaceOpen_t call.
* @param[in] pBuffer The buffer to receive the data into.
* @param[in] bufferLength The length of the buffer pBuffer.
* @param[in] timeoutMilliseconds Timeout in milliseconds for the receive
* operation.
* @param[out] pDataReceivedLength Out parameter to provide the length of the
* actual data received in the buffer pBuffer. Note that it may be less than
* the bufferLength.
*
* @return IOT_COMM_INTERFACE_SUCCESS if the operation is successful, otherwise
* an error code indicating the cause of the error.
*/
typedef CellularCommInterfaceError_t ( * CellularCommInterfaceRecv_t )( CellularCommInterfaceHandle_t commInterfaceHandle,
uint8_t * pBuffer,
uint32_t bufferLength,
uint32_t timeoutMilliseconds,
uint32_t * pDataReceivedLength );
/**
* @brief Close the connection to the comm interface.
*
* @param[in] commInterfaceHandle Comm interface handle as returned from the
* CellularCommInterfaceOpen_t call.
*
* @return IOT_COMM_INTERFACE_SUCCESS if the operation is successful, otherwise
* an error code indicating the cause of the error.
*/
typedef CellularCommInterfaceError_t ( * CellularCommInterfaceClose_t )( CellularCommInterfaceHandle_t commInterfaceHandle );
/**
* @brief Represents the functions of a comm interface.
*
* Functions of these signature should be implemented against a comm interface
* (like UART, SPI etc.).
*/
typedef struct CellularCommInterface
{
CellularCommInterfaceOpen_t open; /**< Cellular communication open interface. */
CellularCommInterfaceSend_t send; /**< Cellular communication send interface. */
CellularCommInterfaceRecv_t recv; /**< Cellular communication recv interface. */
CellularCommInterfaceClose_t close; /**< Cellular communication close interface. */
} CellularCommInterface_t;
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* __CELLULAR_COMM_INTERFACE_H__ */