Merge "[Bugfix][T108][bug-view-1208]Fix printing errors in gnss-test" into GSW_V1453
diff --git a/mbtk/libgsw_lib/gsw_at_interface.c b/mbtk/libgsw_lib/gsw_at_interface.c
index 6620d25..c17bbea 100755
--- a/mbtk/libgsw_lib/gsw_at_interface.c
+++ b/mbtk/libgsw_lib/gsw_at_interface.c
@@ -15,94 +15,7 @@
 #include <stdbool.h>

 #include "gsw_at_interface.h"

 #include "gsw_hal_errcode.h"

-

-#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 GSW_AT "[HAL][GSW_AT]"

-

-#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_AT"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)

-

-#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_AT"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)

-

-#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_AT"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)

-

-#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_AT"" 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_AT"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)

+#include "gsw_log_interface.h"

 

 #define OUT_MAX_SIZE 1024

 #define LINE __LINE__

@@ -111,15 +24,15 @@
 #define SOCKET_ZERO   0

 #define SOCKET_SUCC   1

 #define SOCKET_FAIL  -1

-

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

+#define GSW_AT "[HAL][GSW_AT]"

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

 typedef enum

 {

     A_SUCCESS = 0,

     A_ERROR = -1

 }LYNQ_AT_E;

 

-static mbtk_log fun_ptr_log = NULL;

+//static mbtk_log fun_ptr_log = NULL;

 static void *dlHandle_at = NULL;

 char *lynqLib_at = "/lib/libmbtk_lib.so";

 char *output = NULL;

@@ -135,11 +48,11 @@
 

 

 int socket_local_client (char* name) {

-    LOGD("[%d][%s] enter",LINE,FUNC);

+    LOGD(GSW_AT,"[%d][%s] enter",LINE,FUNC);

     sockfd = socket(AF_UNIX, SOCK_STREAM, 0);

     if (sockfd < 0)

     {

-        LOGD("Can't open stream socket (%s)", name);

+        LOGD(GSW_AT,"Can't open stream socket (%s)", name);

         return -1;

     }

     addr_server.sun_family = AF_UNIX;

@@ -148,32 +61,32 @@
     if (connect(sockfd, (struct sockaddr *) &addr_server, sizeof(struct sockaddr_un)) < 0)

     {

         close(sockfd);

-        LOGD("Can't connect to server side, path: %s, %s", name, strerror(errno));

+        LOGD(GSW_AT,"Can't connect to server side, path: %s, %s", name, strerror(errno));

         return -1;

     }

-    LOGD("[%d][%s] connect %s success",LINE,FUNC,name);

+    LOGD(GSW_AT,"[%d][%s] connect %s success",LINE,FUNC,name);

     return sockfd;

 }

 bool send_msg_to_service(int fd,char *msg,int size)

 {

-    LOGD("[%d][%s] enter",LINE,FUNC);

+    LOGD(GSW_AT,"[%d][%s] enter",LINE,FUNC);

     if (fd < 0)

     {

-        LOGD("fd invalid when send to atci service. errno = %d", errno);

+        LOGD(GSW_AT,"fd invalid when send to atci service. errno = %d", errno);

         return false;

     }

     if(NULL == msg)

     {

-        LOGD("atcmd is null.");

+        LOGD(GSW_AT,"atcmd is null.");

         return false;

     }

     int sendLen = send(fd, msg, size, 0);

     if (sendLen != size)

     {

-        LOGD("lose data when send to atci service. errno = %d", errno);

+        LOGD(GSW_AT,"lose data when send to atci service. errno = %d", errno);

         return false;

     }

-    LOGD("client send to app demo: %s", msg);

+    LOGD(GSW_AT,"client send to app demo: %s", msg);

     return true;

 }

 

