summaryrefslogtreecommitdiff
path: root/polux/application/busybox/util-linux/whitelist.c
diff options
context:
space:
mode:
Diffstat (limited to 'polux/application/busybox/util-linux/whitelist.c')
-rw-r--r--polux/application/busybox/util-linux/whitelist.c218
1 files changed, 218 insertions, 0 deletions
diff --git a/polux/application/busybox/util-linux/whitelist.c b/polux/application/busybox/util-linux/whitelist.c
new file mode 100644
index 0000000000..d78498a4f5
--- /dev/null
+++ b/polux/application/busybox/util-linux/whitelist.c
@@ -0,0 +1,218 @@
+#include <stdio.h>
+#include <net/if.h>
+#include "libbb.h"
+
+#include "spidlib.h"
+
+int whitelist_add(int varc, char **vars);
+int whitelist_del(int varc, char **vars);
+int whitelist_enable(int varc, char **vars);
+int whitelist_disable(int varc, char **vars);
+int whitelist_list(int varc, char **vars);
+int whitelist_show(int varc, char **vars);
+int whitelist_reset(int varc, char **vars);
+
+
+int whitelist_add(int varc, char **vars)
+{
+ spidlib_whitelist_list_t whitelist;
+
+ whitelist.mac_address = vars [0];
+ whitelist.enable = vars[1];
+ whitelist.RFOutput_level = vars [2];
+ whitelist.tei = vars [3];
+ whitelist.autoUpgrade_en = vars [4];
+ /*whitelist.startTime = vars [5]; // TODO 3.10.03
+ whitelist.endTime = vars [6]; //TODO 3.10.03*/
+ whitelist.startTime = "0" ; // TODO 3.10.03
+ whitelist.endTime = "0"; //TODO 3.10.03
+
+
+
+ spidlib_set_whitelist_entry ( &whitelist );
+
+ return 0;
+}
+
+int whitelist_del(int varc, char **vars)
+{
+ spidlib_remove_whitelist_entry (vars[0]);
+
+ return 0;
+}
+
+int whitelist_enable(int varc, char **vars)
+{
+ spidlib_whitelist_list_t whitelist;
+ spidlib_whitelist_entry_t entry [1];
+
+ if (spidlib_get_whitelist_entry (vars[0], entry) == 0)
+ {
+ spidlib_convert_WLstruct_entry_to_list(entry, &whitelist);
+ whitelist.mac_address = vars [0];
+ whitelist.enable = "1";
+ spidlib_set_whitelist_entry ( &whitelist );
+ }
+ else
+ {
+ printf (" Cannot disable this mac address status : not in white list. \n ");
+ }
+
+ return 0;
+}
+
+int whitelist_disable(int varc, char **vars)
+{
+ spidlib_whitelist_list_t whitelist;
+ spidlib_whitelist_entry_t entry [1];
+
+ if (spidlib_get_whitelist_entry (vars[0], entry) == 0)
+ {
+ spidlib_convert_WLstruct_entry_to_list(entry, &whitelist);
+ whitelist.mac_address = vars [0];
+ whitelist.enable = "0";
+ spidlib_set_whitelist_entry ( &whitelist );
+ }
+ else
+ {
+ printf (" Cannot disable this mac address status : not in white list. \n ");
+ }
+
+ return 0;
+}
+
+int whitelist_list(int varc, char **vars)
+{
+ spidlib_whitelist_entry_t entry [SPIDLIB_WHITELIST_MAX_NB];
+ int count = SPIDLIB_WHITELIST_MAX_NB;
+ int j;
+
+ printf ( "%17s %6s %12s %18s %14s %5s %18s %9s %7s\n", "Mac_Address", "Enable", "Is_Connected", "Last_seen_Duration", "RFOutput_Level", "Index", "AutoUpgrade_Enable", "startTime", "endTime");
+
+ if (spidlib_get_whitelist_list (entry, &count) == 0 )
+ {
+ for (j=0 ; j < (count) ; j++)
+ {
+ printf ("%02x:%02x:%02x:%02x:%02x:%02x", entry[j].mac_address[0], entry[j].mac_address[1], entry[j].mac_address[2], entry[j].mac_address[3], entry[j].mac_address[4], entry[j].mac_address[5]);
+ printf (" " "%6d", entry[j].enable);
+ printf (" " "%12d",entry[j].is_connected);
+ printf (" " "%18d", entry[j].last_seen_duration);
+ printf (" " "%14d", entry[j].RFOutput_level);
+ printf (" " "%5d", entry[j].tei);
+ printf (" " "%18d", entry[j].autoUpgrade_en);
+ printf (" " "%9d", entry[j].startTime); //TODO 3.10.03
+ printf (" " "%7d", entry[j].endTime); //TODO 3.10.03
+ printf ("\n");
+ }
+ }
+ else
+ {
+ printf (" Cannot display entire whitelist ... \n ");
+ }
+ return 0;
+}
+
+int whitelist_show(int varc, char **vars)
+{
+ spidlib_whitelist_entry_t entry [1];
+
+ printf ( "%17s %6s %12s %18s %14s %5s %18s %9s %7s\n", "Mac_Address", "Enable", "Is_Connected", "Last_seen_Duration", "RFOutput_Level", "Index", "AutoUpgrade_Enable", "startTime", "endTime");
+ if (spidlib_get_whitelist_entry (vars[0], entry) == 0)
+ {
+ printf ("%02x:%02x:%02x:%02x:%02x:%02x", entry->mac_address[0], entry->mac_address[1], entry->mac_address[2], entry->mac_address[3], entry->mac_address[4], entry->mac_address[5]);
+ printf (" " "%6d", entry->enable);
+ printf (" " "%12d",entry->is_connected);
+ printf (" " "%18d", entry->last_seen_duration);
+ printf (" " "%14d", entry->RFOutput_level);
+ printf (" " "%5d", entry->tei);
+ printf (" " "%18d", entry->autoUpgrade_en);
+ printf (" " "%9d", entry->startTime); //TODO 3.10.03
+ printf (" " "%7d", entry->endTime); //TODO 3.10.03
+ printf ("\n");
+
+ }
+ else
+ {
+ printf (" Cannot display this mac address status : not in white list. \n ");
+ }
+
+ return 0;
+}
+
+int whitelist_reset(int varc, char **vars)
+{
+ spidlib_reset_whitelist ();
+ return 0;
+}
+
+
+#define MAX_ARGV 8
+#define MAX_VARS 8
+static struct command_t {
+ char *argv[MAX_ARGV];
+ char *vars[MAX_VARS];
+ int (*fn)(int argc, char **argv);
+ int n_argv;
+ int n_vars;
+};
+
+#define NB_COMMANDS 7
+static struct command_t commands[NB_COMMANDS] = {
+ { { "whitelist", "add", NULL}, { "<xx:xx:xx:xx:xx:xx>", "<enable>", "<RFOutput Level>", "<slave tei>", "<AutoUpgrade_enable>","<startTime>","<endTime>",NULL}, whitelist_add },
+ { { "whitelist", "del", NULL}, {"<xx:xx:xx:xx:xx:xx>", NULL}, whitelist_del },
+ { { "whitelist", "enable", NULL}, {"<xx:xx:xx:xx:xx:xx>", NULL}, whitelist_enable },
+ { { "whitelist", "disable", NULL}, {"<xx:xx:xx:xx:xx:xx>", NULL}, whitelist_disable },
+ { { "whitelist", "show", NULL}, {"<xx:xx:xx:xx:xx:xx>", NULL}, whitelist_show },
+ { { "whitelist", "list", NULL}, {NULL}, whitelist_list },
+ { { "whitelist", "reset", NULL}, {NULL}, whitelist_reset },
+};
+
+
+void whitelist_usage(void) {
+ int n, i;
+ for (n=0;n<NB_COMMANDS;n++) {
+ for (i=0;i<MAX_ARGV && commands[n].argv[i]; i++) {
+ printf("%s ", commands[n].argv[i]);
+ }
+ for (i=0;i<MAX_VARS && commands[n].vars[i]; i++) {
+ printf("%s ", commands[n].vars[i]);
+ }
+ printf("\n");
+ }
+}
+
+int whitelist_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int whitelist_main(int argc, char **argv)
+{
+ int n, i;
+
+ for (n=0;n<NB_COMMANDS;n++) {
+ commands[n].n_argv=0;
+ commands[n].n_vars=0;
+ for (i=0;(i<MAX_ARGV) && (commands[n].argv[i]);i++) {
+ commands[n].n_argv++;
+ }
+ for (i=0;(i<MAX_VARS) && (commands[n].vars[i]);i++) {
+ commands[n].n_vars++;
+ }
+ // change for optional var of whitelist_add (n=0):
+ if (n==0) commands[n].n_vars--;
+ }
+
+ for (n=0;n<NB_COMMANDS;n++) {
+ if (argc>=(commands[n].n_argv + commands[n].n_vars)) {
+ for (i=1;i<MAX_ARGV;) {
+ if (strcmp(argv[i],commands[n].argv[i])!=0)
+ break;
+ if (++i==commands[n].n_argv) {
+ commands[n].fn(argc-i, &argv[i]);
+ return 0;
+ }
+ }
+ }
+ }
+
+ whitelist_usage();
+ return 0;
+}
+