static ssize_t show_gw_bwidth(struct kobject *kobj, struct attribute *attr, char *buff) { struct bat_priv *bat_priv = kobj_to_batpriv(kobj); int down, up; int gw_bandwidth = atomic_read(&bat_priv->gw_bandwidth); gw_bandwidth_to_kbit(gw_bandwidth, &down, &up); return sprintf(buff, "%i%s/%i%s\n", (down > 2048 ? down / 1024 : down), (down > 2048 ? "MBit" : "KBit"), (up > 2048 ? up / 1024 : up), (up > 2048 ? "MBit" : "KBit")); }
ssize_t gw_bandwidth_set(struct net_device *net_dev, char *buff, size_t count) { struct bat_priv *bat_priv = netdev_priv(net_dev); long gw_bandwidth_tmp = 0, up = 0, down = 0; bool ret; ret = parse_gw_bandwidth(net_dev, buff, &up, &down); if (!ret) goto end; if ((!down) || (down < 256)) down = 2000; if (!up) up = down / 5; kbit_to_gw_bandwidth(down, up, &gw_bandwidth_tmp); /** * the gw bandwidth we guessed above might not match the given * speeds, hence we need to calculate it back to show the number * that is going to be propagated **/ gw_bandwidth_to_kbit((uint8_t)gw_bandwidth_tmp, (int *)&down, (int *)&up); gw_deselect(bat_priv); bat_info(net_dev, "Changing gateway bandwidth from: '%i' to: '%ld' " "(propagating: %ld%s/%ld%s)\n", atomic_read(&bat_priv->gw_bandwidth), gw_bandwidth_tmp, (down > 2048 ? down / 1024 : down), (down > 2048 ? "MBit" : "KBit"), (up > 2048 ? up / 1024 : up), (up > 2048 ? "MBit" : "KBit")); atomic_set(&bat_priv->gw_bandwidth, gw_bandwidth_tmp); end: return count; }