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