Ticket refs #13620: TR-181: List of parameters to be supported

This commit is contained in:
Amin Ben Ramdhane 2018-01-26 16:47:08 +01:00
parent 30f47f79ef
commit 7be69cbae2
13 changed files with 406 additions and 3 deletions

View file

@ -54,7 +54,8 @@ libdatamodel_la_SOURCES += \
../dm/dmtree/tr181/ip.c \
../dm/dmtree/tr181/ppp.c \
../dm/dmtree/tr181/nat.c \
../dm/dmtree/tr181/routing.c
../dm/dmtree/tr181/routing.c \
../dm/dmtree/tr181/userinterface.c
endif
if UPNP_TR064

View file

@ -45,6 +45,7 @@
#include "nat.h"
#include "ppp.h"
#include "routing.h"
#include "userinterface.h"
#endif
#ifdef DATAMODEL_TR098
#include "landevice.h"
@ -111,6 +112,7 @@ DMOBJ tRootObj[] = {
{"NAT", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tnatObj, NULL, NULL},
{"PPP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tpppObj, NULL, NULL},
{"Routing", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tRoutingObj, tRoutingParam, NULL},
{"UserInterface", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tUserInterfaceObj, NULL, NULL},
#endif
{0}
};

View file

@ -39,13 +39,21 @@ DMOBJ tDhcpv4ServerObj[] = {
DMOBJ tDhcpServerPoolObj[] = {
/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/
{"StaticAddress", &DMWRITE, add_dhcp_staticaddress, delete_dhcp_staticaddress, NULL, browseDhcpStaticInst, NULL, NULL, NULL, tDhcpServerPoolAddressParams, NULL},
{"Client", &DMREAD, NULL, NULL, NULL, browseDhcpClientInst, NULL, NULL, NULL, tDhcpServerPoolClientParams, get_dhcp_client_linker},
{"Client", &DMREAD, NULL, NULL, NULL, browseDhcpClientInst, NULL, NULL, tDhcpServerPoolClientObj, tDhcpServerPoolClientParams, get_dhcp_client_linker},
{0}
};
/*** DHCPv4.Server.Pool.{i}.Client.{i}. ***/
DMOBJ tDhcpServerPoolClientObj[] = {
/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/
{"IPv4Address", &DMREAD, NULL, NULL, NULL, browseDhcpClientIPv4Inst, NULL, NULL, NULL, tDhcpServerPoolClientIPv4AddressParams, NULL},
{0}
};
DMLEAF tDhcpServerPoolParams[] = {
/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/
{"DNSServers", &DMWRITE, DMT_STRING, get_dns_server, set_dns_server, NULL, NULL},
{"Status", &DMREAD, DMT_STRING, get_dhcp_status, NULL, NULL, NULL},
{"X_INTENO_SE_DHCPServerConfigurable", &DMWRITE, DMT_BOOL, get_dhcp_configurable, set_dhcp_configurable, NULL, NULL},
{"Enable", &DMWRITE, DMT_BOOL, get_dhcp_enable, set_dhcp_enable, NULL, NULL},
{"MinAddress", &DMWRITE, DMT_STRING, get_dhcp_interval_address_min, set_dhcp_address_min, NULL, NULL},
@ -75,6 +83,13 @@ DMLEAF tDhcpServerPoolClientParams[] = {
{0}
};
/*** DHCPv4.Server.Pool.{i}.Client.{i}.IPv4Address.{i}. ***/
DMLEAF tDhcpServerPoolClientIPv4AddressParams[] = {
/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/
{"LeaseTimeRemaining", &DMREAD, DMT_TIME, get_dhcp_client_ipv4address_leasetime, NULL, NULL, NULL},
{0}
};
/**************************************************************************
* LINKER
***************************************************************************/
@ -284,6 +299,17 @@ int set_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *i
return 0;
}
int get_dhcp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char v[3];
uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) {
dmuci_get_value_by_section_string(s, "ignore", v);
*value = (v[0] == '1') ? "Disabled" : "Enabled";
}
return 0;
}
int get_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
@ -882,6 +908,29 @@ int get_dhcp_client_chaddr(char *refparam, struct dmctx *ctx, void *data, char *
return 0;
}
int get_dhcp_client_ipv4address_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char time_buf[26] = {0};
struct tm *t_tm;
struct dhcp_client_ipv4address_args current_dhcp_client_ipv4address_args = *((struct dhcp_client_ipv4address_args*)data);
*value = "0001-01-01T00:00:00Z";
time_t t_time = current_dhcp_client_ipv4address_args.leasetime;
t_tm = localtime(&t_time);
if (t_tm == NULL)
return 0;
if(strftime(time_buf, sizeof(time_buf), "%FT%T%z", t_tm) == 0)
return 0;
time_buf[25] = time_buf[24];
time_buf[24] = time_buf[23];
time_buf[22] = ':';
time_buf[26] = '\0';
*value = dmstrdup(time_buf);
return 0;
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
@ -945,3 +994,34 @@ int browseDhcpClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da
return 0;
}
int browseDhcpClientIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
unsigned int leasetime;
char *macaddr;
char mac[32], ip[32], buf[512];
json_object *passed_args;
FILE *fp;
struct dhcp_client_ipv4address_args current_dhcp_client_ipv4address_args = {0};
int id = 0;
char *idx = NULL, *idx_last = NULL;
fp = fopen("/tmp/dhcp.leases", "r");
if (fp == NULL)
return 0;
while (fgets (buf , 256 , fp) != NULL) {
sscanf(buf, "%u %s %s", &leasetime, mac, ip);
passed_args= ((struct client_args*)prev_data)->client;
macaddr=dmjson_get_value(passed_args, 1, "macaddr");
if(!strcmp(mac, macaddr)){
current_dhcp_client_ipv4address_args.ip= dmjson_get_value(passed_args, 1, "ipddr");
current_dhcp_client_ipv4address_args.mac= strdup(macaddr);
current_dhcp_client_ipv4address_args.leasetime= leasetime;
idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&current_dhcp_client_ipv4address_args, idx) == DM_STOP)
break;
}
}
return 0;
}

