mj.qu | f47abdc | 2025-01-14 17:23:20 -0800 | [diff] [blame^] | 1 | #ifndef _WEFOTA_MAIN_H_
|
| 2 | #define _WEFOTA_MAIN_H_
|
| 3 |
|
| 4 | #define WEFOTA_HEADER_MAGIC 0x41544F46
|
| 5 | #define WEFOTA_HEADER_PROTOCOL 0x80
|
| 6 | #define WEFOTA_HEADER_TID 0x0A
|
| 7 |
|
| 8 | #define WEFOTA_HEADER_SIZE 107
|
| 9 | #define WEFOTA_REQ_MAX_LEN (WEFOTA_HEADER_SIZE + 68)
|
| 10 |
|
| 11 | #define WEFOTA_DIFF_PACK_DATA_MAX_LEN 1024
|
| 12 | #define WEFOTA_RESP_DIFF_PACK_DATA_MAX_LEN (WEFOTA_DIFF_PACK_DATA_MAX_LEN + 39)
|
| 13 | #define WEFOTA_RESP_MAX_LEN (WEFOTA_HEADER_SIZE + WEFOTA_RESP_DIFF_PACK_DATA_MAX_LEN)
|
| 14 |
|
| 15 | #define WEFOTA_MAX_RETRIES 3
|
| 16 | #define WEFOTA_TIMEOUT_SEC 1
|
| 17 |
|
| 18 | #define WEFOTA_PRODUCT_ID "10300"
|
| 19 |
|
| 20 |
|
| 21 | typedef enum _FOTA_Status{
|
| 22 | FOTA_STATUS_IDLE = 0,
|
| 23 | FOTA_STATUS_GET_IP_1,
|
| 24 | FOTA_STATUS_CHECK_TASK,
|
| 25 | FOTA_STATUS_GET_IP_2,
|
| 26 | FOTA_STATUS_GET_VER_ID,
|
| 27 | FOTA_STATUS_GET_DIFF_PACK_ID,
|
| 28 | FOTA_STATUS_GET_DIFF_PACK_DATA,
|
| 29 | FOTA_STATUS_GET_DIFF_PACK_END,
|
| 30 | FOTA_STATUS_INSTALL_DIFF_PACK,
|
| 31 | FOTA_STATUS_MAX
|
| 32 | } FOTA_Status;
|
| 33 |
|
| 34 | typedef struct _WeFOTA_MSG{
|
| 35 | FOTA_Status status;
|
| 36 | unsigned char req_code;
|
| 37 | unsigned short req_count;
|
| 38 | unsigned char resp_code;
|
| 39 | unsigned short resp_count;
|
| 40 | } WeFOTA_MSG;
|
| 41 |
|
| 42 | #pragma pack(1)
|
| 43 | typedef struct _WeFOTAHeader{
|
| 44 | unsigned int magic; // 4 bytes
|
| 45 | unsigned char protocol; // 1 byte
|
| 46 | unsigned char code; // 1 byte
|
| 47 | unsigned char cgi[9]; // 9 bytes
|
| 48 | unsigned char imsi[15]; // 15 bytes
|
| 49 | unsigned char iccid[20]; // 20 bytes
|
| 50 | unsigned char devid[32]; // 32 bytes,16 meid and 16 imei
|
| 51 | unsigned char gps[20]; // 20 bytes
|
| 52 | unsigned char sig; // 1 byte
|
| 53 | unsigned short tid; // 2 bytes
|
| 54 | unsigned short count; // 2 bytes
|
| 55 | } WeFOTAHeader;
|
| 56 |
|
| 57 | typedef struct _ServerAddr{
|
| 58 | char ip[16];
|
| 59 | unsigned short port;
|
| 60 | } ServerAddr;
|
| 61 |
|
| 62 | typedef struct _FotaTask{
|
| 63 | unsigned char flag;
|
| 64 | unsigned int interval;
|
| 65 | unsigned int delay;
|
| 66 | char destVersion[32];
|
| 67 | } FotaTask;
|
| 68 |
|
| 69 | typedef struct _Version{
|
| 70 | char product[8];
|
| 71 | char orig_version[30];
|
| 72 | char dest_version[30];
|
| 73 | } Version;
|
| 74 |
|
| 75 | typedef struct _VerID{
|
| 76 | char product[8];
|
| 77 | unsigned short orig_verid;
|
| 78 | unsigned short dest_verid;
|
| 79 | } VerID;
|
| 80 |
|
| 81 | typedef struct _DiffPackInfo{
|
| 82 | unsigned char diffPackID[15];
|
| 83 | unsigned char MD5[16];
|
| 84 | unsigned int size;
|
| 85 | } DiffPackInfo;
|
| 86 |
|
| 87 | typedef struct _DiffPackDataReq{
|
| 88 | unsigned char diffPackID[15];
|
| 89 | unsigned int offset;
|
| 90 | unsigned int length;
|
| 91 | } DiffPackDataReq;
|
| 92 |
|
| 93 | typedef struct _DiffPackDataResp{
|
| 94 | unsigned char diffPackID[15];
|
| 95 | unsigned char MD5[16];
|
| 96 | unsigned int offset;
|
| 97 | unsigned int length;
|
| 98 | unsigned char data[1024];
|
| 99 | } DiffPackDataResp;
|
| 100 |
|
| 101 | typedef struct _DiffPackEnd{
|
| 102 | unsigned char diffPackID[15];
|
| 103 | unsigned int costTime;
|
| 104 | } DiffPackEnd;
|
| 105 |
|
| 106 | #pragma pack()
|
| 107 |
|
| 108 | int wefaota_header_init(WeFOTAHeader *hdr);
|
| 109 | void set_fota_status(FOTA_Status status);
|
| 110 | FOTA_Status get_fota_status(void);
|
| 111 |
|
| 112 | #endif |