hostap_proc.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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_show(struct seq_file *m, void *v)
  11. {
  12. local_info_t *local = m->private;
  13. int i;
  14. seq_printf(m, "next_txfid=%d next_alloc=%d\n",
  15. local->next_txfid, local->next_alloc);
  16. for (i = 0; i < PRISM2_TXFID_COUNT; i++)
  17. seq_printf(m, "FID: tx=%04X intransmit=%04X\n",
  18. local->txfid[i], local->intransmitfid[i]);
  19. seq_printf(m, "FW TX rate control: %d\n", local->fw_tx_rate_control);
  20. seq_printf(m, "beacon_int=%d\n", local->beacon_int);
  21. seq_printf(m, "dtim_period=%d\n", local->dtim_period);
  22. seq_printf(m, "wds_max_connections=%d\n", local->wds_max_connections);
  23. seq_printf(m, "dev_enabled=%d\n", local->dev_enabled);
  24. seq_printf(m, "sw_tick_stuck=%d\n", local->sw_tick_stuck);
  25. for (i = 0; i < WEP_KEYS; i++) {
  26. if (local->crypt_info.crypt[i] &&
  27. local->crypt_info.crypt[i]->ops) {
  28. seq_printf(m, "crypt[%d]=%s\n", i,
  29. local->crypt_info.crypt[i]->ops->name);
  30. }
  31. }
  32. seq_printf(m, "pri_only=%d\n", local->pri_only);
  33. seq_printf(m, "pci=%d\n", local->func->hw_type == HOSTAP_HW_PCI);
  34. seq_printf(m, "sram_type=%d\n", local->sram_type);
  35. seq_printf(m, "no_pri=%d\n", local->no_pri);
  36. return 0;
  37. }
  38. static int prism2_debug_proc_open(struct inode *inode, struct file *file)
  39. {
  40. return single_open(file, prism2_debug_proc_show, PDE_DATA(inode));
  41. }
  42. static const struct file_operations prism2_debug_proc_fops = {
  43. .open = prism2_debug_proc_open,
  44. .read = seq_read,
  45. .llseek = seq_lseek,
  46. .release = single_release,
  47. };
  48. #endif /* PRISM2_NO_PROCFS_DEBUG */
  49. static int prism2_stats_proc_show(struct seq_file *m, void *v)
  50. {
  51. local_info_t *local = m->private;
  52. struct comm_tallies_sums *sums = &local->comm_tallies;
  53. seq_printf(m, "TxUnicastFrames=%u\n", sums->tx_unicast_frames);
  54. seq_printf(m, "TxMulticastframes=%u\n", sums->tx_multicast_frames);
  55. seq_printf(m, "TxFragments=%u\n", sums->tx_fragments);
  56. seq_printf(m, "TxUnicastOctets=%u\n", sums->tx_unicast_octets);
  57. seq_printf(m, "TxMulticastOctets=%u\n", sums->tx_multicast_octets);
  58. seq_printf(m, "TxDeferredTransmissions=%u\n",
  59. sums->tx_deferred_transmissions);
  60. seq_printf(m, "TxSingleRetryFrames=%u\n", sums->tx_single_retry_frames);
  61. seq_printf(m, "TxMultipleRetryFrames=%u\n",
  62. sums->tx_multiple_retry_frames);
  63. seq_printf(m, "TxRetryLimitExceeded=%u\n",
  64. sums->tx_retry_limit_exceeded);
  65. seq_printf(m, "TxDiscards=%u\n", sums->tx_discards);
  66. seq_printf(m, "RxUnicastFrames=%u\n", sums->rx_unicast_frames);
  67. seq_printf(m, "RxMulticastFrames=%u\n", sums->rx_multicast_frames);
  68. seq_printf(m, "RxFragments=%u\n", sums->rx_fragments);
  69. seq_printf(m, "RxUnicastOctets=%u\n", sums->rx_unicast_octets);
  70. seq_printf(m, "RxMulticastOctets=%u\n", sums->rx_multicast_octets);
  71. seq_printf(m, "RxFCSErrors=%u\n", sums->rx_fcs_errors);
  72. seq_printf(m, "RxDiscardsNoBuffer=%u\n", sums->rx_discards_no_buffer);
  73. seq_printf(m, "TxDiscardsWrongSA=%u\n", sums->tx_discards_wrong_sa);
  74. seq_printf(m, "RxDiscardsWEPUndecryptable=%u\n",
  75. sums->rx_discards_wep_undecryptable);
  76. seq_printf(m, "RxMessageInMsgFragments=%u\n",
  77. sums->rx_message_in_msg_fragments);
  78. seq_printf(m, "RxMessageInBadMsgFragments=%u\n",
  79. sums->rx_message_in_bad_msg_fragments);
  80. /* FIX: this may grow too long for one page(?) */
  81. return 0;
  82. }
  83. static int prism2_stats_proc_open(struct inode *inode, struct file *file)
  84. {
  85. return single_open(file, prism2_stats_proc_show, PDE_DATA(inode));
  86. }
  87. static const struct file_operations prism2_stats_proc_fops = {
  88. .open = prism2_stats_proc_open,
  89. .read = seq_read,
  90. .llseek = seq_lseek,
  91. .release = single_release,
  92. };
  93. static int prism2_wds_proc_show(struct seq_file *m, void *v)
  94. {
  95. struct list_head *ptr = v;
  96. struct hostap_interface *iface;
  97. iface = list_entry(ptr, struct hostap_interface, list);
  98. if (iface->type == HOSTAP_INTERFACE_WDS)
  99. seq_printf(m, "%s\t%pM\n",
  100. iface->dev->name, iface->u.wds.remote_addr);
  101. return 0;
  102. }
  103. static void *prism2_wds_proc_start(struct seq_file *m, loff_t *_pos)
  104. {
  105. local_info_t *local = m->private;
  106. read_lock_bh(&local->iface_lock);
  107. return seq_list_start(&local->hostap_interfaces, *_pos);
  108. }
  109. static void *prism2_wds_proc_next(struct seq_file *m, void *v, loff_t *_pos)
  110. {
  111. local_info_t *local = m->private;
  112. return seq_list_next(v, &local->hostap_interfaces, _pos);
  113. }
  114. static void prism2_wds_proc_stop(struct seq_file *m, void *v)
  115. {
  116. local_info_t *local = m->private;
  117. read_unlock_bh(&local->iface_lock);
  118. }
  119. static const struct seq_operations prism2_wds_proc_seqops = {
  120. .start = prism2_wds_proc_start,
  121. .next = prism2_wds_proc_next,
  122. .stop = prism2_wds_proc_stop,
  123. .show = prism2_wds_proc_show,
  124. };
  125. static int prism2_wds_proc_open(struct inode *inode, struct file *file)
  126. {
  127. int ret = seq_open(file, &prism2_wds_proc_seqops);
  128. if (ret == 0) {
  129. struct seq_file *m = file->private_data;
  130. m->private = PDE_DATA(inode);
  131. }
  132. return ret;
  133. }
  134. static const struct file_operations prism2_wds_proc_fops = {
  135. .open = prism2_wds_proc_open,
  136. .read = seq_read,
  137. .llseek = seq_lseek,
  138. .release = seq_release,
  139. };
  140. static int prism2_bss_list_proc_show(struct seq_file *m, void *v)
  141. {
  142. local_info_t *local = m->private;
  143. struct list_head *ptr = v;
  144. struct hostap_bss_info *bss;
  145. if (ptr == &local->bss_list) {
  146. seq_printf(m, "#BSSID\tlast_update\tcount\tcapab_info\tSSID(txt)\t"
  147. "SSID(hex)\tWPA IE\n");
  148. return 0;
  149. }
  150. bss = list_entry(ptr, struct hostap_bss_info, list);
  151. seq_printf(m, "%pM\t%lu\t%u\t0x%x\t",
  152. bss->bssid, bss->last_update,
  153. bss->count, bss->capab_info);
  154. seq_printf(m, "%*pE", (int)bss->ssid_len, bss->ssid);
  155. seq_putc(m, '\t');
  156. seq_printf(m, "%*phN", (int)bss->ssid_len, bss->ssid);
  157. seq_putc(m, '\t');
  158. seq_printf(m, "%*phN", (int)bss->wpa_ie_len, bss->wpa_ie);
  159. seq_putc(m, '\n');
  160. return 0;
  161. }
  162. static void *prism2_bss_list_proc_start(struct seq_file *m, loff_t *_pos)
  163. {
  164. local_info_t *local = m->private;
  165. spin_lock_bh(&local->lock);
  166. return seq_list_start_head(&local->bss_list, *_pos);
  167. }
  168. static void *prism2_bss_list_proc_next(struct seq_file *m, void *v, loff_t *_pos)
  169. {
  170. local_info_t *local = m->private;
  171. return seq_list_next(v, &local->bss_list, _pos);
  172. }
  173. static void prism2_bss_list_proc_stop(struct seq_file *m, void *v)
  174. {
  175. local_info_t *local = m->private;
  176. spin_unlock_bh(&local->lock);
  177. }
  178. static const struct seq_operations prism2_bss_list_proc_seqops = {
  179. .start = prism2_bss_list_proc_start,
  180. .next = prism2_bss_list_proc_next,
  181. .stop = prism2_bss_list_proc_stop,
  182. .show = prism2_bss_list_proc_show,
  183. };
  184. static int prism2_bss_list_proc_open(struct inode *inode, struct file *file)
  185. {
  186. int ret = seq_open(file, &prism2_bss_list_proc_seqops);
  187. if (ret == 0) {
  188. struct seq_file *m = file->private_data;
  189. m->private = PDE_DATA(inode);
  190. }
  191. return ret;
  192. }
  193. static const struct file_operations prism2_bss_list_proc_fops = {
  194. .open = prism2_bss_list_proc_open,
  195. .read = seq_read,
  196. .llseek = seq_lseek,
  197. .release = seq_release,
  198. };
  199. static int prism2_crypt_proc_show(struct seq_file *m, void *v)
  200. {
  201. local_info_t *local = m->private;
  202. int i;
  203. seq_printf(m, "tx_keyidx=%d\n", local->crypt_info.tx_keyidx);
  204. for (i = 0; i < WEP_KEYS; i++) {
  205. if (local->crypt_info.crypt[i] &&
  206. local->crypt_info.crypt[i]->ops &&
  207. local->crypt_info.crypt[i]->ops->print_stats) {
  208. local->crypt_info.crypt[i]->ops->print_stats(
  209. m, local->crypt_info.crypt[i]->priv);
  210. }
  211. }
  212. return 0;
  213. }
  214. static int prism2_crypt_proc_open(struct inode *inode, struct file *file)
  215. {
  216. return single_open(file, prism2_crypt_proc_show, PDE_DATA(inode));
  217. }
  218. static const struct file_operations prism2_crypt_proc_fops = {
  219. .open = prism2_crypt_proc_open,
  220. .read = seq_read,
  221. .llseek = seq_lseek,
  222. .release = single_release,
  223. };
  224. static ssize_t prism2_pda_proc_read(struct file *file, char __user *buf,
  225. size_t count, loff_t *_pos)
  226. {
  227. local_info_t *local = PDE_DATA(file_inode(file));
  228. size_t off;
  229. if (local->pda == NULL || *_pos >= PRISM2_PDA_SIZE)
  230. return 0;
  231. off = *_pos;
  232. if (count > PRISM2_PDA_SIZE - off)
  233. count = PRISM2_PDA_SIZE - off;
  234. if (copy_to_user(buf, local->pda + off, count) != 0)
  235. return -EFAULT;
  236. *_pos += count;
  237. return count;
  238. }
  239. static const struct file_operations prism2_pda_proc_fops = {
  240. .read = prism2_pda_proc_read,
  241. .llseek = generic_file_llseek,
  242. };
  243. static ssize_t prism2_aux_dump_proc_no_read(struct file *file, char __user *buf,
  244. size_t bufsize, loff_t *_pos)
  245. {
  246. return 0;
  247. }
  248. static const struct file_operations prism2_aux_dump_proc_fops = {
  249. .read = prism2_aux_dump_proc_no_read,
  250. };
  251. #ifdef PRISM2_IO_DEBUG
  252. static int prism2_io_debug_proc_read(char *page, char **start, off_t off,
  253. int count, int *eof, void *data)
  254. {
  255. local_info_t *local = (local_info_t *) data;
  256. int head = local->io_debug_head;
  257. int start_bytes, left, copy, copied;
  258. if (off + count > PRISM2_IO_DEBUG_SIZE * 4) {
  259. *eof = 1;
  260. if (off >= PRISM2_IO_DEBUG_SIZE * 4)
  261. return 0;
  262. count = PRISM2_IO_DEBUG_SIZE * 4 - off;
  263. }
  264. copied = 0;
  265. start_bytes = (PRISM2_IO_DEBUG_SIZE - head) * 4;
  266. left = count;
  267. if (off < start_bytes) {
  268. copy = start_bytes - off;
  269. if (copy > count)
  270. copy = count;
  271. memcpy(page, ((u8 *) &local->io_debug[head]) + off, copy);
  272. left -= copy;
  273. if (left > 0)
  274. memcpy(&page[copy], local->io_debug, left);
  275. } else {
  276. memcpy(page, ((u8 *) local->io_debug) + (off - start_bytes),
  277. left);
  278. }
  279. *start = page;
  280. return count;
  281. }
  282. #endif /* PRISM2_IO_DEBUG */
  283. #ifndef PRISM2_NO_STATION_MODES
  284. static int prism2_scan_results_proc_show(struct seq_file *m, void *v)
  285. {
  286. local_info_t *local = m->private;
  287. unsigned long entry;
  288. int i, len;
  289. struct hfa384x_hostscan_result *scanres;
  290. u8 *p;
  291. if (v == SEQ_START_TOKEN) {
  292. seq_printf(m,
  293. "CHID ANL SL BcnInt Capab Rate BSSID ATIM SupRates SSID\n");
  294. return 0;
  295. }
  296. entry = (unsigned long)v - 2;
  297. scanres = &local->last_scan_results[entry];
  298. seq_printf(m, "%d %d %d %d 0x%02x %d %pM %d ",
  299. le16_to_cpu(scanres->chid),
  300. (s16) le16_to_cpu(scanres->anl),
  301. (s16) le16_to_cpu(scanres->sl),
  302. le16_to_cpu(scanres->beacon_interval),
  303. le16_to_cpu(scanres->capability),
  304. le16_to_cpu(scanres->rate),
  305. scanres->bssid,
  306. le16_to_cpu(scanres->atim));
  307. p = scanres->sup_rates;
  308. for (i = 0; i < sizeof(scanres->sup_rates); i++) {
  309. if (p[i] == 0)
  310. break;
  311. seq_printf(m, "<%02x>", p[i]);
  312. }
  313. seq_putc(m, ' ');
  314. p = scanres->ssid;
  315. len = le16_to_cpu(scanres->ssid_len);
  316. if (len > 32)
  317. len = 32;
  318. for (i = 0; i < len; i++) {
  319. unsigned char c = p[i];
  320. if (c >= 32 && c < 127)
  321. seq_putc(m, c);
  322. else
  323. seq_printf(m, "<%02x>", c);
  324. }
  325. seq_putc(m, '\n');
  326. return 0;
  327. }
  328. static void *prism2_scan_results_proc_start(struct seq_file *m, loff_t *_pos)
  329. {
  330. local_info_t *local = m->private;
  331. spin_lock_bh(&local->lock);
  332. /* We have a header (pos 0) + N results to show (pos 1...N) */
  333. if (*_pos > local->last_scan_results_count)
  334. return NULL;
  335. return (void *)(unsigned long)(*_pos + 1); /* 0 would be EOF */
  336. }
  337. static void *prism2_scan_results_proc_next(struct seq_file *m, void *v, loff_t *_pos)
  338. {
  339. local_info_t *local = m->private;
  340. ++*_pos;
  341. if (*_pos > local->last_scan_results_count)
  342. return NULL;
  343. return (void *)(unsigned long)(*_pos + 1); /* 0 would be EOF */
  344. }
  345. static void prism2_scan_results_proc_stop(struct seq_file *m, void *v)
  346. {
  347. local_info_t *local = m->private;
  348. spin_unlock_bh(&local->lock);
  349. }
  350. static const struct seq_operations prism2_scan_results_proc_seqops = {
  351. .start = prism2_scan_results_proc_start,
  352. .next = prism2_scan_results_proc_next,
  353. .stop = prism2_scan_results_proc_stop,
  354. .show = prism2_scan_results_proc_show,
  355. };
  356. static int prism2_scan_results_proc_open(struct inode *inode, struct file *file)
  357. {
  358. int ret = seq_open(file, &prism2_scan_results_proc_seqops);
  359. if (ret == 0) {
  360. struct seq_file *m = file->private_data;
  361. m->private = PDE_DATA(inode);
  362. }
  363. return ret;
  364. }
  365. static const struct file_operations prism2_scan_results_proc_fops = {
  366. .open = prism2_scan_results_proc_open,
  367. .read = seq_read,
  368. .llseek = seq_lseek,
  369. .release = seq_release,
  370. };
  371. #endif /* PRISM2_NO_STATION_MODES */
  372. void hostap_init_proc(local_info_t *local)
  373. {
  374. local->proc = NULL;
  375. if (hostap_proc == NULL) {
  376. printk(KERN_WARNING "%s: hostap proc directory not created\n",
  377. local->dev->name);
  378. return;
  379. }
  380. local->proc = proc_mkdir(local->ddev->name, hostap_proc);
  381. if (local->proc == NULL) {
  382. printk(KERN_INFO "/proc/net/hostap/%s creation failed\n",
  383. local->ddev->name);
  384. return;
  385. }
  386. #ifndef PRISM2_NO_PROCFS_DEBUG
  387. proc_create_data("debug", 0, local->proc,
  388. &prism2_debug_proc_fops, local);
  389. #endif /* PRISM2_NO_PROCFS_DEBUG */
  390. proc_create_data("stats", 0, local->proc,
  391. &prism2_stats_proc_fops, local);
  392. proc_create_data("wds", 0, local->proc,
  393. &prism2_wds_proc_fops, local);
  394. proc_create_data("pda", 0, local->proc,
  395. &prism2_pda_proc_fops, local);
  396. proc_create_data("aux_dump", 0, local->proc,
  397. local->func->read_aux_fops ?: &prism2_aux_dump_proc_fops,
  398. local);
  399. proc_create_data("bss_list", 0, local->proc,
  400. &prism2_bss_list_proc_fops, local);
  401. proc_create_data("crypt", 0, local->proc,
  402. &prism2_crypt_proc_fops, local);
  403. #ifdef PRISM2_IO_DEBUG
  404. proc_create_data("io_debug", 0, local->proc,
  405. &prism2_io_debug_proc_fops, local);
  406. #endif /* PRISM2_IO_DEBUG */
  407. #ifndef PRISM2_NO_STATION_MODES
  408. proc_create_data("scan_results", 0, local->proc,
  409. &prism2_scan_results_proc_fops, local);
  410. #endif /* PRISM2_NO_STATION_MODES */
  411. }
  412. void hostap_remove_proc(local_info_t *local)
  413. {
  414. proc_remove(local->proc);
  415. }
  416. EXPORT_SYMBOL(hostap_init_proc);
  417. EXPORT_SYMBOL(hostap_remove_proc);