Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> |
| 3 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/device.h> |
| 12 | #include <linux/if.h> |
| 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/notifier.h> |
| 17 | #include <net/mac80211.h> |
| 18 | #include <net/cfg80211.h> |
| 19 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 20 | #include "rate.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 21 | #include "debugfs.h" |
| 22 | #include "debugfs_netdev.h" |
| 23 | |
| 24 | static ssize_t ieee80211_if_read( |
| 25 | struct ieee80211_sub_if_data *sdata, |
| 26 | char __user *userbuf, |
| 27 | size_t count, loff_t *ppos, |
| 28 | ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int)) |
| 29 | { |
| 30 | char buf[70]; |
| 31 | ssize_t ret = -EINVAL; |
| 32 | |
| 33 | read_lock(&dev_base_lock); |
Luis Carlos Cobo | 73bb3e4 | 2008-03-31 15:10:22 -0700 | [diff] [blame] | 34 | if (sdata->dev->reg_state == NETREG_REGISTERED) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 35 | ret = (*format)(sdata, buf, sizeof(buf)); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 36 | read_unlock(&dev_base_lock); |
Luis Carlos Cobo | 73bb3e4 | 2008-03-31 15:10:22 -0700 | [diff] [blame] | 37 | |
| 38 | if (ret != -EINVAL) |
| 39 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 40 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | #define IEEE80211_IF_FMT(name, field, format_string) \ |
| 45 | static ssize_t ieee80211_if_fmt_##name( \ |
| 46 | const struct ieee80211_sub_if_data *sdata, char *buf, \ |
| 47 | int buflen) \ |
| 48 | { \ |
| 49 | return scnprintf(buf, buflen, format_string, sdata->field); \ |
| 50 | } |
| 51 | #define IEEE80211_IF_FMT_DEC(name, field) \ |
| 52 | IEEE80211_IF_FMT(name, field, "%d\n") |
| 53 | #define IEEE80211_IF_FMT_HEX(name, field) \ |
| 54 | IEEE80211_IF_FMT(name, field, "%#x\n") |
| 55 | #define IEEE80211_IF_FMT_SIZE(name, field) \ |
| 56 | IEEE80211_IF_FMT(name, field, "%zd\n") |
| 57 | |
| 58 | #define IEEE80211_IF_FMT_ATOMIC(name, field) \ |
| 59 | static ssize_t ieee80211_if_fmt_##name( \ |
| 60 | const struct ieee80211_sub_if_data *sdata, \ |
| 61 | char *buf, int buflen) \ |
| 62 | { \ |
| 63 | return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\ |
| 64 | } |
| 65 | |
| 66 | #define IEEE80211_IF_FMT_MAC(name, field) \ |
| 67 | static ssize_t ieee80211_if_fmt_##name( \ |
| 68 | const struct ieee80211_sub_if_data *sdata, char *buf, \ |
| 69 | int buflen) \ |
| 70 | { \ |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 71 | return scnprintf(buf, buflen, "%pM\n", sdata->field); \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | #define __IEEE80211_IF_FILE(name) \ |
| 75 | static ssize_t ieee80211_if_read_##name(struct file *file, \ |
| 76 | char __user *userbuf, \ |
| 77 | size_t count, loff_t *ppos) \ |
| 78 | { \ |
| 79 | return ieee80211_if_read(file->private_data, \ |
| 80 | userbuf, count, ppos, \ |
| 81 | ieee80211_if_fmt_##name); \ |
| 82 | } \ |
| 83 | static const struct file_operations name##_ops = { \ |
| 84 | .read = ieee80211_if_read_##name, \ |
| 85 | .open = mac80211_open_file_generic, \ |
| 86 | } |
| 87 | |
| 88 | #define IEEE80211_IF_FILE(name, field, format) \ |
| 89 | IEEE80211_IF_FMT_##format(name, field) \ |
| 90 | __IEEE80211_IF_FILE(name) |
| 91 | |
| 92 | /* common attributes */ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 93 | IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 94 | IEEE80211_IF_FILE(force_unicast_rateidx, force_unicast_rateidx, DEC); |
| 95 | IEEE80211_IF_FILE(max_ratectrl_rateidx, max_ratectrl_rateidx, DEC); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 96 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 97 | /* STA attributes */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 98 | IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 99 | IEEE80211_IF_FILE(aid, u.mgd.aid, DEC); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 100 | IEEE80211_IF_FILE(capab, u.mgd.capab, HEX); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 101 | |
| 102 | /* AP attributes */ |
| 103 | IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 104 | IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 105 | |
| 106 | static ssize_t ieee80211_if_fmt_num_buffered_multicast( |
| 107 | const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) |
| 108 | { |
| 109 | return scnprintf(buf, buflen, "%u\n", |
| 110 | skb_queue_len(&sdata->u.ap.ps_bc_buf)); |
| 111 | } |
| 112 | __IEEE80211_IF_FILE(num_buffered_multicast); |
| 113 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 114 | /* WDS attributes */ |
| 115 | IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC); |
| 116 | |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 117 | #ifdef CONFIG_MAC80211_MESH |
| 118 | /* Mesh stats attributes */ |
Daniel Walker | c8a61a7 | 2009-08-18 10:59:00 -0700 | [diff] [blame] | 119 | IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC); |
| 120 | IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 121 | IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC); |
| 122 | IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC); |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 123 | IEEE80211_IF_FILE(dropped_frames_no_route, |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 124 | u.mesh.mshstats.dropped_frames_no_route, DEC); |
| 125 | IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC); |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 126 | |
| 127 | /* Mesh parameters */ |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 128 | IEEE80211_IF_FILE(dot11MeshMaxRetries, |
| 129 | u.mesh.mshcfg.dot11MeshMaxRetries, DEC); |
| 130 | IEEE80211_IF_FILE(dot11MeshRetryTimeout, |
| 131 | u.mesh.mshcfg.dot11MeshRetryTimeout, DEC); |
| 132 | IEEE80211_IF_FILE(dot11MeshConfirmTimeout, |
| 133 | u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC); |
| 134 | IEEE80211_IF_FILE(dot11MeshHoldingTimeout, |
| 135 | u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC); |
| 136 | IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC); |
| 137 | IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC); |
| 138 | IEEE80211_IF_FILE(dot11MeshMaxPeerLinks, |
| 139 | u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC); |
| 140 | IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout, |
| 141 | u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC); |
| 142 | IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval, |
| 143 | u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC); |
| 144 | IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime, |
| 145 | u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC); |
| 146 | IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries, |
| 147 | u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC); |
| 148 | IEEE80211_IF_FILE(path_refresh_time, |
| 149 | u.mesh.mshcfg.path_refresh_time, DEC); |
| 150 | IEEE80211_IF_FILE(min_discovery_timeout, |
| 151 | u.mesh.mshcfg.min_discovery_timeout, DEC); |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 152 | #endif |
| 153 | |
| 154 | |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame^] | 155 | #define DEBUGFS_ADD(name, type) \ |
| 156 | debugfs_create_file(#name, 0400, sdata->debugfs.dir, \ |
| 157 | sdata, &name##_ops); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 158 | |
| 159 | static void add_sta_files(struct ieee80211_sub_if_data *sdata) |
| 160 | { |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 161 | DEBUGFS_ADD(drop_unencrypted, sta); |
Jouni Malinen | 93015f0 | 2008-08-25 11:57:06 +0300 | [diff] [blame] | 162 | DEBUGFS_ADD(force_unicast_rateidx, sta); |
| 163 | DEBUGFS_ADD(max_ratectrl_rateidx, sta); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 164 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 165 | DEBUGFS_ADD(bssid, sta); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 166 | DEBUGFS_ADD(aid, sta); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 167 | DEBUGFS_ADD(capab, sta); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | static void add_ap_files(struct ieee80211_sub_if_data *sdata) |
| 171 | { |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 172 | DEBUGFS_ADD(drop_unencrypted, ap); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 173 | DEBUGFS_ADD(force_unicast_rateidx, ap); |
| 174 | DEBUGFS_ADD(max_ratectrl_rateidx, ap); |
| 175 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 176 | DEBUGFS_ADD(num_sta_ps, ap); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 177 | DEBUGFS_ADD(dtim_count, ap); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 178 | DEBUGFS_ADD(num_buffered_multicast, ap); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static void add_wds_files(struct ieee80211_sub_if_data *sdata) |
| 182 | { |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 183 | DEBUGFS_ADD(drop_unencrypted, wds); |
Jouni Malinen | 93015f0 | 2008-08-25 11:57:06 +0300 | [diff] [blame] | 184 | DEBUGFS_ADD(force_unicast_rateidx, wds); |
| 185 | DEBUGFS_ADD(max_ratectrl_rateidx, wds); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 186 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 187 | DEBUGFS_ADD(peer, wds); |
| 188 | } |
| 189 | |
| 190 | static void add_vlan_files(struct ieee80211_sub_if_data *sdata) |
| 191 | { |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 192 | DEBUGFS_ADD(drop_unencrypted, vlan); |
Jouni Malinen | 93015f0 | 2008-08-25 11:57:06 +0300 | [diff] [blame] | 193 | DEBUGFS_ADD(force_unicast_rateidx, vlan); |
| 194 | DEBUGFS_ADD(max_ratectrl_rateidx, vlan); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static void add_monitor_files(struct ieee80211_sub_if_data *sdata) |
| 198 | { |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 201 | #ifdef CONFIG_MAC80211_MESH |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 202 | |
| 203 | static void add_mesh_stats(struct ieee80211_sub_if_data *sdata) |
| 204 | { |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame^] | 205 | struct dentry *dir = debugfs_create_dir("mesh_stats", |
| 206 | sdata->debugfs.dir); |
| 207 | |
| 208 | #define MESHSTATS_ADD(name)\ |
| 209 | debugfs_create_file(#name, 0400, dir, sdata, &name##_ops); |
| 210 | |
Daniel Walker | c8a61a7 | 2009-08-18 10:59:00 -0700 | [diff] [blame] | 211 | MESHSTATS_ADD(fwded_mcast); |
| 212 | MESHSTATS_ADD(fwded_unicast); |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 213 | MESHSTATS_ADD(fwded_frames); |
| 214 | MESHSTATS_ADD(dropped_frames_ttl); |
| 215 | MESHSTATS_ADD(dropped_frames_no_route); |
| 216 | MESHSTATS_ADD(estab_plinks); |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame^] | 217 | #undef MESHSTATS_ADD |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 218 | } |
| 219 | |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 220 | static void add_mesh_config(struct ieee80211_sub_if_data *sdata) |
| 221 | { |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame^] | 222 | struct dentry *dir = debugfs_create_dir("mesh_config", |
| 223 | sdata->debugfs.dir); |
| 224 | |
| 225 | #define MESHPARAMS_ADD(name) \ |
| 226 | debugfs_create_file(#name, 0600, dir, sdata, &name##_ops); |
| 227 | |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 228 | MESHPARAMS_ADD(dot11MeshMaxRetries); |
| 229 | MESHPARAMS_ADD(dot11MeshRetryTimeout); |
| 230 | MESHPARAMS_ADD(dot11MeshConfirmTimeout); |
| 231 | MESHPARAMS_ADD(dot11MeshHoldingTimeout); |
| 232 | MESHPARAMS_ADD(dot11MeshTTL); |
| 233 | MESHPARAMS_ADD(auto_open_plinks); |
| 234 | MESHPARAMS_ADD(dot11MeshMaxPeerLinks); |
| 235 | MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout); |
| 236 | MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval); |
| 237 | MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime); |
| 238 | MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries); |
| 239 | MESHPARAMS_ADD(path_refresh_time); |
| 240 | MESHPARAMS_ADD(min_discovery_timeout); |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame^] | 241 | |
| 242 | #undef MESHPARAMS_ADD |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 243 | } |
| 244 | #endif |
| 245 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 246 | static void add_files(struct ieee80211_sub_if_data *sdata) |
| 247 | { |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame^] | 248 | if (!sdata->debugfs.dir) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 249 | return; |
| 250 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 251 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 252 | case NL80211_IFTYPE_MESH_POINT: |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 253 | #ifdef CONFIG_MAC80211_MESH |
| 254 | add_mesh_stats(sdata); |
| 255 | add_mesh_config(sdata); |
| 256 | #endif |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 257 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 258 | case NL80211_IFTYPE_STATION: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 259 | add_sta_files(sdata); |
| 260 | break; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 261 | case NL80211_IFTYPE_ADHOC: |
| 262 | /* XXX */ |
| 263 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 264 | case NL80211_IFTYPE_AP: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 265 | add_ap_files(sdata); |
| 266 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 267 | case NL80211_IFTYPE_WDS: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 268 | add_wds_files(sdata); |
| 269 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 270 | case NL80211_IFTYPE_MONITOR: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 271 | add_monitor_files(sdata); |
| 272 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 273 | case NL80211_IFTYPE_AP_VLAN: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 274 | add_vlan_files(sdata); |
| 275 | break; |
| 276 | default: |
| 277 | break; |
| 278 | } |
| 279 | } |
| 280 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 281 | static int notif_registered; |
| 282 | |
| 283 | void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata) |
| 284 | { |
| 285 | char buf[10+IFNAMSIZ]; |
| 286 | |
| 287 | if (!notif_registered) |
| 288 | return; |
| 289 | |
| 290 | sprintf(buf, "netdev:%s", sdata->dev->name); |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame^] | 291 | sdata->debugfs.dir = debugfs_create_dir(buf, |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 292 | sdata->local->hw.wiphy->debugfsdir); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 293 | add_files(sdata); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata) |
| 297 | { |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame^] | 298 | if (!sdata->debugfs.dir) |
| 299 | return; |
| 300 | |
| 301 | debugfs_remove_recursive(sdata->debugfs.dir); |
| 302 | sdata->debugfs.dir = NULL; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 305 | static int netdev_notify(struct notifier_block *nb, |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 306 | unsigned long state, |
| 307 | void *ndev) |
| 308 | { |
| 309 | struct net_device *dev = ndev; |
Johannes Berg | 7c8081e | 2007-06-21 18:30:19 +0200 | [diff] [blame] | 310 | struct dentry *dir; |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 311 | struct ieee80211_sub_if_data *sdata; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 312 | char buf[10+IFNAMSIZ]; |
| 313 | |
| 314 | if (state != NETDEV_CHANGENAME) |
| 315 | return 0; |
| 316 | |
| 317 | if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy) |
| 318 | return 0; |
| 319 | |
| 320 | if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid) |
| 321 | return 0; |
| 322 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 323 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 324 | |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame^] | 325 | dir = sdata->debugfs.dir; |
Johannes Berg | c74e90a | 2008-10-08 10:18:36 +0200 | [diff] [blame] | 326 | |
| 327 | if (!dir) |
| 328 | return 0; |
| 329 | |
| 330 | sprintf(buf, "netdev:%s", dev->name); |
Johannes Berg | 7c8081e | 2007-06-21 18:30:19 +0200 | [diff] [blame] | 331 | if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf)) |
| 332 | printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs " |
| 333 | "dir to %s\n", buf); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | static struct notifier_block mac80211_debugfs_netdev_notifier = { |
| 339 | .notifier_call = netdev_notify, |
| 340 | }; |
| 341 | |
| 342 | void ieee80211_debugfs_netdev_init(void) |
| 343 | { |
| 344 | int err; |
| 345 | |
| 346 | err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier); |
| 347 | if (err) { |
| 348 | printk(KERN_ERR |
| 349 | "mac80211: failed to install netdev notifier," |
| 350 | " disabling per-netdev debugfs!\n"); |
| 351 | } else |
| 352 | notif_registered = 1; |
| 353 | } |
| 354 | |
| 355 | void ieee80211_debugfs_netdev_exit(void) |
| 356 | { |
| 357 | unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier); |
| 358 | notif_registered = 0; |
| 359 | } |