summaryrefslogtreecommitdiff
path: root/polux/application/mib/src/mib-interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'polux/application/mib/src/mib-interface.c')
-rwxr-xr-xpolux/application/mib/src/mib-interface.c2426
1 files changed, 2426 insertions, 0 deletions
diff --git a/polux/application/mib/src/mib-interface.c b/polux/application/mib/src/mib-interface.c
new file mode 100755
index 0000000000..bc1d218ac7
--- /dev/null
+++ b/polux/application/mib/src/mib-interface.c
@@ -0,0 +1,2426 @@
+/*
+ ****************************************************************************
+ * PROGRAM MODULE
+ *
+ * $Workfile: mib-interface.c $
+ * $Author: paris $
+ * $Date: 2007/11/16 15:45:16 $
+ *
+ * Copyright (C) 2003 by SPiDCOM Technologies All rights reserved.
+ *
+ ****************************************************************************
+ */
+
+#include "ioctl-interface.h"
+#include "assert.h"
+
+
+#include <stdio.h>
+#include <string.h>
+#include "spidlib.h"
+
+#define GET_ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
+
+
+#ifdef __KERNEL__
+#include "hal.h"
+#endif
+
+#include "mib_lib.h"
+#include "mib-interface.h"
+#include "mib-common.h"
+
+#ifndef __cplusplus
+#define false 0
+#define true 1
+#else
+#endif
+
+#ifndef _DEFAULT_SNMP_NUMBER_HOSTS
+#define _DEFAULT_SNMP_NUMBER_HOSTS 5
+#endif
+
+/* for test purpose */
+#define RET_SUCCESS 0
+
+#include <syslog.h>
+
+/**************************************************************************/
+
+#if 0
+enum plc_modulation modulationFromInt( unsigned int modulation)
+{
+ enum plc_modulation val = PLC_MOD_NONE;
+ switch ( modulation )
+ {
+ case 0:
+ val= PLC_MOD_NONE;
+ break;
+ case 1:
+ val= PLC_MOD_BPSK;
+ break;
+ case 2:
+ val= PLC_MOD_QPSK;
+ break;
+ case 3:
+ val= PLC_MOD_QAM16;
+ break;
+ case 4:
+ val= PLC_MOD_QAM64;
+ break;
+ case 5:
+ val= PLC_MOD_QAM256;
+ break;
+ default:
+ val= PLC_MOD_NONE;
+ }
+ return val;
+}
+#endif
+
+/***********************************************************************
+ * LINUX LINUX LINUX LINUX LINUX LINUX LINUX LINUX LINUX LINUX LINUX *
+ ***********************************************************************/
+#ifdef __LINUX__
+
+#define PLC_MODE_AD_HOC_STR "ad-hoc"
+#define PLC_MODE_SLAVE_STR "slave"
+#define PLC_MODE_MASTER_STR "master"
+
+typedef struct
+{
+ uint8_t mac[6];
+ char ip[20];
+ char mask[20];
+ char gw[20];
+} iface_t;
+
+static iface_t eth_iface;
+static iface_t plc_iface;
+static iface_t br_iface;
+
+static int saved_mode;
+static int current_mode;
+
+//boolean
+static bool bssid_changed = true;
+
+static int analyser_level = 0;
+
+#define INTERFACES_FILE "/usr/local/etc/network/interfaces"
+#define NETWORK_CONFIG_FILE "/usr/local/etc/config/network"
+//#define ETHERNET_SETTINGS_FILE "usr/local/etc/network/eth_settings"
+
+
+//initialized with default mode
+static int plc_power_equalization_on=0;
+static int plc_segmentation_and_reassembly_on=0;
+static int plc_spy_on=0;
+
+
+//network config
+static bool network_config_changed = false; //if no change, do not save this file
+static int stp_on = 1;
+static bool bridge_on = true;
+static bool dhcp_on = false;
+
+static eth_config_t eth_mode;
+//static eth_mode_t eth_mode;
+
+//---- FD01: BEGIN SNMP community
+//agent config
+static char pLocal_snmp_GET_community_name [MAX_COMMUNITY_NAME_SIZE];
+static char pLocal_snmp_SET_community_name [MAX_COMMUNITY_NAME_SIZE];
+//---- FD01: END SNMP community
+
+//static unsigned char aIndexTable [70] [6];
+
+// don't use the socket direcly, use socket_get_instance()
+#define NO_SOCKET -1
+static int mib_interface_socket = NO_SOCKET;
+// function to get the socket. create the socket if it doesn't exist
+int socket_get_instance() {
+ if ( NO_SOCKET == mib_interface_socket ) {
+ //printf("NEW SOCKET INITIALIZED");
+ mib_interface_socket = socket(AF_INET, SOCK_DGRAM, 0);
+ }
+ //printf("mib_interface_socket: %d\n", mib_interface_socket);
+ return mib_interface_socket;
+}
+
+void socket_close() {
+ if ( NO_SOCKET != mib_interface_socket ) {
+ close(mib_interface_socket);
+ mib_interface_socket = NO_SOCKET;
+ }
+}
+
+void parse_interfaces(void)
+{
+ FILE *f;
+ char *buffer;
+ char *p;
+ iface_t *iface;
+ int state;
+
+ memset(&eth_iface,0,sizeof(iface_t));
+ memset(&plc_iface,0,sizeof(iface_t));
+ memset(&br_iface,0,sizeof(iface_t));
+
+ strcpy(eth_iface.ip,"0.0.0.0");
+ strcpy(plc_iface.ip,"0.0.0.0");
+ strcpy(br_iface.ip,"0.0.0.0");
+
+ strcpy(eth_iface.mask,"0.0.0.0");
+ strcpy(plc_iface.mask,"0.0.0.0");
+ strcpy(br_iface.mask,"0.0.0.0");
+
+ strcpy(eth_iface.gw,"0.0.0.0");
+ strcpy(plc_iface.gw,"0.0.0.0");
+ strcpy(br_iface.gw,"0.0.0.0");
+
+ if ((f=fopen(INTERFACES_FILE,"r")))
+ {
+ buffer = malloc(512);
+
+ iface = NULL;
+ state = 0;
+ while(fgets(buffer,512,f))
+ {
+ if ((p=strtok(buffer," \t\n")))
+ {
+ if (!strcmp(p,"auto"))
+ continue;
+ else if (!strcmp(p,"iface"))
+ state = 1;
+ else if (!strcmp(p,"address") && state==1)
+ state = 2;
+ else if (!strcmp(p,"netmask") && state==1)
+ state = 3;
+ else if (!strcmp(p,"gateway") && state==1)
+ state = 4;
+ else if (!strcmp(p,"hwaddress") && state==1)
+ state = 5;
+ else
+ {
+ state = 0;
+ continue; //go to next line
+ }
+
+ if ((p=strtok(NULL," \t\n")))
+ {
+ switch(state)
+ {
+ case 1: // iface
+ if (!strcmp(p,"eth0"))
+ iface = &eth_iface;
+ else if (!strcmp(p,"plc0"))
+ iface = &plc_iface;
+ else if (!strcmp(p,"br0"))
+ iface = &br_iface;
+ else
+ {
+ state = 0;
+ continue; //go to next line
+ }
+ break;
+ case 2: // address
+ strcpy(iface->ip,p);
+ state = 1;
+ break;
+ case 3: // netmask
+ strcpy(iface->mask,p);
+ state = 1;
+ break;
+ case 4: // gateway
+ strcpy(iface->gw,p);
+ state = 1;
+ break;
+ case 5: // hwaddress
+ if (!strcmp(p,"ether") && (p=strtok(NULL," \t\n")))
+ {
+ int mac[6];
+
+ sscanf(p, "%02x:%02x:%02x:%02x:%02x:%02x",
+ &mac[0],&mac[1],&mac[2],&mac[3],&mac[4],&mac[5]);
+ iface->mac[0] = mac[0];
+ iface->mac[1] = mac[1];
+ iface->mac[2] = mac[2];
+ iface->mac[3] = mac[3];
+ iface->mac[4] = mac[4];
+ iface->mac[5] = mac[5];
+ }
+ state = 1;
+ break;
+ default:
+ state = 0;
+ continue; //go to next line
+ }
+ }
+ }
+ }
+
+ free(buffer);
+ fclose(f);
+ }
+
+ // fill macs with current if not set
+ if (strlen(eth_iface.mac)==0)
+ {
+ int skfd= socket_get_instance(); //socket(AF_INET, SOCK_DGRAM, 0);
+ struct ifreq ifr;
+
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name, ETH_DEV);
+ ioctl(skfd, SIOCGIFHWADDR, &ifr);
+ memcpy(eth_iface.mac,ifr.ifr_hwaddr.sa_data,6);
+ //close(skfd);
+ }
+ if (strlen(plc_iface.mac)==0)
+ {
+ int skfd= socket_get_instance(); //socket(AF_INET, SOCK_DGRAM, 0);
+ struct ifreq ifr;
+
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name, PLC_DEV);
+ ioctl(skfd, SIOCGIFHWADDR, &ifr);
+ memcpy(plc_iface.mac,ifr.ifr_hwaddr.sa_data,6);
+ //close(skfd);
+ }
+ // fill br unset with eth
+
+ if (!strcmp(br_iface.ip,"0.0.0.0"))
+ strcpy(br_iface.ip,eth_iface.ip);
+ if (!strcmp(br_iface.mask,"0.0.0.0"))
+ strcpy(br_iface.mask,eth_iface.mask);
+ if (!strcmp(br_iface.gw,"0.0.0.0"))
+ strcpy(br_iface.gw,eth_iface.gw);
+}
+
+
+
+
+
+bool parse_eth_mode(char* p)
+{
+ memset(&eth_mode,0,sizeof(eth_mode));
+
+ if ((0 == p) || (!strncmp(p,"AUTO",4)))
+ {
+ // AUTO mode is the default mode
+ eth_mode.eth_speed = ETH_SPEED_AUTO;
+ eth_mode.eth_duplex = ETH_MODE_AUTO;
+ }
+ else if (!strncmp(p,"10FD",4))
+ {
+ eth_mode.eth_speed = ETH_SPEED_10;
+ eth_mode.eth_duplex = ETH_MODE_FD;
+ }
+ else if (!strncmp(p,"10HD",4))
+ {
+ eth_mode.eth_speed = ETH_SPEED_10;
+ eth_mode.eth_duplex = ETH_MODE_HD;
+ }
+ else if(!strncmp(p,"100FD",5))
+ {
+ eth_mode.eth_speed = ETH_SPEED_100;
+ eth_mode.eth_duplex = ETH_MODE_FD;
+ }
+ else if (!strncmp(p,"100HD",5))
+ {
+ eth_mode.eth_speed = ETH_SPEED_100;
+ eth_mode.eth_duplex = ETH_MODE_HD;
+ }
+ else
+ {
+ //initialize values at AUTO if pb in parsing
+ eth_mode.eth_speed = ETH_SPEED_AUTO;
+ eth_mode.eth_duplex = ETH_MODE_AUTO;
+ return false;
+ }
+
+
+ return true;
+}
+
+
+
+
+
+void parse_network_config(void)
+{
+ FILE *f;
+ char *buffer;
+ char *p;
+ int state;
+
+
+ if ((f=fopen(NETWORK_CONFIG_FILE,"r")))
+ {
+ buffer = malloc(512);
+ bool networking = true;
+
+
+ while(fgets(buffer,512,f))
+ {
+ state = 0;
+ if ((p=strtok(buffer," =\n")))
+ {
+ if (!strcmp(p,"NETWORKING"))
+ state = 1;
+ else if (!strcmp(p,"BRIDGING"))
+ state = 2;
+ if (!strcmp(p,"STP"))
+ state = 3;
+ else if (!strcmp(p,"ETH_MODE"))
+ state = 4;
+ else if (!strcmp(p,"DHCP") && networking)
+ state = 5;
+ else
+ continue; //go to next line
+
+
+ if ((p=strtok(NULL," \n")))
+ {
+ switch(state)
+ {
+ case 1: // NETWORKING
+ if (!strcmp(p,"no"))
+ {
+ networking = false;
+ dhcp_on = false;
+ }
+ else if (!strcmp(p,"yes"))
+ networking = true;
+ else
+ continue;
+ break;
+
+ case 2: // BRIDGING
+ if (!strcmp(p,"no"))
+ bridge_on = false;
+ else if (!strcmp(p,"yes"))
+ bridge_on = true;
+ else
+ continue; //go to next line
+ break;
+
+ case 3: // STP: spanning tree
+ if (!strcmp(p,"no"))
+ stp_on = 0;
+ else if (!strcmp(p,"yes"))
+ stp_on = 1;
+ else
+ continue; //go to next line
+ break;
+
+ case 4: // ETH_MODE
+ if (!parse_eth_mode(p))
+ continue; //go to next line if pb in parsing eth mode
+ break;
+
+ case 5: // DHCP
+ if (!strcmp(p,"no"))
+ dhcp_on = false;
+ else if (!strcmp(p,"yes"))
+ dhcp_on = true;
+ else
+ continue;
+ break;
+
+ default:
+ continue; //go to next line
+ }
+ }
+ }
+ }
+
+ free(buffer);
+ fclose(f);
+ }
+
+}
+
+
+//---- FD01: BEGIN SNMP community
+void parse_agent_config(void)
+{
+ char buffer[MAX_COMMUNITY_NAME_SIZE];
+
+ memset(pLocal_snmp_GET_community_name, 0, MAX_COMMUNITY_NAME_SIZE);
+ memset(pLocal_snmp_SET_community_name, 0, MAX_COMMUNITY_NAME_SIZE);
+
+ if ((spidlib_read_config_param(SPIDLIB_CONFIG_SNMP_PATH, SPIDLIB_ADMIN_PUBLIC_COMMUNITY_KEY, buffer, MAX_COMMUNITY_NAME_SIZE - 1) == 0)
+ && (strlen(buffer) > 0))
+ {
+ strncpy( pLocal_snmp_GET_community_name, buffer, MAX_COMMUNITY_NAME_SIZE-1);
+ }
+ else
+ {
+ strcpy( pLocal_snmp_GET_community_name, _DEFAULT_SNMP_GET_COMMUNITY);
+ }
+
+ if ((spidlib_read_config_param(SPIDLIB_CONFIG_SNMP_PATH, SPIDLIB_ADMIN_PRIVATE_COMMUNITY_KEY, buffer, MAX_COMMUNITY_NAME_SIZE - 1) == 0)
+ && (strlen(buffer) > 0))
+ {
+ strncpy( pLocal_snmp_SET_community_name, buffer, MAX_COMMUNITY_NAME_SIZE-1);
+ }
+ else
+ {
+ strcpy( pLocal_snmp_SET_community_name, _DEFAULT_SNMP_SET_COMMUNITY);
+ }
+
+
+}
+//---- FD01: BEGIN SNMP community
+
+
+
+
+#define VALID_IP(X) (strcmp(X,"0.0.0.0"))
+#define VALID_MAC(X) (X[0] || X[1] || X[2] || X[3] || X[4] || X[5])
+
+
+
+
+void init_plc_options() {
+
+ int buf_len=16;
+ char buffer[buf_len];
+ memset(buffer,0,buf_len);
+ {
+ /* This code produces errir on the read_sysctl, sysctl not found?, comment for now */
+ /*int sysctl_name[]={CTL_NET,NET_PLC,PLC_CE,PLCCE_POWER_EQU};
+ read_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),buffer,&buf_len);
+ if (strcmp(buffer,"AUTO")==0)
+ plc_power_equalization_on = 1;*/
+ }
+ {
+ /* This code produces errir on the read_sysctl, sysctl not found?, comment for now */
+ /*int sysctl_name[]={CTL_NET,NET_PLC,PLC_SAR,PLCSAR_ENABLE};
+ buf_len=16;
+ memset(buffer,0,buf_len);
+ read_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),buffer,&buf_len);
+ if (strcmp(buffer,"1")==0)
+ plc_segmentation_and_reassembly_on = 1;*/
+ }
+ {
+ int sysctl_name[]={CTL_NET,NET_PLC,PLC_SPY,SPY_AUTO,SPY_AUTO_ENABLE};
+ buf_len=16;
+ memset(buffer,0,buf_len);
+ read_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),buffer,&buf_len);
+ plc_spy_on=(strcmp(buffer,"1")==0) ? 1 : 0;
+ }
+}
+
+static void flush_interfaces(void)
+{
+ FILE *f;
+
+ if ((f=fopen(INTERFACES_FILE,"w")))
+ {
+ fprintf(f,"auto lo eth0 plc0 br0\n");
+ fprintf(f,"\n");
+ fprintf(f," iface lo inet loopback\n");
+ fprintf(f,"\n");
+
+ fprintf(f," iface eth0 inet static\n");
+ fprintf(f," address %s\n",eth_iface.ip);
+ fprintf(f," netmask %s\n",eth_iface.mask);
+ if (VALID_IP(eth_iface.gw))
+ fprintf(f," gateway %s\n",eth_iface.gw);
+ fprintf(f,"\n");
+
+ fprintf(f," iface plc0 inet static\n");
+ fprintf(f," address %s\n",plc_iface.ip);
+ fprintf(f," netmask %s\n",plc_iface.mask);
+ fprintf(f,"\n");
+
+ if (VALID_IP(br_iface.ip))
+ {
+ fprintf(f," iface br0 inet static\n");
+ fprintf(f," address %s\n",br_iface.ip);
+ fprintf(f," netmask %s\n",br_iface.mask);
+ if (VALID_IP(br_iface.gw))
+ fprintf(f," gateway %s\n",br_iface.gw);
+ }
+ fprintf(f,"\n");
+
+ fclose(f);
+ sync();
+ }
+}
+
+static void check_mode(void)
+{
+ FILE *f;
+
+ //if ((current_mode!=saved_mode) ) //|| (bssid_changed))
+ {
+ saved_mode = current_mode;
+ //system("grep -v \"net.plc.mode\" /usr/local/etc/sysctl.conf | grep -v \"net.plc.*bssid\" > /tmp/sysctl2.conf");
+ system("grep -v \"net.plc.mode\" /usr/local/etc/sysctl.conf > /tmp/sysctl3.conf");
+ if ((f=fopen("/tmp/sysctl4.conf","w")))
+ {
+ switch(current_mode)
+ {
+ case PLC_MODE_MASTER:
+ fprintf(f,"net.plc.mode=master\n");
+ //fprintf(f,"net.plc.bssid=%d\n", current_bssid);
+ break;
+ case PLC_MODE_SLAVE:
+ fprintf(f,"net.plc.mode=slave\n");
+ //fprintf(f,"net.plc.preferred_bssid=%d\n", current_bssid);
+ break;
+ case PLC_MODE_AD_HOC:
+ default:
+ fprintf(f,"net.plc.mode=ad-hoc\n");
+ break;
+ }
+
+
+ fclose(f);
+
+ system("cat /tmp/sysctl3.conf /tmp/sysctl4.conf > /usr/local/etc/sysctl.conf");
+ unlink("/tmp/sysctl4.conf");
+
+
+ //BSSID and preferred BSSID
+ //system("sysctl net.plc.preferred_bssid >> /usr/local/etc/sysctl.conf");
+ //system("sysctl net.plc.bssid >> /usr/local/etc/sysctl.conf");
+ sync();
+ }
+ unlink("/tmp/sysctl3.conf");
+ }
+}
+
+
+void save_config_network()
+{
+ if (network_config_changed)
+ {
+ system("grep -v \"DHCP\" /usr/local/etc/config/network | grep -v \"STP\" | grep -v \"ETH_MODE\" > /tmp/network_config2");
+ FILE *f;
+ if ((f=fopen("/tmp/network_config1","w")))
+ {
+ char aEth_mode[6];
+ memset(aEth_mode,0,6);
+ bool is_auto = ((eth_mode.eth_speed==ETH_SPEED_AUTO) || (eth_mode.eth_duplex==ETH_MODE_AUTO));
+
+ //If one parameter is AUTO => all is auto
+ if (is_auto)
+ {
+ strncpy(aEth_mode, "AUTO", 4);
+ }
+ else
+ {
+ switch(eth_mode.eth_speed)
+ {
+ case ETH_SPEED_10:
+ strncpy(aEth_mode, "10", 2);
+ break;
+ case ETH_SPEED_100:
+ strncpy(aEth_mode, "100", 3);
+ break;
+ case ETH_SPEED_AUTO:
+ default:
+ // AUTO by default
+ //strncpy(aEth_mode, "AUTO", 4);
+ break;
+ }
+
+ switch(eth_mode.eth_duplex)
+ {
+ case ETH_MODE_HD:
+ strncat(aEth_mode, "HD", 2);
+ break;
+ case ETH_MODE_FD:
+ strncat(aEth_mode, "FD", 2);
+ break;
+ case ETH_MODE_AUTO:
+ default:
+ // AUTO by default
+ // no strcat because AUTO is for both speed and duplex mode
+ //strncpy(aEth_mode, "AUTO", 4);
+ break;
+ }
+ }
+
+ fprintf(f,"ETH_MODE=%s\n",aEth_mode);
+
+ if (dhcp_on)
+ fprintf(f,"DHCP=yes\n");
+ else
+ fprintf(f,"DHCP=no\n");
+
+ if (stp_on == 0)
+ fprintf(f,"STP=no\n");
+ else
+ fprintf(f,"STP=yes\n");
+
+
+ fclose(f);
+ system("cat /tmp/network_config2 /tmp/network_config1 > /usr/local/etc/config/network");
+ unlink("/tmp/network_config1");
+ }
+ unlink("/tmp/network_config2");
+
+ }
+
+}
+
+
+
+
+/***************************************************************************
+ *
+ * init socket
+ *
+ ***************************************************************************/
+
+int init_socket(void) {
+ parse_interfaces();
+ parse_network_config();
+ init_plc_options();
+
+ // ifGeneralInformationGroup structure
+ // ifGeneralInformationGroup structure
+ // PLC Mode
+ int sysctl_name[]={CTL_NET,NET_PLC,PLC_MODE};
+ int buf_len=16;
+ char buffer[buf_len];
+ memset(buffer,0,buf_len);
+
+ read_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),buffer,&buf_len);
+ if (strcmp(buffer,PLC_MODE_AD_HOC_STR)==0)
+ saved_mode=PLC_MODE_AD_HOC;
+ else
+ if (strcmp(buffer,PLC_MODE_SLAVE_STR)==0)
+ saved_mode=PLC_MODE_SLAVE;
+ else
+ {
+ if (strcmp(buffer,PLC_MODE_MASTER_STR)==0)
+ saved_mode=PLC_MODE_MASTER;
+ else
+ saved_mode=PLC_MODE_AD_HOC;
+ }
+ current_mode = saved_mode;
+
+ //BSSID
+ /*int sysctl_name_bssid[] = {CTL_NET,NET_PLC,PLC_BSSID};
+ buf_len=16;
+ memset(buffer,0,buf_len);
+ read_sysctl(sysctl_name_bssid,GET_ARRAY_SIZE(sysctl_name_bssid),buffer,&buf_len);
+ sscanf(buffer,"%u", &saved_bssid);
+ current_bssid = saved_bssid;*/
+
+ return 0;
+}
+
+void close_socket(void) {
+ socket_close();
+}
+
+
+/***************************************************************************
+ *
+ * interface
+ *
+ ***************************************************************************/
+/* All functions return 1 if successfull, 0 otherwise */
+/* ret_value func_name(context pointer, return value pointer)* {} */
+/* No context for the system, system is unique */
+
+bool bridgeOn()
+{
+ struct ifreq ifr;
+ int skfd;
+ bool result;
+
+ skfd = socket_get_instance(); //socket(AF_INET, SOCK_DGRAM, 0);
+
+ // try to get bridge ip
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name, BRIDGE_DEV);
+ result = (ioctl(skfd, SIOCGIFADDR, &ifr)>=0);
+ //close(skfd);
+
+ return result;
+}
+
+/**
+ * To convert from char ip to int ip
+ */
+unsigned long strIP_to_intIP(char* ipAddress)
+{
+ unsigned long intIP=0x00000000;
+ unsigned char scale;
+ char digit[4];
+ unsigned char x,i;
+
+ for(i=0;i<4;i++)
+ {
+ x=0;
+ scale=(3-i)*8;
+ while(*ipAddress!='.' && *ipAddress!='\0')
+ {
+ digit[x++]=*ipAddress++;
+ x&=3;
+ }
+ ipAddress++;
+ digit[x]='\0';
+ intIP|=(atoi(digit)<<scale);
+ }
+ return intIP;
+}
+
+//---- FD01: BEGIN SNMP community
+/***************************************************************************
+ *
+ * agent config
+ *
+ ***************************************************************************/
+int init_agent_config(void)
+{
+ parse_agent_config();
+ return 0;
+}
+
+//---- FD01: END SNMP community
+/******************************************************************************
+ *
+ * mib_getPlcSystem: get PlcSystem data
+ *
+ ******************************************************************************/
+// No context for the system, system is unique
+int mib_getPlcSystem(struct plc_system * plcSystem)
+{
+ int buf_len=128;
+ char buffer[128];
+ memset (buffer,0,buf_len);
+
+ assert (0 != plcSystem);
+
+ int sysctl_name[]={CTL_KERN,KERN_NODENAME}; //hostname
+ read_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),buffer,&buf_len);
+ strcpy(plcSystem->sysname,buffer);
+
+ int sysctl_name2[]={CTL_NET,NET_PLC,PLC_SOFT_V}; //software version
+ buf_len=128;
+ read_sysctl(sysctl_name2,GET_ARRAY_SIZE(sysctl_name2),buffer,&buf_len);
+ strncpy(plcSystem->softwareVersion,buffer,
+ sizeof(plcSystem->softwareVersion));
+
+ sysctl_name2[2]=PLC_BRD_V; //board version
+ buf_len=128;
+ read_sysctl(sysctl_name2,GET_ARRAY_SIZE(sysctl_name2),buffer,&buf_len);
+ strncpy(plcSystem->boardVersion,buffer,
+ sizeof(plcSystem->boardVersion));
+
+ /* This code produces errir on the read_sysctl, sysctl not found?, comment for now */
+ /*sysctl_name2[2]=PLC_AFE_V; //Analogue Front-End Version
+ buf_len=128;
+ read_sysctl(sysctl_name2,GET_ARRAY_SIZE(sysctl_name2),buffer,&buf_len);
+ strncpy(plcSystem->AFEVersion,buffer,
+ sizeof(plcSystem->AFEVersion));*/
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_getSysname: get Sysname
+ *
+ ******************************************************************************/
+int mib_getSysname(char *sysname)
+{
+ int buf_len=64;
+ char buffer[64];
+ memset(buffer,0,buf_len);
+
+ assert (0 != sysname);
+
+ int sysctl_name[]={CTL_KERN,KERN_NODENAME}; //hostname
+ read_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),buffer,&buf_len);
+ strcpy(sysname,buffer);
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_setSysname: set Sysname
+ *
+ ******************************************************************************/
+int mib_setSysname(char *sysname)
+{
+ assert (0 != sysname);
+
+ int sysctl_name[]={CTL_KERN,KERN_NODENAME}; //hostname
+ write_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),sysname,strlen(sysname));
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_getBridgeMac: get bridge data
+ *
+ ******************************************************************************/
+int mib_getBridgeMac(struct bridge_mac * bridgeMac)
+{
+ unsigned char i;
+ struct interface *ife;
+ //union plcbox_t *plcbox;
+ struct ifreq ifr;
+ int skfd;
+
+ assert (0 != bridgeMac);
+
+
+ // get bridge mac
+
+ skfd= socket_get_instance(); //socket(AF_INET, SOCK_DGRAM, 0);
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name, BRIDGE_DEV);
+ ioctl(skfd, SIOCGIFHWADDR, &ifr);
+ memcpy(br_iface.mac,ifr.ifr_hwaddr.sa_data,6);
+
+ // ifGeneralInformationGroup structure
+ bridgeMac->ifGeneralInformationGroup.ifType=IF_MIB_IFTYPE_TRANSPARENTBRIDGE;
+ for(i=0;i<6;i++)
+ bridgeMac->ifGeneralInformationGroup.ifPhysicalAddress[i]=br_iface.mac[i];
+ bridgeMac->ifGeneralInformationGroup.ifAdminStatus=IF_MIB_IFADMINSTATUS_UP;
+ bridgeMac->ifGeneralInformationGroup.ifOperStatus=IF_MIB_IFOPERSTATUS_UP;
+ bridgeMac->ifGeneralInformationGroup.ifHighSpeed=100;
+ bridgeMac->ifGeneralInformationGroup.ifConnectorPresent=IF_MIB_IFCONNECTORPRESENT_FALSE;
+ // sprintf(bridgeMac->ifGeneralInformationGroup.ifDesc,""); -> Using SNMP Agent default value
+ // sprintf(bridgeMac->ifGeneralInformationGroup.ifName,""); -> Using SNMP Agent default value
+ sprintf(bridgeMac->ifGeneralInformationGroup.ifAlias,"bridge");
+
+ // ifHCPacketGroup structure
+ getStats(BRIDGE_DEV,&ife); // Get stats from /proc/net/ -> fixme (use ioctl implementation instead)
+ bridgeMac->ifHCPacketGroup.ifInOctets=ife->stats.rx_bytes;;
+ bridgeMac->ifHCPacketGroup.ifOutOctets=ife->stats.tx_bytes;;
+ bridgeMac->ifHCPacketGroup.ifInUnknownProtos=0;
+ bridgeMac->ifHCPacketGroup.ifInErrors=ife->stats.rx_errors;
+ bridgeMac->ifHCPacketGroup.ifOutErrors=ife->stats.tx_errors;
+ bridgeMac->ifHCPacketGroup.ifInUcastPkts=ife->stats.rx_packets; // to be checked
+ bridgeMac->ifHCPacketGroup.ifOutUcastPkts=ife->stats.tx_packets; // to be checked
+ bridgeMac->ifHCPacketGroup.ifInDiscards=ife->stats.rx_dropped;
+ bridgeMac->ifHCPacketGroup.ifOutDiscards=ife->stats.tx_dropped;
+ bridgeMac->ifHCPacketGroup.ifInMulticastPkts=ife->stats.rx_multicast;
+ bridgeMac->ifHCPacketGroup.ifInBroadcastPkts=0;
+ bridgeMac->ifHCPacketGroup.ifOutMulticastPkts=0;
+ bridgeMac->ifHCPacketGroup.ifOutBroadcastPkts=0;
+ bridgeMac->ifHCPacketGroup.ifPromiscuousMode=IF_MIB_IFPROMISCUOUSMODE_TRUE;
+ bridgeMac->ifHCPacketGroup.ifMtu=0;
+
+ // ipGroup structure
+ bridgeMac->ipGroup.ipAdEntAddr=strIP_to_intIP(br_iface.ip);
+ bridgeMac->ipGroup.ipAdEntNetMask=strIP_to_intIP(br_iface.mask);
+ bridgeMac->ipGroup.ipAdEntBcastAddr=0xFFFFFFFF;
+ bridgeMac->ipGroup.ipNetToMediaType=IP_MIB_IPNETTOMEDIATYPE_STATIC;
+
+ // dot1dBase
+ for(i=0;i<6;i++)
+ bridgeMac->dot1dBase.dot1dBaseBridgeAddress[i]=br_iface.mac[i];
+ bridgeMac->dot1dBase.dot1dBaseType=BRIDGE_MIB_DOT1DBASETYPE_TRANSPARENT_ONLY;
+ bridgeMac->dot1dBase.dot1dBasePortDelayExceededDiscards=0;
+ bridgeMac->dot1dBase.dot1dBasePortMtuExceededDiscards=0;
+
+ // Gateway
+ bridgeMac->ipGateway=strIP_to_intIP(br_iface.gw);
+
+ //close(skfd);
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_setBridgeMac: set bridge data
+ *
+ ******************************************************************************/
+int mib_setBridgeMac(struct bridge_mac * bridgeMac)
+{
+ unsigned char i;
+
+ assert (0 != bridgeMac);
+
+ // ifGeneralInformationGroup structure
+ for(i=0;i<6;i++)
+ br_iface.mac[i]=bridgeMac->ifGeneralInformationGroup.ifPhysicalAddress[i];
+
+ // ipGroup structure
+ sprintf(br_iface.ip,"%d.%d.%d.%d",(bridgeMac->ipGroup.ipAdEntAddr>>24)&0xFF,
+ (bridgeMac->ipGroup.ipAdEntAddr>>16)&0xFF,
+ (bridgeMac->ipGroup.ipAdEntAddr>>8)&0xFF,
+ bridgeMac->ipGroup.ipAdEntAddr&0xFF);
+ sprintf(br_iface.mask,"%d.%d.%d.%d",(bridgeMac->ipGroup.ipAdEntNetMask>>24)&0xFF,
+ (bridgeMac->ipGroup.ipAdEntNetMask>>16)&0xFF,
+ (bridgeMac->ipGroup.ipAdEntNetMask>>8)&0xFF,
+ bridgeMac->ipGroup.ipAdEntNetMask&0xFF);
+
+ // Gateway
+ sprintf(br_iface.gw,"%d.%d.%d.%d",(bridgeMac->ipGateway>>24)&0xFF,
+ (bridgeMac->ipGateway>>16)&0xFF,
+ (bridgeMac->ipGateway>>8)&0xFF,
+ bridgeMac->ipGateway&0xFF);
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_getEthMac: get ethernet data
+ *
+ ******************************************************************************/
+int mib_getEthMac(struct eth_mac * ethMac)
+{
+ unsigned char i;
+ struct interface *ife;
+ //union plcbox_t *plcbox;
+ //struct ifreq ifr;
+ //int skfd;
+
+ assert (0 != ethMac);
+
+ // ifGeneralInformationGroup structure
+ ethMac->ifGeneralInformationGroup.ifType=IF_MIB_IFTYPE_ETHERNETCSMACD;
+ for(i=0;i<6;i++)
+ ethMac->ifGeneralInformationGroup.ifPhysicalAddress[i]=eth_iface.mac[i];
+ ethMac->ifGeneralInformationGroup.ifAdminStatus=IF_MIB_IFADMINSTATUS_UP;
+ ethMac->ifGeneralInformationGroup.ifOperStatus=IF_MIB_IFOPERSTATUS_UP;
+ // ethMac->ifGeneralInformationGroup.ifHighSpeed=100;
+ ethMac->ifGeneralInformationGroup.ifConnectorPresent=IF_MIB_IFCONNECTORPRESENT_TRUE;
+ // sprintf(ethMac->ifGeneralInformationGroup.ifDesc,""); -> Using SNMP Agent default value
+ // sprintf(ethMac->ifGeneralInformationGroup.ifName,""); -> Using SNMP Agent default value
+ sprintf(ethMac->ifGeneralInformationGroup.ifAlias,"ethernet");
+
+ // ifHCPacketGroup structure
+ getStats(ETH_DEV,&ife); // Get stats from /proc/net/ -> fixme (use ioctl implementation instead)
+
+ assert (0 != ife);
+
+ ethMac->ifHCPacketGroup.ifInOctets=ife->stats.rx_bytes;;
+ ethMac->ifHCPacketGroup.ifOutOctets=ife->stats.tx_bytes;;
+ ethMac->ifHCPacketGroup.ifInUnknownProtos=0;
+ ethMac->ifHCPacketGroup.ifInErrors=ife->stats.rx_errors;
+ ethMac->ifHCPacketGroup.ifOutErrors=ife->stats.tx_errors;
+ ethMac->ifHCPacketGroup.ifInUcastPkts=ife->stats.rx_packets; // to be checked
+ ethMac->ifHCPacketGroup.ifOutUcastPkts=ife->stats.tx_packets; // to be checked
+ ethMac->ifHCPacketGroup.ifInDiscards=ife->stats.rx_dropped;
+ ethMac->ifHCPacketGroup.ifOutDiscards=ife->stats.tx_dropped;
+ ethMac->ifHCPacketGroup.ifInMulticastPkts=ife->stats.rx_multicast;
+ ethMac->ifHCPacketGroup.ifInBroadcastPkts=0;
+ ethMac->ifHCPacketGroup.ifOutMulticastPkts=0;
+ ethMac->ifHCPacketGroup.ifOutBroadcastPkts=0;
+ ethMac->ifHCPacketGroup.ifPromiscuousMode=IF_MIB_IFPROMISCUOUSMODE_TRUE;
+ ethMac->ifHCPacketGroup.ifMtu=0;
+
+ // ipGroup structure
+ ethMac->ipGroup.ipAdEntAddr=strIP_to_intIP(eth_iface.ip);
+ ethMac->ipGroup.ipAdEntNetMask=strIP_to_intIP(eth_iface.mask);
+ ethMac->ipGroup.ipAdEntBcastAddr=0xFFFFFFFF;
+ ethMac->ipGroup.ipNetToMediaType=IP_MIB_IPNETTOMEDIATYPE_STATIC;
+
+ // mauIfGrpBasic structure
+ ethMac->mauIfGrpBasic.ifMauStatus=MAU_MIB_RPMAUSTATUS_OPERATIONAL;
+ ethMac->mauIfGrpBasic.ifMauMediaAvailable=MAU_MIB_RPMAUMEDIAAVAILABLE_AVAILABLE;
+ ethMac->mauIfGrpBasic.ifMauMediaAvailableStateExits=0;
+ ethMac->mauIfGrpBasic.ifMauJabberState=MAU_MIB_IFMAUJABBERSTATE_NOJABBER;
+ ethMac->mauIfGrpBasic.ifMauJabberingStateEnters=0;
+
+ // dot3StatsDuplexStatus
+ // ethMac->dot3StatsDuplexStatus=ETHERLIKE_MIB_DOT3STATSDUPLEXSTATUS_FULLDUPLEX;
+
+ // Gateway
+ ethMac->ipGateway=strIP_to_intIP(eth_iface.gw);
+
+ // Get stats from ioctl (not yet implemented)
+ /*
+ if((skfd=socket(AF_INET,SOCK_DGRAM,0))<0)
+ {
+ perror("socket");
+ return -1;
+ }
+
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name,PLC_DEV);
+ plcbox->iocmd=IOCCMD_ETH_STATS;
+ ifr.ifr_data=(caddr_t)plcbox;
+ if(ioctl(skfd,SIOCPLCBOX,&ifr)<0) // Send ifr to driver module
+ {
+ perror("SIOCPLCBOX getEthMac");
+ return (0);
+ }
+
+ close(skfd);
+ */
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_getEthMac: set ethernet data
+ *
+ ******************************************************************************/
+int mib_setEthMac(struct eth_mac * ethMac)
+{
+ unsigned char i;
+
+ assert(0 != ethMac);
+
+ // ifGeneralInformationGroup structure
+ for(i=0;i<6;i++)
+ eth_iface.mac[i]=ethMac->ifGeneralInformationGroup.ifPhysicalAddress[i];
+
+ // ipGroup structure
+ sprintf(eth_iface.ip,"%d.%d.%d.%d",(ethMac->ipGroup.ipAdEntAddr>>24)&0xFF,
+ (ethMac->ipGroup.ipAdEntAddr>>16)&0xFF,
+ (ethMac->ipGroup.ipAdEntAddr>>8)&0xFF,
+ ethMac->ipGroup.ipAdEntAddr&0xFF);
+ sprintf(eth_iface.mask,"%d.%d.%d.%d",(ethMac->ipGroup.ipAdEntNetMask>>24)&0xFF,
+ (ethMac->ipGroup.ipAdEntNetMask>>16)&0xFF,
+ (ethMac->ipGroup.ipAdEntNetMask>>8)&0xFF,
+ ethMac->ipGroup.ipAdEntNetMask&0xFF);
+
+ // Gateway
+ sprintf(eth_iface.gw,"%d.%d.%d.%d",(ethMac->ipGateway>>24)&0xFF,
+ (ethMac->ipGateway>>16)&0xFF,
+ (ethMac->ipGateway>>8)&0xFF,
+ ethMac->ipGateway&0xFF);
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_getPlcMac: get plc data
+ *
+ ******************************************************************************/
+int mib_getPlcMac(struct plc_mac * plcMac)
+{
+ unsigned char i;
+ //struct interface *ife;
+ union plcbox_t plcbox;
+ struct ifreq ifr;
+ int skfd;
+
+ assert(0 != plcMac);
+
+ // ifGeneralInformationGroup structure
+ plcMac->ifGeneralInformationGroup.ifType=IF_MIB_IFTYPE_PLC;
+ for(i=0;i<6;i++)
+ plcMac->ifGeneralInformationGroup.ifPhysicalAddress[i]=plc_iface.mac[i];
+ plcMac->ifGeneralInformationGroup.ifAdminStatus=IF_MIB_IFADMINSTATUS_UP;
+ plcMac->ifGeneralInformationGroup.ifOperStatus=IF_MIB_IFOPERSTATUS_UP;
+ plcMac->ifGeneralInformationGroup.ifHighSpeed=24*(PMD_MAX_BANDS-1);
+ plcMac->ifGeneralInformationGroup.ifConnectorPresent=IF_MIB_IFCONNECTORPRESENT_TRUE;
+ sprintf(plcMac->ifGeneralInformationGroup.ifAlias,"plc");
+
+ // ipGroup structure
+ plcMac->ipGroup.ipAdEntAddr=strIP_to_intIP(plc_iface.ip);
+ plcMac->ipGroup.ipAdEntNetMask=strIP_to_intIP(plc_iface.mask);
+ plcMac->ipGroup.ipAdEntBcastAddr=0xFFFFFFFF;
+ plcMac->ipGroup.ipNetToMediaType=IP_MIB_IPNETTOMEDIATYPE_STATIC;
+
+ // Gateway
+ plcMac->ipGateway=strIP_to_intIP(plc_iface.gw);
+
+ // PLC Mode
+ plcMac->mode=current_mode;
+
+ // Get stats from ioctl (not yet implemented)
+ if((skfd= socket_get_instance())<0) // socket(AF_INET,SOCK_DGRAM,0))<0)
+ {
+ perror("socket");
+ return -1;
+ }
+
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name,PLC_DEV);
+ plcbox.iocmd=IOCCMD_STATS;
+ ifr.ifr_data=(caddr_t)&plcbox;
+ if(ioctl(skfd,SIOCPLCBOX,&ifr)<0) // Send ifr to driver module
+ {
+ //close(skfd);
+ perror("SIOCPLCBOX getPlcMac");
+ return (-1);
+ }
+
+ plcMac->ifHCPacketGroup.ifInOctets = plcbox.stats.netstats.rx_bytes;
+ plcMac->ifHCPacketGroup.ifOutOctets = plcbox.stats.netstats.tx_bytes;
+ plcMac->ifHCPacketGroup.ifInUnknownProtos = 0;
+ plcMac->ifHCPacketGroup.ifInErrors = plcbox.stats.netstats.rx_errors;
+ plcMac->ifHCPacketGroup.ifOutErrors = plcbox.stats.netstats.tx_errors;
+ plcMac->ifHCPacketGroup.ifInUcastPkts = plcbox.stats.packetstats.rx_upackets;
+ plcMac->ifHCPacketGroup.ifOutUcastPkts = plcbox.stats.packetstats.tx_upackets;
+ plcMac->ifHCPacketGroup.ifInDiscards = plcbox.stats.netstats.rx_dropped;
+ plcMac->ifHCPacketGroup.ifOutDiscards = plcbox.stats.netstats.tx_dropped;
+ plcMac->ifHCPacketGroup.ifInMulticastPkts = plcbox.stats.packetstats.rx_mpackets;
+ plcMac->ifHCPacketGroup.ifInBroadcastPkts = plcbox.stats.packetstats.rx_bpackets;
+ plcMac->ifHCPacketGroup.ifOutMulticastPkts = plcbox.stats.packetstats.tx_mpackets;
+ plcMac->ifHCPacketGroup.ifOutBroadcastPkts = plcbox.stats.packetstats.tx_bpackets;
+
+ plcMac->ifHCPacketGroup.ifPromiscuousMode = IF_MIB_IFPROMISCUOUSMODE_TRUE;
+ plcMac->ifHCPacketGroup.ifMtu = 0;
+
+ //close(skfd);
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_setPlcMac: set plc data
+ *
+ ******************************************************************************/
+int mib_setPlcMac(struct plc_mac * plcMac)
+{
+ unsigned char i;
+
+ assert(0 != plcMac);
+
+ // ifGeneralInformationGroup structure
+ for(i=0;i<6;i++)
+ plc_iface.mac[i]=plcMac->ifGeneralInformationGroup.ifPhysicalAddress[i];
+
+ // ipGroup structure
+ sprintf(plc_iface.ip,"%d.%d.%d.%d",(plcMac->ipGroup.ipAdEntAddr>>24)&0xFF,
+ (plcMac->ipGroup.ipAdEntAddr>>16)&0xFF,
+ (plcMac->ipGroup.ipAdEntAddr>>8)&0xFF,
+ plcMac->ipGroup.ipAdEntAddr&0xFF);
+ sprintf(plc_iface.mask,"%d.%d.%d.%d",(plcMac->ipGroup.ipAdEntNetMask>>24)&0xFF,
+ (plcMac->ipGroup.ipAdEntNetMask>>16)&0xFF,
+ (plcMac->ipGroup.ipAdEntNetMask>>8)&0xFF,
+ plcMac->ipGroup.ipAdEntNetMask&0xFF);
+
+ // Gateway
+ sprintf(plc_iface.gw,"%d.%d.%d.%d",(plcMac->ipGateway>>24)&0xFF,
+ (plcMac->ipGateway>>16)&0xFF,
+ (plcMac->ipGateway>>8)&0xFF,
+ plcMac->ipGateway&0xFF);
+
+ // PLC Mode
+ current_mode=plcMac->mode;
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_setStaticBand: set static synchro band
+ *
+ ******************************************************************************/
+int
+mib_setStaticBand ( unsigned int iBand )
+{
+ int buf_len = 32;
+ char buffer[buf_len];
+
+ //syslog(LOG_WARNING, "*** mib_setStaticBand\n");
+ memset(buffer, 0, buf_len);
+ int sysctl_name[] = {CTL_NET, NET_PLC, PLC_BANDS}; // static band
+ read_sysctl(sysctl_name, GET_ARRAY_SIZE(sysctl_name), buffer, &buf_len);
+ sprintf(buffer + buf_len - 2, "%d", iBand);
+ //syslog(LOG_WARNING, "*** wrote iBand = %u\n", iBand);
+
+ return write_sysctl(sysctl_name, GET_ARRAY_SIZE(sysctl_name), buffer, buf_len);
+}
+
+
+/******************************************************************************
+ *
+ * mib_getStaticBand: get static synchro band
+ *
+ ******************************************************************************/
+unsigned int
+mib_getStaticBand ( )
+{
+ int aBand = 0;
+ int buf_len = 32;
+ char buffer[buf_len];
+
+ //syslog(LOG_WARNING, "*** mib_getStaticBand\n");
+ memset(buffer, 0, buf_len);
+ int sysctl_name[] = {CTL_NET, NET_PLC, PLC_BANDS}; // static band
+ read_sysctl(sysctl_name, GET_ARRAY_SIZE(sysctl_name), buffer, &buf_len);
+ sscanf(buffer + buf_len - 2, "%u", &aBand);
+ //syslog(LOG_WARNING, "*** read aBand = %u\n", aBand);
+
+ return aBand;
+}
+
+
+/******************************************************************************
+ *
+ * mib_getHostNb: get number of host/link
+ *
+ ******************************************************************************/
+int mib_getHostNb(void)
+{
+
+ int buf_len = 128;
+ char buffer[buf_len];
+ int sysctl_name[]={CTL_NET, NET_PLC,PLC_PLCP,PLCP_NB_HOSTS};
+ read_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),buffer,&buf_len);
+
+ return atoi(buffer);
+}
+
+
+/******************************************************************************
+ *
+ * mib_getPlcHost: get host data
+ *
+ ******************************************************************************/
+int mib_getPlcHost(int hostNb, struct plc_host * plcHost)
+{
+ struct user_host aUserHost;
+ struct ifreq ifr;
+ int skfd;
+ //int sysctl_name[]={CTL_NET,NET_PLC,PLC_CE,PLCCE_ENABLE};
+ //int buf_len=32;
+ //char buffer[buf_len];
+
+ assert(0 != plcHost);
+
+ aUserHost.index=hostNb;
+ aUserHost.iocmd = 1;
+
+ if((skfd= socket_get_instance())<0) // socket(AF_INET,SOCK_DGRAM,0))<0)
+ {
+ perror("socket");
+ return -1;
+ }
+
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name,"plc0");
+ ifr.ifr_data=(caddr_t)&aUserHost;
+
+ // printf("adress of user host given in ifr data is: %x\n", &aUserHost);
+
+
+ //printf("before ioctl heavy called\n");
+ //fflush(stdout);
+ if(ioctl(skfd,SIOCGHOST,&ifr)<0) // Send ifr to driver module
+ {
+ //close(skfd);
+ return -1;
+ }
+ // printf("after ioctl heavy called\n");
+ //fflush(stdout);
+
+
+
+ //printf("ca avance pas, Thierry deprime \n");
+ //printf("Thiewrry a mal au coude \n");
+ //fflush(stdout);
+
+ // internally done in SIOCGHOST
+ // read_sysctl(sysctl_name, GET_ARRAY_SIZE(sysctl_name), buffer, &buf_len);
+ //passHost.plcHost.automatic = strcmp(buffer,"0")?1:0;
+ memcpy(plcHost,&(aUserHost.plcHost),sizeof(struct plc_host));
+
+ //printf("After memcopy of aUserHost.plchost in heavy\n");
+ //close(skfd);
+
+/*
+ //TEST64SLAVES: simulate iocet
+ int myAddIndex;
+ //printf("add an entry at %d in table\n",hostNb );
+ for ( myAddIndex=0; myAddIndex<6; myAddIndex++ )
+ {
+ aIndexTable[hostNb][myAddIndex] = (unsigned char)plcHost->macAddress[myAddIndex];
+ //printf("Mac add at [%d] is: %d\n", myAddIndex, plcHost->macAddress[myAddIndex]);
+
+ }
+ //TEST64SLAVES: simulate ioctl
+*/
+
+ return 0;
+}
+
+
+
+//light hosts
+int mib_getPlcLightHost(int hostNb, struct plc_host * aLightHost)
+{
+ //SIOCGHOSTLIGHT
+ struct user_host aUserHost;
+ struct ifreq ifr;
+ int skfd;
+
+ assert(0 != aLightHost);
+
+ aUserHost.index=hostNb;
+ aUserHost.iocmd = 2;
+
+ if((skfd= socket_get_instance())<0) // socket(AF_INET,SOCK_DGRAM,0))<0)
+ {
+ perror("socket");
+ return -1;
+ }
+
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name,"plc0");
+ ifr.ifr_data=(caddr_t)&aUserHost;
+
+ // printf("adress of user host given in ifr data is: %x\n", &aUserHost);
+
+ // printf("before ioctl light called\n");
+ //fflush(stdout);
+ if(ioctl(skfd,SIOCGHOST,&ifr)<0) // Send ifr to driver module
+ {
+ //close(skfd);
+ return -1;
+ }
+ // printf("After ioctl light called\n");
+ //fflush(stdout);
+
+ // printf("ca avance pas, Thierry deprime\n ");
+ // printf("Thiewrry a mal au coude \n");
+ //fflush(stdout);
+
+ //memcpy(aLightHost,&passHost,sizeof(struct pass_host));
+ memcpy(aLightHost,&(aUserHost.plcHost),sizeof(struct plc_host));
+ // printf("After memcopy of aUserHost.plchost in aLightHost\n");
+ // fflush(stdout);
+ ///memcpy(&aLightHost->plcHost,&(passHost.plcHost),sizeof(struct plc_host));
+ //close(skfd);
+
+ return 0;
+}
+
+
+int mib_getIndexByMac(const unsigned char iMacAddress[6])
+{
+ struct user_host aUserHost;
+ struct ifreq ifr;
+ int skfd;
+
+
+//printf("MAC add [0] is: %d\n", iMacAddress[0]);
+//printf("MAC add [1] is: %d\n", iMacAddress[1]);
+//printf("MAC add [2] is: %d\n", iMacAddress[2]);
+//printf("MAC add [3] is: %d\n", iMacAddress[3]);
+//printf("MAC add [4] is: %d\n", iMacAddress[4]);
+//printf("MAC add [5] is: %d\n", iMacAddress[5]);
+
+/*
+aPassMac.mac[0]=(unsigned char)0;
+aPassMac.mac[1]=(unsigned char)19;
+aPassMac.mac[2]=(unsigned char)215;
+aPassMac.mac[3]=(unsigned char)35;
+aPassMac.mac[4]=(unsigned char)0;
+aPassMac.mac[5]=(unsigned char)39;
+*/
+
+ assert(0 != iMacAddress);
+ // Fill the mac address
+ int k=0;
+ for ( k=0;k<6;++k)
+ {
+ aUserHost.macAddress[k] = iMacAddress[k];
+ }
+ aUserHost.iocmd = 3;
+
+
+
+ if((skfd= socket_get_instance())<0) //socket(AF_INET,SOCK_DGRAM,0))<0)
+ {
+ perror("socket");
+ return -1;
+ }
+
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name,"plc0");
+ ifr.ifr_data=(caddr_t)&aUserHost;
+
+ // printf("adress of user host given in ifr data is: %x\n", &aUserHost);
+
+ // printf("before ioctl index called\n");
+ // fflush(stdout);
+ int resultIoctl;
+ resultIoctl = ioctl(skfd,SIOCGHOST,&ifr);
+ // printf("After ioctl index called\n");
+ // fflush(stdout);
+
+
+
+// printf("ca avance pas, Thierry deprime\n ");
+// printf("Thiewrry a mal au coude\n ");
+// fflush(stdout);
+
+ if( resultIoctl<0) // Send ifr to driver module
+ {
+
+ // printf("result ioctl: %d\n",resultIoctl );
+ // fflush(stdout);
+ //close(skfd);
+ return -1;
+ }
+
+ //SIOCGHOSTIDBYMAC
+ int aIndex = aUserHost.index;
+ //memcpy(aMacToIdx,&aPassMac,sizeof(struct pass_mac));
+ //close(skfd);
+
+ /* int aIndex ;
+ aIndex = aPassMac.id;*/
+ if (aIndex>=0)
+ return aIndex;
+ else
+ return -1;
+
+
+}
+
+
+/******************************************************************************
+ *
+ * mib_getPlcBasePortByIndex: get host plc base port entry
+ *
+ ******************************************************************************/
+int mib_getPlcBasePortByIndex (int hostNb, struct plc_base_port *plcBasePort)
+{
+ struct user_base_port aUserBasePort;
+ struct ifreq ifr;
+ int skfd;
+ int k = 0;
+
+ assert(0 <= index);
+
+ // Fill user host
+ aUserBasePort.index = hostNb;
+
+ if (0 > (skfd = socket_get_instance()))
+ {
+ perror("socket");
+ return -1;
+ }
+
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name,"plc0");
+ ifr.ifr_data = (caddr_t)&aUserBasePort;
+
+ // Send ifr to driver module
+ if (0 > ioctl(skfd, SIOCGBASEPORT, &ifr))
+ {
+ return -1;
+ }
+
+ // Fill host plc base port entry data
+ for (k=0; k<6; ++k)
+ {
+ plcBasePort->macAddress[k] = aUserBasePort.plcBasePort.macAddress[k];
+ }
+ plcBasePort->automatic = aUserBasePort.plcBasePort.automatic;
+ plcBasePort->avg_att = aUserBasePort.plcBasePort.avg_att;
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_setPlcHost: set host data
+ *
+ ******************************************************************************/
+int mib_setPlcHost(int hostNb, struct plc_host * plcHost)
+{
+ struct pass_host passHost;
+ struct ifreq ifr;
+ int skfd;
+
+ assert (0 != plcHost);
+
+ //int sysctl_name[]={CTL_NET,NET_PLC,PLC_CE,PLCCE_ENABLE};
+ passHost.hostNb=hostNb;
+
+ memcpy(&(passHost.plcHost),plcHost, sizeof(struct plc_host));
+
+ if ((skfd = socket_get_instance())<0) //socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ {
+ perror("socket");
+ return -1;
+ }
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name, PLC_DEV);
+ ifr.ifr_data = (caddr_t) &passHost;
+
+ if(ioctl(skfd,SIOCSHOST,&ifr)<0) // Send ifr to driver module
+ {
+ close(skfd);
+ return -1;
+ }
+
+ close(skfd);
+
+ return 0;
+}
+
+#define SN_SAMPLES (20)
+#define SN_PERIOD (10)
+
+/******************************************************************************
+ *
+ * mib_getPlcAnalyser: get Plc SN Analyser data
+ *
+ ******************************************************************************/
+int mib_getPlcAnalyser(struct plc_analyser * plcAnalyser)
+{
+ struct ifreq ifr;
+ int skfd;
+ int len = 10;
+ char buffer[len];
+ char saved_samples[len];
+ char saved_period[len];
+ int result = 0;
+
+ assert (0!= plcAnalyser);
+
+
+ if(plcAnalyser->enable==0)
+ return 0;
+
+ // SN Samples number
+ int sysctl_name_samples[]={CTL_NET,NET_PLC,PLC_SN,PLC_SN_SAMPLES};
+
+ read_sysctl(sysctl_name_samples, GET_ARRAY_SIZE(sysctl_name_samples), saved_samples, &len);
+
+ sprintf(buffer,"%d",SN_SAMPLES);
+ write_sysctl(sysctl_name_samples,GET_ARRAY_SIZE(sysctl_name_samples),buffer,sizeof(buffer));
+
+ // SN Sampling period
+ int sysctl_name_period[]={CTL_NET,NET_PLC,PLC_SN,PLC_SN_PERIOD};
+
+ len = 10;
+ read_sysctl(sysctl_name_period, GET_ARRAY_SIZE(sysctl_name_period), saved_period, &len);
+
+ sprintf(buffer,"%d",SN_PERIOD);
+ write_sysctl(sysctl_name_period,GET_ARRAY_SIZE(sysctl_name_period),buffer,sizeof(buffer));
+
+ // SN Analyser data
+ if((skfd= socket_get_instance())<0) // socket(AF_INET,SOCK_DGRAM,0))<0)
+ {
+ //close(skfd);
+ perror("socket");
+ result = -1;
+ }
+ else
+ {
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name,PLC_DEV);
+ ifr.ifr_data=(caddr_t)plcAnalyser;
+ if(ioctl(skfd,SIOCGSNANALYSER,&ifr)<0) // Send ifr to driver module
+ {
+ perror("SIOCGSNANALYSER getPlcAnalyser");
+ result = -1;
+ }
+
+ //close(skfd);
+ }
+
+ write_sysctl(sysctl_name_samples,GET_ARRAY_SIZE(sysctl_name_samples), saved_samples,sizeof(saved_samples));
+ write_sysctl(sysctl_name_period,GET_ARRAY_SIZE(sysctl_name_period), buffer,sizeof(saved_period));
+
+ return result;
+}
+
+
+/******************************************************************************
+ *
+ * mib_setPlcAnalyser: set Plc SN Analyser data
+ *
+ ******************************************************************************/
+int mib_setPlcAnalyser(struct plc_analyser * plcAnalyser)
+{
+ int sysctl_name[] = {CTL_NET, NET_PLC, PLC_ANALYSER};
+
+ assert (0 != plcAnalyser);
+
+
+ if (plcAnalyser->enable)
+ {
+ analyser_level++;
+ if (analyser_level==1)
+ {
+ write_sysctl(sysctl_name, GET_ARRAY_SIZE(sysctl_name), "1", 2);
+ }
+ }
+ else
+ {
+ analyser_level--;
+ if (analyser_level==0)
+ {
+ write_sysctl(sysctl_name, GET_ARRAY_SIZE(sysctl_name), "0", 2);
+ }
+ }
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_getAgcAnalyser: get Plc AGC Analyser data
+ *
+ ******************************************************************************/
+int mib_getAgcAnalyser(struct agc_analyser * agcAnalyser)
+{
+ struct ifreq ifr;
+ int skfd;
+ int len = 10;
+ char buffer[len];
+ char saved_samples[len];
+ char saved_period[len];
+ int result = 0;
+
+ memset(buffer,0,len);
+
+ assert ( 0!= agcAnalyser);
+
+ if(agcAnalyser->enable==0)
+ return 0;
+
+ // AGC Samples number
+ int sysctl_name_samples[]={CTL_NET,NET_PLC,PLC_SCAN,PLC_SCAN_SAMPLES};
+
+ read_sysctl(sysctl_name_samples, GET_ARRAY_SIZE(sysctl_name_samples), saved_samples, &len);
+
+ sprintf(buffer,"%d",agcAnalyser->samples);
+ write_sysctl(sysctl_name_samples,GET_ARRAY_SIZE(sysctl_name_samples),buffer,sizeof(buffer));
+
+ // AGC Sampling period
+ int sysctl_name_period[]={CTL_NET,NET_PLC,PLC_SCAN,PLC_SCAN_PERIOD};
+
+ len = 10;
+ read_sysctl(sysctl_name_period, GET_ARRAY_SIZE(sysctl_name_period), saved_period, &len);
+
+ sprintf(buffer,"%d",agcAnalyser->period);
+ write_sysctl(sysctl_name_period,GET_ARRAY_SIZE(sysctl_name_period),buffer,sizeof(buffer));
+
+ // AGC Samples
+ if((skfd= socket_get_instance())<0) //socket(AF_INET,SOCK_DGRAM,0))<0)
+ {
+ perror("socket");
+ //close(skfd);
+ result = -1;
+ }
+ else
+ {
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name,PLC_DEV);
+ ifr.ifr_data=(caddr_t)agcAnalyser;
+ if(ioctl(skfd,SIOCGAGCANALYSER,&ifr)<0) // Send ifr to driver module
+ {
+ perror("SIOCGSNANALYSER getAcAnalyser");
+ result = -1;
+ }
+
+ //close(skfd);
+ }
+
+ write_sysctl(sysctl_name_samples,GET_ARRAY_SIZE(sysctl_name_samples),saved_samples,sizeof(saved_samples));
+ write_sysctl(sysctl_name_period,GET_ARRAY_SIZE(sysctl_name_period),buffer,sizeof(saved_period));
+
+ return result;
+}
+
+
+/******************************************************************************
+ *
+ * mib_setAgcAnalyser: set Plc AGC Analyser data
+ *
+ ******************************************************************************/
+int mib_setAgcAnalyser(struct agc_analyser * agcAnalyser)
+{
+ int sysctl_name[] = {CTL_NET, NET_PLC, PLC_ANALYSER};
+
+ assert(0 != agcAnalyser);
+
+ if (agcAnalyser->enable)
+ {
+ analyser_level++;
+ if (analyser_level==1)
+ {
+ write_sysctl(sysctl_name, GET_ARRAY_SIZE(sysctl_name), "1", 2);
+ }
+ }
+ else
+ {
+ analyser_level--;
+ if (analyser_level==0)
+ {
+ write_sysctl(sysctl_name, GET_ARRAY_SIZE(sysctl_name), "0", 2);
+ }
+ }
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_getSystemCarrier: get System Carrier data
+ *
+ ******************************************************************************/
+// No context for the system_carrier_tab, as the system, it's unique
+int mib_getSystemCarrier(struct system_carrier_tab *systemCarrierTab) {
+
+ struct ifreq ifr; //will contain all the interface parameters
+ int skfd;
+
+ assert( 0 != systemCarrierTab);
+
+ if ((skfd = socket_get_instance())<0) //socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ {
+ perror("socket");
+ return -1;
+ }
+
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name, PLC_DEV);
+ ifr.ifr_data = (caddr_t) systemCarrierTab;
+
+ // plcp_getPilots(systemCarrierTab)
+ if (ioctl(skfd, SIOCGPILOTS, &ifr) < 0) {//send ifr to driver module
+ //close(skfd);
+ perror("SIOCGPILOTS getSystemCarrier");
+ return (-1);
+ }
+
+ // plcp_getNotchs(systemCarrierTab)
+ if (ioctl(skfd, SIOCGNOTCHES, &ifr) < 0) {//send ifr to driver module
+ //close(skfd);
+ perror("SIOCGNOTCHES getSystemCarrier");
+ return (-1);
+ } //printf("groupNotch[0] : %d\n", (*systemCarrierTab).groupNotch[0]);
+
+ // plcp_getAdapts(systemCarrierTab)
+ if (ioctl(skfd, SIOCGADAPTS, &ifr) < 0) {//send ifr to driver module
+ //close(skfd);
+ perror("SIOCGADAPTS getSystemCarrier");
+ return (-1);
+ }
+
+ //close(skfd);
+
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_setSystemCarrier: set System Carrier data
+ *
+ ******************************************************************************/
+int mib_setSystemCarrier(struct system_carrier_tab *systemCarrierTab) {
+
+ struct ifreq ifr; //will contain all the interface parameters
+ int skfd;
+
+ assert ( 0 != systemCarrierTab);
+
+ if ((skfd = socket_get_instance())<0) //socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ {
+ perror("socket");
+ return -1;
+ }
+
+ bzero(&ifr,sizeof(ifr));
+ strcpy(ifr.ifr_name, PLC_DEV);
+ ifr.ifr_data = (caddr_t) systemCarrierTab;
+
+ // plcp_setPilots(systemCarrierTab)
+ if (ioctl(skfd, SIOCSPILOTS, &ifr) < 0) {//send ifr to driver module
+ //close(skfd);
+ perror("SIOCSPILOTS setSystemCarrier");
+ return (-1);
+ }
+
+ // plcp_setNotchs(systemCarrierTab)
+ if (ioctl(skfd, SIOCSNOTCHES, &ifr) < 0) {//send ifr to driver module
+ //close(skfd);
+ perror("SIOCSNOTCHES setSystemCarrier");
+ return (-1);
+ }
+
+ // plcp_setAdapts(systemCarrierTab)
+ if (ioctl(skfd, SIOCSADAPTS, &ifr) < 0) {//send ifr to driver module
+ //close(skfd);
+ perror("SIOCSADAPTS setSystemCarrier");
+ return (-1);
+ }
+ return 0;
+}
+
+
+/******************************************************************************
+ *
+ * mib_setFlagAdapt:
+ *
+ ******************************************************************************/
+int mib_setFlatAdapt(void) { return 0; }
+
+
+/******************************************************************************
+ *
+ * mib_commit: save mib data to flash memory
+ *
+ ******************************************************************************/
+void mib_commit(void)
+{
+ flush_interfaces();
+ save_config_network();
+ //save_linux_sysctl();
+
+ // Let the check mode in last: mode of modem must appear after bssid and preferred bssid
+ check_mode();
+}
+
+
+
+/******************************************************************************
+ *
+ * mib_boardReset: reset system
+ *
+ ******************************************************************************/
+void save_linux_sysctl(void)
+{
+ unlink("/tmp/sysctl1.conf");
+ system("grep -v \"net.plc.mode\" /usr/local/etc/sysctl.conf | \
+ grep -v \"net.plc.*bssid\" | grep -v \"net.plc.bands\" | \
+ grep -v \"net.plc.ce.enable\" | \
+ grep -v \"net.bridge.forwarding\" | \
+ grep -v \"net.plc.ce.power_equ\" | \
+ grep -v \"net.plc.spy.auto*\" | \
+ grep -v \"net.plc.sar.enable*\" | \
+ grep -v \"kernel.hostname\" \
+ > /tmp/sysctl1.conf");
+
+
+ unlink("/tmp/sysctl2.conf");
+ system("sysctl kernel.hostname > /tmp/sysctl2.conf");
+ system("sysctl net.plc.bands >> /tmp/sysctl2.conf");
+ system("sysctl net.plc.ce.enable >> /tmp/sysctl2.conf");
+ system("sysctl net.bridge.forwarding >> /tmp/sysctl2.conf");
+
+ //BSSID and preferred BSSID
+ system("sysctl net.plc.preferred_bssid >> /tmp/sysctl2.conf");
+ system("sysctl net.plc.bssid >> /tmp/sysctl2.conf");
+
+
+ // set plc options
+ if ( plc_power_equalization_on ) {
+ system("echo net.plc.ce.power_equ = AUTO >> /tmp/sysctl2.conf");
+ }
+ else {
+ system("echo net.plc.ce.power_equ = MANUAL >> /tmp/sysctl2.conf");
+ }
+ if ( plc_spy_on ) {
+ system("echo net.plc.spy.auto.enable = 1 >> /tmp/sysctl2.conf");
+ }
+ else {
+ system("echo net.plc.spy.auto.enable = 0 >> /tmp/sysctl2.conf");
+ }
+ if ( plc_segmentation_and_reassembly_on ) {
+ system("echo net.plc.sar.enable = 1 >> /tmp/sysctl2.conf");
+ }
+ else {
+ system("echo net.plc.sar.enable = 0 >> /tmp/sysctl2.conf");
+ }
+ //system("mv /tmp/sysctl.conf /usr/local/etc/plc/sysctl.conf");
+
+ system("cat /tmp/sysctl1.conf /tmp/sysctl2.conf > /usr/local/etc/sysctl.conf");
+ unlink("/tmp/sysctl1.conf");
+ unlink("/tmp/sysctl2.conf");
+
+
+ system("cp /proc/net/plc/notches/0 /usr/local/etc/plc/notches");
+ system("cp /proc/net/plc/pilots/aspros/0 /usr/local/etc/plc/pilots");
+ system("cp /proc/net/plc/adapts/0 /usr/local/etc/plc/adapts");
+
+
+ // flush jffs2
+ sync();
+}
+
+
+
+/******************************************************************************
+ *
+ * mib_boardReset: reset system
+ *
+ ******************************************************************************/
+void mib_boardReset(void)
+{
+ system("reboot");
+ exit(0);
+}
+
+
+
+
+/**********************************************
+ * former FTP, kept for possible compatibility * FIXME
+ **********************************************/
+
+enum mib_softUpgRc mib_openFTP(char ftpServerIp[16], uint16_t ftpServerPort, char* login, char* passwd) //PR50: Updated FTP parameters
+ //enum mib_softUpgRc mib_openFTP(char ftpServerIp[16], char* login, char* passwd) //PR50: Updated FTP parameters
+{
+ //return RC_UPG_OK;
+}
+
+enum mib_softUpgRc mib_closeFTP() {
+ //return RC_UPG_OK;
+}
+
+enum mib_softUpgRc mib_upgradeSoftware(char *ftpIp, uint16_t ftpPort, char* login, char* passwd, char* softwareName)
+{
+ /* ftpPort is in host format */
+ // printf("FTP %s:%d htons(%d)=%d\n", ftpIp, ftpPort, htons(ftpPort));
+ return boottable_create(ftpIp, ftpPort, login, passwd, softwareName);
+}
+
+enum mib_softUpgRc mib_upgradeSecureSoftware(char *ftpIp, uint16_t ftpPort, char* login, char* passwd, char* softwareName, char* md5_file)
+{
+ /* ftpPort is in host format */
+ // printf("FTP %s:%d htons(%d)=%d\n", ftpIp, ftpPort, htons(ftpPort));
+ return boottable_secure_create(ftpIp, ftpPort, login, passwd, softwareName, md5_file);
+}
+
+enum mib_softUpgRc mib_getLastUploadStatus()
+{
+ return LAST_UPLOAD_STATUS;
+ return 0;
+}
+
+enum mib_softUpgRc mib_getSoftwareRelease(char releaseName[10][32])
+{
+ int nbRel = 0;
+
+ // Correction to return correct number of images (used to return one additional image)
+ nbRel = boottable_images(releaseName);
+
+ return nbRel;
+}
+
+/* this function dosen't return but RESET the board */
+enum mib_softUpgRc mib_commitSoftwareUpgrade(char* softwareName)
+{
+ boottable_select(softwareName);
+ /* shell_software_reset_no_wait(0,NULL);*/
+ system("reboot");
+ return RC_UPG_OK;
+}
+
+enum mib_softUpgRc mib_eraseRelease(char *releaseName)
+{
+ return boottable_erase(releaseName);
+}
+
+void mib_get_bootstats(int *boot, int *manual_reset, int *failure_reset)
+{
+ FILE *f;
+ char buffer[16];
+
+ if (boot)
+ {
+ if ((f=fopen("/proc/bootstats/boot","r")))
+ {
+ fread(buffer,1,16,f);
+ *boot = atoi(buffer);
+ }
+ else
+ *boot = -1;
+ }
+
+ if (manual_reset)
+ {
+ if ((f=fopen("/proc/bootstats/manual_reset","r")))
+ {
+ fread(buffer,1,16,f);
+ *manual_reset = atoi(buffer);
+ }
+ else
+ *manual_reset = -1;
+ }
+
+ if (failure_reset)
+ {
+ if ((f=fopen("/proc/bootstats/failure_reset","r")))
+ {
+ fread(buffer,1,16,f);
+ *failure_reset = atoi(buffer);
+ }
+ else
+ *failure_reset = -1;
+ }
+}
+
+
+
+/******************************************************************************
+ *
+ * mib_setEthSpeed
+ *
+ ******************************************************************************/
+int mib_setWishedEthSpeed(enumSpeed_t speed)
+{
+ network_config_changed = true;
+ eth_mode.eth_speed = speed;
+
+ return 0;
+
+}
+
+int mib_getEthSetupSpeed()
+{
+ int result;
+ struct ifreq ifr;
+ int fd;
+
+ fd = socket_get_instance(); //socket(AF_INET,SOCK_DGRAM,0);
+ strcpy(ifr.ifr_name, "eth0");
+ if(ioctl(fd, SIOCGGETLINKSETUPSPEED, &ifr) < 0) {
+ perror("SIOCGGETLINKSETUPSPEED");
+ return -1;
+ }
+ result = (int)ifr.ifr_data;
+ //close(fd);
+ if ( (result != ETH_SPEED_10) && (result != ETH_SPEED_100) && (result != ETH_SPEED_AUTO) )
+ return -1;
+ else
+ return result;
+}
+
+int mib_getEthCurrentSpeed(enumSpeed_t* aSpeed)
+{
+ int result;
+ struct ifreq ifr;
+ int fd;
+
+ fd = socket_get_instance(); //socket(AF_INET,SOCK_DGRAM,0)
+ strcpy(ifr.ifr_name, "eth0");
+ if(ioctl(fd, SIOCGGETLINKCURRENTSPEED, &ifr) < 0) {
+ perror("SIOCGGETLINKCURRENTSPEED");
+ return -1;
+ }
+ result = (int)ifr.ifr_data;
+ //close(fd);
+
+ if (result == ETH_SPEED_10)
+ *aSpeed = ETH_SPEED_10;
+ else if (result == ETH_SPEED_100)
+ *aSpeed = ETH_SPEED_100;
+ else if (result == ETH_SPEED_AUTO)
+ *aSpeed = ETH_SPEED_AUTO;
+ else
+ {
+ *aSpeed = ETH_SPEED_AUTO;
+ return -1; // no good values returned
+ }
+
+ return 0;
+
+}
+
+int mib_setWishedEthMode(enumDuplex_t mode)
+{
+ network_config_changed = true;
+ eth_mode.eth_duplex = mode;
+
+ return 0;
+}
+
+enumDuplex_t mib_getWishedEthMode(void)
+{
+ return eth_mode.eth_duplex;
+}
+
+enumSpeed_t mib_getWishedEthSpeed(void)
+{
+ return eth_mode.eth_speed;
+}
+
+
+int mib_getEthSetupMode()
+{
+ int result=0;
+ struct ifreq ifr;
+ int fd;
+
+ fd = socket_get_instance(); //socket(AF_INET,SOCK_DGRAM,0);
+ strcpy(ifr.ifr_name, "eth0");
+ if(ioctl(fd, SIOCGGETLINKSETUPMODE, &ifr) < 0) {
+ perror("SIOCGGETLINKSETUPMODE");
+ return -1;
+ }
+ result = (int)ifr.ifr_data;
+ //close(fd);
+ if ( (result != ETH_MODE_HD) && (result != ETH_MODE_FD) && (result != ETH_MODE_AUTO) )
+ return -1;
+ else
+ return result;
+}
+
+int mib_getEthCurrentMode(enumDuplex_t* aDuplexMode)
+{
+ int result=0;
+ struct ifreq ifr;
+ int fd;
+
+ fd = socket_get_instance(); //socket(AF_INET,SOCK_DGRAM,0);
+ strcpy(ifr.ifr_name, "eth0");
+ if(ioctl(fd, SIOCGGETLINKCURRENTMODE, &ifr) < 0) {
+ perror("SIOCGGETLINKCURRENTMODE");
+ return -1;
+ }
+ result = (int)ifr.ifr_data;
+ //close(fd);
+
+ if (result == ETH_MODE_FD)
+ *aDuplexMode = ETH_MODE_FD;
+ else if (result == ETH_MODE_HD)
+ *aDuplexMode = ETH_MODE_HD;
+ else if (result == ETH_MODE_AUTO)
+ *aDuplexMode = ETH_MODE_AUTO;
+ else
+ {
+ *aDuplexMode = ETH_MODE_AUTO;
+ return -1; // no good values returned
+ }
+ return 0;
+}
+
+
+
+
+/*int mib_getCurrentEthConfig(eth_config_t* oEth_mode)
+ {
+ int tmp;
+ if (0 != oEth_mode)
+ {
+ oEth_mode->eth_duplex = mib_getEthCurrentMode();
+ }
+ else
+ return -1;
+
+ return 0;
+ }*/
+
+/* BRIDGE IOCTL */
+#include "linux/if_bridge.h"
+
+int mib_getSTPMode(void)
+{
+ int fd;
+ struct ifreq ifr;
+ struct __bridge_info i;
+ unsigned long args[4] = { BRCTL_GET_BRIDGE_INFO,
+ (unsigned long) &i, 0, 0 };
+
+ fd = socket_get_instance(); //socket(AF_INET,SOCK_DGRAM,0);
+ strcpy(ifr.ifr_name, "br0");
+ ifr.ifr_data = (char *) &args;
+
+ if (ioctl(fd, SIOCDEVPRIVATE, &ifr) < 0) {
+ dprintf("%s: can't get info %s\n",
+ "br0", strerror(errno));
+ return errno;
+ }
+ return (i.stp_enabled);
+}
+
+int mib_setSTPMode(int mode)
+{
+ int fd;
+ struct ifreq ifr;
+ unsigned long args[4] = {BRCTL_SET_BRIDGE_STP_STATE, mode, 0, 0 };
+
+ fd = socket_get_instance(); //socket(AF_INET,SOCK_DGRAM,0);
+ strcpy(ifr.ifr_name, "br0");
+ ifr.ifr_data = (char *) &args;
+ ioctl(fd, SIOCDEVPRIVATE, &ifr);
+ if(ioctl(fd, SIOCDEVPRIVATE, &ifr) < 0) {
+ perror("BRCTL_SET_BRIDGE_PRIORITY");
+ return -1;
+ }
+ //close(fd);
+
+ //save the stp mode to save it in flash if it is asked
+ network_config_changed = true;
+ stp_on = mode;
+
+
+ return 0;
+}
+
+
+/*Network config*/
+int mib_getDHCPMode(void)
+{
+ return dhcp_on;
+}
+
+int mib_setDHCPMode(bool mode)
+{
+ network_config_changed = true;
+ dhcp_on = mode;
+ return 0;
+}
+
+
+
+
+/*bridge options*/
+int mib_getBridgeForwarding()
+{
+ int buf_len=64;
+ char buffer[64];
+ memset(buffer,0,buf_len);
+
+ int sysctl_name[]={CTL_NET,NET_BRIDGE,BRIDGE_FORWARDING}; //hostname
+ read_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),buffer,&buf_len);
+
+ return strtoul(buffer,NULL,0);
+}
+
+int mib_setBridgeForwarding(int mode)
+{
+ int buf_len=64;
+ char buffer[64];
+ memset(buffer,0,buf_len);
+
+ int sysctl_name[]={CTL_NET,NET_BRIDGE,BRIDGE_FORWARDING}; //hostname
+ sprintf(buffer,"%d",mode);
+ write_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),buffer,buf_len);
+
+ return 0;
+}
+
+int
+mib_get_plc_spy ( )
+{
+ int buf_len = 8;
+ char buffer[buf_len];
+ int sysctl_name[] = { CTL_NET, NET_PLC, PLC_SPY, SPY_AUTO, SPY_AUTO_ENABLE };
+
+ //syslog(LOG_WARNING, "*** mib_get_plc_spy\n");
+ memset (buffer, 0, buf_len);
+ read_sysctl (sysctl_name, GET_ARRAY_SIZE(sysctl_name), buffer, &buf_len);
+ plc_spy_on = (0 == strcmp (buffer, "0")) ? 0 : 1;
+ //syslog(LOG_WARNING, "*** read plc_spy_on = %u\n", plc_spy_on);
+
+ return plc_spy_on;
+}
+
+void
+mib_set_plc_spy ( int enabled )
+{
+ int buf_len = 8;
+ char buffer[buf_len];
+ int sysctl_name[] = { CTL_NET, NET_PLC, PLC_SPY, SPY_AUTO, SPY_AUTO_ENABLE };
+
+ //syslog(LOG_WARNING, "*** mib_set_plc_spy\n");
+ plc_spy_on = enabled;
+ memset (buffer, 0, buf_len);
+ sprintf(buffer, "%d", plc_spy_on);
+ write_sysctl (sysctl_name, GET_ARRAY_SIZE(sysctl_name), buffer, buf_len);
+ //syslog(LOG_WARNING, "*** wrote plc_spy_on = %u\n", plc_spy_on);
+}
+
+int mib_get_plc_segmentation_and_reassembly() {
+ return plc_segmentation_and_reassembly_on;
+}
+
+void mib_set_plc_segmentation_and_reassembly(int enabled) {
+ plc_segmentation_and_reassembly_on = enabled;
+}
+
+int mib_get_plc_power_equalization() {
+ return plc_power_equalization_on;
+}
+
+void mib_set_plc_power_equalization(bool enabled) {
+ plc_power_equalization_on = enabled;
+}
+
+
+//PLC_PREFERRED_BSSID
+//PLC_BSSID
+unsigned int mib_get_plc_bssid() {
+ int aBssid=0;
+ int buf_len=64;
+ char buffer[buf_len];
+
+ memset(buffer,0,buf_len);
+ int sysctl_name_bssid[] = {CTL_NET,NET_PLC,PLC_BSSID};
+ read_sysctl(sysctl_name_bssid,GET_ARRAY_SIZE(sysctl_name_bssid),buffer,&buf_len);
+ sscanf(buffer,"%u", &aBssid);
+
+ return aBssid;
+}
+
+void mib_set_plc_bssid(unsigned int iBssid) {
+ int buf_len=64;
+ char buffer[buf_len];
+
+ memset(buffer,0,buf_len);
+ int sysctl_name[]={CTL_NET,NET_PLC,PLC_BSSID}; //bssid
+ sprintf(buffer,"%d",iBssid);
+ write_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),buffer,buf_len);
+}
+
+unsigned int mib_get_plc_preferred_bssid() {
+ int aBssid=0;
+ int buf_len=64;
+ char buffer[buf_len];
+
+ memset(buffer,0,buf_len);
+ int sysctl_name_bssid[] = {CTL_NET,NET_PLC,PLC_PREFERRED_BSSID};
+ read_sysctl(sysctl_name_bssid,GET_ARRAY_SIZE(sysctl_name_bssid),buffer,&buf_len);
+ sscanf(buffer,"%u", &aBssid);
+ return aBssid;
+}
+
+void mib_set_plc_preferred_bssid(unsigned int iBssid) {
+ int buf_len=64;
+ char buffer[buf_len];
+
+ memset(buffer,0,buf_len);
+ int sysctl_name[]={CTL_NET,NET_PLC,PLC_PREFERRED_BSSID}; //preferred bssid
+ sprintf(buffer,"%d",iBssid);
+ write_sysctl(sysctl_name,GET_ARRAY_SIZE(sysctl_name),buffer,buf_len);
+}
+
+//---- FD01: BEGIN SNMP community
+
+int mib_get_SNMP_community(char * pSnmp_GET_community_name, char * pSnmp_SET_community_name) {
+
+ /* if problem */
+ if ( ('\0' == pLocal_snmp_GET_community_name[0]) || ('\0' == pLocal_snmp_SET_community_name[0]) )
+ return 1;
+
+ strncpy(pSnmp_GET_community_name, pLocal_snmp_GET_community_name, MAX_COMMUNITY_NAME_SIZE-1);
+ strncpy(pSnmp_SET_community_name ,pLocal_snmp_SET_community_name, MAX_COMMUNITY_NAME_SIZE-1);
+ return 0;
+}
+
+//---- FD01: END SNMP community
+
+
+#endif /*ifdef __LINUX__*/