FreeRTOS: FreeRTOS Cellular Library v1.4.0
FreeRTOS Cellular Library
 
Loading...
Searching...
No Matches
cellular_common.h
Go to the documentation of this file.
1/*
2 * FreeRTOS-Cellular-Interface v1.4.0
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
26 */
27
32#ifndef __CELLULAR_COMMON_H__
33#define __CELLULAR_COMMON_H__
34
35/* *INDENT-OFF* */
36#ifdef __cplusplus
37 extern "C" {
38#endif
39/* *INDENT-ON* */
40
41/* Standard includes. */
42#include <stdbool.h>
43
44/* Cellular includes. */
45#ifndef CELLULAR_DO_NOT_USE_CUSTOM_CONFIG
46 /* Include custom config file before other headers. */
47 #include "cellular_config.h"
48#endif
50#include "cellular_platform.h"
52#include "cellular_types.h"
53#include "cellular_at_core.h"
54
55/*-----------------------------------------------------------*/
56
61typedef struct CellularAtReq
62{
63 const char * pAtCmd;
65 const char * pAtRspPrefix;
67 void * pData;
68 uint16_t dataLen;
70
75typedef struct CellularAtDataReq
76{
77 const uint8_t * pData;
78 uint32_t dataLen;
79 uint32_t * pSentDataLength;
80 const uint8_t * pEndPattern;
84 uint32_t endPatternLen;
86
93typedef void ( * CellularAtParseTokenHandler_t )( CellularContext_t * pContext,
94 char * pInputStr );
95
100typedef struct CellularAtParseTokenMap
101{
102 const char * pStrValue;
105
110typedef enum CellularSocketState
111{
117
122typedef struct CellularSocketContext
123{
124 uint8_t contextId;
125 uint32_t socketId;
131 uint16_t localPort;
134 /* Set using socket options. */
135 uint32_t sendTimeoutMs;
136 uint32_t recvTimeoutMs;
138 /* Set during socket connect. */
141 /* Callback functions. */
149 /* Modem data. */
150 void * pModemData;
152
157typedef struct CellularTokenTable
158{
159 /* URC handler mapping table. */
163 /* Table to decide AT command respone status. */
169 /* Table to URC with prefix Token. */
173 /* Extra success token for specific AT command. */
177
192typedef CellularPktStatus_t ( * CellularATCommandDataPrefixCallback_t ) ( void * pCallbackContext,
193 char * pLine,
194 uint32_t lineLength,
195 char ** pDataStart,
196 uint32_t * pDataLength );
197
210 char * pLine,
211 uint32_t * pBytesRead );
212
223typedef CellularPktStatus_t ( * CellularUndefinedRespCallback_t )( void * pCallbackContext,
224 const char * pLine );
225
240typedef CellularPktStatus_t ( * CellularInputBufferCallback_t ) ( void * pInputBufferCallbackContext,
241 char * pBuffer,
242 uint32_t bufferLength,
243 uint32_t * pBufferLengthHandled );
244
245/*-----------------------------------------------------------*/
246
260CellularError_t _Cellular_LibInit( CellularHandle_t * pCellularHandle,
261 const CellularCommInterface_t * pCommInterface,
262 const CellularTokenTable_t * pTokenTable );
263
276CellularError_t _Cellular_LibCleanup( CellularHandle_t cellularHandle );
277
286void _Cellular_NetworkRegistrationCallback( const CellularContext_t * pContext,
287 CellularUrcEvent_t urcEvent,
288 const CellularServiceStatus_t * pServiceStatus );
289
298void _Cellular_PdnEventCallback( const CellularContext_t * pContext,
299 CellularUrcEvent_t urcEvent,
300 uint8_t contextId );
301
310void _Cellular_SignalStrengthChangedCallback( const CellularContext_t * pContext,
311 CellularUrcEvent_t urcEvent,
312 const CellularSignalInfo_t * pSignalInfo );
313
321void _Cellular_GenericCallback( const CellularContext_t * pContext,
322 const char * pRawData );
323
331void _Cellular_ModemEventCallback( const CellularContext_t * pContext,
332 CellularModemEvent_t modemEvent );
333
344CellularError_t _Cellular_CheckLibraryStatus( CellularContext_t * pContext );
345
356
367
381CellularError_t _Cellular_CreateSocketData( CellularContext_t * pContext,
382 uint8_t contextId,
383 CellularSocketDomain_t socketDomain,
384 CellularSocketType_t socketType,
385 CellularSocketProtocol_t socketProtocol,
386 CellularSocketHandle_t * pSocketHandle );
387
397CellularError_t _Cellular_RemoveSocketData( CellularContext_t * pContext,
398 CellularSocketHandle_t socketHandle );
399
409CellularError_t _Cellular_IsValidSocket( const CellularContext_t * pContext,
410 uint32_t sockIndex );
411
420CellularSocketContext_t * _Cellular_GetSocketData( const CellularContext_t * pContext,
421 uint32_t sockIndex );
422
431CellularError_t _Cellular_IsValidPdn( uint8_t contextId );
432
444 int16_t * pRssiValue );
445
457 int16_t * pBerValue );
458
468CellularError_t _Cellular_GetModuleContext( const CellularContext_t * pContext,
469 void ** ppModuleContext );
470
482 CellularSignalInfo_t * pSignalInfo );
483
493CellularError_t _Cellular_GetCurrentRat( CellularContext_t * pContext,
494 CellularRat_t * pRat );
495
505CellularPktStatus_t _Cellular_AtcmdRequestWithCallback( CellularContext_t * pContext,
506 CellularAtReq_t atReq );
507
519 CellularAtReq_t atReq,
520 uint32_t timeoutMS );
521
539CellularPktStatus_t _Cellular_AtcmdRequestSuccessToken( CellularContext_t * pContext,
540 CellularAtReq_t atReq,
541 uint32_t atTimeoutMS,
542 const char ** pCellularSrcTokenSuccessTable,
543 uint32_t cellularSrcTokenSuccessTableSize );
544
558 CellularAtReq_t atReq,
559 uint32_t timeoutMS,
560 CellularATCommandDataPrefixCallback_t pktDataPrefixCallback,
561 void * pCallbackContext );
562
576 CellularAtReq_t atReq,
577 CellularAtDataReq_t dataReq,
578 uint32_t atTimeoutMS,
579 uint32_t dataTimeoutMS );
580
596CellularPktStatus_t _Cellular_AtcmdDataSend( CellularContext_t * pContext,
597 CellularAtReq_t atReq,
598 CellularAtDataReq_t dataReq,
599 CellularATCommandDataSendPrefixCallback_t pktDataSendPrefixCallback,
600 void * pCallbackContext,
601 uint32_t atTimeoutMS,
602 uint32_t dataTimeoutMS,
603 uint32_t interDelayMS );
604
620 CellularAtReq_t atReq,
621 CellularAtDataReq_t dataReq,
622 uint32_t atTimeoutMS,
623 uint32_t dataTimeoutMS,
624 const char ** pCellularSrcTokenSuccessTable,
625 uint32_t cellularSrcTokenSuccessTableSize );
626
641CellularError_t _Cellular_RegisterUndefinedRespCallback( CellularContext_t * pContext,
642 CellularUndefinedRespCallback_t undefinedRespCallback,
643 void * pCallbackContext );
644
659CellularError_t _Cellular_RegisterInputBufferCallback( CellularContext_t * pContext,
660 CellularInputBufferCallback_t inputBufferCallback,
661 void * pInputBufferCallbackContext );
662
663/* *INDENT-OFF* */
664#ifdef __cplusplus
665 }
666#endif
667/* *INDENT-ON* */
668
669#endif /* __CELLULAR_COMMON_H__ */
CellularATError_t
Represents error codes returned from AT Core APIs.
Definition: cellular_at_core.h:68
void _Cellular_NetworkRegistrationCallback(const CellularContext_t *pContext, CellularUrcEvent_t urcEvent, const CellularServiceStatus_t *pServiceStatus)
Call the network registration callback if the callback is previously set by Cellular_CommonRegisterUr...
Definition: cellular_common.c:834
CellularPktStatus_t(* CellularUndefinedRespCallback_t)(void *pCallbackContext, const char *pLine)
Undefined response callback function.
Definition: cellular_common.h:223
void _Cellular_SignalStrengthChangedCallback(const CellularContext_t *pContext, CellularUrcEvent_t urcEvent, const CellularSignalInfo_t *pSignalInfo)
Call the network registration callback if the callback is previously set by Cellular_RegisterUrcSigna...
Definition: cellular_common.c:859
CellularError_t _Cellular_RegisterUndefinedRespCallback(CellularContext_t *pContext, CellularUndefinedRespCallback_t undefinedRespCallback, void *pCallbackContext)
Register undefined response callback.
Definition: cellular_common.c:1095
CellularError_t _Cellular_TranslatePktStatus(CellularPktStatus_t status)
Translate error code packet status to cellular Status.
Definition: cellular_common.c:463
CellularPktStatus_t _Cellular_TimeoutAtcmdDataSendRequestWithCallback(CellularContext_t *pContext, CellularAtReq_t atReq, CellularAtDataReq_t dataReq, uint32_t atTimeoutMS, uint32_t dataTimeoutMS)
Send the AT command to cellular modem with send data.
Definition: cellular_pkthandler.c:721
void(* CellularAtParseTokenHandler_t)(CellularContext_t *pContext, char *pInputStr)
URC handler function.
Definition: cellular_common.h:93
CellularError_t _Cellular_IsValidPdn(uint8_t contextId)
Check PDN context index validity.
Definition: cellular_common.c:653
void _Cellular_GenericCallback(const CellularContext_t *pContext, const char *pRawData)
Call the network registration callback if the callback is previously set by Cellular_RegisterUrcGener...
Definition: cellular_common.c:872
CellularSocketContext_t * _Cellular_GetSocketData(const CellularContext_t *pContext, uint32_t sockIndex)
Get the socket data structure with socket index.
Definition: cellular_common.c:894
CellularError_t _Cellular_ConvertCsqSignalRssi(int16_t csqRssi, int16_t *pRssiValue)
Convert CSQ command returned RSSI value.
Definition: cellular_common.c:669
CellularError_t _Cellular_GetCurrentRat(CellularContext_t *pContext, CellularRat_t *pRat)
Return the current RAT if previously received with 3GPP AT command.
Definition: cellular_common.c:807
CellularError_t _Cellular_LibCleanup(CellularHandle_t cellularHandle)
One time deinitialization function.
Definition: cellular_common.c:1052
CellularPktStatus_t _Cellular_AtcmdRequestSuccessToken(CellularContext_t *pContext, CellularAtReq_t atReq, uint32_t atTimeoutMS, const char **pCellularSrcTokenSuccessTable, uint32_t cellularSrcTokenSuccessTableSize)
Send the AT command to cellular modem with extra success token table.
Definition: cellular_pkthandler.c:585
CellularError_t _Cellular_CheckLibraryStatus(CellularContext_t *pContext)
Check Library Status.
Definition: cellular_common.c:425
CellularSocketState_t
enum representing different Socket State.
Definition: cellular_common.h:111
@ SOCKETSTATE_CONNECTING
Definition: cellular_common.h:113
@ SOCKETSTATE_DISCONNECTED
Definition: cellular_common.h:115
@ SOCKETSTATE_CONNECTED
Definition: cellular_common.h:114
@ SOCKETSTATE_ALLOCATED
Definition: cellular_common.h:112
CellularPktStatus_t _Cellular_TimeoutAtcmdDataRecvRequestWithCallback(CellularContext_t *pContext, CellularAtReq_t atReq, uint32_t timeoutMS, CellularATCommandDataPrefixCallback_t pktDataPrefixCallback, void *pCallbackContext)
Send the AT command to cellular modem with data buffer response.
Definition: cellular_pkthandler.c:629
CellularPktStatus_t _Cellular_TimeoutAtcmdRequestWithCallback(CellularContext_t *pContext, CellularAtReq_t atReq, uint32_t timeoutMS)
Send the AT command to cellular modem.
Definition: cellular_common.c:1086
CellularPktStatus_t _Cellular_AtcmdRequestWithCallback(CellularContext_t *pContext, CellularAtReq_t atReq)
Send the AT command to cellular modem with default timeout.
Definition: cellular_common.c:1077
CellularPktStatus_t _Cellular_TranslateAtCoreStatus(CellularATError_t status)
Translate Error Code AT Core status to Packet Status.
Definition: cellular_common.c:492
CellularError_t _Cellular_GetModuleContext(const CellularContext_t *pContext, void **ppModuleContext)
Get the socket data structure with socket index.
Definition: cellular_common.c:755
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)
Send the AT command to cellular modem with send data.
Definition: cellular_pkthandler.c:668
CellularError_t _Cellular_CreateSocketData(CellularContext_t *pContext, uint8_t contextId, CellularSocketDomain_t socketDomain, CellularSocketType_t socketType, CellularSocketProtocol_t socketProtocol, CellularSocketHandle_t *pSocketHandle)
Create a socket.
Definition: cellular_common.c:522
void _Cellular_ModemEventCallback(const CellularContext_t *pContext, CellularModemEvent_t modemEvent)
Call the network registration callback if the callback is previously set by Cellular_RegisterModemEve...
Definition: cellular_common.c:883
CellularError_t _Cellular_RemoveSocketData(CellularContext_t *pContext, CellularSocketHandle_t socketHandle)
Remove the socket.
Definition: cellular_common.c:582
CellularError_t _Cellular_RegisterInputBufferCallback(CellularContext_t *pContext, CellularInputBufferCallback_t inputBufferCallback, void *pInputBufferCallbackContext)
Register input buffer callback.
Definition: cellular_common.c:1129
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)
Send the AT command to cellular modem with send data and extra success token table.
Definition: cellular_pkthandler.c:732
CellularPktStatus_t(* CellularInputBufferCallback_t)(void *pInputBufferCallbackContext, char *pBuffer, uint32_t bufferLength, uint32_t *pBufferLengthHandled)
Callback used to process input buffer.
Definition: cellular_common.h:240
CellularError_t _Cellular_IsValidSocket(const CellularContext_t *pContext, uint32_t sockIndex)
Check socket index validity.
Definition: cellular_common.c:630
CellularPktStatus_t(* CellularATCommandDataPrefixCallback_t)(void *pCallbackContext, char *pLine, uint32_t lineLength, char **pDataStart, uint32_t *pDataLength)
Callback used to inform pktio the data start and the length of the data.
Definition: cellular_common.h:192
CellularPktStatus_t(* CellularATCommandDataSendPrefixCallback_t)(void *pCallbackContext, char *pLine, uint32_t *pBytesRead)
Callback used to fix the stream before the send data.
Definition: cellular_common.h:209
void _Cellular_PdnEventCallback(const CellularContext_t *pContext, CellularUrcEvent_t urcEvent, uint8_t contextId)
Call the network registration callback if the callback is previously set by Cellular_RegisterUrcPdnEv...
Definition: cellular_common.c:847
CellularError_t _Cellular_LibInit(CellularHandle_t *pCellularHandle, const CellularCommInterface_t *pCommInterface, const CellularTokenTable_t *pTokenTable)
One time initialization function.
Definition: cellular_common.c:920
CellularError_t _Cellular_ConvertCsqSignalBer(int16_t csqBer, int16_t *pBerValue)
Convert CSQ command returned BER value.
Definition: cellular_common.c:706
CellularError_t _Cellular_ComputeSignalBars(CellularRat_t rat, CellularSignalInfo_t *pSignalInfo)
Convert the signal to bar.
Definition: cellular_common.c:774
This represents the default values for the configuration macros for the Cellular library.
CellularUrcEvent_t
Represents URC events.
Definition: cellular_types.h:212
CellularPktStatus_t
packet Status Names.
Definition: cellular_types.h:338
CellularATCommandType_t
Represents AT Command type.
Definition: cellular_types.h:360
CellularSocketType_t
Represents socket type.
Definition: cellular_types.h:273
CellularSocketAccessMode_t
Represents data access modes.
Definition: cellular_types.h:293
CellularRat_t
Enums representing Radio Access Technologies (RATs). Reference 3GPP TS 27.007 PLMN selection +COPS.
Definition: cellular_types.h:111
CellularError_t
Status code returns from APIs.
Definition: cellular_types.h:88
CellularSocketDomain_t
Represents socket domain.
Definition: cellular_types.h:263
CellularSocketProtocol_t
Represents socket protocol.
Definition: cellular_types.h:283
CellularModemEvent_t
Represents Modem events.
Definition: cellular_types.h:228
void(* CellularSocketClosedCallback_t)(CellularSocketHandle_t socketHandle, void *pCallbackContext)
Callback used to inform that remote end closed the connection for a connected socket.
Definition: cellular_types.h:826
void(* CellularSocketDataReadyCallback_t)(CellularSocketHandle_t socketHandle, void *pCallbackContext)
Callback used to inform that data is ready for reading on a socket.
Definition: cellular_types.h:813
void(* CellularSocketOpenCallback_t)(CellularUrcEvent_t urcEvent, CellularSocketHandle_t socketHandle, void *pCallbackContext)
Callback used to inform about the status of socket open.
Definition: cellular_types.h:801
CellularPktStatus_t(* CellularATCommandResponseReceivedCallback_t)(CellularHandle_t cellularHandle, const CellularATCommandResponse_t *pAtResp, void *pData, uint16_t dataLen)
Callback used to inform about the response of an AT command sent using Cellular_ATCommandRaw API.
Definition: cellular_types.h:726
struct CellularSocketContext * CellularSocketHandle_t
Opaque socket handle.
Definition: cellular_types.h:81
The data command request structure.
Definition: cellular_common.h:76
uint32_t * pSentDataLength
Definition: cellular_common.h:79
const uint8_t * pData
Definition: cellular_common.h:77
uint32_t dataLen
Definition: cellular_common.h:78
uint32_t endPatternLen
Definition: cellular_common.h:84
const uint8_t * pEndPattern
Definition: cellular_common.h:80
the URC token and URC handler mapping structure used by pkthandler.
Definition: cellular_common.h:101
const char * pStrValue
Definition: cellular_common.h:102
CellularAtParseTokenHandler_t parserFunc
Definition: cellular_common.h:103
The AT command request structure.
Definition: cellular_common.h:62
CellularATCommandType_t atCmdType
Definition: cellular_common.h:64
CellularATCommandResponseReceivedCallback_t respCallback
Definition: cellular_common.h:66
const char * pAtCmd
Definition: cellular_common.h:63
uint16_t dataLen
Definition: cellular_common.h:68
void * pData
Definition: cellular_common.h:67
const char * pAtRspPrefix
Definition: cellular_common.h:65
Represents the functions of a comm interface.
Definition: cellular_comm_interface.h:160
Represents IP Address.
Definition: cellular_types.h:673
Represents network service status.
Definition: cellular_types.h:454
Represents signal information.
Definition: cellular_types.h:440
Represents socket address.
Definition: cellular_types.h:708
Parameters involved in sending/receiving data through sockets.
Definition: cellular_common.h:123
CellularSocketDataReadyCallback_t dataReadyCallback
Definition: cellular_common.h:142
CellularSocketType_t socketType
Definition: cellular_common.h:127
uint32_t recvTimeoutMs
Definition: cellular_common.h:136
uint32_t socketId
Definition: cellular_common.h:125
CellularSocketOpenCallback_t openCallback
Definition: cellular_common.h:144
uint32_t sendTimeoutMs
Definition: cellular_common.h:135
CellularSocketAccessMode_t dataMode
Definition: cellular_common.h:132
CellularSocketDomain_t socketDomain
Definition: cellular_common.h:128
uint8_t contextId
Definition: cellular_common.h:124
void * pClosedCallbackContext
Definition: cellular_common.h:147
uint16_t localPort
Definition: cellular_common.h:131
CellularSocketClosedCallback_t closedCallback
Definition: cellular_common.h:146
void * pOpenCallbackContext
Definition: cellular_common.h:145
CellularSocketState_t socketState
Definition: cellular_common.h:126
CellularSocketProtocol_t socketProtocol
Definition: cellular_common.h:129
CellularIPAddress_t localIpAddress
Definition: cellular_common.h:130
void * pDataReadyCallbackContext
Definition: cellular_common.h:143
CellularSocketAddress_t remoteSocketAddress
Definition: cellular_common.h:139
void * pModemData
Definition: cellular_common.h:150
Parameters to setup pktio and pkthandler token tables.
Definition: cellular_common.h:158
uint32_t cellularSrcTokenErrorTableSize
Definition: cellular_common.h:165
uint32_t cellularSrcExtraTokenSuccessTableSize
Definition: cellular_common.h:175
const char ** pCellularUrcTokenWoPrefixTable
Definition: cellular_common.h:170
CellularAtParseTokenMap_t * pCellularUrcHandlerTable
Definition: cellular_common.h:160
uint32_t cellularUrcTokenWoPrefixTableSize
Definition: cellular_common.h:171
uint32_t cellularPrefixToParserMapSize
Definition: cellular_common.h:161
const char ** pCellularSrcExtraTokenSuccessTable
Definition: cellular_common.h:174
const char ** pCellularSrcTokenSuccessTable
Definition: cellular_common.h:166
uint32_t cellularSrcTokenSuccessTableSize
Definition: cellular_common.h:167
const char ** pCellularSrcTokenErrorTable
Definition: cellular_common.h:164