diff --git a/dmtree/tr181/wifi-iopsyswrt.c b/dmtree/tr181/wifi-iopsyswrt.c index 9683207f..a83710c7 100644 --- a/dmtree/tr181/wifi-iopsyswrt.c +++ b/dmtree/tr181/wifi-iopsyswrt.c @@ -223,107 +223,45 @@ int os__get_WiFiSSIDStats_UnknownProtoPacketsReceived(char *refparam, struct dmc return ssid_read_ubus(data, "rx_unknown_packets", value); } -static char *get_associative_device_statistics(struct wifi_associative_device_args *wifi_associative_device, char *key) -{ - json_object *res, *jobj; - char *macaddr, *stats = "0"; - int entries = 0; - - dmubus_call("wifix", "stations", UBUS_ARGS{{"vif", wifi_associative_device->wdev, String}}, 1, &res); - while (res) { - jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "stations"); - if(jobj) { - macaddr = dmjson_get_value(jobj, 1, "macaddr"); - if (!strcmp(macaddr, wifi_associative_device->macaddress)) { - stats = dmjson_get_value(jobj, 2, "stats", key); - if(*stats != '\0') - return stats; - } - entries++; - } else - break; - } - return stats; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.BytesSent!UBUS:wifix/stations/vif,@Name/stats.tx_total_bytes*/ +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.Stats.BytesSent!UBUS:wifi.ap.@Name/stations//stations[i-1].stats.tx_total_bytes*/ int os__get_access_point_associative_device_statistics_tx_bytes(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; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_total_bytes"); + *value = dmjson_get_value((json_object *)data, 2, "stats", "tx_total_bytes"); return 0; } -/*#Device.WiFi.AccessPoint.{i}.Stats.BytesReceived!UBUS:wifix/stations/vif,@Name/stats.rx_data_bytes*/ +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.Stats.BytesReceived!UBUS:wifi.ap.@Name/stations//stations[i-1].stats.rx_data_bytes*/ int os__get_access_point_associative_device_statistics_rx_bytes(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; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "rx_data_bytes"); + *value = dmjson_get_value((json_object *)data, 2, "stats", "rx_data_bytes"); return 0; } -/*#Device.WiFi.AccessPoint.{i}.Stats.PacketsSent!UBUS:wifix/stations/vif,@Name/stats.tx_total_pkts*/ +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.Stats.PacketsSent!UBUS:wifi.ap.@Name/stations//stations[i-1].stats.tx_total_pkts*/ int os__get_access_point_associative_device_statistics_tx_packets(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; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_total_pkts"); + *value = dmjson_get_value((json_object *)data, 2, "stats", "tx_total_pkts"); return 0; } -/*#Device.WiFi.AccessPoint.{i}.Stats.PacketsReceived!UBUS:wifix/stations/vif,@Name/stats.rx_data_pkts*/ +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.Stats.PacketsReceived!UBUS:wifi.ap.@Name/stations//stations[i-1].stats.rx_data_pkts*/ int os__get_access_point_associative_device_statistics_rx_packets(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; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "rx_data_pkts"); + *value = dmjson_get_value((json_object *)data, 2, "stats", "rx_data_pkts"); return 0; } -/*#Device.WiFi.AccessPoint.{i}.Stats.ErrorsSent!UBUS:wifix/stations/vif,@Name/stats.tx_failures*/ +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.Stats.ErrorsSent!UBUS:wifi.ap.@Name/stations//stations[i-1].stats.tx_failures*/ int os__get_access_point_associative_device_statistics_tx_errors(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; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_failures"); + *value = dmjson_get_value((json_object *)data, 2, "stats", "tx_failures"); return 0; } -/*#Device.WiFi.AccessPoint.{i}.Stats.RetransCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retries*/ +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.Stats.RetransCount!UBUS:wifi.ap.@Name/stations//stations[i-1].stats.tx_pkts_retries*/ int os__get_access_point_associative_device_statistics_retrans_count(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; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_pkts_retries"); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.FailedRetransCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retry_exhausted*/ -int os__get_access_point_associative_device_statistics_failed_retrans_count(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; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_pkts_retry_exhausted"); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.RetryCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retries*/ -int os__get_access_point_associative_device_statistics_retry_count(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; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_pkts_retries"); - return 0; -} - -/*#Device.WiFi.AccessPoint.{i}.Stats.MultipleRetryCount!UBUS:wifix/stations/vif,@Name/stats.tx_data_pkts_retried*/ -int os__get_access_point_associative_device_statistics_multiple_retry_count(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; - - *value = get_associative_device_statistics(cur_wifi_associative_device_args_ptr, "tx_data_pkts_retried"); + *value = dmjson_get_value((json_object *)data, 2, "stats", "tx_pkts_retries"); return 0; } @@ -503,14 +441,16 @@ int os__get_radio_possible_channels(char *refparam, struct dmctx *ctx, void *dat int os__get_WiFiRadio_SupportedOperatingChannelBandwidths(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res = NULL, *supp_channels = NULL; - char object[32]; + char object[32], *bandwidth = NULL; snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = ""); supp_channels = dmjson_select_obj_in_array_idx(res, 0, 1, "supp_channels"); if (supp_channels) - *value = dmjson_get_value(supp_channels, 1, "bandwidth"); + bandwidth = dmjson_get_value(supp_channels, 1, "bandwidth"); + if (bandwidth) + dmasprintf(value, "%sMHz", bandwidth); return 0; } @@ -518,12 +458,14 @@ int os__get_WiFiRadio_SupportedOperatingChannelBandwidths(char *refparam, struct int os__get_WiFiRadio_CurrentOperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - char object[32]; + char object[32], *bandwidth = NULL; snprintf(object, sizeof(object), "wifi.radio.%s", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec)); dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "bandwidth"); + bandwidth = dmjson_get_value(res, 1, "bandwidth"); + if (bandwidth) + dmasprintf(value, "%sMHz", bandwidth); return 0; } @@ -569,85 +511,35 @@ int os__get_radio_supported_standard(char *refparam, struct dmctx *ctx, void *da int os__get_access_point_total_associations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - json_object *res, *jobj; - int entries = 0; + json_object *res = NULL, *assoclist = NULL, *arrobj = NULL; + char object[32]; + int i = 0, entries = 0; - dmubus_call("wifix", "stations", UBUS_ARGS{{"vif", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res); - DM_ASSERT(res, *value = "0"); - while (1) { - jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "stations"); - if (jobj == NULL) - break; - entries++; + snprintf(object, sizeof(object), "wifi.ap.%s", ((struct wifi_acp_args *)data)->ifname); + dmubus_call(object, "assoclist", UBUS_ARGS{}, 0, &res); + if (res) { + dmjson_foreach_obj_in_array(res, arrobj, assoclist, i, 1, "assoclist") { + entries++; + } } - dmasprintf(value, "%d", entries); // MEM WILL BE FREED IN DMMEMCLEAN + dmasprintf(value, "%d", entries); return 0; } int os__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, *idx, *idx_last = NULL; - int id = 0, entries = 0; - char *macaddr = NULL, *lastdatadownloadlinkrate = NULL, *lastdatauplinkrate = NULL, *signalstrength = NULL, *noise = NULL, *retrans = NULL, *assoctimestr = NULL; - struct wifi_associative_device_args cur_wifi_associative_device_args = {0}; - struct uci_section *dmmap_section; + json_object *res = NULL, *stations = NULL, *arrobj = NULL; + char object[32], *idx, *idx_last = NULL; + int id = 0, i = 0; - uci_foreach_sections("wireless", "wifi-iface", ss) { - get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ss), &dmmap_section); - dmuci_get_value_by_section_string(dmmap_section, "accesspointinstance", &value); - if(!strcmp(value, prev_instance)){ - dmuci_get_value_by_section_string(ss, "ifname", &ap_ifname); - break; - } - } - - dmubus_call("wifix", "stations", UBUS_ARGS{{"vif", ap_ifname, String}}, 1, &res); - while (res) { - associated_client_obj = dmjson_select_obj_in_array_idx(res, entries, 1, "stations"); - if(associated_client_obj) { - cur_wifi_associative_device_args.wdev = 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")); - cur_wifi_associative_device_args.active = 1; - lastdatadownloadlinkrate = dmjson_get_value(associated_client_obj, 2, "stats", "rate_of_last_rx_pkt"); - 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, 2, "stats", "rate_of_last_tx_pkt"); - 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; - noise=dmjson_get_value(associated_client_obj, 1, "snr"); - if(noise!=NULL && strlen(noise)>0) - cur_wifi_associative_device_args.noise = atoi(noise); - else - cur_wifi_associative_device_args.noise = 0; - retrans= dmjson_get_value(associated_client_obj, 2, "stats", "tx_pkts_retries"); - cur_wifi_associative_device_args.retransmissions= atoi(retrans); - - assoctimestr=dmjson_get_value(associated_client_obj, 1, "in_network"); - if(assoctimestr!=NULL && strlen(assoctimestr)>0) - cur_wifi_associative_device_args.assoctime = atoi(assoctimestr); - else - cur_wifi_associative_device_args.assoctime = 0; - - entries++; + snprintf(object, sizeof(object), "wifi.ap.%s", ((struct wifi_acp_args *)prev_data)->ifname); + dmubus_call(object, "stations", UBUS_ARGS{}, 0, &res); + if (res) { + dmjson_foreach_obj_in_array(res, arrobj, stations, i, 1, "stations") { 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; + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)stations, idx) == DM_STOP) + return 0; } - else - break; } return 0; } diff --git a/dmtree/tr181/wifi-openwrt.c b/dmtree/tr181/wifi-openwrt.c index 0bcb35f7..e5cdd04d 100644 --- a/dmtree/tr181/wifi-openwrt.c +++ b/dmtree/tr181/wifi-openwrt.c @@ -192,73 +192,61 @@ int os__get_WiFiSSIDStats_UnknownProtoPacketsReceived(char *refparam, struct dmc return not_implemented(value); } -/*#Device.WiFi.AccessPoint.{i}.Stats.BytesSent!UBUS:wifix/stations/vif,@Name/stats.tx_total_bytes*/ int os__get_access_point_associative_device_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.AccessPoint.{i}.Stats.BytesReceived!UBUS:wifix/stations/vif,@Name/stats.rx_data_bytes*/ int os__get_access_point_associative_device_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.AccessPoint.{i}.Stats.PacketsSent!UBUS:wifix/stations/vif,@Name/stats.tx_total_pkts*/ int os__get_access_point_associative_device_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.AccessPoint.{i}.Stats.PacketsReceived!UBUS:wifix/stations/vif,@Name/stats.rx_data_pkts*/ int os__get_access_point_associative_device_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.AccessPoint.{i}.Stats.ErrorsSent!UBUS:wifix/stations/vif,@Name/stats.tx_failures*/ int os__get_access_point_associative_device_statistics_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.AccessPoint.{i}.Stats.RetransCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retries*/ int os__get_access_point_associative_device_statistics_retrans_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.AccessPoint.{i}.Stats.FailedRetransCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retry_exhausted*/ int os__get_access_point_associative_device_statistics_failed_retrans_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.AccessPoint.{i}.Stats.RetryCount!UBUS:wifix/stations/vif,@Name/stats.tx_pkts_retries*/ int os__get_access_point_associative_device_statistics_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.AccessPoint.{i}.Stats.MultipleRetryCount!UBUS:wifix/stations/vif,@Name/stats.tx_data_pkts_retried*/ int os__get_access_point_associative_device_statistics_multiple_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.Radio.{i}.MaxBitRate!UBUS:wifi.radio.@Name/status//maxrate*/ int os__get_radio_max_bit_rate (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.Radio.{i}.OperatingFrequencyBand!UBUS:wifi.radio.@Name/status//band*/ int os__get_radio_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.Radio.{i}.ChannelsInUse!UCI:wireless/wifi-device,@i-1/channel*/ int os__get_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); @@ -314,19 +302,16 @@ int os__get_neighboring_wifi_diagnostics_result_noise(char *refparam, struct dmc return not_implemented(value); } -/*#Device.WiFi.Radio.{i}.PossibleChannels!UBUS:wifi.radio.@Name/status//supp_channels[0].channels*/ int os__get_radio_possible_channels(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.Radio.{i}.SupportedOperatingChannelBandwidths!UBUS:wifi.radio.@Name/status//supp_channels[0].bandwidth*/ int os__get_WiFiRadio_SupportedOperatingChannelBandwidths(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); } -/*#Device.WiFi.Radio.{i}.CurrentOperatingChannelBandwidth!UBUS:wifi.radio.@Name/status//bandwidth*/ int os__get_WiFiRadio_CurrentOperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); @@ -341,7 +326,6 @@ int os__browseWifiNeighboringWiFiDiagnosticResultInst(struct dmctx *dmctx, DMNOD return 0; } -/*#Device.WiFi.Radio.{i}.SupportedStandards!UBUS:wifi/status//radio[i-1].standard*/ int os__get_radio_supported_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return not_implemented(value); diff --git a/dmtree/tr181/wifi.c b/dmtree/tr181/wifi.c index 912b964c..6ab444c5 100644 --- a/dmtree/tr181/wifi.c +++ b/dmtree/tr181/wifi.c @@ -41,8 +41,8 @@ static int get_linker_Wifi_Ssid(char *refparam, struct dmctx *dmctx, void *data, static int get_linker_associated_device(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { - if (data && ((struct wifi_associative_device_args*)data)->macaddress) { - *linker = ((struct wifi_associative_device_args*)data)->macaddress; + if (data) { + *linker = dmjson_get_value((json_object *)data, 1, "macaddr"); return 0; } *linker = ""; @@ -358,6 +358,8 @@ static int set_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, ch static int get_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", value); + if (strcmp(*value, "auto") == 0) + *value = "n"; return 0; } @@ -1468,60 +1470,70 @@ static int get_radio_supported_frequency_bands(char *refparam, struct dmctx *ctx return 0; } +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.LastDataDownlinkRate!UBUS:wifi.ap.@Name/stations//stations[i-1].stats.rate_of_last_rx_pkt*/ static 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); + *value = dmjson_get_value((json_object *)data, 2, "stats", "rate_of_last_rx_pkt"); return 0; } +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.LastDataUplinkRate!UBUS:wifi.ap.@Name/stations//stations[i-1].stats.rate_of_last_tx_pkt*/ static 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); + *value = dmjson_get_value((json_object *)data, 2, "stats", "rate_of_last_tx_pkt"); return 0; } +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.SignalStrength!UBUS:wifi.ap.@Name/stations//stations[i-1].rssi*/ static 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); + *value = dmjson_get_value((json_object *)data, 1, "rssi"); return 0; } +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.Retransmissions!UBUS:wifi.ap.@Name/stations//stations[i-1].stats.tx_pkts_retries*/ static int get_WiFiAccessPointAssociatedDevice_Retransmissions(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->retransmissions); + *value = dmjson_get_value((json_object *)data, 2, "stats", "tx_pkts_retries"); return 0; } +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.AssociationTime!UBUS:wifi.ap.@Name/stations//stations[i-1].in_network*/ static int get_WiFiAccessPointAssociatedDevice_AssociationTime(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, "%s", cur_wifi_associative_device_args_ptr->assoctime?int_period_to_date_time_format(cur_wifi_associative_device_args_ptr->assoctime):"0"); + char local_time[32] = {0}; + time_t t_time; + + *value = "0001-01-01T00:00:00Z"; + char *in_network = dmjson_get_value((json_object *)data, 1, "in_network"); + t_time = time(NULL) - atoi(in_network); + if (localtime(&t_time) == NULL) + return -1; + + if (strftime(local_time, sizeof(local_time), "%Y-%m-%dT%H:%M:%SZ", localtime(&t_time)) == 0) + return -1; + + *value = dmstrdup(local_time); return 0; } +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.MACAddress!UBUS:wifi.ap.@Name/stations//stations[i-1].macaddr*/ static 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); + *value = dmjson_get_value((json_object *)data, 1, "macaddr"); return 0; } static 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, "%s", cur_wifi_associative_device_args_ptr->active?"true":"false"); + *value = "true"; return 0; } - +/*#Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.Noise!UBUS:wifi.ap.@Name/stations//stations[i-1].tx_failures*/ static int get_WiFiAccessPointAssociatedDevice_Noise(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->noise); + *value = dmjson_get_value((json_object *)data, 1, "snr"); return 0; } @@ -2610,15 +2622,15 @@ DMLEAF tWiFiAccessPointAssociatedDeviceParams[] = { /* *** Device.WiFi.AccessPoint.{i}.AssociatedDevice.{i}.Stats. *** */ DMLEAF tWiFiAccessPointAssociatedDeviceStatsParams[] = { /* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"BytesSent", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_tx_bytes, NULL, NULL, NULL, BBFDM_BOTH}, -{"BytesReceived", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_rx_bytes, NULL, NULL, NULL, BBFDM_BOTH}, -{"PacketsSent", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_tx_packets, NULL, NULL, NULL, BBFDM_BOTH}, -{"PacketsReceived", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_rx_packets, NULL, NULL, NULL, BBFDM_BOTH}, +{"BytesSent", &DMREAD, DMT_UNLONG, os__get_access_point_associative_device_statistics_tx_bytes, NULL, NULL, NULL, BBFDM_BOTH}, +{"BytesReceived", &DMREAD, DMT_UNLONG, os__get_access_point_associative_device_statistics_rx_bytes, NULL, NULL, NULL, BBFDM_BOTH}, +{"PacketsSent", &DMREAD, DMT_UNLONG, os__get_access_point_associative_device_statistics_tx_packets, NULL, NULL, NULL, BBFDM_BOTH}, +{"PacketsReceived", &DMREAD, DMT_UNLONG, os__get_access_point_associative_device_statistics_rx_packets, NULL, NULL, NULL, BBFDM_BOTH}, {"ErrorsSent", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_tx_errors, NULL, NULL, NULL, BBFDM_BOTH}, {"RetransCount", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_retrans_count, NULL, NULL, NULL, BBFDM_BOTH}, -{"FailedRetransCount", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_failed_retrans_count, NULL, NULL, NULL, BBFDM_BOTH}, -{"RetryCount", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_retry_count, NULL, NULL, NULL, BBFDM_BOTH}, -{"MultipleRetryCount", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_multiple_retry_count, NULL, NULL, NULL, BBFDM_BOTH}, +//{"FailedRetransCount", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_failed_retrans_count, NULL, NULL, NULL, BBFDM_BOTH}, +//{"RetryCount", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_retry_count, NULL, NULL, NULL, BBFDM_BOTH}, +//{"MultipleRetryCount", &DMREAD, DMT_UNINT, os__get_access_point_associative_device_statistics_multiple_retry_count, NULL, NULL, NULL, BBFDM_BOTH}, {0} }; diff --git a/dmtree/tr181/wifi.h b/dmtree/tr181/wifi.h index 613b3d08..cd0a33c9 100644 --- a/dmtree/tr181/wifi.h +++ b/dmtree/tr181/wifi.h @@ -68,17 +68,4 @@ struct wifi_acp_args char *ifname; }; -struct wifi_associative_device_args -{ - int active; - int lastdatadownloadlinkrate; - int lastdatauplinkrate; - int signalstrength; - char *macaddress; - char *wdev; - int noise; - int retransmissions; - int assoctime; -}; - #endif diff --git a/json/tr181.json b/json/tr181.json index 2b2200df..95ead811 100644 --- a/json/tr181.json +++ b/json/tr181.json @@ -937,9 +937,9 @@ "type": "ubus", "ubus": { "object": "router.system", - "method": "info", + "method": "memory", "args": {}, - "key": "memoryKB.total" + "key": "total" } } ] @@ -959,9 +959,9 @@ "type": "ubus", "ubus": { "object": "router.system", - "method": "info", + "method": "memory", "args": {}, - "key": "memoryKB.free" + "key": "free" } } ] @@ -995,9 +995,9 @@ "type": "ubus", "ubus": { "object": "router.system", - "method": "info", + "method": "process", "args": {}, - "key": "system.cpu_per" + "key": "cpu_usage" } } ] @@ -29079,15 +29079,6 @@ "name": "bandwidth" } } - }, - { - "type": "ubus", - "ubus": { - "object": "wifi.radio.@Name", - "method": "status", - "args": {}, - "key": "bandwidth" - } } ] }, @@ -31603,6 +31594,17 @@ ], "pattern": [ "([0-9A-Fa-f][0-9A-Fa-f]:){5}([0-9A-Fa-f][0-9A-Fa-f])" + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].macaddr" + } + } ] }, "OperatingStandard": { @@ -31647,7 +31649,18 @@ "min": 1000 } ], - "unit": "kbps" + "unit": "kbps", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].stats.rate_of_last_rx_pkt" + } + } + ] }, "LastDataUplinkRate": { "type": "unsignedInt", @@ -31663,7 +31676,18 @@ "min": 1000 } ], - "unit": "kbps" + "unit": "kbps", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].stats.rate_of_last_tx_pkt" + } + } + ] }, "AssociationTime": { "type": "dateTime", @@ -31673,7 +31697,18 @@ "cwmp", "usp" ], - "datatype": "dateTime" + "datatype": "dateTime", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].in_network" + } + } + ] }, "SignalStrength": { "type": "int", @@ -31690,7 +31725,18 @@ "max": 0 } ], - "unit": "dBm" + "unit": "dBm", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].rssi" + } + } + ] }, "Noise": { "type": "int", @@ -31707,7 +31753,18 @@ "max": 0 } ], - "unit": "dBm" + "unit": "dBm", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].tx_failures" + } + } + ] }, "Retransmissions": { "type": "unsignedInt", @@ -31724,7 +31781,18 @@ "max": 100 } ], - "unit": "packets" + "unit": "packets", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].stats.tx_pkts_retries" + } + } + ] }, "Active": { "type": "boolean", @@ -31752,7 +31820,18 @@ "cwmp", "usp" ], - "datatype": "StatsCounter64" + "datatype": "StatsCounter64", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].stats.tx_total_bytes" + } + } + ] }, "BytesReceived": { "type": "unsignedInt", @@ -31762,7 +31841,18 @@ "cwmp", "usp" ], - "datatype": "StatsCounter64" + "datatype": "StatsCounter64", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].stats.rx_data_bytes" + } + } + ] }, "PacketsSent": { "type": "unsignedInt", @@ -31772,7 +31862,18 @@ "cwmp", "usp" ], - "datatype": "StatsCounter64" + "datatype": "StatsCounter64", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].stats.tx_total_pkts" + } + } + ] }, "PacketsReceived": { "type": "unsignedInt", @@ -31782,7 +31883,18 @@ "cwmp", "usp" ], - "datatype": "StatsCounter64" + "datatype": "StatsCounter64", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].stats.rx_data_pkts" + } + } + ] }, "ErrorsSent": { "type": "unsignedInt", @@ -31792,7 +31904,18 @@ "cwmp", "usp" ], - "datatype": "StatsCounter32" + "datatype": "StatsCounter32", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].stats.tx_failures" + } + } + ] }, "RetransCount": { "type": "unsignedInt", @@ -31802,7 +31925,18 @@ "cwmp", "usp" ], - "datatype": "StatsCounter32" + "datatype": "StatsCounter32", + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "wifi.ap.@Name", + "method": "stations", + "args": {}, + "key": "stations[i-1].stats.tx_pkts_retries" + } + } + ] }, "FailedRetransCount": { "type": "unsignedInt", @@ -37892,6 +38026,21 @@ "Enabled", "Error_Misconfigured", "Error" + ], + "mapping": [ + { + "type": "uci", + "uci": { + "file": "network", + "section": { + "type": "interface", + "index": "@i-1" + }, + "option": { + "name": "disabled" + } + } + } ] }, "Alias": { diff --git a/tools/generate_json.py b/tools/generate_json.py index 815e1f31..d2a1fdd4 100755 --- a/tools/generate_json.py +++ b/tools/generate_json.py @@ -217,18 +217,24 @@ def generatelistfromfile(dmobject): obj = dmobject.get('name').split(".") if "tr-104" in sys.argv[1]: pathfilename = "../dmtree/tr104/voice_services.c" + pathiopsyswrtfilename = "../dmtree/tr104/voice_services-iopsyswrt.c" elif obj[1] == "SoftwareModules" or obj[1] == "BulkData" : pathfilename = "../dmtree/tr157/" + obj[1].lower() + ".c" + pathiopsyswrtfilename = "../dmtree/tr157/" + obj[1].lower() + "-iopsyswrt.c" else: pathfilename = "../dmtree/tr181/" + obj[1].lower() + ".c" - exists = os.path.isfile(pathfilename) - if exists: - filec = open(pathfilename, "r") - for linec in filec: - if "/*#" in linec: - listmapping.append(linec) - else: - pass + pathiopsyswrtfilename = "../dmtree/tr181/" + obj[1].lower() + "-iopsyswrt.c" + + for x in range(0, 2): + pathfile = pathfilename if x == 0 else pathiopsyswrtfilename + exists = os.path.isfile(pathfile) + if exists: + filec = open(pathfile, "r") + for linec in filec: + if "/*#" in linec: + listmapping.append(linec) + else: + pass def getparammapping(dmobject, dmparam): hasmapping = 0