debugfs.c 49.2 KB
Newer Older
1 2 3 4 5 6
#include <linux/module.h>
#include <linux/dcache.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/mm.h>
#include <net/iw_handler.h>
7

8 9 10
#include "dev.h"
#include "decl.h"
#include "host.h"
11
#include "debugfs.h"
12 13 14 15 16 17 18

static struct dentry *libertas_dir = NULL;
static char *szStates[] = {
	"Connected",
	"Disconnected"
};

19 20 21
#ifdef PROC_DEBUG
static void libertas_debug_init(wlan_private * priv, struct net_device *dev);
#endif
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

static int open_file_generic(struct inode *inode, struct file *file)
{
	file->private_data = inode->i_private;
	return 0;
}

static ssize_t write_file_dummy(struct file *file, const char __user *buf,
                                size_t count, loff_t *ppos)
{
        return -EINVAL;
}

static const size_t len = PAGE_SIZE;

static ssize_t libertas_dev_info(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	size_t pos = 0;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;
	ssize_t res;

	pos += snprintf(buf+pos, len-pos, "state = %s\n",
				szStates[priv->adapter->connect_status]);
	pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
				(u32) priv->adapter->regioncode);

	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);

	free_page(addr);
	return res;
}


static ssize_t libertas_getscantable(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	size_t pos = 0;
	int numscansdone = 0, res;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;
66
	struct bss_descriptor * iter_bss;
67 68 69 70

	pos += snprintf(buf+pos, len-pos,
		"# | ch  | ss  |       bssid       |   cap    |    TSF   | Qual | SSID \n");

71 72
	mutex_lock(&priv->adapter->lock);
	list_for_each_entry (iter_bss, &priv->adapter->network_list, list) {
73 74
		u16 cap;

75
		memcpy(&cap, &iter_bss->cap, sizeof(cap));
76
		pos += snprintf(buf+pos, len-pos,
77
			"%02u| %03d | %03ld | " MAC_FMT " |",
78
			numscansdone, iter_bss->channel, iter_bss->rssi,
79
			MAC_ARG(iter_bss->bssid));
80 81
		pos += snprintf(buf+pos, len-pos, " %04x-", cap);
		pos += snprintf(buf+pos, len-pos, "%c%c%c |",
82 83 84 85 86
				iter_bss->cap.ibss ? 'A' : 'I',
				iter_bss->cap.privacy ? 'P' : ' ',
				iter_bss->cap.spectrummgmt ? 'S' : ' ');
		pos += snprintf(buf+pos, len-pos, " %08llx |", iter_bss->networktsf);
		pos += snprintf(buf+pos, len-pos, " %d |", SCAN_RSSI(iter_bss->rssi));
87 88
		pos += snprintf(buf+pos, len-pos, " %s\n",
		                escape_essid(iter_bss->ssid, iter_bss->ssid_len));
89 90 91

		numscansdone++;
	}
92
	mutex_unlock(&priv->adapter->lock);
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);

	free_page(addr);
	return res;
}

static ssize_t libertas_sleepparams_write(struct file *file,
				const char __user *user_buf, size_t count,
				loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	ssize_t buf_size, res;
	int p1, p2, p3, p4, p5, p6;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, user_buf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	res = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
	if (res != 6) {
		res = -EFAULT;
		goto out_unlock;
	}
120 121 122 123 124 125
	priv->adapter->sp.sp_error = p1;
	priv->adapter->sp.sp_offset = p2;
	priv->adapter->sp.sp_stabletime = p3;
	priv->adapter->sp.sp_calcontrol = p4;
	priv->adapter->sp.sp_extsleepclk = p5;
	priv->adapter->sp.sp_reserved = p6;
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

        res = libertas_prepare_and_send_command(priv,
				cmd_802_11_sleep_params,
				cmd_act_set,
				cmd_option_waitforrsp, 0, NULL);

	if (!res)
		res = count;
	else
		res = -EINVAL;

out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_sleepparams_read(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	ssize_t res;
	size_t pos = 0;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

        res = libertas_prepare_and_send_command(priv,
				cmd_802_11_sleep_params,
				cmd_act_get,
				cmd_option_waitforrsp, 0, NULL);
	if (res) {
		res = -EFAULT;
		goto out_unlock;
	}

	pos += snprintf(buf, len, "%d %d %d %d %d %d\n", adapter->sp.sp_error,
			adapter->sp.sp_offset, adapter->sp.sp_stabletime,
			adapter->sp.sp_calcontrol, adapter->sp.sp_extsleepclk,
			adapter->sp.sp_reserved);

	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);

out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_extscan(struct file *file, const char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	ssize_t res, buf_size;
	union iwreq_data wrqu;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}

188
	libertas_send_specific_SSID_scan(priv, buf, strlen(buf)-1, 0);
189 190

	memset(&wrqu, 0, sizeof(union iwreq_data));
191
	wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244

out_unlock:
	free_page(addr);
	return count;
}

static int libertas_parse_chan(char *buf, size_t count,
			struct wlan_ioctl_user_scan_cfg *scan_cfg, int dur)
{
	char *start, *end, *hold, *str;
	int i = 0;

	start = strstr(buf, "chan=");
	if (!start)
		return -EINVAL;
	start += 5;
	end = strstr(start, " ");
	if (!end)
		end = buf + count;
	hold = kzalloc((end - start)+1, GFP_KERNEL);
	if (!hold)
		return -ENOMEM;
	strncpy(hold, start, end - start);
	hold[(end-start)+1] = '\0';
	while(hold && (str = strsep(&hold, ","))) {
		int chan;
		char band, passive = 0;
		sscanf(str, "%d%c%c", &chan, &band, &passive);
		scan_cfg->chanlist[i].channumber = chan;
		scan_cfg->chanlist[i].scantype = passive ? 1 : 0;
		if (band == 'b' || band == 'g')
			scan_cfg->chanlist[i].radiotype = 0;
		else if (band == 'a')
			scan_cfg->chanlist[i].radiotype = 1;

		scan_cfg->chanlist[i].scantime = dur;
		i++;
	}

