diff --git a/dm/dmtree/tr098/landevice.c b/dm/dmtree/tr098/landevice.c index b3801cc..16a5729 100644 --- a/dm/dmtree/tr098/landevice.c +++ b/dm/dmtree/tr098/landevice.c @@ -3649,20 +3649,13 @@ end: int browselanethernetinterfaceconfigInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { int i = 0; - char *pch, *spch; char *ifname, *wan_eth, *baseifname; char *ieth = NULL, *ieth_last = NULL; struct uci_section *s = NULL; struct ldlanargs *lanargs = (struct ldlanargs *)prev_data; struct ldethargs curr_ethargs = {0}; -#ifdef EX400 - uci_foreach_option_eq("ports", "ethport", "name", "WAN", s) { - dmuci_get_value_by_section_string(s, "ifname", &wan_eth); - } -#else - dmuci_get_option_value_string("layer2_interface_ethernet", "ethernet_interface", "baseifname", &wan_eth); -#endif + dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_eth); dmuci_get_value_by_section_string(lanargs->ldlansection, "ifname", &ifname); lan_eth_update_section_option_list(ifname, section_name(lanargs->ldlansection), wan_eth); uci_path_foreach_option_eq(icwmpd, "dmmap", "lan_eth", "network", section_name(lanargs->ldlansection), s) { diff --git a/dm/dmtree/tr098/layer_2_bridging.c b/dm/dmtree/tr098/layer_2_bridging.c index 97d844c..3945b26 100644 --- a/dm/dmtree/tr098/layer_2_bridging.c +++ b/dm/dmtree/tr098/layer_2_bridging.c @@ -23,9 +23,9 @@ const char *vlan_ifname[3] = {"eth","atm", "ptm"}; char *wan_baseifname = NULL; #ifndef EX400 struct wan_interface wan_interface_tab[3] = { -{"1", "ethernet", "layer2_interface_ethernet", "ethernet_interface"}, -{"2", "adsl", "layer2_interface_adsl", "atm_bridge"}, -{"3", "vdsl", "layer2_interface_vdsl", "vdsl_interface"} +{"1", "ethernet", "ports", "ethport"}, +{"2", "adsl", "dsl", "atm-device"}, +{"3", "vdsl", "dsl", "ptm-device"} }; #endif @@ -99,7 +99,7 @@ int browselayer2_availableinterfaceInst(struct dmctx *dmctx, DMNODE *parent_node uci_foreach_sections(wan_interface_tab[i].package, wan_interface_tab[i].section, wan_s) { waninstance = update_instance(wan_s, waninstance, "waninstance"); dmasprintf(&oface, "%s%cWANDevice%c%s%cWANConnectionDevice%c%s%c", DMROOT, dm_delim, dm_delim, wan_interface_tab[i].instance, dm_delim, dm_delim, waninstance, dm_delim); // MEM WILL BE FREED IN DMMEMCLEAN - dmuci_get_value_by_section_string(wan_s, "baseifname", &base_ifname); + dmuci_get_value_by_section_string(wan_s, "device", &base_ifname); ai_s = update_availableinterface_list(dmctx, base_ifname, &available_inst, &instance_last); init_args_layer2(&curr_args, ai_s, NULL, instance_last, NULL, "WANInterface", oface); if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_args, available_inst) == DM_STOP) @@ -110,7 +110,7 @@ int browselayer2_availableinterfaceInst(struct dmctx *dmctx, DMNODE *parent_node uci_foreach_sections("ports", "ethport", wan_s) { if(!strcmp(wan_s->e.name, "WAN")){ waninstance = update_instance(wan_s, waninstance, "waninstance"); - dmasprintf(&oface, DMROOT_CWMP"WANDevice.1.WANConnectionDevice.%s.", waninstance); // MEM WILL BE FREED IN DMMEMCLEAN + dmasprintf(&oface, "%s%cWANDevice%c1%cWANConnectionDevice%c%s%c", DMROOT, dm_delim, dm_delim, dm_delim, dm_delim, waninstance, dm_delim); // MEM WILL BE FREED IN DMMEMCLEAN dmuci_get_value_by_section_string(wan_s, "baseifname", &base_ifname); ai_s = update_availableinterface_list(dmctx, base_ifname, &available_inst, &instance_last); init_args_layer2(&curr_args, ai_s, NULL, instance_last, NULL, "WANInterface", oface); @@ -148,11 +148,8 @@ int browselayer2_bridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev char *bridge_instance = NULL, *bridge_instance_last = NULL; struct uci_section *bridge_s; struct args_layer2 curr_args = {0}; -#ifdef EX400 - dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_baseifname); -#else - dmuci_get_option_value_string("layer2_interface_ethernet", "Wan", "baseifname", &wan_baseifname); -#endif + + dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_baseifname); uci_foreach_option_eq("network", "interface", "type", "bridge", bridge_s) { bridge_instance = handle_update_instance(1, dmctx, &bridge_instance_last, update_instance_alias, 3, bridge_s, "bridge_instance", "bridge_alias"); init_args_layer2(&curr_args, bridge_s, NULL, NULL, bridge_instance_last, NULL, NULL); @@ -207,7 +204,7 @@ int synchronize_availableinterfaceInst(struct dmctx *dmctx) uci_foreach_sections(wan_interface_tab[i].package, wan_interface_tab[i].section, wan_s) { waninstance = update_instance(wan_s, waninstance, "waninstance"); dmasprintf(&oface, "%s%cWANDevice%c%s%cWANConnectionDevice%c%s%c", DMROOT, dm_delim, dm_delim, wan_interface_tab[i].instance, dm_delim, dm_delim, waninstance, dm_delim); // MEM WILL BE FREED IN DMMEMCLEAN - dmuci_get_value_by_section_string(wan_s, "baseifname", &base_ifname); + dmuci_get_value_by_section_string(wan_s, "device", &base_ifname); update_availableinterface_list(dmctx, base_ifname, &available_inst, &instance_last); } } @@ -215,7 +212,7 @@ int synchronize_availableinterfaceInst(struct dmctx *dmctx) uci_foreach_sections("ports", "ethport", wan_s) { if(!strcmp(wan_s->e.name, "WAN")){ waninstance = update_instance(wan_s, waninstance, "waninstance"); - dmasprintf(&oface, DMROOT_CWMP"WANDevice.1.WANConnectionDevice.%s.", waninstance); // MEM WILL BE FREED IN DMMEMCLEAN + dmasprintf(&oface, "%s%cWANDevice%c1%cWANConnectionDevice%c%s%c", DMROOT, dm_delim, dm_delim, dm_delim, dm_delim, waninstance, dm_delim); // MEM WILL BE FREED IN DMMEMCLEAN dmuci_get_value_by_section_string(wan_s, "baseifname", &base_ifname); update_availableinterface_list(dmctx, base_ifname, &available_inst, &instance_last); } diff --git a/dm/dmtree/tr098/wandevice.c b/dm/dmtree/tr098/wandevice.c index 125d927..69ba4d4 100644 --- a/dm/dmtree/tr098/wandevice.c +++ b/dm/dmtree/tr098/wandevice.c @@ -210,9 +210,9 @@ struct wan_device }; struct wan_device wan_devices[WAN_DEVICE] = { - [WAN_IDX_ETH] = {"1", NULL, "ethernet_interface", "layer2_interface_ethernet"}, - [WAN_IDX_ATM] = {"2", "atm", "atm_bridge", "layer2_interface_adsl"}, - [WAN_IDX_PTM] = {"3", "ptm", "vdsl_interface", "layer2_interface_vdsl"} + [WAN_IDX_ETH] = {"1", "eth0", "ethport", "ports"}, + [WAN_IDX_ATM] = {"2", "atm", "atm-device", "dsl"}, + [WAN_IDX_PTM] = {"3", "ptm", "ptm-device", "dsl"} }; #endif @@ -297,14 +297,13 @@ void set_bridge_layer2(struct dmctx *ctx, char *bridge, struct wanargs *wandcpro } #ifndef EX400 else if (strstr(pch, "atm")) { - uci_foreach_option_eq("layer2_interface_adsl", "atm_bridge", "ifname", pch, s) + uci_foreach_option_eq("network", "device", "name", pch, s) { dmuci_set_value_by_section(s, "bridge", bridge); } - } else if (strstr(pch, "ptm")) { - uci_foreach_option_eq("layer2_interface_vdsl", "vdsl_interface", "ifname", pch, s) + uci_foreach_option_eq("network", "device", "name", pch, s) { dmuci_set_value_by_section(s, "bridge", bridge); } @@ -315,14 +314,11 @@ void set_bridge_layer2(struct dmctx *ctx, char *bridge, struct wanargs *wandcpro uci_foreach_option_eq("network", "interface", "ifname", pch, s) { - dmuci_set_value_by_section(s, "bridge", bridge); - - fprintf(stdout, "bridge = %s\n", bridge); } #else - uci_foreach_option_eq("layer2_interface_ethernet", "ethernet_interface", "ifname", pch, s) + uci_foreach_option_eq("network", "device", "name", pch, s) { dmuci_set_value_by_section(s, "bridge", bridge); } @@ -439,47 +435,40 @@ char *get_last_instance_proto(char *package, char *section, char *opt_inst, char int add_wan_wanconnectiondevice(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { #ifndef EX400 - int iwan, idx; - char *value; char *instance; - char ifname[16] = {0}; - char buf[16] = {0}; - struct uci_section *s = NULL; + char *device = NULL; + char *instance_update = NULL; struct wanargs *wandargs = (struct wanargs *)data; if (wandargs->instance == WAN_INST_ATM) { - idx = get_cfg_layer2idx("layer2_interface_adsl", "atm_bridge", "baseifname", sizeof("atm")-1); - sprintf(buf, "atm%d",idx); - sprintf(ifname,"%s.1",buf); - instance = get_last_instance_lev2("layer2_interface_adsl", "atm_bridge", "waninstance", "baseifname", "atm"); - dmuci_add_section("layer2_interface_adsl", "atm_bridge", &s, &value); - dmuci_set_value_by_section(s, "baseifname", buf); - dmuci_set_value_by_section(s, "bridge", "0"); - dmuci_set_value_by_section(s, "encapseoa", "llcsnap_eth"); - dmuci_set_value_by_section(s, "ifname", ifname); - dmuci_set_value_by_section(s, "link_type", "EoA"); - dmuci_set_value_by_section(s, "unit", buf+3); - dmuci_set_value_by_section(s, "vci", "35"); - dmuci_set_value_by_section(s, "vpi", "8"); - *instancepara = update_instance(s, instance, "waninstance"); + instance = get_last_instance_lev2("dsl", "atm-device", "waninstance", "device", "atm"); + dmasprintf(&device, "atm%d", instance ? atoi(instance) : 0); + dmasprintf(&instance_update, "%d", instance ? atoi(instance)+ 1 : 1); + dmuci_set_value("dsl", device, "", "atm-device"); + dmuci_set_value("dsl", device, "name", "ATM"); + dmuci_set_value("dsl", device, "vpi", "8"); + dmuci_set_value("dsl", device, "vci", "35"); + dmuci_set_value("dsl", device, "device", device); + dmuci_set_value("dsl", device, "link_type", "eoa"); + dmuci_set_value("dsl", device, "encapsulation", "llc"); + dmuci_set_value("dsl", device, "qos_class", "ubr"); + *instancepara = dmuci_set_value("dsl", device, "waninstance", instance_update); return 0; } else if (wandargs->instance == WAN_INST_PTM) { - idx = get_cfg_layer2idx("layer2_interface_vdsl", "vdsl_interface", "baseifname", sizeof("ptm")-1); - sprintf(buf,"ptm%d", idx); - sprintf(ifname,"%s.1",buf); - instance = get_last_instance_lev2("layer2_interface_vdsl", "vdsl_interface", "waninstance", "baseifname", "ptm"); - dmuci_add_section("layer2_interface_vdsl", "vdsl_interface", &s, &value); - dmuci_set_value_by_section(s, "baseifname", buf); - dmuci_set_value_by_section(s, "bridge", "0"); - dmuci_set_value_by_section(s, "ifname", ifname); - dmuci_set_value_by_section(s, "unit", buf+3); - *instancepara = update_instance(s, instance, "waninstance"); + instance = get_last_instance_lev2("dsl", "ptm-device", "waninstance", "device", "ptm"); + dmasprintf(&device, "ptm%d", instance ? atoi(instance) : 0); + dmasprintf(&instance_update, "%d", instance ? atoi(instance)+ 1 : 1); + dmuci_set_value("dsl", device, "", "ptm-device"); + dmuci_set_value("dsl", device, "name", "PTM"); + dmuci_set_value("dsl", device, "device", device); + dmuci_set_value("dsl", device, "priority", "1"); + dmuci_set_value("dsl", device, "portid", "1"); + *instancepara = dmuci_set_value("dsl", device, "waninstance", instance_update); return 0; } return FAULT_9005; #else - return FAULT_9008; #endif } @@ -491,7 +480,7 @@ int delete_wan_wanconnectiondevice(char *refparam, struct dmctx *ctx, void *data struct uci_section *ss = NULL; struct wanargs *wandargs; struct wanargs *wandcdevargs; - + switch (del_action) { case DEL_INST: wandcdevargs = (struct wanargs *)data; @@ -506,7 +495,7 @@ int delete_wan_wanconnectiondevice(char *refparam, struct dmctx *ctx, void *data return 0; case DEL_ALL: wandargs = (struct wanargs *)data; - uci_foreach_option_cont(wan_devices[wandargs->instance - 1].cdev, wan_devices[wandargs->instance - 1].stype, "baseifname", wandargs->fdev, s) { + uci_foreach_option_cont(wan_devices[wandargs->instance - 1].cdev, wan_devices[wandargs->instance - 1].stype, "device", wandargs->fdev, s) { if (ss) dmuci_delete_by_section(ss, NULL, NULL); ss = s; @@ -526,7 +515,6 @@ int delete_wan_wanconnectiondevice(char *refparam, struct dmctx *ctx, void *data } return 0; #else - return FAULT_9008; #endif } @@ -541,7 +529,6 @@ int add_wan_wanipconnection(char *refparam, struct dmctx *ctx, void *data, char instance = get_last_instance_proto("network", "interface", "conipinstance", "ifname", wandcdevargs->fwan, "proto", WAN_PROTO_IP); dmasprintf(instancepara, "%d", instance ? atoi(instance) + 1 : 1); //MEM WILL BE FREED IN DMMEMCLEAN #ifdef EX400 - sprintf(sname,"wan_1_%s_%d_%s", wandcdevargs->iwan, WAN_IP_CONNECTION, *instancepara); #else @@ -593,7 +580,6 @@ int add_wan_wanpppconnection(char *refparam, struct dmctx *ctx, void *data, char instance = get_last_instance_proto("network", "interface", "conpppinstance", "ifname", wandcdevargs->fwan, "proto", WAN_PROTO_PPP); dmasprintf(instancepara, "%d", instance ? atoi(instance) + 1 : 1); #ifdef EX400 - sprintf(sname,"wan_1_%s_%d_%s", wandcdevargs->iwan, WANPPPConnection, *instancepara); #else @@ -1044,16 +1030,19 @@ int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, vo int get_annexm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *val = "0"; - *value = "0"; struct wanargs *wandargs = (struct wanargs *)data; + struct uci_list *v; + struct uci_element *e; + *value = "0"; if (wandargs->instance == WAN_INST_ATM) { - dmuci_get_option_value_string("layer2_interface", "capabilities", "AnnexM", &val); - if (val[0] != '\0') { - if (strcasecmp(val, "enabled") == 0) { - *value = "1"; - return 0; + dmuci_get_option_value_list("dsl","line","mode", &v); + if (v) { + uci_foreach_element(v, e) { + if (strcasecmp(e->name, "AnnexM") == 0) { + *value = "1"; + return 0; + } } } } @@ -1062,9 +1051,10 @@ int get_annexm_status(char *refparam, struct dmctx *ctx, void *data, char *insta int set_annexm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - bool b; - + struct uci_list *v; + struct uci_element *e; struct wanargs *wandargs = (struct wanargs *)data; + bool b; switch (action) { case VALUECHECK: @@ -1076,12 +1066,19 @@ int set_annexm_enable(char *refparam, struct dmctx *ctx, void *data, char *insta return 0; } string_to_bool(value, &b); - if(b) { - dmuci_set_value("layer2_interface", "capabilities", "AnnexM", "Enabled"); + + dmuci_get_option_value_list("dsl","line","mode", &v); + if (v) { + uci_foreach_element(v, e) { + if (strcasecmp(e->name, "AnnexM") == 0 && b==false) { + dmuci_del_list_value("dsl", "line", "mode", "annexm"); + return 0; + }else if(strcasecmp(e->name, "AnnexM") != 0 && b==true){ + dmuci_add_list_value("dsl", "line", "mode", "annexm"); + return 0; + } + } } - else - dmuci_set_value("layer2_interface", "capabilities", "AnnexM", ""); - return 0; } return 0; } @@ -1265,8 +1262,8 @@ int get_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ct struct wanargs *wandcdevargs = (struct wanargs *)data; char *vpi, *vci; struct uci_section *s; - - uci_foreach_option_cont("layer2_interface_adsl", "atm_bridge", "ifname", wandcdevargs->fwan, s) { + + uci_foreach_option_cont("dsl", "atm-device", "device", wandcdevargs->fwan, s) { dmuci_get_value_by_section_string(s, "vpi", &vpi); dmuci_get_value_by_section_string(s, "vci", &vci); dmasprintf(value, "PVC: %s/%s", vpi, vci); // MEM WILL BE FREED IN DMMEMCLEAN @@ -1285,7 +1282,7 @@ int set_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ct case VALUECHECK: return 0; case VALUESET: - uci_foreach_option_cont("layer2_interface_adsl", "atm_bridge", "ifname", wandcdevargs->fwan, s) { + uci_foreach_option_cont("dsl", "atm-device", "device", wandcdevargs->fwan, s) { if (strstr(value, "PVC: ")) value += 5; else @@ -1311,25 +1308,18 @@ int get_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, { struct wanargs *wandcdevargs = (struct wanargs *)data; struct uci_section *s; - char *type, *encapsulation, *encaptype; + char *encapsulation; *value = ""; - uci_foreach_option_cont("layer2_interface_adsl", "atm_bridge", "ifname", wandcdevargs->fwan, s) { - dmuci_get_value_by_section_string(s,"link_type", &type); - if (strcmp(type, "EoA") == 0 ) { - type = "encapseoa"; - } else if (strcmp(type, "PPPoA") == 0) { - type = "encapspppoa"; - } else if (strcmp(type, "IPoA") == 0) { - type = "encapsipoa"; - } - dmuci_get_value_by_section_string(s, type, &encapsulation); + uci_foreach_option_cont("dsl", "atm-device", "device", wandcdevargs->fwan, s) { + dmuci_get_value_by_section_string(s, "encapsulation", &encapsulation); if (strstr(encapsulation, "vcmux")) { *value = "VCMUX"; } else if (strstr(encapsulation, "llc")) { *value = "LLC"; - } else { + } + else { *value = ""; } break; @@ -1339,43 +1329,26 @@ int get_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, int set_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - int i; struct uci_section *s; - char *type, *encapsulation, *encaptype, *pch; + char *type, *encapsulation; struct wanargs *wandcdevargs = (struct wanargs *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - uci_foreach_option_cont("layer2_interface_adsl", "atm_bridge", "ifname", wandcdevargs->fwan, s) { - dmuci_get_value_by_section_string(s, "link_type", &type); - int enc; + uci_foreach_option_cont("dsl", "atm-device", "device", wandcdevargs->fwan, s) { if (strstr(value, "VCMUX")) { - enc = 1; + encapsulation = "vcmux"; } else if (strstr(value, "LLC")) { - enc = 0; - } - else - return 0; - if (strstr(type, "EoA")) { - encaptype = "encapseoa"; - encapsulation = enc ? "vcmux_eth" : "llcsnap_eth"; - } - else if (strstr(type, "PPPoA")) { - encaptype = "encapspppoa"; - encapsulation = enc ? "vcmux_pppoa" : "llcencaps_ppp"; - } - else if (strstr(type, "IPoA")) { - encaptype = "encapsipoa"; - encapsulation = enc ? "vcmux_ipoa" : "llcsnap_rtip"; + encapsulation = "llc"; } else return 0; break; } - dmuci_set_value_by_section(s, encaptype, encapsulation); + dmuci_set_value_by_section(s, "encapsulation", encapsulation); return 0; } return 0; @@ -2319,9 +2292,6 @@ char *get_wan_connection_device_notif(char *refparam, struct dmctx *dmctx, void return "0"; } - - - int browsewandeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { int i = 0; @@ -2335,37 +2305,27 @@ int browsewandeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_dat dmuci_get_option_value_string("cwmp", "cpe", "default_wan_interface", &default_wan); dmuci_get_option_value_string("network", default_wan, "ifname", &default_wan_ifname); dmuci_get_option_value_string("network", default_wan, "proto", &defwanproto); -#ifdef EX400 - dmuci_get_option_value_string("ports", "WAN", "ifname", ð_wan); - -#else - dmuci_get_option_value_string("layer2_interface_ethernet", "Wan", "baseifname", ð_wan); wan_devices[WAN_IDX_ETH].fdev = eth_wan; -#endif + if (strstr(defwanproto, "ppp")) default_wan_proto = WAN_PROTO_PPP; else if (strcmp(defwanproto, "dhcp") == 0 || strcmp(defwanproto, "static") == 0) default_wan_proto = WAN_PROTO_IP; else default_wan_proto = WAN_PROTO_NIL; - update_section_list(DMMAP,"wan_dev", NULL, 3, NULL, NULL, NULL, NULL, NULL); - uci_path_foreach_sections(icwmpd, "dmmap", "wan_dev", s) { + update_section_list(DMMAP,"wan_dev", NULL, 3, NULL, NULL, NULL, NULL, NULL); + uci_path_foreach_sections(icwmpd, "dmmap", "wan_dev", s) { #ifdef EX400 - if(i==WAN_IDX_ETH){ - init_wanargs(&curr_wanargs, i+1, eth_wan, s); - if (strstr(default_wan_ifname, eth_wan)) notif_permission = false; else notif_permission = true; - } #else init_wanargs(&curr_wanargs, i+1, wan_devices[i].fdev, s); - if (strstr(default_wan_ifname, wan_devices[i].fdev)) notif_permission = false; else @@ -2378,17 +2338,16 @@ int browsewandeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_dat else cwritable = "1"; #endif + dev = handle_update_instance(1, dmctx, &dev_last, update_instance_alias_icwmpd, 3, s, "wan_dev_instance", "wan_dev_alias"); #ifdef EX400 if(i==WAN_IDX_ETH){ - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wanargs, dev) == DM_STOP) break; - } #else if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wanargs, dev) == DM_STOP) - break; + break; #endif i++; } @@ -2401,7 +2360,8 @@ int browsewanconnectiondeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void char *fwan; char *wan_ifname; char *iwan = NULL, *iwan_last = NULL; - char *pack, *stype; + char *pack, *stype, *sname; + char uname[32] = ""; bool ipn_perm = true; bool pppn_perm = true; bool notif_permission = true; @@ -2409,54 +2369,69 @@ int browsewanconnectiondeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void struct wanargs *curr_wanargs = (struct wanargs *)prev_data; i = curr_wanargs->instance - 1; + #ifdef EX400 - - if (i==0){ - + if (i == WAN_IDX_ETH){ uci_foreach_sections("ports", "ethport", s) { - if(!strcmp(s->e.name, "WAN")){ - dmuci_get_value_by_section_string(s, "ifname", &fwan); - dmuci_get_option_value_string("network", "wan", "ifname", &wan_ifname); - if (strstr(default_wan_ifname, fwan)) { - notif_permission = false; - if (default_wan_proto == WAN_PROTO_IP) ipn_perm = false; else if (default_wan_proto == WAN_PROTO_PPP) pppn_perm = false; - } iwan = handle_update_instance(2, dmctx, &iwan_last, update_instance_alias, 3, s, "waninstance", "wanalias"); - init_wancdevargs(curr_wanargs, s, fwan, iwan_last, wan_ifname); - - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_wanargs, iwan) == DM_STOP){ + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_wanargs, iwan) == DM_STOP) break; - } - } } } #else pack = wan_devices[i].cdev; stype = wan_devices[i].stype; - uci_foreach_sections(pack, stype, s) { - dmuci_get_value_by_section_string(s, "baseifname", &fwan); - dmuci_get_value_by_section_string(s, "ifname", &wan_ifname); - if (strstr(default_wan_ifname, fwan)) { - notif_permission = false; - if (default_wan_proto == WAN_PROTO_IP) ipn_perm = false; - else if (default_wan_proto == WAN_PROTO_PPP) pppn_perm = false; + + if(i == WAN_IDX_ETH) + { + uci_foreach_sections(pack, stype, s) { + if(!strcmp(s->e.name, "WAN")){ + fwan = eth_wan; //eth0 + sprintf(uname, "%s.1", fwan); + wan_ifname = dmstrdup(uname); //eth0.1 + + if (strstr(default_wan_ifname, fwan)) { + notif_permission = false; + if (default_wan_proto == WAN_PROTO_IP) ipn_perm = false; + else if (default_wan_proto == WAN_PROTO_PPP) pppn_perm = false; + } + iwan = handle_update_instance(2, dmctx, &iwan_last, update_instance_alias, 3, s, "waninstance", "wanalias"); + init_wancdevargs(curr_wanargs, s, fwan, iwan_last, wan_ifname); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_wanargs, iwan) == DM_STOP) + goto end; + } + } + } + else + { + uci_foreach_sections(pack, stype, s) { + dmuci_get_value_by_section_string(s, "device", &fwan); //atm0 + sprintf(uname, "%s.1", fwan); + wan_ifname = dmstrdup(uname); //atm0.1 + + if (strstr(default_wan_ifname, fwan)) { + notif_permission = false; + if (default_wan_proto == WAN_PROTO_IP) ipn_perm = false; + else if (default_wan_proto == WAN_PROTO_PPP) pppn_perm = false; + } + iwan = handle_update_instance(2, dmctx, &iwan_last, update_instance_alias, 3, s, "waninstance", "wanalias"); + init_wancdevargs(curr_wanargs, s, fwan, iwan_last, wan_ifname); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_wanargs, iwan) == DM_STOP) + goto end; } - iwan = handle_update_instance(2, dmctx, &iwan_last, update_instance_alias, 3, s, "waninstance", "wanalias"); - init_wancdevargs(curr_wanargs, s, fwan, iwan_last, wan_ifname); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_wanargs, iwan) == DM_STOP) - break; } #endif +end: return 0; } diff --git a/dm/dmtree/tr181/bridging.c b/dm/dmtree/tr181/bridging.c index c6e07d0..472f2ba 100644 --- a/dm/dmtree/tr181/bridging.c +++ b/dm/dmtree/tr181/bridging.c @@ -19,7 +19,6 @@ char *wan_baseifname = NULL; - /*** Bridging. ***/ DMOBJ tBridgingObj[] = { /* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ @@ -98,7 +97,7 @@ DMLEAF tBridgeVlanPortParams[] = { * LINKER ***************************************************************************/ int get_linker_br_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - if(((struct bridging_port_args *)data)->bridge_port_sec) { + 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; } @@ -107,7 +106,7 @@ int get_linker_br_port(char *refparam, struct dmctx *dmctx, void *data, char *in } int get_linker_br_vlan(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - if(((struct bridging_vlan_args *)data)->vlan_port) { + 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; } @@ -167,49 +166,46 @@ int check_ifname_exist_in_br_ifname_list(char *ifname) int get_br_port_last_inst(char *br_key) { char *tmp; - int r = 0, dr = 0, ds = 0, max; + int max=1; struct uci_section *s; int buf[BUF_SIZE] = {0}; uci_path_foreach_option_eq(icwmpd, "dmmap", "bridge_port", "bridge_key", br_key, s) { dmuci_get_value_by_section_string(s, "bridge_port_instance", &tmp); if (tmp[0] == '\0') - break; + continue; buf[0] = atoi(tmp); + if(buf[0]>max) max=buf[0]; } uci_foreach_option_eq("ports", "ethport", "bridge_key", br_key, s) { dmuci_get_value_by_section_string(s, "bridge_port_instance", &tmp); if (tmp[0] == '\0') - break; + continue; buf[1] = atoi(tmp); + if(buf[1]>max) max=buf[1]; } #ifndef EX400 - uci_foreach_option_eq("layer2_interface_adsl", "atm_bridge", "bridge_key", br_key, s) { + uci_foreach_option_eq("dsl", "atm-device", "bridge_key", br_key, s) { dmuci_get_value_by_section_string(s, "bridge_port_instance", &tmp); if (tmp[0] == '\0') - break; + continue; buf[2] = atoi(tmp); + if(buf[2]>max) max=buf[2]; } - uci_foreach_option_eq("layer2_interface_vdsl", "vdsl_interface", "bridge_key", br_key, s) { + uci_foreach_option_eq("dsl", "ptm-device", "bridge_key", br_key, s) { dmuci_get_value_by_section_string(s, "bridge_port_instance", &tmp); if (tmp[0] == '\0') - break; + continue; buf[3] = atoi(tmp); + if(buf[3]>max) max=buf[3]; } - uci_foreach_option_eq("layer2_interface_ethernet", "ethernet_interface", "bridge_key", br_key, s) { -#else - uci_foreach_option_eq("ports", "ethport", "bridge_key", br_key, s) { #endif - dmuci_get_value_by_section_string(s, "bridge_port_instance", &tmp); - if (tmp[0] == '\0') - break; - buf[4] = atoi(tmp); - } uci_foreach_option_eq("wireless", "wifi-iface", "bridge_key", br_key, s) { dmuci_get_value_by_section_string(s, "bridge_port_instance", &tmp); if (tmp[0] == '\0') - break; - buf[5] = atoi(tmp); + continue; + buf[4] = atoi(tmp); + if(buf[4]>max) max=buf[4]; } uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "bridge_key", br_key, s) { dmuci_get_value_by_section_string(s, "bridge_port_instance", &tmp); @@ -217,7 +213,6 @@ int get_br_port_last_inst(char *br_key) break; buf[6] = atoi(tmp); } - max = max_array(buf, BUF_SIZE); return max; } @@ -270,11 +265,12 @@ char *br_port_update_instance_alias(int action, char **last_inst, void *argv[]) char *alias_opt = (char *) argv[2]; bool *find_max = (bool *) argv[3]; char *br_key = (char *) argv[4]; + int m; dmuci_get_value_by_section_string(s, inst_opt, &instance); if (instance[0] == '\0') { if (*find_max) { - int m = get_br_port_last_inst(br_key); + m = get_br_port_last_inst(br_key); sprintf(buf, "%d", m+1); *find_max = false; } @@ -309,19 +305,19 @@ int reset_br_port(char *br_key) dmuci_set_value_by_section(s, "penable", "0"); } #ifndef EX400 - uci_foreach_option_eq("layer2_interface_adsl", "atm_bridge", "bridge_key", br_key, s) { + uci_foreach_option_eq("dsl", "atm-device", "bridge_key", br_key, s) { dmuci_set_value_by_section(s, "bridge_port_instance", ""); dmuci_set_value_by_section(s, "bridge_port_alias", ""); dmuci_set_value_by_section(s, "bridge_key", ""); dmuci_set_value_by_section(s, "penable", "0"); } - uci_foreach_option_eq("layer2_interface_vdsl", "vdsl_interface", "bridge_key", br_key, s) { + uci_foreach_option_eq("dsl", "ptm-device", "bridge_key", br_key, s) { dmuci_set_value_by_section(s, "bridge_port_instance", ""); dmuci_set_value_by_section(s, "bridge_port_alias", ""); dmuci_set_value_by_section(s, "bridge_key", ""); dmuci_set_value_by_section(s, "penable", "0"); } - uci_foreach_option_eq("layer2_interface_ethernet", "ethernet_interface", "bridge_key", br_key, s) { + uci_foreach_option_eq("ports", "ethport", "bridge_key", br_key, s) { #else uci_foreach_option_eq("ports", "ethport", "bridge_key", br_key, s) { #endif @@ -369,14 +365,14 @@ int update_port_parameters(char *linker, char *br_key, char *br_pt_inst, char *m } #ifndef EX400 } else if (strncmp(linker, "ptm", 3) == 0) { - uci_foreach_option_eq("layer2_interface_vdsl", "vdsl_interface", "ifname", linker, s) { + uci_foreach_option_eq("dsl", "ptm-device", "device", linker, s) { dmuci_set_value_by_section(s, "bridge_key", br_key); dmuci_set_value_by_section(s, "bridge_port_instance", br_pt_inst); dmuci_set_value_by_section(s, "mg_port", mg_port); break; } } else if (strncmp(linker, "atm", 3) == 0) { - uci_foreach_option_eq("layer2_interface_adsl", "atm_bridge", "ifname", linker, s) { + uci_foreach_option_eq("dsl", "atm-device", "device", linker, s) { dmuci_set_value_by_section(s, "bridge_key", br_key); dmuci_set_value_by_section(s, "bridge_port_instance", br_pt_inst); dmuci_set_value_by_section(s, "mg_port", mg_port); @@ -390,6 +386,13 @@ int update_port_parameters(char *linker, char *br_key, char *br_pt_inst, char *m dmuci_set_value_by_section(s, "mg_port", mg_port); break; } + } else if (strncmp(linker, "eth0", 4) == 0) { + uci_foreach_option_eq("network", "device", "name", linker, s) { + dmuci_set_value_by_section(s, "bridge_key", br_key); + dmuci_set_value_by_section(s, "bridge_port_instance", br_pt_inst); + dmuci_set_value_by_section(s, "mg_port", mg_port); + break; + } } else { uci_foreach_option_eq("ports", "ethport", "ifname", linker, s) { dmuci_set_value_by_section(s, "bridge_key", br_key); @@ -397,14 +400,6 @@ int update_port_parameters(char *linker, char *br_key, char *br_pt_inst, char *m dmuci_set_value_by_section(s, "mg_port", mg_port); break; } -#ifndef EX400 - uci_foreach_option_eq("layer2_interface_ethernet", "ethernet_interface", "ifname", linker, s) { - dmuci_set_value_by_section(s, "bridge_key", br_key); - dmuci_set_value_by_section(s, "bridge_port_instance", br_pt_inst); - dmuci_set_value_by_section(s, "mg_port", mg_port); - break; - } -#endif } return 0; } @@ -415,9 +410,8 @@ int update_port_parameters(char *linker, char *br_key, char *br_pt_inst, char *m int get_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - char *br_name; - dmastrcat(&br_name, "br-", section_name(((struct bridging_args *)data)->bridge_sec)); - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", br_name, String}}, 1, &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; @@ -426,11 +420,14 @@ int get_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, 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; } @@ -438,6 +435,7 @@ int set_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, { bool b; int error = string_to_bool(value, &b); + switch (action) { case VALUECHECK: if (error) @@ -817,7 +815,6 @@ int delete_bridge(char *refparam, struct dmctx *ctx, void *data, char *instance, reset_br_port(bridgekey); dmuci_set_value_by_section(bridge_s, "ifname", ""); } - break; } return 0; @@ -941,18 +938,18 @@ int check_port_with_ifname (char * ifname, struct uci_section **ss) { struct uci_section *s; if (check_ifname_is_vlan(ifname)) { - uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "ifname", ifname, s) { + uci_foreach_option_eq("network", "device", "ifname", ifname, s) { *ss = s; break; } #ifndef EX400 } else if (strncmp(ifname, "ptm", 3) == 0) { - uci_foreach_option_eq("layer2_interface_vdsl", "vdsl_interface", "ifname", ifname, s) { + uci_foreach_option_eq("dsl", "ptm-device", "device", ifname, s) { *ss = s; break; } } else if (strncmp(ifname, "atm", 3) == 0) { - uci_foreach_option_eq("layer2_interface_adsl", "atm_bridge", "ifname", ifname, s) { + uci_foreach_option_eq("dsl", "atm-device", "device", ifname, s) { *ss = s; break; } @@ -967,12 +964,6 @@ int check_port_with_ifname (char * ifname, struct uci_section **ss) *ss = s; break; } -#ifndef EX400 - uci_foreach_option_eq("layer2_interface_ethernet", "ethernet_interface", "ifname", ifname, s) { - *ss = s; - break; - } -#endif } return 0; } @@ -985,13 +976,14 @@ int get_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *in char plinker[32]; struct uci_section *s = NULL; char lbuf[512]; - 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)) { + if (strstr(pch, "atm") || strstr(pch, "ptm") || strstr(pch, wan_baseifname)) + continue; check_port_with_ifname(pch, &s); sprintf(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); @@ -1184,11 +1176,8 @@ int browseBridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, struct uci_section *br_s = NULL; char *br_inst = NULL, *br_inst_last = NULL, *ifname; struct bridging_args curr_bridging_args = {0}; -#ifdef EX400 + dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_baseifname); -#else - dmuci_get_option_value_string("layer2_interface_ethernet", "Wan", "baseifname", &wan_baseifname); -#endif uci_foreach_option_eq("network", "interface", "type", "bridge", br_s) { br_inst = handle_update_instance(1, dmctx, &br_inst_last, update_instance_alias, 3, br_s, "bridge_instance", "bridge_alias"); dmuci_get_value_by_section_string(br_s, "ifname", &ifname); @@ -1201,12 +1190,12 @@ int browseBridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct uci_section *eth_s = NULL, *atm_s = NULL, *ptm_s = NULL, *wl_s = NULL, *vlan_s = NULL, *w_eth_s = NULL, *m_port = NULL, *new_port = NULL; + struct uci_section *eth_s = NULL, *atm_s = NULL, *ptm_s = NULL, *wl_s = NULL, *vlan_s = NULL, *w_eth_s = NULL, *new_port = NULL; char *port = NULL, *port_last = NULL, *vlan = NULL, *vlan_last = NULL; - char *ifname_dup = NULL, *pch, *spch, *vid; + char *ifname_dup = NULL, *pch, *spch; bool find_max = true; struct bridging_port_args curr_bridging_port_args = {0}; - + bool found = false; update_section_list(DMMAP,"bridge_port", "bridge_key", 1, ((struct bridging_args *)prev_data)->br_key, "mg_port", "true", "bridge_port_instance", "1"); uci_path_foreach_option_eq(icwmpd, "dmmap", "bridge_port", "bridge_key", ((struct bridging_args *)prev_data)->br_key, new_port) { init_bridging_port_args(&curr_bridging_port_args, new_port, ((struct bridging_args *)prev_data)->bridge_sec, false, ""); @@ -1218,7 +1207,7 @@ int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da 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)) { - bool found = false; + found = false; if(!found) { uci_foreach_option_eq("ports", "ethport", "ifname", pch, eth_s) { dmuci_set_value_by_section(eth_s, "bridge_key", ((struct bridging_args *)prev_data)->br_key); @@ -1234,7 +1223,7 @@ int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da } #ifndef EX400 if(!found) { - uci_foreach_option_eq("layer2_interface_adsl", "atm_bridge", "ifname", pch, atm_s) { + uci_foreach_option_eq("dsl", "atm-device", "device", pch, atm_s) { dmuci_set_value_by_section(atm_s, "bridge_key", ((struct bridging_args *)prev_data)->br_key); dmuci_set_value_by_section(atm_s, "mg_port", "false"); dmuci_set_value_by_section(atm_s, "penable", "1"); @@ -1247,7 +1236,7 @@ int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da } } if(!found) { - uci_foreach_option_eq("layer2_interface_vdsl", "vdsl_interface", "ifname", pch, ptm_s) { + uci_foreach_option_eq("dsl", "ptm-device", "device", pch, ptm_s) { dmuci_set_value_by_section(ptm_s, "bridge_key", ((struct bridging_args *)prev_data)->br_key); dmuci_set_value_by_section(ptm_s, "mg_port", "false"); dmuci_set_value_by_section(ptm_s, "penable", "1"); @@ -1261,21 +1250,20 @@ int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da } #endif if(!found) { -#ifndef EX400 - uci_foreach_option_eq("layer2_interface_ethernet", "ethernet_interface", "ifname", pch, w_eth_s) { -#else - uci_foreach_option_eq("network", "interface", "ifname", pch, w_eth_s) { -#endif - dmuci_set_value_by_section(w_eth_s, "bridge_key", ((struct bridging_args *)prev_data)->br_key); - dmuci_set_value_by_section(w_eth_s, "mg_port", "false"); - dmuci_set_value_by_section(w_eth_s, "penable", "1"); - init_bridging_port_args(&curr_bridging_port_args, w_eth_s, ((struct bridging_args *)prev_data)->bridge_sec, false, pch); - port = handle_update_instance(2, dmctx, &port_last, br_port_update_instance_alias, 5, w_eth_s, "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; - found = true ; - break; + if(strncmp(pch, wan_baseifname, strlen(wan_baseifname))==0){ + uci_foreach_option_eq("network", "device", "name", pch, w_eth_s) { //just if we are in wan eth ifname + dmuci_set_value_by_section(w_eth_s, "bridge_key", ((struct bridging_args *)prev_data)->br_key); + dmuci_set_value_by_section(w_eth_s, "mg_port", "false"); + dmuci_set_value_by_section(w_eth_s, "penable", "1"); + init_bridging_port_args(&curr_bridging_port_args, w_eth_s, ((struct bridging_args *)prev_data)->bridge_sec, false, pch); + port = handle_update_instance(2, dmctx, &port_last, br_port_update_instance_alias, 5, w_eth_s, "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; + found = true ; + break; + } } + } if(!found) { uci_foreach_option_eq("wireless", "wifi-iface", "ifname", pch, wl_s) { diff --git a/dm/dmtree/tr181/dhcp.c b/dm/dmtree/tr181/dhcp.c index ac83254..e2523c0 100644 --- a/dm/dmtree/tr181/dhcp.c +++ b/dm/dmtree/tr181/dhcp.c @@ -94,7 +94,7 @@ DMLEAF tDhcpServerPoolClientIPv4AddressParams[] = { * LINKER ***************************************************************************/ int get_dhcp_client_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - if (((struct client_args *)data)->key) { + if (data && ((struct client_args *)data)->key) { *linker = ((struct client_args *)data)->key; return 0; } else { diff --git a/dm/dmtree/tr181/ethernet.c b/dm/dmtree/tr181/ethernet.c index f2e0143..e2fc8e3 100644 --- a/dm/dmtree/tr181/ethernet.c +++ b/dm/dmtree/tr181/ethernet.c @@ -62,7 +62,7 @@ DMLEAF tEthernetStatParams[] = { * LINKER ***************************************************************************/ int get_linker_val(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - if (((struct eth_port_args *)data)->ifname) { + if (data && ((struct eth_port_args *)data)->ifname) { *linker = ((struct eth_port_args *)data)->ifname; return 0; } else { @@ -338,11 +338,8 @@ int browseEthIfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data char *int_num = NULL, *int_num_last = NULL, *ifname; struct uci_section *ss = NULL; struct eth_port_args curr_eth_port_args = {0}; -#ifndef EX400 - dmuci_get_option_value_string("layer2_interface_ethernet", "Wan", "baseifname", &wan_ifname); -#else + dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_ifname); -#endif uci_foreach_sections("ports", "ethport", ss) { dmuci_get_value_by_section_string(ss, "ifname", &ifname); if (strcmp(ifname, wan_ifname) == 0) { diff --git a/dm/dmtree/tr181/wan.c b/dm/dmtree/tr181/wan.c index a8fa784..8aa6ff9 100644 --- a/dm/dmtree/tr181/wan.c +++ b/dm/dmtree/tr181/wan.c @@ -17,6 +17,8 @@ #include "wan.h" #include "dmjson.h" +#define DSL_LINE 2 + /*** DSL. ***/ DMOBJ tDslObj[] = { /* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ @@ -132,11 +134,27 @@ DMLEAF tPtmLinkStatsParams[] = { {0} }; +enum enum_dslline_idx { + IDX_VDSL, + IDX_ADSL +}; + +struct dsl_line +{ + char *instance; + char *type; +}; + +struct dsl_line dsl_lines[DSL_LINE] = { + [IDX_VDSL] = {"1", "vdsl"}, + [IDX_ADSL] = {"2", "adsl"} +}; + /************************************************************************** * LINKER ***************************************************************************/ int get_atm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - if (((struct atm_args *)data)->ifname) { + if (data && ((struct atm_args *)data)->ifname) { *linker = ((struct atm_args *)data)->ifname; return 0; } @@ -145,7 +163,7 @@ int get_atm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instan } int get_ptm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - if (((struct ptm_args *)data)->ifname){ + if (data && ((struct ptm_args *)data)->ifname){ *linker = ((struct ptm_args *)data)->ifname; return 0; } @@ -153,7 +171,7 @@ int get_ptm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instan return 0; } int get_dsl_line_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - if (((struct dsl_line_args *)data)->type) { + if (data && ((struct dsl_line_args *)data)->type) { *linker = ((struct dsl_line_args *)data)->type; return 0; } @@ -162,7 +180,7 @@ int get_dsl_line_linker(char *refparam, struct dmctx *dmctx, void *data, char *i } int get_dsl_channel_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - if (((struct dsl_line_args *)data)->type){ + if (data && ((struct dsl_line_args *)data)->type){ *linker = ((struct dsl_line_args *)data)->type; return 0; } @@ -310,7 +328,7 @@ int get_dsl_link_downstreammaxrate(char *refparam, struct dmctx *ctx, void *data json_object *res = NULL; json_object *sub_obj = NULL; json_object *sub_obj_2 = NULL; - *value = ""; + *value = "0"; if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); @@ -333,7 +351,7 @@ int get_dsl_link_downstreamattenuation(char *refparam, struct dmctx *ctx, void * { char *attn_down_x100; json_object *res = NULL; - *value = ""; + *value = "0"; if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); @@ -350,7 +368,7 @@ int get_dsl_link_downstreamnoisemargin(char *refparam, struct dmctx *ctx, void * { char *snr_down_x100; json_object *res; - *value = ""; + *value = "0"; if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); @@ -369,7 +387,7 @@ int get_dsl_link_upstreammaxrate(char *refparam, struct dmctx *ctx, void *data, json_object *res = NULL; json_object *sub_obj = NULL; json_object *sub_obj_2 = NULL; - *value = ""; + *value = "0"; if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); @@ -390,7 +408,7 @@ int get_dsl_link_upstreamattenuation(char *refparam, struct dmctx *ctx, void *da { char *attn_up_x100; json_object *res = NULL; - *value = ""; + *value = "0"; if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); @@ -407,7 +425,7 @@ int get_dsl_link_upstreamnoisemargin(char *refparam, struct dmctx *ctx, void *da { char *snr_up_x100; json_object *res; - *value = ""; + *value = "0"; if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); @@ -477,14 +495,18 @@ int get_dsl_channel_upstreamcurrrate(char *refparam, struct dmctx *ctx, void *da int get_channel_annexm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *val = "0"; - *value = ""; + struct uci_list *v; + struct uci_element *e; + *value = "0"; + if (strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0) { - dmuci_get_option_value_string("layer2_interface", "capabilities", "AnnexM", &val); - if (val[0] != '\0') { - if (strcasecmp(val, "enabled") == 0) { - *value = "1"; - return 0; + dmuci_get_option_value_list("dsl","line","mode", &v); + if (v) { + uci_foreach_element(v, e) { + if (strcasecmp(e->name, "AnnexM") == 0) { + *value = "1"; + return 0; + } } } } @@ -493,6 +515,8 @@ int get_channel_annexm_status(char *refparam, struct dmctx *ctx, void *data, cha int set_channel_annexm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct uci_list *v; + struct uci_element *e; bool b; switch (action) { @@ -501,13 +525,23 @@ int set_channel_annexm_status(char *refparam, struct dmctx *ctx, void *data, cha return FAULT_9007; return 0; case VALUESET: - string_to_bool(value, &b); - if(b) { - dmuci_set_value("layer2_interface", "capabilities", "AnnexM", "Enabled"); + if (strcmp(((struct dsl_line_args *)data)->type, "adsl") != 0) { + return 0; + } + string_to_bool(value, &b); + + dmuci_get_option_value_list("dsl","line","mode", &v); + if (v) { + uci_foreach_element(v, e) { + if (strcasecmp(e->name, "AnnexM") == 0 && b==false) { + dmuci_del_list_value("dsl", "line", "mode", "annexm"); + return 0; + }else if(strcasecmp(e->name, "AnnexM") != 0 && b==true){ + dmuci_add_list_value("dsl", "line", "mode", "annexm"); + return 0; + } + } } - else - dmuci_set_value("layer2_interface", "capabilities", "AnnexM", ""); - return 0; } return 0; } @@ -573,20 +607,13 @@ int get_ptm_link_name(char *refparam, struct dmctx *ctx, void *data, char *insta int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *type, *encapsulation; - dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec,"link_type", &type); - if (strcmp(type, "EoA") == 0 ) { - type = "encapseoa"; - } else if (strcmp(type, "PPPoA") == 0) { - type = "encapspppoa"; - } else if (strcmp(type, "IPoA") == 0) { - type = "encapsipoa"; - } - dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, type, &encapsulation); - if (strstr(encapsulation, "vcmux")) { + char *encapsulation; + + dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "encapsulation", &encapsulation); + if (strcasecmp(encapsulation, "vcmux") == 0) { *value = "VCMUX"; } - else if (strstr(encapsulation, "llc")) { + else if (strcasecmp(encapsulation, "llc") == 0) { *value = "LLC"; } else { *value = ""; @@ -596,40 +623,22 @@ int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *i int set_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - int i; - struct uci_section *s; - char *type, *encapsulation, *encaptype, *pch; + char *encapsulation; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "link_type", &type); - int enc; - if (strstr(value, "VCMUX")) { - enc = 1; + if (strcmp(value, "VCMUX") == 0) { + encapsulation = "vcmux"; } - else if (strstr(value, "LLC")) { - enc = 0; - } - else - return 0; - if (strstr(type, "EoA")) { - encaptype = "encapseoa"; - encapsulation = enc ? "vcmux_eth" : "llcsnap_eth"; - } - else if (strstr(type, "PPPoA")) { - encaptype = "encapspppoa"; - encapsulation = enc ? "vcmux_pppoa" : "llcencaps_ppp"; - } - else if (strstr(type, "IPoA")) { - encaptype = "encapsipoa"; - encapsulation = enc ? "vcmux_ipoa" : "llcsnap_rtip"; + else if (strcmp(value, "LLC") == 0) { + encapsulation = "llc"; } else return 0; - dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, encaptype, encapsulation); + dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "encapsulation", encapsulation); return 0; } return 0; @@ -770,49 +779,40 @@ int get_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance /*************************************************************/ int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { - int idx; - char *value; - char *instance; - char ifname[16] = {0}; - char buf[16] = {0}; - struct uci_section *s = NULL; + char *instance = NULL; + char *atm_device = NULL; + char *instance_update = NULL; - idx = get_cfg_layer2idx("layer2_interface_adsl", "atm_bridge", "baseifname", sizeof("atm")-1); - sprintf(buf, "atm%d",idx); - sprintf(ifname,"%s.1",buf); - instance = get_last_instance("layer2_interface_adsl", "atm_bridge", "atmlinkinstance"); - dmuci_add_section("layer2_interface_adsl", "atm_bridge", &s, &value); - dmuci_set_value_by_section(s, "baseifname", buf); - dmuci_set_value_by_section(s, "bridge", "0"); - dmuci_set_value_by_section(s, "encapseoa", "llcsnap_eth"); - dmuci_set_value_by_section(s, "ifname", ifname); - dmuci_set_value_by_section(s, "link_type", "EoA"); - dmuci_set_value_by_section(s, "unit", buf + 3); - dmuci_set_value_by_section(s, "vci", "35"); - dmuci_set_value_by_section(s, "vpi", "8"); - *instancepara = update_instance(s, instance, "atmlinkinstance"); + instance = get_last_instance("dsl", "atm-device", "atmlinkinstance"); + dmasprintf(&atm_device, "atm%d", instance ? atoi(instance) : 0); + dmasprintf(&instance_update, "%d", instance ? atoi(instance)+ 1 : 1); + dmuci_set_value("dsl", atm_device, "", "atm-device"); + dmuci_set_value("dsl", atm_device, "name", "ATM"); + dmuci_set_value("dsl", atm_device, "vpi", "8"); + dmuci_set_value("dsl", atm_device, "vci", "35"); + dmuci_set_value("dsl", atm_device, "device", atm_device); + dmuci_set_value("dsl", atm_device, "link_type", "eoa"); + dmuci_set_value("dsl", atm_device, "encapsulation", "llc"); + dmuci_set_value("dsl", atm_device, "qos_class", "ubr"); + *instancepara = dmuci_set_value("dsl", atm_device, "atmlinkinstance", instance_update); return 0; } int add_ptm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { - int idx; - char *value; - char *instance; - char ifname[16] = {0}; - char buf[16] = {0}; - struct uci_section *s = NULL; + char *instance = NULL; + char *ptm_device = NULL; + char *instance_update = NULL; - idx = get_cfg_layer2idx("layer2_interface_vdsl", "vdsl_interface", "baseifname", sizeof("ptm")-1); - sprintf(buf,"ptm%d", idx); - sprintf(ifname,"%s.1",buf); - instance = get_last_instance("layer2_interface_vdsl", "vdsl_interface", "ptmlinkinstance"); - dmuci_add_section("layer2_interface_vdsl", "vdsl_interface", &s, &value); - dmuci_set_value_by_section(s, "baseifname", buf); - dmuci_set_value_by_section(s, "bridge", "0"); - dmuci_set_value_by_section(s, "ifname", ifname); - dmuci_set_value_by_section(s, "unit", buf + 3); - *instancepara = update_instance(s, instance, "ptmlinkinstance"); + instance = get_last_instance("dsl", "ptm-device", "ptmlinkinstance"); + dmasprintf(&ptm_device, "ptm%d", instance ? atoi(instance) : 0); + dmasprintf(&instance_update, "%d", instance ? atoi(instance)+ 1 : 1); + dmuci_set_value("dsl", ptm_device, "", "ptm-device"); + dmuci_set_value("dsl", ptm_device, "name", "PTM"); + dmuci_set_value("dsl", ptm_device, "device", ptm_device); + dmuci_set_value("dsl", ptm_device, "priority", "1"); + dmuci_set_value("dsl", ptm_device, "portid", "1"); + *instancepara = dmuci_set_value("dsl", ptm_device, "ptmlinkinstance", instance_update); return 0; } @@ -820,45 +820,45 @@ int delete_atm_link(char *refparam, struct dmctx *ctx, void *data, char *instanc { struct uci_section *s = NULL; struct uci_section *ss = NULL; - struct uci_section *ns = NULL; struct uci_section *nss = NULL; char *ifname; + switch (del_action) { case DEL_INST: dmuci_delete_by_section(((struct atm_args *)data)->atm_sec, NULL, NULL); uci_foreach_option_cont("network", "interface", "ifname", ((struct atm_args *)data)->ifname, s) { - if (ss) + if (ss && ifname!=NULL) wan_remove_dev_interface(ss, ((struct atm_args *)data)->ifname); ss = s; } - if (ss != NULL) + if (ss != NULL && ifname!=NULL) wan_remove_dev_interface(ss, ((struct atm_args *)data)->ifname); break; case DEL_ALL: - uci_foreach_sections("layer2_interface_adsl", "atm_bridge", s) { + uci_foreach_sections("dsl", "atm-device", s) { if (ss){ - dmuci_get_value_by_section_string(ss, "ifname", &ifname); + dmuci_get_value_by_section_string(ss, "device", &ifname); dmuci_delete_by_section(ss, NULL, NULL); uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) { - if (nss) + if (nss && ifname!=NULL) wan_remove_dev_interface(nss, ifname); nss = ns; } - if (nss != NULL) + if (nss != NULL && ifname!=NULL) wan_remove_dev_interface(nss, ifname); } ss = s; } if (ss != NULL) { - dmuci_get_value_by_section_string(ss, "ifname", &ifname); + dmuci_get_value_by_section_string(ss, "device", &ifname); dmuci_delete_by_section(ss, NULL, NULL); uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) { - if (nss) + if (nss && ifname!=NULL) wan_remove_dev_interface(nss, ifname); nss = ns; } - if (nss != NULL) + if (nss != NULL && ifname!=NULL) wan_remove_dev_interface(nss, ifname); } break; @@ -871,7 +871,6 @@ int delete_ptm_link(char *refparam, struct dmctx *ctx, void *data, char *instanc char *ifname; struct uci_section *s = NULL; struct uci_section *ss = NULL; - struct uci_section *ns = NULL; struct uci_section *nss = NULL; @@ -879,37 +878,37 @@ int delete_ptm_link(char *refparam, struct dmctx *ctx, void *data, char *instanc case DEL_INST: dmuci_delete_by_section(((struct ptm_args *)data)->ptm_sec, NULL, NULL); uci_foreach_option_cont("network", "interface", "ifname", ((struct ptm_args *)data)->ifname, s) { - if (ss) + if (ss && ifname!=NULL) wan_remove_dev_interface(ss, ((struct ptm_args *)data)->ifname); ss = s; } - if (ss != NULL) + if (ss != NULL && ifname!=NULL) wan_remove_dev_interface(ss, ((struct ptm_args *)data)->ifname); break; case DEL_ALL: - uci_foreach_sections("layer2_interface_vdsl", "vdsl_interface", s) { + uci_foreach_sections("dsl", "ptm-device", s) { if (ss){ - dmuci_get_value_by_section_string(ss, "ifname", &ifname); + dmuci_get_value_by_section_string(ss, "device", &ifname); dmuci_delete_by_section(ss, NULL, NULL); uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) { if (nss) wan_remove_dev_interface(nss, ifname); nss = ns; } - if (nss != NULL) + if (nss != NULL && ifname!=NULL) wan_remove_dev_interface(nss, ifname); } ss = s; } if (ss != NULL) { - dmuci_get_value_by_section_string(ss, "ifname", &ifname); + dmuci_get_value_by_section_string(ss, "device", &ifname); dmuci_delete_by_section(ss, NULL, NULL); uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) { - if (nss) + if (nss && ifname!=NULL) wan_remove_dev_interface(nss, ifname); nss = ns; } - if (nss != NULL) + if (nss != NULL && ifname!=NULL) wan_remove_dev_interface(nss, ifname); } break; @@ -994,45 +993,73 @@ int set_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, /************************************************************* * ENTRY METHOD /*************************************************************/ +int update_create_dmmap_dsl(void){ + struct uci_section *s; + char *alias; + int i; + + uci_foreach_sections("dsl", "dsl-line", s) { + uci_path_foreach_sections(icwmpd, DMMAP, "dsltype", s) { + return 1; + } + + for(i=0; iwifi_radio_sec) { + if(data && ((struct wifi_radio_args *)data)->wifi_radio_sec) { *linker = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec); return 0; } @@ -164,7 +164,7 @@ int get_linker_Wifi_Radio(char *refparam, struct dmctx *dmctx, void *data, char } int get_linker_Wifi_Ssid(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - if(((struct wifi_ssid_args *)data)->ifname) { + if(data && ((struct wifi_ssid_args *)data)->ifname) { *linker = ((struct wifi_ssid_args *)data)->ifname; return 0; } @@ -174,7 +174,7 @@ int get_linker_Wifi_Ssid(char *refparam, struct dmctx *dmctx, void *data, char * int get_linker_associated_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { struct wifi_associative_device_args* cur_wifi_associative_device_args = (struct wifi_associative_device_args*)data; - if(cur_wifi_associative_device_args->macaddress) { + if(data && cur_wifi_associative_device_args->macaddress) { *linker= cur_wifi_associative_device_args->macaddress; return 0; }