diff --git a/dm/dmtree/tr181/dhcp.c b/dm/dmtree/tr181/dhcp.c index aec575e..2e632f8 100644 --- a/dm/dmtree/tr181/dhcp.c +++ b/dm/dmtree/tr181/dhcp.c @@ -18,7 +18,9 @@ #include "dmcommon.h" #include "dhcp.h" + struct dhcp_args cur_dhcp_args = {0}; +struct client_args cur_dhcp_client_args = {0}; struct dhcp_static_args cur_dhcp_staticargs = {0}; /************************************************************* @@ -39,6 +41,15 @@ inline int init_args_dhcp_host(struct dmctx *ctx, struct uci_section *s) args->dhcpsection = s; return 0; } + +inline int init_dhcp_client_args(struct dmctx *ctx, json_object *client) +{ + struct client_args *args = &cur_dhcp_client_args; + ctx->args = (void *)args; + args->client = client; + return 0; +} + /*******************ADD-DEL OBJECT*********************/ int add_dhcp_server(struct dmctx *ctx, char **instancepara) { @@ -764,6 +775,15 @@ int set_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, int action, } return 0; } + +int get_dhcp_client_chaddr(char *refparam, struct dmctx *ctx, char **value) +{ + printf("get_dhcp_client_chaddr \n"); + json_select(cur_dhcp_client_args.client, "macaddr", 0, NULL, value, NULL); + printf("get_dhcp_client_chaddr 2\n"); + return 0; +} + /************************************************************* * ENTRY METHOD /*************************************************************/ @@ -809,7 +829,9 @@ inline int entry_dhcp_instance(struct dmctx *ctx, char *interface, char *int_num DMPARAM("DomainName", ctx, "1", get_dhcp_domainname, set_dhcp_domainname, NULL, 0, 1, UNDEF, NULL); //DMPARAM("Interface", ctx, "1", get_lan_dhcp_domainname, set_lan_dhcp_domainname, NULL, 0, 1, UNDEF, NULL); // refer to IP.Interface DMOBJECT(DMROOT"DHCPv4.Server.Pool.%s.StaticAddress.", ctx, "0", NULL, add_dhcp_staticaddress, delete_dhcp_staticaddress_all, NULL, int_num); //TODO - SUBENTRY(entry_dhcp_static_address, ctx, interface, int_num); + SUBENTRY(entry_dhcp_static_address, ctx, interface, int_num); + DMOBJECT(DMROOT"DHCPv4.Server.Pool.%s.Client.", ctx, "0", NULL, NULL, NULL, NULL, int_num); //TODO + SUBENTRY(entry_dhcp_client, ctx, interface, int_num); return 0; } return FAULT_9005; @@ -838,3 +860,52 @@ inline int entry_dhcp_static_address_instance(struct dmctx *ctx, char *int_num, } return FAULT_9005; } + +inline int entry_dhcp_client(struct dmctx *ctx, char *interface, char *idev ) +{ + printf("entry_dhcp_client \n"); + //struct uci_section *ss = NULL; + struct uci_section *sss = NULL; + char *idx = NULL, *idx_last = NULL; + json_object *res = NULL, *client_obj = NULL; + char *dhcp, *network; + int id = 0; + dmubus_call("router", "clients", UBUS_ARGS{}, 0, &res); + if (res) { + printf("res not null \n"); + json_object_object_foreach(res, key, client_obj) { + json_select(client_obj, "dhcp", 0, NULL, &dhcp, NULL); + printf("dhcp %s \n", dhcp); + if(strcmp(dhcp, "false") == 0) + { + json_select(client_obj, "network", 0, NULL, &network, NULL); + if(strcmp(network, interface) == 0) + { + printf("network %s \n", network); + init_dhcp_client_args(ctx, client_obj); + idx = handle_update_instance(2, ctx, &idx_last, update_instance_without_section, 1, ++id); + printf("before instance cll \n"); + SUBENTRY(entry_dhcp_client_instance, ctx, idev, idx, key); + } + } + + + } + } + return 0; +} + +inline int entry_dhcp_client_instance(struct dmctx *ctx, char *int_num, char *idx, char *key) +{ + char linker[32] = "linker_dhcp:"; + strcat(linker, key); + printf("linker is %s \n",linker); + IF_MATCH(ctx, DMROOT"DHCPv4.Server.Pool.%s.Client.%s.", int_num, idx) { + printf("call entry_dhcp_static_address_instance \n"); + DMOBJECT(DMROOT"DHCPv4.Server.Pool.%s.Client.%s.", ctx, "1", NULL, NULL, NULL, linker, int_num, idx); + DMPARAM("Chaddr", ctx, "0", get_dhcp_client_chaddr, NULL, NULL, 0, 1, UNDEF, NULL); + return 0; + } + return FAULT_9005; +} + diff --git a/dm/dmtree/tr181/dhcp.h b/dm/dmtree/tr181/dhcp.h index dff035d..e6877f6 100644 --- a/dm/dmtree/tr181/dhcp.h +++ b/dm/dmtree/tr181/dhcp.h @@ -22,6 +22,11 @@ struct dhcp_static_args struct uci_section *dhcpsection; }; +struct client_args +{ + json_object *client; +}; + int entry_method_root_dhcp(struct dmctx *ctx); #endif diff --git a/dm/dmtree/tr181/hosts.c b/dm/dmtree/tr181/hosts.c index 6891260..052f73e 100644 --- a/dm/dmtree/tr181/hosts.c +++ b/dm/dmtree/tr181/hosts.c @@ -23,11 +23,12 @@ struct host_args cur_host_args = {0}; /************************************************************* * INIT /*************************************************************/ -inline int init_host_args(struct dmctx *ctx, json_object *clients) +inline int init_host_args(struct dmctx *ctx, json_object *clients, char *key) { struct host_args *args = &cur_host_args; ctx->args = (void *)args; args->client = clients; + args->key = key; return 0; } /************************************************************* @@ -109,6 +110,65 @@ int get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, char **value } return 0; } + +int get_host_dhcp_client(char *refparam, struct dmctx *ctx, char **value) +{ + char *iface, *linker; + dmastrcat(&linker, "linker_dhcp:", cur_host_args.key); + adm_entry_get_linker_param(DMROOT"DHCPv4.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) { + *value = ""; + } + dmfree(linker); + return 0; +} + +char *get_interface_type(char *mac, char *ndev) +{ + json_object *res; + int wlctl_num; + struct uci_section *s, *d; + char *network, *device, *value, *wunit; + char buf[8], *p; + + uci_foreach_sections("wireless", "wifi-device", d) { + wlctl_num = 0; + wunit = section_name(d); + uci_foreach_option_eq("wireless", "wifi-iface", "device", wunit, s) { + dmuci_get_value_by_section_string(s, "network", &network); + if (strcmp(network, ndev) == 0) { + if (wlctl_num != 0) { + sprintf(buf, "%s.%d", wunit, wlctl_num); + p = buf; + } + else { + p = wunit; + } + dmubus_call("router", "sta", UBUS_ARGS{{"vif", p}}, 1, &res); + if(res) { + json_object_object_foreach(res, key, val) { + json_select(val, "assoc_mac", 0, NULL, &value, NULL); + if (strcasecmp(value, mac) == 0) + return "802.11"; + } + } + wlctl_num++; + } + } + } + return "Ethernet"; +} + +int get_host_interfacetype(char *refparam, struct dmctx *ctx, char **value) +{ + char *mac, *network; + + json_select(cur_host_args.client, "macaddr", 0, NULL, &mac, NULL); + json_select(cur_host_args.client, "network", 0, NULL, &network, NULL); + *value = get_interface_type(mac, network); + return 0; +} + /************************************************************* * ENTRY METHOD /*************************************************************/ @@ -131,7 +191,7 @@ inline int entry_host(struct dmctx *ctx) dmubus_call("router", "clients", UBUS_ARGS{}, 0, &res); if (res) { json_object_object_foreach(res, key, client_obj) { - init_host_args(ctx, client_obj); + init_host_args(ctx, client_obj, key); idx = handle_update_instance(2, ctx, &idx_last, update_instance_without_section, 1, ++id); SUBENTRY(entry_host_instance, ctx, idx); } @@ -147,10 +207,10 @@ inline int entry_host_instance(struct dmctx *ctx, char *int_num) DMPARAM("HostName", ctx, "0", get_host_hostname, NULL, NULL, 0, 0, UNDEF, NULL); DMPARAM("Active", ctx, "0", get_host_active, NULL, "xsd:boolean", 0, 0, UNDEF, NULL); DMPARAM("PhysAddress", ctx, "0", get_host_phy_address, NULL, NULL, 0, 0, UNDEF, NULL); - //DMPARAM("X_INTENO_SE_InterfaceType", ctx, "0", get_lan_host_interfacetype, NULL, NULL, 0, 0, UNDEF, NULL); + DMPARAM("X_INTENO_SE_InterfaceType", ctx, "0", get_host_interfacetype, NULL, NULL, 0, 0, UNDEF, NULL); DMPARAM("AddressSource", ctx, "0", get_host_address_source, NULL, NULL, 0, 0, UNDEF, NULL); DMPARAM("LeaseTimeRemaining", ctx, "0", get_host_leasetime_remaining, NULL, NULL, 0, 0, UNDEF, NULL); - //DMPARAM("DHCPClient", ctx, "0", get_eth_port_name, NULL, NULL, 0, 1, UNDEF, NULL); //TO CHECK R/W + DMPARAM("DHCPClient", ctx, "0", get_host_dhcp_client, NULL, NULL, 0, 1, UNDEF, NULL); //TO CHECK R/W return 0; } return FAULT_9005; diff --git a/dm/dmtree/tr181/hosts.h b/dm/dmtree/tr181/hosts.h index 5bee2b2..07ba0a3 100644 --- a/dm/dmtree/tr181/hosts.h +++ b/dm/dmtree/tr181/hosts.h @@ -14,6 +14,7 @@ struct host_args { json_object *client; + char *key; }; int entry_method_root_hosts(struct dmctx *ctx);