blob: 4bca0d38a9078748fe14431433a77eedfe42977f [file] [log] [blame]
#ifndef _WEFOTA_MAIN_H_
#define _WEFOTA_MAIN_H_
#define WEFOTA_HEADER_MAGIC 0x41544F46
#define WEFOTA_HEADER_PROTOCOL 0x80
#define WEFOTA_HEADER_TID 0x0A
#define WEFOTA_HEADER_SIZE 107
#define WEFOTA_REQ_MAX_LEN (WEFOTA_HEADER_SIZE + 68)
#define WEFOTA_DIFF_PACK_DATA_MAX_LEN 1024
#define WEFOTA_RESP_DIFF_PACK_DATA_MAX_LEN (WEFOTA_DIFF_PACK_DATA_MAX_LEN + 39)
#define WEFOTA_RESP_MAX_LEN (WEFOTA_HEADER_SIZE + WEFOTA_RESP_DIFF_PACK_DATA_MAX_LEN)
#define WEFOTA_MAX_RETRIES 3
#define WEFOTA_TIMEOUT_SEC 1
#define WEFOTA_PRODUCT_ID "10300"
typedef enum _FOTA_Status{
FOTA_STATUS_IDLE = 0,
FOTA_STATUS_GET_IP_1,
FOTA_STATUS_CHECK_TASK,
FOTA_STATUS_GET_IP_2,
FOTA_STATUS_GET_VER_ID,
FOTA_STATUS_GET_DIFF_PACK_ID,
FOTA_STATUS_GET_DIFF_PACK_DATA,
FOTA_STATUS_GET_DIFF_PACK_END,
FOTA_STATUS_INSTALL_DIFF_PACK,
FOTA_STATUS_MAX
} FOTA_Status;
typedef struct _WeFOTA_MSG{
FOTA_Status status;
unsigned char req_code;
unsigned short req_count;
unsigned char resp_code;
unsigned short resp_count;
} WeFOTA_MSG;
#pragma pack(1)
typedef struct _WeFOTAHeader{
unsigned int magic; // 4 bytes
unsigned char protocol; // 1 byte
unsigned char code; // 1 byte
unsigned char cgi[9]; // 9 bytes
unsigned char imsi[15]; // 15 bytes
unsigned char iccid[20]; // 20 bytes
unsigned char devid[32]; // 32 bytes,16 meid and 16 imei
unsigned char gps[20]; // 20 bytes
unsigned char sig; // 1 byte
unsigned short tid; // 2 bytes
unsigned short count; // 2 bytes
} WeFOTAHeader;
typedef struct _ServerAddr{
char ip[16];
unsigned short port;
} ServerAddr;
typedef struct _FotaTask{
unsigned char flag;
unsigned int interval;
unsigned int delay;
char destVersion[32];
} FotaTask;
typedef struct _Version{
char product[8];
char orig_version[30];
char dest_version[30];
} Version;
typedef struct _VerID{
char product[8];
unsigned short orig_verid;
unsigned short dest_verid;
} VerID;
typedef struct _DiffPackInfo{
unsigned char diffPackID[15];
unsigned char MD5[16];
unsigned int size;
} DiffPackInfo;
typedef struct _DiffPackDataReq{
unsigned char diffPackID[15];
unsigned int offset;
unsigned int length;
} DiffPackDataReq;
typedef struct _DiffPackDataResp{
unsigned char diffPackID[15];
unsigned char MD5[16];
unsigned int offset;
unsigned int length;
unsigned char data[1024];
} DiffPackDataResp;
typedef struct _DiffPackEnd{
unsigned char diffPackID[15];
unsigned int costTime;
} DiffPackEnd;
#pragma pack()
int wefaota_header_init(WeFOTAHeader *hdr);
void set_fota_status(FOTA_Status status);
FOTA_Status get_fota_status(void);
#endif