0001
0002
0003
0004 #include <linux/types.h>
0005 #include <linux/proc_fs.h>
0006 #include <linux/export.h>
0007 #include <net/lib80211.h>
0008
0009 #include "hostap_wlan.h"
0010 #include "hostap.h"
0011
0012 #define PROC_LIMIT (PAGE_SIZE - 80)
0013
0014 #if !defined(PRISM2_NO_PROCFS_DEBUG) && defined(CONFIG_PROC_FS)
0015 static int prism2_debug_proc_show(struct seq_file *m, void *v)
0016 {
0017 local_info_t *local = m->private;
0018 int i;
0019
0020 seq_printf(m, "next_txfid=%d next_alloc=%d\n",
0021 local->next_txfid, local->next_alloc);
0022 for (i = 0; i < PRISM2_TXFID_COUNT; i++)
0023 seq_printf(m, "FID: tx=%04X intransmit=%04X\n",
0024 local->txfid[i], local->intransmitfid[i]);
0025 seq_printf(m, "FW TX rate control: %d\n", local->fw_tx_rate_control);
0026 seq_printf(m, "beacon_int=%d\n", local->beacon_int);
0027 seq_printf(m, "dtim_period=%d\n", local->dtim_period);
0028 seq_printf(m, "wds_max_connections=%d\n", local->wds_max_connections);
0029 seq_printf(m, "dev_enabled=%d\n", local->dev_enabled);
0030 seq_printf(m, "sw_tick_stuck=%d\n", local->sw_tick_stuck);
0031 for (i = 0; i < WEP_KEYS; i++) {
0032 if (local->crypt_info.crypt[i] &&
0033 local->crypt_info.crypt[i]->ops) {
0034 seq_printf(m, "crypt[%d]=%s\n", i,
0035 local->crypt_info.crypt[i]->ops->name);
0036 }
0037 }
0038 seq_printf(m, "pri_only=%d\n", local->pri_only);
0039 seq_printf(m, "pci=%d\n", local->func->hw_type == HOSTAP_HW_PCI);
0040 seq_printf(m, "sram_type=%d\n", local->sram_type);
0041 seq_printf(m, "no_pri=%d\n", local->no_pri);
0042
0043 return 0;
0044 }
0045 #endif
0046
0047 #ifdef CONFIG_PROC_FS
0048 static int prism2_stats_proc_show(struct seq_file *m, void *v)
0049 {
0050 local_info_t *local = m->private;
0051 struct comm_tallies_sums *sums = &local->comm_tallies;
0052
0053 seq_printf(m, "TxUnicastFrames=%u\n", sums->tx_unicast_frames);
0054 seq_printf(m, "TxMulticastframes=%u\n", sums->tx_multicast_frames);
0055 seq_printf(m, "TxFragments=%u\n", sums->tx_fragments);
0056 seq_printf(m, "TxUnicastOctets=%u\n", sums->tx_unicast_octets);
0057 seq_printf(m, "TxMulticastOctets=%u\n", sums->tx_multicast_octets);
0058 seq_printf(m, "TxDeferredTransmissions=%u\n",
0059 sums->tx_deferred_transmissions);
0060 seq_printf(m, "TxSingleRetryFrames=%u\n", sums->tx_single_retry_frames);
0061 seq_printf(m, "TxMultipleRetryFrames=%u\n",
0062 sums->tx_multiple_retry_frames);
0063 seq_printf(m, "TxRetryLimitExceeded=%u\n",
0064 sums->tx_retry_limit_exceeded);
0065 seq_printf(m, "TxDiscards=%u\n", sums->tx_discards);
0066 seq_printf(m, "RxUnicastFrames=%u\n", sums->rx_unicast_frames);
0067 seq_printf(m, "RxMulticastFrames=%u\n", sums->rx_multicast_frames);
0068 seq_printf(m, "RxFragments=%u\n", sums->rx_fragments);
0069 seq_printf(m, "RxUnicastOctets=%u\n", sums->rx_unicast_octets);
0070 seq_printf(m, "RxMulticastOctets=%u\n", sums->rx_multicast_octets);
0071 seq_printf(m, "RxFCSErrors=%u\n", sums->rx_fcs_errors);
0072 seq_printf(m, "RxDiscardsNoBuffer=%u\n", sums->rx_discards_no_buffer);
0073 seq_printf(m, "TxDiscardsWrongSA=%u\n", sums->tx_discards_wrong_sa);
0074 seq_printf(m, "RxDiscardsWEPUndecryptable=%u\n",
0075 sums->rx_discards_wep_undecryptable);
0076 seq_printf(m, "RxMessageInMsgFragments=%u\n",
0077 sums->rx_message_in_msg_fragments);
0078 seq_printf(m, "RxMessageInBadMsgFragments=%u\n",
0079 sums->rx_message_in_bad_msg_fragments);
0080
0081
0082 return 0;
0083 }
0084 #endif
0085
0086 static int prism2_wds_proc_show(struct seq_file *m, void *v)
0087 {
0088 struct list_head *ptr = v;
0089 struct hostap_interface *iface;
0090
0091 iface = list_entry(ptr, struct hostap_interface, list);
0092 if (iface->type == HOSTAP_INTERFACE_WDS)
0093 seq_printf(m, "%s\t%pM\n",
0094 iface->dev->name, iface->u.wds.remote_addr);
0095 return 0;
0096 }
0097
0098 static void *prism2_wds_proc_start(struct seq_file *m, loff_t *_pos)
0099 {
0100 local_info_t *local = pde_data(file_inode(m->file));
0101 read_lock_bh(&local->iface_lock);
0102 return seq_list_start(&local->hostap_interfaces, *_pos);
0103 }
0104
0105 static void *prism2_wds_proc_next(struct seq_file *m, void *v, loff_t *_pos)
0106 {
0107 local_info_t *local = pde_data(file_inode(m->file));
0108 return seq_list_next(v, &local->hostap_interfaces, _pos);
0109 }
0110
0111 static void prism2_wds_proc_stop(struct seq_file *m, void *v)
0112 {
0113 local_info_t *local = pde_data(file_inode(m->file));
0114 read_unlock_bh(&local->iface_lock);
0115 }
0116
0117 static const struct seq_operations prism2_wds_proc_seqops = {
0118 .start = prism2_wds_proc_start,
0119 .next = prism2_wds_proc_next,
0120 .stop = prism2_wds_proc_stop,
0121 .show = prism2_wds_proc_show,
0122 };
0123
0124 static int prism2_bss_list_proc_show(struct seq_file *m, void *v)
0125 {
0126 local_info_t *local = pde_data(file_inode(m->file));
0127 struct list_head *ptr = v;
0128 struct hostap_bss_info *bss;
0129
0130 if (ptr == &local->bss_list) {
0131 seq_printf(m, "#BSSID\tlast_update\tcount\tcapab_info\tSSID(txt)\t"
0132 "SSID(hex)\tWPA IE\n");
0133 return 0;
0134 }
0135
0136 bss = list_entry(ptr, struct hostap_bss_info, list);
0137 seq_printf(m, "%pM\t%lu\t%u\t0x%x\t",
0138 bss->bssid, bss->last_update,
0139 bss->count, bss->capab_info);
0140
0141 seq_printf(m, "%*pE", (int)bss->ssid_len, bss->ssid);
0142
0143 seq_putc(m, '\t');
0144 seq_printf(m, "%*phN", (int)bss->ssid_len, bss->ssid);
0145 seq_putc(m, '\t');
0146 seq_printf(m, "%*phN", (int)bss->wpa_ie_len, bss->wpa_ie);
0147 seq_putc(m, '\n');
0148 return 0;
0149 }
0150
0151 static void *prism2_bss_list_proc_start(struct seq_file *m, loff_t *_pos)
0152 __acquires(&local->lock)
0153 {
0154 local_info_t *local = pde_data(file_inode(m->file));
0155 spin_lock_bh(&local->lock);
0156 return seq_list_start_head(&local->bss_list, *_pos);
0157 }
0158
0159 static void *prism2_bss_list_proc_next(struct seq_file *m, void *v, loff_t *_pos)
0160 {
0161 local_info_t *local = pde_data(file_inode(m->file));
0162 return seq_list_next(v, &local->bss_list, _pos);
0163 }
0164
0165 static void prism2_bss_list_proc_stop(struct seq_file *m, void *v)
0166 __releases(&local->lock)
0167 {
0168 local_info_t *local = pde_data(file_inode(m->file));
0169 spin_unlock_bh(&local->lock);
0170 }
0171
0172 static const struct seq_operations prism2_bss_list_proc_seqops = {
0173 .start = prism2_bss_list_proc_start,
0174 .next = prism2_bss_list_proc_next,
0175 .stop = prism2_bss_list_proc_stop,
0176 .show = prism2_bss_list_proc_show,
0177 };
0178
0179 #ifdef CONFIG_PROC_FS
0180 static int prism2_crypt_proc_show(struct seq_file *m, void *v)
0181 {
0182 local_info_t *local = m->private;
0183 int i;
0184
0185 seq_printf(m, "tx_keyidx=%d\n", local->crypt_info.tx_keyidx);
0186 for (i = 0; i < WEP_KEYS; i++) {
0187 if (local->crypt_info.crypt[i] &&
0188 local->crypt_info.crypt[i]->ops &&
0189 local->crypt_info.crypt[i]->ops->print_stats) {
0190 local->crypt_info.crypt[i]->ops->print_stats(
0191 m, local->crypt_info.crypt[i]->priv);
0192 }
0193 }
0194 return 0;
0195 }
0196 #endif
0197
0198 static ssize_t prism2_pda_proc_read(struct file *file, char __user *buf,
0199 size_t count, loff_t *_pos)
0200 {
0201 local_info_t *local = pde_data(file_inode(file));
0202 size_t off;
0203
0204 if (local->pda == NULL || *_pos >= PRISM2_PDA_SIZE)
0205 return 0;
0206
0207 off = *_pos;
0208 if (count > PRISM2_PDA_SIZE - off)
0209 count = PRISM2_PDA_SIZE - off;
0210 if (copy_to_user(buf, local->pda + off, count) != 0)
0211 return -EFAULT;
0212 *_pos += count;
0213 return count;
0214 }
0215
0216 static const struct proc_ops prism2_pda_proc_ops = {
0217 .proc_read = prism2_pda_proc_read,
0218 .proc_lseek = generic_file_llseek,
0219 };
0220
0221
0222 static ssize_t prism2_aux_dump_proc_no_read(struct file *file, char __user *buf,
0223 size_t bufsize, loff_t *_pos)
0224 {
0225 return 0;
0226 }
0227
0228 static const struct proc_ops prism2_aux_dump_proc_ops = {
0229 .proc_read = prism2_aux_dump_proc_no_read,
0230 .proc_lseek = default_llseek,
0231 };
0232
0233
0234 #ifdef PRISM2_IO_DEBUG
0235 static int prism2_io_debug_proc_read(char *page, char **start, off_t off,
0236 int count, int *eof, void *data)
0237 {
0238 local_info_t *local = (local_info_t *) data;
0239 int head = local->io_debug_head;
0240 int start_bytes, left, copy;
0241
0242 if (off + count > PRISM2_IO_DEBUG_SIZE * 4) {
0243 *eof = 1;
0244 if (off >= PRISM2_IO_DEBUG_SIZE * 4)
0245 return 0;
0246 count = PRISM2_IO_DEBUG_SIZE * 4 - off;
0247 }
0248
0249 start_bytes = (PRISM2_IO_DEBUG_SIZE - head) * 4;
0250 left = count;
0251
0252 if (off < start_bytes) {
0253 copy = start_bytes - off;
0254 if (copy > count)
0255 copy = count;
0256 memcpy(page, ((u8 *) &local->io_debug[head]) + off, copy);
0257 left -= copy;
0258 if (left > 0)
0259 memcpy(&page[copy], local->io_debug, left);
0260 } else {
0261 memcpy(page, ((u8 *) local->io_debug) + (off - start_bytes),
0262 left);
0263 }
0264
0265 *start = page;
0266
0267 return count;
0268 }
0269 #endif
0270
0271
0272 #ifndef PRISM2_NO_STATION_MODES
0273 static int prism2_scan_results_proc_show(struct seq_file *m, void *v)
0274 {
0275 local_info_t *local = pde_data(file_inode(m->file));
0276 unsigned long entry;
0277 int i, len;
0278 struct hfa384x_hostscan_result *scanres;
0279 u8 *p;
0280
0281 if (v == SEQ_START_TOKEN) {
0282 seq_printf(m,
0283 "CHID ANL SL BcnInt Capab Rate BSSID ATIM SupRates SSID\n");
0284 return 0;
0285 }
0286
0287 entry = (unsigned long)v - 2;
0288 scanres = &local->last_scan_results[entry];
0289
0290 seq_printf(m, "%d %d %d %d 0x%02x %d %pM %d ",
0291 le16_to_cpu(scanres->chid),
0292 (s16) le16_to_cpu(scanres->anl),
0293 (s16) le16_to_cpu(scanres->sl),
0294 le16_to_cpu(scanres->beacon_interval),
0295 le16_to_cpu(scanres->capability),
0296 le16_to_cpu(scanres->rate),
0297 scanres->bssid,
0298 le16_to_cpu(scanres->atim));
0299
0300 p = scanres->sup_rates;
0301 for (i = 0; i < sizeof(scanres->sup_rates); i++) {
0302 if (p[i] == 0)
0303 break;
0304 seq_printf(m, "<%02x>", p[i]);
0305 }
0306 seq_putc(m, ' ');
0307
0308 p = scanres->ssid;
0309 len = le16_to_cpu(scanres->ssid_len);
0310 if (len > 32)
0311 len = 32;
0312 for (i = 0; i < len; i++) {
0313 unsigned char c = p[i];
0314 if (c >= 32 && c < 127)
0315 seq_putc(m, c);
0316 else
0317 seq_printf(m, "<%02x>", c);
0318 }
0319 seq_putc(m, '\n');
0320 return 0;
0321 }
0322
0323 static void *prism2_scan_results_proc_start(struct seq_file *m, loff_t *_pos)
0324 {
0325 local_info_t *local = pde_data(file_inode(m->file));
0326 spin_lock_bh(&local->lock);
0327
0328
0329 if (*_pos > local->last_scan_results_count)
0330 return NULL;
0331 return (void *)(unsigned long)(*_pos + 1);
0332 }
0333
0334 static void *prism2_scan_results_proc_next(struct seq_file *m, void *v, loff_t *_pos)
0335 {
0336 local_info_t *local = pde_data(file_inode(m->file));
0337
0338 ++*_pos;
0339 if (*_pos > local->last_scan_results_count)
0340 return NULL;
0341 return (void *)(unsigned long)(*_pos + 1);
0342 }
0343
0344 static void prism2_scan_results_proc_stop(struct seq_file *m, void *v)
0345 {
0346 local_info_t *local = pde_data(file_inode(m->file));
0347 spin_unlock_bh(&local->lock);
0348 }
0349
0350 static const struct seq_operations prism2_scan_results_proc_seqops = {
0351 .start = prism2_scan_results_proc_start,
0352 .next = prism2_scan_results_proc_next,
0353 .stop = prism2_scan_results_proc_stop,
0354 .show = prism2_scan_results_proc_show,
0355 };
0356 #endif
0357
0358
0359 void hostap_init_proc(local_info_t *local)
0360 {
0361 local->proc = NULL;
0362
0363 if (hostap_proc == NULL) {
0364 printk(KERN_WARNING "%s: hostap proc directory not created\n",
0365 local->dev->name);
0366 return;
0367 }
0368
0369 local->proc = proc_mkdir(local->ddev->name, hostap_proc);
0370 if (local->proc == NULL) {
0371 printk(KERN_INFO "/proc/net/hostap/%s creation failed\n",
0372 local->ddev->name);
0373 return;
0374 }
0375
0376 #ifndef PRISM2_NO_PROCFS_DEBUG
0377 proc_create_single_data("debug", 0, local->proc,
0378 prism2_debug_proc_show, local);
0379 #endif
0380 proc_create_single_data("stats", 0, local->proc, prism2_stats_proc_show,
0381 local);
0382 proc_create_seq_data("wds", 0, local->proc,
0383 &prism2_wds_proc_seqops, local);
0384 proc_create_data("pda", 0, local->proc,
0385 &prism2_pda_proc_ops, local);
0386 proc_create_data("aux_dump", 0, local->proc,
0387 local->func->read_aux_proc_ops ?: &prism2_aux_dump_proc_ops,
0388 local);
0389 proc_create_seq_data("bss_list", 0, local->proc,
0390 &prism2_bss_list_proc_seqops, local);
0391 proc_create_single_data("crypt", 0, local->proc, prism2_crypt_proc_show,
0392 local);
0393 #ifdef PRISM2_IO_DEBUG
0394 proc_create_single_data("io_debug", 0, local->proc,
0395 prism2_debug_proc_show, local);
0396 #endif
0397 #ifndef PRISM2_NO_STATION_MODES
0398 proc_create_seq_data("scan_results", 0, local->proc,
0399 &prism2_scan_results_proc_seqops, local);
0400 #endif
0401 }
0402
0403
0404 void hostap_remove_proc(local_info_t *local)
0405 {
0406 proc_remove(local->proc);
0407 }
0408
0409
0410 EXPORT_SYMBOL(hostap_init_proc);
0411 EXPORT_SYMBOL(hostap_remove_proc);