[Bugfix][T108-GSW][bug-view-1671] gsw get signal, no sinr

    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: I7e65622edd9723a66ebf90368df5e58c4aca6dbc
diff --git a/mbtk/libgsw_lib/gsw_nw_interface.c b/mbtk/libgsw_lib/gsw_nw_interface.c
index 147293c..b63690d 100755
--- a/mbtk/libgsw_lib/gsw_nw_interface.c
+++ b/mbtk/libgsw_lib/gsw_nw_interface.c
@@ -31,6 +31,7 @@
 

 typedef unsigned int uint32;

 typedef unsigned char uint8;

+typedef signed char int8;

 typedef unsigned short uint16;

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

 

@@ -288,6 +289,7 @@
                 // 96: -45 dBm �� rsrp < -44 dBm

                 // 97: -44 dBm �� rsrp

                 // 255: not known or not detectable

+    int8  sinr; //-20-35 dbm

 } __attribute__((packed)) mbtk_signal_info_t;

 

 typedef struct{

@@ -674,6 +676,7 @@
     }

 }

 

+#if 0

 static int32_t gsm_rssi_convert_to_dBm(uint8 rssi)

 {

    if(rssi <= 31)

@@ -686,7 +689,7 @@
         return INT_32_MAX;

     }

 }

-

+#endif

 

 static int32_t rscp_convert_to_minus_dBm(uint8 rscp)

 {

@@ -728,7 +731,7 @@
     }

 }

 

-static int32_t sinr_convert_to_10_times_dB(uint8 sinr)

+static int32_t sinr_convert_to_10_times_dB(int8 sinr)

 {

     if(sinr <=35 && sinr>=-20)

     {

@@ -766,8 +769,19 @@
     }

 }

 

-

-

+static int32_t  rxlev_convert_to_rssi_dBm(uint8 rxlev)

+{

+    if(rxlev<=63)

+    {

+        return rxlev-111;  //0 map -111, below -110

+                           // 63 map -48                           

+    }

+    else

+    {

+        return INT_32_MAX;

+    }

+    

+}

 

 //int ecno;        /**< Valid values are positive integers.  This value is the actual Ec/Io multiplied

 //                      * by -10.  Example: If the actual Ec/Io is -12.5 dB, then this response value

@@ -837,9 +851,35 @@
     return 99;        

 }

 

+//uint8 rssi; // 0: 113 dBm or less

+              // 1: 111 dBm

+              // 2��30: 109��53 dBm

+              // 31: 51 dBm or greater

+              // 99: not known or not detectable

+//uint8 rxlev;// 0:rssi < -110 dBm

+              // 1: -110 dBm �� rssi < -109 dBm

+              // 2: -109 dBm �� rssi < -108 dBm

+              // 60   ......

+              // 61: -50 dBm �� rssi < -49 dBm

+              // 62: -49 dBm �� rssi < -48 dBm

+              // 63: -48 dBm �� rssi

+              // 99: not known or not detectable

 

-

-

+/* change realCsq to level */

+static int rxlevToLevel(uint8 rxlev)

+{

+    if (rxlev <=60) {

+        return (rxlev+3)/2;  //  =(rxlev+1)/2+1,

+                               //   0 map 1

+                               //   1,2  map 2

+                               //   59,60  map 31                                     

+    }

+    else if(rxlev <=63)

+    {

+        return 31;

+    }

+    return 99;        

+}

 

 static int convert_reg_state(int reg_state_t)

 {

@@ -1174,7 +1214,7 @@
             sig_strength->rsrp = rsrp_convert_to_minus_dBm(signal->rsrp);

             sig_strength->rsrq = rsrq_convert_to_minus_dB(signal->rsrq);

             sig_strength->rssi = rsrp_minus_dbm_convert_to_rssi_dBm(sig_strength->rsrp);

-            sig_strength->rssnr=INT_32_MAX;

+            sig_strength->rssnr= sinr_convert_to_10_times_dB(signal->sinr);

             break;

         }

         case MBTK_RADIO_TECH_UTRAN:

@@ -1194,9 +1234,9 @@
         case MBTK_RADIO_TECH_GSM_COMPACT:

         case MBTK_RADIO_TECH_GSM_EGPRS:

         {

-            LOGI("g rssi = %d",signal->rssi);

+            LOGI("g rxlev = %d",signal->rxlev);

             sig_strength->gw_sig_valid = 1;

-            sig_strength->rssi = gsm_rssi_convert_to_dBm(signal->rssi);

+            sig_strength->rssi = rxlev_convert_to_rssi_dBm(signal->rxlev);

             break;

         }

         default:

@@ -2036,8 +2076,8 @@
         case MBTK_RADIO_TECH_GSM_COMPACT:

         case MBTK_RADIO_TECH_GSM_EGPRS:

         {

-            LOGD("gsm rssi = %d (0-31)",signal.rssi);

-            *csq_value = signal.rssi;

+            LOGD("gsm rxlev = %d (0-63)",signal.rxlev);

+            *csq_value = rxlevToLevel(signal.rxlev);

             break;

         }

         default:

@@ -2231,13 +2271,11 @@
                     cell_info->rat = GSW_NETWORK_RADIO_GSM;

 

                     cell_info->mcc_valid = 1;

-                    snprintf(gsm_temp, sizeof(gsm_temp) ,"%d", cell->value5);

+                    snprintf(gsm_temp, sizeof(gsm_temp) ,"%X", cell->value5);

                     strncpy(cell_info->mcc, gsm_temp, sizeof(cell_info->mcc));

 

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

-

                     cell_info->mnc_valid = 1;

-                    snprintf(gsm_temp, sizeof(gsm_temp) ,"%d", cell->value6);

+                    snprintf(gsm_temp, sizeof(gsm_temp) ,"%X", cell->value6);

                     strncpy(cell_info->mnc, gsm_temp, sizeof(cell_info->mnc));

 

                     cell_info->cell_id_valid = 1;

@@ -2248,7 +2286,9 @@
 

                     cell_info->arfcn_valid = 1;

                     cell_info->arfcn = cell->value3;

-                    

+

+                    cell_info->rssi=rxlev_convert_to_rssi_dBm(cell->value7);

+                    cell_info->rssi_valid = (cell_info->rssi!=INT_32_MAX);

                     break;

                 }

                     

@@ -2260,13 +2300,11 @@
                     cell_info->rat = GSW_NETWORK_RADIO_UMTS;

 

                     cell_info->mcc_valid = 1;

-                    snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%d", cell->value4);

+                    snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%X", cell->value4);

                     strncpy(cell_info->mcc, wcdma_temp, sizeof(cell_info->mcc));

 

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

-

                     cell_info->mnc_valid = 1;

-                    snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%d", cell->value5);

+                    snprintf(wcdma_temp, sizeof(wcdma_temp) ,"%X", cell->value5);

                     strncpy(cell_info->mnc, wcdma_temp, sizeof(cell_info->mnc));

 

                     cell_info->lac_valid = 1;

@@ -2760,8 +2798,6 @@
  */

 int gsw_get_imei(int len, char *imei)

 {

-    int ret = -1;

-

     if (nw_init_flag == 0 || nw_info_handle == NULL)

     {

         printf("nw sdk has been deinit\n");

@@ -2780,7 +2816,7 @@
         return GSW_HAL_NORMAL_FAIL;

     }

 

-    ret = mbtk_imei_get(nw_info_handle, (void *)imei);

+    int ret = mbtk_imei_get(nw_info_handle, (void *)imei);

     if(ret != MBTK_ERR_OK)

     {

         LOGE("[gsw_nw] mbtk_imei_get fail [err = %d].", ret);