[Bugfix][T108-GSW][bug-view-1717] gsw modem state monitor doesn't work: link only support dlsym

    Only Configure: No
    Affected branch: unknown
    Affected module: network
    Is it affected on both ZXIC and ASR: only ASR
    Self-test: yes
    Doc Update: no

Change-Id: Icbdd355c5c82b00b2912b868b4a7454a11ef1b17
diff --git a/mbtk/libgsw_lib/gsw_nw_interface.c b/mbtk/libgsw_lib/gsw_nw_interface.c
index 90da70b..f1a8f56 100755
--- a/mbtk/libgsw_lib/gsw_nw_interface.c
+++ b/mbtk/libgsw_lib/gsw_nw_interface.c
@@ -2,7 +2,6 @@
 #include <dlfcn.h>

 #include <time.h>

 #include <pthread.h>

-#include <cutils/properties.h>

 #include "gsw_nw_interface.h"

 #define SIG_TIMER 5

 #define MODEM_TIMER 5

@@ -39,7 +38,8 @@
 typedef unsigned short uint16;

 typedef void (*mbtk_info_callback_func)(const void* data, int data_len);

 

-#define MBTK_READY_UCI "persist.mbtk.sdk.state"

+//#define MBTK_READY_UCI "persist.mbtk.sdk.state"

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

 #define MBTK_READY_STRING_SIZE_MAX (3+1)

 

 

@@ -52,8 +52,6 @@
     MBTK_READY_RIL_FAIL

 }mbtk_ready_status_type;

 

-bool str_empty(const void *str);

-

 typedef enum

 {

     MBTK_DEV_MODEM_MIN_FUN,                                   //Modem 最小功能

@@ -360,6 +358,7 @@
 int (*mbtk_oos_get)(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info);

 int (*mbtk_oos_set)(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info);

 int (*mbtk_imei_get)(mbtk_info_handle_t* handle, void *imei);

+bool (*str_empty)(const void *str);

 

 

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

@@ -643,6 +642,13 @@
        LOGE("mbtk_imei_get dlsym fail\n");

        return GSW_HAL_NORMAL_FAIL;

    }

+   

+   str_empty = (bool (*)(const void *str))dlsym(dlHandle_mbtk, "str_empty");

+   if (str_empty == NULL) 

+   {

+       LOGE("str_empty dlsym fail\n");

+       return GSW_HAL_NORMAL_FAIL;

+   }

 

     return GSW_HAL_SUCCESS;

 }

@@ -1266,24 +1272,24 @@
 }

 

 /*

-typedef enum{

-    MBTK_READY_INIT = -1,

-    MBTK_READY_SUCCESS,

-    MBTK_READY_MODEM_FAIL,

-    MBTK_READY_RESPONSE_FAIL,

-    MBTK_READY_SOCKET_FAIL,

-    MBTK_READY_RIL_FAIL

+typedef enum{
+    MBTK_READY_INIT = -1,
+    MBTK_READY_SUCCESS,
+    MBTK_READY_MODEM_FAIL,
+    MBTK_READY_RESPONSE_FAIL,
+    MBTK_READY_SOCKET_FAIL,
+    MBTK_READY_RIL_FAIL
 }mbtk_ready_status_type;

 

-typedef enum gsw_hal_nw_mode_state_type

-{

-    GSW_MODEM_STATE_UNKNOWN = 0,

-    GSW_MODEM_STATE_ONLINE,

-    GSW_MODEM_STATE_OFFLINE,

-    GSW_SDK_STATE_SERVICE_DOWN,

-    GSW_SDK_STATE_SERVICE_UP,// service down->up 需要routectl 重启

-    GSW_SDK_STATE_GPS_DOWN,

-    GSW_SDK_STATE_GPS_UP,

+typedef enum gsw_hal_nw_mode_state_type
+{
+    GSW_MODEM_STATE_UNKNOWN = 0,
+    GSW_MODEM_STATE_ONLINE,
+    GSW_MODEM_STATE_OFFLINE,
+    GSW_SDK_STATE_SERVICE_DOWN,
+    GSW_SDK_STATE_SERVICE_UP,// service down->up 需要routectl 重启
+    GSW_SDK_STATE_GPS_DOWN,
+    GSW_SDK_STATE_GPS_UP,
 } gsw_mode_state_e;

 

 */

