322 lines
10 KiB
C
322 lines
10 KiB
C
#ifndef EG91_H
|
|
#define EG91_H
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdint.h>
|
|
#include "eg91_conf.h"
|
|
|
|
/* Private Constants --------------------------------------------------------*/
|
|
#define RET_NONE 0x0000 /* RET_NONE shall be 0x0: don't change this value! */
|
|
#define RET_CRLF 0x0001
|
|
#define RET_OK 0x0002 /* do not change this value */
|
|
#define RET_SIM_READY 0x0004
|
|
#define RET_ARROW 0x0008
|
|
#define RET_SENT 0x0010 /* do not change this value */
|
|
#define RET_OPEN 0x0020
|
|
#define RET_ERROR 0x0040 /* do not change this value */
|
|
#define RET_URC_CLOSED 0x0080
|
|
#define RET_URC_RECV 0x0100
|
|
#define RET_URC_IN_FULL 0x0200
|
|
#define RET_URC_INCOM 0x0400
|
|
#define RET_URC_PDPDEACT 0x0800
|
|
#define RET_URC_DNS 0x1000
|
|
#define RET_BUF_FULL 0x2000 /* do not change this value */
|
|
#define RET_READ 0x4000
|
|
#define RET_CME_ERROR 0x8000 /* do not change this value */
|
|
#define RET_CMS_ERROR 0x10000
|
|
#define RET_POWERED_DOWN 0x20000
|
|
#define RET_SEND 0x40000
|
|
#define RET_RESP 0x80000
|
|
#define RET_NETCLOSE 0x80010
|
|
#define RET_UART_READY 0x90000
|
|
#define RET_PING 0x90010
|
|
#define RET_RDY 0x90020
|
|
#define NUM_RESPONSES 25
|
|
|
|
/* Timeouts modem dependent */
|
|
#define EG91_TOUT_SHORT 1000 /* 50 ms 1000 */
|
|
#define EG91_TOUT_100 100 /* 100 ms */
|
|
#define EG91_TOUT_300 350 /* 0,3 sec + margin */
|
|
#define EG91_TOUT_ATSYNC 500
|
|
/* Timeouts network dependent */
|
|
#define EG91_TOUT_5000 5500 /* 5 sec + margin */
|
|
#define EG91_TOUT_15000 16500 /* 15 sec + margin */
|
|
#define EG91_TOUT_40000 42000 /* 40 sec + margin */
|
|
#define EG91_TOUT_60000 64000 /* 1 min + margin */
|
|
#define EG91_TOUT_75000 78000 /* 75 sec + margin */
|
|
#define EG91_TOUT_150000 156000 /* 2,5 min + margin */
|
|
#define EG91_TOUT_180000 186000 /* 3 min + margin */
|
|
|
|
/* Exported constants---------------------------------------------------------*/
|
|
|
|
#define EG91_MAX_APN_NAME_SIZE 32
|
|
#define EG91_MAX_USER_NAME_SIZE 32
|
|
#define EG91_MAX_PSW_NAME_SIZE 32
|
|
|
|
#define EG91_ERROR_STRING_SIZE 40
|
|
|
|
#define EG91_MFC_SIZE 10
|
|
#define EG91_PROD_ID_SIZE 50
|
|
#define EG91_FW_REV_SIZE 100
|
|
#define EG91_IMEI_SIZE 50
|
|
#define EG91_ICCID_SIZE 50
|
|
#define EG91_IMSI_SIZE 50
|
|
|
|
/* Exported macro-------------------------------------------------------------*/
|
|
#ifdef MIN
|
|
#undef MIN
|
|
#endif
|
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
/* Exported typedef ----------------------------------------------------------*/
|
|
typedef int8_t (*IO_Init_Func)(void);
|
|
typedef int8_t (*IO_DeInit_Func)(void);
|
|
typedef int8_t (*IO_Baudrate_Func)(uint32_t BaudRate);
|
|
typedef void (*IO_Flush_Func)(void);
|
|
typedef int16_t (*IO_Send_Func)(uint8_t*, uint16_t);
|
|
typedef int16_t (*IO_ReceiveOne_Func)(uint8_t *pSingleData);
|
|
typedef uint32_t (*App_GetTickCb_Func)(void);
|
|
|
|
typedef struct
|
|
{
|
|
uint32_t retVal;
|
|
char retStr[100];
|
|
} EG91_RetKeywords_t;
|
|
|
|
typedef enum
|
|
{
|
|
EG91_RETURN_OK = RET_OK, /* shall be aligned with above definitions */
|
|
EG91_RETURN_ERROR = RET_ERROR, /* shall be aligned with above definitions */
|
|
EG91_RETURN_CME_ERROR = RET_CME_ERROR, /* shall be aligned with above definitions */
|
|
EG91_RETURN_RETRIEVE_ERROR = -1,
|
|
EG91_RETURN_SEND_ERROR = -2
|
|
} EG91_Return_t;
|
|
|
|
typedef enum
|
|
{
|
|
/* See CME Error Codes */
|
|
EG91_SIM_ERROR = 0,
|
|
EG91_SIM_NOT_INSERTED = 10,
|
|
EG91_SIM_PIN_REQUIRED = 11,
|
|
EG91_SIM_PUK_REQUIRED = 12,
|
|
EG91_SIM_FAILURE = 13,
|
|
EG91_SIM_BUSY = 14,
|
|
EG91_SIM_WRONG = 15,
|
|
EG91_INCORRECT_PSW = 16,
|
|
EG91_SIM_PIN2_REQUIRED = 17,
|
|
EG91_SIM_PUK2_REQUIRED = 18,
|
|
EG91_OPERATION_NOT_ALLOW = 3,
|
|
EG91_SIM_READY = 0xFF
|
|
} EG91_SIMState_t;
|
|
|
|
|
|
typedef enum
|
|
{
|
|
EG91_NRS_NOT_REGISTERED = 0x00,
|
|
EG91_NRS_HOME_NETWORK = 0x01,
|
|
EG91_NRS_TRYING = 0x02,
|
|
EG91_NRS_REG_DENIED = 0x03,
|
|
EG91_NRS_UNKNOWN = 0x04,
|
|
EG91_NRS_ROAMING = 0x05,
|
|
EG91_NRS_ERROR = 0xFF
|
|
} EG91_NetworkRegistrationState_t;
|
|
|
|
typedef enum
|
|
{
|
|
EG91_AP_DEACTIVATED = 0x00,
|
|
EG91_AP_ACVTIVATED = 0x01,
|
|
EG91_AP_ERROR = 0xFF
|
|
} EG91_APState_t;
|
|
|
|
typedef enum
|
|
{
|
|
EG91_INIT_RET_OK = RET_OK, /*shall be aligned with above definitions */
|
|
EG91_INIT_RET_AT_ERR = 0x04,
|
|
EG91_INIT_RET_SIM_ERR = 0x08,
|
|
EG91_INIT_RET_IO_ERR = 0x10,
|
|
EG91_INIT_OTHER_ERR = 0x20
|
|
} EG91_InitRet_t;
|
|
|
|
typedef enum
|
|
{
|
|
EG91_SEND_RET_UART_FAIL = 0x1,
|
|
EG91_SEND_RET_SENT = RET_SENT, /*shall be aligned with above definitions */
|
|
EG91_SEND_RET_BUF_FULL = RET_BUF_FULL, /*shall be aligned with above definitions */
|
|
EG91_SEND_RET_CONN_ERR = RET_ERROR /*shall be aligned with above definitions */
|
|
} EG91_SendRet_t;
|
|
|
|
|
|
typedef enum
|
|
{
|
|
EG91_RECEIVE_RET_INCOMPLETE = 0x01,
|
|
EG91_RECEIVE_RET_OK = RET_OK, /*shall be aligned with above definitions */
|
|
EG91_RECEIVE_RET_PARAM_ERR = 0x04,
|
|
EG91_RECEIVE_RET_COM_ERR = 0x08
|
|
} EG91_ReceiveRet_t;
|
|
|
|
typedef enum
|
|
{
|
|
EG91_TCP_CONNECTION = 0,
|
|
EG91_UDP_CONNECTION = 1,
|
|
EG91_TCP_LISTENER_CONNECTION = 2,
|
|
EG91_UDP_SERVER_CONNECTION = 3
|
|
} EG91_ConnType_t;
|
|
|
|
typedef enum
|
|
{
|
|
EG91_BUFFER_MODE = 0,
|
|
EG91_DIRECT_PUSH = 1,
|
|
EG91_TRANSPARENT_MODE = 2
|
|
} EG91_AccessMode_t;
|
|
|
|
/**
|
|
* \brief Authentication settings for C2C network
|
|
*/
|
|
typedef enum
|
|
{
|
|
EG91_AUTHENT_NONE = 0x00,
|
|
EG91_AUTHENT_PAP = 0x01,
|
|
EG91_AUTHENT_CHAP = 0x02,
|
|
EG91_AUTHENT_PAP_CHAP = 0x03
|
|
} EG91_Authent_t;
|
|
|
|
typedef enum
|
|
{
|
|
EG91_UART_FLW_CTL_NONE = 0x00,
|
|
EG91_UART_FLW_CTL_RTS = 0x01,
|
|
EG91_UART_FLW_CTL_CTS = 0x02,
|
|
EG91_UART_FLW_CTL_RTS_CTS = 0x03,
|
|
} EG91_UART_FLW_CTL_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint32_t BaudRate;
|
|
uint32_t FlowControl;
|
|
} EG91_UARTConfig_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t ContextID; /*!< range is 1-20 */
|
|
uint8_t ContextType; /*!< shall be 1 (IpV */
|
|
uint8_t ApnString[32]; /*!< access point name, string of chars */
|
|
uint8_t Username[32]; /*!< user name, string of chars */
|
|
uint8_t Password[32]; /*!< password, string of chars */
|
|
EG91_Authent_t Authentication;
|
|
} EG91_APConfig_t;
|
|
|
|
typedef struct
|
|
{
|
|
EG91_ConnType_t Type;
|
|
EG91_AccessMode_t AccessMode;
|
|
uint8_t ConnectID;
|
|
uint16_t RemotePort;
|
|
uint16_t LocalPort;
|
|
char *Url;
|
|
} EG91_Conn_t;
|
|
|
|
typedef struct
|
|
{
|
|
EG91_ConnType_t Type;
|
|
EG91_AccessMode_t AccessMode;
|
|
uint16_t ComulatedQirdData;
|
|
uint16_t HaveReadLength;
|
|
uint16_t UnreadLength;
|
|
int16_t UartRemaining; /* if Timeout respects UART speed this should always be 0 */
|
|
} EG91_Socket_t;
|
|
|
|
typedef struct
|
|
{
|
|
IO_Init_Func IO_Init;
|
|
IO_DeInit_Func IO_DeInit;
|
|
IO_Baudrate_Func IO_Baudrate;
|
|
IO_Flush_Func IO_FlushBuffer;
|
|
IO_Send_Func IO_Send;
|
|
IO_ReceiveOne_Func IO_ReceiveOne;
|
|
} EG91_IO_t;
|
|
|
|
typedef struct
|
|
{
|
|
EG91_SIMState_t SimStatus;
|
|
uint8_t RegistStatusString[3];
|
|
uint8_t IMSI[EG91_IMSI_SIZE];
|
|
uint8_t ICCID[EG91_ICCID_SIZE + 1];
|
|
} EG91_SIMInfo_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t Manufacturer[EG91_MFC_SIZE];
|
|
uint8_t ProductID[EG91_PROD_ID_SIZE];
|
|
uint8_t FW_Rev[EG91_FW_REV_SIZE];
|
|
uint8_t Imei[EG91_IMEI_SIZE]; /*International Mobile Equipment Identity*/
|
|
EG91_SIMInfo_t SimInfo;
|
|
uint8_t APsActive;
|
|
uint8_t APContextState[EG91_MAX_CONTEXTS]; /* to decide if keeping all EG91_APConfig_t info. maybe at c2c SW level*/
|
|
EG91_Socket_t SocketInfo[EG91_MAX_SOCKETS]; /* to decide if keeping all EG91_Conn_t info. maybe at c2c SW level*/
|
|
EG91_UARTConfig_t UART_Config;
|
|
EG91_IO_t fops;
|
|
App_GetTickCb_Func GetTickCb;
|
|
uint8_t CmdResp[EG91_CMD_SIZE];
|
|
uint32_t RemainRxData;
|
|
} EG91Object_t;
|
|
|
|
/* Exported functions --------------------------------------------------------*/
|
|
|
|
/* ==== Init and status ==== */
|
|
|
|
EG91_Return_t EG91_RegisterBusIO(EG91Object_t *Obj, IO_Init_Func IO_Init,
|
|
IO_DeInit_Func IO_DeInit, IO_Baudrate_Func IO_Baudrate,
|
|
IO_Send_Func IO_Send, IO_ReceiveOne_Func IO_ReceiveOne,
|
|
IO_Flush_Func IO_Flush);
|
|
|
|
EG91_InitRet_t EG91_Init(EG91Object_t *Obj);
|
|
EG91_Return_t EG91_PowerDown(EG91Object_t *Obj);
|
|
|
|
/* ==== Registration and network selection ==== */
|
|
|
|
EG91_Return_t EG91_GetSignalQualityStatus(EG91Object_t *Obj, int32_t *Qvalue);
|
|
EG91_Return_t EG91_PSAttach(EG91Object_t *Obj);
|
|
EG91_Return_t EG91_AutomaticPlmnSelection(EG91Object_t *Obj);
|
|
EG91_Return_t EG91_SetFullFunctionality(EG91Object_t *Obj);
|
|
EG91_NetworkRegistrationState_t EG91_GetCsNetworkRegistrationStatus(EG91Object_t *Obj);
|
|
EG91_NetworkRegistrationState_t EG91_GetPsNetworkRegistrationStatus(EG91Object_t *Obj);
|
|
EG91_NetworkRegistrationState_t EG91_GetEpsNetworkRegistrationStatus(EG91Object_t *Obj);
|
|
EG91_Return_t EG91_ListOperators(EG91Object_t *Obj, char *Operators);
|
|
EG91_Return_t EG91_GetCurrentOperator(EG91Object_t *Obj, char *Operator, uint8_t Bufsize);
|
|
|
|
/* ==== AP Connection ==== */
|
|
|
|
EG91_Return_t EG91_ConfigurePDPContext(EG91Object_t *Obj, uint8_t ContextID, const char *apn);
|
|
EG91_Return_t EG91_Activate(EG91Object_t *Obj, uint8_t ContextID, const char *apnStr);
|
|
EG91_Return_t EG91_Deactivate(EG91Object_t *Obj, uint8_t ContextID);
|
|
EG91_APState_t EG91_IsActivated(EG91Object_t *Obj, uint8_t ContextID);
|
|
|
|
/* ====IP Addr ==== */
|
|
EG91_Return_t EG91_GetActiveIpAddresses(EG91Object_t *Obj);
|
|
|
|
/* ==== Ping ==== */
|
|
|
|
#if (EG91_USE_PING == 1)
|
|
EG91_Return_t EG91_Ping(EG91Object_t *Obj);
|
|
#endif
|
|
|
|
/* ==== Miscellaneus ==== */
|
|
|
|
EG91_Return_t EG91_ResetToFactoryDefault(EG91Object_t *Obj);
|
|
EG91_Return_t EG91_SetUARTBaudrate(EG91Object_t *Obj, EG91_UARTConfig_t *pconf);
|
|
EG91_Return_t EG91_GetUARTConfig(EG91Object_t *Obj, EG91_UARTConfig_t *pconf);
|
|
|
|
void EG91_GetManufacturer(EG91Object_t *Obj, uint8_t *Manufacturer);
|
|
void EG91_GetProductID(EG91Object_t *Obj, uint8_t *ProductID);
|
|
void EG91_GetFWRevID(EG91Object_t *Obj, uint8_t *Fw_ver);
|
|
|
|
EG91_Return_t EG91_RetrieveLastErrorDetails(EG91Object_t *Obj, char *error_string);
|
|
|
|
/* Application must provide callback function that gives a Timer Tick in ms (e.g. HAL_GetTick())*/
|
|
EG91_Return_t EG91_RegisterTickCb(EG91Object_t *Obj, App_GetTickCb_Func GetTickCb);
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // EG91_H
|