	kfree(hold);
	return i;
}

static void libertas_parse_bssid(char *buf, size_t count,
                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
{
	char *hold;
	unsigned int mac[ETH_ALEN];

	hold = strstr(buf, "bssid=");
	if (!hold)
		return;
	hold += 6;
245 246
	sscanf(hold, MAC_FMT, mac, mac+1, mac+2, mac+3, mac+4, mac+5);
	memcpy(scan_cfg->bssid, mac, ETH_ALEN);
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
}

static void libertas_parse_ssid(char *buf, size_t count,
                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
{
	char *hold, *end;
	ssize_t size;

	hold = strstr(buf, "ssid=");
	if (!hold)
		return;
	hold += 5;
	end = strstr(hold, " ");
	if (!end)
		end = buf + count - 1;

D
Dan Williams 已提交
263
	size = min((size_t)IW_ESSID_MAX_SIZE, (size_t) (end - hold));
264
	strncpy(scan_cfg->ssid, hold, size);
265 266 267 268

	return;
}

269
static int libertas_parse_clear(char *buf, size_t count, const char *tag)
270 271 272 273
{
	char *hold;
	int val;

274
	hold = strstr(buf, tag);
275
	if (!hold)
276 277
		return 0;
	hold += strlen(tag);
278 279 280 281 282
	sscanf(hold, "%d", &val);

	if (val != 0)
		val = 1;

283
	return val;
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
}

static int libertas_parse_dur(char *buf, size_t count,
                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
{
	char *hold;
	int val;

	hold = strstr(buf, "dur=");
	if (!hold)
		return 0;
	hold += 4;
	sscanf(hold, "%d", &val);

	return val;
}

static void libertas_parse_probes(char *buf, size_t count,
                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
{
	char *hold;
	int val;

	hold = strstr(buf, "probes=");
	if (!hold)
		return;
	hold += 7;
	sscanf(hold, "%d", &val);

	scan_cfg->numprobes = val;

	return;
}

static void libertas_parse_type(char *buf, size_t count,
                        struct wlan_ioctl_user_scan_cfg *scan_cfg)
{
	char *hold;
	int val;

	hold = strstr(buf, "type=");
	if (!hold)
		return;
	hold += 5;
	sscanf(hold, "%d", &val);

	/* type=1,2 or 3 */
	if (val < 1 || val > 3)
		return;

	scan_cfg->bsstype = val;

	return;
}

static ssize_t libertas_setuserscan(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	ssize_t res, buf_size;
	struct wlan_ioctl_user_scan_cfg *scan_cfg;
	union iwreq_data wrqu;
	int dur;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	scan_cfg = kzalloc(sizeof(struct wlan_ioctl_user_scan_cfg), GFP_KERNEL);
	if (!scan_cfg)
		return -ENOMEM;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}

	scan_cfg->bsstype = WLAN_SCAN_BSS_TYPE_ANY;

	dur = libertas_parse_dur(buf, count, scan_cfg);
	libertas_parse_chan(buf, count, scan_cfg, dur);
	libertas_parse_bssid(buf, count, scan_cfg);
366
	scan_cfg->clear_bssid = libertas_parse_clear(buf, count, "clear_bssid=");
367
	libertas_parse_ssid(buf, count, scan_cfg);
368
	scan_cfg->clear_ssid = libertas_parse_clear(buf, count, "clear_ssid=");
369 370 371
	libertas_parse_probes(buf, count, scan_cfg);
	libertas_parse_type(buf, count, scan_cfg);

372
	wlan_scan_networks(priv, scan_cfg, 1);
373 374 375 376
	wait_event_interruptible(priv->adapter->cmd_pending,
				 !priv->adapter->nr_cmd_pending);

	memset(&wrqu, 0x00, sizeof(union iwreq_data));
377
	wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
378 379 380 381 382 383 384 385 386 387 388 389 390 391

out_unlock:
	free_page(addr);
	kfree(scan_cfg);
	return count;
}

static int libertas_event_initcmd(wlan_private *priv, void **response_buf,
			struct cmd_ctrl_node **cmdnode,
			struct cmd_ds_command **cmd)
{
	u16 wait_option = cmd_option_waitforrsp;

	if (!(*cmdnode = libertas_get_free_cmd_ctrl_node(priv))) {
392
		lbs_deb_debugfs("failed libertas_get_free_cmd_ctrl_node\n");
393 394 395
		return -ENOMEM;
	}
	if (!(*response_buf = kmalloc(3000, GFP_KERNEL))) {
396
		lbs_deb_debugfs("failed to allocate response buffer!\n");
397 398 399 400 401 402 403 404
		return -ENOMEM;
	}
	libertas_set_cmd_ctrl_node(priv, *cmdnode, 0, wait_option, NULL);
	init_waitqueue_head(&(*cmdnode)->cmdwait_q);
	(*cmdnode)->pdata_buf = *response_buf;
	(*cmdnode)->cmdflags |= CMD_F_HOSTCMD;
	(*cmdnode)->cmdwaitqwoken = 0;
	*cmd = (struct cmd_ds_command *)(*cmdnode)->bufvirtualaddr;
405 406
	(*cmd)->command = cpu_to_le16(cmd_802_11_subscribe_event);
	(*cmd)->seqnum = cpu_to_le16(++priv->adapter->seqnum);
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
	(*cmd)->result = 0;
	return 0;
}

static ssize_t libertas_lowrssi_read(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	void *response_buf;
	int res, cmd_len;
	ssize_t pos = 0;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0) {
		free_page(addr);
		return res;
	}

	event = &pcmdptr->params.subscribe_event;
432 433
	event->action = cpu_to_le16(cmd_act_get);
	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
434 435 436 437 438
	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
439
				 pcmdnode->cmdwaitqwoken);
440 441 442

	pcmdptr = response_buf;
	if (pcmdptr->result) {
443 444
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
445 446 447 448 449
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

450
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
451 452 453 454 455 456 457
		lbs_pr_err("command response incorrect!\n");
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
458 459 460 461
	event = (void *)(response_buf + S_DS_GEN);
	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
		switch (header->type) {
462
		struct mrvlietypes_rssithreshold  *Lowrssi;
463 464 465 466 467 468
		case __constant_cpu_to_le16(TLV_TYPE_RSSI_LOW):
			Lowrssi = (void *)(response_buf + cmd_len);
			pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
					Lowrssi->rssivalue,
					Lowrssi->rssifreq,
					(event->events & cpu_to_le16(0x0001))?1:0);
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
		default:
			cmd_len += sizeof(struct mrvlietypes_snrthreshold);
			break;
		}
	}

	kfree(response_buf);
	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	free_page(addr);
	return res;
}

static u16 libertas_get_events_bitmap(wlan_private *priv)
{
	wlan_adapter *adapter = priv->adapter;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	void *response_buf;
	int res;
	u16 event_bitmap;

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0)
		return res;

	event = &pcmdptr->params.subscribe_event;
496 497
	event->action = cpu_to_le16(cmd_act_get);
	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
498 499 500 501 502
	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
503
				 pcmdnode->cmdwaitqwoken);
504 505 506 507

	pcmdptr = response_buf;

	if (pcmdptr->result) {
508 509
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
510 511 512 513 514 515 516 517 518 519 520
		kfree(response_buf);
		return 0;
	}

	if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
		lbs_pr_err("command response incorrect!\n");
		kfree(response_buf);
		return 0;
	}

	event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
521
	event_bitmap = le16_to_cpu(event->events);
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
	kfree(response_buf);
	return event_bitmap;
}

static ssize_t libertas_lowrssi_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	ssize_t res, buf_size;
	int value, freq, subscribed, cmd_len;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	struct mrvlietypes_rssithreshold *rssi_threshold;
	void *response_buf;
	u16 event_bitmap;
	u8 *ptr;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
	if (res != 3) {
		res = -EFAULT;
		goto out_unlock;
	}

	event_bitmap = libertas_get_events_bitmap(priv);

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0)
		goto out_unlock;

	event = &pcmdptr->params.subscribe_event;
562
	event->action = cpu_to_le16(cmd_act_set);
563 564 565 566 567 568 569 570
	pcmdptr->size = cpu_to_le16(S_DS_GEN +
		sizeof(struct cmd_ds_802_11_subscribe_event) +
		sizeof(struct mrvlietypes_rssithreshold));

	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
	ptr = (u8*) pcmdptr+cmd_len;
	rssi_threshold = (struct mrvlietypes_rssithreshold *)(ptr);
	rssi_threshold->header.type = cpu_to_le16(0x0104);
571 572 573
	rssi_threshold->header.len = cpu_to_le16(2);
	rssi_threshold->rssivalue = value;
	rssi_threshold->rssifreq = freq;
574
	event_bitmap |= subscribed ? 0x0001 : 0x0;
575
	event->events = cpu_to_le16(event_bitmap);
576 577 578 579 580 581

	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
582
				 pcmdnode->cmdwaitqwoken);
583 584 585 586

	pcmdptr = response_buf;

	if (pcmdptr->result) {
587 588
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
589 590 591 592 593
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

594
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
		lbs_pr_err("command response incorrect!\n");
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

	res = count;
out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_lowsnr_read(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	void *response_buf;
	int res, cmd_len;
	ssize_t pos = 0;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0) {
		free_page(addr);
		return res;
	}

	event = &pcmdptr->params.subscribe_event;
628 629
	event->action = cpu_to_le16(cmd_act_get);
	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
630 631 632 633 634
	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
635
				 pcmdnode->cmdwaitqwoken);
636 637 638 639

	pcmdptr = response_buf;

	if (pcmdptr->result) {
640 641
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
642 643 644 645 646
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

647
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
648 649 650 651 652 653 654
		lbs_pr_err("command response incorrect!\n");
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
655 656 657 658
	event = (void *)(response_buf + S_DS_GEN);
	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
		switch (header->type) {
659
		struct mrvlietypes_snrthreshold *LowSnr;
660 661 662 663 664 665
		case __constant_cpu_to_le16(TLV_TYPE_SNR_LOW):
			LowSnr = (void *)(response_buf + cmd_len);
			pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
					LowSnr->snrvalue,
					LowSnr->snrfreq,
					(event->events & cpu_to_le16(0x0002))?1:0);
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
		default:
			cmd_len += sizeof(struct mrvlietypes_snrthreshold);
			break;
		}
	}

	kfree(response_buf);

	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	free_page(addr);
	return res;
}

static ssize_t libertas_lowsnr_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	ssize_t res, buf_size;
	int value, freq, subscribed, cmd_len;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	struct mrvlietypes_snrthreshold *snr_threshold;
	void *response_buf;
	u16 event_bitmap;
	u8 *ptr;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
	if (res != 3) {
		res = -EFAULT;
		goto out_unlock;
	}

	event_bitmap = libertas_get_events_bitmap(priv);

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0)
		goto out_unlock;

	event = &pcmdptr->params.subscribe_event;
