[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: Ic2abd478a26300d86b648adef8c922c7da94e3d2
diff --git a/mbtk/mbtk_rild/src/main.c b/mbtk/mbtk_rild/src/main.c
index a0f0afb..f109c54 100755
--- a/mbtk/mbtk_rild/src/main.c
+++ b/mbtk/mbtk_rild/src/main.c
@@ -1446,23 +1446,12 @@
                 goto EEMGINFOSVC_EXIT;

             }

             // mnc

-            if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)

+            if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)

             {

                 goto EEMGINFOSVC_EXIT;

             }

             cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;

-

-            /*

-            // Jump 3 integer.

-            i = 0;

-            while(i < 3) {

-                if (at_tok_nextint(&line, &tmp_int) < 0)

-                {

-                    goto EEMGINFOSVC_EXIT;

-                }

-                i++;

-            }

-            */

+           

             // lac

             if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)

             {

@@ -1477,9 +1466,9 @@
             }

             cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;

 

-            // Jump 2 integer.

+            // Jump 2 integer, get 3rd number

             i = 0;

-            while(i < 2) {

+            while(i < 3) {

                 if (at_tok_nextint(&line, &tmp_int) < 0)

                 {

                     goto EEMGINFOSVC_EXIT;

@@ -1488,15 +1477,27 @@
             }

 

             // bsic

-            if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)

+            if ( tmp_int < 0 || tmp_int >= 65536)

             {

                 goto EEMGINFOSVC_EXIT;

             }

             cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;

 

-            // Jump 15 integer.

+            // Jump 4 integer, get 5rd number

             i = 0;

-            while(i < 15) {

+            while(i < 5) {

+                if (at_tok_nextint(&line, &tmp_int) < 0)

+                {

+                    goto EEMGINFOSVC_EXIT;

+                }

+                i++;

+            }

+

+            cell_info.cell[cell_info.cell_num].value7=tmp_int; //rxlev

+

+            // Jump 10 integer, get 11rd number

+            i = 0;

+            while(i < 11) {

                 if (at_tok_nextint(&line, &tmp_int) < 0)

                 {

                     goto EEMGINFOSVC_EXIT;

@@ -1505,7 +1506,7 @@
             }

 

             // arfcn

-            if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)

+            if (tmp_int < 0 || tmp_int >= 65536)

             {

                 goto EEMGINFOSVC_EXIT;

             }

@@ -1913,87 +1914,87 @@
  */
 static int asrFlagPathGet(char *asr_flag_path)

 {
-	char buf[128];
-	unsigned char find = 0;
+	char buf[128];

+	unsigned char find = 0;

 	FILE *fd = fopen("/proc/mtd", "r");

-	if (fd == NULL) {
+	if (fd == NULL) {

 		LOGE("Open MTD failed!");

 		return -1;

-	}
+	}

 
-	memset(buf, '\0', 128);
-	while (fgets(buf, 128, fd) != NULL) {
-		if(strstr(buf, "asr_flag")) {
-			char *p = strstr(buf, "mtd");
-			if(p)
-			{
-				int bln;
-				sscanf(p, "mtd%d", &bln);
-				sprintf(asr_flag_path, "/dev/mtdblock%d", bln);
-				find = 1;
-				break;
-			}
-		}
-		memset(buf, '\0', 128);
-	}
+	memset(buf, '\0', 128);

+	while (fgets(buf, 128, fd) != NULL) {

+		if(strstr(buf, "asr_flag")) {

+			char *p = strstr(buf, "mtd");

+			if(p)

+			{

+				int bln;

+				sscanf(p, "mtd%d", &bln);

+				sprintf(asr_flag_path, "/dev/mtdblock%d", bln);

+				find = 1;

+				break;

+			}

+		}

+		memset(buf, '\0', 128);

+	}

 
-	fclose(fd);
+	fclose(fd);

 	return ((find == 1) ? 0 : -1);

 }
 

 static int readFromMTD(const char *path, unsigned int offset, void *buf, int size)

 {
-	int ret, fd;
-	if (!path)
-		return -1;
+	int ret, fd;

+	if (!path)

+		return -1;

 
-	fd = open(path, O_RDONLY);
-	if (fd < 0) {
+	fd = open(path, O_RDONLY);

+	if (fd < 0) {

 		LOGE("readFromMTD open error,%d", errno);

-		return -1;
-	}
+		return -1;

+	}

 
-	ret = lseek(fd, offset, SEEK_SET);
-	if (ret < 0) {
-		close(fd);
+	ret = lseek(fd, offset, SEEK_SET);

+	if (ret < 0) {

+		close(fd);

 		LOGE("readFromMTD lseek error,%d", errno);

-		return -1;
-	}
-	ret = read(fd, buf, size);
-	if (ret < 0) {
-		close(fd);
+		return -1;

+	}

+	ret = read(fd, buf, size);

+	if (ret < 0) {

+		close(fd);

 		LOGE("readFromMTD read error,%d", errno);

-		return -1;
-	}
-	close(fd);
-	return 0;
+		return -1;

+	}

+	close(fd);

+	return 0;

 }
 
 static int writeToMTD(const char *path, unsigned int offset, void *buf, int size)

 {
-	int ret, fd;
+	int ret, fd;

 
-	if (!path)
-		return -1;
+	if (!path)

+		return -1;

 
-	fd = open(path, O_RDWR | O_SYNC);
-	if (fd < 0)
-		return -1;
+	fd = open(path, O_RDWR | O_SYNC);

+	if (fd < 0)

+		return -1;

 
-	ret = lseek(fd, offset, SEEK_SET);
-	if (ret < 0) {
-		close(fd);
-		return -1;
-	}
-	ret = write(fd, buf, size);
-	if (ret < 0) {
+	ret = lseek(fd, offset, SEEK_SET);

+	if (ret < 0) {

+		close(fd);

+		return -1;

+	}

+	ret = write(fd, buf, size);

+	if (ret < 0) {

 		LOGE("writetomtd:write error:%d", errno);

-		close(fd);
-		return -1;
-	}
+		close(fd);

+		return -1;

+	}

 
-	close(fd);
-	return 0;
+	close(fd);

+	return 0;

 }

 #endif

 static void fota_result_check()

diff --git a/mbtk/mbtk_rild/src/mbtk_info_server.c b/mbtk/mbtk_rild/src/mbtk_info_server.c
index 3ebaf1a..14926fc 100755
--- a/mbtk/mbtk_rild/src/mbtk_info_server.c
+++ b/mbtk/mbtk_rild/src/mbtk_info_server.c
@@ -2852,27 +2852,27 @@
     printf("cmgl:%s\n", cmgl);
     ATResponse *response = NULL;
     char cmd[500] = {0};
-	char data[218] = {0};
+    char data[218] = {0};
     int err = 0;
 
-	memcpy(data, cmgl, len);
+    memcpy(data, cmgl, len);
 
-	sprintf(cmd, "at*cell=%s", data);
-	printf("cmd:%s\n", cmd);
+    sprintf(cmd, "at*cell=%s", data);
+    printf("cmd:%s\n", cmd);
 
-	if(strlen(cmd) > 0)
-	{
+    if(strlen(cmd) > 0)
+    {
         err = at_send_command_multiline(cmd, "", &response);
-		if (err < 0 || response->success == 0 || !response->p_intermediates){
-			*cme_err = at_get_cme_error(response);
+        if (err < 0 || response->success == 0 || !response->p_intermediates){
+            *cme_err = at_get_cme_error(response);
         //    printf("at_send_command_multiline() is err-----------------\n");
-			goto exit;
-		}
+            goto exit;
+        }
 
         ATLine* lines_ptr = response->p_intermediates;
         char *line = NULL;
 //        int reg_len = 0;
-//		bool flag = false;
+//        bool flag = false;
         while(lines_ptr)
         {
             line = lines_ptr->line;
@@ -2884,9 +2884,9 @@
 
             lines_ptr = lines_ptr->p_next;
         }
-	}
+    }
     err = 0;
-	memcpy(reg, "req_cell_info_set succss", strlen("req_cell_info_set succss"));
+    memcpy(reg, "req_cell_info_set succss", strlen("req_cell_info_set succss"));
 exit:
     at_response_free(response);
     printf("req_cell_info_set()-----------------end\n");
@@ -2918,6 +2918,7 @@
     int tmp_int;
     char *tmp_ptr = NULL;
     // AT+EEMOPT=1 in the first.
+#if 0
     int err = at_send_command_singleline("AT+CSQ", "+CSQ:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err != NULL)
@@ -2939,8 +2940,8 @@
     }
     signal->rssi = (uint8)tmp_int;
     at_response_free(response);
-
-    err = at_send_command_singleline("AT+CESQ", "+CESQ:", &response);
+#endif
+    int err = at_send_command_singleline("AT*CESQ", "*CESQ:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
         if(cme_err != NULL)
             *cme_err = at_get_cme_error(response);
@@ -2948,7 +2949,7 @@
         goto exit;
     }
 
-    line = response->p_intermediates->line;
+    char* line = response->p_intermediates->line;
     err = at_tok_start(&line);
     if (err < 0)
     {
@@ -2996,6 +2997,14 @@
     }
     signal->rsrp = (uint8)tmp_int;
 
+    
+    err = at_tok_nextint(&line, &tmp_int);
+    if (err < 0)
+    {
+        goto exit;
+    }
+    signal->sinr = (int8)tmp_int;
+
     at_response_free(response);
     err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -5191,30 +5200,30 @@
                 }
                 else     // Lock cell
                 {
-	                char *mem = (char*)(pack->data);
-					int len = pack->data_len;
-	                char reg[100] = {0};
-	                printf("mem:%s, len:%d", pack->data, pack->data_len);
+                    char *mem = (char*)(pack->data);
+                    int len = pack->data_len;
+                    char reg[100] = {0};
+                    printf("mem:%s, len:%d", pack->data, pack->data_len);
 
-	                if(req_cell_info_set(mem, reg, len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
-	                {
-	                //    printf("cpms_set fail\n");
-	                    if(cme_err != MBTK_INFO_ERR_CME_NON) {
-	                        err = MBTK_INFO_ERR_CME + cme_err;
-	                    } else {
-	                        err = MBTK_INFO_ERR_UNKNOWN;
-	                    }
-	                //    LOG("Set req_cell_info_set fail.");
-	                }
-	                else
-	                {
+                    if(req_cell_info_set(mem, reg, len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
+                    {
+                    //    printf("cpms_set fail\n");
+                        if(cme_err != MBTK_INFO_ERR_CME_NON) {
+                            err = MBTK_INFO_ERR_CME + cme_err;
+                        } else {
+                            err = MBTK_INFO_ERR_UNKNOWN;
+                        }
+                    //    LOG("Set req_cell_info_set fail.");
+                    }
+                    else
+                    {
 
-	                    printf("req_cell_info_set success, reg:%s\n", reg);
-	                    pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_CELL_RSP, reg, strlen(reg));
+                        printf("req_cell_info_set success, reg:%s\n", reg);
+                        pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_CELL_RSP, reg, strlen(reg));
 
-	                    // Restart is required to take effect.
-	                    LOG("Will reboot system...");
-	                }
+                        // Restart is required to take effect.
+                        LOG("Will reboot system...");
+                    }
                 }
                 break;
             }
@@ -5714,18 +5723,18 @@
                                         mbtk_net_led_set(MBTK_NET_LED_DATA_CONNECT);
                                         pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, NULL, 0);
 #ifdef MBTK_ALL_CID_SUPPORT
-										if(cid == 1) //cid 1 as a special treatment
-										{
-											mbtk_pdp_cb_info_s pdp_cb_info;
-											memset(&pdp_cb_info, 0x00, sizeof(mbtk_pdp_cb_info_s));
-											pdp_cb_info.cid = cid;
-											pdp_cb_info.auto_urc = false;
-											pdp_cb_info.connect_state = true;
-											memcpy(&(pdp_cb_info.ipv4), &ipv4, sizeof(mbtk_ipv4_info_t));
-											memcpy(&(pdp_cb_info.ipv6), &ipv6, sizeof(mbtk_ipv6_info_t));
-											usleep(1000);
-											pack_rsp_send(cli_info->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
-										}
+                                        if(cid == 1) //cid 1 as a special treatment
+                                        {
+                                            mbtk_pdp_cb_info_s pdp_cb_info;
+                                            memset(&pdp_cb_info, 0x00, sizeof(mbtk_pdp_cb_info_s));
+                                            pdp_cb_info.cid = cid;
+                                            pdp_cb_info.auto_urc = false;
+                                            pdp_cb_info.connect_state = true;
+                                            memcpy(&(pdp_cb_info.ipv4), &ipv4, sizeof(mbtk_ipv4_info_t));
+                                            memcpy(&(pdp_cb_info.ipv6), &ipv6, sizeof(mbtk_ipv6_info_t));
+                                            usleep(1000);
+                                            pack_rsp_send(cli_info->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
+                                        }
 #endif
                                     }
                                     else
@@ -6085,7 +6094,7 @@
                 }
                 break;
             }
