[Feature][T108] [task-view-1792] sys ota adapt log interface

Only Configure: No
Affected branch: GSW_V1453
Affected module: sys ota
Self-test: yes
Doc Update: no

Change-Id: Ie15378f373738d76c3d7f6ddcde8be8b8a33f05d
diff --git a/mbtk/libgsw_lib/gsw_ota_ua_interface.c b/mbtk/libgsw_lib/gsw_ota_ua_interface.c
index 5261c0e..03dccb4 100755
--- a/mbtk/libgsw_lib/gsw_ota_ua_interface.c
+++ b/mbtk/libgsw_lib/gsw_ota_ua_interface.c
@@ -1,192 +1,104 @@
-#include <stdlib.h>

-#include <stdio.h>

-#include <string.h>

-#include <sys/stat.h>

-#include <sys/types.h>

-#include <unistd.h>

-#include <dlfcn.h>

-#include <stdint.h>

-

-#include <errno.h>

-#include <stdbool.h>

-

-#include "gsw_ota_ua_interface.h"

-

-

-

-#define LYNQ_OTA_INPROCESS 3

-#define LYNQ_OTA_SUCCESS   4

-#define LYNQ_OTA_FAILED   5

-

-#ifndef LOG_ERR_LEVEL
-#define LOG_ERR_LEVEL  3      /* error conditions */
-#endif
-#ifndef LOG_WARN_LEVEL
-#define LOG_WARN_LEVEL 4   /* warning conditions */
-#endif
-#ifndef LOG_INFO_LEVEL
-#define LOG_INFO_LEVEL 6      /* informational */
-#endif
-#ifndef LOG_DEBUG_LEVEL
-#define LOG_DEBUG_LEVEL 7     /* debug-level messages */
-#endif
-#ifndef LOG_VERBOSE_LEVEL
-#define LOG_VERBOSE_LEVEL 8
-#endif

-

-

-#define LIB_PATH "/lib/libmbtk_lib.so"

-

-#define GSW_OTA "[HAL][GSW_OTA]"

-

-#define StatFunc(x,y) stat(x,y)

-

-#define LOGV(fmt, args ...) \
-    do{ \
-        char *file_ptr_1001 = __FILE__; \
-        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \
-        char line_1001[10] = {0}; \
-        sprintf(line_1001, "%d", __LINE__); \
-        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
-            if(*ptr_1001 == '/') \
-                 break; \
-            ptr_1001--; \
-        } \
-        fun_ptr_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_OTA"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <dlfcn.h>
+#include <stdint.h>
 
-#define LOGI(fmt, args...) \
-    do{ \
-        char *file_ptr_1001 = __FILE__; \
-        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \
-        char line_1001[10] = {0}; \
-        sprintf(line_1001, "%d", __LINE__); \
-        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
-            if(*ptr_1001 == '/') \
-                 break; \
-            ptr_1001--; \
-        } \
-        fun_ptr_log(LOG_INFO_LEVEL, "%s#%s: "GSW_OTA"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)
+#include <errno.h>
+#include <stdbool.h>
 
-#define LOGD(fmt, args...) \
-    do{ \
-        char *file_ptr_1001 = __FILE__; \
-        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \
-        char line_1001[10] = {0}; \
-        sprintf(line_1001, "%d", __LINE__); \
-        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
-            if(*ptr_1001 == '/') \
-                 break; \
-            ptr_1001--; \
-        } \
-        fun_ptr_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_OTA"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)
+#include "gsw_ota_ua_interface.h"
+#include "gsw_log_interface.h"
 
-#define LOGW(fmt, args...) \
-    do{ \
-        char *file_ptr_1001 = __FILE__; \
-        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \
-        char line_1001[10] = {0}; \
-        sprintf(line_1001, "%d", __LINE__); \
-        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
-            if(*ptr_1001 == '/') \
-                 break; \
-            ptr_1001--; \
-        } \
-        fun_ptr_log(LOG_WARN_LEVEL, "%s#%s: "GSW_OTA"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)
 
-#define LOGE(fmt, args...) \
-    do{ \
-        char *file_ptr_1001 = __FILE__; \

-        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \
-        char line_1001[10] = {0}; \
-        sprintf(line_1001, "%d", __LINE__); \
-        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
-            if(*ptr_1001 == '/') \
-                 break; \
-            ptr_1001--; \
-        } \
-        fun_ptr_log(LOG_ERR_LEVEL, "%s#%s: "GSW_OTA"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)

-    

-

-typedef enum

-{

-    GSW_UPDATE_SUCCEED = 0, //update succeed

-    GSW_UPDATE_INPROGRESS,  //update in progress

-    GSW_UPDATE_BACKUP,      //A/B partition sync in progress

-    GSW_UPDATE_FAILED,      //update failed

-    GSW_UPDATE_WAITEDONE,   //update in-active part finished,not switch update part.

-    GSW_UPDATE_NEEDSYNC,    //switch update part, need sync A/B part

-    GSW_UPDATE_CANCEL       //updata cancel success

-}gsw_update_state_t;

-

-typedef enum

-{

-    GSW_UPDATE_NOERROR=0,          //升级成功

-    GSW_UPDATE_ARGUMENTERROR,      //升级程序启动参数错误

-    GSW_UPDATE_SDCARDNOEXIST,      //未挂载外置FLASH等存储设备

-    GSW_UPDATE_PACKAGENOEXIST,     //升级包不存在

-    GSW_UPDATE_UNZIPFAILED,        //解压升级包出错

-    GSW_UPDATE_PARTITIONFLUSHERROR,//写入分区出错

-    GSW_UPDATE_XMLPARSEERROR,      //解析 fotaconfig.xml 文件出错

-    GSW_UPDATE_DIFFUBIUNATTACH,    //差分升级 UBI 分区挂载异常

-    GSW_UPDATE_NOSPACELEFT,        //空间不足

-    GSW_UPDATE_FILECHECKFAILED,    //MD5 值校验失败

-    GSW_UPDATE_BSPATCHFAILED,      //bspatch 合成新文件夹失败

-    GSW_UPDATE_NOFINDPARTITION,    //待升级分区不存在

-    GSW_UPDATE_UBIVOLUMEERROR,      //差分升级,待升级 UBI 卷不存在

-    GSW_UPDATE_NOFOTACONFIGFILE,   //升级包中无 fotaconfig.xml 文件

-    GSW_UPDATE_GETOLDSOFTWAREFAILED,//读取原始版本固件失败

-    GSW_UPDATE_FILENOTEXIST,       //文件不存在

-    GSW_UPDATE_UPGRADECANCELED,    //升级或分区同步被取消

-    GSW_UPDATE_NONEEDCANCEL,       //取消升级失败

-    GSW_UPDATE_NOGOING             //升级或分区同步正在进行,不可重复操作

-}gsw_update_exit_code_t;

-

-

-typedef struct

-{

-    unsigned int percentage; //update progress0-100

-    gsw_update_state_t update_state;

-    gsw_update_exit_code_t exit_code; 

-}gsw_update_info_s;

-

-typedef struct

-{

-    gsw_update_state_t update_state;

-    uint8_t is_damaged; //TURE: damaged FALSE:no damaged

-    uint8_t damaged_partname[16];

-}gsw_system_status_s;

-

-typedef int  (*mbtk_fota_get_active_absys_type)(void);

-typedef int  (*mbtk_fota_fw_write)(char* fname, int segment_size);

-typedef int  (*mbtk_fota_fw_write_by_url)(char* url, int segment_size,

-                            int conn_timeout, int download_timeout);

-

-typedef int(*fota_callback)(int state, int percent);

-typedef int  (*mbtk_fota_init)(fota_callback cb);

-typedef int  (*mbtk_fota_status)(void);

-

-typedef void (*mbtk_log)(int level, const char *format,...);

-

-static int segment_size =0;

-static int Process_flag = 0;

-char  addr_buf[256] = {0};

-static void *handle = NULL;

-static mbtk_log fun_ptr_log = NULL;

-

-static int s_ota_flag = -1;

-

-int fota_cb(int status, int percent)

-{

-    Process_flag = percent;

-    return 0;

-}

-

-static int funstat(  char *filename)

+#define LYNQ_OTA_INPROCESS 3
+#define LYNQ_OTA_SUCCESS   4
+#define LYNQ_OTA_FAILED   5
+
+
+
+#define LIB_PATH "/lib/libmbtk_lib.so"
+
+#define GSW_OTA "[HAL][GSW_OTA]"
+
+#define StatFunc(x,y) stat(x,y)
+
+typedef enum
+{
+    GSW_UPDATE_SUCCEED = 0, //update succeed
+    GSW_UPDATE_INPROGRESS,  //update in progress
+    GSW_UPDATE_BACKUP,      //A/B partition sync in progress
+    GSW_UPDATE_FAILED,      //update failed
+    GSW_UPDATE_WAITEDONE,   //update in-active part finished,not switch update part.
+    GSW_UPDATE_NEEDSYNC,    //switch update part, need sync A/B part
+    GSW_UPDATE_CANCEL       //updata cancel success
+}gsw_update_state_t;
+
+typedef enum
+{
+    GSW_UPDATE_NOERROR=0,          //升级成功
+    GSW_UPDATE_ARGUMENTERROR,      //升级程序启动参数错误
+    GSW_UPDATE_SDCARDNOEXIST,      //未挂载外置FLASH等存储设备
+    GSW_UPDATE_PACKAGENOEXIST,     //升级包不存在
+    GSW_UPDATE_UNZIPFAILED,        //解压升级包出错
+    GSW_UPDATE_PARTITIONFLUSHERROR,//写入分区出错
+    GSW_UPDATE_XMLPARSEERROR,      //解析 fotaconfig.xml 文件出错
+    GSW_UPDATE_DIFFUBIUNATTACH,    //差分升级 UBI 分区挂载异常
+    GSW_UPDATE_NOSPACELEFT,        //空间不足
+    GSW_UPDATE_FILECHECKFAILED,    //MD5 值校验失败
+    GSW_UPDATE_BSPATCHFAILED,      //bspatch 合成新文件夹失败
+    GSW_UPDATE_NOFINDPARTITION,    //待升级分区不存在
+    GSW_UPDATE_UBIVOLUMEERROR,      //差分升级,待升级 UBI 卷不存在
+    GSW_UPDATE_NOFOTACONFIGFILE,   //升级包中无 fotaconfig.xml 文件
+    GSW_UPDATE_GETOLDSOFTWAREFAILED,//读取原始版本固件失败
+    GSW_UPDATE_FILENOTEXIST,       //文件不存在
+    GSW_UPDATE_UPGRADECANCELED,    //升级或分区同步被取消
+    GSW_UPDATE_NONEEDCANCEL,       //取消升级失败
+    GSW_UPDATE_NOGOING             //升级或分区同步正在进行,不可重复操作
+}gsw_update_exit_code_t;
+
+
+typedef struct
+{
+    unsigned int percentage; //update progress0-100
+    gsw_update_state_t update_state;
+    gsw_update_exit_code_t exit_code; 
+}gsw_update_info_s;
+
+typedef struct
+{
+    gsw_update_state_t update_state;
+    uint8_t is_damaged; //TURE: damaged FALSE:no damaged
+    uint8_t damaged_partname[16];
+}gsw_system_status_s;
+
+typedef int  (*mbtk_fota_get_active_absys_type)(void);
+typedef int  (*mbtk_fota_fw_write)(char* fname, int segment_size);
+typedef int  (*mbtk_fota_fw_write_by_url)(char* url, int segment_size,
+                            int conn_timeout, int download_timeout);
+
+typedef int(*fota_callback)(int state, int percent);
+typedef int  (*mbtk_fota_init)(fota_callback cb);
+typedef int  (*mbtk_fota_status)(void);
+
+static int segment_size =0;
+static int Process_flag = 0;
+char  addr_buf[256] = {0};
+static void *handle = NULL;
+
+
+static int s_ota_flag = -1;
+
+int fota_cb(int status, int percent)
+{
+    Process_flag = percent;
+    return 0;
+}
+
+static int funstat(  char *filename)
 {
     int ret = 0;
     struct stat tmep_s;
@@ -196,7 +108,7 @@
     
     if (ret)
     {
-        LOGE("stat %s failed! error_code: %s", filename ,strerror(errno));
+        LOGE(GSW_OTA, "stat %s failed! error_code:%s", filename ,strerror(errno));
         return -1;
     }
 
@@ -206,393 +118,384 @@
     }
 
     return 0;
-}

-

-int32_t init_handle()

-{

-    if(handle == NULL)

-    {

-        handle = dlopen(LIB_PATH, RTLD_NOW );

-        if(handle == NULL)

-        {

-            return GSW_HAL_NORMAL_FAIL;

-        }

-        if(fun_ptr_log == NULL)

-        {

-            fun_ptr_log = (mbtk_log)dlsym(handle, "mbtk_log");

-            if(fun_ptr_log ==  NULL)

-            {

-                return GSW_HAL_NORMAL_FAIL;

-            }

-        }

-       

-    }

-    

-

-    

-    return GSW_HAL_SUCCESS;

-}

-

-/**

-* @brief Start install modem software

-* @param  [in] char* file_path

-* @param  [out] NULL

-* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL

-*/

-int32_t gsw_update_modem_start_autobackup(char* file_path)

-{

-

-    if(file_path == NULL)

-    {

-        LOGE("invalid file_path \n");

-        return GSW_HAL_NORMAL_FAIL;

-    }

-    

-    

-    mbtk_fota_fw_write func_ptr_update = NULL;

-    mbtk_fota_init func_ptr_init= NULL;

-    mbtk_fota_fw_write_by_url func_ptr_update_url = NULL;

-    

-    

-        

-    int ret = -1;

-    ret = init_handle();

-    if(ret < 0)

-    {

-        LOGE("init_handle fail");

-        return GSW_HAL_NORMAL_FAIL;

-    }

-    

-    func_ptr_update_url = (mbtk_fota_fw_write_by_url)dlsym(handle, "mbtk_fota_fw_write_by_url");

-    if(func_ptr_update_url == NULL)

-    {

-        LOGE("Error: %s", dlerror());

-        return GSW_HAL_NORMAL_FAIL;

-    }

-

-    

-    // Get the function pointer 

-    func_ptr_update = (mbtk_fota_fw_write)dlsym(handle, "mbtk_fota_fw_write");

-    if (func_ptr_update == NULL)

-     {

-        LOGE("Error: %s", dlerror());

-        return GSW_HAL_NORMAL_FAIL;

-    }

-    

-    func_ptr_init = (mbtk_fota_init)dlsym(handle, "mbtk_fota_init");

-    if(func_ptr_init == NULL)

-     {

-        LOGE("Error: %s", dlerror());

-        return GSW_HAL_NORMAL_FAIL;

-    }

-    

-

-    if(s_ota_flag == -1)

-    {

-        ret = func_ptr_init(fota_cb);

-        if(ret < 0)

-        {

-            LOGE("Error: mbtk_fota_init failed");

-        

-            return GSW_HAL_NORMAL_FAIL;

-        }

-        else

-        {

-            s_ota_flag = 0;

-        }

-    }

-

-    if(strncmp(file_path, "http", 4) == 0)

-    {

-        segment_size = 62914560;

-        ret = func_ptr_update_url(file_path, segment_size,10, 600);

-    }

-    else

-    {

-        if(strstr(file_path,"fota.delta") == NULL)

-        {

-            LOGE("Bad file path ");

-            return GSW_HAL_NORMAL_FAIL;

-        }

-        else

-        {

-            if(access(file_path,F_OK) !=0)

-            {

-                LOGE("update  file no exist");

-                return GSW_HAL_NORMAL_FAIL;

-            }

-        }

-            

-        ret = funstat(file_path);

+}
+
+int32_t init_handle()
+{
+    if(handle == NULL)
+    {
+        handle = dlopen(LIB_PATH, RTLD_NOW );
+        if(handle == NULL)
+        {
+            return GSW_HAL_NORMAL_FAIL;
+        }
+    }
+    
+    return GSW_HAL_SUCCESS;
+}
+
+/**
+* @brief Start install modem software
+* @param  [in] char* file_path
+* @param  [out] NULL
+* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
+*/
+int32_t gsw_update_modem_start_autobackup(char* file_path)
+{
+
+    if(file_path == NULL)
+    {
+        LOGE(GSW_OTA, "invalid file_path \n");
+        return GSW_HAL_NORMAL_FAIL;
+    }
+    
+    
+    mbtk_fota_fw_write func_ptr_update = NULL;
+    mbtk_fota_init func_ptr_init= NULL;
+    mbtk_fota_fw_write_by_url func_ptr_update_url = NULL;
+    
+    
+        
+    int ret = -1;
+    ret = init_handle();
+    if(ret < 0)
+    {
+        LOGE(GSW_OTA, "init_handle fail");
+        return GSW_HAL_NORMAL_FAIL;
+    }
+    
+    func_ptr_update_url = (mbtk_fota_fw_write_by_url)dlsym(handle, "mbtk_fota_fw_write_by_url");
+    if(func_ptr_update_url == NULL)
+    {
+        LOGE(GSW_OTA, "Error: %s", dlerror());
+        return GSW_HAL_NORMAL_FAIL;
+    }
+
+    
+    // Get the function pointer 
+    func_ptr_update = (mbtk_fota_fw_write)dlsym(handle, "mbtk_fota_fw_write");
+    if (func_ptr_update == NULL)
+     {
+        LOGE(GSW_OTA, "Error: %s", dlerror());
+        return GSW_HAL_NORMAL_FAIL;
+    }
+    
+    func_ptr_init = (mbtk_fota_init)dlsym(handle, "mbtk_fota_init");
+    if(func_ptr_init == NULL)
+     {
+        LOGE(GSW_OTA, "Error: %s", dlerror());
+        return GSW_HAL_NORMAL_FAIL;
+    }
+    
+
+    if(s_ota_flag == -1)
+    {
+        ret = func_ptr_init(fota_cb);
+        if(ret < 0)
+        {
+            LOGE(GSW_OTA, "Error: mbtk_fota_init failed");
+        
+            return GSW_HAL_NORMAL_FAIL;
+        }
+        else
+        {
+            s_ota_flag = 0;
+        }
+    }
+
+    if(strncmp(file_path, "http", 4) == 0)
+    {
+        segment_size = 62914560;
+        ret = func_ptr_update_url(file_path, segment_size,10, 600);
+    }
+    else
+    {
+        if(strstr(file_path,"fota.delta") == NULL)
+        {
+            LOGE(GSW_OTA, "Bad file path ");
+            return GSW_HAL_NORMAL_FAIL;
+        }
+        else
+        {
+            if(access(file_path,F_OK) !=0)
+            {
+                LOGE(GSW_OTA, "update  file no exist");
+                return GSW_HAL_NORMAL_FAIL;
+            }
+        }
+            
+        ret = funstat(file_path);
         if (ret)
         {
-            LOGE("get segment_size fail");

-            return GSW_HAL_NORMAL_FAIL;  

-        }

-        ret = func_ptr_update(file_path, segment_size);

-        if(ret < 0)

-        {

-            LOGE("Error: mbtk_fota_fw_write failed\n");

-            return GSW_HAL_NORMAL_FAIL;

-        }

-     }

-    return GSW_HAL_SUCCESS;

-

-}

-

-/**

-* @brief check the modem update condition

-* @param  [in] NULL

-* @param  [out] NULL

-* @retval TRUE/FALSE

-*/

-bool gsw_update_modem_check_condition(void)

-{

-    char command[32] = {0};

-    char buffer[64] = {0};

-    const char *process_ota = "{otad}";

-

-    snprintf(command,sizeof(command), "ps | grep %s | grep -v grep", process_ota);

-    FILE *fp = popen(command, "r");

-    if (fp == NULL) 

-    {

-        return false;

-    }

-    

-    if(fgets(buffer, sizeof(buffer), fp)!= NULL)

-    {

-        pclose(fp);

-        return true;

-    }

-    pclose(fp);

-    return false;

-

-}

-

-/**

-* @brief get update modem result

-* @param  [in] NULL

-* @param  [out] NULL

-* @retval E_GSW_OTA_RET

-*/

-int32_t gsw_update_modem_result_query(void)

-{   

-   

-    mbtk_fota_status func_ptr_get_result = NULL;

-    int ret = -1;

-    

-    ret = init_handle();

-    if(ret < 0)

-    {

-        LOGE("init_handle fail");

-        return GSW_HAL_NORMAL_FAIL;

-    }

-    

-    // Get the function pointer 

-    func_ptr_get_result = (mbtk_fota_status)dlsym(handle, "mbtk_fota_status");

-    if (func_ptr_get_result == NULL)

-     {

-        LOGE("Error: %s\n", dlerror());

-        return GSW_HAL_NORMAL_FAIL;

-    }

-    ret = func_ptr_get_result();

-    if(ret < 0 && ret !=-1)

-    {

-        LOGE("Error: mbtk_fota_status failed\n");

-        return GSW_HAL_NORMAL_FAIL;

-    }

-

-    

-    if(ret == LYNQ_OTA_INPROCESS)

-    {

-        return GSW_OTA_INPROCESS;

-

-    }

-    else if(ret == LYNQ_OTA_SUCCESS)

-    {

-        return GSW_OTA_SUCCESS;

-    }

-    else if(ret == -1)

-    {

-        return GSW_OTA_NO_TASK;

-    }

-    

-    return GSW_OTA_FAILURE;

-    

-    

-}

-

-/**

-* @brief Start install modem software

-* @param  [in] char* file_path

-* @param  [out] NULL

-* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL

-*/

-int32_t gsw_update_modem_start_nobackup(char* file_path)

-{

-    

-    return GSW_HAL_SUCCESS;

-}

-

-

-/**

-* @brief get current system

-* @param  [in] NULL

-* @param  [out] NULL

-* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL

-*/

-int32_t gsw_update_modem_get_system(void)

-{

-    int ret = -1;

-   

-    mbtk_fota_get_active_absys_type func_ptr;

-    ret = init_handle();

-    if(ret < 0)

-    {

-        LOGE("init_handle fail");

-        return GSW_HAL_NORMAL_FAIL;

-    }

-

-    // Get the function pointer 

-    func_ptr = (mbtk_fota_get_active_absys_type)dlsym(handle, "mbtk_fota_get_active_absys_type");

-    if (func_ptr == NULL)

-     {

-        LOGE("Error: %s", dlerror());

-        return GSW_HAL_NORMAL_FAIL;

-    }

-    ret = func_ptr();

-    if(ret < 0)

-    {

-        LOGE("Error: mbtk_fota_get_active_absys_type failed");

-        return GSW_HAL_NORMAL_FAIL;

-

-    }

-    

-    

-    return ret;

-

-}

-

-/**

-* @brief cancel update

-* @param  [in] NULL

-* @param  [out] NULL

-* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL

-*/

-int32_t gsw_update_modem_cancel(void)

-{

-    

-    return GSW_HAL_SUCCESS;

-}

-

-/**

-* @brief get modem update info

-* @param  [in] NULL

-* @param  [out] gsw_update_info_s 

-* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL

-*/

-int32_t gsw_update_modem_get_info(gsw_update_info_s *update_info)

-{

-    int ret = -1;

-        

-    mbtk_fota_status     func_ptr_get_info = NULL;

-    

-    ret = init_handle();

-    if(ret < 0)

-    {

-        LOGE("init_handle fail");

-        return GSW_HAL_NORMAL_FAIL;

-    }

-    

-    // Get the function pointer 

-    func_ptr_get_info = (mbtk_fota_status)dlsym(handle, "mbtk_fota_status");

-    if (func_ptr_get_info == NULL)

-     {

-        LOGE("Error: %s\n", dlerror());

-        return GSW_HAL_NORMAL_FAIL;

-    }

-    ret = func_ptr_get_info();

-    if(ret < 0 &&  ret != -1)

-    {

-        LOGE("Error: mbtk_fota_status failed\n");

-        return GSW_HAL_NORMAL_FAIL;

-    }

-

-    //升级成功之后,未重启,不可重复升级

-    if(ret == LYNQ_OTA_INPROCESS)

-    {

-        update_info->exit_code = GSW_UPDATE_NOGOING;

-        update_info->percentage = Process_flag;

-        update_info->update_state = GSW_UPDATE_INPROGRESS;

-    }

-    if(ret == LYNQ_OTA_SUCCESS)

-    {

-        update_info->exit_code = GSW_UPDATE_NOERROR;

-        update_info->percentage = Process_flag;

-        update_info->update_state = GSW_UPDATE_WAITEDONE;

-    }

-

-    

-    if(ret == LYNQ_OTA_FAILED || ret == -1)

-    {

-        update_info->exit_code = GSW_UPDATE_GETOLDSOFTWAREFAILED;

-        update_info->percentage = Process_flag;

-        update_info->update_state = GSW_UPDATE_FAILED;

-    }

-    

-    return GSW_HAL_SUCCESS;

-

-}

-

-

-/**

-* @brief get modem system status

-* @param  [in] NULL

-* @param  [out] gsw_system_status_s 

-* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL

-*/

-int32_t gsw_update_modem_get_status(gsw_system_status_s *system_status)

-{

-    return GSW_HAL_SUCCESS;

-}

-

-/**

-* @brief A/B system sync

-* @param  [in] NULL

-* @param  [out] NULL 

-* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL

-*/

-int32_t gsw_update_modem_sync(void)

-{

-    return GSW_HAL_SUCCESS;

-

-}

-

-/**

-* @brief A/B system switch

-* @param  [in] NULL

-* @param  [out] NULL 

-* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL

-*/

-int32_t gsw_update_modem_switch(void)

-{

-    return GSW_HAL_SUCCESS;

-}

-

-int32_t gsw_update_modem_process(void *bufdata)

-{

-    return gsw_update_modem_start_autobackup(UPDATE_MODEM_PACKAGE);

-}

-

-int32_t gsw_get_ab_system(gsw_system_type *type)

-{

-    int32_t ret = GSW_HAL_NORMAL_FAIL;

-

-    ret = gsw_update_modem_get_system();

-    if (GSW_HAL_NORMAL_FAIL != ret)

-    {

-        *type = (gsw_system_type)ret;

-    }

-

-    return ret;

-}

+            LOGE(GSW_OTA, "get segment_size fail");
+            return GSW_HAL_NORMAL_FAIL;  
+        }
+        ret = func_ptr_update(file_path, segment_size);
+        if(ret < 0)
+        {
+            LOGE(GSW_OTA, "Error: mbtk_fota_fw_write failed\n");
+            return GSW_HAL_NORMAL_FAIL;
+        }
+     }
+    return GSW_HAL_SUCCESS;
+
+}
+
+/**
+* @brief check the modem update condition
+* @param  [in] NULL
+* @param  [out] NULL
+* @retval TRUE/FALSE
+*/
+bool gsw_update_modem_check_condition(void)
+{
+    char command[32] = {0};
+    char buffer[64] = {0};
+    const char *process_ota = "{otad}";
+
+    snprintf(command,sizeof(command), "ps | grep %s | grep -v grep", process_ota);
+    FILE *fp = popen(command, "r");
+    if (fp == NULL) 
+    {
+        return false;
+    }
+    
+    if(fgets(buffer, sizeof(buffer), fp)!= NULL)
+    {
+        pclose(fp);
+        return true;
+    }
+    pclose(fp);
+    return false;
+
+}
+
+/**
+* @brief get update modem result
+* @param  [in] NULL
+* @param  [out] NULL
+* @retval E_GSW_OTA_RET
+*/
+int32_t gsw_update_modem_result_query(void)
+{   
+   
+    mbtk_fota_status func_ptr_get_result = NULL;
+    int ret = -1;
+    
+    ret = init_handle();
+    if(ret < 0)
+    {
+        LOGE(GSW_OTA, "init_handle fail");
+        return GSW_HAL_NORMAL_FAIL;
+    }
+    
+    // Get the function pointer 
+    func_ptr_get_result = (mbtk_fota_status)dlsym(handle, "mbtk_fota_status");
+    if (func_ptr_get_result == NULL)
+     {
+        LOGE(GSW_OTA, "Error: %s\n", dlerror());
+        return GSW_HAL_NORMAL_FAIL;
+    }
+    ret = func_ptr_get_result();
+    if(ret < 0 && ret !=-1)
+    {
+        LOGE(GSW_OTA, "Error: mbtk_fota_status failed\n");
+        return GSW_HAL_NORMAL_FAIL;
+    }
+
+    
+    if(ret == LYNQ_OTA_INPROCESS)
+    {
+        return GSW_OTA_INPROCESS;
+
+    }
+    else if(ret == LYNQ_OTA_SUCCESS)
+    {
+        return GSW_OTA_SUCCESS;
+    }
+    else if(ret == -1)
+    {
+        return GSW_OTA_NO_TASK;
+    }
+    
+    return GSW_OTA_FAILURE;
+    
+    
+}
+
+/**
+* @brief Start install modem software
+* @param  [in] char* file_path
+* @param  [out] NULL
+* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
+*/
+int32_t gsw_update_modem_start_nobackup(char* file_path)
+{
+    
+    return GSW_HAL_SUCCESS;
+}
+
+
+/**
+* @brief get current system
+* @param  [in] NULL
+* @param  [out] NULL
+* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
+*/
+int32_t gsw_update_modem_get_system(void)
+{
+    int ret = -1;
+   
+    mbtk_fota_get_active_absys_type func_ptr;
+    ret = init_handle();
+    if(ret < 0)
+    {
+        LOGE(GSW_OTA, "init_handle fail");
+        return GSW_HAL_NORMAL_FAIL;
+    }
+
+    // Get the function pointer 
+    func_ptr = (mbtk_fota_get_active_absys_type)dlsym(handle, "mbtk_fota_get_active_absys_type");
+    if (func_ptr == NULL)
+     {
+        LOGE(GSW_OTA, "Error: %s", dlerror());
+        return GSW_HAL_NORMAL_FAIL;
+    }
+    ret = func_ptr();
+    if(ret < 0)
+    {
+        LOGE(GSW_OTA, "Error: mbtk_fota_get_active_absys_type failed");
+        return GSW_HAL_NORMAL_FAIL;
+
+    }
+    
+    
+    return ret;
+
+}
+
+/**
+* @brief cancel update
+* @param  [in] NULL
+* @param  [out] NULL
+* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
+*/
+int32_t gsw_update_modem_cancel(void)
+{
+    
+    return GSW_HAL_SUCCESS;
+}
+
+/**
+* @brief get modem update info
+* @param  [in] NULL
+* @param  [out] gsw_update_info_s 
+* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
+*/
+int32_t gsw_update_modem_get_info(gsw_update_info_s *update_info)
+{
+    int ret = -1;
+        
+    mbtk_fota_status     func_ptr_get_info = NULL;
+    
+    ret = init_handle();
+    if(ret < 0)
+    {
+        LOGE(GSW_OTA, "init_handle fail");
+        return GSW_HAL_NORMAL_FAIL;
+    }
+    
+    // Get the function pointer 
+    func_ptr_get_info = (mbtk_fota_status)dlsym(handle, "mbtk_fota_status");
+    if (func_ptr_get_info == NULL)
+     {
+        LOGE(GSW_OTA, "Error: %s\n", dlerror());
+        return GSW_HAL_NORMAL_FAIL;
+    }
+    ret = func_ptr_get_info();
+    if(ret < 0 &&  ret != -1)
+    {
+        LOGE(GSW_OTA, "Error: mbtk_fota_status failed\n");
+        return GSW_HAL_NORMAL_FAIL;
+    }
+
+    //升级成功之后,未重启,不可重复升级
+    if(ret == LYNQ_OTA_INPROCESS)
+    {
+        update_info->exit_code = GSW_UPDATE_NOGOING;
+        update_info->percentage = Process_flag;
+        update_info->update_state = GSW_UPDATE_INPROGRESS;
+    }
+    if(ret == LYNQ_OTA_SUCCESS)
+    {
+        update_info->exit_code = GSW_UPDATE_NOERROR;
+        update_info->percentage = Process_flag;
+        update_info->update_state = GSW_UPDATE_WAITEDONE;
+    }
+
+    
+    if(ret == LYNQ_OTA_FAILED || ret == -1)
+    {
+        update_info->exit_code = GSW_UPDATE_GETOLDSOFTWAREFAILED;
+        update_info->percentage = Process_flag;
+        update_info->update_state = GSW_UPDATE_FAILED;
+    }
+    
+    return GSW_HAL_SUCCESS;
+
+}
+
+
+/**
+* @brief get modem system status
+* @param  [in] NULL
+* @param  [out] gsw_system_status_s 
+* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
+*/
+int32_t gsw_update_modem_get_status(gsw_system_status_s *system_status)
+{
+    return GSW_HAL_SUCCESS;
+}
+
+/**
+* @brief A/B system sync
+* @param  [in] NULL
+* @param  [out] NULL 
+* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
+*/
+int32_t gsw_update_modem_sync(void)
+{
+    return GSW_HAL_SUCCESS;
+
+}
+
+/**
+* @brief A/B system switch
+* @param  [in] NULL
+* @param  [out] NULL 
+* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
+*/
+int32_t gsw_update_modem_switch(void)
+{
+    return GSW_HAL_SUCCESS;
+}
+
+int32_t gsw_update_modem_process(void *bufdata)
+{
+    return gsw_update_modem_start_autobackup(UPDATE_MODEM_PACKAGE);
+}
+
+int32_t gsw_get_ab_system(gsw_system_type *type)
+{
+    int32_t ret = GSW_HAL_NORMAL_FAIL;
+
+    ret = gsw_update_modem_get_system();
+    if (GSW_HAL_NORMAL_FAIL != ret)
+    {
+        *type = (gsw_system_type)ret;
+    }
+
+    return ret;
+}
+
+
diff --git a/mbtk/libgsw_lib/gsw_sys_interface.c b/mbtk/libgsw_lib/gsw_sys_interface.c
index 21656e3..e674fd6 100755
--- a/mbtk/libgsw_lib/gsw_sys_interface.c
+++ b/mbtk/libgsw_lib/gsw_sys_interface.c
@@ -6,206 +6,95 @@
 #include <stddef.h>
 #include <dlfcn.h>
 #include "gsw_sys_interface.h"
+#include "gsw_log_interface.h"
 #define  LOG_LEVLE_CONFIG_FILE "/etc/telinit"
-#define  SSH_STATE_FILE "/tmp/ssh_mode"
-#define  FTP_STATE_FILE "/tmp/ftp_mode"
-#define  LIB_PATH		"/lib/libmbtk_lib.so"
-typedef void (*mbtk_log)(int level, const char *format,...);
-#ifndef LOG_ERR_LEVEL
-#define LOG_ERR_LEVEL  3      /* error conditions */
-#endif
-#define LOGE(fun_ptr_log, fmt, args...) \
-    do{ \
-        char *file_ptr_1001 = __FILE__; \
-        char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1;   \
-        char line_1001[10] = {0}; \
-        sprintf(line_1001, "%d", __LINE__); \
-        while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
-            if(*ptr_1001 == '/') \
-                 break; \
-            ptr_1001--; \
-        } \
-        fun_ptr_log(LOG_ERR_LEVEL,  "%s#%s: [gsw_sys]" fmt, ptr_1001 + 1, line_1001, ##args); \
-    } while(0)
-void write_mode_to_file(const char *file ,const char *mode)
-{
-	FILE *fp = fopen(file, "w");
-	if (!fp)
-	{
-		perror("Failed to open state file for writing");
-		return;
-	}
-	fprintf(fp, "%s\n", mode);
-	fclose(fp);
-}
-int read_mode_from_file(const char *file, char *mode, size_t size)
-{
-	FILE *fp = fopen(file, "r");
-	if (!fp)
-	{
-		return GSW_HAL_NORMAL_FAIL;  // No mode recorded
-	}
-	if (!fgets(mode, size, fp))
-	{
-		fclose(fp);		
-		return GSW_HAL_NORMAL_FAIL;
-	}
-	mode[strcspn(mode, "\n")] = '\0';
-	fclose(fp);
-	return GSW_HAL_SUCCESS;
-}
+
+#define GSW_SYS "[HAL][GSW_SYS]"
 int gsw_sys_svr_ftp_start(const char *cfg)
 {
 	int ret = GSW_HAL_SUCCESS;
 	char command[128];
-	mbtk_log fun_ptr_log;
-	void *handle = dlopen(LIB_PATH, RTLD_NOW);
-	if(NULL == handle)
-		return GSW_HAL_NORMAL_FAIL;
-	
-	fun_ptr_log = (mbtk_log)dlsym(handle, "mbtk_log");
-	if(fun_ptr_log ==  NULL)
-	{
-		ret = GSW_HAL_NORMAL_FAIL;
-		goto exit;
-	}
-	
+
 	if(NULL == cfg)
 	{
-		write_mode_to_file(FTP_STATE_FILE, "init.d");
 		strcpy(command, "/etc/init.d/vsftpd start");
 	}
 	else
 	{
-		write_mode_to_file(FTP_STATE_FILE, "vsftpd");
 		snprintf(command, sizeof(command), "vsftpd %s &", cfg);
 	}
 	ret = system(command);
 	if(ret != 0) {
-		LOGE(fun_ptr_log, "command execution failed command:%s.\n", command);
+		LOGE(GSW_SYS, "command execution failed command:%s.\n", command);
 		goto exit;
 	}
 exit:
-	dlclose(handle);
-	handle = NULL;
 	return ret;
 }
 int gsw_sys_svr_ftp_stop()
 {
 	int ret = GSW_HAL_SUCCESS;
-	char command[64];
-	char mode[64];
-	mbtk_log fun_ptr_log;
-	void *handle = dlopen(LIB_PATH, RTLD_NOW);
-	if(NULL == handle)
-		return GSW_HAL_NORMAL_FAIL;
 	
-	fun_ptr_log = (mbtk_log)dlsym(handle, "mbtk_log");
-	if(fun_ptr_log ==  NULL)
-	{
-		ret = GSW_HAL_NORMAL_FAIL;
-		goto exit;
-	}
-	
-	ret = read_mode_from_file(FTP_STATE_FILE, mode, sizeof(mode));
-	if(0 != ret)
-	{
-		LOGE(fun_ptr_log, "read file:%s error\n", FTP_STATE_FILE);
-		goto exit;
-	}
-	if(strlen(mode) == 0 || strcmp("init.d", mode) == 0)    //strlen(mode)==0为第一次执行
-		strcpy(command, "/etc/init.d/vsftpd stop");
-	else
-		strcpy(command, "killall -TERM vsftpd");
-	
-	ret = system(command);
+	ret = system("/etc/init.d/vsftpd stop");
 	if(ret != 0) 
 	{
-		LOGE(fun_ptr_log, "command execution failed command:%s.\n", command);
-		goto exit;
+		LOGE(GSW_SYS, "command /etc/init.d/vsftpd stop execution failed\n");
+		printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret);
+		ret = system("killall -TERM vsftpd");
+		if(ret != 0)
+		{
+			printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret);
+			LOGE(GSW_SYS, "command killall -TERM vsftpd execution failed\n");
+			goto exit;
+		}
 	}
 	
 exit:
