From 0460307fb4cfaf98956c9700c4ff14de8b318fa1 Mon Sep 17 00:00:00 2001 From: Daniel Danzberger Date: Mon, 9 Mar 2020 21:23:57 +0100 Subject: [PATCH] Only export symbols to the library that belong to the API interface This commit makes all symbols that are not part of the API Interface, or used only in the object files where they are defined, static. Causing the following benefits: - The compiler can resolve functions for better performance - The library size is decreased NOTE: Spec file generators need to be adjusted for newer spec's to not do the same mistakes again Signed-off-by: Daniel Danzberger --- dmtree/tr181/atm.c | 114 +- dmtree/tr181/atm.h | 32 +- dmtree/tr181/bridging.c | 3418 +++++------ dmtree/tr181/bridging.h | 118 - dmtree/tr181/deviceinfo.c | 1184 ++-- dmtree/tr181/deviceinfo.h | 59 +- dmtree/tr181/dhcpv4.c | 6341 ++++++++++----------- dmtree/tr181/dhcpv4.h | 159 - dmtree/tr181/dhcpv6.c | 3669 ++++++------ dmtree/tr181/dhcpv6.h | 158 - dmtree/tr181/dns.c | 334 +- dmtree/tr181/dns.h | 71 - dmtree/tr181/dsl.c | 2595 ++++----- dmtree/tr181/dsl.h | 144 - dmtree/tr181/dynamicdns.c | 233 +- dmtree/tr181/dynamicdns.h | 58 - dmtree/tr181/ethernet.c | 2476 ++++---- dmtree/tr181/ethernet.h | 111 - dmtree/tr181/firewall.c | 2427 ++++---- dmtree/tr181/firewall.h | 75 - dmtree/tr181/gre.c | 1776 +++--- dmtree/tr181/gre.h | 85 - dmtree/tr181/hosts.c | 91 +- dmtree/tr181/hosts.h | 22 - dmtree/tr181/interfacestack.c | 37 +- dmtree/tr181/interfacestack.h | 17 +- dmtree/tr181/ip.c | 3808 ++++++------- dmtree/tr181/ip.h | 162 - dmtree/tr181/managementserver.c | 1354 ++--- dmtree/tr181/managementserver.h | 62 - dmtree/tr181/nat.c | 1281 ++--- dmtree/tr181/nat.h | 45 - dmtree/tr181/ppp.c | 1019 ++-- dmtree/tr181/ppp.h | 46 - dmtree/tr181/ptm.c | 95 +- dmtree/tr181/ptm.h | 23 - dmtree/tr181/qos.c | 7476 +++++++++++++------------ dmtree/tr181/qos.h | 377 -- dmtree/tr181/routing.c | 298 +- dmtree/tr181/routing.h | 71 - dmtree/tr181/security.c | 94 +- dmtree/tr181/security.h | 25 - dmtree/tr181/times.c | 76 +- dmtree/tr181/times.h | 21 - dmtree/tr181/upnp.c | 2234 ++++---- dmtree/tr181/upnp.h | 143 - dmtree/tr181/usb.c | 2224 ++++---- dmtree/tr181/usb.h | 104 - dmtree/tr181/userinterface.c | 48 +- dmtree/tr181/userinterface.h | 7 - dmtree/tr181/users.c | 82 +- dmtree/tr181/users.h | 17 - dmtree/tr181/wifi.c | 6487 ++++++++++----------- dmtree/tr181/wifi.h | 289 - dmtree/tr181/x_iopsys_eu_buttons.c | 48 +- dmtree/tr181/x_iopsys_eu_buttons.h | 12 +- dmtree/tr181/x_iopsys_eu_dropbear.c | 88 +- dmtree/tr181/x_iopsys_eu_dropbear.h | 29 +- dmtree/tr181/x_iopsys_eu_ice.c | 24 +- dmtree/tr181/x_iopsys_eu_ice.h | 6 - dmtree/tr181/x_iopsys_eu_igmp.c | 106 +- dmtree/tr181/x_iopsys_eu_igmp.h | 33 - dmtree/tr181/x_iopsys_eu_ipacccfg.c | 1348 ++--- dmtree/tr181/x_iopsys_eu_ipacccfg.h | 56 - dmtree/tr181/x_iopsys_eu_logincfg.c | 29 +- dmtree/tr181/x_iopsys_eu_logincfg.h | 5 - dmtree/tr181/x_iopsys_eu_owsd.c | 148 +- dmtree/tr181/x_iopsys_eu_owsd.h | 39 - dmtree/tr181/x_iopsys_eu_power_mgmt.c | 31 +- dmtree/tr181/x_iopsys_eu_power_mgmt.h | 7 - dmtree/tr181/x_iopsys_eu_syslog.c | 29 +- dmtree/tr181/x_iopsys_eu_syslog.h | 8 - dmtree/tr181/x_iopsys_eu_wifilife.c | 191 +- dmtree/tr181/x_iopsys_eu_wifilife.h | 9 - dmtree/tr181/xmpp.c | 1055 ++-- dmtree/tr181/xmpp.h | 47 - 76 files changed, 27330 insertions(+), 29790 deletions(-) diff --git a/dmtree/tr181/atm.c b/dmtree/tr181/atm.c index 580ed1de..95cb5ea6 100644 --- a/dmtree/tr181/atm.c +++ b/dmtree/tr181/atm.c @@ -12,47 +12,16 @@ #include "dmentry.h" #include "atm.h" -/*** ATM. ***/ -DMOBJ tATMObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Link", &DMWRITE, add_atm_link, delete_atm_link, NULL, browseAtmLinkInst, NULL, NULL, NULL, tATMLinkObj, tATMLinkParams, get_atm_linker, BBFDM_BOTH}, -{0} -}; - -/*** ATM.Link. ***/ -DMOBJ tATMLinkObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tATMLinkStatsParams, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF tATMLinkParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Alias", &DMWRITE, DMT_STRING, get_atm_alias, set_atm_alias, NULL, NULL, BBFDM_BOTH}, -{"Enable", &DMREAD, DMT_BOOL, get_atm_enable, NULL, NULL, NULL, BBFDM_BOTH}, -{"Name", &DMREAD, DMT_STRING, get_atm_link_name, NULL, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_atm_enable, NULL, NULL, NULL, BBFDM_BOTH}, -{"LowerLayers", &DMREAD, DMT_STRING, get_atm_lower_layer, NULL, NULL, NULL, BBFDM_BOTH}, -{"LinkType", &DMWRITE, DMT_STRING, get_atm_link_type, set_atm_link_type, NULL, NULL, BBFDM_BOTH}, -{"DestinationAddress", &DMWRITE, DMT_STRING, get_atm_destination_address, set_atm_destination_address, NULL, NULL, BBFDM_BOTH}, -{"Encapsulation", &DMWRITE, DMT_STRING, get_atm_encapsulation, set_atm_encapsulation, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/*** ATM.Link.Stats. ***/ -DMLEAF tATMLinkStatsParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"BytesSent", &DMREAD, DMT_UNINT, get_atm_stats_bytes_sent, NULL, NULL, NULL, BBFDM_BOTH}, -{"BytesReceived", &DMREAD, DMT_UNINT, get_atm_stats_bytes_received, NULL, NULL, NULL, BBFDM_BOTH}, -{"PacketsSent", &DMREAD, DMT_UNINT, get_atm_stats_pack_sent, NULL, NULL, NULL, BBFDM_BOTH}, -{"PacketsReceived", &DMREAD, DMT_UNINT, get_atm_stats_pack_received, NULL, NULL, NULL, BBFDM_BOTH}, -{0} +struct atm_args +{ + struct uci_section *atm_sec; + char *ifname; }; /************************************************************************** * LINKER ***************************************************************************/ -int get_atm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +static int get_atm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { if (data && ((struct atm_args *)data)->ifname) { *linker = ((struct atm_args *)data)->ifname; @@ -76,7 +45,7 @@ static inline int init_atm_link(struct atm_args *args, struct uci_section *s, ch * SET & GET DSL LINK PARAMETERS ***************************************************************************/ /*#Device.ATM.Link.{i}.DestinationAddress!UCI:dsl/atm-device,@i-1/vpi*/ -int get_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *vpi, *vci; @@ -86,7 +55,7 @@ int get_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, c return 0; } -int set_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *vpi = NULL, *vci = NULL, *spch; @@ -109,14 +78,14 @@ int set_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, c } /*#Device.ATM.Link.{i}.Name!UCI:dsl/atm-device,@i-1/name*/ -int get_atm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_atm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "name", value); return 0; } /*#Device.ATM.Link.{i}.Encapsulation!UCI:dsl/atm-device,@i-1/encapsulation*/ -int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *encapsulation; @@ -130,7 +99,7 @@ int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *i return 0; } -int set_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -148,7 +117,7 @@ int set_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *i } /*#Device.ATM.Link.{i}.LinkType!UCI:dsl/atm-device,@i-1/link_type*/ -int get_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *link_type; @@ -166,7 +135,7 @@ int get_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *insta return 0; } -int set_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -189,7 +158,7 @@ int set_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *insta return 0; } -int get_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char linker[16]; snprintf(linker, sizeof(linker), "channel_%d", atoi(instance)-1); @@ -209,34 +178,34 @@ static inline int ubus_atm_stats(char **value, char *stat_mod, void *data) } /*#Device.ATM.Link.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/ -int get_atm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_atm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { ubus_atm_stats(value, "rx_bytes", data); return 0; } /*#Device.ATM.Link.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/ -int get_atm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_atm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { ubus_atm_stats(value, "tx_bytes", data); return 0; } /*#Device.ATM.Link.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/ -int get_atm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_atm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { ubus_atm_stats(value, "rx_packets", data); return 0; } /*#Device.ATM.Link.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/ -int get_atm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_atm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { ubus_atm_stats(value, "tx_packets", data); return 0; } -int get_atm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_atm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "true"; return 0; @@ -245,7 +214,7 @@ int get_atm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance /************************************************************* * ADD OBJ *************************************************************/ -int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +static int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *instance = NULL, *atm_device = NULL, *v = NULL, *instance_update = NULL; struct uci_section *dmmap_atm = NULL; @@ -268,7 +237,7 @@ int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instancep return 0; } -int delete_atm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +static int delete_atm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL, *ss = NULL, *ns = NULL, *nss = NULL, *dmmap_section= NULL; char *ifname; @@ -327,7 +296,7 @@ int delete_atm_link(char *refparam, struct dmctx *ctx, void *data, char *instanc /************************************************************* * SET AND GET ALIAS *************************************************************/ -int get_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *dmmap_section = NULL; @@ -337,7 +306,7 @@ int get_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, return 0; } -int set_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *dmmap_section = NULL; @@ -359,7 +328,7 @@ int set_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, * ENTRY METHOD *************************************************************/ /*#Device.ATM.Link.{i}.!UCI:dsl/atm-device/dmmap_dsl*/ -int browseAtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseAtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *wnum = NULL, *channel_last = NULL, *ifname; struct atm_args curr_atm_args = {0}; @@ -377,3 +346,40 @@ int browseAtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, free_dmmap_config_dup_list(&dup_list); return 0; } + +/*** ATM. ***/ +DMOBJ tATMObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Link", &DMWRITE, add_atm_link, delete_atm_link, NULL, browseAtmLinkInst, NULL, NULL, NULL, tATMLinkObj, tATMLinkParams, get_atm_linker, BBFDM_BOTH}, +{0} +}; + +/*** ATM.Link. ***/ +DMOBJ tATMLinkObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tATMLinkStatsParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tATMLinkParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Alias", &DMWRITE, DMT_STRING, get_atm_alias, set_atm_alias, NULL, NULL, BBFDM_BOTH}, +{"Enable", &DMREAD, DMT_BOOL, get_atm_enable, NULL, NULL, NULL, BBFDM_BOTH}, +{"Name", &DMREAD, DMT_STRING, get_atm_link_name, NULL, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_atm_enable, NULL, NULL, NULL, BBFDM_BOTH}, +{"LowerLayers", &DMREAD, DMT_STRING, get_atm_lower_layer, NULL, NULL, NULL, BBFDM_BOTH}, +{"LinkType", &DMWRITE, DMT_STRING, get_atm_link_type, set_atm_link_type, NULL, NULL, BBFDM_BOTH}, +{"DestinationAddress", &DMWRITE, DMT_STRING, get_atm_destination_address, set_atm_destination_address, NULL, NULL, BBFDM_BOTH}, +{"Encapsulation", &DMWRITE, DMT_STRING, get_atm_encapsulation, set_atm_encapsulation, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/*** ATM.Link.Stats. ***/ +DMLEAF tATMLinkStatsParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"BytesSent", &DMREAD, DMT_UNINT, get_atm_stats_bytes_sent, NULL, NULL, NULL, BBFDM_BOTH}, +{"BytesReceived", &DMREAD, DMT_UNINT, get_atm_stats_bytes_received, NULL, NULL, NULL, BBFDM_BOTH}, +{"PacketsSent", &DMREAD, DMT_UNINT, get_atm_stats_pack_sent, NULL, NULL, NULL, BBFDM_BOTH}, +{"PacketsReceived", &DMREAD, DMT_UNINT, get_atm_stats_pack_received, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/atm.h b/dmtree/tr181/atm.h index bc59cb9d..77c7b937 100644 --- a/dmtree/tr181/atm.h +++ b/dmtree/tr181/atm.h @@ -14,39 +14,9 @@ #include -struct atm_args -{ - struct uci_section *atm_sec; - char *ifname; -}; - extern DMOBJ tATMObj[]; extern DMOBJ tATMLinkObj[]; extern DMLEAF tATMLinkParams[]; -extern DMLEAF tATMLinkStatsParams[] ; - -int browseAtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_atm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_atm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_atm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_atm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_atm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_atm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_atm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_atm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); +extern DMLEAF tATMLinkStatsParams[]; #endif diff --git a/dmtree/tr181/bridging.c b/dmtree/tr181/bridging.c index c4971358..c972d9b8 100644 --- a/dmtree/tr181/bridging.c +++ b/dmtree/tr181/bridging.c @@ -13,8 +13,1730 @@ #include "dmentry.h" #include "bridging.h" +struct bridging_args +{ + struct uci_section *bridge_sec; + char *br_key; + char *ifname; + char *br_inst; +}; + +struct bridging_port_args +{ + struct uci_section *bridge_port_sec; + struct uci_section *bridge_sec; + bool vlan; + char *ifname; +}; + +struct bridging_vlan_args +{ + struct uci_section *bridge_vlan_sec; + struct uci_section *bridge_sec; + char *vlan_port; + char *br_inst; + char *ifname; +}; + static char *wan_baseifname = NULL; + +/************************************************************************** +* LINKER +***************************************************************************/ +static int get_linker_br_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct bridging_port_args *)data)->bridge_port_sec) { + dmasprintf(linker, "%s+%s", section_name(((struct bridging_port_args *)data)->bridge_port_sec), ((struct bridging_port_args *)data)->ifname); + return 0; + } + *linker = ""; + return 0; +} + +static int get_linker_br_vlan(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct bridging_vlan_args *)data)->vlan_port) { + dmasprintf(linker, "vlan%s_%s", ((struct bridging_vlan_args *)data)->vlan_port, ((struct bridging_vlan_args *)data)->br_inst); + return 0; + } + *linker = ""; + return 0; +} +/************************************************************************** +* INIT +***************************************************************************/ +static inline int init_bridging_args(struct bridging_args *args, struct uci_section *s, char *last_instance, char *ifname, char *br_instance) +{ + args->bridge_sec = s; + args->br_key = last_instance; + args->ifname = ifname; + args->br_inst = br_instance; + return 0; +} + +static inline int init_bridging_port_args(struct bridging_port_args *args, struct uci_section *s, struct uci_section *bs, bool vlan, char *ifname) +{ + args->bridge_port_sec = s; + args->bridge_sec = bs; + args->vlan = vlan; + args->ifname = ifname; + return 0; +} + +static inline int init_bridging_vlan_args(struct bridging_vlan_args *args, struct uci_section *s, struct uci_section *bs, char *vlan_port, char *br_inst) +{ + args->bridge_vlan_sec = s; + args->bridge_sec = bs; + args->vlan_port = vlan_port; + args->br_inst = br_inst; + return 0; +} + +/************************************************************************** +* INSTANCE MG +***************************************************************************/ +static char *get_last_vid(void) +{ + struct uci_section *vlan_s; + char *vid = NULL, *type; + int num_vid = 0; + + uci_foreach_sections("network", "device", vlan_s) { + if(!vlan_s) + break; + dmuci_get_value_by_section_string(vlan_s, "type", &type); + if (strcmp(type, "untagged") == 0) + continue; + dmuci_get_value_by_section_string(vlan_s, "vid", &vid); + if (atoi(vid) > num_vid) + num_vid = atoi(vid); + dmasprintf(&vid, "%d", num_vid); + } + return vid; +} + +static int check_ifname_exist_in_br_ifname_list(char *ifname) +{ + char *br_ifname_list, *br_ifname_dup, *pch, *spch; + struct uci_section *s; + + uci_foreach_option_eq("network", "interface", "type", "bridge", s) { + dmuci_get_value_by_section_string(s, "ifname", &br_ifname_list); + if (br_ifname_list[0] == '\0') + return 0; + br_ifname_dup = dmstrdup(br_ifname_list); + for (pch = strtok_r(br_ifname_dup, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { + if (strcmp(pch, ifname) == 0) + return 1; + } + } + return 0; +} + +static int get_br_port_last_inst(char *br_key) +{ + char *tmp; + int instance, max = 1; + struct uci_section *s; + + uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", br_key, s) { + dmuci_get_value_by_section_string(s, "bridge_port_instance", &tmp); + if (tmp[0] == '\0') + continue; + instance = atoi(tmp); + if (instance > max) max = instance; + } + return max; +} + +static int reset_br_port(char *br_key) +{ + struct uci_section *s, *prev_s = NULL; + + uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", br_key, s) { + if (prev_s) + dmuci_delete_by_section(prev_s, NULL, NULL); + prev_s = s; + } + if (prev_s) dmuci_delete_by_section(prev_s, NULL, NULL); + return 0; +} + +static int check_ifname_is_not_lan_port(char *ifname) +{ + struct uci_section *s; + + if (!strstr(ifname, wan_baseifname)) { + uci_foreach_option_eq("ports", "ethport", "ifname", ifname, s) { + return 0; + } + } + return 1; +} + +static int update_port_parameters(char *linker, char *br_key, char *br_pt_inst, char *mg_port) +{ + struct uci_section *s, *dmmap_section; + + if (check_ifname_is_vlan(linker)) { + uci_foreach_option_eq("network", "device", "ifname", linker, s) { + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); + dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); + dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); + dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); + break; + } + } else if (strncmp(linker, "ptm", 3) == 0) { + uci_foreach_option_eq("dsl", "ptm-device", "device", linker, s) { + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); + dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); + dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); + dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); + break; + } + } else if (strncmp(linker, "atm", 3) == 0) { + uci_foreach_option_eq("dsl", "atm-device", "device", linker, s) { + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); + dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); + dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); + dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); + break; + } + } else if (strncmp(linker, "wl", 2) == 0) { + uci_foreach_option_eq("wireless", "wifi-iface", "ifname", linker, s) { + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); + dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); + dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); + dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); + break; + } + } else if (strncmp(linker, "eth0", 4) == 0) { + uci_foreach_option_eq("network", "device", "name", linker, s) { + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); + dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); + dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); + dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); + break; + } + } else { + uci_foreach_option_eq("ports", "ethport", "ifname", linker, s) { + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); + dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); + dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); + dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); + break; + } + } + return 0; +} + +static int is_br_port_enabled(struct bridging_port_args *curr_arg) +{ + struct uci_section *vlan_sec = curr_arg->bridge_port_sec, *br_sec = curr_arg->bridge_sec; + char *ifname, *br_ifname, *ifname_dup; + + dmuci_get_value_by_section_string(br_sec, "ifname", &br_ifname); + dmuci_get_value_by_section_string(vlan_sec, "name", &ifname); + ifname_dup = dmstrdup(br_ifname); + if(ifname != NULL && ifname[0] != '\0') { + if (is_strword_in_optionvalue(ifname_dup, ifname)) + return 1; + } + return 0; +} + +static int update_br_port_ifname(struct bridging_port_args *curr_arg, int status) +{ + char ifname_dup[128], *ptr, *baseifname, *ifname, *start, *end; + struct uci_section *vlan_sec = curr_arg->bridge_port_sec, *br_sec = curr_arg->bridge_sec; + int pos=0; + dmuci_get_value_by_section_string(br_sec, "ifname", &ifname); + dmuci_get_value_by_section_string(vlan_sec, "name", &baseifname); + ptr = ifname_dup; + dmstrappendstr(ptr, ifname); + dmstrappendend(ptr); + if(status){ + if (is_strword_in_optionvalue(ifname_dup, baseifname)) return 0; + if (ifname_dup[0] != '\0') dmstrappendchr(ptr, ' '); + dmstrappendstr(ptr, baseifname); + dmstrappendend(ptr); + } else { + if (is_strword_in_optionvalue(ifname_dup, baseifname)) { + start = strstr(ifname_dup, baseifname); + end = start + strlen(baseifname); + if (start != ifname_dup) { + start--; + pos=1; + } + memmove(start, start + strlen(baseifname)+pos, strlen(end) + 1); + } + } + dmuci_set_value_by_section(br_sec, "ifname", ifname_dup); + return 0; +} + +/************************************************************************** +*SET & GET BRIDGING PARAMETERS +***************************************************************************/ +static int get_Max_Bridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "20"; + return 0; +} + +static int get_Max_DBridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "20"; + return 0; +} + +static int get_Max_QBridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "20"; + return 0; +} + +static int get_Max_VLAN_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "20"; + return 0; +} + +static int get_Max_Provider_Bridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +static int get_Max_Filter_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +/*#Device.Bridging.BridgeNumberOfEntries!UCI:network/interface/*/ +static int get_Bridge_Number_Of_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_foreach_option_eq("network", "interface", "type", "bridge", s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +/*#Device.Bridging.Bridge.{i}.Enable!UBUS:network.interface/status/interface,@Name/up*/ +static int get_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct bridging_args *)data)->bridge_sec), String}}, 1, &res); + DM_ASSERT(res, *value = "false"); + *value = dmjson_get_value(res, 1, "up"); + return 0; +} + +static int set_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmubus_call_set("network.interface", b ? "up" : "down", UBUS_ARGS{{"interface", section_name(((struct bridging_args *)data)->bridge_sec), String}}, 1); + return 0; + } + return 0; +} + +/*#Device.Bridging.Bridge.{i}.Status!UBUS:network.interface/status/interface,@Name/up*/ +static int get_br_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct bridging_args *)data)->bridge_sec), String}}, 1, &res); + DM_ASSERT(res, *value = "Disabled"); + *value = dmjson_get_value(res, 1, "up"); + if (strcmp(*value, "true") == 0) + *value = "Enabled"; + else + *value = "Disabled"; + return 0; +} + +static int get_br_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "802.1Q-2011"; + return 0; +} + +static int set_br_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, BridgeStandard, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + return 0; + } + return 0; +} + +static int get_br_port_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", instance, s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +static int get_br_vlan_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "device", "bridge_key", instance, s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +static int get_br_vlan_port_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "device", "bridge_key", instance, s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +static int get_br_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct bridging_args *)data)->bridge_sec, "ifname", value); + return 0; +} + +static int set_br_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", value); + return 0; + } + return 0; +} + +/*#Device.Bridging.Bridge.{i}.Port.{i}.Enable!UBUS:network.device/status/name,@Name/speed*/ +static int get_br_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + char *speed, *val; + struct uci_section *wifi_device_s; + + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "ifname", value); + if(strncmp(*value, "wl", 2) == 0 || strncmp(*value, "ra", 2) == 0 || strncmp(*value, "apclii", 6) == 0) { + uci_foreach_option_eq("wireless", "wifi-iface", "ifname", *value, wifi_device_s) { + dmuci_get_value_by_section_string(wifi_device_s, "disabled", &val); + if ((val[0] == '\0') || (val[0] == '0')) + *value = "true"; + else + *value = "false"; + return 0; + } + } + dmubus_call("network.device", "status", UBUS_ARGS{{"name", *value, String}}, 1, &res); + DM_ASSERT(res, *value = "false"); + speed = dmjson_get_value(res, 1, "speed"); + if(*speed != '\0') + *value = "true"; + else + *value = "false"; + return 0; +} + +static int set_br_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + return 0; + } + return 0; +} + +/*#Device.Bridging.Bridge.{i}.Port.{i}.Status!UBUS:network.device/status/name,@Name/speed*/ +static int get_br_port_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + bool b; + get_br_port_enable(refparam, ctx, data, instance, value); + string_to_bool(*value, &b); + *value = b ? "Up" : "Down"; + return 0; +} + +static int get_br_port_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", value); + return 0; +} + +/*#Device.Bridging.Bridge.{i}.Port.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ +static int get_br_port_last_change(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct bridging_port_args *)data)->bridge_sec), String}}, 1, &res); + DM_ASSERT(res, *value = "0"); + *value = dmjson_get_value(res, 1, "uptime"); + if((*value)[0] == '\0') + *value = "0"; + return 0; +} + +static int get_br_port_management(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); + if (!dmmap_section) + dmmap_section = ((struct bridging_port_args *)data)->bridge_port_sec; + dmuci_get_value_by_section_string(dmmap_section, "mg_port", value); + return 0; +} + +static int set_br_port_management(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + return 0; + } + return 0; +} + +static struct uci_section *check_if_ifname_is_tagged(char *ifname) +{ + struct uci_section *s; + uci_foreach_option_eq("network", "device", "name", ifname, s) { + return s; + } + return NULL; +} + +static int get_br_port_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *name; + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); + if (check_if_ifname_is_tagged(name) != NULL) + *value = "CustomerVLANPort"; + else + *value = ""; + return 0; +} + +static int set_br_port_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, BridgeType, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + return 0; + } + return 0; +} + +static int get_br_port_default_user_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *name, *type; + + *value = ""; + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); + s = check_if_ifname_is_tagged(name); + if (s != NULL) { + dmuci_get_value_by_section_string(s, "type", &type); + if (strcmp(type, "untagged") != 0) + dmuci_get_value_by_section_string(s, "priority", value); + } + return 0; +} + +static int set_br_port_default_user_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s = NULL; + char *name, *type; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "0", "7")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); + s = check_if_ifname_is_tagged(name); + if (s != NULL) { + dmuci_get_value_by_section_string(s, "type", &type); + if (strcmp(type, "untagged") != 0) + dmuci_set_value_by_section(s, "priority", value); + } + return 0; + } + return 0; +} + +static int get_br_port_priority_regeneration(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0,1,2,3,4,5,6,7"; + return 0; +} + +static int set_br_port_priority_regeneration(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt_list(value, "8", "8", NULL, "0", "7")) + return FAULT_9007; + return 0; + case VALUESET: + return 0; + } + return 0; +} + +static int get_br_port_port_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *name; + + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); + if (check_if_ifname_is_tagged(name) != NULL) + *value = "Forwarding"; + else + *value = "Disabled"; + return 0; +} + +static int get_br_port_pvid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *name, *type; + + *value = "1"; + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); + s = check_if_ifname_is_tagged(name); + if (s != NULL) { + dmuci_get_value_by_section_string(s, "type", &type); + if (strcmp(type, "untagged") != 0) + dmuci_get_value_by_section_string(s, "vid", value); + } + return 0; +} + +static int set_br_port_pvid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s = NULL; + char *name, *type, *ifname, *new_name; + int is_enabled; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "1", "4094")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); + s = check_if_ifname_is_tagged(name); + if (s != NULL) { + dmuci_get_value_by_section_string(s, "type", &type); + if (strcmp(type, "untagged") != 0) { + dmuci_set_value_by_section(s, "vid", value); + dmuci_get_value_by_section_string(s, "ifname", &ifname); + dmasprintf(&new_name, "%s.%s", ifname, value); + is_enabled = is_br_port_enabled((struct bridging_port_args *)data); + if (is_enabled) + update_br_port_ifname((struct bridging_port_args *)data, 0); + dmuci_set_value_by_section(s, "name", new_name); + if (is_enabled) + update_br_port_ifname((struct bridging_port_args *)data, 1); + dmfree(new_name); + } + } + return 0; + } + return 0; +} + +static int get_br_port_tpid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *type; + + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "type", &type); + if (strcmp(type, "8021q") == 0 || strcmp(type, "untagged") == 0) + *value = "33024"; + else if (strcmp(type, "8021ad") == 0) + *value = "34984"; + else + *value = "37120"; + return 0; +} + +static int set_br_port_tpid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (strcmp(value, "33024") == 0) + dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_port_sec, "type", "8021q"); + else if (strcmp(value, "34984") == 0) + dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_port_sec, "type", "8021ad"); + return 0; + } + return 0; +} + +/************************************************************************** +* GET STAT +***************************************************************************/ +static int br_get_sysfs(const struct bridging_port_args *br, const char *name, char **value) +{ + char *device; + + dmuci_get_value_by_section_string(br->bridge_port_sec, "ifname", &device); + return get_net_device_sysfs(device, name, value); +} + +/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/ +static int get_br_port_stats_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return br_get_sysfs(data, "statistics/tx_bytes", value); +} + +/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/ +static int get_br_port_stats_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return br_get_sysfs(data, "statistics/rx_bytes", value); +} + +/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/ +static int get_br_port_stats_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return br_get_sysfs(data, "statistics/tx_packets", value); +} + +/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/ +static int get_br_port_stats_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return br_get_sysfs(data, "statistics/rx_packets", value); +} + +/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.ErrorsSent!UBUS:network.device/status/name,@Name/statistics.tx_errors*/ +static int get_br_port_stats_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return br_get_sysfs(data, "statistics/tx_errors", value); +} + +/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.ErrorsReceived!UBUS:network.device/status/name,@Name/statistics.rx_errors*/ +static int get_br_port_stats_rx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return br_get_sysfs(data, "statistics/rx_errors", value); +} + +static int get_br_port_stats_tx_unicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_br_port_stats_rx_unicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.DiscardPacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_dropped*/ +static int get_br_port_stats_tx_discard_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return br_get_sysfs(data, "statistics/tx_dropped", value); +} + +/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.DiscardPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_dropped*/ +static int get_br_port_stats_rx_discard_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return br_get_sysfs(data, "statistics/rx_dropped", value); +} + +static int get_br_port_stats_tx_multicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_br_port_stats_rx_multicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return br_get_sysfs(data, "statistics/multicast", value); +} + +static int get_br_port_stats_tx_broadcast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_br_port_stats_rx_broadcast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_br_port_stats_rx_unknown_proto_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int is_bridge_vlan_enabled(struct bridging_vlan_args *curr_arg) +{ + struct uci_section *vlan_sec = curr_arg->bridge_vlan_sec, *br_sec = curr_arg->bridge_sec; + char *ifname, *br_ifname, *ifname_dup; + + dmuci_get_value_by_section_string(br_sec, "ifname", &br_ifname); + dmuci_get_value_by_section_string(vlan_sec, "name", &ifname); + ifname_dup = dmstrdup(br_ifname); + if (ifname != NULL && ifname[0] != '\0') { + if (is_strword_in_optionvalue(ifname_dup, ifname)) + return 1; + } + return 0; +} + +static int update_br_vlan_ifname(struct bridging_vlan_args *curr_arg, int status) +{ + char ifname_dup[128], *ptr, *baseifname, *ifname, *start, *end; + struct uci_section *vlan_sec = curr_arg->bridge_vlan_sec, *br_sec = curr_arg->bridge_sec; + int pos=0; + dmuci_get_value_by_section_string(br_sec, "ifname", &ifname); + dmuci_get_value_by_section_string(vlan_sec, "name", &baseifname); + ptr = ifname_dup; + dmstrappendstr(ptr, ifname); + dmstrappendend(ptr); + if (status) { + if (is_strword_in_optionvalue(ifname_dup, baseifname)) return 0; + if (ifname_dup[0] != '\0') dmstrappendchr(ptr, ' '); + dmstrappendstr(ptr, baseifname); + dmstrappendend(ptr); + } else { + if (is_strword_in_optionvalue(ifname_dup, baseifname)) { + start = strstr(ifname_dup, baseifname); + end = start + strlen(baseifname); + if (start != ifname_dup) { + start--; + pos=1; + } + memmove(start, start + strlen(baseifname)+pos, strlen(end) + 1); + } + } + dmuci_set_value_by_section(br_sec, "ifname", ifname_dup); + return 0; +} + +static int get_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "false"; + int status = is_bridge_vlan_enabled((struct bridging_vlan_args *)data); + if (status) + *value = "true"; + return 0; +} + +static int set_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + int is_enabled; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + is_enabled = is_bridge_vlan_enabled((struct bridging_vlan_args *)data); + if (b && !is_enabled) { + update_br_vlan_ifname((struct bridging_vlan_args *)data, 1); + } + if (!b && is_enabled) { + update_br_vlan_ifname((struct bridging_vlan_args *)data, 0); + } + return 0; + } + return 0; +} + +static int get_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec)); + return 0; +} + +static int set_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_rename_section_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, value); + return 0; + } + return 0; +} + +static int get_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vid", value); + return 0; +} + +static int set_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *name, *ifname; + int is_enabled; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "1", "4094")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vid", value); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", &ifname); + dmasprintf(&name, "%s.%s", ifname, value); + is_enabled = is_bridge_vlan_enabled((struct bridging_vlan_args *)data); + if(is_enabled) + update_br_vlan_ifname((struct bridging_vlan_args *)data, 0); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "name", name); + if(is_enabled) + update_br_vlan_ifname((struct bridging_vlan_args *)data, 1); + dmfree(name); + return 0; + } + return 0; +} + +static int get_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "priority", value); + return 0; +} + +static int set_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + //TODO + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "priority", value); + return 0; + } + return 0; +} +/************************************************************* +* GET SET ALIAS +**************************************************************/ +static int get_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct bridging_args *)data)->bridge_sec), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "bridge_alias", value); + return 0; +} + +static int set_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct bridging_args *)data)->bridge_sec), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "bridge_alias", value); + return 0; + } + return 0; +} + +static int get_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); + if (!dmmap_section) + dmmap_section = ((struct bridging_port_args *)data)->bridge_port_sec; + dmuci_get_value_by_section_string(dmmap_section, "bridge_port_alias", value); + return 0; +} + +static int set_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); + if(!dmmap_section) + dmmap_section = ((struct bridging_port_args *)data)->bridge_port_sec; + dmuci_set_value_by_section(dmmap_section, "bridge_port_alias", value); + return 0; + } + return 0; +} + +static int get_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "bridge_vlan_alias", value); + return 0; +} + +static int set_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "bridge_vlan_alias", value); + return 0; + } + return 0; +} + +/************************************************************* +* ADD DELETE OBJECT +**************************************************************/ +static int add_bridge(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *last_inst, *v; + char bridge_name[16], ib[8]; + char *p = bridge_name; + struct uci_section* dmmap_bridge = NULL; + + last_inst = get_last_instance_lev2_bbfdm("network", "interface", "dmmap_network", "bridge_instance", "type", "bridge"); + snprintf(ib, sizeof(ib), "%d", last_inst ? atoi(last_inst)+1 : 1); + dmstrappendstr(p, "bridge_0_"); + dmstrappendstr(p, ib); + dmstrappendend(p); + dmuci_set_value("network", bridge_name, "", "interface"); + dmuci_set_value("network", bridge_name, "type", "bridge"); + dmuci_set_value("network", bridge_name, "proto", "dhcp"); + + dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_bridge, &v); + dmuci_set_value_by_section(dmmap_bridge, "section_name", bridge_name); + *instance = update_instance_bbfdm(dmmap_bridge, last_inst, "bridge_instance"); + + update_section_list(DMMAP,"bridge_port", "bridge_key", 1, ib, "mg_port", "true", "bridge_port_instance", "1"); + return 0; +} + +static int delete_bridge(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s = NULL, *prev_s = NULL, *bridge_s, *dmmap_section = NULL; + char *bridgekey = NULL; + + switch (del_action) { + case DEL_INST: + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct bridging_args *)data)->bridge_sec), &dmmap_section); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "type", ""); + dmuci_set_value_by_section(dmmap_section, "bridge_instance", ""); + dmuci_set_value_by_section(dmmap_section, "ip_int_instance", ""); + dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); + uci_path_foreach_option_eq(bbfdm, "dmmap", "bridge_port", "bridge_key", ((struct bridging_args *)data)->br_key, s) { + if (prev_s) + DMUCI_DELETE_BY_SECTION(bbfdm, prev_s, NULL, NULL); + prev_s = s; + } + if (prev_s) + DMUCI_DELETE_BY_SECTION(bbfdm, prev_s, NULL, NULL); + reset_br_port( ((struct bridging_args *)data)->br_key); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", ""); + break; + case DEL_ALL: + uci_foreach_option_eq("network", "interface", "type", "bridge", bridge_s) { + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(bridge_s), &dmmap_section); + dmuci_set_value_by_section(bridge_s, "type", ""); + dmuci_get_value_by_section_string(dmmap_section, "bridge_instance", &bridgekey); + dmuci_set_value_by_section(dmmap_section, "bridge_instance", ""); + dmuci_set_value_by_section(dmmap_section, "ip_int_instance", ""); + dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); + uci_path_foreach_option_eq(bbfdm, "dmmap", "bridge_port", "bridge_key", bridgekey, s) { + prev_s = s; + } + if (prev_s) + DMUCI_DELETE_BY_SECTION(bbfdm, prev_s, NULL, NULL); + reset_br_port(bridgekey); + dmuci_set_value_by_section(bridge_s, "ifname", ""); + } + break; + } + return 0; +} + +static int add_br_vlan(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *value, *last_instance, *v, *vlan_name, *name, *last_vid, *vid; + struct uci_section *vlan_s, *dmmap_bridge_vlan; + + check_create_dmmap_package("dmmap_network"); + last_instance = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network", "device", "bridge_vlan_instance", "bridge_key", ((struct bridging_args *)data)->br_key); + dmasprintf(&vlan_name, "vlan%d", last_instance ? atoi(last_instance)+ 1 : 1); + last_vid = get_last_vid(); + dmasprintf(&name, "%s.%d", wan_baseifname, last_vid ? atoi(last_vid)+ 1 : 1001); + dmasprintf(&vid, "%d", last_vid ? atoi(last_vid)+ 1 : 1001); + dmuci_add_section_and_rename("network", "device", &vlan_s, &value); + dmuci_rename_section_by_section(vlan_s, vlan_name); + dmuci_set_value_by_section(vlan_s, "priority", "0"); + dmuci_set_value_by_section(vlan_s, "type", "8021q"); + dmuci_set_value_by_section(vlan_s, "vid", vid); + dmuci_set_value_by_section(vlan_s, "name", name); + dmuci_set_value_by_section(vlan_s, "ifname", wan_baseifname); + dmfree(name); + dmfree(vid); + + dmuci_add_section_bbfdm("dmmap_network", "device", &dmmap_bridge_vlan, &v); + dmuci_set_value_by_section(dmmap_bridge_vlan, "section_name", vlan_name); + dmuci_set_value_by_section(dmmap_bridge_vlan, "bridge_key", ((struct bridging_args *)data)->br_key); + *instance = update_instance_bbfdm(dmmap_bridge_vlan, last_instance, "bridge_vlan_instance"); + return 0; +} + +static int delete_br_vlan(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + char *vid, *ifname, *type; + struct uci_section *prev_s = NULL, *vlan_s=NULL, *dmmap_section; + char new_ifname[128]; + int is_enabled; + + switch (del_action) { + case DEL_INST: + is_enabled = is_bridge_vlan_enabled((struct bridging_vlan_args *)data); + if(is_enabled) + update_br_vlan_ifname((struct bridging_vlan_args *)data, 0); + get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), &dmmap_section); + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("network", "device", vlan_s) { + dmuci_get_value_by_section_string(vlan_s, "type", &type); + if (strcmp(type, "untagged")==0) + continue; + dmuci_get_value_by_section_string(vlan_s, "vid", &vid); + dmuci_get_value_by_section_string(((struct bridging_args *)data)->bridge_sec, "ifname", &ifname); + if(ifname[0] != '\0' && vid[0] != '\0'){ + remove_vid_interfaces_from_ifname(vid, ifname, new_ifname); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", new_ifname); + } + if (prev_s != NULL){ + get_dmmap_section_of_config_section("dmmap_network", "device", section_name(prev_s), &dmmap_section); + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(prev_s, NULL, NULL); + } + prev_s = vlan_s; + } + if (prev_s != NULL){ + get_dmmap_section_of_config_section("dmmap_network", "device", section_name(prev_s), &dmmap_section); + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(prev_s, NULL, NULL); + } + break; + } + return 0; +} + +static int add_br_port(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *value; + struct uci_section *br_port_s; + + int m = get_br_port_last_inst(((struct bridging_args *)data)->br_key); + dmasprintf(instance, "%d", m+1); + DMUCI_ADD_SECTION(bbfdm, "dmmap_bridge_port", "bridge_port", &br_port_s, &value); + dmuci_set_value_by_section(br_port_s, "bridge_key", ((struct bridging_args *)data)->br_key); + dmuci_set_value_by_section(br_port_s, "bridge_port_instance", *instance); + dmuci_set_value_by_section(br_port_s, "mg_port", "false"); + return 0; +} + +static int delete_br_port(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + char *ifname; + char new_ifname[128]; + struct uci_section *s = NULL, *prev_s = NULL, *dmmap_section= NULL; + + switch (del_action) { + case DEL_INST: + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); + if (!dmmap_section) { + dmmap_section = ((struct bridging_port_args *)data)->bridge_port_sec; + dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); + } else { + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_sec, "ifname", &ifname); + if (ifname[0] != '\0') { + remove_interface_from_ifname(((struct bridging_port_args *)data)->ifname, ifname, new_ifname); + dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_sec, "ifname", new_ifname); + } + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); + dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); + } + break; + case DEL_ALL: + uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", ((struct bridging_args *)data)->br_key, s) { + if (prev_s) + DMUCI_DELETE_BY_SECTION(bbfdm, prev_s, NULL, NULL); + prev_s = s; + } + if (prev_s) + DMUCI_DELETE_BY_SECTION(bbfdm, prev_s, NULL, NULL); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", ""); // TO CHECK + break; + } + return 0; +} + +/************************************************************* +* LOWER LAYER +**************************************************************/ +static int check_port_with_ifname (char *ifname, struct uci_section **ss) +{ + struct uci_section *sss, *s; + char *file_config_name; + char *atm_device, *ptm_device; + + dmasprintf(&file_config_name, "%s","/etc/config/dsl"); + + if (check_ifname_is_vlan(ifname)) { + uci_foreach_option_eq("network", "device", "name", ifname, s) { + *ss = s; + break; + } + } else if (strncmp(ifname, "ptm", 3) == 0) { + if (access( file_config_name, F_OK ) != -1) { + uci_foreach_sections("dsl", "ptm-device", sss) { + dmuci_get_value_by_section_string(sss, "device", &ptm_device); + dmasprintf(&ptm_device, "%s.1", ptm_device); + if (strcmp(ifname, ptm_device) == 0) { + uci_foreach_option_eq("network", "device", "name", ifname, s) { + *ss = s; + break; + } + } + } + } + } else if (strncmp(ifname, "atm", 3) == 0) { + if (access( file_config_name, F_OK ) != -1) { + uci_foreach_sections("dsl", "atm-device", sss) { + dmuci_get_value_by_section_string(sss, "device", &atm_device); + dmasprintf(&atm_device, "%s.1", atm_device); + if (strcmp(ifname, atm_device) == 0) { + uci_foreach_option_eq("network", "device", "name", ifname, s) { + *ss = s; + break; + } + } + } + } + } else if (strncmp(ifname, wan_baseifname, strlen(wan_baseifname)) == 0) { + uci_foreach_option_eq("network", "device", "name", ifname, s) { + *ss = s; + break; + } + } else if (strncmp(ifname, "wl", 2) == 0 || strncmp(ifname, "ra", 2) == 0 || strncmp(ifname, "apclii", 6) == 0) { + uci_foreach_option_eq("wireless", "wifi-iface", "ifname", ifname, s) { + *ss = s; + break; + } + } else { + uci_foreach_option_eq("ports", "ethport", "ifname", ifname, s) { + *ss = s; + break; + } + } + return 0; +} + +static int get_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *mg_port, *pch, *spch, *ifname, *ifname_dup, *p, *linker = ""; + char buf[16], plinker[32], lbuf[512] = { 0, 0 }; + struct uci_section *s = NULL; + + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "mg_port", &mg_port); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_sec, "ifname", &ifname); + if (ifname[0] != '\0' && strcmp(mg_port, "true") == 0) { + ifname_dup = dmstrdup(ifname); + p = lbuf; + for (pch = strtok_r(ifname_dup, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { + check_port_with_ifname(pch, &s); + if(s == NULL) + continue; + snprintf(plinker, sizeof(plinker), "%s+%s", section_name(s), pch); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), plinker, value); + if (*value == NULL) + *value = ""; + dmstrappendstr(p, *value); + dmstrappendchr(p, ','); + } + p = p -1; + dmstrappendend(p); + *value = dmstrdup(lbuf); + return 0; + } else { + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "ifname", &linker); + if (strcmp(linker, wan_baseifname) == 0) { + dmasprintf(&linker, "%s.1", linker); + } + if(((struct bridging_port_args *)data)->vlan) { + strncpy(buf, linker, 5); + buf[5] = '\0'; + strcat(buf, "1"); + linker = buf; + } + } + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + adm_entry_get_linker_param(ctx,dm_print_path("%s%cWiFi%cSSID%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cATM%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPTM%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + + if (*value == NULL) + *value = ""; + return 0; +} + +static int set_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker, *ifname, *p, *br_key, *br_pt_inst = "", *mg_port = "false", *vid = NULL; + char *newvalue= NULL; + char new_ifname[256]; + char tmp[16]; + char pr_linker[32]; + struct uci_section *s; + struct uci_section *dmmap_section= NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) + return FAULT_9007; + get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "mg_port", &mg_port); + if (value[strlen(value)-1]!='.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else + adm_entry_get_linker_value(ctx, value, &linker); + if (strcmp(mg_port, "false")!=0 && linker && !check_ifname_exist_in_br_ifname_list(linker)) + return FAULT_9001; + return 0; + case VALUESET: + if (value[strlen(value)-1]!='.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else + adm_entry_get_linker_value(ctx, value, &linker); + //check ifname(linker) doesn't exit in bridges + if (linker && check_ifname_exist_in_br_ifname_list(linker)) { + //save param of current port and copy it to new port + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "bridge_key", &br_key); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "bridge_port_instance", &br_pt_inst); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "mg_port", &mg_port); + //remove old port (ifname) from bridge + if (((struct bridging_port_args *)data)->ifname[0] != 0 && strcmp(((struct bridging_port_args *)data)->ifname, linker) != 0) { + delete_br_port(NULL, ctx, data, instance, DEL_INST); + } + // check if the current port is already linked with VLAN + snprintf(pr_linker, sizeof(pr_linker), "%s+%s", section_name(((struct bridging_port_args *)data)->bridge_port_sec), ((struct bridging_port_args *)data)->ifname); + uci_foreach_option_eq("network", "device", "br_port_linker", pr_linker, s) { + dmuci_get_value_by_section_string(s, "vlan8021q", &vid); + break; + } + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_sec, "ifname", &ifname); + p = new_ifname; + if (ifname[0] != '\0') { + dmstrappendstr(p, ifname); + dmstrappendchr(p, ' '); + } + if(vid && check_ifname_is_not_lan_port(linker) && !strstr (linker, "wl")) { + strncpy(tmp, linker, 5); + tmp[5] = '\0'; + strcat(tmp, vid); + linker = tmp; + dmstrappendstr(p, tmp); + dmstrappendend(p); + uci_foreach_option_eq("network", "device", "br_port_linker", pr_linker, s) { + snprintf(pr_linker, sizeof(pr_linker), "%s+%s", section_name(s), linker); + dmuci_set_value_by_section(s, "br_port_linker", pr_linker); + dmuci_set_value_by_section(s, "ifname", linker); + dmuci_set_value_by_section(s, "penable", "1"); + } + } else { + dmstrappendstr(p, linker); + dmstrappendend(p); + } + dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_sec, "ifname", new_ifname); + //remove old br_port param to the new one + update_port_parameters(linker, br_key, br_pt_inst, mg_port); + if(((struct bridging_port_args *)data)->ifname[0] == '\0') + DMUCI_DELETE_BY_SECTION(bbfdm,((struct bridging_port_args *)data)->bridge_port_sec, NULL, NULL);// delete dmmap section after remove br_port_instance to adequate config + } else { + return FAULT_9005; + } + return 0; + } + return 0; +} + +static int get_vlan_port_vlan_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char linker[8]; + snprintf(linker, sizeof(linker), "vlan%s_%s", ((struct bridging_vlan_args *)data)->vlan_port, ((struct bridging_vlan_args *)data)->br_inst); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) + *value = ""; + return 0; +} + +static int set_vlan_port_vlan_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + return 0; + } + return 0; +} + +static int get_vlan_port_port_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char linker[16], *name; + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "name", &name); + snprintf(linker, sizeof(linker), "%s+%s", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), name); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) + *value = ""; + return 0; +} + +static int set_vlan_port_port_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker = NULL, *vid, *enable, *vifname, *pch, *p, *br_ifname, tmp[8], new_ifname[16]; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + adm_entry_get_linker_value(ctx, value, &linker); + if (!linker) { + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "br_port_linker", ""); + set_br_vlan_enable(refparam, ctx, data, instance, "false", action); + return 0; + } + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "br_port_linker", linker); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vlan8021q", &vid); + pch = strchr(linker, '+') + 1; + if (pch[0] == '\0') { + dmfree(linker); + return 0; + } + if (vid[0] == '\0') { + if (strstr(pch, "atm") || strstr(pch, "ptm") || strstr(pch, wan_baseifname)) { + strncpy(tmp, pch, 4); + tmp[4] ='\0'; + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", tmp); + } + } else { + if (strstr(pch, "atm") || strstr(pch, "ptm") || strstr(pch, wan_baseifname)) { + p = new_ifname; + strncpy(tmp, pch, 4); + tmp[4] ='\0'; + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", tmp); + dmstrappendstr(p, tmp); + dmstrappendchr(p, '.'); + dmstrappendstr(p, vid); + dmstrappendend(p); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", new_ifname); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "penable", &enable);///TO CHECK + // add to bridge ifname if enable = 1 + if (enable[0] == '1') { + vifname = dmstrdup(new_ifname); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", &br_ifname); + p = new_ifname; + if (br_ifname[0] != '\0') { + dmstrappendstr(p, br_ifname); + dmstrappendchr(p, ' '); + } + dmstrappendstr(p, vifname); + dmstrappendend(p); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", new_ifname); + dmfree(vifname); + } + } + } + dmfree(linker); + return 0; + } + return 0; +} + +static int get_br_vlan_untagged(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int set_br_vlan_untagged(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + return 0; + } + return 0; +} + +/************************************************************* +* ENTRY METHOD +**************************************************************/ +/*#Device.Bridging.Bridge.{i}.!UCI:network/interface/dmmap_network*/ +static int browseBridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *br_inst = NULL, *br_inst_last = NULL, *ifname; + struct bridging_args curr_bridging_args = {0}; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_baseifname); + + synchronize_specific_config_sections_with_dmmap_eq("network", "interface", "dmmap_network", "type", "bridge", &dup_list); + list_for_each_entry(p, &dup_list, list) { + br_inst = handle_update_instance(1, dmctx, &br_inst_last, update_instance_alias, 3, p->dmmap_section, "bridge_instance", "bridge_alias"); + dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); + init_bridging_args(&curr_bridging_args, p->config_section, br_inst_last, ifname, br_inst); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_args, br_inst) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static void set_bridge_port_parameters(struct uci_section *dmmap_section, char* bridge_key) +{ + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_section, "bridge_key", bridge_key); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_section, "mg_port", "false"); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_section, "penable", "1"); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_section, "is_dmmap", "false"); +} + +static int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance){ + struct uci_section *new_port = NULL, *ss_atm = NULL, *ss_ptm = NULL; + char *port = NULL, *port_last = NULL, *ifname_dup = NULL, *pch, *spch, *is_dmmap, *file_config_name, *deviceatm, *deviceptm, *atm_device, *ptm_device; + bool find_max = true, found = false; + struct bridging_port_args curr_bridging_port_args = {0}; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + dmasprintf(&file_config_name, "%s","/etc/config/dsl"); + check_create_dmmap_package("dmmap_bridge_port"); + update_section_list_bbfdm("dmmap_bridge_port","bridge_port", "bridge_key", 1, ((struct bridging_args *)prev_data)->br_key, "mg_port", "true", "bridge_port_instance", "1"); + uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", ((struct bridging_args *)prev_data)->br_key, new_port) { + dmuci_get_value_by_section_string(new_port, "is_dmmap", &is_dmmap); + if(strcmp(is_dmmap, "false") !=0 ) { + init_bridging_port_args(&curr_bridging_port_args, new_port, ((struct bridging_args *)prev_data)->bridge_sec, false, ""); + port = handle_update_instance(2, dmctx, &port_last, update_instance_alias_bbfdm, 5, new_port, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) + goto end; + } + } + + if (((struct bridging_args *)prev_data)->ifname[0] == '\0') + return 0; + ifname_dup = dmstrdup(((struct bridging_args *)prev_data)->ifname); + for (pch = strtok_r(ifname_dup, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { + found = false; + + if (!found) + found= synchronize_multi_config_sections_with_dmmap_eq("ports", "ethport", "dmmap_bridge_port", "bridge_port", "ifname", pch, pch, &dup_list); + + if (!found) + found= synchronize_multi_config_sections_with_dmmap_eq("wireless", "wifi-iface", "dmmap_bridge_port", "bridge_port", "ifname", pch, pch, &dup_list); + + if (access( file_config_name, F_OK ) != -1) { + uci_foreach_sections("dsl", "atm-device", ss_atm) { + dmuci_get_value_by_section_string(ss_atm, "device", &deviceatm); + dmasprintf(&atm_device, "%s.1", deviceatm); + if(!found) { + if(strncmp(pch, atm_device, strlen(atm_device))==0) { + found= synchronize_multi_config_sections_with_dmmap_eq("network", "device", "dmmap_bridge_port", "bridge_port", "name", pch, pch, &dup_list); + } + } + } + + uci_foreach_sections("dsl", "ptm-device", ss_ptm) { + dmuci_get_value_by_section_string(ss_ptm, "device", &deviceptm); + dmasprintf(&ptm_device, "%s.1", deviceptm); + if(!found) { + if(strncmp(pch, ptm_device, strlen(ptm_device))==0) { + found= synchronize_multi_config_sections_with_dmmap_eq("network", "device", "dmmap_bridge_port", "bridge_port", "name", pch, pch, &dup_list); + } + } + } + } + + if (!found) { + if(strncmp(pch, wan_baseifname, strlen(wan_baseifname))==0) { + found= synchronize_multi_config_sections_with_dmmap_eq("network", "device", "dmmap_bridge_port", "bridge_port", "name", pch, pch, &dup_list); + } + } + + if (!found) { + if(strncmp(pch, wan_baseifname, 4) == 0 || strncmp(pch, "ptm", 3) == 0 || strncmp(pch, "atm", 3) == 0){ + found= synchronize_multi_config_sections_with_dmmap_eq_diff("network", "device", "dmmap_bridge_port", "bridge_port", "name", pch, "type", "untagged", pch, &dup_list); + } + } + } + + list_for_each_entry(p, &dup_list, list) { + set_bridge_port_parameters(p->dmmap_section, ((struct bridging_args *)prev_data)->br_key); + init_bridging_port_args(&curr_bridging_port_args, p->config_section, ((struct bridging_args *)prev_data)->bridge_sec, false, (char*)p->additional_attribute); + port = handle_update_instance(2, dmctx, &port_last, update_instance_alias_bbfdm, 5, p->dmmap_section, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) + goto end; + } + free_dmmap_config_dup_list(&dup_list); +end: + dmfree(ifname_dup); + return 0; +} + +/*#Device.Bridging.Bridge.{i}.VLAN.!UCI:network/device/dmmap_network*/ +static int browseBridgeVlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *vlan = NULL, *vlan_last = NULL, *type, *is_lan = NULL; + struct bridging_vlan_args curr_bridging_vlan_args = {0}; + struct bridging_args *br_args = (struct bridging_args *)prev_data; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + dmuci_get_value_by_section_string(br_args->bridge_sec, "is_lan", &is_lan); + if (is_lan == NULL || strcmp(is_lan, "1") != 0) { + synchronize_specific_config_sections_with_dmmap("network", "device", "dmmap_network", &dup_list); + list_for_each_entry(p, &dup_list, list) { + if(!p->config_section) + goto end; + //Check if VLAN or NOT + dmuci_get_value_by_section_string(p->config_section, "type", &type); + if (strcmp(type, "untagged") != 0) { + dmuci_set_value_by_section(p->dmmap_section, "bridge_key", br_args->br_key); + vlan = handle_update_instance(2, dmctx, &vlan_last, update_instance_alias, 3, p->dmmap_section, "bridge_vlan_instance", "bridge_vlan_alias"); + init_bridging_vlan_args(&curr_bridging_vlan_args, p->config_section, br_args->bridge_sec, vlan_last, br_args->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_vlan_args, vlan) == DM_STOP) + goto end; + } + } + free_dmmap_config_dup_list(&dup_list); + } +end: + return 0; +} + +/*#Device.Bridging.Bridge.{i}.VLANPort.!UCI:network/device/dmmap_network*/ +static int browseBridgeVlanPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *vlan = NULL, *vlan_last = NULL, *type, *is_lan = NULL; + struct bridging_vlan_args curr_bridging_vlan_args = {0}; + struct bridging_args *br_args = (struct bridging_args *)prev_data; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + dmuci_get_value_by_section_string(br_args->bridge_sec, "is_lan", &is_lan); + if (is_lan == NULL || strcmp(is_lan, "1") != 0) { + synchronize_specific_config_sections_with_dmmap("network", "device", "dmmap_network", &dup_list); + list_for_each_entry(p, &dup_list, list) { + if(!p->config_section) + goto end; + //Check if VLAN or NOT + dmuci_get_value_by_section_string(p->config_section, "type", &type); + if (strcmp(type, "untagged") != 0) { + dmuci_set_value_by_section(p->dmmap_section, "bridge_key", br_args->br_key); + vlan = handle_update_instance(2, dmctx, &vlan_last, update_instance_alias, 3, p->dmmap_section, "bridge_vlan_instance", "bridge_vlan_alias"); + init_bridging_vlan_args(&curr_bridging_vlan_args, p->config_section, br_args->bridge_sec, vlan_last, br_args->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_vlan_args, vlan) == DM_STOP) + goto end; + } + } + free_dmmap_config_dup_list(&dup_list); + } +end: + return 0; +} + /*** Bridging. ***/ DMOBJ tBridgingObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -123,1699 +1845,3 @@ DMLEAF tBridgingBridgeVLANPortParams[] = { {"Untagged", &DMWRITE, DMT_BOOL, get_br_vlan_untagged, set_br_vlan_untagged, NULL, NULL, BBFDM_BOTH}, {0} }; - -/************************************************************************** -* LINKER -***************************************************************************/ -int get_linker_br_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct bridging_port_args *)data)->bridge_port_sec) { - dmasprintf(linker, "%s+%s", section_name(((struct bridging_port_args *)data)->bridge_port_sec), ((struct bridging_port_args *)data)->ifname); - return 0; - } - *linker = ""; - return 0; -} - -int get_linker_br_vlan(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct bridging_vlan_args *)data)->vlan_port) { - dmasprintf(linker, "vlan%s_%s", ((struct bridging_vlan_args *)data)->vlan_port, ((struct bridging_vlan_args *)data)->br_inst); - return 0; - } - *linker = ""; - return 0; -} -/************************************************************************** -* INIT -***************************************************************************/ -static inline int init_bridging_args(struct bridging_args *args, struct uci_section *s, char *last_instance, char *ifname, char *br_instance) -{ - args->bridge_sec = s; - args->br_key = last_instance; - args->ifname = ifname; - args->br_inst = br_instance; - return 0; -} - -static inline int init_bridging_port_args(struct bridging_port_args *args, struct uci_section *s, struct uci_section *bs, bool vlan, char *ifname) -{ - args->bridge_port_sec = s; - args->bridge_sec = bs; - args->vlan = vlan; - args->ifname = ifname; - return 0; -} - -static inline int init_bridging_vlan_args(struct bridging_vlan_args *args, struct uci_section *s, struct uci_section *bs, char *vlan_port, char *br_inst) -{ - args->bridge_vlan_sec = s; - args->bridge_sec = bs; - args->vlan_port = vlan_port; - args->br_inst = br_inst; - return 0; -} - -/************************************************************************** -* INSTANCE MG -***************************************************************************/ -char *get_last_vid(void) -{ - struct uci_section *vlan_s; - char *vid = NULL, *type; - int num_vid = 0; - - uci_foreach_sections("network", "device", vlan_s) { - if(!vlan_s) - break; - dmuci_get_value_by_section_string(vlan_s, "type", &type); - if (strcmp(type, "untagged") == 0) - continue; - dmuci_get_value_by_section_string(vlan_s, "vid", &vid); - if (atoi(vid) > num_vid) - num_vid = atoi(vid); - dmasprintf(&vid, "%d", num_vid); - } - return vid; -} - -int check_ifname_exist_in_br_ifname_list(char *ifname) -{ - char *br_ifname_list, *br_ifname_dup, *pch, *spch; - struct uci_section *s; - - uci_foreach_option_eq("network", "interface", "type", "bridge", s) { - dmuci_get_value_by_section_string(s, "ifname", &br_ifname_list); - if (br_ifname_list[0] == '\0') - return 0; - br_ifname_dup = dmstrdup(br_ifname_list); - for (pch = strtok_r(br_ifname_dup, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { - if (strcmp(pch, ifname) == 0) - return 1; - } - } - return 0; -} - -int get_br_port_last_inst(char *br_key) -{ - char *tmp; - int instance, max = 1; - struct uci_section *s; - - uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", br_key, s) { - dmuci_get_value_by_section_string(s, "bridge_port_instance", &tmp); - if (tmp[0] == '\0') - continue; - instance = atoi(tmp); - if (instance > max) max = instance; - } - return max; -} - -int reset_br_port(char *br_key) -{ - struct uci_section *s, *prev_s = NULL; - - uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", br_key, s) { - if (prev_s) - dmuci_delete_by_section(prev_s, NULL, NULL); - prev_s = s; - } - if (prev_s) dmuci_delete_by_section(prev_s, NULL, NULL); - return 0; -} - -int check_ifname_is_not_lan_port(char *ifname) -{ - struct uci_section *s; - - if (!strstr(ifname, wan_baseifname)) { - uci_foreach_option_eq("ports", "ethport", "ifname", ifname, s) { - return 0; - } - } - return 1; -} - -int update_port_parameters(char *linker, char *br_key, char *br_pt_inst, char *mg_port) -{ - struct uci_section *s, *dmmap_section; - - if (check_ifname_is_vlan(linker)) { - uci_foreach_option_eq("network", "device", "ifname", linker, s) { - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); - dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); - dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); - break; - } - } else if (strncmp(linker, "ptm", 3) == 0) { - uci_foreach_option_eq("dsl", "ptm-device", "device", linker, s) { - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); - dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); - dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); - break; - } - } else if (strncmp(linker, "atm", 3) == 0) { - uci_foreach_option_eq("dsl", "atm-device", "device", linker, s) { - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); - dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); - dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); - break; - } - } else if (strncmp(linker, "wl", 2) == 0) { - uci_foreach_option_eq("wireless", "wifi-iface", "ifname", linker, s) { - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); - dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); - dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); - break; - } - } else if (strncmp(linker, "eth0", 4) == 0) { - uci_foreach_option_eq("network", "device", "name", linker, s) { - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); - dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); - dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); - break; - } - } else { - uci_foreach_option_eq("ports", "ethport", "ifname", linker, s) { - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section); - dmuci_set_value_by_section(dmmap_section, "bridge_key", br_key); - dmuci_set_value_by_section(dmmap_section, "bridge_port_instance", br_pt_inst); - dmuci_set_value_by_section(dmmap_section, "mg_port", mg_port); - break; - } - } - return 0; -} - -static int is_br_port_enabled(struct bridging_port_args *curr_arg) -{ - struct uci_section *vlan_sec = curr_arg->bridge_port_sec, *br_sec = curr_arg->bridge_sec; - char *ifname, *br_ifname, *ifname_dup; - - dmuci_get_value_by_section_string(br_sec, "ifname", &br_ifname); - dmuci_get_value_by_section_string(vlan_sec, "name", &ifname); - ifname_dup = dmstrdup(br_ifname); - if(ifname != NULL && ifname[0] != '\0') { - if (is_strword_in_optionvalue(ifname_dup, ifname)) - return 1; - } - return 0; -} - -static int update_br_port_ifname(struct bridging_port_args *curr_arg, int status) -{ - char ifname_dup[128], *ptr, *baseifname, *ifname, *start, *end; - struct uci_section *vlan_sec = curr_arg->bridge_port_sec, *br_sec = curr_arg->bridge_sec; - int pos=0; - dmuci_get_value_by_section_string(br_sec, "ifname", &ifname); - dmuci_get_value_by_section_string(vlan_sec, "name", &baseifname); - ptr = ifname_dup; - dmstrappendstr(ptr, ifname); - dmstrappendend(ptr); - if(status){ - if (is_strword_in_optionvalue(ifname_dup, baseifname)) return 0; - if (ifname_dup[0] != '\0') dmstrappendchr(ptr, ' '); - dmstrappendstr(ptr, baseifname); - dmstrappendend(ptr); - } else { - if (is_strword_in_optionvalue(ifname_dup, baseifname)) { - start = strstr(ifname_dup, baseifname); - end = start + strlen(baseifname); - if (start != ifname_dup) { - start--; - pos=1; - } - memmove(start, start + strlen(baseifname)+pos, strlen(end) + 1); - } - } - dmuci_set_value_by_section(br_sec, "ifname", ifname_dup); - return 0; -} - -/************************************************************************** -*SET & GET BRIDGING PARAMETERS -***************************************************************************/ -int get_Max_Bridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "20"; - return 0; -} - -int get_Max_DBridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "20"; - return 0; -} - -int get_Max_QBridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "20"; - return 0; -} - -int get_Max_VLAN_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "20"; - return 0; -} - -int get_Max_Provider_Bridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "0"; - return 0; -} - -int get_Max_Filter_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "0"; - return 0; -} - -/*#Device.Bridging.BridgeNumberOfEntries!UCI:network/interface/*/ -int get_Bridge_Number_Of_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_foreach_option_eq("network", "interface", "type", "bridge", s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -/*#Device.Bridging.Bridge.{i}.Enable!UBUS:network.interface/status/interface,@Name/up*/ -int get_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct bridging_args *)data)->bridge_sec), String}}, 1, &res); - DM_ASSERT(res, *value = "false"); - *value = dmjson_get_value(res, 1, "up"); - return 0; -} - -int set_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmubus_call_set("network.interface", b ? "up" : "down", UBUS_ARGS{{"interface", section_name(((struct bridging_args *)data)->bridge_sec), String}}, 1); - return 0; - } - return 0; -} - -/*#Device.Bridging.Bridge.{i}.Status!UBUS:network.interface/status/interface,@Name/up*/ -int get_br_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct bridging_args *)data)->bridge_sec), String}}, 1, &res); - DM_ASSERT(res, *value = "Disabled"); - *value = dmjson_get_value(res, 1, "up"); - if (strcmp(*value, "true") == 0) - *value = "Enabled"; - else - *value = "Disabled"; - return 0; -} - -int get_br_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "802.1Q-2011"; - return 0; -} - -int set_br_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, BridgeStandard, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - return 0; - } - return 0; -} - -int get_br_port_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", instance, s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -int get_br_vlan_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "device", "bridge_key", instance, s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -int get_br_vlan_port_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "device", "bridge_key", instance, s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -int get_br_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct bridging_args *)data)->bridge_sec, "ifname", value); - return 0; -} - -int set_br_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", value); - return 0; - } - return 0; -} - -/*#Device.Bridging.Bridge.{i}.Port.{i}.Enable!UBUS:network.device/status/name,@Name/speed*/ -int get_br_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - char *speed, *val; - struct uci_section *wifi_device_s; - - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "ifname", value); - if(strncmp(*value, "wl", 2) == 0 || strncmp(*value, "ra", 2) == 0 || strncmp(*value, "apclii", 6) == 0) { - uci_foreach_option_eq("wireless", "wifi-iface", "ifname", *value, wifi_device_s) { - dmuci_get_value_by_section_string(wifi_device_s, "disabled", &val); - if ((val[0] == '\0') || (val[0] == '0')) - *value = "true"; - else - *value = "false"; - return 0; - } - } - dmubus_call("network.device", "status", UBUS_ARGS{{"name", *value, String}}, 1, &res); - DM_ASSERT(res, *value = "false"); - speed = dmjson_get_value(res, 1, "speed"); - if(*speed != '\0') - *value = "true"; - else - *value = "false"; - return 0; -} - -int set_br_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - return 0; - } - return 0; -} - -/*#Device.Bridging.Bridge.{i}.Port.{i}.Status!UBUS:network.device/status/name,@Name/speed*/ -int get_br_port_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - bool b; - get_br_port_enable(refparam, ctx, data, instance, value); - string_to_bool(*value, &b); - *value = b ? "Up" : "Down"; - return 0; -} - -int get_br_port_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", value); - return 0; -} - -/*#Device.Bridging.Bridge.{i}.Port.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ -int get_br_port_last_change(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct bridging_port_args *)data)->bridge_sec), String}}, 1, &res); - DM_ASSERT(res, *value = "0"); - *value = dmjson_get_value(res, 1, "uptime"); - if((*value)[0] == '\0') - *value = "0"; - return 0; -} - -int get_br_port_management(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); - if (!dmmap_section) - dmmap_section = ((struct bridging_port_args *)data)->bridge_port_sec; - dmuci_get_value_by_section_string(dmmap_section, "mg_port", value); - return 0; -} - -int set_br_port_management(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - return 0; - } - return 0; -} - -static struct uci_section *check_if_ifname_is_tagged(char *ifname) -{ - struct uci_section *s; - uci_foreach_option_eq("network", "device", "name", ifname, s) { - return s; - } - return NULL; -} - -int get_br_port_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *name; - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); - if (check_if_ifname_is_tagged(name) != NULL) - *value = "CustomerVLANPort"; - else - *value = ""; - return 0; -} - -int set_br_port_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, BridgeType, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - return 0; - } - return 0; -} - -int get_br_port_default_user_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - char *name, *type; - - *value = ""; - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); - s = check_if_ifname_is_tagged(name); - if (s != NULL) { - dmuci_get_value_by_section_string(s, "type", &type); - if (strcmp(type, "untagged") != 0) - dmuci_get_value_by_section_string(s, "priority", value); - } - return 0; -} - -int set_br_port_default_user_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *s = NULL; - char *name, *type; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "0", "7")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); - s = check_if_ifname_is_tagged(name); - if (s != NULL) { - dmuci_get_value_by_section_string(s, "type", &type); - if (strcmp(type, "untagged") != 0) - dmuci_set_value_by_section(s, "priority", value); - } - return 0; - } - return 0; -} - -int get_br_port_priority_regeneration(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "0,1,2,3,4,5,6,7"; - return 0; -} - -int set_br_port_priority_regeneration(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt_list(value, "8", "8", NULL, "0", "7")) - return FAULT_9007; - return 0; - case VALUESET: - return 0; - } - return 0; -} - -int get_br_port_port_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *name; - - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); - if (check_if_ifname_is_tagged(name) != NULL) - *value = "Forwarding"; - else - *value = "Disabled"; - return 0; -} - -int get_br_port_pvid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - char *name, *type; - - *value = "1"; - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); - s = check_if_ifname_is_tagged(name); - if (s != NULL) { - dmuci_get_value_by_section_string(s, "type", &type); - if (strcmp(type, "untagged") != 0) - dmuci_get_value_by_section_string(s, "vid", value); - } - return 0; -} - -int set_br_port_pvid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *s = NULL; - char *name, *type, *ifname, *new_name; - int is_enabled; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "1", "4094")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name); - s = check_if_ifname_is_tagged(name); - if (s != NULL) { - dmuci_get_value_by_section_string(s, "type", &type); - if (strcmp(type, "untagged") != 0) { - dmuci_set_value_by_section(s, "vid", value); - dmuci_get_value_by_section_string(s, "ifname", &ifname); - dmasprintf(&new_name, "%s.%s", ifname, value); - is_enabled = is_br_port_enabled((struct bridging_port_args *)data); - if (is_enabled) - update_br_port_ifname((struct bridging_port_args *)data, 0); - dmuci_set_value_by_section(s, "name", new_name); - if (is_enabled) - update_br_port_ifname((struct bridging_port_args *)data, 1); - dmfree(new_name); - } - } - return 0; - } - return 0; -} - -int get_br_port_tpid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *type; - - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "type", &type); - if (strcmp(type, "8021q") == 0 || strcmp(type, "untagged") == 0) - *value = "33024"; - else if (strcmp(type, "8021ad") == 0) - *value = "34984"; - else - *value = "37120"; - return 0; -} - -int set_br_port_tpid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (strcmp(value, "33024") == 0) - dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_port_sec, "type", "8021q"); - else if (strcmp(value, "34984") == 0) - dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_port_sec, "type", "8021ad"); - return 0; - } - return 0; -} - -/************************************************************************** -* GET STAT -***************************************************************************/ -static int br_get_sysfs(const struct bridging_port_args *br, const char *name, char **value) -{ - char *device; - - dmuci_get_value_by_section_string(br->bridge_port_sec, "ifname", &device); - return get_net_device_sysfs(device, name, value); -} - -/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/ -int get_br_port_stats_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return br_get_sysfs(data, "statistics/tx_bytes", value); -} - -/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/ -int get_br_port_stats_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return br_get_sysfs(data, "statistics/rx_bytes", value); -} - -/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/ -int get_br_port_stats_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return br_get_sysfs(data, "statistics/tx_packets", value); -} - -/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/ -int get_br_port_stats_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return br_get_sysfs(data, "statistics/rx_packets", value); -} - -/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.ErrorsSent!UBUS:network.device/status/name,@Name/statistics.tx_errors*/ -int get_br_port_stats_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return br_get_sysfs(data, "statistics/tx_errors", value); -} - -/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.ErrorsReceived!UBUS:network.device/status/name,@Name/statistics.rx_errors*/ -int get_br_port_stats_rx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return br_get_sysfs(data, "statistics/rx_errors", value); -} - -int get_br_port_stats_tx_unicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_br_port_stats_rx_unicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.DiscardPacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_dropped*/ -int get_br_port_stats_tx_discard_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return br_get_sysfs(data, "statistics/tx_dropped", value); -} - -/*#Device.Bridging.Bridge.{i}.Port.{i}.Stats.DiscardPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_dropped*/ -int get_br_port_stats_rx_discard_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return br_get_sysfs(data, "statistics/rx_dropped", value); -} - -int get_br_port_stats_tx_multicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_br_port_stats_rx_multicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return br_get_sysfs(data, "statistics/multicast", value); -} - -int get_br_port_stats_tx_broadcast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_br_port_stats_rx_broadcast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_br_port_stats_rx_unknown_proto_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -static int is_bridge_vlan_enabled(struct bridging_vlan_args *curr_arg) -{ - struct uci_section *vlan_sec = curr_arg->bridge_vlan_sec, *br_sec = curr_arg->bridge_sec; - char *ifname, *br_ifname, *ifname_dup; - - dmuci_get_value_by_section_string(br_sec, "ifname", &br_ifname); - dmuci_get_value_by_section_string(vlan_sec, "name", &ifname); - ifname_dup = dmstrdup(br_ifname); - if (ifname != NULL && ifname[0] != '\0') { - if (is_strword_in_optionvalue(ifname_dup, ifname)) - return 1; - } - return 0; -} - -static int update_br_vlan_ifname(struct bridging_vlan_args *curr_arg, int status) -{ - char ifname_dup[128], *ptr, *baseifname, *ifname, *start, *end; - struct uci_section *vlan_sec = curr_arg->bridge_vlan_sec, *br_sec = curr_arg->bridge_sec; - int pos=0; - dmuci_get_value_by_section_string(br_sec, "ifname", &ifname); - dmuci_get_value_by_section_string(vlan_sec, "name", &baseifname); - ptr = ifname_dup; - dmstrappendstr(ptr, ifname); - dmstrappendend(ptr); - if (status) { - if (is_strword_in_optionvalue(ifname_dup, baseifname)) return 0; - if (ifname_dup[0] != '\0') dmstrappendchr(ptr, ' '); - dmstrappendstr(ptr, baseifname); - dmstrappendend(ptr); - } else { - if (is_strword_in_optionvalue(ifname_dup, baseifname)) { - start = strstr(ifname_dup, baseifname); - end = start + strlen(baseifname); - if (start != ifname_dup) { - start--; - pos=1; - } - memmove(start, start + strlen(baseifname)+pos, strlen(end) + 1); - } - } - dmuci_set_value_by_section(br_sec, "ifname", ifname_dup); - return 0; -} - -int get_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "false"; - int status = is_bridge_vlan_enabled((struct bridging_vlan_args *)data); - if (status) - *value = "true"; - return 0; -} - -int set_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - int is_enabled; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - is_enabled = is_bridge_vlan_enabled((struct bridging_vlan_args *)data); - if (b && !is_enabled) { - update_br_vlan_ifname((struct bridging_vlan_args *)data, 1); - } - if (!b && is_enabled) { - update_br_vlan_ifname((struct bridging_vlan_args *)data, 0); - } - return 0; - } - return 0; -} - -int get_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec)); - return 0; -} - -int set_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_rename_section_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, value); - return 0; - } - return 0; -} - -int get_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vid", value); - return 0; -} - -int set_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *name, *ifname; - int is_enabled; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "1", "4094")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vid", value); - dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", &ifname); - dmasprintf(&name, "%s.%s", ifname, value); - is_enabled = is_bridge_vlan_enabled((struct bridging_vlan_args *)data); - if(is_enabled) - update_br_vlan_ifname((struct bridging_vlan_args *)data, 0); - dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "name", name); - if(is_enabled) - update_br_vlan_ifname((struct bridging_vlan_args *)data, 1); - dmfree(name); - return 0; - } - return 0; -} - -int get_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "priority", value); - return 0; -} - -int set_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - //TODO - return 0; - case VALUESET: - dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "priority", value); - return 0; - } - return 0; -} -/************************************************************* -* GET SET ALIAS -**************************************************************/ -int get_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct bridging_args *)data)->bridge_sec), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "bridge_alias", value); - return 0; -} - -int set_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct bridging_args *)data)->bridge_sec), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "bridge_alias", value); - return 0; - } - return 0; -} - -int get_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); - if (!dmmap_section) - dmmap_section = ((struct bridging_port_args *)data)->bridge_port_sec; - dmuci_get_value_by_section_string(dmmap_section, "bridge_port_alias", value); - return 0; -} - -int set_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); - if(!dmmap_section) - dmmap_section = ((struct bridging_port_args *)data)->bridge_port_sec; - dmuci_set_value_by_section(dmmap_section, "bridge_port_alias", value); - return 0; - } - return 0; -} - -int get_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "bridge_vlan_alias", value); - return 0; -} - -int set_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "bridge_vlan_alias", value); - return 0; - } - return 0; -} - -/************************************************************* -* ADD DELETE OBJECT -**************************************************************/ -int add_bridge(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *last_inst, *v; - char bridge_name[16], ib[8]; - char *p = bridge_name; - struct uci_section* dmmap_bridge = NULL; - - last_inst = get_last_instance_lev2_bbfdm("network", "interface", "dmmap_network", "bridge_instance", "type", "bridge"); - snprintf(ib, sizeof(ib), "%d", last_inst ? atoi(last_inst)+1 : 1); - dmstrappendstr(p, "bridge_0_"); - dmstrappendstr(p, ib); - dmstrappendend(p); - dmuci_set_value("network", bridge_name, "", "interface"); - dmuci_set_value("network", bridge_name, "type", "bridge"); - dmuci_set_value("network", bridge_name, "proto", "dhcp"); - - dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_bridge, &v); - dmuci_set_value_by_section(dmmap_bridge, "section_name", bridge_name); - *instance = update_instance_bbfdm(dmmap_bridge, last_inst, "bridge_instance"); - - update_section_list(DMMAP,"bridge_port", "bridge_key", 1, ib, "mg_port", "true", "bridge_port_instance", "1"); - return 0; -} - -int delete_bridge(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *s = NULL, *prev_s = NULL, *bridge_s, *dmmap_section = NULL; - char *bridgekey = NULL; - - switch (del_action) { - case DEL_INST: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct bridging_args *)data)->bridge_sec), &dmmap_section); - dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "type", ""); - dmuci_set_value_by_section(dmmap_section, "bridge_instance", ""); - dmuci_set_value_by_section(dmmap_section, "ip_int_instance", ""); - dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); - uci_path_foreach_option_eq(bbfdm, "dmmap", "bridge_port", "bridge_key", ((struct bridging_args *)data)->br_key, s) { - if (prev_s) - DMUCI_DELETE_BY_SECTION(bbfdm, prev_s, NULL, NULL); - prev_s = s; - } - if (prev_s) - DMUCI_DELETE_BY_SECTION(bbfdm, prev_s, NULL, NULL); - reset_br_port( ((struct bridging_args *)data)->br_key); - dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", ""); - break; - case DEL_ALL: - uci_foreach_option_eq("network", "interface", "type", "bridge", bridge_s) { - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(bridge_s), &dmmap_section); - dmuci_set_value_by_section(bridge_s, "type", ""); - dmuci_get_value_by_section_string(dmmap_section, "bridge_instance", &bridgekey); - dmuci_set_value_by_section(dmmap_section, "bridge_instance", ""); - dmuci_set_value_by_section(dmmap_section, "ip_int_instance", ""); - dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); - uci_path_foreach_option_eq(bbfdm, "dmmap", "bridge_port", "bridge_key", bridgekey, s) { - prev_s = s; - } - if (prev_s) - DMUCI_DELETE_BY_SECTION(bbfdm, prev_s, NULL, NULL); - reset_br_port(bridgekey); - dmuci_set_value_by_section(bridge_s, "ifname", ""); - } - break; - } - return 0; -} - -int add_br_vlan(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *value, *last_instance, *v, *vlan_name, *name, *last_vid, *vid; - struct uci_section *vlan_s, *dmmap_bridge_vlan; - - check_create_dmmap_package("dmmap_network"); - last_instance = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network", "device", "bridge_vlan_instance", "bridge_key", ((struct bridging_args *)data)->br_key); - dmasprintf(&vlan_name, "vlan%d", last_instance ? atoi(last_instance)+ 1 : 1); - last_vid = get_last_vid(); - dmasprintf(&name, "%s.%d", wan_baseifname, last_vid ? atoi(last_vid)+ 1 : 1001); - dmasprintf(&vid, "%d", last_vid ? atoi(last_vid)+ 1 : 1001); - dmuci_add_section_and_rename("network", "device", &vlan_s, &value); - dmuci_rename_section_by_section(vlan_s, vlan_name); - dmuci_set_value_by_section(vlan_s, "priority", "0"); - dmuci_set_value_by_section(vlan_s, "type", "8021q"); - dmuci_set_value_by_section(vlan_s, "vid", vid); - dmuci_set_value_by_section(vlan_s, "name", name); - dmuci_set_value_by_section(vlan_s, "ifname", wan_baseifname); - dmfree(name); - dmfree(vid); - - dmuci_add_section_bbfdm("dmmap_network", "device", &dmmap_bridge_vlan, &v); - dmuci_set_value_by_section(dmmap_bridge_vlan, "section_name", vlan_name); - dmuci_set_value_by_section(dmmap_bridge_vlan, "bridge_key", ((struct bridging_args *)data)->br_key); - *instance = update_instance_bbfdm(dmmap_bridge_vlan, last_instance, "bridge_vlan_instance"); - return 0; -} - -int delete_br_vlan(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - char *vid, *ifname, *type; - struct uci_section *prev_s = NULL, *vlan_s=NULL, *dmmap_section; - char new_ifname[128]; - int is_enabled; - - switch (del_action) { - case DEL_INST: - is_enabled = is_bridge_vlan_enabled((struct bridging_vlan_args *)data); - if(is_enabled) - update_br_vlan_ifname((struct bridging_vlan_args *)data, 0); - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), &dmmap_section); - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, NULL, NULL); - break; - case DEL_ALL: - uci_foreach_sections("network", "device", vlan_s) { - dmuci_get_value_by_section_string(vlan_s, "type", &type); - if (strcmp(type, "untagged")==0) - continue; - dmuci_get_value_by_section_string(vlan_s, "vid", &vid); - dmuci_get_value_by_section_string(((struct bridging_args *)data)->bridge_sec, "ifname", &ifname); - if(ifname[0] != '\0' && vid[0] != '\0'){ - remove_vid_interfaces_from_ifname(vid, ifname, new_ifname); - dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", new_ifname); - } - if (prev_s != NULL){ - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(prev_s), &dmmap_section); - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(prev_s, NULL, NULL); - } - prev_s = vlan_s; - } - if (prev_s != NULL){ - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(prev_s), &dmmap_section); - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(prev_s, NULL, NULL); - } - break; - } - return 0; -} - -int add_br_port(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *value; - struct uci_section *br_port_s; - - int m = get_br_port_last_inst(((struct bridging_args *)data)->br_key); - dmasprintf(instance, "%d", m+1); - DMUCI_ADD_SECTION(bbfdm, "dmmap_bridge_port", "bridge_port", &br_port_s, &value); - dmuci_set_value_by_section(br_port_s, "bridge_key", ((struct bridging_args *)data)->br_key); - dmuci_set_value_by_section(br_port_s, "bridge_port_instance", *instance); - dmuci_set_value_by_section(br_port_s, "mg_port", "false"); - return 0; -} - -int delete_br_port(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - char *ifname; - char new_ifname[128]; - struct uci_section *s = NULL, *prev_s = NULL, *dmmap_section= NULL; - - switch (del_action) { - case DEL_INST: - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); - if (!dmmap_section) { - dmmap_section = ((struct bridging_port_args *)data)->bridge_port_sec; - dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); - } else { - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_sec, "ifname", &ifname); - if (ifname[0] != '\0') { - remove_interface_from_ifname(((struct bridging_port_args *)data)->ifname, ifname, new_ifname); - dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_sec, "ifname", new_ifname); - } - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); - dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); - } - break; - case DEL_ALL: - uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", ((struct bridging_args *)data)->br_key, s) { - if (prev_s) - DMUCI_DELETE_BY_SECTION(bbfdm, prev_s, NULL, NULL); - prev_s = s; - } - if (prev_s) - DMUCI_DELETE_BY_SECTION(bbfdm, prev_s, NULL, NULL); - dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", ""); // TO CHECK - break; - } - return 0; -} - -/************************************************************* -* LOWER LAYER -**************************************************************/ -int check_port_with_ifname (char *ifname, struct uci_section **ss) -{ - struct uci_section *sss, *s; - char *file_config_name; - char *atm_device, *ptm_device; - - dmasprintf(&file_config_name, "%s","/etc/config/dsl"); - - if (check_ifname_is_vlan(ifname)) { - uci_foreach_option_eq("network", "device", "name", ifname, s) { - *ss = s; - break; - } - } else if (strncmp(ifname, "ptm", 3) == 0) { - if (access( file_config_name, F_OK ) != -1) { - uci_foreach_sections("dsl", "ptm-device", sss) { - dmuci_get_value_by_section_string(sss, "device", &ptm_device); - dmasprintf(&ptm_device, "%s.1", ptm_device); - if (strcmp(ifname, ptm_device) == 0) { - uci_foreach_option_eq("network", "device", "name", ifname, s) { - *ss = s; - break; - } - } - } - } - } else if (strncmp(ifname, "atm", 3) == 0) { - if (access( file_config_name, F_OK ) != -1) { - uci_foreach_sections("dsl", "atm-device", sss) { - dmuci_get_value_by_section_string(sss, "device", &atm_device); - dmasprintf(&atm_device, "%s.1", atm_device); - if (strcmp(ifname, atm_device) == 0) { - uci_foreach_option_eq("network", "device", "name", ifname, s) { - *ss = s; - break; - } - } - } - } - } else if (strncmp(ifname, wan_baseifname, strlen(wan_baseifname)) == 0) { - uci_foreach_option_eq("network", "device", "name", ifname, s) { - *ss = s; - break; - } - } else if (strncmp(ifname, "wl", 2) == 0 || strncmp(ifname, "ra", 2) == 0 || strncmp(ifname, "apclii", 6) == 0) { - uci_foreach_option_eq("wireless", "wifi-iface", "ifname", ifname, s) { - *ss = s; - break; - } - } else { - uci_foreach_option_eq("ports", "ethport", "ifname", ifname, s) { - *ss = s; - break; - } - } - return 0; -} - -int get_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *mg_port, *pch, *spch, *ifname, *ifname_dup, *p, *linker = ""; - char buf[16], plinker[32], lbuf[512] = { 0, 0 }; - struct uci_section *s = NULL; - - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "mg_port", &mg_port); - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_sec, "ifname", &ifname); - if (ifname[0] != '\0' && strcmp(mg_port, "true") == 0) { - ifname_dup = dmstrdup(ifname); - p = lbuf; - for (pch = strtok_r(ifname_dup, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { - check_port_with_ifname(pch, &s); - if(s == NULL) - continue; - snprintf(plinker, sizeof(plinker), "%s+%s", section_name(s), pch); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), plinker, value); - if (*value == NULL) - *value = ""; - dmstrappendstr(p, *value); - dmstrappendchr(p, ','); - } - p = p -1; - dmstrappendend(p); - *value = dmstrdup(lbuf); - return 0; - } else { - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "ifname", &linker); - if (strcmp(linker, wan_baseifname) == 0) { - dmasprintf(&linker, "%s.1", linker); - } - if(((struct bridging_port_args *)data)->vlan) { - strncpy(buf, linker, 5); - buf[5] = '\0'; - strcat(buf, "1"); - linker = buf; - } - } - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - adm_entry_get_linker_param(ctx,dm_print_path("%s%cWiFi%cSSID%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cATM%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cPTM%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - - if (*value == NULL) - *value = ""; - return 0; -} - -int set_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *linker, *ifname, *p, *br_key, *br_pt_inst = "", *mg_port = "false", *vid = NULL; - char *newvalue= NULL; - char new_ifname[256]; - char tmp[16]; - char pr_linker[32]; - struct uci_section *s; - struct uci_section *dmmap_section= NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) - return FAULT_9007; - get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section); - dmuci_get_value_by_section_string(dmmap_section, "mg_port", &mg_port); - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); - if (strcmp(mg_port, "false")!=0 && linker && !check_ifname_exist_in_br_ifname_list(linker)) - return FAULT_9001; - return 0; - case VALUESET: - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); - //check ifname(linker) doesn't exit in bridges - if (linker && check_ifname_exist_in_br_ifname_list(linker)) { - //save param of current port and copy it to new port - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "bridge_key", &br_key); - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "bridge_port_instance", &br_pt_inst); - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "mg_port", &mg_port); - //remove old port (ifname) from bridge - if (((struct bridging_port_args *)data)->ifname[0] != 0 && strcmp(((struct bridging_port_args *)data)->ifname, linker) != 0) { - delete_br_port(NULL, ctx, data, instance, DEL_INST); - } - // check if the current port is already linked with VLAN - snprintf(pr_linker, sizeof(pr_linker), "%s+%s", section_name(((struct bridging_port_args *)data)->bridge_port_sec), ((struct bridging_port_args *)data)->ifname); - uci_foreach_option_eq("network", "device", "br_port_linker", pr_linker, s) { - dmuci_get_value_by_section_string(s, "vlan8021q", &vid); - break; - } - dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_sec, "ifname", &ifname); - p = new_ifname; - if (ifname[0] != '\0') { - dmstrappendstr(p, ifname); - dmstrappendchr(p, ' '); - } - if(vid && check_ifname_is_not_lan_port(linker) && !strstr (linker, "wl")) { - strncpy(tmp, linker, 5); - tmp[5] = '\0'; - strcat(tmp, vid); - linker = tmp; - dmstrappendstr(p, tmp); - dmstrappendend(p); - uci_foreach_option_eq("network", "device", "br_port_linker", pr_linker, s) { - snprintf(pr_linker, sizeof(pr_linker), "%s+%s", section_name(s), linker); - dmuci_set_value_by_section(s, "br_port_linker", pr_linker); - dmuci_set_value_by_section(s, "ifname", linker); - dmuci_set_value_by_section(s, "penable", "1"); - } - } else { - dmstrappendstr(p, linker); - dmstrappendend(p); - } - dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_sec, "ifname", new_ifname); - //remove old br_port param to the new one - update_port_parameters(linker, br_key, br_pt_inst, mg_port); - if(((struct bridging_port_args *)data)->ifname[0] == '\0') - DMUCI_DELETE_BY_SECTION(bbfdm,((struct bridging_port_args *)data)->bridge_port_sec, NULL, NULL);// delete dmmap section after remove br_port_instance to adequate config - } else { - return FAULT_9005; - } - return 0; - } - return 0; -} - -int get_vlan_port_vlan_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char linker[8]; - snprintf(linker, sizeof(linker), "vlan%s_%s", ((struct bridging_vlan_args *)data)->vlan_port, ((struct bridging_vlan_args *)data)->br_inst); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; - return 0; -} - -int set_vlan_port_vlan_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - return 0; - } - return 0; -} - -int get_vlan_port_port_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char linker[16], *name; - dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "name", &name); - snprintf(linker, sizeof(linker), "%s+%s", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), name); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; - return 0; -} - -int set_vlan_port_port_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *linker = NULL, *vid, *enable, *vifname, *pch, *p, *br_ifname, tmp[8], new_ifname[16]; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); - if (!linker) { - dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "br_port_linker", ""); - set_br_vlan_enable(refparam, ctx, data, instance, "false", action); - return 0; - } - dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "br_port_linker", linker); - dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vlan8021q", &vid); - pch = strchr(linker, '+') + 1; - if (pch[0] == '\0') { - dmfree(linker); - return 0; - } - if (vid[0] == '\0') { - if (strstr(pch, "atm") || strstr(pch, "ptm") || strstr(pch, wan_baseifname)) { - strncpy(tmp, pch, 4); - tmp[4] ='\0'; - dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", tmp); - } - } else { - if (strstr(pch, "atm") || strstr(pch, "ptm") || strstr(pch, wan_baseifname)) { - p = new_ifname; - strncpy(tmp, pch, 4); - tmp[4] ='\0'; - dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", tmp); - dmstrappendstr(p, tmp); - dmstrappendchr(p, '.'); - dmstrappendstr(p, vid); - dmstrappendend(p); - dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", new_ifname); - dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "penable", &enable);///TO CHECK - // add to bridge ifname if enable = 1 - if (enable[0] == '1') { - vifname = dmstrdup(new_ifname); - dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", &br_ifname); - p = new_ifname; - if (br_ifname[0] != '\0') { - dmstrappendstr(p, br_ifname); - dmstrappendchr(p, ' '); - } - dmstrappendstr(p, vifname); - dmstrappendend(p); - dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", new_ifname); - dmfree(vifname); - } - } - } - dmfree(linker); - return 0; - } - return 0; -} - -int get_br_vlan_untagged(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int set_br_vlan_untagged(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - return 0; - } - return 0; -} - -/************************************************************* -* ENTRY METHOD -**************************************************************/ -/*#Device.Bridging.Bridge.{i}.!UCI:network/interface/dmmap_network*/ -int browseBridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *br_inst = NULL, *br_inst_last = NULL, *ifname; - struct bridging_args curr_bridging_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_baseifname); - - synchronize_specific_config_sections_with_dmmap_eq("network", "interface", "dmmap_network", "type", "bridge", &dup_list); - list_for_each_entry(p, &dup_list, list) { - br_inst = handle_update_instance(1, dmctx, &br_inst_last, update_instance_alias, 3, p->dmmap_section, "bridge_instance", "bridge_alias"); - dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); - init_bridging_args(&curr_bridging_args, p->config_section, br_inst_last, ifname, br_inst); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_args, br_inst) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -static void set_bridge_port_parameters(struct uci_section *dmmap_section, char* bridge_key) -{ - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_section, "bridge_key", bridge_key); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_section, "mg_port", "false"); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_section, "penable", "1"); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_section, "is_dmmap", "false"); -} - -int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance){ - struct uci_section *new_port = NULL, *ss_atm = NULL, *ss_ptm = NULL; - char *port = NULL, *port_last = NULL, *ifname_dup = NULL, *pch, *spch, *is_dmmap, *file_config_name, *deviceatm, *deviceptm, *atm_device, *ptm_device; - bool find_max = true, found = false; - struct bridging_port_args curr_bridging_port_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - dmasprintf(&file_config_name, "%s","/etc/config/dsl"); - check_create_dmmap_package("dmmap_bridge_port"); - update_section_list_bbfdm("dmmap_bridge_port","bridge_port", "bridge_key", 1, ((struct bridging_args *)prev_data)->br_key, "mg_port", "true", "bridge_port_instance", "1"); - uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", ((struct bridging_args *)prev_data)->br_key, new_port) { - dmuci_get_value_by_section_string(new_port, "is_dmmap", &is_dmmap); - if(strcmp(is_dmmap, "false") !=0 ) { - init_bridging_port_args(&curr_bridging_port_args, new_port, ((struct bridging_args *)prev_data)->bridge_sec, false, ""); - port = handle_update_instance(2, dmctx, &port_last, update_instance_alias_bbfdm, 5, new_port, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) - goto end; - } - } - - if (((struct bridging_args *)prev_data)->ifname[0] == '\0') - return 0; - ifname_dup = dmstrdup(((struct bridging_args *)prev_data)->ifname); - for (pch = strtok_r(ifname_dup, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { - found = false; - - if (!found) - found= synchronize_multi_config_sections_with_dmmap_eq("ports", "ethport", "dmmap_bridge_port", "bridge_port", "ifname", pch, pch, &dup_list); - - if (!found) - found= synchronize_multi_config_sections_with_dmmap_eq("wireless", "wifi-iface", "dmmap_bridge_port", "bridge_port", "ifname", pch, pch, &dup_list); - - if (access( file_config_name, F_OK ) != -1) { - uci_foreach_sections("dsl", "atm-device", ss_atm) { - dmuci_get_value_by_section_string(ss_atm, "device", &deviceatm); - dmasprintf(&atm_device, "%s.1", deviceatm); - if(!found) { - if(strncmp(pch, atm_device, strlen(atm_device))==0) { - found= synchronize_multi_config_sections_with_dmmap_eq("network", "device", "dmmap_bridge_port", "bridge_port", "name", pch, pch, &dup_list); - } - } - } - - uci_foreach_sections("dsl", "ptm-device", ss_ptm) { - dmuci_get_value_by_section_string(ss_ptm, "device", &deviceptm); - dmasprintf(&ptm_device, "%s.1", deviceptm); - if(!found) { - if(strncmp(pch, ptm_device, strlen(ptm_device))==0) { - found= synchronize_multi_config_sections_with_dmmap_eq("network", "device", "dmmap_bridge_port", "bridge_port", "name", pch, pch, &dup_list); - } - } - } - } - - if (!found) { - if(strncmp(pch, wan_baseifname, strlen(wan_baseifname))==0) { - found= synchronize_multi_config_sections_with_dmmap_eq("network", "device", "dmmap_bridge_port", "bridge_port", "name", pch, pch, &dup_list); - } - } - - if (!found) { - if(strncmp(pch, wan_baseifname, 4) == 0 || strncmp(pch, "ptm", 3) == 0 || strncmp(pch, "atm", 3) == 0){ - found= synchronize_multi_config_sections_with_dmmap_eq_diff("network", "device", "dmmap_bridge_port", "bridge_port", "name", pch, "type", "untagged", pch, &dup_list); - } - } - } - - list_for_each_entry(p, &dup_list, list) { - set_bridge_port_parameters(p->dmmap_section, ((struct bridging_args *)prev_data)->br_key); - init_bridging_port_args(&curr_bridging_port_args, p->config_section, ((struct bridging_args *)prev_data)->bridge_sec, false, (char*)p->additional_attribute); - port = handle_update_instance(2, dmctx, &port_last, update_instance_alias_bbfdm, 5, p->dmmap_section, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) - goto end; - } - free_dmmap_config_dup_list(&dup_list); -end: - dmfree(ifname_dup); - return 0; -} - -/*#Device.Bridging.Bridge.{i}.VLAN.!UCI:network/device/dmmap_network*/ -int browseBridgeVlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *vlan = NULL, *vlan_last = NULL, *type, *is_lan = NULL; - struct bridging_vlan_args curr_bridging_vlan_args = {0}; - struct bridging_args *br_args = (struct bridging_args *)prev_data; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - dmuci_get_value_by_section_string(br_args->bridge_sec, "is_lan", &is_lan); - if (is_lan == NULL || strcmp(is_lan, "1") != 0) { - synchronize_specific_config_sections_with_dmmap("network", "device", "dmmap_network", &dup_list); - list_for_each_entry(p, &dup_list, list) { - if(!p->config_section) - goto end; - //Check if VLAN or NOT - dmuci_get_value_by_section_string(p->config_section, "type", &type); - if (strcmp(type, "untagged") != 0) { - dmuci_set_value_by_section(p->dmmap_section, "bridge_key", br_args->br_key); - vlan = handle_update_instance(2, dmctx, &vlan_last, update_instance_alias, 3, p->dmmap_section, "bridge_vlan_instance", "bridge_vlan_alias"); - init_bridging_vlan_args(&curr_bridging_vlan_args, p->config_section, br_args->bridge_sec, vlan_last, br_args->br_key); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_vlan_args, vlan) == DM_STOP) - goto end; - } - } - free_dmmap_config_dup_list(&dup_list); - } -end: - return 0; -} - -/*#Device.Bridging.Bridge.{i}.VLANPort.!UCI:network/device/dmmap_network*/ -int browseBridgeVlanPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *vlan = NULL, *vlan_last = NULL, *type, *is_lan = NULL; - struct bridging_vlan_args curr_bridging_vlan_args = {0}; - struct bridging_args *br_args = (struct bridging_args *)prev_data; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - dmuci_get_value_by_section_string(br_args->bridge_sec, "is_lan", &is_lan); - if (is_lan == NULL || strcmp(is_lan, "1") != 0) { - synchronize_specific_config_sections_with_dmmap("network", "device", "dmmap_network", &dup_list); - list_for_each_entry(p, &dup_list, list) { - if(!p->config_section) - goto end; - //Check if VLAN or NOT - dmuci_get_value_by_section_string(p->config_section, "type", &type); - if (strcmp(type, "untagged") != 0) { - dmuci_set_value_by_section(p->dmmap_section, "bridge_key", br_args->br_key); - vlan = handle_update_instance(2, dmctx, &vlan_last, update_instance_alias, 3, p->dmmap_section, "bridge_vlan_instance", "bridge_vlan_alias"); - init_bridging_vlan_args(&curr_bridging_vlan_args, p->config_section, br_args->bridge_sec, vlan_last, br_args->br_key); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_vlan_args, vlan) == DM_STOP) - goto end; - } - } - free_dmmap_config_dup_list(&dup_list); - } -end: - return 0; -} diff --git a/dmtree/tr181/bridging.h b/dmtree/tr181/bridging.h index 4ed25e6a..ef9eb1d9 100644 --- a/dmtree/tr181/bridging.h +++ b/dmtree/tr181/bridging.h @@ -15,31 +15,6 @@ #include -struct bridging_args -{ - struct uci_section *bridge_sec; - char *br_key; - char *ifname; - char *br_inst; -}; - -struct bridging_port_args -{ - struct uci_section *bridge_port_sec; - struct uci_section *bridge_sec; - bool vlan; - char *ifname; -}; - -struct bridging_vlan_args -{ - struct uci_section *bridge_vlan_sec; - struct uci_section *bridge_sec; - char *vlan_port; - char *br_inst; - char *ifname; -}; - extern DMOBJ tBridgingObj[]; extern DMLEAF tBridgingParams[]; extern DMOBJ tBridgingBridgeObj[]; @@ -50,97 +25,4 @@ extern DMLEAF tBridgingBridgeVLANPortParams[]; extern DMOBJ tBridgingBridgePortObj[]; extern DMLEAF tBridgingBridgePortStatsParams[]; -int browseBridgeVlanPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseBridgeVlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseBridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int get_linker_br_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); -int get_linker_br_vlan(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); - -int add_bridge(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delete_bridge(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int add_br_vlan(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delete_br_vlan(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int add_br_port(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delete_br_port(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_Max_Bridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_Max_DBridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_Max_QBridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_Max_VLAN_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_Max_Provider_Bridge_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_Max_Filter_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_Bridge_Number_Of_Entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_port_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_vlan_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_vlan_port_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_br_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_port_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_port_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_last_change(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_management(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_port_management(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_port_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_port_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_port_default_user_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_port_default_user_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_port_priority_regeneration(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_port_priority_regeneration(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_port_port_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_pvid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_port_pvid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_port_tpid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_port_tpid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_br_port_stats_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_rx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_tx_unicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_rx_unicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_tx_discard_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_rx_discard_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_tx_multicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_rx_multicast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_tx_broadcast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_rx_broadcast_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_br_port_stats_rx_unknown_proto_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_vlan_port_vlan_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_vlan_port_vlan_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_vlan_port_port_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_vlan_port_port_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_br_vlan_untagged(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_br_vlan_untagged(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/deviceinfo.c b/dmtree/tr181/deviceinfo.c index 05e8fc0b..83950c34 100644 --- a/dmtree/tr181/deviceinfo.c +++ b/dmtree/tr181/deviceinfo.c @@ -11,6 +11,598 @@ #include "deviceinfo.h" +/* + *DeviceInfo. functions + */ +static char *get_deviceid_manufacturer() +{ + char *v; + dmuci_get_option_value_string("cwmp","cpe","manufacturer", &v); + return v; +} + +static char *get_deviceid_manufactureroui() +{ + char *v, *mac = NULL, str[16], macreadfile[18] = {0}; + json_object *res; + FILE *nvrammac = NULL; + + dmuci_get_option_value_string("cwmp", "cpe", "override_oui", &v); + if (v[0] == '\0') { + dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); + if (!(res)) { + db_get_value_string("hw", "board", "basemac", &mac); + if (!mac || strlen(mac) == 0) { + if ((nvrammac = fopen("/proc/nvram/BaseMacAddr", "r")) == NULL) { + mac = NULL; + } else { + fscanf(nvrammac,"%17[^\n]", macreadfile); + macreadfile[17] = '\0'; + sscanf(macreadfile,"%2c %2c %2c", str, str+2, str+4); + str[6] = '\0'; + v = dmstrdup(str); // MEM WILL BE FREED IN DMMEMCLEAN + fclose(nvrammac); + return v; + } + } + } else + mac = dmjson_get_value(res, 2, "system", "basemac"); + + if(mac) { + size_t ln = strlen(mac); + if (ln < 17) goto not_found; + sscanf (mac,"%2c:%2c:%2c",str,str+2,str+4); + str[6] = '\0'; + v = dmstrdup(str); // MEM WILL BE FREED IN DMMEMCLEAN + return v; + } else + goto not_found; + } + return v; +not_found: + v = ""; + return v; +} + +static char *get_deviceid_productclass() +{ + char *v; + dmuci_get_option_value_string("cwmp", "cpe", "override_productclass", &v); + if (v[0] == '\0') { + db_get_value_string("hw", "board", "iopVerBoard", &v); + return v; + } + return v; +} + +static char *get_deviceid_serialnumber() +{ + char *v; + db_get_value_string("hw", "board", "serial_number", &v); + return v; +} + +static char *get_softwareversion() +{ + char *v; + db_get_value_string("hw", "board", "iopVersion", &v); + return v; +} + +/*#Device.DeviceInfo.Manufacturer!UCI:cwmp/cwmp,cpe/manufacturer*/ +static int get_device_manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_deviceid_manufacturer(); + return 0; +} + +/*#Device.DeviceInfo.ManufacturerOUI!UCI:cwmp/cwmp,cpe/override_oui*/ +static int get_device_manufactureroui(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_deviceid_manufactureroui(); + return 0; +} + +/*#Device.DeviceInfo.ProductClass!UCI:cwmp/cwmp,cpe/override_productclass*/ +static int get_device_productclass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_deviceid_productclass(); + return 0; +} + +static int get_device_serialnumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_deviceid_serialnumber(); + return 0; +} + +static int get_device_softwareversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_softwareversion(); + return 0; +} + +static int get_device_hardwareversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + db_get_value_string("hw", "board", "hardwareVersion", value); + return 0; +} + +static int get_device_routermodel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + db_get_value_string("hw", "board", "routerModel", value); + return 0; +} + +static int get_device_info_uptime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + FILE *fp = NULL; + char *pch, *spch, buf[64]; + *value = "0"; + + fp = fopen(UPTIME, "r"); + if (fp != NULL) { + fgets(buf, 64, fp); + pch = strtok_r(buf, ".", &spch); + if (pch) + *value = dmstrdup(pch); // MEM WILL BE FREED IN DMMEMCLEAN + fclose(fp); + } + return 0; +} + +static int get_device_devicelog(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ""; + int i = 0, nbrlines = 4; + char buff[512], *msg = NULL; + int len = klogctl(3 , buff, sizeof(buff) - 1); /* read ring buffer */ + if (len <= 0) + return 0; + buff[len] = '\0'; + char *p = buff; + while (*p) { + if (*p == '<') { + *p = '('; + if (p == buff || *(p-1) == '\n') { + if(msg == NULL) msg = p; + i++; + if (i == nbrlines) { + *(p-1) = '\0'; + break; + } + } + } + else if (*p == '>') + *p = ')'; + p++; + } + if (msg == NULL) + *value = ""; + else + *value = dmstrdup(msg);// MEM WILL BE FREED IN DMMEMCLEAN + return 0; +} + +static int get_device_specversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1.0"; + return 0; +} + +/*#Device.DeviceInfo.ProvisioningCode!UCI:cwmp/cwmp,cpe/provisioning_code*/ +static int get_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "cpe", "provisioning_code", value); + return 0; +} + +static int set_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp", "cpe", "provisioning_code", value); + return 0; + } + return 0; +} + +static int get_base_mac_addr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 2, "system", "basemac"); + return 0; +} + +static int get_device_memory_bank(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("router.system", "memory_bank", UBUS_ARGS{{}}, 0, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "code"); + return 0; +} + +static int set_device_memory_bank(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + //TODO + return 0; + case VALUESET: + dmubus_call_set("router.system", "memory_bank", UBUS_ARGS{{"bank", value, Integer}}, 1); + return 0; + } + return 0; +} + +static int get_catv_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *catv; + dmuci_get_option_value_string("catv", "catv", "enable", &catv); + if (strcmp(catv, "on") == 0) + *value = "1"; + else + *value = "0"; + return 0; +} + +static int set_device_catvenabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value("catv", "catv", "enable", b ? "on" : "off"); + return 0; + } + return 0; +} + +static int get_catv_optical_input_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("catv", "vpd", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "VPD"); + return 0; +} + +static int get_catv_rf_output_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("catv", "rf", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "RF"); + return 0; +} + +static int get_catv_temperature(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("catv", "temp", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "Temperature"); + return 0; +} + +static int get_catv_voltage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("catv", "vcc", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "VCC"); + return 0; +} + +static int get_vcf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); + return 0; +} + +static int get_vcf_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "version", value); + return 0; +} + +static int get_vcf_date(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + DIR *dir; + struct dirent *d_file; + struct stat attr; + char path[128]; + char date[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"]; + + *value = ""; + dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); + if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) { + while ((d_file = readdir (dir)) != NULL) { + if(strcmp(*value, d_file->d_name) == 0) { + snprintf(path, sizeof(path), DEFAULT_CONFIG_DIR"%s", d_file->d_name); + stat(path, &attr); + strftime(date, sizeof(date), "%Y-%m-%dT%H:%M:%S.000Z", localtime(&attr.st_mtime)); + *value = dmstrdup(date); + } + } + closedir (dir); + } + return 0; +} + +static int get_vcf_backup_restore(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "backup_restore", value); + return 0; +} + +static int get_vcf_desc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "description", value); + return 0; +} + +static int get_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "vcf_alias", value); + return 0; +} + +static int set_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "vcf_alias", value); + return 0; + } + return 0; +} + +static int lookup_vcf_name(char *instance, char **value) +{ + struct uci_section *s = NULL; + uci_path_foreach_option_eq(bbfdm, DMMAP, "vcf", "vcf_instance", instance, s) { + dmuci_get_value_by_section_string(s, "name", value); + } + return 0; +} + +static int check_file_dir(char *name) +{ + DIR *dir; + struct dirent *d_file; + if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) { + while ((d_file = readdir (dir)) != NULL) { + if (strcmp(name, d_file->d_name) == 0) { + closedir(dir); + return 1; + } + } + closedir(dir); + } + return 0; +} + +static int get_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "vlf_alias", value); + return 0; +} + +static int set_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "vlf_alias", value); + return 0; + } + return 0; +} + +static int get_vlf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "log_file", value); + return 0; +} + +static int get_vlf_max_size (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "log_size", value); + *value = (**value) ? *value : "0"; + return 0; +} + +static int get_vlf_persistent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +/*#Device.DeviceInfo.MemoryStatus.Total!UBUS:router.system/info//memoryKB.total*/ +static int get_memory_status_total(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); + DM_ASSERT(res, *value = "0"); + *value = dmjson_get_value(res, 2, "memoryKB", "total"); + return 0; +} + +/*#Device.DeviceInfo.MemoryStatus.Free!UBUS:router.system/info//memoryKB.free*/ +static int get_memory_status_free(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); + DM_ASSERT(res, *value = "0"); + *value = dmjson_get_value(res, 2, "memoryKB", "free"); + return 0; +} + +/*#Device.DeviceInfo.ProcessStatus.CPUUsage!UBUS:router.system/info//system.cpu_per*/ +static int get_process_cpu_usage(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); + DM_ASSERT(res, *value = "0"); + *value = dmjson_get_value(res, 2, "system", "cpu_per"); + return 0; +} + +static int get_process_number_of_entries(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *processes = NULL; + int nbre_process = 0; + + dmubus_call("router.system", "processes", UBUS_ARGS{}, 0, &res); + if (res) { + json_object_object_get_ex(res, "processes", &processes); + if (processes) + nbre_process = json_object_array_length(processes); + } + dmasprintf(value, "%d", nbre_process); + return 0; +} + +static int get_process_pid(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "pid"); + return 0; +} + +static int get_process_command(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "command"); + return 0; +} + +static int get_process_size(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "vsz"); + return 0; +} + +static int get_process_priority(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "priority"); + return 0; +} + +static int get_process_cpu_time(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "cputime"); + return 0; +} + +static int get_process_state(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "state"); + return 0; +} + +static int browsePocessEntriesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *processes = NULL, *arrobj = NULL; + char *idx, *idx_last = NULL; + int id = 0, i = 0; + + dmubus_call("router.system", "processes", UBUS_ARGS{}, 0, &res); + if (res) { + dmjson_foreach_obj_in_array(res, arrobj, processes, i, 1, "processes") { + idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)processes, idx) == DM_STOP) + break; + } + } + return 0; +} + +static int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *vcf = NULL, *vcf_last = NULL, *name; + struct uci_section *s = NULL, *del_sec = NULL; + DIR *dir; + struct dirent *d_file; + + if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) { + while ((d_file = readdir (dir)) != NULL) { + if(d_file->d_name[0] == '.') + continue; + update_section_list(DMMAP,"vcf", "name", 1, d_file->d_name, NULL, NULL, "backup_restore", "1"); + } + closedir (dir); + } + uci_path_foreach_sections(bbfdm, DMMAP, "vcf", s) { + dmuci_get_value_by_section_string(s, "name", &name); + if(del_sec) { + DMUCI_DELETE_BY_SECTION(bbfdm, del_sec, NULL, NULL); + del_sec = NULL; + } + if (check_file_dir(name) == 0) { + del_sec = s; + continue; + } + vcf = handle_update_instance(1, dmctx, &vcf_last, update_instance_alias_bbfdm, 3, s, "vcf_instance", "vcf_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, vcf) == DM_STOP) + break; + } + if(del_sec) + DMUCI_DELETE_BY_SECTION(bbfdm, del_sec, NULL, NULL); + return 0; +} + +//Browse VendorLogFile instances +static int browseVlfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *sys_log_sec, *dm_sec; + char *log_file,*log_size; + int i = 1; + + uci_foreach_sections("system", "system", sys_log_sec) { + if (!sys_log_sec) + break; + dmuci_get_value_by_section_string(sys_log_sec, "log_file", &log_file); + dmuci_get_value_by_section_string(sys_log_sec, "log_size", &log_size); + uci_path_foreach_sections(bbfdm, "dmmap", "vlf", dm_sec) { + if (dm_sec) + break; + } + if (!dm_sec) { + update_section_list(DMMAP,"vlf", NULL, i++, NULL, "log_file", log_file, "log_size", log_size); + } else { + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dm_sec, "log_file", log_file); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dm_sec, "log_size", log_size); + } + } + uci_path_foreach_sections(bbfdm, "dmmap", "vlf", dm_sec) { + char *instance, *last_instance = NULL; + + instance = handle_update_instance(1, dmctx, &last_instance, update_instance_alias_bbfdm, 3, dm_sec, "vlf_instance", "vlf_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)dm_sec, instance) == DM_STOP){ + break; + } + } + return 0; +} + /* *** Device.DeviceInfo. *** */ DMOBJ tDeviceInfoObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -107,595 +699,3 @@ DMLEAF tDeviceInfoVendorLogFileParams[] = { {"Persistent", &DMREAD, DMT_BOOL, get_vlf_persistent, NULL, NULL, NULL, BBFDM_BOTH}, {0} }; - -/* - *DeviceInfo. functions - */ -char *get_deviceid_manufacturer() -{ - char *v; - dmuci_get_option_value_string("cwmp","cpe","manufacturer", &v); - return v; -} - -char *get_deviceid_manufactureroui() -{ - char *v, *mac = NULL, str[16], macreadfile[18] = {0}; - json_object *res; - FILE *nvrammac = NULL; - - dmuci_get_option_value_string("cwmp", "cpe", "override_oui", &v); - if (v[0] == '\0') { - dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); - if (!(res)) { - db_get_value_string("hw", "board", "basemac", &mac); - if (!mac || strlen(mac) == 0) { - if ((nvrammac = fopen("/proc/nvram/BaseMacAddr", "r")) == NULL) { - mac = NULL; - } else { - fscanf(nvrammac,"%17[^\n]", macreadfile); - macreadfile[17] = '\0'; - sscanf(macreadfile,"%2c %2c %2c", str, str+2, str+4); - str[6] = '\0'; - v = dmstrdup(str); // MEM WILL BE FREED IN DMMEMCLEAN - fclose(nvrammac); - return v; - } - } - } else - mac = dmjson_get_value(res, 2, "system", "basemac"); - - if(mac) { - size_t ln = strlen(mac); - if (ln < 17) goto not_found; - sscanf (mac,"%2c:%2c:%2c",str,str+2,str+4); - str[6] = '\0'; - v = dmstrdup(str); // MEM WILL BE FREED IN DMMEMCLEAN - return v; - } else - goto not_found; - } - return v; -not_found: - v = ""; - return v; -} - -char *get_deviceid_productclass() -{ - char *v; - dmuci_get_option_value_string("cwmp", "cpe", "override_productclass", &v); - if (v[0] == '\0') { - db_get_value_string("hw", "board", "iopVerBoard", &v); - return v; - } - return v; -} - -char *get_deviceid_serialnumber() -{ - char *v; - db_get_value_string("hw", "board", "serial_number", &v); - return v; -} - -char *get_softwareversion() -{ - char *v; - db_get_value_string("hw", "board", "iopVersion", &v); - return v; -} - -/*#Device.DeviceInfo.Manufacturer!UCI:cwmp/cwmp,cpe/manufacturer*/ -int get_device_manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_deviceid_manufacturer(); - return 0; -} - -/*#Device.DeviceInfo.ManufacturerOUI!UCI:cwmp/cwmp,cpe/override_oui*/ -int get_device_manufactureroui(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_deviceid_manufactureroui(); - return 0; -} - -/*#Device.DeviceInfo.ProductClass!UCI:cwmp/cwmp,cpe/override_productclass*/ -int get_device_productclass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_deviceid_productclass(); - return 0; -} - -int get_device_serialnumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_deviceid_serialnumber(); - return 0; -} - -int get_device_softwareversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_softwareversion(); - return 0; -} - -int get_device_hardwareversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - db_get_value_string("hw", "board", "hardwareVersion", value); - return 0; -} - -int get_device_routermodel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - db_get_value_string("hw", "board", "routerModel", value); - return 0; -} - -int get_device_info_uptime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - FILE *fp = NULL; - char *pch, *spch, buf[64]; - *value = "0"; - - fp = fopen(UPTIME, "r"); - if (fp != NULL) { - fgets(buf, 64, fp); - pch = strtok_r(buf, ".", &spch); - if (pch) - *value = dmstrdup(pch); // MEM WILL BE FREED IN DMMEMCLEAN - fclose(fp); - } - return 0; -} - -int get_device_devicelog(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ""; - int i = 0, nbrlines = 4; - char buff[512], *msg = NULL; - int len = klogctl(3 , buff, sizeof(buff) - 1); /* read ring buffer */ - if (len <= 0) - return 0; - buff[len] = '\0'; - char *p = buff; - while (*p) { - if (*p == '<') { - *p = '('; - if (p == buff || *(p-1) == '\n') { - if(msg == NULL) msg = p; - i++; - if (i == nbrlines) { - *(p-1) = '\0'; - break; - } - } - } - else if (*p == '>') - *p = ')'; - p++; - } - if (msg == NULL) - *value = ""; - else - *value = dmstrdup(msg);// MEM WILL BE FREED IN DMMEMCLEAN - return 0; -} - -int get_device_specversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1.0"; - return 0; -} - -/*#Device.DeviceInfo.ProvisioningCode!UCI:cwmp/cwmp,cpe/provisioning_code*/ -int get_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "cpe", "provisioning_code", value); - return 0; -} - -int set_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp", "cpe", "provisioning_code", value); - return 0; - } - return 0; -} - -int get_base_mac_addr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 2, "system", "basemac"); - return 0; -} - -int get_device_memory_bank(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("router.system", "memory_bank", UBUS_ARGS{{}}, 0, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "code"); - return 0; -} - -int set_device_memory_bank(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - //TODO - return 0; - case VALUESET: - dmubus_call_set("router.system", "memory_bank", UBUS_ARGS{{"bank", value, Integer}}, 1); - return 0; - } - return 0; -} - -int get_catv_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *catv; - dmuci_get_option_value_string("catv", "catv", "enable", &catv); - if (strcmp(catv, "on") == 0) - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_device_catvenabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value("catv", "catv", "enable", b ? "on" : "off"); - return 0; - } - return 0; -} - -int get_catv_optical_input_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("catv", "vpd", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "VPD"); - return 0; -} - -int get_catv_rf_output_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("catv", "rf", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "RF"); - return 0; -} - -int get_catv_temperature(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("catv", "temp", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "Temperature"); - return 0; -} - -int get_catv_voltage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("catv", "vcc", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "VCC"); - return 0; -} - -int get_vcf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); - return 0; -} - -int get_vcf_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "version", value); - return 0; -} - -int get_vcf_date(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - DIR *dir; - struct dirent *d_file; - struct stat attr; - char path[128]; - char date[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"]; - - *value = ""; - dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); - if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) { - while ((d_file = readdir (dir)) != NULL) { - if(strcmp(*value, d_file->d_name) == 0) { - snprintf(path, sizeof(path), DEFAULT_CONFIG_DIR"%s", d_file->d_name); - stat(path, &attr); - strftime(date, sizeof(date), "%Y-%m-%dT%H:%M:%S.000Z", localtime(&attr.st_mtime)); - *value = dmstrdup(date); - } - } - closedir (dir); - } - return 0; -} - -int get_vcf_backup_restore(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "backup_restore", value); - return 0; -} - -int get_vcf_desc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "description", value); - return 0; -} - -int get_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "vcf_alias", value); - return 0; -} - -int set_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "vcf_alias", value); - return 0; - } - return 0; -} - -int lookup_vcf_name(char *instance, char **value) -{ - struct uci_section *s = NULL; - uci_path_foreach_option_eq(bbfdm, DMMAP, "vcf", "vcf_instance", instance, s) { - dmuci_get_value_by_section_string(s, "name", value); - } - return 0; -} - -int check_file_dir(char *name) -{ - DIR *dir; - struct dirent *d_file; - if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) { - while ((d_file = readdir (dir)) != NULL) { - if (strcmp(name, d_file->d_name) == 0) { - closedir(dir); - return 1; - } - } - closedir(dir); - } - return 0; -} - -int get_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "vlf_alias", value); - return 0; -} - -int set_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "vlf_alias", value); - return 0; - } - return 0; -} - -int get_vlf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "log_file", value); - return 0; -} - -int get_vlf_max_size (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "log_size", value); - *value = (**value) ? *value : "0"; - return 0; -} - -int get_vlf_persistent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "0"; - return 0; -} - -/*#Device.DeviceInfo.MemoryStatus.Total!UBUS:router.system/info//memoryKB.total*/ -int get_memory_status_total(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); - DM_ASSERT(res, *value = "0"); - *value = dmjson_get_value(res, 2, "memoryKB", "total"); - return 0; -} - -/*#Device.DeviceInfo.MemoryStatus.Free!UBUS:router.system/info//memoryKB.free*/ -int get_memory_status_free(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); - DM_ASSERT(res, *value = "0"); - *value = dmjson_get_value(res, 2, "memoryKB", "free"); - return 0; -} - -/*#Device.DeviceInfo.ProcessStatus.CPUUsage!UBUS:router.system/info//system.cpu_per*/ -int get_process_cpu_usage(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); - DM_ASSERT(res, *value = "0"); - *value = dmjson_get_value(res, 2, "system", "cpu_per"); - return 0; -} - -int get_process_number_of_entries(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res = NULL, *processes = NULL; - int nbre_process = 0; - - dmubus_call("router.system", "processes", UBUS_ARGS{}, 0, &res); - if (res) { - json_object_object_get_ex(res, "processes", &processes); - if (processes) - nbre_process = json_object_array_length(processes); - } - dmasprintf(value, "%d", nbre_process); - return 0; -} - -int get_process_pid(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "pid"); - return 0; -} - -int get_process_command(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "command"); - return 0; -} - -int get_process_size(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "vsz"); - return 0; -} - -int get_process_priority(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "priority"); - return 0; -} - -int get_process_cpu_time(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "cputime"); - return 0; -} - -int get_process_state(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "state"); - return 0; -} - -int browsePocessEntriesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - json_object *res = NULL, *processes = NULL, *arrobj = NULL; - char *idx, *idx_last = NULL; - int id = 0, i = 0; - - dmubus_call("router.system", "processes", UBUS_ARGS{}, 0, &res); - if (res) { - dmjson_foreach_obj_in_array(res, arrobj, processes, i, 1, "processes") { - idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)processes, idx) == DM_STOP) - break; - } - } - return 0; -} - -int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *vcf = NULL, *vcf_last = NULL, *name; - struct uci_section *s = NULL, *del_sec = NULL; - DIR *dir; - struct dirent *d_file; - - if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) { - while ((d_file = readdir (dir)) != NULL) { - if(d_file->d_name[0] == '.') - continue; - update_section_list(DMMAP,"vcf", "name", 1, d_file->d_name, NULL, NULL, "backup_restore", "1"); - } - closedir (dir); - } - uci_path_foreach_sections(bbfdm, DMMAP, "vcf", s) { - dmuci_get_value_by_section_string(s, "name", &name); - if(del_sec) { - DMUCI_DELETE_BY_SECTION(bbfdm, del_sec, NULL, NULL); - del_sec = NULL; - } - if (check_file_dir(name) == 0) { - del_sec = s; - continue; - } - vcf = handle_update_instance(1, dmctx, &vcf_last, update_instance_alias_bbfdm, 3, s, "vcf_instance", "vcf_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, vcf) == DM_STOP) - break; - } - if(del_sec) - DMUCI_DELETE_BY_SECTION(bbfdm, del_sec, NULL, NULL); - return 0; -} - -//Browse VendorLogFile instances -int browseVlfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *sys_log_sec, *dm_sec; - char *log_file,*log_size; - int i = 1; - - uci_foreach_sections("system", "system", sys_log_sec) { - if (!sys_log_sec) - break; - dmuci_get_value_by_section_string(sys_log_sec, "log_file", &log_file); - dmuci_get_value_by_section_string(sys_log_sec, "log_size", &log_size); - uci_path_foreach_sections(bbfdm, "dmmap", "vlf", dm_sec) { - if (dm_sec) - break; - } - if (!dm_sec) { - update_section_list(DMMAP,"vlf", NULL, i++, NULL, "log_file", log_file, "log_size", log_size); - } else { - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dm_sec, "log_file", log_file); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dm_sec, "log_size", log_size); - } - } - uci_path_foreach_sections(bbfdm, "dmmap", "vlf", dm_sec) { - char *instance, *last_instance = NULL; - - instance = handle_update_instance(1, dmctx, &last_instance, update_instance_alias_bbfdm, 3, dm_sec, "vlf_instance", "vlf_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)dm_sec, instance) == DM_STOP){ - break; - } - } - return 0; -} diff --git a/dmtree/tr181/deviceinfo.h b/dmtree/tr181/deviceinfo.h index ccab3cb2..6370a1bb 100644 --- a/dmtree/tr181/deviceinfo.h +++ b/dmtree/tr181/deviceinfo.h @@ -17,6 +17,7 @@ #define UPTIME "/proc/uptime" #define DEFAULT_CONFIG_DIR "/etc/config/" + extern DMLEAF tDeviceInfoParams[]; extern DMLEAF tCatTvParams[]; extern DMLEAF tDeviceInfoVendorConfigFileParams[]; @@ -27,62 +28,4 @@ extern DMLEAF tDeviceInfoProcessStatusParams[]; extern DMOBJ tDeviceInfoObj[]; extern DMLEAF tDeviceInfoProcessStatusProcessParams[]; -char *get_deviceid_manufacturer(); -char *get_deviceid_manufactureroui(); -char *get_deviceid_productclass(); -char *get_deviceid_serialnumber(); -char *get_softwareversion(); -int lookup_vcf_name(char *instance, char **value); - -int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseVlfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browsePocessEntriesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int get_device_manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_device_manufactureroui(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_device_routermodel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_device_productclass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_device_serialnumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_device_hardwareversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_device_softwareversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_device_info_uptime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_device_devicelog(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_device_specversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_base_mac_addr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_catv_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_device_memory_bank(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_catv_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_catv_optical_input_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_catv_rf_output_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_catv_temperature(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_catv_voltage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_vcf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_vcf_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_vcf_date(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_vcf_desc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_vcf_backup_restore(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_vlf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_vlf_max_size(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_vlf_persistent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_memory_status_total(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_memory_status_free(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_process_cpu_usage(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_process_number_of_entries(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_process_pid(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_process_command(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_process_size(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_process_priority(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_process_cpu_time(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_process_state(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_device_catvenabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_device_memory_bank(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_device_catvenabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/dhcpv4.c b/dmtree/tr181/dhcpv4.c index 0725193d..a5028a38 100644 --- a/dmtree/tr181/dhcpv4.c +++ b/dmtree/tr181/dhcpv4.c @@ -13,6 +13,3177 @@ #include "dmentry.h" #include "dhcpv4.h" + +struct dhcp_lease { + uint64_t ts; + char hwaddr[20]; + char ipaddr[16]; + struct list_head list; +}; + +struct dhcp_args { + struct uci_section *dhcp_sec; + char *interface; + struct list_head leases; + unsigned n_leases; +}; + +struct dhcp_static_args { + struct uci_section *dhcpsection; +}; + +struct client_args { + const struct dhcp_lease *lease; +}; + +struct dhcp_client_args { + struct uci_section *dhcp_client_conf; + struct uci_section *dhcp_client_dm; + struct uci_section *macclassifier; + struct uci_section *vendorclassidclassifier; + struct uci_section *userclassclassifier; + char *ip; + char *mask; +}; + +struct dhcp_client_option_args { + struct uci_section *opt_sect; + struct uci_section *client_sect; + char *option_tag; + char *value; +}; + +/************************************************************************** +* LINKER +***************************************************************************/ +static int get_dhcp_client_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + const struct client_args *args = data; + + *linker = (char *)args->lease->hwaddr; + return 0; +} + +/************************************************************* +* INIT +**************************************************************/ +static inline void init_dhcp_args(struct dhcp_args *args, struct uci_section *s, char *interface) +{ + args->interface = interface; + args->dhcp_sec = s; + INIT_LIST_HEAD(&args->leases); + args->n_leases = 0; +} + +static inline void init_args_dhcp_host(struct dhcp_static_args *args, struct uci_section *s) +{ + args->dhcpsection = s; +} + +static inline void init_dhcp_client_args(struct client_args *args, const struct dhcp_lease *lease) +{ + args->lease = lease; +} + +/************************************************************* +* Other functions +**************************************************************/ +struct uci_section* exist_other_section_same_order(struct uci_section *dmmap_sect, char * package, char* sect_type, char *order) +{ + struct uci_section *s; + uci_path_foreach_option_eq(bbfdm, package, sect_type, "order", order, s) { + if (strcmp(section_name(s), section_name(dmmap_sect)) != 0) { + return s; + } + } + return NULL; +} + +int set_section_order(char *package, char *dmpackage, char* sect_type, struct uci_section *dmmap_sect, struct uci_section *conf, int set_force, char* order) +{ + char *v = NULL, *sect_name, *incrorder; + struct uci_section *s, *dm; + + dmuci_get_value_by_section_string(dmmap_sect, "order", &v); + if (strlen(v) > 0 && strcmp(v, order) == 0) + return 0; + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "order", order); + if (conf == NULL) { + dmuci_get_value_by_section_string(dmmap_sect, "section_name", §_name); + get_config_section_of_dmmap_section(package, sect_type, sect_name, &s); + } else + s= conf; + + if (strcmp(order, "1") != 0 && s != NULL) { + dmuci_set_value_by_section(s, "force", ""); + } + + if (set_force == 1 && strcmp(order, "1") == 0 && s != NULL) { + dmuci_set_value_by_section(s, "force", "1"); + } + + if ((dm = exist_other_section_same_order(dmmap_sect, dmpackage, sect_type, order)) != NULL) { + dmuci_get_value_by_section_string(dm, "section_name", §_name); + get_config_section_of_dmmap_section(package, sect_type, sect_name, &s); + dmasprintf(&incrorder, "%d", atoi(order)+1); + if (s != NULL && strcmp(order, "1") == 0) { + dmuci_set_value_by_section(s, "force", ""); + } + set_section_order(package, dmpackage, sect_type, dm, s, set_force, incrorder); + } + return 0; + +} + +/*******************ADD-DEL OBJECT*********************/ +static int add_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + char *value, *v; + char *instance; + struct uci_section *s = NULL, *dmmap_dhcp = NULL; + + check_create_dmmap_package("dmmap_dhcp"); + instance = get_last_instance_bbfdm("dmmap_dhcp", "dhcp", "dhcp_instance"); + dmuci_add_section("dhcp", "dhcp", &s, &value); + dmuci_set_value_by_section(s, "start", "100"); + dmuci_set_value_by_section(s, "leasetime", "12h"); + dmuci_set_value_by_section(s, "limit", "150"); + + dmuci_add_section_bbfdm("dmmap_dhcp", "dhcp", &dmmap_dhcp, &v); + dmuci_set_value_by_section(dmmap_dhcp, "section_name", section_name(s)); + *instancepara = update_instance_bbfdm(dmmap_dhcp, instance, "dhcp_instance"); + return 0; +} + +static int delete_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; + + switch (del_action) { + case DEL_INST: + if(is_section_unnamed(section_name(((struct dhcp_args *)data)->dhcp_sec))){ + LIST_HEAD(dup_list); + delete_sections_save_next_sections("dmmap_dhcp", "dhcp", "dhcp_instance", section_name(((struct dhcp_args *)data)->dhcp_sec), atoi(instance), &dup_list); + update_dmmap_sections(&dup_list, "dhcp_instance", "dmmap_dhcp", "dhcp"); + dmuci_delete_by_section_unnamed(((struct dhcp_args *)data)->dhcp_sec, NULL, NULL); + } else { + get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(((struct dhcp_args *)data)->dhcp_sec), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); + dmuci_delete_by_section(((struct dhcp_args *)data)->dhcp_sec, NULL, NULL); + } + + break; + case DEL_ALL: + uci_foreach_sections("dhcp", "dhcp", s) { + if (found != 0){ + get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(s), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL){ + get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + break; + } + return 0; +} + +static int add_dhcp_staticaddress(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + char *value, *v, *instance; + struct uci_section *s = NULL, *dmmap_dhcp_host= NULL; + + check_create_dmmap_package("dmmap_dhcp"); + instance = get_last_instance_lev2_bbfdm("dhcp", "host", "dmmap_dhcp", "ldhcpinstance", "dhcp", ((struct dhcp_args *)data)->interface); + dmuci_add_section("dhcp", "host", &s, &value); + dmuci_set_value_by_section(s, "dhcp", ((struct dhcp_args *)data)->interface); + + + dmuci_add_section_bbfdm("dmmap_dhcp", "host", &dmmap_dhcp_host, &v); + dmuci_set_value_by_section(dmmap_dhcp_host, "section_name", section_name(s)); + *instancepara = update_instance_bbfdm(dmmap_dhcp_host, instance, "ldhcpinstance"); + return 0; +} + +static int delete_dhcp_staticaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; + struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)data; + + switch (del_action) { + case DEL_INST: + if (is_section_unnamed(section_name(dhcpargs->dhcpsection))) { + LIST_HEAD(dup_list); + delete_sections_save_next_sections("dmmap_dhcp", "host", "ldhcpinstance", section_name(dhcpargs->dhcpsection), atoi(instance), &dup_list); + update_dmmap_sections(&dup_list, "ldhcpinstance", "dmmap_dhcp", "host"); + dmuci_delete_by_section_unnamed(dhcpargs->dhcpsection, NULL, NULL); + } else { + get_dmmap_section_of_config_section("dmmap_dhcp", "host", section_name(dhcpargs->dhcpsection), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(dhcpargs->dhcpsection, NULL, NULL); + } + break; + case DEL_ALL: + uci_foreach_option_eq("dhcp", "host", "dhcp", ((struct dhcp_args *)data)->interface, s) { + if (found != 0) { + get_dmmap_section_of_config_section("dmmap_dhcp", "host", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + get_dmmap_section_of_config_section("dmmap_dhcp", "host", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + break; + } + return 0; +} + +static int addObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct uci_section *s, *dmmap_sect; + char *wan_eth, *value, *wanname, *instancepara, *v; + + check_create_dmmap_package("dmmap_dhcp_client"); + instancepara = get_last_instance_bbfdm("dmmap_dhcp_client", "interface", "bbf_dhcpv4client_instance"); + dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_eth); + dmasprintf(&wanname, "%s.1", wan_eth); + dmuci_add_section("network", "interface", &s, &value); + dmuci_set_value_by_section(s, "proto", "dhcp"); + dmuci_set_value_by_section(s, "ifname", wanname); + dmuci_set_value_by_section(s, "type", "anywan"); + dmuci_add_section_bbfdm("dmmap_dhcp_client", "interface", &dmmap_sect, &v); + dmuci_set_value_by_section(dmmap_sect, "section_name", section_name(s)); + *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv4client_instance"); + return 0; +} + +static int delObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)data; + struct uci_section *s, *dmmap_section, *stmp; + json_object *res, *jobj; + + char *v; + char *type, *ipv4addr = "", *ipv6addr = "", *proto, *mask4; + + switch (del_action) { + case DEL_INST: + if (dhcp_client_args->dhcp_client_conf != NULL) { + dmuci_set_value_by_section(dhcp_client_args->dhcp_client_conf, "proto", "static"); + if (strlen(dhcp_client_args->ip) == 0) { + dmasprintf(&ipv4addr, "%s.%s.%s.%s", instance, instance, instance, instance); + dmasprintf(&mask4, "%s", "255.255.255.0"); + } else { + dmasprintf(&ipv4addr, "%s", dhcp_client_args->ip); + dmasprintf(&mask4, "%s", dhcp_client_args->mask); + } + dmuci_set_value_by_section(dhcp_client_args->dhcp_client_conf, "ipaddr", ipv4addr); + dmuci_set_value_by_section(dhcp_client_args->dhcp_client_conf, "netmask", mask4); + } + dmuci_delete_by_section_unnamed_bbfdm(dhcp_client_args->dhcp_client_dm, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("network", "interface", s) { + dmuci_get_value_by_section_string(s, "type", &type); + if (strcmp(type, "alias") == 0 || strcmp(section_name(s), "loopback") == 0) + continue; + dmuci_get_value_by_section_string(s, "ipaddr", &ipv4addr); + dmuci_get_value_by_section_string(s, "netmask", &mask4); + if (ipv4addr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + ipv4addr = dmjson_get_value(jobj, 1, "address"); + mask4= dmjson_get_value(jobj, 1, "mask"); + } + } + dmuci_get_value_by_section_string(s, "ip6addr", &ipv6addr); + if (ipv6addr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); + ipv6addr = dmjson_get_value(jobj, 1, "address"); + } + } + dmuci_get_value_by_section_string(s, "proto", &proto); + if (ipv4addr[0] == '\0' && ipv6addr[0] == '\0' && strcmp(proto, "dhcp") != 0 && strcmp(proto, "dhcpv6") != 0 && strcmp(type, "bridge") != 0) + continue; + + dmuci_set_value_by_section(s, "proto", "static"); + + get_dmmap_section_of_config_section("dmmap_dhcp_client", "interface", section_name(s), &dmmap_section); + if (strlen(ipv4addr) == 0) { + if(dmmap_section != NULL) + dmuci_get_value_by_section_string(dmmap_section, "bbf_dhcpv4client_instance", &v); + else + dmasprintf(&v, "%d", 0); + + dmasprintf(&ipv4addr, "%s.%s.%s.%s", v, v, v, v); + dmasprintf(&mask4, "%s", "255.255.255.0"); + } + dmuci_set_value_by_section(s, "ipaddr", ipv4addr); + dmuci_set_value_by_section(s, "netmask", mask4); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + } + uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcp_client", "interface", stmp, s) { + dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); + } + break; + } + return 0; +} + +static int addObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)data; + struct uci_section *dmmap_sect; + char *value, *instancepara; + + check_create_dmmap_package("dmmap_dhcp_client"); + instancepara = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_dhcp_client", "send_option", "bbf_dhcpv4_sentopt_instance", "section_name", section_name(dhcp_client_args->dhcp_client_conf)); + dmuci_add_section_bbfdm("dmmap_dhcp_client", "send_option", &dmmap_sect, &value); + if(dhcp_client_args->dhcp_client_conf != NULL) + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_client_args->dhcp_client_conf)); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", "0"); + *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv4_sentopt_instance"); + return 0; +} + +static int delObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s, *stmp; + char *list= NULL, *opt_value= NULL; + + switch (del_action) { + case DEL_INST: + if(strcmp(((struct dhcp_client_option_args*) data)->option_tag, "0") != 0) + { + dmasprintf(&opt_value, "%s:%s", ((struct dhcp_client_option_args*) data)->option_tag, ((struct dhcp_client_option_args*) data)->value); + dmuci_get_value_by_section_string(((struct dhcp_client_option_args*) data)->client_sect, "sendopts", &list); + if(list != NULL){ + remove_elt_from_str_list(&list, opt_value); + dmuci_set_value_by_section(((struct dhcp_client_option_args*) data)->client_sect, "sendopts", list); + } + } + dmuci_delete_by_section_unnamed_bbfdm(((struct dhcp_client_option_args*) data)->opt_sect, NULL, NULL); + break; + case DEL_ALL: + dmuci_set_value_by_section(((struct dhcp_client_args*) data)->dhcp_client_conf, "sendopts", ""); + uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcp_client", "send_option", stmp, s) { + dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); + } + break; + } + return 0; +} + +static int addObjDHCPv4ClientReqOption(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)data; + struct uci_section *dmmap_sect; + char *value, *instancepara; + + check_create_dmmap_package("dmmap_dhcp_client"); + instancepara = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_dhcp_client", "req_option", "bbf_dhcpv4_sentopt_instance", "section_name", section_name(dhcp_client_args->dhcp_client_conf)); + dmuci_add_section_bbfdm("dmmap_dhcp_client", "req_option", &dmmap_sect, &value); + if(dhcp_client_args->dhcp_client_conf != NULL) + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_client_args->dhcp_client_conf)); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", "0"); + *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv4_sentopt_instance"); + return 0; +} + +static int delObjDHCPv4ClientReqOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s, *stmp; + char *list = NULL; + + switch (del_action) { + case DEL_INST: + if (strcmp(((struct dhcp_client_option_args*) data)->option_tag, "0") != 0) { + dmuci_get_value_by_section_string(((struct dhcp_client_option_args*) data)->client_sect, "reqopts", &list); + if (list != NULL) { + remove_elt_from_str_list(&list, ((struct dhcp_client_option_args*) data)->option_tag); + dmuci_set_value_by_section(((struct dhcp_client_option_args*) data)->client_sect, "reqopts", list); + } + } + dmuci_delete_by_section_unnamed_bbfdm(((struct dhcp_client_option_args*) data)->opt_sect, NULL, NULL); + break; + case DEL_ALL: + dmuci_set_value_by_section(((struct dhcp_client_args*) data)->dhcp_client_conf, "reqopts", ""); + uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcp_client", "req_option", stmp, s) { + dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); + } + break; + } + return 0; +} + +static int addObjDHCPv4ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct dhcp_args *dhcp_arg = (struct dhcp_args*)data; + struct uci_section *dmmap_sect; + char *value, *instancepara; + + check_create_dmmap_package("dmmap_dhcp"); + instancepara = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_dhcp", "servpool_option", "bbf_dhcpv4_servpool_option_instance", "section_name", section_name(dhcp_arg->dhcp_sec)); + dmuci_add_section_bbfdm("dmmap_dhcp", "servpool_option", &dmmap_sect, &value); + if(dhcp_arg->dhcp_sec != NULL) + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_arg->dhcp_sec)); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", "0"); + *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv4_servpool_option_instance"); + return 0; +} + +static int delObjDHCPv4ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s, *stmp; + char *opt_value = NULL; + struct uci_list *dhcp_options_list = NULL; + + switch (del_action) { + case DEL_INST: + if (strcmp(((struct dhcp_client_option_args*) data)->option_tag, "0") != 0) { + dmasprintf(&opt_value, "%s,%s", ((struct dhcp_client_option_args*) data)->option_tag, ((struct dhcp_client_option_args*) data)->value); + dmuci_get_value_by_section_list(((struct dhcp_client_option_args*) data)->client_sect, "dhcp_option", &dhcp_options_list); + if (dhcp_options_list != NULL) { + dmuci_del_list_value_by_section(((struct dhcp_client_option_args*) data)->client_sect, "dhcp_option", opt_value); + } + } + dmuci_delete_by_section_unnamed_bbfdm(((struct dhcp_client_option_args*) data)->opt_sect, NULL, NULL); + break; + case DEL_ALL: + dmuci_set_value_by_section(((struct dhcp_args*) data)->dhcp_sec, "dhcp_option", ""); + uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcp", "servpool_option", stmp, s) { + dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); + } + break; + } + return 0; +} + +static int addObjDHCPv4RelayForwarding(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct uci_section *s, *dmmap_sect; + char *value, *instancepara, *v; + + check_create_dmmap_package("dmmap_dhcp_relay"); + instancepara = get_last_instance_bbfdm("dmmap_dhcp_relay", "interface", "bbf_dhcpv4relay_instance"); + dmuci_add_section("network", "interface", &s, &value); + dmuci_set_value_by_section(s, "proto", "relay"); + dmuci_add_section_bbfdm("dmmap_dhcp_relay", "interface", &dmmap_sect, &v); + dmuci_set_value_by_section(dmmap_sect, "section_name", section_name(s)); + *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv4relay_instance"); + return 0; +} + +static int delObjDHCPv4RelayForwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct dhcp_client_args *dhcp_relay_args = (struct dhcp_client_args*)data; + struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; + char *proto = NULL; + int found = 0; + + switch (del_action) { + case DEL_INST: + if (is_section_unnamed(section_name(dhcp_relay_args->dhcp_client_conf))) { + LIST_HEAD(dup_list); + delete_sections_save_next_sections("dmmap_dhcp_relay", "interface", "bbf_dhcpv4relay_instance", section_name(dhcp_relay_args->dhcp_client_conf), atoi(instance), &dup_list); + update_dmmap_sections(&dup_list, "bbf_dhcpv4relay_instance", "dmmap_dhcp_relay", "interface"); + dmuci_delete_by_section_unnamed(dhcp_relay_args->dhcp_client_conf, NULL, NULL); + } else { + get_dmmap_section_of_config_section("dmmap_dhcp_relay", "interface", section_name(dhcp_relay_args->dhcp_client_conf), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); + dmuci_delete_by_section(dhcp_relay_args->dhcp_client_conf, NULL, NULL); + } + break; + case DEL_ALL: + uci_foreach_sections("network", "interface", s) { + if (found != 0) { + dmuci_get_value_by_section_string(ss, "proto", &proto); + if (strcmp(proto, "relay") == 0) { + get_dmmap_section_of_config_section("dmmap_dhcp_relay", "interface", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + } + ss = s; + found++; + } + if (ss != NULL) { + dmuci_get_value_by_section_string(ss, "proto", &proto); + if (strcmp(proto, "relay") == 0) { + get_dmmap_section_of_config_section("dmmap_dhcp_relay", "interface", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + } + break; + } + return 0; +} + +/************************************************************* +* GET & SET PARAM +**************************************************************/ +static int get_server_pool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_sect = NULL; + + get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(((struct dhcp_args *)data)->dhcp_sec), &dmmap_sect); + if (dmmap_sect) + dmuci_get_value_by_section_string(dmmap_sect, "dhcp_alias", value); + return 0; +} + +static int set_server_pool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_sect = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(((struct dhcp_args *)data)->dhcp_sec), &dmmap_sect); + if (dmmap_sect) + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "dhcp_alias", value); + return 0; + } + return 0; +} + +/*#Device.DHCPv4.Server.Pool.{i}.DNSServers!UBUS:network.interface/status/interface,@Name/dns-server*/ +static int get_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); + if (res) { + *value = dmjson_get_value_array_all(res, DELIMITOR, 1, "dns-server"); + } else + *value = ""; + if ((*value)[0] == '\0') { + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "dns", value); + *value = dmstrdup(*value); // MEM WILL BE FREED IN DMMEMCLEAN + char *p = *value; + while (*p) { + if (*p == ' ' && p != *value && *(p-1) != ',') + *p++ = ','; + else + p++; + } + } + if ((*value)[0] == '\0') { + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", value); + } + return 0; +} + +static int set_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *dup, *p; + + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, "4", NULL, NULL, "15", NULL, IPv4Address)) + return FAULT_9007; + return 0; + case VALUESET: + dup = dmstrdup(value); + p = dup; + while (*p) { + if (*p == ',') + *p++ = ' '; + else + p++; + } + dmuci_set_value("network", ((struct dhcp_args *)data)->interface, "dns", dup); + dmfree(dup); + return 0; + } + return 0; +} + +static int get_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + *value = "1"; + return 0; + } + *value = "0"; + return 0; +} + +static int set_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + if (!b) { + dmuci_delete_by_section(s, NULL, NULL); + } + break; + } + if (s == NULL && b) { + dmuci_set_value("dhcp",((struct dhcp_args *)data)->interface, NULL, "dhcp"); + dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "interface", ((struct dhcp_args *)data)->interface); + dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "start", "100"); + dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "limit", "150"); + dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "leasetime", "12h"); + } + return 0; + } + return 0; +} + +/*#Device.DHCPv4.Server.Pool.{i}.Status!UCI:dhcp/interface,@i-1/ignore*/ +static int get_dhcp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *v = NULL; + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + dmuci_get_value_by_section_string(s, "ignore", &v); + *value = (v && *v == '1') ? "Disabled" : "Enabled"; + return 0; + } + *value = "Error_Misconfigured"; + return 0; +} + +static int get_dhcp_sever_pool_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_sect = NULL; + + get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(((struct dhcp_args *)data)->dhcp_sec), &dmmap_sect); + if (dmmap_sect) + dmuci_get_value_by_section_string(dmmap_sect, "order", value); + return 0; +} + +static int set_dhcp_sever_pool_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_sect = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", NULL)) + return FAULT_9007; + break; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(((struct dhcp_args *)data)->dhcp_sec), &dmmap_sect); + if (dmmap_sect) + set_section_order("dhcp", "dmmap_dhcp", "dhcp", dmmap_sect, ((struct dhcp_args *)data)->dhcp_sec, 1, value); + break; + } + return 0; +} + +/*#Device.DHCPv4.Server.Pool.{i}.StaticAddressNumberOfEntries!UCI:dhcp/host/*/ +static int get_static_address_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int i = 0; + + uci_foreach_sections("dhcp", "host", s) { + i++; + } + dmasprintf(value, "%d", i); + return 0; +} + +static int get_option_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *dhcp_options_list = NULL; + struct uci_element *e; + int i= 0; + + dmuci_get_value_by_section_list(((struct dhcp_args *)data)->dhcp_sec, "dhcp_option", &dhcp_options_list); + if (dhcp_options_list != NULL) { + uci_foreach_element(dhcp_options_list, e) { + i++; + } + } + dmasprintf(value, "%d", i); + return 0; +} + +static int get_clients_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + const struct dhcp_args *dhcp = data; + + dmasprintf(value, "%u", dhcp->n_leases); + return 0; +} + +/*#Device.DHCPv4.Server.Pool.{i}.Enable!UCI:dhcp/interface,@i-1/ignore*/ +static int get_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + dmuci_get_value_by_section_string(s, "ignore", value); + if ((*value)[0] == '\0') + *value = "1"; + else + *value = "0"; + return 0; + } + *value = "0"; + return 0; +} + +static int set_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + dmuci_set_value_by_section(s, "ignore", b ? "0" : "1"); + break; + } + return 0; + } + return 0; +} + +enum enum_lanip_interval_address { + LANIP_INTERVAL_START, + LANIP_INTERVAL_END +}; + +static int get_dhcp_interval_address(struct dmctx *ctx, void *data, char *instance, char **value, int option) +{ + json_object *res, *jobj; + char bufipstart[16], bufipend[16], *ipaddr = "" , *mask = "", *start , *limit; + struct uci_section *s = NULL; + + *value = ""; + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + dmuci_get_value_by_section_string(s, "start", &start); + if (option == LANIP_INTERVAL_END) + dmuci_get_value_by_section_string(s, "limit", &limit); + break; + } + if (s == NULL) { + return 0; + } + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", &ipaddr); + if (ipaddr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + ipaddr = dmjson_get_value(jobj, 1, "address"); + } + } + if (ipaddr[0] == '\0') { + return 0; + } + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", &mask); + if (mask[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + mask = dmjson_get_value(jobj, 1, "mask"); + if (mask[0] == '\0') { + return 0; + } + mask = cidr2netmask(atoi(mask)); + } + } + if (mask[0] == '\0') { + mask = "255.255.255.0"; + } + if (option == LANIP_INTERVAL_START) { + ipcalc(ipaddr, mask, start, NULL, bufipstart, NULL); + *value = dmstrdup(bufipstart); // MEM WILL BE FREED IN DMMEMCLEAN + } else { + ipcalc(ipaddr, mask, start, limit, bufipstart, bufipend); + *value = dmstrdup(bufipend); // MEM WILL BE FREED IN DMMEMCLEAN + } + return 0; +} + +/*#Device.DHCPv4.Server.Pool.{i}.MinAddress!UCI:dhcp/interface,@i-1/start*/ +static int get_dhcp_interval_address_min(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + get_dhcp_interval_address(ctx, data, instance, value, LANIP_INTERVAL_START); + return 0; +} + +/*#Device.DHCPv4.Server.Pool.{i}.MaxAddress!UCI:dhcp/interface,@i-1/limit*/ +static int get_dhcp_interval_address_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + get_dhcp_interval_address(ctx, data, instance, value, LANIP_INTERVAL_END); + return 0; +} + +static int set_dhcp_address_min(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + json_object *res, *jobj; + char *ipaddr = "", *mask = "", buf[16]; + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", &ipaddr); + if (ipaddr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + ipaddr = dmjson_get_value(jobj, 1, "address"); + } + } + if (ipaddr[0] == '\0') + return 0; + + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", &mask); + if (mask[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + mask = dmjson_get_value(jobj, 1, "mask"); + if (mask[0] == '\0') + return 0; + mask = cidr2netmask(atoi(mask)); + } + } + if (mask[0] == '\0') + mask = "255.255.255.0"; + + ipcalc_rev_start(ipaddr, mask, value, buf); + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + dmuci_set_value_by_section(s, "start", buf); + break; + } + + return 0; + } + return 0; +} + +static int set_dhcp_address_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + json_object *res, *jobj; + char *ipaddr = "", *mask = "", *start, buf[16]; + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) + return FAULT_9007; + return 0; + case VALUESET: + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + dmuci_get_value_by_section_string(s, "start", &start); + break; + } + if (!s) return 0; + + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", &ipaddr); + if (ipaddr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + ipaddr = dmjson_get_value(jobj, 1, "address"); } + } + if (ipaddr[0] == '\0') + return 0; + + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", &mask); + if (mask[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + mask = dmjson_get_value(jobj, 1, "mask"); + if (mask[0] == '\0') + return 0; + mask = cidr2netmask(atoi(mask)); + } + } + if (mask[0] == '\0') + mask = "255.255.255.0"; + + ipcalc_rev_end(ipaddr, mask, start, value, buf); + dmuci_set_value_by_section(s, "limit", buf); + return 0; + } + return 0; +} + + +static int get_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char val[512] = {0}, *p; + struct uci_section *s = NULL; + char *min, *max, *ip; + unsigned int n_min, n_max, n_ip; + *value = ""; + + get_dhcp_interval_address(ctx, data, instance, &min, LANIP_INTERVAL_START); + get_dhcp_interval_address(ctx, data, instance, &max, LANIP_INTERVAL_END); + if (min[0] == '\0' || max[0] == '\0') + return 0; + n_min = inet_network(min); + n_max = inet_network(max); + p = val; + uci_foreach_sections("dhcp", "host", s) { + dmuci_get_value_by_section_string(s, "ip", &ip); + if (ip[0] == '\0') + continue; + n_ip = inet_network(ip); + if (n_ip >= n_min && n_ip <= n_max) { + if (val[0] != '\0') + dmstrappendchr(p, ','); + dmstrappendstr(p, ip); + } + } + dmstrappendend(p); + *value = dmstrdup(val); // MEM WILL BE FREED IN DMMEMCLEAN + return 0; +} + +static int set_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s = NULL, *dhcp_section = NULL; + char *min, *max, *val, *local_value, *pch, *spch; + unsigned int n_min, n_max, n_ip, ipexist= 0; + + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, "32", NULL, NULL, "15", NULL, IPv4Address)) + return FAULT_9007; + return 0; + case VALUESET: + get_dhcp_interval_address(ctx, data, instance, &min, LANIP_INTERVAL_START); + get_dhcp_interval_address(ctx, data, instance, &max, LANIP_INTERVAL_END); + n_min = inet_network(min); + n_max = inet_network(max); + local_value = dmstrdup(value); + + for (pch = strtok_r(local_value, ",", &spch); + pch != NULL; + pch = strtok_r(NULL, ",", &spch)) { + uci_foreach_option_eq("dhcp", "host", "ip", pch, s) { + ipexist = 1; + } + if(ipexist) + continue; + n_ip = inet_network(pch); + + if (n_ip < n_min || n_ip > n_max) + continue; + + dmuci_add_section_and_rename("dhcp", "host", &dhcp_section, &val); + dmuci_set_value_by_section(dhcp_section, "dhcp", ((struct dhcp_args *)data)->interface); + dmuci_set_value_by_section(dhcp_section, "ip", pch); + } + dmfree(local_value); + return 0; + } + return 0; +} + +/*#Device.DHCPv4.Server.Pool.{i}.SubnetMask!UCI:dhcp/interface,@i-1/netmask*/ +static int get_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *mask; + json_object *res, *jobj; + struct uci_section *s = NULL; + char *val; + *value = ""; + + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + dmuci_get_value_by_section_string(s, "netmask", value); + break; + } + if (s == NULL || (*value)[0] == '\0') + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", value); + if ((*value)[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + mask = dmjson_get_value(jobj, 1, "mask"); + int i_mask = atoi(mask); + val = cidr2netmask(i_mask); + *value = dmstrdup(val);// MEM WILL BE FREED IN DMMEMCLEAN + } + return 0; +} + +static int set_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) + return FAULT_9007; + return 0; + case VALUESET: + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + dmuci_set_value_by_section(s, "netmask", value); + return 0; + } + return 0; + } + return 0; +} + +static int get_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "gateway", value); + if ((*value)[0] == '\0') { + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", value); + } + return 0; +} + +static int set_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, "4", NULL, NULL, "15", NULL, IPv4Address)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("network", ((struct dhcp_args *)data)->interface, "gateway", value); + return 0; + } + return 0; +} + +/*#Device.DHCPv4.Server.Pool.{i}.LeaseTime!UCI:dhcp/interface,@i-1/leasetime*/ +static int get_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + int mtime = 0; + char *ltime = "", *pch, *spch, *ltime_ini, *tmp, *tmp_ini; + struct uci_section *s = NULL; + + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + dmuci_get_value_by_section_string(s, "leasetime", <ime); + break; + } + if (ltime[0] == '\0') { + *value = "-1"; + return 0; + } + ltime = dmstrdup(ltime); + ltime_ini = dmstrdup(ltime); + tmp = ltime; + tmp_ini = ltime_ini; + pch = strtok_r(ltime, "h", &spch); + if (strcmp(pch, ltime_ini) != 0) { + mtime = 3600 * atoi(pch); + if(spch[0] != '\0') { + ltime += strlen(pch)+1; + ltime_ini += strlen(pch)+1; + pch = strtok_r(ltime, "m", &spch); + if (strcmp(pch, ltime_ini) != 0) { + mtime += 60 * atoi(pch); + if(spch[0] !='\0') { + ltime += strlen(pch)+1; + ltime_ini += strlen(pch)+1; + pch = strtok_r(ltime, "s", &spch); + if (strcmp(pch, ltime_ini) != 0) { + mtime += atoi(pch); + } + } + } else { + pch = strtok_r(ltime, "s", &spch); + if (strcmp(pch, ltime_ini) != 0) + mtime += atoi(pch); + } + } + } else { + pch = strtok_r(ltime, "m", &spch); + if (strcmp(pch, ltime_ini) != 0) { + mtime += 60 * atoi(pch); + if(spch[0] !='\0') { + ltime += strlen(pch)+1; + ltime_ini += strlen(pch)+1; + pch = strtok_r(ltime, "s", &spch); + if (strcmp(pch, ltime_ini) != 0) { + mtime += atoi(pch); + } + } + } else { + pch = strtok_r(ltime, "s", &spch); + if (strcmp(pch, ltime_ini) != 0) + mtime += atoi(pch); + } + } + dmfree(tmp); + dmfree(tmp_ini); + + dmasprintf(value, "%d", mtime); // MEM WILL BE FREED IN DMMEMCLEAN + return 0; +} + +static int set_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s = NULL; + char buf[32]; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + return 0; + case VALUESET: + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + int val = atoi(value); + snprintf(buf, sizeof(buf), "%ds", val); + dmuci_set_value_by_section(s, "leasetime", buf); + break; + } + return 0; + } + return 0; +} + +static int get_dhcp_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker; + linker = dmstrdup(((struct dhcp_args *)data)->interface); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) + *value = ""; + dmfree(linker); + return 0; +} + +static int set_dhcp_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + adm_entry_get_linker_value(ctx, value, &linker); + if (linker) { + dmuci_set_value_by_section(((struct dhcp_args *)data)->dhcp_sec, "interface", linker); + dmfree(linker); + } + return 0; + } + return 0; +} + +static int get_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *str; + struct uci_list *val; + struct uci_element *e = NULL; + struct uci_section *s = NULL; + *value = ""; + + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + dmuci_get_value_by_section_list(s, "dhcp_option", &val); + if (val) { + uci_foreach_element(val, e) { + if ((str = strstr(e->name, "15,"))) { + *value = dmstrdup(str + sizeof("15,") - 1); //MEM WILL BE FREED IN DMMEMCLEAN + return 0; + } + } + } + } + return 0; +} + +static int set_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_list *val; + struct uci_section *s = NULL; + struct uci_element *e = NULL, *tmp; + char *option = "dhcp_option", buf[64]; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { + dmuci_get_value_by_section_list(s, option, &val); + if (val) { + uci_foreach_element_safe(val, e, tmp) { + if (strstr(tmp->name, "15,")) { + dmuci_del_list_value_by_section(s, "dhcp_option", tmp->name); + } + } + } + break; + } + goto end; + } +end: + snprintf(buf, sizeof(buf), "15,%s", value); + dmuci_add_list_value_by_section(((struct dhcp_args *)data)->dhcp_sec, "dhcp_option", buf); + return 0; +} + +static int get_dhcp_static_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + get_dmmap_section_of_config_section("dmmap_dhcp", "host", section_name(((struct dhcp_static_args *)data)->dhcpsection), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "ldhcpalias", value); + return 0; +} + +static int set_dhcp_static_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_dhcp", "host", section_name(((struct dhcp_static_args *)data)->dhcpsection), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "ldhcpalias", value); + return 0; + } + return 0; +} + +/*#Device.DHCPv4.Server.Pool.{i}.StaticAddress.{i}.Chaddr!UCI:dhcp/host,@i-1/mac*/ +static int get_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *chaddr; + + dmuci_get_value_by_section_string(((struct dhcp_static_args *)data)->dhcpsection, "mac", &chaddr); + if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) + dmuci_get_value_by_section_string(((struct dhcp_static_args *)data)->dhcpsection, "mac_orig", value); + else + *value = chaddr; + return 0; +} + +static int set_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *chaddr; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct dhcp_static_args *)data)->dhcpsection, "mac", &chaddr); + if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) + dmuci_set_value_by_section(((struct dhcp_static_args *)data)->dhcpsection, "mac_orig", value); + else + dmuci_set_value_by_section(((struct dhcp_static_args *)data)->dhcpsection, "mac", value); + return 0; + } + return 0; +} + +/*#Device.DHCPv4.Server.Pool.{i}.StaticAddress.{i}.Yiaddr!UCI:dhcp/host,@i-1/ip*/ +static int get_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dhcp_static_args *)data)->dhcpsection, "ip", value); + return 0; +} + +static int set_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct dhcp_static_args *)data)->dhcpsection, "ip", value); + return 0; + } + return 0; +} + +static int get_dhcp_client_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + const struct client_args *args = data; + + *value = (char *)args->lease->hwaddr; + return 0; +} + +static int get_dhcp_client_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "true"; + return 0; +} + +static int get_dhcp_client_ipv4address_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + const struct client_args *args = data; + + return dm_time_format(args->lease->ts, value); +} + +static int get_dhcp_client_ipv4address_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + const struct client_args *args = data; + + *value = (char *)args->lease->ipaddr; + return 0; +} + +static int get_DHCPv4_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s, *dmmap_sect; + int nbre_confs = 0, nbre_dmmaps = 0; + + uci_foreach_option_eq("network", "interface", "proto", "dhcp", s) { + nbre_confs++; + } + uci_path_foreach_sections(bbfdm, "dmmap_dhcp_client", "interface", dmmap_sect) { + nbre_dmmaps++; + } + if (nbre_dmmaps == 0 || nbre_dmmaps < nbre_confs) + dmasprintf(value, "%d", nbre_confs); + else + dmasprintf(value, "%d", nbre_dmmaps); + return 0; +} + +/*#Device.DHCPv4.Client.{i}.Enable!UCI:network/interface,@i-1/disabled*/ +static int get_DHCPv4Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v = NULL; + + if(((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { + *value = "0"; + return 0; + } + + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", &v); + + if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) + *value = "1"; + else + *value = "0"; + + return 0; +} + +static int set_DHCPv4Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", b ? "0" : "1"); + return 0; + } + return 0; +} + +static int get_DHCPv4Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_dm, "bbf_dhcpv4client_alias", value); + + return 0; +} + +static int set_DHCPv4Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct dhcp_client_args *)data)->dhcp_client_dm, "bbf_dhcpv4client_alias", value); + break; + } + return 0; +} + +static int get_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if(((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { + *value = ""; + return 0; + } + char *linker = dmstrdup(section_name(((struct dhcp_client_args *)data)->dhcp_client_conf)); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + *value = ""; + return 0; +} + +static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s; + char *linker = NULL, *newvalue = NULL, *v; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + + if(strlen(value) == 0 || strcmp(value, "") == 0) + return FAULT_9007; + + if (value[strlen(value)-1]!='.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else + adm_entry_get_linker_value(ctx, value, &linker); + uci_path_foreach_sections(bbfdm, "dmmap_dhcp_client", "interface", s) { + dmuci_get_value_by_section_string(s, "section_name", &v); + if(strcmp(v, linker) == 0) + return FAULT_9007; + } + uci_foreach_sections("network", "interface", s) { + if(strcmp(section_name(s), linker) == 0){ + dmuci_get_value_by_section_string(s, "proto", &v); + if(strcmp(v, "dhcp") != 0) + return FAULT_9007; + } + } + break; + case VALUESET: + if (value[strlen(value)-1]!='.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else + adm_entry_get_linker_value(ctx, value, &linker); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_args *)data)->dhcp_client_dm, "section_name", linker); + break; + } + return 0; +} + +/*#Device.DHCPv4.Client.{i}.Status!UCI:network/interface,@i-1/disabled*/ +static int get_DHCPv4Client_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v = NULL; + if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { + *value = "Error_Misconfigured"; + return 0; + } + + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", &v); + if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) + *value = "Enabled"; + else + *value = "Disabled"; + + return 0; +} + +/*#Device.DHCPv4.Client.{i}.DHCPStatus!UBUS:network.interface/status/interface,@Name/ipv4-address[@i-1].address*/ +static int get_DHCPv4Client_DHCPStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *ipaddr = ""; + json_object *res, *jobj; + + if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) + return 0; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + ipaddr = dmjson_get_value(jobj, 1, "address"); + } + + if (ipaddr[0] == '\0') + *value = "Requesting"; + else + *value = "Bound"; + + return 0; +} + +static int get_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "false"; + return 0; +} + +static int set_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + json_object *res; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL && strcasecmp(value, "true") != 0) + return 0; + + dmubus_call("network.interface", "renew", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + break; + } + return 0; +} + +static int get_DHCPv4Client_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(((struct dhcp_client_args *)data)->ip); + return 0; +} + +static int get_DHCPv4Client_SubnetMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(((struct dhcp_client_args *)data)->mask); + return 0; +} + +/*#Device.DHCPv4.Client.{i}.IPRouters!UBUS:network.interface/status/interface,@Name/route[@i-1].target*/ +static int get_DHCPv4Client_IPRouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v, buf[256] = ""; + json_object *jobj = NULL, *res; + int i = 0; + + if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) + return 0; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + DM_ASSERT(res, *value = ""); + while (1) { + jobj = dmjson_select_obj_in_array_idx(res, i, 1, "route"); + i++; + + if (jobj == NULL) + break; + + v = dmjson_get_value(jobj, 1, "target"); + if (*v == '\0') + continue; + if (strcmp(v, "0.0.0.0") == 0) + continue; + if (buf[0] != '\0') { + strcat(buf, ","); + } else + strcat(buf, v); + } + *value = dmstrdup(buf); + + return 0; +} + +/*#Device.DHCPv4.Client.{i}.DNSServers!UBUS:network.interface/status/interface,@Name/dns-server*/ +static int get_DHCPv4Client_DNSServers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + + if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) + return 0; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value_array_all(res, DELIMITOR, 1, "dns-server"); + return 0; +} + +/*#Device.DHCPv4.Client.{i}.LeaseTimeRemaining!UBUS:network.interface/status/interface,@Name/data.leasetime*/ +static int get_DHCPv4Client_LeaseTimeRemaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + + if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) + return 0; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + if (!res) { + *value = ""; + return 0; + } + *value = dmjson_get_value(res, 2, "data", "leasetime"); + return 0; +} + +static int get_DHCPv4Client_DHCPServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv4Client_PassthroughEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4Client_PassthroughEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv4Client_PassthroughDHCPPool(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4Client_PassthroughDHCPPool(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.DHCPv4.Client.{i}.SentOptionNumberOfEntries!UCI:network/interface,@i-1/sendopts*/ +static int get_DHCPv4Client_SentOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v = NULL; + size_t length; + + if (((struct dhcp_client_args *)data)->dhcp_client_conf != NULL) + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "sendopts", &v); + if (v == NULL) { + *value = "0"; + return 0; + } + strsplit(v, " ", &length); + dmasprintf(value, "%d", length); + return 0; +} + +/*#Device.DHCPv4.Client.{i}.ReqOptionNumberOfEntries!UCI:network/interface,@i-1/reqopts*/ +static int get_DHCPv4Client_ReqOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v = NULL; + size_t length; + + if (((struct dhcp_client_args *)data)->dhcp_client_conf != NULL) + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "reqopts", &v); + if (v == NULL) { + *value = "0"; + return 0; + } + strsplit(v, " ", &length); + dmasprintf(value, "%d", length); + return 0; +} + +static int get_DHCPv4ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v, *opttagvalue = NULL; + + if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) { + *value = "0"; + return 0; + } + dmasprintf(&opttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &v); + if (is_elt_exit_in_str_list(v, opttagvalue)) + *value = "1"; + else + *value = "0"; + + return 0; +} + +static int set_DHCPv4ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + char *v, *opttagvalue= NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &v); + if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) + return 0; + dmasprintf(&opttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); + if (b) { + if (!is_elt_exit_in_str_list(v, opttagvalue)) { + add_elt_to_str_list(&v, opttagvalue); + dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", v); + } + } else { + remove_elt_from_str_list(&v, opttagvalue); + dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", v); + } + break; + } + return 0; +} + +static int get_DHCPv4ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_sentopt_alias", value); + return 0; +} + +static int set_DHCPv4ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_sentopt_alias", value); + break; + } + return 0; +} + +static int get_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(((struct dhcp_client_option_args *)data)->option_tag); + return 0; +} + +static int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *pch, *spch, *list, *v, *opttagvalue, **sendopts, *oldopttagvalue; + size_t length; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", "254")) + return FAULT_9007; + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &v); + if (v == NULL) + return 0; + list = dmstrdup(v); + for (pch = strtok_r(list, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { + sendopts = strsplit(pch, ":", &length); + if (strcmp(sendopts[0], value) == 0) + return FAULT_9007; + } + break; + case VALUESET: + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &v); + dmasprintf(&oldopttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); + if (v != NULL && strlen(v) > 0) + remove_elt_from_str_list(&v, oldopttagvalue); + dmasprintf(&opttagvalue, "%s:%s", value, ((struct dhcp_client_option_args *)data)->value && strlen(((struct dhcp_client_option_args *)data)->value)>0 ? ((struct dhcp_client_option_args *)data)->value:"0"); + add_elt_to_str_list(&v, opttagvalue); + dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "option_tag", value); + break; + } + return 0; +} + +static int get_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(((struct dhcp_client_option_args *)data)->value); + return 0; +} + +static int set_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *v, *opttagvalue, *oldopttagvalue; + + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, "0", "255")) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &v); + dmasprintf(&oldopttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); + remove_elt_from_str_list(&v, oldopttagvalue); + dmasprintf(&opttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, value); + add_elt_to_str_list(&v, opttagvalue); + dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "option_value", value); + break; + } + return 0; +} + +static int get_DHCPv4ClientReqOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v; + + if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) { + *value = "0"; + return 0; + } + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", &v); + if (is_elt_exit_in_str_list(v, ((struct dhcp_client_option_args *)data)->option_tag)) + *value = "1"; + else + *value = "0"; + return 0; +} + +static int set_DHCPv4ClientReqOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + char *v; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", &v); + if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) + return 0; + if (b) { + if (!is_elt_exit_in_str_list(v, ((struct dhcp_client_option_args *)data)->option_tag)) { + add_elt_to_str_list(&v, ((struct dhcp_client_option_args *)data)->option_tag); + dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", v); + } + } else { + remove_elt_from_str_list(&v, ((struct dhcp_client_option_args *)data)->option_tag); + dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", v); + } + break; + } + return 0; +} + +static int get_DHCPv4ClientReqOption_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4ClientReqOption_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv4ClientReqOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_reqtopt_alias", value); + return 0; +} + +static int set_DHCPv4ClientReqOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_reqtopt_alias", value); + break; + } + return 0; +} + +static int get_DHCPv4ClientReqOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(((struct dhcp_client_option_args *)data)->option_tag); + return 0; +} + +static int set_DHCPv4ClientReqOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *pch, *spch, *list, *v; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", "254")) + return FAULT_9007; + + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", &v); + if (v == NULL) + return 0; + list = dmstrdup(v); + for (pch = strtok_r(list, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { + if(strcmp(pch, value) == 0) + return FAULT_9007; + } + break; + case VALUESET: + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", &v); + if (v != NULL && strlen(v) > 0) + remove_elt_from_str_list(&v, ((struct dhcp_client_option_args *)data)->option_tag); + add_elt_to_str_list(&v, value); + dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "option_tag", value); + break; + } + return 0; +} + +static int get_DHCPv4ClientReqOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv4Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv4RelayForwarding_DHCPServerIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4RelayForwarding_DHCPServerIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *dhcp_option_list; + struct uci_element *e; + char **buf; + size_t length; + + if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) { + *value = "0"; + return 0; + } + dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + if (dhcp_option_list != NULL) { + uci_foreach_element(dhcp_option_list, e) { + buf = strsplit(e->name, ",", &length); + if (strcmp(buf[0], ((struct dhcp_client_option_args *)data)->option_tag) == 0) { + *value = "1"; + return 0; + } + } + } + *value = "0"; + return 0; +} + +static int set_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_list *dhcp_option_list; + struct uci_element *e; + char **buf, *opt_value; + size_t length; + bool test = false, b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) + return 0; + dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + dmasprintf(&opt_value, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); + if (dhcp_option_list != NULL) { + uci_foreach_element(dhcp_option_list, e) { + buf = strsplit(e->name, ",", &length); + if (strcmp(buf[0], ((struct dhcp_client_option_args *)data)->option_tag) == 0) { + test = true; + if (!b) + dmuci_del_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", opt_value); + break; + } + } + } + if(!test && b) + dmuci_add_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", opt_value); + } + return 0; +} + +static int get_DHCPv4Server_PoolNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int i= 0; + + uci_foreach_sections("dhcp", "dhcp", s) { + i++; + } + dmasprintf(value, "%d", i); + return 0; +} + +static int get_DHCPv4ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_servpool_option_alias", value); + return 0; +} + +static int set_DHCPv4ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_servpool_option_alias", value); + break; + } + return 0; +} + +static int get_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(((struct dhcp_client_option_args *)data)->option_tag); + return 0; +} + +static int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *opttagvalue, **option, *oldopttagvalue; + size_t length; + struct uci_list *dhcp_option_list = NULL; + struct uci_element *e; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", "254")) + return FAULT_9007; + + dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + if (dhcp_option_list == NULL) + return 0; + uci_foreach_element(dhcp_option_list, e) { + option = strsplit(e->name, ",", &length); + if (strcmp(option[0], value)==0) + return FAULT_9007; + } + break; + case VALUESET: + dmasprintf(&oldopttagvalue, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); + dmasprintf(&opttagvalue, "%s,%s", value, ((struct dhcp_client_option_args *)data)->value); + dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + dmuci_del_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", oldopttagvalue); + dmuci_add_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", opttagvalue); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "option_tag", value); + break; + } + return 0; +} + +static int get_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(((struct dhcp_client_option_args *)data)->value); + return 0; +} + +static int set_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *opttagvalue, **option, *oldopttagvalue; + size_t length; + struct uci_list *dhcp_option_list = NULL; + struct uci_element *e; + + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, "0", "255")) + return FAULT_9007; + + dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + if (dhcp_option_list == NULL) + return 0; + uci_foreach_element(dhcp_option_list, e) { + option = strsplit(e->name, ",", &length); + if (strcmp(option[0], value) == 0) + return FAULT_9007; + } + break; + case VALUESET: + dmasprintf(&oldopttagvalue, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); + dmasprintf(&opttagvalue, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, value); + dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + dmuci_del_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", oldopttagvalue); + dmuci_add_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", opttagvalue); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "option_value", value); + break; + } + return 0; +} + +/*#Device.DHCPv4.Relay.Forwarding.{i}.Enable!UCI:network/interface,@i-1/disabled*/ +static int get_DHCPv4RelayForwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v = NULL; + + if(((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { + *value = "0"; + return 0; + } + + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", &v); + if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) + *value = "1"; + else + *value = "0"; + + return 0; +} + +static int set_DHCPv4RelayForwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", b ? "0" : "1"); + break; + } + return 0; +} + +static int get_DHCPv4RelayForwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_dm, "bbf_dhcpv4relay_alias", value); + return 0; +} + +static int set_DHCPv4RelayForwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct dhcp_client_args *)data)->dhcp_client_dm, "bbf_dhcpv4relay_alias", value); + break; + } + return 0; +} + +static int get_DHCPv4RelayForwarding_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4RelayForwarding_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { + *value = ""; + return 0; + } + char *linker = dmstrdup(section_name(((struct dhcp_client_args *)data)->dhcp_client_conf)); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), linker, value); + return 0; +} + +static int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s; + char *linker = NULL, *newvalue = NULL, *v; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + + if (strlen(value) == 0 || strcmp(value, "") == 0) + return FAULT_9007; + + if (value[strlen(value)-1] != '.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else + adm_entry_get_linker_value(ctx, value, &linker); + if (linker == NULL) + return FAULT_9007; + uci_path_foreach_sections(bbfdm, "dmmap_dhcp_relay", "interface", s) { + dmuci_get_value_by_section_string(s, "section_name", &v); + if (strcmp(v, linker) == 0) + return FAULT_9007; + } + uci_foreach_sections("network", "interface", s) { + if (strcmp(section_name(s), linker) == 0) { + dmuci_get_value_by_section_string(s, "proto", &v); + if(strcmp(v, "relay") != 0) + return FAULT_9007; + } + } + break; + case VALUESET: + if (value[strlen(value)-1]!='.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else + adm_entry_get_linker_value(ctx, value, &linker); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_args *)data)->dhcp_client_dm, "section_name", linker); + break; + } + return 0; +} + +/*#Device.DHCPv4.Relay.Forwarding.{i}.VendorClassID!UCI:network/interface,@i-1/vendorclass*/ +static int get_DHCPv4RelayForwarding_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if(((struct dhcp_client_args *)data)->vendorclassidclassifier) + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->vendorclassidclassifier, "vendorclass", value); + return 0; +} + +static int set_DHCPv4RelayForwarding_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "255", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + if(((struct dhcp_client_args *)data)->vendorclassidclassifier) + dmuci_set_value_by_section(((struct dhcp_client_args *)data)->vendorclassidclassifier, "vendorclass", value); + break; + } + return 0; +} + +static int get_DHCPv4RelayForwarding_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4RelayForwarding_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv4RelayForwarding_VendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4RelayForwarding_VendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, VendorClassIDMode, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.DHCPv4.Relay.Forwarding.{i}.Chaddr!UCI:network/interface,@i-1/mac*/ +static int get_DHCPv4RelayForwarding_Chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *mac, **macarray, *res = NULL, *tmp = ""; + size_t length; + int i; + + if (((struct dhcp_client_args *)data)->macclassifier == NULL) { + *value = ""; + return 0; + } + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->macclassifier, "mac", &mac); + macarray = strsplit(mac, ":", &length); + res = (char*)dmcalloc(18, sizeof(char)); + tmp = res; + for (i = 0; i < 6; i++) { + if (strcmp(macarray[i], "*") == 0) { + sprintf(tmp, "%s", "00"); + } else { + sprintf(tmp, "%s", macarray[i]); + } + tmp += 2; + + if (i < 5) { + sprintf(tmp, "%s", ":"); + tmp++; + } + } + dmasprintf(value, "%s", res); + return 0; +} + +static int set_DHCPv4RelayForwarding_Chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +/*#Device.DHCPv4.Relay.Forwarding.{i}.ChaddrMask!UCI:network/interface,@i-1/mac*/ +static int get_DHCPv4RelayForwarding_ChaddrMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *mac, **macarray, *res = NULL, *tmp = ""; + size_t length; + int i; + + if (((struct dhcp_client_args *)data)->macclassifier == NULL) { + *value= ""; + return 0; + } + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->macclassifier, "mac", &mac); + macarray = strsplit(mac, ":", &length); + res = (char*)dmcalloc(18, sizeof(char)); + tmp = res; + for (i = 0; i < 6; i++) { + if (strcmp(macarray[i], "*") == 0) { + sprintf(tmp, "%s", "00"); + } else { + sprintf(tmp, "%s", "FF"); + } + tmp += 2; + + if (i < 5) { + sprintf(tmp, "%s", ":"); + tmp++; + } + } + dmasprintf(value, "%s", res); + return 0; +} + +static int set_DHCPv4RelayForwarding_ChaddrMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_DHCPv4RelayForwarding_ChaddrExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "true"; + return 0; +} + +static int set_DHCPv4RelayForwarding_ChaddrExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv4RelayForwarding_LocallyServed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4RelayForwarding_LocallyServed(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv4ServerPoolClientOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.DHCPv4.Relay.Forwarding.{i}.Status!UCI:network/interface,@i-1/disabled*/ +static int get_DHCPv4RelayForwarding_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v = NULL; + + if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { + *value= "Error_Misconfigured"; + return 0; + } + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", &v); + if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) + *value= "Enabled"; + else + *value= "Disabled"; + + return 0; +} + +static int get_DHCPv4RelayForwarding_ClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4RelayForwarding_ClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "255")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv4RelayForwarding_ClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4RelayForwarding_ClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.DHCPv4.Relay.Forwarding.{i}.UserClassID!UCI:network/interface,@i-1/userclass*/ +static int get_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if(((struct dhcp_client_args *)data)->userclassclassifier) + dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->userclassclassifier, "userclass", value); + return 0; +} + +static int set_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "255")) + return FAULT_9007; + break; + case VALUESET: + if(((struct dhcp_client_args *)data)->userclassclassifier) + dmuci_set_value_by_section(((struct dhcp_client_args *)data)->userclassclassifier, "userclass", value); + break; + } + return 0; +} + +static int get_DHCPv4RelayForwarding_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv4RelayForwarding_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv4ServerPoolClientOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv4Relay_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *path = "/etc/rc.d/*relayd"; + if (check_file(path)) + *value = "1"; + else + *value = "0"; + return 0; +} + +static int set_DHCPv4Relay_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmcmd("/etc/init.d/relayd", 1, b ? "enable" : "disable"); + break; + } + return 0; +} + +static int get_DHCPv4Relay_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *path = "/etc/rc.d/*relayd"; + if (check_file(path)) + *value = "Enabled"; + else + *value = "Disabled"; + return 0; +} + +static int get_DHCPv4Relay_ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s, *dmmap_sect; + int nbre_confs = 0, nbre_dmmaps = 0; + + uci_foreach_option_eq("network", "interface", "proto", "relay", s) { + nbre_confs++; + } + uci_path_foreach_sections(bbfdm, "dmmap_dhcp_relay", "interface", dmmap_sect) { + nbre_dmmaps++; + } + if (nbre_dmmaps == 0 || nbre_dmmaps < nbre_confs) + dmasprintf(value, "%d", nbre_confs); + else + dmasprintf(value, "%d", nbre_dmmaps); + return 0; +} + +static void dhcp_leases_load(struct list_head *head) +{ + FILE *f = fopen(DHCP_LEASES_FILE, "r"); + char line[128]; + + if (f == NULL) + return; + + while (fgets(line, sizeof(line) - 1, f)) { + struct dhcp_lease *lease; + + if (line[0] == '\n') + continue; + + lease = dmcalloc(1, sizeof(*lease)); + if (lease == NULL) + break; + + sscanf(line, "%" PRId64 "%19s %15s", + &lease->ts, lease->hwaddr, lease->ipaddr); + + list_add_tail(&lease->list, head); + } + fclose(f); +} + +static int interface_get_ipv4(const char *iface, uint32_t *addr, unsigned *bits) +{ + json_object *res; + const char *addr_str = NULL; + int addr_cidr = -1; + + dmubus_call("network.interface", "status", UBUS_ARGS {{"interface", iface, String}}, 1, &res); + if (res) { + json_object *jobj; + + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + if (jobj == NULL) + return -1; + + json_object_object_foreach(jobj, key, val) { + if (!strcmp(key, "address")) + addr_str = json_object_get_string(val); + else if (!strcmp(key, "mask")) + addr_cidr = json_object_get_int(val); + } + } + + if (addr_str == NULL || addr_cidr == -1) + return -1; + + if (inet_pton(AF_INET, addr_str, addr) != 1) + return -1; + + *bits = addr_cidr; + return 0; +} + +static void dhcp_leases_assign_to_interface(struct dhcp_args *dhcp, + struct list_head *src, + const char *iface) +{ + struct dhcp_lease *lease, *tmp; + unsigned iface_addr; + unsigned iface_cidr; + unsigned iface_net; + unsigned iface_bits; + + if (interface_get_ipv4(iface, &iface_addr, &iface_cidr)) + return; + + iface_bits = 32 - iface_cidr; + iface_net = ntohl(iface_addr) >> iface_bits; + + list_for_each_entry_safe(lease, tmp, src, list) { + unsigned addr, net; + + inet_pton(AF_INET, lease->ipaddr, &addr); + net = ntohl(addr) >> iface_bits; + + if (net == iface_net) { + list_move_tail(&lease->list, &dhcp->leases); + dhcp->n_leases += 1; + } + } +} + +/************************************************************* +* ENTRY METHOD +**************************************************************/ +/*#Device.DHCPv4.Server.Pool.{i}.!UCI:dhcp/dhcp/dmmap_dhcp*/ +static int browseDhcpInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *interface, *idhcp = NULL, *idhcp_last = NULL, *v; + struct dhcp_args curr_dhcp_args = {0}; + struct dmmap_dup *p; + LIST_HEAD(leases); + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("dhcp", "dhcp", "dmmap_dhcp", &dup_list); + + if (!list_empty(&dup_list)) + dhcp_leases_load(&leases); + + list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "interface", &interface); + init_dhcp_args(&curr_dhcp_args, p->config_section, interface); + + dhcp_leases_assign_to_interface(&curr_dhcp_args, &leases, interface); + + idhcp = handle_update_instance(1, dmctx, &idhcp_last, update_instance_alias_bbfdm, 3, p->dmmap_section, "dhcp_instance", "dhcp_alias"); + dmuci_get_value_by_section_string(p->dmmap_section, "order", &v); + if (v == NULL || strlen(v) == 0) + set_section_order("dhcp", "dmmap_dhcp", "dhcp", p->dmmap_section, p->config_section, 0, idhcp); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_args, idhcp) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +/*#Device.DHCPv4.Server.Pool.{i}.StaticAddress.{i}.!UCI:dhcp/host/dmmap_dhcp*/ +static int browseDhcpStaticInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *idhcp = NULL, *idhcp_last = NULL; + struct dhcp_static_args curr_dhcp_staticargs = {0}; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap_cont("dhcp", "host", "dmmap_dhcp", "dhcp", ((struct dhcp_args *)prev_data)->interface, &dup_list); + list_for_each_entry(p, &dup_list, list) { + idhcp = handle_update_instance(2, dmctx, &idhcp_last, update_instance_alias_bbfdm, 3, p->dmmap_section, "ldhcpinstance", "ldhcpalias"); + init_args_dhcp_host(&curr_dhcp_staticargs, p->config_section); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_staticargs, idhcp) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int browseDhcpClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + const struct dhcp_args *dhcp = prev_data; + const struct dhcp_lease *lease; + int id = 0; + + list_for_each_entry(lease, &dhcp->leases, list) { + struct client_args client_args; + char *idx, *idx_last = NULL; + + init_dhcp_client_args(&client_args, lease); + idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&client_args, idx) == DM_STOP) + break; + } + return 0; +} + +static int browseDhcpClientIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *idx, *idx_last = NULL; + + idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, 1); + DM_LINK_INST_OBJ(dmctx, parent_node, prev_data, idx); + return 0; +} + +/*#Device.DHCPv4.Client.{i}.!UCI:network/interface/dmmap_dhcp_client*/ +static int browseDHCPv4ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *instance, *instnbr = NULL; + struct dmmap_dup *p; + char *type, *ipv4addr = "", *ipv6addr = "", *proto, *inst, *mask4 = NULL; + json_object *res, *jobj; + struct dhcp_client_args dhcp_client_arg = {0}; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap_eq_no_delete("network", "interface", "dmmap_dhcp_client", "proto", "dhcp", &dup_list); + list_for_each_entry(p, &dup_list, list) { + if (p->config_section != NULL) { + dmuci_get_value_by_section_string(p->config_section, "type", &type); + if (strcmp(type, "alias") == 0 || strcmp(section_name(p->config_section), "loopback") == 0) + continue; + + dmuci_get_value_by_section_string(p->config_section, "ipaddr", &ipv4addr); + dmuci_get_value_by_section_string(p->config_section, "netmask", &mask4); + if (ipv4addr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + ipv4addr = dmjson_get_value(jobj, 1, "address"); + mask4= dmjson_get_value(jobj, 1, "mask"); + } + } + + dmuci_get_value_by_section_string(p->config_section, "ip6addr", &ipv6addr); + if (ipv6addr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); + ipv6addr = dmjson_get_value(jobj, 1, "address"); + } + } + + dmuci_get_value_by_section_string(p->config_section, "proto", &proto); + dmuci_get_value_by_section_string(p->config_section, "ip_int_instance", &inst); + + if (ipv4addr[0] == '\0' && ipv6addr[0] == '\0' && strcmp(proto, "dhcp") != 0 && strcmp(proto, "dhcpv6") != 0 && strcmp(inst, "") == 0 && strcmp(type, "bridge") != 0) { + p->config_section=NULL; + DMUCI_SET_VALUE_BY_SECTION(bbfdm, p->dmmap_section, "section_name", ""); + } + } + + if (ipv4addr == NULL || strlen(ipv4addr) == 0) + dhcp_client_arg.ip = dmstrdup(""); + else + dhcp_client_arg.ip = dmstrdup(ipv4addr); + if (mask4 == NULL || strlen(mask4) == 0) + dhcp_client_arg.mask = dmstrdup(""); + else + dhcp_client_arg.mask = dmstrdup(mask4); + + dhcp_client_arg.dhcp_client_conf = p->config_section; + dhcp_client_arg.dhcp_client_dm= p->dmmap_section; + + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, (void *)p->dmmap_section, "bbf_dhcpv4client_instance", "bbf_dhcpv4client_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_client_arg, instance) == DM_STOP) + break; + } + return 0; +} + +static int browseDHCPv4ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)prev_data; + struct uci_section *dmmap_sect; + struct dhcp_client_option_args dhcp_client_opt_args = {0}; + char *instance, *instnbr = NULL, *v1, *v2, **sentopts = NULL, **buf = NULL, *tmp, *optionvalue, *v = NULL; + size_t length = 0, lgh2; + int i, j; + + if (dhcp_client_args->dhcp_client_conf != NULL) + dmuci_get_value_by_section_string(dhcp_client_args->dhcp_client_conf, "sendopts", &v); + + if (v) sentopts = strsplit(v, " ", &length); + check_create_dmmap_package("dmmap_dhcp_client"); + for (i = 0; i < length; i++) { + if (sentopts[i]) buf = strsplit(sentopts[i], ":", &lgh2); + if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcp_client", "send_option", section_name(dhcp_client_args->dhcp_client_conf), "option_tag", buf[0])) == NULL) { + dmuci_add_section_bbfdm("dmmap_dhcp_client", "send_option", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", buf[0]); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_client_args->dhcp_client_conf)); + } + optionvalue = dmstrdup(buf[1]); + if (lgh2 > 2) { + for (j = 2; j < lgh2; j++) { + tmp = dmstrdup(optionvalue); + dmfree(optionvalue); + optionvalue = NULL; + dmasprintf(&optionvalue, "%s:%s", tmp, buf[j]); + dmfree(tmp); + tmp = NULL; + } + } + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_value", optionvalue); + } + + uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp_client", "send_option", "section_name", dhcp_client_args->dhcp_client_conf?section_name(dhcp_client_args->dhcp_client_conf):"", dmmap_sect) { + dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1); + dmuci_get_value_by_section_string(dmmap_sect, "option_value", &v2); + dhcp_client_opt_args.client_sect= dhcp_client_args->dhcp_client_conf; + dhcp_client_opt_args.option_tag= dmstrdup(v1); + dhcp_client_opt_args.value= dmstrdup(v2); + dhcp_client_opt_args.opt_sect= dmmap_sect; + + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "bbf_dhcpv4_sentopt_instance", "bbf_dhcpv4_sentopt_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_client_opt_args, instance) == DM_STOP) + break; + } + return 0; +} + +static int browseDHCPv4ClientReqOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)prev_data; + struct uci_section *dmmap_sect; + struct dhcp_client_option_args dhcp_client_opt_args = {0}; + char *instance, *instnbr = NULL, *v1, **reqtopts = NULL, *v = NULL; + size_t length = 0; + int i; + + if (dhcp_client_args->dhcp_client_conf != NULL) + dmuci_get_value_by_section_string(dhcp_client_args->dhcp_client_conf, "reqopts", &v); + if (v) reqtopts = strsplit(v, " ", &length); + check_create_dmmap_package("dmmap_dhcp_client"); + for (i = 0; i < length; i++) { + if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcp_client", "req_option", section_name(dhcp_client_args->dhcp_client_conf), "option_tag", reqtopts[i])) == NULL) { + dmuci_add_section_bbfdm("dmmap_dhcp_client", "req_option", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", reqtopts[i]); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_client_args->dhcp_client_conf)); + } + } + + uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp_client", "req_option", "section_name", dhcp_client_args->dhcp_client_conf?section_name(dhcp_client_args->dhcp_client_conf):"", dmmap_sect) { + dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1); + dhcp_client_opt_args.client_sect = dhcp_client_args->dhcp_client_conf; + dhcp_client_opt_args.option_tag = dmstrdup(v1); + dhcp_client_opt_args.value = dmstrdup(""); + dhcp_client_opt_args.opt_sect = dmmap_sect; + + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "bbf_dhcpv4_reqtopt_instance", "bbf_dhcpv4_reqtopt_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_client_opt_args, instance) == DM_STOP) + break; + } + return 0; +} + +static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_list *dhcp_options_list = NULL; + struct uci_element *e; + struct dhcp_args *curr_dhcp_args = (struct dhcp_args*)prev_data; + struct uci_section *dmmap_sect; + char **tagvalue = NULL, *instance, *instnbr = NULL, *optionvalue = NULL, *tmp, *v1, *v2, *v; + size_t length; + int j; + struct dhcp_client_option_args dhcp_client_opt_args = {0}; + + dmuci_get_value_by_section_list(curr_dhcp_args->dhcp_sec, "dhcp_option", &dhcp_options_list); + if (dhcp_options_list != NULL) { + uci_foreach_element(dhcp_options_list, e) { + tagvalue = strsplit(e->name, ",", &length); + if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcp", "servpool_option", section_name(curr_dhcp_args->dhcp_sec), "option_tag", tagvalue[0])) == NULL) { + dmuci_add_section_bbfdm("dmmap_dhcp", "servpool_option", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", tagvalue[0]); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(curr_dhcp_args->dhcp_sec)); + } + optionvalue = dmstrdup(tagvalue[1]); + if (length > 2) { + for (j = 2; j < length; j++) { + tmp = dmstrdup(optionvalue); + dmfree(optionvalue); + optionvalue = NULL; + dmasprintf(&optionvalue, "%s,%s", tmp, tagvalue[j]); + dmfree(tmp); + tmp = NULL; + } + } + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_value", optionvalue); + } + } + uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp", "servpool_option", "section_name", section_name(curr_dhcp_args->dhcp_sec), dmmap_sect) { + dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1); + dmuci_get_value_by_section_string(dmmap_sect, "option_value", &v2); + dhcp_client_opt_args.client_sect = curr_dhcp_args->dhcp_sec; + dhcp_client_opt_args.option_tag = dmstrdup(v1); + dhcp_client_opt_args.value = dmstrdup(v2); + dhcp_client_opt_args.opt_sect = dmmap_sect; + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "bbf_dhcpv4_servpool_option_instance", "bbf_dhcpv4_servpool_option_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_client_opt_args, instance) == DM_STOP) + break; + } + return 0; +} + +static int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + //TODO + return 0; +} + +static char *get_dhcp_network_from_relay_list(char *net_list) +{ + struct uci_section *s; + char **net_list_arr, *v; + int i; + size_t length; + + net_list_arr = strsplit(net_list, " ", &length); + uci_foreach_sections("network", "interface", s) { + dmuci_get_value_by_section_string(s, "proto", &v); + for (i = 0; i < length; i++) { + if (strcmp(net_list_arr[i], section_name(s)) == 0 && strcmp(v, "dhcp") == 0) + return net_list_arr[i]; + } + } + return ""; +} + +struct uci_section* get_dhcp_classifier(char *classifier_name, char *network) +{ + struct uci_section* s = NULL; + char *v; + + uci_foreach_sections("dhcp", classifier_name, s) { + dmuci_get_value_by_section_string(s, "networkid", &v); + if (strcmp(v, network) == 0) + return s; + } + return NULL; +} + +/*#Device.DHCPv4.Relay.Forwarding.{i}.!UCI:network/interface/dmmap_dhcp_relay*/ +static int browseDHCPv4RelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *instance, *instnbr = NULL, *v, *dhcp_network = NULL; + struct dmmap_dup *p; + char *type, *ipv4addr = "", *ipv6addr = "", *proto, *inst, *mask4 = NULL; + json_object *res, *jobj; + struct dhcp_client_args dhcp_relay_arg = {0}; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap_eq_no_delete("network", "interface", "dmmap_dhcp_relay", "proto", "relay", &dup_list); + list_for_each_entry(p, &dup_list, list) { + if (p->config_section != NULL) { + dmuci_get_value_by_section_string(p->config_section, "type", &type); + if (strcmp(type, "alias") == 0 || strcmp(section_name(p->config_section), "loopback") == 0) + continue; + + dmuci_get_value_by_section_string(p->config_section, "ipaddr", &ipv4addr); + dmuci_get_value_by_section_string(p->config_section, "netmask", &mask4); + if (ipv4addr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + ipv4addr = dmjson_get_value(jobj, 1, "address"); + mask4= dmjson_get_value(jobj, 1, "mask"); + } + } + + dmuci_get_value_by_section_string(p->config_section, "ip6addr", &ipv6addr); + if (ipv6addr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); + ipv6addr = dmjson_get_value(jobj, 1, "address"); + } + } + + dmuci_get_value_by_section_string(p->config_section, "proto", &proto); + dmuci_get_value_by_section_string(p->config_section, "ip_int_instance", &inst); + if (ipv4addr[0] == '\0' && ipv6addr[0] == '\0' && strcmp(inst, "") == 0 && strcmp(type, "bridge") != 0 && strcmp(proto, "relay") != 0) { + p->config_section = NULL; + DMUCI_SET_VALUE_BY_SECTION(bbfdm, p->dmmap_section, "section_name", ""); + } + } + + if (ipv4addr == NULL || strlen(ipv4addr) == 0) + dhcp_relay_arg.ip = dmstrdup(""); + else + dhcp_relay_arg.ip = dmstrdup(ipv4addr); + if (mask4 == NULL || strlen(mask4) == 0) + dhcp_relay_arg.mask = dmstrdup(""); + else + dhcp_relay_arg.mask = dmstrdup(mask4); + if (p->config_section != NULL) + dmuci_get_value_by_section_string(p->config_section, "network", &v); + else + v = dmstrdup(""); + + dhcp_network = get_dhcp_network_from_relay_list(v); + if (dhcp_network && strlen(dhcp_network) > 0) { + dhcp_relay_arg.macclassifier = get_dhcp_classifier("mac", dhcp_network); + dhcp_relay_arg.vendorclassidclassifier = get_dhcp_classifier("vendorclass", dhcp_network); + dhcp_relay_arg.userclassclassifier = get_dhcp_classifier("userclass", dhcp_network); + } else { + dhcp_relay_arg.macclassifier = NULL; + dhcp_relay_arg.vendorclassidclassifier = NULL; + dhcp_relay_arg.userclassclassifier = NULL; + } + dhcp_relay_arg.dhcp_client_conf = p->config_section; + + dhcp_relay_arg.dhcp_client_dm= p->dmmap_section; + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, (void *)p->dmmap_section, "bbf_dhcpv4relay_instance", "bbf_dhcpv4relay_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_relay_arg, instance) == DM_STOP) + break; + } + return 0; +} + /*** DHCPv4. ***/ DMOBJ tDHCPv4Obj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -210,3173 +3381,3 @@ DMLEAF tDHCPv4RelayForwardingParams[] = { //{"DHCPServerIPAddress", &DMWRITE, DMT_STRING, get_DHCPv4RelayForwarding_DHCPServerIPAddress, set_DHCPv4RelayForwarding_DHCPServerIPAddress, NULL, NULL, BBFDM_BOTH}, {0} }; - -struct dhcp_lease { - uint64_t ts; - char hwaddr[20]; - char ipaddr[16]; - struct list_head list; -}; - -struct dhcp_args { - struct uci_section *dhcp_sec; - char *interface; - struct list_head leases; - unsigned n_leases; -}; - -struct dhcp_static_args { - struct uci_section *dhcpsection; -}; - -struct client_args { - const struct dhcp_lease *lease; -}; - -struct dhcp_client_args { - struct uci_section *dhcp_client_conf; - struct uci_section *dhcp_client_dm; - struct uci_section *macclassifier; - struct uci_section *vendorclassidclassifier; - struct uci_section *userclassclassifier; - char *ip; - char *mask; -}; - -struct dhcp_client_option_args { - struct uci_section *opt_sect; - struct uci_section *client_sect; - char *option_tag; - char *value; -}; - -/************************************************************************** -* LINKER -***************************************************************************/ -int get_dhcp_client_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - const struct client_args *args = data; - - *linker = (char *)args->lease->hwaddr; - return 0; -} - -/************************************************************* -* INIT -**************************************************************/ -static inline void init_dhcp_args(struct dhcp_args *args, struct uci_section *s, char *interface) -{ - args->interface = interface; - args->dhcp_sec = s; - INIT_LIST_HEAD(&args->leases); - args->n_leases = 0; -} - -static inline void init_args_dhcp_host(struct dhcp_static_args *args, struct uci_section *s) -{ - args->dhcpsection = s; -} - -static inline void init_dhcp_client_args(struct client_args *args, const struct dhcp_lease *lease) -{ - args->lease = lease; -} - -/************************************************************* -* Other functions -**************************************************************/ -struct uci_section* exist_other_section_same_order(struct uci_section *dmmap_sect, char * package, char* sect_type, char *order) -{ - struct uci_section *s; - uci_path_foreach_option_eq(bbfdm, package, sect_type, "order", order, s) { - if (strcmp(section_name(s), section_name(dmmap_sect)) != 0) { - return s; - } - } - return NULL; -} - -int set_section_order(char *package, char *dmpackage, char* sect_type, struct uci_section *dmmap_sect, struct uci_section *conf, int set_force, char* order) -{ - char *v = NULL, *sect_name, *incrorder; - struct uci_section *s, *dm; - - dmuci_get_value_by_section_string(dmmap_sect, "order", &v); - if (strlen(v) > 0 && strcmp(v, order) == 0) - return 0; - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "order", order); - if (conf == NULL) { - dmuci_get_value_by_section_string(dmmap_sect, "section_name", §_name); - get_config_section_of_dmmap_section(package, sect_type, sect_name, &s); - } else - s= conf; - - if (strcmp(order, "1") != 0 && s != NULL) { - dmuci_set_value_by_section(s, "force", ""); - } - - if (set_force == 1 && strcmp(order, "1") == 0 && s != NULL) { - dmuci_set_value_by_section(s, "force", "1"); - } - - if ((dm = exist_other_section_same_order(dmmap_sect, dmpackage, sect_type, order)) != NULL) { - dmuci_get_value_by_section_string(dm, "section_name", §_name); - get_config_section_of_dmmap_section(package, sect_type, sect_name, &s); - dmasprintf(&incrorder, "%d", atoi(order)+1); - if (s != NULL && strcmp(order, "1") == 0) { - dmuci_set_value_by_section(s, "force", ""); - } - set_section_order(package, dmpackage, sect_type, dm, s, set_force, incrorder); - } - return 0; - -} - -/*******************ADD-DEL OBJECT*********************/ -int add_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - char *value, *v; - char *instance; - struct uci_section *s = NULL, *dmmap_dhcp = NULL; - - check_create_dmmap_package("dmmap_dhcp"); - instance = get_last_instance_bbfdm("dmmap_dhcp", "dhcp", "dhcp_instance"); - dmuci_add_section("dhcp", "dhcp", &s, &value); - dmuci_set_value_by_section(s, "start", "100"); - dmuci_set_value_by_section(s, "leasetime", "12h"); - dmuci_set_value_by_section(s, "limit", "150"); - - dmuci_add_section_bbfdm("dmmap_dhcp", "dhcp", &dmmap_dhcp, &v); - dmuci_set_value_by_section(dmmap_dhcp, "section_name", section_name(s)); - *instancepara = update_instance_bbfdm(dmmap_dhcp, instance, "dhcp_instance"); - return 0; -} - -int delete_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - int found = 0; - struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; - - switch (del_action) { - case DEL_INST: - if(is_section_unnamed(section_name(((struct dhcp_args *)data)->dhcp_sec))){ - LIST_HEAD(dup_list); - delete_sections_save_next_sections("dmmap_dhcp", "dhcp", "dhcp_instance", section_name(((struct dhcp_args *)data)->dhcp_sec), atoi(instance), &dup_list); - update_dmmap_sections(&dup_list, "dhcp_instance", "dmmap_dhcp", "dhcp"); - dmuci_delete_by_section_unnamed(((struct dhcp_args *)data)->dhcp_sec, NULL, NULL); - } else { - get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(((struct dhcp_args *)data)->dhcp_sec), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); - dmuci_delete_by_section(((struct dhcp_args *)data)->dhcp_sec, NULL, NULL); - } - - break; - case DEL_ALL: - uci_foreach_sections("dhcp", "dhcp", s) { - if (found != 0){ - get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(s), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL){ - get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - break; - } - return 0; -} - -int add_dhcp_staticaddress(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - char *value, *v, *instance; - struct uci_section *s = NULL, *dmmap_dhcp_host= NULL; - - check_create_dmmap_package("dmmap_dhcp"); - instance = get_last_instance_lev2_bbfdm("dhcp", "host", "dmmap_dhcp", "ldhcpinstance", "dhcp", ((struct dhcp_args *)data)->interface); - dmuci_add_section("dhcp", "host", &s, &value); - dmuci_set_value_by_section(s, "dhcp", ((struct dhcp_args *)data)->interface); - - - dmuci_add_section_bbfdm("dmmap_dhcp", "host", &dmmap_dhcp_host, &v); - dmuci_set_value_by_section(dmmap_dhcp_host, "section_name", section_name(s)); - *instancepara = update_instance_bbfdm(dmmap_dhcp_host, instance, "ldhcpinstance"); - return 0; -} - -int delete_dhcp_staticaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - int found = 0; - struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; - struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)data; - - switch (del_action) { - case DEL_INST: - if (is_section_unnamed(section_name(dhcpargs->dhcpsection))) { - LIST_HEAD(dup_list); - delete_sections_save_next_sections("dmmap_dhcp", "host", "ldhcpinstance", section_name(dhcpargs->dhcpsection), atoi(instance), &dup_list); - update_dmmap_sections(&dup_list, "ldhcpinstance", "dmmap_dhcp", "host"); - dmuci_delete_by_section_unnamed(dhcpargs->dhcpsection, NULL, NULL); - } else { - get_dmmap_section_of_config_section("dmmap_dhcp", "host", section_name(dhcpargs->dhcpsection), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(dhcpargs->dhcpsection, NULL, NULL); - } - break; - case DEL_ALL: - uci_foreach_option_eq("dhcp", "host", "dhcp", ((struct dhcp_args *)data)->interface, s) { - if (found != 0) { - get_dmmap_section_of_config_section("dmmap_dhcp", "host", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - get_dmmap_section_of_config_section("dmmap_dhcp", "host", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - break; - } - return 0; -} - -int addObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct uci_section *s, *dmmap_sect; - char *wan_eth, *value, *wanname, *instancepara, *v; - - check_create_dmmap_package("dmmap_dhcp_client"); - instancepara = get_last_instance_bbfdm("dmmap_dhcp_client", "interface", "bbf_dhcpv4client_instance"); - dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_eth); - dmasprintf(&wanname, "%s.1", wan_eth); - dmuci_add_section("network", "interface", &s, &value); - dmuci_set_value_by_section(s, "proto", "dhcp"); - dmuci_set_value_by_section(s, "ifname", wanname); - dmuci_set_value_by_section(s, "type", "anywan"); - dmuci_add_section_bbfdm("dmmap_dhcp_client", "interface", &dmmap_sect, &v); - dmuci_set_value_by_section(dmmap_sect, "section_name", section_name(s)); - *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv4client_instance"); - return 0; -} - -int delObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)data; - struct uci_section *s, *dmmap_section, *stmp; - json_object *res, *jobj; - - char *v; - char *type, *ipv4addr = "", *ipv6addr = "", *proto, *mask4; - - switch (del_action) { - case DEL_INST: - if (dhcp_client_args->dhcp_client_conf != NULL) { - dmuci_set_value_by_section(dhcp_client_args->dhcp_client_conf, "proto", "static"); - if (strlen(dhcp_client_args->ip) == 0) { - dmasprintf(&ipv4addr, "%s.%s.%s.%s", instance, instance, instance, instance); - dmasprintf(&mask4, "%s", "255.255.255.0"); - } else { - dmasprintf(&ipv4addr, "%s", dhcp_client_args->ip); - dmasprintf(&mask4, "%s", dhcp_client_args->mask); - } - dmuci_set_value_by_section(dhcp_client_args->dhcp_client_conf, "ipaddr", ipv4addr); - dmuci_set_value_by_section(dhcp_client_args->dhcp_client_conf, "netmask", mask4); - } - dmuci_delete_by_section_unnamed_bbfdm(dhcp_client_args->dhcp_client_dm, NULL, NULL); - break; - case DEL_ALL: - uci_foreach_sections("network", "interface", s) { - dmuci_get_value_by_section_string(s, "type", &type); - if (strcmp(type, "alias") == 0 || strcmp(section_name(s), "loopback") == 0) - continue; - dmuci_get_value_by_section_string(s, "ipaddr", &ipv4addr); - dmuci_get_value_by_section_string(s, "netmask", &mask4); - if (ipv4addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - ipv4addr = dmjson_get_value(jobj, 1, "address"); - mask4= dmjson_get_value(jobj, 1, "mask"); - } - } - dmuci_get_value_by_section_string(s, "ip6addr", &ipv6addr); - if (ipv6addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); - ipv6addr = dmjson_get_value(jobj, 1, "address"); - } - } - dmuci_get_value_by_section_string(s, "proto", &proto); - if (ipv4addr[0] == '\0' && ipv6addr[0] == '\0' && strcmp(proto, "dhcp") != 0 && strcmp(proto, "dhcpv6") != 0 && strcmp(type, "bridge") != 0) - continue; - - dmuci_set_value_by_section(s, "proto", "static"); - - get_dmmap_section_of_config_section("dmmap_dhcp_client", "interface", section_name(s), &dmmap_section); - if (strlen(ipv4addr) == 0) { - if(dmmap_section != NULL) - dmuci_get_value_by_section_string(dmmap_section, "bbf_dhcpv4client_instance", &v); - else - dmasprintf(&v, "%d", 0); - - dmasprintf(&ipv4addr, "%s.%s.%s.%s", v, v, v, v); - dmasprintf(&mask4, "%s", "255.255.255.0"); - } - dmuci_set_value_by_section(s, "ipaddr", ipv4addr); - dmuci_set_value_by_section(s, "netmask", mask4); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - } - uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcp_client", "interface", stmp, s) { - dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); - } - break; - } - return 0; -} - -int addObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)data; - struct uci_section *dmmap_sect; - char *value, *instancepara; - - check_create_dmmap_package("dmmap_dhcp_client"); - instancepara = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_dhcp_client", "send_option", "bbf_dhcpv4_sentopt_instance", "section_name", section_name(dhcp_client_args->dhcp_client_conf)); - dmuci_add_section_bbfdm("dmmap_dhcp_client", "send_option", &dmmap_sect, &value); - if(dhcp_client_args->dhcp_client_conf != NULL) - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_client_args->dhcp_client_conf)); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", "0"); - *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv4_sentopt_instance"); - return 0; -} - -int delObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *s, *stmp; - char *list= NULL, *opt_value= NULL; - - switch (del_action) { - case DEL_INST: - if(strcmp(((struct dhcp_client_option_args*) data)->option_tag, "0") != 0) - { - dmasprintf(&opt_value, "%s:%s", ((struct dhcp_client_option_args*) data)->option_tag, ((struct dhcp_client_option_args*) data)->value); - dmuci_get_value_by_section_string(((struct dhcp_client_option_args*) data)->client_sect, "sendopts", &list); - if(list != NULL){ - remove_elt_from_str_list(&list, opt_value); - dmuci_set_value_by_section(((struct dhcp_client_option_args*) data)->client_sect, "sendopts", list); - } - } - dmuci_delete_by_section_unnamed_bbfdm(((struct dhcp_client_option_args*) data)->opt_sect, NULL, NULL); - break; - case DEL_ALL: - dmuci_set_value_by_section(((struct dhcp_client_args*) data)->dhcp_client_conf, "sendopts", ""); - uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcp_client", "send_option", stmp, s) { - dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); - } - break; - } - return 0; -} - -int addObjDHCPv4ClientReqOption(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)data; - struct uci_section *dmmap_sect; - char *value, *instancepara; - - check_create_dmmap_package("dmmap_dhcp_client"); - instancepara = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_dhcp_client", "req_option", "bbf_dhcpv4_sentopt_instance", "section_name", section_name(dhcp_client_args->dhcp_client_conf)); - dmuci_add_section_bbfdm("dmmap_dhcp_client", "req_option", &dmmap_sect, &value); - if(dhcp_client_args->dhcp_client_conf != NULL) - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_client_args->dhcp_client_conf)); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", "0"); - *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv4_sentopt_instance"); - return 0; -} - -int delObjDHCPv4ClientReqOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *s, *stmp; - char *list = NULL; - - switch (del_action) { - case DEL_INST: - if (strcmp(((struct dhcp_client_option_args*) data)->option_tag, "0") != 0) { - dmuci_get_value_by_section_string(((struct dhcp_client_option_args*) data)->client_sect, "reqopts", &list); - if (list != NULL) { - remove_elt_from_str_list(&list, ((struct dhcp_client_option_args*) data)->option_tag); - dmuci_set_value_by_section(((struct dhcp_client_option_args*) data)->client_sect, "reqopts", list); - } - } - dmuci_delete_by_section_unnamed_bbfdm(((struct dhcp_client_option_args*) data)->opt_sect, NULL, NULL); - break; - case DEL_ALL: - dmuci_set_value_by_section(((struct dhcp_client_args*) data)->dhcp_client_conf, "reqopts", ""); - uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcp_client", "req_option", stmp, s) { - dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); - } - break; - } - return 0; -} - -int addObjDHCPv4ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct dhcp_args *dhcp_arg = (struct dhcp_args*)data; - struct uci_section *dmmap_sect; - char *value, *instancepara; - - check_create_dmmap_package("dmmap_dhcp"); - instancepara = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_dhcp", "servpool_option", "bbf_dhcpv4_servpool_option_instance", "section_name", section_name(dhcp_arg->dhcp_sec)); - dmuci_add_section_bbfdm("dmmap_dhcp", "servpool_option", &dmmap_sect, &value); - if(dhcp_arg->dhcp_sec != NULL) - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_arg->dhcp_sec)); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", "0"); - *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv4_servpool_option_instance"); - return 0; -} - -int delObjDHCPv4ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *s, *stmp; - char *opt_value = NULL; - struct uci_list *dhcp_options_list = NULL; - - switch (del_action) { - case DEL_INST: - if (strcmp(((struct dhcp_client_option_args*) data)->option_tag, "0") != 0) { - dmasprintf(&opt_value, "%s,%s", ((struct dhcp_client_option_args*) data)->option_tag, ((struct dhcp_client_option_args*) data)->value); - dmuci_get_value_by_section_list(((struct dhcp_client_option_args*) data)->client_sect, "dhcp_option", &dhcp_options_list); - if (dhcp_options_list != NULL) { - dmuci_del_list_value_by_section(((struct dhcp_client_option_args*) data)->client_sect, "dhcp_option", opt_value); - } - } - dmuci_delete_by_section_unnamed_bbfdm(((struct dhcp_client_option_args*) data)->opt_sect, NULL, NULL); - break; - case DEL_ALL: - dmuci_set_value_by_section(((struct dhcp_args*) data)->dhcp_sec, "dhcp_option", ""); - uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcp", "servpool_option", stmp, s) { - dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); - } - break; - } - return 0; -} - -int addObjDHCPv4RelayForwarding(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct uci_section *s, *dmmap_sect; - char *value, *instancepara, *v; - - check_create_dmmap_package("dmmap_dhcp_relay"); - instancepara = get_last_instance_bbfdm("dmmap_dhcp_relay", "interface", "bbf_dhcpv4relay_instance"); - dmuci_add_section("network", "interface", &s, &value); - dmuci_set_value_by_section(s, "proto", "relay"); - dmuci_add_section_bbfdm("dmmap_dhcp_relay", "interface", &dmmap_sect, &v); - dmuci_set_value_by_section(dmmap_sect, "section_name", section_name(s)); - *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv4relay_instance"); - return 0; -} - -int delObjDHCPv4RelayForwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct dhcp_client_args *dhcp_relay_args = (struct dhcp_client_args*)data; - struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; - char *proto = NULL; - int found = 0; - - switch (del_action) { - case DEL_INST: - if (is_section_unnamed(section_name(dhcp_relay_args->dhcp_client_conf))) { - LIST_HEAD(dup_list); - delete_sections_save_next_sections("dmmap_dhcp_relay", "interface", "bbf_dhcpv4relay_instance", section_name(dhcp_relay_args->dhcp_client_conf), atoi(instance), &dup_list); - update_dmmap_sections(&dup_list, "bbf_dhcpv4relay_instance", "dmmap_dhcp_relay", "interface"); - dmuci_delete_by_section_unnamed(dhcp_relay_args->dhcp_client_conf, NULL, NULL); - } else { - get_dmmap_section_of_config_section("dmmap_dhcp_relay", "interface", section_name(dhcp_relay_args->dhcp_client_conf), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); - dmuci_delete_by_section(dhcp_relay_args->dhcp_client_conf, NULL, NULL); - } - break; - case DEL_ALL: - uci_foreach_sections("network", "interface", s) { - if (found != 0) { - dmuci_get_value_by_section_string(ss, "proto", &proto); - if (strcmp(proto, "relay") == 0) { - get_dmmap_section_of_config_section("dmmap_dhcp_relay", "interface", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - } - ss = s; - found++; - } - if (ss != NULL) { - dmuci_get_value_by_section_string(ss, "proto", &proto); - if (strcmp(proto, "relay") == 0) { - get_dmmap_section_of_config_section("dmmap_dhcp_relay", "interface", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - } - break; - } - return 0; -} - -/************************************************************* -* GET & SET PARAM -**************************************************************/ -int get_server_pool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_sect = NULL; - - get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(((struct dhcp_args *)data)->dhcp_sec), &dmmap_sect); - if (dmmap_sect) - dmuci_get_value_by_section_string(dmmap_sect, "dhcp_alias", value); - return 0; -} - -int set_server_pool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_sect = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(((struct dhcp_args *)data)->dhcp_sec), &dmmap_sect); - if (dmmap_sect) - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "dhcp_alias", value); - return 0; - } - return 0; -} - -/*#Device.DHCPv4.Server.Pool.{i}.DNSServers!UBUS:network.interface/status/interface,@Name/dns-server*/ -int get_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res = NULL; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); - if (res) { - *value = dmjson_get_value_array_all(res, DELIMITOR, 1, "dns-server"); - } else - *value = ""; - if ((*value)[0] == '\0') { - dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "dns", value); - *value = dmstrdup(*value); // MEM WILL BE FREED IN DMMEMCLEAN - char *p = *value; - while (*p) { - if (*p == ' ' && p != *value && *(p-1) != ',') - *p++ = ','; - else - p++; - } - } - if ((*value)[0] == '\0') { - dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", value); - } - return 0; -} - -int set_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *dup, *p; - - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, "4", NULL, NULL, "15", NULL, IPv4Address)) - return FAULT_9007; - return 0; - case VALUESET: - dup = dmstrdup(value); - p = dup; - while (*p) { - if (*p == ',') - *p++ = ' '; - else - p++; - } - dmuci_set_value("network", ((struct dhcp_args *)data)->interface, "dns", dup); - dmfree(dup); - return 0; - } - return 0; -} - -int get_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - *value = "1"; - return 0; - } - *value = "0"; - return 0; -} - -int set_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - if (!b) { - dmuci_delete_by_section(s, NULL, NULL); - } - break; - } - if (s == NULL && b) { - dmuci_set_value("dhcp",((struct dhcp_args *)data)->interface, NULL, "dhcp"); - dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "interface", ((struct dhcp_args *)data)->interface); - dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "start", "100"); - dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "limit", "150"); - dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "leasetime", "12h"); - } - return 0; - } - return 0; -} - -/*#Device.DHCPv4.Server.Pool.{i}.Status!UCI:dhcp/interface,@i-1/ignore*/ -int get_dhcp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - char *v = NULL; - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - dmuci_get_value_by_section_string(s, "ignore", &v); - *value = (v && *v == '1') ? "Disabled" : "Enabled"; - return 0; - } - *value = "Error_Misconfigured"; - return 0; -} - -int get_dhcp_sever_pool_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_sect = NULL; - - get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(((struct dhcp_args *)data)->dhcp_sec), &dmmap_sect); - if (dmmap_sect) - dmuci_get_value_by_section_string(dmmap_sect, "order", value); - return 0; -} - -int set_dhcp_sever_pool_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_sect = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", NULL)) - return FAULT_9007; - break; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_dhcp", "dhcp", section_name(((struct dhcp_args *)data)->dhcp_sec), &dmmap_sect); - if (dmmap_sect) - set_section_order("dhcp", "dmmap_dhcp", "dhcp", dmmap_sect, ((struct dhcp_args *)data)->dhcp_sec, 1, value); - break; - } - return 0; -} - -/*#Device.DHCPv4.Server.Pool.{i}.StaticAddressNumberOfEntries!UCI:dhcp/host/*/ -int get_static_address_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int i = 0; - - uci_foreach_sections("dhcp", "host", s) { - i++; - } - dmasprintf(value, "%d", i); - return 0; -} - -int get_option_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *dhcp_options_list = NULL; - struct uci_element *e; - int i= 0; - - dmuci_get_value_by_section_list(((struct dhcp_args *)data)->dhcp_sec, "dhcp_option", &dhcp_options_list); - if (dhcp_options_list != NULL) { - uci_foreach_element(dhcp_options_list, e) { - i++; - } - } - dmasprintf(value, "%d", i); - return 0; -} - -int get_clients_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - const struct dhcp_args *dhcp = data; - - dmasprintf(value, "%u", dhcp->n_leases); - return 0; -} - -/*#Device.DHCPv4.Server.Pool.{i}.Enable!UCI:dhcp/interface,@i-1/ignore*/ -int get_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - dmuci_get_value_by_section_string(s, "ignore", value); - if ((*value)[0] == '\0') - *value = "1"; - else - *value = "0"; - return 0; - } - *value = "0"; - return 0; -} - -int set_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - dmuci_set_value_by_section(s, "ignore", b ? "0" : "1"); - break; - } - return 0; - } - return 0; -} - -enum enum_lanip_interval_address { - LANIP_INTERVAL_START, - LANIP_INTERVAL_END -}; - -int get_dhcp_interval_address(struct dmctx *ctx, void *data, char *instance, char **value, int option) -{ - json_object *res, *jobj; - char bufipstart[16], bufipend[16], *ipaddr = "" , *mask = "", *start , *limit; - struct uci_section *s = NULL; - - *value = ""; - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - dmuci_get_value_by_section_string(s, "start", &start); - if (option == LANIP_INTERVAL_END) - dmuci_get_value_by_section_string(s, "limit", &limit); - break; - } - if (s == NULL) { - return 0; - } - dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", &ipaddr); - if (ipaddr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - ipaddr = dmjson_get_value(jobj, 1, "address"); - } - } - if (ipaddr[0] == '\0') { - return 0; - } - dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", &mask); - if (mask[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - mask = dmjson_get_value(jobj, 1, "mask"); - if (mask[0] == '\0') { - return 0; - } - mask = cidr2netmask(atoi(mask)); - } - } - if (mask[0] == '\0') { - mask = "255.255.255.0"; - } - if (option == LANIP_INTERVAL_START) { - ipcalc(ipaddr, mask, start, NULL, bufipstart, NULL); - *value = dmstrdup(bufipstart); // MEM WILL BE FREED IN DMMEMCLEAN - } else { - ipcalc(ipaddr, mask, start, limit, bufipstart, bufipend); - *value = dmstrdup(bufipend); // MEM WILL BE FREED IN DMMEMCLEAN - } - return 0; -} - -/*#Device.DHCPv4.Server.Pool.{i}.MinAddress!UCI:dhcp/interface,@i-1/start*/ -int get_dhcp_interval_address_min(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - get_dhcp_interval_address(ctx, data, instance, value, LANIP_INTERVAL_START); - return 0; -} - -/*#Device.DHCPv4.Server.Pool.{i}.MaxAddress!UCI:dhcp/interface,@i-1/limit*/ -int get_dhcp_interval_address_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - get_dhcp_interval_address(ctx, data, instance, value, LANIP_INTERVAL_END); - return 0; -} - -int set_dhcp_address_min(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - json_object *res, *jobj; - char *ipaddr = "", *mask = "", buf[16]; - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", &ipaddr); - if (ipaddr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - ipaddr = dmjson_get_value(jobj, 1, "address"); - } - } - if (ipaddr[0] == '\0') - return 0; - - dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", &mask); - if (mask[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - mask = dmjson_get_value(jobj, 1, "mask"); - if (mask[0] == '\0') - return 0; - mask = cidr2netmask(atoi(mask)); - } - } - if (mask[0] == '\0') - mask = "255.255.255.0"; - - ipcalc_rev_start(ipaddr, mask, value, buf); - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - dmuci_set_value_by_section(s, "start", buf); - break; - } - - return 0; - } - return 0; -} - -int set_dhcp_address_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - json_object *res, *jobj; - char *ipaddr = "", *mask = "", *start, buf[16]; - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) - return FAULT_9007; - return 0; - case VALUESET: - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - dmuci_get_value_by_section_string(s, "start", &start); - break; - } - if (!s) return 0; - - dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", &ipaddr); - if (ipaddr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - ipaddr = dmjson_get_value(jobj, 1, "address"); } - } - if (ipaddr[0] == '\0') - return 0; - - dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", &mask); - if (mask[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - mask = dmjson_get_value(jobj, 1, "mask"); - if (mask[0] == '\0') - return 0; - mask = cidr2netmask(atoi(mask)); - } - } - if (mask[0] == '\0') - mask = "255.255.255.0"; - - ipcalc_rev_end(ipaddr, mask, start, value, buf); - dmuci_set_value_by_section(s, "limit", buf); - return 0; - } - return 0; -} - - -int get_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char val[512] = {0}, *p; - struct uci_section *s = NULL; - char *min, *max, *ip; - unsigned int n_min, n_max, n_ip; - *value = ""; - - get_dhcp_interval_address(ctx, data, instance, &min, LANIP_INTERVAL_START); - get_dhcp_interval_address(ctx, data, instance, &max, LANIP_INTERVAL_END); - if (min[0] == '\0' || max[0] == '\0') - return 0; - n_min = inet_network(min); - n_max = inet_network(max); - p = val; - uci_foreach_sections("dhcp", "host", s) { - dmuci_get_value_by_section_string(s, "ip", &ip); - if (ip[0] == '\0') - continue; - n_ip = inet_network(ip); - if (n_ip >= n_min && n_ip <= n_max) { - if (val[0] != '\0') - dmstrappendchr(p, ','); - dmstrappendstr(p, ip); - } - } - dmstrappendend(p); - *value = dmstrdup(val); // MEM WILL BE FREED IN DMMEMCLEAN - return 0; -} - -int set_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *s = NULL, *dhcp_section = NULL; - char *min, *max, *val, *local_value, *pch, *spch; - unsigned int n_min, n_max, n_ip, ipexist= 0; - - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, "32", NULL, NULL, "15", NULL, IPv4Address)) - return FAULT_9007; - return 0; - case VALUESET: - get_dhcp_interval_address(ctx, data, instance, &min, LANIP_INTERVAL_START); - get_dhcp_interval_address(ctx, data, instance, &max, LANIP_INTERVAL_END); - n_min = inet_network(min); - n_max = inet_network(max); - local_value = dmstrdup(value); - - for (pch = strtok_r(local_value, ",", &spch); - pch != NULL; - pch = strtok_r(NULL, ",", &spch)) { - uci_foreach_option_eq("dhcp", "host", "ip", pch, s) { - ipexist = 1; - } - if(ipexist) - continue; - n_ip = inet_network(pch); - - if (n_ip < n_min || n_ip > n_max) - continue; - - dmuci_add_section_and_rename("dhcp", "host", &dhcp_section, &val); - dmuci_set_value_by_section(dhcp_section, "dhcp", ((struct dhcp_args *)data)->interface); - dmuci_set_value_by_section(dhcp_section, "ip", pch); - } - dmfree(local_value); - return 0; - } - return 0; -} - -/*#Device.DHCPv4.Server.Pool.{i}.SubnetMask!UCI:dhcp/interface,@i-1/netmask*/ -int get_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *mask; - json_object *res, *jobj; - struct uci_section *s = NULL; - char *val; - *value = ""; - - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - dmuci_get_value_by_section_string(s, "netmask", value); - break; - } - if (s == NULL || (*value)[0] == '\0') - dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", value); - if ((*value)[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); - DM_ASSERT(res, *value = ""); - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - mask = dmjson_get_value(jobj, 1, "mask"); - int i_mask = atoi(mask); - val = cidr2netmask(i_mask); - *value = dmstrdup(val);// MEM WILL BE FREED IN DMMEMCLEAN - } - return 0; -} - -int set_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) - return FAULT_9007; - return 0; - case VALUESET: - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - dmuci_set_value_by_section(s, "netmask", value); - return 0; - } - return 0; - } - return 0; -} - -int get_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "gateway", value); - if ((*value)[0] == '\0') { - dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", value); - } - return 0; -} - -int set_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, "4", NULL, NULL, "15", NULL, IPv4Address)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("network", ((struct dhcp_args *)data)->interface, "gateway", value); - return 0; - } - return 0; -} - -/*#Device.DHCPv4.Server.Pool.{i}.LeaseTime!UCI:dhcp/interface,@i-1/leasetime*/ -int get_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - int mtime = 0; - char *ltime = "", *pch, *spch, *ltime_ini, *tmp, *tmp_ini; - struct uci_section *s = NULL; - - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - dmuci_get_value_by_section_string(s, "leasetime", <ime); - break; - } - if (ltime[0] == '\0') { - *value = "-1"; - return 0; - } - ltime = dmstrdup(ltime); - ltime_ini = dmstrdup(ltime); - tmp = ltime; - tmp_ini = ltime_ini; - pch = strtok_r(ltime, "h", &spch); - if (strcmp(pch, ltime_ini) != 0) { - mtime = 3600 * atoi(pch); - if(spch[0] != '\0') { - ltime += strlen(pch)+1; - ltime_ini += strlen(pch)+1; - pch = strtok_r(ltime, "m", &spch); - if (strcmp(pch, ltime_ini) != 0) { - mtime += 60 * atoi(pch); - if(spch[0] !='\0') { - ltime += strlen(pch)+1; - ltime_ini += strlen(pch)+1; - pch = strtok_r(ltime, "s", &spch); - if (strcmp(pch, ltime_ini) != 0) { - mtime += atoi(pch); - } - } - } else { - pch = strtok_r(ltime, "s", &spch); - if (strcmp(pch, ltime_ini) != 0) - mtime += atoi(pch); - } - } - } else { - pch = strtok_r(ltime, "m", &spch); - if (strcmp(pch, ltime_ini) != 0) { - mtime += 60 * atoi(pch); - if(spch[0] !='\0') { - ltime += strlen(pch)+1; - ltime_ini += strlen(pch)+1; - pch = strtok_r(ltime, "s", &spch); - if (strcmp(pch, ltime_ini) != 0) { - mtime += atoi(pch); - } - } - } else { - pch = strtok_r(ltime, "s", &spch); - if (strcmp(pch, ltime_ini) != 0) - mtime += atoi(pch); - } - } - dmfree(tmp); - dmfree(tmp_ini); - - dmasprintf(value, "%d", mtime); // MEM WILL BE FREED IN DMMEMCLEAN - return 0; -} - -int set_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *s = NULL; - char buf[32]; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - return 0; - case VALUESET: - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - int val = atoi(value); - snprintf(buf, sizeof(buf), "%ds", val); - dmuci_set_value_by_section(s, "leasetime", buf); - break; - } - return 0; - } - return 0; -} - -int get_dhcp_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *linker; - linker = dmstrdup(((struct dhcp_args *)data)->interface); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; - dmfree(linker); - return 0; -} - -int set_dhcp_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *linker; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); - if (linker) { - dmuci_set_value_by_section(((struct dhcp_args *)data)->dhcp_sec, "interface", linker); - dmfree(linker); - } - return 0; - } - return 0; -} - -int get_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *str; - struct uci_list *val; - struct uci_element *e = NULL; - struct uci_section *s = NULL; - *value = ""; - - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - dmuci_get_value_by_section_list(s, "dhcp_option", &val); - if (val) { - uci_foreach_element(val, e) { - if ((str = strstr(e->name, "15,"))) { - *value = dmstrdup(str + sizeof("15,") - 1); //MEM WILL BE FREED IN DMMEMCLEAN - return 0; - } - } - } - } - return 0; -} - -int set_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_list *val; - struct uci_section *s = NULL; - struct uci_element *e = NULL, *tmp; - char *option = "dhcp_option", buf[64]; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { - dmuci_get_value_by_section_list(s, option, &val); - if (val) { - uci_foreach_element_safe(val, e, tmp) { - if (strstr(tmp->name, "15,")) { - dmuci_del_list_value_by_section(s, "dhcp_option", tmp->name); - } - } - } - break; - } - goto end; - } -end: - snprintf(buf, sizeof(buf), "15,%s", value); - dmuci_add_list_value_by_section(((struct dhcp_args *)data)->dhcp_sec, "dhcp_option", buf); - return 0; -} - -int get_dhcp_static_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - get_dmmap_section_of_config_section("dmmap_dhcp", "host", section_name(((struct dhcp_static_args *)data)->dhcpsection), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "ldhcpalias", value); - return 0; -} - -int set_dhcp_static_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_dhcp", "host", section_name(((struct dhcp_static_args *)data)->dhcpsection), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "ldhcpalias", value); - return 0; - } - return 0; -} - -/*#Device.DHCPv4.Server.Pool.{i}.StaticAddress.{i}.Chaddr!UCI:dhcp/host,@i-1/mac*/ -int get_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *chaddr; - - dmuci_get_value_by_section_string(((struct dhcp_static_args *)data)->dhcpsection, "mac", &chaddr); - if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) - dmuci_get_value_by_section_string(((struct dhcp_static_args *)data)->dhcpsection, "mac_orig", value); - else - *value = chaddr; - return 0; -} - -int set_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *chaddr; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct dhcp_static_args *)data)->dhcpsection, "mac", &chaddr); - if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) - dmuci_set_value_by_section(((struct dhcp_static_args *)data)->dhcpsection, "mac_orig", value); - else - dmuci_set_value_by_section(((struct dhcp_static_args *)data)->dhcpsection, "mac", value); - return 0; - } - return 0; -} - -/*#Device.DHCPv4.Server.Pool.{i}.StaticAddress.{i}.Yiaddr!UCI:dhcp/host,@i-1/ip*/ -int get_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dhcp_static_args *)data)->dhcpsection, "ip", value); - return 0; -} - -int set_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section(((struct dhcp_static_args *)data)->dhcpsection, "ip", value); - return 0; - } - return 0; -} - -int get_dhcp_client_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - const struct client_args *args = data; - - *value = (char *)args->lease->hwaddr; - return 0; -} - -int get_dhcp_client_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "true"; - return 0; -} - -int get_dhcp_client_ipv4address_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - const struct client_args *args = data; - - return dm_time_format(args->lease->ts, value); -} - -int get_dhcp_client_ipv4address_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - const struct client_args *args = data; - - *value = (char *)args->lease->ipaddr; - return 0; -} - -int get_DHCPv4_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s, *dmmap_sect; - int nbre_confs = 0, nbre_dmmaps = 0; - - uci_foreach_option_eq("network", "interface", "proto", "dhcp", s) { - nbre_confs++; - } - uci_path_foreach_sections(bbfdm, "dmmap_dhcp_client", "interface", dmmap_sect) { - nbre_dmmaps++; - } - if (nbre_dmmaps == 0 || nbre_dmmaps < nbre_confs) - dmasprintf(value, "%d", nbre_confs); - else - dmasprintf(value, "%d", nbre_dmmaps); - return 0; -} - -/*#Device.DHCPv4.Client.{i}.Enable!UCI:network/interface,@i-1/disabled*/ -int get_DHCPv4Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v = NULL; - - if(((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { - *value = "0"; - return 0; - } - - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", &v); - - if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) - *value = "1"; - else - *value = "0"; - - return 0; -} - -int set_DHCPv4Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", b ? "0" : "1"); - return 0; - } - return 0; -} - -int get_DHCPv4Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_dm, "bbf_dhcpv4client_alias", value); - - return 0; -} - -int set_DHCPv4Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->dhcp_client_dm, "bbf_dhcpv4client_alias", value); - break; - } - return 0; -} - -int get_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - if(((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { - *value = ""; - return 0; - } - char *linker = dmstrdup(section_name(((struct dhcp_client_args *)data)->dhcp_client_conf)); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - *value = ""; - return 0; -} - -int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *s; - char *linker = NULL, *newvalue = NULL, *v; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - - if(strlen(value) == 0 || strcmp(value, "") == 0) - return FAULT_9007; - - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); - uci_path_foreach_sections(bbfdm, "dmmap_dhcp_client", "interface", s) { - dmuci_get_value_by_section_string(s, "section_name", &v); - if(strcmp(v, linker) == 0) - return FAULT_9007; - } - uci_foreach_sections("network", "interface", s) { - if(strcmp(section_name(s), linker) == 0){ - dmuci_get_value_by_section_string(s, "proto", &v); - if(strcmp(v, "dhcp") != 0) - return FAULT_9007; - } - } - break; - case VALUESET: - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_args *)data)->dhcp_client_dm, "section_name", linker); - break; - } - return 0; -} - -/*#Device.DHCPv4.Client.{i}.Status!UCI:network/interface,@i-1/disabled*/ -int get_DHCPv4Client_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v = NULL; - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { - *value = "Error_Misconfigured"; - return 0; - } - - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", &v); - if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) - *value = "Enabled"; - else - *value = "Disabled"; - - return 0; -} - -/*#Device.DHCPv4.Client.{i}.DHCPStatus!UBUS:network.interface/status/interface,@Name/ipv4-address[@i-1].address*/ -int get_DHCPv4Client_DHCPStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *ipaddr = ""; - json_object *res, *jobj; - - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) - return 0; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - ipaddr = dmjson_get_value(jobj, 1, "address"); - } - - if (ipaddr[0] == '\0') - *value = "Requesting"; - else - *value = "Bound"; - - return 0; -} - -int get_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "false"; - return 0; -} - -int set_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - json_object *res; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL && strcasecmp(value, "true") != 0) - return 0; - - dmubus_call("network.interface", "renew", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); - break; - } - return 0; -} - -int get_DHCPv4Client_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(((struct dhcp_client_args *)data)->ip); - return 0; -} - -int get_DHCPv4Client_SubnetMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(((struct dhcp_client_args *)data)->mask); - return 0; -} - -/*#Device.DHCPv4.Client.{i}.IPRouters!UBUS:network.interface/status/interface,@Name/route[@i-1].target*/ -int get_DHCPv4Client_IPRouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v, buf[256] = ""; - json_object *jobj = NULL, *res; - int i = 0; - - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) - return 0; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); - DM_ASSERT(res, *value = ""); - while (1) { - jobj = dmjson_select_obj_in_array_idx(res, i, 1, "route"); - i++; - - if (jobj == NULL) - break; - - v = dmjson_get_value(jobj, 1, "target"); - if (*v == '\0') - continue; - if (strcmp(v, "0.0.0.0") == 0) - continue; - if (buf[0] != '\0') { - strcat(buf, ","); - } else - strcat(buf, v); - } - *value = dmstrdup(buf); - - return 0; -} - -/*#Device.DHCPv4.Client.{i}.DNSServers!UBUS:network.interface/status/interface,@Name/dns-server*/ -int get_DHCPv4Client_DNSServers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) - return 0; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value_array_all(res, DELIMITOR, 1, "dns-server"); - return 0; -} - -/*#Device.DHCPv4.Client.{i}.LeaseTimeRemaining!UBUS:network.interface/status/interface,@Name/data.leasetime*/ -int get_DHCPv4Client_LeaseTimeRemaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) - return 0; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcp_client_args *)data)->dhcp_client_conf), String}}, 1, &res); - if (!res) { - *value = ""; - return 0; - } - *value = dmjson_get_value(res, 2, "data", "leasetime"); - return 0; -} - -int get_DHCPv4Client_DHCPServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv4Client_PassthroughEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4Client_PassthroughEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv4Client_PassthroughDHCPPool(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4Client_PassthroughDHCPPool(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.DHCPv4.Client.{i}.SentOptionNumberOfEntries!UCI:network/interface,@i-1/sendopts*/ -int get_DHCPv4Client_SentOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v = NULL; - size_t length; - - if (((struct dhcp_client_args *)data)->dhcp_client_conf != NULL) - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "sendopts", &v); - if (v == NULL) { - *value = "0"; - return 0; - } - strsplit(v, " ", &length); - dmasprintf(value, "%d", length); - return 0; -} - -/*#Device.DHCPv4.Client.{i}.ReqOptionNumberOfEntries!UCI:network/interface,@i-1/reqopts*/ -int get_DHCPv4Client_ReqOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v = NULL; - size_t length; - - if (((struct dhcp_client_args *)data)->dhcp_client_conf != NULL) - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "reqopts", &v); - if (v == NULL) { - *value = "0"; - return 0; - } - strsplit(v, " ", &length); - dmasprintf(value, "%d", length); - return 0; -} - -int get_DHCPv4ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v, *opttagvalue = NULL; - - if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) { - *value = "0"; - return 0; - } - dmasprintf(&opttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &v); - if (is_elt_exit_in_str_list(v, opttagvalue)) - *value = "1"; - else - *value = "0"; - - return 0; -} - -int set_DHCPv4ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - char *v, *opttagvalue= NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &v); - if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) - return 0; - dmasprintf(&opttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); - if (b) { - if (!is_elt_exit_in_str_list(v, opttagvalue)) { - add_elt_to_str_list(&v, opttagvalue); - dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", v); - } - } else { - remove_elt_from_str_list(&v, opttagvalue); - dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", v); - } - break; - } - return 0; -} - -int get_DHCPv4ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_sentopt_alias", value); - return 0; -} - -int set_DHCPv4ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_sentopt_alias", value); - break; - } - return 0; -} - -int get_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(((struct dhcp_client_option_args *)data)->option_tag); - return 0; -} - -int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *pch, *spch, *list, *v, *opttagvalue, **sendopts, *oldopttagvalue; - size_t length; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", "254")) - return FAULT_9007; - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &v); - if (v == NULL) - return 0; - list = dmstrdup(v); - for (pch = strtok_r(list, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { - sendopts = strsplit(pch, ":", &length); - if (strcmp(sendopts[0], value) == 0) - return FAULT_9007; - } - break; - case VALUESET: - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &v); - dmasprintf(&oldopttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); - if (v != NULL && strlen(v) > 0) - remove_elt_from_str_list(&v, oldopttagvalue); - dmasprintf(&opttagvalue, "%s:%s", value, ((struct dhcp_client_option_args *)data)->value && strlen(((struct dhcp_client_option_args *)data)->value)>0 ? ((struct dhcp_client_option_args *)data)->value:"0"); - add_elt_to_str_list(&v, opttagvalue); - dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "option_tag", value); - break; - } - return 0; -} - -int get_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(((struct dhcp_client_option_args *)data)->value); - return 0; -} - -int set_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *v, *opttagvalue, *oldopttagvalue; - - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, "0", "255")) - return FAULT_9007; - break; - case VALUESET: - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &v); - dmasprintf(&oldopttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); - remove_elt_from_str_list(&v, oldopttagvalue); - dmasprintf(&opttagvalue, "%s:%s", ((struct dhcp_client_option_args *)data)->option_tag, value); - add_elt_to_str_list(&v, opttagvalue); - dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "option_value", value); - break; - } - return 0; -} - -int get_DHCPv4ClientReqOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v; - - if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) { - *value = "0"; - return 0; - } - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", &v); - if (is_elt_exit_in_str_list(v, ((struct dhcp_client_option_args *)data)->option_tag)) - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_DHCPv4ClientReqOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - char *v; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", &v); - if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) - return 0; - if (b) { - if (!is_elt_exit_in_str_list(v, ((struct dhcp_client_option_args *)data)->option_tag)) { - add_elt_to_str_list(&v, ((struct dhcp_client_option_args *)data)->option_tag); - dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", v); - } - } else { - remove_elt_from_str_list(&v, ((struct dhcp_client_option_args *)data)->option_tag); - dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", v); - } - break; - } - return 0; -} - -int get_DHCPv4ClientReqOption_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4ClientReqOption_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv4ClientReqOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_reqtopt_alias", value); - return 0; -} - -int set_DHCPv4ClientReqOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_reqtopt_alias", value); - break; - } - return 0; -} - -int get_DHCPv4ClientReqOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(((struct dhcp_client_option_args *)data)->option_tag); - return 0; -} - -int set_DHCPv4ClientReqOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *pch, *spch, *list, *v; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", "254")) - return FAULT_9007; - - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", &v); - if (v == NULL) - return 0; - list = dmstrdup(v); - for (pch = strtok_r(list, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { - if(strcmp(pch, value) == 0) - return FAULT_9007; - } - break; - case VALUESET: - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", &v); - if (v != NULL && strlen(v) > 0) - remove_elt_from_str_list(&v, ((struct dhcp_client_option_args *)data)->option_tag); - add_elt_to_str_list(&v, value); - dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "option_tag", value); - break; - } - return 0; -} - -int get_DHCPv4ClientReqOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv4Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv4RelayForwarding_DHCPServerIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4RelayForwarding_DHCPServerIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *dhcp_option_list; - struct uci_element *e; - char **buf; - size_t length; - - if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) { - *value = "0"; - return 0; - } - dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - if (dhcp_option_list != NULL) { - uci_foreach_element(dhcp_option_list, e) { - buf = strsplit(e->name, ",", &length); - if (strcmp(buf[0], ((struct dhcp_client_option_args *)data)->option_tag) == 0) { - *value = "1"; - return 0; - } - } - } - *value = "0"; - return 0; -} - -int set_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_list *dhcp_option_list; - struct uci_element *e; - char **buf, *opt_value; - size_t length; - bool test = false, b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - if (strcmp(((struct dhcp_client_option_args *)data)->option_tag, "0") == 0) - return 0; - dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - dmasprintf(&opt_value, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); - if (dhcp_option_list != NULL) { - uci_foreach_element(dhcp_option_list, e) { - buf = strsplit(e->name, ",", &length); - if (strcmp(buf[0], ((struct dhcp_client_option_args *)data)->option_tag) == 0) { - test = true; - if (!b) - dmuci_del_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", opt_value); - break; - } - } - } - if(!test && b) - dmuci_add_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", opt_value); - } - return 0; -} - -int get_DHCPv4Server_PoolNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int i= 0; - - uci_foreach_sections("dhcp", "dhcp", s) { - i++; - } - dmasprintf(value, "%d", i); - return 0; -} - -int get_DHCPv4ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_servpool_option_alias", value); - return 0; -} - -int set_DHCPv4ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "bbf_dhcpv4_servpool_option_alias", value); - break; - } - return 0; -} - -int get_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(((struct dhcp_client_option_args *)data)->option_tag); - return 0; -} - -int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *opttagvalue, **option, *oldopttagvalue; - size_t length; - struct uci_list *dhcp_option_list = NULL; - struct uci_element *e; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", "254")) - return FAULT_9007; - - dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - if (dhcp_option_list == NULL) - return 0; - uci_foreach_element(dhcp_option_list, e) { - option = strsplit(e->name, ",", &length); - if (strcmp(option[0], value)==0) - return FAULT_9007; - } - break; - case VALUESET: - dmasprintf(&oldopttagvalue, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); - dmasprintf(&opttagvalue, "%s,%s", value, ((struct dhcp_client_option_args *)data)->value); - dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - dmuci_del_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", oldopttagvalue); - dmuci_add_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", opttagvalue); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "option_tag", value); - break; - } - return 0; -} - -int get_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(((struct dhcp_client_option_args *)data)->value); - return 0; -} - -int set_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *opttagvalue, **option, *oldopttagvalue; - size_t length; - struct uci_list *dhcp_option_list = NULL; - struct uci_element *e; - - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, "0", "255")) - return FAULT_9007; - - dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - if (dhcp_option_list == NULL) - return 0; - uci_foreach_element(dhcp_option_list, e) { - option = strsplit(e->name, ",", &length); - if (strcmp(option[0], value) == 0) - return FAULT_9007; - } - break; - case VALUESET: - dmasprintf(&oldopttagvalue, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, ((struct dhcp_client_option_args *)data)->value); - dmasprintf(&opttagvalue, "%s,%s", ((struct dhcp_client_option_args *)data)->option_tag, value); - dmuci_get_value_by_section_list(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - dmuci_del_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", oldopttagvalue); - dmuci_add_list_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "dhcp_option", opttagvalue); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_option_args *)data)->opt_sect, "option_value", value); - break; - } - return 0; -} - -/*#Device.DHCPv4.Relay.Forwarding.{i}.Enable!UCI:network/interface,@i-1/disabled*/ -int get_DHCPv4RelayForwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v = NULL; - - if(((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { - *value = "0"; - return 0; - } - - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", &v); - if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) - *value = "1"; - else - *value = "0"; - - return 0; -} - -int set_DHCPv4RelayForwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", b ? "0" : "1"); - break; - } - return 0; -} - -int get_DHCPv4RelayForwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_dm, "bbf_dhcpv4relay_alias", value); - return 0; -} - -int set_DHCPv4RelayForwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->dhcp_client_dm, "bbf_dhcpv4relay_alias", value); - break; - } - return 0; -} - -int get_DHCPv4RelayForwarding_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4RelayForwarding_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { - *value = ""; - return 0; - } - char *linker = dmstrdup(section_name(((struct dhcp_client_args *)data)->dhcp_client_conf)); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), linker, value); - return 0; -} - -int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *s; - char *linker = NULL, *newvalue = NULL, *v; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - - if (strlen(value) == 0 || strcmp(value, "") == 0) - return FAULT_9007; - - if (value[strlen(value)-1] != '.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); - if (linker == NULL) - return FAULT_9007; - uci_path_foreach_sections(bbfdm, "dmmap_dhcp_relay", "interface", s) { - dmuci_get_value_by_section_string(s, "section_name", &v); - if (strcmp(v, linker) == 0) - return FAULT_9007; - } - uci_foreach_sections("network", "interface", s) { - if (strcmp(section_name(s), linker) == 0) { - dmuci_get_value_by_section_string(s, "proto", &v); - if(strcmp(v, "relay") != 0) - return FAULT_9007; - } - } - break; - case VALUESET: - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcp_client_args *)data)->dhcp_client_dm, "section_name", linker); - break; - } - return 0; -} - -/*#Device.DHCPv4.Relay.Forwarding.{i}.VendorClassID!UCI:network/interface,@i-1/vendorclass*/ -int get_DHCPv4RelayForwarding_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - if(((struct dhcp_client_args *)data)->vendorclassidclassifier) - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->vendorclassidclassifier, "vendorclass", value); - return 0; -} - -int set_DHCPv4RelayForwarding_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "255", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - if(((struct dhcp_client_args *)data)->vendorclassidclassifier) - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->vendorclassidclassifier, "vendorclass", value); - break; - } - return 0; -} - -int get_DHCPv4RelayForwarding_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4RelayForwarding_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv4RelayForwarding_VendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4RelayForwarding_VendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, VendorClassIDMode, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.DHCPv4.Relay.Forwarding.{i}.Chaddr!UCI:network/interface,@i-1/mac*/ -int get_DHCPv4RelayForwarding_Chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *mac, **macarray, *res = NULL, *tmp = ""; - size_t length; - int i; - - if (((struct dhcp_client_args *)data)->macclassifier == NULL) { - *value = ""; - return 0; - } - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->macclassifier, "mac", &mac); - macarray = strsplit(mac, ":", &length); - res = (char*)dmcalloc(18, sizeof(char)); - tmp = res; - for (i = 0; i < 6; i++) { - if (strcmp(macarray[i], "*") == 0) { - sprintf(tmp, "%s", "00"); - } else { - sprintf(tmp, "%s", macarray[i]); - } - tmp += 2; - - if (i < 5) { - sprintf(tmp, "%s", ":"); - tmp++; - } - } - dmasprintf(value, "%s", res); - return 0; -} - -int set_DHCPv4RelayForwarding_Chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -/*#Device.DHCPv4.Relay.Forwarding.{i}.ChaddrMask!UCI:network/interface,@i-1/mac*/ -int get_DHCPv4RelayForwarding_ChaddrMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *mac, **macarray, *res = NULL, *tmp = ""; - size_t length; - int i; - - if (((struct dhcp_client_args *)data)->macclassifier == NULL) { - *value= ""; - return 0; - } - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->macclassifier, "mac", &mac); - macarray = strsplit(mac, ":", &length); - res = (char*)dmcalloc(18, sizeof(char)); - tmp = res; - for (i = 0; i < 6; i++) { - if (strcmp(macarray[i], "*") == 0) { - sprintf(tmp, "%s", "00"); - } else { - sprintf(tmp, "%s", "FF"); - } - tmp += 2; - - if (i < 5) { - sprintf(tmp, "%s", ":"); - tmp++; - } - } - dmasprintf(value, "%s", res); - return 0; -} - -int set_DHCPv4RelayForwarding_ChaddrMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_DHCPv4RelayForwarding_ChaddrExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "true"; - return 0; -} - -int set_DHCPv4RelayForwarding_ChaddrExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv4RelayForwarding_LocallyServed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4RelayForwarding_LocallyServed(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv4ServerPoolClientOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.DHCPv4.Relay.Forwarding.{i}.Status!UCI:network/interface,@i-1/disabled*/ -int get_DHCPv4RelayForwarding_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v = NULL; - - if (((struct dhcp_client_args *)data)->dhcp_client_conf == NULL) { - *value= "Error_Misconfigured"; - return 0; - } - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dhcp_client_conf, "disabled", &v); - if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) - *value= "Enabled"; - else - *value= "Disabled"; - - return 0; -} - -int get_DHCPv4RelayForwarding_ClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4RelayForwarding_ClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "255")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv4RelayForwarding_ClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4RelayForwarding_ClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.DHCPv4.Relay.Forwarding.{i}.UserClassID!UCI:network/interface,@i-1/userclass*/ -int get_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - if(((struct dhcp_client_args *)data)->userclassclassifier) - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->userclassclassifier, "userclass", value); - return 0; -} - -int set_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "255")) - return FAULT_9007; - break; - case VALUESET: - if(((struct dhcp_client_args *)data)->userclassclassifier) - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->userclassclassifier, "userclass", value); - break; - } - return 0; -} - -int get_DHCPv4RelayForwarding_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv4RelayForwarding_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv4ServerPoolClientOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv4Relay_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *path = "/etc/rc.d/*relayd"; - if (check_file(path)) - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_DHCPv4Relay_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmcmd("/etc/init.d/relayd", 1, b ? "enable" : "disable"); - break; - } - return 0; -} - -int get_DHCPv4Relay_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *path = "/etc/rc.d/*relayd"; - if (check_file(path)) - *value = "Enabled"; - else - *value = "Disabled"; - return 0; -} - -int get_DHCPv4Relay_ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s, *dmmap_sect; - int nbre_confs = 0, nbre_dmmaps = 0; - - uci_foreach_option_eq("network", "interface", "proto", "relay", s) { - nbre_confs++; - } - uci_path_foreach_sections(bbfdm, "dmmap_dhcp_relay", "interface", dmmap_sect) { - nbre_dmmaps++; - } - if (nbre_dmmaps == 0 || nbre_dmmaps < nbre_confs) - dmasprintf(value, "%d", nbre_confs); - else - dmasprintf(value, "%d", nbre_dmmaps); - return 0; -} - -static void dhcp_leases_load(struct list_head *head) -{ - FILE *f = fopen(DHCP_LEASES_FILE, "r"); - char line[128]; - - if (f == NULL) - return; - - while (fgets(line, sizeof(line) - 1, f)) { - struct dhcp_lease *lease; - - if (line[0] == '\n') - continue; - - lease = dmcalloc(1, sizeof(*lease)); - if (lease == NULL) - break; - - sscanf(line, "%" PRId64 "%19s %15s", - &lease->ts, lease->hwaddr, lease->ipaddr); - - list_add_tail(&lease->list, head); - } - fclose(f); -} - -static int interface_get_ipv4(const char *iface, uint32_t *addr, unsigned *bits) -{ - json_object *res; - const char *addr_str = NULL; - int addr_cidr = -1; - - dmubus_call("network.interface", "status", UBUS_ARGS {{"interface", iface, String}}, 1, &res); - if (res) { - json_object *jobj; - - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - if (jobj == NULL) - return -1; - - json_object_object_foreach(jobj, key, val) { - if (!strcmp(key, "address")) - addr_str = json_object_get_string(val); - else if (!strcmp(key, "mask")) - addr_cidr = json_object_get_int(val); - } - } - - if (addr_str == NULL || addr_cidr == -1) - return -1; - - if (inet_pton(AF_INET, addr_str, addr) != 1) - return -1; - - *bits = addr_cidr; - return 0; -} - -static void dhcp_leases_assign_to_interface(struct dhcp_args *dhcp, - struct list_head *src, - const char *iface) -{ - struct dhcp_lease *lease, *tmp; - unsigned iface_addr; - unsigned iface_cidr; - unsigned iface_net; - unsigned iface_bits; - - if (interface_get_ipv4(iface, &iface_addr, &iface_cidr)) - return; - - iface_bits = 32 - iface_cidr; - iface_net = ntohl(iface_addr) >> iface_bits; - - list_for_each_entry_safe(lease, tmp, src, list) { - unsigned addr, net; - - inet_pton(AF_INET, lease->ipaddr, &addr); - net = ntohl(addr) >> iface_bits; - - if (net == iface_net) { - list_move_tail(&lease->list, &dhcp->leases); - dhcp->n_leases += 1; - } - } -} - -/************************************************************* -* ENTRY METHOD -**************************************************************/ -/*#Device.DHCPv4.Server.Pool.{i}.!UCI:dhcp/dhcp/dmmap_dhcp*/ -int browseDhcpInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *interface, *idhcp = NULL, *idhcp_last = NULL, *v; - struct dhcp_args curr_dhcp_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(leases); - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("dhcp", "dhcp", "dmmap_dhcp", &dup_list); - - if (!list_empty(&dup_list)) - dhcp_leases_load(&leases); - - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "interface", &interface); - init_dhcp_args(&curr_dhcp_args, p->config_section, interface); - - dhcp_leases_assign_to_interface(&curr_dhcp_args, &leases, interface); - - idhcp = handle_update_instance(1, dmctx, &idhcp_last, update_instance_alias_bbfdm, 3, p->dmmap_section, "dhcp_instance", "dhcp_alias"); - dmuci_get_value_by_section_string(p->dmmap_section, "order", &v); - if (v == NULL || strlen(v) == 0) - set_section_order("dhcp", "dmmap_dhcp", "dhcp", p->dmmap_section, p->config_section, 0, idhcp); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_args, idhcp) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -/*#Device.DHCPv4.Server.Pool.{i}.StaticAddress.{i}.!UCI:dhcp/host/dmmap_dhcp*/ -int browseDhcpStaticInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *idhcp = NULL, *idhcp_last = NULL; - struct dhcp_static_args curr_dhcp_staticargs = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap_cont("dhcp", "host", "dmmap_dhcp", "dhcp", ((struct dhcp_args *)prev_data)->interface, &dup_list); - list_for_each_entry(p, &dup_list, list) { - idhcp = handle_update_instance(2, dmctx, &idhcp_last, update_instance_alias_bbfdm, 3, p->dmmap_section, "ldhcpinstance", "ldhcpalias"); - init_args_dhcp_host(&curr_dhcp_staticargs, p->config_section); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_staticargs, idhcp) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int browseDhcpClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - const struct dhcp_args *dhcp = prev_data; - const struct dhcp_lease *lease; - int id = 0; - - list_for_each_entry(lease, &dhcp->leases, list) { - struct client_args client_args; - char *idx, *idx_last = NULL; - - init_dhcp_client_args(&client_args, lease); - idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id); - - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&client_args, idx) == DM_STOP) - break; - } - return 0; -} - -int browseDhcpClientIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *idx, *idx_last = NULL; - - idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, 1); - DM_LINK_INST_OBJ(dmctx, parent_node, prev_data, idx); - return 0; -} - -/*#Device.DHCPv4.Client.{i}.!UCI:network/interface/dmmap_dhcp_client*/ -int browseDHCPv4ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *instance, *instnbr = NULL; - struct dmmap_dup *p; - char *type, *ipv4addr = "", *ipv6addr = "", *proto, *inst, *mask4 = NULL; - json_object *res, *jobj; - struct dhcp_client_args dhcp_client_arg = {0}; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap_eq_no_delete("network", "interface", "dmmap_dhcp_client", "proto", "dhcp", &dup_list); - list_for_each_entry(p, &dup_list, list) { - if (p->config_section != NULL) { - dmuci_get_value_by_section_string(p->config_section, "type", &type); - if (strcmp(type, "alias") == 0 || strcmp(section_name(p->config_section), "loopback") == 0) - continue; - - dmuci_get_value_by_section_string(p->config_section, "ipaddr", &ipv4addr); - dmuci_get_value_by_section_string(p->config_section, "netmask", &mask4); - if (ipv4addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - ipv4addr = dmjson_get_value(jobj, 1, "address"); - mask4= dmjson_get_value(jobj, 1, "mask"); - } - } - - dmuci_get_value_by_section_string(p->config_section, "ip6addr", &ipv6addr); - if (ipv6addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); - ipv6addr = dmjson_get_value(jobj, 1, "address"); - } - } - - dmuci_get_value_by_section_string(p->config_section, "proto", &proto); - dmuci_get_value_by_section_string(p->config_section, "ip_int_instance", &inst); - - if (ipv4addr[0] == '\0' && ipv6addr[0] == '\0' && strcmp(proto, "dhcp") != 0 && strcmp(proto, "dhcpv6") != 0 && strcmp(inst, "") == 0 && strcmp(type, "bridge") != 0) { - p->config_section=NULL; - DMUCI_SET_VALUE_BY_SECTION(bbfdm, p->dmmap_section, "section_name", ""); - } - } - - if (ipv4addr == NULL || strlen(ipv4addr) == 0) - dhcp_client_arg.ip = dmstrdup(""); - else - dhcp_client_arg.ip = dmstrdup(ipv4addr); - if (mask4 == NULL || strlen(mask4) == 0) - dhcp_client_arg.mask = dmstrdup(""); - else - dhcp_client_arg.mask = dmstrdup(mask4); - - dhcp_client_arg.dhcp_client_conf = p->config_section; - dhcp_client_arg.dhcp_client_dm= p->dmmap_section; - - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, (void *)p->dmmap_section, "bbf_dhcpv4client_instance", "bbf_dhcpv4client_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_client_arg, instance) == DM_STOP) - break; - } - return 0; -} - -int browseDHCPv4ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)prev_data; - struct uci_section *dmmap_sect; - struct dhcp_client_option_args dhcp_client_opt_args = {0}; - char *instance, *instnbr = NULL, *v1, *v2, **sentopts = NULL, **buf = NULL, *tmp, *optionvalue, *v = NULL; - size_t length = 0, lgh2; - int i, j; - - if (dhcp_client_args->dhcp_client_conf != NULL) - dmuci_get_value_by_section_string(dhcp_client_args->dhcp_client_conf, "sendopts", &v); - - if (v) sentopts = strsplit(v, " ", &length); - check_create_dmmap_package("dmmap_dhcp_client"); - for (i = 0; i < length; i++) { - if (sentopts[i]) buf = strsplit(sentopts[i], ":", &lgh2); - if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcp_client", "send_option", section_name(dhcp_client_args->dhcp_client_conf), "option_tag", buf[0])) == NULL) { - dmuci_add_section_bbfdm("dmmap_dhcp_client", "send_option", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", buf[0]); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_client_args->dhcp_client_conf)); - } - optionvalue = dmstrdup(buf[1]); - if (lgh2 > 2) { - for (j = 2; j < lgh2; j++) { - tmp = dmstrdup(optionvalue); - dmfree(optionvalue); - optionvalue = NULL; - dmasprintf(&optionvalue, "%s:%s", tmp, buf[j]); - dmfree(tmp); - tmp = NULL; - } - } - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_value", optionvalue); - } - - uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp_client", "send_option", "section_name", dhcp_client_args->dhcp_client_conf?section_name(dhcp_client_args->dhcp_client_conf):"", dmmap_sect) { - dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1); - dmuci_get_value_by_section_string(dmmap_sect, "option_value", &v2); - dhcp_client_opt_args.client_sect= dhcp_client_args->dhcp_client_conf; - dhcp_client_opt_args.option_tag= dmstrdup(v1); - dhcp_client_opt_args.value= dmstrdup(v2); - dhcp_client_opt_args.opt_sect= dmmap_sect; - - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "bbf_dhcpv4_sentopt_instance", "bbf_dhcpv4_sentopt_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_client_opt_args, instance) == DM_STOP) - break; - } - return 0; -} - -int browseDHCPv4ClientReqOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)prev_data; - struct uci_section *dmmap_sect; - struct dhcp_client_option_args dhcp_client_opt_args = {0}; - char *instance, *instnbr = NULL, *v1, **reqtopts = NULL, *v = NULL; - size_t length = 0; - int i; - - if (dhcp_client_args->dhcp_client_conf != NULL) - dmuci_get_value_by_section_string(dhcp_client_args->dhcp_client_conf, "reqopts", &v); - if (v) reqtopts = strsplit(v, " ", &length); - check_create_dmmap_package("dmmap_dhcp_client"); - for (i = 0; i < length; i++) { - if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcp_client", "req_option", section_name(dhcp_client_args->dhcp_client_conf), "option_tag", reqtopts[i])) == NULL) { - dmuci_add_section_bbfdm("dmmap_dhcp_client", "req_option", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", reqtopts[i]); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_client_args->dhcp_client_conf)); - } - } - - uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp_client", "req_option", "section_name", dhcp_client_args->dhcp_client_conf?section_name(dhcp_client_args->dhcp_client_conf):"", dmmap_sect) { - dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1); - dhcp_client_opt_args.client_sect = dhcp_client_args->dhcp_client_conf; - dhcp_client_opt_args.option_tag = dmstrdup(v1); - dhcp_client_opt_args.value = dmstrdup(""); - dhcp_client_opt_args.opt_sect = dmmap_sect; - - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "bbf_dhcpv4_reqtopt_instance", "bbf_dhcpv4_reqtopt_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_client_opt_args, instance) == DM_STOP) - break; - } - return 0; -} - -int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_list *dhcp_options_list = NULL; - struct uci_element *e; - struct dhcp_args *curr_dhcp_args = (struct dhcp_args*)prev_data; - struct uci_section *dmmap_sect; - char **tagvalue = NULL, *instance, *instnbr = NULL, *optionvalue = NULL, *tmp, *v1, *v2, *v; - size_t length; - int j; - struct dhcp_client_option_args dhcp_client_opt_args = {0}; - - dmuci_get_value_by_section_list(curr_dhcp_args->dhcp_sec, "dhcp_option", &dhcp_options_list); - if (dhcp_options_list != NULL) { - uci_foreach_element(dhcp_options_list, e) { - tagvalue = strsplit(e->name, ",", &length); - if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcp", "servpool_option", section_name(curr_dhcp_args->dhcp_sec), "option_tag", tagvalue[0])) == NULL) { - dmuci_add_section_bbfdm("dmmap_dhcp", "servpool_option", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", tagvalue[0]); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(curr_dhcp_args->dhcp_sec)); - } - optionvalue = dmstrdup(tagvalue[1]); - if (length > 2) { - for (j = 2; j < length; j++) { - tmp = dmstrdup(optionvalue); - dmfree(optionvalue); - optionvalue = NULL; - dmasprintf(&optionvalue, "%s,%s", tmp, tagvalue[j]); - dmfree(tmp); - tmp = NULL; - } - } - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_value", optionvalue); - } - } - uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp", "servpool_option", "section_name", section_name(curr_dhcp_args->dhcp_sec), dmmap_sect) { - dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1); - dmuci_get_value_by_section_string(dmmap_sect, "option_value", &v2); - dhcp_client_opt_args.client_sect = curr_dhcp_args->dhcp_sec; - dhcp_client_opt_args.option_tag = dmstrdup(v1); - dhcp_client_opt_args.value = dmstrdup(v2); - dhcp_client_opt_args.opt_sect = dmmap_sect; - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "bbf_dhcpv4_servpool_option_instance", "bbf_dhcpv4_servpool_option_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_client_opt_args, instance) == DM_STOP) - break; - } - return 0; -} - -int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - //TODO - return 0; -} - -char *get_dhcp_network_from_relay_list(char *net_list) -{ - struct uci_section *s; - char **net_list_arr, *v; - int i; - size_t length; - - net_list_arr = strsplit(net_list, " ", &length); - uci_foreach_sections("network", "interface", s) { - dmuci_get_value_by_section_string(s, "proto", &v); - for (i = 0; i < length; i++) { - if (strcmp(net_list_arr[i], section_name(s)) == 0 && strcmp(v, "dhcp") == 0) - return net_list_arr[i]; - } - } - return ""; -} - -struct uci_section* get_dhcp_classifier(char *classifier_name, char *network) -{ - struct uci_section* s = NULL; - char *v; - - uci_foreach_sections("dhcp", classifier_name, s) { - dmuci_get_value_by_section_string(s, "networkid", &v); - if (strcmp(v, network) == 0) - return s; - } - return NULL; -} - -/*#Device.DHCPv4.Relay.Forwarding.{i}.!UCI:network/interface/dmmap_dhcp_relay*/ -int browseDHCPv4RelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *instance, *instnbr = NULL, *v, *dhcp_network = NULL; - struct dmmap_dup *p; - char *type, *ipv4addr = "", *ipv6addr = "", *proto, *inst, *mask4 = NULL; - json_object *res, *jobj; - struct dhcp_client_args dhcp_relay_arg = {0}; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap_eq_no_delete("network", "interface", "dmmap_dhcp_relay", "proto", "relay", &dup_list); - list_for_each_entry(p, &dup_list, list) { - if (p->config_section != NULL) { - dmuci_get_value_by_section_string(p->config_section, "type", &type); - if (strcmp(type, "alias") == 0 || strcmp(section_name(p->config_section), "loopback") == 0) - continue; - - dmuci_get_value_by_section_string(p->config_section, "ipaddr", &ipv4addr); - dmuci_get_value_by_section_string(p->config_section, "netmask", &mask4); - if (ipv4addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - ipv4addr = dmjson_get_value(jobj, 1, "address"); - mask4= dmjson_get_value(jobj, 1, "mask"); - } - } - - dmuci_get_value_by_section_string(p->config_section, "ip6addr", &ipv6addr); - if (ipv6addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); - ipv6addr = dmjson_get_value(jobj, 1, "address"); - } - } - - dmuci_get_value_by_section_string(p->config_section, "proto", &proto); - dmuci_get_value_by_section_string(p->config_section, "ip_int_instance", &inst); - if (ipv4addr[0] == '\0' && ipv6addr[0] == '\0' && strcmp(inst, "") == 0 && strcmp(type, "bridge") != 0 && strcmp(proto, "relay") != 0) { - p->config_section = NULL; - DMUCI_SET_VALUE_BY_SECTION(bbfdm, p->dmmap_section, "section_name", ""); - } - } - - if (ipv4addr == NULL || strlen(ipv4addr) == 0) - dhcp_relay_arg.ip = dmstrdup(""); - else - dhcp_relay_arg.ip = dmstrdup(ipv4addr); - if (mask4 == NULL || strlen(mask4) == 0) - dhcp_relay_arg.mask = dmstrdup(""); - else - dhcp_relay_arg.mask = dmstrdup(mask4); - if (p->config_section != NULL) - dmuci_get_value_by_section_string(p->config_section, "network", &v); - else - v = dmstrdup(""); - - dhcp_network = get_dhcp_network_from_relay_list(v); - if (dhcp_network && strlen(dhcp_network) > 0) { - dhcp_relay_arg.macclassifier = get_dhcp_classifier("mac", dhcp_network); - dhcp_relay_arg.vendorclassidclassifier = get_dhcp_classifier("vendorclass", dhcp_network); - dhcp_relay_arg.userclassclassifier = get_dhcp_classifier("userclass", dhcp_network); - } else { - dhcp_relay_arg.macclassifier = NULL; - dhcp_relay_arg.vendorclassidclassifier = NULL; - dhcp_relay_arg.userclassclassifier = NULL; - } - dhcp_relay_arg.dhcp_client_conf = p->config_section; - - dhcp_relay_arg.dhcp_client_dm= p->dmmap_section; - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, (void *)p->dmmap_section, "bbf_dhcpv4relay_instance", "bbf_dhcpv4relay_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_relay_arg, instance) == DM_STOP) - break; - } - return 0; -} diff --git a/dmtree/tr181/dhcpv4.h b/dmtree/tr181/dhcpv4.h index 53b83efd..8f6a66eb 100644 --- a/dmtree/tr181/dhcpv4.h +++ b/dmtree/tr181/dhcpv4.h @@ -37,165 +37,6 @@ extern DMOBJ tDHCPv4RelayObj[]; extern DMLEAF tDHCPv4RelayParams[]; extern DMLEAF tDHCPv4RelayForwardingParams[]; -int browseDhcpInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDhcpStaticInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDhcpClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDhcpClientIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv4ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv4ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv4ClientReqOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv4RelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int add_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int add_dhcp_staticaddress(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_dhcp_staticaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjDHCPv4ClientReqOption(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjDHCPv4ClientReqOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjDHCPv4ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjDHCPv4ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjDHCPv4RelayForwarding(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjDHCPv4RelayForwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_server_pool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_interval_address_min(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_interval_address_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_static_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_client_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_client_ipv4address_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_client_ipv4address_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_sever_pool_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_static_address_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_option_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_clients_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_dhcp_client_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_server_pool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_address_min(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_address_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_static_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_dhcp_sever_pool_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_dhcp_client_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); int set_section_order(char *package, char *dmpackage, char* sect_type, struct uci_section *dmmap_sect, struct uci_section *conf, int set_force, char* order); -int get_DHCPv4_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4Client_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Client_DHCPStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4Client_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Client_SubnetMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Client_IPRouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Client_DNSServers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Client_LeaseTimeRemaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Client_DHCPServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Client_PassthroughEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4Client_PassthroughEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4Client_PassthroughDHCPPool(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4Client_PassthroughDHCPPool(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4Client_SentOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Client_ReqOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ClientReqOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ClientReqOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ClientReqOption_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ClientReqOption_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ClientReqOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ClientReqOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ClientReqOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ClientReqOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ClientReqOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4Server_PoolNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ServerPoolClientOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4RelayForwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4RelayForwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_VendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_VendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_ClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_ClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_ClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_ClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_Chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_Chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_ChaddrMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_ChaddrMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_ChaddrExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_ChaddrExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_LocallyServed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_LocallyServed(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4RelayForwarding_DHCPServerIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4RelayForwarding_DHCPServerIPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4ServerPoolClientOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Relay_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv4Relay_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv4Relay_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv4Relay_ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); #endif diff --git a/dmtree/tr181/dhcpv6.c b/dmtree/tr181/dhcpv6.c index af11c36c..91378cf9 100644 --- a/dmtree/tr181/dhcpv6.c +++ b/dmtree/tr181/dhcpv6.c @@ -12,6 +12,1854 @@ #include "dhcpv4.h" #include "dhcpv6.h" + +struct dhcpv6_client_args +{ + struct uci_section *dhcp_client_conf; + struct uci_section *dhcp_client_dm; + char *ip; +}; + +struct dhcpv6_args +{ + struct uci_section *dhcp_sec; + char *interface; +}; + +struct clientv6_args +{ + json_object *client; + json_object *clientparam; + int idx; +}; + +struct dhcpv6_client_option_args { + struct uci_section *opt_sect; + struct uci_section *client_sect; + char *option_tag; + char *value; +}; + +struct uci_section* get_dhcpv6_classifier(char *classifier_name, char *network) +{ + struct uci_section *s = NULL; + char *v; + + uci_foreach_sections("dhcp", classifier_name, s) { + dmuci_get_value_by_section_string(s, "networkid", &v); + if (strcmp(v, network) == 0) + return s; + } + return NULL; +} + +static inline int init_dhcpv6_client_args(struct clientv6_args *args, json_object *client, json_object *client_param, int i) +{ + args->client = client; + args->clientparam = client_param; + args->idx = i; + return 0; +} + +struct uci_section* exist_other_section_dhcp6_same_order(struct uci_section *dmmap_sect, char * package, char* sect_type, char *order) +{ + struct uci_section *s; + uci_path_foreach_option_eq(bbfdm, package, sect_type, "order", order, s) { + if (strcmp(section_name(s), section_name(dmmap_sect)) != 0) { + return s; + } + } + return NULL; +} + +static int set_section_dhcp6_order(char *package, char *dmpackage, char* sect_type, struct uci_section *dmmap_sect, struct uci_section *conf, int set_force, char* order) +{ + char *v = NULL, *sect_name, *incrorder; + struct uci_section *s, *dm; + dmuci_get_value_by_section_string(dmmap_sect, "order", &v); + if(strlen(v) > 0 && strcmp(v, order) == 0) + return 0; + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "order", order); + if (conf == NULL) { + dmuci_get_value_by_section_string(dmmap_sect, "section_name", §_name); + get_config_section_of_dmmap_section(package, sect_type, sect_name, &s); + } else + s= conf; + + if (strcmp(order, "1") != 0 && s != NULL) { + dmuci_set_value_by_section(s, "force", ""); + } + + if (set_force==1 && strcmp(order, "1") == 0 && s != NULL) { + dmuci_set_value_by_section(s, "force", "1"); + } + + if ((dm = exist_other_section_dhcp6_same_order(dmmap_sect, dmpackage, sect_type, order)) != NULL) { + dmuci_get_value_by_section_string(dm, "section_name", §_name); + get_config_section_of_dmmap_section(package, sect_type, sect_name, &s); + dmasprintf(&incrorder, "%d", atoi(order)+1); + if (s != NULL && strcmp(order, "1") == 0) { + dmuci_set_value_by_section(s, "force", ""); + } + set_section_dhcp6_order(package, dmpackage, sect_type, dm, s, set_force, incrorder); + } + return 0; + +} + +static inline int init_dhcpv6_args(struct dhcpv6_args *args, struct uci_section *s, char *interface) +{ + args->interface = interface; + args->dhcp_sec = s; + return 0; +} + +/*#Device.DHCPv6.Client.{i}.!UCI:network/interface/dmmap_dhcpv6*/ +static int browseDHCPv6ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct dmmap_dup *p; + struct dhcpv6_client_args dhcpv6_client_arg = {0}; + json_object *res, *jobj; + char *instance, *instnbr = NULL, *ipv6addr = NULL; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap_eq_no_delete("network", "interface", "dmmap_dhcpv6", "proto", "dhcpv6", &dup_list); + list_for_each_entry(p, &dup_list, list) { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); + ipv6addr = dmjson_get_value(jobj, 1, "address"); + } + dhcpv6_client_arg.dhcp_client_conf = p->config_section; + dhcpv6_client_arg.dhcp_client_dm = p->dmmap_section; + dhcpv6_client_arg.ip = dmstrdup(ipv6addr?ipv6addr:""); + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, p->dmmap_section, "bbf_dhcpv6client_instance", "bbf_dhcpv6client_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcpv6_client_arg, instance) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int browseDHCPv6ClientServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + //TODO + return 0; +} + +static int browseDHCPv6ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + //TODO + return 0; +} + +static int browseDHCPv6ClientReceivedOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + //TODO + return 0; +} + +/*#Device.DHCPv6.Server.Pool.{i}.!UCI:dhcp/dhcp/dmmap_dhcpv6*/ +static int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *interface, *idhcp = NULL, *idhcp_last = NULL, *v; + struct dhcpv6_args curr_dhcp6_args = {0}; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap_eq("dhcp", "dhcp", "dmmap_dhcpv6", "dhcpv6", "server", &dup_list); + list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "interface", &interface); + init_dhcpv6_args(&curr_dhcp6_args, p->config_section, interface); + idhcp = handle_update_instance(1, dmctx, &idhcp_last, update_instance_alias_bbfdm, 3, p->dmmap_section, "dhcpv6_serv_pool_instance", "dhcpv6_serv_pool_alias"); + dmuci_get_value_by_section_string(p->dmmap_section, "order", &v); + if (v == NULL || strlen(v) == 0) + set_section_dhcp6_order("dhcp", "dmmap_dhcpv6", "dhcp", p->dmmap_section, p->config_section, 0, idhcp); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp6_args, idhcp) == DM_STOP) + break; + } + + free_dmmap_config_dup_list(&dup_list); + + return 0; +} + +static int browseDHCPv6ServerPoolClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct dhcpv6_args *dhcp_arg= (struct dhcpv6_args*)prev_data; + json_object *res, *res1, *jobj, *dev_obj= NULL, *net_obj= NULL; + struct clientv6_args curr_dhcp_client_args = {0}; + int i = 0; + char *idx = NULL, *idx_last = NULL, *device; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(dhcp_arg->dhcp_sec), String}}, 1, &res1); + if (!res1) return 0; + device = dmjson_get_value(res1, 1, "device"); + dmubus_call("dhcp", "ipv6leases", UBUS_ARGS{}, 0, &res); + if (!res) return 0; + dev_obj = dmjson_get_obj(res, 1, "device"); + if (!dev_obj) return 0; + net_obj = dmjson_get_obj(dev_obj, 1, device); + if (!net_obj) return 0; + + while (1) { + jobj = dmjson_select_obj_in_array_idx(net_obj, i, 1, "leases"); + if (!jobj) break; + init_dhcpv6_client_args(&curr_dhcp_client_args, jobj, NULL, i); + i++; + idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, i); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_client_args, idx) == DM_STOP) + break; + } + return 0; +} + +static int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_list *dhcp_options_list = NULL; + struct uci_element *e; + struct dhcpv6_args *curr_dhcp_args = (struct dhcpv6_args*)prev_data; + struct uci_section *dmmap_sect; + char **tagvalue = NULL, *instance, *instnbr = NULL, *optionvalue= NULL, *tmp, *v1, *v2, *v; + size_t length; + int j; + struct dhcpv6_client_option_args dhcp_client_opt_args = {0}; + + dmuci_get_value_by_section_list(curr_dhcp_args->dhcp_sec, "dhcp_option", &dhcp_options_list); + if (dhcp_options_list != NULL) { + uci_foreach_element(dhcp_options_list, e) { + tagvalue= strsplit(e->name, ",", &length); + if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcpv6", "servpool_option", section_name(curr_dhcp_args->dhcp_sec), "option_tag", tagvalue[0])) == NULL) { + dmuci_add_section_bbfdm("dmmap_dhcpv6", "servpool_option", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", tagvalue[0]); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(curr_dhcp_args->dhcp_sec)); + } + optionvalue=dmstrdup(tagvalue[1]); + if (length > 2) { + for (j = 2; j < length; j++){ + tmp=dmstrdup(optionvalue); + dmfree(optionvalue); + optionvalue= NULL; + dmasprintf(&optionvalue, "%s,%s", tmp, tagvalue[j]); + dmfree(tmp); + tmp= NULL; + } + } + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_value", optionvalue); + } + } + uci_path_foreach_option_eq(bbfdm, "dmmap_dhcpv6", "servpool_option", "section_name", section_name(curr_dhcp_args->dhcp_sec), dmmap_sect) { + dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1); + dmuci_get_value_by_section_string(dmmap_sect, "option_value", &v2); + dhcp_client_opt_args.client_sect= curr_dhcp_args->dhcp_sec; + dhcp_client_opt_args.option_tag = dmstrdup(v1); + dhcp_client_opt_args.value = dmstrdup(v2); + dhcp_client_opt_args.opt_sect = dmmap_sect; + instance= handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "bbf_dhcpv6_servpool_option_instance", "bbf_dhcpv6_servpool_option_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_client_opt_args, instance) == DM_STOP) + break; + } + return 0; +} + +static int browseDHCPv6ServerPoolClientIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct clientv6_args *dhcpv6_serv_pool_client = (struct clientv6_args *)prev_data; + json_object *address_obj= NULL; + struct clientv6_args curr_dhcv6_address_args = {0}; + char *idx = NULL, *idx_last = NULL; + int i = 0; + + while (1) { + address_obj = dmjson_select_obj_in_array_idx(dhcpv6_serv_pool_client->client, i, 1, "ipv6-addr"); + if (address_obj == NULL) + break; + init_dhcpv6_client_args(&curr_dhcv6_address_args, dhcpv6_serv_pool_client->client, address_obj, i); + i++; + idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, i); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcv6_address_args, idx) == DM_STOP) + break; + } + + return 0; +} + +static int browseDHCPv6ServerPoolClientIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct clientv6_args *dhcpv6_serv_pool_client = (struct clientv6_args *)prev_data; + json_object *address_obj = NULL; + struct clientv6_args curr_dhcv6_address_args = {0}; + char *idx = NULL, *idx_last = NULL; + int i = 0; + + while (1) { + address_obj = dmjson_select_obj_in_array_idx(dhcpv6_serv_pool_client->client, i, 1, "ipv6-prefix"); + if (address_obj == NULL) + break; + init_dhcpv6_client_args(&curr_dhcv6_address_args, dhcpv6_serv_pool_client->client, address_obj, i); + i++; + idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, i); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcv6_address_args, idx) == DM_STOP) + break; + } + + return 0; +} + +static int browseDHCPv6ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + //TODO + return 0; +} + + +static int addObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct uci_section *s, *dmmap_sect; + char *value, *instancepara, *v; + + check_create_dmmap_package("dmmap_dhcpv6"); + instancepara = get_last_instance_bbfdm("dmmap_dhcpv6", "interface", "bbf_dhcpv6client_instance"); + dmuci_add_section("network", "interface", &s, &value); + dmuci_set_value_by_section(s, "proto", "dhcpv6"); + dmuci_set_value_by_section(s, "ifname", "@wan"); + dmuci_set_value_by_section(s, "type", "anywan"); + dmuci_add_section_bbfdm("dmmap_dhcpv6", "interface", &dmmap_sect, &v); + dmuci_set_value_by_section(dmmap_sect, "section_name", section_name(s)); + *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv6client_instance"); + return 0; +} + +static int delObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct dhcpv6_client_args *dhcpv6_client_args = (struct dhcpv6_client_args*)data; + struct uci_section *s, *dmmap_section, *ss = NULL; + int found = 0; + char *proto; + + switch (del_action) { + case DEL_INST: + if(dhcpv6_client_args->dhcp_client_conf != NULL && is_section_unnamed(section_name(dhcpv6_client_args->dhcp_client_conf))){ + LIST_HEAD(dup_list); + delete_sections_save_next_sections("dmmap_dhcpv6", "interface", "bbf_dhcpv6client_instance", section_name(dhcpv6_client_args->dhcp_client_conf), atoi(instance), &dup_list); + update_dmmap_sections(&dup_list, "bbf_dhcpv6client_instance", "dmmap_dhcpv6", "interface"); + dmuci_delete_by_section_unnamed(dhcpv6_client_args->dhcp_client_conf, NULL, NULL); + } else { + get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(dhcpv6_client_args->dhcp_client_conf), &dmmap_section); + dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); + dmuci_delete_by_section(dhcpv6_client_args->dhcp_client_conf, NULL, NULL); + } + break; + case DEL_ALL: + uci_foreach_sections("network", "interface", s) { + if (found != 0) { + dmuci_get_value_by_section_string(ss, "proto", &proto); + if(strcmp(proto, "dhcpv6") == 0) { + get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(ss), &dmmap_section); + if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + } + ss = s; + found++; + } + if (ss != NULL) { + dmuci_get_value_by_section_string(ss, "proto", &proto); + if (strcmp(proto, "dhcpv6") == 0) { + get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(ss), &dmmap_section); + if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + } + break; + } + return 0; +} + +static int addObjDHCPv6ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + //TODO + return 0; +} + +static int delObjDHCPv6ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + switch (del_action) { + case DEL_INST: + //TODO + break; + case DEL_ALL: + //TODO + break; + } + return 0; +} + +static int addObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *value, *v, *instancepara; + struct uci_section *s = NULL, *dmmap_dhcp= NULL; + + check_create_dmmap_package("dmmap_dhcpv6"); + instancepara = get_last_instance_bbfdm("dmmap_dhcpv6", "dhcp", "dhcpv6_serv_pool_instance"); + dmuci_add_section("dhcp", "dhcp", &s, &value); + dmuci_set_value_by_section(s, "dhcpv6", "server"); + dmuci_set_value_by_section(s, "start", "100"); + dmuci_set_value_by_section(s, "leasetime", "12h"); + dmuci_set_value_by_section(s, "limit", "150"); + + dmuci_add_section_bbfdm("dmmap_dhcpv6", "dhcp", &dmmap_dhcp, &v); + dmuci_set_value_by_section(dmmap_dhcp, "section_name", section_name(s)); + *instance = update_instance_bbfdm(dmmap_dhcp, instancepara, "dhcpv6_serv_pool_instance"); + return 0; +} + +static int delObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; + char *dhcpv6 = NULL; + + switch (del_action) { + case DEL_INST: + if(is_section_unnamed(section_name(((struct dhcpv6_args *)data)->dhcp_sec))){ + LIST_HEAD(dup_list); + delete_sections_save_next_sections("dmmap_dhcpv6", "dhcp", "dhcpv6_serv_pool_instance", section_name(((struct dhcpv6_args *)data)->dhcp_sec), atoi(instance), &dup_list); + update_dmmap_sections(&dup_list, "dhcpv6_serv_pool_instance", "dmmap_dhcpv6", "dhcp"); + dmuci_delete_by_section_unnamed(((struct dhcpv6_args *)data)->dhcp_sec, NULL, NULL); + } else { + get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_section); + if(dmmap_section) dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); + dmuci_delete_by_section(((struct dhcpv6_args *)data)->dhcp_sec, NULL, NULL); + } + break; + case DEL_ALL: + uci_foreach_sections("dhcp", "dhcp", s) { + if (found != 0){ + dmuci_get_value_by_section_string(ss, "dhcpv6", &dhcpv6); + if(strcmp(dhcpv6, "server") == 0){ + get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(s), &dmmap_section); + if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + } + ss = s; + found++; + } + if (ss != NULL){ + dmuci_get_value_by_section_string(ss, "dhcpv6", &dhcpv6); + if(strcmp(dhcpv6, "server") == 0){ + get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(ss), &dmmap_section); + if(dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + } + break; + } + return 0; +} + +static int addObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct dhcpv6_args *dhcp_arg = (struct dhcpv6_args*)data; + struct uci_section *dmmap_sect; + char *value, *instancepara; + + check_create_dmmap_package("dmmap_dhcpv6"); + instancepara = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_dhcpv6", "servpool_option", "bbf_dhcpv6_servpool_option_instance", "section_name", section_name(dhcp_arg->dhcp_sec)); + dmuci_add_section_bbfdm("dmmap_dhcpv6", "servpool_option", &dmmap_sect, &value); + if (dhcp_arg->dhcp_sec != NULL) + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_arg->dhcp_sec)); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", "0"); + *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv6_servpool_option_instance"); + return 0; +} + +static int delObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s, *stmp; + char *opt_value = NULL; + struct uci_list *dhcp_options_list = NULL; + + switch (del_action) { + case DEL_INST: + if (strcmp(((struct dhcpv6_client_option_args*) data)->option_tag, "0") != 0) { + dmasprintf(&opt_value, "%s,%s", ((struct dhcpv6_client_option_args*) data)->option_tag, ((struct dhcpv6_client_option_args*) data)->value); + dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args*) data)->client_sect, "dhcp_option", &dhcp_options_list); + if (dhcp_options_list != NULL) { + dmuci_del_list_value_by_section(((struct dhcpv6_client_option_args*) data)->client_sect, "dhcp_option", opt_value); + } + } + dmuci_delete_by_section_unnamed_bbfdm(((struct dhcpv6_client_option_args*) data)->opt_sect, NULL, NULL); + break; + case DEL_ALL: + dmuci_set_value_by_section(((struct dhcpv6_args*) data)->dhcp_sec, "dhcp_option", ""); + uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcpv6", "servpool_option", stmp, s) { + dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); + } + break; + } + return 0; +} + +static int get_DHCPv6_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_path_foreach_sections(bbfdm, "dmmap_dhcpv6", "interface", s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +/*#Device.DHCPv6.Client.{i}.Enable!UCI:network/interface,@i-1/disabled*/ +static int get_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v = NULL; + + if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { + *value = "0"; + return 0; + } + + dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", &v); + if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) + *value = "1"; + else + *value = "0"; + return 0; +} + +static int set_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", b ? "0" : "1"); + return 0; + } + return 0; +} + +static int get_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_dm, "bbf_dhcpv6client_alias", value); + return 0; +} + +static int set_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_dm, "bbf_dhcpv6client_alias", value); + break; + } + return 0; +} + +static int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { + *value = ""; + return 0; + } + + char *linker = dmstrdup(section_name(((struct dhcpv6_client_args *)data)->dhcp_client_conf)); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), linker, value); + return 0; +} + +static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s; + char *linker = NULL, *newvalue = NULL, *v; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + + if (strlen(value) == 0 || strcmp(value, "") == 0) { + return FAULT_9007; + } + + if (value[strlen(value)-1] != '.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else { + adm_entry_get_linker_value(ctx, value, &linker); + } + uci_path_foreach_sections(bbfdm, "dmmap_dhcpv6", "interface", s) { + dmuci_get_value_by_section_string(s, "section_name", &v); + if (strcmp(v, linker) == 0) + return FAULT_9007; + } + uci_foreach_sections("network", "interface", s) { + if (strcmp(section_name(s), linker) == 0) { + dmuci_get_value_by_section_string(s, "proto", &v); + if (strcmp(v, "dhcpv6") != 0) + return FAULT_9007; + } + } + break; + case VALUESET: + if (value[strlen(value)-1]!='.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else { + adm_entry_get_linker_value(ctx, value, &linker); + } + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcpv6_client_args *)data)->dhcp_client_dm, "section_name", linker); + break; + } + return 0; +} + +/*#Device.DHCPv6.Client.{i}.Status!UCI:network/interface,@i-1/disabled*/ +static int get_DHCPv6Client_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v = NULL; + if(((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { + *value = "Error_Misconfigured"; + return 0; + } + + dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", &v); + if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) + *value = "Enabled"; + else + *value = "Disabled"; + return 0; +} + +/*#Device.DHCPv6.Client.{i}.DUID!UBUS:network.interface/status/interface,@Name/data.passthru*/ +static int get_DHCPv6Client_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcpv6_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + if (res) { + *value = dmjson_get_value(res, 2, "data", "passthru"); + } + return 0; +} + +/*#Device.DHCPv6.Client.{i}.RequestAddresses!UCI:network/interface,@i-1/reqaddress*/ +static int get_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v = NULL; + if(((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { + *value = ""; + return 0; + } + + dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqaddress", &v); + if (strcmp(v, "none") == 0) + *value = "0"; + else + *value = "1"; + return 0; +} + +static int set_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqaddress", b ? "force" : "none"); + break; + } + return 0; +} + +/*#Device.DHCPv6.Client.{i}.RequestPrefixes!UCI:network/interface,@i-1/reqprefix*/ +static int get_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v = ""; + if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { + *value = ""; + return 0; + } + + dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqprefix", &v); + if (strcmp(v, "no") == 0) + *value = "0"; + else + *value = "1"; + return 0; +} + +static int set_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqprefix", b ? "auto" : "no"); + return 0; + } + return 0; +} + +static int get_DHCPv6Client_RapidCommit(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6Client_RapidCommit(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "false"; + return 0; +} + +static int set_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + json_object *res; + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL && !b) + return 0; + + dmubus_call("network.interface", "renew", UBUS_ARGS{{"interface", section_name(((struct dhcpv6_client_args *)data)->dhcp_client_conf), String}}, 1, &res); + break; + } + return 0; +} + +static int get_DHCPv6Client_SuggestedT1(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6Client_SuggestedT1(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6Client_SuggestedT2(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6Client_SuggestedT2(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6Client_SupportedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.DHCPv6.Client.{i}.RequestedOptions!UCI:network/interface,@i-1/reqopts*/ +static int get_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if(((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { + *value = ""; + return 0; + } + dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqopts", value); + return 0; +} + +static int set_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt_list(value, NULL, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqopts", value); + break; + } + return 0; +} + +static int get_DHCPv6Client_ServerNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6Client_SentOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6Client_ReceivedOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ClientServer_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ClientServer_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ClientServer_InformationRefreshTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "0", "65535")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, "0", "65535")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ClientReceivedOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ClientReceivedOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ClientReceivedOption_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *path = "/etc/rc.d/*odhcpd"; + if (check_file(path)) + *value = "1"; + else + *value = "0"; + return 0; +} + +static int set_DHCPv6Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmcmd("/etc/init.d/odhcpd", 1, b ? "enable" : "disable"); + break; + } + return 0; +} + +static int get_DHCPv6Server_PoolNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int i = 0; + char *v = NULL; + + uci_foreach_sections("dhcp", "dhcp", s) { + dmuci_get_value_by_section_string(s, "dhcpv6", &v); + if (v!=NULL && strcmp(v, "server") == 0) + i++; + } + dmasprintf(value, "%d", i); + return 0; +} + +/*#Device.DHCPv6.Server.Pool.{i}.Enable!UCI:dhcp/dhcp,@i-1/ignore*/ +static int get_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcpv6_args *)data)->interface, s) { + dmuci_get_value_by_section_string(s, "ignore", value); + if ((*value)[0] == '\0') + *value = "1"; + else + *value = "0"; + return 0; + } + *value = "0"; + return 0; +} + +static int set_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcpv6_args *)data)->interface, s) { + dmuci_set_value_by_section(s, "ignore", b ? "0" : "1"); + break; + } + return 0; + } + return 0; +} + +/*#Device.DHCPv6.Server.Pool.{i}.Status!UCI:dhcp/dhcp,@i-1/ignore*/ +static int get_DHCPv6ServerPool_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *v= NULL; + + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcpv6_args *)data)->interface, s) { + dmuci_get_value_by_section_string(s, "ignore", &v); + *value = (v && *v == '1') ? "Disabled" : "Enabled"; + return 0; + } + *value="Error_Misconfigured"; + return 0; +} + +static int get_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_sect = NULL; + + get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect); + if (dmmap_sect) + dmuci_get_value_by_section_string(dmmap_sect, "dhcpv6_serv_pool_alias", value); + return 0; +} + +static int set_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_sect = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect); + if (dmmap_sect) + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "dhcpv6_serv_pool_alias", value); + return 0; + } + return 0; +} + +static int get_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_sect = NULL; + + get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect); + if (dmmap_sect) + dmuci_get_value_by_section_string(dmmap_sect, "order", value); + return 0; +} + +static int set_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_sect = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", NULL)) + return FAULT_9007; + break; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect); + if (dmmap_sect) + set_section_order("dhcp", "dmmap_dhcpv6", "dhcp", dmmap_sect, ((struct dhcpv6_args *)data)->dhcp_sec, 1, value); + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker; + linker = dmstrdup(((struct dhcpv6_args *)data)->interface); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + *value = ""; + dmfree(linker); + return 0; +} + +static int set_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + adm_entry_get_linker_value(ctx, value, &linker); + if (linker) { + dmuci_set_value_by_section(((struct dhcpv6_args *)data)->dhcp_sec, "interface", linker); + dmfree(linker); + } + return 0; + } + return 0; +} + +static int get_DHCPv6ServerPool_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPool_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "130")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_DUIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPool_DUIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.DHCPv6.Server.Pool.{i}.VendorClassID!UCI:dhcp/dhcp,@i-1/vendorclass*/ +static int get_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *vendorclassidclassifier = get_dhcpv6_classifier("vendorclass", ((struct dhcpv6_args *)data)->interface); + if (vendorclassidclassifier) + dmuci_get_value_by_section_string(vendorclassidclassifier, "vendorclass", value); + return 0; +} + +static int set_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *vendorclassidclassifier = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "65535")) + return FAULT_9007; + break; + case VALUESET: + vendorclassidclassifier = get_dhcpv6_classifier("vendorclass", ((struct dhcpv6_args *)data)->interface); + if (vendorclassidclassifier) + dmuci_set_value_by_section(vendorclassidclassifier, "vendorclass", value); + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPool_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.DHCPv6.Server.Pool.{i}.UserClassID!UCI:dhcp/dhcp,@i-1/userclass*/ +static int get_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *userclassidclassifier= get_dhcpv6_classifier("userclass", ((struct dhcpv6_args *)data)->interface); + if (userclassidclassifier) + dmuci_get_value_by_section_string(userclassidclassifier, "userclass", value); + return 0; +} + +static int set_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *userclassidclassifier; + + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "65535")) + return FAULT_9007; + break; + case VALUESET: + userclassidclassifier= get_dhcpv6_classifier("userclass", ((struct dhcpv6_args *)data)->interface); + if (userclassidclassifier) + dmuci_set_value_by_section(userclassidclassifier, "userclass", value); + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPool_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *macaddrclassifier; + char *mac, **macarray, *res = NULL, *tmp = ""; + int i; + size_t length; + + macaddrclassifier = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface); + if (macaddrclassifier == NULL) { + *value= ""; + return 0; + } + dmuci_get_value_by_section_string(macaddrclassifier, "mac", &mac); + macarray = strsplit(mac, ":", &length); + res = (char*)dmcalloc(18, sizeof(char)); + tmp = res; + for (i = 0; i < 6; i++) { + if(strcmp(macarray[i], "*") == 0) { + sprintf(tmp, "%s", "00"); + } else { + sprintf(tmp, "%s", macarray[i]); + } + tmp += 2; + + if (i < 5) { + sprintf(tmp, "%s", ":"); + tmp++; + } + } + dmasprintf(value, "%s", res); + return 0; +} + +static int set_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "45", NULL, IPv6Address)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *macaddrclassifier; + char *mac, **macarray, *res = NULL, *tmp = ""; + int i; + size_t length; + + macaddrclassifier = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface); + if (macaddrclassifier == NULL) { + *value= ""; + return 0; + } + dmuci_get_value_by_section_string(macaddrclassifier, "mac", &mac); + macarray = strsplit(mac, ":", &length); + res = (char *)dmcalloc(18, sizeof(char)); + tmp = res; + for (i = 0; i < 6; i++) { + if (strcmp(macarray[i], "*") == 0) { + sprintf(tmp, "%s", "00"); + } else { + sprintf(tmp, "%s", "FF"); + } + tmp += 2; + if (i < 5) { + sprintf(tmp, "%s", ":"); + tmp++; + } + } + dmasprintf(value, "%s", res); + return 0; +} + +static int set_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "45", NULL, IPv6Address)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_SourceAddressExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPool_SourceAddressExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_IANAEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPool_IANAEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_IANAManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPool_IANAManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, "8", NULL, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_IANAPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ServerPool_IAPDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPool_IAPDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_IAPDManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPool_IAPDManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, "8", NULL, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_IAPDPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ServerPool_IAPDAddLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPool_IAPDAddLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, "64")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ServerPool_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res, *res1, *jobj, *dev_obj = NULL, *next_obj = NULL; + char *device; + int i = 0; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcpv6_args *)data)->dhcp_sec), String}}, 1, &res1); + DM_ASSERT(res1, *value = "0"); + device = dmjson_get_value(res1, 1, "device"); + dmubus_call("dhcp", "ipv6leases", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = "0"); + dev_obj = dmjson_get_obj(res, 1, "device"); + DM_ASSERT(dev_obj, *value = "0"); + next_obj = dmjson_get_obj(dev_obj, 1, device); + DM_ASSERT(next_obj, *value = "0"); + while (1) { + jobj = dmjson_select_obj_in_array_idx(next_obj, i, 1, "leases"); + if (jobj == NULL) + break; + i++; + } + dmasprintf(value, "%d", i); + return 0; +} + +static int get_DHCPv6ServerPool_OptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *dhcp_options_list = NULL; + struct uci_element *e; + int i = 0; + + dmuci_get_value_by_section_list(((struct dhcpv6_args *)data)->dhcp_sec, "dhcp_option", &dhcp_options_list); + if (dhcp_options_list != NULL) { + uci_foreach_element(dhcp_options_list, e) { + i++; + } + } + dmasprintf(value, "%d", i); + return 0; +} + +static int get_DHCPv6ServerPoolClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPoolClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + break; + case VALUESET: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + //TODO + break; + } + return 0; +} + +static int get_DHCPv6ServerPoolClient_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ServerPoolClient_Active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ServerPoolClient_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *address_obj = NULL; + int i = 0; + + while (1) { + address_obj = dmjson_select_obj_in_array_idx(((struct clientv6_args *)data)->client, i, 1, "ipv6-addr"); + if (address_obj == NULL) + break; + i++; + } + dmasprintf(value, "%d", i); + return 0; +} + +static int get_DHCPv6ServerPoolClient_IPv6PrefixNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *address_obj = NULL; + int i= 0; + + while (1) { + address_obj = dmjson_select_obj_in_array_idx(((struct clientv6_args *)data)->client, i, 1, "ipv6-prefix"); + if (address_obj == NULL) + break; + i++; + } + dmasprintf(value, "%d", i); + return 0; +} + +static int get_DHCPv6ServerPoolClient_OptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ServerPoolClientIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "address"); + return 0; +} + +static int get_DHCPv6ServerPoolClientIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "preferred-lifetime"); + return 0; +} + +static int get_DHCPv6ServerPoolClientIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "valid-lifetime"); + return 0; +} + +static int get_DHCPv6ServerPoolClientIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "address"); + return 0; +} + +static int get_DHCPv6ServerPoolClientIPv6Prefix_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "preferred-lifetime"); + return 0; +} + +static int get_DHCPv6ServerPoolClientIPv6Prefix_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "valid-lifetime"); + return 0; +} + +static int get_DHCPv6ServerPoolClientOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ServerPoolClientOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *dhcp_option_list; + struct uci_element *e; + char **buf; + size_t length; + + if(strcmp(((struct dhcpv6_client_option_args *)data)->option_tag, "0") == 0){ + *value= "0"; + return 0; + } + + dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + if (dhcp_option_list != NULL) { + uci_foreach_element(dhcp_option_list, e) { + buf = strsplit(e->name, ",", &length); + if (strcmp(buf[0], ((struct dhcpv6_client_option_args *)data)->option_tag) == 0) { + *value= "1"; + return 0; + } + } + } + + *value= "0"; + return 0; +} + +static int set_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_list *dhcp_option_list; + struct uci_element *e; + char **buf, *opt_value; + size_t length; + bool test = false, b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + + if (strcmp(((struct dhcpv6_client_option_args *)data)->option_tag, "0") == 0) + return 0; + + dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + dmasprintf(&opt_value, "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, ((struct dhcpv6_client_option_args *)data)->value); + + if (dhcp_option_list != NULL) { + uci_foreach_element(dhcp_option_list, e) { + buf = strsplit(e->name, ",", &length); + if (strcmp(buf[0], ((struct dhcpv6_client_option_args *)data)->option_tag) == 0) { + test = true; + if (!b) + dmuci_del_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", opt_value); + break; + } + } + } + if (!test && b) + dmuci_add_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", opt_value); + } + return 0; +} + +static int get_DHCPv6ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dhcpv6_client_option_args *)data)->opt_sect, "bbf_dhcpv6_servpool_option_alias", value); + return 0; + +} + +static int set_DHCPv6ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcpv6_client_option_args *)data)->opt_sect, "bbf_dhcpv6_servpool_option_alias", value); + break; + } + return 0; +} + +static int get_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(((struct dhcpv6_client_option_args *)data)->option_tag); + return 0; +} + +static int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *opttagvalue, **option, *oldopttagvalue; + size_t length; + struct uci_list *dhcp_option_list= NULL; + struct uci_element *e; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "0", "65535")) + return FAULT_9007; + + dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + + if (dhcp_option_list == NULL) + return 0; + + uci_foreach_element(dhcp_option_list, e) { + option = strsplit(e->name, ",", &length); + if (strcmp(option[0], value)==0) + return FAULT_9007; + } + break; + case VALUESET: + dmasprintf(&oldopttagvalue, "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, ((struct dhcpv6_client_option_args *)data)->value); + dmasprintf(&opttagvalue, "%s,%s", value, ((struct dhcpv6_client_option_args *)data)->value); + dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + dmuci_del_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", oldopttagvalue); + dmuci_add_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", opttagvalue); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcpv6_client_option_args *)data)->opt_sect, "option_tag", value); + break; + } + return 0; +} + +static int get_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value= dmstrdup(((struct dhcpv6_client_option_args *)data)->value); + return 0; +} + +static int set_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *opttagvalue, **option, *oldopttagvalue; + size_t length; + struct uci_list *dhcp_option_list = NULL; + struct uci_element *e; + + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, "0", "65535")) + return FAULT_9007; + + dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + if (dhcp_option_list == NULL) + return 0; + + uci_foreach_element(dhcp_option_list, e) { + option = strsplit(e->name, ",", &length); + if (strcmp(option[0], value) == 0) + return FAULT_9007; + } + break; + case VALUESET: + dmasprintf(&oldopttagvalue, "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, ((struct dhcpv6_client_option_args *)data)->value); + dmasprintf(&opttagvalue, "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, value); + dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); + dmuci_del_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", oldopttagvalue); + dmuci_add_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", opttagvalue); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcpv6_client_option_args *)data)->opt_sect, "option_value", value); + break; + } + return 0; +} + +static int get_DHCPv6ServerPoolOption_PassthroughClient(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_DHCPv6ServerPoolOption_PassthroughClient(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + /* *** Device.DHCPv6. *** */ DMOBJ tDHCPv6Obj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -190,1824 +2038,3 @@ DMLEAF tDHCPv6ServerPoolOptionParams[] = { //{"PassthroughClient", &DMWRITE, DMT_STRING, get_DHCPv6ServerPoolOption_PassthroughClient, set_DHCPv6ServerPoolOption_PassthroughClient, NULL, NULL, BBFDM_BOTH}, {0} }; - -struct uci_section* get_dhcpv6_classifier(char *classifier_name, char *network) -{ - struct uci_section *s = NULL; - char *v; - - uci_foreach_sections("dhcp", classifier_name, s) { - dmuci_get_value_by_section_string(s, "networkid", &v); - if (strcmp(v, network) == 0) - return s; - } - return NULL; -} - -static inline int init_dhcpv6_client_args(struct clientv6_args *args, json_object *client, json_object *client_param, int i) -{ - args->client = client; - args->clientparam = client_param; - args->idx = i; - return 0; -} - -struct uci_section* exist_other_section_dhcp6_same_order(struct uci_section *dmmap_sect, char * package, char* sect_type, char *order) -{ - struct uci_section *s; - uci_path_foreach_option_eq(bbfdm, package, sect_type, "order", order, s) { - if (strcmp(section_name(s), section_name(dmmap_sect)) != 0) { - return s; - } - } - return NULL; -} - -int set_section_dhcp6_order(char *package, char *dmpackage, char* sect_type, struct uci_section *dmmap_sect, struct uci_section *conf, int set_force, char* order) -{ - char *v = NULL, *sect_name, *incrorder; - struct uci_section *s, *dm; - dmuci_get_value_by_section_string(dmmap_sect, "order", &v); - if(strlen(v) > 0 && strcmp(v, order) == 0) - return 0; - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "order", order); - if (conf == NULL) { - dmuci_get_value_by_section_string(dmmap_sect, "section_name", §_name); - get_config_section_of_dmmap_section(package, sect_type, sect_name, &s); - } else - s= conf; - - if (strcmp(order, "1") != 0 && s != NULL) { - dmuci_set_value_by_section(s, "force", ""); - } - - if (set_force==1 && strcmp(order, "1") == 0 && s != NULL) { - dmuci_set_value_by_section(s, "force", "1"); - } - - if ((dm = exist_other_section_dhcp6_same_order(dmmap_sect, dmpackage, sect_type, order)) != NULL) { - dmuci_get_value_by_section_string(dm, "section_name", §_name); - get_config_section_of_dmmap_section(package, sect_type, sect_name, &s); - dmasprintf(&incrorder, "%d", atoi(order)+1); - if (s != NULL && strcmp(order, "1") == 0) { - dmuci_set_value_by_section(s, "force", ""); - } - set_section_dhcp6_order(package, dmpackage, sect_type, dm, s, set_force, incrorder); - } - return 0; - -} - -static inline int init_dhcpv6_args(struct dhcpv6_args *args, struct uci_section *s, char *interface) -{ - args->interface = interface; - args->dhcp_sec = s; - return 0; -} - -/*#Device.DHCPv6.Client.{i}.!UCI:network/interface/dmmap_dhcpv6*/ -int browseDHCPv6ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct dmmap_dup *p; - struct dhcpv6_client_args dhcpv6_client_arg = {0}; - json_object *res, *jobj; - char *instance, *instnbr = NULL, *ipv6addr = NULL; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap_eq_no_delete("network", "interface", "dmmap_dhcpv6", "proto", "dhcpv6", &dup_list); - list_for_each_entry(p, &dup_list, list) { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); - ipv6addr = dmjson_get_value(jobj, 1, "address"); - } - dhcpv6_client_arg.dhcp_client_conf = p->config_section; - dhcpv6_client_arg.dhcp_client_dm = p->dmmap_section; - dhcpv6_client_arg.ip = dmstrdup(ipv6addr?ipv6addr:""); - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, p->dmmap_section, "bbf_dhcpv6client_instance", "bbf_dhcpv6client_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcpv6_client_arg, instance) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int browseDHCPv6ClientServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - //TODO - return 0; -} - -int browseDHCPv6ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - //TODO - return 0; -} - -int browseDHCPv6ClientReceivedOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - //TODO - return 0; -} - -/*#Device.DHCPv6.Server.Pool.{i}.!UCI:dhcp/dhcp/dmmap_dhcpv6*/ -int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *interface, *idhcp = NULL, *idhcp_last = NULL, *v; - struct dhcpv6_args curr_dhcp6_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap_eq("dhcp", "dhcp", "dmmap_dhcpv6", "dhcpv6", "server", &dup_list); - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "interface", &interface); - init_dhcpv6_args(&curr_dhcp6_args, p->config_section, interface); - idhcp = handle_update_instance(1, dmctx, &idhcp_last, update_instance_alias_bbfdm, 3, p->dmmap_section, "dhcpv6_serv_pool_instance", "dhcpv6_serv_pool_alias"); - dmuci_get_value_by_section_string(p->dmmap_section, "order", &v); - if (v == NULL || strlen(v) == 0) - set_section_dhcp6_order("dhcp", "dmmap_dhcpv6", "dhcp", p->dmmap_section, p->config_section, 0, idhcp); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp6_args, idhcp) == DM_STOP) - break; - } - - free_dmmap_config_dup_list(&dup_list); - - return 0; -} - -int browseDHCPv6ServerPoolClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct dhcpv6_args *dhcp_arg= (struct dhcpv6_args*)prev_data; - json_object *res, *res1, *jobj, *dev_obj= NULL, *net_obj= NULL; - struct clientv6_args curr_dhcp_client_args = {0}; - int i = 0; - char *idx = NULL, *idx_last = NULL, *device; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(dhcp_arg->dhcp_sec), String}}, 1, &res1); - if (!res1) return 0; - device = dmjson_get_value(res1, 1, "device"); - dmubus_call("dhcp", "ipv6leases", UBUS_ARGS{}, 0, &res); - if (!res) return 0; - dev_obj = dmjson_get_obj(res, 1, "device"); - if (!dev_obj) return 0; - net_obj = dmjson_get_obj(dev_obj, 1, device); - if (!net_obj) return 0; - - while (1) { - jobj = dmjson_select_obj_in_array_idx(net_obj, i, 1, "leases"); - if (!jobj) break; - init_dhcpv6_client_args(&curr_dhcp_client_args, jobj, NULL, i); - i++; - idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, i); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_client_args, idx) == DM_STOP) - break; - } - return 0; -} - -int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_list *dhcp_options_list = NULL; - struct uci_element *e; - struct dhcpv6_args *curr_dhcp_args = (struct dhcpv6_args*)prev_data; - struct uci_section *dmmap_sect; - char **tagvalue = NULL, *instance, *instnbr = NULL, *optionvalue= NULL, *tmp, *v1, *v2, *v; - size_t length; - int j; - struct dhcpv6_client_option_args dhcp_client_opt_args = {0}; - - dmuci_get_value_by_section_list(curr_dhcp_args->dhcp_sec, "dhcp_option", &dhcp_options_list); - if (dhcp_options_list != NULL) { - uci_foreach_element(dhcp_options_list, e) { - tagvalue= strsplit(e->name, ",", &length); - if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcpv6", "servpool_option", section_name(curr_dhcp_args->dhcp_sec), "option_tag", tagvalue[0])) == NULL) { - dmuci_add_section_bbfdm("dmmap_dhcpv6", "servpool_option", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", tagvalue[0]); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(curr_dhcp_args->dhcp_sec)); - } - optionvalue=dmstrdup(tagvalue[1]); - if (length > 2) { - for (j = 2; j < length; j++){ - tmp=dmstrdup(optionvalue); - dmfree(optionvalue); - optionvalue= NULL; - dmasprintf(&optionvalue, "%s,%s", tmp, tagvalue[j]); - dmfree(tmp); - tmp= NULL; - } - } - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_value", optionvalue); - } - } - uci_path_foreach_option_eq(bbfdm, "dmmap_dhcpv6", "servpool_option", "section_name", section_name(curr_dhcp_args->dhcp_sec), dmmap_sect) { - dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &v1); - dmuci_get_value_by_section_string(dmmap_sect, "option_value", &v2); - dhcp_client_opt_args.client_sect= curr_dhcp_args->dhcp_sec; - dhcp_client_opt_args.option_tag = dmstrdup(v1); - dhcp_client_opt_args.value = dmstrdup(v2); - dhcp_client_opt_args.opt_sect = dmmap_sect; - instance= handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "bbf_dhcpv6_servpool_option_instance", "bbf_dhcpv6_servpool_option_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &dhcp_client_opt_args, instance) == DM_STOP) - break; - } - return 0; -} - -int browseDHCPv6ServerPoolClientIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct clientv6_args *dhcpv6_serv_pool_client = (struct clientv6_args *)prev_data; - json_object *address_obj= NULL; - struct clientv6_args curr_dhcv6_address_args = {0}; - char *idx = NULL, *idx_last = NULL; - int i = 0; - - while (1) { - address_obj = dmjson_select_obj_in_array_idx(dhcpv6_serv_pool_client->client, i, 1, "ipv6-addr"); - if (address_obj == NULL) - break; - init_dhcpv6_client_args(&curr_dhcv6_address_args, dhcpv6_serv_pool_client->client, address_obj, i); - i++; - idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, i); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcv6_address_args, idx) == DM_STOP) - break; - } - - return 0; -} - -int browseDHCPv6ServerPoolClientIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct clientv6_args *dhcpv6_serv_pool_client = (struct clientv6_args *)prev_data; - json_object *address_obj = NULL; - struct clientv6_args curr_dhcv6_address_args = {0}; - char *idx = NULL, *idx_last = NULL; - int i = 0; - - while (1) { - address_obj = dmjson_select_obj_in_array_idx(dhcpv6_serv_pool_client->client, i, 1, "ipv6-prefix"); - if (address_obj == NULL) - break; - init_dhcpv6_client_args(&curr_dhcv6_address_args, dhcpv6_serv_pool_client->client, address_obj, i); - i++; - idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, i); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcv6_address_args, idx) == DM_STOP) - break; - } - - return 0; -} - -int browseDHCPv6ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - //TODO - return 0; -} - - -int addObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct uci_section *s, *dmmap_sect; - char *value, *instancepara, *v; - - check_create_dmmap_package("dmmap_dhcpv6"); - instancepara = get_last_instance_bbfdm("dmmap_dhcpv6", "interface", "bbf_dhcpv6client_instance"); - dmuci_add_section("network", "interface", &s, &value); - dmuci_set_value_by_section(s, "proto", "dhcpv6"); - dmuci_set_value_by_section(s, "ifname", "@wan"); - dmuci_set_value_by_section(s, "type", "anywan"); - dmuci_add_section_bbfdm("dmmap_dhcpv6", "interface", &dmmap_sect, &v); - dmuci_set_value_by_section(dmmap_sect, "section_name", section_name(s)); - *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv6client_instance"); - return 0; -} - -int delObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct dhcpv6_client_args *dhcpv6_client_args = (struct dhcpv6_client_args*)data; - struct uci_section *s, *dmmap_section, *ss = NULL; - int found = 0; - char *proto; - - switch (del_action) { - case DEL_INST: - if(dhcpv6_client_args->dhcp_client_conf != NULL && is_section_unnamed(section_name(dhcpv6_client_args->dhcp_client_conf))){ - LIST_HEAD(dup_list); - delete_sections_save_next_sections("dmmap_dhcpv6", "interface", "bbf_dhcpv6client_instance", section_name(dhcpv6_client_args->dhcp_client_conf), atoi(instance), &dup_list); - update_dmmap_sections(&dup_list, "bbf_dhcpv6client_instance", "dmmap_dhcpv6", "interface"); - dmuci_delete_by_section_unnamed(dhcpv6_client_args->dhcp_client_conf, NULL, NULL); - } else { - get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(dhcpv6_client_args->dhcp_client_conf), &dmmap_section); - dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); - dmuci_delete_by_section(dhcpv6_client_args->dhcp_client_conf, NULL, NULL); - } - break; - case DEL_ALL: - uci_foreach_sections("network", "interface", s) { - if (found != 0) { - dmuci_get_value_by_section_string(ss, "proto", &proto); - if(strcmp(proto, "dhcpv6") == 0) { - get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(ss), &dmmap_section); - if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - } - ss = s; - found++; - } - if (ss != NULL) { - dmuci_get_value_by_section_string(ss, "proto", &proto); - if (strcmp(proto, "dhcpv6") == 0) { - get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(ss), &dmmap_section); - if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - } - break; - } - return 0; -} - -int addObjDHCPv6ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - //TODO - return 0; -} - -int delObjDHCPv6ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - switch (del_action) { - case DEL_INST: - //TODO - break; - case DEL_ALL: - //TODO - break; - } - return 0; -} - -int addObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *value, *v, *instancepara; - struct uci_section *s = NULL, *dmmap_dhcp= NULL; - - check_create_dmmap_package("dmmap_dhcpv6"); - instancepara = get_last_instance_bbfdm("dmmap_dhcpv6", "dhcp", "dhcpv6_serv_pool_instance"); - dmuci_add_section("dhcp", "dhcp", &s, &value); - dmuci_set_value_by_section(s, "dhcpv6", "server"); - dmuci_set_value_by_section(s, "start", "100"); - dmuci_set_value_by_section(s, "leasetime", "12h"); - dmuci_set_value_by_section(s, "limit", "150"); - - dmuci_add_section_bbfdm("dmmap_dhcpv6", "dhcp", &dmmap_dhcp, &v); - dmuci_set_value_by_section(dmmap_dhcp, "section_name", section_name(s)); - *instance = update_instance_bbfdm(dmmap_dhcp, instancepara, "dhcpv6_serv_pool_instance"); - return 0; -} - -int delObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - int found = 0; - struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; - char *dhcpv6 = NULL; - - switch (del_action) { - case DEL_INST: - if(is_section_unnamed(section_name(((struct dhcpv6_args *)data)->dhcp_sec))){ - LIST_HEAD(dup_list); - delete_sections_save_next_sections("dmmap_dhcpv6", "dhcp", "dhcpv6_serv_pool_instance", section_name(((struct dhcpv6_args *)data)->dhcp_sec), atoi(instance), &dup_list); - update_dmmap_sections(&dup_list, "dhcpv6_serv_pool_instance", "dmmap_dhcpv6", "dhcp"); - dmuci_delete_by_section_unnamed(((struct dhcpv6_args *)data)->dhcp_sec, NULL, NULL); - } else { - get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_section); - if(dmmap_section) dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); - dmuci_delete_by_section(((struct dhcpv6_args *)data)->dhcp_sec, NULL, NULL); - } - break; - case DEL_ALL: - uci_foreach_sections("dhcp", "dhcp", s) { - if (found != 0){ - dmuci_get_value_by_section_string(ss, "dhcpv6", &dhcpv6); - if(strcmp(dhcpv6, "server") == 0){ - get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(s), &dmmap_section); - if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - } - ss = s; - found++; - } - if (ss != NULL){ - dmuci_get_value_by_section_string(ss, "dhcpv6", &dhcpv6); - if(strcmp(dhcpv6, "server") == 0){ - get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(ss), &dmmap_section); - if(dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - } - break; - } - return 0; -} - -int addObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct dhcpv6_args *dhcp_arg = (struct dhcpv6_args*)data; - struct uci_section *dmmap_sect; - char *value, *instancepara; - - check_create_dmmap_package("dmmap_dhcpv6"); - instancepara = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_dhcpv6", "servpool_option", "bbf_dhcpv6_servpool_option_instance", "section_name", section_name(dhcp_arg->dhcp_sec)); - dmuci_add_section_bbfdm("dmmap_dhcpv6", "servpool_option", &dmmap_sect, &value); - if (dhcp_arg->dhcp_sec != NULL) - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "section_name", section_name(dhcp_arg->dhcp_sec)); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "option_tag", "0"); - *instance = update_instance_bbfdm(dmmap_sect, instancepara, "bbf_dhcpv6_servpool_option_instance"); - return 0; -} - -int delObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *s, *stmp; - char *opt_value = NULL; - struct uci_list *dhcp_options_list = NULL; - - switch (del_action) { - case DEL_INST: - if (strcmp(((struct dhcpv6_client_option_args*) data)->option_tag, "0") != 0) { - dmasprintf(&opt_value, "%s,%s", ((struct dhcpv6_client_option_args*) data)->option_tag, ((struct dhcpv6_client_option_args*) data)->value); - dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args*) data)->client_sect, "dhcp_option", &dhcp_options_list); - if (dhcp_options_list != NULL) { - dmuci_del_list_value_by_section(((struct dhcpv6_client_option_args*) data)->client_sect, "dhcp_option", opt_value); - } - } - dmuci_delete_by_section_unnamed_bbfdm(((struct dhcpv6_client_option_args*) data)->opt_sect, NULL, NULL); - break; - case DEL_ALL: - dmuci_set_value_by_section(((struct dhcpv6_args*) data)->dhcp_sec, "dhcp_option", ""); - uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcpv6", "servpool_option", stmp, s) { - dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); - } - break; - } - return 0; -} - -int get_DHCPv6_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_path_foreach_sections(bbfdm, "dmmap_dhcpv6", "interface", s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -/*#Device.DHCPv6.Client.{i}.Enable!UCI:network/interface,@i-1/disabled*/ -int get_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v = NULL; - - if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = "0"; - return 0; - } - - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", &v); - if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", b ? "0" : "1"); - return 0; - } - return 0; -} - -int get_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_dm, "bbf_dhcpv6client_alias", value); - return 0; -} - -int set_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_dm, "bbf_dhcpv6client_alias", value); - break; - } - return 0; -} - -int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = ""; - return 0; - } - - char *linker = dmstrdup(section_name(((struct dhcpv6_client_args *)data)->dhcp_client_conf)); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), linker, value); - return 0; -} - -int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *s; - char *linker = NULL, *newvalue = NULL, *v; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - - if (strlen(value) == 0 || strcmp(value, "") == 0) { - return FAULT_9007; - } - - if (value[strlen(value)-1] != '.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else { - adm_entry_get_linker_value(ctx, value, &linker); - } - uci_path_foreach_sections(bbfdm, "dmmap_dhcpv6", "interface", s) { - dmuci_get_value_by_section_string(s, "section_name", &v); - if (strcmp(v, linker) == 0) - return FAULT_9007; - } - uci_foreach_sections("network", "interface", s) { - if (strcmp(section_name(s), linker) == 0) { - dmuci_get_value_by_section_string(s, "proto", &v); - if (strcmp(v, "dhcpv6") != 0) - return FAULT_9007; - } - } - break; - case VALUESET: - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else { - adm_entry_get_linker_value(ctx, value, &linker); - } - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcpv6_client_args *)data)->dhcp_client_dm, "section_name", linker); - break; - } - return 0; -} - -/*#Device.DHCPv6.Client.{i}.Status!UCI:network/interface,@i-1/disabled*/ -int get_DHCPv6Client_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v = NULL; - if(((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = "Error_Misconfigured"; - return 0; - } - - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", &v); - if (v == NULL || strlen(v) == 0 || strcmp(v, "1") != 0) - *value = "Enabled"; - else - *value = "Disabled"; - return 0; -} - -/*#Device.DHCPv6.Client.{i}.DUID!UBUS:network.interface/status/interface,@Name/data.passthru*/ -int get_DHCPv6Client_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcpv6_client_args *)data)->dhcp_client_conf), String}}, 1, &res); - if (res) { - *value = dmjson_get_value(res, 2, "data", "passthru"); - } - return 0; -} - -/*#Device.DHCPv6.Client.{i}.RequestAddresses!UCI:network/interface,@i-1/reqaddress*/ -int get_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v = NULL; - if(((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = ""; - return 0; - } - - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqaddress", &v); - if (strcmp(v, "none") == 0) - *value = "0"; - else - *value = "1"; - return 0; -} - -int set_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqaddress", b ? "force" : "none"); - break; - } - return 0; -} - -/*#Device.DHCPv6.Client.{i}.RequestPrefixes!UCI:network/interface,@i-1/reqprefix*/ -int get_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v = ""; - if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = ""; - return 0; - } - - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqprefix", &v); - if (strcmp(v, "no") == 0) - *value = "0"; - else - *value = "1"; - return 0; -} - -int set_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqprefix", b ? "auto" : "no"); - return 0; - } - return 0; -} - -int get_DHCPv6Client_RapidCommit(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6Client_RapidCommit(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "false"; - return 0; -} - -int set_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - json_object *res; - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - if (((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL && !b) - return 0; - - dmubus_call("network.interface", "renew", UBUS_ARGS{{"interface", section_name(((struct dhcpv6_client_args *)data)->dhcp_client_conf), String}}, 1, &res); - break; - } - return 0; -} - -int get_DHCPv6Client_SuggestedT1(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6Client_SuggestedT1(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6Client_SuggestedT2(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6Client_SuggestedT2(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6Client_SupportedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.DHCPv6.Client.{i}.RequestedOptions!UCI:network/interface,@i-1/reqopts*/ -int get_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - if(((struct dhcpv6_client_args *)data)->dhcp_client_conf == NULL) { - *value = ""; - return 0; - } - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqopts", value); - return 0; -} - -int set_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt_list(value, NULL, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqopts", value); - break; - } - return 0; -} - -int get_DHCPv6Client_ServerNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6Client_SentOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6Client_ReceivedOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ClientServer_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ClientServer_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ClientServer_InformationRefreshTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "0", "65535")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, "0", "65535")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ClientReceivedOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ClientReceivedOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ClientReceivedOption_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *path = "/etc/rc.d/*odhcpd"; - if (check_file(path)) - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_DHCPv6Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmcmd("/etc/init.d/odhcpd", 1, b ? "enable" : "disable"); - break; - } - return 0; -} - -int get_DHCPv6Server_PoolNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int i = 0; - char *v = NULL; - - uci_foreach_sections("dhcp", "dhcp", s) { - dmuci_get_value_by_section_string(s, "dhcpv6", &v); - if (v!=NULL && strcmp(v, "server") == 0) - i++; - } - dmasprintf(value, "%d", i); - return 0; -} - -/*#Device.DHCPv6.Server.Pool.{i}.Enable!UCI:dhcp/dhcp,@i-1/ignore*/ -int get_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcpv6_args *)data)->interface, s) { - dmuci_get_value_by_section_string(s, "ignore", value); - if ((*value)[0] == '\0') - *value = "1"; - else - *value = "0"; - return 0; - } - *value = "0"; - return 0; -} - -int set_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcpv6_args *)data)->interface, s) { - dmuci_set_value_by_section(s, "ignore", b ? "0" : "1"); - break; - } - return 0; - } - return 0; -} - -/*#Device.DHCPv6.Server.Pool.{i}.Status!UCI:dhcp/dhcp,@i-1/ignore*/ -int get_DHCPv6ServerPool_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - char *v= NULL; - - uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcpv6_args *)data)->interface, s) { - dmuci_get_value_by_section_string(s, "ignore", &v); - *value = (v && *v == '1') ? "Disabled" : "Enabled"; - return 0; - } - *value="Error_Misconfigured"; - return 0; -} - -int get_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_sect = NULL; - - get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect); - if (dmmap_sect) - dmuci_get_value_by_section_string(dmmap_sect, "dhcpv6_serv_pool_alias", value); - return 0; -} - -int set_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_sect = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect); - if (dmmap_sect) - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "dhcpv6_serv_pool_alias", value); - return 0; - } - return 0; -} - -int get_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_sect = NULL; - - get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect); - if (dmmap_sect) - dmuci_get_value_by_section_string(dmmap_sect, "order", value); - return 0; -} - -int set_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_sect = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", NULL)) - return FAULT_9007; - break; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect); - if (dmmap_sect) - set_section_order("dhcp", "dmmap_dhcpv6", "dhcp", dmmap_sect, ((struct dhcpv6_args *)data)->dhcp_sec, 1, value); - break; - } - return 0; -} - -int get_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *linker; - linker = dmstrdup(((struct dhcpv6_args *)data)->interface); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - *value = ""; - dmfree(linker); - return 0; -} - -int set_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *linker; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); - if (linker) { - dmuci_set_value_by_section(((struct dhcpv6_args *)data)->dhcp_sec, "interface", linker); - dmfree(linker); - } - return 0; - } - return 0; -} - -int get_DHCPv6ServerPool_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPool_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "130")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ServerPool_DUIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPool_DUIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.DHCPv6.Server.Pool.{i}.VendorClassID!UCI:dhcp/dhcp,@i-1/vendorclass*/ -int get_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *vendorclassidclassifier = get_dhcpv6_classifier("vendorclass", ((struct dhcpv6_args *)data)->interface); - if (vendorclassidclassifier) - dmuci_get_value_by_section_string(vendorclassidclassifier, "vendorclass", value); - return 0; -} - -int set_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *vendorclassidclassifier = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "65535")) - return FAULT_9007; - break; - case VALUESET: - vendorclassidclassifier = get_dhcpv6_classifier("vendorclass", ((struct dhcpv6_args *)data)->interface); - if (vendorclassidclassifier) - dmuci_set_value_by_section(vendorclassidclassifier, "vendorclass", value); - break; - } - return 0; -} - -int get_DHCPv6ServerPool_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPool_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.DHCPv6.Server.Pool.{i}.UserClassID!UCI:dhcp/dhcp,@i-1/userclass*/ -int get_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *userclassidclassifier= get_dhcpv6_classifier("userclass", ((struct dhcpv6_args *)data)->interface); - if (userclassidclassifier) - dmuci_get_value_by_section_string(userclassidclassifier, "userclass", value); - return 0; -} - -int set_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *userclassidclassifier; - - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "65535")) - return FAULT_9007; - break; - case VALUESET: - userclassidclassifier= get_dhcpv6_classifier("userclass", ((struct dhcpv6_args *)data)->interface); - if (userclassidclassifier) - dmuci_set_value_by_section(userclassidclassifier, "userclass", value); - break; - } - return 0; -} - -int get_DHCPv6ServerPool_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPool_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *macaddrclassifier; - char *mac, **macarray, *res = NULL, *tmp = ""; - int i; - size_t length; - - macaddrclassifier = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface); - if (macaddrclassifier == NULL) { - *value= ""; - return 0; - } - dmuci_get_value_by_section_string(macaddrclassifier, "mac", &mac); - macarray = strsplit(mac, ":", &length); - res = (char*)dmcalloc(18, sizeof(char)); - tmp = res; - for (i = 0; i < 6; i++) { - if(strcmp(macarray[i], "*") == 0) { - sprintf(tmp, "%s", "00"); - } else { - sprintf(tmp, "%s", macarray[i]); - } - tmp += 2; - - if (i < 5) { - sprintf(tmp, "%s", ":"); - tmp++; - } - } - dmasprintf(value, "%s", res); - return 0; -} - -int set_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "45", NULL, IPv6Address)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *macaddrclassifier; - char *mac, **macarray, *res = NULL, *tmp = ""; - int i; - size_t length; - - macaddrclassifier = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface); - if (macaddrclassifier == NULL) { - *value= ""; - return 0; - } - dmuci_get_value_by_section_string(macaddrclassifier, "mac", &mac); - macarray = strsplit(mac, ":", &length); - res = (char *)dmcalloc(18, sizeof(char)); - tmp = res; - for (i = 0; i < 6; i++) { - if (strcmp(macarray[i], "*") == 0) { - sprintf(tmp, "%s", "00"); - } else { - sprintf(tmp, "%s", "FF"); - } - tmp += 2; - if (i < 5) { - sprintf(tmp, "%s", ":"); - tmp++; - } - } - dmasprintf(value, "%s", res); - return 0; -} - -int set_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "45", NULL, IPv6Address)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_DHCPv6ServerPool_SourceAddressExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPool_SourceAddressExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ServerPool_IANAEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPool_IANAEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ServerPool_IANAManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPool_IANAManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, "8", NULL, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ServerPool_IANAPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ServerPool_IAPDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPool_IAPDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ServerPool_IAPDManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPool_IAPDManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, "8", NULL, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ServerPool_IAPDPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ServerPool_IAPDAddLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPool_IAPDAddLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, "64")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_DHCPv6ServerPool_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res, *res1, *jobj, *dev_obj = NULL, *next_obj = NULL; - char *device; - int i = 0; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcpv6_args *)data)->dhcp_sec), String}}, 1, &res1); - DM_ASSERT(res1, *value = "0"); - device = dmjson_get_value(res1, 1, "device"); - dmubus_call("dhcp", "ipv6leases", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = "0"); - dev_obj = dmjson_get_obj(res, 1, "device"); - DM_ASSERT(dev_obj, *value = "0"); - next_obj = dmjson_get_obj(dev_obj, 1, device); - DM_ASSERT(next_obj, *value = "0"); - while (1) { - jobj = dmjson_select_obj_in_array_idx(next_obj, i, 1, "leases"); - if (jobj == NULL) - break; - i++; - } - dmasprintf(value, "%d", i); - return 0; -} - -int get_DHCPv6ServerPool_OptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *dhcp_options_list = NULL; - struct uci_element *e; - int i = 0; - - dmuci_get_value_by_section_list(((struct dhcpv6_args *)data)->dhcp_sec, "dhcp_option", &dhcp_options_list); - if (dhcp_options_list != NULL) { - uci_foreach_element(dhcp_options_list, e) { - i++; - } - } - dmasprintf(value, "%d", i); - return 0; -} - -int get_DHCPv6ServerPoolClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPoolClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - break; - case VALUESET: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - //TODO - break; - } - return 0; -} - -int get_DHCPv6ServerPoolClient_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ServerPoolClient_Active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ServerPoolClient_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *address_obj = NULL; - int i = 0; - - while (1) { - address_obj = dmjson_select_obj_in_array_idx(((struct clientv6_args *)data)->client, i, 1, "ipv6-addr"); - if (address_obj == NULL) - break; - i++; - } - dmasprintf(value, "%d", i); - return 0; -} - -int get_DHCPv6ServerPoolClient_IPv6PrefixNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *address_obj = NULL; - int i= 0; - - while (1) { - address_obj = dmjson_select_obj_in_array_idx(((struct clientv6_args *)data)->client, i, 1, "ipv6-prefix"); - if (address_obj == NULL) - break; - i++; - } - dmasprintf(value, "%d", i); - return 0; -} - -int get_DHCPv6ServerPoolClient_OptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ServerPoolClientIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "address"); - return 0; -} - -int get_DHCPv6ServerPoolClientIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "preferred-lifetime"); - return 0; -} - -int get_DHCPv6ServerPoolClientIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "valid-lifetime"); - return 0; -} - -int get_DHCPv6ServerPoolClientIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "address"); - return 0; -} - -int get_DHCPv6ServerPoolClientIPv6Prefix_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "preferred-lifetime"); - return 0; -} - -int get_DHCPv6ServerPoolClientIPv6Prefix_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "valid-lifetime"); - return 0; -} - -int get_DHCPv6ServerPoolClientOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ServerPoolClientOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *dhcp_option_list; - struct uci_element *e; - char **buf; - size_t length; - - if(strcmp(((struct dhcpv6_client_option_args *)data)->option_tag, "0") == 0){ - *value= "0"; - return 0; - } - - dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - if (dhcp_option_list != NULL) { - uci_foreach_element(dhcp_option_list, e) { - buf = strsplit(e->name, ",", &length); - if (strcmp(buf[0], ((struct dhcpv6_client_option_args *)data)->option_tag) == 0) { - *value= "1"; - return 0; - } - } - } - - *value= "0"; - return 0; -} - -int set_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_list *dhcp_option_list; - struct uci_element *e; - char **buf, *opt_value; - size_t length; - bool test = false, b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - - if (strcmp(((struct dhcpv6_client_option_args *)data)->option_tag, "0") == 0) - return 0; - - dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - dmasprintf(&opt_value, "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, ((struct dhcpv6_client_option_args *)data)->value); - - if (dhcp_option_list != NULL) { - uci_foreach_element(dhcp_option_list, e) { - buf = strsplit(e->name, ",", &length); - if (strcmp(buf[0], ((struct dhcpv6_client_option_args *)data)->option_tag) == 0) { - test = true; - if (!b) - dmuci_del_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", opt_value); - break; - } - } - } - if (!test && b) - dmuci_add_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", opt_value); - } - return 0; -} - -int get_DHCPv6ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dhcpv6_client_option_args *)data)->opt_sect, "bbf_dhcpv6_servpool_option_alias", value); - return 0; - -} - -int set_DHCPv6ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcpv6_client_option_args *)data)->opt_sect, "bbf_dhcpv6_servpool_option_alias", value); - break; - } - return 0; -} - -int get_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(((struct dhcpv6_client_option_args *)data)->option_tag); - return 0; -} - -int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *opttagvalue, **option, *oldopttagvalue; - size_t length; - struct uci_list *dhcp_option_list= NULL; - struct uci_element *e; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "0", "65535")) - return FAULT_9007; - - dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - - if (dhcp_option_list == NULL) - return 0; - - uci_foreach_element(dhcp_option_list, e) { - option = strsplit(e->name, ",", &length); - if (strcmp(option[0], value)==0) - return FAULT_9007; - } - break; - case VALUESET: - dmasprintf(&oldopttagvalue, "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, ((struct dhcpv6_client_option_args *)data)->value); - dmasprintf(&opttagvalue, "%s,%s", value, ((struct dhcpv6_client_option_args *)data)->value); - dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - dmuci_del_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", oldopttagvalue); - dmuci_add_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", opttagvalue); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcpv6_client_option_args *)data)->opt_sect, "option_tag", value); - break; - } - return 0; -} - -int get_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value= dmstrdup(((struct dhcpv6_client_option_args *)data)->value); - return 0; -} - -int set_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *opttagvalue, **option, *oldopttagvalue; - size_t length; - struct uci_list *dhcp_option_list = NULL; - struct uci_element *e; - - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, "0", "65535")) - return FAULT_9007; - - dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - if (dhcp_option_list == NULL) - return 0; - - uci_foreach_element(dhcp_option_list, e) { - option = strsplit(e->name, ",", &length); - if (strcmp(option[0], value) == 0) - return FAULT_9007; - } - break; - case VALUESET: - dmasprintf(&oldopttagvalue, "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, ((struct dhcpv6_client_option_args *)data)->value); - dmasprintf(&opttagvalue, "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, value); - dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_option_list); - dmuci_del_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", oldopttagvalue); - dmuci_add_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", opttagvalue); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ((struct dhcpv6_client_option_args *)data)->opt_sect, "option_value", value); - break; - } - return 0; -} - -int get_DHCPv6ServerPoolOption_PassthroughClient(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_DHCPv6ServerPoolOption_PassthroughClient(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - diff --git a/dmtree/tr181/dhcpv6.h b/dmtree/tr181/dhcpv6.h index 13511a7c..8b65d8c3 100644 --- a/dmtree/tr181/dhcpv6.h +++ b/dmtree/tr181/dhcpv6.h @@ -31,163 +31,5 @@ extern DMLEAF tDHCPv6ServerPoolClientIPv6PrefixParams[]; extern DMLEAF tDHCPv6ServerPoolClientOptionParams[]; extern DMLEAF tDHCPv6ServerPoolOptionParams[]; -struct dhcpv6_client_args -{ - struct uci_section *dhcp_client_conf; - struct uci_section *dhcp_client_dm; - char *ip; -}; - -struct dhcpv6_args -{ - struct uci_section *dhcp_sec; - char *interface; -}; - -struct clientv6_args -{ - json_object *client; - json_object *clientparam; - int idx; -}; - -struct dhcpv6_client_option_args { - struct uci_section *opt_sect; - struct uci_section *client_sect; - char *option_tag; - char *value; -}; - -int browseDHCPv6ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv6ClientServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv6ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv6ClientReceivedOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv6ServerPoolClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv6ServerPoolClientIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv6ServerPoolClientIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDHCPv6ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int addObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjDHCPv6ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjDHCPv6ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_DHCPv6_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6Client_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6Client_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6Client_RapidCommit(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6Client_RapidCommit(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6Client_SuggestedT1(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6Client_SuggestedT1(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6Client_SuggestedT2(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6Client_SuggestedT2(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6Client_SupportedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6Client_ServerNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6Client_SentOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6Client_ReceivedOptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ClientServer_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ClientServer_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ClientServer_InformationRefreshTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ClientReceivedOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ClientReceivedOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ClientReceivedOption_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6Server_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6Server_PoolNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_DUIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_DUIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_VendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_UserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_SourceAddressExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_SourceAddressExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_IANAEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_IANAEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_IANAManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_IANAManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_IANAPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPool_IAPDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_IAPDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_IAPDManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_IAPDManualPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_IAPDPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPool_IAPDAddLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPool_IAPDAddLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPool_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPool_OptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPoolClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPoolClient_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClient_Active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClient_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClient_IPv6PrefixNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClient_OptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClientIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClientIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClientIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClientIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClientIPv6Prefix_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClientIPv6Prefix_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClientOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolClientOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DHCPv6ServerPoolOption_PassthroughClient(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DHCPv6ServerPoolOption_PassthroughClient(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif //__DHCPV6_H diff --git a/dmtree/tr181/dns.c b/dmtree/tr181/dns.c index a3c3949a..db0d5ff1 100644 --- a/dmtree/tr181/dns.c +++ b/dmtree/tr181/dns.c @@ -11,118 +11,22 @@ #include "dmentry.h" #include "dns.h" -/* *** Device.DNS. *** */ -DMOBJ tDNSObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Client", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tDNSClientObj, tDNSClientParams, NULL, BBFDM_BOTH}, -{"Relay", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tDNSRelayObj, tDNSRelayParams, NULL, BBFDM_BOTH}, -{"Diagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tDNSDiagnosticsObj, NULL, NULL, BBFDM_BOTH}, -{0} + +struct NSLookupResult +{ + char *Status; + char *AnswerType; + char *HostNameReturned; + char *IPAddresses; + char *DNSServerIP; + char *ResponseTime; }; -DMLEAF tDNSParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"SupportedRecordTypes", &DMREAD, DMT_STRING, get_dns_supported_record_types, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.DNS.Client. *** */ -DMOBJ tDNSClientObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Server", &DMWRITE, add_client_server, delete_client_server, NULL, browseServerInst, NULL, NULL, NULL, NULL, tDNSClientServerParams, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF tDNSClientParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_client_enable, set_client_enable, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_client_status, NULL, NULL, NULL, BBFDM_BOTH}, -{"ServerNumberOfEntries", &DMREAD, DMT_UNINT, get_client_server_number_of_entries, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.DNS.Client.Server.{i}. *** */ -DMLEAF tDNSClientServerParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_server_enable, set_server_enable, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_server_status, NULL, NULL, NULL, BBFDM_BOTH}, -{"Alias", &DMWRITE, DMT_STRING, get_server_alias, set_server_alias, NULL, NULL, BBFDM_BOTH}, -{"DNSServer", &DMWRITE, DMT_STRING, get_server_dns_server, set_server_dns_server, NULL, NULL, BBFDM_BOTH}, -{"Interface", &DMWRITE, DMT_STRING, get_server_interface, set_server_interface, NULL, NULL, BBFDM_BOTH}, -{"Type", &DMREAD, DMT_STRING, get_server_type, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.DNS.Relay. *** */ -DMOBJ tDNSRelayObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Forwarding", &DMWRITE, add_relay_forwarding, delete_relay_forwarding, NULL, browseRelayForwardingInst, NULL, NULL, NULL, NULL, tDNSRelayForwardingParams, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF tDNSRelayParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_relay_enable, set_relay_enable, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_relay_status, NULL, NULL, NULL, BBFDM_BOTH}, -{"ForwardNumberOfEntries", &DMREAD, DMT_UNINT, get_relay_forward_number_of_entries, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.DNS.Relay.Forwarding.{i}. *** */ -DMLEAF tDNSRelayForwardingParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_forwarding_enable, set_forwarding_enable, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_forwarding_status, NULL, NULL, NULL, BBFDM_BOTH}, -{"Alias", &DMWRITE, DMT_STRING, get_forwarding_alias, set_forwarding_alias, NULL, NULL, BBFDM_BOTH}, -{"DNSServer", &DMWRITE, DMT_STRING, get_forwarding_dns_server, set_forwarding_dns_server, NULL, NULL, BBFDM_BOTH}, -{"Interface", &DMWRITE, DMT_STRING, get_forwarding_interface, set_forwarding_interface, NULL, NULL, BBFDM_BOTH}, -{"Type", &DMREAD, DMT_STRING, get_forwarding_type, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.DNS.Diagnostics. *** */ -DMOBJ tDNSDiagnosticsObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"NSLookupDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tDNSDiagnosticsNSLookupDiagnosticsObj, tDNSDiagnosticsNSLookupDiagnosticsParams, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.DNS.Diagnostics.NSLookupDiagnostics. *** */ -DMOBJ tDNSDiagnosticsNSLookupDiagnosticsObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Result", &DMREAD, NULL, NULL, NULL, browseResultInst, NULL, NULL, NULL, NULL, tDNSDiagnosticsNSLookupDiagnosticsResultParams, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF tDNSDiagnosticsNSLookupDiagnosticsParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"DiagnosticsState", &DMWRITE, DMT_STRING, get_nslookupdiagnostics_diagnostics_state, set_nslookupdiagnostics_diagnostics_state, NULL, NULL, BBFDM_BOTH}, -{"Interface", &DMWRITE, DMT_STRING, get_nslookupdiagnostics_interface, set_nslookupdiagnostics_interface, NULL, NULL, BBFDM_BOTH}, -{"HostName", &DMWRITE, DMT_STRING, get_nslookupdiagnostics_host_name, set_nslookupdiagnostics_host_name, NULL, NULL, BBFDM_BOTH}, -{"DNSServer", &DMWRITE, DMT_STRING, get_nslookupdiagnostics_d_n_s_server, set_nslookupdiagnostics_d_n_s_server, NULL, NULL, BBFDM_BOTH}, -{"Timeout", &DMWRITE, DMT_UNINT, get_nslookupdiagnostics_timeout, set_nslookupdiagnostics_timeout, NULL, NULL, BBFDM_BOTH}, -{"NumberOfRepetitions", &DMWRITE, DMT_UNINT, get_nslookupdiagnostics_number_of_repetitions, set_nslookupdiagnostics_number_of_repetitions, NULL, NULL, BBFDM_BOTH}, -{"SuccessCount", &DMREAD, DMT_UNINT, get_nslookupdiagnostics_success_count, NULL, NULL, NULL, BBFDM_BOTH}, -{"ResultNumberOfEntries", &DMREAD, DMT_UNINT, get_nslookupdiagnostics_result_number_of_entries, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.DNS.Diagnostics.NSLookupDiagnostics.Result.{i}. *** */ -DMLEAF tDNSDiagnosticsNSLookupDiagnosticsResultParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Status", &DMREAD, DMT_STRING, get_result_status, NULL, NULL, NULL, BBFDM_BOTH}, -{"AnswerType", &DMREAD, DMT_STRING, get_result_answer_type, NULL, NULL, NULL, BBFDM_BOTH}, -{"HostNameReturned", &DMREAD, DMT_STRING, get_result_host_name_returned, NULL, NULL, NULL, BBFDM_BOTH}, -{"IPAddresses", &DMREAD, DMT_STRING, get_result_i_p_addresses, NULL, NULL, NULL, BBFDM_BOTH}, -{"DNSServerIP", &DMREAD, DMT_STRING, get_result_d_n_s_server_i_p, NULL, NULL, NULL, BBFDM_BOTH}, -{"ResponseTime", &DMREAD, DMT_UNINT, get_result_response_time, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; /******************************** * init function ********************************/ -inline int init_nslookup_results(struct NSLookupResult *args, char *Status, char *AnswerType, char *HostNameReturned, char *IPAddresses, char *DNSServerIP, char *ResponseTime) +static inline int init_nslookup_results(struct NSLookupResult *args, char *Status, char *AnswerType, char *HostNameReturned, char *IPAddresses, char *DNSServerIP, char *ResponseTime) { args->Status = Status; args->AnswerType = AnswerType; @@ -233,7 +137,7 @@ static int dmmap_synchronizeDNSClientRelayServer(struct dmctx *dmctx, DMNODE *pa } /******************************** Browse Functions ****************************************/ -int browseServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s = NULL; char *instance, *instnbr = NULL; @@ -247,7 +151,7 @@ int browseServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, return 0; } -int browseRelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseRelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s = NULL; char *instance, *instnbr = NULL; @@ -262,7 +166,7 @@ int browseRelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *pr return 0; } -int browseResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s = NULL; char *instance, *idx_last = NULL; @@ -276,7 +180,7 @@ int browseResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, } /*********************************** Add/Delet Object functions *************************/ -int add_client_server(char *refparam, struct dmctx *ctx, void *data, char **instance) +static int add_client_server(char *refparam, struct dmctx *ctx, void *data, char **instance) { struct uci_section *s = NULL; char *v, *inst; @@ -292,7 +196,7 @@ int add_client_server(char *refparam, struct dmctx *ctx, void *data, char **inst return 0; } -int add_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char **instance) +static int add_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char **instance) { struct uci_section *s = NULL; char *v, *inst; @@ -308,7 +212,7 @@ int add_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char **i return 0; } -int delete_client_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +static int delete_client_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL, *ss = NULL, *stmp = NULL; char *interface, *ip, *str; @@ -345,7 +249,7 @@ int delete_client_server(char *refparam, struct dmctx *ctx, void *data, char *in return 0; } -int delete_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +static int delete_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL, *ss = NULL, *stmp = NULL; char *interface, *ip, *str; @@ -383,25 +287,25 @@ int delete_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char } /***************************************** Get/Set Parameter functions ***********************/ -int get_dns_supported_record_types(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_dns_supported_record_types(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "A,AAAA,PTR"; return 0; } -int get_client_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_client_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "1"; return 0; } -int get_client_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_client_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "Enabled"; return 0; } -int get_client_server_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_client_server_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; int cnt = 0; @@ -414,13 +318,13 @@ int get_client_server_number_of_entries(char *refparam, struct dmctx *ctx, void return 0; } -int get_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "enable", value); return 0; } -int get_server_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_server_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *v; @@ -429,19 +333,19 @@ int get_server_status(char *refparam, struct dmctx *ctx, void *data, char *insta return 0; } -int get_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "dns_server_alias", value); return 0; } -int get_server_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_server_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "ip", value); return 0; } -int get_server_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_server_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker; @@ -452,7 +356,7 @@ int get_server_interface(char *refparam, struct dmctx *ctx, void *data, char *in return 0; } -int get_server_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_server_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *v; *value = "Static"; @@ -467,7 +371,7 @@ int get_server_type(char *refparam, struct dmctx *ctx, void *data, char *instanc return 0; } -int get_relay_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_relay_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *path = "/etc/rc.d/*dnsmasq"; if (check_file(path)) @@ -477,7 +381,7 @@ int get_relay_enable(char *refparam, struct dmctx *ctx, void *data, char *instan return 0; } -int get_relay_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_relay_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *path = "/etc/rc.d/*dnsmasq"; if (check_file(path)) @@ -487,7 +391,7 @@ int get_relay_status(char *refparam, struct dmctx *ctx, void *data, char *instan return 0; } -int get_relay_forward_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_relay_forward_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; int cnt = 0; @@ -500,13 +404,13 @@ int get_relay_forward_number_of_entries(char *refparam, struct dmctx *ctx, void return 0; } -int get_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "enable", value); return 0; } -int get_forwarding_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_forwarding_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *v; @@ -515,19 +419,19 @@ int get_forwarding_status(char *refparam, struct dmctx *ctx, void *data, char *i return 0; } -int get_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "dns_server_alias", value); return 0; } -int get_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "ip", value); return 0; } -int get_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker; @@ -538,7 +442,7 @@ int get_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int get_forwarding_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_forwarding_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *v; *value = "Static"; @@ -553,49 +457,49 @@ int get_forwarding_type(char *refparam, struct dmctx *ctx, void *data, char *ins return 0; } -int get_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = nslookup_get("DiagnosticState", "None"); return 0; } -int get_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@nslookupdiagnostic[0]", "interface", value); return 0; } -int get_nslookupdiagnostics_host_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_nslookupdiagnostics_host_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@nslookupdiagnostic[0]", "HostName", value); return 0; } -int get_nslookupdiagnostics_d_n_s_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_nslookupdiagnostics_d_n_s_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@nslookupdiagnostic[0]", "DNSServer", value); return 0; } -int get_nslookupdiagnostics_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_nslookupdiagnostics_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = nslookup_get("Timeout", "5000"); return 0; } -int get_nslookupdiagnostics_number_of_repetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_nslookupdiagnostics_number_of_repetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = nslookup_get("NumberOfRepetitions", "1"); return 0; } -int get_nslookupdiagnostics_success_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_nslookupdiagnostics_success_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = nslookup_get("SuccessCount", "0"); return 0; } -int get_nslookupdiagnostics_result_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_nslookupdiagnostics_result_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; int cnt = 0; @@ -607,43 +511,43 @@ int get_nslookupdiagnostics_result_number_of_entries(char *refparam, struct dmct return 0; } -int get_result_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_result_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "Status", value); return 0; } -int get_result_answer_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_result_answer_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "AnswerType", value); return 0; } -int get_result_host_name_returned(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_result_host_name_returned(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "HostNameReturned", value); return 0; } -int get_result_i_p_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_result_i_p_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "IPAddresses", value); return 0; } -int get_result_d_n_s_server_i_p(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_result_d_n_s_server_i_p(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "DNSServerIP", value); return 0; } -int get_result_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_result_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "ResponseTime", value); return 0; } -int set_client_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_client_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -656,7 +560,7 @@ int set_client_enable(char *refparam, struct dmctx *ctx, void *data, char *insta return 0; } -int set_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *str, *ip, *interface; bool b, ob; @@ -687,7 +591,7 @@ int set_server_enable(char *refparam, struct dmctx *ctx, void *data, char *insta return 0; } -int set_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -701,7 +605,7 @@ int set_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instan return 0; } -int set_server_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_server_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *str, *oip, *interface; struct uci_list *v; @@ -746,7 +650,7 @@ int set_server_dns_server(char *refparam, struct dmctx *ctx, void *data, char *i return 0; } -int set_server_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_server_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *str, *ointerface, *ip, *interface; @@ -774,7 +678,7 @@ int set_server_interface(char *refparam, struct dmctx *ctx, void *data, char *in return 0; } -int set_relay_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_relay_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -791,7 +695,7 @@ int set_relay_enable(char *refparam, struct dmctx *ctx, void *data, char *instan return 0; } -int set_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *str, *ip, *interface; bool b, ob; @@ -822,7 +726,7 @@ int set_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *i return 0; } -int set_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -836,7 +740,7 @@ int set_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *in return 0; } -int set_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *str, *oip, *interface; struct uci_list *v; @@ -881,7 +785,7 @@ int set_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *data, cha return 0; } -int set_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *str, *ointerface, *ip, *interface; @@ -909,7 +813,7 @@ int set_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int set_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -933,7 +837,7 @@ int set_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, return 0; } -int set_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -954,7 +858,7 @@ int set_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx, void *d return 0; } -int set_nslookupdiagnostics_host_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_nslookupdiagnostics_host_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -975,7 +879,7 @@ int set_nslookupdiagnostics_host_name(char *refparam, struct dmctx *ctx, void *d return 0; } -int set_nslookupdiagnostics_d_n_s_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_nslookupdiagnostics_d_n_s_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -996,7 +900,7 @@ int set_nslookupdiagnostics_d_n_s_server(char *refparam, struct dmctx *ctx, void return 0; } -int set_nslookupdiagnostics_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_nslookupdiagnostics_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -1017,7 +921,7 @@ int set_nslookupdiagnostics_timeout(char *refparam, struct dmctx *ctx, void *dat return 0; } -int set_nslookupdiagnostics_number_of_repetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_nslookupdiagnostics_number_of_repetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -1038,4 +942,110 @@ int set_nslookupdiagnostics_number_of_repetitions(char *refparam, struct dmctx * return 0; } +/* *** Device.DNS. *** */ +DMOBJ tDNSObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Client", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tDNSClientObj, tDNSClientParams, NULL, BBFDM_BOTH}, +{"Relay", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tDNSRelayObj, tDNSRelayParams, NULL, BBFDM_BOTH}, +{"Diagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tDNSDiagnosticsObj, NULL, NULL, BBFDM_BOTH}, +{0} +}; +DMLEAF tDNSParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"SupportedRecordTypes", &DMREAD, DMT_STRING, get_dns_supported_record_types, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.DNS.Client. *** */ +DMOBJ tDNSClientObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Server", &DMWRITE, add_client_server, delete_client_server, NULL, browseServerInst, NULL, NULL, NULL, NULL, tDNSClientServerParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tDNSClientParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_client_enable, set_client_enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_client_status, NULL, NULL, NULL, BBFDM_BOTH}, +{"ServerNumberOfEntries", &DMREAD, DMT_UNINT, get_client_server_number_of_entries, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.DNS.Client.Server.{i}. *** */ +DMLEAF tDNSClientServerParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_server_enable, set_server_enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_server_status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Alias", &DMWRITE, DMT_STRING, get_server_alias, set_server_alias, NULL, NULL, BBFDM_BOTH}, +{"DNSServer", &DMWRITE, DMT_STRING, get_server_dns_server, set_server_dns_server, NULL, NULL, BBFDM_BOTH}, +{"Interface", &DMWRITE, DMT_STRING, get_server_interface, set_server_interface, NULL, NULL, BBFDM_BOTH}, +{"Type", &DMREAD, DMT_STRING, get_server_type, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.DNS.Relay. *** */ +DMOBJ tDNSRelayObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Forwarding", &DMWRITE, add_relay_forwarding, delete_relay_forwarding, NULL, browseRelayForwardingInst, NULL, NULL, NULL, NULL, tDNSRelayForwardingParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tDNSRelayParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_relay_enable, set_relay_enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_relay_status, NULL, NULL, NULL, BBFDM_BOTH}, +{"ForwardNumberOfEntries", &DMREAD, DMT_UNINT, get_relay_forward_number_of_entries, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.DNS.Relay.Forwarding.{i}. *** */ +DMLEAF tDNSRelayForwardingParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_forwarding_enable, set_forwarding_enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_forwarding_status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Alias", &DMWRITE, DMT_STRING, get_forwarding_alias, set_forwarding_alias, NULL, NULL, BBFDM_BOTH}, +{"DNSServer", &DMWRITE, DMT_STRING, get_forwarding_dns_server, set_forwarding_dns_server, NULL, NULL, BBFDM_BOTH}, +{"Interface", &DMWRITE, DMT_STRING, get_forwarding_interface, set_forwarding_interface, NULL, NULL, BBFDM_BOTH}, +{"Type", &DMREAD, DMT_STRING, get_forwarding_type, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.DNS.Diagnostics. *** */ +DMOBJ tDNSDiagnosticsObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"NSLookupDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tDNSDiagnosticsNSLookupDiagnosticsObj, tDNSDiagnosticsNSLookupDiagnosticsParams, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.DNS.Diagnostics.NSLookupDiagnostics. *** */ +DMOBJ tDNSDiagnosticsNSLookupDiagnosticsObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Result", &DMREAD, NULL, NULL, NULL, browseResultInst, NULL, NULL, NULL, NULL, tDNSDiagnosticsNSLookupDiagnosticsResultParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tDNSDiagnosticsNSLookupDiagnosticsParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"DiagnosticsState", &DMWRITE, DMT_STRING, get_nslookupdiagnostics_diagnostics_state, set_nslookupdiagnostics_diagnostics_state, NULL, NULL, BBFDM_BOTH}, +{"Interface", &DMWRITE, DMT_STRING, get_nslookupdiagnostics_interface, set_nslookupdiagnostics_interface, NULL, NULL, BBFDM_BOTH}, +{"HostName", &DMWRITE, DMT_STRING, get_nslookupdiagnostics_host_name, set_nslookupdiagnostics_host_name, NULL, NULL, BBFDM_BOTH}, +{"DNSServer", &DMWRITE, DMT_STRING, get_nslookupdiagnostics_d_n_s_server, set_nslookupdiagnostics_d_n_s_server, NULL, NULL, BBFDM_BOTH}, +{"Timeout", &DMWRITE, DMT_UNINT, get_nslookupdiagnostics_timeout, set_nslookupdiagnostics_timeout, NULL, NULL, BBFDM_BOTH}, +{"NumberOfRepetitions", &DMWRITE, DMT_UNINT, get_nslookupdiagnostics_number_of_repetitions, set_nslookupdiagnostics_number_of_repetitions, NULL, NULL, BBFDM_BOTH}, +{"SuccessCount", &DMREAD, DMT_UNINT, get_nslookupdiagnostics_success_count, NULL, NULL, NULL, BBFDM_BOTH}, +{"ResultNumberOfEntries", &DMREAD, DMT_UNINT, get_nslookupdiagnostics_result_number_of_entries, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.DNS.Diagnostics.NSLookupDiagnostics.Result.{i}. *** */ +DMLEAF tDNSDiagnosticsNSLookupDiagnosticsResultParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Status", &DMREAD, DMT_STRING, get_result_status, NULL, NULL, NULL, BBFDM_BOTH}, +{"AnswerType", &DMREAD, DMT_STRING, get_result_answer_type, NULL, NULL, NULL, BBFDM_BOTH}, +{"HostNameReturned", &DMREAD, DMT_STRING, get_result_host_name_returned, NULL, NULL, NULL, BBFDM_BOTH}, +{"IPAddresses", &DMREAD, DMT_STRING, get_result_i_p_addresses, NULL, NULL, NULL, BBFDM_BOTH}, +{"DNSServerIP", &DMREAD, DMT_STRING, get_result_d_n_s_server_i_p, NULL, NULL, NULL, BBFDM_BOTH}, +{"ResponseTime", &DMREAD, DMT_UNINT, get_result_response_time, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/dns.h b/dmtree/tr181/dns.h index dde7ba14..e118e8a4 100644 --- a/dmtree/tr181/dns.h +++ b/dmtree/tr181/dns.h @@ -26,75 +26,4 @@ extern DMLEAF tDNSDiagnosticsNSLookupDiagnosticsParams[]; extern DMOBJ tDNSDiagnosticsNSLookupDiagnosticsObj[]; extern DMLEAF tDNSDiagnosticsNSLookupDiagnosticsResultParams[]; -struct NSLookupResult -{ - char *Status; - char *AnswerType; - char *HostNameReturned; - char *IPAddresses; - char *DNSServerIP; - char *ResponseTime; -}; - -int browseServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseRelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int add_client_server(char *refparam, struct dmctx *ctx, void *data, char **instance); -int add_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char **instance); - -int delete_client_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int delete_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_dns_supported_record_types(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_client_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_client_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_client_server_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_server_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_server_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_server_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_server_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_relay_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_relay_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_relay_forward_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_forwarding_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_forwarding_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nslookupdiagnostics_host_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nslookupdiagnostics_d_n_s_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nslookupdiagnostics_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nslookupdiagnostics_number_of_repetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nslookupdiagnostics_success_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nslookupdiagnostics_result_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_result_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_result_answer_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_result_host_name_returned(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_result_i_p_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_result_d_n_s_server_i_p(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_result_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_client_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_server_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_server_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_relay_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_nslookupdiagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_nslookupdiagnostics_host_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_nslookupdiagnostics_d_n_s_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_nslookupdiagnostics_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_nslookupdiagnostics_number_of_repetitions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/dsl.c b/dmtree/tr181/dsl.c index 4f4bede4..0fce81b2 100644 --- a/dmtree/tr181/dsl.c +++ b/dmtree/tr181/dsl.c @@ -11,6 +11,1310 @@ #include "dmentry.h" #include "dsl.h" + +struct dsl_line_args +{ + struct uci_section *line_sec; + char *id; +}; + +struct dsl_channel_args +{ + struct uci_section *channel_sec; + char *id; +}; + +/************************************************************************** +* LINKER +***************************************************************************/ +static int get_dsl_line_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct dsl_line_args *)data)->id) { + dmasprintf(linker, "line_%s", ((struct dsl_line_args *)data)->id); + return 0; + } + *linker = "" ; + return 0; +} + +static int get_dsl_channel_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct dsl_line_args *)data)->id){ + dmasprintf(linker, "channel_%s", ((struct dsl_line_args *)data)->id); + return 0; + } + *linker = "" ; + return 0; +} + +/************************************************************************** +* INIT +***************************************************************************/ +static inline int init_dsl_line(struct dsl_line_args *args, struct uci_section *s) +{ + args->line_sec = s; + return 0; +} + +static inline int init_dsl_channel(struct dsl_channel_args *args, struct uci_section *s) +{ + args->channel_sec = s; + return 0; +} + +/*************************************************************/ +static struct uci_section *update_create_dmmap_dsl_line(char *curr_id) +{ + struct uci_section *s = NULL; + char *name, *instance; + + uci_path_foreach_option_eq(bbfdm, "dmmap", "dsl_line", "id", curr_id, s) { + return s; + } + if (!s) { + dmasprintf(&instance, "%d", atoi(curr_id)+1); + DMUCI_ADD_SECTION(bbfdm, "dmmap", "dsl_line", &s, &name); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "id", curr_id); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "dsl_line_instance", instance); + dmfree(instance); + } + return s; +} + +static struct uci_section *update_create_dmmap_dsl_channel(char *curr_id) +{ + struct uci_section *s = NULL; + char *name, *instance; + + uci_path_foreach_option_eq(bbfdm, "dmmap", "dsl_channel", "id", curr_id, s) { + return s; + } + if (!s) { + dmasprintf(&instance, "%d", atoi(curr_id)+1); + DMUCI_ADD_SECTION(bbfdm, "dmmap", "dsl_channel", &s, &name); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "id", curr_id); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "dsl_channel_instance", instance); + dmfree(instance); + } + return s; +} +/************************************************************* +* ENTRY METHOD +*************************************************************/ +static int browseDSLLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *line_obj = NULL; + struct dsl_line_args cur_dsl_line_args = {0}; + struct uci_section *s = NULL; + char *dsl_int = NULL, *dsl_int_last = NULL; + int entries = 0; + + dmubus_call("dsl", "status", UBUS_ARGS{}, 0, &res); + while (res) { + line_obj = dmjson_select_obj_in_array_idx(res, entries, 1, "line"); + if(line_obj) { + cur_dsl_line_args.id = dmjson_get_value(line_obj, 1, "id"); + entries++; + s = update_create_dmmap_dsl_line(cur_dsl_line_args.id); + init_dsl_line(&cur_dsl_line_args, s); + dsl_int = handle_update_instance(1, dmctx, &dsl_int_last, update_instance_alias, 3, s, "dsl_line_instance", "dsl_line_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_dsl_line_args, dsl_int) == DM_STOP) + break; + } + else + break; + } + return 0; +} + +static int browseDSLChannelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *line_obj = NULL, *channel_obj = NULL; + struct dsl_channel_args cur_dsl_channel_args = {0}; + struct uci_section *s = NULL; + char *dsl_int = NULL, *dsl_int_last = NULL; + int entries_line = 0, entries_channel = 0; + + dmubus_call("dsl", "status", UBUS_ARGS{}, 0, &res); + while (res) { + line_obj = dmjson_select_obj_in_array_idx(res, entries_line, 1, "line"); + while (line_obj) { + channel_obj = dmjson_select_obj_in_array_idx(line_obj, entries_channel, 1, "channel"); + if(channel_obj) { + cur_dsl_channel_args.id = dmjson_get_value(channel_obj, 1, "id"); + entries_channel++; + s = update_create_dmmap_dsl_channel(cur_dsl_channel_args.id); + init_dsl_channel(&cur_dsl_channel_args, s); + dsl_int = handle_update_instance(1, dmctx, &dsl_int_last, update_instance_alias, 3, s, "dsl_channel_instance", "dsl_channel_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_dsl_channel_args, dsl_int) == DM_STOP) + break; + } + else + break; + } + entries_line++; + if(!line_obj) + break; + } + return 0; +} + +/************************************************************************** +* COMMON FUNCTIONS +***************************************************************************/ +static char *get_dsl_value_without_argument(char *command1, char *id, char *command2, char *key) +{ + json_object *res; + char command[16], *value = "0"; + + snprintf(command, sizeof(command), "%s.%s", command1, id); + dmubus_call(command, command2, UBUS_ARGS{}, 0, &res); + if (!res) return ""; + value = dmjson_get_value(res, 1, key); + return value; +} + +static char *get_dsl_value_without_argument_and_with_two_key(char *command1, char *id, char *command2, char *key1, char *key2) +{ + json_object *res; + char command[16], *value = "0"; + + snprintf(command, sizeof(command), "%s.%s", command1, id); + dmubus_call(command, command2, UBUS_ARGS{}, 0, &res); + if (!res) return ""; + value = dmjson_get_value(res, 2, key1, key2); + return value; +} + +static char *get_dsl_value_with_argument(char *command1, char *id, char *command2, char *argument, char *key) +{ + json_object *res; + char command[16], *value = "0"; + + snprintf(command, sizeof(command), "%s.%s", command1, id); + dmubus_call(command, command2, UBUS_ARGS{{"interval", argument, String}}, 1, &res); + if (!res) return ""; + value = dmjson_get_value(res, 1, key); + return value; +} + +static char *get_dsl_value_array_without_argument(char *command1, char *id, char *command2, char *key) +{ + json_object *res; + char command[16], *value= "0"; + + snprintf(command, sizeof(command), "%s.%s", command1, id); + dmubus_call(command, command2, UBUS_ARGS{}, 0, &res); + if (!res) return ""; + value = dmjson_get_value_array_all(res, DELIMITOR, 1, key); + return value; +} + +/************************************************************************** +* GET & SET DSL PARAMETERS +***************************************************************************/ +static int get_DSL_LineNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_path_foreach_sections(bbfdm, "dmmap", "dsl_line", s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +static int get_DSL_ChannelNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_path_foreach_sections(bbfdm, "dmmap", "dsl_channel", s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +/*#Device.DSL.Line.{i}.Enable!UBUS:dsl.line.0/status//status*/ +static int get_DSLLine_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *status = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "status"); + *value = (strcmp(status, "up") == 0) ? "1" : "0"; + return 0; +} + +static int set_DSLLine_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +/*#Device.DSL.Line.{i}.Status!UBUS:dsl.line.0/status//status*/ +static int get_DSLLine_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *status = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "status"); + *value = (strcmp(status, "up") == 0) ? "Up" : "Down"; + return 0; +} + +static int get_DSLLine_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dsl_line_args *)data)->line_sec, "dsl_line_alias", value); + return 0; +} + +static int set_DSLLine_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct dsl_line_args *)data)->line_sec, "dsl_line_alias", value); + break; + } + return 0; +} + +static int get_DSLLine_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct dsl_line_args*)data)->id; + return 0; +} + +static int get_DSLLine_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ""; + return 0; +} + +static int set_DSLLine_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +/*#Device.DSL.Line.{i}.Upstream!UBUS:dsl.line.0/status//upstream*/ +static int get_DSLLine_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "upstream"); + return 0; +} + +/*#Device.DSL.Line.{i}.FirmwareVersion!UBUS:dsl.line.0/status//firmware_version*/ +static int get_DSLLine_FirmwareVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "firmware_version"); + return 0; +} + +/*#Device.DSL.Line.{i}.LinkStatus!UBUS:dsl.line.0/status//link_status*/ +static int get_DSLLine_LinkStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *link_status = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "link_status"); + if(strcmp(link_status, "up") == 0) + *value = "Up"; + else if(strcmp(link_status, "initializing") == 0) + *value = "Initializing"; + else if(strcmp(link_status, "no_signal") == 0) + *value = "NoSignal"; + else if(strcmp(link_status, "disabled") == 0) + *value = "Disabled"; + else if(strcmp(link_status, "establishing") == 0) + *value = "EstablishingLink"; + else if(strcmp(link_status, "error") == 0) + *value = "Error"; + else + *value = link_status; + return 0; +} + +static char *get_dsl_standard(char *str) +{ + char *dsl_standard; + + if(strcmp(str, "gdmt_annexa") == 0) + dsl_standard = "G.992.1_Annex_A"; + else if(strcmp(str, "gdmt_annexb") == 0) + dsl_standard = "G.992.1_Annex_B"; + else if(strcmp(str, "gdmt_annexc") == 0) + dsl_standard = "G.992.1_Annex_C"; + else if(strcmp(str, "t1413") == 0) + dsl_standard = "T1.413"; + else if(strcmp(str, "t1413_i2") == 0) + dsl_standard = "T1.413i2"; + else if(strcmp(str, "glite") == 0) + dsl_standard = "G.992.2"; + else if(strcmp(str, "etsi_101_388") == 0) + dsl_standard = "ETSI_101_388"; + else if(strcmp(str, "adsl2_annexa") == 0) + dsl_standard = "G.992.3_Annex_A"; + else if(strcmp(str, "adsl2_annexb") == 0) + dsl_standard = "G.992.3_Annex_B"; + else if(strcmp(str, "adsl2_annexc") == 0) + dsl_standard = "G.992.3_Annex_C"; + else if(strcmp(str, "adsl2_annexi") == 0) + dsl_standard = "G.992.3_Annex_I"; + else if(strcmp(str, "adsl2_annexj") == 0) + dsl_standard = "G.992.3_Annex_J"; + else if(strcmp(str, "adsl2_annexl") == 0) + dsl_standard = "G.992.3_Annex_L"; + else if(strcmp(str, "adsl2_annexm") == 0) + dsl_standard = "G.992.3_Annex_M"; + else if(strcmp(str, "splitterless_adsl2") == 0) + dsl_standard = "G.992.4"; + else if(strcmp(str, "adsl2p_annexa") == 0) + dsl_standard = "G.992.5_Annex_A"; + else if(strcmp(str, "adsl2p_annexb") == 0) + dsl_standard = "G.992.5_Annex_B"; + else if(strcmp(str, "adsl2p_annexc") == 0) + dsl_standard = "G.992.5_Annex_C"; + else if(strcmp(str, "adsl2p_annexi") == 0) + dsl_standard = "G.992.5_Annex_I"; + else if(strcmp(str, "adsl2p_annexj") == 0) + dsl_standard = "G.992.5_Annex_J"; + else if(strcmp(str, "adsl2p_annexm") == 0) + dsl_standard = "G.992.5_Annex_M"; + else if(strcmp(str, "vdsl") == 0) + dsl_standard = "G.993.1"; + else if(strcmp(str, "vdsl2_annexa") == 0) + dsl_standard = "G.993.2_Annex_A"; + else if(strcmp(str, "vdsl2_annexb") == 0) + dsl_standard = "G.993.2_Annex_B"; + else if(strcmp(str, "vdsl2_annexc") == 0) + dsl_standard = "G.993.2_Annex_C"; + else + dsl_standard = str; + + return dsl_standard; +} + +/*#Device.DSL.Line.{i}.StandardsSupported!UBUS:dsl.line.0/status//standards_supported*/ +static int get_DSLLine_StandardsSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *standards_supported,*pch, *spch, *tmp, *tmpPtr, *str = ""; + + *value = ""; + standards_supported = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "standards_supported"); + if(standards_supported[0] == '\0') + return 0; + for (pch = strtok_r(standards_supported, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) + { + tmp = get_dsl_standard(pch); + if(*str == '\0') + dmasprintf(&str, "%s", tmp); + else { + tmpPtr = str; + dmasprintf(&str, "%s,%s", tmpPtr, tmp); + } + } + *value = str; + return 0; +} + +/*#Device.DSL.Line.{i}.XTSE!UBUS:dsl.line.0/status//xtse*/ +static int get_DSLLine_XTSE(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *xtse,*pch, *spch, *tmpPtr, *str = ""; + + *value = ""; + xtse = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtse"); + if(xtse[0] == '\0') + return 0; + for (pch = strtok_r(xtse, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) + { + if(*str == '\0') + dmasprintf(&str, "%s", pch); + else { + tmpPtr = str; + dmasprintf(&str, "%s%s", tmpPtr, pch); + } + } + *value = str; + return 0; +} + +/*#Device.DSL.Line.{i}.StandardUsed!UBUS:dsl.line.0/status//standard_used*/ +static int get_DSLLine_StandardUsed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *standard_used = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "standard_used"); + *value = get_dsl_standard(standard_used); + return 0; +} + +/*#Device.DSL.Line.{i}.XTSUsed!UBUS:dsl.line.0/status//xtse_used*/ +static int get_DSLLine_XTSUsed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *xtse_used,*pch, *spch, *tmpPtr, *str = ""; + + *value = ""; + xtse_used = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtse_used"); + if(xtse_used[0] == '\0') + return 0; + for (pch = strtok_r(xtse_used, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) + { + if(*str == '\0') + dmasprintf(&str, "%s", pch); + else { + tmpPtr = str; + dmasprintf(&str, "%s%s", tmpPtr, pch); + } + } + *value = str; + return 0; +} + +/*#Device.DSL.Line.{i}.LineEncoding!UBUS:dsl.line.0/status//line_encoding*/ +static int get_DSLLine_LineEncoding(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *line_encoding = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "line_encoding"); + if(strcmp(line_encoding, "dmt") == 0) + *value = "DMT"; + else if(strcmp(line_encoding, "cap") == 0) + *value = "CAP"; + else if(strcmp(line_encoding, "2b1q") == 0) + *value = "2B1Q"; + else if(strcmp(line_encoding, "43bt") == 0) + *value = "43BT"; + else if(strcmp(line_encoding, "pam") == 0) + *value = "PAM"; + else if(strcmp(line_encoding, "qam") == 0) + *value = "QAM"; + else + *value = line_encoding; + return 0; +} + +/*#Device.DSL.Line.{i}.AllowedProfiles!UBUS:dsl.line.0/status//allowed_profiles*/ +static int get_DSLLine_AllowedProfiles(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "allowed_profiles"); + return 0; +} + +/*#Device.DSL.Line.{i}.CurrentProfile!UBUS:dsl.line.0/status//current_profile*/ +static int get_DSLLine_CurrentProfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "current_profile"); + return 0; +} + +/*#Device.DSL.Line.{i}.PowerManagementState!UBUS:dsl.line.0/status//power_management_state*/ +static int get_DSLLine_PowerManagementState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *power_management_state = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "power_management_state"); + if(strcmp(power_management_state, "l0") == 0) + *value = "L0"; + else if(strcmp(power_management_state, "l1") == 0) + *value = "L1"; + else if(strcmp(power_management_state, "l2") == 0) + *value = "L2"; + else if(strcmp(power_management_state, "l3") == 0) + *value = "L3"; + else if(strcmp(power_management_state, "l4") == 0) + *value = "L4"; + else + *value = power_management_state; + return 0; +} + +/*#Device.DSL.Line.{i}.SuccessFailureCause!UBUS:dsl.line.0/status//success_failure_cause*/ +static int get_DSLLine_SuccessFailureCause(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "success_failure_cause"); + return 0; +} + +/*#Device.DSL.Line.{i}.UPBOKLERPb!UBUS:dsl.line.0/status//upbokler_pb*/ +static int get_DSLLine_UPBOKLERPb(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "upbokler_pb"); + return 0; +} + +/*#Device.DSL.Line.{i}.RXTHRSHds!UBUS:dsl.line.0/status//rxthrsh_ds*/ +static int get_DSLLine_RXTHRSHds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "rxthrsh_ds"); + return 0; +} + +/*#Device.DSL.Line.{i}.ACTRAMODEds!UBUS:dsl.line.0/status//act_ra_mode.ds*/ +static int get_DSLLine_ACTRAMODEds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "act_ra_mode", "ds"); + return 0; +} + +/*#Device.DSL.Line.{i}.ACTRAMODEus!UBUS:dsl.line.0/status//act_ra_mode.us*/ +static int get_DSLLine_ACTRAMODEus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "act_ra_mode", "us"); + return 0; +} + +/*#Device.DSL.Line.{i}.SNRMROCus!UBUS:dsl.line.0/status//snr_mroc_us*/ +static int get_DSLLine_SNRMROCus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "snr_mroc_us"); + return 0; +} + +/*#Device.DSL.Line.{i}.LastStateTransmittedDownstream!UBUS:dsl.line.0/status//last_state_transmitted.ds*/ +static int get_DSLLine_LastStateTransmittedDownstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "last_state_transmitted", "ds"); + return 0; +} + +/*#Device.DSL.Line.{i}.LastStateTransmittedUpstream!UBUS:dsl.line.0/status//last_state_transmitted.us*/ +static int get_DSLLine_LastStateTransmittedUpstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "last_state_transmitted", "us"); + return 0; +} + +/*#Device.DSL.Line.{i}.US0MASK!UBUS:dsl.line.0/status//us0_mask*/ +static int get_DSLLine_US0MASK(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "us0_mask"); + return 0; +} + +/*#Device.DSL.Line.{i}.TRELLISds!UBUS:dsl.line.0/status//trellis.ds*/ +static int get_DSLLine_TRELLISds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "trellis", "ds"); + return 0; +} + +/*#Device.DSL.Line.{i}.TRELLISus!UBUS:dsl.line.0/status//trellis.us*/ +static int get_DSLLine_TRELLISus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "trellis", "us"); + return 0; +} + +/*#Device.DSL.Line.{i}.ACTSNRMODEds!UBUS:dsl.line.0/status//act_snr_mode.ds*/ +static int get_DSLLine_ACTSNRMODEds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "act_snr_mode", "ds"); + return 0; +} + +/*#Device.DSL.Line.{i}.ACTSNRMODEus!UBUS:dsl.line.0/status//act_snr_mode.us*/ +static int get_DSLLine_ACTSNRMODEus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "act_snr_mode", "us"); + return 0; +} + +/*#Device.DSL.Line.{i}.LineNumber!UBUS:dsl.line.0/status//line_number*/ +static int get_DSLLine_LineNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "line_number"); + return 0; +} + +/*#Device.DSL.Line.{i}.UpstreamMaxBitRate!UBUS:dsl.line.0/status//max_bit_rate.us*/ +static int get_DSLLine_UpstreamMaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "max_bit_rate", "us"); + return 0; +} + +/*#Device.DSL.Line.{i}.DownstreamMaxBitRate!UBUS:dsl.line.0/status//max_bit_rate.ds*/ +static int get_DSLLine_DownstreamMaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "max_bit_rate", "ds"); + return 0; +} + +/*#Device.DSL.Line.{i}.UpstreamNoiseMargin!UBUS:dsl.line.0/status//noise_margin.us*/ +static int get_DSLLine_UpstreamNoiseMargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "noise_margin", "us"); + return 0; +} + +/*#Device.DSL.Line.{i}.DownstreamNoiseMargin!UBUS:dsl.line.0/status//noise_margin.ds*/ +static int get_DSLLine_DownstreamNoiseMargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "noise_margin", "ds"); + return 0; +} + +/*#Device.DSL.Line.{i}.SNRMpbus!UBUS:dsl.line.0/status//snr_mpb_us*/ +static int get_DSLLine_SNRMpbus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "snr_mpb_us"); + return 0; +} + +/*#Device.DSL.Line.{i}.SNRMpbds!UBUS:dsl.line.0/status//snr_mpb_ds*/ +static int get_DSLLine_SNRMpbds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "snr_mpb_ds"); + return 0; +} + +/*#Device.DSL.Line.{i}.UpstreamAttenuation!UBUS:dsl.line.0/status//attenuation.us*/ +static int get_DSLLine_UpstreamAttenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "attenuation", "us"); + return 0; +} + +/*#Device.DSL.Line.{i}.DownstreamAttenuation!UBUS:dsl.line.0/status//attenuation.ds*/ +static int get_DSLLine_DownstreamAttenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "attenuation", "ds"); + return 0; +} + +/*#Device.DSL.Line.{i}.UpstreamPower!UBUS:dsl.line.0/status//power.us*/ +static int get_DSLLine_UpstreamPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "power", "us"); + return 0; +} + +/*#Device.DSL.Line.{i}.DownstreamPower!UBUS:dsl.line.0/status//power.ds*/ +static int get_DSLLine_DownstreamPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "power", "ds"); + return 0; +} + +/*#Device.DSL.Line.{i}.XTURVendor!UBUS:dsl.line.0/status//xtur_vendor*/ +static int get_DSLLine_XTURVendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtur_vendor"); + return 0; +} + +/*#Device.DSL.Line.{i}.XTURCountry!UBUS:dsl.line.0/status//xtur_country*/ +static int get_DSLLine_XTURCountry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtur_country"); + return 0; +} + +/*#Device.DSL.Line.{i}.XTURANSIStd!UBUS:dsl.line.0/status//xtur_ansi_std*/ +static int get_DSLLine_XTURANSIStd(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtur_ansi_std"); + return 0; +} + +/*#Device.DSL.Line.{i}.XTURANSIRev!UBUS:dsl.line.0/status//xtur_ansi_rev*/ +static int get_DSLLine_XTURANSIRev(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtur_ansi_rev"); + return 0; +} + +/*#Device.DSL.Line.{i}.XTUCVendor!UBUS:dsl.line.0/status//xtuc_vendor*/ +static int get_DSLLine_XTUCVendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtuc_vendor"); + return 0; +} + +/*#Device.DSL.Line.{i}.XTUCCountry!UBUS:dsl.line.0/status//xtuc_country*/ +static int get_DSLLine_XTUCCountry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtuc_country"); + return 0; +} + +/*#Device.DSL.Line.{i}.XTUCANSIStd!UBUS:dsl.line.0/status//xtuc_ansi_std*/ +static int get_DSLLine_XTUCANSIStd(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtuc_ansi_std"); + return 0; +} + +/*#Device.DSL.Line.{i}.XTUCANSIRev!UBUS:dsl.line.0/status//xtuc_ansi_rev*/ +static int get_DSLLine_XTUCANSIRev(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line",((struct dsl_line_args*)data)->id, "status", "xtuc_ansi_rev"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.TotalStart!UBUS:dsl.line.0/stats//total_start*/ +static int get_DSLLineStats_TotalStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "total_start"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.ShowtimeStart!UBUS:dsl.line.0/stats//showtime_start*/ +static int get_DSLLineStats_ShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "showtime_start"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.LastShowtimeStart!UBUS:dsl.line.0/stats//last_showtime_start*/ +static int get_DSLLineStats_LastShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "last_showtime_start"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.CurrentDayStart!UBUS:dsl.line.0/stats//current_day_start*/ +static int get_DSLLineStats_CurrentDayStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "current_day_start"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.QuarterHourStart!UBUS:dsl.line.0/stats//quarter_hour_start*/ +static int get_DSLLineStats_QuarterHourStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "quarter_hour_start"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.Total.ErroredSecs!UBUS:dsl.line.0/stats//total.errored_secs*/ +static int get_DSLLineStatsTotal_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "total", "errored_secs"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.Total.SeverelyErroredSecs!UBUS:dsl.line.0/stats//total.severely_errored_secs*/ +static int get_DSLLineStatsTotal_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "total", "severely_errored_secs"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.Showtime.ErroredSecs!UBUS:dsl.line.0/stats//showtime.severely_errored_secs*/ +static int get_DSLLineStatsShowtime_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "showtime", "errored_secs"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.Showtime.SeverelyErroredSecs!UBUS:dsl.line.0/stats//showtime.severely_errored_secs*/ +static int get_DSLLineStatsShowtime_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "showtime", "severely_errored_secs"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.LastShowtime.ErroredSecs!UBUS:dsl.line.0/stats//lastshowtime.errored_secs*/ +static int get_DSLLineStatsLastShowtime_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "lastshowtime", "errored_secs"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.LastShowtime.SeverelyErroredSecs!UBUS:dsl.line.0/stats//lastshowtime.severely_errored_secs*/ +static int get_DSLLineStatsLastShowtime_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "lastshowtime", "severely_errored_secs"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.CurrentDay.ErroredSecs!UBUS:dsl.line.0/stats//currentday.errored_secs*/ +static int get_DSLLineStatsCurrentDay_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "currentday", "errored_secs"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.CurrentDay.SeverelyErroredSecs!UBUS:dsl.line.0/stats//currentday.severely_errored_secs*/ +static int get_DSLLineStatsCurrentDay_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "currentday", "severely_errored_secs"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.QuarterHour.ErroredSecs!UBUS:dsl.line.0/stats//quarterhour.severely_errored_secs*/ +static int get_DSLLineStatsQuarterHour_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "quarterhour", "errored_secs"); + return 0; +} + +/*#Device.DSL.Line.{i}.Stats.QuarterHour.SeverelyErroredSecs!UBUS:dsl.line.0/stats//quarterhour.severely_errored_secs*/ +static int get_DSLLineStatsQuarterHour_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "quarterhour", "severely_errored_secs"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Enable!UBUS:dsl.channel.0/status//status*/ +static int get_DSLChannel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *status = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "status"); + *value = (strcmp(status, "up") == 0) ? "1" : "0"; + return 0; +} + +static int set_DSLChannel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +/*#Device.DSL.Channel.{i}.Status!UBUS:dsl.channel.0/status//status*/ +static int get_DSLChannel_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *status = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "status"); + *value = (strcmp(status, "up") == 0) ? "Up" : "Down"; + return 0; +} + +static int get_DSLChannel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dsl_channel_args *)data)->channel_sec, "dsl_channel_alias", value); + return 0; +} + +static int set_DSLChannel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct dsl_channel_args *)data)->channel_sec, "dsl_channel_alias", value); + break; + } + return 0; +} + +static int get_DSLChannel_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct dsl_channel_args*)data)->id; + return 0; +} + +static int get_DSLChannel_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char linker[8]; + snprintf(linker, sizeof(linker), "line_%s", ((struct dsl_line_args *)data)->id); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cDSL%cLine%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) + *value = ""; + return 0; +} + +static char *get_dsl_link_encapsulation_standard(char *str) +{ + char *dsl_link_encapsulation_standard = ""; + + if(strcmp(str, "adsl2_atm") == 0) + dsl_link_encapsulation_standard = "G.992.3_Annex_K_ATM"; + else if(strcmp(str, "adsl2_ptm") == 0) + dsl_link_encapsulation_standard = "G.992.3_Annex_K_PTM"; + else if(strcmp(str, "vdsl2_atm") == 0) + dsl_link_encapsulation_standard = "G.993.2_Annex_K_ATM"; + else if(strcmp(str, "vdsl2_ptm") == 0) + dsl_link_encapsulation_standard = "G.993.2_Annex_K_PTM"; + else if(strcmp(str, "auto") == 0) + dsl_link_encapsulation_standard = "G.994.1"; + else + dsl_link_encapsulation_standard = "unknown"; + + return dsl_link_encapsulation_standard; +} + +/*#Device.DSL.Channel.{i}.LinkEncapsulationSupported!UBUS:dsl.channel.0/status//link_encapsulation_supported*/ +static int get_DSLChannel_LinkEncapsulationSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *link_encapsulation_supported,*pch, *spch, *tmp, *tmpPtr, *str = ""; + + *value = ""; + link_encapsulation_supported = get_dsl_value_array_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "link_encapsulation_supported"); + if(link_encapsulation_supported[0] == '\0') + return 0; + for (pch = strtok_r(link_encapsulation_supported, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) + { + tmp = get_dsl_link_encapsulation_standard(pch); + if(*str == '\0') + dmasprintf(&str, "%s", tmp); + else { + tmpPtr = str; + dmasprintf(&str, "%s,%s", tmpPtr, tmp); + } + } + *value = str; + return 0; +} + +/*#Device.DSL.Channel.{i}.LinkEncapsulationUsed!UBUS:dsl.channel.0/status//link_encapsulation_used*/ +static int get_DSLChannel_LinkEncapsulationUsed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *link_encapsulation_used = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "link_encapsulation_used"); + *value = get_dsl_link_encapsulation_standard(link_encapsulation_used); + return 0; +} + +/*#Device.DSL.Channel.{i}.LPATH!UBUS:dsl.channel.0/status//lpath*/ +static int get_DSLChannel_LPATH(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "lpath"); + return 0; +} + +/*#Device.DSL.Channel.{i}.INTLVDEPTH!UBUS:dsl.channel.0/status//intlvdepth*/ +static int get_DSLChannel_INTLVDEPTH(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "intlvdepth"); + return 0; +} + +/*#Device.DSL.Channel.{i}.INTLVBLOCK!UBUS:dsl.channel.0/status//intlvblock*/ +static int get_DSLChannel_INTLVBLOCK(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "intlvblock"); + return 0; +} + +/*#Device.DSL.Channel.{i}.ActualInterleavingDelay!UBUS:dsl.channel.0/status//actual_interleaving_delay*/ +static int get_DSLChannel_ActualInterleavingDelay(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "actual_interleaving_delay"); + return 0; +} + +/*#Device.DSL.Channel.{i}.ACTINP!UBUS:dsl.channel.0/status//actinp*/ +static int get_DSLChannel_ACTINP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "actinp"); + return 0; +} + +/*#Device.DSL.Channel.{i}.INPREPORT!UBUS:dsl.channel.0/status//inpreport*/ +static int get_DSLChannel_INPREPORT(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "inpreport"); + return 0; +} + +/*#Device.DSL.Channel.{i}.NFEC!UBUS:dsl.channel.0/status//nfec*/ +static int get_DSLChannel_NFEC(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "nfec"); + return 0; +} + +/*#Device.DSL.Channel.{i}.RFEC!UBUS:dsl.channel.0/status//rfec*/ +static int get_DSLChannel_RFEC(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "rfec"); + return 0; +} + +/*#Device.DSL.Channel.{i}.LSYMB!UBUS:dsl.channel.0/status//lsymb*/ +static int get_DSLChannel_LSYMB(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "lsymb"); + return 0; +} + +/*#Device.DSL.Channel.{i}.UpstreamCurrRate!UBUS:dsl.channel.0/status//curr_rate.us*/ +static int get_DSLChannel_UpstreamCurrRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "curr_rate", "us"); + return 0; +} + +/*#Device.DSL.Channel.{i}.DownstreamCurrRate!UBUS:dsl.channel.0/status//curr_rate.ds*/ +static int get_DSLChannel_DownstreamCurrRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "curr_rate", "ds"); + return 0; +} + +/*#Device.DSL.Channel.{i}.ACTNDR!UBUS:dsl.channel.0/status//actndr.ds*/ +static int get_DSLChannel_ACTNDR(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "actndr", "ds"); + return 0; +} + +/*#Device.DSL.Channel.{i}.ACTINPREIN!UBUS:dsl.channel.0/status//actinprein.ds*/ +static int get_DSLChannel_ACTINPREIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument_and_with_two_key("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "actinprein", "ds"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.TotalStart!UBUS:dsl.channel.0/stats//total_start*/ +static int get_DSLChannelStats_TotalStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total_start"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.ShowtimeStart(!UBUS:dsl.channel.0/stats//showtime_start*/ +static int get_DSLChannelStats_ShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime_start"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.LastShowtimeStart!UBUS:dsl.channel.0/stats//last_showtime_start*/ +static int get_DSLChannelStats_LastShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "last_showtime_start"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.CurrentDayStart!UBUS:dsl.channel.0/stats//current_day_start*/ +static int get_DSLChannelStats_CurrentDayStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "current_day_start"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.QuarterHourStart!UBUS:dsl.channel.0/stats//quarter_hour_start*/ +static int get_DSLChannelStats_QuarterHourStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarter_hour_start"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.Total.XTURFECErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ +static int get_DSLChannelStatsTotal_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtur_fec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.Total.XTUCFECErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ +static int get_DSLChannelStatsTotal_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtuc_fec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.Total.XTURHECErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ +static int get_DSLChannelStatsTotal_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtur_hec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.Total.XTUCHECErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ +static int get_DSLChannelStatsTotal_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtuc_hec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.Total.XTURCRCErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ +static int get_DSLChannelStatsTotal_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtur_crc_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.Total.XTUCCRCErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ +static int get_DSLChannelStatsTotal_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtuc_crc_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.Showtime.XTURFECErrors!UBUS:dsl.channel.0/stats//showtime.xtur_fec_errors*/ +static int get_DSLChannelStatsShowtime_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtur_fec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.Showtime.XTUCFECErrors!UBUS:dsl.channel.0/stats//showtime.xtuc_fec_errors*/ +static int get_DSLChannelStatsShowtime_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtuc_fec_errors"); + return 0;} + +/*#Device.DSL.Channel.{i}.Stats.Showtime.XTURHECErrors!UBUS:dsl.channel.0/stats//showtime.xtur_hec_errors*/ +static int get_DSLChannelStatsShowtime_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtur_hec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.Showtime.XTUCHECErrors!UBUS:dsl.channel.0/stats//showtime.xtuc_hec_errors*/ +static int get_DSLChannelStatsShowtime_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtuc_hec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.Showtime.XTURCRCErrors!UBUS:dsl.channel.0/stats//showtime.xtur_crc_errors*/ +static int get_DSLChannelStatsShowtime_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtur_crc_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.Showtime.XTUCCRCErrors!UBUS:dsl.channel.0/stats//showtime.xtuc_crc_errors*/ +static int get_DSLChannelStatsShowtime_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtuc_crc_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTURFECErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtur_fec_errors*/ +static int get_DSLChannelStatsLastShowtime_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtur_fec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTUCFECErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtuc_fec_errors*/ +static int get_DSLChannelStatsLastShowtime_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtuc_fec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTURHECErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtur_hec_errors*/ +static int get_DSLChannelStatsLastShowtime_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtur_hec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTUCHECErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtuc_hec_errors*/ +static int get_DSLChannelStatsLastShowtime_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtuc_hec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTURCRCErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtur_crc_errors*/ +static int get_DSLChannelStatsLastShowtime_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtur_crc_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTUCCRCErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtuc_crc_errors*/ +static int get_DSLChannelStatsLastShowtime_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtuc_crc_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTURFECErrors!UBUS:dsl.channel.0/stats//currentday.xtur_fec_errors*/ +static int get_DSLChannelStatsCurrentDay_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtur_fec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTUCFECErrors!UBUS:dsl.channel.0/stats//currentday.xtuc_fec_errors*/ +static int get_DSLChannelStatsCurrentDay_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtuc_fec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTURHECErrors!UBUS:dsl.channel.0/stats//currentday.xtur_hec_errors*/ +static int get_DSLChannelStatsCurrentDay_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtur_hec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTUCHECErrors!UBUS:dsl.channel.0/stats//currentday.xtuc_hec_errors*/ +static int get_DSLChannelStatsCurrentDay_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtuc_hec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTURCRCErrors!UBUS:dsl.channel.0/stats//currentday.xtur_crc_errors*/ +static int get_DSLChannelStatsCurrentDay_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtur_crc_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTUCCRCErrors!UBUS:dsl.channel.0/stats//currentday.xtuc_crc_errors*/ +static int get_DSLChannelStatsCurrentDay_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtuc_crc_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTURFECErrors!UBUS:dsl.channel.0/stats//quarterhour.xtur_fec_errors*/ +static int get_DSLChannelStatsQuarterHour_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtur_fec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTUCFECErrors!UBUS:dsl.channel.0/stats//quarterhour.xtuc_fec_errors*/ +static int get_DSLChannelStatsQuarterHour_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtuc_fec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTURHECErrors!UBUS:dsl.channel.0/stats//quarterhour.xtur_hec_errors*/ +static int get_DSLChannelStatsQuarterHour_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtur_hec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTUCHECErrors!UBUS:dsl.channel.0/stats//quarterhour.xtuc_hec_errors*/ +static int get_DSLChannelStatsQuarterHour_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtuc_hec_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTURCRCErrors!UBUS:dsl.channel.0/stats//quarterhour.xtur_crc_errors*/ +static int get_DSLChannelStatsQuarterHour_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtur_crc_errors"); + return 0; +} + +/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTUCCRCErrors!UBUS:dsl.channel.0/stats//quarterhour.xtuc_crc_errors*/ +static int get_DSLChannelStatsQuarterHour_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtuc_crc_errors"); + return 0; +} + /* *** Device.DSL. *** */ DMOBJ tDSLObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -259,1294 +1563,3 @@ DMLEAF tDSLChannelStatsQuarterHourParams[] = { {"XTUCCRCErrors", &DMREAD, DMT_UNINT, get_DSLChannelStatsQuarterHour_XTUCCRCErrors, NULL, NULL, NULL, BBFDM_BOTH}, {0} }; - -/************************************************************************** -* LINKER -***************************************************************************/ -int get_dsl_line_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct dsl_line_args *)data)->id) { - dmasprintf(linker, "line_%s", ((struct dsl_line_args *)data)->id); - return 0; - } - *linker = "" ; - return 0; -} - -int get_dsl_channel_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct dsl_line_args *)data)->id){ - dmasprintf(linker, "channel_%s", ((struct dsl_line_args *)data)->id); - return 0; - } - *linker = "" ; - return 0; -} - -/************************************************************************** -* INIT -***************************************************************************/ -static inline int init_dsl_line(struct dsl_line_args *args, struct uci_section *s) -{ - args->line_sec = s; - return 0; -} - -static inline int init_dsl_channel(struct dsl_channel_args *args, struct uci_section *s) -{ - args->channel_sec = s; - return 0; -} - -/*************************************************************/ -static struct uci_section *update_create_dmmap_dsl_line(char *curr_id) -{ - struct uci_section *s = NULL; - char *name, *instance; - - uci_path_foreach_option_eq(bbfdm, "dmmap", "dsl_line", "id", curr_id, s) { - return s; - } - if (!s) { - dmasprintf(&instance, "%d", atoi(curr_id)+1); - DMUCI_ADD_SECTION(bbfdm, "dmmap", "dsl_line", &s, &name); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "id", curr_id); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "dsl_line_instance", instance); - dmfree(instance); - } - return s; -} - -static struct uci_section *update_create_dmmap_dsl_channel(char *curr_id) -{ - struct uci_section *s = NULL; - char *name, *instance; - - uci_path_foreach_option_eq(bbfdm, "dmmap", "dsl_channel", "id", curr_id, s) { - return s; - } - if (!s) { - dmasprintf(&instance, "%d", atoi(curr_id)+1); - DMUCI_ADD_SECTION(bbfdm, "dmmap", "dsl_channel", &s, &name); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "id", curr_id); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "dsl_channel_instance", instance); - dmfree(instance); - } - return s; -} -/************************************************************* -* ENTRY METHOD -*************************************************************/ -int browseDSLLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - json_object *res = NULL, *line_obj = NULL; - struct dsl_line_args cur_dsl_line_args = {0}; - struct uci_section *s = NULL; - char *dsl_int = NULL, *dsl_int_last = NULL; - int entries = 0; - - dmubus_call("dsl", "status", UBUS_ARGS{}, 0, &res); - while (res) { - line_obj = dmjson_select_obj_in_array_idx(res, entries, 1, "line"); - if(line_obj) { - cur_dsl_line_args.id = dmjson_get_value(line_obj, 1, "id"); - entries++; - s = update_create_dmmap_dsl_line(cur_dsl_line_args.id); - init_dsl_line(&cur_dsl_line_args, s); - dsl_int = handle_update_instance(1, dmctx, &dsl_int_last, update_instance_alias, 3, s, "dsl_line_instance", "dsl_line_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_dsl_line_args, dsl_int) == DM_STOP) - break; - } - else - break; - } - return 0; -} - -int browseDSLChannelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - json_object *res = NULL, *line_obj = NULL, *channel_obj = NULL; - struct dsl_channel_args cur_dsl_channel_args = {0}; - struct uci_section *s = NULL; - char *dsl_int = NULL, *dsl_int_last = NULL; - int entries_line = 0, entries_channel = 0; - - dmubus_call("dsl", "status", UBUS_ARGS{}, 0, &res); - while (res) { - line_obj = dmjson_select_obj_in_array_idx(res, entries_line, 1, "line"); - while (line_obj) { - channel_obj = dmjson_select_obj_in_array_idx(line_obj, entries_channel, 1, "channel"); - if(channel_obj) { - cur_dsl_channel_args.id = dmjson_get_value(channel_obj, 1, "id"); - entries_channel++; - s = update_create_dmmap_dsl_channel(cur_dsl_channel_args.id); - init_dsl_channel(&cur_dsl_channel_args, s); - dsl_int = handle_update_instance(1, dmctx, &dsl_int_last, update_instance_alias, 3, s, "dsl_channel_instance", "dsl_channel_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_dsl_channel_args, dsl_int) == DM_STOP) - break; - } - else - break; - } - entries_line++; - if(!line_obj) - break; - } - return 0; -} - -/************************************************************************** -* COMMON FUNCTIONS -***************************************************************************/ -static char *get_dsl_value_without_argument(char *command1, char *id, char *command2, char *key) -{ - json_object *res; - char command[16], *value = "0"; - - snprintf(command, sizeof(command), "%s.%s", command1, id); - dmubus_call(command, command2, UBUS_ARGS{}, 0, &res); - if (!res) return ""; - value = dmjson_get_value(res, 1, key); - return value; -} - -static char *get_dsl_value_without_argument_and_with_two_key(char *command1, char *id, char *command2, char *key1, char *key2) -{ - json_object *res; - char command[16], *value = "0"; - - snprintf(command, sizeof(command), "%s.%s", command1, id); - dmubus_call(command, command2, UBUS_ARGS{}, 0, &res); - if (!res) return ""; - value = dmjson_get_value(res, 2, key1, key2); - return value; -} - -static char *get_dsl_value_with_argument(char *command1, char *id, char *command2, char *argument, char *key) -{ - json_object *res; - char command[16], *value = "0"; - - snprintf(command, sizeof(command), "%s.%s", command1, id); - dmubus_call(command, command2, UBUS_ARGS{{"interval", argument, String}}, 1, &res); - if (!res) return ""; - value = dmjson_get_value(res, 1, key); - return value; -} - -static char *get_dsl_value_array_without_argument(char *command1, char *id, char *command2, char *key) -{ - json_object *res; - char command[16], *value= "0"; - - snprintf(command, sizeof(command), "%s.%s", command1, id); - dmubus_call(command, command2, UBUS_ARGS{}, 0, &res); - if (!res) return ""; - value = dmjson_get_value_array_all(res, DELIMITOR, 1, key); - return value; -} - -/************************************************************************** -* GET & SET DSL PARAMETERS -***************************************************************************/ -int get_DSL_LineNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_path_foreach_sections(bbfdm, "dmmap", "dsl_line", s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -int get_DSL_ChannelNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_path_foreach_sections(bbfdm, "dmmap", "dsl_channel", s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -/*#Device.DSL.Line.{i}.Enable!UBUS:dsl.line.0/status//status*/ -int get_DSLLine_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *status = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "status"); - *value = (strcmp(status, "up") == 0) ? "1" : "0"; - return 0; -} - -int set_DSLLine_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -/*#Device.DSL.Line.{i}.Status!UBUS:dsl.line.0/status//status*/ -int get_DSLLine_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *status = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "status"); - *value = (strcmp(status, "up") == 0) ? "Up" : "Down"; - return 0; -} - -int get_DSLLine_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dsl_line_args *)data)->line_sec, "dsl_line_alias", value); - return 0; -} - -int set_DSLLine_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct dsl_line_args *)data)->line_sec, "dsl_line_alias", value); - break; - } - return 0; -} - -int get_DSLLine_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct dsl_line_args*)data)->id; - return 0; -} - -int get_DSLLine_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ""; - return 0; -} - -int set_DSLLine_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -/*#Device.DSL.Line.{i}.Upstream!UBUS:dsl.line.0/status//upstream*/ -int get_DSLLine_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "upstream"); - return 0; -} - -/*#Device.DSL.Line.{i}.FirmwareVersion!UBUS:dsl.line.0/status//firmware_version*/ -int get_DSLLine_FirmwareVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "firmware_version"); - return 0; -} - -/*#Device.DSL.Line.{i}.LinkStatus!UBUS:dsl.line.0/status//link_status*/ -int get_DSLLine_LinkStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *link_status = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "link_status"); - if(strcmp(link_status, "up") == 0) - *value = "Up"; - else if(strcmp(link_status, "initializing") == 0) - *value = "Initializing"; - else if(strcmp(link_status, "no_signal") == 0) - *value = "NoSignal"; - else if(strcmp(link_status, "disabled") == 0) - *value = "Disabled"; - else if(strcmp(link_status, "establishing") == 0) - *value = "EstablishingLink"; - else if(strcmp(link_status, "error") == 0) - *value = "Error"; - else - *value = link_status; - return 0; -} - -static char *get_dsl_standard(char *str) -{ - char *dsl_standard; - - if(strcmp(str, "gdmt_annexa") == 0) - dsl_standard = "G.992.1_Annex_A"; - else if(strcmp(str, "gdmt_annexb") == 0) - dsl_standard = "G.992.1_Annex_B"; - else if(strcmp(str, "gdmt_annexc") == 0) - dsl_standard = "G.992.1_Annex_C"; - else if(strcmp(str, "t1413") == 0) - dsl_standard = "T1.413"; - else if(strcmp(str, "t1413_i2") == 0) - dsl_standard = "T1.413i2"; - else if(strcmp(str, "glite") == 0) - dsl_standard = "G.992.2"; - else if(strcmp(str, "etsi_101_388") == 0) - dsl_standard = "ETSI_101_388"; - else if(strcmp(str, "adsl2_annexa") == 0) - dsl_standard = "G.992.3_Annex_A"; - else if(strcmp(str, "adsl2_annexb") == 0) - dsl_standard = "G.992.3_Annex_B"; - else if(strcmp(str, "adsl2_annexc") == 0) - dsl_standard = "G.992.3_Annex_C"; - else if(strcmp(str, "adsl2_annexi") == 0) - dsl_standard = "G.992.3_Annex_I"; - else if(strcmp(str, "adsl2_annexj") == 0) - dsl_standard = "G.992.3_Annex_J"; - else if(strcmp(str, "adsl2_annexl") == 0) - dsl_standard = "G.992.3_Annex_L"; - else if(strcmp(str, "adsl2_annexm") == 0) - dsl_standard = "G.992.3_Annex_M"; - else if(strcmp(str, "splitterless_adsl2") == 0) - dsl_standard = "G.992.4"; - else if(strcmp(str, "adsl2p_annexa") == 0) - dsl_standard = "G.992.5_Annex_A"; - else if(strcmp(str, "adsl2p_annexb") == 0) - dsl_standard = "G.992.5_Annex_B"; - else if(strcmp(str, "adsl2p_annexc") == 0) - dsl_standard = "G.992.5_Annex_C"; - else if(strcmp(str, "adsl2p_annexi") == 0) - dsl_standard = "G.992.5_Annex_I"; - else if(strcmp(str, "adsl2p_annexj") == 0) - dsl_standard = "G.992.5_Annex_J"; - else if(strcmp(str, "adsl2p_annexm") == 0) - dsl_standard = "G.992.5_Annex_M"; - else if(strcmp(str, "vdsl") == 0) - dsl_standard = "G.993.1"; - else if(strcmp(str, "vdsl2_annexa") == 0) - dsl_standard = "G.993.2_Annex_A"; - else if(strcmp(str, "vdsl2_annexb") == 0) - dsl_standard = "G.993.2_Annex_B"; - else if(strcmp(str, "vdsl2_annexc") == 0) - dsl_standard = "G.993.2_Annex_C"; - else - dsl_standard = str; - - return dsl_standard; -} - -/*#Device.DSL.Line.{i}.StandardsSupported!UBUS:dsl.line.0/status//standards_supported*/ -int get_DSLLine_StandardsSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *standards_supported,*pch, *spch, *tmp, *tmpPtr, *str = ""; - - *value = ""; - standards_supported = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "standards_supported"); - if(standards_supported[0] == '\0') - return 0; - for (pch = strtok_r(standards_supported, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) - { - tmp = get_dsl_standard(pch); - if(*str == '\0') - dmasprintf(&str, "%s", tmp); - else { - tmpPtr = str; - dmasprintf(&str, "%s,%s", tmpPtr, tmp); - } - } - *value = str; - return 0; -} - -/*#Device.DSL.Line.{i}.XTSE!UBUS:dsl.line.0/status//xtse*/ -int get_DSLLine_XTSE(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *xtse,*pch, *spch, *tmpPtr, *str = ""; - - *value = ""; - xtse = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtse"); - if(xtse[0] == '\0') - return 0; - for (pch = strtok_r(xtse, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) - { - if(*str == '\0') - dmasprintf(&str, "%s", pch); - else { - tmpPtr = str; - dmasprintf(&str, "%s%s", tmpPtr, pch); - } - } - *value = str; - return 0; -} - -/*#Device.DSL.Line.{i}.StandardUsed!UBUS:dsl.line.0/status//standard_used*/ -int get_DSLLine_StandardUsed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *standard_used = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "standard_used"); - *value = get_dsl_standard(standard_used); - return 0; -} - -/*#Device.DSL.Line.{i}.XTSUsed!UBUS:dsl.line.0/status//xtse_used*/ -int get_DSLLine_XTSUsed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *xtse_used,*pch, *spch, *tmpPtr, *str = ""; - - *value = ""; - xtse_used = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtse_used"); - if(xtse_used[0] == '\0') - return 0; - for (pch = strtok_r(xtse_used, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) - { - if(*str == '\0') - dmasprintf(&str, "%s", pch); - else { - tmpPtr = str; - dmasprintf(&str, "%s%s", tmpPtr, pch); - } - } - *value = str; - return 0; -} - -/*#Device.DSL.Line.{i}.LineEncoding!UBUS:dsl.line.0/status//line_encoding*/ -int get_DSLLine_LineEncoding(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *line_encoding = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "line_encoding"); - if(strcmp(line_encoding, "dmt") == 0) - *value = "DMT"; - else if(strcmp(line_encoding, "cap") == 0) - *value = "CAP"; - else if(strcmp(line_encoding, "2b1q") == 0) - *value = "2B1Q"; - else if(strcmp(line_encoding, "43bt") == 0) - *value = "43BT"; - else if(strcmp(line_encoding, "pam") == 0) - *value = "PAM"; - else if(strcmp(line_encoding, "qam") == 0) - *value = "QAM"; - else - *value = line_encoding; - return 0; -} - -/*#Device.DSL.Line.{i}.AllowedProfiles!UBUS:dsl.line.0/status//allowed_profiles*/ -int get_DSLLine_AllowedProfiles(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "allowed_profiles"); - return 0; -} - -/*#Device.DSL.Line.{i}.CurrentProfile!UBUS:dsl.line.0/status//current_profile*/ -int get_DSLLine_CurrentProfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "current_profile"); - return 0; -} - -/*#Device.DSL.Line.{i}.PowerManagementState!UBUS:dsl.line.0/status//power_management_state*/ -int get_DSLLine_PowerManagementState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *power_management_state = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "power_management_state"); - if(strcmp(power_management_state, "l0") == 0) - *value = "L0"; - else if(strcmp(power_management_state, "l1") == 0) - *value = "L1"; - else if(strcmp(power_management_state, "l2") == 0) - *value = "L2"; - else if(strcmp(power_management_state, "l3") == 0) - *value = "L3"; - else if(strcmp(power_management_state, "l4") == 0) - *value = "L4"; - else - *value = power_management_state; - return 0; -} - -/*#Device.DSL.Line.{i}.SuccessFailureCause!UBUS:dsl.line.0/status//success_failure_cause*/ -int get_DSLLine_SuccessFailureCause(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "success_failure_cause"); - return 0; -} - -/*#Device.DSL.Line.{i}.UPBOKLERPb!UBUS:dsl.line.0/status//upbokler_pb*/ -int get_DSLLine_UPBOKLERPb(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "upbokler_pb"); - return 0; -} - -/*#Device.DSL.Line.{i}.RXTHRSHds!UBUS:dsl.line.0/status//rxthrsh_ds*/ -int get_DSLLine_RXTHRSHds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "rxthrsh_ds"); - return 0; -} - -/*#Device.DSL.Line.{i}.ACTRAMODEds!UBUS:dsl.line.0/status//act_ra_mode.ds*/ -int get_DSLLine_ACTRAMODEds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "act_ra_mode", "ds"); - return 0; -} - -/*#Device.DSL.Line.{i}.ACTRAMODEus!UBUS:dsl.line.0/status//act_ra_mode.us*/ -int get_DSLLine_ACTRAMODEus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "act_ra_mode", "us"); - return 0; -} - -/*#Device.DSL.Line.{i}.SNRMROCus!UBUS:dsl.line.0/status//snr_mroc_us*/ -int get_DSLLine_SNRMROCus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "snr_mroc_us"); - return 0; -} - -/*#Device.DSL.Line.{i}.LastStateTransmittedDownstream!UBUS:dsl.line.0/status//last_state_transmitted.ds*/ -int get_DSLLine_LastStateTransmittedDownstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "last_state_transmitted", "ds"); - return 0; -} - -/*#Device.DSL.Line.{i}.LastStateTransmittedUpstream!UBUS:dsl.line.0/status//last_state_transmitted.us*/ -int get_DSLLine_LastStateTransmittedUpstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "last_state_transmitted", "us"); - return 0; -} - -/*#Device.DSL.Line.{i}.US0MASK!UBUS:dsl.line.0/status//us0_mask*/ -int get_DSLLine_US0MASK(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "us0_mask"); - return 0; -} - -/*#Device.DSL.Line.{i}.TRELLISds!UBUS:dsl.line.0/status//trellis.ds*/ -int get_DSLLine_TRELLISds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "trellis", "ds"); - return 0; -} - -/*#Device.DSL.Line.{i}.TRELLISus!UBUS:dsl.line.0/status//trellis.us*/ -int get_DSLLine_TRELLISus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "trellis", "us"); - return 0; -} - -/*#Device.DSL.Line.{i}.ACTSNRMODEds!UBUS:dsl.line.0/status//act_snr_mode.ds*/ -int get_DSLLine_ACTSNRMODEds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "act_snr_mode", "ds"); - return 0; -} - -/*#Device.DSL.Line.{i}.ACTSNRMODEus!UBUS:dsl.line.0/status//act_snr_mode.us*/ -int get_DSLLine_ACTSNRMODEus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "act_snr_mode", "us"); - return 0; -} - -/*#Device.DSL.Line.{i}.LineNumber!UBUS:dsl.line.0/status//line_number*/ -int get_DSLLine_LineNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "line_number"); - return 0; -} - -/*#Device.DSL.Line.{i}.UpstreamMaxBitRate!UBUS:dsl.line.0/status//max_bit_rate.us*/ -int get_DSLLine_UpstreamMaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "max_bit_rate", "us"); - return 0; -} - -/*#Device.DSL.Line.{i}.DownstreamMaxBitRate!UBUS:dsl.line.0/status//max_bit_rate.ds*/ -int get_DSLLine_DownstreamMaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "max_bit_rate", "ds"); - return 0; -} - -/*#Device.DSL.Line.{i}.UpstreamNoiseMargin!UBUS:dsl.line.0/status//noise_margin.us*/ -int get_DSLLine_UpstreamNoiseMargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "noise_margin", "us"); - return 0; -} - -/*#Device.DSL.Line.{i}.DownstreamNoiseMargin!UBUS:dsl.line.0/status//noise_margin.ds*/ -int get_DSLLine_DownstreamNoiseMargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "noise_margin", "ds"); - return 0; -} - -/*#Device.DSL.Line.{i}.SNRMpbus!UBUS:dsl.line.0/status//snr_mpb_us*/ -int get_DSLLine_SNRMpbus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "snr_mpb_us"); - return 0; -} - -/*#Device.DSL.Line.{i}.SNRMpbds!UBUS:dsl.line.0/status//snr_mpb_ds*/ -int get_DSLLine_SNRMpbds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "snr_mpb_ds"); - return 0; -} - -/*#Device.DSL.Line.{i}.UpstreamAttenuation!UBUS:dsl.line.0/status//attenuation.us*/ -int get_DSLLine_UpstreamAttenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "attenuation", "us"); - return 0; -} - -/*#Device.DSL.Line.{i}.DownstreamAttenuation!UBUS:dsl.line.0/status//attenuation.ds*/ -int get_DSLLine_DownstreamAttenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "attenuation", "ds"); - return 0; -} - -/*#Device.DSL.Line.{i}.UpstreamPower!UBUS:dsl.line.0/status//power.us*/ -int get_DSLLine_UpstreamPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "power", "us"); - return 0; -} - -/*#Device.DSL.Line.{i}.DownstreamPower!UBUS:dsl.line.0/status//power.ds*/ -int get_DSLLine_DownstreamPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.line", ((struct dsl_line_args*)data)->id, "status", "power", "ds"); - return 0; -} - -/*#Device.DSL.Line.{i}.XTURVendor!UBUS:dsl.line.0/status//xtur_vendor*/ -int get_DSLLine_XTURVendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtur_vendor"); - return 0; -} - -/*#Device.DSL.Line.{i}.XTURCountry!UBUS:dsl.line.0/status//xtur_country*/ -int get_DSLLine_XTURCountry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtur_country"); - return 0; -} - -/*#Device.DSL.Line.{i}.XTURANSIStd!UBUS:dsl.line.0/status//xtur_ansi_std*/ -int get_DSLLine_XTURANSIStd(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtur_ansi_std"); - return 0; -} - -/*#Device.DSL.Line.{i}.XTURANSIRev!UBUS:dsl.line.0/status//xtur_ansi_rev*/ -int get_DSLLine_XTURANSIRev(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtur_ansi_rev"); - return 0; -} - -/*#Device.DSL.Line.{i}.XTUCVendor!UBUS:dsl.line.0/status//xtuc_vendor*/ -int get_DSLLine_XTUCVendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtuc_vendor"); - return 0; -} - -/*#Device.DSL.Line.{i}.XTUCCountry!UBUS:dsl.line.0/status//xtuc_country*/ -int get_DSLLine_XTUCCountry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtuc_country"); - return 0; -} - -/*#Device.DSL.Line.{i}.XTUCANSIStd!UBUS:dsl.line.0/status//xtuc_ansi_std*/ -int get_DSLLine_XTUCANSIStd(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "xtuc_ansi_std"); - return 0; -} - -/*#Device.DSL.Line.{i}.XTUCANSIRev!UBUS:dsl.line.0/status//xtuc_ansi_rev*/ -int get_DSLLine_XTUCANSIRev(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line",((struct dsl_line_args*)data)->id, "status", "xtuc_ansi_rev"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.TotalStart!UBUS:dsl.line.0/stats//total_start*/ -int get_DSLLineStats_TotalStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "total_start"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.ShowtimeStart!UBUS:dsl.line.0/stats//showtime_start*/ -int get_DSLLineStats_ShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "showtime_start"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.LastShowtimeStart!UBUS:dsl.line.0/stats//last_showtime_start*/ -int get_DSLLineStats_LastShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "last_showtime_start"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.CurrentDayStart!UBUS:dsl.line.0/stats//current_day_start*/ -int get_DSLLineStats_CurrentDayStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "current_day_start"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.QuarterHourStart!UBUS:dsl.line.0/stats//quarter_hour_start*/ -int get_DSLLineStats_QuarterHourStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "quarter_hour_start"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.Total.ErroredSecs!UBUS:dsl.line.0/stats//total.errored_secs*/ -int get_DSLLineStatsTotal_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "total", "errored_secs"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.Total.SeverelyErroredSecs!UBUS:dsl.line.0/stats//total.severely_errored_secs*/ -int get_DSLLineStatsTotal_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "total", "severely_errored_secs"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.Showtime.ErroredSecs!UBUS:dsl.line.0/stats//showtime.severely_errored_secs*/ -int get_DSLLineStatsShowtime_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "showtime", "errored_secs"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.Showtime.SeverelyErroredSecs!UBUS:dsl.line.0/stats//showtime.severely_errored_secs*/ -int get_DSLLineStatsShowtime_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "showtime", "severely_errored_secs"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.LastShowtime.ErroredSecs!UBUS:dsl.line.0/stats//lastshowtime.errored_secs*/ -int get_DSLLineStatsLastShowtime_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "lastshowtime", "errored_secs"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.LastShowtime.SeverelyErroredSecs!UBUS:dsl.line.0/stats//lastshowtime.severely_errored_secs*/ -int get_DSLLineStatsLastShowtime_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "lastshowtime", "severely_errored_secs"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.CurrentDay.ErroredSecs!UBUS:dsl.line.0/stats//currentday.errored_secs*/ -int get_DSLLineStatsCurrentDay_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "currentday", "errored_secs"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.CurrentDay.SeverelyErroredSecs!UBUS:dsl.line.0/stats//currentday.severely_errored_secs*/ -int get_DSLLineStatsCurrentDay_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "currentday", "severely_errored_secs"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.QuarterHour.ErroredSecs!UBUS:dsl.line.0/stats//quarterhour.severely_errored_secs*/ -int get_DSLLineStatsQuarterHour_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "quarterhour", "errored_secs"); - return 0; -} - -/*#Device.DSL.Line.{i}.Stats.QuarterHour.SeverelyErroredSecs!UBUS:dsl.line.0/stats//quarterhour.severely_errored_secs*/ -int get_DSLLineStatsQuarterHour_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.line", ((struct dsl_line_args*)data)->id, "stats", "quarterhour", "severely_errored_secs"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Enable!UBUS:dsl.channel.0/status//status*/ -int get_DSLChannel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *status = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "status"); - *value = (strcmp(status, "up") == 0) ? "1" : "0"; - return 0; -} - -int set_DSLChannel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -/*#Device.DSL.Channel.{i}.Status!UBUS:dsl.channel.0/status//status*/ -int get_DSLChannel_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *status = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "status"); - *value = (strcmp(status, "up") == 0) ? "Up" : "Down"; - return 0; -} - -int get_DSLChannel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dsl_channel_args *)data)->channel_sec, "dsl_channel_alias", value); - return 0; -} - -int set_DSLChannel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct dsl_channel_args *)data)->channel_sec, "dsl_channel_alias", value); - break; - } - return 0; -} - -int get_DSLChannel_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct dsl_channel_args*)data)->id; - return 0; -} - -int get_DSLChannel_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char linker[8]; - snprintf(linker, sizeof(linker), "line_%s", ((struct dsl_line_args *)data)->id); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cDSL%cLine%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; - return 0; -} - -static char *get_dsl_link_encapsulation_standard(char *str) -{ - char *dsl_link_encapsulation_standard = ""; - - if(strcmp(str, "adsl2_atm") == 0) - dsl_link_encapsulation_standard = "G.992.3_Annex_K_ATM"; - else if(strcmp(str, "adsl2_ptm") == 0) - dsl_link_encapsulation_standard = "G.992.3_Annex_K_PTM"; - else if(strcmp(str, "vdsl2_atm") == 0) - dsl_link_encapsulation_standard = "G.993.2_Annex_K_ATM"; - else if(strcmp(str, "vdsl2_ptm") == 0) - dsl_link_encapsulation_standard = "G.993.2_Annex_K_PTM"; - else if(strcmp(str, "auto") == 0) - dsl_link_encapsulation_standard = "G.994.1"; - else - dsl_link_encapsulation_standard = "unknown"; - - return dsl_link_encapsulation_standard; -} - -/*#Device.DSL.Channel.{i}.LinkEncapsulationSupported!UBUS:dsl.channel.0/status//link_encapsulation_supported*/ -int get_DSLChannel_LinkEncapsulationSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *link_encapsulation_supported,*pch, *spch, *tmp, *tmpPtr, *str = ""; - - *value = ""; - link_encapsulation_supported = get_dsl_value_array_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "link_encapsulation_supported"); - if(link_encapsulation_supported[0] == '\0') - return 0; - for (pch = strtok_r(link_encapsulation_supported, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) - { - tmp = get_dsl_link_encapsulation_standard(pch); - if(*str == '\0') - dmasprintf(&str, "%s", tmp); - else { - tmpPtr = str; - dmasprintf(&str, "%s,%s", tmpPtr, tmp); - } - } - *value = str; - return 0; -} - -/*#Device.DSL.Channel.{i}.LinkEncapsulationUsed!UBUS:dsl.channel.0/status//link_encapsulation_used*/ -int get_DSLChannel_LinkEncapsulationUsed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *link_encapsulation_used = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "link_encapsulation_used"); - *value = get_dsl_link_encapsulation_standard(link_encapsulation_used); - return 0; -} - -/*#Device.DSL.Channel.{i}.LPATH!UBUS:dsl.channel.0/status//lpath*/ -int get_DSLChannel_LPATH(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "lpath"); - return 0; -} - -/*#Device.DSL.Channel.{i}.INTLVDEPTH!UBUS:dsl.channel.0/status//intlvdepth*/ -int get_DSLChannel_INTLVDEPTH(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "intlvdepth"); - return 0; -} - -/*#Device.DSL.Channel.{i}.INTLVBLOCK!UBUS:dsl.channel.0/status//intlvblock*/ -int get_DSLChannel_INTLVBLOCK(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "intlvblock"); - return 0; -} - -/*#Device.DSL.Channel.{i}.ActualInterleavingDelay!UBUS:dsl.channel.0/status//actual_interleaving_delay*/ -int get_DSLChannel_ActualInterleavingDelay(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "actual_interleaving_delay"); - return 0; -} - -/*#Device.DSL.Channel.{i}.ACTINP!UBUS:dsl.channel.0/status//actinp*/ -int get_DSLChannel_ACTINP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "actinp"); - return 0; -} - -/*#Device.DSL.Channel.{i}.INPREPORT!UBUS:dsl.channel.0/status//inpreport*/ -int get_DSLChannel_INPREPORT(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "inpreport"); - return 0; -} - -/*#Device.DSL.Channel.{i}.NFEC!UBUS:dsl.channel.0/status//nfec*/ -int get_DSLChannel_NFEC(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "nfec"); - return 0; -} - -/*#Device.DSL.Channel.{i}.RFEC!UBUS:dsl.channel.0/status//rfec*/ -int get_DSLChannel_RFEC(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "rfec"); - return 0; -} - -/*#Device.DSL.Channel.{i}.LSYMB!UBUS:dsl.channel.0/status//lsymb*/ -int get_DSLChannel_LSYMB(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "lsymb"); - return 0; -} - -/*#Device.DSL.Channel.{i}.UpstreamCurrRate!UBUS:dsl.channel.0/status//curr_rate.us*/ -int get_DSLChannel_UpstreamCurrRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "curr_rate", "us"); - return 0; -} - -/*#Device.DSL.Channel.{i}.DownstreamCurrRate!UBUS:dsl.channel.0/status//curr_rate.ds*/ -int get_DSLChannel_DownstreamCurrRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "curr_rate", "ds"); - return 0; -} - -/*#Device.DSL.Channel.{i}.ACTNDR!UBUS:dsl.channel.0/status//actndr.ds*/ -int get_DSLChannel_ACTNDR(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "actndr", "ds"); - return 0; -} - -/*#Device.DSL.Channel.{i}.ACTINPREIN!UBUS:dsl.channel.0/status//actinprein.ds*/ -int get_DSLChannel_ACTINPREIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument_and_with_two_key("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "actinprein", "ds"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.TotalStart!UBUS:dsl.channel.0/stats//total_start*/ -int get_DSLChannelStats_TotalStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total_start"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.ShowtimeStart(!UBUS:dsl.channel.0/stats//showtime_start*/ -int get_DSLChannelStats_ShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime_start"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.LastShowtimeStart!UBUS:dsl.channel.0/stats//last_showtime_start*/ -int get_DSLChannelStats_LastShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "last_showtime_start"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.CurrentDayStart!UBUS:dsl.channel.0/stats//current_day_start*/ -int get_DSLChannelStats_CurrentDayStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "current_day_start"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.QuarterHourStart!UBUS:dsl.channel.0/stats//quarter_hour_start*/ -int get_DSLChannelStats_QuarterHourStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarter_hour_start"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.Total.XTURFECErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ -int get_DSLChannelStatsTotal_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtur_fec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.Total.XTUCFECErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ -int get_DSLChannelStatsTotal_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtuc_fec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.Total.XTURHECErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ -int get_DSLChannelStatsTotal_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtur_hec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.Total.XTUCHECErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ -int get_DSLChannelStatsTotal_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtuc_hec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.Total.XTURCRCErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ -int get_DSLChannelStatsTotal_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtur_crc_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.Total.XTUCCRCErrors!UBUS:dsl.channel.0/stats//total.xtur_fec_errors*/ -int get_DSLChannelStatsTotal_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "total", "xtuc_crc_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.Showtime.XTURFECErrors!UBUS:dsl.channel.0/stats//showtime.xtur_fec_errors*/ -int get_DSLChannelStatsShowtime_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtur_fec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.Showtime.XTUCFECErrors!UBUS:dsl.channel.0/stats//showtime.xtuc_fec_errors*/ -int get_DSLChannelStatsShowtime_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtuc_fec_errors"); - return 0;} - -/*#Device.DSL.Channel.{i}.Stats.Showtime.XTURHECErrors!UBUS:dsl.channel.0/stats//showtime.xtur_hec_errors*/ -int get_DSLChannelStatsShowtime_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtur_hec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.Showtime.XTUCHECErrors!UBUS:dsl.channel.0/stats//showtime.xtuc_hec_errors*/ -int get_DSLChannelStatsShowtime_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtuc_hec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.Showtime.XTURCRCErrors!UBUS:dsl.channel.0/stats//showtime.xtur_crc_errors*/ -int get_DSLChannelStatsShowtime_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtur_crc_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.Showtime.XTUCCRCErrors!UBUS:dsl.channel.0/stats//showtime.xtuc_crc_errors*/ -int get_DSLChannelStatsShowtime_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "showtime", "xtuc_crc_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTURFECErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtur_fec_errors*/ -int get_DSLChannelStatsLastShowtime_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtur_fec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTUCFECErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtuc_fec_errors*/ -int get_DSLChannelStatsLastShowtime_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtuc_fec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTURHECErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtur_hec_errors*/ -int get_DSLChannelStatsLastShowtime_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtur_hec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTUCHECErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtuc_hec_errors*/ -int get_DSLChannelStatsLastShowtime_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtuc_hec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTURCRCErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtur_crc_errors*/ -int get_DSLChannelStatsLastShowtime_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtur_crc_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.LastShowtime.XTUCCRCErrors!UBUS:dsl.channel.0/stats//lastshowtime.xtuc_crc_errors*/ -int get_DSLChannelStatsLastShowtime_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "lastshowtime", "xtuc_crc_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTURFECErrors!UBUS:dsl.channel.0/stats//currentday.xtur_fec_errors*/ -int get_DSLChannelStatsCurrentDay_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtur_fec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTUCFECErrors!UBUS:dsl.channel.0/stats//currentday.xtuc_fec_errors*/ -int get_DSLChannelStatsCurrentDay_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtuc_fec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTURHECErrors!UBUS:dsl.channel.0/stats//currentday.xtur_hec_errors*/ -int get_DSLChannelStatsCurrentDay_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtur_hec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTUCHECErrors!UBUS:dsl.channel.0/stats//currentday.xtuc_hec_errors*/ -int get_DSLChannelStatsCurrentDay_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtuc_hec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTURCRCErrors!UBUS:dsl.channel.0/stats//currentday.xtur_crc_errors*/ -int get_DSLChannelStatsCurrentDay_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtur_crc_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.CurrentDay.XTUCCRCErrors!UBUS:dsl.channel.0/stats//currentday.xtuc_crc_errors*/ -int get_DSLChannelStatsCurrentDay_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "currentday", "xtuc_crc_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTURFECErrors!UBUS:dsl.channel.0/stats//quarterhour.xtur_fec_errors*/ -int get_DSLChannelStatsQuarterHour_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtur_fec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTUCFECErrors!UBUS:dsl.channel.0/stats//quarterhour.xtuc_fec_errors*/ -int get_DSLChannelStatsQuarterHour_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtuc_fec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTURHECErrors!UBUS:dsl.channel.0/stats//quarterhour.xtur_hec_errors*/ -int get_DSLChannelStatsQuarterHour_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtur_hec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTUCHECErrors!UBUS:dsl.channel.0/stats//quarterhour.xtuc_hec_errors*/ -int get_DSLChannelStatsQuarterHour_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtuc_hec_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTURCRCErrors!UBUS:dsl.channel.0/stats//quarterhour.xtur_crc_errors*/ -int get_DSLChannelStatsQuarterHour_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtur_crc_errors"); - return 0; -} - -/*#Device.DSL.Channel.{i}.Stats.QuarterHour.XTUCCRCErrors!UBUS:dsl.channel.0/stats//quarterhour.xtuc_crc_errors*/ -int get_DSLChannelStatsQuarterHour_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_dsl_value_with_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "stats", "quarterhour", "xtuc_crc_errors"); - return 0; -} diff --git a/dmtree/tr181/dsl.h b/dmtree/tr181/dsl.h index 56bedb00..d4790b57 100644 --- a/dmtree/tr181/dsl.h +++ b/dmtree/tr181/dsl.h @@ -13,18 +13,6 @@ #include -struct dsl_line_args -{ - struct uci_section *line_sec; - char *id; -}; - -struct dsl_channel_args -{ - struct uci_section *channel_sec; - char *id; -}; - extern DMOBJ tDSLObj[]; extern DMLEAF tDSLParams[]; extern DMOBJ tDSLLineObj[]; @@ -46,136 +34,4 @@ extern DMLEAF tDSLChannelStatsLastShowtimeParams[]; extern DMLEAF tDSLChannelStatsCurrentDayParams[]; extern DMLEAF tDSLChannelStatsQuarterHourParams[]; -int browseDSLLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDSLChannelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int get_dsl_line_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); -int get_dsl_channel_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); - -int get_DSL_LineNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSL_ChannelNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DSLLine_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DSLLine_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DSLLine_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DSLLine_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DSLLine_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DSLLine_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_FirmwareVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_LinkStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_StandardsSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_XTSE(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_StandardUsed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_XTSUsed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_LineEncoding(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_AllowedProfiles(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_CurrentProfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_PowerManagementState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_SuccessFailureCause(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_UPBOKLERPb(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_RXTHRSHds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_ACTRAMODEds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_ACTRAMODEus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_SNRMROCus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_LastStateTransmittedDownstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_LastStateTransmittedUpstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_US0MASK(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_TRELLISds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_TRELLISus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_ACTSNRMODEds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_ACTSNRMODEus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_LineNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_UpstreamMaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_DownstreamMaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_UpstreamNoiseMargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_DownstreamNoiseMargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_SNRMpbus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_SNRMpbds(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_UpstreamAttenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_DownstreamAttenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_UpstreamPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_DownstreamPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_XTURVendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_XTURCountry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_XTURANSIStd(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_XTURANSIRev(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_XTUCVendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_XTUCCountry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_XTUCANSIStd(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLine_XTUCANSIRev(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStats_TotalStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStats_ShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStats_LastShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStats_CurrentDayStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStats_QuarterHourStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStatsTotal_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStatsTotal_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStatsShowtime_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStatsShowtime_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStatsLastShowtime_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStatsLastShowtime_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStatsCurrentDay_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStatsCurrentDay_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStatsQuarterHour_ErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLLineStatsQuarterHour_SeverelyErroredSecs(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DSLChannel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DSLChannel_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DSLChannel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DSLChannel_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_LinkEncapsulationSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_LinkEncapsulationUsed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_LPATH(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_INTLVDEPTH(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_INTLVBLOCK(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_ActualInterleavingDelay(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_ACTINP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_INPREPORT(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_NFEC(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_RFEC(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_LSYMB(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_UpstreamCurrRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_DownstreamCurrRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_ACTNDR(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannel_ACTINPREIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStats_TotalStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStats_ShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStats_LastShowtimeStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStats_CurrentDayStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStats_QuarterHourStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsTotal_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsTotal_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsTotal_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsTotal_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsTotal_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsTotal_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsShowtime_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsShowtime_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsShowtime_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsShowtime_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsShowtime_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsShowtime_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsLastShowtime_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsLastShowtime_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsLastShowtime_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsLastShowtime_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsLastShowtime_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsLastShowtime_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsCurrentDay_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsCurrentDay_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsCurrentDay_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsCurrentDay_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsCurrentDay_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsCurrentDay_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsQuarterHour_XTURFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsQuarterHour_XTUCFECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsQuarterHour_XTURHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsQuarterHour_XTUCHECErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsQuarterHour_XTURCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DSLChannelStatsQuarterHour_XTUCCRCErrors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - #endif //__DSL_H diff --git a/dmtree/tr181/dynamicdns.c b/dmtree/tr181/dynamicdns.c index 8f315d3d..c34ee6b0 100644 --- a/dmtree/tr181/dynamicdns.c +++ b/dmtree/tr181/dynamicdns.c @@ -11,74 +11,12 @@ #include "dmentry.h" #include "dynamicdns.h" -/* *** Device.DynamicDNS. *** */ -DMOBJ tDynamicDNSObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Client", &DMWRITE, addObjDynamicDNSClient, delObjDynamicDNSClient, NULL, browseDynamicDNSClientInst, NULL, NULL, NULL, tDynamicDNSClientObj, tDynamicDNSClientParams, NULL, BBFDM_BOTH}, -{"Server", &DMWRITE, addObjDynamicDNSServer, delObjDynamicDNSServer, NULL, browseDynamicDNSServerInst, NULL, NULL, NULL, NULL, tDynamicDNSServerParams, get_linker_dynamicdns_server, BBFDM_BOTH}, -{0} -}; - -DMLEAF tDynamicDNSParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"ClientNumberOfEntries", &DMREAD, DMT_UNINT, get_DynamicDNS_ClientNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, -{"ServerNumberOfEntries", &DMREAD, DMT_UNINT, get_DynamicDNS_ServerNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, -{"SupportedServices", &DMREAD, DMT_STRING, get_DynamicDNS_SupportedServices, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.DynamicDNS.Client.{i}. *** */ -DMOBJ tDynamicDNSClientObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Hostname", &DMWRITE, NULL, NULL, NULL, browseDynamicDNSClientHostnameInst, NULL, NULL, NULL, NULL, tDynamicDNSClientHostnameParams, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF tDynamicDNSClientParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_DynamicDNSClient_Enable, set_DynamicDNSClient_Enable, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_DynamicDNSClient_Status, NULL, NULL, NULL, BBFDM_BOTH}, -{"Alias", &DMWRITE, DMT_STRING, get_DynamicDNSClient_Alias, set_DynamicDNSClient_Alias, NULL, NULL, BBFDM_BOTH}, -{"LastError", &DMREAD, DMT_STRING, get_DynamicDNSClient_LastError, NULL, NULL, NULL, BBFDM_BOTH}, -{"Server", &DMWRITE, DMT_STRING, get_DynamicDNSClient_Server, set_DynamicDNSClient_Server, NULL, NULL, BBFDM_BOTH}, -{"Interface", &DMWRITE, DMT_STRING, get_DynamicDNSClient_Interface, set_DynamicDNSClient_Interface, NULL, NULL, BBFDM_BOTH}, -{"Username", &DMWRITE, DMT_STRING, get_DynamicDNSClient_Username, set_DynamicDNSClient_Username, NULL, NULL, BBFDM_BOTH}, -{"Password", &DMWRITE, DMT_STRING, get_DynamicDNSClient_Password, set_DynamicDNSClient_Password, NULL, NULL, BBFDM_BOTH}, -{"HostnameNumberOfEntries", &DMREAD, DMT_UNINT, get_DynamicDNSClient_HostnameNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.DynamicDNS.Client.{i}.Hostname.{i}. *** */ -DMLEAF tDynamicDNSClientHostnameParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_DynamicDNSClientHostname_Enable, set_DynamicDNSClientHostname_Enable, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_DynamicDNSClientHostname_Status, NULL, NULL, NULL, BBFDM_BOTH}, -{"Name", &DMWRITE, DMT_STRING, get_DynamicDNSClientHostname_Name, set_DynamicDNSClientHostname_Name, NULL, NULL, BBFDM_BOTH}, -{"LastUpdate", &DMREAD, DMT_TIME, get_DynamicDNSClientHostname_LastUpdate, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.DynamicDNS.Server.{i}. *** */ -DMLEAF tDynamicDNSServerParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Enable, set_DynamicDNSServer_Enable, NULL, NULL, BBFDM_BOTH}, -{"Name", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Name, set_DynamicDNSServer_Name, NULL, NULL, BBFDM_BOTH}, -{"Alias", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Alias, set_DynamicDNSServer_Alias, NULL, NULL, BBFDM_BOTH}, -{"ServiceName", &DMWRITE, DMT_STRING, get_DynamicDNSServer_ServiceName, set_DynamicDNSServer_ServiceName, NULL, NULL, BBFDM_BOTH}, -{"ServerAddress", &DMWRITE, DMT_STRING, get_DynamicDNSServer_ServerAddress, set_DynamicDNSServer_ServerAddress, NULL, NULL, BBFDM_BOTH}, -{"ServerPort", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_ServerPort, set_DynamicDNSServer_ServerPort, NULL, NULL, BBFDM_BOTH}, -{"SupportedProtocols", &DMREAD, DMT_STRING, get_DynamicDNSServer_SupportedProtocols, NULL, NULL, NULL, BBFDM_BOTH}, -{"Protocol", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Protocol, set_DynamicDNSServer_Protocol, NULL, NULL, BBFDM_BOTH}, -{"CheckInterval", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_CheckInterval, set_DynamicDNSServer_CheckInterval, NULL, NULL, BBFDM_BOTH}, -{"RetryInterval", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_RetryInterval, set_DynamicDNSServer_RetryInterval, NULL, NULL, BBFDM_BOTH}, -{"MaxRetries", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_MaxRetries, set_DynamicDNSServer_MaxRetries, NULL, NULL, BBFDM_BOTH}, -{0} -}; +#define DDNS_PROVIDERS_FILE "/etc/ddns/services" /************************************************************************** * LINKER ***************************************************************************/ -int get_linker_dynamicdns_server(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +static int get_linker_dynamicdns_server(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { char *service_name; if (data) { @@ -95,7 +33,7 @@ int get_linker_dynamicdns_server(char *refparam, struct dmctx *dmctx, void *data * ENTRY METHOD *************************************************************/ /*#Device.DynamicDNS.Client.{i}.!UCI:ddns/service/dmmap_ddns*/ -int browseDynamicDNSClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseDynamicDNSClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *inst = NULL, *inst_last = NULL; struct dmmap_dup *p; @@ -185,7 +123,7 @@ static int dmmap_synchronizeDynamicDNSServer(struct dmctx *dmctx, DMNODE *parent } /*#Device.DynamicDNS.Server.{i}.!UCI:ddns/service/dmmap_ddns*/ -int browseDynamicDNSServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseDynamicDNSServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *inst = NULL, *inst_last = NULL; struct uci_section *s = NULL; @@ -200,7 +138,7 @@ int browseDynamicDNSServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *p return 0; } -int browseDynamicDNSClientHostnameInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseDynamicDNSClientHostnameInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { DM_LINK_INST_OBJ(dmctx, parent_node, prev_data, "1"); return 0; @@ -209,7 +147,7 @@ int browseDynamicDNSClientHostnameInst(struct dmctx *dmctx, DMNODE *parent_node, /************************************************************* * ADD & DEL OBJ *************************************************************/ -int addObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char **instance) +static int addObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char **instance) { char inst[8], *last_inst, *value, *v, *s_name; struct uci_section *dmmap = NULL, *s = NULL; @@ -238,7 +176,7 @@ int addObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char * return 0; } -int delObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +static int delObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; int found = 0; @@ -272,7 +210,7 @@ int delObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char * return 0; } -int addObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char **instance) +static int addObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char **instance) { char inst[8], *last_inst, *value, *v, *s_name; struct uci_section *dmmap = NULL, *s = NULL; @@ -301,7 +239,7 @@ int addObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char * return 0; } -int delObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +static int delObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL, *ss = NULL, *stmp = NULL, *dmmap_section= NULL; int found = 0; @@ -340,7 +278,7 @@ int delObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char * /************************************************************* * GET & SET PARAM *************************************************************/ -int get_DynamicDNS_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNS_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; int cnt = 0; @@ -352,7 +290,7 @@ int get_DynamicDNS_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void return 0; } -int get_DynamicDNS_ServerNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNS_ServerNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; int cnt = 0; @@ -365,7 +303,7 @@ int get_DynamicDNS_ServerNumberOfEntries(char *refparam, struct dmctx *ctx, void return 0; } -int get_DynamicDNS_SupportedServices(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNS_SupportedServices(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { FILE *fp = NULL; char line[256] = "", buf[1024] = "", buf_tmp[1024] = "", *pch = NULL, *spch = NULL; @@ -394,7 +332,7 @@ int get_DynamicDNS_SupportedServices(char *refparam, struct dmctx *ctx, void *da } /*#Device.DynamicDNS.Client.{i}.Enable!UCI:ddns/service,@i-1/enabled*/ -int get_DynamicDNSClient_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClient_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value); if (*value[0] == '\0') @@ -402,7 +340,7 @@ int get_DynamicDNSClient_Enable(char *refparam, struct dmctx *ctx, void *data, c return 0; } -int set_DynamicDNSClient_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSClient_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -420,7 +358,7 @@ int set_DynamicDNSClient_Enable(char *refparam, struct dmctx *ctx, void *data, c } /*#Device.DynamicDNS.Client.{i}.Status!UCI:ddns/service,@i-1/enabled*/ -int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { FILE* fp = NULL; char buf[512] = "", path[64] = "", status[32] = "", *enable, *logdir = NULL; @@ -454,7 +392,7 @@ int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void *data, c return 0; } -int get_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *dmmap_section = NULL; @@ -464,7 +402,7 @@ int get_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, ch return 0; } -int set_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *dmmap_section = NULL; @@ -482,7 +420,7 @@ int set_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, ch return 0; } -int get_DynamicDNSClient_LastError(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClient_LastError(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { FILE* fp = NULL; char buf[512] = "", path[64] = "", status[32] = "", *enable, *logdir = NULL; @@ -519,7 +457,7 @@ int get_DynamicDNSClient_LastError(char *refparam, struct dmctx *ctx, void *data } /*#Device.DynamicDNS.Client.{i}.Server!UCI:ddns/service,@i-1/service_name*/ -int get_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *service_name; dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name); @@ -529,7 +467,7 @@ int get_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, c return 0; } -int set_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker = NULL; @@ -550,7 +488,7 @@ int set_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, c } /*#Device.DynamicDNS.Client.{i}.Interface!UCI:ddns/service,@i-1/interface*/ -int get_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *interface; dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface); @@ -560,7 +498,7 @@ int get_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data return 0; } -int set_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker = NULL; @@ -581,13 +519,13 @@ int set_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data } /*#Device.DynamicDNS.Client.{i}.Username!UCI:ddns/service,@i-1/username*/ -int get_DynamicDNSClient_Username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClient_Username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "username", value); return 0; } -int set_DynamicDNSClient_Username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSClient_Username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -602,13 +540,13 @@ int set_DynamicDNSClient_Username(char *refparam, struct dmctx *ctx, void *data, } /*#Device.DynamicDNS.Client.{i}.Password!UCI:ddns/service,@i-1/password*/ -int get_DynamicDNSClient_Password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClient_Password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ""; return 0; } -int set_DynamicDNSClient_Password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSClient_Password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -622,14 +560,14 @@ int set_DynamicDNSClient_Password(char *refparam, struct dmctx *ctx, void *data, return 0; } -int get_DynamicDNSClient_HostnameNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClient_HostnameNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "1"; return 0; } /*#Device.DynamicDNS.Client.{i}.Hostname.{i}.Enable!UCI:ddns/service,@i-1/enabled*/ -int get_DynamicDNSClientHostname_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClientHostname_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value); if (*value[0] == '\0') @@ -637,7 +575,7 @@ int get_DynamicDNSClientHostname_Enable(char *refparam, struct dmctx *ctx, void return 0; } -int set_DynamicDNSClientHostname_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSClientHostname_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -655,7 +593,7 @@ int set_DynamicDNSClientHostname_Enable(char *refparam, struct dmctx *ctx, void } /*#Device.DynamicDNS.Client.{i}.Hostname.{i}.Status!UCI:ddns/service,@i-1/enabled*/ -int get_DynamicDNSClientHostname_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClientHostname_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { FILE* fp = NULL; char buf[512] = "", path[64] = "", status[32] = "", *enable, *logdir = NULL; @@ -688,13 +626,13 @@ int get_DynamicDNSClientHostname_Status(char *refparam, struct dmctx *ctx, void } /*#Device.DynamicDNS.Client.{i}.Hostname.{i}.Name!UCI:ddns/service,@i-1/domain*/ -int get_DynamicDNSClientHostname_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClientHostname_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "domain", value); return 0; } -int set_DynamicDNSClientHostname_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSClientHostname_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -709,7 +647,7 @@ int set_DynamicDNSClientHostname_Name(char *refparam, struct dmctx *ctx, void *d return 0; } -int get_DynamicDNSClientHostname_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSClientHostname_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct tm *ts; time_t epoch_time, now = time(NULL); @@ -749,7 +687,7 @@ int get_DynamicDNSClientHostname_LastUpdate(char *refparam, struct dmctx *ctx, v } /*#Device.DynamicDNS.Server.{i}.Enable!UCI:ddns/service,@i-1/enabled*/ -int get_DynamicDNSServer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSServer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value); if (*value[0] == '\0') @@ -757,7 +695,7 @@ int get_DynamicDNSServer_Enable(char *refparam, struct dmctx *ctx, void *data, c return 0; } -int set_DynamicDNSServer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSServer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; char *service_name; @@ -778,13 +716,13 @@ int set_DynamicDNSServer_Enable(char *refparam, struct dmctx *ctx, void *data, c return 0; } -int get_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", value); return 0; } -int set_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; char *service_name; @@ -806,13 +744,13 @@ int set_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *data, cha return 0; } -int get_DynamicDNSServer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSServer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "serveralias", value); return 0; } -int set_DynamicDNSServer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSServer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -827,13 +765,13 @@ int set_DynamicDNSServer_Alias(char *refparam, struct dmctx *ctx, void *data, ch } /*#Device.DynamicDNS.Server.{i}.ServiceName!UCI:ddns/service,@i-1/service_name*/ -int get_DynamicDNSServer_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSServer_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", value); return 0; } -int set_DynamicDNSServer_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSServer_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; char *service_name; @@ -855,7 +793,7 @@ int set_DynamicDNSServer_ServiceName(char *refparam, struct dmctx *ctx, void *da } /*#Device.DynamicDNS.Server.{i}.ServerAddress!UCI:ddns/service,@i-1/dns_server*/ -int get_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *dns_server; @@ -871,7 +809,7 @@ int get_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void * return 0; } -int set_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; char new[64], *dns_server, *service_name; @@ -913,7 +851,7 @@ int set_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void * } /*#Device.DynamicDNS.Server.{i}.ServerPort!UCI:ddns/service,@i-1/dns_server*/ -int get_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *dns_server; *value = "0"; @@ -928,7 +866,7 @@ int get_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *dat return 0; } -int set_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; char new[64], *dns_server, *service_name; @@ -973,14 +911,14 @@ int set_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *dat return 0; } -int get_DynamicDNSServer_SupportedProtocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSServer_SupportedProtocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "HTTP,HTTPS"; return 0; } /*#Device.DynamicDNS.Server.{i}.Protocol!UCI:ddns/service,@i-1/use_https*/ -int get_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "use_https", value); if (*value[0] == '\0' || strcmp(*value, "0") == 0) @@ -990,7 +928,7 @@ int get_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void *data, return 0; } -int set_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; char *service_name; @@ -1018,7 +956,7 @@ int set_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void *data, } /*#Device.DynamicDNS.Server.{i}.CheckInterval!UCI:ddns/service,@i-1/check_interval*/ -int get_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "check_interval", value); if (*value[0] == '\0') @@ -1026,7 +964,7 @@ int get_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, void * return 0; } -int set_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; char buf[16] = "", *check_unit, *service_name; @@ -1058,7 +996,7 @@ int set_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, void * } /*#Device.DynamicDNS.Server.{i}.RetryInterval!UCI:ddns/service,@i-1/retry_interval*/ -int get_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "retry_interval", value); if (*value[0] == '\0') @@ -1066,7 +1004,7 @@ int get_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, void * return 0; } -int set_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; char buf[16] = "", *retry_unit, *service_name; @@ -1097,7 +1035,7 @@ int set_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, void * } /*#Device.DynamicDNS.Server.{i}.MaxRetries!UCI:ddns/service,@i-1/retry_count*/ -int get_DynamicDNSServer_MaxRetries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_DynamicDNSServer_MaxRetries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "retry_count", value); if (*value[0] == '\0') @@ -1105,7 +1043,7 @@ int get_DynamicDNSServer_MaxRetries(char *refparam, struct dmctx *ctx, void *dat return 0; } -int set_DynamicDNSServer_MaxRetries(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_DynamicDNSServer_MaxRetries(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; char *service_name; @@ -1126,3 +1064,66 @@ int set_DynamicDNSServer_MaxRetries(char *refparam, struct dmctx *ctx, void *dat return 0; } +/* *** Device.DynamicDNS. *** */ +DMOBJ tDynamicDNSObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Client", &DMWRITE, addObjDynamicDNSClient, delObjDynamicDNSClient, NULL, browseDynamicDNSClientInst, NULL, NULL, NULL, tDynamicDNSClientObj, tDynamicDNSClientParams, NULL, BBFDM_BOTH}, +{"Server", &DMWRITE, addObjDynamicDNSServer, delObjDynamicDNSServer, NULL, browseDynamicDNSServerInst, NULL, NULL, NULL, NULL, tDynamicDNSServerParams, get_linker_dynamicdns_server, BBFDM_BOTH}, +{0} +}; + +DMLEAF tDynamicDNSParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"ClientNumberOfEntries", &DMREAD, DMT_UNINT, get_DynamicDNS_ClientNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{"ServerNumberOfEntries", &DMREAD, DMT_UNINT, get_DynamicDNS_ServerNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{"SupportedServices", &DMREAD, DMT_STRING, get_DynamicDNS_SupportedServices, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.DynamicDNS.Client.{i}. *** */ +DMOBJ tDynamicDNSClientObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Hostname", &DMWRITE, NULL, NULL, NULL, browseDynamicDNSClientHostnameInst, NULL, NULL, NULL, NULL, tDynamicDNSClientHostnameParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tDynamicDNSClientParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_DynamicDNSClient_Enable, set_DynamicDNSClient_Enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_DynamicDNSClient_Status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Alias", &DMWRITE, DMT_STRING, get_DynamicDNSClient_Alias, set_DynamicDNSClient_Alias, NULL, NULL, BBFDM_BOTH}, +{"LastError", &DMREAD, DMT_STRING, get_DynamicDNSClient_LastError, NULL, NULL, NULL, BBFDM_BOTH}, +{"Server", &DMWRITE, DMT_STRING, get_DynamicDNSClient_Server, set_DynamicDNSClient_Server, NULL, NULL, BBFDM_BOTH}, +{"Interface", &DMWRITE, DMT_STRING, get_DynamicDNSClient_Interface, set_DynamicDNSClient_Interface, NULL, NULL, BBFDM_BOTH}, +{"Username", &DMWRITE, DMT_STRING, get_DynamicDNSClient_Username, set_DynamicDNSClient_Username, NULL, NULL, BBFDM_BOTH}, +{"Password", &DMWRITE, DMT_STRING, get_DynamicDNSClient_Password, set_DynamicDNSClient_Password, NULL, NULL, BBFDM_BOTH}, +{"HostnameNumberOfEntries", &DMREAD, DMT_UNINT, get_DynamicDNSClient_HostnameNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.DynamicDNS.Client.{i}.Hostname.{i}. *** */ +DMLEAF tDynamicDNSClientHostnameParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_DynamicDNSClientHostname_Enable, set_DynamicDNSClientHostname_Enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_DynamicDNSClientHostname_Status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Name", &DMWRITE, DMT_STRING, get_DynamicDNSClientHostname_Name, set_DynamicDNSClientHostname_Name, NULL, NULL, BBFDM_BOTH}, +{"LastUpdate", &DMREAD, DMT_TIME, get_DynamicDNSClientHostname_LastUpdate, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.DynamicDNS.Server.{i}. *** */ +DMLEAF tDynamicDNSServerParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Enable, set_DynamicDNSServer_Enable, NULL, NULL, BBFDM_BOTH}, +{"Name", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Name, set_DynamicDNSServer_Name, NULL, NULL, BBFDM_BOTH}, +{"Alias", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Alias, set_DynamicDNSServer_Alias, NULL, NULL, BBFDM_BOTH}, +{"ServiceName", &DMWRITE, DMT_STRING, get_DynamicDNSServer_ServiceName, set_DynamicDNSServer_ServiceName, NULL, NULL, BBFDM_BOTH}, +{"ServerAddress", &DMWRITE, DMT_STRING, get_DynamicDNSServer_ServerAddress, set_DynamicDNSServer_ServerAddress, NULL, NULL, BBFDM_BOTH}, +{"ServerPort", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_ServerPort, set_DynamicDNSServer_ServerPort, NULL, NULL, BBFDM_BOTH}, +{"SupportedProtocols", &DMREAD, DMT_STRING, get_DynamicDNSServer_SupportedProtocols, NULL, NULL, NULL, BBFDM_BOTH}, +{"Protocol", &DMWRITE, DMT_STRING, get_DynamicDNSServer_Protocol, set_DynamicDNSServer_Protocol, NULL, NULL, BBFDM_BOTH}, +{"CheckInterval", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_CheckInterval, set_DynamicDNSServer_CheckInterval, NULL, NULL, BBFDM_BOTH}, +{"RetryInterval", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_RetryInterval, set_DynamicDNSServer_RetryInterval, NULL, NULL, BBFDM_BOTH}, +{"MaxRetries", &DMWRITE, DMT_UNINT, get_DynamicDNSServer_MaxRetries, set_DynamicDNSServer_MaxRetries, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/dynamicdns.h b/dmtree/tr181/dynamicdns.h index 64dd6b39..f568be1f 100644 --- a/dmtree/tr181/dynamicdns.h +++ b/dmtree/tr181/dynamicdns.h @@ -20,63 +20,5 @@ extern DMLEAF tDynamicDNSClientParams[]; extern DMLEAF tDynamicDNSClientHostnameParams[]; extern DMLEAF tDynamicDNSServerParams[]; -#define DDNS_PROVIDERS_FILE "/etc/ddns/services" - -int browseDynamicDNSClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDynamicDNSServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseDynamicDNSClientHostnameInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int addObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int get_linker_dynamicdns_server(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); - -int get_DynamicDNS_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DynamicDNS_ServerNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DynamicDNS_SupportedServices(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DynamicDNSClient_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSClient_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSClient_LastError(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSClient_Username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSClient_Username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSClient_Password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSClient_Password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSClient_HostnameNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DynamicDNSClientHostname_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSClientHostname_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSClientHostname_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DynamicDNSClientHostname_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSClientHostname_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSClientHostname_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DynamicDNSServer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSServer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSServer_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSServer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSServer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSServer_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSServer_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSServer_SupportedProtocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_DynamicDNSServer_MaxRetries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_DynamicDNSServer_MaxRetries(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif //__DYNAMICDNS_H diff --git a/dmtree/tr181/ethernet.c b/dmtree/tr181/ethernet.c index 757a5dc1..5953313c 100644 --- a/dmtree/tr181/ethernet.c +++ b/dmtree/tr181/ethernet.c @@ -13,7 +13,1247 @@ #include "dmentry.h" #include "ethernet.h" -char *wan_ifname = NULL; +struct eth_port_args +{ + struct uci_section *eth_port_sec; + char *ifname; +}; + +static char *wan_ifname = NULL; + +/************************************************************* +* INIT +**************************************************************/ +static inline int init_eth_port(struct eth_port_args *args, struct uci_section *s, char *ifname) +{ + args->eth_port_sec = s; + args->ifname = ifname; + return 0; +} + +/************************************************************* +* COMMON Functions +**************************************************************/ +static int eth_iface_sysfs(const struct dm_args *args, const char *name, char **value) +{ + char *device; + + dmuci_get_value_by_section_string(args->section, "device", &device); + return get_net_device_sysfs(device, name, value); +} + +static int eth_port_sysfs(const struct eth_port_args *args, const char *name, char **value) +{ + return get_net_device_sysfs(args->ifname, name, value); +} + +static int is_mac_exist(char *macaddr) +{ + struct uci_section *s = NULL; + char *mac; + + uci_path_foreach_sections(bbfdm, DMMAP, "link", s) { + dmuci_get_value_by_section_string(s, "mac", &mac); + if (strcmp(mac, macaddr) == 0) + return 1; + } + return 0; +} + +static void create_link(char *ifname) +{ + char *macaddr, *v, *device; + struct uci_section *dmmap = NULL; + + macaddr = get_macaddr(ifname); + if (macaddr[0] == '\0') + return; + + device = get_device(ifname); + if (device[0] == '\0') + return; + + /* Interfaces might share the same mac address */ + if (is_mac_exist(macaddr)) + return; + + dmuci_add_section_bbfdm(DMMAP, "link", &dmmap, &v); + dmuci_set_value_by_section(dmmap, "mac", macaddr); + dmuci_set_value_by_section(dmmap, "device", device); + dmuci_set_value_by_section(dmmap, "section_name", ifname); +} + +static int dmmap_synchronizeEthernetLink(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *s = NULL; + char *type, *ifname; + + uci_foreach_sections("network", "interface", s) { + dmuci_get_value_by_section_string(s, "type", &type); + if (strcmp(type, "alias") == 0 || strcmp(section_name(s), "loopback") == 0) + continue; + + dmuci_get_value_by_section_string(s, "ifname", &ifname); + if (*ifname == '\0' || *ifname == '@') + continue; + + create_link(section_name(s)); + } + return 0; +} + +/************************************************************* +* ENTRY METHOD +**************************************************************/ +/*#Device.Ethernet.Interface.{i}.!UCI:ports/ethport/dmmap_ports*/ +static int browseEthernetInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *int_num = NULL, *int_num_last = NULL, *ifname; + struct eth_port_args curr_eth_port_args = {0}; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("ports", "ethport", "dmmap_ports", &dup_list); + dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_ifname); + list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); + if (strcmp(ifname, wan_ifname) == 0) { + if(strchr(ifname, '.')== NULL) + dmasprintf(&ifname, "%s.1", ifname); + } + init_eth_port(&curr_eth_port_args, p->config_section, ifname); + int_num = handle_update_instance(1, dmctx, &int_num_last, update_instance_alias, 3, p->dmmap_section, "eth_port_instance", "eth_port_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_eth_port_args, int_num) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int browseEthernetLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct dm_args args = {0}; + struct uci_section *s = NULL; + char *id_last = NULL, *id = NULL; + + dmmap_synchronizeEthernetLink(dmctx, NULL, NULL, NULL); + uci_path_foreach_sections(bbfdm, DMMAP, "link", s) { + args.section = s; + id = handle_update_instance(1, dmctx, &id_last, update_instance_alias_bbfdm, 3, s, "link_instance", "link_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&args, id) == DM_STOP) { + break; + } + } + return 0; +} + +/*#Device.Ethernet.VLANTermination.{i}.!UCI:network/device/dmmap_network*/ +static int browseEthernetVLANTerminationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *vlan_term = NULL, *vlan_term_last = NULL, *type= NULL, *vlan_method= NULL; + struct dm_args curr_vlan_term_args = {0}; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("network", "device", "dmmap_network", &dup_list); + list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "type", &type); + dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); + if ((strcmp(vlan_method, "2") != 0 && strcmp(vlan_method, "1") != 0) || (strcmp(vlan_method, "1") == 0 && strcmp(type, "untagged") == 0) ) + continue; + curr_vlan_term_args.section = p->config_section; + if(strcmp(vlan_method, "2") == 0) + vlan_term = handle_update_instance(1, dmctx, &vlan_term_last, update_instance_alias, 3, p->dmmap_section, "all_vlan_term_instance", "all_vlan_term_alias"); + else + vlan_term = handle_update_instance(1, dmctx, &vlan_term_last, update_instance_alias, 3, p->dmmap_section, "only_tagged_vlan_term_instance", "vlan_term_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_vlan_term_args, vlan_term) == DM_STOP) + break; + } + + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +/************************************************************* +* LINKER +**************************************************************/ +static int get_linker_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct eth_port_args *)data)->ifname) { + *linker = ((struct eth_port_args *)data)->ifname; + return 0; + } else { + *linker = ""; + return 0; + } +} + +static int get_linker_link(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "section_name", linker); + return 0; +} + +static int get_linker_vlan_term(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if(((struct dm_args *)data)->section) { + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", linker); + return 0; + } else { + *linker = ""; + return 0; + } +} + +/************************************************************* +* ADD & DEL OBJ +**************************************************************/ +static int addObjEthernetLink(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *inst, *v; + struct uci_section *dmmap_network= NULL; + + inst = get_last_instance_bbfdm(DMMAP, "link", "link_instance"); + + dmuci_add_section_bbfdm(DMMAP, "link", &dmmap_network, &v); + *instance = update_instance_bbfdm(dmmap_network, inst, "link_instance"); + return 0; +} + +static int delObjEthernetLink(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + char *sect_name= NULL; + struct uci_section *s = NULL; + switch (del_action) { + case DEL_INST: + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "section_name", §_name); + get_config_section_of_dmmap_section("network", "interface", sect_name, &s); + if(!s) { + dmuci_delete_by_section(((struct dm_args *)data)->section, NULL, NULL); + return 0; + } + return FAULT_9005; + break; + case DEL_ALL: + return FAULT_9005; + break; + } + + return 0; +} + +static int addObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *inst, *v, *eth_wan, *vid, *name, *vlan_name, *vlan_method = NULL; + struct uci_section *dmmap_network= NULL; + + check_create_dmmap_package("dmmap_network"); + dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); + if(strcmp(vlan_method, "2") == 0) + inst = get_vlan_last_instance_bbfdm("dmmap_network", "device", "all_vlan_term_instance", vlan_method); + else + inst = get_vlan_last_instance_bbfdm("dmmap_network", "device", "only_tagged_vlan_term_instance", vlan_method); + + dmuci_get_option_value_string("ports", "WAN", "ifname", ð_wan); + dmasprintf(&vid, "%d", inst?atoi(inst)+4:4); + dmasprintf(&vlan_name, "vlan_%s", vid); + dmuci_set_value("network", vlan_name, "", "device"); + dmuci_set_value("network", vlan_name, "ifname", eth_wan); + dmuci_set_value("network", vlan_name, "type", "8021q"); + dmuci_set_value("network", vlan_name, "vid", vid); + dmasprintf(&name, "%s.%s", eth_wan, vid); + dmuci_set_value("network", vlan_name, "name", name); + + dmuci_add_section_bbfdm("dmmap_network", "device", &dmmap_network, &v); + dmuci_set_value_by_section(dmmap_network, "section_name", vlan_name); + if(strcmp(vlan_method, "2") == 0) + *instance = update_instance_bbfdm(dmmap_network, inst, "all_vlan_term_instance"); + else + *instance = update_instance_bbfdm(dmmap_network, inst, "only_tagged_vlan_term_instance"); + + return 0; +} + +static int delObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; + char *vlan_method = NULL; + + switch (del_action) { + case DEL_INST: + dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); + if(is_section_unnamed(section_name(((struct dm_args *)data)->section))) { + LIST_HEAD(dup_list); + if(strcmp(vlan_method, "2") == 0) { + delete_sections_save_next_sections("dmmap_network", "device", "all_vlan_term_instance", section_name((struct uci_section *)data), atoi(instance), &dup_list); + update_dmmap_sections(&dup_list, "all_vlan_term_instance", "dmmap_network", "device"); + } + else { + delete_sections_save_next_sections("dmmap_network", "device", "only_tagged_vlan_term_instance", section_name((struct uci_section *)data), atoi(instance), &dup_list); + update_dmmap_sections(&dup_list, "only_tagged_vlan_term_instance", "dmmap_network", "device"); + } + dmuci_delete_by_section_unnamed(((struct dm_args *)data)->section, NULL, NULL); + } else { + get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name(((struct dm_args *)data)->section), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); + dmuci_delete_by_section(((struct dm_args *)data)->section, NULL, NULL); + } + break; + case DEL_ALL: + uci_foreach_sections("network", "device", s) { + if (found != 0){ + get_dmmap_section_of_config_section("dmmap_network", "device", section_name(s), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL){ + get_dmmap_section_of_config_section("dmmap_network", "device", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + break; + } + return 0; +} + +/************************************************************* +* GET & SET PARAM +**************************************************************/ +/*#Device.Ethernet.InterfaceNumberOfEntries!UCI:ports/ethport/*/ +static int get_Ethernet_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_foreach_sections("ports", "ethport", s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +static int get_Ethernet_LinkNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + dmmap_synchronizeEthernetLink(ctx, NULL, NULL, NULL); + uci_path_foreach_sections(bbfdm, DMMAP, "link", s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +/*#Device.Ethernet.VLANTerminationNumberOfEntries!UCI:network/device/*/ +static int get_Ethernet_VLANTerminationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *type, *vlan_method; + int cnt = 0; + + uci_foreach_sections("network", "device", s) { + dmuci_get_value_by_section_string(s, "type", &type); + dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); + if ((strcmp(vlan_method, "2") != 0 && strcmp(vlan_method, "1") != 0) || (strcmp(vlan_method, "1") == 0 && strcmp(type, "untagged") == 0)) + continue; + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +/*#Device.Ethernet.Interface.{i}.Enable!UBUS:network.device/status/name,@Name/carrier*/ +static int get_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + char *ifname; + + if (strstr(((struct eth_port_args *)data)->ifname, wan_ifname)) { + ifname = dmstrdup(wan_ifname); + } else + ifname = dmstrdup(((struct eth_port_args *)data)->ifname); + + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ifname, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "carrier"); + dmfree(ifname); + return 0; +} + +static int set_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + char *ifname; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if (strstr(((struct eth_port_args *)data)->ifname, wan_ifname)) + ifname = dmstrdup(wan_ifname); + else + ifname = dmstrdup(((struct eth_port_args *)data)->ifname); + + DMCMD("ethctl", 3, ifname, "phy-power", b ? "up" : "down"); + dmfree(ifname); + return 0; + } + return 0; +} + +/*#Device.Ethernet.Interface.{i}.Status!UBUS:network.device/status/name,@Name/carrier*/ +static int get_EthernetInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + bool b; + + get_EthernetInterface_Enable(refparam, ctx, data, instance, value); + string_to_bool(*value, &b); + *value = b ? "Up" : "Down"; + return 0; +} + +static int get_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_ports", "ethport", section_name(((struct eth_port_args *)data)->eth_port_sec), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "eth_port_alias", value); + if (*value == NULL || strlen(*value) < 1) + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "name", value); + return 0; +} + +static int set_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_ports", "ethport", section_name(((struct eth_port_args *)data)->eth_port_sec), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "eth_port_alias", value); + return 0; + } + return 0; +} + +/*#Device.Ethernet.Interface.{i}.Name!UCI:ports/ethport,@i-1/name*/ +static int get_EthernetInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "name", value); + return 0; +} + +/*#Device.Ethernet.Interface.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ +static int get_EthernetInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + struct uci_section *s = NULL; + char *ifname; + + *value ="0"; + uci_foreach_sections("network", "interface", s) { + dmuci_get_value_by_section_string(s, "ifname", &ifname); + if (strstr(ifname, ((struct eth_port_args *)data)->ifname)) { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); + DM_ASSERT(res, *value = "0"); + *value = dmjson_get_value(res, 1, "uptime"); + if((*value)[0] == '\0') + *value = "0"; + break; + } + } + return 0; +} + +static int get_EthernetInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ""; + return 0; +} + +static int set_EthernetInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_EthernetInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *ifname; + dmuci_get_option_value_string("network", "lan", "ifname", &ifname); + if (strstr(ifname, ((struct eth_port_args *)data)->ifname)) + *value = "1"; + else + *value = "0"; + return 0; +} + +/*#Device.Ethernet.Interface.{i}.MACAddress!UBUS:network.device/status/name,@Name/macaddr*/ +static int get_EthernetInterface_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_port_sysfs(data, "address", value); +} + +/*#Device.Ethernet.Interface.{i}.MaxBitRate!UCI:ports/ethport,@i-1/speed*/ +static int get_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *pch, *spch, *speed; + + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &speed); + if (speed[0] == '\0' || strcmp(speed, "disabled") == 0 ) + *value = "0"; + else { + if (strcmp(speed, "auto") == 0) + *value = "-1"; + else { + pch = strtok_r(speed, "FHfh", &spch); + *value = dmstrdup(pch); + } + } + return 0; +} + +static int set_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *duplex, *val = "", *p = ""; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (strcasecmp(value, "0") == 0 ) + dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "disabled"); + else if (strcmp(value, "-1") == 0) + dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "auto"); + else { + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &duplex); + if (strcmp(duplex, "auto") == 0 || strcmp(duplex, "disabled") == 0) + p = "FDAUTO"; + else + p = strchr(duplex, 'F') ? strchr(duplex, 'F') : strchr(duplex, 'H'); + if (p) dmastrcat(&val, value, p); + dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", val); + dmfree(val); + } + return 0; + } + return 0; +} + +/*#Device.Ethernet.Interface.{i}.CurrentBitRate!UBUS:network.device/status/name,@Name/speed*/ +static int get_EthernetInterface_CurrentBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + char *speed, *pch; + + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res); + DM_ASSERT(res, *value = "0"); + speed = dmjson_get_value(res, 1, "speed"); + if(speed[0] != '\0') { + pch = strtok(speed, "FHfh"); + *value = dmstrdup(pch); + } else + *value = "0"; + return 0; +} + +/*#Device.Ethernet.Interface.{i}.DuplexMode!UCI:ports/status/ethport,@i-1/speed*/ +static int get_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", value); + if (*value[0] == '\0') + *value = ""; + else if (strcmp(*value, "auto") == 0) + *value = "Auto"; + else { + if (strchr(*value, 'F')) + *value = "Full"; + else if (strchr(*value, 'H')) + *value = "Half"; + else + *value = ""; + } + return 0; +} + +static int set_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *m, *spch, *rate, *val = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, DuplexMode, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (strcasecmp(value, "auto") == 0) { + dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "auto"); + return 0; + } + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &m); + m = dmstrdup(m); + rate = m; + if (strcmp(rate, "auto") == 0) + rate = "100"; + else { + strtok_r(rate, "FHfh", &spch); + } + if (strcasecmp(value, "full") == 0) + dmastrcat(&val, rate, "FD"); + else if (strcasecmp(value, "half") == 0) + dmastrcat(&val, rate, "HD"); + else { + dmfree(m); + return 0; + } + dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", val); + dmfree(m); + dmfree(val); + return 0; + } + return 0; +} + +static int get_EthernetInterface_EEECapability(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +/*#Device.Ethernet.Interface.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/ +static int get_EthernetInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_port_sysfs(data, "statistics/tx_bytes", value); +} + +/*#Device.Ethernet.Interface.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/ +static int get_EthernetInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_port_sysfs(data, "statistics/rx_bytes", value); +} + +/*#Device.Ethernet.Interface.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/ +static int get_EthernetInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_port_sysfs(data, "statistics/tx_packets", value); +} + +/*#Device.Ethernet.Interface.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/ +static int get_EthernetInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_port_sysfs(data, "statistics/rx_packets", value); +} + +/*#Device.Ethernet.Interface.{i}.Stats.ErrorsSent!UBUS:network.device/status/name,@Name/statistics.tx_errors*/ +static int get_EthernetInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_port_sysfs(data, "statistics/tx_errors", value); +} + +/*#Device.Ethernet.Interface.{i}.Stats.ErrorsReceived!UBUS:network.device/status/name,@Name/statistics.rx_errors*/ +static int get_EthernetInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_port_sysfs(data, "statistics/rx_errors", value); +} + +static int get_EthernetInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.Ethernet.Interface.{i}.Stats.DiscardPacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_dropped*/ +static int get_EthernetInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_port_sysfs(data, "statistics/tx_dropped", value); +} + +/*#Device.Ethernet.Interface.{i}.Stats.DiscardPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_dropped*/ +static int get_EthernetInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_port_sysfs(data, "statistics/rx_dropped", value); +} + +static int get_EthernetInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_port_sysfs(data, "statistics/multicast", value); +} + +static int get_EthernetInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetLink_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "true"; + return 0; +} + +static int set_EthernetLink_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_EthernetLink_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Up"; + return 0; +} + +static int get_EthernetLink_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "link_alias", value); + return 0; +} + +static int set_EthernetLink_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct dm_args *)data)->section, "link_alias", value); + break; + } + return 0; +} + +static int get_EthernetLink_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(section_name(((struct dm_args *)data)->section)); + return 0; +} + +static int get_EthernetLink_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + char *interface; + + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "section_name", &interface); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); + DM_ASSERT(res, *value = "0"); + *value = dmjson_get_value(res, 1, "uptime"); + if((*value)[0] == '\0') + *value = "0"; + return 0; +} + +static int get_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *link_mac, *type, *ifname, *mac, *br_inst, *mg, *p, linker[64] = ""; + struct uci_section *dmmap_section, *port; + + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "mac", &link_mac); + uci_foreach_sections("network", "interface", s) { + dmuci_get_value_by_section_string(s, "type", &type); + if (strcmp(type, "alias") == 0 || strcmp(section_name(s), "loopback") == 0) + continue; + + dmuci_get_value_by_section_string(s, "ifname", &ifname); + if (*ifname == '\0' || *ifname == '@') + continue; + + mac = get_macaddr(section_name(s)); + if (mac[0] == '\0' || strcasecmp(mac, link_mac) != 0) + continue; + + if (strcmp(type, "bridge") == 0) { + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(s), &dmmap_section); + if (dmmap_section != NULL) { + dmuci_get_value_by_section_string(dmmap_section, "bridge_instance", &br_inst); + uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", br_inst, port) { + dmuci_get_value_by_section_string(port, "mg_port", &mg); + if (strcmp(mg, "true") == 0) + snprintf(linker, sizeof(linker), "%s+", section_name(port)); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + *value = ""; + } + } + } + else { + /* for upstream interface, set the lowerlayer to wan port of Ethernet.Interface */ + p = strchr(ifname, '.'); + if (p) { + /*linker of wan port of interface is eth0.1*/ + *(p+1) = '1'; + *(p+2) = '\0'; + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value); + } + } + break; + } + return 0; +} + +static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_EthernetLink_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "mac", value); + return 0; +} + +static int get_EthernetLinkStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/tx_bytes", value); +} + +static int get_EthernetLinkStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/rx_bytes", value); +} + +static int get_EthernetLinkStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/tx_packets", value); +} + +static int get_EthernetLinkStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/rx_packets", value); +} + +static int get_EthernetLinkStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/tx_errors", value); +} + +static int get_EthernetLinkStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/rx_errors", value); +} + +static int get_EthernetLinkStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetLinkStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetLinkStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/tx_dropped", value); +} + +static int get_EthernetLinkStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/rx_dropped", value); +} + +static int get_EthernetLinkStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetLinkStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/multicast", value); +} + +static int get_EthernetLinkStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetLinkStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetLinkStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetVLANTermination_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "true"; + return 0; +} + +static int set_EthernetVLANTermination_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_EthernetVLANTermination_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Up"; + return 0; +} + +static int get_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + char *vlan_method = NULL; + + get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct dm_args *)data)->section), &dmmap_section); + if (dmmap_section) { + dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); + if(strcmp(vlan_method, "2") == 0) + dmuci_get_value_by_section_string(dmmap_section, "all_vlan_term_alias", value); + else + dmuci_get_value_by_section_string(dmmap_section, "vlan_term_alias", value); + } + return 0; +} + +static int set_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + char *vlan_method = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct dm_args *)data)->section), &dmmap_section); + if (dmmap_section) { + dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); + if(strcmp(vlan_method, "2") == 0) + dmuci_set_value_by_section(dmmap_section, "all_vlan_term_alias", value); + else + dmuci_set_value_by_section(dmmap_section, "vlan_term_alias", value); + } + return 0; + } + return 0; +} + +static int get_EthernetVLANTermination_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(section_name(((struct dm_args *)data)->section)); + return 0; +} + +/*#Device.Ethernet.VLANTermination.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ +static int get_EthernetVLANTermination_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + struct uci_section *s = NULL; + char *ifname, *devifname; + + *value ="0"; + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", &devifname); + uci_foreach_sections("network", "interface", s) { + dmuci_get_value_by_section_string(s, "ifname", &ifname); + if (strstr(ifname, devifname)) { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); + DM_ASSERT(res, *value = "0"); + *value = dmjson_get_value(res, 1, "uptime"); + if((*value)[0] == '\0') + *value = "0"; + break; + } + } + return 0; +} + +static int get_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *pch, *spch, *devifname, *ifname, *dupifname; + struct uci_section *section; + + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", &devifname); + uci_foreach_sections("network", "interface", section) { + dmuci_get_value_by_section_string(section, "ifname", &ifname); + dupifname = dmstrdup(ifname); + for (pch = strtok_r(dupifname, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { + if(strcmp(pch, devifname) == 0){ + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(section), value); + break; + } + } + } + return 0; +} + +static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *iface_list, *linker = NULL, *newvalue = NULL, *vlan_name = NULL; + struct uci_section *s; + + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (value[strlen(value)-1] != '.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else + adm_entry_get_linker_value(ctx, value, &linker); + + if (linker == NULL || *linker == '\0') + return -1; + + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", &vlan_name); + uci_foreach_sections("network", "interface", s) { + dmuci_get_value_by_section_string(s, "ifname", &iface_list); + if(strcmp(section_name(s), linker) != 0 && is_elt_exit_in_str_list(iface_list, vlan_name)) { + remove_elt_from_str_list(&iface_list, vlan_name); + dmuci_set_value_by_section(s, "ifname", iface_list); + } else if (strcmp(section_name(s), linker) == 0 && !is_elt_exit_in_str_list(iface_list, vlan_name)) { + add_elt_to_str_list(&iface_list, vlan_name); + dmuci_set_value_by_section(s, "ifname", iface_list); + } + } + } + return 0; +} + +/*#Device.Ethernet.VLANTermination.{i}.LastChange!UCI:network/device,@i-1/vid*/ +static int get_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "vid", value); + return 0; +} + +static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *ifname, *name, *vid, *curr_ifname; + struct uci_section *s; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", "4094")) + return FAULT_9007; + return 0; + case VALUESET: { + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "ifname", &ifname); + dmasprintf(&name, "%s.%s", ifname, value); + dmuci_set_value_by_section(((struct dm_args *)data)->section, "name", name); + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "vid", &vid); + dmuci_set_value_by_section(((struct dm_args *)data)->section, "vid", value); + dmasprintf(&curr_ifname, "%s.%s", ifname, vid); + uci_foreach_option_eq("network", "interface", "ifname", curr_ifname, s) { + dmuci_set_value_by_section(s, "ifname", name); + } + dmfree(name); + dmfree(curr_ifname); + return 0; + } + } + return 0; +} + +/*#Device.Ethernet.VLANTermination.{i}.TPID!UCI:network/device,@i-1/type*/ +static int get_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *type; + dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "type", &type); + if (strcmp(type, "8021q") == 0 || strcmp(type, "untagged") == 0) + *value = "33024"; + else if (strcmp(type, "8021ad") == 0) + *value = "34984"; + else + *value = "37120"; + return 0; +} + +static int set_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (strcmp(value, "33024") == 0) + dmuci_set_value_by_section(((struct dm_args *)data)->section, "type", "8021q"); + else if (strcmp(value, "34984") == 0) + dmuci_set_value_by_section(((struct dm_args *)data)->section, "type", "8021ad"); + else + return -1; + return 0; + } + return 0; +} + +/*#Device.Ethernet.VLANTermination.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/ +static int get_EthernetVLANTerminationStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/tx_bytes", value); +} + +/*#Device.Ethernet.VLANTermination.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/ +static int get_EthernetVLANTerminationStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/rx_bytes", value); +} + +/*#Device.Ethernet.VLANTermination.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/ +static int get_EthernetVLANTerminationStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/tx_packets", value); +} + +/*#Device.Ethernet.VLANTermination.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/ +static int get_EthernetVLANTerminationStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/rx_packets", value); +} + +/*#Device.Ethernet.VLANTermination.{i}.Stats.ErrorsSent!UBUS:network.device/status/name,@Name/statistics.tx_errors*/ +static int get_EthernetVLANTerminationStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/tx_errors", value); +} + +/*#Device.Ethernet.VLANTermination.{i}.Stats.ErrorsReceived!UBUS:network.device/status/name,@Name/statistics.rx_errors*/ +static int get_EthernetVLANTerminationStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/rx_errors", value); +} + +static int get_EthernetVLANTerminationStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetVLANTerminationStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.Ethernet.VLANTermination.{i}.Stats.DiscardPacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_dropped*/ +static int get_EthernetVLANTerminationStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/tx_dropped", value); +} + +/*#Device.Ethernet.VLANTermination.{i}.Stats.DiscardPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_dropped*/ +static int get_EthernetVLANTerminationStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/rx_dropped", value); +} + +static int get_EthernetVLANTerminationStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetVLANTerminationStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return eth_iface_sysfs(data, "statistics/multicast", value); +} + +static int get_EthernetVLANTerminationStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetVLANTerminationStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_EthernetVLANTerminationStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} /* *** Device.Ethernet. *** */ DMOBJ tEthernetObj[] = { @@ -157,1237 +1397,3 @@ DMLEAF tEthernetVLANTerminationStatsParams[] = { //{"UnknownProtoPacketsReceived", &DMREAD, DMT_UNINT, get_EthernetVLANTerminationStats_UnknownProtoPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH}, {0} }; - -/************************************************************* -* INIT -**************************************************************/ -static inline int init_eth_port(struct eth_port_args *args, struct uci_section *s, char *ifname) -{ - args->eth_port_sec = s; - args->ifname = ifname; - return 0; -} - -/************************************************************* -* COMMON Functions -**************************************************************/ -static int eth_iface_sysfs(const struct dm_args *args, const char *name, char **value) -{ - char *device; - - dmuci_get_value_by_section_string(args->section, "device", &device); - return get_net_device_sysfs(device, name, value); -} - -static int eth_port_sysfs(const struct eth_port_args *args, const char *name, char **value) -{ - return get_net_device_sysfs(args->ifname, name, value); -} - -static int is_mac_exist(char *macaddr) -{ - struct uci_section *s = NULL; - char *mac; - - uci_path_foreach_sections(bbfdm, DMMAP, "link", s) { - dmuci_get_value_by_section_string(s, "mac", &mac); - if (strcmp(mac, macaddr) == 0) - return 1; - } - return 0; -} - -static void create_link(char *ifname) -{ - char *macaddr, *v, *device; - struct uci_section *dmmap = NULL; - - macaddr = get_macaddr(ifname); - if (macaddr[0] == '\0') - return; - - device = get_device(ifname); - if (device[0] == '\0') - return; - - /* Interfaces might share the same mac address */ - if (is_mac_exist(macaddr)) - return; - - dmuci_add_section_bbfdm(DMMAP, "link", &dmmap, &v); - dmuci_set_value_by_section(dmmap, "mac", macaddr); - dmuci_set_value_by_section(dmmap, "device", device); - dmuci_set_value_by_section(dmmap, "section_name", ifname); -} - -static int dmmap_synchronizeEthernetLink(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *s = NULL; - char *type, *ifname; - - uci_foreach_sections("network", "interface", s) { - dmuci_get_value_by_section_string(s, "type", &type); - if (strcmp(type, "alias") == 0 || strcmp(section_name(s), "loopback") == 0) - continue; - - dmuci_get_value_by_section_string(s, "ifname", &ifname); - if (*ifname == '\0' || *ifname == '@') - continue; - - create_link(section_name(s)); - } - return 0; -} - -/************************************************************* -* ENTRY METHOD -**************************************************************/ -/*#Device.Ethernet.Interface.{i}.!UCI:ports/ethport/dmmap_ports*/ -int browseEthernetInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *int_num = NULL, *int_num_last = NULL, *ifname; - struct eth_port_args curr_eth_port_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("ports", "ethport", "dmmap_ports", &dup_list); - dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_ifname); - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); - if (strcmp(ifname, wan_ifname) == 0) { - if(strchr(ifname, '.')== NULL) - dmasprintf(&ifname, "%s.1", ifname); - } - init_eth_port(&curr_eth_port_args, p->config_section, ifname); - int_num = handle_update_instance(1, dmctx, &int_num_last, update_instance_alias, 3, p->dmmap_section, "eth_port_instance", "eth_port_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_eth_port_args, int_num) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int browseEthernetLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct dm_args args = {0}; - struct uci_section *s = NULL; - char *id_last = NULL, *id = NULL; - - dmmap_synchronizeEthernetLink(dmctx, NULL, NULL, NULL); - uci_path_foreach_sections(bbfdm, DMMAP, "link", s) { - args.section = s; - id = handle_update_instance(1, dmctx, &id_last, update_instance_alias_bbfdm, 3, s, "link_instance", "link_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&args, id) == DM_STOP) { - break; - } - } - return 0; -} - -/*#Device.Ethernet.VLANTermination.{i}.!UCI:network/device/dmmap_network*/ -int browseEthernetVLANTerminationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *vlan_term = NULL, *vlan_term_last = NULL, *type= NULL, *vlan_method= NULL; - struct dm_args curr_vlan_term_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("network", "device", "dmmap_network", &dup_list); - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "type", &type); - dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); - if ((strcmp(vlan_method, "2") != 0 && strcmp(vlan_method, "1") != 0) || (strcmp(vlan_method, "1") == 0 && strcmp(type, "untagged") == 0) ) - continue; - curr_vlan_term_args.section = p->config_section; - if(strcmp(vlan_method, "2") == 0) - vlan_term = handle_update_instance(1, dmctx, &vlan_term_last, update_instance_alias, 3, p->dmmap_section, "all_vlan_term_instance", "all_vlan_term_alias"); - else - vlan_term = handle_update_instance(1, dmctx, &vlan_term_last, update_instance_alias, 3, p->dmmap_section, "only_tagged_vlan_term_instance", "vlan_term_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_vlan_term_args, vlan_term) == DM_STOP) - break; - } - - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -/************************************************************* -* LINKER -**************************************************************/ -int get_linker_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct eth_port_args *)data)->ifname) { - *linker = ((struct eth_port_args *)data)->ifname; - return 0; - } else { - *linker = ""; - return 0; - } -} - -int get_linker_link(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "section_name", linker); - return 0; -} - -int get_linker_vlan_term(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if(((struct dm_args *)data)->section) { - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", linker); - return 0; - } else { - *linker = ""; - return 0; - } -} - -/************************************************************* -* ADD & DEL OBJ -**************************************************************/ -int addObjEthernetLink(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *inst, *v; - struct uci_section *dmmap_network= NULL; - - inst = get_last_instance_bbfdm(DMMAP, "link", "link_instance"); - - dmuci_add_section_bbfdm(DMMAP, "link", &dmmap_network, &v); - *instance = update_instance_bbfdm(dmmap_network, inst, "link_instance"); - return 0; -} - -int delObjEthernetLink(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - char *sect_name= NULL; - struct uci_section *s = NULL; - switch (del_action) { - case DEL_INST: - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "section_name", §_name); - get_config_section_of_dmmap_section("network", "interface", sect_name, &s); - if(!s) { - dmuci_delete_by_section(((struct dm_args *)data)->section, NULL, NULL); - return 0; - } - return FAULT_9005; - break; - case DEL_ALL: - return FAULT_9005; - break; - } - - return 0; -} - -int addObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *inst, *v, *eth_wan, *vid, *name, *vlan_name, *vlan_method = NULL; - struct uci_section *dmmap_network= NULL; - - check_create_dmmap_package("dmmap_network"); - dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); - if(strcmp(vlan_method, "2") == 0) - inst = get_vlan_last_instance_bbfdm("dmmap_network", "device", "all_vlan_term_instance", vlan_method); - else - inst = get_vlan_last_instance_bbfdm("dmmap_network", "device", "only_tagged_vlan_term_instance", vlan_method); - - dmuci_get_option_value_string("ports", "WAN", "ifname", ð_wan); - dmasprintf(&vid, "%d", inst?atoi(inst)+4:4); - dmasprintf(&vlan_name, "vlan_%s", vid); - dmuci_set_value("network", vlan_name, "", "device"); - dmuci_set_value("network", vlan_name, "ifname", eth_wan); - dmuci_set_value("network", vlan_name, "type", "8021q"); - dmuci_set_value("network", vlan_name, "vid", vid); - dmasprintf(&name, "%s.%s", eth_wan, vid); - dmuci_set_value("network", vlan_name, "name", name); - - dmuci_add_section_bbfdm("dmmap_network", "device", &dmmap_network, &v); - dmuci_set_value_by_section(dmmap_network, "section_name", vlan_name); - if(strcmp(vlan_method, "2") == 0) - *instance = update_instance_bbfdm(dmmap_network, inst, "all_vlan_term_instance"); - else - *instance = update_instance_bbfdm(dmmap_network, inst, "only_tagged_vlan_term_instance"); - - return 0; -} - -int delObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - int found = 0; - struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; - char *vlan_method = NULL; - - switch (del_action) { - case DEL_INST: - dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); - if(is_section_unnamed(section_name(((struct dm_args *)data)->section))) { - LIST_HEAD(dup_list); - if(strcmp(vlan_method, "2") == 0) { - delete_sections_save_next_sections("dmmap_network", "device", "all_vlan_term_instance", section_name((struct uci_section *)data), atoi(instance), &dup_list); - update_dmmap_sections(&dup_list, "all_vlan_term_instance", "dmmap_network", "device"); - } - else { - delete_sections_save_next_sections("dmmap_network", "device", "only_tagged_vlan_term_instance", section_name((struct uci_section *)data), atoi(instance), &dup_list); - update_dmmap_sections(&dup_list, "only_tagged_vlan_term_instance", "dmmap_network", "device"); - } - dmuci_delete_by_section_unnamed(((struct dm_args *)data)->section, NULL, NULL); - } else { - get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name(((struct dm_args *)data)->section), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); - dmuci_delete_by_section(((struct dm_args *)data)->section, NULL, NULL); - } - break; - case DEL_ALL: - uci_foreach_sections("network", "device", s) { - if (found != 0){ - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(s), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL){ - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - break; - } - return 0; -} - -/************************************************************* -* GET & SET PARAM -**************************************************************/ -/*#Device.Ethernet.InterfaceNumberOfEntries!UCI:ports/ethport/*/ -int get_Ethernet_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_foreach_sections("ports", "ethport", s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -int get_Ethernet_LinkNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - dmmap_synchronizeEthernetLink(ctx, NULL, NULL, NULL); - uci_path_foreach_sections(bbfdm, DMMAP, "link", s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -/*#Device.Ethernet.VLANTerminationNumberOfEntries!UCI:network/device/*/ -int get_Ethernet_VLANTerminationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - char *type, *vlan_method; - int cnt = 0; - - uci_foreach_sections("network", "device", s) { - dmuci_get_value_by_section_string(s, "type", &type); - dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); - if ((strcmp(vlan_method, "2") != 0 && strcmp(vlan_method, "1") != 0) || (strcmp(vlan_method, "1") == 0 && strcmp(type, "untagged") == 0)) - continue; - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -/*#Device.Ethernet.Interface.{i}.Enable!UBUS:network.device/status/name,@Name/carrier*/ -int get_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - char *ifname; - - if (strstr(((struct eth_port_args *)data)->ifname, wan_ifname)) { - ifname = dmstrdup(wan_ifname); - } else - ifname = dmstrdup(((struct eth_port_args *)data)->ifname); - - dmubus_call("network.device", "status", UBUS_ARGS{{"name", ifname, String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "carrier"); - dmfree(ifname); - return 0; -} - -int set_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - char *ifname; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - if (strstr(((struct eth_port_args *)data)->ifname, wan_ifname)) - ifname = dmstrdup(wan_ifname); - else - ifname = dmstrdup(((struct eth_port_args *)data)->ifname); - - DMCMD("ethctl", 3, ifname, "phy-power", b ? "up" : "down"); - dmfree(ifname); - return 0; - } - return 0; -} - -/*#Device.Ethernet.Interface.{i}.Status!UBUS:network.device/status/name,@Name/carrier*/ -int get_EthernetInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - bool b; - - get_EthernetInterface_Enable(refparam, ctx, data, instance, value); - string_to_bool(*value, &b); - *value = b ? "Up" : "Down"; - return 0; -} - -int get_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_ports", "ethport", section_name(((struct eth_port_args *)data)->eth_port_sec), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "eth_port_alias", value); - if (*value == NULL || strlen(*value) < 1) - dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "name", value); - return 0; -} - -int set_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_ports", "ethport", section_name(((struct eth_port_args *)data)->eth_port_sec), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "eth_port_alias", value); - return 0; - } - return 0; -} - -/*#Device.Ethernet.Interface.{i}.Name!UCI:ports/ethport,@i-1/name*/ -int get_EthernetInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "name", value); - return 0; -} - -/*#Device.Ethernet.Interface.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ -int get_EthernetInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - struct uci_section *s = NULL; - char *ifname; - - *value ="0"; - uci_foreach_sections("network", "interface", s) { - dmuci_get_value_by_section_string(s, "ifname", &ifname); - if (strstr(ifname, ((struct eth_port_args *)data)->ifname)) { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); - DM_ASSERT(res, *value = "0"); - *value = dmjson_get_value(res, 1, "uptime"); - if((*value)[0] == '\0') - *value = "0"; - break; - } - } - return 0; -} - -int get_EthernetInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ""; - return 0; -} - -int set_EthernetInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_EthernetInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *ifname; - dmuci_get_option_value_string("network", "lan", "ifname", &ifname); - if (strstr(ifname, ((struct eth_port_args *)data)->ifname)) - *value = "1"; - else - *value = "0"; - return 0; -} - -/*#Device.Ethernet.Interface.{i}.MACAddress!UBUS:network.device/status/name,@Name/macaddr*/ -int get_EthernetInterface_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_port_sysfs(data, "address", value); -} - -/*#Device.Ethernet.Interface.{i}.MaxBitRate!UCI:ports/ethport,@i-1/speed*/ -int get_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *pch, *spch, *speed; - - dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &speed); - if (speed[0] == '\0' || strcmp(speed, "disabled") == 0 ) - *value = "0"; - else { - if (strcmp(speed, "auto") == 0) - *value = "-1"; - else { - pch = strtok_r(speed, "FHfh", &spch); - *value = dmstrdup(pch); - } - } - return 0; -} - -int set_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *duplex, *val = "", *p = ""; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (strcasecmp(value, "0") == 0 ) - dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "disabled"); - else if (strcmp(value, "-1") == 0) - dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "auto"); - else { - dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &duplex); - if (strcmp(duplex, "auto") == 0 || strcmp(duplex, "disabled") == 0) - p = "FDAUTO"; - else - p = strchr(duplex, 'F') ? strchr(duplex, 'F') : strchr(duplex, 'H'); - if (p) dmastrcat(&val, value, p); - dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", val); - dmfree(val); - } - return 0; - } - return 0; -} - -/*#Device.Ethernet.Interface.{i}.CurrentBitRate!UBUS:network.device/status/name,@Name/speed*/ -int get_EthernetInterface_CurrentBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - char *speed, *pch; - - dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res); - DM_ASSERT(res, *value = "0"); - speed = dmjson_get_value(res, 1, "speed"); - if(speed[0] != '\0') { - pch = strtok(speed, "FHfh"); - *value = dmstrdup(pch); - } else - *value = "0"; - return 0; -} - -/*#Device.Ethernet.Interface.{i}.DuplexMode!UCI:ports/status/ethport,@i-1/speed*/ -int get_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", value); - if (*value[0] == '\0') - *value = ""; - else if (strcmp(*value, "auto") == 0) - *value = "Auto"; - else { - if (strchr(*value, 'F')) - *value = "Full"; - else if (strchr(*value, 'H')) - *value = "Half"; - else - *value = ""; - } - return 0; -} - -int set_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *m, *spch, *rate, *val = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, DuplexMode, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (strcasecmp(value, "auto") == 0) { - dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "auto"); - return 0; - } - dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &m); - m = dmstrdup(m); - rate = m; - if (strcmp(rate, "auto") == 0) - rate = "100"; - else { - strtok_r(rate, "FHfh", &spch); - } - if (strcasecmp(value, "full") == 0) - dmastrcat(&val, rate, "FD"); - else if (strcasecmp(value, "half") == 0) - dmastrcat(&val, rate, "HD"); - else { - dmfree(m); - return 0; - } - dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", val); - dmfree(m); - dmfree(val); - return 0; - } - return 0; -} - -int get_EthernetInterface_EEECapability(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "0"; - return 0; -} - -/*#Device.Ethernet.Interface.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/ -int get_EthernetInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_port_sysfs(data, "statistics/tx_bytes", value); -} - -/*#Device.Ethernet.Interface.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/ -int get_EthernetInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_port_sysfs(data, "statistics/rx_bytes", value); -} - -/*#Device.Ethernet.Interface.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/ -int get_EthernetInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_port_sysfs(data, "statistics/tx_packets", value); -} - -/*#Device.Ethernet.Interface.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/ -int get_EthernetInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_port_sysfs(data, "statistics/rx_packets", value); -} - -/*#Device.Ethernet.Interface.{i}.Stats.ErrorsSent!UBUS:network.device/status/name,@Name/statistics.tx_errors*/ -int get_EthernetInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_port_sysfs(data, "statistics/tx_errors", value); -} - -/*#Device.Ethernet.Interface.{i}.Stats.ErrorsReceived!UBUS:network.device/status/name,@Name/statistics.rx_errors*/ -int get_EthernetInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_port_sysfs(data, "statistics/rx_errors", value); -} - -int get_EthernetInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.Ethernet.Interface.{i}.Stats.DiscardPacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_dropped*/ -int get_EthernetInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_port_sysfs(data, "statistics/tx_dropped", value); -} - -/*#Device.Ethernet.Interface.{i}.Stats.DiscardPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_dropped*/ -int get_EthernetInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_port_sysfs(data, "statistics/rx_dropped", value); -} - -int get_EthernetInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_port_sysfs(data, "statistics/multicast", value); -} - -int get_EthernetInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetLink_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "true"; - return 0; -} - -int set_EthernetLink_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_EthernetLink_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Up"; - return 0; -} - -int get_EthernetLink_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "link_alias", value); - return 0; -} - -int set_EthernetLink_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct dm_args *)data)->section, "link_alias", value); - break; - } - return 0; -} - -int get_EthernetLink_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(section_name(((struct dm_args *)data)->section)); - return 0; -} - -int get_EthernetLink_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - char *interface; - - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "section_name", &interface); - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); - DM_ASSERT(res, *value = "0"); - *value = dmjson_get_value(res, 1, "uptime"); - if((*value)[0] == '\0') - *value = "0"; - return 0; -} - -int get_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - char *link_mac, *type, *ifname, *mac, *br_inst, *mg, *p, linker[64] = ""; - struct uci_section *dmmap_section, *port; - - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "mac", &link_mac); - uci_foreach_sections("network", "interface", s) { - dmuci_get_value_by_section_string(s, "type", &type); - if (strcmp(type, "alias") == 0 || strcmp(section_name(s), "loopback") == 0) - continue; - - dmuci_get_value_by_section_string(s, "ifname", &ifname); - if (*ifname == '\0' || *ifname == '@') - continue; - - mac = get_macaddr(section_name(s)); - if (mac[0] == '\0' || strcasecmp(mac, link_mac) != 0) - continue; - - if (strcmp(type, "bridge") == 0) { - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(s), &dmmap_section); - if (dmmap_section != NULL) { - dmuci_get_value_by_section_string(dmmap_section, "bridge_instance", &br_inst); - uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", br_inst, port) { - dmuci_get_value_by_section_string(port, "mg_port", &mg); - if (strcmp(mg, "true") == 0) - snprintf(linker, sizeof(linker), "%s+", section_name(port)); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - *value = ""; - } - } - } - else { - /* for upstream interface, set the lowerlayer to wan port of Ethernet.Interface */ - p = strchr(ifname, '.'); - if (p) { - /*linker of wan port of interface is eth0.1*/ - *(p+1) = '1'; - *(p+2) = '\0'; - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value); - } - } - break; - } - return 0; -} - -int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_EthernetLink_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "mac", value); - return 0; -} - -int get_EthernetLinkStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/tx_bytes", value); -} - -int get_EthernetLinkStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/rx_bytes", value); -} - -int get_EthernetLinkStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/tx_packets", value); -} - -int get_EthernetLinkStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/rx_packets", value); -} - -int get_EthernetLinkStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/tx_errors", value); -} - -int get_EthernetLinkStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/rx_errors", value); -} - -int get_EthernetLinkStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetLinkStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetLinkStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/tx_dropped", value); -} - -int get_EthernetLinkStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/rx_dropped", value); -} - -int get_EthernetLinkStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetLinkStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/multicast", value); -} - -int get_EthernetLinkStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetLinkStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetLinkStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetVLANTermination_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "true"; - return 0; -} - -int set_EthernetVLANTermination_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_EthernetVLANTermination_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Up"; - return 0; -} - -int get_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - char *vlan_method = NULL; - - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct dm_args *)data)->section), &dmmap_section); - if (dmmap_section) { - dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); - if(strcmp(vlan_method, "2") == 0) - dmuci_get_value_by_section_string(dmmap_section, "all_vlan_term_alias", value); - else - dmuci_get_value_by_section_string(dmmap_section, "vlan_term_alias", value); - } - return 0; -} - -int set_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - char *vlan_method = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct dm_args *)data)->section), &dmmap_section); - if (dmmap_section) { - dmuci_get_option_value_string("cwmp", "cpe", "vlan_method", &vlan_method); - if(strcmp(vlan_method, "2") == 0) - dmuci_set_value_by_section(dmmap_section, "all_vlan_term_alias", value); - else - dmuci_set_value_by_section(dmmap_section, "vlan_term_alias", value); - } - return 0; - } - return 0; -} - -int get_EthernetVLANTermination_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(section_name(((struct dm_args *)data)->section)); - return 0; -} - -/*#Device.Ethernet.VLANTermination.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ -int get_EthernetVLANTermination_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - struct uci_section *s = NULL; - char *ifname, *devifname; - - *value ="0"; - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", &devifname); - uci_foreach_sections("network", "interface", s) { - dmuci_get_value_by_section_string(s, "ifname", &ifname); - if (strstr(ifname, devifname)) { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); - DM_ASSERT(res, *value = "0"); - *value = dmjson_get_value(res, 1, "uptime"); - if((*value)[0] == '\0') - *value = "0"; - break; - } - } - return 0; -} - -int get_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *pch, *spch, *devifname, *ifname, *dupifname; - struct uci_section *section; - - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", &devifname); - uci_foreach_sections("network", "interface", section) { - dmuci_get_value_by_section_string(section, "ifname", &ifname); - dupifname = dmstrdup(ifname); - for (pch = strtok_r(dupifname, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { - if(strcmp(pch, devifname) == 0){ - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(section), value); - break; - } - } - } - return 0; -} - -int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *iface_list, *linker = NULL, *newvalue = NULL, *vlan_name = NULL; - struct uci_section *s; - - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (value[strlen(value)-1] != '.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); - - if (linker == NULL || *linker == '\0') - return -1; - - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "name", &vlan_name); - uci_foreach_sections("network", "interface", s) { - dmuci_get_value_by_section_string(s, "ifname", &iface_list); - if(strcmp(section_name(s), linker) != 0 && is_elt_exit_in_str_list(iface_list, vlan_name)) { - remove_elt_from_str_list(&iface_list, vlan_name); - dmuci_set_value_by_section(s, "ifname", iface_list); - } else if (strcmp(section_name(s), linker) == 0 && !is_elt_exit_in_str_list(iface_list, vlan_name)) { - add_elt_to_str_list(&iface_list, vlan_name); - dmuci_set_value_by_section(s, "ifname", iface_list); - } - } - } - return 0; -} - -/*#Device.Ethernet.VLANTermination.{i}.LastChange!UCI:network/device,@i-1/vid*/ -int get_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "0"; - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "vid", value); - return 0; -} - -int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *ifname, *name, *vid, *curr_ifname; - struct uci_section *s; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", "4094")) - return FAULT_9007; - return 0; - case VALUESET: { - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "ifname", &ifname); - dmasprintf(&name, "%s.%s", ifname, value); - dmuci_set_value_by_section(((struct dm_args *)data)->section, "name", name); - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "vid", &vid); - dmuci_set_value_by_section(((struct dm_args *)data)->section, "vid", value); - dmasprintf(&curr_ifname, "%s.%s", ifname, vid); - uci_foreach_option_eq("network", "interface", "ifname", curr_ifname, s) { - dmuci_set_value_by_section(s, "ifname", name); - } - dmfree(name); - dmfree(curr_ifname); - return 0; - } - } - return 0; -} - -/*#Device.Ethernet.VLANTermination.{i}.TPID!UCI:network/device,@i-1/type*/ -int get_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *type; - dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "type", &type); - if (strcmp(type, "8021q") == 0 || strcmp(type, "untagged") == 0) - *value = "33024"; - else if (strcmp(type, "8021ad") == 0) - *value = "34984"; - else - *value = "37120"; - return 0; -} - -int set_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (strcmp(value, "33024") == 0) - dmuci_set_value_by_section(((struct dm_args *)data)->section, "type", "8021q"); - else if (strcmp(value, "34984") == 0) - dmuci_set_value_by_section(((struct dm_args *)data)->section, "type", "8021ad"); - else - return -1; - return 0; - } - return 0; -} - -/*#Device.Ethernet.VLANTermination.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/ -int get_EthernetVLANTerminationStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/tx_bytes", value); -} - -/*#Device.Ethernet.VLANTermination.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/ -int get_EthernetVLANTerminationStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/rx_bytes", value); -} - -/*#Device.Ethernet.VLANTermination.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/ -int get_EthernetVLANTerminationStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/tx_packets", value); -} - -/*#Device.Ethernet.VLANTermination.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/ -int get_EthernetVLANTerminationStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/rx_packets", value); -} - -/*#Device.Ethernet.VLANTermination.{i}.Stats.ErrorsSent!UBUS:network.device/status/name,@Name/statistics.tx_errors*/ -int get_EthernetVLANTerminationStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/tx_errors", value); -} - -/*#Device.Ethernet.VLANTermination.{i}.Stats.ErrorsReceived!UBUS:network.device/status/name,@Name/statistics.rx_errors*/ -int get_EthernetVLANTerminationStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/rx_errors", value); -} - -int get_EthernetVLANTerminationStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetVLANTerminationStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.Ethernet.VLANTermination.{i}.Stats.DiscardPacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_dropped*/ -int get_EthernetVLANTerminationStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/tx_dropped", value); -} - -/*#Device.Ethernet.VLANTermination.{i}.Stats.DiscardPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_dropped*/ -int get_EthernetVLANTerminationStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/rx_dropped", value); -} - -int get_EthernetVLANTerminationStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetVLANTerminationStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return eth_iface_sysfs(data, "statistics/multicast", value); -} - -int get_EthernetVLANTerminationStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetVLANTerminationStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_EthernetVLANTerminationStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} diff --git a/dmtree/tr181/ethernet.h b/dmtree/tr181/ethernet.h index 89e1240c..01d7a999 100644 --- a/dmtree/tr181/ethernet.h +++ b/dmtree/tr181/ethernet.h @@ -15,12 +15,6 @@ #include -struct eth_port_args -{ - struct uci_section *eth_port_sec; - char *ifname; -}; - extern DMOBJ tEthernetObj[]; extern DMLEAF tEthernetParams[]; extern DMOBJ tEthernetInterfaceObj[]; @@ -33,109 +27,4 @@ extern DMOBJ tEthernetVLANTerminationObj[]; extern DMLEAF tEthernetVLANTerminationParams[]; extern DMLEAF tEthernetVLANTerminationStatsParams[]; -int browseEthernetInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseEthernetLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseEthernetVLANTerminationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int addObjEthernetLink(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjEthernetLink(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_linker_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); -int get_linker_link(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); -int get_linker_vlan_term(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); - -int get_Ethernet_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_Ethernet_LinkNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_Ethernet_VLANTerminationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterface_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetInterface_CurrentBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetInterface_EEECapability(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_EthernetLink_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetLink_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetLink_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLink_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetLink_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetLink_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLink_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetLink_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetLinkStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_EthernetVLANTermination_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetVLANTermination_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetVLANTermination_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetVLANTermination_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTermination_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_EthernetVLANTerminationStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_EthernetVLANTerminationStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - #endif //__ETHERNET_H diff --git a/dmtree/tr181/firewall.c b/dmtree/tr181/firewall.c index e353d7c2..8fb0ab18 100644 --- a/dmtree/tr181/firewall.c +++ b/dmtree/tr181/firewall.c @@ -11,6 +11,1220 @@ #include "dmentry.h" #include "firewall.h" + +/***************************** Browse Functions ***********************************/ +static int browseLevelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *s; + char *v, *instnbr = NULL; + + check_create_dmmap_package("dmmap_firewall"); + s = is_dmmap_section_exist("dmmap_firewall", "level"); + if (!s) dmuci_add_section_bbfdm("dmmap_firewall", "level", &s, &v); + handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "firewall_level_instance", "firewall_level_alias"); + DM_LINK_INST_OBJ(dmctx, parent_node, s, "1"); + return 0; +} + +static int browseChainInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *s; + char *v, *instnbr = NULL; + + check_create_dmmap_package("dmmap_firewall"); + s = is_dmmap_section_exist("dmmap_firewall", "chain"); + if (!s) dmuci_add_section_bbfdm("dmmap_firewall", "chain", &s, &v); + handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "firewall_chain_instance", "firewall_chain_alias"); + DM_LINK_INST_OBJ(dmctx, parent_node, s, "1"); + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.!UCI:firewall/rule/dmmap_firewall*/ +static int browseRuleInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *instance, *instnbr = NULL; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("firewall", "rule", "dmmap_firewall", &dup_list); + list_for_each_entry(p, &dup_list, list) { + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, p->dmmap_section, "firewall_chain_rule_instance", "firewall_chain_rule_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, instance) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int add_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct uci_section *s, *dmmap_firewall_rule; + char *last_inst = NULL, *sect_name = NULL, *rule_name, *v; + char ib[8]; + + last_inst = get_last_instance_bbfdm("dmmap_firewall", "rule", "firewall_chain_rule_instance"); + snprintf(ib, sizeof(ib), "%s", last_inst ? last_inst : "1"); + dmasprintf(&rule_name, "Firewall rule %d", atoi(ib)+1); + + dmuci_add_section("firewall", "rule", &s, §_name); + dmuci_set_value_by_section(s, "name", rule_name); + dmuci_set_value_by_section(s, "dest", "lan"); + dmuci_set_value_by_section(s, "src", "wan"); + dmuci_set_value_by_section(s, "target", "ACCEPT"); + + dmuci_add_section_bbfdm("dmmap_firewall", "rule", &dmmap_firewall_rule, &v); + dmuci_set_value_by_section(dmmap_firewall_rule, "section_name", sect_name); + *instance = update_instance_bbfdm(dmmap_firewall_rule, last_inst, "firewall_chain_rule_instance"); + return 0; +} + +static int delete_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; + int found = 0; + + switch (del_action) { + case DEL_INST: + if (is_section_unnamed(section_name((struct uci_section *)data))) { + LIST_HEAD(dup_list); + delete_sections_save_next_sections("dmmap_firewall", "rule", "firewall_chain_rule_instance", section_name((struct uci_section *)data), atoi(instance), &dup_list); + update_dmmap_sections(&dup_list, "firewall_chain_rule_instance", "dmmap_firewall", "rule"); + dmuci_delete_by_section_unnamed((struct uci_section *)data, NULL, NULL); + } else { + get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); + dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); + } + break; + case DEL_ALL: + uci_foreach_sections("firewall", "rule", s) { + if (found != 0) { + get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ss), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ss), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + } + return 0; +} + +/***************************************** Set/Get Parameter functions ***********************/ +static int get_firewall_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *path = "/etc/rc.d/*firewall"; + if (check_file(path)) + *value = "1"; + else + *value = "0"; + return 0; +} + +static int get_firewall_config(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Advanced"; + return 0; +} + +static int get_firewall_advanced_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Device.Firewall.Level.1."; + return 0; +} + +static int get_firewall_level_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int get_firewall_chain_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int get_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); + return 0; +} + +static int get_level_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "description", value); + return 0; +} + +static int get_level_chain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Device.Firewall.Chain.1."; + return 0; +} + +static int get_level_port_mapping_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *v; + + uci_foreach_sections("firewall", "zone", s) { + dmuci_get_value_by_section_string(s, "masq", &v); + if (*v == '1') { + *value = "1"; + return 0; + } + } + *value = "0"; + return 0; +} + +static int get_level_default_log_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *v; + + uci_foreach_sections("firewall", "zone", s) { + dmuci_get_value_by_section_string(s, "log", &v); + if (*v == '1') { + *value = "1"; + return 0; + } + } + *value = "0"; + return 0; +} + +static int get_chain_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int get_chain_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); + return 0; +} + +static int get_chain_creator(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Defaults"; + return 0; +} + +/*#Device.Firewall.Chain.{i}.RuleNumberOfEntries!UCI:firewall/rule/*/ +static int get_chain_rule_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_foreach_sections("firewall", "rule", s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.Enable!UCI:firewall/rule,@i-1/enabled*/ +static int get_rule_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v; + dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &v); + *value = (*v == 'n' || *v == '0' ) ? "0" : "1"; + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.Status!UCI:firewall/rule,@i-1/enabled*/ +static int get_rule_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v; + dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &v); + *value = (*v == 'n' || *v == '0') ? "Disabled" : "Enabled"; + return 0; +} + +static int get_rule_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dms = NULL; + get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dms); + if (dms) + dmuci_get_value_by_section_string(dms, "firewall_chain_rule_instance", value); + return 0; +} + +static int get_rule_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dms = NULL; + get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dms); + if (dms) + dmuci_get_value_by_section_string(dms, "description", value); + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.Target!UCI:firewall/rule,@i-1/target*/ +static int get_rule_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v; + + dmuci_get_value_by_section_string((struct uci_section *)data, "target", &v); + if (strcasecmp(v, "Accept") == 0) + *value = "Accept"; + else if (strcasecmp(v, "Reject") == 0) + *value = "Reject"; + else if (strcasecmp(v, "Drop") == 0) + *value = "Drop"; + else if (strcasecmp(v, "MARK") == 0) + *value = "Return"; + else + *value = v; + return 0; +} + +static int get_rule_target_chain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *v = NULL, *v1 = NULL; + struct uci_element *e; + char *vallink, *zone, buf[256] = "", *val; + struct uci_section *s = NULL; + + dmuci_get_value_by_section_string((struct uci_section *)data, "src", &zone); + if (zone == NULL || strlen(zone) == 0) + return 0; + + if (strcmp(zone, "*") == 0) { + v = dmcalloc(1, sizeof(struct uci_list)); + uci_list_init(v); + uci_foreach_sections("firewall", "zone", s) { + dmuci_get_value_by_section_list(s, "network", &v1); + uci_add_list_to_list(v1, v); + } + } else { + uci_foreach_sections("firewall", "zone", s) { + dmuci_get_value_by_section_string(s, "name", &val); + if (strcmp(val, zone) == 0) { + dmuci_get_value_by_section_list(s, "network", &v); + break; + } + } + } + + if (v != NULL) { + uci_foreach_element(v, e) { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), e->name, &vallink); + if (*vallink == '\0') + continue; + if (*buf != '\0') + strcat(buf, ","); + strcat(buf, vallink); + } + } else { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), zone, &vallink); + strcpy(buf, vallink); + } + + *value = dmstrdup(buf); + return 0; +} + +static int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *v = NULL; + struct uci_element *e; + char *zone, *ifaceobj, buf[256] = "", *val; + struct uci_section *s = NULL; + + dmuci_get_value_by_section_string((struct uci_section *)data, "dest", &zone); + uci_foreach_sections("firewall", "zone", s) { + dmuci_get_value_by_section_string(s, "name", &val); + if (strcmp(val, zone) == 0) { + dmuci_get_value_by_section_list(s, "network", &v); + break; + } + } + if (v != NULL) { + uci_foreach_element(v, e) { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), e->name, &ifaceobj); + if (*ifaceobj == '\0') + continue; + if (*buf != '\0') + strcat(buf, ","); + strcat(buf, ifaceobj); + } + } + + *value = dmstrdup(buf); + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.IPVersion!UCI:firewall/rule,@i-1/family*/ +static int get_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *ipversion; + + dmuci_get_value_by_section_string((struct uci_section *)data, "family", &ipversion); + if (strcasecmp(ipversion, "ipv4") == 0) { + *value = "4"; + } else if (strcasecmp(ipversion, "ipv6") == 0) { + *value = "6"; + } else { + *value = "-1"; + } + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.DestIp!UCI:firewall/rule,@i-1/dest_ip*/ +static int get_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char buf[64], *pch, *destip; + + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip); + strcpy(buf, destip); + pch = strchr(buf, '/'); + if (pch) *pch = '\0'; + *value = dmstrdup(buf); + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.DestMask!UCI:firewall/rule,@i-1/dest_ip*/ +static int get_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *pch, *destip; + + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip); + if (*destip == '\0') + return 0; + + pch = strchr(destip, '/'); + if (pch) { + *value = pch+1; + } else { + *value = ""; + } + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.SourceIp!UCI:firewall/rule,@i-1/src_ip*/ +static int get_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char buf[64], *pch, *srcip; + + dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip); + strcpy(buf, srcip); + pch = strchr(buf, '/'); + if (pch) + *pch = '\0'; + *value = dmstrdup(buf); + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.SourceMask!UCI:firewall/rule,@i-1/src_ip*/ +static int get_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *pch, *srcip; + *value = ""; + + dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip); + if (*srcip == '\0') + return 0; + + pch = strchr(srcip, '/'); + if (pch) { + *value = pch+1; + } else { + *value = ""; + } + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.Protocol!UCI:firewall/rule,@i-1/proto*/ +static int get_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + FILE *fp; + char *v, buf[256], protocol[32], protocol_nbr[16]; + + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &v); + *value = "-1"; + if (*v == '\0' || *v == '0') { + return 0; + } + if (isdigit_str(v)) { + *value = v; + return 0; + } + fp = fopen("/etc/protocols", "r"); + if (fp == NULL) + return 0; + while (fgets (buf , 256 , fp) != NULL) { + sscanf(buf, "%31s %15s", protocol, protocol_nbr); + if (strcmp(protocol, v) == 0) { + *value = dmstrdup(protocol_nbr); + fclose(fp); + return 0; + } + } + fclose(fp); + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.DestPort!UCI:firewall/rule,@i-1/dest_port*/ +static int get_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *tmp,*v; + + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v); + v = dmstrdup(v); + tmp = strchr(v, ':'); + if (tmp == NULL) + tmp = strchr(v, '-'); + if (tmp) + *tmp = '\0'; + if (*v == '\0') { + *value = "-1"; + return 0; + } + *value = v; + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.DestPortRangeMax!UCI:firewall/rule,@i-1/dest_port*/ +static int get_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *tmp, *v; + + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v); + tmp = strchr(v, ':'); + if (tmp == NULL) + tmp = strchr(v, '-'); + *value = (tmp) ? tmp+1 : "-1"; + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.SourcePort!UCI:firewall/rule,@i-1/src_port*/ +static int get_rule_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *tmp, *v; + + dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v); + v = dmstrdup(v); + tmp = strchr(v, ':'); + if (tmp == NULL) + tmp = strchr(v, '-'); + if (tmp) + *tmp = '\0'; + if (*v == '\0') { + *value = "-1"; + return 0; + } + *value = v; + return 0; +} + +/*#Device.Firewall.Chain.{i}.Rule.{i}.SourcePortRangeMax!UCI:firewall/rule,@i-1/src_port*/ +static int get_rule_source_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *tmp, *v; + + dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v); + tmp = strchr(v, ':'); + if (tmp == NULL) + tmp = strchr(v, '-'); + *value = (tmp) ? tmp+1 : "-1"; + return 0; +} + +static int get_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *v= NULL; + struct uci_element *e; + char *ptr; + + dmasprintf(value, "%s", ""); + dmuci_get_value_by_section_list((struct uci_section *)data, "icmp_type", &v); + if (v != NULL) { + uci_foreach_element(v, e) { + ptr = dmstrdup(*value); + dmfree(*value); + + if (strlen(ptr) == 0) + dmasprintf(value, "%s", e->name); + else { + dmasprintf(value, "%s %s", ptr, e->name); + dmfree(ptr); + } + } + } + return 0; +} + +static int get_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v = NULL; + dmuci_get_value_by_section_string((struct uci_section *)data, "src_mac", &v); + *value = (v) ? v : ""; + return 0; +} + +static int get_time_span_supported_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "mon tue wed thu fri sat sun"; + return 0; +} + +static int get_time_span_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v; + dmuci_get_value_by_section_string((struct uci_section *)data, "weekdays", &v); + *value = (v) ? v : ""; + return 0; +} + +static int get_time_span_start_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v; + dmuci_get_value_by_section_string((struct uci_section *)data, "start_time", &v); + *value = (v) ? v : ""; + return 0; +} + +static int get_time_span_stop_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v; + dmuci_get_value_by_section_string((struct uci_section *)data, "stop_time", &v); + *value = (v) ? v : ""; + return 0; +} + +static int set_firewall_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmcmd("/etc/init.d/firewall", 1, b ? "enable" : "disable"); + break; + } + return 0; +} + +static int set_firewall_config(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, Config, NULL)) + return FAULT_9007; + break; + case VALUESET: + if (strcasecmp(value, "Advanced") != 0) + return FAULT_9007; + break; + } + return 0; +} + +static int set_firewall_advanced_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + if (strcasecmp(value, "Device.Firewall.Level.1.") != 0) + return FAULT_9007; + break; + } + return 0; +} + +static int set_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + DMUCI_SET_VALUE_BY_SECTION(bbfdm, (struct uci_section *)data, "name", value); + break; + } + return 0; +} + +static int set_level_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + DMUCI_SET_VALUE_BY_SECTION(bbfdm, (struct uci_section *)data, "description", value); + break; + } + return 0; +} + +static int set_level_port_mapping_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + struct uci_section *s = NULL; + char *v, *v2; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + if (b) { + uci_foreach_sections("firewall", "zone", s) { + dmuci_get_value_by_section_string(s, "src", &v); + dmuci_get_value_by_section_string(s, "name", &v2); + if (strcasestr(v, "wan") || strcasestr(v2, "wan")) { + dmuci_set_value_by_section(s, "masq", "1"); + return 0; + } + } + } else { + uci_foreach_sections("firewall", "zone", s) { + dmuci_set_value_by_section(s, "masq", ""); + } + } + break; + } + return 0; +} + +static int set_level_default_log_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + if (b) { + uci_foreach_sections("firewall", "zone", s) { + dmuci_set_value_by_section(s, "log", "1"); + } + } else { + uci_foreach_sections("firewall", "zone", s) { + dmuci_set_value_by_section(s, "log", ""); + } + } + break; + } + return 0; +} + +static int set_chain_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int set_chain_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + DMUCI_SET_VALUE_BY_SECTION(bbfdm, (struct uci_section *)data, "name", value); + break; + } + return 0; +} + +static int set_rule_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "" : "no"); + break; + } + return 0; +} + +static int set_rule_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int set_rule_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dms = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dms); + if (dms) + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dms, "description", value); + break; + } + return 0; +} + +static int set_rule_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, Target, NULL)) + return FAULT_9007; + break; + case VALUESET: + if (strcasecmp(value, "Accept") == 0) + dmuci_set_value_by_section((struct uci_section *)data, "target", "ACCEPT"); + else if (strcasecmp(value, "Reject") == 0) + dmuci_set_value_by_section((struct uci_section *)data, "target", "REJECT"); + else if (strcasecmp(value, "Drop") == 0) + dmuci_set_value_by_section((struct uci_section *)data, "target", "DROP"); + else if (strcasecmp(value, "Return") == 0) + dmuci_set_value_by_section((struct uci_section *)data, "target", "MARK"); + break; + } + return 0; +} + +static int set_rule_target_chain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int set_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *iface, *zone, *net; + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + + adm_entry_get_linker_value(ctx, value, &iface); + if (iface == NULL || iface[0] == '\0') + return FAULT_9007; + break; + case VALUESET: + adm_entry_get_linker_value(ctx, value, &iface); + if (iface && iface[0] != '\0') { + uci_foreach_sections("firewall", "zone", s) { + dmuci_get_value_by_section_string(s, "network", &net); + if (dm_strword(net, iface)) { + dmuci_get_value_by_section_string(s, "name", &zone); + dmuci_set_value_by_section((struct uci_section *)data, "src", zone); + break; + } + } + } + break; + } + return 0; +} + +static int set_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *iface, *zone, *net; + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + adm_entry_get_linker_value(ctx, value, &iface); + if (iface != NULL && iface[0] != '\0') { + uci_foreach_sections("firewall", "zone", s) { + dmuci_get_value_by_section_string(s, "name", &net); + if (dm_strword(net, iface)) { + dmuci_get_value_by_section_string(s, "name", &zone); + dmuci_set_value_by_section((struct uci_section *)data, "dest", zone); + break; + } + } + } + break; + } + return 0; +} + +static int set_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "15")) + return FAULT_9007; + break; + case VALUESET: + if (strcmp(value, "4") == 0) + dmuci_set_value_by_section((struct uci_section *)data, "family", "ipv4"); + else if (strcmp(value, "6") == 0) + dmuci_set_value_by_section((struct uci_section *)data, "family", "ipv6"); + else if (strcmp(value, "-1") == 0) + dmuci_set_value_by_section((struct uci_section *)data, "family", ""); + break; + } + return 0; +} + +static int set_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char buf[64], new[64], *pch, *destip; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip); + strcpy(buf, destip); + pch = strchr(buf, '/'); + if (pch) + snprintf(new, sizeof(new), "%s%s", value, pch); + else + strcpy(new, value); + dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", new); + break; + } + return 0; +} + +static int set_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char buf[64], new[64], *pch, *destip; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "49", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip); + strcpy(buf, destip); + pch = strchr(buf, '/'); + if (pch) + *pch = '\0'; + snprintf(new, sizeof(new), "%s/%s", buf, value); + dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", new); + break; + } + return 0; +} + +static int set_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char buf[64], new[64], *pch, *srcip; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip); + strcpy(buf, srcip); + pch = strchr(buf, '/'); + if (pch) + snprintf(new, sizeof(new), "%s%s", value, pch); + else + strcpy(new, value); + dmuci_set_value_by_section((struct uci_section *)data, "src_ip", new); + break; + } + return 0; +} + +static int set_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char buf[64], new[64], *pch, *srcip; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "49", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip); + strcpy(buf, srcip); + pch = strchr(buf, '/'); + if (pch) + *pch = '\0'; + snprintf(new, sizeof(new), "%s/%s", buf, value); + dmuci_set_value_by_section((struct uci_section *)data, "src_ip", new); + break; + } + return 0; +} + +static int set_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "255")) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "proto", (*value == '-') ? "" : value); + break; + } + return 0; +} + +static int set_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char buffer[64], *v, *tmp = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "65535")) + return FAULT_9007; + break; + case VALUESET: + if (*value == '-') + value = ""; + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v); + tmp = strchr(v, ':'); + if (tmp == NULL) + tmp = strchr(v, '-'); + if (tmp == NULL) + snprintf(buffer, sizeof(buffer), "%s", value); + else + snprintf(buffer, sizeof(buffer), "%s%s", value, tmp); + dmuci_set_value_by_section((struct uci_section *)data, "dest_port", buffer); + break; + } + return 0; +} + +static int set_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *v, *tmp, *buf, buffer[64]; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "65535")) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v); + buf = dmstrdup(v); + v = buf; + tmp = strchr(buf, ':'); + if (tmp == NULL) + tmp = strchr(v, '-'); + if (tmp) + *tmp = '\0'; + if (*value == '-') + snprintf(buffer, sizeof(buffer), "%s", v); + else + snprintf(buffer, sizeof(buffer), "%s:%s", v, value); + dmfree(buf); + dmuci_set_value_by_section((struct uci_section *)data, "dest_port", buffer); + break; + } + return 0; +} + +static int set_rule_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char buffer[64], *v, *tmp = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "65535")) + return FAULT_9007; + break; + case VALUESET: + if (*value == '-') + value = ""; + dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v); + tmp = strchr(v, ':'); + if (tmp == NULL) + tmp = strchr(v, '-'); + if (tmp == NULL) + snprintf(buffer, sizeof(buffer), "%s", value); + else + snprintf(buffer, sizeof(buffer), "%s%s", value, tmp); + dmuci_set_value_by_section((struct uci_section *)data, "src_port", buffer); + break; + } + return 0; +} + +static int set_rule_source_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *v, *tmp, *buf, buffer[64]; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "65535")) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v); + buf = dmstrdup(v); + v = buf; + tmp = strchr(buf, ':'); + if (tmp == NULL) + tmp = strchr(buf, '-'); + if (tmp) + *tmp = '\0'; + if (*value == '-') + snprintf(buffer, sizeof(buffer), "%s", v); + else + snprintf(buffer, sizeof(buffer), "%s:%s", v, value); + dmfree(buf); + dmuci_set_value_by_section((struct uci_section *)data, "src_port", buffer); + break; + } + return 0; +} + +static int set_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + int i; + size_t length; + char **devices = NULL; + + switch (action) { + case VALUECHECK: + //TODO + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "icmp_type", ""); + devices = strsplit(value, " ", &length); + for (i = 0; i < length; i++) + dmuci_add_list_value_by_section((struct uci_section *)data, "icmp_type", devices[i]); + break; + } + return 0; +} + +static int set_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + //TODO + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "src_mac", value); + break; + } + return 0; +} + +static int set_time_span_supported_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + //TODO + break; + case VALUESET: + break; + } + return 0; +} + +static int set_time_span_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + //TODO + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "weekdays", value); + break; + } + return 0; +} + +static int set_time_span_start_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + //TODO + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "start_time", value); + break; + } + return 0; +} + +static int set_time_span_stop_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + //TODO + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "stop_time", value); + break; + } + return 0; +} + /* *** Device.Firewall. *** */ DMOBJ tFirewallObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -96,1216 +1310,3 @@ DMLEAF tTimeSpanParams[] = { {"StopTime", &DMWRITE, DMT_STRING, get_time_span_stop_time, set_time_span_stop_time, NULL, NULL, BBFDM_BOTH}, {0} }; - -/***************************** Browse Functions ***********************************/ -int browseLevelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *s; - char *v, *instnbr = NULL; - - check_create_dmmap_package("dmmap_firewall"); - s = is_dmmap_section_exist("dmmap_firewall", "level"); - if (!s) dmuci_add_section_bbfdm("dmmap_firewall", "level", &s, &v); - handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "firewall_level_instance", "firewall_level_alias"); - DM_LINK_INST_OBJ(dmctx, parent_node, s, "1"); - return 0; -} - -int browseChainInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *s; - char *v, *instnbr = NULL; - - check_create_dmmap_package("dmmap_firewall"); - s = is_dmmap_section_exist("dmmap_firewall", "chain"); - if (!s) dmuci_add_section_bbfdm("dmmap_firewall", "chain", &s, &v); - handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "firewall_chain_instance", "firewall_chain_alias"); - DM_LINK_INST_OBJ(dmctx, parent_node, s, "1"); - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.!UCI:firewall/rule/dmmap_firewall*/ -int browseRuleInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *instance, *instnbr = NULL; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("firewall", "rule", "dmmap_firewall", &dup_list); - list_for_each_entry(p, &dup_list, list) { - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, p->dmmap_section, "firewall_chain_rule_instance", "firewall_chain_rule_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, instance) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int add_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct uci_section *s, *dmmap_firewall_rule; - char *last_inst = NULL, *sect_name = NULL, *rule_name, *v; - char ib[8]; - - last_inst = get_last_instance_bbfdm("dmmap_firewall", "rule", "firewall_chain_rule_instance"); - snprintf(ib, sizeof(ib), "%s", last_inst ? last_inst : "1"); - dmasprintf(&rule_name, "Firewall rule %d", atoi(ib)+1); - - dmuci_add_section("firewall", "rule", &s, §_name); - dmuci_set_value_by_section(s, "name", rule_name); - dmuci_set_value_by_section(s, "dest", "lan"); - dmuci_set_value_by_section(s, "src", "wan"); - dmuci_set_value_by_section(s, "target", "ACCEPT"); - - dmuci_add_section_bbfdm("dmmap_firewall", "rule", &dmmap_firewall_rule, &v); - dmuci_set_value_by_section(dmmap_firewall_rule, "section_name", sect_name); - *instance = update_instance_bbfdm(dmmap_firewall_rule, last_inst, "firewall_chain_rule_instance"); - return 0; -} - -int delete_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; - int found = 0; - - switch (del_action) { - case DEL_INST: - if (is_section_unnamed(section_name((struct uci_section *)data))) { - LIST_HEAD(dup_list); - delete_sections_save_next_sections("dmmap_firewall", "rule", "firewall_chain_rule_instance", section_name((struct uci_section *)data), atoi(instance), &dup_list); - update_dmmap_sections(&dup_list, "firewall_chain_rule_instance", "dmmap_firewall", "rule"); - dmuci_delete_by_section_unnamed((struct uci_section *)data, NULL, NULL); - } else { - get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); - dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); - } - break; - case DEL_ALL: - uci_foreach_sections("firewall", "rule", s) { - if (found != 0) { - get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ss), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ss), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - } - return 0; -} - -/***************************************** Set/Get Parameter functions ***********************/ -int get_firewall_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *path = "/etc/rc.d/*firewall"; - if (check_file(path)) - *value = "1"; - else - *value = "0"; - return 0; -} - -int get_firewall_config(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Advanced"; - return 0; -} - -int get_firewall_advanced_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Device.Firewall.Level.1."; - return 0; -} - -int get_firewall_level_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int get_firewall_chain_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int get_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); - return 0; -} - -int get_level_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "description", value); - return 0; -} - -int get_level_chain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Device.Firewall.Chain.1."; - return 0; -} - -int get_level_port_mapping_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - char *v; - - uci_foreach_sections("firewall", "zone", s) { - dmuci_get_value_by_section_string(s, "masq", &v); - if (*v == '1') { - *value = "1"; - return 0; - } - } - *value = "0"; - return 0; -} - -int get_level_default_log_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - char *v; - - uci_foreach_sections("firewall", "zone", s) { - dmuci_get_value_by_section_string(s, "log", &v); - if (*v == '1') { - *value = "1"; - return 0; - } - } - *value = "0"; - return 0; -} - -int get_chain_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int get_chain_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); - return 0; -} - -int get_chain_creator(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Defaults"; - return 0; -} - -/*#Device.Firewall.Chain.{i}.RuleNumberOfEntries!UCI:firewall/rule/*/ -int get_chain_rule_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_foreach_sections("firewall", "rule", s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.Enable!UCI:firewall/rule,@i-1/enabled*/ -int get_rule_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v; - dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &v); - *value = (*v == 'n' || *v == '0' ) ? "0" : "1"; - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.Status!UCI:firewall/rule,@i-1/enabled*/ -int get_rule_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v; - dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &v); - *value = (*v == 'n' || *v == '0') ? "Disabled" : "Enabled"; - return 0; -} - -int get_rule_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dms = NULL; - get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dms); - if (dms) - dmuci_get_value_by_section_string(dms, "firewall_chain_rule_instance", value); - return 0; -} - -int get_rule_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dms = NULL; - get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dms); - if (dms) - dmuci_get_value_by_section_string(dms, "description", value); - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.Target!UCI:firewall/rule,@i-1/target*/ -int get_rule_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v; - - dmuci_get_value_by_section_string((struct uci_section *)data, "target", &v); - if (strcasecmp(v, "Accept") == 0) - *value = "Accept"; - else if (strcasecmp(v, "Reject") == 0) - *value = "Reject"; - else if (strcasecmp(v, "Drop") == 0) - *value = "Drop"; - else if (strcasecmp(v, "MARK") == 0) - *value = "Return"; - else - *value = v; - return 0; -} - -int get_rule_target_chain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *v = NULL, *v1 = NULL; - struct uci_element *e; - char *vallink, *zone, buf[256] = "", *val; - struct uci_section *s = NULL; - - dmuci_get_value_by_section_string((struct uci_section *)data, "src", &zone); - if (zone == NULL || strlen(zone) == 0) - return 0; - - if (strcmp(zone, "*") == 0) { - v = dmcalloc(1, sizeof(struct uci_list)); - uci_list_init(v); - uci_foreach_sections("firewall", "zone", s) { - dmuci_get_value_by_section_list(s, "network", &v1); - uci_add_list_to_list(v1, v); - } - } else { - uci_foreach_sections("firewall", "zone", s) { - dmuci_get_value_by_section_string(s, "name", &val); - if (strcmp(val, zone) == 0) { - dmuci_get_value_by_section_list(s, "network", &v); - break; - } - } - } - - if (v != NULL) { - uci_foreach_element(v, e) { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), e->name, &vallink); - if (*vallink == '\0') - continue; - if (*buf != '\0') - strcat(buf, ","); - strcat(buf, vallink); - } - } else { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), zone, &vallink); - strcpy(buf, vallink); - } - - *value = dmstrdup(buf); - return 0; -} - -int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *v = NULL; - struct uci_element *e; - char *zone, *ifaceobj, buf[256] = "", *val; - struct uci_section *s = NULL; - - dmuci_get_value_by_section_string((struct uci_section *)data, "dest", &zone); - uci_foreach_sections("firewall", "zone", s) { - dmuci_get_value_by_section_string(s, "name", &val); - if (strcmp(val, zone) == 0) { - dmuci_get_value_by_section_list(s, "network", &v); - break; - } - } - if (v != NULL) { - uci_foreach_element(v, e) { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), e->name, &ifaceobj); - if (*ifaceobj == '\0') - continue; - if (*buf != '\0') - strcat(buf, ","); - strcat(buf, ifaceobj); - } - } - - *value = dmstrdup(buf); - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.IPVersion!UCI:firewall/rule,@i-1/family*/ -int get_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *ipversion; - - dmuci_get_value_by_section_string((struct uci_section *)data, "family", &ipversion); - if (strcasecmp(ipversion, "ipv4") == 0) { - *value = "4"; - } else if (strcasecmp(ipversion, "ipv6") == 0) { - *value = "6"; - } else { - *value = "-1"; - } - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.DestIp!UCI:firewall/rule,@i-1/dest_ip*/ -int get_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char buf[64], *pch, *destip; - - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip); - strcpy(buf, destip); - pch = strchr(buf, '/'); - if (pch) *pch = '\0'; - *value = dmstrdup(buf); - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.DestMask!UCI:firewall/rule,@i-1/dest_ip*/ -int get_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *pch, *destip; - - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip); - if (*destip == '\0') - return 0; - - pch = strchr(destip, '/'); - if (pch) { - *value = pch+1; - } else { - *value = ""; - } - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.SourceIp!UCI:firewall/rule,@i-1/src_ip*/ -int get_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char buf[64], *pch, *srcip; - - dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip); - strcpy(buf, srcip); - pch = strchr(buf, '/'); - if (pch) - *pch = '\0'; - *value = dmstrdup(buf); - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.SourceMask!UCI:firewall/rule,@i-1/src_ip*/ -int get_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *pch, *srcip; - *value = ""; - - dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip); - if (*srcip == '\0') - return 0; - - pch = strchr(srcip, '/'); - if (pch) { - *value = pch+1; - } else { - *value = ""; - } - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.Protocol!UCI:firewall/rule,@i-1/proto*/ -int get_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - FILE *fp; - char *v, buf[256], protocol[32], protocol_nbr[16]; - - dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &v); - *value = "-1"; - if (*v == '\0' || *v == '0') { - return 0; - } - if (isdigit_str(v)) { - *value = v; - return 0; - } - fp = fopen("/etc/protocols", "r"); - if (fp == NULL) - return 0; - while (fgets (buf , 256 , fp) != NULL) { - sscanf(buf, "%31s %15s", protocol, protocol_nbr); - if (strcmp(protocol, v) == 0) { - *value = dmstrdup(protocol_nbr); - fclose(fp); - return 0; - } - } - fclose(fp); - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.DestPort!UCI:firewall/rule,@i-1/dest_port*/ -int get_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *tmp,*v; - - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v); - v = dmstrdup(v); - tmp = strchr(v, ':'); - if (tmp == NULL) - tmp = strchr(v, '-'); - if (tmp) - *tmp = '\0'; - if (*v == '\0') { - *value = "-1"; - return 0; - } - *value = v; - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.DestPortRangeMax!UCI:firewall/rule,@i-1/dest_port*/ -int get_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *tmp, *v; - - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v); - tmp = strchr(v, ':'); - if (tmp == NULL) - tmp = strchr(v, '-'); - *value = (tmp) ? tmp+1 : "-1"; - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.SourcePort!UCI:firewall/rule,@i-1/src_port*/ -int get_rule_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *tmp, *v; - - dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v); - v = dmstrdup(v); - tmp = strchr(v, ':'); - if (tmp == NULL) - tmp = strchr(v, '-'); - if (tmp) - *tmp = '\0'; - if (*v == '\0') { - *value = "-1"; - return 0; - } - *value = v; - return 0; -} - -/*#Device.Firewall.Chain.{i}.Rule.{i}.SourcePortRangeMax!UCI:firewall/rule,@i-1/src_port*/ -int get_rule_source_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *tmp, *v; - - dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v); - tmp = strchr(v, ':'); - if (tmp == NULL) - tmp = strchr(v, '-'); - *value = (tmp) ? tmp+1 : "-1"; - return 0; -} - -int get_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *v= NULL; - struct uci_element *e; - char *ptr; - - dmasprintf(value, "%s", ""); - dmuci_get_value_by_section_list((struct uci_section *)data, "icmp_type", &v); - if (v != NULL) { - uci_foreach_element(v, e) { - ptr = dmstrdup(*value); - dmfree(*value); - - if (strlen(ptr) == 0) - dmasprintf(value, "%s", e->name); - else { - dmasprintf(value, "%s %s", ptr, e->name); - dmfree(ptr); - } - } - } - return 0; -} - -int get_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v = NULL; - dmuci_get_value_by_section_string((struct uci_section *)data, "src_mac", &v); - *value = (v) ? v : ""; - return 0; -} - -int get_time_span_supported_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "mon tue wed thu fri sat sun"; - return 0; -} - -int get_time_span_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v; - dmuci_get_value_by_section_string((struct uci_section *)data, "weekdays", &v); - *value = (v) ? v : ""; - return 0; -} - -int get_time_span_start_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v; - dmuci_get_value_by_section_string((struct uci_section *)data, "start_time", &v); - *value = (v) ? v : ""; - return 0; -} - -int get_time_span_stop_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v; - dmuci_get_value_by_section_string((struct uci_section *)data, "stop_time", &v); - *value = (v) ? v : ""; - return 0; -} - -int set_firewall_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmcmd("/etc/init.d/firewall", 1, b ? "enable" : "disable"); - break; - } - return 0; -} - -int set_firewall_config(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, Config, NULL)) - return FAULT_9007; - break; - case VALUESET: - if (strcasecmp(value, "Advanced") != 0) - return FAULT_9007; - break; - } - return 0; -} - -int set_firewall_advanced_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - if (strcasecmp(value, "Device.Firewall.Level.1.") != 0) - return FAULT_9007; - break; - } - return 0; -} - -int set_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - DMUCI_SET_VALUE_BY_SECTION(bbfdm, (struct uci_section *)data, "name", value); - break; - } - return 0; -} - -int set_level_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - DMUCI_SET_VALUE_BY_SECTION(bbfdm, (struct uci_section *)data, "description", value); - break; - } - return 0; -} - -int set_level_port_mapping_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - struct uci_section *s = NULL; - char *v, *v2; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - if (b) { - uci_foreach_sections("firewall", "zone", s) { - dmuci_get_value_by_section_string(s, "src", &v); - dmuci_get_value_by_section_string(s, "name", &v2); - if (strcasestr(v, "wan") || strcasestr(v2, "wan")) { - dmuci_set_value_by_section(s, "masq", "1"); - return 0; - } - } - } else { - uci_foreach_sections("firewall", "zone", s) { - dmuci_set_value_by_section(s, "masq", ""); - } - } - break; - } - return 0; -} - -int set_level_default_log_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - if (b) { - uci_foreach_sections("firewall", "zone", s) { - dmuci_set_value_by_section(s, "log", "1"); - } - } else { - uci_foreach_sections("firewall", "zone", s) { - dmuci_set_value_by_section(s, "log", ""); - } - } - break; - } - return 0; -} - -int set_chain_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int set_chain_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - DMUCI_SET_VALUE_BY_SECTION(bbfdm, (struct uci_section *)data, "name", value); - break; - } - return 0; -} - -int set_rule_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "" : "no"); - break; - } - return 0; -} - -int set_rule_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int set_rule_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dms = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dms); - if (dms) - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dms, "description", value); - break; - } - return 0; -} - -int set_rule_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, Target, NULL)) - return FAULT_9007; - break; - case VALUESET: - if (strcasecmp(value, "Accept") == 0) - dmuci_set_value_by_section((struct uci_section *)data, "target", "ACCEPT"); - else if (strcasecmp(value, "Reject") == 0) - dmuci_set_value_by_section((struct uci_section *)data, "target", "REJECT"); - else if (strcasecmp(value, "Drop") == 0) - dmuci_set_value_by_section((struct uci_section *)data, "target", "DROP"); - else if (strcasecmp(value, "Return") == 0) - dmuci_set_value_by_section((struct uci_section *)data, "target", "MARK"); - break; - } - return 0; -} - -int set_rule_target_chain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int set_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *iface, *zone, *net; - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - - adm_entry_get_linker_value(ctx, value, &iface); - if (iface == NULL || iface[0] == '\0') - return FAULT_9007; - break; - case VALUESET: - adm_entry_get_linker_value(ctx, value, &iface); - if (iface && iface[0] != '\0') { - uci_foreach_sections("firewall", "zone", s) { - dmuci_get_value_by_section_string(s, "network", &net); - if (dm_strword(net, iface)) { - dmuci_get_value_by_section_string(s, "name", &zone); - dmuci_set_value_by_section((struct uci_section *)data, "src", zone); - break; - } - } - } - break; - } - return 0; -} - -int set_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *iface, *zone, *net; - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - adm_entry_get_linker_value(ctx, value, &iface); - if (iface != NULL && iface[0] != '\0') { - uci_foreach_sections("firewall", "zone", s) { - dmuci_get_value_by_section_string(s, "name", &net); - if (dm_strword(net, iface)) { - dmuci_get_value_by_section_string(s, "name", &zone); - dmuci_set_value_by_section((struct uci_section *)data, "dest", zone); - break; - } - } - } - break; - } - return 0; -} - -int set_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "15")) - return FAULT_9007; - break; - case VALUESET: - if (strcmp(value, "4") == 0) - dmuci_set_value_by_section((struct uci_section *)data, "family", "ipv4"); - else if (strcmp(value, "6") == 0) - dmuci_set_value_by_section((struct uci_section *)data, "family", "ipv6"); - else if (strcmp(value, "-1") == 0) - dmuci_set_value_by_section((struct uci_section *)data, "family", ""); - break; - } - return 0; -} - -int set_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char buf[64], new[64], *pch, *destip; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) - return FAULT_9007; - break; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip); - strcpy(buf, destip); - pch = strchr(buf, '/'); - if (pch) - snprintf(new, sizeof(new), "%s%s", value, pch); - else - strcpy(new, value); - dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", new); - break; - } - return 0; -} - -int set_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char buf[64], new[64], *pch, *destip; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "49", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip); - strcpy(buf, destip); - pch = strchr(buf, '/'); - if (pch) - *pch = '\0'; - snprintf(new, sizeof(new), "%s/%s", buf, value); - dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", new); - break; - } - return 0; -} - -int set_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char buf[64], new[64], *pch, *srcip; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) - return FAULT_9007; - break; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip); - strcpy(buf, srcip); - pch = strchr(buf, '/'); - if (pch) - snprintf(new, sizeof(new), "%s%s", value, pch); - else - strcpy(new, value); - dmuci_set_value_by_section((struct uci_section *)data, "src_ip", new); - break; - } - return 0; -} - -int set_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char buf[64], new[64], *pch, *srcip; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "49", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip); - strcpy(buf, srcip); - pch = strchr(buf, '/'); - if (pch) - *pch = '\0'; - snprintf(new, sizeof(new), "%s/%s", buf, value); - dmuci_set_value_by_section((struct uci_section *)data, "src_ip", new); - break; - } - return 0; -} - -int set_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "255")) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "proto", (*value == '-') ? "" : value); - break; - } - return 0; -} - -int set_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char buffer[64], *v, *tmp = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "65535")) - return FAULT_9007; - break; - case VALUESET: - if (*value == '-') - value = ""; - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v); - tmp = strchr(v, ':'); - if (tmp == NULL) - tmp = strchr(v, '-'); - if (tmp == NULL) - snprintf(buffer, sizeof(buffer), "%s", value); - else - snprintf(buffer, sizeof(buffer), "%s%s", value, tmp); - dmuci_set_value_by_section((struct uci_section *)data, "dest_port", buffer); - break; - } - return 0; -} - -int set_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *v, *tmp, *buf, buffer[64]; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "65535")) - return FAULT_9007; - break; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v); - buf = dmstrdup(v); - v = buf; - tmp = strchr(buf, ':'); - if (tmp == NULL) - tmp = strchr(v, '-'); - if (tmp) - *tmp = '\0'; - if (*value == '-') - snprintf(buffer, sizeof(buffer), "%s", v); - else - snprintf(buffer, sizeof(buffer), "%s:%s", v, value); - dmfree(buf); - dmuci_set_value_by_section((struct uci_section *)data, "dest_port", buffer); - break; - } - return 0; -} - -int set_rule_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char buffer[64], *v, *tmp = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "65535")) - return FAULT_9007; - break; - case VALUESET: - if (*value == '-') - value = ""; - dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v); - tmp = strchr(v, ':'); - if (tmp == NULL) - tmp = strchr(v, '-'); - if (tmp == NULL) - snprintf(buffer, sizeof(buffer), "%s", value); - else - snprintf(buffer, sizeof(buffer), "%s%s", value, tmp); - dmuci_set_value_by_section((struct uci_section *)data, "src_port", buffer); - break; - } - return 0; -} - -int set_rule_source_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *v, *tmp, *buf, buffer[64]; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "65535")) - return FAULT_9007; - break; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v); - buf = dmstrdup(v); - v = buf; - tmp = strchr(buf, ':'); - if (tmp == NULL) - tmp = strchr(buf, '-'); - if (tmp) - *tmp = '\0'; - if (*value == '-') - snprintf(buffer, sizeof(buffer), "%s", v); - else - snprintf(buffer, sizeof(buffer), "%s:%s", v, value); - dmfree(buf); - dmuci_set_value_by_section((struct uci_section *)data, "src_port", buffer); - break; - } - return 0; -} - -int set_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - int i; - size_t length; - char **devices = NULL; - - switch (action) { - case VALUECHECK: - //TODO - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "icmp_type", ""); - devices = strsplit(value, " ", &length); - for (i = 0; i < length; i++) - dmuci_add_list_value_by_section((struct uci_section *)data, "icmp_type", devices[i]); - break; - } - return 0; -} - -int set_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - //TODO - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "src_mac", value); - break; - } - return 0; -} - -int set_time_span_supported_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - //TODO - break; - case VALUESET: - break; - } - return 0; -} - -int set_time_span_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - //TODO - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "weekdays", value); - break; - } - return 0; -} - -int set_time_span_start_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - //TODO - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "start_time", value); - break; - } - return 0; -} - -int set_time_span_stop_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - //TODO - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "stop_time", value); - break; - } - return 0; -} diff --git a/dmtree/tr181/firewall.h b/dmtree/tr181/firewall.h index bc17d11a..385819b2 100644 --- a/dmtree/tr181/firewall.h +++ b/dmtree/tr181/firewall.h @@ -22,79 +22,4 @@ extern DMLEAF tFirewallChainRuleParams[]; extern DMOBJ tFirewallChainRuleObj[]; extern DMLEAF tTimeSpanParams[]; -int browseLevelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseChainInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseRuleInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int add_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delete_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int get_firewall_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_firewall_config(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_firewall_advanced_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_firewall_level_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_firewall_chain_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_level_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_level_chain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_level_port_mapping_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_level_default_log_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_chain_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_chain_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_chain_creator(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_chain_rule_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_target_chain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_source_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_span_supported_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_span_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_span_start_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_span_stop_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_firewall_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_firewall_config(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_firewall_advanced_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_level_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_level_port_mapping_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_level_default_log_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_chain_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_chain_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_target_chain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_source_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_time_span_supported_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_time_span_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_time_span_start_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_time_span_stop_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); #endif diff --git a/dmtree/tr181/gre.c b/dmtree/tr181/gre.c index 40bb2965..ed054876 100644 --- a/dmtree/tr181/gre.c +++ b/dmtree/tr181/gre.c @@ -10,6 +10,894 @@ #include "gre.h" + +/************************************************************* +* ENTRY METHOD +*************************************************************/ +static int browseGRETunnelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *gretun_inst= NULL, *gretun_inst_last= NULL; + struct dmmap_dup *p= NULL; + + LIST_HEAD(dup_list); + synchronize_specific_config_sections_with_dmmap_eq("network", "interface", "dmmap_network", "proto", "gre", &dup_list); + list_for_each_entry(p, &dup_list, list) { + gretun_inst = handle_update_instance(1, dmctx, &gretun_inst_last, update_instance_alias, 3, p->dmmap_section, "gretunnel_instance", "gretunnel_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, gretun_inst) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int browseGREFilterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + //TODO + return 0; +} + +struct uci_section *has_tunnel_interface_route(char *interface) +{ + struct uci_section *s; + + uci_foreach_option_eq("network", "route", "interface", interface, s) { + return s; + } + return NULL; +} + +static int browseGRETunnelInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *greiface_inst= NULL, *greiface_inst_last= NULL, *ifname= NULL; + struct dmmap_dup *p, *dm= (struct dmmap_dup *)prev_data; + struct uci_section *s; + + LIST_HEAD(dup_list); + dmasprintf(&ifname, "@%s", section_name(dm->config_section)); + synchronize_specific_config_sections_with_dmmap_eq("network", "interface", "dmmap_network", "ifname", ifname, &dup_list); + list_for_each_entry(p, &dup_list, list) { + if ((s = has_tunnel_interface_route(section_name(p->config_section))) == NULL) + continue; + greiface_inst = handle_update_instance(1, dmctx, &greiface_inst_last, update_instance_alias, 3, p->dmmap_section, "greiface_instance", "greiface_alias"); + p->additional_attribute= dm->config_section; + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, greiface_inst) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +/************************************************************* +* ADD & DEL OBJ +*************************************************************/ +static int addObjGRETunnel(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + char *value, *v, *instance; + struct uci_section *gre_sec = NULL, *dmmap_sec = NULL; + + check_create_dmmap_package("dmmap_network"); + instance = get_last_instance_lev2_bbfdm("network", "interface", "dmmap_network", "gretunnel_instance", "proto", "gre"); + + dmuci_add_section("network", "interface", &gre_sec, &value); + dmuci_set_value_by_section(gre_sec, "proto", "gre"); + + dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_sec, &v); + dmuci_set_value_by_section(dmmap_sec, "section_name", section_name(gre_sec)); + *instancepara = update_instance_bbfdm(dmmap_sec, instance, "gretunnel_instance"); + return 0; +} + +static int delObjGRETunnel(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; + int found = 0; + + switch (del_action) { + case DEL_INST: + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); + if (dmmap_section != NULL) { + dmuci_set_value_by_section(dmmap_section, "gretunnel_instance", ""); + dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", ""); + } + dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_option_eq("network", "interface", "proto", "gre", s) { + if (found != 0) { + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) { + dmuci_set_value_by_section(dmmap_section, "gretunnel_instance", ""); + dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", ""); + } + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL){ + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) { + dmuci_set_value_by_section(dmmap_section, "gretunnel_instance", ""); + dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", ""); + } + dmuci_delete_by_section(ss, NULL, NULL); + } + break; + } + return 0; +} + +static int addObjGREFilter(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + //TODO + return 0; +} + +static int delObjGREFilter(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + switch (del_action) { + case DEL_INST: + //TODO + break; + case DEL_ALL: + //TODO + break; + } + return 0; +} + +static int addObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + char *value, *v, *instance, *ifname; + struct uci_section *greiface_sec = NULL, *dmmap_sec= NULL, *route_sec= NULL; + + check_create_dmmap_package("dmmap_network"); + instance= get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network", "interface", "greiface_instance", "gre_tunnel_sect", section_name(((struct dmmap_dup *)data)->config_section)); + + dmuci_add_section("network", "interface", &greiface_sec, &value); + dmasprintf(&ifname, "@%s", section_name(((struct dmmap_dup *)data)->config_section)); + dmuci_set_value_by_section(greiface_sec, "ifname", ifname); + + dmuci_add_section("network", "route", &route_sec, &value); + dmuci_set_value_by_section(route_sec, "interface", section_name(greiface_sec)); + + dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_sec, &v); + dmuci_set_value_by_section(dmmap_sec, "section_name", section_name(greiface_sec)); + dmuci_set_value_by_section(dmmap_sec, "gre_tunnel_sect", section_name(((struct dmmap_dup *)data)->config_section)); + *instancepara = update_instance_bbfdm(dmmap_sec, instance, "greiface_instance"); + return 0; +} + +static int delObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s = NULL, *ss = NULL, *s1 = NULL, *dmmap_section = NULL; + int found = 0; + char *iface = NULL, *atiface = NULL; + + switch (del_action) { + case DEL_INST: + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); + if (dmmap_section != NULL) { + dmuci_set_value_by_section(dmmap_section, "greiface_instance", ""); + dmuci_set_value_by_section(dmmap_section, "greiface_alias", ""); + } + if ((s = has_tunnel_interface_route(section_name(((struct dmmap_dup *)data)->config_section))) != NULL) + dmuci_delete_by_section(s, NULL, NULL); + dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("network", "interface", s) { + dmuci_get_value_by_section_string(s, "ifname", &iface); + dmasprintf(&atiface, "@%s", section_name(((struct dmmap_dup *)data)->config_section)); + + if(!iface || strcmp(iface, atiface) != 0) + continue; + if (found != 0){ + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) { + dmuci_set_value_by_section(dmmap_section, "greiface_instance", ""); + dmuci_set_value_by_section(dmmap_section, "greiface_alias", ""); + } + if ((s1 = has_tunnel_interface_route(section_name(ss))) != NULL) + dmuci_delete_by_section(s1, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL){ + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) { + dmuci_set_value_by_section(dmmap_section, "greiface_instance", ""); + dmuci_set_value_by_section(dmmap_section, "greiface_alias", ""); + } + if ((s1 = has_tunnel_interface_route(section_name(ss))) != NULL) + dmuci_delete_by_section(s1, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + break; + } + return 0; +} + +/************************************************************* +* GET & SET PARAM +*************************************************************/ +static char *get_gre_tunnel_interface_statistics(char *interface, char *key) +{ + json_object *res = NULL, *diag = NULL; + char *device, *value = "0"; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); + if (!res) return value; + device = dmjson_get_value(res, 1, "device"); + if(device[0] != '\0') { + dmubus_call("network.device", "status", UBUS_ARGS{{"name", device, String}}, 1, &diag); + if (diag) + value = dmjson_get_value(diag, 2, "statistics", key); + } + return value; +} + +static int get_GRE_TunnelNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s= NULL; + int i= 0; + uci_foreach_option_eq("network", "interface", "proto", "gre", s) { + i++; + } + dmasprintf(value, "%d", i); + return 0; +} + +static int get_GRE_FilterNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_GRETunnel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnel_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_GRETunnel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "gretunnel_alias", value); + return 0; +} + +static int set_GRETunnel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", value); + break; + } + return 0; +} + +static int get_GRETunnel_RemoteEndpoints(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnel_RemoteEndpoints(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, "4", NULL, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnel_KeepAlivePolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnel_KeepAlivePolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, KeepAlivePolicy, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnel_KeepAliveTimeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnel_KeepAliveTimeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnel_KeepAliveThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "keepalive", value); + return 0; +} + +static int set_GRETunnel_KeepAliveThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "keepalive", value); + break; + } + return 0; +} + +static int get_GRETunnel_DeliveryHeaderProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnel_DeliveryHeaderProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, DeliveryHeaderProtocol, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnel_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnel_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnel_ConnectedRemoteEndpoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "peeraddr", value); + return 0; +} + +static int get_GRETunnel_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + char *ifname; + int i = 0; + + dmasprintf(&ifname, "@%s", section_name(((struct dmmap_dup *)data)->config_section)); + uci_foreach_option_eq("network", "interface", "ifname", ifname, s) { + i++; + } + dmasprintf(value, "%d", i); + return 0; +} + +static int get_GRETunnelStats_KeepAliveSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_GRETunnelStats_KeepAliveReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_GRETunnelStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_bytes"); + return 0; +} + +static int get_GRETunnelStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_bytes"); + return 0; +} + +static int get_GRETunnelStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_packets"); + return 0; +} + +static int get_GRETunnelStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_packets"); + return 0; +} + +static int get_GRETunnelStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_errors"); + return 0; +} + +static int get_GRETunnelStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_errors"); + return 0; +} + +static int get_GRETunnelInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnelInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnelInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_GRETunnelInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "greiface_alias", value); + return 0; +} + +static int set_GRETunnelInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "greiface_alias", value); + break; + } + return 0; +} + +static int get_GRETunnelInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(section_name(((struct dmmap_dup *)data)->config_section)); + return 0; +} + +static int get_GRETunnelInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_GRETunnelInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnelInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnelInterface_ProtocolIdOverride(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnelInterface_ProtocolIdOverride(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnelInterface_UseChecksum(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnelInterface_UseChecksum(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnelInterface_KeyIdentifierGenerationPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnelInterface_KeyIdentifierGenerationPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, KeyIdentifierGenerationPolicy, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnelInterface_KeyIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnelInterface_KeyIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnelInterface_UseSequenceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GRETunnelInterface_UseSequenceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GRETunnelInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_bytes"); + return 0; +} + +static int get_GRETunnelInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_bytes"); + return 0; +} + +static int get_GRETunnelInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_packets"); + return 0; +} + +static int get_GRETunnelInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_packets"); + return 0; +} + +static int get_GRETunnelInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_errors"); + return 0; +} + +static int get_GRETunnelInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_errors"); + return 0; +} + +static int get_GRETunnelInterfaceStats_DiscardChecksumReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_GRETunnelInterfaceStats_DiscardSequenceNumberReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_GREFilter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GREFilter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GREFilter_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_GREFilter_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GREFilter_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GREFilter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GREFilter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GREFilter_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GREFilter_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GREFilter_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GREFilter_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GREFilter_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GREFilter_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GREFilter_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GREFilter_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_GREFilter_DSCPMarkPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_GREFilter_DSCPMarkPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", "63")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + /* *** Device.GRE. *** */ DMOBJ tGREObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nexjsontobj, nextobj, leaf, linker, bbfdm_type*/ @@ -114,891 +1002,3 @@ DMLEAF tGREFilterParams[] = { //{"DSCPMarkPolicy", &DMWRITE, DMT_INT, get_GREFilter_DSCPMarkPolicy, set_GREFilter_DSCPMarkPolicy, NULL, NULL, BBFDM_BOTH}, {0} }; - -/************************************************************* -* ENTRY METHOD -*************************************************************/ -int browseGRETunnelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *gretun_inst= NULL, *gretun_inst_last= NULL; - struct dmmap_dup *p= NULL; - - LIST_HEAD(dup_list); - synchronize_specific_config_sections_with_dmmap_eq("network", "interface", "dmmap_network", "proto", "gre", &dup_list); - list_for_each_entry(p, &dup_list, list) { - gretun_inst = handle_update_instance(1, dmctx, &gretun_inst_last, update_instance_alias, 3, p->dmmap_section, "gretunnel_instance", "gretunnel_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, gretun_inst) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int browseGREFilterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - //TODO - return 0; -} - -struct uci_section *has_tunnel_interface_route(char *interface) -{ - struct uci_section *s; - - uci_foreach_option_eq("network", "route", "interface", interface, s) { - return s; - } - return NULL; -} - -int browseGRETunnelInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *greiface_inst= NULL, *greiface_inst_last= NULL, *ifname= NULL; - struct dmmap_dup *p, *dm= (struct dmmap_dup *)prev_data; - struct uci_section *s; - - LIST_HEAD(dup_list); - dmasprintf(&ifname, "@%s", section_name(dm->config_section)); - synchronize_specific_config_sections_with_dmmap_eq("network", "interface", "dmmap_network", "ifname", ifname, &dup_list); - list_for_each_entry(p, &dup_list, list) { - if ((s = has_tunnel_interface_route(section_name(p->config_section))) == NULL) - continue; - greiface_inst = handle_update_instance(1, dmctx, &greiface_inst_last, update_instance_alias, 3, p->dmmap_section, "greiface_instance", "greiface_alias"); - p->additional_attribute= dm->config_section; - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, greiface_inst) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -/************************************************************* -* ADD & DEL OBJ -*************************************************************/ -int addObjGRETunnel(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - char *value, *v, *instance; - struct uci_section *gre_sec = NULL, *dmmap_sec = NULL; - - check_create_dmmap_package("dmmap_network"); - instance = get_last_instance_lev2_bbfdm("network", "interface", "dmmap_network", "gretunnel_instance", "proto", "gre"); - - dmuci_add_section("network", "interface", &gre_sec, &value); - dmuci_set_value_by_section(gre_sec, "proto", "gre"); - - dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_sec, &v); - dmuci_set_value_by_section(dmmap_sec, "section_name", section_name(gre_sec)); - *instancepara = update_instance_bbfdm(dmmap_sec, instance, "gretunnel_instance"); - return 0; -} - -int delObjGRETunnel(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; - int found = 0; - - switch (del_action) { - case DEL_INST: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); - if (dmmap_section != NULL) { - dmuci_set_value_by_section(dmmap_section, "gretunnel_instance", ""); - dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", ""); - } - dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL); - break; - case DEL_ALL: - uci_foreach_option_eq("network", "interface", "proto", "gre", s) { - if (found != 0) { - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) { - dmuci_set_value_by_section(dmmap_section, "gretunnel_instance", ""); - dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", ""); - } - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL){ - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) { - dmuci_set_value_by_section(dmmap_section, "gretunnel_instance", ""); - dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", ""); - } - dmuci_delete_by_section(ss, NULL, NULL); - } - break; - } - return 0; -} - -int addObjGREFilter(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - //TODO - return 0; -} - -int delObjGREFilter(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - switch (del_action) { - case DEL_INST: - //TODO - break; - case DEL_ALL: - //TODO - break; - } - return 0; -} - -int addObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - char *value, *v, *instance, *ifname; - struct uci_section *greiface_sec = NULL, *dmmap_sec= NULL, *route_sec= NULL; - - check_create_dmmap_package("dmmap_network"); - instance= get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network", "interface", "greiface_instance", "gre_tunnel_sect", section_name(((struct dmmap_dup *)data)->config_section)); - - dmuci_add_section("network", "interface", &greiface_sec, &value); - dmasprintf(&ifname, "@%s", section_name(((struct dmmap_dup *)data)->config_section)); - dmuci_set_value_by_section(greiface_sec, "ifname", ifname); - - dmuci_add_section("network", "route", &route_sec, &value); - dmuci_set_value_by_section(route_sec, "interface", section_name(greiface_sec)); - - dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_sec, &v); - dmuci_set_value_by_section(dmmap_sec, "section_name", section_name(greiface_sec)); - dmuci_set_value_by_section(dmmap_sec, "gre_tunnel_sect", section_name(((struct dmmap_dup *)data)->config_section)); - *instancepara = update_instance_bbfdm(dmmap_sec, instance, "greiface_instance"); - return 0; -} - -int delObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *s = NULL, *ss = NULL, *s1 = NULL, *dmmap_section = NULL; - int found = 0; - char *iface = NULL, *atiface = NULL; - - switch (del_action) { - case DEL_INST: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); - if (dmmap_section != NULL) { - dmuci_set_value_by_section(dmmap_section, "greiface_instance", ""); - dmuci_set_value_by_section(dmmap_section, "greiface_alias", ""); - } - if ((s = has_tunnel_interface_route(section_name(((struct dmmap_dup *)data)->config_section))) != NULL) - dmuci_delete_by_section(s, NULL, NULL); - dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL); - break; - case DEL_ALL: - uci_foreach_sections("network", "interface", s) { - dmuci_get_value_by_section_string(s, "ifname", &iface); - dmasprintf(&atiface, "@%s", section_name(((struct dmmap_dup *)data)->config_section)); - - if(!iface || strcmp(iface, atiface) != 0) - continue; - if (found != 0){ - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) { - dmuci_set_value_by_section(dmmap_section, "greiface_instance", ""); - dmuci_set_value_by_section(dmmap_section, "greiface_alias", ""); - } - if ((s1 = has_tunnel_interface_route(section_name(ss))) != NULL) - dmuci_delete_by_section(s1, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL){ - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) { - dmuci_set_value_by_section(dmmap_section, "greiface_instance", ""); - dmuci_set_value_by_section(dmmap_section, "greiface_alias", ""); - } - if ((s1 = has_tunnel_interface_route(section_name(ss))) != NULL) - dmuci_delete_by_section(s1, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - break; - } - return 0; -} - -/************************************************************* -* GET & SET PARAM -*************************************************************/ -static char *get_gre_tunnel_interface_statistics(char *interface, char *key) -{ - json_object *res = NULL, *diag = NULL; - char *device, *value = "0"; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); - if (!res) return value; - device = dmjson_get_value(res, 1, "device"); - if(device[0] != '\0') { - dmubus_call("network.device", "status", UBUS_ARGS{{"name", device, String}}, 1, &diag); - if (diag) - value = dmjson_get_value(diag, 2, "statistics", key); - } - return value; -} - -int get_GRE_TunnelNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s= NULL; - int i= 0; - uci_foreach_option_eq("network", "interface", "proto", "gre", s) { - i++; - } - dmasprintf(value, "%d", i); - return 0; -} - -int get_GRE_FilterNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_GRETunnel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnel_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_GRETunnel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "gretunnel_alias", value); - return 0; -} - -int set_GRETunnel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", value); - break; - } - return 0; -} - -int get_GRETunnel_RemoteEndpoints(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnel_RemoteEndpoints(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, "4", NULL, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnel_KeepAlivePolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnel_KeepAlivePolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, KeepAlivePolicy, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnel_KeepAliveTimeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnel_KeepAliveTimeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnel_KeepAliveThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "keepalive", value); - return 0; -} - -int set_GRETunnel_KeepAliveThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "keepalive", value); - break; - } - return 0; -} - -int get_GRETunnel_DeliveryHeaderProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnel_DeliveryHeaderProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, DeliveryHeaderProtocol, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnel_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnel_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnel_ConnectedRemoteEndpoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "peeraddr", value); - return 0; -} - -int get_GRETunnel_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - char *ifname; - int i = 0; - - dmasprintf(&ifname, "@%s", section_name(((struct dmmap_dup *)data)->config_section)); - uci_foreach_option_eq("network", "interface", "ifname", ifname, s) { - i++; - } - dmasprintf(value, "%d", i); - return 0; -} - -int get_GRETunnelStats_KeepAliveSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_GRETunnelStats_KeepAliveReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_GRETunnelStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_bytes"); - return 0; -} - -int get_GRETunnelStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_bytes"); - return 0; -} - -int get_GRETunnelStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_packets"); - return 0; -} - -int get_GRETunnelStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_packets"); - return 0; -} - -int get_GRETunnelStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_errors"); - return 0; -} - -int get_GRETunnelStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value= get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_errors"); - return 0; -} - -int get_GRETunnelInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnelInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnelInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_GRETunnelInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "greiface_alias", value); - return 0; -} - -int set_GRETunnelInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "greiface_alias", value); - break; - } - return 0; -} - -int get_GRETunnelInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(section_name(((struct dmmap_dup *)data)->config_section)); - return 0; -} - -int get_GRETunnelInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_GRETunnelInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnelInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnelInterface_ProtocolIdOverride(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnelInterface_ProtocolIdOverride(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnelInterface_UseChecksum(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnelInterface_UseChecksum(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnelInterface_KeyIdentifierGenerationPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnelInterface_KeyIdentifierGenerationPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, KeyIdentifierGenerationPolicy, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnelInterface_KeyIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnelInterface_KeyIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnelInterface_UseSequenceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GRETunnelInterface_UseSequenceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GRETunnelInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_bytes"); - return 0; -} - -int get_GRETunnelInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_bytes"); - return 0; -} - -int get_GRETunnelInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_packets"); - return 0; -} - -int get_GRETunnelInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_packets"); - return 0; -} - -int get_GRETunnelInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "tx_errors"); - return 0; -} - -int get_GRETunnelInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_gre_tunnel_interface_statistics(section_name(((struct dmmap_dup *)data)->config_section), "rx_errors"); - return 0; -} - -int get_GRETunnelInterfaceStats_DiscardChecksumReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_GRETunnelInterfaceStats_DiscardSequenceNumberReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_GREFilter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GREFilter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GREFilter_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_GREFilter_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GREFilter_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GREFilter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GREFilter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GREFilter_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GREFilter_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GREFilter_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GREFilter_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GREFilter_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GREFilter_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GREFilter_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GREFilter_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_GREFilter_DSCPMarkPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_GREFilter_DSCPMarkPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", "63")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - diff --git a/dmtree/tr181/gre.h b/dmtree/tr181/gre.h index 0c414e54..991867ee 100644 --- a/dmtree/tr181/gre.h +++ b/dmtree/tr181/gre.h @@ -23,90 +23,5 @@ extern DMLEAF tGRETunnelInterfaceParams[]; extern DMLEAF tGRETunnelInterfaceStatsParams[]; extern DMLEAF tGREFilterParams[]; -int browseGRETunnelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseGREFilterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseGRETunnelInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int addObjGRETunnel(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjGRETunnel(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjGREFilter(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjGREFilter(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_GRE_TunnelNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRE_FilterNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnel_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnel_RemoteEndpoints(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnel_RemoteEndpoints(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnel_KeepAlivePolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnel_KeepAlivePolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnel_KeepAliveTimeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnel_KeepAliveTimeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnel_KeepAliveThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnel_KeepAliveThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnel_DeliveryHeaderProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnel_DeliveryHeaderProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnel_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnel_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnel_ConnectedRemoteEndpoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnel_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelStats_KeepAliveSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelStats_KeepAliveReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnelInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnelInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnelInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnelInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnelInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnelInterface_ProtocolIdOverride(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnelInterface_ProtocolIdOverride(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnelInterface_UseChecksum(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnelInterface_UseChecksum(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnelInterface_KeyIdentifierGenerationPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnelInterface_KeyIdentifierGenerationPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnelInterface_KeyIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnelInterface_KeyIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnelInterface_UseSequenceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GRETunnelInterface_UseSequenceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GRETunnelInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelInterfaceStats_DiscardChecksumReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GRETunnelInterfaceStats_DiscardSequenceNumberReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GREFilter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GREFilter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GREFilter_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_GREFilter_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GREFilter_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GREFilter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GREFilter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GREFilter_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GREFilter_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GREFilter_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GREFilter_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GREFilter_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GREFilter_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GREFilter_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GREFilter_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_GREFilter_DSCPMarkPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_GREFilter_DSCPMarkPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif //__GRE_H diff --git a/dmtree/tr181/hosts.c b/dmtree/tr181/hosts.c index c15ad873..d7e55915 100644 --- a/dmtree/tr181/hosts.c +++ b/dmtree/tr181/hosts.c @@ -12,35 +12,10 @@ #include "dmentry.h" #include "hosts.h" -/* *** Device.Hosts. *** */ -DMOBJ tHostsObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Host", &DMREAD, NULL, NULL, NULL, browsehostInst, NULL, NULL, NULL, NULL, tHostsHostParams, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF tHostsParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"HostNumberOfEntries", &DMREAD, DMT_UNINT, get_host_nbr_entries, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.Hosts.Host.{i}. *** */ -DMLEAF tHostsHostParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"AssociatedDevice", &DMREAD, DMT_STRING, get_host_associateddevice, NULL, NULL, NULL, BBFDM_BOTH}, -{"Layer3Interface", &DMREAD, DMT_STRING, get_host_layer3interface, NULL, NULL, NULL, BBFDM_BOTH}, -{"IPAddress", &DMREAD, DMT_STRING, get_host_ipaddress, NULL, NULL, NULL, BBFDM_BOTH}, -{"HostName", &DMREAD, DMT_STRING, get_host_hostname, NULL, NULL, NULL, BBFDM_BOTH}, -{"Active", &DMREAD, DMT_BOOL, get_host_active, NULL, NULL, NULL, BBFDM_BOTH}, -{"PhysAddress", &DMREAD, DMT_STRING, get_host_phy_address, NULL, NULL, NULL, BBFDM_BOTH}, -{CUSTOM_PREFIX"LinkType", &DMREAD, DMT_STRING, get_host_interfacetype, NULL, NULL, NULL, BBFDM_BOTH}, -{"AddressSource", &DMREAD, DMT_STRING, get_host_address_source, NULL, NULL, NULL, BBFDM_BOTH}, -{"LeaseTimeRemaining", &DMREAD, DMT_INT, get_host_leasetime_remaining, NULL, NULL, NULL, BBFDM_BOTH}, -{"DHCPClient", &DMREAD, DMT_STRING, get_host_dhcp_client, NULL, NULL, NULL, BBFDM_BOTH}, -{CUSTOM_PREFIX"InterfaceType", &DMREAD, DMT_STRING, get_host_interface_type, NULL, NULL, NULL, BBFDM_BOTH}, -{CUSTOM_PREFIX"ifname", &DMREAD, DMT_STRING, get_host_interfacename, NULL, NULL, NULL, BBFDM_BOTH}, -{0} +struct host_args +{ + json_object *client; + char *key; }; @@ -56,7 +31,7 @@ static inline int init_host_args(struct host_args *args, json_object *clients, c /************************************************************* * GET & SET PARAM **************************************************************/ -int get_host_associateddevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_associateddevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *ss; char *accesspointInstance = NULL, *wifiAssociativeDeviecPath; @@ -77,7 +52,7 @@ int get_host_associateddevice(char *refparam, struct dmctx *ctx, void *data, cha return 0; } -int get_host_layer3interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_layer3interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *ip_linker=dmjson_get_value(((struct host_args *)data)->client, 1, "network"); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", ip_linker, value); @@ -86,7 +61,7 @@ int get_host_layer3interface(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int get_host_interface_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_interface_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *type= NULL; char *ifname = dmjson_get_value(((struct host_args *)data)->client, 1, "network"); @@ -104,7 +79,7 @@ int get_host_interface_type(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int get_host_interfacename(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_interfacename(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *frequency, *wireless; @@ -123,31 +98,31 @@ int get_host_interfacename(char *refparam, struct dmctx *ctx, void *data, char * return 0; } -int get_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = dmjson_get_value(((struct host_args *)data)->client, 1, "ipaddr"); return 0; } -int get_host_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = dmjson_get_value(((struct host_args *)data)->client, 1, "hostname"); return 0; } -int get_host_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = dmjson_get_value(((struct host_args *)data)->client, 1, "connected"); return 0; } -int get_host_phy_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_phy_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = dmjson_get_value(((struct host_args *)data)->client, 1, "macaddr"); return 0; } -int get_host_address_source(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_address_source(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *dhcp; @@ -159,7 +134,7 @@ int get_host_address_source(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *dhcp; FILE *fp; @@ -200,7 +175,7 @@ int get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, void *data, return 0; } -int get_host_dhcp_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_dhcp_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker; dmasprintf(&linker, "%s", ((struct host_args *)data)->key); @@ -247,7 +222,7 @@ static char *get_interface_type(char *mac, char *ndev) return "Ethernet"; } -int get_host_interfacetype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_interfacetype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *mac, *network; @@ -257,7 +232,7 @@ int get_host_interfacetype(char *refparam, struct dmctx *ctx, void *data, char * return 0; } -int get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int entries = 0; json_object *res; @@ -276,7 +251,7 @@ int get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *in /************************************************************* * ENTRY METHOD **************************************************************/ -int browsehostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browsehostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { json_object *res; char *idx, *idx_last = NULL, *connected; @@ -298,3 +273,33 @@ int browsehostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, ch return 0; } +/* *** Device.Hosts. *** */ +DMOBJ tHostsObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Host", &DMREAD, NULL, NULL, NULL, browsehostInst, NULL, NULL, NULL, NULL, tHostsHostParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tHostsParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"HostNumberOfEntries", &DMREAD, DMT_UNINT, get_host_nbr_entries, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.Hosts.Host.{i}. *** */ +DMLEAF tHostsHostParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"AssociatedDevice", &DMREAD, DMT_STRING, get_host_associateddevice, NULL, NULL, NULL, BBFDM_BOTH}, +{"Layer3Interface", &DMREAD, DMT_STRING, get_host_layer3interface, NULL, NULL, NULL, BBFDM_BOTH}, +{"IPAddress", &DMREAD, DMT_STRING, get_host_ipaddress, NULL, NULL, NULL, BBFDM_BOTH}, +{"HostName", &DMREAD, DMT_STRING, get_host_hostname, NULL, NULL, NULL, BBFDM_BOTH}, +{"Active", &DMREAD, DMT_BOOL, get_host_active, NULL, NULL, NULL, BBFDM_BOTH}, +{"PhysAddress", &DMREAD, DMT_STRING, get_host_phy_address, NULL, NULL, NULL, BBFDM_BOTH}, +{CUSTOM_PREFIX"LinkType", &DMREAD, DMT_STRING, get_host_interfacetype, NULL, NULL, NULL, BBFDM_BOTH}, +{"AddressSource", &DMREAD, DMT_STRING, get_host_address_source, NULL, NULL, NULL, BBFDM_BOTH}, +{"LeaseTimeRemaining", &DMREAD, DMT_INT, get_host_leasetime_remaining, NULL, NULL, NULL, BBFDM_BOTH}, +{"DHCPClient", &DMREAD, DMT_STRING, get_host_dhcp_client, NULL, NULL, NULL, BBFDM_BOTH}, +{CUSTOM_PREFIX"InterfaceType", &DMREAD, DMT_STRING, get_host_interface_type, NULL, NULL, NULL, BBFDM_BOTH}, +{CUSTOM_PREFIX"ifname", &DMREAD, DMT_STRING, get_host_interfacename, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/hosts.h b/dmtree/tr181/hosts.h index e464013e..0dd3c3d6 100644 --- a/dmtree/tr181/hosts.h +++ b/dmtree/tr181/hosts.h @@ -14,30 +14,8 @@ #include -struct host_args -{ - json_object *client; - char *key; -}; - extern DMOBJ tHostsObj[]; extern DMLEAF tHostsParams[]; extern DMLEAF tHostsHostParams[]; -int browsehostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_associateddevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_layer3interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_interface_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_interfacename(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_phy_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_interfacetype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_address_source(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_host_dhcp_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - #endif diff --git a/dmtree/tr181/interfacestack.c b/dmtree/tr181/interfacestack.c index 4c254059..dcd5b855 100644 --- a/dmtree/tr181/interfacestack.c +++ b/dmtree/tr181/interfacestack.c @@ -11,15 +11,11 @@ #include "dmentry.h" #include "interfacestack.h" -/* *** Device.InterfaceStack.{i}. *** */ -DMLEAF tInterfaceStackParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Alias", &DMWRITE, DMT_STRING, get_InterfaceStack_Alias, set_InterfaceStack_Alias, NULL, NULL, BBFDM_BOTH}, -{"HigherLayer", &DMREAD, DMT_STRING, get_InterfaceStack_HigherLayer, NULL, NULL, NULL, BBFDM_BOTH}, -{"LowerLayer", &DMREAD, DMT_STRING, get_InterfaceStack_LowerLayer, NULL, NULL, NULL, BBFDM_BOTH}, -{"HigherAlias", &DMREAD, DMT_STRING, get_InterfaceStack_HigherAlias, NULL, NULL, NULL, BBFDM_BOTH}, -{"LowerAlias", &DMREAD, DMT_STRING, get_InterfaceStack_LowerAlias, NULL, NULL, NULL, BBFDM_BOTH}, -{0} +struct interfacestack_data { + char *lowerlayer; + char *higherlayer; + char *loweralias; + char *higheralias; }; /************************************************************* @@ -473,7 +469,7 @@ int get_Device_InterfaceStackNumberOfEntries(char *refparam, struct dmctx *ctx, return 0; } -int get_InterfaceStack_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_InterfaceStack_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; uci_path_foreach_option_eq(bbfdm, "dmmap_interface_stack", "interface_stack", "interface_stack_instance", instance, s) { @@ -482,7 +478,7 @@ int get_InterfaceStack_Alias(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int set_InterfaceStack_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_InterfaceStack_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s = NULL; @@ -500,26 +496,37 @@ int set_InterfaceStack_Alias(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int get_InterfaceStack_HigherLayer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_InterfaceStack_HigherLayer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = dmstrdup(((struct interfacestack_data *)data)->higherlayer); return 0; } -int get_InterfaceStack_LowerLayer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_InterfaceStack_LowerLayer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = dmstrdup(((struct interfacestack_data *)data)->lowerlayer); return 0; } -int get_InterfaceStack_HigherAlias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_InterfaceStack_HigherAlias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = dmstrdup(((struct interfacestack_data *)data)->higheralias); return 0; } -int get_InterfaceStack_LowerAlias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_InterfaceStack_LowerAlias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = dmstrdup(((struct interfacestack_data *)data)->loweralias); return 0; } + +/* *** Device.InterfaceStack.{i}. *** */ +DMLEAF tInterfaceStackParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Alias", &DMWRITE, DMT_STRING, get_InterfaceStack_Alias, set_InterfaceStack_Alias, NULL, NULL, BBFDM_BOTH}, +{"HigherLayer", &DMREAD, DMT_STRING, get_InterfaceStack_HigherLayer, NULL, NULL, NULL, BBFDM_BOTH}, +{"LowerLayer", &DMREAD, DMT_STRING, get_InterfaceStack_LowerLayer, NULL, NULL, NULL, BBFDM_BOTH}, +{"HigherAlias", &DMREAD, DMT_STRING, get_InterfaceStack_HigherAlias, NULL, NULL, NULL, BBFDM_BOTH}, +{"LowerAlias", &DMREAD, DMT_STRING, get_InterfaceStack_LowerAlias, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/interfacestack.h b/dmtree/tr181/interfacestack.h index 6cd06f09..4535555a 100644 --- a/dmtree/tr181/interfacestack.h +++ b/dmtree/tr181/interfacestack.h @@ -15,22 +15,7 @@ extern DMLEAF tInterfaceStackParams[]; -struct interfacestack_data { - char *lowerlayer; - char *higherlayer; - char *loweralias; - char *higheralias; -}; - +int get_Device_InterfaceStackNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int get_Device_InterfaceStackNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_InterfaceStack_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_InterfaceStack_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_InterfaceStack_HigherLayer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_InterfaceStack_LowerLayer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_InterfaceStack_HigherAlias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_InterfaceStack_LowerAlias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - #endif //__INTERFACESTACK_H diff --git a/dmtree/tr181/ip.c b/dmtree/tr181/ip.c index 695e5c0a..e5b3b8b6 100644 --- a/dmtree/tr181/ip.c +++ b/dmtree/tr181/ip.c @@ -16,8 +16,1922 @@ #include "diagnostics.h" #endif -struct dm_forced_inform_s IPv4INFRM = {0, get_ipv4_finform}; -struct dm_forced_inform_s IPv6INFRM = {0, get_ipv6_finform}; +struct ip_args +{ + struct uci_section *ip_sec; + char *ip_4address; +}; + +struct ipv6_args +{ + struct uci_section *ip_sec; + char *ip_6address; + char *ip_6mask; + char *ip_6preferred; + char *ip_6valid; +}; + +struct ipv6prefix_args +{ + struct uci_section *ip_sec; + char *ip_6prefixaddress; + char *ip_6prefixmask; + char *ip_6prefixpreferred; + char *ip_6prefixvalid; +}; + +static unsigned char get_ipv4_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance) +{ + return 1; +} + +static unsigned char get_ipv6_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance) +{ + return 1; +} + +/************************************************************* +* INIT +**************************************************************/ +static inline int init_ip_args(struct ip_args *args, struct uci_section *s, char *ip_4address) +{ + args->ip_sec = s; + args->ip_4address = ip_4address; + return 0; +} + +static inline int init_ipv6_args(struct ipv6_args *args, struct uci_section *s, char *ip_6address, char *ip_6mask, char *ip_6preferred, char *ip_6valid) +{ + args->ip_sec = s; + args->ip_6address = ip_6address; + args->ip_6mask = ip_6mask; + args->ip_6preferred = ip_6preferred; + args->ip_6valid = ip_6valid; + return 0; +} + +static inline int init_ipv6prefix_args(struct ipv6prefix_args *args, struct uci_section *s, char *ip_6prefixaddress, char *ip_6prefixmask, char *ip_6prefixpreferred, char *ip_6prefixvalid) +{ + args->ip_sec = s; + args->ip_6prefixaddress = ip_6prefixaddress; + args->ip_6prefixmask = ip_6prefixmask; + args->ip_6prefixpreferred = ip_6prefixpreferred; + args->ip_6prefixvalid = ip_6prefixvalid; + return 0; +} + +/************************************************************* +* COMMON Functions +**************************************************************/ +static int get_ip_iface_sysfs(const struct ip_args *ip, const char *name, char **value) +{ + return get_net_iface_sysfs(section_name(ip->ip_sec), name, value); +} + +static char *ubus_call_get_value_with_two_objects(char *interface, char *obj1, char *obj2, char *key) +{ + json_object *res, *jobj1 = NULL, *jobj2 = NULL; + char *value = ""; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); + if (res) { + jobj1 = dmjson_select_obj_in_array_idx(res, 0, 1, obj1); + if(jobj1) + jobj2 = dmjson_get_obj(jobj1, 1, obj2); + if(jobj2) + value = dmjson_get_value(jobj2, 1, key); + } + return value; +} + +static char *ubus_call_get_value(char *interface, char *obj, char *key) +{ + json_object *res, *jobj; + char *value = ""; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, obj); + value = dmjson_get_value(jobj, 1, key); + } + return value; +} + +static char *get_child_prefix_linker(char *interface) +{ + char *address = NULL, *mask = NULL, *value; + json_object *res, *jobj, *jobj1, *jobj2; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); + if(res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-prefix"); + if(jobj) { + jobj1 = dmjson_get_obj(jobj, 1, "assigned"); + if(jobj1) { + jobj2 = dmjson_get_obj(jobj1, 1, "lan"); + if(jobj2) { + address = dmjson_get_value(jobj2, 1, "address"); + mask = dmjson_get_value(jobj2, 1, "mask"); + dmasprintf(&value, "%s/%s", address,mask); + return value; + } + } + } + } + return ""; +} + +/************************************************************* +* GET & SET PARAM +**************************************************************/ +/* + * *** Device.IP. *** + */ +static int get_IP_IPv4Capable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int get_IP_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int set_IP_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_IP_IPv4Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Enabled"; + return 0; +} + +static int get_IP_IPv6Capable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int get_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int set_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_IP_IPv6Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Enabled"; + return 0; +} + +static int get_IP_ULAPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("network", "globals", "ula_prefix", value); + return 0; +} + +static int set_IP_ULAPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "49", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value("network", "globals", "ula_prefix", value); + break; + } + return 0; +} + +static int get_IP_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_foreach_sections("network", "interface", s) { + if (strcmp(section_name(s), "loopback") == 0) + continue; + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +/* + * *** Device.IP.Interface. *** + */ +/*#Device.IP.Interface.{i}.Enable!UCI:network/interface,@i-1/disabled*/ +static int get_IPInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v; + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "disabled", &v); + *value = (*v != '1') ? "1" : "0"; + return 0; +} + +static int set_IPInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "disabled", (b) ? "0" : "1"); + break; + } + return 0; +} + +/*#Device.IP.Interface.{i}.Status!UCI:network/interface,@i-1/disabled*/ +static int get_IPInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + char *val = NULL; + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res); + DM_ASSERT(res, *value = "Down"); + val = dmjson_get_value(res, 1, "up"); + *value = !strcmp(val, "true") ? "Up" : "Down"; + return 0; +} + +static int get_IPInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(section_name(((struct ip_args *)data)->ip_sec)); + return 0; +} + +static int get_IPInterface_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int set_IPInterface_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv6Enable!UCI:network/interface,@i-1/ipv6*/ +static int get_IPInterface_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *v; + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ipv6", &v); + *value = (*v != '0') ? "1" : "0"; + return 0; +} + +static int set_IPInterface_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipv6", (b) ? "" : "0"); + break; + } + return 0; +} + +/*#Device.IP.Interface.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ +static int get_IPInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "uptime"); + return 0; +} + +static int get_IPInterface_Router(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Device.Routing.Router.1."; + return 0; +} + +static int set_IPInterface_Router(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +static int set_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + char *ubus_object; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + if (b) { + dmastrcat(&ubus_object, "network.interface.", section_name(((struct uci_section *)data))); + dmubus_call_set(ubus_object, "down", UBUS_ARGS{}, 0); + dmubus_call_set(ubus_object, "up", UBUS_ARGS{}, 0); + dmfree(ubus_object); + } + break; + } + return 0; +} + +static int get_IPInterface_MaxMTUSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return get_ip_iface_sysfs(data, "mtu", value); +} + +static int set_IPInterface_MaxMTUSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "64", "65535")) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "mtu", value); + break; + } + return 0; +} + +static int get_IPInterface_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if (strcmp(section_name(((struct ip_args *)data)->ip_sec), "loopback") == 0) + *value = "Loopback"; + else + *value = "Normal"; + return 0; +} + +static int get_IPInterface_Loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if (strcmp(section_name(((struct ip_args *)data)->ip_sec), "loopback") == 0) + *value = "1"; + else + *value = "0"; + return 0; +} + +static int set_IPInterface_Loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_IPInterface_IPv4AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + char *inst; + + *value = "0"; + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "interface", "section_name", section_name(((struct ip_args *)data)->ip_sec), s) { + dmuci_get_value_by_section_string(s, "ipv4_instance", &inst); + if(inst[0] != '\0') + *value = "1"; + } + return 0; +} + +static int get_IPInterface_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int cnt = 0; + + *value = "0"; + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "section_name", section_name(((struct ip_args *)data)->ip_sec), s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +static int get_IPInterface_IPv6PrefixNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int cnt = 0; + + *value = "0"; + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "section_name", section_name(((struct ip_args *)data)->ip_sec), s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +static int get_IPInterface_TWAMPReflectorNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + uci_foreach_option_eq("cwmp_twamp", "twamp_reflector", "interface", section_name(((struct ip_args *)data)->ip_sec), s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +/* + * *** Device.IP.Interface.{i}.IPv4Address.{i}. *** + */ +static struct uci_section *create_firewall_zone_config(char *iface) +{ + struct uci_section *s; + char *value, *name; + + dmuci_add_section_and_rename("firewall", "zone", &s, &value); + dmasprintf(&name, "fwl_%s", iface); + dmuci_set_value_by_section(s, "name", name); + dmuci_set_value_by_section(s, "input", "DROP"); + dmuci_set_value_by_section(s, "forward", "DROP"); + dmuci_set_value_by_section(s, "output", "ACCEPT"); + dmuci_set_value_by_section(s, "network", iface); + dmfree(name); + return s; +} + +static int get_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *input = "", *forward = ""; + struct uci_section *s = NULL; + + uci_foreach_option_cont("firewall", "zone", "network", section_name(((struct ip_args *)data)->ip_sec), s) { + dmuci_get_value_by_section_string(s, "input", &input); + dmuci_get_value_by_section_string(s, "forward", &forward); + if (strcmp(input, "ACCEPT") !=0 && strcmp(forward, "ACCEPT") !=0) { + *value = "1"; + return 0; + } + } + *value = "0"; + return 0; +} + +static int set_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + int cnt = 0; + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + value = b ? "DROP" : "ACCEPT"; + uci_foreach_option_cont("firewall", "zone", "network", section_name(((struct ip_args *)data)->ip_sec), s) { + dmuci_set_value_by_section(s, "input", value); + dmuci_set_value_by_section(s, "forward", value); + cnt++; + } + if (cnt == 0 && b) + create_firewall_zone_config(section_name(((struct ip_args *)data)->ip_sec)); + return 0; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv4Address.{i}.IPAddress!UCI:network/interface,@i-1/ipaddr*/ +static int get_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct ip_args *)data)->ip_4address; + return 0; +} + +static int set_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *proto; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); + if(strcmp(proto, "static") == 0) + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", value); + return 0; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv4Address.{i}.SubnetMask!UCI:network/interface,@i-1/netmask*/ +static int get_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res, *jobj; + char *mask; + + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "netmask", &mask); + if (mask[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + mask = dmjson_get_value(jobj, 1, "mask"); + if (mask[0] == '\0') + return 0; + mask = cidr2netmask(atoi(mask)); + } + } + *value = mask; + return 0; +} + +static int set_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *proto; + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); + if(strcmp(proto, "static") == 0) + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "netmask", value); + return 0; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv4Address.{i}.AddressingType!UCI:network/interface,@i-1/proto*/ +static int get_ipv4_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", value); + if (strcmp(*value, "static") == 0) + *value = "Static"; + else if (strcmp(*value, "dhcp") == 0) + *value = "DHCP"; + else + *value = ""; + return 0; +} + +static int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char linker[64] = "", *proto, *device, *mac; + const struct ip_args *ip = data; + char *section; + + dmuci_get_value_by_section_string(ip->ip_sec, "proto", &proto); + if (strstr(proto, "ppp")) { + snprintf(linker, sizeof(linker), "%s", section_name(((struct ip_args *)data)->ip_sec)); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + goto end; + } + + section = section_name(ip->ip_sec); + device = get_device(section); + if (device[0] != '\0') { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cVLANTermination%c", dmroot, dm_delim, dm_delim, dm_delim), device, value); + if (*value != NULL) + return 0; + } + + mac = get_macaddr(section); + if (mac[0] != '\0') { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), mac, value); + goto end; + } + +end: + if (*value == NULL) + *value = ""; + return 0; +} + +static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker = NULL, *newvalue = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (value[strlen(value)-1]!='.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else + adm_entry_get_linker_value(ctx, value, &linker); + + if (linker) + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ifname", linker); + else + return FAULT_9005; + + return 0; + } + return 0; +} + +/* + * *** Device.IP.Interface.{i}.IPv6Address.{i}. *** + */ +/*#Device.IP.Interface.{i}.IPv6Address.{i}.IPAddress!UCI:network/interface,@i-1/ip6addr*/ +static int get_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct ipv6_args *)data)->ip_6address; + if(((struct ipv6_args *)data)->ip_6mask[0] != '\0') + dmasprintf(value, "%s/%s", ((struct ipv6_args *)data)->ip_6address, ((struct ipv6_args *)data)->ip_6mask); + return 0; +} + +static int set_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *proto; + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "45", NULL, IPv6Address)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", &proto); + if(strcmp(proto, "static") == 0) + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6addr", value); + return 0; + } + return 0; +} + +static int get_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int set_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_IPInterfaceIPv6Address_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Enabled"; + return 0; +} + +static int get_IPInterfaceIPv6Address_IPAddressStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if(((struct ipv6_args *)data)->ip_6valid[0] != '\0') + *value = "Preferred"; + else + *value = "Unknown"; + return 0; +} + +static int get_IPInterfaceIPv6Address_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ubus_call_get_value_with_two_objects(section_name(((struct ipv6_args *)data)->ip_sec), "ipv6-prefix-assignment", "local-address", "address"); + if(*value[0] != '\0') + *value = "AutoConfigured"; + else { + dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", value); + if (strcmp(*value, "static") == 0) + *value = "Static"; + else if (strcmp(*value, "dhcpv6") == 0) + *value = "DHCPv6"; + else + *value = "WellKnown"; + } + return 0; +} + +static int get_IPInterfaceIPv6Address_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section; + char *inst; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ipv6_args *)data)->ip_sec), &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "ip_int_instance", &inst); + + *value = ""; + if(((struct ipv6prefix_args *)data)->ip_6prefixaddress[0] != '\0') + dmasprintf(value, "Device.IP.Interface.%s.IPv6Prefix.1.", inst); + return 0; +} + +static int set_IPInterfaceIPv6Address_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv6Address.{i}.PreferredLifetime!UCI:network/interface,@i-1/adv_preferred_lifetime*/ +static int get_IPInterfaceIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char local_time[32] = {0}; + char *preferred = ((struct ipv6_args *)data)->ip_6preferred; + *value = "0001-01-01T00:00:00Z"; + if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) + return 0; + *value = dmstrdup(local_time); + return 0; +} + +static int set_IPInterfaceIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char buf[32] = "", *proto; + + switch (action) { + case VALUECHECK: + if (dm_validate_dateTime(value)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", &proto); + if(strcasecmp(proto, "static") == 0) { + get_shift_time_shift(value, buf); + if (!(*buf)) + return 0; + dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "adv_preferred_lifetime", buf); + } + return 0; + } + return 0; +} + +/*#Device.IP.Interface.{i}.IPv6Address.{i}.ValidLifetime!UCI:network/interface,@i-1/adv_valid_lifetime*/ +static int get_IPInterfaceIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char local_time[32] = {0}; + char *preferred = ((struct ipv6_args *)data)->ip_6valid; + *value = "0001-01-01T00:00:00Z"; + if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) + return 0; + *value = dmstrdup(local_time); + return 0; +} + +static int set_IPInterfaceIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char buf[32] = "", *proto; + + switch (action) { + case VALUECHECK: + if (dm_validate_dateTime(value)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", &proto); + if(strcasecmp(proto, "static") == 0) { + get_shift_time_shift(value, buf); + if (!(*buf)) + return 0; + dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "adv_valid_lifetime", buf); + } + return 0; + } + return 0; +} + +/* + * *** Device.IP.Interface.{i}.IPv6Prefix.{i}. *** + */ +static int get_IPInterfaceIPv6Prefix_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int set_IPInterfaceIPv6Prefix_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_IPInterfaceIPv6Prefix_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Enabled"; + return 0; +} + +static int get_IPInterfaceIPv6Prefix_PrefixStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if(((struct ipv6prefix_args *)data)->ip_6prefixvalid[0] != '\0') + *value = "Preferred"; + else + *value = "Unknown"; + return 0; +} + +/*#Device.IP.Interface.{i}.IPv6Prefix.{i}.Prefix!UCI:network/interface,@i-1/ip6prefix*/ +static int get_IPInterfaceIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct ipv6prefix_args *)data)->ip_6prefixaddress; + if(((struct ipv6prefix_args *)data)->ip_6prefixmask[0] != '\0') + dmasprintf(value, "%s/%s", ((struct ipv6prefix_args *)data)->ip_6prefixaddress, ((struct ipv6prefix_args *)data)->ip_6prefixmask); + return 0; +} + +static int set_IPInterfaceIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *proto; + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "49", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct ipv6prefix_args *)data)->ip_sec, "proto", &proto); + if(strcmp(proto, "static") == 0) + dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "ip6prefix", value); + return 0; + } + return 0; +} + +static int get_IPInterfaceIPv6Prefix_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ubus_call_get_value(section_name(((struct ipv6prefix_args *)data)->ip_sec), "ipv6-prefix-assignment", "address"); + if(*value[0] != '\0') + *value = "AutoConfigured"; + else { + dmuci_get_value_by_section_string(((struct ipv6prefix_args *)data)->ip_sec, "proto", value); + if (strcmp(*value, "static") == 0) + *value = "Static"; + else if (strcmp(*value, "dhcpv6") == 0) + *value = "DHCPv6"; + else + *value = "WellKnown"; + } + return 0; +} + +static int get_IPInterfaceIPv6Prefix_StaticType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Static"; + return 0; +} + +static int set_IPInterfaceIPv6Prefix_StaticType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, StaticType, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_IPInterfaceIPv6Prefix_ParentPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker; + dmasprintf(&linker, "%s/%s", ((struct ipv6prefix_args *)data)->ip_6prefixaddress, ((struct ipv6prefix_args *)data)->ip_6prefixmask); + if(linker[0] != '\0') + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + *value = ""; + return 0; +} + +static int set_IPInterfaceIPv6Prefix_ParentPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_IPInterfaceIPv6Prefix_ChildPrefixBits(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_child_prefix_linker(section_name(((struct ipv6prefix_args *)data)->ip_sec)); + return 0; +} + +static int set_IPInterfaceIPv6Prefix_ChildPrefixBits(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "49", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_IPInterfaceIPv6Prefix_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char local_time[32] = {0}; + char *preferred = ((struct ipv6prefix_args *)data)->ip_6prefixpreferred; + *value = "0001-01-01T00:00:00Z"; + if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) + return 0; + *value = dmstrdup(local_time); + return 0; +} + +static int set_IPInterfaceIPv6Prefix_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_dateTime(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_IPInterfaceIPv6Prefix_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char local_time[32] = {0}; + char *preferred = ((struct ipv6prefix_args *)data)->ip_6prefixvalid; + *value = "0001-01-01T00:00:00Z"; + if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) + return 0; + *value = dmstrdup(local_time); + return 0; +} + +static int set_IPInterfaceIPv6Prefix_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_dateTime(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +/* + * *** Device.IP.Interface.{i}.Stats. *** + */ +static int get_ip_interface_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return get_ip_iface_sysfs(data, "statistics/tx_bytes", value); +} + +static int get_ip_interface_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return get_ip_iface_sysfs(data, "statistics/rx_bytes", value); +} + +static int get_ip_interface_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return get_ip_iface_sysfs(data, "statistics/tx_packets", value); +} + +static int get_ip_interface_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return get_ip_iface_sysfs(data, "statistics/rx_packets", value); +} + +static int get_ip_interface_statistics_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return get_ip_iface_sysfs(data, "statistics/tx_errors", value); +} + +static int get_ip_interface_statistics_rx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return get_ip_iface_sysfs(data, "statistics/rx_errors", value); +} + +static int get_ip_interface_statistics_tx_discardpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return get_ip_iface_sysfs(data, "statistics/tx_dropped", value); +} + +static int get_ip_interface_statistics_rx_discardpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return get_ip_iface_sysfs(data, "statistics/rx_dropped", value); +} + +static int get_ip_interface_statistics_tx_unicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_ip_interface_statistics_rx_unicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_ip_interface_statistics_tx_multicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_ip_interface_statistics_rx_multicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return get_ip_iface_sysfs(data, "statistics/multicast", value); +} + +static int get_ip_interface_statistics_tx_broadcastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_ip_interface_statistics_rx_broadcastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_ip_interface_statistics_rx_unknownprotopackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/* + * *** Device.IP.Interface.{i}.TWAMPReflector.{i}. *** + */ +static int get_IPInterfaceTWAMPReflector_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "enable", value); + return 0; +} + +static int set_IPInterfaceTWAMPReflector_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + struct uci_section *s; + char *interface, *device, *id, *ipv4addr = ""; + json_object *res, *jobj; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + if(b) { + dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface); + dmuci_get_value_by_section_string((struct uci_section *)data, "id", &id); + dmuci_set_value_by_section((struct uci_section *)data, "enable", "1"); + dmuci_set_value("cwmp_twamp", "twamp", "id", id); + uci_foreach_sections("network", "interface", s) { + if(strcmp(section_name(s), interface) != 0) + continue; + dmuci_get_value_by_section_string(s, "ipaddr", &ipv4addr); + break; + } + if (ipv4addr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + ipv4addr = dmjson_get_value(jobj, 1, "address"); + if (ipv4addr[0] == '\0') + dmuci_set_value_by_section((struct uci_section *)data, "ip_version", "6"); + else + dmuci_set_value_by_section((struct uci_section *)data, "ip_version", "4"); + } + } else + dmuci_set_value_by_section((struct uci_section *)data, "ip_version", "4"); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); + if (res) { + device = dmjson_get_value(res, 1, "device"); + dmuci_set_value_by_section((struct uci_section *)data, "device", device); + } + dmuci_set_value_by_section((struct uci_section *)data, "device", get_device(interface)); + } else { + dmuci_set_value_by_section((struct uci_section *)data, "enable", "0"); + } + break; + } + return 0; +} + +static int get_IPInterfaceTWAMPReflector_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *enable; + + dmuci_get_value_by_section_string((struct uci_section *)data, "enable", &enable); + if (strcmp(enable, "1") == 0) + *value = "Active"; + else + *value = "Disabled"; + return 0; +} + +static int get_IPInterfaceTWAMPReflector_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "twamp_alias", value); + return 0; +} + +static int set_IPInterfaceTWAMPReflector_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "twamp_alias", value); + break; + } + return 0; +} + +static int get_IPInterfaceTWAMPReflector_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "port", value); + return 0; +} + +static int set_IPInterfaceTWAMPReflector_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, "65535")) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "port", value); + break; + } + return 0; +} + +static int get_IPInterfaceTWAMPReflector_MaximumTTL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "max_ttl", value); + return 0; +} + +static int set_IPInterfaceTWAMPReflector_MaximumTTL(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", "255")) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "max_ttl", value); + break; + } + return 0; +} + +static int get_IPInterfaceTWAMPReflector_IPAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "ip_list", value); + return 0; +} + +static int set_IPInterfaceTWAMPReflector_IPAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "255", NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "ip_list", value); + break; + } + return 0; +} + +static int get_IPInterfaceTWAMPReflector_PortAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "port_list", value); + return 0; +} + +static int set_IPInterfaceTWAMPReflector_PortAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "255", NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "port_list", value); + break; + } + return 0; +} + +/************************************************************* +* GET & SET ALIAS +**************************************************************/ +static int get_IPInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "ip_int_alias", value); + return 0; +} + +static int set_IPInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); + if (dmmap_section != NULL) + dmuci_set_value_by_section(dmmap_section, "ip_int_alias", value); + return 0; + } + return 0; +} + +static int get_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "ipv4_alias", value); + return 0; +} + +static int set_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); + if (dmmap_section != NULL) + dmuci_set_value_by_section(dmmap_section, "ipv4_alias", value); + return 0; + } + return 0; +} + +static int get_IPInterfaceIPv6Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + char *name; + + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "ipv6_instance", instance, dmmap_section) { + dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); + if(strcmp(name, section_name(((struct ipv6_args *)data)->ip_sec)) == 0) + dmuci_get_value_by_section_string(dmmap_section, "ipv6_alias", value); + } + return 0; +} + +static int set_IPInterfaceIPv6Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + char *name; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "ipv6_instance", instance, dmmap_section) { + dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); + if(strcmp(name, section_name(((struct ipv6_args *)data)->ip_sec)) == 0) + break; + } + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "ipv6_alias", value); + return 0; + } + return 0; +} + +static int get_IPInterfaceIPv6Prefix_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + char *name; + + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "ipv6prefix_instance", instance, dmmap_section) { + dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); + if(strcmp(name, section_name(((struct ipv6prefix_args *)data)->ip_sec)) == 0) + dmuci_get_value_by_section_string(dmmap_section, "ipv6prefix_alias", value); + } + return 0; +} + +static int set_IPInterfaceIPv6Prefix_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + char *name; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "ipv6prefix_instance", instance, dmmap_section) { + dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); + if(strcmp(name, section_name(((struct ipv6prefix_args *)data)->ip_sec)) == 0) + break; + } + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "ipv6prefix_alias", value); + return 0; + } + return 0; +} + +/************************************************************* +* ADD & DEL OBJ +**************************************************************/ +static char *get_last_instance_cond(char* dmmap_package, char *package, char *section, char *opt_inst, char *opt_cond, char *cond_val, char *opt_filter, char *filter_val, char *refused_interface) +{ + struct uci_section *s, *dmmap_section; + char *inst = NULL, *val, *val_f; + char *ipv4addr = "", *ipv6addr = "", *proto; + json_object *res, *jobj; + + uci_foreach_sections(package, section, s) { + if (opt_cond) dmuci_get_value_by_section_string(s, opt_cond, &val); + if (opt_filter) dmuci_get_value_by_section_string(s, opt_filter, &val_f); + if(opt_cond && opt_filter && (strcmp(val, cond_val) == 0 || strcmp(val_f, filter_val) == 0)) + continue; + if (strcmp(section_name(s), refused_interface)==0) + continue; + + dmuci_get_value_by_section_string(s, "ipaddr", &ipv4addr); + if (ipv4addr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); + ipv4addr = dmjson_get_value(jobj, 1, "address"); + } + } + dmuci_get_value_by_section_string(s, "ip6addr", &ipv6addr); + if (ipv6addr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); + if (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); + ipv6addr = dmjson_get_value(jobj, 1, "address"); + } + } + dmuci_get_value_by_section_string(s, "proto", &proto); + if (ipv4addr[0] == '\0' && ipv6addr[0] == '\0' && strcmp(proto, "dhcp") != 0 && strcmp(proto, "dhcpv6") != 0 && strcmp(val, "bridge") != 0) { + continue; + } + get_dmmap_section_of_config_section(dmmap_package, section, section_name(s), &dmmap_section); + inst = update_instance_bbfdm(dmmap_section, inst, opt_inst); + } + return inst; +} + +static int add_ip_interface(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *last_inst, *v; + char ip_name[32], ib[8]; + char *p = ip_name; + struct uci_section *dmmap_ip_interface; + + last_inst = get_last_instance_cond("dmmap_network", "network", "interface", "ip_int_instance", "type", "alias", "proto", "", "loopback"); + snprintf(ib, sizeof(ib), "%d", last_inst ? atoi(last_inst)+1 : 1); + dmstrappendstr(p, "ip_interface_"); + dmstrappendstr(p, ib); + dmstrappendend(p); + dmuci_set_value("network", ip_name, "", "interface"); + dmuci_set_value("network", ip_name, "proto", "dhcp"); + + dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_ip_interface, &v); + dmuci_set_value_by_section(dmmap_ip_interface, "section_name", ip_name); + *instance = update_instance_bbfdm(dmmap_ip_interface, last_inst, "ip_int_instance"); + return 0; +} + +static int delete_ip_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *dmmap_section = NULL; + + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(((struct ip_args *)data)->ip_sec, NULL, NULL); + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); + if(dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); + break; + case DEL_ALL: + return FAULT_9005; + } + return 0; +} + +static int add_ipv4(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + char *instance; + struct uci_section *dmmap_section; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "ipv4_instance", &instance); + *instancepara = update_instance_bbfdm(dmmap_section, instance, "ipv4_instance"); + if(instance[0] == '\0') { + dmuci_set_value_by_section(dmmap_section, "ipv4_instance", *instancepara); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", "0.0.0.0"); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", "static"); + } + return 0; +} + +static int delete_ipv4(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *dmmap_section; + + switch (del_action) { + case DEL_INST: + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", ""); + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); + if(dmmap_section != NULL) + dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); + break; + case DEL_ALL: + return FAULT_9005; + } + return 0; +} + +static int add_ipv6(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + struct uci_section *s, *ss; + char *ip, *name, *inst, *curr_inst; + + uci_foreach_sections("network", "interface", s) { + if(strcmp(section_name(s), section_name(((struct ipv6_args *)data)->ip_sec)) != 0) + continue; + dmuci_get_value_by_section_string(s, "ip6addr", &ip); + break; + } + if(ip[0] == '\0') { + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "section_name", section_name(((struct ipv6_args *)data)->ip_sec), s) { + dmuci_get_value_by_section_string(s, "ipv6_instance", &inst); + } + dmasprintf(&curr_inst, "%d", atoi(inst)+1); + dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "ip6addr", "::"); + dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "proto", "static"); + DMUCI_ADD_SECTION(bbfdm, "dmmap_network", "ipv6", &ss, &name); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ss, "section_name", section_name(((struct ipv6_args *)data)->ip_sec)); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ss, "ipv6_instance", curr_inst); + } + return 0; +} + +static int delete_ipv6(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *dmmap_section; + + get_dmmap_section_of_config_section("dmmap_network", "ipv6", section_name(((struct ipv6_args *)data)->ip_sec), &dmmap_section); + switch (del_action) { + case DEL_INST: + dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "ip6addr", ""); + dmuci_set_value_by_section(dmmap_section, "ipv6_instance", ""); + dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "proto", ""); + break; + case DEL_ALL: + return FAULT_9005; + } + return 0; +} + +static int add_ipv6_prefix(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + struct uci_section *s, *ss; + char *ip, *name, *inst, *curr_inst; + + uci_foreach_sections("network", "interface", s) { + if(strcmp(section_name(s), section_name(((struct ipv6prefix_args *)data)->ip_sec)) != 0) + continue; + dmuci_get_value_by_section_string(s, "ip6prefix", &ip); + break; + } + if(ip[0] == '\0') { + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "section_name", section_name(((struct ipv6prefix_args *)data)->ip_sec), s) { + dmuci_get_value_by_section_string(s, "ipv6prefix_instance", &inst); + } + dmasprintf(&curr_inst, "%d", atoi(inst)+1); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6prefix", "::"); + dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "proto", "static"); + DMUCI_ADD_SECTION(bbfdm, "dmmap_network", "ipv6prefix", &ss, &name); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ss, "section_name", section_name(((struct ipv6prefix_args *)data)->ip_sec)); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, ss, "ipv6prefix_instance", curr_inst); + } + return 0; +} + +static int delete_ipv6_prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *dmmap_section; + + get_dmmap_section_of_config_section("dmmap_network", "ipv6prefix", section_name(((struct ipv6prefix_args *)data)->ip_sec), &dmmap_section); + switch (del_action) { + case DEL_INST: + dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "ip6prefix", ""); + dmuci_set_value_by_section(dmmap_section, "ipv6prefix_instance", ""); + dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "proto", ""); + break; + case DEL_ALL: + return FAULT_9005; + } + return 0; +} + +static char *get_last_instance_with_option(char *package, char *section, char *option, char *val, char *opt_inst) +{ + struct uci_section *s; + char *inst = NULL; + + uci_foreach_option_eq(package, section, option, val, s) { + inst = update_instance(s, inst, opt_inst); + } + return inst; +} + +static char *get_last_id(char *package, char *section) +{ + struct uci_section *s; + char *id; + int cnt = 0; + + uci_foreach_sections(package, section, s) { + cnt++; + } + dmasprintf(&id, "%d", cnt+1); + return id; +} + +static int addObjIPInterfaceTWAMPReflector(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct uci_section *connection; + char *value1, *last_inst, *id; + + last_inst = get_last_instance_with_option("cwmp_twamp", "twamp_reflector", "interface", section_name(((struct ip_args *)data)->ip_sec), "twamp_inst"); + id = get_last_id("cwmp_twamp", "twamp_reflector"); + dmuci_add_section("cwmp_twamp", "twamp_reflector", &connection, &value1); + dmasprintf(instance, "%d", last_inst?atoi(last_inst)+1:1); + dmuci_set_value_by_section(connection, "twamp_inst", *instance); + dmuci_set_value_by_section(connection, "id", id); + dmuci_set_value_by_section(connection, "enable", "0"); + dmuci_set_value_by_section(connection, "interface", section_name(((struct ip_args *)data)->ip_sec)); + dmuci_set_value_by_section(connection, "port", "862"); + dmuci_set_value_by_section(connection, "max_ttl", "1"); + return 0; +} + +static int delObjIPInterfaceTWAMPReflector(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct uci_section *s, *ss = NULL; + char *interface; + struct uci_section *section = (struct uci_section *)data; + + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(section, NULL, NULL); + return 0; + case DEL_ALL: + uci_foreach_sections("cwmp_twamp", "twamp_reflector", s) { + dmuci_get_value_by_section_string(s, "interface", &interface); + if(strcmp(interface, section_name(((struct ip_args *)data)->ip_sec)) != 0) + continue; + if (found != 0) { + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + dmuci_delete_by_section(ss, NULL, NULL); + } + return 0; + } + return 0; +} + +/************************************************************************** +* LINKER +***************************************************************************/ +static int get_linker_ip_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct ip_args *)data)->ip_sec) { + dmasprintf(linker,"%s", section_name(((struct ip_args *)data)->ip_sec)); + return 0; + } else { + *linker = ""; + return 0; + } +} + +static int get_linker_ipv6_prefix(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (((struct ipv6prefix_args *)data)->ip_sec) { + dmasprintf(linker,"%s", get_child_prefix_linker(section_name(((struct ipv6prefix_args *)data)->ip_sec))); + return 0; + } else { + *linker = ""; + return 0; + } +} + +/************************************************************* +* ENTRY METHOD +**************************************************************/ +/*#Device.IP.Interface.{i}.!UCI:network/interface/dmmap_network*/ +static int browseIPIfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *ip_int = NULL, *ip_int_last = NULL; + char *type, *ipv4addr = ""; + struct ip_args curr_ip_args = {0}; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("network", "interface", "dmmap_network", &dup_list); + list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "type", &type); + if (strcmp(type, "alias") == 0 || strcmp(section_name(p->config_section), "loopback")==0) + continue; + + /* IPv4 address */ + dmuci_get_value_by_section_string(p->config_section, "ipaddr", &ipv4addr); + if (ipv4addr[0] == '\0') + ipv4addr = ubus_call_get_value(section_name(p->config_section), "ipv4-address", "address"); + + init_ip_args(&curr_ip_args, p->config_section, ipv4addr); + ip_int = handle_update_instance(1, dmctx, &ip_int_last, update_instance_alias, 3, p->dmmap_section, "ip_int_instance", "ip_int_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ip_args, ip_int) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int browseIfaceIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *ipv4_inst = NULL, *ipv4_inst_last = NULL; + struct uci_section *dmmap_section; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)prev_data)->ip_sec), &dmmap_section); + if(((struct ip_args *)prev_data)->ip_4address[0] != '\0') { + ipv4_inst = handle_update_instance(2, dmctx, &ipv4_inst_last, update_instance_alias, 3, dmmap_section, "ipv4_instance", "ipv4_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, prev_data, ipv4_inst) == DM_STOP) + goto end; + } +end: + return 0; +} + +static struct uci_section *update_dmmap_network_ipv6(char *curr_inst, char *section_name) +{ + struct uci_section *s = NULL; + char *inst, *name; + + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "section_name", section_name, s) { + dmuci_get_value_by_section_string(s, "ipv6_instance", &inst); + if(strcmp(curr_inst, inst) == 0) + return s; + } + if (!s) { + DMUCI_ADD_SECTION(bbfdm, "dmmap_network", "ipv6", &s, &name); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "section_name", section_name); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "ipv6_instance", curr_inst); + } + return s; +} + +static int browseIfaceIPv6Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *s; + char *ipv6_int = NULL, *ipv6_int_last = NULL, *ipv6addr = "", *ipv6mask = "", *ipv6_preferred = "", *ipv6_valid = "", buf[4]=""; + struct ipv6_args curr_ipv6_args = {0}; + json_object *res, *jobj, *jobj1; + int entries = 0; + + if(prev_data && ((struct ip_args *)prev_data)->ip_sec) { + dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "ip6addr", &ipv6addr); + dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "adv_preferred_lifetime", &ipv6_preferred); + dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "adv_valid_lifetime", &ipv6_valid); + if (ipv6addr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)prev_data)->ip_sec), String}}, 1, &res); + while (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-prefix-assignment"); + if(jobj) { + jobj1 = dmjson_get_obj(jobj, 1, "local-address"); + if(jobj1) { + ipv6addr = dmjson_get_value(jobj1, 1, "address"); + ipv6mask = dmjson_get_value(jobj1, 1, "mask"); + goto browse; + } + } + jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "ipv6-address"); + if(jobj) { + ipv6addr = dmjson_get_value(jobj, 1, "address"); + ipv6mask = dmjson_get_value(jobj, 1, "mask"); + if (ipv6_preferred[0] == '\0') + ipv6_preferred = dmjson_get_value(jobj, 1, "preferred"); + if (ipv6_valid[0] == '\0') + ipv6_valid = dmjson_get_value(jobj, 1, "valid"); + entries++; + snprintf(buf, sizeof(buf), "%d", entries); + s = update_dmmap_network_ipv6(buf, section_name(((struct ip_args *)prev_data)->ip_sec)); + init_ipv6_args(&curr_ipv6_args, ((struct ip_args *)prev_data)->ip_sec, ipv6addr, ipv6mask, ipv6_preferred, ipv6_valid); + ipv6_int = handle_update_instance(1, dmctx, &ipv6_int_last, update_instance_alias, 3, s, "ipv6_instance", "ipv6_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6_args, ipv6_int) == DM_STOP) + goto end; + } else + goto end; + } + } +browse: + s = update_dmmap_network_ipv6("1", section_name(((struct ip_args *)prev_data)->ip_sec)); + init_ipv6_args(&curr_ipv6_args, ((struct ip_args *)prev_data)->ip_sec, ipv6addr, ipv6mask, ipv6_preferred, ipv6_valid); + ipv6_int = handle_update_instance(1, dmctx, &ipv6_int_last, update_instance_alias, 3, s, "ipv6_instance", "ipv6_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6_args, ipv6_int) == DM_STOP) + goto end; + } +end: + return 0; +} + + +static struct uci_section *update_dmmap_network_ipv6prefix(char *curr_inst, char *section_name) +{ + struct uci_section *s = NULL; + char *inst, *name; + + uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "section_name", section_name, s) { + dmuci_get_value_by_section_string(s, "ipv6prefix_instance", &inst); + if(strcmp(curr_inst, inst) == 0) + return s; + } + if (!s) { + DMUCI_ADD_SECTION(bbfdm, "dmmap_network", "ipv6prefix", &s, &name); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "section_name", section_name); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "ipv6prefix_instance", curr_inst); + } + return s; +} + +static int browseIfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *s; + char *ipv6prefix_int = NULL, *ipv6prefix_int_last = NULL, *ipv6prefixaddr = "", *ipv6prefixmask = "", *ipv6prefix_preferred = "", *ipv6prefix_valid = "", buf[4] = ""; + struct ipv6prefix_args curr_ipv6prefix_args = {0}; + json_object *res, *jobj; + int entries = 0; + + if(prev_data && ((struct ip_args *)prev_data)->ip_sec) { + dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "ip6prefix", &ipv6prefixaddr); + if (ipv6prefixaddr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)prev_data)->ip_sec), String}}, 1, &res); + while (res) { + jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-prefix-assignment"); + if(jobj) { + ipv6prefixaddr = dmjson_get_value(jobj, 1, "address"); + ipv6prefixmask = dmjson_get_value(jobj, 1, "mask"); + ipv6prefix_preferred = dmjson_get_value(jobj, 1, "preferred"); + ipv6prefix_valid = dmjson_get_value(jobj, 1, "valid"); + goto browse; + } + jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "ipv6-prefix"); + if(jobj) { + ipv6prefixaddr = dmjson_get_value(jobj, 1, "address"); + ipv6prefixmask = dmjson_get_value(jobj, 1, "mask"); + ipv6prefix_preferred = dmjson_get_value(jobj, 1, "preferred"); + ipv6prefix_valid = dmjson_get_value(jobj, 1, "valid"); + entries++; + snprintf(buf, sizeof(buf), "%d", entries); + s = update_dmmap_network_ipv6prefix(buf, section_name(((struct ip_args *)prev_data)->ip_sec)); + init_ipv6prefix_args(&curr_ipv6prefix_args, ((struct ip_args *)prev_data)->ip_sec, ipv6prefixaddr, ipv6prefixmask, ipv6prefix_preferred, ipv6prefix_valid); + ipv6prefix_int = handle_update_instance(1, dmctx, &ipv6prefix_int_last, update_instance_alias, 3, s, "ipv6prefix_instance", "ipv6prefix_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6prefix_args, ipv6prefix_int) == DM_STOP) + goto end; + } else + goto end; + } + } +browse: + s = update_dmmap_network_ipv6prefix("1", section_name(((struct ip_args *)prev_data)->ip_sec)); + init_ipv6prefix_args(&curr_ipv6prefix_args, ((struct ip_args *)prev_data)->ip_sec, ipv6prefixaddr, ipv6prefixmask, ipv6prefix_preferred, ipv6prefix_valid); + ipv6prefix_int = handle_update_instance(1, dmctx, &ipv6prefix_int_last, update_instance_alias, 3, s, "ipv6prefix_instance", "ipv6prefix_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6prefix_args, ipv6prefix_int) == DM_STOP) + goto end; + } +end: + return 0; +} + +static int browseIPInterfaceTWAMPReflectorInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *s = NULL; + char *twamp_inst = NULL, *twamp_inst_last = NULL; + + uci_foreach_option_eq("cwmp_twamp", "twamp_reflector", "interface", section_name(((struct ip_args *)prev_data)->ip_sec), s) { + twamp_inst = handle_update_instance(2, dmctx, &twamp_inst_last, update_instance_alias, 3, (void *)s, "twamp_inst", "twamp_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, twamp_inst) == DM_STOP) + break; + } + return 0; +} + +static struct dm_forced_inform_s IPv4INFRM = {0, get_ipv4_finform}; +static struct dm_forced_inform_s IPv6INFRM = {0, get_ipv6_finform}; /* *** Device.IP. *** */ DMOBJ tIPObj[] = { @@ -153,1893 +2067,3 @@ DMLEAF tIPInterfaceTWAMPReflectorParams[] = { {"PortAllowedList", &DMWRITE, DMT_STRING, get_IPInterfaceTWAMPReflector_PortAllowedList, set_IPInterfaceTWAMPReflector_PortAllowedList, NULL, NULL, BBFDM_BOTH}, {0} }; - -unsigned char get_ipv4_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance) -{ - return 1; -} - -unsigned char get_ipv6_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance) -{ - return 1; -} - -/************************************************************* -* INIT -**************************************************************/ -static inline int init_ip_args(struct ip_args *args, struct uci_section *s, char *ip_4address) -{ - args->ip_sec = s; - args->ip_4address = ip_4address; - return 0; -} - -static inline int init_ipv6_args(struct ipv6_args *args, struct uci_section *s, char *ip_6address, char *ip_6mask, char *ip_6preferred, char *ip_6valid) -{ - args->ip_sec = s; - args->ip_6address = ip_6address; - args->ip_6mask = ip_6mask; - args->ip_6preferred = ip_6preferred; - args->ip_6valid = ip_6valid; - return 0; -} - -static inline int init_ipv6prefix_args(struct ipv6prefix_args *args, struct uci_section *s, char *ip_6prefixaddress, char *ip_6prefixmask, char *ip_6prefixpreferred, char *ip_6prefixvalid) -{ - args->ip_sec = s; - args->ip_6prefixaddress = ip_6prefixaddress; - args->ip_6prefixmask = ip_6prefixmask; - args->ip_6prefixpreferred = ip_6prefixpreferred; - args->ip_6prefixvalid = ip_6prefixvalid; - return 0; -} - -/************************************************************* -* COMMON Functions -**************************************************************/ -static int get_ip_iface_sysfs(const struct ip_args *ip, const char *name, char **value) -{ - return get_net_iface_sysfs(section_name(ip->ip_sec), name, value); -} - -static char *ubus_call_get_value_with_two_objects(char *interface, char *obj1, char *obj2, char *key) -{ - json_object *res, *jobj1 = NULL, *jobj2 = NULL; - char *value = ""; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); - if (res) { - jobj1 = dmjson_select_obj_in_array_idx(res, 0, 1, obj1); - if(jobj1) - jobj2 = dmjson_get_obj(jobj1, 1, obj2); - if(jobj2) - value = dmjson_get_value(jobj2, 1, key); - } - return value; -} - -static char *ubus_call_get_value(char *interface, char *obj, char *key) -{ - json_object *res, *jobj; - char *value = ""; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, obj); - value = dmjson_get_value(jobj, 1, key); - } - return value; -} - -static char *get_child_prefix_linker(char *interface) -{ - char *address = NULL, *mask = NULL, *value; - json_object *res, *jobj, *jobj1, *jobj2; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); - if(res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-prefix"); - if(jobj) { - jobj1 = dmjson_get_obj(jobj, 1, "assigned"); - if(jobj1) { - jobj2 = dmjson_get_obj(jobj1, 1, "lan"); - if(jobj2) { - address = dmjson_get_value(jobj2, 1, "address"); - mask = dmjson_get_value(jobj2, 1, "mask"); - dmasprintf(&value, "%s/%s", address,mask); - return value; - } - } - } - } - return ""; -} - -/************************************************************* -* GET & SET PARAM -**************************************************************/ -/* - * *** Device.IP. *** - */ -int get_IP_IPv4Capable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int get_IP_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int set_IP_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_IP_IPv4Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Enabled"; - return 0; -} - -int get_IP_IPv6Capable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int get_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int set_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_IP_IPv6Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Enabled"; - return 0; -} - -int get_IP_ULAPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("network", "globals", "ula_prefix", value); - return 0; -} - -int set_IP_ULAPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "49", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value("network", "globals", "ula_prefix", value); - break; - } - return 0; -} - -int get_IP_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_foreach_sections("network", "interface", s) { - if (strcmp(section_name(s), "loopback") == 0) - continue; - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -/* - * *** Device.IP.Interface. *** - */ -/*#Device.IP.Interface.{i}.Enable!UCI:network/interface,@i-1/disabled*/ -int get_IPInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v; - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "disabled", &v); - *value = (*v != '1') ? "1" : "0"; - return 0; -} - -int set_IPInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "disabled", (b) ? "0" : "1"); - break; - } - return 0; -} - -/*#Device.IP.Interface.{i}.Status!UCI:network/interface,@i-1/disabled*/ -int get_IPInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - char *val = NULL; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res); - DM_ASSERT(res, *value = "Down"); - val = dmjson_get_value(res, 1, "up"); - *value = !strcmp(val, "true") ? "Up" : "Down"; - return 0; -} - -int get_IPInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(section_name(((struct ip_args *)data)->ip_sec)); - return 0; -} - -int get_IPInterface_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int set_IPInterface_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -/*#Device.IP.Interface.{i}.IPv6Enable!UCI:network/interface,@i-1/ipv6*/ -int get_IPInterface_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *v; - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ipv6", &v); - *value = (*v != '0') ? "1" : "0"; - return 0; -} - -int set_IPInterface_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipv6", (b) ? "" : "0"); - break; - } - return 0; -} - -/*#Device.IP.Interface.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ -int get_IPInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "uptime"); - return 0; -} - -int get_IPInterface_Router(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Device.Routing.Router.1."; - return 0; -} - -int set_IPInterface_Router(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "0"; - return 0; -} - -int set_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - char *ubus_object; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - if (b) { - dmastrcat(&ubus_object, "network.interface.", section_name(((struct uci_section *)data))); - dmubus_call_set(ubus_object, "down", UBUS_ARGS{}, 0); - dmubus_call_set(ubus_object, "up", UBUS_ARGS{}, 0); - dmfree(ubus_object); - } - break; - } - return 0; -} - -int get_IPInterface_MaxMTUSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return get_ip_iface_sysfs(data, "mtu", value); -} - -int set_IPInterface_MaxMTUSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "64", "65535")) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "mtu", value); - break; - } - return 0; -} - -int get_IPInterface_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - if (strcmp(section_name(((struct ip_args *)data)->ip_sec), "loopback") == 0) - *value = "Loopback"; - else - *value = "Normal"; - return 0; -} - -int get_IPInterface_Loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - if (strcmp(section_name(((struct ip_args *)data)->ip_sec), "loopback") == 0) - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_IPInterface_Loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_IPInterface_IPv4AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - char *inst; - - *value = "0"; - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "interface", "section_name", section_name(((struct ip_args *)data)->ip_sec), s) { - dmuci_get_value_by_section_string(s, "ipv4_instance", &inst); - if(inst[0] != '\0') - *value = "1"; - } - return 0; -} - -int get_IPInterface_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int cnt = 0; - - *value = "0"; - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "section_name", section_name(((struct ip_args *)data)->ip_sec), s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -int get_IPInterface_IPv6PrefixNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int cnt = 0; - - *value = "0"; - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "section_name", section_name(((struct ip_args *)data)->ip_sec), s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -int get_IPInterface_TWAMPReflectorNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - uci_foreach_option_eq("cwmp_twamp", "twamp_reflector", "interface", section_name(((struct ip_args *)data)->ip_sec), s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -/* - * *** Device.IP.Interface.{i}.IPv4Address.{i}. *** - */ -static struct uci_section *create_firewall_zone_config(char *iface) -{ - struct uci_section *s; - char *value, *name; - - dmuci_add_section_and_rename("firewall", "zone", &s, &value); - dmasprintf(&name, "fwl_%s", iface); - dmuci_set_value_by_section(s, "name", name); - dmuci_set_value_by_section(s, "input", "DROP"); - dmuci_set_value_by_section(s, "forward", "DROP"); - dmuci_set_value_by_section(s, "output", "ACCEPT"); - dmuci_set_value_by_section(s, "network", iface); - dmfree(name); - return s; -} - -int get_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *input = "", *forward = ""; - struct uci_section *s = NULL; - - uci_foreach_option_cont("firewall", "zone", "network", section_name(((struct ip_args *)data)->ip_sec), s) { - dmuci_get_value_by_section_string(s, "input", &input); - dmuci_get_value_by_section_string(s, "forward", &forward); - if (strcmp(input, "ACCEPT") !=0 && strcmp(forward, "ACCEPT") !=0) { - *value = "1"; - return 0; - } - } - *value = "0"; - return 0; -} - -int set_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - int cnt = 0; - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - value = b ? "DROP" : "ACCEPT"; - uci_foreach_option_cont("firewall", "zone", "network", section_name(((struct ip_args *)data)->ip_sec), s) { - dmuci_set_value_by_section(s, "input", value); - dmuci_set_value_by_section(s, "forward", value); - cnt++; - } - if (cnt == 0 && b) - create_firewall_zone_config(section_name(((struct ip_args *)data)->ip_sec)); - return 0; - } - return 0; -} - -/*#Device.IP.Interface.{i}.IPv4Address.{i}.IPAddress!UCI:network/interface,@i-1/ipaddr*/ -int get_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct ip_args *)data)->ip_4address; - return 0; -} - -int set_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *proto; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); - if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", value); - return 0; - } - return 0; -} - -/*#Device.IP.Interface.{i}.IPv4Address.{i}.SubnetMask!UCI:network/interface,@i-1/netmask*/ -int get_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res, *jobj; - char *mask; - - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "netmask", &mask); - if (mask[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - mask = dmjson_get_value(jobj, 1, "mask"); - if (mask[0] == '\0') - return 0; - mask = cidr2netmask(atoi(mask)); - } - } - *value = mask; - return 0; -} - -int set_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *proto; - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "15", NULL, IPv4Address)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); - if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "netmask", value); - return 0; - } - return 0; -} - -/*#Device.IP.Interface.{i}.IPv4Address.{i}.AddressingType!UCI:network/interface,@i-1/proto*/ -int get_ipv4_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", value); - if (strcmp(*value, "static") == 0) - *value = "Static"; - else if (strcmp(*value, "dhcp") == 0) - *value = "DHCP"; - else - *value = ""; - return 0; -} - -int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char linker[64] = "", *proto, *device, *mac; - const struct ip_args *ip = data; - char *section; - - dmuci_get_value_by_section_string(ip->ip_sec, "proto", &proto); - if (strstr(proto, "ppp")) { - snprintf(linker, sizeof(linker), "%s", section_name(((struct ip_args *)data)->ip_sec)); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - goto end; - } - - section = section_name(ip->ip_sec); - device = get_device(section); - if (device[0] != '\0') { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cVLANTermination%c", dmroot, dm_delim, dm_delim, dm_delim), device, value); - if (*value != NULL) - return 0; - } - - mac = get_macaddr(section); - if (mac[0] != '\0') { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), mac, value); - goto end; - } - -end: - if (*value == NULL) - *value = ""; - return 0; -} - -int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *linker = NULL, *newvalue = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); - - if (linker) - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ifname", linker); - else - return FAULT_9005; - - return 0; - } - return 0; -} - -/* - * *** Device.IP.Interface.{i}.IPv6Address.{i}. *** - */ -/*#Device.IP.Interface.{i}.IPv6Address.{i}.IPAddress!UCI:network/interface,@i-1/ip6addr*/ -int get_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct ipv6_args *)data)->ip_6address; - if(((struct ipv6_args *)data)->ip_6mask[0] != '\0') - dmasprintf(value, "%s/%s", ((struct ipv6_args *)data)->ip_6address, ((struct ipv6_args *)data)->ip_6mask); - return 0; -} - -int set_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *proto; - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "45", NULL, IPv6Address)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", &proto); - if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6addr", value); - return 0; - } - return 0; -} - -int get_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int set_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_IPInterfaceIPv6Address_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Enabled"; - return 0; -} - -int get_IPInterfaceIPv6Address_IPAddressStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - if(((struct ipv6_args *)data)->ip_6valid[0] != '\0') - *value = "Preferred"; - else - *value = "Unknown"; - return 0; -} - -int get_IPInterfaceIPv6Address_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ubus_call_get_value_with_two_objects(section_name(((struct ipv6_args *)data)->ip_sec), "ipv6-prefix-assignment", "local-address", "address"); - if(*value[0] != '\0') - *value = "AutoConfigured"; - else { - dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", value); - if (strcmp(*value, "static") == 0) - *value = "Static"; - else if (strcmp(*value, "dhcpv6") == 0) - *value = "DHCPv6"; - else - *value = "WellKnown"; - } - return 0; -} - -int get_IPInterfaceIPv6Address_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section; - char *inst; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ipv6_args *)data)->ip_sec), &dmmap_section); - dmuci_get_value_by_section_string(dmmap_section, "ip_int_instance", &inst); - - *value = ""; - if(((struct ipv6prefix_args *)data)->ip_6prefixaddress[0] != '\0') - dmasprintf(value, "Device.IP.Interface.%s.IPv6Prefix.1.", inst); - return 0; -} - -int set_IPInterfaceIPv6Address_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -/*#Device.IP.Interface.{i}.IPv6Address.{i}.PreferredLifetime!UCI:network/interface,@i-1/adv_preferred_lifetime*/ -int get_IPInterfaceIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char local_time[32] = {0}; - char *preferred = ((struct ipv6_args *)data)->ip_6preferred; - *value = "0001-01-01T00:00:00Z"; - if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) - return 0; - *value = dmstrdup(local_time); - return 0; -} - -int set_IPInterfaceIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char buf[32] = "", *proto; - - switch (action) { - case VALUECHECK: - if (dm_validate_dateTime(value)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", &proto); - if(strcasecmp(proto, "static") == 0) { - get_shift_time_shift(value, buf); - if (!(*buf)) - return 0; - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "adv_preferred_lifetime", buf); - } - return 0; - } - return 0; -} - -/*#Device.IP.Interface.{i}.IPv6Address.{i}.ValidLifetime!UCI:network/interface,@i-1/adv_valid_lifetime*/ -int get_IPInterfaceIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char local_time[32] = {0}; - char *preferred = ((struct ipv6_args *)data)->ip_6valid; - *value = "0001-01-01T00:00:00Z"; - if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) - return 0; - *value = dmstrdup(local_time); - return 0; -} - -int set_IPInterfaceIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char buf[32] = "", *proto; - - switch (action) { - case VALUECHECK: - if (dm_validate_dateTime(value)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct ipv6_args *)data)->ip_sec, "proto", &proto); - if(strcasecmp(proto, "static") == 0) { - get_shift_time_shift(value, buf); - if (!(*buf)) - return 0; - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "adv_valid_lifetime", buf); - } - return 0; - } - return 0; -} - -/* - * *** Device.IP.Interface.{i}.IPv6Prefix.{i}. *** - */ -int get_IPInterfaceIPv6Prefix_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int set_IPInterfaceIPv6Prefix_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_IPInterfaceIPv6Prefix_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Enabled"; - return 0; -} - -int get_IPInterfaceIPv6Prefix_PrefixStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - if(((struct ipv6prefix_args *)data)->ip_6prefixvalid[0] != '\0') - *value = "Preferred"; - else - *value = "Unknown"; - return 0; -} - -/*#Device.IP.Interface.{i}.IPv6Prefix.{i}.Prefix!UCI:network/interface,@i-1/ip6prefix*/ -int get_IPInterfaceIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct ipv6prefix_args *)data)->ip_6prefixaddress; - if(((struct ipv6prefix_args *)data)->ip_6prefixmask[0] != '\0') - dmasprintf(value, "%s/%s", ((struct ipv6prefix_args *)data)->ip_6prefixaddress, ((struct ipv6prefix_args *)data)->ip_6prefixmask); - return 0; -} - -int set_IPInterfaceIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *proto; - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "49", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct ipv6prefix_args *)data)->ip_sec, "proto", &proto); - if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "ip6prefix", value); - return 0; - } - return 0; -} - -int get_IPInterfaceIPv6Prefix_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ubus_call_get_value(section_name(((struct ipv6prefix_args *)data)->ip_sec), "ipv6-prefix-assignment", "address"); - if(*value[0] != '\0') - *value = "AutoConfigured"; - else { - dmuci_get_value_by_section_string(((struct ipv6prefix_args *)data)->ip_sec, "proto", value); - if (strcmp(*value, "static") == 0) - *value = "Static"; - else if (strcmp(*value, "dhcpv6") == 0) - *value = "DHCPv6"; - else - *value = "WellKnown"; - } - return 0; -} - -int get_IPInterfaceIPv6Prefix_StaticType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Static"; - return 0; -} - -int set_IPInterfaceIPv6Prefix_StaticType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, StaticType, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_IPInterfaceIPv6Prefix_ParentPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *linker; - dmasprintf(&linker, "%s/%s", ((struct ipv6prefix_args *)data)->ip_6prefixaddress, ((struct ipv6prefix_args *)data)->ip_6prefixmask); - if(linker[0] != '\0') - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - *value = ""; - return 0; -} - -int set_IPInterfaceIPv6Prefix_ParentPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_IPInterfaceIPv6Prefix_ChildPrefixBits(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_child_prefix_linker(section_name(((struct ipv6prefix_args *)data)->ip_sec)); - return 0; -} - -int set_IPInterfaceIPv6Prefix_ChildPrefixBits(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "49", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_IPInterfaceIPv6Prefix_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char local_time[32] = {0}; - char *preferred = ((struct ipv6prefix_args *)data)->ip_6prefixpreferred; - *value = "0001-01-01T00:00:00Z"; - if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) - return 0; - *value = dmstrdup(local_time); - return 0; -} - -int set_IPInterfaceIPv6Prefix_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_dateTime(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_IPInterfaceIPv6Prefix_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char local_time[32] = {0}; - char *preferred = ((struct ipv6prefix_args *)data)->ip_6prefixvalid; - *value = "0001-01-01T00:00:00Z"; - if (get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1) - return 0; - *value = dmstrdup(local_time); - return 0; -} - -int set_IPInterfaceIPv6Prefix_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_dateTime(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -/* - * *** Device.IP.Interface.{i}.Stats. *** - */ -int get_ip_interface_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return get_ip_iface_sysfs(data, "statistics/tx_bytes", value); -} - -int get_ip_interface_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return get_ip_iface_sysfs(data, "statistics/rx_bytes", value); -} - -int get_ip_interface_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return get_ip_iface_sysfs(data, "statistics/tx_packets", value); -} - -int get_ip_interface_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return get_ip_iface_sysfs(data, "statistics/rx_packets", value); -} - -int get_ip_interface_statistics_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return get_ip_iface_sysfs(data, "statistics/tx_errors", value); -} - -int get_ip_interface_statistics_rx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return get_ip_iface_sysfs(data, "statistics/rx_errors", value); -} - -int get_ip_interface_statistics_tx_discardpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return get_ip_iface_sysfs(data, "statistics/tx_dropped", value); -} - -int get_ip_interface_statistics_rx_discardpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return get_ip_iface_sysfs(data, "statistics/rx_dropped", value); -} - -int get_ip_interface_statistics_tx_unicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_ip_interface_statistics_rx_unicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_ip_interface_statistics_tx_multicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_ip_interface_statistics_rx_multicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return get_ip_iface_sysfs(data, "statistics/multicast", value); -} - -int get_ip_interface_statistics_tx_broadcastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_ip_interface_statistics_rx_broadcastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_ip_interface_statistics_rx_unknownprotopackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/* - * *** Device.IP.Interface.{i}.TWAMPReflector.{i}. *** - */ -int get_IPInterfaceTWAMPReflector_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "enable", value); - return 0; -} - -int set_IPInterfaceTWAMPReflector_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - struct uci_section *s; - char *interface, *device, *id, *ipv4addr = ""; - json_object *res, *jobj; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - if(b) { - dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface); - dmuci_get_value_by_section_string((struct uci_section *)data, "id", &id); - dmuci_set_value_by_section((struct uci_section *)data, "enable", "1"); - dmuci_set_value("cwmp_twamp", "twamp", "id", id); - uci_foreach_sections("network", "interface", s) { - if(strcmp(section_name(s), interface) != 0) - continue; - dmuci_get_value_by_section_string(s, "ipaddr", &ipv4addr); - break; - } - if (ipv4addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - ipv4addr = dmjson_get_value(jobj, 1, "address"); - if (ipv4addr[0] == '\0') - dmuci_set_value_by_section((struct uci_section *)data, "ip_version", "6"); - else - dmuci_set_value_by_section((struct uci_section *)data, "ip_version", "4"); - } - } else - dmuci_set_value_by_section((struct uci_section *)data, "ip_version", "4"); - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); - if (res) { - device = dmjson_get_value(res, 1, "device"); - dmuci_set_value_by_section((struct uci_section *)data, "device", device); - } - dmuci_set_value_by_section((struct uci_section *)data, "device", get_device(interface)); - } else { - dmuci_set_value_by_section((struct uci_section *)data, "enable", "0"); - } - break; - } - return 0; -} - -int get_IPInterfaceTWAMPReflector_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *enable; - - dmuci_get_value_by_section_string((struct uci_section *)data, "enable", &enable); - if (strcmp(enable, "1") == 0) - *value = "Active"; - else - *value = "Disabled"; - return 0; -} - -int get_IPInterfaceTWAMPReflector_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "twamp_alias", value); - return 0; -} - -int set_IPInterfaceTWAMPReflector_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "twamp_alias", value); - break; - } - return 0; -} - -int get_IPInterfaceTWAMPReflector_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "port", value); - return 0; -} - -int set_IPInterfaceTWAMPReflector_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, "65535")) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "port", value); - break; - } - return 0; -} - -int get_IPInterfaceTWAMPReflector_MaximumTTL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "max_ttl", value); - return 0; -} - -int set_IPInterfaceTWAMPReflector_MaximumTTL(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", "255")) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "max_ttl", value); - break; - } - return 0; -} - -int get_IPInterfaceTWAMPReflector_IPAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "ip_list", value); - return 0; -} - -int set_IPInterfaceTWAMPReflector_IPAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "255", NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "ip_list", value); - break; - } - return 0; -} - -int get_IPInterfaceTWAMPReflector_PortAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "port_list", value); - return 0; -} - -int set_IPInterfaceTWAMPReflector_PortAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "255", NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "port_list", value); - break; - } - return 0; -} - -/************************************************************* -* GET & SET ALIAS -**************************************************************/ -int get_IPInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "ip_int_alias", value); - return 0; -} - -int set_IPInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - if (dmmap_section != NULL) - dmuci_set_value_by_section(dmmap_section, "ip_int_alias", value); - return 0; - } - return 0; -} - -int get_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "ipv4_alias", value); - return 0; -} - -int set_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - if (dmmap_section != NULL) - dmuci_set_value_by_section(dmmap_section, "ipv4_alias", value); - return 0; - } - return 0; -} - -int get_IPInterfaceIPv6Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - char *name; - - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "ipv6_instance", instance, dmmap_section) { - dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); - if(strcmp(name, section_name(((struct ipv6_args *)data)->ip_sec)) == 0) - dmuci_get_value_by_section_string(dmmap_section, "ipv6_alias", value); - } - return 0; -} - -int set_IPInterfaceIPv6Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - char *name; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "ipv6_instance", instance, dmmap_section) { - dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); - if(strcmp(name, section_name(((struct ipv6_args *)data)->ip_sec)) == 0) - break; - } - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "ipv6_alias", value); - return 0; - } - return 0; -} - -int get_IPInterfaceIPv6Prefix_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - char *name; - - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "ipv6prefix_instance", instance, dmmap_section) { - dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); - if(strcmp(name, section_name(((struct ipv6prefix_args *)data)->ip_sec)) == 0) - dmuci_get_value_by_section_string(dmmap_section, "ipv6prefix_alias", value); - } - return 0; -} - -int set_IPInterfaceIPv6Prefix_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - char *name; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "ipv6prefix_instance", instance, dmmap_section) { - dmuci_get_value_by_section_string(dmmap_section, "section_name", &name); - if(strcmp(name, section_name(((struct ipv6prefix_args *)data)->ip_sec)) == 0) - break; - } - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "ipv6prefix_alias", value); - return 0; - } - return 0; -} - -/************************************************************* -* ADD & DEL OBJ -**************************************************************/ -char *get_last_instance_cond(char* dmmap_package, char *package, char *section, char *opt_inst, char *opt_cond, char *cond_val, char *opt_filter, char *filter_val, char *refused_interface) -{ - struct uci_section *s, *dmmap_section; - char *inst = NULL, *val, *val_f; - char *ipv4addr = "", *ipv6addr = "", *proto; - json_object *res, *jobj; - - uci_foreach_sections(package, section, s) { - if (opt_cond) dmuci_get_value_by_section_string(s, opt_cond, &val); - if (opt_filter) dmuci_get_value_by_section_string(s, opt_filter, &val_f); - if(opt_cond && opt_filter && (strcmp(val, cond_val) == 0 || strcmp(val_f, filter_val) == 0)) - continue; - if (strcmp(section_name(s), refused_interface)==0) - continue; - - dmuci_get_value_by_section_string(s, "ipaddr", &ipv4addr); - if (ipv4addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); - ipv4addr = dmjson_get_value(jobj, 1, "address"); - } - } - dmuci_get_value_by_section_string(s, "ip6addr", &ipv6addr); - if (ipv6addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); - if (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address"); - ipv6addr = dmjson_get_value(jobj, 1, "address"); - } - } - dmuci_get_value_by_section_string(s, "proto", &proto); - if (ipv4addr[0] == '\0' && ipv6addr[0] == '\0' && strcmp(proto, "dhcp") != 0 && strcmp(proto, "dhcpv6") != 0 && strcmp(val, "bridge") != 0) { - continue; - } - get_dmmap_section_of_config_section(dmmap_package, section, section_name(s), &dmmap_section); - inst = update_instance_bbfdm(dmmap_section, inst, opt_inst); - } - return inst; -} - -int add_ip_interface(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *last_inst, *v; - char ip_name[32], ib[8]; - char *p = ip_name; - struct uci_section *dmmap_ip_interface; - - last_inst = get_last_instance_cond("dmmap_network", "network", "interface", "ip_int_instance", "type", "alias", "proto", "", "loopback"); - snprintf(ib, sizeof(ib), "%d", last_inst ? atoi(last_inst)+1 : 1); - dmstrappendstr(p, "ip_interface_"); - dmstrappendstr(p, ib); - dmstrappendend(p); - dmuci_set_value("network", ip_name, "", "interface"); - dmuci_set_value("network", ip_name, "proto", "dhcp"); - - dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_ip_interface, &v); - dmuci_set_value_by_section(dmmap_ip_interface, "section_name", ip_name); - *instance = update_instance_bbfdm(dmmap_ip_interface, last_inst, "ip_int_instance"); - return 0; -} - -int delete_ip_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *dmmap_section = NULL; - - switch (del_action) { - case DEL_INST: - dmuci_delete_by_section(((struct ip_args *)data)->ip_sec, NULL, NULL); - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - if(dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); - break; - case DEL_ALL: - return FAULT_9005; - } - return 0; -} - -int add_ipv4(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - char *instance; - struct uci_section *dmmap_section; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - dmuci_get_value_by_section_string(dmmap_section, "ipv4_instance", &instance); - *instancepara = update_instance_bbfdm(dmmap_section, instance, "ipv4_instance"); - if(instance[0] == '\0') { - dmuci_set_value_by_section(dmmap_section, "ipv4_instance", *instancepara); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", "0.0.0.0"); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", "static"); - } - return 0; -} - -int delete_ipv4(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *dmmap_section; - - switch (del_action) { - case DEL_INST: - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", ""); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", ""); - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section); - if(dmmap_section != NULL) - dmuci_set_value_by_section(dmmap_section, "ipv4_instance", ""); - break; - case DEL_ALL: - return FAULT_9005; - } - return 0; -} - -int add_ipv6(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - struct uci_section *s, *ss; - char *ip, *name, *inst, *curr_inst; - - uci_foreach_sections("network", "interface", s) { - if(strcmp(section_name(s), section_name(((struct ipv6_args *)data)->ip_sec)) != 0) - continue; - dmuci_get_value_by_section_string(s, "ip6addr", &ip); - break; - } - if(ip[0] == '\0') { - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "section_name", section_name(((struct ipv6_args *)data)->ip_sec), s) { - dmuci_get_value_by_section_string(s, "ipv6_instance", &inst); - } - dmasprintf(&curr_inst, "%d", atoi(inst)+1); - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "ip6addr", "::"); - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "proto", "static"); - DMUCI_ADD_SECTION(bbfdm, "dmmap_network", "ipv6", &ss, &name); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ss, "section_name", section_name(((struct ipv6_args *)data)->ip_sec)); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ss, "ipv6_instance", curr_inst); - } - return 0; -} - -int delete_ipv6(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *dmmap_section; - - get_dmmap_section_of_config_section("dmmap_network", "ipv6", section_name(((struct ipv6_args *)data)->ip_sec), &dmmap_section); - switch (del_action) { - case DEL_INST: - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "ip6addr", ""); - dmuci_set_value_by_section(dmmap_section, "ipv6_instance", ""); - dmuci_set_value_by_section(((struct ipv6_args *)data)->ip_sec, "proto", ""); - break; - case DEL_ALL: - return FAULT_9005; - } - return 0; -} - -int add_ipv6_prefix(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - struct uci_section *s, *ss; - char *ip, *name, *inst, *curr_inst; - - uci_foreach_sections("network", "interface", s) { - if(strcmp(section_name(s), section_name(((struct ipv6prefix_args *)data)->ip_sec)) != 0) - continue; - dmuci_get_value_by_section_string(s, "ip6prefix", &ip); - break; - } - if(ip[0] == '\0') { - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "section_name", section_name(((struct ipv6prefix_args *)data)->ip_sec), s) { - dmuci_get_value_by_section_string(s, "ipv6prefix_instance", &inst); - } - dmasprintf(&curr_inst, "%d", atoi(inst)+1); - dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6prefix", "::"); - dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "proto", "static"); - DMUCI_ADD_SECTION(bbfdm, "dmmap_network", "ipv6prefix", &ss, &name); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ss, "section_name", section_name(((struct ipv6prefix_args *)data)->ip_sec)); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, ss, "ipv6prefix_instance", curr_inst); - } - return 0; -} - -int delete_ipv6_prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *dmmap_section; - - get_dmmap_section_of_config_section("dmmap_network", "ipv6prefix", section_name(((struct ipv6prefix_args *)data)->ip_sec), &dmmap_section); - switch (del_action) { - case DEL_INST: - dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "ip6prefix", ""); - dmuci_set_value_by_section(dmmap_section, "ipv6prefix_instance", ""); - dmuci_set_value_by_section(((struct ipv6prefix_args *)data)->ip_sec, "proto", ""); - break; - case DEL_ALL: - return FAULT_9005; - } - return 0; -} - -static char *get_last_instance_with_option(char *package, char *section, char *option, char *val, char *opt_inst) -{ - struct uci_section *s; - char *inst = NULL; - - uci_foreach_option_eq(package, section, option, val, s) { - inst = update_instance(s, inst, opt_inst); - } - return inst; -} - -static char *get_last_id(char *package, char *section) -{ - struct uci_section *s; - char *id; - int cnt = 0; - - uci_foreach_sections(package, section, s) { - cnt++; - } - dmasprintf(&id, "%d", cnt+1); - return id; -} - -int addObjIPInterfaceTWAMPReflector(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct uci_section *connection; - char *value1, *last_inst, *id; - - last_inst = get_last_instance_with_option("cwmp_twamp", "twamp_reflector", "interface", section_name(((struct ip_args *)data)->ip_sec), "twamp_inst"); - id = get_last_id("cwmp_twamp", "twamp_reflector"); - dmuci_add_section("cwmp_twamp", "twamp_reflector", &connection, &value1); - dmasprintf(instance, "%d", last_inst?atoi(last_inst)+1:1); - dmuci_set_value_by_section(connection, "twamp_inst", *instance); - dmuci_set_value_by_section(connection, "id", id); - dmuci_set_value_by_section(connection, "enable", "0"); - dmuci_set_value_by_section(connection, "interface", section_name(((struct ip_args *)data)->ip_sec)); - dmuci_set_value_by_section(connection, "port", "862"); - dmuci_set_value_by_section(connection, "max_ttl", "1"); - return 0; -} - -int delObjIPInterfaceTWAMPReflector(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - int found = 0; - struct uci_section *s, *ss = NULL; - char *interface; - struct uci_section *section = (struct uci_section *)data; - - switch (del_action) { - case DEL_INST: - dmuci_delete_by_section(section, NULL, NULL); - return 0; - case DEL_ALL: - uci_foreach_sections("cwmp_twamp", "twamp_reflector", s) { - dmuci_get_value_by_section_string(s, "interface", &interface); - if(strcmp(interface, section_name(((struct ip_args *)data)->ip_sec)) != 0) - continue; - if (found != 0) { - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - dmuci_delete_by_section(ss, NULL, NULL); - } - return 0; - } - return 0; -} - -/************************************************************************** -* LINKER -***************************************************************************/ -int get_linker_ip_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct ip_args *)data)->ip_sec) { - dmasprintf(linker,"%s", section_name(((struct ip_args *)data)->ip_sec)); - return 0; - } else { - *linker = ""; - return 0; - } -} - -int get_linker_ipv6_prefix(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (((struct ipv6prefix_args *)data)->ip_sec) { - dmasprintf(linker,"%s", get_child_prefix_linker(section_name(((struct ipv6prefix_args *)data)->ip_sec))); - return 0; - } else { - *linker = ""; - return 0; - } -} - -/************************************************************* -* ENTRY METHOD -**************************************************************/ -/*#Device.IP.Interface.{i}.!UCI:network/interface/dmmap_network*/ -int browseIPIfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *ip_int = NULL, *ip_int_last = NULL; - char *type, *ipv4addr = ""; - struct ip_args curr_ip_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("network", "interface", "dmmap_network", &dup_list); - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "type", &type); - if (strcmp(type, "alias") == 0 || strcmp(section_name(p->config_section), "loopback")==0) - continue; - - /* IPv4 address */ - dmuci_get_value_by_section_string(p->config_section, "ipaddr", &ipv4addr); - if (ipv4addr[0] == '\0') - ipv4addr = ubus_call_get_value(section_name(p->config_section), "ipv4-address", "address"); - - init_ip_args(&curr_ip_args, p->config_section, ipv4addr); - ip_int = handle_update_instance(1, dmctx, &ip_int_last, update_instance_alias, 3, p->dmmap_section, "ip_int_instance", "ip_int_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ip_args, ip_int) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int browseIfaceIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *ipv4_inst = NULL, *ipv4_inst_last = NULL; - struct uci_section *dmmap_section; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)prev_data)->ip_sec), &dmmap_section); - if(((struct ip_args *)prev_data)->ip_4address[0] != '\0') { - ipv4_inst = handle_update_instance(2, dmctx, &ipv4_inst_last, update_instance_alias, 3, dmmap_section, "ipv4_instance", "ipv4_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, prev_data, ipv4_inst) == DM_STOP) - goto end; - } -end: - return 0; -} - -static struct uci_section *update_dmmap_network_ipv6(char *curr_inst, char *section_name) -{ - struct uci_section *s = NULL; - char *inst, *name; - - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6", "section_name", section_name, s) { - dmuci_get_value_by_section_string(s, "ipv6_instance", &inst); - if(strcmp(curr_inst, inst) == 0) - return s; - } - if (!s) { - DMUCI_ADD_SECTION(bbfdm, "dmmap_network", "ipv6", &s, &name); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "section_name", section_name); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "ipv6_instance", curr_inst); - } - return s; -} - -int browseIfaceIPv6Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *s; - char *ipv6_int = NULL, *ipv6_int_last = NULL, *ipv6addr = "", *ipv6mask = "", *ipv6_preferred = "", *ipv6_valid = "", buf[4]=""; - struct ipv6_args curr_ipv6_args = {0}; - json_object *res, *jobj, *jobj1; - int entries = 0; - - if(prev_data && ((struct ip_args *)prev_data)->ip_sec) { - dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "ip6addr", &ipv6addr); - dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "adv_preferred_lifetime", &ipv6_preferred); - dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "adv_valid_lifetime", &ipv6_valid); - if (ipv6addr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)prev_data)->ip_sec), String}}, 1, &res); - while (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-prefix-assignment"); - if(jobj) { - jobj1 = dmjson_get_obj(jobj, 1, "local-address"); - if(jobj1) { - ipv6addr = dmjson_get_value(jobj1, 1, "address"); - ipv6mask = dmjson_get_value(jobj1, 1, "mask"); - goto browse; - } - } - jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "ipv6-address"); - if(jobj) { - ipv6addr = dmjson_get_value(jobj, 1, "address"); - ipv6mask = dmjson_get_value(jobj, 1, "mask"); - if (ipv6_preferred[0] == '\0') - ipv6_preferred = dmjson_get_value(jobj, 1, "preferred"); - if (ipv6_valid[0] == '\0') - ipv6_valid = dmjson_get_value(jobj, 1, "valid"); - entries++; - snprintf(buf, sizeof(buf), "%d", entries); - s = update_dmmap_network_ipv6(buf, section_name(((struct ip_args *)prev_data)->ip_sec)); - init_ipv6_args(&curr_ipv6_args, ((struct ip_args *)prev_data)->ip_sec, ipv6addr, ipv6mask, ipv6_preferred, ipv6_valid); - ipv6_int = handle_update_instance(1, dmctx, &ipv6_int_last, update_instance_alias, 3, s, "ipv6_instance", "ipv6_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6_args, ipv6_int) == DM_STOP) - goto end; - } else - goto end; - } - } -browse: - s = update_dmmap_network_ipv6("1", section_name(((struct ip_args *)prev_data)->ip_sec)); - init_ipv6_args(&curr_ipv6_args, ((struct ip_args *)prev_data)->ip_sec, ipv6addr, ipv6mask, ipv6_preferred, ipv6_valid); - ipv6_int = handle_update_instance(1, dmctx, &ipv6_int_last, update_instance_alias, 3, s, "ipv6_instance", "ipv6_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6_args, ipv6_int) == DM_STOP) - goto end; - } -end: - return 0; -} - - -static struct uci_section *update_dmmap_network_ipv6prefix(char *curr_inst, char *section_name) -{ - struct uci_section *s = NULL; - char *inst, *name; - - uci_path_foreach_option_eq(bbfdm, "dmmap_network", "ipv6prefix", "section_name", section_name, s) { - dmuci_get_value_by_section_string(s, "ipv6prefix_instance", &inst); - if(strcmp(curr_inst, inst) == 0) - return s; - } - if (!s) { - DMUCI_ADD_SECTION(bbfdm, "dmmap_network", "ipv6prefix", &s, &name); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "section_name", section_name); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "ipv6prefix_instance", curr_inst); - } - return s; -} - -int browseIfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *s; - char *ipv6prefix_int = NULL, *ipv6prefix_int_last = NULL, *ipv6prefixaddr = "", *ipv6prefixmask = "", *ipv6prefix_preferred = "", *ipv6prefix_valid = "", buf[4] = ""; - struct ipv6prefix_args curr_ipv6prefix_args = {0}; - json_object *res, *jobj; - int entries = 0; - - if(prev_data && ((struct ip_args *)prev_data)->ip_sec) { - dmuci_get_value_by_section_string(((struct ip_args *)prev_data)->ip_sec, "ip6prefix", &ipv6prefixaddr); - if (ipv6prefixaddr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)prev_data)->ip_sec), String}}, 1, &res); - while (res) { - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-prefix-assignment"); - if(jobj) { - ipv6prefixaddr = dmjson_get_value(jobj, 1, "address"); - ipv6prefixmask = dmjson_get_value(jobj, 1, "mask"); - ipv6prefix_preferred = dmjson_get_value(jobj, 1, "preferred"); - ipv6prefix_valid = dmjson_get_value(jobj, 1, "valid"); - goto browse; - } - jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "ipv6-prefix"); - if(jobj) { - ipv6prefixaddr = dmjson_get_value(jobj, 1, "address"); - ipv6prefixmask = dmjson_get_value(jobj, 1, "mask"); - ipv6prefix_preferred = dmjson_get_value(jobj, 1, "preferred"); - ipv6prefix_valid = dmjson_get_value(jobj, 1, "valid"); - entries++; - snprintf(buf, sizeof(buf), "%d", entries); - s = update_dmmap_network_ipv6prefix(buf, section_name(((struct ip_args *)prev_data)->ip_sec)); - init_ipv6prefix_args(&curr_ipv6prefix_args, ((struct ip_args *)prev_data)->ip_sec, ipv6prefixaddr, ipv6prefixmask, ipv6prefix_preferred, ipv6prefix_valid); - ipv6prefix_int = handle_update_instance(1, dmctx, &ipv6prefix_int_last, update_instance_alias, 3, s, "ipv6prefix_instance", "ipv6prefix_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6prefix_args, ipv6prefix_int) == DM_STOP) - goto end; - } else - goto end; - } - } -browse: - s = update_dmmap_network_ipv6prefix("1", section_name(((struct ip_args *)prev_data)->ip_sec)); - init_ipv6prefix_args(&curr_ipv6prefix_args, ((struct ip_args *)prev_data)->ip_sec, ipv6prefixaddr, ipv6prefixmask, ipv6prefix_preferred, ipv6prefix_valid); - ipv6prefix_int = handle_update_instance(1, dmctx, &ipv6prefix_int_last, update_instance_alias, 3, s, "ipv6prefix_instance", "ipv6prefix_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ipv6prefix_args, ipv6prefix_int) == DM_STOP) - goto end; - } -end: - return 0; -} - -int browseIPInterfaceTWAMPReflectorInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *s = NULL; - char *twamp_inst = NULL, *twamp_inst_last = NULL; - - uci_foreach_option_eq("cwmp_twamp", "twamp_reflector", "interface", section_name(((struct ip_args *)prev_data)->ip_sec), s) { - twamp_inst = handle_update_instance(2, dmctx, &twamp_inst_last, update_instance_alias, 3, (void *)s, "twamp_inst", "twamp_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, twamp_inst) == DM_STOP) - break; - } - return 0; -} diff --git a/dmtree/tr181/ip.h b/dmtree/tr181/ip.h index fc2a43e3..50837393 100644 --- a/dmtree/tr181/ip.h +++ b/dmtree/tr181/ip.h @@ -15,30 +15,6 @@ #include -struct ip_args -{ - struct uci_section *ip_sec; - char *ip_4address; -}; - -struct ipv6_args -{ - struct uci_section *ip_sec; - char *ip_6address; - char *ip_6mask; - char *ip_6preferred; - char *ip_6valid; -}; - -struct ipv6prefix_args -{ - struct uci_section *ip_sec; - char *ip_6prefixaddress; - char *ip_6prefixmask; - char *ip_6prefixpreferred; - char *ip_6prefixvalid; -}; - extern DMOBJ tIPObj[]; extern DMLEAF tIPParams[]; extern DMOBJ tIPInterfaceObj[]; @@ -49,142 +25,4 @@ extern DMLEAF tIPInterfaceIPv6PrefixParams[]; extern DMLEAF tIPInterfaceStatsParams[]; extern DMLEAF tIPInterfaceTWAMPReflectorParams[]; -unsigned char get_ipv4_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance); -unsigned char get_ipv6_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance); - -int get_linker_ip_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); -int get_linker_ipv6_prefix(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); - -int browseIPIfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseIfaceIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseIfaceIPv6Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseIfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseIPInterfaceTWAMPReflectorInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int add_ip_interface(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_ip_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int add_ipv4(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_ipv4(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int add_ipv6(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_ipv6(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int add_ipv6_prefix(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delete_ipv6_prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjIPInterfaceTWAMPReflector(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjIPInterfaceTWAMPReflector(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_IP_IPv4Capable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IP_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IP_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IP_IPv4Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IP_IPv6Capable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IP_IPv6Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IP_ULAPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IP_ULAPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IP_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_ipv4_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_IPInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterface_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterface_IPv4Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterface_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterface_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterface_Router(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterface_Router(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterface_MaxMTUSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterface_MaxMTUSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterface_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterface_Loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterface_Loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterface_IPv4AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterface_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterface_IPv6PrefixNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterface_TWAMPReflectorNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Address_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterfaceIPv6Address_IPAddressStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterfaceIPv6Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Address_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Address_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterfaceIPv6Address_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Address_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_IPInterfaceIPv6Prefix_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Prefix_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Prefix_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterfaceIPv6Prefix_PrefixStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterfaceIPv6Prefix_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Prefix_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Prefix_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterfaceIPv6Prefix_StaticType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Prefix_StaticType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Prefix_ParentPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Prefix_ParentPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Prefix_ChildPrefixBits(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Prefix_ChildPrefixBits(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Prefix_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Prefix_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceIPv6Prefix_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceIPv6Prefix_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_IPInterfaceTWAMPReflector_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceTWAMPReflector_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceTWAMPReflector_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_IPInterfaceTWAMPReflector_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceTWAMPReflector_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceTWAMPReflector_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceTWAMPReflector_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceTWAMPReflector_MaximumTTL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceTWAMPReflector_MaximumTTL(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceTWAMPReflector_IPAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceTWAMPReflector_IPAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_IPInterfaceTWAMPReflector_PortAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_IPInterfaceTWAMPReflector_PortAllowedList(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_ip_interface_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_rx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_tx_discardpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_rx_discardpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_tx_unicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_rx_unicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_tx_multicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_rx_multicastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_tx_broadcastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_rx_broadcastpackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ip_interface_statistics_rx_unknownprotopackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - #endif diff --git a/dmtree/tr181/managementserver.c b/dmtree/tr181/managementserver.c index 0a1475a0..7a7c93cb 100644 --- a/dmtree/tr181/managementserver.c +++ b/dmtree/tr181/managementserver.c @@ -12,6 +12,683 @@ #include "managementserver.h" +/*#Device.ManagementServer.URL!UCI:cwmp/cwmp,acs/url*/ +static int get_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *dhcp = NULL, *url = NULL, *provisioning_value = NULL; + + dmuci_get_option_value_string("cwmp", "acs", "dhcp_discovery", &dhcp); + dmuci_get_option_value_string("cwmp", "acs", "url", &url); + dmuci_get_varstate_string("cwmp", "acs", "dhcp_url", &provisioning_value); + + if ( ((dhcp && strcmp(dhcp, "enable") == 0 ) || ((url == NULL) || (url[0] == '\0'))) && ((provisioning_value != NULL) && (provisioning_value[0] != '\0')) ) + *value = provisioning_value; + else if ((url != NULL) && (url[0] != '\0')) + *value = url; + else + *value = dmstrdup("http://192.168.1.1:8080/openacs/acs"); + return 0; +} + +static int set_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value("cwmp", "acs", "dhcp_discovery", "disable"); + dmuci_set_value("cwmp", "acs", "url", value); + cwmp_set_end_session(END_SESSION_RELOAD); + break; + } + return 0; +} + +/*#Device.ManagementServer.Username!UCI:cwmp/cwmp,acs/userid*/ +static int get_management_server_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "acs", "userid", value); + return 0; +} + +static int set_management_server_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp", "acs", "userid", value); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.Password!UCI:cwmp/cwmp,acs/passwd*/ +static int set_management_server_passwd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp", "acs", "passwd", value); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.ParameterKey!UCI:cwmp/cwmp,acs/ParameterKey*/ +static int get_management_server_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "acs", "ParameterKey", value); + return 0; +} + +/*#Device.ManagementServer.PeriodicInformEnable!UCI:cwmp/cwmp,acs/periodic_inform_enable*/ +static int get_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "acs", "periodic_inform_enable", value); + return 0; +} + +static int set_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value("cwmp", "acs", "periodic_inform_enable", b ? "1" : "0"); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.PeriodicInformInterval!UCI:cwmp/cwmp,acs/periodic_inform_interval*/ +static int get_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "acs", "periodic_inform_interval", value); + return 0; +} + +static int set_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp", "acs", "periodic_inform_interval", value); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.PeriodicInformTime!UCI:cwmp/cwmp,acs/periodic_inform_time*/ +static int get_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + time_t time_value; + + dmuci_get_option_value_string("cwmp", "acs", "periodic_inform_time", value); + if ((*value)[0] != '0' && (*value)[0] != '\0') { + time_value = atoi(*value); + char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"]; + strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&time_value)); + *value = dmstrdup(s_now); // MEM WILL BE FREED IN DMMEMCLEAN + } else { + *value = "0001-01-01T00:00:00Z"; + } + return 0; +} + +static int set_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct tm tm; + char buf[16]; + + switch (action) { + case VALUECHECK: + if (dm_validate_dateTime(value)) + return FAULT_9007; + return 0; + case VALUESET: + strptime(value, "%Y-%m-%dT%H:%M:%S", &tm); + snprintf(buf, sizeof(buf), "%ld", mktime(&tm)); + dmuci_set_value("cwmp", "acs", "periodic_inform_time", buf); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.ConnectionRequestURL!UCI:cwmp/cwmp,cpe/port*/ +static int get_management_server_connection_request_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *ip, *port, *iface; + + dmuci_get_option_value_string("cwmp", "cpe", "default_wan_interface", &iface); + network_get_ipaddr(&ip, iface); + dmuci_get_option_value_string("cwmp", "cpe", "port", &port); + if (ip[0] != '\0' && port[0] != '\0') { + char buf[64]; + snprintf(buf, sizeof(buf), "http://%s:%s/", ip, port); + *value = dmstrdup(buf); // MEM WILL BE FREED IN DMMEMCLEAN + } + return 0; +} + +/*#Device.ManagementServer.ConnectionRequestUsername!UCI:cwmp/cwmp,cpe/userid*/ +static int get_management_server_connection_request_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "cpe", "userid", value); + return 0; +} + +static int set_management_server_connection_request_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp", "cpe", "userid", value); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.ConnectionRequestPassword!UCI:cwmp/cwmp,cpe/passwd*/ +static int set_management_server_connection_request_passwd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp", "cpe", "passwd", value); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +static int get_lwn_protocol_supported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "UDP"; + return 0; +} + +/*#Device.ManagementServer.LightweightNotificationProtocolsUsed!UCI:cwmp/cwmp,lwn/enable*/ +static int get_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + bool b; + char *tmp; + + dmuci_get_option_value_string("cwmp", "lwn", "enable", &tmp); + string_to_bool(tmp, &b); + *value = b ? "UDP" : ""; + return 0; +} + +static int set_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (strcmp(value,"UDP") == 0) + dmuci_set_value("cwmp", "lwn", "enable", "1"); + else + dmuci_set_value("cwmp", "lwn", "enable", "0"); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.UDPLightweightNotificationHost!UCI:cwmp/cwmp,lwn/hostname*/ +static int get_lwn_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "lwn", "hostname", value); + return 0; +} + +static int set_lwn_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp", "lwn", "hostname", value); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.UDPLightweightNotificationPort!UCI:cwmp/cwmp,lwn/port*/ +static int get_lwn_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "lwn", "port", value); + return 0; +} + +static int set_lwn_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp", "lwn", "port", value); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +static int get_management_server_http_compression_supportted(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "GZIP,Deflate"; + return 0; +} + +/*#Device.ManagementServer.HTTPCompression!UCI:cwmp/cwmp,acs/compression*/ +static int get_management_server_http_compression(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "acs", "compression", value); + return 0; +} + +static int set_management_server_http_compression(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (strcasecmp(value, "gzip") == 0 || strcasecmp(value, "deflate") == 0 || strncasecmp(value, "disable", 7) == 0) { + dmuci_set_value("cwmp", "acs", "compression", value); + cwmp_set_end_session(END_SESSION_RELOAD); + } + return 0; + } + return 0; +} + +/*#Device.ManagementServer.CWMPRetryMinimumWaitInterval!UCI:cwmp/cwmp,acs/retry_min_wait_interval*/ +static int get_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "acs", "retry_min_wait_interval", value); + return 0; +} + +static int set_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", "65535")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp", "acs", "retry_min_wait_interval", value); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.CWMPRetryIntervalMultiplier!UCI:cwmp/cwmp,acs/retry_interval_multiplier*/ +static int get_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "acs", "retry_interval_multiplier", value); + return 0; +} + +static int set_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1000", "65535")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp", "acs", "retry_interval_multiplier", value); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.AliasBasedAddressing!UCI:cwmp/cwmp,cpe/amd_version*/ +static int get_alias_based_addressing(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "cpe", "amd_version", value); + if ((*value)[0] == '\0'|| atoi(*value) <= AMD_4) + *value = "false"; + else + *value = "true"; + return 0; +} + +/*#Device.ManagementServer.InstanceMode!UCI:cwmp/cwmp,cpe/instance_mode*/ +static int get_instance_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp", "cpe", "instance_mode", value); + return 0; +} + +static int set_instance_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, InstanceMode, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp", "cpe", "instance_mode", value); + cwmp_set_end_session(END_SESSION_RELOAD); + return 0; + } + return 0; +} + +/* + * STUN parameters + */ +/*#Device.ManagementServer.UDPConnectionRequestAddress!UCI:cwmp_stun/stun,stun/crudp_address*/ +static int get_upd_cr_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_varstate_string("cwmp_stun", "stun", "crudp_address", value); + return 0; +} + +static int get_stun_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *path = "/etc/rc.d/*icwmp_stund"; + if (check_file(path)) + *value = "1"; + else + *value = "0"; + return 0; +} + +static int set_stun_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if(b) { + DMCMD("/etc/rc.common", 2, "/etc/init.d/icwmp_stund", "enable"); + DMCMD("/etc/rc.common", 2, "/etc/init.d/icwmp_stund", "start"); + } + else { + DMCMD("/etc/rc.common", 2, "/etc/init.d/icwmp_stund", "disable"); + DMCMD("/etc/rc.common", 2, "/etc/init.d/icwmp_stund", "stop"); + } + return 0; + } + return 0; +} + +/*#Device.ManagementServer.STUNServerAddress!UCI:cwmp_stun/stun,stun/server_address*/ +static int get_stun_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp_stun", "stun", "server_address", value); + return 0; +} + +static int set_stun_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp_stun", "stun", "server_address", value); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.STUNServerPort!UCI:cwmp_stun/stun,stun/server_port*/ +static int get_stun_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp_stun", "stun", "server_port", value); + return 0; +} + +static int set_stun_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "0", "65535")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp_stun", "stun", "server_port", value); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.STUNUsername!UCI:cwmp_stun/stun,stun/username*/ +static int get_stun_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp_stun", "stun", "username", value); + return 0; +} + +static int set_stun_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp_stun", "stun", "username", value); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.STUNPassword!UCI:cwmp_stun/stun,stun/password*/ +static int get_stun_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ""; + return 0; +} + +static int set_stun_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp_stun", "stun", "password", value); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.STUNMaximumKeepAlivePeriod!UCI:cwmp_stun/stun,stun/max_keepalive*/ +static int get_stun_maximum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp_stun", "stun", "max_keepalive", value); + return 0; +} + +static int set_stun_maximum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp_stun", "stun", "max_keepalive", value); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.STUNMinimumKeepAlivePeriod!UCI:cwmp_stun/stun,stun/min_keepalive*/ +static int get_stun_minimum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp_stun", "stun", "min_keepalive", value); + return 0; +} + +static int set_stun_minimum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp_stun", "stun", "min_keepalive", value); + return 0; + } + return 0; +} + +/*#Device.ManagementServer.NATDetected!UCI:cwmp_stun/stun,stun/nat_detected*/ +static int get_nat_detected(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *path = "/etc/rc.d/*icwmp_stund"; + char *v; + + if (check_file(path)) { //stun is enabled + dmuci_get_varstate_string("cwmp_stun", "stun", "nat_detected", &v); + *value = (*v == '1') ? "true" : "false"; + } else + *value = "false"; + return 0; +} + +/* + * XMPP parameters + */ +/*#Device.ManagementServer.ConnReqAllowedJabberIDs!UCI:cwmp_xmpp/cwmp,xmpp/allowed_jid*/ +static int get_management_server_conn_rep_allowed_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("cwmp_xmpp", "xmpp", "allowed_jid", value); + return 0; +} + +static int set_management_server_conn_rep_allowed_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, "32", NULL, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("cwmp_xmpp", "xmpp", "allowed_jid", value); + return 0; + } + return 0; +} + +static int get_management_server_conn_req_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + char *username, *domain, *resource, *tmpPtr = NULL, *strResponse = NULL; + + uci_foreach_sections("cwmp_xmpp", "xmpp_connection", s) { + dmuci_get_value_by_section_string(s, "username", &username); + dmuci_get_value_by_section_string(s, "domain", &domain); + dmuci_get_value_by_section_string(s, "resource", &resource); + if(*username != '\0' || *domain != '\0' || *resource != '\0') { + if(!strResponse) + dmasprintf(&strResponse, "%s@%s/%s", username, domain, resource); + else { + tmpPtr = dmstrdup(strResponse); + dmfree(strResponse); + dmasprintf(&strResponse, "%s,%s@%s/%s", tmpPtr, username, domain, resource); + dmfree(tmpPtr); + } + } + } + *value = strResponse ? strResponse : ""; + return 0; +} + +static int get_management_server_conn_req_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *id; + + dmuci_get_option_value_string("cwmp_xmpp", "xmpp", "id", &id); + if (strlen(id)) dmasprintf(value, "Device.XMPP.Connection.%s", id); + return 0; +} + +static int set_management_server_conn_req_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *str, *connection_instance; + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if ((str = strstr(value, "Device.XMPP.Connection."))) { + value = dmstrdup(str + sizeof("Device.XMPP.Connection.") - 1); //MEM WILL BE FREED IN DMMEMCLEAN + } + uci_foreach_sections("cwmp_xmpp", "xmpp_connection", s) { + dmuci_get_value_by_section_string(s, "connection_instance", &connection_instance); + if(strcmp(value, connection_instance) == 0) { + dmuci_set_value("cwmp_xmpp", "xmpp", "id", value); + break; + } + } + return 0; + } + return 0; +} + +static int get_management_server_supported_conn_req_methods(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "HTTP,XMPP,STUN"; + return 0; +} + /*** ManagementServer. ***/ DMLEAF tManagementServerParams[] = { /* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ @@ -50,680 +727,3 @@ DMLEAF tManagementServerParams[] = { {"NATDetected", &DMREAD, DMT_BOOL, get_nat_detected, NULL, NULL, NULL, BBFDM_CWMP}, {0} }; - -/*#Device.ManagementServer.URL!UCI:cwmp/cwmp,acs/url*/ -int get_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *dhcp = NULL, *url = NULL, *provisioning_value = NULL; - - dmuci_get_option_value_string("cwmp", "acs", "dhcp_discovery", &dhcp); - dmuci_get_option_value_string("cwmp", "acs", "url", &url); - dmuci_get_varstate_string("cwmp", "acs", "dhcp_url", &provisioning_value); - - if ( ((dhcp && strcmp(dhcp, "enable") == 0 ) || ((url == NULL) || (url[0] == '\0'))) && ((provisioning_value != NULL) && (provisioning_value[0] != '\0')) ) - *value = provisioning_value; - else if ((url != NULL) && (url[0] != '\0')) - *value = url; - else - *value = dmstrdup("http://192.168.1.1:8080/openacs/acs"); - return 0; -} - -int set_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value("cwmp", "acs", "dhcp_discovery", "disable"); - dmuci_set_value("cwmp", "acs", "url", value); - cwmp_set_end_session(END_SESSION_RELOAD); - break; - } - return 0; -} - -/*#Device.ManagementServer.Username!UCI:cwmp/cwmp,acs/userid*/ -int get_management_server_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "acs", "userid", value); - return 0; -} - -int set_management_server_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp", "acs", "userid", value); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.Password!UCI:cwmp/cwmp,acs/passwd*/ -int set_management_server_passwd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp", "acs", "passwd", value); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.ParameterKey!UCI:cwmp/cwmp,acs/ParameterKey*/ -int get_management_server_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "acs", "ParameterKey", value); - return 0; -} - -/*#Device.ManagementServer.PeriodicInformEnable!UCI:cwmp/cwmp,acs/periodic_inform_enable*/ -int get_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "acs", "periodic_inform_enable", value); - return 0; -} - -int set_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value("cwmp", "acs", "periodic_inform_enable", b ? "1" : "0"); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.PeriodicInformInterval!UCI:cwmp/cwmp,acs/periodic_inform_interval*/ -int get_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "acs", "periodic_inform_interval", value); - return 0; -} - -int set_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp", "acs", "periodic_inform_interval", value); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.PeriodicInformTime!UCI:cwmp/cwmp,acs/periodic_inform_time*/ -int get_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - time_t time_value; - - dmuci_get_option_value_string("cwmp", "acs", "periodic_inform_time", value); - if ((*value)[0] != '0' && (*value)[0] != '\0') { - time_value = atoi(*value); - char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"]; - strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&time_value)); - *value = dmstrdup(s_now); // MEM WILL BE FREED IN DMMEMCLEAN - } else { - *value = "0001-01-01T00:00:00Z"; - } - return 0; -} - -int set_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct tm tm; - char buf[16]; - - switch (action) { - case VALUECHECK: - if (dm_validate_dateTime(value)) - return FAULT_9007; - return 0; - case VALUESET: - strptime(value, "%Y-%m-%dT%H:%M:%S", &tm); - snprintf(buf, sizeof(buf), "%ld", mktime(&tm)); - dmuci_set_value("cwmp", "acs", "periodic_inform_time", buf); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.ConnectionRequestURL!UCI:cwmp/cwmp,cpe/port*/ -int get_management_server_connection_request_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *ip, *port, *iface; - - dmuci_get_option_value_string("cwmp", "cpe", "default_wan_interface", &iface); - network_get_ipaddr(&ip, iface); - dmuci_get_option_value_string("cwmp", "cpe", "port", &port); - if (ip[0] != '\0' && port[0] != '\0') { - char buf[64]; - snprintf(buf, sizeof(buf), "http://%s:%s/", ip, port); - *value = dmstrdup(buf); // MEM WILL BE FREED IN DMMEMCLEAN - } - return 0; -} - -/*#Device.ManagementServer.ConnectionRequestUsername!UCI:cwmp/cwmp,cpe/userid*/ -int get_management_server_connection_request_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "cpe", "userid", value); - return 0; -} - -int set_management_server_connection_request_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp", "cpe", "userid", value); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.ConnectionRequestPassword!UCI:cwmp/cwmp,cpe/passwd*/ -int set_management_server_connection_request_passwd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp", "cpe", "passwd", value); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -int get_lwn_protocol_supported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "UDP"; - return 0; -} - -/*#Device.ManagementServer.LightweightNotificationProtocolsUsed!UCI:cwmp/cwmp,lwn/enable*/ -int get_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - bool b; - char *tmp; - - dmuci_get_option_value_string("cwmp", "lwn", "enable", &tmp); - string_to_bool(tmp, &b); - *value = b ? "UDP" : ""; - return 0; -} - -int set_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (strcmp(value,"UDP") == 0) - dmuci_set_value("cwmp", "lwn", "enable", "1"); - else - dmuci_set_value("cwmp", "lwn", "enable", "0"); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.UDPLightweightNotificationHost!UCI:cwmp/cwmp,lwn/hostname*/ -int get_lwn_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "lwn", "hostname", value); - return 0; -} - -int set_lwn_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp", "lwn", "hostname", value); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.UDPLightweightNotificationPort!UCI:cwmp/cwmp,lwn/port*/ -int get_lwn_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "lwn", "port", value); - return 0; -} - -int set_lwn_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp", "lwn", "port", value); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -int get_management_server_http_compression_supportted(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "GZIP,Deflate"; - return 0; -} - -/*#Device.ManagementServer.HTTPCompression!UCI:cwmp/cwmp,acs/compression*/ -int get_management_server_http_compression(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "acs", "compression", value); - return 0; -} - -int set_management_server_http_compression(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (strcasecmp(value, "gzip") == 0 || strcasecmp(value, "deflate") == 0 || strncasecmp(value, "disable", 7) == 0) { - dmuci_set_value("cwmp", "acs", "compression", value); - cwmp_set_end_session(END_SESSION_RELOAD); - } - return 0; - } - return 0; -} - -/*#Device.ManagementServer.CWMPRetryMinimumWaitInterval!UCI:cwmp/cwmp,acs/retry_min_wait_interval*/ -int get_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "acs", "retry_min_wait_interval", value); - return 0; -} - -int set_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", "65535")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp", "acs", "retry_min_wait_interval", value); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.CWMPRetryIntervalMultiplier!UCI:cwmp/cwmp,acs/retry_interval_multiplier*/ -int get_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "acs", "retry_interval_multiplier", value); - return 0; -} - -int set_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1000", "65535")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp", "acs", "retry_interval_multiplier", value); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.AliasBasedAddressing!UCI:cwmp/cwmp,cpe/amd_version*/ -int get_alias_based_addressing(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "cpe", "amd_version", value); - if ((*value)[0] == '\0'|| atoi(*value) <= AMD_4) - *value = "false"; - else - *value = "true"; - return 0; -} - -/*#Device.ManagementServer.InstanceMode!UCI:cwmp/cwmp,cpe/instance_mode*/ -int get_instance_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp", "cpe", "instance_mode", value); - return 0; -} - -int set_instance_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, InstanceMode, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp", "cpe", "instance_mode", value); - cwmp_set_end_session(END_SESSION_RELOAD); - return 0; - } - return 0; -} - -/* - * STUN parameters - */ -/*#Device.ManagementServer.UDPConnectionRequestAddress!UCI:cwmp_stun/stun,stun/crudp_address*/ -int get_upd_cr_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_varstate_string("cwmp_stun", "stun", "crudp_address", value); - return 0; -} - -int get_stun_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *path = "/etc/rc.d/*icwmp_stund"; - if (check_file(path)) - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_stun_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - if(b) { - DMCMD("/etc/rc.common", 2, "/etc/init.d/icwmp_stund", "enable"); - DMCMD("/etc/rc.common", 2, "/etc/init.d/icwmp_stund", "start"); - } - else { - DMCMD("/etc/rc.common", 2, "/etc/init.d/icwmp_stund", "disable"); - DMCMD("/etc/rc.common", 2, "/etc/init.d/icwmp_stund", "stop"); - } - return 0; - } - return 0; -} - -/*#Device.ManagementServer.STUNServerAddress!UCI:cwmp_stun/stun,stun/server_address*/ -int get_stun_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp_stun", "stun", "server_address", value); - return 0; -} - -int set_stun_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp_stun", "stun", "server_address", value); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.STUNServerPort!UCI:cwmp_stun/stun,stun/server_port*/ -int get_stun_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp_stun", "stun", "server_port", value); - return 0; -} - -int set_stun_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "0", "65535")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp_stun", "stun", "server_port", value); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.STUNUsername!UCI:cwmp_stun/stun,stun/username*/ -int get_stun_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp_stun", "stun", "username", value); - return 0; -} - -int set_stun_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp_stun", "stun", "username", value); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.STUNPassword!UCI:cwmp_stun/stun,stun/password*/ -int get_stun_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ""; - return 0; -} - -int set_stun_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp_stun", "stun", "password", value); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.STUNMaximumKeepAlivePeriod!UCI:cwmp_stun/stun,stun/max_keepalive*/ -int get_stun_maximum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp_stun", "stun", "max_keepalive", value); - return 0; -} - -int set_stun_maximum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp_stun", "stun", "max_keepalive", value); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.STUNMinimumKeepAlivePeriod!UCI:cwmp_stun/stun,stun/min_keepalive*/ -int get_stun_minimum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp_stun", "stun", "min_keepalive", value); - return 0; -} - -int set_stun_minimum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp_stun", "stun", "min_keepalive", value); - return 0; - } - return 0; -} - -/*#Device.ManagementServer.NATDetected!UCI:cwmp_stun/stun,stun/nat_detected*/ -int get_nat_detected(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *path = "/etc/rc.d/*icwmp_stund"; - char *v; - - if (check_file(path)) { //stun is enabled - dmuci_get_varstate_string("cwmp_stun", "stun", "nat_detected", &v); - *value = (*v == '1') ? "true" : "false"; - } else - *value = "false"; - return 0; -} - -/* - * XMPP parameters - */ -/*#Device.ManagementServer.ConnReqAllowedJabberIDs!UCI:cwmp_xmpp/cwmp,xmpp/allowed_jid*/ -int get_management_server_conn_rep_allowed_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("cwmp_xmpp", "xmpp", "allowed_jid", value); - return 0; -} - -int set_management_server_conn_rep_allowed_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, "32", NULL, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("cwmp_xmpp", "xmpp", "allowed_jid", value); - return 0; - } - return 0; -} - -int get_management_server_conn_req_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - char *username, *domain, *resource, *tmpPtr = NULL, *strResponse = NULL; - - uci_foreach_sections("cwmp_xmpp", "xmpp_connection", s) { - dmuci_get_value_by_section_string(s, "username", &username); - dmuci_get_value_by_section_string(s, "domain", &domain); - dmuci_get_value_by_section_string(s, "resource", &resource); - if(*username != '\0' || *domain != '\0' || *resource != '\0') { - if(!strResponse) - dmasprintf(&strResponse, "%s@%s/%s", username, domain, resource); - else { - tmpPtr = dmstrdup(strResponse); - dmfree(strResponse); - dmasprintf(&strResponse, "%s,%s@%s/%s", tmpPtr, username, domain, resource); - dmfree(tmpPtr); - } - } - } - *value = strResponse ? strResponse : ""; - return 0; -} - -int get_management_server_conn_req_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *id; - - dmuci_get_option_value_string("cwmp_xmpp", "xmpp", "id", &id); - if (strlen(id)) dmasprintf(value, "Device.XMPP.Connection.%s", id); - return 0; -} - -int set_management_server_conn_req_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *str, *connection_instance; - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if ((str = strstr(value, "Device.XMPP.Connection."))) { - value = dmstrdup(str + sizeof("Device.XMPP.Connection.") - 1); //MEM WILL BE FREED IN DMMEMCLEAN - } - uci_foreach_sections("cwmp_xmpp", "xmpp_connection", s) { - dmuci_get_value_by_section_string(s, "connection_instance", &connection_instance); - if(strcmp(value, connection_instance) == 0) { - dmuci_set_value("cwmp_xmpp", "xmpp", "id", value); - break; - } - } - return 0; - } - return 0; -} - -int get_management_server_supported_conn_req_methods(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "HTTP,XMPP,STUN"; - return 0; -} diff --git a/dmtree/tr181/managementserver.h b/dmtree/tr181/managementserver.h index 74eb12f2..082f252b 100644 --- a/dmtree/tr181/managementserver.h +++ b/dmtree/tr181/managementserver.h @@ -16,66 +16,4 @@ extern DMLEAF tManagementServerParams[]; -int get_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_empty(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_connection_request_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_connection_request_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_http_compression_supportted(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_http_compression(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_lwn_protocol_supported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_lwn_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_lwn_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_alias_based_addressing(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_instance_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_conn_rep_allowed_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_conn_req_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_conn_req_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_management_server_supported_conn_req_methods(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_upd_cr_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_upd_cr_address_notification_limit(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_stun_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_stun_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_stun_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_stun_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_stun_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_stun_maximum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_stun_minimum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nat_detected(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_passwd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_connection_request_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_connection_request_passwd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_http_compression(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_lwn_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_lwn_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_instance_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_conn_rep_allowed_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_management_server_conn_req_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int set_upd_cr_address_notification_limit(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_stun_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_stun_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_stun_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_stun_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_stun_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_stun_maximum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_stun_minimum_keepalive_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); #endif diff --git a/dmtree/tr181/nat.c b/dmtree/tr181/nat.c index 65316fe3..153f2312 100644 --- a/dmtree/tr181/nat.c +++ b/dmtree/tr181/nat.c @@ -13,6 +13,647 @@ #include "dmentry.h" #include "nat.h" + +/************************************************************* +* ADD DEL OBJ +**************************************************************/ +static int add_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *value, *v, *inst, name[16]; + struct uci_section *s = NULL, *dmmap_firewall = NULL; + + check_create_dmmap_package("dmmap_firewall"); + inst = get_last_instance_bbfdm("dmmap_firewall", "zone", "interface_setting_instance"); + snprintf(name, sizeof(name), "iface_set_%d", inst ? (atoi(inst)+1) : 1); + dmuci_add_section_and_rename("firewall", "zone", &s, &value); + dmuci_set_value_by_section(s, "input", "REJECT"); + dmuci_set_value_by_section(s, "output", "ACCEPT"); + dmuci_set_value_by_section(s, "forward", "REJECT"); + dmuci_set_value_by_section(s, "name", name); + + dmuci_add_section_bbfdm("dmmap_firewall", "zone", &dmmap_firewall, &v); + dmuci_set_value_by_section(dmmap_firewall, "section_name", section_name(s)); + *instance = update_instance_bbfdm(dmmap_firewall, inst, "interface_setting_instance"); + return 0; + +} + +static int delete_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct uci_section *s = NULL, *ss = NULL, *dmmap_firewall = NULL; + + switch (del_action) { + case DEL_INST: + get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_firewall); + if (dmmap_firewall) + dmuci_delete_by_section(dmmap_firewall, NULL, NULL); + dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("firewall", "zone", s) { + if (found != 0) { + get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name(ss), &dmmap_firewall); + if (dmmap_firewall) + dmuci_delete_by_section(dmmap_firewall, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name(ss), &dmmap_firewall); + if(dmmap_firewall) + dmuci_delete_by_section(dmmap_firewall, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + return 0; + } + return 0; +} + +static int add_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *value, *v, *inst, name[16]; + struct uci_section *s = NULL, *dmmap_firewall = NULL; + + check_create_dmmap_package("dmmap_firewall"); + inst = get_last_instance_bbfdm("dmmap_firewall", "redirect", "port_mapping_instance"); + snprintf(name, sizeof(name), "port_map_%d", inst ? (atoi(inst)+1) : 1); + dmuci_add_section_and_rename("firewall", "redirect", &s, &value); + dmuci_set_value_by_section(s, "name", name); + dmuci_set_value_by_section(s, "src", "wan"); + dmuci_set_value_by_section(s, "target", "DNAT"); + dmuci_set_value_by_section(s, "dest", "lan"); + + dmuci_add_section_bbfdm("dmmap_firewall", "redirect", &dmmap_firewall, &v); + dmuci_set_value_by_section(dmmap_firewall, "section_name", section_name(s)); + *instance = update_instance_bbfdm(dmmap_firewall, inst, "port_mapping_instance"); + return 0; + +} + +static int delete_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct uci_section *s = NULL, *ss = NULL, *dmmap_firewall = NULL; + + switch (del_action) { + case DEL_INST: + get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name((struct uci_section *)data), &dmmap_firewall); + if (dmmap_firewall) + dmuci_delete_by_section(dmmap_firewall, NULL, NULL); + dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("firewall", "redirect", s) { + if (found != 0) { + get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(ss), &dmmap_firewall); + if (dmmap_firewall) + dmuci_delete_by_section(dmmap_firewall, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(ss), &dmmap_firewall); + if (dmmap_firewall) + dmuci_delete_by_section(dmmap_firewall, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + return 0; + } + return 0; +} + +/************************************************************************** +* SET & GET VALUE +***************************************************************************/ +/*#Device.NAT.InterfaceSettingNumberOfEntries!UCI:firewall/zone/*/ +static int get_nat_interface_setting_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_foreach_sections("firewall", "zone", s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +/*#Device.NAT.PortMappingNumberOfEntries!UCI:firewall/redirect/*/ +static int get_nat_port_mapping_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + int cnt = 0; + + uci_foreach_sections("firewall", "redirect", s) { + cnt++; + } + dmasprintf(value, "%d", cnt); + return 0; +} + +/*#Device.NAT.InterfaceSetting.{i}.Enable!UCI:firewall/zone,@i-1/masq*/ +static int get_nat_interface_setting_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *val; + dmuci_get_value_by_section_string((struct uci_section *)data, "masq", &val); + *value = (*val == '1') ? "1" : "0"; + return 0; +} + +static int set_nat_interface_setting_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section((struct uci_section *)data, "masq", b ? "1" : "0"); + return 0; + } + return 0; +} + +/*#Device.NAT.InterfaceSetting.{i}.Status!UCI:firewall/zone,@i-1/masq*/ +static int get_nat_interface_setting_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *val; + dmuci_get_value_by_section_string((struct uci_section *)data, "masq", &val); + *value = (*val == '1') ? "Enabled" : "Disabled"; + return 0; +} + +static int get_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "interface_setting_alias", value); + return 0; +} + +static int set_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "interface_setting_alias", value); + return 0; + } + return 0; +} + +static int get_nat_interface_setting_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *v; + struct uci_element *e; + char *ifaceobj, buf[256] = ""; + + *value = ""; + dmuci_get_value_by_section_list((struct uci_section *)data, "network", &v); + if (v == NULL) + return 0; + uci_foreach_element(v, e) { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), e->name, &ifaceobj); // MEM WILL BE FREED IN DMMEMCLEAN + if (ifaceobj == NULL) + continue; + if (*buf != '\0') + strcat(buf, ","); + strcat(buf, ifaceobj); + } + *value = dmstrdup(buf); + return 0; +} + +static int set_nat_interface_setting_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *iface, *pch, *pchr, buf[256] = ""; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + strcpy(buf, value); + dmuci_set_value_by_section((struct uci_section *)data, "network", ""); + for(pch = strtok_r(buf, ",", &pchr); pch != NULL; pch = strtok_r(NULL, ",", &pchr)) { + adm_entry_get_linker_value(ctx, pch, &iface); + if (iface) { + dmuci_add_list_value_by_section((struct uci_section *)data, "network", iface); + dmfree(iface); + } + } + return 0; + } + return 0; +} + +/*#Device.NAT.PortMapping.{i}.Enable!UCI:firewall/redirect,@i-1/enabled*/ +static int get_nat_port_mapping_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *val; + dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &val); + *value = (*val == '1') ? "1" : "0"; + return 0; +} + +static int set_nat_port_mapping_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0"); + return 0; + } + return 0; +} + +/*#Device.NAT.PortMapping.{i}.Status!UCI:firewall/redirect,@i-1/enabled*/ +static int get_nat_port_mapping_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *val; + dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &val); + *value = (*val == '1') ? "Enabled" : "Disabled"; + return 0; +} + +static int get_nat_port_mapping_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name((struct uci_section *)data), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "port_mapping_alias", value); + return 0; +} + +static int set_nat_port_mapping_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name((struct uci_section *)data), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "port_mapping_alias", value); + return 0; + } + return 0; +} + +static int get_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + struct uci_list *v; + struct uci_element *e; + char *zone, *name, *ifaceobj, buf[256] = ""; + + dmuci_get_value_by_section_string((struct uci_section *)data, "src", &zone); + uci_foreach_sections("firewall", "zone", s) { + dmuci_get_value_by_section_string(s, "name", &name); + if (strcmp(zone, name) == 0) { + dmuci_get_value_by_section_list(s, "network", &v); + break; + } + } + if (v == NULL) + return 0; + uci_foreach_element(v, e) { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), e->name, &ifaceobj); // MEM WILL BE FREED IN DMMEMCLEAN + if (ifaceobj == NULL) + continue; + if (*buf != '\0') + strcat(buf, ","); + strcat(buf, ifaceobj); + } + *value = dmstrdup(buf); + return 0; +} + +static int set_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *iface, *network, *zone; + struct uci_section *s = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + adm_entry_get_linker_value(ctx, value, &iface); + if (iface[0] != '\0') { + uci_foreach_sections("firewall", "zone", s) { + dmuci_get_value_by_section_string(s, "network", &network); + if (is_strword_in_optionvalue(network, iface)) { + dmuci_get_value_by_section_string(s, "name", &zone); + dmuci_set_value_by_section((struct uci_section *)data, "src", zone); + break; + } + } + } + break; + } + return 0; +} + +static int get_nat_port_mapping_all_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_nat_port_mapping_all_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + //TODO + return 0; + } + return 0; +} + +static int get_nat_port_mapping_lease_duration(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + // CPE only supports static port forwards + //TODO + return 0; +} + +static int set_nat_port_mapping_lease_duration(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + // Nothing to set for static port forwards + //TODO + return 0; + } + return 0; +} + +/*#Device.NAT.PortMapping.{i}.RemoteHost!UCI:firewall/redirect,@i-1/src_dip*/ +static int get_nat_port_mapping_remote_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "src_dip", value); + return 0; +} + +static int set_nat_port_mapping_remote_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "src_dip", value); + return 0; + } + return 0; +} + +/*#Device.NAT.PortMapping.{i}.ExternalPort!UCI:firewall/redirect,@i-1/src_dport*/ +static int get_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *dport, *tmp; + dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &dport); + if (*dport == '\0') { + *value = "0"; + return 0; + } + tmp = strchr(dport, ':'); + if (tmp) + *tmp = '\0'; + *value = dport; + return 0; +} + +static int set_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *dport, buffer[64]; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "0", "65535")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &dport); + dport = strchr(dport, ':'); + if (dport == NULL) + snprintf(buffer, sizeof(buffer), "%s", value); + else + snprintf(buffer, sizeof(buffer), "%s%s", value, dport); + dmuci_set_value_by_section((struct uci_section *)data, "src_dport", buffer); + return 0; + } + return 0; +} + +/*#Device.NAT.PortMapping.{i}.ExternalPortEndRange!UCI:firewall/redirect,@i-1/src_dport*/ +static int get_nat_port_mapping_external_port_end_range(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *dport, *tmp; + dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &dport); + tmp = strchr(dport, ':'); + *value = (tmp) ? tmp+1 : "0"; + return 0; +} + +static int set_nat_port_mapping_external_port_end_range(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *dport, *tmp, buffer[64]; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "0", "65535")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &dport); + tmp = strchr(dport, ':'); + if (tmp) + *tmp = '\0'; + if (*value == '0') + snprintf(buffer, sizeof(buffer), "%s", dport); + else + snprintf(buffer, sizeof(buffer), "%s:%s", dport, value); + dmuci_set_value_by_section((struct uci_section *)data, "src_dport", buffer); + return 0; + } + return 0; +} + +/*#Device.NAT.PortMapping.{i}.InternalPort!UCI:firewall/redirect,@i-1/dest_port*/ +static int get_nat_port_mapping_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", value); + return 0; +} + +static int set_nat_port_mapping_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "0", "65535")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "dest_port", value); + return 0; + } + return 0; +} + +/*#Device.NAT.PortMapping.{i}.Protocol!UCI:firewall/redirect,@i-1/proto*/ +static int get_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *proto; + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); + if (strcmp(proto, "tcp") == 0) + *value = "TCP"; + else if (strcmp(proto, "udp") == 0) + *value = "UDP"; + else + *value = "TCP/UDP"; + return 0; +} + +static int set_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NATProtocol, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (strcasecmp("TCP", value) == 0) + dmuci_set_value_by_section((struct uci_section *)data, "proto", "tcp"); + else if (strcasecmp("UDP", value) == 0) + dmuci_set_value_by_section((struct uci_section *)data, "proto", "udp"); + else + dmuci_set_value_by_section((struct uci_section *)data, "proto", "tcpudp"); + return 0; + } + return 0; +} + +/*#Device.NAT.PortMapping.{i}.InternalClient!UCI:firewall/redirect,@i-1/dest_ip*/ +static int get_nat_port_mapping_internal_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", value); + return 0; +} + +static int set_nat_port_mapping_internal_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", value); + return 0; + } + return 0; +} + +/*#Device.NAT.PortMapping.{i}.Description!UCI:firewall/redirect,@i-1/name*/ +static int get_nat_port_mapping_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); + return 0; +} + +static int set_nat_port_mapping_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "name", value); + return 0; + } + return 0; +} + +/************************************************************* +* ENTRY METHOD +**************************************************************/ +/*#Device.NAT.InterfaceSetting.{i}.!UCI:firewall/zone/dmmap_firewall*/ +static int browseInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *nati, *nati_last = NULL; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("firewall", "zone", "dmmap_firewall", &dup_list); + list_for_each_entry(p, &dup_list, list) { + nati = handle_update_instance(1, dmctx, &nati_last, update_instance_alias, 3, p->dmmap_section, "interface_setting_instance", "interface_setting_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, nati) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +/*#Device.NAT.PortMapping.{i}.!UCI:firewall/redirect/dmmap_firewall*/ +static int browsePortMappingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *natp, *natp_last = NULL, *target; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("firewall", "redirect", "dmmap_firewall", &dup_list); + list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "target", &target); + if (*target != '\0' && strcmp(target, "DNAT") != 0) + continue; + natp = handle_update_instance(1, dmctx, &natp_last, update_instance_alias, 3, p->dmmap_section, "port_mapping_instance", "port_mapping_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, natp) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + /* *** Device.NAT. *** */ DMOBJ tNATObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -56,643 +697,3 @@ DMLEAF tNATPortMappingParams[] = { {"Description", &DMWRITE, DMT_STRING, get_nat_port_mapping_description, set_nat_port_mapping_description, NULL, NULL, BBFDM_BOTH}, {0} }; - -/************************************************************* -* ADD DEL OBJ -**************************************************************/ -int add_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *value, *v, *inst, name[16]; - struct uci_section *s = NULL, *dmmap_firewall = NULL; - - check_create_dmmap_package("dmmap_firewall"); - inst = get_last_instance_bbfdm("dmmap_firewall", "zone", "interface_setting_instance"); - snprintf(name, sizeof(name), "iface_set_%d", inst ? (atoi(inst)+1) : 1); - dmuci_add_section_and_rename("firewall", "zone", &s, &value); - dmuci_set_value_by_section(s, "input", "REJECT"); - dmuci_set_value_by_section(s, "output", "ACCEPT"); - dmuci_set_value_by_section(s, "forward", "REJECT"); - dmuci_set_value_by_section(s, "name", name); - - dmuci_add_section_bbfdm("dmmap_firewall", "zone", &dmmap_firewall, &v); - dmuci_set_value_by_section(dmmap_firewall, "section_name", section_name(s)); - *instance = update_instance_bbfdm(dmmap_firewall, inst, "interface_setting_instance"); - return 0; - -} - -int delete_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - int found = 0; - struct uci_section *s = NULL, *ss = NULL, *dmmap_firewall = NULL; - - switch (del_action) { - case DEL_INST: - get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_firewall); - if (dmmap_firewall) - dmuci_delete_by_section(dmmap_firewall, NULL, NULL); - dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); - break; - case DEL_ALL: - uci_foreach_sections("firewall", "zone", s) { - if (found != 0) { - get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name(ss), &dmmap_firewall); - if (dmmap_firewall) - dmuci_delete_by_section(dmmap_firewall, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name(ss), &dmmap_firewall); - if(dmmap_firewall) - dmuci_delete_by_section(dmmap_firewall, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - return 0; - } - return 0; -} - -int add_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *value, *v, *inst, name[16]; - struct uci_section *s = NULL, *dmmap_firewall = NULL; - - check_create_dmmap_package("dmmap_firewall"); - inst = get_last_instance_bbfdm("dmmap_firewall", "redirect", "port_mapping_instance"); - snprintf(name, sizeof(name), "port_map_%d", inst ? (atoi(inst)+1) : 1); - dmuci_add_section_and_rename("firewall", "redirect", &s, &value); - dmuci_set_value_by_section(s, "name", name); - dmuci_set_value_by_section(s, "src", "wan"); - dmuci_set_value_by_section(s, "target", "DNAT"); - dmuci_set_value_by_section(s, "dest", "lan"); - - dmuci_add_section_bbfdm("dmmap_firewall", "redirect", &dmmap_firewall, &v); - dmuci_set_value_by_section(dmmap_firewall, "section_name", section_name(s)); - *instance = update_instance_bbfdm(dmmap_firewall, inst, "port_mapping_instance"); - return 0; - -} - -int delete_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - int found = 0; - struct uci_section *s = NULL, *ss = NULL, *dmmap_firewall = NULL; - - switch (del_action) { - case DEL_INST: - get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name((struct uci_section *)data), &dmmap_firewall); - if (dmmap_firewall) - dmuci_delete_by_section(dmmap_firewall, NULL, NULL); - dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); - break; - case DEL_ALL: - uci_foreach_sections("firewall", "redirect", s) { - if (found != 0) { - get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(ss), &dmmap_firewall); - if (dmmap_firewall) - dmuci_delete_by_section(dmmap_firewall, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(ss), &dmmap_firewall); - if (dmmap_firewall) - dmuci_delete_by_section(dmmap_firewall, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - return 0; - } - return 0; -} - -/************************************************************************** -* SET & GET VALUE -***************************************************************************/ -/*#Device.NAT.InterfaceSettingNumberOfEntries!UCI:firewall/zone/*/ -int get_nat_interface_setting_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_foreach_sections("firewall", "zone", s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -/*#Device.NAT.PortMappingNumberOfEntries!UCI:firewall/redirect/*/ -int get_nat_port_mapping_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - int cnt = 0; - - uci_foreach_sections("firewall", "redirect", s) { - cnt++; - } - dmasprintf(value, "%d", cnt); - return 0; -} - -/*#Device.NAT.InterfaceSetting.{i}.Enable!UCI:firewall/zone,@i-1/masq*/ -int get_nat_interface_setting_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *val; - dmuci_get_value_by_section_string((struct uci_section *)data, "masq", &val); - *value = (*val == '1') ? "1" : "0"; - return 0; -} - -int set_nat_interface_setting_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "masq", b ? "1" : "0"); - return 0; - } - return 0; -} - -/*#Device.NAT.InterfaceSetting.{i}.Status!UCI:firewall/zone,@i-1/masq*/ -int get_nat_interface_setting_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *val; - dmuci_get_value_by_section_string((struct uci_section *)data, "masq", &val); - *value = (*val == '1') ? "Enabled" : "Disabled"; - return 0; -} - -int get_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "interface_setting_alias", value); - return 0; -} - -int set_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "interface_setting_alias", value); - return 0; - } - return 0; -} - -int get_nat_interface_setting_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *v; - struct uci_element *e; - char *ifaceobj, buf[256] = ""; - - *value = ""; - dmuci_get_value_by_section_list((struct uci_section *)data, "network", &v); - if (v == NULL) - return 0; - uci_foreach_element(v, e) { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), e->name, &ifaceobj); // MEM WILL BE FREED IN DMMEMCLEAN - if (ifaceobj == NULL) - continue; - if (*buf != '\0') - strcat(buf, ","); - strcat(buf, ifaceobj); - } - *value = dmstrdup(buf); - return 0; -} - -int set_nat_interface_setting_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *iface, *pch, *pchr, buf[256] = ""; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - strcpy(buf, value); - dmuci_set_value_by_section((struct uci_section *)data, "network", ""); - for(pch = strtok_r(buf, ",", &pchr); pch != NULL; pch = strtok_r(NULL, ",", &pchr)) { - adm_entry_get_linker_value(ctx, pch, &iface); - if (iface) { - dmuci_add_list_value_by_section((struct uci_section *)data, "network", iface); - dmfree(iface); - } - } - return 0; - } - return 0; -} - -/*#Device.NAT.PortMapping.{i}.Enable!UCI:firewall/redirect,@i-1/enabled*/ -int get_nat_port_mapping_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *val; - dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &val); - *value = (*val == '1') ? "1" : "0"; - return 0; -} - -int set_nat_port_mapping_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0"); - return 0; - } - return 0; -} - -/*#Device.NAT.PortMapping.{i}.Status!UCI:firewall/redirect,@i-1/enabled*/ -int get_nat_port_mapping_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *val; - dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &val); - *value = (*val == '1') ? "Enabled" : "Disabled"; - return 0; -} - -int get_nat_port_mapping_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name((struct uci_section *)data), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "port_mapping_alias", value); - return 0; -} - -int set_nat_port_mapping_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name((struct uci_section *)data), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "port_mapping_alias", value); - return 0; - } - return 0; -} - -int get_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s = NULL; - struct uci_list *v; - struct uci_element *e; - char *zone, *name, *ifaceobj, buf[256] = ""; - - dmuci_get_value_by_section_string((struct uci_section *)data, "src", &zone); - uci_foreach_sections("firewall", "zone", s) { - dmuci_get_value_by_section_string(s, "name", &name); - if (strcmp(zone, name) == 0) { - dmuci_get_value_by_section_list(s, "network", &v); - break; - } - } - if (v == NULL) - return 0; - uci_foreach_element(v, e) { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), e->name, &ifaceobj); // MEM WILL BE FREED IN DMMEMCLEAN - if (ifaceobj == NULL) - continue; - if (*buf != '\0') - strcat(buf, ","); - strcat(buf, ifaceobj); - } - *value = dmstrdup(buf); - return 0; -} - -int set_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *iface, *network, *zone; - struct uci_section *s = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - adm_entry_get_linker_value(ctx, value, &iface); - if (iface[0] != '\0') { - uci_foreach_sections("firewall", "zone", s) { - dmuci_get_value_by_section_string(s, "network", &network); - if (is_strword_in_optionvalue(network, iface)) { - dmuci_get_value_by_section_string(s, "name", &zone); - dmuci_set_value_by_section((struct uci_section *)data, "src", zone); - break; - } - } - } - break; - } - return 0; -} - -int get_nat_port_mapping_all_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_nat_port_mapping_all_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - //TODO - return 0; - } - return 0; -} - -int get_nat_port_mapping_lease_duration(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - // CPE only supports static port forwards - //TODO - return 0; -} - -int set_nat_port_mapping_lease_duration(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - // Nothing to set for static port forwards - //TODO - return 0; - } - return 0; -} - -/*#Device.NAT.PortMapping.{i}.RemoteHost!UCI:firewall/redirect,@i-1/src_dip*/ -int get_nat_port_mapping_remote_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "src_dip", value); - return 0; -} - -int set_nat_port_mapping_remote_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "src_dip", value); - return 0; - } - return 0; -} - -/*#Device.NAT.PortMapping.{i}.ExternalPort!UCI:firewall/redirect,@i-1/src_dport*/ -int get_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *dport, *tmp; - dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &dport); - if (*dport == '\0') { - *value = "0"; - return 0; - } - tmp = strchr(dport, ':'); - if (tmp) - *tmp = '\0'; - *value = dport; - return 0; -} - -int set_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *dport, buffer[64]; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "0", "65535")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &dport); - dport = strchr(dport, ':'); - if (dport == NULL) - snprintf(buffer, sizeof(buffer), "%s", value); - else - snprintf(buffer, sizeof(buffer), "%s%s", value, dport); - dmuci_set_value_by_section((struct uci_section *)data, "src_dport", buffer); - return 0; - } - return 0; -} - -/*#Device.NAT.PortMapping.{i}.ExternalPortEndRange!UCI:firewall/redirect,@i-1/src_dport*/ -int get_nat_port_mapping_external_port_end_range(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *dport, *tmp; - dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &dport); - tmp = strchr(dport, ':'); - *value = (tmp) ? tmp+1 : "0"; - return 0; -} - -int set_nat_port_mapping_external_port_end_range(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *dport, *tmp, buffer[64]; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "0", "65535")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &dport); - tmp = strchr(dport, ':'); - if (tmp) - *tmp = '\0'; - if (*value == '0') - snprintf(buffer, sizeof(buffer), "%s", dport); - else - snprintf(buffer, sizeof(buffer), "%s:%s", dport, value); - dmuci_set_value_by_section((struct uci_section *)data, "src_dport", buffer); - return 0; - } - return 0; -} - -/*#Device.NAT.PortMapping.{i}.InternalPort!UCI:firewall/redirect,@i-1/dest_port*/ -int get_nat_port_mapping_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", value); - return 0; -} - -int set_nat_port_mapping_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "0", "65535")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "dest_port", value); - return 0; - } - return 0; -} - -/*#Device.NAT.PortMapping.{i}.Protocol!UCI:firewall/redirect,@i-1/proto*/ -int get_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *proto; - dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); - if (strcmp(proto, "tcp") == 0) - *value = "TCP"; - else if (strcmp(proto, "udp") == 0) - *value = "UDP"; - else - *value = "TCP/UDP"; - return 0; -} - -int set_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NATProtocol, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (strcasecmp("TCP", value) == 0) - dmuci_set_value_by_section((struct uci_section *)data, "proto", "tcp"); - else if (strcasecmp("UDP", value) == 0) - dmuci_set_value_by_section((struct uci_section *)data, "proto", "udp"); - else - dmuci_set_value_by_section((struct uci_section *)data, "proto", "tcpudp"); - return 0; - } - return 0; -} - -/*#Device.NAT.PortMapping.{i}.InternalClient!UCI:firewall/redirect,@i-1/dest_ip*/ -int get_nat_port_mapping_internal_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", value); - return 0; -} - -int set_nat_port_mapping_internal_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", value); - return 0; - } - return 0; -} - -/*#Device.NAT.PortMapping.{i}.Description!UCI:firewall/redirect,@i-1/name*/ -int get_nat_port_mapping_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); - return 0; -} - -int set_nat_port_mapping_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "name", value); - return 0; - } - return 0; -} - -/************************************************************* -* ENTRY METHOD -**************************************************************/ -/*#Device.NAT.InterfaceSetting.{i}.!UCI:firewall/zone/dmmap_firewall*/ -int browseInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *nati, *nati_last = NULL; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("firewall", "zone", "dmmap_firewall", &dup_list); - list_for_each_entry(p, &dup_list, list) { - nati = handle_update_instance(1, dmctx, &nati_last, update_instance_alias, 3, p->dmmap_section, "interface_setting_instance", "interface_setting_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, nati) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -/*#Device.NAT.PortMapping.{i}.!UCI:firewall/redirect/dmmap_firewall*/ -int browsePortMappingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *natp, *natp_last = NULL, *target; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("firewall", "redirect", "dmmap_firewall", &dup_list); - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "target", &target); - if (*target != '\0' && strcmp(target, "DNAT") != 0) - continue; - natp = handle_update_instance(1, dmctx, &natp_last, update_instance_alias, 3, p->dmmap_section, "port_mapping_instance", "port_mapping_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, natp) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} diff --git a/dmtree/tr181/nat.h b/dmtree/tr181/nat.h index 1d81a5ca..20bb4ba6 100644 --- a/dmtree/tr181/nat.h +++ b/dmtree/tr181/nat.h @@ -20,49 +20,4 @@ extern DMLEAF tNATParams[]; extern DMLEAF tNATInterfaceSettingParams[]; extern DMLEAF tNATPortMappingParams[]; -int browseInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browsePortMappingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int add_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delete_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int add_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delete_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_nat_interface_setting_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nat_port_mapping_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_nat_interface_setting_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_interface_setting_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_interface_setting_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_interface_setting_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_interface_setting_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_nat_port_mapping_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_port_mapping_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_nat_port_mapping_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_port_mapping_all_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_all_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_port_mapping_lease_duration(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_lease_duration(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_port_mapping_remote_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_remote_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_port_mapping_external_port_end_range(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_external_port_end_range(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_port_mapping_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_port_mapping_internal_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_internal_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_nat_port_mapping_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_nat_port_mapping_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/ppp.c b/dmtree/tr181/ppp.c index 2ad5ca4b..b4f456c2 100644 --- a/dmtree/tr181/ppp.c +++ b/dmtree/tr181/ppp.c @@ -12,6 +12,516 @@ #include "dmentry.h" #include "ppp.h" + +/************************************************************* +* GET SET ALIAS +**************************************************************/ +static int get_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "ppp_int_alias", value); + return 0; +} + +static int set_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "ppp_int_alias", value); + return 0; + } + return 0; +} + +/************************************************************************** +* GET & SET PARAMETERS +***************************************************************************/ +/*#Device.PPP.Interface.{i}.Enable!UBUS:network.interface/status/interface,@Name/up*/ +static int get_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res); + DM_ASSERT(res, *value = "false"); + *value = dmjson_get_value(res, 1, "up"); + return 0; +} + +static int set_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + char *ubus_object; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmastrcat(&ubus_object, "network.interface.", section_name(((struct uci_section *)data))); + dmubus_call_set(ubus_object, b ? "up" : "down", UBUS_ARGS{}, 0); + dmfree(ubus_object); + break; + } + return 0; +} + +/*#Device.PPP.Interface.{i}.Status!UBUS:network.interface/status/interface,@Name/up*/ +static int get_PPPInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + char *status; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res); + DM_ASSERT(res, *value = "Down"); + status = dmjson_get_value(res, 1, "up"); + if (strcmp(status, "true") == 0) + *value= "Up"; + else + *value= "Down"; + return 0; +} + +/*#Device.PPP.Interface.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ +static int get_PPPInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "uptime"); + return 0; +} + +static int get_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "false"; + return 0; +} + +static int set_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + char *ubus_object; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + if (b) { + dmastrcat(&ubus_object, "network.interface.", section_name(((struct uci_section *)data))); + dmubus_call_set(ubus_object, "down", UBUS_ARGS{}, 0); + dmubus_call_set(ubus_object, "up", UBUS_ARGS{}, 0); + dmfree(ubus_object); + } + break; + } + return 0; +} + +static int get_ppp_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmstrdup(section_name(((struct uci_section *)data))); + return 0; +} + +/*#Device.PPP.Interface.{i}.ConnectionStatus!UBUS:network.interface/status/interface,@Name/up*/ +static int get_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *status = NULL, *uptime = NULL, *pending = NULL; + json_object *res = NULL, *jobj = NULL; + bool bstatus = false, bpend = false; + + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res); + DM_ASSERT(res, *value = ""); + jobj = dmjson_get_obj(res, 1, "up"); + if (jobj) { + status = dmjson_get_value(res, 1, "up"); + string_to_bool(status, &bstatus); + if (bstatus) { + uptime = dmjson_get_value(res, 1, "uptime"); + pending = dmjson_get_value(res, 1, "pending"); + string_to_bool(pending, &bpend); + } + } + if (uptime && atoi(uptime) > 0) + *value = "Connected"; + else if (pending && bpend) + *value = "Pending Disconnect"; + else + *value = "Disconnected"; + return 0; +} + +/*#Device.PPP.Interface.{i}.Username!UCI:network/interface,@i-1/username*/ +static int get_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct uci_section *)data), "username", value); + return 0; +} + +static int set_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct uci_section *)data), "username", value); + return 0; + } + return 0; +} + +/*#Device.PPP.Interface.{i}.Password!UCI:network/interface,@i-1/password*/ +static int set_ppp_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct uci_section *)data), "password", value); + return 0; + } + return 0; +} + +static int ppp_read_sysfs(struct uci_section *sect, const char *name, char **value) +{ + char *proto; + int rc = 0; + + dmuci_get_value_by_section_string(sect, "proto", &proto); + + if (!strcmp(proto, "pppoe")) { + char *ifname; + + dmuci_get_value_by_section_string(sect, "ifname", &ifname); + rc = get_net_device_sysfs(ifname, name, value); + } + return rc; +} + +/*#Device.PPP.Interface.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/ +static int get_ppp_eth_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ppp_read_sysfs(data, "statistics/rx_bytes", value); +} + +/*#Device.PPP.Interface.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/ +static int get_ppp_eth_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ppp_read_sysfs(data, "statistics/tx_bytes", value); +} + +/*#Device.PPP.Interface.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/ +static int get_ppp_eth_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ppp_read_sysfs(data, "statistics/rx_packets", value); +} + +/*#Device.PPP.Interface.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/ +static int get_ppp_eth_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ppp_read_sysfs(data, "statistics/tx_packets", value); +} + +/*#Device.PPP.Interface.{i}.Stats.ErrorsSent!UBUS:network.device/status/name,@Name/statistics.tx_errors*/ +static int get_PPPInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ppp_read_sysfs(data, "statistics/tx_errors", value); +} + +/*#Device.PPP.Interface.{i}.Stats.ErrorsReceived!UBUS:network.device/status/name,@Name/statistics.rx_errors*/ +static int get_PPPInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ppp_read_sysfs(data, "statistics/rx_errors", value); +} + +static int get_PPPInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_PPPInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.PPP.Interface.{i}.Stats.DiscardPacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_dropped*/ +static int get_PPPInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ppp_read_sysfs(data, "statistics/tx_dropped", value); +} + +/*#Device.PPP.Interface.{i}.Stats.DiscardPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_dropped*/ +static int get_PPPInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ppp_read_sysfs(data, "statistics/rx_dropped", value); +} + +static int get_PPPInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_PPPInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ppp_read_sysfs(data, "statistics/multicast", value); +} + +static int get_PPPInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_PPPInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_PPPInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker; + dmuci_get_value_by_section_string(((struct uci_section *)data), "ifname", &linker); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cATM%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPTM%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cSSID%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + *value = ""; + return 0; +} + +static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker, *newvalue = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (value[strlen(value)-1]!='.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else + adm_entry_get_linker_value(ctx, value, &linker); + if(linker) + dmuci_set_value_by_section(((struct uci_section *)data), "ifname", linker); + else + return FAULT_9005; + return 0; + } + return 0; +} + +static int get_PPP_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + char *proto; + int nbre= 0; + + uci_foreach_sections("network", "interface", s) { + dmuci_get_value_by_section_string(s, "proto", &proto); + if (!strstr(proto, "ppp")) + continue; + nbre++; + } + dmasprintf(value, "%d", nbre); + return 0; +} + +static int get_PPPInterfacePPPoE_SessionID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.PPP.Interface.{i}.PPPoE.ACName!UCI:network/interface,@i-1/ac*/ +static int get_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *proto; + dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto); + if (strcmp(proto, "pppoe") == 0) { + dmuci_get_value_by_section_string(((struct uci_section *)data), "ac", value); + return 0; + } + return 0; +} + +static int set_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *proto; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + + dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto); + if (strcmp(proto, "pppoe") != 0) + return FAULT_9001; + break; + case VALUESET: + dmuci_set_value_by_section(((struct uci_section *)data), "ac", value); + break; + } + return 0; +} + +/*#Device.PPP.Interface.{i}.PPPoE.ServiceName!UCI:network/interface,@i-1/service*/ +static int get_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *proto; + dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto); + if (strcmp(proto, "pppoe") == 0) { + dmuci_get_value_by_section_string(((struct uci_section *)data), "service", value); + return 0; + } + return 0; +} + +static int set_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *proto; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + + dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto); + if (strcmp(proto, "pppoe") != 0) + return FAULT_9001; + break; + case VALUESET: + dmuci_set_value_by_section(((struct uci_section *)data), "service", value); + break; + } + return 0; +} + +/************************************************************************** +* LINKER +***************************************************************************/ +static int get_linker_ppp_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + + if(((struct uci_section *)data)) { + dmasprintf(linker, "%s", section_name(((struct uci_section *)data))); + return 0; + } + *linker = ""; + return 0; +} + +/************************************************************* +* ADD DEL OBJ +**************************************************************/ +static int add_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char name[16] = {0}; + char *inst, *v; + struct uci_section *dmmap_ppp = NULL; + + check_create_dmmap_package("dmmap_network"); + inst = get_last_instance_lev2_bbfdm("network", "interface", "dmmap_network", "ppp_int_instance", "proto", "ppp"); + snprintf(name, sizeof(name), "ppp_%d", inst ? (atoi(inst)+1) : 1); + dmuci_set_value("network", name, "", "interface"); + dmuci_set_value("network", name, "proto", "ppp"); + dmuci_set_value("network", name, "username", name); + dmuci_set_value("network", name, "password", name); + dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_ppp, &v); + dmuci_set_value_by_section(dmmap_ppp, "section_name", name); + *instance = update_instance_bbfdm(dmmap_ppp, inst, "ppp_int_instance"); + return 0; +} + +static int delete_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct uci_section *ppp_s = NULL, *ss = NULL, *dmmap_section = NULL; + + switch (del_action) { + case DEL_INST: + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct uci_section *)data)), &dmmap_section); + if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(((struct uci_section *)data), NULL, NULL); + break; + case DEL_ALL: + uci_foreach_option_eq("network", "interface", "proto", "ppp", ppp_s) { + if (found != 0) { + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); + if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = ppp_s; + found++; + } + if (ss != NULL) { + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); + if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + break; + } + return 0; +} + +/************************************************************* +* ENTRY METHOD +**************************************************************/ +/*#Device.PPP.Interface.{i}.!UCI:network/interface/dmmap_network*/ +static int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *ppp_int = NULL, *ppp_int_last = NULL, *proto; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("network", "interface", "dmmap_network", &dup_list); + list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "proto", &proto); + if (!strstr(proto, "ppp")) + continue; + ppp_int = handle_update_instance(1, dmctx, &ppp_int_last, update_instance_alias, 3, p->dmmap_section, "ppp_int_instance", "ppp_int_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, ppp_int) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + /* *** Device.PPP. *** */ DMOBJ tPPPObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -77,512 +587,3 @@ DMLEAF tPPPInterfaceStatsParams[] = { //{"UnknownProtoPacketsReceived", &DMREAD, DMT_UNINT, get_PPPInterfaceStats_UnknownProtoPacketsReceived, NULL, NULL, NULL, BBFDM_BOTH}, {0} }; - -/************************************************************* -* GET SET ALIAS -**************************************************************/ -int get_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "ppp_int_alias", value); - return 0; -} - -int set_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "ppp_int_alias", value); - return 0; - } - return 0; -} - -/************************************************************************** -* GET & SET PARAMETERS -***************************************************************************/ -/*#Device.PPP.Interface.{i}.Enable!UBUS:network.interface/status/interface,@Name/up*/ -int get_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res); - DM_ASSERT(res, *value = "false"); - *value = dmjson_get_value(res, 1, "up"); - return 0; -} - -int set_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - char *ubus_object; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmastrcat(&ubus_object, "network.interface.", section_name(((struct uci_section *)data))); - dmubus_call_set(ubus_object, b ? "up" : "down", UBUS_ARGS{}, 0); - dmfree(ubus_object); - break; - } - return 0; -} - -/*#Device.PPP.Interface.{i}.Status!UBUS:network.interface/status/interface,@Name/up*/ -int get_PPPInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - char *status; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res); - DM_ASSERT(res, *value = "Down"); - status = dmjson_get_value(res, 1, "up"); - if (strcmp(status, "true") == 0) - *value= "Up"; - else - *value= "Down"; - return 0; -} - -/*#Device.PPP.Interface.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/ -int get_PPPInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "uptime"); - return 0; -} - -int get_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "false"; - return 0; -} - -int set_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - char *ubus_object; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - if (b) { - dmastrcat(&ubus_object, "network.interface.", section_name(((struct uci_section *)data))); - dmubus_call_set(ubus_object, "down", UBUS_ARGS{}, 0); - dmubus_call_set(ubus_object, "up", UBUS_ARGS{}, 0); - dmfree(ubus_object); - } - break; - } - return 0; -} - -int get_ppp_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmstrdup(section_name(((struct uci_section *)data))); - return 0; -} - -/*#Device.PPP.Interface.{i}.ConnectionStatus!UBUS:network.interface/status/interface,@Name/up*/ -int get_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *status = NULL, *uptime = NULL, *pending = NULL; - json_object *res = NULL, *jobj = NULL; - bool bstatus = false, bpend = false; - - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res); - DM_ASSERT(res, *value = ""); - jobj = dmjson_get_obj(res, 1, "up"); - if (jobj) { - status = dmjson_get_value(res, 1, "up"); - string_to_bool(status, &bstatus); - if (bstatus) { - uptime = dmjson_get_value(res, 1, "uptime"); - pending = dmjson_get_value(res, 1, "pending"); - string_to_bool(pending, &bpend); - } - } - if (uptime && atoi(uptime) > 0) - *value = "Connected"; - else if (pending && bpend) - *value = "Pending Disconnect"; - else - *value = "Disconnected"; - return 0; -} - -/*#Device.PPP.Interface.{i}.Username!UCI:network/interface,@i-1/username*/ -int get_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct uci_section *)data), "username", value); - return 0; -} - -int set_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section(((struct uci_section *)data), "username", value); - return 0; - } - return 0; -} - -/*#Device.PPP.Interface.{i}.Password!UCI:network/interface,@i-1/password*/ -int set_ppp_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section(((struct uci_section *)data), "password", value); - return 0; - } - return 0; -} - -static int ppp_read_sysfs(struct uci_section *sect, const char *name, char **value) -{ - char *proto; - int rc = 0; - - dmuci_get_value_by_section_string(sect, "proto", &proto); - - if (!strcmp(proto, "pppoe")) { - char *ifname; - - dmuci_get_value_by_section_string(sect, "ifname", &ifname); - rc = get_net_device_sysfs(ifname, name, value); - } - return rc; -} - -/*#Device.PPP.Interface.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/ -int get_ppp_eth_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ppp_read_sysfs(data, "statistics/rx_bytes", value); -} - -/*#Device.PPP.Interface.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/ -int get_ppp_eth_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ppp_read_sysfs(data, "statistics/tx_bytes", value); -} - -/*#Device.PPP.Interface.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/ -int get_ppp_eth_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ppp_read_sysfs(data, "statistics/rx_packets", value); -} - -/*#Device.PPP.Interface.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/ -int get_ppp_eth_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ppp_read_sysfs(data, "statistics/tx_packets", value); -} - -/*#Device.PPP.Interface.{i}.Stats.ErrorsSent!UBUS:network.device/status/name,@Name/statistics.tx_errors*/ -int get_PPPInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ppp_read_sysfs(data, "statistics/tx_errors", value); -} - -/*#Device.PPP.Interface.{i}.Stats.ErrorsReceived!UBUS:network.device/status/name,@Name/statistics.rx_errors*/ -int get_PPPInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ppp_read_sysfs(data, "statistics/rx_errors", value); -} - -int get_PPPInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_PPPInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.PPP.Interface.{i}.Stats.DiscardPacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_dropped*/ -int get_PPPInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ppp_read_sysfs(data, "statistics/tx_dropped", value); -} - -/*#Device.PPP.Interface.{i}.Stats.DiscardPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_dropped*/ -int get_PPPInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ppp_read_sysfs(data, "statistics/rx_dropped", value); -} - -int get_PPPInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_PPPInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ppp_read_sysfs(data, "statistics/multicast", value); -} - -int get_PPPInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_PPPInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_PPPInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *linker; - dmuci_get_value_by_section_string(((struct uci_section *)data), "ifname", &linker); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cATM%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cPTM%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cSSID%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - *value = ""; - return 0; -} - -int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *linker, *newvalue = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (value[strlen(value)-1]!='.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); - if(linker) - dmuci_set_value_by_section(((struct uci_section *)data), "ifname", linker); - else - return FAULT_9005; - return 0; - } - return 0; -} - -int get_PPP_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - char *proto; - int nbre= 0; - - uci_foreach_sections("network", "interface", s) { - dmuci_get_value_by_section_string(s, "proto", &proto); - if (!strstr(proto, "ppp")) - continue; - nbre++; - } - dmasprintf(value, "%d", nbre); - return 0; -} - -int get_PPPInterfacePPPoE_SessionID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.PPP.Interface.{i}.PPPoE.ACName!UCI:network/interface,@i-1/ac*/ -int get_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *proto; - dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto); - if (strcmp(proto, "pppoe") == 0) { - dmuci_get_value_by_section_string(((struct uci_section *)data), "ac", value); - return 0; - } - return 0; -} - -int set_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *proto; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - - dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto); - if (strcmp(proto, "pppoe") != 0) - return FAULT_9001; - break; - case VALUESET: - dmuci_set_value_by_section(((struct uci_section *)data), "ac", value); - break; - } - return 0; -} - -/*#Device.PPP.Interface.{i}.PPPoE.ServiceName!UCI:network/interface,@i-1/service*/ -int get_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *proto; - dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto); - if (strcmp(proto, "pppoe") == 0) { - dmuci_get_value_by_section_string(((struct uci_section *)data), "service", value); - return 0; - } - return 0; -} - -int set_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *proto; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - - dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto); - if (strcmp(proto, "pppoe") != 0) - return FAULT_9001; - break; - case VALUESET: - dmuci_set_value_by_section(((struct uci_section *)data), "service", value); - break; - } - return 0; -} - -/************************************************************************** -* LINKER -***************************************************************************/ -int get_linker_ppp_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - - if(((struct uci_section *)data)) { - dmasprintf(linker, "%s", section_name(((struct uci_section *)data))); - return 0; - } - *linker = ""; - return 0; -} - -/************************************************************* -* ADD DEL OBJ -**************************************************************/ -int add_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char name[16] = {0}; - char *inst, *v; - struct uci_section *dmmap_ppp = NULL; - - check_create_dmmap_package("dmmap_network"); - inst = get_last_instance_lev2_bbfdm("network", "interface", "dmmap_network", "ppp_int_instance", "proto", "ppp"); - snprintf(name, sizeof(name), "ppp_%d", inst ? (atoi(inst)+1) : 1); - dmuci_set_value("network", name, "", "interface"); - dmuci_set_value("network", name, "proto", "ppp"); - dmuci_set_value("network", name, "username", name); - dmuci_set_value("network", name, "password", name); - dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_ppp, &v); - dmuci_set_value_by_section(dmmap_ppp, "section_name", name); - *instance = update_instance_bbfdm(dmmap_ppp, inst, "ppp_int_instance"); - return 0; -} - -int delete_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - int found = 0; - struct uci_section *ppp_s = NULL, *ss = NULL, *dmmap_section = NULL; - - switch (del_action) { - case DEL_INST: - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct uci_section *)data)), &dmmap_section); - if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(((struct uci_section *)data), NULL, NULL); - break; - case DEL_ALL: - uci_foreach_option_eq("network", "interface", "proto", "ppp", ppp_s) { - if (found != 0) { - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); - if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = ppp_s; - found++; - } - if (ss != NULL) { - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section); - if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - break; - } - return 0; -} - -/************************************************************* -* ENTRY METHOD -**************************************************************/ -/*#Device.PPP.Interface.{i}.!UCI:network/interface/dmmap_network*/ -int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *ppp_int = NULL, *ppp_int_last = NULL, *proto; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("network", "interface", "dmmap_network", &dup_list); - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "proto", &proto); - if (!strstr(proto, "ppp")) - continue; - ppp_int = handle_update_instance(1, dmctx, &ppp_int_last, update_instance_alias, 3, p->dmmap_section, "ppp_int_instance", "ppp_int_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, ppp_int) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} diff --git a/dmtree/tr181/ppp.h b/dmtree/tr181/ppp.h index 40e57cdb..eb2bd3b0 100644 --- a/dmtree/tr181/ppp.h +++ b/dmtree/tr181/ppp.h @@ -21,50 +21,4 @@ extern DMLEAF tPPPInterfaceParams[]; extern DMLEAF tPPPInterfacePPPoEParams[]; extern DMLEAF tPPPInterfaceStatsParams[]; -int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int get_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ppp_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ppp_eth_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ppp_eth_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ppp_eth_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ppp_eth_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_ppp_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_linker_ppp_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); -int get_PPP_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int add_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delete_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_PPPInterfacePPPoE_SessionID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/ptm.c b/dmtree/tr181/ptm.c index 815db40a..d8e9bf69 100644 --- a/dmtree/tr181/ptm.c +++ b/dmtree/tr181/ptm.c @@ -12,44 +12,17 @@ #include "dmentry.h" #include "ptm.h" -/* *** Device.PTM. *** */ -DMOBJ tPTMObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Link", &DMWRITE, add_ptm_link, delete_ptm_link, NULL, browsePtmLinkInst, NULL, NULL, NULL, tPTMLinkObj, tPTMLinkParams, get_ptm_linker, BBFDM_BOTH}, -{0} +struct ptm_args +{ + struct uci_section *ptm_sec; + char *ifname; }; -/* *** Device.PTM.Link.{i}. *** */ -DMOBJ tPTMLinkObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tPTMLinkStatsParams, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF tPTMLinkParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Alias", &DMWRITE, DMT_STRING, get_ptm_alias, set_ptm_alias, NULL, NULL, BBFDM_BOTH}, -{"Enable", &DMREAD, DMT_BOOL, get_ptm_enable, NULL, NULL, NULL, BBFDM_BOTH}, -{"Name", &DMREAD, DMT_STRING, get_ptm_link_name, NULL, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_ptm_enable, NULL, NULL, NULL, BBFDM_BOTH}, -{"LowerLayers", &DMREAD, DMT_STRING, get_ptm_lower_layer, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.PTM.Link.{i}.Stats. *** */ -DMLEAF tPTMLinkStatsParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"BytesSent", &DMREAD, DMT_UNLONG, get_ptm_stats_bytes_sent, NULL, NULL, NULL, BBFDM_BOTH}, -{"BytesReceived", &DMREAD, DMT_UNLONG, get_ptm_stats_bytes_received, NULL, NULL, NULL, BBFDM_BOTH}, -{"PacketsSent", &DMREAD, DMT_UNLONG, get_ptm_stats_pack_sent, NULL, NULL, NULL, BBFDM_BOTH}, -{"PacketsReceived", &DMREAD, DMT_UNLONG, get_ptm_stats_pack_received, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; /************************************************************************** * LINKER ***************************************************************************/ -int get_ptm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +static int get_ptm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { if (data && ((struct ptm_args *)data)->ifname) { *linker = ((struct ptm_args *)data)->ifname; @@ -73,13 +46,13 @@ static inline int init_ptm_link(struct ptm_args *args, struct uci_section *s, ch * SET & GET DSL LINK PARAMETERS ***************************************************************************/ /*#Device.PTM.Link.{i}.Name!UCI:dsl/ptm-device,@i-1/name*/ -int get_ptm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_ptm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string(((struct ptm_args *)data)->ptm_sec, "name", value); return 0; } -int get_ptm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_ptm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char linker[16]; snprintf(linker, sizeof(linker), "channel_%d", atoi(instance)-1); @@ -99,34 +72,34 @@ static inline int ubus_ptm_stats(char **value, char *stat_mod, void *data) } /*#Device.PTM.Link.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/ -int get_ptm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_ptm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { ubus_ptm_stats(value, "rx_bytes", data); return 0; } /*#Device.PTM.Link.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/ -int get_ptm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_ptm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { ubus_ptm_stats(value, "tx_bytes", data); return 0; } /*#Device.PTM.Link.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/ -int get_ptm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_ptm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { ubus_ptm_stats(value, "rx_packets", data); return 0; } /*#Device.PTM.Link.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/ -int get_ptm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_ptm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { ubus_ptm_stats(value, "tx_packets", data); return 0; } -int get_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "true"; return 0; @@ -135,7 +108,7 @@ int get_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance /************************************************************* * ADD OBJ *************************************************************/ -int add_ptm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +static int add_ptm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *instance = NULL, *ptm_device = NULL, *v = NULL, *instance_update = NULL; struct uci_section *dmmap_ptm = NULL; @@ -155,7 +128,7 @@ int add_ptm_link(char *refparam, struct dmctx *ctx, void *data, char **instancep return 0; } -int delete_ptm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +static int delete_ptm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { char *ifname; struct uci_section *s = NULL, *ss = NULL, *ns = NULL, *nss = NULL, *dmmap_section= NULL; @@ -214,7 +187,7 @@ int delete_ptm_link(char *refparam, struct dmctx *ctx, void *data, char *instanc /************************************************************* * SET AND GET ALIAS *************************************************************/ -int get_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *dmmap_section = NULL; @@ -224,7 +197,7 @@ int get_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, return 0; } -int set_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *dmmap_section = NULL; @@ -246,7 +219,7 @@ int set_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, * ENTRY METHOD *************************************************************/ /*#Device.PTM.Link.{i}.!UCI:dsl/ptm-device/dmmap_dsl*/ -int browsePtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browsePtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *wnum = NULL, *channel_last = NULL, *ifname; struct ptm_args curr_ptm_args = {0}; @@ -264,3 +237,37 @@ int browsePtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, free_dmmap_config_dup_list(&dup_list); return 0; } + +/* *** Device.PTM. *** */ +DMOBJ tPTMObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Link", &DMWRITE, add_ptm_link, delete_ptm_link, NULL, browsePtmLinkInst, NULL, NULL, NULL, tPTMLinkObj, tPTMLinkParams, get_ptm_linker, BBFDM_BOTH}, +{0} +}; + +/* *** Device.PTM.Link.{i}. *** */ +DMOBJ tPTMLinkObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tPTMLinkStatsParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tPTMLinkParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Alias", &DMWRITE, DMT_STRING, get_ptm_alias, set_ptm_alias, NULL, NULL, BBFDM_BOTH}, +{"Enable", &DMREAD, DMT_BOOL, get_ptm_enable, NULL, NULL, NULL, BBFDM_BOTH}, +{"Name", &DMREAD, DMT_STRING, get_ptm_link_name, NULL, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_ptm_enable, NULL, NULL, NULL, BBFDM_BOTH}, +{"LowerLayers", &DMREAD, DMT_STRING, get_ptm_lower_layer, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.PTM.Link.{i}.Stats. *** */ +DMLEAF tPTMLinkStatsParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"BytesSent", &DMREAD, DMT_UNLONG, get_ptm_stats_bytes_sent, NULL, NULL, NULL, BBFDM_BOTH}, +{"BytesReceived", &DMREAD, DMT_UNLONG, get_ptm_stats_bytes_received, NULL, NULL, NULL, BBFDM_BOTH}, +{"PacketsSent", &DMREAD, DMT_UNLONG, get_ptm_stats_pack_sent, NULL, NULL, NULL, BBFDM_BOTH}, +{"PacketsReceived", &DMREAD, DMT_UNLONG, get_ptm_stats_pack_received, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/ptm.h b/dmtree/tr181/ptm.h index 04ae2872..eb683ddf 100644 --- a/dmtree/tr181/ptm.h +++ b/dmtree/tr181/ptm.h @@ -14,32 +14,9 @@ #include -struct ptm_args -{ - struct uci_section *ptm_sec; - char *ifname; -}; - extern DMOBJ tPTMObj[]; extern DMOBJ tPTMLinkObj[]; extern DMLEAF tPTMLinkStatsParams[]; extern DMLEAF tPTMLinkParams[]; -int browsePtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int add_ptm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_ptm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ptm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ptm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ptm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ptm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ptm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ptm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_ptm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); - #endif diff --git a/dmtree/tr181/qos.c b/dmtree/tr181/qos.c index 8ce12257..553f36e7 100644 --- a/dmtree/tr181/qos.c +++ b/dmtree/tr181/qos.c @@ -11,6 +11,3755 @@ #include "dmentry.h" #include "qos.h" +#define queuessts1 "^qdisc noqueue [0-9]*: dev [[:alnum:]]* [[:alnum:]]* refcnt [0-9]*" +#define queuessts2 "^qdisc pfifo_fast [0-9]*: dev [[:alnum:]]* [[:alnum:]]* refcnt [0-9]*" + +struct queuestats +{ + struct uci_section *dmsect; + char dev[50]; + char user[50]; + char priomap[50]; + int noqueue; + int pfifo_fast; + int refcnt; + int bands; + int bytes_sent; + int pkt_sent; + int pkt_dropped; + int pkt_overlimits; + int pkt_requeues; + int backlog_b; + int backlog_p; + int backlog_requeues; +}; + +/************************************************************************** +* LINKER +***************************************************************************/ +static int get_linker_qos_queue(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct dmmap_dup *)data)->config_section) { + dmasprintf(linker,"%s", section_name(((struct dmmap_dup *)data)->config_section)); + return 0; + } else { + *linker = ""; + return 0; + } +} + +/************************************************************************** +* Browse functions +***************************************************************************/ +/*#Device.QoS.Classification.{i}.!UCI:qos/classify/dmmap_qos*/ +static int browseQoSClassificationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *wnum = NULL, *wnum_last = NULL; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("qos", "classify", "dmmap_qos", &dup_list); + list_for_each_entry(p, &dup_list, list) { + wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, p->dmmap_section, "classifinstance", "classifalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, wnum) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int browseQoSAppInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + //TODO + return 0; +} + +static int browseQoSFlowInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + //TODO + return 0; +} + +static int browseQoSPolicerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + //TODO + return 0; +} + +/*#Device.QoS.Queue.{i}.!UCI:qos/class/dmmap_qos*/ +static int browseQoSQueueInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *wnum = NULL, *wnum_last = NULL; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("qos", "class", "dmmap_qos", &dup_list); + list_for_each_entry(p, &dup_list, list) { + wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, p->dmmap_section, "queueinstance", "queuealias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, wnum) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +struct uci_section *get_dup_qos_stats_section_in_dmmap(char *dmmap_package, char *section_type, char *dev) +{ + struct uci_section *s; + + uci_path_foreach_option_eq(bbfdm, dmmap_package, section_type, "dev_link", dev, s) { + return s; + } + + return NULL; +} + +static int browseQoSQueueStatsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *dmmap_sect; + char *questatsout[256], *instance = NULL, *inst_last = NULL, *v, *lastinstancestore = NULL, dev[50] = "", user[50] = ""; + int length, i, ret; + struct queuestats queuests = {0}, emptyquestats = {0}; + regex_t regex1, regex2; + + regcomp(®ex1, queuessts1, 0); + regcomp(®ex2, queuessts2, 0); + check_create_dmmap_package("dmmap_qos"); + command_exec_output_to_array("tc -s qdisc", questatsout, &length); + for (i = 0; i < length; i++){ + switch (i%3) { + case 0: ret = regexec(®ex1, questatsout[i], 0, NULL, 0); + if (ret == 0) + sscanf(questatsout[i], "qdisc noqueue %d: dev %49s %49s refcnt %d\n", &queuests.noqueue, dev, user, &queuests.refcnt); + else { + ret= regexec(®ex2, questatsout[i], 0, NULL, 0); + if (ret == 0) + sscanf(questatsout[i], "qdisc pfifo_fast %d: dev %49s %49s refcnt %d\n", &queuests.pfifo_fast, dev, user, &queuests.refcnt); + } + strcpy(queuests.dev, dev); + break; + case 1: sscanf(questatsout[i], " Sent %d bytes %d pkt (dropped %d, overlimits %d requeues %d)\n", &queuests.bytes_sent, &queuests.pkt_sent, &queuests.pkt_dropped, &queuests.pkt_overlimits, &queuests.pkt_requeues); + break; + case 2: sscanf(questatsout[i], " backlog %db %dp requeues %d\n", &queuests.backlog_b, &queuests.backlog_p, &queuests.backlog_requeues); + if ((dmmap_sect = get_dup_qos_stats_section_in_dmmap("dmmap_qos", "qos_queue_stats", queuests.dev)) == NULL) { + dmuci_add_section_bbfdm("dmmap_qos", "qos_queue_stats", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "dev_link", queuests.dev); + } + queuests.dmsect= dmmap_sect; + + if(lastinstancestore != NULL && inst_last !=NULL) + inst_last= dmstrdup(lastinstancestore); + instance = handle_update_instance(1, dmctx, &inst_last, update_instance_alias, 3, dmmap_sect, "queuestatsinstance", "queuestatsalias"); + lastinstancestore= dmstrdup(inst_last); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&queuests, instance) == DM_STOP) + goto end; + queuests = emptyquestats; + break; + } + } + end: + return 0; +} + +static int browseQoSShaperInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *wnum = NULL, *wnum_last = NULL; + struct dmmap_dup *p; + char *limitrate = NULL; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("qos", "class", "dmmap_qos", &dup_list); + list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "limitrate", &limitrate); + if (limitrate == NULL || strlen(limitrate) == 0) + continue; + wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, p->dmmap_section, "shaperinstance", "shaperalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, wnum) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + + +static int addObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct uci_section *s, *dmmap_qos_classify; + char *last_inst = NULL, *sect_name = NULL, *qos_comment, *v; + char ib[8]; + last_inst = get_last_instance_bbfdm("dmmap_qos", "classify", "classifinstance"); + if (last_inst) + snprintf(ib, sizeof(ib), "%s", last_inst); + else + snprintf(ib, sizeof(ib), "%s", "1"); + dmasprintf(&qos_comment, "QoS classify %d", atoi(ib)+1); + + dmuci_add_section("qos", "classify", &s, §_name); + dmuci_set_value_by_section(s, "comment", qos_comment); + + dmuci_add_section_bbfdm("dmmap_qos", "classify", &dmmap_qos_classify, &v); + dmuci_set_value_by_section(dmmap_qos_classify, "section_name", sect_name); + *instance = update_instance_bbfdm(dmmap_qos_classify, last_inst, "classifinstance"); + return 0; +} + +static int delObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct dmmap_dup *p = (struct dmmap_dup*)data; + struct uci_section *s = NULL, *ss = NULL, *dmmap_section; + int found = 0; + + switch (del_action) { + case DEL_INST: + if(is_section_unnamed(section_name(p->config_section))){ + LIST_HEAD(dup_list); + delete_sections_save_next_sections("dmmap_qos", "classify", "classifinstance", section_name(p->config_section), atoi(instance), &dup_list); + update_dmmap_sections(&dup_list, "classifinstance", "dmmap_qos", "classify"); + dmuci_delete_by_section_unnamed(p->config_section, NULL, NULL); + } else { + get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(p->config_section), &dmmap_section); + dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); + dmuci_delete_by_section(p->config_section, NULL, NULL); + } + break; + case DEL_ALL: + uci_foreach_sections("qos", "classify", s) { + if (found != 0){ + get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(ss), &dmmap_section); + if(dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(ss), &dmmap_section); + if(dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + break; + } + return 0; +} + +static int addObjQoSApp(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + //TODO + return 0; +} + +static int delObjQoSApp(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + switch (del_action) { + case DEL_INST: + //TODO + break; + case DEL_ALL: + //TODO + break; + } + return 0; +} + +static int addObjQoSFlow(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + //TODO + return 0; +} + +static int delObjQoSFlow(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + switch (del_action) { + case DEL_INST: + //TODO + break; + case DEL_ALL: + //TODO + break; + } + return 0; +} + +static int addObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + //TODO + return 0; +} + +static int delObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + switch (del_action) { + case DEL_INST: + //TODO + break; + case DEL_ALL: + //TODO + break; + } + return 0; +} + +static int addObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct uci_section *s, *dmmap_qos_class; + char *last_inst = NULL, *sect_name = NULL, *v; + char ib[8]; + + last_inst = get_last_instance_bbfdm("dmmap_qos", "class", "queueinstance"); + if (last_inst) + snprintf(ib, sizeof(ib), "%s", last_inst); + else + snprintf(ib, sizeof(ib), "%s", "1"); + + dmuci_add_section("qos", "class", &s, §_name); + dmuci_set_value_by_section(s, "packetsize", "1000"); + + dmuci_add_section_bbfdm("dmmap_qos", "class", &dmmap_qos_class, &v); + dmuci_set_value_by_section(dmmap_qos_class, "section_name", sect_name); + *instance = update_instance_bbfdm(dmmap_qos_class, last_inst, "queueinstance"); + return 0; +} + +static int delObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + struct uci_section *s = NULL, *ss = NULL, *dmmap_section; + int found = 0; + + switch (del_action) { + case DEL_INST: + if (is_section_unnamed(section_name(p->config_section))) { + LIST_HEAD(dup_list); + delete_sections_save_next_sections("dmmap_qos", "class", "queueinstance", section_name(p->config_section), atoi(instance), &dup_list); + update_dmmap_sections(&dup_list, "queueinstance", "dmmap_qos", "class"); + dmuci_delete_by_section_unnamed(p->config_section, NULL, NULL); + } else { + get_dmmap_section_of_config_section("dmmap_qos", "class", section_name(p->config_section), &dmmap_section); + dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); + dmuci_delete_by_section(p->config_section, NULL, NULL); + } + break; + case DEL_ALL: + uci_foreach_sections("qos", "class", s) { + if (found != 0) { + get_dmmap_section_of_config_section("dmmap_qos", "class", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + get_dmmap_section_of_config_section("dmmap_qos", "class", section_name(ss), &dmmap_section); + if (dmmap_section != NULL) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + break; + } + return 0; +} + +static int addObjQoSQueueStats(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + //TODO + return 0; +} + +static int delObjQoSQueueStats(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + switch (del_action) { + case DEL_INST: + //TODO + break; + case DEL_ALL: + //TODO + break; + } + return 0; +} + +static int addObjQoSShaper(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + struct uci_section *s, *dmmap_qos_class; + char *last_inst = NULL, *sect_name = NULL, *v; + char ib[8]; + + last_inst= get_last_instance_bbfdm_without_update("dmmap_qos", "class", "shaperinstance"); + if (last_inst) + snprintf(ib, sizeof(ib), "%s", last_inst); + else + snprintf(ib, sizeof(ib), "%s", "1"); + + dmuci_add_section("qos", "class", &s, §_name); + dmuci_set_value_by_section(s, "limitrate", "1000"); + + dmuci_add_section_bbfdm("dmmap_qos", "class", &dmmap_qos_class, &v); + dmuci_set_value_by_section(dmmap_qos_class, "section_name", sect_name); + *instance = update_instance_bbfdm(dmmap_qos_class, last_inst, "shaperinstance"); + return 0; +} + +static int delObjQoSShaper(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + struct uci_section *s, *dmmap_sect; + switch (del_action) { + case DEL_INST: + dmuci_set_value_by_section(p->config_section, "limitrate", ""); + dmuci_set_value_by_section(p->dmmap_section, "shaperinstance", ""); + break; + case DEL_ALL: + uci_foreach_sections("qos", "class", s) { + get_dmmap_section_of_config_section("dmmap_qos", "class", section_name(s), &dmmap_sect); + dmuci_set_value_by_section(s, "limitrate", ""); + dmuci_set_value_by_section(dmmap_sect, "shaperinstance", ""); + } + break; + } + return 0; +} + + +static int get_QoS_MaxClassificationEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.QoS.ClassificationNumberOfEntries!UCI:qos/classify/*/ +static int get_QoS_ClassificationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int nbre= 0; + uci_foreach_sections("qos", "classify", s) { + nbre++; + } + dmasprintf(value, "%d", nbre); + return 0; +} + +static int get_QoS_MaxAppEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoS_AppNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoS_MaxFlowEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoS_FlowNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoS_MaxPolicerEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoS_PolicerNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoS_MaxQueueEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.QoS.QueueNumberOfEntries!UCI:qos/class/*/ +static int get_QoS_QueueNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int nbre= 0; + + uci_foreach_sections("qos", "class", s) { + nbre++; + } + dmasprintf(value, "%d", nbre); + return 0; +} + +static int get_QoS_QueueStatsNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *questatsout[256]; + int length; + + command_exec_output_to_array("tc -s qdisc", questatsout, &length); + dmasprintf(value, "%d", length/3); + return 0; +} + +static int get_QoS_MaxShaperEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoS_ShaperNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int nbre= 0; + char *rate= NULL; + + uci_foreach_sections("qos", "class", s) { + + dmuci_get_value_by_section_string(s, "limitrate", &rate); + + if(rate == NULL || strlen(rate)<=0) + continue; + nbre++; + } + dmasprintf(value, "%d", nbre); + return 0; +} + +static int get_QoS_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoS_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoS_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoS_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoS_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoS_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoS_DefaultQueue(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker; + + dmuci_get_option_value_string("qos", "Default", "default", &linker); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cQoS%cQueue%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + *value = ""; + return 0; +} + +static int set_QoS_DefaultQueue(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + adm_entry_get_linker_value(ctx, value, &linker); + dmuci_set_value("qos", "Default", "default", linker); + break; + } + return 0; +} + +static int get_QoS_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + char *linker, *classtarget; + + dmuci_get_option_value_string("qos", "Default", "default", &linker); + uci_foreach_sections("qos", "classify", s) { + dmuci_get_value_by_section_string(s, "target", &classtarget); + if (strcmp(classtarget, linker) == 0) { + dmuci_get_value_by_section_string(s, "dscp", value); + return 0; + } + } + *value= ""; + return 0; +} + +static int set_QoS_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoS_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoS_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoS_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoS_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoS_AvailableAppList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSClassification_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSClassification_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + dmuci_get_value_by_section_string(p->dmmap_section, "classifalias", value); + return 0; +} + +static int set_QoSClassification_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(p->dmmap_section, "classifalias", value); + break; + } + return 0; +} + +static int get_QoSClassification_DHCPType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DHCPType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, DHCPType, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup *) data; + struct uci_section *s; + char *classes = NULL, **classesarr, *classgroup = NULL, *ifaceclassgrp, *targetclass; + size_t length; + + dmuci_get_value_by_section_string(p->config_section, "target", &targetclass); + uci_foreach_sections("qos", "classgroup", s) { + dmuci_get_value_by_section_string(s, "classes", &classes); + classesarr = strsplit(classes, " ", &length); + if (classes != NULL && is_array_elt_exist(classesarr, targetclass, length)) { + dmasprintf(&classgroup, "%s", section_name(s)); + break; + } + } + if (classgroup == NULL) + return 0; + uci_foreach_sections("qos", "interface", s) { + dmuci_get_value_by_section_string(s, "classgroup", &ifaceclassgrp); + if (ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0) { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); + if (*value == NULL) + *value = ""; + } + } + return 0; +} + +static int set_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.QoS.Classification.{i}.DestIP!UCI:qos/classify,@i-1/dsthost*/ +static int get_QoSClassification_DestIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + dmuci_get_value_by_section_string(p->config_section, "dsthost", value); + return 0; +} + +static int set_QoSClassification_DestIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(p->config_section, "dsthost", value); + break; + } + return 0; +} + +static int get_QoSClassification_DestMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "49", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.QoS.Classification.{i}.SourceIP!UCI:qos/classify,@i-1/srchost*/ +static int get_QoSClassification_SourceIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + dmuci_get_value_by_section_string(p->config_section, "srchost", value); + return 0; +} + +static int set_QoSClassification_SourceIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(p->config_section, "srchost", value); + break; + } + return 0; +} + +static int get_QoSClassification_SourceMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "49", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.QoS.Classification.{i}.Protocol!UCI:qos/classify,@i-1/proto*/ +static int get_QoSClassification_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + dmuci_get_value_by_section_string(p->config_section, "proto", value); + return 0; +} + +static int set_QoSClassification_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "255")) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(p->config_section, "proto", value); + break; + } + return 0; +} + +static int get_QoSClassification_ProtocolExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_ProtocolExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.QoS.Classification.{i}.DestPort!UCI:qos/classify,@i-1/dstports*/ +static int get_QoSClassification_DestPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + dmuci_get_value_by_section_string(p->config_section, "dstports", value); + return 0; +} + +static int set_QoSClassification_DestPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "65535")) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(p->config_section, "dstports", value); + break; + } + return 0; +} + +/*#Device.QoS.Classification.{i}.DestPortRangeMax!UCI:qos/classify,@i-1/portrange*/ +static int get_QoSClassification_DestPortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + dmuci_get_value_by_section_string(p->config_section, "portrange", value); + return 0; +} + +static int set_QoSClassification_DestPortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "65535")) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(p->config_section, "portrange", value); + break; + } + return 0; +} + +static int get_QoSClassification_DestPortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestPortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.QoS.Classification.{i}.SourcePort!UCI:qos/classify,@i-1/srcports*/ +static int get_QoSClassification_SourcePort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + dmuci_get_value_by_section_string(p->config_section, "srcports", value); + return 0; +} + +static int set_QoSClassification_SourcePort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "65535")) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(p->config_section, "srcports", value); + break; + } + return 0; +} + +static int get_QoSClassification_SourcePortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourcePortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "65535")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourcePortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourcePortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_Ethertype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_Ethertype(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_EthertypeExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_EthertypeExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_LLCControl(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_LLCControl(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_LLCControlExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_LLCControlExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SNAPOUI(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SNAPOUI(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SNAPOUIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SNAPOUIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "255", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "65535")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, VendorClassIDMode, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "255", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "65535")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, VendorClassIDMode, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "65535")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "65535")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "65535")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "65535")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "65535")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_SourceVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_SourceVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "0", "255")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "65535")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DestVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DestVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "0", "255")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_TCPACK(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_TCPACK(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_TCPACKExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_TCPACKExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_IPLengthMin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_IPLengthMin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_IPLengthMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_IPLengthMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_IPLengthExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_IPLengthExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DSCPCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DSCPCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "63")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_DSCPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_DSCPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.QoS.Classification.{i}.DSCPMark!UCI:qos/classify,@i-1/dscp*/ +static int get_QoSClassification_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup *)data; + dmuci_get_value_by_section_string(p->config_section, "dscp", value); + return 0; +} + +static int set_QoSClassification_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup *)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(p->config_section, "dscp", value); + break; + } + return 0; +} + +static int get_QoSClassification_EthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_EthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_EthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_EthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_InnerEthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_InnerEthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_InnerEthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_InnerEthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_EthernetDEICheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_EthernetDEICheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_EthernetDEIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_EthernetDEIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_OutOfBandInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_OutOfBandInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSClassification_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSClassification_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSApp_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSApp_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSApp_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSApp_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSApp_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSApp_ProtocolIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSApp_ProtocolIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSApp_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSApp_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSApp_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSApp_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSApp_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSApp_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSApp_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSApp_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSApp_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSApp_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSApp_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSApp_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSApp_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSApp_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSFlow_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_TypeParameters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_TypeParameters(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSFlow_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSFlow_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-2", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSPolicer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSPolicer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSPolicer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_CommittedRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSPolicer_CommittedRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_CommittedBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSPolicer_CommittedBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_ExcessBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSPolicer_ExcessBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_PeakRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSPolicer_PeakRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_PeakBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSPolicer_PeakBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_MeterType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSPolicer_MeterType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_PossibleMeterTypes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSPolicer_ConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSPolicer_ConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, ConformingAction)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_PartialConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSPolicer_PartialConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, ConformingAction)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_NonConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSPolicer_NonConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, ConformingAction)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSPolicer_TotalCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSPolicer_TotalCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSPolicer_ConformingCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSPolicer_ConformingCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSPolicer_PartiallyConformingCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSPolicer_PartiallyConformingCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSPolicer_NonConformingCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSPolicer_NonConformingCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSQueue_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueue_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueue_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSQueue_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + dmuci_get_value_by_section_string(p->dmmap_section, "queuealias", value); + return 0; +} + +static int set_QoSQueue_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(p->dmmap_section, "queuealias", value); + break; + } + return 0; +} + +static int get_QoSQueue_TrafficClasses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueue_TrafficClasses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt_list(value, NULL, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p = (struct dmmap_dup *)data; + struct uci_section *s; + char *classes = NULL, **classesarr, *classgroup = NULL, *ifaceclassgrp; + size_t length; + + uci_foreach_sections("qos", "classgroup", s) { + dmuci_get_value_by_section_string(s, "classes", &classes); + classesarr = strsplit(classes, " ", &length); + if (classes != NULL && is_array_elt_exist(classesarr, section_name(p->config_section), length)){ + dmasprintf(&classgroup, "%s", section_name(s)); + break; + } + } + if(classgroup == NULL) + return 0; + uci_foreach_sections("qos", "interface", s) { + dmuci_get_value_by_section_string(s, "classgroup", &ifaceclassgrp); + if (ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0) { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); + if (*value == NULL) + *value = ""; + } + } + return 0; +} + +static int set_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueue_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueue_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueue_HardwareAssisted(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.QoS.Queue.{i}.BufferLength!UCI:qos/class,@i-1/maxsize*/ +static int get_QoSQueue_BufferLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + dmuci_get_value_by_section_string(p->config_section, "maxsize", value); + return 0; +} + +static int get_QoSQueue_Weight(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueue_Weight(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueue_Precedence(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueue_Precedence(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueue_REDThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueue_REDThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, "100")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueue_REDPercentage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueue_REDPercentage(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, "100")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueue_DropAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueue_DropAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, DropAlgorithm, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueue_SchedulerAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueue_SchedulerAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, SchedulerAlgorithm, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.QoS.Queue.{i}.ShapingRate!UCI:qos/class,@i-1/limitrate*/ +static int get_QoSQueue_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + char *rate= NULL; + + dmuci_get_value_by_section_string(p->config_section, "limitrate", &rate); + if (rate != NULL && atoi(rate)>=0) + dmasprintf(value, "%s", rate); + else + dmasprintf(value, "%s", "-1"); + return 0; +} + +static int set_QoSQueue_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + if(atoi(value)>=0) + dmuci_set_value_by_section(p->config_section, "limitrate", value); + else + dmuci_set_value_by_section(p->config_section, "limitrate", ""); + + break; + } + return 0; +} + +static int get_QoSQueue_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueue_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueueStats_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueueStats_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueueStats_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSQueueStats_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct queuestats *qts= (struct queuestats*)data; + dmuci_get_value_by_section_string(qts->dmsect, "queuestatsalias", value); + return 0; +} + +static int set_QoSQueueStats_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct queuestats *qts= (struct queuestats*)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(qts->dmsect, "queuestatsalias", value); + break; + } + return 0; +} + +static int get_QoSQueueStats_Queue(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSQueueStats_Queue(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueueStats_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct queuestats *qts= (struct queuestats*)data; + + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), qts->dev, value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), qts->dev, value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), qts->dev, value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cRadio%c", dmroot, dm_delim, dm_delim, dm_delim), qts->dev, value); + if (*value == NULL) + *value = ""; + return 0; +} + +static int set_QoSQueueStats_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSQueueStats_OutputPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct queuestats *queuests= (struct queuestats*)data; + dmasprintf(value, "%d", queuests->pkt_sent); + return 0; +} + +static int get_QoSQueueStats_OutputBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct queuestats *queuests= (struct queuestats*)data; + dmasprintf(value, "%d", queuests->bytes_sent); + return 0; +} + +static int get_QoSQueueStats_DroppedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct queuestats *queuests= (struct queuestats*)data; + dmasprintf(value, "%d", queuests->pkt_dropped); + return 0; +} + +static int get_QoSQueueStats_DroppedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return 0; +} + +static int get_QoSQueueStats_QueueOccupancyPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct queuestats *queuests= (struct queuestats*)data; + dmasprintf(value, "%d", queuests->pkt_requeues); + return 0; +} + +static int get_QoSQueueStats_QueueOccupancyPercentage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSShaper_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSShaper_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSShaper_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_QoSShaper_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + dmuci_get_value_by_section_string(p->dmmap_section, "shaperalias", value); + return 0; +} + +static int set_QoSShaper_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(p->dmmap_section, "shaperalias", value); + break; + } + return 0; +} + +static int get_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p = (struct dmmap_dup *)data; + struct uci_section *s; + char *classes = NULL, **classesarr, *classgroup = NULL, *ifaceclassgrp; + size_t length; + + uci_foreach_sections("qos", "classgroup", s) { + dmuci_get_value_by_section_string(s, "classes", &classes); + classesarr= strsplit(classes, " ", &length); + if (classes != NULL && is_array_elt_exist(classesarr, section_name(p->config_section), length)){ + dmasprintf(&classgroup, "%s", section_name(s)); + break; + } + } + if(classgroup == NULL) + return 0; + uci_foreach_sections("qos", "interface", s) { + dmuci_get_value_by_section_string(s, "classgroup", &ifaceclassgrp); + if (ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0) { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); + if (*value == NULL) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); + if (*value == NULL) + *value = ""; + } + } + return 0; +} + +static int set_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_QoSShaper_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + char *rate= NULL; + + dmuci_get_value_by_section_string(p->config_section, "limitrate", &rate); + if (rate != NULL && atoi(rate)>=0) + dmasprintf(value, "%s", rate); + else + dmasprintf(value, "%s", "-1"); + return 0; +} + +static int set_QoSShaper_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct dmmap_dup *p= (struct dmmap_dup*)data; + + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", NULL)) + return FAULT_9007; + break; + case VALUESET: + if(atoi(value)>=0) + dmuci_set_value_by_section(p->config_section, "limitrate", value); + else + dmuci_set_value_by_section(p->config_section, "limitrate", ""); + + break; + } + return 0; +} + +static int get_QoSShaper_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_QoSShaper_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + /* *** Device.QoS. *** */ DMOBJ tQoSObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -253,3730 +4002,3 @@ DMLEAF tQoSShaperParams[] = { //{"ShapingBurstSize", &DMWRITE, DMT_UNINT, get_QoSShaper_ShapingBurstSize, set_QoSShaper_ShapingBurstSize, NULL, NULL, BBFDM_BOTH}, {0} }; - -/************************************************************************** -* LINKER -***************************************************************************/ -int get_linker_qos_queue(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct dmmap_dup *)data)->config_section) { - dmasprintf(linker,"%s", section_name(((struct dmmap_dup *)data)->config_section)); - return 0; - } else { - *linker = ""; - return 0; - } -} - -/************************************************************************** -* Browse functions -***************************************************************************/ -/*#Device.QoS.Classification.{i}.!UCI:qos/classify/dmmap_qos*/ -int browseQoSClassificationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *wnum = NULL, *wnum_last = NULL; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("qos", "classify", "dmmap_qos", &dup_list); - list_for_each_entry(p, &dup_list, list) { - wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, p->dmmap_section, "classifinstance", "classifalias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, wnum) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int browseQoSAppInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - //TODO - return 0; -} - -int browseQoSFlowInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - //TODO - return 0; -} - -int browseQoSPolicerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - //TODO - return 0; -} - -/*#Device.QoS.Queue.{i}.!UCI:qos/class/dmmap_qos*/ -int browseQoSQueueInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *wnum = NULL, *wnum_last = NULL; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("qos", "class", "dmmap_qos", &dup_list); - list_for_each_entry(p, &dup_list, list) { - wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, p->dmmap_section, "queueinstance", "queuealias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, wnum) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -struct uci_section *get_dup_qos_stats_section_in_dmmap(char *dmmap_package, char *section_type, char *dev) -{ - struct uci_section *s; - - uci_path_foreach_option_eq(bbfdm, dmmap_package, section_type, "dev_link", dev, s) { - return s; - } - - return NULL; -} - -int browseQoSQueueStatsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *dmmap_sect; - char *questatsout[256], *instance = NULL, *inst_last = NULL, *v, *lastinstancestore = NULL, dev[50] = "", user[50] = ""; - int length, i, ret; - struct queuestats queuests = {0}, emptyquestats = {0}; - regex_t regex1, regex2; - - regcomp(®ex1, queuessts1, 0); - regcomp(®ex2, queuessts2, 0); - check_create_dmmap_package("dmmap_qos"); - command_exec_output_to_array("tc -s qdisc", questatsout, &length); - for (i = 0; i < length; i++){ - switch (i%3) { - case 0: ret = regexec(®ex1, questatsout[i], 0, NULL, 0); - if (ret == 0) - sscanf(questatsout[i], "qdisc noqueue %d: dev %49s %49s refcnt %d\n", &queuests.noqueue, dev, user, &queuests.refcnt); - else { - ret= regexec(®ex2, questatsout[i], 0, NULL, 0); - if (ret == 0) - sscanf(questatsout[i], "qdisc pfifo_fast %d: dev %49s %49s refcnt %d\n", &queuests.pfifo_fast, dev, user, &queuests.refcnt); - } - strcpy(queuests.dev, dev); - break; - case 1: sscanf(questatsout[i], " Sent %d bytes %d pkt (dropped %d, overlimits %d requeues %d)\n", &queuests.bytes_sent, &queuests.pkt_sent, &queuests.pkt_dropped, &queuests.pkt_overlimits, &queuests.pkt_requeues); - break; - case 2: sscanf(questatsout[i], " backlog %db %dp requeues %d\n", &queuests.backlog_b, &queuests.backlog_p, &queuests.backlog_requeues); - if ((dmmap_sect = get_dup_qos_stats_section_in_dmmap("dmmap_qos", "qos_queue_stats", queuests.dev)) == NULL) { - dmuci_add_section_bbfdm("dmmap_qos", "qos_queue_stats", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "dev_link", queuests.dev); - } - queuests.dmsect= dmmap_sect; - - if(lastinstancestore != NULL && inst_last !=NULL) - inst_last= dmstrdup(lastinstancestore); - instance = handle_update_instance(1, dmctx, &inst_last, update_instance_alias, 3, dmmap_sect, "queuestatsinstance", "queuestatsalias"); - lastinstancestore= dmstrdup(inst_last); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&queuests, instance) == DM_STOP) - goto end; - queuests = emptyquestats; - break; - } - } - end: - return 0; -} - -int browseQoSShaperInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *wnum = NULL, *wnum_last = NULL; - struct dmmap_dup *p; - char *limitrate = NULL; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("qos", "class", "dmmap_qos", &dup_list); - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "limitrate", &limitrate); - if (limitrate == NULL || strlen(limitrate) == 0) - continue; - wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, p->dmmap_section, "shaperinstance", "shaperalias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, wnum) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - - -int addObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct uci_section *s, *dmmap_qos_classify; - char *last_inst = NULL, *sect_name = NULL, *qos_comment, *v; - char ib[8]; - last_inst = get_last_instance_bbfdm("dmmap_qos", "classify", "classifinstance"); - if (last_inst) - snprintf(ib, sizeof(ib), "%s", last_inst); - else - snprintf(ib, sizeof(ib), "%s", "1"); - dmasprintf(&qos_comment, "QoS classify %d", atoi(ib)+1); - - dmuci_add_section("qos", "classify", &s, §_name); - dmuci_set_value_by_section(s, "comment", qos_comment); - - dmuci_add_section_bbfdm("dmmap_qos", "classify", &dmmap_qos_classify, &v); - dmuci_set_value_by_section(dmmap_qos_classify, "section_name", sect_name); - *instance = update_instance_bbfdm(dmmap_qos_classify, last_inst, "classifinstance"); - return 0; -} - -int delObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct dmmap_dup *p = (struct dmmap_dup*)data; - struct uci_section *s = NULL, *ss = NULL, *dmmap_section; - int found = 0; - - switch (del_action) { - case DEL_INST: - if(is_section_unnamed(section_name(p->config_section))){ - LIST_HEAD(dup_list); - delete_sections_save_next_sections("dmmap_qos", "classify", "classifinstance", section_name(p->config_section), atoi(instance), &dup_list); - update_dmmap_sections(&dup_list, "classifinstance", "dmmap_qos", "classify"); - dmuci_delete_by_section_unnamed(p->config_section, NULL, NULL); - } else { - get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(p->config_section), &dmmap_section); - dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); - dmuci_delete_by_section(p->config_section, NULL, NULL); - } - break; - case DEL_ALL: - uci_foreach_sections("qos", "classify", s) { - if (found != 0){ - get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(ss), &dmmap_section); - if(dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(ss), &dmmap_section); - if(dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - break; - } - return 0; -} - -int addObjQoSApp(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - //TODO - return 0; -} - -int delObjQoSApp(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - switch (del_action) { - case DEL_INST: - //TODO - break; - case DEL_ALL: - //TODO - break; - } - return 0; -} - -int addObjQoSFlow(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - //TODO - return 0; -} - -int delObjQoSFlow(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - switch (del_action) { - case DEL_INST: - //TODO - break; - case DEL_ALL: - //TODO - break; - } - return 0; -} - -int addObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - //TODO - return 0; -} - -int delObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - switch (del_action) { - case DEL_INST: - //TODO - break; - case DEL_ALL: - //TODO - break; - } - return 0; -} - -int addObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct uci_section *s, *dmmap_qos_class; - char *last_inst = NULL, *sect_name = NULL, *v; - char ib[8]; - - last_inst = get_last_instance_bbfdm("dmmap_qos", "class", "queueinstance"); - if (last_inst) - snprintf(ib, sizeof(ib), "%s", last_inst); - else - snprintf(ib, sizeof(ib), "%s", "1"); - - dmuci_add_section("qos", "class", &s, §_name); - dmuci_set_value_by_section(s, "packetsize", "1000"); - - dmuci_add_section_bbfdm("dmmap_qos", "class", &dmmap_qos_class, &v); - dmuci_set_value_by_section(dmmap_qos_class, "section_name", sect_name); - *instance = update_instance_bbfdm(dmmap_qos_class, last_inst, "queueinstance"); - return 0; -} - -int delObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - struct uci_section *s = NULL, *ss = NULL, *dmmap_section; - int found = 0; - - switch (del_action) { - case DEL_INST: - if (is_section_unnamed(section_name(p->config_section))) { - LIST_HEAD(dup_list); - delete_sections_save_next_sections("dmmap_qos", "class", "queueinstance", section_name(p->config_section), atoi(instance), &dup_list); - update_dmmap_sections(&dup_list, "queueinstance", "dmmap_qos", "class"); - dmuci_delete_by_section_unnamed(p->config_section, NULL, NULL); - } else { - get_dmmap_section_of_config_section("dmmap_qos", "class", section_name(p->config_section), &dmmap_section); - dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL); - dmuci_delete_by_section(p->config_section, NULL, NULL); - } - break; - case DEL_ALL: - uci_foreach_sections("qos", "class", s) { - if (found != 0) { - get_dmmap_section_of_config_section("dmmap_qos", "class", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - get_dmmap_section_of_config_section("dmmap_qos", "class", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - break; - } - return 0; -} - -int addObjQoSQueueStats(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - //TODO - return 0; -} - -int delObjQoSQueueStats(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - switch (del_action) { - case DEL_INST: - //TODO - break; - case DEL_ALL: - //TODO - break; - } - return 0; -} - -int addObjQoSShaper(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - struct uci_section *s, *dmmap_qos_class; - char *last_inst = NULL, *sect_name = NULL, *v; - char ib[8]; - - last_inst= get_last_instance_bbfdm_without_update("dmmap_qos", "class", "shaperinstance"); - if (last_inst) - snprintf(ib, sizeof(ib), "%s", last_inst); - else - snprintf(ib, sizeof(ib), "%s", "1"); - - dmuci_add_section("qos", "class", &s, §_name); - dmuci_set_value_by_section(s, "limitrate", "1000"); - - dmuci_add_section_bbfdm("dmmap_qos", "class", &dmmap_qos_class, &v); - dmuci_set_value_by_section(dmmap_qos_class, "section_name", sect_name); - *instance = update_instance_bbfdm(dmmap_qos_class, last_inst, "shaperinstance"); - return 0; -} - -int delObjQoSShaper(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - struct uci_section *s, *dmmap_sect; - switch (del_action) { - case DEL_INST: - dmuci_set_value_by_section(p->config_section, "limitrate", ""); - dmuci_set_value_by_section(p->dmmap_section, "shaperinstance", ""); - break; - case DEL_ALL: - uci_foreach_sections("qos", "class", s) { - get_dmmap_section_of_config_section("dmmap_qos", "class", section_name(s), &dmmap_sect); - dmuci_set_value_by_section(s, "limitrate", ""); - dmuci_set_value_by_section(dmmap_sect, "shaperinstance", ""); - } - break; - } - return 0; -} - - -int get_QoS_MaxClassificationEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.QoS.ClassificationNumberOfEntries!UCI:qos/classify/*/ -int get_QoS_ClassificationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int nbre= 0; - uci_foreach_sections("qos", "classify", s) { - nbre++; - } - dmasprintf(value, "%d", nbre); - return 0; -} - -int get_QoS_MaxAppEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoS_AppNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoS_MaxFlowEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoS_FlowNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoS_MaxPolicerEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoS_PolicerNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoS_MaxQueueEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.QoS.QueueNumberOfEntries!UCI:qos/class/*/ -int get_QoS_QueueNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int nbre= 0; - - uci_foreach_sections("qos", "class", s) { - nbre++; - } - dmasprintf(value, "%d", nbre); - return 0; -} - -int get_QoS_QueueStatsNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *questatsout[256]; - int length; - - command_exec_output_to_array("tc -s qdisc", questatsout, &length); - dmasprintf(value, "%d", length/3); - return 0; -} - -int get_QoS_MaxShaperEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoS_ShaperNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int nbre= 0; - char *rate= NULL; - - uci_foreach_sections("qos", "class", s) { - - dmuci_get_value_by_section_string(s, "limitrate", &rate); - - if(rate == NULL || strlen(rate)<=0) - continue; - nbre++; - } - dmasprintf(value, "%d", nbre); - return 0; -} - -int get_QoS_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoS_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoS_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoS_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoS_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoS_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoS_DefaultQueue(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *linker; - - dmuci_get_option_value_string("qos", "Default", "default", &linker); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cQoS%cQueue%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); - if (*value == NULL) - *value = ""; - return 0; -} - -int set_QoS_DefaultQueue(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *linker; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - adm_entry_get_linker_value(ctx, value, &linker); - dmuci_set_value("qos", "Default", "default", linker); - break; - } - return 0; -} - -int get_QoS_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - char *linker, *classtarget; - - dmuci_get_option_value_string("qos", "Default", "default", &linker); - uci_foreach_sections("qos", "classify", s) { - dmuci_get_value_by_section_string(s, "target", &classtarget); - if (strcmp(classtarget, linker) == 0) { - dmuci_get_value_by_section_string(s, "dscp", value); - return 0; - } - } - *value= ""; - return 0; -} - -int set_QoS_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoS_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoS_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoS_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoS_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoS_AvailableAppList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSClassification_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSClassification_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - dmuci_get_value_by_section_string(p->dmmap_section, "classifalias", value); - return 0; -} - -int set_QoSClassification_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(p->dmmap_section, "classifalias", value); - break; - } - return 0; -} - -int get_QoSClassification_DHCPType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DHCPType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, DHCPType, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup *) data; - struct uci_section *s; - char *classes = NULL, **classesarr, *classgroup = NULL, *ifaceclassgrp, *targetclass; - size_t length; - - dmuci_get_value_by_section_string(p->config_section, "target", &targetclass); - uci_foreach_sections("qos", "classgroup", s) { - dmuci_get_value_by_section_string(s, "classes", &classes); - classesarr = strsplit(classes, " ", &length); - if (classes != NULL && is_array_elt_exist(classesarr, targetclass, length)) { - dmasprintf(&classgroup, "%s", section_name(s)); - break; - } - } - if (classgroup == NULL) - return 0; - uci_foreach_sections("qos", "interface", s) { - dmuci_get_value_by_section_string(s, "classgroup", &ifaceclassgrp); - if (ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0) { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); - if (*value == NULL) - *value = ""; - } - } - return 0; -} - -int set_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.QoS.Classification.{i}.DestIP!UCI:qos/classify,@i-1/dsthost*/ -int get_QoSClassification_DestIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - dmuci_get_value_by_section_string(p->config_section, "dsthost", value); - return 0; -} - -int set_QoSClassification_DestIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(p->config_section, "dsthost", value); - break; - } - return 0; -} - -int get_QoSClassification_DestMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "49", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.QoS.Classification.{i}.SourceIP!UCI:qos/classify,@i-1/srchost*/ -int get_QoSClassification_SourceIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - dmuci_get_value_by_section_string(p->config_section, "srchost", value); - return 0; -} - -int set_QoSClassification_SourceIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(p->config_section, "srchost", value); - break; - } - return 0; -} - -int get_QoSClassification_SourceMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "49", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.QoS.Classification.{i}.Protocol!UCI:qos/classify,@i-1/proto*/ -int get_QoSClassification_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - dmuci_get_value_by_section_string(p->config_section, "proto", value); - return 0; -} - -int set_QoSClassification_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "255")) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(p->config_section, "proto", value); - break; - } - return 0; -} - -int get_QoSClassification_ProtocolExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_ProtocolExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.QoS.Classification.{i}.DestPort!UCI:qos/classify,@i-1/dstports*/ -int get_QoSClassification_DestPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - dmuci_get_value_by_section_string(p->config_section, "dstports", value); - return 0; -} - -int set_QoSClassification_DestPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "65535")) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(p->config_section, "dstports", value); - break; - } - return 0; -} - -/*#Device.QoS.Classification.{i}.DestPortRangeMax!UCI:qos/classify,@i-1/portrange*/ -int get_QoSClassification_DestPortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - dmuci_get_value_by_section_string(p->config_section, "portrange", value); - return 0; -} - -int set_QoSClassification_DestPortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "65535")) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(p->config_section, "portrange", value); - break; - } - return 0; -} - -int get_QoSClassification_DestPortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestPortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.QoS.Classification.{i}.SourcePort!UCI:qos/classify,@i-1/srcports*/ -int get_QoSClassification_SourcePort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - dmuci_get_value_by_section_string(p->config_section, "srcports", value); - return 0; -} - -int set_QoSClassification_SourcePort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "65535")) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(p->config_section, "srcports", value); - break; - } - return 0; -} - -int get_QoSClassification_SourcePortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourcePortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "65535")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourcePortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourcePortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "17", NULL, MACAddress)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_Ethertype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_Ethertype(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_EthertypeExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_EthertypeExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_LLCControl(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_LLCControl(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_LLCControlExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_LLCControlExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SNAPOUI(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SNAPOUI(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SNAPOUIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SNAPOUIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "255", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "65535")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, VendorClassIDMode, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "255", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "65535")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, VendorClassIDMode, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "65535")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "65535")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "65535")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "65535")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "65535")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_SourceVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_SourceVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "0", "255")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "65535")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DestVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DestVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "0", "255")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_TCPACK(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_TCPACK(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_TCPACKExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_TCPACKExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_IPLengthMin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_IPLengthMin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_IPLengthMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_IPLengthMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_IPLengthExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_IPLengthExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DSCPCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DSCPCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "63")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_DSCPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_DSCPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.QoS.Classification.{i}.DSCPMark!UCI:qos/classify,@i-1/dscp*/ -int get_QoSClassification_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup *)data; - dmuci_get_value_by_section_string(p->config_section, "dscp", value); - return 0; -} - -int set_QoSClassification_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup *)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(p->config_section, "dscp", value); - break; - } - return 0; -} - -int get_QoSClassification_EthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_EthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_EthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_EthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_InnerEthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_InnerEthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_InnerEthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_InnerEthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_EthernetDEICheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_EthernetDEICheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_EthernetDEIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_EthernetDEIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_OutOfBandInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_OutOfBandInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSClassification_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSClassification_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSApp_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSApp_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSApp_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSApp_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSApp_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSApp_ProtocolIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSApp_ProtocolIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSApp_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSApp_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSApp_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSApp_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSApp_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSApp_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSApp_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSApp_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSApp_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSApp_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSApp_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSApp_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSApp_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSApp_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSFlow_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_TypeParameters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_TypeParameters(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSFlow_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSFlow_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-2", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSPolicer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSPolicer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSPolicer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_CommittedRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSPolicer_CommittedRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_CommittedBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSPolicer_CommittedBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_ExcessBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSPolicer_ExcessBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_PeakRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSPolicer_PeakRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_PeakBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSPolicer_PeakBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_MeterType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSPolicer_MeterType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_PossibleMeterTypes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSPolicer_ConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSPolicer_ConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, ConformingAction)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_PartialConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSPolicer_PartialConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, ConformingAction)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_NonConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSPolicer_NonConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, ConformingAction)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSPolicer_TotalCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSPolicer_TotalCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSPolicer_ConformingCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSPolicer_ConformingCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSPolicer_PartiallyConformingCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSPolicer_PartiallyConformingCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSPolicer_NonConformingCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSPolicer_NonConformingCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSQueue_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueue_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueue_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSQueue_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - dmuci_get_value_by_section_string(p->dmmap_section, "queuealias", value); - return 0; -} - -int set_QoSQueue_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(p->dmmap_section, "queuealias", value); - break; - } - return 0; -} - -int get_QoSQueue_TrafficClasses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueue_TrafficClasses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt_list(value, NULL, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p = (struct dmmap_dup *)data; - struct uci_section *s; - char *classes = NULL, **classesarr, *classgroup = NULL, *ifaceclassgrp; - size_t length; - - uci_foreach_sections("qos", "classgroup", s) { - dmuci_get_value_by_section_string(s, "classes", &classes); - classesarr = strsplit(classes, " ", &length); - if (classes != NULL && is_array_elt_exist(classesarr, section_name(p->config_section), length)){ - dmasprintf(&classgroup, "%s", section_name(s)); - break; - } - } - if(classgroup == NULL) - return 0; - uci_foreach_sections("qos", "interface", s) { - dmuci_get_value_by_section_string(s, "classgroup", &ifaceclassgrp); - if (ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0) { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); - if (*value == NULL) - *value = ""; - } - } - return 0; -} - -int set_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueue_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueue_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueue_HardwareAssisted(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.QoS.Queue.{i}.BufferLength!UCI:qos/class,@i-1/maxsize*/ -int get_QoSQueue_BufferLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - dmuci_get_value_by_section_string(p->config_section, "maxsize", value); - return 0; -} - -int get_QoSQueue_Weight(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueue_Weight(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueue_Precedence(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueue_Precedence(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueue_REDThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueue_REDThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, "100")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueue_REDPercentage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueue_REDPercentage(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, "100")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueue_DropAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueue_DropAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, DropAlgorithm, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueue_SchedulerAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueue_SchedulerAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, SchedulerAlgorithm, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.QoS.Queue.{i}.ShapingRate!UCI:qos/class,@i-1/limitrate*/ -int get_QoSQueue_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - char *rate= NULL; - - dmuci_get_value_by_section_string(p->config_section, "limitrate", &rate); - if (rate != NULL && atoi(rate)>=0) - dmasprintf(value, "%s", rate); - else - dmasprintf(value, "%s", "-1"); - return 0; -} - -int set_QoSQueue_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - if(atoi(value)>=0) - dmuci_set_value_by_section(p->config_section, "limitrate", value); - else - dmuci_set_value_by_section(p->config_section, "limitrate", ""); - - break; - } - return 0; -} - -int get_QoSQueue_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueue_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueueStats_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueueStats_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueueStats_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSQueueStats_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct queuestats *qts= (struct queuestats*)data; - dmuci_get_value_by_section_string(qts->dmsect, "queuestatsalias", value); - return 0; -} - -int set_QoSQueueStats_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct queuestats *qts= (struct queuestats*)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(qts->dmsect, "queuestatsalias", value); - break; - } - return 0; -} - -int get_QoSQueueStats_Queue(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSQueueStats_Queue(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueueStats_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct queuestats *qts= (struct queuestats*)data; - - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), qts->dev, value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), qts->dev, value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), qts->dev, value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cRadio%c", dmroot, dm_delim, dm_delim, dm_delim), qts->dev, value); - if (*value == NULL) - *value = ""; - return 0; -} - -int set_QoSQueueStats_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSQueueStats_OutputPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct queuestats *queuests= (struct queuestats*)data; - dmasprintf(value, "%d", queuests->pkt_sent); - return 0; -} - -int get_QoSQueueStats_OutputBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct queuestats *queuests= (struct queuestats*)data; - dmasprintf(value, "%d", queuests->bytes_sent); - return 0; -} - -int get_QoSQueueStats_DroppedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct queuestats *queuests= (struct queuestats*)data; - dmasprintf(value, "%d", queuests->pkt_dropped); - return 0; -} - -int get_QoSQueueStats_DroppedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return 0; -} - -int get_QoSQueueStats_QueueOccupancyPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct queuestats *queuests= (struct queuestats*)data; - dmasprintf(value, "%d", queuests->pkt_requeues); - return 0; -} - -int get_QoSQueueStats_QueueOccupancyPercentage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSShaper_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSShaper_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSShaper_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_QoSShaper_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - dmuci_get_value_by_section_string(p->dmmap_section, "shaperalias", value); - return 0; -} - -int set_QoSShaper_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(p->dmmap_section, "shaperalias", value); - break; - } - return 0; -} - -int get_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p = (struct dmmap_dup *)data; - struct uci_section *s; - char *classes = NULL, **classesarr, *classgroup = NULL, *ifaceclassgrp; - size_t length; - - uci_foreach_sections("qos", "classgroup", s) { - dmuci_get_value_by_section_string(s, "classes", &classes); - classesarr= strsplit(classes, " ", &length); - if (classes != NULL && is_array_elt_exist(classesarr, section_name(p->config_section), length)){ - dmasprintf(&classgroup, "%s", section_name(s)); - break; - } - } - if(classgroup == NULL) - return 0; - uci_foreach_sections("qos", "interface", s) { - dmuci_get_value_by_section_string(s, "classgroup", &ifaceclassgrp); - if (ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0) { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); - if (*value == NULL) - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value); - if (*value == NULL) - *value = ""; - } - } - return 0; -} - -int set_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_QoSShaper_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - char *rate= NULL; - - dmuci_get_value_by_section_string(p->config_section, "limitrate", &rate); - if (rate != NULL && atoi(rate)>=0) - dmasprintf(value, "%s", rate); - else - dmasprintf(value, "%s", "-1"); - return 0; -} - -int set_QoSShaper_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct dmmap_dup *p= (struct dmmap_dup*)data; - - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", NULL)) - return FAULT_9007; - break; - case VALUESET: - if(atoi(value)>=0) - dmuci_set_value_by_section(p->config_section, "limitrate", value); - else - dmuci_set_value_by_section(p->config_section, "limitrate", ""); - - break; - } - return 0; -} - -int get_QoSShaper_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_QoSShaper_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - diff --git a/dmtree/tr181/qos.h b/dmtree/tr181/qos.h index 5603cf4f..a3e213e8 100644 --- a/dmtree/tr181/qos.h +++ b/dmtree/tr181/qos.h @@ -23,382 +23,5 @@ extern DMLEAF tQoSQueueParams[]; extern DMLEAF tQoSQueueStatsParams[]; extern DMLEAF tQoSShaperParams[]; -#define queuessts1 "^qdisc noqueue [0-9]*: dev [[:alnum:]]* [[:alnum:]]* refcnt [0-9]*" -#define queuessts2 "^qdisc pfifo_fast [0-9]*: dev [[:alnum:]]* [[:alnum:]]* refcnt [0-9]*" - -struct queuestats -{ - struct uci_section *dmsect; - char dev[50]; - char user[50]; - char priomap[50]; - int noqueue; - int pfifo_fast; - int refcnt; - int bands; - int bytes_sent; - int pkt_sent; - int pkt_dropped; - int pkt_overlimits; - int pkt_requeues; - int backlog_b; - int backlog_p; - int backlog_requeues; -}; - -int get_linker_qos_queue(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); - -int browseQoSClassificationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseQoSAppInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseQoSFlowInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseQoSPolicerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseQoSQueueInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseQoSQueueStatsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseQoSShaperInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int addObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjQoSApp(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjQoSApp(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjQoSFlow(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjQoSFlow(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjQoSQueueStats(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjQoSQueueStats(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjQoSShaper(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjQoSShaper(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_QoS_MaxClassificationEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_ClassificationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_MaxAppEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_AppNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_MaxFlowEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_FlowNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_MaxPolicerEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_PolicerNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_MaxQueueEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_QueueNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_QueueStatsNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_MaxShaperEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_ShaperNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoS_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoS_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoS_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoS_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoS_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoS_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoS_DefaultQueue(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoS_DefaultQueue(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoS_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoS_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoS_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoS_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoS_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoS_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoS_AvailableAppList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSClassification_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSClassification_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DHCPType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DHCPType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceIPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_ProtocolExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_ProtocolExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestPortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestPortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestPortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestPortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourcePort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourcePort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourcePortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourcePortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourcePortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourcePortExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestMACMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestMACExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_Ethertype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_Ethertype(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_EthertypeExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_EthertypeExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DSAP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DSAPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_LLCControl(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_LLCControl(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_LLCControlExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_LLCControlExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SNAPOUI(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SNAPOUI(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SNAPOUIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SNAPOUIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestVendorClassIDv6(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestVendorClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestVendorClassIDMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestClientIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestUserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestUserClassIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_SourceVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_SourceVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestVendorSpecificInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestVendorSpecificInfoExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestVendorSpecificInfoEnterprise(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DestVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DestVendorSpecificInfoSubOption(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_TCPACK(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_TCPACK(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_TCPACKExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_TCPACKExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_IPLengthMin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_IPLengthMin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_IPLengthMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_IPLengthMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_IPLengthExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_IPLengthExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DSCPCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DSCPCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DSCPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DSCPExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_EthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_EthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_EthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_EthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_InnerEthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_InnerEthernetPriorityCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_InnerEthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_InnerEthernetPriorityExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_EthernetDEICheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_EthernetDEICheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_EthernetDEIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_EthernetDEIExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_VLANIDCheck(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_VLANIDExclude(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_OutOfBandInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_OutOfBandInfo(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSClassification_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSClassification_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSApp_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSApp_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSApp_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSApp_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSApp_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSApp_ProtocolIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSApp_ProtocolIdentifier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSApp_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSApp_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSApp_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSApp_DefaultForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSApp_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSApp_DefaultTrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSApp_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSApp_DefaultPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSApp_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSApp_DefaultDSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSApp_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSApp_DefaultEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSApp_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSApp_DefaultInnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSFlow_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_TypeParameters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_TypeParameters(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_App(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_TrafficClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_Policer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_DSCPMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_EthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSFlow_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSFlow_InnerEthernetPriorityMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSPolicer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSPolicer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSPolicer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_CommittedRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSPolicer_CommittedRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_CommittedBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSPolicer_CommittedBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_ExcessBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSPolicer_ExcessBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_PeakRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSPolicer_PeakRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_PeakBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSPolicer_PeakBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_MeterType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSPolicer_MeterType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_PossibleMeterTypes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSPolicer_ConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSPolicer_ConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_PartialConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSPolicer_PartialConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_NonConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSPolicer_NonConformingAction(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSPolicer_TotalCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSPolicer_TotalCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSPolicer_ConformingCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSPolicer_ConformingCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSPolicer_PartiallyConformingCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSPolicer_PartiallyConformingCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSPolicer_NonConformingCountedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSPolicer_NonConformingCountedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSQueue_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSQueue_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_TrafficClasses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_TrafficClasses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_HardwareAssisted(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSQueue_BufferLength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSQueue_Weight(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_Weight(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_Precedence(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_Precedence(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_REDThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_REDThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_REDPercentage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_REDPercentage(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_DropAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_DropAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_SchedulerAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_SchedulerAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueue_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueue_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueueStats_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueueStats_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueueStats_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSQueueStats_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueueStats_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueueStats_Queue(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueueStats_Queue(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueueStats_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSQueueStats_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSQueueStats_OutputPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSQueueStats_OutputBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSQueueStats_DroppedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSQueueStats_DroppedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSQueueStats_QueueOccupancyPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSQueueStats_QueueOccupancyPercentage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSShaper_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSShaper_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSShaper_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_QoSShaper_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSShaper_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSShaper_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSShaper_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_QoSShaper_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_QoSShaper_ShapingBurstSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif //__QOS_H diff --git a/dmtree/tr181/routing.c b/dmtree/tr181/routing.c index cda4bcc3..04be703a 100644 --- a/dmtree/tr181/routing.c +++ b/dmtree/tr181/routing.c @@ -13,93 +13,12 @@ #include "dmentry.h" #include "routing.h" -/* *** Device.Routing. *** */ -DMOBJ tRoutingObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Router", &DMREAD, NULL, NULL, NULL, browseRouterInst, NULL, NULL, NULL, tRoutingRouterObj, tRoutingRouterParams, NULL, BBFDM_BOTH}, -{"RouteInformation", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tRoutingRouteInformationObj, tRoutingRouteInformationParams, NULL, BBFDM_BOTH}, -{0} -}; +#define PROC_ROUTE6 "/proc/net/ipv6_route" -DMLEAF tRoutingParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"RouterNumberOfEntries", &DMREAD, DMT_UNINT, get_router_nbr_entry, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.Routing.Router.{i}. *** */ -DMOBJ tRoutingRouterObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"IPv4Forwarding", &DMWRITE, add_ipv4forwarding, delete_ipv4forwarding, NULL, browseIPv4ForwardingInst, NULL, NULL, NULL, NULL, tRoutingRouterIPv4ForwardingParams, NULL, BBFDM_BOTH}, -{"IPv6Forwarding", &DMWRITE, add_ipv6Forwarding, delete_ipv6Forwarding, NULL, browseIPv6ForwardingInst, NULL, NULL, NULL, NULL, tRoutingRouterIPv6ForwardingParams, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF tRoutingRouterParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_RoutingRouter_Enable, set_RoutingRouter_Enable, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_RoutingRouter_Status, NULL, NULL, NULL, BBFDM_BOTH}, -{"Alias", &DMWRITE, DMT_STRING, get_RoutingRouter_Alias, set_RoutingRouter_Alias, NULL, NULL, BBFDM_BOTH}, -{"IPv4ForwardingNumberOfEntries", &DMREAD, DMT_UNINT, get_RoutingRouter_IPv4ForwardingNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, -{"IPv6ForwardingNumberOfEntries", &DMREAD, DMT_UNINT, get_RoutingRouter_IPv6ForwardingNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.Routing.Router.{i}.IPv4Forwarding.{i}. *** */ -DMLEAF tRoutingRouterIPv4ForwardingParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMRouting, DMT_BOOL, get_router_ipv4forwarding_enable, set_router_ipv4forwarding_enable, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_router_ipv4forwarding_status, NULL, NULL, NULL, BBFDM_BOTH}, -{"Alias", &DMWRITE, DMT_STRING, get_router_ipv4forwarding_alias, set_router_ipv4forwarding_alias, NULL, NULL, BBFDM_BOTH}, -{"StaticRoute", &DMREAD, DMT_BOOL, get_router_ipv4forwarding_static_route, NULL, NULL, NULL, BBFDM_BOTH}, -{"DestIPAddress", &DMRouting, DMT_STRING, get_router_ipv4forwarding_destip, set_router_ipv4forwarding_destip, NULL, NULL, BBFDM_BOTH}, -{"DestSubnetMask", &DMRouting, DMT_STRING, get_router_ipv4forwarding_destmask, set_router_ipv4forwarding_destmask, NULL, NULL, BBFDM_BOTH}, -{"ForwardingPolicy", &DMREAD, DMT_INT, get_router_ipv4forwarding_forwarding_policy, NULL, NULL, NULL, BBFDM_BOTH}, -{"GatewayIPAddress", &DMRouting, DMT_STRING, get_router_ipv4forwarding_gatewayip, set_router_ipv4forwarding_gatewayip, NULL, NULL, BBFDM_BOTH}, -{"Interface", &DMRouting, DMT_STRING, get_router_ipv4forwarding_interface_linker_parameter, set_router_ipv4forwarding_interface_linker_parameter, NULL, NULL, BBFDM_BOTH}, -{"Origin", &DMREAD, DMT_STRING, get_router_ipv4forwarding_origin, NULL, NULL, NULL, BBFDM_BOTH}, -{"ForwardingMetric", &DMRouting, DMT_INT, get_router_ipv4forwarding_metric, set_router_ipv4forwarding_metric, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.Routing.Router.{i}.IPv4Forwarding.{i}. *** */ -DMLEAF tRoutingRouterIPv6ForwardingParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMRouting, DMT_BOOL, get_RoutingRouterIPv6Forwarding_Enable, set_RoutingRouterIPv6Forwarding_Enable, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_RoutingRouterIPv6Forwarding_Status, NULL, NULL, NULL, BBFDM_BOTH}, -{"Alias", &DMWRITE, DMT_STRING, get_RoutingRouterIPv6Forwarding_Alias, set_RoutingRouterIPv6Forwarding_Alias, NULL, NULL, BBFDM_BOTH}, -{"DestIPPrefix", &DMRouting, DMT_STRING, get_RoutingRouterIPv6Forwarding_DestIPPrefix, set_RoutingRouterIPv6Forwarding_DestIPPrefix, NULL, NULL, BBFDM_BOTH}, -{"ForwardingPolicy", &DMRouting, DMT_INT, get_RoutingRouterIPv6Forwarding_ForwardingPolicy, set_RoutingRouterIPv6Forwarding_ForwardingPolicy, NULL, NULL, BBFDM_BOTH}, -{"NextHop", &DMRouting, DMT_STRING, get_RoutingRouterIPv6Forwarding_NextHop, set_RoutingRouterIPv6Forwarding_NextHop, NULL, NULL, BBFDM_BOTH}, -{"Interface", &DMRouting, DMT_STRING, get_RoutingRouterIPv6Forwarding_Interface, set_RoutingRouterIPv6Forwarding_Interface, NULL, NULL, BBFDM_BOTH}, -{"Origin", &DMREAD, DMT_STRING, get_RoutingRouterIPv6Forwarding_Origin, NULL, NULL, NULL, BBFDM_BOTH}, -{"ForwardingMetric", &DMRouting, DMT_INT, get_RoutingRouterIPv6Forwarding_ForwardingMetric, set_RoutingRouterIPv6Forwarding_ForwardingMetric, NULL, NULL, BBFDM_BOTH}, -{"ExpirationTime", &DMREAD, DMT_TIME, get_RoutingRouterIPv6Forwarding_ExpirationTime, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.Routing.RouteInformation. *** */ -DMOBJ tRoutingRouteInformationObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"InterfaceSetting", &DMREAD, NULL, NULL, NULL, browseRoutingRouteInformationInterfaceSettingInst, NULL, NULL, NULL, NULL, tRoutingRouteInformationInterfaceSettingParams, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF tRoutingRouteInformationParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_RoutingRouteInformation_Enable, set_RoutingRouteInformation_Enable, NULL, NULL, BBFDM_BOTH}, -{"InterfaceSettingNumberOfEntries", &DMREAD, DMT_UNINT, get_RoutingRouteInformation_InterfaceSettingNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.Routing.RouteInformation.InterfaceSetting.{i}. *** */ -DMLEAF tRoutingRouteInformationInterfaceSettingParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Status", &DMREAD, DMT_STRING, get_RoutingRouteInformationInterfaceSetting_Status, NULL, NULL, NULL, BBFDM_BOTH}, -{"Interface", &DMREAD, DMT_STRING, get_RoutingRouteInformationInterfaceSetting_Interface, NULL, NULL, NULL, BBFDM_BOTH}, -{"SourceRouter", &DMREAD, DMT_STRING, get_RoutingRouteInformationInterfaceSetting_SourceRouter, NULL, NULL, NULL, BBFDM_BOTH}, -{"RouteLifetime", &DMREAD, DMT_TIME, get_RoutingRouteInformationInterfaceSetting_RouteLifetime, NULL, NULL, NULL, BBFDM_BOTH}, -{0} +enum enum_route_type { + ROUTE_STATIC, + ROUTE_DYNAMIC, + ROUTE_DISABLED }; /******************************** @@ -505,19 +424,19 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN /************************************************************* * GET & SET PARAM **************************************************************/ -int get_router_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "1"; return 0; } -int get_RoutingRouter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "1"; return 0; } -int set_RoutingRouter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_RoutingRouter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -530,14 +449,14 @@ int set_RoutingRouter_Enable(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int get_RoutingRouter_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouter_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "Enabled"; return 0; } /*#Device.Routing.Router.{i}.IPv4ForwardingNumberOfEntries!UCI:network/route/*/ -int get_RoutingRouter_IPv4ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouter_IPv4ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s; int cnt = 0; @@ -557,7 +476,7 @@ int get_RoutingRouter_IPv4ForwardingNumberOfEntries(char *refparam, struct dmctx } /*#Device.Routing.Router.{i}.IPv6ForwardingNumberOfEntries!UCI:network/route6/*/ -int get_RoutingRouter_IPv6ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouter_IPv6ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s; int cnt = 0; @@ -573,7 +492,7 @@ int get_RoutingRouter_IPv6ForwardingNumberOfEntries(char *refparam, struct dmctx return 0; } -int get_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if(((struct routingfwdargs *)data)->type == ROUTE_DISABLED) *value = "0"; @@ -582,7 +501,7 @@ int get_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *da return 0; } -int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -608,7 +527,7 @@ int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *da return 0; } -int get_router_ipv4forwarding_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_ipv4forwarding_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if(((struct routingfwdargs *)data)->type == ROUTE_DISABLED) { *value = "Disabled"; @@ -622,7 +541,7 @@ int get_router_ipv4forwarding_status(char *refparam, struct dmctx *ctx, void *da } /*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.DestIPAddress!UCI:network/route,@i-1/target*/ -int get_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if (((struct routingfwdargs *)data)->routefwdsection != NULL) dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "target", value); @@ -631,7 +550,7 @@ int get_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *da return 0; } -int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -646,7 +565,7 @@ int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *da } /*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.DestSubnetMask!UCI:network/route,@i-1/netmask*/ -int get_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if (((struct routingfwdargs *)data)->routefwdsection != NULL) dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "netmask", value); @@ -655,7 +574,7 @@ int get_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void * return 0; } -int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -669,7 +588,7 @@ int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void * return 0; } -int get_router_ipv4forwarding_static_route(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_ipv4forwarding_static_route(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if (((struct routingfwdargs *)data)->type != ROUTE_DYNAMIC) *value = "1"; @@ -679,13 +598,13 @@ int get_router_ipv4forwarding_static_route(char *refparam, struct dmctx *ctx, vo return 0; } -int get_router_ipv4forwarding_forwarding_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_ipv4forwarding_forwarding_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "-1"; return 0; } -int get_router_ipv4forwarding_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_ipv4forwarding_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if (((struct routingfwdargs *)data)->type != ROUTE_DYNAMIC) *value = "Static"; @@ -693,7 +612,7 @@ int get_router_ipv4forwarding_origin(char *refparam, struct dmctx *ctx, void *da } /*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.GatewayIPAddress!UCI:network/route,@i-1/gateway*/ -int get_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if (((struct routingfwdargs *)data)->routefwdsection != NULL) dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "gateway", value); @@ -702,7 +621,7 @@ int get_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void return 0; } -int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -716,7 +635,7 @@ int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void return 0; } -int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker; @@ -730,7 +649,7 @@ int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct return 0; } -int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker; @@ -751,7 +670,7 @@ int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct } /*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.ForwardingMetric!UCI:network/route,@i-1/metric*/ -int get_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if (((struct routingfwdargs *)data)->routefwdsection != NULL) dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "metric", value); @@ -760,7 +679,7 @@ int get_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *da return 0; } -int set_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -774,13 +693,13 @@ int set_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *da return 0; } -int get_RoutingRouterIPv6Forwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouterIPv6Forwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "1"; return 0; } -int set_RoutingRouterIPv6Forwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_RoutingRouterIPv6Forwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -793,14 +712,14 @@ int set_RoutingRouterIPv6Forwarding_Enable(char *refparam, struct dmctx *ctx, vo return 0; } -int get_RoutingRouterIPv6Forwarding_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouterIPv6Forwarding_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "Enabled"; return 0; } /*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.DestIPPrefix!UCI:network/route,@i-1/target*/ -int get_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if (((struct routingfwdargs *)data)->routefwdsection != NULL) dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "target", value); @@ -809,7 +728,7 @@ int get_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *c return 0; } -int set_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -823,13 +742,13 @@ int set_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *c return 0; } -int get_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "-1"; return 0; } -int set_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -843,7 +762,7 @@ int set_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, struct dmct } /*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.NextHop!UCI:network/route,@i-1/gateway*/ -int get_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if (((struct routingfwdargs *)data)->routefwdsection != NULL) dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "gateway", value); @@ -852,7 +771,7 @@ int get_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, v return 0; } -int set_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -866,7 +785,7 @@ int set_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, v return 0; } -int get_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker; @@ -880,7 +799,7 @@ int get_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, return 0; } -int set_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker; @@ -900,7 +819,7 @@ int set_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, return 0; } -int get_RoutingRouterIPv6Forwarding_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouterIPv6Forwarding_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if (((struct routingfwdargs *)data)->type != ROUTE_DYNAMIC) *value = "Static"; @@ -908,7 +827,7 @@ int get_RoutingRouterIPv6Forwarding_Origin(char *refparam, struct dmctx *ctx, vo } /*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.ForwardingMetric!UCI:network/route,@i-1/metric*/ -int get_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { if (((struct routingfwdargs *)data)->routefwdsection != NULL) dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "metric", value); @@ -917,7 +836,7 @@ int get_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmct return 0; } -int set_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -931,19 +850,19 @@ int set_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmct return 0; } -int get_RoutingRouterIPv6Forwarding_ExpirationTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouterIPv6Forwarding_ExpirationTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "9999-12-31T23:59:59Z"; return 0; } -int get_RoutingRouteInformation_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouteInformation_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "1"; return 0; } -int set_RoutingRouteInformation_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_RoutingRouteInformation_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -956,7 +875,7 @@ int set_RoutingRouteInformation_Enable(char *refparam, struct dmctx *ctx, void * return 0; } -int get_RoutingRouteInformation_InterfaceSettingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouteInformation_InterfaceSettingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; json_object *res, *route_obj; @@ -982,7 +901,7 @@ int get_RoutingRouteInformation_InterfaceSettingNumberOfEntries(char *refparam, return 0; } -int get_RoutingRouteInformationInterfaceSetting_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouteInformationInterfaceSetting_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; char *target, *mask, *nexthop, *gateway, *ip_target, buf[64]; @@ -1003,7 +922,7 @@ int get_RoutingRouteInformationInterfaceSetting_Status(char *refparam, struct dm return 0; } -int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; char buf[512], dev[32], ipstr[INET6_ADDRSTRLEN + 8], gwstr[INET6_ADDRSTRLEN + 8]; @@ -1057,13 +976,13 @@ int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, struct return 0; } -int get_RoutingRouteInformationInterfaceSetting_SourceRouter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouteInformationInterfaceSetting_SourceRouter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = dmjson_get_value((struct json_object *)data, 1, "source"); return 0; } -int get_RoutingRouteInformationInterfaceSetting_RouteLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouteInformationInterfaceSetting_RouteLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char local_time[32] = {0}; char *valid = dmjson_get_value((struct json_object *)data, 1, "valid"); @@ -1077,13 +996,13 @@ int get_RoutingRouteInformationInterfaceSetting_RouteLifetime(char *refparam, st /************************************************************* * SET AND GET ALIAS FOR ROUTER OBJ **************************************************************/ -int get_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "router_alias", value); return 0; } -int set_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -1097,7 +1016,7 @@ int set_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int get_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *dmmap_section = NULL; @@ -1112,7 +1031,7 @@ int get_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *dat return 0; } -int set_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *dmmap_section = NULL; @@ -1135,7 +1054,7 @@ int set_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *dat return 0; } -int get_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *dmmap_section = NULL; @@ -1148,7 +1067,7 @@ int get_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, voi return 0; } -int set_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *dmmap_section = NULL; @@ -1169,7 +1088,7 @@ int set_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, voi return 0; } -char *get_routing_perm(char *refparam, struct dmctx *dmctx, void *data, char *instance) +static char *get_routing_perm(char *refparam, struct dmctx *dmctx, void *data, char *instance) { return ((struct routingfwdargs *)data)->permission; } @@ -1179,7 +1098,7 @@ struct dm_permession_s DMRouting = {"0", &get_routing_perm}; /************************************************************* * ADD DEL OBJ **************************************************************/ -int add_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +static int add_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *value, *v, instance[8]; struct uci_section *s = NULL; @@ -1199,7 +1118,7 @@ int add_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char **ins return 0; } -int delete_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +static int delete_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *dmmap_section = NULL; @@ -1219,7 +1138,7 @@ int delete_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char *i return 0; } -int add_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +static int add_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *value, *v, instance[8]; struct uci_section *s = NULL; @@ -1239,7 +1158,7 @@ int add_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char **ins return 0; } -int delete_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +static int delete_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *dmmap_section = NULL; @@ -1259,7 +1178,7 @@ int delete_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char *i /************************************************************* * SUB ENTRIES **************************************************************/ -int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s = NULL; char *r = NULL, *r_last = NULL; @@ -1274,7 +1193,7 @@ int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, } /*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.!UCI:network/route/dmmap_route_forwarding*/ -int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *iroute = NULL, *iroute_last = NULL; struct uci_section *ss = NULL; @@ -1311,7 +1230,7 @@ end: } /*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.!UCI:network/route6/dmmap_route_forwarding*/ -int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *iroute = NULL, *iroute_last = NULL; struct uci_section *ss = NULL; @@ -1339,7 +1258,7 @@ end: return 0; } -int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s = NULL; json_object *res, *route_obj; @@ -1366,3 +1285,92 @@ int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx, DMNOD } return 0; } + +/* *** Device.Routing. *** */ +DMOBJ tRoutingObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Router", &DMREAD, NULL, NULL, NULL, browseRouterInst, NULL, NULL, NULL, tRoutingRouterObj, tRoutingRouterParams, NULL, BBFDM_BOTH}, +{"RouteInformation", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tRoutingRouteInformationObj, tRoutingRouteInformationParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tRoutingParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"RouterNumberOfEntries", &DMREAD, DMT_UNINT, get_router_nbr_entry, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.Routing.Router.{i}. *** */ +DMOBJ tRoutingRouterObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"IPv4Forwarding", &DMWRITE, add_ipv4forwarding, delete_ipv4forwarding, NULL, browseIPv4ForwardingInst, NULL, NULL, NULL, NULL, tRoutingRouterIPv4ForwardingParams, NULL, BBFDM_BOTH}, +{"IPv6Forwarding", &DMWRITE, add_ipv6Forwarding, delete_ipv6Forwarding, NULL, browseIPv6ForwardingInst, NULL, NULL, NULL, NULL, tRoutingRouterIPv6ForwardingParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tRoutingRouterParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_RoutingRouter_Enable, set_RoutingRouter_Enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_RoutingRouter_Status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Alias", &DMWRITE, DMT_STRING, get_RoutingRouter_Alias, set_RoutingRouter_Alias, NULL, NULL, BBFDM_BOTH}, +{"IPv4ForwardingNumberOfEntries", &DMREAD, DMT_UNINT, get_RoutingRouter_IPv4ForwardingNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{"IPv6ForwardingNumberOfEntries", &DMREAD, DMT_UNINT, get_RoutingRouter_IPv6ForwardingNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.Routing.Router.{i}.IPv4Forwarding.{i}. *** */ +DMLEAF tRoutingRouterIPv4ForwardingParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMRouting, DMT_BOOL, get_router_ipv4forwarding_enable, set_router_ipv4forwarding_enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_router_ipv4forwarding_status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Alias", &DMWRITE, DMT_STRING, get_router_ipv4forwarding_alias, set_router_ipv4forwarding_alias, NULL, NULL, BBFDM_BOTH}, +{"StaticRoute", &DMREAD, DMT_BOOL, get_router_ipv4forwarding_static_route, NULL, NULL, NULL, BBFDM_BOTH}, +{"DestIPAddress", &DMRouting, DMT_STRING, get_router_ipv4forwarding_destip, set_router_ipv4forwarding_destip, NULL, NULL, BBFDM_BOTH}, +{"DestSubnetMask", &DMRouting, DMT_STRING, get_router_ipv4forwarding_destmask, set_router_ipv4forwarding_destmask, NULL, NULL, BBFDM_BOTH}, +{"ForwardingPolicy", &DMREAD, DMT_INT, get_router_ipv4forwarding_forwarding_policy, NULL, NULL, NULL, BBFDM_BOTH}, +{"GatewayIPAddress", &DMRouting, DMT_STRING, get_router_ipv4forwarding_gatewayip, set_router_ipv4forwarding_gatewayip, NULL, NULL, BBFDM_BOTH}, +{"Interface", &DMRouting, DMT_STRING, get_router_ipv4forwarding_interface_linker_parameter, set_router_ipv4forwarding_interface_linker_parameter, NULL, NULL, BBFDM_BOTH}, +{"Origin", &DMREAD, DMT_STRING, get_router_ipv4forwarding_origin, NULL, NULL, NULL, BBFDM_BOTH}, +{"ForwardingMetric", &DMRouting, DMT_INT, get_router_ipv4forwarding_metric, set_router_ipv4forwarding_metric, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.Routing.Router.{i}.IPv4Forwarding.{i}. *** */ +DMLEAF tRoutingRouterIPv6ForwardingParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMRouting, DMT_BOOL, get_RoutingRouterIPv6Forwarding_Enable, set_RoutingRouterIPv6Forwarding_Enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_RoutingRouterIPv6Forwarding_Status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Alias", &DMWRITE, DMT_STRING, get_RoutingRouterIPv6Forwarding_Alias, set_RoutingRouterIPv6Forwarding_Alias, NULL, NULL, BBFDM_BOTH}, +{"DestIPPrefix", &DMRouting, DMT_STRING, get_RoutingRouterIPv6Forwarding_DestIPPrefix, set_RoutingRouterIPv6Forwarding_DestIPPrefix, NULL, NULL, BBFDM_BOTH}, +{"ForwardingPolicy", &DMRouting, DMT_INT, get_RoutingRouterIPv6Forwarding_ForwardingPolicy, set_RoutingRouterIPv6Forwarding_ForwardingPolicy, NULL, NULL, BBFDM_BOTH}, +{"NextHop", &DMRouting, DMT_STRING, get_RoutingRouterIPv6Forwarding_NextHop, set_RoutingRouterIPv6Forwarding_NextHop, NULL, NULL, BBFDM_BOTH}, +{"Interface", &DMRouting, DMT_STRING, get_RoutingRouterIPv6Forwarding_Interface, set_RoutingRouterIPv6Forwarding_Interface, NULL, NULL, BBFDM_BOTH}, +{"Origin", &DMREAD, DMT_STRING, get_RoutingRouterIPv6Forwarding_Origin, NULL, NULL, NULL, BBFDM_BOTH}, +{"ForwardingMetric", &DMRouting, DMT_INT, get_RoutingRouterIPv6Forwarding_ForwardingMetric, set_RoutingRouterIPv6Forwarding_ForwardingMetric, NULL, NULL, BBFDM_BOTH}, +{"ExpirationTime", &DMREAD, DMT_TIME, get_RoutingRouterIPv6Forwarding_ExpirationTime, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.Routing.RouteInformation. *** */ +DMOBJ tRoutingRouteInformationObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"InterfaceSetting", &DMREAD, NULL, NULL, NULL, browseRoutingRouteInformationInterfaceSettingInst, NULL, NULL, NULL, NULL, tRoutingRouteInformationInterfaceSettingParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tRoutingRouteInformationParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_RoutingRouteInformation_Enable, set_RoutingRouteInformation_Enable, NULL, NULL, BBFDM_BOTH}, +{"InterfaceSettingNumberOfEntries", &DMREAD, DMT_UNINT, get_RoutingRouteInformation_InterfaceSettingNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.Routing.RouteInformation.InterfaceSetting.{i}. *** */ +DMLEAF tRoutingRouteInformationInterfaceSettingParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Status", &DMREAD, DMT_STRING, get_RoutingRouteInformationInterfaceSetting_Status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Interface", &DMREAD, DMT_STRING, get_RoutingRouteInformationInterfaceSetting_Interface, NULL, NULL, NULL, BBFDM_BOTH}, +{"SourceRouter", &DMREAD, DMT_STRING, get_RoutingRouteInformationInterfaceSetting_SourceRouter, NULL, NULL, NULL, BBFDM_BOTH}, +{"RouteLifetime", &DMREAD, DMT_TIME, get_RoutingRouteInformationInterfaceSetting_RouteLifetime, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/routing.h b/dmtree/tr181/routing.h index 2f2363cf..366fca55 100644 --- a/dmtree/tr181/routing.h +++ b/dmtree/tr181/routing.h @@ -15,15 +15,8 @@ #include -#define PROC_ROUTE6 "/proc/net/ipv6_route" extern struct dm_permession_s DMRouting; -enum enum_route_type { - ROUTE_STATIC, - ROUTE_DYNAMIC, - ROUTE_DISABLED -}; - extern DMOBJ tRoutingObj[]; extern DMLEAF tRoutingParams[]; extern DMOBJ tRoutingRouterObj[]; @@ -34,68 +27,4 @@ extern DMOBJ tRoutingRouteInformationObj[]; extern DMLEAF tRoutingRouteInformationParams[]; extern DMLEAF tRoutingRouteInformationInterfaceSettingParams[]; -int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int add_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int add_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delete_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_router_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_RoutingRouter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_RoutingRouter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_RoutingRouter_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_RoutingRouter_IPv4ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_RoutingRouter_IPv6ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_router_ipv4forwarding_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_router_ipv4forwarding_static_route(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_router_ipv4forwarding_forwarding_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_router_ipv4forwarding_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_RoutingRouterIPv6Forwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_RoutingRouterIPv6Forwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_RoutingRouterIPv6Forwarding_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_RoutingRouterIPv6Forwarding_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_RoutingRouterIPv6Forwarding_ExpirationTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_RoutingRouteInformation_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_RoutingRouteInformation_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_RoutingRouteInformation_InterfaceSettingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_RoutingRouteInformationInterfaceSetting_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_RoutingRouteInformationInterfaceSetting_SourceRouter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_RoutingRouteInformationInterfaceSetting_RouteLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - #endif diff --git a/dmtree/tr181/security.c b/dmtree/tr181/security.c index 51629953..708f20b2 100644 --- a/dmtree/tr181/security.c +++ b/dmtree/tr181/security.c @@ -10,33 +10,18 @@ #include "security.h" -/* *** Device.Security. *** */ -DMOBJ tSecurityObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Certificate", &DMREAD, NULL, NULL, NULL, browseSecurityCertificateInst, NULL, NULL, NULL, NULL, tSecurityCertificateParams, NULL, BBFDM_BOTH}, -{0} +#define DATE_LEN 128 + +struct certificate_profile { + char *path; +#ifdef LOPENSSL + X509 *openssl_cert; +#elif LMBEDTLS + mbedtls_x509_crt mbdtls_cert; +#endif + struct uci_section *dmmap_sect; }; -DMLEAF tSecurityParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"CertificateNumberOfEntries", &DMREAD, DMT_UNINT, get_Security_CertificateNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.Security.Certificate.{i}. *** */ -DMLEAF tSecurityCertificateParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -//{"Enable", &DMWRITE, DMT_BOOL, get_SecurityCertificate_Enable, set_SecurityCertificate_Enable, NULL, NULL, BBFDM_BOTH}, -{"LastModif", &DMREAD, DMT_TIME, get_SecurityCertificate_LastModif, NULL, NULL, NULL, BBFDM_BOTH}, -{"SerialNumber", &DMREAD, DMT_STRING, get_SecurityCertificate_SerialNumber, NULL, NULL, NULL, BBFDM_BOTH}, -{"Issuer", &DMREAD, DMT_STRING, get_SecurityCertificate_Issuer, NULL, NULL, NULL, BBFDM_BOTH}, -{"NotBefore", &DMREAD, DMT_TIME, get_SecurityCertificate_NotBefore, NULL, NULL, NULL, BBFDM_BOTH}, -{"NotAfter", &DMREAD, DMT_TIME, get_SecurityCertificate_NotAfter, NULL, NULL, NULL, BBFDM_BOTH}, -{"Subject", &DMREAD, DMT_STRING, get_SecurityCertificate_Subject, NULL, NULL, NULL, BBFDM_BOTH}, -//{"SubjectAlt", &DMREAD, DMT_STRING, get_SecurityCertificate_SubjectAlt, NULL, NULL, NULL, BBFDM_BOTH}, -{"SignatureAlgorithm", &DMREAD, DMT_STRING, get_SecurityCertificate_SignatureAlgorithm, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; /************************************************************ * Init function *************************************************************/ @@ -58,7 +43,7 @@ struct uci_section *dmsect, struct certificate_profile *certprofile) } #ifdef LOPENSSL -int convert_ASN1TIME(ASN1_TIME *t, char* buf, size_t len) +static int convert_ASN1TIME(ASN1_TIME *t, char* buf, size_t len) { int rc; BIO *b = BIO_new(BIO_s_mem()); @@ -76,7 +61,7 @@ int convert_ASN1TIME(ASN1_TIME *t, char* buf, size_t len) return EXIT_SUCCESS; } -char *get_certificate_sig_alg(int sig_nid) +static char *get_certificate_sig_alg(int sig_nid) { switch(sig_nid) { case NID_sha256WithRSAEncryption: @@ -132,7 +117,7 @@ char *get_certificate_sig_alg(int sig_nid) } } #elif LMBEDTLS -char *get_certificate_md(mbedtls_md_type_t sig_md) +static char *get_certificate_md(mbedtls_md_type_t sig_md) { switch(sig_md) { case MBEDTLS_MD_MD2: @@ -159,7 +144,7 @@ char *get_certificate_md(mbedtls_md_type_t sig_md) return ""; } -char *get_certificate_pk(mbedtls_pk_type_t sig_pk) +static char *get_certificate_pk(mbedtls_pk_type_t sig_pk) { switch(sig_pk) { case MBEDTLS_PK_RSA: @@ -185,7 +170,7 @@ char *get_certificate_pk(mbedtls_pk_type_t sig_pk) /************************************************************* * ENTRY METHOD **************************************************************/ -int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { int length, i; char **certifcates_paths = NULL; @@ -241,7 +226,7 @@ int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_node, void /************************************************************* * GET & SET PARAM **************************************************************/ -int get_Security_CertificateNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_Security_CertificateNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int length, i; char **certifcates_paths = NULL; @@ -276,13 +261,13 @@ int get_Security_CertificateNumberOfEntries(char *refparam, struct dmctx *ctx, v return 0; } -int get_SecurityCertificate_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_SecurityCertificate_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { //TODO return 0; } -int set_SecurityCertificate_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_SecurityCertificate_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -296,7 +281,7 @@ int set_SecurityCertificate_Enable(char *refparam, struct dmctx *ctx, void *data return 0; } -int get_SecurityCertificate_LastModif(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_SecurityCertificate_LastModif(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct certificate_profile *cert_profile = (struct certificate_profile*)data; struct stat b; @@ -307,7 +292,7 @@ int get_SecurityCertificate_LastModif(char *refparam, struct dmctx *ctx, void *d return 0; } -int get_SecurityCertificate_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_SecurityCertificate_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct certificate_profile *cert_profile = (struct certificate_profile*)data; *value = ""; @@ -320,7 +305,7 @@ int get_SecurityCertificate_SerialNumber(char *refparam, struct dmctx *ctx, void return 0; } -int get_SecurityCertificate_Issuer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_SecurityCertificate_Issuer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct certificate_profile *cert_profile = (struct certificate_profile*)data; *value = ""; @@ -340,7 +325,7 @@ int get_SecurityCertificate_Issuer(char *refparam, struct dmctx *ctx, void *data return 0; } -int get_SecurityCertificate_NotBefore(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_SecurityCertificate_NotBefore(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct certificate_profile *cert_profile = (struct certificate_profile*)data; *value = ""; @@ -355,7 +340,7 @@ int get_SecurityCertificate_NotBefore(char *refparam, struct dmctx *ctx, void *d return 0; } -int get_SecurityCertificate_NotAfter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_SecurityCertificate_NotAfter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct certificate_profile *cert_profile = (struct certificate_profile*)data; *value = ""; @@ -370,7 +355,7 @@ int get_SecurityCertificate_NotAfter(char *refparam, struct dmctx *ctx, void *da return 0; } -int get_SecurityCertificate_Subject(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_SecurityCertificate_Subject(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct certificate_profile *cert_profile = (struct certificate_profile*)data; *value = ""; @@ -390,13 +375,13 @@ int get_SecurityCertificate_Subject(char *refparam, struct dmctx *ctx, void *dat return 0; } -int get_SecurityCertificate_SubjectAlt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_SecurityCertificate_SubjectAlt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { //TODO return 0; } -int get_SecurityCertificate_SignatureAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_SecurityCertificate_SignatureAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct certificate_profile *cert_profile = (struct certificate_profile*)data; *value = ""; @@ -408,3 +393,30 @@ int get_SecurityCertificate_SignatureAlgorithm(char *refparam, struct dmctx *ctx return 0; } +/* *** Device.Security. *** */ +DMOBJ tSecurityObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"Certificate", &DMREAD, NULL, NULL, NULL, browseSecurityCertificateInst, NULL, NULL, NULL, NULL, tSecurityCertificateParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tSecurityParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"CertificateNumberOfEntries", &DMREAD, DMT_UNINT, get_Security_CertificateNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.Security.Certificate.{i}. *** */ +DMLEAF tSecurityCertificateParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +//{"Enable", &DMWRITE, DMT_BOOL, get_SecurityCertificate_Enable, set_SecurityCertificate_Enable, NULL, NULL, BBFDM_BOTH}, +{"LastModif", &DMREAD, DMT_TIME, get_SecurityCertificate_LastModif, NULL, NULL, NULL, BBFDM_BOTH}, +{"SerialNumber", &DMREAD, DMT_STRING, get_SecurityCertificate_SerialNumber, NULL, NULL, NULL, BBFDM_BOTH}, +{"Issuer", &DMREAD, DMT_STRING, get_SecurityCertificate_Issuer, NULL, NULL, NULL, BBFDM_BOTH}, +{"NotBefore", &DMREAD, DMT_TIME, get_SecurityCertificate_NotBefore, NULL, NULL, NULL, BBFDM_BOTH}, +{"NotAfter", &DMREAD, DMT_TIME, get_SecurityCertificate_NotAfter, NULL, NULL, NULL, BBFDM_BOTH}, +{"Subject", &DMREAD, DMT_STRING, get_SecurityCertificate_Subject, NULL, NULL, NULL, BBFDM_BOTH}, +//{"SubjectAlt", &DMREAD, DMT_STRING, get_SecurityCertificate_SubjectAlt, NULL, NULL, NULL, BBFDM_BOTH}, +{"SignatureAlgorithm", &DMREAD, DMT_STRING, get_SecurityCertificate_SignatureAlgorithm, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/security.h b/dmtree/tr181/security.h index bdbd69de..4ecde434 100644 --- a/dmtree/tr181/security.h +++ b/dmtree/tr181/security.h @@ -22,34 +22,9 @@ #include #endif -#define DATE_LEN 128 - -struct certificate_profile { - char *path; -#ifdef LOPENSSL - X509 *openssl_cert; -#elif LMBEDTLS - mbedtls_x509_crt mbdtls_cert; -#endif - struct uci_section *dmmap_sect; -}; - extern DMOBJ tSecurityObj[]; extern DMLEAF tSecurityParams[]; extern DMLEAF tSecurityCertificateParams[]; -int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int get_Security_CertificateNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_SecurityCertificate_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_SecurityCertificate_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_SecurityCertificate_LastModif(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_SecurityCertificate_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_SecurityCertificate_Issuer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_SecurityCertificate_NotBefore(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_SecurityCertificate_NotAfter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_SecurityCertificate_Subject(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_SecurityCertificate_SubjectAlt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_SecurityCertificate_SignatureAlgorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); #endif //__SECURITY_H diff --git a/dmtree/tr181/times.c b/dmtree/tr181/times.c index b83cebda..820085b6 100644 --- a/dmtree/tr181/times.c +++ b/dmtree/tr181/times.c @@ -12,24 +12,7 @@ #include "dmentry.h" #include "times.h" -/* *** Device.Time. *** */ -DMLEAF tTimeParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_time_enable, set_time_enable, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_time_status, NULL, NULL, NULL, BBFDM_BOTH}, -{"NTPServer1", &DMWRITE, DMT_STRING, get_time_ntpserver1, set_time_ntpserver1, NULL, NULL, BBFDM_BOTH}, -{"NTPServer2", &DMWRITE, DMT_STRING, get_time_ntpserver2, set_time_ntpserver2, NULL, NULL, BBFDM_BOTH}, -{"NTPServer3", &DMWRITE, DMT_STRING, get_time_ntpserver3, set_time_ntpserver3, NULL, NULL, BBFDM_BOTH}, -{"NTPServer4", &DMWRITE, DMT_STRING, get_time_ntpserver4, set_time_ntpserver4, NULL, NULL, BBFDM_BOTH}, -{"NTPServer5", &DMWRITE, DMT_STRING, get_time_ntpserver5, set_time_ntpserver5, NULL, NULL, BBFDM_BOTH}, -{"CurrentLocalTime", &DMREAD, DMT_TIME, get_time_CurrentLocalTime, NULL, NULL, NULL, BBFDM_BOTH}, -{"LocalTimeZone", &DMWRITE, DMT_STRING, get_time_LocalTimeZone, set_time_LocalTimeZone, NULL, NULL, BBFDM_BOTH}, -{CUSTOM_PREFIX"LocalTimeZoneOlson", &DMREAD, DMT_STRING, get_local_time_zone_olson, NULL, NULL, NULL, BBFDM_BOTH}, -{CUSTOM_PREFIX"SourceInterface", &DMWRITE, DMT_STRING, get_time_source_interface, set_time_source_interface, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -int get_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *path = "/etc/rc.d/*ntpd"; @@ -40,7 +23,7 @@ int get_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instanc return 0; } -int set_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; pid_t pid; @@ -70,7 +53,7 @@ int set_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instanc return 0; } -int get_time_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_time_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *path = "/etc/rc.d/*ntpd"; @@ -81,19 +64,19 @@ int get_time_status(char *refparam, struct dmctx *ctx, void *data, char *instanc return 0; } -int get_time_CurrentLocalTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_time_CurrentLocalTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return dm_time_format(time(NULL), value); } /*#Device.Time.LocalTimeZone!UCI:system/system,@system[0]/timezone*/ -int get_time_LocalTimeZone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_time_LocalTimeZone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("system", "@system[0]", "timezone", value); return 0; } -int set_time_LocalTimeZone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_time_LocalTimeZone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -107,13 +90,13 @@ int set_time_LocalTimeZone(char *refparam, struct dmctx *ctx, void *data, char * return 0; } -int get_local_time_zone_olson(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_local_time_zone_olson(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("system", "@system[0]", "zonename", value); return 0; } -int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value, int index) +static int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value, int index) { bool found = 0; int element = 0; @@ -141,7 +124,7 @@ int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value, int inde return 0; } -int get_time_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_time_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *iface = NULL, *interface = NULL; *value = ""; @@ -155,32 +138,32 @@ int get_time_source_interface(char *refparam, struct dmctx *ctx, void *data, cha return 0; } -int get_time_ntpserver1(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_time_ntpserver1(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_time_ntpserver(refparam, ctx, value, 1); } -int get_time_ntpserver2(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_time_ntpserver2(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_time_ntpserver(refparam, ctx, value, 2); } -int get_time_ntpserver3(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_time_ntpserver3(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_time_ntpserver(refparam, ctx, value, 3); } -int get_time_ntpserver4(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_time_ntpserver4(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_time_ntpserver(refparam, ctx, value, 4); } -int get_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_time_ntpserver(refparam, ctx, value, 5); } -int set_time_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_time_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *iface= NULL; switch (action) { @@ -197,7 +180,7 @@ int set_time_source_interface(char *refparam, struct dmctx *ctx, void *data, cha return 0; } -int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *value, int index) +static int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *value, int index) { struct uci_list *v; struct uci_element *e; @@ -240,27 +223,44 @@ int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *valu return 0; } -int set_time_ntpserver1(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_time_ntpserver1(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { return set_time_ntpserver(refparam, ctx, action, value, 1); } -int set_time_ntpserver2(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_time_ntpserver2(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { return set_time_ntpserver(refparam, ctx, action, value, 2); } -int set_time_ntpserver3(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_time_ntpserver3(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { return set_time_ntpserver(refparam, ctx, action, value, 3); } -int set_time_ntpserver4(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_time_ntpserver4(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { return set_time_ntpserver(refparam, ctx, action, value, 4); } -int set_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { return set_time_ntpserver(refparam, ctx, action, value, 5); } + +/* *** Device.Time. *** */ +DMLEAF tTimeParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_time_enable, set_time_enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_time_status, NULL, NULL, NULL, BBFDM_BOTH}, +{"NTPServer1", &DMWRITE, DMT_STRING, get_time_ntpserver1, set_time_ntpserver1, NULL, NULL, BBFDM_BOTH}, +{"NTPServer2", &DMWRITE, DMT_STRING, get_time_ntpserver2, set_time_ntpserver2, NULL, NULL, BBFDM_BOTH}, +{"NTPServer3", &DMWRITE, DMT_STRING, get_time_ntpserver3, set_time_ntpserver3, NULL, NULL, BBFDM_BOTH}, +{"NTPServer4", &DMWRITE, DMT_STRING, get_time_ntpserver4, set_time_ntpserver4, NULL, NULL, BBFDM_BOTH}, +{"NTPServer5", &DMWRITE, DMT_STRING, get_time_ntpserver5, set_time_ntpserver5, NULL, NULL, BBFDM_BOTH}, +{"CurrentLocalTime", &DMREAD, DMT_TIME, get_time_CurrentLocalTime, NULL, NULL, NULL, BBFDM_BOTH}, +{"LocalTimeZone", &DMWRITE, DMT_STRING, get_time_LocalTimeZone, set_time_LocalTimeZone, NULL, NULL, BBFDM_BOTH}, +{CUSTOM_PREFIX"LocalTimeZoneOlson", &DMREAD, DMT_STRING, get_local_time_zone_olson, NULL, NULL, NULL, BBFDM_BOTH}, +{CUSTOM_PREFIX"SourceInterface", &DMWRITE, DMT_STRING, get_time_source_interface, set_time_source_interface, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/times.h b/dmtree/tr181/times.h index cae190be..3d05d56a 100644 --- a/dmtree/tr181/times.h +++ b/dmtree/tr181/times.h @@ -16,25 +16,4 @@ extern DMLEAF tTimeParams[]; -int get_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_ntpserver1(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_ntpserver2(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_ntpserver3(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_ntpserver4(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_CurrentLocalTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_LocalTimeZone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_time_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_local_time_zone_olson(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_time_ntpserver1(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_time_ntpserver2(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_time_ntpserver3(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_time_ntpserver4(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_time_LocalTimeZone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_time_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/upnp.c b/dmtree/tr181/upnp.c index 2336b7ee..c44220b0 100644 --- a/dmtree/tr181/upnp.c +++ b/dmtree/tr181/upnp.c @@ -12,6 +12,1144 @@ #include "dmentry.h" #include "upnp.h" +struct upnpdiscovery { + char *st; + char *usn; + char *uuid; + char *urn; + char *descurl; + struct uci_section *dmmap_sect; +}; + +struct upnp_device_inst { + char *device_type; + char *friendly_name; + char *manufacturer; + char *manufacturer_url; + char *model_description; + char *model_name; + char *model_number; + char *model_url; + char *serial_number; + char *udn; + char *uuid; + char *preentation_url; + char *parentudn; + char *upc; + struct uci_section *dmmap_sect; +}; + +struct upnp_service_inst { + char *parentudn; + char *serviceid; + char *servicetype; + char *scpdurl; + char *controlurl; + char *eventsuburl; + struct uci_section *dmmap_sect; +}; + +struct upnp_description_file_info { + char *desc_url; + struct uci_section *dmmap_sect; +}; + +/************************************************************************** +* LINKER +***************************************************************************/ +static int get_root_device_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct upnpdiscovery *)data)->uuid) { + dmasprintf(linker, "%s", ((struct upnpdiscovery *)data)->uuid); + return 0; + } + *linker = "" ; + return 0; +} + +static int get_device_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct upnpdiscovery *)data)->uuid){ + dmasprintf(linker, "%s", ((struct upnpdiscovery *)data)->uuid); + return 0; + } + *linker = "" ; + return 0; +} + +static int get_device_instance_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct upnp_device_inst *)data)->udn){ + dmasprintf(linker, "%s", ((struct upnp_device_inst *)data)->udn); + return 0; + } + *linker = "" ; + return 0; +} + +static int get_service_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct upnpdiscovery *)data)->usn){ + dmasprintf(linker, "%s", ((struct upnpdiscovery *)data)->usn); + return 0; + } + *linker = "" ; + return 0; +} + +/************************************************************* +* ENTRY METHOD +**************************************************************/ +static int browseUPnPDiscoveryRootDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *devices = NULL, *device = NULL; + struct upnpdiscovery upnp_dev = {}; + char *descurl = NULL, *st = NULL, *usn = NULL, *is_root_device = NULL, *instance = NULL, *instnbr = NULL, *v = NULL; + char **stparams = NULL, **uuid, **urn; + int i; + size_t length; + struct uci_section* dmmap_sect= NULL; + + dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + json_object_object_get_ex(res, "devices", &devices); + if (devices == NULL) + return 0; + size_t nbre_devices = json_object_array_length(devices); + + if (nbre_devices > 0) { + check_create_dmmap_package("dmmap_upnp"); + for (i = 0; i < nbre_devices; i++) { + device = json_object_array_get_idx(devices, i); + is_root_device = dmjson_get_value(device, 1, "is_root_device"); + if(strcmp(is_root_device, "0") == 0) + continue; + descurl = dmjson_get_value(device, 1, "descurl"); + st = dmjson_get_value(device, 1, "st"); + usn = dmjson_get_value(device, 1, "usn"); + stparams = strsplit_by_str(usn, "::"); + uuid = strsplit(stparams[0], ":", &length); + urn = strsplit(stparams[1], ":", &length); + dmasprintf(&upnp_dev.descurl, "%s", descurl); + dmasprintf(&upnp_dev.st, "%s", st); + dmasprintf(&upnp_dev.usn, "%s", usn); + dmasprintf(&upnp_dev.uuid, "%s", uuid[1]); + dmasprintf(&upnp_dev.urn, "%s", urn[1]); + if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_root_device", "uuid", uuid[1])) == NULL) { + dmuci_add_section_bbfdm("dmmap_upnp", "upnp_root_device", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "uuid", uuid[1]); + } + upnp_dev.dmmap_sect = dmmap_sect; + + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_root_device_instance", "upnp_root_device_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev, instance) == DM_STOP) + return 0; + } + } + return 0; +} + +static int browseUPnPDiscoveryDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *devices = NULL, *device = NULL; + struct upnpdiscovery upnp_dev = {}; + char *descurl = NULL, *st = NULL, *usn = NULL, *instance = NULL, *instnbr = NULL, *v = NULL; + char **stparams= NULL, **uuid, **urn; + int i; + size_t lengthuuid, lengthurn; + struct uci_section* dmmap_sect= NULL; + + dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + json_object_object_get_ex(res, "devices", &devices); + if (devices == NULL) + return 0; + size_t nbre_devices = json_object_array_length(devices); + + if (nbre_devices > 0) { + check_create_dmmap_package("dmmap_upnp"); + for(i=0; i0?uuid[1]:""); + dmasprintf(&upnp_dev.urn, "%s", lengthurn>0?urn[1]:""); + if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_device", "uuid", uuid[1])) == NULL) { + dmuci_add_section_bbfdm("dmmap_upnp", "upnp_device", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "uuid", uuid[1]); + } + upnp_dev.dmmap_sect = dmmap_sect; + + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_evice_instance", "upnp_device_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev, instance) == DM_STOP) + return 0; + } + } + return 0; +} + +static int browseUPnPDiscoveryServiceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *services = NULL, *service = NULL; + struct upnpdiscovery upnp_dev = {}; + char *descurl = NULL, *st = NULL, *usn = NULL, *instance = NULL, *instnbr = NULL, *v = NULL; + char **stparams = NULL, **uuid, **urn; + int i; + size_t lengthuuid, lengthurn; + struct uci_section* dmmap_sect = NULL; + + dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + json_object_object_get_ex(res, "services", &services); + if (services == NULL) + return 0; + size_t nbre_services = json_object_array_length(services); + + if (nbre_services > 0) { + check_create_dmmap_package("dmmap_upnp"); + for (i = 0; i < nbre_services; i++){ + service = json_object_array_get_idx(services, i); + descurl = dmjson_get_value(service, 1, "descurl"); + st = dmjson_get_value(service, 1, "st"); + usn = dmjson_get_value(service, 1, "usn"); + stparams = strsplit_by_str(usn, "::"); + uuid = strsplit(stparams[0], ":", &lengthuuid); + urn = strsplit(stparams[1], ":", &lengthurn); + dmasprintf(&upnp_dev.descurl, "%s", descurl?descurl:""); + dmasprintf(&upnp_dev.st, "%s", st?st:""); + dmasprintf(&upnp_dev.usn, "%s", usn?usn:""); + dmasprintf(&upnp_dev.uuid, "%s", lengthuuid>0?uuid[1]:""); + dmasprintf(&upnp_dev.urn, "%s", lengthurn>0?urn[1]:""); + if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_service", "usn", usn)) == NULL) { + dmuci_add_section_bbfdm("dmmap_upnp", "upnp_service", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "usn", usn); + } + upnp_dev.dmmap_sect = dmmap_sect; + + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_service_instance", "upnp_service_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev, instance) == DM_STOP) + return 0; + } + } + return 0; +} + +static int browseUPnPDescriptionDeviceDescriptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *descriptions = NULL, *description = NULL; + struct upnp_description_file_info upnp_desc= {}; + char *descurl = NULL, *instance = NULL, *instnbr = NULL, *v = NULL; + int i; + struct uci_section* dmmap_sect = NULL; + + dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + json_object_object_get_ex(res, "descriptions", &descriptions); + if (descriptions == NULL) + return 0; + size_t nbre_descriptions = json_object_array_length(descriptions); + + if (nbre_descriptions > 0) { + check_create_dmmap_package("dmmap_upnp"); + for (i = 0; i < nbre_descriptions; i++) { + description = json_object_array_get_idx(descriptions, i); + descurl = dmjson_get_value(description, 1, "descurl"); + dmasprintf(&upnp_desc.desc_url, "%s", descurl?descurl:""); + if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_description", "descurl", descurl)) == NULL) { + dmuci_add_section_bbfdm("dmmap_upnp", "upnp_description", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "descurl", descurl); + } + upnp_desc.dmmap_sect = dmmap_sect; + + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_service_instance", "upnp_service_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_desc, instance) == DM_STOP) + return 0; + } + } + return 0; +} + +static int browseUPnPDescriptionDeviceInstanceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *devices_instances = NULL, *device_inst = NULL; + struct upnp_device_inst upnp_dev_inst = {}; + char *instance = NULL, *instnbr = NULL, *v; + int i; + struct uci_section* dmmap_sect = NULL; + + dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + json_object_object_get_ex(res, "devicesinstances", &devices_instances); + if (devices_instances == NULL) + return 0; + size_t nbre_devices_inst = json_object_array_length(devices_instances); + + if (nbre_devices_inst > 0) { + check_create_dmmap_package("dmmap_upnp"); + for (i = 0; i < nbre_devices_inst; i++){ + device_inst = json_object_array_get_idx(devices_instances, i); + dmasprintf(&upnp_dev_inst.parentudn, "%s", dmjson_get_value(device_inst, 1, "parent_dev")); + dmasprintf(&upnp_dev_inst.device_type, "%s", dmjson_get_value(device_inst, 1, "deviceType")); + dmasprintf(&upnp_dev_inst.friendly_name, "%s", dmjson_get_value(device_inst, 1, "friendlyName")); + dmasprintf(&upnp_dev_inst.manufacturer, "%s", dmjson_get_value(device_inst, 1, "manufacturer")); + dmasprintf(&upnp_dev_inst.manufacturer_url, "%s", dmjson_get_value(device_inst, 1, "manufacturerURL")); + dmasprintf(&upnp_dev_inst.model_description, "%s", dmjson_get_value(device_inst, 1, "modelDescription")); + dmasprintf(&upnp_dev_inst.model_name, "%s", dmjson_get_value(device_inst, 1, "modelName")); + dmasprintf(&upnp_dev_inst.model_number, "%s", dmjson_get_value(device_inst, 1, "modelNumber")); + dmasprintf(&upnp_dev_inst.model_url, "%s", dmjson_get_value(device_inst, 1, "modelURL")); + dmasprintf(&upnp_dev_inst.serial_number, "%s", dmjson_get_value(device_inst, 1, "serialNumber")); + dmasprintf(&upnp_dev_inst.udn, "%s", dmjson_get_value(device_inst, 1, "UDN")); + dmasprintf(&upnp_dev_inst.upc, "%s", dmjson_get_value(device_inst, 1, "UPC")); + if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_device_inst", "udn", dmjson_get_value(device_inst, 1, "UDN"))) == NULL) { + dmuci_add_section_bbfdm("dmmap_upnp", "upnp_device_inst", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "udn", dmjson_get_value(device_inst, 1, "UDN")); + } + upnp_dev_inst.dmmap_sect = dmmap_sect; + + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_device_inst_instance", "upnp_device_inst_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev_inst, instance) == DM_STOP) + return 0; + } + } + return 0; +} + +static int browseUPnPDescriptionServiceInstanceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *services_instances = NULL, *service_inst = NULL; + struct upnp_service_inst upnp_services_inst = {}; + char *instance = NULL, *instnbr = NULL, *v; + int i; + struct uci_section* dmmap_sect = NULL; + + dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + json_object_object_get_ex(res, "servicesinstances", &services_instances); + if (services_instances == NULL) + return 0; + size_t nbre_devices_inst = json_object_array_length(services_instances); + + if (nbre_devices_inst > 0) { + check_create_dmmap_package("dmmap_upnp"); + for (i = 0; i < nbre_devices_inst; i++) { + service_inst = json_object_array_get_idx(services_instances, i); + dmasprintf(&upnp_services_inst.parentudn, "%s", dmjson_get_value(service_inst, 1, "parent_dev")); + dmasprintf(&upnp_services_inst.serviceid, "%s", dmjson_get_value(service_inst, 1, "serviceId")); + dmasprintf(&upnp_services_inst.servicetype, "%s", dmjson_get_value(service_inst, 1, "serviceType")); + dmasprintf(&upnp_services_inst.scpdurl, "%s", dmjson_get_value(service_inst, 1, "SCPDURL")); + dmasprintf(&upnp_services_inst.controlurl, "%s", dmjson_get_value(service_inst, 1, "controlURL")); + dmasprintf(&upnp_services_inst.eventsuburl, "%s", dmjson_get_value(service_inst, 1, "eventSubURL")); + if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_service_inst", "serviceid", dmjson_get_value(service_inst, 1, "serviceId"))) == NULL) { + dmuci_add_section_bbfdm("dmmap_upnp", "upnp_service_inst", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "serviceid", dmjson_get_value(service_inst, 1, "serviceId")); + } + upnp_services_inst.dmmap_sect = dmmap_sect; + + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_service_inst_instance", "upnp_service_inst_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_services_inst, instance) == DM_STOP) + return 0; + } + } + return 0; +} +/************************************************************* +* GET & SET PARAM +**************************************************************/ +/*#Device.UPnP.Device.Enable!UCI:upnpd/upnpd,config/enabled*/ +static int get_UPnPDevice_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("upnpd","config","enabled", value); + if ((*value)[0] == '\0') { + *value = "1"; + } + return 0; +} + +static int set_UPnPDevice_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value("upnpd", "config", "enabled", b ? "" : "0"); + return 0; + } + return 0; +} + +static int get_upnp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + pid_t pid = get_pid("miniupnpd"); + *value = (pid < 0) ? "Down" : "Up"; + return 0; +} + +static int get_UPnPDevice_UPnPMediaServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *path = "/etc/rc.d/*minidlna"; + *value = (check_file(path)) ? "1" : "0"; + return 0; +} + +static int set_UPnPDevice_UPnPMediaServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmcmd("/etc/init.d/minidlna", 1, b ? "enable" : "disable"); + break; + } + return 0; +} + +static int get_UPnPDevice_UPnPMediaRenderer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_UPnPDevice_UPnPMediaRenderer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_UPnPDevice_UPnPWLANAccessPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_UPnPDevice_UPnPWLANAccessPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_UPnPDevice_UPnPQoSDevice (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_UPnPDevice_UPnPQoSDevice (char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_UPnPDevice_UPnPQoSPolicyHolder(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_UPnPDevice_UPnPQoSPolicyHolder(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_UPnPDevice_UPnPIGD(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *path = "/etc/rc.d/*miniupnpd"; + *value = (check_file(path)) ? "1" : "0"; + return 0; +} + +static int set_UPnPDevice_UPnPIGD(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmcmd("/etc/init.d/miniupnpd", 1, b ? "enable" : "disable"); + break; + } + return 0; +} + +static int get_UPnPDevice_UPnPDMBasicMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_UPnPDevice_UPnPDMBasicMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_UPnPDevice_UPnPDMConfigurationMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_UPnPDevice_UPnPDMConfigurationMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_UPnPDevice_UPnPDMSoftwareMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_UPnPDevice_UPnPDMSoftwareMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPArchitecture(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPArchitectureMinorVer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPMediaServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPMediaRenderer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPWLANAccessPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPBasicDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPQoSDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPQoSPolicyHolder(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPIGD(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPDMBasicMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPDMConfigurationMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDeviceCapabilities_UPnPDMSoftwareMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDiscovery_RootDeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + int nbre = 0, i; + char *is_root_device = NULL; + json_object *res = NULL, *devices = NULL, *device = NULL; + + *value = "0"; + dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + + json_object_object_get_ex(res, "devices", &devices); + if (devices == NULL) + return 0; + + size_t nbre_devices = json_object_array_length(devices); + if (nbre_devices > 0){ + for (i = 0; i < nbre_devices; i++){ + device = json_object_array_get_idx(devices, i); + is_root_device = dmjson_get_value(device, 1, "is_root_device"); + if(strcmp(is_root_device, "0") == 0) + continue; + nbre ++; + } + } + dmasprintf(value, "%d", nbre); + return 0; +} + +static int get_UPnPDiscovery_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res, *devices; + + *value = "0"; + dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + + json_object_object_get_ex(res, "devices", &devices); + if (devices == NULL) + return 0; + + size_t nbre_devices = json_object_array_length(devices); + dmasprintf(value, "%d", nbre_devices); + return 0; +} + +static int get_UPnPDiscovery_ServiceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res, *services; + + *value = "0"; + dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + + json_object_object_get_ex(res, "services", &services); + if (services == NULL) + return 0; + + size_t nbre_services = json_object_array_length(services); + dmasprintf(value, "%d", nbre_services); + return 0; +} + +static int get_UPnPDiscoveryRootDevice_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.UPnP.Discovery.RootDevice.{i}.UUID!UBUS:upnpc/discovery//devices[i-1].st*/ +static int get_UPnPDiscoveryRootDevice_UUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnpdiscovery *)data)->uuid; + return 0; +} + +/*#Device.UPnP.Discovery.RootDevice.{i}.USN!UBUS:upnpc/discovery//devices[i-1].usn*/ +static int get_UPnPDiscoveryRootDevice_USN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnpdiscovery *)data)->usn; + return 0; +} + +static int get_UPnPDiscoveryRootDevice_LeaseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.UPnP.Discovery.RootDevice.{i}.Location!UBUS:upnpc/discovery//devices[i-1].descurl*/ +static int get_UPnPDiscoveryRootDevice_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnpdiscovery *)data)->descurl; + return 0; +} + +static int get_UPnPDiscoveryRootDevice_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDiscoveryRootDevice_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDiscoveryRootDevice_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDiscoveryDevice_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.UPnP.Discovery.Device.{i}.UUID!UBUS:upnpc/discovery//devices[i-1].st*/ +static int get_UPnPDiscoveryDevice_UUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnpdiscovery *)data)->uuid; + return 0; +} + +/*#Device.UPnP.Discovery.Device.{i}.USN!UBUS:upnpc/discovery//devices[i-1].usn*/ +static int get_UPnPDiscoveryDevice_USN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnpdiscovery *)data)->usn; + return 0; +} + +static int get_UPnPDiscoveryDevice_LeaseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.UPnP.Discovery.Device.{i}.Location!UBUS:upnpc/discovery//devices[i-1].descurl*/ +static int get_UPnPDiscoveryDevice_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnpdiscovery *)data)->descurl; + return 0; +} + +static int get_UPnPDiscoveryDevice_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDiscoveryDevice_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDiscoveryDevice_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDiscoveryService_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.UPnP.Discovery.Service.{i}.USN!UBUS:upnpc/discovery//services[i-1].usn*/ +static int get_UPnPDiscoveryService_USN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnpdiscovery *)data)->usn; + return 0; +} + +static int get_UPnPDiscoveryService_LeaseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.UPnP.Discovery.Service.{i}.Location!UBUS:upnpc/discovery//services[i-1].descurl*/ +static int get_UPnPDiscoveryService_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnpdiscovery *)data)->descurl; + return 0; +} + +static int get_UPnPDiscoveryService_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDiscoveryService_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDiscoveryService_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDiscoveryService_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *rootdevlink = NULL, *devlink = NULL; + + adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cRootDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), ((struct upnpdiscovery *)data)->uuid, &rootdevlink); + if (rootdevlink != NULL) { + *value = rootdevlink; + return 0; + } + adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), ((struct upnpdiscovery *)data)->uuid, &devlink); + if (devlink != NULL) { + *value = devlink; + return 0; + } + *value = ""; + return 0; +} + +static int get_UPnPDescription_DeviceDescriptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res, *descriptions; + + *value = "0"; + dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + + json_object_object_get_ex(res, "descriptions", &descriptions); + if (descriptions == NULL) + return 0; + + size_t nbre_descriptions = json_object_array_length(descriptions); + dmasprintf(value, "%d", nbre_descriptions); + return 0; +} + +static int get_UPnPDescription_DeviceInstanceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res, *devicesinstances; + + *value = "0"; + dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + + json_object_object_get_ex(res, "devicesinstances", &devicesinstances); + if (devicesinstances == NULL) + return 0; + + size_t nbre_devinstances = json_object_array_length(devicesinstances); + dmasprintf(value, "%d", nbre_devinstances); + return 0; +} + +static int get_UPnPDescription_ServiceInstanceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res, *servicesinstances; + + *value = "0"; + dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); + if (res == NULL) + return 0; + + json_object_object_get_ex(res, "servicesinstances", &servicesinstances); + if (servicesinstances == NULL) + return 0; + + size_t nbre_servinstances = json_object_array_length(servicesinstances); + dmasprintf(value, "%d", nbre_servinstances); + return 0; +} + +/*#Device.UPnP.Description.DeviceDescription.{i}.URLBase!UBUS:upnpc/description//descriptions[i-1].descurl*/ +static int get_UPnPDescriptionDeviceDescription_URLBase(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_description_file_info *)data)->desc_url; + return 0; +} + +static int get_UPnPDescriptionDeviceDescription_SpecVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_UPnPDescriptionDeviceDescription_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.UDN!UBUS:upnpc/description//devicesinstances[i-1].UDN*/ +static int get_UPnPDescriptionDeviceInstance_UDN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->udn; + return 0; +} + +static int get_UPnPDescriptionDeviceInstance_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *devinstlink = NULL; + + adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDescription%cDeviceInstance%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), ((struct upnp_device_inst *)data)->parentudn, &devinstlink); + if (devinstlink != NULL) + *value = devinstlink; + return 0; +} + +static int get_UPnPDescriptionDeviceInstance_DiscoveryDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct upnp_device_inst *upnpdevinst = (struct upnp_device_inst *)data; + char *rootdevlink = NULL, *devlink = NULL, **udnarray = NULL; + size_t length; + + if (upnpdevinst->udn && upnpdevinst->udn[0]) { + udnarray = strsplit(upnpdevinst->udn, ":", &length); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cRootDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), udnarray[1], &rootdevlink); + if (rootdevlink != NULL) { + *value = rootdevlink; + return 0; + } + adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), udnarray[1], &devlink); + if (devlink != NULL) { + *value =devlink; + return 0; + } + } + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.DeviceType!UBUS:upnpc/description//devicesinstances[i-1].deviceType*/ +static int get_UPnPDescriptionDeviceInstance_DeviceType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->device_type; + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.FriendlyName!UBUS:upnpc/description//devicesinstances[i-1].friendlyName*/ +static int get_UPnPDescriptionDeviceInstance_FriendlyName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->friendly_name; + return 0; +} + +static int get_UPnPDescriptionDeviceInstance_DeviceCategory(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.Manufacturer!UBUS:upnpc/description//devicesinstances[i-1].manufacturer*/ +static int get_UPnPDescriptionDeviceInstance_Manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->manufacturer; + return 0; +} + +static int get_UPnPDescriptionDeviceInstance_ManufacturerOUI(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.ManufacturerURL!UBUS:upnpc/description//devicesinstances[i-1].manufacturerURL*/ +static int get_UPnPDescriptionDeviceInstance_ManufacturerURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->manufacturer_url; + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.ModelDescription!UBUS:upnpc/description//devicesinstances[i-1].modelDescription*/ +static int get_UPnPDescriptionDeviceInstance_ModelDescription(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->model_description; + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.ModelName!UBUS:upnpc/description//devicesinstances[i-1].modelName*/ +static int get_UPnPDescriptionDeviceInstance_ModelName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->model_name; + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.ModelNumber!UBUS:upnpc/description//devicesinstances[i-1].modelNumber*/ +static int get_UPnPDescriptionDeviceInstance_ModelNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->model_number; + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.ModelURL!UBUS:upnpc/description//devicesinstances[i-1].modelURL*/ +static int get_UPnPDescriptionDeviceInstance_ModelURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->model_url; + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.SerialNumber!UBUS:upnpc/description//devicesinstances[i-1].serialNumber*/ +static int get_UPnPDescriptionDeviceInstance_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->serial_number; + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.UPC!UBUS:upnpc/description//devicesinstances[i-1].UPC*/ +static int get_UPnPDescriptionDeviceInstance_UPC(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->upc; + return 0; +} + +/*#Device.UPnP.Description.DeviceInstance.{i}.PresentationURL!UBUS:upnpc/description//devicesinstances[i-1].preentation_url*/ +static int get_UPnPDescriptionDeviceInstance_PresentationURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_device_inst *)data)->preentation_url; + return 0; +} + +static int get_UPnPDescriptionServiceInstance_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *devinstlink = NULL; + + adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDescription%cDeviceInstance%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), ((struct upnp_service_inst *)data)->parentudn, &devinstlink); + if (devinstlink != NULL) + *value = devinstlink; + return 0; +} + +/*#Device.UPnP.Description.ServiceInstance.{i}.ServiceId!UBUS:upnpc/description//servicesinstances[i-1].serviceId*/ +static int get_UPnPDescriptionServiceInstance_ServiceId(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_service_inst *)data)->serviceid; + return 0; +} + +static int get_UPnPDescriptionServiceInstance_ServiceDiscovery(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *usn = NULL, *devlink = NULL; + + dmasprintf(&usn, "%s::%s", ((struct upnp_service_inst *)data)->parentudn, ((struct upnp_service_inst *)data)->servicetype); + if (usn && usn[0]) { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cService%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), usn, &devlink); + if (devlink != NULL) + *value = devlink; + } + return 0; +} + +/*#Device.UPnP.Description.ServiceInstance.{i}.ServiceType!UBUS:upnpc/description//servicesinstances[i-1].serviceType*/ +static int get_UPnPDescriptionServiceInstance_ServiceType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_service_inst *)data)->servicetype; + return 0; +} + +/*#Device.UPnP.Description.ServiceInstance.{i}.SCPDURL!UBUS:upnpc/description//servicesinstances[i-1].SCPDURL*/ +static int get_UPnPDescriptionServiceInstance_SCPDURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_service_inst *)data)->scpdurl; + return 0; +} + +/*#Device.UPnP.Description.ServiceInstance.{i}.ControlURL!UBUS:upnpc/description//servicesinstances[i-1].controlURL*/ +static int get_UPnPDescriptionServiceInstance_ControlURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_service_inst *)data)->controlurl; + return 0; +} + +/*#Device.UPnP.Description.ServiceInstance.{i}.EventSubURL!UBUS:upnpc/description//servicesinstances[i-1].eventSubURL*/ +static int get_UPnPDescriptionServiceInstance_EventSubURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ((struct upnp_service_inst *)data)->eventsuburl; + return 0; +} + /* *** Device.UPnP. *** */ DMOBJ tUPnPObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -181,1099 +1319,3 @@ DMLEAF tUPnPDescriptionServiceInstanceParams[] = { {"EventSubURL", &DMREAD, DMT_STRING, get_UPnPDescriptionServiceInstance_EventSubURL, NULL, NULL, NULL, BBFDM_BOTH}, {0} }; - -/************************************************************************** -* LINKER -***************************************************************************/ -int get_root_device_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct upnpdiscovery *)data)->uuid) { - dmasprintf(linker, "%s", ((struct upnpdiscovery *)data)->uuid); - return 0; - } - *linker = "" ; - return 0; -} - -int get_device_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct upnpdiscovery *)data)->uuid){ - dmasprintf(linker, "%s", ((struct upnpdiscovery *)data)->uuid); - return 0; - } - *linker = "" ; - return 0; -} - -int get_device_instance_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct upnp_device_inst *)data)->udn){ - dmasprintf(linker, "%s", ((struct upnp_device_inst *)data)->udn); - return 0; - } - *linker = "" ; - return 0; -} - -int get_service_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct upnpdiscovery *)data)->usn){ - dmasprintf(linker, "%s", ((struct upnpdiscovery *)data)->usn); - return 0; - } - *linker = "" ; - return 0; -} - -/************************************************************* -* ENTRY METHOD -**************************************************************/ -int browseUPnPDiscoveryRootDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - json_object *res = NULL, *devices = NULL, *device = NULL; - struct upnpdiscovery upnp_dev = {}; - char *descurl = NULL, *st = NULL, *usn = NULL, *is_root_device = NULL, *instance = NULL, *instnbr = NULL, *v = NULL; - char **stparams = NULL, **uuid, **urn; - int i; - size_t length; - struct uci_section* dmmap_sect= NULL; - - dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - json_object_object_get_ex(res, "devices", &devices); - if (devices == NULL) - return 0; - size_t nbre_devices = json_object_array_length(devices); - - if (nbre_devices > 0) { - check_create_dmmap_package("dmmap_upnp"); - for (i = 0; i < nbre_devices; i++) { - device = json_object_array_get_idx(devices, i); - is_root_device = dmjson_get_value(device, 1, "is_root_device"); - if(strcmp(is_root_device, "0") == 0) - continue; - descurl = dmjson_get_value(device, 1, "descurl"); - st = dmjson_get_value(device, 1, "st"); - usn = dmjson_get_value(device, 1, "usn"); - stparams = strsplit_by_str(usn, "::"); - uuid = strsplit(stparams[0], ":", &length); - urn = strsplit(stparams[1], ":", &length); - dmasprintf(&upnp_dev.descurl, "%s", descurl); - dmasprintf(&upnp_dev.st, "%s", st); - dmasprintf(&upnp_dev.usn, "%s", usn); - dmasprintf(&upnp_dev.uuid, "%s", uuid[1]); - dmasprintf(&upnp_dev.urn, "%s", urn[1]); - if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_root_device", "uuid", uuid[1])) == NULL) { - dmuci_add_section_bbfdm("dmmap_upnp", "upnp_root_device", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "uuid", uuid[1]); - } - upnp_dev.dmmap_sect = dmmap_sect; - - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_root_device_instance", "upnp_root_device_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev, instance) == DM_STOP) - return 0; - } - } - return 0; -} - -int browseUPnPDiscoveryDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - json_object *res = NULL, *devices = NULL, *device = NULL; - struct upnpdiscovery upnp_dev = {}; - char *descurl = NULL, *st = NULL, *usn = NULL, *instance = NULL, *instnbr = NULL, *v = NULL; - char **stparams= NULL, **uuid, **urn; - int i; - size_t lengthuuid, lengthurn; - struct uci_section* dmmap_sect= NULL; - - dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - json_object_object_get_ex(res, "devices", &devices); - if (devices == NULL) - return 0; - size_t nbre_devices = json_object_array_length(devices); - - if (nbre_devices > 0) { - check_create_dmmap_package("dmmap_upnp"); - for(i=0; i0?uuid[1]:""); - dmasprintf(&upnp_dev.urn, "%s", lengthurn>0?urn[1]:""); - if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_device", "uuid", uuid[1])) == NULL) { - dmuci_add_section_bbfdm("dmmap_upnp", "upnp_device", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "uuid", uuid[1]); - } - upnp_dev.dmmap_sect = dmmap_sect; - - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_evice_instance", "upnp_device_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev, instance) == DM_STOP) - return 0; - } - } - return 0; -} - -int browseUPnPDiscoveryServiceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - json_object *res = NULL, *services = NULL, *service = NULL; - struct upnpdiscovery upnp_dev = {}; - char *descurl = NULL, *st = NULL, *usn = NULL, *instance = NULL, *instnbr = NULL, *v = NULL; - char **stparams = NULL, **uuid, **urn; - int i; - size_t lengthuuid, lengthurn; - struct uci_section* dmmap_sect = NULL; - - dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - json_object_object_get_ex(res, "services", &services); - if (services == NULL) - return 0; - size_t nbre_services = json_object_array_length(services); - - if (nbre_services > 0) { - check_create_dmmap_package("dmmap_upnp"); - for (i = 0; i < nbre_services; i++){ - service = json_object_array_get_idx(services, i); - descurl = dmjson_get_value(service, 1, "descurl"); - st = dmjson_get_value(service, 1, "st"); - usn = dmjson_get_value(service, 1, "usn"); - stparams = strsplit_by_str(usn, "::"); - uuid = strsplit(stparams[0], ":", &lengthuuid); - urn = strsplit(stparams[1], ":", &lengthurn); - dmasprintf(&upnp_dev.descurl, "%s", descurl?descurl:""); - dmasprintf(&upnp_dev.st, "%s", st?st:""); - dmasprintf(&upnp_dev.usn, "%s", usn?usn:""); - dmasprintf(&upnp_dev.uuid, "%s", lengthuuid>0?uuid[1]:""); - dmasprintf(&upnp_dev.urn, "%s", lengthurn>0?urn[1]:""); - if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_service", "usn", usn)) == NULL) { - dmuci_add_section_bbfdm("dmmap_upnp", "upnp_service", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "usn", usn); - } - upnp_dev.dmmap_sect = dmmap_sect; - - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_service_instance", "upnp_service_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev, instance) == DM_STOP) - return 0; - } - } - return 0; -} - -int browseUPnPDescriptionDeviceDescriptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - json_object *res = NULL, *descriptions = NULL, *description = NULL; - struct upnp_description_file_info upnp_desc= {}; - char *descurl = NULL, *instance = NULL, *instnbr = NULL, *v = NULL; - int i; - struct uci_section* dmmap_sect = NULL; - - dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - json_object_object_get_ex(res, "descriptions", &descriptions); - if (descriptions == NULL) - return 0; - size_t nbre_descriptions = json_object_array_length(descriptions); - - if (nbre_descriptions > 0) { - check_create_dmmap_package("dmmap_upnp"); - for (i = 0; i < nbre_descriptions; i++) { - description = json_object_array_get_idx(descriptions, i); - descurl = dmjson_get_value(description, 1, "descurl"); - dmasprintf(&upnp_desc.desc_url, "%s", descurl?descurl:""); - if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_description", "descurl", descurl)) == NULL) { - dmuci_add_section_bbfdm("dmmap_upnp", "upnp_description", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "descurl", descurl); - } - upnp_desc.dmmap_sect = dmmap_sect; - - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_service_instance", "upnp_service_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_desc, instance) == DM_STOP) - return 0; - } - } - return 0; -} - -int browseUPnPDescriptionDeviceInstanceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - json_object *res = NULL, *devices_instances = NULL, *device_inst = NULL; - struct upnp_device_inst upnp_dev_inst = {}; - char *instance = NULL, *instnbr = NULL, *v; - int i; - struct uci_section* dmmap_sect = NULL; - - dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - json_object_object_get_ex(res, "devicesinstances", &devices_instances); - if (devices_instances == NULL) - return 0; - size_t nbre_devices_inst = json_object_array_length(devices_instances); - - if (nbre_devices_inst > 0) { - check_create_dmmap_package("dmmap_upnp"); - for (i = 0; i < nbre_devices_inst; i++){ - device_inst = json_object_array_get_idx(devices_instances, i); - dmasprintf(&upnp_dev_inst.parentudn, "%s", dmjson_get_value(device_inst, 1, "parent_dev")); - dmasprintf(&upnp_dev_inst.device_type, "%s", dmjson_get_value(device_inst, 1, "deviceType")); - dmasprintf(&upnp_dev_inst.friendly_name, "%s", dmjson_get_value(device_inst, 1, "friendlyName")); - dmasprintf(&upnp_dev_inst.manufacturer, "%s", dmjson_get_value(device_inst, 1, "manufacturer")); - dmasprintf(&upnp_dev_inst.manufacturer_url, "%s", dmjson_get_value(device_inst, 1, "manufacturerURL")); - dmasprintf(&upnp_dev_inst.model_description, "%s", dmjson_get_value(device_inst, 1, "modelDescription")); - dmasprintf(&upnp_dev_inst.model_name, "%s", dmjson_get_value(device_inst, 1, "modelName")); - dmasprintf(&upnp_dev_inst.model_number, "%s", dmjson_get_value(device_inst, 1, "modelNumber")); - dmasprintf(&upnp_dev_inst.model_url, "%s", dmjson_get_value(device_inst, 1, "modelURL")); - dmasprintf(&upnp_dev_inst.serial_number, "%s", dmjson_get_value(device_inst, 1, "serialNumber")); - dmasprintf(&upnp_dev_inst.udn, "%s", dmjson_get_value(device_inst, 1, "UDN")); - dmasprintf(&upnp_dev_inst.upc, "%s", dmjson_get_value(device_inst, 1, "UPC")); - if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_device_inst", "udn", dmjson_get_value(device_inst, 1, "UDN"))) == NULL) { - dmuci_add_section_bbfdm("dmmap_upnp", "upnp_device_inst", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "udn", dmjson_get_value(device_inst, 1, "UDN")); - } - upnp_dev_inst.dmmap_sect = dmmap_sect; - - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_device_inst_instance", "upnp_device_inst_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev_inst, instance) == DM_STOP) - return 0; - } - } - return 0; -} - -int browseUPnPDescriptionServiceInstanceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - json_object *res = NULL, *services_instances = NULL, *service_inst = NULL; - struct upnp_service_inst upnp_services_inst = {}; - char *instance = NULL, *instnbr = NULL, *v; - int i; - struct uci_section* dmmap_sect = NULL; - - dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - json_object_object_get_ex(res, "servicesinstances", &services_instances); - if (services_instances == NULL) - return 0; - size_t nbre_devices_inst = json_object_array_length(services_instances); - - if (nbre_devices_inst > 0) { - check_create_dmmap_package("dmmap_upnp"); - for (i = 0; i < nbre_devices_inst; i++) { - service_inst = json_object_array_get_idx(services_instances, i); - dmasprintf(&upnp_services_inst.parentudn, "%s", dmjson_get_value(service_inst, 1, "parent_dev")); - dmasprintf(&upnp_services_inst.serviceid, "%s", dmjson_get_value(service_inst, 1, "serviceId")); - dmasprintf(&upnp_services_inst.servicetype, "%s", dmjson_get_value(service_inst, 1, "serviceType")); - dmasprintf(&upnp_services_inst.scpdurl, "%s", dmjson_get_value(service_inst, 1, "SCPDURL")); - dmasprintf(&upnp_services_inst.controlurl, "%s", dmjson_get_value(service_inst, 1, "controlURL")); - dmasprintf(&upnp_services_inst.eventsuburl, "%s", dmjson_get_value(service_inst, 1, "eventSubURL")); - if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_service_inst", "serviceid", dmjson_get_value(service_inst, 1, "serviceId"))) == NULL) { - dmuci_add_section_bbfdm("dmmap_upnp", "upnp_service_inst", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "serviceid", dmjson_get_value(service_inst, 1, "serviceId")); - } - upnp_services_inst.dmmap_sect = dmmap_sect; - - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "upnp_service_inst_instance", "upnp_service_inst_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_services_inst, instance) == DM_STOP) - return 0; - } - } - return 0; -} -/************************************************************* -* GET & SET PARAM -**************************************************************/ -/*#Device.UPnP.Device.Enable!UCI:upnpd/upnpd,config/enabled*/ -int get_UPnPDevice_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("upnpd","config","enabled", value); - if ((*value)[0] == '\0') { - *value = "1"; - } - return 0; -} - -int set_UPnPDevice_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value("upnpd", "config", "enabled", b ? "" : "0"); - return 0; - } - return 0; -} - -int get_upnp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - pid_t pid = get_pid("miniupnpd"); - *value = (pid < 0) ? "Down" : "Up"; - return 0; -} - -int get_UPnPDevice_UPnPMediaServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *path = "/etc/rc.d/*minidlna"; - *value = (check_file(path)) ? "1" : "0"; - return 0; -} - -int set_UPnPDevice_UPnPMediaServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmcmd("/etc/init.d/minidlna", 1, b ? "enable" : "disable"); - break; - } - return 0; -} - -int get_UPnPDevice_UPnPMediaRenderer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_UPnPDevice_UPnPMediaRenderer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_UPnPDevice_UPnPWLANAccessPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_UPnPDevice_UPnPWLANAccessPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_UPnPDevice_UPnPQoSDevice (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_UPnPDevice_UPnPQoSDevice (char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_UPnPDevice_UPnPQoSPolicyHolder(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_UPnPDevice_UPnPQoSPolicyHolder(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_UPnPDevice_UPnPIGD(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *path = "/etc/rc.d/*miniupnpd"; - *value = (check_file(path)) ? "1" : "0"; - return 0; -} - -int set_UPnPDevice_UPnPIGD(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmcmd("/etc/init.d/miniupnpd", 1, b ? "enable" : "disable"); - break; - } - return 0; -} - -int get_UPnPDevice_UPnPDMBasicMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_UPnPDevice_UPnPDMBasicMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_UPnPDevice_UPnPDMConfigurationMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_UPnPDevice_UPnPDMConfigurationMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_UPnPDevice_UPnPDMSoftwareMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_UPnPDevice_UPnPDMSoftwareMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPArchitecture(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPArchitectureMinorVer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPMediaServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPMediaRenderer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPWLANAccessPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPBasicDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPQoSDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPQoSPolicyHolder(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPIGD(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPDMBasicMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPDMConfigurationMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDeviceCapabilities_UPnPDMSoftwareMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDiscovery_RootDeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - int nbre = 0, i; - char *is_root_device = NULL; - json_object *res = NULL, *devices = NULL, *device = NULL; - - *value = "0"; - dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - - json_object_object_get_ex(res, "devices", &devices); - if (devices == NULL) - return 0; - - size_t nbre_devices = json_object_array_length(devices); - if (nbre_devices > 0){ - for (i = 0; i < nbre_devices; i++){ - device = json_object_array_get_idx(devices, i); - is_root_device = dmjson_get_value(device, 1, "is_root_device"); - if(strcmp(is_root_device, "0") == 0) - continue; - nbre ++; - } - } - dmasprintf(value, "%d", nbre); - return 0; -} - -int get_UPnPDiscovery_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res, *devices; - - *value = "0"; - dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - - json_object_object_get_ex(res, "devices", &devices); - if (devices == NULL) - return 0; - - size_t nbre_devices = json_object_array_length(devices); - dmasprintf(value, "%d", nbre_devices); - return 0; -} - -int get_UPnPDiscovery_ServiceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res, *services; - - *value = "0"; - dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - - json_object_object_get_ex(res, "services", &services); - if (services == NULL) - return 0; - - size_t nbre_services = json_object_array_length(services); - dmasprintf(value, "%d", nbre_services); - return 0; -} - -int get_UPnPDiscoveryRootDevice_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.UPnP.Discovery.RootDevice.{i}.UUID!UBUS:upnpc/discovery//devices[i-1].st*/ -int get_UPnPDiscoveryRootDevice_UUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnpdiscovery *)data)->uuid; - return 0; -} - -/*#Device.UPnP.Discovery.RootDevice.{i}.USN!UBUS:upnpc/discovery//devices[i-1].usn*/ -int get_UPnPDiscoveryRootDevice_USN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnpdiscovery *)data)->usn; - return 0; -} - -int get_UPnPDiscoveryRootDevice_LeaseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.UPnP.Discovery.RootDevice.{i}.Location!UBUS:upnpc/discovery//devices[i-1].descurl*/ -int get_UPnPDiscoveryRootDevice_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnpdiscovery *)data)->descurl; - return 0; -} - -int get_UPnPDiscoveryRootDevice_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDiscoveryRootDevice_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDiscoveryRootDevice_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDiscoveryDevice_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.UPnP.Discovery.Device.{i}.UUID!UBUS:upnpc/discovery//devices[i-1].st*/ -int get_UPnPDiscoveryDevice_UUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnpdiscovery *)data)->uuid; - return 0; -} - -/*#Device.UPnP.Discovery.Device.{i}.USN!UBUS:upnpc/discovery//devices[i-1].usn*/ -int get_UPnPDiscoveryDevice_USN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnpdiscovery *)data)->usn; - return 0; -} - -int get_UPnPDiscoveryDevice_LeaseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.UPnP.Discovery.Device.{i}.Location!UBUS:upnpc/discovery//devices[i-1].descurl*/ -int get_UPnPDiscoveryDevice_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnpdiscovery *)data)->descurl; - return 0; -} - -int get_UPnPDiscoveryDevice_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDiscoveryDevice_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDiscoveryDevice_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDiscoveryService_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.UPnP.Discovery.Service.{i}.USN!UBUS:upnpc/discovery//services[i-1].usn*/ -int get_UPnPDiscoveryService_USN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnpdiscovery *)data)->usn; - return 0; -} - -int get_UPnPDiscoveryService_LeaseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.UPnP.Discovery.Service.{i}.Location!UBUS:upnpc/discovery//services[i-1].descurl*/ -int get_UPnPDiscoveryService_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnpdiscovery *)data)->descurl; - return 0; -} - -int get_UPnPDiscoveryService_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDiscoveryService_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDiscoveryService_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDiscoveryService_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *rootdevlink = NULL, *devlink = NULL; - - adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cRootDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), ((struct upnpdiscovery *)data)->uuid, &rootdevlink); - if (rootdevlink != NULL) { - *value = rootdevlink; - return 0; - } - adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), ((struct upnpdiscovery *)data)->uuid, &devlink); - if (devlink != NULL) { - *value = devlink; - return 0; - } - *value = ""; - return 0; -} - -int get_UPnPDescription_DeviceDescriptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res, *descriptions; - - *value = "0"; - dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - - json_object_object_get_ex(res, "descriptions", &descriptions); - if (descriptions == NULL) - return 0; - - size_t nbre_descriptions = json_object_array_length(descriptions); - dmasprintf(value, "%d", nbre_descriptions); - return 0; -} - -int get_UPnPDescription_DeviceInstanceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res, *devicesinstances; - - *value = "0"; - dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - - json_object_object_get_ex(res, "devicesinstances", &devicesinstances); - if (devicesinstances == NULL) - return 0; - - size_t nbre_devinstances = json_object_array_length(devicesinstances); - dmasprintf(value, "%d", nbre_devinstances); - return 0; -} - -int get_UPnPDescription_ServiceInstanceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res, *servicesinstances; - - *value = "0"; - dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res); - if (res == NULL) - return 0; - - json_object_object_get_ex(res, "servicesinstances", &servicesinstances); - if (servicesinstances == NULL) - return 0; - - size_t nbre_servinstances = json_object_array_length(servicesinstances); - dmasprintf(value, "%d", nbre_servinstances); - return 0; -} - -/*#Device.UPnP.Description.DeviceDescription.{i}.URLBase!UBUS:upnpc/description//descriptions[i-1].descurl*/ -int get_UPnPDescriptionDeviceDescription_URLBase(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_description_file_info *)data)->desc_url; - return 0; -} - -int get_UPnPDescriptionDeviceDescription_SpecVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_UPnPDescriptionDeviceDescription_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.UDN!UBUS:upnpc/description//devicesinstances[i-1].UDN*/ -int get_UPnPDescriptionDeviceInstance_UDN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->udn; - return 0; -} - -int get_UPnPDescriptionDeviceInstance_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *devinstlink = NULL; - - adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDescription%cDeviceInstance%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), ((struct upnp_device_inst *)data)->parentudn, &devinstlink); - if (devinstlink != NULL) - *value = devinstlink; - return 0; -} - -int get_UPnPDescriptionDeviceInstance_DiscoveryDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct upnp_device_inst *upnpdevinst = (struct upnp_device_inst *)data; - char *rootdevlink = NULL, *devlink = NULL, **udnarray = NULL; - size_t length; - - if (upnpdevinst->udn && upnpdevinst->udn[0]) { - udnarray = strsplit(upnpdevinst->udn, ":", &length); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cRootDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), udnarray[1], &rootdevlink); - if (rootdevlink != NULL) { - *value = rootdevlink; - return 0; - } - adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), udnarray[1], &devlink); - if (devlink != NULL) { - *value =devlink; - return 0; - } - } - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.DeviceType!UBUS:upnpc/description//devicesinstances[i-1].deviceType*/ -int get_UPnPDescriptionDeviceInstance_DeviceType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->device_type; - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.FriendlyName!UBUS:upnpc/description//devicesinstances[i-1].friendlyName*/ -int get_UPnPDescriptionDeviceInstance_FriendlyName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->friendly_name; - return 0; -} - -int get_UPnPDescriptionDeviceInstance_DeviceCategory(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.Manufacturer!UBUS:upnpc/description//devicesinstances[i-1].manufacturer*/ -int get_UPnPDescriptionDeviceInstance_Manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->manufacturer; - return 0; -} - -int get_UPnPDescriptionDeviceInstance_ManufacturerOUI(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.ManufacturerURL!UBUS:upnpc/description//devicesinstances[i-1].manufacturerURL*/ -int get_UPnPDescriptionDeviceInstance_ManufacturerURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->manufacturer_url; - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.ModelDescription!UBUS:upnpc/description//devicesinstances[i-1].modelDescription*/ -int get_UPnPDescriptionDeviceInstance_ModelDescription(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->model_description; - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.ModelName!UBUS:upnpc/description//devicesinstances[i-1].modelName*/ -int get_UPnPDescriptionDeviceInstance_ModelName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->model_name; - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.ModelNumber!UBUS:upnpc/description//devicesinstances[i-1].modelNumber*/ -int get_UPnPDescriptionDeviceInstance_ModelNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->model_number; - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.ModelURL!UBUS:upnpc/description//devicesinstances[i-1].modelURL*/ -int get_UPnPDescriptionDeviceInstance_ModelURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->model_url; - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.SerialNumber!UBUS:upnpc/description//devicesinstances[i-1].serialNumber*/ -int get_UPnPDescriptionDeviceInstance_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->serial_number; - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.UPC!UBUS:upnpc/description//devicesinstances[i-1].UPC*/ -int get_UPnPDescriptionDeviceInstance_UPC(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->upc; - return 0; -} - -/*#Device.UPnP.Description.DeviceInstance.{i}.PresentationURL!UBUS:upnpc/description//devicesinstances[i-1].preentation_url*/ -int get_UPnPDescriptionDeviceInstance_PresentationURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_device_inst *)data)->preentation_url; - return 0; -} - -int get_UPnPDescriptionServiceInstance_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *devinstlink = NULL; - - adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDescription%cDeviceInstance%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), ((struct upnp_service_inst *)data)->parentudn, &devinstlink); - if (devinstlink != NULL) - *value = devinstlink; - return 0; -} - -/*#Device.UPnP.Description.ServiceInstance.{i}.ServiceId!UBUS:upnpc/description//servicesinstances[i-1].serviceId*/ -int get_UPnPDescriptionServiceInstance_ServiceId(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_service_inst *)data)->serviceid; - return 0; -} - -int get_UPnPDescriptionServiceInstance_ServiceDiscovery(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *usn = NULL, *devlink = NULL; - - dmasprintf(&usn, "%s::%s", ((struct upnp_service_inst *)data)->parentudn, ((struct upnp_service_inst *)data)->servicetype); - if (usn && usn[0]) { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cService%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), usn, &devlink); - if (devlink != NULL) - *value = devlink; - } - return 0; -} - -/*#Device.UPnP.Description.ServiceInstance.{i}.ServiceType!UBUS:upnpc/description//servicesinstances[i-1].serviceType*/ -int get_UPnPDescriptionServiceInstance_ServiceType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_service_inst *)data)->servicetype; - return 0; -} - -/*#Device.UPnP.Description.ServiceInstance.{i}.SCPDURL!UBUS:upnpc/description//servicesinstances[i-1].SCPDURL*/ -int get_UPnPDescriptionServiceInstance_SCPDURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_service_inst *)data)->scpdurl; - return 0; -} - -/*#Device.UPnP.Description.ServiceInstance.{i}.ControlURL!UBUS:upnpc/description//servicesinstances[i-1].controlURL*/ -int get_UPnPDescriptionServiceInstance_ControlURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_service_inst *)data)->controlurl; - return 0; -} - -/*#Device.UPnP.Description.ServiceInstance.{i}.EventSubURL!UBUS:upnpc/description//servicesinstances[i-1].eventSubURL*/ -int get_UPnPDescriptionServiceInstance_EventSubURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ((struct upnp_service_inst *)data)->eventsuburl; - return 0; -} diff --git a/dmtree/tr181/upnp.h b/dmtree/tr181/upnp.h index 67242d94..727a52af 100644 --- a/dmtree/tr181/upnp.h +++ b/dmtree/tr181/upnp.h @@ -29,148 +29,5 @@ extern DMLEAF tUPnPDescriptionDeviceDescriptionParams[]; extern DMLEAF tUPnPDescriptionDeviceInstanceParams[]; extern DMLEAF tUPnPDescriptionServiceInstanceParams[]; -struct upnpdiscovery { - char *st; - char *usn; - char *uuid; - char *urn; - char *descurl; - struct uci_section *dmmap_sect; -}; - -struct upnp_device_inst { - char *device_type; - char *friendly_name; - char *manufacturer; - char *manufacturer_url; - char *model_description; - char *model_name; - char *model_number; - char *model_url; - char *serial_number; - char *udn; - char *uuid; - char *preentation_url; - char *parentudn; - char *upc; - struct uci_section *dmmap_sect; -}; - -struct upnp_service_inst { - char *parentudn; - char *serviceid; - char *servicetype; - char *scpdurl; - char *controlurl; - char *eventsuburl; - struct uci_section *dmmap_sect; -}; - -struct upnp_description_file_info { - char *desc_url; - struct uci_section *dmmap_sect; -}; - -int browseUPnPDiscoveryRootDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseUPnPDiscoveryDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseUPnPDiscoveryServiceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseUPnPDescriptionDeviceDescriptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseUPnPDescriptionDeviceInstanceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseUPnPDescriptionServiceInstanceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int get_UPnPDevice_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_UPnPDevice_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_UPnPDevice_UPnPMediaServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_UPnPDevice_UPnPMediaServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_UPnPDevice_UPnPMediaRenderer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_UPnPDevice_UPnPMediaRenderer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_UPnPDevice_UPnPWLANAccessPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_UPnPDevice_UPnPWLANAccessPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_UPnPDevice_UPnPQoSDevice (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_UPnPDevice_UPnPQoSDevice (char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_UPnPDevice_UPnPQoSPolicyHolder(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_UPnPDevice_UPnPQoSPolicyHolder(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_UPnPDevice_UPnPIGD(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_UPnPDevice_UPnPIGD(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_UPnPDevice_UPnPDMBasicMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_UPnPDevice_UPnPDMBasicMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_UPnPDevice_UPnPDMConfigurationMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_UPnPDevice_UPnPDMConfigurationMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_UPnPDevice_UPnPDMSoftwareMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_UPnPDevice_UPnPDMSoftwareMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_UPnPDeviceCapabilities_UPnPArchitecture(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDeviceCapabilities_UPnPArchitectureMinorVer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDeviceCapabilities_UPnPMediaServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDeviceCapabilities_UPnPMediaRenderer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDeviceCapabilities_UPnPWLANAccessPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDeviceCapabilities_UPnPBasicDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDeviceCapabilities_UPnPQoSDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDeviceCapabilities_UPnPQoSPolicyHolder(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDeviceCapabilities_UPnPIGD(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDeviceCapabilities_UPnPDMBasicMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDeviceCapabilities_UPnPDMConfigurationMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDeviceCapabilities_UPnPDMSoftwareMgmt(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscovery_RootDeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscovery_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscovery_ServiceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryRootDevice_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryRootDevice_UUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryRootDevice_USN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryRootDevice_LeaseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryRootDevice_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryRootDevice_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryRootDevice_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryRootDevice_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryDevice_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryDevice_UUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryDevice_USN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryDevice_LeaseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryDevice_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryDevice_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryDevice_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryDevice_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryService_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryService_USN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryService_LeaseTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryService_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryService_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryService_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryService_LastUpdate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDiscoveryService_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescription_DeviceDescriptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescription_DeviceInstanceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescription_ServiceInstanceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceDescription_URLBase(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceDescription_SpecVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceDescription_Host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_UDN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_DiscoveryDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_DeviceType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_FriendlyName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_DeviceCategory(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_Manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_ManufacturerOUI(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_ManufacturerURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_ModelDescription(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_ModelName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_ModelNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_ModelURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_UPC(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionDeviceInstance_PresentationURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionServiceInstance_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionServiceInstance_ServiceId(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionServiceInstance_ServiceDiscovery(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionServiceInstance_ServiceType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionServiceInstance_SCPDURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionServiceInstance_ControlURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_UPnPDescriptionServiceInstance_EventSubURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_upnp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int get_root_device_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); -int get_device_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); -int get_device_instance_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); -int get_service_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); #endif //__UPNP_H diff --git a/dmtree/tr181/usb.c b/dmtree/tr181/usb.c index 63862e34..b1229364 100644 --- a/dmtree/tr181/usb.c +++ b/dmtree/tr181/usb.c @@ -11,6 +11,1128 @@ #include "dmentry.h" #include "usb.h" +#define SYSFS_USB_DEVICES_PATH "/sys/bus/usb/devices" + +struct usb_port +{ + struct uci_section *dm_usb_port; + char *folder_name; + char *folder_path; + struct uci_section *dmsect; +}; + +struct usb_interface +{ + struct uci_section *dm_usb_iface; + char *iface_name; + char *iface_path; + char *statistics_path; + char *portlink; +}; + + +/************************************************************* +* INIT +*************************************************************/ +static void init_usb_port(struct uci_section *dm, char *folder_name, char *folder_path, struct usb_port *port) +{ + port->dm_usb_port = dm; + port->folder_name = dmstrdup(folder_name); + port->folder_path = dmstrdup(folder_path); +} + +static void init_usb_interface(struct uci_section *dm, char *iface_name, char *iface_path, char *statistics_path, char *portlink, struct usb_interface *iface) +{ + iface->dm_usb_iface = dm; + iface->iface_name = dmstrdup(iface_name); + iface->iface_path = dmstrdup(iface_path); + iface->portlink = dmstrdup(portlink); + iface->statistics_path = dmstrdup(statistics_path); +} + +/************************************************************* +* ENTRY METHOD +*************************************************************/ +static int read_sysfs_file(const char *file, char **value) +{ + char buf[128]; + int rc; + + rc = dm_read_sysfs_file(file, buf, sizeof(buf)); + *value = dmstrdup(buf); + + return rc; +} + +static int read_sysfs(const char *path, const char *name, char **value) +{ + char file[256]; + + snprintf(file, sizeof(file), "%s/%s", path, name); + return read_sysfs_file(file, value); +} + +static int __read_sysfs(const char *path, const char *name, char *dst, unsigned len) +{ + char file[256]; + + snprintf(file, sizeof(file), "%s/%s", path, name); + return dm_read_sysfs_file(file, dst, len); +} + +static int read_sysfs_usb_port(const struct usb_port *port, const char *name, char **value) +{ + return read_sysfs(port->folder_path, name, value); +} + +static int read_sysfs_usb_iface(const struct usb_interface *iface, const char *name, char **value) +{ + return read_sysfs(iface->iface_path, name, value); +} + +static int read_sysfs_usb_net_iface(const struct usb_interface *iface, const char *name, char **value) +{ + return get_net_device_sysfs(iface->iface_name, name, value); +} + +static int __read_sysfs_usb_port(const struct usb_port *port, const char *name, char *dst, unsigned len) +{ + return __read_sysfs(port->folder_path, name, dst, len); +} + +static int __read_sysfs_usb_iface(const struct usb_interface *iface, const char *name, char *dst, unsigned len) +{ + return __read_sysfs(iface->iface_path, name, dst, len); +} + +static void writeFileContent(const char *filepath, const char *data) +{ + FILE *fp = fopen(filepath, "ab"); + + if (fp != NULL) { + fputs(data, fp); + fclose(fp); + } +} + +static int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + DIR *dir; + struct dirent *ent; + char *iface_path, *statistics_path, *instnbr = NULL, *instance = NULL; + size_t length; + char **foldersplit; + struct usb_interface iface= {}; + LIST_HEAD(dup_list); + struct sysfs_dmsection *p; + + synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_interface", "port_link", "usb_iface_instance", &dup_list); + list_for_each_entry(p, &dup_list, list) { + char netfolderpath[256]; + char port_link[128]; + char iface_name[64]; + + port_link[0] = 0; + iface_name[0] = 0; + + snprintf(netfolderpath, sizeof(netfolderpath), "%s/%s/net", SYSFS_USB_DEVICES_PATH, p->sysfs_folder_name); + if(!isfolderexist(netfolderpath)){ + //dmuci_delete_by_section_unnamed_bbfdm(p->dm, NULL, NULL); + continue; + } + if(p->dm){ + foldersplit= strsplit(p->sysfs_folder_name, ":", &length); + snprintf(port_link, sizeof(port_link), "%s", foldersplit[0]); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, p->dm, "port_link", port_link); + } + sysfs_foreach_file(netfolderpath, dir, ent) { + if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0) + continue; + + snprintf(iface_name, sizeof(iface_name), "%s", ent->d_name); + break; + } + if (dir) + closedir(dir); + + dmasprintf(&iface_path, "%s/%s", netfolderpath, iface_name); + dmasprintf(&statistics_path, "%s/statistics", iface_path); + init_usb_interface(p->dm, iface_name, iface_path, statistics_path, port_link, &iface); + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, p->dm, "usb_iface_instance", "usb_iface_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &iface, instance) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *instnbr = NULL, *instance = NULL; + struct usb_port port = {0}; + struct sysfs_dmsection *p; + LIST_HEAD(dup_list); + regex_t regex1 = {}; + regex_t regex2 = {}; + + regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0); + regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); + check_create_dmmap_package("dmmap_usb"); + synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, + "dmmap_usb", "dmmap_port", "port_link", "usb_port_instance", &dup_list); + + list_for_each_entry(p, &dup_list, list) { + if(regexec(®ex1, p->sysfs_folder_name, 0, NULL, 0) != 0 && + regexec(®ex2, p->sysfs_folder_name, 0, NULL, 0) !=0 && + strstr(p->sysfs_folder_name, "usb") != p->sysfs_folder_name) { + dmuci_delete_by_section_unnamed_bbfdm(p->dm, NULL, NULL); + continue; + } + init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port); + instance = handle_update_instance(1, dmctx, &instnbr, + update_instance_alias_bbfdm, 3, p->dm, + "usb_port_instance", "usb_port_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + regfree(®ex1); + regfree(®ex2); + return 0; +} + +static int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct sysfs_dmsection *p; + char *instance = NULL, *instnbr = NULL; + struct usb_port port= {}; + LIST_HEAD(dup_list); + + check_create_dmmap_package("dmmap_usb"); + synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_host", "port_link", "usb_host_instance", &dup_list); + list_for_each_entry(p, &dup_list, list) { + if(!strstr(p->sysfs_folder_name, "usb")) + continue; + + init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port); + port.dmsect= p->dm; + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, p->dm, "usb_host_instance", "usb_host_alias"); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, char *dmmap_package, char *dmmap_section, char *opt_name, char* inst_opt, int is_root, struct list_head *dup_list) +{ + struct uci_section *s, *stmp, *dmmap_sect; + DIR *dir; + struct dirent *ent; + char *v, *sysfs_rep_path, *instance = NULL; + struct sysfs_dmsection *p; + regex_t regex1 = {}, regex2 = {}; + + regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0); + regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); + + LIST_HEAD(dup_list_no_inst); + dmmap_file_path_get(dmmap_package); + + sysfs_foreach_file(sysfsrep, dir, ent) { + if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0) + continue; + + if (regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) ==0) { + char deviceClassFile[256]; + char deviceClass[16]; + + snprintf(deviceClassFile, sizeof(deviceClassFile), "%s/%s/bDeviceClass", sysfsrep, ent->d_name); + dm_read_sysfs_file(deviceClassFile, deviceClass, sizeof(deviceClass)); + + if(strncmp(deviceClass, "09", 2) == 0){ + char hubpath[256]; + + snprintf(hubpath, sizeof(hubpath), "%s/%s", sysfsrep, ent->d_name); + synchronize_usb_devices_with_dmmap_opt_recursively(hubpath, dmmap_package, dmmap_section, opt_name, inst_opt, 0, dup_list); + } + /* + * create/update corresponding dmmap section that have same config_section link and using param_value_array + */ + dmasprintf(&sysfs_rep_path, "%s/%s", sysfsrep, ent->d_name); + if ((dmmap_sect = get_dup_section_in_dmmap_opt(dmmap_package, dmmap_section, opt_name, sysfs_rep_path)) == NULL) { + dmuci_add_section_bbfdm(dmmap_package, dmmap_section, &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, opt_name, sysfs_rep_path); + } + dmuci_get_value_by_section_string(dmmap_sect, inst_opt, &instance); + /* + * Add system and dmmap sections to the list + */ + if (instance == NULL || strlen(instance) <= 0) + add_sysfs_sectons_list_paramameter(&dup_list_no_inst, dmmap_sect, ent->d_name, sysfs_rep_path); + else + add_sysfs_sectons_list_paramameter(dup_list, dmmap_sect, ent->d_name, sysfs_rep_path); + } + } + if (dir) + closedir(dir); + regfree(®ex1); + regfree(®ex2); + /* + * fusion two lists + */ + list_for_each_entry(p, &dup_list_no_inst, list) { + add_sysfs_sectons_list_paramameter(dup_list, p->dm, p->sysfs_folder_name, p->sysfs_folder_path); + } + /* + * Delete unused dmmap sections + */ + if(is_root){ + uci_path_foreach_sections_safe(bbfdm, dmmap_package, dmmap_section, stmp, s) { + dmuci_get_value_by_section_string(s, opt_name, &v); + if(isfolderexist(v) == 0){ + dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); + } + } + } + return 0; +} + +static int browseUSBUSBHostsHostDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct sysfs_dmsection *p; + char *instance = NULL, *instnbr = NULL; + struct usb_port port= {}; + struct usb_port *prev_port= (struct usb_port *)prev_data; + LIST_HEAD(dup_list); + + check_create_dmmap_package("dmmap_usb"); + synchronize_usb_devices_with_dmmap_opt_recursively(prev_port->folder_path, "dmmap_usb", "dmmap_host_device", "port_link", "usb_host_device_instance", 1, &dup_list); + list_for_each_entry(p, &dup_list, list) { + init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port); + port.dmsect= prev_port->dmsect; + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, p->dm, "usb_host_device_instance", "usb_host_device_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int browseUSBUSBHostsHostDeviceConfigurationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + const struct usb_port *usb_dev = prev_data; + struct usb_port port = {}; + struct uci_section *s; + char nbre[16], *v, *instnbr = NULL; + + __read_sysfs_usb_port(usb_dev, "bNumConfigurations", nbre, sizeof(nbre)); + if(nbre[0] == '0') + return 0; + + check_create_dmmap_package("dmmap_usb"); + s = is_dmmap_section_exist("dmmap_usb", "usb_device_conf"); + if (!s) dmuci_add_section_bbfdm("dmmap_usb", "usb_device_conf", &s, &v); + + init_usb_port(s, usb_dev->folder_name, usb_dev->folder_path, &port); + handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "usb_device_conf_instance", "usb_device_conf_alias"); + DM_LINK_INST_OBJ(dmctx, parent_node, &port, "1"); + return 0; +} + +static int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + DIR *dir; + struct dirent *ent; + struct usb_port *usb_dev = (struct usb_port*)prev_data; + struct usb_port port = {0}; + char *sysfs_rep_path, *v, *instance = NULL, *instnbr = NULL; + struct uci_section *dmmap_sect; + regex_t regex1 = {}; + regex_t regex2 = {}; + + regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]:[0-9][0-9]*\\.[0-9]*[0-9]$", 0); + regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]:[0-9][0-9]*\\.[0-9]*[0-9]$", 0); + check_create_dmmap_package("dmmap_usb"); + sysfs_foreach_file(usb_dev->folder_path, dir, ent) { + if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0) + continue; + if(regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) ==0) { + dmasprintf(&sysfs_rep_path, "%s/%s", usb_dev->folder_path, ent->d_name); + if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_usb", "usb_device_conf_interface", "port_link", sysfs_rep_path)) == NULL) { + dmuci_add_section_bbfdm("dmmap_usb", "usb_device_conf_interface", &dmmap_sect, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "port_link", sysfs_rep_path); + } + + init_usb_port(dmmap_sect, ent->d_name, sysfs_rep_path, &port); + instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "usb_device_conf_iface_instance", "usb_device_conf_iface_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP) + break; + } + } + if (dir) + closedir(dir); + regfree(®ex1); + regfree(®ex2); + return 0; +} + +/************************************************************* +* GET & SET PARAM +**************************************************************/ +static int get_USB_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + DIR *dir; + struct dirent *ent; + char filename[128]; + char buffer[64]; + int nbre= 0; + ssize_t rc; + + if ((dir = opendir ("/sys/class/net")) == NULL) + return 0; + + while ((ent = readdir (dir)) != NULL) { + sprintf(filename, "/sys/class/net/%s", ent->d_name); + rc = readlink (filename, buffer, sizeof(buffer) - 1); + if (rc > 0) { + buffer[rc] = 0; + + if(strstr(buffer, "/usb")) + nbre++; + } + } + closedir(dir); + dmasprintf(value, "%d", nbre); + return 0; +} + +static int get_USB_PortNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + DIR *dir; + struct dirent *ent; + int nbre = 0; + regex_t regex1 = {}; + regex_t regex2 = {}; + + regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0); + regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); + + sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) { + if(regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) ==0 || strstr(ent->d_name, "usb") == ent->d_name) + nbre++; + } + if (dir) + closedir(dir); + + regfree(®ex1); + regfree(®ex2); + + dmasprintf(value, "%d", nbre); + return 0; +} + +static int isfileexist(const char *filepath) +{ + return access(filepath, F_OK) == 0; +} + +static int get_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char carrier[8]; + + __read_sysfs_usb_iface(data, "carrier", carrier, sizeof(carrier)); + + if (carrier[0] == '1') + *value = "1"; + else + *value = "0"; + return 0; +} + +static int set_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_USBInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char carrier[8]; + + __read_sysfs_usb_iface(data, "carrier", carrier, sizeof(carrier)); + + if (carrier[0] == '1') + *value = "up"; + else + *value = "down"; + return 0; +} + +static int get_USBInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct usb_interface *usbiface= (struct usb_interface *)data; + dmuci_get_value_by_section_string(usbiface->dm_usb_iface, "usb_iface_alias", value); + return 0; +} + +static int set_USBInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct usb_interface *usbiface= (struct usb_interface *)data; + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + DMUCI_SET_VALUE_BY_SECTION(bbfdm, usbiface->dm_usb_iface, "usb_iface_alias", value); + break; + } + return 0; +} + +static int get_USBInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct usb_interface *usbiface= (struct usb_interface *)data; + dmasprintf(value, "%s", usbiface->iface_name); + return 0; +} + +static int get_USBInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + const struct usb_interface *iface = data; + + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), iface->iface_name, value); + return 0; +} + +static int set_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_USBInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_USBInterface_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_iface(data, "address", value); +} + +static int get_USBInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_iface(data, "queues/tx-0/tx_maxrate", value); +} + +static int get_USBInterface_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_USBInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_net_iface(data, "statistics/tx_bytes", value); +} + +static int get_USBInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_net_iface(data, "statistics/rx_bytes", value); +} + +static int get_USBInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_net_iface(data, "statistics/tx_packets", value); +} + +static int get_USBInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_net_iface(data, "statistics/rx_packets", value); +} + +static int get_USBInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_net_iface(data, "statistics/tx_errors", value); +} + +static int get_USBInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_net_iface(data, "statistics/rx_errors", value); +} + +static int get_USBInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_USBInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_USBInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_net_iface(data, "statistics/tx_dropped", value); +} + +static int get_USBInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_net_iface(data, "statistics/rx_dropped", value); +} + +static int get_USBInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_USBInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_net_iface(data, "statistics/multicast", value); +} + +static int get_USBInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_USBInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_USBInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_USBPort_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct usb_port* port=(struct usb_port *)data; + dmuci_get_value_by_section_string(port->dm_usb_port, "usb_port_alias", value); + return 0; +} + +static int set_USBPort_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct usb_port* port = (struct usb_port *)data; + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(port->dm_usb_port, "usb_port_alias", value); + break; + } + return 0; +} + +static int get_USBPort_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + const struct usb_port *port = data; + *value = dmstrdup(port->folder_name); + return 0; +} + +static int get_USBPort_Standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char buf[16]; + + __read_sysfs_usb_port(data, "bcdDevice", buf, sizeof(buf)); + dmasprintf(value, "%c.%c", buf[0], buf[0]); + return 0; +} + +static int get_USBPort_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + const struct usb_port *port = data; + char deviceclass[32]; + + __read_sysfs_usb_port(port, "bDeviceClass", deviceclass, sizeof(deviceclass)); + + if(strstr(port->folder_name, "usb") == port->folder_name) + *value= "Host"; + else if (strcmp(deviceclass, "09") == 0) + *value= "Hub"; + else + *value= "Device"; + return 0; +} + +static int get_USBPort_Receptacle(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return 0; +} + +static int get_USBPort_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char speed[16]; + + __read_sysfs_usb_port(data, "speed", speed, sizeof(speed)); + + if(strcmp(speed, "1.5") == 0) + *value= "Low"; + else if(strcmp(speed, "12") == 0) + *value= "Full"; + else if(strcmp(speed, "480") == 0) + *value= "High"; + else + *value= "Super"; + return 0; +} + +static int get_USBPort_Power(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char pwrctl[16]; + + __read_sysfs_usb_port(data, "power/control", pwrctl, sizeof(pwrctl)); + + if (pwrctl[0] == 0) + *value = ""; + else if (!strcmp(pwrctl, "auto")) + *value ="Self"; + else + *value ="Bus"; + + return 0; +} + +static int get_USBUSBHosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + DIR *dir; + struct dirent *ent; + int nbre= 0; + + sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) { + if(strstr(ent->d_name, "usb") == ent->d_name) + nbre++; + } + if (dir) closedir(dir); + dmasprintf(value, "%d", nbre); + return 0; +} + +static int get_USBUSBHostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct usb_port* port=(struct usb_port *)data; + dmuci_get_value_by_section_string(port->dm_usb_port, "usb_host_alias", value); + return 0; +} + +static int set_USBUSBHostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct usb_port* port=(struct usb_port *)data; + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(port->dm_usb_port, "usb_host_alias", value); + break; + } + return 0; +} + +static int get_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char up[32]; + + __read_sysfs_usb_port(data, "power/wakeup", up, sizeof(up)); + *value = strcmp(up, "enabled") == 0 ? "1" : "0"; + return 0; +} + +static int set_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct usb_port *usbhost= (struct usb_port *)data; + bool b; + char *filepath; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmasprintf(&filepath, "%s/power/wakeup", usbhost->folder_path); + if(b) + writeFileContent(usbhost->folder_path, "enabled"); + else + writeFileContent(usbhost->folder_path, "disabled"); + break; + } + return 0; +} + +static int get_USBUSBHostsHost_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct usb_port* port=(struct usb_port *)data; + dmasprintf(value, "%s", port->folder_name); + return 0; +} + +static int get_USBUSBHostsHost_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char serial[64]; + + __read_sysfs_usb_port(data, "serial", serial, sizeof(serial)); + + if(strcasestr(serial, "ohci")!=NULL) + *value= "OHCI"; + else if(strcasestr(serial, "ehci")!=NULL) + *value= "EHCI"; + else if(strcasestr(serial, "uhci")!=NULL) + *value= "UHCI"; + else + *value= "xHCI"; + return 0; +} + +static int get_USBUSBHostsHost_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_USBUSBHostsHost_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char power[64]; + + __read_sysfs_usb_port(data, "power/level", power, sizeof(power)); + + if(power[0] == 0 || strcmp(power, "suspend") == 0) + *value= "false"; + else + *value= "true"; + + return 0; +} + +static int set_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct usb_port *host= (struct usb_port *)data; + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + char *filepath; + dmasprintf(&filepath, "%s/power/level", host->folder_path); + if (!isfileexist(filepath)) + break; + writeFileContent(filepath, b?"on":"suspend"); + break; + } + return 0; +} + +static int get_USBUSBHostsHost_USBVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + const struct usb_port *port = data; + char file[256]; + char buf[16] = { 0, 0 }; + + snprintf(file, sizeof(file), "%s/bcdDevice", port->folder_path); + dm_read_sysfs_file(file, buf, sizeof(buf)); + + dmasprintf(value, "%c.%c", buf[1], buf[2]); + return 0; +} + +static int get_number_devices(char *folderpath, int *nbre) +{ + DIR *dir; + struct dirent *ent; + regex_t regex1 = {}; + regex_t regex2 = {}; + + regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0); + regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); + + sysfs_foreach_file(folderpath, dir, ent) { + if (regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) == 0) { + char deviceClassFile[256]; + char deviceClass[16]; + + snprintf(deviceClassFile, sizeof(deviceClassFile), "%s/%s/bDeviceClass", folderpath, ent->d_name); + dm_read_sysfs_file(deviceClassFile, deviceClass, sizeof(deviceClass)); + + if(strncmp(deviceClass, "09", 2) == 0){ + char hubpath[256]; + + snprintf(hubpath, sizeof(hubpath), "%s/%s", folderpath, ent->d_name); + get_number_devices(hubpath, nbre); + } + (*nbre)++; + } + } + if (dir) + closedir(dir); + regfree(®ex1); + regfree(®ex2); + return 0; +} + +static int get_USBUSBHostsHost_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct usb_port* usb_host= (struct usb_port *) data; + int dev_nbre= 0; + + get_number_devices(usb_host->folder_path, &dev_nbre); + dmasprintf(value, "%d", dev_nbre); + return 0; +} + +static int get_USBUSBHostsHostDevice_DeviceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct usb_port *usbdev= (struct usb_port *)data; + size_t length; + char **filename= strsplit(usbdev->folder_name, "-", &length); + char **port= strsplit(filename[1], ".", &length); + dmasprintf(value ,"%s", port[0]); + + return 0; +} + +static int get_USBUSBHostsHostDevice_USBVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "bcdDevice", value); +} + +static int get_USBUSBHostsHostDevice_DeviceClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "bDeviceClass", value); +} + +static int get_USBUSBHostsHostDevice_DeviceSubClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "bDeviceSubClass", value); +} + +static int get_USBUSBHostsHostDevice_DeviceVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_USBUSBHostsHostDevice_DeviceProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "bDeviceProtocol", value); +} + +static int get_USBUSBHostsHostDevice_ProductID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "idProduct", value); +} + +static int get_USBUSBHostsHostDevice_VendorID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "idVendor", value); +} + +static int get_USBUSBHostsHostDevice_Manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "manufacturer", value); +} + +static int get_USBUSBHostsHostDevice_ProductClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "product", value); +} + +static int get_USBUSBHostsHostDevice_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "urbnum", value); +} + +static int get_USBUSBHostsHostDevice_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct usb_port *port= (struct usb_port *)data; + size_t length; + char **busname, **portname; + regex_t regex1 = {}; + regex_t regex2 = {}; + + regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0); + regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); + if (regexec(®ex1, port->folder_name, 0, NULL, 0) == 0 || regexec(®ex2, port->folder_name, 0, NULL, 0) == 0) { + busname = strsplit(port->folder_name, "-", &length); + portname = strsplit(busname[1], ".", &length); + *value = dmstrdup(portname[0]); + goto out; + } + *value = "0"; +out: + regfree(®ex1); + regfree(®ex2); + return 0; +} + +static int get_USBUSBHostsHostDevice_USBPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct usb_port *port= (struct usb_port *)data; + adm_entry_get_linker_param(ctx, dm_print_path("%s%cUSB%cPort%c", dmroot, dm_delim, dm_delim, dm_delim), port->folder_name, value); + return 0; +} + +static int get_USBUSBHostsHostDevice_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return get_USBPort_Rate(refparam, ctx, data, instance, value); +} + +static int get_USBUSBHostsHostDevice_Parent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct usb_port *port = (struct usb_port*)data; + char *v; + regex_t regex1 = {}; + + regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); + if(regexec(®ex1, port->folder_name, 0, NULL, 0) != 0 || port->dmsect == NULL){ + *value = ""; + goto out; + } + dmuci_get_value_by_section_string(port->dmsect, "usb_host_instance", &v); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cUSB%cUSBHosts%cHost%c%s%vDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim, v, dm_delim, dm_delim), port->folder_name, value); + if (*value == NULL) + *value = ""; +out: + regfree(®ex1); + return 0; +} + +static int get_USBUSBHostsHostDevice_MaxChildren(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "maxchild", value); +} + +static int get_USBUSBHostsHostDevice_IsSuspended(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char status[16]; + + __read_sysfs_usb_port(data, "power/runtime_status", status, sizeof(status)); + if(strncmp(status, "suspended", 9) == 0) + *value= "1"; + else + *value = "0"; + return 0; +} + +static int get_USBUSBHostsHostDevice_IsSelfPowered(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_USBUSBHostsHostDevice_ConfigurationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "bNumConfigurations", value); +} + +static int get_USBUSBHostsHostDeviceConfiguration_ConfigurationNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "bConfigurationValue", value); +} + +static int get_USBUSBHostsHostDeviceConfiguration_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "bNumInterfaces", value); +} + +static int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "bInterfaceNumber", value); +} + +static int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "bInterfaceClass", value); +} + +static int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceSubClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "bInterfaceSubClass", value); +} + +static int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return read_sysfs_usb_port(data, "bInterfaceProtocol", value); +} + +static int get_linker_usb_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + struct usb_port *port = (struct usb_port *)data; + if (port && port->folder_name) { + *linker = dmstrdup(port->folder_name); + return 0; + } else { + *linker = ""; + return 0; + } +} + +static int get_linker_usb_host_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + struct usb_port *port = (struct usb_port *)data; + if(port && port->folder_name) { + *linker = dmstrdup(port->folder_name); + return 0; + } else { + *linker = ""; + return 0; + } +} + /* *** Device.USB. *** */ DMOBJ tUSBObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -170,1105 +1292,3 @@ DMLEAF tUSBUSBHostsHostDeviceConfigurationInterfaceParams[] = { {"InterfaceProtocol", &DMREAD, DMT_HEXBIN, get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceProtocol, NULL, NULL, NULL, BBFDM_BOTH}, {0} }; - -/************************************************************* -* INIT -*************************************************************/ -static void init_usb_port(struct uci_section *dm, char *folder_name, char *folder_path, struct usb_port *port) -{ - port->dm_usb_port = dm; - port->folder_name = dmstrdup(folder_name); - port->folder_path = dmstrdup(folder_path); -} - -static void init_usb_interface(struct uci_section *dm, char *iface_name, char *iface_path, char *statistics_path, char *portlink, struct usb_interface *iface) -{ - iface->dm_usb_iface = dm; - iface->iface_name = dmstrdup(iface_name); - iface->iface_path = dmstrdup(iface_path); - iface->portlink = dmstrdup(portlink); - iface->statistics_path = dmstrdup(statistics_path); -} - -/************************************************************* -* ENTRY METHOD -*************************************************************/ -static int read_sysfs_file(const char *file, char **value) -{ - char buf[128]; - int rc; - - rc = dm_read_sysfs_file(file, buf, sizeof(buf)); - *value = dmstrdup(buf); - - return rc; -} - -static int read_sysfs(const char *path, const char *name, char **value) -{ - char file[256]; - - snprintf(file, sizeof(file), "%s/%s", path, name); - return read_sysfs_file(file, value); -} - -static int __read_sysfs(const char *path, const char *name, char *dst, unsigned len) -{ - char file[256]; - - snprintf(file, sizeof(file), "%s/%s", path, name); - return dm_read_sysfs_file(file, dst, len); -} - -static int read_sysfs_usb_port(const struct usb_port *port, const char *name, char **value) -{ - return read_sysfs(port->folder_path, name, value); -} - -static int read_sysfs_usb_iface(const struct usb_interface *iface, const char *name, char **value) -{ - return read_sysfs(iface->iface_path, name, value); -} - -static int read_sysfs_usb_net_iface(const struct usb_interface *iface, const char *name, char **value) -{ - return get_net_device_sysfs(iface->iface_name, name, value); -} - -static int __read_sysfs_usb_port(const struct usb_port *port, const char *name, char *dst, unsigned len) -{ - return __read_sysfs(port->folder_path, name, dst, len); -} - -static int __read_sysfs_usb_iface(const struct usb_interface *iface, const char *name, char *dst, unsigned len) -{ - return __read_sysfs(iface->iface_path, name, dst, len); -} - -static void writeFileContent(const char *filepath, const char *data) -{ - FILE *fp = fopen(filepath, "ab"); - - if (fp != NULL) { - fputs(data, fp); - fclose(fp); - } -} - -int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - DIR *dir; - struct dirent *ent; - char *iface_path, *statistics_path, *instnbr = NULL, *instance = NULL; - size_t length; - char **foldersplit; - struct usb_interface iface= {}; - LIST_HEAD(dup_list); - struct sysfs_dmsection *p; - - synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_interface", "port_link", "usb_iface_instance", &dup_list); - list_for_each_entry(p, &dup_list, list) { - char netfolderpath[256]; - char port_link[128]; - char iface_name[64]; - - port_link[0] = 0; - iface_name[0] = 0; - - snprintf(netfolderpath, sizeof(netfolderpath), "%s/%s/net", SYSFS_USB_DEVICES_PATH, p->sysfs_folder_name); - if(!isfolderexist(netfolderpath)){ - //dmuci_delete_by_section_unnamed_bbfdm(p->dm, NULL, NULL); - continue; - } - if(p->dm){ - foldersplit= strsplit(p->sysfs_folder_name, ":", &length); - snprintf(port_link, sizeof(port_link), "%s", foldersplit[0]); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, p->dm, "port_link", port_link); - } - sysfs_foreach_file(netfolderpath, dir, ent) { - if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0) - continue; - - snprintf(iface_name, sizeof(iface_name), "%s", ent->d_name); - break; - } - if (dir) - closedir(dir); - - dmasprintf(&iface_path, "%s/%s", netfolderpath, iface_name); - dmasprintf(&statistics_path, "%s/statistics", iface_path); - init_usb_interface(p->dm, iface_name, iface_path, statistics_path, port_link, &iface); - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, p->dm, "usb_iface_instance", "usb_iface_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &iface, instance) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *instnbr = NULL, *instance = NULL; - struct usb_port port = {0}; - struct sysfs_dmsection *p; - LIST_HEAD(dup_list); - regex_t regex1 = {}; - regex_t regex2 = {}; - - regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0); - regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); - check_create_dmmap_package("dmmap_usb"); - synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, - "dmmap_usb", "dmmap_port", "port_link", "usb_port_instance", &dup_list); - - list_for_each_entry(p, &dup_list, list) { - if(regexec(®ex1, p->sysfs_folder_name, 0, NULL, 0) != 0 && - regexec(®ex2, p->sysfs_folder_name, 0, NULL, 0) !=0 && - strstr(p->sysfs_folder_name, "usb") != p->sysfs_folder_name) { - dmuci_delete_by_section_unnamed_bbfdm(p->dm, NULL, NULL); - continue; - } - init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port); - instance = handle_update_instance(1, dmctx, &instnbr, - update_instance_alias_bbfdm, 3, p->dm, - "usb_port_instance", "usb_port_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - regfree(®ex1); - regfree(®ex2); - return 0; -} - -int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct sysfs_dmsection *p; - char *instance = NULL, *instnbr = NULL; - struct usb_port port= {}; - LIST_HEAD(dup_list); - - check_create_dmmap_package("dmmap_usb"); - synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_host", "port_link", "usb_host_instance", &dup_list); - list_for_each_entry(p, &dup_list, list) { - if(!strstr(p->sysfs_folder_name, "usb")) - continue; - - init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port); - port.dmsect= p->dm; - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, p->dm, "usb_host_instance", "usb_host_alias"); - - if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, char *dmmap_package, char *dmmap_section, char *opt_name, char* inst_opt, int is_root, struct list_head *dup_list) -{ - struct uci_section *s, *stmp, *dmmap_sect; - DIR *dir; - struct dirent *ent; - char *v, *sysfs_rep_path, *instance = NULL; - struct sysfs_dmsection *p; - regex_t regex1 = {}, regex2 = {}; - - regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0); - regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); - - LIST_HEAD(dup_list_no_inst); - dmmap_file_path_get(dmmap_package); - - sysfs_foreach_file(sysfsrep, dir, ent) { - if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0) - continue; - - if (regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) ==0) { - char deviceClassFile[256]; - char deviceClass[16]; - - snprintf(deviceClassFile, sizeof(deviceClassFile), "%s/%s/bDeviceClass", sysfsrep, ent->d_name); - dm_read_sysfs_file(deviceClassFile, deviceClass, sizeof(deviceClass)); - - if(strncmp(deviceClass, "09", 2) == 0){ - char hubpath[256]; - - snprintf(hubpath, sizeof(hubpath), "%s/%s", sysfsrep, ent->d_name); - synchronize_usb_devices_with_dmmap_opt_recursively(hubpath, dmmap_package, dmmap_section, opt_name, inst_opt, 0, dup_list); - } - /* - * create/update corresponding dmmap section that have same config_section link and using param_value_array - */ - dmasprintf(&sysfs_rep_path, "%s/%s", sysfsrep, ent->d_name); - if ((dmmap_sect = get_dup_section_in_dmmap_opt(dmmap_package, dmmap_section, opt_name, sysfs_rep_path)) == NULL) { - dmuci_add_section_bbfdm(dmmap_package, dmmap_section, &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, opt_name, sysfs_rep_path); - } - dmuci_get_value_by_section_string(dmmap_sect, inst_opt, &instance); - /* - * Add system and dmmap sections to the list - */ - if (instance == NULL || strlen(instance) <= 0) - add_sysfs_sectons_list_paramameter(&dup_list_no_inst, dmmap_sect, ent->d_name, sysfs_rep_path); - else - add_sysfs_sectons_list_paramameter(dup_list, dmmap_sect, ent->d_name, sysfs_rep_path); - } - } - if (dir) - closedir(dir); - regfree(®ex1); - regfree(®ex2); - /* - * fusion two lists - */ - list_for_each_entry(p, &dup_list_no_inst, list) { - add_sysfs_sectons_list_paramameter(dup_list, p->dm, p->sysfs_folder_name, p->sysfs_folder_path); - } - /* - * Delete unused dmmap sections - */ - if(is_root){ - uci_path_foreach_sections_safe(bbfdm, dmmap_package, dmmap_section, stmp, s) { - dmuci_get_value_by_section_string(s, opt_name, &v); - if(isfolderexist(v) == 0){ - dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); - } - } - } - return 0; -} - -int browseUSBUSBHostsHostDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct sysfs_dmsection *p; - char *instance = NULL, *instnbr = NULL; - struct usb_port port= {}; - struct usb_port *prev_port= (struct usb_port *)prev_data; - LIST_HEAD(dup_list); - - check_create_dmmap_package("dmmap_usb"); - synchronize_usb_devices_with_dmmap_opt_recursively(prev_port->folder_path, "dmmap_usb", "dmmap_host_device", "port_link", "usb_host_device_instance", 1, &dup_list); - list_for_each_entry(p, &dup_list, list) { - init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port); - port.dmsect= prev_port->dmsect; - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, p->dm, "usb_host_device_instance", "usb_host_device_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int browseUSBUSBHostsHostDeviceConfigurationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - const struct usb_port *usb_dev = prev_data; - struct usb_port port = {}; - struct uci_section *s; - char nbre[16], *v, *instnbr = NULL; - - __read_sysfs_usb_port(usb_dev, "bNumConfigurations", nbre, sizeof(nbre)); - if(nbre[0] == '0') - return 0; - - check_create_dmmap_package("dmmap_usb"); - s = is_dmmap_section_exist("dmmap_usb", "usb_device_conf"); - if (!s) dmuci_add_section_bbfdm("dmmap_usb", "usb_device_conf", &s, &v); - - init_usb_port(s, usb_dev->folder_name, usb_dev->folder_path, &port); - handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "usb_device_conf_instance", "usb_device_conf_alias"); - DM_LINK_INST_OBJ(dmctx, parent_node, &port, "1"); - return 0; -} - -int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - DIR *dir; - struct dirent *ent; - struct usb_port *usb_dev = (struct usb_port*)prev_data; - struct usb_port port = {0}; - char *sysfs_rep_path, *v, *instance = NULL, *instnbr = NULL; - struct uci_section *dmmap_sect; - regex_t regex1 = {}; - regex_t regex2 = {}; - - regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]:[0-9][0-9]*\\.[0-9]*[0-9]$", 0); - regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]:[0-9][0-9]*\\.[0-9]*[0-9]$", 0); - check_create_dmmap_package("dmmap_usb"); - sysfs_foreach_file(usb_dev->folder_path, dir, ent) { - if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0) - continue; - if(regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) ==0) { - dmasprintf(&sysfs_rep_path, "%s/%s", usb_dev->folder_path, ent->d_name); - if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_usb", "usb_device_conf_interface", "port_link", sysfs_rep_path)) == NULL) { - dmuci_add_section_bbfdm("dmmap_usb", "usb_device_conf_interface", &dmmap_sect, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dmmap_sect, "port_link", sysfs_rep_path); - } - - init_usb_port(dmmap_sect, ent->d_name, sysfs_rep_path, &port); - instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, dmmap_sect, "usb_device_conf_iface_instance", "usb_device_conf_iface_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP) - break; - } - } - if (dir) - closedir(dir); - regfree(®ex1); - regfree(®ex2); - return 0; -} - -/************************************************************* -* GET & SET PARAM -**************************************************************/ -int get_USB_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - DIR *dir; - struct dirent *ent; - char filename[128]; - char buffer[64]; - int nbre= 0; - ssize_t rc; - - if ((dir = opendir ("/sys/class/net")) == NULL) - return 0; - - while ((ent = readdir (dir)) != NULL) { - sprintf(filename, "/sys/class/net/%s", ent->d_name); - rc = readlink (filename, buffer, sizeof(buffer) - 1); - if (rc > 0) { - buffer[rc] = 0; - - if(strstr(buffer, "/usb")) - nbre++; - } - } - closedir(dir); - dmasprintf(value, "%d", nbre); - return 0; -} - -int get_USB_PortNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - DIR *dir; - struct dirent *ent; - int nbre = 0; - regex_t regex1 = {}; - regex_t regex2 = {}; - - regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0); - regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); - - sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) { - if(regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) ==0 || strstr(ent->d_name, "usb") == ent->d_name) - nbre++; - } - if (dir) - closedir(dir); - - regfree(®ex1); - regfree(®ex2); - - dmasprintf(value, "%d", nbre); - return 0; -} - -static int isfileexist(const char *filepath) -{ - return access(filepath, F_OK) == 0; -} - -int get_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char carrier[8]; - - __read_sysfs_usb_iface(data, "carrier", carrier, sizeof(carrier)); - - if (carrier[0] == '1') - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_USBInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char carrier[8]; - - __read_sysfs_usb_iface(data, "carrier", carrier, sizeof(carrier)); - - if (carrier[0] == '1') - *value = "up"; - else - *value = "down"; - return 0; -} - -int get_USBInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct usb_interface *usbiface= (struct usb_interface *)data; - dmuci_get_value_by_section_string(usbiface->dm_usb_iface, "usb_iface_alias", value); - return 0; -} - -int set_USBInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct usb_interface *usbiface= (struct usb_interface *)data; - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - DMUCI_SET_VALUE_BY_SECTION(bbfdm, usbiface->dm_usb_iface, "usb_iface_alias", value); - break; - } - return 0; -} - -int get_USBInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct usb_interface *usbiface= (struct usb_interface *)data; - dmasprintf(value, "%s", usbiface->iface_name); - return 0; -} - -int get_USBInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - const struct usb_interface *iface = data; - - adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), iface->iface_name, value); - return 0; -} - -int set_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_USBInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_USBInterface_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_iface(data, "address", value); -} - -int get_USBInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_iface(data, "queues/tx-0/tx_maxrate", value); -} - -int get_USBInterface_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_USBInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_net_iface(data, "statistics/tx_bytes", value); -} - -int get_USBInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_net_iface(data, "statistics/rx_bytes", value); -} - -int get_USBInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_net_iface(data, "statistics/tx_packets", value); -} - -int get_USBInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_net_iface(data, "statistics/rx_packets", value); -} - -int get_USBInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_net_iface(data, "statistics/tx_errors", value); -} - -int get_USBInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_net_iface(data, "statistics/rx_errors", value); -} - -int get_USBInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_USBInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_USBInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_net_iface(data, "statistics/tx_dropped", value); -} - -int get_USBInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_net_iface(data, "statistics/rx_dropped", value); -} - -int get_USBInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_USBInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_net_iface(data, "statistics/multicast", value); -} - -int get_USBInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_USBInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_USBInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_USBPort_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct usb_port* port=(struct usb_port *)data; - dmuci_get_value_by_section_string(port->dm_usb_port, "usb_port_alias", value); - return 0; -} - -int set_USBPort_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct usb_port* port = (struct usb_port *)data; - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(port->dm_usb_port, "usb_port_alias", value); - break; - } - return 0; -} - -int get_USBPort_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - const struct usb_port *port = data; - *value = dmstrdup(port->folder_name); - return 0; -} - -int get_USBPort_Standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char buf[16]; - - __read_sysfs_usb_port(data, "bcdDevice", buf, sizeof(buf)); - dmasprintf(value, "%c.%c", buf[0], buf[0]); - return 0; -} - -int get_USBPort_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - const struct usb_port *port = data; - char deviceclass[32]; - - __read_sysfs_usb_port(port, "bDeviceClass", deviceclass, sizeof(deviceclass)); - - if(strstr(port->folder_name, "usb") == port->folder_name) - *value= "Host"; - else if (strcmp(deviceclass, "09") == 0) - *value= "Hub"; - else - *value= "Device"; - return 0; -} - -int get_USBPort_Receptacle(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return 0; -} - -int get_USBPort_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char speed[16]; - - __read_sysfs_usb_port(data, "speed", speed, sizeof(speed)); - - if(strcmp(speed, "1.5") == 0) - *value= "Low"; - else if(strcmp(speed, "12") == 0) - *value= "Full"; - else if(strcmp(speed, "480") == 0) - *value= "High"; - else - *value= "Super"; - return 0; -} - -int get_USBPort_Power(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char pwrctl[16]; - - __read_sysfs_usb_port(data, "power/control", pwrctl, sizeof(pwrctl)); - - if (pwrctl[0] == 0) - *value = ""; - else if (!strcmp(pwrctl, "auto")) - *value ="Self"; - else - *value ="Bus"; - - return 0; -} - -int get_USBUSBHosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - DIR *dir; - struct dirent *ent; - int nbre= 0; - - sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) { - if(strstr(ent->d_name, "usb") == ent->d_name) - nbre++; - } - if (dir) closedir(dir); - dmasprintf(value, "%d", nbre); - return 0; -} - -int get_USBUSBHostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct usb_port* port=(struct usb_port *)data; - dmuci_get_value_by_section_string(port->dm_usb_port, "usb_host_alias", value); - return 0; -} - -int set_USBUSBHostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct usb_port* port=(struct usb_port *)data; - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(port->dm_usb_port, "usb_host_alias", value); - break; - } - return 0; -} - -int get_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char up[32]; - - __read_sysfs_usb_port(data, "power/wakeup", up, sizeof(up)); - *value = strcmp(up, "enabled") == 0 ? "1" : "0"; - return 0; -} - -int set_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct usb_port *usbhost= (struct usb_port *)data; - bool b; - char *filepath; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmasprintf(&filepath, "%s/power/wakeup", usbhost->folder_path); - if(b) - writeFileContent(usbhost->folder_path, "enabled"); - else - writeFileContent(usbhost->folder_path, "disabled"); - break; - } - return 0; -} - -int get_USBUSBHostsHost_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct usb_port* port=(struct usb_port *)data; - dmasprintf(value, "%s", port->folder_name); - return 0; -} - -int get_USBUSBHostsHost_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char serial[64]; - - __read_sysfs_usb_port(data, "serial", serial, sizeof(serial)); - - if(strcasestr(serial, "ohci")!=NULL) - *value= "OHCI"; - else if(strcasestr(serial, "ehci")!=NULL) - *value= "EHCI"; - else if(strcasestr(serial, "uhci")!=NULL) - *value= "UHCI"; - else - *value= "xHCI"; - return 0; -} - -int get_USBUSBHostsHost_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_USBUSBHostsHost_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char power[64]; - - __read_sysfs_usb_port(data, "power/level", power, sizeof(power)); - - if(power[0] == 0 || strcmp(power, "suspend") == 0) - *value= "false"; - else - *value= "true"; - - return 0; -} - -int set_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct usb_port *host= (struct usb_port *)data; - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - char *filepath; - dmasprintf(&filepath, "%s/power/level", host->folder_path); - if (!isfileexist(filepath)) - break; - writeFileContent(filepath, b?"on":"suspend"); - break; - } - return 0; -} - -int get_USBUSBHostsHost_USBVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - const struct usb_port *port = data; - char file[256]; - char buf[16] = { 0, 0 }; - - snprintf(file, sizeof(file), "%s/bcdDevice", port->folder_path); - dm_read_sysfs_file(file, buf, sizeof(buf)); - - dmasprintf(value, "%c.%c", buf[1], buf[2]); - return 0; -} - -int get_number_devices(char *folderpath, int *nbre) -{ - DIR *dir; - struct dirent *ent; - regex_t regex1 = {}; - regex_t regex2 = {}; - - regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0); - regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); - - sysfs_foreach_file(folderpath, dir, ent) { - if (regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) == 0) { - char deviceClassFile[256]; - char deviceClass[16]; - - snprintf(deviceClassFile, sizeof(deviceClassFile), "%s/%s/bDeviceClass", folderpath, ent->d_name); - dm_read_sysfs_file(deviceClassFile, deviceClass, sizeof(deviceClass)); - - if(strncmp(deviceClass, "09", 2) == 0){ - char hubpath[256]; - - snprintf(hubpath, sizeof(hubpath), "%s/%s", folderpath, ent->d_name); - get_number_devices(hubpath, nbre); - } - (*nbre)++; - } - } - if (dir) - closedir(dir); - regfree(®ex1); - regfree(®ex2); - return 0; -} - -int get_USBUSBHostsHost_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct usb_port* usb_host= (struct usb_port *) data; - int dev_nbre= 0; - - get_number_devices(usb_host->folder_path, &dev_nbre); - dmasprintf(value, "%d", dev_nbre); - return 0; -} - -int get_USBUSBHostsHostDevice_DeviceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct usb_port *usbdev= (struct usb_port *)data; - size_t length; - char **filename= strsplit(usbdev->folder_name, "-", &length); - char **port= strsplit(filename[1], ".", &length); - dmasprintf(value ,"%s", port[0]); - - return 0; -} - -int get_USBUSBHostsHostDevice_USBVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "bcdDevice", value); -} - -int get_USBUSBHostsHostDevice_DeviceClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "bDeviceClass", value); -} - -int get_USBUSBHostsHostDevice_DeviceSubClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "bDeviceSubClass", value); -} - -int get_USBUSBHostsHostDevice_DeviceVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_USBUSBHostsHostDevice_DeviceProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "bDeviceProtocol", value); -} - -int get_USBUSBHostsHostDevice_ProductID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "idProduct", value); -} - -int get_USBUSBHostsHostDevice_VendorID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "idVendor", value); -} - -int get_USBUSBHostsHostDevice_Manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "manufacturer", value); -} - -int get_USBUSBHostsHostDevice_ProductClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "product", value); -} - -int get_USBUSBHostsHostDevice_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "urbnum", value); -} - -int get_USBUSBHostsHostDevice_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct usb_port *port= (struct usb_port *)data; - size_t length; - char **busname, **portname; - regex_t regex1 = {}; - regex_t regex2 = {}; - - regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0); - regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); - if (regexec(®ex1, port->folder_name, 0, NULL, 0) == 0 || regexec(®ex2, port->folder_name, 0, NULL, 0) == 0) { - busname = strsplit(port->folder_name, "-", &length); - portname = strsplit(busname[1], ".", &length); - *value = dmstrdup(portname[0]); - goto out; - } - *value = "0"; -out: - regfree(®ex1); - regfree(®ex2); - return 0; -} - -int get_USBUSBHostsHostDevice_USBPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct usb_port *port= (struct usb_port *)data; - adm_entry_get_linker_param(ctx, dm_print_path("%s%cUSB%cPort%c", dmroot, dm_delim, dm_delim, dm_delim), port->folder_name, value); - return 0; -} - -int get_USBUSBHostsHostDevice_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return get_USBPort_Rate(refparam, ctx, data, instance, value); -} - -int get_USBUSBHostsHostDevice_Parent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct usb_port *port = (struct usb_port*)data; - char *v; - regex_t regex1 = {}; - - regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); - if(regexec(®ex1, port->folder_name, 0, NULL, 0) != 0 || port->dmsect == NULL){ - *value = ""; - goto out; - } - dmuci_get_value_by_section_string(port->dmsect, "usb_host_instance", &v); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cUSB%cUSBHosts%cHost%c%s%vDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim, v, dm_delim, dm_delim), port->folder_name, value); - if (*value == NULL) - *value = ""; -out: - regfree(®ex1); - return 0; -} - -int get_USBUSBHostsHostDevice_MaxChildren(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "maxchild", value); -} - -int get_USBUSBHostsHostDevice_IsSuspended(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char status[16]; - - __read_sysfs_usb_port(data, "power/runtime_status", status, sizeof(status)); - if(strncmp(status, "suspended", 9) == 0) - *value= "1"; - else - *value = "0"; - return 0; -} - -int get_USBUSBHostsHostDevice_IsSelfPowered(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_USBUSBHostsHostDevice_ConfigurationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "bNumConfigurations", value); -} - -int get_USBUSBHostsHostDeviceConfiguration_ConfigurationNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "bConfigurationValue", value); -} - -int get_USBUSBHostsHostDeviceConfiguration_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "bNumInterfaces", value); -} - -int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "bInterfaceNumber", value); -} - -int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "bInterfaceClass", value); -} - -int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceSubClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "bInterfaceSubClass", value); -} - -int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return read_sysfs_usb_port(data, "bInterfaceProtocol", value); -} - -int get_linker_usb_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - struct usb_port *port = (struct usb_port *)data; - if (port && port->folder_name) { - *linker = dmstrdup(port->folder_name); - return 0; - } else { - *linker = ""; - return 0; - } -} - -int get_linker_usb_host_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - struct usb_port *port = (struct usb_port *)data; - if(port && port->folder_name) { - *linker = dmstrdup(port->folder_name); - return 0; - } else { - *linker = ""; - return 0; - } -} diff --git a/dmtree/tr181/usb.h b/dmtree/tr181/usb.h index e7cdfaec..e2d70eaa 100644 --- a/dmtree/tr181/usb.h +++ b/dmtree/tr181/usb.h @@ -29,109 +29,5 @@ extern DMOBJ tUSBUSBHostsHostDeviceConfigurationObj[]; extern DMLEAF tUSBUSBHostsHostDeviceConfigurationParams[]; extern DMLEAF tUSBUSBHostsHostDeviceConfigurationInterfaceParams[]; -#define SYSFS_USB_DEVICES_PATH "/sys/bus/usb/devices" - -struct usb_port -{ - struct uci_section *dm_usb_port; - char *folder_name; - char *folder_path; - struct uci_section *dmsect; -}; - -struct usb_interface -{ - struct uci_section *dm_usb_iface; - char *iface_name; - char *iface_path; - char *statistics_path; - char *portlink; -}; - -int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseUSBUSBHostsHostDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseUSBUSBHostsHostDeviceConfigurationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int get_USB_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USB_PortNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_USBInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_USBInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_USBInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_USBInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterface_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterface_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBPort_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_USBPort_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_USBPort_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBPort_Standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBPort_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBPort_Receptacle(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBPort_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBPort_Power(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_USBUSBHostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_USBUSBHostsHost_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHost_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHost_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_USBUSBHostsHost_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_USBUSBHostsHost_USBVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHost_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_DeviceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_USBVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_DeviceClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_DeviceSubClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_DeviceVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_DeviceProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_ProductID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_VendorID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_Manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_ProductClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_USBPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_Parent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_MaxChildren(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_IsSuspended(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_IsSelfPowered(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDevice_ConfigurationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDeviceConfiguration_ConfigurationNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDeviceConfiguration_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceSubClass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_USBUSBHostsHostDeviceConfigurationInterface_InterfaceProtocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_linker_usb_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); -int get_linker_usb_host_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); #endif //__USB_H diff --git a/dmtree/tr181/userinterface.c b/dmtree/tr181/userinterface.c index caa74bda..967b8abf 100644 --- a/dmtree/tr181/userinterface.c +++ b/dmtree/tr181/userinterface.c @@ -12,23 +12,6 @@ #include "userinterface.h" -/* *** Device.UserInterface. *** */ -DMOBJ tUserInterfaceObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"RemoteAccess", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tUserInterfaceRemoteAccessParams, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.UserInterface.RemoteAccess. *** */ -DMLEAF tUserInterfaceRemoteAccessParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_userint_remoteaccesss_enable, set_userint_remoteaccesss_enable, NULL, NULL, BBFDM_BOTH}, -{"Port", &DMWRITE, DMT_UNINT, get_userint_remoteaccesss_port, set_userint_remoteaccesss_port, NULL, NULL, BBFDM_BOTH}, -{"SupportedProtocols", &DMREAD, DMT_STRING, get_userint_remoteaccesss_supportedprotocols, NULL, NULL, NULL, BBFDM_BOTH}, -{"Protocol", &DMWRITE, DMT_STRING, get_userint_remoteaccesss_protocol, set_userint_remoteaccesss_protocol, NULL, NULL, BBFDM_BOTH}, -{0} -}; - /************************************************************************** * GET & SET PARAMETERS ***************************************************************************/ @@ -47,7 +30,7 @@ static void add_default_rule(char *port, char *enable, char *owsd) dmuci_set_value_by_section(ss, "enabled", enable); } -int get_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *ss; char *rule_name, *rule_enabled; @@ -64,7 +47,7 @@ int get_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *da return 0; } -int set_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *ss; char *rule_name; @@ -90,7 +73,7 @@ int set_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *da return 0; } -int get_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *ss; char *rule_name, *dest_port; @@ -107,7 +90,7 @@ int get_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data return 0; } -int set_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *ss; char *rule_name, *owsd; @@ -148,7 +131,7 @@ static int get_supportedprotocols(void) return found_https; } -int get_userint_remoteaccesss_supportedprotocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_userint_remoteaccesss_supportedprotocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int found = get_supportedprotocols(); if (found) { @@ -159,7 +142,7 @@ int get_userint_remoteaccesss_supportedprotocols(char *refparam, struct dmctx *c return 0; } -int get_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *ss; char *rule_name, *rule_owsd; @@ -179,7 +162,7 @@ int get_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void * return 0; } -int set_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *ss; char *rule_name, *name_http; @@ -220,3 +203,20 @@ int set_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void * } return 0; } + +/* *** Device.UserInterface. *** */ +DMOBJ tUserInterfaceObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"RemoteAccess", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tUserInterfaceRemoteAccessParams, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.UserInterface.RemoteAccess. *** */ +DMLEAF tUserInterfaceRemoteAccessParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_userint_remoteaccesss_enable, set_userint_remoteaccesss_enable, NULL, NULL, BBFDM_BOTH}, +{"Port", &DMWRITE, DMT_UNINT, get_userint_remoteaccesss_port, set_userint_remoteaccesss_port, NULL, NULL, BBFDM_BOTH}, +{"SupportedProtocols", &DMREAD, DMT_STRING, get_userint_remoteaccesss_supportedprotocols, NULL, NULL, NULL, BBFDM_BOTH}, +{"Protocol", &DMWRITE, DMT_STRING, get_userint_remoteaccesss_protocol, set_userint_remoteaccesss_protocol, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/userinterface.h b/dmtree/tr181/userinterface.h index f187ff1f..74d0c604 100644 --- a/dmtree/tr181/userinterface.h +++ b/dmtree/tr181/userinterface.h @@ -18,11 +18,4 @@ extern DMLEAF tUserInterfaceRemoteAccessParams[]; extern DMOBJ tUserInterfaceObj[]; -int get_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_userint_remoteaccesss_supportedprotocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); #endif diff --git a/dmtree/tr181/users.c b/dmtree/tr181/users.c index a46630b4..5e0db698 100644 --- a/dmtree/tr181/users.c +++ b/dmtree/tr181/users.c @@ -11,34 +11,9 @@ #include "users.h" -/* *** Device.Users. *** */ -DMOBJ tUsersObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"User", &DMWRITE, add_users_user, delete_users_user, NULL, browseUserInst, NULL, NULL, NULL, NULL, tUsersUserParams, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF tUsersParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"UserNumberOfEntries", &DMREAD, DMT_UNINT, get_users_user_number_of_entries, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.Users.User.{i}. *** */ -DMLEAF tUsersUserParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Alias", &DMWRITE, DMT_STRING, get_user_alias, set_user_alias, NULL, NULL, BBFDM_BOTH}, -{"Enable", &DMWRITE, DMT_BOOL, get_user_enable, set_user_enable, NULL, NULL, BBFDM_BOTH}, -{"Username", &DMWRITE, DMT_STRING, get_user_username, set_user_username, NULL, NULL, BBFDM_BOTH}, -{"Password", &DMWRITE, DMT_STRING, get_user_password, set_user_password, NULL, NULL, BBFDM_BOTH}, -{"RemoteAccessCapable", &DMWRITE, DMT_BOOL, get_user_remote_accessable, set_user_remote_accessable, NULL, NULL, BBFDM_BOTH}, -{"Language", &DMWRITE, DMT_STRING, get_user_language, set_user_language, NULL, NULL, BBFDM_BOTH}, -{0} -}; - /***************************** Browse Functions ***********************************/ /*#Device.Users.User.{i}.!UCI:users/user/dmmap_users*/ -int browseUserInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseUserInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *instance, *instnbr = NULL; struct dmmap_dup *p; @@ -54,7 +29,7 @@ int browseUserInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, ch return 0; } -int add_users_user(char *refparam, struct dmctx *ctx, void *data, char **instance) +static int add_users_user(char *refparam, struct dmctx *ctx, void *data, char **instance) { struct uci_section *s, *dmmap_user; char ib[8], *last_inst = NULL, *sect_name = NULL, *username, *v; @@ -73,7 +48,7 @@ int add_users_user(char *refparam, struct dmctx *ctx, void *data, char **instanc return 0; } -int delete_users_user(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +static int delete_users_user(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; int found = 0; @@ -116,7 +91,7 @@ int delete_users_user(char *refparam, struct dmctx *ctx, void *data, char *insta /***************************************** Set/Get Parameter functions ***********************/ /*#Device.Users.UserNumberOfEntries!UCI:users/user/*/ -int get_users_user_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_users_user_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; int cnt = 0; @@ -128,7 +103,7 @@ int get_users_user_number_of_entries(char *refparam, struct dmctx *ctx, void *da return 0; } -int get_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *dmmap_section = NULL; @@ -139,40 +114,40 @@ int get_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance } /*#Device.Users.User.{i}.Enable!UCI:users/user,@i-1/enabled*/ -int get_user_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_user_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value); return 0; } -int get_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = dmstrdup(section_name((struct uci_section *)data)); return 0; } /*#Device.Users.User.{i}.Password!UCI:users/user,@i-1/password*/ -int get_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ""; return 0; } /*#Device.Users.User.{i}.RemoteAccessCapable!UCI:users/user,@i-1/remote_access*/ -int get_user_remote_accessable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_user_remote_accessable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "remote_access", value); return 0; } /*#Device.Users.User.{i}.Language!UCI:users/user,@i-1/language*/ -int get_user_language(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_user_language(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "language", value); return 0; } -int set_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *dmmap_section = NULL; @@ -190,7 +165,7 @@ int set_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance return 0; } -int set_user_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_user_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -204,7 +179,7 @@ int set_user_enable(char *refparam, struct dmctx *ctx, void *data, char *instanc return 0; } -int set_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -218,7 +193,7 @@ int set_user_username(char *refparam, struct dmctx *ctx, void *data, char *insta return 0; } -int set_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -232,7 +207,7 @@ int set_user_password(char *refparam, struct dmctx *ctx, void *data, char *insta return 0; } -int set_user_remote_accessable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_user_remote_accessable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -246,7 +221,7 @@ int set_user_remote_accessable(char *refparam, struct dmctx *ctx, void *data, ch return 0; } -int set_user_language(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_user_language(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -259,3 +234,28 @@ int set_user_language(char *refparam, struct dmctx *ctx, void *data, char *insta } return 0; } + +/* *** Device.Users. *** */ +DMOBJ tUsersObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"User", &DMWRITE, add_users_user, delete_users_user, NULL, browseUserInst, NULL, NULL, NULL, NULL, tUsersUserParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tUsersParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"UserNumberOfEntries", &DMREAD, DMT_UNINT, get_users_user_number_of_entries, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.Users.User.{i}. *** */ +DMLEAF tUsersUserParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Alias", &DMWRITE, DMT_STRING, get_user_alias, set_user_alias, NULL, NULL, BBFDM_BOTH}, +{"Enable", &DMWRITE, DMT_BOOL, get_user_enable, set_user_enable, NULL, NULL, BBFDM_BOTH}, +{"Username", &DMWRITE, DMT_STRING, get_user_username, set_user_username, NULL, NULL, BBFDM_BOTH}, +{"Password", &DMWRITE, DMT_STRING, get_user_password, set_user_password, NULL, NULL, BBFDM_BOTH}, +{"RemoteAccessCapable", &DMWRITE, DMT_BOOL, get_user_remote_accessable, set_user_remote_accessable, NULL, NULL, BBFDM_BOTH}, +{"Language", &DMWRITE, DMT_STRING, get_user_language, set_user_language, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/users.h b/dmtree/tr181/users.h index d237731a..0f01d6e1 100644 --- a/dmtree/tr181/users.h +++ b/dmtree/tr181/users.h @@ -17,21 +17,4 @@ extern DMOBJ tUsersObj[]; extern DMLEAF tUsersParams[]; extern DMLEAF tUsersUserParams[]; - -int browseUserInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int add_users_user(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delete_users_user(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int get_users_user_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_user_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_user_remote_accessable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_user_language(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_user_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_user_remote_accessable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_user_language(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); #endif diff --git a/dmtree/tr181/wifi.c b/dmtree/tr181/wifi.c index 52514fdb..d0a14e8a 100644 --- a/dmtree/tr181/wifi.c +++ b/dmtree/tr181/wifi.c @@ -14,6 +14,3268 @@ #include "wepkey.h" #include "wifi.h" +struct wifi_radio_args +{ + struct uci_section *wifi_radio_sec; +}; + +struct wifi_ssid_args +{ + struct uci_section *wifi_ssid_sec; + char *ifname; + char *linker; +}; + +struct wifi_enp_args +{ + struct uci_section *wifi_enp_sec; + char *ifname; +}; + +struct wifi_acp_args +{ + struct uci_section *wifi_acp_sec; + char *ifname; +}; + +struct wifi_associative_device_args +{ + int active; + int lastdatadownloadlinkrate; + int lastdatauplinkrate; + int signalstrength; + char *macaddress; + char *wdev; + int noise; + int retransmissions; + int assoctime; +}; + +/************************************************************************** +* LINKER +***************************************************************************/ +static int get_linker_Wifi_Radio(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct wifi_radio_args *)data)->wifi_radio_sec) { + *linker = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec); + return 0; + } + *linker = ""; + return 0; +} + +static int get_linker_Wifi_Ssid(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct wifi_ssid_args *)data)->ifname) { + *linker = ((struct wifi_ssid_args *)data)->ifname; + return 0; + } + *linker = ""; + return 0; +} + +static int get_linker_associated_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data && ((struct wifi_associative_device_args*)data)->macaddress) { + *linker = ((struct wifi_associative_device_args*)data)->macaddress; + return 0; + } + *linker = ""; + return 0; +} +/************************************************************************** +* INIT +***************************************************************************/ +static inline int init_wifi_radio(struct wifi_radio_args *args, struct uci_section *s) +{ + args->wifi_radio_sec = s; + return 0; +} + +static inline int init_wifi_ssid(struct wifi_ssid_args *args, struct uci_section *s, char *wiface, char *linker) +{ + args->wifi_ssid_sec = s; + args->ifname = wiface; + args->linker = linker; + return 0; +} + +static inline int init_wifi_acp(struct wifi_acp_args *args, struct uci_section *s, char *wiface) +{ + args->wifi_acp_sec = s; + args->ifname = wiface; + return 0; +} + +static inline int init_wifi_enp(struct wifi_enp_args *args, struct uci_section *s, char *wiface) +{ + args->wifi_enp_sec = s; + args->ifname = wiface; + return 0; +} +/************************************************************************** +* SET & GET VALUE +***************************************************************************/ +/*#Device.WiFi.RadioNumberOfEntries!UCI:wireless/wifi-device/*/ +static int get_WiFi_RadioNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int nbre = 0; + + uci_foreach_sections("wireless", "wifi-device", s) { + nbre++; + } + dmasprintf(value, "%d", nbre); + return 0; +} + +/*#Device.WiFi.SSIDNumberOfEntries!UCI:wireless/wifi-iface/*/ +static int get_WiFi_SSIDNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int nbre = 0; + + uci_foreach_sections("wireless", "wifi-iface", s) { + nbre++; + } + dmasprintf(value, "%d", nbre); + return 0; +} + +/*#Device.WiFi.AccessPointNumberOfEntries!UCI:wireless/wifi-iface/*/ +static int get_WiFi_AccessPointNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int nbre= 0; + char *mode= NULL; + + uci_foreach_sections("wireless", "wifi-iface", s) { + dmuci_get_value_by_section_string(s, "mode", &mode); + if ((strlen(mode)>0 || mode[0] != '\0') && strcmp(mode, "ap") != 0) + continue; + nbre++; + } + dmasprintf(value, "%d", nbre); + return 0; +} + +/*#Device.WiFi.EndPointNumberOfEntries!UCI:wireless/wifi-iface/*/ +static int get_WiFi_EndPointNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int nbre = 0; + char *mode = NULL; + + uci_foreach_sections("wireless", "wifi-iface", s) { + dmuci_get_value_by_section_string(s, "mode", &mode); + if (strcmp(mode, "wet") == 0 || strcmp(mode, "sta") == 0) + nbre++; + } + dmasprintf(value, "%d", nbre); + return 0; +} + +static int get_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("wireless", "bandsteering", "enabled", value); + return 0; +} + +static int set_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value("wireless", "bandsteering", "enabled", b ? "1" : "0"); + return 0; + } + return 0; +} + +/*#Device.WiFi.SSID.{i}.Enable!UCI:wireless/wifi-iface,@i-1/disabled*/ +static int get_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *val; + + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "disabled", &val); + if ((val[0] == '\0') || (val[0] == '0')) + *value = "1"; + else + *value = "0"; + return 0; +} + +static int set_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "disabled", b ? "0" : "1"); + return 0; + } + return 0; +} + +/*#Device.WiFi.SSID.{i}.Status!UCI:wireless/wifi-iface,@i-1/disabled*/ +static int get_wifi_status (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "disabled", value); + if ((*value)[0] == '\0' || (*value)[0] == '0') + *value = "Up"; + else + *value = "Down"; + return 0; +} + +/*#Device.WiFi.SSID.{i}.SSID!UCI:wireless/wifi-iface,@i-1/ssid*/ +static int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "ssid", value); + return 0; +} + +static int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "32", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "ssid", value); + return 0; + } + return 0; +} + +/*#Device.WiFi.SSID.{i}.BSSID!UBUS:wifi.ap.@Name/status//bssid*/ +static int get_wlan_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL; + char object[32]; + + snprintf(object, sizeof(object), "wifi.ap.%s", ((struct wifi_ssid_args *)data)->ifname); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "bssid"); + return 0; +} + +/*#Device.WiFi.SSID.{i}.MACAddress!UBUS:router.device/status/name,@Name/macaddr*/ +static int get_WiFiSSID_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "macaddr"); + return 0; +} + +/*#Device.WiFi.Radio.{i}.Enable!UCI:wireless/wifi-device,@i-1/disabled*/ +static int get_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *val; + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "disabled", &val); + + if (val[0] == '1') + *value = "0"; + else + *value = "1"; + return 0; +} + +static int set_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "disabled", b ? "0" : "1"); + return 0; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.Status!UCI:wireless/wifi-device,@i-1/disabled*/ +static int get_radio_status (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "disabled", value); + if ((*value)[0] == '1') + *value = "Down"; + else + *value = "Up"; + return 0; +} + +static int get_WiFiRadio_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ""; + return 0; +} + +static int set_WiFiRadio_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_WiFiRadio_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmasprintf(value, "%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); + return 0; +} + +/*#Device.WiFi.Radio.{i}.MaxBitRate!UBUS:wifi.radio.@Name/status//maxrate*/ +static int get_radio_max_bit_rate (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL; + char object[32]; + + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "maxrate"); + return 0; +} + +/*#Device.WiFi.Radio.{i}.OperatingFrequencyBand!UBUS:wifi.radio.@Name/status//band*/ +static int get_radio_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL; + char object[32]; + + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "band"); + return 0; +} + +/*#Device.WiFi.Radio.{i}.OperatingChannelBandwidth!UCI:wireless/wifi-device,@i-1/bandwidth&UBUS:wifi.radio.@Name/status//bandwidth*/ +static int get_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL; + char object[32], *bandwith; + + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", &bandwith); + if (bandwith[0] == '\0') { + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + bandwith = dmjson_get_value(res, 1, "bandwidth"); + } + dmastrcat(value, *value, "MHz"); // MEM WILL BE FREED IN DMMEMCLEAN + return 0; +} + +static int set_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *pch, *spch, *dup; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dup = dmstrdup(value); + pch = strtok_r(dup, "Mm", &spch); + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", pch); + dmfree(dup); + return 0; + } + return 0; +} + +static int get_radio_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "maxassoc", value); + return 0; +} + +static int set_radio_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + //TODO + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "maxassoc", value); + return 0; + } + return 0; +} + +static int get_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *val; + *value = "0"; + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "band", &val); + if (val[0] == 'a') { + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "dfsc", value); + if ((*value)[0] == '\0') + *value = "0"; + } + return 0; +} + +static int set_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + char *val; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "band", &val); + if (val[0] == 'a') { + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "dfsc", b ? "1" : "0"); + } + return 0; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.SupportedStandards!UBUS:wifi/status//radio[i-1].standard*/ +static int get_radio_supported_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *radios = NULL, *arrobj = NULL; + char *name; + int i = 0; + + dmubus_call("wifi", "status", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + dmjson_foreach_obj_in_array(res, arrobj, radios, i, 1, "radios") { + name = dmjson_get_value(radios, 1, "name"); + if (strcmp(name, section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)) == 0) { + *value = dmjson_get_value(radios, 1, "standard"); + return 0; + } + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.OperatingStandards!UCI:wireless/wifi-device,@i-1/hwmode*/ +static int get_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", value); + return 0; +} + +static int set_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + json_object *res = NULL; + char object[32], *freq; + + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + if (!res) return 0; + freq = dmjson_get_value(res, 1, "frequency"); + if (strcmp(freq, "5Ghz") == 0) { + if (strcmp(value, "n") == 0) + value = "11n"; + else if (strcmp(value, "ac") == 0) + value = "11ac"; + } else { + if (strcmp(value, "b") == 0) + value = "11b"; + else if (strcmp(value, "b,g") == 0 || strcmp(value, "g,b") == 0) + value = "11bg"; + else if (strcmp(value, "g") == 0) + value = "11g"; + else if (strcmp(value, "n") == 0) + value = "11n"; + } + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", value); + return 0; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.PossibleChannels!UBUS:wifi.radio.@Name/status//supp_channels[0].channels*/ +static int get_radio_possible_channels(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *supp_channels = NULL; + char object[32]; + + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + supp_channels = dmjson_select_obj_in_array_idx(res, 0, 1, "supp_channels"); + if (supp_channels) + *value = dmjson_get_value_array_all(supp_channels, DELIMITOR, 1, "channels"); + return 0; +} + +static int get_WiFiRadio_AutoChannelSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "true"; + return 0; +} + +/*#Device.WiFi.Radio.{i}.AutoChannelRefreshPeriod!UCI:wireless/wifi-device,@i-1/scantimer*/ +static int get_WiFiRadio_AutoChannelRefreshPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "scantimer", value); + return 0; +} + +static int set_WiFiRadio_AutoChannelRefreshPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "scantimer", value); + break; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.MaxSupportedAssociations!UCI:wireless/wifi-device,@i-1/maxassoc*/ +static int get_WiFiRadio_MaxSupportedAssociations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "maxassoc", value); + return 0; +} + +/*#Device.WiFi.Radio.{i}.FragmentationThreshold!UCI:wireless/wifi-device,@i-1/frag*/ +static int get_WiFiRadio_FragmentationThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "frag", value); + return 0; +} + +static int set_WiFiRadio_FragmentationThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "frag", value); + break; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.RTSThreshold!UCI:wireless/wifi-device,@i-1/rts*/ +static int get_WiFiRadio_RTSThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "rts", value); + return 0; +} + +static int set_WiFiRadio_RTSThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "rts", value); + break; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.BeaconPeriod!UCI:wireless/wifi-device,@i-1/beacon_int*/ +static int get_WiFiRadio_BeaconPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "beacon_int", value); + return 0; +} + +static int set_WiFiRadio_BeaconPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "beacon_int", value); + break; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.DTIMPeriod!UCI:wireless/wifi-device,@i-1/dtim_period*/ +static int get_WiFiRadio_DTIMPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "dtim_period", value); + return 0; +} + +static int set_WiFiRadio_DTIMPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "dtim_period", value); + break; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.SupportedOperatingChannelBandwidths!UBUS:wifi.radio.@Name/status//supp_channels[0].bandwidth*/ +static int get_WiFiRadio_SupportedOperatingChannelBandwidths(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *supp_channels = NULL; + char object[32]; + + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + supp_channels = dmjson_select_obj_in_array_idx(res, 0, 1, "supp_channels"); + if (supp_channels) + *value = dmjson_get_value(supp_channels, 1, "bandwidth"); + return 0; +} + +/*#Device.WiFi.Radio.{i}.OperatingChannelBandwidth!UCI:wireless/wifi-device,@i-1/bandwidth*/ +static int get_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", value); + if(*value[0] == '\0') { + *value = ""; + return 0; + } + dmastrcat(value, *value, "MHz"); + return 0; +} + +static int set_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", value); + break; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.CurrentOperatingChannelBandwidth!UBUS:wifi.radio.@Name/status//bandwidth*/ +static int get_WiFiRadio_CurrentOperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + char object[32]; + + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "bandwidth"); + return 0; +} + +/*#Device.WiFi.Radio.{i}.PreambleType!UCI:wireless/wifi-device,@i-1/short_preamble*/ +static int get_WiFiRadio_PreambleType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *preamble = NULL; + + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "short_preamble", &preamble); + if (preamble[0] == '\0' || strlen(preamble) == 0 || strcmp(preamble, "1") != 0) + *value = "long"; + else + *value = "short"; + return 0; +} + +static int set_WiFiRadio_PreambleType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, PreambleType, NULL)) + return FAULT_9007; + break; + case VALUESET: + if(strcmp(value, "short") == 0) + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "short_preamble", "1"); + else + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "short_preamble", "0"); + break; + } + return 0; +} + +static int get_WiFiRadio_IEEE80211hSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "true"; + return 0; +} + +/*#Device.WiFi.Radio.{i}.IEEE80211hEnabled!UCI:wireless/wifi-device,@i-1/doth*/ +static int get_WiFiRadio_IEEE80211hEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "doth", value); + return 0; +} + +static int set_WiFiRadio_IEEE80211hEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "doth", b ? "1" : "0"); + break; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.TransmitPower!UCI:wireless/wifi-device,@i-1/txpower*/ +static int get_WiFiRadio_TransmitPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "txpower", value); + return 0; +} + +static int set_WiFiRadio_TransmitPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, "-1", "100")) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "txpower", value); + break; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.RegulatoryDomain!UCI:wireless/wifi-device,@i-1/country*/ +static int get_WiFiRadio_RegulatoryDomain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *country, **arr; + size_t length; + + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "country", &country); + arr = strsplit(country, "/", &length); + if(arr && arr[0]) + dmasprintf(value, "%s", arr[0]); + else + *value= ""; + + return 0; +} + +static int set_WiFiRadio_RegulatoryDomain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *country, **arr; + size_t length; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, "3", "3", NULL, RegulatoryDomain)) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "country", &country); + if (strlen(country) > 0) { + arr = strsplit(country, "/", &length); + dmasprintf(&country, "%s/%s", value, arr[1]); + } else + dmasprintf(&country, "%s/1", value); + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "country", country); + break; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.ChannelsInUse!UCI:wireless/wifi-device,@i-1/channel*/ +static int get_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL; + + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); + if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') { + char object[32]; + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "channel"); + } + return 0; +} + +static int set_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", "255")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); + return 0; + } + return 0; +} + +/*#Device.WiFi.Radio.{i}.AutoChannelEnable!UCI:wireless/wifi-device,@i-1/channel*/ +static int get_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); + if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') + *value = "1"; + else + *value = "0"; + return 0; +} + +static int set_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + json_object *res = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if (b) + value = "auto"; + else { + char object[32]; + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + if (res) return 0; + value = dmjson_get_value(res, 1, "channel"); + } + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); + return 0; + } + return 0; +} + +/************************************************************* +* GET STAT +**************************************************************/ +static int ssid_read_ubus(const struct wifi_ssid_args *args, const char *name, char **value) +{ + json_object *res = NULL; + char object[32]; + + snprintf(object, sizeof(object), "wifi.ap.%s", args->ifname); + dmubus_call(object, "stats", UBUS_ARGS{}, 0, &res); + if (!res) { + *value = "0"; + return 0; + } + *value = dmjson_get_value(res, 1, name); + return 0; +} + +static int radio_read_ubus(const struct wifi_radio_args *args, const char *name, char **value) +{ + json_object *res = NULL; + char object[32]; + + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(args->wifi_radio_sec)); + dmubus_call(object, "stats", UBUS_ARGS{}, 0, &res); + if (!res) { + *value = "0"; + return 0; + } + *value = dmjson_get_value(res, 1, name); + return 0; +} + +/*#Device.WiFi.Radio.{i}.Stats.BytesSent!UBUS:wifi.radio.@Name/stats//tx_bytes*/ +static int get_WiFiRadioStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return radio_read_ubus(data, "tx_bytes", value); +} + +/*#Device.WiFi.Radio.{i}.Stats.BytesReceived!UBUS:wifi.radio.@Name/stats//rx_bytes*/ +static int get_WiFiRadioStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return radio_read_ubus(data, "rx_bytes", value); +} + +/*#Device.WiFi.Radio.{i}.Stats.PacketsSent!UBUS:wifi.radio.@Name/stats//tx_packets*/ +static int get_WiFiRadioStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return radio_read_ubus(data, "tx_packets", value); +} + +/*#Device.WiFi.Radio.{i}.Stats.PacketsReceived!UBUS:wifi.radio.@Name/stats//rx_packets*/ +static int get_WiFiRadioStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return radio_read_ubus(data, "rx_packets", value); +} + +/*#Device.WiFi.Radio.{i}.Stats.ErrorsSent!UBUS:wifi.radio.@Name/stats//tx_error_packets*/ +static int get_WiFiRadioStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return radio_read_ubus(data, "tx_error_packets", value); +} + +/*#Device.WiFi.Radio.{i}.Stats.ErrorsReceived!UBUS:wifi.radio.@Name/stats//rx_error_packets*/ +static int get_WiFiRadioStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return radio_read_ubus(data, "rx_error_packets", value); +} + +/*#Device.WiFi.Radio.{i}.Stats.DiscardPacketsSent!UBUS:wifi.radio.@Name/stats//tx_dropped_packets*/ +static int get_WiFiRadioStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return radio_read_ubus(data, "tx_dropped_packets", value); +} + +/*#Device.WiFi.Radio.{i}.Stats.DiscardPacketsReceived!UBUS:wifi.radio.@Name/stats//rx_dropped_packets*/ +static int get_WiFiRadioStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return radio_read_ubus(data, "rx_dropped_packets", value); +} + +/*#Device.WiFi.Radio.{i}.Stats.FCSErrorCount!UBUS:wifi.radio.@Name/stats//rx_fcs_error_packets*/ +static int get_WiFiRadioStats_FCSErrorCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return radio_read_ubus(data, "rx_fcs_error_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.BytesSent!UBUS:wifi.ap.@Name/stats//tx_bytes*/ +static int get_WiFiSSIDStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "tx_bytes", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.BytesReceived!UBUS:wifi.ap.@Name/stats//rx_bytes*/ +static int get_WiFiSSIDStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "rx_bytes", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.PacketsSent!UBUS:wifi.ap.@Name/stats//tx_packets*/ +static int get_WiFiSSIDStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "tx_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.PacketsReceived!UBUS:wifi.ap.@Name/stats//rx_packets*/ +static int get_WiFiSSIDStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "rx_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.ErrorsSent!UBUS:wifi.ap.@Name/stats//tx_error_packets*/ +static int get_WiFiSSIDStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "tx_error_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.ErrorsReceived!UBUS:wifi.ap.@Name/stats//rx_error_packets*/ +static int get_WiFiSSIDStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "rx_error_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.DiscardPacketsSent!UBUS:wifi.ap.@Name/stats//tx_dropped_packets*/ +static int get_WiFiSSIDStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "tx_dropped_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.DiscardPacketsReceived!UBUS:wifi.ap.@Name/stats//rx_dropped_packets*/ +static int get_WiFiSSIDStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "rx_dropped_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.UnicastPacketsSent!UBUS:wifi.ap.@Name/stats//tx_unicast_packets*/ +static int get_WiFiSSIDStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "tx_unicast_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.UnicastPacketsReceived!UBUS:wifi.ap.@Name/stats//rx_unicast_packets*/ +static int get_WiFiSSIDStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "rx_unicast_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.MulticastPacketsSent!UBUS:wifi.ap.@Name/stats//tx_multicast_packets*/ +static int get_WiFiSSIDStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "tx_multicast_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.MulticastPacketsReceived!UBUS:wifi.ap.@Name/stats//rx_multicast_packets*/ +static int get_WiFiSSIDStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "rx_multicast_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.BroadcastPacketsSent!UBUS:wifi.ap.@Name/stats//tx_broadcast_packets*/ +static int get_WiFiSSIDStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "tx_broadcast_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.BroadcastPacketsReceived!UBUS:wifi.ap.@Name/stats//rx_broadcast_packets*/ +static int get_WiFiSSIDStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "rx_broadcast_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.RetransCount!UBUS:wifi.ap.@Name/stats//tx_retrans_packets*/ +static int get_WiFiSSIDStats_RetransCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "tx_retrans_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.FailedRetransCount!UBUS:wifi.ap.@Name/stats//tx_retrans_fail_packets*/ +static int get_WiFiSSIDStats_FailedRetransCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "tx_retrans_fail_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.RetryCount!UBUS:wifi.ap.@Name/stats//tx_retry_packets*/ +static int get_WiFiSSIDStats_RetryCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "tx_retry_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.MultipleRetryCount!UBUS:wifi.ap.@Name/stats//tx_multi_retry_packets*/ +static int get_WiFiSSIDStats_MultipleRetryCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "tx_multi_retry_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.ACKFailureCount!UBUS:wifi.ap.@Name/stats//ack_fail_packets*/ +static int get_WiFiSSIDStats_ACKFailureCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "ack_fail_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.AggregatedPacketCount!UBUS:wifi.ap.@Name/stats//aggregate_packets*/ +static int get_WiFiSSIDStats_AggregatedPacketCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "aggregate_packets", value); +} + +/*#Device.WiFi.SSID.{i}.Stats.UnknownProtoPacketsReceived!UBUS:wifi.ap.@Name/stats//rx_unknown_packets*/ +static int get_WiFiSSIDStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return ssid_read_ubus(data, "rx_unknown_packets", value); +} + +static char *get_associative_device_statistics(struct wifi_associative_device_args *wifi_associative_device, char *key) +{ + json_object *res, *jobj; + char *macaddr, *stats = "0"; + int entries = 0; + + dmubus_call("wifix", "stations", UBUS_ARGS{{"vif", wifi_associative_device->wdev, String}}, 1, &res); + while (res) { + jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "stations"); + if(jobj) { + macaddr = dmjson_get_value(jobj, 1, "macaddr"); + if (!strcmp(macaddr, wifi_associative_device->macaddress)) { + stats = dmjson_get_value(jobj, 2, "stats", key); + if(*stats != '\0') + return stats; + } + entries++; + } else + break; + } + return stats; +} + +/*#Device.WiFi.AccessPoint.{i}.Stats.BytesSent!UBUS:wifix/stations/vif,@Name/stats.tx_total_bytes*/ +static int get_access_point_associative_device_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; + + *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_total_bytes"); + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Stats.BytesReceived!UBUS:wifix/stations/vif,@Name/stats.rx_data_bytes*/ +static int get_access_point_associative_device_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; + + *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "rx_data_bytes"); + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Stats.PacketsSent!UBUS:wifix/stations/vif,@Name/stats.tx_total_pkts*/ +static int get_access_point_associative_device_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; + + *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_total_pkts"); + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Stats.PacketsReceived!UBUS:wifix/stations/vif,@Name/stats.rx_data_pkts*/ +static int get_access_point_associative_device_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; + + *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "rx_data_pkts"); + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Stats.ErrorsSent!UBUS:wifix/stations/vif,@Name/stats.tx_failures*/ +static int get_access_point_associative_device_statistics_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; + + *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_failures"); + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Stats.RetransCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retries*/ +static int get_access_point_associative_device_statistics_retrans_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; + + *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_pkts_retries"); + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Stats.FailedRetransCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retry_exhausted*/ +static int get_access_point_associative_device_statistics_failed_retrans_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; + + *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_pkts_retry_exhausted"); + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Stats.RetryCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retries*/ +static int get_access_point_associative_device_statistics_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; + + *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_pkts_retries"); + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Stats.MultipleRetryCount!UBUS:wifix/stations/vif,@Name/stats.tx_data_pkts_retried*/ +static int get_access_point_associative_device_statistics_multiple_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; + + *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_data_pkts_retried"); + return 0; +} + +/************************************************************************** +* SET & GET VALUE +***************************************************************************/ +/*#Device.WiFi.SSID.{i}.SSIDAdvertisementEnabled!UCI:wireless/wifi-iface,@i-1/hidden*/ +static int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *hidden; + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "hidden", &hidden); + if (hidden[0] == '1' && hidden[1] == '\0') + *value = "0"; + else + *value = "1"; + return 0; +} + +static int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "hidden", b ? "" : "1"); + return 0; + + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.WMMEnable!UCI:wireless/wifi-device,@i-1/wmm*/ +static int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + bool b; + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", value); + dmuci_get_option_value_string("wireless", *value, "wmm", value); + string_to_bool(*value, &b); + *value = (b) ? "true" : "false"; + return 0; +} + +static int set_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + char *device; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", &device); + if (b) { + dmuci_set_value("wireless", device, "wmm", "1"); + dmuci_set_value("wireless", device, "wmm_noack", "1"); + dmuci_set_value("wireless", device, "wmm_apsd", "1"); + } else { + dmuci_set_value("wireless", device, "wmm", "0"); + dmuci_set_value("wireless", device, "wmm_noack", ""); + dmuci_set_value("wireless", device, "wmm_apsd", ""); + } + return 0; + } + return 0; +} + +static int get_access_point_total_associations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res, *jobj; + int entries = 0; + + dmubus_call("wifix", "stations", UBUS_ARGS{{"vif", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res); + DM_ASSERT(res, *value = "0"); + while (1) { + jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "stations"); + if (jobj == NULL) + break; + entries++; + } + dmasprintf(value, "%d", entries); // MEM WILL BE FREED IN DMMEMCLEAN + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.MaxAssociatedDevices!UCI:wireless/wifi-iface,@i-1/maxassoc*/ +static int get_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *device; + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "device", &device); + dmuci_get_option_value_string("wireless", device, "maxassoc", value); + return 0; +} + +static int set_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *device; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", &device); + dmuci_set_value("wireless", device, "maxassoc", value); + return 0; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.MACAddressControlEnabled!UCI:wireless/wifi-iface,@i-1/macfilter*/ +static int get_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *macfilter; + + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "macfilter", &macfilter); + if (strcmp(macfilter, "deny") == 0 || strcmp(macfilter, "disable") == 0) + *value = "false"; + else + *value = "true"; + return 0; +} + +static int get_WiFiAccessPoint_WMMCapability(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "true"; + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.MaxAllowedAssociations!UCI:wireless/wifi-iface,@i-1/maxassoc*/ +static int get_WiFiAccessPoint_MaxAllowedAssociations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *device; + + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", &device); + dmuci_get_option_value_string("wireless", device, "maxassoc", value); + return 0; +} + +static int set_WiFiAccessPoint_MaxAllowedAssociations(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *device; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", &device); + dmuci_set_value("wireless", device, "maxassoc", value); + break; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.IsolationEnable!UCI:wireless/wifi-iface,@i-1/isolate*/ +static int get_WiFiAccessPoint_IsolationEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "isolate", value); + return 0; +} + +static int set_WiFiAccessPoint_IsolationEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "isolate", b ? "1" : "0"); + break; + } + return 0; +} + +static int get_WiFiAccessPoint_AllowedMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *val; + dmuci_get_value_by_section_list(((struct wifi_acp_args *)data)->wifi_acp_sec, "maclist", &val); + if (val) + *value = dmuci_list_to_string(val, " "); + else + *value = ""; + return 0; +} + +static int set_WiFiAccessPoint_AllowedMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + size_t length; + int i; + char **arr; + + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, NULL, NULL, "17", NULL, MACAddress)) + return FAULT_9007; + break; + case VALUESET: + arr= strsplit(value, " ", &length); + for (i = 0; i < length; i++){ + dmuci_add_list_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "maclist", arr[i]); + } + break; + } + return 0; +} + +static int get_WiFiAccessPoint_UAPSDCapability(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "true"; + return 0; +} + +static int set_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "macfilter", b ? "allow" : "disable"); + return 0; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.UAPSDEnable!UCI:wireless/wifi-iface,@i-1/wmm_apsd*/ +static int get_WiFiAccessPoint_UAPSDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "wmm_apsd", value); + return 0; +} + +static int set_WiFiAccessPoint_UAPSDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wmm_apsd", b ? "1" : "0"); + break; + } + return 0; +} + +static int get_access_point_security_supported_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "None, WEP-64, WEP-128, WPA-Personal, WPA2-Personal, WPA-WPA2-Personal, WPA-Enterprise, WPA2-Enterprise, WPA-WPA2-Enterprise"; + return 0; +} + +static void get_value_security_mode(char **value, char *encryption, char *cipher) +{ + if (strcmp(encryption, "none") == 0) + *value = "None"; + else if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0) + *value = "WEP-64"; + else if (strcmp(encryption, "psk") == 0) + *value = "WPA-Personal"; + else if (strcmp(encryption, "wpa") == 0) + *value = "WPA-Enterprise"; + else if ((strcmp(encryption, "psk2") == 0 && strcmp(cipher, "auto") == 0) || (strcmp(encryption, "psk2") == 0 && strcmp(cipher, "ccmp") == 0) || (strcmp(encryption, "psk2") == 0 && *cipher == '\0')) + *value = "WPA2-Personal"; + else if (strcmp(encryption, "wpa2") == 0) + *value = "WPA2-Enterprise"; + else if ((strcmp(encryption, "mixed-psk") == 0 && strcmp(cipher, "auto") == 0) || (strcmp(encryption, "mixed-psk") == 0 && strcmp(cipher, "ccmp") == 0) || (strcmp(encryption, "mixed-psk") == 0 && strcmp(cipher, "tkip+ccmp") == 0) || (strcmp(encryption, "mixed-psk") == 0 && *cipher == '\0')) + *value = "WPA-WPA2-Personal"; + else if (strcmp(encryption, "wpa-mixed") == 0 || strcmp(encryption, "mixed-wpa") == 0) + *value = "WPA-WPA2-Enterprise"; +} + +static int get_access_point_security_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *encryption, *cipher, *mode; + + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", &cipher); + if (*encryption == '\0' && *cipher == '\0') { + *value = "None"; + return 0; + } + else + get_value_security_mode(&mode, encryption, cipher); + + *value = mode; + return 0; +} + +static int set_access_point_security_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *option, *gnw; + char *encryption, *cipher, *mode; + char strk64[4][11]; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", &cipher); + get_value_security_mode(&mode, encryption, cipher); + if (strcmp(value, mode) != 0) { + if (strcmp(value, "None") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "none"); + } + else if (strcmp(value, "WEP-64") == 0 || strcmp(value, "WEP-128") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "wep-open"); + wepkey64("Iopsys", strk64); + int i = 0; + while (i < 4) { + dmasprintf(&option, "key%d", i + 1); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, option, strk64[i]); + dmfree(option); + i++; + } + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", "1"); + } + else if (strcmp(value, "WPA-Personal") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + gnw = get_nvram_wpakey(); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "psk"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", gnw); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", "tkip"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", "3600"); + dmfree(gnw); + } + else if (strcmp(value, "WPA-Enterprise") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "wpa"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", ""); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", "1812"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", ""); + } + else if (strcmp(value, "WPA2-Personal") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + gnw = get_nvram_wpakey(); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "psk2"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", gnw); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", "ccmp"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", "3600"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps", "1"); + dmfree(gnw); + } + else if (strcmp(value, "WPA2-Enterprise") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "wpa2"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", ""); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", "1812"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", ""); + } + else if (strcmp(value, "WPA-WPA2-Personal") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + gnw = get_nvram_wpakey(); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "mixed-psk"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", gnw); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", "tkip+ccmp"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", "3600"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps", "1"); + dmfree(gnw); + } + else if (strcmp(value, "WPA-WPA2-Enterprise") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "wpa-mixed"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", ""); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", "1812"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", ""); + } + } + return 0; + } + return 0; +} + +static int set_access_point_security_wepkey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *key_index, *encryption; + char buf[8]; + + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, "13", "13")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0 ) { + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "key_index", &key_index); + snprintf(buf, sizeof(buf), "key%s", key_index); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, buf, value); + } + return 0; + } + return 0; +} + +static int get_access_point_security_wepkey_index(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *key_index; + + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "key_index", &key_index); + if (*key_index == '\0') + *value = "1"; + else + *value = key_index; + return 0; +} + +static int set_access_point_security_wepkey_index(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + //TODO + return 0; + case VALUESET: + if (atoi(value)>=1 && atoi(value)<=4) { + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key_index", value); + } + return 0; + } + return 0; +} + +static int set_access_point_security_shared_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *encryption; + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "32")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", value); + } + return 0; + } + return 0; +} + +static int set_access_point_security_passphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *encryption; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, "8", "63", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { + set_access_point_security_shared_key(refparam, ctx, data, instance, value, action); + } + return 0; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Security.RekeyingInterval!UCI:wireless/wifi-iface,@i-1/gtk_rekey*/ +static int get_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", value); + return 0; +} + +static int set_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *encryption; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0 || strcmp(encryption, "none") == 0) + return 0; + else { + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", value); + } + return 0; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Security.RadiusServerIPAddr!UCI:wireless/wifi-iface,@i-1/radius_server*/ +static int get_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", value); + return 0; +} + +static int set_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *encryption; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0 || strcmp(encryption, "wpa-mixed") == 0) + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", value); + return 0; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Security.RadiusServerPort!UCI:wireless/wifi-iface,@i-1/radius_port*/ +static int get_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", value); + return 0; +} + +static int set_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *encryption; + + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0 || strcmp(encryption, "wpa-mixed") == 0) + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", value); + return 0; + } + return 0; +} + +static int set_access_point_security_radius_secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *encryption; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0 || strcmp(encryption, "wpa-mixed") == 0) + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", value); + return 0; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Security.MFPConfig!UCI:wireless/wifi-iface,@i-1/ieee80211w*/ +static int get_WiFiAccessPointSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "ieee80211w", value); + return 0; +} + +static int set_WiFiAccessPointSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, MFPConfig, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "ieee80211w", value); + break; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.WPS.Enable!UCI:wireless/wifi-iface,@i-1/wps*/ +static int get_WiFiAccessPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps", value); + if(*value[0] == '\0') + *value= "0"; + return 0; +} + +static int set_WiFiAccessPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps", b ? "1" : "0"); + break; + } + return 0; +} + +static int get_WiFiAccessPointWPS_ConfigMethodsSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "PushButton,Label,PIN"; + return 0; +} + +static int get_WiFiAccessPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *pushbut = NULL, *label = NULL, *pin = NULL, *str1, *str2, *str3; + + dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pushbutton", &pushbut); + dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_label", &label); + dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pin", &pin); + + if (pushbut == NULL || pushbut[0] == '\0' || strcmp(pushbut, "1") != 0) + str1 = dmstrdup(""); + else + str1 = dmstrdup("PushButton"); + + if (label == NULL || label[0] == '\0' || strcmp(label, "1") != 0) + str2 = dmstrdup(""); + else { + if(pushbut == NULL || pushbut[0] == '\0' || strcmp(pushbut, "1") != 0) + str2 = dmstrdup("Label"); + else + str2 = dmstrdup(",Label"); + } + + if( pin == NULL || pin[0] == '\0') + str3 = dmstrdup(""); + else { + if((pushbut != NULL && pushbut[0] != '\0' && strcmp(pushbut, "1") == 0) || (label != NULL && label[0] != '\0' && strcmp(label, "1") == 0)) + str3 = dmstrdup(",PIN"); + else + str3 = dmstrdup("PIN"); + } + + dmasprintf(value,"%s%s%s", str1, str2, str3); + return 0; +} + +static int set_WiFiAccessPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.WPS.Status!UCI:wireless/wifi-iface,@i-1/wps*/ +static int get_WiFiAccessPointWPS_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *wps_status; + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps", &wps_status); + if (strcmp(wps_status, "0") == 0) + *value = "Disabled"; + else + *value = "Configured"; + return 0; +} + +static int get_WiFiAccessPointWPS_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.WPS.PIN!UCI:wireless/wifi-iface,@i-1/wps_pin*/ +static int get_WiFiAccessPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps_pin", value); + return 0; +} + +static int set_WiFiAccessPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "8", NULL, PIN)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps_pin", value); + break; + } + return 0; +} + +static int get_WiFiAccessPointAccounting_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_WiFiAccessPointAccounting_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Accounting.ServerIPAddr!UCI:wireless/wifi-iface,@i-1/acct_server*/ +static int get_WiFiAccessPointAccounting_ServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_server", value); + return 0; +} + +static int set_WiFiAccessPointAccounting_ServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_server", value); + break; + } + return 0; +} + +static int get_WiFiAccessPointAccounting_SecondaryServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_WiFiAccessPointAccounting_SecondaryServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Accounting.ServerPort!UCI:wireless/wifi-iface,@i-1/acct_port*/ +static int get_WiFiAccessPointAccounting_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_port", value); + return 0; +} + +static int set_WiFiAccessPointAccounting_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_port", value); + break; + } + return 0; +} + +static int get_WiFiAccessPointAccounting_SecondaryServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_WiFiAccessPointAccounting_SecondaryServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.Accounting.Secret!UCI:wireless/wifi-iface,@i-1/acct_secret*/ +static int get_WiFiAccessPointAccounting_Secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_secret", value); + return 0; +} + +static int set_WiFiAccessPointAccounting_Secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_secret", value); + break; + } + return 0; +} + +static int get_WiFiAccessPointAccounting_SecondarySecret(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_WiFiAccessPointAccounting_SecondarySecret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_WiFiAccessPointAccounting_InterimInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_WiFiAccessPointAccounting_InterimInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "60", NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_radio_supported_frequency_bands(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "2.4GHz,5GHz"; + return 0; +} + +static int get_access_point_associative_device_lastdatadownlinkrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; + dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->lastdatadownloadlinkrate); + return 0; +} + +static int get_access_point_associative_device_lastdatauplinkrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; + dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->lastdatauplinkrate); + return 0; +} + +static int get_access_point_associative_device_signalstrength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; + dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->signalstrength); + return 0; +} + +static int get_WiFiAccessPointAssociatedDevice_Retransmissions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; + dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->retransmissions); + return 0; +} + +static int get_WiFiAccessPointAssociatedDevice_AssociationTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; + dmasprintf(value, "%s", cur_wifi_associative_device_args_ptr->assoctime?int_period_to_date_time_format(cur_wifi_associative_device_args_ptr->assoctime):"0"); + return 0; +} + +static int get_access_point_associative_device_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; + dmasprintf(value, cur_wifi_associative_device_args_ptr->macaddress); + return 0; +} + +static int get_access_point_associative_device_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; + dmasprintf(value, "%s", cur_wifi_associative_device_args_ptr->active?"true":"false"); + return 0; +} + + +static int get_WiFiAccessPointAssociatedDevice_Noise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; + dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->noise); + return 0; +} + +static int get_access_point_ieee80211r_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "ieee80211r", value); + if ((*value)[0] == '\0') + *value = "0"; + return 0; +} + +static int set_access_point_ieee80211r_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "ieee80211r", b ? "1" : "0"); + return 0; + } + return 0; +} + +/*#Device.WiFi.EndPoint.{i}.Enable!UCI:wireless/wifi-iface,@i-1/disabled*/ +static int get_WiFiEndPoint_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "disabled", value); + if (((*value)[0] == '\0') || ((*value)[0] == '0')) + *value = "1"; + else + *value = "0"; + return 0; +} + +static int set_WiFiEndPoint_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "disabled", b ? "0" : "1"); + break; + } + return 0; +} + +/*#Device.WiFi.EndPoint.{i}.Status!UCI:wireless/wifi-iface,@i-1/disabled*/ +static int get_WiFiEndPoint_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "disabled", value); + if ((*value)[0] == '\0' || (*value)[0] == '0') + *value = "Up"; + else + *value = "Down"; + return 0; +} + +static int get_WiFiEndPoint_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_enp_args *)data)->wifi_enp_sec), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "endpointalias", value); + return 0; +} + +static int set_WiFiEndPoint_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_enp_args *)data)->wifi_enp_sec), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "endpointalias", value); + return 0; + } + return 0; +} + +static int get_WiFiEndPoint_ProfileReference(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_WiFiEndPoint_ProfileReference(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_WiFiEndPoint_SSIDReference(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cSSID%c", dmroot, dm_delim, dm_delim, dm_delim), ((struct wifi_enp_args *)data)->ifname, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) + *value = ""; + return 0; +} + +static int get_WiFiEndPointProfile_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +static int set_WiFiEndPointProfile_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +static int get_WiFiEndPointProfile_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Active"; + return 0; +} + +static int get_WiFiEndPointProfile_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL, *dm = NULL; + char *epinst = NULL; + + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name((struct uci_section*)data), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "endpointinstance", &epinst); + get_dmmap_section_of_config_section_eq("dmmap_wireless", "ep_profile", "ep_key", epinst, &dm); + if (dm) + dmuci_get_value_by_section_string(dm, "ep_profile_alias", value); + return 0; +} + +static int set_WiFiEndPointProfile_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL, *dm = NULL; + char *epinst = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name((struct uci_section*)data), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "endpointinstance", &epinst); + get_dmmap_section_of_config_section_eq("dmmap_wireless", "ep_profile", "ep_key", epinst, &dm); + if (dm) + DMUCI_SET_VALUE_BY_SECTION(bbfdm, dm, "ep_profile_alias", value); + break; + } + return 0; +} + +/*#Device.WiFi.EndPoint.{i}.Profile.{i}.SSID!UCI:wireless/wifi-iface,@i-1/ssid*/ +static int get_WiFiEndPointProfile_SSID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section*)data, "ssid", value); + return 0; +} + +static int set_WiFiEndPointProfile_SSID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "32", NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section*)data, "ssid", value); + break; + } + return 0; +} + +static int get_WiFiEndPointProfile_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_WiFiEndPointProfile_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +static int get_WiFiEndPointProfile_Priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int set_WiFiEndPointProfile_Priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, "255")) + return FAULT_9007; + break; + case VALUESET: + //TODO + break; + } + return 0; +} + +/*#Device.WiFi.EndPoint.{i}.Profile.{i}.Security.SSID!UCI:wireless/wifi-iface,@i-1/encryption*/ +static int get_WiFiEndPointProfileSecurity_ModeEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *encryption, *cipher, *mode; + + dmuci_get_value_by_section_string((struct uci_section *)data, "encryption", &encryption); + dmuci_get_value_by_section_string((struct uci_section *)data, "cipher", &cipher); + if (*encryption == '\0' && *cipher == '\0') { + *value = "None"; + return 0; + } + else + get_value_security_mode(&mode, encryption, cipher); + + *value = mode; + return 0; +} + +static int set_WiFiEndPointProfileSecurity_ModeEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *option, *gnw; + char *encryption, *cipher, *mode; + char strk64[4][11]; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); + dmuci_get_value_by_section_string((struct uci_section*)data, "cipher", &cipher); + get_value_security_mode(&mode, encryption, cipher); + + if (strcmp(value, mode) != 0) { + if (strcmp(value, "None") == 0) { + reset_wlan((struct uci_section*)data); + dmuci_set_value_by_section((struct uci_section*)data, "encryption", "none"); + } + else if (strcmp(value, "WEP-64") == 0 || strcmp(value, "WEP-128") == 0) { + reset_wlan((struct uci_section*)data); + dmuci_set_value_by_section((struct uci_section*)data, "encryption", "wep-open"); + wepkey64("Iopsys", strk64); + int i = 0; + while (i < 4) { + dmasprintf(&option, "key%d", i + 1); + dmuci_set_value_by_section((struct uci_section*)data, option, strk64[i]); + dmfree(option); + i++; + } + dmuci_set_value_by_section((struct uci_section*)data, "key", "1"); + } + else if (strcmp(value, "WPA-Personal") == 0) { + reset_wlan((struct uci_section*)data); + gnw = get_nvram_wpakey(); + dmuci_set_value_by_section((struct uci_section*)data, "encryption", "psk"); + dmuci_set_value_by_section((struct uci_section*)data, "key", gnw); + dmuci_set_value_by_section((struct uci_section*)data, "cipher", "tkip"); + dmuci_set_value_by_section((struct uci_section*)data, "gtk_rekey", "3600"); + dmfree(gnw); + } + else if (strcmp(value, "WPA-Enterprise") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + dmuci_set_value_by_section((struct uci_section*)data, "encryption", "wpa"); + dmuci_set_value_by_section((struct uci_section*)data, "radius_server", ""); + dmuci_set_value_by_section((struct uci_section*)data, "radius_port", "1812"); + dmuci_set_value_by_section((struct uci_section*)data, "radius_secret", ""); + } + else if (strcmp(value, "WPA2-Personal") == 0) { + reset_wlan((struct uci_section*)data); + gnw = get_nvram_wpakey(); + dmuci_set_value_by_section((struct uci_section*)data, "encryption", "psk2"); + dmuci_set_value_by_section((struct uci_section*)data, "key", gnw); + dmuci_set_value_by_section((struct uci_section*)data, "cipher", "ccmp"); + dmuci_set_value_by_section((struct uci_section*)data, "gtk_rekey", "3600"); + dmuci_set_value_by_section((struct uci_section*)data, "wps", "1"); + dmfree(gnw); + } + else if (strcmp(value, "WPA2-Enterprise") == 0) { + reset_wlan((struct uci_section*)data); + dmuci_set_value_by_section((struct uci_section*)data, "encryption", "wpa2"); + dmuci_set_value_by_section((struct uci_section*)data, "radius_server", ""); + dmuci_set_value_by_section((struct uci_section*)data, "radius_port", "1812"); + dmuci_set_value_by_section((struct uci_section*)data, "radius_secret", ""); + } + else if (strcmp(value, "WPA-WPA2-Personal") == 0) { + reset_wlan((struct uci_section*)data); + gnw = get_nvram_wpakey(); + dmuci_set_value_by_section((struct uci_section*)data, "encryption", "mixed-psk"); + dmuci_set_value_by_section((struct uci_section*)data, "key", gnw); + dmuci_set_value_by_section((struct uci_section*)data, "cipher", "tkip+ccmp"); + dmuci_set_value_by_section((struct uci_section*)data, "gtk_rekey", "3600"); + dmuci_set_value_by_section((struct uci_section*)data, "wps", "1"); + dmfree(gnw); + } + else if (strcmp(value, "WPA-WPA2-Enterprise") == 0) { + reset_wlan((struct uci_section*)data); + dmuci_set_value_by_section((struct uci_section*)data, "encryption", "wpa-mixed"); + dmuci_set_value_by_section((struct uci_section*)data, "radius_server", ""); + dmuci_set_value_by_section((struct uci_section*)data, "radius_port", "1812"); + dmuci_set_value_by_section((struct uci_section*)data, "radius_secret", ""); + } + } + return 0; + } + return 0; +} + +static int set_WiFiEndPointProfileSecurity_WEPKey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *key_index, *encryption; + char buf[8]; + + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, "13", "13")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); + if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0 ) { + dmuci_get_value_by_section_string((struct uci_section*)data, "key_index", &key_index); + sprintf(buf,"key%s", key_index); + dmuci_set_value_by_section((struct uci_section*)data, buf, value); + } + return 0; + } + return 0; +} + +static int set_WiFiEndPointProfileSecurity_PreSharedKey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *encryption; + + switch (action) { + case VALUECHECK: + if (dm_validate_hexBinary(value, NULL, "32")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); + if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { + dmuci_set_value_by_section((struct uci_section*)data, "key", value); + } + return 0; + } + return 0; +} + +static int set_WiFiEndPointProfileSecurity_KeyPassphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *encryption; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, "8", "63", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); + if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { + set_WiFiEndPointProfileSecurity_PreSharedKey(refparam, ctx, data, instance, value, action); + } + return 0; + } + return 0; +} + +/*#Device.WiFi.EndPoint.{i}.Profile.{i}.Security.MFPConfig!UCI:wireless/wifi-iface,@i-1/ieee80211w*/ +static int get_WiFiEndPointProfileSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section*)data, "ieee80211w", value); + return 0; +} + +static int set_WiFiEndPointProfileSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, MFPConfig, NULL)) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section((struct uci_section*)data, "ieee80211w", value); + break; + } + return 0; +} + +static int get_WiFiEndPointStats_LastDataDownlinkRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_WiFiEndPointStats_LastDataUplinkRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_WiFiEndPointStats_SignalStrength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_WiFiEndPointStats_Retransmissions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +static int get_WiFiEndPointSecurity_ModesSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.WiFi.EndPoint.{i}.WPS.Enable!UCI:wireless/wifi-iface,@i-1/wps*/ +static int get_WiFiEndPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps", value); + if(*value[0] == '\0') + *value = "0"; + return 0; +} + +static int set_WiFiEndPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + break; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps", b ? "1" : "0"); + break; + } + return 0; +} + +static int get_WiFiEndPointWPS_ConfigMethodsSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "PushButton,Label,PIN"; + return 0; +} + +static int get_WiFiEndPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *pushbut = NULL, *label = NULL, *pin = NULL, *str1, *str2, *str3; + + dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pushbutton", &pushbut); + dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_label", &label); + dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pin", &pin); + + if (pushbut == NULL || pushbut[0]=='\0' || strcmp(pushbut, "1")!=0) + str1 = dmstrdup(""); + else + str1 = dmstrdup("PushButton"); + + if (label == NULL || label[0]=='\0' || strcmp(label, "1")!=0) + str2 = dmstrdup(""); + else { + if (pushbut == NULL || pushbut[0]=='\0' || strcmp(pushbut, "1")!=0) + str2 = dmstrdup("Label"); + else + str2 = dmstrdup(",Label"); + } + + if (pin == NULL || pin[0]=='\0') + str3 = dmstrdup(""); + else { + if ((pushbut != NULL && pushbut[0] != '\0' && strcmp(pushbut, "1") == 0) || (label != NULL && label[0] != '\0' && strcmp(label, "1") == 0)) + str3 = dmstrdup(",PIN"); + else + str3 = dmstrdup("PIN"); + } + + dmasprintf(value,"%s%s%s", str1, str2, str3); + return 0; +} + +static int set_WiFiEndPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +/*#Device.WiFi.EndPoint.{i}.WPS.Status!UCI:wireless/wifi-iface,@i-1/wps*/ +static int get_WiFiEndPointWPS_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *wps_status; + + dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps", &wps_status); + if (strcmp(wps_status, "0") == 0 || wps_status[0] == '\0') + *value = "Disabled"; + else + *value = "Configured"; + return 0; +} + +static int get_WiFiEndPointWPS_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.WiFi.EndPoint.{i}.WPS.PIN!UCI:wireless/wifi-iface,@i-1/wps_pin*/ +static int get_WiFiEndPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pin", value); + return 0; +} + +static int set_WiFiEndPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "8", "8")) + return FAULT_9007; + break; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pin", value); + break; + } + return 0; +} + +static int get_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *ss; + json_object *res = NULL, *neighboring_wifi_obj = NULL; + char object[32]; + + uci_foreach_sections("wireless", "wifi-device", ss) { + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(ss)); + dmubus_call(object, "scanresults", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = "None"); + neighboring_wifi_obj = dmjson_select_obj_in_array_idx(res, 0, 1, "accesspoints"); + if (neighboring_wifi_obj) { + *value = "Complete"; + break; + } else + *value = "None"; + } + return 0; +} + +static int set_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *ss; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, DiagnosticsState, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (strcmp(value, "Requested") == 0) { + uci_foreach_sections("wireless", "wifi-device", ss) { + char object[32]; + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(ss)); + dmubus_call_set(object, "scan", UBUS_ARGS{}, 0); + } + dmubus_call_set("tr069", "inform", UBUS_ARGS{{"event", "8 DIAGNOSTICS COMPLETE", String}}, 1); + } + return 0; + } + return 0; +} + +static int get_neighboring_wifi_diagnostics_result_number_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *ss; + json_object *res = NULL, *accesspoints = NULL; + size_t entries = 0, result = 0; + char object[32]; + *value = "0"; + + uci_foreach_sections("wireless", "wifi-device", ss) { + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(ss)); + dmubus_call(object, "scanresults", UBUS_ARGS{}, 0, &res); + if (res) { + json_object_object_get_ex(res, "accesspoints", &accesspoints); + if (accesspoints) + entries = json_object_array_length(accesspoints); + } + result = result + entries; + entries = 0; + } + dmasprintf(value, "%d", result); // MEM WILL BE FREED IN DMMEMCLEAN + return 0; +} + +static int get_neighboring_wifi_diagnostics_result_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "ssid"); + return 0; +} + +static int get_neighboring_wifi_diagnostics_result_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "bssid"); + return 0; +} + +static int get_neighboring_wifi_diagnostics_result_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "channel"); + return 0; +} + +static int get_neighboring_wifi_diagnostics_result_signal_strength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "rssi"); + return 0; +} + +static int get_neighboring_wifi_diagnostics_result_operating_frequency_band(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "band"); + return 0; +} + +static int get_neighboring_wifi_diagnostics_result_noise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "snr"); + return 0; +} + +/************************************************************************** +* SET AND GET ALIAS +***************************************************************************/ +static int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-device", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "radioalias", value); + return 0; +} + +static int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-device", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "radioalias", value); + return 0; + } + return 0; +} + +static int get_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_ssid_args *)data)->wifi_ssid_sec), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "ssidalias", value); + return 0; +} + +static int set_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_ssid_args *)data)->wifi_ssid_sec), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "ssidalias", value); + return 0; + } + return 0; +} + +static int get_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_acp_args *)data)->wifi_acp_sec), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "accesspointalias", value); + return 0; +} + +static int set_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_acp_args *)data)->wifi_acp_sec), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "accesspointalias", value); + return 0; + } + return 0; +} +/************************************************************* +* GET & SET LOWER LAYER +**************************************************************/ +static int get_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if (data && ((struct wifi_ssid_args *)data)->linker[0] != '\0') { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cRadio%c", dmroot, dm_delim, dm_delim, dm_delim), ((struct wifi_ssid_args *)data)->linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) + *value = ""; + } + return 0; +} + +static int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker, *newvalue = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + if (value[strlen(value)-1] != '.') { + dmasprintf(&newvalue, "%s.", value); + adm_entry_get_linker_value(ctx, newvalue, &linker); + } else + adm_entry_get_linker_value(ctx, value, &linker); + if (linker) { + dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "device", linker); + dmfree(linker); + } else + return FAULT_9005; + return 0; + } + return 0; +} + +static int get_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cSSID%c", dmroot, dm_delim, dm_delim, dm_delim), ((struct wifi_acp_args *)data)->ifname, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) + *value = ""; + return 0; +} + +/************************************************************* +* ADD DEL OBJ +**************************************************************/ +static int add_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *value, *v, *inst, ssid[16] = {0}; + struct uci_section *s = NULL, *dmmap_wifi = NULL; + + check_create_dmmap_package("dmmap_wireless"); + inst = get_last_instance_bbfdm("dmmap_wireless", "wifi-iface", "ssidinstance"); + snprintf(ssid, sizeof(ssid), "iopsys_%d", inst ? (atoi(inst)+1) : 1); + dmuci_add_section("wireless", "wifi-iface", &s, &value); + dmuci_set_value_by_section(s, "device", "wl0"); + dmuci_set_value_by_section(s, "encryption", "none"); + dmuci_set_value_by_section(s, "macfilter", "0"); + dmuci_set_value_by_section(s, "mode", "ap"); + dmuci_set_value_by_section(s, "ssid", ssid); + + dmuci_add_section_bbfdm("dmmap_wireless", "wifi-iface", &dmmap_wifi, &v); + dmuci_set_value_by_section(dmmap_wifi, "section_name", section_name(s)); + *instance = update_instance_bbfdm(dmmap_wifi, inst, "ssidinstance"); + return 0; +} + +static int delete_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; + + switch (del_action) { + case DEL_INST: + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_ssid_args *)data)->wifi_ssid_sec), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("wireless", "wifi-iface", s) { + if (found != 0){ + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ss), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL){ + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ss), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + return 0; + } + return 0; +} + +static int addObjWiFiEndPoint(char *refparam, struct dmctx *ctx, void *data, char **instance) +{ + char *value, *v, *instancepara, *instancepara1, *instancepara2; + struct uci_section *endpoint_sec = NULL, *dmmap_sec= NULL; + + check_create_dmmap_package("dmmap_wireless"); + instancepara1 = get_last_instance_lev2_bbfdm("wireless", "wifi-iface", "dmmap_wireless", "endpointinstance", "mode", "wet")?get_last_instance_lev2_bbfdm("wireless", "wifi-iface", "dmmap_wireless", "endpointinstance", "mode", "wet"):"0"; + instancepara2 = get_last_instance_lev2_bbfdm("wireless", "wifi-iface", "dmmap_wireless", "endpointinstance", "mode", "sta")?get_last_instance_lev2_bbfdm("wireless", "wifi-iface", "dmmap_wireless", "endpointinstance", "mode", "sta"):"0"; + instancepara=atoi(instancepara1)>atoi(instancepara2)?dmstrdup(instancepara1):dmstrdup(instancepara2); + dmuci_add_section("wireless", "wifi-iface", &endpoint_sec, &value); + dmuci_set_value_by_section(endpoint_sec, "device", "wl1"); + dmuci_set_value_by_section(endpoint_sec, "mode", "wet"); + dmuci_set_value_by_section(endpoint_sec, "network", "lan"); + + dmuci_add_section_bbfdm("dmmap_wireless", "wifi-iface", &dmmap_sec, &v); + dmuci_set_value_by_section(dmmap_sec, "section_name", section_name(endpoint_sec)); + *instance = update_instance_bbfdm(dmmap_sec, instancepara, "endpointinstance"); + return 0; +} + +static int delObjWiFiEndPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s = NULL, *dmmap_section = NULL; + char *mode; + + switch (del_action) { + case DEL_INST: + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_ssid_args *)data)->wifi_ssid_sec), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "endpointinstance", ""); + dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "mode", ""); + break; + case DEL_ALL: + uci_foreach_sections("wireless", "wifi-iface", s) { + dmuci_get_value_by_section_string(s, "mode", &mode); + if (strcmp(mode, "sta") != 0 && strcmp(mode, "wet") != 0) + continue; + dmuci_set_value_by_section(s, "mode", ""); + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(s), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "endpointinstance", ""); + } + } + return 0; +} +/************************************************************* +* ENTRY METHOD +**************************************************************/ +/*#Device.WiFi.Radio.{i}.!UCI:wireless/wifi-device/dmmap_wireless*/ +static int browseWifiRadioInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *wnum = NULL, *wnum_last = NULL; + struct wifi_radio_args curr_wifi_radio_args = {0}; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("wireless", "wifi-device", "dmmap_wireless", &dup_list); + list_for_each_entry(p, &dup_list, list) { + init_wifi_radio(&curr_wifi_radio_args, p->config_section); + wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, p->dmmap_section, "radioinstance", "radioalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wifi_radio_args, wnum) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +/*#Device.WiFi.SSID.{i}.!UCI:wireless/wifi-iface/dmmap_wireless*/ +static int browseWifiSsidInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *wnum = NULL, *ssid_last = NULL, *ifname, *linker; + struct wifi_ssid_args curr_wifi_ssid_args = {0}; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("wireless", "wifi-iface", "dmmap_wireless", &dup_list); + list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "device", &linker); + ifname = get_device_from_wifi_iface(linker, section_name(p->config_section)); + init_wifi_ssid(&curr_wifi_ssid_args, p->config_section, ifname, linker); + wnum = handle_update_instance(1, dmctx, &ssid_last, update_instance_alias, 3, p->dmmap_section, "ssidinstance", "ssidalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wifi_ssid_args, wnum) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +/*#Device.WiFi.AccessPoint.{i}.!UCI:wireless/wifi-iface/dmmap_wireless*/ +static int browseWifiAccessPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *wnum = NULL, *ifname, *acpt_last = NULL, *mode = NULL; + struct wifi_acp_args curr_wifi_acp_args = {0}; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("wireless", "wifi-iface", "dmmap_wireless", &dup_list); + list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "mode", &mode); + if ((strlen(mode)>0 || mode[0] != '\0') &&strcmp(mode, "ap") != 0) + continue; + dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); + init_wifi_acp(&curr_wifi_acp_args, p->config_section, ifname); + wnum = handle_update_instance(1, dmctx, &acpt_last, update_instance_alias, 3, p->dmmap_section, "accesspointinstance", "accesspointalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wifi_acp_args, wnum) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +/*#Device.WiFi.EndPoint.{i}.!UCI:wireless/wifi-iface/dmmap_wireless*/ +static int browseWiFiEndPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *wnum = NULL, *ifname, *acpt_last = NULL, *mode= NULL; + struct wifi_enp_args curr_wifi_enp_args = {0}; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("wireless", "wifi-iface", "dmmap_wireless", &dup_list); + list_for_each_entry(p, &dup_list, list) { + dmuci_get_value_by_section_string(p->config_section, "mode", &mode); + if(strcmp(mode, "wet")!=0 && strcmp(mode, "sta")!=0) + continue; + dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); + init_wifi_enp(&curr_wifi_enp_args, p->config_section, ifname); + wnum = handle_update_instance(1, dmctx, &acpt_last, update_instance_alias, 3, p->dmmap_section, "endpointinstance", "endpointalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wifi_enp_args, wnum) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int browse_wifi_associated_device(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res, *associated_client_obj; + struct uci_section *ss = NULL; + char *value, *ap_ifname, *idx, *idx_last = NULL; + int id = 0, entries = 0; + char *macaddr = NULL, *lastdatadownloadlinkrate = NULL, *lastdatauplinkrate = NULL, *signalstrength = NULL, *noise = NULL, *retrans = NULL, *assoctimestr = NULL; + struct wifi_associative_device_args cur_wifi_associative_device_args = {0}; + struct uci_section *dmmap_section; + + uci_foreach_sections("wireless", "wifi-iface", ss) { + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ss), &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "accesspointinstance", &value); + if(!strcmp(value, prev_instance)){ + dmuci_get_value_by_section_string(ss, "ifname", &ap_ifname); + break; + } + } + + dmubus_call("wifix", "stations", UBUS_ARGS{{"vif", ap_ifname, String}}, 1, &res); + while (res) { + associated_client_obj = dmjson_select_obj_in_array_idx(res, entries, 1, "stations"); + if(associated_client_obj) { + cur_wifi_associative_device_args.wdev = ap_ifname; + macaddr = dmjson_get_value(associated_client_obj, 1, "macaddr"); + if(macaddr!=NULL && strlen(macaddr)>0) + dmasprintf(&(cur_wifi_associative_device_args.macaddress),dmjson_get_value(associated_client_obj, 1, "macaddr")); + cur_wifi_associative_device_args.active = 1; + lastdatadownloadlinkrate = dmjson_get_value(associated_client_obj, 2, "stats", "rate_of_last_rx_pkt"); + if(lastdatadownloadlinkrate!=NULL && strlen(lastdatadownloadlinkrate)>0) + cur_wifi_associative_device_args.lastdatadownloadlinkrate = atoi(lastdatadownloadlinkrate); + else + cur_wifi_associative_device_args.lastdatadownloadlinkrate = 0; + lastdatauplinkrate = dmjson_get_value(associated_client_obj, 2, "stats", "rate_of_last_tx_pkt"); + if(lastdatauplinkrate!=NULL && strlen(lastdatauplinkrate)>0) + cur_wifi_associative_device_args.lastdatauplinkrate = atoi(lastdatauplinkrate); + else + cur_wifi_associative_device_args.lastdatauplinkrate = 0; + signalstrength=dmjson_get_value(associated_client_obj, 1, "rssi"); + if(signalstrength!=NULL && strlen(signalstrength)>0) + cur_wifi_associative_device_args.signalstrength = atoi(signalstrength); + else + cur_wifi_associative_device_args.signalstrength = 0; + noise=dmjson_get_value(associated_client_obj, 1, "snr"); + if(noise!=NULL && strlen(noise)>0) + cur_wifi_associative_device_args.noise = atoi(noise); + else + cur_wifi_associative_device_args.noise = 0; + retrans= dmjson_get_value(associated_client_obj, 2, "stats", "tx_pkts_retries"); + cur_wifi_associative_device_args.retransmissions= atoi(retrans); + + assoctimestr=dmjson_get_value(associated_client_obj, 1, "in_network"); + if(assoctimestr!=NULL && strlen(assoctimestr)>0) + cur_wifi_associative_device_args.assoctime = atoi(assoctimestr); + else + cur_wifi_associative_device_args.assoctime = 0; + + entries++; + idx = handle_update_instance(3, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_wifi_associative_device_args, idx) == DM_STOP) + break; + } + else + break; + } + return 0; +} + +static int browseWifiNeighboringWiFiDiagnosticResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *ss; + json_object *res = NULL, *accesspoints = NULL, *arrobj = NULL; + char object[32], *idx, *idx_last = NULL; + int id = 0, i = 0; + + uci_foreach_sections("wireless", "wifi-device", ss) { + snprintf(object, sizeof(object), "wifi.radio.%s", section_name(ss)); + dmubus_call(object, "scanresults", UBUS_ARGS{}, 0, &res); + if (res) { + dmjson_foreach_obj_in_array(res, arrobj, accesspoints, i, 1, "accesspoints") { + idx = handle_update_instance(3, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)accesspoints, idx) == DM_STOP) + return 0; + } + } + } + return 0; +} + +static int browseWiFiEndPointProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *s= NULL; + char *v, *instnbr = NULL, *ep_instance; + struct wifi_enp_args *ep_args = (struct wifi_enp_args *)prev_data; + struct uci_section *dmmap_section = NULL; + + check_create_dmmap_package("dmmap_wireless"); + + get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ep_args->wifi_enp_sec), &dmmap_section); + dmuci_get_value_by_section_string(dmmap_section, "endpointinstance", &ep_instance); + s = is_dmmap_section_exist_eq("dmmap_wireless", "ep_profile", "ep_key", ep_instance); + if(!s) + dmuci_add_section_bbfdm("dmmap_wireless", "ep_profile", &s, &v); + DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "ep_key", ep_instance); + handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "ep_profile_instance", "ep_profile_alias"); + + DM_LINK_INST_OBJ(dmctx, parent_node, ep_args->wifi_enp_sec, "1"); + return 0; +} + /* *** Device.WiFi. *** */ DMOBJ tWiFiObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -360,3228 +3622,3 @@ DMLEAF tWiFiEndPointWPSParams[] = { {"PIN", &DMWRITE, DMT_UNINT, get_WiFiEndPointWPS_PIN, set_WiFiEndPointWPS_PIN, NULL, NULL, BBFDM_BOTH}, {0} }; - -/************************************************************************** -* LINKER -***************************************************************************/ -int get_linker_Wifi_Radio(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct wifi_radio_args *)data)->wifi_radio_sec) { - *linker = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec); - return 0; - } - *linker = ""; - return 0; -} - -int get_linker_Wifi_Ssid(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct wifi_ssid_args *)data)->ifname) { - *linker = ((struct wifi_ssid_args *)data)->ifname; - return 0; - } - *linker = ""; - return 0; -} - -int get_linker_associated_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - if (data && ((struct wifi_associative_device_args*)data)->macaddress) { - *linker = ((struct wifi_associative_device_args*)data)->macaddress; - return 0; - } - *linker = ""; - return 0; -} -/************************************************************************** -* INIT -***************************************************************************/ -static inline int init_wifi_radio(struct wifi_radio_args *args, struct uci_section *s) -{ - args->wifi_radio_sec = s; - return 0; -} - -static inline int init_wifi_ssid(struct wifi_ssid_args *args, struct uci_section *s, char *wiface, char *linker) -{ - args->wifi_ssid_sec = s; - args->ifname = wiface; - args->linker = linker; - return 0; -} - -static inline int init_wifi_acp(struct wifi_acp_args *args, struct uci_section *s, char *wiface) -{ - args->wifi_acp_sec = s; - args->ifname = wiface; - return 0; -} - -static inline int init_wifi_enp(struct wifi_enp_args *args, struct uci_section *s, char *wiface) -{ - args->wifi_enp_sec = s; - args->ifname = wiface; - return 0; -} -/************************************************************************** -* SET & GET VALUE -***************************************************************************/ -/*#Device.WiFi.RadioNumberOfEntries!UCI:wireless/wifi-device/*/ -int get_WiFi_RadioNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int nbre = 0; - - uci_foreach_sections("wireless", "wifi-device", s) { - nbre++; - } - dmasprintf(value, "%d", nbre); - return 0; -} - -/*#Device.WiFi.SSIDNumberOfEntries!UCI:wireless/wifi-iface/*/ -int get_WiFi_SSIDNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int nbre = 0; - - uci_foreach_sections("wireless", "wifi-iface", s) { - nbre++; - } - dmasprintf(value, "%d", nbre); - return 0; -} - -/*#Device.WiFi.AccessPointNumberOfEntries!UCI:wireless/wifi-iface/*/ -int get_WiFi_AccessPointNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int nbre= 0; - char *mode= NULL; - - uci_foreach_sections("wireless", "wifi-iface", s) { - dmuci_get_value_by_section_string(s, "mode", &mode); - if ((strlen(mode)>0 || mode[0] != '\0') && strcmp(mode, "ap") != 0) - continue; - nbre++; - } - dmasprintf(value, "%d", nbre); - return 0; -} - -/*#Device.WiFi.EndPointNumberOfEntries!UCI:wireless/wifi-iface/*/ -int get_WiFi_EndPointNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int nbre = 0; - char *mode = NULL; - - uci_foreach_sections("wireless", "wifi-iface", s) { - dmuci_get_value_by_section_string(s, "mode", &mode); - if (strcmp(mode, "wet") == 0 || strcmp(mode, "sta") == 0) - nbre++; - } - dmasprintf(value, "%d", nbre); - return 0; -} - -int get_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("wireless", "bandsteering", "enabled", value); - return 0; -} - -int set_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value("wireless", "bandsteering", "enabled", b ? "1" : "0"); - return 0; - } - return 0; -} - -/*#Device.WiFi.SSID.{i}.Enable!UCI:wireless/wifi-iface,@i-1/disabled*/ -int get_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *val; - - dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "disabled", &val); - if ((val[0] == '\0') || (val[0] == '0')) - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "disabled", b ? "0" : "1"); - return 0; - } - return 0; -} - -/*#Device.WiFi.SSID.{i}.Status!UCI:wireless/wifi-iface,@i-1/disabled*/ -int get_wifi_status (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "disabled", value); - if ((*value)[0] == '\0' || (*value)[0] == '0') - *value = "Up"; - else - *value = "Down"; - return 0; -} - -/*#Device.WiFi.SSID.{i}.SSID!UCI:wireless/wifi-iface,@i-1/ssid*/ -int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "ssid", value); - return 0; -} - -int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "32", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "ssid", value); - return 0; - } - return 0; -} - -/*#Device.WiFi.SSID.{i}.BSSID!UBUS:wifi.ap.@Name/status//bssid*/ -int get_wlan_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res = NULL; - char object[32]; - - snprintf(object, sizeof(object), "wifi.ap.%s", ((struct wifi_ssid_args *)data)->ifname); - dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "bssid"); - return 0; -} - -/*#Device.WiFi.SSID.{i}.MACAddress!UBUS:router.device/status/name,@Name/macaddr*/ -int get_WiFiSSID_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "macaddr"); - return 0; -} - -/*#Device.WiFi.Radio.{i}.Enable!UCI:wireless/wifi-device,@i-1/disabled*/ -int get_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *val; - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "disabled", &val); - - if (val[0] == '1') - *value = "0"; - else - *value = "1"; - return 0; -} - -int set_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "disabled", b ? "0" : "1"); - return 0; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.Status!UCI:wireless/wifi-device,@i-1/disabled*/ -int get_radio_status (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "disabled", value); - if ((*value)[0] == '1') - *value = "Down"; - else - *value = "Up"; - return 0; -} - -int get_WiFiRadio_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ""; - return 0; -} - -int set_WiFiRadio_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_WiFiRadio_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmasprintf(value, "%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); - return 0; -} - -/*#Device.WiFi.Radio.{i}.MaxBitRate!UBUS:wifi.radio.@Name/status//maxrate*/ -int get_radio_max_bit_rate (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res = NULL; - char object[32]; - - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); - dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "maxrate"); - return 0; -} - -/*#Device.WiFi.Radio.{i}.OperatingFrequencyBand!UBUS:wifi.radio.@Name/status//band*/ -int get_radio_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res = NULL; - char object[32]; - - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); - dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "band"); - return 0; -} - -/*#Device.WiFi.Radio.{i}.OperatingChannelBandwidth!UCI:wireless/wifi-device,@i-1/bandwidth&UBUS:wifi.radio.@Name/status//bandwidth*/ -int get_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res = NULL; - char object[32], *bandwith; - - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", &bandwith); - if (bandwith[0] == '\0') { - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); - dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - bandwith = dmjson_get_value(res, 1, "bandwidth"); - } - dmastrcat(value, *value, "MHz"); // MEM WILL BE FREED IN DMMEMCLEAN - return 0; -} - -int set_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *pch, *spch, *dup; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dup = dmstrdup(value); - pch = strtok_r(dup, "Mm", &spch); - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", pch); - dmfree(dup); - return 0; - } - return 0; -} - -int get_radio_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "maxassoc", value); - return 0; -} - -int set_radio_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - //TODO - return 0; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "maxassoc", value); - return 0; - } - return 0; -} - -int get_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *val; - *value = "0"; - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "band", &val); - if (val[0] == 'a') { - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "dfsc", value); - if ((*value)[0] == '\0') - *value = "0"; - } - return 0; -} - -int set_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - char *val; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "band", &val); - if (val[0] == 'a') { - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "dfsc", b ? "1" : "0"); - } - return 0; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.SupportedStandards!UBUS:wifi/status//radio[i-1].standard*/ -int get_radio_supported_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res = NULL, *radios = NULL, *arrobj = NULL; - char *name; - int i = 0; - - dmubus_call("wifi", "status", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - dmjson_foreach_obj_in_array(res, arrobj, radios, i, 1, "radios") { - name = dmjson_get_value(radios, 1, "name"); - if (strcmp(name, section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)) == 0) { - *value = dmjson_get_value(radios, 1, "standard"); - return 0; - } - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.OperatingStandards!UCI:wireless/wifi-device,@i-1/hwmode*/ -int get_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", value); - return 0; -} - -int set_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - json_object *res = NULL; - char object[32], *freq; - - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); - dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); - if (!res) return 0; - freq = dmjson_get_value(res, 1, "frequency"); - if (strcmp(freq, "5Ghz") == 0) { - if (strcmp(value, "n") == 0) - value = "11n"; - else if (strcmp(value, "ac") == 0) - value = "11ac"; - } else { - if (strcmp(value, "b") == 0) - value = "11b"; - else if (strcmp(value, "b,g") == 0 || strcmp(value, "g,b") == 0) - value = "11bg"; - else if (strcmp(value, "g") == 0) - value = "11g"; - else if (strcmp(value, "n") == 0) - value = "11n"; - } - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", value); - return 0; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.PossibleChannels!UBUS:wifi.radio.@Name/status//supp_channels[0].channels*/ -int get_radio_possible_channels(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res = NULL, *supp_channels = NULL; - char object[32]; - - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); - dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - supp_channels = dmjson_select_obj_in_array_idx(res, 0, 1, "supp_channels"); - if (supp_channels) - *value = dmjson_get_value_array_all(supp_channels, DELIMITOR, 1, "channels"); - return 0; -} - -int get_WiFiRadio_AutoChannelSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "true"; - return 0; -} - -/*#Device.WiFi.Radio.{i}.AutoChannelRefreshPeriod!UCI:wireless/wifi-device,@i-1/scantimer*/ -int get_WiFiRadio_AutoChannelRefreshPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "scantimer", value); - return 0; -} - -int set_WiFiRadio_AutoChannelRefreshPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "scantimer", value); - break; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.MaxSupportedAssociations!UCI:wireless/wifi-device,@i-1/maxassoc*/ -int get_WiFiRadio_MaxSupportedAssociations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "maxassoc", value); - return 0; -} - -/*#Device.WiFi.Radio.{i}.FragmentationThreshold!UCI:wireless/wifi-device,@i-1/frag*/ -int get_WiFiRadio_FragmentationThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "frag", value); - return 0; -} - -int set_WiFiRadio_FragmentationThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "frag", value); - break; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.RTSThreshold!UCI:wireless/wifi-device,@i-1/rts*/ -int get_WiFiRadio_RTSThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "rts", value); - return 0; -} - -int set_WiFiRadio_RTSThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "rts", value); - break; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.BeaconPeriod!UCI:wireless/wifi-device,@i-1/beacon_int*/ -int get_WiFiRadio_BeaconPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "beacon_int", value); - return 0; -} - -int set_WiFiRadio_BeaconPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "beacon_int", value); - break; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.DTIMPeriod!UCI:wireless/wifi-device,@i-1/dtim_period*/ -int get_WiFiRadio_DTIMPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "dtim_period", value); - return 0; -} - -int set_WiFiRadio_DTIMPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "dtim_period", value); - break; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.SupportedOperatingChannelBandwidths!UBUS:wifi.radio.@Name/status//supp_channels[0].bandwidth*/ -int get_WiFiRadio_SupportedOperatingChannelBandwidths(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res = NULL, *supp_channels = NULL; - char object[32]; - - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); - dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - supp_channels = dmjson_select_obj_in_array_idx(res, 0, 1, "supp_channels"); - if (supp_channels) - *value = dmjson_get_value(supp_channels, 1, "bandwidth"); - return 0; -} - -/*#Device.WiFi.Radio.{i}.OperatingChannelBandwidth!UCI:wireless/wifi-device,@i-1/bandwidth*/ -int get_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", value); - if(*value[0] == '\0') { - *value = ""; - return 0; - } - dmastrcat(value, *value, "MHz"); - return 0; -} - -int set_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", value); - break; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.CurrentOperatingChannelBandwidth!UBUS:wifi.radio.@Name/status//bandwidth*/ -int get_WiFiRadio_CurrentOperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res; - char object[32]; - - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); - dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "bandwidth"); - return 0; -} - -/*#Device.WiFi.Radio.{i}.PreambleType!UCI:wireless/wifi-device,@i-1/short_preamble*/ -int get_WiFiRadio_PreambleType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *preamble = NULL; - - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "short_preamble", &preamble); - if (preamble[0] == '\0' || strlen(preamble) == 0 || strcmp(preamble, "1") != 0) - *value = "long"; - else - *value = "short"; - return 0; -} - -int set_WiFiRadio_PreambleType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, PreambleType, NULL)) - return FAULT_9007; - break; - case VALUESET: - if(strcmp(value, "short") == 0) - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "short_preamble", "1"); - else - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "short_preamble", "0"); - break; - } - return 0; -} - -int get_WiFiRadio_IEEE80211hSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "true"; - return 0; -} - -/*#Device.WiFi.Radio.{i}.IEEE80211hEnabled!UCI:wireless/wifi-device,@i-1/doth*/ -int get_WiFiRadio_IEEE80211hEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "doth", value); - return 0; -} - -int set_WiFiRadio_IEEE80211hEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "doth", b ? "1" : "0"); - break; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.TransmitPower!UCI:wireless/wifi-device,@i-1/txpower*/ -int get_WiFiRadio_TransmitPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "txpower", value); - return 0; -} - -int set_WiFiRadio_TransmitPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_int(value, "-1", "100")) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "txpower", value); - break; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.RegulatoryDomain!UCI:wireless/wifi-device,@i-1/country*/ -int get_WiFiRadio_RegulatoryDomain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *country, **arr; - size_t length; - - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "country", &country); - arr = strsplit(country, "/", &length); - if(arr && arr[0]) - dmasprintf(value, "%s", arr[0]); - else - *value= ""; - - return 0; -} - -int set_WiFiRadio_RegulatoryDomain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *country, **arr; - size_t length; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, "3", "3", NULL, RegulatoryDomain)) - return FAULT_9007; - break; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "country", &country); - if (strlen(country) > 0) { - arr = strsplit(country, "/", &length); - dmasprintf(&country, "%s/%s", value, arr[1]); - } else - dmasprintf(&country, "%s/1", value); - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "country", country); - break; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.ChannelsInUse!UCI:wireless/wifi-device,@i-1/channel*/ -int get_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res = NULL; - - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); - if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') { - char object[32]; - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); - dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "channel"); - } - return 0; -} - -int set_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", "255")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); - return 0; - } - return 0; -} - -/*#Device.WiFi.Radio.{i}.AutoChannelEnable!UCI:wireless/wifi-device,@i-1/channel*/ -int get_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); - if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - json_object *res = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - if (b) - value = "auto"; - else { - char object[32]; - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); - dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); - if (res) return 0; - value = dmjson_get_value(res, 1, "channel"); - } - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); - return 0; - } - return 0; -} - -/************************************************************* -* GET STAT -**************************************************************/ -static int ssid_read_ubus(const struct wifi_ssid_args *args, const char *name, char **value) -{ - json_object *res = NULL; - char object[32]; - - snprintf(object, sizeof(object), "wifi.ap.%s", args->ifname); - dmubus_call(object, "stats", UBUS_ARGS{}, 0, &res); - if (!res) { - *value = "0"; - return 0; - } - *value = dmjson_get_value(res, 1, name); - return 0; -} - -static int radio_read_ubus(const struct wifi_radio_args *args, const char *name, char **value) -{ - json_object *res = NULL; - char object[32]; - - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(args->wifi_radio_sec)); - dmubus_call(object, "stats", UBUS_ARGS{}, 0, &res); - if (!res) { - *value = "0"; - return 0; - } - *value = dmjson_get_value(res, 1, name); - return 0; -} - -/*#Device.WiFi.Radio.{i}.Stats.BytesSent!UBUS:wifi.radio.@Name/stats//tx_bytes*/ -int get_WiFiRadioStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return radio_read_ubus(data, "tx_bytes", value); -} - -/*#Device.WiFi.Radio.{i}.Stats.BytesReceived!UBUS:wifi.radio.@Name/stats//rx_bytes*/ -int get_WiFiRadioStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return radio_read_ubus(data, "rx_bytes", value); -} - -/*#Device.WiFi.Radio.{i}.Stats.PacketsSent!UBUS:wifi.radio.@Name/stats//tx_packets*/ -int get_WiFiRadioStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return radio_read_ubus(data, "tx_packets", value); -} - -/*#Device.WiFi.Radio.{i}.Stats.PacketsReceived!UBUS:wifi.radio.@Name/stats//rx_packets*/ -int get_WiFiRadioStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return radio_read_ubus(data, "rx_packets", value); -} - -/*#Device.WiFi.Radio.{i}.Stats.ErrorsSent!UBUS:wifi.radio.@Name/stats//tx_error_packets*/ -int get_WiFiRadioStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return radio_read_ubus(data, "tx_error_packets", value); -} - -/*#Device.WiFi.Radio.{i}.Stats.ErrorsReceived!UBUS:wifi.radio.@Name/stats//rx_error_packets*/ -int get_WiFiRadioStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return radio_read_ubus(data, "rx_error_packets", value); -} - -/*#Device.WiFi.Radio.{i}.Stats.DiscardPacketsSent!UBUS:wifi.radio.@Name/stats//tx_dropped_packets*/ -int get_WiFiRadioStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return radio_read_ubus(data, "tx_dropped_packets", value); -} - -/*#Device.WiFi.Radio.{i}.Stats.DiscardPacketsReceived!UBUS:wifi.radio.@Name/stats//rx_dropped_packets*/ -int get_WiFiRadioStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return radio_read_ubus(data, "rx_dropped_packets", value); -} - -/*#Device.WiFi.Radio.{i}.Stats.FCSErrorCount!UBUS:wifi.radio.@Name/stats//rx_fcs_error_packets*/ -int get_WiFiRadioStats_FCSErrorCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return radio_read_ubus(data, "rx_fcs_error_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.BytesSent!UBUS:wifi.ap.@Name/stats//tx_bytes*/ -int get_WiFiSSIDStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "tx_bytes", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.BytesReceived!UBUS:wifi.ap.@Name/stats//rx_bytes*/ -int get_WiFiSSIDStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "rx_bytes", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.PacketsSent!UBUS:wifi.ap.@Name/stats//tx_packets*/ -int get_WiFiSSIDStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "tx_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.PacketsReceived!UBUS:wifi.ap.@Name/stats//rx_packets*/ -int get_WiFiSSIDStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "rx_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.ErrorsSent!UBUS:wifi.ap.@Name/stats//tx_error_packets*/ -int get_WiFiSSIDStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "tx_error_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.ErrorsReceived!UBUS:wifi.ap.@Name/stats//rx_error_packets*/ -int get_WiFiSSIDStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "rx_error_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.DiscardPacketsSent!UBUS:wifi.ap.@Name/stats//tx_dropped_packets*/ -int get_WiFiSSIDStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "tx_dropped_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.DiscardPacketsReceived!UBUS:wifi.ap.@Name/stats//rx_dropped_packets*/ -int get_WiFiSSIDStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "rx_dropped_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.UnicastPacketsSent!UBUS:wifi.ap.@Name/stats//tx_unicast_packets*/ -int get_WiFiSSIDStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "tx_unicast_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.UnicastPacketsReceived!UBUS:wifi.ap.@Name/stats//rx_unicast_packets*/ -int get_WiFiSSIDStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "rx_unicast_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.MulticastPacketsSent!UBUS:wifi.ap.@Name/stats//tx_multicast_packets*/ -int get_WiFiSSIDStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "tx_multicast_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.MulticastPacketsReceived!UBUS:wifi.ap.@Name/stats//rx_multicast_packets*/ -int get_WiFiSSIDStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "rx_multicast_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.BroadcastPacketsSent!UBUS:wifi.ap.@Name/stats//tx_broadcast_packets*/ -int get_WiFiSSIDStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "tx_broadcast_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.BroadcastPacketsReceived!UBUS:wifi.ap.@Name/stats//rx_broadcast_packets*/ -int get_WiFiSSIDStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "rx_broadcast_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.RetransCount!UBUS:wifi.ap.@Name/stats//tx_retrans_packets*/ -int get_WiFiSSIDStats_RetransCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "tx_retrans_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.FailedRetransCount!UBUS:wifi.ap.@Name/stats//tx_retrans_fail_packets*/ -int get_WiFiSSIDStats_FailedRetransCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "tx_retrans_fail_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.RetryCount!UBUS:wifi.ap.@Name/stats//tx_retry_packets*/ -int get_WiFiSSIDStats_RetryCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "tx_retry_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.MultipleRetryCount!UBUS:wifi.ap.@Name/stats//tx_multi_retry_packets*/ -int get_WiFiSSIDStats_MultipleRetryCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "tx_multi_retry_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.ACKFailureCount!UBUS:wifi.ap.@Name/stats//ack_fail_packets*/ -int get_WiFiSSIDStats_ACKFailureCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "ack_fail_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.AggregatedPacketCount!UBUS:wifi.ap.@Name/stats//aggregate_packets*/ -int get_WiFiSSIDStats_AggregatedPacketCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "aggregate_packets", value); -} - -/*#Device.WiFi.SSID.{i}.Stats.UnknownProtoPacketsReceived!UBUS:wifi.ap.@Name/stats//rx_unknown_packets*/ -int get_WiFiSSIDStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - return ssid_read_ubus(data, "rx_unknown_packets", value); -} - -static char *get_associative_device_statistics(struct wifi_associative_device_args *wifi_associative_device, char *key) -{ - json_object *res, *jobj; - char *macaddr, *stats = "0"; - int entries = 0; - - dmubus_call("wifix", "stations", UBUS_ARGS{{"vif", wifi_associative_device->wdev, String}}, 1, &res); - while (res) { - jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "stations"); - if(jobj) { - macaddr = dmjson_get_value(jobj, 1, "macaddr"); - if (!strcmp(macaddr, wifi_associative_device->macaddress)) { - stats = dmjson_get_value(jobj, 2, "stats", key); - if(*stats != '\0') - return stats; - } - entries++; - } else - break; - } - return stats; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.BytesSent!UBUS:wifix/stations/vif,@Name/stats.tx_total_bytes*/ -int get_access_point_associative_device_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_total_bytes"); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.BytesReceived!UBUS:wifix/stations/vif,@Name/stats.rx_data_bytes*/ -int get_access_point_associative_device_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "rx_data_bytes"); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.PacketsSent!UBUS:wifix/stations/vif,@Name/stats.tx_total_pkts*/ -int get_access_point_associative_device_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_total_pkts"); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.PacketsReceived!UBUS:wifix/stations/vif,@Name/stats.rx_data_pkts*/ -int get_access_point_associative_device_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "rx_data_pkts"); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.ErrorsSent!UBUS:wifix/stations/vif,@Name/stats.tx_failures*/ -int get_access_point_associative_device_statistics_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_failures"); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.RetransCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retries*/ -int get_access_point_associative_device_statistics_retrans_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_pkts_retries"); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.FailedRetransCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retry_exhausted*/ -int get_access_point_associative_device_statistics_failed_retrans_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_pkts_retry_exhausted"); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.RetryCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retries*/ -int get_access_point_associative_device_statistics_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_pkts_retries"); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.MultipleRetryCount!UBUS:wifix/stations/vif,@Name/stats.tx_data_pkts_retried*/ -int get_access_point_associative_device_statistics_multiple_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr = (struct wifi_associative_device_args*)data; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_data_pkts_retried"); - return 0; -} - -/************************************************************************** -* SET & GET VALUE -***************************************************************************/ -/*#Device.WiFi.SSID.{i}.SSIDAdvertisementEnabled!UCI:wireless/wifi-iface,@i-1/hidden*/ -int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *hidden; - dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "hidden", &hidden); - if (hidden[0] == '1' && hidden[1] == '\0') - *value = "0"; - else - *value = "1"; - return 0; -} - -int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "hidden", b ? "" : "1"); - return 0; - - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.WMMEnable!UCI:wireless/wifi-device,@i-1/wmm*/ -int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - bool b; - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", value); - dmuci_get_option_value_string("wireless", *value, "wmm", value); - string_to_bool(*value, &b); - *value = (b) ? "true" : "false"; - return 0; -} - -int set_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - char *device; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", &device); - if (b) { - dmuci_set_value("wireless", device, "wmm", "1"); - dmuci_set_value("wireless", device, "wmm_noack", "1"); - dmuci_set_value("wireless", device, "wmm_apsd", "1"); - } else { - dmuci_set_value("wireless", device, "wmm", "0"); - dmuci_set_value("wireless", device, "wmm_noack", ""); - dmuci_set_value("wireless", device, "wmm_apsd", ""); - } - return 0; - } - return 0; -} - -int get_access_point_total_associations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res, *jobj; - int entries = 0; - - dmubus_call("wifix", "stations", UBUS_ARGS{{"vif", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res); - DM_ASSERT(res, *value = "0"); - while (1) { - jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "stations"); - if (jobj == NULL) - break; - entries++; - } - dmasprintf(value, "%d", entries); // MEM WILL BE FREED IN DMMEMCLEAN - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.MaxAssociatedDevices!UCI:wireless/wifi-iface,@i-1/maxassoc*/ -int get_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *device; - dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "device", &device); - dmuci_get_option_value_string("wireless", device, "maxassoc", value); - return 0; -} - -int set_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *device; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", &device); - dmuci_set_value("wireless", device, "maxassoc", value); - return 0; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.MACAddressControlEnabled!UCI:wireless/wifi-iface,@i-1/macfilter*/ -int get_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *macfilter; - - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "macfilter", &macfilter); - if (strcmp(macfilter, "deny") == 0 || strcmp(macfilter, "disable") == 0) - *value = "false"; - else - *value = "true"; - return 0; -} - -int get_WiFiAccessPoint_WMMCapability(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "true"; - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.MaxAllowedAssociations!UCI:wireless/wifi-iface,@i-1/maxassoc*/ -int get_WiFiAccessPoint_MaxAllowedAssociations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *device; - - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", &device); - dmuci_get_option_value_string("wireless", device, "maxassoc", value); - return 0; -} - -int set_WiFiAccessPoint_MaxAllowedAssociations(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *device; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", &device); - dmuci_set_value("wireless", device, "maxassoc", value); - break; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.IsolationEnable!UCI:wireless/wifi-iface,@i-1/isolate*/ -int get_WiFiAccessPoint_IsolationEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "isolate", value); - return 0; -} - -int set_WiFiAccessPoint_IsolationEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "isolate", b ? "1" : "0"); - break; - } - return 0; -} - -int get_WiFiAccessPoint_AllowedMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *val; - dmuci_get_value_by_section_list(((struct wifi_acp_args *)data)->wifi_acp_sec, "maclist", &val); - if (val) - *value = dmuci_list_to_string(val, " "); - else - *value = ""; - return 0; -} - -int set_WiFiAccessPoint_AllowedMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - size_t length; - int i; - char **arr; - - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, NULL, NULL, "17", NULL, MACAddress)) - return FAULT_9007; - break; - case VALUESET: - arr= strsplit(value, " ", &length); - for (i = 0; i < length; i++){ - dmuci_add_list_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "maclist", arr[i]); - } - break; - } - return 0; -} - -int get_WiFiAccessPoint_UAPSDCapability(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "true"; - return 0; -} - -int set_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "macfilter", b ? "allow" : "disable"); - return 0; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.UAPSDEnable!UCI:wireless/wifi-iface,@i-1/wmm_apsd*/ -int get_WiFiAccessPoint_UAPSDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "wmm_apsd", value); - return 0; -} - -int set_WiFiAccessPoint_UAPSDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wmm_apsd", b ? "1" : "0"); - break; - } - return 0; -} - -int get_access_point_security_supported_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "None, WEP-64, WEP-128, WPA-Personal, WPA2-Personal, WPA-WPA2-Personal, WPA-Enterprise, WPA2-Enterprise, WPA-WPA2-Enterprise"; - return 0; -} - -static void get_value_security_mode(char **value, char *encryption, char *cipher) -{ - if (strcmp(encryption, "none") == 0) - *value = "None"; - else if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0) - *value = "WEP-64"; - else if (strcmp(encryption, "psk") == 0) - *value = "WPA-Personal"; - else if (strcmp(encryption, "wpa") == 0) - *value = "WPA-Enterprise"; - else if ((strcmp(encryption, "psk2") == 0 && strcmp(cipher, "auto") == 0) || (strcmp(encryption, "psk2") == 0 && strcmp(cipher, "ccmp") == 0) || (strcmp(encryption, "psk2") == 0 && *cipher == '\0')) - *value = "WPA2-Personal"; - else if (strcmp(encryption, "wpa2") == 0) - *value = "WPA2-Enterprise"; - else if ((strcmp(encryption, "mixed-psk") == 0 && strcmp(cipher, "auto") == 0) || (strcmp(encryption, "mixed-psk") == 0 && strcmp(cipher, "ccmp") == 0) || (strcmp(encryption, "mixed-psk") == 0 && strcmp(cipher, "tkip+ccmp") == 0) || (strcmp(encryption, "mixed-psk") == 0 && *cipher == '\0')) - *value = "WPA-WPA2-Personal"; - else if (strcmp(encryption, "wpa-mixed") == 0 || strcmp(encryption, "mixed-wpa") == 0) - *value = "WPA-WPA2-Enterprise"; -} - -int get_access_point_security_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *encryption, *cipher, *mode; - - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", &cipher); - if (*encryption == '\0' && *cipher == '\0') { - *value = "None"; - return 0; - } - else - get_value_security_mode(&mode, encryption, cipher); - - *value = mode; - return 0; -} - -int set_access_point_security_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *option, *gnw; - char *encryption, *cipher, *mode; - char strk64[4][11]; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", &cipher); - get_value_security_mode(&mode, encryption, cipher); - if (strcmp(value, mode) != 0) { - if (strcmp(value, "None") == 0) { - reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "none"); - } - else if (strcmp(value, "WEP-64") == 0 || strcmp(value, "WEP-128") == 0) { - reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "wep-open"); - wepkey64("Iopsys", strk64); - int i = 0; - while (i < 4) { - dmasprintf(&option, "key%d", i + 1); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, option, strk64[i]); - dmfree(option); - i++; - } - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", "1"); - } - else if (strcmp(value, "WPA-Personal") == 0) { - reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); - gnw = get_nvram_wpakey(); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "psk"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", gnw); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", "tkip"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", "3600"); - dmfree(gnw); - } - else if (strcmp(value, "WPA-Enterprise") == 0) { - reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "wpa"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", ""); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", "1812"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", ""); - } - else if (strcmp(value, "WPA2-Personal") == 0) { - reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); - gnw = get_nvram_wpakey(); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "psk2"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", gnw); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", "ccmp"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", "3600"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps", "1"); - dmfree(gnw); - } - else if (strcmp(value, "WPA2-Enterprise") == 0) { - reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "wpa2"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", ""); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", "1812"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", ""); - } - else if (strcmp(value, "WPA-WPA2-Personal") == 0) { - reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); - gnw = get_nvram_wpakey(); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "mixed-psk"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", gnw); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", "tkip+ccmp"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", "3600"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps", "1"); - dmfree(gnw); - } - else if (strcmp(value, "WPA-WPA2-Enterprise") == 0) { - reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "wpa-mixed"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", ""); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", "1812"); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", ""); - } - } - return 0; - } - return 0; -} - -int set_access_point_security_wepkey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *key_index, *encryption; - char buf[8]; - - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, "13", "13")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); - if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0 ) { - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "key_index", &key_index); - snprintf(buf, sizeof(buf), "key%s", key_index); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, buf, value); - } - return 0; - } - return 0; -} - -int get_access_point_security_wepkey_index(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *key_index; - - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "key_index", &key_index); - if (*key_index == '\0') - *value = "1"; - else - *value = key_index; - return 0; -} - -int set_access_point_security_wepkey_index(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - //TODO - return 0; - case VALUESET: - if (atoi(value)>=1 && atoi(value)<=4) { - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key_index", value); - } - return 0; - } - return 0; -} - -int set_access_point_security_shared_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *encryption; - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "32")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); - if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", value); - } - return 0; - } - return 0; -} - -int set_access_point_security_passphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *encryption; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, "8", "63", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); - if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { - set_access_point_security_shared_key(refparam, ctx, data, instance, value, action); - } - return 0; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Security.RekeyingInterval!UCI:wireless/wifi-iface,@i-1/gtk_rekey*/ -int get_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", value); - return 0; -} - -int set_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *encryption; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); - if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0 || strcmp(encryption, "none") == 0) - return 0; - else { - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", value); - } - return 0; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Security.RadiusServerIPAddr!UCI:wireless/wifi-iface,@i-1/radius_server*/ -int get_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", value); - return 0; -} - -int set_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *encryption; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); - if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0 || strcmp(encryption, "wpa-mixed") == 0) - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", value); - return 0; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Security.RadiusServerPort!UCI:wireless/wifi-iface,@i-1/radius_port*/ -int get_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", value); - return 0; -} - -int set_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *encryption; - - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); - if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0 || strcmp(encryption, "wpa-mixed") == 0) - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", value); - return 0; - } - return 0; -} - -int set_access_point_security_radius_secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *encryption; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); - if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0 || strcmp(encryption, "wpa-mixed") == 0) - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", value); - return 0; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Security.MFPConfig!UCI:wireless/wifi-iface,@i-1/ieee80211w*/ -int get_WiFiAccessPointSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "ieee80211w", value); - return 0; -} - -int set_WiFiAccessPointSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, MFPConfig, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "ieee80211w", value); - break; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.WPS.Enable!UCI:wireless/wifi-iface,@i-1/wps*/ -int get_WiFiAccessPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps", value); - if(*value[0] == '\0') - *value= "0"; - return 0; -} - -int set_WiFiAccessPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps", b ? "1" : "0"); - break; - } - return 0; -} - -int get_WiFiAccessPointWPS_ConfigMethodsSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "PushButton,Label,PIN"; - return 0; -} - -int get_WiFiAccessPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *pushbut = NULL, *label = NULL, *pin = NULL, *str1, *str2, *str3; - - dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pushbutton", &pushbut); - dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_label", &label); - dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pin", &pin); - - if (pushbut == NULL || pushbut[0] == '\0' || strcmp(pushbut, "1") != 0) - str1 = dmstrdup(""); - else - str1 = dmstrdup("PushButton"); - - if (label == NULL || label[0] == '\0' || strcmp(label, "1") != 0) - str2 = dmstrdup(""); - else { - if(pushbut == NULL || pushbut[0] == '\0' || strcmp(pushbut, "1") != 0) - str2 = dmstrdup("Label"); - else - str2 = dmstrdup(",Label"); - } - - if( pin == NULL || pin[0] == '\0') - str3 = dmstrdup(""); - else { - if((pushbut != NULL && pushbut[0] != '\0' && strcmp(pushbut, "1") == 0) || (label != NULL && label[0] != '\0' && strcmp(label, "1") == 0)) - str3 = dmstrdup(",PIN"); - else - str3 = dmstrdup("PIN"); - } - - dmasprintf(value,"%s%s%s", str1, str2, str3); - return 0; -} - -int set_WiFiAccessPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.WPS.Status!UCI:wireless/wifi-iface,@i-1/wps*/ -int get_WiFiAccessPointWPS_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *wps_status; - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps", &wps_status); - if (strcmp(wps_status, "0") == 0) - *value = "Disabled"; - else - *value = "Configured"; - return 0; -} - -int get_WiFiAccessPointWPS_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.WPS.PIN!UCI:wireless/wifi-iface,@i-1/wps_pin*/ -int get_WiFiAccessPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps_pin", value); - return 0; -} - -int set_WiFiAccessPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "8", NULL, PIN)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps_pin", value); - break; - } - return 0; -} - -int get_WiFiAccessPointAccounting_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_WiFiAccessPointAccounting_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Accounting.ServerIPAddr!UCI:wireless/wifi-iface,@i-1/acct_server*/ -int get_WiFiAccessPointAccounting_ServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_server", value); - return 0; -} - -int set_WiFiAccessPointAccounting_ServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_server", value); - break; - } - return 0; -} - -int get_WiFiAccessPointAccounting_SecondaryServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_WiFiAccessPointAccounting_SecondaryServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "45", NULL, IPAddress)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Accounting.ServerPort!UCI:wireless/wifi-iface,@i-1/acct_port*/ -int get_WiFiAccessPointAccounting_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_port", value); - return 0; -} - -int set_WiFiAccessPointAccounting_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_port", value); - break; - } - return 0; -} - -int get_WiFiAccessPointAccounting_SecondaryServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_WiFiAccessPointAccounting_SecondaryServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Accounting.Secret!UCI:wireless/wifi-iface,@i-1/acct_secret*/ -int get_WiFiAccessPointAccounting_Secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_secret", value); - return 0; -} - -int set_WiFiAccessPointAccounting_Secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "acct_secret", value); - break; - } - return 0; -} - -int get_WiFiAccessPointAccounting_SecondarySecret(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_WiFiAccessPointAccounting_SecondarySecret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_WiFiAccessPointAccounting_InterimInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_WiFiAccessPointAccounting_InterimInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "60", NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_radio_supported_frequency_bands(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "2.4GHz,5GHz"; - return 0; -} - -int get_access_point_associative_device_lastdatadownlinkrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; - dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->lastdatadownloadlinkrate); - return 0; -} - -int get_access_point_associative_device_lastdatauplinkrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; - dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->lastdatauplinkrate); - return 0; -} - -int get_access_point_associative_device_signalstrength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; - dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->signalstrength); - return 0; -} - -int get_WiFiAccessPointAssociatedDevice_Retransmissions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; - dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->retransmissions); - return 0; -} - -int get_WiFiAccessPointAssociatedDevice_AssociationTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; - dmasprintf(value, "%s", cur_wifi_associative_device_args_ptr->assoctime?int_period_to_date_time_format(cur_wifi_associative_device_args_ptr->assoctime):"0"); - return 0; -} - -int get_access_point_associative_device_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; - dmasprintf(value, cur_wifi_associative_device_args_ptr->macaddress); - return 0; -} - -int get_access_point_associative_device_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; - dmasprintf(value, "%s", cur_wifi_associative_device_args_ptr->active?"true":"false"); - return 0; -} - - -int get_WiFiAccessPointAssociatedDevice_Noise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data; - dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->noise); - return 0; -} - -int get_access_point_ieee80211r_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "ieee80211r", value); - if ((*value)[0] == '\0') - *value = "0"; - return 0; -} - -int set_access_point_ieee80211r_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "ieee80211r", b ? "1" : "0"); - return 0; - } - return 0; -} - -/*#Device.WiFi.EndPoint.{i}.Enable!UCI:wireless/wifi-iface,@i-1/disabled*/ -int get_WiFiEndPoint_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "disabled", value); - if (((*value)[0] == '\0') || ((*value)[0] == '0')) - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_WiFiEndPoint_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "disabled", b ? "0" : "1"); - break; - } - return 0; -} - -/*#Device.WiFi.EndPoint.{i}.Status!UCI:wireless/wifi-iface,@i-1/disabled*/ -int get_WiFiEndPoint_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "disabled", value); - if ((*value)[0] == '\0' || (*value)[0] == '0') - *value = "Up"; - else - *value = "Down"; - return 0; -} - -int get_WiFiEndPoint_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_enp_args *)data)->wifi_enp_sec), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "endpointalias", value); - return 0; -} - -int set_WiFiEndPoint_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_enp_args *)data)->wifi_enp_sec), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "endpointalias", value); - return 0; - } - return 0; -} - -int get_WiFiEndPoint_ProfileReference(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_WiFiEndPoint_ProfileReference(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_WiFiEndPoint_SSIDReference(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cSSID%c", dmroot, dm_delim, dm_delim, dm_delim), ((struct wifi_enp_args *)data)->ifname, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; - return 0; -} - -int get_WiFiEndPointProfile_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -int set_WiFiEndPointProfile_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -int get_WiFiEndPointProfile_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "Active"; - return 0; -} - -int get_WiFiEndPointProfile_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL, *dm = NULL; - char *epinst = NULL; - - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name((struct uci_section*)data), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "endpointinstance", &epinst); - get_dmmap_section_of_config_section_eq("dmmap_wireless", "ep_profile", "ep_key", epinst, &dm); - if (dm) - dmuci_get_value_by_section_string(dm, "ep_profile_alias", value); - return 0; -} - -int set_WiFiEndPointProfile_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL, *dm = NULL; - char *epinst = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name((struct uci_section*)data), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "endpointinstance", &epinst); - get_dmmap_section_of_config_section_eq("dmmap_wireless", "ep_profile", "ep_key", epinst, &dm); - if (dm) - DMUCI_SET_VALUE_BY_SECTION(bbfdm, dm, "ep_profile_alias", value); - break; - } - return 0; -} - -/*#Device.WiFi.EndPoint.{i}.Profile.{i}.SSID!UCI:wireless/wifi-iface,@i-1/ssid*/ -int get_WiFiEndPointProfile_SSID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section*)data, "ssid", value); - return 0; -} - -int set_WiFiEndPointProfile_SSID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "32", NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section*)data, "ssid", value); - break; - } - return 0; -} - -int get_WiFiEndPointProfile_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_WiFiEndPointProfile_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -int get_WiFiEndPointProfile_Priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int set_WiFiEndPointProfile_Priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, "255")) - return FAULT_9007; - break; - case VALUESET: - //TODO - break; - } - return 0; -} - -/*#Device.WiFi.EndPoint.{i}.Profile.{i}.Security.SSID!UCI:wireless/wifi-iface,@i-1/encryption*/ -int get_WiFiEndPointProfileSecurity_ModeEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *encryption, *cipher, *mode; - - dmuci_get_value_by_section_string((struct uci_section *)data, "encryption", &encryption); - dmuci_get_value_by_section_string((struct uci_section *)data, "cipher", &cipher); - if (*encryption == '\0' && *cipher == '\0') { - *value = "None"; - return 0; - } - else - get_value_security_mode(&mode, encryption, cipher); - - *value = mode; - return 0; -} - -int set_WiFiEndPointProfileSecurity_ModeEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *option, *gnw; - char *encryption, *cipher, *mode; - char strk64[4][11]; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); - dmuci_get_value_by_section_string((struct uci_section*)data, "cipher", &cipher); - get_value_security_mode(&mode, encryption, cipher); - - if (strcmp(value, mode) != 0) { - if (strcmp(value, "None") == 0) { - reset_wlan((struct uci_section*)data); - dmuci_set_value_by_section((struct uci_section*)data, "encryption", "none"); - } - else if (strcmp(value, "WEP-64") == 0 || strcmp(value, "WEP-128") == 0) { - reset_wlan((struct uci_section*)data); - dmuci_set_value_by_section((struct uci_section*)data, "encryption", "wep-open"); - wepkey64("Iopsys", strk64); - int i = 0; - while (i < 4) { - dmasprintf(&option, "key%d", i + 1); - dmuci_set_value_by_section((struct uci_section*)data, option, strk64[i]); - dmfree(option); - i++; - } - dmuci_set_value_by_section((struct uci_section*)data, "key", "1"); - } - else if (strcmp(value, "WPA-Personal") == 0) { - reset_wlan((struct uci_section*)data); - gnw = get_nvram_wpakey(); - dmuci_set_value_by_section((struct uci_section*)data, "encryption", "psk"); - dmuci_set_value_by_section((struct uci_section*)data, "key", gnw); - dmuci_set_value_by_section((struct uci_section*)data, "cipher", "tkip"); - dmuci_set_value_by_section((struct uci_section*)data, "gtk_rekey", "3600"); - dmfree(gnw); - } - else if (strcmp(value, "WPA-Enterprise") == 0) { - reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); - dmuci_set_value_by_section((struct uci_section*)data, "encryption", "wpa"); - dmuci_set_value_by_section((struct uci_section*)data, "radius_server", ""); - dmuci_set_value_by_section((struct uci_section*)data, "radius_port", "1812"); - dmuci_set_value_by_section((struct uci_section*)data, "radius_secret", ""); - } - else if (strcmp(value, "WPA2-Personal") == 0) { - reset_wlan((struct uci_section*)data); - gnw = get_nvram_wpakey(); - dmuci_set_value_by_section((struct uci_section*)data, "encryption", "psk2"); - dmuci_set_value_by_section((struct uci_section*)data, "key", gnw); - dmuci_set_value_by_section((struct uci_section*)data, "cipher", "ccmp"); - dmuci_set_value_by_section((struct uci_section*)data, "gtk_rekey", "3600"); - dmuci_set_value_by_section((struct uci_section*)data, "wps", "1"); - dmfree(gnw); - } - else if (strcmp(value, "WPA2-Enterprise") == 0) { - reset_wlan((struct uci_section*)data); - dmuci_set_value_by_section((struct uci_section*)data, "encryption", "wpa2"); - dmuci_set_value_by_section((struct uci_section*)data, "radius_server", ""); - dmuci_set_value_by_section((struct uci_section*)data, "radius_port", "1812"); - dmuci_set_value_by_section((struct uci_section*)data, "radius_secret", ""); - } - else if (strcmp(value, "WPA-WPA2-Personal") == 0) { - reset_wlan((struct uci_section*)data); - gnw = get_nvram_wpakey(); - dmuci_set_value_by_section((struct uci_section*)data, "encryption", "mixed-psk"); - dmuci_set_value_by_section((struct uci_section*)data, "key", gnw); - dmuci_set_value_by_section((struct uci_section*)data, "cipher", "tkip+ccmp"); - dmuci_set_value_by_section((struct uci_section*)data, "gtk_rekey", "3600"); - dmuci_set_value_by_section((struct uci_section*)data, "wps", "1"); - dmfree(gnw); - } - else if (strcmp(value, "WPA-WPA2-Enterprise") == 0) { - reset_wlan((struct uci_section*)data); - dmuci_set_value_by_section((struct uci_section*)data, "encryption", "wpa-mixed"); - dmuci_set_value_by_section((struct uci_section*)data, "radius_server", ""); - dmuci_set_value_by_section((struct uci_section*)data, "radius_port", "1812"); - dmuci_set_value_by_section((struct uci_section*)data, "radius_secret", ""); - } - } - return 0; - } - return 0; -} - -int set_WiFiEndPointProfileSecurity_WEPKey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *key_index, *encryption; - char buf[8]; - - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, "13", "13")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); - if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0 ) { - dmuci_get_value_by_section_string((struct uci_section*)data, "key_index", &key_index); - sprintf(buf,"key%s", key_index); - dmuci_set_value_by_section((struct uci_section*)data, buf, value); - } - return 0; - } - return 0; -} - -int set_WiFiEndPointProfileSecurity_PreSharedKey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *encryption; - - switch (action) { - case VALUECHECK: - if (dm_validate_hexBinary(value, NULL, "32")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); - if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { - dmuci_set_value_by_section((struct uci_section*)data, "key", value); - } - return 0; - } - return 0; -} - -int set_WiFiEndPointProfileSecurity_KeyPassphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *encryption; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, "8", "63", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); - if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { - set_WiFiEndPointProfileSecurity_PreSharedKey(refparam, ctx, data, instance, value, action); - } - return 0; - } - return 0; -} - -/*#Device.WiFi.EndPoint.{i}.Profile.{i}.Security.MFPConfig!UCI:wireless/wifi-iface,@i-1/ieee80211w*/ -int get_WiFiEndPointProfileSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section*)data, "ieee80211w", value); - return 0; -} - -int set_WiFiEndPointProfileSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, MFPConfig, NULL)) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section((struct uci_section*)data, "ieee80211w", value); - break; - } - return 0; -} - -int get_WiFiEndPointStats_LastDataDownlinkRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_WiFiEndPointStats_LastDataUplinkRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_WiFiEndPointStats_SignalStrength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_WiFiEndPointStats_Retransmissions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -int get_WiFiEndPointSecurity_ModesSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.WiFi.EndPoint.{i}.WPS.Enable!UCI:wireless/wifi-iface,@i-1/wps*/ -int get_WiFiEndPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps", value); - if(*value[0] == '\0') - *value = "0"; - return 0; -} - -int set_WiFiEndPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - break; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps", b ? "1" : "0"); - break; - } - return 0; -} - -int get_WiFiEndPointWPS_ConfigMethodsSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "PushButton,Label,PIN"; - return 0; -} - -int get_WiFiEndPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *pushbut = NULL, *label = NULL, *pin = NULL, *str1, *str2, *str3; - - dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pushbutton", &pushbut); - dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_label", &label); - dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pin", &pin); - - if (pushbut == NULL || pushbut[0]=='\0' || strcmp(pushbut, "1")!=0) - str1 = dmstrdup(""); - else - str1 = dmstrdup("PushButton"); - - if (label == NULL || label[0]=='\0' || strcmp(label, "1")!=0) - str2 = dmstrdup(""); - else { - if (pushbut == NULL || pushbut[0]=='\0' || strcmp(pushbut, "1")!=0) - str2 = dmstrdup("Label"); - else - str2 = dmstrdup(",Label"); - } - - if (pin == NULL || pin[0]=='\0') - str3 = dmstrdup(""); - else { - if ((pushbut != NULL && pushbut[0] != '\0' && strcmp(pushbut, "1") == 0) || (label != NULL && label[0] != '\0' && strcmp(label, "1") == 0)) - str3 = dmstrdup(",PIN"); - else - str3 = dmstrdup("PIN"); - } - - dmasprintf(value,"%s%s%s", str1, str2, str3); - return 0; -} - -int set_WiFiEndPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) - return FAULT_9007; - break; - case VALUESET: - break; - } - return 0; -} - -/*#Device.WiFi.EndPoint.{i}.WPS.Status!UCI:wireless/wifi-iface,@i-1/wps*/ -int get_WiFiEndPointWPS_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *wps_status; - - dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps", &wps_status); - if (strcmp(wps_status, "0") == 0 || wps_status[0] == '\0') - *value = "Disabled"; - else - *value = "Configured"; - return 0; -} - -int get_WiFiEndPointWPS_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - //TODO - return 0; -} - -/*#Device.WiFi.EndPoint.{i}.WPS.PIN!UCI:wireless/wifi-iface,@i-1/wps_pin*/ -int get_WiFiEndPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pin", value); - return 0; -} - -int set_WiFiEndPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "8", "8")) - return FAULT_9007; - break; - case VALUESET: - dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pin", value); - break; - } - return 0; -} - -int get_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *ss; - json_object *res = NULL, *neighboring_wifi_obj = NULL; - char object[32]; - - uci_foreach_sections("wireless", "wifi-device", ss) { - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(ss)); - dmubus_call(object, "scanresults", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = "None"); - neighboring_wifi_obj = dmjson_select_obj_in_array_idx(res, 0, 1, "accesspoints"); - if (neighboring_wifi_obj) { - *value = "Complete"; - break; - } else - *value = "None"; - } - return 0; -} - -int set_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *ss; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, DiagnosticsState, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (strcmp(value, "Requested") == 0) { - uci_foreach_sections("wireless", "wifi-device", ss) { - char object[32]; - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(ss)); - dmubus_call_set(object, "scan", UBUS_ARGS{}, 0); - } - dmubus_call_set("tr069", "inform", UBUS_ARGS{{"event", "8 DIAGNOSTICS COMPLETE", String}}, 1); - } - return 0; - } - return 0; -} - -int get_neighboring_wifi_diagnostics_result_number_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *ss; - json_object *res = NULL, *accesspoints = NULL; - size_t entries = 0, result = 0; - char object[32]; - *value = "0"; - - uci_foreach_sections("wireless", "wifi-device", ss) { - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(ss)); - dmubus_call(object, "scanresults", UBUS_ARGS{}, 0, &res); - if (res) { - json_object_object_get_ex(res, "accesspoints", &accesspoints); - if (accesspoints) - entries = json_object_array_length(accesspoints); - } - result = result + entries; - entries = 0; - } - dmasprintf(value, "%d", result); // MEM WILL BE FREED IN DMMEMCLEAN - return 0; -} - -int get_neighboring_wifi_diagnostics_result_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "ssid"); - return 0; -} - -int get_neighboring_wifi_diagnostics_result_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "bssid"); - return 0; -} - -int get_neighboring_wifi_diagnostics_result_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "channel"); - return 0; -} - -int get_neighboring_wifi_diagnostics_result_signal_strength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "rssi"); - return 0; -} - -int get_neighboring_wifi_diagnostics_result_operating_frequency_band(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "band"); - return 0; -} - -int get_neighboring_wifi_diagnostics_result_noise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value((json_object *)data, 1, "snr"); - return 0; -} - -/************************************************************************** -* SET AND GET ALIAS -***************************************************************************/ -int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-device", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "radioalias", value); - return 0; -} - -int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-device", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "radioalias", value); - return 0; - } - return 0; -} - -int get_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_ssid_args *)data)->wifi_ssid_sec), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "ssidalias", value); - return 0; -} - -int set_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_ssid_args *)data)->wifi_ssid_sec), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "ssidalias", value); - return 0; - } - return 0; -} - -int get_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_acp_args *)data)->wifi_acp_sec), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "accesspointalias", value); - return 0; -} - -int set_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_acp_args *)data)->wifi_acp_sec), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "accesspointalias", value); - return 0; - } - return 0; -} -/************************************************************* -* GET & SET LOWER LAYER -**************************************************************/ -int get_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - if (data && ((struct wifi_ssid_args *)data)->linker[0] != '\0') { - adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cRadio%c", dmroot, dm_delim, dm_delim, dm_delim), ((struct wifi_ssid_args *)data)->linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; - } - return 0; -} - -int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *linker, *newvalue = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string_list(value, NULL, NULL, "1024", NULL, NULL, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - if (value[strlen(value)-1] != '.') { - dmasprintf(&newvalue, "%s.", value); - adm_entry_get_linker_value(ctx, newvalue, &linker); - } else - adm_entry_get_linker_value(ctx, value, &linker); - if (linker) { - dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "device", linker); - dmfree(linker); - } else - return FAULT_9005; - return 0; - } - return 0; -} - -int get_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cSSID%c", dmroot, dm_delim, dm_delim, dm_delim), ((struct wifi_acp_args *)data)->ifname, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; - return 0; -} - -/************************************************************* -* ADD DEL OBJ -**************************************************************/ -int add_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *value, *v, *inst, ssid[16] = {0}; - struct uci_section *s = NULL, *dmmap_wifi = NULL; - - check_create_dmmap_package("dmmap_wireless"); - inst = get_last_instance_bbfdm("dmmap_wireless", "wifi-iface", "ssidinstance"); - snprintf(ssid, sizeof(ssid), "iopsys_%d", inst ? (atoi(inst)+1) : 1); - dmuci_add_section("wireless", "wifi-iface", &s, &value); - dmuci_set_value_by_section(s, "device", "wl0"); - dmuci_set_value_by_section(s, "encryption", "none"); - dmuci_set_value_by_section(s, "macfilter", "0"); - dmuci_set_value_by_section(s, "mode", "ap"); - dmuci_set_value_by_section(s, "ssid", ssid); - - dmuci_add_section_bbfdm("dmmap_wireless", "wifi-iface", &dmmap_wifi, &v); - dmuci_set_value_by_section(dmmap_wifi, "section_name", section_name(s)); - *instance = update_instance_bbfdm(dmmap_wifi, inst, "ssidinstance"); - return 0; -} - -int delete_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - int found = 0; - struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; - - switch (del_action) { - case DEL_INST: - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_ssid_args *)data)->wifi_ssid_sec), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, NULL, NULL); - break; - case DEL_ALL: - uci_foreach_sections("wireless", "wifi-iface", s) { - if (found != 0){ - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ss), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL){ - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ss), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - return 0; - } - return 0; -} - -int addObjWiFiEndPoint(char *refparam, struct dmctx *ctx, void *data, char **instance) -{ - char *value, *v, *instancepara, *instancepara1, *instancepara2; - struct uci_section *endpoint_sec = NULL, *dmmap_sec= NULL; - - check_create_dmmap_package("dmmap_wireless"); - instancepara1 = get_last_instance_lev2_bbfdm("wireless", "wifi-iface", "dmmap_wireless", "endpointinstance", "mode", "wet")?get_last_instance_lev2_bbfdm("wireless", "wifi-iface", "dmmap_wireless", "endpointinstance", "mode", "wet"):"0"; - instancepara2 = get_last_instance_lev2_bbfdm("wireless", "wifi-iface", "dmmap_wireless", "endpointinstance", "mode", "sta")?get_last_instance_lev2_bbfdm("wireless", "wifi-iface", "dmmap_wireless", "endpointinstance", "mode", "sta"):"0"; - instancepara=atoi(instancepara1)>atoi(instancepara2)?dmstrdup(instancepara1):dmstrdup(instancepara2); - dmuci_add_section("wireless", "wifi-iface", &endpoint_sec, &value); - dmuci_set_value_by_section(endpoint_sec, "device", "wl1"); - dmuci_set_value_by_section(endpoint_sec, "mode", "wet"); - dmuci_set_value_by_section(endpoint_sec, "network", "lan"); - - dmuci_add_section_bbfdm("dmmap_wireless", "wifi-iface", &dmmap_sec, &v); - dmuci_set_value_by_section(dmmap_sec, "section_name", section_name(endpoint_sec)); - *instance = update_instance_bbfdm(dmmap_sec, instancepara, "endpointinstance"); - return 0; -} - -int delObjWiFiEndPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *s = NULL, *dmmap_section = NULL; - char *mode; - - switch (del_action) { - case DEL_INST: - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_ssid_args *)data)->wifi_ssid_sec), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "endpointinstance", ""); - dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "mode", ""); - break; - case DEL_ALL: - uci_foreach_sections("wireless", "wifi-iface", s) { - dmuci_get_value_by_section_string(s, "mode", &mode); - if (strcmp(mode, "sta") != 0 && strcmp(mode, "wet") != 0) - continue; - dmuci_set_value_by_section(s, "mode", ""); - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(s), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "endpointinstance", ""); - } - } - return 0; -} -/************************************************************* -* ENTRY METHOD -**************************************************************/ -/*#Device.WiFi.Radio.{i}.!UCI:wireless/wifi-device/dmmap_wireless*/ -int browseWifiRadioInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *wnum = NULL, *wnum_last = NULL; - struct wifi_radio_args curr_wifi_radio_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("wireless", "wifi-device", "dmmap_wireless", &dup_list); - list_for_each_entry(p, &dup_list, list) { - init_wifi_radio(&curr_wifi_radio_args, p->config_section); - wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, p->dmmap_section, "radioinstance", "radioalias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wifi_radio_args, wnum) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -/*#Device.WiFi.SSID.{i}.!UCI:wireless/wifi-iface/dmmap_wireless*/ -int browseWifiSsidInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *wnum = NULL, *ssid_last = NULL, *ifname, *linker; - struct wifi_ssid_args curr_wifi_ssid_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("wireless", "wifi-iface", "dmmap_wireless", &dup_list); - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "device", &linker); - ifname = get_device_from_wifi_iface(linker, section_name(p->config_section)); - init_wifi_ssid(&curr_wifi_ssid_args, p->config_section, ifname, linker); - wnum = handle_update_instance(1, dmctx, &ssid_last, update_instance_alias, 3, p->dmmap_section, "ssidinstance", "ssidalias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wifi_ssid_args, wnum) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.!UCI:wireless/wifi-iface/dmmap_wireless*/ -int browseWifiAccessPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *wnum = NULL, *ifname, *acpt_last = NULL, *mode = NULL; - struct wifi_acp_args curr_wifi_acp_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("wireless", "wifi-iface", "dmmap_wireless", &dup_list); - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "mode", &mode); - if ((strlen(mode)>0 || mode[0] != '\0') &&strcmp(mode, "ap") != 0) - continue; - dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); - init_wifi_acp(&curr_wifi_acp_args, p->config_section, ifname); - wnum = handle_update_instance(1, dmctx, &acpt_last, update_instance_alias, 3, p->dmmap_section, "accesspointinstance", "accesspointalias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wifi_acp_args, wnum) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -/*#Device.WiFi.EndPoint.{i}.!UCI:wireless/wifi-iface/dmmap_wireless*/ -int browseWiFiEndPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *wnum = NULL, *ifname, *acpt_last = NULL, *mode= NULL; - struct wifi_enp_args curr_wifi_enp_args = {0}; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("wireless", "wifi-iface", "dmmap_wireless", &dup_list); - list_for_each_entry(p, &dup_list, list) { - dmuci_get_value_by_section_string(p->config_section, "mode", &mode); - if(strcmp(mode, "wet")!=0 && strcmp(mode, "sta")!=0) - continue; - dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); - init_wifi_enp(&curr_wifi_enp_args, p->config_section, ifname); - wnum = handle_update_instance(1, dmctx, &acpt_last, update_instance_alias, 3, p->dmmap_section, "endpointinstance", "endpointalias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wifi_enp_args, wnum) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int browse_wifi_associated_device(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - json_object *res, *associated_client_obj; - struct uci_section *ss = NULL; - char *value, *ap_ifname, *idx, *idx_last = NULL; - int id = 0, entries = 0; - char *macaddr = NULL, *lastdatadownloadlinkrate = NULL, *lastdatauplinkrate = NULL, *signalstrength = NULL, *noise = NULL, *retrans = NULL, *assoctimestr = NULL; - struct wifi_associative_device_args cur_wifi_associative_device_args = {0}; - struct uci_section *dmmap_section; - - uci_foreach_sections("wireless", "wifi-iface", ss) { - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ss), &dmmap_section); - dmuci_get_value_by_section_string(dmmap_section, "accesspointinstance", &value); - if(!strcmp(value, prev_instance)){ - dmuci_get_value_by_section_string(ss, "ifname", &ap_ifname); - break; - } - } - - dmubus_call("wifix", "stations", UBUS_ARGS{{"vif", ap_ifname, String}}, 1, &res); - while (res) { - associated_client_obj = dmjson_select_obj_in_array_idx(res, entries, 1, "stations"); - if(associated_client_obj) { - cur_wifi_associative_device_args.wdev = ap_ifname; - macaddr = dmjson_get_value(associated_client_obj, 1, "macaddr"); - if(macaddr!=NULL && strlen(macaddr)>0) - dmasprintf(&(cur_wifi_associative_device_args.macaddress),dmjson_get_value(associated_client_obj, 1, "macaddr")); - cur_wifi_associative_device_args.active = 1; - lastdatadownloadlinkrate = dmjson_get_value(associated_client_obj, 2, "stats", "rate_of_last_rx_pkt"); - if(lastdatadownloadlinkrate!=NULL && strlen(lastdatadownloadlinkrate)>0) - cur_wifi_associative_device_args.lastdatadownloadlinkrate = atoi(lastdatadownloadlinkrate); - else - cur_wifi_associative_device_args.lastdatadownloadlinkrate = 0; - lastdatauplinkrate = dmjson_get_value(associated_client_obj, 2, "stats", "rate_of_last_tx_pkt"); - if(lastdatauplinkrate!=NULL && strlen(lastdatauplinkrate)>0) - cur_wifi_associative_device_args.lastdatauplinkrate = atoi(lastdatauplinkrate); - else - cur_wifi_associative_device_args.lastdatauplinkrate = 0; - signalstrength=dmjson_get_value(associated_client_obj, 1, "rssi"); - if(signalstrength!=NULL && strlen(signalstrength)>0) - cur_wifi_associative_device_args.signalstrength = atoi(signalstrength); - else - cur_wifi_associative_device_args.signalstrength = 0; - noise=dmjson_get_value(associated_client_obj, 1, "snr"); - if(noise!=NULL && strlen(noise)>0) - cur_wifi_associative_device_args.noise = atoi(noise); - else - cur_wifi_associative_device_args.noise = 0; - retrans= dmjson_get_value(associated_client_obj, 2, "stats", "tx_pkts_retries"); - cur_wifi_associative_device_args.retransmissions= atoi(retrans); - - assoctimestr=dmjson_get_value(associated_client_obj, 1, "in_network"); - if(assoctimestr!=NULL && strlen(assoctimestr)>0) - cur_wifi_associative_device_args.assoctime = atoi(assoctimestr); - else - cur_wifi_associative_device_args.assoctime = 0; - - entries++; - idx = handle_update_instance(3, dmctx, &idx_last, update_instance_without_section, 1, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_wifi_associative_device_args, idx) == DM_STOP) - break; - } - else - break; - } - return 0; -} - -int browseWifiNeighboringWiFiDiagnosticResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *ss; - json_object *res = NULL, *accesspoints = NULL, *arrobj = NULL; - char object[32], *idx, *idx_last = NULL; - int id = 0, i = 0; - - uci_foreach_sections("wireless", "wifi-device", ss) { - snprintf(object, sizeof(object), "wifi.radio.%s", section_name(ss)); - dmubus_call(object, "scanresults", UBUS_ARGS{}, 0, &res); - if (res) { - dmjson_foreach_obj_in_array(res, arrobj, accesspoints, i, 1, "accesspoints") { - idx = handle_update_instance(3, dmctx, &idx_last, update_instance_without_section, 1, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)accesspoints, idx) == DM_STOP) - return 0; - } - } - } - return 0; -} - -int browseWiFiEndPointProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - struct uci_section *s= NULL; - char *v, *instnbr = NULL, *ep_instance; - struct wifi_enp_args *ep_args = (struct wifi_enp_args *)prev_data; - struct uci_section *dmmap_section = NULL; - - check_create_dmmap_package("dmmap_wireless"); - - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ep_args->wifi_enp_sec), &dmmap_section); - dmuci_get_value_by_section_string(dmmap_section, "endpointinstance", &ep_instance); - s = is_dmmap_section_exist_eq("dmmap_wireless", "ep_profile", "ep_key", ep_instance); - if(!s) - dmuci_add_section_bbfdm("dmmap_wireless", "ep_profile", &s, &v); - DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "ep_key", ep_instance); - handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "ep_profile_instance", "ep_profile_alias"); - - DM_LINK_INST_OBJ(dmctx, parent_node, ep_args->wifi_enp_sec, "1"); - return 0; -} diff --git a/dmtree/tr181/wifi.h b/dmtree/tr181/wifi.h index ffc8454b..0189af3f 100644 --- a/dmtree/tr181/wifi.h +++ b/dmtree/tr181/wifi.h @@ -15,43 +15,6 @@ #include -struct wifi_radio_args -{ - struct uci_section *wifi_radio_sec; -}; - -struct wifi_ssid_args -{ - struct uci_section *wifi_ssid_sec; - char *ifname; - char *linker; -}; - -struct wifi_enp_args -{ - struct uci_section *wifi_enp_sec; - char *ifname; -}; - -struct wifi_acp_args -{ - struct uci_section *wifi_acp_sec; - char *ifname; -}; - -struct wifi_associative_device_args -{ - int active; - int lastdatadownloadlinkrate; - int lastdatauplinkrate; - int signalstrength; - char *macaddress; - char *wdev; - int noise; - int retransmissions; - int assoctime; -}; - extern DMOBJ tWiFiObj[]; extern DMLEAF tWiFiParams[]; extern DMOBJ tWiFiRadioObj[]; @@ -81,256 +44,4 @@ extern DMOBJ tWiFiEndPointProfileObj[]; extern DMLEAF tWiFiEndPointProfileParams[]; extern DMLEAF tWiFiEndPointProfileSecurityParams[]; -int browseWifiSsidInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseWifiAccessPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseWifiRadioInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browse_wifi_associated_device(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseWifiNeighboringWiFiDiagnosticResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseWiFiEndPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseWiFiEndPointProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int add_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int addObjWiFiEndPoint(char *refparam, struct dmctx *ctx, void *data, char **instance); -int delObjWiFiEndPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_WiFi_RadioNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFi_SSIDNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFi_AccessPointNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFi_EndPointNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - -int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_max_bit_rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_supported_frequency_bands(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_supported_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_radio_possible_channels(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_AutoChannelSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_AutoChannelRefreshPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadioStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadioStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadioStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadioStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadioStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadioStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadioStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadioStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadioStats_FCSErrorCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_wifi_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_wlan_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_RetransCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_FailedRetransCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_RetryCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_MultipleRetryCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_ACKFailureCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_AggregatedPacketCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSIDStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_wifi_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_total_associations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_security_supported_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_security_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_security_wepkey_index(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_ieee80211r_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_lastdatadownlinkrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_lastdatauplinkrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_signalstrength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_statistics_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_statistics_retrans_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_statistics_failed_retrans_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_statistics_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_access_point_associative_device_statistics_multiple_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_neighboring_wifi_diagnostics_result_number_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_neighboring_wifi_diagnostics_result_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_neighboring_wifi_diagnostics_result_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_neighboring_wifi_diagnostics_result_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_neighboring_wifi_diagnostics_result_signal_strength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_neighboring_wifi_diagnostics_result_operating_frequency_band(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_neighboring_wifi_diagnostics_result_noise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_linker_Wifi_Radio(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_linker_Wifi_Ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_linker_associated_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); -int get_WiFiRadio_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_MaxSupportedAssociations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_FragmentationThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_RTSThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_SupportedOperatingChannelBandwidths(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_CurrentOperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_BeaconPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_DTIMPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointWPS_ConfigMethodsSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointWPS_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointWPS_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointAssociatedDevice_Noise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointAccounting_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointAccounting_ServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointAccounting_SecondaryServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointAccounting_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointAccounting_SecondaryServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointAccounting_Secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointAccounting_SecondarySecret(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointAccounting_InterimInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiSSID_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPoint_UAPSDCapability(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPoint_WMMCapability(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPoint_UAPSDCapability(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPoint_UAPSDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointAssociatedDevice_Retransmissions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPoint_MaxAllowedAssociations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_PreambleType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_IEEE80211hSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_IEEE80211hEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_TransmitPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiRadio_RegulatoryDomain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPoint_IsolationEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPointAssociatedDevice_AssociationTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPoint_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPoint_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPoint_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPoint_ProfileReference(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPoint_SSIDReference(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointStats_LastDataDownlinkRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointStats_LastDataUplinkRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointStats_SignalStrength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointStats_Retransmissions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointSecurity_ModesSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointWPS_ConfigMethodsSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointWPS_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointWPS_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiAccessPoint_AllowedMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointProfile_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointProfile_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointProfile_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointProfile_SSID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointProfile_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointProfile_Priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointProfileSecurity_ModeEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_WiFiEndPointProfileSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_radio_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiRadio_AutoChannelRefreshPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_security_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_security_wepkey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_security_wepkey_index(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_security_shared_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_security_passphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_security_radius_secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_access_point_ieee80211r_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiRadio_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiRadio_FragmentationThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiRadio_RTSThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiRadio_BeaconPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiRadio_DTIMPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointAccounting_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointAccounting_ServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointAccounting_SecondaryServerIPAddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointAccounting_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointAccounting_SecondaryServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointAccounting_Secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointAccounting_SecondarySecret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointAccounting_InterimInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPoint_UAPSDEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPointSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPoint_MaxAllowedAssociations(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiRadio_PreambleType(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiRadio_IEEE80211hEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiRadio_TransmitPower(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiRadio_RegulatoryDomain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPoint_IsolationEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPoint_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPoint_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPoint_ProfileReference(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointWPS_PIN(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiAccessPoint_AllowedMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointProfile_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointProfile_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointProfile_SSID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointProfile_Location(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointProfile_Priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointProfileSecurity_ModeEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointProfileSecurity_WEPKey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointProfileSecurity_PreSharedKey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointProfileSecurity_KeyPassphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_WiFiEndPointProfileSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/x_iopsys_eu_buttons.c b/dmtree/tr181/x_iopsys_eu_buttons.c index fcd7b89b..b2c7c577 100644 --- a/dmtree/tr181/x_iopsys_eu_buttons.c +++ b/dmtree/tr181/x_iopsys_eu_buttons.c @@ -12,19 +12,6 @@ #include "x_iopsys_eu_buttons.h" -/*** DMROOT.X_IOPSYS_EU_Buttons.{i}. ****/ -DMLEAF X_IOPSYS_EU_ButtonParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Alias", &DMWRITE, DMT_STRING, get_x_iopsys_eu_button_alias, set_x_iopsys_eu_button_alias, NULL, NULL, BBFDM_BOTH}, -{"button", &DMREAD, DMT_STRING, get_x_iopsys_eu_button_name, NULL, NULL, NULL, BBFDM_BOTH}, -{"hotplug", &DMREAD, DMT_STRING, get_x_iopsys_eu_button_hotplug, NULL, NULL, NULL, BBFDM_BOTH}, -{"hotplug_long", &DMREAD, DMT_STRING, get_x_iopsys_eu_button_hotplug_long, NULL, NULL, NULL, BBFDM_BOTH}, -{"minpress", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_button_minpress, set_x_iopsys_eu_button_minpress, NULL, NULL, BBFDM_BOTH}, -{"longpress", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_button_longpress, set_x_iopsys_eu_button_longpress, NULL, NULL, BBFDM_BOTH}, -{"enable", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_button_enable, set_x_iopsys_eu_button_enable, NULL, NULL, BBFDM_BOTH}, -{0} -}; - int browseXIopsysEuButton(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *ibutton = NULL, *ibutton_last = NULL; @@ -45,7 +32,7 @@ int browseXIopsysEuButton(struct dmctx *dmctx, DMNODE *parent_node, void *prev_d **** function related to button **** **************************************************************************************/ -int get_x_iopsys_eu_button_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_button_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_list *val; @@ -57,25 +44,25 @@ int get_x_iopsys_eu_button_name(char *refparam, struct dmctx *ctx, void *data, c return 0; } -int get_x_iopsys_eu_button_hotplug(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_button_hotplug(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "hotplug", value); return 0; } -int get_x_iopsys_eu_button_hotplug_long(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_button_hotplug_long(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "hotplug_long", value); return 0; } -int get_x_iopsys_eu_button_minpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_button_minpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "minpress", value); return 0; } -int set_x_iopsys_eu_button_minpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_button_minpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -88,13 +75,13 @@ int set_x_iopsys_eu_button_minpress(char *refparam, struct dmctx *ctx, void *dat return 0; } -int get_x_iopsys_eu_button_longpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_button_longpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "longpress", value); return 0; } -int set_x_iopsys_eu_button_longpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_button_longpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -108,7 +95,7 @@ int set_x_iopsys_eu_button_longpress(char *refparam, struct dmctx *ctx, void *da } -int get_x_iopsys_eu_button_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_button_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "enable", value); if ((*value)[0] == '\0') { @@ -117,7 +104,7 @@ int get_x_iopsys_eu_button_enable(char *refparam, struct dmctx *ctx, void *data, return 0; } -int set_x_iopsys_eu_button_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_button_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -134,7 +121,7 @@ int set_x_iopsys_eu_button_enable(char *refparam, struct dmctx *ctx, void *data, return 0; } ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_x_iopsys_eu_button_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_button_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *dmmap_section = NULL; @@ -144,7 +131,7 @@ int get_x_iopsys_eu_button_alias(char *refparam, struct dmctx *ctx, void *data, return 0; } -int set_x_iopsys_eu_button_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_button_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *dmmap_section = NULL; @@ -161,3 +148,16 @@ int set_x_iopsys_eu_button_alias(char *refparam, struct dmctx *ctx, void *data, } return 0; } + +/*** DMROOT.X_IOPSYS_EU_Buttons.{i}. ****/ +DMLEAF X_IOPSYS_EU_ButtonParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Alias", &DMWRITE, DMT_STRING, get_x_iopsys_eu_button_alias, set_x_iopsys_eu_button_alias, NULL, NULL, BBFDM_BOTH}, +{"button", &DMREAD, DMT_STRING, get_x_iopsys_eu_button_name, NULL, NULL, NULL, BBFDM_BOTH}, +{"hotplug", &DMREAD, DMT_STRING, get_x_iopsys_eu_button_hotplug, NULL, NULL, NULL, BBFDM_BOTH}, +{"hotplug_long", &DMREAD, DMT_STRING, get_x_iopsys_eu_button_hotplug_long, NULL, NULL, NULL, BBFDM_BOTH}, +{"minpress", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_button_minpress, set_x_iopsys_eu_button_minpress, NULL, NULL, BBFDM_BOTH}, +{"longpress", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_button_longpress, set_x_iopsys_eu_button_longpress, NULL, NULL, BBFDM_BOTH}, +{"enable", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_button_enable, set_x_iopsys_eu_button_enable, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/x_iopsys_eu_buttons.h b/dmtree/tr181/x_iopsys_eu_buttons.h index d14ddcfb..cb1ce301 100644 --- a/dmtree/tr181/x_iopsys_eu_buttons.h +++ b/dmtree/tr181/x_iopsys_eu_buttons.h @@ -16,17 +16,7 @@ #include extern DMLEAF X_IOPSYS_EU_ButtonParams[]; + int browseXIopsysEuButton(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int get_x_iopsys_eu_button_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_x_iopsys_eu_button_hotplug(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_x_iopsys_eu_button_hotplug_long(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_x_iopsys_eu_button_minpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_button_minpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_button_longpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_button_longpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_button_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_button_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_button_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_button_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); #endif diff --git a/dmtree/tr181/x_iopsys_eu_dropbear.c b/dmtree/tr181/x_iopsys_eu_dropbear.c index eac5fb09..1b1f21ba 100644 --- a/dmtree/tr181/x_iopsys_eu_dropbear.c +++ b/dmtree/tr181/x_iopsys_eu_dropbear.c @@ -11,24 +11,6 @@ #include "x_iopsys_eu_dropbear.h" -/*** DMROOT.X_IOPSYS_EU_Dropbear.{i}. ****/ -DMLEAF X_IOPSYS_EU_DropbearParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Alias", &DMWRITE, DMT_STRING, get_x_iopsys_eu_dropbear_alias, set_x_iopsys_eu_dropbear_alias, NULL, NULL, BBFDM_BOTH}, -{"PasswordAuth", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_dropbear_password_auth, set_x_iopsys_eu_dropbear_password_auth, NULL, NULL, BBFDM_BOTH}, -{"RootPasswordAuth", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_dropbear_root_password_auth, set_x_iopsys_eu_dropbear_root_password_auth, NULL, NULL, BBFDM_BOTH}, -{"Port", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_dropbear_port, set_x_iopsys_eu_dropbear_port, NULL, NULL, BBFDM_BOTH}, -{"RootLogin", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_dropbear_root_login, set_x_iopsys_eu_dropbear_root_login, NULL, NULL, BBFDM_BOTH}, -{"GatewayPorts", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_dropbear_gateway_ports, set_x_iopsys_eu_dropbear_gateway_ports, NULL, NULL, BBFDM_BOTH}, -{"Interface", &DMWRITE, DMT_STRING, get_x_iopsys_eu_dropbear_interface, set_x_iopsys_eu_dropbear_interface, NULL, NULL, BBFDM_BOTH}, -{"rsakeyfile", &DMWRITE, DMT_STRING, get_x_iopsys_eu_dropbear_rsakeyfile, set_x_iopsys_eu_dropbear_rsakeyfile, NULL, NULL, BBFDM_BOTH}, -{"dsskeyfile", &DMWRITE, DMT_STRING, get_x_iopsys_eu_dropbear_dsskeyfile, set_x_iopsys_eu_dropbear_dsskeyfile, NULL, NULL, BBFDM_BOTH}, -{"SSHKeepAlive", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_dropbear_ssh_keepalive, set_x_iopsys_eu_dropbear_ssh_keepalive, NULL, NULL, BBFDM_BOTH}, -{"IdleTimeout", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_dropbear_idle_timeout, set_x_iopsys_eu_dropbear_idle_timeout, NULL, NULL, BBFDM_BOTH}, -{"verbose", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_dropbear_verbose, set_x_iopsys_eu_dropbear_verbose, NULL, NULL, BBFDM_BOTH}, -{"BannerFile", &DMWRITE, DMT_STRING, get_x_iopsys_eu_dropbear_banner_file, set_x_iopsys_eu_dropbear_banner_file, NULL, NULL, BBFDM_BOTH}, -{0} -}; int browseXIopsysEuDropbear(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { @@ -48,7 +30,7 @@ int browseXIopsysEuDropbear(struct dmctx *dmctx, DMNODE *parent_node, void *prev /************************************************************************************* **** function **** **************************************************************************************/ -int get_x_iopsys_eu_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "PasswordAuth", value); if ((*value)[0] == '\0' || ((*value)[0] == 'o' && (*value)[1] == 'n') || (*value)[0] == '1') @@ -58,7 +40,7 @@ int get_x_iopsys_eu_dropbear_password_auth(char *refparam, struct dmctx *ctx, vo return 0; } -int set_x_iopsys_eu_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -75,7 +57,7 @@ int set_x_iopsys_eu_dropbear_password_auth(char *refparam, struct dmctx *ctx, vo return 0; } -int get_x_iopsys_eu_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "RootPasswordAuth", value); if ((*value)[0] == '\0' || ((*value)[0] == 'o' && (*value)[1] == 'n') || (*value)[0] == '1') @@ -85,7 +67,7 @@ int get_x_iopsys_eu_dropbear_root_password_auth(char *refparam, struct dmctx *ct return 0; } -int set_x_iopsys_eu_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -102,7 +84,7 @@ int set_x_iopsys_eu_dropbear_root_password_auth(char *refparam, struct dmctx *ct return 0; } -int get_x_iopsys_eu_dropbear_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "Port", value); if ((*value)[0] == '\0') { @@ -111,7 +93,7 @@ int get_x_iopsys_eu_dropbear_port(char *refparam, struct dmctx *ctx, void *data, return 0; } -int set_x_iopsys_eu_dropbear_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -127,7 +109,7 @@ int set_x_iopsys_eu_dropbear_port(char *refparam, struct dmctx *ctx, void *data, return 0; } -int get_x_iopsys_eu_dropbear_root_login(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_root_login(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "RootLogin", value); if ((*value)[0] == '\0' || ((*value)[0] == 'o' && (*value)[1] == 'n') || (*value)[0] == '1' ) @@ -137,7 +119,7 @@ int get_x_iopsys_eu_dropbear_root_login(char *refparam, struct dmctx *ctx, void return 0; } -int set_x_iopsys_eu_dropbear_root_login(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_root_login(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -154,7 +136,7 @@ int set_x_iopsys_eu_dropbear_root_login(char *refparam, struct dmctx *ctx, void return 0; } -int get_x_iopsys_eu_dropbear_verbose(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_verbose(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "verbose", value); if ((*value)[0] == '\0' || (*value)[0] == '0' ) @@ -164,7 +146,7 @@ int get_x_iopsys_eu_dropbear_verbose(char *refparam, struct dmctx *ctx, void *da return 0; } -int set_x_iopsys_eu_dropbear_verbose(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_verbose(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -181,7 +163,7 @@ int set_x_iopsys_eu_dropbear_verbose(char *refparam, struct dmctx *ctx, void *da return 0; } -int get_x_iopsys_eu_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "GatewayPorts", value); if ((*value)[0] == '\0' || (*value)[0] == '0' ) @@ -191,7 +173,7 @@ int get_x_iopsys_eu_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, vo return 0; } -int set_x_iopsys_eu_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -208,13 +190,13 @@ int set_x_iopsys_eu_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, vo return 0; } -int get_x_iopsys_eu_dropbear_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "Interface", value); return 0; } -int set_x_iopsys_eu_dropbear_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -227,13 +209,13 @@ int set_x_iopsys_eu_dropbear_interface(char *refparam, struct dmctx *ctx, void * return 0; } -int get_x_iopsys_eu_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "rsakeyfile", value); return 0; } -int set_x_iopsys_eu_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -246,13 +228,13 @@ int set_x_iopsys_eu_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void return 0; } -int get_x_iopsys_eu_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "dsskeyfile", value); return 0; } -int set_x_iopsys_eu_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -265,7 +247,7 @@ int set_x_iopsys_eu_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void return 0; } -int get_x_iopsys_eu_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "SSHKeepAlive", value); if ((*value)[0] == '\0') { @@ -274,7 +256,7 @@ int get_x_iopsys_eu_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, vo return 0; } -int set_x_iopsys_eu_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -290,7 +272,7 @@ int set_x_iopsys_eu_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, vo return 0; } -int get_x_iopsys_eu_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "IdleTimeout", value); if ((*value)[0] == '\0') { @@ -299,7 +281,7 @@ int get_x_iopsys_eu_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, voi return 0; } -int set_x_iopsys_eu_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -315,13 +297,13 @@ int set_x_iopsys_eu_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, voi return 0; } -int get_x_iopsys_eu_dropbear_banner_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_banner_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "BannerFile", value); return 0; } -int set_x_iopsys_eu_dropbear_banner_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_banner_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -336,7 +318,7 @@ int set_x_iopsys_eu_dropbear_banner_file(char *refparam, struct dmctx *ctx, void ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_x_iopsys_eu_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *dmmap_section = NULL; @@ -346,7 +328,7 @@ int get_x_iopsys_eu_dropbear_alias(char *refparam, struct dmctx *ctx, void *data return 0; } -int set_x_iopsys_eu_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *dmmap_section = NULL; @@ -425,3 +407,21 @@ int delete_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char return 0; } +/*** DMROOT.X_IOPSYS_EU_Dropbear.{i}. ****/ +DMLEAF X_IOPSYS_EU_DropbearParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Alias", &DMWRITE, DMT_STRING, get_x_iopsys_eu_dropbear_alias, set_x_iopsys_eu_dropbear_alias, NULL, NULL, BBFDM_BOTH}, +{"PasswordAuth", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_dropbear_password_auth, set_x_iopsys_eu_dropbear_password_auth, NULL, NULL, BBFDM_BOTH}, +{"RootPasswordAuth", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_dropbear_root_password_auth, set_x_iopsys_eu_dropbear_root_password_auth, NULL, NULL, BBFDM_BOTH}, +{"Port", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_dropbear_port, set_x_iopsys_eu_dropbear_port, NULL, NULL, BBFDM_BOTH}, +{"RootLogin", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_dropbear_root_login, set_x_iopsys_eu_dropbear_root_login, NULL, NULL, BBFDM_BOTH}, +{"GatewayPorts", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_dropbear_gateway_ports, set_x_iopsys_eu_dropbear_gateway_ports, NULL, NULL, BBFDM_BOTH}, +{"Interface", &DMWRITE, DMT_STRING, get_x_iopsys_eu_dropbear_interface, set_x_iopsys_eu_dropbear_interface, NULL, NULL, BBFDM_BOTH}, +{"rsakeyfile", &DMWRITE, DMT_STRING, get_x_iopsys_eu_dropbear_rsakeyfile, set_x_iopsys_eu_dropbear_rsakeyfile, NULL, NULL, BBFDM_BOTH}, +{"dsskeyfile", &DMWRITE, DMT_STRING, get_x_iopsys_eu_dropbear_dsskeyfile, set_x_iopsys_eu_dropbear_dsskeyfile, NULL, NULL, BBFDM_BOTH}, +{"SSHKeepAlive", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_dropbear_ssh_keepalive, set_x_iopsys_eu_dropbear_ssh_keepalive, NULL, NULL, BBFDM_BOTH}, +{"IdleTimeout", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_dropbear_idle_timeout, set_x_iopsys_eu_dropbear_idle_timeout, NULL, NULL, BBFDM_BOTH}, +{"verbose", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_dropbear_verbose, set_x_iopsys_eu_dropbear_verbose, NULL, NULL, BBFDM_BOTH}, +{"BannerFile", &DMWRITE, DMT_STRING, get_x_iopsys_eu_dropbear_banner_file, set_x_iopsys_eu_dropbear_banner_file, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/x_iopsys_eu_dropbear.h b/dmtree/tr181/x_iopsys_eu_dropbear.h index 71598ec2..c279dffa 100644 --- a/dmtree/tr181/x_iopsys_eu_dropbear.h +++ b/dmtree/tr181/x_iopsys_eu_dropbear.h @@ -15,34 +15,9 @@ #include extern DMLEAF X_IOPSYS_EU_DropbearParams[]; -int browseXIopsysEuDropbear(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int get_x_iopsys_eu_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_root_login(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_root_login(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_verbose(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_verbose(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_banner_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_banner_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + int add_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char **instancepara); int delete_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int browseXIopsysEuDropbear(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); #endif diff --git a/dmtree/tr181/x_iopsys_eu_ice.c b/dmtree/tr181/x_iopsys_eu_ice.c index b2656a04..d9b47944 100644 --- a/dmtree/tr181/x_iopsys_eu_ice.c +++ b/dmtree/tr181/x_iopsys_eu_ice.c @@ -11,21 +11,13 @@ #include "x_iopsys_eu_ice.h" -/*** DMROOT.X_IOPSYS_EU_ICE. ***/ -DMLEAF tSe_IceParam[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_ice_cloud_enable, set_ice_cloud_enable, NULL, NULL, BBFDM_BOTH}, -{"Server", &DMWRITE, DMT_STRING, get_ice_cloud_server, set_ice_cloud_server, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -int get_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("ice", "cloud", "enabled", value); return 0; } -int set_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -42,13 +34,13 @@ int set_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *in return 0; } -int get_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("ice", "cloud", "server", value); return 0; } -int set_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -61,3 +53,11 @@ int set_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *in } return 0; } + +/*** DMROOT.X_IOPSYS_EU_ICE. ***/ +DMLEAF tSe_IceParam[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_ice_cloud_enable, set_ice_cloud_enable, NULL, NULL, BBFDM_BOTH}, +{"Server", &DMWRITE, DMT_STRING, get_ice_cloud_server, set_ice_cloud_server, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/x_iopsys_eu_ice.h b/dmtree/tr181/x_iopsys_eu_ice.h index aa45fcbd..3efefd74 100644 --- a/dmtree/tr181/x_iopsys_eu_ice.h +++ b/dmtree/tr181/x_iopsys_eu_ice.h @@ -16,10 +16,4 @@ extern DMLEAF tSe_IceParam[]; -int get_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/x_iopsys_eu_igmp.c b/dmtree/tr181/x_iopsys_eu_igmp.c index 57231fb8..49820263 100644 --- a/dmtree/tr181/x_iopsys_eu_igmp.c +++ b/dmtree/tr181/x_iopsys_eu_igmp.c @@ -11,34 +11,13 @@ #include "x_iopsys_eu_igmp.h" -DMLEAF tSe_IgmpParam[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"DifferentiateService", &DMWRITE, DMT_STRING, get_igmp_dscp_mark, set_igmp_dscp_mark, NULL, NULL, BBFDM_BOTH}, -{"ProxyInterface", &DMWRITE, DMT_STRING, get_igmp_proxy_interface, set_igmp_proxy_interface, NULL, NULL, BBFDM_BOTH}, -{"DefaultVersion", &DMWRITE, DMT_STRING, get_igmp_default_version, set_igmp_default_version, NULL, NULL, BBFDM_BOTH}, -{"QueryInterval", &DMWRITE, DMT_UNINT, get_igmp_query_interval, set_igmp_query_interval, NULL, NULL, BBFDM_BOTH}, -{"QueryResponseInterval", &DMWRITE, DMT_UNINT, get_igmp_query_response_interval, set_igmp_query_response_interval, NULL, NULL, BBFDM_BOTH}, -{"LastMemberQueryInterval", &DMWRITE, DMT_UNINT, get_igmp_last_member_queryinterval, set_igmp_last_member_queryinterval, NULL, NULL, BBFDM_BOTH}, -{"RobustnessValue", &DMWRITE, DMT_INT, get_igmp_robustness_value, set_igmp_robustness_value, NULL, NULL, BBFDM_BOTH}, -{"LanToLanMulticastEnable", &DMWRITE, DMT_BOOL, get_igmp_multicast_enable, set_igmp_multicast_enable, NULL, NULL, BBFDM_BOTH}, -{"MaxGroup", &DMWRITE, DMT_UNINT, get_igmp_maxgroup, set_igmp_maxgroup, NULL, NULL, BBFDM_BOTH}, -{"MaxSources", &DMWRITE, DMT_UNINT, get_igmp_maxsources, set_igmp_maxsources, NULL, NULL, BBFDM_BOTH}, -{"MaxMembers", &DMWRITE, DMT_UNINT, get_igmp_maxmembers, set_igmp_maxmembers, NULL, NULL, BBFDM_BOTH}, -{"FastLeaveEnable", &DMWRITE, DMT_BOOL, get_igmp_fastleave_enable, set_igmp_fastleave_enable, NULL, NULL, BBFDM_BOTH}, -{"JoinImmediateEnable", &DMWRITE, DMT_BOOL, get_igmp_joinimmediate_enable, set_igmp_joinimmediate_enable, NULL, NULL, BBFDM_BOTH}, -{"ProxyEnable", &DMWRITE, DMT_BOOL, get_igmp_proxy_enable, set_igmp_proxy_enable, NULL, NULL, BBFDM_BOTH}, -{"SnoopingMode", &DMWRITE, DMT_STRING, get_igmp_snooping_mode, set_igmp_snooping_mode, NULL, NULL, BBFDM_BOTH}, -{"SnoopingInterfaces", &DMWRITE, DMT_STRING, get_igmp_snooping_interface, set_igmp_snooping_interface, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -int get_igmp_dscp_mark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_dscp_mark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_dscp_mark", value); return 0; } -int set_igmp_dscp_mark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_dscp_mark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -50,7 +29,7 @@ int set_igmp_dscp_mark(char *refparam, struct dmctx *ctx, void *data, char *inst return 0; } -int get_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *p; dmuci_get_option_value_string("mcpd", "mcpd", "igmp_proxy_interfaces", value); @@ -62,7 +41,7 @@ int get_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int set_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *p; @@ -85,13 +64,13 @@ int set_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int get_igmp_default_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_default_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_default_version", value); return 0; } -int set_igmp_default_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_default_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -103,13 +82,13 @@ int set_igmp_default_version(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int get_igmp_query_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_query_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_query_interval", value); return 0; } -int set_igmp_query_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_query_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -121,13 +100,13 @@ int set_igmp_query_interval(char *refparam, struct dmctx *ctx, void *data, char return 0; } -int get_igmp_query_response_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_query_response_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_query_response_interval", value); return 0; } -int set_igmp_query_response_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_query_response_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -139,13 +118,13 @@ int set_igmp_query_response_interval(char *refparam, struct dmctx *ctx, void *da return 0; } -int get_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_last_member_query_interval", value); return 0; } -int set_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -157,13 +136,13 @@ int set_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, void * return 0; } -int get_igmp_robustness_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_robustness_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_robustness_value", value); return 0; } -int set_igmp_robustness_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_robustness_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -175,7 +154,7 @@ int set_igmp_robustness_value(char *refparam, struct dmctx *ctx, void *data, cha return 0; } -int get_igmp_multicast_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_multicast_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_lan_to_lan_multicast", value); if ((*value)[0] == '\0') { @@ -184,7 +163,7 @@ int get_igmp_multicast_enable(char *refparam, struct dmctx *ctx, void *data, cha return 0; } -int set_igmp_multicast_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_multicast_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -201,7 +180,7 @@ int set_igmp_multicast_enable(char *refparam, struct dmctx *ctx, void *data, cha return 0; } -int get_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_fast_leave", value); if ((*value)[0] == '\0') { @@ -210,7 +189,7 @@ int get_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, void *data, cha return 0; } -int set_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -227,7 +206,7 @@ int set_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, void *data, cha return 0; } -int get_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_join_immediate", value); if ((*value)[0] == '\0') { @@ -236,7 +215,7 @@ int get_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, void *data, return 0; } -int set_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -253,7 +232,7 @@ int set_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, void *data, return 0; } -int get_igmp_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_proxy_enable", value); if ((*value)[0] == '\0') { @@ -262,7 +241,7 @@ int get_igmp_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *i return 0; } -int set_igmp_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -279,13 +258,13 @@ int set_igmp_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *i return 0; } -int get_igmp_maxgroup(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_maxgroup(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_max_groups", value); return 0; } -int set_igmp_maxgroup(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_maxgroup(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -297,13 +276,13 @@ int set_igmp_maxgroup(char *refparam, struct dmctx *ctx, void *data, char *insta return 0; } -int get_igmp_maxsources(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_maxsources(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_max_sources", value); return 0; } -int set_igmp_maxsources(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_maxsources(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -315,13 +294,13 @@ int set_igmp_maxsources(char *refparam, struct dmctx *ctx, void *data, char *ins return 0; } -int get_igmp_maxmembers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_maxmembers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_max_members", value); return 0; } -int set_igmp_maxmembers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_maxmembers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -333,13 +312,13 @@ int set_igmp_maxmembers(char *refparam, struct dmctx *ctx, void *data, char *ins return 0; } -int get_igmp_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_snooping_enable", value); return 0; } -int set_igmp_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -351,7 +330,7 @@ int set_igmp_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char * return 0; } -int get_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *p; @@ -365,7 +344,7 @@ int get_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, c return 0; } -int set_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *p; @@ -387,3 +366,24 @@ int set_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, c } return 0; } + +DMLEAF tSe_IgmpParam[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"DifferentiateService", &DMWRITE, DMT_STRING, get_igmp_dscp_mark, set_igmp_dscp_mark, NULL, NULL, BBFDM_BOTH}, +{"ProxyInterface", &DMWRITE, DMT_STRING, get_igmp_proxy_interface, set_igmp_proxy_interface, NULL, NULL, BBFDM_BOTH}, +{"DefaultVersion", &DMWRITE, DMT_STRING, get_igmp_default_version, set_igmp_default_version, NULL, NULL, BBFDM_BOTH}, +{"QueryInterval", &DMWRITE, DMT_UNINT, get_igmp_query_interval, set_igmp_query_interval, NULL, NULL, BBFDM_BOTH}, +{"QueryResponseInterval", &DMWRITE, DMT_UNINT, get_igmp_query_response_interval, set_igmp_query_response_interval, NULL, NULL, BBFDM_BOTH}, +{"LastMemberQueryInterval", &DMWRITE, DMT_UNINT, get_igmp_last_member_queryinterval, set_igmp_last_member_queryinterval, NULL, NULL, BBFDM_BOTH}, +{"RobustnessValue", &DMWRITE, DMT_INT, get_igmp_robustness_value, set_igmp_robustness_value, NULL, NULL, BBFDM_BOTH}, +{"LanToLanMulticastEnable", &DMWRITE, DMT_BOOL, get_igmp_multicast_enable, set_igmp_multicast_enable, NULL, NULL, BBFDM_BOTH}, +{"MaxGroup", &DMWRITE, DMT_UNINT, get_igmp_maxgroup, set_igmp_maxgroup, NULL, NULL, BBFDM_BOTH}, +{"MaxSources", &DMWRITE, DMT_UNINT, get_igmp_maxsources, set_igmp_maxsources, NULL, NULL, BBFDM_BOTH}, +{"MaxMembers", &DMWRITE, DMT_UNINT, get_igmp_maxmembers, set_igmp_maxmembers, NULL, NULL, BBFDM_BOTH}, +{"FastLeaveEnable", &DMWRITE, DMT_BOOL, get_igmp_fastleave_enable, set_igmp_fastleave_enable, NULL, NULL, BBFDM_BOTH}, +{"JoinImmediateEnable", &DMWRITE, DMT_BOOL, get_igmp_joinimmediate_enable, set_igmp_joinimmediate_enable, NULL, NULL, BBFDM_BOTH}, +{"ProxyEnable", &DMWRITE, DMT_BOOL, get_igmp_proxy_enable, set_igmp_proxy_enable, NULL, NULL, BBFDM_BOTH}, +{"SnoopingMode", &DMWRITE, DMT_STRING, get_igmp_snooping_mode, set_igmp_snooping_mode, NULL, NULL, BBFDM_BOTH}, +{"SnoopingInterfaces", &DMWRITE, DMT_STRING, get_igmp_snooping_interface, set_igmp_snooping_interface, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/x_iopsys_eu_igmp.h b/dmtree/tr181/x_iopsys_eu_igmp.h index aa1ce791..8da5d48b 100644 --- a/dmtree/tr181/x_iopsys_eu_igmp.h +++ b/dmtree/tr181/x_iopsys_eu_igmp.h @@ -16,37 +16,4 @@ extern DMLEAF tSe_IgmpParam[]; -int get_igmp_dscp_mark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_dscp_mark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_default_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_default_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_query_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_query_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_query_response_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_query_response_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_robustness_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_robustness_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_multicast_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_multicast_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_maxgroup(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_maxgroup(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_maxsources(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_maxsources(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_maxmembers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_maxmembers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/x_iopsys_eu_ipacccfg.c b/dmtree/tr181/x_iopsys_eu_ipacccfg.c index 435bfd31..0ed64780 100644 --- a/dmtree/tr181/x_iopsys_eu_ipacccfg.c +++ b/dmtree/tr181/x_iopsys_eu_ipacccfg.c @@ -12,6 +12,680 @@ #include "x_iopsys_eu_ipacccfg.h" + +/************************************************************************************* +**** function related to get_object_ip_acc_list_cfgobj **** +**************************************************************************************/ +static int get_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value); + if ((*value)[0] == '\0') { + *value = "1"; + } + return 0; +} + +static int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if(b) { + value = ""; + } + else { + value = "0"; + } + dmuci_set_value_by_section((struct uci_section *)data, "enabled", value); + return 0; + } + return 0; +} + +static int get_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "family", value); + return 0; +} + +static int set_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "family", value); + return 0; + } + return 0; +} + +static int get_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", value); + return 0; +} + +static int set_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "proto", value); + return 0; + } + return 0; +} + +static int get_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); + return 0; +} + +static int set_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "name", value); + return 0; + } + return 0; +} + +static int get_x_iopsys_eu_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *val; + + dmuci_get_value_by_section_list((struct uci_section *)data, "src_ip", &val); + if (val) { + *value = dmuci_list_to_string(val, ","); + } else + *value = ""; + if ((*value)[0] == '\0') { + *value = "0.0.0.0/0"; + return 0; + } + return 0; +} + +static int set_x_iopsys_eu_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *pch, *spch, *val; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_delete_by_section((struct uci_section *)data, "src_ip", ""); + val = dmstrdup(value); + pch = strtok_r(val, " ,", &spch); + while (pch != NULL) { + dmuci_add_list_value_by_section((struct uci_section *)data, "src_ip", pch); + pch = strtok_r(NULL, " ,", &spch); + } + dmfree(val); + return 0; + } + return 0; +} + +static int get_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", value); + return 0; +} + +static int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "dest_port", value); + return 0; + } + return 0; +} + +static int get_x_bcm_com_ip_acc_list_cfgobj_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "target", value); + return 0; +} + +static int set_x_bcm_com_ip_acc_list_cfgobj_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "target", value); + return 0; + } + return 0; +} + +/************************************************************************************* +**** function related to get_cache_object_port_forwarding **** +**************************************************************************************/ +static int get_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); + return 0; +} + +static int set_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "name", value); + return 0; + } + return 0; +} + +static int get_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value); + return 0; +} + +static int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if(b) + dmuci_set_value_by_section((struct uci_section *)data, "enabled", "1"); + else + dmuci_set_value_by_section((struct uci_section *)data, "enabled", "0"); + return 0; + } + return 0; +} + +static int get_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "reflection", value); + if((*value)[0] == '\0') { + *value = "1"; + } + return 0; +} + +static int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section((struct uci_section *)data, "reflection", b ? "1" : "0"); + return 0; + } + return 0; +} + +static int get_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "proto", value); + return 0; +} + +static int set_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "proto", value); + return 0; + } + return 0; +} + +static int get_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "src", value); + return 0; +} + +static int set_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "src", value); + return 0; + } + return 0; +} + +static int get_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "dest", value); + return 0; +} + +static int set_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "dest", value); + return 0; + } + return 0; +} + +static int get_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", value); + return 0; +} + +static int set_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "src_dport", value); + return 0; + } + return 0; +} + +static int get_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", value); + if ((*value)[0] == '\0') { + *value = "any"; + } + return 0; +} + +static int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcasecmp(value, "any") == 0) { + value = ""; + } + dmuci_set_value_by_section((struct uci_section *)data, "dest_port", value); + return 0; + } + return 0; +} + +static int get_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", value); + if ((*value)[0] == '\0') { + *value = "any"; + } + return 0; +} + +static int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcasecmp(value, "any") == 0) { + value = ""; + } + dmuci_set_value_by_section((struct uci_section *)data, "src_port", value); + return 0; + } + return 0; +} + +static int get_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", value); + return 0; +} + +static int set_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", value); + return 0; + } + return 0; +} + +static int get_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "src_dip", value); + if ((*value)[0] == '\0') { + *value = "any"; + } + return 0; +} + +static int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcasecmp(value, "any") == 0) { + value = ""; + } + dmuci_set_value_by_section((struct uci_section *)data, "src_dip", value); + return 0; + } + return 0; +} + +static int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *val; + + dmuci_get_value_by_section_list((struct uci_section *)data, "src_ip", &val); + if (val) { + *value = dmuci_list_to_string(val, ","); + } else { + *value = ""; + } + if ((*value)[0] == '\0') { + *value = "any"; + } + return 0; +} + +static int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *pch, *val, *spch; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcasecmp(value, "any") == 0) { + dmuci_delete_by_section((struct uci_section *)data, "src_ip", ""); + } else { + dmuci_delete_by_section((struct uci_section *)data, "src_ip", ""); + val = dmstrdup(value); + pch = strtok_r(val, " ,", &spch); + while (pch != NULL) { + dmuci_add_list_value_by_section((struct uci_section *)data, "src_ip", pch); + pch = strtok_r(NULL, " ,", &spch); + } + dmfree(val); + } + return 0; + } + return 0; +} + +static int get_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_list *list = NULL; + + dmuci_get_value_by_section_list((struct uci_section *)data, "src_mac", &list); + *value = dmuci_list_to_string(list, " "); + return 0; +} + +static int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *pch, *spch; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_delete_by_section((struct uci_section *)data, "src_mac", NULL); + value = dmstrdup(value); + pch = strtok_r(value, " ", &spch); + while (pch != NULL) { + dmuci_add_list_value_by_section((struct uci_section *)data, "src_mac", pch); + pch = strtok_r(NULL, " ", &spch); + } + dmfree(value); + return 0; + } + return 0; +} + +/***** ADD DEL OBJ *******/ +static int add_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + char *value, *v, *instance; + struct uci_section *rule = NULL, *dmmap_rule = NULL; + + check_create_dmmap_package("dmmap_firewall"); + instance = get_last_instance_bbfdm("dmmap_firewall", "rule", "fruleinstance"); + dmuci_add_section_and_rename("firewall", "rule", &rule, &value); + dmuci_set_value_by_section(rule, "type", "generic"); + dmuci_set_value_by_section(rule, "name", "new_rule"); + dmuci_set_value_by_section(rule, "proto", "all"); + dmuci_set_value_by_section(rule, "target", "ACCPET"); + dmuci_set_value_by_section(rule, "family", "ipv4"); + dmuci_set_value_by_section(rule, "enabled", "1"); + dmuci_set_value_by_section(rule, "hidden", "1"); + dmuci_set_value_by_section(rule, "parental", "0"); + + dmuci_add_section_bbfdm("dmmap_firewall", "rule", &dmmap_rule, &v); + dmuci_set_value_by_section(dmmap_rule, "section_name", section_name(rule)); + *instancepara = update_instance_bbfdm(dmmap_rule, instance, "fruleinstance"); + return 0; +} + +static int delete_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; + int found = 0; + + switch (del_action) { + case DEL_INST: + get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("firewall", "rule", s) { + if (found != 0) { + get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(s), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ss), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + break; + } + + return 0; +} + +static int add_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + char *value, *v, *instance; + struct uci_section *redirect = NULL, *dmmap_redirect = NULL; + + check_create_dmmap_package("dmmap_firewall"); + instance = get_last_instance_bbfdm("dmmap_firewall", "redirect", "forwardinstance"); + dmuci_add_section_and_rename("firewall", "redirect", &redirect, &value); + dmuci_set_value_by_section(redirect, "enabled", "0"); + dmuci_set_value_by_section(redirect, "target", "DNAT"); + dmuci_set_value_by_section(redirect, "proto", "tcp udp"); + + dmuci_add_section_bbfdm("dmmap_firewall", "redirect", &dmmap_redirect, &v); + dmuci_set_value_by_section(dmmap_redirect, "section_name", section_name(redirect)); + *instancepara = update_instance_bbfdm(dmmap_redirect, instance, "forwardinstance"); + return 0; +} + + +static int delete_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct uci_section *forwardsection = (struct uci_section *)data, *s = NULL, *ss = NULL, *dmmap_section = NULL; + + switch (del_action) { + case DEL_INST: + get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(forwardsection), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(forwardsection, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_option_eq("firewall", "redirect", "target", "DNAT", s) { + if (found != 0) { + get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(s), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(ss), &dmmap_section); + if (dmmap_section) + dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + break; + } + return 0; +} + +////////////////////////SET AND GET ALIAS///////////////////////////////// +static int get_x_iopsys_eu_cfgobj_address_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *ipaccsection = (struct uci_section *)data; + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ipaccsection), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "frulealias", value); + return 0; +} + +static int set_x_iopsys_eu_cfgobj_address_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *ipaccsection = (struct uci_section *)data; + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ipaccsection), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "frulealias", value); + return 0; + } + return 0; +} + +static int get_port_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *forwardsection = (struct uci_section *)data; + struct uci_section *dmmap_section = NULL; + + get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(forwardsection), &dmmap_section); + if (dmmap_section) + dmuci_get_value_by_section_string(dmmap_section, "forwardalias", value); + return 0; +} + +static int set_port_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *forwardsection = (struct uci_section *)data; + struct uci_section *dmmap_section = NULL; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(forwardsection), &dmmap_section); + if (dmmap_section) + dmuci_set_value_by_section(dmmap_section, "forwardalias", value); + return 0; + } + return 0; +} + +static int browseAccListInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *irule = NULL, *irule_last = NULL; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("firewall", "rule", "dmmap_firewall", &dup_list); + list_for_each_entry(p, &dup_list, list) { + irule = handle_update_instance(1, dmctx, &irule_last, update_instance_alias_bbfdm, 3, p->dmmap_section, "fruleinstance", "frulealias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, irule) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +static int browseport_forwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *iforward = NULL, *iforward_last = NULL; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap_eq("firewall", "redirect", "dmmap_firewall", "target", "DNAT", &dup_list); + list_for_each_entry(p, &dup_list, list) { + iforward = handle_update_instance(1, dmctx, &iforward_last, update_instance_alias, 3, p->dmmap_section, "forwardinstance", "forwardalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, iforward) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + /*** DMROOT.X_IOPSYS_EU_IpAccCfg. ***/ DMOBJ tSe_IpAccObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -51,677 +725,3 @@ DMLEAF tSe_IpAccCfgParam[] = { {"Target", &DMWRITE, DMT_STRING, get_x_bcm_com_ip_acc_list_cfgobj_target, set_x_bcm_com_ip_acc_list_cfgobj_target, NULL, NULL, BBFDM_BOTH}, {0} }; - -/************************************************************************************* -**** function related to get_object_ip_acc_list_cfgobj **** -**************************************************************************************/ -int get_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value); - if ((*value)[0] == '\0') { - *value = "1"; - } - return 0; -} - -int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - if(b) { - value = ""; - } - else { - value = "0"; - } - dmuci_set_value_by_section((struct uci_section *)data, "enabled", value); - return 0; - } - return 0; -} - -int get_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "family", value); - return 0; -} - -int set_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "family", value); - return 0; - } - return 0; -} - -int get_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "proto", value); - return 0; -} - -int set_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "proto", value); - return 0; - } - return 0; -} - -int get_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); - return 0; -} - -int set_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "name", value); - return 0; - } - return 0; -} - -int get_x_iopsys_eu_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *val; - - dmuci_get_value_by_section_list((struct uci_section *)data, "src_ip", &val); - if (val) { - *value = dmuci_list_to_string(val, ","); - } else - *value = ""; - if ((*value)[0] == '\0') { - *value = "0.0.0.0/0"; - return 0; - } - return 0; -} - -int set_x_iopsys_eu_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *pch, *spch, *val; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_delete_by_section((struct uci_section *)data, "src_ip", ""); - val = dmstrdup(value); - pch = strtok_r(val, " ,", &spch); - while (pch != NULL) { - dmuci_add_list_value_by_section((struct uci_section *)data, "src_ip", pch); - pch = strtok_r(NULL, " ,", &spch); - } - dmfree(val); - return 0; - } - return 0; -} - -int get_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", value); - return 0; -} - -int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "dest_port", value); - return 0; - } - return 0; -} - -int get_x_bcm_com_ip_acc_list_cfgobj_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "target", value); - return 0; -} - -int set_x_bcm_com_ip_acc_list_cfgobj_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "target", value); - return 0; - } - return 0; -} - -/************************************************************************************* -**** function related to get_cache_object_port_forwarding **** -**************************************************************************************/ -int get_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "name", value); - return 0; -} - -int set_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "name", value); - return 0; - } - return 0; -} - -int get_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value); - return 0; -} - -int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - if(b) - dmuci_set_value_by_section((struct uci_section *)data, "enabled", "1"); - else - dmuci_set_value_by_section((struct uci_section *)data, "enabled", "0"); - return 0; - } - return 0; -} - -int get_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "reflection", value); - if((*value)[0] == '\0') { - *value = "1"; - } - return 0; -} - -int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "reflection", b ? "1" : "0"); - return 0; - } - return 0; -} - -int get_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "proto", value); - return 0; -} - -int set_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "proto", value); - return 0; - } - return 0; -} - -int get_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "src", value); - return 0; -} - -int set_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "src", value); - return 0; - } - return 0; -} - -int get_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "dest", value); - return 0; -} - -int set_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "dest", value); - return 0; - } - return 0; -} - -int get_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", value); - return 0; -} - -int set_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "src_dport", value); - return 0; - } - return 0; -} - -int get_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", value); - if ((*value)[0] == '\0') { - *value = "any"; - } - return 0; -} - -int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - if (strcasecmp(value, "any") == 0) { - value = ""; - } - dmuci_set_value_by_section((struct uci_section *)data, "dest_port", value); - return 0; - } - return 0; -} - -int get_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", value); - if ((*value)[0] == '\0') { - *value = "any"; - } - return 0; -} - -int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - if (strcasecmp(value, "any") == 0) { - value = ""; - } - dmuci_set_value_by_section((struct uci_section *)data, "src_port", value); - return 0; - } - return 0; -} - -int get_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", value); - return 0; -} - -int set_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", value); - return 0; - } - return 0; -} - -int get_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "src_dip", value); - if ((*value)[0] == '\0') { - *value = "any"; - } - return 0; -} - -int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - if (strcasecmp(value, "any") == 0) { - value = ""; - } - dmuci_set_value_by_section((struct uci_section *)data, "src_dip", value); - return 0; - } - return 0; -} - -int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *val; - - dmuci_get_value_by_section_list((struct uci_section *)data, "src_ip", &val); - if (val) { - *value = dmuci_list_to_string(val, ","); - } else { - *value = ""; - } - if ((*value)[0] == '\0') { - *value = "any"; - } - return 0; -} - -int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *pch, *val, *spch; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - if (strcasecmp(value, "any") == 0) { - dmuci_delete_by_section((struct uci_section *)data, "src_ip", ""); - } else { - dmuci_delete_by_section((struct uci_section *)data, "src_ip", ""); - val = dmstrdup(value); - pch = strtok_r(val, " ,", &spch); - while (pch != NULL) { - dmuci_add_list_value_by_section((struct uci_section *)data, "src_ip", pch); - pch = strtok_r(NULL, " ,", &spch); - } - dmfree(val); - } - return 0; - } - return 0; -} - -int get_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_list *list = NULL; - - dmuci_get_value_by_section_list((struct uci_section *)data, "src_mac", &list); - *value = dmuci_list_to_string(list, " "); - return 0; -} - -int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char *pch, *spch; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_delete_by_section((struct uci_section *)data, "src_mac", NULL); - value = dmstrdup(value); - pch = strtok_r(value, " ", &spch); - while (pch != NULL) { - dmuci_add_list_value_by_section((struct uci_section *)data, "src_mac", pch); - pch = strtok_r(NULL, " ", &spch); - } - dmfree(value); - return 0; - } - return 0; -} - -/***** ADD DEL OBJ *******/ -int add_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - char *value, *v, *instance; - struct uci_section *rule = NULL, *dmmap_rule = NULL; - - check_create_dmmap_package("dmmap_firewall"); - instance = get_last_instance_bbfdm("dmmap_firewall", "rule", "fruleinstance"); - dmuci_add_section_and_rename("firewall", "rule", &rule, &value); - dmuci_set_value_by_section(rule, "type", "generic"); - dmuci_set_value_by_section(rule, "name", "new_rule"); - dmuci_set_value_by_section(rule, "proto", "all"); - dmuci_set_value_by_section(rule, "target", "ACCPET"); - dmuci_set_value_by_section(rule, "family", "ipv4"); - dmuci_set_value_by_section(rule, "enabled", "1"); - dmuci_set_value_by_section(rule, "hidden", "1"); - dmuci_set_value_by_section(rule, "parental", "0"); - - dmuci_add_section_bbfdm("dmmap_firewall", "rule", &dmmap_rule, &v); - dmuci_set_value_by_section(dmmap_rule, "section_name", section_name(rule)); - *instancepara = update_instance_bbfdm(dmmap_rule, instance, "fruleinstance"); - return 0; -} - -int delete_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; - int found = 0; - - switch (del_action) { - case DEL_INST: - get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); - break; - case DEL_ALL: - uci_foreach_sections("firewall", "rule", s) { - if (found != 0) { - get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(s), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ss), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - break; - } - - return 0; -} - -int add_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - char *value, *v, *instance; - struct uci_section *redirect = NULL, *dmmap_redirect = NULL; - - check_create_dmmap_package("dmmap_firewall"); - instance = get_last_instance_bbfdm("dmmap_firewall", "redirect", "forwardinstance"); - dmuci_add_section_and_rename("firewall", "redirect", &redirect, &value); - dmuci_set_value_by_section(redirect, "enabled", "0"); - dmuci_set_value_by_section(redirect, "target", "DNAT"); - dmuci_set_value_by_section(redirect, "proto", "tcp udp"); - - dmuci_add_section_bbfdm("dmmap_firewall", "redirect", &dmmap_redirect, &v); - dmuci_set_value_by_section(dmmap_redirect, "section_name", section_name(redirect)); - *instancepara = update_instance_bbfdm(dmmap_redirect, instance, "forwardinstance"); - return 0; -} - - -int delete_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - int found = 0; - struct uci_section *forwardsection = (struct uci_section *)data, *s = NULL, *ss = NULL, *dmmap_section = NULL; - - switch (del_action) { - case DEL_INST: - get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(forwardsection), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(forwardsection, NULL, NULL); - break; - case DEL_ALL: - uci_foreach_option_eq("firewall", "redirect", "target", "DNAT", s) { - if (found != 0) { - get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(s), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(ss), &dmmap_section); - if (dmmap_section) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - break; - } - return 0; -} - -////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_x_iopsys_eu_cfgobj_address_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *ipaccsection = (struct uci_section *)data; - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ipaccsection), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "frulealias", value); - return 0; -} - -int set_x_iopsys_eu_cfgobj_address_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *ipaccsection = (struct uci_section *)data; - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ipaccsection), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "frulealias", value); - return 0; - } - return 0; -} - -int get_port_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *forwardsection = (struct uci_section *)data; - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(forwardsection), &dmmap_section); - if (dmmap_section) - dmuci_get_value_by_section_string(dmmap_section, "forwardalias", value); - return 0; -} - -int set_port_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - struct uci_section *forwardsection = (struct uci_section *)data; - struct uci_section *dmmap_section = NULL; - - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(forwardsection), &dmmap_section); - if (dmmap_section) - dmuci_set_value_by_section(dmmap_section, "forwardalias", value); - return 0; - } - return 0; -} - -int browseAccListInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *irule = NULL, *irule_last = NULL; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("firewall", "rule", "dmmap_firewall", &dup_list); - list_for_each_entry(p, &dup_list, list) { - irule = handle_update_instance(1, dmctx, &irule_last, update_instance_alias_bbfdm, 3, p->dmmap_section, "fruleinstance", "frulealias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, irule) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -int browseport_forwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *iforward = NULL, *iforward_last = NULL; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap_eq("firewall", "redirect", "dmmap_firewall", "target", "DNAT", &dup_list); - list_for_each_entry(p, &dup_list, list) { - iforward = handle_update_instance(1, dmctx, &iforward_last, update_instance_alias, 3, p->dmmap_section, "forwardinstance", "forwardalias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, iforward) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - diff --git a/dmtree/tr181/x_iopsys_eu_ipacccfg.h b/dmtree/tr181/x_iopsys_eu_ipacccfg.h index ffa07c33..bf1b9a34 100644 --- a/dmtree/tr181/x_iopsys_eu_ipacccfg.h +++ b/dmtree/tr181/x_iopsys_eu_ipacccfg.h @@ -19,60 +19,4 @@ extern DMOBJ tSe_IpAccObj[]; extern DMLEAF tSe_IpAccCfgParam[]; extern DMLEAF tSe_PortForwardingParam[]; - -int browseport_forwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browseAccListInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int add_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int add_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_port_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_x_iopsys_eu_cfgobj_address_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_x_iopsys_eu_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_x_bcm_com_ip_acc_list_cfgobj_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_port_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_x_iopsys_eu_cfgobj_address_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_x_iopsys_eu_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_x_bcm_com_ip_acc_list_cfgobj_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/x_iopsys_eu_logincfg.c b/dmtree/tr181/x_iopsys_eu_logincfg.c index a87e1d6c..1f7389e8 100644 --- a/dmtree/tr181/x_iopsys_eu_logincfg.c +++ b/dmtree/tr181/x_iopsys_eu_logincfg.c @@ -11,17 +11,8 @@ #include "x_iopsys_eu_logincfg.h" -/*** DMROOT.X_IOPSYS_EU_LoginCfg. ***/ -DMLEAF tSe_LoginCfgParam[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"AdminPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_admin_password, NULL, NULL, BBFDM_BOTH}, -{"SupportPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_support_password, NULL, NULL, BBFDM_BOTH}, -{"UserPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_user_password, NULL, NULL, BBFDM_BOTH}, -{"RootPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_root_password, NULL, NULL, BBFDM_BOTH}, -{0} -}; -int set_x_bcm_password(char *refparam, struct dmctx *ctx, int action, char *value, char *user_type) +static int set_x_bcm_password(char *refparam, struct dmctx *ctx, int action, char *value, char *user_type) { switch (action) { case VALUECHECK: @@ -33,26 +24,36 @@ int set_x_bcm_password(char *refparam, struct dmctx *ctx, int action, char *valu return 0; } -int set_x_bcm_admin_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_bcm_admin_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { set_x_bcm_password(refparam, ctx, action, value, "admin"); return 0; } -int set_x_bcm_support_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_bcm_support_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { set_x_bcm_password(refparam, ctx, action, value, "support"); return 0; } -int set_x_bcm_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_bcm_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { set_x_bcm_password(refparam, ctx, action, value, "user"); return 0; } -int set_x_bcm_root_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_bcm_root_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { set_x_bcm_password(refparam, ctx, action, value, "root"); return 0; } + +/*** DMROOT.X_IOPSYS_EU_LoginCfg. ***/ +DMLEAF tSe_LoginCfgParam[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"AdminPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_admin_password, NULL, NULL, BBFDM_BOTH}, +{"SupportPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_support_password, NULL, NULL, BBFDM_BOTH}, +{"UserPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_user_password, NULL, NULL, BBFDM_BOTH}, +{"RootPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_root_password, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/x_iopsys_eu_logincfg.h b/dmtree/tr181/x_iopsys_eu_logincfg.h index 80f46739..b6467550 100644 --- a/dmtree/tr181/x_iopsys_eu_logincfg.h +++ b/dmtree/tr181/x_iopsys_eu_logincfg.h @@ -16,9 +16,4 @@ extern DMLEAF tSe_LoginCfgParam[]; -int set_x_bcm_admin_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_x_bcm_support_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_x_bcm_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_x_bcm_root_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/x_iopsys_eu_owsd.c b/dmtree/tr181/x_iopsys_eu_owsd.c index c99b34cc..4a73def3 100644 --- a/dmtree/tr181/x_iopsys_eu_owsd.c +++ b/dmtree/tr181/x_iopsys_eu_owsd.c @@ -13,46 +13,7 @@ #include "dmentry.h" #include "x_iopsys_eu_owsd.h" -/*** DMROOT.X_IOPSYS_EU_Owsd. ***/ -DMLEAF XIopsysEuOwsdParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Socket", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_global_sock, set_x_iopsys_eu_owsd_global_sock, NULL, NULL, BBFDM_BOTH}, -{"Redirect", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_global_redirect, set_x_iopsys_eu_owsd_global_redirect, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -DMOBJ XIopsysEuOwsdObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{CUSTOM_PREFIX"UbusProxy", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, UbusProxyParams, NULL, BBFDM_BOTH}, -{CUSTOM_PREFIX"ListenObj", &DMWRITE, add_owsd_listen, delete_owsd_listen_instance, NULL, browseXIopsysEuOwsdListenObj, NULL, NULL, NULL, NULL, X_IOPSYS_EU_ListenObjParams, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF UbusProxyParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Enable", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_owsd_ubus_proxy_enable, set_x_iopsys_eu_owsd_ubus_proxy_enable, NULL, NULL, BBFDM_BOTH}, -{"UbusProxyCert", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_proxy_cert, set_x_iopsys_eu_owsd_ubus_proxy_cert, NULL, NULL, BBFDM_BOTH}, -{"UbusProxyKey", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_proxy_key, set_x_iopsys_eu_owsd_ubus_proxy_key, NULL, NULL, BBFDM_BOTH}, -{"UbusProxyCa", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_proxy_ca, set_x_iopsys_eu_owsd_ubus_proxy_ca, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -DMLEAF X_IOPSYS_EU_ListenObjParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"Alias", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_listenobj_alias, set_x_iopsys_eu_owsd_listenobj_alias, NULL, NULL, BBFDM_BOTH}, -{"Port", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_owsd_listenobj_port, set_x_iopsys_eu_owsd_listenobj_port, NULL, NULL, BBFDM_BOTH}, -{"Interface", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_listenobj_interface, set_x_iopsys_eu_owsd_listenobj_interface, NULL, NULL, BBFDM_BOTH}, -{"Ipv6", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_owsd_listenobj_ipv6_enable, set_x_iopsys_eu_owsd_listenobj_ipv6_enable, NULL, NULL, BBFDM_BOTH}, -{"Whitelist_interface", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_owsd_listenobj_whitelist_interface, set_x_iopsys_eu_owsd_listenobj_whitelist_interface, NULL, NULL, BBFDM_BOTH}, -{"Whitelist_dhcp", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_owsd_listenobj_whitelist_dhcp, set_x_iopsys_eu_owsd_listenobj_whitelist_dhcp, NULL, NULL, BBFDM_BOTH}, -{"Origin", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_listenobj_origin, set_x_iopsys_eu_owsd_listenobj_origin, NULL, NULL, BBFDM_BOTH}, -{"UbusCert", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_cert, set_x_iopsys_eu_owsd_ubus_cert, NULL, NULL, BBFDM_BOTH}, -{"UbusKey", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_key, set_x_iopsys_eu_owsd_ubus_key, NULL, NULL, BBFDM_BOTH}, -{"UbusCa", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_ca, set_x_iopsys_eu_owsd_ubus_ca, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -int browseXIopsysEuOwsdListenObj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +static int browseXIopsysEuOwsdListenObj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *iowsd_listen = NULL, *iowsd_listen_last = NULL; struct dmmap_dup *p; @@ -71,13 +32,13 @@ int browseXIopsysEuOwsdListenObj(struct dmctx *dmctx, DMNODE *parent_node, void /************************************************************************************* **** function related to owsd_origin **** **************************************************************************************/ -int get_x_iopsys_eu_owsd_global_sock(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_global_sock(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("owsd", "global", "sock", value); return 0; } -int set_x_iopsys_eu_owsd_global_sock(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_global_sock(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -89,13 +50,13 @@ int set_x_iopsys_eu_owsd_global_sock(char *refparam, struct dmctx *ctx, void *da return 0; } -int get_x_iopsys_eu_owsd_global_redirect(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_global_redirect(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("owsd", "global", "redirect", value); return 0; } -int set_x_iopsys_eu_owsd_global_redirect(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_global_redirect(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -110,7 +71,7 @@ int set_x_iopsys_eu_owsd_global_redirect(char *refparam, struct dmctx *ctx, void /************************************************************************************* **** function related to owsd_listenobj **** **************************************************************************************/ -int get_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "port", value); if ((*value)[0] == '\0') { @@ -119,7 +80,7 @@ int get_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void return 0; } -int set_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -131,7 +92,7 @@ int set_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void return 0; } -int get_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *iface; @@ -144,7 +105,7 @@ int get_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, return 0; } -int set_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker; @@ -162,7 +123,7 @@ int set_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, return 0; } -int get_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "ipv6", value); if ((*value)[0] != '\0' && (*value)[0] == 'o' && (*value)[1] == 'n' ) { @@ -173,7 +134,7 @@ int get_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx return 0; } -int set_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -190,7 +151,7 @@ int set_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx return 0; } -int get_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "whitelist_interface_as_origin", value); if ((*value)[0] == '\0' ) { @@ -199,7 +160,7 @@ int get_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dm return 0; } -int set_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -216,7 +177,7 @@ int set_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dm return 0; } -int get_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "whitelist_dhcp_domains", value); if ((*value)[0] == '\0') { @@ -225,7 +186,7 @@ int get_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx * return 0; } -int set_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -242,7 +203,7 @@ int set_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx * return 0; } -int get_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_list *val; @@ -254,7 +215,7 @@ int get_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, voi return 0; } -int set_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch, *spch; @@ -276,7 +237,7 @@ int set_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, voi } ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_x_iopsys_eu_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *dmmap_section = NULL; @@ -286,7 +247,7 @@ int get_x_iopsys_eu_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void return 0; } -int set_x_iopsys_eu_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *dmmap_section = NULL; @@ -302,13 +263,13 @@ int set_x_iopsys_eu_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void return 0; } -int get_x_iopsys_eu_owsd_ubus_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_ubus_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("owsd","ubusproxy","enable", value); return 0; } -int set_x_iopsys_eu_owsd_ubus_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_ubus_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -320,13 +281,13 @@ int set_x_iopsys_eu_owsd_ubus_proxy_enable(char *refparam, struct dmctx *ctx, vo return 0; } -int get_x_iopsys_eu_owsd_ubus_proxy_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_ubus_proxy_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("owsd","ubusproxy","peer_cert", value); return 0; } -int set_x_iopsys_eu_owsd_ubus_proxy_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_ubus_proxy_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -338,13 +299,13 @@ int set_x_iopsys_eu_owsd_ubus_proxy_cert(char *refparam, struct dmctx *ctx, void return 0; } -int get_x_iopsys_eu_owsd_ubus_proxy_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_ubus_proxy_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("owsd","ubusproxy","peer_key", value); return 0; } -int set_x_iopsys_eu_owsd_ubus_proxy_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_ubus_proxy_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -356,13 +317,13 @@ int set_x_iopsys_eu_owsd_ubus_proxy_key(char *refparam, struct dmctx *ctx, void return 0; } -int get_x_iopsys_eu_owsd_ubus_proxy_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_ubus_proxy_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("owsd","ubusproxy","peer_ca", value); return 0; } -int set_x_iopsys_eu_owsd_ubus_proxy_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_ubus_proxy_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -374,7 +335,7 @@ int set_x_iopsys_eu_owsd_ubus_proxy_ca(char *refparam, struct dmctx *ctx, void * return 0; } -int get_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *net_cur_mode = NULL; dmuci_get_option_value_string("netmode", "setup", "curmode", &net_cur_mode); @@ -385,7 +346,7 @@ int get_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data return 0; } -int set_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *net_cur_mode = NULL; @@ -403,7 +364,7 @@ int set_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data return 0; } -int get_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *net_cur_mode= NULL; @@ -414,7 +375,7 @@ int get_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data, return 0; } -int set_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *net_cur_mode = NULL; @@ -432,7 +393,7 @@ int set_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data, return 0; } -int get_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *net_cur_mode = NULL; @@ -443,7 +404,7 @@ int get_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data, return 0; } -int set_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *net_cur_mode = NULL; @@ -462,7 +423,7 @@ int set_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data, } /***** ADD DEL OBJ *******/ -int add_owsd_listen(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +static int add_owsd_listen(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *value, *v, *instance; struct uci_section *listen_sec = NULL, *dmmap_sec = NULL; @@ -482,7 +443,7 @@ int add_owsd_listen(char *refparam, struct dmctx *ctx, void *data, char **instan return 0; } -int delete_owsd_listen_instance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +static int delete_owsd_listen_instance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; @@ -522,3 +483,42 @@ int delete_owsd_listen_instance(char *refparam, struct dmctx *ctx, void *data, c } return 0; } + +/*** DMROOT.X_IOPSYS_EU_Owsd. ***/ +DMLEAF XIopsysEuOwsdParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Socket", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_global_sock, set_x_iopsys_eu_owsd_global_sock, NULL, NULL, BBFDM_BOTH}, +{"Redirect", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_global_redirect, set_x_iopsys_eu_owsd_global_redirect, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +DMOBJ XIopsysEuOwsdObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{CUSTOM_PREFIX"UbusProxy", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, UbusProxyParams, NULL, BBFDM_BOTH}, +{CUSTOM_PREFIX"ListenObj", &DMWRITE, add_owsd_listen, delete_owsd_listen_instance, NULL, browseXIopsysEuOwsdListenObj, NULL, NULL, NULL, NULL, X_IOPSYS_EU_ListenObjParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF UbusProxyParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_owsd_ubus_proxy_enable, set_x_iopsys_eu_owsd_ubus_proxy_enable, NULL, NULL, BBFDM_BOTH}, +{"UbusProxyCert", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_proxy_cert, set_x_iopsys_eu_owsd_ubus_proxy_cert, NULL, NULL, BBFDM_BOTH}, +{"UbusProxyKey", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_proxy_key, set_x_iopsys_eu_owsd_ubus_proxy_key, NULL, NULL, BBFDM_BOTH}, +{"UbusProxyCa", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_proxy_ca, set_x_iopsys_eu_owsd_ubus_proxy_ca, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF X_IOPSYS_EU_ListenObjParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Alias", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_listenobj_alias, set_x_iopsys_eu_owsd_listenobj_alias, NULL, NULL, BBFDM_BOTH}, +{"Port", &DMWRITE, DMT_UNINT, get_x_iopsys_eu_owsd_listenobj_port, set_x_iopsys_eu_owsd_listenobj_port, NULL, NULL, BBFDM_BOTH}, +{"Interface", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_listenobj_interface, set_x_iopsys_eu_owsd_listenobj_interface, NULL, NULL, BBFDM_BOTH}, +{"Ipv6", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_owsd_listenobj_ipv6_enable, set_x_iopsys_eu_owsd_listenobj_ipv6_enable, NULL, NULL, BBFDM_BOTH}, +{"Whitelist_interface", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_owsd_listenobj_whitelist_interface, set_x_iopsys_eu_owsd_listenobj_whitelist_interface, NULL, NULL, BBFDM_BOTH}, +{"Whitelist_dhcp", &DMWRITE, DMT_BOOL, get_x_iopsys_eu_owsd_listenobj_whitelist_dhcp, set_x_iopsys_eu_owsd_listenobj_whitelist_dhcp, NULL, NULL, BBFDM_BOTH}, +{"Origin", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_listenobj_origin, set_x_iopsys_eu_owsd_listenobj_origin, NULL, NULL, BBFDM_BOTH}, +{"UbusCert", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_cert, set_x_iopsys_eu_owsd_ubus_cert, NULL, NULL, BBFDM_BOTH}, +{"UbusKey", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_key, set_x_iopsys_eu_owsd_ubus_key, NULL, NULL, BBFDM_BOTH}, +{"UbusCa", &DMWRITE, DMT_STRING, get_x_iopsys_eu_owsd_ubus_ca, set_x_iopsys_eu_owsd_ubus_ca, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/x_iopsys_eu_owsd.h b/dmtree/tr181/x_iopsys_eu_owsd.h index b6f8eb2a..5aaff00a 100644 --- a/dmtree/tr181/x_iopsys_eu_owsd.h +++ b/dmtree/tr181/x_iopsys_eu_owsd.h @@ -20,43 +20,4 @@ extern DMOBJ XIopsysEuOwsdObj[]; extern DMLEAF X_IOPSYS_EU_ListenObjParams[]; extern DMLEAF UbusProxyParams[]; -int browseXIopsysEuOwsdListenObj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int add_owsd_listen(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_owsd_listen_instance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - - -int get_x_iopsys_eu_owsd_global_sock(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_global_sock(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_global_redirect(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_global_redirect(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_ubus_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_ubus_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_ubus_proxy_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_ubus_proxy_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_ubus_proxy_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_ubus_proxy_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_ubus_proxy_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_ubus_proxy_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/x_iopsys_eu_power_mgmt.c b/dmtree/tr181/x_iopsys_eu_power_mgmt.c index 299f867e..4d88d049 100644 --- a/dmtree/tr181/x_iopsys_eu_power_mgmt.c +++ b/dmtree/tr181/x_iopsys_eu_power_mgmt.c @@ -13,29 +13,20 @@ #include "x_iopsys_eu_power_mgmt.h" -/*** DMROOT.X_IOPSYS_EU_PowerManagement. ***/ -DMLEAF tSe_PowerManagementParam[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"EthernetAutoPowerDownEnable", &DMWRITE, DMT_BOOL, get_pwr_mgmt_value_ethapd, set_power_mgmt_param_ethapd, NULL, NULL, BBFDM_BOTH}, -{"EnergyEfficientEthernetEnable", &DMWRITE, DMT_BOOL, get_pwr_mgmt_value_eee, set_power_mgmt_param_eee, NULL, NULL, BBFDM_BOTH}, -{"NumberOfEthernetInterfacesPoweredUp", &DMREAD, DMT_UNINT, get_pwr_nbr_interfaces_up, NULL, NULL, NULL, BBFDM_BOTH}, -{"NumberOfEthernetInterfacesPoweredDown", &DMREAD, DMT_UNINT, get_pwr_nbr_interfaces_down, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; -int get_pwr_mgmt_value_ethapd(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_pwr_mgmt_value_ethapd(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("power_mgmt", "power_mgmt", "ethapd", value); return 0; } -int get_pwr_mgmt_value_eee(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_pwr_mgmt_value_eee(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("power_mgmt", "power_mgmt", "eee", value); return 0; } -int get_pwr_nbr_interfaces_up(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_pwr_nbr_interfaces_up(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char buf[256]; int pp; @@ -50,7 +41,7 @@ int get_pwr_nbr_interfaces_up(char *refparam, struct dmctx *ctx, void *data, cha return 0; } -int get_pwr_nbr_interfaces_down(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_pwr_nbr_interfaces_down(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char buf[256]; int pp; @@ -65,7 +56,7 @@ int get_pwr_nbr_interfaces_down(char *refparam, struct dmctx *ctx, void *data, c return 0; } -int set_power_mgmt_param_ethapd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_power_mgmt_param_ethapd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -82,7 +73,7 @@ int set_power_mgmt_param_ethapd(char *refparam, struct dmctx *ctx, void *data, c return 0; } -int set_power_mgmt_param_eee(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_power_mgmt_param_eee(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -98,3 +89,13 @@ int set_power_mgmt_param_eee(char *refparam, struct dmctx *ctx, void *data, char } return 0; } + +/*** DMROOT.X_IOPSYS_EU_PowerManagement. ***/ +DMLEAF tSe_PowerManagementParam[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"EthernetAutoPowerDownEnable", &DMWRITE, DMT_BOOL, get_pwr_mgmt_value_ethapd, set_power_mgmt_param_ethapd, NULL, NULL, BBFDM_BOTH}, +{"EnergyEfficientEthernetEnable", &DMWRITE, DMT_BOOL, get_pwr_mgmt_value_eee, set_power_mgmt_param_eee, NULL, NULL, BBFDM_BOTH}, +{"NumberOfEthernetInterfacesPoweredUp", &DMREAD, DMT_UNINT, get_pwr_nbr_interfaces_up, NULL, NULL, NULL, BBFDM_BOTH}, +{"NumberOfEthernetInterfacesPoweredDown", &DMREAD, DMT_UNINT, get_pwr_nbr_interfaces_down, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/x_iopsys_eu_power_mgmt.h b/dmtree/tr181/x_iopsys_eu_power_mgmt.h index cd1bc25c..b74f4307 100644 --- a/dmtree/tr181/x_iopsys_eu_power_mgmt.h +++ b/dmtree/tr181/x_iopsys_eu_power_mgmt.h @@ -16,11 +16,4 @@ extern DMLEAF tSe_PowerManagementParam[]; -int get_pwr_mgmt_value_ethapd(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_pwr_mgmt_value_eee(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_pwr_nbr_interfaces_up(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_pwr_nbr_interfaces_down(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_power_mgmt_param_ethapd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_power_mgmt_param_eee(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); #endif diff --git a/dmtree/tr181/x_iopsys_eu_syslog.c b/dmtree/tr181/x_iopsys_eu_syslog.c index 069c724a..0961639c 100644 --- a/dmtree/tr181/x_iopsys_eu_syslog.c +++ b/dmtree/tr181/x_iopsys_eu_syslog.c @@ -11,22 +11,14 @@ #include "x_iopsys_eu_syslog.h" -/*** DMROOT.X_IOPSYS_EU_SyslogCfg. ***/ -DMLEAF tSe_SyslogCfgParam[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"ServerIPAddress", &DMWRITE, DMT_STRING, get_server_ip_address, set_server_ip_address, NULL, NULL, BBFDM_BOTH}, -{"ServerPortNumber", &DMWRITE, DMT_UNINT, get_server_port_number, set_server_port_number, NULL, NULL, BBFDM_BOTH}, -{"RemoteLogLevel", &DMWRITE, DMT_UNINT, get_remote_log_level, set_remote_log_level, NULL, NULL, BBFDM_BOTH}, -{0} -}; -int get_server_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_server_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("system", "@system[0]", "log_ip", value); return 0; } -int set_server_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_server_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -38,7 +30,7 @@ int set_server_ip_address(char *refparam, struct dmctx *ctx, void *data, char *i return 0; } -int get_server_port_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_server_port_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; dmuci_get_option_value_string("system", "@system[0]", "log_port", &tmp); @@ -49,7 +41,7 @@ int get_server_port_number(char *refparam, struct dmctx *ctx, void *data, char * return 0; } -int set_server_port_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_server_port_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -61,7 +53,7 @@ int set_server_port_number(char *refparam, struct dmctx *ctx, void *data, char * return 0; } -int get_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +static int get_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; dmuci_get_option_value_string("system", "@system[0]", "conloglevel", &tmp); @@ -72,7 +64,7 @@ int get_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *in return 0; } -int set_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -83,3 +75,12 @@ int set_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *in } return 0; } + +/*** DMROOT.X_IOPSYS_EU_SyslogCfg. ***/ +DMLEAF tSe_SyslogCfgParam[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"ServerIPAddress", &DMWRITE, DMT_STRING, get_server_ip_address, set_server_ip_address, NULL, NULL, BBFDM_BOTH}, +{"ServerPortNumber", &DMWRITE, DMT_UNINT, get_server_port_number, set_server_port_number, NULL, NULL, BBFDM_BOTH}, +{"RemoteLogLevel", &DMWRITE, DMT_UNINT, get_remote_log_level, set_remote_log_level, NULL, NULL, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/tr181/x_iopsys_eu_syslog.h b/dmtree/tr181/x_iopsys_eu_syslog.h index 4be78136..2d641dd7 100644 --- a/dmtree/tr181/x_iopsys_eu_syslog.h +++ b/dmtree/tr181/x_iopsys_eu_syslog.h @@ -16,12 +16,4 @@ extern DMLEAF tSe_SyslogCfgParam[]; -int get_server_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_server_port_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_server_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_server_port_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif diff --git a/dmtree/tr181/x_iopsys_eu_wifilife.c b/dmtree/tr181/x_iopsys_eu_wifilife.c index 2041d51c..e807ab93 100644 --- a/dmtree/tr181/x_iopsys_eu_wifilife.c +++ b/dmtree/tr181/x_iopsys_eu_wifilife.c @@ -10,6 +10,102 @@ #include "x_iopsys_eu_wifilife.h" + +static int browseWifiLifeSteeringObj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *isteer = NULL, *isteer_last = NULL; + struct dmmap_dup *p; + LIST_HEAD(dup_list); + + synchronize_specific_config_sections_with_dmmap("wifilife", "steer", "dmmap_wifilife", &dup_list); + list_for_each_entry(p, &dup_list, list) { + isteer = handle_update_instance(1, dmctx, &isteer_last, update_instance_alias, 3, p->dmmap_section, "steer_instance", "steer_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, isteer) == DM_STOP) + break; + } + free_dmmap_config_dup_list(&dup_list); + return 0; +} + +/************************************************************************************* +**** GET / SET function **** +**************************************************************************************/ +static int get_x_iopsys_eu_wifilife_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string("wifilife", "@wifilife[0]", "enabled", value); + if ((*value)[0] == '\0') { + *value = "1"; + } + return 0; +} + +static int set_x_iopsys_eu_wifilife_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value("wifilife", "@wifilife[0]", "enabled", b ? "1" : "0"); + return 0; + } + return 0; +} + +static int get_wifilife_steering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value); + if ((*value)[0] == '\0') + *value = "0"; + return 0; +} + +static int set_wifilife_steering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0"); + return 0; + } + return 0; +} + +static int get_wifilife_steering_legacy_fallback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "fallback_legacy", value); + if ((*value)[0] == '\0') + *value = "0"; + return 0; +} + +static int set_wifilife_steering_legacy_fallback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section((struct uci_section *)data, "fallback_legacy", b ? "1" : "0"); + return 0; + } + return 0; +} + /*** DMROOT.X_IOPSYS_EU_WiFiLife. ****/ DMOBJ X_IOPSYS_EU_WiFiLifeObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -29,98 +125,3 @@ DMLEAF WiFiLifeSteeringParams[] = { {"LegacyFallback", &DMWRITE, DMT_BOOL, get_wifilife_steering_legacy_fallback, set_wifilife_steering_legacy_fallback, NULL, NULL, BBFDM_BOTH}, {0} }; - -int browseWifiLifeSteeringObj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *isteer = NULL, *isteer_last = NULL; - struct dmmap_dup *p; - LIST_HEAD(dup_list); - - synchronize_specific_config_sections_with_dmmap("wifilife", "steer", "dmmap_wifilife", &dup_list); - list_for_each_entry(p, &dup_list, list) { - isteer = handle_update_instance(1, dmctx, &isteer_last, update_instance_alias, 3, p->dmmap_section, "steer_instance", "steer_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, isteer) == DM_STOP) - break; - } - free_dmmap_config_dup_list(&dup_list); - return 0; -} - -/************************************************************************************* -**** GET / SET function **** -**************************************************************************************/ -int get_x_iopsys_eu_wifilife_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_option_value_string("wifilife", "@wifilife[0]", "enabled", value); - if ((*value)[0] == '\0') { - *value = "1"; - } - return 0; -} - -int set_x_iopsys_eu_wifilife_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value("wifilife", "@wifilife[0]", "enabled", b ? "1" : "0"); - return 0; - } - return 0; -} - -int get_wifilife_steering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value); - if ((*value)[0] == '\0') - *value = "0"; - return 0; -} - -int set_wifilife_steering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0"); - return 0; - } - return 0; -} - -int get_wifilife_steering_legacy_fallback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "fallback_legacy", value); - if ((*value)[0] == '\0') - *value = "0"; - return 0; -} - -int set_wifilife_steering_legacy_fallback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "fallback_legacy", b ? "1" : "0"); - return 0; - } - return 0; -} diff --git a/dmtree/tr181/x_iopsys_eu_wifilife.h b/dmtree/tr181/x_iopsys_eu_wifilife.h index 8bb055ad..3ea62415 100644 --- a/dmtree/tr181/x_iopsys_eu_wifilife.h +++ b/dmtree/tr181/x_iopsys_eu_wifilife.h @@ -17,13 +17,4 @@ extern DMOBJ X_IOPSYS_EU_WiFiLifeObj[]; extern DMLEAF X_IOPSYS_EU_WiFiLifeParams[]; extern DMLEAF WiFiLifeSteeringParams[]; -int browseWifiLifeSteeringObj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int get_x_iopsys_eu_wifilife_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_x_iopsys_eu_wifilife_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_wifilife_steering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_wifilife_steering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_wifilife_steering_legacy_fallback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int set_wifilife_steering_legacy_fallback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); - #endif // __WIFILIFE_H diff --git a/dmtree/tr181/xmpp.c b/dmtree/tr181/xmpp.c index 30e78fab..a7fdaa56 100644 --- a/dmtree/tr181/xmpp.c +++ b/dmtree/tr181/xmpp.c @@ -12,6 +12,533 @@ #include "xmpp.h" +static int add_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + struct uci_section *xmpp_connection, *xmpp_connection_server; + char *value1, *value2, *last_inst; + + last_inst = get_last_instance("cwmp_xmpp", "xmpp_connection", "connection_instance"); + dmuci_add_section_and_rename("cwmp_xmpp", "xmpp_connection", &xmpp_connection, &value1); + dmuci_add_section_and_rename("cwmp_xmpp", "xmpp_connection_server", &xmpp_connection_server, &value2); + dmasprintf(instancepara, "%d", atoi(last_inst)+1); + dmuci_set_value_by_section(xmpp_connection, "connection_instance", *instancepara); + dmuci_set_value_by_section(xmpp_connection, "enable", "0"); + dmuci_set_value_by_section(xmpp_connection, "interval", "30"); + dmuci_set_value_by_section(xmpp_connection, "attempt", "16"); + dmuci_set_value_by_section(xmpp_connection, "serveralgorithm", "DNS-SRV"); + dmuci_set_value_by_section(xmpp_connection_server, "id_connection", *instancepara); + dmuci_set_value_by_section(xmpp_connection_server, "connection_server_instance", "1"); + dmuci_set_value_by_section(xmpp_connection_server, "enable", "0"); + dmuci_set_value_by_section(xmpp_connection_server, "port", "5222"); + return 0; +} + +static int delete_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct uci_section *s, *ss = NULL; + char *prev_connection_instance; + + switch (del_action) { + case DEL_INST: + dmuci_get_value_by_section_string((struct uci_section *)data, "connection_instance", &prev_connection_instance); + uci_foreach_option_eq("cwmp_xmpp", "xmpp_connection_server", "id_connection", prev_connection_instance, s) { + dmuci_delete_by_section(s, NULL, NULL); + break; + } + dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); + return 0; + case DEL_ALL: + uci_foreach_sections("cwmp_xmpp", "xmpp_connection", s) { + if (found != 0) { + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + dmuci_delete_by_section(ss, NULL, NULL); + } + uci_foreach_sections("cwmp_xmpp", "xmpp_connection_server", s) { + if (found != 0) { + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + dmuci_delete_by_section(ss, NULL, NULL); + } + return 0; + } + return 0; +} + +/*#Device.XMPP.ConnectionNumberOfEntries!UCI:cwmp_xmpp/xmpp_connection/*/ +static int get_xmpp_connection_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s; + int cnt = 0; + + uci_foreach_sections("cwmp_xmpp", "xmpp_connection", s) { + cnt++; + } + dmasprintf(value, "%d", cnt); // MEM WILL BE FREED IN DMMEMCLEAN + return 0; +} + +static int get_xmpp_connection_supported_server_connect_algorithms(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "DNS-SRV,ServerTable"; + return 0; +} + +/*#Device.XMPP.Connection.{i}.Enable!UCI:cwmp_xmpp/xmpp_connection,@i-1/enable*/ +static int get_connection_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "enable", value); + return 0; +} + +static int set_connection_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section((struct uci_section *)data, "enable", b ? "1" : "0"); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.Alias!UCI:cwmp_xmpp/xmpp_connection,@i-1/connection_alias*/ +static int get_xmpp_connection_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "connection_alias", value); + return 0; +} + +static int set_xmpp_connection_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "connection_alias", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.Username!UCI:cwmp_xmpp/xmpp_connection,@i-1/username*/ +static int get_xmpp_connection_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "username", value); + return 0; +} + +static int set_xmpp_connection_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "username", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.Password!UCI:cwmp_xmpp/xmpp_connection,@i-1/password*/ +static int get_xmpp_connection_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ""; + return 0; +} + +static int set_xmpp_connection_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "password", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.Domain!UCI:cwmp_xmpp/xmpp_connection,@i-1/domain*/ +static int get_xmpp_connection_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "domain", value); + return 0; +} + +static int set_xmpp_connection_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "domain", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.Resource!UCI:cwmp_xmpp/xmpp_connection,@i-1/resource*/ +static int get_xmpp_connection_resource(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "resource", value); + return 0; +} + +static int set_xmpp_connection_resource(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "resource", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.ServerConnectAlgorithm!UCI:cwmp_xmpp/xmpp_connection,@i-1/serveralgorithm*/ +static int get_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "serveralgorithm", value); + return 0; +} + +static int set_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, NULL, NULL, ServerConnectAlgorithm)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "serveralgorithm", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.KeepAliveInterval!UCI:cwmp_xmpp/xmpp_connection,@i-1/interval*/ +static int get_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "interval", value); + return 0; +} + +static int set_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_long(value, "-1", NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "interval", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.ServerConnectAttempts!UCI:cwmp_xmpp/xmpp_connection,@i-1/attempt*/ +static int get_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "attempt", value); + return 0; +} + +static int set_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "attempt", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.ServerRetryInitialInterval!UCI:cwmp_xmpp/xmpp_connection,@i-1/initial_retry_interval*/ +static int get_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "initial_retry_interval", value); + return 0; +} + +static int set_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", "65535")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "initial_retry_interval", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.ServerRetryIntervalMultiplier!UCI:cwmp_xmpp/xmpp_connection,@i-1/retry_interval_multiplier*/ +static int get_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "retry_interval_multiplier", value); + return 0; +} + +static int set_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1000", "65535")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "retry_interval_multiplier", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.ServerRetryMaxInterval!UCI:cwmp_xmpp/xmpp_connection,@i-1/retry_max_interval*/ +static int get_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "retry_max_interval", value); + return 0; +} + +static int set_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "1", NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "retry_max_interval", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.UseTLS!UCI:cwmp_xmpp/xmpp_connection,@i-1/usetls*/ +static int get_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "usetls", value); + return 0; +} + +static int set_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section((struct uci_section *)data, "usetls", b ? "1" : "0"); + return 0; + } + return 0; +} + +static int get_xmpp_connection_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *resource, *domain, *username; + + dmuci_get_value_by_section_string((struct uci_section *)data, "resource", &resource); + dmuci_get_value_by_section_string((struct uci_section *)data, "domain", &domain); + dmuci_get_value_by_section_string((struct uci_section *)data, "username", &username); + if (*resource != '\0' || *domain != '\0' || *username != '\0') + dmasprintf(value, "%s@%s/%s", username, domain, resource); + else + *value = ""; + return 0; +} + +/*#Device.XMPP.Connection.{i}.Status!UCI:cwmp_xmpp/xmpp_connection,@i-1/enable*/ +static int get_xmpp_connection_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *status; + + dmuci_get_value_by_section_string((struct uci_section *)data, "enable", &status); + if (strcmp(status, "1") == 0) + *value = "Enabled"; + else + *value = "Disabled"; + return 0; +} + +static int get_xmpp_connection_server_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +/*#Device.XMPP.Connection.{i}.Server.{i}.Enable!UCI:cwmp_xmpp/xmpp_connection,@i-1/enable*/ +static int get_xmpp_connection_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "enable", value); + return 0; +} + +static int set_xmpp_connection_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + + switch (action) { + case VALUECHECK: + if (dm_validate_boolean(value)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_set_value_by_section((struct uci_section *)data, "enable", b ? "1" : "0"); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.Server.{i}.Alias!UCI:cwmp_xmpp/xmpp_connection,@i-1/connection_server_alias*/ +static int get_xmpp_connection_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "connection_server_alias", value); + return 0; +} + +static int set_xmpp_connection_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "64", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "connection_server_alias", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.Server.{i}.ServerAddress!UCI:cwmp_xmpp/xmpp_connection,@i-1/server_address*/ +static int get_xmpp_connection_server_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "server_address", value); + return 0; +} + +static int set_xmpp_connection_server_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, NULL, "256", NULL, NULL)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "server_address", value); + return 0; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.Server.{i}.Port!UCI:cwmp_xmpp/xmpp_connection,@i-1/port*/ +static int get_xmpp_connection_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string((struct uci_section *)data, "port", value); + return 0; +} + +static int set_xmpp_connection_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_unsignedInt(value, "0", "65535")) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section((struct uci_section *)data, "port", value); + return 0; + } + return 0; +} + +/************************************************************************** +* LINKER +***************************************************************************/ +static int get_xmpp_connection_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + char *conn_instance; + + if (data) { + dmuci_get_value_by_section_string((struct uci_section *)data, "connection_instance", &conn_instance); + dmasprintf(linker,"xmppc:%s", conn_instance); + } else + *linker = ""; + return 0; +} + +/************************************************************* +* ENTRY METHOD +**************************************************************/ +/*#Device.XMPP.Connection.{i}.!UCI:cwmp_xmpp/xmpp_connection/dmmap_cwmp_xmpp*/ +static int browsexmpp_connectionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *iconnection = NULL, *iconnection_last = NULL; + struct uci_section *s = NULL; + + uci_foreach_sections("cwmp_xmpp", "xmpp_connection", s) { + iconnection = handle_update_instance(1, dmctx, &iconnection_last, update_instance_alias, 3, s, "connection_instance", "connection_instance_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, iconnection) == DM_STOP) + break; + } + return 0; +} + +/*#Device.XMPP.Connection.{i}.!UCI:cwmp_xmpp/xmpp_connection_server/dmmap_cwmp_xmpp*/ +static int browsexmpp_connection_serverInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *iconnectionserver = NULL, *iconnectionserver_last = NULL, *prev_connection_instance; + struct uci_section *s = NULL, *connsection = (struct uci_section *)prev_data; + + dmuci_get_value_by_section_string(connsection, "connection_instance", &prev_connection_instance); + uci_foreach_option_eq("cwmp_xmpp", "xmpp_connection_server", "id_connection", prev_connection_instance, s) { + iconnectionserver = handle_update_instance(1, dmctx, &iconnectionserver_last, update_instance_alias, 3, s, "connection_server_instance", "connection_server_instance_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, iconnectionserver) == DM_STOP) + break; + } + return 0; +} + /* *** Device.XMPP. *** */ DMOBJ tXMPPObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ @@ -63,531 +590,3 @@ DMLEAF tXMPPConnectionServerParams[] = { {"Port", &DMWRITE, DMT_UNINT, get_xmpp_connection_server_port, set_xmpp_connection_server_port, NULL, NULL, BBFDM_BOTH}, {0} }; - -int add_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char **instancepara) -{ - struct uci_section *xmpp_connection, *xmpp_connection_server; - char *value1, *value2, *last_inst; - - last_inst = get_last_instance("cwmp_xmpp", "xmpp_connection", "connection_instance"); - dmuci_add_section_and_rename("cwmp_xmpp", "xmpp_connection", &xmpp_connection, &value1); - dmuci_add_section_and_rename("cwmp_xmpp", "xmpp_connection_server", &xmpp_connection_server, &value2); - dmasprintf(instancepara, "%d", atoi(last_inst)+1); - dmuci_set_value_by_section(xmpp_connection, "connection_instance", *instancepara); - dmuci_set_value_by_section(xmpp_connection, "enable", "0"); - dmuci_set_value_by_section(xmpp_connection, "interval", "30"); - dmuci_set_value_by_section(xmpp_connection, "attempt", "16"); - dmuci_set_value_by_section(xmpp_connection, "serveralgorithm", "DNS-SRV"); - dmuci_set_value_by_section(xmpp_connection_server, "id_connection", *instancepara); - dmuci_set_value_by_section(xmpp_connection_server, "connection_server_instance", "1"); - dmuci_set_value_by_section(xmpp_connection_server, "enable", "0"); - dmuci_set_value_by_section(xmpp_connection_server, "port", "5222"); - return 0; -} - -int delete_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) -{ - int found = 0; - struct uci_section *s, *ss = NULL; - char *prev_connection_instance; - - switch (del_action) { - case DEL_INST: - dmuci_get_value_by_section_string((struct uci_section *)data, "connection_instance", &prev_connection_instance); - uci_foreach_option_eq("cwmp_xmpp", "xmpp_connection_server", "id_connection", prev_connection_instance, s) { - dmuci_delete_by_section(s, NULL, NULL); - break; - } - dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); - return 0; - case DEL_ALL: - uci_foreach_sections("cwmp_xmpp", "xmpp_connection", s) { - if (found != 0) { - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - dmuci_delete_by_section(ss, NULL, NULL); - } - uci_foreach_sections("cwmp_xmpp", "xmpp_connection_server", s) { - if (found != 0) { - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - dmuci_delete_by_section(ss, NULL, NULL); - } - return 0; - } - return 0; -} - -/*#Device.XMPP.ConnectionNumberOfEntries!UCI:cwmp_xmpp/xmpp_connection/*/ -int get_xmpp_connection_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *s; - int cnt = 0; - - uci_foreach_sections("cwmp_xmpp", "xmpp_connection", s) { - cnt++; - } - dmasprintf(value, "%d", cnt); // MEM WILL BE FREED IN DMMEMCLEAN - return 0; -} - -int get_xmpp_connection_supported_server_connect_algorithms(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "DNS-SRV,ServerTable"; - return 0; -} - -/*#Device.XMPP.Connection.{i}.Enable!UCI:cwmp_xmpp/xmpp_connection,@i-1/enable*/ -int get_connection_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "enable", value); - return 0; -} - -int set_connection_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "enable", b ? "1" : "0"); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.Alias!UCI:cwmp_xmpp/xmpp_connection,@i-1/connection_alias*/ -int get_xmpp_connection_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "connection_alias", value); - return 0; -} - -int set_xmpp_connection_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "connection_alias", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.Username!UCI:cwmp_xmpp/xmpp_connection,@i-1/username*/ -int get_xmpp_connection_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "username", value); - return 0; -} - -int set_xmpp_connection_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "username", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.Password!UCI:cwmp_xmpp/xmpp_connection,@i-1/password*/ -int get_xmpp_connection_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = ""; - return 0; -} - -int set_xmpp_connection_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "password", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.Domain!UCI:cwmp_xmpp/xmpp_connection,@i-1/domain*/ -int get_xmpp_connection_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "domain", value); - return 0; -} - -int set_xmpp_connection_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "domain", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.Resource!UCI:cwmp_xmpp/xmpp_connection,@i-1/resource*/ -int get_xmpp_connection_resource(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "resource", value); - return 0; -} - -int set_xmpp_connection_resource(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "resource", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.ServerConnectAlgorithm!UCI:cwmp_xmpp/xmpp_connection,@i-1/serveralgorithm*/ -int get_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "serveralgorithm", value); - return 0; -} - -int set_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, NULL, NULL, ServerConnectAlgorithm)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "serveralgorithm", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.KeepAliveInterval!UCI:cwmp_xmpp/xmpp_connection,@i-1/interval*/ -int get_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "interval", value); - return 0; -} - -int set_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_long(value, "-1", NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "interval", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.ServerConnectAttempts!UCI:cwmp_xmpp/xmpp_connection,@i-1/attempt*/ -int get_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "attempt", value); - return 0; -} - -int set_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "attempt", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.ServerRetryInitialInterval!UCI:cwmp_xmpp/xmpp_connection,@i-1/initial_retry_interval*/ -int get_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "initial_retry_interval", value); - return 0; -} - -int set_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", "65535")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "initial_retry_interval", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.ServerRetryIntervalMultiplier!UCI:cwmp_xmpp/xmpp_connection,@i-1/retry_interval_multiplier*/ -int get_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "retry_interval_multiplier", value); - return 0; -} - -int set_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1000", "65535")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "retry_interval_multiplier", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.ServerRetryMaxInterval!UCI:cwmp_xmpp/xmpp_connection,@i-1/retry_max_interval*/ -int get_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "retry_max_interval", value); - return 0; -} - -int set_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "1", NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "retry_max_interval", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.UseTLS!UCI:cwmp_xmpp/xmpp_connection,@i-1/usetls*/ -int get_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "usetls", value); - return 0; -} - -int set_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "usetls", b ? "1" : "0"); - return 0; - } - return 0; -} - -int get_xmpp_connection_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *resource, *domain, *username; - - dmuci_get_value_by_section_string((struct uci_section *)data, "resource", &resource); - dmuci_get_value_by_section_string((struct uci_section *)data, "domain", &domain); - dmuci_get_value_by_section_string((struct uci_section *)data, "username", &username); - if (*resource != '\0' || *domain != '\0' || *username != '\0') - dmasprintf(value, "%s@%s/%s", username, domain, resource); - else - *value = ""; - return 0; -} - -/*#Device.XMPP.Connection.{i}.Status!UCI:cwmp_xmpp/xmpp_connection,@i-1/enable*/ -int get_xmpp_connection_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *status; - - dmuci_get_value_by_section_string((struct uci_section *)data, "enable", &status); - if (strcmp(status, "1") == 0) - *value = "Enabled"; - else - *value = "Disabled"; - return 0; -} - -int get_xmpp_connection_server_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = "1"; - return 0; -} - -/*#Device.XMPP.Connection.{i}.Server.{i}.Enable!UCI:cwmp_xmpp/xmpp_connection,@i-1/enable*/ -int get_xmpp_connection_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "enable", value); - return 0; -} - -int set_xmpp_connection_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - bool b; - - switch (action) { - case VALUECHECK: - if (dm_validate_boolean(value)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "enable", b ? "1" : "0"); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.Server.{i}.Alias!UCI:cwmp_xmpp/xmpp_connection,@i-1/connection_server_alias*/ -int get_xmpp_connection_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "connection_server_alias", value); - return 0; -} - -int set_xmpp_connection_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "64", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "connection_server_alias", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.Server.{i}.ServerAddress!UCI:cwmp_xmpp/xmpp_connection,@i-1/server_address*/ -int get_xmpp_connection_server_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "server_address", value); - return 0; -} - -int set_xmpp_connection_server_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, NULL, "256", NULL, NULL)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "server_address", value); - return 0; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.Server.{i}.Port!UCI:cwmp_xmpp/xmpp_connection,@i-1/port*/ -int get_xmpp_connection_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "port", value); - return 0; -} - -int set_xmpp_connection_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_unsignedInt(value, "0", "65535")) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "port", value); - return 0; - } - return 0; -} - -/************************************************************************** -* LINKER -***************************************************************************/ -int get_xmpp_connection_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) -{ - char *conn_instance; - - if (data) { - dmuci_get_value_by_section_string((struct uci_section *)data, "connection_instance", &conn_instance); - dmasprintf(linker,"xmppc:%s", conn_instance); - } else - *linker = ""; - return 0; -} - -/************************************************************* -* ENTRY METHOD -**************************************************************/ -/*#Device.XMPP.Connection.{i}.!UCI:cwmp_xmpp/xmpp_connection/dmmap_cwmp_xmpp*/ -int browsexmpp_connectionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *iconnection = NULL, *iconnection_last = NULL; - struct uci_section *s = NULL; - - uci_foreach_sections("cwmp_xmpp", "xmpp_connection", s) { - iconnection = handle_update_instance(1, dmctx, &iconnection_last, update_instance_alias, 3, s, "connection_instance", "connection_instance_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, iconnection) == DM_STOP) - break; - } - return 0; -} - -/*#Device.XMPP.Connection.{i}.!UCI:cwmp_xmpp/xmpp_connection_server/dmmap_cwmp_xmpp*/ -int browsexmpp_connection_serverInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - char *iconnectionserver = NULL, *iconnectionserver_last = NULL, *prev_connection_instance; - struct uci_section *s = NULL, *connsection = (struct uci_section *)prev_data; - - dmuci_get_value_by_section_string(connsection, "connection_instance", &prev_connection_instance); - uci_foreach_option_eq("cwmp_xmpp", "xmpp_connection_server", "id_connection", prev_connection_instance, s) { - iconnectionserver = handle_update_instance(1, dmctx, &iconnectionserver_last, update_instance_alias, 3, s, "connection_server_instance", "connection_server_instance_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, iconnectionserver) == DM_STOP) - break; - } - return 0; -} - diff --git a/dmtree/tr181/xmpp.h b/dmtree/tr181/xmpp.h index 48136920..b3d61c1f 100644 --- a/dmtree/tr181/xmpp.h +++ b/dmtree/tr181/xmpp.h @@ -21,51 +21,4 @@ extern DMLEAF tXMPPConnectionParams[]; extern DMOBJ tXMPPConnectionObj[]; extern DMLEAF tXMPPConnectionServerParams[]; -int browsexmpp_connectionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int browsexmpp_connection_serverInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int add_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char **instancepara); -int delete_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); - -int get_xmpp_connection_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_supported_server_connect_algorithms(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_connection_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_resource(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_server_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_server_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int get_xmpp_connection_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); - -int set_connection_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_resource(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_server_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_server_server_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int set_xmpp_connection_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int get_xmpp_connection_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); #endif