FreeRTOS: FreeRTOS Cellular Library v1.2.0
FreeRTOS Cellular Library
cellular_common.h
Go to the documentation of this file.
1/*
2 * FreeRTOS-Cellular-Interface v1.2.0
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * https://www.FreeRTOS.org
23 * https://github.com/FreeRTOS
24 */
25
30#ifndef __CELLULAR_COMMON_H__
31#define __CELLULAR_COMMON_H__
32
33/* *INDENT-OFF* */
34#ifdef __cplusplus
35 extern "C" {
36#endif
37/* *INDENT-ON* */
38
39/* Standard includes. */
40#include <stdbool.h>
41
42/* Cellular includes. */
43#ifndef CELLULAR_DO_NOT_USE_CUSTOM_CONFIG
44 /* Include custom config file before other headers. */
45 #include "cellular_config.h"
46#endif
48#include "cellular_platform.h"
50#include "cellular_types.h"
51#include "cellular_at_core.h"
52
53/*-----------------------------------------------------------*/
54
59typedef struct CellularAtReq
60{
61 const char * pAtCmd;
63 const char * pAtRspPrefix;
65 void * pData;
66 uint16_t dataLen;
68
73typedef struct CellularAtDataReq
74{
75 const uint8_t * pData;
76 uint32_t dataLen;
77 uint32_t * pSentDataLength;
78 const uint8_t * pEndPattern;
82 uint32_t endPatternLen;
84
91typedef void ( * CellularAtParseTokenHandler_t )( CellularContext_t * pContext,
92 char * pInputStr );
93
98typedef struct CellularAtParseTokenMap
99{
100 const char * pStrValue;
103
108typedef enum CellularSocketState
109{
115
120typedef struct CellularSocketContext
121{
122 uint8_t contextId;
123 uint32_t socketId;
129 uint16_t localPort;
132 /* Set using socket options. */
133 uint32_t sendTimeoutMs;
134 uint32_t recvTimeoutMs;
136 /* Set during socket connect. */
139 /* Callback functions. */
147 /* Modem data. */
148 void * pModemData;
150
155typedef struct CellularTokenTable
156{
157 /* URC handler mapping table. */
161 /* Table to decide AT command respone status. */
167 /* Table to URC with prefix Token. */
171 /* Extra success token for specific AT command. */
175
190typedef CellularPktStatus_t ( * CellularATCommandDataPrefixCallback_t ) ( void * pCallbackContext,
191 char * pLine,
192 uint32_t lineLength,
193 char ** pDataStart,
194 uint32_t * pDataLength );
195
208 char * pLine,
209 uint32_t * pBytesRead );
210
211/*-----------------------------------------------------------*/
212
227 const CellularCommInterface_t * pCommInterface,
228 const CellularTokenTable_t * pTokenTable );
229
243
253 CellularUrcEvent_t urcEvent,
254 const CellularServiceStatus_t * pServiceStatus );
255
265 CellularUrcEvent_t urcEvent,
266 uint8_t contextId );
267
277 CellularUrcEvent_t urcEvent,
278 const CellularSignalInfo_t * pSignalInfo );
279
288 const char * pRawData );
289
298 CellularModemEvent_t modemEvent );
299
311
322
333
348 uint8_t contextId,
349 CellularSocketDomain_t socketDomain,
350 CellularSocketType_t socketType,
351 CellularSocketProtocol_t socketProtocol,
352 CellularSocketHandle_t * pSocketHandle );
353
364 CellularSocketHandle_t socketHandle );
365
376 uint32_t sockIndex );
377
387 uint32_t sockIndex );
388
398
410 int16_t * pRssiValue );
411
423 int16_t * pBerValue );
424
435 void ** ppModuleContext );
436
448 CellularSignalInfo_t * pSignalInfo );
449
460 CellularRat_t * pRat );
461
472 CellularAtReq_t atReq );
473
485 CellularAtReq_t atReq,
486 uint32_t timeoutMS );
487
501 CellularAtReq_t atReq,
502 uint32_t timeoutMS,
503 CellularATCommandDataPrefixCallback_t pktDataPrefixCallback,
504 void * pCallbackContext );
505
519 CellularAtReq_t atReq,
520 CellularAtDataReq_t dataReq,
521 uint32_t atTimeoutMS,
522 uint32_t dataTimeoutMS );
523
540 CellularAtReq_t atReq,
541 CellularAtDataReq_t dataReq,
542 CellularATCommandDataSendPrefixCallback_t pktDataSendPrefixCallback,
543 void * pCallbackContext,
544 uint32_t atTimeoutMS,
545 uint32_t dataTimeoutMS,
546 uint32_t interDelayMS );
547
563 CellularAtReq_t atReq,
564 CellularAtDataReq_t dataReq,
565 uint32_t atTimeoutMS,
566 uint32_t dataTimeoutMS,
567 const char ** pCellularSrcTokenSuccessTable,
568 uint32_t cellularSrcTokenSuccessTableSize );
569
570/* *INDENT-OFF* */
571#ifdef __cplusplus
572 }
573#endif
574/* *INDENT-ON* */
575
576#endif /* __CELLULAR_COMMON_H__ */
CellularATError_t
Represents error codes returned from AT Core APIs.
Definition: cellular_at_core.h:69
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...
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...
CellularError_t _Cellular_TranslatePktStatus(CellularPktStatus_t status)
Translate error code packet status to cellular Status.
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.
CellularError_t _Cellular_IsValidPdn(uint8_t contextId)
Check PDN context index validity.
void _Cellular_GenericCallback(const CellularContext_t *pContext, const char *pRawData)
Call the network registration callback if the callback is previously set by Cellular_RegisterUrcGener...
CellularSocketContext_t * _Cellular_GetSocketData(const CellularContext_t *pContext, uint32_t sockIndex)
Get the socket data structure with socket index.
CellularError_t _Cellular_ConvertCsqSignalRssi(int16_t csqRssi, int16_t *pRssiValue)
Convert CSQ command returned RSSI value.
CellularError_t _Cellular_GetCurrentRat(CellularContext_t *pContext, CellularRat_t *pRat)
Return the current RAT if previously received with 3GPP AT command.
CellularError_t _Cellular_LibCleanup(CellularHandle_t cellularHandle)
One time deinitialization function.
CellularError_t _Cellular_CheckLibraryStatus(CellularContext_t *pContext)
Check Library Status.
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.
CellularPktStatus_t _Cellular_TimeoutAtcmdRequestWithCallback(CellularContext_t *pContext, CellularAtReq_t atReq, uint32_t timeoutMS)
Send the AT command to cellular modem.
CellularPktStatus_t _Cellular_AtcmdRequestWithCallback(CellularContext_t *pContext, CellularAtReq_t atReq)
Send the AT command to cellular modem with default timeout.
CellularPktStatus_t _Cellular_TranslateAtCoreStatus(CellularATError_t status)
Translate Error Code AT Core status to Packet Status.
CellularError_t _Cellular_GetModuleContext(const CellularContext_t *pContext, void **ppModuleContext)
Get the socket data structure with socket index.
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.
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.
void _Cellular_ModemEventCallback(const CellularContext_t *pContext, CellularModemEvent_t modemEvent)
Call the network registration callback if the callback is previously set by Cellular_RegisterModemEve...
CellularError_t _Cellular_RemoveSocketData(CellularContext_t *pContext, CellularSocketHandle_t socketHandle)
Remove the socket.
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.
CellularError_t _Cellular_IsValidSocket(const CellularContext_t *pContext, uint32_t sockIndex)
Check socket index validity.
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...
CellularError_t _Cellular_LibInit(CellularHandle_t *pCellularHandle, const CellularCommInterface_t *pCommInterface, const CellularTokenTable_t *pTokenTable)
One time initialization function.
CellularError_t _Cellular_ConvertCsqSignalBer(int16_t csqBer, int16_t *pBerValue)
Convert CSQ command retruned BER value.
CellularError_t _Cellular_ComputeSignalBars(CellularRat_t rat, CellularSignalInfo_t *pSignalInfo)
Convert the signal to bar.
This represents the default values for the configuration macros for the Cellular library.
CellularSocketState_t
enum representing different Socket State.
Definition: cellular_common.h:109
@ SOCKETSTATE_CONNECTING
Definition: cellular_common.h:111
@ SOCKETSTATE_DISCONNECTED
Definition: cellular_common.h:113
@ SOCKETSTATE_CONNECTED
Definition: cellular_common.h:112
@ SOCKETSTATE_ALLOCATED
Definition: cellular_common.h:110
void(* CellularAtParseTokenHandler_t)(CellularContext_t *pContext, char *pInputStr)
URC handler function.
Definition: cellular_common.h:91
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:190
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:207
CellularUrcEvent_t
Represents URC events.
Definition: cellular_types.h:210
CellularPktStatus_t
packet Status Names.
Definition: cellular_types.h:335
CellularATCommandType_t
Represents AT Command type.
Definition: cellular_types.h:357
CellularSocketType_t
Represents socket type.
Definition: cellular_types.h:271
CellularSocketAccessMode_t
Represents data access modes.
Definition: cellular_types.h:291
CellularRat_t
Enums representing Radio Access Technologies (RATs). Reference 3GPP TS 27.007 PLMN selection +COPS.
Definition: cellular_types.h:109
CellularError_t
Status code returns from APIs.
Definition: cellular_types.h:86
CellularSocketDomain_t
Represents socket domain.
Definition: cellular_types.h:261
CellularSocketProtocol_t
Represents socket protocol.
Definition: cellular_types.h:281
CellularModemEvent_t
Represents Modem events.
Definition: cellular_types.h:226
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:821
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:808
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:796
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:721
struct CellularSocketContext * CellularSocketHandle_t
Opaque socket handle.
Definition: cellular_types.h:79
struct CellularContext CellularContext_t
Opaque Cellular context structure type.
Definition: cellular_types.h:65
struct CellularContext * CellularHandle_t
Opaque Cellular handle.
Definition: cellular_types.h:71
The data command request structure.
Definition: cellular_common.h:74
uint32_t * pSentDataLength
Definition: cellular_common.h:77
const uint8_t * pData
Definition: cellular_common.h:75
uint32_t dataLen
Definition: cellular_common.h:76
uint32_t endPatternLen
Definition: cellular_common.h:82
const uint8_t * pEndPattern
Definition: cellular_common.h:78
the URC token and URC handler mapping structure used by pkthanlder.
Definition: cellular_common.h:99
const char * pStrValue
Definition: cellular_common.h:100
CellularAtParseTokenHandler_t parserFunc
Definition: cellular_common.h:101
The AT command request structure.
Definition: cellular_common.h:60
CellularATCommandType_t atCmdType
Definition: cellular_common.h:62
CellularATCommandResponseReceivedCallback_t respCallback
Definition: cellular_common.h:64
const char * pAtCmd
Definition: cellular_common.h:61
uint16_t dataLen
Definition: cellular_common.h:66
void * pData
Definition: cellular_common.h:65
const char * pAtRspPrefix
Definition: cellular_common.h:63
Represents the functions of a comm interface.
Definition: cellular_comm_interface.h:158
Represents IP Address.
Definition: cellular_types.h:668
Represents network service status.
Definition: cellular_types.h:449
Represents signal information.
Definition: cellular_types.h:435
Represents socket address.
Definition: cellular_types.h:703
Parameters involved in sending/receiving data through sockets.
Definition: cellular_common.h:121
CellularSocketDataReadyCallback_t dataReadyCallback
Definition: cellular_common.h:140
CellularSocketType_t socketType
Definition: cellular_common.h:125
uint32_t recvTimeoutMs
Definition: cellular_common.h:134
uint32_t socketId
Definition: cellular_common.h:123
CellularSocketOpenCallback_t openCallback
Definition: cellular_common.h:142
uint32_t sendTimeoutMs
Definition: cellular_common.h:133
CellularSocketAccessMode_t dataMode
Definition: cellular_common.h:130
CellularSocketDomain_t socketDomain
Definition: cellular_common.h:126
uint8_t contextId
Definition: cellular_common.h:122
void * pClosedCallbackContext
Definition: cellular_common.h:145
uint16_t localPort
Definition: cellular_common.h:129
CellularSocketClosedCallback_t closedCallback
Definition: cellular_common.h:144
void * pOpenCallbackContext
Definition: cellular_common.h:143
CellularSocketState_t socketState
Definition: cellular_common.h:124
CellularSocketProtocol_t socketProtocol
Definition: cellular_common.h:127
CellularIPAddress_t localIpAddress
Definition: cellular_common.h:128
void * pDataReadyCallbackContext
Definition: cellular_common.h:141
CellularSocketAddress_t remoteSocketAddress
Definition: cellular_common.h:137
void * pModemData
Definition: cellular_common.h:148
Parameters to setup pktio and pkthandler token tables.
Definition: cellular_common.h:156
uint32_t cellularSrcTokenErrorTableSize
Definition: cellular_common.h:163
uint32_t cellularSrcExtraTokenSuccessTableSize
Definition: cellular_common.h:173
const char ** pCellularUrcTokenWoPrefixTable
Definition: cellular_common.h:168
CellularAtParseTokenMap_t * pCellularUrcHandlerTable
Definition: cellular_common.h:158
uint32_t cellularUrcTokenWoPrefixTableSize
Definition: cellular_common.h:169
uint32_t cellularPrefixToParserMapSize
Definition: cellular_common.h:159
const char ** pCellularSrcExtraTokenSuccessTable
Definition: cellular_common.h:172
const char ** pCellularSrcTokenSuccessTable
Definition: cellular_common.h:164
uint32_t cellularSrcTokenSuccessTableSize
Definition: cellular_common.h:165
const char ** pCellularSrcTokenErrorTable
Definition: cellular_common.h:162