View file

@ -30,17 +30,25 @@ struct client_args
char *key;
};
struct dhcp_client_ipv4address_args {
char *mac;
char *ip;
unsigned int leasetime;
};
extern DMOBJ tDhcpv4Obj[];
extern DMOBJ tDhcpv4ServerObj[];
extern DMOBJ tDhcpServerPoolObj[];
extern DMOBJ tDhcpServerPoolClientObj[];
extern DMLEAF tDhcpServerPoolParams[];
extern DMLEAF tDhcpServerPoolAddressParams[];
extern DMLEAF tDhcpServerPoolClientParams[];
extern DMLEAF tDhcpServerPoolClientIPv4AddressParams[];
int browseDhcpInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int browseDhcpStaticInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int browseDhcpClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int browseDhcpClientIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int add_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char **instancepara);
int delete_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action);
@ -49,6 +57,7 @@ int delete_dhcp_staticaddress(char *refparam, struct dmctx *ctx, void *data, cha
int get_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_dhcp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_dhcp_interval_address_min(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_dhcp_interval_address_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
@ -62,6 +71,7 @@ int get_dhcp_static_alias(char *refparam, struct dmctx *ctx, void *data, char *i
int get_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_dhcp_client_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_dhcp_client_ipv4address_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int set_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);

View file

@ -84,7 +84,15 @@ inline int init_eth_port(struct eth_port_args *args, struct uci_section *s, char
***************************************************************************/
int get_eth_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *eth_instance;
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "eth_port_alias", value);
if(*value == NULL || strlen(*value)<1)
{
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "eth_port_instance", &eth_instance);
dmasprintf(value, "cpe-%s", eth_instance);
}
return 0;
}

View file

@ -34,6 +34,8 @@ DMLEAF thostsParam[] = {
/*** Hosts.Host ***/
DMLEAF thostParam[] = {
{"AssociatedDevice", &DMREAD, DMT_STRING, get_host_associateddevice, NULL, NULL, &DMNONE},
{"Layer3Interface", &DMREAD, DMT_STRING, get_host_layer3interface, NULL, NULL, &DMNONE},
{"IPAddress", &DMREAD, DMT_STRING, get_host_ipaddress, NULL, NULL, &DMNONE},
{"HostName", &DMREAD, DMT_STRING, get_host_hostname, NULL, NULL, &DMNONE},
{"Active", &DMREAD, DMT_BOOL, get_host_active, NULL, NULL, &DMNONE},
@ -42,6 +44,8 @@ DMLEAF thostParam[] = {
{"AddressSource", &DMREAD, DMT_STRING, get_host_address_source, NULL, NULL, &DMNONE},
{"LeaseTimeRemaining", &DMREAD, DMT_STRING, get_host_leasetime_remaining, NULL, NULL, &DMNONE},
{"DHCPClient", &DMREAD, DMT_STRING, get_host_dhcp_client, NULL, NULL, NULL},
{"X_IOPSYS_InterfaceType", &DMREAD, DMT_STRING, get_host_interface_type, NULL, NULL, &DMNONE},
{"X_IOPSYS_ifname", &DMREAD, DMT_STRING, get_host_interfacename, NULL, NULL, &DMNONE},
{0}
};
@ -58,6 +62,60 @@ inline int init_host_args(struct host_args *args, json_object *clients, char *ke
/*************************************************************
* GET & SET PARAM
/*************************************************************/
int get_host_associateddevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ss;
char *macaddr_linker=dmjson_get_value(((struct host_args *)data)->client, 1, "macaddr");
char *accesspointInstance= NULL, *wifiAssociativeDeviecPath;
uci_foreach_sections("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)
*value = "";
return 0;
}
int get_host_layer3interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *ip_linker=dmjson_get_value(((struct host_args *)data)->client, 1, "network");
adm_entry_get_linker_param(ctx, "Device.IP.Interface.", ip_linker, value);
if (*value == NULL)
*value = "";
return 0;
}
int get_host_interface_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *type= NULL;
char *ifname = dmjson_get_value(((struct host_args *)data)->client, 1, "network");
struct uci_section *ss = NULL;
uci_foreach_sections("network", "interface", ss) {
if(!strcmp(ifname, section_name(ss))){
dmuci_get_value_by_section_string(ss, "type", &type);
if(type!=NULL){
if(!strcmp(type, "bridge")) *value="Bridge";else *value= "Normal";
break;
}
}
}
return 0;
}
int get_host_interfacename(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value(((struct host_args *)data)->client, 1, "network");
if (*value == NULL)
*value = "";
return 0;
}
int get_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmjson_get_value(((struct host_args *)data)->client, 1, "ipaddr");

View file

@ -24,6 +24,10 @@ extern DMOBJ thostsObj[];
int browsehostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_host_associateddevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_host_layer3interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_host_interface_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_host_interfacename(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_host_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_host_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);

View file

@ -34,6 +34,7 @@ DMOBJ tIPObj[] = {
DMLEAF tIPintParams[] = {
/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/
{"Enable", &DMWRITE, DMT_BOOL, get_ip_interface_enable, set_ip_interface_enable, NULL, NULL},
{"Status", &DMREAD, DMT_STRING, get_ip_interface_status, NULL, NULL, NULL},
{"Name", &DMREAD, DMT_STRING, get_ip_interface_name, NULL, NULL, NULL},
{"LowerLayers", &DMWRITE, DMT_STRING, get_ip_int_lower_layer, set_ip_int_lower_layer, NULL, NULL},
{0}
@ -340,6 +341,16 @@ int set_ip_interface_enable(char *refparam, struct dmctx *ctx, void *data, char
return 0;
}
int get_ip_interface_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
char *lan_name = section_name(((struct ip_args *)data)->ip_sec), *val= NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name, String}}, 1, &res);
val = dmjson_get_value(res, 1, "up");
*value = !strcmp(val, "true") ? "Up" : "Down";
return 0;
}
int get_ip_interface_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmstrdup(section_name(((struct ip_args *)data)->ip_sec));
@ -761,7 +772,6 @@ int delete_ipv6(char *refparam, struct dmctx *ctx, void *data, char *instance, u
* LINKER
***************************************************************************/
int get_linker_ip_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) {
if(((struct ip_args *)data)->ip_sec) {
dmasprintf(linker,"%s", section_name(((struct ip_args *)data)->ip_sec));
return 0;

View file

@ -40,6 +40,7 @@ int add_ipv6(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
int delete_ipv6(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action);
int get_ip_interface_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_ip_interface_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_ip_interface_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_ip_int_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);

View file

@ -0,0 +1,84 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2018 Inteno Broadband Technology AB
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include "dmuci.h"
#include "dmubus.h"
#include "dmcwmp.h"
#include "dmjson.h"
#include "dmcommon.h"
#include "userinterface.h"
/*** USerInterface. ***/
DMOBJ tUserInterfaceObj[] = {
/* OBJ, permission, addobj, delobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker(10)*/
{"RemoteAccess", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tUserIntRemoteAccessParam, NULL},
{0}
};
/*** USerInterface.RemoteAccess. ***/
DMLEAF tUserIntRemoteAccessParam[] = {
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification(7)*/
{"Enable", &DMWRITE, DMT_BOOL, get_userint_remoteaccesss_enable, set_userint_remoteaccesss_enable, NULL, NULL},
{0}
};
/**************************************************************************
* GET & SET PARAMETERS
***************************************************************************/
int get_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ss;
char *rule_name, *rule_target;
int section_found= 0;
uci_foreach_sections("firewall", "rule", ss) {
dmuci_get_value_by_section_string(ss, "name", &rule_name);
if(!strcmp(rule_name, "juci-remote-access")){
section_found= 1;
dmuci_get_value_by_section_string(ss, "target", &rule_target);
*value= !strcmp(rule_target, "ACCEPT") ? "1": "0";
return 0;
}
}
*value = "0";
return 0;
}
int set_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *ss;
char *rule_name, *rule_target;
int section_found= 0;
char *ret;
struct uci_ptr config;
uci_foreach_sections("firewall", "rule", ss) {
dmuci_get_value_by_section_string(ss, "name", &rule_name);
if(!strcmp(rule_name, "juci-remote-access")){
if(!strcmp(value, "1")) dmuci_set_value_by_section(ss, "target", "ACCEPT"); else dmuci_set_value_by_section(ss, "target", "REJECT");
return 0;
}
}
dmuci_add_section("firewall", "rule", &ss, &ret);
dmuci_set_value_by_section(ss, "name", "juci-remote-access");
dmuci_set_value_by_section(ss, "src", "wan");
dmuci_set_value_by_section(ss, "dest_port", "80");
dmuci_set_value_by_section(ss, "proto", "tcp");
dmuci_set_value_by_section(ss, "fruleinstance", "10");
if(!strcmp(value, "1")) dmuci_set_value_by_section(ss, "target", "ACCEPT"); else dmuci_set_value_by_section(ss, "target", "REJECT");
dmuci_commit();
return 0;
}

