/*
* Wireless Tools
*
- * Jean II - HPLB '99
+ * Jean II - HPLB '99 - HPL 99->04
*
- * Main code for "iwconfig". This is the generic tool for most
- * manipulations...
- * You need to link this code against "iwcommon.c" and "-lm".
+ * This tool can manipulate the spy list : add addresses and display stat
+ * You need to link this code against "iwlib.c" and "-lm".
+ *
+ * This file is released under the GPL license.
+ * Copyright (c) 1997-2004 Jean Tourrilhes <jt@hpl.hp.com>
*/
-#include "iwcommon.h" /* Header */
+#include "iwlib.h" /* Header */
/************************* DISPLAY ROUTINES **************************/
/*
* Display the spy list of addresses and the associated stats
*/
-static void
+static int
print_spy_info(int skfd,
- char * ifname)
+ char * ifname,
+ char * args[],
+ int count)
{
struct iwreq wrq;
char buffer[(sizeof(struct iw_quality) +
sizeof(struct sockaddr)) * IW_MAX_SPY];
- struct sockaddr hwa[IW_MAX_SPY];
- struct iw_quality qual[IW_MAX_SPY];
+ char temp[128];
+ struct sockaddr * hwa;
+ struct iw_quality * qual;
iwrange range;
int has_range = 0;
int n;
int i;
+ /* Avoid "Unused parameter" warning */
+ args = args; count = count;
+
/* Collect stats */
- strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
wrq.u.data.pointer = (caddr_t) buffer;
- wrq.u.data.length = 0;
+ wrq.u.data.length = IW_MAX_SPY;
wrq.u.data.flags = 0;
- if(ioctl(skfd, SIOCGIWSPY, &wrq) < 0)
+ if(iw_get_ext(skfd, ifname, SIOCGIWSPY, &wrq) < 0)
{
- fprintf(stderr, "%-8.8s Interface doesn't support wireless statistic collection\n\n", ifname);
- return;
+ fprintf(stderr, "%-8.16s Interface doesn't support wireless statistic collection\n\n", ifname);
+ return(-1);
}
/* Number of addresses */
n = wrq.u.data.length;
-
-
- /* Check if we have valid address types */
- if(check_addr_type(skfd, ifname) < 0)
+ /* Check if we have valid mac address type */
+ if(iw_check_mac_addr_type(skfd, ifname) < 0)
{
- fprintf(stderr, "%-8.8s Interface doesn't support MAC & IP addresses\n\n", ifname);
- return;
+ fprintf(stderr, "%-8.16s Interface doesn't support MAC addresses\n\n", ifname);
+ return(-2);
}
/* Get range info if we can */
- if(get_range_info(skfd, ifname, &(range)) >= 0)
+ if(iw_get_range_info(skfd, ifname, &(range)) >= 0)
has_range = 1;
/* Display it */
if(n == 0)
- printf("%-8.8s No statistics to collect\n", ifname);
+ printf("%-8.16s No statistics to collect\n", ifname);
else
- printf("%-8.8s Statistics collected:\n", ifname);
+ printf("%-8.16s Statistics collected:\n", ifname);
/* The two lists */
-
- memcpy(hwa, buffer, n * sizeof(struct sockaddr));
- memcpy(qual, buffer + n*sizeof(struct sockaddr), n*sizeof(struct iw_quality));
+ hwa = (struct sockaddr *) buffer;
+ qual = (struct iw_quality *) (buffer + (sizeof(struct sockaddr) * n));
for(i = 0; i < n; i++)
{
- if(has_range && (qual[i].level != 0))
- /* If the statistics are in dBm */
- if(qual[i].level > range.max_qual.level)
- printf(" %s : Quality %d/%d ; Signal %d dBm ; Noise %d dBm %s\n",
- pr_ether(hwa[i].sa_data),
- qual[i].qual, range.max_qual.qual,
- qual[i].level - 0x100, qual[i].noise - 0x100,
- qual[i].updated & 0x7 ? "(updated)" : "");
- else
- printf(" %s : Quality %d/%d ; Signal %d/%d ; Noise %d/%d %s\n",
- pr_ether(hwa[i].sa_data),
- qual[i].qual, range.max_qual.qual,
- qual[i].level, range.max_qual.level,
- qual[i].noise, range.max_qual.noise,
- qual[i].updated & 0x7 ? "(updated)" : "");
- else
- printf(" %s : Quality %d ; Signal %d ; Noise %d %s\n",
- pr_ether(hwa[i].sa_data),
- qual[i].qual, qual[i].level, qual[i].noise,
- qual[i].updated & 0x7 ? "(updated)" : "");
+ /* Print stats for each address */
+ printf(" %s : ", iw_saether_ntop(&hwa[i], temp));
+ iw_print_stats(temp, sizeof(temp), &qual[i], &range, has_range);
+ printf("%s\n", temp);
}
- printf("\n");
-}
-/*------------------------------------------------------------------*/
-/*
- * Get info on all devices and print it on the screen
- */
-static void
-print_spy_devices(int skfd)
-{
- char buff[1024];
- struct ifconf ifc;
- struct ifreq *ifr;
- int i;
-
- /* Get list of active devices */
- ifc.ifc_len = sizeof(buff);
- ifc.ifc_buf = buff;
- if(ioctl(skfd, SIOCGIFCONF, &ifc) < 0)
+ if((n > 0) && (has_range) && (range.we_version_compiled > 11))
{
- fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno));
- return;
- }
- ifr = ifc.ifc_req;
-
- /* Print them */
- for(i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++)
- print_spy_info(skfd, ifr->ifr_name);
-}
+ iwstats stats;
-/*------------------------------------------------------------------*/
-/*
- * Print the number of channels and available frequency for the device
- */
-static void
-print_freq_info(int skfd,
- char * ifname)
-{
- struct iwreq wrq;
- float freq;
- struct iw_range range;
- int k;
-
- strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
- wrq.u.data.pointer = (caddr_t) ⦥
- wrq.u.data.length = 0;
- wrq.u.data.flags = 0;
- if(ioctl(skfd, SIOCGIWRANGE, &wrq) < 0)
- fprintf(stderr, "%-8.8s no frequency information.\n\n",
- ifname);
- else
- {
- if(range.num_frequency > 0)
+ /* Get /proc/net/wireless */
+ if(iw_get_stats(skfd, ifname, &stats, &range, has_range) >= 0)
{
- printf("%-8.8s %d channels in total; available frequencies :\n",
- ifname, range.num_channels);
- /* Print them all */
- for(k = 0; k < range.num_frequency; k++)
- {
-#if WIRELESS_EXT > 7
- printf("\t Channel %.2d : ", range.freq[k].i);
-#else
- printf("\t ");
-#endif
- freq = freq2float(&(range.freq[k]));
- if(freq >= GIGA)
- printf("%g GHz\n", freq / GIGA);
- else
- if(freq >= MEGA)
- printf("%g MHz\n", freq / MEGA);
- else
- printf("%g kHz\n", freq / KILO);
- }
- printf("\n\n");
+ iw_print_stats(temp, sizeof(temp), &stats.qual, &range, has_range);
+ printf(" Link/Cell/AP : %s\n", temp);
+ /* Display the static data */
+ iw_print_stats(temp, sizeof(temp),
+ &range.avg_qual, &range, has_range);
+ printf(" Typical/Reference : %s\n", temp);
}
- else
- printf("%-8.8s %d channels\n\n",
- ifname, range.num_channels);
- }
-}
-
-/*------------------------------------------------------------------*/
-/*
- * Get frequency info on all devices and print it on the screen
- */
-static void
-print_freq_devices(int skfd)
-{
- char buff[1024];
- struct ifconf ifc;
- struct ifreq *ifr;
- int i;
-
- /* Get list of active devices */
- ifc.ifc_len = sizeof(buff);
- ifc.ifc_buf = buff;
- if(ioctl(skfd, SIOCGIFCONF, &ifc) < 0)
- {
- fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno));
- return;
}
- ifr = ifc.ifc_req;
- /* Print them */
- for(i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++)
- print_freq_info(skfd, ifr->ifr_name);
+ printf("\n");
+ return(0);
}
-#if WIRELESS_EXT > 5
/*------------------------------------------------------------------*/
/*
- * Display the list of ap addresses and the associated stats
- * Exacly the same as the spy list, only with different IOCTL and messages
+ * Get spy thresholds from the driver and display
*/
-static void
-print_ap_info(int skfd,
- char * ifname)
+static int
+get_spy_threshold(int skfd, /* The socket */
+ char * ifname, /* Dev name */
+ char * args[], /* Command line args */
+ int count) /* Args count */
{
struct iwreq wrq;
- char buffer[(sizeof(struct iw_quality) +
- sizeof(struct sockaddr)) * IW_MAX_AP];
- struct sockaddr * hwa;
- struct iw_quality * qual;
+ struct iw_thrspy threshold;
iwrange range;
- int has_range = 0;
- int has_qual = 0;
- int n;
- int i;
+ int has_range = 0;
- /* Collect stats */
- strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
- wrq.u.data.pointer = (caddr_t) buffer;
- wrq.u.data.length = 0;
- wrq.u.data.flags = 0;
- if(ioctl(skfd, SIOCGIWAPLIST, &wrq) < 0)
- {
- fprintf(stderr, "%-8.8s Interface doesn't have a list of Access Points\n\n", ifname);
- return;
- }
+ /* Avoid "Unused parameter" warning */
+ args = args; count = count;
- /* Number of addresses */
- n = wrq.u.data.length;
- has_qual = wrq.u.data.flags;
-
- /* The two lists */
- hwa = (struct sockaddr *) buffer;
- qual = (struct iw_quality *) (buffer + (sizeof(struct sockaddr) * n));
-
- /* Check if we have valid address types */
- if(check_addr_type(skfd, ifname) < 0)
+ /* Time to send thresholds to the driver */
+ wrq.u.data.pointer = (caddr_t) &threshold;
+ wrq.u.data.length = 1;
+ wrq.u.data.flags = 0;
+ if(iw_set_ext(skfd, ifname, SIOCGIWTHRSPY, &wrq) < 0)
{
- fprintf(stderr, "%-8.8s Interface doesn't support MAC & IP addresses\n\n", ifname);
- return;
+ fprintf(stderr, "Interface doesn't support thresholds...\n");
+ fprintf(stderr, "SIOCGIWTHRSPY: %s\n", strerror(errno));
+ return(-1);
}
/* Get range info if we can */
- if(get_range_info(skfd, ifname, &(range)) >= 0)
+ if(iw_get_range_info(skfd, ifname, &(range)) >= 0)
has_range = 1;
- /* Display it */
- if(n == 0)
- printf("%-8.8s No Access Point in range\n", ifname);
- else
- printf("%-8.8s Access Points in range:\n", ifname);
- for(i = 0; i < n; i++)
+ /* Display thresholds */
+ if((has_range) && (threshold.low.level))
{
- if(has_qual)
- if(has_range)
- /* If the statistics are in dBm */
- if(qual[i].level > range.max_qual.level)
- printf(" %s : Quality %d/%d ; Signal %d dBm ; Noise %d dBm %s\n",
- pr_ether(hwa[i].sa_data),
- qual[i].qual, range.max_qual.qual,
- qual[i].level - 0x100, qual[i].noise - 0x100,
- qual[i].updated & 0x7 ? "(updated)" : "");
- else
- printf(" %s : Quality %d/%d ; Signal %d/%d ; Noise %d/%d %s\n",
- pr_ether(hwa[i].sa_data),
- qual[i].qual, range.max_qual.qual,
- qual[i].level, range.max_qual.level,
- qual[i].noise, range.max_qual.noise,
- qual[i].updated & 0x7 ? "(updated)" : "");
- else
- printf(" %s : Quality %d ; Signal %d ; Noise %d %s\n",
- pr_ether(hwa[i].sa_data),
- qual[i].qual, qual[i].level, qual[i].noise,
- qual[i].updated & 0x7 ? "(updated)" : "");
- else
- printf(" %s\n", pr_ether(hwa[i].sa_data));
- }
- printf("\n");
-}
-
-/*------------------------------------------------------------------*/
-/*
- * Get list of AP on all devices and print it on the screen
- */
-static void
-print_ap_devices(int skfd)
-{
- char buff[1024];
- struct ifconf ifc;
- struct ifreq *ifr;
- int i;
-
- /* Get list of active devices */
- ifc.ifc_len = sizeof(buff);
- ifc.ifc_buf = buff;
- if(ioctl(skfd, SIOCGIFCONF, &ifc) < 0)
- {
- fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno));
- return;
- }
- ifr = ifc.ifc_req;
-
- /* Print them */
- for(i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++)
- print_ap_info(skfd, ifr->ifr_name);
-}
-#endif /* WIRELESS_EXT > 5 */
-
-#if WIRELESS_EXT > 7
-/*------------------------------------------------------------------*/
-/*
- * Print the number of available bitrates for the device
- */
-static void
-print_bitrate_info(int skfd,
- char * ifname)
-{
- struct iwreq wrq;
- float bitrate;
- struct iw_range range;
- int k;
-
- strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
- wrq.u.data.pointer = (caddr_t) ⦥
- wrq.u.data.length = 0;
- wrq.u.data.flags = 0;
- if(ioctl(skfd, SIOCGIWRANGE, &wrq) < 0)
- fprintf(stderr, "%-8.8s no bit-rate information.\n\n",
- ifname);
- else
- {
- if((range.num_bitrates > 0) && (range.num_bitrates < IW_MAX_BITRATES))
+ /* If the statistics are in dBm */
+ if(threshold.low.level > range.max_qual.level)
{
- printf("%-8.8s %d available bit-rates :\n",
- ifname, range.num_bitrates);
- /* Print them all */
- for(k = 0; k < range.num_bitrates; k++)
- {
- printf("\t ");
- bitrate = range.bitrate[k];
- if(bitrate >= GIGA)
- printf("%g Gb/s\n", bitrate / GIGA);
- else
- if(bitrate >= MEGA)
- printf("%g Mb/s\n", bitrate / MEGA);
- else
- printf("%g kb/s\n", bitrate / KILO);
- }
- printf("\n\n");
+ /* Statistics are in dBm (absolute power measurement) */
+ printf("%-8.16s Low threshold:%d dBm High threshold:%d dBm\n\n",
+ ifname,
+ threshold.low.level - 0x100, threshold.high.level - 0x100);
}
else
- printf("%-8.8s No bit-rates ? Please update driver...\n\n", ifname);
+ {
+ /* Statistics are relative values (0 -> max) */
+ printf("%-8.16s Low threshold:%d/%d High threshold:%d/%d\n\n",
+ ifname,
+ threshold.low.level, range.max_qual.level,
+ threshold.high.level, range.max_qual.level);
+ }
}
-}
-
-/*------------------------------------------------------------------*/
-/*
- * Get bit-rate info on all devices and print it on the screen
- */
-static void
-print_bitrate_devices(int skfd)
-{
- char buff[1024];
- struct ifconf ifc;
- struct ifreq *ifr;
- int i;
-
- /* Get list of active devices */
- ifc.ifc_len = sizeof(buff);
- ifc.ifc_buf = buff;
- if(ioctl(skfd, SIOCGIFCONF, &ifc) < 0)
+ else
{
- fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno));
- return;
+ /* We can't read the range, so we don't know... */
+ printf("%-8.16s Low threshold:%d High threshold:%d\n\n",
+ ifname,
+ threshold.low.level, threshold.high.level);
}
- ifr = ifc.ifc_req;
- /* Print them */
- for(i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++)
- print_bitrate_info(skfd, ifr->ifr_name);
+ return(0);
}
-#endif /* WIRELESS_EXT > 7 */
/************************* SETTING ROUTINES **************************/
*/
static int
set_spy_info(int skfd, /* The socket */
+ char * ifname, /* Dev name */
char * args[], /* Command line args */
- int count, /* Args count */
- char * ifname) /* Dev name */
+ int count) /* Args count */
{
struct iwreq wrq;
int i;
/* Read command line */
i = 0; /* first arg to read */
- nbr = 0; /* Number of args readen so far */
-
- /* Check if we have valid address types */
- if(check_addr_type(skfd, ifname) < 0)
- {
- fprintf(stderr, "%-8.8s Interface doesn't support MAC & IP addresses\n", ifname);
- return(-1);
- }
+ nbr = 0; /* Number of args read so far */
/* "off" : disable functionality (set 0 addresses) */
if(!strcmp(args[0], "off"))
- i = count; /* hack */
-
- /* "+" : add all addresses already in the driver */
- if(!strcmp(args[0], "+"))
+ i = 1; /* skip the "off" */
+ else
{
- char buffer[(sizeof(struct iw_quality) +
+ /* "+" : add all addresses already in the driver */
+ if(!strcmp(args[0], "+"))
+ {
+ char buffer[(sizeof(struct iw_quality) +
sizeof(struct sockaddr)) * IW_MAX_SPY];
- strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
- wrq.u.data.pointer = (caddr_t) buffer;
- wrq.u.data.length = 0;
- wrq.u.data.flags = 0;
- if(ioctl(skfd, SIOCGIWSPY, &wrq) < 0)
- {
- fprintf(stderr, "Interface doesn't accept reading addresses...\n");
- fprintf(stderr, "SIOCGIWSPY: %s\n", strerror(errno));
- return(-1);
- }
+ /* Check if we have valid mac address type */
+ if(iw_check_mac_addr_type(skfd, ifname) < 0)
+ {
+ fprintf(stderr, "%-8.16s Interface doesn't support MAC addresses\n", ifname);
+ return(-1);
+ }
- /* Copy old addresses */
- nbr = wrq.u.data.length;
- memcpy(hw_address, buffer, nbr * sizeof(struct sockaddr));
+ wrq.u.data.pointer = (caddr_t) buffer;
+ wrq.u.data.length = IW_MAX_SPY;
+ wrq.u.data.flags = 0;
+ if(iw_get_ext(skfd, ifname, SIOCGIWSPY, &wrq) < 0)
+ {
+ fprintf(stderr, "Interface doesn't accept reading addresses...\n");
+ fprintf(stderr, "SIOCGIWSPY: %s\n", strerror(errno));
+ return(-1);
+ }
- i = 1; /* skip the "+" */
- }
+ /* Copy old addresses */
+ nbr = wrq.u.data.length;
+ memcpy(hw_address, buffer, nbr * sizeof(struct sockaddr));
- /* Read other args on command line */
- while((i < count) && (nbr < IW_MAX_SPY))
- {
- if(in_addr(skfd, ifname, args[i++], &(hw_address[nbr])) < 0)
- continue;
- nbr++;
- }
+ i = 1; /* skip the "+" */
+ }
- /* Check the number of addresses */
- if((nbr == 0) && strcmp(args[0], "off"))
- {
- fprintf(stderr, "No valid addresses found : exiting...\n");
- exit(0);
+ /* Read other args on command line */
+ while((i < count) && (nbr < IW_MAX_SPY))
+ {
+ /* Get the address and check if the interface supports it */
+ if(iw_in_addr(skfd, ifname, args[i++], &(hw_address[nbr])) < 0)
+ continue;
+ nbr++;
+ }
+
+ /* Check the number of addresses */
+ if(nbr == 0)
+ {
+ fprintf(stderr, "No valid addresses found : exiting...\n");
+ return(-1);
+ }
}
/* Check if there is some remaining arguments */
if(i < count)
{
- fprintf(stderr, "Got only the first %d addresses, remaining discarded\n", IW_MAX_SPY);
+ fprintf(stderr, "Got only the first %d arguments, remaining discarded\n", i);
}
/* Time to do send addresses to the driver */
- strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
wrq.u.data.pointer = (caddr_t) hw_address;
wrq.u.data.length = nbr;
wrq.u.data.flags = 0;
- if(ioctl(skfd, SIOCSIWSPY, &wrq) < 0)
+ if(iw_set_ext(skfd, ifname, SIOCSIWSPY, &wrq) < 0)
{
fprintf(stderr, "Interface doesn't accept addresses...\n");
fprintf(stderr, "SIOCSIWSPY: %s\n", strerror(errno));
return(0);
}
-/******************************* MAIN ********************************/
-
/*------------------------------------------------------------------*/
/*
- * The main !
+ * Set spy thresholds in the driver from command line
*/
-int
-main(int argc,
- char ** argv)
+static int
+set_spy_threshold(int skfd, /* The socket */
+ char * ifname, /* Dev name */
+ char * args[], /* Command line args */
+ int count) /* Args count */
{
- int skfd = -1; /* generic raw socket desc. */
- int goterr = 0;
-
- /* Create a channel to the NET kernel. */
- if((skfd = sockets_open()) < 0)
- {
- perror("socket");
- exit(-1);
- }
-
- /* No argument : show the list of all device + info */
- if(argc == 1)
- {
- print_spy_devices(skfd);
- close(skfd);
- exit(0);
- }
+ struct iwreq wrq;
+ struct iw_thrspy threshold;
+ int low_thr;
+ int high_thr;
- /* Special cases take one... */
- /* Help */
- if((!strncmp(argv[1], "-h", 9)) ||
- (!strcmp(argv[1], "--help")))
- {
- fprintf(stderr, "Usage: iwspy interface [+] [MAC address] [IP address]\n");
- fprintf(stderr, " interface [freq]\n");
- fprintf(stderr, " interface [ap]\n");
- close(skfd);
- exit(0);
- }
+ /* Init */
+ memset(&threshold, '\0', sizeof(threshold));
- /* Frequency list */
- if((!strncmp(argv[1], "freq", 4)) ||
- (!strncmp(argv[1], "channel", 7)))
+ /* "off" : disable functionality (set 0 addresses) */
+ if(!strcmp(args[0], "off"))
{
- print_freq_devices(skfd);
- close(skfd);
- exit(0);
+ /* Just send null threshold, will disable it */
}
-
-#if WIRELESS_EXT > 5
- /* Access Point list */
- if(!strcasecmp(argv[1], "ap"))
+ else
{
- print_ap_devices(skfd);
- close(skfd);
- exit(0);
+ /* Try to get our threshold */
+ if(count < 2)
+ {
+ fprintf(stderr, "%-8.16s Need two threshold values\n", ifname);
+ return(-1);
+ }
+ if((sscanf(args[0], "%i", &low_thr) != 1) ||
+ (sscanf(args[1], "%i", &high_thr) != 1))
+ {
+ fprintf(stderr, "%-8.16s Invalid threshold values\n", ifname);
+ return(-1);
+ }
+ /* Basic sanity check */
+ if(high_thr < low_thr)
+ {
+ fprintf(stderr, "%-8.16s Inverted threshold range\n", ifname);
+ return(-1);
+ }
+ /* Copy thresholds */
+ threshold.low.level = low_thr;
+ threshold.low.updated = 0x2;
+ threshold.high.level = high_thr;
+ threshold.high.updated = 0x2;
}
-#endif /* WIRELESS_EXT > 5 */
-#if WIRELESS_EXT > 7
- /* Bit-rate list */
- if((!strncmp(argv[1], "bit", 3)) ||
- (!strcmp(argv[1], "rate")))
+ /* Time to send thresholds to the driver */
+ wrq.u.data.pointer = (caddr_t) &threshold;
+ wrq.u.data.length = 1;
+ wrq.u.data.flags = 0;
+ if(iw_set_ext(skfd, ifname, SIOCSIWTHRSPY, &wrq) < 0)
{
- print_bitrate_devices(skfd);
- close(skfd);
- exit(0);
+ fprintf(stderr, "Interface doesn't accept thresholds...\n");
+ fprintf(stderr, "SIOCSIWTHRSPY: %s\n", strerror(errno));
+ return(-1);
}
-#endif /* WIRELESS_EXT > 7 */
- /* The device name must be the first argument */
- /* Name only : show spy list for that device only */
- if(argc == 2)
- {
- print_spy_info(skfd, argv[1]);
- close(skfd);
- exit(0);
- }
+ return(0);
+}
- /* Special cases take two... */
- /* Frequency list */
- if((!strncmp(argv[2], "freq", 4)) ||
- (!strncmp(argv[2], "channel", 7)))
- {
- print_freq_info(skfd, argv[1]);
- close(skfd);
- exit(0);
- }
+/******************************* MAIN ********************************/
-#if WIRELESS_EXT > 5
- /* Access Point list */
- if(!strcasecmp(argv[2], "ap"))
- {
- print_ap_info(skfd, argv[1]);
- close(skfd);
- exit(0);
- }
-#endif /* WIRELESS_EXT > 5 */
+/*------------------------------------------------------------------*/
+/*
+ * The main !
+ */
+int
+main(int argc,
+ char ** argv)
+{
+ int skfd; /* generic raw socket desc. */
+ int goterr = 0;
-#if WIRELESS_EXT > 7
- /* Access Point list */
- if((!strncmp(argv[2], "bit", 3)) ||
- (!strcmp(argv[2], "rate")))
+ /* Create a channel to the NET kernel. */
+ if((skfd = iw_sockets_open()) < 0)
{
- print_bitrate_info(skfd, argv[1]);
- close(skfd);
- exit(0);
+ perror("socket");
+ return(-1);
}
-#endif /* WIRELESS_EXT > 7 */
- /* Otherwise, it's a list of address to set in the spy list */
- goterr = set_spy_info(skfd, argv + 2, argc - 2, argv[1]);
+ /* No argument : show the list of all device + info */
+ if(argc == 1)
+ iw_enum_devices(skfd, &print_spy_info, NULL, 0);
+ else
+ /* Special cases take one... */
+ /* Help */
+ if((!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "--help")))
+ fprintf(stderr, "Usage: iwspy interface [+] [MAC address] [IP address]\n");
+ else
+ /* Version */
+ if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))
+ goterr = iw_print_version_info("iwspy");
+ else
+ /* The device name must be the first argument */
+ /* Name only : show spy list for that device only */
+ if(argc == 2)
+ print_spy_info(skfd, argv[1], NULL, 0);
+ else
+ /* Special commands */
+ if(!strcmp(argv[2], "setthr"))
+ goterr = set_spy_threshold(skfd, argv[1], argv + 3, argc - 3);
+ else
+ if(!strcmp(argv[2], "getthr"))
+ goterr = get_spy_threshold(skfd, argv[1], argv + 3, argc - 3);
+ else
+ /* Otherwise, it's a list of address to set in the spy list */
+ goterr = set_spy_info(skfd, argv[1], argv + 2, argc - 2);
/* Close the socket. */
- close(skfd);
+ iw_sockets_close(skfd);
- return(1);
+ return(goterr);
}