more preprocessor magic
This commit is contained in:
parent
221cb400c8
commit
4c371de8f9
6 changed files with 89 additions and 167 deletions
87
src/Lookup.h
87
src/Lookup.h
|
@ -1,87 +0,0 @@
|
||||||
/*
|
|
||||||
* Switch.cpp
|
|
||||||
*
|
|
||||||
* Created on: 29.09.2015
|
|
||||||
* Author: jdi
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "table.h"
|
|
||||||
|
|
||||||
static table rcv_lookup = { //
|
|
||||||
{ 1, table::STRING, "type" }, //+string
|
|
||||||
{ 2, table::STRING, "hostname" }, //+string
|
|
||||||
{ 3, table::HEX, "mac" }, //+byte[6]
|
|
||||||
{ 4, table::DEC, "ip_addr" }, //+byte[4]
|
|
||||||
{ 5, table::DEC, "ip_mask" }, //+byte[4]
|
|
||||||
{ 6, table::DEC, "gateway" }, //+byte[4]
|
|
||||||
{ 7, table::STRING, "firmware_version" },//+
|
|
||||||
{ 8, table::STRING, "hardware_version" },//+
|
|
||||||
{ 9, table::DEC, "dhcp" }, //+bool byte
|
|
||||||
{ 10, table::DEC, "ports" }, //+byte, maybe number of ports
|
|
||||||
|
|
||||||
{ 4352, table::HEX, "igmp_snooping" }, //???
|
|
||||||
{ 4096, table::HEX, "port_settings" }, //+per port
|
|
||||||
{ 4608, table::HEX, "port_trunk" }, //byte[5] last byte bitmask??
|
|
||||||
|
|
||||||
{ 8192, table::HEX, "mtu_vlan" }, //byte[2] first byte bool,second byte port id
|
|
||||||
{ 8448, table::HEX, "port_vlan_1" }, //???
|
|
||||||
{ 8450, table::HEX, "port_vlan_2" }, //???
|
|
||||||
{ 8704, table::HEX, "vlan_enabled" }, //+bool byte
|
|
||||||
{ 8705, table::HEX, "vlan" }, //+one set per vlan
|
|
||||||
{ 8706, table::HEX, "vlan_pvid" }, //+per port
|
|
||||||
{ 8707, table::HEX, "vlan ?????" }, //????
|
|
||||||
|
|
||||||
{ 12288, table::HEX, "qos_basic_enabled" }, //+bool = QoS Mod
|
|
||||||
{ 12289, table::HEX, "qos_basic" }, //+per port ???
|
|
||||||
{ 12544, table::HEX, "bandwidth_control_1" }, //+per port ???
|
|
||||||
{ 12545, table::HEX, "bandwidth_control_2" }, //+per port ???
|
|
||||||
{ 12800, table::HEX, "storm_control" }, //+per port ???
|
|
||||||
{ 16640, table::HEX, "port_mirror" }, //byte[10] second byte port id???
|
|
||||||
{ 16384, table::HEX, "port_statistics" }, //+per port ???
|
|
||||||
{ 16896, table::HEX, "cable_test" }, //+per port ???
|
|
||||||
{ 17152, table::HEX, "loop_prevention" }, //+bool byte
|
|
||||||
|
|
||||||
//{0000," "},
|
|
||||||
};
|
|
||||||
|
|
||||||
static table snd_lookup = {
|
|
||||||
|
|
||||||
// TODO find out if id is unique in response
|
|
||||||
{ 2, table::HEX, "system_info" }, //page sysinfo
|
|
||||||
{ 9, table::HEX, "ip_config" }, //page sysinfo
|
|
||||||
{ 10, table::HEX, "ports" }, //after login
|
|
||||||
{ 512, table::STRING, "login_user" }, //string
|
|
||||||
{ 513, table::STRING, "new_user" }, //string
|
|
||||||
{ 514, table::STRING, "login_password" }, //string
|
|
||||||
{ 515, table::STRING, "new_passwoord" }, //string
|
|
||||||
{ 773, table::HEX, "reboot" }, //bool byte = save config
|
|
||||||
|
|
||||||
{ 1280, table::ACTION, "reset" }, //
|
|
||||||
{ 1536, table::ACTION, "flash" }, //update firmware
|
|
||||||
|
|
||||||
{ 2200, table::HEX, "vlan" }, //vlan
|
|
||||||
{ 2304, table::ACTION, "save" }, //save
|
|
||||||
{ 2305, table::ACTION, "ping" }, //sent before SET ???
|
|
||||||
|
|
||||||
{ 4352, table::HEX, "igmp_snooping" }, //switching
|
|
||||||
{ 4096, table::HEX, "port_settings" }, //switching
|
|
||||||
{ 4608, table::HEX, "port_trunk" }, //byte[5] last byte bitmask??
|
|
||||||
|
|
||||||
{ 8192, table::HEX, "mtu_vlan" }, //byte[2] first byte bool, second byte port id
|
|
||||||
{ 8449, table::HEX, "port_vlan ???" }, //???
|
|
||||||
{ 8448, table::HEX, "port_vlan" }, //open page
|
|
||||||
{ 8704, table::HEX, "vlan_enabled" }, //??? get vlan / set status
|
|
||||||
{ 8705, table::HEX, "vlan" }, // per vlan
|
|
||||||
{ 8706, table::HEX, "vlan_pvid" }, //per port
|
|
||||||
|
|
||||||
{ 12288, table::HEX, "qos_basic_enabled" }, //bool = QoS Mod
|
|
||||||
{ 12289, table::HEX, "qos_basic" }, //per port
|
|
||||||
{ 12544, table::HEX, "bandwidth_control_1" }, //per port
|
|
||||||
{ 12545, table::HEX, "bandwidth_control_2" }, //per port
|
|
||||||
{ 12800, table::HEX, "storm_control" }, //???
|
|
||||||
{ 16640, table::HEX, "port_mirror" }, //byte[10] second byte port id??
|
|
||||||
{ 16384, table::HEX, "port_statistics" }, //???
|
|
||||||
{ 17152, table::HEX, "loop_prevention" }, //bool byte
|
|
||||||
|
|
||||||
//{0000," "},
|
|
||||||
};
|
|
|
@ -20,49 +20,47 @@ int Switch::parse(datasets arr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Switch::parse(dataset d) {
|
int Switch::parse(dataset d) {
|
||||||
auto lookup = (options.flags & FLAG_REVERSE) ? snd_lookup : rcv_lookup;
|
switch (d.type) {
|
||||||
std::string id = lookup.exists(d.type)?lookup[d.type]:"unknown";
|
case RCV_TYPE:
|
||||||
switch(d.type){
|
device.type = d.value;
|
||||||
case TYPE:
|
|
||||||
device.type = d.value;
|
|
||||||
break;
|
break;
|
||||||
}
|
case RCV_MAC:
|
||||||
|
|
||||||
if (id == "mac") {
|
|
||||||
device.mac = d.value;
|
device.mac = d.value;
|
||||||
}
|
break;
|
||||||
else if (d.type == "firmware_version") {
|
case FIRMWARE_VERSION:
|
||||||
device.firmware_version = d.value;
|
device.firmware_version = d.value;
|
||||||
}
|
break;
|
||||||
else if (id == "hardware_version") {
|
case HARDWARE_VERSION:
|
||||||
device.hardware_version = d.value;
|
device.hardware_version = d.value;
|
||||||
}
|
break;
|
||||||
else if (id == "ports") {
|
case PORTS:
|
||||||
device.ports = d.value[0];
|
device.ports = d.value[0];
|
||||||
}
|
break;
|
||||||
else if (id == "hostname") {
|
case HOSTNAME:
|
||||||
settings.hostname = d.value;
|
settings.hostname = d.value;
|
||||||
}
|
break;
|
||||||
else if (id == "ip_addr") {
|
case IP_ADDR:
|
||||||
settings.ip_addr = d.value;
|
settings.ip_addr = d.value;
|
||||||
}
|
break;
|
||||||
else if (id == "ip_mask") {
|
case IP_MASK:
|
||||||
settings.ip_mask = d.value;
|
settings.ip_mask = d.value;
|
||||||
}
|
break;
|
||||||
else if (id == "gateway") {
|
case GATEWAY:
|
||||||
settings.gateway = d.value;
|
settings.gateway = d.value;
|
||||||
}
|
break;
|
||||||
else if (id == "dhcp_enabled") {
|
case DHCP_ENABLED:
|
||||||
settings.dhcp = d.value[0];
|
settings.dhcp = d.value[0];
|
||||||
}
|
break;
|
||||||
else if (id == "loop_prevention") {
|
case LOOP_PREVENTION:
|
||||||
settings.loop_prevention = d.value[0];
|
settings.loop_prevention = d.value[0];
|
||||||
}
|
break;
|
||||||
else if (id == "qos_basic_enabled") {
|
case QOS_BASIC_ENABLED:
|
||||||
settings.qos_enabled = d.value[0];
|
settings.qos_enabled = d.value[0];
|
||||||
}
|
break;
|
||||||
else if (id == "vlan_enabled") {
|
case VLAN_ENABLED:
|
||||||
settings.vlan_enabled = d.value[0];
|
settings.vlan_enabled = d.value[0];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
src/lookup.h
19
src/lookup.h
|
@ -1,17 +1,30 @@
|
||||||
enum {
|
enum {
|
||||||
#define LOOKUP_SET(id, num, type) FOO_ ## id = num,
|
#define LOOKUP_SET(id, num, type) RCV_ ## id = num,
|
||||||
|
#include "lookup/rcv.lst"
|
||||||
#include "lookup/general.lst"
|
#include "lookup/general.lst"
|
||||||
|
#undef LOOKUP_SET
|
||||||
|
#define LOOKUP_SET(id, num, type) SND_ ## id = num,
|
||||||
|
#include "lookup/snd.lst"
|
||||||
|
#include "lookup/general.lst"
|
||||||
|
#undef LOOKUP_SET
|
||||||
|
#define LOOKUP_SET(id, num, type) id = num,
|
||||||
|
#include "lookup/rcv.lst"
|
||||||
|
#include "lookup/snd.lst"
|
||||||
|
#include "lookup/general.lst"
|
||||||
|
#undef LOOKUP_SET
|
||||||
};
|
};
|
||||||
|
|
||||||
static table rcv_lookup {
|
static table rcv_lookup {
|
||||||
#define LOOKUP_SET(id, num, type) { FOO_ ## id, table::type, #id },
|
#define LOOKUP_SET(id, num, type) { RCV_ ## id, table::type, #id },
|
||||||
#include "lookup/rcv.lst"
|
#include "lookup/rcv.lst"
|
||||||
#include "lookup/general.lst"
|
#include "lookup/general.lst"
|
||||||
|
#undef LOOKUP_SET
|
||||||
};
|
};
|
||||||
|
|
||||||
static table snd_lookup {
|
static table snd_lookup {
|
||||||
#define LOOKUP_SET(id, num, type) { FOO_ ## id, table::type, #id },
|
#define LOOKUP_SET(id, num, type) { SND_ ## id, table::type, #id },
|
||||||
#include "lookup/snd.lst"
|
#include "lookup/snd.lst"
|
||||||
#include "lookup/general.lst"
|
#include "lookup/general.lst"
|
||||||
|
#undef LOOKUP_SET
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
LOOKUP_SET(IGMP_SNOOPING, 4352, HEX) //???
|
LOOKUP_SET(PORTS, 10, DEC) //+byte, maybe number of ports
|
||||||
LOOKUP_SET(PORTS_SETTINGS, 4096, HEX) //+per port
|
|
||||||
LOOKUP_SET(PORT_TRUNK, 4608, HEX) //byte[5] last byte bitmask??
|
|
||||||
|
|
||||||
LOOKUP_SET(MTU_VLAN, 8192, HEX) //byte[2] first byte bool,second byte port id
|
LOOKUP_SET(IGMP_SNOOPING, 4352, HEX) //???
|
||||||
LOOKUP_SET(PORT_VLAN_ENABLED, 8448, BOOL) //open page
|
LOOKUP_SET(PORTS_SETTINGS, 4096, HEX) //+per port
|
||||||
LOOKUP_SET(PORT_VLAN, 8449, HEX)
|
LOOKUP_SET(PORT_TRUNK, 4608, HEX) //byte[5] last byte bitmask??
|
||||||
LOOKUP_SET(PORT_VLAN_MAX, 8450, DEC)
|
|
||||||
LOOKUP_SET(VLAN_ENABLED, 8704, BOOL) //+bool byte
|
|
||||||
LOOKUP_SET(VLAN, 8705, HEX) //+one set per vlan
|
|
||||||
LOOKUP_SET(VLAN_PVID, 8706, HEX) //+per port
|
|
||||||
LOOKUP_SET(VLAN_FOOOO, 8707, DEC) //????
|
|
||||||
|
|
||||||
LOOKUP_SET(QOS_BASIC_ENABLED, 12288, BOOL) //+bool = QoS Mod
|
LOOKUP_SET(MTU_VLAN, 8192, HEX) //byte[2] first byte bool,second byte port id
|
||||||
LOOKUP_SET(QOS_BASIC, 12289, HEX) //+per port ???
|
LOOKUP_SET(PORT_VLAN_ENABLED, 8448, BOOL) //open page
|
||||||
LOOKUP_SET(BANDWIDTH_CONTROL_INGRESS, 12544, HEX) //+per port ???
|
LOOKUP_SET(PORT_VLAN, 8449, HEX)
|
||||||
LOOKUP_SET(BANDWIDTH_CONTROL_EGRESS, 12545, HEX) //+per port ???
|
LOOKUP_SET(PORT_VLAN_MAX, 8450, DEC)
|
||||||
LOOKUP_SET(STORM_CONTROL, 12800, HEX) //+per port ???
|
LOOKUP_SET(VLAN_ENABLED, 8704, BOOL) //+bool byte
|
||||||
LOOKUP_SET(PORT_MIRROR, 16640, HEX) //byte[10] second byte port id???
|
LOOKUP_SET(VLAN, 8705, HEX) //+one set per vlan
|
||||||
LOOKUP_SET(PORT_STATISTICS, 16384, HEX) //+per port ???
|
LOOKUP_SET(VLAN_PVID, 8706, HEX) //+per port
|
||||||
LOOKUP_SET(CABLE_TEST, 16896, HEX) //+per port ???
|
LOOKUP_SET(VLAN_FOOOO, 8707, DEC) //????
|
||||||
LOOKUP_SET(LOOP_PREVENTION, 17152, BOOL) //+bool byte
|
|
||||||
|
LOOKUP_SET(QOS_BASIC_ENABLED, 12288, BOOL) //+bool = QoS Mod
|
||||||
|
LOOKUP_SET(QOS_BASIC, 12289, HEX) //+per port ???
|
||||||
|
LOOKUP_SET(BW_CONTROL_INGRESS, 12544, HEX) //+per port ???
|
||||||
|
LOOKUP_SET(BW_CONTROL_EGRESS, 12545, HEX) //+per port ???
|
||||||
|
LOOKUP_SET(STORM_CONTROL, 12800, HEX) //+per port ???
|
||||||
|
LOOKUP_SET(PORT_MIRROR, 16640, HEX) //byte[10] second byte port id???
|
||||||
|
LOOKUP_SET(PORT_STATISTICS, 16384, HEX) //+per port ???
|
||||||
|
LOOKUP_SET(CABLE_TEST, 16896, HEX) //+per port ???
|
||||||
|
LOOKUP_SET(LOOP_PREVENTION, 17152, BOOL) //+bool byte
|
||||||
|
|
||||||
#undef LOOKUP_SET
|
|
|
@ -1,15 +1,13 @@
|
||||||
LOOKUP_SET(TYPE, 1, STRING) //+string
|
LOOKUP_SET(TYPE, 1, STRING) //+string
|
||||||
LOOKUP_SET(HOSTNAME, 2, STRING) //+string
|
LOOKUP_SET(HOSTNAME, 2, STRING) //+string
|
||||||
LOOKUP_SET(MAC, 3, HEX) //+byte[6]
|
LOOKUP_SET(MAC, 3, HEX) //+byte[6]
|
||||||
LOOKUP_SET(IP_ADDR, 4, DEC) //+byte[4]
|
LOOKUP_SET(IP_ADDR, 4, DEC) //+byte[4]
|
||||||
LOOKUP_SET(IP_MASK, 5, DEC) //+byte[4]
|
LOOKUP_SET(IP_MASK, 5, DEC) //+byte[4]
|
||||||
LOOKUP_SET(GATEWAY, 6, DEC) //+byte[4]
|
LOOKUP_SET(GATEWAY, 6, DEC) //+byte[4]
|
||||||
LOOKUP_SET(FIRMWARE_VERSION, 7, STRING)
|
LOOKUP_SET(FIRMWARE_VERSION, 7, STRING)
|
||||||
LOOKUP_SET(HARDWARE_VERSION, 8, STRING)
|
LOOKUP_SET(HARDWARE_VERSION, 8, STRING)
|
||||||
LOOKUP_SET(DHCP_ENABLED, 9, BOOL) //+bool byte
|
LOOKUP_SET(DHCP_ENABLED, 9, BOOL) //+bool byte
|
||||||
LOOKUP_SET(PORTS, 10, DEC) //+byte, maybe number of ports
|
|
||||||
|
LOOKUP_SET(PORT_VLAN_FOOOOO, 2101, HEX)
|
||||||
|
|
||||||
LOOKUP_SET(PORT_VLAN_FOOOOO, 2101, HEX)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
LOOKUP_SET(SYSTEM_INFO, 2, HEX) //page sysinfo
|
LOOKUP_SET(SYSTEM_INFO, 2, HEX) //page sysinfo
|
||||||
LOOKUP_SET(IP_CONFIG, 9, HEX) //page sysinfo
|
LOOKUP_SET(IP_CONFIG, 9, HEX) //page sysinfo
|
||||||
LOOKUP_SET(PORTS, 10, HEX) //after login
|
|
||||||
|
|
||||||
|
|
||||||
LOOKUP_SET(LOGIN_USER, 512, STRING) //string
|
LOOKUP_SET(LOGIN_USER, 512, STRING) //string
|
||||||
LOOKUP_SET(NEW_USER, 513, STRING) //string
|
LOOKUP_SET(NEW_USER, 513, STRING) //string
|
||||||
LOOKUP_SET(LOGIN_PASSWORD, 514, STRING) //string
|
LOOKUP_SET(LOGIN_PASSWORD, 514, STRING) //string
|
||||||
LOOKUP_SET(NEW_PASSWORD, 515, STRING) //string
|
LOOKUP_SET(NEW_PASSWORD, 515, STRING) //string
|
||||||
LOOKUP_SET(REBOOT, 773, BOOL) //bool byte = save config
|
LOOKUP_SET(REBOOT, 773, BOOL) //bool byte = save config
|
||||||
|
|
||||||
LOOKUP_SET(RESET, 1280, ACTION) //
|
LOOKUP_SET(RESET, 1280, ACTION) //
|
||||||
LOOKUP_SET(FLASH, 1536, ACTION) //update firmware
|
LOOKUP_SET(FLASH, 1536, ACTION) //update firmware
|
||||||
LOOKUP_SET(VLAN_FOOOOOO, 2200, HEX) //vlan
|
LOOKUP_SET(VLAN_FOOOOOO, 2200, HEX) //vlan
|
||||||
LOOKUP_SET(SAVE, 2304, ACTION) //save
|
LOOKUP_SET(SAVE, 2304, ACTION) //save
|
||||||
LOOKUP_SET(PING, 2305, ACTION) //sent before SET ???
|
LOOKUP_SET(PING, 2305, ACTION) //sent before SET ???
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue