• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/iwinfo/iwinfo_cli.c

  1 /*
  2  * iwinfo - Wireless Information Library - Command line frontend
  3  *
  4  *   Copyright (C) 2011 Jo-Philipp Wich <xm@subsignal.org>
  5  *
  6  * The iwinfo library is free software: you can redistribute it and/or
  7  * modify it under the terms of the GNU General Public License version 2
  8  * as published by the Free Software Foundation.
  9  *
 10  * The iwinfo library is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 13  * See the GNU General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU General Public License along
 16  * with the iwinfo library. If not, see http://www.gnu.org/licenses/.
 17  */
 18 
 19 #include <stdio.h>
 20 #include <glob.h>
 21 
 22 #include "iwinfo.h"
 23 
 24 
 25 static char * format_bssid(unsigned char *mac)
 26 {
 27         static char buf[18];
 28 
 29         snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X",
 30                 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
 31 
 32         return buf;
 33 }
 34 
 35 static char * format_ssid(char *ssid)
 36 {
 37         static char buf[IWINFO_ESSID_MAX_SIZE+3];
 38 
 39         if (ssid && ssid[0])
 40                 snprintf(buf, sizeof(buf), "\"%s\"", ssid);
 41         else
 42                 snprintf(buf, sizeof(buf), "unknown");
 43 
 44         return buf;
 45 }
 46 
 47 static char * format_channel(int ch)
 48 {
 49         static char buf[8];
 50 
 51         if (ch <= 0)
 52                 snprintf(buf, sizeof(buf), "unknown");
 53         else
 54                 snprintf(buf, sizeof(buf), "%d", ch);
 55 
 56         return buf;
 57 }
 58 
 59 static char * format_frequency(int freq)
 60 {
 61         static char buf[10];
 62 
 63         if (freq <= 0)
 64                 snprintf(buf, sizeof(buf), "unknown");
 65         else
 66                 snprintf(buf, sizeof(buf), "%.3f GHz", ((float)freq / 1000.0));
 67 
 68         return buf;
 69 }
 70 
 71 static char * format_txpower(int pwr)
 72 {
 73         static char buf[10];
 74 
 75         if (pwr < 0)
 76                 snprintf(buf, sizeof(buf), "unknown");
 77         else
 78                 snprintf(buf, sizeof(buf), "%d dBm", pwr);
 79 
 80         return buf;
 81 }
 82 
 83 static char * format_quality(int qual)
 84 {
 85         static char buf[8];
 86 
 87         if (qual < 0)
 88                 snprintf(buf, sizeof(buf), "unknown");
 89         else
 90                 snprintf(buf, sizeof(buf), "%d", qual);
 91 
 92         return buf;
 93 }
 94 
 95 static char * format_quality_max(int qmax)
 96 {
 97         static char buf[8];
 98 
 99         if (qmax < 0)
100                 snprintf(buf, sizeof(buf), "unknown");
101         else
102                 snprintf(buf, sizeof(buf), "%d", qmax);
103 
104         return buf;
105 }
106 
107 static char * format_signal(int sig)
108 {
109         static char buf[10];
110 
111         if (!sig)
112                 snprintf(buf, sizeof(buf), "unknown");
113         else
114                 snprintf(buf, sizeof(buf), "%d dBm", sig);
115 
116         return buf;
117 }
118 
119 static char * format_noise(int noise)
120 {
121         static char buf[10];
122 
123         if (!noise)
124                 snprintf(buf, sizeof(buf), "unknown");
125         else
126                 snprintf(buf, sizeof(buf), "%d dBm", noise);
127 
128         return buf;
129 }
130 
131 static char * format_rate(int rate)
132 {
133         static char buf[18];
134 
135         if (rate <= 0)
136                 snprintf(buf, sizeof(buf), "unknown");
137         else
138                 snprintf(buf, sizeof(buf), "%d.%d MBit/s",
139                         rate / 1000, (rate % 1000) / 100);
140 
141         return buf;
142 }
143 
144 static char * format_enc_ciphers(int ciphers)
145 {
146         static char str[128] = { 0 };
147         char *pos = str;
148 
149         if (ciphers & IWINFO_CIPHER_WEP40)
150                 pos += sprintf(pos, "WEP-40, ");
151 
152         if (ciphers & IWINFO_CIPHER_WEP104)
153                 pos += sprintf(pos, "WEP-104, ");
154 
155         if (ciphers & IWINFO_CIPHER_TKIP)
156                 pos += sprintf(pos, "TKIP, ");
157 
158         if (ciphers & IWINFO_CIPHER_CCMP)
159                 pos += sprintf(pos, "CCMP, ");
160 
161         if (ciphers & IWINFO_CIPHER_WRAP)
162                 pos += sprintf(pos, "WRAP, ");
163 
164         if (ciphers & IWINFO_CIPHER_AESOCB)
165                 pos += sprintf(pos, "AES-OCB, ");
166 
167         if (ciphers & IWINFO_CIPHER_CKIP)
168                 pos += sprintf(pos, "CKIP, ");
169 
170         if (!ciphers || (ciphers & IWINFO_CIPHER_NONE))
171                 pos += sprintf(pos, "NONE, ");
172 
173         *(pos - 2) = 0;
174 
175         return str;
176 }
177 
178 static char * format_enc_suites(int suites)
179 {
180         static char str[64] = { 0 };
181         char *pos = str;
182 
183         if (suites & IWINFO_KMGMT_PSK)
184                 pos += sprintf(pos, "PSK/");
185 
186         if (suites & IWINFO_KMGMT_8021x)
187                 pos += sprintf(pos, "802.1X/");
188 
189         if (suites & IWINFO_KMGMT_SAE)
190                 pos += sprintf(pos, "SAE/");
191 
192         if (suites & IWINFO_KMGMT_OWE)
193                 pos += sprintf(pos, "OWE/");
194 
195         if (!suites || (suites & IWINFO_KMGMT_NONE))
196                 pos += sprintf(pos, "NONE/");
197 
198         *(pos - 1) = 0;
199 
200         return str;
201 }
202 
203 static char * format_encryption(struct iwinfo_crypto_entry *c)
204 {
205         static char buf[512];
206         char *pos = buf;
207         int i, n;
208 
209         if (!c)
210         {
211                 snprintf(buf, sizeof(buf), "unknown");
212         }
213         else if (c->enabled)
214         {
215                 /* WEP */
216                 if (c->auth_algs && !c->wpa_version)
217                 {
218                         if ((c->auth_algs & IWINFO_AUTH_OPEN) &&
219                                 (c->auth_algs & IWINFO_AUTH_SHARED))
220                         {
221                                 snprintf(buf, sizeof(buf), "WEP Open/Shared (%s)",
222                                         format_enc_ciphers(c->pair_ciphers));
223                         }
224                         else if (c->auth_algs & IWINFO_AUTH_OPEN)
225                         {
226                                 snprintf(buf, sizeof(buf), "WEP Open System (%s)",
227                                         format_enc_ciphers(c->pair_ciphers));
228                         }
229                         else if (c->auth_algs & IWINFO_AUTH_SHARED)
230                         {
231                                 snprintf(buf, sizeof(buf), "WEP Shared Auth (%s)",
232                                         format_enc_ciphers(c->pair_ciphers));
233                         }
234                 }
235 
236                 /* WPA */
237                 else if (c->wpa_version)
238                 {
239                         for (i = 0, n = 0; i < 3; i++)
240                                 if (c->wpa_version & (1 << i))
241                                         n++;
242 
243                         if (n > 1)
244                                 pos += sprintf(pos, "mixed ");
245 
246                         for (i = 0; i < 3; i++)
247                                 if (c->wpa_version & (1 << i))
248                                         if (i)
249                                                 pos += sprintf(pos, "WPA%d/", i + 1);
250                                         else
251                                                 pos += sprintf(pos, "WPA/");
252 
253                         pos--;
254 
255                         sprintf(pos, " %s (%s)",
256                                 format_enc_suites(c->auth_suites),
257                                 format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
258                 }
259                 else
260                 {
261                         snprintf(buf, sizeof(buf), "none");
262                 }
263         }
264         else
265         {
266                 snprintf(buf, sizeof(buf), "none");
267         }
268 
269         return buf;
270 }
271 
272 static char * format_hwmodes(int modes)
273 {
274         static char buf[15];
275 
276         if (modes <= 0)
277                 snprintf(buf, sizeof(buf), "unknown");
278         else
279                 snprintf(buf, sizeof(buf), "802.11%s%s%s%s%s%s",
280                         (modes & IWINFO_80211_A) ? "a" : "",
281                         (modes & IWINFO_80211_B) ? "b" : "",
282                         (modes & IWINFO_80211_G) ? "g" : "",
283                         (modes & IWINFO_80211_N) ? "n" : "",
284                         (modes & IWINFO_80211_AC) ? "ac" : "",
285                         (modes & IWINFO_80211_AD) ? "ad" : "");
286 
287         return buf;
288 }
289 
290 static char * format_assocrate(struct iwinfo_rate_entry *r)
291 {
292         static char buf[80];
293         char *p = buf;
294         int l = sizeof(buf);
295 
296         if (r->rate <= 0)
297         {
298                 snprintf(buf, sizeof(buf), "unknown");
299         }
300         else
301         {
302                 p += snprintf(p, l, "%s", format_rate(r->rate));
303                 l = sizeof(buf) - (p - buf);
304 
305                 if (r->is_ht)
306                 {
307                         p += snprintf(p, l, ", MCS %d, %dMHz", r->mcs, r->mhz);
308                         l = sizeof(buf) - (p - buf);
309                 }
310                 else if (r->is_vht)
311                 {
312                         p += snprintf(p, l, ", VHT-MCS %d, %dMHz", r->mcs, r->mhz);
313                         l = sizeof(buf) - (p - buf);
314 
315                         if (r->nss)
316                         {
317                                 p += snprintf(p, l, ", VHT-NSS %d", r->nss);
318                                 l = sizeof(buf) - (p - buf);
319                         }
320                 }
321         }
322 
323         return buf;
324 }
325 
326 
327 static const char * print_type(const struct iwinfo_ops *iw, const char *ifname)
328 {
329         const char *type = iwinfo_type(ifname);
330         return type ? type : "unknown";
331 }
332 
333 static char * print_hardware_id(const struct iwinfo_ops *iw, const char *ifname)
334 {
335         static char buf[20];
336         struct iwinfo_hardware_id ids;
337 
338         if (!iw->hardware_id(ifname, (char *)&ids))
339         {
340                 snprintf(buf, sizeof(buf), "%04X:%04X %04X:%04X",
341                         ids.vendor_id, ids.device_id,
342                         ids.subsystem_vendor_id, ids.subsystem_device_id);
343         }
344         else
345         {
346                 snprintf(buf, sizeof(buf), "unknown");
347         }
348 
349         return buf;
350 }
351 
352 static char * print_hardware_name(const struct iwinfo_ops *iw, const char *ifname)
353 {
354         static char buf[128];
355 
356         if (iw->hardware_name(ifname, buf))
357                 snprintf(buf, sizeof(buf), "unknown");
358 
359         return buf;
360 }
361 
362 static char * print_txpower_offset(const struct iwinfo_ops *iw, const char *ifname)
363 {
364         int off;
365         static char buf[12];
366 
367         if (iw->txpower_offset(ifname, &off))
368                 snprintf(buf, sizeof(buf), "unknown");
369         else if (off != 0)
370                 snprintf(buf, sizeof(buf), "%d dB", off);
371         else
372                 snprintf(buf, sizeof(buf), "none");
373 
374         return buf;
375 }
376 
377 static char * print_frequency_offset(const struct iwinfo_ops *iw, const char *ifname)
378 {
379         int off;
380         static char buf[12];
381 
382         if (iw->frequency_offset(ifname, &off))
383                 snprintf(buf, sizeof(buf), "unknown");
384         else if (off != 0)
385                 snprintf(buf, sizeof(buf), "%.3f GHz", ((float)off / 1000.0));
386         else
387                 snprintf(buf, sizeof(buf), "none");
388 
389         return buf;
390 }
391 
392 static char * print_ssid(const struct iwinfo_ops *iw, const char *ifname)
393 {
394         char buf[IWINFO_ESSID_MAX_SIZE+1] = { 0 };
395 
396         if (iw->ssid(ifname, buf))
397                 memset(buf, 0, sizeof(buf));
398 
399         return format_ssid(buf);
400 }
401 
402 static char * print_bssid(const struct iwinfo_ops *iw, const char *ifname)
403 {
404         static char buf[18] = { 0 };
405 
406         if (iw->bssid(ifname, buf))
407                 snprintf(buf, sizeof(buf), "00:00:00:00:00:00");
408 
409         return buf;
410 }
411 
412 static char * print_mode(const struct iwinfo_ops *iw, const char *ifname)
413 {
414         int mode;
415         static char buf[128];
416 
417         if (iw->mode(ifname, &mode))
418                 mode = IWINFO_OPMODE_UNKNOWN;
419 
420         snprintf(buf, sizeof(buf), "%s", IWINFO_OPMODE_NAMES[mode]);
421 
422         return buf;
423 }
424 
425 static char * print_channel(const struct iwinfo_ops *iw, const char *ifname)
426 {
427         int ch;
428         if (iw->channel(ifname, &ch))
429                 ch = -1;
430 
431         return format_channel(ch);
432 }
433 
434 static char * print_frequency(const struct iwinfo_ops *iw, const char *ifname)
435 {
436         int freq;
437         if (iw->frequency(ifname, &freq))
438                 freq = -1;
439 
440         return format_frequency(freq);
441 }
442 
443 static char * print_txpower(const struct iwinfo_ops *iw, const char *ifname)
444 {
445         int pwr, off;
446         if (iw->txpower_offset(ifname, &off))
447                 off = 0;
448 
449         if (iw->txpower(ifname, &pwr))
450                 pwr = -1;
451         else
452                 pwr += off;
453 
454         return format_txpower(pwr);
455 }
456 
457 static char * print_quality(const struct iwinfo_ops *iw, const char *ifname)
458 {
459         int qual;
460         if (iw->quality(ifname, &qual))
461                 qual = -1;
462 
463         return format_quality(qual);
464 }
465 
466 static char * print_quality_max(const struct iwinfo_ops *iw, const char *ifname)
467 {
468         int qmax;
469         if (iw->quality_max(ifname, &qmax))
470                 qmax = -1;
471 
472         return format_quality_max(qmax);
473 }
474 
475 static char * print_signal(const struct iwinfo_ops *iw, const char *ifname)
476 {
477         int sig;
478         if (iw->signal(ifname, &sig))
479                 sig = 0;
480 
481         return format_signal(sig);
482 }
483 
484 static char * print_noise(const struct iwinfo_ops *iw, const char *ifname)
485 {
486         int noise;
487         if (iw->noise(ifname, &noise))
488                 noise = 0;
489 
490         return format_noise(noise);
491 }
492 
493 static char * print_rate(const struct iwinfo_ops *iw, const char *ifname)
494 {
495         int rate;
496         if (iw->bitrate(ifname, &rate))
497                 rate = -1;
498 
499         return format_rate(rate);
500 }
501 
502 static char * print_encryption(const struct iwinfo_ops *iw, const char *ifname)
503 {
504         struct iwinfo_crypto_entry c = { 0 };
505         if (iw->encryption(ifname, (char *)&c))
506                 return format_encryption(NULL);
507 
508         return format_encryption(&c);
509 }
510 
511 static char * print_hwmodes(const struct iwinfo_ops *iw, const char *ifname)
512 {
513         int modes;
514         if (iw->hwmodelist(ifname, &modes))
515                 modes = -1;
516 
517         return format_hwmodes(modes);
518 }
519 
520 static char * print_mbssid_supp(const struct iwinfo_ops *iw, const char *ifname)
521 {
522         int supp;
523         static char buf[4];
524 
525         if (iw->mbssid_support(ifname, &supp))
526                 snprintf(buf, sizeof(buf), "no");
527         else
528                 snprintf(buf, sizeof(buf), "%s", supp ? "yes" : "no");
529 
530         return buf;
531 }
532 
533 static char * print_phyname(const struct iwinfo_ops *iw, const char *ifname)
534 {
535         static char buf[32];
536 
537         if (!iw->phyname(ifname, buf))
538                 return buf;
539 
540         return "?";
541 }
542 
543 
544 static void print_info(const struct iwinfo_ops *iw, const char *ifname)
545 {
546         printf("%-9s ESSID: %s\n",
547                 ifname,
548                 print_ssid(iw, ifname));
549         printf("          Access Point: %s\n",
550                 print_bssid(iw, ifname));
551         printf("          Mode: %s  Channel: %s (%s)\n",
552                 print_mode(iw, ifname),
553                 print_channel(iw, ifname),
554                 print_frequency(iw, ifname));
555         printf("          Tx-Power: %s  Link Quality: %s/%s\n",
556                 print_txpower(iw, ifname),
557                 print_quality(iw, ifname),
558                 print_quality_max(iw, ifname));
559         printf("          Signal: %s  Noise: %s\n",
560                 print_signal(iw, ifname),
561                 print_noise(iw, ifname));
562         printf("          Bit Rate: %s\n",
563                 print_rate(iw, ifname));
564         printf("          Encryption: %s\n",
565                 print_encryption(iw, ifname));
566         printf("          Type: %s  HW Mode(s): %s\n",
567                 print_type(iw, ifname),
568                 print_hwmodes(iw, ifname));
569         printf("          Hardware: %s [%s]\n",
570                 print_hardware_id(iw, ifname),
571                 print_hardware_name(iw, ifname));
572         printf("          TX power offset: %s\n",
573                 print_txpower_offset(iw, ifname));
574         printf("          Frequency offset: %s\n",
575                 print_frequency_offset(iw, ifname));
576         printf("          Supports VAPs: %s  PHY name: %s\n",
577                 print_mbssid_supp(iw, ifname),
578                 print_phyname(iw, ifname));
579 }
580 
581 
582 static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname)
583 {
584         int i, x, len;
585         char buf[IWINFO_BUFSIZE];
586         struct iwinfo_scanlist_entry *e;
587 
588         if (iw->scanlist(ifname, buf, &len))
589         {
590                 printf("Scanning not possible\n\n");
591                 return;
592         }
593         else if (len <= 0)
594         {
595                 printf("No scan results\n\n");
596                 return;
597         }
598 
599         for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_scanlist_entry), x++)
600         {
601                 e = (struct iwinfo_scanlist_entry *) &buf[i];
602 
603                 printf("Cell %02d - Address: %s\n",
604                         x,
605                         format_bssid(e->mac));
606                 printf("          ESSID: %s\n",
607                         format_ssid(e->ssid));
608                 printf("          Mode: %s  Channel: %s\n",
609                         IWINFO_OPMODE_NAMES[e->mode],
610                         format_channel(e->channel));
611                 printf("          Signal: %s  Quality: %s/%s\n",
612                         format_signal(e->signal - 0x100),
613                         format_quality(e->quality),
614                         format_quality_max(e->quality_max));
615                 printf("          Encryption: %s\n",
616                         format_encryption(&e->crypto));
617                 if (e->has_bss_load) {
618                         printf("          Station count: %u\n",
619                                 e->station_count);
620                         printf("          Channel utilization: %u/255\n",
621                                 e->channel_utilization);
622                         printf("          Available admission capacity: %u (*32us)\n",
623                                 e->admission_capacity);
624                 }
625                 printf("\n");
626         }
627 }
628 
629 
630 static void print_txpwrlist(const struct iwinfo_ops *iw, const char *ifname)
631 {
632         int len, pwr, off, i;
633         char buf[IWINFO_BUFSIZE];
634         struct iwinfo_txpwrlist_entry *e;
635 
636         if (iw->txpwrlist(ifname, buf, &len) || len <= 0)
637         {
638                 printf("No TX power information available\n");
639                 return;
640         }
641 
642         if (iw->txpower(ifname, &pwr))
643                 pwr = -1;
644 
645         if (iw->txpower_offset(ifname, &off))
646                 off = 0;
647 
648         for (i = 0; i < len; i += sizeof(struct iwinfo_txpwrlist_entry))
649         {
650                 e = (struct iwinfo_txpwrlist_entry *) &buf[i];
651 
652                 printf("%s%3d dBm (%4d mW)\n",
653                         (pwr == e->dbm) ? "*" : " ",
654                         e->dbm + off,
655                         iwinfo_dbm2mw(e->dbm + off));
656         }
657 }
658 
659 
660 static void print_freqlist(const struct iwinfo_ops *iw, const char *ifname)
661 {
662         int i, len, ch;
663         char buf[IWINFO_BUFSIZE];
664         struct iwinfo_freqlist_entry *e;
665 
666         if (iw->freqlist(ifname, buf, &len) || len <= 0)
667         {
668                 printf("No frequency information available\n");
669                 return;
670         }
671 
672         if (iw->channel(ifname, &ch))
673                 ch = -1;
674 
675         for (i = 0; i < len; i += sizeof(struct iwinfo_freqlist_entry))
676         {
677                 e = (struct iwinfo_freqlist_entry *) &buf[i];
678 
679                 printf("%s %s (Channel %s)%s\n",
680                         (ch == e->channel) ? "*" : " ",
681                         format_frequency(e->mhz),
682                         format_channel(e->channel),
683                         e->restricted ? " [restricted]" : "");
684         }
685 }
686 
687 
688 static void print_assoclist(const struct iwinfo_ops *iw, const char *ifname)
689 {
690         int i, len;
691         char buf[IWINFO_BUFSIZE];
692         struct iwinfo_assoclist_entry *e;
693 
694         if (iw->assoclist(ifname, buf, &len))
695         {
696                 printf("No information available\n");
697                 return;
698         }
699         else if (len <= 0)
700         {
701                 printf("No station connected\n");
702                 return;
703         }
704 
705         for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry))
706         {
707                 e = (struct iwinfo_assoclist_entry *) &buf[i];
708 
709                 printf("%s  %s / %s (SNR %d)  %d ms ago\n",
710                         format_bssid(e->mac),
711                         format_signal(e->signal),
712                         format_noise(e->noise),
713                         (e->signal - e->noise),
714                         e->inactive);
715 
716                 printf("        RX: %-38s  %8d Pkts.\n",
717                         format_assocrate(&e->rx_rate),
718                         e->rx_packets
719                 );
720 
721                 printf("        TX: %-38s  %8d Pkts.\n",
722                         format_assocrate(&e->tx_rate),
723                         e->tx_packets
724                 );
725 
726                 printf("        expected throughput: %s\n\n",
727                         format_rate(e->thr));
728         }
729 }
730 
731 
732 static char * lookup_country(char *buf, int len, int iso3166)
733 {
734         int i;
735         struct iwinfo_country_entry *c;
736 
737         for (i = 0; i < len; i += sizeof(struct iwinfo_country_entry))
738         {
739                 c = (struct iwinfo_country_entry *) &buf[i];
740 
741                 if (c->iso3166 == iso3166)
742                         return c->ccode;
743         }
744 
745         return NULL;
746 }
747 
748 static void print_countrylist(const struct iwinfo_ops *iw, const char *ifname)
749 {
750         int len;
751         char buf[IWINFO_BUFSIZE];
752         char *ccode;
753         char curcode[3];
754         const struct iwinfo_iso3166_label *l;
755 
756         if (iw->countrylist(ifname, buf, &len))
757         {
758                 printf("No country code information available\n");
759                 return;
760         }
761 
762         if (iw->country(ifname, curcode))
763                 memset(curcode, 0, sizeof(curcode));
764 
765         for (l = IWINFO_ISO3166_NAMES; l->iso3166; l++)
766         {
767                 if ((ccode = lookup_country(buf, len, l->iso3166)) != NULL)
768                 {
769                         printf("%s %4s  %c%c\n",
770                                 strncmp(ccode, curcode, 2) ? " " : "*",
771                                 ccode, (l->iso3166 / 256), (l->iso3166 % 256));
772                 }
773         }
774 }
775 
776 static void print_htmodelist(const struct iwinfo_ops *iw, const char *ifname)
777 {
778         int i, htmodes = 0;
779 
780         if (iw->htmodelist(ifname, &htmodes))
781         {
782                 printf("No HT mode information available\n");
783                 return;
784         }
785 
786         for (i = 0; i < ARRAY_SIZE(IWINFO_HTMODE_NAMES); i++)
787                 if (htmodes & (1 << i))
788                         printf("%s ", IWINFO_HTMODE_NAMES[i]);
789 
790         printf("\n");
791 }
792 
793 static void lookup_phy(const struct iwinfo_ops *iw, const char *section)
794 {
795         char buf[IWINFO_BUFSIZE];
796 
797         if (!iw->lookup_phy)
798         {
799                 fprintf(stderr, "Not supported\n");
800                 return;
801         }
802 
803         if (iw->lookup_phy(section, buf))
804         {
805                 fprintf(stderr, "Phy not found\n");
806                 return;
807         }
808 
809         printf("%s\n", buf);
810 }
811 
812 
813 int main(int argc, char **argv)
814 {
815         int i, rv = 0;
816         char *p;
817         const struct iwinfo_ops *iw;
818         glob_t globbuf;
819 
820         if (argc > 1 && argc < 3)
821         {
822                 fprintf(stderr,
823                         "Usage:\n"
824                         "       iwinfo <device> info\n"
825                         "       iwinfo <device> scan\n"
826                         "       iwinfo <device> txpowerlist\n"
827                         "       iwinfo <device> freqlist\n"
828                         "       iwinfo <device> assoclist\n"
829                         "       iwinfo <device> countrylist\n"
830                         "       iwinfo <device> htmodelist\n"
831                         "       iwinfo <backend> phyname <section>\n"
832                 );
833 
834                 return 1;
835         }
836 
837         if (argc == 1)
838         {
839                 glob("/sys/class/net/*", 0, NULL, &globbuf);
840 
841                 for (i = 0; i < globbuf.gl_pathc; i++)
842                 {
843                         p = strrchr(globbuf.gl_pathv[i], '/');
844 
845                         if (!p)
846                                 continue;
847 
848                         iw = iwinfo_backend(++p);
849 
850                         if (!iw)
851                                 continue;
852 
853                         print_info(iw, p);
854                         printf("\n");
855                 }
856 
857                 globfree(&globbuf);
858                 return 0;
859         }
860 
861         if (argc > 3)
862         {
863                 iw = iwinfo_backend_by_name(argv[1]);
864 
865                 if (!iw)
866                 {
867                         fprintf(stderr, "No such wireless backend: %s\n", argv[1]);
868                         rv = 1;
869                 }
870                 else
871                 {
872                         switch (argv[2][0])
873                         {
874                         case 'p':
875                                 lookup_phy(iw, argv[3]);
876                                 break;
877 
878                         default:
879                                 fprintf(stderr, "Unknown command: %s\n", argv[2]);
880                                 rv = 1;
881                         }
882                 }
883         }
884         else
885         {
886                 iw = iwinfo_backend(argv[1]);
887 
888                 if (!iw)
889                 {
890                         fprintf(stderr, "No such wireless device: %s\n", argv[1]);
891                         rv = 1;
892                 }
893                 else
894                 {
895                         for (i = 2; i < argc; i++)
896                         {
897                                 switch(argv[i][0])
898                                 {
899                                 case 'i':
900                                         print_info(iw, argv[1]);
901                                         break;
902 
903                                 case 's':
904                                         print_scanlist(iw, argv[1]);
905                                         break;
906 
907                                 case 't':
908                                         print_txpwrlist(iw, argv[1]);
909                                         break;
910 
911                                 case 'f':
912                                         print_freqlist(iw, argv[1]);
913                                         break;
914 
915                                 case 'a':
916                                         print_assoclist(iw, argv[1]);
917                                         break;
918 
919                                 case 'c':
920                                         print_countrylist(iw, argv[1]);
921                                         break;
922 
923                                 case 'h':
924                                         print_htmodelist(iw, argv[1]);
925                                         break;
926 
927                                 default:
928                                         fprintf(stderr, "Unknown command: %s\n", argv[i]);
929                                         rv = 1;
930                                 }
931                         }
932                 }
933         }
934 
935         iwinfo_finish();
936 
937         return rv;
938 }
939 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt