zte's code,first commit
Change-Id: I9a04da59e459a9bc0d67f101f700d9d7dc8d681b
diff --git a/ap/lib/libdmgr/inc/curl_adapter.h b/ap/lib/libdmgr/inc/curl_adapter.h
new file mode 100644
index 0000000..6886f4a
--- /dev/null
+++ b/ap/lib/libdmgr/inc/curl_adapter.h
@@ -0,0 +1,18 @@
+#ifndef _CURL_ADAPTER_H_
+#define _CURL_ADAPTER_H_
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <dmgr_api.h>
+
+typedef size_t(*callbackFunc)(void *ptr, size_t size, size_t nmemb, void *stream);
+
+int http_post(const char* url, char* post_buf, policy_info_t *policy,
+ callbackFunc func, void *ptr);
+int http_get(const char*url, long resume_from, policy_info_t *policy,
+ callbackFunc func, void *ptr);
+
+int http_is_reponse_successful(long resp_code) ;
+long http_get_response_code();
+
+#endif // !_CURL_ADAPTER_H_
diff --git a/ap/lib/libdmgr/inc/fota_comm.h b/ap/lib/libdmgr/inc/fota_comm.h
new file mode 100644
index 0000000..5828218
--- /dev/null
+++ b/ap/lib/libdmgr/inc/fota_comm.h
@@ -0,0 +1,127 @@
+#ifndef _FOTA_COMM_H_
+#define _FOTA_COMM_H_
+
+
+#include "dmgr_api.h"
+
+#include "fota_protocol_util.h"
+#include "fota_http_util.h"
+
+#include "curl_adapter.h"
+#include "assert.h"
+#include <fcntl.h>
+
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+
+//#define MEM_DEBUG
+
+
+void dump_mem_info(void);
+
+#define fota_sleep sleep
+#define fota_assert assert
+#define fota_ftruncate ftruncate
+
+#ifdef MEM_DEBUG
+
+void* realloc_debug(void *ptr, size_t size, const char*func, long line);
+void* malloc_debug(size_t bytes, const char* func, long line);
+void free_debug(void*p, const char* func, long line);
+char* strdup_debug(const char* str, const char* func, long line);
+
+#define fota_malloc(size) malloc_debug(size, __FUNCTION__, __LINE__)
+#define fota_free(ptr) do{if(ptr) free_debug(ptr, __FUNCTION__, __LINE__); ptr=NULL;}while(0)
+#define fota_strdup(str) strdup_debug(str, __FUNCTION__, __LINE__)
+#define fota_realloc(ptr, size) realloc_debug(ptr, size, __FUNCTION__, __LINE__)
+#else
+#define fota_malloc(size) malloc(size)
+#define fota_free(ptr) do{if(ptr) free(ptr); ptr=NULL;}while(0)
+#define fota_strdup(str) strdup(str)
+#define fota_realloc(ptr, size) realloc(ptr, size)
+
+#endif
+
+
+#define FOTA_FAIL -1
+#define FOTA_SUCCESS 0
+#define FOTA_ERROR -1
+
+
+
+#define LOGD(fmt, args ...) \
+ do { printf("[DMGR][%s-%d]:"fmt, __FUNCTION__, __LINE__, ##args); } while (0)
+
+
+
+#define FOTA_DEFAULT_URL "http://fotazxic.zte.com.cn/Fota/Download.do"
+
+#define DEFAULT_DL_URL "http://47.96.134.20/Fota/"
+
+#define FOTA_SERVER_DOMAIN_NAME "fotazxic.zte.com.cn"
+
+#define VERSION_FILE "version_file"
+#define REG_POLICY_INFO "policy_info"
+
+#define HTTP_LINE_ENDING "\r\n"
+
+/* fota版本号 */
+#define FOTA_VERSION 1
+#define ZX_FOTA_DM_LIB_VERSION "zte dmgr lib version 1.0.0"
+
+/* #define NB_7100 */
+#ifdef NB_7100
+#define PROTOCOL_VERSION "2.0"
+#else
+#define PROTOCOL_VERSION "2.1"
+#endif
+
+/* action code */
+#define SESSION_OPEN 0x8000
+#define REGISTER_DEVICE_INFO 0x8001
+#define REGISTER_POLICY_INFO 0x8002
+#define CHECK_VRESION 0x8003
+#define DOWNLOAD_VRESION 0x8004
+#define UPDATE_RESULT 0x8005
+#define SESSION_CLOSE 0x8006
+
+
+typedef enum {
+ UPGRADE_OK = 0,
+ UPGRADE_FAIL
+} UPGRADE_RESULT;
+
+
+typedef struct {
+ char *IMEI;
+ char *download_url;
+ char *version_path;
+ unsigned int devNum;
+ char *dev_info;
+ policy_info_t *policy_info;
+
+} config_info_t;
+
+
+typedef struct {
+ long resp_code;
+ int result_code;
+ int action_code;
+} post_result_t;
+
+
+
+typedef struct {
+ config_info_t config_info;
+ notifier_block_t *notifier_list[MAX_USER_NOTIFIERS];
+ post_result_t post_result;
+ download_info_t download_info;
+
+} dmgr_info_t;
+
+extern dmgr_t g_dmgr;
+
+#endif /* _FOTA_COMM_H_ */
diff --git a/ap/lib/libdmgr/inc/fota_http_util.h b/ap/lib/libdmgr/inc/fota_http_util.h
new file mode 100644
index 0000000..cb487ff
--- /dev/null
+++ b/ap/lib/libdmgr/inc/fota_http_util.h
@@ -0,0 +1,6 @@
+#ifndef _FOTA_HTTP_UTIL_H_
+#define _FOTA_HTTP_UTIL_H_
+
+int http_response_decode(unsigned int responsecode);
+size_t save_data_to_file(char* filename, char *data, int len);
+#endif
diff --git a/ap/lib/libdmgr/inc/fota_protocol_util.h b/ap/lib/libdmgr/inc/fota_protocol_util.h
new file mode 100644
index 0000000..66aa1b9
--- /dev/null
+++ b/ap/lib/libdmgr/inc/fota_protocol_util.h
@@ -0,0 +1,82 @@
+#ifndef _FOTA_PROTOCOL_UTIL_H_
+#define _FOTA_PROTOCOL_UTIL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define LINE_BUF_SIZE 128
+
+typedef enum {
+ INT_ARGUMENT = 1,
+ DOUBLE_ARGUMENT,
+ STRING_ARGUMENT,
+ HEX_ARGUMENT,
+ CHARACTER_ARGUMENT,
+ POINTER_ARGUMENT,
+ MESSAGE_END
+} ArgumentType;
+
+typedef struct {
+ ArgumentType type;
+ union {
+ int int_val;
+ double double_val;
+ char *string_val;
+ void *pointer_val;
+ int character_val;
+ } u;
+} ArgumentInfo;
+
+typedef struct {
+ char *string;
+} VString;
+
+/*ÐÒéijÏîÖµÀàÐÍ*/
+typedef enum {
+ ITEMTYPE_DEC,
+ ITEMTYPE_HEX,
+ ITEMTYPE_STRING
+} ItemType;
+
+
+/*º¯ÊýÉùÃ÷*/
+char* protocol_package(char *description, ...);
+
+void format_arguments(VString *message, va_list ap);
+
+int get_action_code(char *content);
+
+int get_result_code(char *content);
+
+int get_version_info(char *content, version_info_t *versionInfo);
+
+int get_version_down_info(char *content, download_info_t *downloadInfo);
+
+void str_append(VString *message, char *str);
+
+void free_version_info(version_info_t *version_info);
+void print_version_info(version_info_t *version_info);
+
+
+
+
+/* notifier list */
+notifier_block_t* notifier_list_add(notifier_block_t* notifier_list, notifier_block_t* notifier_msg);
+
+int notifier_list_free(notifier_block_t* notifier_list);
+
+void notify_callback_process(dmgr_t dm_id, unsigned short event_id, unsigned short msgid, void* data);
+/* notifier list end */
+
+int version_md5_check(const char *filename, char *md5_expect);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+