static ssize_t store_gw_mode(struct kobject *kobj, struct attribute *attr, char *buff, size_t count) { struct net_device *net_dev = kobj_to_netdev(kobj); struct bat_priv *bat_priv = netdev_priv(net_dev); char *curr_gw_mode_str; int gw_mode_tmp = -1; if (buff[count - 1] == '\n') buff[count - 1] = '\0'; if (strncmp(buff, GW_MODE_OFF_NAME, strlen(GW_MODE_OFF_NAME)) == 0) gw_mode_tmp = GW_MODE_OFF; if (strncmp(buff, GW_MODE_CLIENT_NAME, strlen(GW_MODE_CLIENT_NAME)) == 0) gw_mode_tmp = GW_MODE_CLIENT; if (strncmp(buff, GW_MODE_SERVER_NAME, strlen(GW_MODE_SERVER_NAME)) == 0) gw_mode_tmp = GW_MODE_SERVER; if (gw_mode_tmp < 0) { bat_info(net_dev, "Invalid parameter for 'gw mode' setting received: " "%s\n", buff); return -EINVAL; } if (atomic_read(&bat_priv->gw_mode) == gw_mode_tmp) return count; switch (atomic_read(&bat_priv->gw_mode)) { case GW_MODE_CLIENT: curr_gw_mode_str = GW_MODE_CLIENT_NAME; break; case GW_MODE_SERVER: curr_gw_mode_str = GW_MODE_SERVER_NAME; break; default: curr_gw_mode_str = GW_MODE_OFF_NAME; break; } bat_info(net_dev, "Changing gw mode from: %s to: %s\n", curr_gw_mode_str, buff); gw_deselect(bat_priv); atomic_set(&bat_priv->gw_mode, (unsigned)gw_mode_tmp); return count; }
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; }
static void post_gw_deselect(struct net_device *net_dev) { struct bat_priv *bat_priv = netdev_priv(net_dev); gw_deselect(bat_priv); }