715
	event->action = cpu_to_le16(cmd_act_set);
716 717 718 719 720 721 722
	pcmdptr->size = cpu_to_le16(S_DS_GEN +
		sizeof(struct cmd_ds_802_11_subscribe_event) +
		sizeof(struct mrvlietypes_snrthreshold));
	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
	ptr = (u8*) pcmdptr+cmd_len;
	snr_threshold = (struct mrvlietypes_snrthreshold *)(ptr);
	snr_threshold->header.type = cpu_to_le16(TLV_TYPE_SNR_LOW);
723 724 725
	snr_threshold->header.len = cpu_to_le16(2);
	snr_threshold->snrvalue = value;
	snr_threshold->snrfreq = freq;
726
	event_bitmap |= subscribed ? 0x0002 : 0x0;
727
	event->events = cpu_to_le16(event_bitmap);
728 729 730 731 732 733

	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
734
				 pcmdnode->cmdwaitqwoken);
735 736 737 738

	pcmdptr = response_buf;

	if (pcmdptr->result) {
739 740
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
741 742 743 744 745
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

746
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
		lbs_pr_err("command response incorrect!\n");
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

	res = count;

out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_failcount_read(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	void *response_buf;
	int res, cmd_len;
	ssize_t pos = 0;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0) {
		free_page(addr);
		return res;
	}

	event = &pcmdptr->params.subscribe_event;
781 782
	event->action = cpu_to_le16(cmd_act_get);
	pcmdptr->size =	cpu_to_le16(sizeof(*event) + S_DS_GEN);
783 784 785 786 787
	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
788
				 pcmdnode->cmdwaitqwoken);
789 790 791 792

	pcmdptr = response_buf;

	if (pcmdptr->result) {
793 794
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
795 796 797 798 799
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

800
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
801 802 803 804 805 806 807
		lbs_pr_err("command response incorrect!\n");
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
808 809 810 811
	event = (void *)(response_buf + S_DS_GEN);
	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
		switch (header->type) {
812
		struct mrvlietypes_failurecount *failcount;
813 814 815 816 817 818
		case __constant_cpu_to_le16(TLV_TYPE_FAILCOUNT):
			failcount = (void *)(response_buf + cmd_len);
			pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
					failcount->failvalue,
					failcount->Failfreq,
					(event->events & cpu_to_le16(0x0004))?1:0);
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
		default:
			cmd_len += sizeof(struct mrvlietypes_failurecount);
			break;
		}
	}

	kfree(response_buf);
	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	free_page(addr);
	return res;
}

static ssize_t libertas_failcount_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	ssize_t res, buf_size;
	int value, freq, subscribed, cmd_len;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	struct mrvlietypes_failurecount *failcount;
	void *response_buf;
	u16 event_bitmap;
	u8 *ptr;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
	if (res != 3) {
		res = -EFAULT;
		goto out_unlock;
	}

	event_bitmap = libertas_get_events_bitmap(priv);

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0)
		goto out_unlock;

	event = &pcmdptr->params.subscribe_event;
867
	event->action = cpu_to_le16(cmd_act_set);
868 869 870 871 872 873 874
	pcmdptr->size = cpu_to_le16(S_DS_GEN +
		sizeof(struct cmd_ds_802_11_subscribe_event) +
		sizeof(struct mrvlietypes_failurecount));
	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
	ptr = (u8*) pcmdptr+cmd_len;
	failcount = (struct mrvlietypes_failurecount *)(ptr);
	failcount->header.type = cpu_to_le16(TLV_TYPE_FAILCOUNT);
875 876 877
	failcount->header.len = cpu_to_le16(2);
	failcount->failvalue = value;
	failcount->Failfreq = freq;
878
	event_bitmap |= subscribed ? 0x0004 : 0x0;
879
	event->events = cpu_to_le16(event_bitmap);
880 881 882 883 884 885

	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
886
				 pcmdnode->cmdwaitqwoken);
887 888 889 890

	pcmdptr = (struct cmd_ds_command *)response_buf;

	if (pcmdptr->result) {
891 892
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
893 894 895 896 897
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

898
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
		lbs_pr_err("command response incorrect!\n");
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

	res = count;
out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_bcnmiss_read(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	void *response_buf;
	int res, cmd_len;
	ssize_t pos = 0;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0) {
		free_page(addr);
		return res;
	}

	event = &pcmdptr->params.subscribe_event;
932 933
	event->action = cpu_to_le16(cmd_act_get);
	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
934 935 936 937 938
	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
939
				 pcmdnode->cmdwaitqwoken);
940 941 942 943

	pcmdptr = response_buf;

	if (pcmdptr->result) {
944 945
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
946 947 948 949 950
		free_page(addr);
		kfree(response_buf);
		return 0;
	}

951
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
952 953 954 955 956 957 958
		lbs_pr_err("command response incorrect!\n");
		free_page(addr);
		kfree(response_buf);
		return 0;
	}

	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
959 960 961 962
	event = (void *)(response_buf + S_DS_GEN);
	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
		switch (header->type) {
963
		struct mrvlietypes_beaconsmissed *bcnmiss;
964 965 966 967 968
		case __constant_cpu_to_le16(TLV_TYPE_BCNMISS):
			bcnmiss = (void *)(response_buf + cmd_len);
			pos += snprintf(buf+pos, len-pos, "%d N/A %d\n",
					bcnmiss->beaconmissed,
					(event->events & cpu_to_le16(0x0008))?1:0);
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
		default:
			cmd_len += sizeof(struct mrvlietypes_beaconsmissed);
			break;
		}
	}

	kfree(response_buf);

	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	free_page(addr);
	return res;
}

static ssize_t libertas_bcnmiss_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	ssize_t res, buf_size;
	int value, freq, subscribed, cmd_len;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	struct mrvlietypes_beaconsmissed *bcnmiss;
	void *response_buf;
	u16 event_bitmap;
	u8 *ptr;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
	if (res != 3) {
		res = -EFAULT;
		goto out_unlock;
	}

	event_bitmap = libertas_get_events_bitmap(priv);

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0)
		goto out_unlock;

	event = &pcmdptr->params.subscribe_event;
1018
	event->action = cpu_to_le16(cmd_act_set);
1019 1020 1021 1022 1023 1024 1025
	pcmdptr->size = cpu_to_le16(S_DS_GEN +
		sizeof(struct cmd_ds_802_11_subscribe_event) +
		sizeof(struct mrvlietypes_beaconsmissed));
	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
	ptr = (u8*) pcmdptr+cmd_len;
	bcnmiss = (struct mrvlietypes_beaconsmissed *)(ptr);
	bcnmiss->header.type = cpu_to_le16(TLV_TYPE_BCNMISS);
1026 1027
	bcnmiss->header.len = cpu_to_le16(2);
	bcnmiss->beaconmissed = value;
1028
	event_bitmap |= subscribed ? 0x0008 : 0x0;
1029
	event->events = cpu_to_le16(event_bitmap);
1030 1031 1032 1033 1034 1035

	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
1036
				 pcmdnode->cmdwaitqwoken);
1037 1038 1039 1040

	pcmdptr = response_buf;

	if (pcmdptr->result) {
1041 1042
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
1043 1044 1045 1046 1047
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

1048
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
		lbs_pr_err("command response incorrect!\n");
		free_page(addr);
		kfree(response_buf);
		return 0;
	}

	res = count;
out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_highrssi_read(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	void *response_buf;
	int res, cmd_len;
	ssize_t pos = 0;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0) {
		free_page(addr);
		return res;
	}

	event = &pcmdptr->params.subscribe_event;
1082 1083
	event->action = cpu_to_le16(cmd_act_get);
	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
1084 1085 1086 1087 1088
	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
1089
				 pcmdnode->cmdwaitqwoken);
1090 1091 1092 1093

	pcmdptr = response_buf;

	if (pcmdptr->result) {
1094 1095
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
1096 1097 1098 1099 1100
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

1101
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
1102 1103 1104 1105 1106 1107 1108
		lbs_pr_err("command response incorrect!\n");
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
1109 1110 1111 1112
	event = (void *)(response_buf + S_DS_GEN);
	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
		switch (header->type) {
1113
		struct mrvlietypes_rssithreshold  *Highrssi;
1114 1115 1116 1117 1118 1119
		case __constant_cpu_to_le16(TLV_TYPE_RSSI_HIGH):
			Highrssi = (void *)(response_buf + cmd_len);
			pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
					Highrssi->rssivalue,
					Highrssi->rssifreq,
					(event->events & cpu_to_le16(0x0010))?1:0);
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
		default:
			cmd_len += sizeof(struct mrvlietypes_snrthreshold);
			break;
		}
	}

	kfree(response_buf);

	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	free_page(addr);
	return res;
}

static ssize_t libertas_highrssi_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	ssize_t res, buf_size;
	int value, freq, subscribed, cmd_len;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	struct mrvlietypes_rssithreshold *rssi_threshold;
	void *response_buf;
	u16 event_bitmap;
	u8 *ptr;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
	if (res != 3) {
		res = -EFAULT;
		goto out_unlock;
	}

	event_bitmap = libertas_get_events_bitmap(priv);

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0)
		goto out_unlock;

	event = &pcmdptr->params.subscribe_event;
1169
	event->action = cpu_to_le16(cmd_act_set);
1170 1171 1172 1173 1174 1175 1176
	pcmdptr->size = cpu_to_le16(S_DS_GEN +
		sizeof(struct cmd_ds_802_11_subscribe_event) +
		sizeof(struct mrvlietypes_rssithreshold));
	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
	ptr = (u8*) pcmdptr+cmd_len;
	rssi_threshold = (struct mrvlietypes_rssithreshold *)(ptr);
	rssi_threshold->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
1177 1178 1179
	rssi_threshold->header.len = cpu_to_le16(2);
	rssi_threshold->rssivalue = value;
	rssi_threshold->rssifreq = freq;
1180
	event_bitmap |= subscribed ? 0x0010 : 0x0;
1181
	event->events = cpu_to_le16(event_bitmap);
1182 1183 1184 1185 1186 1187

	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
1188
				 pcmdnode->cmdwaitqwoken);
1189 1190 1191 1192

	pcmdptr = response_buf;

	if (pcmdptr->result) {
1193 1194
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
1195 1196 1197 1198
		kfree(response_buf);
		return 0;
	}

1199
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
		lbs_pr_err("command response incorrect!\n");
		kfree(response_buf);
		return 0;
	}

	res = count;
out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_highsnr_read(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	void *response_buf;
	int res, cmd_len;
	ssize_t pos = 0;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0) {
		free_page(addr);
		return res;
	}

	event = &pcmdptr->params.subscribe_event;
1232 1233
	event->action = cpu_to_le16(cmd_act_get);
	pcmdptr->size = cpu_to_le16(sizeof(*event) + S_DS_GEN);
1234 1235 1236 1237 1238
	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
1239
				 pcmdnode->cmdwaitqwoken);
1240 1241 1242 1243

	pcmdptr = response_buf;

	if (pcmdptr->result) {
1244 1245
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
1246 1247 1248 1249 1250
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

1251
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
1252 1253 1254 1255 1256 1257 1258
		lbs_pr_err("command response incorrect!\n");
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
1259 1260 1261 1262
	event = (void *)(response_buf + S_DS_GEN);
	while (cmd_len < le16_to_cpu(pcmdptr->size)) {
		struct mrvlietypesheader *header = (void *)(response_buf + cmd_len);
		switch (header->type) {
1263
		struct mrvlietypes_snrthreshold *HighSnr;
1264 1265 1266 1267 1268 1269
		case __constant_cpu_to_le16(TLV_TYPE_SNR_HIGH):
			HighSnr = (void *)(response_buf + cmd_len);
			pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
					HighSnr->snrvalue,
					HighSnr->snrfreq,
					(event->events & cpu_to_le16(0x0020))?1:0);
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
		default:
			cmd_len += sizeof(struct mrvlietypes_snrthreshold);
			break;
		}
	}

	kfree(response_buf);

	res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	free_page(addr);
	return res;
}

static ssize_t libertas_highsnr_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	ssize_t res, buf_size;
	int value, freq, subscribed, cmd_len;
	struct cmd_ctrl_node *pcmdnode;
	struct cmd_ds_command *pcmdptr;
	struct cmd_ds_802_11_subscribe_event *event;
	struct mrvlietypes_snrthreshold *snr_threshold;
	void *response_buf;
	u16 event_bitmap;
	u8 *ptr;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
	if (res != 3) {
		res = -EFAULT;
		goto out_unlock;
	}

	event_bitmap = libertas_get_events_bitmap(priv);

	res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
	if (res < 0)
		goto out_unlock;

	event = &pcmdptr->params.subscribe_event;
1319
	event->action = cpu_to_le16(cmd_act_set);
1320 1321 1322 1323 1324 1325 1326
	pcmdptr->size = cpu_to_le16(S_DS_GEN +
		sizeof(struct cmd_ds_802_11_subscribe_event) +
		sizeof(struct mrvlietypes_snrthreshold));
	cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
	ptr = (u8*) pcmdptr+cmd_len;
	snr_threshold = (struct mrvlietypes_snrthreshold *)(ptr);
	snr_threshold->header.type = cpu_to_le16(TLV_TYPE_SNR_HIGH);
1327 1328 1329
	snr_threshold->header.len = cpu_to_le16(2);
	snr_threshold->snrvalue = value;
	snr_threshold->snrfreq = freq;
1330
	event_bitmap |= subscribed ? 0x0020 : 0x0;
1331
	event->events = cpu_to_le16(event_bitmap);
1332 1333 1334 1335 1336 1337

	libertas_queue_cmd(adapter, pcmdnode, 1);
	wake_up_interruptible(&priv->mainthread.waitq);

	/* Sleep until response is generated by FW */
	wait_event_interruptible(pcmdnode->cmdwait_q,
1338
				 pcmdnode->cmdwaitqwoken);
1339 1340 1341 1342

	pcmdptr = response_buf;

	if (pcmdptr->result) {
1343 1344
		lbs_pr_err("%s: fail, result=%d\n", __func__,
			   le16_to_cpu(pcmdptr->result));
1345 1346 1347 1348 1349
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

1350
	if (pcmdptr->command != cpu_to_le16(cmd_ret_802_11_subscribe_event)) {
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626
		lbs_pr_err("command response incorrect!\n");
		kfree(response_buf);
		free_page(addr);
		return 0;
	}

	res = count;
out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_rdmac_read(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	struct wlan_offset_value offval;
	ssize_t pos = 0;
	int ret;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	offval.offset = priv->mac_offset;
	offval.value = 0;

	ret = libertas_prepare_and_send_command(priv,
				cmd_mac_reg_access, 0,
				cmd_option_waitforrsp, 0, &offval);
	mdelay(10);
	pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
				priv->mac_offset, adapter->offsetvalue.value);

	ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	free_page(addr);
	return ret;
}

static ssize_t libertas_rdmac_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	ssize_t res, buf_size;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
	res = count;
out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_wrmac_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{

	wlan_private *priv = file->private_data;
	ssize_t res, buf_size;
	u32 offset, value;
	struct wlan_offset_value offval;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	res = sscanf(buf, "%x %x", &offset, &value);
	if (res != 2) {
		res = -EFAULT;
		goto out_unlock;
	}

	offval.offset = offset;
	offval.value = value;
	res = libertas_prepare_and_send_command(priv,
				cmd_mac_reg_access, 1,
				cmd_option_waitforrsp, 0, &offval);
	mdelay(10);

	res = count;
out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_rdbbp_read(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	struct wlan_offset_value offval;
	ssize_t pos = 0;
	int ret;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	offval.offset = priv->bbp_offset;
	offval.value = 0;

	ret = libertas_prepare_and_send_command(priv,
				cmd_bbp_reg_access, 0,
				cmd_option_waitforrsp, 0, &offval);
	mdelay(10);
	pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
				priv->bbp_offset, adapter->offsetvalue.value);

	ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	free_page(addr);

	return ret;
}

static ssize_t libertas_rdbbp_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	ssize_t res, buf_size;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
	res = count;
out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_wrbbp_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{

	wlan_private *priv = file->private_data;
	ssize_t res, buf_size;
	u32 offset, value;
	struct wlan_offset_value offval;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	res = sscanf(buf, "%x %x", &offset, &value);
	if (res != 2) {
		res = -EFAULT;
		goto out_unlock;
	}

	offval.offset = offset;
	offval.value = value;
	res = libertas_prepare_and_send_command(priv,
				cmd_bbp_reg_access, 1,
				cmd_option_waitforrsp, 0, &offval);
	mdelay(10);

	res = count;
out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_rdrf_read(struct file *file, char __user *userbuf,
				  size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	wlan_adapter *adapter = priv->adapter;
	struct wlan_offset_value offval;
	ssize_t pos = 0;
	int ret;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	offval.offset = priv->rf_offset;
	offval.value = 0;

	ret = libertas_prepare_and_send_command(priv,
				cmd_rf_reg_access, 0,
				cmd_option_waitforrsp, 0, &offval);
	mdelay(10);
	pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
				priv->rf_offset, adapter->offsetvalue.value);

	ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
	free_page(addr);

	return ret;
}

static ssize_t libertas_rdrf_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{
	wlan_private *priv = file->private_data;
	ssize_t res, buf_size;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
	res = count;
out_unlock:
	free_page(addr);
	return res;
}

static ssize_t libertas_wrrf_write(struct file *file,
				    const char __user *userbuf,
				    size_t count, loff_t *ppos)
{

	wlan_private *priv = file->private_data;
	ssize_t res, buf_size;
	u32 offset, value;
	struct wlan_offset_value offval;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	buf_size = min(count, len - 1);
	if (copy_from_user(buf, userbuf, buf_size)) {
		res = -EFAULT;
		goto out_unlock;
	}
	res = sscanf(buf, "%x %x", &offset, &value);
	if (res != 2) {
		res = -EFAULT;
		goto out_unlock;
	}

	offval.offset = offset;
	offval.value = value;
	res = libertas_prepare_and_send_command(priv,
				cmd_rf_reg_access, 1,
				cmd_option_waitforrsp, 0, &offval);
	mdelay(10);

	res = count;
out_unlock:
	free_page(addr);
	return res;
}

#define FOPS(fread, fwrite) { \
	.owner = THIS_MODULE, \
	.open = open_file_generic, \
	.read = (fread), \
	.write = (fwrite), \
}

struct libertas_debugfs_files {
	char *name;
	int perm;
	struct file_operations fops;
};

1627
static struct libertas_debugfs_files debugfs_files[] = {
1628 1629 1630 1631 1632 1633 1634 1635 1636
	{ "info", 0444, FOPS(libertas_dev_info, write_file_dummy), },
	{ "getscantable", 0444, FOPS(libertas_getscantable,
					write_file_dummy), },
	{ "sleepparams", 0644, FOPS(libertas_sleepparams_read,
				libertas_sleepparams_write), },
	{ "extscan", 0600, FOPS(NULL, libertas_extscan), },
	{ "setuserscan", 0600, FOPS(NULL, libertas_setuserscan), },
};

1637
static struct libertas_debugfs_files debugfs_events_files[] = {
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
	{"low_rssi", 0644, FOPS(libertas_lowrssi_read,
				libertas_lowrssi_write), },
	{"low_snr", 0644, FOPS(libertas_lowsnr_read,
				libertas_lowsnr_write), },
	{"failure_count", 0644, FOPS(libertas_failcount_read,
				libertas_failcount_write), },
	{"beacon_missed", 0644, FOPS(libertas_bcnmiss_read,
				libertas_bcnmiss_write), },
	{"high_rssi", 0644, FOPS(libertas_highrssi_read,
				libertas_highrssi_write), },
	{"high_snr", 0644, FOPS(libertas_highsnr_read,
				libertas_highsnr_write), },
};

1652
static struct libertas_debugfs_files debugfs_regs_files[] = {
1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737
	{"rdmac", 0644, FOPS(libertas_rdmac_read, libertas_rdmac_write), },
	{"wrmac", 0600, FOPS(NULL, libertas_wrmac_write), },
	{"rdbbp", 0644, FOPS(libertas_rdbbp_read, libertas_rdbbp_write), },
	{"wrbbp", 0600, FOPS(NULL, libertas_wrbbp_write), },
	{"rdrf", 0644, FOPS(libertas_rdrf_read, libertas_rdrf_write), },
	{"wrrf", 0600, FOPS(NULL, libertas_wrrf_write), },
};

void libertas_debugfs_init(void)
{
	if (!libertas_dir)
		libertas_dir = debugfs_create_dir("libertas_wireless", NULL);

	return;
}

void libertas_debugfs_remove(void)
{
	if (libertas_dir)
		 debugfs_remove(libertas_dir);
	return;
}

void libertas_debugfs_init_one(wlan_private *priv, struct net_device *dev)
{
	int i;
	struct libertas_debugfs_files *files;
	if (!libertas_dir)
		goto exit;

	priv->debugfs_dir = debugfs_create_dir(dev->name, libertas_dir);
	if (!priv->debugfs_dir)
		goto exit;

	for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
		files = &debugfs_files[i];
		priv->debugfs_files[i] = debugfs_create_file(files->name,
							     files->perm,
							     priv->debugfs_dir,
							     priv,
							     &files->fops);
	}

	priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
	if (!priv->events_dir)
		goto exit;

	for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
		files = &debugfs_events_files[i];
		priv->debugfs_events_files[i] = debugfs_create_file(files->name,
							     files->perm,
							     priv->events_dir,
							     priv,
							     &files->fops);
	}

	priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
	if (!priv->regs_dir)
		goto exit;

	for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
		files = &debugfs_regs_files[i];
		priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
							     files->perm,
							     priv->regs_dir,
							     priv,
							     &files->fops);
	}

#ifdef PROC_DEBUG
	libertas_debug_init(priv, dev);
#endif
exit:
	return;
}

void libertas_debugfs_remove_one(wlan_private *priv)
{
	int i;

	for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
		debugfs_remove(priv->debugfs_regs_files[i]);

	debugfs_remove(priv->regs_dir);

1738
	for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
1739 1740 1741 1742 1743 1744 1745 1746
		debugfs_remove(priv->debugfs_events_files[i]);

	debugfs_remove(priv->events_dir);
#ifdef PROC_DEBUG
	debugfs_remove(priv->debugfs_debug);
#endif
	for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
		debugfs_remove(priv->debugfs_files[i]);
1747
	debugfs_remove(priv->debugfs_dir);
1748 1749
}

1750 1751


1752 1753
/* debug entry */

1754 1755
#ifdef PROC_DEBUG

1756 1757
#define item_size(n)	(FIELD_SIZEOF(wlan_adapter, n))
#define item_addr(n)	(offsetof(wlan_adapter, n))
1758

1759

1760 1761 1762
struct debug_data {
	char name[32];
	u32 size;
D
Dan Williams 已提交
1763
	size_t addr;
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773
};

/* To debug any member of wlan_adapter, simply add one line here.
 */
static struct debug_data items[] = {
	{"intcounter", item_size(intcounter), item_addr(intcounter)},
	{"psmode", item_size(psmode), item_addr(psmode)},
	{"psstate", item_size(psstate), item_addr(psstate)},
};

1774
static int num_of_items = ARRAY_SIZE(items);
1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809

/**
 *  @brief proc read function
 *
 *  @param page	   pointer to buffer
 *  @param s       read data starting position
 *  @param off     offset
 *  @param cnt     counter
 *  @param eof     end of file flag
 *  @param data    data to output
 *  @return 	   number of output data
 */
static ssize_t wlan_debugfs_read(struct file *file, char __user *userbuf,
			size_t count, loff_t *ppos)
{
	int val = 0;
	size_t pos = 0;
	ssize_t res;
	char *p;
	int i;
	struct debug_data *d;
	unsigned long addr = get_zeroed_page(GFP_KERNEL);
	char *buf = (char *)addr;

	p = buf;

	d = (struct debug_data *)file->private_data;

	for (i = 0; i < num_of_items; i++) {
		if (d[i].size == 1)
			val = *((u8 *) d[i].addr);
		else if (d[i].size == 2)
			val = *((u16 *) d[i].addr);
		else if (d[i].size == 4)
			val = *((u32 *) d[i].addr);
D
Dan Williams 已提交
1810 1811
		else if (d[i].size == 8)
			val = *((u64 *) d[i].addr);
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830

		pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
	}

	res = simple_read_from_buffer(userbuf, count, ppos, p, pos);

	free_page(addr);
	return res;
}

/**
 *  @brief proc write function
 *
 *  @param f	   file pointer
 *  @param buf     pointer to data buffer
 *  @param cnt     data number to write
 *  @param data    data to write
 *  @return 	   number of data
 */
D
Dan Williams 已提交
1831
static ssize_t wlan_debugfs_write(struct file *f, const char __user *buf,
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846
			    size_t cnt, loff_t *ppos)
{
	int r, i;
	char *pdata;
	char *p;
	char *p0;
	char *p1;
	char *p2;
	struct debug_data *d = (struct debug_data *)f->private_data;

	pdata = (char *)kmalloc(cnt, GFP_KERNEL);
	if (pdata == NULL)
		return 0;

	if (copy_from_user(pdata, buf, cnt)) {
1847
		lbs_deb_debugfs("Copy from user failed\n");
1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865
		kfree(pdata);
		return 0;
	}

	p0 = pdata;
	for (i = 0; i < num_of_items; i++) {
		do {
			p = strstr(p0, d[i].name);
			if (p == NULL)
				break;
			p1 = strchr(p, '\n');
			if (p1 == NULL)
				break;
			p0 = p1++;
			p2 = strchr(p, '=');
			if (!p2)
				break;
			p2++;
1866
			r = simple_strtoul(p2, NULL, 0);
1867 1868 1869 1870 1871 1872
			if (d[i].size == 1)
				*((u8 *) d[i].addr) = (u8) r;
			else if (d[i].size == 2)
				*((u16 *) d[i].addr) = (u16) r;
			else if (d[i].size == 4)
				*((u32 *) d[i].addr) = (u32) r;
D
Dan Williams 已提交
1873 1874
			else if (d[i].size == 8)
				*((u64 *) d[i].addr) = (u64) r;
1875 1876 1877 1878 1879
			break;
		} while (1);
	}
	kfree(pdata);

D
Dan Williams 已提交
1880
	return (ssize_t)cnt;
1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896
}

static struct file_operations libertas_debug_fops = {
	.owner = THIS_MODULE,
	.open = open_file_generic,
	.write = wlan_debugfs_write,
	.read = wlan_debugfs_read,
};

/**
 *  @brief create debug proc file
 *
 *  @param priv	   pointer wlan_private
 *  @param dev     pointer net_device
 *  @return 	   N/A
 */
1897
static void libertas_debug_init(wlan_private * priv, struct net_device *dev)
1898 1899 1900 1901 1902 1903 1904
{
	int i;

	if (!priv->debugfs_dir)
		return;

	for (i = 0; i < num_of_items; i++)
D
Dan Williams 已提交
1905
		items[i].addr += (size_t) priv->adapter;
1906 1907 1908 1909 1910

	priv->debugfs_debug = debugfs_create_file("debug", 0644,
						  priv->debugfs_dir, &items[0],
						  &libertas_debug_fops);
}
1911
#endif
1912