hostap_proc.c 13 KB

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