summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarie Rannou2009-09-16 10:11:58 +0200
committerMarie Rannou2009-09-16 10:11:58 +0200
commita51d7c01daed73002fb26166ba50f961901658c9 (patch)
tree1f7ff6d6a776ff1feea0fc5a1b87bc0fa73f495e
parent8754f8c6e35fc1e20412c2fe6f3aec6140301f31 (diff)
[spidlib-busybox] Add a master_config function which gathers all config wanted for master (qos, vlan, RFlevel,..) and which is accessible by a busybox function.This one is called on a rcS.d script at each start.
-rw-r--r--application/busybox/include/applets.h1
-rw-r--r--application/busybox/include/usage.h5
-rw-r--r--application/busybox/util-linux/Config.in9
-rw-r--r--application/busybox/util-linux/Kbuild1
-rw-r--r--application/busybox/util-linux/master_config.c18
-rw-r--r--application/busybox/util-linux/qos.c3
-rw-r--r--application/plcbox/plcbox.c2
-rw-r--r--application/spidlib/Makefile2
-rw-r--r--application/spidlib/inc/config_keys.h1
-rw-r--r--application/spidlib/src/network/master_config.c259
-rw-r--r--package/busybox/spc2xx_defconfig1
-rw-r--r--package/initramfs/root/factory/rcS.d/20masterinit8
-rw-r--r--package/initramfs/root/factory/system.conf3
13 files changed, 309 insertions, 4 deletions
diff --git a/application/busybox/include/applets.h b/application/busybox/include/applets.h
index 81e10bf1cd..7fcbcdd51d 100644
--- a/application/busybox/include/applets.h
+++ b/application/busybox/include/applets.h
@@ -408,6 +408,7 @@ USE_WHITELIST(APPLET(whitelist, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_TRAFFIC_LIMIT(APPLET(traffic_limit, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_VLAN(APPLET(vlan, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_QOS(APPLET(qos, _BB_DIR_BIN, _BB_SUID_NEVER))
+USE_MASTER_CONFIG(APPLET(master_config, _BB_DIR_BIN, _BB_SUID_NEVER))
#if !defined(PROTOTYPES) && !defined(NAME_MAIN_CNAME) && !defined(MAKE_USAGE)
};
#endif
diff --git a/application/busybox/include/usage.h b/application/busybox/include/usage.h
index e3cf216b69..8a9ef50236 100644
--- a/application/busybox/include/usage.h
+++ b/application/busybox/include/usage.h
@@ -4512,4 +4512,9 @@
"No argument"
#define qos_full_usage \
"No argument"
+
+#define master_config_trivial_usage \
+ "No argument"
+#define master_config_full_usage \
+ "No argument"
#endif /* __BB_USAGE_H__ */
diff --git a/application/busybox/util-linux/Config.in b/application/busybox/util-linux/Config.in
index b62dfe61c1..7a7a2fb291 100644
--- a/application/busybox/util-linux/Config.in
+++ b/application/busybox/util-linux/Config.in
@@ -851,8 +851,15 @@ config VLAN
Vlan application
config QOS
- bool "QoS
+ bool "QoS"
default n
help
QoS action
+
+config MASTER_CONFIG
+ bool "master_config"
+ default n
+ help
+ Master configuration
+
endmenu
diff --git a/application/busybox/util-linux/Kbuild b/application/busybox/util-linux/Kbuild
index 16331f0277..05012018d0 100644
--- a/application/busybox/util-linux/Kbuild
+++ b/application/busybox/util-linux/Kbuild
@@ -41,5 +41,6 @@ lib-$(CONFIG_WHITELIST) +=whitelist.o
lib-$(CONFIG_TRAFFIC_LIMIT) +=traffic_limit.o
lib-$(CONFIG_VLAN) +=vlan.o
lib-$(CONFIG_QOS) +=qos.o
+lib-$(CONFIG_MASTER_CONFIG) +=master_config.o
diff --git a/application/busybox/util-linux/master_config.c b/application/busybox/util-linux/master_config.c
new file mode 100644
index 0000000000..d41b246bd5
--- /dev/null
+++ b/application/busybox/util-linux/master_config.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <net/if.h>
+#include "libbb.h"
+#include "spidlib.h"
+
+int master_config_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int master_config_main(int argc, char **argv)
+{
+
+ if (argc !=2) goto usage;
+ spidlib_master_config();
+ return 0;
+
+usage:
+ printf("Please enter one of the following commands : \n");
+ printf("%s reset\n", argv[0]);
+ return 0;
+} \ No newline at end of file
diff --git a/application/busybox/util-linux/qos.c b/application/busybox/util-linux/qos.c
index b8efb22f90..74dc3c6fca 100644
--- a/application/busybox/util-linux/qos.c
+++ b/application/busybox/util-linux/qos.c
@@ -15,4 +15,5 @@ usage:
printf("Please enter one of the following commands : \n");
printf("%s reset\n", argv[0]);
return 0;
-} \ No newline at end of file
+}
+
diff --git a/application/plcbox/plcbox.c b/application/plcbox/plcbox.c
index 1ea67b3306..00b4201a32 100644
--- a/application/plcbox/plcbox.c
+++ b/application/plcbox/plcbox.c
@@ -21,6 +21,7 @@ extern int whitelist_main(int argc, char **argv);
extern int traffic_limit_main(int argc, char **argv);
extern int vlan_main(int argc, char **argv);
extern int qos_main(int argc, char **argv);
+extern int master_config_main(int argc, char **argv);
static struct pb_applet applet_table[] = {
{ "clean", clean_main },
@@ -31,6 +32,7 @@ static struct pb_applet applet_table[] = {
{ "s1", s1_main },
{ "s2", s2_main },
{ "s4", s4_main },
+ { "master_config", master_config_main },
{ "mib", mib_main },
{ "qos", qos_main },
{ "testraw", testraw_main },
diff --git a/application/spidlib/Makefile b/application/spidlib/Makefile
index 32de585278..15e39b2138 100644
--- a/application/spidlib/Makefile
+++ b/application/spidlib/Makefile
@@ -20,7 +20,7 @@ SERVICE_OBJ = 8021x_supplicant_state.o 8021x_supplicant_identity.o 8021x_supplic
8021x_auth_mode.o 8021x_auth_state.o ftp_state.o http_state.o snmp_state.o serial_state.o \
telnet_state.o snmp_analog_alarm.o snmp_discrete_alarm.o
NETWORK_OBJ = bridge.o ip_addr.o ip_data.o ip_netmask.o ip_mode.o mac.o mode.o route_default.o \
- vlan.o ip_gateway.o traffic_limit.o service.o port.o
+ vlan.o ip_gateway.o traffic_limit.o service.o port.o master_config.o
ETHERNET_OBJ = duplex.o speed.o
WHITELIST_OBJ = get_whitelist_entry.o get_whitelist_list.o set_whitelist_entry.o remove_whitelist_entry.o reset_whitelist.o whitelist_enable.o
SECU_OBJ = md5.o
diff --git a/application/spidlib/inc/config_keys.h b/application/spidlib/inc/config_keys.h
index c9e0fbe12c..8d46e1e88e 100644
--- a/application/spidlib/inc/config_keys.h
+++ b/application/spidlib/inc/config_keys.h
@@ -30,6 +30,7 @@
//#define SPIDLIB_ALL_IP_MASK_KEY "ALL_IP_MASK"
//#define SPIDLIB_ALL_IP_GATEWAY_KEY "ALL_IP_GATEWAY"
#define SPIDLIB_RF_OUTPUT_LEVEL_KEY "RF_OUTPUT_LEVEL"
+#define SPIDLIB_RF_MASTER_OUTPUT_LEVEL_KEY "RF_MASTER_OUTPUT_LEVEL"
#define SPIDLIB_EXT_MAC_LIMITATION_KEY "MAC_LIMITATION"
#define SPIDLIB_WHITELIST_ENABLE_KEY "WHITELIST"
diff --git a/application/spidlib/src/network/master_config.c b/application/spidlib/src/network/master_config.c
new file mode 100644
index 0000000000..c0b844a801
--- /dev/null
+++ b/application/spidlib/src/network/master_config.c
@@ -0,0 +1,259 @@
+/*-----------------------------------------------------------------------------
+ File: master_config.c
+ Description: Function to configure master with qos prio, vla, RFOutput, ...
+ Project: SPiDLIB
+ Target: SPiDCOM modem w/ SPC200e
+ Version: 0.1
+ Revision list: -
+ Company: SPiDCOM
+ Author: Marie Rannou
+ Date: Sept 2009
+-----------------------------------------------------------------------------*/
+
+/*---------------------- Include files --------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "spidlib.h"
+#include <syslog.h>
+
+#define DEFAULT_BCAST_LIMIT 100
+#define BURST_RATIO 10
+
+
+/*-----------------------------------------------------------------------------
+ Function: set_broadcast_restriction
+input:
+ none
+ Output: -1 if error, else 0;
+-----------------------------------------------------------------------------*/
+int set_broadcast_restriction(void)
+{
+ char value[16];
+ char temp[256];
+ unsigned int broad_limit = DEFAULT_BCAST_LIMIT;
+
+ /* Parse broadcast restriction config file and create a file for the config */
+ if ((spidlib_read_config_param(SPIDLIB_CONFIG_SYSTEM_PATH, SPIDLIB_ADMIN_BROADCAST_LIMIT_EN_KEY, value, sizeof(value)) != 0)
+ || !SPIDLIB_GET_BOOLEAN (value))
+ {
+ return -1;
+ }
+
+ if (spidlib_read_config_param(SPIDLIB_CONFIG_SYSTEM_PATH, SPIDLIB_ADMIN_BROADCAST_LIMIT_KEY, value, sizeof(value)) >= 0)
+ {
+ broad_limit = strtoul(value, NULL, 10);
+ }
+
+ /* If value is null, avoid any broadcast limitations*/
+ if (broad_limit == 0 ) return 0;
+
+ sprintf(temp, "ebtables -t nat -A PREROUTING -i eth0 -d broadcast --limit %d/sec --limit-burst %d -j ACCEPT\nebtables -t nat -A PREROUTING -i eth0 -d broadcast -j DROP\n", broad_limit, broad_limit / BURST_RATIO);
+ system(temp);
+
+ return 0;
+}
+
+/*-----------------------------------------------------------------------------
+ Function: set_unknown_restriction
+input:
+ none
+ Output: -1 if error, else 0;
+-----------------------------------------------------------------------------*/
+int set_unknown_restriction(void)
+{
+ char value[16];
+ char temp[256];
+ unsigned int unknown_limit = DEFAULT_BCAST_LIMIT;
+
+ /* Parse broadcast restriction config file and create a file for the config */
+ if ((spidlib_read_config_param(SPIDLIB_CONFIG_SYSTEM_PATH, SPIDLIB_ADMIN_UNKNOWN_LIMIT_EN_KEY, value, sizeof(value)) != 0)
+ || !SPIDLIB_GET_BOOLEAN (value))
+ {
+ return -1;
+ }
+
+ if (spidlib_read_config_param(SPIDLIB_CONFIG_SYSTEM_PATH, SPIDLIB_ADMIN_UNKNOWN_LIMIT_KEY, value, sizeof(value)) >= 0)
+ {
+ unknown_limit = strtoul(value, NULL, 10);
+ }
+
+ /* If value is null, avoid any limitations for this parameter*/
+ if (unknown_limit == 0 ) return 0;
+
+
+ sprintf(temp, "ebtables -t nat -A PREROUTING -i eth0 --plc-dst unknown --limit %d/sec --limit-burst %d -j ACCEPT\nebtables -t nat -A PREROUTING -i eth0 --plc-dst unknown -j DROP\n", unknown_limit, unknown_limit / BURST_RATIO);
+ system(temp);
+
+ return 0;
+}
+
+/*-----------------------------------------------------------------------------
+ Function: set_RF_output_level
+input:
+ none
+ Output: -1 if error, else 0;
+-----------------------------------------------------------------------------*/
+int set_RF_output_level(void)
+{
+ char get_RF_output_level[16];
+ unsigned int rf_level;
+ int fd_sysctl_conf = -1, fd_exec_slave = -1;
+ char temp[256];
+ spidlib_whitelist_entry_t wl_entry;
+
+ /*Parse system.conf file to get RFMaster_output_level*/
+ if (spidlib_read_config_param(SPIDLIB_CONFIG_SYSTEM_PATH, SPIDLIB_RF_MASTER_OUTPUT_LEVEL_KEY, get_RF_output_level, sizeof(get_RF_output_level)) != 0 )
+ {
+ return -1;
+ }
+
+ sscanf(get_RF_output_level, "%u", &rf_level);
+
+ /* Fill in sysctl.conf file */
+ /* if ((fd_sysctl_conf = open(SPIDLIB_CONFIG_SYSCTL_PATH, O_WRONLY| O_CREAT | O_APPEND, 0777)) < 0)
+ {
+ return -1;
+ }*/ //TODO
+
+ /* Fill in 88slave */
+ /* if ((fd_exec_slave = open(SLAVE_FILE, O_WRONLY| O_CREAT | O_APPEND, 0777)) < 0)
+ {
+ return -1;
+ }*/ //TODO
+
+/*
+
+ if (rf_level == output_level_values[0])
+ {
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", OUTPUT_LEVEL_103_STR_SYSCTL);
+ write(fd_sysctl_conf, temp, strlen(temp));
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", architecture==SPIDLIB_ARCHI_SPC200E?OUTPUT_LEVEL_103_STR_S2_E:OUTPUT_LEVEL_103_STR_S2_C);
+ write(fd_exec_slave, temp, strlen(temp));
+ }
+ else if (rf_level == output_level_values[1])
+ {
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", OUTPUT_LEVEL_105_STR_SYSCTL);
+ write(fd_sysctl_conf, temp, strlen(temp));
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", architecture==SPIDLIB_ARCHI_SPC200E?OUTPUT_LEVEL_105_STR_S2_E:OUTPUT_LEVEL_105_STR_S2_C);
+ write(fd_exec_slave, temp, strlen(temp));
+ }
+ else if (rf_level == output_level_values[2])
+ {
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", OUTPUT_LEVEL_108_STR_SYSCTL);
+ write(fd_sysctl_conf, temp, strlen(temp));
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", architecture==SPIDLIB_ARCHI_SPC200E?OUTPUT_LEVEL_108_STR_S2_E:OUTPUT_LEVEL_108_STR_S2_C);
+ write(fd_exec_slave, temp, strlen(temp));
+ }
+ else if (rf_level == output_level_values[3])
+ {
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", OUTPUT_LEVEL_111_STR_SYSCTL);
+ write(fd_sysctl_conf, temp, strlen(temp));
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", architecture==SPIDLIB_ARCHI_SPC200E?OUTPUT_LEVEL_111_STR_S2_E:OUTPUT_LEVEL_111_STR_S2_C);
+ write(fd_exec_slave, temp, strlen(temp));
+ }
+ else if (rf_level == output_level_values[4])
+ {
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", OUTPUT_LEVEL_114_STR_SYSCTL);
+ write(fd_sysctl_conf, temp, strlen(temp));
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", architecture==SPIDLIB_ARCHI_SPC200E?OUTPUT_LEVEL_114_STR_S2_E:OUTPUT_LEVEL_114_STR_S2_C);
+ write(fd_exec_slave, temp, strlen(temp));
+ }
+ else if (rf_level == output_level_values[5])
+ {
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", OUTPUT_LEVEL_117_STR_SYSCTL);
+ write(fd_sysctl_conf, temp, strlen(temp));
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", architecture==SPIDLIB_ARCHI_SPC200E?OUTPUT_LEVEL_117_STR_S2_E:OUTPUT_LEVEL_117_STR_S2_C);
+ write(fd_exec_slave, temp, strlen(temp));
+ }
+ else if (rf_level == output_level_values[6])
+ {
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", OUTPUT_LEVEL_120_STR_SYSCTL);
+ write(fd_sysctl_conf, temp, strlen(temp));
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", architecture==SPIDLIB_ARCHI_SPC200E?OUTPUT_LEVEL_120_STR_S2_E:OUTPUT_LEVEL_120_STR_S2_C);
+ write(fd_exec_slave, temp, strlen(temp));
+ }
+ else if (rf_level == output_level_values[7])
+ {
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", OUTPUT_LEVEL_123_STR_SYSCTL);
+ write(fd_sysctl_conf, temp, strlen(temp));
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", architecture==SPIDLIB_ARCHI_SPC200E?OUTPUT_LEVEL_123_STR_S2_E:OUTPUT_LEVEL_123_STR_S2_C);
+ write(fd_exec_slave, temp, strlen(temp));
+ }
+ else if (rf_level == output_level_values[8])
+ {
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", OUTPUT_LEVEL_126_STR_SYSCTL);
+ write(fd_sysctl_conf, temp, strlen(temp));
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", architecture==SPIDLIB_ARCHI_SPC200E?OUTPUT_LEVEL_126_STR_S2_E:OUTPUT_LEVEL_126_STR_S2_C);
+ write(fd_exec_slave, temp, strlen(temp));
+ }
+ else if (rf_level == output_level_values[9])
+ {
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", OUTPUT_LEVEL_129_STR_SYSCTL);
+ write(fd_sysctl_conf, temp, strlen(temp));
+ memset(temp, 0, sizeof(temp));
+ sprintf(temp, "%s", architecture==SPIDLIB_ARCHI_SPC200E?OUTPUT_LEVEL_129_STR_S2_E:OUTPUT_LEVEL_129_STR_S2_C);
+ write(fd_exec_slave, temp, strlen(temp));
+ }
+ else
+ {
+ syslog(LOG_DEBUG, "config_creator: invalid output level value: %u %s", rf_level, get_RF_output_level_all);
+ close(fd_sysctl_conf);
+ close(fd_exec_slave);
+ return -1;
+ }
+
+ close(fd_sysctl_conf);
+ close(fd_exec_slave);*///TODO
+
+ return 0;
+}
+
+
+/*-----------------------------------------------------------------------------
+ Function: spidlib_config_master
+input:
+ none
+ Output:
+-----------------------------------------------------------------------------*/
+int spidlib_master_config (void)
+{
+ // Manage Vlans on Master
+ if ( spidlib_vlan_action () !=0 ) return -1;
+
+ // Manage Qos prio on Master
+ if (spidlib_qos_action() !=0) return -1;
+
+ // Build broadcast restriction for Master
+ if (set_broadcast_restriction() !=0) return -1;
+
+ // Build Unknown restrictions for Master
+ if (set_unknown_restriction() !=0) return -1;
+
+ // Define RFOutput Level for Master
+ if (set_RF_output_level() !=0) return -1;
+
+ return 0;
+}
+
diff --git a/package/busybox/spc2xx_defconfig b/package/busybox/spc2xx_defconfig
index 1d61b66121..9b2d842006 100644
--- a/package/busybox/spc2xx_defconfig
+++ b/package/busybox/spc2xx_defconfig
@@ -525,6 +525,7 @@ CONFIG_WHITELIST=y
# CONFIG_TRAFFIC_LIMIT is not set
CONFIG_VLAN=y
CONFIG_QOS=y
+CONFIG_MASTER_CONFIG=y
#
# Miscellaneous Utilities
diff --git a/package/initramfs/root/factory/rcS.d/20masterinit b/package/initramfs/root/factory/rcS.d/20masterinit
new file mode 100644
index 0000000000..4eca4520fe
--- /dev/null
+++ b/package/initramfs/root/factory/rcS.d/20masterinit
@@ -0,0 +1,8 @@
+#! /bin/sh
+# /etc/rcS.d/20masterinit
+#
+
+ # Launch qos on master
+ [ -e /bin/master_config ] && master_config reset
+
+
diff --git a/package/initramfs/root/factory/system.conf b/package/initramfs/root/factory/system.conf
index 429ff789d9..30e96bca31 100644
--- a/package/initramfs/root/factory/system.conf
+++ b/package/initramfs/root/factory/system.conf
@@ -13,6 +13,7 @@ BROADCAST_LIMIT_VALUE = 10
UNKNOWN_LIMIT_ENABLE = no
UNKNOWN_LIMIT_VALUE = 10
MAC_LIMITATION = 0
-OUTPUT_LEVEL = 120
+RF_OUTPUT_LEVEL = 120
+RF_MASTER_OUTPUT_LEVEL = 120
VLAN_ENABLE = no
MASTER_VID = 1