[Bugfix][T108-GSW][bug-view-1583] gsw_get_cellinfo: miss info

    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: Ie1f0f9e6a9a7cf13627269a7063f8af5e92c06de
diff --git a/mbtk/libgsw_lib/gsw_nw_interface.c b/mbtk/libgsw_lib/gsw_nw_interface.c
index c8853c0..147293c 100755
--- a/mbtk/libgsw_lib/gsw_nw_interface.c
+++ b/mbtk/libgsw_lib/gsw_nw_interface.c
@@ -91,28 +91,32 @@
 

 typedef struct

 {

+    // NR server cell:

+    // NR cell:

     // LTE server cell: tac, PCI, dlEuarfcn, ulEuarfcn, band

     // LTE cell: phyCellId,euArfcn,rsrp,rsrq

     // WCDMA server cell: lac, ci, arfcn

     // WCDMA cell: lac, ci, arfcn

     // GSM server cell: lac, ci, arfcn, bsic

     // GSM cell:

-    uint32 value1;

-    uint32 value2;

-    uint32 value3;

-    uint32 value4;

-    uint32 value5;

-    uint32 value6;

-    uint32 value7;

-    uint32 value8;

-    uint32 value9;

-    uint32 value10;

+    uint32 value1; //tac

+    uint32 value2; //pci

+    uint32 value3; //dlEuarfcn

+    uint32 value4; //bler

+    uint32 value5; //band

+    uint32 value6; //mcc

+    uint32 value7; //mnc

+    uint32 value8; //rsrp

+    uint32 value9; //rsrq

+    uint32 value10; //cell identiy

+    uint32 value11; //sinr

+    uint32 value12; //is tdd

+    uint32 value13;

+    uint32 value14;

+    uint32 value15;

 } __attribute__((packed)) mbtk_cell_info_t;

 

 

-

-

-

 typedef struct

 {

     uint8 net_pref;     // mbtk_net_pref_enum

@@ -302,11 +306,11 @@
 #define lib_mbtk_path "/lib/libmbtk_lib.so"

 mbtk_info_handle_t*       nw_info_handle = NULL;

 

-static GSW_NW_ServingInfoHandlePtr serving_cb;

-static GSW_NW_SigInfoHandlePtr sig_cb;

-static GSW_NW_RejectCauseHandlePtr reject_cb;

-static GSW_NW_ModemStateHandlePtr modem_cb;

-static GSW_NW_AirplaneModeHandlePtr airplane_cb;

+static GSW_NW_ServingInfoHandlePtr serving_cb=NULL;

+static GSW_NW_SigInfoHandlePtr sig_cb=NULL;

+static GSW_NW_RejectCauseHandlePtr reject_cb=NULL;

+static GSW_NW_ModemStateHandlePtr modem_cb=NULL;

+static GSW_NW_AirplaneModeHandlePtr airplane_cb=NULL;

 

 static void *dlHandle_mbtk;

 int nw_init_flag = 0;

@@ -670,6 +674,20 @@
     }

 }

 

+static int32_t gsm_rssi_convert_to_dBm(uint8 rssi)

+{

+   if(rssi <= 31)

+    {

+        return rssi * 2 - 113;  //0 map -113

+                                //31 map -51

+    }

+    else

+    {

+        return INT_32_MAX;

+    }

+}

+

+

 static int32_t rscp_convert_to_minus_dBm(uint8 rscp)

 {

     if(rscp <= 96)

@@ -710,6 +728,46 @@
     }

 }

 

+static int32_t sinr_convert_to_10_times_dB(uint8 sinr)

+{

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

+    {

+        return sinr*10;   //35 map 350 db

+                            // -20 map -2000 db

+    }

+    else 

+    {

+        return INT_32_MAX;

+    }

+}

+

+

+static int32_t rscp_minus_dbm_convert_to_rssi_dBm(int32_t rscp)

+{

+    if(rscp!=INT_32_MAX)

+    {

+        return -rscp;

+    }

+    else

+    {

+        return INT_32_MAX;

+    }

+}

+

+static int32_t rsrp_minus_dbm_convert_to_rssi_dBm(int32_t rsrp)

+{

+    if(rsrp!=INT_32_MAX)

+    {

+        return -rsrp;

+    }

+    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

@@ -1115,7 +1173,7 @@
             sig_strength->lte_sig_valid = 1;

             sig_strength->rsrp = rsrp_convert_to_minus_dBm(signal->rsrp);

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

-            sig_strength->rssi =rsrpToLevel(signal->rsrp-141);

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

             sig_strength->rssnr=INT_32_MAX;

             break;

         }

@@ -1129,7 +1187,7 @@
             sig_strength->wcdma_sig_valid = 1;

             sig_strength->rscp = rscp_convert_to_minus_dBm(signal->rscp);

             sig_strength->ecno = ecno_convert_to_minus_10_times_dB(signal->ecno);

-            sig_strength->rssi =rscpToLevel(signal->rscp-121);

