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 int mac80211_open_file_generic(struct inode *inode, struct file *file)
00019 {
00020         file->private_data = inode->i_private;
00021         return 0;
00022 }
00023 
00024 #define DEBUGFS_FORMAT_BUFFER_SIZE 100
00025 
00026 int mac80211_format_buffer(char __user *userbuf, size_t count,
00027                                   loff_t *ppos, char *fmt, ...)
00028 {
00029         va_list args;
00030         char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
00031         int res;
00032 
00033         va_start(args, fmt);
00034         res = vscnprintf(buf, sizeof(buf), fmt, args);
00035         va_end(args);
00036 
00037         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
00038 }
00039 
00040 #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...)                   \
00041 static ssize_t name## _read(struct file *file, char __user *userbuf,    \
00042                             size_t count, loff_t *ppos)                 \
00043 {                                                                       \
00044         struct ieee80211_local *local = file->private_data;             \
00045                                                                         \
00046         return mac80211_format_buffer(userbuf, count, ppos,             \
00047                                       fmt "\n", ##value);               \
00048 }
00049 
00050 #define DEBUGFS_READONLY_FILE_OPS(name)                 \
00051 static const struct file_operations name## _ops = {                     \
00052         .read = name## _read,                                           \
00053         .open = mac80211_open_file_generic,                             \
00054         .llseek = generic_file_llseek,                                  \
00055 };
00056 
00057 #define DEBUGFS_READONLY_FILE(name, fmt, value...)              \
00058         DEBUGFS_READONLY_FILE_FN(name, fmt, value)              \
00059         DEBUGFS_READONLY_FILE_OPS(name)
00060 
00061 #define DEBUGFS_ADD(name)                                               \
00062         debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
00063 
00064 #define DEBUGFS_ADD_MODE(name, mode)                                    \
00065         debugfs_create_file(#name, mode, phyd, local, &name## _ops);
00066 
00067 
00068 DEBUGFS_READONLY_FILE(user_power, "%d",
00069                       local->user_power_level);
00070 DEBUGFS_READONLY_FILE(power, "%d",
00071                       local->hw.conf.power_level);
00072 DEBUGFS_READONLY_FILE(frequency, "%d",
00073                       local->hw.conf.channel->center_freq);
00074 DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
00075                       local->total_ps_buffered);
00076 DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
00077                       local->wep_iv & 0xffffff);
00078 DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
00079         local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
00080 
00081 static ssize_t reset_write(struct file *file, const char __user *user_buf,
00082                            size_t count, loff_t *ppos)
00083 {
00084         struct ieee80211_local *local = file->private_data;
00085 
00086         rtnl_lock();
00087         __ieee80211_suspend(&local->hw, NULL);
00088         __ieee80211_resume(&local->hw);
00089         rtnl_unlock();
00090 
00091         return count;
00092 }
00093 
00094 static const struct file_operations reset_ops = {
00095         .write = reset_write,
00096         .open = mac80211_open_file_generic,
00097         .llseek = noop_llseek,
00098 };
00099 
00100 static ssize_t noack_read(struct file *file, char __user *user_buf,
00101                           size_t count, loff_t *ppos)
00102 {
00103         struct ieee80211_local *local = file->private_data;
00104 
00105         return mac80211_format_buffer(user_buf, count, ppos, "%d\n",
00106                                       local->wifi_wme_noack_test);
00107 }
00108 
00109 static ssize_t noack_write(struct file *file,
00110                            const char __user *user_buf,
00111                            size_t count, loff_t *ppos)
00112 {
00113         struct ieee80211_local *local = file->private_data;
00114         char buf[10];
00115         size_t len;
00116 
00117         len = min(count, sizeof(buf) - 1);
00118         if (copy_from_user(buf, user_buf, len))
00119                 return -EFAULT;
00120         buf[len] = '\0';
00121 
00122         local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
00123 
00124         return count;
00125 }
00126 
00127 static const struct file_operations noack_ops = {
00128         .read = noack_read,
00129         .write = noack_write,
00130         .open = mac80211_open_file_generic,
00131         .llseek = default_llseek,
00132 };
00133 
00134 static ssize_t uapsd_queues_read(struct file *file, char __user *user_buf,
00135                                  size_t count, loff_t *ppos)
00136 {
00137         struct ieee80211_local *local = file->private_data;
00138         return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
00139                                       local->uapsd_queues);
00140 }
00141 
00142 static ssize_t uapsd_queues_write(struct file *file,
00143                                   const char __user *user_buf,
00144                                   size_t count, loff_t *ppos)
00145 {
00146         struct ieee80211_local *local = file->private_data;
00147         u8 val;
00148         int ret;
00149 
00150         ret = kstrtou8_from_user(user_buf, count, 0, &val);
00151         if (ret)
00152                 return ret;
00153 
00154         if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
00155                 return -ERANGE;
00156 
00157         local->uapsd_queues = val;
00158 
00159         return count;
00160 }
00161 
00162 static const struct file_operations uapsd_queues_ops = {
00163         .read = uapsd_queues_read,
00164         .write = uapsd_queues_write,
00165         .open = mac80211_open_file_generic,
00166         .llseek = default_llseek,
00167 };
00168 
00169 static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf,
00170                                      size_t count, loff_t *ppos)
00171 {
00172         struct ieee80211_local *local = file->private_data;
00173 
00174         return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
00175                                       local->uapsd_max_sp_len);
00176 }
00177 
00178 static ssize_t uapsd_max_sp_len_write(struct file *file,
00179                                       const char __user *user_buf,
00180                                       size_t count, loff_t *ppos)
00181 {
00182         struct ieee80211_local *local = file->private_data;
00183         unsigned long val;
00184         char buf[10];
00185         size_t len;
00186         int ret;
00187 
00188         len = min(count, sizeof(buf) - 1);
00189         if (copy_from_user(buf, user_buf, len))
00190                 return -EFAULT;
00191         buf[len] = '\0';
00192 
00193         ret = strict_strtoul(buf, 0, &val);
00194 
00195         if (ret)
00196                 return -EINVAL;
00197 
00198         if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
00199                 return -ERANGE;
00200 
00201         local->uapsd_max_sp_len = val;
00202 
00203         return count;
00204 }
00205 
00206 static const struct file_operations uapsd_max_sp_len_ops = {
00207         .read = uapsd_max_sp_len_read,
00208         .write = uapsd_max_sp_len_write,
00209         .open = mac80211_open_file_generic,
00210         .llseek = default_llseek,
00211 };
00212 
00213 static ssize_t channel_type_read(struct file *file, char __user *user_buf,
00214                        size_t count, loff_t *ppos)
00215 {
00216         struct ieee80211_local *local = file->private_data;
00217         const char *buf;
00218 
00219         switch (local->hw.conf.channel_type) {
00220         case NL80211_CHAN_NO_HT:
00221                 buf = "no ht\n";
00222                 break;
00223         case NL80211_CHAN_HT20:
00224                 buf = "ht20\n";
00225                 break;
00226         case NL80211_CHAN_HT40MINUS:
00227                 buf = "ht40-\n";
00228                 break;
00229         case NL80211_CHAN_HT40PLUS:
00230                 buf = "ht40+\n";
00231                 break;
00232         default:
00233                 buf = "???";
00234                 break;
00235         }
00236 
00237         return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
00238 }
00239 
00240 static ssize_t hwflags_read(struct file *file, char __user *user_buf,
00241                             size_t count, loff_t *ppos)
00242 {
00243         struct ieee80211_local *local = file->private_data;
00244         int mxln = 500;
00245         ssize_t rv;
00246         char *buf = kzalloc(mxln, GFP_KERNEL);
00247         int sf = 0; /* how many written so far */
00248 
00249         if (!buf)
00250                 return 0;
00251 
00252         sf += snprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
00253         if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
00254                 sf += snprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
00255         if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
00256                 sf += snprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
00257         if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
00258                 sf += snprintf(buf + sf, mxln - sf,
00259                                "HOST_BCAST_PS_BUFFERING\n");
00260         if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
00261                 sf += snprintf(buf + sf, mxln - sf,
00262                                "2GHZ_SHORT_SLOT_INCAPABLE\n");
00263         if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
00264                 sf += snprintf(buf + sf, mxln - sf,
00265                                "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
00266         if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
00267                 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
00268         if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
00269                 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
00270         if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
00271                 sf += snprintf(buf + sf, mxln - sf, "NEED_DTIM_PERIOD\n");
00272         if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
00273                 sf += snprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
00274         if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
00275                 sf += snprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
00276         if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
00277                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
00278         if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
00279                 sf += snprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
00280         if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
00281                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
00282         if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
00283                 sf += snprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
00284         if (local->hw.flags & IEEE80211_HW_BEACON_FILTER)
00285                 sf += snprintf(buf + sf, mxln - sf, "BEACON_FILTER\n");
00286         if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS)
00287                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n");
00288         if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
00289                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_SMPS\n");
00290         if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
00291                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n");
00292         if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
00293                 sf += snprintf(buf + sf, mxln - sf, "REPORTS_TX_ACK_STATUS\n");
00294         if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
00295                 sf += snprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
00296         if (local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)
00297                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_CQM_RSSI\n");
00298         if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
00299                 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
00300         if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
00301                 sf += snprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
00302         if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
00303                 sf += snprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
00304 
00305         rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
00306         kfree(buf);
00307         return rv;
00308 }
00309 
00310 static ssize_t queues_read(struct file *file, char __user *user_buf,
00311                            size_t count, loff_t *ppos)
00312 {
00313         struct ieee80211_local *local = file->private_data;
00314         unsigned long flags;
00315         char buf[IEEE80211_MAX_QUEUES * 20];
00316         int q, res = 0;
00317 
00318         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
00319         for (q = 0; q < local->hw.queues; q++)
00320                 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
00321                                 local->queue_stop_reasons[q],
00322                                 skb_queue_len(&local->pending[q]));
00323         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
00324 
00325         return simple_read_from_buffer(user_buf, count, ppos, buf, res);
00326 }
00327 
00328 DEBUGFS_READONLY_FILE_OPS(hwflags);
00329 DEBUGFS_READONLY_FILE_OPS(channel_type);
00330 DEBUGFS_READONLY_FILE_OPS(queues);
00331 
00332 /* statistics stuff */
00333 
00334 static ssize_t format_devstat_counter(struct ieee80211_local *local,
00335         char __user *userbuf,
00336         size_t count, loff_t *ppos,
00337         int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
00338                           int buflen))
00339 {
00340         struct ieee80211_low_level_stats stats;
00341         char buf[20];
00342         int res;
00343 
00344         rtnl_lock();
00345         res = drv_get_stats(local, &stats);
00346         rtnl_unlock();
00347         if (res)
00348                 return res;
00349         res = printvalue(&stats, buf, sizeof(buf));
00350         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
00351 }
00352 
00353 #define DEBUGFS_DEVSTATS_FILE(name)                                     \
00354 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
00355                                  char *buf, int buflen)                 \
00356 {                                                                       \
00357         return scnprintf(buf, buflen, "%u\n", stats->name);             \
00358 }                                                                       \
00359 static ssize_t stats_ ##name## _read(struct file *file,                 \
00360                                      char __user *userbuf,              \
00361                                      size_t count, loff_t *ppos)        \
00362 {                                                                       \
00363         return format_devstat_counter(file->private_data,               \
00364                                       userbuf,                          \
00365                                       count,                            \
00366                                       ppos,                             \
00367                                       print_devstats_##name);           \
00368 }                                                                       \
00369                                                                         \
00370 static const struct file_operations stats_ ##name## _ops = {            \
00371         .read = stats_ ##name## _read,                                  \
00372         .open = mac80211_open_file_generic,                             \
00373         .llseek = generic_file_llseek,                                  \
00374 };
00375 
00376 #define DEBUGFS_STATS_ADD(name, field)                                  \
00377         debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
00378 #define DEBUGFS_DEVSTATS_ADD(name)                                      \
00379         debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
00380 
00381 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
00382 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
00383 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
00384 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
00385 
00386 void debugfs_hw_add(struct ieee80211_local *local)
00387 {
00388         struct dentry *phyd = local->hw.wiphy->debugfsdir;
00389         struct dentry *statsd;
00390 
00391         if (!phyd)
00392                 return;
00393 
00394         local->debugfs.keys = debugfs_create_dir("keys", phyd);
00395 
00396         DEBUGFS_ADD(frequency);
00397         DEBUGFS_ADD(total_ps_buffered);
00398         DEBUGFS_ADD(wep_iv);
00399         DEBUGFS_ADD(queues);
00400         DEBUGFS_ADD_MODE(reset, 0200);
00401         DEBUGFS_ADD(noack);
00402         DEBUGFS_ADD(uapsd_queues);
00403         DEBUGFS_ADD(uapsd_max_sp_len);
00404         DEBUGFS_ADD(channel_type);
00405         DEBUGFS_ADD(hwflags);
00406         DEBUGFS_ADD(user_power);
00407         DEBUGFS_ADD(power);
00408 
00409         statsd = debugfs_create_dir("statistics", phyd);
00410 
00411         /* if the dir failed, don't put all the other things into the root! */
00412         if (!statsd)
00413                 return;
00414 
00415         DEBUGFS_STATS_ADD(transmitted_fragment_count,
00416                 local->dot11TransmittedFragmentCount);
00417         DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
00418                 local->dot11MulticastTransmittedFrameCount);
00419         DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
00420         DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
00421         DEBUGFS_STATS_ADD(multiple_retry_count,
00422                 local->dot11MultipleRetryCount);
00423         DEBUGFS_STATS_ADD(frame_duplicate_count,
00424                 local->dot11FrameDuplicateCount);
00425         DEBUGFS_STATS_ADD(received_fragment_count,
00426                 local->dot11ReceivedFragmentCount);
00427         DEBUGFS_STATS_ADD(multicast_received_frame_count,
00428                 local->dot11MulticastReceivedFrameCount);
00429         DEBUGFS_STATS_ADD(transmitted_frame_count,
00430                 local->dot11TransmittedFrameCount);
00431 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
00432         DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
00433         DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
00434         DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
00435                 local->tx_handlers_drop_unencrypted);
00436         DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
00437                 local->tx_handlers_drop_fragment);
00438         DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
00439                 local->tx_handlers_drop_wep);
00440         DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
00441                 local->tx_handlers_drop_not_assoc);
00442         DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
00443                 local->tx_handlers_drop_unauth_port);
00444         DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
00445         DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
00446         DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
00447                 local->rx_handlers_drop_nullfunc);
00448         DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
00449                 local->rx_handlers_drop_defrag);
00450         DEBUGFS_STATS_ADD(rx_handlers_drop_short,
00451                 local->rx_handlers_drop_short);
00452         DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan,
00453                 local->rx_handlers_drop_passive_scan);
00454         DEBUGFS_STATS_ADD(tx_expand_skb_head,
00455                 local->tx_expand_skb_head);
00456         DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
00457                 local->tx_expand_skb_head_cloned);
00458         DEBUGFS_STATS_ADD(rx_expand_skb_head,
00459                 local->rx_expand_skb_head);
00460         DEBUGFS_STATS_ADD(rx_expand_skb_head2,
00461                 local->rx_expand_skb_head2);
00462         DEBUGFS_STATS_ADD(rx_handlers_fragments,
00463                 local->rx_handlers_fragments);
00464         DEBUGFS_STATS_ADD(tx_status_drop,
00465                 local->tx_status_drop);
00466 #endif
00467         DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
00468         DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
00469         DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
00470         DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
00471 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:54