@@ -1291,7 +1297,7 @@
 static void convert_uci_to_gsw_modem_state(int uci, int *state)

 {

     switch(uci)

-	{

+    {

         case MBTK_READY_SUCCESS:

             *state=GSW_MODEM_STATE_ONLINE;

             return;

@@ -1455,6 +1461,7 @@
 

 }

 

+

 static void gsw_reject_callback(GSW_NW_RADIO_ACCESS_TECH_E rat, GSW_SERVICE_DOMAIN_E domain, int cause)

 {

     LOGE("gsw_reject_callback start,rat = %d,domain = %d,cause = %d\n",rat,domain,cause);

@@ -1510,16 +1517,36 @@
     }

 }

 

+int get_sdk_ready()

+{

+    char buffer[MBTK_READY_STRING_SIZE_MAX];

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

+    if(NULL == fp)

+    {

+        LOGE("popen sdk ready fail");

+        return -1;

+    }

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

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

+    {

+        pclose(fp);

+        LOGE("fgets failed:");

+        return -1;

+    }

+    pclose(fp);

+    LOGE("get_sdk_ready:%s",buffer);

+    return atoi(buffer);

+}

+

 int gsw_get_modem_state(int *state)

 {

-    char buf[MBTK_READY_STRING_SIZE_MAX];

-    if(property_get(MBTK_READY_UCI, buf, "") > 0 && !str_empty(buf))

+    int uci_value = get_sdk_ready();

+    if(uci_value < 0)

     {

-        int uci_value=atoi(buf);

-        convert_uci_to_gsw_modem_state(uci_value,state);

-        return GSW_HAL_SUCCESS;

+        return GSW_HAL_NORMAL_FAIL;

     }

-    return GSW_HAL_NORMAL_FAIL;

+    convert_uci_to_gsw_modem_state(uci_value,state);

+    return GSW_HAL_SUCCESS;

 }

 

 int g_mode_state=((int)(GSW_MODEM_STATE_UNKNOWN))-1;

@@ -1527,13 +1554,13 @@
 { 

     while(nw_init_flag)

     {

+        int state;

+        int ret = gsw_get_modem_state(&state);

         if(modem_cb != NULL)

         {

-            int state;

-            int ret = gsw_get_modem_state(&state);

             if(ret != 0)

             {

-                LOGE("gsw_get_modem_state fail, ret is %d",ret);

+                modem_cb(GSW_MODEM_STATE_UNKNOWN);

             }

             else if(state!=g_mode_state)

             {

@@ -1645,7 +1672,7 @@
     ret = mbtk_nw_api_import();

     if (ret != 0)

     {

-        LOGE("mbtk_nw_api_import fail\n");

+        printf("mbtk_nw_api_import fail\n");

         return GSW_HAL_NORMAL_FAIL;

     }

 

@@ -2148,7 +2175,7 @@
         return GSW_HAL_NORMAL_FAIL;

     }

 

-    mbtk_signal_info_t signal = {0};

+    mbtk_signal_info_t signal;

     int ret = mbtk_net_signal_get(nw_info_handle, &signal);

     if(ret != 0)

     {

@@ -2309,13 +2336,11 @@
             strcpy(OperatorFN, lynq_operator_mcc_mnc[i].lynq_operator_l);

             strcpy(OperatorSH, lynq_operator_mcc_mnc[i].lynq_operator_s);

 

-            memset(temp,0,sizeof(temp));

-            memset(nw_operator_name_infos->mcc,0,sizeof(nw_operator_name_infos->mcc));

+

             sprintf(temp, "%u", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)/100);

             strncpy(nw_operator_name_infos->mcc, temp, strlen(temp));

 

-            memset(temp,0,sizeof(temp));

-            memset(nw_operator_name_infos->mnc,0,sizeof(nw_operator_name_infos->mnc));

+

             sprintf(temp, "%u", (lynq_operator_mcc_mnc[i].lynq_mcc_mnc)%100);

             strncpy(nw_operator_name_infos->mnc, temp, strlen(temp));

         }

@@ -2370,7 +2395,7 @@
                 case 0:

                 {

                     LOGD("GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell->value1, cell->value2, cell->value3, cell->value4);

-                    char gsm_temp[12] = {0};

+                    char gsm_temp[12];

 

                     cell_info->rat = GSW_NETWORK_RADIO_GSM;

 

@@ -2399,7 +2424,7 @@
                 case 1:

                 {

                     LOGD("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3);

-                    char wcdma_temp[12] = {0};

+                    char wcdma_temp[12];

 

                     cell_info->rat = GSW_NETWORK_RADIO_UMTS;

 

@@ -2428,9 +2453,8 @@
                 case 2:

                 {

                     LOGE("LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);

-                    

-                    char lte_temp[12] = {0};

 

+                    char lte_temp[12];

                     cell_info->rat = GSW_NETWORK_RADIO_LTE;

 

                     cell_info->mcc_valid = 1;

@@ -2517,6 +2541,7 @@
                     char lte_temp[12] = {0};

                     cell_info->ext_info[neibor_count].rat = GSW_NETWORK_RADIO_LTE;

 

+                 

                     cell_info->ext_info[neibor_count].pci = cell->value1;

                     cell_info->ext_info[neibor_count].pci_valid = 1;

 

@@ -2537,8 +2562,6 @@
                           snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value6);

                           strncpy(cell_info->ext_info[neibor_count].mcc, lte_temp, sizeof(cell_info->ext_info[neibor_count].mcc));

 

-                          cell_info->ext_info[neibor_count].cell_id = cell->value5;

-                          cell_info->ext_info[neibor_count].cell_id_valid = 1;

 

                           snprintf(lte_temp, sizeof(lte_temp) ,"%X", cell->value7);

                           strncpy(cell_info->ext_info[neibor_count].mnc, lte_temp, sizeof(cell_info->ext_info[neibor_count].mnc));