Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | #include <linux/module.h> |
| 2 | #include <linux/dcache.h> |
| 3 | #include <linux/debugfs.h> |
| 4 | #include <linux/delay.h> |
| 5 | #include <linux/mm.h> |
Geert Uytterhoeven | d8b0fb5 | 2007-10-08 09:43:02 +0200 | [diff] [blame] | 6 | #include <linux/string.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 7 | #include <net/iw_handler.h> |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 8 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 9 | #include "dev.h" |
| 10 | #include "decl.h" |
| 11 | #include "host.h" |
Dan Williams | 5bdb3ef | 2007-05-10 23:08:05 -0400 | [diff] [blame] | 12 | #include "debugfs.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 13 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 14 | static struct dentry *lbs_dir; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 15 | static char *szStates[] = { |
| 16 | "Connected", |
| 17 | "Disconnected" |
| 18 | }; |
| 19 | |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 20 | #ifdef PROC_DEBUG |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 21 | static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev); |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 22 | #endif |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 23 | |
| 24 | static int open_file_generic(struct inode *inode, struct file *file) |
| 25 | { |
| 26 | file->private_data = inode->i_private; |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | static ssize_t write_file_dummy(struct file *file, const char __user *buf, |
| 31 | size_t count, loff_t *ppos) |
| 32 | { |
| 33 | return -EINVAL; |
| 34 | } |
| 35 | |
| 36 | static const size_t len = PAGE_SIZE; |
| 37 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 38 | static ssize_t lbs_dev_info(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 39 | size_t count, loff_t *ppos) |
| 40 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 41 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 42 | size_t pos = 0; |
| 43 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 44 | char *buf = (char *)addr; |
| 45 | ssize_t res; |
| 46 | |
| 47 | pos += snprintf(buf+pos, len-pos, "state = %s\n", |
| 48 | szStates[priv->adapter->connect_status]); |
| 49 | pos += snprintf(buf+pos, len-pos, "region_code = %02x\n", |
| 50 | (u32) priv->adapter->regioncode); |
| 51 | |
| 52 | res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 53 | |
| 54 | free_page(addr); |
| 55 | return res; |
| 56 | } |
| 57 | |
| 58 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 59 | static ssize_t lbs_getscantable(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 60 | size_t count, loff_t *ppos) |
| 61 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 62 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 63 | size_t pos = 0; |
| 64 | int numscansdone = 0, res; |
| 65 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 66 | char *buf = (char *)addr; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 67 | DECLARE_MAC_BUF(mac); |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 68 | struct bss_descriptor * iter_bss; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 69 | |
| 70 | pos += snprintf(buf+pos, len-pos, |
Holger Schurig | a2235ed | 2007-08-02 13:12:45 -0400 | [diff] [blame] | 71 | "# | ch | rssi | bssid | cap | Qual | SSID \n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 72 | |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 73 | mutex_lock(&priv->adapter->lock); |
| 74 | list_for_each_entry (iter_bss, &priv->adapter->network_list, list) { |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 75 | u16 ibss = (iter_bss->capability & WLAN_CAPABILITY_IBSS); |
| 76 | u16 privacy = (iter_bss->capability & WLAN_CAPABILITY_PRIVACY); |
| 77 | u16 spectrum_mgmt = (iter_bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 78 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 79 | pos += snprintf(buf+pos, len-pos, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 80 | "%02u| %03d | %04ld | %s |", |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 81 | numscansdone, iter_bss->channel, iter_bss->rssi, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 82 | print_mac(mac, iter_bss->bssid)); |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 83 | pos += snprintf(buf+pos, len-pos, " %04x-", iter_bss->capability); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 84 | pos += snprintf(buf+pos, len-pos, "%c%c%c |", |
Dan Williams | 0c9ca690 | 2007-08-02 10:43:44 -0400 | [diff] [blame] | 85 | ibss ? 'A' : 'I', privacy ? 'P' : ' ', |
| 86 | spectrum_mgmt ? 'S' : ' '); |
Holger Schurig | a2235ed | 2007-08-02 13:12:45 -0400 | [diff] [blame] | 87 | pos += snprintf(buf+pos, len-pos, " %04d |", SCAN_RSSI(iter_bss->rssi)); |
Dan Williams | d8efea2 | 2007-05-28 23:54:55 -0400 | [diff] [blame] | 88 | pos += snprintf(buf+pos, len-pos, " %s\n", |
| 89 | escape_essid(iter_bss->ssid, iter_bss->ssid_len)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 90 | |
| 91 | numscansdone++; |
| 92 | } |
Dan Williams | fcdb53d | 2007-05-25 16:15:56 -0400 | [diff] [blame] | 93 | mutex_unlock(&priv->adapter->lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 94 | |
| 95 | res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 96 | |
| 97 | free_page(addr); |
| 98 | return res; |
| 99 | } |
| 100 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 101 | static ssize_t lbs_sleepparams_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 102 | const char __user *user_buf, size_t count, |
| 103 | loff_t *ppos) |
| 104 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 105 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 106 | ssize_t buf_size, res; |
| 107 | int p1, p2, p3, p4, p5, p6; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 108 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 109 | char *buf = (char *)addr; |
| 110 | |
| 111 | buf_size = min(count, len - 1); |
| 112 | if (copy_from_user(buf, user_buf, buf_size)) { |
| 113 | res = -EFAULT; |
| 114 | goto out_unlock; |
| 115 | } |
| 116 | res = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6); |
| 117 | if (res != 6) { |
| 118 | res = -EFAULT; |
| 119 | goto out_unlock; |
| 120 | } |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 121 | priv->adapter->sp.sp_error = p1; |
| 122 | priv->adapter->sp.sp_offset = p2; |
| 123 | priv->adapter->sp.sp_stabletime = p3; |
| 124 | priv->adapter->sp.sp_calcontrol = p4; |
| 125 | priv->adapter->sp.sp_extsleepclk = p5; |
| 126 | priv->adapter->sp.sp_reserved = p6; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 127 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 128 | res = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 129 | CMD_802_11_SLEEP_PARAMS, |
| 130 | CMD_ACT_SET, |
| 131 | CMD_OPTION_WAITFORRSP, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 132 | |
| 133 | if (!res) |
| 134 | res = count; |
| 135 | else |
| 136 | res = -EINVAL; |
| 137 | |
| 138 | out_unlock: |
| 139 | free_page(addr); |
| 140 | return res; |
| 141 | } |
| 142 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 143 | static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 144 | size_t count, loff_t *ppos) |
| 145 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 146 | struct lbs_private *priv = file->private_data; |
| 147 | struct lbs_adapter *adapter = priv->adapter; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 148 | ssize_t res; |
| 149 | size_t pos = 0; |
| 150 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 151 | char *buf = (char *)addr; |
| 152 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 153 | res = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 154 | CMD_802_11_SLEEP_PARAMS, |
| 155 | CMD_ACT_GET, |
| 156 | CMD_OPTION_WAITFORRSP, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 157 | if (res) { |
| 158 | res = -EFAULT; |
| 159 | goto out_unlock; |
| 160 | } |
| 161 | |
| 162 | pos += snprintf(buf, len, "%d %d %d %d %d %d\n", adapter->sp.sp_error, |
| 163 | adapter->sp.sp_offset, adapter->sp.sp_stabletime, |
| 164 | adapter->sp.sp_calcontrol, adapter->sp.sp_extsleepclk, |
| 165 | adapter->sp.sp_reserved); |
| 166 | |
| 167 | res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 168 | |
| 169 | out_unlock: |
| 170 | free_page(addr); |
| 171 | return res; |
| 172 | } |
| 173 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 174 | static ssize_t lbs_extscan(struct file *file, const char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 175 | size_t count, loff_t *ppos) |
| 176 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 177 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 178 | ssize_t res, buf_size; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 179 | union iwreq_data wrqu; |
| 180 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 181 | char *buf = (char *)addr; |
| 182 | |
| 183 | buf_size = min(count, len - 1); |
| 184 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 185 | res = -EFAULT; |
| 186 | goto out_unlock; |
| 187 | } |
| 188 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 189 | lbs_send_specific_ssid_scan(priv, buf, strlen(buf)-1, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 190 | |
| 191 | memset(&wrqu, 0, sizeof(union iwreq_data)); |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 192 | wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 193 | |
| 194 | out_unlock: |
| 195 | free_page(addr); |
| 196 | return count; |
| 197 | } |
| 198 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 199 | static int lbs_parse_chan(char *buf, size_t count, |
| 200 | struct lbs_ioctl_user_scan_cfg *scan_cfg, int dur) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 201 | { |
| 202 | char *start, *end, *hold, *str; |
| 203 | int i = 0; |
| 204 | |
| 205 | start = strstr(buf, "chan="); |
| 206 | if (!start) |
| 207 | return -EINVAL; |
| 208 | start += 5; |
Geert Uytterhoeven | d8b0fb5 | 2007-10-08 09:43:02 +0200 | [diff] [blame] | 209 | end = strchr(start, ' '); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 210 | if (!end) |
| 211 | end = buf + count; |
| 212 | hold = kzalloc((end - start)+1, GFP_KERNEL); |
| 213 | if (!hold) |
| 214 | return -ENOMEM; |
| 215 | strncpy(hold, start, end - start); |
| 216 | hold[(end-start)+1] = '\0'; |
| 217 | while(hold && (str = strsep(&hold, ","))) { |
| 218 | int chan; |
| 219 | char band, passive = 0; |
| 220 | sscanf(str, "%d%c%c", &chan, &band, &passive); |
| 221 | scan_cfg->chanlist[i].channumber = chan; |
| 222 | scan_cfg->chanlist[i].scantype = passive ? 1 : 0; |
| 223 | if (band == 'b' || band == 'g') |
| 224 | scan_cfg->chanlist[i].radiotype = 0; |
| 225 | else if (band == 'a') |
| 226 | scan_cfg->chanlist[i].radiotype = 1; |
| 227 | |
| 228 | scan_cfg->chanlist[i].scantime = dur; |
| 229 | i++; |
| 230 | } |
| 231 | |
| 232 | kfree(hold); |
| 233 | return i; |
| 234 | } |
| 235 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 236 | static void lbs_parse_bssid(char *buf, size_t count, |
| 237 | struct lbs_ioctl_user_scan_cfg *scan_cfg) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 238 | { |
| 239 | char *hold; |
| 240 | unsigned int mac[ETH_ALEN]; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 241 | |
| 242 | hold = strstr(buf, "bssid="); |
| 243 | if (!hold) |
| 244 | return; |
| 245 | hold += 6; |
David S. Miller | 15ca36f | 2007-12-27 16:43:38 -0800 | [diff] [blame] | 246 | sscanf(hold, "%02x:%02x:%02x:%02x:%02x:%02x", |
| 247 | mac, mac+1, mac+2, mac+3, mac+4, mac+5); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 248 | memcpy(scan_cfg->bssid, mac, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 249 | } |
| 250 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 251 | static void lbs_parse_ssid(char *buf, size_t count, |
| 252 | struct lbs_ioctl_user_scan_cfg *scan_cfg) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 253 | { |
| 254 | char *hold, *end; |
| 255 | ssize_t size; |
| 256 | |
| 257 | hold = strstr(buf, "ssid="); |
| 258 | if (!hold) |
| 259 | return; |
| 260 | hold += 5; |
Geert Uytterhoeven | d8b0fb5 | 2007-10-08 09:43:02 +0200 | [diff] [blame] | 261 | end = strchr(hold, ' '); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 262 | if (!end) |
| 263 | end = buf + count - 1; |
| 264 | |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 265 | size = min((size_t)IW_ESSID_MAX_SIZE, (size_t) (end - hold)); |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 266 | strncpy(scan_cfg->ssid, hold, size); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 267 | |
| 268 | return; |
| 269 | } |
| 270 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 271 | static int lbs_parse_clear(char *buf, size_t count, const char *tag) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 272 | { |
| 273 | char *hold; |
| 274 | int val; |
| 275 | |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 276 | hold = strstr(buf, tag); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 277 | if (!hold) |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 278 | return 0; |
| 279 | hold += strlen(tag); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 280 | sscanf(hold, "%d", &val); |
| 281 | |
| 282 | if (val != 0) |
| 283 | val = 1; |
| 284 | |
Dan Williams | eb8f733 | 2007-05-25 16:25:21 -0400 | [diff] [blame] | 285 | return val; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 286 | } |
| 287 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 288 | static int lbs_parse_dur(char *buf, size_t count, |
| 289 | struct lbs_ioctl_user_scan_cfg *scan_cfg) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 290 | { |
| 291 | char *hold; |
| 292 | int val; |
| 293 | |
| 294 | hold = strstr(buf, "dur="); |
| 295 | if (!hold) |
| 296 | return 0; |
| 297 | hold += 4; |
| 298 | sscanf(hold, "%d", &val); |
| 299 | |
| 300 | return val; |
| 301 | } |
| 302 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 303 | static void lbs_parse_probes(char *buf, size_t count, |
| 304 | struct lbs_ioctl_user_scan_cfg *scan_cfg) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 305 | { |
| 306 | char *hold; |
| 307 | int val; |
| 308 | |
| 309 | hold = strstr(buf, "probes="); |
| 310 | if (!hold) |
| 311 | return; |
| 312 | hold += 7; |
| 313 | sscanf(hold, "%d", &val); |
| 314 | |
| 315 | scan_cfg->numprobes = val; |
| 316 | |
| 317 | return; |
| 318 | } |
| 319 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 320 | static void lbs_parse_type(char *buf, size_t count, |
| 321 | struct lbs_ioctl_user_scan_cfg *scan_cfg) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 322 | { |
| 323 | char *hold; |
| 324 | int val; |
| 325 | |
| 326 | hold = strstr(buf, "type="); |
| 327 | if (!hold) |
| 328 | return; |
| 329 | hold += 5; |
| 330 | sscanf(hold, "%d", &val); |
| 331 | |
| 332 | /* type=1,2 or 3 */ |
| 333 | if (val < 1 || val > 3) |
| 334 | return; |
| 335 | |
| 336 | scan_cfg->bsstype = val; |
| 337 | |
| 338 | return; |
| 339 | } |
| 340 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 341 | static ssize_t lbs_setuserscan(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 342 | const char __user *userbuf, |
| 343 | size_t count, loff_t *ppos) |
| 344 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 345 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 346 | ssize_t res, buf_size; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 347 | struct lbs_ioctl_user_scan_cfg *scan_cfg; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 348 | union iwreq_data wrqu; |
| 349 | int dur; |
| 350 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 351 | char *buf = (char *)addr; |
| 352 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 353 | scan_cfg = kzalloc(sizeof(struct lbs_ioctl_user_scan_cfg), GFP_KERNEL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 354 | if (!scan_cfg) |
| 355 | return -ENOMEM; |
| 356 | |
| 357 | buf_size = min(count, len - 1); |
| 358 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 359 | res = -EFAULT; |
| 360 | goto out_unlock; |
| 361 | } |
| 362 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 363 | scan_cfg->bsstype = LBS_SCAN_BSS_TYPE_ANY; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 364 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 365 | dur = lbs_parse_dur(buf, count, scan_cfg); |
| 366 | lbs_parse_chan(buf, count, scan_cfg, dur); |
| 367 | lbs_parse_bssid(buf, count, scan_cfg); |
| 368 | scan_cfg->clear_bssid = lbs_parse_clear(buf, count, "clear_bssid="); |
| 369 | lbs_parse_ssid(buf, count, scan_cfg); |
| 370 | scan_cfg->clear_ssid = lbs_parse_clear(buf, count, "clear_ssid="); |
| 371 | lbs_parse_probes(buf, count, scan_cfg); |
| 372 | lbs_parse_type(buf, count, scan_cfg); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 373 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 374 | lbs_scan_networks(priv, scan_cfg, 1); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 375 | wait_event_interruptible(priv->adapter->cmd_pending, |
| 376 | !priv->adapter->nr_cmd_pending); |
| 377 | |
| 378 | memset(&wrqu, 0x00, sizeof(union iwreq_data)); |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 379 | wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 380 | |
| 381 | out_unlock: |
| 382 | free_page(addr); |
| 383 | kfree(scan_cfg); |
| 384 | return count; |
| 385 | } |
| 386 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 387 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 388 | /* |
| 389 | * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might |
| 390 | * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the |
| 391 | * firmware. Here's an example: |
| 392 | * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00 |
| 393 | * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03 |
| 394 | * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 395 | * |
| 396 | * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length, |
| 397 | * 00 00 are the data bytes of this TLV. For this TLV, their meaning is |
| 398 | * defined in mrvlietypes_thresholds |
| 399 | * |
| 400 | * This function searches in this TLV data chunk for a given TLV type |
| 401 | * and returns a pointer to the first data byte of the TLV, or to NULL |
| 402 | * if the TLV hasn't been found. |
| 403 | */ |
| 404 | static void *lbs_tlv_find(u16 tlv_type, const u8 *tlv, u16 size) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 405 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 406 | __le16 le_type = cpu_to_le16(tlv_type); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 407 | ssize_t pos = 0; |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 408 | struct mrvlietypesheader *tlv_h; |
| 409 | while (pos < size) { |
| 410 | u16 length; |
| 411 | tlv_h = (struct mrvlietypesheader *) tlv; |
| 412 | if (tlv_h->type == le_type) |
| 413 | return tlv_h; |
| 414 | if (tlv_h->len == 0) |
| 415 | return NULL; |
| 416 | length = le16_to_cpu(tlv_h->len) + |
| 417 | sizeof(struct mrvlietypesheader); |
| 418 | pos += length; |
| 419 | tlv += length; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 420 | } |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 421 | return NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 422 | } |
| 423 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 424 | |
| 425 | /* |
| 426 | * This just gets the bitmap of currently subscribed events. Used when |
| 427 | * adding an additonal event subscription. |
| 428 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 429 | static u16 lbs_get_events_bitmap(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 430 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 431 | ssize_t res; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 432 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 433 | struct cmd_ds_802_11_subscribe_event *events = kzalloc( |
| 434 | sizeof(struct cmd_ds_802_11_subscribe_event), |
| 435 | GFP_KERNEL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 436 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 437 | res = lbs_prepare_and_send_command(priv, |
| 438 | CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET, |
| 439 | CMD_OPTION_WAITFORRSP, 0, events); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 440 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 441 | if (res) { |
| 442 | kfree(events); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 443 | return 0; |
| 444 | } |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 445 | return le16_to_cpu(events->events); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 446 | } |
| 447 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 448 | |
| 449 | static ssize_t lbs_threshold_read( |
| 450 | u16 tlv_type, u16 event_mask, |
| 451 | struct file *file, char __user *userbuf, |
| 452 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 453 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 454 | struct lbs_private *priv = file->private_data; |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 455 | ssize_t res = 0; |
| 456 | size_t pos = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 457 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 458 | char *buf = (char *)addr; |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 459 | u8 value; |
| 460 | u8 freq; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 461 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 462 | struct cmd_ds_802_11_subscribe_event *events = kzalloc( |
| 463 | sizeof(struct cmd_ds_802_11_subscribe_event), |
| 464 | GFP_KERNEL); |
| 465 | struct mrvlietypes_thresholds *got; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 466 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 467 | res = lbs_prepare_and_send_command(priv, |
| 468 | CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET, |
| 469 | CMD_OPTION_WAITFORRSP, 0, events); |
| 470 | if (res) { |
| 471 | kfree(events); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 472 | return res; |
| 473 | } |
| 474 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 475 | got = lbs_tlv_find(tlv_type, events->tlv, sizeof(events->tlv)); |
| 476 | if (got) { |
| 477 | value = got->value; |
| 478 | freq = got->freq; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 479 | } |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 480 | kfree(events); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 481 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 482 | if (got) |
| 483 | pos += snprintf(buf, len, "%d %d %d\n", value, freq, |
| 484 | !!(le16_to_cpu(events->events) & event_mask)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 485 | |
| 486 | res = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 487 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 488 | free_page(addr); |
| 489 | return res; |
| 490 | } |
| 491 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 492 | |
| 493 | static ssize_t lbs_threshold_write( |
| 494 | u16 tlv_type, u16 event_mask, |
| 495 | struct file *file, |
| 496 | const char __user *userbuf, |
| 497 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 498 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 499 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 500 | ssize_t res, buf_size; |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 501 | int value, freq, curr_mask, new_mask; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 502 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 503 | char *buf = (char *)addr; |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 504 | struct cmd_ds_802_11_subscribe_event *events; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 505 | |
| 506 | buf_size = min(count, len - 1); |
| 507 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 508 | res = -EFAULT; |
| 509 | goto out_unlock; |
| 510 | } |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 511 | res = sscanf(buf, "%d %d %d", &value, &freq, &new_mask); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 512 | if (res != 3) { |
| 513 | res = -EFAULT; |
| 514 | goto out_unlock; |
| 515 | } |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 516 | curr_mask = lbs_get_events_bitmap(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 517 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 518 | if (new_mask) |
| 519 | new_mask = curr_mask | event_mask; |
| 520 | else |
| 521 | new_mask = curr_mask & ~event_mask; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 522 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 523 | /* Now everything is set and we can send stuff down to the firmware */ |
| 524 | events = kzalloc( |
| 525 | sizeof(struct cmd_ds_802_11_subscribe_event), |
| 526 | GFP_KERNEL); |
| 527 | if (events) { |
| 528 | struct mrvlietypes_thresholds *tlv = |
| 529 | (struct mrvlietypes_thresholds *) events->tlv; |
| 530 | events->action = cpu_to_le16(CMD_ACT_SET); |
| 531 | events->events = cpu_to_le16(new_mask); |
| 532 | tlv->header.type = cpu_to_le16(tlv_type); |
| 533 | tlv->header.len = cpu_to_le16( |
| 534 | sizeof(struct mrvlietypes_thresholds) - |
| 535 | sizeof(struct mrvlietypesheader)); |
| 536 | tlv->value = value; |
| 537 | if (tlv_type != TLV_TYPE_BCNMISS) |
| 538 | tlv->freq = freq; |
| 539 | lbs_prepare_and_send_command(priv, |
| 540 | CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_SET, |
| 541 | CMD_OPTION_WAITFORRSP, 0, events); |
| 542 | kfree(events); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | res = count; |
| 546 | out_unlock: |
| 547 | free_page(addr); |
| 548 | return res; |
| 549 | } |
| 550 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 551 | |
| 552 | static ssize_t lbs_lowrssi_read( |
| 553 | struct file *file, char __user *userbuf, |
| 554 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 555 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 556 | return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW, |
| 557 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 558 | } |
| 559 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 560 | |
| 561 | static ssize_t lbs_lowrssi_write( |
| 562 | struct file *file, const char __user *userbuf, |
| 563 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 564 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 565 | return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW, |
| 566 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 567 | } |
| 568 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 569 | |
| 570 | static ssize_t lbs_lowsnr_read( |
| 571 | struct file *file, char __user *userbuf, |
| 572 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 573 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 574 | return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW, |
| 575 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 576 | } |
| 577 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 578 | |
| 579 | static ssize_t lbs_lowsnr_write( |
| 580 | struct file *file, const char __user *userbuf, |
| 581 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 582 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 583 | return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW, |
| 584 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 585 | } |
| 586 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 587 | |
| 588 | static ssize_t lbs_failcount_read( |
| 589 | struct file *file, char __user *userbuf, |
| 590 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 591 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 592 | return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT, |
| 593 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 594 | } |
| 595 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 596 | |
| 597 | static ssize_t lbs_failcount_write( |
| 598 | struct file *file, const char __user *userbuf, |
| 599 | size_t count, loff_t *ppos) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 600 | { |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 601 | return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT, |
| 602 | file, userbuf, count, ppos); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 603 | } |
| 604 | |
Holger Schurig | 3a18864 | 2007-11-26 10:07:14 +0100 | [diff] [blame^] | 605 | |
| 606 | static ssize_t lbs_highrssi_read( |
| 607 | struct file *file, char __user *userbuf, |
| 608 | size_t count, loff_t *ppos) |
| 609 | { |
| 610 | return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH, |
| 611 | file, userbuf, count, ppos); |
| 612 | } |
| 613 | |
| 614 | |
| 615 | static ssize_t lbs_highrssi_write( |
| 616 | struct file *file, const char __user *userbuf, |
| 617 | size_t count, loff_t *ppos) |
| 618 | { |
| 619 | return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH, |
| 620 | file, userbuf, count, ppos); |
| 621 | } |
| 622 | |
| 623 | |
| 624 | static ssize_t lbs_highsnr_read( |
| 625 | struct file *file, char __user *userbuf, |
| 626 | size_t count, loff_t *ppos) |
| 627 | { |
| 628 | return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH, |
| 629 | file, userbuf, count, ppos); |
| 630 | } |
| 631 | |
| 632 | |
| 633 | static ssize_t lbs_highsnr_write( |
| 634 | struct file *file, const char __user *userbuf, |
| 635 | size_t count, loff_t *ppos) |
| 636 | { |
| 637 | return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH, |
| 638 | file, userbuf, count, ppos); |
| 639 | } |
| 640 | |
| 641 | static ssize_t lbs_bcnmiss_read( |
| 642 | struct file *file, char __user *userbuf, |
| 643 | size_t count, loff_t *ppos) |
| 644 | { |
| 645 | return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS, |
| 646 | file, userbuf, count, ppos); |
| 647 | } |
| 648 | |
| 649 | |
| 650 | static ssize_t lbs_bcnmiss_write( |
| 651 | struct file *file, const char __user *userbuf, |
| 652 | size_t count, loff_t *ppos) |
| 653 | { |
| 654 | return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS, |
| 655 | file, userbuf, count, ppos); |
| 656 | } |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 665 | static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 666 | size_t count, loff_t *ppos) |
| 667 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 668 | struct lbs_private *priv = file->private_data; |
| 669 | struct lbs_adapter *adapter = priv->adapter; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 670 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 671 | ssize_t pos = 0; |
| 672 | int ret; |
| 673 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 674 | char *buf = (char *)addr; |
| 675 | |
| 676 | offval.offset = priv->mac_offset; |
| 677 | offval.value = 0; |
| 678 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 679 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 680 | CMD_MAC_REG_ACCESS, 0, |
| 681 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 682 | mdelay(10); |
| 683 | pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n", |
| 684 | priv->mac_offset, adapter->offsetvalue.value); |
| 685 | |
| 686 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 687 | free_page(addr); |
| 688 | return ret; |
| 689 | } |
| 690 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 691 | static ssize_t lbs_rdmac_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 692 | const char __user *userbuf, |
| 693 | size_t count, loff_t *ppos) |
| 694 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 695 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 696 | ssize_t res, buf_size; |
| 697 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 698 | char *buf = (char *)addr; |
| 699 | |
| 700 | buf_size = min(count, len - 1); |
| 701 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 702 | res = -EFAULT; |
| 703 | goto out_unlock; |
| 704 | } |
| 705 | priv->mac_offset = simple_strtoul((char *)buf, NULL, 16); |
| 706 | res = count; |
| 707 | out_unlock: |
| 708 | free_page(addr); |
| 709 | return res; |
| 710 | } |
| 711 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 712 | static ssize_t lbs_wrmac_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 713 | const char __user *userbuf, |
| 714 | size_t count, loff_t *ppos) |
| 715 | { |
| 716 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 717 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 718 | ssize_t res, buf_size; |
| 719 | u32 offset, value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 720 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 721 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 722 | char *buf = (char *)addr; |
| 723 | |
| 724 | buf_size = min(count, len - 1); |
| 725 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 726 | res = -EFAULT; |
| 727 | goto out_unlock; |
| 728 | } |
| 729 | res = sscanf(buf, "%x %x", &offset, &value); |
| 730 | if (res != 2) { |
| 731 | res = -EFAULT; |
| 732 | goto out_unlock; |
| 733 | } |
| 734 | |
| 735 | offval.offset = offset; |
| 736 | offval.value = value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 737 | res = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 738 | CMD_MAC_REG_ACCESS, 1, |
| 739 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 740 | mdelay(10); |
| 741 | |
| 742 | res = count; |
| 743 | out_unlock: |
| 744 | free_page(addr); |
| 745 | return res; |
| 746 | } |
| 747 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 748 | static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 749 | size_t count, loff_t *ppos) |
| 750 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 751 | struct lbs_private *priv = file->private_data; |
| 752 | struct lbs_adapter *adapter = priv->adapter; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 753 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 754 | ssize_t pos = 0; |
| 755 | int ret; |
| 756 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 757 | char *buf = (char *)addr; |
| 758 | |
| 759 | offval.offset = priv->bbp_offset; |
| 760 | offval.value = 0; |
| 761 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 762 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 763 | CMD_BBP_REG_ACCESS, 0, |
| 764 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 765 | mdelay(10); |
| 766 | pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n", |
| 767 | priv->bbp_offset, adapter->offsetvalue.value); |
| 768 | |
| 769 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 770 | free_page(addr); |
| 771 | |
| 772 | return ret; |
| 773 | } |
| 774 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 775 | static ssize_t lbs_rdbbp_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 776 | const char __user *userbuf, |
| 777 | size_t count, loff_t *ppos) |
| 778 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 779 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 780 | ssize_t res, buf_size; |
| 781 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 782 | char *buf = (char *)addr; |
| 783 | |
| 784 | buf_size = min(count, len - 1); |
| 785 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 786 | res = -EFAULT; |
| 787 | goto out_unlock; |
| 788 | } |
| 789 | priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16); |
| 790 | res = count; |
| 791 | out_unlock: |
| 792 | free_page(addr); |
| 793 | return res; |
| 794 | } |
| 795 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 796 | static ssize_t lbs_wrbbp_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 797 | const char __user *userbuf, |
| 798 | size_t count, loff_t *ppos) |
| 799 | { |
| 800 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 801 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 802 | ssize_t res, buf_size; |
| 803 | u32 offset, value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 804 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 805 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 806 | char *buf = (char *)addr; |
| 807 | |
| 808 | buf_size = min(count, len - 1); |
| 809 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 810 | res = -EFAULT; |
| 811 | goto out_unlock; |
| 812 | } |
| 813 | res = sscanf(buf, "%x %x", &offset, &value); |
| 814 | if (res != 2) { |
| 815 | res = -EFAULT; |
| 816 | goto out_unlock; |
| 817 | } |
| 818 | |
| 819 | offval.offset = offset; |
| 820 | offval.value = value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 821 | res = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 822 | CMD_BBP_REG_ACCESS, 1, |
| 823 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 824 | mdelay(10); |
| 825 | |
| 826 | res = count; |
| 827 | out_unlock: |
| 828 | free_page(addr); |
| 829 | return res; |
| 830 | } |
| 831 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 832 | static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 833 | size_t count, loff_t *ppos) |
| 834 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 835 | struct lbs_private *priv = file->private_data; |
| 836 | struct lbs_adapter *adapter = priv->adapter; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 837 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 838 | ssize_t pos = 0; |
| 839 | int ret; |
| 840 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 841 | char *buf = (char *)addr; |
| 842 | |
| 843 | offval.offset = priv->rf_offset; |
| 844 | offval.value = 0; |
| 845 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 846 | ret = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 847 | CMD_RF_REG_ACCESS, 0, |
| 848 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 849 | mdelay(10); |
| 850 | pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n", |
| 851 | priv->rf_offset, adapter->offsetvalue.value); |
| 852 | |
| 853 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos); |
| 854 | free_page(addr); |
| 855 | |
| 856 | return ret; |
| 857 | } |
| 858 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 859 | static ssize_t lbs_rdrf_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 860 | const char __user *userbuf, |
| 861 | size_t count, loff_t *ppos) |
| 862 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 863 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 864 | ssize_t res, buf_size; |
| 865 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 866 | char *buf = (char *)addr; |
| 867 | |
| 868 | buf_size = min(count, len - 1); |
| 869 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 870 | res = -EFAULT; |
| 871 | goto out_unlock; |
| 872 | } |
| 873 | priv->rf_offset = simple_strtoul((char *)buf, NULL, 16); |
| 874 | res = count; |
| 875 | out_unlock: |
| 876 | free_page(addr); |
| 877 | return res; |
| 878 | } |
| 879 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 880 | static ssize_t lbs_wrrf_write(struct file *file, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 881 | const char __user *userbuf, |
| 882 | size_t count, loff_t *ppos) |
| 883 | { |
| 884 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 885 | struct lbs_private *priv = file->private_data; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 886 | ssize_t res, buf_size; |
| 887 | u32 offset, value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 888 | struct lbs_offset_value offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 889 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 890 | char *buf = (char *)addr; |
| 891 | |
| 892 | buf_size = min(count, len - 1); |
| 893 | if (copy_from_user(buf, userbuf, buf_size)) { |
| 894 | res = -EFAULT; |
| 895 | goto out_unlock; |
| 896 | } |
| 897 | res = sscanf(buf, "%x %x", &offset, &value); |
| 898 | if (res != 2) { |
| 899 | res = -EFAULT; |
| 900 | goto out_unlock; |
| 901 | } |
| 902 | |
| 903 | offval.offset = offset; |
| 904 | offval.value = value; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 905 | res = lbs_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 906 | CMD_RF_REG_ACCESS, 1, |
| 907 | CMD_OPTION_WAITFORRSP, 0, &offval); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 908 | mdelay(10); |
| 909 | |
| 910 | res = count; |
| 911 | out_unlock: |
| 912 | free_page(addr); |
| 913 | return res; |
| 914 | } |
| 915 | |
| 916 | #define FOPS(fread, fwrite) { \ |
| 917 | .owner = THIS_MODULE, \ |
| 918 | .open = open_file_generic, \ |
| 919 | .read = (fread), \ |
| 920 | .write = (fwrite), \ |
| 921 | } |
| 922 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 923 | struct lbs_debugfs_files { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 924 | char *name; |
| 925 | int perm; |
| 926 | struct file_operations fops; |
| 927 | }; |
| 928 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 929 | static struct lbs_debugfs_files debugfs_files[] = { |
| 930 | { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), }, |
| 931 | { "getscantable", 0444, FOPS(lbs_getscantable, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 932 | write_file_dummy), }, |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 933 | { "sleepparams", 0644, FOPS(lbs_sleepparams_read, |
| 934 | lbs_sleepparams_write), }, |
| 935 | { "extscan", 0600, FOPS(NULL, lbs_extscan), }, |
| 936 | { "setuserscan", 0600, FOPS(NULL, lbs_setuserscan), }, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 937 | }; |
| 938 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 939 | static struct lbs_debugfs_files debugfs_events_files[] = { |
| 940 | {"low_rssi", 0644, FOPS(lbs_lowrssi_read, |
| 941 | lbs_lowrssi_write), }, |
| 942 | {"low_snr", 0644, FOPS(lbs_lowsnr_read, |
| 943 | lbs_lowsnr_write), }, |
| 944 | {"failure_count", 0644, FOPS(lbs_failcount_read, |
| 945 | lbs_failcount_write), }, |
| 946 | {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read, |
| 947 | lbs_bcnmiss_write), }, |
| 948 | {"high_rssi", 0644, FOPS(lbs_highrssi_read, |
| 949 | lbs_highrssi_write), }, |
| 950 | {"high_snr", 0644, FOPS(lbs_highsnr_read, |
| 951 | lbs_highsnr_write), }, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 952 | }; |
| 953 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 954 | static struct lbs_debugfs_files debugfs_regs_files[] = { |
| 955 | {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), }, |
| 956 | {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), }, |
| 957 | {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), }, |
| 958 | {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), }, |
| 959 | {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), }, |
| 960 | {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), }, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 961 | }; |
| 962 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 963 | void lbs_debugfs_init(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 964 | { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 965 | if (!lbs_dir) |
| 966 | lbs_dir = debugfs_create_dir("lbs_wireless", NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 967 | |
| 968 | return; |
| 969 | } |
| 970 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 971 | void lbs_debugfs_remove(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 972 | { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 973 | if (lbs_dir) |
| 974 | debugfs_remove(lbs_dir); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 975 | return; |
| 976 | } |
| 977 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 978 | void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 979 | { |
| 980 | int i; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 981 | struct lbs_debugfs_files *files; |
| 982 | if (!lbs_dir) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 983 | goto exit; |
| 984 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 985 | priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 986 | if (!priv->debugfs_dir) |
| 987 | goto exit; |
| 988 | |
| 989 | for (i=0; i<ARRAY_SIZE(debugfs_files); i++) { |
| 990 | files = &debugfs_files[i]; |
| 991 | priv->debugfs_files[i] = debugfs_create_file(files->name, |
| 992 | files->perm, |
| 993 | priv->debugfs_dir, |
| 994 | priv, |
| 995 | &files->fops); |
| 996 | } |
| 997 | |
| 998 | priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir); |
| 999 | if (!priv->events_dir) |
| 1000 | goto exit; |
| 1001 | |
| 1002 | for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) { |
| 1003 | files = &debugfs_events_files[i]; |
| 1004 | priv->debugfs_events_files[i] = debugfs_create_file(files->name, |
| 1005 | files->perm, |
| 1006 | priv->events_dir, |
| 1007 | priv, |
| 1008 | &files->fops); |
| 1009 | } |
| 1010 | |
| 1011 | priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir); |
| 1012 | if (!priv->regs_dir) |
| 1013 | goto exit; |
| 1014 | |
| 1015 | for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) { |
| 1016 | files = &debugfs_regs_files[i]; |
| 1017 | priv->debugfs_regs_files[i] = debugfs_create_file(files->name, |
| 1018 | files->perm, |
| 1019 | priv->regs_dir, |
| 1020 | priv, |
| 1021 | &files->fops); |
| 1022 | } |
| 1023 | |
| 1024 | #ifdef PROC_DEBUG |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1025 | lbs_debug_init(priv, dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1026 | #endif |
| 1027 | exit: |
| 1028 | return; |
| 1029 | } |
| 1030 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1031 | void lbs_debugfs_remove_one(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1032 | { |
| 1033 | int i; |
| 1034 | |
| 1035 | for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) |
| 1036 | debugfs_remove(priv->debugfs_regs_files[i]); |
| 1037 | |
| 1038 | debugfs_remove(priv->regs_dir); |
| 1039 | |
Holger Schurig | 0b7db95 | 2007-05-24 23:47:34 -0400 | [diff] [blame] | 1040 | for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1041 | debugfs_remove(priv->debugfs_events_files[i]); |
| 1042 | |
| 1043 | debugfs_remove(priv->events_dir); |
| 1044 | #ifdef PROC_DEBUG |
| 1045 | debugfs_remove(priv->debugfs_debug); |
| 1046 | #endif |
| 1047 | for(i=0; i<ARRAY_SIZE(debugfs_files); i++) |
| 1048 | debugfs_remove(priv->debugfs_files[i]); |
Holger Schurig | 0b7db95 | 2007-05-24 23:47:34 -0400 | [diff] [blame] | 1049 | debugfs_remove(priv->debugfs_dir); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1050 | } |
| 1051 | |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 1052 | |
| 1053 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1054 | /* debug entry */ |
| 1055 | |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 1056 | #ifdef PROC_DEBUG |
| 1057 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1058 | #define item_size(n) (FIELD_SIZEOF(struct lbs_adapter, n)) |
| 1059 | #define item_addr(n) (offsetof(struct lbs_adapter, n)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1060 | |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 1061 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1062 | struct debug_data { |
| 1063 | char name[32]; |
| 1064 | u32 size; |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 1065 | size_t addr; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1066 | }; |
| 1067 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1068 | /* To debug any member of struct lbs_adapter, simply add one line here. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1069 | */ |
| 1070 | static struct debug_data items[] = { |
| 1071 | {"intcounter", item_size(intcounter), item_addr(intcounter)}, |
| 1072 | {"psmode", item_size(psmode), item_addr(psmode)}, |
| 1073 | {"psstate", item_size(psstate), item_addr(psstate)}, |
| 1074 | }; |
| 1075 | |
Tony Breeds | d2f11e0 | 2007-03-09 13:11:46 +1100 | [diff] [blame] | 1076 | static int num_of_items = ARRAY_SIZE(items); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1077 | |
| 1078 | /** |
| 1079 | * @brief proc read function |
| 1080 | * |
| 1081 | * @param page pointer to buffer |
| 1082 | * @param s read data starting position |
| 1083 | * @param off offset |
| 1084 | * @param cnt counter |
| 1085 | * @param eof end of file flag |
| 1086 | * @param data data to output |
| 1087 | * @return number of output data |
| 1088 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1089 | static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1090 | size_t count, loff_t *ppos) |
| 1091 | { |
| 1092 | int val = 0; |
| 1093 | size_t pos = 0; |
| 1094 | ssize_t res; |
| 1095 | char *p; |
| 1096 | int i; |
| 1097 | struct debug_data *d; |
| 1098 | unsigned long addr = get_zeroed_page(GFP_KERNEL); |
| 1099 | char *buf = (char *)addr; |
| 1100 | |
| 1101 | p = buf; |
| 1102 | |
| 1103 | d = (struct debug_data *)file->private_data; |
| 1104 | |
| 1105 | for (i = 0; i < num_of_items; i++) { |
| 1106 | if (d[i].size == 1) |
| 1107 | val = *((u8 *) d[i].addr); |
| 1108 | else if (d[i].size == 2) |
| 1109 | val = *((u16 *) d[i].addr); |
| 1110 | else if (d[i].size == 4) |
| 1111 | val = *((u32 *) d[i].addr); |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 1112 | else if (d[i].size == 8) |
| 1113 | val = *((u64 *) d[i].addr); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1114 | |
| 1115 | pos += sprintf(p + pos, "%s=%d\n", d[i].name, val); |
| 1116 | } |
| 1117 | |
| 1118 | res = simple_read_from_buffer(userbuf, count, ppos, p, pos); |
| 1119 | |
| 1120 | free_page(addr); |
| 1121 | return res; |
| 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * @brief proc write function |
| 1126 | * |
| 1127 | * @param f file pointer |
| 1128 | * @param buf pointer to data buffer |
| 1129 | * @param cnt data number to write |
| 1130 | * @param data data to write |
| 1131 | * @return number of data |
| 1132 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1133 | static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1134 | size_t cnt, loff_t *ppos) |
| 1135 | { |
| 1136 | int r, i; |
| 1137 | char *pdata; |
| 1138 | char *p; |
| 1139 | char *p0; |
| 1140 | char *p1; |
| 1141 | char *p2; |
| 1142 | struct debug_data *d = (struct debug_data *)f->private_data; |
| 1143 | |
Jesper Juhl | 655b4d1 | 2007-08-24 11:48:16 -0400 | [diff] [blame] | 1144 | pdata = kmalloc(cnt, GFP_KERNEL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1145 | if (pdata == NULL) |
| 1146 | return 0; |
| 1147 | |
| 1148 | if (copy_from_user(pdata, buf, cnt)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1149 | lbs_deb_debugfs("Copy from user failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1150 | kfree(pdata); |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
| 1154 | p0 = pdata; |
| 1155 | for (i = 0; i < num_of_items; i++) { |
| 1156 | do { |
| 1157 | p = strstr(p0, d[i].name); |
| 1158 | if (p == NULL) |
| 1159 | break; |
| 1160 | p1 = strchr(p, '\n'); |
| 1161 | if (p1 == NULL) |
| 1162 | break; |
| 1163 | p0 = p1++; |
| 1164 | p2 = strchr(p, '='); |
| 1165 | if (!p2) |
| 1166 | break; |
| 1167 | p2++; |
Tony Breeds | d2f11e0 | 2007-03-09 13:11:46 +1100 | [diff] [blame] | 1168 | r = simple_strtoul(p2, NULL, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1169 | if (d[i].size == 1) |
| 1170 | *((u8 *) d[i].addr) = (u8) r; |
| 1171 | else if (d[i].size == 2) |
| 1172 | *((u16 *) d[i].addr) = (u16) r; |
| 1173 | else if (d[i].size == 4) |
| 1174 | *((u32 *) d[i].addr) = (u32) r; |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 1175 | else if (d[i].size == 8) |
| 1176 | *((u64 *) d[i].addr) = (u64) r; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1177 | break; |
| 1178 | } while (1); |
| 1179 | } |
| 1180 | kfree(pdata); |
| 1181 | |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 1182 | return (ssize_t)cnt; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1183 | } |
| 1184 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1185 | static struct file_operations lbs_debug_fops = { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1186 | .owner = THIS_MODULE, |
| 1187 | .open = open_file_generic, |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1188 | .write = lbs_debugfs_write, |
| 1189 | .read = lbs_debugfs_read, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1190 | }; |
| 1191 | |
| 1192 | /** |
| 1193 | * @brief create debug proc file |
| 1194 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1195 | * @param priv pointer struct lbs_private |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1196 | * @param dev pointer net_device |
| 1197 | * @return N/A |
| 1198 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1199 | static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1200 | { |
| 1201 | int i; |
| 1202 | |
| 1203 | if (!priv->debugfs_dir) |
| 1204 | return; |
| 1205 | |
| 1206 | for (i = 0; i < num_of_items; i++) |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 1207 | items[i].addr += (size_t) priv->adapter; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1208 | |
| 1209 | priv->debugfs_debug = debugfs_create_file("debug", 0644, |
| 1210 | priv->debugfs_dir, &items[0], |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1211 | &lbs_debug_fops); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1212 | } |
Holger Schurig | 4686820 | 2007-05-25 00:37:28 -0400 | [diff] [blame] | 1213 | #endif |