+            sig_strength->rssi = rscp_minus_dbm_convert_to_rssi_dBm(sig_strength->rscp);   

             break;

         }

         case MBTK_RADIO_TECH_GSM:

@@ -1138,7 +1196,7 @@
         {

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

             sig_strength->gw_sig_valid = 1;

-            sig_strength->rssi = signal->rssi;

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

             break;

         }

         default:

@@ -2144,7 +2202,6 @@
  */

 int gsw_get_cell_info(GSW_NW_CELL_INFO *cell_info)

 {

-    int ret = -1;

 

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

     {

@@ -2153,12 +2210,14 @@
     }

 

     list_node_t* cell_list = NULL;

-    int neibor_count = 0;

     mbtk_cell_type_enum type;

-    ret = mbtk_cell_get(nw_info_handle, &type, &cell_list);

+    int ret = mbtk_cell_get(nw_info_handle, &type, &cell_list);

     if(ret || cell_list == NULL) {

         LOGE("mbtk_cell_get failed : %d\n", ret);

+        list_free(cell_list);

+        return GSW_HAL_NORMAL_FAIL;

     } else {

+        memset(cell_info,0,sizeof(GSW_NW_CELL_INFO));

         list_first(cell_list);

         mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list);

         if(cell) { // Current server cell.

@@ -2167,7 +2226,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;

 

@@ -2196,7 +2255,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;

 

@@ -2227,17 +2286,14 @@
                 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;

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

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

 

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

-

                     cell_info->mnc_valid = 1;

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

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

@@ -2257,15 +2313,25 @@
                     cell_info->band_valid = 1;

                     cell_info->band = cell->value5;

 

-                    cell_info->rsrp_valid = 1;

-                    cell_info->rsrp = cell->value8;

+                    cell_info->rssnr = sinr_convert_to_10_times_dB(cell->value11);

+                    cell_info->rssnr_valid=(cell_info->rssnr!=INT_32_MAX);

 

-                    cell_info->rsrq_valid = 1;

-                    cell_info->rsrq = cell->value9;

+                    cell_info->lteMode_valid = 1;

+                    cell_info->lteMode =(!(cell->value12));            

+

+                    

+                    cell_info->rsrp = rsrp_convert_to_minus_dBm(cell->value8);

+                    cell_info->rsrp_valid = (cell_info->rsrp!=INT_32_MAX);

+

+                    cell_info->rsrq = rsrq_convert_to_minus_dB(cell->value9);

+                    cell_info->rsrq_valid = (cell_info->rsrq!=INT_32_MAX);

 

                     cell_info->cell_id_valid = 1;

                     cell_info->cell_id = cell->value10;

 

+                    cell_info->rssi=rsrp_minus_dbm_convert_to_rssi_dBm(cell_info->rsrp);

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

+

                     break;

                 }

 

@@ -2273,7 +2339,7 @@
                     break;

             }

         }

-

+        int neibor_count = 0;

         while ((cell = (mbtk_cell_info_t*) list_next(cell_list)) && neibor_count < 5)

         {

             switch(type)

@@ -2308,34 +2374,40 @@
                     char lte_temp[12] = {0};

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

 

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

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

-

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

-

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

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

-

+                 

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

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

 

                     cell_info->ext_info[neibor_count].arfcn = cell->value2;

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

 

-                    cell_info->ext_info[neibor_count].rsrp = cell->value3;

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

+                    cell_info->ext_info[neibor_count].rsrp = rsrp_convert_to_minus_dBm(cell->value3);

+                    cell_info->ext_info[neibor_count].rsrp_valid = (cell_info->ext_info[neibor_count].rsrp!=INT_32_MAX);

 

-                    cell_info->ext_info[neibor_count].rsrq = cell->value4;

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

+                    cell_info->ext_info[neibor_count].rsrq = rsrq_convert_to_minus_dB(cell->value4);

+                    cell_info->ext_info[neibor_count].rsrq_valid = (cell_info->ext_info[neibor_count].rsrq!=INT_32_MAX);                 

+                    

+                    if(cell->value7!=INT_32_MAX)

+                    {

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

 

-                    cell_info->ext_info[neibor_count].band = cell->value9;

-                    cell_info->ext_info[neibor_count].band_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));

+                         

+                          

+                          //value 8 is tac

 

-                    cell_info->ext_info[neibor_count].rssi = cell->value10;

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

+                          cell_info->ext_info[neibor_count].band = cell->value9;

+                          cell_info->ext_info[neibor_count].band_valid = 1;

+

+                          cell_info->ext_info[neibor_count].rssi=rsrp_minus_dbm_convert_to_rssi_dBm(cell_info->ext_info[neibor_count].rsrp);

+                          cell_info->ext_info[neibor_count].rssi_valid = (cell_info->ext_info[neibor_count].rssi!=INT_32_MAX);

+                    }

 

                     neibor_count++;

                 }

@@ -2344,6 +2416,7 @@
                     break;

             }

         }

+        cell_info->ext_info_len=neibor_count;

     }

     list_free(cell_list);