Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
210a55c
Update cellular library to MIT license
chinglee-iot Mar 29, 2021
298ae4c
Merge branch 'FreeRTOS:main' into main
chinglee-iot Jun 30, 2021
21ea9bc
Merge branch 'FreeRTOS:main' into main
chinglee-iot Jul 16, 2021
6690f3b
Merge branch 'FreeRTOS:main' into main
chinglee-iot Jul 23, 2021
4a58d89
Merge branch 'FreeRTOS:main' into main
chinglee-iot Aug 24, 2021
955ebc0
Merge branch 'FreeRTOS:main' into main
chinglee-iot Oct 25, 2021
bba8adf
Merge branch 'FreeRTOS:main' into main
chinglee-iot Nov 4, 2021
440bec9
Merge branch 'FreeRTOS:main' into main
chinglee-iot Nov 9, 2021
a0fb7c7
Merge branch 'FreeRTOS:main' into main
chinglee-iot Nov 16, 2021
b28ed63
Merge branch 'FreeRTOS:main' into main
chinglee-iot Nov 24, 2021
b40cb10
Merge branch 'FreeRTOS:main' into main
chinglee-iot Dec 1, 2021
ca024c6
Merge branch 'FreeRTOS:main' into main
chinglee-iot Dec 1, 2021
277d8b7
Merge branch 'FreeRTOS:main' into main
chinglee-iot Dec 15, 2021
06402e9
Merge branch 'FreeRTOS:main' into main
chinglee-iot Dec 21, 2021
a993410
Merge branch 'FreeRTOS:main' into main
chinglee-iot Dec 21, 2021
45b9bcd
Merge branch 'FreeRTOS:main' into main
chinglee-iot Dec 27, 2021
cacbf87
Merge branch 'FreeRTOS:main' into main
chinglee-iot Jan 6, 2022
128407c
Merge branch 'FreeRTOS:main' into main
chinglee-iot Jan 7, 2022
b1e3e46
Merge branch 'FreeRTOS:main' into main
chinglee-iot Jan 10, 2022
70e76c4
Merge branch 'FreeRTOS:main' into main
chinglee-iot Jan 11, 2022
107896c
Merge branch 'FreeRTOS:main' into main
chinglee-iot Feb 7, 2022
b3f4fab
Merge branch 'FreeRTOS:main' into main
chinglee-iot Mar 15, 2022
5027c96
Merge branch 'FreeRTOS:main' into main
chinglee-iot Apr 27, 2022
61f5c46
Merge branch 'FreeRTOS:main' into main
chinglee-iot May 11, 2022
14cb0e7
Merge branch 'FreeRTOS:main' into main
chinglee-iot Jun 7, 2022
e11d62e
Handle network registration URC received in SRC
chinglee-iot Jun 7, 2022
d29ac57
Update lexicon format and test cases
chinglee-iot Jun 7, 2022
6be2b33
Fix spell size and test cases
chinglee-iot Jun 7, 2022
a79a2bf
Move regType outside of the loop
chinglee-iot Jun 8, 2022
3f8b356
Fix format
chinglee-iot Jun 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/doxygen/include/size_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</tr>
<tr>
<td>cellular_3gpp_api.c</td>
<td><center>6.3K</center></td>
<td><center>5.8K</center></td>
<td><center>6.4K</center></td>
<td><center>5.9K</center></td>
</tr>
<tr>
<td>cellular_3gpp_urc_handler.c</td>
Expand Down Expand Up @@ -44,7 +44,7 @@
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>14.1K</center></b></td>
<td><b><center>12.8K</center></b></td>
<td><b><center>14.2K</center></b></td>
<td><b><center>12.9K</center></b></td>
</tr>
</table>
5 changes: 5 additions & 0 deletions lexicon.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
accessmode
activatepdn
activetimevalue
actstatus
af
aka
api
Expand Down Expand Up @@ -142,6 +143,7 @@ checkcrsmmemorystatus
checkcrsmreadstatus
checklibrarystatus
chk
ci
ciev
clearbits
closedcallback
Expand Down Expand Up @@ -283,6 +285,7 @@ eventgrouphandle
evt
fasle
ff
fffe
ffffff
findlineinstream
firmwareversion
Expand Down Expand Up @@ -726,6 +729,7 @@ sendtimeoutms
sensorhub
seperator
serialnumber
servicestatus
sessionid
setbits
setbitsfromisr
Expand Down Expand Up @@ -768,6 +772,7 @@ src
stacksize
stanard
standalone
stat
staticqueue
staticsemaphore
stm
Expand Down
73 changes: 68 additions & 5 deletions source/cellular_3gpp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ static CellularPktStatus_t _Cellular_RecvFuncGetManufactureId( CellularContext_t
const CellularATCommandResponse_t * pAtResp,
void * pData,
uint16_t dataLen );
static bool regResponseIsUrc( char * pRegLine );
static CellularPktStatus_t _Cellular_RecvFuncGetNetworkReg( CellularContext_t * pContext,
const CellularATCommandResponse_t * pAtResp,
void * pData,
Expand Down Expand Up @@ -738,6 +739,50 @@ static CellularPktStatus_t _Cellular_RecvFuncGetManufactureId( CellularContext_t

/*-----------------------------------------------------------*/


static bool regResponseIsUrc( char * pRegLine )
{
bool isUrcResponse = false;
char * pSeparator = NULL;

/* CREG, CEREG, CGREG has the same prefix for AT command response and URC.
* There will be cases that the URC code is regarded as AT command response.
* The response content can be used to distinguish them.
*
* Take AT+CREG for example, CREG has the following response format.
* Read response : +CREG: <n>,<stat>[,<lac>,<ci>[,<AcTStatus>]]
* URC : +CREG: <stat>[,[<lac>],[<ci>][,[<AcTStatus>][,<cause_type>, <reject_cause>]]]
*
* Not registered searching response:
* Read response : +CREG: 2,2
* URC : +CREG: 2
*
* Registered, home network response
* Read response : +CREG: 2,1,"FFFE","341B50D",8
* URC : +CREG: 1,"FFFE","341B50D", 8
*/
pSeparator = strstr( pRegLine, "," );

if( pSeparator == NULL )
{
/* Not registered searching response case. */
isUrcResponse = true;
}
else if( pSeparator[ 1 ] == '"' )
{
/* Registered case, the second token start with '"' */
isUrcResponse = true;
}
else
{
isUrcResponse = false;
}

return isUrcResponse;
}

/*-----------------------------------------------------------*/

static CellularPktStatus_t _Cellular_RecvFuncGetNetworkReg( CellularContext_t * pContext,
const CellularATCommandResponse_t * pAtResp,
void * pData,
Expand All @@ -747,6 +792,7 @@ static CellularPktStatus_t _Cellular_RecvFuncGetNetworkReg( CellularContext_t *
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
CellularATError_t atCoreStatus = CELLULAR_AT_SUCCESS;
CellularNetworkRegType_t regType = CELLULAR_REG_TYPE_UNKNOWN;
CellularATCommandLine_t * pCommandLine = NULL;

if( pContext == NULL )
{
Expand All @@ -764,17 +810,34 @@ static CellularPktStatus_t _Cellular_RecvFuncGetNetworkReg( CellularContext_t *
}
else
{
pCommandLine = pAtResp->pItm;
regType = *( ( CellularNetworkRegType_t * ) pData );
pPregLine = pAtResp->pItm->pLine;
atCoreStatus = Cellular_ATRemoveLeadingWhiteSpaces( &pPregLine );
pktStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus );

if( pktStatus == CELLULAR_PKT_STATUS_OK )
while( ( pCommandLine != NULL ) && ( pktStatus == CELLULAR_PKT_STATUS_OK ) )
{
pPregLine = pCommandLine->pLine;

/* Assumption is that the data is null terminated so we don't need the dataLen. */
_Cellular_LockAtDataMutex( pContext );
pktStatus = _Cellular_ParseRegStatus( pContext, pPregLine, false, regType );

if( regResponseIsUrc( pPregLine ) == true )
{
/* Remove the prefix for URC handler. */
atCoreStatus = Cellular_ATRemovePrefix( &pPregLine );
pktStatus = _Cellular_TranslateAtCoreStatus( atCoreStatus );

if( pktStatus == CELLULAR_PKT_STATUS_OK )
{
pktStatus = _Cellular_ParseRegStatus( pContext, pPregLine, true, regType );
}
}
else
{
pktStatus = _Cellular_ParseRegStatus( pContext, pPregLine, false, regType );
}

_Cellular_UnlockAtDataMutex( pContext );
pCommandLine = pCommandLine->pNext;
}

LogDebug( ( "atcmd network register status %d pktStatus:%d", regType, pktStatus ) );
Expand Down
151 changes: 147 additions & 4 deletions test/unit-test/cellular_3gpp_api_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,27 @@
/**
* @brief Cellular sample prefix string input.
*/
#define CELLULAR_SAMPLE_PREFIX_STRING_INPUT "+CPIN:READY"
#define CELLULAR_SAMPLE_PREFIX_STRING_INPUT "+CPIN:READY"

/**
* @brief Cellular sample network registration URC not registered.
*/
#define CELLULAR_SAMPLE_NETWORK_REGISTRATION_RESPONSE "+CREG: 2,2"

/**
* @brief Cellular sample network registration URC not registered.
*/
#define CELLULAR_SAMPLE_NETWORK_REGISTRATION_URC_NOT_REGISTERED "+CREG: 2"

/**
* @brief Cellular sample network registration URC registered.
*/
#define CELLULAR_SAMPLE_NETWORK_REGISTRATION_URC_REGISTERED "+CREG: 1,\"FFFE\",\"341B50D\", 8"

/**
* @brief Cellular sample prefix string output.
*/
#define CELLULAR_SAMPLE_PREFIX_STRING_OUTPUT "READY"
#define CELLULAR_SAMPLE_PREFIX_STRING_OUTPUT "READY"

/**
* @brief operator information.
Expand Down Expand Up @@ -586,6 +601,29 @@ CellularPktStatus_t Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetNetworkRe
_saveData( pLine, &atResp, strlen( pLine ) + 1 );
pktStatus = atReq.respCallback( pContext, &atResp, pData, sizeof( pData ) );
}
else if( cbCondition == 4 )
{
char pLine[] = CELLULAR_SAMPLE_NETWORK_REGISTRATION_URC_NOT_REGISTERED;

_saveData( pLine, &atResp, strlen( pLine ) + 1 );
pktStatus = atReq.respCallback( pContext, &atResp, pData, sizeof( pData ) );
}
else if( cbCondition == 5 )
{
char pLine[] = CELLULAR_SAMPLE_NETWORK_REGISTRATION_URC_REGISTERED;

_saveData( pLine, &atResp, strlen( pLine ) + 1 );
pktStatus = atReq.respCallback( pContext, &atResp, pData, sizeof( pData ) );
}
else if( cbCondition == 6 )
{
char pLine[] = CELLULAR_SAMPLE_NETWORK_REGISTRATION_RESPONSE;
char pLine2[] = CELLULAR_SAMPLE_NETWORK_REGISTRATION_URC_REGISTERED;

_saveData( pLine, &atResp, strlen( pLine ) + 1 );
_saveData( pLine2, &atResp, strlen( pLine2 ) + 1 );
pktStatus = atReq.respCallback( pContext, &atResp, pData, sizeof( pData ) );
}
}

return pktStatus;
Expand Down Expand Up @@ -3030,7 +3068,7 @@ void test_Cellular_CommonGetServiceStatus_Cb__Cellular_RecvFuncGetNetworkReg_AtC
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetNetworkReg );
_Cellular_TranslatePktStatus_ExpectAndReturn( CELLULAR_PKT_STATUS_INVALID_HANDLE, CELLULAR_INTERNAL_FAILURE );

Cellular_ATRemoveLeadingWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_ERROR );
Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_ERROR );
_Cellular_TranslateAtCoreStatus_IgnoreAndReturn( CELLULAR_PKT_STATUS_FAILURE );

/* called by atcmdUpdateMccMnc. */
Expand Down Expand Up @@ -3060,7 +3098,7 @@ void test_Cellular_CommonGetServiceStatus_Cb__Cellular_RecvFuncGetNetworkReg_Hap
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetNetworkReg );
_Cellular_TranslatePktStatus_ExpectAndReturn( CELLULAR_PKT_STATUS_INVALID_HANDLE, CELLULAR_INTERNAL_FAILURE );

Cellular_ATRemoveLeadingWhiteSpaces_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
_Cellular_TranslateAtCoreStatus_IgnoreAndReturn( CELLULAR_PKT_STATUS_OK );
/* _Cellular_ParseRegStatus */
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_BAD_PARAMETER );
Expand All @@ -3074,6 +3112,111 @@ void test_Cellular_CommonGetServiceStatus_Cb__Cellular_RecvFuncGetNetworkReg_Hap
TEST_ASSERT_EQUAL( CELLULAR_SUCCESS, cellularStatus );
}

/**
* @brief Test that_Cellular_ParseRegStatus return error in callback function _Cellular_RecvFuncGetNetworkReg
* for Cellular_CommonGetServiceStatus to return CELLULAR_SUCCESS.
*/
void test_Cellular_CommonGetServiceStatus_Cb__Cellular_RecvFuncGetNetworkReg_Parse_Error( void )
{
CellularError_t cellularStatus = CELLULAR_SUCCESS;
CellularContext_t context;

memset( &context, 0, sizeof( CellularContext_t ) );
CellularHandle_t cellularHandle = &context;
CellularServiceStatus_t serviceStatus;

_Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS );

/* called by atcmdQueryRegStatus -> queryNetworkStatus for CREG. */
cbCondition = 6;
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetNetworkReg );
_Cellular_TranslatePktStatus_ExpectAndReturn( CELLULAR_PKT_STATUS_INVALID_HANDLE, CELLULAR_INTERNAL_FAILURE );

/* Return error in _Cellular_ParseRegStatus. */
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_BAD_PARAMETER );
_Cellular_TranslateAtCoreStatus_IgnoreAndReturn( CELLULAR_PKT_STATUS_INVALID_HANDLE );
_Cellular_NetworkRegistrationCallback_Ignore();