-			case MBTK_INFO_ID_LED_REQ:
+            case MBTK_INFO_ID_LED_REQ:
             {
                  if(pack->data_len == 0 || pack->data == NULL)
                 {
@@ -7060,7 +7069,7 @@
         {
             // Get network state and signal.
             char buff[256] = {0};
-            uint8 data_signal[8];
+            uint8 data_signal[9];
             mbtk_signal_info_t signal;
             memset(&signal, 0xFF, sizeof(mbtk_signal_info_t));
             if(!req_net_signal_get(&signal, NULL)) {
@@ -7069,24 +7078,24 @@
                 gettimeofday(&log_time, NULL);
                 struct tm* tm_t = localtime(&(log_time.tv_sec));
                 strftime(tmp, 50, "%F %T", tm_t);
-                snprintf(buff, sizeof(buff), "%s:%d,%d,%d,%d,%d,%d,%d,%d", tmp, signal.type, signal.rssi, signal.rxlev, signal.ber, signal.rscp, signal.ecno,
-                    signal.rsrq, signal.rsrp);
+                snprintf(buff, sizeof(buff), "%s:%d,%d,%d,%d,%d,%d,%d,%d,%d", tmp, signal.type, signal.rssi, signal.rxlev, signal.ber, signal.rscp, signal.ecno,
+                    signal.rsrq, signal.rsrp,signal.sinr);
                 mbtk_signal_log(buff);
-            }
-
-            if(signal_globe.type != signal.type)
-            {
-                data_signal[0] = signal.type;
-                data_signal[1] = signal.rssi;
-                data_signal[2] = signal.rxlev;
-                data_signal[3] = signal.ber;
-                data_signal[4] = signal.rscp;
-                data_signal[5] = signal.ecno;
-                data_signal[6] = signal.rsrq;
-                data_signal[7] = signal.rsrp;
-                signal_globe.type = signal.type;
-                signal_state_change(data_signal, sizeof(data_signal));
-            }
+                if(signal_globe.type != signal.type)
+                {
+                    data_signal[0] = signal.type;
+                    data_signal[1] = signal.rssi;
+                    data_signal[2] = signal.rxlev;
+                    data_signal[3] = signal.ber;
+                    data_signal[4] = signal.rscp;
+                    data_signal[5] = signal.ecno;
+                    data_signal[6] = signal.rsrq;
+                    data_signal[7] = signal.rsrp;
+                    data_signal[8] = signal.sinr;
+                    signal_globe.type = signal.type;
+                    signal_state_change(data_signal, sizeof(data_signal));
+                }
+            }          
             break;
         }
         case INFO_URC_MSG_CALL_STATE:
@@ -7267,24 +7276,24 @@
 static int partition_name_2_dev(const char *name, char *dev) {
     if(name == NULL || dev == NULL) {
         LOGE("ARG error.");
-		return -1;
+        return -1;
     }
 
     FILE* fp = fopen("/proc/mtd", "r");
-	if (fp == NULL) {
-		LOGE("Open MTD failed!");
-		return -1;
-	}
+    if (fp == NULL) {
+        LOGE("Open MTD failed!");
+        return -1;
+    }
 
     char buf[1024];
-	while (fgets(buf, 1024, fp) != NULL) {
-		if(strstr(buf, name)) {
+    while (fgets(buf, 1024, fp) != NULL) {
+        if(strstr(buf, name)) {
             int index = atoi(buf + 3);
             sprintf(dev, "/dev/mtdblock%d", index);
             LOGD("%s -> %s", name, dev);
             return 0;
-		}
-	}
+        }
+    }
 
     return -1;
 }