[Bugfix][T800][bug-view-1810] the remoting SIM card can`t register network and data call

Only Configure: No
Affected branch: wom_ecc
Affected module: network,data
Is it affected on IC: only MTK
Self-test: yes
Doc Update: no

Change-Id: I30827b1ecadc2c2be6853c0ebb92ff98faeab7ae
diff --git a/env_rndis.sh b/env_rndis.sh
old mode 100644
new mode 100755
diff --git a/src/lynq/framework/lynq-ril-service/src/data/data_gdbus.cpp b/src/lynq/framework/lynq-ril-service/src/data/data_gdbus.cpp
index 03b43dd..d2a4ffe 100755
--- a/src/lynq/framework/lynq-ril-service/src/data/data_gdbus.cpp
+++ b/src/lynq/framework/lynq-ril-service/src/data/data_gdbus.cpp
@@ -435,12 +435,18 @@
     }
     //reason = const_cast<gchar*>(g_variant_dup_string(result, NULL));
     g_variant_get (result, "(&s)", &reason);
-    RLOGD("modifyApnDB_method_cb reason %s", ((reason == NULL)? "":reason));
-    printf("modify apn db success, return message: %s\n", ((reason == NULL)? "":reason));
-    //printf("modifyApnDB_method_cb reason %s\n", ((reason == NULL)? "":reason));
-    /*lei add for at+lmdapn*/
-    lynq_output_info("+LEAPNMOD:%s\n", ((reason == NULL)? "":reason));
-    /*lei add for at+lmdapn*/
+    RLOGD("modifyApnDB_method_cb reason %s,apn_mask_flag_g:%d", ((reason == NULL)? "":reason),apn_mask_flag_g);
+    printf("modifyApnDB_method_cb reason %s,apn_mask_flag_g:%d\n", ((reason == NULL)? "":reason),apn_mask_flag_g);
+    /**for WOM remoting sim card start 2025/07/08**/
+    if(apn_mask_flag_g == 0)
+    {
+        apn_mask_flag_g = 1;
+    }
+    else
+    {
+        lynq_output_info("+LEAPNMOD:%s\n", ((reason == NULL)? "":reason));
+    }
+    /**for WOM remoting sim card end 2025/07/08**/
     g_variant_unref(result);
     lynq_data_modify_apn(reason,LYNQ_URC_MODIFY_APNDB);
 }
diff --git a/src/lynq/framework/lynq-ril-service/src/lynq_common.cpp b/src/lynq/framework/lynq-ril-service/src/lynq_common.cpp
index 5b4ffb6..fba1a59 100755
--- a/src/lynq/framework/lynq-ril-service/src/lynq_common.cpp
+++ b/src/lynq/framework/lynq-ril-service/src/lynq_common.cpp
@@ -29,13 +29,12 @@
 };
 #undef LOG_TAG
 #define LOG_TAG "LYNQ_COMMON"
-
 extern apn_table_t apn_table[LYNQ_APN_CHANNEL_MAX] = {};
 extern int apn_count = 0;
 extern char lynq_at[LYNQ_AT_LEN_MAX]= {};
 pthread_cond_t lynq_at_cond = PTHREAD_COND_INITIALIZER;
 pthread_mutex_t lynq_at_mutex= PTHREAD_MUTEX_INITIALIZER;
-
+int apn_mask_flag_g = 1;
 
 //int lynqSendToRil(int argc,char *argv[],int uToken);
 usb_at_transfer_t *lynqFindId(char *cmd)
@@ -517,6 +516,27 @@
     return 0;
 }
 
+int get_mcc_mnc(char mcc[4],char mnc[4])
+{
+    int slot = 0;
+    int len = 0;
+    char config[64] = { 0 };
+    char mccmnc_value[64] = { 0 };
+    slot = get_default_sim_all();
+    snprintf(config,sizeof(config),"vendor.ril.data.gsm_mcc_mnc%d",slot);
+    utils::mtk_property_get(config,mccmnc_value,"0");
+    len = strlen(mccmnc_value);
+    printf("***get_mcc_mnc len:%d,value:%s***\n",len,mccmnc_value);
+    RLOGD("***get_mcc_mnc len:%d,value:%s***\n",len,mccmnc_value);
+    if((len == 5) || (len == 6)) //mcc+mnc=5/6
+    {
+        strncpy(mcc,mccmnc_value,3);
+        strncpy(mnc,mccmnc_value+3,3);
+        return 0;
+    }
+    return 1;
+}
+
 int insert_apn_char(char *agc, char *id,char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier)
 {
     char strtmp[10][64];
@@ -611,7 +631,15 @@
         argv[10];//password  argv[11] normalprotocol argv[12] roamingprotocol
     */
     int operate = 0;
-    int ret = -1;
+    int ret_mcc = -1;
+    int ret_mnc = -1;
+    int id_original_value = 0;
+    int id_new_value;
+    char mcc[4] = { 0 };
+    char mnc[4] = { 0 };
+    char *new_argv[10] = {};
+    char apn_info[512] = { 0 };
+    char temp[8] = { 0 };
     if(argc < 3)
     {
         RLOGD("parameter error!!!");
@@ -622,23 +650,44 @@
         syncRespToUsb(100);
         return -1;
     }
-    char *new_argv[10] = {};
-    char apn_info[512];
+    apn_mask_flag_g = 1;
+    if(NULL != argv[4])
+    {
+        id_original_value = atoi(argv[4]);
+        id_new_value = id_original_value - LYNQ_APN_URC_MASK;
+    }
     operate = atoi(argv[3]);
     new_argv[0] = (char *)rilReq;
     if(operate == 0)//insert apn db
     {
         for(int i = 4; i < 14; i++)
         {
-            printf("argv[%d] %s\n", i,argv[i]);
             if(argv[i] == NULL)
             {
+                RLOGE("argv[%d] is NULL\n", i);
+                printf("argv[%d] is NULL\n", i);
                 syncRespToUsb(100);
                 return -1;
             }
         }
-        insert_apn_char(apn_info, argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]);
         new_argv[1] = "0";
+        /**for WOM remoting sim card start 2025/07/08**/
+        if(0 == get_mcc_mnc(mcc,mnc))
+        {
+            ret_mcc = strncmp(argv[5],mcc,3);
+            ret_mnc = strncmp(argv[6],mnc,3);
+            if((ret_mcc != 0) || (ret_mnc != 0))
+            {
+                snprintf(temp,sizeof(temp),"%d",id_new_value);
+                insert_apn_char(apn_info,temp, mcc, mnc, argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]);
+                new_argv[2] = apn_info;
+                apn_mask_flag_g = 0;
+                android::lynqSendToRil(3,new_argv,uToken);
+                usleep(500*1000);
+            }
+        }
+	/**for WOM remoting sim card end 2025/07/08**/
+        insert_apn_char(apn_info, argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]);
         new_argv[2] = apn_info;
         android::lynqSendToRil(3,new_argv,uToken);
         usleep(100*1000);
@@ -651,11 +700,19 @@
             syncRespToUsb(100);
             return -1;
         }
-        sprintf(apn_info, "id=%s", argv[4]);
         new_argv[1] = "1";
+        sprintf(apn_info, "id=%s", argv[4]);
         new_argv[2] = apn_info;
         android::lynqSendToRil(3,new_argv,uToken);
+        usleep(500*1000);
+        /**for WOM remoting sim card start 2025/07/08**/
+        memset(apn_info,0,sizeof(apn_info));
+        sprintf(apn_info, "id=%d", id_new_value);
+        new_argv[2] = apn_info;
+        apn_mask_flag_g = 0;
+        android::lynqSendToRil(3,new_argv,uToken);
         usleep(100*1000);
+        /**for WOM remoting sim card end 2025/07/08**/
         syncRespToUsb(0);
     }
     else if(operate == 2)//query apn db
@@ -676,16 +733,33 @@
     {
         for(int i = 4; i < 14; i++)
         {
-            printf("argv[%d] %s\n", i,argv[i]);
             if(argv[i] == NULL)
             {
+                RLOGE("argv[%d] is NULL\n", i);
+                printf("argv[%d] is NULL\n", i);
                 syncRespToUsb(100);
                 return -1;
             }
         }
+        new_argv[1] = "3";
+        /**for WOM remoting sim card start 2025/07/08**/
+	if(0 == get_mcc_mnc(mcc,mnc))
+        {
+            ret_mcc = strncmp(argv[5],mcc,3);
+            ret_mnc = strncmp(argv[6],mnc,3);
+            if((ret_mcc != 0) || (ret_mnc != 0))
+            {
+                snprintf(temp,sizeof(temp),"%d",id_new_value);
+                insert_apn_char(apn_info,temp, mcc, mnc, argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]);
+                new_argv[2] = apn_info;
+                apn_mask_flag_g = 0;
+                android::lynqSendToRil(3,new_argv,uToken);
+                usleep(500*1000);
+            }
+        }
+        /**for WOM remoting sim card end 2025/07/08**/
         insert_apn_char(apn_info, argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]);
         //sprintf(new_argv[1], "%d", operate);
-        new_argv[1] = "3";
         new_argv[2] = apn_info;
         android::lynqSendToRil(3,new_argv,uToken);
         usleep(100*1000);
diff --git a/src/lynq/framework/lynq-ril-service/src/lynq_common.h b/src/lynq/framework/lynq-ril-service/src/lynq_common.h
index 483986a..acf26b8 100755
--- a/src/lynq/framework/lynq-ril-service/src/lynq_common.h
+++ b/src/lynq/framework/lynq-ril-service/src/lynq_common.h
@@ -68,7 +68,7 @@
 #define LYNQ_REQUEST_APN (LYNQ_VERSION +27)
 #define LYNQ_USER_REQUEST_GNSS (LYNQ_VERSION +100)
 #define LYNQ_USER_REQUEST_OTHRE (LYNQ_VERSION +101)
-
+#define LYNQ_APN_URC_MASK (LYNQ_VERSION +27)
 typedef struct
 {
     int cmdId;
@@ -98,6 +98,7 @@
 extern apn_table_t apn_table[LYNQ_APN_CHANNEL_MAX];
 extern int apn_count;
 extern char lynq_at[LYNQ_AT_LEN_MAX];
+extern int apn_mask_flag_g; //0:mask urc;1:show urc
 usb_at_transfer_t *lynqFindId(char *cmd);
 usb_cmd_t * lynqFindUsbEvent(char *cmd);
 int transferAtToRequest(char *cmd);