Index: /branches/rel_apv_10_7_3/usr/click/bin/heartbeat/heartbeat.c
===================================================================
--- /branches/rel_apv_10_7_3/usr/click/bin/heartbeat/heartbeat.c	(revision 40078)
+++ /branches/rel_apv_10_7_3/usr/click/bin/heartbeat/heartbeat.c	(working copy)
@@ -9,6 +9,7 @@
 #include <stdio.h>
 #include <time.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <curl/curl.h>
 #include <sys/stat.h>
 #ifdef UOS_X86
@@ -779,9 +780,14 @@
                         logging("[heartbeat]Current device is enabled successfully and update license.", 1);
                         bandwidth_volume_update(bandwidth_limit);
                         feactl_p->max_vapv_bandwidth = bandwidth_limit * 1000000;
-                        FILE *f = fopen("/ca/etc/bw_cm", "w");
-                        fprintf(f, "%d\n", feactl_p->max_vapv_bandwidth);
-                        fclose(f);
+			char buf[16];
+			int len = snprintf(buf, sizeof(buf), "%d\n", feactl_p->max_vapv_bandwidth);
+			int fd = open("/ca/etc/bw_cm", O_WRONLY | O_CREAT | O_TRUNC, 0644);
+			if (fd != -1) {
+				write(fd, buf, len);
+				close(fd);
+			}
+
                         logging("[heartbeat]Current device update bandwidth", 1);
                         strncpy(heartbeat_info.license_key, license_key, LICENSE_KEY);
                         strncpy(heartbeat_info.cm_serial_number, cm_serial_number, CM_SN);
@@ -795,9 +801,13 @@
                 } else if (heartbeat_info.bandwidth_limit != bandwidth_limit) {
                     bandwidth_volume_update(bandwidth_limit);
                     feactl_p->max_vapv_bandwidth = bandwidth_limit * 1000000;
-                    FILE *f = fopen("/ca/etc/bw_cm", "w");
-                    fprintf(f, "%d\n", feactl_p->max_vapv_bandwidth);
-                    fclose(f);
+		    char buf[16];
+		    int len = snprintf(buf, sizeof(buf), "%d\n", feactl_p->max_vapv_bandwidth);
+		    int fd = open("/ca/etc/bw_cm", O_WRONLY | O_CREAT | O_TRUNC, 0644);
+		    if (fd != -1) {
+			    write(fd, buf, len);
+			    close(fd);
+		    }
                     logging("[heartbeat]Just update bandwidth successfully.", 1);
                     heartbeat_info.bandwidth_limit = bandwidth_limit;
                     heartbeat_info.heartbeat_time = t;
@@ -809,9 +819,13 @@
                     heartbeat_info.bandwidth_limit = 1;
                     bandwidth_volume_update(1);
                     feactl_p->max_vapv_bandwidth = 1 * 1000000;
-                    FILE *f = fopen("/ca/etc/bw_cm", "w");
-                    fprintf(f, "%d\n", feactl_p->max_vapv_bandwidth);
-                    fclose(f);
+		    char buf[16];
+		    int len = snprintf(buf, sizeof(buf), "%d\n", feactl_p->max_vapv_bandwidth);
+		    int fd = open("/ca/etc/bw_cm", O_WRONLY | O_CREAT | O_TRUNC, 0644);
+		    if (fd != -1) {
+			    write(fd, buf, len);
+			    close(fd);
+		    }
                     memset(heartbeat_info.cm_serial_number, 0, sizeof(heartbeat_info.cm_serial_number));
                     memset(heartbeat_info.license_key, 0, sizeof(heartbeat_info.license_key));
                     heartbeat_info.heartbeat_time = t;
@@ -868,7 +882,7 @@
 	    }
 	} else {
 	    logging("[heartbeat]http status != 200. licensepermit enabled!", 1);
-	    heartbeat_info.device_manage_status = UNREGISTERED;
+	    write_heartbeat_info(CM_INFO, &heartbeat_info);
 	}
     }
 end:
Index: /branches/rel_apv_10_7_3/usr/click/bin/vtch/vtch-guest.c
===================================================================
--- /branches/rel_apv_10_7_3/usr/click/bin/vtch/vtch-guest.c	(revision 40078)
+++ /branches/rel_apv_10_7_3/usr/click/bin/vtch/vtch-guest.c	(working copy)
@@ -357,11 +357,11 @@
 				fclose(f);
 			    }
 			}
