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


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