hostap_proc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. int i;
  146. if (ptr == &local->bss_list) {
  147. seq_printf(m, "#BSSID\tlast_update\tcount\tcapab_info\tSSID(txt)\t"
  148. "SSID(hex)\tWPA IE\n");
  149. return 0;
  150. }
  151. bss = list_entry(ptr, struct hostap_bss_info, list);
  152. seq_printf(m, "%pM\t%lu\t%u\t0x%x\t",
  153. bss->bssid, bss->last_update,
  154. bss->count, bss->capab_info);
  155. for (i = 0; i < bss->ssid_len; i++)
  156. seq_putc(m,bss->ssid[i] >= 32 && bss->ssid[i] < 127 ?
  157. bss->ssid[i] : '_');
  158. seq_putc(m, '\t');
  159. for (i = 0; i < bss->ssid_len; i++)
  160. seq_printf(m, "%02x", bss->ssid[i]);
  161. seq_putc(m, '\t');
  162. for (i = 0; i < bss->wpa_ie_len; i++)
  163. seq_printf(m, "%02x", bss->wpa_ie[i]);
  164. seq_putc(m, '\n');
  165. return 0;
  166. }
  167. static void *prism2_bss_list_proc_start(struct seq_file *m, loff_t *_pos)
  168. {
  169. local_info_t *local = m->private;
  170. spin_lock_bh(&local->lock);
  171. return seq_list_start_head(&local->bss_list, *_pos);
  172. }
  173. static void *prism2_bss_list_proc_next(struct seq_file *m, void *v, loff_t *_pos)
  174. {
  175. local_info_t *local = m->private;
  176. return seq_list_next(v, &local->bss_list, _pos);
  177. }
  178. static void prism2_bss_list_proc_stop(struct seq_file *m, void *v)
  179. {
  180. local_info_t *local = m->private;
  181. spin_unlock_bh(&local->lock);
  182. }
  183. static const struct seq_operations prism2_bss_list_proc_seqops = {
  184. .start = prism2_bss_list_proc_start,
  185. .next = prism2_bss_list_proc_next,
  186. .stop = prism2_bss_list_proc_stop,
  187. .show = prism2_bss_list_proc_show,
  188. };
  189. static int prism2_bss_list_proc_open(struct inode *inode, struct file *file)
  190. {
  191. int ret = seq_open(file, &prism2_bss_list_proc_seqops);
  192. if (ret == 0) {
  193. struct seq_file *m = file->private_data;
  194. m->private = PDE_DATA(inode);
  195. }
  196. return ret;
  197. }
  198. static const struct file_operations prism2_bss_list_proc_fops = {
  199. .open = prism2_bss_list_proc_open,
  200. .read = seq_read,
  201. .llseek = seq_lseek,
  202. .release = seq_release,
  203. };
  204. static int prism2_crypt_proc_show(struct seq_file *m, void *v)
  205. {
  206. local_info_t *local = m->private;
  207. int i;
  208. seq_printf(m, "tx_keyidx=%d\n", local->crypt_info.tx_keyidx);
  209. for (i = 0; i < WEP_KEYS; i++) {
  210. if (local->crypt_info.crypt[i] &&
  211. local->crypt_info.crypt[i]->ops &&
  212. local->crypt_info.crypt[i]->ops->print_stats) {
  213. local->crypt_info.crypt[i]->ops->print_stats(
  214. m, local->crypt_info.crypt[i]->priv);
  215. }
  216. }
  217. return 0;
  218. }
  219. static int prism2_crypt_proc_open(struct inode *inode, struct file *file)
  220. {
  221. return single_open(file, prism2_crypt_proc_show, PDE_DATA(inode));
  222. }
  223. static const struct file_operations prism2_crypt_proc_fops = {
  224. .open = prism2_crypt_proc_open,
  225. .read = seq_read,
  226. .llseek = seq_lseek,
  227. .release = single_release,
  228. };
  229. static ssize_t prism2_pda_proc_read(struct file *file, char __user *buf,
  230. size_t count, loff_t *_pos)
  231. {
  232. local_info_t *local = PDE_DATA(file_inode(file));
  233. size_t off;
  234. if (local->pda == NULL || *_pos >= PRISM2_PDA_SIZE)
  235. return 0;
  236. off = *_pos;
  237. if (count > PRISM2_PDA_SIZE - off)
  238. count = PRISM2_PDA_SIZE - off;
  239. if (copy_to_user(buf, local->pda + off, count) != 0)
  240. return -EFAULT;
  241. *_pos += count;
  242. return count;
  243. }
  244. static const struct file_operations prism2_pda_proc_fops = {
  245. .read = prism2_pda_proc_read,
  246. .llseek = generic_file_llseek,
  247. };
  248. static ssize_t prism2_aux_dump_proc_no_read(struct file *file, char __user *buf,
  249. size_t bufsize, loff_t *_pos)
  250. {
  251. return 0;
  252. }
  253. static const struct file_operations prism2_aux_dump_proc_fops = {
  254. .read = prism2_aux_dump_proc_no_read,
  255. };
  256. #ifdef PRISM2_IO_DEBUG
  257. static int prism2_io_debug_proc_read(char *page, char **start, off_t off,
  258. int count, int *eof, void *data)
  259. {
  260. local_info_t *local = (local_info_t *) data;
  261. int head = local->io_debug_head;
  262. int start_bytes, left, copy, copied;
  263. if (off + count > PRISM2_IO_DEBUG_SIZE * 4) {
  264. *eof = 1;
  265. if (off >= PRISM2_IO_DEBUG_SIZE * 4)
  266. return 0;
  267. count = PRISM2_IO_DEBUG_SIZE * 4 - off;
  268. }
  269. copied = 0;
  270. start_bytes = (PRISM2_IO_DEBUG_SIZE - head) * 4;
  271. left = count;
  272. if (off < start_bytes) {
  273. copy = start_bytes - off;
  274. if (copy > count)
  275. copy = count;
  276. memcpy(page, ((u8 *) &local->io_debug[head]) + off, copy);
  277. left -= copy;
  278. if (left > 0)
  279. memcpy(&page[copy], local->io_debug, left);
  280. } else {
  281. memcpy(page, ((u8 *) local->io_debug) + (off - start_bytes),
  282. left);
  283. }
  284. *start = page;
  285. return count;
  286. }
  287. #endif /* PRISM2_IO_DEBUG */
  288. #ifndef PRISM2_NO_STATION_MODES
  289. static int prism2_scan_results_proc_show(struct seq_file *m, void *v)
  290. {
  291. local_info_t *local = m->private;
  292. unsigned long entry;
  293. int i, len;
  294. struct hfa384x_hostscan_result *scanres;
  295. u8 *p;
  296. if (v == SEQ_START_TOKEN) {
  297. seq_printf(m,
  298. "CHID ANL SL BcnInt Capab Rate BSSID ATIM SupRates SSID\n");
  299. return 0;
  300. }
  301. entry = (unsigned long)v - 2;
  302. scanres = &local->last_scan_results[entry];
  303. seq_printf(m, "%d %d %d %d 0x%02x %d %pM %d ",
  304. le16_to_cpu(scanres->chid),
  305. (s16) le16_to_cpu(scanres->anl),
  306. (s16) le16_to_cpu(scanres->sl),
  307. le16_to_cpu(scanres->beacon_interval),
  308. le16_to_cpu(scanres->capability),
  309. le16_to_cpu(scanres->rate),
  310. scanres->bssid,
  311. le16_to_cpu(scanres->atim));
  312. p = scanres->sup_rates;
  313. for (i = 0; i < sizeof(scanres->sup_rates); i++) {
  314. if (p[i] == 0)
  315. break;
  316. seq_printf(m, "<%02x>", p[i]);
  317. }
  318. seq_putc(m, ' ');
  319. p = scanres->ssid;
  320. len = le16_to_cpu(scanres->ssid_len);
  321. if (len > 32)
  322. len = 32;
  323. for (i = 0; i < len; i++) {
  324. unsigned char c = p[i];
  325. if (c >= 32 && c < 127)
  326. seq_putc(m, c);
  327. else
  328. seq_printf(m, "<%02x>", c);
  329. }
  330. seq_putc(m, '\n');
  331. return 0;
  332. }
  333. static void *prism2_scan_results_proc_start(struct seq_file *m, loff_t *_pos)
  334. {
  335. local_info_t *local = m->private;
  336. spin_lock_bh(&local->lock);
  337. /* We have a header (pos 0) + N results to show (pos 1...N) */
  338. if (*_pos > local->last_scan_results_count)
  339. return NULL;
  340. return (void *)(unsigned long)(*_pos + 1); /* 0 would be EOF */
  341. }
  342. static void *prism2_scan_results_proc_next(struct seq_file *m, void *v, loff_t *_pos)
  343. {
  344. local_info_t *local = m->private;
  345. ++*_pos;
  346. if (*_pos > local->last_scan_results_count)
  347. return NULL;
  348. return (void *)(unsigned long)(*_pos + 1); /* 0 would be EOF */
  349. }
  350. static void prism2_scan_results_proc_stop(struct seq_file *m, void *v)
  351. {
  352. local_info_t *local = m->private;
  353. spin_unlock_bh(&local->lock);
  354. }
  355. static const struct seq_operations prism2_scan_results_proc_seqops = {
  356. .start = prism2_scan_results_proc_start,
  357. .next = prism2_scan_results_proc_next,
  358. .stop = prism2_scan_results_proc_stop,
  359. .show = prism2_scan_results_proc_show,
  360. };
  361. static int prism2_scan_results_proc_open(struct inode *inode, struct file *file)
  362. {
  363. int ret = seq_open(file, &prism2_scan_results_proc_seqops);
  364. if (ret == 0) {
  365. struct seq_file *m = file->private_data;
  366. m->private = PDE_DATA(inode);
  367. }
  368. return ret;
  369. }
  370. static const struct file_operations prism2_scan_results_proc_fops = {
  371. .open = prism2_scan_results_proc_open,
  372. .read = seq_read,
  373. .llseek = seq_lseek,
  374. .release = seq_release,
  375. };
  376. #endif /* PRISM2_NO_STATION_MODES */
  377. void hostap_init_proc(local_info_t *local)
  378. {
  379. local->proc = NULL;
  380. if (hostap_proc == NULL) {
  381. printk(KERN_WARNING "%s: hostap proc directory not created\n",
  382. local->dev->name);
  383. return;
  384. }
  385. local->proc = proc_mkdir(local->ddev->name, hostap_proc);
  386. if (local->proc == NULL) {
  387. printk(KERN_INFO "/proc/net/hostap/%s creation failed\n",
  388. local->ddev->name);
  389. return;
  390. }
  391. #ifndef PRISM2_NO_PROCFS_DEBUG
  392. proc_create_data("debug", 0, local->proc,
  393. &prism2_debug_proc_fops, local);
  394. #endif /* PRISM2_NO_PROCFS_DEBUG */
  395. proc_create_data("stats", 0, local->proc,
  396. &prism2_stats_proc_fops, local);
  397. proc_create_data("wds", 0, local->proc,
  398. &prism2_wds_proc_fops, local);
  399. proc_create_data("pda", 0, local->proc,
  400. &prism2_pda_proc_fops, local);
  401. proc_create_data("aux_dump", 0, local->proc,
  402. local->func->read_aux_fops ?: &prism2_aux_dump_proc_fops,
  403. local);
  404. proc_create_data("bss_list", 0, local->proc,
  405. &prism2_bss_list_proc_fops, local);
  406. proc_create_data("crypt", 0, local->proc,
  407. &prism2_crypt_proc_fops, local);
  408. #ifdef PRISM2_IO_DEBUG
  409. proc_create_data("io_debug", 0, local->proc,
  410. &prism2_io_debug_proc_fops, local);
  411. #endif /* PRISM2_IO_DEBUG */
  412. #ifndef PRISM2_NO_STATION_MODES
  413. proc_create_data("scan_results", 0, local->proc,
  414. &prism2_scan_results_proc_fops, local);
  415. #endif /* PRISM2_NO_STATION_MODES */
  416. }
  417. void hostap_remove_proc(local_info_t *local)
  418. {
  419. remove_proc_subtree(local->ddev->name, hostap_proc);
  420. }
  421. EXPORT_SYMBOL(hostap_init_proc);
  422. EXPORT_SYMBOL(hostap_remove_proc);