/* called by atcmdUpdateMccMnc. */
_Cellular_TranslatePktStatus_IgnoreAndReturn( CELLULAR_SUCCESS );

/* The serviceStatus is updated and verified in cellular_3gpp_urc_handler.c test cases. */
cellularStatus = Cellular_CommonGetServiceStatus( cellularHandle, &serviceStatus );
TEST_ASSERT_EQUAL( CELLULAR_SUCCESS, cellularStatus );
}

/**
* @brief Test that network not registered URC is received in callback function
* _Cellular_RecvFuncGetNetworkReg for Cellular_CommonGetServiceStatus to return CELLULAR_SUCCESS.
*/
void test_Cellular_CommonGetServiceStatus_Cb__Cellular_RecvFuncGetNetworkReg_URC_not_registered( void )
{
CellularError_t cellularStatus = CELLULAR_SUCCESS;
CellularContext_t context;

memset( &context, 0, sizeof( CellularContext_t ) );
CellularHandle_t cellularHandle = &context;
CellularServiceStatus_t serviceStatus;

_Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS );

/* called by atcmdQueryRegStatus -> queryNetworkStatus for +CREG:2. */
cbCondition = 4;
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetNetworkReg );
_Cellular_TranslatePktStatus_ExpectAndReturn( CELLULAR_PKT_STATUS_INVALID_HANDLE, CELLULAR_INTERNAL_FAILURE );

Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
_Cellular_TranslateAtCoreStatus_IgnoreAndReturn( CELLULAR_PKT_STATUS_INVALID_HANDLE );

