nl80211: support reading hardware id from phy directly
[project/iwinfo.git] / 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[14];
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 || (suites & IWINFO_KMGMT_NONE))
190 pos += sprintf(pos, "NONE/");
191
192 *(pos - 1) = 0;
193
194 return str;
195 }
196
197 static char * format_encryption(struct iwinfo_crypto_entry *c)
198 {
199 static char buf[512];
200
201 if (!c)
202 {
203 snprintf(buf, sizeof(buf), "unknown");
204 }
205 else if (c->enabled)
206 {
207 /* WEP */
208 if (c->auth_algs && !c->wpa_version)
209 {
210 if ((c->auth_algs & IWINFO_AUTH_OPEN) &&
211 (c->auth_algs & IWINFO_AUTH_SHARED))
212 {
213 snprintf(buf, sizeof(buf), "WEP Open/Shared (%s)",
214 format_enc_ciphers(c->pair_ciphers));
215 }
216 else if (c->auth_algs & IWINFO_AUTH_OPEN)
217 {
218 snprintf(buf, sizeof(buf), "WEP Open System (%s)",
219 format_enc_ciphers(c->pair_ciphers));
220 }
221 else if (c->auth_algs & IWINFO_AUTH_SHARED)
222 {
223 snprintf(buf, sizeof(buf), "WEP Shared Auth (%s)",
224 format_enc_ciphers(c->pair_ciphers));
225 }
226 }
227
228 /* WPA */
229 else if (c->wpa_version)
230 {
231 switch (c->wpa_version) {
232 case 3:
233 snprintf(buf, sizeof(buf), "mixed WPA/WPA2 %s (%s)",
234 format_enc_suites(c->auth_suites),
235 format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
236 break;
237
238 case 2:
239 snprintf(buf, sizeof(buf), "WPA2 %s (%s)",
240 format_enc_suites(c->auth_suites),
241 format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
242 break;
243
244 case 1:
245 snprintf(buf, sizeof(buf), "WPA %s (%s)",
246 format_enc_suites(c->auth_suites),
247 format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
248 break;
249 }
250 }
251 else
252 {
253 snprintf(buf, sizeof(buf), "none");
254 }
255 }
256 else
257 {
258 snprintf(buf, sizeof(buf), "none");
259 }
260
261 return buf;
262 }
263
264 static char * format_hwmodes(int modes)
265 {
266 static char buf[15];
267
268 if (modes <= 0)
269 snprintf(buf, sizeof(buf), "unknown");
270 else
271 snprintf(buf, sizeof(buf), "802.11%s%s%s%s%s%s",
272 (modes & IWINFO_80211_A) ? "a" : "",
273 (modes & IWINFO_80211_B) ? "b" : "",
274 (modes & IWINFO_80211_G) ? "g" : "",
275 (modes & IWINFO_80211_N) ? "n" : "",
276 (modes & IWINFO_80211_AC) ? "ac" : "",
277 (modes & IWINFO_80211_AD) ? "ad" : "");
278
279 return buf;
280 }
281
282 static char * format_assocrate(struct iwinfo_rate_entry *r)
283 {
284 static char buf[80];
285 char *p = buf;
286 int l = sizeof(buf);
287
288 if (r->rate <= 0)
289 {
290 snprintf(buf, sizeof(buf), "unknown");
291 }
292 else
293 {
294 p += snprintf(p, l, "%s", format_rate(r->rate));
295 l = sizeof(buf) - (p - buf);
296
297 if (r->is_ht)
298 {
299 p += snprintf(p, l, ", MCS %d, %dMHz", r->mcs, r->mhz);
300 l = sizeof(buf) - (p - buf);
301 }
302 else if (r->is_vht)
303 {
304 p += snprintf(p, l, ", VHT-MCS %d, %dMHz", r->mcs, r->mhz);
305 l = sizeof(buf) - (p - buf);
306
307 if (r->nss)
308 {
309 p += snprintf(p, l, ", VHT-NSS %d", r->nss);
310 l = sizeof(buf) - (p - buf);
311 }
312 }
313 }
314
315 return buf;
316 }
317
318
319 static const char * print_type(const struct iwinfo_ops *iw, const char *ifname)
320 {
321 const char *type = iwinfo_type(ifname);
322 return type ? type : "unknown";
323 }
324
325 static char * print_hardware_id(const struct iwinfo_ops *iw, const char *ifname)
326 {
327 static char buf[20];
328 struct iwinfo_hardware_id ids;
329
330 if (!iw->hardware_id(ifname, (char *)&ids))
331 {
332 snprintf(buf, sizeof(buf), "%04X:%04X %04X:%04X",
333 ids.vendor_id, ids.device_id,
334 ids.subsystem_vendor_id, ids.subsystem_device_id);
335 }
336 else
337 {
338 snprintf(buf, sizeof(buf), "unknown");
339 }
340
341 return buf;
342 }
343
344 static char * print_hardware_name(const struct iwinfo_ops *iw, const char *ifname)
345 {
346 static char buf[128];
347
348 if (iw->hardware_name(ifname, buf))
349 snprintf(buf, sizeof(buf), "unknown");
350
351 return buf;
352 }
353
354 static char * print_txpower_offset(const struct iwinfo_ops *iw, const char *ifname)
355 {
356 int off;
357 static char buf[12];
358
359 if (iw->txpower_offset(ifname, &off))
360 snprintf(buf, sizeof(buf), "unknown");
361 else if (off != 0)
362 snprintf(buf, sizeof(buf), "%d dB", off);
363 else
364 snprintf(buf, sizeof(buf), "none");
365
366 return buf;
367 }
368
369 static char * print_frequency_offset(const struct iwinfo_ops *iw, const char *ifname)
370 {
371 int off;
372 static char buf[12];
373
374 if (iw->frequency_offset(ifname, &off))
375 snprintf(buf, sizeof(buf), "unknown");
376 else if (off != 0)
377 snprintf(buf, sizeof(buf), "%.3f GHz", ((float)off / 1000.0));
378 else
379 snprintf(buf, sizeof(buf), "none");
380
381 return buf;
382 }
383
384 static char * print_ssid(const struct iwinfo_ops *iw, const char *ifname)
385 {
386 char buf[IWINFO_ESSID_MAX_SIZE+1] = { 0 };
387
388 if (iw->ssid(ifname, buf))
389 memset(buf, 0, sizeof(buf));
390
391 return format_ssid(buf);
392 }
393
394 static char * print_bssid(const struct iwinfo_ops *iw, const char *ifname)
395 {
396 static char buf[18] = { 0 };
397
398 if (iw->bssid(ifname, buf))
399 snprintf(buf, sizeof(buf), "00:00:00:00:00:00");
400
401 return buf;
402 }
403
404 static char * print_mode(const struct iwinfo_ops *iw, const char *ifname)
405 {
406 int mode;
407 static char buf[128];
408
409 if (iw->mode(ifname, &mode))
410 mode = IWINFO_OPMODE_UNKNOWN;
411
412 snprintf(buf, sizeof(buf), "%s", IWINFO_OPMODE_NAMES[mode]);
413
414 return buf;
415 }
416
417 static char * print_channel(const struct iwinfo_ops *iw, const char *ifname)
418 {
419 int ch;
420 if (iw->channel(ifname, &ch))
421 ch = -1;
422
423 return format_channel(ch);
424 }
425
426 static char * print_frequency(const struct iwinfo_ops *iw, const char *ifname)
427 {
428 int freq;
429 if (iw->frequency(ifname, &freq))
430 freq = -1;
431
432 return format_frequency(freq);
433 }
434
435 static char * print_txpower(const struct iwinfo_ops *iw, const char *ifname)
436 {
437 int pwr, off;
438 if (iw->txpower_offset(ifname, &off))
439 off = 0;
440
441 if (iw->txpower(ifname, &pwr))
442 pwr = -1;
443 else
444 pwr += off;
445
446 return format_txpower(pwr);
447 }
448
449 static char * print_quality(const struct iwinfo_ops *iw, const char *ifname)
450 {
451 int qual;
452 if (iw->quality(ifname, &qual))
453 qual = -1;
454
455 return format_quality(qual);
456 }
457
458 static char * print_quality_max(const struct iwinfo_ops *iw, const char *ifname)
459 {
460 int qmax;
461 if (iw->quality_max(ifname, &qmax))
462 qmax = -1;
463
464 return format_quality_max(qmax);
465 }
466
467 static char * print_signal(const struct iwinfo_ops *iw, const char *ifname)
468 {
469 int sig;
470 if (iw->signal(ifname, &sig))
471 sig = 0;
472
473 return format_signal(sig);
474 }
475
476 static char * print_noise(const struct iwinfo_ops *iw, const char *ifname)
477 {
478 int noise;
479 if (iw->noise(ifname, &noise))
480 noise = 0;
481
482 return format_noise(noise);
483 }
484
485 static char * print_rate(const struct iwinfo_ops *iw, const char *ifname)
486 {
487 int rate;
488 if (iw->bitrate(ifname, &rate))
489 rate = -1;
490
491 return format_rate(rate);
492 }
493
494 static char * print_encryption(const struct iwinfo_ops *iw, const char *ifname)
495 {
496 struct iwinfo_crypto_entry c = { 0 };
497 if (iw->encryption(ifname, (char *)&c))
498 return format_encryption(NULL);
499
500 return format_encryption(&c);
501 }
502
503 static char * print_hwmodes(const struct iwinfo_ops *iw, const char *ifname)
504 {
505 int modes;
506 if (iw->hwmodelist(ifname, &modes))
507 modes = -1;
508
509 return format_hwmodes(modes);
510 }
511
512 static char * print_mbssid_supp(const struct iwinfo_ops *iw, const char *ifname)
513 {
514 int supp;
515 static char buf[4];
516
517 if (iw->mbssid_support(ifname, &supp))
518 snprintf(buf, sizeof(buf), "no");
519 else
520 snprintf(buf, sizeof(buf), "%s", supp ? "yes" : "no");
521
522 return buf;
523 }
524
525 static char * print_phyname(const struct iwinfo_ops *iw, const char *ifname)
526 {
527 static char buf[32];
528
529 if (!iw->phyname(ifname, buf))
530 return buf;
531
532 return "?";
533 }
534
535
536 static void print_info(const struct iwinfo_ops *iw, const char *ifname)
537 {
538 printf("%-9s ESSID: %s\n",
539 ifname,
540 print_ssid(iw, ifname));
541 printf(" Access Point: %s\n",
542 print_bssid(iw, ifname));
543 printf(" Mode: %s Channel: %s (%s)\n",
544 print_mode(iw, ifname),
545 print_channel(iw, ifname),
546 print_frequency(iw, ifname));
547 printf(" Tx-Power: %s Link Quality: %s/%s\n",
548 print_txpower(iw, ifname),
549 print_quality(iw, ifname),
550 print_quality_max(iw, ifname));
551 printf(" Signal: %s Noise: %s\n",
552 print_signal(iw, ifname),
553 print_noise(iw, ifname));
554 printf(" Bit Rate: %s\n",
555 print_rate(iw, ifname));
556 printf(" Encryption: %s\n",
557 print_encryption(iw, ifname));
558 printf(" Type: %s HW Mode(s): %s\n",
559 print_type(iw, ifname),
560 print_hwmodes(iw, ifname));
561 printf(" Hardware: %s [%s]\n",
562 print_hardware_id(iw, ifname),
563 print_hardware_name(iw, ifname));
564 printf(" TX power offset: %s\n",
565 print_txpower_offset(iw, ifname));
566 printf(" Frequency offset: %s\n",
567 print_frequency_offset(iw, ifname));
568 printf(" Supports VAPs: %s PHY name: %s\n",
569 print_mbssid_supp(iw, ifname),
570 print_phyname(iw, ifname));
571 }
572
573
574 static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname)
575 {
576 int i, x, len;
577 char buf[IWINFO_BUFSIZE];
578 struct iwinfo_scanlist_entry *e;
579
580 if (iw->scanlist(ifname, buf, &len))
581 {
582 printf("Scanning not possible\n\n");
583 return;
584 }
585 else if (len <= 0)
586 {
587 printf("No scan results\n\n");
588 return;
589 }
590
591 for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_scanlist_entry), x++)
592 {
593 e = (struct iwinfo_scanlist_entry *) &buf[i];
594
595 printf("Cell %02d - Address: %s\n",
596 x,
597 format_bssid(e->mac));
598 printf(" ESSID: %s\n",
599 format_ssid(e->ssid));
600 printf(" Mode: %s Channel: %s\n",
601 IWINFO_OPMODE_NAMES[e->mode],
602 format_channel(e->channel));
603 printf(" Signal: %s Quality: %s/%s\n",
604 format_signal(e->signal - 0x100),
605 format_quality(e->quality),
606 format_quality_max(e->quality_max));
607 printf(" Encryption: %s\n\n",
608 format_encryption(&e->crypto));
609 }
610 }
611
612
613 static void print_txpwrlist(const struct iwinfo_ops *iw, const char *ifname)
614 {
615 int len, pwr, off, i;
616 char buf[IWINFO_BUFSIZE];
617 struct iwinfo_txpwrlist_entry *e;
618
619 if (iw->txpwrlist(ifname, buf, &len) || len <= 0)
620 {
621 printf("No TX power information available\n");
622 return;
623 }
624
625 if (iw->txpower(ifname, &pwr))
626 pwr = -1;
627
628 if (iw->txpower_offset(ifname, &off))
629 off = 0;
630
631 for (i = 0; i < len; i += sizeof(struct iwinfo_txpwrlist_entry))
632 {
633 e = (struct iwinfo_txpwrlist_entry *) &buf[i];
634
635 printf("%s%3d dBm (%4d mW)\n",
636 (pwr == e->dbm) ? "*" : " ",
637 e->dbm + off,
638 iwinfo_dbm2mw(e->dbm + off));
639 }
640 }
641
642
643 static void print_freqlist(const struct iwinfo_ops *iw, const char *ifname)
644 {
645 int i, len, ch;
646 char buf[IWINFO_BUFSIZE];
647 struct iwinfo_freqlist_entry *e;
648
649 if (iw->freqlist(ifname, buf, &len) || len <= 0)
650 {
651 printf("No frequency information available\n");
652 return;
653 }
654
655 if (iw->channel(ifname, &ch))
656 ch = -1;
657
658 for (i = 0; i < len; i += sizeof(struct iwinfo_freqlist_entry))
659 {
660 e = (struct iwinfo_freqlist_entry *) &buf[i];
661
662 printf("%s %s (Channel %s)%s\n",
663 (ch == e->channel) ? "*" : " ",
664 format_frequency(e->mhz),
665 format_channel(e->channel),
666 e->restricted ? " [restricted]" : "");
667 }
668 }
669
670
671 static void print_assoclist(const struct iwinfo_ops *iw, const char *ifname)
672 {
673 int i, len;
674 char buf[IWINFO_BUFSIZE];
675 struct iwinfo_assoclist_entry *e;
676
677 if (iw->assoclist(ifname, buf, &len))
678 {
679 printf("No information available\n");
680 return;
681 }
682 else if (len <= 0)
683 {
684 printf("No station connected\n");
685 return;
686 }
687
688 for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry))
689 {
690 e = (struct iwinfo_assoclist_entry *) &buf[i];
691
692 printf("%s %s / %s (SNR %d) %d ms ago\n",
693 format_bssid(e->mac),
694 format_signal(e->signal),
695 format_noise(e->noise),
696 (e->signal - e->noise),
697 e->inactive);
698
699 printf(" RX: %-38s %8d Pkts.\n",
700 format_assocrate(&e->rx_rate),
701 e->rx_packets
702 );
703
704 printf(" TX: %-38s %8d Pkts.\n",
705 format_assocrate(&e->tx_rate),
706 e->tx_packets
707 );
708
709 printf(" expected throughput: %s\n\n",
710 format_rate(e->thr));
711 }
712 }
713
714
715 static char * lookup_country(char *buf, int len, int iso3166)
716 {
717 int i;
718 struct iwinfo_country_entry *c;
719
720 for (i = 0; i < len; i += sizeof(struct iwinfo_country_entry))
721 {
722 c = (struct iwinfo_country_entry *) &buf[i];
723
724 if (c->iso3166 == iso3166)
725 return c->ccode;
726 }
727
728 return NULL;
729 }
730
731 static void print_countrylist(const struct iwinfo_ops *iw, const char *ifname)
732 {
733 int len;
734 char buf[IWINFO_BUFSIZE];
735 char *ccode;
736 char curcode[3];
737 const struct iwinfo_iso3166_label *l;
738
739 if (iw->countrylist(ifname, buf, &len))
740 {
741 printf("No country code information available\n");
742 return;
743 }
744
745 if (iw->country(ifname, curcode))
746 memset(curcode, 0, sizeof(curcode));
747
748 for (l = IWINFO_ISO3166_NAMES; l->iso3166; l++)
749 {
750 if ((ccode = lookup_country(buf, len, l->iso3166)) != NULL)
751 {
752 printf("%s %4s %c%c\n",
753 strncmp(ccode, curcode, 2) ? " " : "*",
754 ccode, (l->iso3166 / 256), (l->iso3166 % 256));
755 }
756 }
757 }
758
759 static void print_htmodelist(const struct iwinfo_ops *iw, const char *ifname)
760 {
761 int i, htmodes = 0;
762
763 if (iw->htmodelist(ifname, &htmodes))
764 {
765 printf("No HT mode information available\n");
766 return;
767 }
768
769 for (i = 0; i < ARRAY_SIZE(IWINFO_HTMODE_NAMES); i++)
770 if (htmodes & (1 << i))
771 printf("%s ", IWINFO_HTMODE_NAMES[i]);
772
773 printf("\n");
774 }
775
776 static void lookup_phy(const struct iwinfo_ops *iw, const char *section)
777 {
778 char buf[IWINFO_BUFSIZE];
779
780 if (!iw->lookup_phy)
781 {
782 fprintf(stderr, "Not supported\n");
783 return;
784 }
785
786 if (iw->lookup_phy(section, buf))
787 {
788 fprintf(stderr, "Phy not found\n");
789 return;
790 }
791
792 printf("%s\n", buf);
793 }
794
795
796 int main(int argc, char **argv)
797 {
798 int i, rv = 0;
799 char *p;
800 const struct iwinfo_ops *iw;
801 glob_t globbuf;
802
803 if (argc > 1 && argc < 3)
804 {
805 fprintf(stderr,
806 "Usage:\n"
807 " iwinfo <device> info\n"
808 " iwinfo <device> scan\n"
809 " iwinfo <device> txpowerlist\n"
810 " iwinfo <device> freqlist\n"
811 " iwinfo <device> assoclist\n"
812 " iwinfo <device> countrylist\n"
813 " iwinfo <device> htmodelist\n"
814 " iwinfo <backend> phyname <section>\n"
815 );
816
817 return 1;
818 }
819
820 if (argc == 1)
821 {
822 glob("/sys/class/net/*", 0, NULL, &globbuf);
823
824 for (i = 0; i < globbuf.gl_pathc; i++)
825 {
826 p = strrchr(globbuf.gl_pathv[i], '/');
827
828 if (!p)
829 continue;
830
831 iw = iwinfo_backend(++p);
832
833 if (!iw)
834 continue;
835
836 print_info(iw, p);
837 printf("\n");
838 }
839
840 globfree(&globbuf);
841 return 0;
842 }
843
844 if (argc > 3)
845 {
846 iw = iwinfo_backend_by_name(argv[1]);
847
848 if (!iw)
849 {
850 fprintf(stderr, "No such wireless backend: %s\n", argv[1]);
851 rv = 1;
852 }
853 else
854 {
855 switch (argv[2][0])
856 {
857 case 'p':
858 lookup_phy(iw, argv[3]);
859 break;
860
861 default:
862 fprintf(stderr, "Unknown command: %s\n", argv[2]);
863 rv = 1;
864 }
865 }
866 }
867 else
868 {
869 iw = iwinfo_backend(argv[1]);
870
871 if (!iw)
872 {
873 fprintf(stderr, "No such wireless device: %s\n", argv[1]);
874 rv = 1;
875 }
876 else
877 {
878 for (i = 2; i < argc; i++)
879 {
880 switch(argv[i][0])
881 {
882 case 'i':
883 print_info(iw, argv[1]);
884 break;
885
886 case 's':
887 print_scanlist(iw, argv[1]);
888 break;
889
890 case 't':
891 print_txpwrlist(iw, argv[1]);
892 break;
893
894 case 'f':
895 print_freqlist(iw, argv[1]);
896 break;
897
898 case 'a':
899 print_assoclist(iw, argv[1]);
900 break;
901
902 case 'c':
903 print_countrylist(iw, argv[1]);
904 break;
905
906 case 'h':
907 print_htmodelist(iw, argv[1]);
908 break;
909
910 default:
911 fprintf(stderr, "Unknown command: %s\n", argv[i]);
912 rv = 1;
913 }
914 }
915 }
916 }
917
918 iwinfo_finish();
919
920 return rv;
921 }