1 #include <linux/module.h>
2 #include <linux/dcache.h>
3 #include <linux/debugfs.h>
4 #include <linux/delay.h>
6 #include <net/iw_handler.h>
11 static struct dentry *libertas_dir = NULL;
12 static char *szStates[] = {
17 void libertas_debug_init(wlan_private * priv, struct net_device *dev);
19 static int open_file_generic(struct inode *inode, struct file *file)
21 file->private_data = inode->i_private;
25 static ssize_t write_file_dummy(struct file *file, const char __user *buf,
26 size_t count, loff_t *ppos)
31 static const size_t len = PAGE_SIZE;
33 static ssize_t libertas_dev_info(struct file *file, char __user *userbuf,
34 size_t count, loff_t *ppos)
36 wlan_private *priv = file->private_data;
38 unsigned long addr = get_zeroed_page(GFP_KERNEL);
39 char *buf = (char *)addr;
42 pos += snprintf(buf+pos, len-pos, "state = %s\n",
43 szStates[priv->adapter->connect_status]);
44 pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
45 (u32) priv->adapter->regioncode);
47 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
54 static ssize_t libertas_getscantable(struct file *file, char __user *userbuf,
55 size_t count, loff_t *ppos)
57 wlan_private *priv = file->private_data;
59 int numscansdone = 0, res;
60 unsigned long addr = get_zeroed_page(GFP_KERNEL);
61 char *buf = (char *)addr;
63 pos += snprintf(buf+pos, len-pos,
64 "---------------------------------------");
65 pos += snprintf(buf+pos, len-pos,
66 "---------------------------------------\n");
67 pos += snprintf(buf+pos, len-pos,
68 "# | ch | ss | bssid | cap | TSF | Qual | SSID \n");
69 pos += snprintf(buf+pos, len-pos,
70 "---------------------------------------");
71 pos += snprintf(buf+pos, len-pos,
72 "---------------------------------------\n");
74 while (numscansdone < priv->adapter->numinscantable) {
75 struct bss_descriptor *pbssinfo;
78 pbssinfo = &priv->adapter->scantable[numscansdone];
79 memcpy(&cap, &pbssinfo->cap, sizeof(cap));
80 pos += snprintf(buf+pos, len-pos,
81 "%02u| %03d | %03ld | %02x:%02x:%02x:%02x:%02x:%02x |",
82 numscansdone, pbssinfo->channel, pbssinfo->rssi,
83 pbssinfo->macaddress[0], pbssinfo->macaddress[1],
84 pbssinfo->macaddress[2], pbssinfo->macaddress[3],
85 pbssinfo->macaddress[4], pbssinfo->macaddress[5]);
86 pos += snprintf(buf+pos, len-pos, " %04x-", cap);
87 pos += snprintf(buf+pos, len-pos, "%c%c%c |",
88 pbssinfo->cap.ibss ? 'A' : 'I',
89 pbssinfo->cap.privacy ? 'P' : ' ',
90 pbssinfo->cap.spectrummgmt ? 'S' : ' ');
91 pos += snprintf(buf+pos, len-pos, " %08llx |", pbssinfo->networktsf);
92 pos += snprintf(buf+pos, len-pos, " %d |",
93 SCAN_RSSI(priv->adapter->scantable[numscansdone].rssi));
95 pos += snprintf(buf+pos, len-pos, " %s\n", pbssinfo->ssid.ssid);
100 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
106 static ssize_t libertas_sleepparams_write(struct file *file,
107 const char __user *user_buf, size_t count,
110 wlan_private *priv = file->private_data;
111 ssize_t buf_size, res;
112 int p1, p2, p3, p4, p5, p6;
113 struct sleep_params sp;
114 unsigned long addr = get_zeroed_page(GFP_KERNEL);
115 char *buf = (char *)addr;
117 buf_size = min(count, len - 1);
118 if (copy_from_user(buf, user_buf, buf_size)) {
122 res = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
129 sp.sp_stabletime = p3;
130 sp.sp_calcontrol = p4;
131 sp.sp_extsleepclk = p5;
134 memcpy(&priv->adapter->sp, &sp, sizeof(struct sleep_params));
136 res = libertas_prepare_and_send_command(priv,
137 cmd_802_11_sleep_params,
139 cmd_option_waitforrsp, 0, NULL);
151 static ssize_t libertas_sleepparams_read(struct file *file, char __user *userbuf,
152 size_t count, loff_t *ppos)
154 wlan_private *priv = file->private_data;
155 wlan_adapter *adapter = priv->adapter;
158 unsigned long addr = get_zeroed_page(GFP_KERNEL);
159 char *buf = (char *)addr;
161 res = libertas_prepare_and_send_command(priv,
162 cmd_802_11_sleep_params,
164 cmd_option_waitforrsp, 0, NULL);
170 pos += snprintf(buf, len, "%d %d %d %d %d %d\n", adapter->sp.sp_error,
171 adapter->sp.sp_offset, adapter->sp.sp_stabletime,
172 adapter->sp.sp_calcontrol, adapter->sp.sp_extsleepclk,
173 adapter->sp.sp_reserved);
175 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
182 static ssize_t libertas_extscan(struct file *file, const char __user *userbuf,
183 size_t count, loff_t *ppos)
185 wlan_private *priv = file->private_data;
186 ssize_t res, buf_size;
187 struct WLAN_802_11_SSID extscan_ssid;
188 union iwreq_data wrqu;
189 unsigned long addr = get_zeroed_page(GFP_KERNEL);
190 char *buf = (char *)addr;
192 buf_size = min(count, len - 1);
193 if (copy_from_user(buf, userbuf, buf_size)) {
198 memcpy(&extscan_ssid.ssid, buf, strlen(buf)-1);
199 extscan_ssid.ssidlength = strlen(buf)-1;
201 libertas_send_specific_SSID_scan(priv, &extscan_ssid, 1);
203 memset(&wrqu, 0, sizeof(union iwreq_data));
204 wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu, NULL);
211 static int libertas_parse_chan(char *buf, size_t count,
212 struct wlan_ioctl_user_scan_cfg *scan_cfg, int dur)
214 char *start, *end, *hold, *str;
217 start = strstr(buf, "chan=");
221 end = strstr(start, " ");
224 hold = kzalloc((end - start)+1, GFP_KERNEL);
227 strncpy(hold, start, end - start);
228 hold[(end-start)+1] = '\0';
229 while(hold && (str = strsep(&hold, ","))) {
231 char band, passive = 0;
232 sscanf(str, "%d%c%c", &chan, &band, &passive);
233 scan_cfg->chanlist[i].channumber = chan;
234 scan_cfg->chanlist[i].scantype = passive ? 1 : 0;
235 if (band == 'b' || band == 'g')
236 scan_cfg->chanlist[i].radiotype = 0;
237 else if (band == 'a')
238 scan_cfg->chanlist[i].radiotype = 1;
240 scan_cfg->chanlist[i].scantime = dur;
248 static void libertas_parse_bssid(char *buf, size_t count,
249 struct wlan_ioctl_user_scan_cfg *scan_cfg)
252 unsigned int mac[ETH_ALEN];
255 hold = strstr(buf, "bssid=");
259 sscanf(hold, "%2x:%2x:%2x:%2x:%2x:%2x", mac, mac+1, mac+2, mac+3,
261 for(i=0;i<ETH_ALEN;i++)
262 scan_cfg->specificBSSID[i] = mac[i];
265 static void libertas_parse_ssid(char *buf, size_t count,
266 struct wlan_ioctl_user_scan_cfg *scan_cfg)
271 hold = strstr(buf, "ssid=");
275 end = strstr(hold, " ");
277 end = buf + count - 1;
279 size = min(IW_ESSID_MAX_SIZE, end - hold);
280 strncpy(scan_cfg->specificSSID, hold, size);
285 static void libertas_parse_keep(char *buf, size_t count,
286 struct wlan_ioctl_user_scan_cfg *scan_cfg)
291 hold = strstr(buf, "keep=");
295 sscanf(hold, "%d", &val);
300 scan_cfg->keeppreviousscan = val;
304 static int libertas_parse_dur(char *buf, size_t count,
305 struct wlan_ioctl_user_scan_cfg *scan_cfg)
310 hold = strstr(buf, "dur=");
314 sscanf(hold, "%d", &val);
319 static void libertas_parse_probes(char *buf, size_t count,
320 struct wlan_ioctl_user_scan_cfg *scan_cfg)
325 hold = strstr(buf, "probes=");
329 sscanf(hold, "%d", &val);
331 scan_cfg->numprobes = val;
336 static void libertas_parse_type(char *buf, size_t count,
337 struct wlan_ioctl_user_scan_cfg *scan_cfg)
342 hold = strstr(buf, "type=");
346 sscanf(hold, "%d", &val);
349 if (val < 1 || val > 3)
352 scan_cfg->bsstype = val;
357 static ssize_t libertas_setuserscan(struct file *file,
358 const char __user *userbuf,
359 size_t count, loff_t *ppos)
361 wlan_private *priv = file->private_data;
362 ssize_t res, buf_size;
363 struct wlan_ioctl_user_scan_cfg *scan_cfg;
364 union iwreq_data wrqu;
366 unsigned long addr = get_zeroed_page(GFP_KERNEL);
367 char *buf = (char *)addr;
369 scan_cfg = kzalloc(sizeof(struct wlan_ioctl_user_scan_cfg), GFP_KERNEL);
373 buf_size = min(count, len - 1);
374 if (copy_from_user(buf, userbuf, buf_size)) {
379 scan_cfg->bsstype = WLAN_SCAN_BSS_TYPE_ANY;
381 dur = libertas_parse_dur(buf, count, scan_cfg);
382 libertas_parse_chan(buf, count, scan_cfg, dur);
383 libertas_parse_bssid(buf, count, scan_cfg);
384 libertas_parse_ssid(buf, count, scan_cfg);
385 libertas_parse_keep(buf, count, scan_cfg);
386 libertas_parse_probes(buf, count, scan_cfg);
387 libertas_parse_type(buf, count, scan_cfg);
389 wlan_scan_networks(priv, scan_cfg);
390 wait_event_interruptible(priv->adapter->cmd_pending,
391 !priv->adapter->nr_cmd_pending);
393 memset(&wrqu, 0x00, sizeof(union iwreq_data));
394 wireless_send_event(priv->wlan_dev.netdev, SIOCGIWSCAN, &wrqu, NULL);
402 static int libertas_event_initcmd(wlan_private *priv, void **response_buf,
403 struct cmd_ctrl_node **cmdnode,
404 struct cmd_ds_command **cmd)
406 u16 wait_option = cmd_option_waitforrsp;
408 if (!(*cmdnode = libertas_get_free_cmd_ctrl_node(priv))) {
409 lbs_pr_debug(1, "failed libertas_get_free_cmd_ctrl_node\n");
412 if (!(*response_buf = kmalloc(3000, GFP_KERNEL))) {
413 lbs_pr_debug(1, "failed to allocate response buffer!\n");
416 libertas_set_cmd_ctrl_node(priv, *cmdnode, 0, wait_option, NULL);
417 init_waitqueue_head(&(*cmdnode)->cmdwait_q);
418 (*cmdnode)->pdata_buf = *response_buf;
419 (*cmdnode)->cmdflags |= CMD_F_HOSTCMD;
420 (*cmdnode)->cmdwaitqwoken = 0;
421 *cmd = (struct cmd_ds_command *)(*cmdnode)->bufvirtualaddr;
422 (*cmd)->command = cmd_802_11_subscribe_event;
423 (*cmd)->seqnum = ++priv->adapter->seqnum;
428 static ssize_t libertas_lowrssi_read(struct file *file, char __user *userbuf,
429 size_t count, loff_t *ppos)
431 wlan_private *priv = file->private_data;
432 wlan_adapter *adapter = priv->adapter;
433 struct cmd_ctrl_node *pcmdnode;
434 struct cmd_ds_command *pcmdptr;
435 struct cmd_ds_802_11_subscribe_event *event;
439 unsigned long addr = get_zeroed_page(GFP_KERNEL);
440 char *buf = (char *)addr;
442 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
448 event = &pcmdptr->params.subscribe_event;
449 event->action = cmd_act_get;
451 cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
452 libertas_queue_cmd(adapter, pcmdnode, 1);
453 wake_up_interruptible(&priv->mainthread.waitq);
455 /* Sleep until response is generated by FW */
456 wait_event_interruptible(pcmdnode->cmdwait_q,
457 pcmdnode->cmdwaitqwoken);
459 pcmdptr = response_buf;
460 if (pcmdptr->result) {
461 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
468 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
469 lbs_pr_err("command response incorrect!\n");
475 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
476 event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
477 while (cmd_len < pcmdptr->size) {
478 struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
479 switch(header->type) {
480 struct mrvlietypes_rssithreshold *Lowrssi;
481 case TLV_TYPE_RSSI_LOW:
482 Lowrssi = (struct mrvlietypes_rssithreshold *)(response_buf + cmd_len);
483 pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
486 (event->events & 0x0001)?1:0);
488 cmd_len += sizeof(struct mrvlietypes_snrthreshold);
494 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
499 static u16 libertas_get_events_bitmap(wlan_private *priv)
501 wlan_adapter *adapter = priv->adapter;
502 struct cmd_ctrl_node *pcmdnode;
503 struct cmd_ds_command *pcmdptr;
504 struct cmd_ds_802_11_subscribe_event *event;
509 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
513 event = &pcmdptr->params.subscribe_event;
514 event->action = cmd_act_get;
516 cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
517 libertas_queue_cmd(adapter, pcmdnode, 1);
518 wake_up_interruptible(&priv->mainthread.waitq);
520 /* Sleep until response is generated by FW */
521 wait_event_interruptible(pcmdnode->cmdwait_q,
522 pcmdnode->cmdwaitqwoken);
524 pcmdptr = response_buf;
526 if (pcmdptr->result) {
527 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
533 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
534 lbs_pr_err("command response incorrect!\n");
539 event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
540 event_bitmap = event->events;
545 static ssize_t libertas_lowrssi_write(struct file *file,
546 const char __user *userbuf,
547 size_t count, loff_t *ppos)
549 wlan_private *priv = file->private_data;
550 wlan_adapter *adapter = priv->adapter;
551 ssize_t res, buf_size;
552 int value, freq, subscribed, cmd_len;
553 struct cmd_ctrl_node *pcmdnode;
554 struct cmd_ds_command *pcmdptr;
555 struct cmd_ds_802_11_subscribe_event *event;
556 struct mrvlietypes_rssithreshold *rssi_threshold;
560 unsigned long addr = get_zeroed_page(GFP_KERNEL);
561 char *buf = (char *)addr;
563 buf_size = min(count, len - 1);
564 if (copy_from_user(buf, userbuf, buf_size)) {
568 res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
574 event_bitmap = libertas_get_events_bitmap(priv);
576 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
580 event = &pcmdptr->params.subscribe_event;
581 event->action = cmd_act_set;
582 pcmdptr->size = cpu_to_le16(S_DS_GEN +
583 sizeof(struct cmd_ds_802_11_subscribe_event) +
584 sizeof(struct mrvlietypes_rssithreshold));
586 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
587 ptr = (u8*) pcmdptr+cmd_len;
588 rssi_threshold = (struct mrvlietypes_rssithreshold *)(ptr);
589 rssi_threshold->header.type = cpu_to_le16(0x0104);
590 rssi_threshold->header.len = 2;
591 rssi_threshold->rssivalue = cpu_to_le16(value);
592 rssi_threshold->rssifreq = cpu_to_le16(freq);
593 event_bitmap |= subscribed ? 0x0001 : 0x0;
594 event->events = event_bitmap;
596 libertas_queue_cmd(adapter, pcmdnode, 1);
597 wake_up_interruptible(&priv->mainthread.waitq);
599 /* Sleep until response is generated by FW */
600 wait_event_interruptible(pcmdnode->cmdwait_q,
601 pcmdnode->cmdwaitqwoken);
603 pcmdptr = response_buf;
605 if (pcmdptr->result) {
606 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
613 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
614 lbs_pr_err("command response incorrect!\n");
626 static ssize_t libertas_lowsnr_read(struct file *file, char __user *userbuf,
627 size_t count, loff_t *ppos)
629 wlan_private *priv = file->private_data;
630 wlan_adapter *adapter = priv->adapter;
631 struct cmd_ctrl_node *pcmdnode;
632 struct cmd_ds_command *pcmdptr;
633 struct cmd_ds_802_11_subscribe_event *event;
637 unsigned long addr = get_zeroed_page(GFP_KERNEL);
638 char *buf = (char *)addr;
640 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
646 event = &pcmdptr->params.subscribe_event;
647 event->action = cmd_act_get;
649 cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
650 libertas_queue_cmd(adapter, pcmdnode, 1);
651 wake_up_interruptible(&priv->mainthread.waitq);
653 /* Sleep until response is generated by FW */
654 wait_event_interruptible(pcmdnode->cmdwait_q,
655 pcmdnode->cmdwaitqwoken);
657 pcmdptr = response_buf;
659 if (pcmdptr->result) {
660 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
667 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
668 lbs_pr_err("command response incorrect!\n");
674 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
675 event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
676 while (cmd_len < pcmdptr->size) {
677 struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
678 switch(header->type) {
679 struct mrvlietypes_snrthreshold *LowSnr;
680 case TLV_TYPE_SNR_LOW:
681 LowSnr = (struct mrvlietypes_snrthreshold *)(response_buf + cmd_len);
682 pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
685 (event->events & 0x0002)?1:0);
687 cmd_len += sizeof(struct mrvlietypes_snrthreshold);
694 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
699 static ssize_t libertas_lowsnr_write(struct file *file,
700 const char __user *userbuf,
701 size_t count, loff_t *ppos)
703 wlan_private *priv = file->private_data;
704 wlan_adapter *adapter = priv->adapter;
705 ssize_t res, buf_size;
706 int value, freq, subscribed, cmd_len;
707 struct cmd_ctrl_node *pcmdnode;
708 struct cmd_ds_command *pcmdptr;
709 struct cmd_ds_802_11_subscribe_event *event;
710 struct mrvlietypes_snrthreshold *snr_threshold;
714 unsigned long addr = get_zeroed_page(GFP_KERNEL);
715 char *buf = (char *)addr;
717 buf_size = min(count, len - 1);
718 if (copy_from_user(buf, userbuf, buf_size)) {
722 res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
728 event_bitmap = libertas_get_events_bitmap(priv);
730 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
734 event = &pcmdptr->params.subscribe_event;
735 event->action = cmd_act_set;
736 pcmdptr->size = cpu_to_le16(S_DS_GEN +
737 sizeof(struct cmd_ds_802_11_subscribe_event) +
738 sizeof(struct mrvlietypes_snrthreshold));
739 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
740 ptr = (u8*) pcmdptr+cmd_len;
741 snr_threshold = (struct mrvlietypes_snrthreshold *)(ptr);
742 snr_threshold->header.type = cpu_to_le16(TLV_TYPE_SNR_LOW);
743 snr_threshold->header.len = 2;
744 snr_threshold->snrvalue = cpu_to_le16(value);
745 snr_threshold->snrfreq = cpu_to_le16(freq);
746 event_bitmap |= subscribed ? 0x0002 : 0x0;
747 event->events = event_bitmap;
749 libertas_queue_cmd(adapter, pcmdnode, 1);
750 wake_up_interruptible(&priv->mainthread.waitq);
752 /* Sleep until response is generated by FW */
753 wait_event_interruptible(pcmdnode->cmdwait_q,
754 pcmdnode->cmdwaitqwoken);
756 pcmdptr = response_buf;
758 if (pcmdptr->result) {
759 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
766 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
767 lbs_pr_err("command response incorrect!\n");
780 static ssize_t libertas_failcount_read(struct file *file, char __user *userbuf,
781 size_t count, loff_t *ppos)
783 wlan_private *priv = file->private_data;
784 wlan_adapter *adapter = priv->adapter;
785 struct cmd_ctrl_node *pcmdnode;
786 struct cmd_ds_command *pcmdptr;
787 struct cmd_ds_802_11_subscribe_event *event;
791 unsigned long addr = get_zeroed_page(GFP_KERNEL);
792 char *buf = (char *)addr;
794 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
800 event = &pcmdptr->params.subscribe_event;
801 event->action = cmd_act_get;
803 cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
804 libertas_queue_cmd(adapter, pcmdnode, 1);
805 wake_up_interruptible(&priv->mainthread.waitq);
807 /* Sleep until response is generated by FW */
808 wait_event_interruptible(pcmdnode->cmdwait_q,
809 pcmdnode->cmdwaitqwoken);
811 pcmdptr = response_buf;
813 if (pcmdptr->result) {
814 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
821 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
822 lbs_pr_err("command response incorrect!\n");
828 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
829 event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
830 while (cmd_len < pcmdptr->size) {
831 struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
832 switch(header->type) {
833 struct mrvlietypes_failurecount *failcount;
834 case TLV_TYPE_FAILCOUNT:
835 failcount = (struct mrvlietypes_failurecount *)(response_buf + cmd_len);
836 pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
837 failcount->failvalue,
839 (event->events & 0x0004)?1:0);
841 cmd_len += sizeof(struct mrvlietypes_failurecount);
847 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
852 static ssize_t libertas_failcount_write(struct file *file,
853 const char __user *userbuf,
854 size_t count, loff_t *ppos)
856 wlan_private *priv = file->private_data;
857 wlan_adapter *adapter = priv->adapter;
858 ssize_t res, buf_size;
859 int value, freq, subscribed, cmd_len;
860 struct cmd_ctrl_node *pcmdnode;
861 struct cmd_ds_command *pcmdptr;
862 struct cmd_ds_802_11_subscribe_event *event;
863 struct mrvlietypes_failurecount *failcount;
867 unsigned long addr = get_zeroed_page(GFP_KERNEL);
868 char *buf = (char *)addr;
870 buf_size = min(count, len - 1);
871 if (copy_from_user(buf, userbuf, buf_size)) {
875 res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
881 event_bitmap = libertas_get_events_bitmap(priv);
883 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
887 event = &pcmdptr->params.subscribe_event;
888 event->action = cmd_act_set;
889 pcmdptr->size = cpu_to_le16(S_DS_GEN +
890 sizeof(struct cmd_ds_802_11_subscribe_event) +
891 sizeof(struct mrvlietypes_failurecount));
892 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
893 ptr = (u8*) pcmdptr+cmd_len;
894 failcount = (struct mrvlietypes_failurecount *)(ptr);
895 failcount->header.type = cpu_to_le16(TLV_TYPE_FAILCOUNT);
896 failcount->header.len = 2;
897 failcount->failvalue = cpu_to_le16(value);
898 failcount->Failfreq = cpu_to_le16(freq);
899 event_bitmap |= subscribed ? 0x0004 : 0x0;
900 event->events = event_bitmap;
902 libertas_queue_cmd(adapter, pcmdnode, 1);
903 wake_up_interruptible(&priv->mainthread.waitq);
905 /* Sleep until response is generated by FW */
906 wait_event_interruptible(pcmdnode->cmdwait_q,
907 pcmdnode->cmdwaitqwoken);
909 pcmdptr = (struct cmd_ds_command *)response_buf;
911 if (pcmdptr->result) {
912 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
919 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
920 lbs_pr_err("command response incorrect!\n");
932 static ssize_t libertas_bcnmiss_read(struct file *file, char __user *userbuf,
933 size_t count, loff_t *ppos)
935 wlan_private *priv = file->private_data;
936 wlan_adapter *adapter = priv->adapter;
937 struct cmd_ctrl_node *pcmdnode;
938 struct cmd_ds_command *pcmdptr;
939 struct cmd_ds_802_11_subscribe_event *event;
943 unsigned long addr = get_zeroed_page(GFP_KERNEL);
944 char *buf = (char *)addr;
946 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
952 event = &pcmdptr->params.subscribe_event;
953 event->action = cmd_act_get;
955 cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
956 libertas_queue_cmd(adapter, pcmdnode, 1);
957 wake_up_interruptible(&priv->mainthread.waitq);
959 /* Sleep until response is generated by FW */
960 wait_event_interruptible(pcmdnode->cmdwait_q,
961 pcmdnode->cmdwaitqwoken);
963 pcmdptr = response_buf;
965 if (pcmdptr->result) {
966 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
973 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
974 lbs_pr_err("command response incorrect!\n");
980 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
981 event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
982 while (cmd_len < pcmdptr->size) {
983 struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
984 switch(header->type) {
985 struct mrvlietypes_beaconsmissed *bcnmiss;
986 case TLV_TYPE_BCNMISS:
987 bcnmiss = (struct mrvlietypes_beaconsmissed *)(response_buf + cmd_len);
988 pos += snprintf(buf+pos, len-pos, "%d N/A %d\n",
989 bcnmiss->beaconmissed,
990 (event->events & 0x0008)?1:0);
992 cmd_len += sizeof(struct mrvlietypes_beaconsmissed);
999 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
1004 static ssize_t libertas_bcnmiss_write(struct file *file,
1005 const char __user *userbuf,
1006 size_t count, loff_t *ppos)
1008 wlan_private *priv = file->private_data;
1009 wlan_adapter *adapter = priv->adapter;
1010 ssize_t res, buf_size;
1011 int value, freq, subscribed, cmd_len;
1012 struct cmd_ctrl_node *pcmdnode;
1013 struct cmd_ds_command *pcmdptr;
1014 struct cmd_ds_802_11_subscribe_event *event;
1015 struct mrvlietypes_beaconsmissed *bcnmiss;
1019 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1020 char *buf = (char *)addr;
1022 buf_size = min(count, len - 1);
1023 if (copy_from_user(buf, userbuf, buf_size)) {
1027 res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
1033 event_bitmap = libertas_get_events_bitmap(priv);
1035 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
1039 event = &pcmdptr->params.subscribe_event;
1040 event->action = cmd_act_set;
1041 pcmdptr->size = cpu_to_le16(S_DS_GEN +
1042 sizeof(struct cmd_ds_802_11_subscribe_event) +
1043 sizeof(struct mrvlietypes_beaconsmissed));
1044 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
1045 ptr = (u8*) pcmdptr+cmd_len;
1046 bcnmiss = (struct mrvlietypes_beaconsmissed *)(ptr);
1047 bcnmiss->header.type = cpu_to_le16(TLV_TYPE_BCNMISS);
1048 bcnmiss->header.len = 2;
1049 bcnmiss->beaconmissed = cpu_to_le16(value);
1050 event_bitmap |= subscribed ? 0x0008 : 0x0;
1051 event->events = event_bitmap;
1053 libertas_queue_cmd(adapter, pcmdnode, 1);
1054 wake_up_interruptible(&priv->mainthread.waitq);
1056 /* Sleep until response is generated by FW */
1057 wait_event_interruptible(pcmdnode->cmdwait_q,
1058 pcmdnode->cmdwaitqwoken);
1060 pcmdptr = response_buf;
1062 if (pcmdptr->result) {
1063 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
1065 kfree(response_buf);
1070 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
1071 lbs_pr_err("command response incorrect!\n");
1073 kfree(response_buf);
1083 static ssize_t libertas_highrssi_read(struct file *file, char __user *userbuf,
1084 size_t count, loff_t *ppos)
1086 wlan_private *priv = file->private_data;
1087 wlan_adapter *adapter = priv->adapter;
1088 struct cmd_ctrl_node *pcmdnode;
1089 struct cmd_ds_command *pcmdptr;
1090 struct cmd_ds_802_11_subscribe_event *event;
1094 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1095 char *buf = (char *)addr;
1097 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
1103 event = &pcmdptr->params.subscribe_event;
1104 event->action = cmd_act_get;
1106 cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
1107 libertas_queue_cmd(adapter, pcmdnode, 1);
1108 wake_up_interruptible(&priv->mainthread.waitq);
1110 /* Sleep until response is generated by FW */
1111 wait_event_interruptible(pcmdnode->cmdwait_q,
1112 pcmdnode->cmdwaitqwoken);
1114 pcmdptr = response_buf;
1116 if (pcmdptr->result) {
1117 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
1119 kfree(response_buf);
1124 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
1125 lbs_pr_err("command response incorrect!\n");
1126 kfree(response_buf);
1131 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
1132 event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
1133 while (cmd_len < pcmdptr->size) {
1134 struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
1135 switch(header->type) {
1136 struct mrvlietypes_rssithreshold *Highrssi;
1137 case TLV_TYPE_RSSI_HIGH:
1138 Highrssi = (struct mrvlietypes_rssithreshold *)(response_buf + cmd_len);
1139 pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
1140 Highrssi->rssivalue,
1142 (event->events & 0x0010)?1:0);
1144 cmd_len += sizeof(struct mrvlietypes_snrthreshold);
1149 kfree(response_buf);
1151 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
1156 static ssize_t libertas_highrssi_write(struct file *file,
1157 const char __user *userbuf,
1158 size_t count, loff_t *ppos)
1160 wlan_private *priv = file->private_data;
1161 wlan_adapter *adapter = priv->adapter;
1162 ssize_t res, buf_size;
1163 int value, freq, subscribed, cmd_len;
1164 struct cmd_ctrl_node *pcmdnode;
1165 struct cmd_ds_command *pcmdptr;
1166 struct cmd_ds_802_11_subscribe_event *event;
1167 struct mrvlietypes_rssithreshold *rssi_threshold;
1171 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1172 char *buf = (char *)addr;
1174 buf_size = min(count, len - 1);
1175 if (copy_from_user(buf, userbuf, buf_size)) {
1179 res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
1185 event_bitmap = libertas_get_events_bitmap(priv);
1187 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
1191 event = &pcmdptr->params.subscribe_event;
1192 event->action = cmd_act_set;
1193 pcmdptr->size = cpu_to_le16(S_DS_GEN +
1194 sizeof(struct cmd_ds_802_11_subscribe_event) +
1195 sizeof(struct mrvlietypes_rssithreshold));
1196 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
1197 ptr = (u8*) pcmdptr+cmd_len;
1198 rssi_threshold = (struct mrvlietypes_rssithreshold *)(ptr);
1199 rssi_threshold->header.type = cpu_to_le16(TLV_TYPE_RSSI_HIGH);
1200 rssi_threshold->header.len = 2;
1201 rssi_threshold->rssivalue = cpu_to_le16(value);
1202 rssi_threshold->rssifreq = cpu_to_le16(freq);
1203 event_bitmap |= subscribed ? 0x0010 : 0x0;
1204 event->events = event_bitmap;
1206 libertas_queue_cmd(adapter, pcmdnode, 1);
1207 wake_up_interruptible(&priv->mainthread.waitq);
1209 /* Sleep until response is generated by FW */
1210 wait_event_interruptible(pcmdnode->cmdwait_q,
1211 pcmdnode->cmdwaitqwoken);
1213 pcmdptr = response_buf;
1215 if (pcmdptr->result) {
1216 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
1218 kfree(response_buf);
1222 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
1223 lbs_pr_err("command response incorrect!\n");
1224 kfree(response_buf);
1234 static ssize_t libertas_highsnr_read(struct file *file, char __user *userbuf,
1235 size_t count, loff_t *ppos)
1237 wlan_private *priv = file->private_data;
1238 wlan_adapter *adapter = priv->adapter;
1239 struct cmd_ctrl_node *pcmdnode;
1240 struct cmd_ds_command *pcmdptr;
1241 struct cmd_ds_802_11_subscribe_event *event;
1245 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1246 char *buf = (char *)addr;
1248 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
1254 event = &pcmdptr->params.subscribe_event;
1255 event->action = cmd_act_get;
1257 cpu_to_le16(sizeof(struct cmd_ds_802_11_subscribe_event) + S_DS_GEN);
1258 libertas_queue_cmd(adapter, pcmdnode, 1);
1259 wake_up_interruptible(&priv->mainthread.waitq);
1261 /* Sleep until response is generated by FW */
1262 wait_event_interruptible(pcmdnode->cmdwait_q,
1263 pcmdnode->cmdwaitqwoken);
1265 pcmdptr = response_buf;
1267 if (pcmdptr->result) {
1268 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
1270 kfree(response_buf);
1275 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
1276 lbs_pr_err("command response incorrect!\n");
1277 kfree(response_buf);
1282 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
1283 event = (struct cmd_ds_802_11_subscribe_event *)(response_buf + S_DS_GEN);
1284 while (cmd_len < pcmdptr->size) {
1285 struct mrvlietypesheader *header = (struct mrvlietypesheader *)(response_buf + cmd_len);
1286 switch(header->type) {
1287 struct mrvlietypes_snrthreshold *HighSnr;
1288 case TLV_TYPE_SNR_HIGH:
1289 HighSnr = (struct mrvlietypes_snrthreshold *)(response_buf + cmd_len);
1290 pos += snprintf(buf+pos, len-pos, "%d %d %d\n",
1293 (event->events & 0x0020)?1:0);
1295 cmd_len += sizeof(struct mrvlietypes_snrthreshold);
1300 kfree(response_buf);
1302 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
1307 static ssize_t libertas_highsnr_write(struct file *file,
1308 const char __user *userbuf,
1309 size_t count, loff_t *ppos)
1311 wlan_private *priv = file->private_data;
1312 wlan_adapter *adapter = priv->adapter;
1313 ssize_t res, buf_size;
1314 int value, freq, subscribed, cmd_len;
1315 struct cmd_ctrl_node *pcmdnode;
1316 struct cmd_ds_command *pcmdptr;
1317 struct cmd_ds_802_11_subscribe_event *event;
1318 struct mrvlietypes_snrthreshold *snr_threshold;
1322 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1323 char *buf = (char *)addr;
1325 buf_size = min(count, len - 1);
1326 if (copy_from_user(buf, userbuf, buf_size)) {
1330 res = sscanf(buf, "%d %d %d", &value, &freq, &subscribed);
1336 event_bitmap = libertas_get_events_bitmap(priv);
1338 res = libertas_event_initcmd(priv, &response_buf, &pcmdnode, &pcmdptr);
1342 event = &pcmdptr->params.subscribe_event;
1343 event->action = cmd_act_set;
1344 pcmdptr->size = cpu_to_le16(S_DS_GEN +
1345 sizeof(struct cmd_ds_802_11_subscribe_event) +
1346 sizeof(struct mrvlietypes_snrthreshold));
1347 cmd_len = S_DS_GEN + sizeof(struct cmd_ds_802_11_subscribe_event);
1348 ptr = (u8*) pcmdptr+cmd_len;
1349 snr_threshold = (struct mrvlietypes_snrthreshold *)(ptr);
1350 snr_threshold->header.type = cpu_to_le16(TLV_TYPE_SNR_HIGH);
1351 snr_threshold->header.len = 2;
1352 snr_threshold->snrvalue = cpu_to_le16(value);
1353 snr_threshold->snrfreq = cpu_to_le16(freq);
1354 event_bitmap |= subscribed ? 0x0020 : 0x0;
1355 event->events = event_bitmap;
1357 libertas_queue_cmd(adapter, pcmdnode, 1);
1358 wake_up_interruptible(&priv->mainthread.waitq);
1360 /* Sleep until response is generated by FW */
1361 wait_event_interruptible(pcmdnode->cmdwait_q,
1362 pcmdnode->cmdwaitqwoken);
1364 pcmdptr = response_buf;
1366 if (pcmdptr->result) {
1367 lbs_pr_err("%s: fail, result=%d\n", __FUNCTION__,
1369 kfree(response_buf);
1374 if (pcmdptr->command != cmd_ret_802_11_subscribe_event) {
1375 lbs_pr_err("command response incorrect!\n");
1376 kfree(response_buf);
1387 static ssize_t libertas_rdmac_read(struct file *file, char __user *userbuf,
1388 size_t count, loff_t *ppos)
1390 wlan_private *priv = file->private_data;
1391 wlan_adapter *adapter = priv->adapter;
1392 struct wlan_offset_value offval;
1395 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1396 char *buf = (char *)addr;
1398 offval.offset = priv->mac_offset;
1401 ret = libertas_prepare_and_send_command(priv,
1402 cmd_mac_reg_access, 0,
1403 cmd_option_waitforrsp, 0, &offval);
1405 pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
1406 priv->mac_offset, adapter->offsetvalue.value);
1408 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
1413 static ssize_t libertas_rdmac_write(struct file *file,
1414 const char __user *userbuf,
1415 size_t count, loff_t *ppos)
1417 wlan_private *priv = file->private_data;
1418 ssize_t res, buf_size;
1419 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1420 char *buf = (char *)addr;
1422 buf_size = min(count, len - 1);
1423 if (copy_from_user(buf, userbuf, buf_size)) {
1427 priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
1434 static ssize_t libertas_wrmac_write(struct file *file,
1435 const char __user *userbuf,
1436 size_t count, loff_t *ppos)
1439 wlan_private *priv = file->private_data;
1440 ssize_t res, buf_size;
1442 struct wlan_offset_value offval;
1443 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1444 char *buf = (char *)addr;
1446 buf_size = min(count, len - 1);
1447 if (copy_from_user(buf, userbuf, buf_size)) {
1451 res = sscanf(buf, "%x %x", &offset, &value);
1457 offval.offset = offset;
1458 offval.value = value;
1459 res = libertas_prepare_and_send_command(priv,
1460 cmd_mac_reg_access, 1,
1461 cmd_option_waitforrsp, 0, &offval);
1470 static ssize_t libertas_rdbbp_read(struct file *file, char __user *userbuf,
1471 size_t count, loff_t *ppos)
1473 wlan_private *priv = file->private_data;
1474 wlan_adapter *adapter = priv->adapter;
1475 struct wlan_offset_value offval;
1478 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1479 char *buf = (char *)addr;
1481 offval.offset = priv->bbp_offset;
1484 ret = libertas_prepare_and_send_command(priv,
1485 cmd_bbp_reg_access, 0,
1486 cmd_option_waitforrsp, 0, &offval);
1488 pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
1489 priv->bbp_offset, adapter->offsetvalue.value);
1491 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
1497 static ssize_t libertas_rdbbp_write(struct file *file,
1498 const char __user *userbuf,
1499 size_t count, loff_t *ppos)
1501 wlan_private *priv = file->private_data;
1502 ssize_t res, buf_size;
1503 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1504 char *buf = (char *)addr;
1506 buf_size = min(count, len - 1);
1507 if (copy_from_user(buf, userbuf, buf_size)) {
1511 priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
1518 static ssize_t libertas_wrbbp_write(struct file *file,
1519 const char __user *userbuf,
1520 size_t count, loff_t *ppos)
1523 wlan_private *priv = file->private_data;
1524 ssize_t res, buf_size;
1526 struct wlan_offset_value offval;
1527 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1528 char *buf = (char *)addr;
1530 buf_size = min(count, len - 1);
1531 if (copy_from_user(buf, userbuf, buf_size)) {
1535 res = sscanf(buf, "%x %x", &offset, &value);
1541 offval.offset = offset;
1542 offval.value = value;
1543 res = libertas_prepare_and_send_command(priv,
1544 cmd_bbp_reg_access, 1,
1545 cmd_option_waitforrsp, 0, &offval);
1554 static ssize_t libertas_rdrf_read(struct file *file, char __user *userbuf,
1555 size_t count, loff_t *ppos)
1557 wlan_private *priv = file->private_data;
1558 wlan_adapter *adapter = priv->adapter;
1559 struct wlan_offset_value offval;
1562 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1563 char *buf = (char *)addr;
1565 offval.offset = priv->rf_offset;
1568 ret = libertas_prepare_and_send_command(priv,
1569 cmd_rf_reg_access, 0,
1570 cmd_option_waitforrsp, 0, &offval);
1572 pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
1573 priv->rf_offset, adapter->offsetvalue.value);
1575 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
1581 static ssize_t libertas_rdrf_write(struct file *file,
1582 const char __user *userbuf,
1583 size_t count, loff_t *ppos)
1585 wlan_private *priv = file->private_data;
1586 ssize_t res, buf_size;
1587 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1588 char *buf = (char *)addr;
1590 buf_size = min(count, len - 1);
1591 if (copy_from_user(buf, userbuf, buf_size)) {
1595 priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
1602 static ssize_t libertas_wrrf_write(struct file *file,
1603 const char __user *userbuf,
1604 size_t count, loff_t *ppos)
1607 wlan_private *priv = file->private_data;
1608 ssize_t res, buf_size;
1610 struct wlan_offset_value offval;
1611 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1612 char *buf = (char *)addr;
1614 buf_size = min(count, len - 1);
1615 if (copy_from_user(buf, userbuf, buf_size)) {
1619 res = sscanf(buf, "%x %x", &offset, &value);
1625 offval.offset = offset;
1626 offval.value = value;
1627 res = libertas_prepare_and_send_command(priv,
1628 cmd_rf_reg_access, 1,
1629 cmd_option_waitforrsp, 0, &offval);
1638 #define FOPS(fread, fwrite) { \
1639 .owner = THIS_MODULE, \
1640 .open = open_file_generic, \
1642 .write = (fwrite), \
1645 struct libertas_debugfs_files {
1648 struct file_operations fops;
1651 struct libertas_debugfs_files debugfs_files[] = {
1652 { "info", 0444, FOPS(libertas_dev_info, write_file_dummy), },
1653 { "getscantable", 0444, FOPS(libertas_getscantable,
1654 write_file_dummy), },
1655 { "sleepparams", 0644, FOPS(libertas_sleepparams_read,
1656 libertas_sleepparams_write), },
1657 { "extscan", 0600, FOPS(NULL, libertas_extscan), },
1658 { "setuserscan", 0600, FOPS(NULL, libertas_setuserscan), },
1661 struct libertas_debugfs_files debugfs_events_files[] = {
1662 {"low_rssi", 0644, FOPS(libertas_lowrssi_read,
1663 libertas_lowrssi_write), },
1664 {"low_snr", 0644, FOPS(libertas_lowsnr_read,
1665 libertas_lowsnr_write), },
1666 {"failure_count", 0644, FOPS(libertas_failcount_read,
1667 libertas_failcount_write), },
1668 {"beacon_missed", 0644, FOPS(libertas_bcnmiss_read,
1669 libertas_bcnmiss_write), },
1670 {"high_rssi", 0644, FOPS(libertas_highrssi_read,
1671 libertas_highrssi_write), },
1672 {"high_snr", 0644, FOPS(libertas_highsnr_read,
1673 libertas_highsnr_write), },
1676 struct libertas_debugfs_files debugfs_regs_files[] = {
1677 {"rdmac", 0644, FOPS(libertas_rdmac_read, libertas_rdmac_write), },
1678 {"wrmac", 0600, FOPS(NULL, libertas_wrmac_write), },
1679 {"rdbbp", 0644, FOPS(libertas_rdbbp_read, libertas_rdbbp_write), },
1680 {"wrbbp", 0600, FOPS(NULL, libertas_wrbbp_write), },
1681 {"rdrf", 0644, FOPS(libertas_rdrf_read, libertas_rdrf_write), },
1682 {"wrrf", 0600, FOPS(NULL, libertas_wrrf_write), },
1685 void libertas_debugfs_init(void)
1688 libertas_dir = debugfs_create_dir("libertas_wireless", NULL);
1693 void libertas_debugfs_remove(void)
1696 debugfs_remove(libertas_dir);
1700 void libertas_debugfs_init_one(wlan_private *priv, struct net_device *dev)
1703 struct libertas_debugfs_files *files;
1707 priv->debugfs_dir = debugfs_create_dir(dev->name, libertas_dir);
1708 if (!priv->debugfs_dir)
1711 for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
1712 files = &debugfs_files[i];
1713 priv->debugfs_files[i] = debugfs_create_file(files->name,
1720 priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
1721 if (!priv->events_dir)
1724 for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
1725 files = &debugfs_events_files[i];
1726 priv->debugfs_events_files[i] = debugfs_create_file(files->name,
1733 priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
1734 if (!priv->regs_dir)
1737 for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
1738 files = &debugfs_regs_files[i];
1739 priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
1747 libertas_debug_init(priv, dev);
1753 void libertas_debugfs_remove_one(wlan_private *priv)
1757 for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
1758 debugfs_remove(priv->debugfs_regs_files[i]);
1760 debugfs_remove(priv->regs_dir);
1762 for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
1763 debugfs_remove(priv->debugfs_events_files[i]);
1765 debugfs_remove(priv->events_dir);
1767 debugfs_remove(priv->debugfs_debug);
1769 for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
1770 debugfs_remove(priv->debugfs_files[i]);
1775 #define item_size(n) (FIELD_SIZEOF(wlan_adapter, n))
1776 #define item_addr(n) (offsetof(wlan_adapter, n))
1784 /* To debug any member of wlan_adapter, simply add one line here.
1786 static struct debug_data items[] = {
1787 {"intcounter", item_size(intcounter), item_addr(intcounter)},
1788 {"psmode", item_size(psmode), item_addr(psmode)},
1789 {"psstate", item_size(psstate), item_addr(psstate)},
1792 static int num_of_items = ARRAY_SIZE(items);
1795 * @brief proc read function
1797 * @param page pointer to buffer
1798 * @param s read data starting position
1800 * @param cnt counter
1801 * @param eof end of file flag
1802 * @param data data to output
1803 * @return number of output data
1805 static ssize_t wlan_debugfs_read(struct file *file, char __user *userbuf,
1806 size_t count, loff_t *ppos)
1813 struct debug_data *d;
1814 unsigned long addr = get_zeroed_page(GFP_KERNEL);
1815 char *buf = (char *)addr;
1819 d = (struct debug_data *)file->private_data;
1821 for (i = 0; i < num_of_items; i++) {
1823 val = *((u8 *) d[i].addr);
1824 else if (d[i].size == 2)
1825 val = *((u16 *) d[i].addr);
1826 else if (d[i].size == 4)
1827 val = *((u32 *) d[i].addr);
1829 pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
1832 res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
1839 * @brief proc write function
1841 * @param f file pointer
1842 * @param buf pointer to data buffer
1843 * @param cnt data number to write
1844 * @param data data to write
1845 * @return number of data
1847 static int wlan_debugfs_write(struct file *f, const char __user *buf,
1848 size_t cnt, loff_t *ppos)
1856 struct debug_data *d = (struct debug_data *)f->private_data;
1858 pdata = (char *)kmalloc(cnt, GFP_KERNEL);
1862 if (copy_from_user(pdata, buf, cnt)) {
1863 lbs_pr_debug(1, "Copy from user failed\n");
1869 for (i = 0; i < num_of_items; i++) {
1871 p = strstr(p0, d[i].name);
1874 p1 = strchr(p, '\n');
1878 p2 = strchr(p, '=');
1882 r = simple_strtoul(p2, NULL, 0);
1884 *((u8 *) d[i].addr) = (u8) r;
1885 else if (d[i].size == 2)
1886 *((u16 *) d[i].addr) = (u16) r;
1887 else if (d[i].size == 4)
1888 *((u32 *) d[i].addr) = (u32) r;
1897 static struct file_operations libertas_debug_fops = {
1898 .owner = THIS_MODULE,
1899 .open = open_file_generic,
1900 .write = wlan_debugfs_write,
1901 .read = wlan_debugfs_read,
1905 * @brief create debug proc file
1907 * @param priv pointer wlan_private
1908 * @param dev pointer net_device
1911 void libertas_debug_init(wlan_private * priv, struct net_device *dev)
1915 if (!priv->debugfs_dir)
1918 for (i = 0; i < num_of_items; i++)
1919 items[i].addr += (u32) priv->adapter;
1921 priv->debugfs_debug = debugfs_create_file("debug", 0644,
1922 priv->debugfs_dir, &items[0],
1923 &libertas_debug_fops);
1927 * @brief remove proc file
1929 * @param priv pointer wlan_private
1932 void libertas_debug_remove(wlan_private * priv)
1934 debugfs_remove(priv->debugfs_debug);