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(u16 tlv_type
, const u8
*tlv
, u16 size
)
352 __le16 le_type
= cpu_to_le16(tlv_type
);
354 struct mrvlietypesheader
*tlv_h
;
357 tlv_h
= (struct mrvlietypesheader
*) tlv
;
358 if (tlv_h
->type
== le_type
)
362 length
= le16_to_cpu(tlv_h
->len
) +
363 sizeof(struct mrvlietypesheader
);
372 * This just gets the bitmap of currently subscribed events. Used when
373 * adding an additonal event subscription.
375 static u16
lbs_get_events_bitmap(struct lbs_private
*priv
)
379 struct cmd_ds_802_11_subscribe_event
*events
= kzalloc(
380 sizeof(struct cmd_ds_802_11_subscribe_event
),
383 res
= lbs_prepare_and_send_command(priv
,
384 CMD_802_11_SUBSCRIBE_EVENT
, CMD_ACT_GET
,
385 CMD_OPTION_WAITFORRSP
, 0, events
);
391 return le16_to_cpu(events
->events
);
395 static ssize_t
lbs_threshold_read(
396 u16 tlv_type
, u16 event_mask
,
397 struct file
*file
, char __user
*userbuf
,
398 size_t count
, loff_t
*ppos
)
400 struct lbs_private
*priv
= file
->private_data
;
403 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
404 char *buf
= (char *)addr
;
409 struct cmd_ds_802_11_subscribe_event
*subscribed
= kzalloc(
410 sizeof(struct cmd_ds_802_11_subscribe_event
),
412 struct mrvlietypes_thresholds
*got
;
414 res
= lbs_prepare_and_send_command(priv
,
415 CMD_802_11_SUBSCRIBE_EVENT
, CMD_ACT_GET
,
416 CMD_OPTION_WAITFORRSP
, 0, subscribed
);
422 got
= lbs_tlv_find(tlv_type
, subscribed
->tlv
, sizeof(subscribed
->tlv
));
426 events
= le16_to_cpu(subscribed
->events
);
431 pos
+= snprintf(buf
, len
, "%d %d %d\n", value
, freq
,
432 !!(events
& event_mask
));
434 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
441 static ssize_t
lbs_threshold_write(
442 u16 tlv_type
, u16 event_mask
,
444 const char __user
*userbuf
,
445 size_t count
, loff_t
*ppos
)
447 struct lbs_private
*priv
= file
->private_data
;
448 ssize_t res
, buf_size
;
449 int value
, freq
, curr_mask
, new_mask
;
450 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
451 char *buf
= (char *)addr
;
452 struct cmd_ds_802_11_subscribe_event
*events
;
454 buf_size
= min(count
, len
- 1);
455 if (copy_from_user(buf
, userbuf
, buf_size
)) {
459 res
= sscanf(buf
, "%d %d %d", &value
, &freq
, &new_mask
);
464 curr_mask
= lbs_get_events_bitmap(priv
);
467 new_mask
= curr_mask
| event_mask
;
469 new_mask
= curr_mask
& ~event_mask
;
471 /* Now everything is set and we can send stuff down to the firmware */
473 sizeof(struct cmd_ds_802_11_subscribe_event
),
476 struct mrvlietypes_thresholds
*tlv
=
477 (struct mrvlietypes_thresholds
*) events
->tlv
;
478 events
->action
= cpu_to_le16(CMD_ACT_SET
);
479 events
->events
= cpu_to_le16(new_mask
);
480 tlv
->header
.type
= cpu_to_le16(tlv_type
);
481 tlv
->header
.len
= cpu_to_le16(
482 sizeof(struct mrvlietypes_thresholds
) -
483 sizeof(struct mrvlietypesheader
));
485 if (tlv_type
!= TLV_TYPE_BCNMISS
)
487 lbs_prepare_and_send_command(priv
,
488 CMD_802_11_SUBSCRIBE_EVENT
, CMD_ACT_SET
,
489 CMD_OPTION_WAITFORRSP
, 0, events
);
500 static ssize_t
lbs_lowrssi_read(
501 struct file
*file
, char __user
*userbuf
,
502 size_t count
, loff_t
*ppos
)
504 return lbs_threshold_read(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
505 file
, userbuf
, count
, ppos
);
509 static ssize_t
lbs_lowrssi_write(
510 struct file
*file
, const char __user
*userbuf
,
511 size_t count
, loff_t
*ppos
)
513 return lbs_threshold_write(TLV_TYPE_RSSI_LOW
, CMD_SUBSCRIBE_RSSI_LOW
,
514 file
, userbuf
, count
, ppos
);
518 static ssize_t
lbs_lowsnr_read(
519 struct file
*file
, char __user
*userbuf
,
520 size_t count
, loff_t
*ppos
)
522 return lbs_threshold_read(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
523 file
, userbuf
, count
, ppos
);
527 static ssize_t
lbs_lowsnr_write(
528 struct file
*file
, const char __user
*userbuf
,
529 size_t count
, loff_t
*ppos
)
531 return lbs_threshold_write(TLV_TYPE_SNR_LOW
, CMD_SUBSCRIBE_SNR_LOW
,
532 file
, userbuf
, count
, ppos
);
536 static ssize_t
lbs_failcount_read(
537 struct file
*file
, char __user
*userbuf
,
538 size_t count
, loff_t
*ppos
)
540 return lbs_threshold_read(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
541 file
, userbuf
, count
, ppos
);
545 static ssize_t
lbs_failcount_write(
546 struct file
*file
, const char __user
*userbuf
,
547 size_t count
, loff_t
*ppos
)
549 return lbs_threshold_write(TLV_TYPE_FAILCOUNT
, CMD_SUBSCRIBE_FAILCOUNT
,
550 file
, userbuf
, count
, ppos
);
554 static ssize_t
lbs_highrssi_read(
555 struct file
*file
, char __user
*userbuf
,
556 size_t count
, loff_t
*ppos
)
558 return lbs_threshold_read(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
559 file
, userbuf
, count
, ppos
);
563 static ssize_t
lbs_highrssi_write(
564 struct file
*file
, const char __user
*userbuf
,
565 size_t count
, loff_t
*ppos
)
567 return lbs_threshold_write(TLV_TYPE_RSSI_HIGH
, CMD_SUBSCRIBE_RSSI_HIGH
,
568 file
, userbuf
, count
, ppos
);
572 static ssize_t
lbs_highsnr_read(
573 struct file
*file
, char __user
*userbuf
,
574 size_t count
, loff_t
*ppos
)
576 return lbs_threshold_read(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
577 file
, userbuf
, count
, ppos
);
581 static ssize_t
lbs_highsnr_write(
582 struct file
*file
, const char __user
*userbuf
,
583 size_t count
, loff_t
*ppos
)
585 return lbs_threshold_write(TLV_TYPE_SNR_HIGH
, CMD_SUBSCRIBE_SNR_HIGH
,
586 file
, userbuf
, count
, ppos
);
589 static ssize_t
lbs_bcnmiss_read(
590 struct file
*file
, char __user
*userbuf
,
591 size_t count
, loff_t
*ppos
)
593 return lbs_threshold_read(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
594 file
, userbuf
, count
, ppos
);
598 static ssize_t
lbs_bcnmiss_write(
599 struct file
*file
, const char __user
*userbuf
,
600 size_t count
, loff_t
*ppos
)
602 return lbs_threshold_write(TLV_TYPE_BCNMISS
, CMD_SUBSCRIBE_BCNMISS
,
603 file
, userbuf
, count
, ppos
);
613 static ssize_t
lbs_rdmac_read(struct file
*file
, char __user
*userbuf
,
614 size_t count
, loff_t
*ppos
)
616 struct lbs_private
*priv
= file
->private_data
;
617 struct lbs_offset_value offval
;
620 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
621 char *buf
= (char *)addr
;
623 offval
.offset
= priv
->mac_offset
;
626 ret
= lbs_prepare_and_send_command(priv
,
627 CMD_MAC_REG_ACCESS
, 0,
628 CMD_OPTION_WAITFORRSP
, 0, &offval
);
630 pos
+= snprintf(buf
+pos
, len
-pos
, "MAC[0x%x] = 0x%08x\n",
631 priv
->mac_offset
, priv
->offsetvalue
.value
);
633 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
638 static ssize_t
lbs_rdmac_write(struct file
*file
,
639 const char __user
*userbuf
,
640 size_t count
, loff_t
*ppos
)
642 struct lbs_private
*priv
= file
->private_data
;
643 ssize_t res
, buf_size
;
644 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
645 char *buf
= (char *)addr
;
647 buf_size
= min(count
, len
- 1);
648 if (copy_from_user(buf
, userbuf
, buf_size
)) {
652 priv
->mac_offset
= simple_strtoul((char *)buf
, NULL
, 16);
659 static ssize_t
lbs_wrmac_write(struct file
*file
,
660 const char __user
*userbuf
,
661 size_t count
, loff_t
*ppos
)
664 struct lbs_private
*priv
= file
->private_data
;
665 ssize_t res
, buf_size
;
667 struct lbs_offset_value offval
;
668 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
669 char *buf
= (char *)addr
;
671 buf_size
= min(count
, len
- 1);
672 if (copy_from_user(buf
, userbuf
, buf_size
)) {
676 res
= sscanf(buf
, "%x %x", &offset
, &value
);
682 offval
.offset
= offset
;
683 offval
.value
= value
;
684 res
= lbs_prepare_and_send_command(priv
,
685 CMD_MAC_REG_ACCESS
, 1,
686 CMD_OPTION_WAITFORRSP
, 0, &offval
);
695 static ssize_t
lbs_rdbbp_read(struct file
*file
, char __user
*userbuf
,
696 size_t count
, loff_t
*ppos
)
698 struct lbs_private
*priv
= file
->private_data
;
699 struct lbs_offset_value offval
;
702 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
703 char *buf
= (char *)addr
;
705 offval
.offset
= priv
->bbp_offset
;
708 ret
= lbs_prepare_and_send_command(priv
,
709 CMD_BBP_REG_ACCESS
, 0,
710 CMD_OPTION_WAITFORRSP
, 0, &offval
);
712 pos
+= snprintf(buf
+pos
, len
-pos
, "BBP[0x%x] = 0x%08x\n",
713 priv
->bbp_offset
, priv
->offsetvalue
.value
);
715 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
721 static ssize_t
lbs_rdbbp_write(struct file
*file
,
722 const char __user
*userbuf
,
723 size_t count
, loff_t
*ppos
)
725 struct lbs_private
*priv
= file
->private_data
;
726 ssize_t res
, buf_size
;
727 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
728 char *buf
= (char *)addr
;
730 buf_size
= min(count
, len
- 1);
731 if (copy_from_user(buf
, userbuf
, buf_size
)) {
735 priv
->bbp_offset
= simple_strtoul((char *)buf
, NULL
, 16);
742 static ssize_t
lbs_wrbbp_write(struct file
*file
,
743 const char __user
*userbuf
,
744 size_t count
, loff_t
*ppos
)
747 struct lbs_private
*priv
= file
->private_data
;
748 ssize_t res
, buf_size
;
750 struct lbs_offset_value offval
;
751 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
752 char *buf
= (char *)addr
;
754 buf_size
= min(count
, len
- 1);
755 if (copy_from_user(buf
, userbuf
, buf_size
)) {
759 res
= sscanf(buf
, "%x %x", &offset
, &value
);
765 offval
.offset
= offset
;
766 offval
.value
= value
;
767 res
= lbs_prepare_and_send_command(priv
,
768 CMD_BBP_REG_ACCESS
, 1,
769 CMD_OPTION_WAITFORRSP
, 0, &offval
);
778 static ssize_t
lbs_rdrf_read(struct file
*file
, char __user
*userbuf
,
779 size_t count
, loff_t
*ppos
)
781 struct lbs_private
*priv
= file
->private_data
;
782 struct lbs_offset_value offval
;
785 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
786 char *buf
= (char *)addr
;
788 offval
.offset
= priv
->rf_offset
;
791 ret
= lbs_prepare_and_send_command(priv
,
792 CMD_RF_REG_ACCESS
, 0,
793 CMD_OPTION_WAITFORRSP
, 0, &offval
);
795 pos
+= snprintf(buf
+pos
, len
-pos
, "RF[0x%x] = 0x%08x\n",
796 priv
->rf_offset
, priv
->offsetvalue
.value
);
798 ret
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
804 static ssize_t
lbs_rdrf_write(struct file
*file
,
805 const char __user
*userbuf
,
806 size_t count
, loff_t
*ppos
)
808 struct lbs_private
*priv
= file
->private_data
;
809 ssize_t res
, buf_size
;
810 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
811 char *buf
= (char *)addr
;
813 buf_size
= min(count
, len
- 1);
814 if (copy_from_user(buf
, userbuf
, buf_size
)) {
818 priv
->rf_offset
= simple_strtoul((char *)buf
, NULL
, 16);
825 static ssize_t
lbs_wrrf_write(struct file
*file
,
826 const char __user
*userbuf
,
827 size_t count
, loff_t
*ppos
)
830 struct lbs_private
*priv
= file
->private_data
;
831 ssize_t res
, buf_size
;
833 struct lbs_offset_value offval
;
834 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
835 char *buf
= (char *)addr
;
837 buf_size
= min(count
, len
- 1);
838 if (copy_from_user(buf
, userbuf
, buf_size
)) {
842 res
= sscanf(buf
, "%x %x", &offset
, &value
);
848 offval
.offset
= offset
;
849 offval
.value
= value
;
850 res
= lbs_prepare_and_send_command(priv
,
851 CMD_RF_REG_ACCESS
, 1,
852 CMD_OPTION_WAITFORRSP
, 0, &offval
);
861 #define FOPS(fread, fwrite) { \
862 .owner = THIS_MODULE, \
863 .open = open_file_generic, \
868 struct lbs_debugfs_files
{
871 struct file_operations fops
;
874 static struct lbs_debugfs_files debugfs_files
[] = {
875 { "info", 0444, FOPS(lbs_dev_info
, write_file_dummy
), },
876 { "getscantable", 0444, FOPS(lbs_getscantable
,
877 write_file_dummy
), },
878 { "sleepparams", 0644, FOPS(lbs_sleepparams_read
,
879 lbs_sleepparams_write
), },
880 { "extscan", 0600, FOPS(NULL
, lbs_extscan
), },
881 { "setuserscan", 0600, FOPS(NULL
, lbs_setuserscan
), },
884 static struct lbs_debugfs_files debugfs_events_files
[] = {
885 {"low_rssi", 0644, FOPS(lbs_lowrssi_read
,
886 lbs_lowrssi_write
), },
887 {"low_snr", 0644, FOPS(lbs_lowsnr_read
,
888 lbs_lowsnr_write
), },
889 {"failure_count", 0644, FOPS(lbs_failcount_read
,
890 lbs_failcount_write
), },
891 {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read
,
892 lbs_bcnmiss_write
), },
893 {"high_rssi", 0644, FOPS(lbs_highrssi_read
,
894 lbs_highrssi_write
), },
895 {"high_snr", 0644, FOPS(lbs_highsnr_read
,
896 lbs_highsnr_write
), },
899 static struct lbs_debugfs_files debugfs_regs_files
[] = {
900 {"rdmac", 0644, FOPS(lbs_rdmac_read
, lbs_rdmac_write
), },
901 {"wrmac", 0600, FOPS(NULL
, lbs_wrmac_write
), },
902 {"rdbbp", 0644, FOPS(lbs_rdbbp_read
, lbs_rdbbp_write
), },
903 {"wrbbp", 0600, FOPS(NULL
, lbs_wrbbp_write
), },
904 {"rdrf", 0644, FOPS(lbs_rdrf_read
, lbs_rdrf_write
), },
905 {"wrrf", 0600, FOPS(NULL
, lbs_wrrf_write
), },
908 void lbs_debugfs_init(void)
911 lbs_dir
= debugfs_create_dir("lbs_wireless", NULL
);
916 void lbs_debugfs_remove(void)
919 debugfs_remove(lbs_dir
);
923 void lbs_debugfs_init_one(struct lbs_private
*priv
, struct net_device
*dev
)
926 struct lbs_debugfs_files
*files
;
930 priv
->debugfs_dir
= debugfs_create_dir(dev
->name
, lbs_dir
);
931 if (!priv
->debugfs_dir
)
934 for (i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++) {
935 files
= &debugfs_files
[i
];
936 priv
->debugfs_files
[i
] = debugfs_create_file(files
->name
,
943 priv
->events_dir
= debugfs_create_dir("subscribed_events", priv
->debugfs_dir
);
944 if (!priv
->events_dir
)
947 for (i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++) {
948 files
= &debugfs_events_files
[i
];
949 priv
->debugfs_events_files
[i
] = debugfs_create_file(files
->name
,
956 priv
->regs_dir
= debugfs_create_dir("registers", priv
->debugfs_dir
);
960 for (i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++) {
961 files
= &debugfs_regs_files
[i
];
962 priv
->debugfs_regs_files
[i
] = debugfs_create_file(files
->name
,
970 lbs_debug_init(priv
, dev
);
976 void lbs_debugfs_remove_one(struct lbs_private
*priv
)
980 for(i
=0; i
<ARRAY_SIZE(debugfs_regs_files
); i
++)
981 debugfs_remove(priv
->debugfs_regs_files
[i
]);
983 debugfs_remove(priv
->regs_dir
);
985 for(i
=0; i
<ARRAY_SIZE(debugfs_events_files
); i
++)
986 debugfs_remove(priv
->debugfs_events_files
[i
]);
988 debugfs_remove(priv
->events_dir
);
990 debugfs_remove(priv
->debugfs_debug
);
992 for(i
=0; i
<ARRAY_SIZE(debugfs_files
); i
++)
993 debugfs_remove(priv
->debugfs_files
[i
]);
994 debugfs_remove(priv
->debugfs_dir
);
1003 #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
1004 #define item_addr(n) (offsetof(struct lbs_private, n))
1013 /* To debug any member of struct lbs_private, simply add one line here.
1015 static struct debug_data items
[] = {
1016 {"intcounter", item_size(intcounter
), item_addr(intcounter
)},
1017 {"psmode", item_size(psmode
), item_addr(psmode
)},
1018 {"psstate", item_size(psstate
), item_addr(psstate
)},
1021 static int num_of_items
= ARRAY_SIZE(items
);
1024 * @brief proc read function
1026 * @param page pointer to buffer
1027 * @param s read data starting position
1029 * @param cnt counter
1030 * @param eof end of file flag
1031 * @param data data to output
1032 * @return number of output data
1034 static ssize_t
lbs_debugfs_read(struct file
*file
, char __user
*userbuf
,
1035 size_t count
, loff_t
*ppos
)
1042 struct debug_data
*d
;
1043 unsigned long addr
= get_zeroed_page(GFP_KERNEL
);
1044 char *buf
= (char *)addr
;
1048 d
= (struct debug_data
*)file
->private_data
;
1050 for (i
= 0; i
< num_of_items
; i
++) {
1052 val
= *((u8
*) d
[i
].addr
);
1053 else if (d
[i
].size
== 2)
1054 val
= *((u16
*) d
[i
].addr
);
1055 else if (d
[i
].size
== 4)
1056 val
= *((u32
*) d
[i
].addr
);
1057 else if (d
[i
].size
== 8)
1058 val
= *((u64
*) d
[i
].addr
);
1060 pos
+= sprintf(p
+ pos
, "%s=%d\n", d
[i
].name
, val
);
1063 res
= simple_read_from_buffer(userbuf
, count
, ppos
, p
, pos
);
1070 * @brief proc write function
1072 * @param f file pointer
1073 * @param buf pointer to data buffer
1074 * @param cnt data number to write
1075 * @param data data to write
1076 * @return number of data
1078 static ssize_t
lbs_debugfs_write(struct file
*f
, const char __user
*buf
,
1079 size_t cnt
, loff_t
*ppos
)
1087 struct debug_data
*d
= (struct debug_data
*)f
->private_data
;
1089 pdata
= kmalloc(cnt
, GFP_KERNEL
);
1093 if (copy_from_user(pdata
, buf
, cnt
)) {
1094 lbs_deb_debugfs("Copy from user failed\n");
1100 for (i
= 0; i
< num_of_items
; i
++) {
1102 p
= strstr(p0
, d
[i
].name
);
1105 p1
= strchr(p
, '\n');
1109 p2
= strchr(p
, '=');
1113 r
= simple_strtoul(p2
, NULL
, 0);
1115 *((u8
*) d
[i
].addr
) = (u8
) r
;
1116 else if (d
[i
].size
== 2)
1117 *((u16
*) d
[i
].addr
) = (u16
) r
;
1118 else if (d
[i
].size
== 4)
1119 *((u32
*) d
[i
].addr
) = (u32
) r
;
1120 else if (d
[i
].size
== 8)
1121 *((u64
*) d
[i
].addr
) = (u64
) r
;
1127 return (ssize_t
)cnt
;
1130 static struct file_operations lbs_debug_fops
= {
1131 .owner
= THIS_MODULE
,
1132 .open
= open_file_generic
,
1133 .write
= lbs_debugfs_write
,
1134 .read
= lbs_debugfs_read
,
1138 * @brief create debug proc file
1140 * @param priv pointer struct lbs_private
1141 * @param dev pointer net_device
1144 static void lbs_debug_init(struct lbs_private
*priv
, struct net_device
*dev
)
1148 if (!priv
->debugfs_dir
)
1151 for (i
= 0; i
< num_of_items
; i
++)
1152 items
[i
].addr
+= (size_t) priv
;
1154 priv
->debugfs_debug
= debugfs_create_file("debug", 0644,
1155 priv
->debugfs_dir
, &items
[0],