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