View file

@ -0,0 +1,21 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2016 Inteno Broadband Technology AB
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*
*/
#ifndef __USER_INTERFACE_H
#define __USER_INTERFACE_H
extern DMLEAF tUserIntRemoteAccessParam[];
extern DMOBJ tUserInterfaceObj[];
int get_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int set_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
#endif

View file

@ -107,6 +107,7 @@ DMLEAF tWifiSsidStatsParams[] = {
DMOBJ tAcessPointSecurityObj[] = {
/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/
{"Security", &DMWRITE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tWifiAcessPointSecurityParams, NULL},
{"AssociatedDevice", &DMREAD, NULL, NULL, NULL, browse_wifi_associated_device, NULL, NULL, NULL, tWifiAcessPointAssociatedDeviceParams, get_linker_associated_device},
{0}
};
@ -139,6 +140,17 @@ DMLEAF tWifiAcessPointSecurityParams[] = {
{0}
};
/*** WiFi.AccessPoint.AssociatedDevice. ***/
DMLEAF tWifiAcessPointAssociatedDeviceParams[] = {
/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/
{"Active", &DMREAD, DMT_BOOL, get_access_point_associative_device_active, NULL, NULL, NULL},
{"MACAddress", &DMREAD, DMT_STRING ,get_access_point_associative_device_mac, NULL, NULL, NULL},
{"LastDataDownlinkRate", &DMREAD, DMT_UNINT, get_access_point_associative_device_lastdatadownlinkrate, NULL, NULL, NULL},
{"LastDataUplinkRate", &DMREAD, DMT_UNINT, get_access_point_associative_device_lastdatauplinkrate, NULL, NULL, NULL},
{"SignalStrength", &DMREAD, DMT_INT, get_access_point_associative_device_signalstrength, NULL, NULL, NULL},
{0}
};
/**************************************************************************
* LINKER
***************************************************************************/
@ -159,6 +171,16 @@ int get_linker_Wifi_Ssid(char *refparam, struct dmctx *dmctx, void *data, char *
*linker = "";
return 0;
}
int get_linker_associated_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) {
struct wifi_associative_device_args* cur_wifi_associative_device_args = (struct wifi_associative_device_args*)data;
if(cur_wifi_associative_device_args->macaddress) {
*linker= cur_wifi_associative_device_args->macaddress;
return 0;
}
*linker = "";
return 0;
}
/**************************************************************************
* INIT
***************************************************************************/
@ -1058,6 +1080,41 @@ int get_radio_supported_frequency_bands(char *refparam, struct dmctx *ctx, void
*value = "2.4GHz, 5GHz";
return 0;
}
int get_access_point_associative_device_lastdatadownlinkrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data;
dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->lastdatadownloadlinkrate);
return 0;
}
int get_access_point_associative_device_lastdatauplinkrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data;
dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->lastdatauplinkrate);
return 0;
}
int get_access_point_associative_device_signalstrength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data;
dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->signalstrength);
return 0;
}
int get_access_point_associative_device_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data;
dmasprintf(value, cur_wifi_associative_device_args_ptr->macaddress);
return 0;
}
int get_access_point_associative_device_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct wifi_associative_device_args *cur_wifi_associative_device_args_ptr=(struct wifi_associative_device_args*)data;
dmasprintf(value, "%d", cur_wifi_associative_device_args_ptr->active);
return 0;
}
/**************************************************************************
* SET AND GET ALIAS
***************************************************************************/
@ -1251,3 +1308,53 @@ int browseWifiAccessPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *pr
}
return 0;
}
int browse_wifi_associated_device(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance){
json_object *res, *associated_client_obj;
struct uci_section *ss = NULL;
char *value, *ap_ifname, *ad_ifname, *is_wireless;
int id = 0;
char *idx, *idx_last = NULL;
char *macaddr= NULL, *active= NULL, *lastdatadownloadlinkrate= NULL, *lastdatauplinkrate= NULL, *signalstrength= NULL;
struct wifi_associative_device_args cur_wifi_associative_device_args = {0}, *args;
uci_foreach_sections("wireless", "wifi-iface", ss) {
dmuci_get_value_by_section_string(ss, "accesspointinstance", &value);
if(!strcmp(value, prev_instance)){
dmuci_get_value_by_section_string(ss, "ifname", &ap_ifname);
break;
}
}
dmubus_call("router.network", "clients", UBUS_ARGS{}, 0, &res);
if (res) {
json_object_object_foreach(res, key, associated_client_obj) {
is_wireless = dmjson_get_value(associated_client_obj, 1, "wireless");
if(!strcmp(is_wireless, "true")){
ad_ifname = dmjson_get_value(associated_client_obj, 1, "wdev");
if(!strcmp(ad_ifname, ap_ifname)){
macaddr=dmjson_get_value(associated_client_obj, 1, "macaddr");
if(macaddr!=NULL && strlen(macaddr)>0) dmasprintf(&(cur_wifi_associative_device_args.macaddress),dmjson_get_value(associated_client_obj, 1, "macaddr"));
active=dmjson_get_value(associated_client_obj, 1, "connected");
if(active !=NULL && strlen(active)>0){
if(!strcmp(active, "true")) cur_wifi_associative_device_args.active= 1; else cur_wifi_associative_device_args.active= 0;
}
lastdatadownloadlinkrate=dmjson_get_value(associated_client_obj, 1, "rx_rate");
if(lastdatadownloadlinkrate!=NULL && strlen(lastdatadownloadlinkrate)>0) cur_wifi_associative_device_args.lastdatadownloadlinkrate= atoi(lastdatadownloadlinkrate);
else cur_wifi_associative_device_args.lastdatadownloadlinkrate = 0;
lastdatauplinkrate=dmjson_get_value(associated_client_obj, 1, "tx_rate");
if(lastdatauplinkrate!=NULL && strlen(lastdatauplinkrate)>0) cur_wifi_associative_device_args.lastdatauplinkrate= atoi(lastdatauplinkrate);
else cur_wifi_associative_device_args.lastdatauplinkrate = 0;
signalstrength=dmjson_get_value(associated_client_obj, 1, "rssi");
if(signalstrength!=NULL && strlen(signalstrength)>0) cur_wifi_associative_device_args.signalstrength= atoi(signalstrength);
else cur_wifi_associative_device_args.signalstrength = 0;
args= &cur_wifi_associative_device_args;
idx = handle_update_instance(3, dmctx, &idx_last, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_wifi_associative_device_args, idx) == DM_STOP)
break;
}
}
}
}
}

View file

@ -28,6 +28,15 @@ struct wifi_acp_args
char *ifname;
};
struct wifi_associative_device_args
{
int active;
int lastdatadownloadlinkrate;
int lastdatauplinkrate;
int signalstrength;
char *macaddress;
};
extern DMOBJ tWifiObj[];
extern DMLEAF tWifiParams[];
extern DMOBJ tWifiRadioStatsObj[];
@ -37,12 +46,14 @@ extern DMLEAF tWifiAcessPointParams[];
extern DMLEAF tWifiSsidParams[];
extern DMLEAF tWifiRadioParams[];
extern DMLEAF tWifiAcessPointSecurityParams[];
extern DMLEAF tWifiAcessPointAssociatedDeviceParams[];
extern DMLEAF tWifiRadioStatsParams[];
extern DMLEAF tWifiSsidStatsParams[];
int browseWifiSsidInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int browseWifiAccessPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int browseWifiRadioInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int browse_wifi_associated_device(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int add_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char **instancepara);
int delete_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action);
@ -91,8 +102,14 @@ int get_access_point_security_modes(char *refparam, struct dmctx *ctx, void *dat
int get_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_access_point_associative_device_lastdatadownlinkrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_access_point_associative_device_lastdatauplinkrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_access_point_associative_device_signalstrength(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_access_point_associative_device_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_access_point_associative_device_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_linker_Wifi_Radio(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_linker_Wifi_Ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_linker_associated_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker);
int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);