hostap_proc.c 12 KB

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