@@ -181,15 +94,15 @@
 {

     int ret = 0;

     ret = recv(fd, buf, len, 0);

-    LOGD("[%d][%s] recv after",LINE,FUNC);

+    LOGD(GSW_AT,"[%d][%s] recv after",LINE,FUNC);

     if (ret < 0)

     {

-        LOGD("acti_cmd_recv client select error, ret=%d, error=%s(%d),fd=%d", ret,strerror(errno), errno, fd);

+        LOGD(GSW_AT,"acti_cmd_recv client select error, ret=%d, error=%s(%d),fd=%d", ret,strerror(errno), errno, fd);

         return SOCKET_FAIL;

     }

     else if(ret == 0)

     {

-        LOGD("acti_cmd_recv client recv error, ret=%d, error=%s(%d),fd=%d", ret,strerror(errno), errno, fd);

+        LOGD(GSW_AT,"acti_cmd_recv client recv error, ret=%d, error=%s(%d),fd=%d", ret,strerror(errno), errno, fd);

         return SOCKET_ZERO;

     }

   return SOCKET_SUCC;

@@ -202,14 +115,14 @@
  */

 void *thread_recv(void *parm)

 {

-    LOGD("[%d][%s] enter",LINE,FUNC);

+    LOGD(GSW_AT,"[%d][%s] enter",LINE,FUNC);

     char at_cmd[100] = {0};

     int fd = -1;

     int ret = 0;

     fd = socket_local_client(AT_EXTERSION_SOCKET_NAME);

     if(fd <= 0)

     {

-        LOGE("socket_local_client  fail\n");

+        LOGE(GSW_AT,"socket_local_client  fail\n");

         connect_state = false;

         pthread_mutex_unlock(&s_startupMutex);

         return NULL;

@@ -217,7 +130,7 @@
     int len_buf = strlen(buffer_at);

     if(!send_msg_to_service(fd,buffer_at,len_buf))

     {

-        LOGE("send_msg_to_service  fail\n");

+        LOGE(GSW_AT,"send_msg_to_service  fail\n");

         connect_state = false;

         pthread_mutex_unlock(&s_startupMutex);

         return NULL;

@@ -228,7 +141,7 @@
     output = (char *)malloc(sizeof(char)*OUT_MAX_SIZE);

     if(NULL == output)

     {

-        LOGE("thread_recv malloc fail\n");

+        LOGE(GSW_AT,"thread_recv malloc fail\n");

         return NULL;

     }

     TryNewLink:

@@ -237,7 +150,7 @@
         if (connect(fd, (struct sockaddr *) &addr_server, sizeof(struct sockaddr_un)) < 0)

         {

             close(fd);

-            LOGE("Can't connect to server side, path: %s, errno:%d", AT_EXTERSION_SOCKET_NAME, errno);

+            LOGE(GSW_AT,"Can't connect to server side, path: %s, errno:%d", AT_EXTERSION_SOCKET_NAME, errno);

             return NULL;

         }

         connect_state = true;

@@ -249,12 +162,12 @@
         ret = atsvc_cmd_recv(fd, at_cmd,sizeof(at_cmd));

         if (ret < 0)

         {

-            LOGE("[%d][%s]receive CMD error",LINE,FUNC);

+            LOGE(GSW_AT,"[%d][%s]receive CMD error",LINE,FUNC);

             continue;

         }

         else if(ret == SOCKET_ZERO)

         {

-            LOGE("maybe client socket closed 1. retry new link!");

+            LOGE(GSW_AT,"maybe client socket closed 1. retry new link!");

             connect_state = false;

             goto TryNewLink;

         }

@@ -266,10 +179,10 @@
 	    }

         //begin deal with callback

         tmp(input, output, OUT_MAX_SIZE);

-        LOGD("lynq_reg_third_at send output to service\n");

+        LOGD(GSW_AT,"lynq_reg_third_at send output to service\n");

         if(!send_msg_to_service(fd,output, strlen(output)))

         {

-            LOGE("thread_recv send fail\n");

+            LOGE(GSW_AT,"thread_recv send fail\n");

             continue;

         }

     }

@@ -289,14 +202,14 @@
  */

 int lynq_connect_service_start(void)

 {

-    LOGD("[%d][%s] enter",LINE,FUNC);

+    LOGD(GSW_AT,"[%d][%s] enter",LINE,FUNC);

     pthread_t lynq_at_tid;

     int rt = pthread_create(&lynq_at_tid, NULL, thread_recv, NULL);

     pthread_mutex_lock(&s_startupMutex);

-    LOGD("[%d][%s] pthread mutex unlock",LINE,FUNC);

+    LOGD(GSW_AT,"[%d][%s] pthread mutex unlock",LINE,FUNC);

     if((connect_state != true) && rt < 0)

     {

-        LOGE("connect fail,rt:%d,connect state:%d\n",rt,connect_state);

+        LOGE(GSW_AT,"connect fail,rt:%d,connect state:%d\n",rt,connect_state);

         return -1;

     }

     return 0;

@@ -317,23 +230,23 @@
     

     memcpy(buffer_at, atcmd, strlen(atcmd));

     tmp = func;

-    LOGD("lynq_reg_third_at start\n");

+    LOGD(GSW_AT,"lynq_reg_third_at start\n");

     int ret = lynq_connect_service_start();

     

     if(ret != 0)

     {

-        LOGE("lynq_connect_service_start start failed\n");

+        LOGE(GSW_AT,"lynq_connect_service_start start failed\n");

         return GSW_HAL_NORMAL_FAIL;

     }

-    LOGD("lynq_connect_service_start success ret:%d\n",ret);

+    LOGD(GSW_AT,"lynq_connect_service_start success ret:%d\n",ret);

     return GSW_HAL_SUCCESS;

 }

 

 int32_t gsw_sdk_at_init(void)

 {

     dlHandle_at = dlopen(lynqLib_at, RTLD_NOW);

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

-    if(fun_ptr_log == NULL || dlHandle_at == NULL)

+    //fun_ptr_log = (mbtk_log)dlsym(dlHandle_at, "mbtk_log");

+    if(dlHandle_at == NULL)

     {

         return GSW_HAL_NORMAL_FAIL;

     }

@@ -344,12 +257,12 @@
 {

     if (num != soc_max)

     {

-        LOGE("temperture if not support,num is %d\n",num);

+        LOGE(GSW_AT,"temperture if not support,num is %d\n",num);

         return GSW_HAL_SUCCESS;

     }

     if (NULL == temp)

     {

-        LOGE("temperture is null\n");

+        LOGE(GSW_AT,"temperture is null\n");

         return GSW_HAL_ARG_INVALID;

     }

 

@@ -359,18 +272,18 @@
     fp = fopen(cmd, "r");

     if (fp == NULL)

     {

-        LOGE("Unable to open file");

+        LOGE(GSW_AT,"Unable to open file");

         return GSW_HAL_NORMAL_FAIL;

     }

     if (fgets(buf, sizeof(buf), fp) == NULL)

     {

-        LOGE("fgets fail");

+        LOGE(GSW_AT,"fgets fail");

         fclose(fp);

         return GSW_HAL_NORMAL_FAIL;

     }

     if (strlen(buf) == 0)

     {

-        LOGE("read len == 0\n");

+        LOGE(GSW_AT,"read len == 0\n");

         fclose(fp);

         return GSW_HAL_NORMAL_FAIL;

     }

diff --git a/mbtk/libgsw_lib/gsw_log_interface.c b/mbtk/libgsw_lib/gsw_log_interface.c
new file mode 100755
index 0000000..ae51b01
--- /dev/null
+++ b/mbtk/libgsw_lib/gsw_log_interface.c
@@ -0,0 +1,29 @@
+#include "gsw_log_interface.h"
+
+void *handle = NULL;
+int log_initialized = 0;
+mbtk_log gsw_fun_ptr_log;
+int init_log_func(void)
+{
+    if (log_initialized)
+        return 0;
+
+    handle = dlopen("/lib/libmbtk_lib.so", RTLD_NOW);
+    if (!handle)
+        {
+        syslog(LOG_ERR, "Failed to load library: %s", dlerror());
+        return -1;
+    }
+
+    gsw_fun_ptr_log = (mbtk_log)dlsym(handle, "mbtk_log");
+    if (!gsw_fun_ptr_log)
+        {
+        syslog(LOG_ERR, "Cannot load symbol 'mbtk_log': %s", dlerror());
+        dlclose(handle);
+        handle = NULL;
+        return -1;
+    }
+
+    log_initialized = 1;
+    return 0;
+}
diff --git a/mbtk/libgsw_lib/gsw_log_interface.h b/mbtk/libgsw_lib/gsw_log_interface.h
new file mode 100755
index 0000000..cc59c0f
--- /dev/null
+++ b/mbtk/libgsw_lib/gsw_log_interface.h
@@ -0,0 +1,61 @@
+#ifndef GSW_LOG_INTERFACE_H

+#define GSW_LOG_INTERFACE_H

+

+#include <stdio.h>

+#include <stdlib.h>

+#include <string.h>

+#include <unistd.h>

+#include <fcntl.h>

+#include <stdarg.h>

+#include <dlfcn.h>

+#include <syslog.h>

+

+#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

+

+typedef void (*mbtk_log)(int level, const char *fmt, ...);

+

+extern mbtk_log gsw_fun_ptr_log;

+

+int init_log_func(void);

+

+

+#define LOG(level, tag, 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--; \

+		} \

+		if(0 == init_log_func()) {\

+			gsw_fun_ptr_log(level, "%s#%s: %s " fmt, ptr_1001 + 1, line_1001, tag, ##args); \

+		} else { \

+			printf("%s#%s: [%s] %s " fmt "\n", ptr_1001 + 1, line_1001, #level, tag, ##args); \

+		} \

+	} while(0)

+

+

+#define LOGV(tag, fmt, args...)    LOG(LOG_VERBOSE_LEVEL, tag, fmt, ##args)

+#define LOGD(tag, fmt, args...)    LOG(LOG_DEBUG_LEVEL, tag, fmt, ##args)

+#define LOGI(tag, fmt, args...)    LOG(LOG_INFO_LEVEL, tag, fmt, ##args)

+#define LOGW(tag, fmt, args...)    LOG(LOG_WARN_LEVEL, tag, fmt, ##args)

+#define LOGE(tag, fmt, args...)    LOG(LOG_ERR_LEVEL, tag, fmt, ##args)

+

+#endif

diff --git a/mbtk/libgsw_lib/gsw_pm_interface.c b/mbtk/libgsw_lib/gsw_pm_interface.c
index 0d1aec4..ee28780 100755
--- a/mbtk/libgsw_lib/gsw_pm_interface.c
+++ b/mbtk/libgsw_lib/gsw_pm_interface.c
@@ -15,105 +15,22 @@
 #include <stdint.h>

 #include <sys/time.h>

 #include "gsw_pm_interface.h"

-

-#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

+#include "gsw_log_interface.h"

 

 #define GSW_PM "[HAL][GSW_PM]"

 #define GSW_WAKELOCK_NAME "gsw_app_wakelock"

-#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_PM"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)

-

-#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_PM"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)

-

-#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_PM"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)

-

-#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_PM"" 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_PM"" fmt, ptr_1001 + 1, line_1001, ##args); \

-    } while(0)

     

-

 #define LOCK_MAX_SIZE 129

 #define SDK_READY_CMD "uci get persist.mbtk.sdk__state"

+#define MBTK_REBOOT_REASON "uci get persist.mbtk.reboot_reason"

 #define CHECK_SYSTEM(cmd) do { \

     int _ret = system(cmd); \

     if (_ret == -1) perror("system error"); \

 } while(0)

+

 typedef void (*GSW_PM_WAKEUPCALLBACK)(int32_t wakeup_in);

 typedef void (*mbtk_lpm_handler_t)(int32_t wakeup_in);

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

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

 

 int (*mbtk_autosuspend_enable)(char);

 int (*mbtk_wakelock_create)(const char* name , size_t);

@@ -121,6 +38,7 @@
 int (*mbtk_wakelock_unlock)(int);

 int (*mbtk_wakelock_destroy)(int);

 int (*mbtk_lpm_init)(mbtk_lpm_handler_t );

+

 int lock_fd = -1;

 

 typedef struct

@@ -130,7 +48,7 @@
 } mbtk_lock_name_s;

 static mbtk_lock_name_s lock_name[LOCK_MAX_SIZE]={0};

 

-static mbtk_log fun_ptr_log = NULL;

+//static mbtk_log fun_ptr_log = NULL;

 static void *dlHandle_sleep = NULL;

 char *lynqLib_sleep = "/lib/libmbtk_lib.so";

 

@@ -179,11 +97,11 @@
 

 static int handle()

 {

-    if(dlHandle_sleep == NULL || fun_ptr_log == NULL)

+    if(dlHandle_sleep == NULL)

     {

         dlHandle_sleep = dlopen(lynqLib_sleep, RTLD_NOW);

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

-        if(fun_ptr_log == NULL || dlHandle_sleep == NULL)

+        //fun_ptr_log = (mbtk_log)dlsym(dlHandle_sleep, "mbtk_log");

+        if(dlHandle_sleep == NULL)

         {

             return GSW_HAL_NORMAL_FAIL;

         }

@@ -200,7 +118,7 @@
     ret = mbtk_autosuspend_enable(1);

     if(ret < 0)

     {

-        LOGE("mbtk_autosuspend_enable FAIL.\n");

+        LOGE(GSW_PM,"mbtk_autosuspend_enable FAIL.\n");

         return GSW_HAL_NORMAL_FAIL;

     }

     return GSW_HAL_SUCCESS;

@@ -220,7 +138,7 @@
     ret = mbtk_autosuspend_enable(0);

     if(ret < 0)

     {

-        LOGE("mbtk_autosuspend_enable FAIL.\n");

+        LOGE(GSW_PM,"mbtk_autosuspend_enable FAIL.\n");

         return GSW_HAL_NORMAL_FAIL;

     }

     return GSW_HAL_SUCCESS;

@@ -242,7 +160,7 @@
     ret = mbtk_lpm_init((mbtk_lpm_handler_t)wakeup_callback);

     if(ret < 0)

     {

-        LOGE("mbtk_lpm_init FAIL.\n");

+        LOGE(GSW_PM,"mbtk_lpm_init FAIL.\n");

         return GSW_HAL_NORMAL_FAIL;

     }

     return GSW_HAL_SUCCESS;

@@ -271,7 +189,7 @@
     }

     if (i >= LOCK_MAX_SIZE)

     {

-        LOGE("mbtk_wakelock_lock not create.\n");

+        LOGE(GSW_PM,"mbtk_wakelock_lock not create.\n");

         return GSW_HAL_NORMAL_FAIL;

     }

 

@@ -279,7 +197,7 @@
     ret = mbtk_wakelock_unlock(lock_fd);

     if(ret < 0)

     {

-        LOGE("mbtk_wakelock_unlock FAIL.\n");

+        LOGE(GSW_PM,"mbtk_wakelock_unlock FAIL.\n");

         return GSW_HAL_NORMAL_FAIL;

     }

 

@@ -287,7 +205,7 @@
     ret = mbtk_wakelock_destroy(lock_fd);

     if(ret < 0)

     {

-        LOGE("mbtk_wakelock_destroy FAIL.\n");

+        LOGE(GSW_PM,"mbtk_wakelock_destroy FAIL.\n");

         return GSW_HAL_NORMAL_FAIL;

     }

     if (lock_name[i].name != NULL)

@@ -316,7 +234,7 @@
     lock_fd = mbtk_wakelock_create(gsw_wakelock_name, strlen(gsw_wakelock_name));

     if(lock_fd < 0)

     {

-        LOGE("mbtk_wakelock_create FAIL.\n");

+        LOGE(GSW_PM,"mbtk_wakelock_create FAIL.\n");

         ret = GSW_HAL_NORMAL_FAIL;

         goto end;

     }

@@ -325,7 +243,7 @@
     ret = mbtk_wakelock_lock(lock_fd);

     if(ret < 0)

     {

-        LOGE("mbtk_wakelock_lock FAIL.\n");

+        LOGE(GSW_PM,"mbtk_wakelock_lock FAIL.\n");

         ret = GSW_HAL_NORMAL_FAIL;

         goto end;

     }

@@ -336,14 +254,14 @@
     }

     if(i == LOCK_MAX_SIZE)

     {

-        LOGE("mbtk_wakelock_lock not space FAIL.\n");

+        LOGE(GSW_PM,"mbtk_wakelock_lock not space FAIL.\n");

         ret = GSW_HAL_NORMAL_FAIL;

         goto end;

     }

     lock_name[i].name = malloc(strlen(gsw_wakelock_name)+1);

     if (lock_name[i].name == NULL)

     {

-        LOGE("mbtk_wakelock_lock remeber FAIL.\n");

+        LOGE(GSW_PM,"mbtk_wakelock_lock remeber FAIL.\n");

         ret = GSW_HAL_NORMAL_FAIL;

         goto end;

     }

@@ -391,6 +309,40 @@
     }

     return;

 }

