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>
15 static struct dentry
*lbs_dir
;
16 static char *szStates
[] = {
22 static void lbs_debug_init(struct lbs_private
*priv
, struct net_device
*dev
);
25 static int open_file_generic(struct inode
*inode
, struct file
*file
)
27 file
->private_data
= inode
->i_private
;
31 static ssize_t
write_file_dummy(struct file
*file
, const char __user
*buf
,
32 size_t count
, loff_t
*ppos
)
37 static const size_t len
= PAGE_SIZE
;
39 static ssize_t
lbs_dev_info(struct file
*file
, char __user
*userbuf
,
40 size_t count
, loff_t
*ppos
)
42 struct lbs_private
*priv
= file
->private_data
;
44 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
45 char *buf
= (char *)addr
;
48 pos
+= snprintf(buf
+pos
, len
-pos
, "state = %s\n",
49 szStates
[priv
->connect_status
]);
50 pos
+= snprintf(buf
+pos
, len
-pos
, "region_code = %02x\n",
51 (u32
) priv
->regioncode
);
53 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
60 static ssize_t
lbs_getscantable(struct file
*file
, char __user
*userbuf
,
61 size_t count
, loff_t
*ppos
)
63 struct lbs_private
*priv
= file
->private_data
;
65 int numscansdone
= 0, res
;
66 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
67 char *buf
= (char *)addr
;
69 struct bss_descriptor
* iter_bss
;
71 pos
+= snprintf(buf
+pos
, len
-pos
,
72 "# | ch | rssi | bssid | cap | Qual | SSID \n");
74 mutex_lock(&priv
->lock
);
75 list_for_each_entry (iter_bss
, &priv
->network_list
, list
) {
76 u16 ibss
= (iter_bss
->capability
& WLAN_CAPABILITY_IBSS
);
77 u16 privacy
= (iter_bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
78 u16 spectrum_mgmt
= (iter_bss
->capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
);
80 pos
+= snprintf(buf
+pos
, len
-pos
,
81 "%02u| %03d | %04ld | %s |",
82 numscansdone
, iter_bss
->channel
, iter_bss
->rssi
,
83 print_mac(mac
, iter_bss
->bssid
));
84 pos
+= snprintf(buf
+pos
, len
-pos
, " %04x-", iter_bss
->capability
);
85 pos
+= snprintf(buf
+pos
, len
-pos
, "%c%c%c |",
86 ibss
? 'A' : 'I', privacy
? 'P' : ' ',
87 spectrum_mgmt
? 'S' : ' ');
88 pos
+= snprintf(buf
+pos
, len
-pos
, " %04d |", SCAN_RSSI(iter_bss
->rssi
));
89 pos
+= snprintf(buf
+pos
, len
-pos
, " %s\n",
90 escape_essid(iter_bss
->ssid
, iter_bss
->ssid_len
));
94 mutex_unlock(&priv
->lock
);
96 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
102 static ssize_t
lbs_sleepparams_write(struct file
*file
,
103 const char __user
*user_buf
, size_t count
,
106 struct lbs_private
*priv
= file
->private_data
;
107 ssize_t buf_size
, ret
;
108 struct sleep_params sp
;
109 int p1
, p2
, p3
, p4
, p5
, p6
;
110 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
111 char *buf
= (char *)addr
;
113 buf_size
= min(count
, len
- 1);
114 if (copy_from_user(buf
, user_buf
, buf_size
)) {
118 ret
= sscanf(buf
, "%d %d %d %d %d %d", &p1
, &p2
, &p3
, &p4
, &p5
, &p6
);
125 sp
.sp_stabletime
= p3
;
126 sp
.sp_calcontrol
= p4
;
127 sp
.sp_extsleepclk
= p5
;
130 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_SET
, &sp
);
141 static ssize_t
lbs_sleepparams_read(struct file
*file
, char __user
*userbuf
,
142 size_t count
, loff_t
*ppos
)
144 struct lbs_private
*priv
= file
->private_data
;
147 struct sleep_params sp
;
148 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
149 char *buf
= (char *)addr
;
151 ret
= lbs_cmd_802_11_sleep_params(priv
, CMD_ACT_GET
, &sp
);
155 pos
+= snprintf(buf
, len
, "%d %d %d %d %d %d\n", sp
.sp_error
,
156 sp
.sp_offset
, sp
.sp_stabletime
,
157 sp
.sp_calcontrol
, sp
.sp_extsleepclk
,
160 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
167 static ssize_t
lbs_extscan(struct file
*file
, const char __user
*userbuf
,
168 size_t count
, loff_t
*ppos
)
170 struct lbs_private
*priv
= file
->private_data
;
171 ssize_t res
, buf_size
;
172 union iwreq_data wrqu
;
173 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
174 char *buf
= (char *)addr
;
176 buf_size
= min(count
, len
- 1);
177 if (copy_from_user(buf
, userbuf
, buf_size
)) {
182 lbs_send_specific_ssid_scan(priv
, buf
, strlen(buf
)-1, 0);
184 memset(&wrqu
, 0, sizeof(union iwreq_data
));
185 wireless_send_event(priv
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
192 static void lbs_parse_bssid(char *buf
, size_t count
,
193 struct lbs_ioctl_user_scan_cfg
*scan_cfg
)
196 unsigned int mac
[ETH_ALEN
];
198 hold
= strstr(buf
, "bssid=");
202 sscanf(hold
, "%02x:%02x:%02x:%02x:%02x:%02x",
203 mac
, mac
+1, mac
+2, mac
+3, mac
+4, mac
+5);
204 memcpy(scan_cfg
->bssid
, mac
, ETH_ALEN
);
207 static void lbs_parse_ssid(char *buf
, size_t count
,
208 struct lbs_ioctl_user_scan_cfg
*scan_cfg
)
213 hold
= strstr(buf
, "ssid=");
217 end
= strchr(hold
, ' ');
219 end
= buf
+ count
- 1;
221 size
= min((size_t)IW_ESSID_MAX_SIZE
, (size_t) (end
- hold
));
222 strncpy(scan_cfg
->ssid
, hold
, size
);
227 static int lbs_parse_clear(char *buf
, size_t count
, const char *tag
)
232 hold
= strstr(buf
, tag
);
236 sscanf(hold
, "%d", &val
);
244 static int lbs_parse_dur(char *buf
, size_t count
,
245 struct lbs_ioctl_user_scan_cfg
*scan_cfg
)
250 hold
= strstr(buf
, "dur=");
254 sscanf(hold
, "%d", &val
);
259 static void lbs_parse_type(char *buf
, size_t count
,
260 struct lbs_ioctl_user_scan_cfg
*scan_cfg
)
265 hold
= strstr(buf
, "type=");
269 sscanf(hold
, "%d", &val
);
272 if (val
< 1 || val
> 3)
275 scan_cfg
->bsstype
= val
;
280 static ssize_t
lbs_setuserscan(struct file
*file
,
281 const char __user
*userbuf
,
282 size_t count
, loff_t
*ppos
)
284 struct lbs_private
*priv
= file
->private_data
;
285 ssize_t res
, buf_size
;
286 struct lbs_ioctl_user_scan_cfg
*scan_cfg
;
287 union iwreq_data wrqu
;
289 char *buf
= (char *)get_zeroed_page(GFP_KERNEL
);
294 buf_size
= min(count
, len
- 1);
295 if (copy_from_user(buf
, userbuf
, buf_size
)) {
300 scan_cfg
= kzalloc(sizeof(struct lbs_ioctl_user_scan_cfg
), GFP_KERNEL
);
307 scan_cfg
->bsstype
= LBS_SCAN_BSS_TYPE_ANY
;
309 dur
= lbs_parse_dur(buf
, count
, scan_cfg
);
310 lbs_parse_bssid(buf
, count
, scan_cfg
);
311 scan_cfg
->clear_bssid
= lbs_parse_clear(buf
, count
, "clear_bssid=");
312 lbs_parse_ssid(buf
, count
, scan_cfg
);
313 scan_cfg
->clear_ssid
= lbs_parse_clear(buf
, count
, "clear_ssid=");
314 lbs_parse_type(buf
, count
, scan_cfg
);
316 lbs_scan_networks(priv
, scan_cfg
, 1);
317 wait_event_interruptible(priv
->cmd_pending
,
318 priv
->surpriseremoved
|| !priv
->last_scanned_channel
);
320 if (priv
->surpriseremoved
)
323 memset(&wrqu
, 0x00, sizeof(union iwreq_data
));
324 wireless_send_event(priv
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
329 free_page((unsigned long)buf
);
335 * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
336 * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
337 * firmware. Here's an example:
338 * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
339 * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
340 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
342 * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
343 * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
344 * defined in mrvlietypes_thresholds
346 * This function searches in this TLV data chunk for a given TLV type
347 * and returns a pointer to the first data byte of the TLV, or to NULL
348 * if the TLV hasn't been found.
350 static void *lbs_tlv_find(uint16_t tlv_type
, const uint8_t *tlv
, uint16_t size
)
352 struct mrvlietypesheader
*tlv_h
;
357 tlv_h
= (struct mrvlietypesheader
*) tlv
;
360 if (tlv_h
->type
== cpu_to_le16(tlv_type
))
362 length
= le16_to_cpu(tlv_h
->len
) + sizeof(*tlv_h
);
370 static ssize_t
lbs_threshold_read(uint16_t tlv_type
, uint16_t event_mask
,
371 struct file
*file
, char __user
*userbuf
,
372 size_t count
, loff_t
*ppos
)
374 struct cmd_ds_802_11_subscribe_event
*subscribed
;
375 struct mrvlietypes_thresholds
*got
;
376 struct lbs_private
*priv
= file
->private_data
;
384 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
388 subscribed
= kzalloc(sizeof(*subscribed
), GFP_KERNEL
);
394 subscribed
->hdr
.size
= cpu_to_le16(sizeof(*subscribed
));
395 subscribed
->action
= cpu_to_le16(CMD_ACT_GET
);
397 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, subscribed
);
401 got
= lbs_tlv_find(tlv_type
, subscribed
->tlv
, sizeof(subscribed
->tlv
));
405 events
= le16_to_cpu(subscribed
->events
);
407 pos
+= snprintf(buf
, len
, "%d %d %d\n", value
, freq
,
408 !!(events
& event_mask
));
411 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
417 free_page((unsigned long)buf
);
422 static ssize_t
lbs_threshold_write(uint16_t tlv_type
, uint16_t event_mask
,
424 const char __user
*userbuf
, size_t count
,
427 struct cmd_ds_802_11_subscribe_event
*events
;
428 struct mrvlietypes_thresholds
*tlv
;
429 struct lbs_private
*priv
= file
->private_data
;
431 int value
, freq
, new_mask
;
436 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
440 buf_size
= min(count
, len
- 1);
441 if (copy_from_user(buf
, userbuf
, buf_size
)) {
445 ret
= sscanf(buf
, "%d %d %d", &value
, &freq
, &new_mask
);
450 events
= kzalloc(sizeof(*events
), GFP_KERNEL
);
456 events
->hdr
.size
= cpu_to_le16(sizeof(*events
));
457 events
->action
= cpu_to_le16(CMD_ACT_GET
);
459 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
463 curr_mask
= le16_to_cpu(events
->events
);
466 new_mask
= curr_mask
| event_mask
;
468 new_mask
= curr_mask
& ~event_mask
;
470 /* Now everything is set and we can send stuff down to the firmware */
472 tlv
= (void *)events
->tlv
;
474 events
->action
= cpu_to_le16(CMD_ACT_SET
);
475 events
->events
= cpu_to_le16(new_mask
);
476 tlv
->header
.type
= cpu_to_le16(tlv_type
);
477 tlv
->header
.len
= cpu_to_le16(sizeof(*tlv
) - sizeof(tlv
->header
));
479 if (tlv_type
!= TLV_TYPE_BCNMISS
)
482 /* The command header, the event mask, and the one TLV */
483 events
->hdr
.size
= cpu_to_le16(sizeof(events
->hdr
) + 2 + sizeof(*tlv
));
485 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SUBSCRIBE_EVENT
, events
);
492 free_page((unsigned long)buf
);
497 static ssize_t
lbs_lowrssi_read(struct file
*file
, char __user
*userbuf
,
498 size_t count
, loff_t
*ppos
)
500 return lbs_threshold_read(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
501 file
, userbuf
, count
, ppos
);
505 static ssize_t
lbs_lowrssi_write(struct file
*file
, const char __user
*userbuf
,
506 size_t count
, loff_t
*ppos
)
508 return lbs_threshold_write(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
509 file
, userbuf
, count
, ppos
);
513 static ssize_t
lbs_lowsnr_read(struct file
*file
, char __user
*userbuf
,
514 size_t count
, loff_t
*ppos
)
516 return lbs_threshold_read(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
517 file
, userbuf
, count
, ppos
);
521 static ssize_t
lbs_lowsnr_write(struct file
*file
, const char __user
*userbuf
,
522 size_t count
, loff_t
*ppos
)
524 return lbs_threshold_write(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
525 file
, userbuf
, count
, ppos
);
529 static ssize_t
lbs_failcount_read(struct file
*file
, char __user
*userbuf
,
530 size_t count
, loff_t
*ppos
)
532 return lbs_threshold_read(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
533 file
, userbuf
, count
, ppos
);
537 static ssize_t
lbs_failcount_write(struct file
*file
, const char __user
*userbuf
,
538 size_t count
, loff_t
*ppos
)
540 return lbs_threshold_write(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
541 file
, userbuf
, count
, ppos
);
545 static ssize_t
lbs_highrssi_read(struct file
*file
, char __user
*userbuf
,
546 size_t count
, loff_t
*ppos
)
548 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
549 file
, userbuf
, count
, ppos
);
553 static ssize_t
lbs_highrssi_write(struct file
*file
, const char __user
*userbuf
,
554 size_t count
, loff_t
*ppos
)
556 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
557 file
, userbuf
, count
, ppos
);
561 static ssize_t
lbs_highsnr_read(struct file
*file
, char __user
*userbuf
,
562 size_t count
, loff_t
*ppos
)
564 return lbs_threshold_read(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
565 file
, userbuf
, count
, ppos
);
569 static ssize_t
lbs_highsnr_write(struct file
*file
, const char __user
*userbuf
,
570 size_t count
, loff_t
*ppos
)
572 return lbs_threshold_write(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
573 file
, userbuf
, count
, ppos
);
576 static ssize_t
lbs_bcnmiss_read(struct file
*file
, char __user
*userbuf
,
577 size_t count
, loff_t
*ppos
)
579 return lbs_threshold_read(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
580 file
, userbuf
, count
, ppos
);
584 static ssize_t
lbs_bcnmiss_write(struct file
*file
, const char __user
*userbuf
,
585 size_t count
, loff_t
*ppos
)
587 return lbs_threshold_write(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
588 file
, userbuf
, count
, ppos
);
593 static ssize_t
lbs_rdmac_read(struct file
*file
, char __user
*userbuf
,
594 size_t count
, loff_t
*ppos
)
596 struct lbs_private
*priv
= file
->private_data
;
597 struct lbs_offset_value offval
;
600 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
601 char *buf
= (char *)addr
;
603 offval
.offset
= priv
->mac_offset
;
606 ret
= lbs_prepare_and_send_command(priv
,
607 CMD_MAC_REG_ACCESS
, 0,
608 CMD_OPTION_WAITFORRSP
, 0, &offval
);
610 pos
+= snprintf(buf
+pos
, len
-pos
, "MAC[0x%x] = 0x%08x\n",
611 priv
->mac_offset
, priv
->offsetvalue
.value
);
613 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
618 static ssize_t
lbs_rdmac_write(struct file
*file
,
619 const char __user
*userbuf
,
620 size_t count
, loff_t
*ppos
)
622 struct lbs_private
*priv
= file
->private_data
;
623 ssize_t res
, buf_size
;
624 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
625 char *buf
= (char *)addr
;
627 buf_size
= min(count
, len
- 1);
628 if (copy_from_user(buf
, userbuf
, buf_size
)) {
632 priv
->mac_offset
= simple_strtoul((char *)buf
, NULL
, 16);
639 static ssize_t
lbs_wrmac_write(struct file
*file
,
640 const char __user
*userbuf
,
641 size_t count
, loff_t
*ppos
)
644 struct lbs_private
*priv
= file
->private_data
;
645 ssize_t res
, buf_size
;
647 struct lbs_offset_value offval
;
648 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
649 char *buf
= (char *)addr
;
651 buf_size
= min(count
, len
- 1);
652 if (copy_from_user(buf
, userbuf
, buf_size
)) {
656 res
= sscanf(buf
, "%x %x", &offset
, &value
);
662 offval
.offset
= offset
;
663 offval
.value
= value
;
664 res
= lbs_prepare_and_send_command(priv
,
665 CMD_MAC_REG_ACCESS
, 1,
666 CMD_OPTION_WAITFORRSP
, 0, &offval
);
675 static ssize_t
lbs_rdbbp_read(struct file
*file
, char __user
*userbuf
,
676 size_t count
, loff_t
*ppos
)
678 struct lbs_private
*priv
= file
->private_data
;
679 struct lbs_offset_value offval
;
682 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
683 char *buf
= (char *)addr
;
685 offval
.offset
= priv
->bbp_offset
;
688 ret
= lbs_prepare_and_send_command(priv
,
689 CMD_BBP_REG_ACCESS
, 0,
690 CMD_OPTION_WAITFORRSP
, 0, &offval
);
692 pos
+= snprintf(buf
+pos
, len
-pos
, "BBP[0x%x] = 0x%08x\n",
693 priv
->bbp_offset
, priv
->offsetvalue
.value
);
695 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
701 static ssize_t
lbs_rdbbp_write(struct file
*file
,
702 const char __user
*userbuf
,
703 size_t count
, loff_t
*ppos
)
705 struct lbs_private
*priv
= file
->private_data
;
706 ssize_t res
, buf_size
;
707 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
708 char *buf
= (char *)addr
;
710 buf_size
= min(count
, len
- 1);
711 if (copy_from_user(buf
, userbuf
, buf_size
)) {
715 priv
->bbp_offset
= simple_strtoul((char *)buf
, NULL
, 16);
722 static ssize_t
lbs_wrbbp_write(struct file
*file
,
723 const char __user
*userbuf
,
724 size_t count
, loff_t
*ppos
)
727 struct lbs_private
*priv
= file
->private_data
;
728 ssize_t res
, buf_size
;
730 struct lbs_offset_value offval
;
731 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
732 char *buf
= (char *)addr
;
734 buf_size
= min(count
, len
- 1);
735 if (copy_from_user(buf
, userbuf
, buf_size
)) {
739 res
= sscanf(buf
, "%x %x", &offset
, &value
);
745 offval
.offset
= offset
;
746 offval
.value
= value
;
747 res
= lbs_prepare_and_send_command(priv
,
748 CMD_BBP_REG_ACCESS
, 1,
749 CMD_OPTION_WAITFORRSP
, 0, &offval
);
758 static ssize_t
lbs_rdrf_read(struct file
*file
, char __user
*userbuf
,
759 size_t count
, loff_t
*ppos
)
761 struct lbs_private
*priv
= file
->private_data
;
762 struct lbs_offset_value offval
;
765 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
766 char *buf
= (char *)addr
;
768 offval
.offset
= priv
->rf_offset
;
771 ret
= lbs_prepare_and_send_command(priv
,
772 CMD_RF_REG_ACCESS
, 0,
773 CMD_OPTION_WAITFORRSP
, 0, &offval
);
775 pos
+= snprintf(buf
+pos
, len
-pos
, "RF[0x%x] = 0x%08x\n",
776 priv
->rf_offset
, priv
->offsetvalue
.value
);
778 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
784 static ssize_t
lbs_rdrf_write(struct file
*file
,
785 const char __user
*userbuf
,
786 size_t count
, loff_t
*ppos
)
788 struct lbs_private
*priv
= file
->private_data
;
789 ssize_t res
, buf_size
;
790 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
791 char *buf
= (char *)addr
;
793 buf_size
= min(count
, len
- 1);
794 if (copy_from_user(buf
, userbuf
, buf_size
)) {
798 priv
->rf_offset
= simple_strtoul((char *)buf
, NULL
, 16);
805 static ssize_t
lbs_wrrf_write(struct file
*file
,
806 const char __user
*userbuf
,
807 size_t count
, loff_t
*ppos
)
810 struct lbs_private
*priv
= file
->private_data
;
811 ssize_t res
, buf_size
;
813 struct lbs_offset_value offval
;
814 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
815 char *buf
= (char *)addr
;
817 buf_size
= min(count
, len
- 1);
818 if (copy_from_user(buf
, userbuf
, buf_size
)) {
822 res
= sscanf(buf
, "%x %x", &offset
, &value
);
828 offval
.offset
= offset
;
829 offval
.value
= value
;
830 res
= lbs_prepare_and_send_command(priv
,
831 CMD_RF_REG_ACCESS
, 1,
832 CMD_OPTION_WAITFORRSP
, 0, &offval
);
841 #define FOPS(fread, fwrite) { \
842 .owner = THIS_MODULE, \
843 .open = open_file_generic, \
848 struct lbs_debugfs_files
{
851 struct file_operations fops
;
854 static struct lbs_debugfs_files debugfs_files
[] = {
855 { "info", 0444, FOPS(lbs_dev_info
, write_file_dummy
), },
856 { "getscantable", 0444, FOPS(lbs_getscantable
,
857 write_file_dummy
), },
858 { "sleepparams", 0644, FOPS(lbs_sleepparams_read
,
859 lbs_sleepparams_write
), },
860 { "extscan", 0600, FOPS(NULL
, lbs_extscan
), },
861 { "setuserscan", 0600, FOPS(NULL
, lbs_setuserscan
), },
864 static struct lbs_debugfs_files debugfs_events_files
[] = {
865 {"low_rssi", 0644, FOPS(lbs_lowrssi_read
,
866 lbs_lowrssi_write
), },
867 {"low_snr", 0644, FOPS(lbs_lowsnr_read
,
868 lbs_lowsnr_write
), },
869 {"failure_count", 0644, FOPS(lbs_failcount_read
,
870 lbs_failcount_write
), },
871 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read
,
872 lbs_bcnmiss_write
), },
873 {"high_rssi", 0644, FOPS(lbs_highrssi_read
,
874 lbs_highrssi_write
), },
875 {"high_snr", 0644, FOPS(lbs_highsnr_read
,
876 lbs_highsnr_write
), },
879 static struct lbs_debugfs_files debugfs_regs_files
[] = {
880 {"rdmac", 0644, FOPS(lbs_rdmac_read
, lbs_rdmac_write
), },
881 {"wrmac", 0600, FOPS(NULL
, lbs_wrmac_write
), },
882 {"rdbbp", 0644, FOPS(lbs_rdbbp_read
, lbs_rdbbp_write
), },
883 {"wrbbp", 0600, FOPS(NULL
, lbs_wrbbp_write
), },
884 {"rdrf", 0644, FOPS(lbs_rdrf_read
, lbs_rdrf_write
), },
885 {"wrrf", 0600, FOPS(NULL
, lbs_wrrf_write
), },
888 void lbs_debugfs_init(void)
891 lbs_dir
= debugfs_create_dir("lbs_wireless", NULL
);
896 void lbs_debugfs_remove(void)
899 debugfs_remove(lbs_dir
);
903 void lbs_debugfs_init_one(struct lbs_private
*priv
, struct net_device
*dev
)
906 struct lbs_debugfs_files
*files
;
910 priv
->debugfs_dir
= debugfs_create_dir(dev
->name
, lbs_dir
);
911 if (!priv
->debugfs_dir
)
914 for (i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++) {
915 files
= &debugfs_files
[i
];
916 priv
->debugfs_files
[i
] = debugfs_create_file(files
->name
,
923 priv
->events_dir
= debugfs_create_dir("subscribed_events", priv
->debugfs_dir
);
924 if (!priv
->events_dir
)
927 for (i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++) {
928 files
= &debugfs_events_files
[i
];
929 priv
->debugfs_events_files
[i
] = debugfs_create_file(files
->name
,
936 priv
->regs_dir
= debugfs_create_dir("registers", priv
->debugfs_dir
);
940 for (i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++) {
941 files
= &debugfs_regs_files
[i
];
942 priv
->debugfs_regs_files
[i
] = debugfs_create_file(files
->name
,
950 lbs_debug_init(priv
, dev
);
956 void lbs_debugfs_remove_one(struct lbs_private
*priv
)
960 for(i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++)
961 debugfs_remove(priv
->debugfs_regs_files
[i
]);
963 debugfs_remove(priv
->regs_dir
);
965 for(i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++)
966 debugfs_remove(priv
->debugfs_events_files
[i
]);
968 debugfs_remove(priv
->events_dir
);
970 debugfs_remove(priv
->debugfs_debug
);
972 for(i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++)
973 debugfs_remove(priv
->debugfs_files
[i
]);
974 debugfs_remove(priv
->debugfs_dir
);
983 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
984 #define item_addr(n) (offsetof(struct lbs_private, n))
993 /* To debug any member of struct lbs_private, simply add one line here.
995 static struct debug_data items
[] = {
996 {"intcounter", item_size(intcounter
), item_addr(intcounter
)},
997 {"psmode", item_size(psmode
), item_addr(psmode
)},
998 {"psstate", item_size(psstate
), item_addr(psstate
)},
1001 static int num_of_items
= ARRAY_SIZE(items
);
1004 * @brief proc read function
1006 * @param page pointer to buffer
1007 * @param s read data starting position
1009 * @param cnt counter
1010 * @param eof end of file flag
1011 * @param data data to output
1012 * @return number of output data
1014 static ssize_t
lbs_debugfs_read(struct file
*file
, char __user
*userbuf
,
1015 size_t count
, loff_t
*ppos
)
1022 struct debug_data
*d
;
1023 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1024 char *buf
= (char *)addr
;
1028 d
= (struct debug_data
*)file
->private_data
;
1030 for (i
= 0; i
< num_of_items
; i
++) {
1032 val
= *((u8
*) d
[i
].addr
);
1033 else if (d
[i
].size
== 2)
1034 val
= *((u16
*) d
[i
].addr
);
1035 else if (d
[i
].size
== 4)
1036 val
= *((u32
*) d
[i
].addr
);
1037 else if (d
[i
].size
== 8)
1038 val
= *((u64
*) d
[i
].addr
);
1040 pos
+= sprintf(p
+ pos
, "%s=%d\n", d
[i
].name
, val
);
1043 res
= simple_read_from_buffer(userbuf
, count
, ppos
, p
, pos
);
1050 * @brief proc write function
1052 * @param f file pointer
1053 * @param buf pointer to data buffer
1054 * @param cnt data number to write
1055 * @param data data to write
1056 * @return number of data
1058 static ssize_t
lbs_debugfs_write(struct file
*f
, const char __user
*buf
,
1059 size_t cnt
, loff_t
*ppos
)
1067 struct debug_data
*d
= (struct debug_data
*)f
->private_data
;
1069 pdata
= kmalloc(cnt
, GFP_KERNEL
);
1073 if (copy_from_user(pdata
, buf
, cnt
)) {
1074 lbs_deb_debugfs("Copy from user failed\n");
1080 for (i
= 0; i
< num_of_items
; i
++) {
1082 p
= strstr(p0
, d
[i
].name
);
1085 p1
= strchr(p
, '\n');
1089 p2
= strchr(p
, '=');
1093 r
= simple_strtoul(p2
, NULL
, 0);
1095 *((u8
*) d
[i
].addr
) = (u8
) r
;
1096 else if (d
[i
].size
== 2)
1097 *((u16
*) d
[i
].addr
) = (u16
) r
;
1098 else if (d
[i
].size
== 4)
1099 *((u32
*) d
[i
].addr
) = (u32
) r
;
1100 else if (d
[i
].size
== 8)
1101 *((u64
*) d
[i
].addr
) = (u64
) r
;
1107 return (ssize_t
)cnt
;
1110 static struct file_operations lbs_debug_fops
= {
1111 .owner
= THIS_MODULE
,
1112 .open
= open_file_generic
,
1113 .write
= lbs_debugfs_write
,
1114 .read
= lbs_debugfs_read
,
1118 * @brief create debug proc file
1120 * @param priv pointer struct lbs_private
1121 * @param dev pointer net_device
1124 static void lbs_debug_init(struct lbs_private
*priv
, struct net_device
*dev
)
1128 if (!priv
->debugfs_dir
)
1131 for (i
= 0; i
< num_of_items
; i
++)
1132 items
[i
].addr
+= (size_t) priv
;
1134 priv
->debugfs_debug
= debugfs_create_file("debug", 0644,
1135 priv
->debugfs_dir
, &items
[0],