iwinfo_cli.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. /*
  2. * iwinfo - Wireless Information Library - Command line frontend
  3. *
  4. * Copyright (C) 2011 Jo-Philipp Wich <[email protected]>
  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. #include <stdio.h>
  19. #include <glob.h>
  20. #include "iwinfo.h"
  21. static char * format_bssid(unsigned char *mac)
  22. {
  23. static char buf[18];
  24. snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X",
  25. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  26. return buf;
  27. }
  28. static char * format_ssid(char *ssid)
  29. {
  30. static char buf[IWINFO_ESSID_MAX_SIZE+3];
  31. if (ssid && ssid[0])
  32. snprintf(buf, sizeof(buf), "\"%s\"", ssid);
  33. else
  34. snprintf(buf, sizeof(buf), "unknown");
  35. return buf;
  36. }
  37. static char * format_channel(int ch)
  38. {
  39. static char buf[8];
  40. if (ch <= 0)
  41. snprintf(buf, sizeof(buf), "unknown");
  42. else
  43. snprintf(buf, sizeof(buf), "%d", ch);
  44. return buf;
  45. }
  46. static char * format_frequency(int freq)
  47. {
  48. static char buf[10];
  49. if (freq <= 0)
  50. snprintf(buf, sizeof(buf), "unknown");
  51. else
  52. snprintf(buf, sizeof(buf), "%.3f GHz", ((float)freq / 1000.0));
  53. return buf;
  54. }
  55. static char * format_txpower(int pwr)
  56. {
  57. static char buf[10];
  58. if (pwr < 0)
  59. snprintf(buf, sizeof(buf), "unknown");
  60. else
  61. snprintf(buf, sizeof(buf), "%d dBm", pwr);
  62. return buf;
  63. }
  64. static char * format_quality(int qual)
  65. {
  66. static char buf[8];
  67. if (qual < 0)
  68. snprintf(buf, sizeof(buf), "unknown");
  69. else
  70. snprintf(buf, sizeof(buf), "%d", qual);
  71. return buf;
  72. }
  73. static char * format_quality_max(int qmax)
  74. {
  75. static char buf[8];
  76. if (qmax < 0)
  77. snprintf(buf, sizeof(buf), "unknown");
  78. else
  79. snprintf(buf, sizeof(buf), "%d", qmax);
  80. return buf;
  81. }
  82. static char * format_signal(int sig)
  83. {
  84. static char buf[10];
  85. if (!sig)
  86. snprintf(buf, sizeof(buf), "unknown");
  87. else
  88. snprintf(buf, sizeof(buf), "%d dBm", sig);
  89. return buf;
  90. }
  91. static char * format_noise(int noise)
  92. {
  93. static char buf[10];
  94. if (!noise)
  95. snprintf(buf, sizeof(buf), "unknown");
  96. else
  97. snprintf(buf, sizeof(buf), "%d dBm", noise);
  98. return buf;
  99. }
  100. static char * format_rate(int rate)
  101. {
  102. static char buf[14];
  103. if (rate <= 0)
  104. snprintf(buf, sizeof(buf), "unknown");
  105. else
  106. snprintf(buf, sizeof(buf), "%d.%d MBit/s",
  107. rate / 1000, (rate % 1000) / 100);
  108. return buf;
  109. }
  110. static char * format_enc_ciphers(int ciphers)
  111. {
  112. static char str[128] = { 0 };
  113. char *pos = str;
  114. if (ciphers & IWINFO_CIPHER_WEP40)
  115. pos += sprintf(pos, "WEP-40, ");
  116. if (ciphers & IWINFO_CIPHER_WEP104)
  117. pos += sprintf(pos, "WEP-104, ");
  118. if (ciphers & IWINFO_CIPHER_TKIP)
  119. pos += sprintf(pos, "TKIP, ");
  120. if (ciphers & IWINFO_CIPHER_CCMP)
  121. pos += sprintf(pos, "CCMP, ");
  122. if (ciphers & IWINFO_CIPHER_WRAP)
  123. pos += sprintf(pos, "WRAP, ");
  124. if (ciphers & IWINFO_CIPHER_AESOCB)
  125. pos += sprintf(pos, "AES-OCB, ");
  126. if (ciphers & IWINFO_CIPHER_CKIP)
  127. pos += sprintf(pos, "CKIP, ");
  128. if (!ciphers || (ciphers & IWINFO_CIPHER_NONE))
  129. pos += sprintf(pos, "NONE, ");
  130. *(pos - 2) = 0;
  131. return str;
  132. }
  133. static char * format_enc_suites(int suites)
  134. {
  135. static char str[64] = { 0 };
  136. char *pos = str;
  137. if (suites & IWINFO_KMGMT_PSK)
  138. pos += sprintf(pos, "PSK/");
  139. if (suites & IWINFO_KMGMT_8021x)
  140. pos += sprintf(pos, "802.1X/");
  141. if (!suites || (suites & IWINFO_KMGMT_NONE))
  142. pos += sprintf(pos, "NONE/");
  143. *(pos - 1) = 0;
  144. return str;
  145. }
  146. static char * format_encryption(struct iwinfo_crypto_entry *c)
  147. {
  148. static char buf[512];
  149. if (!c)
  150. {
  151. snprintf(buf, sizeof(buf), "unknown");
  152. }
  153. else if (c->enabled)
  154. {
  155. /* WEP */
  156. if (c->auth_algs && !c->wpa_version)
  157. {
  158. if ((c->auth_algs & IWINFO_AUTH_OPEN) &&
  159. (c->auth_algs & IWINFO_AUTH_SHARED))
  160. {
  161. snprintf(buf, sizeof(buf), "WEP Open/Shared (%s)",
  162. format_enc_ciphers(c->pair_ciphers));
  163. }
  164. else if (c->auth_algs & IWINFO_AUTH_OPEN)
  165. {
  166. snprintf(buf, sizeof(buf), "WEP Open System (%s)",
  167. format_enc_ciphers(c->pair_ciphers));
  168. }
  169. else if (c->auth_algs & IWINFO_AUTH_SHARED)
  170. {
  171. snprintf(buf, sizeof(buf), "WEP Shared Auth (%s)",
  172. format_enc_ciphers(c->pair_ciphers));
  173. }
  174. }
  175. /* WPA */
  176. else if (c->wpa_version)
  177. {
  178. switch (c->wpa_version) {
  179. case 3:
  180. snprintf(buf, sizeof(buf), "mixed WPA/WPA2 %s (%s)",
  181. format_enc_suites(c->auth_suites),
  182. format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
  183. break;
  184. case 2:
  185. snprintf(buf, sizeof(buf), "WPA2 %s (%s)",
  186. format_enc_suites(c->auth_suites),
  187. format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
  188. break;
  189. case 1:
  190. snprintf(buf, sizeof(buf), "WPA %s (%s)",
  191. format_enc_suites(c->auth_suites),
  192. format_enc_ciphers(c->pair_ciphers | c->group_ciphers));
  193. break;
  194. }
  195. }
  196. else
  197. {
  198. snprintf(buf, sizeof(buf), "none");
  199. }
  200. }
  201. else
  202. {
  203. snprintf(buf, sizeof(buf), "none");
  204. }
  205. return buf;
  206. }
  207. static char * format_hwmodes(int modes)
  208. {
  209. static char buf[12];
  210. if (modes <= 0)
  211. snprintf(buf, sizeof(buf), "unknown");
  212. else
  213. snprintf(buf, sizeof(buf), "802.11%s%s%s%s",
  214. (modes & IWINFO_80211_A) ? "a" : "",
  215. (modes & IWINFO_80211_B) ? "b" : "",
  216. (modes & IWINFO_80211_G) ? "g" : "",
  217. (modes & IWINFO_80211_N) ? "n" : "");
  218. return buf;
  219. }
  220. static char * format_assocrate(struct iwinfo_rate_entry *r)
  221. {
  222. static char buf[40];
  223. char *p = buf;
  224. int l = sizeof(buf);
  225. if (r->rate <= 0)
  226. {
  227. snprintf(buf, sizeof(buf), "unknown");
  228. }
  229. else
  230. {
  231. p += snprintf(p, l, "%s", format_rate(r->rate));
  232. l = sizeof(buf) - (p - buf);
  233. if (r->mcs >= 0)
  234. {
  235. p += snprintf(p, l, ", MCS %d, %dMHz", r->mcs, 20 + r->is_40mhz*20);
  236. l = sizeof(buf) - (p - buf);
  237. if (r->is_short_gi)
  238. p += snprintf(p, l, ", short GI");
  239. }
  240. }
  241. return buf;
  242. }
  243. static const char * print_type(const struct iwinfo_ops *iw, const char *ifname)
  244. {
  245. const char *type = iwinfo_type(ifname);
  246. return type ? type : "unknown";
  247. }
  248. static char * print_hardware_id(const struct iwinfo_ops *iw, const char *ifname)
  249. {
  250. static char buf[20];
  251. struct iwinfo_hardware_id ids;
  252. if (!iw->hardware_id(ifname, (char *)&ids))
  253. {
  254. snprintf(buf, sizeof(buf), "%04X:%04X %04X:%04X",
  255. ids.vendor_id, ids.device_id,
  256. ids.subsystem_vendor_id, ids.subsystem_device_id);
  257. }
  258. else
  259. {
  260. snprintf(buf, sizeof(buf), "unknown");
  261. }
  262. return buf;
  263. }
  264. static char * print_hardware_name(const struct iwinfo_ops *iw, const char *ifname)
  265. {
  266. static char buf[128];
  267. if (iw->hardware_name(ifname, buf))
  268. snprintf(buf, sizeof(buf), "unknown");
  269. return buf;
  270. }
  271. static char * print_txpower_offset(const struct iwinfo_ops *iw, const char *ifname)
  272. {
  273. int off;
  274. static char buf[12];
  275. if (iw->txpower_offset(ifname, &off))
  276. snprintf(buf, sizeof(buf), "unknown");
  277. else if (off != 0)
  278. snprintf(buf, sizeof(buf), "%d dB", off);
  279. else
  280. snprintf(buf, sizeof(buf), "none");
  281. return buf;
  282. }
  283. static char * print_frequency_offset(const struct iwinfo_ops *iw, const char *ifname)
  284. {
  285. int off;
  286. static char buf[12];
  287. if (iw->frequency_offset(ifname, &off))
  288. snprintf(buf, sizeof(buf), "unknown");
  289. else if (off != 0)
  290. snprintf(buf, sizeof(buf), "%.3f GHz", ((float)off / 1000.0));
  291. else
  292. snprintf(buf, sizeof(buf), "none");
  293. return buf;
  294. }
  295. static char * print_ssid(const struct iwinfo_ops *iw, const char *ifname)
  296. {
  297. char buf[IWINFO_ESSID_MAX_SIZE+1] = { 0 };
  298. if (iw->ssid(ifname, buf))
  299. memset(buf, 0, sizeof(buf));
  300. return format_ssid(buf);
  301. }
  302. static char * print_bssid(const struct iwinfo_ops *iw, const char *ifname)
  303. {
  304. static char buf[18] = { 0 };
  305. if (iw->bssid(ifname, buf))
  306. snprintf(buf, sizeof(buf), "00:00:00:00:00:00");
  307. return buf;
  308. }
  309. static char * print_mode(const struct iwinfo_ops *iw, const char *ifname)
  310. {
  311. int mode;
  312. static char buf[128];
  313. if (iw->mode(ifname, &mode))
  314. mode = IWINFO_OPMODE_UNKNOWN;
  315. snprintf(buf, sizeof(buf), "%s", IWINFO_OPMODE_NAMES[mode]);
  316. return buf;
  317. }
  318. static char * print_channel(const struct iwinfo_ops *iw, const char *ifname)
  319. {
  320. int ch;
  321. if (iw->channel(ifname, &ch))
  322. ch = -1;
  323. return format_channel(ch);
  324. }
  325. static char * print_frequency(const struct iwinfo_ops *iw, const char *ifname)
  326. {
  327. int freq;
  328. if (iw->frequency(ifname, &freq))
  329. freq = -1;
  330. return format_frequency(freq);
  331. }
  332. static char * print_txpower(const struct iwinfo_ops *iw, const char *ifname)
  333. {
  334. int pwr, off;
  335. if (iw->txpower_offset(ifname, &off))
  336. off = 0;
  337. if (iw->txpower(ifname, &pwr))
  338. pwr = -1;
  339. else
  340. pwr += off;
  341. return format_txpower(pwr);
  342. }
  343. static char * print_quality(const struct iwinfo_ops *iw, const char *ifname)
  344. {
  345. int qual;
  346. if (iw->quality(ifname, &qual))
  347. qual = -1;
  348. return format_quality(qual);
  349. }
  350. static char * print_quality_max(const struct iwinfo_ops *iw, const char *ifname)
  351. {
  352. int qmax;
  353. if (iw->quality_max(ifname, &qmax))
  354. qmax = -1;
  355. return format_quality_max(qmax);
  356. }
  357. static char * print_signal(const struct iwinfo_ops *iw, const char *ifname)
  358. {
  359. int sig;
  360. if (iw->signal(ifname, &sig))
  361. sig = 0;
  362. return format_signal(sig);
  363. }
  364. static char * print_noise(const struct iwinfo_ops *iw, const char *ifname)
  365. {
  366. int noise;
  367. if (iw->noise(ifname, &noise))
  368. noise = 0;
  369. return format_noise(noise);
  370. }
  371. static char * print_rate(const struct iwinfo_ops *iw, const char *ifname)
  372. {
  373. int rate;
  374. if (iw->bitrate(ifname, &rate))
  375. rate = -1;
  376. return format_rate(rate);
  377. }
  378. static char * print_encryption(const struct iwinfo_ops *iw, const char *ifname)
  379. {
  380. struct iwinfo_crypto_entry c = { 0 };
  381. if (iw->encryption(ifname, (char *)&c))
  382. return format_encryption(NULL);
  383. return format_encryption(&c);
  384. }
  385. static char * print_hwmodes(const struct iwinfo_ops *iw, const char *ifname)
  386. {
  387. int modes;
  388. if (iw->hwmodelist(ifname, &modes))
  389. modes = -1;
  390. return format_hwmodes(modes);
  391. }
  392. static char * print_mbssid_supp(const struct iwinfo_ops *iw, const char *ifname)
  393. {
  394. int supp;
  395. static char buf[4];
  396. if (iw->mbssid_support(ifname, &supp))
  397. snprintf(buf, sizeof(buf), "no");
  398. else
  399. snprintf(buf, sizeof(buf), "%s", supp ? "yes" : "no");
  400. return buf;
  401. }
  402. static void print_info(const struct iwinfo_ops *iw, const char *ifname)
  403. {
  404. printf("%-9s ESSID: %s\n",
  405. ifname,
  406. print_ssid(iw, ifname));
  407. printf(" Access Point: %s\n",
  408. print_bssid(iw, ifname));
  409. printf(" Mode: %s Channel: %s (%s)\n",
  410. print_mode(iw, ifname),
  411. print_channel(iw, ifname),
  412. print_frequency(iw, ifname));
  413. printf(" Tx-Power: %s Link Quality: %s/%s\n",
  414. print_txpower(iw, ifname),
  415. print_quality(iw, ifname),
  416. print_quality_max(iw, ifname));
  417. printf(" Signal: %s Noise: %s\n",
  418. print_signal(iw, ifname),
  419. print_noise(iw, ifname));
  420. printf(" Bit Rate: %s\n",
  421. print_rate(iw, ifname));
  422. printf(" Encryption: %s\n",
  423. print_encryption(iw, ifname));
  424. printf(" Type: %s HW Mode(s): %s\n",
  425. print_type(iw, ifname),
  426. print_hwmodes(iw, ifname));
  427. printf(" Hardware: %s [%s]\n",
  428. print_hardware_id(iw, ifname),
  429. print_hardware_name(iw, ifname));
  430. printf(" TX power offset: %s\n",
  431. print_txpower_offset(iw, ifname));
  432. printf(" Frequency offset: %s\n",
  433. print_frequency_offset(iw, ifname));
  434. printf(" Supports VAPs: %s\n",
  435. print_mbssid_supp(iw, ifname));
  436. }
  437. static void print_scanlist(const struct iwinfo_ops *iw, const char *ifname)
  438. {
  439. int i, x, len;
  440. char buf[IWINFO_BUFSIZE];
  441. struct iwinfo_scanlist_entry *e;
  442. if (iw->scanlist(ifname, buf, &len))
  443. {
  444. printf("Scanning not possible\n\n");
  445. return;
  446. }
  447. else if (len <= 0)
  448. {
  449. printf("No scan results\n\n");
  450. return;
  451. }
  452. for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_scanlist_entry), x++)
  453. {
  454. e = (struct iwinfo_scanlist_entry *) &buf[i];
  455. printf("Cell %02d - Address: %s\n",
  456. x,
  457. format_bssid(e->mac));
  458. printf(" ESSID: %s\n",
  459. format_ssid(e->ssid));
  460. printf(" Mode: %s Channel: %s\n",
  461. IWINFO_OPMODE_NAMES[e->mode],
  462. format_channel(e->channel));
  463. printf(" Signal: %s Quality: %s/%s\n",
  464. format_signal(e->signal - 0x100),
  465. format_quality(e->quality),
  466. format_quality_max(e->quality_max));
  467. printf(" Encryption: %s\n\n",
  468. format_encryption(&e->crypto));
  469. }
  470. }
  471. static void print_txpwrlist(const struct iwinfo_ops *iw, const char *ifname)
  472. {
  473. int len, pwr, off, i;
  474. char buf[IWINFO_BUFSIZE];
  475. struct iwinfo_txpwrlist_entry *e;
  476. if (iw->txpwrlist(ifname, buf, &len) || len <= 0)
  477. {
  478. printf("No TX power information available\n");
  479. return;
  480. }
  481. if (iw->txpower(ifname, &pwr))
  482. pwr = -1;
  483. if (iw->txpower_offset(ifname, &off))
  484. off = 0;
  485. for (i = 0; i < len; i += sizeof(struct iwinfo_txpwrlist_entry))
  486. {
  487. e = (struct iwinfo_txpwrlist_entry *) &buf[i];
  488. printf("%s%3d dBm (%4d mW)\n",
  489. (pwr == e->dbm) ? "*" : " ",
  490. e->dbm + off,
  491. iwinfo_dbm2mw(e->dbm + off));
  492. }
  493. }
  494. static void print_freqlist(const struct iwinfo_ops *iw, const char *ifname)
  495. {
  496. int i, len, ch;
  497. char buf[IWINFO_BUFSIZE];
  498. struct iwinfo_freqlist_entry *e;
  499. if (iw->freqlist(ifname, buf, &len) || len <= 0)
  500. {
  501. printf("No frequency information available\n");
  502. return;
  503. }
  504. if (iw->channel(ifname, &ch))
  505. ch = -1;
  506. for (i = 0; i < len; i += sizeof(struct iwinfo_freqlist_entry))
  507. {
  508. e = (struct iwinfo_freqlist_entry *) &buf[i];
  509. printf("%s %s (Channel %s)%s\n",
  510. (ch == e->channel) ? "*" : " ",
  511. format_frequency(e->mhz),
  512. format_channel(e->channel),
  513. e->restricted ? " [restricted]" : "");
  514. }
  515. }
  516. static void print_assoclist(const struct iwinfo_ops *iw, const char *ifname)
  517. {
  518. int i, len;
  519. char buf[IWINFO_BUFSIZE];
  520. struct iwinfo_assoclist_entry *e;
  521. if (iw->assoclist(ifname, buf, &len))
  522. {
  523. printf("No information available\n");
  524. return;
  525. }
  526. else if (len <= 0)
  527. {
  528. printf("No station connected\n");
  529. return;
  530. }
  531. for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry))
  532. {
  533. e = (struct iwinfo_assoclist_entry *) &buf[i];
  534. printf("%s %s / %s (SNR %d) %d ms ago\n",
  535. format_bssid(e->mac),
  536. format_signal(e->signal),
  537. format_noise(e->noise),
  538. (e->signal - e->noise),
  539. e->inactive);
  540. printf(" RX: %-38s %8d Pkts.\n",
  541. format_assocrate(&e->rx_rate),
  542. e->rx_packets
  543. );
  544. printf(" TX: %-38s %8d Pkts.\n\n",
  545. format_assocrate(&e->tx_rate),
  546. e->tx_packets
  547. );
  548. }
  549. }
  550. static char * lookup_country(char *buf, int len, int iso3166)
  551. {
  552. int i;
  553. struct iwinfo_country_entry *c;
  554. for (i = 0; i < len; i += sizeof(struct iwinfo_country_entry))
  555. {
  556. c = (struct iwinfo_country_entry *) &buf[i];
  557. if (c->iso3166 == iso3166)
  558. return c->ccode;
  559. }
  560. return NULL;
  561. }
  562. static void print_countrylist(const struct iwinfo_ops *iw, const char *ifname)
  563. {
  564. int len;
  565. char buf[IWINFO_BUFSIZE];
  566. char *ccode;
  567. char curcode[3];
  568. const struct iwinfo_iso3166_label *l;
  569. if (iw->countrylist(ifname, buf, &len))
  570. {
  571. printf("No country code information available\n");
  572. return;
  573. }
  574. if (iw->country(ifname, curcode))
  575. memset(curcode, 0, sizeof(curcode));
  576. for (l = IWINFO_ISO3166_NAMES; l->iso3166; l++)
  577. {
  578. if ((ccode = lookup_country(buf, len, l->iso3166)) != NULL)
  579. {
  580. printf("%s %4s %c%c\n",
  581. strncmp(ccode, curcode, 2) ? " " : "*",
  582. ccode, (l->iso3166 / 256), (l->iso3166 % 256));
  583. }
  584. }
  585. }
  586. int main(int argc, char **argv)
  587. {
  588. int i;
  589. char *p;
  590. const struct iwinfo_ops *iw;
  591. glob_t globbuf;
  592. if (argc > 1 && argc < 3)
  593. {
  594. fprintf(stderr,
  595. "Usage:\n"
  596. " iwinfo <device> info\n"
  597. " iwinfo <device> scan\n"
  598. " iwinfo <device> txpowerlist\n"
  599. " iwinfo <device> freqlist\n"
  600. " iwinfo <device> assoclist\n"
  601. " iwinfo <device> countrylist\n"
  602. );
  603. return 1;
  604. }
  605. if (argc == 1)
  606. {
  607. glob("/sys/class/net/*", 0, NULL, &globbuf);
  608. for (i = 0; i < globbuf.gl_pathc; i++)
  609. {
  610. p = strrchr(globbuf.gl_pathv[i], '/');
  611. if (!p)
  612. continue;
  613. iw = iwinfo_backend(++p);
  614. if (!iw)
  615. continue;
  616. print_info(iw, p);
  617. printf("\n");
  618. }
  619. globfree(&globbuf);
  620. return 0;
  621. }
  622. iw = iwinfo_backend(argv[1]);
  623. if (!iw)
  624. {
  625. fprintf(stderr, "No such wireless device: %s\n", argv[1]);
  626. return 1;
  627. }
  628. for (i = 2; i < argc; i++)
  629. {
  630. switch(argv[i][0])
  631. {
  632. case 'i':
  633. print_info(iw, argv[1]);
  634. break;
  635. case 's':
  636. print_scanlist(iw, argv[1]);
  637. break;
  638. case 't':
  639. print_txpwrlist(iw, argv[1]);
  640. break;
  641. case 'f':
  642. print_freqlist(iw, argv[1]);
  643. break;
  644. case 'a':
  645. print_assoclist(iw, argv[1]);
  646. break;
  647. case 'c':
  648. print_countrylist(iw, argv[1]);
  649. break;
  650. default:
  651. fprintf(stderr, "Unknown command: %s\n", argv[i]);
  652. return 1;
  653. }
  654. }
  655. iwinfo_finish();
  656. return 0;
  657. }