From 80652051f58e5070cd047594599ae4a82257d18f Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Tue, 12 May 2020 16:39:12 +0100 Subject: [PATCH] Ticket refs#2538: TR-181: Device.Hosts.Host.{i}.InterfaceType is missing --- dmtree/tr181/hosts-iopsyswrt.c | 381 +++++++++++++++++++++------------ dmtree/tr181/hosts-openwrt.c | 137 ++++++++++-- dmtree/tr181/hosts.c | 61 ++++-- dmtree/tr181/hosts.h | 10 +- dmtree/tr181/os.h | 36 ++-- json/convertor_json_to_c.py | 3 + json/tr181.json | 204 +++++++++++++++++- 7 files changed, 639 insertions(+), 193 deletions(-) diff --git a/dmtree/tr181/hosts-iopsyswrt.c b/dmtree/tr181/hosts-iopsyswrt.c index 343729a7..ae298922 100644 --- a/dmtree/tr181/hosts-iopsyswrt.c +++ b/dmtree/tr181/hosts-iopsyswrt.c @@ -1,175 +1,272 @@ +/* + * Copyright (C) 2020 iopsys Software Solutions AB + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 + * as published by the Free Software Foundation + * + * Author: Amin Ben Ramdhane + */ + #include "os.h" #include "dmentry.h" -struct host_args +/************************************************************* +* ENTRY METHOD +**************************************************************/ +/*#Device.Hosts.Host.{i}.!UBUS:router.network/hosts//hosts*/ +int os__browseHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - json_object *client; - char *key; -}; + json_object *res = NULL, *host_obj = NULL, *arrobj = NULL; + char *idx = NULL, *idx_last = NULL; + int id = 0, i = 0; -static inline int init_host_args(struct host_args *args, json_object *clients, char *key) -{ - args->client = clients; - args->key = key; - return 0; -} - -int os__browsehostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) -{ - json_object *res; - char *idx, *idx_last = NULL, *connected; - int id = 0; - struct host_args curr_host_args = {0}; - - dmubus_call("router.network", "clients", UBUS_ARGS{}, 0, &res); + dmubus_call("router.network", "hosts", UBUS_ARGS{}, 0, &res); if (res) { - json_object_object_foreach(res, key, client_obj) { - connected = dmjson_get_value(client_obj, 1, "connected"); - if(strcmp(connected, "false") == 0) - continue; - init_host_args(&curr_host_args, client_obj, key); - idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_host_args, idx) == DM_STOP) + dmjson_foreach_obj_in_array(res, arrobj, host_obj, i, 1, "hosts") { + idx = handle_update_instance(1, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)host_obj, idx) == DM_STOP) break; } } return 0; } -int os__get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.Hosts.Host.{i}.IPv4Address.{i}.!UBUS:router.network/hosts//hosts[@i-1].ipv4addr*/ +int os__browseHostsHostIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - int entries = 0; - json_object *res; + json_object *ip_arr, *host_obj = (json_object *)prev_data; + char *idx = NULL, *idx_last = NULL, *ipv4addr = NULL; + int id = 0, i = 0; - dmubus_call("router.network", "clients", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = "0"); - json_object_object_foreach(res, key, client_obj) { - UNUSED(key); - UNUSED(client_obj); - entries++; + dmjson_foreach_value_in_array(host_obj, ip_arr, ipv4addr, i, 1, "ipv4addr") { + idx = handle_update_instance(1, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)ipv4addr, idx) == DM_STOP) + break; + } + return 0; +} + +/*#Device.Hosts.Host.{i}.IPv6Address.{i}.!UBUS:router.network/hosts//hosts[@i-1].ipv6addr*/ +int os__browseHostsHostIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *ip_arr, *host_obj = (json_object *)prev_data; + char *idx = NULL, *idx_last = NULL, *ipv6addr = NULL; + int id = 0, i = 0; + + dmjson_foreach_value_in_array(host_obj, ip_arr, ipv6addr, i, 1, "ipv6addr") { + idx = handle_update_instance(1, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)ipv6addr, idx) == DM_STOP) + break; } - dmasprintf(value, "%d", entries); // MEM WILL BE FREED IN DMMEMCLEAN return 0; } /************************************************************* * GET & SET PARAM **************************************************************/ -int os__get_host_associateddevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.Hosts.HostNumberOfEntries!UBUS:router.network/hosts//hosts*/ +int os__get_Hosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *ss; - char *accesspointInstance = NULL, *wifiAssociativeDeviecPath; - char *macaddr_linker = dmjson_get_value(((struct host_args *)data)->client, 1, "macaddr"); + json_object *res = NULL, *hosts = NULL; + size_t nbre_hosts = 0; - uci_path_foreach_sections(bbfdm, "dmmap_wireless", "wifi-iface", ss) { - dmuci_get_value_by_section_string(ss, "accesspointinstance", &accesspointInstance); - if(accesspointInstance[0] != '\0') - dmasprintf(&wifiAssociativeDeviecPath, "Device.WiFi.AccessPoint.%s.AssociatedDevice.", accesspointInstance); - accesspointInstance = NULL; - adm_entry_get_linker_param(ctx, wifiAssociativeDeviecPath, macaddr_linker, value); - if(*value != NULL) + dmubus_call("router.network", "hosts", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = "0"); + json_object_object_get_ex(res, "hosts", &hosts); + nbre_hosts = json_object_array_length(hosts); + dmasprintf(value, "%d", nbre_hosts); + return 0; +} + +int os__get_HostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + + char *macaddr = dmjson_get_value((json_object *)data, 1, "macaddr"); + uci_path_foreach_sections(bbfdm, "dmmap", "hosts", s) { + char *mac; + dmuci_get_value_by_section_string(s, "mac", &mac); + if (strcmp(mac, macaddr) == 0) { + dmuci_get_value_by_section_string(s, "alias", value); break; - } - - if (*value == NULL) - *value = ""; - return 0; -} - -int os__get_host_layer3interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *ip_linker=dmjson_get_value(((struct host_args *)data)->client, 1, "network"); - adm_entry_get_linker_param(ctx, "Device.IP.Interface.", ip_linker, value); - if (*value == NULL) - *value = ""; - return 0; -} - -int os__get_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value(((struct host_args *)data)->client, 1, "ipaddr"); - return 0; -} - -int os__get_host_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value(((struct host_args *)data)->client, 1, "hostname"); - return 0; -} - -int os__get_host_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value(((struct host_args *)data)->client, 1, "connected"); - return 0; -} - -int os__get_host_phy_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = dmjson_get_value(((struct host_args *)data)->client, 1, "macaddr"); - return 0; -} - -int os__get_host_address_source(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *dhcp; - - dhcp = dmjson_get_value(((struct host_args *)data)->client, 1, "dhcp"); - if (strcasecmp(dhcp, "true") == 0) - *value = "DHCP"; - else - *value = "Static"; - return 0; -} - -int os__get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *dhcp; - FILE *fp; - char line[MAX_DHCP_LEASES]; - char *leasetime, *mac_f, *mac, *line1; - char delimiter[] = " \t"; - - dhcp = dmjson_get_value(((struct host_args *)data)->client, 1, "dhcp"); - if (strcmp(dhcp, "false") == 0) { - *value = "0"; - } - else { - mac = dmjson_get_value(((struct host_args *)data)->client, 1, "macaddr"); - fp = fopen(DHCP_LEASES_FILE, "r"); - if ( fp != NULL) - { - while (fgets(line, MAX_DHCP_LEASES, fp) != NULL ) - { - if (line[0] == '\n') - continue; - line1 = dmstrdup(line); - leasetime = cut_fx(line, delimiter, 1); - mac_f = cut_fx(line1, delimiter, 2); - if (strcasecmp(mac, mac_f) == 0) { - int rem_lease = atoi(leasetime) - time(NULL); - if (rem_lease < 0) - *value = "-1"; - else - dmasprintf(value, "%d", rem_lease); // MEM WILL BE FREED IN DMMEMCLEAN - fclose(fp) ; - return 0; - } - } - fclose(fp); - *value = "0"; } } + if ((*value)[0] == '\0') + dmasprintf(value, "cpe-%s", instance); return 0; } -int os__get_host_dhcp_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +int os__set_HostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *linker; - dmasprintf(&linker, "%s", ((struct host_args *)data)->key); - adm_entry_get_linker_param(ctx, dm_print_path("%s%cDHCPv4%c", dmroot, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) { - *value = ""; + struct uci_section *s = NULL, *dmmap = NULL; + char *macaddr, *v; + + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0)) + return FAULT_9007; + break; + case VALUESET: + macaddr = dmjson_get_value((json_object *)data, 1, "macaddr"); + uci_path_foreach_option_eq(bbfdm, "dmmap", "hosts", "mac", macaddr, s) { + dmuci_set_value_by_section_bbfdm(s, "alias", value); + return 0; + } + dmuci_add_section_bbfdm("dmmap", "hosts", &dmmap, &v); + dmuci_set_value_by_section(dmmap, "mac", macaddr); + dmuci_set_value_by_section(dmmap, "alias", value); + break; } - dmfree(linker); + return 0; +} + +/*#Device.Hosts.Host.{i}.PhysAddress!UBUS:router.network/hosts//hosts[@i-1].macaddr*/ +int os__get_HostsHost_PhysAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "macaddr"); + return 0; +} + +/*#Device.Hosts.Host.{i}.IPAddress!UBUS:router.network/hosts//hosts[@i-1].ipaddr*/ +int os__get_HostsHost_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "ipaddr"); + return 0; +} + +/*#Device.Hosts.Host.{i}.AddressSource!UBUS:router.network/hosts//hosts[@i-1].addrsrc*/ +int os__get_HostsHost_AddressSource(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "addrsrc"); + *value = (strcmp(*value, "dhcp") == 0) ? "DHCP" : "Static"; + return 0; +} + +int os__get_HostsHost_DHCPClient(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker = dmjson_get_value((json_object *)data, 1, "macaddr"); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cDHCPv4%cServer%cPool%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + *value = ""; + return 0; +} + +/*#Device.Hosts.Host.{i}.LeaseTimeRemaining!UBUS:router.network/hosts//hosts[@i-1].leasetmrmn*/ +int os__get_HostsHost_LeaseTimeRemaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "leasetmrmn"); + return 0; +} + +int os__get_HostsHost_AssociatedDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker = dmjson_get_value((json_object *)data, 1, "macaddr"); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cAccessPoint%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + *value = ""; + return 0; +} + +int os__get_HostsHost_Layer1Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker = dmjson_get_value((json_object *)data, 1, "device"); + char *type = dmjson_get_value((json_object *)data, 1, "type"); + if (strcmp(type, "wifi") == 0) + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cRadio%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + else + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + *value = ""; + return 0; +} + +int os__get_HostsHost_Layer3Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker = dmjson_get_value((json_object *)data, 1, "network"); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) + *value = ""; + return 0; +} + +/*#Device.Hosts.Host.{i}.InterfaceType!UBUS:router.network/hosts//hosts[@i-1].type*/ +int os__get_HostsHost_InterfaceType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "type"); + *value = (strcmp(*value, "ethernet") == 0) ? "Ethernet" : "Wi-Fi"; + return 0; +} + +/*#Device.Hosts.Host.{i}.VendorClassID!UBUS:router.network/hosts//hosts[@i-1].dhcpopts.vcid*/ +int os__get_HostsHost_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 2, "dhcpopts", "vcid"); + return 0; +} + +/*#Device.Hosts.Host.{i}.ClientID!UBUS:router.network/hosts//hosts[@i-1].dhcpopts.clid*/ +int os__get_HostsHost_ClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 2, "dhcpopts", "clid"); + return 0; +} + +/*#Device.Hosts.Host.{i}.UserClassID!UBUS:router.network/hosts//hosts[@i-1].dhcpopts.ucid*/ +int os__get_HostsHost_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 2, "dhcpopts", "ucid"); + return 0; +} + +/*#Device.Hosts.Host.{i}.HostName!UBUS:router.network/hosts//hosts[@i-1].hostname*/ +int os__get_HostsHost_HostName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "hostname"); + return 0; +} + +/*#Device.Hosts.Host.{i}.Active!UBUS:router.network/hosts//hosts[@i-1].active*/ +int os__get_HostsHost_Active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "active"); + return 0; +} + +/*#Device.Hosts.Host.{i}.IPv4AddressNumberOfEntries!UBUS:router.network/hosts//hosts[@i-1].ipv4addr*/ +int os__get_HostsHost_IPv4AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *ipv4addr = NULL; + size_t nbre_addr = 0; + + json_object_object_get_ex((json_object *)data, "ipv4addr", &ipv4addr); + nbre_addr = json_object_array_length(ipv4addr); + dmasprintf(value, "%d", nbre_addr); + return 0; +} + +/*#Device.Hosts.Host.{i}.IPv6AddressNumberOfEntries!UBUS:router.network/hosts//hosts[@i-1].ipv6addr*/ +int os__get_HostsHost_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *ipv6addr = NULL; + size_t nbre_addr = 0; + + json_object_object_get_ex((json_object *)data, "ipv6addr", &ipv6addr); + nbre_addr = json_object_array_length(ipv6addr); + dmasprintf(value, "%d", nbre_addr); + return 0; +} + +/*#Device.Hosts.Host.{i}.IPv4Address.{i}.IPAddress!UBUS:router.network/hosts//hosts[@i-1].ipv4addr[@i-1]*/ +int os__get_HostsHostIPv4Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = (char *)data; + return 0; +} + +/*#Device.Hosts.Host.{i}.IPv6Address.{i}.IPAddress!UBUS:router.network/hosts//hosts[@i-1].ipv6addr[@i-1]*/ +int os__get_HostsHostIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = (char *)data; return 0; } diff --git a/dmtree/tr181/hosts-openwrt.c b/dmtree/tr181/hosts-openwrt.c index 133bba7a..f1bb7dd9 100644 --- a/dmtree/tr181/hosts-openwrt.c +++ b/dmtree/tr181/hosts-openwrt.c @@ -1,63 +1,176 @@ #include "os.h" - static int not_implemented(char **value) { *value = ""; return 0; } -int os__browsehostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +/************************************************************* +* ENTRY METHOD +**************************************************************/ +int os__browseHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { return 0; } -int os__get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +int os__browseHostsHostIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + return 0; +} + +int os__browseHostsHostIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + return 0; +} + +/************************************************************* +* GET & SET PARAM +**************************************************************/ +int os__get_Hosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -int os__get_host_associateddevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +int os__get_HostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -int os__get_host_layer3interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +int os__set_HostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0)) + return FAULT_9007; + break; + case VALUESET: + break; + } + return 0; +} + +int os__get_HostsHost_PhysAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -int os__get_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +int os__get_HostsHost_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -int os__get_host_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +int os__get_HostsHost_AddressSource(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -int os__get_host_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +int os__get_HostsHost_DHCPClient(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -int os__get_host_phy_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +int os__get_HostsHost_LeaseTimeRemaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -int os__get_host_address_source(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +int os__get_HostsHost_AssociatedDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -int os__get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +int os__get_HostsHost_Layer1Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -int os__get_host_dhcp_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +int os__get_HostsHost_Layer3Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHost_InterfaceType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHost_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHost_ClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHost_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHost_HostName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHost_Active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHost_IPv4AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHost_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHostIPv4Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHostIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHostWANStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHostWANStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHostWANStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHostWANStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHostWANStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHostWANStats_RetransCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + return not_implemented(value); +} + +int os__get_HostsHostWANStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } diff --git a/dmtree/tr181/hosts.c b/dmtree/tr181/hosts.c index f93afbd0..0fdf22e0 100644 --- a/dmtree/tr181/hosts.c +++ b/dmtree/tr181/hosts.c @@ -1,42 +1,69 @@ /* - * Copyright (C) 2019 iopsys Software Solutions AB + * Copyright (C) 2020 iopsys Software Solutions AB * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 2.1 * as published by the Free Software Foundation * - * Author: Anis Ellouze - * + * Author: Amin Ben Ramdhane */ #include "hosts.h" #include "os.h" - /* *** Device.Hosts. *** */ DMOBJ tHostsObj[] = { /* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ -{"Host", &DMREAD, NULL, NULL, NULL, os__browsehostInst, NULL, NULL, NULL, NULL, tHostsHostParams, NULL, BBFDM_BOTH}, +{"Host", &DMREAD, NULL, NULL, NULL, os__browseHostsHostInst, NULL, NULL, NULL, tHostsHostObj, tHostsHostParams, NULL, BBFDM_BOTH}, {0} }; DMLEAF tHostsParams[] = { /* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"HostNumberOfEntries", &DMREAD, DMT_UNINT, os__get_host_nbr_entries, NULL, NULL, NULL, BBFDM_BOTH}, +{"HostNumberOfEntries", &DMREAD, DMT_UNINT, os__get_Hosts_HostNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, {0} }; /* *** Device.Hosts.Host.{i}. *** */ -DMLEAF tHostsHostParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"AssociatedDevice", &DMREAD, DMT_STRING, os__get_host_associateddevice, NULL, NULL, NULL, BBFDM_BOTH}, -{"Layer3Interface", &DMREAD, DMT_STRING, os__get_host_layer3interface, NULL, NULL, NULL, BBFDM_BOTH}, -{"IPAddress", &DMREAD, DMT_STRING, os__get_host_ipaddress, NULL, NULL, NULL, BBFDM_BOTH}, -{"HostName", &DMREAD, DMT_STRING, os__get_host_hostname, NULL, NULL, NULL, BBFDM_BOTH}, -{"Active", &DMREAD, DMT_BOOL, os__get_host_active, NULL, NULL, NULL, BBFDM_BOTH}, -{"PhysAddress", &DMREAD, DMT_STRING, os__get_host_phy_address, NULL, NULL, NULL, BBFDM_BOTH}, -{"AddressSource", &DMREAD, DMT_STRING, os__get_host_address_source, NULL, NULL, NULL, BBFDM_BOTH}, -{"LeaseTimeRemaining", &DMREAD, DMT_INT, os__get_host_leasetime_remaining, NULL, NULL, NULL, BBFDM_BOTH}, -{"DHCPClient", &DMREAD, DMT_STRING, os__get_host_dhcp_client, NULL, NULL, NULL, BBFDM_BOTH}, +DMOBJ tHostsHostObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/ +{"IPv4Address", &DMREAD, NULL, NULL, NULL, os__browseHostsHostIPv4AddressInst, NULL, NULL, NULL, NULL, tHostsHostIPv4AddressParams, NULL, BBFDM_BOTH}, +{"IPv6Address", &DMREAD, NULL, NULL, NULL, os__browseHostsHostIPv6AddressInst, NULL, NULL, NULL, NULL, tHostsHostIPv6AddressParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tHostsHostParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Alias", &DMWRITE, DMT_STRING, os__get_HostsHost_Alias, os__set_HostsHost_Alias, NULL, NULL, BBFDM_BOTH}, +{"PhysAddress", &DMREAD, DMT_STRING, os__get_HostsHost_PhysAddress, NULL, NULL, NULL, BBFDM_BOTH}, +{"IPAddress", &DMREAD, DMT_STRING, os__get_HostsHost_IPAddress, NULL, NULL, NULL, BBFDM_BOTH}, +{"AddressSource", &DMREAD, DMT_STRING, os__get_HostsHost_AddressSource, NULL, NULL, NULL, BBFDM_BOTH}, +{"DHCPClient", &DMREAD, DMT_STRING, os__get_HostsHost_DHCPClient, NULL, NULL, NULL, BBFDM_BOTH}, +{"LeaseTimeRemaining", &DMREAD, DMT_INT, os__get_HostsHost_LeaseTimeRemaining, NULL, NULL, NULL, BBFDM_BOTH}, +{"AssociatedDevice", &DMREAD, DMT_STRING, os__get_HostsHost_AssociatedDevice, NULL, NULL, NULL, BBFDM_BOTH}, +{"Layer1Interface", &DMREAD, DMT_STRING, os__get_HostsHost_Layer1Interface, NULL, NULL, NULL, BBFDM_BOTH}, +{"Layer3Interface", &DMREAD, DMT_STRING, os__get_HostsHost_Layer3Interface, NULL, NULL, NULL, BBFDM_BOTH}, +{"InterfaceType", &DMREAD, DMT_STRING, os__get_HostsHost_InterfaceType, NULL, NULL, NULL, BBFDM_BOTH}, +{"VendorClassID", &DMREAD, DMT_STRING, os__get_HostsHost_VendorClassID, NULL, NULL, NULL, BBFDM_BOTH}, +{"ClientID", &DMREAD, DMT_HEXBIN, os__get_HostsHost_ClientID, NULL, NULL, NULL, BBFDM_BOTH}, +{"UserClassID", &DMREAD, DMT_HEXBIN, os__get_HostsHost_UserClassID, NULL, NULL, NULL, BBFDM_BOTH}, +{"HostName", &DMREAD, DMT_STRING, os__get_HostsHost_HostName, NULL, NULL, NULL, BBFDM_BOTH}, +{"Active", &DMREAD, DMT_BOOL, os__get_HostsHost_Active, NULL, NULL, NULL, BBFDM_BOTH}, +{"IPv4AddressNumberOfEntries", &DMREAD, DMT_UNINT, os__get_HostsHost_IPv4AddressNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{"IPv6AddressNumberOfEntries", &DMREAD, DMT_UNINT, os__get_HostsHost_IPv6AddressNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.Hosts.Host.{i}.IPv4Address.{i}. *** */ +DMLEAF tHostsHostIPv4AddressParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"IPAddress", &DMREAD, DMT_STRING, os__get_HostsHostIPv4Address_IPAddress, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.Hosts.Host.{i}.IPv6Address.{i}. *** */ +DMLEAF tHostsHostIPv6AddressParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"IPAddress", &DMREAD, DMT_STRING, os__get_HostsHostIPv6Address_IPAddress, NULL, NULL, NULL, BBFDM_BOTH}, {0} }; diff --git a/dmtree/tr181/hosts.h b/dmtree/tr181/hosts.h index 0dd3c3d6..a7dac859 100644 --- a/dmtree/tr181/hosts.h +++ b/dmtree/tr181/hosts.h @@ -1,12 +1,11 @@ /* - * Copyright (C) 2019 iopsys Software Solutions AB + * Copyright (C) 2020 iopsys Software Solutions AB * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 2.1 * as published by the Free Software Foundation * - * Author: Anis Ellouze - * + * Author: Amin Ben Ramdhane */ #ifndef __HOSTS_H @@ -16,6 +15,9 @@ extern DMOBJ tHostsObj[]; extern DMLEAF tHostsParams[]; +extern DMOBJ tHostsHostObj[]; extern DMLEAF tHostsHostParams[]; +extern DMLEAF tHostsHostIPv4AddressParams[]; +extern DMLEAF tHostsHostIPv6AddressParams[]; -#endif +#endif //__HOSTS_H diff --git a/dmtree/tr181/os.h b/dmtree/tr181/os.h index 38b54dcb..df41d597 100644 --- a/dmtree/tr181/os.h +++ b/dmtree/tr181/os.h @@ -29,18 +29,30 @@ int os__get_process_cpu_time(char* refparam, struct dmctx *ctx, void *data, char int os__get_process_state(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value); int os__browseProcessEntriesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int os__browsehostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int os__get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int os__get_host_associateddevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int os__get_host_layer3interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int os__get_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int os__get_host_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int os__get_host_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int os__get_host_phy_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int os__get_host_address_source(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int os__get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int os__get_host_dhcp_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__browseHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int os__browseHostsHostIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int os__browseHostsHostIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int os__get_Hosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__set_HostsHost_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int os__get_HostsHost_PhysAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_AddressSource(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_DHCPClient(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_LeaseTimeRemaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_AssociatedDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_Layer1Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_Layer3Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_InterfaceType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_ClientID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_HostName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_Active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_IPv4AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHost_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHostIPv4Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os__get_HostsHostIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); #include "wifi.h" diff --git a/json/convertor_json_to_c.py b/json/convertor_json_to_c.py index e6c8f657..58681fb3 100755 --- a/json/convertor_json_to_c.py +++ b/json/convertor_json_to_c.py @@ -122,6 +122,9 @@ def get_mapping_param( mappingobj ): arg1, arg2 = getargsparam(argsobj) key = getoptionparam(ubusobj, "key") return type, object, method, arg1, arg2, key + elif type == "procfs" or type == "sysfs": + file = getoptionparam(mappingobj, "file") + return type, file, "", "", "", "" else: cliobj = getoptionparam(mappingobj, "cli") command = getoptionparam(cliobj, "command") diff --git a/json/tr181.json b/json/tr181.json index b206746a..dce2467e 100644 --- a/json/tr181.json +++ b/json/tr181.json @@ -38442,7 +38442,7 @@ "usp" ], "datatype": "boolean" - }, + } }, "Device.IP.Interface.{i}.Stats.": { "type": "object", @@ -52020,7 +52020,18 @@ "cwmp", "usp" ], - "datatype": "unsignedInt" + "datatype": "unsignedInt", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts" + } + } + ] }, "Device.Hosts.Host.{i}.": { "type": "object", @@ -52030,6 +52041,15 @@ ], "access": false, "array": true, + "mapping": { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts" + } + }, "Alias": { "type": "string", "read": true, @@ -52058,6 +52078,17 @@ { "max": 64 } + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].macaddr" + } + } ] }, "IPAddress": { @@ -52073,6 +52104,17 @@ { "max": 45 } + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].ipaddr" + } + } ] }, "AddressSource": { @@ -52089,6 +52131,17 @@ "Static", "AutoIP", "None" + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].addrsrc" + } + } ] }, "DHCPClient": { @@ -52120,7 +52173,18 @@ "min": -1 } ], - "unit": "seconds" + "unit": "seconds", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].leasetmrmn" + } + } + ] }, "AssociatedDevice": { "type": "string", @@ -52185,6 +52249,17 @@ "UPA", "Wi-Fi", "Other" + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].type" + } + } ] }, "VendorClassID": { @@ -52200,6 +52275,17 @@ { "max": 255 } + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].dhcpopts.vcid" + } + } ] }, "ClientID": { @@ -52215,6 +52301,17 @@ { "max": 65535 } + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].dhcpopts.clid" + } + } ] }, "UserClassID": { @@ -52230,6 +52327,17 @@ { "max": 65535 } + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].dhcpopts.ucid" + } + } ] }, "HostName": { @@ -52245,6 +52353,17 @@ { "max": 64 } + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].hostname" + } + } ] }, "Active": { @@ -52255,7 +52374,18 @@ "cwmp", "usp" ], - "datatype": "boolean" + "datatype": "boolean", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].active" + } + } + ] }, "ActiveLastChange": { "type": "dateTime", @@ -52275,7 +52405,18 @@ "cwmp", "usp" ], - "datatype": "unsignedInt" + "datatype": "unsignedInt", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].ipv4addr" + } + } + ] }, "IPv6AddressNumberOfEntries": { "type": "unsignedInt", @@ -52285,7 +52426,18 @@ "cwmp", "usp" ], - "datatype": "unsignedInt" + "datatype": "unsignedInt", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].ipv6addr" + } + } + ] }, "Device.Hosts.Host.{i}.IPv4Address.{i}.": { "type": "object", @@ -52295,6 +52447,15 @@ ], "access": false, "array": true, + "mapping": { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].ipv4addr" + } + }, "IPAddress": { "type": "string", "read": true, @@ -52311,6 +52472,17 @@ ], "pattern": [ "((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])" + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].ipv4addr[@i-1]" + } + } ] } }, @@ -52322,6 +52494,15 @@ ], "access": false, "array": true, + "mapping": { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].ipv6addr" + } + }, "IPAddress": { "type": "string", "read": true, @@ -52335,6 +52516,17 @@ { "max": 45 } + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "router.network", + "method": "hosts", + "args": {}, + "key": "hosts[@i-1].ipv6addr[@i-1]" + } + } ] } },