优化demo代码解决NW部分参数处理错误

Change-Id: I4db3c717b535160ff7dc12bc9723d0d03ef303e8
diff --git a/mbtk/liblynq_lib/src/lynq_network.c b/mbtk/liblynq_lib/src/lynq_network.c
index 98bf359..86bd562 100755
--- a/mbtk/liblynq_lib/src/lynq_network.c
+++ b/mbtk/liblynq_lib/src/lynq_network.c
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+
 mbtk_info_handle_t* lynq_nw_info_handle = NULL;
 uint64_t tmp_mode = 0xFF;
 
@@ -49,8 +50,197 @@
     {"China Telecom","CT",46011}
 };
 
-void lynq_nw_state_change_cb(const void* data, int data_len)
+#if 0
+//T106的实现
+/*Used to wait for an update signal*/
+int lynq_wait_signalchanges(int *handle)
 {
+    LYDBGLOG("start wait signalchanges info");
+    if(NULL == handle)
+    {
+        LYERRLOG("illegal input");
+        return LYNQ_E_PARAMETER_ANONALY;
+    }
+    wait_urc_signal_changes();
+    LYDBGLOG("get signalchanges");
+    *handle = s_module_wait_urc_id;
+    return RESULT_OK;   
+}
+
+bool is_support_urc(int urc_id)
+{
+    switch(urc_id)
+    {
+        case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
+        case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED:
+        case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
+        case RIL_UNSOL_SIGNAL_STRENGTH:
+            return true;                
+        default:
+            return false;
+    }    
+}
+
+/*Used to get urc info*/
+int lynq_get_urc_info(const int handle,signalStrength_t *solSigStren,int *slot_id)
+{
+    if(g_module_init_flag != MODULE_RUNNING)
+    {
+        LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+        return -1;
+    }
+    LYDBGLOG("start get urc info");
+    if(is_support_urc(handle)==false)
+    {
+        LYINFLOG("invalid handle!!!");
+        return -1;
+    }
+    if((handle ==RIL_UNSOL_SIGNAL_STRENGTH && NULL == solSigStren) || 
+        (handle !=RIL_UNSOL_SIGNAL_STRENGTH && NULL == slot_id))
+    {
+        LYINFLOG("incoming solSigStren or slot_id is NULL!!!");
+        return -1;
+    }
+    switch(handle)
+    {        
+        case RIL_UNSOL_SIGNAL_STRENGTH: //1009
+        {
+            LYDBGLOG("get state update to signal info");
+            solSigStren->gw_sig_valid = s_network_urc_solSigStren.gw_sig_valid;
+            solSigStren->rssi = s_network_urc_solSigStren.rssi;
+            solSigStren->wcdma_signalstrength = s_network_urc_solSigStren.wcdma_signalstrength;
+            solSigStren->wcdma_sig_valid = s_network_urc_solSigStren.wcdma_sig_valid;
+            solSigStren->rscp = s_network_urc_solSigStren.rscp;
+            solSigStren->ecno = s_network_urc_solSigStren.ecno;
+            solSigStren->lte_signalstrength = s_network_urc_solSigStren.lte_signalstrength;
+            solSigStren->lte_sig_valid = s_network_urc_solSigStren.lte_sig_valid;
+            solSigStren->rsrp = s_network_urc_solSigStren.rsrp;
+            solSigStren->rsrq = s_network_urc_solSigStren.rsrq;
+            solSigStren->rssnr = s_network_urc_solSigStren.rssnr;
+            solSigStren->nr_sig_valid = s_network_urc_solSigStren.nr_sig_valid;
+            solSigStren->ssRsrp = s_network_urc_solSigStren.ssRsrp;
+            solSigStren->ssRsrq = s_network_urc_solSigStren.ssRsrq;
+            solSigStren->ssSinr = s_network_urc_solSigStren.ssSinr;
+            solSigStren->csiRsrp = s_network_urc_solSigStren.csiRsrp;
+            solSigStren->csiRsrq = s_network_urc_solSigStren.csiRsrq;
+            solSigStren->csiSinr = s_network_urc_solSigStren.csiSinr;
+            break;
+        }
+        default:
+        {
+            *slot_id = s_module_urc_slot_id;
+            LYINFLOG("slot_id = %d",s_module_urc_slot_id);
+        }        
+    }
+    return 0;   
+}
+
+
+void urc_msg_process_voice_reg()
+{
+    if(s_handlerPtr != NULL)
+    {
+        s_handlerPtr(g_nw_val,NW_IND_VOICE_REG_EVENT_IND_FLAG,NULL,0,s_contextPtr);
+    }
+}
+
+void urc_msg_process_data_reg()
+{
+    if(s_handlerPtr != NULL)
+    {
+        s_handlerPtr(g_nw_val,NW_IND_DATA_REG_EVENT_IND_FLAG,NULL,0,s_contextPtr);
+    }  
+}
+
+void urc_msg_process_ims_reg()
+{
+    if(s_handlerPtr != NULL)
+    {
+        s_handlerPtr(g_nw_val,NW_IND_IMS_REG_EVENT_IND_FLAG,NULL,0,s_contextPtr);
+    }
+}
+
+void *new_network_thread_recv(void *context)
+{
+    int handle = -1;  
+    uint32_t ind_flag = 0;
+
+    while (1)
+    {
+        lynq_wait_signalchanges(&handle);
+
+        switch(handle)
+        {
+            case 1002: //RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
+            {
+                urc_msg_process_voice_reg();
+               
+                break;
+            }
+            case 3015://RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED:
+            {   
+                urc_msg_process_data_reg();               
+                break;
+            }        
+            case 1009://RIL_UNSOL_SIGNAL_STRENGTH:
+            {   
+                urc_msg_process_signal_strength();
+                break;
+            }
+            case 1037://RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
+            {   
+                urc_msg_process_ims_reg();
+                break;
+            }
+        }        
+    }
+    return NULL;
+}
+
+void urc_msg_process_signal_strength()
+{
+    signalStrength_t signalstrength;
+    int slot_id;
+
+    int ret = lynq_get_urc_info(1009,&signalstrength,&slot_id);
+    if (ret == 0)
+    {
+        QSER_NW_SINGNAL_EVENT_IND_T msg_buf;
+        msg_buf.gsm_sig_info_valid = signalstrength.gw_sig_valid;
+        msg_buf.gsm_sig_info.rssi = signalstrength.rssi;
+        msg_buf.wcdma_sig_info_valid = signalstrength.wcdma_sig_valid;
+        msg_buf.wcdma_sig_info.rssi = signalstrength.rscp;
+        msg_buf.wcdma_sig_info.ecio = signalstrength.ecno;
+        msg_buf.tdscdma_sig_info_valid = 0;
+        msg_buf.lte_sig_info_valid = signalstrength.lte_sig_valid;
+        msg_buf.lte_sig_info.rssi = -125;
+        msg_buf.lte_sig_info.rsrp = signalstrength.rsrp;
+        msg_buf.lte_sig_info.rsrq = signalstrength.rsrq;
+        msg_buf.lte_sig_info.snr = signalstrength.rssnr;
+        msg_buf.cdma_sig_info_valid = 0;
+        msg_buf.hdr_sig_info_valid = 0;
+        msg_buf.nr_sig_info_valid = signalstrength.nr_sig_valid;
+        msg_buf.nr_sig_info.ssRsrp = signalstrength.ssRsrp;
+        msg_buf.nr_sig_info.ssRsrq = signalstrength.ssRsrq;
+        msg_buf.nr_sig_info.ssSinr = signalstrength.ssSinr;
+        msg_buf.nr_sig_info.csiRsrp = signalstrength.csiRsrp;
+        msg_buf.nr_sig_info.csiRsrq = signalstrength.csiRsrq;
+        msg_buf.nr_sig_info.csiSinr = signalstrength.csiSinr;
+        void *ind_msg_buf= &msg_buf;
+        if(s_handlerPtr!=NULL)
+        {
+            s_handlerPtr(g_nw_val,NW_IND_SIGNAL_STRENGTH_EVENT_IND_FLAG,ind_msg_buf,sizeof (msg_buf) ,s_contextPtr);
+        }         
+   }   
+}
+
+#endif
+
+
+
+void lynq_signal_state_change_cb(const void* data, int data_len)
+{
+#if 0
 
 /*
     uint8 *net_data = NULL;
@@ -74,10 +264,87 @@
     }
 */
 
-    if(lynq_func_cb_handle.handlerPtr != NULL)//数据原样输出
+    if(s_handlerPtr != NULL)//数据原样输出
     {
-        lynq_func_cb_handle.handlerPtr(g_nw_val, NW_IND_DATA_REG_EVENT_IND_FLAG, data, data_len, NULL);
+        s_handlerPtr(g_nw_val, NW_IND_DATA_REG_EVENT_IND_FLAG, data, data_len, NULL);
     }
+#endif
+
+    /*
+    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;
+    */
+
+    uint8 *net_data = NULL;
+    QSER_NW_SINGNAL_EVENT_IND_T msg_buf;
+
+    if(data && data_len > 0)
+    {
+        net_data = (uint8*)data;
+        //printf("net_data[0] => *net_data =%d\n",*net_data);
+        msg_buf.gsm_sig_info_valid = FALSE;
+        msg_buf.lte_sig_info_valid = FALSE;
+        msg_buf.wcdma_sig_info_valid = FALSE;
+
+        if(*net_data == MBTK_RADIO_TECH_GSM || *net_data == MBTK_RADIO_TECH_GSM_COMPACT || \
+           *net_data == MBTK_RADIO_TECH_GSM_EGPRS)              //GSM
+        {
+            msg_buf.gsm_sig_info_valid = TRUE;
+        }
+        else if(*net_data == MBTK_RADIO_TECH_E_UTRAN)     //LTE
+        {
+            msg_buf.lte_sig_info_valid = TRUE;
+        }
+        else if (*net_data == MBTK_RADIO_TECH_UTRAN || *net_data == MBTK_RADIO_TECH_UTRAN_HSDPA || \
+                 *net_data == MBTK_RADIO_TECH_UTRAN_HSUPA || *net_data == MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA ||  \
+                 *net_data == MBTK_RADIO_TECH_UTRAN_HSPA )//WCDMA
+        {
+            msg_buf.wcdma_sig_info_valid = TRUE;
+        }
+
+        //msg_buf.gsm_sig_info_valid = TRUE;//signalstrength.gw_sig_valid;
+        msg_buf.gsm_sig_info.rssi = *(net_data + 1);//signalstrength.rssi;
+        printf("rssi = %d\n", *(net_data + 1));
+        //msg_buf.wcdma_sig_info_valid = TRUE;//.wcdma_sig_valid;
+        msg_buf.wcdma_sig_info.rssi = *(net_data + 4);//signalstrength.rscp;
+        printf("rscp = %d\n", *(net_data + 4));
+        msg_buf.wcdma_sig_info.ecio = *(net_data + 5);//signalstrength.ecno;
+        printf("ecno = %d\n", *(net_data + 5));
+        msg_buf.tdscdma_sig_info_valid = FALSE;
+        //msg_buf.lte_sig_info_valid = TRUE;//signalstrength.lte_sig_valid;
+        msg_buf.lte_sig_info.rssi = -125;
+        msg_buf.lte_sig_info.rsrp = *(net_data + 7);//signalstrength.rsrp;
+        printf("rsrp = %d\n", *(net_data + 7));
+        msg_buf.lte_sig_info.rsrq = *(net_data + 6);//signalstrength.rsrq;
+        printf("rsrq = %d\n", *(net_data + 6));
+        msg_buf.lte_sig_info.snr = 0x7FFFFFFFF; //signalstrength.rssnr;(当前mbtk没有该参数)
+        msg_buf.cdma_sig_info_valid = FALSE;
+        msg_buf.hdr_sig_info_valid = FALSE;
+        msg_buf.nr_sig_info_valid = FALSE;//(当前mbtk没有该参数)
+        msg_buf.nr_sig_info.ssRsrp = 0;
+        msg_buf.nr_sig_info.ssRsrq = 0;
+        msg_buf.nr_sig_info.ssSinr = 0;
+        msg_buf.nr_sig_info.csiRsrp = 0;
+        msg_buf.nr_sig_info.csiRsrq = 0;
+        msg_buf.nr_sig_info.csiSinr = 0;
+
+        void *ind_msg_buf= &msg_buf;
+        if(lynq_func_cb_handle.handlerPtr != NULL)
+        {
+            lynq_func_cb_handle.handlerPtr(g_nw_val, NW_IND_SIGNAL_STRENGTH_EVENT_IND_FLAG, ind_msg_buf, sizeof (msg_buf), lynq_func_cb_handle.contextPtr);
+        }
+    }
+    else
+    {
+        LOGE("lynq_nw_state_change_cb : NULL");
+    }
+
 }
 
 
