^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * This file implement the Wireless Extensions proc API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * (As all part of the Linux kernel, this file is GPL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * The /proc/net/wireless file is a human readable user-space interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * exporting various wireless specific statistics from the wireless devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * This is the most popular part of the Wireless Extensions ;-)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * The content of the file is basically the content of "struct iw_statistics".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/wireless.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <net/iw_handler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <net/wext.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static void wireless_seq_printf_stats(struct seq_file *seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* Get stats from the driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct iw_statistics *stats = get_wireless_stats(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static struct iw_statistics nullstats = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* show device if it's wireless regardless of current stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (!stats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #ifdef CONFIG_WIRELESS_EXT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (dev->wireless_handlers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) stats = &nullstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #ifdef CONFIG_CFG80211
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (dev->ieee80211_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) stats = &nullstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (stats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) "%6d %6d %6d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) dev->name, stats->status, stats->qual.qual,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) stats->qual.updated & IW_QUAL_QUAL_UPDATED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) ? '.' : ' ',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ((__s32) stats->qual.level) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) stats->qual.updated & IW_QUAL_LEVEL_UPDATED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ? '.' : ' ',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) ((__s32) stats->qual.noise) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) stats->qual.updated & IW_QUAL_NOISE_UPDATED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ? '.' : ' ',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) stats->discard.nwid, stats->discard.code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) stats->discard.fragment, stats->discard.retries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) stats->discard.misc, stats->miss.beacon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (stats != &nullstats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* ---------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * Print info for /proc/net/wireless (print all entries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static int wireless_dev_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) might_sleep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (v == SEQ_START_TOKEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) seq_printf(seq, "Inter-| sta-| Quality | Discarded "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) "packets | Missed | WE\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) " face | tus | link level noise | nwid "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) "crypt frag retry misc | beacon | %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) WIRELESS_EXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) wireless_seq_printf_stats(seq, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static void *wireless_dev_seq_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct net *net = seq_file_net(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) loff_t off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (!*pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return SEQ_START_TOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) off = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) for_each_netdev(net, dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (off++ == *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void *wireless_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct net *net = seq_file_net(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) ++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return v == SEQ_START_TOKEN ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) first_net_device(net) : next_net_device(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static void wireless_dev_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static const struct seq_operations wireless_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .start = wireless_dev_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .next = wireless_dev_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .stop = wireless_dev_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .show = wireless_dev_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int __net_init wext_proc_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* Create /proc/net/wireless entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (!proc_create_net("wireless", 0444, net->proc_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) &wireless_seq_ops, sizeof(struct seq_net_private)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) void __net_exit wext_proc_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) remove_proc_entry("wireless", net->proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }