From 8e547ac1cd9efca1c69b36bb3e0d36ea3b41dd89 Mon Sep 17 00:00:00 2001 From: Imen Bhiri Date: Tue, 1 Sep 2015 13:01:11 +0100 Subject: [PATCH] Update files and add add/del object functions --- dm/dmcommon.c | 101 ++-- dm/dmcommon.h | 3 +- dm/dmtree/landevice.c | 1139 ++++++++++++++++++++++++++--------------- dm/dmtree/landevice.h | 15 +- dm/dmtree/wandevice.c | 266 ++++++++-- dm/dmtree/wandevice.h | 17 +- 6 files changed, 1029 insertions(+), 512 deletions(-) diff --git a/dm/dmcommon.c b/dm/dmcommon.c index b6fee45..8663fa2 100644 --- a/dm/dmcommon.c +++ b/dm/dmcommon.c @@ -9,6 +9,7 @@ * Author: Feten Besbes */ +#include #include #include #include @@ -18,18 +19,18 @@ #include #include "dmcwmp.h" -void compress_spaces(char *str) //REMOVE TO DMCOMMON +void compress_spaces(char *str) { - char *dst = str; - for (; *str; ++str) { - *dst++ = *str; - if (isspace(*str)) { - do ++str; - while (isspace(*str)); - --str; - } - } - *dst = '\0'; + char *dst = str; + for (; *str; ++str) { + *dst++ = *str; + if (isspace(*str)) { + do ++str; + while (isspace(*str)); + --str; + } + } + *dst = '\0'; } char *cut_fx(char *str, char *delimiter, int occurence) { @@ -45,43 +46,35 @@ char *cut_fx(char *str, char *delimiter, int occurence) pid_t get_pid(char *pname) { - DIR* dir; - struct dirent* ent; - char* endptr; - char buf[512]; + DIR* dir; + struct dirent* ent; + char* endptr; + char buf[512]; - if (!(dir = opendir("/proc"))) { - return -1; - } - - while((ent = readdir(dir)) != NULL) { - /* if endptr is not a null character, the directory is not - * entirely numeric, so ignore it */ - long lpid = strtol(ent->d_name, &endptr, 10); - if (*endptr != '\0') { - continue; - } - - /* try to open the cmdline file */ - snprintf(buf, sizeof(buf), "/proc/%ld/cmdline", lpid); - FILE* fp = fopen(buf, "r"); - - if (fp) { - if (fgets(buf, sizeof(buf), fp) != NULL) { - /* check the first token in the file, the program name */ - char* first = strtok(buf, " "); - if (strstr(first, pname)) { - fclose(fp); - closedir(dir); - return (pid_t)lpid; - } - } - fclose(fp); - } - } - - closedir(dir); - return -1; + if (!(dir = opendir("/proc"))) { + return -1; + } + while((ent = readdir(dir)) != NULL) { + long lpid = strtol(ent->d_name, &endptr, 10); + if (*endptr != '\0') { + continue; + } + snprintf(buf, sizeof(buf), "/proc/%ld/cmdline", lpid); + FILE* fp = fopen(buf, "r"); + if (fp) { + if (fgets(buf, sizeof(buf), fp) != NULL) { + char* first = strtok(buf, " "); + if (strstr(first, pname)) { + fclose(fp); + closedir(dir); + return (pid_t)lpid; + } + } + fclose(fp); + } + } + closedir(dir); + return -1; } int check_file(char *path) @@ -93,3 +86,17 @@ int check_file(char *path) } return 0; } + +char *cidr2netmask(int bits) +{ + uint32_t mask; + struct in_addr ip_addr; + uint8_t u_bits = (uint8_t)bits; + char *netmask; + char tmp[32] = {0}; + + mask = ((0xFFFFFFFFUL << (32 - u_bits)) & 0xFFFFFFFFUL); + mask = htonl(mask); + ip_addr.s_addr = mask; + return inet_ntoa(ip_addr); +} \ No newline at end of file diff --git a/dm/dmcommon.h b/dm/dmcommon.h index efd27e4..0fbf14b 100644 --- a/dm/dmcommon.h +++ b/dm/dmcommon.h @@ -21,9 +21,10 @@ do { \ } \ } while(0) +void compress_spaces(char *str); char *cut_fx(char *str, char *delimiter, int occurence); pid_t get_pid(char *pname); int check_file(char *path); -void compress_spaces(char *str); +char *cidr2netmask(int bits); #endif diff --git a/dm/dmtree/landevice.c b/dm/dmtree/landevice.c index e86eef1..defd17d 100644 --- a/dm/dmtree/landevice.c +++ b/dm/dmtree/landevice.c @@ -23,6 +23,7 @@ char *DHCPSTATICADDRESS_DISABLED_CHADDR="00:00:00:00:00:01"; struct ldlanargs { struct uci_section *ldlansection; + char *ldinstance; }; struct ldipargs @@ -54,11 +55,12 @@ struct lddhcpargs cur_dhcpargs = {0}; struct ldwlanargs cur_wlanargs = {0}; struct ldethargs cur_ethargs = {0}; -inline int init_ldargs_lan(struct dmctx *ctx, struct uci_section *s) +inline int init_ldargs_lan(struct dmctx *ctx, struct uci_section *s, char *iwan) { struct ldlanargs *args = &cur_lanargs; ctx->args = (void *)args; args->ldlansection = s; + args->ldinstance = iwan; return 0; } @@ -96,19 +98,103 @@ inline int init_ldargs_eth_cfg(struct dmctx *ctx, char *eth) args->eth = eth; } -int ip_to_int(char *address) //TODO there is already standrard function +/*******************ADD-DEL OBJECT*********************/ +int add_landevice_dhcpstaticaddress(struct dmctx *ctx, char **instancepara) { - unsigned int res; - char *pch; - pch = strtok(address,"."); - unsigned int multiple = 256 * 256 * 256; - while (pch) { - res += atoi(pch) * multiple; - multiple /=256; - pch = strtok(NULL, "."); - } - return res; + char *value; + char instance[8] = {0}; + struct uci_section *s = NULL; + struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + char *lan_name = section_name(lanargs->ldlansection); + + sprintf(instance, "%d", atoi(max_instance("dhcp", "host", "interface", "ldhcpinstance", lan_name)) + 1); + dmuci_add_section("dhcp", "host", &s, &value); + dmuci_set_value_by_section(s, "mac", DHCPSTATICADDRESS_DISABLED_CHADDR); + dmuci_set_value_by_section(s, "interface", lan_name); + dmuci_set_value_by_section(s, "ldhcpinstance", instance); + *instancepara = dmstrdup(instance); + return 0; } + +int delete_landevice_dhcpstaticaddress_all(struct dmctx *ctx) +{ + int found = 0; + char *lan_name; + struct uci_section *s = NULL; + struct uci_section *ss = NULL; + struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + + lan_name = section_name(lanargs->ldlansection); + uci_foreach_option_eq("dhcp", "host", "interface", lan_name, 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; +} + +int delete_landevice_dhcpstaticaddress(struct dmctx *ctx) +{ + struct lddhcpargs *dhcpargs = (struct lddhcpargs *)ctx->args; + + dmuci_delete_by_section(dhcpargs->lddhcpsection, NULL, NULL); + return 0; +} + +int add_landevice_wlanconfiguration(struct dmctx *ctx, char **instancepara) +{ + char *value; + char ssid[16] = {0}; + char instance[8] = {0}; + struct uci_section *s = NULL; + struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + char *lan_name = section_name(lanargs->ldlansection); + + sprintf(instance, "%d", atoi(max_instance("wireless", "wifi-iface", "network", "lwlaninstance", lan_name)) + 1); + sprintf(ssid, "Inteno_%s_%s", lan_name, instance); + 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, "network", lan_name); + dmuci_set_value_by_section(s, "ssid", ssid); + dmuci_set_value_by_section(s, "lwlaninstance", instance); + *instancepara = dmstrdup(instance); + return 0; +} + +int delete_landevice_wlanconfiguration_all(struct dmctx *ctx) +{ + int found = 0; + char *lan_name; + struct uci_section *s = NULL; + struct uci_section *ss = NULL; + struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + + lan_name = section_name(lanargs->ldlansection); + uci_foreach_option_eq("wireless", "wifi-iface", "network", lan_name, 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; +} + +int delete_landevice_wlanconfiguration(struct dmctx *ctx) +{ + struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + + dmuci_delete_by_section(wlanargs->lwlansection, NULL, NULL); + return 0; +} +/******************************************************/ /************************************************************************** **** **** function related to landevice_lanhostconfigmanagement **** **** ***************************************************************************/ @@ -136,24 +222,13 @@ int get_lan_dns(char *refparam, struct dmctx *ctx, char **value) int set_lan_dns(char *refparam, struct dmctx *ctx, int action, char *value) { - /*struct ldlanargs *lanargs = (struct ldlanargs *)args; - struct *uci_ptr = lanargs->ptr; - int i; - char *lan_name = dmstrdup(section_name(lanargs->ldlansection)); - - for(i = 0; value[i]; i++) { - if (value[i] == ',') { - value[i] = ' '; - } - } - dmuci_set_value_by_section(&uci_ptr, lanargs->ldlansection, "dns", value);*/ - // delay_service reload "network" "1" //TODO BY IBH - // delay_service reload "dnsmasq" "1" //TODO BY IBH + struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: - //TODO BY IBH + case VALUESET: + dmuci_set_value_by_section(lanargs->ldlansection, "dns", value); //TODO value=${value//,/ } return 0; } return 0; @@ -165,48 +240,50 @@ int get_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, char **v struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; uci_foreach_option_eq("dhcp", "dhcp", "interface", section_name(lanargs->ldlansection), s) { - if (s != NULL) { - TRACE("section found s name %s section type is %s \n\n", s->e.name, s->type); - *value = "1"; - return 0; - } - } - if (s == NULL) { - TRACE("no section found \n"); - *value = "0"; + TRACE("section found s name %s section type is %s \n\n", s->e.name, s->type); + *value = "1"; + return 0; } + *value = "0"; return 0; } int set_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, int action, char *value) { + static bool b; struct uci_section *s = NULL; struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; char *lan_name = section_name(lanargs->ldlansection); - //TODO switch action here VALUECHECK VALUESET???? - - uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { - if (s != NULL && value[0] == '0') { - TRACE("uci_del_section(s)"); //TODO BY FETEN - break; - } + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { + if (value[0] == '0') { + dmuci_delete_by_section(s, NULL, NULL); + break; + } + } + if (s == NULL && value[0] == '1') { + char *str_value = NULL; + str_value = "dhcp"; + dmuci_set_value("dhcp",lan_name, NULL, str_value);//check if the allocation for set value is made in uci_set_function + dmuci_set_value("dhcp", lan_name, "interface", lan_name); + str_value = "100"; + dmuci_set_value("dhcp", lan_name, "start", str_value); + str_value = "150"; + dmuci_set_value("dhcp", lan_name, "limit", str_value); + str_value = "12h"; + dmuci_set_value("dhcp", lan_name, "leasetime", str_value); + } + if (value[0] != '1' && value[0] != '0') { + return 0; + } + return 0; } - if (s == NULL && value[0] == '1') { - char *str_value = NULL; - str_value = "dhcp"; - dmuci_set_value("dhcp",lan_name, NULL, str_value);//check if the allocation for set value is made in uci_set_function - dmuci_set_value("dhcp", lan_name, "interface", lan_name); - str_value = "100"; - dmuci_set_value("dhcp", lan_name, "start", str_value); - str_value = "150"; - dmuci_set_value("dhcp", lan_name, "limit", str_value); - str_value = "12h"; - dmuci_set_value("dhcp", lan_name, "leasetime", str_value); - } - if (value[0] != '1' && value[0] != '0') { - return 0; - } return 0; } @@ -234,22 +311,29 @@ int get_lan_dhcp_server_enable(char *refparam, struct dmctx *ctx, char **value) int set_lan_dhcp_server_enable(char *refparam, struct dmctx *ctx, int action, char *value) { + static bool b; struct uci_section *s = NULL; struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; char *lan_name = section_name(lanargs->ldlansection); - //TODO switch action here VALUECHECK VALUESET???? - - uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { - if (s != NULL) { - if (value[0] == '1') - dmuci_set_value_by_section(s, "ignore", ""); - else if (value[0] == '0') - dmuci_set_value_by_section(s, "ignore", "1"); - else - return 0; - } - break; + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { + if (s != NULL) { + if (value[0] == '1') + dmuci_set_value_by_section(s, "ignore", ""); + else if (value[0] == '0') + dmuci_set_value_by_section(s, "ignore", "1"); + else + return 0; + } + break; + } + return 0; } return 0; } @@ -263,12 +347,10 @@ int get_lan_dhcp_interval_address_start(char *refparam, struct dmctx *ctx, char struct uci_section *s = NULL; uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { - if (s != NULL) { - TRACE("section start found \n"); - dmuci_get_value_by_section_string(s, "start", &start); - dmuci_get_value_by_section_string(s, "limit", &limit); - break; - } + TRACE("section start found \n"); + dmuci_get_value_by_section_string(s, "start", &start); + dmuci_get_value_by_section_string(s, "limit", &limit); + break; } if (s == NULL) { start = ""; @@ -293,7 +375,7 @@ int get_lan_dhcp_interval_address_start(char *refparam, struct dmctx *ctx, char if (res) { json_select(res, "ipv4-address", 0, "mask", &mask, NULL); mask = "TOCODE :`cidr2netmask $mask` "; - } + } } TRACE("start vaut mask %s \n", mask); if (mask[0] == '\0') { @@ -315,12 +397,10 @@ int get_lan_dhcp_interval_address_end(char *refparam, struct dmctx *ctx, char ** char *lan_name = section_name(lanargs->ldlansection); uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { - if (s != NULL) { - TRACE("section start found \n"); - dmuci_get_value_by_section_string(s, "start", &start); - dmuci_get_value_by_section_string(s, "limit", &limit); - break; - } + TRACE("section start found \n"); + dmuci_get_value_by_section_string(s, "start", &start); + dmuci_get_value_by_section_string(s, "limit", &limit); + break; } TRACE("start vaut %s and limit vaut %s \n", start, limit); if (s == NULL) { @@ -335,7 +415,6 @@ int get_lan_dhcp_interval_address_end(char *refparam, struct dmctx *ctx, char ** dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name}}, 1, &res); json_select(res, "ipv4-address", 0, "address", &ipaddr, NULL); } - TRACE("start vaut ipaddr %s \n", ipaddr); if (ipaddr[0] == '\0') { goto end; } @@ -345,7 +424,6 @@ int get_lan_dhcp_interval_address_end(char *refparam, struct dmctx *ctx, char ** json_select(res, "ipv4-address", 0, "mask", &mask, NULL); mask = "TOCODE :`cidr2netmask $mask` "; } - TRACE("start vaut mask %s \n", mask); if (mask[0] == '\0') { goto end; } @@ -358,20 +436,93 @@ end: int set_lan_dhcp_address_start(char *refparam, struct dmctx *ctx, int action, char *value) { - //TODO switch action here VALUECHECK VALUESET???? + json_object *res; + char *ipaddr, *mask, *start , *limit; + unsigned int i_ipaddr, i_mask, i_val; + struct uci_section *s = NULL; + struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + char *lan_name = section_name(lanargs->ldlansection); + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_get_value_by_section_string(lanargs->ldlansection, "ipaddr", &ipaddr); + if (ipaddr[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name}}, 1, &res); + if (res) { + json_select(res, "ipv4-address", 0, "address", &ipaddr, NULL); + if (ipaddr[0] == '\0') + return 0; + } + } + dmuci_get_value_by_section_string(lanargs->ldlansection, "netmask", &mask); + if (mask[0] == '\0') { + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name}}, 1, &res); + if (res) { + json_select(res, "ipv4-address", 0, "mask", &mask, NULL); + //mask=`cidr2netmask $mask` TO CODE + if (mask[0] == '\0') + return 0; + } + } + i_val = inet_network(value); + i_ipaddr = inet_network(ipaddr); + i_mask = inet_network(mask); + //i_val - (i_ipaddr & i_mask);//TO CHECK + if (i_val < (i_ipaddr & i_mask)) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { + dmuci_set_value_by_section(s, "start", "0"); + break; //TO CHECK + } + } + else { + uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { + dmuci_set_value_by_section(s, "start", value); + break; //TO CHECK + } + } + return 0; + } return 0; } int set_lan_dhcp_address_end(char *refparam, struct dmctx *ctx, int action, char *value) { - //TODO switch action here VALUECHECK VALUESET???? + unsigned int i_val; + char *start; + struct uci_section *s = NULL; + struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + char *lan_name = section_name(lanargs->ldlansection); + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + get_lan_dhcp_interval_address_start(refparam, ctx, &start); + if (start[0] == '\0') + return 0; + if (inet_network(start) < inet_network(value)) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { + dmuci_set_value_by_section(s, "limit", "0"); + return 0;//TO CHECK + } + } + else { + uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { + dmuci_set_value_by_section(s, "limit", value); + return 0;//TO CHECK + } + } + return 0; + } return 0; } int get_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, char **value) { char val[512] = {0}; - struct uci_section *s = NULL; + struct uci_section *s = NULL; char *min, *max, *ip, *s_n_ip; unsigned int n_min, n_max, n_ip; struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; @@ -379,12 +530,12 @@ int get_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, char **va get_lan_dhcp_interval_address_start(refparam, ctx, &min); get_lan_dhcp_interval_address_end(refparam, ctx, &max); - n_min = ip_to_int(min); - n_max = ip_to_int(max); + n_min = inet_network(min); + n_max = inet_network(max); uci_foreach_sections("dhcp", "host", s) { if (s != NULL) { dmuci_get_value_by_section_string(s, "ip", &ip); - n_ip = ip_to_int(ip); + n_ip = inet_network(ip); dmasprintf(&s_n_ip, "%u", n_ip); if (n_ip >= n_min && n_ip <= n_max) {//CONCAT IT'S BETTER TO ADD FUNCTION FOR THIS TO CHECK int len = strlen(val); @@ -404,7 +555,48 @@ int get_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, char **va int set_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, int action, char *value) { - //TODO switch action here VALUECHECK VALUESET???? + struct uci_section *s = NULL; + struct uci_section *dhcp_section = NULL; + char *min, *max, *ip, *val, *local_value; + unsigned int n_min, n_max, n_ip; + struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + char *lan_name = section_name(lanargs->ldlansection); + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + get_lan_dhcp_interval_address_start(refparam, ctx, &min); + get_lan_dhcp_interval_address_end(refparam, ctx, &max); + n_min = inet_network(min); + n_max = inet_network(max); + local_value = dmstrdup(value); + char *pch = strtok(local_value,","); + while (pch != NULL) { + uci_foreach_option_eq("dhcp", "host", "ip", pch, s) { + goto next; + } + n_ip = inet_network(ip); + if (n_ip < n_min && n_ip > n_max) + goto next; + else { + dmuci_add_section("dhcp", "host", &dhcp_section, &val); + dmuci_set_value_by_section(dhcp_section, "mac", DHCPSTATICADDRESS_DISABLED_CHADDR); + dmuci_set_value_by_section(dhcp_section, "interface", lan_name); + dmuci_set_value_by_section(dhcp_section, "ip", pch); + } + next: + pch = strtok(NULL, ","); + } + dmfree(local_value); + uci_foreach_sections("dhcp", "host", s) { + dmuci_get_value_by_section_string(s, "ip", &ip); + n_ip = inet_network(ip); + if (n_ip > n_min && n_ip < n_max) + dmuci_delete_by_section(s, NULL, NULL); + } + return 0; + } return 0; } @@ -415,12 +607,11 @@ int get_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, char **value) char *mask; json_object *res; struct uci_section *s = NULL; + char val[32]; uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { - if (s != NULL) { - dmuci_get_value_by_section_string(s, "netmask", value); - break; - } + dmuci_get_value_by_section_string(s, "netmask", value); + break; } if (s == NULL) *value = ""; @@ -431,14 +622,28 @@ int get_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, char **value) dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name}}, 1, &res); DM_ASSERT(res, *value = ""); json_select(res, "ipv4-address", 0, "mask", &mask, NULL); - *value = "TOCODE `cidr2netmask $mask`"; + int i_mask = atoi(mask); + sprintf(val, "%s", cidr2netmask(i_mask)); + *value = dmstrdup(val);// MEM WILL BE FREED IN DMMEMCLEAN } return 0; } int set_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, int action, char *value) { - //TODO switch action here VALUECHECK VALUESET???? + struct uci_section *s = NULL; + struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + char *lan_name = section_name(lanargs->ldlansection); + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { + dmuci_set_value_by_section(s, "netmask", value); + } + return 0; + } return 0; } int get_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, char **value) @@ -457,8 +662,13 @@ int set_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, int action, char * struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; char *lan_name = section_name(lanargs->ldlansection); - //TODO switch action here VALUECHECK VALUESET???? - dmuci_set_value("network", lan_name, "gateway", value); + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value("network", lan_name, "gateway", value); + return 0; + } return 0; } @@ -471,10 +681,8 @@ int get_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, char **value) char *lan_name = section_name(lanargs->ldlansection); uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { - if (s != NULL) { - dmuci_get_value_by_section_string(s, "leasetime", <ime); - break; - } + dmuci_get_value_by_section_string(s, "leasetime", <ime); + break; } if (ltime[0] == '\0') { *value = "-1"; @@ -483,7 +691,7 @@ int get_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, char **value) len = strlen(ltime)-1; if (ltime[len] != 'm') { - mtime = 3600; + mtime = 3600; if (ltime[len] != 'h') { *value = "0";//TO CHECK IF NO VALUE DO WE HAVE TO SET VALUE TO 0 return 0; @@ -502,54 +710,44 @@ int set_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, int action, char * struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; char *lan_name = section_name(lanargs->ldlansection); - //TODO switch action here VALUECHECK VALUESET???? - uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { - if (s != NULL) { - sprintf(buf, "%dm", (atoi(value) % 60)); - dmuci_set_value_by_section(s, "leasetime", buf); - break; - } - } + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { + sprintf(buf, "%dm", (atoi(value) % 60)); + dmuci_set_value_by_section(s, "leasetime", buf); + break; + } + return 0; + } return 0; } int get_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, char **value) { - char *result, *pch, *str; - char *dn = "15"; + char *result, *pch, *str; struct uci_list *val; - struct uci_section *s = NULL; + struct uci_element *e = NULL; + struct uci_section *s = NULL; struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; char *lan_name = section_name(lanargs->ldlansection); uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { - if (s) { - dmuci_get_value_by_section_list(s, "dhcp_option", &val); //val is a list - *value = "parcourir la liste"; //TODO BY IBH - /*TRACE("result is %s \n", result); - pch = strtok(result," "); - TRACE("pch is %s \n", pch); - while (pch) { - if (!strstr(pch, dn)) { - pch = strtok(NULL, " "); - continue; + dmuci_get_value_by_section_list(s, "dhcp_option", &val); + *value = ""; + if (val) { + uci_foreach_element(val, e) + { + if (strstr(e->name, "15,")) { + //*value = //get precedent //TODO + goto end; } - str = dmstrdup(pch+3); - if(!*value) - *value = dmstrdup(str); - else - dmasprintf(value, "%s --- %s", *value, str); - TRACE("value ==> %s\n", *value); - pch = strtok(NULL, " "); - break; + *value = e->name; } - goto end;*/ } } end: - /*free(str); - free(dn); - free(result);*/ return 0; } @@ -558,29 +756,33 @@ int set_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, int action, char char *result, *dn, *pch; struct uci_list *val; struct uci_section *s = NULL; + struct uci_element *e = NULL; char *option = "dhcp_option"; struct ldipargs *ipargs = (struct ldipargs *)ctx->args; char *lan_name = section_name(ipargs->ldipsection); - //TODO switch action here VALUECHECK VALUESET???? - - uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { - if (s != NULL) { - dmuci_get_value_by_section_list(s, option, &val); //TODO ADD PARCOUR DE LA LISTE - /*pch = strtok(result," "); - while (pch != NULL) { - dn = dmstrdup(cut_fx(pch, ",", 2)); //TO DO REMOVE SUBSTRING FROM STRING - if (strcmp(dn, pch) == 0) { - pch = strtok(NULL, " "); - continue; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { + dmuci_get_value_by_section_list(s, option, &val); + if (val) { + uci_foreach_element(val, e) + { + if (strstr(e->name, "15,")) { + dmuci_del_list_value_by_section(s, "dhcp_option", e->name); + goto end; + } + } } - //$UCI_DEL_LIST dhcp.$dface.dhcp_option=$dop;//TODO BY FETEN - //uci_del_list() - pch = strtok(NULL, " "); - }*/ - } - } - dmuci_add_list_value("dhcp", lan_name, "dhcp_option", "15,val");//TODO BY FETEN: ADD uci_add_list_section + break; + } + goto end; + } + +end: + dmuci_add_list_value("dhcp", lan_name, "dhcp_option", "15,val"); // delay_service reload "network" "1" // delay_service restart "dnsmasq" "1" return 0; @@ -588,41 +790,46 @@ int set_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, int action, char int get_lan_host_nbr_entries(char *refparam, struct dmctx *ctx, char **value) { - struct ldipargs *ipargs = (struct ldipargs *)ctx->args; - char *lan_name = section_name(ipargs->ldipsection); + int entries = 0; + char *network; + json_object *res; + struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + char *lan_name = section_name(lanargs->ldlansection); - //ubus call router clients | grep -c "\"network\": \"$flan\"" //TODO BY IBH - *value = "TOCODE"; + dmubus_call("router", "clients", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = "0"); + json_object_object_foreach(res, key, val) { + json_select(val, "network", 0, NULL, &network, NULL); + if (strcmp(network, lan_name) == 0) + entries++; + } + dmasprintf(value, "%d", entries); // MEM WILL BE FREED IN DMMEMCLEAN return 0; } /***************************************************************************/ -//#define DMINSTANCES(...) ## __VA_ARGS__ int filter_lan_device_interface(struct uci_section *s, void *v) { char *ifname = NULL; - char *phy_itf = NULL; + char *phy_itf = NULL, *phy_itf_local; char *pch, *ftype; dmuci_get_value_by_section_string(s, "type", &ftype); if (strcmp(ftype, "alias") != 0) { dmuci_get_value_by_section_string(s, "ifname", &ifname); - //check is physical - //char *phy_int=`db get hw.board.ethernetLanPorts`; //TODO BY IBH - //db_get_value("hw", "board", "ethernetLanPorts", &phy_itf); + db_get_value_string("hw", "board", "ethernetLanPorts", &phy_itf); //TODO KMD: copy &phy_itf to a local buf - phy_itf = "eth1 eth2 eth3 eth4"; //TODO - phy_itf = dmstrdup(phy_itf); + phy_itf_local = dmstrdup(phy_itf); TRACE("end db_get_value\n"); - pch = strtok(phy_itf," "); + pch = strtok(phy_itf_local," "); while (pch != NULL) { if (strstr(ifname, pch)) { - dmfree(phy_itf); + dmfree(phy_itf_local); return 0; } pch = strtok(NULL, " "); } - dmfree(phy_itf); + dmfree(phy_itf_local); } return -1; } @@ -634,7 +841,7 @@ int filter_lan_ip_interface(struct uci_section *ss, void *v) dmuci_get_value_by_section_string(ss, "type", &type); if (ss == lds) { return 0; - } + } else if (strcmp(type, "alias") == 0) { dmuci_get_value_by_section_string(ss, "ifname", &value); if(value[0] == 'b' && value[1] == 'r' && value[2] == '-') @@ -663,10 +870,30 @@ int get_interface_enable_ubus(char *refparam, struct dmctx *ctx, char **value) return 0; } +//REMOVE TO DMCOOMON USED BY WANDevice int set_interface_enable_ubus(char *refparam, struct dmctx *ctx, int action, char *value) { - //TODO switch action here VALUECHECK VALUESET???? - //TODO BY IBH + static bool b; + json_object *res; + char *ubus_object; + struct ldipargs *ipargs = (struct ldipargs *)ctx->args; + char *lan_name = section_name(ipargs->ldipsection); + + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + dmastrcat(&ubus_object, "network.interface.", lan_name); + if(b) { + dmubus_call(ubus_object, "up", UBUS_ARGS{}, 0, &res); + } + else + dmubus_call(ubus_object, "down", UBUS_ARGS{}, 0, &res); + dmfree(ubus_object); + return 0; + } return 0; } @@ -678,14 +905,12 @@ int get_interface_firewall_enabled(char *refparam, struct dmctx *ctx, char **val char *lan_name = section_name(ipargs->ldipsection); uci_foreach_option_cont("firewall", "zone", "network", lan_name, s) { - if (s != NULL) { - dmuci_get_value_by_section_string(s, "input", &input); - if (strcmp(input, "ACCEPT") !=0 && strcmp(input, "forward") !=0) { - *value = "1"; - return 0; - } - break; //TODO TO CHECK + dmuci_get_value_by_section_string(s, "input", &input); + if (strcmp(input, "ACCEPT") !=0 && strcmp(input, "forward") !=0) { + *value = "1"; + return 0; } + break; //TODO TO CHECK } *value = "0"; return 0; @@ -712,26 +937,28 @@ int set_interface_firewall_enabled(char *refparam, struct dmctx *ctx, int action int cnt = 0; struct uci_section *s = NULL; struct ldipargs *ipargs = (struct ldipargs *)ctx->args; - char *lan_name = section_name(ipargs->ldipsection); + char *lan_name = section_name(ipargs->ldipsection); - //TODO switch action here VALUECHECK VALUESET???? - - if (value[0] == '1') - value = "DROP"; - else if (value[0] == '0') - value = "ACCEPT"; - else - return 0; - uci_foreach_option_cont("firewall", "zone", "network", lan_name, s) { - if (s != NULL) { - dmuci_set_value_by_section(s, "input", value); - dmuci_set_value_by_section(s, "forward", value); - cnt++; - } + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (value[0] == '1') + value = "DROP"; + else if (value[0] == '0') + value = "ACCEPT"; + else + return 0; + uci_foreach_option_cont("firewall", "zone", "network", lan_name, s) { + dmuci_set_value_by_section(s, "input", value); + dmuci_set_value_by_section(s, "forward", value); + cnt++; + } + if (cnt == 0 && strcmp(value,"DROP") ==0) + create_firewall_zone_config("fwl", lan_name, "DROP", "DROP", ""); + //delay_service reload "firewall" "1" //TODO BY IBH + return 0; } - if (cnt == 0 && strcmp(value,"DROP") ==0) - create_firewall_zone_config("fwl", lan_name, "DROP", "DROP", ""); - //delay_service reload "firewall" "1" //TODO BY IBH return 0; } @@ -739,7 +966,7 @@ int set_interface_firewall_enabled(char *refparam, struct dmctx *ctx, int action int get_interface_ipaddress(char *refparam, struct dmctx *ctx, char **value) { char *proto; - json_object *res; + json_object *res; struct ldipargs *ipargs = (struct ldipargs *)ctx->args;//TO CHECK char *lan_name = section_name(ipargs->ldipsection); @@ -749,7 +976,7 @@ int get_interface_ipaddress(char *refparam, struct dmctx *ctx, char **value) else { dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name}}, 1, &res); DM_ASSERT(res, *value = ""); - json_select(res, "ipv4-address", 0, "address", value, NULL); + json_select(res, "ipv4-address", 0, "address", value, NULL); } return 0; } @@ -758,11 +985,16 @@ int set_interface_ipaddress(char *refparam, struct dmctx *ctx, int action, char { struct ldipargs *ipargs = (struct ldipargs *)ctx->args; - //TODO switch action here VALUECHECK VALUESET???? - char *lan_name = section_name(ipargs->ldipsection); - if (value[0] != '\0') { - dmuci_set_value_by_section(ipargs->ldipsection, "ipaddr", value); + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (value[0] != '\0') { + dmuci_set_value_by_section(ipargs->ldipsection, "ipaddr", value); + } + return 0; } return 0; } @@ -772,7 +1004,8 @@ int get_interface_subnetmask(char *refparam, struct dmctx *ctx, char **value) struct ldipargs *ipargs = (struct ldipargs *)ctx->args; char *proto; char *val = NULL; - json_object *res; + json_object *res; + char tmp[32]; char *lan_name = section_name(ipargs->ldipsection); dmuci_get_value_by_section_string(ipargs->ldipsection, "proto", &proto); @@ -781,7 +1014,8 @@ int get_interface_subnetmask(char *refparam, struct dmctx *ctx, char **value) else { dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name}}, 1, &res); json_select(res, "ipv4-address", 0, "mask", &val, NULL); - *value = "cidr2netmask $val"; //TODO ADD THIS FUNCTION + sprintf(tmp, "%s", cidr2netmask(atoi(val))); + *value = dmstrdup(tmp); // MEM WILL BE FREED IN DMMEMCLEAN } return 0; } @@ -790,10 +1024,14 @@ int set_interface_subnetmask(char *refparam, struct dmctx *ctx, int action, char { struct ldipargs *ipargs = (struct ldipargs *)ctx->args; - //TODO switch action here VALUECHECK VALUESET???? - - if (value[0] != '\0') { - dmuci_set_value_by_section(ipargs->ldipsection, "netmask", value); + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (value[0] != '\0') { + dmuci_set_value_by_section(ipargs->ldipsection, "netmask", value); + } + return 0; } return 0; } @@ -814,14 +1052,18 @@ int set_interface_addressingtype(char *refparam, struct dmctx *ctx, int action, { struct ldipargs *ipargs = (struct ldipargs *)ctx->args; - //TODO switch action here VALUECHECK VALUESET???? - - if (strcmp(value, "Static") == 0) - dmuci_set_value_by_section(ipargs->ldipsection, "proto", "static"); - else if (strcmp(value, "DHCP") == 0) - dmuci_set_value_by_section(ipargs->ldipsection, "proto", "dhcp"); - else - return 0; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "Static") == 0) + dmuci_set_value_by_section(ipargs->ldipsection, "proto", "static"); + else if (strcmp(value, "DHCP") == 0) + dmuci_set_value_by_section(ipargs->ldipsection, "proto", "dhcp"); + else + return 0; + return 0; + } return 0; } @@ -845,28 +1087,35 @@ int get_dhcpstaticaddress_enable (char *refparam, struct dmctx *ctx, char **valu int set_dhcpstaticaddress_enable(char *refparam, struct dmctx *ctx, int action, char *value) { char *chaddr; + static bool b; struct lddhcpargs *dhcpargs = (struct lddhcpargs *)ctx->args; - //TODO switch action here VALUECHECK VALUESET???? - - dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac", &chaddr); - if (value[0] == '1' && value[1] == '\0') { - if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) { - char *orig_chaddr; - dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac_orig", &orig_chaddr); - dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac", orig_chaddr); - } else { + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; return 0; - } - } else if (value[0] == '0' && value[1] == '\0') { - if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) + case VALUESET: + dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac", &chaddr); + if (value[0] == '1' && value[1] == '\0') { + if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) { + char *orig_chaddr; + dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac_orig", &orig_chaddr); + dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac", orig_chaddr); + } else { + return 0; + } + } else if (value[0] == '0' && value[1] == '\0') { + if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) + return 0; + else { + char *orig_chaddr; + dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac_orig", &orig_chaddr); + dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac_orig", orig_chaddr); + dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac", DHCPSTATICADDRESS_DISABLED_CHADDR); + } + } return 0; - else { - char *orig_chaddr; - dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac_orig", &orig_chaddr); - dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac_orig", orig_chaddr); - dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac", DHCPSTATICADDRESS_DISABLED_CHADDR); - } } return 0; } @@ -890,9 +1139,9 @@ int set_dhcpstaticaddress_chaddr(char *refparam, struct dmctx *ctx, int action, struct lddhcpargs *dhcpargs = (struct lddhcpargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac", &chaddr); if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac_orig", value); @@ -915,9 +1164,9 @@ int set_dhcpstaticaddress_yiaddr(char *refparam, struct dmctx *ctx, int action, struct lddhcpargs *dhcpargs = (struct lddhcpargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_set_value_by_section(dhcpargs->lddhcpsection, "ip", value); } return 0; @@ -933,11 +1182,11 @@ int get_lan_ethernet_interfaces(char *ndev, char *iface[], int var, int *length) { int i = 0; int index = 0; - char *name, *value; + char *name, *value; json_object *res = NULL; dmastrcat(&name, "br-", ndev); - dmubus_call("network.device", "status", UBUS_ARGS{{"name", name}}, 1, &res); //TO CHECK WITH FETEN IF NO RES !!!!!! + dmubus_call("network.device", "status", UBUS_ARGS{{"name", name}}, 1, &res); //TODO DM UBUS ASSERT if (res == NULL) { iface[0] = ndev; @@ -966,7 +1215,7 @@ int get_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, char **value struct ldethargs *ethargs = (struct ldethargs *)ctx->args; //dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "ip", value); - dmubus_call("network.device", "status", UBUS_ARGS{{"name", ethargs->eth}}, 1, &res); //TO CHECK WITH FETEN IF NO RES !!!!!! + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ethargs->eth}}, 1, &res); DM_ASSERT(res, *value = ""); int i = json_select(res, "link", -1, NULL, value, NULL); if (i == -1) @@ -980,11 +1229,11 @@ int set_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, int action, struct ldethargs *ethargs = (struct ldethargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: if (string_to_bool(value, &b)) return FAULT_9007; return 0; - VALUESET: + case VALUESET: if (b) { TRACE("ethctl ethargs->eth phy-power up"); //LINUX CMD } @@ -1039,9 +1288,9 @@ int set_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, int acti struct ldethargs *ethargs = (struct ldethargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: if (strcasecmp(value, "auto") == 0) { dmuci_set_value("ports", "@ethports[0]", ethargs->eth, "auto"); return 0; @@ -1061,7 +1310,6 @@ int set_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, int acti dmuci_set_value("ports", "@ethports[0]", ethargs->eth, val); dmfree(val); } - } return 0; } @@ -1095,9 +1343,9 @@ int set_lan_eth_iface_cfg_duplexmode(char *refparam, struct dmctx *ctx, int acti struct ldethargs *ethargs = (struct ldethargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: if (strcasecmp(value, "auto") == 0) { dmuci_set_value("ports", "@ethports[0]", ethargs->eth, "auto"); return 0; @@ -1173,9 +1421,9 @@ inline int get_landevice_ethernet_interface_config(struct dmctx *ctx, char *idev { DMOBJECT(DMROOT"LANDevice.%s.LANEthernetInterfaceConfig.%s.", ctx, "0", 1, NULL, NULL, NULL, idev, ieth); DMPARAM("Enable", ctx, "1", get_lan_eth_iface_cfg_enable, set_lan_eth_iface_cfg_enable, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_lan_eth_iface_cfg_status, NULL, "", 0, 0, UNDEF, NULL); - DMPARAM("MaxBitRate", ctx, "1", get_lan_eth_iface_cfg_maxbitrate, set_lan_eth_iface_cfg_maxbitrate, "", 0, 0, UNDEF, NULL); - DMPARAM("DuplexMode", ctx, "1", get_lan_eth_iface_cfg_duplexmode, set_lan_eth_iface_cfg_duplexmode, "", 0, 0, UNDEF, NULL); + DMPARAM("Status", ctx, "0", get_lan_eth_iface_cfg_status, NULL, NULL, 0, 0, UNDEF, NULL); + DMPARAM("MaxBitRate", ctx, "1", get_lan_eth_iface_cfg_maxbitrate, set_lan_eth_iface_cfg_maxbitrate, NULL, 0, 0, UNDEF, NULL); + DMPARAM("DuplexMode", ctx, "1", get_lan_eth_iface_cfg_duplexmode, set_lan_eth_iface_cfg_duplexmode, NULL, 0, 0, UNDEF, NULL); DMOBJECT(DMROOT"LANDevice.%s.LANEthernetInterfaceConfig.%s.Stats.", ctx, "0", 1, NULL, NULL, NULL, idev, ieth); DMPARAM("BytesSent", ctx, "0", get_lan_eth_iface_cfg_stats_tx_bytes, NULL, "xsd:unsignedInt", 0, 0, UNDEF, NULL); DMPARAM("BytesReceived", ctx, "0", get_lan_eth_iface_cfg_stats_rx_bytes, NULL, "xsd:unsignedInt", 0, 0, UNDEF, NULL); @@ -1209,31 +1457,34 @@ int entry_method_root_LANDevice(struct dmctx *ctx) uci_foreach_filter_func("network", "interface", NULL, &filter_lan_device_interface, s) { TRACE("section type %s section name %s \n\n", s->e.name, s->type); //DMOBJECT(DMROOT"LANDevice.%s.", ctx, "0", 1, NULL, NULL, NULL, DMINSTANCES(idev, idev2)); - init_ldargs_lan(ctx, s); - idev = update_instance(s, cur_idev, "ldinstance"); + idev = update_instance(s, cur_idev, "ldinstance"); + init_ldargs_lan(ctx, s, idev); DMOBJECT(DMROOT"LANDevice.%s.", ctx, "0", 0, NULL, NULL, NULL, idev); DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.", ctx, "0", 1, NULL, NULL, NULL, idev); - DMPARAM("DNSServers", ctx, "1", get_lan_dns, set_lan_dns, "", 0, 0, UNDEF, NULL); + DMPARAM("DNSServers", ctx, "1", get_lan_dns, set_lan_dns, NULL, 0, 0, UNDEF, NULL); DMPARAM("DHCPServerConfigurable", ctx, "1", get_lan_dhcp_server_configurable, set_lan_dhcp_server_configurable, "xsd:boolean", 0, 0, UNDEF, NULL); DMPARAM("DHCPServerEnable", ctx, "1", get_lan_dhcp_server_enable, set_lan_dhcp_server_enable, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("MinAddress", ctx, "1", get_lan_dhcp_interval_address_start, set_lan_dhcp_address_start, "", 0, 0, UNDEF, NULL); - DMPARAM("MaxAddress", ctx, "1", get_lan_dhcp_interval_address_end, set_lan_dhcp_address_end, "", 0, 0, UNDEF, NULL); - DMPARAM("ReservedAddresses", ctx, "1", get_lan_dhcp_reserved_addresses, set_lan_dhcp_reserved_addresses, "", 0, 0, UNDEF, NULL); - DMPARAM("SubnetMask", ctx, "1", get_lan_dhcp_subnetmask, set_lan_dhcp_subnetmask, "", 0, 0, UNDEF, NULL); - DMPARAM("IPRouters", ctx, "1", get_lan_dhcp_iprouters, set_lan_dhcp_iprouters, "", 0, 0, UNDEF, NULL); - DMPARAM("DHCPLeaseTime", ctx, "1", get_lan_dhcp_leasetime, set_lan_dhcp_leasetime, "", 0, 0, UNDEF, NULL); - DMPARAM("DomainName", ctx, "1", get_lan_dhcp_domainname, set_lan_dhcp_domainname, "", 0, 0, UNDEF, NULL); + DMPARAM("MinAddress", ctx, "1", get_lan_dhcp_interval_address_start, set_lan_dhcp_address_start, NULL, 0, 0, UNDEF, NULL); + DMPARAM("MaxAddress", ctx, "1", get_lan_dhcp_interval_address_end, set_lan_dhcp_address_end, NULL, 0, 0, UNDEF, NULL); + DMPARAM("ReservedAddresses", ctx, "1", get_lan_dhcp_reserved_addresses, set_lan_dhcp_reserved_addresses, NULL, 0, 0, UNDEF, NULL); + DMPARAM("SubnetMask", ctx, "1", get_lan_dhcp_subnetmask, set_lan_dhcp_subnetmask, NULL, 0, 0, UNDEF, NULL); + DMPARAM("IPRouters", ctx, "1", get_lan_dhcp_iprouters, set_lan_dhcp_iprouters, NULL, 0, 0, UNDEF, NULL); + DMPARAM("DHCPLeaseTime", ctx, "1", get_lan_dhcp_leasetime, set_lan_dhcp_leasetime, NULL, 0, 0, UNDEF, NULL); + DMPARAM("DomainName", ctx, "1", get_lan_dhcp_domainname, set_lan_dhcp_domainname, NULL, 0, 0, UNDEF, NULL); DMOBJECT(DMROOT"LANDevice.%s.Hosts.", ctx, "0", 0, NULL, NULL, NULL, idev); DMPARAM("HostNumberOfEntries", ctx, "0", get_lan_host_nbr_entries, NULL, "xsd:unsignedInt", 0, 0, UNDEF, NULL); + //HOST DYNAMIC + DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.IPInterface.", ctx, "0", 1, NULL, NULL, NULL, idev); - DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPStaticAddress.", ctx, "1", 1, NULL, NULL, NULL, idev); + DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPStaticAddress.", ctx, "1", 1, add_landevice_dhcpstaticaddress, delete_landevice_dhcpstaticaddress_all, NULL, idev); cur_ilan = NULL; uci_foreach_filter_func("network", "interface", s, filter_lan_ip_interface, ss) { ilan = update_instance(ss, cur_ilan, "lipinstance"); init_ldargs_ip(ctx, ss); SUBENTRY(get_landevice_lanhostconfigmanagement_ipinterface, ctx, idev, ilan); //ndev is not used //nlan can be passed as cur_idhcp = NULL; - uci_foreach_option_cont("dhcp", "dhcp", "interface", section_name(ss), sss) { + //uci_foreach_option_cont("dhcp", "dhcp", "interface", section_name(ss), sss) { TOCHECK + uci_foreach_option_cont("dhcp", "host", "interface", section_name(ss), sss) { idhcp = update_instance(sss, cur_idhcp, "ldhcpinstance"); init_ldargs_dhcp(ctx, sss); SUBENTRY(get_landevice_lanhostconfigmanagement_dhcpstaticaddress, ctx, idev, idhcp); @@ -1245,7 +1496,7 @@ int entry_method_root_LANDevice(struct dmctx *ctx) cur_ilan = dmstrdup(ilan); } dmfree(cur_ilan); - DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.", ctx, "0", 0, NULL, NULL, NULL, idev); + DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.", ctx, "0", 0, add_landevice_wlanconfiguration, delete_landevice_wlanconfiguration_all, NULL, idev); uci_foreach_sections("wireless", "wifi-device", ss) { int wlctl_num=0; cur_iwlan = NULL; @@ -1301,11 +1552,11 @@ int set_wlan_enable(char *refparam, struct dmctx *ctx, int action, char *value) static bool b; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: if (string_to_bool(value, &b)) return FAULT_9007; return 0; - VALUESET: + case VALUESET: if (b) value = "0"; else @@ -1327,8 +1578,9 @@ int get_wlan_status (char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_wlan_bssid (char *refparam, struct dmctx *ctx, char **value) +int get_wlan_bssid(char *refparam, struct dmctx *ctx, char **value) { + json_object *res; char *wunit, buf[8]; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; @@ -1337,7 +1589,9 @@ int get_wlan_bssid (char *refparam, struct dmctx *ctx, char **value) sprintf(buf, "%s.%d", wunit, wlanargs->wlctl_num); wunit = buf; } - *value = "`/usr/sbin/wlctl -i $wunit bssid`"; //TODO GET THE EQUIVALENT UBUS CMD OR LINUX CMD + dmubus_call("router", "wl", UBUS_ARGS{{"vif", wunit}}, 1, &res); + DM_ASSERT(res, *value = ""); + json_select(res, "bssid", 0, NULL, value, NULL); return 0; } @@ -1354,9 +1608,9 @@ int set_wlan_max_bit_rate(char *refparam, struct dmctx *ctx, int action, char *v struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_set_value("wireless", wlanargs->wunit, "hwmode", value); } return 0; @@ -1364,11 +1618,16 @@ int set_wlan_max_bit_rate(char *refparam, struct dmctx *ctx, int action, char *v int get_wlan_channel(char *refparam, struct dmctx *ctx, char **value) { + json_object *res; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; dmuci_get_option_value_string("wireless", wlanargs->wunit, "channel", value); - if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') - *value = "`/usr/sbin/wlctl -i $wunit channel|grep \"target channel\"|awk -F ' ' '{print$3}'`"; //TODO LINUX EQUIVALENT COMMAND + if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') { + //*value = "`/usr/sbin/wlctl -i $wunit channel|grep \"target channel\"|awk -F ' ' '{print$3}'`"; + dmubus_call("router", "wl", UBUS_ARGS{{"vif", wlanargs->wunit}}, 1, &res); + DM_ASSERT(res, *value =""); + json_select(res, "channel", 0, NULL, value, NULL); + } return 0; } @@ -1377,9 +1636,9 @@ int set_wlan_channel(char *refparam, struct dmctx *ctx, int action, char *value) struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_set_value("wireless", wlanargs->wunit, "channel", value); } return 0; @@ -1400,18 +1659,25 @@ int get_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, char **value int set_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, int action, char *value) { static bool b; + json_object *res; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: if (string_to_bool(value, &b)) return FAULT_9007; return 0; - VALUESET: + case VALUESET: if (b) value = "auto"; - else - value = "`/usr/sbin/wlctl -i $wunit channel|grep \"target channel\"|awk -F ' ' '{print$3}'`";//TODO LINUX EQUIVALENT COMMANDE + else { + //value = "`/usr/sbin/wlctl -i $wunit channel|grep \"target channel\"|awk -F ' ' '{print$3}'`"; + dmubus_call("router", "wl", UBUS_ARGS{{"vif", wlanargs->wunit}}, 1, &res); + if(res == NULL) + value = ""; + else + json_select(res, "channel", 0, NULL, &value, NULL); + } dmuci_set_value("wireless", wlanargs->wunit, "channel", value); } return 0; @@ -1430,9 +1696,9 @@ int set_wlan_ssid(char *refparam, struct dmctx *ctx, int action, char *value) struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_set_value_by_section(wlanargs->lwlansection, "ssid", value); } return 0; @@ -1490,9 +1756,9 @@ int set_wlan_beacon_type(char *refparam, struct dmctx *ctx, int action, char *va char strk64[4][11]; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(value, "None") != 0) { value = "none"; @@ -1552,8 +1818,7 @@ int set_wlan_beacon_type(char *refparam, struct dmctx *ctx, int action, char *va } dmuci_set_value_by_section(wlanargs->lwlansection, "encryption", "value"); } - //delay_service reload "network" "1" //TODO BY IBH - } + } return 0; } @@ -1575,11 +1840,11 @@ int set_wlan_mac_control_enable(char *refparam, struct dmctx *ctx, int action, c struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: if (string_to_bool(value, &b)) return FAULT_9007; return 0; - VALUESET: + case VALUESET: if (b) value = "2"; else @@ -1611,9 +1876,9 @@ int set_wlan_standard(char *refparam, struct dmctx *ctx, int action, char *value struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: if (strcmp(value, "b") == 0) value = "11b"; else if (strcmp(value, "g") == 0) @@ -1646,11 +1911,10 @@ int set_wlan_wep_key_index(char *refparam, struct dmctx *ctx, int action, char * struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); - //delay_service reload "network" "1" TODO BY IBH if (strcmp(encryption, "wep-shared") != 0 && strcmp(encryption, "wep-open") != 0) { reset_wlan(wlanargs->lwlansection); @@ -1676,9 +1940,9 @@ int set_wlan_key_passphrase(char *refparam, struct dmctx *ctx, int action, char struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(encryption, "wep-shared") == 0 || strcmp(encryption, "wep-open") == 0) { wepkey64("Inteno", strk64); @@ -1694,7 +1958,7 @@ int set_wlan_key_passphrase(char *refparam, struct dmctx *ctx, int action, char else set_wlan_pre_shared_key(refparam, ctx, action, value); //TODO CHECK } - return 0; + return 0; } int get_wlan_wep_encryption_level(char *refparam, struct dmctx *ctx, char **value) @@ -1724,9 +1988,9 @@ int set_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, int actio struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(value, "WEPEncryption") == 0) { if (strcmp(encryption, "wep-shared") != 0 && strcmp(encryption, "wep-open") != 0) { @@ -1739,7 +2003,7 @@ int set_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, int actio dmuci_set_value_by_section(wlanargs->lwlansection, option, strk64[i]); dmfree(option); i++; - } + } dmuci_set_value_by_section(wlanargs->lwlansection, "encryption", value); } } else if (strcmp(value, "None") == 0) { @@ -1770,9 +2034,9 @@ int set_wlan_basic_authentication_mode(char *refparam, struct dmctx *ctx, int ac struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(value, "SharedAuthentication") == 0) { if (strcmp(encryption, "wep-shared") != 0 && strcmp(encryption, "wep-open") != 0) { @@ -1818,9 +2082,9 @@ int set_wlan_wpa_encryption_modes(char *refparam, struct dmctx *ctx, int action, struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(value, "TKIPEncryption") == 0) { if(!strstr(encryption, "psk")) { @@ -1876,9 +2140,9 @@ int set_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, int acti struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(value, "PSKAuthentication") == 0) { if (!strstr(encryption, "psk")) { @@ -1899,7 +2163,7 @@ int set_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, int acti } dmuci_set_value_by_section(wlanargs->lwlansection, "encryption", "wpa"); } - } + } return 0; } @@ -1926,9 +2190,9 @@ int set_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, int ac struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(value, "TKIPEncryption") == 0) { if (!strstr(encryption, "psk")) { @@ -1963,7 +2227,7 @@ int set_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, int ac } dmuci_set_value_by_section(wlanargs->lwlansection, "encryption", "psk2+tkip+ccmp"); } - } + } return 0; } @@ -1987,9 +2251,9 @@ int set_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, int struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(value, "PSKAuthentication") == 0) { if (!strstr(encryption, "psk")) { @@ -2018,7 +2282,8 @@ int set_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, int int get_wlan_radio_enabled(char *refparam, struct dmctx *ctx, char **value) { int val; - char *wunit, buf[8]; + json_object *res; + char *wunit, *radio, buf[8]; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; *value = ""; @@ -2029,8 +2294,10 @@ int get_wlan_radio_enabled(char *refparam, struct dmctx *ctx, char **value) else { wunit = wlanargs->wunit; } - char *radio = "`/usr/sbin/wlctl -i $wunit radio`"; //TODO GET THE EQUIVALENT UBUS CMD OR LINUX CMD - //convert hex to decimal + //char *radio = "`/usr/sbin/wlctl -i $wunit radio`"; + dmubus_call("router", "wl", UBUS_ARGS{{"vif", wunit}}, 1, &res); + DM_ASSERT(res, *value = dmstrdup("")); //TO CHECK + json_select(res, "radio", 0, NULL, &radio, NULL); sscanf(radio, "%x", &val); if (val == 0) *value = "1"; @@ -2046,11 +2313,11 @@ int set_wlan_radio_enabled(char *refparam, struct dmctx *ctx, int action, char * struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: if (string_to_bool(value, &b)) return FAULT_9007; return 0; - VALUESET: + case VALUESET: if (!b) value = "off"; else @@ -2083,9 +2350,9 @@ int set_wlan_device_operation_mode(char *refparam, struct dmctx *ctx, int action struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: if (strcmp(value, "InfrastructureAccessPoint") == 0) dmuci_set_value_by_section(wlanargs->lwlansection, "mode", "ap"); } @@ -2111,9 +2378,9 @@ int set_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, int struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(value, "None") == 0) { reset_wlan(wlanargs->lwlansection); @@ -2134,6 +2401,8 @@ int set_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, int int get_wlan_total_associations(char *refparam, struct dmctx *ctx, char **value) { + int i = 0; + json_object *res; char *wunit, buf[8]; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; @@ -2143,7 +2412,14 @@ int get_wlan_total_associations(char *refparam, struct dmctx *ctx, char **value) } else wunit = wlanargs->wunit; - *value = "`/usr/sbin/wlctl -i $wunit assoclist | grep -c 'assoclist'`";//TODO ADD LINUX CMD + dmubus_call("router", "sta", UBUS_ARGS{{"vif", wunit}}, 1, &res); + DM_ASSERT(res, *value = "0"); //TO CHECK + json_object_object_foreach(res, key, val) { + TRACE("TotalAssociations json obj %s\n", key); + if (strstr(key, "sta-")) + i++; + } + dmasprintf(value, "%d", i); // MEM WILL BE FREED IN DMMEMCLEAN return 0; } @@ -2240,16 +2516,15 @@ int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, int ac struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: if (string_to_bool(value, &b)) return FAULT_9007; return 0; - VALUESET: + case VALUESET: if (b) dmuci_set_value_by_section(wlanargs->lwlansection, "hidden", ""); else dmuci_set_value_by_section(wlanargs->lwlansection, "hidden", "1"); - } return 0; } @@ -2273,11 +2548,11 @@ int set_wlan_wps_enable(char *refparam, struct dmctx *ctx, int action, char *val struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: if (string_to_bool(value, &b)) return FAULT_9007; return 0; - VALUESET: + case VALUESET: if (b) dmuci_set_value_by_section(wlanargs->lwlansection, "wps_pbc", "1"); else @@ -2301,28 +2576,39 @@ int get_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, char **value) int set_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, int action, char *value) { char *channel; + json_object *res; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: if (strcmp(value, "Auto")) dmuci_set_value("wireless", wlanargs->wunit, "channel", "auto"); - else if (strcmp(value, "Manual")) - channel = "`/usr/sbin/wlctl -i $wunit channel |grep \"target channel\" |awk -F ' ' '{print$3}'`"; //TODO GET LINUX CMD - dmuci_set_value("wireless", wlanargs->wunit, "channel", channel); + else if (strcmp(value, "Manual")) { + dmubus_call("router", "wl", UBUS_ARGS{{"vif", wlanargs->wunit}}, 1, &res); + //DM_ASSERT(res, *value = dmstrdup("")); + if (res != NULL) { + json_select(res, "channel", 0, NULL, &channel, NULL); + dmuci_set_value("wireless", wlanargs->wunit, "channel", channel); + } + } } - return 0; } int get_x_inteno_se_supported_standard(char *refparam, struct dmctx *ctx, char **value) { + char *freq; + json_object *res; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; - char *status = "";// `wlctl -i wlanargs->wunit status |awk '$1==""Chanspec:" {print$2}'` //TODO LINUX EQUIVALENT CMD - if (strcmp(status, "5GHz") == 0) + + // `wlctl -i wlanargs->wunit status |awk '$1==""Chanspec:" {print$2}'` + dmubus_call("router", "wl", UBUS_ARGS{{"vif", wlanargs->wunit}}, 1, &res); + DM_ASSERT(res, *value = "b, g, n, gst, lrs"); + json_select(res, "frequency", 0, NULL, &freq, NULL); + if (strcmp(freq, "5") == 0) *value = "a, n, ac"; else *value = "b, g, n, gst, lrs"; @@ -2331,12 +2617,18 @@ int get_x_inteno_se_supported_standard(char *refparam, struct dmctx *ctx, char * int get_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, char **value) { + char *bandwith; + json_object *res; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; dmuci_get_option_value_string("wireless", wlanargs->wunit, "bandwidth", value); if (value[0] == '\0') - *value = "LINUX EQUIVALENT CMD"; //`wlctl -i wlanargs->wunit status |awk '$1=="Chanspec:" {print$5}'` //TODO LINUX EQUIVALENT CMD - //echo "${val//[^0-9]/}""MHz" //TODO LINUX EQUIVALENT CMD + { + dmubus_call("router", "wl", UBUS_ARGS{{"vif", wlanargs->wunit}}, 1, &res); + DM_ASSERT(res, *value = dmstrdup("MHz")); + json_select(res, "bandwidth", 0, NULL, &bandwith, NULL); + dmastrcat(value, bandwith, "MHz"); // MEM WILL BE FREED IN DMMEMCLEAN + } return 0; } @@ -2346,9 +2638,9 @@ int set_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ct struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: x = (int)strtol(value, (char **)NULL, 10); dmasprintf(&value, "%d", x);//TODO CHECK if ((value[0] == '0' && value[1] == '\0') || value[0] == '\0') { @@ -2357,7 +2649,7 @@ int set_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ct } dmuci_set_value("wireless", wlanargs->wunit, "bandwidth", value); dmfree(value); - } + } return 0; } @@ -2374,30 +2666,64 @@ int set_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, int action, char struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_set_value_by_section(wlanargs->lwlansection, "bss_max", value); } return 0; } -//TODO TO CODE -int set_wlan_wep_key(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_wep_key(char *refparam, struct dmctx *ctx, int action, char *value, char *key_index) { + char *encryption, *option; + char strk64[4][11]; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: - //uci_set_value_section(wlanargs->lwlansection, "bss_max", value); + case VALUESET: + dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); + if (strcmp(encryption, "wep-shared") != 0 && strcmp(encryption, "wep-open") != 0) { + reset_wlan(wlanargs->lwlansection); + dmuci_set_value_by_section(wlanargs->lwlansection, "encryption", "wep-open"); + wepkey64("Inteno", strk64); + int i = 0; + while (i < 4) { + dmasprintf(&option, "key%d", i + 1); + dmuci_set_value_by_section(wlanargs->lwlansection, option, strk64[i++]); + dmfree(option); + i++; + } + dmuci_set_value_by_section(wlanargs->lwlansection, "key", "1"); + } + dmuci_set_value_by_section(wlanargs->lwlansection, key_index, value); return 0; } return 0; } +int set_wlan_wep_key1(char *refparam, struct dmctx *ctx, int action, char *value) +{ + return set_wlan_wep_key(refparam, ctx, action, value, "key1"); +} + +int set_wlan_wep_key2(char *refparam, struct dmctx *ctx, int action, char *value) +{ + return set_wlan_wep_key(refparam, ctx, action, value, "key2"); +} + +int set_wlan_wep_key3(char *refparam, struct dmctx *ctx, int action, char *value) +{ + return set_wlan_wep_key(refparam, ctx, action, value, "key3"); +} + +int set_wlan_wep_key4(char *refparam, struct dmctx *ctx, int action, char *value) +{ + return set_wlan_wep_key(refparam, ctx, action, value, "key4"); +} /****************************************************************************************/ /*int filter_wlan_interface (struct uci_section *sss, void *v) @@ -2417,70 +2743,72 @@ inline int get_landevice_lanhostconfigmanagement_ipinterface (struct dmctx *ctx, DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.IPInterface.%s.", ctx, "0", 1, NULL, NULL, section_name(ipargs->ldipsection), idev, ilan);//TO CHECK "linker_interface:$nlan" DMPARAM("Enable", ctx, "1", get_interface_enable_ubus, set_interface_enable_ubus, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("X_BROADCOM_COM_FirewallEnabled", ctx, "1", get_interface_firewall_enabled, set_interface_firewall_enabled, "", 0, 0, UNDEF, NULL); - DMPARAM("IPInterfaceIPAddress", ctx, "1", get_interface_ipaddress, set_interface_ipaddress, "", 0, 0, UNDEF, NULL); - DMPARAM("IPInterfaceSubnetMask", ctx, "1", get_interface_subnetmask, set_interface_subnetmask, "", "0", 0, UNDEF, NULL); - DMPARAM("IPInterfaceAddressingType", ctx, "1", get_interface_addressingtype, set_interface_addressingtype, "", 0, 0, UNDEF, NULL); + DMPARAM("X_BROADCOM_COM_FirewallEnabled", ctx, "1", get_interface_firewall_enabled, set_interface_firewall_enabled, NULL, 0, 0, UNDEF, NULL); + DMPARAM("IPInterfaceIPAddress", ctx, "1", get_interface_ipaddress, set_interface_ipaddress, NULL, 0, 0, UNDEF, NULL); + DMPARAM("IPInterfaceSubnetMask", ctx, "1", get_interface_subnetmask, set_interface_subnetmask, NULL, 0, 0, UNDEF, NULL); + DMPARAM("IPInterfaceAddressingType", ctx, "1", get_interface_addressingtype, set_interface_addressingtype, NULL, 0, 0, UNDEF, NULL); return 0; } inline int get_landevice_lanhostconfigmanagement_dhcpstaticaddress(struct dmctx *ctx, char *idev, char *idhcp) //TODO CAN WE USE TYPE VOID { - DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPStaticAddress.%s.", ctx, "1", 1, NULL, NULL, NULL, idev, idhcp); + DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPStaticAddress.%s.", ctx, "1", 1, NULL, delete_landevice_dhcpstaticaddress, NULL, idev, idhcp); DMPARAM("Enable", ctx, "1", get_dhcpstaticaddress_enable, set_dhcpstaticaddress_enable, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("Chaddr", ctx, "1", get_dhcpstaticaddress_chaddr, set_dhcpstaticaddress_chaddr, "", 0, 0, UNDEF, NULL); - DMPARAM("Yiaddr", ctx, "1", get_dhcpstaticaddress_yiaddr, set_dhcpstaticaddress_yiaddr, "", 0, 0, UNDEF, NULL); + DMPARAM("Chaddr", ctx, "1", get_dhcpstaticaddress_chaddr, set_dhcpstaticaddress_chaddr, NULL, 0, 0, UNDEF, NULL); + DMPARAM("Yiaddr", ctx, "1", get_dhcpstaticaddress_yiaddr, set_dhcpstaticaddress_yiaddr, NULL, 0, 0, UNDEF, NULL); return 0; } inline int get_landevice_wlanconfiguration_generic(struct dmctx *ctx, char *idev,char *iwlan) { int pki = 0; - DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.", ctx, "0", 0, NULL, NULL, NULL, idev, iwlan); + DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.", ctx, "0", 0, NULL, delete_landevice_wlanconfiguration, NULL, idev, iwlan); DMPARAM("Enable", ctx, "1", get_wlan_enable, set_wlan_enable, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_wlan_status, NULL, "", 0, 0, UNDEF, NULL); - DMPARAM("BSSID", ctx, "0", get_wlan_bssid, NULL, "", 0, 0, UNDEF, NULL); - DMPARAM("MaxBitRate", ctx, "1", get_wlan_max_bit_rate, set_wlan_max_bit_rate, "", 0, 0, UNDEF, NULL); + DMPARAM("Status", ctx, "0", get_wlan_status, NULL, NULL, 0, 0, UNDEF, NULL); + DMPARAM("BSSID", ctx, "0", get_wlan_bssid, NULL, NULL, 0, 0, UNDEF, NULL); + DMPARAM("MaxBitRate", ctx, "1", get_wlan_max_bit_rate, set_wlan_max_bit_rate, NULL, 0, 0, UNDEF, NULL); DMPARAM("Channel", ctx, "1", get_wlan_channel, set_wlan_channel, "xsd:unsignedInt", 0, 0, UNDEF, NULL); DMPARAM("AutoChannelEnable", ctx, "1", get_wlan_auto_channel_enable, set_wlan_auto_channel_enable, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("SSID", ctx, "1", get_wlan_ssid, set_wlan_ssid, "", 0, 0, UNDEF, NULL); - DMPARAM("BeaconType", ctx, "1", get_wlan_beacon_type, set_wlan_beacon_type, "", 0, 0, UNDEF, NULL); + DMPARAM("SSID", ctx, "1", get_wlan_ssid, set_wlan_ssid, NULL, 0, 0, UNDEF, NULL); + DMPARAM("BeaconType", ctx, "1", get_wlan_beacon_type, set_wlan_beacon_type, NULL, 0, 0, UNDEF, NULL); DMPARAM("MACAddressControlEnabled", ctx, "1", get_wlan_mac_control_enable, set_wlan_mac_control_enable, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("Standard", ctx, "1", get_wlan_standard, set_wlan_standard, "", "0", 0, UNDEF, NULL); + DMPARAM("Standard", ctx, "1", get_wlan_standard, set_wlan_standard, NULL, "0", 0, UNDEF, NULL); DMPARAM("WEPKeyIndex", ctx, "1", get_wlan_wep_key_index, set_wlan_wep_key_index, "xsd:unsignedInt", 0, 0, UNDEF, NULL); - DMPARAM("KeyPassphrase", ctx, "1", get_empty, set_wlan_key_passphrase, "", 0, 0, UNDEF, NULL); - DMPARAM("WEPEncryptionLevel", ctx, "0", get_wlan_wep_encryption_level, NULL, "", 0, 0, UNDEF, NULL); - DMPARAM("BasicEncryptionModes", ctx, "1", get_wlan_basic_encryption_modes, set_wlan_basic_encryption_modes, "", 0, 0, UNDEF, NULL); - DMPARAM("BasicAuthenticationMode", ctx, "1", get_wlan_basic_authentication_mode, set_wlan_basic_authentication_mode, "", 0, 0, UNDEF, NULL); - DMPARAM("WPAEncryptionModes", ctx, "1", get_wlan_wpa_encryption_modes, set_wlan_wpa_encryption_modes, "", 0, 0, UNDEF, NULL); - DMPARAM("WPAAuthenticationMode", ctx, "1", get_wlan_wpa_authentication_mode, set_wlan_wpa_authentication_mode, "", 0, 0, UNDEF, NULL); - DMPARAM("IEEE11iEncryptionModes", ctx, "1", get_wlan_ieee_11i_encryption_modes, set_wlan_ieee_11i_encryption_modes, "", 0, 0, UNDEF, NULL); - DMPARAM("IEEE11iAuthenticationMode", ctx, "1", get_wlan_ieee_11i_authentication_mode, set_wlan_ieee_11i_authentication_mode, "", 0, 0, UNDEF, NULL); + DMPARAM("KeyPassphrase", ctx, "1", get_empty, set_wlan_key_passphrase, NULL, 0, 0, UNDEF, NULL); + DMPARAM("WEPEncryptionLevel", ctx, "0", get_wlan_wep_encryption_level, NULL, NULL, 0, 0, UNDEF, NULL); + DMPARAM("BasicEncryptionModes", ctx, "1", get_wlan_basic_encryption_modes, set_wlan_basic_encryption_modes, NULL, 0, 0, UNDEF, NULL); + DMPARAM("BasicAuthenticationMode", ctx, "1", get_wlan_basic_authentication_mode, set_wlan_basic_authentication_mode, NULL, 0, 0, UNDEF, NULL); + DMPARAM("WPAEncryptionModes", ctx, "1", get_wlan_wpa_encryption_modes, set_wlan_wpa_encryption_modes, NULL, 0, 0, UNDEF, NULL); + DMPARAM("WPAAuthenticationMode", ctx, "1", get_wlan_wpa_authentication_mode, set_wlan_wpa_authentication_mode, NULL, 0, 0, UNDEF, NULL); + DMPARAM("IEEE11iEncryptionModes", ctx, "1", get_wlan_ieee_11i_encryption_modes, set_wlan_ieee_11i_encryption_modes, NULL, 0, 0, UNDEF, NULL); + DMPARAM("IEEE11iAuthenticationMode", ctx, "1", get_wlan_ieee_11i_authentication_mode, set_wlan_ieee_11i_authentication_mode, NULL, 0, 0, UNDEF, NULL); DMPARAM("RadioEnabled", ctx, "1", get_wlan_radio_enabled, set_wlan_radio_enabled, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("DeviceOperationMode", ctx, "1", get_wlan_device_operation_mode, set_wlan_device_operation_mode, "", 0, 0, UNDEF, NULL); - DMPARAM("AuthenticationServiceMode", ctx, "1", get_wlan_authentication_service_mode, set_wlan_authentication_service_mode, "", 0, 0, UNDEF, NULL); + DMPARAM("DeviceOperationMode", ctx, "1", get_wlan_device_operation_mode, set_wlan_device_operation_mode, NULL, 0, 0, UNDEF, NULL); + DMPARAM("AuthenticationServiceMode", ctx, "1", get_wlan_authentication_service_mode, set_wlan_authentication_service_mode, NULL, 0, 0, UNDEF, NULL); DMPARAM("TotalAssociations", ctx, "0", get_wlan_total_associations, NULL, "xsd:unsignedInt", 0, 0, UNDEF, NULL); - DMPARAM("ChannelsInUse", ctx, "1", get_wlan_channel, set_wlan_channel, "", 0, 0, UNDEF, NULL); + DMPARAM("ChannelsInUse", ctx, "1", get_wlan_channel, set_wlan_channel, NULL, 0, 0, UNDEF, NULL); DMPARAM("TotalBytesSent", ctx, "0", get_wlan_devstatus_statistics_tx_bytes, NULL, "xsd:unsignedInt", 0, 0, UNDEF, NULL); DMPARAM("TotalBytesReceived", ctx, "0", get_wlan_devstatus_statistics_rx_bytes, NULL, "xsd:unsignedInt", 0, 0, UNDEF, NULL); DMPARAM("TotalPacketsSent", ctx, "0", get_wlan_devstatus_statistics_tx_packets, NULL, "xsd:unsignedInt", 0, 0, UNDEF, NULL); DMPARAM("TotalPacketsReceived", ctx, "0", get_wlan_devstatus_statistics_rx_packets, NULL, "xsd:unsignedInt", 0, 0, UNDEF, NULL); DMPARAM("SSIDAdvertisementEnabled", ctx, "1", get_wlan_ssid_advertisement_enable, set_wlan_ssid_advertisement_enable, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("X_INTENO_SE_ChannelMode", ctx, "1", get_x_inteno_se_channelmode, set_x_inteno_se_channelmode, "", 0, 0, UNDEF, NULL); - DMPARAM("X_INTENO_SE_SupportedStandards", ctx, "0", get_x_inteno_se_supported_standard, NULL, "", 0, 0, UNDEF, NULL); - DMPARAM("X_INTENO_SE_OperatingChannelBandwidth", ctx, "1", get_x_inteno_se_operating_channel_bandwidth, set_x_inteno_se_operating_channel_bandwidth, "", 0, 0, UNDEF, NULL); - DMPARAM("X_INTENO_SE_MaxSSID", ctx, "1", get_x_inteno_se_maxssid, set_x_inteno_se_maxssid, "", 0, 0, UNDEF, NULL); + DMPARAM("X_INTENO_SE_ChannelMode", ctx, "1", get_x_inteno_se_channelmode, set_x_inteno_se_channelmode, NULL, 0, 0, UNDEF, NULL); + DMPARAM("X_INTENO_SE_SupportedStandards", ctx, "0", get_x_inteno_se_supported_standard, NULL, NULL, 0, 0, UNDEF, NULL); + DMPARAM("X_INTENO_SE_OperatingChannelBandwidth", ctx, "1", get_x_inteno_se_operating_channel_bandwidth, set_x_inteno_se_operating_channel_bandwidth, NULL, 0, 0, UNDEF, NULL); + DMPARAM("X_INTENO_SE_MaxSSID", ctx, "1", get_x_inteno_se_maxssid, set_x_inteno_se_maxssid, NULL, 0, 0, UNDEF, NULL); + //DYNAMIC WLAN + //DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.AssociatedDevice.", ctx, "0", 0, NULL, NULL, NULL, idev, iwlan); //Check if we can move it DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.WPS.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan); //Check if we can move it DMPARAM("Enable", ctx, "1", get_wlan_wps_enable, set_wlan_wps_enable, "xsd:boolean", 0, 0, UNDEF, NULL); DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.WEPKey.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan); DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.WEPKey.1.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan); - DMPARAM("WEPKey", ctx, "1", get_empty, set_wlan_wep_key, "", 0, 0, UNDEF, NULL); + DMPARAM("WEPKey", ctx, "1", get_empty, set_wlan_wep_key1, NULL, 0, 0, UNDEF, NULL); DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.WEPKey.2.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan); - DMPARAM("WEPKey", ctx, "1", get_empty, set_wlan_wep_key, "", 0, 0, UNDEF, NULL); + DMPARAM("WEPKey", ctx, "1", get_empty, set_wlan_wep_key2, NULL, 0, 0, UNDEF, NULL); DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.WEPKey.3.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan); - DMPARAM("WEPKey", ctx, "1", get_empty, set_wlan_wep_key, "", 0, 0, UNDEF, NULL); + DMPARAM("WEPKey", ctx, "1", get_empty, set_wlan_wep_key3, NULL, 0, 0, UNDEF, NULL); DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.WEPKey.4.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan); - DMPARAM("WEPKey", ctx, "1", get_empty, set_wlan_wep_key, "", 0, 0, UNDEF, NULL); //TODO CHECK PARAM ORDER + DMPARAM("WEPKey", ctx, "1", get_empty, set_wlan_wep_key4, NULL, 0, 0, UNDEF, NULL); //TODO CHECK PARAM ORDER DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.PreSharedKey.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan); while (pki++ != 10) { SUBENTRY(get_landevice_wlanconfiguration_presharedkey, ctx, pki, idev, iwlan); //"$wunit" "$wlctl_num" "$uci_num" are not needed @@ -2493,9 +2821,9 @@ int set_wlan_pre_shared_key(char *refparam, struct dmctx *ctx, int action, char char *encryption; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (!strstr(encryption, "psk")) { reset_wlan(wlanargs->lwlansection); @@ -2507,37 +2835,11 @@ int set_wlan_pre_shared_key(char *refparam, struct dmctx *ctx, int action, char return 0; } -/*int set_wlan_key_passphrase(char *refparam, struct dmctx *ctx, char *value) -{ - struct ldwlanargs *wlanargs = (struct ldwlanargs *)args; - char *encryption; - dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); - int i=0; - //delay_service reload "network" "1" //TODO BY IBH - if (strcmp(encryption, "wep-shared") == 0 || strcmp(encryption, "wep-open") == 0) { - /*for key in `/usr/sbin/wepkeygen 64 $val`;do - $UCI_SET wireless.@wifi-iface[$num].key$i="$key" - let i++ - done*/ - /*char *keys=dmstrdup("`/usr/sbin/wepkeygen 64 $val`"); //TODO BY IBH - char *pch = strtok(keys," "); - while (pch != NULL) { - dmuci_set_value_by_section(); - pch = strtok(NULL, " "); - } - } - } else if (strcmp(encryption, "none") == 0) { - //echo error //EQUIVALENT - return 0; - } else { - set_wlan_pre_shared_key(refparam, args, value); //TO CHECK - } - return 0; -}*/ - int get_wlan_psk_assoc_MACAddress(char *refparam, struct dmctx *ctx, char **value) { + json_object *res; char *wunit, *encryption, buf[8]; + char sta_pki[8]; struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); @@ -2549,21 +2851,26 @@ int get_wlan_psk_assoc_MACAddress(char *refparam, struct dmctx *ctx, char **valu else wunit = wlanargs->wunit; TRACE("pki vaut %d \n", wlanargs->pki); - wlanargs->pki = wlanargs->pki + 1; - TRACE("pki vaut %d \n", wlanargs->pki); - *value = "TO CODE:`/usr/sbin/wlctl -i $wunit assoclist|awk -F' ' '{print $2}'`"; + sprintf(sta_pki, "%s.%d", "sta-", wlanargs->pki); + dmubus_call("router", "sta", UBUS_ARGS{{"vif", wunit}}, 1, &res); + DM_ASSERT(res, *value = ""); + json_select(res, sta_pki, -1, "macaddr", value, NULL); } + *value = ""; return 0; } inline int get_landevice_wlanconfiguration_presharedkey(struct dmctx *ctx, int pki, char *idev, char *iwlan) { char *pki_c; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + wlanargs->pki = pki; //TOCHECK dmasprintf(&pki_c, "%d", pki); + DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.PreSharedKey.%s.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan, pki_c); - DMPARAM("PreSharedKey", ctx, "1", get_empty, set_wlan_pre_shared_key, "", 0, 0, UNDEF, NULL); - DMPARAM("KeyPassphrase", ctx, "1", get_empty, set_wlan_key_passphrase, "", 0, 0, UNDEF, NULL); - DMPARAM("AssociatedDeviceMACAddress", ctx, "0", get_wlan_psk_assoc_MACAddress, NULL, "", 0, 0, UNDEF, NULL); + DMPARAM("PreSharedKey", ctx, "1", get_empty, set_wlan_pre_shared_key, NULL, 0, 0, UNDEF, NULL); + DMPARAM("KeyPassphrase", ctx, "1", get_empty, set_wlan_key_passphrase, NULL, 0, 0, UNDEF, NULL); + DMPARAM("AssociatedDeviceMACAddress", ctx, "0", get_wlan_psk_assoc_MACAddress, NULL, NULL, 0, 0, UNDEF, NULL); dmfree(pki_c); return 0; } diff --git a/dm/dmtree/landevice.h b/dm/dmtree/landevice.h index 3d0a852..819cefa 100644 --- a/dm/dmtree/landevice.h +++ b/dm/dmtree/landevice.h @@ -18,8 +18,13 @@ inline int init_ldargs_dhcp(struct dmctx *ctx, struct uci_section *s); inline int init_ldargs_wlan(struct dmctx *ctx, struct uci_section *s, int wlctl_num, char *wunit, int pki); inline int init_ldargs_eth_cfg(struct dmctx *ctx, char *eth); inline int init_ldargs_ip(struct dmctx *ctx, struct uci_section *s); -inline int init_ldargs_lan(struct dmctx *ctx, struct uci_section *s); -int ip_to_int(char *address); +inline int init_ldargs_lan(struct dmctx *ctx, struct uci_section *s, char *iwan); +int add_landevice_dhcpstaticaddress(struct dmctx *ctx, char **instancepara); +int delete_landevice_dhcpstaticaddress_all(struct dmctx *ctx); +int delete_landevice_dhcpstaticaddress(struct dmctx *ctx); +int add_landevice_wlanconfiguration(struct dmctx *ctx, char **instancepara); +int delete_landevice_wlanconfiguration_all(struct dmctx *ctx); +int delete_landevice_wlanconfiguration(struct dmctx *ctx); int reset_wlan(struct uci_section *s); int get_lan_dns(char *refparam, struct dmctx *ctx, char **value); int set_lan_dns(char *refparam, struct dmctx *ctx, int action, char *value); @@ -121,7 +126,11 @@ int get_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ct int set_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, int action, char *value); int get_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, char **value); int set_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, int action, char *value); -int set_wlan_wep_key(char *refparam, struct dmctx *ctx, int action, char *value); +int set_wlan_wep_key(char *refparam, struct dmctx *ctx, int action, char *value, char *key_index); +int set_wlan_wep_key1(char *refparam, struct dmctx *ctx, int action, char *value); +int set_wlan_wep_key2(char *refparam, struct dmctx *ctx, int action, char *value); +int set_wlan_wep_key3(char *refparam, struct dmctx *ctx, int action, char *value); +int set_wlan_wep_key4(char *refparam, struct dmctx *ctx, int action, char *value); inline int get_landevice_lanhostconfigmanagement_ipinterface (struct dmctx *ctx, char *idev, char *ilan); inline int get_landevice_lanhostconfigmanagement_dhcpstaticaddress(struct dmctx *ctx, char *idev, char *idhcp); inline int get_landevice_wlanconfiguration_generic(struct dmctx *ctx, char *idev,char *iwlan); diff --git a/dm/dmtree/wandevice.c b/dm/dmtree/wandevice.c index f74d56e..24e8b8c 100644 --- a/dm/dmtree/wandevice.c +++ b/dm/dmtree/wandevice.c @@ -24,6 +24,11 @@ #define WAN_INST_PTM 3 #define DEFAULT_WAN_DEVICE_MNG_INTERFACE_IP "" //TODO ASK KMD +enum WAN_TYPE_CONNECTION { + WAN_IP_CONNECTION, + WANPPPConnection +}; + enum enum_wan_dsl { WAN_DSL_NODSL, WAN_DSL_ADSL, @@ -55,7 +60,10 @@ struct wanargs struct wanargs cur_wanargs = {0}; struct wancdevargs { + struct uci_section *wandevsection; + int index; char *fwan; + char *iwan; }; struct wancdevargs cur_wancdevargs = {0}; @@ -86,11 +94,14 @@ inline int init_wancprotoargs(struct dmctx *ctx, struct uci_section *s) return 0; } -inline int init_wancdevargs(struct dmctx *ctx, char *fwan) +inline int init_wancdevargs(struct dmctx *ctx, struct uci_section *s, int index, char *fwan, char *iwan) { struct wancdevargs *args = &cur_wancdevargs; ctx->args = (void *)args; + args->wandevsection = s; + args->index = index; args->fwan = fwan; + args->iwan = iwan; return 0; } @@ -105,6 +116,192 @@ int network_get_ipaddr(char **value, char *iface) return 0; } +/****** ADD-DEL OBJECT *******************/ +int add_wan_wanconnectiondevice(struct dmctx *ctx, char **instancepara) +{ + int iwan; + char *value; + char instance[8] = {0}; + char ifname[16] = {0}; + char buf[16] = {0}; + struct uci_section *s = NULL; + struct wanargs *wandargs = (struct wanargs *)ctx->args; + TRACE("%d \n", wandargs->instance); + if (wandargs->instance == WAN_INST_ATM) { + sprintf(instance, "%s", max_instance("layer2_interface_adsl", "atm_bridge", "baseifname", "waninstance", "atm")); + iwan = atoi(instance); + sprintf(buf,"atm%s",instance); + sprintf(ifname,"%s.1",buf); + sprintf(instance,"%d",iwan + 1); + 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"); + dmuci_set_value_by_section(s, "waninstance", instance); + //delay_service restart "layer2_interface_adsl" "1" + *instancepara = dmstrdup(instance); + //delay_service restart "layer2_interface" "1" + //freecwmp_output "" "" "" "" "" "" "1" "$iwan" + return 0; + } + else if (strcmp(wandargs->fdev, "ptm") == 0) { + sprintf(instance, "%s", max_instance("layer2_interface_vdsl", "vdsl_interface", "baseifname", "waninstance", "ptm")); + iwan = atoi(instance); + sprintf(buf,"ptm%s",instance); + sprintf(ifname,"%s.1",buf); + sprintf(instance,"%d",iwan + 1); + 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); + //delay_service restart "layer2_interface_vdsl" "1" + dmuci_set_value_by_section(s, "waninstance", instance); + *instancepara = dmstrdup(instance); + //delay_service restart "layer2_interface" "1" + //freecwmp_output "" "" "" "" "" "" "1" "$iwan" + return 0; + } + return FAULT_9005; +} + +int delete_wan_wanconnectiondevice_all(struct dmctx *ctx) +{ + int found = 0; + struct uci_section *s = NULL; + struct uci_section *ss = NULL; + struct wanargs *wandargs = (struct wanargs *)ctx->args; + TRACE("%d \n", wandargs->instance); + + uci_foreach_option_cont(wan_devices[wandargs->instance - 1].cdev, wan_devices[wandargs->instance - 1].stype, "baseifname", wandargs->fdev, 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; +} + +int delete_wan_wanconnectiondevice(struct dmctx *ctx) +{ + struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + + dmuci_delete_by_section(wandcdevargs->wandevsection, NULL, NULL); + dmuci_commit(); + return 0; +} +int add_wan_wanipconnection(struct dmctx *ctx, char **instancepara) +{ + struct uci_section *s; + char *value; + struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + int found = 0; + char sname[16] = {0}; + char ifname[8] = {0}; + char instance[8] = {0}; + //TO CHECK NORMALLY THIS IS NOT NECESSAR + /*uci_foreach_option_eq(wan_devices[wandcdevargs->index].cdev, wan_devices[wandcdevargs->index].stype, "baseifname", wandcdevargs->fwan, s) { + found++; + break; + } + if(found == 0) { + return FAULT_9005; + } *///TO CHECK NORMALLY THIS IS NOT NECESSAR $idev""_$iwan""_$iproto""_$((++iconp) + sprintf(instance, "%d", atoi(max_instance("network", "interface", "ifname", "conpinstance", wandcdevargs->fwan)) + 1); + sprintf(sname,"wan_%s_%s_%s_%s", wan_devices[wandcdevargs->index].instance, wandcdevargs->iwan, WAN_IP_CONNECTION, instance); //TODO ADD FUNCTION TO RENAME A SECTION"wan_""$idev""_$iwan""_$iproto""_$((++iconp))" + sprintf(ifname, "%s.1", wandcdevargs->fwan); + dmuci_add_section("network", "interface", &s, &value); + dmuci_rename_section_by_section(s, sname); + dmuci_set_value_by_section(s, "ifname", ifname); + dmuci_set_value_by_section(s, "proto", "dhcp"); + dmuci_set_value_by_section(s, "conpinstance", instance); + *instancepara = dmstrdup(instance); + return 0; +} + +int delete_wan_wanipconnectiondevice_all(struct dmctx *ctx) +{ + int found = 0; + char *ifname, *iproto; + struct uci_section *s = NULL; + struct uci_section *ss = NULL; + struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + + dmuci_get_value_by_section_string(wandcdevargs->wandevsection, "ifname", &ifname); + uci_foreach_option_eq("network", "interface", "ifname", ifname, s) { + dmuci_get_value_by_section_string(s, "proto", &iproto); + if (strcmp(iproto, "dhcp") == 0) { //CHECK IF WE CAN OPTIMISE AND IF iproto can be static + 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; +} + +int delete_wan_wanipconnectiondevice(struct dmctx *ctx) +{ + struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + + dmuci_delete_by_section(wandcdevargs->wandevsection, NULL, NULL); + return 0; +} + +int add_wan_wanpppconnection(struct dmctx *ctx, char **instancepara) +{ + struct uci_section *s; + char *value; + struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + int found = 0; + char sname[16] = {0}; + char ifname[8] = {0}; + char instance[8] = {0}; + + sprintf(instance, "%d", atoi(max_instance("network", "interface", "ifname", "conpinstance", wandcdevargs->fwan)) + 1) ; + sprintf(sname,"wan_%s_%s_%s_%s", wan_devices[wandcdevargs->index].instance, wandcdevargs->iwan, WANPPPConnection, instance); //TODO ADD FUNCTION TO RENAME A SECTION"wan_""$idev""_$iwan""_$iproto""_$((++iconp))" + sprintf(ifname, "%s.1", wandcdevargs->fwan); + dmuci_add_section("network", "interface", &s, &value); + dmuci_rename_section_by_section(s, sname); + dmuci_set_value_by_section(s, "ifname", ifname); + dmuci_set_value_by_section(s, "proto", "pppoe"); + dmuci_set_value_by_section(s, "conpinstance", instance); + *instancepara = dmstrdup(instance); + return 0; +} +int delete_wan_wanpppconnectiondevice_all(struct dmctx *ctx) +{ + int found = 0; + char *ifname, *iproto; + struct uci_section *s = NULL; + struct uci_section *ss = NULL; + struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + + dmuci_get_value_by_section_string(wandcdevargs->wandevsection, "ifname", &ifname); + uci_foreach_option_eq("network", "interface", "ifname", ifname, s) { + dmuci_get_value_by_section_string(s, "proto", &iproto); + if (strcmp(iproto, "pppoe") == 0) { //CHECK IF WE CAN OPTIMISE AND IF iproto can be pppoa + 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; +} +/********************/ + /************************************************************************** **** **** function related to get_wandevice_wandevice_parameters **** **** ***************************************************************************/ @@ -159,7 +356,6 @@ int get_wan_device_wan_dsl_interface_config_status(char *refparam, struct dmctx *value = "NoSignal Not a dsl interface"; else { json_object *res = NULL; - dsl = get_wan_device_wan_dsl_traffic(); if (!(wandargs->instance == WAN_INST_ATM && dsl == WAN_DSL_ADSL) && !(wandargs->instance == WAN_INST_PTM && dsl == WAN_DSL_VDSL) ) { @@ -202,7 +398,6 @@ int get_wan_device_wan_dsl_interface_config_modulation_type(char *refparam, stru *value = ""; return 0; } - dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = ""); json_select(res, "dslstats", -1, "mode", &mode, NULL); @@ -271,7 +466,6 @@ int get_wan_device_dsl_downstreamcurrrate(char *refparam, struct dmctx *ctx, cha !(wandargs->instance == WAN_INST_PTM && dsl == WAN_DSL_VDSL) ) { return 0; } - dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); json_select(res, "dslstats", -1, NULL, NULL, &sub_obj); @@ -303,7 +497,6 @@ int get_wan_device_dsl_downstreammaxrate(char *refparam, struct dmctx *ctx, char !(wandargs->instance == WAN_INST_PTM && dsl == WAN_DSL_VDSL) ) { return 0; } - dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); json_select(res, "dslstats", -1, NULL, NULL, &sub_obj); @@ -333,16 +526,15 @@ int get_wan_device_dsl_downstreamattenuation(char *refparam, struct dmctx *ctx, !(wandargs->instance == WAN_INST_PTM && dsl == WAN_DSL_VDSL) ) { return 0; } - dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); json_select(res, "dslstats", -1, "attn_down_x100", &attn_down_x100, NULL); if (attn_down_x100) { - dmasprintf(&attn_down_x100, "%d", (atoi(attn_down_x100) % 10)); // MEM WILL BE FREED IN DMMEMCLEAN + dmasprintf(&attn_down_x100, "%d", (atoi(attn_down_x100) % 10));// MEM WILL BE FREED IN DMMEMCLEAN *value = attn_down_x100; } } - return 0; + return 0; } int get_wan_device_dsl_downstreamnoisemargin(char *refparam, struct dmctx *ctx, char **value) @@ -360,14 +552,13 @@ int get_wan_device_dsl_downstreamnoisemargin(char *refparam, struct dmctx *ctx, !(wandargs->instance == WAN_INST_PTM && dsl == WAN_DSL_VDSL) ) { return 0; } - dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); json_select(res, "dslstats", -1, "snr_down_x100", &snr_down_x100, NULL); if (snr_down_x100) { - dmasprintf(&snr_down_x100, "%d", (atoi(snr_down_x100) % 10)); // MEM WILL BE FREED IN DMMEMCLEAN + dmasprintf(&snr_down_x100, "%d", (atoi(snr_down_x100) % 10));// MEM WILL BE FREED IN DMMEMCLEAN *value = snr_down_x100; - } + } } return 0; } @@ -388,7 +579,6 @@ int get_wan_device_dsl_upstreamcurrrate(char *refparam, struct dmctx *ctx, char !(wandargs->instance == WAN_INST_PTM && dsl == WAN_DSL_VDSL) ) { return 0; } - dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); json_select(res, "dslstats", -1, NULL, NULL, &sub_obj); @@ -417,7 +607,6 @@ int get_wan_device_dsl_upstreammaxrate(char *refparam, struct dmctx *ctx, char * !(wandargs->instance == WAN_INST_PTM && dsl == WAN_DSL_VDSL) ) { return 0; } - dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); json_select(res, "dslstats", -1, NULL, NULL, &sub_obj); @@ -445,7 +634,6 @@ int get_wan_device_dsl_upstreamattenuation(char *refparam, struct dmctx *ctx, ch !(wandargs->instance == WAN_INST_PTM && dsl == WAN_DSL_VDSL) ) { return 0; } - dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); json_select(res, "dslstats", -1, "attn_up_x100", &attn_up_x100, NULL); @@ -454,7 +642,7 @@ int get_wan_device_dsl_upstreamattenuation(char *refparam, struct dmctx *ctx, ch *value = attn_up_x100; } } - return 0; + return 0; } int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, char **value) @@ -466,7 +654,7 @@ int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, ch if (wandargs->instance == WAN_INST_ETH) { *value = "0"; return 0; - } + } else { dsl = get_wan_device_wan_dsl_traffic(); if (!(wandargs->instance == WAN_INST_ATM && dsl == WAN_DSL_ADSL) && @@ -474,12 +662,11 @@ int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, ch *value = "0"; return 0; } - dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); json_select(res, "dslstats", -1, "snr_up_x100", &snr_up_x100, NULL); if (snr_up_x100) { - dmasprintf(&snr_up_x100, "%d", (atoi(snr_up_x100) % 10)); // MEM WILL BE FREED IN DMMEMCLEAN + dmasprintf(&snr_up_x100, "%d", (atoi(snr_up_x100) % 10));// MEM WILL BE FREED IN DMMEMCLEAN *value = snr_up_x100; } else { @@ -495,9 +682,11 @@ int get_annexm_status(char *refparam, struct dmctx *ctx, char **value) if (wandargs->instance == WAN_INST_ATM) { dmuci_get_option_value_string("layer2_interface", "capabilities", "AnnexM", value); } - if (strcasecmp(*value, "enabled") == 0) { - *value = "1"; - return 0; + if (*value != NULL) { + if (strcasecmp(*value, "enabled") == 0) { + *value = "1"; + return 0; + } } *value = "0"; return 0; @@ -599,7 +788,7 @@ int set_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, int action, char //ubus call network.interface.$intf down '{}' & //TODO goto end; } - } + } } } else @@ -609,7 +798,7 @@ int set_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, int action, char return 0; } end: - return 0; + return 0; } int get_wan_eth_intf_status(char *refparam, struct dmctx *ctx, char **value) @@ -713,7 +902,7 @@ int get_wandevice_wandevice_parameters(struct dmctx *ctx, char *dev, char *fdev) string_to_bool(notif_permission, ¬if_b); TRACE("get_wandevice_wandevice_parameters %s\n", dev); DMOBJECT(DMROOT"WANDevice.%s.", ctx, "0", notif_b, NULL, NULL, NULL, dev); //TODO CHECK NOTIF PERMISSION AND PERMISSION - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.", ctx, cwritable, notif_b, NULL, NULL, NULL, dev); + DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.", ctx, cwritable, notif_b, add_wan_wanconnectiondevice, delete_wan_wanconnectiondevice_all, NULL, dev); DMOBJECT(DMROOT"WANDevice.%s.WANCommonInterfaceConfig.", ctx, "0", 1, NULL, NULL, NULL, dev); DMPARAM("WANAccessType", ctx, "0", get_wan_device_wan_access_type, NULL, NULL, 0, 0, UNDEF, NULL); DMOBJECT(DMROOT"WANDevice.%s.WANDSLInterfaceConfig.", ctx, "0", 1, NULL, NULL, NULL, dev); @@ -744,6 +933,7 @@ int get_wandevice_wandevice_parameters(struct dmctx *ctx, char *dev, char *fdev) return 0; } +//TO CHECK int check_multiwan_interface(struct uci_section *s) { char *type, *value; @@ -754,7 +944,7 @@ int check_multiwan_interface(struct uci_section *s) value = dmstrdup(value); char *pch = strtok(value," "); while (pch != NULL) { - if(strcmp(pch, "atm") == 0 || strcmp(pch, "ptm") == 0 || strcmp(pch, "eth0") == 0) + if(strstr(pch, "atm") || strstr(pch, "ptm") || strstr(pch, "eth0")) { dmfree(value); return 1; @@ -762,7 +952,7 @@ int check_multiwan_interface(struct uci_section *s) pch = strtok(NULL, " "); } dmfree(value); - return 0; + return 0; } int entry_method_root_WANDevice(struct dmctx *ctx) @@ -795,7 +985,7 @@ int entry_method_root_WANDevice(struct dmctx *ctx) TRACE("entry_method_root_WANDevice call update_instance %s\n", iwan); TRACE("entry_method_root_WANDevice call update_instance end\n"); //wanconnectiondevice - init_wancdevargs(ctx, fwan); + init_wancdevargs(ctx, s, i, fwan, iwan); SUBENTRY(get_wandevice_wanconnectiondevice_parameters, ctx, wan_devices[i].instance, iwan);//"$idev" "$iwan" "$fwan" ONLY fdev will be used as arg for get and set function //BREAK POINT1 cur_iconp = NULL; @@ -864,9 +1054,9 @@ int set_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ct else return 0; value = dmstrdup(value); - vpi = strtock(value, "/"); + vpi = strtok(value, "/"); if (vpi) { - vci = strtock(NULL, "/"); + vci = strtok(NULL, "/"); } if (vpi && vci) { dmuci_set_value_by_section(s, "vpi", vpi); @@ -973,9 +1163,9 @@ int get_wandevice_wanconnectiondevice_parameters(struct dmctx *ctx, char *idev, if (strcmp(proto, "pppoa") == 0 || strcmp(proto, "pppoe") == 0) pppn_perm = 0; } - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.", ctx, cwritable, string_to_bool(notif_permission, &b_notif), NULL, NULL, NULL, idev, iwan);//noti permission is bool ADD notif_permission, - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.", ctx, "1", ipn_perm, NULL, NULL, NULL, idev, iwan); //ADD notif_permission:ipn_perm, - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANPPPConnection.", ctx, "1", pppn_perm, NULL, NULL, NULL, idev, iwan); //ADD notif_permission:pppn_perm, + DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.", ctx, cwritable, string_to_bool(notif_permission, &b_notif), NULL, delete_wan_wanconnectiondevice, NULL, idev, iwan);//noti permission is bool ADD notif_permission, + DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.", ctx, "1", ipn_perm, add_wan_wanipconnection, delete_wan_wanipconnectiondevice_all, NULL, idev, iwan); //ADD notif_permission:ipn_perm, + DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANPPPConnection.", ctx, "1", pppn_perm, add_wan_wanpppconnection, delete_wan_wanpppconnectiondevice_all, NULL, idev, iwan); //ADD notif_permission:pppn_perm, if (strcmp(idev, wan_devices[1].instance) == 0) { DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANDSLLinkConfig.", ctx, "0", 1, NULL, NULL, NULL, idev, iwan); //ADD notif_permission:, true DMPARAM("Enable", ctx, "0", get_wan_dsl_link_config_enable, NULL, "xsd:boolean", 0, 0, UNDEF, NULL); @@ -1006,7 +1196,7 @@ int get_wandevice_wanprotoclconnection_parameters(struct dmctx *ctx, char *idev, } if (strcmp(proto, "dhcp") == 0 || strcmp(proto, "static") == 0) { - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.%s.", ctx, "1", notif_b, NULL, NULL, section_name(wandcprotoargs->wancprotosection), idev, iwan, iconp);//TO CHECK "linker_interface:$nlan" + DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.%s.", ctx, "1", notif_b, NULL, delete_wan_wanconnectiondevice, section_name(wandcprotoargs->wancprotosection), idev, iwan, iconp);//TO CHECK "linker_interface:$nlan" DMPARAM("Enable", ctx, "1", get_interface_enable_ubus, set_interface_enable_ubus, "xsd:boolean", 0, 0, UNDEF, NULL); DMPARAM("ConnectionStatus", ctx, "0", get_wan_device_mng_status, NULL, NULL, 0, 0, UNDEF, NULL); DMPARAM("ExternalIPAddress", ctx, "0", get_wan_device_mng_interface_ip, NULL, NULL, notif_b, forced_inform_eip, UNDEF, NULL); //TO ADD "$forced_notify" @@ -1020,7 +1210,7 @@ int get_wandevice_wanprotoclconnection_parameters(struct dmctx *ctx, char *idev, //DMPARAM("DNSOverrideAllowed", ctx, "", , , "xsd:boolean", 0, 0, UNDEF, NULL); } else if (strcmp(proto, "pppoa") == 0 || strcmp(proto, "pppoe") == 0) { - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANPPPConnection.%s.", ctx, "1", 1, NULL, NULL, linker, idev, iwan, iconp);//TO CHECK "linker_interface:$nlan" + DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANPPPConnection.%s.", ctx, "1", 1, NULL, delete_wan_wanconnectiondevice, linker, idev, iwan, iconp);//TO CHECK "linker_interface:$nlan" DMPARAM("Enable", ctx, "1", get_interface_enable_ubus, set_interface_enable_ubus, "xsd:boolean", 0, 0, UNDEF, NULL); DMPARAM("ConnectionStatus", ctx, "0", get_wan_device_ppp_status, NULL, NULL, 0, 0, UNDEF, NULL); DMPARAM("ExternalIPAddress", ctx, "0", get_wan_device_ppp_interface_ip, NULL, NULL, notif_b, forced_inform_eip, UNDEF, NULL); //TO ADD "$forced_notify" @@ -1377,7 +1567,7 @@ int get_wan_device_ppp_interface_ip(char *refparam, struct dmctx *ctx, char **va else { intf = section_name(wandcprotoargs->wancprotosection); network_get_ipaddr(value, intf); //TODO FUNCTION NOT FOUND - } + } return 0; } @@ -1419,7 +1609,7 @@ int set_wan_device_username(char *refparam, struct dmctx *ctx, int action, char case VALUESET: dmuci_set_value_by_section(wandcprotoargs->wancprotosection, "username", value); return 0; - } + } return 0; } @@ -1428,11 +1618,11 @@ int set_wan_device_password(char *refparam, struct dmctx *ctx, int action, char struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); switch (action) { - case VALUECHECK: + case VALUECHECK: return 0; case VALUESET: dmuci_set_value_by_section(wandcprotoargs->wancprotosection, "password", value); return 0; - } + } return 0; } diff --git a/dm/dmtree/wandevice.h b/dm/dmtree/wandevice.h index d4e8ef5..09a99f1 100644 --- a/dm/dmtree/wandevice.h +++ b/dm/dmtree/wandevice.h @@ -13,12 +13,19 @@ #define __WAN_DEVICE_H #include #include -inline int init_wanargs(struct dmctx *ctx, char *idev, char *fdev); +inline int init_wanargs(struct dmctx *ctx, int wan_instance, char *fdev); inline int init_wancprotoargs(struct dmctx *ctx, struct uci_section *s); -inline int init_wancdevargs(struct dmctx *ctx, char *fwan); -char *get_wan_device_wan_dsl_traffic(); +inline int init_wancdevargs(struct dmctx *ctx, struct uci_section *s, int index, char *fwan, char *iwan); +int get_wan_device_wan_dsl_traffic(); int check_multiwan_interface(struct uci_section *s); int network_get_ipaddr(char **value, char *iface); +int add_wan_wanconnectiondevice(struct dmctx *ctx, char **instancepara); +int delete_wan_wanconnectiondevice_all(struct dmctx *ctx); +int delete_wan_wanconnectiondevice(struct dmctx *ctx); +int delete_wan_wanipconnectiondevice_all(struct dmctx *ctx); +int delete_wan_wanipconnectiondevice(struct dmctx *ctx); +int add_wan_wanpppconnection(struct dmctx *ctx, char **instancepara); +int delete_wan_wanpppconnectiondevice_all(struct dmctx *ctx); /************************************************************************** **** **** function related to get_wandevice_wandevice_parameters **** **** ***************************************************************************/ @@ -79,10 +86,6 @@ int get_wan_device_mng_interface_mac(char *refparam, struct dmctx *ctx, char **v int get_wan_device_ppp_username(char *refparam, struct dmctx *ctx, char **value); int set_wan_device_username(char *refparam, struct dmctx *ctx, int action, char *value); int set_wan_device_password(char *refparam, struct dmctx *ctx, int action, char *value); - - - -//OLD int get_wan_device_wan_dsl_interface_config_status(char *refparam, struct dmctx *ctx, char **value); int get_wan_device_wan_dsl_interface_config_modulation_type(char *refparam, struct dmctx *ctx, char **value); int get_wan_device_dsl_datapath(char *refparam, struct dmctx *ctx, char **value);