debugfs.c
Go to the documentation of this file.
00001 
00002 /*
00003  * mac80211 debugfs for wireless PHYs
00004  *
00005  * Copyright 2007       Johannes Berg <johannes@sipsolutions.net>
00006  *
00007  * GPLv2
00008  *
00009  */
00010 
00011 #include <linux/debugfs.h>
00012 #include <linux/rtnetlink.h>
00013 #include "ieee80211_i.h"
00014 #include "driver-ops.h"
00015 #include "rate.h"
00016 #include "debugfs.h"
00017 
00018 #define DEBUGFS_FORMAT_BUFFER_SIZE 100
00019 
00020 int mac80211_format_buffer(char __user *userbuf, size_t count,
00021                                   loff_t *ppos, char *fmt, ...)
00022 {
00023         va_list args;
00024         char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
00025         int res;
00026 
00027         va_start(args, fmt);
00028         res = vscnprintf(buf, sizeof(buf), fmt, args);
00029         va_end(args);
00030 
00031         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
00032 }
00033 
00034 #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...)                   \
00035 static ssize_t name## _read(struct file *file, char __user *userbuf,    \
00036                             size_t count, loff_t *ppos)                 \
00037 {                                                                       \
00038         struct ieee80211_local *local = file->private_data;             \
00039                                                                         \
00040         return mac80211_format_buffer(userbuf, count, ppos,             \
00041                                       fmt "\n", ##value);               \
00042 }
00043 
00044 #define DEBUGFS_READONLY_FILE_OPS(name)                 \
00045 static const struct file_operations name## _ops = {                     \
00046         .read = name## _read,                                           \
00047         .open = simple_open,                                            \
00048         .llseek = generic_file_llseek,                                  \
00049 };
00050 
00051 #define DEBUGFS_READONLY_FILE(name, fmt, value...)              \
00052         DEBUGFS_READONLY_FILE_FN(name, fmt, value)              \
00053         DEBUGFS_READONLY_FILE_OPS(name)
00054 
00055 #define DEBUGFS_ADD(name)                                               \
00056         debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
00057 
00058 #define DEBUGFS_ADD_MODE(name, mode)                                    \
00059         debugfs_create_file(#name, mode, phyd, local, &name## _ops);
00060 
00061 
00062 DEBUGFS_READONLY_FILE(user_power, "%d",
00063                       local->user_power_level);
00064 DEBUGFS_READONLY_FILE(power, "%d",
00065                       local->hw.conf.power_level);
00066 DEBUGFS_READONLY_FILE(frequency, "%d",
00067                       local->hw.conf.channel->center_freq);
00068 DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
00069                       local->total_ps_buffered);
00070 DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
00071                       local->wep_iv & 0xffffff);
00072 DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
00073         local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
00074 
00075 static ssize_t reset_write(struct file *file, const char __user *user_buf,
00076                            size_t count, loff_t *ppos)
00077 {
00078         struct ieee80211_local *local = file->private_data;
00079 
00080         rtnl_lock();
00081         __ieee80211_suspend(&local->hw, NULL);
00082         __ieee80211_resume(&local->hw);
00083         rtnl_unlock();
00084 
00085         return count;
00086 }
00087 
00088 static const struct file_operations reset_ops = {
00089         .write = reset_write,
00090         .open = simple_open,
00091         .llseek = noop_llseek,
00092 };
00093 
00094 static ssize_t channel_type_read(struct file *file, char __user *user_buf,
00095                        size_t count, loff_t *ppos)
00096 {
00097         struct ieee80211_local *local = file->private_data;
00098         const char *buf;
00099 
00100         switch (local->hw.conf.channel_type) {
00101         case NL80211_CHAN_NO_HT:
00102                 buf = "no ht\n";
00103                 break;
00104         case NL80211_CHAN_HT20:
00105                 buf = "ht20\n";
00106                 break;
00107         case NL80211_CHAN_HT40MINUS:
00108                 buf = "ht40-\n";
00109                 break;
00110         case NL80211_CHAN_HT40PLUS:
00111                 buf = "ht40+\n";
00112                 break;
00113         default:
00114                 buf = "???";
00115                 break;
00116         }
00117 
00118         return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
00119 }
00120 
00121 static ssize_t hwflags_read(struct file *file, char __user *user_buf,
00122                             size_t count, loff_t *ppos)
00123 {
00124         struct ieee80211_local *local = file->private_data;
00125         int mxln = 500;
00126         ssize_t rv;
00127         char *buf = kzalloc(mxln, GFP_KERNEL);
00128         int sf = 0; /* how many written so far */
00129 
00130         if (!buf)
00131                 return 0;
00132 
00133         sf += snprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
00134         if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
00135                 sf += snprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
00136         if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
00137                 sf += snprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
00138         if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
00139                 sf += snprintf(buf + sf, mxln - sf,
00140                                "HOST_BCAST_PS_BUFFERING\n");
00141         if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
00142                 sf += snprintf(buf + sf, mxln - sf,
00143                                "2GHZ_SHORT_SLOT_INCAPABLE\n");
00144         if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
00145                 sf += snprintf(buf + sf, mxln - sf,
00146                                "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
00147         if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
00148                 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
00149         if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
00150                 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
00151         if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
00152                 sf += snprintf(buf + sf, mxln - sf, "NEED_DTIM_PERIOD\n");
00153         if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
00154                 sf += snprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
00155         if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
00156                 sf += snprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
00157         if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
00158                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
00159         if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
00160                 sf += snprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
00161         if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
00162                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
00163         if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
00164                 sf += snprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
00165         if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS)
00166                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n");
00167         if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
00168                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_SMPS\n");
00169         if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
00170                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n");
00171         if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
00172                 sf += snprintf(buf + sf, mxln - sf, "REPORTS_TX_ACK_STATUS\n");
00173         if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
00174                 sf += snprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
00175         if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
00176                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
00177         if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
00178                 sf += snprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
00179         if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
00180                 sf += snprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
00181         if (local->hw.flags & IEEE80211_HW_SCAN_WHILE_IDLE)
00182                 sf += snprintf(buf + sf, mxln - sf, "SCAN_WHILE_IDLE\n");
00183 
00184         rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
00185         kfree(buf);
00186         return rv;
00187 }
00188 
00189 static ssize_t queues_read(struct file *file, char __user *user_buf,
00190                            size_t count, loff_t *ppos)
00191 {
00192         struct ieee80211_local *local = file->private_data;
00193         unsigned long flags;
00194         char buf[IEEE80211_MAX_QUEUES * 20];
00195         int q, res = 0;
00196 
00197         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
00198         for (q = 0; q < local->hw.queues; q++)
00199                 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
00200                                 local->queue_stop_reasons[q],
00201                                 skb_queue_len(&local->pending[q]));
00202         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
00203 
00204         return simple_read_from_buffer(user_buf, count, ppos, buf, res);
00205 }
00206 
00207 DEBUGFS_READONLY_FILE_OPS(hwflags);
00208 DEBUGFS_READONLY_FILE_OPS(channel_type);
00209 DEBUGFS_READONLY_FILE_OPS(queues);
00210 
00211 /* statistics stuff */
00212 
00213 static ssize_t format_devstat_counter(struct ieee80211_local *local,
00214         char __user *userbuf,
00215         size_t count, loff_t *ppos,
00216         int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
00217                           int buflen))
00218 {
00219         struct ieee80211_low_level_stats stats;
00220         char buf[20];
00221         int res;
00222 
00223         rtnl_lock();
00224         res = drv_get_stats(local, &stats);
00225         rtnl_unlock();
00226         if (res)
00227                 return res;
00228         res = printvalue(&stats, buf, sizeof(buf));
00229         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
00230 }
00231 
00232 #define DEBUGFS_DEVSTATS_FILE(name)                                     \
00233 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
00234                                  char *buf, int buflen)                 \
00235 {                                                                       \
00236         return scnprintf(buf, buflen, "%u\n", stats->name);             \
00237 }                                                                       \
00238 static ssize_t stats_ ##name## _read(struct file *file,                 \
00239                                      char __user *userbuf,              \
00240                                      size_t count, loff_t *ppos)        \
00241 {                                                                       \
00242         return format_devstat_counter(file->private_data,               \
00243                                       userbuf,                          \
00244                                       count,                            \
00245                                       ppos,                             \
00246                                       print_devstats_##name);           \
00247 }                                                                       \
00248                                                                         \
00249 static const struct file_operations stats_ ##name## _ops = {            \
00250         .read = stats_ ##name## _read,                                  \
00251         .open = simple_open,                                            \
00252         .llseek = generic_file_llseek,                                  \
00253 };
00254 
00255 #define DEBUGFS_STATS_ADD(name, field)                                  \
00256         debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
00257 #define DEBUGFS_DEVSTATS_ADD(name)                                      \
00258         debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
00259 
00260 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
00261 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
00262 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
00263 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
00264 
00265 void debugfs_hw_add(struct ieee80211_local *local)
00266 {
00267         struct dentry *phyd = local->hw.wiphy->debugfsdir;
00268         struct dentry *statsd;
00269 
00270         if (!phyd)
00271                 return;
00272 
00273         local->debugfs.keys = debugfs_create_dir("keys", phyd);
00274 
00275         DEBUGFS_ADD(frequency);
00276         DEBUGFS_ADD(total_ps_buffered);
00277         DEBUGFS_ADD(wep_iv);
00278         DEBUGFS_ADD(queues);
00279         DEBUGFS_ADD_MODE(reset, 0200);
00280         DEBUGFS_ADD(channel_type);
00281         DEBUGFS_ADD(hwflags);
00282         DEBUGFS_ADD(user_power);
00283         DEBUGFS_ADD(power);
00284 
00285         statsd = debugfs_create_dir("statistics", phyd);
00286 
00287         /* if the dir failed, don't put all the other things into the root! */
00288         if (!statsd)
00289                 return;
00290 
00291         DEBUGFS_STATS_ADD(transmitted_fragment_count,
00292                 local->dot11TransmittedFragmentCount);
00293         DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
00294                 local->dot11MulticastTransmittedFrameCount);
00295         DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
00296         DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
00297         DEBUGFS_STATS_ADD(multiple_retry_count,
00298                 local->dot11MultipleRetryCount);
00299         DEBUGFS_STATS_ADD(frame_duplicate_count,
00300                 local->dot11FrameDuplicateCount);
00301         DEBUGFS_STATS_ADD(received_fragment_count,
00302                 local->dot11ReceivedFragmentCount);
00303         DEBUGFS_STATS_ADD(multicast_received_frame_count,
00304                 local->dot11MulticastReceivedFrameCount);
00305         DEBUGFS_STATS_ADD(transmitted_frame_count,
00306                 local->dot11TransmittedFrameCount);
00307 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
00308         DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
00309         DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
00310         DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
00311                 local->tx_handlers_drop_unencrypted);
00312         DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
00313                 local->tx_handlers_drop_fragment);
00314         DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
00315                 local->tx_handlers_drop_wep);
00316         DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
00317                 local->tx_handlers_drop_not_assoc);
00318         DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
00319                 local->tx_handlers_drop_unauth_port);
00320         DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
00321         DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
00322         DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
00323                 local->rx_handlers_drop_nullfunc);
00324         DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
00325                 local->rx_handlers_drop_defrag);
00326         DEBUGFS_STATS_ADD(rx_handlers_drop_short,
00327                 local->rx_handlers_drop_short);
00328         DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan,
00329                 local->rx_handlers_drop_passive_scan);
00330         DEBUGFS_STATS_ADD(tx_expand_skb_head,
00331                 local->tx_expand_skb_head);
00332         DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
00333                 local->tx_expand_skb_head_cloned);
00334         DEBUGFS_STATS_ADD(rx_expand_skb_head,
00335                 local->rx_expand_skb_head);
00336         DEBUGFS_STATS_ADD(rx_expand_skb_head2,
00337                 local->rx_expand_skb_head2);
00338         DEBUGFS_STATS_ADD(rx_handlers_fragments,
00339                 local->rx_handlers_fragments);
00340         DEBUGFS_STATS_ADD(tx_status_drop,
00341                 local->tx_status_drop);
00342 #endif
00343         DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
00344         DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
00345         DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
00346         DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
00347 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:09