+ /* Check value type */
+ if(!strcasecmp(args[i], "period"))
+ {
+ wrq.u.power.flags |= IW_POWER_PERIOD;
+ if(++i >= count)
+ ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
+ }
+ else
+ if(!strcasecmp(args[i], "timeout"))
+ {
+ wrq.u.power.flags |= IW_POWER_TIMEOUT;
+ if(++i >= count)
+ ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER);
+ }
+
+ /* Is there any value to grab ? */
+ if(sscanf(args[i], "%lg", &(temp)) == 1)
+ {
+ temp *= MEGA; /* default = s */
+ if(index(args[i], 'u')) temp /= MEGA;
+ if(index(args[i], 'm')) temp /= KILO;
+ wrq.u.power.value = (long) temp;
+ if((wrq.u.power.flags & IW_POWER_TYPE) == 0)
+ wrq.u.power.flags |= IW_POWER_PERIOD;
+ ++i;
+ gotone = 1;
+ }
+
+ /* Now, check the mode */
+ if(i < count)
+ {
+ if(!strcasecmp(args[i], "all"))
+ wrq.u.power.flags |= IW_POWER_ALL_R;
+ if(!strncasecmp(args[i], "unicast", 4))
+ wrq.u.power.flags |= IW_POWER_UNICAST_R;
+ if(!strncasecmp(args[i], "multicast", 5))
+ wrq.u.power.flags |= IW_POWER_MULTICAST_R;
+ if(!strncasecmp(args[i], "force", 5))
+ wrq.u.power.flags |= IW_POWER_FORCE_S;
+ if(!strcasecmp(args[i], "repeat"))
+ wrq.u.power.flags |= IW_POWER_REPEATER;
+ if(wrq.u.power.flags & IW_POWER_MODE)
+ {
+ ++i;
+ gotone = 1;
+ }
+ }
+ if(!gotone)
+ ABORT_ARG_TYPE("Set Power Management", SIOCSIWPOWER,
+ args[i]);
+ --i;
+ }
+
+ IW_SET_EXT_ERR(skfd, ifname, SIOCSIWPOWER, &wrq,
+ "Set Power Management");
+ continue;
+ }
+
+ /* ---------- Set Transmit-Power ---------- */
+ if(!strncmp(args[i], "txpower", 3))
+ {
+ struct iw_range range;
+
+ if(++i >= count)
+ ABORT_ARG_NUM("Set Tx Power", SIOCSIWTXPOW);
+
+ /* Extract range info */
+ if(iw_get_range_info(skfd, ifname, &range) < 0)
+ memset(&range, 0, sizeof(range));
+
+ /* Prepare the request */
+ wrq.u.txpower.value = -1;
+ wrq.u.txpower.fixed = 1;
+ wrq.u.txpower.disabled = 0;
+ wrq.u.txpower.flags = IW_TXPOW_DBM;
+ if(!strcasecmp(args[i], "off"))
+ wrq.u.txpower.disabled = 1; /* i.e. turn radio off */
+ else
+ if(!strcasecmp(args[i], "auto"))
+ wrq.u.txpower.fixed = 0; /* i.e. use power control */
+ else
+ {
+ if(!strcasecmp(args[i], "on"))
+ {
+ /* Get old tx-power */
+ IW_GET_EXT_ERR(skfd, ifname, SIOCGIWTXPOW, &wrq,
+ "Set Tx Power");
+ wrq.u.txpower.disabled = 0;
+ }
+ else
+ {
+ if(!strcasecmp(args[i], "fixed"))
+ {
+ /* Get old tx-power */
+ IW_GET_EXT_ERR(skfd, ifname, SIOCGIWTXPOW, &wrq,
+ "Set Tx Power");
+ wrq.u.txpower.fixed = 1;
+ wrq.u.txpower.disabled = 0;
+ }
+ else /* Should be a numeric value */
+ {
+ int power;
+ int ismwatt = 0;
+
+ /* Get the value */
+ if(sscanf(args[i], "%i", &(power)) != 1)
+ ABORT_ARG_TYPE("Set Tx Power", SIOCSIWTXPOW,
+ args[i]);
+
+ /* Check if milliwatt */
+ ismwatt = (index(args[i], 'm') != NULL);
+
+ /* Convert */
+ if(range.txpower_capa & IW_TXPOW_RELATIVE)
+ {
+ /* Can't convert */
+ if(ismwatt)
+ ABORT_ARG_TYPE("Set Tx Power",
+ SIOCSIWTXPOW,
+ args[i]);
+ }
+ else
+ if(range.txpower_capa & IW_TXPOW_MWATT)
+ {
+ if(!ismwatt)
+ power = iw_dbm2mwatt(power);
+ wrq.u.txpower.flags = IW_TXPOW_MWATT;
+ }
+ else
+ {
+ if(ismwatt)
+ power = iw_mwatt2dbm(power);
+ wrq.u.txpower.flags = IW_TXPOW_DBM;
+ }
+ wrq.u.txpower.value = power;
+
+ /* Check for an additional argument */
+ if(((i+1) < count) &&
+ (!strcasecmp(args[i+1], "auto")))
+ {
+ wrq.u.txpower.fixed = 0;
+ ++i;
+ }
+ if(((i+1) < count) &&
+ (!strcasecmp(args[i+1], "fixed")))
+ {
+ wrq.u.txpower.fixed = 1;
+ ++i;
+ }
+ }
+ }
+ }
+
+ IW_SET_EXT_ERR(skfd, ifname, SIOCSIWTXPOW, &wrq,
+ "Set Tx Power");
+ continue;
+ }
+
+ /* ---------- Set Retry limit ---------- */
+ if(!strncmp(args[i], "retry", 3))
+ {
+ double temp;
+ int gotone = 0;
+
+ if(++i >= count)
+ ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);
+
+ /* Default - nope */
+ wrq.u.retry.flags = IW_RETRY_LIMIT;
+ wrq.u.retry.disabled = 0;
+
+ /* Check value modifier */
+ if(!strcasecmp(args[i], "min"))
+ {
+ wrq.u.retry.flags |= IW_RETRY_MIN;
+ if(++i >= count)
+ ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY);