X-Git-Url: http://git.osdn.net/view?p=android-x86%2Fexternal-wireless-tools.git;a=blobdiff_plain;f=wireless_tools%2Fiwconfig.c;h=ace3f8cfc4a42213bf2c3bc32837262fc1d053f7;hp=3fa06111780ae2ed3712dfd5ecd2241bf2831ee4;hb=9d82610feb36dcd56d621e7831cbf5eec3f51104;hpb=db34c20cecd8e65eca87ef9a5397b6b69c24dcad diff --git a/wireless_tools/iwconfig.c b/wireless_tools/iwconfig.c index 3fa0611..ace3f8c 100644 --- a/wireless_tools/iwconfig.c +++ b/wireless_tools/iwconfig.c @@ -1,14 +1,14 @@ /* * Wireless Tools * - * Jean II - HPLB 97->99 - HPL 99->01 + * Jean II - HPLB 97->99 - HPL 99->04 * * Main code for "iwconfig". This is the generic tool for most * manipulations... * You need to link this code against "iwlib.c" and "-lm". * * This file is released under the GPL license. - * Copyright (c) 1997-2002 Jean Tourrilhes + * Copyright (c) 1997-2004 Jean Tourrilhes */ #include "iwlib.h" /* Header */ @@ -27,6 +27,7 @@ iw_usage(void) fprintf(stderr, " [mode {managed|ad-hoc|...}\n"); fprintf(stderr, " [freq N.NNNN[k|M|G]]\n"); fprintf(stderr, " [channel N]\n"); + fprintf(stderr, " [ap {N|off|auto}]\n"); fprintf(stderr, " [sens N]\n"); fprintf(stderr, " [nick N]\n"); fprintf(stderr, " [rate {N|auto|fixed}]\n"); @@ -57,43 +58,24 @@ get_info(int skfd, memset((char *) info, 0, sizeof(struct wireless_info)); - /* Get wireless name */ - if(iw_get_ext(skfd, ifname, SIOCGIWNAME, &wrq) < 0) + /* Get basic information */ + if(iw_get_basic_config(skfd, ifname, &(info->b)) < 0) { /* If no wireless name : no wireless extensions */ /* But let's check if the interface exists at all */ struct ifreq ifr; - strcpy(ifr.ifr_name, ifname); + strncpy(ifr.ifr_name, ifname, IFNAMSIZ); if(ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) return(-ENODEV); else return(-ENOTSUP); } - else - { - strncpy(info->name, wrq.u.name, IFNAMSIZ); - info->name[IFNAMSIZ] = '\0'; - } /* Get ranges */ if(iw_get_range_info(skfd, ifname, &(info->range)) >= 0) info->has_range = 1; - /* Get network ID */ - if(iw_get_ext(skfd, ifname, SIOCGIWNWID, &wrq) >= 0) - { - info->has_nwid = 1; - memcpy(&(info->nwid), &(wrq.u.nwid), sizeof(iwparam)); - } - - /* Get frequency / channel */ - if(iw_get_ext(skfd, ifname, SIOCGIWFREQ, &wrq) >= 0) - { - info->has_freq = 1; - info->freq = iw_freq2float(&(wrq.u.freq)); - } - /* Get sensitivity */ if(iw_get_ext(skfd, ifname, SIOCGIWSENS, &wrq) >= 0) { @@ -101,27 +83,6 @@ get_info(int skfd, memcpy(&(info->sens), &(wrq.u.sens), sizeof(iwparam)); } - /* Get encryption information */ - wrq.u.data.pointer = (caddr_t) info->key; - wrq.u.data.length = IW_ENCODING_TOKEN_MAX; - wrq.u.data.flags = 0; - if(iw_get_ext(skfd, ifname, SIOCGIWENCODE, &wrq) >= 0) - { - info->has_key = 1; - info->key_size = wrq.u.data.length; - info->key_flags = wrq.u.data.flags; - } - - /* Get ESSID */ - wrq.u.essid.pointer = (caddr_t) info->essid; - wrq.u.essid.length = IW_ESSID_MAX_SIZE + 1; - wrq.u.essid.flags = 0; - if(iw_get_ext(skfd, ifname, SIOCGIWESSID, &wrq) >= 0) - { - info->has_essid = 1; - info->essid_on = wrq.u.data.flags; - } - /* Get AP address */ if(iw_get_ext(skfd, ifname, SIOCGIWAP, &wrq) >= 0) { @@ -158,14 +119,6 @@ get_info(int skfd, memcpy(&(info->frag), &(wrq.u.frag), sizeof(iwparam)); } - /* Get operation mode */ - if(iw_get_ext(skfd, ifname, SIOCGIWMODE, &wrq) >= 0) - { - info->mode = wrq.u.mode; - if((info->mode < IW_NUM_OPER_MODE) && (info->mode >= 0)) - info->has_mode = 1; - } - /* Get Power Management settings */ wrq.u.power.flags = 0; if(iw_get_ext(skfd, ifname, SIOCGIWPOWER, &wrq) >= 0) @@ -174,26 +127,29 @@ get_info(int skfd, memcpy(&(info->power), &(wrq.u.power), sizeof(iwparam)); } -#if WIRELESS_EXT > 9 - /* Get Transmit Power */ - if(iw_get_ext(skfd, ifname, SIOCGIWTXPOW, &wrq) >= 0) + if((info->has_range) && (info->range.we_version_compiled > 9)) { - info->has_txpower = 1; - memcpy(&(info->txpower), &(wrq.u.txpower), sizeof(iwparam)); + /* Get Transmit Power */ + if(iw_get_ext(skfd, ifname, SIOCGIWTXPOW, &wrq) >= 0) + { + info->has_txpower = 1; + memcpy(&(info->txpower), &(wrq.u.txpower), sizeof(iwparam)); + } } -#endif -#if WIRELESS_EXT > 10 - /* Get retry limit/lifetime */ - if(iw_get_ext(skfd, ifname, SIOCGIWRETRY, &wrq) >= 0) + if((info->has_range) && (info->range.we_version_compiled > 10)) { - info->has_retry = 1; - memcpy(&(info->retry), &(wrq.u.retry), sizeof(iwparam)); + /* Get retry limit/lifetime */ + if(iw_get_ext(skfd, ifname, SIOCGIWRETRY, &wrq) >= 0) + { + info->has_retry = 1; + memcpy(&(info->retry), &(wrq.u.retry), sizeof(iwparam)); + } } -#endif /* WIRELESS_EXT > 10 */ /* Get stats */ - if(iw_get_stats(skfd, ifname, &(info->stats)) >= 0) + if(iw_get_stats(skfd, ifname, &(info->stats), + &info->range, info->has_range) >= 0) { info->has_stats = 1; } @@ -216,19 +172,19 @@ display_info(struct wireless_info * info, int tokens = 3; /* For name */ /* Display device name and wireless name (name of the protocol used) */ - printf("%-8.8s %s ", ifname, info->name); + printf("%-8.16s %s ", ifname, info->b.name); /* Display ESSID (extended network), if any */ - if(info->has_essid) + if(info->b.has_essid) { - if(info->essid_on) + if(info->b.essid_on) { /* Does it have an ESSID index ? */ - if((info->essid_on & IW_ENCODE_INDEX) > 1) - printf("ESSID:\"%s\" [%d] ", info->essid, - (info->essid_on & IW_ENCODE_INDEX)); + if((info->b.essid_on & IW_ENCODE_INDEX) > 1) + printf("ESSID:\"%s\" [%d] ", info->b.essid, + (info->b.essid_on & IW_ENCODE_INDEX)); else - printf("ESSID:\"%s\" ", info->essid); + printf("ESSID:\"%s\" ", info->b.essid); } else printf("ESSID:off/any "); @@ -239,35 +195,43 @@ display_info(struct wireless_info * info, printf("Nickname:\"%s\"", info->nickname); /* Formatting */ - if(info->has_essid || info->has_nickname) + if(info->b.has_essid || info->has_nickname) { printf("\n "); tokens = 0; } /* Display Network ID */ - if(info->has_nwid) + if(info->b.has_nwid) { /* Note : should display proper number of digit according to info * in range structure */ - if(info->nwid.disabled) + if(info->b.nwid.disabled) printf("NWID:off/any "); else - printf("NWID:%X ", info->nwid.value); + printf("NWID:%X ", info->b.nwid.value); tokens +=2; } /* Display the current mode of operation */ - if(info->has_mode) + if(info->b.has_mode) { - printf("Mode:%s ", iw_operation_mode[info->mode]); + printf("Mode:%s ", iw_operation_mode[info->b.mode]); tokens +=3; } /* Display frequency / channel */ - if(info->has_freq) + if(info->b.has_freq) { - iw_print_freq(buffer, info->freq); + double freq = info->b.freq; /* Frequency/channel */ + int channel = -1; /* Converted to channel */ + /* Some driver insist of returning channel instead of frequency. + * This fixes them up. Note that, driver should still return + * frequency, because other tools depend on it. */ + if(info->has_range && (freq < KILO)) + channel = iw_channel_to_freq((int) freq, &freq, &info->range); + /* Display */ + iw_print_freq(buffer, sizeof(buffer), freq, -1, info->b.freq_flags); printf("%s ", buffer); tokens +=4; } @@ -284,11 +248,11 @@ display_info(struct wireless_info * info, tokens +=6; /* Oups ! No Access Point in Ad-Hoc mode */ - if((info->has_mode) && (info->mode == IW_MODE_ADHOC)) + if((info->b.has_mode) && (info->b.mode == IW_MODE_ADHOC)) printf("Cell:"); else printf("Access Point:"); - printf(" %s ", iw_pr_ether(buffer, info->ap_addr.sa_data)); + printf(" %s ", iw_pr_ether(buffer, info->ap_addr.sa_data)); } /* Display the currently used/set bit-rate */ @@ -303,11 +267,10 @@ display_info(struct wireless_info * info, tokens +=3; /* Display it */ - iw_print_bitrate(buffer, info->bitrate.value); + iw_print_bitrate(buffer, sizeof(buffer), info->bitrate.value); printf("Bit Rate%c%s ", (info->bitrate.fixed ? '=' : ':'), buffer); } -#if WIRELESS_EXT > 9 /* Display the Transmit Power */ if(info->has_txpower) { @@ -319,30 +282,10 @@ display_info(struct wireless_info * info, } tokens +=3; - /* Disabled ? */ - if(info->txpower.disabled) - printf("Tx-Power:off "); - else - { - int dbm; - - /* Fixed ? */ - if(info->txpower.fixed) - printf("Tx-Power="); - else - printf("Tx-Power:"); - - /* Convert everything to dBm */ - if(info->txpower.flags & IW_TXPOW_MWATT) - dbm = iw_mwatt2dbm(info->txpower.value); - else - dbm = info->txpower.value; - - /* Display */ - printf("%d dBm ", dbm); - } + /* Display it */ + iw_print_txpower(buffer, sizeof(buffer), &info->txpower); + printf("Tx-Power%c%s ", (info->txpower.fixed ? '=' : ':'), buffer); } -#endif /* Display sensitivity */ if(info->has_sens) @@ -374,7 +317,6 @@ display_info(struct wireless_info * info, printf("\n "); tokens = 0; -#if WIRELESS_EXT > 10 /* Display retry limit/lifetime information */ if(info->has_retry) { @@ -387,7 +329,7 @@ display_info(struct wireless_info * info, /* Let's check the value and its type */ if(info->retry.flags & IW_RETRY_TYPE) { - iw_print_retry_value(buffer, + iw_print_retry_value(buffer, sizeof(buffer), info->retry.value, info->retry.flags); printf("%s", buffer); } @@ -399,7 +341,6 @@ display_info(struct wireless_info * info, printf(" "); tokens += 5; /* Between 3 and 5, depend on flags */ } -#endif /* WIRELESS_EXT > 10 */ /* Display the RTS threshold */ if(info->has_rts) @@ -452,23 +393,24 @@ display_info(struct wireless_info * info, /* Display encryption information */ /* Note : we display only the "current" key, use iwlist to list all keys */ - if(info->has_key) + if(info->b.has_key) { printf("Encryption key:"); - if((info->key_flags & IW_ENCODE_DISABLED) || (info->key_size == 0)) + if((info->b.key_flags & IW_ENCODE_DISABLED) || (info->b.key_size == 0)) printf("off\n "); else { /* Display the key */ - iw_print_key(buffer, info->key, info->key_size, info->key_flags); + iw_print_key(buffer, sizeof(buffer), + info->b.key, info->b.key_size, info->b.key_flags); printf("%s", buffer); /* Other info... */ - if((info->key_flags & IW_ENCODE_INDEX) > 1) - printf(" [%d]", info->key_flags & IW_ENCODE_INDEX); - if(info->key_flags & IW_ENCODE_RESTRICTED) + if((info->b.key_flags & IW_ENCODE_INDEX) > 1) + printf(" [%d]", info->b.key_flags & IW_ENCODE_INDEX); + if(info->b.key_flags & IW_ENCODE_RESTRICTED) printf(" Security mode:restricted"); - if(info->key_flags & IW_ENCODE_OPEN) + if(info->b.key_flags & IW_ENCODE_OPEN) printf(" Security mode:open"); printf("\n "); } @@ -488,12 +430,13 @@ display_info(struct wireless_info * info, /* Let's check the value and its type */ if(info->power.flags & IW_POWER_TYPE) { - iw_print_pm_value(buffer, info->power.value, info->power.flags); + iw_print_pm_value(buffer, sizeof(buffer), + info->power.value, info->power.flags); printf("%s ", buffer); } /* Let's check the mode */ - iw_print_pm_mode(buffer, info->power.flags); + iw_print_pm_mode(buffer, sizeof(buffer), info->power.flags); printf("%s", buffer); /* Let's check if nothing (simply on) */ @@ -506,24 +449,23 @@ display_info(struct wireless_info * info, /* Display statistics */ if(info->has_stats) { - info->stats.qual.updated = 0x0; /* Not that reliable, disable */ - iw_print_stats(buffer, &info->stats.qual, &info->range, info->has_range); + iw_print_stats(buffer, sizeof(buffer), + &info->stats.qual, &info->range, info->has_range); printf("Link %s\n", buffer); -#if WIRELESS_EXT > 11 - printf(" Rx invalid nwid:%d Rx invalid crypt:%d Rx invalid frag:%d\n Tx excessive retries:%d Invalid misc:%d Missed beacon:%d\n", - info->stats.discard.nwid, - info->stats.discard.code, - info->stats.discard.fragment, - info->stats.discard.retries, - info->stats.discard.misc, - info->stats.miss.beacon); -#else /* WIRELESS_EXT > 11 */ - printf(" Rx invalid nwid:%d invalid crypt:%d invalid misc:%d\n", - info->stats.discard.nwid, - info->stats.discard.code, - info->stats.discard.misc); -#endif /* WIRELESS_EXT > 11 */ + if(info->range.we_version_compiled > 11) + printf(" Rx invalid nwid:%d Rx invalid crypt:%d Rx invalid frag:%d\n Tx excessive retries:%d Invalid misc:%d Missed beacon:%d\n", + info->stats.discard.nwid, + info->stats.discard.code, + info->stats.discard.fragment, + info->stats.discard.retries, + info->stats.discard.misc, + info->stats.miss.beacon); + else + printf(" Rx invalid nwid:%d invalid crypt:%d invalid misc:%d\n", + info->stats.discard.nwid, + info->stats.discard.code, + info->stats.discard.misc); } printf("\n"); @@ -555,12 +497,12 @@ print_info(int skfd, break; case -ENOTSUP: - fprintf(stderr, "%-8.8s no wireless extensions.\n\n", + fprintf(stderr, "%-8.16s no wireless extensions.\n\n", ifname); break; default: - fprintf(stderr, "%-8.8s %s\n\n", ifname, strerror(-rc)); + fprintf(stderr, "%-8.16s %s\n\n", ifname, strerror(-rc)); } return(rc); } @@ -702,13 +644,48 @@ set_info(int skfd, /* The socket */ if(++i >= count) ABORT_ARG_NUM("Set Frequency", SIOCSIWFREQ); - if(sscanf(args[i], "%lg", &(freq)) != 1) - ABORT_ARG_TYPE("Set Frequency", SIOCSIWFREQ, args[i]); - if(index(args[i], 'G')) freq *= GIGA; - if(index(args[i], 'M')) freq *= MEGA; - if(index(args[i], 'k')) freq *= KILO; + if(!strcasecmp(args[i], "auto")) + { + wrq.u.freq.m = -1; + wrq.u.freq.e = 0; + wrq.u.freq.flags = 0; + } + else + { + if(!strcasecmp(args[i], "fixed")) + { + /* Get old bitrate */ + IW_GET_EXT_ERR(skfd, ifname, SIOCGIWFREQ, &wrq, + "Set Bit Rate"); + wrq.u.freq.flags = IW_FREQ_FIXED; + } + else /* Should be a numeric value */ + { + if(sscanf(args[i], "%lg", &(freq)) != 1) + ABORT_ARG_TYPE("Set Frequency", SIOCSIWFREQ, args[i]); + if(index(args[i], 'G')) freq *= GIGA; + if(index(args[i], 'M')) freq *= MEGA; + if(index(args[i], 'k')) freq *= KILO; + + iw_float2freq(freq, &(wrq.u.freq)); - iw_float2freq(freq, &(wrq.u.freq)); + wrq.u.freq.flags = IW_FREQ_FIXED; + + /* Check for an additional argument */ + if(((i+1) < count) && + (!strcasecmp(args[i+1], "auto"))) + { + wrq.u.freq.flags = 0; + ++i; + } + if(((i+1) < count) && + (!strcasecmp(args[i+1], "fixed"))) + { + wrq.u.freq.flags = IW_FREQ_FIXED; + ++i; + } + } + } IW_SET_EXT_ERR(skfd, ifname, SIOCSIWFREQ, &wrq, "Set Frequency"); @@ -806,14 +783,12 @@ set_info(int skfd, /* The socket */ ++i; gotone++; } -#if WIRELESS_EXT > 15 if((i < count) && (!strncasecmp(args[i], "temporary", 4))) { wrq.u.data.flags |= IW_ENCODE_TEMP; ++i; gotone++; } -#endif } while(gotone != oldone); @@ -1192,7 +1167,6 @@ set_info(int skfd, /* The socket */ continue; } -#if WIRELESS_EXT > 9 /* ---------- Set Transmit-Power ---------- */ if(!strncmp(args[i], "txpower", 3)) { @@ -1209,7 +1183,7 @@ set_info(int skfd, /* The socket */ wrq.u.txpower.value = -1; wrq.u.txpower.fixed = 1; wrq.u.txpower.disabled = 0; - wrq.u.data.flags = IW_TXPOW_DBM; + wrq.u.txpower.flags = IW_TXPOW_DBM; if(!strcasecmp(args[i], "off")) wrq.u.txpower.disabled = 1; /* i.e. turn radio off */ else @@ -1217,52 +1191,73 @@ set_info(int skfd, /* The socket */ wrq.u.txpower.fixed = 0; /* i.e. use power control */ else { - if(!strcasecmp(args[i], "fixed")) + if(!strcasecmp(args[i], "on")) { /* 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 */ + else { - 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_MWATT) - { - if(!ismwatt) - power = iw_dbm2mwatt(power); - wrq.u.data.flags = IW_TXPOW_MWATT; - } - else + if(!strcasecmp(args[i], "fixed")) { - if(ismwatt) - power = iw_mwatt2dbm(power); - wrq.u.data.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; + /* 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; } - if(((i+1) < count) && - (!strcasecmp(args[i+1], "fixed"))) + else /* Should be a numeric value */ { - wrq.u.txpower.fixed = 1; - ++i; + 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; + } } } } @@ -1271,9 +1266,7 @@ set_info(int skfd, /* The socket */ "Set Tx Power"); continue; } -#endif -#if WIRELESS_EXT > 10 /* ---------- Set Retry limit ---------- */ if(!strncmp(args[i], "retry", 3)) { @@ -1343,8 +1336,6 @@ set_info(int skfd, /* The socket */ continue; } -#endif /* WIRELESS_EXT > 10 */ - /* ---------- Other ---------- */ /* Here we have an unrecognised arg... */ fprintf(stderr, "Error : unrecognised wireless request \"%s\"\n", @@ -1394,7 +1385,7 @@ main(int argc, goterr = set_info(skfd, argv + 2, argc - 2, argv[1]); /* Close the socket. */ - close(skfd); + iw_sockets_close(skfd); return(goterr); }