Index: /branches/amp_3_7/extensions/license_server/license_server/encode_license.c
===================================================================
--- /branches/amp_3_7/extensions/license_server/license_server/encode_license.c	(revision 2455)
+++ /branches/amp_3_7/extensions/license_server/license_server/encode_license.c	(working copy)
@@ -1445,6 +1445,23 @@
     *(features_list + cur_len) = feature_tmp;
 }
 
+int print_usage() {
+    printf("Usage:  ./enckey <serial_number> <memory_limit> <cpu_limit> <bandwidth_limit> <date> <license-key-length> <number-of-vAPV> <memory-type> <memory-number> <optional-field-key: feature-name> <optional-field-value: 0 / 1>");
+    printf("\nNote: \n\t1. The Serial Number can be either 16-digit or 30-digit which is available from CLI command 'show version' output.\n\t2. The Serial Number (52-digit) should be replaced with Array Key if the Array Key is given from CLI command 'show version' output.");
+    printf("\n\nmemory_limit : 0 for No limit.");
+    printf("\ncpu_limit : 0 for No limit.");
+    printf("\nbandwidth_limit (unit: Mbps): number (Example: 1024).");
+    printf("\ndate format: yyyymmdd. 99999999 for non-evaluation license");
+    printf("\nlicense-key-length: 72 or 81");
+    printf("\nmemory-type: allowed values are: 2 / 4 / 6 / 8 / 16. To use default - 0");
+    printf("\nmemory-number: To use default - 0");
+    printf("\nDefault vAPV features: WebWall  Clustering  L4SLB  L7SLB  Caching  SSL  tProxy  SwCompression  LLB  QoS  MultiLang  DynRoute  IPv6  SWMaintenance");
+    printf("\nAvailable vAPV features: WebWall  Clustering  L4SLB  L7SLB  Caching  SSL  tProxy  SwCompression  LLB  QoS  MultiLang  DynRoute  IPv6  SWMaintenance HwCompression GSLB CCB REDUNDANT VolumeLicensing WAF DataCollection SSLInterception");
+    printf("\nTo override the feature (1 - enable, 0 - disable)s: <feature-name> <0/1> (Example: GSLB 1 SSL 0)");
+    printf("\n\n");
+    return 0;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -1710,6 +1727,223 @@
                     "date elements" );
             }
         }
+    } else {
+        /**
+         * Command line mode
+         * serial_number    -> argv[1]
+         * memory_limit     -> argv[2]
+         * cpu_limit        -> argv[3]
+         * bandwidth_limit  -> argv[4]
+         * date             -> argv[5]
+         * lic_len          -> argv[6]
+         * va_capacity      -> argv[7]
+         * memory_type      -> argv[8]
+         * memory_number    -> argv[9]
+         * optional-feature-name -> argv[10]
+         * optional-feature-enable -> argv[11]
+         * ...
+         */
+
+        if(argc == 2 || argc < 10 || strcmp(argv[1], "--help")==0){
+            return print_usage();
+        }
+
+        char default_features[14][15];
+        strcpy(default_features[0], "WebWall");
+        strcpy(default_features[1], "Clustering");
+        strcpy(default_features[2], "L4SLB");
+        strcpy(default_features[3], "L7SLB");
+        strcpy(default_features[4], "Caching");
+        strcpy(default_features[5], "SSL");
+        strcpy(default_features[6], "tProxy");
+        strcpy(default_features[7], "SwCompression");
+        strcpy(default_features[8], "LLB");
+        strcpy(default_features[9], "QoS");
+        strcpy(default_features[10], "MultiLang");
+        strcpy(default_features[11], "DynRoute");
+        strcpy(default_features[12], "IPv6");
+        strcpy(default_features[13], "SWMaintenance");
+
+        bandwidth_unit = 0; //Mbps
+
+        serial = argv[1];
+        memory_limit = atoi(argv[2]);
+        cpu_limit = atoi(argv[3]);
+        bandwidth_limit = atoi(argv[4]);
+        model = "AMP 3.0";
+        date = argv[5]; // yyyymmdd
+
+        lic_len = atoi(argv[6]);
+        if (lic_len != 72 && lic_len != 81) {
+            printf("\nInvalid license ket length found. Allowed are 72 and 81\n\n");
+            return print_usage();
+        }
+
+        va_capacity = atoi(argv[7]);
+        AFM_SET_FEACTL_VA_CAP(features, va_capacity);
+
+        int mem_type = atoi(argv[8]);
+        if (mem_type != 0 && mem_type != 2 && mem_type != 4 && mem_type != 6 && mem_type != 8 && mem_type != 16) {
+            printf("\nInvalid memory type (G) found. Allowed are 2, 4, 6, 8 and 16. To use default: 0\n\n");
+            return print_usage();
+        }
+        int mem_num = atoi(argv[9]);
+        
+        // coname = argv[];
+        
+        if (memory_limit == 0) {
+            memory_nolimit_flag = 1;
+        }
+        if (cpu_limit == 0) {
+            cpu_nolimit_flag = 1;
+        }
+
+        int i, j;
+        
+        char selected_features[25][15];
+        int override_features_count;
+
+        if (argc % 2 != 0) {
+            printf("\nInvalid features usage: <feature-name> <1/0 to enable/disable>\n");
+            return print_usage();
+        }
+
+        int is_default_override = 0;
+        if (argc > 10) {
+            for (i=10; i < argc; i++) {
+                is_default_override = 0;
+                for (j=0; j<14; j++) {
+                    if (strcmp(argv[i], default_features[j]) == 0) {
+                        is_default_override = 1;
+                        if (atoi(argv[i+1]) == 0) {
+                            strcpy(default_features[j], "InvalidX");
+                        }
+                    }
+                }
+                for (j = 0; j < MAX_APV_FEATURE; j++) {
+                    // override default.
+                    if (strcmp(argv[i], array_features[j].name) == 0 && atoi(argv[i+1]) == 1 && is_default_override == 0) {
+                        features |= array_features[j].hex;
+                    }
+                }
+                i++;
+            }
+        } 
+
+        for (i = 0; i < 14; i++) {
+            for (j = 0; j < MAX_APV_FEATURE; j++) {
+                if (strcmp(default_features[i], array_features[j].name) == 0) {
+                    features |= array_features[j].hex;
+                }
+            }
+        }
+        
+        printf("\n\n\t\t\t*** Array AMP volume license generator for AMP ***\n");
+
+        printf("\nAMP serial number: %s", serial);
+        printf("\nMemory limit: %d", memory_limit);
+        printf("\nCPU limit: %d", cpu_limit);
+        printf("\nBandwidth limit: %d Mbps", bandwidth_limit);
+        printf("\nModel: %s", model);
+        printf("\nDate: %s", date);
+        printf("\nLicense key length: %d", lic_len);
+        printf("\nNumber of Licensed vAPVs: %d", va_capacity);
+        printf("\nMemory Type: %d", mem_type);
+        printf("\nMemory Number: %d", mem_num);
+
+        if (mem_type > 0) {
+            if (mem_num > 512) {
+                extend_bit_flag = 1;
+                type_id_len = 10;
+            }
+            construct_features_block(features_list, extend_bit_flag, type_id_len, mem_num, 1, 1, -1);
+        }
+
+        if (memory_nolimit_flag != 0) {
+            if (memory_limit >= 512) {
+                extend_bit_flag = 1;
+                type_id_len = 10;
+            }
+            construct_features_block(features_list, extend_bit_flag, type_id_len, memory_limit, 1, feature_or_device, -1);
+        }
+
+        if (cpu_nolimit_flag != 0) {
+            if (cpu_limit >= 512) {
+                extend_bit_flag = 1;
+                type_id_len = 10;
+            }
+            construct_features_block(features_list, extend_bit_flag, type_id_len, cpu_limit, 2, feature_or_device, -1);
+        }
+
+        if (bandwidth_limit >= 218) {
+            extend_bit_flag = 1;
+            type_id_len = 10;
+        }
+        construct_features_block(features_list, extend_bit_flag, type_id_len, bandwidth_limit, 3, feature_or_device, bandwidth_unit);
+        
+        int fea_len = count_64array(features_list, FEATURES_NUM);
+        if (fea_len > 0) {
+            features32_list[0] = get_low_32(features_list[0]);
+            if ((features32_list[0] & TEST_FIRST_FEATURE) == 0) {
+                concat_flag = 1;
+            }
+
+            for (int k = 1; k < fea_len; ++k) {
+                int fea32_len = count_32array(features32_list, FEATURES_NUM);
+                if ((get_low_32(features_list[k]) & TEST_FIRST_FEATURE) == 0) {
+                    if (concat_flag == 1) {
+                        features32_list[fea32_len - 1] |= (get_low_32(features_list[k]) << 16);
+                        concat_flag = 0;
+                    } else {
+                        features32_list[fea32_len] = get_low_32(features_list[k]);
+                        concat_flag = 1;
+                    }
+                } else {
+                    if (concat_flag == 1) {
+                        features32_list[fea32_len -1 ] |= ((get_low_32(features_list[k]) & 0x0000FFFF) << 16);
+                        features32_list[fea32_len] = (get_low_32(features_list[k]) >> 16);
+                        concat_flag = 1;
+                    } else {
+                        features32_list[fea32_len] = get_low_32(features_list[k]);
+                        concat_flag = 0;
+                    }
+                }
+            }
+        }
+
+        int fea32_len = count_32array(features32_list, FEATURES_NUM);
+
+        lefttrim(serial);
+        righttrim(serial);
+        lefttrim(date);
+        righttrim(date);
+
+        len = strlen( serial );
+        if( ((len == SERNUMLEN-1) || (len == MACLEN-1) || (len == ARRAYKEYLEN-1)) && model && date ) {
+            if (checkinput(date, &features, model, &model_idx, 0) < 0) {
+                printf("\nUnable to compute license: %s\n", g_ci_error_msg);
+                return 0;
+            }
+
+            lic = avx_encode( serial, features, date, coname, model_idx, 0 , lic_len, fea32_len, features32_list);
+            
+            if( lic ) {
+                char fea_msg[1024];
+                printf("\n\nLicense key: %s", lic);
+                show_feature_cgi(features, fea_msg, sizeof(fea_msg));
+                lefttrim(fea_msg);
+                righttrim(fea_msg);
+                printf("\nLicensed Features: %s\n", fea_msg);
+            } else {
+                printf("\nUnable to compue license, try again\n");
+            }
+        } else {
+            if( (len != SERNUMLEN-1) && (len != MACLEN-1) && (len != ARRAYKEYLEN-1) ) {
+                printf("\nPlease check the serial number!!\n");
+            } else {
+                printf("\nPlease check the model or date elements\n");
+            }
+        }
     }
 
     return 0;
