Merge "[Bugfix][T108-GSW][bug-view-1974] if called too early,  mbtk rtp init will fail" into GSW_V1453
diff --git a/build.sh b/build.sh
index 950ef41..735d3ff 100755
--- a/build.sh
+++ b/build.sh
@@ -578,7 +578,7 @@
 	# OPT_SEC=y
 	if [ "$SEC_SUPPORT" == "Y" ];then
 		# build mbtk lib in the first.
-		build_mbtk
+		#build_mbtk
 	        excmd make -j8 V=99 2>&1 | tee build.log
 	#	excmd make OPT_SEC=y -j1 V=99 2>&1 | tee build.log
 	else
diff --git a/config/defconfig_asr1806p301 b/config/defconfig_asr1806p301
index 7d97dde..1b33184 100755
--- a/config/defconfig_asr1806p301
+++ b/config/defconfig_asr1806p301
@@ -5799,7 +5799,7 @@
 # CONFIG_PACKAGE_libtheora is not set
 # CONFIG_PACKAGE_libtiff is not set
 # CONFIG_PACKAGE_libtins is not set
-# CONFIG_PACKAGE_libtirpc is not set
+CONFIG_PACKAGE_libtirpc=y
 # CONFIG_PACKAGE_libtorrent-rasterbar is not set
 # CONFIG_PACKAGE_libtraceevent is not set
 # CONFIG_PACKAGE_libtraceevent-extra is not set
@@ -5842,7 +5842,7 @@
 # CONFIG_PACKAGE_libwebsockets-full is not set
 # CONFIG_PACKAGE_libwebsockets-mbedtls is not set
 # CONFIG_PACKAGE_libwebsockets-openssl is not set
-# CONFIG_PACKAGE_libwrap is not set
+CONFIG_PACKAGE_libwrap=y
 # CONFIG_PACKAGE_libx264 is not set
 # CONFIG_PACKAGE_libxerces-c is not set
 # CONFIG_PACKAGE_libxerces-c-samples is not set
@@ -6991,7 +6991,9 @@
 # CONFIG_PACKAGE_remserial is not set
 # CONFIG_PACKAGE_restic-rest-server is not set
 # CONFIG_PACKAGE_rpcapd is not set
-# CONFIG_PACKAGE_rpcbind is not set
+CONFIG_PACKAGE_rpcbind=y
+CONFIG_RPCBIND_LIBWRAP=y
+CONFIG_RPCBIND_RMTCALLS=y
 # CONFIG_PACKAGE_rssileds is not set
 # CONFIG_PACKAGE_rsyslog is not set
 # CONFIG_PACKAGE_safe-search is not set
diff --git a/external/subpack/net/vsftpd/Makefile b/external/subpack/net/vsftpd/Makefile
old mode 100644
new mode 100755
index 4e75f75..571fb7a
--- a/external/subpack/net/vsftpd/Makefile
+++ b/external/subpack/net/vsftpd/Makefile
@@ -34,6 +34,7 @@
 $(call Package/vsftpd/Default)
   VARIANT:=notls
   TITLE+= (no TLS)
+  DEPENDS+=+libwrap
 endef
 
 define Package/vsftpd-tls
@@ -59,10 +60,12 @@
 endif
 
 TARGET_CFLAGS += -D_GNU_SOURCE -include fcntl.h
+TARGET_LDFLAGS += -lwrap
 
 ifeq ($(BUILD_VARIANT),notls)
  define Build/Compile
 	$(SED) 's/-lcrypt -lnsl/$(NLSSTRING)/' $(PKG_BUILD_DIR)/Makefile
+	$(SED) 's/#undef VSF_BUILD_TCPWRAPPERS/#define VSF_BUILD_TCPWRAPPERS/' $(PKG_BUILD_DIR)/builddefs.h
 	$(MAKE) -C $(PKG_BUILD_DIR) \
 		CC="$(TARGET_CC)" \
 		CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \
diff --git a/external/subpack/net/vsftpd/files/vsftpd.init b/external/subpack/net/vsftpd/files/vsftpd.init
index 0f37da4..b3dee9e 100644
--- a/external/subpack/net/vsftpd/files/vsftpd.init
+++ b/external/subpack/net/vsftpd/files/vsftpd.init
@@ -8,6 +8,8 @@
 
 start_service() {
     mkdir -m 0755 -p /var/run/vsftpd
+    mkdir -m 0755 -p /media/ftp
+
     procd_open_instance
     procd_set_param command "$PROG"
     procd_set_param respawn
diff --git a/marvell/lte-telephony/apps/atcmd_server_ss/src/telcontroller.c b/marvell/lte-telephony/apps/atcmd_server_ss/src/telcontroller.c
index d80dfbc..28f02a0 100755
--- a/marvell/lte-telephony/apps/atcmd_server_ss/src/telcontroller.c
+++ b/marvell/lte-telephony/apps/atcmd_server_ss/src/telcontroller.c
@@ -3771,11 +3771,12 @@
         if(strcmp(line_cut,white_list[i]) == 0)
         {
             ERRMSG(mbtk_check_extension_atcmd, "[%s]count %d,pass atcmd:%s",__FUNCTION__,i,line_cut);
+			free(line_cut);
             return -1;
         }
     }
     needleP =strstr(register_atcmd_buff,line_cut);
-    if(NULL != needleP)
+    if(NULL != needleP && (needleP[strlen(line_cut)] == ';' || needleP[strlen(line_cut)] == '\0'))
     {
         ERRMSG(mbtk_check_extension_atcmd, "[%s] find atcmd:%s",__FUNCTION__,line_cut);
         free(line_cut);
diff --git a/marvell/services/ota/otad.c b/marvell/services/ota/otad.c
index bb0e9f4..0fe7023 100755
--- a/marvell/services/ota/otad.c
+++ b/marvell/services/ota/otad.c
@@ -950,11 +950,12 @@
 										if (rc == -2) {

 											OTA_ERR("%s: abort by download request.\n", __func__);

 										}

-										mbtk_mtd = -1;

-										set_mtd_check_type(mbtk_mtd);

+

 										else

 									#endif

 										OTA_ERR("Fatal error: sync failed...\n");

+									mbtk_mtd = -1;

+									set_mtd_check_type(mbtk_mtd);

 									return rc;

 								}

 							OTA_DEBUG("Sync %s to %s OK...\n", pSrc->name, pDst->name);

diff --git a/mbtk/libgsw_lib/gsw_nw_interface.c b/mbtk/libgsw_lib/gsw_nw_interface.c
index 7be4b24..beb811c 100755
--- a/mbtk/libgsw_lib/gsw_nw_interface.c
+++ b/mbtk/libgsw_lib/gsw_nw_interface.c
@@ -403,6 +403,8 @@
     GSW_PREFER_MODE_NR5G_LTE_WCDMA_GSM    = 32,   /**<  5G/4G/3G/2G*/

 } PREFER_MODE_E;

 

+#define NW_THEAD_NUM (3)

+

 static int mbtk_nw_api_import()

 {

     dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);

@@ -1549,7 +1551,7 @@
     {

         return GSW_HAL_NORMAL_FAIL;

     }

-

+    

     void* cb_func;

     if(handle_ptr == NULL)

     {

@@ -1599,6 +1601,70 @@
     return GSW_HAL_SUCCESS;

 }

 

+static void gsw_un_reg_all()

+{

+    gsw_reg_serving_info_callback(NULL);

+    gsw_reg_sig_info_callback(NULL);

+    gsw_reg_operating_mode_callback(NULL);

+    gsw_reg_set_modem_status_event_callback(NULL);

+    gsw_reg_rej_cause_callback(NULL);

+}

+

+pthread_t s_tid[NW_THEAD_NUM] = {-1,-1,-1};

+void* s_thread_func[NW_THEAD_NUM]={

+         (void*)gsw_sig_info_timer,

+         (void*)gsw_modem_state_timer,

+         (void*)gsw_serving_info_timer

+         };

+

+static void gsw_close_all_thread()

+{

+    int i,ret;

+

+    

+    nw_init_flag=0;

+

+/*  had better not use thread cancel, maybe handle->send_mutex is locked now, cancel will not release this mutex

+    for(i=0; i<NW_THEAD_NUM; i++)

+    {

+        if(s_tid[i]!=-1)

+        {

+            ret = pthread_cancel(s_tid[i]);

+            LOGE(GSW_NW,"pthread %d cancel, ret is %d",i, ret); 

+        }

+    }

+*/

+

+    for(i=0;i<NW_THEAD_NUM;i++)

+    {

+        if(s_tid[i]!=-1)

+        {

+            ret = pthread_join(s_tid[i],NULL);

+            LOGE(GSW_NW,"pthread %d join, ret is %d",i, ret); 

+            s_tid[i]=-1;

+        }

+    }

+}

+

+static int gsw_start_all_thread()

+{ 

+    int i,ret;

+    for(i=0; i<NW_THEAD_NUM;i++)

+    {

+        ret = pthread_create(&(s_tid[i]), NULL,s_thread_func[i], NULL);

+        if (ret != 0)

+        {

+            LOGE(GSW_NW,"pthread_create fail %d,ret is %d",i,ret);

+            gsw_close_all_thread();

+            return GSW_HAL_ERROR_GNSS_NO_THRESHOLDS;

+        }

+    }

+    

+    return GSW_HAL_SUCCESS;

+

+}

+

+

 

 /**

  * @brief network sdk init

@@ -1608,18 +1674,15 @@
  */

 int gsw_nw_sdk_init(int token)

 {

-    int ret = -1;

-    pthread_t nw_info_thread;

-

     if (nw_init_flag == 1 && nw_info_handle != NULL)

     {

         return GSW_HAL_SUCCESS;

     }

 

-    ret = mbtk_nw_api_import();

+    int ret = mbtk_nw_api_import();

     if (ret != 0)

     {

-        printf("mbtk_nw_api_import fail\n");

+        printf("mbtk_nw_api_import fail");

         return GSW_HAL_NORMAL_FAIL;

     }

 

@@ -1627,7 +1690,7 @@
 

     if (nw_info_handle == NULL)

     {

-        LOGE(GSW_NW,"mbtk_info_handle_get fail\n");

+        LOGE(GSW_NW,"mbtk_info_handle_get fail");

         return GSW_HAL_NORMAL_FAIL;

     }

 

@@ -1635,39 +1698,23 @@
     ret = mbtk_fplmn_get(nw_info_handle, fplmn);

     if(ret != 0)

     {

-        LOGE(GSW_NW,"mbtk_fplmn_get failed : %d\n",ret);

+        LOGE(GSW_NW,"mbtk_fplmn_get failed, ret is %d",ret);

         return GSW_HAL_NORMAL_FAIL;

     }

     fplmn_max_length = (strlen(fplmn)/6);

-    LOGE(GSW_NW,"fplmn = %s, fplmn_max_length = %d\n",fplmn,fplmn_max_length);

-   

+    LOGE(GSW_NW,"fplmn = %s, fplmn_max_length = %d",fplmn,fplmn_max_length);

 

     nw_init_flag = 1;

+    ret=gsw_start_all_thread();

 

-    ret = pthread_create(&nw_info_thread, NULL, (void*)gsw_sig_info_timer, NULL);

-    if (ret != 0)

+    if(ret != 0) 

     {

-        LOGE(GSW_NW,"pthread_create fail 1,ret is %d", ret);

-        nw_init_flag = 0;

-        return GSW_HAL_ERROR_GNSS_NO_THRESHOLDS;

+         nw_init_flag = 0;

+        LOGE(GSW_NW,"gsw_start_all_thread failed , ret is %d",ret);

+        return GSW_HAL_NORMAL_FAIL;

     }

 

-    

-    ret = pthread_create(&nw_info_thread, NULL, (void*)gsw_modem_state_timer, NULL);

-    if (ret != 0)

-    {

-        LOGE(GSW_NW,"pthread_create fail 2,ret is %d", ret);

-        nw_init_flag = 0;

-        return GSW_HAL_ERROR_GNSS_NO_THRESHOLDS;

-    }

-

-    ret = pthread_create(&nw_info_thread, NULL, (void*)gsw_serving_info_timer, NULL);

-    if (ret != 0)

-    {

-        LOGE(GSW_NW,"pthread_create fail 3,ret is %d", ret);

-        nw_init_flag = 0;

-        return GSW_HAL_ERROR_GNSS_NO_THRESHOLDS;

-    }

+    LOGE(GSW_NW,"gsw nw init suc");

 

     return GSW_HAL_SUCCESS;

 }

@@ -1688,16 +1735,20 @@
         return GSW_HAL_NORMAL_FAIL;

     }

 

+    gsw_un_reg_all();// had better un-reg before thread close

+    gsw_close_all_thread();//in it,  nw_init_flag=0  and  cb unreg

+    

     ret = mbtk_info_handle_free(&nw_info_handle);

     if(ret != GSW_HAL_SUCCESS)

     {

-        LOGE(GSW_NW,"mbtk_info_handle_free fail\n");

+        LOGE(GSW_NW,"mbtk_info_handle_free fail");

         return GSW_HAL_NORMAL_FAIL;

     }

 

     dlclose(dlHandle_mbtk);

     nw_info_handle = NULL;

-    nw_init_flag = 0;

+    

+    LOGE(GSW_NW,"gsw_nw_sdk_deinit suc");

 

     return GSW_HAL_SUCCESS;

 

diff --git a/mbtk/mbtk_version b/mbtk/mbtk_version
index c34fd6d..3512ced 100755
--- a/mbtk/mbtk_version
+++ b/mbtk/mbtk_version
@@ -1,3 +1,3 @@
-PATCH_INDEX=5
+PATCH_INDEX=6
 GIT_COMMIT=be5ef44399ae1d36692f7cdc06e31fe98b36a346
 PATCH_DATE=2025-03-05_16:31:55
diff --git a/package/mbtk-rootfs/Makefile b/package/mbtk-rootfs/Makefile
index 530b1fa..4cfc959 100755
--- a/package/mbtk-rootfs/Makefile
+++ b/package/mbtk-rootfs/Makefile
@@ -47,6 +47,7 @@
 
 define Build/Compile
 	@echo "Do nothing."
+	make -C $(TOPDIR)/mbtk/
 endef
 
 define Build/Clean
diff --git a/target/linux/mmp/base-files/etc/group b/target/linux/mmp/base-files/etc/group
index 02a94c6..1d9adcc 100755
--- a/target/linux/mmp/base-files/etc/group
+++ b/target/linux/mmp/base-files/etc/group
@@ -1,2 +1,4 @@
 root:x:0:
 mbtk:x:1000:
+ftp:x:1001:
+nobody:x:65534:
diff --git a/target/linux/mmp/base-files/etc/passwd b/target/linux/mmp/base-files/etc/passwd
index dcfb4a9..c1819eb 100755
--- a/target/linux/mmp/base-files/etc/passwd
+++ b/target/linux/mmp/base-files/etc/passwd
@@ -1,2 +1,4 @@
 root:x:0:0:root:/root:/bin/ash
 mbtk:x:1000:1000:mbtk:/home/mbtk:/bin/ash
+ftp:x:1001:1001:FTP User:/media/ftp:/bin/false
+nobody:x:65534:65534:nobody:/dev/null:/bin/false