-			syslog(LOG_USER | LOG_INFO, "Stop setting license as invalid.\n");
+			syslog(LOG_USER | LOG_INFO, "Activation server enabled. Stop setting license as invalid.\n");
 			break;
 		    }
 		} else	{
-		    syslog(LOG_USER | LOG_INFO, "activation server failed");
+		    syslog(LOG_USER | LOG_INFO, "activation server not enabled");
 		}
 		null_kernel_license_features();
 		syslog(LOG_EMERG, "guest_handle_msg call set_license_invalid...");
Index: /branches/rel_apv_10_7_3/usr/click/lib/libfeactl/feactl.c
===================================================================
--- /branches/rel_apv_10_7_3/usr/click/lib/libfeactl/feactl.c	(revision 40078)
+++ /branches/rel_apv_10_7_3/usr/click/lib/libfeactl/feactl.c	(working copy)
@@ -3169,6 +3169,31 @@
 		vapv_bandwidth_multiplier = 0;
 	}
 	feactl_p->max_vapv_bandwidth *= vapv_bandwidth_multiplier;
+	if (access("/var/crash/cm_address", F_OK) == 0) {
+		int is_licensepermit_enable;
+		size_t len = sizeof(is_licensepermit_enable);
+		if (sysctlbyname("net.inet.clicktcp.licensepermit_enable", &is_licensepermit_enable,
+					&len, NULL, 0)) {
+			syslog(LOG_EMERG, "error retrieving license information");
+		}
+		if (is_licensepermit_enable) {
+			syslog(LOG_EMERG, "licensepermit is enabled.\n");
+			if (access("/ca/etc/bw_cm", F_OK) == 0) {
+				syslog(LOG_EMERG, "set_license_limits : read bandwidth from file\n");
+				FILE *f = fopen("/ca/etc/bw_cm", "r");
+				if (f) {
+					fscanf(f, "%d", &(feactl_p->max_vapv_bandwidth));
+					syslog(LOG_EMERG, "set_license_limits : setting bandwidth to : %d\n", feactl_p->max_vapv_bandwidth);
+					fclose(f);
+				}
+			}
+		} else {
+			syslog(LOG_EMERG, "set_license_limits : licensepermit not enabled. setting bandwidth to : %d\n", feactl_p->max_vapv_bandwidth);
+		}
+	} else  {
+		syslog(LOG_USER | LOG_INFO, "activation server not enabled");
+	}
+
 	bandwidth_volume_update(feactl_p->max_vapv_bandwidth / 1000000);
 
 	return;
Index: /branches/rel_apv_10_7_3/usr/click/lib/libwebui/webui.c
===================================================================
--- /branches/rel_apv_10_7_3/usr/click/lib/libwebui/webui.c	(revision 40078)
+++ /branches/rel_apv_10_7_3/usr/click/lib/libwebui/webui.c	(working copy)
@@ -3507,20 +3507,34 @@
     return 0;
 }
 
+int restart_flag = 0;
 ca_errcode_t clear_activation_server(void)
 {
-	int model_id = 0;
-	model_id = get_manufacture_model_id();
-	if (model_id == AFM_MODEL_vAPV) {
-		return delete_activation_server();
-	}
+        int model_id = 0;
+        model_id = get_manufacture_model_id();
+        if (model_id == AFM_MODEL_vAPV) {
+                int is_licensepermit_enable;
+                size_t len = sizeof(is_licensepermit_enable);
+                if (sysctlbyname("net.inet.clicktcp.licensepermit_enable", &is_licensepermit_enable,
+                                        &len, NULL, 0)) {
+                        fastlog_syslog(LOG_EMERG, "error retrieving license information");
+                }
+                if (is_licensepermit_enable) {
+                        fastlog_syslog(LOG_EMERG, "licensepermit is enabled.\n");
+                        restart_flag = 1;
 
-	return 0;
+                }
+                return delete_activation_server();
+        }
+
+        return 0;
 }
 
 ca_errcode_t delete_activation_server(void)
 {
 	int model_id = 0;
+	int flag = restart_flag;
+	restart_flag = 0;
 	model_id = get_manufacture_model_id();
 	if (model_id != AFM_MODEL_vAPV) {
 		printf("The operation is only supported on "ARRAY_PRODINFO_vAPV"!\n");
@@ -3545,9 +3559,14 @@
     	}
     	detach_feactlp(feactl_p);
     }
-	unlink("/var/crash/cm_address");
-	unlink("/ca/conf/cm_info.confg");
-	stop_in_sysmon("/ca/bin/heartbeat");
+    if (flag) {
+            printf("licensepermit is enabled. Don't remove CM files while restart\n");
+
+    } else {
+            unlink("/var/crash/cm_address");
+            unlink("/ca/conf/cm_info.confg");
+            stop_in_sysmon("/ca/bin/heartbeat");
+    }
 	return 0;
 }
 
