yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | #ifndef _FOTA_COMM_H_ |
| 2 | #define _FOTA_COMM_H_ |
| 3 | |
| 4 | |
| 5 | #include "dmgr_api.h" |
| 6 | |
| 7 | #include "fota_protocol_util.h" |
| 8 | #include "fota_http_util.h" |
| 9 | |
| 10 | #include "curl_adapter.h" |
| 11 | #include "assert.h" |
| 12 | #include <fcntl.h> |
| 13 | |
| 14 | |
| 15 | #include <unistd.h> |
| 16 | #include <sys/types.h> |
| 17 | #include <sys/stat.h> |
| 18 | #include <string.h> |
| 19 | |
| 20 | //#define MEM_DEBUG |
| 21 | |
| 22 | |
| 23 | void dump_mem_info(void); |
| 24 | |
| 25 | #define fota_sleep sleep |
| 26 | #define fota_assert assert |
| 27 | #define fota_ftruncate ftruncate |
| 28 | |
| 29 | #ifdef MEM_DEBUG |
| 30 | |
| 31 | void* realloc_debug(void *ptr, size_t size, const char*func, long line); |
| 32 | void* malloc_debug(size_t bytes, const char* func, long line); |
| 33 | void free_debug(void*p, const char* func, long line); |
| 34 | char* strdup_debug(const char* str, const char* func, long line); |
| 35 | |
| 36 | #define fota_malloc(size) malloc_debug(size, __FUNCTION__, __LINE__) |
| 37 | #define fota_free(ptr) do{if(ptr) free_debug(ptr, __FUNCTION__, __LINE__); ptr=NULL;}while(0) |
| 38 | #define fota_strdup(str) strdup_debug(str, __FUNCTION__, __LINE__) |
| 39 | #define fota_realloc(ptr, size) realloc_debug(ptr, size, __FUNCTION__, __LINE__) |
| 40 | #else |
| 41 | #define fota_malloc(size) malloc(size) |
| 42 | #define fota_free(ptr) do{if(ptr) free(ptr); ptr=NULL;}while(0) |
| 43 | #define fota_strdup(str) strdup(str) |
| 44 | #define fota_realloc(ptr, size) realloc(ptr, size) |
| 45 | |
| 46 | #endif |
| 47 | |
| 48 | |
| 49 | #define FOTA_FAIL -1 |
| 50 | #define FOTA_SUCCESS 0 |
| 51 | #define FOTA_ERROR -1 |
| 52 | |
| 53 | |
| 54 | |
| 55 | #define LOGD(fmt, args ...) \ |
| 56 | do { printf("[DMGR][%s-%d]:"fmt, __FUNCTION__, __LINE__, ##args); } while (0) |
| 57 | |
| 58 | |
| 59 | |
| 60 | #define FOTA_DEFAULT_URL "http://fotazxic.zte.com.cn/Fota/Download.do" |
| 61 | |
| 62 | #define DEFAULT_DL_URL "http://47.96.134.20/Fota/" |
| 63 | |
| 64 | #define FOTA_SERVER_DOMAIN_NAME "fotazxic.zte.com.cn" |
| 65 | |
| 66 | #define VERSION_FILE "version_file" |
| 67 | #define REG_POLICY_INFO "policy_info" |
| 68 | |
| 69 | #define HTTP_LINE_ENDING "\r\n" |
| 70 | |
| 71 | /* fota版本号 */ |
| 72 | #define FOTA_VERSION 1 |
| 73 | #define ZX_FOTA_DM_LIB_VERSION "zte dmgr lib version 1.0.0" |
| 74 | |
| 75 | /* #define NB_7100 */ |
| 76 | #ifdef NB_7100 |
| 77 | #define PROTOCOL_VERSION "2.0" |
| 78 | #else |
| 79 | #define PROTOCOL_VERSION "2.1" |
| 80 | #endif |
| 81 | |
| 82 | /* action code */ |
| 83 | #define SESSION_OPEN 0x8000 |
| 84 | #define REGISTER_DEVICE_INFO 0x8001 |
| 85 | #define REGISTER_POLICY_INFO 0x8002 |
| 86 | #define CHECK_VRESION 0x8003 |
| 87 | #define DOWNLOAD_VRESION 0x8004 |
| 88 | #define UPDATE_RESULT 0x8005 |
| 89 | #define SESSION_CLOSE 0x8006 |
| 90 | |
| 91 | |
| 92 | typedef enum { |
| 93 | UPGRADE_OK = 0, |
| 94 | UPGRADE_FAIL |
| 95 | } UPGRADE_RESULT; |
| 96 | |
| 97 | |
| 98 | typedef struct { |
| 99 | char *IMEI; |
| 100 | char *download_url; |
| 101 | char *version_path; |
| 102 | unsigned int devNum; |
| 103 | char *dev_info; |
| 104 | policy_info_t *policy_info; |
| 105 | |
| 106 | } config_info_t; |
| 107 | |
| 108 | |
| 109 | typedef struct { |
| 110 | long resp_code; |
| 111 | int result_code; |
| 112 | int action_code; |
| 113 | } post_result_t; |
| 114 | |
| 115 | |
| 116 | |
| 117 | typedef struct { |
| 118 | config_info_t config_info; |
| 119 | notifier_block_t *notifier_list[MAX_USER_NOTIFIERS]; |
| 120 | post_result_t post_result; |
| 121 | download_info_t download_info; |
| 122 | |
| 123 | } dmgr_info_t; |
| 124 | |
| 125 | extern dmgr_t g_dmgr; |
| 126 | |
| 127 | #endif /* _FOTA_COMM_H_ */ |