hostap_proc.c 12 KB

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