Merge tag 'vfio-v3.18-rc1' of git://github.com/awilliam/linux-vfio
[cascardo/linux.git] / drivers / net / wireless / hostap / hostap_proc.c
1 /* /proc routines for Host AP driver */
2
3 #include <linux/types.h>
4 #include <linux/proc_fs.h>
5 #include <linux/export.h>
6 #include <net/lib80211.h>
7
8 #include "hostap_wlan.h"
9 #include "hostap.h"
10
11 #define PROC_LIMIT (PAGE_SIZE - 80)
12
13
14 #ifndef PRISM2_NO_PROCFS_DEBUG
15 static int prism2_debug_proc_show(struct seq_file *m, void *v)
16 {
17         local_info_t *local = m->private;
18         int i;
19
20         seq_printf(m, "next_txfid=%d next_alloc=%d\n",
21                    local->next_txfid, local->next_alloc);
22         for (i = 0; i < PRISM2_TXFID_COUNT; i++)
23                 seq_printf(m, "FID: tx=%04X intransmit=%04X\n",
24                            local->txfid[i], local->intransmitfid[i]);
25         seq_printf(m, "FW TX rate control: %d\n", local->fw_tx_rate_control);
26         seq_printf(m, "beacon_int=%d\n", local->beacon_int);
27         seq_printf(m, "dtim_period=%d\n", local->dtim_period);
28         seq_printf(m, "wds_max_connections=%d\n", local->wds_max_connections);
29         seq_printf(m, "dev_enabled=%d\n", local->dev_enabled);
30         seq_printf(m, "sw_tick_stuck=%d\n", local->sw_tick_stuck);
31         for (i = 0; i < WEP_KEYS; i++) {
32                 if (local->crypt_info.crypt[i] &&
33                     local->crypt_info.crypt[i]->ops) {
34                         seq_printf(m, "crypt[%d]=%s\n", i,
35                                    local->crypt_info.crypt[i]->ops->name);
36                 }
37         }
38         seq_printf(m, "pri_only=%d\n", local->pri_only);
39         seq_printf(m, "pci=%d\n", local->func->hw_type == HOSTAP_HW_PCI);
40         seq_printf(m, "sram_type=%d\n", local->sram_type);
41         seq_printf(m, "no_pri=%d\n", local->no_pri);
42
43         return 0;
44 }
45
46 static int prism2_debug_proc_open(struct inode *inode, struct file *file)
47 {
48         return single_open(file, prism2_debug_proc_show, PDE_DATA(inode));
49 }
50
51 static const struct file_operations prism2_debug_proc_fops = {
52         .open           = prism2_debug_proc_open,
53         .read           = seq_read,
54         .llseek         = seq_lseek,
55         .release        = single_release,
56 };
57 #endif /* PRISM2_NO_PROCFS_DEBUG */
58
59
60 static int prism2_stats_proc_show(struct seq_file *m, void *v)
61 {
62         local_info_t *local = m->private;
63         struct comm_tallies_sums *sums = &local->comm_tallies;
64
65         seq_printf(m, "TxUnicastFrames=%u\n", sums->tx_unicast_frames);
66         seq_printf(m, "TxMulticastframes=%u\n", sums->tx_multicast_frames);
67         seq_printf(m, "TxFragments=%u\n", sums->tx_fragments);
68         seq_printf(m, "TxUnicastOctets=%u\n", sums->tx_unicast_octets);
69         seq_printf(m, "TxMulticastOctets=%u\n", sums->tx_multicast_octets);
70         seq_printf(m, "TxDeferredTransmissions=%u\n",
71                    sums->tx_deferred_transmissions);
72         seq_printf(m, "TxSingleRetryFrames=%u\n", sums->tx_single_retry_frames);
73         seq_printf(m, "TxMultipleRetryFrames=%u\n",
74                    sums->tx_multiple_retry_frames);
75         seq_printf(m, "TxRetryLimitExceeded=%u\n",
76                    sums->tx_retry_limit_exceeded);
77         seq_printf(m, "TxDiscards=%u\n", sums->tx_discards);
78         seq_printf(m, "RxUnicastFrames=%u\n", sums->rx_unicast_frames);
79         seq_printf(m, "RxMulticastFrames=%u\n", sums->rx_multicast_frames);
80         seq_printf(m, "RxFragments=%u\n", sums->rx_fragments);
81         seq_printf(m, "RxUnicastOctets=%u\n", sums->rx_unicast_octets);
82         seq_printf(m, "RxMulticastOctets=%u\n", sums->rx_multicast_octets);
83         seq_printf(m, "RxFCSErrors=%u\n", sums->rx_fcs_errors);
84         seq_printf(m, "RxDiscardsNoBuffer=%u\n", sums->rx_discards_no_buffer);
85         seq_printf(m, "TxDiscardsWrongSA=%u\n", sums->tx_discards_wrong_sa);
86         seq_printf(m, "RxDiscardsWEPUndecryptable=%u\n",
87                    sums->rx_discards_wep_undecryptable);
88         seq_printf(m, "RxMessageInMsgFragments=%u\n",
89                    sums->rx_message_in_msg_fragments);
90         seq_printf(m, "RxMessageInBadMsgFragments=%u\n",
91                    sums->rx_message_in_bad_msg_fragments);
92         /* FIX: this may grow too long for one page(?) */
93
94         return 0;
95 }
96
97 static int prism2_stats_proc_open(struct inode *inode, struct file *file)
98 {
99         return single_open(file, prism2_stats_proc_show, PDE_DATA(inode));
100 }
101
102 static const struct file_operations prism2_stats_proc_fops = {
103         .open           = prism2_stats_proc_open,
104         .read           = seq_read,
105         .llseek         = seq_lseek,
106         .release        = single_release,
107 };
108
109
110 static int prism2_wds_proc_show(struct seq_file *m, void *v)
111 {
112         struct list_head *ptr = v;
113         struct hostap_interface *iface;
114
115         iface = list_entry(ptr, struct hostap_interface, list);
116         if (iface->type == HOSTAP_INTERFACE_WDS)
117                 seq_printf(m, "%s\t%pM\n",
118                            iface->dev->name, iface->u.wds.remote_addr);
119         return 0;
120 }
121
122 static void *prism2_wds_proc_start(struct seq_file *m, loff_t *_pos)
123 {
124         local_info_t *local = m->private;
125         read_lock_bh(&local->iface_lock);
126         return seq_list_start(&local->hostap_interfaces, *_pos);
127 }
128
129 static void *prism2_wds_proc_next(struct seq_file *m, void *v, loff_t *_pos)
130 {
131         local_info_t *local = m->private;
132         return seq_list_next(v, &local->hostap_interfaces, _pos);
133 }
134
135 static void prism2_wds_proc_stop(struct seq_file *m, void *v)
136 {
137         local_info_t *local = m->private;
138         read_unlock_bh(&local->iface_lock);
139 }
140
141 static const struct seq_operations prism2_wds_proc_seqops = {
142         .start  = prism2_wds_proc_start,
143         .next   = prism2_wds_proc_next,
144         .stop   = prism2_wds_proc_stop,
145         .show   = prism2_wds_proc_show,
146 };
147
148 static int prism2_wds_proc_open(struct inode *inode, struct file *file)
149 {
150         int ret = seq_open(file, &prism2_wds_proc_seqops);
151         if (ret == 0) {
152                 struct seq_file *m = file->private_data;
153                 m->private = PDE_DATA(inode);
154         }
155         return ret;
156 }
157
158 static const struct file_operations prism2_wds_proc_fops = {
159         .open           = prism2_wds_proc_open,
160         .read           = seq_read,
161         .llseek         = seq_lseek,
162         .release        = seq_release,
163 };
164
165
166 static int prism2_bss_list_proc_show(struct seq_file *m, void *v)
167 {
168         local_info_t *local = m->private;
169         struct list_head *ptr = v;
170         struct hostap_bss_info *bss;
171         int i;
172
173         if (ptr == &local->bss_list) {
174                 seq_printf(m, "#BSSID\tlast_update\tcount\tcapab_info\tSSID(txt)\t"
175                            "SSID(hex)\tWPA IE\n");
176                 return 0;
177         }
178
179         bss = list_entry(ptr, struct hostap_bss_info, list);
180         seq_printf(m, "%pM\t%lu\t%u\t0x%x\t",
181                    bss->bssid, bss->last_update,
182                    bss->count, bss->capab_info);
183
184         for (i = 0; i < bss->ssid_len; i++)
185                 seq_putc(m,bss->ssid[i] >= 32 && bss->ssid[i] < 127 ?
186                            bss->ssid[i] : '_');
187
188         seq_putc(m, '\t');
189         seq_printf(m, "%*phN", (int)bss->ssid_len, bss->ssid);
190         seq_putc(m, '\t');
191         seq_printf(m, "%*phN", (int)bss->wpa_ie_len, bss->wpa_ie);
192         seq_putc(m, '\n');
193         return 0;
194 }
195
196 static void *prism2_bss_list_proc_start(struct seq_file *m, loff_t *_pos)
197 {
198         local_info_t *local = m->private;
199         spin_lock_bh(&local->lock);
200         return seq_list_start_head(&local->bss_list, *_pos);
201 }
202
203 static void *prism2_bss_list_proc_next(struct seq_file *m, void *v, loff_t *_pos)
204 {
205         local_info_t *local = m->private;
206         return seq_list_next(v, &local->bss_list, _pos);
207 }
208
209 static void prism2_bss_list_proc_stop(struct seq_file *m, void *v)
210 {
211         local_info_t *local = m->private;
212         spin_unlock_bh(&local->lock);
213 }
214
215 static const struct seq_operations prism2_bss_list_proc_seqops = {
216         .start  = prism2_bss_list_proc_start,
217         .next   = prism2_bss_list_proc_next,
218         .stop   = prism2_bss_list_proc_stop,
219         .show   = prism2_bss_list_proc_show,
220 };
221
222 static int prism2_bss_list_proc_open(struct inode *inode, struct file *file)
223 {
224         int ret = seq_open(file, &prism2_bss_list_proc_seqops);
225         if (ret == 0) {
226                 struct seq_file *m = file->private_data;
227                 m->private = PDE_DATA(inode);
228         }
229         return ret;
230 }
231
232 static const struct file_operations prism2_bss_list_proc_fops = {
233         .open           = prism2_bss_list_proc_open,
234         .read           = seq_read,
235         .llseek         = seq_lseek,
236         .release        = seq_release,
237 };
238
239
240 static int prism2_crypt_proc_show(struct seq_file *m, void *v)
241 {
242         local_info_t *local = m->private;
243         int i;
244
245         seq_printf(m, "tx_keyidx=%d\n", local->crypt_info.tx_keyidx);
246         for (i = 0; i < WEP_KEYS; i++) {
247                 if (local->crypt_info.crypt[i] &&
248                     local->crypt_info.crypt[i]->ops &&
249                     local->crypt_info.crypt[i]->ops->print_stats) {
250                         local->crypt_info.crypt[i]->ops->print_stats(
251                                 m, local->crypt_info.crypt[i]->priv);
252                 }
253         }
254         return 0;
255 }
256
257 static int prism2_crypt_proc_open(struct inode *inode, struct file *file)
258 {
259         return single_open(file, prism2_crypt_proc_show, PDE_DATA(inode));
260 }
261
262 static const struct file_operations prism2_crypt_proc_fops = {
263         .open           = prism2_crypt_proc_open,
264         .read           = seq_read,
265         .llseek         = seq_lseek,
266         .release        = single_release,
267 };
268
269
270 static ssize_t prism2_pda_proc_read(struct file *file, char __user *buf,
271                                     size_t count, loff_t *_pos)
272 {
273         local_info_t *local = PDE_DATA(file_inode(file));
274         size_t off;
275
276         if (local->pda == NULL || *_pos >= PRISM2_PDA_SIZE)
277                 return 0;
278
279         off = *_pos;
280         if (count > PRISM2_PDA_SIZE - off)
281                 count = PRISM2_PDA_SIZE - off;
282         if (copy_to_user(buf, local->pda + off, count) != 0)
283                 return -EFAULT;
284         *_pos += count;
285         return count;
286 }
287
288 static const struct file_operations prism2_pda_proc_fops = {
289         .read           = prism2_pda_proc_read,
290         .llseek         = generic_file_llseek,
291 };
292
293
294 static ssize_t prism2_aux_dump_proc_no_read(struct file *file, char __user *buf,
295                                             size_t bufsize, loff_t *_pos)
296 {
297         return 0;
298 }
299
300 static const struct file_operations prism2_aux_dump_proc_fops = {
301         .read           = prism2_aux_dump_proc_no_read,
302 };
303
304
305 #ifdef PRISM2_IO_DEBUG
306 static int prism2_io_debug_proc_read(char *page, char **start, off_t off,
307                                      int count, int *eof, void *data)
308 {
309         local_info_t *local = (local_info_t *) data;
310         int head = local->io_debug_head;
311         int start_bytes, left, copy, copied;
312
313         if (off + count > PRISM2_IO_DEBUG_SIZE * 4) {
314                 *eof = 1;
315                 if (off >= PRISM2_IO_DEBUG_SIZE * 4)
316                         return 0;
317                 count = PRISM2_IO_DEBUG_SIZE * 4 - off;
318         }
319
320         copied = 0;
321         start_bytes = (PRISM2_IO_DEBUG_SIZE - head) * 4;
322         left = count;
323
324         if (off < start_bytes) {
325                 copy = start_bytes - off;
326                 if (copy > count)
327                         copy = count;
328                 memcpy(page, ((u8 *) &local->io_debug[head]) + off, copy);
329                 left -= copy;
330                 if (left > 0)
331                         memcpy(&page[copy], local->io_debug, left);
332         } else {
333                 memcpy(page, ((u8 *) local->io_debug) + (off - start_bytes),
334                        left);
335         }
336
337         *start = page;
338
339         return count;
340 }
341 #endif /* PRISM2_IO_DEBUG */
342
343
344 #ifndef PRISM2_NO_STATION_MODES
345 static int prism2_scan_results_proc_show(struct seq_file *m, void *v)
346 {
347         local_info_t *local = m->private;
348         unsigned long entry;
349         int i, len;
350         struct hfa384x_hostscan_result *scanres;
351         u8 *p;
352
353         if (v == SEQ_START_TOKEN) {
354                 seq_printf(m,
355                            "CHID ANL SL BcnInt Capab Rate BSSID ATIM SupRates SSID\n");
356                 return 0;
357         }
358
359         entry = (unsigned long)v - 2;
360         scanres = &local->last_scan_results[entry];
361
362         seq_printf(m, "%d %d %d %d 0x%02x %d %pM %d ",
363                    le16_to_cpu(scanres->chid),
364                    (s16) le16_to_cpu(scanres->anl),
365                    (s16) le16_to_cpu(scanres->sl),
366                    le16_to_cpu(scanres->beacon_interval),
367                    le16_to_cpu(scanres->capability),
368                    le16_to_cpu(scanres->rate),
369                    scanres->bssid,
370                    le16_to_cpu(scanres->atim));
371
372         p = scanres->sup_rates;
373         for (i = 0; i < sizeof(scanres->sup_rates); i++) {
374                 if (p[i] == 0)
375                         break;
376                 seq_printf(m, "<%02x>", p[i]);
377         }
378         seq_putc(m, ' ');
379
380         p = scanres->ssid;
381         len = le16_to_cpu(scanres->ssid_len);
382         if (len > 32)
383                 len = 32;
384         for (i = 0; i < len; i++) {
385                 unsigned char c = p[i];
386                 if (c >= 32 && c < 127)
387                         seq_putc(m, c);
388                 else
389                         seq_printf(m, "<%02x>", c);
390         }
391         seq_putc(m, '\n');
392         return 0;
393 }
394
395 static void *prism2_scan_results_proc_start(struct seq_file *m, loff_t *_pos)
396 {
397         local_info_t *local = m->private;
398         spin_lock_bh(&local->lock);
399
400         /* We have a header (pos 0) + N results to show (pos 1...N) */
401         if (*_pos > local->last_scan_results_count)
402                 return NULL;
403         return (void *)(unsigned long)(*_pos + 1); /* 0 would be EOF */
404 }
405
406 static void *prism2_scan_results_proc_next(struct seq_file *m, void *v, loff_t *_pos)
407 {
408         local_info_t *local = m->private;
409
410         ++*_pos;
411         if (*_pos > local->last_scan_results_count)
412                 return NULL;
413         return (void *)(unsigned long)(*_pos + 1); /* 0 would be EOF */
414 }
415
416 static void prism2_scan_results_proc_stop(struct seq_file *m, void *v)
417 {
418         local_info_t *local = m->private;
419         spin_unlock_bh(&local->lock);
420 }
421
422 static const struct seq_operations prism2_scan_results_proc_seqops = {
423         .start  = prism2_scan_results_proc_start,
424         .next   = prism2_scan_results_proc_next,
425         .stop   = prism2_scan_results_proc_stop,
426         .show   = prism2_scan_results_proc_show,
427 };
428
429 static int prism2_scan_results_proc_open(struct inode *inode, struct file *file)
430 {
431         int ret = seq_open(file, &prism2_scan_results_proc_seqops);
432         if (ret == 0) {
433                 struct seq_file *m = file->private_data;
434                 m->private = PDE_DATA(inode);
435         }
436         return ret;
437 }
438
439 static const struct file_operations prism2_scan_results_proc_fops = {
440         .open           = prism2_scan_results_proc_open,
441         .read           = seq_read,
442         .llseek         = seq_lseek,
443         .release        = seq_release,
444 };
445
446
447 #endif /* PRISM2_NO_STATION_MODES */
448
449
450 void hostap_init_proc(local_info_t *local)
451 {
452         local->proc = NULL;
453
454         if (hostap_proc == NULL) {
455                 printk(KERN_WARNING "%s: hostap proc directory not created\n",
456                        local->dev->name);
457                 return;
458         }
459
460         local->proc = proc_mkdir(local->ddev->name, hostap_proc);
461         if (local->proc == NULL) {
462                 printk(KERN_INFO "/proc/net/hostap/%s creation failed\n",
463                        local->ddev->name);
464                 return;
465         }
466
467 #ifndef PRISM2_NO_PROCFS_DEBUG
468         proc_create_data("debug", 0, local->proc,
469                          &prism2_debug_proc_fops, local);
470 #endif /* PRISM2_NO_PROCFS_DEBUG */
471         proc_create_data("stats", 0, local->proc,
472                          &prism2_stats_proc_fops, local);
473         proc_create_data("wds", 0, local->proc,
474                          &prism2_wds_proc_fops, local);
475         proc_create_data("pda", 0, local->proc,
476                          &prism2_pda_proc_fops, local);
477         proc_create_data("aux_dump", 0, local->proc,
478                          local->func->read_aux_fops ?: &prism2_aux_dump_proc_fops,
479                          local);
480         proc_create_data("bss_list", 0, local->proc,
481                          &prism2_bss_list_proc_fops, local);
482         proc_create_data("crypt", 0, local->proc,
483                          &prism2_crypt_proc_fops, local);
484 #ifdef PRISM2_IO_DEBUG
485         proc_create_data("io_debug", 0, local->proc,
486                          &prism2_io_debug_proc_fops, local);
487 #endif /* PRISM2_IO_DEBUG */
488 #ifndef PRISM2_NO_STATION_MODES
489         proc_create_data("scan_results", 0, local->proc,
490                          &prism2_scan_results_proc_fops, local);
491 #endif /* PRISM2_NO_STATION_MODES */
492 }
493
494
495 void hostap_remove_proc(local_info_t *local)
496 {
497         proc_remove(local->proc);
498 }
499
500
501 EXPORT_SYMBOL(hostap_init_proc);
502 EXPORT_SYMBOL(hostap_remove_proc);