-	dlclose(handle);
-	handle = NULL;
 	return ret;
 }
 int gsw_sys_svr_ssh_start(const char *cfg)
 {
 	int ret= GSW_HAL_SUCCESS;
 	char command[128];
-	mbtk_log fun_ptr_log;
-	void *handle = dlopen(LIB_PATH, RTLD_NOW);
-	if(NULL == handle)
-		return GSW_HAL_NORMAL_FAIL;
-	
-	fun_ptr_log = (mbtk_log)dlsym(handle, "mbtk_log");
-	if(fun_ptr_log ==  NULL)
-	{
-		ret = GSW_HAL_NORMAL_FAIL;
-		goto exit;
-	}
 		
 	if(NULL == cfg)
 	{			
-		write_mode_to_file(SSH_STATE_FILE, "init.d");
 		strcpy(command, "/etc/init.d/sshd start");
 	}
 	else
 	{
-		write_mode_to_file(SSH_STATE_FILE, "sshd");
 		snprintf(command, sizeof(command), "/usr/sbin/sshd -f %s &", cfg);
 	}
 	
 	ret = system(command);
 	if(ret != 0)
 	{
-		LOGE(fun_ptr_log, "command execution failed command:%s.\n", command);
+		LOGE(GSW_SYS, "command execution failed command:%s.\n", command);
 		goto exit;
 	}
 	
-exit:	
-	dlclose(handle);
-	handle = NULL;
+exit:
 	return ret;
 }
 int gsw_sys_svr_ssh_stop()
 {
 	int ret = GSW_HAL_SUCCESS;
-	char command[64];
-	char mode[64];
-	mbtk_log fun_ptr_log;
-	void *handle = dlopen(LIB_PATH, RTLD_NOW);
-	if(NULL == handle)
-		return GSW_HAL_NORMAL_FAIL;
 	
-	fun_ptr_log = (mbtk_log)dlsym(handle, "mbtk_log");
-	if(fun_ptr_log ==  NULL)
-	{
-		ret = GSW_HAL_NORMAL_FAIL;
-		goto exit;
-	}
-	
-	ret = read_mode_from_file(SSH_STATE_FILE, mode, sizeof(mode));
-	if(0 != ret)
-	{
-		LOGE(fun_ptr_log, "read file:%s error\n", SSH_STATE_FILE);
-		goto exit;
-	}
-	if(strlen(mode) == 0 || strcmp("init.d", mode) == 0)    //strlen(mode)==0为第一次执行
-		strcpy(command, "/etc/init.d/sshd stop");
-	else
-		strcpy(command, "killall sshd");
-	ret = system(command);
+	ret = system("/etc/init.d/sshd stop");
 	if(ret != 0) 
 	{
-		LOGE(fun_ptr_log, "command execution failed command:%s.\n", command);
-		goto exit;
+		printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret);
+		LOGE(GSW_SYS, "command /etc/init.d/sshd stop sshd execution failed\n");
+		ret = system("killall sshd");
+		if(ret != 0)
+		{
+			printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret);
+			LOGE(GSW_SYS, "command killall sshd execution failed\n");
+			goto exit;
+		}
 	}
 	
-exit:	
-	dlclose(handle);
-	handle = NULL;
+exit:
 	return ret;
 }
 int gsw_sys_svr_syslog_restart(const char *log_lvl)
@@ -216,17 +105,6 @@
 	int level = 0;
 	char *log_level_params[8] = {"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"};
 	char *log_level_values[8] = {"1", "2", "3", "4", "5", "6", "7", "8"};
-	mbtk_log fun_ptr_log;
-	void *handle = dlopen(LIB_PATH, RTLD_NOW);
-	if(NULL == handle)
-		return GSW_HAL_NORMAL_FAIL;
-	
-	fun_ptr_log = (mbtk_log)dlsym(handle, "mbtk_log");
-	if(fun_ptr_log ==  NULL)
-	{
-		ret = GSW_HAL_NORMAL_FAIL;
-		goto exit;
-	}
 	snprintf(command, sizeof(command), 
 			 "grep -q 'setprop sys.default.loglevel' %s", LOG_LEVLE_CONFIG_FILE);
 	for(level = 0; level < 8; level++)
@@ -236,7 +114,7 @@
 	}
 	if(8 == level)
 	{
-		LOGE(fun_ptr_log, "Parameter error\n");
+		LOGE(GSW_SYS, "Parameter error\n");
 		ret = GSW_HAL_NORMAL_FAIL;
 	    goto exit;
 	}
@@ -244,7 +122,7 @@
 	ret = system(command);
 	if (ret != 0)
 	{
-		LOGE(fun_ptr_log, "config option not exist.\n");
+		LOGE(GSW_SYS, "config option not exist.\n");
 	    goto exit;
 	}
 	snprintf(command, sizeof(command), 
@@ -254,12 +132,10 @@
 	ret = system(command);
 	if (ret != 0)
 	{
-	    LOGE(fun_ptr_log, "command execution failed.\n");
+	    LOGE(GSW_SYS, "command execution failed.\n");
 	    goto exit;
 	}
-exit:	
-	dlclose(handle);
-	handle = NULL;
+exit:
 	return ret;
 }