hostap_proc.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /* /proc routines for Host AP driver */
  2. #include <linux/types.h>
  3. #include <linux/proc_fs.h>
  4. #include <linux/export.h>
  5. #include <net/lib80211.h>
  6. #include "hostap_wlan.h"
  7. #include "hostap.h"
  8. #define PROC_LIMIT (PAGE_SIZE - 80)
  9. #ifndef PRISM2_NO_PROCFS_DEBUG
  10. static int prism2_debug_proc_read(char *page, char **start, off_t off,
  11. int count, int *eof, void *data)
  12. {
  13. char *p = page;
  14. local_info_t *local = (local_info_t *) data;
  15. int i;
  16. if (off != 0) {
  17. *eof = 1;
  18. return 0;
  19. }
  20. p += sprintf(p, "next_txfid=%d next_alloc=%d\n",
  21. local->next_txfid, local->next_alloc);
  22. for (i = 0; i < PRISM2_TXFID_COUNT; i++)
  23. p += sprintf(p, "FID: tx=%04X intransmit=%04X\n",
  24. local->txfid[i], local->intransmitfid[i]);
  25. p += sprintf(p, "FW TX rate control: %d\n", local->fw_tx_rate_control);
  26. p += sprintf(p, "beacon_int=%d\n", local->beacon_int);
  27. p += sprintf(p, "dtim_period=%d\n", local->dtim_period);
  28. p += sprintf(p, "wds_max_connections=%d\n",
  29. local->wds_max_connections);
  30. p += sprintf(p, "dev_enabled=%d\n", local->dev_enabled);
  31. p += sprintf(p, "sw_tick_stuck=%d\n", local->sw_tick_stuck);
  32. for (i = 0; i < WEP_KEYS; i++) {
  33. if (local->crypt_info.crypt[i] &&
  34. local->crypt_info.crypt[i]->ops) {
  35. p += sprintf(p, "crypt[%d]=%s\n", i,
  36. local->crypt_info.crypt[i]->ops->name);
  37. }
  38. }
  39. p += sprintf(p, "pri_only=%d\n", local->pri_only);
  40. p += sprintf(p, "pci=%d\n", local->func->hw_type == HOSTAP_HW_PCI);
  41. p += sprintf(p, "sram_type=%d\n", local->sram_type);
  42. p += sprintf(p, "no_pri=%d\n", local->no_pri);
  43. return (p - page);
  44. }
  45. #endif /* PRISM2_NO_PROCFS_DEBUG */
  46. static int prism2_stats_proc_read(char *page, char **start, off_t off,
  47. int count, int *eof, void *data)
  48. {
  49. char *p = page;
  50. local_info_t *local = (local_info_t *) data;
  51. struct comm_tallies_sums *sums = &local->comm_tallies;
  52. if (off != 0) {
  53. *eof = 1;
  54. return 0;
  55. }
  56. p += sprintf(p, "TxUnicastFrames=%u\n", sums->tx_unicast_frames);
  57. p += sprintf(p, "TxMulticastframes=%u\n", sums->tx_multicast_frames);
  58. p += sprintf(p, "TxFragments=%u\n", sums->tx_fragments);
  59. p += sprintf(p, "TxUnicastOctets=%u\n", sums->tx_unicast_octets);
  60. p += sprintf(p, "TxMulticastOctets=%u\n", sums->tx_multicast_octets);
  61. p += sprintf(p, "TxDeferredTransmissions=%u\n",
  62. sums->tx_deferred_transmissions);
  63. p += sprintf(p, "TxSingleRetryFrames=%u\n",
  64. sums->tx_single_retry_frames);
  65. p += sprintf(p, "TxMultipleRetryFrames=%u\n",
  66. sums->tx_multiple_retry_frames);
  67. p += sprintf(p, "TxRetryLimitExceeded=%u\n",
  68. sums->tx_retry_limit_exceeded);
  69. p += sprintf(p, "TxDiscards=%u\n", sums->tx_discards);
  70. p += sprintf(p, "RxUnicastFrames=%u\n", sums->rx_unicast_frames);
  71. p += sprintf(p, "RxMulticastFrames=%u\n", sums->rx_multicast_frames);
  72. p += sprintf(p, "RxFragments=%u\n", sums->rx_fragments);
  73. p += sprintf(p, "RxUnicastOctets=%u\n", sums->rx_unicast_octets);
  74. p += sprintf(p, "RxMulticastOctets=%u\n", sums->rx_multicast_octets);
  75. p += sprintf(p, "RxFCSErrors=%u\n", sums->rx_fcs_errors);
  76. p += sprintf(p, "RxDiscardsNoBuffer=%u\n",
  77. sums->rx_discards_no_buffer);
  78. p += sprintf(p, "TxDiscardsWrongSA=%u\n", sums->tx_discards_wrong_sa);
  79. p += sprintf(p, "RxDiscardsWEPUndecryptable=%u\n",
  80. sums->rx_discards_wep_undecryptable);
  81. p += sprintf(p, "RxMessageInMsgFragments=%u\n",
  82. sums->rx_message_in_msg_fragments);
  83. p += sprintf(p, "RxMessageInBadMsgFragments=%u\n",
  84. sums->rx_message_in_bad_msg_fragments);
  85. /* FIX: this may grow too long for one page(?) */
  86. return (p - page);
  87. }
  88. static int prism2_wds_proc_read(char *page, char **start, off_t off,
  89. int count, int *eof, void *data)
  90. {
  91. char *p = page;
  92. local_info_t *local = (local_info_t *) data;
  93. struct list_head *ptr;
  94. struct hostap_interface *iface;
  95. if (off > PROC_LIMIT) {
  96. *eof = 1;
  97. return 0;
  98. }
  99. read_lock_bh(&local->iface_lock);
  100. list_for_each(ptr, &local->hostap_interfaces) {
  101. iface = list_entry(ptr, struct hostap_interface, list);
  102. if (iface->type != HOSTAP_INTERFACE_WDS)
  103. continue;
  104. p += sprintf(p, "%s\t%pM\n",
  105. iface->dev->name,
  106. iface->u.wds.remote_addr);
  107. if ((p - page) > PROC_LIMIT) {
  108. printk(KERN_DEBUG "%s: wds proc did not fit\n",
  109. local->dev->name);
  110. break;
  111. }
  112. }
  113. read_unlock_bh(&local->iface_lock);
  114. if ((p - page) <= off) {
  115. *eof = 1;
  116. return 0;
  117. }
  118. *start = page + off;
  119. return (p - page - off);
  120. }
  121. static int prism2_bss_list_proc_read(char *page, char **start, off_t off,
  122. int count, int *eof, void *data)
  123. {
  124. char *p = page;
  125. local_info_t *local = (local_info_t *) data;
  126. struct list_head *ptr;
  127. struct hostap_bss_info *bss;
  128. int i;
  129. if (off > PROC_LIMIT) {
  130. *eof = 1;
  131. return 0;
  132. }
  133. p += sprintf(p, "#BSSID\tlast_update\tcount\tcapab_info\tSSID(txt)\t"
  134. "SSID(hex)\tWPA IE\n");
  135. spin_lock_bh(&local->lock);
  136. list_for_each(ptr, &local->bss_list) {
  137. bss = list_entry(ptr, struct hostap_bss_info, list);
  138. p += sprintf(p, "%pM\t%lu\t%u\t0x%x\t",
  139. bss->bssid, bss->last_update,
  140. bss->count, bss->capab_info);
  141. for (i = 0; i < bss->ssid_len; i++) {
  142. p += sprintf(p, "%c",
  143. bss->ssid[i] >= 32 && bss->ssid[i] < 127 ?
  144. bss->ssid[i] : '_');
  145. }
  146. p += sprintf(p, "\t");
  147. for (i = 0; i < bss->ssid_len; i++) {
  148. p += sprintf(p, "%02x", bss->ssid[i]);
  149. }
  150. p += sprintf(p, "\t");
  151. for (i = 0; i < bss->wpa_ie_len; i++) {
  152. p += sprintf(p, "%02x", bss->wpa_ie[i]);
  153. }
  154. p += sprintf(p, "\n");
  155. if ((p - page) > PROC_LIMIT) {
  156. printk(KERN_DEBUG "%s: BSS proc did not fit\n",
  157. local->dev->name);
  158. break;
  159. }
  160. }
  161. spin_unlock_bh(&local->lock);
  162. if ((p - page) <= off) {
  163. *eof = 1;
  164. return 0;
  165. }
  166. *start = page + off;
  167. return (p - page - off);
  168. }
  169. static int prism2_crypt_proc_read(char *page, char **start, off_t off,
  170. int count, int *eof, void *data)
  171. {
  172. char *p = page;
  173. local_info_t *local = (local_info_t *) data;
  174. int i;
  175. if (off > PROC_LIMIT) {
  176. *eof = 1;
  177. return 0;
  178. }
  179. p += sprintf(p, "tx_keyidx=%d\n", local->crypt_info.tx_keyidx);
  180. for (i = 0; i < WEP_KEYS; i++) {
  181. if (local->crypt_info.crypt[i] &&
  182. local->crypt_info.crypt[i]->ops &&
  183. local->crypt_info.crypt[i]->ops->print_stats) {
  184. p = local->crypt_info.crypt[i]->ops->print_stats(
  185. p, local->crypt_info.crypt[i]->priv);
  186. }
  187. }
  188. if ((p - page) <= off) {
  189. *eof = 1;
  190. return 0;
  191. }
  192. *start = page + off;
  193. return (p - page - off);
  194. }
  195. static int prism2_pda_proc_read(char *page, char **start, off_t off,
  196. int count, int *eof, void *data)
  197. {
  198. local_info_t *local = (local_info_t *) data;
  199. if (local->pda == NULL || off >= PRISM2_PDA_SIZE) {
  200. *eof = 1;
  201. return 0;
  202. }
  203. if (off + count > PRISM2_PDA_SIZE)
  204. count = PRISM2_PDA_SIZE - off;
  205. memcpy(page, local->pda + off, count);
  206. return count;
  207. }
  208. static int prism2_aux_dump_proc_read(char *page, char **start, off_t off,
  209. int count, int *eof, void *data)
  210. {
  211. local_info_t *local = (local_info_t *) data;
  212. if (local->func->read_aux == NULL) {
  213. *eof = 1;
  214. return 0;
  215. }
  216. if (local->func->read_aux(local->dev, off, count, page)) {
  217. *eof = 1;
  218. return 0;
  219. }
  220. *start = page;
  221. return count;
  222. }
  223. #ifdef PRISM2_IO_DEBUG
  224. static int prism2_io_debug_proc_read(char *page, char **start, off_t off,
  225. int count, int *eof, void *data)
  226. {
  227. local_info_t *local = (local_info_t *) data;
  228. int head = local->io_debug_head;
  229. int start_bytes, left, copy, copied;
  230. if (off + count > PRISM2_IO_DEBUG_SIZE * 4) {
  231. *eof = 1;
  232. if (off >= PRISM2_IO_DEBUG_SIZE * 4)
  233. return 0;
  234. count = PRISM2_IO_DEBUG_SIZE * 4 - off;
  235. }
  236. copied = 0;
  237. start_bytes = (PRISM2_IO_DEBUG_SIZE - head) * 4;
  238. left = count;
  239. if (off < start_bytes) {
  240. copy = start_bytes - off;
  241. if (copy > count)
  242. copy = count;
  243. memcpy(page, ((u8 *) &local->io_debug[head]) + off, copy);
  244. left -= copy;
  245. if (left > 0)
  246. memcpy(&page[copy], local->io_debug, left);
  247. } else {
  248. memcpy(page, ((u8 *) local->io_debug) + (off - start_bytes),
  249. left);
  250. }
  251. *start = page;
  252. return count;
  253. }
  254. #endif /* PRISM2_IO_DEBUG */
  255. #ifndef PRISM2_NO_STATION_MODES
  256. static int prism2_scan_results_proc_read(char *page, char **start, off_t off,
  257. int count, int *eof, void *data)
  258. {
  259. char *p = page;
  260. local_info_t *local = (local_info_t *) data;
  261. int entry, i, len, total = 0;
  262. struct hfa384x_hostscan_result *scanres;
  263. u8 *pos;
  264. p += sprintf(p, "CHID ANL SL BcnInt Capab Rate BSSID ATIM SupRates "
  265. "SSID\n");
  266. spin_lock_bh(&local->lock);
  267. for (entry = 0; entry < local->last_scan_results_count; entry++) {
  268. scanres = &local->last_scan_results[entry];
  269. if (total + (p - page) <= off) {
  270. total += p - page;
  271. p = page;
  272. }
  273. if (total + (p - page) > off + count)
  274. break;
  275. if ((p - page) > (PAGE_SIZE - 200))
  276. break;
  277. p += sprintf(p, "%d %d %d %d 0x%02x %d %pM %d ",
  278. le16_to_cpu(scanres->chid),
  279. (s16) le16_to_cpu(scanres->anl),
  280. (s16) le16_to_cpu(scanres->sl),
  281. le16_to_cpu(scanres->beacon_interval),
  282. le16_to_cpu(scanres->capability),
  283. le16_to_cpu(scanres->rate),
  284. scanres->bssid,
  285. le16_to_cpu(scanres->atim));
  286. pos = scanres->sup_rates;
  287. for (i = 0; i < sizeof(scanres->sup_rates); i++) {
  288. if (pos[i] == 0)
  289. break;
  290. p += sprintf(p, "<%02x>", pos[i]);
  291. }
  292. p += sprintf(p, " ");
  293. pos = scanres->ssid;
  294. len = le16_to_cpu(scanres->ssid_len);
  295. if (len > 32)
  296. len = 32;
  297. for (i = 0; i < len; i++) {
  298. unsigned char c = pos[i];
  299. if (c >= 32 && c < 127)
  300. p += sprintf(p, "%c", c);
  301. else
  302. p += sprintf(p, "<%02x>", c);
  303. }
  304. p += sprintf(p, "\n");
  305. }
  306. spin_unlock_bh(&local->lock);
  307. total += (p - page);
  308. if (total >= off + count)
  309. *eof = 1;
  310. if (total < off) {
  311. *eof = 1;
  312. return 0;
  313. }
  314. len = total - off;
  315. if (len > (p - page))
  316. len = p - page;
  317. *start = p - len;
  318. if (len > count)
  319. len = count;
  320. return len;
  321. }
  322. #endif /* PRISM2_NO_STATION_MODES */
  323. void hostap_init_proc(local_info_t *local)
  324. {
  325. local->proc = NULL;
  326. if (hostap_proc == NULL) {
  327. printk(KERN_WARNING "%s: hostap proc directory not created\n",
  328. local->dev->name);
  329. return;
  330. }
  331. local->proc = proc_mkdir(local->ddev->name, hostap_proc);
  332. if (local->proc == NULL) {
  333. printk(KERN_INFO "/proc/net/hostap/%s creation failed\n",
  334. local->ddev->name);
  335. return;
  336. }
  337. #ifndef PRISM2_NO_PROCFS_DEBUG
  338. create_proc_read_entry("debug", 0, local->proc,
  339. prism2_debug_proc_read, local);
  340. #endif /* PRISM2_NO_PROCFS_DEBUG */
  341. create_proc_read_entry("stats", 0, local->proc,
  342. prism2_stats_proc_read, local);
  343. create_proc_read_entry("wds", 0, local->proc,
  344. prism2_wds_proc_read, local);
  345. create_proc_read_entry("pda", 0, local->proc,
  346. prism2_pda_proc_read, local);
  347. create_proc_read_entry("aux_dump", 0, local->proc,
  348. prism2_aux_dump_proc_read, local);
  349. create_proc_read_entry("bss_list", 0, local->proc,
  350. prism2_bss_list_proc_read, local);
  351. create_proc_read_entry("crypt", 0, local->proc,
  352. prism2_crypt_proc_read, local);
  353. #ifdef PRISM2_IO_DEBUG
  354. create_proc_read_entry("io_debug", 0, local->proc,
  355. prism2_io_debug_proc_read, local);
  356. #endif /* PRISM2_IO_DEBUG */
  357. #ifndef PRISM2_NO_STATION_MODES
  358. create_proc_read_entry("scan_results", 0, local->proc,
  359. prism2_scan_results_proc_read, local);
  360. #endif /* PRISM2_NO_STATION_MODES */
  361. }
  362. void hostap_remove_proc(local_info_t *local)
  363. {
  364. if (local->proc != NULL) {
  365. #ifndef PRISM2_NO_STATION_MODES
  366. remove_proc_entry("scan_results", local->proc);
  367. #endif /* PRISM2_NO_STATION_MODES */
  368. #ifdef PRISM2_IO_DEBUG
  369. remove_proc_entry("io_debug", local->proc);
  370. #endif /* PRISM2_IO_DEBUG */
  371. remove_proc_entry("pda", local->proc);
  372. remove_proc_entry("aux_dump", local->proc);
  373. remove_proc_entry("wds", local->proc);
  374. remove_proc_entry("stats", local->proc);
  375. remove_proc_entry("bss_list", local->proc);
  376. remove_proc_entry("crypt", local->proc);
  377. #ifndef PRISM2_NO_PROCFS_DEBUG
  378. remove_proc_entry("debug", local->proc);
  379. #endif /* PRISM2_NO_PROCFS_DEBUG */
  380. if (hostap_proc != NULL)
  381. remove_proc_entry(local->proc->name, hostap_proc);
  382. }
  383. }
  384. EXPORT_SYMBOL(hostap_init_proc);
  385. EXPORT_SYMBOL(hostap_remove_proc);