+

+/**

+* @brief get Modem reset reason

+* @param [in]int32_t * reset_reason

+* @retval void

+*/

+int32_t gsw_get_modem_reset_reason(int32_t *reset_reason)

+{

+    char buf[8] = {0};

+    int value = -1;

+    FILE *fp = popen(MBTK_REBOOT_REASON, "r");

+    if(NULL == fp)

+    {

+        return GSW_HAL_NORMAL_FAIL;

+    }

+    memset(buf,0,sizeof(buf));

+    if(fgets(buf, sizeof(buf), fp) == NULL)

+    {

+        pclose(fp);

+        perror("fgets failed:");

+        return GSW_HAL_NORMAL_FAIL;

+    }

+    pclose(fp);

+    value = atoi(buf);   

+        

+    if (value >= 0 && value <= 6) 

+    {

+        *reset_reason = (int32_t)value;

+        return GSW_HAL_SUCCESS;

+    }

+    return GSW_HAL_NORMAL_FAIL;

+}

+

+

 /**

  * @brief enable autosleep

  * @return int : 0 is success , other failed

diff --git a/mbtk/libgsw_lib/gsw_secrypt_ss_interface.c b/mbtk/libgsw_lib/gsw_secrypt_ss_interface.c
index 7447fc5..4d95869 100755
--- a/mbtk/libgsw_lib/gsw_secrypt_ss_interface.c
+++ b/mbtk/libgsw_lib/gsw_secrypt_ss_interface.c
@@ -6,95 +6,10 @@
 #include <stdint.h>
 #include "gsw_secrypt_ss_interface.h"
 #include "gsw_hal_errcode.h"
-
-#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
+#include "gsw_log_interface.h"
 
 #define GSW_TEE "[HAL][GSW_TEE]"
 
-#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--; \
-        } \
-        mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_TEE"" fmt, ptr_1001 + 1, line_1001, ##args); \
-    } while(0)
-
-#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--; \
-        } \
-        mbtk_log(LOG_INFO_LEVEL, "%s#%s: "GSW_TEE"" fmt, ptr_1001 + 1, line_1001, ##args); \
-    } while(0)
-
-#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--; \
-        } \
-        mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_TEE"" fmt, ptr_1001 + 1, line_1001, ##args); \
-    } while(0)
-
-#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--; \
-        } \
-        mbtk_log(LOG_WARN_LEVEL, "%s#%s: "GSW_TEE"" 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--; \
-        } \
-        mbtk_log(LOG_ERR_LEVEL, "%s#%s: "GSW_TEE"" fmt, ptr_1001 + 1, line_1001, ##args); \
-    } while(0)
-
 /**
  * struct TEEC_Context - Represents a connection between a client application
  * and a TEE.
@@ -156,8 +71,8 @@
 static void *dlHandle_mbtk;
 
 typedef uint32_t TEEC_Result;
-static void (*mbtk_log)(int level, const char *format, ...);
-static void (*mbtk_log_init)(char *path, char *tag);
+// static void (*mbtk_log)(int level, const char *format, ...);
+// static void (*mbtk_log_init)(char *path, char *tag);
 
 int (*prepare_tee_session)(struct test_ctx *ctx);
 void (*terminate_tee_session)(struct test_ctx *ctx);
@@ -180,50 +95,50 @@
         return GSW_HAL_NORMAL_FAIL;
     }
 
-    mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
-    if (mbtk_log_init == NULL) 
-    {
-        return GSW_HAL_NORMAL_FAIL;
-    }
+    // mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
+    // if (mbtk_log_init == NULL) 
+    // {
+    //     return GSW_HAL_NORMAL_FAIL;
+    // }
 
-    mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
-    if (mbtk_log == NULL) 
-    {
-        return GSW_HAL_NORMAL_FAIL;
-    }
+    // mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
+    // if (mbtk_log == NULL) 
+    // {
+    //     return GSW_HAL_NORMAL_FAIL;
+    // }
 
     prepare_tee_session = (int (*)(struct test_ctx *ctx))dlsym(dlHandle_secure, "prepare_tee_session");
     if (prepare_tee_session == NULL) 
     {
-        LOGE("prepare_tee_session dlsym fail\n");
+        LOGE(GSW_TEE,"prepare_tee_session dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     terminate_tee_session = (void (*)(struct test_ctx *ctx))dlsym(dlHandle_secure, "terminate_tee_session");
     if (terminate_tee_session == NULL) 
     {
-        LOGE("terminate_tee_session dlsym fail\n");
+        LOGE(GSW_TEE,"terminate_tee_session dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     read_secure_object = (TEEC_Result (*)(struct test_ctx *ctx, const char *id,char *data, size_t *data_len))dlsym(dlHandle_secure, "read_secure_object");
     if (read_secure_object == NULL) 
     {
-        LOGE("read_secure_object dlsym fail\n");
+        LOGE(GSW_TEE,"read_secure_object dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     write_secure_object = (TEEC_Result (*)(struct test_ctx *ctx, const char *id,char *data, size_t data_len))dlsym(dlHandle_secure, "write_secure_object");
     if (write_secure_object == NULL) 
     {
-        LOGE("write_secure_object dlsym fail\n");
+        LOGE(GSW_TEE,"write_secure_object dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     delete_secure_object = (TEEC_Result (*)(struct test_ctx *ctx, const char *id))dlsym(dlHandle_secure, "delete_secure_object");
     if (delete_secure_object == NULL) 
     {
-        LOGE("delete_secure_object dlsym fail\n");
+        LOGE(GSW_TEE,"delete_secure_object dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
@@ -238,15 +153,16 @@
 */
 int32_t gsw_tee_sdk_init(void)
 {
+    LOGE(GSW_TEE,"init start\n");
     int32_t ret = 0;
     ret = tee_api_import();
     if(ret)
     {
-	LOGE("tee_api_import fail\n");
+	LOGE(GSW_TEE,"tee_api_import fail\n");
         return ret;
     }
     ret = prepare_tee_session(&ctx);
-    LOGE("init end\n");
+    LOGE(GSW_TEE,"init end\n");
     return ret;
 }
 
@@ -261,7 +177,7 @@
 #define basic_buf_len  7000
 int32_t gsw_tee_read_secure_data(const char* in_obj_name, char* out_buf, unsigned int* p_out_buf_len)
 {
-    LOGE("start read\n");
+    LOGE(GSW_TEE,"start read\n");
     if (in_obj_name == NULL || out_buf == NULL)
     {
         return GSW_HAL_NORMAL_FAIL;
@@ -272,19 +188,19 @@
     char *tmp_buf = (char*)malloc(basic_buf_len);
     if (NULL == tmp_buf)
     {
-        LOGE("Failed malloc fail");
+        LOGE(GSW_TEE,"Failed malloc fail");
         return GSW_HAL_NO_MEMORY;
     }
     
     TEEC_Result res = read_secure_object(&ctx, in_obj_name, tmp_buf, &size);
     if (res != TEEC_SUCCESS)
     {
-        LOGE("Failed to read an object from the secure storage");
+        LOGE(GSW_TEE,"Failed to read an object from the secure storage");
         ret = GSW_HAL_NORMAL_FAIL;
         free(tmp_buf);
         return ret;
     }
-    LOGE("really start end\n");
+    LOGE(GSW_TEE,"really start end\n");
     memcpy(out_buf, tmp_buf, size);
     *p_out_buf_len = size;
     free(tmp_buf);
@@ -300,7 +216,7 @@
 */
 int32_t gsw_tee_write_secure_data(const char* in_obj_name, char* in_buf, unsigned int in_buf_len)
 {
-    LOGE("write start\n");
+    LOGE(GSW_TEE,"write start\n");
     if (in_obj_name == NULL || in_buf == NULL)
         return GSW_HAL_NORMAL_FAIL;
     int32_t ret = 0;
@@ -308,10 +224,10 @@
     TEEC_Result res = write_secure_object(&ctx, in_obj_name,in_buf, in_buf_len);
     if (res != TEEC_SUCCESS)
     {
-	LOGE("Failed to write an object from the secure storage");
+	LOGE(GSW_TEE,"Failed to write an object from the secure storage");
         ret = GSW_HAL_NORMAL_FAIL;
     }
-    LOGE("write really end\n");
+    LOGE(GSW_TEE,"write really end\n");
     return ret;
 }
 
@@ -323,7 +239,7 @@
 */
 int32_t gsw_tee_delete_secure_data(const char* in_obj_name)
 {
-    LOGE("delete start\n");
+    LOGE(GSW_TEE,"delete start\n");
     if (in_obj_name == NULL)
         return GSW_HAL_NORMAL_FAIL;
     int32_t ret = 0;
@@ -331,10 +247,10 @@
     TEEC_Result res = delete_secure_object(&ctx, in_obj_name);
     if (res != TEEC_SUCCESS)
     {
-	LOGE("Failed to delete the object: 0x%x", res);
+	LOGE(GSW_TEE,"Failed to delete the object: 0x%x", res);
         ret = GSW_HAL_NORMAL_FAIL;
     }
-    LOGE("delete really end\n");
+    LOGE(GSW_TEE,"delete really end\n");
     return ret;
 }
 
@@ -352,23 +268,23 @@
     char *tmp_buf = (char*)malloc(basic_buf_len);
     if (NULL == tmp_buf)
     {
-        LOGE("Failed malloc fail");
+        LOGE(GSW_TEE,"Failed malloc fail");
         return GSW_HAL_NO_MEMORY;
     }
     TEEC_Result res = read_secure_object(&ctx, in_obj_name, tmp_buf, &size);
     if (res == TEEC_ERROR_ITEM_NOT_FOUND)
     {
-        LOGE("the obj no found\n");
+        LOGE(GSW_TEE,"the obj no found\n");
         ret = GSW_HAL_ERROR_TEE_SFS_FILE_NOEXIST;
     }
     else if (res == TEEC_SUCCESS)
     {
-        LOGE("the obj is exist\n");
+        LOGE(GSW_TEE,"the obj is exist\n");
         ret = GSW_HAL_SUCCESS;
     }
     else
     {
-        LOGE("Failed to read an object from the secure storage");
+        LOGE(GSW_TEE,"Failed to read an object from the secure storage");
         ret = GSW_HAL_NORMAL_FAIL;
     }
     free(tmp_buf);
@@ -383,7 +299,7 @@
 */
 int32_t gsw_tee_sdk_deinit(void)
 {
-    LOGE("deinit start\n");
+    LOGE(GSW_TEE,"deinit start\n");
     if (terminate_tee_session) {
         terminate_tee_session(&ctx);  // 终止TEE会话
         terminate_tee_session = NULL;
@@ -398,7 +314,7 @@
         dlclose(dlHandle_mbtk);  // 卸载日志库
         dlHandle_mbtk = NULL;
     }
-    LOGE("deinit end\n");
+    LOGE(GSW_TEE,"deinit end\n");
     return GSW_HAL_SUCCESS;
 }
 
@@ -414,7 +330,7 @@
         s_init_flag = 0xAA55;
         return GSW_HAL_SUCCESS;
     }
-    LOGE("secure sdk init fail!!!");
+    LOGE(GSW_TEE,"secure sdk init fail!!!");
     return GSW_HAL_NORMAL_FAIL;
 }
 
@@ -423,7 +339,7 @@
 #if 0
     if (NULL == objname || NULL == exist_state)
     {
-        LOGE("storage query input param error objname %p, exist_state %p",objname, exist_state);
+        LOGE(GSW_TEE,"storage query input param error objname %p, exist_state %p",objname, exist_state);
         return GSW_HAL_ARG_INVALID;
     }
     int32_t ret = gsw_secure_init();
@@ -451,7 +367,7 @@
 #if 0
     if (NULL == objname || NULL == outbuf || NULL == outlen)
     {
-        LOGE("storage read input param error objname %p, outbuf %p, outlen %p",objname, outbuf, outlen);
+        LOGE(GSW_TEE,"storage read input param error objname %p, outbuf %p, outlen %p",objname, outbuf, outlen);
         return GSW_HAL_ARG_INVALID;
     }
     int32_t ret = gsw_secure_init();
@@ -472,7 +388,7 @@
 #if 0
     if (NULL == objname || NULL == inbuf || 0 == inlen)
     {
-        LOGE("storage write input param error objname %p, outbuf %p, inlen %u",objname, inbuf, inlen);
+        LOGE(GSW_TEE,"storage write input param error objname %p, outbuf %p, inlen %u",objname, inbuf, inlen);
         return GSW_HAL_ARG_INVALID;
     }
     int32_t ret = gsw_secure_init();
@@ -491,7 +407,7 @@
 #if 0
     if (NULL == objname)
     {
-        LOGE("storage delete input param error objname %p",objname);
+        LOGE(GSW_TEE,"storage delete input param error objname %p",objname);
         return GSW_HAL_ARG_INVALID;
     }
     int32_t ret = gsw_secure_init();
diff --git a/mbtk/libgsw_lib/gsw_sms_interface.c b/mbtk/libgsw_lib/gsw_sms_interface.c
index 415bc49..3b8ea47 100755
--- a/mbtk/libgsw_lib/gsw_sms_interface.c
+++ b/mbtk/libgsw_lib/gsw_sms_interface.c
@@ -5,7 +5,7 @@
 #include <dlfcn.h>
 #include <time.h>
 #include "gsw_nw_interface.h"
-
+#include "gsw_log_interface.h"
 typedef unsigned short uint16_t;
 typedef unsigned int uint32_t;
 typedef unsigned char uint8_t;
@@ -127,101 +127,14 @@
 int (*mbtk_sms_csca_set)(mbtk_info_handle_t* handle, char * csca);
 int (*mbtk_sms_csca_get)(mbtk_info_handle_t* handle, char *buf);
 int (*mbtk_sms_cnmi_set)(mbtk_info_handle_t* handle);
-static void (*mbtk_log)(int level, const char *format, ...);
-static void (*mbtk_log_init)(char *path, char *tag);
+// static void (*mbtk_log)(int level, const char *format, ...);
+// static void (*mbtk_log_init)(char *path, char *tag);
 int (*smsPduEncode)(const char *smsc, const char *da_num, const char *msg, int charset, char *smsc_pdu, char **pdu);
 int (*smsPduDecode)(const char *pdu_str, int pdu_len, char *da_num, char *smsc, char *msg, int *charset, int *curr_pack, int *total_pack, char *date);
 kal_int32 (*_mdapi_sms_get_msg_num)(const char *msg, int charset, kal_int32 *msg_num, kal_int32 *msg_len);
 
-#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 GSW_SMS "[HAL][GSW_SMS]"
 
-#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--; \
-        } \
-        mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_SMS"" fmt, ptr_1001 + 1, line_1001, ##args); \
-    } while(0)
-
-#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--; \
-        } \
-        mbtk_log(LOG_INFO_LEVEL, "%s#%s: "GSW_SMS"" fmt, ptr_1001 + 1, line_1001, ##args); \
-    } while(0)
-
-#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--; \
-        } \
-        mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_SMS"" fmt, ptr_1001 + 1, line_1001, ##args); \
-    } while(0)
-
-#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--; \
-        } \
-        mbtk_log(LOG_WARN_LEVEL, "%s#%s: "GSW_SMS"" 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--; \
-        } \
-        mbtk_log(LOG_ERR_LEVEL, "%s#%s: "GSW_SMS"" fmt, ptr_1001 + 1, line_1001, ##args); \
-    } while(0)
-
-
-
 static mbtk_info_handle_t* sms_info_handle = NULL;
 static sms_client_handle_type handle;
 static char sms_center_address[SMSC_MAX_LEN] = {0};
@@ -236,106 +149,106 @@
         return GSW_HAL_NORMAL_FAIL;
     }
 
-    mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
-    if (mbtk_log_init == NULL) 
-    {
-        return GSW_HAL_NORMAL_FAIL;
-    }
+    // mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
+    // if (mbtk_log_init == NULL) 
+    // {
+    //     return GSW_HAL_NORMAL_FAIL;
+    // }
 
-    mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
-    if (mbtk_log == NULL) 
-    {
-        return GSW_HAL_NORMAL_FAIL;
-    }
+    // mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
+    // if (mbtk_log == NULL) 
+    // {
+    //     return GSW_HAL_NORMAL_FAIL;
+    // }
 
     mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
     if (mbtk_info_handle_get == NULL) 
     {
-        LOGE("mbtk_info_handle_get dlsym fail\n");
+        LOGE(GSW_SMS,"mbtk_info_handle_get dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     mbtk_sms_state_change_cb_reg = (int (*)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb))dlsym(dlHandle_mbtk, "mbtk_sms_state_change_cb_reg");
     if (mbtk_sms_state_change_cb_reg == NULL) 
     {
-        LOGE("mbtk_sms_state_change_cb_reg dlsym fail\n");
+        LOGE(GSW_SMS,"mbtk_sms_state_change_cb_reg dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     mbtk_info_handle_free = (int (*)(mbtk_info_handle_t** handle))dlsym(dlHandle_mbtk, "mbtk_info_handle_free");
     if (mbtk_info_handle_free == NULL) 
     {
-        LOGE("mbtk_info_handle_free dlsym fail\n");
+        LOGE(GSW_SMS,"mbtk_info_handle_free dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     PDUDecoding = (struct SMS_Struct (*)(const char *data))dlsym(dlHandle_mbtk, "PDUDecoding");
     if (PDUDecoding == NULL) 
     {
-        LOGE("PDUDecoding dlsym fail\n");
+        LOGE(GSW_SMS,"PDUDecoding dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     SCADecoding = (char *(*)(const char *data, int *EndIndex))dlsym(dlHandle_mbtk, "SCADecoding");
     if (SCADecoding == NULL) 
     {
-        LOGE("SCADecoding dlsym fail\n");
+        LOGE(GSW_SMS,"SCADecoding dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     SCAEncoding = (char *(*)(char *SCA))dlsym(dlHandle_mbtk, "SCAEncoding");
     if (SCAEncoding == NULL) 
     {
-        LOGE("SCAEncoding dlsym fail\n");
+        LOGE(GSW_SMS,"SCAEncoding dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     PDUEncoding = (struct PDUS *(*)(char *SCA, char *DA, char *UDC, struct UDHS *udhs))dlsym(dlHandle_mbtk, "PDUEncoding");
     if (PDUEncoding == NULL) 
     {
-        LOGE("PDUEncoding dlsym fail\n");
+        LOGE(GSW_SMS,"PDUEncoding dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     mbtk_sms_cmgf_set = (int (*)(mbtk_info_handle_t* handle, int mode))dlsym(dlHandle_mbtk, "mbtk_sms_cmgf_set");
     if (mbtk_sms_cmgf_set == NULL) 
     {
-        LOGE("mbtk_sms_cmgf_set dlsym fail\n");
+        LOGE(GSW_SMS,"mbtk_sms_cmgf_set dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     mbtk_sms_cmgs_set = (int (*)(mbtk_info_handle_t* handle, char * cmgs, char *resp))dlsym(dlHandle_mbtk, "mbtk_sms_cmgs_set");
     if (mbtk_sms_cmgs_set == NULL) 
     {
-        LOGE("mbtk_sms_cmgs_set dlsym fail\n");
+        LOGE(GSW_SMS,"mbtk_sms_cmgs_set dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     mbtk_sms_csca_set = (int (*)(mbtk_info_handle_t* handle, char * csca))dlsym(dlHandle_mbtk, "mbtk_sms_csca_set");
     if (mbtk_sms_csca_set == NULL) 
     {
-        LOGE("mbtk_sms_csca_set dlsym fail\n");
+        LOGE(GSW_SMS,"mbtk_sms_csca_set dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     mbtk_sms_csca_get = (int (*)(mbtk_info_handle_t* handle, char *buf))dlsym(dlHandle_mbtk, "mbtk_sms_csca_get");
     if (mbtk_sms_csca_get == NULL) 
     {
-        LOGE("mbtk_sms_csca_get dlsym fail\n");
+        LOGE(GSW_SMS,"mbtk_sms_csca_get dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     mbtk_sms_cnmi_set = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_sms_cnmi_set");
     if (mbtk_sms_cnmi_set == NULL) 
     {
-        LOGE("mbtk_sms_cnmi_set dlsym fail\n");
+        LOGE(GSW_SMS,"mbtk_sms_cnmi_set dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     smsPduEncode = (int (*)(const char *smsc, const char *da_num, const char *msg, int charset, char *smsc_pdu, char **pdu))dlsym(dlHandle_mbtk, "smsPduEncode");
     if (smsPduEncode == NULL) 
     {
-        LOGE("smsPduEncode dlsym fail\n");
+        LOGE(GSW_SMS,"smsPduEncode dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
@@ -343,14 +256,14 @@
     smsPduDecode = (int (*)(const char *pdu_str, int pdu_len, char *da_num, char *smsc, char *msg, int *charset, int *curr_pack, int *total_pack, char *date))dlsym(dlHandle_mbtk,"smsPduDecode");
     if (smsPduDecode == NULL) 
     {
-        LOGE("smsPduDecode dlsym fail\n");
+        LOGE(GSW_SMS,"smsPduDecode dlsym fail\n");
         return GSW_HAL_NORMAL_FAIL;
     }
 
     _mdapi_sms_get_msg_num = (kal_int32 (*)(const char *msg, int charset, kal_int32 *msg_num, kal_int32 *msg_len))dlsym(dlHandle_mbtk,"_mdapi_sms_get_msg_num");
     if (_mdapi_sms_get_msg_num == NULL) 
     {
-        LOGE("_mdapi_sms_get_msg_num dlsym fail");
+        LOGE(GSW_SMS,"_mdapi_sms_get_msg_num dlsym fail");
         return GSW_HAL_NORMAL_FAIL;
     }
 
@@ -374,7 +287,7 @@
 }
 
 void gsw_sms_state_change_cb(const void* data, int data_len) {
-    LOGD("gsw_sms_state_change_cb -------start\n");
+    LOGD(GSW_SMS,"gsw_sms_state_change_cb -------start\n");
 
     uint8 *ptr = (uint8*)data;
 
@@ -398,9 +311,9 @@
     int total_pack = 1;
     if(ptr == NULL)
     {
-        LOGE("ptr is null");
+        LOGE(GSW_SMS,"ptr is null");
     }
-    LOGE("ptr: %s\n,data_len = %d\n", (char *)ptr, data_len);
+    LOGE(GSW_SMS,"ptr: %s\n,data_len = %d\n", (char *)ptr, data_len);
     if(data_len > MDAPI_MAX_PDU_SIZE)
     {
         strncpy(received_pdu, (const char *)ptr, MDAPI_MAX_PDU_SIZE-1);
@@ -412,12 +325,12 @@
     ret = smsPduDecode((const char *)received_pdu, data_len, num, smsc, msg, &charset, &curr_pack, &total_pack,date);
     if(ret != 0)
     {
-        LOGE("smsPduDecode fail\n");
+        LOGE(GSW_SMS,"smsPduDecode fail\n");
         return ;
     }
-    LOGE("smsPduDecode ret: %d\n", ret);
-    LOGE("SMS :%s, %s, %d\n", __FILE__, __FUNCTION__, __LINE__);
-    LOGE("[EVENT][MT_SMS]PDU decode:smsc: %s\n, phone number: %s\ncharset: %d\n msg_len: %d\n message content: %s\n curr_pack: %d\n total_pack: %d\n date: %s", smsc, num, charset, strlen(msg), msg, curr_pack, total_pack, date);
+    LOGE(GSW_SMS,"smsPduDecode ret: %d\n", ret);
+    LOGE(GSW_SMS,"SMS :%s, %s, %d\n", __FILE__, __FUNCTION__, __LINE__);
+    LOGE(GSW_SMS,"[EVENT][MT_SMS]PDU decode:smsc: %s\n, phone number: %s\ncharset: %d\n msg_len: %d\n message content: %s\n curr_pack: %d\n total_pack: %d\n date: %s", smsc, num, charset, strlen(msg), msg, curr_pack, total_pack, date);
 
     gsw_sms_msg.content_encode = charset;
     memcpy(gsw_sms_msg.src_num, num, strlen(num));
@@ -426,17 +339,17 @@
 
     if(sscanf(date, "%4[^-]-%2[^-]-%2[^ ] %2[^:]:%2[^:]:%2s", (char*)gsw_sms_date.year, (char*)gsw_sms_date.month, (char*)gsw_sms_date.day, (char*)gsw_sms_date.hour, (char*)gsw_sms_date.minutes, (char*)gsw_sms_date.seconds)<=0)
     {
-        LOGE("sscanf failed\n");
+        LOGE(GSW_SMS,"sscanf failed\n");
     }
 
     snprintf((char *)gsw_sms_date.timezone, sizeof(gsw_sms_date.timezone), "%s","+8");
 
-    LOGE("Year: %s\n", (char*)gsw_sms_date.year);
-    LOGE("Month: %s\n", (char*)gsw_sms_date.month);
-    LOGE("Day: %s\n", (char*)gsw_sms_date.day);
-    LOGE("Hour: %s\n", (char*)gsw_sms_date.hour);
-    LOGE("Minute: %s\n", (char*)gsw_sms_date.minutes);
-    LOGE("Second: %s\n", (char*)gsw_sms_date.seconds);
+    LOGE(GSW_SMS,"Year: %s\n", (char*)gsw_sms_date.year);
+    LOGE(GSW_SMS,"Month: %s\n", (char*)gsw_sms_date.month);
+    LOGE(GSW_SMS,"Day: %s\n", (char*)gsw_sms_date.day);
+    LOGE(GSW_SMS,"Hour: %s\n", (char*)gsw_sms_date.hour);
+    LOGE(GSW_SMS,"Minute: %s\n", (char*)gsw_sms_date.minutes);
+    LOGE(GSW_SMS,"Second: %s\n", (char*)gsw_sms_date.seconds);
 
     gsw_sms_msg.date = gsw_sms_date;
 
@@ -445,7 +358,7 @@
         // if(total_pack > 1 && curr_pack < total_pack)
         // {
             gsw_sms_callback(GSW_SMS_RECEIVED_FLG, &gsw_sms_msg);
-            LOGD("the gsw_sms_state_e is %d\n",GSW_SMS_RECEIVED_FLG);
+            LOGD(GSW_SMS,"the gsw_sms_state_e is %d\n",GSW_SMS_RECEIVED_FLG);
         // }
         // else
         // {
@@ -472,7 +385,7 @@
 
     if(handle_ptr == NULL)
     {
-        LOGE("gsw_sms_reg_callback fail,handle_ptr is null\n");
+        LOGE(GSW_SMS,"gsw_sms_reg_callback fail,handle_ptr is null\n");
         return -1;
     }
     else
@@ -495,17 +408,17 @@
 
     if(init_flag == 1)
     {
-        LOGE("has init sms sdk,return\n");
+        LOGE(GSW_SMS,"has init sms sdk,return\n");
         return GSW_HAL_SUCCESS;
     }
 
     ret = mbtk_sms_import();
     if(ret != 0)
     {
-        if(mbtk_log != NULL)
-        {
-            LOGE("[gsw_sms_sdk_init]mbtk_sms_import fail\n");
-        }
+        // if(mbtk_log != NULL)
+        // {
+        //     LOGE(GSW_SMS,"[gsw_sms_sdk_init]mbtk_sms_import fail\n");
+        // }
         return GSW_HAL_NORMAL_FAIL;
     }
 
@@ -514,7 +427,7 @@
     sms_info_handle = mbtk_info_handle_get();
     if(sms_info_handle == NULL)
     {
-        LOGE("[gsw_sms_sdk_init] mbtk handle init fail\n");
+        LOGE(GSW_SMS,"[gsw_sms_sdk_init] mbtk handle init fail\n");
         dlclose(dlHandle_mbtk);
         return GSW_HAL_NORMAL_FAIL;
     }
@@ -522,14 +435,14 @@
     ret = mbtk_sms_cnmi_set(sms_info_handle);
     if(ret != 0)
     {
-        LOGE("mbtk_sms_cnmi_set fail.[%d]\n", ret);
+        LOGE(GSW_SMS,"mbtk_sms_cnmi_set fail.[%d]\n", ret);
         return GSW_HAL_NORMAL_FAIL;
     }
 
     ret = mbtk_sms_state_change_cb_reg(sms_info_handle, gsw_sms_state_change_cb);
     if(ret != 0)
     {
-        LOGE("mbtk_sms_state_change_cb_reg fail.[%d]\n", ret);
+        LOGE(GSW_SMS,"mbtk_sms_state_change_cb_reg fail.[%d]\n", ret);
         if(sms_info_handle)
         {
             mbtk_info_handle_free(&sms_info_handle);
@@ -538,7 +451,7 @@
         return GSW_HAL_NORMAL_FAIL;
     }
 
-    LOGD("[gsw_sms_sdk_init]gsw_sms_sdk_init success\n");
+    LOGD(GSW_SMS,"[gsw_sms_sdk_init]gsw_sms_sdk_init success\n");
     init_flag = 1;
     return GSW_HAL_SUCCESS;
 }
@@ -558,31 +471,31 @@
         return -1;
     }
 
-    LOGD("callback clear\n");
+    LOGD(GSW_SMS,"callback clear\n");
     gsw_sms_callback = NULL;
 
-    LOGD("handle_free\n");
+    LOGD(GSW_SMS,"handle_free\n");
     if(sms_info_handle != NULL)
     {
         ret = mbtk_info_handle_free(&sms_info_handle);
         if(ret != 0)
         {
-            LOGE("[gsw_sms_sdk_deinit]mbtk_info_handle_free fail\n");
+            LOGE(GSW_SMS,"[gsw_sms_sdk_deinit]mbtk_info_handle_free fail\n");
             return GSW_HAL_NORMAL_FAIL;
         }
         sms_info_handle = NULL;
     }
 
-    LOGD("dlclose start\n");
+    LOGD(GSW_SMS,"dlclose start\n");
     if(dlHandle_mbtk == NULL)
     {
-        LOGE("[gsw_sms_sdk_deinit]dlHandle_sms is null\n");
+        LOGE(GSW_SMS,"[gsw_sms_sdk_deinit]dlHandle_sms is null\n");
     }
     else
     {
         dlclose(dlHandle_mbtk);
     }
-    LOGD("dlclose end\n");
+    LOGD(GSW_SMS,"dlclose end\n");
     init_flag = 0;
     return GSW_HAL_SUCCESS;
 }
@@ -611,8 +524,8 @@
 
     if(strlen((char *)msg) > GSW_SMS_RECV_CONT_MAX || strlen((char *)msg) == 0 || strlen((char *)phone_num) == 0)
     {
-        LOGE("strlen(telephony_num):%d", strlen((char *)phone_num));
-        LOGE("strlen(msg):%d", strlen((char *)msg));
+        LOGE(GSW_SMS,"strlen(telephony_num):%d", strlen((char *)phone_num));
+        LOGE(GSW_SMS,"strlen(msg):%d", strlen((char *)msg));
         return GSW_HAL_ARG_INVALID;
     }
 
@@ -641,10 +554,10 @@
         status = _mdapi_sms_get_msg_num((char *)msg, char_set, &msg_num, &pdu_msg_len);
     }
     
-    LOGE("%s, %s, %d, msg_len = [%d] ,msg_num=[%d]\n", __FILE__, __FUNCTION__, __LINE__, msg_len, msg_num);
+    LOGE(GSW_SMS,"%s, %s, %d, msg_len = [%d] ,msg_num=[%d]\n", __FILE__, __FUNCTION__, __LINE__, msg_len, msg_num);
     if(status == MDAPI_RET_ERROR)
     {
-        LOGE("get message number failed\n");
+        LOGE(GSW_SMS,"get message number failed\n");
         //return GSW_HAL_NORMAL_FAIL;
     }
     else
@@ -653,7 +566,7 @@
         pdu = (char **)malloc(sizeof(char *) * msg_num);
         if(pdu == NULL)
         {
-            LOGE("%s, %s, %d, allocate memory for pdu failed\n", __FILE__, __FUNCTION__, __LINE__);
+            LOGE(GSW_SMS,"%s, %s, %d, allocate memory for pdu failed\n", __FILE__, __FUNCTION__, __LINE__);
             return GSW_HAL_NORMAL_FAIL;
         }
 
@@ -671,13 +584,13 @@
                     }
                     free(pdu);
                     pdu = NULL;
-                    LOGE("%s, %s, %d, allocate memory for pdu[%d] failed\n", __FILE__, __FUNCTION__, __LINE__,index);
+                    LOGE(GSW_SMS,"%s, %s, %d, allocate memory for pdu[%d] failed\n", __FILE__, __FUNCTION__, __LINE__,index);
                     return GSW_HAL_NORMAL_FAIL;
                 }
                 else
                 {
                     memset(pdu[index], 0, MAX_PDU_SIZE);
-                    LOGE("%s, %s, %d, pdu[%d} init value is: %s \n", __FILE__, __FUNCTION__, __LINE__, index, pdu[index]);
+                    LOGE(GSW_SMS,"%s, %s, %d, pdu[%d} init value is: %s \n", __FILE__, __FUNCTION__, __LINE__, index, pdu[index]);
                 }
             }
         }
@@ -699,23 +612,23 @@
             char pdu_data[MAX_PDU_SIZE] = {0};
             char *p = pdu_data;
 
-            LOGE("index:%d\n",index);
-            LOGE("%s, %s, %d, smscPDU: %s, pdu: %s",__FILE__, __FUNCTION__, __LINE__, smscPDU, pdu[index]);
+            LOGE(GSW_SMS,"index:%d\n",index);
+            LOGE(GSW_SMS,"%s, %s, %d, smscPDU: %s, pdu: %s",__FILE__, __FUNCTION__, __LINE__, smscPDU, pdu[index]);
             sprintf(p, "%s",smscPDU);
-            LOGE("pdu_data:%s\n", pdu_data);
+            LOGE(GSW_SMS,"pdu_data:%s\n", pdu_data);
             int sc = strlen(pdu_data);
             sprintf(p+strlen(p), "%s", pdu[index]);
-            LOGE("pdu_data:%s\n", pdu_data);
+            LOGE(GSW_SMS,"pdu_data:%s\n", pdu_data);
 
             int t = strlen(pdu_data);
             sprintf(cmgs, "%d,%s", (t-sc)/2, pdu_data);
-            LOGE("cmgs:%s\n", cmgs);
+            LOGE(GSW_SMS,"cmgs:%s\n", cmgs);
             memset(resp, 0, sizeof(resp));
 
             err = mbtk_sms_cmgf_set(sms_info_handle, 0);
             if(err)
             {
-                LOGE("cmgf set error : %d\n", err);
+                LOGE(GSW_SMS,"cmgf set error : %d\n", err);
                 for(index = 0; index < msg_num; index++){
                     free(pdu[index]);
                     pdu[index] = NULL;
@@ -726,13 +639,13 @@
             }
             else
             {
-                LOGD("cmgf set success\n");
+                LOGD(GSW_SMS,"cmgf set success\n");
             }
 
             err = mbtk_sms_cmgs_set(sms_info_handle, cmgs, resp);
             if(err)
             {
-                LOGE("cmgs send fail\n");
+                LOGE(GSW_SMS,"cmgs send fail\n");
                 for(index = 0; index < msg_num; index++){
                     free(pdu[index]);
                     pdu[index] = NULL;
@@ -743,7 +656,7 @@
             }
             else
             {
-                LOGD("cmgs send success, resp:%s\n", resp);
+                LOGD(GSW_SMS,"cmgs send success, resp:%s\n", resp);
             }
 
         }
@@ -781,14 +694,14 @@
 
     if(smsc == NULL || len <= 0)
     {
-        LOGE("smsc is null or len = %d\n",len);
+        LOGE(GSW_SMS,"smsc is null or len = %d\n",len);
         return GSW_HAL_ARG_INVALID;
     }
 
     ret = mbtk_sms_csca_get(sms_info_handle, smsc_temp);
     if(smsc_temp[0] == '\0')
     {
-        LOGE("gsw_get_smsc_address Error : %d\n", ret);
+        LOGE(GSW_SMS,"gsw_get_smsc_address Error : %d\n", ret);
         return GSW_HAL_NORMAL_FAIL;
     }
 
@@ -802,7 +715,7 @@
             substr = malloc(len_t + 1);
             if (NULL == substr)
             {
-                LOGE("substr = NULL, malloc faill!!!\n");
+                LOGE(GSW_SMS,"substr = NULL, malloc faill!!!\n");
                 return GSW_HAL_NO_MEMORY;
             }
             strncpy(substr, p1 + 1, len_t);
@@ -810,13 +723,13 @@
             memcpy(smsc, substr, strlen(substr));
             memcpy(sms_center_address, substr, strlen(substr));
 
-            LOGE("qser_sms_getsmscenteraddress success, smsc = %s\n", sms_center_address);
+            LOGE(GSW_SMS,"qser_sms_getsmscenteraddress success, smsc = %s\n", sms_center_address);
             free(substr);
             substr = NULL;
         }
         else
         {
-            LOGE("String inside double quotes not found\n");
+            LOGE(GSW_SMS,"String inside double quotes not found\n");
             return GSW_HAL_NORMAL_FAIL;
         }
     }
@@ -842,7 +755,7 @@
 
     if(smsc == NULL || strlen((char *)smsc) == 0)
     {
-        LOGE("smsc is null or empty\n");
+        LOGE(GSW_SMS,"smsc is null or empty\n");
         return GSW_HAL_ARG_INVALID;
     }
 
@@ -850,11 +763,11 @@
 
     if(ret == 0)
     {
-        LOGE("set smsc success,smsc = %s\n",smsc);
+        LOGE(GSW_SMS,"set smsc success,smsc = %s\n",smsc);
     }
     else
     {
-        LOGE("set smsc fail,ret = %d\n", ret);
+        LOGE(GSW_SMS,"set smsc fail,ret = %d\n", ret);
         return GSW_HAL_NORMAL_FAIL;
     }
 
diff --git a/mbtk/test/libgsw_lib/gsw_pm_test.c b/mbtk/test/libgsw_lib/gsw_pm_test.c
index 933cf9e..49e69d2 100755
--- a/mbtk/test/libgsw_lib/gsw_pm_test.c
+++ b/mbtk/test/libgsw_lib/gsw_pm_test.c
@@ -27,21 +27,31 @@
 int32_t (*gsw_pm_sdk_init)(GSW_PM_WAKEUPCALLBACK );

 int32_t (*gsw_pm_enter_sleep)(const char *gsw_wakelock_name);

 int32_t (*gsw_pm_exit_sleep)(const char *gsw_wakelock_name);

+int32_t (*gsw_get_modem_reset_reason)(int32_t *reset_reason); 

 void (*gsw_modem_log_sync)(void);

 

 const char *tmp_name = "pm_test_lock";

-

 void *dlHandle_pm;

 char *lynqLib_pm = "/lib/libgsw_lib.so";

 

-void user_help(void)

-{

+const char *reset_reason_str[] = {

+    "Normal",

+    "Download",

+    "Power Off",

+    "Hardware",

+    "Command",

+    "Abnormal",

+    "Unknown"

+};

+

+void user_help(void) {

     printf("\t1 autosleep_enable\n"

            "\t2 autosleep_disenable \n"

            "\t3 pm_sdk_init\n"

            "\t4 pm_enter_sleep\n"

            "\t5 pm_exit_sleep\n"

            "\t6 modem_log_sync\n"

+           "\t7 get_modem_reset_reason\n" 

            "please input operator: >> ");

 }

 

@@ -49,6 +59,7 @@
 {

     int ret;

     int opt = 0;

+    int32_t reset_reason = 0;

     dlHandle_pm = dlopen(lynqLib_pm, RTLD_NOW);

     while(1)

     {

@@ -126,7 +137,30 @@
             printf("gsw_modem_log_sync success.\n");

             return 0;

         }

+        case 7:

+        {

+            gsw_get_modem_reset_reason = (int32_t(*)(int32_t*))dlsym(dlHandle_pm, "gsw_get_modem_reset_reason");

+                if (!gsw_get_modem_reset_reason)

+                {

+                    fprintf(stderr, "dlsym error: %s\n", dlerror());

+                    break;

+                }

+                ret = gsw_get_modem_reset_reason(&reset_reason);

+

+                if (ret == 0)

+                {

+                    const char *reason = "Invalid Reason";

+                    if (reset_reason >= 0 && reset_reason <= 6)

+                    {

+                        reason = reset_reason_str[reset_reason];

+                    }

+                    printf("Modem reset reason: %d (%s)\n", reset_reason, reason);

+                } else {

+                    printf("Failed to get reset reason (error: %d)\n", ret);

+                }

+                break;

+        }

         }

     }

     return 0;

-}
\ No newline at end of file
+}