/* _Cellular_ParseRegStatus */
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_BAD_PARAMETER );
_Cellular_TranslateAtCoreStatus_IgnoreAndReturn( CELLULAR_PKT_STATUS_INVALID_HANDLE );
_Cellular_NetworkRegistrationCallback_Ignore();

/* called by atcmdUpdateMccMnc. */
_Cellular_TranslatePktStatus_IgnoreAndReturn( CELLULAR_SUCCESS );

/* The serviceStatus is updated and verified in cellular_3gpp_urc_handler.c test cases. */
cellularStatus = Cellular_CommonGetServiceStatus( cellularHandle, &serviceStatus );
TEST_ASSERT_EQUAL( CELLULAR_SUCCESS, cellularStatus );
}

/**
* @brief Test that network registered URC is received in callback function
* _Cellular_RecvFuncGetNetworkReg for Cellular_CommonGetServiceStatus to return CELLULAR_SUCCESS.
*/
void test_Cellular_CommonGetServiceStatus_Cb__Cellular_RecvFuncGetNetworkReg_URC_registered( void )
{
CellularError_t cellularStatus = CELLULAR_SUCCESS;
CellularContext_t context;

memset( &context, 0, sizeof( CellularContext_t ) );
CellularHandle_t cellularHandle = &context;
CellularServiceStatus_t serviceStatus;

_Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS );

/* called by atcmdQueryRegStatus -> queryNetworkStatus for +CREG:2. */
cbCondition = 5;
_Cellular_AtcmdRequestWithCallback_StubWithCallback( Mock_AtcmdRequestWithCallback__Cellular_RecvFuncGetNetworkReg );
_Cellular_TranslatePktStatus_ExpectAndReturn( CELLULAR_PKT_STATUS_INVALID_HANDLE, CELLULAR_INTERNAL_FAILURE );

Cellular_ATRemovePrefix_IgnoreAndReturn( CELLULAR_AT_SUCCESS );
_Cellular_TranslateAtCoreStatus_IgnoreAndReturn( CELLULAR_PKT_STATUS_OK );

/* _Cellular_ParseRegStatus */
Cellular_ATRemoveAllDoubleQuote_IgnoreAndReturn( CELLULAR_AT_BAD_PARAMETER );
_Cellular_TranslateAtCoreStatus_IgnoreAndReturn( CELLULAR_PKT_STATUS_OK );
_Cellular_NetworkRegistrationCallback_Ignore();

/* called by atcmdUpdateMccMnc. */
_Cellular_TranslatePktStatus_IgnoreAndReturn( CELLULAR_SUCCESS );

/* The serviceStatus is updated and verified in cellular_3gpp_urc_handler.c test cases. */
cellularStatus = Cellular_CommonGetServiceStatus( cellularHandle, &serviceStatus );
TEST_ASSERT_EQUAL( CELLULAR_SUCCESS, cellularStatus );
}

/**
* @brief Test that wrong psRegStatus case Cellular_CommonGetServiceStatus to return CELLULAR_SUCCESS.
*/
Expand Down