debugfs_sta.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2003-2005  Devicescape Software, Inc.
00003  * Copyright (c) 2006   Jiri Benc <jbenc@suse.cz>
00004  * Copyright 2007       Johannes Berg <johannes@sipsolutions.net>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License version 2 as
00008  * published by the Free Software Foundation.
00009  */
00010 
00011 #include <linux/debugfs.h>
00012 #include <linux/ieee80211.h>
00013 #include "ieee80211_i.h"
00014 #include "debugfs.h"
00015 #include "debugfs_sta.h"
00016 #include "sta_info.h"
00017 
00018 /* sta attributtes */
00019 
00020 #define STA_READ(name, field, format_string)                            \
00021 static ssize_t sta_ ##name## _read(struct file *file,                   \
00022                                    char __user *userbuf,                \
00023                                    size_t count, loff_t *ppos)          \
00024 {                                                                       \
00025         struct sta_info *sta = file->private_data;                      \
00026         return mac80211_format_buffer(userbuf, count, ppos,             \
00027                                       format_string, sta->field);       \
00028 }
00029 #define STA_READ_D(name, field) STA_READ(name, field, "%d\n")
00030 #define STA_READ_U(name, field) STA_READ(name, field, "%u\n")
00031 #define STA_READ_S(name, field) STA_READ(name, field, "%s\n")
00032 
00033 #define STA_OPS(name)                                                   \
00034 static const struct file_operations sta_ ##name## _ops = {              \
00035         .read = sta_##name##_read,                                      \
00036         .open = mac80211_open_file_generic,                             \
00037         .llseek = generic_file_llseek,                                  \
00038 }
00039 
00040 #define STA_OPS_RW(name)                                                \
00041 static const struct file_operations sta_ ##name## _ops = {              \
00042         .read = sta_##name##_read,                                      \
00043         .write = sta_##name##_write,                                    \
00044         .open = mac80211_open_file_generic,                             \
00045         .llseek = generic_file_llseek,                                  \
00046 }
00047 
00048 #define STA_FILE(name, field, format)                                   \
00049                 STA_READ_##format(name, field)                          \
00050                 STA_OPS(name)
00051 
00052 STA_FILE(aid, sta.aid, D);
00053 STA_FILE(dev, sdata->name, S);
00054 STA_FILE(last_signal, last_signal, D);
00055 
00056 static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
00057                               size_t count, loff_t *ppos)
00058 {
00059         char buf[121];
00060         struct sta_info *sta = file->private_data;
00061 
00062 #define TEST(flg) \
00063         test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
00064 
00065         int res = scnprintf(buf, sizeof(buf),
00066                             "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
00067                             TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
00068                             TEST(PS_DRIVER), TEST(AUTHORIZED),
00069                             TEST(SHORT_PREAMBLE), TEST(ASSOC_AP),
00070                             TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
00071                             TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
00072                             TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
00073                             TEST(TDLS_PEER_AUTH));
00074 #undef TEST
00075         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
00076 }
00077 STA_OPS(flags);
00078 
00079 static ssize_t sta_num_ps_buf_frames_read(struct file *file,
00080                                           char __user *userbuf,
00081                                           size_t count, loff_t *ppos)
00082 {
00083         struct sta_info *sta = file->private_data;
00084         char buf[17*IEEE80211_NUM_ACS], *p = buf;
00085         int ac;
00086 
00087         for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
00088                 p += scnprintf(p, sizeof(buf)+buf-p, "AC%d: %d\n", ac,
00089                                skb_queue_len(&sta->ps_tx_buf[ac]) +
00090                                skb_queue_len(&sta->tx_filtered[ac]));
00091         return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
00092 }
00093 STA_OPS(num_ps_buf_frames);
00094 
00095 static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
00096                                     size_t count, loff_t *ppos)
00097 {
00098         struct sta_info *sta = file->private_data;
00099         return mac80211_format_buffer(userbuf, count, ppos, "%d\n",
00100                                       jiffies_to_msecs(jiffies - sta->last_rx));
00101 }
00102 STA_OPS(inactive_ms);
00103 
00104 
00105 static ssize_t sta_connected_time_read(struct file *file, char __user *userbuf,
00106                                         size_t count, loff_t *ppos)
00107 {
00108         struct sta_info *sta = file->private_data;
00109         struct timespec uptime;
00110         struct tm result;
00111         long connected_time_secs;
00112         char buf[100];
00113         int res;
00114         do_posix_clock_monotonic_gettime(&uptime);
00115         connected_time_secs = uptime.tv_sec - sta->last_connected;
00116         time_to_tm(connected_time_secs, 0, &result);
00117         result.tm_year -= 70;
00118         result.tm_mday -= 1;
00119         res = scnprintf(buf, sizeof(buf),
00120                 "years  - %ld\nmonths - %d\ndays   - %d\nclock  - %d:%d:%d\n\n",
00121                         result.tm_year, result.tm_mon, result.tm_mday,
00122                         result.tm_hour, result.tm_min, result.tm_sec);
00123         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
00124 }
00125 STA_OPS(connected_time);
00126 
00127 
00128 
00129 static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
00130                                       size_t count, loff_t *ppos)
00131 {
00132         char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
00133         int i;
00134         struct sta_info *sta = file->private_data;
00135         for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
00136                 p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
00137                                le16_to_cpu(sta->last_seq_ctrl[i]));
00138         p += scnprintf(p, sizeof(buf)+buf-p, "\n");
00139         return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
00140 }
00141 STA_OPS(last_seq_ctrl);
00142 
00143 static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
00144                                         size_t count, loff_t *ppos)
00145 {
00146         char buf[71 + STA_TID_NUM * 40], *p = buf;
00147         int i;
00148         struct sta_info *sta = file->private_data;
00149         struct tid_ampdu_rx *tid_rx;
00150         struct tid_ampdu_tx *tid_tx;
00151 
00152         rcu_read_lock();
00153 
00154         p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
00155                         sta->ampdu_mlme.dialog_token_allocator + 1);
00156         p += scnprintf(p, sizeof(buf) + buf - p,
00157                        "TID\t\tRX active\tDTKN\tSSN\t\tTX\tDTKN\tpending\n");
00158 
00159         for (i = 0; i < STA_TID_NUM; i++) {
00160                 tid_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[i]);
00161                 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[i]);
00162 
00163                 p += scnprintf(p, sizeof(buf) + buf - p, "%02d", i);
00164                 p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_rx);
00165                 p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
00166                                 tid_rx ? tid_rx->dialog_token : 0);
00167                 p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.3x",
00168                                 tid_rx ? tid_rx->ssn : 0);
00169 
00170                 p += scnprintf(p, sizeof(buf) + buf - p, "\t\t%x", !!tid_tx);
00171                 p += scnprintf(p, sizeof(buf) + buf - p, "\t%#.2x",
00172                                 tid_tx ? tid_tx->dialog_token : 0);
00173                 p += scnprintf(p, sizeof(buf) + buf - p, "\t%03d",
00174                                 tid_tx ? skb_queue_len(&tid_tx->pending) : 0);
00175                 p += scnprintf(p, sizeof(buf) + buf - p, "\n");
00176         }
00177         rcu_read_unlock();
00178 
00179         return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
00180 }
00181 
00182 static ssize_t sta_agg_status_write(struct file *file, const char __user *userbuf,
00183                                     size_t count, loff_t *ppos)
00184 {
00185         char _buf[12], *buf = _buf;
00186         struct sta_info *sta = file->private_data;
00187         bool start, tx;
00188         unsigned long tid;
00189         int ret;
00190 
00191         if (count > sizeof(_buf))
00192                 return -EINVAL;
00193 
00194         if (copy_from_user(buf, userbuf, count))
00195                 return -EFAULT;
00196 
00197         buf[sizeof(_buf) - 1] = '\0';
00198 
00199         if (strncmp(buf, "tx ", 3) == 0) {
00200                 buf += 3;
00201                 tx = true;
00202         } else if (strncmp(buf, "rx ", 3) == 0) {
00203                 buf += 3;
00204                 tx = false;
00205         } else
00206                 return -EINVAL;
00207 
00208         if (strncmp(buf, "start ", 6) == 0) {
00209                 buf += 6;
00210                 start = true;
00211                 if (!tx)
00212                         return -EINVAL;
00213         } else if (strncmp(buf, "stop ", 5) == 0) {
00214                 buf += 5;
00215                 start = false;
00216         } else
00217                 return -EINVAL;
00218 
00219         tid = simple_strtoul(buf, NULL, 0);
00220 
00221         if (tid >= STA_TID_NUM)
00222                 return -EINVAL;
00223 
00224         if (tx) {
00225                 if (start)
00226                         ret = ieee80211_start_tx_ba_session(&sta->sta, tid, 5000);
00227                 else
00228                         ret = ieee80211_stop_tx_ba_session(&sta->sta, tid);
00229         } else {
00230                 __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
00231                                                3, true);
00232                 ret = 0;
00233         }
00234 
00235         return ret ?: count;
00236 }
00237 STA_OPS_RW(agg_status);
00238 
00239 static ssize_t sta_ht_capa_read(struct file *file, char __user *userbuf,
00240                                 size_t count, loff_t *ppos)
00241 {
00242 #define PRINT_HT_CAP(_cond, _str) \
00243         do { \
00244         if (_cond) \
00245                         p += scnprintf(p, sizeof(buf)+buf-p, "\t" _str "\n"); \
00246         } while (0)
00247         char buf[512], *p = buf;
00248         int i;
00249         struct sta_info *sta = file->private_data;
00250         struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
00251 
00252         p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
00253                         htc->ht_supported ? "" : "not ");
00254         if (htc->ht_supported) {
00255                 p += scnprintf(p, sizeof(buf)+buf-p, "cap: %#.4x\n", htc->cap);
00256 
00257                 PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDPC");
00258                 PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
00259                 PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
00260 
00261                 PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
00262                 PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
00263                 PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
00264 
00265                 PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
00266                 PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
00267                 PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
00268                 PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
00269 
00270                 PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
00271                 PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
00272                 PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
00273                 PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
00274 
00275                 PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
00276 
00277                 PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: "
00278                              "3839 bytes");
00279                 PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: "
00280                              "7935 bytes");
00281 
00282                 /*
00283                  * For beacons and probe response this would mean the BSS
00284                  * does or does not allow the usage of DSSS/CCK HT40.
00285                  * Otherwise it means the STA does or does not use
00286                  * DSSS/CCK HT40.
00287                  */
00288                 PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
00289                 PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
00290 
00291                 /* BIT(13) is reserved */
00292 
00293                 PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
00294 
00295                 PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
00296 
00297                 p += scnprintf(p, sizeof(buf)+buf-p, "ampdu factor/density: %d/%d\n",
00298                                 htc->ampdu_factor, htc->ampdu_density);
00299                 p += scnprintf(p, sizeof(buf)+buf-p, "MCS mask:");
00300 
00301                 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
00302                         p += scnprintf(p, sizeof(buf)+buf-p, " %.2x",
00303                                         htc->mcs.rx_mask[i]);
00304                 p += scnprintf(p, sizeof(buf)+buf-p, "\n");
00305 
00306                 /* If not set this is meaningless */
00307                 if (le16_to_cpu(htc->mcs.rx_highest)) {
00308                         p += scnprintf(p, sizeof(buf)+buf-p,
00309                                        "MCS rx highest: %d Mbps\n",
00310                                        le16_to_cpu(htc->mcs.rx_highest));
00311                 }
00312 
00313                 p += scnprintf(p, sizeof(buf)+buf-p, "MCS tx params: %x\n",
00314                                 htc->mcs.tx_params);
00315         }
00316 
00317         return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
00318 }
00319 STA_OPS(ht_capa);
00320 
00321 #define DEBUGFS_ADD(name) \
00322         debugfs_create_file(#name, 0400, \
00323                 sta->debugfs.dir, sta, &sta_ ##name## _ops);
00324 
00325 #define DEBUGFS_ADD_COUNTER(name, field)                                \
00326         if (sizeof(sta->field) == sizeof(u32))                          \
00327                 debugfs_create_u32(#name, 0400, sta->debugfs.dir,       \
00328                         (u32 *) &sta->field);                           \
00329         else                                                            \
00330                 debugfs_create_u64(#name, 0400, sta->debugfs.dir,       \
00331                         (u64 *) &sta->field);
00332 
00333 void ieee80211_sta_debugfs_add(struct sta_info *sta)
00334 {
00335         struct dentry *stations_dir = sta->sdata->debugfs.subdir_stations;
00336         u8 mac[3*ETH_ALEN];
00337 
00338         sta->debugfs.add_has_run = true;
00339 
00340         if (!stations_dir)
00341                 return;
00342 
00343         snprintf(mac, sizeof(mac), "%pM", sta->sta.addr);
00344 
00345         /*
00346          * This might fail due to a race condition:
00347          * When mac80211 unlinks a station, the debugfs entries
00348          * remain, but it is already possible to link a new
00349          * station with the same address which triggers adding
00350          * it to debugfs; therefore, if the old station isn't
00351          * destroyed quickly enough the old station's debugfs
00352          * dir might still be around.
00353          */
00354         sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
00355         if (!sta->debugfs.dir)
00356                 return;
00357 
00358         DEBUGFS_ADD(flags);
00359         DEBUGFS_ADD(num_ps_buf_frames);
00360         DEBUGFS_ADD(inactive_ms);
00361         DEBUGFS_ADD(connected_time);
00362         DEBUGFS_ADD(last_seq_ctrl);
00363         DEBUGFS_ADD(agg_status);
00364         DEBUGFS_ADD(dev);
00365         DEBUGFS_ADD(last_signal);
00366         DEBUGFS_ADD(ht_capa);
00367 
00368         DEBUGFS_ADD_COUNTER(rx_packets, rx_packets);
00369         DEBUGFS_ADD_COUNTER(tx_packets, tx_packets);
00370         DEBUGFS_ADD_COUNTER(rx_bytes, rx_bytes);
00371         DEBUGFS_ADD_COUNTER(tx_bytes, tx_bytes);
00372         DEBUGFS_ADD_COUNTER(rx_duplicates, num_duplicates);
00373         DEBUGFS_ADD_COUNTER(rx_fragments, rx_fragments);
00374         DEBUGFS_ADD_COUNTER(rx_dropped, rx_dropped);
00375         DEBUGFS_ADD_COUNTER(tx_fragments, tx_fragments);
00376         DEBUGFS_ADD_COUNTER(tx_filtered, tx_filtered_count);
00377         DEBUGFS_ADD_COUNTER(tx_retry_failed, tx_retry_failed);
00378         DEBUGFS_ADD_COUNTER(tx_retry_count, tx_retry_count);
00379         DEBUGFS_ADD_COUNTER(wep_weak_iv_count, wep_weak_iv_count);
00380 }
00381 
00382 void ieee80211_sta_debugfs_remove(struct sta_info *sta)
00383 {
00384         debugfs_remove_recursive(sta->debugfs.dir);
00385         sta->debugfs.dir = NULL;
00386 }


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