From 3fcb34e087e75929e70c78cf539aeb9bebf1489c Mon Sep 17 00:00:00 2001 From: gwl Date: Fri, 26 Apr 2013 11:55:41 +0800 Subject: [PATCH] add new function of automatic identifi USB Wifi Type. --- drivers/net/wireless/Kconfig | 6 + .../net/wireless/wifi_sys/rkwifi_sys_iface.c | 111 +++++++++++++++++- 2 files changed, 115 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig index 703c3b7bd3d6..80035535f87f 100755 --- a/drivers/net/wireless/Kconfig +++ b/drivers/net/wireless/Kconfig @@ -26,6 +26,12 @@ config WLAN_80211 This option does not affect the kernel build, it only lets you choose drivers. +config AIDC + bool "Enable WIFI AIDS(Automatic Identification USB Wifi Type)" + depends on RTL8188EU || RTL8192CU || RTL8723AU || RT5370 + default n + ---help--- + choice prompt "WiFi device driver support" default WIFI_NONE diff --git a/drivers/net/wireless/wifi_sys/rkwifi_sys_iface.c b/drivers/net/wireless/wifi_sys/rkwifi_sys_iface.c index 52df660620d2..e3c9832fc847 100755 --- a/drivers/net/wireless/wifi_sys/rkwifi_sys_iface.c +++ b/drivers/net/wireless/wifi_sys/rkwifi_sys_iface.c @@ -1,11 +1,13 @@ - - #include #include #include #include #include +#include +#include +#include +#include #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) static ssize_t wifi_chip_read(struct class *cls, struct class_attribute *attr, char *_buf) @@ -189,10 +191,109 @@ static ssize_t wifi_pcba_write(struct class *cls, char *_buf, size_t _count) return _count; } +#ifdef CONFIG_AIDC +int check_wifi_type_from_id(int id, char * _buf) { + int count = 0; + + switch(id) { + case 0x8179: + count = sprintf(_buf, "%s", "RTL8188EU"); + printk("Current WiFi chip is RTL8188EU.\n"); + break; + case 0x0179: + count = sprintf(_buf, "%s", "RTL8188EU"); + printk("Current WiFi chip is RTL8188ETV.\n"); + break; + case 0x5370: + count = sprintf(_buf, "%s", "RT5370"); + printk("Current WiFi chip is RT5370.\n"); + break; + case 0x0724: + count = sprintf(_buf, "%s", "RTL8723AU"); + printk("Current WiFi chip is RTL8723AU.\n"); + break; + case 0x8176: + count = sprintf(_buf, "%s", "RTL8188CU"); + printk("Current WiFi chip is RTL8188CU.\n"); + break; + case 0x018A: + count = sprintf(_buf, "%s", "RTL8188CU"); + printk("Current WiFi chip is RTL8188CTV.\n"); + break; + default: + printk("Unsupported usb wifi.............\n"); + } + return count; +} + +extern int rk29sdk_wifi_power(int on); +extern int wifi_activate_usb(void); +extern int wifi_deactivate_usb(void); +#define USB_IDP_SYS_PATCH_1 "/sys/bus/usb/devices/1-1/idProduct" +#define USB_IDP_SYS_PATCH_2 "/sys/bus/usb/devices/2-1/idProduct" +#define USB_IDV_SYS_PATCH_1 "/sys/bus/usb/devices/1-1/idVendor" +#define USB_IDV_SYS_PATCH_2 "/sys/bus/usb/devices/2-1/idVendor" +#define USB_PRODUCT_SYS_PATCH "/sys/bus/usb/devices/1-1/product" +//5370 802.11 n WLAN +//8723 802.11n WLAN Adapter +//8188eu 802.11n NIC +//8188cu 802.11n WLAN Adapter +char aidc_type[20] = {0}; + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) +static ssize_t wifi_aidc_read(struct class *cls, struct class_attribute *attr, char *_buf) +#else +static ssize_t wifi_aidc_read(struct class *cls, char *_buf) +#endif +{ + int count = 0, retry = 10, idP = 0;// idV = 0; + ssize_t nread; + loff_t pos = 0; + char usbid[20] = {0}; + struct file *file = NULL; + mm_segment_t old_fs; + + sprintf(_buf, "%s", "UNKNOW"); + wifi_activate_usb(); + msleep(2000); + old_fs = get_fs(); + set_fs(KERNEL_DS); + while(retry--) { + file = filp_open(USB_IDP_SYS_PATCH_2, O_RDONLY, 0); + if (IS_ERR(file)) { + printk("\nCannot open \"%s\", retry = %d\n", USB_IDP_SYS_PATCH_2, retry); + file = filp_open(USB_IDP_SYS_PATCH_1, O_RDONLY, 0); + if (IS_ERR(file)) { + printk("\nCannot open \"%s\", retry = %d\n", USB_IDP_SYS_PATCH_1, retry); + msleep(500); + continue; + } + } + break; + } + if(retry <= 0) { + set_fs(old_fs); + return count; + } + nread = vfs_read(file, (char __user *)usbid, sizeof(usbid), &pos); + set_fs(old_fs); + filp_close(file, NULL); + wifi_deactivate_usb(); + idP = simple_strtol(usbid, NULL, 16); + printk("Get usb wifi idProduct = 0X%04X\n", idP); + count = check_wifi_type_from_id(idP, _buf); + + return count; +} +#endif //CONFIG_AIDC + static struct class *rkwifi_class = NULL; static CLASS_ATTR(chip, 0664, wifi_chip_read, NULL); static CLASS_ATTR(p2p, 0664, wifi_p2p_read, NULL); static CLASS_ATTR(pcba, 0664, wifi_pcba_read, wifi_pcba_write); +#ifdef CONFIG_AIDC +static CLASS_ATTR(aidc, 0664, wifi_aidc_read, NULL); +#endif int rkwifi_sysif_init(void) { @@ -212,6 +313,9 @@ int rkwifi_sysif_init(void) ret = class_create_file(rkwifi_class, &class_attr_chip); ret = class_create_file(rkwifi_class, &class_attr_p2p); ret = class_create_file(rkwifi_class, &class_attr_pcba); +#ifdef CONFIG_AIDC + ret = class_create_file(rkwifi_class, &class_attr_aidc); +#endif return 0; } @@ -222,6 +326,9 @@ void rkwifi_sysif_exit(void) class_remove_file(rkwifi_class, &class_attr_chip); class_remove_file(rkwifi_class, &class_attr_p2p); class_remove_file(rkwifi_class, &class_attr_pcba); +#ifdef CONFIG_AIDC + class_remove_file(rkwifi_class, &class_attr_aidc); +#endif class_destroy(rkwifi_class); rkwifi_class = NULL; -- 2.34.1