1 #include <linux/module.h>
2 #include <linux/dcache.h>
3 #include <linux/debugfs.h>
4 #include <linux/delay.h>
6 #include <linux/string.h>
7 #include <net/iw_handler.h>
14 static struct dentry
*libertas_dir
= NULL
;
15 static char *szStates
[] = {
21 static void libertas_debug_init(wlan_private
* priv
, struct net_device
*dev
);
24 static int open_file_generic(struct inode
*inode
, struct file
*file
)
26 file
->private_data
= inode
->i_private
;
30 static ssize_t
write_file_dummy(struct file
*file
, const char __user
*buf
,
31 size_t count
, loff_t
*ppos
)
36 static const size_t len
= PAGE_SIZE
;
38 static ssize_t
libertas_dev_info(struct file
*file
, char __user
*userbuf
,
39 size_t count
, loff_t
*ppos
)
41 wlan_private
*priv
= file
->private_data
;
43 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
44 char *buf
= (char *)addr
;
47 pos
+= snprintf(buf
+pos
, len
-pos
, "state = %s\n",
48 szStates
[priv
->adapter
->connect_status
]);
49 pos
+= snprintf(buf
+pos
, len
-pos
, "region_code = %02x\n",
50 (u32
) priv
->adapter
->regioncode
);
52 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
59 static ssize_t
libertas_getscantable(struct file
*file
, char __user
*userbuf
,
60 size_t count
, loff_t
*ppos
)
62 wlan_private
*priv
= file
->private_data
;
64 int numscansdone
= 0, res
;
65 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
66 char *buf
= (char *)addr
;
68 struct bss_descriptor
* iter_bss
;
70 pos
+= snprintf(buf
+pos
, len
-pos
,
71 "# | ch | rssi | bssid | cap | Qual | SSID \n");
73 mutex_lock(&priv
->adapter
->lock
);
74 list_for_each_entry (iter_bss
, &priv
->adapter
->network_list
, list
) {
75 u16 ibss
= (iter_bss
->capability
& WLAN_CAPABILITY_IBSS
);
76 u16 privacy
= (iter_bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
77 u16 spectrum_mgmt
= (iter_bss
->capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
);
79 pos
+= snprintf(buf
+pos
, len
-pos
,
80 "%02u| %03d | %04ld | %s |",
81 numscansdone
, iter_bss
->channel
, iter_bss
->rssi
,
82 print_mac(mac
, iter_bss
->bssid
));
83 pos
+= snprintf(buf
+pos
, len
-pos
, " %04x-", iter_bss
->capability
);
84 pos
+= snprintf(buf
+pos
, len
-pos
, "%c%c%c |",
85 ibss
? 'A' : 'I', privacy
? 'P' : ' ',
86 spectrum_mgmt
? 'S' : ' ');
87 pos
+= snprintf(buf
+pos
, len
-pos
, " %04d |", SCAN_RSSI(iter_bss
->rssi
));
88 pos
+= snprintf(buf
+pos
, len
-pos
, " %s\n",
89 escape_essid(iter_bss
->ssid
, iter_bss
->ssid_len
));
93 mutex_unlock(&priv
->adapter
->lock
);
95 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
101 static ssize_t
libertas_sleepparams_write(struct file
*file
,
102 const char __user
*user_buf
, size_t count
,
105 wlan_private
*priv
= file
->private_data
;
106 ssize_t buf_size
, res
;
107 int p1
, p2
, p3
, p4
, p5
, p6
;
108 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
109 char *buf
= (char *)addr
;
111 buf_size
= min(count
, len
- 1);
112 if (copy_from_user(buf
, user_buf
, buf_size
)) {
116 res
= sscanf(buf
, "%d %d %d %d %d %d", &p1
, &p2
, &p3
, &p4
, &p5
, &p6
);
121 priv
->adapter
->sp
.sp_error
= p1
;
122 priv
->adapter
->sp
.sp_offset
= p2
;
123 priv
->adapter
->sp
.sp_stabletime
= p3
;
124 priv
->adapter
->sp
.sp_calcontrol
= p4
;
125 priv
->adapter
->sp
.sp_extsleepclk
= p5
;
126 priv
->adapter
->sp
.sp_reserved
= p6
;
128 res
= libertas_prepare_and_send_command(priv
,
129 CMD_802_11_SLEEP_PARAMS
,
131 CMD_OPTION_WAITFORRSP
, 0, NULL
);
143 static ssize_t
libertas_sleepparams_read(struct file
*file
, char __user
*userbuf
,
144 size_t count
, loff_t
*ppos
)
146 wlan_private
*priv
= file
->private_data
;
147 wlan_adapter
*adapter
= priv
->adapter
;
150 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
151 char *buf
= (char *)addr
;
153 res
= libertas_prepare_and_send_command(priv
,
154 CMD_802_11_SLEEP_PARAMS
,
156 CMD_OPTION_WAITFORRSP
, 0, NULL
);
162 pos
+= snprintf(buf
, len
, "%d %d %d %d %d %d\n", adapter
->sp
.sp_error
,
163 adapter
->sp
.sp_offset
, adapter
->sp
.sp_stabletime
,
164 adapter
->sp
.sp_calcontrol
, adapter
->sp
.sp_extsleepclk
,
165 adapter
->sp
.sp_reserved
);
167 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
174 static ssize_t
libertas_extscan(struct file
*file
, const char __user
*userbuf
,
175 size_t count
, loff_t
*ppos
)
177 wlan_private
*priv
= file
->private_data
;
178 ssize_t res
, buf_size
;
179 union iwreq_data wrqu
;
180 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
181 char *buf
= (char *)addr
;
183 buf_size
= min(count
, len
- 1);
184 if (copy_from_user(buf
, userbuf
, buf_size
)) {
189 libertas_send_specific_ssid_scan(priv
, buf
, strlen(buf
)-1, 0);
191 memset(&wrqu
, 0, sizeof(union iwreq_data
));
192 wireless_send_event(priv
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
199 static int libertas_parse_chan(char *buf
, size_t count
,
200 struct wlan_ioctl_user_scan_cfg
*scan_cfg
, int dur
)
202 char *start
, *end
, *hold
, *str
;
205 start
= strstr(buf
, "chan=");
209 end
= strchr(start
, ' ');
212 hold
= kzalloc((end
- start
)+1, GFP_KERNEL
);
215 strncpy(hold
, start
, end
- start
);
216 hold
[(end
-start
)+1] = '\0';
217 while(hold
&& (str
= strsep(&hold
, ","))) {
219 char band
, passive
= 0;
220 sscanf(str
, "%d%c%c", &chan
, &band
, &passive
);
221 scan_cfg
->chanlist
[i
].channumber
= chan
;
222 scan_cfg
->chanlist
[i
].scantype
= passive
? 1 : 0;
223 if (band
== 'b' || band
== 'g')
224 scan_cfg
->chanlist
[i
].radiotype
= 0;
225 else if (band
== 'a')
226 scan_cfg
->chanlist
[i
].radiotype
= 1;
228 scan_cfg
->chanlist
[i
].scantime
= dur
;
236 static void libertas_parse_bssid(char *buf
, size_t count
,
237 struct wlan_ioctl_user_scan_cfg
*scan_cfg
)
240 unsigned int mac
[ETH_ALEN
];
242 hold
= strstr(buf
, "bssid=");
246 sscanf(hold
, MAC_FMT
, mac
, mac
+1, mac
+2, mac
+3, mac
+4, mac
+5);
247 memcpy(scan_cfg
->bssid
, mac
, ETH_ALEN
);
250 static void libertas_parse_ssid(char *buf
, size_t count
,
251 struct wlan_ioctl_user_scan_cfg
*scan_cfg
)
256 hold
= strstr(buf
, "ssid=");
260 end
= strchr(hold
, ' ');
262 end
= buf
+ count
- 1;
264 size
= min((size_t)IW_ESSID_MAX_SIZE
, (size_t) (end
- hold
));
265 strncpy(scan_cfg
->ssid
, hold
, size
);
270 static int libertas_parse_clear(char *buf
, size_t count
, const char *tag
)
275 hold
= strstr(buf
, tag
);
279 sscanf(hold
, "%d", &val
);
287 static int libertas_parse_dur(char *buf
, size_t count
,
288 struct wlan_ioctl_user_scan_cfg
*scan_cfg
)
293 hold
= strstr(buf
, "dur=");
297 sscanf(hold
, "%d", &val
);
302 static void libertas_parse_probes(char *buf
, size_t count
,
303 struct wlan_ioctl_user_scan_cfg
*scan_cfg
)
308 hold
= strstr(buf
, "probes=");
312 sscanf(hold
, "%d", &val
);
314 scan_cfg
->numprobes
= val
;
319 static void libertas_parse_type(char *buf
, size_t count
,
320 struct wlan_ioctl_user_scan_cfg
*scan_cfg
)
325 hold
= strstr(buf
, "type=");
329 sscanf(hold
, "%d", &val
);
332 if (val
< 1 || val
> 3)
335 scan_cfg
->bsstype
= val
;
340 static ssize_t
libertas_setuserscan(struct file
*file
,
341 const char __user
*userbuf
,
342 size_t count
, loff_t
*ppos
)
344 wlan_private
*priv
= file
->private_data
;
345 ssize_t res
, buf_size
;
346 struct wlan_ioctl_user_scan_cfg
*scan_cfg
;
347 union iwreq_data wrqu
;
349 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
350 char *buf
= (char *)addr
;
352 scan_cfg
= kzalloc(sizeof(struct wlan_ioctl_user_scan_cfg
), GFP_KERNEL
);
356 buf_size
= min(count
, len
- 1);
357 if (copy_from_user(buf
, userbuf
, buf_size
)) {
362 scan_cfg
->bsstype
= WLAN_SCAN_BSS_TYPE_ANY
;
364 dur
= libertas_parse_dur(buf
, count
, scan_cfg
);
365 libertas_parse_chan(buf
, count
, scan_cfg
, dur
);
366 libertas_parse_bssid(buf
, count
, scan_cfg
);
367 scan_cfg
->clear_bssid
= libertas_parse_clear(buf
, count
, "clear_bssid=");
368 libertas_parse_ssid(buf
, count
, scan_cfg
);
369 scan_cfg
->clear_ssid
= libertas_parse_clear(buf
, count
, "clear_ssid=");
370 libertas_parse_probes(buf
, count
, scan_cfg
);
371 libertas_parse_type(buf
, count
, scan_cfg
);
373 wlan_scan_networks(priv
, scan_cfg
, 1);
374 wait_event_interruptible(priv
->adapter
->cmd_pending
,
375 !priv
->adapter
->nr_cmd_pending
);
377 memset(&wrqu
, 0x00, sizeof(union iwreq_data
));
378 wireless_send_event(priv
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
386 static int libertas_event_initcmd(wlan_private
*priv
, void **response_buf
,
387 struct cmd_ctrl_node
**cmdnode
,
388 struct cmd_ds_command
**cmd
)
390 u16 wait_option
= CMD_OPTION_WAITFORRSP
;
392 if (!(*cmdnode
= libertas_get_free_cmd_ctrl_node(priv
))) {
393 lbs_deb_debugfs("failed libertas_get_free_cmd_ctrl_node\n");
396 if (!(*response_buf
= kmalloc(3000, GFP_KERNEL
))) {
397 lbs_deb_debugfs("failed to allocate response buffer!\n");
400 libertas_set_cmd_ctrl_node(priv
, *cmdnode
, 0, wait_option
, NULL
);
401 init_waitqueue_head(&(*cmdnode
)->cmdwait_q
);
402 (*cmdnode
)->pdata_buf
= *response_buf
;
403 (*cmdnode
)->cmdflags
|= CMD_F_HOSTCMD
;
404 (*cmdnode
)->cmdwaitqwoken
= 0;
405 *cmd
= (struct cmd_ds_command
*)(*cmdnode
)->bufvirtualaddr
;
406 (*cmd
)->command
= cpu_to_le16(CMD_802_11_SUBSCRIBE_EVENT
);
407 (*cmd
)->seqnum
= cpu_to_le16(++priv
->adapter
->seqnum
);
412 static ssize_t
libertas_lowrssi_read(struct file
*file
, char __user
*userbuf
,
413 size_t count
, loff_t
*ppos
)
415 wlan_private
*priv
= file
->private_data
;
416 wlan_adapter
*adapter
= priv
->adapter
;
417 struct cmd_ctrl_node
*pcmdnode
;
418 struct cmd_ds_command
*pcmdptr
;
419 struct cmd_ds_802_11_subscribe_event
*event
;
423 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
424 char *buf
= (char *)addr
;
426 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
432 event
= &pcmdptr
->params
.subscribe_event
;
433 event
->action
= cpu_to_le16(CMD_ACT_GET
);
434 pcmdptr
->size
= cpu_to_le16(sizeof(*event
) + S_DS_GEN
);
435 libertas_queue_cmd(adapter
, pcmdnode
, 1);
436 wake_up_interruptible(&priv
->waitq
);
438 /* Sleep until response is generated by FW */
439 wait_event_interruptible(pcmdnode
->cmdwait_q
,
440 pcmdnode
->cmdwaitqwoken
);
442 pcmdptr
= response_buf
;
443 if (pcmdptr
->result
) {
444 lbs_pr_err("%s: fail, result=%d\n", __func__
,
445 le16_to_cpu(pcmdptr
->result
));
451 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
452 lbs_pr_err("command response incorrect!\n");
458 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
459 event
= (void *)(response_buf
+ S_DS_GEN
);
460 while (cmd_len
< le16_to_cpu(pcmdptr
->size
)) {
461 struct mrvlietypesheader
*header
= (void *)(response_buf
+ cmd_len
);
462 switch (header
->type
) {
463 struct mrvlietypes_rssithreshold
*Lowrssi
;
464 case __constant_cpu_to_le16(TLV_TYPE_RSSI_LOW
):
465 Lowrssi
= (void *)(response_buf
+ cmd_len
);
466 pos
+= snprintf(buf
+pos
, len
-pos
, "%d %d %d\n",
469 (event
->events
& cpu_to_le16(0x0001))?1:0);
471 cmd_len
+= sizeof(struct mrvlietypes_snrthreshold
);
477 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
482 static u16
libertas_get_events_bitmap(wlan_private
*priv
)
484 wlan_adapter
*adapter
= priv
->adapter
;
485 struct cmd_ctrl_node
*pcmdnode
;
486 struct cmd_ds_command
*pcmdptr
;
487 struct cmd_ds_802_11_subscribe_event
*event
;
492 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
496 event
= &pcmdptr
->params
.subscribe_event
;
497 event
->action
= cpu_to_le16(CMD_ACT_GET
);
498 pcmdptr
->size
= cpu_to_le16(sizeof(*event
) + S_DS_GEN
);
499 libertas_queue_cmd(adapter
, pcmdnode
, 1);
500 wake_up_interruptible(&priv
->waitq
);
502 /* Sleep until response is generated by FW */
503 wait_event_interruptible(pcmdnode
->cmdwait_q
,
504 pcmdnode
->cmdwaitqwoken
);
506 pcmdptr
= response_buf
;
508 if (pcmdptr
->result
) {
509 lbs_pr_err("%s: fail, result=%d\n", __func__
,
510 le16_to_cpu(pcmdptr
->result
));
515 if (le16_to_cpu(pcmdptr
->command
) != CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
)) {
516 lbs_pr_err("command response incorrect!\n");
521 event
= (struct cmd_ds_802_11_subscribe_event
*)(response_buf
+ S_DS_GEN
);
522 event_bitmap
= le16_to_cpu(event
->events
);
527 static ssize_t
libertas_lowrssi_write(struct file
*file
,
528 const char __user
*userbuf
,
529 size_t count
, loff_t
*ppos
)
531 wlan_private
*priv
= file
->private_data
;
532 wlan_adapter
*adapter
= priv
->adapter
;
533 ssize_t res
, buf_size
;
534 int value
, freq
, subscribed
, cmd_len
;
535 struct cmd_ctrl_node
*pcmdnode
;
536 struct cmd_ds_command
*pcmdptr
;
537 struct cmd_ds_802_11_subscribe_event
*event
;
538 struct mrvlietypes_rssithreshold
*rssi_threshold
;
542 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
543 char *buf
= (char *)addr
;
545 buf_size
= min(count
, len
- 1);
546 if (copy_from_user(buf
, userbuf
, buf_size
)) {
550 res
= sscanf(buf
, "%d %d %d", &value
, &freq
, &subscribed
);
556 event_bitmap
= libertas_get_events_bitmap(priv
);
558 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
562 event
= &pcmdptr
->params
.subscribe_event
;
563 event
->action
= cpu_to_le16(CMD_ACT_SET
);
564 pcmdptr
->size
= cpu_to_le16(S_DS_GEN
+
565 sizeof(struct cmd_ds_802_11_subscribe_event
) +
566 sizeof(struct mrvlietypes_rssithreshold
));
568 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
569 ptr
= (u8
*) pcmdptr
+cmd_len
;
570 rssi_threshold
= (struct mrvlietypes_rssithreshold
*)(ptr
);
571 rssi_threshold
->header
.type
= cpu_to_le16(0x0104);
572 rssi_threshold
->header
.len
= cpu_to_le16(2);
573 rssi_threshold
->rssivalue
= value
;
574 rssi_threshold
->rssifreq
= freq
;
575 event_bitmap
|= subscribed
? 0x0001 : 0x0;
576 event
->events
= cpu_to_le16(event_bitmap
);
578 libertas_queue_cmd(adapter
, pcmdnode
, 1);
579 wake_up_interruptible(&priv
->waitq
);
581 /* Sleep until response is generated by FW */
582 wait_event_interruptible(pcmdnode
->cmdwait_q
,
583 pcmdnode
->cmdwaitqwoken
);
585 pcmdptr
= response_buf
;
587 if (pcmdptr
->result
) {
588 lbs_pr_err("%s: fail, result=%d\n", __func__
,
589 le16_to_cpu(pcmdptr
->result
));
595 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
596 lbs_pr_err("command response incorrect!\n");
608 static ssize_t
libertas_lowsnr_read(struct file
*file
, char __user
*userbuf
,
609 size_t count
, loff_t
*ppos
)
611 wlan_private
*priv
= file
->private_data
;
612 wlan_adapter
*adapter
= priv
->adapter
;
613 struct cmd_ctrl_node
*pcmdnode
;
614 struct cmd_ds_command
*pcmdptr
;
615 struct cmd_ds_802_11_subscribe_event
*event
;
619 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
620 char *buf
= (char *)addr
;
622 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
628 event
= &pcmdptr
->params
.subscribe_event
;
629 event
->action
= cpu_to_le16(CMD_ACT_GET
);
630 pcmdptr
->size
= cpu_to_le16(sizeof(*event
) + S_DS_GEN
);
631 libertas_queue_cmd(adapter
, pcmdnode
, 1);
632 wake_up_interruptible(&priv
->waitq
);
634 /* Sleep until response is generated by FW */
635 wait_event_interruptible(pcmdnode
->cmdwait_q
,
636 pcmdnode
->cmdwaitqwoken
);
638 pcmdptr
= response_buf
;
640 if (pcmdptr
->result
) {
641 lbs_pr_err("%s: fail, result=%d\n", __func__
,
642 le16_to_cpu(pcmdptr
->result
));
648 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
649 lbs_pr_err("command response incorrect!\n");
655 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
656 event
= (void *)(response_buf
+ S_DS_GEN
);
657 while (cmd_len
< le16_to_cpu(pcmdptr
->size
)) {
658 struct mrvlietypesheader
*header
= (void *)(response_buf
+ cmd_len
);
659 switch (header
->type
) {
660 struct mrvlietypes_snrthreshold
*LowSnr
;
661 case __constant_cpu_to_le16(TLV_TYPE_SNR_LOW
):
662 LowSnr
= (void *)(response_buf
+ cmd_len
);
663 pos
+= snprintf(buf
+pos
, len
-pos
, "%d %d %d\n",
666 (event
->events
& cpu_to_le16(0x0002))?1:0);
668 cmd_len
+= sizeof(struct mrvlietypes_snrthreshold
);
675 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
680 static ssize_t
libertas_lowsnr_write(struct file
*file
,
681 const char __user
*userbuf
,
682 size_t count
, loff_t
*ppos
)
684 wlan_private
*priv
= file
->private_data
;
685 wlan_adapter
*adapter
= priv
->adapter
;
686 ssize_t res
, buf_size
;
687 int value
, freq
, subscribed
, cmd_len
;
688 struct cmd_ctrl_node
*pcmdnode
;
689 struct cmd_ds_command
*pcmdptr
;
690 struct cmd_ds_802_11_subscribe_event
*event
;
691 struct mrvlietypes_snrthreshold
*snr_threshold
;
695 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
696 char *buf
= (char *)addr
;
698 buf_size
= min(count
, len
- 1);
699 if (copy_from_user(buf
, userbuf
, buf_size
)) {
703 res
= sscanf(buf
, "%d %d %d", &value
, &freq
, &subscribed
);
709 event_bitmap
= libertas_get_events_bitmap(priv
);
711 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
715 event
= &pcmdptr
->params
.subscribe_event
;
716 event
->action
= cpu_to_le16(CMD_ACT_SET
);
717 pcmdptr
->size
= cpu_to_le16(S_DS_GEN
+
718 sizeof(struct cmd_ds_802_11_subscribe_event
) +
719 sizeof(struct mrvlietypes_snrthreshold
));
720 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
721 ptr
= (u8
*) pcmdptr
+cmd_len
;
722 snr_threshold
= (struct mrvlietypes_snrthreshold
*)(ptr
);
723 snr_threshold
->header
.type
= cpu_to_le16(TLV_TYPE_SNR_LOW
);
724 snr_threshold
->header
.len
= cpu_to_le16(2);
725 snr_threshold
->snrvalue
= value
;
726 snr_threshold
->snrfreq
= freq
;
727 event_bitmap
|= subscribed
? 0x0002 : 0x0;
728 event
->events
= cpu_to_le16(event_bitmap
);
730 libertas_queue_cmd(adapter
, pcmdnode
, 1);
731 wake_up_interruptible(&priv
->waitq
);
733 /* Sleep until response is generated by FW */
734 wait_event_interruptible(pcmdnode
->cmdwait_q
,
735 pcmdnode
->cmdwaitqwoken
);
737 pcmdptr
= response_buf
;
739 if (pcmdptr
->result
) {
740 lbs_pr_err("%s: fail, result=%d\n", __func__
,
741 le16_to_cpu(pcmdptr
->result
));
747 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
748 lbs_pr_err("command response incorrect!\n");
761 static ssize_t
libertas_failcount_read(struct file
*file
, char __user
*userbuf
,
762 size_t count
, loff_t
*ppos
)
764 wlan_private
*priv
= file
->private_data
;
765 wlan_adapter
*adapter
= priv
->adapter
;
766 struct cmd_ctrl_node
*pcmdnode
;
767 struct cmd_ds_command
*pcmdptr
;
768 struct cmd_ds_802_11_subscribe_event
*event
;
772 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
773 char *buf
= (char *)addr
;
775 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
781 event
= &pcmdptr
->params
.subscribe_event
;
782 event
->action
= cpu_to_le16(CMD_ACT_GET
);
783 pcmdptr
->size
= cpu_to_le16(sizeof(*event
) + S_DS_GEN
);
784 libertas_queue_cmd(adapter
, pcmdnode
, 1);
785 wake_up_interruptible(&priv
->waitq
);
787 /* Sleep until response is generated by FW */
788 wait_event_interruptible(pcmdnode
->cmdwait_q
,
789 pcmdnode
->cmdwaitqwoken
);
791 pcmdptr
= response_buf
;
793 if (pcmdptr
->result
) {
794 lbs_pr_err("%s: fail, result=%d\n", __func__
,
795 le16_to_cpu(pcmdptr
->result
));
801 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
802 lbs_pr_err("command response incorrect!\n");
808 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
809 event
= (void *)(response_buf
+ S_DS_GEN
);
810 while (cmd_len
< le16_to_cpu(pcmdptr
->size
)) {
811 struct mrvlietypesheader
*header
= (void *)(response_buf
+ cmd_len
);
812 switch (header
->type
) {
813 struct mrvlietypes_failurecount
*failcount
;
814 case __constant_cpu_to_le16(TLV_TYPE_FAILCOUNT
):
815 failcount
= (void *)(response_buf
+ cmd_len
);
816 pos
+= snprintf(buf
+pos
, len
-pos
, "%d %d %d\n",
817 failcount
->failvalue
,
819 (event
->events
& cpu_to_le16(0x0004))?1:0);
821 cmd_len
+= sizeof(struct mrvlietypes_failurecount
);
827 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
832 static ssize_t
libertas_failcount_write(struct file
*file
,
833 const char __user
*userbuf
,
834 size_t count
, loff_t
*ppos
)
836 wlan_private
*priv
= file
->private_data
;
837 wlan_adapter
*adapter
= priv
->adapter
;
838 ssize_t res
, buf_size
;
839 int value
, freq
, subscribed
, cmd_len
;
840 struct cmd_ctrl_node
*pcmdnode
;
841 struct cmd_ds_command
*pcmdptr
;
842 struct cmd_ds_802_11_subscribe_event
*event
;
843 struct mrvlietypes_failurecount
*failcount
;
847 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
848 char *buf
= (char *)addr
;
850 buf_size
= min(count
, len
- 1);
851 if (copy_from_user(buf
, userbuf
, buf_size
)) {
855 res
= sscanf(buf
, "%d %d %d", &value
, &freq
, &subscribed
);
861 event_bitmap
= libertas_get_events_bitmap(priv
);
863 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
867 event
= &pcmdptr
->params
.subscribe_event
;
868 event
->action
= cpu_to_le16(CMD_ACT_SET
);
869 pcmdptr
->size
= cpu_to_le16(S_DS_GEN
+
870 sizeof(struct cmd_ds_802_11_subscribe_event
) +
871 sizeof(struct mrvlietypes_failurecount
));
872 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
873 ptr
= (u8
*) pcmdptr
+cmd_len
;
874 failcount
= (struct mrvlietypes_failurecount
*)(ptr
);
875 failcount
->header
.type
= cpu_to_le16(TLV_TYPE_FAILCOUNT
);
876 failcount
->header
.len
= cpu_to_le16(2);
877 failcount
->failvalue
= value
;
878 failcount
->Failfreq
= freq
;
879 event_bitmap
|= subscribed
? 0x0004 : 0x0;
880 event
->events
= cpu_to_le16(event_bitmap
);
882 libertas_queue_cmd(adapter
, pcmdnode
, 1);
883 wake_up_interruptible(&priv
->waitq
);
885 /* Sleep until response is generated by FW */
886 wait_event_interruptible(pcmdnode
->cmdwait_q
,
887 pcmdnode
->cmdwaitqwoken
);
889 pcmdptr
= (struct cmd_ds_command
*)response_buf
;
891 if (pcmdptr
->result
) {
892 lbs_pr_err("%s: fail, result=%d\n", __func__
,
893 le16_to_cpu(pcmdptr
->result
));
899 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
900 lbs_pr_err("command response incorrect!\n");
912 static ssize_t
libertas_bcnmiss_read(struct file
*file
, char __user
*userbuf
,
913 size_t count
, loff_t
*ppos
)
915 wlan_private
*priv
= file
->private_data
;
916 wlan_adapter
*adapter
= priv
->adapter
;
917 struct cmd_ctrl_node
*pcmdnode
;
918 struct cmd_ds_command
*pcmdptr
;
919 struct cmd_ds_802_11_subscribe_event
*event
;
923 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
924 char *buf
= (char *)addr
;
926 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
932 event
= &pcmdptr
->params
.subscribe_event
;
933 event
->action
= cpu_to_le16(CMD_ACT_GET
);
934 pcmdptr
->size
= cpu_to_le16(sizeof(*event
) + S_DS_GEN
);
935 libertas_queue_cmd(adapter
, pcmdnode
, 1);
936 wake_up_interruptible(&priv
->waitq
);
938 /* Sleep until response is generated by FW */
939 wait_event_interruptible(pcmdnode
->cmdwait_q
,
940 pcmdnode
->cmdwaitqwoken
);
942 pcmdptr
= response_buf
;
944 if (pcmdptr
->result
) {
945 lbs_pr_err("%s: fail, result=%d\n", __func__
,
946 le16_to_cpu(pcmdptr
->result
));
952 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
953 lbs_pr_err("command response incorrect!\n");
959 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
960 event
= (void *)(response_buf
+ S_DS_GEN
);
961 while (cmd_len
< le16_to_cpu(pcmdptr
->size
)) {
962 struct mrvlietypesheader
*header
= (void *)(response_buf
+ cmd_len
);
963 switch (header
->type
) {
964 struct mrvlietypes_beaconsmissed
*bcnmiss
;
965 case __constant_cpu_to_le16(TLV_TYPE_BCNMISS
):
966 bcnmiss
= (void *)(response_buf
+ cmd_len
);
967 pos
+= snprintf(buf
+pos
, len
-pos
, "%d N/A %d\n",
968 bcnmiss
->beaconmissed
,
969 (event
->events
& cpu_to_le16(0x0008))?1:0);
971 cmd_len
+= sizeof(struct mrvlietypes_beaconsmissed
);
978 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
983 static ssize_t
libertas_bcnmiss_write(struct file
*file
,
984 const char __user
*userbuf
,
985 size_t count
, loff_t
*ppos
)
987 wlan_private
*priv
= file
->private_data
;
988 wlan_adapter
*adapter
= priv
->adapter
;
989 ssize_t res
, buf_size
;
990 int value
, freq
, subscribed
, cmd_len
;
991 struct cmd_ctrl_node
*pcmdnode
;
992 struct cmd_ds_command
*pcmdptr
;
993 struct cmd_ds_802_11_subscribe_event
*event
;
994 struct mrvlietypes_beaconsmissed
*bcnmiss
;
998 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
999 char *buf
= (char *)addr
;
1001 buf_size
= min(count
, len
- 1);
1002 if (copy_from_user(buf
, userbuf
, buf_size
)) {
1006 res
= sscanf(buf
, "%d %d %d", &value
, &freq
, &subscribed
);
1012 event_bitmap
= libertas_get_events_bitmap(priv
);
1014 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
1018 event
= &pcmdptr
->params
.subscribe_event
;
1019 event
->action
= cpu_to_le16(CMD_ACT_SET
);
1020 pcmdptr
->size
= cpu_to_le16(S_DS_GEN
+
1021 sizeof(struct cmd_ds_802_11_subscribe_event
) +
1022 sizeof(struct mrvlietypes_beaconsmissed
));
1023 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
1024 ptr
= (u8
*) pcmdptr
+cmd_len
;
1025 bcnmiss
= (struct mrvlietypes_beaconsmissed
*)(ptr
);
1026 bcnmiss
->header
.type
= cpu_to_le16(TLV_TYPE_BCNMISS
);
1027 bcnmiss
->header
.len
= cpu_to_le16(2);
1028 bcnmiss
->beaconmissed
= value
;
1029 event_bitmap
|= subscribed
? 0x0008 : 0x0;
1030 event
->events
= cpu_to_le16(event_bitmap
);
1032 libertas_queue_cmd(adapter
, pcmdnode
, 1);
1033 wake_up_interruptible(&priv
->waitq
);
1035 /* Sleep until response is generated by FW */
1036 wait_event_interruptible(pcmdnode
->cmdwait_q
,
1037 pcmdnode
->cmdwaitqwoken
);
1039 pcmdptr
= response_buf
;
1041 if (pcmdptr
->result
) {
1042 lbs_pr_err("%s: fail, result=%d\n", __func__
,
1043 le16_to_cpu(pcmdptr
->result
));
1044 kfree(response_buf
);
1049 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
1050 lbs_pr_err("command response incorrect!\n");
1052 kfree(response_buf
);
1062 static ssize_t
libertas_highrssi_read(struct file
*file
, char __user
*userbuf
,
1063 size_t count
, loff_t
*ppos
)
1065 wlan_private
*priv
= file
->private_data
;
1066 wlan_adapter
*adapter
= priv
->adapter
;
1067 struct cmd_ctrl_node
*pcmdnode
;
1068 struct cmd_ds_command
*pcmdptr
;
1069 struct cmd_ds_802_11_subscribe_event
*event
;
1073 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1074 char *buf
= (char *)addr
;
1076 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
1082 event
= &pcmdptr
->params
.subscribe_event
;
1083 event
->action
= cpu_to_le16(CMD_ACT_GET
);
1084 pcmdptr
->size
= cpu_to_le16(sizeof(*event
) + S_DS_GEN
);
1085 libertas_queue_cmd(adapter
, pcmdnode
, 1);
1086 wake_up_interruptible(&priv
->waitq
);
1088 /* Sleep until response is generated by FW */
1089 wait_event_interruptible(pcmdnode
->cmdwait_q
,
1090 pcmdnode
->cmdwaitqwoken
);
1092 pcmdptr
= response_buf
;
1094 if (pcmdptr
->result
) {
1095 lbs_pr_err("%s: fail, result=%d\n", __func__
,
1096 le16_to_cpu(pcmdptr
->result
));
1097 kfree(response_buf
);
1102 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
1103 lbs_pr_err("command response incorrect!\n");
1104 kfree(response_buf
);
1109 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
1110 event
= (void *)(response_buf
+ S_DS_GEN
);
1111 while (cmd_len
< le16_to_cpu(pcmdptr
->size
)) {
1112 struct mrvlietypesheader
*header
= (void *)(response_buf
+ cmd_len
);
1113 switch (header
->type
) {
1114 struct mrvlietypes_rssithreshold
*Highrssi
;
1115 case __constant_cpu_to_le16(TLV_TYPE_RSSI_HIGH
):
1116 Highrssi
= (void *)(response_buf
+ cmd_len
);
1117 pos
+= snprintf(buf
+pos
, len
-pos
, "%d %d %d\n",
1118 Highrssi
->rssivalue
,
1120 (event
->events
& cpu_to_le16(0x0010))?1:0);
1122 cmd_len
+= sizeof(struct mrvlietypes_snrthreshold
);
1127 kfree(response_buf
);
1129 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
1134 static ssize_t
libertas_highrssi_write(struct file
*file
,
1135 const char __user
*userbuf
,
1136 size_t count
, loff_t
*ppos
)
1138 wlan_private
*priv
= file
->private_data
;
1139 wlan_adapter
*adapter
= priv
->adapter
;
1140 ssize_t res
, buf_size
;
1141 int value
, freq
, subscribed
, cmd_len
;
1142 struct cmd_ctrl_node
*pcmdnode
;
1143 struct cmd_ds_command
*pcmdptr
;
1144 struct cmd_ds_802_11_subscribe_event
*event
;
1145 struct mrvlietypes_rssithreshold
*rssi_threshold
;
1149 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1150 char *buf
= (char *)addr
;
1152 buf_size
= min(count
, len
- 1);
1153 if (copy_from_user(buf
, userbuf
, buf_size
)) {
1157 res
= sscanf(buf
, "%d %d %d", &value
, &freq
, &subscribed
);
1163 event_bitmap
= libertas_get_events_bitmap(priv
);
1165 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
1169 event
= &pcmdptr
->params
.subscribe_event
;
1170 event
->action
= cpu_to_le16(CMD_ACT_SET
);
1171 pcmdptr
->size
= cpu_to_le16(S_DS_GEN
+
1172 sizeof(struct cmd_ds_802_11_subscribe_event
) +
1173 sizeof(struct mrvlietypes_rssithreshold
));
1174 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
1175 ptr
= (u8
*) pcmdptr
+cmd_len
;
1176 rssi_threshold
= (struct mrvlietypes_rssithreshold
*)(ptr
);
1177 rssi_threshold
->header
.type
= cpu_to_le16(TLV_TYPE_RSSI_HIGH
);
1178 rssi_threshold
->header
.len
= cpu_to_le16(2);
1179 rssi_threshold
->rssivalue
= value
;
1180 rssi_threshold
->rssifreq
= freq
;
1181 event_bitmap
|= subscribed
? 0x0010 : 0x0;
1182 event
->events
= cpu_to_le16(event_bitmap
);
1184 libertas_queue_cmd(adapter
, pcmdnode
, 1);
1185 wake_up_interruptible(&priv
->waitq
);
1187 /* Sleep until response is generated by FW */
1188 wait_event_interruptible(pcmdnode
->cmdwait_q
,
1189 pcmdnode
->cmdwaitqwoken
);
1191 pcmdptr
= response_buf
;
1193 if (pcmdptr
->result
) {
1194 lbs_pr_err("%s: fail, result=%d\n", __func__
,
1195 le16_to_cpu(pcmdptr
->result
));
1196 kfree(response_buf
);
1200 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
1201 lbs_pr_err("command response incorrect!\n");
1202 kfree(response_buf
);
1212 static ssize_t
libertas_highsnr_read(struct file
*file
, char __user
*userbuf
,
1213 size_t count
, loff_t
*ppos
)
1215 wlan_private
*priv
= file
->private_data
;
1216 wlan_adapter
*adapter
= priv
->adapter
;
1217 struct cmd_ctrl_node
*pcmdnode
;
1218 struct cmd_ds_command
*pcmdptr
;
1219 struct cmd_ds_802_11_subscribe_event
*event
;
1223 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1224 char *buf
= (char *)addr
;
1226 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
1232 event
= &pcmdptr
->params
.subscribe_event
;
1233 event
->action
= cpu_to_le16(CMD_ACT_GET
);
1234 pcmdptr
->size
= cpu_to_le16(sizeof(*event
) + S_DS_GEN
);
1235 libertas_queue_cmd(adapter
, pcmdnode
, 1);
1236 wake_up_interruptible(&priv
->waitq
);
1238 /* Sleep until response is generated by FW */
1239 wait_event_interruptible(pcmdnode
->cmdwait_q
,
1240 pcmdnode
->cmdwaitqwoken
);
1242 pcmdptr
= response_buf
;
1244 if (pcmdptr
->result
) {
1245 lbs_pr_err("%s: fail, result=%d\n", __func__
,
1246 le16_to_cpu(pcmdptr
->result
));
1247 kfree(response_buf
);
1252 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
1253 lbs_pr_err("command response incorrect!\n");
1254 kfree(response_buf
);
1259 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
1260 event
= (void *)(response_buf
+ S_DS_GEN
);
1261 while (cmd_len
< le16_to_cpu(pcmdptr
->size
)) {
1262 struct mrvlietypesheader
*header
= (void *)(response_buf
+ cmd_len
);
1263 switch (header
->type
) {
1264 struct mrvlietypes_snrthreshold
*HighSnr
;
1265 case __constant_cpu_to_le16(TLV_TYPE_SNR_HIGH
):
1266 HighSnr
= (void *)(response_buf
+ cmd_len
);
1267 pos
+= snprintf(buf
+pos
, len
-pos
, "%d %d %d\n",
1270 (event
->events
& cpu_to_le16(0x0020))?1:0);
1272 cmd_len
+= sizeof(struct mrvlietypes_snrthreshold
);
1277 kfree(response_buf
);
1279 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
1284 static ssize_t
libertas_highsnr_write(struct file
*file
,
1285 const char __user
*userbuf
,
1286 size_t count
, loff_t
*ppos
)
1288 wlan_private
*priv
= file
->private_data
;
1289 wlan_adapter
*adapter
= priv
->adapter
;
1290 ssize_t res
, buf_size
;
1291 int value
, freq
, subscribed
, cmd_len
;
1292 struct cmd_ctrl_node
*pcmdnode
;
1293 struct cmd_ds_command
*pcmdptr
;
1294 struct cmd_ds_802_11_subscribe_event
*event
;
1295 struct mrvlietypes_snrthreshold
*snr_threshold
;
1299 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1300 char *buf
= (char *)addr
;
1302 buf_size
= min(count
, len
- 1);
1303 if (copy_from_user(buf
, userbuf
, buf_size
)) {
1307 res
= sscanf(buf
, "%d %d %d", &value
, &freq
, &subscribed
);
1313 event_bitmap
= libertas_get_events_bitmap(priv
);
1315 res
= libertas_event_initcmd(priv
, &response_buf
, &pcmdnode
, &pcmdptr
);
1319 event
= &pcmdptr
->params
.subscribe_event
;
1320 event
->action
= cpu_to_le16(CMD_ACT_SET
);
1321 pcmdptr
->size
= cpu_to_le16(S_DS_GEN
+
1322 sizeof(struct cmd_ds_802_11_subscribe_event
) +
1323 sizeof(struct mrvlietypes_snrthreshold
));
1324 cmd_len
= S_DS_GEN
+ sizeof(struct cmd_ds_802_11_subscribe_event
);
1325 ptr
= (u8
*) pcmdptr
+cmd_len
;
1326 snr_threshold
= (struct mrvlietypes_snrthreshold
*)(ptr
);
1327 snr_threshold
->header
.type
= cpu_to_le16(TLV_TYPE_SNR_HIGH
);
1328 snr_threshold
->header
.len
= cpu_to_le16(2);
1329 snr_threshold
->snrvalue
= value
;
1330 snr_threshold
->snrfreq
= freq
;
1331 event_bitmap
|= subscribed
? 0x0020 : 0x0;
1332 event
->events
= cpu_to_le16(event_bitmap
);
1334 libertas_queue_cmd(adapter
, pcmdnode
, 1);
1335 wake_up_interruptible(&priv
->waitq
);
1337 /* Sleep until response is generated by FW */
1338 wait_event_interruptible(pcmdnode
->cmdwait_q
,
1339 pcmdnode
->cmdwaitqwoken
);
1341 pcmdptr
= response_buf
;
1343 if (pcmdptr
->result
) {
1344 lbs_pr_err("%s: fail, result=%d\n", __func__
,
1345 le16_to_cpu(pcmdptr
->result
));
1346 kfree(response_buf
);
1351 if (pcmdptr
->command
!= cpu_to_le16(CMD_RET(CMD_802_11_SUBSCRIBE_EVENT
))) {
1352 lbs_pr_err("command response incorrect!\n");
1353 kfree(response_buf
);
1364 static ssize_t
libertas_rdmac_read(struct file
*file
, char __user
*userbuf
,
1365 size_t count
, loff_t
*ppos
)
1367 wlan_private
*priv
= file
->private_data
;
1368 wlan_adapter
*adapter
= priv
->adapter
;
1369 struct wlan_offset_value offval
;
1372 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1373 char *buf
= (char *)addr
;
1375 offval
.offset
= priv
->mac_offset
;
1378 ret
= libertas_prepare_and_send_command(priv
,
1379 CMD_MAC_REG_ACCESS
, 0,
1380 CMD_OPTION_WAITFORRSP
, 0, &offval
);
1382 pos
+= snprintf(buf
+pos
, len
-pos
, "MAC[0x%x] = 0x%08x\n",
1383 priv
->mac_offset
, adapter
->offsetvalue
.value
);
1385 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
1390 static ssize_t
libertas_rdmac_write(struct file
*file
,
1391 const char __user
*userbuf
,
1392 size_t count
, loff_t
*ppos
)
1394 wlan_private
*priv
= file
->private_data
;
1395 ssize_t res
, buf_size
;
1396 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1397 char *buf
= (char *)addr
;
1399 buf_size
= min(count
, len
- 1);
1400 if (copy_from_user(buf
, userbuf
, buf_size
)) {
1404 priv
->mac_offset
= simple_strtoul((char *)buf
, NULL
, 16);
1411 static ssize_t
libertas_wrmac_write(struct file
*file
,
1412 const char __user
*userbuf
,
1413 size_t count
, loff_t
*ppos
)
1416 wlan_private
*priv
= file
->private_data
;
1417 ssize_t res
, buf_size
;
1419 struct wlan_offset_value offval
;
1420 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1421 char *buf
= (char *)addr
;
1423 buf_size
= min(count
, len
- 1);
1424 if (copy_from_user(buf
, userbuf
, buf_size
)) {
1428 res
= sscanf(buf
, "%x %x", &offset
, &value
);
1434 offval
.offset
= offset
;
1435 offval
.value
= value
;
1436 res
= libertas_prepare_and_send_command(priv
,
1437 CMD_MAC_REG_ACCESS
, 1,
1438 CMD_OPTION_WAITFORRSP
, 0, &offval
);
1447 static ssize_t
libertas_rdbbp_read(struct file
*file
, char __user
*userbuf
,
1448 size_t count
, loff_t
*ppos
)
1450 wlan_private
*priv
= file
->private_data
;
1451 wlan_adapter
*adapter
= priv
->adapter
;
1452 struct wlan_offset_value offval
;
1455 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1456 char *buf
= (char *)addr
;
1458 offval
.offset
= priv
->bbp_offset
;
1461 ret
= libertas_prepare_and_send_command(priv
,
1462 CMD_BBP_REG_ACCESS
, 0,
1463 CMD_OPTION_WAITFORRSP
, 0, &offval
);
1465 pos
+= snprintf(buf
+pos
, len
-pos
, "BBP[0x%x] = 0x%08x\n",
1466 priv
->bbp_offset
, adapter
->offsetvalue
.value
);
1468 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
1474 static ssize_t
libertas_rdbbp_write(struct file
*file
,
1475 const char __user
*userbuf
,
1476 size_t count
, loff_t
*ppos
)
1478 wlan_private
*priv
= file
->private_data
;
1479 ssize_t res
, buf_size
;
1480 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1481 char *buf
= (char *)addr
;
1483 buf_size
= min(count
, len
- 1);
1484 if (copy_from_user(buf
, userbuf
, buf_size
)) {
1488 priv
->bbp_offset
= simple_strtoul((char *)buf
, NULL
, 16);
1495 static ssize_t
libertas_wrbbp_write(struct file
*file
,
1496 const char __user
*userbuf
,
1497 size_t count
, loff_t
*ppos
)
1500 wlan_private
*priv
= file
->private_data
;
1501 ssize_t res
, buf_size
;
1503 struct wlan_offset_value offval
;
1504 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1505 char *buf
= (char *)addr
;
1507 buf_size
= min(count
, len
- 1);
1508 if (copy_from_user(buf
, userbuf
, buf_size
)) {
1512 res
= sscanf(buf
, "%x %x", &offset
, &value
);
1518 offval
.offset
= offset
;
1519 offval
.value
= value
;
1520 res
= libertas_prepare_and_send_command(priv
,
1521 CMD_BBP_REG_ACCESS
, 1,
1522 CMD_OPTION_WAITFORRSP
, 0, &offval
);
1531 static ssize_t
libertas_rdrf_read(struct file
*file
, char __user
*userbuf
,
1532 size_t count
, loff_t
*ppos
)
1534 wlan_private
*priv
= file
->private_data
;
1535 wlan_adapter
*adapter
= priv
->adapter
;
1536 struct wlan_offset_value offval
;
1539 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1540 char *buf
= (char *)addr
;
1542 offval
.offset
= priv
->rf_offset
;
1545 ret
= libertas_prepare_and_send_command(priv
,
1546 CMD_RF_REG_ACCESS
, 0,
1547 CMD_OPTION_WAITFORRSP
, 0, &offval
);
1549 pos
+= snprintf(buf
+pos
, len
-pos
, "RF[0x%x] = 0x%08x\n",
1550 priv
->rf_offset
, adapter
->offsetvalue
.value
);
1552 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
1558 static ssize_t
libertas_rdrf_write(struct file
*file
,
1559 const char __user
*userbuf
,
1560 size_t count
, loff_t
*ppos
)
1562 wlan_private
*priv
= file
->private_data
;
1563 ssize_t res
, buf_size
;
1564 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1565 char *buf
= (char *)addr
;
1567 buf_size
= min(count
, len
- 1);
1568 if (copy_from_user(buf
, userbuf
, buf_size
)) {
1572 priv
->rf_offset
= simple_strtoul((char *)buf
, NULL
, 16);
1579 static ssize_t
libertas_wrrf_write(struct file
*file
,
1580 const char __user
*userbuf
,
1581 size_t count
, loff_t
*ppos
)
1584 wlan_private
*priv
= file
->private_data
;
1585 ssize_t res
, buf_size
;
1587 struct wlan_offset_value offval
;
1588 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1589 char *buf
= (char *)addr
;
1591 buf_size
= min(count
, len
- 1);
1592 if (copy_from_user(buf
, userbuf
, buf_size
)) {
1596 res
= sscanf(buf
, "%x %x", &offset
, &value
);
1602 offval
.offset
= offset
;
1603 offval
.value
= value
;
1604 res
= libertas_prepare_and_send_command(priv
,
1605 CMD_RF_REG_ACCESS
, 1,
1606 CMD_OPTION_WAITFORRSP
, 0, &offval
);
1615 #define FOPS(fread, fwrite) { \
1616 .owner = THIS_MODULE, \
1617 .open = open_file_generic, \
1619 .write = (fwrite), \
1622 struct libertas_debugfs_files
{
1625 struct file_operations fops
;
1628 static struct libertas_debugfs_files debugfs_files
[] = {
1629 { "info", 0444, FOPS(libertas_dev_info
, write_file_dummy
), },
1630 { "getscantable", 0444, FOPS(libertas_getscantable
,
1631 write_file_dummy
), },
1632 { "sleepparams", 0644, FOPS(libertas_sleepparams_read
,
1633 libertas_sleepparams_write
), },
1634 { "extscan", 0600, FOPS(NULL
, libertas_extscan
), },
1635 { "setuserscan", 0600, FOPS(NULL
, libertas_setuserscan
), },
1638 static struct libertas_debugfs_files debugfs_events_files
[] = {
1639 {"low_rssi", 0644, FOPS(libertas_lowrssi_read
,
1640 libertas_lowrssi_write
), },
1641 {"low_snr", 0644, FOPS(libertas_lowsnr_read
,
1642 libertas_lowsnr_write
), },
1643 {"failure_count", 0644, FOPS(libertas_failcount_read
,
1644 libertas_failcount_write
), },
1645 {"beacon_missed", 0644, FOPS(libertas_bcnmiss_read
,
1646 libertas_bcnmiss_write
), },
1647 {"high_rssi", 0644, FOPS(libertas_highrssi_read
,
1648 libertas_highrssi_write
), },
1649 {"high_snr", 0644, FOPS(libertas_highsnr_read
,
1650 libertas_highsnr_write
), },
1653 static struct libertas_debugfs_files debugfs_regs_files
[] = {
1654 {"rdmac", 0644, FOPS(libertas_rdmac_read
, libertas_rdmac_write
), },
1655 {"wrmac", 0600, FOPS(NULL
, libertas_wrmac_write
), },
1656 {"rdbbp", 0644, FOPS(libertas_rdbbp_read
, libertas_rdbbp_write
), },
1657 {"wrbbp", 0600, FOPS(NULL
, libertas_wrbbp_write
), },
1658 {"rdrf", 0644, FOPS(libertas_rdrf_read
, libertas_rdrf_write
), },
1659 {"wrrf", 0600, FOPS(NULL
, libertas_wrrf_write
), },
1662 void libertas_debugfs_init(void)
1665 libertas_dir
= debugfs_create_dir("libertas_wireless", NULL
);
1670 void libertas_debugfs_remove(void)
1673 debugfs_remove(libertas_dir
);
1677 void libertas_debugfs_init_one(wlan_private
*priv
, struct net_device
*dev
)
1680 struct libertas_debugfs_files
*files
;
1684 priv
->debugfs_dir
= debugfs_create_dir(dev
->name
, libertas_dir
);
1685 if (!priv
->debugfs_dir
)
1688 for (i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++) {
1689 files
= &debugfs_files
[i
];
1690 priv
->debugfs_files
[i
] = debugfs_create_file(files
->name
,
1697 priv
->events_dir
= debugfs_create_dir("subscribed_events", priv
->debugfs_dir
);
1698 if (!priv
->events_dir
)
1701 for (i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++) {
1702 files
= &debugfs_events_files
[i
];
1703 priv
->debugfs_events_files
[i
] = debugfs_create_file(files
->name
,
1710 priv
->regs_dir
= debugfs_create_dir("registers", priv
->debugfs_dir
);
1711 if (!priv
->regs_dir
)
1714 for (i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++) {
1715 files
= &debugfs_regs_files
[i
];
1716 priv
->debugfs_regs_files
[i
] = debugfs_create_file(files
->name
,
1724 libertas_debug_init(priv
, dev
);
1730 void libertas_debugfs_remove_one(wlan_private
*priv
)
1734 for(i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++)
1735 debugfs_remove(priv
->debugfs_regs_files
[i
]);
1737 debugfs_remove(priv
->regs_dir
);
1739 for(i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++)
1740 debugfs_remove(priv
->debugfs_events_files
[i
]);
1742 debugfs_remove(priv
->events_dir
);
1744 debugfs_remove(priv
->debugfs_debug
);
1746 for(i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++)
1747 debugfs_remove(priv
->debugfs_files
[i
]);
1748 debugfs_remove(priv
->debugfs_dir
);
1757 #define item_size(n) (FIELD_SIZEOF(wlan_adapter, n))
1758 #define item_addr(n) (offsetof(wlan_adapter, n))
1767 /* To debug any member of wlan_adapter, simply add one line here.
1769 static struct debug_data items
[] = {
1770 {"intcounter", item_size(intcounter
), item_addr(intcounter
)},
1771 {"psmode", item_size(psmode
), item_addr(psmode
)},
1772 {"psstate", item_size(psstate
), item_addr(psstate
)},
1775 static int num_of_items
= ARRAY_SIZE(items
);
1778 * @brief proc read function
1780 * @param page pointer to buffer
1781 * @param s read data starting position
1783 * @param cnt counter
1784 * @param eof end of file flag
1785 * @param data data to output
1786 * @return number of output data
1788 static ssize_t
wlan_debugfs_read(struct file
*file
, char __user
*userbuf
,
1789 size_t count
, loff_t
*ppos
)
1796 struct debug_data
*d
;
1797 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1798 char *buf
= (char *)addr
;
1802 d
= (struct debug_data
*)file
->private_data
;
1804 for (i
= 0; i
< num_of_items
; i
++) {
1806 val
= *((u8
*) d
[i
].addr
);
1807 else if (d
[i
].size
== 2)
1808 val
= *((u16
*) d
[i
].addr
);
1809 else if (d
[i
].size
== 4)
1810 val
= *((u32
*) d
[i
].addr
);
1811 else if (d
[i
].size
== 8)
1812 val
= *((u64
*) d
[i
].addr
);
1814 pos
+= sprintf(p
+ pos
, "%s=%d\n", d
[i
].name
, val
);
1817 res
= simple_read_from_buffer(userbuf
, count
, ppos
, p
, pos
);
1824 * @brief proc write function
1826 * @param f file pointer
1827 * @param buf pointer to data buffer
1828 * @param cnt data number to write
1829 * @param data data to write
1830 * @return number of data
1832 static ssize_t
wlan_debugfs_write(struct file
*f
, const char __user
*buf
,
1833 size_t cnt
, loff_t
*ppos
)
1841 struct debug_data
*d
= (struct debug_data
*)f
->private_data
;
1843 pdata
= kmalloc(cnt
, GFP_KERNEL
);
1847 if (copy_from_user(pdata
, buf
, cnt
)) {
1848 lbs_deb_debugfs("Copy from user failed\n");
1854 for (i
= 0; i
< num_of_items
; i
++) {
1856 p
= strstr(p0
, d
[i
].name
);
1859 p1
= strchr(p
, '\n');
1863 p2
= strchr(p
, '=');
1867 r
= simple_strtoul(p2
, NULL
, 0);
1869 *((u8
*) d
[i
].addr
) = (u8
) r
;
1870 else if (d
[i
].size
== 2)
1871 *((u16
*) d
[i
].addr
) = (u16
) r
;
1872 else if (d
[i
].size
== 4)
1873 *((u32
*) d
[i
].addr
) = (u32
) r
;
1874 else if (d
[i
].size
== 8)
1875 *((u64
*) d
[i
].addr
) = (u64
) r
;
1881 return (ssize_t
)cnt
;
1884 static struct file_operations libertas_debug_fops
= {
1885 .owner
= THIS_MODULE
,
1886 .open
= open_file_generic
,
1887 .write
= wlan_debugfs_write
,
1888 .read
= wlan_debugfs_read
,
1892 * @brief create debug proc file
1894 * @param priv pointer wlan_private
1895 * @param dev pointer net_device
1898 static void libertas_debug_init(wlan_private
* priv
, struct net_device
*dev
)
1902 if (!priv
->debugfs_dir
)
1905 for (i
= 0; i
< num_of_items
; i
++)
1906 items
[i
].addr
+= (size_t) priv
->adapter
;
1908 priv
->debugfs_debug
= debugfs_create_file("debug", 0644,
1909 priv
->debugfs_dir
, &items
[0],
1910 &libertas_debug_fops
);