@@ -154,24 +421,24 @@
     } else {
         switch(net_mode)
         {
-            //只做234G的下配 MBTK_NET_PREF_GSM_ONLY/MBTK_NET_PREF_GSM_UMTS_UMTS_PREF/MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF
+            //只做234G的下配 MBTK_NET_PREF_GSM_ONLY/MBTK_NET_PREF_UMTS_ONLY/MBTK_NET_PREF_LTE_ONLY
             case QSER_NW_MODE_GSM:
                 mbtk_net_pre = MBTK_NET_PREF_GSM_ONLY;
                 break;
             case QSER_NW_MODE_WCDMA:
-                mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_UMTS_PREF;
+                mbtk_net_pre = MBTK_NET_PREF_UMTS_ONLY;
                 break;
             case QSER_NW_MODE_CDMA:
-                mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_UMTS_PREF;
+                //mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_UMTS_PREF;
                 break;
             case QSER_NW_MODE_EVDO:
-                mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_UMTS_PREF;
+                //mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_UMTS_PREF;
                 break;
             case QSER_NW_MODE_LTE:
-                mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF;
+                mbtk_net_pre = MBTK_NET_PREF_LTE_ONLY;
                 break;
             case QSER_NW_MODE_TDSCDMA:
-                mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_UMTS_PREF;
+                //mbtk_net_pre = MBTK_NET_PREF_GSM_UMTS_UMTS_PREF;
                 break;
             default:
                 mbtk_net_pre = 0xFF;
@@ -213,6 +480,8 @@
         return -1;
     }
 
+    mbtk_signal_state_change_cb_reg(lynq_nw_info_handle, NULL);
+
     if(lynq_nw_info_handle)
     {
         mbtk_info_handle_free(&lynq_nw_info_handle);
@@ -406,11 +675,35 @@
         //暂时未知是否其他也被使用,现根据ql模块的传输情况,
         //只配置3gpp,涉及call,data状态没有对应的匹配的就没有赋值
 
-        pt_info->voice_registration_valid = FALSE;
-        //pt_info->voice_registration
+        pt_info->voice_registration_valid = TRUE;
+        pt_info->voice_registration.deny_reason = 0;
+        pt_info->voice_registration.roaming = 0;
+        pt_info->voice_registration.tech_domain = 0;
 
-        pt_info->data_registration_valid = FALSE;
-        //pt_info->data_registration
+
+        pt_info->data_registration_valid = TRUE;
+        pt_info->data_registration.deny_reason = 0;
+        pt_info->data_registration.roaming = 0;
+        pt_info->data_registration.tech_domain = 0;
+
+        if (reg.call_state == 1 || reg.call_state == 5)
+        {
+            pt_info->voice_registration.registration_state = E_QSER_NW_SERVICE_FULL;
+        }
+        else if (reg.call_state == 0 || reg.call_state == 2 || reg.call_state == 3 || reg.call_state == 4)
+        {
+            pt_info->voice_registration.registration_state = E_QSER_NW_SERVICE_NONE;
+        }
+        
+        if (reg.data_state == 1 || reg.data_state == 5)
+        {
+            pt_info->data_registration.registration_state = E_QSER_NW_SERVICE_FULL;
+        }
+        else if (reg.data_state == 0 || reg.data_state == 2 || reg.data_state == 3 || reg.data_state == 4)
+        {
+            pt_info->data_registration.registration_state = E_QSER_NW_SERVICE_NONE;
+        }
+
 
         pt_info->voice_registration_details_3gpp_valid = TRUE;
         pt_info->voice_registration_details_3gpp.lac = reg.lac;
@@ -449,6 +742,8 @@
             {
                 pt_info->data_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_GPRS;
                 pt_info->voice_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_GSM;
+                pt_info->data_registration.radio_tech = E_QSER_NW_RADIO_TECH_GPRS;
+                pt_info->voice_registration.radio_tech = E_QSER_NW_RADIO_TECH_GSM;
                 break;
             }
             case MBTK_RADIO_TECH_UTRAN:
@@ -458,18 +753,26 @@
             {
                 pt_info->data_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_UMTS;
                 pt_info->voice_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_UMTS;
+                pt_info->data_registration.radio_tech = E_QSER_NW_RADIO_TECH_UMTS;
+                pt_info->voice_registration.radio_tech = E_QSER_NW_RADIO_TECH_UMTS;
                 break;
             }
             case MBTK_RADIO_TECH_E_UTRAN:
             {
                 pt_info->data_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_LTE;
                 pt_info->voice_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_LTE;
+                pt_info->data_registration.radio_tech = E_QSER_NW_RADIO_TECH_LTE;
+                pt_info->voice_registration.radio_tech = E_QSER_NW_RADIO_TECH_LTE;
                 break;
             }
             default:
             {
                 pt_info->data_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_NONE;
                 pt_info->voice_registration_details_3gpp.radio_tech = E_QSER_NW_RADIO_TECH_NONE;
+                pt_info->data_registration.radio_tech = E_QSER_NW_RADIO_TECH_NONE;
+                pt_info->voice_registration.radio_tech = E_QSER_NW_RADIO_TECH_NONE;
+                pt_info->data_registration.registration_state = E_QSER_NW_SERVICE_NONE;
+                pt_info->voice_registration.registration_state = E_QSER_NW_SERVICE_NONE;
                 break;
             }
         }
@@ -510,6 +813,7 @@
     else
     {
         memset(pt_info, 0x0, sizeof(QSER_NW_SIGNAL_STRENGTH_INFO_T));
+        
         if(signal.type == MBTK_RADIO_TECH_GSM || signal.type == MBTK_RADIO_TECH_GSM_COMPACT || \
            signal.type == MBTK_RADIO_TECH_GSM_EGPRS)              //GSM
         {
@@ -521,21 +825,44 @@
             pt_info->lte_sig_info_valid = TRUE;
             pt_info->lte_sig_info.rsrp = signal.rsrp;
             pt_info->lte_sig_info.rsrq = signal.rsrq;
-            pt_info->lte_sig_info.snr = 0;                  //->MBTK接口无该参数,写死值为0
-            pt_info->lte_sig_info.rssi = signal.rssi;
+            pt_info->lte_sig_info.snr = 0x7FFFFFFFF;                  //->MBTK接口无该参数(对应参数为rssnr,该值INT_MAX:0x7FFFFFFFF表示无效值),写死值为0x7FFFFFFFF 
+            pt_info->lte_sig_info.rssi = -125;
         }
         else if (signal.type == MBTK_RADIO_TECH_UTRAN || signal.type == MBTK_RADIO_TECH_UTRAN_HSDPA || \
                  signal.type == MBTK_RADIO_TECH_UTRAN_HSUPA || signal.type == MBTK_RADIO_TECH_UTRAN_HSDPA_HSUPA ||  \
                  signal.type == MBTK_RADIO_TECH_UTRAN_HSPA )//WCDMA
         {
             pt_info->wcdma_sig_info_valid = TRUE;
-            pt_info->wcdma_sig_info.rssi = signal.rssi;
-            pt_info->wcdma_sig_info.ecio = 0;               //->MBTK接口无该参数,写死值为0
+            pt_info->wcdma_sig_info.rssi = signal.rscp;
+            pt_info->wcdma_sig_info.ecio = signal.ecno;
         }
         else
         {
             return -1;
         }
+        /*
+        pt_info->gsm_sig_info_valid = 1//signal.gw_sig_valid;
+        pt_info->gsm_sig_info.rssi = signal.rssi;//signal.rssi-110;
+        pt_info->wcdma_sig_info_valid = 1//signal.wcdma_sig_valid;
+        pt_info->wcdma_sig_info.rssi = signal.rscp;//signal.wcdma_signalstrength-110;
+        pt_info->wcdma_sig_info.ecio = //signal.ecno/5;
+        pt_info->tdscdma_sig_info_valid = 0;
+        pt_info->lte_sig_info_valid = 1//signal.lte_sig_valid;
+        pt_info->lte_sig_info.rssi = -125;//signal.lte_signalstrength-110;
+        pt_info->lte_sig_info.rsrp = signal.rsrp;//signal.rsrp*(-1);
+        pt_info->lte_sig_info.rsrq = signal.rsrq;//signal.rsrq*(-1);
+        pt_info->lte_sig_info.snr = 0x7FFFFFFFF;//signal.rssnr;
+        pt_info->cdma_sig_info_valid = 0;
+        pt_info->hdr_sig_info_valid = 0;
+        //mbtk 无nr
+        pt_info->nr_sig_info_valid = 0//signal.nr_sig_valid;
+        pt_info->nr_sig_info.ssRsrp = 0//signal.ssRsrp;
+        pt_info->nr_sig_info.ssRsrq = 0//signal.ssRsrq;
+        pt_info->nr_sig_info.ssSinr = 0//signal.ssSinr;
+        pt_info->nr_sig_info.csiRsrp = 0//signal.csiRsrp;
+        pt_info->nr_sig_info.csiRsrq = 0//signal.csiRsrq;
+        pt_info->nr_sig_info.csiSinr = 0//signal.csiSinr;
+        */
     }
 
     return 0;
@@ -562,7 +889,7 @@
     lynq_func_cb_handle.handlerPtr = handlerPtr;
     lynq_func_cb_handle.contextPtr = contextPtr;
 
-    mbtk_net_state_change_cb_reg(lynq_nw_info_handle, lynq_nw_state_change_cb);
+    mbtk_signal_state_change_cb_reg(lynq_nw_info_handle, lynq_signal_state_change_cb);
 
     return 0;
 }
diff --git a/mbtk/liblynq_lib/src/lynq_sms.c b/mbtk/liblynq_lib/src/lynq_sms.c
index 519d21a..2c56e35 100755
--- a/mbtk/liblynq_lib/src/lynq_sms.c
+++ b/mbtk/liblynq_lib/src/lynq_sms.c
@@ -103,6 +103,8 @@
         return -1;
     }
 
+    mbtk_sms_state_change_cb_reg(sms_info_handle, NULL);
+
     if(sms_info_handle)
     {
         mbtk_info_handle_free(&sms_info_handle);