Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'staging-3.15-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging

Pull staging driver fixes from Greg KH:
"Here are a few staging driver fixes for issues that have been reported
for 3.15-rc2.

Also dominating the diffstat for the pull request is the removal of
the rtl8187se driver. It's no longer needed in staging as a "real"
driver for this hardware is now merged in the tree in the "correct"
location in drivers/net/

All of these patches have been tested in linux-next"

* tag 'staging-3.15-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging:
staging: r8188eu: Fix case where ethtype was never obtained and always be checked against 0
staging: r8712u: Fix case where ethtype was never obtained and always be checked against 0
staging: r8188eu: Calling rtw_get_stainfo() with a NULL sta_addr will return NULL
staging: comedi: fix circular locking dependency in comedi_mmap()
staging: r8723au: Add missing initialization of change_inx in sort algorithm
Staging: unisys: use after free in list_for_each()
staging: unisys: use after free in error messages
staging: speakup: fix misuse of kstrtol() in handle_goto()
staging: goldfish: Call free_irq in error path
staging: delete rtl8187se wireless driver
staging: rtl8723au: Fix buffer overflow in rtw_get_wfd_ie()
staging: gs_fpgaboot: remove __TIMESTAMP__ macro
staging: vme: fix memory leak in vme_user_probe()
staging: fpgaboot: clean up Makefile
staging/usbip: fix store_attach() sscanf return value check
staging/usbip: userspace - fix usbipd SIGSEGV from refresh_exported_devices()
staging: rtl8188eu: remove spaces, correct counts to unbreak P2P ioctls
staging/rtl8821ae: Fix OOM handling in _rtl_init_deferred_work()

+154 -19978
-2
drivers/staging/Kconfig
··· 40 40 41 41 source "drivers/staging/panel/Kconfig" 42 42 43 - source "drivers/staging/rtl8187se/Kconfig" 44 - 45 43 source "drivers/staging/rtl8192u/Kconfig" 46 44 47 45 source "drivers/staging/rtl8192e/Kconfig"
-1
drivers/staging/Makefile
··· 12 12 obj-$(CONFIG_COMEDI) += comedi/ 13 13 obj-$(CONFIG_FB_OLPC_DCON) += olpc_dcon/ 14 14 obj-$(CONFIG_PANEL) += panel/ 15 - obj-$(CONFIG_R8187SE) += rtl8187se/ 16 15 obj-$(CONFIG_RTL8192U) += rtl8192u/ 17 16 obj-$(CONFIG_RTL8192E) += rtl8192e/ 18 17 obj-$(CONFIG_R8712U) += rtl8712/
+35 -2
drivers/staging/comedi/comedi_buf.c
··· 61 61 struct comedi_subdevice *s) 62 62 { 63 63 struct comedi_async *async = s->async; 64 + struct comedi_buf_map *bm; 65 + unsigned long flags; 64 66 65 67 if (async->prealloc_buf) { 66 68 vunmap(async->prealloc_buf); ··· 70 68 async->prealloc_bufsz = 0; 71 69 } 72 70 73 - comedi_buf_map_put(async->buf_map); 71 + spin_lock_irqsave(&s->spin_lock, flags); 72 + bm = async->buf_map; 74 73 async->buf_map = NULL; 74 + spin_unlock_irqrestore(&s->spin_lock, flags); 75 + comedi_buf_map_put(bm); 75 76 } 76 77 77 78 static void __comedi_buf_alloc(struct comedi_device *dev, ··· 85 80 struct page **pages = NULL; 86 81 struct comedi_buf_map *bm; 87 82 struct comedi_buf_page *buf; 83 + unsigned long flags; 88 84 unsigned i; 89 85 90 86 if (!IS_ENABLED(CONFIG_HAS_DMA) && s->async_dma_dir != DMA_NONE) { ··· 98 92 if (!bm) 99 93 return; 100 94 101 - async->buf_map = bm; 102 95 kref_init(&bm->refcount); 96 + spin_lock_irqsave(&s->spin_lock, flags); 97 + async->buf_map = bm; 98 + spin_unlock_irqrestore(&s->spin_lock, flags); 103 99 bm->dma_dir = s->async_dma_dir; 104 100 if (bm->dma_dir != DMA_NONE) 105 101 /* Need ref to hardware device to free buffer later. */ ··· 135 127 136 128 pages[i] = virt_to_page(buf->virt_addr); 137 129 } 130 + spin_lock_irqsave(&s->spin_lock, flags); 138 131 bm->n_pages = i; 132 + spin_unlock_irqrestore(&s->spin_lock, flags); 139 133 140 134 /* vmap the prealloc_buf if all the pages were allocated */ 141 135 if (i == n_pages) ··· 158 148 if (bm) 159 149 return kref_put(&bm->refcount, comedi_buf_map_kref_release); 160 150 return 1; 151 + } 152 + 153 + /* returns s->async->buf_map and increments its kref refcount */ 154 + struct comedi_buf_map * 155 + comedi_buf_map_from_subdev_get(struct comedi_subdevice *s) 156 + { 157 + struct comedi_async *async = s->async; 158 + struct comedi_buf_map *bm = NULL; 159 + unsigned long flags; 160 + 161 + if (!async) 162 + return NULL; 163 + 164 + spin_lock_irqsave(&s->spin_lock, flags); 165 + bm = async->buf_map; 166 + /* only want it if buffer pages allocated */ 167 + if (bm && bm->n_pages) 168 + comedi_buf_map_get(bm); 169 + else 170 + bm = NULL; 171 + spin_unlock_irqrestore(&s->spin_lock, flags); 172 + 173 + return bm; 161 174 } 162 175 163 176 bool comedi_buf_is_mmapped(struct comedi_async *async)
+14 -4
drivers/staging/comedi/comedi_fops.c
··· 1926 1926 struct comedi_device *dev = file->private_data; 1927 1927 struct comedi_subdevice *s; 1928 1928 struct comedi_async *async; 1929 - struct comedi_buf_map *bm; 1929 + struct comedi_buf_map *bm = NULL; 1930 1930 unsigned long start = vma->vm_start; 1931 1931 unsigned long size; 1932 1932 int n_pages; 1933 1933 int i; 1934 1934 int retval; 1935 1935 1936 - mutex_lock(&dev->mutex); 1936 + /* 1937 + * 'trylock' avoids circular dependency with current->mm->mmap_sem 1938 + * and down-reading &dev->attach_lock should normally succeed without 1939 + * contention unless the device is in the process of being attached 1940 + * or detached. 1941 + */ 1942 + if (!down_read_trylock(&dev->attach_lock)) 1943 + return -EAGAIN; 1937 1944 1938 1945 if (!dev->attached) { 1939 1946 dev_dbg(dev->class_dev, "no driver attached\n"); ··· 1980 1973 } 1981 1974 1982 1975 n_pages = size >> PAGE_SHIFT; 1983 - bm = async->buf_map; 1976 + 1977 + /* get reference to current buf map (if any) */ 1978 + bm = comedi_buf_map_from_subdev_get(s); 1984 1979 if (!bm || n_pages > bm->n_pages) { 1985 1980 retval = -EINVAL; 1986 1981 goto done; ··· 2006 1997 2007 1998 retval = 0; 2008 1999 done: 2009 - mutex_unlock(&dev->mutex); 2000 + up_read(&dev->attach_lock); 2001 + comedi_buf_map_put(bm); /* put reference to buf map - okay if NULL */ 2010 2002 return retval; 2011 2003 } 2012 2004
+2
drivers/staging/comedi/comedi_internal.h
··· 19 19 bool comedi_buf_is_mmapped(struct comedi_async *async); 20 20 void comedi_buf_map_get(struct comedi_buf_map *bm); 21 21 int comedi_buf_map_put(struct comedi_buf_map *bm); 22 + struct comedi_buf_map *comedi_buf_map_from_subdev_get( 23 + struct comedi_subdevice *s); 22 24 unsigned int comedi_buf_write_n_allocated(struct comedi_async *async); 23 25 void comedi_device_cancel_all(struct comedi_device *dev); 24 26
+1
drivers/staging/goldfish/goldfish_audio.c
··· 334 334 return 0; 335 335 336 336 err_misc_register_failed: 337 + free_irq(data->irq, data); 337 338 err_request_irq_failed: 338 339 dma_free_coherent(&pdev->dev, COMBINED_BUFFER_SIZE, 339 340 data->buffer_virt, data->buffer_phys);
-2
drivers/staging/gs_fpgaboot/Makefile
··· 1 1 gs_fpga-y += gs_fpgaboot.o io.o 2 2 obj-$(CONFIG_GS_FPGABOOT) += gs_fpga.o 3 - 4 - ccflags-$(CONFIG_GS_FPGA_DEBUG) := -DDEBUG
-1
drivers/staging/gs_fpgaboot/gs_fpgaboot.c
··· 373 373 r = -1; 374 374 375 375 pr_info("FPGA DOWNLOAD --->\n"); 376 - pr_info("built at %s UTC\n", __TIMESTAMP__); 377 376 378 377 pr_info("FPGA image file name: %s\n", file); 379 378
-10
drivers/staging/rtl8187se/Kconfig
··· 1 - config R8187SE 2 - tristate "RealTek RTL8187SE Wireless LAN NIC driver" 3 - depends on PCI && WLAN 4 - depends on m 5 - select WIRELESS_EXT 6 - select WEXT_PRIV 7 - select EEPROM_93CX6 8 - select CRYPTO 9 - ---help--- 10 - If built as a module, it will be called r8187se.ko.
-38
drivers/staging/rtl8187se/Makefile
··· 1 - 2 - #ccflags-y += -DCONFIG_IEEE80211_NOWEP=y 3 - #ccflags-y += -std=gnu89 4 - #ccflags-y += -O2 5 - #CC = gcc 6 - 7 - ccflags-y := -DSW_ANTE 8 - ccflags-y += -DTX_TRACK 9 - ccflags-y += -DHIGH_POWER 10 - ccflags-y += -DSW_DIG 11 - ccflags-y += -DRATE_ADAPT 12 - 13 - #enable it for legacy power save, disable it for leisure power save 14 - ccflags-y += -DENABLE_LPS 15 - 16 - 17 - #ccflags-y := -mhard-float -DCONFIG_FORCE_HARD_FLOAT=y 18 - 19 - r8187se-y := \ 20 - r8180_core.o \ 21 - r8180_wx.o \ 22 - r8180_rtl8225z2.o \ 23 - r8185b_init.o \ 24 - r8180_dm.o \ 25 - ieee80211/dot11d.o \ 26 - ieee80211/ieee80211_softmac.o \ 27 - ieee80211/ieee80211_rx.o \ 28 - ieee80211/ieee80211_tx.o \ 29 - ieee80211/ieee80211_wx.o \ 30 - ieee80211/ieee80211_module.o \ 31 - ieee80211/ieee80211_softmac_wx.o \ 32 - ieee80211/ieee80211_crypt.o \ 33 - ieee80211/ieee80211_crypt_tkip.o \ 34 - ieee80211/ieee80211_crypt_ccmp.o \ 35 - ieee80211/ieee80211_crypt_wep.o 36 - 37 - obj-$(CONFIG_R8187SE) += r8187se.o 38 -
drivers/staging/rtl8187se/Module.symvers
-13
drivers/staging/rtl8187se/TODO
··· 1 - TODO: 2 - - prepare private ieee80211 stack for merge with rtl8192su's version: 3 - - add hwsec_active flag to struct ieee80211_device 4 - - add bHwSec flag to cb_desc structure 5 - - switch to use shared "librtl" instead of private ieee80211 stack 6 - - switch to use LIB80211 7 - - switch to use MAC80211 8 - - use kernel coding style 9 - - checkpatch.pl fixes 10 - - sparse fixes 11 - - integrate with drivers/net/wireless/rtl818x 12 - 13 - Please send any patches to Greg Kroah-Hartman <greg@kroah.com>.
-189
drivers/staging/rtl8187se/ieee80211/dot11d.c
··· 1 - #include "dot11d.h" 2 - 3 - void Dot11d_Init(struct ieee80211_device *ieee) 4 - { 5 - PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(ieee); 6 - 7 - pDot11dInfo->bEnabled = 0; 8 - 9 - pDot11dInfo->State = DOT11D_STATE_NONE; 10 - pDot11dInfo->CountryIeLen = 0; 11 - memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1); 12 - memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1); 13 - RESET_CIE_WATCHDOG(ieee); 14 - 15 - netdev_info(ieee->dev, "Dot11d_Init()\n"); 16 - } 17 - 18 - /* Reset to the state as we are just entering a regulatory domain. */ 19 - void Dot11d_Reset(struct ieee80211_device *ieee) 20 - { 21 - u32 i; 22 - PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(ieee); 23 - 24 - /* Clear old channel map */ 25 - memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1); 26 - memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1); 27 - /* Set new channel map */ 28 - for (i = 1; i <= 11; i++) 29 - (pDot11dInfo->channel_map)[i] = 1; 30 - 31 - for (i = 12; i <= 14; i++) 32 - (pDot11dInfo->channel_map)[i] = 2; 33 - 34 - pDot11dInfo->State = DOT11D_STATE_NONE; 35 - pDot11dInfo->CountryIeLen = 0; 36 - RESET_CIE_WATCHDOG(ieee); 37 - } 38 - 39 - /* 40 - * Description: 41 - * Update country IE from Beacon or Probe Response and configure PHY for 42 - * operation in the regulatory domain. 43 - * 44 - * TODO: 45 - * Configure Tx power. 46 - * 47 - * Assumption: 48 - * 1. IS_DOT11D_ENABLE() is TRUE. 49 - * 2. Input IE is an valid one. 50 - */ 51 - void Dot11d_UpdateCountryIe(struct ieee80211_device *dev, u8 *pTaddr, 52 - u16 CoutryIeLen, u8 *pCoutryIe) 53 - { 54 - PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); 55 - u8 i, j, NumTriples, MaxChnlNum; 56 - u8 index, MaxTxPowerInDbm; 57 - PCHNL_TXPOWER_TRIPLE pTriple; 58 - 59 - if ((CoutryIeLen - 3)%3 != 0) { 60 - netdev_info(dev->dev, "Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n"); 61 - Dot11d_Reset(dev); 62 - return; 63 - } 64 - 65 - memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1); 66 - memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1); 67 - MaxChnlNum = 0; 68 - NumTriples = (CoutryIeLen - 3) / 3; /* skip 3-byte country string. */ 69 - pTriple = (PCHNL_TXPOWER_TRIPLE)(pCoutryIe + 3); 70 - for (i = 0; i < NumTriples; i++) { 71 - if (MaxChnlNum >= pTriple->FirstChnl) { 72 - /* 73 - * It is not in a monotonically increasing order, 74 - * so stop processing. 75 - */ 76 - netdev_info(dev->dev, 77 - "Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n"); 78 - Dot11d_Reset(dev); 79 - return; 80 - } 81 - if (MAX_CHANNEL_NUMBER < 82 - (pTriple->FirstChnl + pTriple->NumChnls)) { 83 - /* 84 - * It is not a valid set of channel id, 85 - * so stop processing 86 - */ 87 - netdev_info(dev->dev, 88 - "Dot11d_UpdateCountryIe(): Invalid country IE, skip it........2\n"); 89 - Dot11d_Reset(dev); 90 - return; 91 - } 92 - 93 - for (j = 0; j < pTriple->NumChnls; j++) { 94 - index = pTriple->FirstChnl + j; 95 - pDot11dInfo->channel_map[index] = 1; 96 - MaxTxPowerInDbm = pTriple->MaxTxPowerInDbm; 97 - pDot11dInfo->MaxTxPwrDbmList[index] = MaxTxPowerInDbm; 98 - MaxChnlNum = pTriple->FirstChnl + j; 99 - } 100 - 101 - pTriple = (PCHNL_TXPOWER_TRIPLE)((u8 *)pTriple + 3); 102 - } 103 - #if 1 104 - netdev_info(dev->dev, "Channel List:"); 105 - for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) 106 - if (pDot11dInfo->channel_map[i] > 0) 107 - netdev_info(dev->dev, " %d", i); 108 - netdev_info(dev->dev, "\n"); 109 - #endif 110 - 111 - UPDATE_CIE_SRC(dev, pTaddr); 112 - 113 - pDot11dInfo->CountryIeLen = CoutryIeLen; 114 - memcpy(pDot11dInfo->CountryIeBuf, pCoutryIe, CoutryIeLen); 115 - pDot11dInfo->State = DOT11D_STATE_LEARNED; 116 - } 117 - 118 - u8 DOT11D_GetMaxTxPwrInDbm(struct ieee80211_device *dev, u8 Channel) 119 - { 120 - PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); 121 - u8 MaxTxPwrInDbm = 255; 122 - 123 - if (MAX_CHANNEL_NUMBER < Channel) { 124 - netdev_info(dev->dev, "DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n"); 125 - return MaxTxPwrInDbm; 126 - } 127 - if (pDot11dInfo->channel_map[Channel]) 128 - MaxTxPwrInDbm = pDot11dInfo->MaxTxPwrDbmList[Channel]; 129 - 130 - return MaxTxPwrInDbm; 131 - } 132 - 133 - 134 - void DOT11D_ScanComplete(struct ieee80211_device *dev) 135 - { 136 - PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); 137 - 138 - switch (pDot11dInfo->State) { 139 - case DOT11D_STATE_LEARNED: 140 - pDot11dInfo->State = DOT11D_STATE_DONE; 141 - break; 142 - 143 - case DOT11D_STATE_DONE: 144 - if (GET_CIE_WATCHDOG(dev) == 0) { 145 - /* Reset country IE if previous one is gone. */ 146 - Dot11d_Reset(dev); 147 - } 148 - break; 149 - case DOT11D_STATE_NONE: 150 - break; 151 - } 152 - } 153 - 154 - int IsLegalChannel(struct ieee80211_device *dev, u8 channel) 155 - { 156 - PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); 157 - 158 - if (MAX_CHANNEL_NUMBER < channel) { 159 - netdev_info(dev->dev, "IsLegalChannel(): Invalid Channel\n"); 160 - return 0; 161 - } 162 - if (pDot11dInfo->channel_map[channel] > 0) 163 - return 1; 164 - return 0; 165 - } 166 - 167 - int ToLegalChannel(struct ieee80211_device *dev, u8 channel) 168 - { 169 - PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); 170 - u8 default_chn = 0; 171 - u32 i = 0; 172 - 173 - for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) { 174 - if (pDot11dInfo->channel_map[i] > 0) { 175 - default_chn = i; 176 - break; 177 - } 178 - } 179 - 180 - if (MAX_CHANNEL_NUMBER < channel) { 181 - netdev_info(dev->dev, "IsLegalChannel(): Invalid Channel\n"); 182 - return default_chn; 183 - } 184 - 185 - if (pDot11dInfo->channel_map[channel] > 0) 186 - return channel; 187 - 188 - return default_chn; 189 - }
-71
drivers/staging/rtl8187se/ieee80211/dot11d.h
··· 1 - #ifndef __INC_DOT11D_H 2 - #define __INC_DOT11D_H 3 - 4 - #include "ieee80211.h" 5 - 6 - /* #define ENABLE_DOT11D */ 7 - 8 - /* #define DOT11D_MAX_CHNL_NUM 83 */ 9 - 10 - typedef struct _CHNL_TXPOWER_TRIPLE { 11 - u8 FirstChnl; 12 - u8 NumChnls; 13 - u8 MaxTxPowerInDbm; 14 - } CHNL_TXPOWER_TRIPLE, *PCHNL_TXPOWER_TRIPLE; 15 - 16 - typedef enum _DOT11D_STATE { 17 - DOT11D_STATE_NONE = 0, 18 - DOT11D_STATE_LEARNED, 19 - DOT11D_STATE_DONE, 20 - } DOT11D_STATE; 21 - 22 - typedef struct _RT_DOT11D_INFO { 23 - /* DECLARE_RT_OBJECT(RT_DOT12D_INFO); */ 24 - 25 - bool bEnabled; /* dot11MultiDomainCapabilityEnabled */ 26 - 27 - u16 CountryIeLen; /* > 0 if CountryIeBuf[] contains valid country information element. */ 28 - u8 CountryIeBuf[MAX_IE_LEN]; 29 - u8 CountryIeSrcAddr[6]; /* Source AP of the country IE. */ 30 - u8 CountryIeWatchdog; 31 - 32 - u8 channel_map[MAX_CHANNEL_NUMBER+1]; /* !!!Value 0: Invalid, 1: Valid (active scan), 2: Valid (passive scan) */ 33 - /* u8 ChnlListLen; // #Bytes valid in ChnlList[]. */ 34 - /* u8 ChnlList[DOT11D_MAX_CHNL_NUM]; */ 35 - u8 MaxTxPwrDbmList[MAX_CHANNEL_NUMBER+1]; 36 - 37 - DOT11D_STATE State; 38 - } RT_DOT11D_INFO, *PRT_DOT11D_INFO; 39 - 40 - #define eqMacAddr(a, b) (((a)[0] == (b)[0] && (a)[1] == (b)[1] && (a)[2] == (b)[2] && (a)[3] == (b)[3] && (a)[4] == (b)[4] && (a)[5] == (b)[5]) ? 1:0) 41 - #define cpMacAddr(des, src) ((des)[0] = (src)[0], (des)[1] = (src)[1], (des)[2] = (src)[2], (des)[3] = (src)[3], (des)[4] = (src)[4], (des)[5] = (src)[5]) 42 - #define GET_DOT11D_INFO(__pIeeeDev) ((PRT_DOT11D_INFO)((__pIeeeDev)->pDot11dInfo)) 43 - 44 - #define IS_DOT11D_ENABLE(__pIeeeDev) GET_DOT11D_INFO(__pIeeeDev)->bEnabled 45 - #define IS_COUNTRY_IE_VALID(__pIeeeDev) (GET_DOT11D_INFO(__pIeeeDev)->CountryIeLen > 0) 46 - 47 - #define IS_EQUAL_CIE_SRC(__pIeeeDev, __pTa) eqMacAddr(GET_DOT11D_INFO(__pIeeeDev)->CountryIeSrcAddr, __pTa) 48 - #define UPDATE_CIE_SRC(__pIeeeDev, __pTa) cpMacAddr(GET_DOT11D_INFO(__pIeeeDev)->CountryIeSrcAddr, __pTa) 49 - 50 - #define IS_COUNTRY_IE_CHANGED(__pIeeeDev, __Ie) \ 51 - (((__Ie).Length == 0 || (__Ie).Length != GET_DOT11D_INFO(__pIeeeDev)->CountryIeLen) ? \ 52 - FALSE : \ 53 - (!memcmp(GET_DOT11D_INFO(__pIeeeDev)->CountryIeBuf, (__Ie).Octet, (__Ie).Length))) 54 - 55 - #define CIE_WATCHDOG_TH 1 56 - #define GET_CIE_WATCHDOG(__pIeeeDev) GET_DOT11D_INFO(__pIeeeDev)->CountryIeWatchdog 57 - #define RESET_CIE_WATCHDOG(__pIeeeDev) GET_CIE_WATCHDOG(__pIeeeDev) = 0 58 - #define UPDATE_CIE_WATCHDOG(__pIeeeDev) ++GET_CIE_WATCHDOG(__pIeeeDev) 59 - 60 - #define IS_DOT11D_STATE_DONE(__pIeeeDev) (GET_DOT11D_INFO(__pIeeeDev)->State == DOT11D_STATE_DONE) 61 - 62 - void Dot11d_Init(struct ieee80211_device *dev); 63 - void Dot11d_Reset(struct ieee80211_device *dev); 64 - void Dot11d_UpdateCountryIe(struct ieee80211_device *dev, u8 *pTaddr, 65 - u16 CoutryIeLen, u8 *pCoutryIe); 66 - u8 DOT11D_GetMaxTxPwrInDbm(struct ieee80211_device *dev, u8 Channel); 67 - void DOT11D_ScanComplete(struct ieee80211_device *dev); 68 - int IsLegalChannel(struct ieee80211_device *dev, u8 channel); 69 - int ToLegalChannel(struct ieee80211_device *dev, u8 channel); 70 - 71 - #endif /* #ifndef __INC_DOT11D_H */
-1496
drivers/staging/rtl8187se/ieee80211/ieee80211.h
··· 1 - /* 2 - * Merged with mainline ieee80211.h in Aug 2004. Original ieee802_11 3 - * remains copyright by the original authors 4 - * 5 - * Portions of the merged code are based on Host AP (software wireless 6 - * LAN access point) driver for Intersil Prism2/2.5/3. 7 - * 8 - * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen 9 - * <jkmaline@cc.hut.fi> 10 - * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> 11 - * 12 - * Adaption to a generic IEEE 802.11 stack by James Ketrenos 13 - * <jketreno@linux.intel.com> 14 - * Copyright (c) 2004, Intel Corporation 15 - * 16 - * Modified for Realtek's wi-fi cards by Andrea Merello 17 - * <andrea.merello@gmail.com> 18 - * 19 - * This program is free software; you can redistribute it and/or modify 20 - * it under the terms of the GNU General Public License version 2 as 21 - * published by the Free Software Foundation. See README and COPYING for 22 - * more details. 23 - */ 24 - #ifndef IEEE80211_H 25 - #define IEEE80211_H 26 - #include <linux/if_ether.h> /* ETH_ALEN */ 27 - #include <linux/kernel.h> /* ARRAY_SIZE */ 28 - #include <linux/jiffies.h> 29 - #include <linux/timer.h> 30 - #include <linux/sched.h> 31 - #include <linux/semaphore.h> 32 - #include <linux/wireless.h> 33 - #include <linux/ieee80211.h> 34 - #include <linux/interrupt.h> 35 - 36 - #define KEY_TYPE_NA 0x0 37 - #define KEY_TYPE_WEP40 0x1 38 - #define KEY_TYPE_TKIP 0x2 39 - #define KEY_TYPE_CCMP 0x4 40 - #define KEY_TYPE_WEP104 0x5 41 - 42 - #define aSifsTime 10 43 - 44 - #define MGMT_QUEUE_NUM 5 45 - 46 - 47 - #define IEEE_CMD_SET_WPA_PARAM 1 48 - #define IEEE_CMD_SET_WPA_IE 2 49 - #define IEEE_CMD_SET_ENCRYPTION 3 50 - #define IEEE_CMD_MLME 4 51 - 52 - #define IEEE_PARAM_WPA_ENABLED 1 53 - #define IEEE_PARAM_TKIP_COUNTERMEASURES 2 54 - #define IEEE_PARAM_DROP_UNENCRYPTED 3 55 - #define IEEE_PARAM_PRIVACY_INVOKED 4 56 - #define IEEE_PARAM_AUTH_ALGS 5 57 - #define IEEE_PARAM_IEEE_802_1X 6 58 - //It should consistent with the driver_XXX.c 59 - // David, 2006.9.26 60 - #define IEEE_PARAM_WPAX_SELECT 7 61 - //Added for notify the encryption type selection 62 - // David, 2006.9.26 63 - #define IEEE_PROTO_WPA 1 64 - #define IEEE_PROTO_RSN 2 65 - //Added for notify the encryption type selection 66 - // David, 2006.9.26 67 - #define IEEE_WPAX_USEGROUP 0 68 - #define IEEE_WPAX_WEP40 1 69 - #define IEEE_WPAX_TKIP 2 70 - #define IEEE_WPAX_WRAP 3 71 - #define IEEE_WPAX_CCMP 4 72 - #define IEEE_WPAX_WEP104 5 73 - 74 - #define IEEE_KEY_MGMT_IEEE8021X 1 75 - #define IEEE_KEY_MGMT_PSK 2 76 - 77 - 78 - 79 - #define IEEE_MLME_STA_DEAUTH 1 80 - #define IEEE_MLME_STA_DISASSOC 2 81 - 82 - 83 - #define IEEE_CRYPT_ERR_UNKNOWN_ALG 2 84 - #define IEEE_CRYPT_ERR_UNKNOWN_ADDR 3 85 - #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED 4 86 - #define IEEE_CRYPT_ERR_KEY_SET_FAILED 5 87 - #define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED 6 88 - #define IEEE_CRYPT_ERR_CARD_CONF_FAILED 7 89 - 90 - 91 - #define IEEE_CRYPT_ALG_NAME_LEN 16 92 - 93 - extern int ieee80211_crypto_tkip_init(void); 94 - extern void ieee80211_crypto_tkip_exit(void); 95 - 96 - //by amy for ps 97 - typedef struct ieee_param { 98 - u32 cmd; 99 - u8 sta_addr[ETH_ALEN]; 100 - union { 101 - struct { 102 - u8 name; 103 - u32 value; 104 - } wpa_param; 105 - struct { 106 - u32 len; 107 - u8 reserved[32]; 108 - u8 data[0]; 109 - } wpa_ie; 110 - struct{ 111 - int command; 112 - int reason_code; 113 - } mlme; 114 - struct { 115 - u8 alg[IEEE_CRYPT_ALG_NAME_LEN]; 116 - u8 set_tx; 117 - u32 err; 118 - u8 idx; 119 - u8 seq[8]; /* sequence counter (set: RX, get: TX) */ 120 - u16 key_len; 121 - u8 key[0]; 122 - } crypt; 123 - 124 - } u; 125 - }ieee_param; 126 - 127 - 128 - #define MSECS(t) msecs_to_jiffies(t) 129 - #define msleep_interruptible_rtl msleep_interruptible 130 - 131 - #define IEEE80211_DATA_LEN 2304 132 - /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section 133 - 6.2.1.1.2. 134 - 135 - The figure in section 7.1.2 suggests a body size of up to 2312 136 - bytes is allowed, which is a bit confusing, I suspect this 137 - represents the 2304 bytes of real data, plus a possible 8 bytes of 138 - WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */ 139 - 140 - #define IEEE80211_3ADDR_LEN 24 141 - #define IEEE80211_4ADDR_LEN 30 142 - #define IEEE80211_FCS_LEN 4 143 - #define IEEE80211_HLEN IEEE80211_4ADDR_LEN 144 - #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN) 145 - #define IEEE80211_MGMT_HDR_LEN 24 146 - #define IEEE80211_DATA_HDR3_LEN 24 147 - #define IEEE80211_DATA_HDR4_LEN 30 148 - 149 - #define MIN_FRAG_THRESHOLD 256U 150 - #define MAX_FRAG_THRESHOLD 2346U 151 - 152 - /* Frame control field constants */ 153 - #define IEEE80211_FCTL_DSTODS 0x0300 //added by david 154 - #define IEEE80211_FCTL_WEP 0x4000 155 - 156 - /* debug macros */ 157 - 158 - #ifdef CONFIG_IEEE80211_DEBUG 159 - extern u32 ieee80211_debug_level; 160 - #define IEEE80211_DEBUG(level, fmt, args...) \ 161 - do { if (ieee80211_debug_level & (level)) \ 162 - printk(KERN_DEBUG "ieee80211: %c %s " fmt, \ 163 - in_interrupt() ? 'I' : 'U', __func__ , ## args); } while (0) 164 - #else 165 - #define IEEE80211_DEBUG(level, fmt, args...) do {} while (0) 166 - #endif /* CONFIG_IEEE80211_DEBUG */ 167 - 168 - /* 169 - * To use the debug system; 170 - * 171 - * If you are defining a new debug classification, simply add it to the #define 172 - * list here in the form of: 173 - * 174 - * #define IEEE80211_DL_xxxx VALUE 175 - * 176 - * shifting value to the left one bit from the previous entry. xxxx should be 177 - * the name of the classification (for example, WEP) 178 - * 179 - * You then need to either add a IEEE80211_xxxx_DEBUG() macro definition for your 180 - * classification, or use IEEE80211_DEBUG(IEEE80211_DL_xxxx, ...) whenever you want 181 - * to send output to that classification. 182 - * 183 - * To add your debug level to the list of levels seen when you perform 184 - * 185 - * % cat /proc/net/ipw/debug_level 186 - * 187 - * you simply need to add your entry to the ipw_debug_levels array. 188 - * 189 - * If you do not see debug_level in /proc/net/ipw then you do not have 190 - * CONFIG_IEEE80211_DEBUG defined in your kernel configuration 191 - * 192 - */ 193 - 194 - #define IEEE80211_DL_INFO (1<<0) 195 - #define IEEE80211_DL_WX (1<<1) 196 - #define IEEE80211_DL_SCAN (1<<2) 197 - #define IEEE80211_DL_STATE (1<<3) 198 - #define IEEE80211_DL_MGMT (1<<4) 199 - #define IEEE80211_DL_FRAG (1<<5) 200 - #define IEEE80211_DL_EAP (1<<6) 201 - #define IEEE80211_DL_DROP (1<<7) 202 - 203 - #define IEEE80211_DL_TX (1<<8) 204 - #define IEEE80211_DL_RX (1<<9) 205 - 206 - #define IEEE80211_ERROR(f, a...) printk(KERN_ERR "ieee80211: " f, ## a) 207 - #define IEEE80211_WARNING(f, a...) printk(KERN_WARNING "ieee80211: " f, ## a) 208 - #define IEEE80211_DEBUG_INFO(f, a...) IEEE80211_DEBUG(IEEE80211_DL_INFO, f, ## a) 209 - 210 - #define IEEE80211_DEBUG_WX(f, a...) IEEE80211_DEBUG(IEEE80211_DL_WX, f, ## a) 211 - #define IEEE80211_DEBUG_SCAN(f, a...) IEEE80211_DEBUG(IEEE80211_DL_SCAN, f, ## a) 212 - //#define IEEE_DEBUG_SCAN IEEE80211_WARNING 213 - #define IEEE80211_DEBUG_STATE(f, a...) IEEE80211_DEBUG(IEEE80211_DL_STATE, f, ## a) 214 - #define IEEE80211_DEBUG_MGMT(f, a...) IEEE80211_DEBUG(IEEE80211_DL_MGMT, f, ## a) 215 - #define IEEE80211_DEBUG_FRAG(f, a...) IEEE80211_DEBUG(IEEE80211_DL_FRAG, f, ## a) 216 - #define IEEE80211_DEBUG_EAP(f, a...) IEEE80211_DEBUG(IEEE80211_DL_EAP, f, ## a) 217 - #define IEEE80211_DEBUG_DROP(f, a...) IEEE80211_DEBUG(IEEE80211_DL_DROP, f, ## a) 218 - #define IEEE80211_DEBUG_TX(f, a...) IEEE80211_DEBUG(IEEE80211_DL_TX, f, ## a) 219 - #define IEEE80211_DEBUG_RX(f, a...) IEEE80211_DEBUG(IEEE80211_DL_RX, f, ## a) 220 - #include <linux/netdevice.h> 221 - #include <linux/if_arp.h> /* ARPHRD_ETHER */ 222 - 223 - #ifndef WIRELESS_SPY 224 - #define WIRELESS_SPY // enable iwspy support 225 - #endif 226 - #include <net/iw_handler.h> // new driver API 227 - 228 - #ifndef ETH_P_PAE 229 - #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */ 230 - #endif /* ETH_P_PAE */ 231 - 232 - #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */ 233 - 234 - #ifndef ETH_P_80211_RAW 235 - #define ETH_P_80211_RAW (ETH_P_ECONET + 1) 236 - #endif 237 - 238 - /* IEEE 802.11 defines */ 239 - 240 - #define P80211_OUI_LEN 3 241 - 242 - struct ieee80211_snap_hdr { 243 - 244 - u8 dsap; /* always 0xAA */ 245 - u8 ssap; /* always 0xAA */ 246 - u8 ctrl; /* always 0x03 */ 247 - u8 oui[P80211_OUI_LEN]; /* organizational universal id */ 248 - 249 - } __attribute__ ((packed)); 250 - 251 - #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr) 252 - 253 - #define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE) 254 - #define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE) 255 - 256 - #define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG) 257 - #define WLAN_GET_SEQ_SEQ(seq) ((seq) & IEEE80211_SCTL_SEQ) 258 - 259 - #define WLAN_CAPABILITY_BSS (1<<0) 260 - #define WLAN_CAPABILITY_SHORT_SLOT (1<<10) 261 - 262 - #define IEEE80211_STATMASK_SIGNAL (1<<0) 263 - #define IEEE80211_STATMASK_RSSI (1<<1) 264 - #define IEEE80211_STATMASK_NOISE (1<<2) 265 - #define IEEE80211_STATMASK_RATE (1<<3) 266 - #define IEEE80211_STATMASK_WEMASK 0x7 267 - 268 - 269 - #define IEEE80211_CCK_MODULATION (1<<0) 270 - #define IEEE80211_OFDM_MODULATION (1<<1) 271 - 272 - #define IEEE80211_24GHZ_BAND (1<<0) 273 - #define IEEE80211_52GHZ_BAND (1<<1) 274 - 275 - #define IEEE80211_CCK_RATE_LEN 4 276 - #define IEEE80211_CCK_RATE_1MB 0x02 277 - #define IEEE80211_CCK_RATE_2MB 0x04 278 - #define IEEE80211_CCK_RATE_5MB 0x0B 279 - #define IEEE80211_CCK_RATE_11MB 0x16 280 - #define IEEE80211_OFDM_RATE_LEN 8 281 - #define IEEE80211_OFDM_RATE_6MB 0x0C 282 - #define IEEE80211_OFDM_RATE_9MB 0x12 283 - #define IEEE80211_OFDM_RATE_12MB 0x18 284 - #define IEEE80211_OFDM_RATE_18MB 0x24 285 - #define IEEE80211_OFDM_RATE_24MB 0x30 286 - #define IEEE80211_OFDM_RATE_36MB 0x48 287 - #define IEEE80211_OFDM_RATE_48MB 0x60 288 - #define IEEE80211_OFDM_RATE_54MB 0x6C 289 - #define IEEE80211_BASIC_RATE_MASK 0x80 290 - 291 - #define IEEE80211_CCK_RATE_1MB_MASK (1<<0) 292 - #define IEEE80211_CCK_RATE_2MB_MASK (1<<1) 293 - #define IEEE80211_CCK_RATE_5MB_MASK (1<<2) 294 - #define IEEE80211_CCK_RATE_11MB_MASK (1<<3) 295 - #define IEEE80211_OFDM_RATE_6MB_MASK (1<<4) 296 - #define IEEE80211_OFDM_RATE_9MB_MASK (1<<5) 297 - #define IEEE80211_OFDM_RATE_12MB_MASK (1<<6) 298 - #define IEEE80211_OFDM_RATE_18MB_MASK (1<<7) 299 - #define IEEE80211_OFDM_RATE_24MB_MASK (1<<8) 300 - #define IEEE80211_OFDM_RATE_36MB_MASK (1<<9) 301 - #define IEEE80211_OFDM_RATE_48MB_MASK (1<<10) 302 - #define IEEE80211_OFDM_RATE_54MB_MASK (1<<11) 303 - 304 - #define IEEE80211_CCK_RATES_MASK 0x0000000F 305 - #define IEEE80211_CCK_BASIC_RATES_MASK (IEEE80211_CCK_RATE_1MB_MASK | \ 306 - IEEE80211_CCK_RATE_2MB_MASK) 307 - #define IEEE80211_CCK_DEFAULT_RATES_MASK (IEEE80211_CCK_BASIC_RATES_MASK | \ 308 - IEEE80211_CCK_RATE_5MB_MASK | \ 309 - IEEE80211_CCK_RATE_11MB_MASK) 310 - 311 - #define IEEE80211_OFDM_RATES_MASK 0x00000FF0 312 - #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \ 313 - IEEE80211_OFDM_RATE_12MB_MASK | \ 314 - IEEE80211_OFDM_RATE_24MB_MASK) 315 - #define IEEE80211_OFDM_DEFAULT_RATES_MASK (IEEE80211_OFDM_BASIC_RATES_MASK | \ 316 - IEEE80211_OFDM_RATE_9MB_MASK | \ 317 - IEEE80211_OFDM_RATE_18MB_MASK | \ 318 - IEEE80211_OFDM_RATE_36MB_MASK | \ 319 - IEEE80211_OFDM_RATE_48MB_MASK | \ 320 - IEEE80211_OFDM_RATE_54MB_MASK) 321 - #define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \ 322 - IEEE80211_CCK_DEFAULT_RATES_MASK) 323 - 324 - #define IEEE80211_NUM_OFDM_RATES 8 325 - #define IEEE80211_NUM_CCK_RATES 4 326 - #define IEEE80211_OFDM_SHIFT_MASK_A 4 327 - 328 - /* this is stolen and modified from the madwifi driver*/ 329 - #define IEEE80211_FC0_TYPE_MASK 0x0c 330 - #define IEEE80211_FC0_TYPE_DATA 0x08 331 - #define IEEE80211_FC0_SUBTYPE_MASK 0xB0 332 - #define IEEE80211_FC0_SUBTYPE_QOS 0x80 333 - 334 - #define IEEE80211_QOS_HAS_SEQ(fc) \ 335 - (((fc) & (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) == \ 336 - (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS)) 337 - 338 - /* this is stolen from ipw2200 driver */ 339 - #define IEEE_IBSS_MAC_HASH_SIZE 31 340 - struct ieee_ibss_seq { 341 - u8 mac[ETH_ALEN]; 342 - u16 seq_num[17]; 343 - u16 frag_num[17]; 344 - unsigned long packet_time[17]; 345 - struct list_head list; 346 - }; 347 - 348 - /* NOTE: This data is for statistical purposes; not all hardware provides this 349 - * information for frames received. Not setting these will not cause 350 - * any adverse affects. */ 351 - struct ieee80211_rx_stats { 352 - u32 mac_time[2]; 353 - u8 signalstrength; 354 - s8 rssi; 355 - u8 signal; 356 - u8 noise; 357 - u16 rate; /* in 100 kbps */ 358 - u8 received_channel; 359 - u8 control; 360 - u8 mask; 361 - u8 freq; 362 - u16 len; 363 - u8 nic_type; 364 - }; 365 - 366 - /* IEEE 802.11 requires that STA supports concurrent reception of at least 367 - * three fragmented frames. This define can be increased to support more 368 - * concurrent frames, but it should be noted that each entry can consume about 369 - * 2 kB of RAM and increasing cache size will slow down frame reassembly. */ 370 - #define IEEE80211_FRAG_CACHE_LEN 4 371 - 372 - struct ieee80211_frag_entry { 373 - unsigned long first_frag_time; 374 - unsigned int seq; 375 - unsigned int last_frag; 376 - struct sk_buff *skb; 377 - u8 src_addr[ETH_ALEN]; 378 - u8 dst_addr[ETH_ALEN]; 379 - }; 380 - 381 - struct ieee80211_stats { 382 - unsigned int tx_unicast_frames; 383 - unsigned int tx_multicast_frames; 384 - unsigned int tx_fragments; 385 - unsigned int tx_unicast_octets; 386 - unsigned int tx_multicast_octets; 387 - unsigned int tx_deferred_transmissions; 388 - unsigned int tx_single_retry_frames; 389 - unsigned int tx_multiple_retry_frames; 390 - unsigned int tx_retry_limit_exceeded; 391 - unsigned int tx_discards; 392 - unsigned int rx_unicast_frames; 393 - unsigned int rx_multicast_frames; 394 - unsigned int rx_fragments; 395 - unsigned int rx_unicast_octets; 396 - unsigned int rx_multicast_octets; 397 - unsigned int rx_fcs_errors; 398 - unsigned int rx_discards_no_buffer; 399 - unsigned int tx_discards_wrong_sa; 400 - unsigned int rx_discards_undecryptable; 401 - unsigned int rx_message_in_msg_fragments; 402 - unsigned int rx_message_in_bad_msg_fragments; 403 - }; 404 - 405 - struct ieee80211_device; 406 - 407 - #include "ieee80211_crypt.h" 408 - 409 - #define SEC_KEY_1 (1<<0) 410 - #define SEC_KEY_2 (1<<1) 411 - #define SEC_KEY_3 (1<<2) 412 - #define SEC_KEY_4 (1<<3) 413 - #define SEC_ACTIVE_KEY (1<<4) 414 - #define SEC_AUTH_MODE (1<<5) 415 - #define SEC_UNICAST_GROUP (1<<6) 416 - #define SEC_LEVEL (1<<7) 417 - #define SEC_ENABLED (1<<8) 418 - 419 - #define SEC_LEVEL_0 0 /* None */ 420 - #define SEC_LEVEL_1 1 /* WEP 40 and 104 bit */ 421 - #define SEC_LEVEL_2 2 /* Level 1 + TKIP */ 422 - #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */ 423 - #define SEC_LEVEL_3 4 /* Level 2 + CCMP */ 424 - 425 - #define WEP_KEYS 4 426 - #define WEP_KEY_LEN 13 427 - 428 - #define WEP_KEY_LEN_MODIF 32 429 - 430 - struct ieee80211_security { 431 - u16 active_key:2, 432 - enabled:1, 433 - auth_mode:2, 434 - auth_algo:4, 435 - unicast_uses_group:1; 436 - u8 key_sizes[WEP_KEYS]; 437 - u8 keys[WEP_KEYS][WEP_KEY_LEN_MODIF]; 438 - u8 level; 439 - u16 flags; 440 - } __attribute__ ((packed)); 441 - 442 - 443 - /* 444 - 445 - 802.11 data frame from AP 446 - 447 - ,-------------------------------------------------------------------. 448 - Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 | 449 - |------|------|---------|---------|---------|------|---------|------| 450 - Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | frame | fcs | 451 - | | tion | (BSSID) | | | ence | data | | 452 - `-------------------------------------------------------------------' 453 - 454 - Total: 28-2340 bytes 455 - 456 - */ 457 - 458 - /* Management Frame Information Element Types */ 459 - enum { 460 - MFIE_TYPE_SSID = 0, 461 - MFIE_TYPE_RATES = 1, 462 - MFIE_TYPE_FH_SET = 2, 463 - MFIE_TYPE_DS_SET = 3, 464 - MFIE_TYPE_CF_SET = 4, 465 - MFIE_TYPE_TIM = 5, 466 - MFIE_TYPE_IBSS_SET = 6, 467 - MFIE_TYPE_COUNTRY = 7, 468 - MFIE_TYPE_CHALLENGE = 16, 469 - MFIE_TYPE_ERP = 42, 470 - MFIE_TYPE_RSN = 48, 471 - MFIE_TYPE_RATES_EX = 50, 472 - MFIE_TYPE_GENERIC = 221, 473 - }; 474 - 475 - struct ieee80211_header_data { 476 - __le16 frame_ctl; 477 - u16 duration_id; 478 - u8 addr1[6]; 479 - u8 addr2[6]; 480 - u8 addr3[6]; 481 - u16 seq_ctrl; 482 - }; 483 - 484 - struct ieee80211_hdr_4addr { 485 - __le16 frame_ctl; 486 - u16 duration_id; 487 - u8 addr1[ETH_ALEN]; 488 - u8 addr2[ETH_ALEN]; 489 - u8 addr3[ETH_ALEN]; 490 - u16 seq_ctl; 491 - u8 addr4[ETH_ALEN]; 492 - } __attribute__ ((packed)); 493 - 494 - struct ieee80211_hdr_3addrqos { 495 - u16 frame_ctl; 496 - u16 duration_id; 497 - u8 addr1[ETH_ALEN]; 498 - u8 addr2[ETH_ALEN]; 499 - u8 addr3[ETH_ALEN]; 500 - u16 seq_ctl; 501 - u16 qos_ctl; 502 - } __attribute__ ((packed)); 503 - 504 - struct ieee80211_hdr_4addrqos { 505 - u16 frame_ctl; 506 - u16 duration_id; 507 - u8 addr1[ETH_ALEN]; 508 - u8 addr2[ETH_ALEN]; 509 - u8 addr3[ETH_ALEN]; 510 - u16 seq_ctl; 511 - u8 addr4[ETH_ALEN]; 512 - u16 qos_ctl; 513 - } __attribute__ ((packed)); 514 - 515 - struct ieee80211_info_element_hdr { 516 - u8 id; 517 - u8 len; 518 - } __attribute__ ((packed)); 519 - 520 - struct ieee80211_info_element { 521 - u8 id; 522 - u8 len; 523 - u8 data[0]; 524 - } __attribute__ ((packed)); 525 - 526 - struct ieee80211_authentication { 527 - struct ieee80211_header_data header; 528 - u16 algorithm; 529 - u16 transaction; 530 - u16 status; 531 - //struct ieee80211_info_element_hdr info_element; 532 - } __attribute__ ((packed)); 533 - 534 - struct ieee80211_disassoc_frame { 535 - struct ieee80211_hdr_3addr header; 536 - u16 reasoncode; 537 - } __attribute__ ((packed)); 538 - 539 - struct ieee80211_probe_request { 540 - struct ieee80211_header_data header; 541 - /* struct ieee80211_info_element info_element; */ 542 - } __attribute__ ((packed)); 543 - 544 - struct ieee80211_probe_response { 545 - struct ieee80211_header_data header; 546 - u32 time_stamp[2]; 547 - u16 beacon_interval; 548 - u16 capability; 549 - struct ieee80211_info_element info_element; 550 - } __attribute__ ((packed)); 551 - 552 - struct ieee80211_assoc_request_frame { 553 - struct ieee80211_hdr_3addr header; 554 - u16 capability; 555 - u16 listen_interval; 556 - //u8 current_ap[ETH_ALEN]; 557 - struct ieee80211_info_element_hdr info_element; 558 - } __attribute__ ((packed)); 559 - 560 - struct ieee80211_assoc_response_frame { 561 - struct ieee80211_hdr_3addr header; 562 - u16 capability; 563 - u16 status; 564 - u16 aid; 565 - struct ieee80211_info_element info_element; /* supported rates */ 566 - } __attribute__ ((packed)); 567 - 568 - struct ieee80211_txb { 569 - u8 nr_frags; 570 - u8 encrypted; 571 - u16 reserved; 572 - u16 frag_size; 573 - u16 payload_size; 574 - struct sk_buff *fragments[0]; 575 - }; 576 - 577 - /* SWEEP TABLE ENTRIES NUMBER */ 578 - #define MAX_SWEEP_TAB_ENTRIES 42 579 - #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET 7 580 - 581 - /* MAX_RATES_LENGTH needs to be 12. The spec says 8, and many APs 582 - * only use 8, and then use extended rates for the remaining supported 583 - * rates. Other APs, however, stick all of their supported rates on the 584 - * main rates information element... */ 585 - #define MAX_RATES_LENGTH ((u8)12) 586 - #define MAX_RATES_EX_LENGTH ((u8)16) 587 - 588 - #define MAX_NETWORK_COUNT 128 589 - 590 - #define MAX_CHANNEL_NUMBER 165 591 - 592 - #define IEEE80211_SOFTMAC_SCAN_TIME 100 /* (HZ / 2) */ 593 - #define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2) 594 - 595 - #define CRC_LENGTH 4U 596 - 597 - #define MAX_WPA_IE_LEN 64 598 - 599 - #define NETWORK_EMPTY_ESSID (1 << 0) 600 - #define NETWORK_HAS_OFDM (1 << 1) 601 - #define NETWORK_HAS_CCK (1 << 2) 602 - 603 - struct ieee80211_wmm_ac_param { 604 - u8 ac_aci_acm_aifsn; 605 - u8 ac_ecwmin_ecwmax; 606 - u16 ac_txop_limit; 607 - }; 608 - 609 - struct ieee80211_wmm_ts_info { 610 - u8 ac_dir_tid; 611 - u8 ac_up_psb; 612 - u8 reserved; 613 - } __attribute__ ((packed)); 614 - 615 - struct ieee80211_wmm_tspec_elem { 616 - struct ieee80211_wmm_ts_info ts_info; 617 - u16 norm_msdu_size; 618 - u16 max_msdu_size; 619 - u32 min_serv_inter; 620 - u32 max_serv_inter; 621 - u32 inact_inter; 622 - u32 suspen_inter; 623 - u32 serv_start_time; 624 - u32 min_data_rate; 625 - u32 mean_data_rate; 626 - u32 peak_data_rate; 627 - u32 max_burst_size; 628 - u32 delay_bound; 629 - u32 min_phy_rate; 630 - u16 surp_band_allow; 631 - u16 medium_time; 632 - }__attribute__((packed)); 633 - 634 - enum eap_type { 635 - EAP_PACKET = 0, 636 - EAPOL_START, 637 - EAPOL_LOGOFF, 638 - EAPOL_KEY, 639 - EAPOL_ENCAP_ASF_ALERT 640 - }; 641 - 642 - static const char *eap_types[] = { 643 - [EAP_PACKET] = "EAP-Packet", 644 - [EAPOL_START] = "EAPOL-Start", 645 - [EAPOL_LOGOFF] = "EAPOL-Logoff", 646 - [EAPOL_KEY] = "EAPOL-Key", 647 - [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert" 648 - }; 649 - 650 - static inline const char *eap_get_type(int type) 651 - { 652 - return (type >= ARRAY_SIZE(eap_types)) ? "Unknown" : eap_types[type]; 653 - } 654 - 655 - struct eapol { 656 - u8 snap[6]; 657 - u16 ethertype; 658 - u8 version; 659 - u8 type; 660 - u16 length; 661 - } __attribute__ ((packed)); 662 - 663 - struct ieee80211_softmac_stats { 664 - unsigned int rx_ass_ok; 665 - unsigned int rx_ass_err; 666 - unsigned int rx_probe_rq; 667 - unsigned int tx_probe_rs; 668 - unsigned int tx_beacons; 669 - unsigned int rx_auth_rq; 670 - unsigned int rx_auth_rs_ok; 671 - unsigned int rx_auth_rs_err; 672 - unsigned int tx_auth_rq; 673 - unsigned int no_auth_rs; 674 - unsigned int no_ass_rs; 675 - unsigned int tx_ass_rq; 676 - unsigned int rx_ass_rq; 677 - unsigned int tx_probe_rq; 678 - unsigned int reassoc; 679 - unsigned int swtxstop; 680 - unsigned int swtxawake; 681 - }; 682 - 683 - #define BEACON_PROBE_SSID_ID_POSITION 12 684 - 685 - /* 686 - * These are the data types that can make up management packets 687 - * 688 - u16 auth_algorithm; 689 - u16 auth_sequence; 690 - u16 beacon_interval; 691 - u16 capability; 692 - u8 current_ap[ETH_ALEN]; 693 - u16 listen_interval; 694 - struct { 695 - u16 association_id:14, reserved:2; 696 - } __attribute__ ((packed)); 697 - u32 time_stamp[2]; 698 - u16 reason; 699 - u16 status; 700 - */ 701 - 702 - #define IEEE80211_DEFAULT_TX_ESSID "Penguin" 703 - #define IEEE80211_DEFAULT_BASIC_RATE 10 704 - 705 - enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame}; 706 - #define MAX_SP_Len (WMM_all_frame << 4) 707 - #define IEEE80211_QOS_TID 0x0f 708 - #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5) 709 - 710 - #define MAX_IE_LEN 0xFF //+YJ,080625 711 - 712 - struct rtl8187se_channel_list { 713 - u8 channel[MAX_CHANNEL_NUMBER + 1]; 714 - u8 len; 715 - }; 716 - 717 - //by amy for ps 718 - #define IEEE80211_WATCH_DOG_TIME 2000 719 - //by amy for ps 720 - //by amy for antenna 721 - #define ANTENNA_DIVERSITY_TIMER_PERIOD 1000 // 1000 m 722 - //by amy for antenna 723 - 724 - #define IEEE80211_DTIM_MBCAST 4 725 - #define IEEE80211_DTIM_UCAST 2 726 - #define IEEE80211_DTIM_VALID 1 727 - #define IEEE80211_DTIM_INVALID 0 728 - 729 - #define IEEE80211_PS_DISABLED 0 730 - #define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST 731 - #define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST 732 - #define IEEE80211_PS_ENABLE IEEE80211_DTIM_VALID 733 - //added by David for QoS 2006/6/30 734 - //#define WMM_Hang_8187 735 - #ifdef WMM_Hang_8187 736 - #undef WMM_Hang_8187 737 - #endif 738 - 739 - #define WME_AC_BE 0x00 740 - #define WME_AC_BK 0x01 741 - #define WME_AC_VI 0x02 742 - #define WME_AC_VO 0x03 743 - #define WME_ACI_MASK 0x03 744 - #define WME_AIFSN_MASK 0x03 745 - #define WME_AC_PRAM_LEN 16 746 - 747 - //UP Mapping to AC, using in MgntQuery_SequenceNumber() and maybe for DSCP 748 - //#define UP2AC(up) ((up<3) ? ((up==0)?1:0) : (up>>1)) 749 - #define UP2AC(up) ( \ 750 - ((up) < 1) ? WME_AC_BE : \ 751 - ((up) < 3) ? WME_AC_BK : \ 752 - ((up) < 4) ? WME_AC_BE : \ 753 - ((up) < 6) ? WME_AC_VI : \ 754 - WME_AC_VO) 755 - //AC Mapping to UP, using in Tx part for selecting the corresponding TX queue 756 - #define AC2UP(_ac) ( \ 757 - ((_ac) == WME_AC_VO) ? 6 : \ 758 - ((_ac) == WME_AC_VI) ? 5 : \ 759 - ((_ac) == WME_AC_BK) ? 1 : \ 760 - 0) 761 - 762 - #define ETHER_ADDR_LEN 6 /* length of an Ethernet address */ 763 - struct ether_header { 764 - u8 ether_dhost[ETHER_ADDR_LEN]; 765 - u8 ether_shost[ETHER_ADDR_LEN]; 766 - u16 ether_type; 767 - } __attribute__((packed)); 768 - 769 - #ifndef ETHERTYPE_PAE 770 - #define ETHERTYPE_PAE 0x888e /* EAPOL PAE/802.1x */ 771 - #endif 772 - #ifndef ETHERTYPE_IP 773 - #define ETHERTYPE_IP 0x0800 /* IP protocol */ 774 - #endif 775 - 776 - struct ieee80211_network { 777 - /* These entries are used to identify a unique network */ 778 - u8 bssid[ETH_ALEN]; 779 - u8 channel; 780 - /* Ensure null-terminated for any debug msgs */ 781 - u8 ssid[IW_ESSID_MAX_SIZE + 1]; 782 - u8 ssid_len; 783 - 784 - /* These are network statistics */ 785 - struct ieee80211_rx_stats stats; 786 - u16 capability; 787 - u8 rates[MAX_RATES_LENGTH]; 788 - u8 rates_len; 789 - u8 rates_ex[MAX_RATES_EX_LENGTH]; 790 - u8 rates_ex_len; 791 - unsigned long last_scanned; 792 - u8 mode; 793 - u8 flags; 794 - u32 last_associate; 795 - u32 time_stamp[2]; 796 - u16 beacon_interval; 797 - u16 listen_interval; 798 - u16 atim_window; 799 - u8 wpa_ie[MAX_WPA_IE_LEN]; 800 - size_t wpa_ie_len; 801 - u8 rsn_ie[MAX_WPA_IE_LEN]; 802 - size_t rsn_ie_len; 803 - u8 dtim_period; 804 - u8 dtim_data; 805 - u32 last_dtim_sta_time[2]; 806 - struct list_head list; 807 - //appeded for QoS 808 - u8 wmm_info; 809 - struct ieee80211_wmm_ac_param wmm_param[4]; 810 - u8 QoS_Enable; 811 - u8 SignalStrength; 812 - //by amy 080312 813 - u8 HighestOperaRate; 814 - //by amy 080312 815 - u8 Turbo_Enable;//enable turbo mode, added by thomas 816 - u16 CountryIeLen; 817 - u8 CountryIeBuf[MAX_IE_LEN]; 818 - }; 819 - 820 - enum ieee80211_state { 821 - 822 - /* the card is not linked at all */ 823 - IEEE80211_NOLINK = 0, 824 - 825 - /* IEEE80211_ASSOCIATING* are for BSS client mode 826 - * the driver shall not perform RX filtering unless 827 - * the state is LINKED. 828 - * The driver shall just check for the state LINKED and 829 - * defaults to NOLINK for ALL the other states (including 830 - * LINKED_SCANNING) 831 - */ 832 - 833 - /* the association procedure will start (wq scheduling)*/ 834 - IEEE80211_ASSOCIATING, 835 - IEEE80211_ASSOCIATING_RETRY, 836 - 837 - /* the association procedure is sending AUTH request*/ 838 - IEEE80211_ASSOCIATING_AUTHENTICATING, 839 - 840 - /* the association procedure has successfully authenticated 841 - * and is sending association request 842 - */ 843 - IEEE80211_ASSOCIATING_AUTHENTICATED, 844 - 845 - /* the link is ok. the card associated to a BSS or linked 846 - * to a ibss cell or acting as an AP and creating the bss 847 - */ 848 - IEEE80211_LINKED, 849 - 850 - /* same as LINKED, but the driver shall apply RX filter 851 - * rules as we are in NO_LINK mode. As the card is still 852 - * logically linked, but it is doing a syncro site survey 853 - * then it will be back to LINKED state. 854 - */ 855 - IEEE80211_LINKED_SCANNING, 856 - 857 - }; 858 - 859 - #define DEFAULT_MAX_SCAN_AGE (15 * HZ) 860 - #define DEFAULT_FTS 2346 861 - 862 - #define CFG_IEEE80211_RESERVE_FCS (1<<0) 863 - #define CFG_IEEE80211_COMPUTE_FCS (1<<1) 864 - 865 - typedef struct tx_pending_t{ 866 - int frag; 867 - struct ieee80211_txb *txb; 868 - }tx_pending_t; 869 - 870 - enum { 871 - COUNTRY_CODE_FCC = 0, 872 - COUNTRY_CODE_IC = 1, 873 - COUNTRY_CODE_ETSI = 2, 874 - COUNTRY_CODE_SPAIN = 3, 875 - COUNTRY_CODE_FRANCE = 4, 876 - COUNTRY_CODE_MKK = 5, 877 - COUNTRY_CODE_MKK1 = 6, 878 - COUNTRY_CODE_ISRAEL = 7, 879 - COUNTRY_CODE_TELEC = 8, 880 - COUNTRY_CODE_GLOBAL_DOMAIN = 9, 881 - COUNTRY_CODE_WORLD_WIDE_13_INDEX = 10 882 - }; 883 - 884 - struct ieee80211_device { 885 - struct net_device *dev; 886 - 887 - /* Bookkeeping structures */ 888 - struct net_device_stats stats; 889 - struct ieee80211_stats ieee_stats; 890 - struct ieee80211_softmac_stats softmac_stats; 891 - 892 - /* Probe / Beacon management */ 893 - struct list_head network_free_list; 894 - struct list_head network_list; 895 - struct ieee80211_network *networks; 896 - int scans; 897 - int scan_age; 898 - 899 - int iw_mode; /* operating mode (IW_MODE_*) */ 900 - 901 - spinlock_t lock; 902 - spinlock_t wpax_suitlist_lock; 903 - 904 - int tx_headroom; /* Set to size of any additional room needed at front 905 - * of allocated Tx SKBs */ 906 - u32 config; 907 - 908 - /* WEP and other encryption related settings at the device level */ 909 - int open_wep; /* Set to 1 to allow unencrypted frames */ 910 - 911 - int reset_on_keychange; /* Set to 1 if the HW needs to be reset on 912 - * WEP key changes */ 913 - 914 - /* If the host performs {en,de}cryption, then set to 1 */ 915 - int host_encrypt; 916 - int host_decrypt; 917 - int ieee802_1x; /* is IEEE 802.1X used */ 918 - 919 - /* WPA data */ 920 - int wpa_enabled; 921 - int drop_unencrypted; 922 - int tkip_countermeasures; 923 - int privacy_invoked; 924 - size_t wpa_ie_len; 925 - u8 *wpa_ie; 926 - 927 - u8 ap_mac_addr[6]; 928 - u16 pairwise_key_type; 929 - u16 broadcast_key_type; 930 - 931 - struct list_head crypt_deinit_list; 932 - struct ieee80211_crypt_data *crypt[WEP_KEYS]; 933 - int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */ 934 - struct timer_list crypt_deinit_timer; 935 - 936 - int bcrx_sta_key; /* use individual keys to override default keys even 937 - * with RX of broad/multicast frames */ 938 - 939 - /* Fragmentation structures */ 940 - /* each stream contains an entry */ 941 - struct ieee80211_frag_entry frag_cache[17][IEEE80211_FRAG_CACHE_LEN]; 942 - unsigned int frag_next_idx[17]; 943 - u16 fts; /* Fragmentation Threshold */ 944 - 945 - /* This stores infos for the current network. 946 - * Either the network we are associated in INFRASTRUCTURE 947 - * or the network that we are creating in MASTER mode. 948 - * ad-hoc is a mixture ;-). 949 - * Note that in infrastructure mode, even when not associated, 950 - * fields bssid and essid may be valid (if wpa_set and essid_set 951 - * are true) as thy carry the value set by the user via iwconfig 952 - */ 953 - struct ieee80211_network current_network; 954 - 955 - 956 - enum ieee80211_state state; 957 - 958 - int short_slot; 959 - int mode; /* A, B, G */ 960 - int modulation; /* CCK, OFDM */ 961 - int freq_band; /* 2.4Ghz, 5.2Ghz, Mixed */ 962 - int abg_true; /* ABG flag */ 963 - 964 - /* used for forcing the ibss workqueue to terminate 965 - * without wait for the syncro scan to terminate 966 - */ 967 - short sync_scan_hurryup; 968 - 969 - void * pDot11dInfo; 970 - bool bGlobalDomain; 971 - 972 - // For Liteon Ch12~13 passive scan 973 - u8 MinPassiveChnlNum; 974 - u8 IbssStartChnl; 975 - 976 - int rate; /* current rate */ 977 - int basic_rate; 978 - //FIXME: please callback, see if redundant with softmac_features 979 - short active_scan; 980 - 981 - /* this contains flags for selectively enable softmac support */ 982 - u16 softmac_features; 983 - 984 - /* if the sequence control field is not filled by HW */ 985 - u16 seq_ctrl[5]; 986 - 987 - /* association procedure transaction sequence number */ 988 - u16 associate_seq; 989 - 990 - /* AID for RTXed association responses */ 991 - u16 assoc_id; 992 - 993 - /* power save mode related*/ 994 - short ps; 995 - short sta_sleep; 996 - int ps_timeout; 997 - struct tasklet_struct ps_task; 998 - u32 ps_th; 999 - u32 ps_tl; 1000 - 1001 - short raw_tx; 1002 - /* used if IEEE_SOFTMAC_TX_QUEUE is set */ 1003 - short queue_stop; 1004 - short scanning; 1005 - short proto_started; 1006 - 1007 - struct semaphore wx_sem; 1008 - struct semaphore scan_sem; 1009 - 1010 - spinlock_t mgmt_tx_lock; 1011 - spinlock_t beacon_lock; 1012 - 1013 - short beacon_txing; 1014 - 1015 - short wap_set; 1016 - short ssid_set; 1017 - 1018 - u8 wpax_type_set; //{added by David, 2006.9.28} 1019 - u32 wpax_type_notify; //{added by David, 2006.9.26} 1020 - 1021 - /* QoS related flag */ 1022 - char init_wmmparam_flag; 1023 - 1024 - /* for discarding duplicated packets in IBSS */ 1025 - struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE]; 1026 - 1027 - /* for discarding duplicated packets in BSS */ 1028 - u16 last_rxseq_num[17]; /* rx seq previous per-tid */ 1029 - u16 last_rxfrag_num[17];/* tx frag previous per-tid */ 1030 - unsigned long last_packet_time[17]; 1031 - 1032 - /* for PS mode */ 1033 - unsigned long last_rx_ps_time; 1034 - 1035 - /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */ 1036 - struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM]; 1037 - int mgmt_queue_head; 1038 - int mgmt_queue_tail; 1039 - 1040 - 1041 - /* used if IEEE_SOFTMAC_TX_QUEUE is set */ 1042 - struct tx_pending_t tx_pending; 1043 - 1044 - /* used if IEEE_SOFTMAC_ASSOCIATE is set */ 1045 - struct timer_list associate_timer; 1046 - 1047 - /* used if IEEE_SOFTMAC_BEACONS is set */ 1048 - struct timer_list beacon_timer; 1049 - 1050 - struct work_struct associate_complete_wq; 1051 - // struct work_struct associate_retry_wq; 1052 - struct work_struct associate_procedure_wq; 1053 - // struct work_struct softmac_scan_wq; 1054 - struct work_struct wx_sync_scan_wq; 1055 - struct work_struct wmm_param_update_wq; 1056 - struct work_struct ps_request_tx_ack_wq;//for ps 1057 - // struct work_struct hw_wakeup_wq; 1058 - // struct work_struct hw_sleep_wq; 1059 - // struct work_struct watch_dog_wq; 1060 - bool bInactivePs; 1061 - bool actscanning; 1062 - bool beinretry; 1063 - u16 ListenInterval; 1064 - unsigned long NumRxDataInPeriod; //YJ,add,080828 1065 - unsigned long NumRxBcnInPeriod; //YJ,add,080828 1066 - unsigned long NumRxOkTotal; 1067 - unsigned long NumRxUnicast;//YJ,add,080828,for keep alive 1068 - bool bHwRadioOff; 1069 - struct delayed_work softmac_scan_wq; 1070 - struct delayed_work associate_retry_wq; 1071 - struct delayed_work hw_wakeup_wq; 1072 - struct delayed_work hw_sleep_wq;//+by amy 080324 1073 - struct delayed_work watch_dog_wq; 1074 - struct delayed_work sw_antenna_wq; 1075 - struct delayed_work start_ibss_wq; 1076 - //by amy for rate adaptive 080312 1077 - struct delayed_work rate_adapter_wq; 1078 - //by amy for rate adaptive 1079 - struct delayed_work hw_dig_wq; 1080 - struct delayed_work tx_pw_wq; 1081 - 1082 - //Added for RF power on power off by lizhaoming 080512 1083 - struct delayed_work GPIOChangeRFWorkItem; 1084 - 1085 - struct workqueue_struct *wq; 1086 - 1087 - /* Callback functions */ 1088 - void (*set_security)(struct net_device *dev, 1089 - struct ieee80211_security *sec); 1090 - 1091 - /* Used to TX data frame by using txb structs. 1092 - * this is not used if in the softmac_features 1093 - * is set the flag IEEE_SOFTMAC_TX_QUEUE 1094 - */ 1095 - int (*hard_start_xmit)(struct ieee80211_txb *txb, 1096 - struct net_device *dev); 1097 - 1098 - int (*reset_port)(struct net_device *dev); 1099 - 1100 - /* Softmac-generated frames (management) are TXed via this 1101 - * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is 1102 - * not set. As some cards may have different HW queues that 1103 - * one might want to use for data and management frames 1104 - * the option to have two callbacks might be useful. 1105 - * This function can't sleep. 1106 - */ 1107 - int (*softmac_hard_start_xmit)(struct sk_buff *skb, 1108 - struct net_device *dev); 1109 - 1110 - /* used instead of hard_start_xmit (not softmac_hard_start_xmit) 1111 - * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data 1112 - * frames. If the option IEEE_SOFTMAC_SINGLE_QUEUE is also set 1113 - * then also management frames are sent via this callback. 1114 - * This function can't sleep. 1115 - */ 1116 - void (*softmac_data_hard_start_xmit)(struct sk_buff *skb, 1117 - struct net_device *dev,int rate); 1118 - 1119 - /* stops the HW queue for DATA frames. Useful to avoid 1120 - * waste time to TX data frame when we are reassociating 1121 - * This function can sleep. 1122 - */ 1123 - void (*data_hard_stop)(struct net_device *dev); 1124 - 1125 - /* OK this is complementar to data_poll_hard_stop */ 1126 - void (*data_hard_resume)(struct net_device *dev); 1127 - 1128 - /* ask to the driver to retune the radio . 1129 - * This function can sleep. the driver should ensure 1130 - * the radio has been switched before return. 1131 - */ 1132 - void (*set_chan)(struct net_device *dev,short ch); 1133 - 1134 - /* These are not used if the ieee stack takes care of 1135 - * scanning (IEEE_SOFTMAC_SCAN feature set). 1136 - * In this case only the set_chan is used. 1137 - * 1138 - * The syncro version is similar to the start_scan but 1139 - * does not return until all channels has been scanned. 1140 - * this is called in user context and should sleep, 1141 - * it is called in a work_queue when switching to ad-hoc mode 1142 - * or in behalf of iwlist scan when the card is associated 1143 - * and root user ask for a scan. 1144 - * the function stop_scan should stop both the syncro and 1145 - * background scanning and can sleep. 1146 - * The function start_scan should initiate the background 1147 - * scanning and can't sleep. 1148 - */ 1149 - void (*scan_syncro)(struct net_device *dev); 1150 - void (*start_scan)(struct net_device *dev); 1151 - void (*stop_scan)(struct net_device *dev); 1152 - 1153 - /* indicate the driver that the link state is changed 1154 - * for example it may indicate the card is associated now. 1155 - * Driver might be interested in this to apply RX filter 1156 - * rules or simply light the LINK led 1157 - */ 1158 - void (*link_change)(struct net_device *dev); 1159 - 1160 - /* these two function indicates to the HW when to start 1161 - * and stop to send beacons. This is used when the 1162 - * IEEE_SOFTMAC_BEACONS is not set. For now the 1163 - * stop_send_bacons is NOT guaranteed to be called only 1164 - * after start_send_beacons. 1165 - */ 1166 - void (*start_send_beacons) (struct net_device *dev); 1167 - void (*stop_send_beacons) (struct net_device *dev); 1168 - 1169 - /* power save mode related */ 1170 - void (*sta_wake_up) (struct net_device *dev); 1171 - void (*ps_request_tx_ack) (struct net_device *dev); 1172 - void (*enter_sleep_state) (struct net_device *dev, u32 th, u32 tl); 1173 - short (*ps_is_queue_empty) (struct net_device *dev); 1174 - 1175 - /* QoS related */ 1176 - //void (*wmm_param_update) (struct net_device *dev, u8 *ac_param); 1177 - //void (*wmm_param_update) (struct ieee80211_device *ieee); 1178 - 1179 - /* This must be the last item so that it points to the data 1180 - * allocated beyond this structure by alloc_ieee80211 */ 1181 - u8 priv[0]; 1182 - }; 1183 - 1184 - #define IEEE_A (1<<0) 1185 - #define IEEE_B (1<<1) 1186 - #define IEEE_G (1<<2) 1187 - #define IEEE_MODE_MASK (IEEE_A|IEEE_B|IEEE_G) 1188 - 1189 - /* Generate a 802.11 header */ 1190 - 1191 - /* Uses the channel change callback directly 1192 - * instead of [start/stop] scan callbacks 1193 - */ 1194 - #define IEEE_SOFTMAC_SCAN (1<<2) 1195 - 1196 - /* Perform authentication and association handshake */ 1197 - #define IEEE_SOFTMAC_ASSOCIATE (1<<3) 1198 - 1199 - /* Generate probe requests */ 1200 - #define IEEE_SOFTMAC_PROBERQ (1<<4) 1201 - 1202 - /* Generate response to probe requests */ 1203 - #define IEEE_SOFTMAC_PROBERS (1<<5) 1204 - 1205 - /* The ieee802.11 stack will manages the netif queue 1206 - * wake/stop for the driver, taking care of 802.11 1207 - * fragmentation. See softmac.c for details. */ 1208 - #define IEEE_SOFTMAC_TX_QUEUE (1<<7) 1209 - 1210 - /* Uses only the softmac_data_hard_start_xmit 1211 - * even for TX management frames. 1212 - */ 1213 - #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8) 1214 - 1215 - /* Generate beacons. The stack will enqueue beacons 1216 - * to the card 1217 - */ 1218 - #define IEEE_SOFTMAC_BEACONS (1<<6) 1219 - 1220 - 1221 - 1222 - static inline void *ieee80211_priv(struct net_device *dev) 1223 - { 1224 - return ((struct ieee80211_device *)netdev_priv(dev))->priv; 1225 - } 1226 - 1227 - static inline int ieee80211_is_empty_essid(const char *essid, int essid_len) 1228 - { 1229 - /* Single white space is for Linksys APs */ 1230 - if (essid_len == 1 && essid[0] == ' ') 1231 - return 1; 1232 - 1233 - /* Otherwise, if the entire essid is 0, we assume it is hidden */ 1234 - while (essid_len) { 1235 - essid_len--; 1236 - if (essid[essid_len] != '\0') 1237 - return 0; 1238 - } 1239 - 1240 - return 1; 1241 - } 1242 - 1243 - static inline int ieee80211_is_valid_mode(struct ieee80211_device *ieee, 1244 - int mode) 1245 - { 1246 - /* 1247 - * It is possible for both access points and our device to support 1248 - * combinations of modes, so as long as there is one valid combination 1249 - * of ap/device supported modes, then return success 1250 - * 1251 - */ 1252 - if ((mode & IEEE_A) && 1253 - (ieee->modulation & IEEE80211_OFDM_MODULATION) && 1254 - (ieee->freq_band & IEEE80211_52GHZ_BAND)) 1255 - return 1; 1256 - 1257 - if ((mode & IEEE_G) && 1258 - (ieee->modulation & IEEE80211_OFDM_MODULATION) && 1259 - (ieee->freq_band & IEEE80211_24GHZ_BAND)) 1260 - return 1; 1261 - 1262 - if ((mode & IEEE_B) && 1263 - (ieee->modulation & IEEE80211_CCK_MODULATION) && 1264 - (ieee->freq_band & IEEE80211_24GHZ_BAND)) 1265 - return 1; 1266 - 1267 - return 0; 1268 - } 1269 - 1270 - static inline int ieee80211_get_hdrlen(u16 fc) 1271 - { 1272 - int hdrlen = 24; 1273 - 1274 - switch (WLAN_FC_GET_TYPE(fc)) { 1275 - case IEEE80211_FTYPE_DATA: 1276 - if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS)) 1277 - hdrlen = 30; /* Addr4 */ 1278 - if(IEEE80211_QOS_HAS_SEQ(fc)) 1279 - hdrlen += 2; /* QOS ctrl*/ 1280 - break; 1281 - case IEEE80211_FTYPE_CTL: 1282 - switch (WLAN_FC_GET_STYPE(fc)) { 1283 - case IEEE80211_STYPE_CTS: 1284 - case IEEE80211_STYPE_ACK: 1285 - hdrlen = 10; 1286 - break; 1287 - default: 1288 - hdrlen = 16; 1289 - break; 1290 - } 1291 - break; 1292 - } 1293 - 1294 - return hdrlen; 1295 - } 1296 - 1297 - 1298 - 1299 - /* ieee80211.c */ 1300 - extern void free_ieee80211(struct net_device *dev); 1301 - extern struct net_device *alloc_ieee80211(int sizeof_priv); 1302 - 1303 - extern int ieee80211_set_encryption(struct ieee80211_device *ieee); 1304 - 1305 - /* ieee80211_tx.c */ 1306 - 1307 - extern int ieee80211_encrypt_fragment(struct ieee80211_device *ieee, 1308 - struct sk_buff *frag, int hdr_len); 1309 - 1310 - extern int ieee80211_rtl_xmit(struct sk_buff *skb, struct net_device *dev); 1311 - extern void ieee80211_txb_free(struct ieee80211_txb *); 1312 - 1313 - 1314 - /* ieee80211_rx.c */ 1315 - extern int ieee80211_rtl_rx(struct ieee80211_device *ieee, struct sk_buff *skb, 1316 - struct ieee80211_rx_stats *rx_stats); 1317 - extern void ieee80211_rx_mgt(struct ieee80211_device *ieee, 1318 - struct ieee80211_hdr_4addr *header, 1319 - struct ieee80211_rx_stats *stats); 1320 - 1321 - /* ieee80211_wx.c */ 1322 - extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee, 1323 - struct iw_request_info *info, 1324 - union iwreq_data *wrqu, char *key); 1325 - extern int ieee80211_wx_set_encode(struct ieee80211_device *ieee, 1326 - struct iw_request_info *info, 1327 - union iwreq_data *wrqu, char *key); 1328 - extern int ieee80211_wx_get_encode(struct ieee80211_device *ieee, 1329 - struct iw_request_info *info, 1330 - union iwreq_data *wrqu, char *key); 1331 - extern int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee, 1332 - struct iw_request_info *info, 1333 - union iwreq_data *wrqu, char *extra); 1334 - int ieee80211_wx_set_auth(struct ieee80211_device *ieee, 1335 - struct iw_request_info *info, 1336 - struct iw_param *data, char *extra); 1337 - int ieee80211_wx_set_mlme(struct ieee80211_device *ieee, 1338 - struct iw_request_info *info, 1339 - union iwreq_data *wrqu, char *extra); 1340 - 1341 - int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len); 1342 - /* ieee80211_softmac.c */ 1343 - extern short ieee80211_is_54g(const struct ieee80211_network *net); 1344 - extern short ieee80211_is_shortslot(const struct ieee80211_network *net); 1345 - extern int ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, 1346 - struct sk_buff *skb, 1347 - struct ieee80211_rx_stats *rx_stats, 1348 - u16 type, u16 stype); 1349 - extern void ieee80211_softmac_new_net(struct ieee80211_device *ieee, 1350 - struct ieee80211_network *net); 1351 - 1352 - extern void ieee80211_softmac_xmit(struct ieee80211_txb *txb, 1353 - struct ieee80211_device *ieee); 1354 - extern void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee); 1355 - extern void ieee80211_start_bss(struct ieee80211_device *ieee); 1356 - extern void ieee80211_start_master_bss(struct ieee80211_device *ieee); 1357 - extern void ieee80211_start_ibss(struct ieee80211_device *ieee); 1358 - extern void ieee80211_softmac_init(struct ieee80211_device *ieee); 1359 - extern void ieee80211_softmac_free(struct ieee80211_device *ieee); 1360 - extern void ieee80211_associate_abort(struct ieee80211_device *ieee); 1361 - extern void ieee80211_disassociate(struct ieee80211_device *ieee); 1362 - extern void ieee80211_stop_scan(struct ieee80211_device *ieee); 1363 - extern void ieee80211_start_scan_syncro(struct ieee80211_device *ieee); 1364 - extern void ieee80211_check_all_nets(struct ieee80211_device *ieee); 1365 - extern void ieee80211_start_protocol(struct ieee80211_device *ieee); 1366 - extern void ieee80211_stop_protocol(struct ieee80211_device *ieee); 1367 - extern void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee); 1368 - extern void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee); 1369 - extern void ieee80211_reset_queue(struct ieee80211_device *ieee); 1370 - extern void ieee80211_rtl_wake_queue(struct ieee80211_device *ieee); 1371 - extern void ieee80211_rtl_stop_queue(struct ieee80211_device *ieee); 1372 - extern struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee); 1373 - extern void ieee80211_start_send_beacons(struct ieee80211_device *ieee); 1374 - extern void ieee80211_stop_send_beacons(struct ieee80211_device *ieee); 1375 - extern int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, 1376 - struct iw_point *p); 1377 - extern void notify_wx_assoc_event(struct ieee80211_device *ieee); 1378 - extern void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success); 1379 - extern void SendDisassociation(struct ieee80211_device *ieee, u8 *asSta, 1380 - u8 asRsn); 1381 - extern void ieee80211_rtl_start_scan(struct ieee80211_device *ieee); 1382 - 1383 - //Add for RF power on power off by lizhaoming 080512 1384 - extern void SendDisassociation(struct ieee80211_device *ieee, u8 *asSta, 1385 - u8 asRsn); 1386 - 1387 - /* ieee80211_crypt_ccmp&tkip&wep.c */ 1388 - extern void ieee80211_tkip_null(void); 1389 - extern void ieee80211_wep_null(void); 1390 - extern void ieee80211_ccmp_null(void); 1391 - /* ieee80211_softmac_wx.c */ 1392 - 1393 - extern int ieee80211_wx_get_wap(struct ieee80211_device *ieee, 1394 - struct iw_request_info *info, 1395 - union iwreq_data *wrqu, char *ext); 1396 - 1397 - extern int ieee80211_wx_set_wap(struct ieee80211_device *ieee, 1398 - struct iw_request_info *info, 1399 - union iwreq_data *awrq, 1400 - char *extra); 1401 - 1402 - extern int ieee80211_wx_get_essid(struct ieee80211_device *ieee, 1403 - struct iw_request_info *a, 1404 - union iwreq_data *wrqu, char *b); 1405 - 1406 - extern int ieee80211_wx_set_rate(struct ieee80211_device *ieee, 1407 - struct iw_request_info *info, 1408 - union iwreq_data *wrqu, char *extra); 1409 - 1410 - extern int ieee80211_wx_get_rate(struct ieee80211_device *ieee, 1411 - struct iw_request_info *info, 1412 - union iwreq_data *wrqu, char *extra); 1413 - 1414 - extern int ieee80211_wx_set_mode(struct ieee80211_device *ieee, 1415 - struct iw_request_info *a, 1416 - union iwreq_data *wrqu, char *b); 1417 - 1418 - extern int ieee80211_wx_set_scan(struct ieee80211_device *ieee, 1419 - struct iw_request_info *a, 1420 - union iwreq_data *wrqu, char *b); 1421 - 1422 - extern int ieee80211_wx_set_essid(struct ieee80211_device *ieee, 1423 - struct iw_request_info *a, 1424 - union iwreq_data *wrqu, char *extra); 1425 - 1426 - extern int ieee80211_wx_get_mode(struct ieee80211_device *ieee, 1427 - struct iw_request_info *a, 1428 - union iwreq_data *wrqu, char *b); 1429 - 1430 - extern int ieee80211_wx_set_freq(struct ieee80211_device *ieee, 1431 - struct iw_request_info *a, 1432 - union iwreq_data *wrqu, char *b); 1433 - 1434 - extern int ieee80211_wx_get_freq(struct ieee80211_device *ieee, 1435 - struct iw_request_info *a, 1436 - union iwreq_data *wrqu, char *b); 1437 - 1438 - extern void ieee80211_wx_sync_scan_wq(struct work_struct *work); 1439 - 1440 - extern int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee, 1441 - struct iw_request_info *info, 1442 - union iwreq_data *wrqu, char *extra); 1443 - 1444 - extern int ieee80211_wx_get_name(struct ieee80211_device *ieee, 1445 - struct iw_request_info *info, 1446 - union iwreq_data *wrqu, char *extra); 1447 - 1448 - extern int ieee80211_wx_set_power(struct ieee80211_device *ieee, 1449 - struct iw_request_info *info, 1450 - union iwreq_data *wrqu, char *extra); 1451 - 1452 - extern int ieee80211_wx_get_power(struct ieee80211_device *ieee, 1453 - struct iw_request_info *info, 1454 - union iwreq_data *wrqu, char *extra); 1455 - 1456 - extern void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device *ieee); 1457 - 1458 - extern void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee, 1459 - short pwr); 1460 - 1461 - extern const long ieee80211_wlan_frequencies[]; 1462 - 1463 - extern inline void ieee80211_increment_scans(struct ieee80211_device *ieee) 1464 - { 1465 - ieee->scans++; 1466 - } 1467 - 1468 - extern inline int ieee80211_get_scans(struct ieee80211_device *ieee) 1469 - { 1470 - return ieee->scans; 1471 - } 1472 - 1473 - static inline const char *escape_essid(const char *essid, u8 essid_len) { 1474 - static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; 1475 - const char *s = essid; 1476 - char *d = escaped; 1477 - 1478 - if (ieee80211_is_empty_essid(essid, essid_len)) { 1479 - memcpy(escaped, "<hidden>", sizeof("<hidden>")); 1480 - return escaped; 1481 - } 1482 - 1483 - essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE); 1484 - while (essid_len--) { 1485 - if (*s == '\0') { 1486 - *d++ = '\\'; 1487 - *d++ = '0'; 1488 - s++; 1489 - } else { 1490 - *d++ = *s++; 1491 - } 1492 - } 1493 - *d = '\0'; 1494 - return escaped; 1495 - } 1496 - #endif /* IEEE80211_H */
-240
drivers/staging/rtl8187se/ieee80211/ieee80211_crypt.c
··· 1 - /* 2 - * Host AP crypto routines 3 - * 4 - * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> 5 - * Portions Copyright (C) 2004, Intel Corporation <jketreno@linux.intel.com> 6 - * 7 - * This program is free software; you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License version 2 as 9 - * published by the Free Software Foundation. See README and COPYING for 10 - * more details. 11 - * 12 - */ 13 - 14 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 15 - 16 - //#include <linux/config.h> 17 - #include <linux/module.h> 18 - #include <linux/slab.h> 19 - #include <linux/string.h> 20 - #include <linux/errno.h> 21 - 22 - #include "ieee80211.h" 23 - 24 - MODULE_AUTHOR("Jouni Malinen"); 25 - MODULE_DESCRIPTION("HostAP crypto"); 26 - MODULE_LICENSE("GPL"); 27 - 28 - struct ieee80211_crypto_alg { 29 - struct list_head list; 30 - struct ieee80211_crypto_ops *ops; 31 - }; 32 - 33 - 34 - struct ieee80211_crypto { 35 - struct list_head algs; 36 - spinlock_t lock; 37 - }; 38 - 39 - static struct ieee80211_crypto *hcrypt; 40 - 41 - void ieee80211_crypt_deinit_entries(struct ieee80211_device *ieee, int force) 42 - { 43 - struct list_head *ptr, *n; 44 - struct ieee80211_crypt_data *entry; 45 - 46 - for (ptr = ieee->crypt_deinit_list.next, n = ptr->next; 47 - ptr != &ieee->crypt_deinit_list; ptr = n, n = ptr->next) { 48 - entry = list_entry(ptr, struct ieee80211_crypt_data, list); 49 - 50 - if (atomic_read(&entry->refcnt) != 0 && !force) 51 - continue; 52 - 53 - list_del(ptr); 54 - 55 - if (entry->ops) 56 - entry->ops->deinit(entry->priv); 57 - kfree(entry); 58 - } 59 - } 60 - 61 - void ieee80211_crypt_deinit_handler(unsigned long data) 62 - { 63 - struct ieee80211_device *ieee = (struct ieee80211_device *)data; 64 - unsigned long flags; 65 - 66 - spin_lock_irqsave(&ieee->lock, flags); 67 - ieee80211_crypt_deinit_entries(ieee, 0); 68 - if (!list_empty(&ieee->crypt_deinit_list)) { 69 - pr_debug("entries remaining in delayed crypt deletion list\n"); 70 - ieee->crypt_deinit_timer.expires = jiffies + HZ; 71 - add_timer(&ieee->crypt_deinit_timer); 72 - } 73 - spin_unlock_irqrestore(&ieee->lock, flags); 74 - 75 - } 76 - 77 - void ieee80211_crypt_delayed_deinit(struct ieee80211_device *ieee, 78 - struct ieee80211_crypt_data **crypt) 79 - { 80 - struct ieee80211_crypt_data *tmp; 81 - unsigned long flags; 82 - 83 - if (*crypt == NULL) 84 - return; 85 - 86 - tmp = *crypt; 87 - *crypt = NULL; 88 - 89 - /* must not run ops->deinit() while there may be pending encrypt or 90 - * decrypt operations. Use a list of delayed deinits to avoid needing 91 - * locking. */ 92 - 93 - spin_lock_irqsave(&ieee->lock, flags); 94 - list_add(&tmp->list, &ieee->crypt_deinit_list); 95 - if (!timer_pending(&ieee->crypt_deinit_timer)) { 96 - ieee->crypt_deinit_timer.expires = jiffies + HZ; 97 - add_timer(&ieee->crypt_deinit_timer); 98 - } 99 - spin_unlock_irqrestore(&ieee->lock, flags); 100 - } 101 - 102 - int ieee80211_register_crypto_ops(struct ieee80211_crypto_ops *ops) 103 - { 104 - unsigned long flags; 105 - struct ieee80211_crypto_alg *alg; 106 - 107 - if (hcrypt == NULL) 108 - return -1; 109 - 110 - alg = kzalloc(sizeof(*alg), GFP_KERNEL); 111 - if (alg == NULL) 112 - return -ENOMEM; 113 - 114 - alg->ops = ops; 115 - 116 - spin_lock_irqsave(&hcrypt->lock, flags); 117 - list_add(&alg->list, &hcrypt->algs); 118 - spin_unlock_irqrestore(&hcrypt->lock, flags); 119 - 120 - pr_debug("registered algorithm '%s'\n", ops->name); 121 - 122 - return 0; 123 - } 124 - 125 - int ieee80211_unregister_crypto_ops(struct ieee80211_crypto_ops *ops) 126 - { 127 - unsigned long flags; 128 - struct list_head *ptr; 129 - struct ieee80211_crypto_alg *del_alg = NULL; 130 - 131 - if (hcrypt == NULL) 132 - return -1; 133 - 134 - spin_lock_irqsave(&hcrypt->lock, flags); 135 - for (ptr = hcrypt->algs.next; ptr != &hcrypt->algs; ptr = ptr->next) { 136 - struct ieee80211_crypto_alg *alg = 137 - (struct ieee80211_crypto_alg *) ptr; 138 - if (alg->ops == ops) { 139 - list_del(&alg->list); 140 - del_alg = alg; 141 - break; 142 - } 143 - } 144 - spin_unlock_irqrestore(&hcrypt->lock, flags); 145 - 146 - if (del_alg) { 147 - pr_debug("unregistered algorithm '%s'\n", ops->name); 148 - kfree(del_alg); 149 - } 150 - 151 - return del_alg ? 0 : -1; 152 - } 153 - 154 - 155 - struct ieee80211_crypto_ops *ieee80211_get_crypto_ops(const char *name) 156 - { 157 - unsigned long flags; 158 - struct list_head *ptr; 159 - struct ieee80211_crypto_alg *found_alg = NULL; 160 - 161 - if (hcrypt == NULL) 162 - return NULL; 163 - 164 - spin_lock_irqsave(&hcrypt->lock, flags); 165 - for (ptr = hcrypt->algs.next; ptr != &hcrypt->algs; ptr = ptr->next) { 166 - struct ieee80211_crypto_alg *alg = 167 - (struct ieee80211_crypto_alg *) ptr; 168 - if (strcmp(alg->ops->name, name) == 0) { 169 - found_alg = alg; 170 - break; 171 - } 172 - } 173 - spin_unlock_irqrestore(&hcrypt->lock, flags); 174 - 175 - if (found_alg) 176 - return found_alg->ops; 177 - else 178 - return NULL; 179 - } 180 - 181 - 182 - static void *ieee80211_crypt_null_init(int keyidx) { return (void *) 1; } 183 - static void ieee80211_crypt_null_deinit(void *priv) {} 184 - 185 - static struct ieee80211_crypto_ops ieee80211_crypt_null = { 186 - .name = "NULL", 187 - .init = ieee80211_crypt_null_init, 188 - .deinit = ieee80211_crypt_null_deinit, 189 - .encrypt_mpdu = NULL, 190 - .decrypt_mpdu = NULL, 191 - .encrypt_msdu = NULL, 192 - .decrypt_msdu = NULL, 193 - .set_key = NULL, 194 - .get_key = NULL, 195 - .extra_prefix_len = 0, 196 - .extra_postfix_len = 0, 197 - .owner = THIS_MODULE, 198 - }; 199 - 200 - 201 - int ieee80211_crypto_init(void) 202 - { 203 - int ret = -ENOMEM; 204 - 205 - hcrypt = kzalloc(sizeof(*hcrypt), GFP_KERNEL); 206 - if (!hcrypt) 207 - goto out; 208 - 209 - INIT_LIST_HEAD(&hcrypt->algs); 210 - spin_lock_init(&hcrypt->lock); 211 - 212 - ret = ieee80211_register_crypto_ops(&ieee80211_crypt_null); 213 - if (ret < 0) { 214 - kfree(hcrypt); 215 - hcrypt = NULL; 216 - } 217 - out: 218 - return ret; 219 - } 220 - 221 - 222 - void ieee80211_crypto_deinit(void) 223 - { 224 - struct list_head *ptr, *n; 225 - struct ieee80211_crypto_alg *alg = NULL; 226 - 227 - if (hcrypt == NULL) 228 - return; 229 - 230 - list_for_each_safe(ptr, n, &hcrypt->algs) { 231 - alg = list_entry(ptr, struct ieee80211_crypto_alg, list); 232 - if (alg) { 233 - list_del(ptr); 234 - pr_debug("unregistered algorithm '%s' (deinit)\n", 235 - alg->ops->name); 236 - kfree(alg); 237 - } 238 - } 239 - kfree(hcrypt); 240 - }
-86
drivers/staging/rtl8187se/ieee80211/ieee80211_crypt.h
··· 1 - /* 2 - * Original code based on Host AP (software wireless LAN access point) driver 3 - * for Intersil Prism2/2.5/3. 4 - * 5 - * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen 6 - * <jkmaline@cc.hut.fi> 7 - * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> 8 - * 9 - * Adaption to a generic IEEE 802.11 stack by James Ketrenos 10 - * <jketreno@linux.intel.com> 11 - * 12 - * Copyright (c) 2004, Intel Corporation 13 - * 14 - * This program is free software; you can redistribute it and/or modify 15 - * it under the terms of the GNU General Public License version 2 as 16 - * published by the Free Software Foundation. See README and COPYING for 17 - * more details. 18 - */ 19 - 20 - /* 21 - * This file defines the interface to the ieee80211 crypto module. 22 - */ 23 - #ifndef IEEE80211_CRYPT_H 24 - #define IEEE80211_CRYPT_H 25 - 26 - #include <linux/skbuff.h> 27 - 28 - struct ieee80211_crypto_ops { 29 - const char *name; 30 - 31 - /* init new crypto context (e.g., allocate private data space, 32 - * select IV, etc.); returns NULL on failure or pointer to allocated 33 - * private data on success */ 34 - void * (*init)(int keyidx); 35 - 36 - /* deinitialize crypto context and free allocated private data */ 37 - void (*deinit)(void *priv); 38 - 39 - /* encrypt/decrypt return < 0 on error or >= 0 on success. The return 40 - * value from decrypt_mpdu is passed as the keyidx value for 41 - * decrypt_msdu. skb must have enough head and tail room for the 42 - * encryption; if not, error will be returned; these functions are 43 - * called for all MPDUs (i.e., fragments). 44 - */ 45 - int (*encrypt_mpdu)(struct sk_buff *skb, int hdr_len, void *priv); 46 - int (*decrypt_mpdu)(struct sk_buff *skb, int hdr_len, void *priv); 47 - 48 - /* These functions are called for full MSDUs, i.e. full frames. 49 - * These can be NULL if full MSDU operations are not needed. */ 50 - int (*encrypt_msdu)(struct sk_buff *skb, int hdr_len, void *priv); 51 - int (*decrypt_msdu)(struct sk_buff *skb, int keyidx, int hdr_len, 52 - void *priv); 53 - 54 - int (*set_key)(void *key, int len, u8 *seq, void *priv); 55 - int (*get_key)(void *key, int len, u8 *seq, void *priv); 56 - 57 - /* procfs handler for printing out key information and possible 58 - * statistics */ 59 - char * (*print_stats)(char *p, void *priv); 60 - 61 - /* maximum number of bytes added by encryption; encrypt buf is 62 - * allocated with extra_prefix_len bytes, copy of in_buf, and 63 - * extra_postfix_len; encrypt need not use all this space, but 64 - * the result must start at the beginning of the buffer and correct 65 - * length must be returned */ 66 - int extra_prefix_len, extra_postfix_len; 67 - 68 - struct module *owner; 69 - }; 70 - 71 - struct ieee80211_crypt_data { 72 - struct list_head list; /* delayed deletion list */ 73 - struct ieee80211_crypto_ops *ops; 74 - void *priv; 75 - atomic_t refcnt; 76 - }; 77 - 78 - int ieee80211_register_crypto_ops(struct ieee80211_crypto_ops *ops); 79 - int ieee80211_unregister_crypto_ops(struct ieee80211_crypto_ops *ops); 80 - struct ieee80211_crypto_ops *ieee80211_get_crypto_ops(const char *name); 81 - void ieee80211_crypt_deinit_entries(struct ieee80211_device *, int); 82 - void ieee80211_crypt_deinit_handler(unsigned long); 83 - void ieee80211_crypt_delayed_deinit(struct ieee80211_device *ieee, 84 - struct ieee80211_crypt_data **crypt); 85 - 86 - #endif
-455
drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_ccmp.c
··· 1 - /* 2 - * Host AP crypt: host-based CCMP encryption implementation for Host AP driver 3 - * 4 - * Copyright (c) 2003-2004, Jouni Malinen <jkmaline@cc.hut.fi> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. See README and COPYING for 9 - * more details. 10 - */ 11 - 12 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13 - 14 - #include <linux/module.h> 15 - #include <linux/slab.h> 16 - #include <linux/random.h> 17 - #include <linux/skbuff.h> 18 - #include <linux/netdevice.h> 19 - #include <linux/if_ether.h> 20 - #include <linux/if_arp.h> 21 - #include <linux/string.h> 22 - #include <linux/wireless.h> 23 - 24 - #include "ieee80211.h" 25 - 26 - #include <linux/crypto.h> 27 - #include <linux/scatterlist.h> 28 - 29 - MODULE_AUTHOR("Jouni Malinen"); 30 - MODULE_DESCRIPTION("Host AP crypt: CCMP"); 31 - MODULE_LICENSE("GPL"); 32 - 33 - 34 - #define AES_BLOCK_LEN 16 35 - #define CCMP_HDR_LEN 8 36 - #define CCMP_MIC_LEN 8 37 - #define CCMP_TK_LEN 16 38 - #define CCMP_PN_LEN 6 39 - 40 - struct ieee80211_ccmp_data { 41 - u8 key[CCMP_TK_LEN]; 42 - int key_set; 43 - 44 - u8 tx_pn[CCMP_PN_LEN]; 45 - u8 rx_pn[CCMP_PN_LEN]; 46 - 47 - u32 dot11RSNAStatsCCMPFormatErrors; 48 - u32 dot11RSNAStatsCCMPReplays; 49 - u32 dot11RSNAStatsCCMPDecryptErrors; 50 - 51 - int key_idx; 52 - 53 - struct crypto_tfm *tfm; 54 - 55 - /* scratch buffers for virt_to_page() (crypto API) */ 56 - u8 tx_b0[AES_BLOCK_LEN], tx_b[AES_BLOCK_LEN], 57 - tx_e[AES_BLOCK_LEN], tx_s0[AES_BLOCK_LEN]; 58 - u8 rx_b0[AES_BLOCK_LEN], rx_b[AES_BLOCK_LEN], rx_a[AES_BLOCK_LEN]; 59 - }; 60 - 61 - static void ieee80211_ccmp_aes_encrypt(struct crypto_tfm *tfm, 62 - const u8 pt[16], u8 ct[16]) 63 - { 64 - crypto_cipher_encrypt_one((void *)tfm, ct, pt); 65 - } 66 - 67 - static void *ieee80211_ccmp_init(int key_idx) 68 - { 69 - struct ieee80211_ccmp_data *priv; 70 - 71 - priv = kzalloc(sizeof(*priv), GFP_ATOMIC); 72 - if (priv == NULL) 73 - goto fail; 74 - priv->key_idx = key_idx; 75 - 76 - priv->tfm = (void *)crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC); 77 - if (IS_ERR(priv->tfm)) { 78 - pr_debug("could not allocate crypto API aes\n"); 79 - priv->tfm = NULL; 80 - goto fail; 81 - } 82 - 83 - return priv; 84 - 85 - fail: 86 - if (priv) { 87 - if (priv->tfm) 88 - crypto_free_cipher((void *)priv->tfm); 89 - kfree(priv); 90 - } 91 - 92 - return NULL; 93 - } 94 - 95 - 96 - static void ieee80211_ccmp_deinit(void *priv) 97 - { 98 - struct ieee80211_ccmp_data *_priv = priv; 99 - 100 - if (_priv && _priv->tfm) 101 - crypto_free_cipher((void *)_priv->tfm); 102 - kfree(priv); 103 - } 104 - 105 - 106 - static inline void xor_block(u8 *b, u8 *a, size_t len) 107 - { 108 - int i; 109 - for (i = 0; i < len; i++) 110 - b[i] ^= a[i]; 111 - } 112 - 113 - static void ccmp_init_blocks(struct crypto_tfm *tfm, 114 - struct ieee80211_hdr_4addr *hdr, 115 - u8 *pn, size_t dlen, u8 *b0, u8 *auth, 116 - u8 *s0) 117 - { 118 - u8 *pos, qc = 0; 119 - size_t aad_len; 120 - u16 fc; 121 - int a4_included, qc_included; 122 - u8 aad[2 * AES_BLOCK_LEN]; 123 - 124 - fc = le16_to_cpu(hdr->frame_ctl); 125 - a4_included = ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == 126 - (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)); 127 - /* 128 - qc_included = ((WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA) && 129 - (WLAN_FC_GET_STYPE(fc) & 0x08)); 130 - */ 131 - qc_included = ((WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA) && 132 - (WLAN_FC_GET_STYPE(fc) & 0x80)); 133 - aad_len = 22; 134 - if (a4_included) 135 - aad_len += 6; 136 - if (qc_included) { 137 - pos = (u8 *) &hdr->addr4; 138 - if (a4_included) 139 - pos += 6; 140 - qc = *pos & 0x0f; 141 - aad_len += 2; 142 - } 143 - /* CCM Initial Block: 144 - * Flag (Include authentication header, M=3 (8-octet MIC), 145 - * L=1 (2-octet Dlen)) 146 - * Nonce: 0x00 | A2 | PN 147 - * Dlen */ 148 - b0[0] = 0x59; 149 - b0[1] = qc; 150 - memcpy(b0 + 2, hdr->addr2, ETH_ALEN); 151 - memcpy(b0 + 8, pn, CCMP_PN_LEN); 152 - b0[14] = (dlen >> 8) & 0xff; 153 - b0[15] = dlen & 0xff; 154 - 155 - /* AAD: 156 - * FC with bits 4..6 and 11..13 masked to zero; 14 is always one 157 - * A1 | A2 | A3 158 - * SC with bits 4..15 (seq#) masked to zero 159 - * A4 (if present) 160 - * QC (if present) 161 - */ 162 - pos = (u8 *) hdr; 163 - aad[0] = 0; /* aad_len >> 8 */ 164 - aad[1] = aad_len & 0xff; 165 - aad[2] = pos[0] & 0x8f; 166 - aad[3] = pos[1] & 0xc7; 167 - memcpy(aad + 4, hdr->addr1, 3 * ETH_ALEN); 168 - pos = (u8 *) &hdr->seq_ctl; 169 - aad[22] = pos[0] & 0x0f; 170 - aad[23] = 0; /* all bits masked */ 171 - memset(aad + 24, 0, 8); 172 - if (a4_included) 173 - memcpy(aad + 24, hdr->addr4, ETH_ALEN); 174 - if (qc_included) { 175 - aad[a4_included ? 30 : 24] = qc; 176 - /* rest of QC masked */ 177 - } 178 - 179 - /* Start with the first block and AAD */ 180 - ieee80211_ccmp_aes_encrypt(tfm, b0, auth); 181 - xor_block(auth, aad, AES_BLOCK_LEN); 182 - ieee80211_ccmp_aes_encrypt(tfm, auth, auth); 183 - xor_block(auth, &aad[AES_BLOCK_LEN], AES_BLOCK_LEN); 184 - ieee80211_ccmp_aes_encrypt(tfm, auth, auth); 185 - b0[0] &= 0x07; 186 - b0[14] = b0[15] = 0; 187 - ieee80211_ccmp_aes_encrypt(tfm, b0, s0); 188 - } 189 - 190 - static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv) 191 - { 192 - struct ieee80211_ccmp_data *key = priv; 193 - int data_len, i; 194 - u8 *pos; 195 - struct ieee80211_hdr_4addr *hdr; 196 - int blocks, last, len; 197 - u8 *mic; 198 - u8 *b0 = key->tx_b0; 199 - u8 *b = key->tx_b; 200 - u8 *e = key->tx_e; 201 - u8 *s0 = key->tx_s0; 202 - 203 - if (skb_headroom(skb) < CCMP_HDR_LEN || 204 - skb_tailroom(skb) < CCMP_MIC_LEN || 205 - skb->len < hdr_len) 206 - return -1; 207 - 208 - data_len = skb->len - hdr_len; 209 - pos = skb_push(skb, CCMP_HDR_LEN); 210 - memmove(pos, pos + CCMP_HDR_LEN, hdr_len); 211 - pos += hdr_len; 212 - 213 - i = CCMP_PN_LEN - 1; 214 - while (i >= 0) { 215 - key->tx_pn[i]++; 216 - if (key->tx_pn[i] != 0) 217 - break; 218 - i--; 219 - } 220 - 221 - *pos++ = key->tx_pn[5]; 222 - *pos++ = key->tx_pn[4]; 223 - *pos++ = 0; 224 - *pos++ = (key->key_idx << 6) | (1 << 5) /* Ext IV included */; 225 - *pos++ = key->tx_pn[3]; 226 - *pos++ = key->tx_pn[2]; 227 - *pos++ = key->tx_pn[1]; 228 - *pos++ = key->tx_pn[0]; 229 - 230 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 231 - mic = skb_put(skb, CCMP_MIC_LEN); 232 - 233 - ccmp_init_blocks(key->tfm, hdr, key->tx_pn, data_len, b0, b, s0); 234 - 235 - blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN; 236 - last = data_len % AES_BLOCK_LEN; 237 - 238 - for (i = 1; i <= blocks; i++) { 239 - len = (i == blocks && last) ? last : AES_BLOCK_LEN; 240 - /* Authentication */ 241 - xor_block(b, pos, len); 242 - ieee80211_ccmp_aes_encrypt(key->tfm, b, b); 243 - /* Encryption, with counter */ 244 - b0[14] = (i >> 8) & 0xff; 245 - b0[15] = i & 0xff; 246 - ieee80211_ccmp_aes_encrypt(key->tfm, b0, e); 247 - xor_block(pos, e, len); 248 - pos += len; 249 - } 250 - 251 - for (i = 0; i < CCMP_MIC_LEN; i++) 252 - mic[i] = b[i] ^ s0[i]; 253 - 254 - return 0; 255 - } 256 - 257 - 258 - static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv) 259 - { 260 - struct ieee80211_ccmp_data *key = priv; 261 - u8 keyidx, *pos; 262 - struct ieee80211_hdr_4addr *hdr; 263 - u8 pn[6]; 264 - size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN - CCMP_MIC_LEN; 265 - u8 *mic = skb->data + skb->len - CCMP_MIC_LEN; 266 - u8 *b0 = key->rx_b0; 267 - u8 *b = key->rx_b; 268 - u8 *a = key->rx_a; 269 - int i, blocks, last, len; 270 - 271 - if (skb->len < hdr_len + CCMP_HDR_LEN + CCMP_MIC_LEN) { 272 - key->dot11RSNAStatsCCMPFormatErrors++; 273 - return -1; 274 - } 275 - 276 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 277 - pos = skb->data + hdr_len; 278 - keyidx = pos[3]; 279 - if (!(keyidx & (1 << 5))) { 280 - if (net_ratelimit()) { 281 - pr_debug("received packet without ExtIV flag from %pM\n", 282 - hdr->addr2); 283 - } 284 - key->dot11RSNAStatsCCMPFormatErrors++; 285 - return -2; 286 - } 287 - keyidx >>= 6; 288 - if (key->key_idx != keyidx) { 289 - pr_debug("RX tkey->key_idx=%d frame keyidx=%d priv=%p\n", 290 - key->key_idx, keyidx, priv); 291 - return -6; 292 - } 293 - if (!key->key_set) { 294 - if (net_ratelimit()) { 295 - pr_debug("received packet from %pM with keyid=%d that does not have a configured key\n", 296 - hdr->addr2, keyidx); 297 - } 298 - return -3; 299 - } 300 - 301 - pn[0] = pos[7]; 302 - pn[1] = pos[6]; 303 - pn[2] = pos[5]; 304 - pn[3] = pos[4]; 305 - pn[4] = pos[1]; 306 - pn[5] = pos[0]; 307 - pos += 8; 308 - 309 - if (memcmp(pn, key->rx_pn, CCMP_PN_LEN) <= 0) { 310 - if (net_ratelimit()) { 311 - pr_debug("replay detected: STA=%pM previous PN %pm received PN %pm\n", 312 - hdr->addr2, key->rx_pn, pn); 313 - } 314 - key->dot11RSNAStatsCCMPReplays++; 315 - return -4; 316 - } 317 - 318 - ccmp_init_blocks(key->tfm, hdr, pn, data_len, b0, a, b); 319 - xor_block(mic, b, CCMP_MIC_LEN); 320 - 321 - blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN; 322 - last = data_len % AES_BLOCK_LEN; 323 - 324 - for (i = 1; i <= blocks; i++) { 325 - len = (i == blocks && last) ? last : AES_BLOCK_LEN; 326 - /* Decrypt, with counter */ 327 - b0[14] = (i >> 8) & 0xff; 328 - b0[15] = i & 0xff; 329 - ieee80211_ccmp_aes_encrypt(key->tfm, b0, b); 330 - xor_block(pos, b, len); 331 - /* Authentication */ 332 - xor_block(a, pos, len); 333 - ieee80211_ccmp_aes_encrypt(key->tfm, a, a); 334 - pos += len; 335 - } 336 - 337 - if (memcmp(mic, a, CCMP_MIC_LEN) != 0) { 338 - if (net_ratelimit()) 339 - pr_debug("decrypt failed: STA=%pM\n", hdr->addr2); 340 - 341 - key->dot11RSNAStatsCCMPDecryptErrors++; 342 - return -5; 343 - } 344 - 345 - memcpy(key->rx_pn, pn, CCMP_PN_LEN); 346 - 347 - /* Remove hdr and MIC */ 348 - memmove(skb->data + CCMP_HDR_LEN, skb->data, hdr_len); 349 - skb_pull(skb, CCMP_HDR_LEN); 350 - skb_trim(skb, skb->len - CCMP_MIC_LEN); 351 - 352 - return keyidx; 353 - } 354 - 355 - 356 - static int ieee80211_ccmp_set_key(void *key, int len, u8 *seq, void *priv) 357 - { 358 - struct ieee80211_ccmp_data *data = priv; 359 - int keyidx; 360 - struct crypto_tfm *tfm = data->tfm; 361 - 362 - keyidx = data->key_idx; 363 - memset(data, 0, sizeof(*data)); 364 - data->key_idx = keyidx; 365 - data->tfm = tfm; 366 - if (len == CCMP_TK_LEN) { 367 - memcpy(data->key, key, CCMP_TK_LEN); 368 - data->key_set = 1; 369 - if (seq) { 370 - data->rx_pn[0] = seq[5]; 371 - data->rx_pn[1] = seq[4]; 372 - data->rx_pn[2] = seq[3]; 373 - data->rx_pn[3] = seq[2]; 374 - data->rx_pn[4] = seq[1]; 375 - data->rx_pn[5] = seq[0]; 376 - } 377 - crypto_cipher_setkey((void *)data->tfm, data->key, CCMP_TK_LEN); 378 - } else if (len == 0) 379 - data->key_set = 0; 380 - else 381 - return -1; 382 - 383 - return 0; 384 - } 385 - 386 - 387 - static int ieee80211_ccmp_get_key(void *key, int len, u8 *seq, void *priv) 388 - { 389 - struct ieee80211_ccmp_data *data = priv; 390 - 391 - if (len < CCMP_TK_LEN) 392 - return -1; 393 - 394 - if (!data->key_set) 395 - return 0; 396 - memcpy(key, data->key, CCMP_TK_LEN); 397 - 398 - if (seq) { 399 - seq[0] = data->tx_pn[5]; 400 - seq[1] = data->tx_pn[4]; 401 - seq[2] = data->tx_pn[3]; 402 - seq[3] = data->tx_pn[2]; 403 - seq[4] = data->tx_pn[1]; 404 - seq[5] = data->tx_pn[0]; 405 - } 406 - 407 - return CCMP_TK_LEN; 408 - } 409 - 410 - 411 - static char *ieee80211_ccmp_print_stats(char *p, void *priv) 412 - { 413 - struct ieee80211_ccmp_data *ccmp = priv; 414 - p += sprintf(p, 415 - "key[%d] alg=CCMP key_set=%d tx_pn=%pm rx_pn=%pm format_errors=%d replays=%d decrypt_errors=%d\n", 416 - ccmp->key_idx, ccmp->key_set, 417 - ccmp->tx_pn, ccmp->rx_pn, 418 - ccmp->dot11RSNAStatsCCMPFormatErrors, 419 - ccmp->dot11RSNAStatsCCMPReplays, 420 - ccmp->dot11RSNAStatsCCMPDecryptErrors); 421 - 422 - return p; 423 - } 424 - 425 - void ieee80211_ccmp_null(void) 426 - { 427 - return; 428 - } 429 - static struct ieee80211_crypto_ops ieee80211_crypt_ccmp = { 430 - .name = "CCMP", 431 - .init = ieee80211_ccmp_init, 432 - .deinit = ieee80211_ccmp_deinit, 433 - .encrypt_mpdu = ieee80211_ccmp_encrypt, 434 - .decrypt_mpdu = ieee80211_ccmp_decrypt, 435 - .encrypt_msdu = NULL, 436 - .decrypt_msdu = NULL, 437 - .set_key = ieee80211_ccmp_set_key, 438 - .get_key = ieee80211_ccmp_get_key, 439 - .print_stats = ieee80211_ccmp_print_stats, 440 - .extra_prefix_len = CCMP_HDR_LEN, 441 - .extra_postfix_len = CCMP_MIC_LEN, 442 - .owner = THIS_MODULE, 443 - }; 444 - 445 - 446 - int ieee80211_crypto_ccmp_init(void) 447 - { 448 - return ieee80211_register_crypto_ops(&ieee80211_crypt_ccmp); 449 - } 450 - 451 - 452 - void ieee80211_crypto_ccmp_exit(void) 453 - { 454 - ieee80211_unregister_crypto_ops(&ieee80211_crypt_ccmp); 455 - }
-740
drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c
··· 1 - /* 2 - * Host AP crypt: host-based TKIP encryption implementation for Host AP driver 3 - * 4 - * Copyright (c) 2003-2004, Jouni Malinen <jkmaline@cc.hut.fi> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. See README and COPYING for 9 - * more details. 10 - */ 11 - 12 - #include <linux/module.h> 13 - #include <linux/slab.h> 14 - #include <linux/random.h> 15 - #include <linux/skbuff.h> 16 - #include <linux/netdevice.h> 17 - #include <linux/if_ether.h> 18 - #include <linux/if_arp.h> 19 - #include <asm/string.h> 20 - 21 - #include "ieee80211.h" 22 - 23 - #include <linux/crypto.h> 24 - #include <linux/scatterlist.h> 25 - #include <linux/crc32.h> 26 - 27 - MODULE_AUTHOR("Jouni Malinen"); 28 - MODULE_DESCRIPTION("Host AP crypt: TKIP"); 29 - MODULE_LICENSE("GPL"); 30 - 31 - 32 - struct ieee80211_tkip_data { 33 - #define TKIP_KEY_LEN 32 34 - u8 key[TKIP_KEY_LEN]; 35 - int key_set; 36 - 37 - u32 tx_iv32; 38 - u16 tx_iv16; 39 - u16 tx_ttak[5]; 40 - int tx_phase1_done; 41 - 42 - u32 rx_iv32; 43 - u16 rx_iv16; 44 - u16 rx_ttak[5]; 45 - int rx_phase1_done; 46 - u32 rx_iv32_new; 47 - u16 rx_iv16_new; 48 - 49 - u32 dot11RSNAStatsTKIPReplays; 50 - u32 dot11RSNAStatsTKIPICVErrors; 51 - u32 dot11RSNAStatsTKIPLocalMICFailures; 52 - 53 - int key_idx; 54 - 55 - struct crypto_blkcipher *rx_tfm_arc4; 56 - struct crypto_hash *rx_tfm_michael; 57 - struct crypto_blkcipher *tx_tfm_arc4; 58 - struct crypto_hash *tx_tfm_michael; 59 - struct crypto_tfm *tfm_arc4; 60 - struct crypto_tfm *tfm_michael; 61 - 62 - /* scratch buffers for virt_to_page() (crypto API) */ 63 - u8 rx_hdr[16], tx_hdr[16]; 64 - }; 65 - 66 - static void *ieee80211_tkip_init(int key_idx) 67 - { 68 - struct ieee80211_tkip_data *priv; 69 - 70 - priv = kzalloc(sizeof(*priv), GFP_ATOMIC); 71 - if (priv == NULL) 72 - goto fail; 73 - priv->key_idx = key_idx; 74 - 75 - priv->tx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, 76 - CRYPTO_ALG_ASYNC); 77 - if (IS_ERR(priv->tx_tfm_arc4)) { 78 - printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate " 79 - "crypto API arc4\n"); 80 - priv->tx_tfm_arc4 = NULL; 81 - goto fail; 82 - } 83 - 84 - priv->tx_tfm_michael = crypto_alloc_hash("michael_mic", 0, 85 - CRYPTO_ALG_ASYNC); 86 - if (IS_ERR(priv->tx_tfm_michael)) { 87 - printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate " 88 - "crypto API michael_mic\n"); 89 - priv->tx_tfm_michael = NULL; 90 - goto fail; 91 - } 92 - 93 - priv->rx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, 94 - CRYPTO_ALG_ASYNC); 95 - if (IS_ERR(priv->rx_tfm_arc4)) { 96 - printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate " 97 - "crypto API arc4\n"); 98 - priv->rx_tfm_arc4 = NULL; 99 - goto fail; 100 - } 101 - 102 - priv->rx_tfm_michael = crypto_alloc_hash("michael_mic", 0, 103 - CRYPTO_ALG_ASYNC); 104 - if (IS_ERR(priv->rx_tfm_michael)) { 105 - printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate " 106 - "crypto API michael_mic\n"); 107 - priv->rx_tfm_michael = NULL; 108 - goto fail; 109 - } 110 - 111 - return priv; 112 - 113 - fail: 114 - if (priv) { 115 - if (priv->tx_tfm_michael) 116 - crypto_free_hash(priv->tx_tfm_michael); 117 - if (priv->tx_tfm_arc4) 118 - crypto_free_blkcipher(priv->tx_tfm_arc4); 119 - if (priv->rx_tfm_michael) 120 - crypto_free_hash(priv->rx_tfm_michael); 121 - if (priv->rx_tfm_arc4) 122 - crypto_free_blkcipher(priv->rx_tfm_arc4); 123 - kfree(priv); 124 - } 125 - 126 - return NULL; 127 - } 128 - 129 - 130 - static void ieee80211_tkip_deinit(void *priv) 131 - { 132 - struct ieee80211_tkip_data *_priv = priv; 133 - 134 - if (_priv) { 135 - if (_priv->tx_tfm_michael) 136 - crypto_free_hash(_priv->tx_tfm_michael); 137 - if (_priv->tx_tfm_arc4) 138 - crypto_free_blkcipher(_priv->tx_tfm_arc4); 139 - if (_priv->rx_tfm_michael) 140 - crypto_free_hash(_priv->rx_tfm_michael); 141 - if (_priv->rx_tfm_arc4) 142 - crypto_free_blkcipher(_priv->rx_tfm_arc4); 143 - } 144 - kfree(priv); 145 - } 146 - 147 - 148 - static inline u16 RotR1(u16 val) 149 - { 150 - return (val >> 1) | (val << 15); 151 - } 152 - 153 - 154 - static inline u8 Lo8(u16 val) 155 - { 156 - return val & 0xff; 157 - } 158 - 159 - 160 - static inline u8 Hi8(u16 val) 161 - { 162 - return val >> 8; 163 - } 164 - 165 - 166 - static inline u16 Lo16(u32 val) 167 - { 168 - return val & 0xffff; 169 - } 170 - 171 - 172 - static inline u16 Hi16(u32 val) 173 - { 174 - return val >> 16; 175 - } 176 - 177 - 178 - static inline u16 Mk16(u8 hi, u8 lo) 179 - { 180 - return lo | (((u16) hi) << 8); 181 - } 182 - 183 - 184 - static inline u16 Mk16_le(u16 *v) 185 - { 186 - return le16_to_cpu(*v); 187 - } 188 - 189 - 190 - static const u16 Sbox[256] = { 191 - 0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154, 192 - 0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A, 193 - 0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B, 194 - 0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B, 195 - 0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F, 196 - 0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F, 197 - 0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5, 198 - 0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F, 199 - 0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB, 200 - 0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397, 201 - 0xA6F5, 0xB968, 0x0000, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED, 202 - 0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A, 203 - 0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194, 204 - 0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3, 205 - 0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104, 206 - 0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D, 207 - 0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39, 208 - 0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695, 209 - 0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83, 210 - 0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76, 211 - 0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4, 212 - 0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B, 213 - 0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0, 214 - 0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018, 215 - 0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751, 216 - 0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85, 217 - 0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12, 218 - 0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9, 219 - 0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7, 220 - 0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A, 221 - 0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8, 222 - 0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A, 223 - }; 224 - 225 - 226 - static inline u16 _S_(u16 v) 227 - { 228 - u16 t = Sbox[Hi8(v)]; 229 - return Sbox[Lo8(v)] ^ ((t << 8) | (t >> 8)); 230 - } 231 - 232 - #define PHASE1_LOOP_COUNT 8 233 - 234 - static void tkip_mixing_phase1(u16 *TTAK, const u8 *TK, const u8 *TA, u32 IV32) 235 - { 236 - int i, j; 237 - 238 - /* Initialize the 80-bit TTAK from TSC (IV32) and TA[0..5] */ 239 - TTAK[0] = Lo16(IV32); 240 - TTAK[1] = Hi16(IV32); 241 - TTAK[2] = Mk16(TA[1], TA[0]); 242 - TTAK[3] = Mk16(TA[3], TA[2]); 243 - TTAK[4] = Mk16(TA[5], TA[4]); 244 - 245 - for (i = 0; i < PHASE1_LOOP_COUNT; i++) { 246 - j = 2 * (i & 1); 247 - TTAK[0] += _S_(TTAK[4] ^ Mk16(TK[1 + j], TK[0 + j])); 248 - TTAK[1] += _S_(TTAK[0] ^ Mk16(TK[5 + j], TK[4 + j])); 249 - TTAK[2] += _S_(TTAK[1] ^ Mk16(TK[9 + j], TK[8 + j])); 250 - TTAK[3] += _S_(TTAK[2] ^ Mk16(TK[13 + j], TK[12 + j])); 251 - TTAK[4] += _S_(TTAK[3] ^ Mk16(TK[1 + j], TK[0 + j])) + i; 252 - } 253 - } 254 - 255 - 256 - static void tkip_mixing_phase2(u8 *WEPSeed, const u8 *TK, const u16 *TTAK, 257 - u16 IV16) 258 - { 259 - /* Make temporary area overlap WEP seed so that the final copy can be 260 - * avoided on little endian hosts. */ 261 - u16 *PPK = (u16 *) &WEPSeed[4]; 262 - 263 - /* Step 1 - make copy of TTAK and bring in TSC */ 264 - PPK[0] = TTAK[0]; 265 - PPK[1] = TTAK[1]; 266 - PPK[2] = TTAK[2]; 267 - PPK[3] = TTAK[3]; 268 - PPK[4] = TTAK[4]; 269 - PPK[5] = TTAK[4] + IV16; 270 - 271 - /* Step 2 - 96-bit bijective mixing using S-box */ 272 - PPK[0] += _S_(PPK[5] ^ Mk16_le((u16 *) &TK[0])); 273 - PPK[1] += _S_(PPK[0] ^ Mk16_le((u16 *) &TK[2])); 274 - PPK[2] += _S_(PPK[1] ^ Mk16_le((u16 *) &TK[4])); 275 - PPK[3] += _S_(PPK[2] ^ Mk16_le((u16 *) &TK[6])); 276 - PPK[4] += _S_(PPK[3] ^ Mk16_le((u16 *) &TK[8])); 277 - PPK[5] += _S_(PPK[4] ^ Mk16_le((u16 *) &TK[10])); 278 - 279 - PPK[0] += RotR1(PPK[5] ^ Mk16_le((u16 *) &TK[12])); 280 - PPK[1] += RotR1(PPK[0] ^ Mk16_le((u16 *) &TK[14])); 281 - PPK[2] += RotR1(PPK[1]); 282 - PPK[3] += RotR1(PPK[2]); 283 - PPK[4] += RotR1(PPK[3]); 284 - PPK[5] += RotR1(PPK[4]); 285 - 286 - /* Step 3 - bring in last of TK bits, assign 24-bit WEP IV value 287 - * WEPSeed[0..2] is transmitted as WEP IV */ 288 - WEPSeed[0] = Hi8(IV16); 289 - WEPSeed[1] = (Hi8(IV16) | 0x20) & 0x7F; 290 - WEPSeed[2] = Lo8(IV16); 291 - WEPSeed[3] = Lo8((PPK[5] ^ Mk16_le((u16 *) &TK[0])) >> 1); 292 - 293 - #ifdef __BIG_ENDIAN 294 - { 295 - int i; 296 - for (i = 0; i < 6; i++) 297 - PPK[i] = (PPK[i] << 8) | (PPK[i] >> 8); 298 - } 299 - #endif 300 - } 301 - 302 - static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv) 303 - { 304 - struct ieee80211_tkip_data *tkey = priv; 305 - struct blkcipher_desc desc = {.tfm = tkey->tx_tfm_arc4}; 306 - int len; 307 - u8 *pos; 308 - struct ieee80211_hdr_4addr *hdr; 309 - u8 rc4key[16], *icv; 310 - u32 crc; 311 - struct scatterlist sg; 312 - int ret; 313 - 314 - ret = 0; 315 - if (skb_headroom(skb) < 8 || skb_tailroom(skb) < 4 || 316 - skb->len < hdr_len) 317 - return -1; 318 - 319 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 320 - 321 - if (!tkey->tx_phase1_done) { 322 - tkip_mixing_phase1(tkey->tx_ttak, tkey->key, hdr->addr2, 323 - tkey->tx_iv32); 324 - tkey->tx_phase1_done = 1; 325 - } 326 - tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak, tkey->tx_iv16); 327 - 328 - len = skb->len - hdr_len; 329 - pos = skb_push(skb, 8); 330 - memmove(pos, pos + 8, hdr_len); 331 - pos += hdr_len; 332 - 333 - *pos++ = rc4key[0]; 334 - *pos++ = rc4key[1]; 335 - *pos++ = rc4key[2]; 336 - *pos++ = (tkey->key_idx << 6) | (1 << 5) /* Ext IV included */; 337 - *pos++ = tkey->tx_iv32 & 0xff; 338 - *pos++ = (tkey->tx_iv32 >> 8) & 0xff; 339 - *pos++ = (tkey->tx_iv32 >> 16) & 0xff; 340 - *pos++ = (tkey->tx_iv32 >> 24) & 0xff; 341 - 342 - icv = skb_put(skb, 4); 343 - crc = ~crc32_le(~0, pos, len); 344 - icv[0] = crc; 345 - icv[1] = crc >> 8; 346 - icv[2] = crc >> 16; 347 - icv[3] = crc >> 24; 348 - crypto_blkcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16); 349 - sg_init_one(&sg, pos, len + 4); 350 - ret = crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4); 351 - 352 - tkey->tx_iv16++; 353 - if (tkey->tx_iv16 == 0) { 354 - tkey->tx_phase1_done = 0; 355 - tkey->tx_iv32++; 356 - } 357 - return ret; 358 - } 359 - 360 - static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) 361 - { 362 - struct ieee80211_tkip_data *tkey = priv; 363 - struct blkcipher_desc desc = { .tfm = tkey->rx_tfm_arc4 }; 364 - u8 keyidx, *pos; 365 - u32 iv32; 366 - u16 iv16; 367 - struct ieee80211_hdr_4addr *hdr; 368 - u8 icv[4]; 369 - u32 crc; 370 - struct scatterlist sg; 371 - u8 rc4key[16]; 372 - int plen; 373 - 374 - if (skb->len < hdr_len + 8 + 4) 375 - return -1; 376 - 377 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 378 - pos = skb->data + hdr_len; 379 - keyidx = pos[3]; 380 - if (!(keyidx & (1 << 5))) { 381 - if (net_ratelimit()) { 382 - printk(KERN_DEBUG "TKIP: received packet without ExtIV" 383 - " flag from %pM\n", hdr->addr2); 384 - } 385 - return -2; 386 - } 387 - keyidx >>= 6; 388 - if (tkey->key_idx != keyidx) { 389 - printk(KERN_DEBUG "TKIP: RX tkey->key_idx=%d frame " 390 - "keyidx=%d priv=%p\n", tkey->key_idx, keyidx, priv); 391 - return -6; 392 - } 393 - if (!tkey->key_set) { 394 - if (net_ratelimit()) { 395 - printk(KERN_DEBUG "TKIP: received packet from %pM" 396 - " with keyid=%d that does not have a configured" 397 - " key\n", hdr->addr2, keyidx); 398 - } 399 - return -3; 400 - } 401 - iv16 = (pos[0] << 8) | pos[2]; 402 - iv32 = pos[4] | (pos[5] << 8) | (pos[6] << 16) | (pos[7] << 24); 403 - pos += 8; 404 - 405 - if (iv32 < tkey->rx_iv32 || 406 - (iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16)) { 407 - if (net_ratelimit()) { 408 - printk(KERN_DEBUG "TKIP: replay detected: STA=%pM" 409 - " previous TSC %08x%04x received TSC " 410 - "%08x%04x\n", hdr->addr2, 411 - tkey->rx_iv32, tkey->rx_iv16, iv32, iv16); 412 - } 413 - tkey->dot11RSNAStatsTKIPReplays++; 414 - return -4; 415 - } 416 - 417 - if (iv32 != tkey->rx_iv32 || !tkey->rx_phase1_done) { 418 - tkip_mixing_phase1(tkey->rx_ttak, tkey->key, hdr->addr2, iv32); 419 - tkey->rx_phase1_done = 1; 420 - } 421 - tkip_mixing_phase2(rc4key, tkey->key, tkey->rx_ttak, iv16); 422 - 423 - plen = skb->len - hdr_len - 12; 424 - crypto_blkcipher_setkey(tkey->rx_tfm_arc4, rc4key, 16); 425 - sg_init_one(&sg, pos, plen + 4); 426 - if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) { 427 - if (net_ratelimit()) { 428 - printk(KERN_DEBUG ": TKIP: failed to decrypt " 429 - "received packet from %pM\n", 430 - hdr->addr2); 431 - } 432 - return -7; 433 - } 434 - 435 - crc = ~crc32_le(~0, pos, plen); 436 - icv[0] = crc; 437 - icv[1] = crc >> 8; 438 - icv[2] = crc >> 16; 439 - icv[3] = crc >> 24; 440 - if (memcmp(icv, pos + plen, 4) != 0) { 441 - if (iv32 != tkey->rx_iv32) { 442 - /* Previously cached Phase1 result was already lost, so 443 - * it needs to be recalculated for the next packet. */ 444 - tkey->rx_phase1_done = 0; 445 - } 446 - if (net_ratelimit()) { 447 - printk(KERN_DEBUG "TKIP: ICV error detected: STA=" 448 - "%pM\n", hdr->addr2); 449 - } 450 - tkey->dot11RSNAStatsTKIPICVErrors++; 451 - return -5; 452 - } 453 - 454 - /* Update real counters only after Michael MIC verification has 455 - * completed */ 456 - tkey->rx_iv32_new = iv32; 457 - tkey->rx_iv16_new = iv16; 458 - 459 - /* Remove IV and ICV */ 460 - memmove(skb->data + 8, skb->data, hdr_len); 461 - skb_pull(skb, 8); 462 - skb_trim(skb, skb->len - 4); 463 - 464 - return keyidx; 465 - } 466 - 467 - static int michael_mic(struct crypto_hash *tfm_michael, u8 *key, u8 *hdr, 468 - u8 *data, size_t data_len, u8 *mic) 469 - { 470 - struct hash_desc desc; 471 - struct scatterlist sg[2]; 472 - 473 - if (tfm_michael == NULL) { 474 - printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n"); 475 - return -1; 476 - } 477 - 478 - sg_init_table(sg, 2); 479 - sg_set_buf(&sg[0], hdr, 16); 480 - sg_set_buf(&sg[1], data, data_len); 481 - 482 - if (crypto_hash_setkey(tfm_michael, key, 8)) 483 - return -1; 484 - 485 - desc.tfm = tfm_michael; 486 - desc.flags = 0; 487 - return crypto_hash_digest(&desc, sg, data_len + 16, mic); 488 - } 489 - 490 - static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr) 491 - { 492 - struct ieee80211_hdr_4addr *hdr11; 493 - 494 - hdr11 = (struct ieee80211_hdr_4addr *)skb->data; 495 - switch (le16_to_cpu(hdr11->frame_ctl) & 496 - (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) { 497 - case IEEE80211_FCTL_TODS: 498 - memcpy(hdr, hdr11->addr3, ETH_ALEN); /* DA */ 499 - memcpy(hdr + ETH_ALEN, hdr11->addr2, ETH_ALEN); /* SA */ 500 - break; 501 - case IEEE80211_FCTL_FROMDS: 502 - memcpy(hdr, hdr11->addr1, ETH_ALEN); /* DA */ 503 - memcpy(hdr + ETH_ALEN, hdr11->addr3, ETH_ALEN); /* SA */ 504 - break; 505 - case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS: 506 - memcpy(hdr, hdr11->addr3, ETH_ALEN); /* DA */ 507 - memcpy(hdr + ETH_ALEN, hdr11->addr4, ETH_ALEN); /* SA */ 508 - break; 509 - case 0: 510 - memcpy(hdr, hdr11->addr1, ETH_ALEN); /* DA */ 511 - memcpy(hdr + ETH_ALEN, hdr11->addr2, ETH_ALEN); /* SA */ 512 - break; 513 - } 514 - 515 - hdr[12] = 0; /* priority */ 516 - 517 - hdr[13] = hdr[14] = hdr[15] = 0; /* reserved */ 518 - } 519 - 520 - 521 - static int ieee80211_michael_mic_add(struct sk_buff *skb, int hdr_len, 522 - void *priv) 523 - { 524 - struct ieee80211_tkip_data *tkey = priv; 525 - u8 *pos; 526 - struct ieee80211_hdr_4addr *hdr; 527 - 528 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 529 - 530 - if (skb_tailroom(skb) < 8 || skb->len < hdr_len) { 531 - printk(KERN_DEBUG "Invalid packet for Michael MIC add " 532 - "(tailroom=%d hdr_len=%d skb->len=%d)\n", 533 - skb_tailroom(skb), hdr_len, skb->len); 534 - return -1; 535 - } 536 - 537 - michael_mic_hdr(skb, tkey->tx_hdr); 538 - 539 - if (IEEE80211_QOS_HAS_SEQ(le16_to_cpu(hdr->frame_ctl))) 540 - tkey->tx_hdr[12] = *(skb->data + hdr_len - 2) & 0x07; 541 - 542 - pos = skb_put(skb, 8); 543 - 544 - if (michael_mic(tkey->tx_tfm_michael, &tkey->key[16], tkey->tx_hdr, 545 - skb->data + hdr_len, skb->len - 8 - hdr_len, pos)) 546 - return -1; 547 - 548 - return 0; 549 - } 550 - 551 - static void ieee80211_michael_mic_failure(struct net_device *dev, 552 - struct ieee80211_hdr_4addr *hdr, 553 - int keyidx) 554 - { 555 - union iwreq_data wrqu; 556 - struct iw_michaelmicfailure ev; 557 - 558 - /* TODO: needed parameters: count, keyid, key type, TSC */ 559 - memset(&ev, 0, sizeof(ev)); 560 - ev.flags = keyidx & IW_MICFAILURE_KEY_ID; 561 - if (hdr->addr1[0] & 0x01) 562 - ev.flags |= IW_MICFAILURE_GROUP; 563 - else 564 - ev.flags |= IW_MICFAILURE_PAIRWISE; 565 - ev.src_addr.sa_family = ARPHRD_ETHER; 566 - memcpy(ev.src_addr.sa_data, hdr->addr2, ETH_ALEN); 567 - memset(&wrqu, 0, sizeof(wrqu)); 568 - wrqu.data.length = sizeof(ev); 569 - wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, (char *) &ev); 570 - } 571 - 572 - static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx, 573 - int hdr_len, void *priv) 574 - { 575 - struct ieee80211_tkip_data *tkey = priv; 576 - u8 mic[8]; 577 - struct ieee80211_hdr_4addr *hdr; 578 - 579 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 580 - 581 - if (!tkey->key_set) 582 - return -1; 583 - 584 - michael_mic_hdr(skb, tkey->rx_hdr); 585 - if (IEEE80211_QOS_HAS_SEQ(le16_to_cpu(hdr->frame_ctl))) 586 - tkey->rx_hdr[12] = *(skb->data + hdr_len - 2) & 0x07; 587 - 588 - if (michael_mic(tkey->rx_tfm_michael, &tkey->key[24], tkey->rx_hdr, 589 - skb->data + hdr_len, skb->len - 8 - hdr_len, mic)) 590 - return -1; 591 - 592 - if (memcmp(mic, skb->data + skb->len - 8, 8) != 0) { 593 - struct ieee80211_hdr_4addr *hdr; 594 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 595 - printk(KERN_DEBUG "%s: Michael MIC verification failed for " 596 - "MSDU from %pM keyidx=%d\n", 597 - skb->dev ? skb->dev->name : "N/A", hdr->addr2, 598 - keyidx); 599 - if (skb->dev) 600 - ieee80211_michael_mic_failure(skb->dev, hdr, keyidx); 601 - tkey->dot11RSNAStatsTKIPLocalMICFailures++; 602 - return -1; 603 - } 604 - 605 - /* Update TSC counters for RX now that the packet verification has 606 - * completed. */ 607 - tkey->rx_iv32 = tkey->rx_iv32_new; 608 - tkey->rx_iv16 = tkey->rx_iv16_new; 609 - 610 - skb_trim(skb, skb->len - 8); 611 - 612 - return 0; 613 - } 614 - 615 - 616 - static int ieee80211_tkip_set_key(void *key, int len, u8 *seq, void *priv) 617 - { 618 - struct ieee80211_tkip_data *tkey = priv; 619 - int keyidx; 620 - struct crypto_hash *tfm = tkey->tx_tfm_michael; 621 - struct crypto_blkcipher *tfm2 = tkey->tx_tfm_arc4; 622 - struct crypto_hash *tfm3 = tkey->rx_tfm_michael; 623 - struct crypto_blkcipher *tfm4 = tkey->rx_tfm_arc4; 624 - 625 - keyidx = tkey->key_idx; 626 - memset(tkey, 0, sizeof(*tkey)); 627 - tkey->key_idx = keyidx; 628 - 629 - tkey->tx_tfm_michael = tfm; 630 - tkey->tx_tfm_arc4 = tfm2; 631 - tkey->rx_tfm_michael = tfm3; 632 - tkey->rx_tfm_arc4 = tfm4; 633 - 634 - if (len == TKIP_KEY_LEN) { 635 - memcpy(tkey->key, key, TKIP_KEY_LEN); 636 - tkey->key_set = 1; 637 - tkey->tx_iv16 = 1; /* TSC is initialized to 1 */ 638 - if (seq) { 639 - tkey->rx_iv32 = (seq[5] << 24) | (seq[4] << 16) | 640 - (seq[3] << 8) | seq[2]; 641 - tkey->rx_iv16 = (seq[1] << 8) | seq[0]; 642 - } 643 - } else if (len == 0) 644 - tkey->key_set = 0; 645 - else 646 - return -1; 647 - 648 - return 0; 649 - } 650 - 651 - 652 - static int ieee80211_tkip_get_key(void *key, int len, u8 *seq, void *priv) 653 - { 654 - struct ieee80211_tkip_data *tkey = priv; 655 - 656 - if (len < TKIP_KEY_LEN) 657 - return -1; 658 - 659 - if (!tkey->key_set) 660 - return 0; 661 - memcpy(key, tkey->key, TKIP_KEY_LEN); 662 - 663 - if (seq) { 664 - /* Return the sequence number of the last transmitted frame. */ 665 - u16 iv16 = tkey->tx_iv16; 666 - u32 iv32 = tkey->tx_iv32; 667 - if (iv16 == 0) 668 - iv32--; 669 - iv16--; 670 - seq[0] = tkey->tx_iv16; 671 - seq[1] = tkey->tx_iv16 >> 8; 672 - seq[2] = tkey->tx_iv32; 673 - seq[3] = tkey->tx_iv32 >> 8; 674 - seq[4] = tkey->tx_iv32 >> 16; 675 - seq[5] = tkey->tx_iv32 >> 24; 676 - } 677 - 678 - return TKIP_KEY_LEN; 679 - } 680 - 681 - 682 - static char *ieee80211_tkip_print_stats(char *p, void *priv) 683 - { 684 - struct ieee80211_tkip_data *tkip = priv; 685 - p += sprintf(p, "key[%d] alg=TKIP key_set=%d " 686 - "tx_pn=%02x%02x%02x%02x%02x%02x " 687 - "rx_pn=%02x%02x%02x%02x%02x%02x " 688 - "replays=%d icv_errors=%d local_mic_failures=%d\n", 689 - tkip->key_idx, tkip->key_set, 690 - (tkip->tx_iv32 >> 24) & 0xff, 691 - (tkip->tx_iv32 >> 16) & 0xff, 692 - (tkip->tx_iv32 >> 8) & 0xff, 693 - tkip->tx_iv32 & 0xff, 694 - (tkip->tx_iv16 >> 8) & 0xff, 695 - tkip->tx_iv16 & 0xff, 696 - (tkip->rx_iv32 >> 24) & 0xff, 697 - (tkip->rx_iv32 >> 16) & 0xff, 698 - (tkip->rx_iv32 >> 8) & 0xff, 699 - tkip->rx_iv32 & 0xff, 700 - (tkip->rx_iv16 >> 8) & 0xff, 701 - tkip->rx_iv16 & 0xff, 702 - tkip->dot11RSNAStatsTKIPReplays, 703 - tkip->dot11RSNAStatsTKIPICVErrors, 704 - tkip->dot11RSNAStatsTKIPLocalMICFailures); 705 - return p; 706 - } 707 - 708 - 709 - static struct ieee80211_crypto_ops ieee80211_crypt_tkip = { 710 - .name = "TKIP", 711 - .init = ieee80211_tkip_init, 712 - .deinit = ieee80211_tkip_deinit, 713 - .encrypt_mpdu = ieee80211_tkip_encrypt, 714 - .decrypt_mpdu = ieee80211_tkip_decrypt, 715 - .encrypt_msdu = ieee80211_michael_mic_add, 716 - .decrypt_msdu = ieee80211_michael_mic_verify, 717 - .set_key = ieee80211_tkip_set_key, 718 - .get_key = ieee80211_tkip_get_key, 719 - .print_stats = ieee80211_tkip_print_stats, 720 - .extra_prefix_len = 4 + 4, /* IV + ExtIV */ 721 - .extra_postfix_len = 8 + 4, /* MIC + ICV */ 722 - .owner = THIS_MODULE, 723 - }; 724 - 725 - 726 - int ieee80211_crypto_tkip_init(void) 727 - { 728 - return ieee80211_register_crypto_ops(&ieee80211_crypt_tkip); 729 - } 730 - 731 - 732 - void ieee80211_crypto_tkip_exit(void) 733 - { 734 - ieee80211_unregister_crypto_ops(&ieee80211_crypt_tkip); 735 - } 736 - 737 - 738 - void ieee80211_tkip_null(void) 739 - { 740 - }
-277
drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_wep.c
··· 1 - /* 2 - * Host AP crypt: host-based WEP encryption implementation for Host AP driver 3 - * 4 - * Copyright (c) 2002-2004, Jouni Malinen <jkmaline@cc.hut.fi> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. See README and COPYING for 9 - * more details. 10 - */ 11 - 12 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13 - 14 - #include <linux/module.h> 15 - #include <linux/slab.h> 16 - #include <linux/random.h> 17 - #include <linux/skbuff.h> 18 - #include <linux/string.h> 19 - 20 - #include "ieee80211.h" 21 - 22 - #include <linux/crypto.h> 23 - #include <linux/scatterlist.h> 24 - #include <linux/crc32.h> 25 - 26 - MODULE_AUTHOR("Jouni Malinen"); 27 - MODULE_DESCRIPTION("Host AP crypt: WEP"); 28 - MODULE_LICENSE("GPL"); 29 - 30 - struct prism2_wep_data { 31 - u32 iv; 32 - #define WEP_KEY_LEN 13 33 - u8 key[WEP_KEY_LEN + 1]; 34 - u8 key_len; 35 - u8 key_idx; 36 - struct crypto_blkcipher *tx_tfm; 37 - struct crypto_blkcipher *rx_tfm; 38 - }; 39 - 40 - static void *prism2_wep_init(int keyidx) 41 - { 42 - struct prism2_wep_data *priv; 43 - 44 - priv = kzalloc(sizeof(*priv), GFP_ATOMIC); 45 - if (priv == NULL) 46 - goto fail; 47 - priv->key_idx = keyidx; 48 - priv->tx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); 49 - if (IS_ERR(priv->tx_tfm)) { 50 - pr_debug("could not allocate crypto API arc4\n"); 51 - priv->tx_tfm = NULL; 52 - goto fail; 53 - } 54 - priv->rx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); 55 - if (IS_ERR(priv->rx_tfm)) { 56 - pr_debug("could not allocate crypto API arc4\n"); 57 - priv->rx_tfm = NULL; 58 - goto fail; 59 - } 60 - 61 - /* start WEP IV from a random value */ 62 - get_random_bytes(&priv->iv, 4); 63 - 64 - return priv; 65 - 66 - fail: 67 - if (priv) { 68 - if (priv->tx_tfm) 69 - crypto_free_blkcipher(priv->tx_tfm); 70 - if (priv->rx_tfm) 71 - crypto_free_blkcipher(priv->rx_tfm); 72 - kfree(priv); 73 - } 74 - 75 - return NULL; 76 - } 77 - 78 - static void prism2_wep_deinit(void *priv) 79 - { 80 - struct prism2_wep_data *_priv = priv; 81 - 82 - if (_priv) { 83 - if (_priv->tx_tfm) 84 - crypto_free_blkcipher(_priv->tx_tfm); 85 - if (_priv->rx_tfm) 86 - crypto_free_blkcipher(_priv->rx_tfm); 87 - } 88 - 89 - kfree(priv); 90 - } 91 - 92 - /* Perform WEP encryption on given skb that has at least 4 bytes of headroom 93 - * for IV and 4 bytes of tailroom for ICV. Both IV and ICV will be transmitted, 94 - * so the payload length increases with 8 bytes. 95 - * 96 - * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data)) 97 - */ 98 - static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) 99 - { 100 - struct prism2_wep_data *wep = priv; 101 - struct blkcipher_desc desc = { .tfm = wep->tx_tfm }; 102 - u32 klen, len; 103 - u8 key[WEP_KEY_LEN + 3]; 104 - u8 *pos; 105 - u32 crc; 106 - u8 *icv; 107 - struct scatterlist sg; 108 - 109 - if (skb_headroom(skb) < 4 || skb_tailroom(skb) < 4 || 110 - skb->len < hdr_len) 111 - return -1; 112 - 113 - len = skb->len - hdr_len; 114 - pos = skb_push(skb, 4); 115 - memmove(pos, pos + 4, hdr_len); 116 - pos += hdr_len; 117 - 118 - klen = 3 + wep->key_len; 119 - 120 - wep->iv++; 121 - 122 - /* Fluhrer, Mantin, and Shamir have reported weaknesses in the key 123 - * scheduling algorithm of RC4. At least IVs (KeyByte + 3, 0xff, N) 124 - * can be used to speedup attacks, so avoid using them. */ 125 - if ((wep->iv & 0xff00) == 0xff00) { 126 - u8 B = (wep->iv >> 16) & 0xff; 127 - if (B >= 3 && B < klen) 128 - wep->iv += 0x0100; 129 - } 130 - 131 - /* Prepend 24-bit IV to RC4 key and TX frame */ 132 - *pos++ = key[0] = (wep->iv >> 16) & 0xff; 133 - *pos++ = key[1] = (wep->iv >> 8) & 0xff; 134 - *pos++ = key[2] = wep->iv & 0xff; 135 - *pos++ = wep->key_idx << 6; 136 - 137 - /* Copy rest of the WEP key (the secret part) */ 138 - memcpy(key + 3, wep->key, wep->key_len); 139 - 140 - /* Append little-endian CRC32 and encrypt it to produce ICV */ 141 - crc = ~crc32_le(~0, pos, len); 142 - icv = skb_put(skb, 4); 143 - icv[0] = crc; 144 - icv[1] = crc >> 8; 145 - icv[2] = crc >> 16; 146 - icv[3] = crc >> 24; 147 - 148 - crypto_blkcipher_setkey(wep->tx_tfm, key, klen); 149 - sg_init_one(&sg, pos, len + 4); 150 - 151 - return crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4); 152 - } 153 - 154 - /* Perform WEP decryption on given buffer. Buffer includes whole WEP part of 155 - * the frame: IV (4 bytes), encrypted payload (including SNAP header), 156 - * ICV (4 bytes). len includes both IV and ICV. 157 - * 158 - * Returns 0 if frame was decrypted successfully and ICV was correct and -1 on 159 - * failure. If frame is OK, IV and ICV will be removed. 160 - */ 161 - static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv) 162 - { 163 - struct prism2_wep_data *wep = priv; 164 - struct blkcipher_desc desc = { .tfm = wep->rx_tfm }; 165 - u32 klen, plen; 166 - u8 key[WEP_KEY_LEN + 3]; 167 - u8 keyidx, *pos; 168 - u32 crc; 169 - u8 icv[4]; 170 - struct scatterlist sg; 171 - 172 - if (skb->len < hdr_len + 8) 173 - return -1; 174 - 175 - pos = skb->data + hdr_len; 176 - key[0] = *pos++; 177 - key[1] = *pos++; 178 - key[2] = *pos++; 179 - keyidx = *pos++ >> 6; 180 - if (keyidx != wep->key_idx) 181 - return -1; 182 - 183 - klen = 3 + wep->key_len; 184 - 185 - /* Copy rest of the WEP key (the secret part) */ 186 - memcpy(key + 3, wep->key, wep->key_len); 187 - 188 - /* Apply RC4 to data and compute CRC32 over decrypted data */ 189 - plen = skb->len - hdr_len - 8; 190 - 191 - crypto_blkcipher_setkey(wep->rx_tfm, key, klen); 192 - sg_init_one(&sg, pos, plen + 4); 193 - 194 - if (crypto_blkcipher_decrypt(&desc, &sg, &sg, plen + 4)) 195 - return -7; 196 - 197 - crc = ~crc32_le(~0, pos, plen); 198 - icv[0] = crc; 199 - icv[1] = crc >> 8; 200 - icv[2] = crc >> 16; 201 - icv[3] = crc >> 24; 202 - 203 - if (memcmp(icv, pos + plen, 4) != 0) { 204 - /* ICV mismatch - drop frame */ 205 - return -2; 206 - } 207 - 208 - /* Remove IV and ICV */ 209 - memmove(skb->data + 4, skb->data, hdr_len); 210 - skb_pull(skb, 4); 211 - skb_trim(skb, skb->len - 4); 212 - return 0; 213 - } 214 - 215 - static int prism2_wep_set_key(void *key, int len, u8 *seq, void *priv) 216 - { 217 - struct prism2_wep_data *wep = priv; 218 - 219 - if (len < 0 || len > WEP_KEY_LEN) 220 - return -1; 221 - 222 - memcpy(wep->key, key, len); 223 - wep->key_len = len; 224 - 225 - return 0; 226 - } 227 - 228 - static int prism2_wep_get_key(void *key, int len, u8 *seq, void *priv) 229 - { 230 - struct prism2_wep_data *wep = priv; 231 - 232 - if (len < wep->key_len) 233 - return -1; 234 - 235 - memcpy(key, wep->key, wep->key_len); 236 - 237 - return wep->key_len; 238 - } 239 - 240 - static char *prism2_wep_print_stats(char *p, void *priv) 241 - { 242 - struct prism2_wep_data *wep = priv; 243 - p += sprintf(p, "key[%d] alg=WEP len=%d\n", 244 - wep->key_idx, wep->key_len); 245 - return p; 246 - } 247 - 248 - static struct ieee80211_crypto_ops ieee80211_crypt_wep = { 249 - .name = "WEP", 250 - .init = prism2_wep_init, 251 - .deinit = prism2_wep_deinit, 252 - .encrypt_mpdu = prism2_wep_encrypt, 253 - .decrypt_mpdu = prism2_wep_decrypt, 254 - .encrypt_msdu = NULL, 255 - .decrypt_msdu = NULL, 256 - .set_key = prism2_wep_set_key, 257 - .get_key = prism2_wep_get_key, 258 - .print_stats = prism2_wep_print_stats, 259 - .extra_prefix_len = 4, /* IV */ 260 - .extra_postfix_len = 4, /* ICV */ 261 - .owner = THIS_MODULE, 262 - }; 263 - 264 - int ieee80211_crypto_wep_init(void) 265 - { 266 - return ieee80211_register_crypto_ops(&ieee80211_crypt_wep); 267 - } 268 - 269 - void ieee80211_crypto_wep_exit(void) 270 - { 271 - ieee80211_unregister_crypto_ops(&ieee80211_crypt_wep); 272 - } 273 - 274 - void ieee80211_wep_null(void) 275 - { 276 - return; 277 - }
-203
drivers/staging/rtl8187se/ieee80211/ieee80211_module.c
··· 1 - /******************************************************************************* 2 - 3 - Copyright(c) 2004 Intel Corporation. All rights reserved. 4 - 5 - Portions of this file are based on the WEP enablement code provided by the 6 - Host AP project hostap-drivers v0.1.3 7 - Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen 8 - <jkmaline@cc.hut.fi> 9 - Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> 10 - 11 - This program is free software; you can redistribute it and/or modify it 12 - under the terms of version 2 of the GNU General Public License as 13 - published by the Free Software Foundation. 14 - 15 - This program is distributed in the hope that it will be useful, but WITHOUT 16 - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 18 - more details. 19 - 20 - You should have received a copy of the GNU General Public License along with 21 - this program; if not, write to the Free Software Foundation, Inc., 59 22 - Temple Place - Suite 330, Boston, MA 02111-1307, USA. 23 - 24 - The full GNU General Public License is included in this distribution in the 25 - file called LICENSE. 26 - 27 - Contact Information: 28 - James P. Ketrenos <ipw2100-admin@linux.intel.com> 29 - Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 30 - 31 - *******************************************************************************/ 32 - 33 - #include <linux/compiler.h> 34 - //#include <linux/config.h> 35 - #include <linux/errno.h> 36 - #include <linux/if_arp.h> 37 - #include <linux/in6.h> 38 - #include <linux/in.h> 39 - #include <linux/ip.h> 40 - #include <linux/kernel.h> 41 - #include <linux/module.h> 42 - #include <linux/netdevice.h> 43 - #include <linux/pci.h> 44 - #include <linux/proc_fs.h> 45 - #include <linux/skbuff.h> 46 - #include <linux/slab.h> 47 - #include <linux/tcp.h> 48 - #include <linux/types.h> 49 - #include <linux/wireless.h> 50 - #include <linux/etherdevice.h> 51 - #include <linux/uaccess.h> 52 - #include <net/arp.h> 53 - #include <net/net_namespace.h> 54 - 55 - #include "ieee80211.h" 56 - 57 - MODULE_DESCRIPTION("802.11 data/management/control stack"); 58 - MODULE_AUTHOR("Copyright (C) 2004 Intel Corporation <jketreno@linux.intel.com>"); 59 - MODULE_LICENSE("GPL"); 60 - 61 - #define DRV_NAME "ieee80211" 62 - 63 - static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee) 64 - { 65 - if (ieee->networks) 66 - return 0; 67 - 68 - ieee->networks = kcalloc( 69 - MAX_NETWORK_COUNT, sizeof(struct ieee80211_network), 70 - GFP_KERNEL); 71 - if (!ieee->networks) 72 - return -ENOMEM; 73 - 74 - return 0; 75 - } 76 - 77 - static inline void ieee80211_networks_free(struct ieee80211_device *ieee) 78 - { 79 - if (!ieee->networks) 80 - return; 81 - kfree(ieee->networks); 82 - ieee->networks = NULL; 83 - } 84 - 85 - static inline void ieee80211_networks_initialize(struct ieee80211_device *ieee) 86 - { 87 - int i; 88 - 89 - INIT_LIST_HEAD(&ieee->network_free_list); 90 - INIT_LIST_HEAD(&ieee->network_list); 91 - for (i = 0; i < MAX_NETWORK_COUNT; i++) 92 - list_add_tail(&ieee->networks[i].list, &ieee->network_free_list); 93 - } 94 - 95 - 96 - struct net_device *alloc_ieee80211(int sizeof_priv) 97 - { 98 - struct ieee80211_device *ieee; 99 - struct net_device *dev; 100 - int i, err; 101 - 102 - IEEE80211_DEBUG_INFO("Initializing...\n"); 103 - 104 - dev = alloc_etherdev(sizeof(struct ieee80211_device) + sizeof_priv); 105 - if (!dev) { 106 - IEEE80211_ERROR("Unable to network device.\n"); 107 - goto failed; 108 - } 109 - ieee = netdev_priv(dev); 110 - 111 - ieee->dev = dev; 112 - 113 - err = ieee80211_networks_allocate(ieee); 114 - if (err) { 115 - IEEE80211_ERROR("Unable to allocate beacon storage: %d\n", 116 - err); 117 - goto failed; 118 - } 119 - ieee80211_networks_initialize(ieee); 120 - 121 - /* Default fragmentation threshold is maximum payload size */ 122 - ieee->fts = DEFAULT_FTS; 123 - ieee->scan_age = DEFAULT_MAX_SCAN_AGE; 124 - ieee->open_wep = 1; 125 - 126 - /* Default to enabling full open WEP with host based encrypt/decrypt */ 127 - ieee->host_encrypt = 1; 128 - ieee->host_decrypt = 1; 129 - ieee->ieee802_1x = 1; /* Default to supporting 802.1x */ 130 - 131 - INIT_LIST_HEAD(&ieee->crypt_deinit_list); 132 - init_timer(&ieee->crypt_deinit_timer); 133 - ieee->crypt_deinit_timer.data = (unsigned long)ieee; 134 - ieee->crypt_deinit_timer.function = ieee80211_crypt_deinit_handler; 135 - 136 - spin_lock_init(&ieee->lock); 137 - spin_lock_init(&ieee->wpax_suitlist_lock); 138 - 139 - ieee->wpax_type_set = 0; 140 - ieee->wpa_enabled = 0; 141 - ieee->tkip_countermeasures = 0; 142 - ieee->drop_unencrypted = 0; 143 - ieee->privacy_invoked = 0; 144 - ieee->ieee802_1x = 1; 145 - ieee->raw_tx = 0; 146 - 147 - ieee80211_softmac_init(ieee); 148 - 149 - for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++) 150 - INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]); 151 - 152 - for (i = 0; i < 17; i++) { 153 - ieee->last_rxseq_num[i] = -1; 154 - ieee->last_rxfrag_num[i] = -1; 155 - ieee->last_packet_time[i] = 0; 156 - } 157 - //These function were added to load crypte module autoly 158 - ieee80211_tkip_null(); 159 - ieee80211_wep_null(); 160 - ieee80211_ccmp_null(); 161 - return dev; 162 - 163 - failed: 164 - if (dev) 165 - free_netdev(dev); 166 - return NULL; 167 - } 168 - 169 - 170 - void free_ieee80211(struct net_device *dev) 171 - { 172 - struct ieee80211_device *ieee = netdev_priv(dev); 173 - 174 - int i; 175 - struct list_head *p, *q; 176 - 177 - 178 - ieee80211_softmac_free(ieee); 179 - del_timer_sync(&ieee->crypt_deinit_timer); 180 - ieee80211_crypt_deinit_entries(ieee, 1); 181 - 182 - for (i = 0; i < WEP_KEYS; i++) { 183 - struct ieee80211_crypt_data *crypt = ieee->crypt[i]; 184 - if (crypt) { 185 - if (crypt->ops) 186 - crypt->ops->deinit(crypt->priv); 187 - kfree(crypt); 188 - ieee->crypt[i] = NULL; 189 - } 190 - } 191 - 192 - ieee80211_networks_free(ieee); 193 - 194 - for (i = 0; i < IEEE_IBSS_MAC_HASH_SIZE; i++) { 195 - list_for_each_safe(p, q, &ieee->ibss_mac_hash[i]) { 196 - kfree(list_entry(p, struct ieee_ibss_seq, list)); 197 - list_del(p); 198 - } 199 - } 200 - 201 - 202 - free_netdev(dev); 203 - }
-1486
drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c
··· 1 - /* 2 - * Original code based Host AP (software wireless LAN access point) driver 3 - * for Intersil Prism2/2.5/3 - hostap.o module, common routines 4 - * 5 - * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen 6 - * <jkmaline@cc.hut.fi> 7 - * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> 8 - * Copyright (c) 2004, Intel Corporation 9 - * 10 - * This program is free software; you can redistribute it and/or modify 11 - * it under the terms of the GNU General Public License version 2 as 12 - * published by the Free Software Foundation. See README and COPYING for 13 - * more details. 14 - ****************************************************************************** 15 - 16 - Few modifications for Realtek's Wi-Fi drivers by 17 - Andrea Merello <andrea.merello@gmail.com> 18 - 19 - A special thanks goes to Realtek for their support ! 20 - 21 - ******************************************************************************/ 22 - 23 - 24 - #include <linux/compiler.h> 25 - //#include <linux/config.h> 26 - #include <linux/errno.h> 27 - #include <linux/if_arp.h> 28 - #include <linux/in6.h> 29 - #include <linux/in.h> 30 - #include <linux/ip.h> 31 - #include <linux/kernel.h> 32 - #include <linux/module.h> 33 - #include <linux/netdevice.h> 34 - #include <linux/pci.h> 35 - #include <linux/proc_fs.h> 36 - #include <linux/skbuff.h> 37 - #include <linux/slab.h> 38 - #include <linux/tcp.h> 39 - #include <linux/types.h> 40 - #include <linux/wireless.h> 41 - #include <linux/etherdevice.h> 42 - #include <linux/uaccess.h> 43 - #include <linux/ctype.h> 44 - 45 - #include "ieee80211.h" 46 - #include "dot11d.h" 47 - static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee, 48 - struct sk_buff *skb, 49 - struct ieee80211_rx_stats *rx_stats) 50 - { 51 - struct ieee80211_hdr_4addr *hdr = 52 - (struct ieee80211_hdr_4addr *)skb->data; 53 - u16 fc = le16_to_cpu(hdr->frame_ctl); 54 - 55 - skb->dev = ieee->dev; 56 - skb_reset_mac_header(skb); 57 - skb_pull(skb, ieee80211_get_hdrlen(fc)); 58 - skb->pkt_type = PACKET_OTHERHOST; 59 - skb->protocol = __constant_htons(ETH_P_80211_RAW); 60 - memset(skb->cb, 0, sizeof(skb->cb)); 61 - netif_rx(skb); 62 - } 63 - 64 - 65 - /* Called only as a tasklet (software IRQ) */ 66 - static struct ieee80211_frag_entry * 67 - ieee80211_frag_cache_find(struct ieee80211_device *ieee, unsigned int seq, 68 - unsigned int frag, u8 tid, u8 *src, u8 *dst) 69 - { 70 - struct ieee80211_frag_entry *entry; 71 - int i; 72 - 73 - for (i = 0; i < IEEE80211_FRAG_CACHE_LEN; i++) { 74 - entry = &ieee->frag_cache[tid][i]; 75 - if (entry->skb != NULL && 76 - time_after(jiffies, entry->first_frag_time + 2 * HZ)) { 77 - IEEE80211_DEBUG_FRAG( 78 - "expiring fragment cache entry " 79 - "seq=%u last_frag=%u\n", 80 - entry->seq, entry->last_frag); 81 - dev_kfree_skb_any(entry->skb); 82 - entry->skb = NULL; 83 - } 84 - 85 - if (entry->skb != NULL && entry->seq == seq && 86 - (entry->last_frag + 1 == frag || frag == -1) && 87 - memcmp(entry->src_addr, src, ETH_ALEN) == 0 && 88 - memcmp(entry->dst_addr, dst, ETH_ALEN) == 0) 89 - return entry; 90 - } 91 - 92 - return NULL; 93 - } 94 - 95 - /* Called only as a tasklet (software IRQ) */ 96 - static struct sk_buff * 97 - ieee80211_frag_cache_get(struct ieee80211_device *ieee, 98 - struct ieee80211_hdr_4addr *hdr) 99 - { 100 - struct sk_buff *skb = NULL; 101 - u16 fc = le16_to_cpu(hdr->frame_ctl); 102 - u16 sc = le16_to_cpu(hdr->seq_ctl); 103 - unsigned int frag = WLAN_GET_SEQ_FRAG(sc); 104 - unsigned int seq = WLAN_GET_SEQ_SEQ(sc); 105 - struct ieee80211_frag_entry *entry; 106 - struct ieee80211_hdr_3addrqos *hdr_3addrqos; 107 - struct ieee80211_hdr_4addrqos *hdr_4addrqos; 108 - u8 tid; 109 - 110 - if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) { 111 - hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr; 112 - tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QOS_TID; 113 - tid = UP2AC(tid); 114 - tid++; 115 - } else if (IEEE80211_QOS_HAS_SEQ(fc)) { 116 - hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr; 117 - tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QOS_TID; 118 - tid = UP2AC(tid); 119 - tid++; 120 - } else { 121 - tid = 0; 122 - } 123 - 124 - if (frag == 0) { 125 - /* Reserve enough space to fit maximum frame length */ 126 - skb = dev_alloc_skb(ieee->dev->mtu + 127 - sizeof(struct ieee80211_hdr_4addr) + 128 - 8 /* LLC */ + 129 - 2 /* alignment */ + 130 - 8 /* WEP */ + 131 - ETH_ALEN /* WDS */ + 132 - (IEEE80211_QOS_HAS_SEQ(fc) ? 2 : 0) /* QOS Control */); 133 - if (skb == NULL) 134 - return NULL; 135 - 136 - entry = &ieee->frag_cache[tid][ieee->frag_next_idx[tid]]; 137 - ieee->frag_next_idx[tid]++; 138 - if (ieee->frag_next_idx[tid] >= IEEE80211_FRAG_CACHE_LEN) 139 - ieee->frag_next_idx[tid] = 0; 140 - 141 - if (entry->skb != NULL) 142 - dev_kfree_skb_any(entry->skb); 143 - 144 - entry->first_frag_time = jiffies; 145 - entry->seq = seq; 146 - entry->last_frag = frag; 147 - entry->skb = skb; 148 - memcpy(entry->src_addr, hdr->addr2, ETH_ALEN); 149 - memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN); 150 - } else { 151 - /* received a fragment of a frame for which the head fragment 152 - * should have already been received */ 153 - entry = ieee80211_frag_cache_find(ieee, seq, frag, tid, hdr->addr2, 154 - hdr->addr1); 155 - if (entry != NULL) { 156 - entry->last_frag = frag; 157 - skb = entry->skb; 158 - } 159 - } 160 - 161 - return skb; 162 - } 163 - 164 - 165 - /* Called only as a tasklet (software IRQ) */ 166 - static int ieee80211_frag_cache_invalidate(struct ieee80211_device *ieee, 167 - struct ieee80211_hdr_4addr *hdr) 168 - { 169 - u16 fc = le16_to_cpu(hdr->frame_ctl); 170 - u16 sc = le16_to_cpu(hdr->seq_ctl); 171 - unsigned int seq = WLAN_GET_SEQ_SEQ(sc); 172 - struct ieee80211_frag_entry *entry; 173 - struct ieee80211_hdr_3addrqos *hdr_3addrqos; 174 - struct ieee80211_hdr_4addrqos *hdr_4addrqos; 175 - u8 tid; 176 - 177 - if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) { 178 - hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)hdr; 179 - tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QOS_TID; 180 - tid = UP2AC(tid); 181 - tid++; 182 - } else if (IEEE80211_QOS_HAS_SEQ(fc)) { 183 - hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)hdr; 184 - tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QOS_TID; 185 - tid = UP2AC(tid); 186 - tid++; 187 - } else { 188 - tid = 0; 189 - } 190 - 191 - entry = ieee80211_frag_cache_find(ieee, seq, -1, tid, hdr->addr2, 192 - hdr->addr1); 193 - 194 - if (entry == NULL) { 195 - IEEE80211_DEBUG_FRAG( 196 - "could not invalidate fragment cache " 197 - "entry (seq=%u)\n", seq); 198 - return -1; 199 - } 200 - 201 - entry->skb = NULL; 202 - return 0; 203 - } 204 - 205 - 206 - 207 - /* ieee80211_rx_frame_mgtmt 208 - * 209 - * Responsible for handling management control frames 210 - * 211 - * Called by ieee80211_rx */ 212 - static inline int 213 - ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb, 214 - struct ieee80211_rx_stats *rx_stats, u16 type, 215 - u16 stype) 216 - { 217 - struct ieee80211_hdr_4addr *hdr; 218 - 219 - // cheat the the hdr type 220 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 221 - 222 - /* On the struct stats definition there is written that 223 - * this is not mandatory.... but seems that the probe 224 - * response parser uses it 225 - */ 226 - rx_stats->len = skb->len; 227 - ieee80211_rx_mgt(ieee, (struct ieee80211_hdr_4addr *)skb->data, 228 - rx_stats); 229 - 230 - if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))) { 231 - dev_kfree_skb_any(skb); 232 - return 0; 233 - } 234 - 235 - ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype); 236 - 237 - dev_kfree_skb_any(skb); 238 - 239 - return 0; 240 - 241 - } 242 - 243 - 244 - 245 - /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ 246 - /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ 247 - static unsigned char rfc1042_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; 248 - /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ 249 - static unsigned char bridge_tunnel_header[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; 250 - /* No encapsulation header if EtherType < 0x600 (=length) */ 251 - 252 - /* Called by ieee80211_rx_frame_decrypt */ 253 - static int ieee80211_is_eapol_frame(struct ieee80211_device *ieee, 254 - struct sk_buff *skb, size_t hdrlen) 255 - { 256 - struct net_device *dev = ieee->dev; 257 - u16 fc, ethertype; 258 - struct ieee80211_hdr_4addr *hdr; 259 - u8 *pos; 260 - 261 - if (skb->len < 24) 262 - return 0; 263 - 264 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 265 - fc = le16_to_cpu(hdr->frame_ctl); 266 - 267 - /* check that the frame is unicast frame to us */ 268 - if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == 269 - IEEE80211_FCTL_TODS && 270 - memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 && 271 - memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) { 272 - /* ToDS frame with own addr BSSID and DA */ 273 - } else if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) == 274 - IEEE80211_FCTL_FROMDS && 275 - memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) { 276 - /* FromDS frame with own addr as DA */ 277 - } else 278 - return 0; 279 - 280 - if (skb->len < 24 + 8) 281 - return 0; 282 - 283 - /* check for port access entity Ethernet type */ 284 - // pos = skb->data + 24; 285 - pos = skb->data + hdrlen; 286 - ethertype = (pos[6] << 8) | pos[7]; 287 - if (ethertype == ETH_P_PAE) 288 - return 1; 289 - 290 - return 0; 291 - } 292 - 293 - /* Called only as a tasklet (software IRQ), by ieee80211_rx */ 294 - static inline int 295 - ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb, 296 - struct ieee80211_crypt_data *crypt) 297 - { 298 - struct ieee80211_hdr_4addr *hdr; 299 - int res, hdrlen; 300 - 301 - if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL) 302 - return 0; 303 - 304 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 305 - hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); 306 - 307 - #ifdef CONFIG_IEEE80211_CRYPT_TKIP 308 - if (ieee->tkip_countermeasures && 309 - strcmp(crypt->ops->name, "TKIP") == 0) { 310 - if (net_ratelimit()) { 311 - netdev_dbg(ieee->dev, 312 - "TKIP countermeasures: dropped received packet from %pM\n", 313 - ieee->dev->name, hdr->addr2); 314 - } 315 - return -1; 316 - } 317 - #endif 318 - 319 - atomic_inc(&crypt->refcnt); 320 - res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv); 321 - atomic_dec(&crypt->refcnt); 322 - if (res < 0) { 323 - IEEE80211_DEBUG_DROP( 324 - "decryption failed (SA=%pM" 325 - ") res=%d\n", hdr->addr2, res); 326 - if (res == -2) 327 - IEEE80211_DEBUG_DROP("Decryption failed ICV " 328 - "mismatch (key %d)\n", 329 - skb->data[hdrlen + 3] >> 6); 330 - ieee->ieee_stats.rx_discards_undecryptable++; 331 - return -1; 332 - } 333 - 334 - return res; 335 - } 336 - 337 - 338 - /* Called only as a tasklet (software IRQ), by ieee80211_rx */ 339 - static inline int 340 - ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee, 341 - struct sk_buff *skb, int keyidx, 342 - struct ieee80211_crypt_data *crypt) 343 - { 344 - struct ieee80211_hdr_4addr *hdr; 345 - int res, hdrlen; 346 - 347 - if (crypt == NULL || crypt->ops->decrypt_msdu == NULL) 348 - return 0; 349 - 350 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 351 - hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); 352 - 353 - atomic_inc(&crypt->refcnt); 354 - res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv); 355 - atomic_dec(&crypt->refcnt); 356 - if (res < 0) { 357 - netdev_dbg(ieee->dev, 358 - "MSDU decryption/MIC verification failed (SA=%pM keyidx=%d)\n", 359 - hdr->addr2, keyidx); 360 - return -1; 361 - } 362 - 363 - return 0; 364 - } 365 - 366 - 367 - /* this function is stolen from ipw2200 driver*/ 368 - #define IEEE_PACKET_RETRY_TIME (5*HZ) 369 - static int is_duplicate_packet(struct ieee80211_device *ieee, 370 - struct ieee80211_hdr_4addr *header) 371 - { 372 - u16 fc = le16_to_cpu(header->frame_ctl); 373 - u16 sc = le16_to_cpu(header->seq_ctl); 374 - u16 seq = WLAN_GET_SEQ_SEQ(sc); 375 - u16 frag = WLAN_GET_SEQ_FRAG(sc); 376 - u16 *last_seq, *last_frag; 377 - unsigned long *last_time; 378 - struct ieee80211_hdr_3addrqos *hdr_3addrqos; 379 - struct ieee80211_hdr_4addrqos *hdr_4addrqos; 380 - u8 tid; 381 - 382 - //TO2DS and QoS 383 - if (((fc & IEEE80211_FCTL_DSTODS) == IEEE80211_FCTL_DSTODS) && IEEE80211_QOS_HAS_SEQ(fc)) { 384 - hdr_4addrqos = (struct ieee80211_hdr_4addrqos *)header; 385 - tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & IEEE80211_QOS_TID; 386 - tid = UP2AC(tid); 387 - tid++; 388 - } else if (IEEE80211_QOS_HAS_SEQ(fc)) { //QoS 389 - hdr_3addrqos = (struct ieee80211_hdr_3addrqos *)header; 390 - tid = le16_to_cpu(hdr_3addrqos->qos_ctl) & IEEE80211_QOS_TID; 391 - tid = UP2AC(tid); 392 - tid++; 393 - } else { // no QoS 394 - tid = 0; 395 - } 396 - switch (ieee->iw_mode) { 397 - case IW_MODE_ADHOC: 398 - { 399 - struct list_head *p; 400 - struct ieee_ibss_seq *entry = NULL; 401 - u8 *mac = header->addr2; 402 - int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE; 403 - 404 - list_for_each(p, &ieee->ibss_mac_hash[index]) { 405 - entry = list_entry(p, struct ieee_ibss_seq, list); 406 - if (!memcmp(entry->mac, mac, ETH_ALEN)) 407 - break; 408 - } 409 - // if (memcmp(entry->mac, mac, ETH_ALEN)){ 410 - if (p == &ieee->ibss_mac_hash[index]) { 411 - entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC); 412 - if (!entry) 413 - return 0; 414 - 415 - memcpy(entry->mac, mac, ETH_ALEN); 416 - entry->seq_num[tid] = seq; 417 - entry->frag_num[tid] = frag; 418 - entry->packet_time[tid] = jiffies; 419 - list_add(&entry->list, &ieee->ibss_mac_hash[index]); 420 - return 0; 421 - } 422 - last_seq = &entry->seq_num[tid]; 423 - last_frag = &entry->frag_num[tid]; 424 - last_time = &entry->packet_time[tid]; 425 - break; 426 - } 427 - 428 - case IW_MODE_INFRA: 429 - last_seq = &ieee->last_rxseq_num[tid]; 430 - last_frag = &ieee->last_rxfrag_num[tid]; 431 - last_time = &ieee->last_packet_time[tid]; 432 - 433 - break; 434 - default: 435 - return 0; 436 - } 437 - 438 - // if(tid != 0) { 439 - // printk(KERN_WARNING ":)))))))))))%x %x %x, fc(%x)\n", tid, *last_seq, seq, header->frame_ctl); 440 - // } 441 - if ((*last_seq == seq) && 442 - time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) { 443 - if (*last_frag == frag) { 444 - //printk(KERN_WARNING "[1] go drop!\n"); 445 - goto drop; 446 - 447 - } 448 - if (*last_frag + 1 != frag) 449 - /* out-of-order fragment */ 450 - //printk(KERN_WARNING "[2] go drop!\n"); 451 - goto drop; 452 - } else 453 - *last_seq = seq; 454 - 455 - *last_frag = frag; 456 - *last_time = jiffies; 457 - return 0; 458 - 459 - drop: 460 - // BUG_ON(!(fc & IEEE80211_FCTL_RETRY)); 461 - // printk("DUP\n"); 462 - 463 - return 1; 464 - } 465 - 466 - 467 - /* All received frames are sent to this function. @skb contains the frame in 468 - * IEEE 802.11 format, i.e., in the format it was sent over air. 469 - * This function is called only as a tasklet (software IRQ). */ 470 - int ieee80211_rtl_rx(struct ieee80211_device *ieee, struct sk_buff *skb, 471 - struct ieee80211_rx_stats *rx_stats) 472 - { 473 - struct net_device *dev = ieee->dev; 474 - //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 475 - struct ieee80211_hdr_4addr *hdr; 476 - 477 - size_t hdrlen; 478 - u16 fc, type, stype, sc; 479 - struct net_device_stats *stats; 480 - unsigned int frag; 481 - u8 *payload; 482 - u16 ethertype; 483 - u8 dst[ETH_ALEN]; 484 - u8 src[ETH_ALEN]; 485 - u8 bssid[ETH_ALEN]; 486 - struct ieee80211_crypt_data *crypt = NULL; 487 - int keyidx = 0; 488 - 489 - // cheat the the hdr type 490 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 491 - stats = &ieee->stats; 492 - 493 - if (skb->len < 10) { 494 - netdev_info(ieee->dev, "SKB length < 10\n"); 495 - goto rx_dropped; 496 - } 497 - 498 - fc = le16_to_cpu(hdr->frame_ctl); 499 - type = WLAN_FC_GET_TYPE(fc); 500 - stype = WLAN_FC_GET_STYPE(fc); 501 - sc = le16_to_cpu(hdr->seq_ctl); 502 - 503 - frag = WLAN_GET_SEQ_FRAG(sc); 504 - 505 - //YJ,add,080828,for keep alive 506 - if ((fc & IEEE80211_FCTL_TODS) != IEEE80211_FCTL_TODS) { 507 - if (!memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) 508 - ieee->NumRxUnicast++; 509 - } else { 510 - if (!memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN)) 511 - ieee->NumRxUnicast++; 512 - } 513 - //YJ,add,080828,for keep alive,end 514 - 515 - hdrlen = ieee80211_get_hdrlen(fc); 516 - 517 - 518 - if (ieee->iw_mode == IW_MODE_MONITOR) { 519 - ieee80211_monitor_rx(ieee, skb, rx_stats); 520 - stats->rx_packets++; 521 - stats->rx_bytes += skb->len; 522 - return 1; 523 - } 524 - 525 - if (ieee->host_decrypt) { 526 - int idx = 0; 527 - if (skb->len >= hdrlen + 3) 528 - idx = skb->data[hdrlen + 3] >> 6; 529 - crypt = ieee->crypt[idx]; 530 - 531 - /* allow NULL decrypt to indicate an station specific override 532 - * for default encryption */ 533 - if (crypt && (crypt->ops == NULL || 534 - crypt->ops->decrypt_mpdu == NULL)) 535 - crypt = NULL; 536 - 537 - if (!crypt && (fc & IEEE80211_FCTL_WEP)) { 538 - /* This seems to be triggered by some (multicast?) 539 - * frames from other than current BSS, so just drop the 540 - * frames silently instead of filling system log with 541 - * these reports. */ 542 - IEEE80211_DEBUG_DROP("Decryption failed (not set)" 543 - " (SA=%pM)\n", 544 - hdr->addr2); 545 - ieee->ieee_stats.rx_discards_undecryptable++; 546 - goto rx_dropped; 547 - } 548 - } 549 - 550 - if (skb->len < IEEE80211_DATA_HDR3_LEN) 551 - goto rx_dropped; 552 - 553 - // if QoS enabled, should check the sequence for each of the AC 554 - if (is_duplicate_packet(ieee, hdr)) 555 - goto rx_dropped; 556 - 557 - 558 - if (type == IEEE80211_FTYPE_MGMT) { 559 - if (ieee80211_rx_frame_mgmt(ieee, skb, rx_stats, type, stype)) 560 - goto rx_dropped; 561 - else 562 - goto rx_exit; 563 - } 564 - 565 - /* Data frame - extract src/dst addresses */ 566 - switch (fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) { 567 - case IEEE80211_FCTL_FROMDS: 568 - memcpy(dst, hdr->addr1, ETH_ALEN); 569 - memcpy(src, hdr->addr3, ETH_ALEN); 570 - memcpy(bssid, hdr->addr2, ETH_ALEN); 571 - break; 572 - case IEEE80211_FCTL_TODS: 573 - memcpy(dst, hdr->addr3, ETH_ALEN); 574 - memcpy(src, hdr->addr2, ETH_ALEN); 575 - memcpy(bssid, hdr->addr1, ETH_ALEN); 576 - break; 577 - case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS: 578 - if (skb->len < IEEE80211_DATA_HDR4_LEN) 579 - goto rx_dropped; 580 - memcpy(dst, hdr->addr3, ETH_ALEN); 581 - memcpy(src, hdr->addr4, ETH_ALEN); 582 - memcpy(bssid, ieee->current_network.bssid, ETH_ALEN); 583 - break; 584 - case 0: 585 - memcpy(dst, hdr->addr1, ETH_ALEN); 586 - memcpy(src, hdr->addr2, ETH_ALEN); 587 - memcpy(bssid, hdr->addr3, ETH_ALEN); 588 - break; 589 - } 590 - 591 - 592 - dev->last_rx = jiffies; 593 - 594 - 595 - /* Nullfunc frames may have PS-bit set, so they must be passed to 596 - * hostap_handle_sta_rx() before being dropped here. */ 597 - if (stype != IEEE80211_STYPE_DATA && 598 - stype != IEEE80211_STYPE_DATA_CFACK && 599 - stype != IEEE80211_STYPE_DATA_CFPOLL && 600 - stype != IEEE80211_STYPE_DATA_CFACKPOLL && 601 - stype != IEEE80211_STYPE_QOS_DATA//add by David,2006.8.4 602 - ) { 603 - if (stype != IEEE80211_STYPE_NULLFUNC) 604 - IEEE80211_DEBUG_DROP( 605 - "RX: dropped data frame " 606 - "with no data (type=0x%02x, " 607 - "subtype=0x%02x, len=%d)\n", 608 - type, stype, skb->len); 609 - goto rx_dropped; 610 - } 611 - if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN)) 612 - goto rx_dropped; 613 - 614 - ieee->NumRxDataInPeriod++; 615 - ieee->NumRxOkTotal++; 616 - /* skb: hdr + (possibly fragmented, possibly encrypted) payload */ 617 - 618 - if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && 619 - (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0) 620 - goto rx_dropped; 621 - 622 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 623 - 624 - /* skb: hdr + (possibly fragmented) plaintext payload */ 625 - // PR: FIXME: hostap has additional conditions in the "if" below: 626 - // ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && 627 - if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) { 628 - int flen; 629 - struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr); 630 - IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag); 631 - 632 - if (!frag_skb) { 633 - IEEE80211_DEBUG(IEEE80211_DL_RX | IEEE80211_DL_FRAG, 634 - "Rx cannot get skb from fragment " 635 - "cache (morefrag=%d seq=%u frag=%u)\n", 636 - (fc & IEEE80211_FCTL_MOREFRAGS) != 0, 637 - WLAN_GET_SEQ_SEQ(sc), frag); 638 - goto rx_dropped; 639 - } 640 - flen = skb->len; 641 - if (frag != 0) 642 - flen -= hdrlen; 643 - 644 - if (frag_skb->tail + flen > frag_skb->end) { 645 - netdev_warn(ieee->dev, 646 - "host decrypted and reassembled frame did not fit skb\n"); 647 - ieee80211_frag_cache_invalidate(ieee, hdr); 648 - goto rx_dropped; 649 - } 650 - 651 - if (frag == 0) { 652 - /* copy first fragment (including full headers) into 653 - * beginning of the fragment cache skb */ 654 - memcpy(skb_put(frag_skb, flen), skb->data, flen); 655 - } else { 656 - /* append frame payload to the end of the fragment 657 - * cache skb */ 658 - memcpy(skb_put(frag_skb, flen), skb->data + hdrlen, 659 - flen); 660 - } 661 - dev_kfree_skb_any(skb); 662 - skb = NULL; 663 - 664 - if (fc & IEEE80211_FCTL_MOREFRAGS) { 665 - /* more fragments expected - leave the skb in fragment 666 - * cache for now; it will be delivered to upper layers 667 - * after all fragments have been received */ 668 - goto rx_exit; 669 - } 670 - 671 - /* this was the last fragment and the frame will be 672 - * delivered, so remove skb from fragment cache */ 673 - skb = frag_skb; 674 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 675 - ieee80211_frag_cache_invalidate(ieee, hdr); 676 - } 677 - 678 - /* skb: hdr + (possible reassembled) full MSDU payload; possibly still 679 - * encrypted/authenticated */ 680 - if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && 681 - ieee80211_rx_frame_decrypt_msdu(ieee, skb, keyidx, crypt)) 682 - goto rx_dropped; 683 - 684 - hdr = (struct ieee80211_hdr_4addr *)skb->data; 685 - if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep) { 686 - if (/*ieee->ieee802_1x &&*/ 687 - ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { 688 - 689 - #ifdef CONFIG_IEEE80211_DEBUG 690 - /* pass unencrypted EAPOL frames even if encryption is 691 - * configured */ 692 - struct eapol *eap = (struct eapol *)(skb->data + 693 - 24); 694 - IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n", 695 - eap_get_type(eap->type)); 696 - #endif 697 - } else { 698 - IEEE80211_DEBUG_DROP( 699 - "encryption configured, but RX " 700 - "frame not encrypted (SA=%pM)\n", 701 - hdr->addr2); 702 - goto rx_dropped; 703 - } 704 - } 705 - 706 - #ifdef CONFIG_IEEE80211_DEBUG 707 - if (crypt && !(fc & IEEE80211_FCTL_WEP) && 708 - ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { 709 - struct eapol *eap = (struct eapol *)(skb->data + 710 - 24); 711 - IEEE80211_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n", 712 - eap_get_type(eap->type)); 713 - } 714 - #endif 715 - 716 - if (crypt && !(fc & IEEE80211_FCTL_WEP) && !ieee->open_wep && 717 - !ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { 718 - IEEE80211_DEBUG_DROP( 719 - "dropped unencrypted RX data " 720 - "frame from %pM" 721 - " (drop_unencrypted=1)\n", 722 - hdr->addr2); 723 - goto rx_dropped; 724 - } 725 - /* 726 - if(ieee80211_is_eapol_frame(ieee, skb, hdrlen)) { 727 - printk(KERN_WARNING "RX: IEEE802.1X EPAOL frame!\n"); 728 - } 729 - */ 730 - /* skb: hdr + (possible reassembled) full plaintext payload */ 731 - payload = skb->data + hdrlen; 732 - ethertype = (payload[6] << 8) | payload[7]; 733 - 734 - 735 - /* convert hdr + possible LLC headers into Ethernet header */ 736 - if (skb->len - hdrlen >= 8 && 737 - ((memcmp(payload, rfc1042_header, SNAP_SIZE) == 0 && 738 - ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || 739 - memcmp(payload, bridge_tunnel_header, SNAP_SIZE) == 0)) { 740 - /* remove RFC1042 or Bridge-Tunnel encapsulation and 741 - * replace EtherType */ 742 - skb_pull(skb, hdrlen + SNAP_SIZE); 743 - memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); 744 - memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); 745 - } else { 746 - u16 len; 747 - /* Leave Ethernet header part of hdr and full payload */ 748 - skb_pull(skb, hdrlen); 749 - len = htons(skb->len); 750 - memcpy(skb_push(skb, 2), &len, 2); 751 - memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); 752 - memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); 753 - } 754 - 755 - 756 - stats->rx_packets++; 757 - stats->rx_bytes += skb->len; 758 - 759 - if (skb) { 760 - skb->protocol = eth_type_trans(skb, dev); 761 - memset(skb->cb, 0, sizeof(skb->cb)); 762 - skb->dev = dev; 763 - skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */ 764 - ieee->last_rx_ps_time = jiffies; 765 - netif_rx(skb); 766 - } 767 - 768 - rx_exit: 769 - return 1; 770 - 771 - rx_dropped: 772 - stats->rx_dropped++; 773 - 774 - /* Returning 0 indicates to caller that we have not handled the SKB-- 775 - * so it is still allocated and can be used again by underlying 776 - * hardware as a DMA target */ 777 - return 0; 778 - } 779 - 780 - #define MGMT_FRAME_FIXED_PART_LENGTH 0x24 781 - 782 - static inline int ieee80211_is_ofdm_rate(u8 rate) 783 - { 784 - switch (rate & ~IEEE80211_BASIC_RATE_MASK) { 785 - case IEEE80211_OFDM_RATE_6MB: 786 - case IEEE80211_OFDM_RATE_9MB: 787 - case IEEE80211_OFDM_RATE_12MB: 788 - case IEEE80211_OFDM_RATE_18MB: 789 - case IEEE80211_OFDM_RATE_24MB: 790 - case IEEE80211_OFDM_RATE_36MB: 791 - case IEEE80211_OFDM_RATE_48MB: 792 - case IEEE80211_OFDM_RATE_54MB: 793 - return 1; 794 - } 795 - return 0; 796 - } 797 - 798 - static inline int ieee80211_SignalStrengthTranslate(int CurrSS) 799 - { 800 - int RetSS; 801 - 802 - // Step 1. Scale mapping. 803 - if (CurrSS >= 71 && CurrSS <= 100) 804 - RetSS = 90 + ((CurrSS - 70) / 3); 805 - else if (CurrSS >= 41 && CurrSS <= 70) 806 - RetSS = 78 + ((CurrSS - 40) / 3); 807 - else if (CurrSS >= 31 && CurrSS <= 40) 808 - RetSS = 66 + (CurrSS - 30); 809 - else if (CurrSS >= 21 && CurrSS <= 30) 810 - RetSS = 54 + (CurrSS - 20); 811 - else if (CurrSS >= 5 && CurrSS <= 20) 812 - RetSS = 42 + (((CurrSS - 5) * 2) / 3); 813 - else if (CurrSS == 4) 814 - RetSS = 36; 815 - else if (CurrSS == 3) 816 - RetSS = 27; 817 - else if (CurrSS == 2) 818 - RetSS = 18; 819 - else if (CurrSS == 1) 820 - RetSS = 9; 821 - else 822 - RetSS = CurrSS; 823 - 824 - //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS)); 825 - 826 - // Step 2. Smoothing. 827 - 828 - //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS)); 829 - 830 - return RetSS; 831 - } 832 - 833 - static inline void 834 - ieee80211_extract_country_ie(struct ieee80211_device *ieee, 835 - struct ieee80211_info_element *info_element, 836 - struct ieee80211_network *network, u8 *addr2) 837 - { 838 - if (IS_DOT11D_ENABLE(ieee)) { 839 - if (info_element->len != 0) { 840 - memcpy(network->CountryIeBuf, info_element->data, info_element->len); 841 - network->CountryIeLen = info_element->len; 842 - 843 - if (!IS_COUNTRY_IE_VALID(ieee)) 844 - Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data); 845 - } 846 - 847 - // 848 - // 070305, rcnjko: I update country IE watch dog here because 849 - // some AP (e.g. Cisco 1242) don't include country IE in their 850 - // probe response frame. 851 - // 852 - if (IS_EQUAL_CIE_SRC(ieee, addr2)) 853 - UPDATE_CIE_WATCHDOG(ieee); 854 - } 855 - 856 - } 857 - 858 - /* SignalStrengthIndex is 0-100 */ 859 - static int ieee80211_TranslateToDbm(unsigned char SignalStrengthIndex) 860 - { 861 - unsigned char SignalPower; // in dBm. 862 - 863 - // Translate to dBm (x=0.5y-95). 864 - SignalPower = (int)SignalStrengthIndex * 7 / 10; 865 - SignalPower -= 95; 866 - 867 - return SignalPower; 868 - } 869 - inline int ieee80211_network_init( 870 - struct ieee80211_device *ieee, 871 - struct ieee80211_probe_response *beacon, 872 - struct ieee80211_network *network, 873 - struct ieee80211_rx_stats *stats) 874 - { 875 - #ifdef CONFIG_IEEE80211_DEBUG 876 - char rates_str[64]; 877 - char *p; 878 - #endif 879 - struct ieee80211_info_element *info_element; 880 - u16 left; 881 - u8 i; 882 - short offset; 883 - u8 curRate = 0, hOpRate = 0, curRate_ex = 0; 884 - 885 - /* Pull out fixed field data */ 886 - memcpy(network->bssid, beacon->header.addr3, ETH_ALEN); 887 - network->capability = beacon->capability; 888 - network->last_scanned = jiffies; 889 - network->time_stamp[0] = beacon->time_stamp[0]; 890 - network->time_stamp[1] = beacon->time_stamp[1]; 891 - network->beacon_interval = beacon->beacon_interval; 892 - /* Where to pull this? beacon->listen_interval;*/ 893 - network->listen_interval = 0x0A; 894 - network->rates_len = network->rates_ex_len = 0; 895 - network->last_associate = 0; 896 - network->ssid_len = 0; 897 - network->flags = 0; 898 - network->atim_window = 0; 899 - network->QoS_Enable = 0; 900 - //by amy 080312 901 - network->HighestOperaRate = 0; 902 - //by amy 080312 903 - network->Turbo_Enable = 0; 904 - network->CountryIeLen = 0; 905 - memset(network->CountryIeBuf, 0, MAX_IE_LEN); 906 - 907 - if (stats->freq == IEEE80211_52GHZ_BAND) { 908 - /* for A band (No DS info) */ 909 - network->channel = stats->received_channel; 910 - } else 911 - network->flags |= NETWORK_HAS_CCK; 912 - 913 - network->wpa_ie_len = 0; 914 - network->rsn_ie_len = 0; 915 - 916 - info_element = &beacon->info_element; 917 - left = stats->len - ((void *)info_element - (void *)beacon); 918 - while (left >= sizeof(struct ieee80211_info_element_hdr)) { 919 - if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) { 920 - IEEE80211_DEBUG_SCAN("SCAN: parse failed: info_element->len + 2 > left : info_element->len+2=%d left=%d.\n", 921 - info_element->len + sizeof(struct ieee80211_info_element), 922 - left); 923 - return 1; 924 - } 925 - 926 - switch (info_element->id) { 927 - case MFIE_TYPE_SSID: 928 - if (ieee80211_is_empty_essid(info_element->data, 929 - info_element->len)) { 930 - network->flags |= NETWORK_EMPTY_ESSID; 931 - break; 932 - } 933 - 934 - network->ssid_len = min(info_element->len, 935 - (u8)IW_ESSID_MAX_SIZE); 936 - memcpy(network->ssid, info_element->data, network->ssid_len); 937 - if (network->ssid_len < IW_ESSID_MAX_SIZE) 938 - memset(network->ssid + network->ssid_len, 0, 939 - IW_ESSID_MAX_SIZE - network->ssid_len); 940 - 941 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_SSID: '%s' len=%d.\n", 942 - network->ssid, network->ssid_len); 943 - break; 944 - 945 - case MFIE_TYPE_RATES: 946 - #ifdef CONFIG_IEEE80211_DEBUG 947 - p = rates_str; 948 - #endif 949 - network->rates_len = min(info_element->len, MAX_RATES_LENGTH); 950 - for (i = 0; i < network->rates_len; i++) { 951 - network->rates[i] = info_element->data[i]; 952 - curRate = network->rates[i] & 0x7f; 953 - if (hOpRate < curRate) 954 - hOpRate = curRate; 955 - #ifdef CONFIG_IEEE80211_DEBUG 956 - p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]); 957 - #endif 958 - if (ieee80211_is_ofdm_rate(info_element->data[i])) { 959 - network->flags |= NETWORK_HAS_OFDM; 960 - if (info_element->data[i] & 961 - IEEE80211_BASIC_RATE_MASK) 962 - network->flags &= 963 - ~NETWORK_HAS_CCK; 964 - } 965 - } 966 - 967 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES: '%s' (%d)\n", 968 - rates_str, network->rates_len); 969 - break; 970 - 971 - case MFIE_TYPE_RATES_EX: 972 - #ifdef CONFIG_IEEE80211_DEBUG 973 - p = rates_str; 974 - #endif 975 - network->rates_ex_len = min(info_element->len, MAX_RATES_EX_LENGTH); 976 - for (i = 0; i < network->rates_ex_len; i++) { 977 - network->rates_ex[i] = info_element->data[i]; 978 - curRate_ex = network->rates_ex[i] & 0x7f; 979 - if (hOpRate < curRate_ex) 980 - hOpRate = curRate_ex; 981 - #ifdef CONFIG_IEEE80211_DEBUG 982 - p += snprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]); 983 - #endif 984 - if (ieee80211_is_ofdm_rate(info_element->data[i])) { 985 - network->flags |= NETWORK_HAS_OFDM; 986 - if (info_element->data[i] & 987 - IEEE80211_BASIC_RATE_MASK) 988 - network->flags &= 989 - ~NETWORK_HAS_CCK; 990 - } 991 - } 992 - 993 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_RATES_EX: '%s' (%d)\n", 994 - rates_str, network->rates_ex_len); 995 - break; 996 - 997 - case MFIE_TYPE_DS_SET: 998 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_DS_SET: %d\n", 999 - info_element->data[0]); 1000 - if (stats->freq == IEEE80211_24GHZ_BAND) 1001 - network->channel = info_element->data[0]; 1002 - break; 1003 - 1004 - case MFIE_TYPE_FH_SET: 1005 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_FH_SET: ignored\n"); 1006 - break; 1007 - 1008 - case MFIE_TYPE_CF_SET: 1009 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_CF_SET: ignored\n"); 1010 - break; 1011 - 1012 - case MFIE_TYPE_TIM: 1013 - 1014 - if (info_element->len < 4) 1015 - break; 1016 - 1017 - network->dtim_period = info_element->data[1]; 1018 - 1019 - if (ieee->state != IEEE80211_LINKED) 1020 - break; 1021 - 1022 - network->last_dtim_sta_time[0] = jiffies; 1023 - network->last_dtim_sta_time[1] = stats->mac_time[1]; 1024 - 1025 - network->dtim_data = IEEE80211_DTIM_VALID; 1026 - 1027 - if (info_element->data[0] != 0) 1028 - break; 1029 - 1030 - if (info_element->data[2] & 1) 1031 - network->dtim_data |= IEEE80211_DTIM_MBCAST; 1032 - 1033 - offset = (info_element->data[2] >> 1)*2; 1034 - 1035 - //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id); 1036 - 1037 - /* add and modified for ps 2008.1.22 */ 1038 - if (ieee->assoc_id < 8*offset || 1039 - ieee->assoc_id > 8*(offset + info_element->len - 3)) { 1040 - break; 1041 - } 1042 - 1043 - offset = (ieee->assoc_id/8) - offset;// + ((aid % 8)? 0 : 1) ; 1044 - 1045 - // printk("offset:%x data:%x, ucast:%d\n", offset, 1046 - // info_element->data[3+offset] , 1047 - // info_element->data[3+offset] & (1<<(ieee->assoc_id%8))); 1048 - 1049 - if (info_element->data[3+offset] & (1<<(ieee->assoc_id%8))) 1050 - network->dtim_data |= IEEE80211_DTIM_UCAST; 1051 - 1052 - break; 1053 - 1054 - case MFIE_TYPE_IBSS_SET: 1055 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_IBSS_SET: ignored\n"); 1056 - break; 1057 - 1058 - case MFIE_TYPE_CHALLENGE: 1059 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_CHALLENGE: ignored\n"); 1060 - break; 1061 - 1062 - case MFIE_TYPE_GENERIC: 1063 - //nic is 87B 1064 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", 1065 - info_element->len); 1066 - if (info_element->len >= 4 && 1067 - info_element->data[0] == 0x00 && 1068 - info_element->data[1] == 0x50 && 1069 - info_element->data[2] == 0xf2 && 1070 - info_element->data[3] == 0x01) { 1071 - network->wpa_ie_len = min(info_element->len + 2, 1072 - MAX_WPA_IE_LEN); 1073 - memcpy(network->wpa_ie, info_element, 1074 - network->wpa_ie_len); 1075 - } 1076 - 1077 - if (info_element->len == 7 && 1078 - info_element->data[0] == 0x00 && 1079 - info_element->data[1] == 0xe0 && 1080 - info_element->data[2] == 0x4c && 1081 - info_element->data[3] == 0x01 && 1082 - info_element->data[4] == 0x02) { 1083 - network->Turbo_Enable = 1; 1084 - } 1085 - if (1 == stats->nic_type) //nic 87 1086 - break; 1087 - 1088 - if (info_element->len >= 5 && 1089 - info_element->data[0] == 0x00 && 1090 - info_element->data[1] == 0x50 && 1091 - info_element->data[2] == 0xf2 && 1092 - info_element->data[3] == 0x02 && 1093 - info_element->data[4] == 0x00) { 1094 - //printk(KERN_WARNING "wmm info updated: %x\n", info_element->data[6]); 1095 - //WMM Information Element 1096 - network->wmm_info = info_element->data[6]; 1097 - network->QoS_Enable = 1; 1098 - } 1099 - 1100 - if (info_element->len >= 8 && 1101 - info_element->data[0] == 0x00 && 1102 - info_element->data[1] == 0x50 && 1103 - info_element->data[2] == 0xf2 && 1104 - info_element->data[3] == 0x02 && 1105 - info_element->data[4] == 0x01) { 1106 - // Not care about version at present. 1107 - //WMM Information Element 1108 - //printk(KERN_WARNING "wmm info&param updated: %x\n", info_element->data[6]); 1109 - network->wmm_info = info_element->data[6]; 1110 - //WMM Parameter Element 1111 - memcpy(network->wmm_param, (u8 *)(info_element->data + 8), (info_element->len - 8)); 1112 - network->QoS_Enable = 1; 1113 - } 1114 - break; 1115 - 1116 - case MFIE_TYPE_RSN: 1117 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_RSN: %d bytes\n", 1118 - info_element->len); 1119 - network->rsn_ie_len = min(info_element->len + 2, 1120 - MAX_WPA_IE_LEN); 1121 - memcpy(network->rsn_ie, info_element, 1122 - network->rsn_ie_len); 1123 - break; 1124 - case MFIE_TYPE_COUNTRY: 1125 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n", 1126 - info_element->len); 1127 - // printk("=====>Receive <%s> Country IE\n",network->ssid); 1128 - ieee80211_extract_country_ie(ieee, info_element, network, beacon->header.addr2); 1129 - break; 1130 - default: 1131 - IEEE80211_DEBUG_SCAN("unsupported IE %d\n", 1132 - info_element->id); 1133 - break; 1134 - } 1135 - 1136 - left -= sizeof(struct ieee80211_info_element_hdr) + 1137 - info_element->len; 1138 - info_element = (struct ieee80211_info_element *) 1139 - &info_element->data[info_element->len]; 1140 - } 1141 - //by amy 080312 1142 - network->HighestOperaRate = hOpRate; 1143 - //by amy 080312 1144 - network->mode = 0; 1145 - if (stats->freq == IEEE80211_52GHZ_BAND) 1146 - network->mode = IEEE_A; 1147 - else { 1148 - if (network->flags & NETWORK_HAS_OFDM) 1149 - network->mode |= IEEE_G; 1150 - if (network->flags & NETWORK_HAS_CCK) 1151 - network->mode |= IEEE_B; 1152 - } 1153 - 1154 - if (network->mode == 0) { 1155 - IEEE80211_DEBUG_SCAN("Filtered out '%s (%pM)' " 1156 - "network.\n", 1157 - escape_essid(network->ssid, 1158 - network->ssid_len), 1159 - network->bssid); 1160 - return 1; 1161 - } 1162 - 1163 - if (ieee80211_is_empty_essid(network->ssid, network->ssid_len)) 1164 - network->flags |= NETWORK_EMPTY_ESSID; 1165 - 1166 - stats->signal = ieee80211_TranslateToDbm(stats->signalstrength); 1167 - //stats->noise = stats->signal - stats->noise; 1168 - stats->noise = ieee80211_TranslateToDbm(100 - stats->signalstrength) - 25; 1169 - memcpy(&network->stats, stats, sizeof(network->stats)); 1170 - 1171 - return 0; 1172 - } 1173 - 1174 - static inline int is_same_network(struct ieee80211_network *src, 1175 - struct ieee80211_network *dst, 1176 - struct ieee80211_device *ieee) 1177 - { 1178 - /* A network is only a duplicate if the channel, BSSID, ESSID 1179 - * and the capability field (in particular IBSS and BSS) all match. 1180 - * We treat all <hidden> with the same BSSID and channel 1181 - * as one network */ 1182 - return (((src->ssid_len == dst->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) && //YJ,mod,080819,for hidden ap 1183 - //((src->ssid_len == dst->ssid_len) && 1184 - (src->channel == dst->channel) && 1185 - !memcmp(src->bssid, dst->bssid, ETH_ALEN) && 1186 - (!memcmp(src->ssid, dst->ssid, src->ssid_len) || (ieee->iw_mode == IW_MODE_INFRA)) && //YJ,mod,080819,for hidden ap 1187 - //!memcmp(src->ssid, dst->ssid, src->ssid_len) && 1188 - ((src->capability & WLAN_CAPABILITY_IBSS) == 1189 - (dst->capability & WLAN_CAPABILITY_IBSS)) && 1190 - ((src->capability & WLAN_CAPABILITY_BSS) == 1191 - (dst->capability & WLAN_CAPABILITY_BSS))); 1192 - } 1193 - 1194 - inline void update_network(struct ieee80211_network *dst, 1195 - struct ieee80211_network *src) 1196 - { 1197 - unsigned char quality = src->stats.signalstrength; 1198 - unsigned char signal = 0; 1199 - unsigned char noise = 0; 1200 - if (dst->stats.signalstrength > 0) 1201 - quality = (dst->stats.signalstrength * 5 + src->stats.signalstrength + 5)/6; 1202 - signal = ieee80211_TranslateToDbm(quality); 1203 - //noise = signal - src->stats.noise; 1204 - if (dst->stats.noise > 0) 1205 - noise = (dst->stats.noise * 5 + src->stats.noise)/6; 1206 - //if(strcmp(dst->ssid, "linksys_lzm000") == 0) 1207 - // printk("ssid:%s, quality:%d, signal:%d\n", dst->ssid, quality, signal); 1208 - memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats)); 1209 - dst->stats.signalstrength = quality; 1210 - dst->stats.signal = signal; 1211 - // printk("==================>stats.signal is %d\n",dst->stats.signal); 1212 - dst->stats.noise = noise; 1213 - 1214 - 1215 - dst->capability = src->capability; 1216 - memcpy(dst->rates, src->rates, src->rates_len); 1217 - dst->rates_len = src->rates_len; 1218 - memcpy(dst->rates_ex, src->rates_ex, src->rates_ex_len); 1219 - dst->rates_ex_len = src->rates_ex_len; 1220 - dst->HighestOperaRate = src->HighestOperaRate; 1221 - //printk("==========>in %s: src->ssid is %s,chan is %d\n",__func__,src->ssid,src->channel); 1222 - 1223 - //YJ,add,080819,for hidden ap 1224 - if (src->ssid_len > 0) { 1225 - //if(src->ssid_len == 13) 1226 - // printk("=====================>>>>>>>> Dst ssid: %s Src ssid: %s\n", dst->ssid, src->ssid); 1227 - memset(dst->ssid, 0, dst->ssid_len); 1228 - dst->ssid_len = src->ssid_len; 1229 - memcpy(dst->ssid, src->ssid, src->ssid_len); 1230 - } 1231 - //YJ,add,080819,for hidden ap,end 1232 - 1233 - dst->channel = src->channel; 1234 - dst->mode = src->mode; 1235 - dst->flags = src->flags; 1236 - dst->time_stamp[0] = src->time_stamp[0]; 1237 - dst->time_stamp[1] = src->time_stamp[1]; 1238 - 1239 - dst->beacon_interval = src->beacon_interval; 1240 - dst->listen_interval = src->listen_interval; 1241 - dst->atim_window = src->atim_window; 1242 - dst->dtim_period = src->dtim_period; 1243 - dst->dtim_data = src->dtim_data; 1244 - dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0]; 1245 - dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1]; 1246 - // printk("update:%s, dtim_period:%x, dtim_data:%x\n", src->ssid, src->dtim_period, src->dtim_data); 1247 - memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len); 1248 - dst->wpa_ie_len = src->wpa_ie_len; 1249 - memcpy(dst->rsn_ie, src->rsn_ie, src->rsn_ie_len); 1250 - dst->rsn_ie_len = src->rsn_ie_len; 1251 - 1252 - dst->last_scanned = jiffies; 1253 - /* dst->last_associate is not overwritten */ 1254 - // disable QoS process now, added by David 2006/7/25 1255 - #if 1 1256 - dst->wmm_info = src->wmm_info; //sure to exist in beacon or probe response frame. 1257 - /* 1258 - if((dst->wmm_info^src->wmm_info)&0x0f) {//Param Set Count change, update Parameter 1259 - memcpy(dst->wmm_param, src->wmm_param, IEEE80211_AC_PRAM_LEN); 1260 - } 1261 - */ 1262 - if (src->wmm_param[0].ac_aci_acm_aifsn || \ 1263 - src->wmm_param[1].ac_aci_acm_aifsn || \ 1264 - src->wmm_param[2].ac_aci_acm_aifsn || \ 1265 - src->wmm_param[3].ac_aci_acm_aifsn) { 1266 - memcpy(dst->wmm_param, src->wmm_param, WME_AC_PRAM_LEN); 1267 - } 1268 - dst->QoS_Enable = src->QoS_Enable; 1269 - #else 1270 - dst->QoS_Enable = 1;//for Rtl8187 simulation 1271 - #endif 1272 - dst->SignalStrength = src->SignalStrength; 1273 - dst->Turbo_Enable = src->Turbo_Enable; 1274 - dst->CountryIeLen = src->CountryIeLen; 1275 - memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen); 1276 - } 1277 - 1278 - 1279 - inline void 1280 - ieee80211_process_probe_response(struct ieee80211_device *ieee, 1281 - struct ieee80211_probe_response *beacon, 1282 - struct ieee80211_rx_stats *stats) 1283 - { 1284 - struct ieee80211_network network; 1285 - struct ieee80211_network *target; 1286 - struct ieee80211_network *oldest = NULL; 1287 - #ifdef CONFIG_IEEE80211_DEBUG 1288 - struct ieee80211_info_element *info_element = &beacon->info_element; 1289 - #endif 1290 - unsigned long flags; 1291 - short renew; 1292 - u8 wmm_info; 1293 - u8 is_beacon = (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_BEACON) ? 1 : 0; //YJ,add,080819,for hidden ap 1294 - 1295 - memset(&network, 0, sizeof(struct ieee80211_network)); 1296 - 1297 - IEEE80211_DEBUG_SCAN( 1298 - "'%s' (%pM): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n", 1299 - escape_essid(info_element->data, info_element->len), 1300 - beacon->header.addr3, 1301 - (beacon->capability & (1<<0xf)) ? '1' : '0', 1302 - (beacon->capability & (1<<0xe)) ? '1' : '0', 1303 - (beacon->capability & (1<<0xd)) ? '1' : '0', 1304 - (beacon->capability & (1<<0xc)) ? '1' : '0', 1305 - (beacon->capability & (1<<0xb)) ? '1' : '0', 1306 - (beacon->capability & (1<<0xa)) ? '1' : '0', 1307 - (beacon->capability & (1<<0x9)) ? '1' : '0', 1308 - (beacon->capability & (1<<0x8)) ? '1' : '0', 1309 - (beacon->capability & (1<<0x7)) ? '1' : '0', 1310 - (beacon->capability & (1<<0x6)) ? '1' : '0', 1311 - (beacon->capability & (1<<0x5)) ? '1' : '0', 1312 - (beacon->capability & (1<<0x4)) ? '1' : '0', 1313 - (beacon->capability & (1<<0x3)) ? '1' : '0', 1314 - (beacon->capability & (1<<0x2)) ? '1' : '0', 1315 - (beacon->capability & (1<<0x1)) ? '1' : '0', 1316 - (beacon->capability & (1<<0x0)) ? '1' : '0'); 1317 - 1318 - if (ieee80211_network_init(ieee, beacon, &network, stats)) { 1319 - IEEE80211_DEBUG_SCAN("Dropped '%s' (%pM) via %s.\n", 1320 - escape_essid(info_element->data, 1321 - info_element->len), 1322 - beacon->header.addr3, 1323 - WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == 1324 - IEEE80211_STYPE_PROBE_RESP ? 1325 - "PROBE RESPONSE" : "BEACON"); 1326 - return; 1327 - } 1328 - 1329 - // For Asus EeePc request, 1330 - // (1) if wireless adapter receive get any 802.11d country code in AP beacon, 1331 - // wireless adapter should follow the country code. 1332 - // (2) If there is no any country code in beacon, 1333 - // then wireless adapter should do active scan from ch1~11 and 1334 - // passive scan from ch12~14 1335 - if (ieee->bGlobalDomain) { 1336 - if (WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == IEEE80211_STYPE_PROBE_RESP) { 1337 - // Case 1: Country code 1338 - if (IS_COUNTRY_IE_VALID(ieee)) { 1339 - if (!IsLegalChannel(ieee, network.channel)) { 1340 - printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel); 1341 - return; 1342 - } 1343 - } 1344 - // Case 2: No any country code. 1345 - else { 1346 - // Filter over channel ch12~14 1347 - if (network.channel > 11) { 1348 - printk("GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n", network.channel); 1349 - return; 1350 - } 1351 - } 1352 - } else { 1353 - // Case 1: Country code 1354 - if (IS_COUNTRY_IE_VALID(ieee)) { 1355 - if (!IsLegalChannel(ieee, network.channel)) { 1356 - printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n", network.channel); 1357 - return; 1358 - } 1359 - } 1360 - // Case 2: No any country code. 1361 - else { 1362 - // Filter over channel ch12~14 1363 - if (network.channel > 14) { 1364 - printk("GetScanInfo(): For Global Domain, filter beacon at channel(%d).\n", network.channel); 1365 - return; 1366 - } 1367 - } 1368 - } 1369 - } 1370 - /* The network parsed correctly -- so now we scan our known networks 1371 - * to see if we can find it in our list. 1372 - * 1373 - * NOTE: This search is definitely not optimized. Once its doing 1374 - * the "right thing" we'll optimize it for efficiency if 1375 - * necessary */ 1376 - 1377 - /* Search for this entry in the list and update it if it is 1378 - * already there. */ 1379 - 1380 - spin_lock_irqsave(&ieee->lock, flags); 1381 - 1382 - if (is_same_network(&ieee->current_network, &network, ieee)) { 1383 - wmm_info = ieee->current_network.wmm_info; 1384 - //YJ,add,080819,for hidden ap 1385 - if (is_beacon == 0) 1386 - network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & ieee->current_network.flags); 1387 - else if (ieee->state == IEEE80211_LINKED) 1388 - ieee->NumRxBcnInPeriod++; 1389 - //YJ,add,080819,for hidden ap,end 1390 - //printk("====>network.ssid=%s cur_ssid=%s\n", network.ssid, ieee->current_network.ssid); 1391 - update_network(&ieee->current_network, &network); 1392 - } 1393 - 1394 - list_for_each_entry(target, &ieee->network_list, list) { 1395 - if (is_same_network(target, &network, ieee)) 1396 - break; 1397 - if ((oldest == NULL) || 1398 - (target->last_scanned < oldest->last_scanned)) 1399 - oldest = target; 1400 - } 1401 - 1402 - /* If we didn't find a match, then get a new network slot to initialize 1403 - * with this beacon's information */ 1404 - if (&target->list == &ieee->network_list) { 1405 - if (list_empty(&ieee->network_free_list)) { 1406 - /* If there are no more slots, expire the oldest */ 1407 - list_del(&oldest->list); 1408 - target = oldest; 1409 - IEEE80211_DEBUG_SCAN("Expired '%s' (%pM) from " 1410 - "network list.\n", 1411 - escape_essid(target->ssid, 1412 - target->ssid_len), 1413 - target->bssid); 1414 - } else { 1415 - /* Otherwise just pull from the free list */ 1416 - target = list_entry(ieee->network_free_list.next, 1417 - struct ieee80211_network, list); 1418 - list_del(ieee->network_free_list.next); 1419 - } 1420 - 1421 - 1422 - #ifdef CONFIG_IEEE80211_DEBUG 1423 - IEEE80211_DEBUG_SCAN("Adding '%s' (%pM) via %s.\n", 1424 - escape_essid(network.ssid, 1425 - network.ssid_len), 1426 - network.bssid, 1427 - WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == 1428 - IEEE80211_STYPE_PROBE_RESP ? 1429 - "PROBE RESPONSE" : "BEACON"); 1430 - #endif 1431 - 1432 - memcpy(target, &network, sizeof(*target)); 1433 - list_add_tail(&target->list, &ieee->network_list); 1434 - } else { 1435 - IEEE80211_DEBUG_SCAN("Updating '%s' (%pM) via %s.\n", 1436 - escape_essid(target->ssid, 1437 - target->ssid_len), 1438 - target->bssid, 1439 - WLAN_FC_GET_STYPE(beacon->header.frame_ctl) == 1440 - IEEE80211_STYPE_PROBE_RESP ? 1441 - "PROBE RESPONSE" : "BEACON"); 1442 - 1443 - /* we have an entry and we are going to update it. But this entry may 1444 - * be already expired. In this case we do the same as we found a new 1445 - * net and call the new_net handler 1446 - */ 1447 - renew = !time_after(target->last_scanned + ieee->scan_age, jiffies); 1448 - //YJ,add,080819,for hidden ap 1449 - if (is_beacon == 0) 1450 - network.flags = (~NETWORK_EMPTY_ESSID & network.flags)|(NETWORK_EMPTY_ESSID & target->flags); 1451 - //if(strncmp(network.ssid, "linksys-c",9) == 0) 1452 - // printk("====>2 network.ssid=%s FLAG=%d target.ssid=%s FLAG=%d\n", network.ssid, network.flags, target->ssid, target->flags); 1453 - if (((network.flags & NETWORK_EMPTY_ESSID) == NETWORK_EMPTY_ESSID) \ 1454 - && (((network.ssid_len > 0) && (strncmp(target->ssid, network.ssid, network.ssid_len)))\ 1455 - || ((ieee->current_network.ssid_len == network.ssid_len) && (strncmp(ieee->current_network.ssid, network.ssid, network.ssid_len) == 0) && (ieee->state == IEEE80211_NOLINK)))) 1456 - renew = 1; 1457 - //YJ,add,080819,for hidden ap,end 1458 - update_network(target, &network); 1459 - } 1460 - 1461 - spin_unlock_irqrestore(&ieee->lock, flags); 1462 - } 1463 - 1464 - void ieee80211_rx_mgt(struct ieee80211_device *ieee, 1465 - struct ieee80211_hdr_4addr *header, 1466 - struct ieee80211_rx_stats *stats) 1467 - { 1468 - switch (WLAN_FC_GET_STYPE(header->frame_ctl)) { 1469 - 1470 - case IEEE80211_STYPE_BEACON: 1471 - IEEE80211_DEBUG_MGMT("received BEACON (%d)\n", 1472 - WLAN_FC_GET_STYPE(header->frame_ctl)); 1473 - IEEE80211_DEBUG_SCAN("Beacon\n"); 1474 - ieee80211_process_probe_response( 1475 - ieee, (struct ieee80211_probe_response *)header, stats); 1476 - break; 1477 - 1478 - case IEEE80211_STYPE_PROBE_RESP: 1479 - IEEE80211_DEBUG_MGMT("received PROBE RESPONSE (%d)\n", 1480 - WLAN_FC_GET_STYPE(header->frame_ctl)); 1481 - IEEE80211_DEBUG_SCAN("Probe response\n"); 1482 - ieee80211_process_probe_response( 1483 - ieee, (struct ieee80211_probe_response *)header, stats); 1484 - break; 1485 - } 1486 - }
-2711
drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c
··· 1 - /* IEEE 802.11 SoftMAC layer 2 - * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com> 3 - * 4 - * Mostly extracted from the rtl8180-sa2400 driver for the 5 - * in-kernel generic ieee802.11 stack. 6 - * 7 - * Few lines might be stolen from other part of the ieee80211 8 - * stack. Copyright who own it's copyright 9 - * 10 - * WPA code stolen from the ipw2200 driver. 11 - * Copyright who own it's copyright. 12 - * 13 - * released under the GPL 14 - */ 15 - 16 - #include "ieee80211.h" 17 - 18 - #include <linux/random.h> 19 - #include <linux/delay.h> 20 - #include <linux/slab.h> 21 - #include <linux/interrupt.h> 22 - #include <linux/uaccess.h> 23 - #include <linux/etherdevice.h> 24 - 25 - #include "dot11d.h" 26 - 27 - short ieee80211_is_54g(const struct ieee80211_network *net) 28 - { 29 - return (net->rates_ex_len > 0) || (net->rates_len > 4); 30 - } 31 - 32 - short ieee80211_is_shortslot(const struct ieee80211_network *net) 33 - { 34 - return net->capability & WLAN_CAPABILITY_SHORT_SLOT; 35 - } 36 - 37 - /* returns the total length needed for placing the RATE MFIE 38 - * tag and the EXTENDED RATE MFIE tag if needed. 39 - * It encludes two bytes per tag for the tag itself and its len 40 - */ 41 - static unsigned int ieee80211_MFIE_rate_len(struct ieee80211_device *ieee) 42 - { 43 - unsigned int rate_len = 0; 44 - 45 - if (ieee->modulation & IEEE80211_CCK_MODULATION) 46 - rate_len = IEEE80211_CCK_RATE_LEN + 2; 47 - 48 - if (ieee->modulation & IEEE80211_OFDM_MODULATION) 49 - 50 - rate_len += IEEE80211_OFDM_RATE_LEN + 2; 51 - 52 - return rate_len; 53 - } 54 - 55 - /* place the MFIE rate, tag to the memory (double) poised. 56 - * Then it updates the pointer so that it points after the new MFIE tag added. 57 - */ 58 - static void ieee80211_MFIE_Brate(struct ieee80211_device *ieee, u8 **tag_p) 59 - { 60 - u8 *tag = *tag_p; 61 - 62 - if (ieee->modulation & IEEE80211_CCK_MODULATION) { 63 - *tag++ = MFIE_TYPE_RATES; 64 - *tag++ = 4; 65 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; 66 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; 67 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB; 68 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB; 69 - } 70 - 71 - /* We may add an option for custom rates that specific HW might support */ 72 - *tag_p = tag; 73 - } 74 - 75 - static void ieee80211_MFIE_Grate(struct ieee80211_device *ieee, u8 **tag_p) 76 - { 77 - u8 *tag = *tag_p; 78 - 79 - if (ieee->modulation & IEEE80211_OFDM_MODULATION) { 80 - *tag++ = MFIE_TYPE_RATES_EX; 81 - *tag++ = 8; 82 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB; 83 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB; 84 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB; 85 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB; 86 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB; 87 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB; 88 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB; 89 - *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB; 90 - 91 - } 92 - /* We may add an option for custom rates that specific HW might support */ 93 - *tag_p = tag; 94 - } 95 - 96 - static void ieee80211_WMM_Info(struct ieee80211_device *ieee, u8 **tag_p) 97 - { 98 - u8 *tag = *tag_p; 99 - 100 - *tag++ = MFIE_TYPE_GENERIC; /* 0 */ 101 - *tag++ = 7; 102 - *tag++ = 0x00; 103 - *tag++ = 0x50; 104 - *tag++ = 0xf2; 105 - *tag++ = 0x02; /* 5 */ 106 - *tag++ = 0x00; 107 - *tag++ = 0x01; 108 - #ifdef SUPPORT_USPD 109 - if (ieee->current_network.wmm_info & 0x80) 110 - *tag++ = 0x0f|MAX_SP_Len; 111 - else 112 - *tag++ = MAX_SP_Len; 113 - #else 114 - *tag++ = MAX_SP_Len; 115 - #endif 116 - *tag_p = tag; 117 - } 118 - 119 - static void ieee80211_TURBO_Info(struct ieee80211_device *ieee, u8 **tag_p) 120 - { 121 - u8 *tag = *tag_p; 122 - *tag++ = MFIE_TYPE_GENERIC; /* 0 */ 123 - *tag++ = 7; 124 - *tag++ = 0x00; 125 - *tag++ = 0xe0; 126 - *tag++ = 0x4c; 127 - *tag++ = 0x01; /* 5 */ 128 - *tag++ = 0x02; 129 - *tag++ = 0x11; 130 - *tag++ = 0x00; 131 - *tag_p = tag; 132 - printk(KERN_ALERT "This is enable turbo mode IE process\n"); 133 - } 134 - 135 - static void enqueue_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb) 136 - { 137 - int nh; 138 - nh = (ieee->mgmt_queue_head + 1) % MGMT_QUEUE_NUM; 139 - 140 - ieee->mgmt_queue_head = nh; 141 - ieee->mgmt_queue_ring[nh] = skb; 142 - } 143 - 144 - static struct sk_buff *dequeue_mgmt(struct ieee80211_device *ieee) 145 - { 146 - struct sk_buff *ret; 147 - 148 - if (ieee->mgmt_queue_tail == ieee->mgmt_queue_head) 149 - return NULL; 150 - 151 - ret = ieee->mgmt_queue_ring[ieee->mgmt_queue_tail]; 152 - 153 - ieee->mgmt_queue_tail = 154 - (ieee->mgmt_queue_tail + 1) % MGMT_QUEUE_NUM; 155 - 156 - return ret; 157 - } 158 - 159 - static void init_mgmt_queue(struct ieee80211_device *ieee) 160 - { 161 - ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0; 162 - } 163 - 164 - void ieee80211_sta_wakeup(struct ieee80211_device *ieee, short nl); 165 - 166 - inline void softmac_mgmt_xmit(struct sk_buff *skb, 167 - struct ieee80211_device *ieee) 168 - { 169 - unsigned long flags; 170 - short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE; 171 - struct ieee80211_hdr_3addr *header = 172 - (struct ieee80211_hdr_3addr *) skb->data; 173 - 174 - spin_lock_irqsave(&ieee->lock, flags); 175 - 176 - /* called with 2nd param 0, no mgmt lock required */ 177 - ieee80211_sta_wakeup(ieee, 0); 178 - 179 - if (single) { 180 - if (ieee->queue_stop) { 181 - enqueue_mgmt(ieee, skb); 182 - } else { 183 - header->seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0]<<4); 184 - 185 - if (ieee->seq_ctrl[0] == 0xFFF) 186 - ieee->seq_ctrl[0] = 0; 187 - else 188 - ieee->seq_ctrl[0]++; 189 - 190 - /* avoid watchdog triggers */ 191 - ieee->dev->trans_start = jiffies; 192 - ieee->softmac_data_hard_start_xmit(skb, ieee->dev, ieee->basic_rate); 193 - } 194 - 195 - spin_unlock_irqrestore(&ieee->lock, flags); 196 - } else { 197 - spin_unlock_irqrestore(&ieee->lock, flags); 198 - spin_lock_irqsave(&ieee->mgmt_tx_lock, flags); 199 - 200 - header->seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4); 201 - 202 - if (ieee->seq_ctrl[0] == 0xFFF) 203 - ieee->seq_ctrl[0] = 0; 204 - else 205 - ieee->seq_ctrl[0]++; 206 - 207 - /* avoid watchdog triggers */ 208 - ieee->dev->trans_start = jiffies; 209 - ieee->softmac_hard_start_xmit(skb, ieee->dev); 210 - 211 - spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags); 212 - } 213 - } 214 - 215 - inline void softmac_ps_mgmt_xmit(struct sk_buff *skb, 216 - struct ieee80211_device *ieee) 217 - { 218 - short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE; 219 - struct ieee80211_hdr_3addr *header = 220 - (struct ieee80211_hdr_3addr *) skb->data; 221 - 222 - if (single) { 223 - header->seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4); 224 - 225 - if (ieee->seq_ctrl[0] == 0xFFF) 226 - ieee->seq_ctrl[0] = 0; 227 - else 228 - ieee->seq_ctrl[0]++; 229 - 230 - /* avoid watchdog triggers */ 231 - ieee->dev->trans_start = jiffies; 232 - ieee->softmac_data_hard_start_xmit(skb, ieee->dev, ieee->basic_rate); 233 - } else { 234 - header->seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4); 235 - 236 - if (ieee->seq_ctrl[0] == 0xFFF) 237 - ieee->seq_ctrl[0] = 0; 238 - else 239 - ieee->seq_ctrl[0]++; 240 - 241 - /* avoid watchdog triggers */ 242 - ieee->dev->trans_start = jiffies; 243 - ieee->softmac_hard_start_xmit(skb, ieee->dev); 244 - } 245 - } 246 - 247 - inline struct sk_buff * 248 - ieee80211_disassociate_skb(struct ieee80211_network *beacon, 249 - struct ieee80211_device *ieee, u8 asRsn) 250 - { 251 - struct sk_buff *skb; 252 - struct ieee80211_disassoc_frame *disass; 253 - 254 - skb = dev_alloc_skb(sizeof(struct ieee80211_disassoc_frame)); 255 - if (!skb) 256 - return NULL; 257 - 258 - disass = (struct ieee80211_disassoc_frame *) skb_put(skb, sizeof(struct ieee80211_disassoc_frame)); 259 - disass->header.frame_control = cpu_to_le16(IEEE80211_STYPE_DISASSOC); 260 - disass->header.duration_id = 0; 261 - 262 - memcpy(disass->header.addr1, beacon->bssid, ETH_ALEN); 263 - memcpy(disass->header.addr2, ieee->dev->dev_addr, ETH_ALEN); 264 - memcpy(disass->header.addr3, beacon->bssid, ETH_ALEN); 265 - 266 - disass->reasoncode = asRsn; 267 - return skb; 268 - } 269 - 270 - void SendDisassociation(struct ieee80211_device *ieee, u8 *asSta, u8 asRsn) 271 - { 272 - struct ieee80211_network *beacon = &ieee->current_network; 273 - struct sk_buff *skb; 274 - skb = ieee80211_disassociate_skb(beacon, ieee, asRsn); 275 - if (skb) 276 - softmac_mgmt_xmit(skb, ieee); 277 - } 278 - 279 - inline struct sk_buff *ieee80211_probe_req(struct ieee80211_device *ieee) 280 - { 281 - unsigned int len, rate_len; 282 - u8 *tag; 283 - struct sk_buff *skb; 284 - struct ieee80211_probe_request *req; 285 - 286 - len = ieee->current_network.ssid_len; 287 - 288 - rate_len = ieee80211_MFIE_rate_len(ieee); 289 - 290 - skb = dev_alloc_skb(sizeof(struct ieee80211_probe_request) + 291 - 2 + len + rate_len); 292 - if (!skb) 293 - return NULL; 294 - 295 - req = (struct ieee80211_probe_request *) skb_put(skb, sizeof(struct ieee80211_probe_request)); 296 - req->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); 297 - req->header.duration_id = 0; /* FIXME: is this OK ? */ 298 - 299 - memset(req->header.addr1, 0xff, ETH_ALEN); 300 - memcpy(req->header.addr2, ieee->dev->dev_addr, ETH_ALEN); 301 - memset(req->header.addr3, 0xff, ETH_ALEN); 302 - 303 - tag = (u8 *) skb_put(skb, len + 2 + rate_len); 304 - 305 - *tag++ = MFIE_TYPE_SSID; 306 - *tag++ = len; 307 - memcpy(tag, ieee->current_network.ssid, len); 308 - tag += len; 309 - ieee80211_MFIE_Brate(ieee, &tag); 310 - ieee80211_MFIE_Grate(ieee, &tag); 311 - 312 - return skb; 313 - } 314 - 315 - struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee); 316 - 317 - static void ieee80211_send_beacon(struct ieee80211_device *ieee) 318 - { 319 - struct sk_buff *skb; 320 - 321 - skb = ieee80211_get_beacon_(ieee); 322 - 323 - if (skb) { 324 - softmac_mgmt_xmit(skb, ieee); 325 - ieee->softmac_stats.tx_beacons++; 326 - dev_kfree_skb_any(skb); 327 - } 328 - 329 - ieee->beacon_timer.expires = jiffies + 330 - (MSECS(ieee->current_network.beacon_interval - 5)); 331 - 332 - if (ieee->beacon_txing) 333 - add_timer(&ieee->beacon_timer); 334 - } 335 - 336 - 337 - static void ieee80211_send_beacon_cb(unsigned long _ieee) 338 - { 339 - struct ieee80211_device *ieee = 340 - (struct ieee80211_device *) _ieee; 341 - unsigned long flags; 342 - 343 - spin_lock_irqsave(&ieee->beacon_lock, flags); 344 - ieee80211_send_beacon(ieee); 345 - spin_unlock_irqrestore(&ieee->beacon_lock, flags); 346 - } 347 - 348 - static void ieee80211_send_probe(struct ieee80211_device *ieee) 349 - { 350 - struct sk_buff *skb; 351 - 352 - skb = ieee80211_probe_req(ieee); 353 - if (skb) { 354 - softmac_mgmt_xmit(skb, ieee); 355 - ieee->softmac_stats.tx_probe_rq++; 356 - } 357 - } 358 - 359 - static void ieee80211_send_probe_requests(struct ieee80211_device *ieee) 360 - { 361 - if (ieee->active_scan && (ieee->softmac_features & IEEE_SOFTMAC_PROBERQ)) { 362 - ieee80211_send_probe(ieee); 363 - ieee80211_send_probe(ieee); 364 - } 365 - } 366 - 367 - /* this performs syncro scan blocking the caller until all channels 368 - * in the allowed channel map has been checked. 369 - */ 370 - static void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee) 371 - { 372 - short ch = 0; 373 - u8 channel_map[MAX_CHANNEL_NUMBER+1]; 374 - memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1); 375 - down(&ieee->scan_sem); 376 - 377 - while (1) { 378 - do { 379 - ch++; 380 - if (ch > MAX_CHANNEL_NUMBER) 381 - goto out; /* scan completed */ 382 - 383 - } while (!channel_map[ch]); 384 - /* this function can be called in two situations 385 - * 1- We have switched to ad-hoc mode and we are 386 - * performing a complete syncro scan before conclude 387 - * there are no interesting cell and to create a 388 - * new one. In this case the link state is 389 - * IEEE80211_NOLINK until we found an interesting cell. 390 - * If so the ieee8021_new_net, called by the RX path 391 - * will set the state to IEEE80211_LINKED, so we stop 392 - * scanning 393 - * 2- We are linked and the root uses run iwlist scan. 394 - * So we switch to IEEE80211_LINKED_SCANNING to remember 395 - * that we are still logically linked (not interested in 396 - * new network events, despite for updating the net list, 397 - * but we are temporarily 'unlinked' as the driver shall 398 - * not filter RX frames and the channel is changing. 399 - * So the only situation in witch are interested is to check 400 - * if the state become LINKED because of the #1 situation 401 - */ 402 - 403 - if (ieee->state == IEEE80211_LINKED) 404 - goto out; 405 - 406 - ieee->set_chan(ieee->dev, ch); 407 - if (channel_map[ch] == 1) 408 - ieee80211_send_probe_requests(ieee); 409 - 410 - /* this prevent excessive time wait when we 411 - * need to wait for a syncro scan to end.. 412 - */ 413 - if (ieee->sync_scan_hurryup) 414 - goto out; 415 - 416 - msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME); 417 - } 418 - out: 419 - ieee->sync_scan_hurryup = 0; 420 - up(&ieee->scan_sem); 421 - if (IS_DOT11D_ENABLE(ieee)) 422 - DOT11D_ScanComplete(ieee); 423 - } 424 - 425 - void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device *ieee) 426 - { 427 - int ch; 428 - unsigned int watch_dog = 0; 429 - u8 channel_map[MAX_CHANNEL_NUMBER+1]; 430 - memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1); 431 - down(&ieee->scan_sem); 432 - ch = ieee->current_network.channel; 433 - 434 - while (1) { 435 - /* this function can be called in two situations 436 - * 1- We have switched to ad-hoc mode and we are 437 - * performing a complete syncro scan before conclude 438 - * there are no interesting cell and to create a 439 - * new one. In this case the link state is 440 - * IEEE80211_NOLINK until we found an interesting cell. 441 - * If so the ieee8021_new_net, called by the RX path 442 - * will set the state to IEEE80211_LINKED, so we stop 443 - * scanning 444 - * 2- We are linked and the root uses run iwlist scan. 445 - * So we switch to IEEE80211_LINKED_SCANNING to remember 446 - * that we are still logically linked (not interested in 447 - * new network events, despite for updating the net list, 448 - * but we are temporarily 'unlinked' as the driver shall 449 - * not filter RX frames and the channel is changing. 450 - * So the only situation in witch are interested is to check 451 - * if the state become LINKED because of the #1 situation 452 - */ 453 - if (ieee->state == IEEE80211_LINKED) 454 - goto out; 455 - 456 - if (channel_map[ieee->current_network.channel] > 0) 457 - ieee->set_chan(ieee->dev, ieee->current_network.channel); 458 - 459 - if (channel_map[ieee->current_network.channel] == 1) 460 - ieee80211_send_probe_requests(ieee); 461 - 462 - msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME); 463 - 464 - do { 465 - if (watch_dog++ >= MAX_CHANNEL_NUMBER) 466 - goto out; /* scan completed */ 467 - 468 - ieee->current_network.channel = (ieee->current_network.channel + 1)%MAX_CHANNEL_NUMBER; 469 - } while (!channel_map[ieee->current_network.channel]); 470 - } 471 - out: 472 - ieee->actscanning = false; 473 - up(&ieee->scan_sem); 474 - if (IS_DOT11D_ENABLE(ieee)) 475 - DOT11D_ScanComplete(ieee); 476 - } 477 - 478 - static void ieee80211_softmac_scan_wq(struct work_struct *work) 479 - { 480 - struct delayed_work *dwork = to_delayed_work(work); 481 - struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq); 482 - static short watchdog; 483 - u8 channel_map[MAX_CHANNEL_NUMBER+1]; 484 - memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1); 485 - down(&ieee->scan_sem); 486 - 487 - do { 488 - ieee->current_network.channel = 489 - (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER; 490 - if (watchdog++ > MAX_CHANNEL_NUMBER) 491 - goto out; /* no good chans */ 492 - } while (!channel_map[ieee->current_network.channel]); 493 - 494 - if (ieee->scanning == 0) { 495 - printk("error out, scanning = 0\n"); 496 - goto out; 497 - } 498 - ieee->set_chan(ieee->dev, ieee->current_network.channel); 499 - if (channel_map[ieee->current_network.channel] == 1) 500 - ieee80211_send_probe_requests(ieee); 501 - 502 - queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME); 503 - up(&ieee->scan_sem); 504 - return; 505 - out: 506 - ieee->actscanning = false; 507 - watchdog = 0; 508 - ieee->scanning = 0; 509 - up(&ieee->scan_sem); 510 - 511 - if (IS_DOT11D_ENABLE(ieee)) 512 - DOT11D_ScanComplete(ieee); 513 - return; 514 - } 515 - 516 - static void ieee80211_beacons_start(struct ieee80211_device *ieee) 517 - { 518 - unsigned long flags; 519 - 520 - spin_lock_irqsave(&ieee->beacon_lock, flags); 521 - 522 - ieee->beacon_txing = 1; 523 - ieee80211_send_beacon(ieee); 524 - 525 - spin_unlock_irqrestore(&ieee->beacon_lock, flags); 526 - } 527 - 528 - static void ieee80211_beacons_stop(struct ieee80211_device *ieee) 529 - { 530 - unsigned long flags; 531 - 532 - spin_lock_irqsave(&ieee->beacon_lock, flags); 533 - 534 - ieee->beacon_txing = 0; 535 - del_timer_sync(&ieee->beacon_timer); 536 - 537 - spin_unlock_irqrestore(&ieee->beacon_lock, flags); 538 - } 539 - 540 - void ieee80211_stop_send_beacons(struct ieee80211_device *ieee) 541 - { 542 - if (ieee->stop_send_beacons) 543 - ieee->stop_send_beacons(ieee->dev); 544 - if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS) 545 - ieee80211_beacons_stop(ieee); 546 - } 547 - 548 - void ieee80211_start_send_beacons(struct ieee80211_device *ieee) 549 - { 550 - if (ieee->start_send_beacons) 551 - ieee->start_send_beacons(ieee->dev); 552 - if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS) 553 - ieee80211_beacons_start(ieee); 554 - } 555 - 556 - static void ieee80211_softmac_stop_scan(struct ieee80211_device *ieee) 557 - { 558 - down(&ieee->scan_sem); 559 - 560 - if (ieee->scanning == 1) { 561 - ieee->scanning = 0; 562 - cancel_delayed_work(&ieee->softmac_scan_wq); 563 - } 564 - 565 - up(&ieee->scan_sem); 566 - } 567 - 568 - void ieee80211_stop_scan(struct ieee80211_device *ieee) 569 - { 570 - if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) 571 - ieee80211_softmac_stop_scan(ieee); 572 - else 573 - ieee->stop_scan(ieee->dev); 574 - } 575 - 576 - /* called with ieee->lock held */ 577 - void ieee80211_rtl_start_scan(struct ieee80211_device *ieee) 578 - { 579 - if (IS_DOT11D_ENABLE(ieee)) { 580 - if (IS_COUNTRY_IE_VALID(ieee)) 581 - RESET_CIE_WATCHDOG(ieee); 582 - } 583 - 584 - if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) { 585 - if (ieee->scanning == 0) { 586 - ieee->scanning = 1; 587 - #if 1 588 - queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, 0); 589 - #endif 590 - } 591 - }else 592 - ieee->start_scan(ieee->dev); 593 - } 594 - 595 - /* called with wx_sem held */ 596 - void ieee80211_start_scan_syncro(struct ieee80211_device *ieee) 597 - { 598 - if (IS_DOT11D_ENABLE(ieee)) { 599 - if (IS_COUNTRY_IE_VALID(ieee)) 600 - RESET_CIE_WATCHDOG(ieee); 601 - } 602 - ieee->sync_scan_hurryup = 0; 603 - 604 - if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) 605 - ieee80211_softmac_scan_syncro(ieee); 606 - else 607 - ieee->scan_syncro(ieee->dev); 608 - } 609 - 610 - inline struct sk_buff * 611 - ieee80211_authentication_req(struct ieee80211_network *beacon, 612 - struct ieee80211_device *ieee, int challengelen) 613 - { 614 - struct sk_buff *skb; 615 - struct ieee80211_authentication *auth; 616 - 617 - skb = dev_alloc_skb(sizeof(struct ieee80211_authentication) + challengelen); 618 - 619 - if (!skb) 620 - return NULL; 621 - 622 - auth = (struct ieee80211_authentication *) 623 - skb_put(skb, sizeof(struct ieee80211_authentication)); 624 - 625 - auth->header.frame_ctl = IEEE80211_STYPE_AUTH; 626 - if (challengelen) 627 - auth->header.frame_ctl |= IEEE80211_FCTL_WEP; 628 - 629 - auth->header.duration_id = 0x013a; /* FIXME */ 630 - 631 - memcpy(auth->header.addr1, beacon->bssid, ETH_ALEN); 632 - memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN); 633 - memcpy(auth->header.addr3, beacon->bssid, ETH_ALEN); 634 - 635 - auth->algorithm = ieee->open_wep ? WLAN_AUTH_OPEN : WLAN_AUTH_SHARED_KEY; 636 - 637 - auth->transaction = cpu_to_le16(ieee->associate_seq); 638 - ieee->associate_seq++; 639 - 640 - auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS); 641 - 642 - return skb; 643 - } 644 - 645 - static struct sk_buff *ieee80211_probe_resp(struct ieee80211_device *ieee, 646 - u8 *dest) 647 - { 648 - u8 *tag; 649 - int beacon_size; 650 - struct ieee80211_probe_response *beacon_buf; 651 - struct sk_buff *skb; 652 - int encrypt; 653 - int atim_len, erp_len; 654 - struct ieee80211_crypt_data *crypt; 655 - 656 - char *ssid = ieee->current_network.ssid; 657 - int ssid_len = ieee->current_network.ssid_len; 658 - int rate_len = ieee->current_network.rates_len+2; 659 - int rate_ex_len = ieee->current_network.rates_ex_len; 660 - int wpa_ie_len = ieee->wpa_ie_len; 661 - if (rate_ex_len > 0) 662 - rate_ex_len += 2; 663 - 664 - if (ieee->current_network.capability & WLAN_CAPABILITY_IBSS) 665 - atim_len = 4; 666 - else 667 - atim_len = 0; 668 - 669 - if (ieee80211_is_54g(&ieee->current_network)) 670 - erp_len = 3; 671 - else 672 - erp_len = 0; 673 - 674 - beacon_size = sizeof(struct ieee80211_probe_response)+ 675 - ssid_len 676 - +3 /* channel */ 677 - +rate_len 678 - +rate_ex_len 679 - +atim_len 680 - +wpa_ie_len 681 - +erp_len; 682 - 683 - skb = dev_alloc_skb(beacon_size); 684 - 685 - if (!skb) 686 - return NULL; 687 - 688 - beacon_buf = (struct ieee80211_probe_response *) skb_put(skb, beacon_size); 689 - 690 - memcpy(beacon_buf->header.addr1, dest, ETH_ALEN); 691 - memcpy(beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN); 692 - memcpy(beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN); 693 - 694 - beacon_buf->header.duration_id = 0; /* FIXME */ 695 - beacon_buf->beacon_interval = 696 - cpu_to_le16(ieee->current_network.beacon_interval); 697 - beacon_buf->capability = 698 - cpu_to_le16(ieee->current_network.capability & WLAN_CAPABILITY_IBSS); 699 - 700 - if (ieee->short_slot && (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_SLOT)) 701 - beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT); 702 - 703 - crypt = ieee->crypt[ieee->tx_keyidx]; 704 - 705 - encrypt = ieee->host_encrypt && crypt && crypt->ops && 706 - ((0 == strcmp(crypt->ops->name, "WEP")) || wpa_ie_len); 707 - 708 - if (encrypt) 709 - beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); 710 - 711 - 712 - beacon_buf->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_RESP); 713 - 714 - beacon_buf->info_element.id = MFIE_TYPE_SSID; 715 - beacon_buf->info_element.len = ssid_len; 716 - 717 - tag = (u8 *) beacon_buf->info_element.data; 718 - 719 - memcpy(tag, ssid, ssid_len); 720 - 721 - tag += ssid_len; 722 - 723 - *(tag++) = MFIE_TYPE_RATES; 724 - *(tag++) = rate_len - 2; 725 - memcpy(tag, ieee->current_network.rates, rate_len-2); 726 - tag += rate_len - 2; 727 - 728 - *(tag++) = MFIE_TYPE_DS_SET; 729 - *(tag++) = 1; 730 - *(tag++) = ieee->current_network.channel; 731 - 732 - if (atim_len) { 733 - *(tag++) = MFIE_TYPE_IBSS_SET; 734 - *(tag++) = 2; 735 - *((u16 *)(tag)) = cpu_to_le16(ieee->current_network.atim_window); 736 - tag += 2; 737 - } 738 - 739 - if (erp_len) { 740 - *(tag++) = MFIE_TYPE_ERP; 741 - *(tag++) = 1; 742 - *(tag++) = 0; 743 - } 744 - 745 - if (rate_ex_len) { 746 - *(tag++) = MFIE_TYPE_RATES_EX; 747 - *(tag++) = rate_ex_len-2; 748 - memcpy(tag, ieee->current_network.rates_ex, rate_ex_len-2); 749 - tag += rate_ex_len - 2; 750 - } 751 - 752 - if (wpa_ie_len) { 753 - if (ieee->iw_mode == IW_MODE_ADHOC) { 754 - /* as Windows will set pairwise key same as the group 755 - * key which is not allowed in Linux, so set this for 756 - * IOT issue. 757 - */ 758 - memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4); 759 - } 760 - 761 - memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len); 762 - } 763 - skb->dev = ieee->dev; 764 - return skb; 765 - } 766 - 767 - static struct sk_buff *ieee80211_assoc_resp(struct ieee80211_device *ieee, 768 - u8 *dest) 769 - { 770 - struct sk_buff *skb; 771 - u8 *tag; 772 - 773 - struct ieee80211_crypt_data *crypt; 774 - struct ieee80211_assoc_response_frame *assoc; 775 - short encrypt; 776 - 777 - unsigned int rate_len = ieee80211_MFIE_rate_len(ieee); 778 - int len = sizeof(struct ieee80211_assoc_response_frame) + rate_len; 779 - 780 - skb = dev_alloc_skb(len); 781 - 782 - if (!skb) 783 - return NULL; 784 - 785 - assoc = (struct ieee80211_assoc_response_frame *) 786 - skb_put(skb, sizeof(struct ieee80211_assoc_response_frame)); 787 - 788 - assoc->header.frame_control = cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP); 789 - memcpy(assoc->header.addr1, dest, ETH_ALEN); 790 - memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN); 791 - memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN); 792 - assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ? 793 - WLAN_CAPABILITY_BSS : WLAN_CAPABILITY_IBSS); 794 - 795 - if (ieee->short_slot) 796 - assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT); 797 - 798 - if (ieee->host_encrypt) 799 - crypt = ieee->crypt[ieee->tx_keyidx]; 800 - else 801 - crypt = NULL; 802 - 803 - encrypt = (crypt && crypt->ops); 804 - 805 - if (encrypt) 806 - assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); 807 - 808 - assoc->status = 0; 809 - assoc->aid = cpu_to_le16(ieee->assoc_id); 810 - if (ieee->assoc_id == 0x2007) 811 - ieee->assoc_id = 0; 812 - else 813 - ieee->assoc_id++; 814 - 815 - tag = (u8 *) skb_put(skb, rate_len); 816 - 817 - ieee80211_MFIE_Brate(ieee, &tag); 818 - ieee80211_MFIE_Grate(ieee, &tag); 819 - 820 - return skb; 821 - } 822 - 823 - static struct sk_buff *ieee80211_auth_resp(struct ieee80211_device *ieee, 824 - int status, u8 *dest) 825 - { 826 - struct sk_buff *skb; 827 - struct ieee80211_authentication *auth; 828 - 829 - skb = dev_alloc_skb(sizeof(struct ieee80211_authentication)+1); 830 - 831 - if (!skb) 832 - return NULL; 833 - 834 - skb->len = sizeof(struct ieee80211_authentication); 835 - 836 - auth = (struct ieee80211_authentication *)skb->data; 837 - 838 - auth->status = cpu_to_le16(status); 839 - auth->transaction = cpu_to_le16(2); 840 - auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN); 841 - 842 - memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN); 843 - memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN); 844 - memcpy(auth->header.addr1, dest, ETH_ALEN); 845 - auth->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_AUTH); 846 - return skb; 847 - } 848 - 849 - static struct sk_buff *ieee80211_null_func(struct ieee80211_device *ieee, short pwr) 850 - { 851 - struct sk_buff *skb; 852 - struct ieee80211_hdr_3addr *hdr; 853 - 854 - skb = dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr)); 855 - 856 - if (!skb) 857 - return NULL; 858 - 859 - hdr = (struct ieee80211_hdr_3addr *)skb_put(skb, sizeof(struct ieee80211_hdr_3addr)); 860 - 861 - memcpy(hdr->addr1, ieee->current_network.bssid, ETH_ALEN); 862 - memcpy(hdr->addr2, ieee->dev->dev_addr, ETH_ALEN); 863 - memcpy(hdr->addr3, ieee->current_network.bssid, ETH_ALEN); 864 - 865 - hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | 866 - IEEE80211_STYPE_NULLFUNC | IEEE80211_FCTL_TODS | 867 - (pwr ? IEEE80211_FCTL_PM:0)); 868 - 869 - return skb; 870 - } 871 - 872 - static void ieee80211_resp_to_assoc_rq(struct ieee80211_device *ieee, u8 *dest) 873 - { 874 - struct sk_buff *buf = ieee80211_assoc_resp(ieee, dest); 875 - 876 - if (buf) { 877 - softmac_mgmt_xmit(buf, ieee); 878 - dev_kfree_skb_any(buf); 879 - } 880 - } 881 - 882 - static void ieee80211_resp_to_auth(struct ieee80211_device *ieee, int s, u8 *dest) 883 - { 884 - struct sk_buff *buf = ieee80211_auth_resp(ieee, s, dest); 885 - 886 - if (buf) { 887 - softmac_mgmt_xmit(buf, ieee); 888 - dev_kfree_skb_any(buf); 889 - } 890 - } 891 - 892 - static void ieee80211_resp_to_probe(struct ieee80211_device *ieee, u8 *dest) 893 - { 894 - struct sk_buff *buf = ieee80211_probe_resp(ieee, dest); 895 - 896 - if (buf) { 897 - softmac_mgmt_xmit(buf, ieee); 898 - dev_kfree_skb_any(buf); 899 - } 900 - } 901 - 902 - inline struct sk_buff * 903 - ieee80211_association_req(struct ieee80211_network *beacon, 904 - struct ieee80211_device *ieee) 905 - { 906 - struct sk_buff *skb; 907 - 908 - struct ieee80211_assoc_request_frame *hdr; 909 - u8 *tag; 910 - unsigned int wpa_len = beacon->wpa_ie_len; 911 - #if 1 912 - /* for testing purpose */ 913 - unsigned int rsn_len = beacon->rsn_ie_len; 914 - #endif 915 - unsigned int rate_len = ieee80211_MFIE_rate_len(ieee); 916 - unsigned int wmm_info_len = beacon->QoS_Enable?9:0; 917 - unsigned int turbo_info_len = beacon->Turbo_Enable?9:0; 918 - 919 - u8 encry_proto = ieee->wpax_type_notify & 0xff; 920 - 921 - int len = 0; 922 - 923 - /* [0] Notify type of encryption: WPA/WPA2 924 - * [1] pair wise type 925 - * [2] authen type 926 - */ 927 - if (ieee->wpax_type_set) { 928 - if (IEEE_PROTO_WPA == encry_proto) { 929 - rsn_len = 0; 930 - } else if (IEEE_PROTO_RSN == encry_proto) { 931 - wpa_len = 0; 932 - } 933 - } 934 - len = sizeof(struct ieee80211_assoc_request_frame)+ 935 - + beacon->ssid_len /* essid tagged val */ 936 - + rate_len /* rates tagged val */ 937 - + wpa_len 938 - + rsn_len 939 - + wmm_info_len 940 - + turbo_info_len; 941 - 942 - skb = dev_alloc_skb(len); 943 - 944 - if (!skb) 945 - return NULL; 946 - 947 - hdr = (struct ieee80211_assoc_request_frame *) 948 - skb_put(skb, sizeof(struct ieee80211_assoc_request_frame)); 949 - 950 - hdr->header.frame_control = IEEE80211_STYPE_ASSOC_REQ; 951 - hdr->header.duration_id = 37; /* FIXME */ 952 - memcpy(hdr->header.addr1, beacon->bssid, ETH_ALEN); 953 - memcpy(hdr->header.addr2, ieee->dev->dev_addr, ETH_ALEN); 954 - memcpy(hdr->header.addr3, beacon->bssid, ETH_ALEN); 955 - memcpy(ieee->ap_mac_addr, beacon->bssid, ETH_ALEN); /* for HW security */ 956 - 957 - hdr->capability = cpu_to_le16(WLAN_CAPABILITY_BSS); 958 - if (beacon->capability & WLAN_CAPABILITY_PRIVACY) 959 - hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); 960 - if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) 961 - hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); 962 - 963 - if (ieee->short_slot) 964 - hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT); 965 - 966 - hdr->listen_interval = 0xa; /* FIXME */ 967 - 968 - hdr->info_element.id = MFIE_TYPE_SSID; 969 - 970 - hdr->info_element.len = beacon->ssid_len; 971 - tag = skb_put(skb, beacon->ssid_len); 972 - memcpy(tag, beacon->ssid, beacon->ssid_len); 973 - 974 - tag = skb_put(skb, rate_len); 975 - 976 - ieee80211_MFIE_Brate(ieee, &tag); 977 - ieee80211_MFIE_Grate(ieee, &tag); 978 - 979 - /* add rsn==0 condition for ap's mix security mode(wpa+wpa2) 980 - * choose AES encryption as default algorithm while using mixed mode. 981 - */ 982 - 983 - tag = skb_put(skb, ieee->wpa_ie_len); 984 - memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len); 985 - 986 - tag = skb_put(skb, wmm_info_len); 987 - if (wmm_info_len) 988 - ieee80211_WMM_Info(ieee, &tag); 989 - 990 - tag = skb_put(skb, turbo_info_len); 991 - if (turbo_info_len) 992 - ieee80211_TURBO_Info(ieee, &tag); 993 - 994 - return skb; 995 - } 996 - 997 - void ieee80211_associate_abort(struct ieee80211_device *ieee) 998 - { 999 - unsigned long flags; 1000 - spin_lock_irqsave(&ieee->lock, flags); 1001 - 1002 - ieee->associate_seq++; 1003 - 1004 - /* don't scan, and avoid to have the RX path possibly 1005 - * try again to associate. Even do not react to AUTH or 1006 - * ASSOC response. Just wait for the retry wq to be scheduled. 1007 - * Here we will check if there are good nets to associate 1008 - * with, so we retry or just get back to NO_LINK and scanning 1009 - */ 1010 - if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING) { 1011 - IEEE80211_DEBUG_MGMT("Authentication failed\n"); 1012 - ieee->softmac_stats.no_auth_rs++; 1013 - } else { 1014 - IEEE80211_DEBUG_MGMT("Association failed\n"); 1015 - ieee->softmac_stats.no_ass_rs++; 1016 - } 1017 - 1018 - ieee->state = IEEE80211_ASSOCIATING_RETRY; 1019 - 1020 - queue_delayed_work(ieee->wq, &ieee->associate_retry_wq, IEEE80211_SOFTMAC_ASSOC_RETRY_TIME); 1021 - 1022 - spin_unlock_irqrestore(&ieee->lock, flags); 1023 - } 1024 - 1025 - static void ieee80211_associate_abort_cb(unsigned long dev) 1026 - { 1027 - ieee80211_associate_abort((struct ieee80211_device *) dev); 1028 - } 1029 - 1030 - static void ieee80211_associate_step1(struct ieee80211_device *ieee) 1031 - { 1032 - struct ieee80211_network *beacon = &ieee->current_network; 1033 - struct sk_buff *skb; 1034 - 1035 - IEEE80211_DEBUG_MGMT("Stopping scan\n"); 1036 - ieee->softmac_stats.tx_auth_rq++; 1037 - skb = ieee80211_authentication_req(beacon, ieee, 0); 1038 - if (!skb) { 1039 - ieee80211_associate_abort(ieee); 1040 - } else { 1041 - ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATING; 1042 - IEEE80211_DEBUG_MGMT("Sending authentication request\n"); 1043 - softmac_mgmt_xmit(skb, ieee); 1044 - /* BUGON when you try to add_timer twice, using mod_timer may 1045 - * be better. 1046 - */ 1047 - if (!timer_pending(&ieee->associate_timer)) { 1048 - ieee->associate_timer.expires = jiffies + (HZ / 2); 1049 - add_timer(&ieee->associate_timer); 1050 - } 1051 - /* If call dev_kfree_skb_any,a warning will ocur.... 1052 - * KERNEL: assertion (!atomic_read(&skb->users)) failed at 1053 - * net/core/dev.c (1708) 1054 - */ 1055 - } 1056 - } 1057 - 1058 - static void ieee80211_rtl_auth_challenge(struct ieee80211_device *ieee, u8 *challenge, 1059 - int chlen) 1060 - { 1061 - u8 *c; 1062 - struct sk_buff *skb; 1063 - struct ieee80211_network *beacon = &ieee->current_network; 1064 - del_timer_sync(&ieee->associate_timer); 1065 - ieee->associate_seq++; 1066 - ieee->softmac_stats.tx_auth_rq++; 1067 - 1068 - skb = ieee80211_authentication_req(beacon, ieee, chlen+2); 1069 - if (!skb) 1070 - ieee80211_associate_abort(ieee); 1071 - else { 1072 - c = skb_put(skb, chlen+2); 1073 - *(c++) = MFIE_TYPE_CHALLENGE; 1074 - *(c++) = chlen; 1075 - memcpy(c, challenge, chlen); 1076 - 1077 - IEEE80211_DEBUG_MGMT("Sending authentication challenge response\n"); 1078 - 1079 - ieee80211_encrypt_fragment(ieee, skb, sizeof(struct ieee80211_hdr_3addr)); 1080 - 1081 - softmac_mgmt_xmit(skb, ieee); 1082 - if (!timer_pending(&ieee->associate_timer)) { 1083 - ieee->associate_timer.expires = jiffies + (HZ / 2); 1084 - add_timer(&ieee->associate_timer); 1085 - } 1086 - dev_kfree_skb_any(skb); 1087 - } 1088 - kfree(challenge); 1089 - } 1090 - 1091 - static void ieee80211_associate_step2(struct ieee80211_device *ieee) 1092 - { 1093 - struct sk_buff *skb; 1094 - struct ieee80211_network *beacon = &ieee->current_network; 1095 - 1096 - del_timer_sync(&ieee->associate_timer); 1097 - 1098 - IEEE80211_DEBUG_MGMT("Sending association request\n"); 1099 - ieee->softmac_stats.tx_ass_rq++; 1100 - skb = ieee80211_association_req(beacon, ieee); 1101 - if (!skb) 1102 - ieee80211_associate_abort(ieee); 1103 - else { 1104 - softmac_mgmt_xmit(skb, ieee); 1105 - if (!timer_pending(&ieee->associate_timer)) { 1106 - ieee->associate_timer.expires = jiffies + (HZ / 2); 1107 - add_timer(&ieee->associate_timer); 1108 - } 1109 - } 1110 - } 1111 - 1112 - static void ieee80211_associate_complete_wq(struct work_struct *work) 1113 - { 1114 - struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_complete_wq); 1115 - 1116 - printk(KERN_INFO "Associated successfully\n"); 1117 - if (ieee80211_is_54g(&ieee->current_network) && 1118 - (ieee->modulation & IEEE80211_OFDM_MODULATION)) { 1119 - ieee->rate = 540; 1120 - printk(KERN_INFO"Using G rates\n"); 1121 - } else { 1122 - ieee->rate = 110; 1123 - printk(KERN_INFO"Using B rates\n"); 1124 - } 1125 - ieee->link_change(ieee->dev); 1126 - notify_wx_assoc_event(ieee); 1127 - if (ieee->data_hard_resume) 1128 - ieee->data_hard_resume(ieee->dev); 1129 - netif_carrier_on(ieee->dev); 1130 - } 1131 - 1132 - static void ieee80211_associate_complete(struct ieee80211_device *ieee) 1133 - { 1134 - del_timer_sync(&ieee->associate_timer); 1135 - 1136 - ieee->state = IEEE80211_LINKED; 1137 - IEEE80211_DEBUG_MGMT("Successfully associated\n"); 1138 - 1139 - queue_work(ieee->wq, &ieee->associate_complete_wq); 1140 - } 1141 - 1142 - static void ieee80211_associate_procedure_wq(struct work_struct *work) 1143 - { 1144 - struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_procedure_wq); 1145 - 1146 - ieee->sync_scan_hurryup = 1; 1147 - down(&ieee->wx_sem); 1148 - 1149 - if (ieee->data_hard_stop) 1150 - ieee->data_hard_stop(ieee->dev); 1151 - 1152 - ieee80211_stop_scan(ieee); 1153 - ieee->set_chan(ieee->dev, ieee->current_network.channel); 1154 - 1155 - ieee->associate_seq = 1; 1156 - ieee80211_associate_step1(ieee); 1157 - 1158 - up(&ieee->wx_sem); 1159 - } 1160 - 1161 - inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, 1162 - struct ieee80211_network *net) 1163 - { 1164 - u8 tmp_ssid[IW_ESSID_MAX_SIZE+1]; 1165 - int tmp_ssid_len = 0; 1166 - 1167 - short apset, ssidset, ssidbroad, apmatch, ssidmatch; 1168 - 1169 - /* we are interested in new new only if we are not associated 1170 - * and we are not associating / authenticating 1171 - */ 1172 - if (ieee->state != IEEE80211_NOLINK) 1173 - return; 1174 - 1175 - if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability & WLAN_CAPABILITY_BSS)) 1176 - return; 1177 - 1178 - if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability & WLAN_CAPABILITY_IBSS)) 1179 - return; 1180 - 1181 - if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) { 1182 - /* if the user specified the AP MAC, we need also the essid 1183 - * This could be obtained by beacons or, if the network does not 1184 - * broadcast it, it can be put manually. 1185 - */ 1186 - apset = ieee->wap_set; 1187 - ssidset = ieee->ssid_set; 1188 - ssidbroad = !(net->ssid_len == 0 || net->ssid[0] == '\0'); 1189 - apmatch = (memcmp(ieee->current_network.bssid, net->bssid, ETH_ALEN) == 0); 1190 - 1191 - if (ieee->current_network.ssid_len != net->ssid_len) 1192 - ssidmatch = 0; 1193 - else 1194 - ssidmatch = (0 == strncmp(ieee->current_network.ssid, net->ssid, net->ssid_len)); 1195 - 1196 - /* if the user set the AP check if match. 1197 - * if the network does not broadcast essid we check the user 1198 - * supplied ANY essid 1199 - * if the network does broadcast and the user does not set essid 1200 - * it is OK 1201 - * if the network does broadcast and the user did set essid 1202 - * chech if essid match 1203 - * (apset && apmatch && ((ssidset && ssidbroad && ssidmatch) || 1204 - * (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) || 1205 - * if the ap is not set, check that the user set the bssid and 1206 - * the network does broadcast and that those two bssid matches 1207 - * (!apset && ssidset && ssidbroad && ssidmatch) 1208 - */ 1209 - if ((apset && apmatch && ((ssidset && ssidbroad && ssidmatch) || 1210 - (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) || 1211 - (!apset && ssidset && ssidbroad && ssidmatch)) { 1212 - /* if the essid is hidden replace it with the 1213 - * essid provided by the user. 1214 - */ 1215 - if (!ssidbroad) { 1216 - strncpy(tmp_ssid, ieee->current_network.ssid, IW_ESSID_MAX_SIZE); 1217 - tmp_ssid_len = ieee->current_network.ssid_len; 1218 - } 1219 - memcpy(&ieee->current_network, net, sizeof(struct ieee80211_network)); 1220 - 1221 - if (!ssidbroad) { 1222 - strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE); 1223 - ieee->current_network.ssid_len = tmp_ssid_len; 1224 - } 1225 - printk(KERN_INFO"Linking with %s: channel is %d\n", ieee->current_network.ssid, ieee->current_network.channel); 1226 - 1227 - if (ieee->iw_mode == IW_MODE_INFRA) { 1228 - ieee->state = IEEE80211_ASSOCIATING; 1229 - ieee->beinretry = false; 1230 - queue_work(ieee->wq, &ieee->associate_procedure_wq); 1231 - } else { 1232 - if (ieee80211_is_54g(&ieee->current_network) && 1233 - (ieee->modulation & IEEE80211_OFDM_MODULATION)) { 1234 - ieee->rate = 540; 1235 - printk(KERN_INFO"Using G rates\n"); 1236 - } else { 1237 - ieee->rate = 110; 1238 - printk(KERN_INFO"Using B rates\n"); 1239 - } 1240 - ieee->state = IEEE80211_LINKED; 1241 - ieee->beinretry = false; 1242 - } 1243 - } 1244 - } 1245 - } 1246 - 1247 - void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee) 1248 - { 1249 - unsigned long flags; 1250 - struct ieee80211_network *target; 1251 - 1252 - spin_lock_irqsave(&ieee->lock, flags); 1253 - list_for_each_entry(target, &ieee->network_list, list) { 1254 - /* if the state become different that NOLINK means 1255 - * we had found what we are searching for 1256 - */ 1257 - if (ieee->state != IEEE80211_NOLINK) 1258 - break; 1259 - 1260 - if (ieee->scan_age == 0 || time_after(target->last_scanned + ieee->scan_age, jiffies)) 1261 - ieee80211_softmac_new_net(ieee, target); 1262 - } 1263 - spin_unlock_irqrestore(&ieee->lock, flags); 1264 - } 1265 - 1266 - static inline u16 auth_parse(struct sk_buff *skb, u8 **challenge, int *chlen) 1267 - { 1268 - struct ieee80211_authentication *a; 1269 - u8 *t; 1270 - if (skb->len < (sizeof(struct ieee80211_authentication) - sizeof(struct ieee80211_info_element))) { 1271 - IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len); 1272 - return 0xcafe; 1273 - } 1274 - *challenge = NULL; 1275 - a = (struct ieee80211_authentication *) skb->data; 1276 - if (skb->len > (sizeof(struct ieee80211_authentication) + 3)) { 1277 - t = skb->data + sizeof(struct ieee80211_authentication); 1278 - 1279 - if (*(t++) == MFIE_TYPE_CHALLENGE) { 1280 - *chlen = *(t++); 1281 - *challenge = kmemdup(t, *chlen, GFP_ATOMIC); 1282 - if (!*challenge) 1283 - return -ENOMEM; 1284 - } 1285 - } 1286 - return cpu_to_le16(a->status); 1287 - } 1288 - 1289 - static int auth_rq_parse(struct sk_buff *skb, u8 *dest) 1290 - { 1291 - struct ieee80211_authentication *a; 1292 - 1293 - if (skb->len < (sizeof(struct ieee80211_authentication) - sizeof(struct ieee80211_info_element))) { 1294 - IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n", skb->len); 1295 - return -1; 1296 - } 1297 - a = (struct ieee80211_authentication *) skb->data; 1298 - 1299 - memcpy(dest, a->header.addr2, ETH_ALEN); 1300 - 1301 - if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN) 1302 - return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; 1303 - 1304 - return WLAN_STATUS_SUCCESS; 1305 - } 1306 - 1307 - static short probe_rq_parse(struct ieee80211_device *ieee, struct sk_buff *skb, 1308 - u8 *src) 1309 - { 1310 - u8 *tag; 1311 - u8 *skbend; 1312 - u8 *ssid = NULL; 1313 - u8 ssidlen = 0; 1314 - 1315 - struct ieee80211_hdr_3addr *header = 1316 - (struct ieee80211_hdr_3addr *) skb->data; 1317 - 1318 - if (skb->len < sizeof(struct ieee80211_hdr_3addr)) 1319 - return -1; /* corrupted */ 1320 - 1321 - memcpy(src, header->addr2, ETH_ALEN); 1322 - 1323 - skbend = (u8 *)skb->data + skb->len; 1324 - 1325 - tag = skb->data + sizeof(struct ieee80211_hdr_3addr); 1326 - 1327 - while (tag+1 < skbend) { 1328 - if (*tag == 0) { 1329 - ssid = tag+2; 1330 - ssidlen = *(tag+1); 1331 - break; 1332 - } 1333 - tag++; /* point to the len field */ 1334 - tag = tag + *(tag); /* point to the last data byte of the tag */ 1335 - tag++; /* point to the next tag */ 1336 - } 1337 - 1338 - if (ssidlen == 0) 1339 - return 1; 1340 - 1341 - if (!ssid) 1342 - return 1; /* ssid not found in tagged param */ 1343 - 1344 - return (!strncmp(ssid, ieee->current_network.ssid, ssidlen)); 1345 - 1346 - } 1347 - 1348 - static int assoc_rq_parse(struct sk_buff *skb, u8 *dest) 1349 - { 1350 - struct ieee80211_assoc_request_frame *a; 1351 - 1352 - if (skb->len < (sizeof(struct ieee80211_assoc_request_frame) - 1353 - sizeof(struct ieee80211_info_element))) { 1354 - 1355 - IEEE80211_DEBUG_MGMT("invalid len in auth request:%d\n", skb->len); 1356 - return -1; 1357 - } 1358 - 1359 - a = (struct ieee80211_assoc_request_frame *) skb->data; 1360 - 1361 - memcpy(dest, a->header.addr2, ETH_ALEN); 1362 - 1363 - return 0; 1364 - } 1365 - 1366 - static inline u16 assoc_parse(struct sk_buff *skb, int *aid) 1367 - { 1368 - struct ieee80211_assoc_response_frame *a; 1369 - if (skb->len < sizeof(struct ieee80211_assoc_response_frame)) { 1370 - IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len); 1371 - return 0xcafe; 1372 - } 1373 - 1374 - a = (struct ieee80211_assoc_response_frame *) skb->data; 1375 - *aid = le16_to_cpu(a->aid) & 0x3fff; 1376 - return le16_to_cpu(a->status); 1377 - } 1378 - 1379 - static inline void ieee80211_rx_probe_rq(struct ieee80211_device *ieee, 1380 - struct sk_buff *skb) 1381 - { 1382 - u8 dest[ETH_ALEN]; 1383 - 1384 - ieee->softmac_stats.rx_probe_rq++; 1385 - if (probe_rq_parse(ieee, skb, dest)) { 1386 - ieee->softmac_stats.tx_probe_rs++; 1387 - ieee80211_resp_to_probe(ieee, dest); 1388 - } 1389 - } 1390 - 1391 - inline void ieee80211_rx_auth_rq(struct ieee80211_device *ieee, 1392 - struct sk_buff *skb) 1393 - { 1394 - u8 dest[ETH_ALEN]; 1395 - int status; 1396 - ieee->softmac_stats.rx_auth_rq++; 1397 - 1398 - status = auth_rq_parse(skb, dest); 1399 - if (status != -1) 1400 - ieee80211_resp_to_auth(ieee, status, dest); 1401 - } 1402 - 1403 - inline void 1404 - ieee80211_rx_assoc_rq(struct ieee80211_device *ieee, struct sk_buff *skb) 1405 - { 1406 - 1407 - u8 dest[ETH_ALEN]; 1408 - 1409 - ieee->softmac_stats.rx_ass_rq++; 1410 - if (assoc_rq_parse(skb, dest) != -1) 1411 - ieee80211_resp_to_assoc_rq(ieee, dest); 1412 - 1413 - 1414 - printk(KERN_INFO"New client associated: %pM\n", dest); 1415 - } 1416 - 1417 - void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee, short pwr) 1418 - { 1419 - struct sk_buff *buf = ieee80211_null_func(ieee, pwr); 1420 - 1421 - if (buf) 1422 - softmac_ps_mgmt_xmit(buf, ieee); 1423 - } 1424 - 1425 - static short ieee80211_sta_ps_sleep(struct ieee80211_device *ieee, u32 *time_h, 1426 - u32 *time_l) 1427 - { 1428 - int timeout = 0; 1429 - 1430 - u8 dtim; 1431 - dtim = ieee->current_network.dtim_data; 1432 - 1433 - if (!(dtim & IEEE80211_DTIM_VALID)) 1434 - return 0; 1435 - else 1436 - timeout = ieee->current_network.beacon_interval; 1437 - 1438 - ieee->current_network.dtim_data = IEEE80211_DTIM_INVALID; 1439 - 1440 - if (dtim & ((IEEE80211_DTIM_UCAST | IEEE80211_DTIM_MBCAST) & ieee->ps)) 1441 - return 2; 1442 - 1443 - if (!time_after(jiffies, ieee->dev->trans_start + MSECS(timeout))) 1444 - return 0; 1445 - 1446 - if (!time_after(jiffies, ieee->last_rx_ps_time + MSECS(timeout))) 1447 - return 0; 1448 - 1449 - if ((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) && 1450 - (ieee->mgmt_queue_tail != ieee->mgmt_queue_head)) 1451 - return 0; 1452 - 1453 - if (time_l) { 1454 - *time_l = ieee->current_network.last_dtim_sta_time[0] 1455 - + MSECS((ieee->current_network.beacon_interval)); 1456 - } 1457 - 1458 - if (time_h) { 1459 - *time_h = ieee->current_network.last_dtim_sta_time[1]; 1460 - if (time_l && *time_l < ieee->current_network.last_dtim_sta_time[0]) 1461 - *time_h += 1; 1462 - } 1463 - 1464 - return 1; 1465 - } 1466 - 1467 - static inline void ieee80211_sta_ps(struct ieee80211_device *ieee) 1468 - { 1469 - 1470 - u32 th, tl; 1471 - short sleep; 1472 - 1473 - unsigned long flags, flags2; 1474 - 1475 - spin_lock_irqsave(&ieee->lock, flags); 1476 - 1477 - if ((ieee->ps == IEEE80211_PS_DISABLED || 1478 - ieee->iw_mode != IW_MODE_INFRA || 1479 - ieee->state != IEEE80211_LINKED)) { 1480 - 1481 - /* #warning CHECK_LOCK_HERE */ 1482 - spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); 1483 - 1484 - ieee80211_sta_wakeup(ieee, 1); 1485 - 1486 - spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); 1487 - } 1488 - 1489 - sleep = ieee80211_sta_ps_sleep(ieee, &th, &tl); 1490 - /* 2 wake, 1 sleep, 0 do nothing */ 1491 - if (sleep == 0) 1492 - goto out; 1493 - 1494 - if (sleep == 1) { 1495 - if (ieee->sta_sleep == 1) 1496 - ieee->enter_sleep_state(ieee->dev, th, tl); 1497 - 1498 - else if (ieee->sta_sleep == 0) { 1499 - spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); 1500 - if (ieee->ps_is_queue_empty(ieee->dev)) { 1501 - ieee->sta_sleep = 2; 1502 - 1503 - ieee->ps_request_tx_ack(ieee->dev); 1504 - 1505 - ieee80211_sta_ps_send_null_frame(ieee, 1); 1506 - 1507 - ieee->ps_th = th; 1508 - ieee->ps_tl = tl; 1509 - } 1510 - spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); 1511 - } 1512 - } else if (sleep == 2) { 1513 - /* #warning CHECK_LOCK_HERE */ 1514 - spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); 1515 - 1516 - ieee80211_sta_wakeup(ieee, 1); 1517 - 1518 - spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); 1519 - } 1520 - out: 1521 - spin_unlock_irqrestore(&ieee->lock, flags); 1522 - } 1523 - 1524 - void ieee80211_sta_wakeup(struct ieee80211_device *ieee, short nl) 1525 - { 1526 - if (ieee->sta_sleep == 0) { 1527 - if (nl) { 1528 - ieee->ps_request_tx_ack(ieee->dev); 1529 - ieee80211_sta_ps_send_null_frame(ieee, 0); 1530 - } 1531 - return; 1532 - } 1533 - 1534 - if (ieee->sta_sleep == 1) 1535 - ieee->sta_wake_up(ieee->dev); 1536 - 1537 - ieee->sta_sleep = 0; 1538 - 1539 - if (nl) { 1540 - ieee->ps_request_tx_ack(ieee->dev); 1541 - ieee80211_sta_ps_send_null_frame(ieee, 0); 1542 - } 1543 - } 1544 - 1545 - void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success) 1546 - { 1547 - unsigned long flags, flags2; 1548 - 1549 - spin_lock_irqsave(&ieee->lock, flags); 1550 - if (ieee->sta_sleep == 2) { 1551 - /* Null frame with PS bit set */ 1552 - if (success) { 1553 - ieee->sta_sleep = 1; 1554 - ieee->enter_sleep_state(ieee->dev, ieee->ps_th, ieee->ps_tl); 1555 - } 1556 - /* if the card report not success we can't be sure the AP 1557 - * has not RXed so we can't assume the AP believe us awake 1558 - */ 1559 - } else { 1560 - if ((ieee->sta_sleep == 0) && !success) { 1561 - spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); 1562 - ieee80211_sta_ps_send_null_frame(ieee, 0); 1563 - spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); 1564 - } 1565 - } 1566 - spin_unlock_irqrestore(&ieee->lock, flags); 1567 - } 1568 - 1569 - inline int ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, 1570 - struct sk_buff *skb, 1571 - struct ieee80211_rx_stats *rx_stats, 1572 - u16 type, u16 stype) 1573 - { 1574 - struct ieee80211_hdr_3addr *header = (struct ieee80211_hdr_3addr *) skb->data; 1575 - u16 errcode; 1576 - u8 *challenge = NULL; 1577 - int chlen = 0; 1578 - int aid = 0; 1579 - struct ieee80211_assoc_response_frame *assoc_resp; 1580 - struct ieee80211_info_element *info_element; 1581 - 1582 - if (!ieee->proto_started) 1583 - return 0; 1584 - 1585 - if (ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED && 1586 - ieee->iw_mode == IW_MODE_INFRA && 1587 - ieee->state == IEEE80211_LINKED)) 1588 - 1589 - tasklet_schedule(&ieee->ps_task); 1590 - 1591 - if (WLAN_FC_GET_STYPE(header->frame_control) != IEEE80211_STYPE_PROBE_RESP && 1592 - WLAN_FC_GET_STYPE(header->frame_control) != IEEE80211_STYPE_BEACON) 1593 - ieee->last_rx_ps_time = jiffies; 1594 - 1595 - switch (WLAN_FC_GET_STYPE(header->frame_control)) { 1596 - case IEEE80211_STYPE_ASSOC_RESP: 1597 - case IEEE80211_STYPE_REASSOC_RESP: 1598 - IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n", 1599 - WLAN_FC_GET_STYPE(header->frame_ctl)); 1600 - if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && 1601 - ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED && 1602 - ieee->iw_mode == IW_MODE_INFRA) { 1603 - errcode = assoc_parse(skb, &aid); 1604 - if (0 == errcode) { 1605 - u16 left; 1606 - 1607 - ieee->state = IEEE80211_LINKED; 1608 - ieee->assoc_id = aid; 1609 - ieee->softmac_stats.rx_ass_ok++; 1610 - /* card type is 8187 */ 1611 - if (1 == rx_stats->nic_type) 1612 - goto associate_complete; 1613 - 1614 - assoc_resp = (struct ieee80211_assoc_response_frame *)skb->data; 1615 - info_element = &assoc_resp->info_element; 1616 - left = skb->len - ((void *)info_element - (void *)assoc_resp); 1617 - 1618 - while (left >= sizeof(struct ieee80211_info_element_hdr)) { 1619 - if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) { 1620 - printk(KERN_WARNING "[re]associate response error!"); 1621 - return 1; 1622 - } 1623 - switch (info_element->id) { 1624 - case MFIE_TYPE_GENERIC: 1625 - IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", info_element->len); 1626 - if (info_element->len >= 8 && 1627 - info_element->data[0] == 0x00 && 1628 - info_element->data[1] == 0x50 && 1629 - info_element->data[2] == 0xf2 && 1630 - info_element->data[3] == 0x02 && 1631 - info_element->data[4] == 0x01) { 1632 - /* Not care about version at present. 1633 - * WMM Parameter Element. 1634 - */ 1635 - memcpy(ieee->current_network.wmm_param, (u8 *)(info_element->data\ 1636 - + 8), (info_element->len - 8)); 1637 - 1638 - if (((ieee->current_network.wmm_info^info_element->data[6])& \ 1639 - 0x0f) || (!ieee->init_wmmparam_flag)) { 1640 - /* refresh parameter element for current network 1641 - * update the register parameter for hardware. 1642 - */ 1643 - ieee->init_wmmparam_flag = 1; 1644 - queue_work(ieee->wq, &ieee->wmm_param_update_wq); 1645 - } 1646 - /* update info_element for current network */ 1647 - ieee->current_network.wmm_info = info_element->data[6]; 1648 - } 1649 - break; 1650 - default: 1651 - /* nothing to do at present!!! */ 1652 - break; 1653 - } 1654 - 1655 - left -= sizeof(struct ieee80211_info_element_hdr) + 1656 - info_element->len; 1657 - info_element = (struct ieee80211_info_element *) 1658 - &info_element->data[info_element->len]; 1659 - } 1660 - /* legacy AP, reset the AC_xx_param register */ 1661 - if (!ieee->init_wmmparam_flag) { 1662 - queue_work(ieee->wq, &ieee->wmm_param_update_wq); 1663 - ieee->init_wmmparam_flag = 1; /* indicate AC_xx_param upated since last associate */ 1664 - } 1665 - associate_complete: 1666 - ieee80211_associate_complete(ieee); 1667 - } else { 1668 - ieee->softmac_stats.rx_ass_err++; 1669 - IEEE80211_DEBUG_MGMT( 1670 - "Association response status code 0x%x\n", 1671 - errcode); 1672 - ieee80211_associate_abort(ieee); 1673 - } 1674 - } 1675 - break; 1676 - case IEEE80211_STYPE_ASSOC_REQ: 1677 - case IEEE80211_STYPE_REASSOC_REQ: 1678 - if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && 1679 - ieee->iw_mode == IW_MODE_MASTER) 1680 - 1681 - ieee80211_rx_assoc_rq(ieee, skb); 1682 - break; 1683 - case IEEE80211_STYPE_AUTH: 1684 - if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) { 1685 - if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING && 1686 - ieee->iw_mode == IW_MODE_INFRA){ 1687 - IEEE80211_DEBUG_MGMT("Received authentication response"); 1688 - 1689 - errcode = auth_parse(skb, &challenge, &chlen); 1690 - if (0 == errcode) { 1691 - if (ieee->open_wep || !challenge) { 1692 - ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATED; 1693 - ieee->softmac_stats.rx_auth_rs_ok++; 1694 - 1695 - ieee80211_associate_step2(ieee); 1696 - } else { 1697 - ieee80211_rtl_auth_challenge(ieee, challenge, chlen); 1698 - } 1699 - } else { 1700 - ieee->softmac_stats.rx_auth_rs_err++; 1701 - IEEE80211_DEBUG_MGMT("Authentication response status code 0x%x", errcode); 1702 - ieee80211_associate_abort(ieee); 1703 - } 1704 - 1705 - } else if (ieee->iw_mode == IW_MODE_MASTER) { 1706 - ieee80211_rx_auth_rq(ieee, skb); 1707 - } 1708 - } 1709 - break; 1710 - case IEEE80211_STYPE_PROBE_REQ: 1711 - if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) && 1712 - ((ieee->iw_mode == IW_MODE_ADHOC || 1713 - ieee->iw_mode == IW_MODE_MASTER) && 1714 - ieee->state == IEEE80211_LINKED)) 1715 - 1716 - ieee80211_rx_probe_rq(ieee, skb); 1717 - break; 1718 - case IEEE80211_STYPE_DISASSOC: 1719 - case IEEE80211_STYPE_DEAUTH: 1720 - /* FIXME for now repeat all the association procedure 1721 - * both for disassociation and deauthentication 1722 - */ 1723 - if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && 1724 - (ieee->state == IEEE80211_LINKED) && 1725 - (ieee->iw_mode == IW_MODE_INFRA) && 1726 - (!memcmp(header->addr2, ieee->current_network.bssid, ETH_ALEN))) { 1727 - ieee->state = IEEE80211_ASSOCIATING; 1728 - ieee->softmac_stats.reassoc++; 1729 - 1730 - queue_work(ieee->wq, &ieee->associate_procedure_wq); 1731 - } 1732 - break; 1733 - default: 1734 - return -1; 1735 - break; 1736 - } 1737 - return 0; 1738 - } 1739 - 1740 - /* following are for a simpler TX queue management. 1741 - * Instead of using netif_[stop/wake]_queue the driver 1742 - * will uses these two function (plus a reset one), that 1743 - * will internally uses the kernel netif_* and takes 1744 - * care of the ieee802.11 fragmentation. 1745 - * So the driver receives a fragment per time and might 1746 - * call the stop function when it want without take care 1747 - * to have enough room to TX an entire packet. 1748 - * This might be useful if each fragment need it's own 1749 - * descriptor, thus just keep a total free memory > than 1750 - * the max fragmentation threshold is not enough.. If the 1751 - * ieee802.11 stack passed a TXB struct then you needed 1752 - * to keep N free descriptors where 1753 - * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD 1754 - * In this way you need just one and the 802.11 stack 1755 - * will take care of buffering fragments and pass them to 1756 - * to the driver later, when it wakes the queue. 1757 - */ 1758 - 1759 - void ieee80211_softmac_xmit(struct ieee80211_txb *txb, 1760 - struct ieee80211_device *ieee) 1761 - { 1762 - unsigned long flags; 1763 - int i; 1764 - 1765 - spin_lock_irqsave(&ieee->lock, flags); 1766 - 1767 - /* called with 2nd parm 0, no tx mgmt lock required */ 1768 - ieee80211_sta_wakeup(ieee, 0); 1769 - 1770 - for (i = 0; i < txb->nr_frags; i++) { 1771 - if (ieee->queue_stop) { 1772 - ieee->tx_pending.txb = txb; 1773 - ieee->tx_pending.frag = i; 1774 - goto exit; 1775 - } else { 1776 - ieee->softmac_data_hard_start_xmit( 1777 - txb->fragments[i], 1778 - ieee->dev, ieee->rate); 1779 - ieee->stats.tx_packets++; 1780 - ieee->stats.tx_bytes += txb->fragments[i]->len; 1781 - ieee->dev->trans_start = jiffies; 1782 - } 1783 - } 1784 - 1785 - ieee80211_txb_free(txb); 1786 - 1787 - exit: 1788 - spin_unlock_irqrestore(&ieee->lock, flags); 1789 - } 1790 - 1791 - /* called with ieee->lock acquired */ 1792 - static void ieee80211_resume_tx(struct ieee80211_device *ieee) 1793 - { 1794 - int i; 1795 - for (i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags; i++) { 1796 - 1797 - if (ieee->queue_stop) { 1798 - ieee->tx_pending.frag = i; 1799 - return; 1800 - } else { 1801 - ieee->softmac_data_hard_start_xmit( 1802 - ieee->tx_pending.txb->fragments[i], 1803 - ieee->dev, ieee->rate); 1804 - ieee->stats.tx_packets++; 1805 - ieee->dev->trans_start = jiffies; 1806 - } 1807 - } 1808 - 1809 - ieee80211_txb_free(ieee->tx_pending.txb); 1810 - ieee->tx_pending.txb = NULL; 1811 - } 1812 - 1813 - void ieee80211_reset_queue(struct ieee80211_device *ieee) 1814 - { 1815 - unsigned long flags; 1816 - 1817 - spin_lock_irqsave(&ieee->lock, flags); 1818 - init_mgmt_queue(ieee); 1819 - if (ieee->tx_pending.txb) { 1820 - ieee80211_txb_free(ieee->tx_pending.txb); 1821 - ieee->tx_pending.txb = NULL; 1822 - } 1823 - ieee->queue_stop = 0; 1824 - spin_unlock_irqrestore(&ieee->lock, flags); 1825 - } 1826 - 1827 - void ieee80211_rtl_wake_queue(struct ieee80211_device *ieee) 1828 - { 1829 - unsigned long flags; 1830 - struct sk_buff *skb; 1831 - struct ieee80211_hdr_3addr *header; 1832 - 1833 - spin_lock_irqsave(&ieee->lock, flags); 1834 - if (!ieee->queue_stop) 1835 - goto exit; 1836 - 1837 - ieee->queue_stop = 0; 1838 - 1839 - if (ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) { 1840 - while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))) { 1841 - header = (struct ieee80211_hdr_3addr *) skb->data; 1842 - 1843 - header->seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4); 1844 - 1845 - if (ieee->seq_ctrl[0] == 0xFFF) 1846 - ieee->seq_ctrl[0] = 0; 1847 - else 1848 - ieee->seq_ctrl[0]++; 1849 - 1850 - ieee->softmac_data_hard_start_xmit(skb, ieee->dev, ieee->basic_rate); 1851 - dev_kfree_skb_any(skb); 1852 - } 1853 - } 1854 - if (!ieee->queue_stop && ieee->tx_pending.txb) 1855 - ieee80211_resume_tx(ieee); 1856 - 1857 - if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)) { 1858 - ieee->softmac_stats.swtxawake++; 1859 - netif_wake_queue(ieee->dev); 1860 - } 1861 - exit: 1862 - spin_unlock_irqrestore(&ieee->lock, flags); 1863 - } 1864 - 1865 - void ieee80211_rtl_stop_queue(struct ieee80211_device *ieee) 1866 - { 1867 - if (!netif_queue_stopped(ieee->dev)) { 1868 - netif_stop_queue(ieee->dev); 1869 - ieee->softmac_stats.swtxstop++; 1870 - } 1871 - ieee->queue_stop = 1; 1872 - } 1873 - 1874 - inline void ieee80211_randomize_cell(struct ieee80211_device *ieee) 1875 - { 1876 - random_ether_addr(ieee->current_network.bssid); 1877 - } 1878 - 1879 - /* called in user context only */ 1880 - void ieee80211_start_master_bss(struct ieee80211_device *ieee) 1881 - { 1882 - ieee->assoc_id = 1; 1883 - 1884 - if (ieee->current_network.ssid_len == 0) { 1885 - strncpy(ieee->current_network.ssid, 1886 - IEEE80211_DEFAULT_TX_ESSID, 1887 - IW_ESSID_MAX_SIZE); 1888 - 1889 - ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID); 1890 - ieee->ssid_set = 1; 1891 - } 1892 - 1893 - memcpy(ieee->current_network.bssid, ieee->dev->dev_addr, ETH_ALEN); 1894 - 1895 - ieee->set_chan(ieee->dev, ieee->current_network.channel); 1896 - ieee->state = IEEE80211_LINKED; 1897 - ieee->link_change(ieee->dev); 1898 - notify_wx_assoc_event(ieee); 1899 - 1900 - if (ieee->data_hard_resume) 1901 - ieee->data_hard_resume(ieee->dev); 1902 - 1903 - netif_carrier_on(ieee->dev); 1904 - } 1905 - 1906 - static void ieee80211_start_monitor_mode(struct ieee80211_device *ieee) 1907 - { 1908 - if (ieee->raw_tx) { 1909 - 1910 - if (ieee->data_hard_resume) 1911 - ieee->data_hard_resume(ieee->dev); 1912 - 1913 - netif_carrier_on(ieee->dev); 1914 - } 1915 - } 1916 - 1917 - static void ieee80211_start_ibss_wq(struct work_struct *work) 1918 - { 1919 - struct delayed_work *dwork = to_delayed_work(work); 1920 - struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, start_ibss_wq); 1921 - 1922 - /* iwconfig mode ad-hoc will schedule this and return 1923 - * on the other hand this will block further iwconfig SET 1924 - * operations because of the wx_sem hold. 1925 - * Anyway some most set operations set a flag to speed-up 1926 - * (abort) this wq (when syncro scanning) before sleeping 1927 - * on the semaphore 1928 - */ 1929 - 1930 - down(&ieee->wx_sem); 1931 - 1932 - if (ieee->current_network.ssid_len == 0) { 1933 - strcpy(ieee->current_network.ssid, IEEE80211_DEFAULT_TX_ESSID); 1934 - ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID); 1935 - ieee->ssid_set = 1; 1936 - } 1937 - 1938 - /* check if we have this cell in our network list */ 1939 - ieee80211_softmac_check_all_nets(ieee); 1940 - 1941 - if (ieee->state == IEEE80211_NOLINK) 1942 - ieee->current_network.channel = 10; 1943 - /* if not then the state is not linked. Maybe the user switched to 1944 - * ad-hoc mode just after being in monitor mode, or just after 1945 - * being very few time in managed mode (so the card have had no 1946 - * time to scan all the chans..) or we have just run up the iface 1947 - * after setting ad-hoc mode. So we have to give another try.. 1948 - * Here, in ibss mode, should be safe to do this without extra care 1949 - * (in bss mode we had to make sure no-one tried to associate when 1950 - * we had just checked the ieee->state and we was going to start the 1951 - * scan) because in ibss mode the ieee80211_new_net function, when 1952 - * finds a good net, just set the ieee->state to IEEE80211_LINKED, 1953 - * so, at worst, we waste a bit of time to initiate an unneeded syncro 1954 - * scan, that will stop at the first round because it sees the state 1955 - * associated. 1956 - */ 1957 - if (ieee->state == IEEE80211_NOLINK) 1958 - ieee80211_start_scan_syncro(ieee); 1959 - 1960 - /* the network definitively is not here.. create a new cell */ 1961 - if (ieee->state == IEEE80211_NOLINK) { 1962 - printk("creating new IBSS cell\n"); 1963 - if (!ieee->wap_set) 1964 - ieee80211_randomize_cell(ieee); 1965 - 1966 - if (ieee->modulation & IEEE80211_CCK_MODULATION) { 1967 - ieee->current_network.rates_len = 4; 1968 - 1969 - ieee->current_network.rates[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; 1970 - ieee->current_network.rates[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; 1971 - ieee->current_network.rates[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB; 1972 - ieee->current_network.rates[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB; 1973 - 1974 - } else 1975 - ieee->current_network.rates_len = 0; 1976 - 1977 - if (ieee->modulation & IEEE80211_OFDM_MODULATION) { 1978 - ieee->current_network.rates_ex_len = 8; 1979 - 1980 - ieee->current_network.rates_ex[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB; 1981 - ieee->current_network.rates_ex[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB; 1982 - ieee->current_network.rates_ex[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB; 1983 - ieee->current_network.rates_ex[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB; 1984 - ieee->current_network.rates_ex[4] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB; 1985 - ieee->current_network.rates_ex[5] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB; 1986 - ieee->current_network.rates_ex[6] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB; 1987 - ieee->current_network.rates_ex[7] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB; 1988 - 1989 - ieee->rate = 540; 1990 - } else { 1991 - ieee->current_network.rates_ex_len = 0; 1992 - ieee->rate = 110; 1993 - } 1994 - 1995 - /* By default, WMM function will be disabled in IBSS mode */ 1996 - ieee->current_network.QoS_Enable = 0; 1997 - 1998 - ieee->current_network.atim_window = 0; 1999 - ieee->current_network.capability = WLAN_CAPABILITY_IBSS; 2000 - if (ieee->short_slot) 2001 - ieee->current_network.capability |= WLAN_CAPABILITY_SHORT_SLOT; 2002 - } 2003 - 2004 - ieee->state = IEEE80211_LINKED; 2005 - ieee->set_chan(ieee->dev, ieee->current_network.channel); 2006 - ieee->link_change(ieee->dev); 2007 - 2008 - notify_wx_assoc_event(ieee); 2009 - 2010 - ieee80211_start_send_beacons(ieee); 2011 - printk(KERN_WARNING "after sending beacon packet!\n"); 2012 - 2013 - if (ieee->data_hard_resume) 2014 - ieee->data_hard_resume(ieee->dev); 2015 - 2016 - netif_carrier_on(ieee->dev); 2017 - 2018 - up(&ieee->wx_sem); 2019 - } 2020 - 2021 - inline void ieee80211_start_ibss(struct ieee80211_device *ieee) 2022 - { 2023 - queue_delayed_work(ieee->wq, &ieee->start_ibss_wq, 100); 2024 - } 2025 - 2026 - /* this is called only in user context, with wx_sem held */ 2027 - void ieee80211_start_bss(struct ieee80211_device *ieee) 2028 - { 2029 - unsigned long flags; 2030 - /* Ref: 802.11d 11.1.3.3 2031 - * STA shall not start a BSS unless properly formed Beacon frame 2032 - * including a Country IE. 2033 - */ 2034 - if (IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee)) { 2035 - if (!ieee->bGlobalDomain) 2036 - return; 2037 - } 2038 - /* check if we have already found the net we are interested in (if any). 2039 - * if not (we are disassociated and we are not 2040 - * in associating / authenticating phase) start the background scanning. 2041 - */ 2042 - ieee80211_softmac_check_all_nets(ieee); 2043 - 2044 - /* ensure no-one start an associating process (thus setting 2045 - * the ieee->state to ieee80211_ASSOCIATING) while we 2046 - * have just cheked it and we are going to enable scan. 2047 - * The ieee80211_new_net function is always called with 2048 - * lock held (from both ieee80211_softmac_check_all_nets and 2049 - * the rx path), so we cannot be in the middle of such function 2050 - */ 2051 - spin_lock_irqsave(&ieee->lock, flags); 2052 - 2053 - if (ieee->state == IEEE80211_NOLINK) { 2054 - ieee->actscanning = true; 2055 - ieee80211_rtl_start_scan(ieee); 2056 - } 2057 - spin_unlock_irqrestore(&ieee->lock, flags); 2058 - } 2059 - 2060 - /* called only in userspace context */ 2061 - void ieee80211_disassociate(struct ieee80211_device *ieee) 2062 - { 2063 - netif_carrier_off(ieee->dev); 2064 - 2065 - if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE) 2066 - ieee80211_reset_queue(ieee); 2067 - 2068 - if (ieee->data_hard_stop) 2069 - ieee->data_hard_stop(ieee->dev); 2070 - 2071 - if (IS_DOT11D_ENABLE(ieee)) 2072 - Dot11d_Reset(ieee); 2073 - 2074 - ieee->link_change(ieee->dev); 2075 - if (ieee->state == IEEE80211_LINKED) 2076 - notify_wx_assoc_event(ieee); 2077 - ieee->state = IEEE80211_NOLINK; 2078 - 2079 - } 2080 - static void ieee80211_associate_retry_wq(struct work_struct *work) 2081 - { 2082 - struct delayed_work *dwork = to_delayed_work(work); 2083 - struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq); 2084 - unsigned long flags; 2085 - down(&ieee->wx_sem); 2086 - if (!ieee->proto_started) 2087 - goto exit; 2088 - if (ieee->state != IEEE80211_ASSOCIATING_RETRY) 2089 - goto exit; 2090 - /* until we do not set the state to IEEE80211_NOLINK 2091 - * there are no possibility to have someone else trying 2092 - * to start an association procedure (we get here with 2093 - * ieee->state = IEEE80211_ASSOCIATING). 2094 - * When we set the state to IEEE80211_NOLINK it is possible 2095 - * that the RX path run an attempt to associate, but 2096 - * both ieee80211_softmac_check_all_nets and the 2097 - * RX path works with ieee->lock held so there are no 2098 - * problems. If we are still disassociated then start a scan. 2099 - * the lock here is necessary to ensure no one try to start 2100 - * an association procedure when we have just checked the 2101 - * state and we are going to start the scan. 2102 - */ 2103 - ieee->state = IEEE80211_NOLINK; 2104 - ieee->beinretry = true; 2105 - ieee80211_softmac_check_all_nets(ieee); 2106 - 2107 - spin_lock_irqsave(&ieee->lock, flags); 2108 - 2109 - if (ieee->state == IEEE80211_NOLINK) { 2110 - ieee->beinretry = false; 2111 - ieee->actscanning = true; 2112 - ieee80211_rtl_start_scan(ieee); 2113 - } 2114 - if (ieee->state == IEEE80211_NOLINK) 2115 - notify_wx_assoc_event(ieee); 2116 - spin_unlock_irqrestore(&ieee->lock, flags); 2117 - 2118 - exit: 2119 - up(&ieee->wx_sem); 2120 - } 2121 - 2122 - struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee) 2123 - { 2124 - u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 2125 - 2126 - struct sk_buff *skb = NULL; 2127 - struct ieee80211_probe_response *b; 2128 - 2129 - skb = ieee80211_probe_resp(ieee, broadcast_addr); 2130 - if (!skb) 2131 - return NULL; 2132 - 2133 - b = (struct ieee80211_probe_response *) skb->data; 2134 - b->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_BEACON); 2135 - 2136 - return skb; 2137 - } 2138 - 2139 - struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee) 2140 - { 2141 - struct sk_buff *skb; 2142 - struct ieee80211_probe_response *b; 2143 - 2144 - skb = ieee80211_get_beacon_(ieee); 2145 - if (!skb) 2146 - return NULL; 2147 - 2148 - b = (struct ieee80211_probe_response *) skb->data; 2149 - b->header.seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4); 2150 - 2151 - if (ieee->seq_ctrl[0] == 0xFFF) 2152 - ieee->seq_ctrl[0] = 0; 2153 - else 2154 - ieee->seq_ctrl[0]++; 2155 - 2156 - return skb; 2157 - } 2158 - 2159 - void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee) 2160 - { 2161 - ieee->sync_scan_hurryup = 1; 2162 - down(&ieee->wx_sem); 2163 - ieee80211_stop_protocol(ieee); 2164 - up(&ieee->wx_sem); 2165 - } 2166 - 2167 - void ieee80211_stop_protocol(struct ieee80211_device *ieee) 2168 - { 2169 - if (!ieee->proto_started) 2170 - return; 2171 - 2172 - ieee->proto_started = 0; 2173 - 2174 - ieee80211_stop_send_beacons(ieee); 2175 - if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state == IEEE80211_LINKED)) 2176 - SendDisassociation(ieee, NULL, WLAN_REASON_DISASSOC_STA_HAS_LEFT); 2177 - 2178 - del_timer_sync(&ieee->associate_timer); 2179 - cancel_delayed_work(&ieee->associate_retry_wq); 2180 - cancel_delayed_work(&ieee->start_ibss_wq); 2181 - ieee80211_stop_scan(ieee); 2182 - 2183 - ieee80211_disassociate(ieee); 2184 - } 2185 - 2186 - void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee) 2187 - { 2188 - ieee->sync_scan_hurryup = 0; 2189 - down(&ieee->wx_sem); 2190 - ieee80211_start_protocol(ieee); 2191 - up(&ieee->wx_sem); 2192 - } 2193 - 2194 - void ieee80211_start_protocol(struct ieee80211_device *ieee) 2195 - { 2196 - short ch = 0; 2197 - int i = 0; 2198 - 2199 - if (ieee->proto_started) 2200 - return; 2201 - 2202 - ieee->proto_started = 1; 2203 - 2204 - if (ieee->current_network.channel == 0) { 2205 - do { 2206 - ch++; 2207 - if (ch > MAX_CHANNEL_NUMBER) 2208 - return; /* no channel found */ 2209 - 2210 - } while (!GET_DOT11D_INFO(ieee)->channel_map[ch]); 2211 - 2212 - ieee->current_network.channel = ch; 2213 - } 2214 - 2215 - if (ieee->current_network.beacon_interval == 0) 2216 - ieee->current_network.beacon_interval = 100; 2217 - ieee->set_chan(ieee->dev, ieee->current_network.channel); 2218 - 2219 - for (i = 0; i < 17; i++) { 2220 - ieee->last_rxseq_num[i] = -1; 2221 - ieee->last_rxfrag_num[i] = -1; 2222 - ieee->last_packet_time[i] = 0; 2223 - } 2224 - 2225 - ieee->init_wmmparam_flag = 0; /* reinitialize AC_xx_PARAM registers. */ 2226 - 2227 - /* if the user set the MAC of the ad-hoc cell and then 2228 - * switch to managed mode, shall we make sure that association 2229 - * attempts does not fail just because the user provide the essid 2230 - * and the nic is still checking for the AP MAC ?? 2231 - */ 2232 - switch (ieee->iw_mode) { 2233 - case IW_MODE_AUTO: 2234 - ieee->iw_mode = IW_MODE_INFRA; 2235 - /* not set break here intentionly */ 2236 - case IW_MODE_INFRA: 2237 - ieee80211_start_bss(ieee); 2238 - break; 2239 - 2240 - case IW_MODE_ADHOC: 2241 - ieee80211_start_ibss(ieee); 2242 - break; 2243 - 2244 - case IW_MODE_MASTER: 2245 - ieee80211_start_master_bss(ieee); 2246 - break; 2247 - 2248 - case IW_MODE_MONITOR: 2249 - ieee80211_start_monitor_mode(ieee); 2250 - break; 2251 - 2252 - default: 2253 - ieee->iw_mode = IW_MODE_INFRA; 2254 - ieee80211_start_bss(ieee); 2255 - break; 2256 - } 2257 - } 2258 - 2259 - #define DRV_NAME "Ieee80211" 2260 - void ieee80211_softmac_init(struct ieee80211_device *ieee) 2261 - { 2262 - int i; 2263 - memset(&ieee->current_network, 0, sizeof(struct ieee80211_network)); 2264 - 2265 - ieee->state = IEEE80211_NOLINK; 2266 - ieee->sync_scan_hurryup = 0; 2267 - for (i = 0; i < 5; i++) 2268 - ieee->seq_ctrl[i] = 0; 2269 - 2270 - ieee->assoc_id = 0; 2271 - ieee->queue_stop = 0; 2272 - ieee->scanning = 0; 2273 - ieee->softmac_features = 0; /* so IEEE2100-like driver are happy */ 2274 - ieee->wap_set = 0; 2275 - ieee->ssid_set = 0; 2276 - ieee->proto_started = 0; 2277 - ieee->basic_rate = IEEE80211_DEFAULT_BASIC_RATE; 2278 - ieee->rate = 3; 2279 - ieee->ps = IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST; 2280 - ieee->sta_sleep = 0; 2281 - ieee->bInactivePs = false; 2282 - ieee->actscanning = false; 2283 - ieee->ListenInterval = 2; 2284 - ieee->NumRxDataInPeriod = 0; 2285 - ieee->NumRxBcnInPeriod = 0; 2286 - ieee->NumRxOkTotal = 0; 2287 - ieee->NumRxUnicast = 0; /* for keep alive */ 2288 - ieee->beinretry = false; 2289 - ieee->bHwRadioOff = false; 2290 - 2291 - init_mgmt_queue(ieee); 2292 - 2293 - ieee->tx_pending.txb = NULL; 2294 - 2295 - init_timer(&ieee->associate_timer); 2296 - ieee->associate_timer.data = (unsigned long)ieee; 2297 - ieee->associate_timer.function = ieee80211_associate_abort_cb; 2298 - 2299 - init_timer(&ieee->beacon_timer); 2300 - ieee->beacon_timer.data = (unsigned long) ieee; 2301 - ieee->beacon_timer.function = ieee80211_send_beacon_cb; 2302 - 2303 - ieee->wq = create_workqueue(DRV_NAME); 2304 - 2305 - INIT_DELAYED_WORK(&ieee->start_ibss_wq, (void *) ieee80211_start_ibss_wq); 2306 - INIT_WORK(&ieee->associate_complete_wq, (void *) ieee80211_associate_complete_wq); 2307 - INIT_WORK(&ieee->associate_procedure_wq, (void *) ieee80211_associate_procedure_wq); 2308 - INIT_DELAYED_WORK(&ieee->softmac_scan_wq, (void *) ieee80211_softmac_scan_wq); 2309 - INIT_DELAYED_WORK(&ieee->associate_retry_wq, (void *) ieee80211_associate_retry_wq); 2310 - INIT_WORK(&ieee->wx_sync_scan_wq, (void *) ieee80211_wx_sync_scan_wq); 2311 - 2312 - sema_init(&ieee->wx_sem, 1); 2313 - sema_init(&ieee->scan_sem, 1); 2314 - 2315 - spin_lock_init(&ieee->mgmt_tx_lock); 2316 - spin_lock_init(&ieee->beacon_lock); 2317 - 2318 - tasklet_init(&ieee->ps_task, 2319 - (void(*)(unsigned long)) ieee80211_sta_ps, 2320 - (unsigned long)ieee); 2321 - ieee->pDot11dInfo = kmalloc(sizeof(RT_DOT11D_INFO), GFP_ATOMIC); 2322 - } 2323 - 2324 - void ieee80211_softmac_free(struct ieee80211_device *ieee) 2325 - { 2326 - down(&ieee->wx_sem); 2327 - 2328 - del_timer_sync(&ieee->associate_timer); 2329 - cancel_delayed_work(&ieee->associate_retry_wq); 2330 - 2331 - /* add for RF power on power of */ 2332 - cancel_delayed_work(&ieee->GPIOChangeRFWorkItem); 2333 - 2334 - destroy_workqueue(ieee->wq); 2335 - kfree(ieee->pDot11dInfo); 2336 - up(&ieee->wx_sem); 2337 - } 2338 - 2339 - /* Start of WPA code. This is stolen from the ipw2200 driver */ 2340 - static int ieee80211_wpa_enable(struct ieee80211_device *ieee, int value) 2341 - { 2342 - /* This is called when wpa_supplicant loads and closes the driver 2343 - * interface. */ 2344 - printk("%s WPA\n", value ? "enabling" : "disabling"); 2345 - ieee->wpa_enabled = value; 2346 - return 0; 2347 - } 2348 - 2349 - static void ieee80211_wpa_assoc_frame(struct ieee80211_device *ieee, char *wpa_ie, 2350 - int wpa_ie_len) 2351 - { 2352 - /* make sure WPA is enabled */ 2353 - ieee80211_wpa_enable(ieee, 1); 2354 - 2355 - ieee80211_disassociate(ieee); 2356 - } 2357 - 2358 - static int ieee80211_wpa_mlme(struct ieee80211_device *ieee, int command, 2359 - int reason) 2360 - { 2361 - int ret = 0; 2362 - 2363 - switch (command) { 2364 - case IEEE_MLME_STA_DEAUTH: 2365 - /* silently ignore */ 2366 - break; 2367 - 2368 - case IEEE_MLME_STA_DISASSOC: 2369 - ieee80211_disassociate(ieee); 2370 - break; 2371 - 2372 - default: 2373 - printk("Unknown MLME request: %d\n", command); 2374 - ret = -EOPNOTSUPP; 2375 - } 2376 - 2377 - return ret; 2378 - } 2379 - 2380 - static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee, 2381 - struct ieee_param *param, int plen) 2382 - { 2383 - u8 *buf; 2384 - 2385 - if (param->u.wpa_ie.len > MAX_WPA_IE_LEN || 2386 - (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL)) 2387 - return -EINVAL; 2388 - 2389 - if (param->u.wpa_ie.len) { 2390 - buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len, 2391 - GFP_KERNEL); 2392 - if (buf == NULL) 2393 - return -ENOMEM; 2394 - 2395 - kfree(ieee->wpa_ie); 2396 - ieee->wpa_ie = buf; 2397 - ieee->wpa_ie_len = param->u.wpa_ie.len; 2398 - } else { 2399 - kfree(ieee->wpa_ie); 2400 - ieee->wpa_ie = NULL; 2401 - ieee->wpa_ie_len = 0; 2402 - } 2403 - 2404 - ieee80211_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len); 2405 - return 0; 2406 - } 2407 - 2408 - #define AUTH_ALG_OPEN_SYSTEM 0x1 2409 - #define AUTH_ALG_SHARED_KEY 0x2 2410 - 2411 - static int ieee80211_wpa_set_auth_algs(struct ieee80211_device *ieee, int value) 2412 - { 2413 - struct ieee80211_security sec = { 2414 - .flags = SEC_AUTH_MODE, 2415 - }; 2416 - int ret = 0; 2417 - 2418 - if (value & AUTH_ALG_SHARED_KEY) { 2419 - sec.auth_mode = WLAN_AUTH_SHARED_KEY; 2420 - ieee->open_wep = 0; 2421 - } else { 2422 - sec.auth_mode = WLAN_AUTH_OPEN; 2423 - ieee->open_wep = 1; 2424 - } 2425 - 2426 - if (ieee->set_security) 2427 - ieee->set_security(ieee->dev, &sec); 2428 - else 2429 - ret = -EOPNOTSUPP; 2430 - 2431 - return ret; 2432 - } 2433 - 2434 - static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, 2435 - u32 value) 2436 - { 2437 - int ret = 0; 2438 - unsigned long flags; 2439 - 2440 - switch (name) { 2441 - case IEEE_PARAM_WPA_ENABLED: 2442 - ret = ieee80211_wpa_enable(ieee, value); 2443 - break; 2444 - 2445 - case IEEE_PARAM_TKIP_COUNTERMEASURES: 2446 - ieee->tkip_countermeasures = value; 2447 - break; 2448 - 2449 - case IEEE_PARAM_DROP_UNENCRYPTED: { 2450 - /* HACK: 2451 - * 2452 - * wpa_supplicant calls set_wpa_enabled when the driver 2453 - * is loaded and unloaded, regardless of if WPA is being 2454 - * used. No other calls are made which can be used to 2455 - * determine if encryption will be used or not prior to 2456 - * association being expected. If encryption is not being 2457 - * used, drop_unencrypted is set to false, else true -- we 2458 - * can use this to determine if the CAP_PRIVACY_ON bit should 2459 - * be set. 2460 - */ 2461 - struct ieee80211_security sec = { 2462 - .flags = SEC_ENABLED, 2463 - .enabled = value, 2464 - }; 2465 - ieee->drop_unencrypted = value; 2466 - /* We only change SEC_LEVEL for open mode. Others 2467 - * are set by ipw_wpa_set_encryption. 2468 - */ 2469 - if (!value) { 2470 - sec.flags |= SEC_LEVEL; 2471 - sec.level = SEC_LEVEL_0; 2472 - } else { 2473 - sec.flags |= SEC_LEVEL; 2474 - sec.level = SEC_LEVEL_1; 2475 - } 2476 - if (ieee->set_security) 2477 - ieee->set_security(ieee->dev, &sec); 2478 - break; 2479 - } 2480 - 2481 - case IEEE_PARAM_PRIVACY_INVOKED: 2482 - ieee->privacy_invoked = value; 2483 - break; 2484 - case IEEE_PARAM_AUTH_ALGS: 2485 - ret = ieee80211_wpa_set_auth_algs(ieee, value); 2486 - break; 2487 - case IEEE_PARAM_IEEE_802_1X: 2488 - ieee->ieee802_1x = value; 2489 - break; 2490 - case IEEE_PARAM_WPAX_SELECT: 2491 - spin_lock_irqsave(&ieee->wpax_suitlist_lock, flags); 2492 - ieee->wpax_type_set = 1; 2493 - ieee->wpax_type_notify = value; 2494 - spin_unlock_irqrestore(&ieee->wpax_suitlist_lock, flags); 2495 - break; 2496 - default: 2497 - printk("Unknown WPA param: %d\n", name); 2498 - ret = -EOPNOTSUPP; 2499 - } 2500 - 2501 - return ret; 2502 - } 2503 - 2504 - /* implementation borrowed from hostap driver */ 2505 - 2506 - static int ieee80211_wpa_set_encryption(struct ieee80211_device *ieee, 2507 - struct ieee_param *param, int param_len) 2508 - { 2509 - int ret = 0; 2510 - 2511 - struct ieee80211_crypto_ops *ops; 2512 - struct ieee80211_crypt_data **crypt; 2513 - 2514 - struct ieee80211_security sec = { 2515 - .flags = 0, 2516 - }; 2517 - 2518 - param->u.crypt.err = 0; 2519 - param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; 2520 - 2521 - if (param_len != 2522 - (int) ((char *) param->u.crypt.key - (char *) param) + 2523 - param->u.crypt.key_len) { 2524 - printk("Len mismatch %d, %d\n", param_len, 2525 - param->u.crypt.key_len); 2526 - return -EINVAL; 2527 - } 2528 - if (is_broadcast_ether_addr(param->sta_addr)) { 2529 - if (param->u.crypt.idx >= WEP_KEYS) 2530 - return -EINVAL; 2531 - crypt = &ieee->crypt[param->u.crypt.idx]; 2532 - } else { 2533 - return -EINVAL; 2534 - } 2535 - 2536 - if (strcmp(param->u.crypt.alg, "none") == 0) { 2537 - if (crypt) { 2538 - sec.enabled = 0; 2539 - /* FIXME FIXME */ 2540 - sec.level = SEC_LEVEL_0; 2541 - sec.flags |= SEC_ENABLED | SEC_LEVEL; 2542 - ieee80211_crypt_delayed_deinit(ieee, crypt); 2543 - } 2544 - goto done; 2545 - } 2546 - sec.enabled = 1; 2547 - /* FIXME FIXME */ 2548 - sec.flags |= SEC_ENABLED; 2549 - 2550 - /* IPW HW cannot build TKIP MIC, host decryption still needed. */ 2551 - if (!(ieee->host_encrypt || ieee->host_decrypt) && 2552 - strcmp(param->u.crypt.alg, "TKIP")) 2553 - goto skip_host_crypt; 2554 - 2555 - ops = ieee80211_get_crypto_ops(param->u.crypt.alg); 2556 - if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) 2557 - ops = ieee80211_get_crypto_ops(param->u.crypt.alg); 2558 - else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) 2559 - ops = ieee80211_get_crypto_ops(param->u.crypt.alg); 2560 - else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) 2561 - ops = ieee80211_get_crypto_ops(param->u.crypt.alg); 2562 - if (ops == NULL) { 2563 - printk("unknown crypto alg '%s'\n", param->u.crypt.alg); 2564 - param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG; 2565 - ret = -EINVAL; 2566 - goto done; 2567 - } 2568 - 2569 - if (*crypt == NULL || (*crypt)->ops != ops) { 2570 - struct ieee80211_crypt_data *new_crypt; 2571 - 2572 - ieee80211_crypt_delayed_deinit(ieee, crypt); 2573 - 2574 - new_crypt = kmalloc(sizeof(*new_crypt), GFP_KERNEL); 2575 - if (new_crypt == NULL) { 2576 - ret = -ENOMEM; 2577 - goto done; 2578 - } 2579 - memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data)); 2580 - new_crypt->ops = ops; 2581 - if (new_crypt->ops) 2582 - new_crypt->priv = 2583 - new_crypt->ops->init(param->u.crypt.idx); 2584 - 2585 - if (new_crypt->priv == NULL) { 2586 - kfree(new_crypt); 2587 - param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED; 2588 - ret = -EINVAL; 2589 - goto done; 2590 - } 2591 - 2592 - *crypt = new_crypt; 2593 - } 2594 - 2595 - if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key && 2596 - (*crypt)->ops->set_key(param->u.crypt.key, 2597 - param->u.crypt.key_len, param->u.crypt.seq, 2598 - (*crypt)->priv) < 0) { 2599 - printk("key setting failed\n"); 2600 - param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED; 2601 - ret = -EINVAL; 2602 - goto done; 2603 - } 2604 - 2605 - skip_host_crypt: 2606 - if (param->u.crypt.set_tx) { 2607 - ieee->tx_keyidx = param->u.crypt.idx; 2608 - sec.active_key = param->u.crypt.idx; 2609 - sec.flags |= SEC_ACTIVE_KEY; 2610 - } else 2611 - sec.flags &= ~SEC_ACTIVE_KEY; 2612 - 2613 - if (param->u.crypt.alg != NULL) { 2614 - memcpy(sec.keys[param->u.crypt.idx], 2615 - param->u.crypt.key, 2616 - param->u.crypt.key_len); 2617 - sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len; 2618 - sec.flags |= (1 << param->u.crypt.idx); 2619 - 2620 - if (strcmp(param->u.crypt.alg, "WEP") == 0) { 2621 - sec.flags |= SEC_LEVEL; 2622 - sec.level = SEC_LEVEL_1; 2623 - } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) { 2624 - sec.flags |= SEC_LEVEL; 2625 - sec.level = SEC_LEVEL_2; 2626 - } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { 2627 - sec.flags |= SEC_LEVEL; 2628 - sec.level = SEC_LEVEL_3; 2629 - } 2630 - } 2631 - done: 2632 - if (ieee->set_security) 2633 - ieee->set_security(ieee->dev, &sec); 2634 - 2635 - /* Do not reset port if card is in Managed mode since resetting will 2636 - * generate new IEEE 802.11 authentication which may end up in looping 2637 - * with IEEE 802.1X. If your hardware requires a reset after WEP 2638 - * configuration (for example... Prism2), implement the reset_port in 2639 - * the callbacks structures used to initialize the 802.11 stack. */ 2640 - if (ieee->reset_on_keychange && 2641 - ieee->iw_mode != IW_MODE_INFRA && 2642 - ieee->reset_port && 2643 - ieee->reset_port(ieee->dev)) { 2644 - printk("reset_port failed\n"); 2645 - param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED; 2646 - return -EINVAL; 2647 - } 2648 - 2649 - return ret; 2650 - } 2651 - 2652 - int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, 2653 - struct iw_point *p) 2654 - { 2655 - struct ieee_param *param; 2656 - int ret = 0; 2657 - 2658 - down(&ieee->wx_sem); 2659 - 2660 - if (p->length < sizeof(struct ieee_param) || !p->pointer) { 2661 - ret = -EINVAL; 2662 - goto out; 2663 - } 2664 - 2665 - param = memdup_user(p->pointer, p->length); 2666 - if (IS_ERR(param)) { 2667 - ret = PTR_ERR(param); 2668 - goto out; 2669 - } 2670 - 2671 - switch (param->cmd) { 2672 - case IEEE_CMD_SET_WPA_PARAM: 2673 - ret = ieee80211_wpa_set_param(ieee, param->u.wpa_param.name, 2674 - param->u.wpa_param.value); 2675 - break; 2676 - case IEEE_CMD_SET_WPA_IE: 2677 - ret = ieee80211_wpa_set_wpa_ie(ieee, param, p->length); 2678 - break; 2679 - case IEEE_CMD_SET_ENCRYPTION: 2680 - ret = ieee80211_wpa_set_encryption(ieee, param, p->length); 2681 - break; 2682 - case IEEE_CMD_MLME: 2683 - ret = ieee80211_wpa_mlme(ieee, param->u.mlme.command, 2684 - param->u.mlme.reason_code); 2685 - break; 2686 - default: 2687 - printk("Unknown WPA supplicant request: %d\n", param->cmd); 2688 - ret = -EOPNOTSUPP; 2689 - break; 2690 - } 2691 - 2692 - if (ret == 0 && copy_to_user(p->pointer, param, p->length)) 2693 - ret = -EFAULT; 2694 - 2695 - kfree(param); 2696 - out: 2697 - up(&ieee->wx_sem); 2698 - 2699 - return ret; 2700 - } 2701 - 2702 - void notify_wx_assoc_event(struct ieee80211_device *ieee) 2703 - { 2704 - union iwreq_data wrqu; 2705 - wrqu.ap_addr.sa_family = ARPHRD_ETHER; 2706 - if (ieee->state == IEEE80211_LINKED) 2707 - memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid, ETH_ALEN); 2708 - else 2709 - memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); 2710 - wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL); 2711 - }
-567
drivers/staging/rtl8187se/ieee80211/ieee80211_softmac_wx.c
··· 1 - /* IEEE 802.11 SoftMAC layer 2 - * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com> 3 - * 4 - * Mostly extracted from the rtl8180-sa2400 driver for the 5 - * in-kernel generic ieee802.11 stack. 6 - * 7 - * Some pieces of code might be stolen from ipw2100 driver 8 - * copyright of who own it's copyright ;-) 9 - * 10 - * PS wx handler mostly stolen from hostap, copyright who 11 - * own it's copyright ;-) 12 - * 13 - * released under the GPL 14 - */ 15 - 16 - 17 - #include <linux/etherdevice.h> 18 - 19 - #include "ieee80211.h" 20 - 21 - /* FIXME: add A freqs */ 22 - 23 - const long ieee80211_wlan_frequencies[] = { 24 - 2412, 2417, 2422, 2427, 25 - 2432, 2437, 2442, 2447, 26 - 2452, 2457, 2462, 2467, 27 - 2472, 2484 28 - }; 29 - 30 - 31 - int ieee80211_wx_set_freq(struct ieee80211_device *ieee, 32 - struct iw_request_info *a, union iwreq_data *wrqu, 33 - char *b) 34 - { 35 - int ret; 36 - struct iw_freq *fwrq = &wrqu->freq; 37 - // printk("in %s\n",__func__); 38 - down(&ieee->wx_sem); 39 - 40 - if (ieee->iw_mode == IW_MODE_INFRA) { 41 - ret = -EOPNOTSUPP; 42 - goto out; 43 - } 44 - 45 - /* if setting by freq convert to channel */ 46 - if (fwrq->e == 1) { 47 - if ((fwrq->m >= (int) 2.412e8 && 48 - fwrq->m <= (int) 2.487e8)) { 49 - int f = fwrq->m / 100000; 50 - int c = 0; 51 - 52 - while ((c < 14) && (f != ieee80211_wlan_frequencies[c])) 53 - c++; 54 - 55 - /* hack to fall through */ 56 - fwrq->e = 0; 57 - fwrq->m = c + 1; 58 - } 59 - } 60 - 61 - if (fwrq->e > 0 || fwrq->m > 14 || fwrq->m < 1) { 62 - ret = -EOPNOTSUPP; 63 - goto out; 64 - 65 - } else { /* Set the channel */ 66 - 67 - 68 - ieee->current_network.channel = fwrq->m; 69 - ieee->set_chan(ieee->dev, ieee->current_network.channel); 70 - 71 - if (ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER) 72 - if (ieee->state == IEEE80211_LINKED) { 73 - ieee80211_stop_send_beacons(ieee); 74 - ieee80211_start_send_beacons(ieee); 75 - } 76 - } 77 - 78 - ret = 0; 79 - out: 80 - up(&ieee->wx_sem); 81 - return ret; 82 - } 83 - 84 - 85 - int ieee80211_wx_get_freq(struct ieee80211_device *ieee, 86 - struct iw_request_info *a, union iwreq_data *wrqu, 87 - char *b) 88 - { 89 - struct iw_freq *fwrq = &wrqu->freq; 90 - 91 - if (ieee->current_network.channel == 0) 92 - return -1; 93 - 94 - fwrq->m = ieee->current_network.channel; 95 - fwrq->e = 0; 96 - 97 - return 0; 98 - } 99 - 100 - int ieee80211_wx_get_wap(struct ieee80211_device *ieee, 101 - struct iw_request_info *info, union iwreq_data *wrqu, 102 - char *extra) 103 - { 104 - unsigned long flags; 105 - 106 - wrqu->ap_addr.sa_family = ARPHRD_ETHER; 107 - 108 - if (ieee->iw_mode == IW_MODE_MONITOR) 109 - return -1; 110 - 111 - /* We want avoid to give to the user inconsistent infos*/ 112 - spin_lock_irqsave(&ieee->lock, flags); 113 - 114 - if (ieee->state != IEEE80211_LINKED && 115 - ieee->state != IEEE80211_LINKED_SCANNING && 116 - ieee->wap_set == 0) 117 - 118 - memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); 119 - else 120 - memcpy(wrqu->ap_addr.sa_data, 121 - ieee->current_network.bssid, ETH_ALEN); 122 - 123 - spin_unlock_irqrestore(&ieee->lock, flags); 124 - 125 - return 0; 126 - } 127 - 128 - 129 - int ieee80211_wx_set_wap(struct ieee80211_device *ieee, 130 - struct iw_request_info *info, union iwreq_data *awrq, 131 - char *extra) 132 - { 133 - 134 - int ret = 0; 135 - unsigned long flags; 136 - 137 - short ifup = ieee->proto_started;//dev->flags & IFF_UP; 138 - struct sockaddr *temp = (struct sockaddr *)awrq; 139 - 140 - //printk("=======Set WAP:"); 141 - ieee->sync_scan_hurryup = 1; 142 - 143 - down(&ieee->wx_sem); 144 - /* use ifconfig hw ether */ 145 - if (ieee->iw_mode == IW_MODE_MASTER) { 146 - ret = -1; 147 - goto out; 148 - } 149 - 150 - if (temp->sa_family != ARPHRD_ETHER) { 151 - ret = -EINVAL; 152 - goto out; 153 - } 154 - 155 - if (ifup) 156 - ieee80211_stop_protocol(ieee); 157 - 158 - /* just to avoid to give inconsistent infos in the 159 - * get wx method. not really needed otherwise 160 - */ 161 - spin_lock_irqsave(&ieee->lock, flags); 162 - 163 - memcpy(ieee->current_network.bssid, temp->sa_data, ETH_ALEN); 164 - ieee->wap_set = !is_zero_ether_addr(temp->sa_data); 165 - //printk(" %x:%x:%x:%x:%x:%x\n", ieee->current_network.bssid[0],ieee->current_network.bssid[1],ieee->current_network.bssid[2],ieee->current_network.bssid[3],ieee->current_network.bssid[4],ieee->current_network.bssid[5]); 166 - 167 - spin_unlock_irqrestore(&ieee->lock, flags); 168 - 169 - if (ifup) 170 - ieee80211_start_protocol(ieee); 171 - 172 - out: 173 - up(&ieee->wx_sem); 174 - return ret; 175 - } 176 - 177 - int ieee80211_wx_get_essid(struct ieee80211_device *ieee, 178 - struct iw_request_info *a, union iwreq_data *wrqu, 179 - char *b) 180 - { 181 - int len, ret = 0; 182 - unsigned long flags; 183 - 184 - if (ieee->iw_mode == IW_MODE_MONITOR) 185 - return -1; 186 - 187 - /* We want avoid to give to the user inconsistent infos*/ 188 - spin_lock_irqsave(&ieee->lock, flags); 189 - 190 - if (ieee->current_network.ssid[0] == '\0' || 191 - ieee->current_network.ssid_len == 0){ 192 - ret = -1; 193 - goto out; 194 - } 195 - 196 - if (ieee->state != IEEE80211_LINKED && 197 - ieee->state != IEEE80211_LINKED_SCANNING && 198 - ieee->ssid_set == 0){ 199 - ret = -1; 200 - goto out; 201 - } 202 - len = ieee->current_network.ssid_len; 203 - wrqu->essid.length = len; 204 - strncpy(b, ieee->current_network.ssid, len); 205 - wrqu->essid.flags = 1; 206 - 207 - out: 208 - spin_unlock_irqrestore(&ieee->lock, flags); 209 - 210 - return ret; 211 - 212 - } 213 - 214 - int ieee80211_wx_set_rate(struct ieee80211_device *ieee, 215 - struct iw_request_info *info, union iwreq_data *wrqu, 216 - char *extra) 217 - { 218 - 219 - u32 target_rate = wrqu->bitrate.value; 220 - 221 - //added by lizhaoming for auto mode 222 - if (target_rate == -1) 223 - ieee->rate = 110; 224 - else 225 - ieee->rate = target_rate/100000; 226 - 227 - //FIXME: we might want to limit rate also in management protocols. 228 - return 0; 229 - } 230 - 231 - 232 - 233 - int ieee80211_wx_get_rate(struct ieee80211_device *ieee, 234 - struct iw_request_info *info, union iwreq_data *wrqu, 235 - char *extra) 236 - { 237 - 238 - wrqu->bitrate.value = ieee->rate * 100000; 239 - 240 - return 0; 241 - } 242 - 243 - int ieee80211_wx_set_mode(struct ieee80211_device *ieee, 244 - struct iw_request_info *a, union iwreq_data *wrqu, 245 - char *b) 246 - { 247 - 248 - ieee->sync_scan_hurryup = 1; 249 - 250 - down(&ieee->wx_sem); 251 - 252 - if (wrqu->mode == ieee->iw_mode) 253 - goto out; 254 - 255 - if (wrqu->mode == IW_MODE_MONITOR) 256 - ieee->dev->type = ARPHRD_IEEE80211; 257 - else 258 - ieee->dev->type = ARPHRD_ETHER; 259 - 260 - if (!ieee->proto_started) { 261 - ieee->iw_mode = wrqu->mode; 262 - } else { 263 - ieee80211_stop_protocol(ieee); 264 - ieee->iw_mode = wrqu->mode; 265 - ieee80211_start_protocol(ieee); 266 - } 267 - 268 - out: 269 - up(&ieee->wx_sem); 270 - return 0; 271 - } 272 - 273 - 274 - void ieee80211_wx_sync_scan_wq(struct work_struct *work) 275 - { 276 - struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, wx_sync_scan_wq); 277 - short chan; 278 - 279 - chan = ieee->current_network.channel; 280 - 281 - if (ieee->data_hard_stop) 282 - ieee->data_hard_stop(ieee->dev); 283 - 284 - ieee80211_stop_send_beacons(ieee); 285 - 286 - ieee->state = IEEE80211_LINKED_SCANNING; 287 - ieee->link_change(ieee->dev); 288 - 289 - ieee80211_start_scan_syncro(ieee); 290 - 291 - ieee->set_chan(ieee->dev, chan); 292 - 293 - ieee->state = IEEE80211_LINKED; 294 - ieee->link_change(ieee->dev); 295 - 296 - if (ieee->data_hard_resume) 297 - ieee->data_hard_resume(ieee->dev); 298 - 299 - if (ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER) 300 - ieee80211_start_send_beacons(ieee); 301 - 302 - //YJ,add,080828, In prevent of lossing ping packet during scanning 303 - //ieee80211_sta_ps_send_null_frame(ieee, false); 304 - //YJ,add,080828,end 305 - 306 - up(&ieee->wx_sem); 307 - 308 - } 309 - 310 - int ieee80211_wx_set_scan(struct ieee80211_device *ieee, 311 - struct iw_request_info *a, union iwreq_data *wrqu, 312 - char *b) 313 - { 314 - int ret = 0; 315 - 316 - down(&ieee->wx_sem); 317 - 318 - if (ieee->iw_mode == IW_MODE_MONITOR || !(ieee->proto_started)) { 319 - ret = -1; 320 - goto out; 321 - } 322 - //YJ,add,080828 323 - //In prevent of lossing ping packet during scanning 324 - //ieee80211_sta_ps_send_null_frame(ieee, true); 325 - //YJ,add,080828,end 326 - 327 - if (ieee->state == IEEE80211_LINKED) { 328 - queue_work(ieee->wq, &ieee->wx_sync_scan_wq); 329 - /* intentionally forget to up sem */ 330 - return 0; 331 - } 332 - 333 - out: 334 - up(&ieee->wx_sem); 335 - return ret; 336 - } 337 - 338 - int ieee80211_wx_set_essid(struct ieee80211_device *ieee, 339 - struct iw_request_info *a, union iwreq_data *wrqu, 340 - char *extra) 341 - { 342 - 343 - int ret = 0, len; 344 - short proto_started; 345 - unsigned long flags; 346 - 347 - ieee->sync_scan_hurryup = 1; 348 - 349 - down(&ieee->wx_sem); 350 - 351 - proto_started = ieee->proto_started; 352 - 353 - if (wrqu->essid.length > IW_ESSID_MAX_SIZE) { 354 - ret = -E2BIG; 355 - goto out; 356 - } 357 - 358 - if (ieee->iw_mode == IW_MODE_MONITOR) { 359 - ret = -1; 360 - goto out; 361 - } 362 - 363 - if (proto_started) 364 - ieee80211_stop_protocol(ieee); 365 - 366 - /* this is just to be sure that the GET wx callback 367 - * has consistent infos. not needed otherwise 368 - */ 369 - spin_lock_irqsave(&ieee->lock, flags); 370 - 371 - if (wrqu->essid.flags && wrqu->essid.length) { 372 - //YJ,modified,080819 373 - len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ? (wrqu->essid.length) : IW_ESSID_MAX_SIZE; 374 - memset(ieee->current_network.ssid, 0, ieee->current_network.ssid_len); //YJ,add,080819 375 - strncpy(ieee->current_network.ssid, extra, len); 376 - ieee->current_network.ssid_len = len; 377 - ieee->ssid_set = 1; 378 - //YJ,modified,080819,end 379 - 380 - //YJ,add,080819,for hidden ap 381 - if (len == 0) { 382 - memset(ieee->current_network.bssid, 0, ETH_ALEN); 383 - ieee->current_network.capability = 0; 384 - } 385 - //YJ,add,080819,for hidden ap,end 386 - } else { 387 - ieee->ssid_set = 0; 388 - ieee->current_network.ssid[0] = '\0'; 389 - ieee->current_network.ssid_len = 0; 390 - } 391 - //printk("==========set essid %s!\n",ieee->current_network.ssid); 392 - spin_unlock_irqrestore(&ieee->lock, flags); 393 - 394 - if (proto_started) 395 - ieee80211_start_protocol(ieee); 396 - out: 397 - up(&ieee->wx_sem); 398 - return ret; 399 - } 400 - 401 - int ieee80211_wx_get_mode(struct ieee80211_device *ieee, 402 - struct iw_request_info *a, union iwreq_data *wrqu, 403 - char *b) 404 - { 405 - 406 - wrqu->mode = ieee->iw_mode; 407 - return 0; 408 - } 409 - 410 - int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee, 411 - struct iw_request_info *info, union iwreq_data *wrqu, 412 - char *extra) 413 - { 414 - 415 - int *parms = (int *)extra; 416 - int enable = (parms[0] > 0); 417 - short prev = ieee->raw_tx; 418 - 419 - down(&ieee->wx_sem); 420 - 421 - if (enable) 422 - ieee->raw_tx = 1; 423 - else 424 - ieee->raw_tx = 0; 425 - 426 - netdev_info(ieee->dev, "raw TX is %s\n", 427 - ieee->raw_tx ? "enabled" : "disabled"); 428 - 429 - if (ieee->iw_mode == IW_MODE_MONITOR) { 430 - if (prev == 0 && ieee->raw_tx) { 431 - if (ieee->data_hard_resume) 432 - ieee->data_hard_resume(ieee->dev); 433 - 434 - netif_carrier_on(ieee->dev); 435 - } 436 - 437 - if (prev && ieee->raw_tx == 1) 438 - netif_carrier_off(ieee->dev); 439 - } 440 - 441 - up(&ieee->wx_sem); 442 - 443 - return 0; 444 - } 445 - 446 - int ieee80211_wx_get_name(struct ieee80211_device *ieee, 447 - struct iw_request_info *info, union iwreq_data *wrqu, 448 - char *extra) 449 - { 450 - strlcpy(wrqu->name, "802.11", IFNAMSIZ); 451 - if (ieee->modulation & IEEE80211_CCK_MODULATION) { 452 - strlcat(wrqu->name, "b", IFNAMSIZ); 453 - if (ieee->modulation & IEEE80211_OFDM_MODULATION) 454 - strlcat(wrqu->name, "/g", IFNAMSIZ); 455 - } else if (ieee->modulation & IEEE80211_OFDM_MODULATION) 456 - strlcat(wrqu->name, "g", IFNAMSIZ); 457 - 458 - if ((ieee->state == IEEE80211_LINKED) || 459 - (ieee->state == IEEE80211_LINKED_SCANNING)) 460 - strlcat(wrqu->name, " link", IFNAMSIZ); 461 - else if (ieee->state != IEEE80211_NOLINK) 462 - strlcat(wrqu->name, " .....", IFNAMSIZ); 463 - 464 - 465 - return 0; 466 - } 467 - 468 - 469 - /* this is mostly stolen from hostap */ 470 - int ieee80211_wx_set_power(struct ieee80211_device *ieee, 471 - struct iw_request_info *info, union iwreq_data *wrqu, 472 - char *extra) 473 - { 474 - int ret = 0; 475 - 476 - if ((!ieee->sta_wake_up) || 477 - (!ieee->ps_request_tx_ack) || 478 - (!ieee->enter_sleep_state) || 479 - (!ieee->ps_is_queue_empty)) { 480 - 481 - printk("ERROR. PS mode tried to be use but driver missed a callback\n\n"); 482 - 483 - return -1; 484 - } 485 - 486 - down(&ieee->wx_sem); 487 - 488 - if (wrqu->power.disabled) { 489 - ieee->ps = IEEE80211_PS_DISABLED; 490 - 491 - goto exit; 492 - } 493 - switch (wrqu->power.flags & IW_POWER_MODE) { 494 - case IW_POWER_UNICAST_R: 495 - ieee->ps = IEEE80211_PS_UNICAST; 496 - 497 - break; 498 - case IW_POWER_ALL_R: 499 - ieee->ps = IEEE80211_PS_UNICAST | IEEE80211_PS_MBCAST; 500 - break; 501 - 502 - case IW_POWER_ON: 503 - ieee->ps = IEEE80211_PS_DISABLED; 504 - break; 505 - 506 - default: 507 - ret = -EINVAL; 508 - goto exit; 509 - } 510 - 511 - if (wrqu->power.flags & IW_POWER_TIMEOUT) { 512 - 513 - ieee->ps_timeout = wrqu->power.value / 1000; 514 - printk("Timeout %d\n", ieee->ps_timeout); 515 - } 516 - 517 - if (wrqu->power.flags & IW_POWER_PERIOD) { 518 - 519 - ret = -EOPNOTSUPP; 520 - goto exit; 521 - //wrq->value / 1024; 522 - 523 - } 524 - exit: 525 - up(&ieee->wx_sem); 526 - return ret; 527 - 528 - } 529 - 530 - /* this is stolen from hostap */ 531 - int ieee80211_wx_get_power(struct ieee80211_device *ieee, 532 - struct iw_request_info *info, union iwreq_data *wrqu, 533 - char *extra) 534 - { 535 - int ret = 0; 536 - 537 - down(&ieee->wx_sem); 538 - 539 - if (ieee->ps == IEEE80211_PS_DISABLED) { 540 - wrqu->power.disabled = 1; 541 - goto exit; 542 - } 543 - 544 - wrqu->power.disabled = 0; 545 - 546 - // if ((wrqu->power.flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { 547 - wrqu->power.flags = IW_POWER_TIMEOUT; 548 - wrqu->power.value = ieee->ps_timeout * 1000; 549 - // } else { 550 - // ret = -EOPNOTSUPP; 551 - // goto exit; 552 - //wrqu->power.flags = IW_POWER_PERIOD; 553 - //wrqu->power.value = ieee->current_network.dtim_period * 554 - // ieee->current_network.beacon_interval * 1024; 555 - // } 556 - 557 - 558 - if (ieee->ps & IEEE80211_PS_MBCAST) 559 - wrqu->power.flags |= IW_POWER_ALL_R; 560 - else 561 - wrqu->power.flags |= IW_POWER_UNICAST_R; 562 - 563 - exit: 564 - up(&ieee->wx_sem); 565 - return ret; 566 - 567 - }
-591
drivers/staging/rtl8187se/ieee80211/ieee80211_tx.c
··· 1 - /****************************************************************************** 2 - 3 - Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved. 4 - 5 - This program is free software; you can redistribute it and/or modify it 6 - under the terms of version 2 of the GNU General Public License as 7 - published by the Free Software Foundation. 8 - 9 - This program is distributed in the hope that it will be useful, but WITHOUT 10 - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 - more details. 13 - 14 - You should have received a copy of the GNU General Public License along with 15 - this program; if not, write to the Free Software Foundation, Inc., 59 16 - Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 - 18 - The full GNU General Public License is included in this distribution in the 19 - file called LICENSE. 20 - 21 - Contact Information: 22 - James P. Ketrenos <ipw2100-admin@linux.intel.com> 23 - Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 24 - 25 - ****************************************************************************** 26 - 27 - Few modifications for Realtek's Wi-Fi drivers by 28 - Andrea Merello <andrea.merello@gmail.com> 29 - 30 - A special thanks goes to Realtek for their support ! 31 - 32 - ******************************************************************************/ 33 - 34 - #include <linux/compiler.h> 35 - #include <linux/errno.h> 36 - #include <linux/if_arp.h> 37 - #include <linux/in6.h> 38 - #include <linux/in.h> 39 - #include <linux/ip.h> 40 - #include <linux/kernel.h> 41 - #include <linux/module.h> 42 - #include <linux/netdevice.h> 43 - #include <linux/pci.h> 44 - #include <linux/proc_fs.h> 45 - #include <linux/skbuff.h> 46 - #include <linux/slab.h> 47 - #include <linux/tcp.h> 48 - #include <linux/types.h> 49 - #include <linux/wireless.h> 50 - #include <linux/etherdevice.h> 51 - #include <asm/uaccess.h> 52 - #include <linux/if_vlan.h> 53 - 54 - #include "ieee80211.h" 55 - 56 - 57 - /* 58 - 59 - 60 - 802.11 Data Frame 61 - 62 - 63 - 802.11 frame_contorl for data frames - 2 bytes 64 - ,-----------------------------------------------------------------------------------------. 65 - bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e | 66 - |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------| 67 - val | 0 | 0 | 0 | 1 | x | 0 | 0 | 0 | 1 | 0 | x | x | x | x | x | 68 - |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------| 69 - desc | ^-ver-^ | ^type-^ | ^-----subtype-----^ | to |from |more |retry| pwr |more |wep | 70 - | | | x=0 data,x=1 data+ack | DS | DS |frag | | mgm |data | | 71 - '-----------------------------------------------------------------------------------------' 72 - /\ 73 - | 74 - 802.11 Data Frame | 75 - ,--------- 'ctrl' expands to >-----------' 76 - | 77 - ,--'---,-------------------------------------------------------------. 78 - Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 | 79 - |------|------|---------|---------|---------|------|---------|------| 80 - Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | Frame | fcs | 81 - | | tion | (BSSID) | | | ence | data | | 82 - `--------------------------------------------------| |------' 83 - Total: 28 non-data bytes `----.----' 84 - | 85 - .- 'Frame data' expands to <---------------------------' 86 - | 87 - V 88 - ,---------------------------------------------------. 89 - Bytes | 1 | 1 | 1 | 3 | 2 | 0-2304 | 90 - |------|------|---------|----------|------|---------| 91 - Desc. | SNAP | SNAP | Control |Eth Tunnel| Type | IP | 92 - | DSAP | SSAP | | | | Packet | 93 - | 0xAA | 0xAA |0x03 (UI)|0x00-00-F8| | | 94 - `-----------------------------------------| | 95 - Total: 8 non-data bytes `----.----' 96 - | 97 - .- 'IP Packet' expands, if WEP enabled, to <--' 98 - | 99 - V 100 - ,-----------------------. 101 - Bytes | 4 | 0-2296 | 4 | 102 - |-----|-----------|-----| 103 - Desc. | IV | Encrypted | ICV | 104 - | | IP Packet | | 105 - `-----------------------' 106 - Total: 8 non-data bytes 107 - 108 - 109 - 802.3 Ethernet Data Frame 110 - 111 - ,-----------------------------------------. 112 - Bytes | 6 | 6 | 2 | Variable | 4 | 113 - |-------|-------|------|-----------|------| 114 - Desc. | Dest. | Source| Type | IP Packet | fcs | 115 - | MAC | MAC | | | | 116 - `-----------------------------------------' 117 - Total: 18 non-data bytes 118 - 119 - In the event that fragmentation is required, the incoming payload is split into 120 - N parts of size ieee->fts. The first fragment contains the SNAP header and the 121 - remaining packets are just data. 122 - 123 - If encryption is enabled, each fragment payload size is reduced by enough space 124 - to add the prefix and postfix (IV and ICV totalling 8 bytes in the case of WEP) 125 - So if you have 1500 bytes of payload with ieee->fts set to 500 without 126 - encryption it will take 3 frames. With WEP it will take 4 frames as the 127 - payload of each frame is reduced to 492 bytes. 128 - 129 - * SKB visualization 130 - * 131 - * ,- skb->data 132 - * | 133 - * | ETHERNET HEADER ,-<-- PAYLOAD 134 - * | | 14 bytes from skb->data 135 - * | 2 bytes for Type --> ,T. | (sizeof ethhdr) 136 - * | | | | 137 - * |,-Dest.--. ,--Src.---. | | | 138 - * | 6 bytes| | 6 bytes | | | | 139 - * v | | | | | | 140 - * 0 | v 1 | v | v 2 141 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 142 - * ^ | ^ | ^ | 143 - * | | | | | | 144 - * | | | | `T' <---- 2 bytes for Type 145 - * | | | | 146 - * | | '---SNAP--' <-------- 6 bytes for SNAP 147 - * | | 148 - * `-IV--' <-------------------- 4 bytes for IV (WEP) 149 - * 150 - * SNAP HEADER 151 - * 152 - */ 153 - 154 - static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 }; 155 - static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 }; 156 - 157 - static inline int ieee80211_put_snap(u8 *data, u16 h_proto) 158 - { 159 - struct ieee80211_snap_hdr *snap; 160 - u8 *oui; 161 - 162 - snap = (struct ieee80211_snap_hdr *)data; 163 - snap->dsap = 0xaa; 164 - snap->ssap = 0xaa; 165 - snap->ctrl = 0x03; 166 - 167 - if (h_proto == 0x8137 || h_proto == 0x80f3) 168 - oui = P802_1H_OUI; 169 - else 170 - oui = RFC1042_OUI; 171 - snap->oui[0] = oui[0]; 172 - snap->oui[1] = oui[1]; 173 - snap->oui[2] = oui[2]; 174 - 175 - *(u16 *)(data + SNAP_SIZE) = htons(h_proto); 176 - 177 - return SNAP_SIZE + sizeof(u16); 178 - } 179 - 180 - int ieee80211_encrypt_fragment(struct ieee80211_device *ieee, 181 - struct sk_buff *frag, int hdr_len) 182 - { 183 - struct ieee80211_crypt_data* crypt = ieee->crypt[ieee->tx_keyidx]; 184 - int res; 185 - 186 - /* 187 - * added to care about null crypt condition, to solve that system hangs 188 - * when shared keys error 189 - */ 190 - if (!crypt || !crypt->ops) 191 - return -1; 192 - 193 - #ifdef CONFIG_IEEE80211_CRYPT_TKIP 194 - struct ieee80211_hdr_4addr *header; 195 - 196 - if (ieee->tkip_countermeasures && 197 - crypt && crypt->ops && strcmp(crypt->ops->name, "TKIP") == 0) { 198 - header = (struct ieee80211_hdr_4addr *)frag->data; 199 - if (net_ratelimit()) { 200 - netdev_dbg(ieee->dev, "TKIP countermeasures: dropped " 201 - "TX packet to %pM\n", header->addr1); 202 - } 203 - return -1; 204 - } 205 - #endif 206 - /* 207 - * To encrypt, frame format is: 208 - * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes) 209 - * 210 - * PR: FIXME: Copied from hostap. Check fragmentation/MSDU/MPDU 211 - * encryption. 212 - * 213 - * Host-based IEEE 802.11 fragmentation for TX is not yet supported, so 214 - * call both MSDU and MPDU encryption functions from here. 215 - */ 216 - atomic_inc(&crypt->refcnt); 217 - res = 0; 218 - if (crypt->ops->encrypt_msdu) 219 - res = crypt->ops->encrypt_msdu(frag, hdr_len, crypt->priv); 220 - if (res == 0 && crypt->ops->encrypt_mpdu) 221 - res = crypt->ops->encrypt_mpdu(frag, hdr_len, crypt->priv); 222 - 223 - atomic_dec(&crypt->refcnt); 224 - if (res < 0) { 225 - netdev_info(ieee->dev, "Encryption failed: len=%d.\n", frag->len); 226 - ieee->ieee_stats.tx_discards++; 227 - return -1; 228 - } 229 - 230 - return 0; 231 - } 232 - 233 - 234 - void ieee80211_txb_free(struct ieee80211_txb *txb) 235 - { 236 - int i; 237 - if (unlikely(!txb)) 238 - return; 239 - for (i = 0; i < txb->nr_frags; i++) 240 - if (txb->fragments[i]) 241 - dev_kfree_skb_any(txb->fragments[i]); 242 - kfree(txb); 243 - } 244 - 245 - static struct ieee80211_txb *ieee80211_alloc_txb(int nr_frags, int txb_size, 246 - gfp_t gfp_mask) 247 - { 248 - struct ieee80211_txb *txb; 249 - int i; 250 - txb = kmalloc( 251 - sizeof(struct ieee80211_txb) + (sizeof(u8 *) * nr_frags), 252 - gfp_mask); 253 - if (!txb) 254 - return NULL; 255 - 256 - memset(txb, 0, sizeof(struct ieee80211_txb)); 257 - txb->nr_frags = nr_frags; 258 - txb->frag_size = txb_size; 259 - 260 - for (i = 0; i < nr_frags; i++) { 261 - txb->fragments[i] = dev_alloc_skb(txb_size); 262 - if (unlikely(!txb->fragments[i])) { 263 - i--; 264 - break; 265 - } 266 - } 267 - if (unlikely(i != nr_frags)) { 268 - while (i >= 0) 269 - dev_kfree_skb_any(txb->fragments[i--]); 270 - kfree(txb); 271 - return NULL; 272 - } 273 - return txb; 274 - } 275 - 276 - /* 277 - * Classify the to-be send data packet 278 - * Need to acquire the sent queue index. 279 - */ 280 - static int ieee80211_classify(struct sk_buff *skb, 281 - struct ieee80211_network *network) 282 - { 283 - struct ether_header *eh = (struct ether_header *)skb->data; 284 - unsigned int wme_UP = 0; 285 - 286 - if (!network->QoS_Enable) { 287 - skb->priority = 0; 288 - return(wme_UP); 289 - } 290 - 291 - if (eh->ether_type == __constant_htons(ETHERTYPE_IP)) { 292 - const struct iphdr *ih = (struct iphdr *)(skb->data + 293 - sizeof(struct ether_header)); 294 - wme_UP = (ih->tos >> 5)&0x07; 295 - } else if (vlan_tx_tag_present(skb)) {/* vtag packet */ 296 - #ifndef VLAN_PRI_SHIFT 297 - #define VLAN_PRI_SHIFT 13 /* Shift to find VLAN user priority */ 298 - #define VLAN_PRI_MASK 7 /* Mask for user priority bits in VLAN */ 299 - #endif 300 - u32 tag = vlan_tx_tag_get(skb); 301 - wme_UP = (tag >> VLAN_PRI_SHIFT) & VLAN_PRI_MASK; 302 - } else if (ETH_P_PAE == ntohs(((struct ethhdr *)skb->data)->h_proto)) { 303 - wme_UP = 7; 304 - } 305 - 306 - skb->priority = wme_UP; 307 - return(wme_UP); 308 - } 309 - 310 - /* SKBs are added to the ieee->tx_queue. */ 311 - int ieee80211_rtl_xmit(struct sk_buff *skb, struct net_device *dev) 312 - { 313 - struct ieee80211_device *ieee = netdev_priv(dev); 314 - struct ieee80211_txb *txb = NULL; 315 - struct ieee80211_hdr_3addrqos *frag_hdr; 316 - int i, bytes_per_frag, nr_frags, bytes_last_frag, frag_size; 317 - unsigned long flags; 318 - struct net_device_stats *stats = &ieee->stats; 319 - int ether_type, encrypt; 320 - int bytes, fc, qos_ctl, hdr_len; 321 - struct sk_buff *skb_frag; 322 - struct ieee80211_hdr_3addrqos header = { /* Ensure zero initialized */ 323 - .duration_id = 0, 324 - .seq_ctl = 0, 325 - .qos_ctl = 0 326 - }; 327 - u8 dest[ETH_ALEN], src[ETH_ALEN]; 328 - 329 - struct ieee80211_crypt_data* crypt; 330 - 331 - spin_lock_irqsave(&ieee->lock, flags); 332 - 333 - /* 334 - * If there is no driver handler to take the TXB, don't bother 335 - * creating it... 336 - */ 337 - if ((!ieee->hard_start_xmit && 338 - !(ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)) || 339 - ((!ieee->softmac_data_hard_start_xmit && 340 - (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) { 341 - netdev_warn(ieee->dev, "No xmit handler.\n"); 342 - goto success; 343 - } 344 - 345 - ieee80211_classify(skb,&ieee->current_network); 346 - if (likely(ieee->raw_tx == 0)){ 347 - 348 - if (unlikely(skb->len < SNAP_SIZE + sizeof(u16))) { 349 - netdev_warn(ieee->dev, "skb too small (%d).\n", skb->len); 350 - goto success; 351 - } 352 - 353 - ether_type = ntohs(((struct ethhdr *)skb->data)->h_proto); 354 - 355 - crypt = ieee->crypt[ieee->tx_keyidx]; 356 - 357 - encrypt = !(ether_type == ETH_P_PAE && ieee->ieee802_1x) && 358 - ieee->host_encrypt && crypt && crypt->ops; 359 - 360 - if (!encrypt && ieee->ieee802_1x && 361 - ieee->drop_unencrypted && ether_type != ETH_P_PAE) { 362 - stats->tx_dropped++; 363 - goto success; 364 - } 365 - 366 - #ifdef CONFIG_IEEE80211_DEBUG 367 - if (crypt && !encrypt && ether_type == ETH_P_PAE) { 368 - struct eapol *eap = (struct eapol *)(skb->data + 369 - sizeof(struct ethhdr) - SNAP_SIZE - sizeof(u16)); 370 - IEEE80211_DEBUG_EAP("TX: IEEE 802.11 EAPOL frame: %s\n", 371 - eap_get_type(eap->type)); 372 - } 373 - #endif 374 - 375 - /* Save source and destination addresses */ 376 - memcpy(&dest, skb->data, ETH_ALEN); 377 - memcpy(&src, skb->data+ETH_ALEN, ETH_ALEN); 378 - 379 - /* Advance the SKB to the start of the payload */ 380 - skb_pull(skb, sizeof(struct ethhdr)); 381 - 382 - /* Determine total amount of storage required for TXB packets */ 383 - bytes = skb->len + SNAP_SIZE + sizeof(u16); 384 - 385 - if (ieee->current_network.QoS_Enable) { 386 - if (encrypt) 387 - fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA | 388 - IEEE80211_FCTL_WEP; 389 - else 390 - fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA; 391 - 392 - } else { 393 - if (encrypt) 394 - fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA | 395 - IEEE80211_FCTL_WEP; 396 - else 397 - fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA; 398 - } 399 - 400 - if (ieee->iw_mode == IW_MODE_INFRA) { 401 - fc |= IEEE80211_FCTL_TODS; 402 - /* To DS: Addr1 = BSSID, Addr2 = SA, Addr3 = DA */ 403 - memcpy(&header.addr1, ieee->current_network.bssid, ETH_ALEN); 404 - memcpy(&header.addr2, &src, ETH_ALEN); 405 - memcpy(&header.addr3, &dest, ETH_ALEN); 406 - } else if (ieee->iw_mode == IW_MODE_ADHOC) { 407 - /* 408 - * not From/To DS: Addr1 = DA, Addr2 = SA, 409 - * Addr3 = BSSID 410 - */ 411 - memcpy(&header.addr1, dest, ETH_ALEN); 412 - memcpy(&header.addr2, src, ETH_ALEN); 413 - memcpy(&header.addr3, ieee->current_network.bssid, ETH_ALEN); 414 - } 415 - header.frame_ctl = cpu_to_le16(fc); 416 - 417 - /* 418 - * Determine fragmentation size based on destination (multicast 419 - * and broadcast are not fragmented) 420 - */ 421 - if (is_multicast_ether_addr(header.addr1)) { 422 - frag_size = MAX_FRAG_THRESHOLD; 423 - qos_ctl = QOS_CTL_NOTCONTAIN_ACK; 424 - } else { 425 - /* default:392 */ 426 - frag_size = ieee->fts; 427 - qos_ctl = 0; 428 - } 429 - 430 - if (ieee->current_network.QoS_Enable) { 431 - hdr_len = IEEE80211_3ADDR_LEN + 2; 432 - /* skb->priority is set in the ieee80211_classify() */ 433 - qos_ctl |= skb->priority; 434 - header.qos_ctl = cpu_to_le16(qos_ctl); 435 - } else { 436 - hdr_len = IEEE80211_3ADDR_LEN; 437 - } 438 - 439 - /* 440 - * Determine amount of payload per fragment. Regardless of if 441 - * this stack is providing the full 802.11 header, one will 442 - * eventually be affixed to this fragment -- so we must account 443 - * for it when determining the amount of payload space. 444 - */ 445 - bytes_per_frag = frag_size - hdr_len; 446 - if (ieee->config & 447 - (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS)) 448 - bytes_per_frag -= IEEE80211_FCS_LEN; 449 - 450 - /* Each fragment may need to have room for encryption pre/postfix */ 451 - if (encrypt) 452 - bytes_per_frag -= crypt->ops->extra_prefix_len + 453 - crypt->ops->extra_postfix_len; 454 - 455 - /* 456 - * Number of fragments is the total bytes_per_frag / 457 - * payload_per_fragment 458 - */ 459 - nr_frags = bytes / bytes_per_frag; 460 - bytes_last_frag = bytes % bytes_per_frag; 461 - if (bytes_last_frag) 462 - nr_frags++; 463 - else 464 - bytes_last_frag = bytes_per_frag; 465 - 466 - /* 467 - * When we allocate the TXB we allocate enough space for the 468 - * reserve and full fragment bytes (bytes_per_frag doesn't 469 - * include prefix, postfix, header, FCS, etc.) 470 - */ 471 - txb = ieee80211_alloc_txb(nr_frags, frag_size, GFP_ATOMIC); 472 - if (unlikely(!txb)) { 473 - netdev_warn(ieee->dev, "Could not allocate TXB\n"); 474 - goto failed; 475 - } 476 - txb->encrypted = encrypt; 477 - txb->payload_size = bytes; 478 - 479 - for (i = 0; i < nr_frags; i++) { 480 - skb_frag = txb->fragments[i]; 481 - skb_frag->priority = UP2AC(skb->priority); 482 - if (encrypt) 483 - skb_reserve(skb_frag, crypt->ops->extra_prefix_len); 484 - 485 - frag_hdr = (struct ieee80211_hdr_3addrqos *)skb_put( 486 - skb_frag, hdr_len); 487 - memcpy(frag_hdr, &header, hdr_len); 488 - 489 - /* 490 - * If this is not the last fragment, then add the MOREFRAGS 491 - * bit to the frame control 492 - */ 493 - if (i != nr_frags - 1) { 494 - frag_hdr->frame_ctl = cpu_to_le16( 495 - fc | IEEE80211_FCTL_MOREFRAGS); 496 - bytes = bytes_per_frag; 497 - 498 - } else { 499 - /* The last fragment takes the remaining length */ 500 - bytes = bytes_last_frag; 501 - } 502 - if (ieee->current_network.QoS_Enable) { 503 - /* 504 - * add 1 only indicate to corresponding seq 505 - * number control 2006/7/12 506 - */ 507 - frag_hdr->seq_ctl = cpu_to_le16( 508 - ieee->seq_ctrl[UP2AC(skb->priority)+1]<<4 | i); 509 - } else { 510 - frag_hdr->seq_ctl = cpu_to_le16( 511 - ieee->seq_ctrl[0]<<4 | i); 512 - } 513 - 514 - /* Put a SNAP header on the first fragment */ 515 - if (i == 0) { 516 - ieee80211_put_snap( 517 - skb_put(skb_frag, SNAP_SIZE + sizeof(u16)), 518 - ether_type); 519 - bytes -= SNAP_SIZE + sizeof(u16); 520 - } 521 - 522 - memcpy(skb_put(skb_frag, bytes), skb->data, bytes); 523 - 524 - /* Advance the SKB... */ 525 - skb_pull(skb, bytes); 526 - 527 - /* 528 - * Encryption routine will move the header forward in 529 - * order to insert the IV between the header and the 530 - * payload 531 - */ 532 - if (encrypt) 533 - ieee80211_encrypt_fragment(ieee, skb_frag, hdr_len); 534 - if (ieee->config & 535 - (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS)) 536 - skb_put(skb_frag, 4); 537 - } 538 - /* Advance sequence number in data frame. */ 539 - if (ieee->current_network.QoS_Enable) { 540 - if (ieee->seq_ctrl[UP2AC(skb->priority) + 1] == 0xFFF) 541 - ieee->seq_ctrl[UP2AC(skb->priority) + 1] = 0; 542 - else 543 - ieee->seq_ctrl[UP2AC(skb->priority) + 1]++; 544 - } else { 545 - if (ieee->seq_ctrl[0] == 0xFFF) 546 - ieee->seq_ctrl[0] = 0; 547 - else 548 - ieee->seq_ctrl[0]++; 549 - } 550 - } else { 551 - if (unlikely(skb->len < sizeof(struct ieee80211_hdr_3addr))) { 552 - netdev_warn(ieee->dev, "skb too small (%d).\n", skb->len); 553 - goto success; 554 - } 555 - 556 - txb = ieee80211_alloc_txb(1, skb->len, GFP_ATOMIC); 557 - if (!txb) { 558 - netdev_warn(ieee->dev, "Could not allocate TXB\n"); 559 - goto failed; 560 - } 561 - 562 - txb->encrypted = 0; 563 - txb->payload_size = skb->len; 564 - memcpy(skb_put(txb->fragments[0], skb->len), skb->data, skb->len); 565 - } 566 - 567 - success: 568 - spin_unlock_irqrestore(&ieee->lock, flags); 569 - dev_kfree_skb_any(skb); 570 - if (txb) { 571 - if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE) { 572 - ieee80211_softmac_xmit(txb, ieee); 573 - } else { 574 - if ((*ieee->hard_start_xmit)(txb, dev) == 0) { 575 - stats->tx_packets++; 576 - stats->tx_bytes += txb->payload_size; 577 - return NETDEV_TX_OK; 578 - } 579 - ieee80211_txb_free(txb); 580 - } 581 - } 582 - 583 - return NETDEV_TX_OK; 584 - 585 - failed: 586 - spin_unlock_irqrestore(&ieee->lock, flags); 587 - netif_stop_queue(dev); 588 - stats->tx_errors++; 589 - return NETDEV_TX_BUSY; 590 - 591 - }
-713
drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c
··· 1 - /* 2 - * Copyright(c) 2004 Intel Corporation. All rights reserved. 3 - * 4 - * Portions of this file are based on the WEP enablement code provided by the 5 - * Host AP project hostap-drivers v0.1.3 6 - * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen 7 - * <jkmaline@cc.hut.fi> 8 - * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> 9 - * 10 - * This program is free software; you can redistribute it and/or modify it 11 - * under the terms of version 2 of the GNU General Public License as 12 - * published by the Free Software Foundation. 13 - * 14 - * This program is distributed in the hope that it will be useful, but WITHOUT 15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 17 - * more details. 18 - * 19 - * You should have received a copy of the GNU General Public License along with 20 - * this program; if not, write to the Free Software Foundation, Inc., 59 21 - * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 - * 23 - * The full GNU General Public License is included in this distribution in the 24 - * file called LICENSE. 25 - * 26 - * Contact Information: 27 - * James P. Ketrenos <ipw2100-admin@linux.intel.com> 28 - * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 29 - */ 30 - 31 - #include <linux/wireless.h> 32 - #include <linux/kmod.h> 33 - #include <linux/slab.h> 34 - #include <linux/module.h> 35 - #include <linux/etherdevice.h> 36 - 37 - #include "ieee80211.h" 38 - static const char *ieee80211_modes[] = { 39 - "?", "a", "b", "ab", "g", "ag", "bg", "abg" 40 - }; 41 - 42 - #define MAX_CUSTOM_LEN 64 43 - static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee, 44 - char *start, char *stop, 45 - struct ieee80211_network *network, 46 - struct iw_request_info *info) 47 - { 48 - char custom[MAX_CUSTOM_LEN]; 49 - char *p; 50 - struct iw_event iwe; 51 - int i, j; 52 - u8 max_rate, rate; 53 - 54 - /* First entry *MUST* be the AP MAC address */ 55 - iwe.cmd = SIOCGIWAP; 56 - iwe.u.ap_addr.sa_family = ARPHRD_ETHER; 57 - ether_addr_copy(iwe.u.ap_addr.sa_data, network->bssid); 58 - start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN); 59 - 60 - /* Remaining entries will be displayed in the order we provide them */ 61 - 62 - /* Add the ESSID */ 63 - iwe.cmd = SIOCGIWESSID; 64 - iwe.u.data.flags = 1; 65 - if (network->ssid_len == 0) { 66 - iwe.u.data.length = sizeof("<hidden>"); 67 - start = iwe_stream_add_point(info, start, stop, &iwe, "<hidden>"); 68 - } else { 69 - iwe.u.data.length = min_t(u8, network->ssid_len, 32); 70 - start = iwe_stream_add_point(info, start, stop, &iwe, network->ssid); 71 - } 72 - /* Add the protocol name */ 73 - iwe.cmd = SIOCGIWNAME; 74 - snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11%s", ieee80211_modes[network->mode]); 75 - start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN); 76 - 77 - /* Add mode */ 78 - iwe.cmd = SIOCGIWMODE; 79 - if (network->capability & 80 - (WLAN_CAPABILITY_BSS | WLAN_CAPABILITY_IBSS)) { 81 - if (network->capability & WLAN_CAPABILITY_BSS) 82 - iwe.u.mode = IW_MODE_MASTER; 83 - else 84 - iwe.u.mode = IW_MODE_ADHOC; 85 - 86 - start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN); 87 - } 88 - 89 - /* Add frequency/channel */ 90 - iwe.cmd = SIOCGIWFREQ; 91 - iwe.u.freq.m = network->channel; 92 - iwe.u.freq.e = 0; 93 - iwe.u.freq.i = 0; 94 - start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_FREQ_LEN); 95 - 96 - /* Add encryption capability */ 97 - iwe.cmd = SIOCGIWENCODE; 98 - if (network->capability & WLAN_CAPABILITY_PRIVACY) 99 - iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; 100 - else 101 - iwe.u.data.flags = IW_ENCODE_DISABLED; 102 - iwe.u.data.length = 0; 103 - start = iwe_stream_add_point(info, start, stop, &iwe, network->ssid); 104 - 105 - /* Add basic and extended rates */ 106 - max_rate = 0; 107 - p = custom; 108 - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): "); 109 - for (i = 0, j = 0; i < network->rates_len; ) { 110 - if (j < network->rates_ex_len && 111 - ((network->rates_ex[j] & 0x7F) < 112 - (network->rates[i] & 0x7F))) 113 - rate = network->rates_ex[j++] & 0x7F; 114 - else 115 - rate = network->rates[i++] & 0x7F; 116 - if (rate > max_rate) 117 - max_rate = rate; 118 - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), 119 - "%d%s ", rate >> 1, (rate & 1) ? ".5" : ""); 120 - } 121 - for (; j < network->rates_ex_len; j++) { 122 - rate = network->rates_ex[j] & 0x7F; 123 - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), 124 - "%d%s ", rate >> 1, (rate & 1) ? ".5" : ""); 125 - if (rate > max_rate) 126 - max_rate = rate; 127 - } 128 - 129 - iwe.cmd = SIOCGIWRATE; 130 - iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; 131 - iwe.u.bitrate.value = max_rate * 500000; 132 - start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_PARAM_LEN); 133 - 134 - iwe.cmd = IWEVCUSTOM; 135 - iwe.u.data.length = p - custom; 136 - if (iwe.u.data.length) 137 - start = iwe_stream_add_point(info, start, stop, &iwe, custom); 138 - 139 - /* Add quality statistics */ 140 - /* TODO: Fix these values... */ 141 - if (network->stats.signal == 0 || network->stats.rssi == 0) 142 - netdev_info(ieee->dev, "========>signal:%d, rssi:%d\n", 143 - network->stats.signal, network->stats.rssi); 144 - iwe.cmd = IWEVQUAL; 145 - iwe.u.qual.qual = network->stats.signalstrength; 146 - iwe.u.qual.level = network->stats.signal; 147 - iwe.u.qual.noise = network->stats.noise; 148 - iwe.u.qual.updated = network->stats.mask & IEEE80211_STATMASK_WEMASK; 149 - if (!(network->stats.mask & IEEE80211_STATMASK_RSSI)) 150 - iwe.u.qual.updated |= IW_QUAL_LEVEL_INVALID; 151 - if (!(network->stats.mask & IEEE80211_STATMASK_NOISE)) 152 - iwe.u.qual.updated |= IW_QUAL_NOISE_INVALID; 153 - if (!(network->stats.mask & IEEE80211_STATMASK_SIGNAL)) 154 - iwe.u.qual.updated |= IW_QUAL_QUAL_INVALID; 155 - iwe.u.qual.updated = 7; 156 - start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN); 157 - 158 - iwe.cmd = IWEVCUSTOM; 159 - p = custom; 160 - 161 - iwe.u.data.length = p - custom; 162 - if (iwe.u.data.length) 163 - start = iwe_stream_add_point(info, start, stop, &iwe, custom); 164 - 165 - memset(&iwe, 0, sizeof(iwe)); 166 - if (network->wpa_ie_len) { 167 - char buf[MAX_WPA_IE_LEN]; 168 - memcpy(buf, network->wpa_ie, network->wpa_ie_len); 169 - iwe.cmd = IWEVGENIE; 170 - iwe.u.data.length = network->wpa_ie_len; 171 - start = iwe_stream_add_point(info, start, stop, &iwe, buf); 172 - } 173 - 174 - memset(&iwe, 0, sizeof(iwe)); 175 - if (network->rsn_ie_len) { 176 - char buf[MAX_WPA_IE_LEN]; 177 - memcpy(buf, network->rsn_ie, network->rsn_ie_len); 178 - iwe.cmd = IWEVGENIE; 179 - iwe.u.data.length = network->rsn_ie_len; 180 - start = iwe_stream_add_point(info, start, stop, &iwe, buf); 181 - } 182 - 183 - /* Add EXTRA: Age to display seconds since last beacon/probe response 184 - * for given network. 185 - */ 186 - iwe.cmd = IWEVCUSTOM; 187 - p = custom; 188 - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), 189 - " Last beacon: %lums ago", (jiffies - network->last_scanned) / (HZ / 100)); 190 - iwe.u.data.length = p - custom; 191 - if (iwe.u.data.length) 192 - start = iwe_stream_add_point(info, start, stop, &iwe, custom); 193 - 194 - return start; 195 - } 196 - 197 - int ieee80211_wx_get_scan(struct ieee80211_device *ieee, 198 - struct iw_request_info *info, 199 - union iwreq_data *wrqu, char *extra) 200 - { 201 - struct ieee80211_network *network; 202 - unsigned long flags; 203 - int err = 0; 204 - char *ev = extra; 205 - char *stop = ev + wrqu->data.length; 206 - int i = 0; 207 - 208 - IEEE80211_DEBUG_WX("Getting scan\n"); 209 - down(&ieee->wx_sem); 210 - spin_lock_irqsave(&ieee->lock, flags); 211 - 212 - if (!ieee->bHwRadioOff) { 213 - list_for_each_entry(network, &ieee->network_list, list) { 214 - i++; 215 - 216 - if ((stop-ev) < 200) { 217 - err = -E2BIG; 218 - break; 219 - } 220 - if (ieee->scan_age == 0 || 221 - time_after(network->last_scanned + ieee->scan_age, jiffies)) { 222 - ev = rtl818x_translate_scan(ieee, ev, stop, network, info); 223 - } else 224 - IEEE80211_DEBUG_SCAN( 225 - "Not showing network '%s (" 226 - "%pM)' due to age (%lums).\n", 227 - escape_essid(network->ssid, 228 - network->ssid_len), 229 - network->bssid, 230 - (jiffies - network->last_scanned) / (HZ / 100)); 231 - } 232 - } 233 - spin_unlock_irqrestore(&ieee->lock, flags); 234 - up(&ieee->wx_sem); 235 - wrqu->data.length = ev - extra; 236 - wrqu->data.flags = 0; 237 - IEEE80211_DEBUG_WX("exit: %d networks returned.\n", i); 238 - 239 - return err; 240 - } 241 - 242 - int ieee80211_wx_set_encode(struct ieee80211_device *ieee, 243 - struct iw_request_info *info, 244 - union iwreq_data *wrqu, char *keybuf) 245 - { 246 - struct iw_point *erq = &(wrqu->encoding); 247 - struct net_device *dev = ieee->dev; 248 - struct ieee80211_security sec = { 249 - .flags = 0 250 - }; 251 - int i, key, key_provided, len; 252 - struct ieee80211_crypt_data **crypt; 253 - 254 - IEEE80211_DEBUG_WX("SET_ENCODE\n"); 255 - 256 - key = erq->flags & IW_ENCODE_INDEX; 257 - if (key) { 258 - if (key > WEP_KEYS) 259 - return -EINVAL; 260 - key--; 261 - key_provided = 1; 262 - } else { 263 - key_provided = 0; 264 - key = ieee->tx_keyidx; 265 - } 266 - 267 - IEEE80211_DEBUG_WX("Key: %d [%s]\n", key, key_provided ? 268 - "provided" : "default"); 269 - 270 - crypt = &ieee->crypt[key]; 271 - 272 - if (erq->flags & IW_ENCODE_DISABLED) { 273 - if (key_provided && *crypt) { 274 - IEEE80211_DEBUG_WX("Disabling encryption on key %d.\n", 275 - key); 276 - ieee80211_crypt_delayed_deinit(ieee, crypt); 277 - } else 278 - IEEE80211_DEBUG_WX("Disabling encryption.\n"); 279 - 280 - /* Check all the keys to see if any are still configured, 281 - * and if no key index was provided, de-init them all. 282 - */ 283 - for (i = 0; i < WEP_KEYS; i++) { 284 - if (ieee->crypt[i] != NULL) { 285 - if (key_provided) 286 - break; 287 - ieee80211_crypt_delayed_deinit( 288 - ieee, &ieee->crypt[i]); 289 - } 290 - } 291 - 292 - if (i == WEP_KEYS) { 293 - sec.enabled = 0; 294 - sec.level = SEC_LEVEL_0; 295 - sec.flags |= SEC_ENABLED | SEC_LEVEL; 296 - } 297 - 298 - goto done; 299 - } 300 - 301 - sec.enabled = 1; 302 - sec.flags |= SEC_ENABLED; 303 - 304 - if (*crypt != NULL && (*crypt)->ops != NULL && 305 - strcmp((*crypt)->ops->name, "WEP") != 0) { 306 - /* changing to use WEP; deinit previously used algorithm 307 - * on this key. 308 - */ 309 - ieee80211_crypt_delayed_deinit(ieee, crypt); 310 - } 311 - 312 - if (*crypt == NULL) { 313 - struct ieee80211_crypt_data *new_crypt; 314 - 315 - /* take WEP into use */ 316 - new_crypt = kzalloc(sizeof(struct ieee80211_crypt_data), 317 - GFP_KERNEL); 318 - if (new_crypt == NULL) 319 - return -ENOMEM; 320 - new_crypt->ops = ieee80211_get_crypto_ops("WEP"); 321 - if (!new_crypt->ops) 322 - new_crypt->ops = ieee80211_get_crypto_ops("WEP"); 323 - 324 - if (new_crypt->ops) 325 - new_crypt->priv = new_crypt->ops->init(key); 326 - 327 - if (!new_crypt->ops || !new_crypt->priv) { 328 - kfree(new_crypt); 329 - new_crypt = NULL; 330 - 331 - netdev_warn(ieee->dev, 332 - "could not initialize WEP: load module ieee80211_crypt_wep\n"); 333 - return -EOPNOTSUPP; 334 - } 335 - *crypt = new_crypt; 336 - } 337 - 338 - /* If a new key was provided, set it up */ 339 - if (erq->length > 0) { 340 - len = erq->length <= 5 ? 5 : 13; 341 - memcpy(sec.keys[key], keybuf, erq->length); 342 - if (len > erq->length) 343 - memset(sec.keys[key] + erq->length, 0, 344 - len - erq->length); 345 - IEEE80211_DEBUG_WX("Setting key %d to '%s' (%d:%d bytes)\n", 346 - key, escape_essid(sec.keys[key], len), 347 - erq->length, len); 348 - sec.key_sizes[key] = len; 349 - (*crypt)->ops->set_key(sec.keys[key], len, NULL, 350 - (*crypt)->priv); 351 - sec.flags |= (1 << key); 352 - /* This ensures a key will be activated if no key is 353 - * explicitly set. 354 - */ 355 - if (key == sec.active_key) 356 - sec.flags |= SEC_ACTIVE_KEY; 357 - ieee->tx_keyidx = key; 358 - } else { 359 - len = (*crypt)->ops->get_key(sec.keys[key], WEP_KEY_LEN, 360 - NULL, (*crypt)->priv); 361 - if (len == 0) { 362 - /* Set a default key of all 0 */ 363 - IEEE80211_DEBUG_WX("Setting key %d to all zero.\n", 364 - key); 365 - memset(sec.keys[key], 0, 13); 366 - (*crypt)->ops->set_key(sec.keys[key], 13, NULL, 367 - (*crypt)->priv); 368 - sec.key_sizes[key] = 13; 369 - sec.flags |= (1 << key); 370 - } 371 - 372 - /* No key data - just set the default TX key index */ 373 - if (key_provided) { 374 - IEEE80211_DEBUG_WX( 375 - "Setting key %d to default Tx key.\n", key); 376 - ieee->tx_keyidx = key; 377 - sec.active_key = key; 378 - sec.flags |= SEC_ACTIVE_KEY; 379 - } 380 - } 381 - 382 - done: 383 - ieee->open_wep = !(erq->flags & IW_ENCODE_RESTRICTED); 384 - sec.auth_mode = ieee->open_wep ? WLAN_AUTH_OPEN : WLAN_AUTH_SHARED_KEY; 385 - sec.flags |= SEC_AUTH_MODE; 386 - IEEE80211_DEBUG_WX("Auth: %s\n", sec.auth_mode == WLAN_AUTH_OPEN ? 387 - "OPEN" : "SHARED KEY"); 388 - 389 - /* For now we just support WEP, so only set that security level... 390 - * TODO: When WPA is added this is one place that needs to change 391 - */ 392 - sec.flags |= SEC_LEVEL; 393 - sec.level = SEC_LEVEL_1; /* 40 and 104 bit WEP */ 394 - 395 - if (ieee->set_security) 396 - ieee->set_security(dev, &sec); 397 - 398 - /* Do not reset port if card is in Managed mode since resetting will 399 - * generate new IEEE 802.11 authentication which may end up in looping 400 - * with IEEE 802.1X. If your hardware requires a reset after WEP 401 - * configuration (for example... Prism2), implement the reset_port in 402 - * the callbacks structures used to initialize the 802.11 stack. 403 - */ 404 - if (ieee->reset_on_keychange && 405 - ieee->iw_mode != IW_MODE_INFRA && 406 - ieee->reset_port && ieee->reset_port(dev)) { 407 - netdev_dbg(ieee->dev, "reset_port failed\n"); 408 - return -EINVAL; 409 - } 410 - return 0; 411 - } 412 - 413 - int ieee80211_wx_get_encode(struct ieee80211_device *ieee, 414 - struct iw_request_info *info, 415 - union iwreq_data *wrqu, char *keybuf) 416 - { 417 - struct iw_point *erq = &(wrqu->encoding); 418 - int len, key; 419 - struct ieee80211_crypt_data *crypt; 420 - 421 - IEEE80211_DEBUG_WX("GET_ENCODE\n"); 422 - 423 - if (ieee->iw_mode == IW_MODE_MONITOR) 424 - return -1; 425 - 426 - key = erq->flags & IW_ENCODE_INDEX; 427 - if (key) { 428 - if (key > WEP_KEYS) 429 - return -EINVAL; 430 - key--; 431 - } else 432 - key = ieee->tx_keyidx; 433 - 434 - crypt = ieee->crypt[key]; 435 - erq->flags = key + 1; 436 - 437 - if (crypt == NULL || crypt->ops == NULL) { 438 - erq->length = 0; 439 - erq->flags |= IW_ENCODE_DISABLED; 440 - return 0; 441 - } 442 - 443 - if (strcmp(crypt->ops->name, "WEP") != 0) { 444 - /* only WEP is supported with wireless extensions, so just 445 - * report that encryption is used. 446 - */ 447 - erq->length = 0; 448 - erq->flags |= IW_ENCODE_ENABLED; 449 - return 0; 450 - } 451 - 452 - len = crypt->ops->get_key(keybuf, WEP_KEY_LEN, NULL, crypt->priv); 453 - erq->length = (len >= 0 ? len : 0); 454 - 455 - erq->flags |= IW_ENCODE_ENABLED; 456 - 457 - if (ieee->open_wep) 458 - erq->flags |= IW_ENCODE_OPEN; 459 - else 460 - erq->flags |= IW_ENCODE_RESTRICTED; 461 - 462 - return 0; 463 - } 464 - 465 - int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee, 466 - struct iw_request_info *info, 467 - union iwreq_data *wrqu, char *extra) 468 - { 469 - struct net_device *dev = ieee->dev; 470 - struct iw_point *encoding = &wrqu->encoding; 471 - struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; 472 - int i, idx, ret = 0; 473 - int group_key = 0; 474 - const char *alg; 475 - struct ieee80211_crypto_ops *ops; 476 - struct ieee80211_crypt_data **crypt; 477 - 478 - struct ieee80211_security sec = { 479 - .flags = 0, 480 - }; 481 - idx = encoding->flags & IW_ENCODE_INDEX; 482 - if (idx) { 483 - if (idx < 1 || idx > WEP_KEYS) 484 - return -EINVAL; 485 - idx--; 486 - } else 487 - idx = ieee->tx_keyidx; 488 - 489 - if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { 490 - crypt = &ieee->crypt[idx]; 491 - group_key = 1; 492 - } else { 493 - /* some Cisco APs use idx>0 for unicast in dynamic WEP */ 494 - if (idx != 0 && ext->alg != IW_ENCODE_ALG_WEP) 495 - return -EINVAL; 496 - if (ieee->iw_mode == IW_MODE_INFRA) 497 - crypt = &ieee->crypt[idx]; 498 - else 499 - return -EINVAL; 500 - } 501 - 502 - sec.flags |= SEC_ENABLED; 503 - if ((encoding->flags & IW_ENCODE_DISABLED) || 504 - ext->alg == IW_ENCODE_ALG_NONE) { 505 - if (*crypt) 506 - ieee80211_crypt_delayed_deinit(ieee, crypt); 507 - 508 - for (i = 0; i < WEP_KEYS; i++) 509 - if (ieee->crypt[i] != NULL) 510 - break; 511 - 512 - if (i == WEP_KEYS) { 513 - sec.enabled = 0; 514 - sec.level = SEC_LEVEL_0; 515 - sec.flags |= SEC_LEVEL; 516 - } 517 - goto done; 518 - } 519 - 520 - sec.enabled = 1; 521 - 522 - switch (ext->alg) { 523 - case IW_ENCODE_ALG_WEP: 524 - alg = "WEP"; 525 - break; 526 - case IW_ENCODE_ALG_TKIP: 527 - alg = "TKIP"; 528 - break; 529 - case IW_ENCODE_ALG_CCMP: 530 - alg = "CCMP"; 531 - break; 532 - default: 533 - IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n", 534 - dev->name, ext->alg); 535 - ret = -EINVAL; 536 - goto done; 537 - } 538 - 539 - ops = ieee80211_get_crypto_ops(alg); 540 - if (ops == NULL) 541 - ops = ieee80211_get_crypto_ops(alg); 542 - if (ops == NULL) { 543 - IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n", 544 - dev->name, ext->alg); 545 - netdev_err(ieee->dev, "========>unknown crypto alg %d\n", 546 - ext->alg); 547 - ret = -EINVAL; 548 - goto done; 549 - } 550 - 551 - if (*crypt == NULL || (*crypt)->ops != ops) { 552 - struct ieee80211_crypt_data *new_crypt; 553 - 554 - ieee80211_crypt_delayed_deinit(ieee, crypt); 555 - 556 - new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL); 557 - if (new_crypt == NULL) { 558 - ret = -ENOMEM; 559 - goto done; 560 - } 561 - new_crypt->ops = ops; 562 - if (new_crypt->ops) 563 - new_crypt->priv = new_crypt->ops->init(idx); 564 - if (new_crypt->priv == NULL) { 565 - kfree(new_crypt); 566 - ret = -EINVAL; 567 - goto done; 568 - } 569 - *crypt = new_crypt; 570 - 571 - } 572 - 573 - if (ext->key_len > 0 && (*crypt)->ops->set_key && 574 - (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq, 575 - (*crypt)->priv) < 0) { 576 - IEEE80211_DEBUG_WX("%s: key setting failed\n", dev->name); 577 - netdev_err(ieee->dev, "key setting failed\n"); 578 - ret = -EINVAL; 579 - goto done; 580 - } 581 - #if 1 582 - if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { 583 - ieee->tx_keyidx = idx; 584 - sec.active_key = idx; 585 - sec.flags |= SEC_ACTIVE_KEY; 586 - } 587 - 588 - if (ext->alg != IW_ENCODE_ALG_NONE) { 589 - memcpy(sec.keys[idx], ext->key, ext->key_len); 590 - sec.key_sizes[idx] = ext->key_len; 591 - sec.flags |= (1 << idx); 592 - if (ext->alg == IW_ENCODE_ALG_WEP) { 593 - sec.flags |= SEC_LEVEL; 594 - sec.level = SEC_LEVEL_1; 595 - } else if (ext->alg == IW_ENCODE_ALG_TKIP) { 596 - sec.flags |= SEC_LEVEL; 597 - sec.level = SEC_LEVEL_2; 598 - } else if (ext->alg == IW_ENCODE_ALG_CCMP) { 599 - sec.flags |= SEC_LEVEL; 600 - sec.level = SEC_LEVEL_3; 601 - } 602 - /* Don't set sec level for group keys. */ 603 - if (group_key) 604 - sec.flags &= ~SEC_LEVEL; 605 - } 606 - #endif 607 - done: 608 - if (ieee->set_security) 609 - ieee->set_security(ieee->dev, &sec); 610 - 611 - if (ieee->reset_on_keychange && 612 - ieee->iw_mode != IW_MODE_INFRA && 613 - ieee->reset_port && ieee->reset_port(dev)) { 614 - IEEE80211_DEBUG_WX("%s: reset_port failed\n", dev->name); 615 - return -EINVAL; 616 - } 617 - 618 - return ret; 619 - } 620 - 621 - int ieee80211_wx_set_mlme(struct ieee80211_device *ieee, 622 - struct iw_request_info *info, 623 - union iwreq_data *wrqu, char *extra) 624 - { 625 - struct iw_mlme *mlme = (struct iw_mlme *) extra; 626 - #if 1 627 - switch (mlme->cmd) { 628 - case IW_MLME_DEAUTH: 629 - case IW_MLME_DISASSOC: 630 - ieee80211_disassociate(ieee); 631 - break; 632 - default: 633 - return -EOPNOTSUPP; 634 - } 635 - #endif 636 - return 0; 637 - } 638 - 639 - int ieee80211_wx_set_auth(struct ieee80211_device *ieee, 640 - struct iw_request_info *info, 641 - struct iw_param *data, char *extra) 642 - { 643 - switch (data->flags & IW_AUTH_INDEX) { 644 - case IW_AUTH_WPA_VERSION: 645 - /* need to support wpa2 here */ 646 - break; 647 - case IW_AUTH_CIPHER_PAIRWISE: 648 - case IW_AUTH_CIPHER_GROUP: 649 - case IW_AUTH_KEY_MGMT: 650 - /* Host AP driver does not use these parameters and allows 651 - * wpa_supplicant to control them internally. 652 - */ 653 - break; 654 - case IW_AUTH_TKIP_COUNTERMEASURES: 655 - ieee->tkip_countermeasures = data->value; 656 - break; 657 - case IW_AUTH_DROP_UNENCRYPTED: 658 - ieee->drop_unencrypted = data->value; 659 - break; 660 - 661 - case IW_AUTH_80211_AUTH_ALG: 662 - ieee->open_wep = (data->value&IW_AUTH_ALG_OPEN_SYSTEM) ? 1 : 0; 663 - break; 664 - 665 - #if 1 666 - case IW_AUTH_WPA_ENABLED: 667 - ieee->wpa_enabled = (data->value) ? 1 : 0; 668 - break; 669 - 670 - #endif 671 - case IW_AUTH_RX_UNENCRYPTED_EAPOL: 672 - ieee->ieee802_1x = data->value; 673 - break; 674 - case IW_AUTH_PRIVACY_INVOKED: 675 - ieee->privacy_invoked = data->value; 676 - break; 677 - default: 678 - return -EOPNOTSUPP; 679 - } 680 - return 0; 681 - } 682 - 683 - #if 1 684 - int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len) 685 - { 686 - u8 *buf = NULL; 687 - 688 - if (len > MAX_WPA_IE_LEN || (len && ie == NULL)) { 689 - netdev_err(ieee->dev, "return error out, len:%zu\n", len); 690 - return -EINVAL; 691 - } 692 - 693 - if (len) { 694 - if (len != ie[1]+2) { 695 - netdev_err(ieee->dev, "len:%zu, ie:%d\n", len, ie[1]); 696 - return -EINVAL; 697 - } 698 - buf = kmemdup(ie, len, GFP_KERNEL); 699 - if (buf == NULL) 700 - return -ENOMEM; 701 - kfree(ieee->wpa_ie); 702 - ieee->wpa_ie = buf; 703 - ieee->wpa_ie_len = len; 704 - } else { 705 - kfree(ieee->wpa_ie); 706 - ieee->wpa_ie = NULL; 707 - ieee->wpa_ie_len = 0; 708 - } 709 - 710 - return 0; 711 - 712 - } 713 - #endif
-640
drivers/staging/rtl8187se/r8180.h
··· 1 - /* 2 - * This is part of rtl8180 OpenSource driver. 3 - * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com> 4 - * Released under the terms of GPL (General Public Licence) 5 - * 6 - * Parts of this driver are based on the GPL part of the official realtek driver 7 - * 8 - * Parts of this driver are based on the rtl8180 driver skeleton from Patric 9 - * Schenke & Andres Salomon 10 - * 11 - * Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver 12 - * 13 - * We want to thanks the Authors of those projects and the Ndiswrapper project 14 - * Authors. 15 - */ 16 - 17 - #ifndef R8180H 18 - #define R8180H 19 - 20 - #include <linux/interrupt.h> 21 - 22 - #define RTL8180_MODULE_NAME "r8180" 23 - #define DMESG(x, a...) printk(KERN_INFO RTL8180_MODULE_NAME ": " x "\n", ## a) 24 - #define DMESGW(x, a...) printk(KERN_WARNING RTL8180_MODULE_NAME ": WW:" x "\n", ## a) 25 - #define DMESGE(x, a...) printk(KERN_WARNING RTL8180_MODULE_NAME ": EE:" x "\n", ## a) 26 - 27 - #include <linux/module.h> 28 - #include <linux/kernel.h> 29 - #include <linux/ioport.h> 30 - #include <linux/sched.h> 31 - #include <linux/types.h> 32 - #include <linux/slab.h> 33 - #include <linux/netdevice.h> 34 - #include <linux/pci.h> 35 - #include <linux/etherdevice.h> 36 - #include <linux/delay.h> 37 - #include <linux/rtnetlink.h> /* for rtnl_lock() */ 38 - #include <linux/wireless.h> 39 - #include <linux/timer.h> 40 - #include <linux/proc_fs.h> /* Necessary because we use the proc fs. */ 41 - #include <linux/if_arp.h> 42 - #include "ieee80211/ieee80211.h" 43 - #include <asm/io.h> 44 - 45 - #define EPROM_93c46 0 46 - #define EPROM_93c56 1 47 - 48 - #define RTL_IOCTL_WPA_SUPPLICANT (SIOCIWFIRSTPRIV + 30) 49 - 50 - #define DEFAULT_FRAG_THRESHOLD 2342U 51 - #define MIN_FRAG_THRESHOLD 256U 52 - #define DEFAULT_RTS_THRESHOLD 2342U 53 - #define MIN_RTS_THRESHOLD 0U 54 - #define MAX_RTS_THRESHOLD 2342U 55 - #define DEFAULT_BEACONINTERVAL 0x64U 56 - 57 - #define DEFAULT_RETRY_RTS 7 58 - #define DEFAULT_RETRY_DATA 7 59 - 60 - #define BEACON_QUEUE 6 61 - 62 - #define aSifsTime 10 63 - 64 - #define sCrcLng 4 65 - #define sAckCtsLng 112 /* bits in ACK and CTS frames. */ 66 - /* +by amy 080312. */ 67 - #define RATE_ADAPTIVE_TIMER_PERIOD 300 68 - 69 - enum wireless_mode { 70 - WIRELESS_MODE_UNKNOWN = 0x00, 71 - WIRELESS_MODE_A = 0x01, 72 - WIRELESS_MODE_B = 0x02, 73 - WIRELESS_MODE_G = 0x04, 74 - WIRELESS_MODE_AUTO = 0x08, 75 - }; 76 - 77 - struct chnl_access_setting { 78 - u16 sifs_timer; 79 - u16 difs_timer; 80 - u16 slot_time_timer; 81 - u16 eifs_timer; 82 - u16 cwmin_index; 83 - u16 cwmax_index; 84 - }; 85 - 86 - enum nic_t { 87 - NIC_8185 = 1, 88 - NIC_8185B 89 - }; 90 - 91 - typedef u32 AC_CODING; 92 - #define AC0_BE 0 /* ACI: 0x00 */ /* Best Effort. */ 93 - #define AC1_BK 1 /* ACI: 0x01 */ /* Background. */ 94 - #define AC2_VI 2 /* ACI: 0x10 */ /* Video. */ 95 - #define AC3_VO 3 /* ACI: 0x11 */ /* Voice. */ 96 - #define AC_MAX 4 /* Max: define total number; Should not to be used as a real 97 - * enum. 98 - */ 99 - 100 - /* 101 - * ECWmin/ECWmax field. 102 - * Ref: WMM spec 2.2.2: WME Parameter Element, p.13. 103 - */ 104 - typedef union _ECW { 105 - u8 charData; 106 - struct { 107 - u8 ECWmin:4; 108 - u8 ECWmax:4; 109 - } f; /* Field */ 110 - } ECW, *PECW; 111 - 112 - /* 113 - * ACI/AIFSN Field. Ref: WMM spec 2.2.2: WME Parameter Element, p.12. 114 - */ 115 - typedef union _ACI_AIFSN { 116 - u8 charData; 117 - 118 - struct { 119 - u8 AIFSN:4; 120 - u8 ACM:1; 121 - u8 ACI:2; 122 - u8 Reserved:1; 123 - } f; /* Field */ 124 - } ACI_AIFSN, *PACI_AIFSN; 125 - 126 - /* 127 - * AC Parameters Record Format. 128 - * Ref: WMM spec 2.2.2: WME Parameter Element, p.12. 129 - */ 130 - typedef union _AC_PARAM { 131 - u32 longData; 132 - u8 charData[4]; 133 - 134 - struct { 135 - ACI_AIFSN AciAifsn; 136 - ECW Ecw; 137 - u16 TXOPLimit; 138 - } f; /* Field */ 139 - } AC_PARAM, *PAC_PARAM; 140 - 141 - struct buffer { 142 - struct buffer *next; 143 - u32 *buf; 144 - dma_addr_t dma; 145 - }; 146 - 147 - /* YJ,modified,080828. */ 148 - struct stats { 149 - unsigned long txrdu; 150 - unsigned long rxrdu; 151 - unsigned long rxnolast; 152 - unsigned long rxnodata; 153 - unsigned long rxnopointer; 154 - unsigned long txnperr; 155 - unsigned long txresumed; 156 - unsigned long rxerr; 157 - unsigned long rxoverflow; 158 - unsigned long rxint; 159 - unsigned long txbkpokint; 160 - unsigned long txbepoking; 161 - unsigned long txbkperr; 162 - unsigned long txbeperr; 163 - unsigned long txnpokint; 164 - unsigned long txhpokint; 165 - unsigned long txhperr; 166 - unsigned long ints; 167 - unsigned long shints; 168 - unsigned long txoverflow; 169 - unsigned long rxdmafail; 170 - unsigned long txbeacon; 171 - unsigned long txbeaconerr; 172 - unsigned long txlpokint; 173 - unsigned long txlperr; 174 - unsigned long txretry; /* retry number tony 20060601 */ 175 - unsigned long rxcrcerrmin; /* crc error (0-500) */ 176 - unsigned long rxcrcerrmid; /* crc error (500-1000) */ 177 - unsigned long rxcrcerrmax; /* crc error (>1000) */ 178 - unsigned long rxicverr; /* ICV error */ 179 - }; 180 - 181 - #define MAX_LD_SLOT_NUM 10 182 - #define KEEP_ALIVE_INTERVAL 20 /* in seconds. */ 183 - #define CHECK_FOR_HANG_PERIOD 2 /* be equal to watchdog check time. */ 184 - #define DEFAULT_KEEP_ALIVE_LEVEL 1 185 - #define DEFAULT_SLOT_NUM 2 186 - #define POWER_PROFILE_AC 0 187 - #define POWER_PROFILE_BATTERY 1 188 - 189 - struct link_detect_t { 190 - u32 rx_frame_num[MAX_LD_SLOT_NUM]; /* number of Rx Frame. 191 - * CheckForHang_period to determine 192 - * link status. 193 - */ 194 - u16 slot_num; /* number of CheckForHang period to determine link status, 195 - * default is 2. 196 - */ 197 - u16 slot_index; 198 - u32 num_tx_ok_in_period; /* number of packet transmitted during 199 - * CheckForHang. 200 - */ 201 - u32 num_rx_ok_in_period; /* number of packet received during 202 - * CheckForHang. 203 - */ 204 - u8 idle_count; /* (KEEP_ALIVE_INTERVAL / CHECK_FOR_HANG_PERIOD) */ 205 - u32 last_num_tx_unicast; 206 - u32 last_num_rx_unicast; 207 - 208 - bool b_busy_traffic; /* when it is set to 1, UI cann't scan at will. */ 209 - }; 210 - 211 - /* YJ,modified,080828,end */ 212 - 213 - /* by amy for led 214 - * ========================================================================== 215 - * LED customization. 216 - * ========================================================================== 217 - */ 218 - enum led_strategy_8185 { 219 - SW_LED_MODE0, 220 - SW_LED_MODE1, 221 - HW_LED, /* HW control 2 LEDs, LED0 and LED1 (there are 4 different 222 - * control modes). */ 223 - }; 224 - 225 - enum rt_rf_power_state { 226 - RF_ON, 227 - RF_SLEEP, 228 - RF_OFF 229 - }; 230 - 231 - enum _ReasonCode { 232 - unspec_reason = 0x1, 233 - auth_not_valid = 0x2, 234 - deauth_lv_ss = 0x3, 235 - inactivity = 0x4, 236 - ap_overload = 0x5, 237 - class2_err = 0x6, 238 - class3_err = 0x7, 239 - disas_lv_ss = 0x8, 240 - asoc_not_auth = 0x9, 241 - 242 - /* ----MIC_CHECK */ 243 - mic_failure = 0xe, 244 - /* ----END MIC_CHECK */ 245 - 246 - /* Reason code defined in 802.11i D10.0 p.28. */ 247 - invalid_IE = 0x0d, 248 - four_way_tmout = 0x0f, 249 - two_way_tmout = 0x10, 250 - IE_dismatch = 0x11, 251 - invalid_Gcipher = 0x12, 252 - invalid_Pcipher = 0x13, 253 - invalid_AKMP = 0x14, 254 - unsup_RSNIEver = 0x15, 255 - invalid_RSNIE = 0x16, 256 - auth_802_1x_fail = 0x17, 257 - ciper_reject = 0x18, 258 - 259 - /* Reason code defined in 7.3.1.7, 802.1e D13.0, p.42. Added by Annie, 260 - * 2005-11-15. 261 - */ 262 - QoS_unspec = 0x20, /* 32 */ 263 - QAP_bandwidth = 0x21, /* 33 */ 264 - poor_condition = 0x22, /* 34 */ 265 - no_facility = 0x23, /* 35 */ 266 - /* Where is 36??? */ 267 - req_declined = 0x25, /* 37 */ 268 - invalid_param = 0x26, /* 38 */ 269 - req_not_honored = 0x27, /* 39 */ 270 - TS_not_created = 0x2F, /* 47 */ 271 - DL_not_allowed = 0x30, /* 48 */ 272 - dest_not_exist = 0x31, /* 49 */ 273 - dest_not_QSTA = 0x32, /* 50 */ 274 - }; 275 - 276 - enum rt_ps_mode { 277 - ACTIVE, /* Active/Continuous access. */ 278 - MAX_PS, /* Max power save mode. */ 279 - FAST_PS /* Fast power save mode. */ 280 - }; 281 - 282 - /* by amy for power save. */ 283 - struct r8180_priv { 284 - struct pci_dev *pdev; 285 - 286 - short epromtype; 287 - int irq; 288 - struct ieee80211_device *ieee80211; 289 - 290 - short plcp_preamble_mode; /* 0:auto 1:short 2:long */ 291 - 292 - spinlock_t irq_th_lock; 293 - spinlock_t tx_lock; 294 - spinlock_t ps_lock; 295 - spinlock_t rf_ps_lock; 296 - 297 - u16 irq_mask; 298 - short irq_enabled; 299 - struct net_device *dev; 300 - short chan; 301 - short sens; 302 - short max_sens; 303 - u8 chtxpwr[15]; /* channels from 1 to 14, 0 not used. */ 304 - u8 chtxpwr_ofdm[15]; /* channels from 1 to 14, 0 not used. */ 305 - u8 channel_plan; /* it's the channel plan index. */ 306 - short up; 307 - short crcmon; /* if 1 allow bad crc frame reception in monitor mode. */ 308 - 309 - struct timer_list scan_timer; 310 - spinlock_t scan_lock; 311 - u8 active_probe; 312 - struct semaphore wx_sem; 313 - short hw_wep; 314 - 315 - short digphy; 316 - short antb; 317 - short diversity; 318 - u32 key0[4]; 319 - short (*rf_set_sens)(struct net_device *dev, short sens); 320 - void (*rf_set_chan)(struct net_device *dev, short ch); 321 - void (*rf_close)(struct net_device *dev); 322 - void (*rf_init)(struct net_device *dev); 323 - void (*rf_sleep)(struct net_device *dev); 324 - void (*rf_wakeup)(struct net_device *dev); 325 - /* short rate; */ 326 - short promisc; 327 - /* stats */ 328 - struct stats stats; 329 - struct link_detect_t link_detect; /* YJ,add,080828 */ 330 - struct iw_statistics wstats; 331 - 332 - /* RX stuff. */ 333 - u32 *rxring; 334 - u32 *rxringtail; 335 - dma_addr_t rxringdma; 336 - struct buffer *rxbuffer; 337 - struct buffer *rxbufferhead; 338 - int rxringcount; 339 - u16 rxbuffersize; 340 - 341 - struct sk_buff *rx_skb; 342 - 343 - short rx_skb_complete; 344 - 345 - u32 rx_prevlen; 346 - 347 - u32 *txmapring; 348 - u32 *txbkpring; 349 - u32 *txbepring; 350 - u32 *txvipring; 351 - u32 *txvopring; 352 - u32 *txhpring; 353 - dma_addr_t txmapringdma; 354 - dma_addr_t txbkpringdma; 355 - dma_addr_t txbepringdma; 356 - dma_addr_t txvipringdma; 357 - dma_addr_t txvopringdma; 358 - dma_addr_t txhpringdma; 359 - u32 *txmapringtail; 360 - u32 *txbkpringtail; 361 - u32 *txbepringtail; 362 - u32 *txvipringtail; 363 - u32 *txvopringtail; 364 - u32 *txhpringtail; 365 - u32 *txmapringhead; 366 - u32 *txbkpringhead; 367 - u32 *txbepringhead; 368 - u32 *txvipringhead; 369 - u32 *txvopringhead; 370 - u32 *txhpringhead; 371 - struct buffer *txmapbufs; 372 - struct buffer *txbkpbufs; 373 - struct buffer *txbepbufs; 374 - struct buffer *txvipbufs; 375 - struct buffer *txvopbufs; 376 - struct buffer *txhpbufs; 377 - struct buffer *txmapbufstail; 378 - struct buffer *txbkpbufstail; 379 - struct buffer *txbepbufstail; 380 - struct buffer *txvipbufstail; 381 - struct buffer *txvopbufstail; 382 - struct buffer *txhpbufstail; 383 - 384 - int txringcount; 385 - int txbuffsize; 386 - struct tasklet_struct irq_rx_tasklet; 387 - u8 dma_poll_mask; 388 - 389 - /* adhoc/master mode stuff. */ 390 - u32 *txbeaconringtail; 391 - dma_addr_t txbeaconringdma; 392 - u32 *txbeaconring; 393 - int txbeaconcount; 394 - struct buffer *txbeaconbufs; 395 - struct buffer *txbeaconbufstail; 396 - 397 - u8 retry_data; 398 - u8 retry_rts; 399 - u16 rts; 400 - 401 - /* by amy for led. */ 402 - enum led_strategy_8185 led_strategy; 403 - /* by amy for led. */ 404 - 405 - /* by amy for power save. */ 406 - struct timer_list watch_dog_timer; 407 - bool bInactivePs; 408 - bool bSwRfProcessing; 409 - enum rt_rf_power_state eInactivePowerState; 410 - enum rt_rf_power_state eRFPowerState; 411 - u32 RfOffReason; 412 - bool RFChangeInProgress; 413 - bool SetRFPowerStateInProgress; 414 - u8 RFProgType; 415 - bool bLeisurePs; 416 - enum rt_ps_mode dot11PowerSaveMode; 417 - u8 TxPollingTimes; 418 - 419 - bool bApBufOurFrame; /* TRUE if AP buffer our unicast data , we will 420 - * keep eAwake until receive data or timeout. 421 - */ 422 - u8 WaitBufDataBcnCount; 423 - u8 WaitBufDataTimeOut; 424 - 425 - /* by amy for power save. */ 426 - /* by amy for antenna. */ 427 - u8 EEPROMSwAntennaDiversity; 428 - bool EEPROMDefaultAntenna1; 429 - u8 RegSwAntennaDiversityMechanism; 430 - bool bSwAntennaDiverity; 431 - u8 RegDefaultAntenna; 432 - bool bDefaultAntenna1; 433 - u8 SignalStrength; 434 - long Stats_SignalStrength; 435 - long LastSignalStrengthInPercent; /* In percentage, used for smoothing, 436 - * e.g. Moving Average. 437 - */ 438 - u8 SignalQuality; /* in 0-100 index. */ 439 - long Stats_SignalQuality; 440 - long RecvSignalPower; /* in dBm. */ 441 - long Stats_RecvSignalPower; 442 - u8 LastRxPktAntenna; /* +by amy 080312 Antenna which received the lasted 443 - * packet. 0: Aux, 1:Main. Added by Roger, 444 - * 2008.01.25. 445 - */ 446 - u32 AdRxOkCnt; 447 - long AdRxSignalStrength; 448 - u8 CurrAntennaIndex; /* Index to current Antenna (both Tx and Rx). */ 449 - u8 AdTickCount; /* Times of SwAntennaDiversityTimer happened. */ 450 - u8 AdCheckPeriod; /* # of period SwAntennaDiversityTimer to check Rx 451 - * signal strength for SW Antenna Diversity. 452 - */ 453 - u8 AdMinCheckPeriod; /* Min value of AdCheckPeriod. */ 454 - u8 AdMaxCheckPeriod; /* Max value of AdCheckPeriod. */ 455 - long AdRxSsThreshold; /* Signal strength threshold to switch antenna. */ 456 - long AdMaxRxSsThreshold; /* Max value of AdRxSsThreshold. */ 457 - bool bAdSwitchedChecking; /* TRUE if we shall shall check Rx signal 458 - * strength for last time switching antenna. 459 - */ 460 - long AdRxSsBeforeSwitched; /* Rx signal strength before we switched 461 - * antenna. 462 - */ 463 - struct timer_list SwAntennaDiversityTimer; 464 - /* by amy for antenna {by amy 080312 */ 465 - 466 - /* Crystal calibration. Added by Roger, 2007.12.11. */ 467 - 468 - bool bXtalCalibration; /* Crystal calibration.*/ 469 - u8 XtalCal_Xin; /* Crystal calibration for Xin. 0~7.5pF */ 470 - u8 XtalCal_Xout; /* Crystal calibration for Xout. 0~7.5pF */ 471 - 472 - /* Tx power tracking with thermal meter indication. 473 - * Added by Roger, 2007.12.11. 474 - */ 475 - 476 - bool bTxPowerTrack; /* Tx Power tracking. */ 477 - u8 ThermalMeter; /* Thermal meter reference indication. */ 478 - 479 - /* Dynamic Initial Gain Adjustment Mechanism. Added by Bruce, 480 - * 2007-02-14. 481 - */ 482 - bool bDigMechanism; /* TRUE if DIG is enabled, FALSE ow. */ 483 - bool bRegHighPowerMechanism; /* For High Power Mechanism. 061010, 484 - * by rcnjko. 485 - */ 486 - u32 FalseAlarmRegValue; 487 - u8 RegDigOfdmFaUpTh; /* Upper threshold of OFDM false alarm, which is 488 - * used in DIG. 489 - */ 490 - u8 DIG_NumberFallbackVote; 491 - u8 DIG_NumberUpgradeVote; 492 - /* For HW antenna diversity, added by Roger, 2008.01.30. */ 493 - u32 AdMainAntennaRxOkCnt; /* Main antenna Rx OK count. */ 494 - u32 AdAuxAntennaRxOkCnt; /* Aux antenna Rx OK count. */ 495 - bool bHWAdSwitched; /* TRUE if we has switched default antenna by HW 496 - * evaluation. 497 - */ 498 - /* RF High Power upper/lower threshold. */ 499 - u8 RegHiPwrUpperTh; 500 - u8 RegHiPwrLowerTh; 501 - /* RF RSSI High Power upper/lower Threshold. */ 502 - u8 RegRSSIHiPwrUpperTh; 503 - u8 RegRSSIHiPwrLowerTh; 504 - /* Current CCK RSSI value to determine CCK high power, asked by SD3 DZ, 505 - * by Bruce, 2007-04-12. 506 - */ 507 - u8 CurCCKRSSI; 508 - bool bCurCCKPkt; 509 - /* High Power Mechanism. Added by amy, 080312. */ 510 - bool bToUpdateTxPwr; 511 - long UndecoratedSmoothedSS; 512 - long UndecoratedSmoothedRxPower; 513 - u8 RSSI; 514 - char RxPower; 515 - u8 InitialGain; 516 - /* For adjust Dig Threshold during Legacy/Leisure Power Save Mode. */ 517 - u32 DozePeriodInPast2Sec; 518 - /* Don't access BB/RF under disable PLL situation. */ 519 - u8 InitialGainBackUp; 520 - u8 RegBModeGainStage; 521 - /* by amy for rate adaptive */ 522 - struct timer_list rateadapter_timer; 523 - u32 RateAdaptivePeriod; 524 - bool bEnhanceTxPwr; 525 - bool bUpdateARFR; 526 - int ForcedDataRate; /* Force Data Rate. 0: Auto, 0x02: 1M ~ 0x6C: 54M.) 527 - */ 528 - u32 NumTxUnicast; /* YJ,add,080828,for keep alive. */ 529 - u8 keepAliveLevel; /*YJ,add,080828,for KeepAlive. */ 530 - unsigned long NumTxOkTotal; 531 - u16 LastRetryCnt; 532 - u16 LastRetryRate; 533 - unsigned long LastTxokCnt; 534 - unsigned long LastRxokCnt; 535 - u16 CurrRetryCnt; 536 - unsigned long LastTxOKBytes; 537 - unsigned long NumTxOkBytesTotal; 538 - u8 LastFailTxRate; 539 - long LastFailTxRateSS; 540 - u8 FailTxRateCount; 541 - u32 LastTxThroughput; 542 - /* for up rate. */ 543 - unsigned short bTryuping; 544 - u8 CurrTxRate; /* the rate before up. */ 545 - u16 CurrRetryRate; 546 - u16 TryupingCount; 547 - u8 TryDownCountLowData; 548 - u8 TryupingCountNoData; 549 - 550 - u8 CurrentOperaRate; 551 - struct work_struct reset_wq; 552 - struct work_struct watch_dog_wq; 553 - short ack_tx_to_ieee; 554 - 555 - u8 dma_poll_stop_mask; 556 - 557 - u16 ShortRetryLimit; 558 - u16 LongRetryLimit; 559 - u16 EarlyRxThreshold; 560 - u32 TransmitConfig; 561 - u32 ReceiveConfig; 562 - u32 IntrMask; 563 - 564 - struct chnl_access_setting ChannelAccessSetting; 565 - }; 566 - 567 - #define MANAGE_PRIORITY 0 568 - #define BK_PRIORITY 1 569 - #define BE_PRIORITY 2 570 - #define VI_PRIORITY 3 571 - #define VO_PRIORITY 4 572 - #define HI_PRIORITY 5 573 - #define BEACON_PRIORITY 6 574 - 575 - #define LOW_PRIORITY VI_PRIORITY 576 - #define NORM_PRIORITY VO_PRIORITY 577 - /* AC2Queue mapping. */ 578 - #define AC2Q(_ac) (((_ac) == WME_AC_VO) ? VO_PRIORITY : \ 579 - ((_ac) == WME_AC_VI) ? VI_PRIORITY : \ 580 - ((_ac) == WME_AC_BK) ? BK_PRIORITY : \ 581 - BE_PRIORITY) 582 - 583 - short rtl8180_tx(struct net_device *dev, u8 *skbuf, int len, int priority, 584 - bool morefrag, short fragdesc, int rate); 585 - 586 - u8 read_nic_byte(struct net_device *dev, int x); 587 - u32 read_nic_dword(struct net_device *dev, int x); 588 - u16 read_nic_word(struct net_device *dev, int x); 589 - void write_nic_byte(struct net_device *dev, int x, u8 y); 590 - void write_nic_word(struct net_device *dev, int x, u16 y); 591 - void write_nic_dword(struct net_device *dev, int x, u32 y); 592 - void force_pci_posting(struct net_device *dev); 593 - 594 - void rtl8180_rtx_disable(struct net_device *); 595 - void rtl8180_set_anaparam(struct net_device *dev, u32 a); 596 - void rtl8185_set_anaparam2(struct net_device *dev, u32 a); 597 - void rtl8180_set_hw_wep(struct net_device *dev); 598 - void rtl8180_no_hw_wep(struct net_device *dev); 599 - void rtl8180_update_msr(struct net_device *dev); 600 - void rtl8180_beacon_tx_disable(struct net_device *dev); 601 - void rtl8180_beacon_rx_disable(struct net_device *dev); 602 - int rtl8180_down(struct net_device *dev); 603 - int rtl8180_up(struct net_device *dev); 604 - void rtl8180_commit(struct net_device *dev); 605 - void rtl8180_set_chan(struct net_device *dev, short ch); 606 - void write_phy(struct net_device *dev, u8 adr, u8 data); 607 - void write_phy_cck(struct net_device *dev, u8 adr, u32 data); 608 - void write_phy_ofdm(struct net_device *dev, u8 adr, u32 data); 609 - void rtl8185_tx_antenna(struct net_device *dev, u8 ant); 610 - void rtl8185_rf_pins_enable(struct net_device *dev); 611 - void IPSEnter(struct net_device *dev); 612 - void IPSLeave(struct net_device *dev); 613 - int get_curr_tx_free_desc(struct net_device *dev, int priority); 614 - void UpdateInitialGain(struct net_device *dev); 615 - bool SetAntennaConfig87SE(struct net_device *dev, u8 DefaultAnt, 616 - bool bAntDiversity); 617 - 618 - void rtl8185b_adapter_start(struct net_device *dev); 619 - void rtl8185b_rx_enable(struct net_device *dev); 620 - void rtl8185b_tx_enable(struct net_device *dev); 621 - void rtl8180_reset(struct net_device *dev); 622 - void rtl8185b_irq_enable(struct net_device *dev); 623 - void fix_rx_fifo(struct net_device *dev); 624 - void fix_tx_fifo(struct net_device *dev); 625 - void rtl8225z2_SetTXPowerLevel(struct net_device *dev, short ch); 626 - void rtl8180_rate_adapter(struct work_struct *work); 627 - bool MgntActSet_RF_State(struct net_device *dev, enum rt_rf_power_state StateToSet, 628 - u32 ChangeSource); 629 - 630 - #endif 631 - 632 - /* fun with the built-in ieee80211 stack... */ 633 - extern int ieee80211_crypto_init(void); 634 - extern void ieee80211_crypto_deinit(void); 635 - extern int ieee80211_crypto_tkip_init(void); 636 - extern void ieee80211_crypto_tkip_exit(void); 637 - extern int ieee80211_crypto_ccmp_init(void); 638 - extern void ieee80211_crypto_ccmp_exit(void); 639 - extern int ieee80211_crypto_wep_init(void); 640 - extern void ieee80211_crypto_wep_exit(void);
-54
drivers/staging/rtl8187se/r8180_93cx6.h
··· 1 - /* 2 - This is part of rtl8180 OpenSource driver 3 - Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com> 4 - Released under the terms of GPL (General Public Licence) 5 - 6 - Parts of this driver are based on the GPL part of the official realtek driver 7 - Parts of this driver are based on the rtl8180 driver skeleton from Patric Schenke & Andres Salomon 8 - Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver 9 - 10 - We want to tanks the Authors of such projects and the Ndiswrapper project Authors. 11 - */ 12 - 13 - /*This files contains card eeprom (93c46 or 93c56) programming routines*/ 14 - /*memory is addressed by WORDS*/ 15 - 16 - #include "r8180.h" 17 - #include "r8180_hw.h" 18 - 19 - #define EPROM_DELAY 10 20 - 21 - #define EPROM_ANAPARAM_ADDRLWORD 0xd 22 - #define EPROM_ANAPARAM_ADDRHWORD 0xe 23 - 24 - #define RFCHIPID 0x6 25 - #define RFCHIPID_INTERSIL 1 26 - #define RFCHIPID_RFMD 2 27 - #define RFCHIPID_PHILIPS 3 28 - #define RFCHIPID_MAXIM 4 29 - #define RFCHIPID_GCT 5 30 - #define RFCHIPID_RTL8225 9 31 - #define RF_ZEBRA2 11 32 - #define EPROM_TXPW_BASE 0x05 33 - #define RF_ZEBRA4 12 34 - #define RFCHIPID_RTL8255 0xa 35 - #define RF_PARAM 0x19 36 - #define RF_PARAM_DIGPHY_SHIFT 0 37 - #define RF_PARAM_ANTBDEFAULT_SHIFT 1 38 - #define RF_PARAM_CARRIERSENSE_SHIFT 2 39 - #define RF_PARAM_CARRIERSENSE_MASK (3<<2) 40 - #define ENERGY_TRESHOLD 0x17 41 - #define EPROM_VERSION 0x1E 42 - #define MAC_ADR 0x7 43 - 44 - #define CIS 0x18 45 - 46 - #define EPROM_TXPW_OFDM_CH1_2 0x20 47 - 48 - #define EPROM_TXPW_CH1_2 0x30 49 - 50 - #define RTL818X_EEPROM_CMD_READ (1 << 0) 51 - #define RTL818X_EEPROM_CMD_WRITE (1 << 1) 52 - #define RTL818X_EEPROM_CMD_CK (1 << 2) 53 - #define RTL818X_EEPROM_CMD_CS (1 << 3) 54 -
-3775
drivers/staging/rtl8187se/r8180_core.c
··· 1 - /* 2 - * This is part of rtl818x pci OpenSource driver - v 0.1 3 - * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com> 4 - * Released under the terms of GPL (General Public License) 5 - * 6 - * Parts of this driver are based on the GPL part of the official 7 - * Realtek driver. 8 - * 9 - * Parts of this driver are based on the rtl8180 driver skeleton 10 - * from Patric Schenke & Andres Salomon. 11 - * 12 - * Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver. 13 - * 14 - * Parts of BB/RF code are derived from David Young rtl8180 netbsd driver. 15 - * 16 - * RSSI calc function from 'The Deuce' 17 - * 18 - * Some ideas borrowed from the 8139too.c driver included in linux kernel. 19 - * 20 - * We (I?) want to thanks the Authors of those projecs and also the 21 - * Ndiswrapper's project Authors. 22 - * 23 - * A big big thanks goes also to Realtek corp. for their help in my attempt to 24 - * add RTL8185 and RTL8225 support, and to David Young also. 25 - * 26 - * Power management interface routines. 27 - * Written by Mariusz Matuszek. 28 - */ 29 - 30 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 31 - 32 - #undef RX_DONT_PASS_UL 33 - #undef DUMMY_RX 34 - 35 - #include <linux/slab.h> 36 - #include <linux/syscalls.h> 37 - #include <linux/eeprom_93cx6.h> 38 - #include <linux/interrupt.h> 39 - #include <linux/proc_fs.h> 40 - #include <linux/seq_file.h> 41 - 42 - #include "r8180_hw.h" 43 - #include "r8180.h" 44 - #include "r8180_rtl8225.h" /* RTL8225 Radio frontend */ 45 - #include "r8180_93cx6.h" /* Card EEPROM */ 46 - #include "r8180_wx.h" 47 - #include "r8180_dm.h" 48 - 49 - #include "ieee80211/dot11d.h" 50 - 51 - static struct pci_device_id rtl8180_pci_id_tbl[] = { 52 - { 53 - .vendor = PCI_VENDOR_ID_REALTEK, 54 - .device = 0x8199, 55 - .subvendor = PCI_ANY_ID, 56 - .subdevice = PCI_ANY_ID, 57 - .driver_data = 0, 58 - }, 59 - { 60 - .vendor = 0, 61 - .device = 0, 62 - .subvendor = 0, 63 - .subdevice = 0, 64 - .driver_data = 0, 65 - } 66 - }; 67 - 68 - static char ifname[IFNAMSIZ] = "wlan%d"; 69 - static int hwwep; 70 - 71 - MODULE_LICENSE("GPL"); 72 - MODULE_DEVICE_TABLE(pci, rtl8180_pci_id_tbl); 73 - MODULE_AUTHOR("Andrea Merello <andrea.merello@gmail.com>"); 74 - MODULE_DESCRIPTION("Linux driver for Realtek RTL8187SE WiFi cards"); 75 - 76 - module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR); 77 - module_param(hwwep, int, S_IRUGO|S_IWUSR); 78 - 79 - MODULE_PARM_DESC(hwwep, " Try to use hardware WEP support. Still broken and not available on all cards"); 80 - 81 - static int rtl8180_pci_probe(struct pci_dev *pdev, 82 - const struct pci_device_id *id); 83 - 84 - static void rtl8180_pci_remove(struct pci_dev *pdev); 85 - 86 - static void rtl8180_shutdown(struct pci_dev *pdev) 87 - { 88 - struct net_device *dev = pci_get_drvdata(pdev); 89 - if (dev->netdev_ops->ndo_stop) 90 - dev->netdev_ops->ndo_stop(dev); 91 - pci_disable_device(pdev); 92 - } 93 - 94 - static int rtl8180_suspend(struct pci_dev *pdev, pm_message_t state) 95 - { 96 - struct net_device *dev = pci_get_drvdata(pdev); 97 - 98 - if (!netif_running(dev)) 99 - goto out_pci_suspend; 100 - 101 - if (dev->netdev_ops->ndo_stop) 102 - dev->netdev_ops->ndo_stop(dev); 103 - 104 - netif_device_detach(dev); 105 - 106 - out_pci_suspend: 107 - pci_save_state(pdev); 108 - pci_disable_device(pdev); 109 - pci_set_power_state(pdev, pci_choose_state(pdev, state)); 110 - return 0; 111 - } 112 - 113 - static int rtl8180_resume(struct pci_dev *pdev) 114 - { 115 - struct net_device *dev = pci_get_drvdata(pdev); 116 - int err; 117 - u32 val; 118 - 119 - pci_set_power_state(pdev, PCI_D0); 120 - 121 - err = pci_enable_device(pdev); 122 - if (err) { 123 - dev_err(&pdev->dev, "pci_enable_device failed on resume\n"); 124 - 125 - return err; 126 - } 127 - 128 - pci_restore_state(pdev); 129 - 130 - /* 131 - * Suspend/Resume resets the PCI configuration space, so we have to 132 - * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries 133 - * from interfering with C3 CPU state. pci_restore_state won't help 134 - * here since it only restores the first 64 bytes pci config header. 135 - */ 136 - pci_read_config_dword(pdev, 0x40, &val); 137 - if ((val & 0x0000ff00) != 0) 138 - pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); 139 - 140 - if (!netif_running(dev)) 141 - goto out; 142 - 143 - if (dev->netdev_ops->ndo_open) 144 - dev->netdev_ops->ndo_open(dev); 145 - 146 - netif_device_attach(dev); 147 - out: 148 - return 0; 149 - } 150 - 151 - static struct pci_driver rtl8180_pci_driver = { 152 - .name = RTL8180_MODULE_NAME, 153 - .id_table = rtl8180_pci_id_tbl, 154 - .probe = rtl8180_pci_probe, 155 - .remove = rtl8180_pci_remove, 156 - .suspend = rtl8180_suspend, 157 - .resume = rtl8180_resume, 158 - .shutdown = rtl8180_shutdown, 159 - }; 160 - 161 - u8 read_nic_byte(struct net_device *dev, int x) 162 - { 163 - return 0xff&readb((u8 __iomem *)dev->mem_start + x); 164 - } 165 - 166 - u32 read_nic_dword(struct net_device *dev, int x) 167 - { 168 - return readl((u8 __iomem *)dev->mem_start + x); 169 - } 170 - 171 - u16 read_nic_word(struct net_device *dev, int x) 172 - { 173 - return readw((u8 __iomem *)dev->mem_start + x); 174 - } 175 - 176 - void write_nic_byte(struct net_device *dev, int x, u8 y) 177 - { 178 - writeb(y, (u8 __iomem *)dev->mem_start + x); 179 - udelay(20); 180 - } 181 - 182 - void write_nic_dword(struct net_device *dev, int x, u32 y) 183 - { 184 - writel(y, (u8 __iomem *)dev->mem_start + x); 185 - udelay(20); 186 - } 187 - 188 - void write_nic_word(struct net_device *dev, int x, u16 y) 189 - { 190 - writew(y, (u8 __iomem *)dev->mem_start + x); 191 - udelay(20); 192 - } 193 - 194 - inline void force_pci_posting(struct net_device *dev) 195 - { 196 - read_nic_byte(dev, EPROM_CMD); 197 - mb(); 198 - } 199 - 200 - static irqreturn_t rtl8180_interrupt(int irq, void *netdev); 201 - void set_nic_rxring(struct net_device *dev); 202 - void set_nic_txring(struct net_device *dev); 203 - static struct net_device_stats *rtl8180_stats(struct net_device *dev); 204 - void rtl8180_commit(struct net_device *dev); 205 - void rtl8180_start_tx_beacon(struct net_device *dev); 206 - 207 - static struct proc_dir_entry *rtl8180_proc; 208 - 209 - static int proc_get_registers(struct seq_file *m, void *v) 210 - { 211 - struct net_device *dev = m->private; 212 - int i, n, max = 0xff; 213 - 214 - /* This dump the current register page */ 215 - for (n = 0; n <= max;) { 216 - seq_printf(m, "\nD: %2x > ", n); 217 - 218 - for (i = 0; i < 16 && n <= max; i++, n++) 219 - seq_printf(m, "%2x ", read_nic_byte(dev, n)); 220 - } 221 - seq_putc(m, '\n'); 222 - return 0; 223 - } 224 - 225 - int get_curr_tx_free_desc(struct net_device *dev, int priority); 226 - 227 - static int proc_get_stats_hw(struct seq_file *m, void *v) 228 - { 229 - return 0; 230 - } 231 - 232 - static int proc_get_stats_rx(struct seq_file *m, void *v) 233 - { 234 - struct net_device *dev = m->private; 235 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 236 - 237 - seq_printf(m, 238 - "RX OK: %lu\n" 239 - "RX Retry: %lu\n" 240 - "RX CRC Error(0-500): %lu\n" 241 - "RX CRC Error(500-1000): %lu\n" 242 - "RX CRC Error(>1000): %lu\n" 243 - "RX ICV Error: %lu\n", 244 - priv->stats.rxint, 245 - priv->stats.rxerr, 246 - priv->stats.rxcrcerrmin, 247 - priv->stats.rxcrcerrmid, 248 - priv->stats.rxcrcerrmax, 249 - priv->stats.rxicverr 250 - ); 251 - 252 - return 0; 253 - } 254 - 255 - static int proc_get_stats_tx(struct seq_file *m, void *v) 256 - { 257 - struct net_device *dev = m->private; 258 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 259 - unsigned long totalOK; 260 - 261 - totalOK = priv->stats.txnpokint + priv->stats.txhpokint + 262 - priv->stats.txlpokint; 263 - 264 - seq_printf(m, 265 - "TX OK: %lu\n" 266 - "TX Error: %lu\n" 267 - "TX Retry: %lu\n" 268 - "TX beacon OK: %lu\n" 269 - "TX beacon error: %lu\n", 270 - totalOK, 271 - priv->stats.txnperr+priv->stats.txhperr+priv->stats.txlperr, 272 - priv->stats.txretry, 273 - priv->stats.txbeacon, 274 - priv->stats.txbeaconerr 275 - ); 276 - 277 - return 0; 278 - } 279 - 280 - static void rtl8180_proc_module_init(void) 281 - { 282 - DMESG("Initializing proc filesystem"); 283 - rtl8180_proc = proc_mkdir(RTL8180_MODULE_NAME, init_net.proc_net); 284 - } 285 - 286 - static void rtl8180_proc_module_remove(void) 287 - { 288 - remove_proc_entry(RTL8180_MODULE_NAME, init_net.proc_net); 289 - } 290 - 291 - static void rtl8180_proc_remove_one(struct net_device *dev) 292 - { 293 - remove_proc_subtree(dev->name, rtl8180_proc); 294 - } 295 - 296 - /* 297 - * seq_file wrappers for procfile show routines. 298 - */ 299 - static int rtl8180_proc_open(struct inode *inode, struct file *file) 300 - { 301 - struct net_device *dev = proc_get_parent_data(inode); 302 - int (*show)(struct seq_file *, void *) = PDE_DATA(inode); 303 - 304 - return single_open(file, show, dev); 305 - } 306 - 307 - static const struct file_operations rtl8180_proc_fops = { 308 - .open = rtl8180_proc_open, 309 - .read = seq_read, 310 - .llseek = seq_lseek, 311 - .release = single_release, 312 - }; 313 - 314 - /* 315 - * Table of proc files we need to create. 316 - */ 317 - struct rtl8180_proc_file { 318 - char name[12]; 319 - int (*show)(struct seq_file *, void *); 320 - }; 321 - 322 - static const struct rtl8180_proc_file rtl8180_proc_files[] = { 323 - { "stats-hw", &proc_get_stats_hw }, 324 - { "stats-rx", &proc_get_stats_rx }, 325 - { "stats-tx", &proc_get_stats_tx }, 326 - { "registers", &proc_get_registers }, 327 - { "" } 328 - }; 329 - 330 - static void rtl8180_proc_init_one(struct net_device *dev) 331 - { 332 - const struct rtl8180_proc_file *f; 333 - struct proc_dir_entry *dir; 334 - 335 - dir = proc_mkdir_data(dev->name, 0, rtl8180_proc, dev); 336 - if (!dir) { 337 - DMESGE("Unable to initialize /proc/net/r8180/%s\n", dev->name); 338 - return; 339 - } 340 - 341 - for (f = rtl8180_proc_files; f->name[0]; f++) { 342 - if (!proc_create_data(f->name, S_IFREG | S_IRUGO, dir, 343 - &rtl8180_proc_fops, f->show)) { 344 - DMESGE("Unable to initialize /proc/net/r8180/%s/%s\n", 345 - dev->name, f->name); 346 - return; 347 - } 348 - } 349 - } 350 - 351 - /* 352 - * FIXME: check if we can use some standard already-existent 353 - * data type+functions in kernel. 354 - */ 355 - 356 - static short buffer_add(struct buffer **buffer, u32 *buf, dma_addr_t dma, 357 - struct buffer **bufferhead) 358 - { 359 - struct buffer *tmp; 360 - 361 - if (!*buffer) { 362 - 363 - *buffer = kmalloc(sizeof(struct buffer), GFP_KERNEL); 364 - 365 - if (*buffer == NULL) { 366 - DMESGE("Failed to kmalloc head of TX/RX struct"); 367 - return -1; 368 - } 369 - (*buffer)->next = *buffer; 370 - (*buffer)->buf = buf; 371 - (*buffer)->dma = dma; 372 - if (bufferhead != NULL) 373 - (*bufferhead) = (*buffer); 374 - return 0; 375 - } 376 - tmp = *buffer; 377 - 378 - while (tmp->next != (*buffer)) 379 - tmp = tmp->next; 380 - tmp->next = kmalloc(sizeof(struct buffer), GFP_KERNEL); 381 - if (tmp->next == NULL) { 382 - DMESGE("Failed to kmalloc TX/RX struct"); 383 - return -1; 384 - } 385 - tmp->next->buf = buf; 386 - tmp->next->dma = dma; 387 - tmp->next->next = *buffer; 388 - 389 - return 0; 390 - } 391 - 392 - static void buffer_free(struct net_device *dev, struct buffer **buffer, int len, 393 - short consistent) 394 - { 395 - 396 - struct buffer *tmp, *next; 397 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 398 - struct pci_dev *pdev = priv->pdev; 399 - 400 - if (!*buffer) 401 - return; 402 - 403 - tmp = *buffer; 404 - 405 - do { 406 - next = tmp->next; 407 - if (consistent) { 408 - pci_free_consistent(pdev, len, 409 - tmp->buf, tmp->dma); 410 - } else { 411 - pci_unmap_single(pdev, tmp->dma, 412 - len, PCI_DMA_FROMDEVICE); 413 - kfree(tmp->buf); 414 - } 415 - kfree(tmp); 416 - tmp = next; 417 - } while (next != *buffer); 418 - 419 - *buffer = NULL; 420 - } 421 - 422 - int get_curr_tx_free_desc(struct net_device *dev, int priority) 423 - { 424 - struct r8180_priv *priv = ieee80211_priv(dev); 425 - u32 *tail; 426 - u32 *head; 427 - int ret; 428 - 429 - switch (priority) { 430 - case MANAGE_PRIORITY: 431 - head = priv->txmapringhead; 432 - tail = priv->txmapringtail; 433 - break; 434 - case BK_PRIORITY: 435 - head = priv->txbkpringhead; 436 - tail = priv->txbkpringtail; 437 - break; 438 - case BE_PRIORITY: 439 - head = priv->txbepringhead; 440 - tail = priv->txbepringtail; 441 - break; 442 - case VI_PRIORITY: 443 - head = priv->txvipringhead; 444 - tail = priv->txvipringtail; 445 - break; 446 - case VO_PRIORITY: 447 - head = priv->txvopringhead; 448 - tail = priv->txvopringtail; 449 - break; 450 - case HI_PRIORITY: 451 - head = priv->txhpringhead; 452 - tail = priv->txhpringtail; 453 - break; 454 - default: 455 - return -1; 456 - } 457 - 458 - if (head <= tail) 459 - ret = priv->txringcount - (tail - head)/8; 460 - else 461 - ret = (head - tail)/8; 462 - 463 - if (ret > priv->txringcount) 464 - DMESG("BUG"); 465 - 466 - return ret; 467 - } 468 - 469 - static short check_nic_enought_desc(struct net_device *dev, int priority) 470 - { 471 - struct r8180_priv *priv = ieee80211_priv(dev); 472 - struct ieee80211_device *ieee = netdev_priv(dev); 473 - int requiredbyte; 474 - int required; 475 - 476 - requiredbyte = priv->ieee80211->fts + 477 - sizeof(struct ieee80211_header_data); 478 - 479 - if (ieee->current_network.QoS_Enable) 480 - requiredbyte += 2; 481 - 482 - required = requiredbyte / (priv->txbuffsize-4); 483 - 484 - if (requiredbyte % priv->txbuffsize) 485 - required++; 486 - 487 - /* for now we keep two free descriptor as a safety boundary 488 - * between the tail and the head 489 - */ 490 - 491 - return required + 2 < get_curr_tx_free_desc(dev, priority); 492 - } 493 - 494 - void fix_tx_fifo(struct net_device *dev) 495 - { 496 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 497 - u32 *tmp; 498 - int i; 499 - 500 - for (tmp = priv->txmapring, i = 0; 501 - i < priv->txringcount; 502 - tmp += 8, i++) { 503 - *tmp = *tmp & ~(1<<31); 504 - } 505 - 506 - for (tmp = priv->txbkpring, i = 0; 507 - i < priv->txringcount; 508 - tmp += 8, i++) { 509 - *tmp = *tmp & ~(1<<31); 510 - } 511 - 512 - for (tmp = priv->txbepring, i = 0; 513 - i < priv->txringcount; 514 - tmp += 8, i++) { 515 - *tmp = *tmp & ~(1<<31); 516 - } 517 - for (tmp = priv->txvipring, i = 0; 518 - i < priv->txringcount; 519 - tmp += 8, i++) { 520 - *tmp = *tmp & ~(1<<31); 521 - } 522 - 523 - for (tmp = priv->txvopring, i = 0; 524 - i < priv->txringcount; 525 - tmp += 8, i++) { 526 - *tmp = *tmp & ~(1<<31); 527 - } 528 - 529 - for (tmp = priv->txhpring, i = 0; 530 - i < priv->txringcount; 531 - tmp += 8, i++) { 532 - *tmp = *tmp & ~(1<<31); 533 - } 534 - 535 - for (tmp = priv->txbeaconring, i = 0; 536 - i < priv->txbeaconcount; 537 - tmp += 8, i++) { 538 - *tmp = *tmp & ~(1<<31); 539 - } 540 - 541 - priv->txmapringtail = priv->txmapring; 542 - priv->txmapringhead = priv->txmapring; 543 - priv->txmapbufstail = priv->txmapbufs; 544 - 545 - priv->txbkpringtail = priv->txbkpring; 546 - priv->txbkpringhead = priv->txbkpring; 547 - priv->txbkpbufstail = priv->txbkpbufs; 548 - 549 - priv->txbepringtail = priv->txbepring; 550 - priv->txbepringhead = priv->txbepring; 551 - priv->txbepbufstail = priv->txbepbufs; 552 - 553 - priv->txvipringtail = priv->txvipring; 554 - priv->txvipringhead = priv->txvipring; 555 - priv->txvipbufstail = priv->txvipbufs; 556 - 557 - priv->txvopringtail = priv->txvopring; 558 - priv->txvopringhead = priv->txvopring; 559 - priv->txvopbufstail = priv->txvopbufs; 560 - 561 - priv->txhpringtail = priv->txhpring; 562 - priv->txhpringhead = priv->txhpring; 563 - priv->txhpbufstail = priv->txhpbufs; 564 - 565 - priv->txbeaconringtail = priv->txbeaconring; 566 - priv->txbeaconbufstail = priv->txbeaconbufs; 567 - set_nic_txring(dev); 568 - 569 - ieee80211_reset_queue(priv->ieee80211); 570 - priv->ack_tx_to_ieee = 0; 571 - } 572 - 573 - void fix_rx_fifo(struct net_device *dev) 574 - { 575 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 576 - u32 *tmp; 577 - struct buffer *rxbuf; 578 - u8 rx_desc_size; 579 - 580 - rx_desc_size = 8; /* 4*8 = 32 bytes */ 581 - 582 - for (tmp = priv->rxring, rxbuf = priv->rxbufferhead; 583 - (tmp < (priv->rxring)+(priv->rxringcount)*rx_desc_size); 584 - tmp += rx_desc_size, rxbuf = rxbuf->next) { 585 - *(tmp+2) = rxbuf->dma; 586 - *tmp = *tmp & ~0xfff; 587 - *tmp = *tmp | priv->rxbuffersize; 588 - *tmp |= (1<<31); 589 - } 590 - 591 - priv->rxringtail = priv->rxring; 592 - priv->rxbuffer = priv->rxbufferhead; 593 - priv->rx_skb_complete = 1; 594 - set_nic_rxring(dev); 595 - } 596 - 597 - static void rtl8180_irq_disable(struct net_device *dev) 598 - { 599 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 600 - 601 - write_nic_dword(dev, IMR, 0); 602 - force_pci_posting(dev); 603 - priv->irq_enabled = 0; 604 - } 605 - 606 - void rtl8180_set_mode(struct net_device *dev, int mode) 607 - { 608 - u8 ecmd; 609 - 610 - ecmd = read_nic_byte(dev, EPROM_CMD); 611 - ecmd = ecmd & ~EPROM_CMD_OPERATING_MODE_MASK; 612 - ecmd = ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT); 613 - ecmd = ecmd & ~(1<<EPROM_CS_SHIFT); 614 - ecmd = ecmd & ~(1<<EPROM_CK_SHIFT); 615 - write_nic_byte(dev, EPROM_CMD, ecmd); 616 - } 617 - 618 - void rtl8180_beacon_tx_enable(struct net_device *dev); 619 - 620 - void rtl8180_update_msr(struct net_device *dev) 621 - { 622 - struct r8180_priv *priv = ieee80211_priv(dev); 623 - u8 msr; 624 - u32 rxconf; 625 - 626 - msr = read_nic_byte(dev, MSR); 627 - msr &= ~MSR_LINK_MASK; 628 - 629 - rxconf = read_nic_dword(dev, RX_CONF); 630 - 631 - if (priv->ieee80211->state == IEEE80211_LINKED) { 632 - if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) 633 - msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT); 634 - else if (priv->ieee80211->iw_mode == IW_MODE_MASTER) 635 - msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT); 636 - else if (priv->ieee80211->iw_mode == IW_MODE_INFRA) 637 - msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT); 638 - else 639 - msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT); 640 - rxconf |= (1<<RX_CHECK_BSSID_SHIFT); 641 - 642 - } else { 643 - msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT); 644 - rxconf &= ~(1<<RX_CHECK_BSSID_SHIFT); 645 - } 646 - 647 - write_nic_byte(dev, MSR, msr); 648 - write_nic_dword(dev, RX_CONF, rxconf); 649 - } 650 - 651 - void rtl8180_set_chan(struct net_device *dev, short ch) 652 - { 653 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 654 - 655 - if ((ch > 14) || (ch < 1)) { 656 - netdev_err(dev, "In %s: Invalid channel %d\n", __func__, ch); 657 - return; 658 - } 659 - 660 - priv->chan = ch; 661 - priv->rf_set_chan(dev, priv->chan); 662 - } 663 - 664 - void set_nic_txring(struct net_device *dev) 665 - { 666 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 667 - 668 - write_nic_dword(dev, TX_MANAGEPRIORITY_RING_ADDR, priv->txmapringdma); 669 - write_nic_dword(dev, TX_BKPRIORITY_RING_ADDR, priv->txbkpringdma); 670 - write_nic_dword(dev, TX_BEPRIORITY_RING_ADDR, priv->txbepringdma); 671 - write_nic_dword(dev, TX_VIPRIORITY_RING_ADDR, priv->txvipringdma); 672 - write_nic_dword(dev, TX_VOPRIORITY_RING_ADDR, priv->txvopringdma); 673 - write_nic_dword(dev, TX_HIGHPRIORITY_RING_ADDR, priv->txhpringdma); 674 - write_nic_dword(dev, TX_BEACON_RING_ADDR, priv->txbeaconringdma); 675 - } 676 - 677 - void rtl8180_beacon_tx_enable(struct net_device *dev) 678 - { 679 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 680 - 681 - rtl8180_set_mode(dev, EPROM_CMD_CONFIG); 682 - priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_BQ); 683 - write_nic_byte(dev, TPPollStop, priv->dma_poll_mask); 684 - rtl8180_set_mode(dev, EPROM_CMD_NORMAL); 685 - } 686 - 687 - void rtl8180_beacon_tx_disable(struct net_device *dev) 688 - { 689 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 690 - 691 - rtl8180_set_mode(dev, EPROM_CMD_CONFIG); 692 - priv->dma_poll_stop_mask |= TPPOLLSTOP_BQ; 693 - write_nic_byte(dev, TPPollStop, priv->dma_poll_stop_mask); 694 - rtl8180_set_mode(dev, EPROM_CMD_NORMAL); 695 - 696 - } 697 - 698 - void rtl8180_rtx_disable(struct net_device *dev) 699 - { 700 - u8 cmd; 701 - struct r8180_priv *priv = ieee80211_priv(dev); 702 - 703 - cmd = read_nic_byte(dev, CMD); 704 - write_nic_byte(dev, CMD, cmd & 705 - ~((1<<CMD_RX_ENABLE_SHIFT)|(1<<CMD_TX_ENABLE_SHIFT))); 706 - force_pci_posting(dev); 707 - mdelay(10); 708 - 709 - if (!priv->rx_skb_complete) 710 - dev_kfree_skb_any(priv->rx_skb); 711 - } 712 - 713 - static short alloc_tx_desc_ring(struct net_device *dev, int bufsize, int count, 714 - int addr) 715 - { 716 - int i; 717 - u32 *desc; 718 - u32 *tmp; 719 - dma_addr_t dma_desc, dma_tmp; 720 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 721 - struct pci_dev *pdev = priv->pdev; 722 - void *buf; 723 - 724 - if ((bufsize & 0xfff) != bufsize) { 725 - DMESGE("TX buffer allocation too large"); 726 - return 0; 727 - } 728 - desc = (u32 *)pci_alloc_consistent(pdev, 729 - sizeof(u32)*8*count+256, &dma_desc); 730 - if (desc == NULL) 731 - return -1; 732 - 733 - if (dma_desc & 0xff) 734 - /* 735 - * descriptor's buffer must be 256 byte aligned 736 - * we shouldn't be here, since we set DMA mask ! 737 - */ 738 - WARN(1, "DMA buffer is not aligned\n"); 739 - 740 - tmp = desc; 741 - 742 - for (i = 0; i < count; i++) { 743 - buf = (void *)pci_alloc_consistent(pdev, bufsize, &dma_tmp); 744 - if (buf == NULL) 745 - return -ENOMEM; 746 - 747 - switch (addr) { 748 - case TX_MANAGEPRIORITY_RING_ADDR: 749 - if (-1 == buffer_add(&priv->txmapbufs, 750 - buf, dma_tmp, NULL)) { 751 - DMESGE("Unable to allocate mem for buffer NP"); 752 - return -ENOMEM; 753 - } 754 - break; 755 - case TX_BKPRIORITY_RING_ADDR: 756 - if (-1 == buffer_add(&priv->txbkpbufs, 757 - buf, dma_tmp, NULL)) { 758 - DMESGE("Unable to allocate mem for buffer LP"); 759 - return -ENOMEM; 760 - } 761 - break; 762 - case TX_BEPRIORITY_RING_ADDR: 763 - if (-1 == buffer_add(&priv->txbepbufs, 764 - buf, dma_tmp, NULL)) { 765 - DMESGE("Unable to allocate mem for buffer NP"); 766 - return -ENOMEM; 767 - } 768 - break; 769 - case TX_VIPRIORITY_RING_ADDR: 770 - if (-1 == buffer_add(&priv->txvipbufs, 771 - buf, dma_tmp, NULL)) { 772 - DMESGE("Unable to allocate mem for buffer LP"); 773 - return -ENOMEM; 774 - } 775 - break; 776 - case TX_VOPRIORITY_RING_ADDR: 777 - if (-1 == buffer_add(&priv->txvopbufs, 778 - buf, dma_tmp, NULL)) { 779 - DMESGE("Unable to allocate mem for buffer NP"); 780 - return -ENOMEM; 781 - } 782 - break; 783 - case TX_HIGHPRIORITY_RING_ADDR: 784 - if (-1 == buffer_add(&priv->txhpbufs, 785 - buf, dma_tmp, NULL)) { 786 - DMESGE("Unable to allocate mem for buffer HP"); 787 - return -ENOMEM; 788 - } 789 - break; 790 - case TX_BEACON_RING_ADDR: 791 - if (-1 == buffer_add(&priv->txbeaconbufs, 792 - buf, dma_tmp, NULL)) { 793 - DMESGE("Unable to allocate mem for buffer BP"); 794 - return -ENOMEM; 795 - } 796 - break; 797 - } 798 - *tmp = *tmp & ~(1<<31); /* descriptor empty, owned by the drv */ 799 - *(tmp+2) = (u32)dma_tmp; 800 - *(tmp+3) = bufsize; 801 - 802 - if (i+1 < count) 803 - *(tmp+4) = (u32)dma_desc+((i+1)*8*4); 804 - else 805 - *(tmp+4) = (u32)dma_desc; 806 - 807 - tmp = tmp+8; 808 - } 809 - 810 - switch (addr) { 811 - case TX_MANAGEPRIORITY_RING_ADDR: 812 - priv->txmapringdma = dma_desc; 813 - priv->txmapring = desc; 814 - break; 815 - case TX_BKPRIORITY_RING_ADDR: 816 - priv->txbkpringdma = dma_desc; 817 - priv->txbkpring = desc; 818 - break; 819 - case TX_BEPRIORITY_RING_ADDR: 820 - priv->txbepringdma = dma_desc; 821 - priv->txbepring = desc; 822 - break; 823 - case TX_VIPRIORITY_RING_ADDR: 824 - priv->txvipringdma = dma_desc; 825 - priv->txvipring = desc; 826 - break; 827 - case TX_VOPRIORITY_RING_ADDR: 828 - priv->txvopringdma = dma_desc; 829 - priv->txvopring = desc; 830 - break; 831 - case TX_HIGHPRIORITY_RING_ADDR: 832 - priv->txhpringdma = dma_desc; 833 - priv->txhpring = desc; 834 - break; 835 - case TX_BEACON_RING_ADDR: 836 - priv->txbeaconringdma = dma_desc; 837 - priv->txbeaconring = desc; 838 - break; 839 - 840 - } 841 - 842 - return 0; 843 - } 844 - 845 - static void free_tx_desc_rings(struct net_device *dev) 846 - { 847 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 848 - struct pci_dev *pdev = priv->pdev; 849 - int count = priv->txringcount; 850 - 851 - pci_free_consistent(pdev, sizeof(u32)*8*count+256, 852 - priv->txmapring, priv->txmapringdma); 853 - buffer_free(dev, &(priv->txmapbufs), priv->txbuffsize, 1); 854 - 855 - pci_free_consistent(pdev, sizeof(u32)*8*count+256, 856 - priv->txbkpring, priv->txbkpringdma); 857 - buffer_free(dev, &(priv->txbkpbufs), priv->txbuffsize, 1); 858 - 859 - pci_free_consistent(pdev, sizeof(u32)*8*count+256, 860 - priv->txbepring, priv->txbepringdma); 861 - buffer_free(dev, &(priv->txbepbufs), priv->txbuffsize, 1); 862 - 863 - pci_free_consistent(pdev, sizeof(u32)*8*count+256, 864 - priv->txvipring, priv->txvipringdma); 865 - buffer_free(dev, &(priv->txvipbufs), priv->txbuffsize, 1); 866 - 867 - pci_free_consistent(pdev, sizeof(u32)*8*count+256, 868 - priv->txvopring, priv->txvopringdma); 869 - buffer_free(dev, &(priv->txvopbufs), priv->txbuffsize, 1); 870 - 871 - pci_free_consistent(pdev, sizeof(u32)*8*count+256, 872 - priv->txhpring, priv->txhpringdma); 873 - buffer_free(dev, &(priv->txhpbufs), priv->txbuffsize, 1); 874 - 875 - count = priv->txbeaconcount; 876 - pci_free_consistent(pdev, sizeof(u32)*8*count+256, 877 - priv->txbeaconring, priv->txbeaconringdma); 878 - buffer_free(dev, &(priv->txbeaconbufs), priv->txbuffsize, 1); 879 - } 880 - 881 - static void free_rx_desc_ring(struct net_device *dev) 882 - { 883 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 884 - struct pci_dev *pdev = priv->pdev; 885 - int count = priv->rxringcount; 886 - 887 - pci_free_consistent(pdev, sizeof(u32)*8*count+256, 888 - priv->rxring, priv->rxringdma); 889 - 890 - buffer_free(dev, &(priv->rxbuffer), priv->rxbuffersize, 0); 891 - } 892 - 893 - static short alloc_rx_desc_ring(struct net_device *dev, u16 bufsize, int count) 894 - { 895 - int i; 896 - u32 *desc; 897 - u32 *tmp; 898 - dma_addr_t dma_desc, dma_tmp; 899 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 900 - struct pci_dev *pdev = priv->pdev; 901 - void *buf; 902 - u8 rx_desc_size; 903 - 904 - rx_desc_size = 8; /* 4*8 = 32 bytes */ 905 - 906 - if ((bufsize & 0xfff) != bufsize) { 907 - DMESGE("RX buffer allocation too large"); 908 - return -1; 909 - } 910 - 911 - desc = (u32 *)pci_alloc_consistent(pdev, 912 - sizeof(u32) * rx_desc_size * count + 256, &dma_desc); 913 - 914 - if (dma_desc & 0xff) 915 - /* 916 - * descriptor's buffer must be 256 byte aligned 917 - * should never happen since we specify the DMA mask 918 - */ 919 - WARN(1, "DMA buffer is not aligned\n"); 920 - 921 - priv->rxring = desc; 922 - priv->rxringdma = dma_desc; 923 - tmp = desc; 924 - 925 - for (i = 0; i < count; i++) { 926 - buf = kmalloc(bufsize * sizeof(u8), GFP_ATOMIC); 927 - if (buf == NULL) { 928 - DMESGE("Failed to kmalloc RX buffer"); 929 - return -1; 930 - } 931 - 932 - dma_tmp = pci_map_single(pdev, buf, bufsize * sizeof(u8), 933 - PCI_DMA_FROMDEVICE); 934 - if (pci_dma_mapping_error(pdev, dma_tmp)) 935 - return -1; 936 - if (-1 == buffer_add(&(priv->rxbuffer), buf, dma_tmp, 937 - &(priv->rxbufferhead))) { 938 - DMESGE("Unable to allocate mem RX buf"); 939 - return -1; 940 - } 941 - *tmp = 0; /* zero pads the header of the descriptor */ 942 - *tmp = *tmp | (bufsize&0xfff); 943 - *(tmp+2) = (u32)dma_tmp; 944 - *tmp = *tmp | (1<<31); /* descriptor void, owned by the NIC */ 945 - 946 - tmp = tmp+rx_desc_size; 947 - } 948 - 949 - /* this is the last descriptor */ 950 - *(tmp - rx_desc_size) = *(tmp - rx_desc_size) | (1 << 30); 951 - 952 - return 0; 953 - } 954 - 955 - 956 - void set_nic_rxring(struct net_device *dev) 957 - { 958 - u8 pgreg; 959 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 960 - 961 - pgreg = read_nic_byte(dev, PGSELECT); 962 - write_nic_byte(dev, PGSELECT, pgreg & ~(1<<PGSELECT_PG_SHIFT)); 963 - 964 - write_nic_dword(dev, RXRING_ADDR, priv->rxringdma); 965 - } 966 - 967 - void rtl8180_reset(struct net_device *dev) 968 - { 969 - u8 cr; 970 - 971 - rtl8180_irq_disable(dev); 972 - 973 - cr = read_nic_byte(dev, CMD); 974 - cr = cr & 2; 975 - cr = cr | (1<<CMD_RST_SHIFT); 976 - write_nic_byte(dev, CMD, cr); 977 - 978 - force_pci_posting(dev); 979 - 980 - mdelay(200); 981 - 982 - if (read_nic_byte(dev, CMD) & (1<<CMD_RST_SHIFT)) 983 - DMESGW("Card reset timeout!"); 984 - else 985 - DMESG("Card successfully reset"); 986 - 987 - rtl8180_set_mode(dev, EPROM_CMD_LOAD); 988 - force_pci_posting(dev); 989 - mdelay(200); 990 - } 991 - 992 - inline u16 ieeerate2rtlrate(int rate) 993 - { 994 - switch (rate) { 995 - case 10: 996 - return 0; 997 - case 20: 998 - return 1; 999 - case 55: 1000 - return 2; 1001 - case 110: 1002 - return 3; 1003 - case 60: 1004 - return 4; 1005 - case 90: 1006 - return 5; 1007 - case 120: 1008 - return 6; 1009 - case 180: 1010 - return 7; 1011 - case 240: 1012 - return 8; 1013 - case 360: 1014 - return 9; 1015 - case 480: 1016 - return 10; 1017 - case 540: 1018 - return 11; 1019 - default: 1020 - return 3; 1021 - } 1022 - } 1023 - 1024 - static u16 rtl_rate[] = {10, 20, 55, 110, 60, 1025 - 90, 120, 180, 240, 360, 480, 540, 720}; 1026 - 1027 - inline u16 rtl8180_rate2rate(short rate) 1028 - { 1029 - if (rate > 12) 1030 - return 10; 1031 - return rtl_rate[rate]; 1032 - } 1033 - 1034 - inline u8 rtl8180_IsWirelessBMode(u16 rate) 1035 - { 1036 - if (((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220)) 1037 - return 1; 1038 - else 1039 - return 0; 1040 - } 1041 - 1042 - u16 N_DBPSOfRate(u16 DataRate); 1043 - 1044 - static u16 ComputeTxTime(u16 FrameLength, u16 DataRate, u8 bManagementFrame, 1045 - u8 bShortPreamble) 1046 - { 1047 - u16 FrameTime; 1048 - u16 N_DBPS; 1049 - u16 Ceiling; 1050 - 1051 - if (rtl8180_IsWirelessBMode(DataRate)) { 1052 - if (bManagementFrame || !bShortPreamble || DataRate == 10) 1053 - /* long preamble */ 1054 - FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10))); 1055 - else 1056 - /* short preamble */ 1057 - FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10))); 1058 - 1059 - if ((FrameLength*8 % (DataRate/10)) != 0) /* get the ceilling */ 1060 - FrameTime++; 1061 - } else { /* 802.11g DSSS-OFDM PLCP length field calculation. */ 1062 - N_DBPS = N_DBPSOfRate(DataRate); 1063 - Ceiling = (16 + 8*FrameLength + 6) / N_DBPS 1064 - + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0); 1065 - FrameTime = (u16)(16 + 4 + 4*Ceiling + 6); 1066 - } 1067 - return FrameTime; 1068 - } 1069 - 1070 - u16 N_DBPSOfRate(u16 DataRate) 1071 - { 1072 - u16 N_DBPS = 24; 1073 - 1074 - switch (DataRate) { 1075 - case 60: 1076 - N_DBPS = 24; 1077 - break; 1078 - case 90: 1079 - N_DBPS = 36; 1080 - break; 1081 - case 120: 1082 - N_DBPS = 48; 1083 - break; 1084 - case 180: 1085 - N_DBPS = 72; 1086 - break; 1087 - case 240: 1088 - N_DBPS = 96; 1089 - break; 1090 - case 360: 1091 - N_DBPS = 144; 1092 - break; 1093 - case 480: 1094 - N_DBPS = 192; 1095 - break; 1096 - case 540: 1097 - N_DBPS = 216; 1098 - break; 1099 - default: 1100 - break; 1101 - } 1102 - 1103 - return N_DBPS; 1104 - } 1105 - 1106 - /* 1107 - * For Netgear case, they want good-looking signal strength. 1108 - */ 1109 - static long NetgearSignalStrengthTranslate(long LastSS, long CurrSS) 1110 - { 1111 - long RetSS; 1112 - 1113 - /* Step 1. Scale mapping. */ 1114 - if (CurrSS >= 71 && CurrSS <= 100) 1115 - RetSS = 90 + ((CurrSS - 70) / 3); 1116 - else if (CurrSS >= 41 && CurrSS <= 70) 1117 - RetSS = 78 + ((CurrSS - 40) / 3); 1118 - else if (CurrSS >= 31 && CurrSS <= 40) 1119 - RetSS = 66 + (CurrSS - 30); 1120 - else if (CurrSS >= 21 && CurrSS <= 30) 1121 - RetSS = 54 + (CurrSS - 20); 1122 - else if (CurrSS >= 5 && CurrSS <= 20) 1123 - RetSS = 42 + (((CurrSS - 5) * 2) / 3); 1124 - else if (CurrSS == 4) 1125 - RetSS = 36; 1126 - else if (CurrSS == 3) 1127 - RetSS = 27; 1128 - else if (CurrSS == 2) 1129 - RetSS = 18; 1130 - else if (CurrSS == 1) 1131 - RetSS = 9; 1132 - else 1133 - RetSS = CurrSS; 1134 - 1135 - /* Step 2. Smoothing. */ 1136 - if (LastSS > 0) 1137 - RetSS = ((LastSS * 5) + (RetSS) + 5) / 6; 1138 - 1139 - return RetSS; 1140 - } 1141 - 1142 - /* 1143 - * Translate 0-100 signal strength index into dBm. 1144 - */ 1145 - static long TranslateToDbm8185(u8 SignalStrengthIndex) 1146 - { 1147 - long SignalPower; 1148 - 1149 - /* Translate to dBm (x=0.5y-95). */ 1150 - SignalPower = (long)((SignalStrengthIndex + 1) >> 1); 1151 - SignalPower -= 95; 1152 - 1153 - return SignalPower; 1154 - } 1155 - 1156 - /* 1157 - * Perform signal smoothing for dynamic mechanism. 1158 - * This is different with PerformSignalSmoothing8185 in smoothing formula. 1159 - * No dramatic adjustment is applied because dynamic mechanism need some 1160 - * degree of correctness. Ported from 8187B. 1161 - */ 1162 - static void PerformUndecoratedSignalSmoothing8185(struct r8180_priv *priv, 1163 - bool bCckRate) 1164 - { 1165 - long smoothedSS; 1166 - long smoothedRx; 1167 - 1168 - /* Determine the current packet is CCK rate. */ 1169 - priv->bCurCCKPkt = bCckRate; 1170 - 1171 - smoothedSS = priv->SignalStrength * 10; 1172 - 1173 - if (priv->UndecoratedSmoothedSS >= 0) 1174 - smoothedSS = ((priv->UndecoratedSmoothedSS * 5) + 1175 - smoothedSS) / 6; 1176 - 1177 - priv->UndecoratedSmoothedSS = smoothedSS; 1178 - 1179 - smoothedRx = ((priv->UndecoratedSmoothedRxPower * 50) + 1180 - (priv->RxPower * 11)) / 60; 1181 - 1182 - priv->UndecoratedSmoothedRxPower = smoothedRx; 1183 - 1184 - if (bCckRate) 1185 - priv->CurCCKRSSI = priv->RSSI; 1186 - else 1187 - priv->CurCCKRSSI = 0; 1188 - } 1189 - 1190 - 1191 - /* 1192 - * This is rough RX isr handling routine 1193 - */ 1194 - static void rtl8180_rx(struct net_device *dev) 1195 - { 1196 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1197 - struct sk_buff *tmp_skb; 1198 - short first, last; 1199 - u32 len; 1200 - int lastlen; 1201 - unsigned char quality, signal; 1202 - u8 rate; 1203 - u32 *tmp, *tmp2; 1204 - u8 rx_desc_size; 1205 - u8 padding; 1206 - char rxpower = 0; 1207 - u32 RXAGC = 0; 1208 - long RxAGC_dBm = 0; 1209 - u8 LNA = 0, BB = 0; 1210 - u8 LNA_gain[4] = {02, 17, 29, 39}; 1211 - u8 Antenna = 0; 1212 - struct ieee80211_hdr_4addr *hdr; 1213 - u16 fc, type; 1214 - u8 bHwError = 0, bCRC = 0, bICV = 0; 1215 - bool bCckRate = false; 1216 - u8 RSSI = 0; 1217 - long SignalStrengthIndex = 0; 1218 - struct ieee80211_rx_stats stats = { 1219 - .signal = 0, 1220 - .noise = -98, 1221 - .rate = 0, 1222 - .freq = IEEE80211_24GHZ_BAND, 1223 - }; 1224 - 1225 - stats.nic_type = NIC_8185B; 1226 - rx_desc_size = 8; 1227 - 1228 - if ((*(priv->rxringtail)) & (1<<31)) { 1229 - /* we have got an RX int, but the descriptor. we are pointing 1230 - * is empty. 1231 - */ 1232 - 1233 - priv->stats.rxnodata++; 1234 - priv->ieee80211->stats.rx_errors++; 1235 - 1236 - tmp2 = NULL; 1237 - tmp = priv->rxringtail; 1238 - do { 1239 - if (tmp == priv->rxring) 1240 - tmp = priv->rxring + (priv->rxringcount - 1) * 1241 - rx_desc_size; 1242 - else 1243 - tmp -= rx_desc_size; 1244 - 1245 - if (!(*tmp & (1<<31))) 1246 - tmp2 = tmp; 1247 - } while (tmp != priv->rxring); 1248 - 1249 - if (tmp2) 1250 - priv->rxringtail = tmp2; 1251 - } 1252 - 1253 - /* while there are filled descriptors */ 1254 - while (!(*(priv->rxringtail) & (1<<31))) { 1255 - if (*(priv->rxringtail) & (1<<26)) 1256 - DMESGW("RX buffer overflow"); 1257 - if (*(priv->rxringtail) & (1<<12)) 1258 - priv->stats.rxicverr++; 1259 - 1260 - if (*(priv->rxringtail) & (1<<27)) { 1261 - priv->stats.rxdmafail++; 1262 - goto drop; 1263 - } 1264 - 1265 - pci_dma_sync_single_for_cpu(priv->pdev, 1266 - priv->rxbuffer->dma, 1267 - priv->rxbuffersize * sizeof(u8), 1268 - PCI_DMA_FROMDEVICE); 1269 - 1270 - first = *(priv->rxringtail) & (1<<29) ? 1 : 0; 1271 - if (first) 1272 - priv->rx_prevlen = 0; 1273 - 1274 - last = *(priv->rxringtail) & (1<<28) ? 1 : 0; 1275 - if (last) { 1276 - lastlen = ((*priv->rxringtail) & 0xfff); 1277 - 1278 - /* if the last descriptor (that should tell us the total 1279 - * packet len) tell us something less than the 1280 - * descriptors len we had until now, then there is some 1281 - * problem.. 1282 - * workaround to prevent kernel panic 1283 - */ 1284 - if (lastlen < priv->rx_prevlen) 1285 - len = 0; 1286 - else 1287 - len = lastlen-priv->rx_prevlen; 1288 - 1289 - if (*(priv->rxringtail) & (1<<13)) { 1290 - if ((*(priv->rxringtail) & 0xfff) < 500) 1291 - priv->stats.rxcrcerrmin++; 1292 - else if ((*(priv->rxringtail) & 0x0fff) > 1000) 1293 - priv->stats.rxcrcerrmax++; 1294 - else 1295 - priv->stats.rxcrcerrmid++; 1296 - 1297 - } 1298 - 1299 - } else { 1300 - len = priv->rxbuffersize; 1301 - } 1302 - 1303 - if (first && last) { 1304 - padding = ((*(priv->rxringtail+3))&(0x04000000))>>26; 1305 - } else if (first) { 1306 - padding = ((*(priv->rxringtail+3))&(0x04000000))>>26; 1307 - if (padding) 1308 - len -= 2; 1309 - } else { 1310 - padding = 0; 1311 - } 1312 - padding = 0; 1313 - priv->rx_prevlen += len; 1314 - 1315 - if (priv->rx_prevlen > MAX_FRAG_THRESHOLD + 100) { 1316 - /* HW is probably passing several buggy frames without 1317 - * FD or LD flag set. 1318 - * Throw this garbage away to prevent skb memory 1319 - * exhausting 1320 - */ 1321 - if (!priv->rx_skb_complete) 1322 - dev_kfree_skb_any(priv->rx_skb); 1323 - priv->rx_skb_complete = 1; 1324 - } 1325 - 1326 - signal = (unsigned char)((*(priv->rxringtail + 3) & 1327 - 0x00ff0000) >> 16); 1328 - signal = (signal & 0xfe) >> 1; 1329 - 1330 - quality = (unsigned char)((*(priv->rxringtail+3)) & (0xff)); 1331 - 1332 - stats.mac_time[0] = *(priv->rxringtail+1); 1333 - stats.mac_time[1] = *(priv->rxringtail+2); 1334 - 1335 - rxpower = ((char)((*(priv->rxringtail + 4) & 1336 - 0x00ff0000) >> 16)) / 2 - 42; 1337 - 1338 - RSSI = ((u8)((*(priv->rxringtail + 3) & 1339 - 0x0000ff00) >> 8)) & 0x7f; 1340 - 1341 - rate = ((*(priv->rxringtail)) & 1342 - ((1<<23)|(1<<22)|(1<<21)|(1<<20)))>>20; 1343 - 1344 - stats.rate = rtl8180_rate2rate(rate); 1345 - Antenna = (*(priv->rxringtail + 3) & 0x00008000) == 0 ? 0 : 1; 1346 - if (!rtl8180_IsWirelessBMode(stats.rate)) { /* OFDM rate. */ 1347 - RxAGC_dBm = rxpower+1; /* bias */ 1348 - } else { /* CCK rate. */ 1349 - RxAGC_dBm = signal; /* bit 0 discard */ 1350 - 1351 - LNA = (u8) (RxAGC_dBm & 0x60) >> 5; /* bit 6~ bit 5 */ 1352 - BB = (u8) (RxAGC_dBm & 0x1F); /* bit 4 ~ bit 0 */ 1353 - 1354 - /* Pin_11b=-(LNA_gain+BB_gain) (dBm) */ 1355 - RxAGC_dBm = -(LNA_gain[LNA] + (BB * 2)); 1356 - 1357 - RxAGC_dBm += 4; /* bias */ 1358 - } 1359 - 1360 - if (RxAGC_dBm & 0x80) /* absolute value */ 1361 - RXAGC = ~(RxAGC_dBm)+1; 1362 - bCckRate = rtl8180_IsWirelessBMode(stats.rate); 1363 - /* Translate RXAGC into 1-100. */ 1364 - if (!rtl8180_IsWirelessBMode(stats.rate)) { /* OFDM rate. */ 1365 - if (RXAGC > 90) 1366 - RXAGC = 90; 1367 - else if (RXAGC < 25) 1368 - RXAGC = 25; 1369 - RXAGC = (90-RXAGC)*100/65; 1370 - } else { /* CCK rate. */ 1371 - if (RXAGC > 95) 1372 - RXAGC = 95; 1373 - else if (RXAGC < 30) 1374 - RXAGC = 30; 1375 - RXAGC = (95-RXAGC)*100/65; 1376 - } 1377 - priv->SignalStrength = (u8)RXAGC; 1378 - priv->RecvSignalPower = RxAGC_dBm; 1379 - priv->RxPower = rxpower; 1380 - priv->RSSI = RSSI; 1381 - /* SQ translation formula is provided by SD3 DZ. 2006.06.27 */ 1382 - if (quality >= 127) 1383 - /* 0 causes epc to show signal zero, walk around now */ 1384 - quality = 1; 1385 - else if (quality < 27) 1386 - quality = 100; 1387 - else 1388 - quality = 127 - quality; 1389 - priv->SignalQuality = quality; 1390 - 1391 - stats.signal = (u8) quality; 1392 - 1393 - stats.signalstrength = RXAGC; 1394 - if (stats.signalstrength > 100) 1395 - stats.signalstrength = 100; 1396 - stats.signalstrength = (stats.signalstrength * 70) / 100 + 30; 1397 - stats.rssi = priv->wstats.qual.qual = priv->SignalQuality; 1398 - stats.noise = priv->wstats.qual.noise = 1399 - 100 - priv->wstats.qual.qual; 1400 - bHwError = (((*(priv->rxringtail)) & (0x00000fff)) == 4080) | 1401 - (((*(priv->rxringtail)) & (0x04000000)) != 0) | 1402 - (((*(priv->rxringtail)) & (0x08000000)) != 0) | 1403 - (((~(*(priv->rxringtail))) & (0x10000000)) != 0) | 1404 - (((~(*(priv->rxringtail))) & (0x20000000)) != 0); 1405 - bCRC = ((*(priv->rxringtail)) & (0x00002000)) >> 13; 1406 - bICV = ((*(priv->rxringtail)) & (0x00001000)) >> 12; 1407 - hdr = (struct ieee80211_hdr_4addr *)priv->rxbuffer->buf; 1408 - fc = le16_to_cpu(hdr->frame_ctl); 1409 - type = WLAN_FC_GET_TYPE(fc); 1410 - 1411 - if (IEEE80211_FTYPE_CTL != type && 1412 - !bHwError && !bCRC && !bICV && 1413 - eqMacAddr(priv->ieee80211->current_network.bssid, 1414 - fc & IEEE80211_FCTL_TODS ? hdr->addr1 : 1415 - fc & IEEE80211_FCTL_FROMDS ? hdr->addr2 : 1416 - hdr->addr3)) { 1417 - 1418 - /* Perform signal smoothing for dynamic 1419 - * mechanism on demand. This is different 1420 - * with PerformSignalSmoothing8185 in smoothing 1421 - * fomula. No dramatic adjustion is apply 1422 - * because dynamic mechanism need some degree 1423 - * of correctness. */ 1424 - PerformUndecoratedSignalSmoothing8185(priv, bCckRate); 1425 - 1426 - /* For good-looking singal strength. */ 1427 - SignalStrengthIndex = NetgearSignalStrengthTranslate( 1428 - priv->LastSignalStrengthInPercent, 1429 - priv->SignalStrength); 1430 - 1431 - priv->LastSignalStrengthInPercent = SignalStrengthIndex; 1432 - priv->Stats_SignalStrength = 1433 - TranslateToDbm8185((u8)SignalStrengthIndex); 1434 - 1435 - /* 1436 - * We need more correct power of received packets and 1437 - * the "SignalStrength" of RxStats is beautified, so we 1438 - * record the correct power here. 1439 - */ 1440 - 1441 - priv->Stats_SignalQuality = (long)( 1442 - priv->Stats_SignalQuality * 5 + 1443 - (long)priv->SignalQuality + 5) / 6; 1444 - 1445 - priv->Stats_RecvSignalPower = (long)( 1446 - priv->Stats_RecvSignalPower * 5 + 1447 - priv->RecvSignalPower - 1) / 6; 1448 - 1449 - /* 1450 - * Figure out which antenna received the last packet. 1451 - * 0: aux, 1: main 1452 - */ 1453 - priv->LastRxPktAntenna = Antenna ? 1 : 0; 1454 - SwAntennaDiversityRxOk8185(dev, priv->SignalStrength); 1455 - } 1456 - 1457 - if (first) { 1458 - if (!priv->rx_skb_complete) { 1459 - /* seems that HW sometimes fails to receive and 1460 - * doesn't provide the last descriptor. 1461 - */ 1462 - dev_kfree_skb_any(priv->rx_skb); 1463 - priv->stats.rxnolast++; 1464 - } 1465 - priv->rx_skb = dev_alloc_skb(len+2); 1466 - if (!priv->rx_skb) 1467 - goto drop; 1468 - 1469 - priv->rx_skb_complete = 0; 1470 - priv->rx_skb->dev = dev; 1471 - } else { 1472 - /* if we are here we should have already RXed the first 1473 - * frame. 1474 - * If we get here and the skb is not allocated then 1475 - * we have just throw out garbage (skb not allocated) 1476 - * and we are still rxing garbage.... 1477 - */ 1478 - if (!priv->rx_skb_complete) { 1479 - 1480 - tmp_skb = dev_alloc_skb( 1481 - priv->rx_skb->len + len + 2); 1482 - 1483 - if (!tmp_skb) 1484 - goto drop; 1485 - 1486 - tmp_skb->dev = dev; 1487 - 1488 - memcpy(skb_put(tmp_skb, priv->rx_skb->len), 1489 - priv->rx_skb->data, 1490 - priv->rx_skb->len); 1491 - 1492 - dev_kfree_skb_any(priv->rx_skb); 1493 - 1494 - priv->rx_skb = tmp_skb; 1495 - } 1496 - } 1497 - 1498 - if (!priv->rx_skb_complete) { 1499 - memcpy(skb_put(priv->rx_skb, len), ((unsigned char *) 1500 - priv->rxbuffer->buf) + (padding ? 2 : 0), len); 1501 - } 1502 - 1503 - if (last && !priv->rx_skb_complete) { 1504 - if (priv->rx_skb->len > 4) 1505 - skb_trim(priv->rx_skb, priv->rx_skb->len-4); 1506 - if (!ieee80211_rtl_rx(priv->ieee80211, 1507 - priv->rx_skb, &stats)) 1508 - dev_kfree_skb_any(priv->rx_skb); 1509 - priv->rx_skb_complete = 1; 1510 - } 1511 - 1512 - pci_dma_sync_single_for_device(priv->pdev, 1513 - priv->rxbuffer->dma, 1514 - priv->rxbuffersize * sizeof(u8), 1515 - PCI_DMA_FROMDEVICE); 1516 - 1517 - drop: /* this is used when we have not enough mem */ 1518 - /* restore the descriptor */ 1519 - *(priv->rxringtail+2) = priv->rxbuffer->dma; 1520 - *(priv->rxringtail) = *(priv->rxringtail) & ~0xfff; 1521 - *(priv->rxringtail) = 1522 - *(priv->rxringtail) | priv->rxbuffersize; 1523 - 1524 - *(priv->rxringtail) = 1525 - *(priv->rxringtail) | (1<<31); 1526 - 1527 - priv->rxringtail += rx_desc_size; 1528 - if (priv->rxringtail >= 1529 - (priv->rxring)+(priv->rxringcount)*rx_desc_size) 1530 - priv->rxringtail = priv->rxring; 1531 - 1532 - priv->rxbuffer = (priv->rxbuffer->next); 1533 - } 1534 - } 1535 - 1536 - 1537 - static void rtl8180_dma_kick(struct net_device *dev, int priority) 1538 - { 1539 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1540 - 1541 - rtl8180_set_mode(dev, EPROM_CMD_CONFIG); 1542 - write_nic_byte(dev, TX_DMA_POLLING, 1543 - (1 << (priority + 1)) | priv->dma_poll_mask); 1544 - rtl8180_set_mode(dev, EPROM_CMD_NORMAL); 1545 - 1546 - force_pci_posting(dev); 1547 - } 1548 - 1549 - static void rtl8180_data_hard_stop(struct net_device *dev) 1550 - { 1551 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1552 - 1553 - rtl8180_set_mode(dev, EPROM_CMD_CONFIG); 1554 - priv->dma_poll_stop_mask |= TPPOLLSTOP_AC_VIQ; 1555 - write_nic_byte(dev, TPPollStop, priv->dma_poll_stop_mask); 1556 - rtl8180_set_mode(dev, EPROM_CMD_NORMAL); 1557 - } 1558 - 1559 - static void rtl8180_data_hard_resume(struct net_device *dev) 1560 - { 1561 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1562 - 1563 - rtl8180_set_mode(dev, EPROM_CMD_CONFIG); 1564 - priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_AC_VIQ); 1565 - write_nic_byte(dev, TPPollStop, priv->dma_poll_stop_mask); 1566 - rtl8180_set_mode(dev, EPROM_CMD_NORMAL); 1567 - } 1568 - 1569 - /* 1570 - * This function TX data frames when the ieee80211 stack requires this. 1571 - * It checks also if we need to stop the ieee tx queue, eventually do it 1572 - */ 1573 - static void rtl8180_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, 1574 - int rate) 1575 - { 1576 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1577 - int mode; 1578 - struct ieee80211_hdr_3addr *h = (struct ieee80211_hdr_3addr *)skb->data; 1579 - bool morefrag = le16_to_cpu(h->frame_control) & IEEE80211_FCTL_MOREFRAGS; 1580 - unsigned long flags; 1581 - int priority; 1582 - 1583 - mode = priv->ieee80211->iw_mode; 1584 - 1585 - rate = ieeerate2rtlrate(rate); 1586 - /* 1587 - * This function doesn't require lock because we make sure it's called 1588 - * with the tx_lock already acquired. 1589 - * This come from the kernel's hard_xmit callback (through the ieee 1590 - * stack, or from the try_wake_queue (again through the ieee stack. 1591 - */ 1592 - priority = AC2Q(skb->priority); 1593 - spin_lock_irqsave(&priv->tx_lock, flags); 1594 - 1595 - if (priv->ieee80211->bHwRadioOff) { 1596 - spin_unlock_irqrestore(&priv->tx_lock, flags); 1597 - 1598 - return; 1599 - } 1600 - 1601 - if (!check_nic_enought_desc(dev, priority)) { 1602 - DMESGW("Error: no descriptor left by previous TX (avail %d) ", 1603 - get_curr_tx_free_desc(dev, priority)); 1604 - ieee80211_rtl_stop_queue(priv->ieee80211); 1605 - } 1606 - rtl8180_tx(dev, skb->data, skb->len, priority, morefrag, 0, rate); 1607 - if (!check_nic_enought_desc(dev, priority)) 1608 - ieee80211_rtl_stop_queue(priv->ieee80211); 1609 - 1610 - spin_unlock_irqrestore(&priv->tx_lock, flags); 1611 - } 1612 - 1613 - /* 1614 - * This is a rough attempt to TX a frame 1615 - * This is called by the ieee 80211 stack to TX management frames. 1616 - * If the ring is full packets are dropped (for data frame the queue 1617 - * is stopped before this can happen). For this reason it is better 1618 - * if the descriptors are larger than the largest management frame 1619 - * we intend to TX: i'm unsure what the HW does if it will not find 1620 - * the last fragment of a frame because it has been dropped... 1621 - * Since queues for Management and Data frames are different we 1622 - * might use a different lock than tx_lock (for example mgmt_tx_lock) 1623 - */ 1624 - /* these function may loop if invoked with 0 descriptors or 0 len buffer */ 1625 - static int rtl8180_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) 1626 - { 1627 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1628 - unsigned long flags; 1629 - int priority; 1630 - 1631 - priority = MANAGE_PRIORITY; 1632 - 1633 - spin_lock_irqsave(&priv->tx_lock, flags); 1634 - 1635 - if (priv->ieee80211->bHwRadioOff) { 1636 - spin_unlock_irqrestore(&priv->tx_lock, flags); 1637 - dev_kfree_skb_any(skb); 1638 - return NETDEV_TX_OK; 1639 - } 1640 - 1641 - rtl8180_tx(dev, skb->data, skb->len, priority, 1642 - 0, 0, ieeerate2rtlrate(priv->ieee80211->basic_rate)); 1643 - 1644 - priv->ieee80211->stats.tx_bytes += skb->len; 1645 - priv->ieee80211->stats.tx_packets++; 1646 - spin_unlock_irqrestore(&priv->tx_lock, flags); 1647 - 1648 - dev_kfree_skb_any(skb); 1649 - return NETDEV_TX_OK; 1650 - } 1651 - 1652 - static void rtl8180_prepare_beacon(struct net_device *dev) 1653 - { 1654 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1655 - struct sk_buff *skb; 1656 - 1657 - u16 word = read_nic_word(dev, BcnItv); 1658 - word &= ~BcnItv_BcnItv; /* clear Bcn_Itv */ 1659 - 1660 - /* word |= 0x64; */ 1661 - word |= cpu_to_le16(priv->ieee80211->current_network.beacon_interval); 1662 - 1663 - write_nic_word(dev, BcnItv, word); 1664 - 1665 - skb = ieee80211_get_beacon(priv->ieee80211); 1666 - if (skb) { 1667 - rtl8180_tx(dev, skb->data, skb->len, BEACON_PRIORITY, 1668 - 0, 0, ieeerate2rtlrate(priv->ieee80211->basic_rate)); 1669 - dev_kfree_skb_any(skb); 1670 - } 1671 - } 1672 - 1673 - /* 1674 - * This function do the real dirty work: it enqueues a TX command descriptor in 1675 - * the ring buffer, copyes the frame in a TX buffer and kicks the NIC to ensure 1676 - * it does the DMA transfer. 1677 - */ 1678 - short rtl8180_tx(struct net_device *dev, u8 *txbuf, int len, int priority, 1679 - bool morefrag, short descfrag, int rate) 1680 - { 1681 - struct r8180_priv *priv = ieee80211_priv(dev); 1682 - u32 *tail, *temp_tail; 1683 - u32 *begin; 1684 - u32 *buf; 1685 - int i; 1686 - int remain; 1687 - int buflen; 1688 - int count; 1689 - struct buffer *buflist; 1690 - struct ieee80211_hdr_3addr *frag_hdr = 1691 - (struct ieee80211_hdr_3addr *)txbuf; 1692 - u8 dest[ETH_ALEN]; 1693 - u8 bUseShortPreamble = 0; 1694 - u8 bCTSEnable = 0; 1695 - u8 bRTSEnable = 0; 1696 - u16 Duration = 0; 1697 - u16 RtsDur = 0; 1698 - u16 ThisFrameTime = 0; 1699 - u16 TxDescDuration = 0; 1700 - bool ownbit_flag = false; 1701 - 1702 - switch (priority) { 1703 - case MANAGE_PRIORITY: 1704 - tail = priv->txmapringtail; 1705 - begin = priv->txmapring; 1706 - buflist = priv->txmapbufstail; 1707 - count = priv->txringcount; 1708 - break; 1709 - case BK_PRIORITY: 1710 - tail = priv->txbkpringtail; 1711 - begin = priv->txbkpring; 1712 - buflist = priv->txbkpbufstail; 1713 - count = priv->txringcount; 1714 - break; 1715 - case BE_PRIORITY: 1716 - tail = priv->txbepringtail; 1717 - begin = priv->txbepring; 1718 - buflist = priv->txbepbufstail; 1719 - count = priv->txringcount; 1720 - break; 1721 - case VI_PRIORITY: 1722 - tail = priv->txvipringtail; 1723 - begin = priv->txvipring; 1724 - buflist = priv->txvipbufstail; 1725 - count = priv->txringcount; 1726 - break; 1727 - case VO_PRIORITY: 1728 - tail = priv->txvopringtail; 1729 - begin = priv->txvopring; 1730 - buflist = priv->txvopbufstail; 1731 - count = priv->txringcount; 1732 - break; 1733 - case HI_PRIORITY: 1734 - tail = priv->txhpringtail; 1735 - begin = priv->txhpring; 1736 - buflist = priv->txhpbufstail; 1737 - count = priv->txringcount; 1738 - break; 1739 - case BEACON_PRIORITY: 1740 - tail = priv->txbeaconringtail; 1741 - begin = priv->txbeaconring; 1742 - buflist = priv->txbeaconbufstail; 1743 - count = priv->txbeaconcount; 1744 - break; 1745 - default: 1746 - return -1; 1747 - break; 1748 - } 1749 - 1750 - memcpy(&dest, frag_hdr->addr1, ETH_ALEN); 1751 - if (is_multicast_ether_addr(dest)) { 1752 - Duration = 0; 1753 - RtsDur = 0; 1754 - bRTSEnable = 0; 1755 - bCTSEnable = 0; 1756 - 1757 - ThisFrameTime = ComputeTxTime(len + sCrcLng, 1758 - rtl8180_rate2rate(rate), 0, bUseShortPreamble); 1759 - TxDescDuration = ThisFrameTime; 1760 - } else { /* Unicast packet */ 1761 - u16 AckTime; 1762 - 1763 - /* for Keep alive */ 1764 - priv->NumTxUnicast++; 1765 - 1766 - /* Figure out ACK rate according to BSS basic rate 1767 - * and Tx rate. 1768 - * AckCTSLng = 14 use 1M bps send 1769 - */ 1770 - AckTime = ComputeTxTime(14, 10, 0, 0); 1771 - 1772 - if (((len + sCrcLng) > priv->rts) && priv->rts) { /* RTS/CTS. */ 1773 - u16 RtsTime, CtsTime; 1774 - bRTSEnable = 1; 1775 - bCTSEnable = 0; 1776 - 1777 - /* Rate and time required for RTS. */ 1778 - RtsTime = ComputeTxTime(sAckCtsLng / 8, 1779 - priv->ieee80211->basic_rate, 0, 0); 1780 - 1781 - /* Rate and time required for CTS. 1782 - * AckCTSLng = 14 use 1M bps send 1783 - */ 1784 - CtsTime = ComputeTxTime(14, 10, 0, 0); 1785 - 1786 - /* Figure out time required to transmit this frame. */ 1787 - ThisFrameTime = ComputeTxTime(len + sCrcLng, 1788 - rtl8180_rate2rate(rate), 0, 1789 - bUseShortPreamble); 1790 - 1791 - /* RTS-CTS-ThisFrame-ACK. */ 1792 - RtsDur = CtsTime + ThisFrameTime + 1793 - AckTime + 3 * aSifsTime; 1794 - 1795 - TxDescDuration = RtsTime + RtsDur; 1796 - } else { /* Normal case. */ 1797 - bCTSEnable = 0; 1798 - bRTSEnable = 0; 1799 - RtsDur = 0; 1800 - 1801 - ThisFrameTime = ComputeTxTime(len + sCrcLng, 1802 - rtl8180_rate2rate(rate), 0, bUseShortPreamble); 1803 - TxDescDuration = ThisFrameTime + aSifsTime + AckTime; 1804 - } 1805 - 1806 - if (!(le16_to_cpu(frag_hdr->frame_control) & IEEE80211_FCTL_MOREFRAGS)) { 1807 - /* ThisFrame-ACK. */ 1808 - Duration = aSifsTime + AckTime; 1809 - } else { /* One or more fragments remained. */ 1810 - u16 NextFragTime; 1811 - 1812 - /* pretend following packet length = current packet */ 1813 - NextFragTime = ComputeTxTime(len + sCrcLng, 1814 - rtl8180_rate2rate(rate), 0, bUseShortPreamble); 1815 - 1816 - /* ThisFrag-ACk-NextFrag-ACK. */ 1817 - Duration = NextFragTime + 3 * aSifsTime + 2 * AckTime; 1818 - } 1819 - 1820 - } /* End of Unicast packet */ 1821 - 1822 - frag_hdr->duration_id = Duration; 1823 - 1824 - buflen = priv->txbuffsize; 1825 - remain = len; 1826 - temp_tail = tail; 1827 - 1828 - while (remain != 0) { 1829 - mb(); 1830 - if (!buflist) { 1831 - DMESGE("TX buffer error, cannot TX frames. pri %d.", 1832 - priority); 1833 - return -1; 1834 - } 1835 - buf = buflist->buf; 1836 - 1837 - if ((*tail & (1 << 31)) && (priority != BEACON_PRIORITY)) { 1838 - DMESGW("No more TX desc, returning %x of %x", 1839 - remain, len); 1840 - priv->stats.txrdu++; 1841 - return remain; 1842 - } 1843 - 1844 - *tail = 0; /* zeroes header */ 1845 - *(tail+1) = 0; 1846 - *(tail+3) = 0; 1847 - *(tail+5) = 0; 1848 - *(tail+6) = 0; 1849 - *(tail+7) = 0; 1850 - 1851 - /* FIXME: should be triggered by HW encryption parameters.*/ 1852 - *tail |= (1<<15); /* no encrypt */ 1853 - 1854 - if (remain == len && !descfrag) { 1855 - ownbit_flag = false; 1856 - *tail = *tail | (1 << 29); /* first segment of packet */ 1857 - *tail = *tail | (len); 1858 - } else { 1859 - ownbit_flag = true; 1860 - } 1861 - 1862 - for (i = 0; i < buflen && remain > 0; i++, remain--) { 1863 - /* copy data into descriptor pointed DMAble buffer */ 1864 - ((u8 *)buf)[i] = txbuf[i]; 1865 - 1866 - if (remain == 4 && i+4 >= buflen) 1867 - break; 1868 - /* ensure the last desc has at least 4 bytes payload */ 1869 - } 1870 - txbuf = txbuf + i; 1871 - *(tail+3) = *(tail+3) & ~0xfff; 1872 - *(tail+3) = *(tail+3) | i; /* buffer length */ 1873 - 1874 - if (bCTSEnable) 1875 - *tail |= (1<<18); 1876 - 1877 - if (bRTSEnable) { /* rts enable */ 1878 - /* RTS RATE */ 1879 - *tail |= (ieeerate2rtlrate( 1880 - priv->ieee80211->basic_rate) << 19); 1881 - 1882 - *tail |= (1<<23); /* rts enable */ 1883 - *(tail+1) |= (RtsDur&0xffff); /* RTS Duration */ 1884 - } 1885 - *(tail+3) |= ((TxDescDuration&0xffff)<<16); /* DURATION */ 1886 - 1887 - *(tail + 5) |= (11 << 8); /* retry lim; */ 1888 - 1889 - *tail = *tail | ((rate&0xf) << 24); 1890 - 1891 - if (morefrag) 1892 - *tail = (*tail) | (1<<17); /* more fragment */ 1893 - if (!remain) 1894 - *tail = (*tail) | (1<<28); /* last segment of frame */ 1895 - 1896 - *(tail+5) = *(tail+5)|(2<<27); 1897 - *(tail+7) = *(tail+7)|(1<<4); 1898 - 1899 - wmb(); 1900 - if (ownbit_flag) 1901 - /* descriptor ready to be txed */ 1902 - *tail |= (1 << 31); 1903 - 1904 - if ((tail - begin)/8 == count-1) 1905 - tail = begin; 1906 - else 1907 - tail = tail+8; 1908 - 1909 - buflist = buflist->next; 1910 - 1911 - mb(); 1912 - 1913 - switch (priority) { 1914 - case MANAGE_PRIORITY: 1915 - priv->txmapringtail = tail; 1916 - priv->txmapbufstail = buflist; 1917 - break; 1918 - case BK_PRIORITY: 1919 - priv->txbkpringtail = tail; 1920 - priv->txbkpbufstail = buflist; 1921 - break; 1922 - case BE_PRIORITY: 1923 - priv->txbepringtail = tail; 1924 - priv->txbepbufstail = buflist; 1925 - break; 1926 - case VI_PRIORITY: 1927 - priv->txvipringtail = tail; 1928 - priv->txvipbufstail = buflist; 1929 - break; 1930 - case VO_PRIORITY: 1931 - priv->txvopringtail = tail; 1932 - priv->txvopbufstail = buflist; 1933 - break; 1934 - case HI_PRIORITY: 1935 - priv->txhpringtail = tail; 1936 - priv->txhpbufstail = buflist; 1937 - break; 1938 - case BEACON_PRIORITY: 1939 - /* 1940 - * The HW seems to be happy with the 1st 1941 - * descriptor filled and the 2nd empty... 1942 - * So always update descriptor 1 and never 1943 - * touch 2nd 1944 - */ 1945 - break; 1946 - } 1947 - } 1948 - *temp_tail = *temp_tail | (1<<31); /* descriptor ready to be txed */ 1949 - rtl8180_dma_kick(dev, priority); 1950 - 1951 - return 0; 1952 - } 1953 - 1954 - void rtl8180_irq_rx_tasklet(struct r8180_priv *priv); 1955 - 1956 - static void rtl8180_link_change(struct net_device *dev) 1957 - { 1958 - struct r8180_priv *priv = ieee80211_priv(dev); 1959 - u16 beacon_interval; 1960 - struct ieee80211_network *net = &priv->ieee80211->current_network; 1961 - 1962 - rtl8180_update_msr(dev); 1963 - 1964 - rtl8180_set_mode(dev, EPROM_CMD_CONFIG); 1965 - 1966 - write_nic_dword(dev, BSSID, ((u32 *)net->bssid)[0]); 1967 - write_nic_word(dev, BSSID+4, ((u16 *)net->bssid)[2]); 1968 - 1969 - beacon_interval = read_nic_word(dev, BEACON_INTERVAL); 1970 - beacon_interval &= ~BEACON_INTERVAL_MASK; 1971 - beacon_interval |= net->beacon_interval; 1972 - write_nic_word(dev, BEACON_INTERVAL, beacon_interval); 1973 - 1974 - rtl8180_set_mode(dev, EPROM_CMD_NORMAL); 1975 - 1976 - rtl8180_set_chan(dev, priv->chan); 1977 - } 1978 - 1979 - static void rtl8180_rq_tx_ack(struct net_device *dev) 1980 - { 1981 - 1982 - struct r8180_priv *priv = ieee80211_priv(dev); 1983 - 1984 - write_nic_byte(dev, CONFIG4, 1985 - read_nic_byte(dev, CONFIG4) | CONFIG4_PWRMGT); 1986 - priv->ack_tx_to_ieee = 1; 1987 - } 1988 - 1989 - static short rtl8180_is_tx_queue_empty(struct net_device *dev) 1990 - { 1991 - 1992 - struct r8180_priv *priv = ieee80211_priv(dev); 1993 - u32 *d; 1994 - 1995 - for (d = priv->txmapring; 1996 - d < priv->txmapring + priv->txringcount; d += 8) 1997 - if (*d & (1<<31)) 1998 - return 0; 1999 - 2000 - for (d = priv->txbkpring; 2001 - d < priv->txbkpring + priv->txringcount; d += 8) 2002 - if (*d & (1<<31)) 2003 - return 0; 2004 - 2005 - for (d = priv->txbepring; 2006 - d < priv->txbepring + priv->txringcount; d += 8) 2007 - if (*d & (1<<31)) 2008 - return 0; 2009 - 2010 - for (d = priv->txvipring; 2011 - d < priv->txvipring + priv->txringcount; d += 8) 2012 - if (*d & (1<<31)) 2013 - return 0; 2014 - 2015 - for (d = priv->txvopring; 2016 - d < priv->txvopring + priv->txringcount; d += 8) 2017 - if (*d & (1<<31)) 2018 - return 0; 2019 - 2020 - for (d = priv->txhpring; 2021 - d < priv->txhpring + priv->txringcount; d += 8) 2022 - if (*d & (1<<31)) 2023 - return 0; 2024 - return 1; 2025 - } 2026 - 2027 - static void rtl8180_hw_wakeup(struct net_device *dev) 2028 - { 2029 - unsigned long flags; 2030 - struct r8180_priv *priv = ieee80211_priv(dev); 2031 - 2032 - spin_lock_irqsave(&priv->ps_lock, flags); 2033 - write_nic_byte(dev, CONFIG4, 2034 - read_nic_byte(dev, CONFIG4) & ~CONFIG4_PWRMGT); 2035 - if (priv->rf_wakeup) 2036 - priv->rf_wakeup(dev); 2037 - spin_unlock_irqrestore(&priv->ps_lock, flags); 2038 - } 2039 - 2040 - static void rtl8180_hw_sleep_down(struct net_device *dev) 2041 - { 2042 - unsigned long flags; 2043 - struct r8180_priv *priv = ieee80211_priv(dev); 2044 - 2045 - spin_lock_irqsave(&priv->ps_lock, flags); 2046 - if (priv->rf_sleep) 2047 - priv->rf_sleep(dev); 2048 - spin_unlock_irqrestore(&priv->ps_lock, flags); 2049 - } 2050 - 2051 - static void rtl8180_hw_sleep(struct net_device *dev, u32 th, u32 tl) 2052 - { 2053 - struct r8180_priv *priv = ieee80211_priv(dev); 2054 - u32 rb = jiffies; 2055 - unsigned long flags; 2056 - 2057 - spin_lock_irqsave(&priv->ps_lock, flags); 2058 - 2059 - /* 2060 - * Writing HW register with 0 equals to disable 2061 - * the timer, that is not really what we want 2062 - */ 2063 - tl -= MSECS(4+16+7); 2064 - 2065 - /* 2066 - * If the interval in which we are requested to sleep is too 2067 - * short then give up and remain awake 2068 - */ 2069 - if (((tl >= rb) && (tl-rb) <= MSECS(MIN_SLEEP_TIME)) 2070 - || ((rb > tl) && (rb-tl) < MSECS(MIN_SLEEP_TIME))) { 2071 - spin_unlock_irqrestore(&priv->ps_lock, flags); 2072 - netdev_warn(dev, "too short to sleep\n"); 2073 - return; 2074 - } 2075 - 2076 - { 2077 - u32 tmp = (tl > rb) ? (tl-rb) : (rb-tl); 2078 - 2079 - priv->DozePeriodInPast2Sec += jiffies_to_msecs(tmp); 2080 - /* as tl may be less than rb */ 2081 - queue_delayed_work(priv->ieee80211->wq, 2082 - &priv->ieee80211->hw_wakeup_wq, tmp); 2083 - } 2084 - /* 2085 - * If we suspect the TimerInt is gone beyond tl 2086 - * while setting it, then give up 2087 - */ 2088 - 2089 - if (((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME))) || 2090 - ((tl < rb) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))) { 2091 - spin_unlock_irqrestore(&priv->ps_lock, flags); 2092 - return; 2093 - } 2094 - 2095 - queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_sleep_wq); 2096 - spin_unlock_irqrestore(&priv->ps_lock, flags); 2097 - } 2098 - 2099 - static void rtl8180_wmm_single_param_update(struct net_device *dev, 2100 - u8 mode, AC_CODING eACI, PAC_PARAM param) 2101 - { 2102 - u8 u1bAIFS; 2103 - u32 u4bAcParam; 2104 - 2105 - /* Retrieve parameters to update. */ 2106 - /* Mode G/A: slotTimeTimer = 9; Mode B: 20 */ 2107 - u1bAIFS = param->f.AciAifsn.f.AIFSN * ((mode & IEEE_G) == IEEE_G ? 2108 - 9 : 20) + aSifsTime; 2109 - u4bAcParam = (((u32)param->f.TXOPLimit << AC_PARAM_TXOP_LIMIT_OFFSET) | 2110 - ((u32)param->f.Ecw.f.ECWmax << AC_PARAM_ECW_MAX_OFFSET) | 2111 - ((u32)param->f.Ecw.f.ECWmin << AC_PARAM_ECW_MIN_OFFSET) | 2112 - ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET)); 2113 - 2114 - switch (eACI) { 2115 - case AC1_BK: 2116 - write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); 2117 - return; 2118 - case AC0_BE: 2119 - write_nic_dword(dev, AC_BE_PARAM, u4bAcParam); 2120 - return; 2121 - case AC2_VI: 2122 - write_nic_dword(dev, AC_VI_PARAM, u4bAcParam); 2123 - return; 2124 - case AC3_VO: 2125 - write_nic_dword(dev, AC_VO_PARAM, u4bAcParam); 2126 - return; 2127 - default: 2128 - pr_warn("SetHwReg8185(): invalid ACI: %d!\n", eACI); 2129 - return; 2130 - } 2131 - } 2132 - 2133 - static void rtl8180_wmm_param_update(struct work_struct *work) 2134 - { 2135 - struct ieee80211_device *ieee = container_of(work, 2136 - struct ieee80211_device, wmm_param_update_wq); 2137 - struct net_device *dev = ieee->dev; 2138 - u8 *ac_param = (u8 *)(ieee->current_network.wmm_param); 2139 - u8 mode = ieee->current_network.mode; 2140 - AC_CODING eACI; 2141 - AC_PARAM AcParam; 2142 - 2143 - if (!ieee->current_network.QoS_Enable) { 2144 - /* legacy ac_xx_param update */ 2145 - AcParam.longData = 0; 2146 - AcParam.f.AciAifsn.f.AIFSN = 2; /* Follow 802.11 DIFS. */ 2147 - AcParam.f.AciAifsn.f.ACM = 0; 2148 - AcParam.f.Ecw.f.ECWmin = 3; /* Follow 802.11 CWmin. */ 2149 - AcParam.f.Ecw.f.ECWmax = 7; /* Follow 802.11 CWmax. */ 2150 - AcParam.f.TXOPLimit = 0; 2151 - 2152 - for (eACI = 0; eACI < AC_MAX; eACI++) { 2153 - AcParam.f.AciAifsn.f.ACI = (u8)eACI; 2154 - 2155 - rtl8180_wmm_single_param_update(dev, mode, eACI, 2156 - (PAC_PARAM)&AcParam); 2157 - } 2158 - return; 2159 - } 2160 - 2161 - for (eACI = 0; eACI < AC_MAX; eACI++) { 2162 - rtl8180_wmm_single_param_update(dev, mode, 2163 - ((PAC_PARAM)ac_param)->f.AciAifsn.f.ACI, 2164 - (PAC_PARAM)ac_param); 2165 - 2166 - ac_param += sizeof(AC_PARAM); 2167 - } 2168 - } 2169 - 2170 - void rtl8180_restart_wq(struct work_struct *work); 2171 - void rtl8180_watch_dog_wq(struct work_struct *work); 2172 - void rtl8180_hw_wakeup_wq(struct work_struct *work); 2173 - void rtl8180_hw_sleep_wq(struct work_struct *work); 2174 - void rtl8180_sw_antenna_wq(struct work_struct *work); 2175 - void rtl8180_watch_dog(struct net_device *dev); 2176 - 2177 - static void watch_dog_adaptive(unsigned long data) 2178 - { 2179 - struct r8180_priv *priv = ieee80211_priv((struct net_device *)data); 2180 - 2181 - if (!priv->up) { 2182 - DMESG("<----watch_dog_adaptive():driver is not up!\n"); 2183 - return; 2184 - } 2185 - 2186 - /* Tx High Power Mechanism. */ 2187 - if (CheckHighPower((struct net_device *)data)) 2188 - queue_work(priv->ieee80211->wq, 2189 - (void *)&priv->ieee80211->tx_pw_wq); 2190 - 2191 - /* Tx Power Tracking on 87SE. */ 2192 - if (CheckTxPwrTracking((struct net_device *)data)) 2193 - TxPwrTracking87SE((struct net_device *)data); 2194 - 2195 - /* Perform DIG immediately. */ 2196 - if (CheckDig((struct net_device *)data)) 2197 - queue_work(priv->ieee80211->wq, 2198 - (void *)&priv->ieee80211->hw_dig_wq); 2199 - 2200 - rtl8180_watch_dog((struct net_device *)data); 2201 - 2202 - queue_work(priv->ieee80211->wq, 2203 - (void *)&priv->ieee80211->GPIOChangeRFWorkItem); 2204 - 2205 - priv->watch_dog_timer.expires = jiffies + 2206 - MSECS(IEEE80211_WATCH_DOG_TIME); 2207 - 2208 - add_timer(&priv->watch_dog_timer); 2209 - } 2210 - 2211 - static struct rtl8187se_channel_list channel_plan_list[] = { 2212 - /* FCC */ 2213 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 2214 - 44, 48, 52, 56, 60, 64}, 19}, 2215 - 2216 - /* IC */ 2217 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11}, 2218 - 2219 - /* ETSI */ 2220 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 2221 - 44, 48, 52, 56, 60, 64}, 21}, 2222 - 2223 - /* Spain. Change to ETSI. */ 2224 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 2225 - 44, 48, 52, 56, 60, 64}, 21}, 2226 - 2227 - /* France. Change to ETSI. */ 2228 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 2229 - 44, 48, 52, 56, 60, 64}, 21}, 2230 - 2231 - /* MKK */ 2232 - {{14, 36, 40, 44, 48, 52, 56, 60, 64}, 9}, 2233 - 2234 - /* MKK1 */ 2235 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 2236 - 40, 44, 48, 52, 56, 60, 64}, 22}, 2237 - 2238 - /* Israel. */ 2239 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 2240 - 44, 48, 52, 56, 60, 64}, 21}, 2241 - 2242 - /* For 11a , TELEC */ 2243 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 34, 38, 42, 46}, 17}, 2244 - 2245 - /* For Global Domain. 1-11 active, 12-14 passive. */ 2246 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14}, 2247 - 2248 - /* world wide 13: ch1~ch11 active, ch12~13 passive */ 2249 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13} 2250 - }; 2251 - 2252 - static void rtl8180_set_channel_map(u8 channel_plan, 2253 - struct ieee80211_device *ieee) 2254 - { 2255 - int i; 2256 - 2257 - ieee->MinPassiveChnlNum = MAX_CHANNEL_NUMBER+1; 2258 - ieee->IbssStartChnl = 0; 2259 - 2260 - switch (channel_plan) { 2261 - case COUNTRY_CODE_FCC: 2262 - case COUNTRY_CODE_IC: 2263 - case COUNTRY_CODE_ETSI: 2264 - case COUNTRY_CODE_SPAIN: 2265 - case COUNTRY_CODE_FRANCE: 2266 - case COUNTRY_CODE_MKK: 2267 - case COUNTRY_CODE_MKK1: 2268 - case COUNTRY_CODE_ISRAEL: 2269 - case COUNTRY_CODE_TELEC: 2270 - { 2271 - Dot11d_Init(ieee); 2272 - ieee->bGlobalDomain = false; 2273 - if (channel_plan_list[channel_plan].len != 0) { 2274 - /* Clear old channel map */ 2275 - memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map)); 2276 - /* Set new channel map */ 2277 - for (i = 0; i < channel_plan_list[channel_plan].len; i++) { 2278 - if (channel_plan_list[channel_plan].channel[i] <= 14) 2279 - GET_DOT11D_INFO(ieee)->channel_map[channel_plan_list[channel_plan].channel[i]] = 1; 2280 - } 2281 - } 2282 - break; 2283 - } 2284 - case COUNTRY_CODE_GLOBAL_DOMAIN: 2285 - { 2286 - GET_DOT11D_INFO(ieee)->bEnabled = false; 2287 - Dot11d_Reset(ieee); 2288 - ieee->bGlobalDomain = true; 2289 - break; 2290 - } 2291 - case COUNTRY_CODE_WORLD_WIDE_13_INDEX: 2292 - { 2293 - ieee->MinPassiveChnlNum = 12; 2294 - ieee->IbssStartChnl = 10; 2295 - break; 2296 - } 2297 - default: 2298 - { 2299 - Dot11d_Init(ieee); 2300 - ieee->bGlobalDomain = false; 2301 - memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map)); 2302 - for (i = 1; i <= 14; i++) 2303 - GET_DOT11D_INFO(ieee)->channel_map[i] = 1; 2304 - break; 2305 - } 2306 - } 2307 - } 2308 - 2309 - void GPIOChangeRFWorkItemCallBack(struct work_struct *work); 2310 - 2311 - static void rtl8180_statistics_init(struct stats *pstats) 2312 - { 2313 - memset(pstats, 0, sizeof(struct stats)); 2314 - } 2315 - 2316 - static void rtl8180_link_detect_init(struct link_detect_t *plink_detect) 2317 - { 2318 - memset(plink_detect, 0, sizeof(struct link_detect_t)); 2319 - plink_detect->slot_num = DEFAULT_SLOT_NUM; 2320 - } 2321 - 2322 - static void rtl8187se_eeprom_register_read(struct eeprom_93cx6 *eeprom) 2323 - { 2324 - struct net_device *dev = eeprom->data; 2325 - u8 reg = read_nic_byte(dev, EPROM_CMD); 2326 - 2327 - eeprom->reg_data_in = reg & RTL818X_EEPROM_CMD_WRITE; 2328 - eeprom->reg_data_out = reg & RTL818X_EEPROM_CMD_READ; 2329 - eeprom->reg_data_clock = reg & RTL818X_EEPROM_CMD_CK; 2330 - eeprom->reg_chip_select = reg & RTL818X_EEPROM_CMD_CS; 2331 - } 2332 - 2333 - static void rtl8187se_eeprom_register_write(struct eeprom_93cx6 *eeprom) 2334 - { 2335 - struct net_device *dev = eeprom->data; 2336 - u8 reg = 2 << 6; 2337 - 2338 - if (eeprom->reg_data_in) 2339 - reg |= RTL818X_EEPROM_CMD_WRITE; 2340 - if (eeprom->reg_data_out) 2341 - reg |= RTL818X_EEPROM_CMD_READ; 2342 - if (eeprom->reg_data_clock) 2343 - reg |= RTL818X_EEPROM_CMD_CK; 2344 - if (eeprom->reg_chip_select) 2345 - reg |= RTL818X_EEPROM_CMD_CS; 2346 - 2347 - write_nic_byte(dev, EPROM_CMD, reg); 2348 - read_nic_byte(dev, EPROM_CMD); 2349 - udelay(10); 2350 - } 2351 - 2352 - static short rtl8180_init(struct net_device *dev) 2353 - { 2354 - struct r8180_priv *priv = ieee80211_priv(dev); 2355 - u16 word; 2356 - u16 usValue; 2357 - u16 tmpu16; 2358 - int i, j; 2359 - struct eeprom_93cx6 eeprom; 2360 - u16 eeprom_val; 2361 - 2362 - eeprom.data = dev; 2363 - eeprom.register_read = rtl8187se_eeprom_register_read; 2364 - eeprom.register_write = rtl8187se_eeprom_register_write; 2365 - eeprom.width = PCI_EEPROM_WIDTH_93C46; 2366 - 2367 - eeprom_93cx6_read(&eeprom, EEPROM_COUNTRY_CODE>>1, &eeprom_val); 2368 - priv->channel_plan = eeprom_val & 0xFF; 2369 - if (priv->channel_plan > COUNTRY_CODE_GLOBAL_DOMAIN) { 2370 - netdev_err(dev, "rtl8180_init: Invalid channel plan! Set to default.\n"); 2371 - priv->channel_plan = 0; 2372 - } 2373 - 2374 - DMESG("Channel plan is %d\n", priv->channel_plan); 2375 - rtl8180_set_channel_map(priv->channel_plan, priv->ieee80211); 2376 - 2377 - /* FIXME: these constants are placed in a bad pleace. */ 2378 - priv->txbuffsize = 2048; /* 1024; */ 2379 - priv->txringcount = 32; /* 32; */ 2380 - priv->rxbuffersize = 2048; /* 1024; */ 2381 - priv->rxringcount = 64; /* 32; */ 2382 - priv->txbeaconcount = 2; 2383 - priv->rx_skb_complete = 1; 2384 - 2385 - priv->RFChangeInProgress = false; 2386 - priv->SetRFPowerStateInProgress = false; 2387 - priv->RFProgType = 0; 2388 - 2389 - priv->irq_enabled = 0; 2390 - 2391 - rtl8180_statistics_init(&priv->stats); 2392 - rtl8180_link_detect_init(&priv->link_detect); 2393 - 2394 - priv->ack_tx_to_ieee = 0; 2395 - priv->ieee80211->current_network.beacon_interval = 2396 - DEFAULT_BEACONINTERVAL; 2397 - priv->ieee80211->iw_mode = IW_MODE_INFRA; 2398 - priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN | 2399 - IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ | 2400 - IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE; 2401 - priv->ieee80211->active_scan = 1; 2402 - priv->ieee80211->rate = 110; /* 11 mbps */ 2403 - priv->ieee80211->modulation = IEEE80211_CCK_MODULATION; 2404 - priv->ieee80211->host_encrypt = 1; 2405 - priv->ieee80211->host_decrypt = 1; 2406 - priv->ieee80211->sta_wake_up = rtl8180_hw_wakeup; 2407 - priv->ieee80211->ps_request_tx_ack = rtl8180_rq_tx_ack; 2408 - priv->ieee80211->enter_sleep_state = rtl8180_hw_sleep; 2409 - priv->ieee80211->ps_is_queue_empty = rtl8180_is_tx_queue_empty; 2410 - 2411 - priv->hw_wep = hwwep; 2412 - priv->dev = dev; 2413 - priv->retry_rts = DEFAULT_RETRY_RTS; 2414 - priv->retry_data = DEFAULT_RETRY_DATA; 2415 - priv->RFChangeInProgress = false; 2416 - priv->SetRFPowerStateInProgress = false; 2417 - priv->RFProgType = 0; 2418 - priv->bInactivePs = true; /* false; */ 2419 - priv->ieee80211->bInactivePs = priv->bInactivePs; 2420 - priv->bSwRfProcessing = false; 2421 - priv->eRFPowerState = RF_OFF; 2422 - priv->RfOffReason = 0; 2423 - priv->led_strategy = SW_LED_MODE0; 2424 - priv->TxPollingTimes = 0; 2425 - priv->bLeisurePs = true; 2426 - priv->dot11PowerSaveMode = ACTIVE; 2427 - priv->AdMinCheckPeriod = 5; 2428 - priv->AdMaxCheckPeriod = 10; 2429 - priv->AdMaxRxSsThreshold = 30; /* 60->30 */ 2430 - priv->AdRxSsThreshold = 20; /* 50->20 */ 2431 - priv->AdCheckPeriod = priv->AdMinCheckPeriod; 2432 - priv->AdTickCount = 0; 2433 - priv->AdRxSignalStrength = -1; 2434 - priv->RegSwAntennaDiversityMechanism = 0; 2435 - priv->RegDefaultAntenna = 0; 2436 - priv->SignalStrength = 0; 2437 - priv->AdRxOkCnt = 0; 2438 - priv->CurrAntennaIndex = 0; 2439 - priv->AdRxSsBeforeSwitched = 0; 2440 - init_timer(&priv->SwAntennaDiversityTimer); 2441 - priv->SwAntennaDiversityTimer.data = (unsigned long)dev; 2442 - priv->SwAntennaDiversityTimer.function = 2443 - (void *)SwAntennaDiversityTimerCallback; 2444 - priv->bDigMechanism = true; 2445 - priv->InitialGain = 6; 2446 - priv->bXtalCalibration = false; 2447 - priv->XtalCal_Xin = 0; 2448 - priv->XtalCal_Xout = 0; 2449 - priv->bTxPowerTrack = false; 2450 - priv->ThermalMeter = 0; 2451 - priv->FalseAlarmRegValue = 0; 2452 - priv->RegDigOfdmFaUpTh = 0xc; /* Upper threshold of OFDM false alarm, 2453 - which is used in DIG. */ 2454 - priv->DIG_NumberFallbackVote = 0; 2455 - priv->DIG_NumberUpgradeVote = 0; 2456 - priv->LastSignalStrengthInPercent = 0; 2457 - priv->Stats_SignalStrength = 0; 2458 - priv->LastRxPktAntenna = 0; 2459 - priv->SignalQuality = 0; /* in 0-100 index. */ 2460 - priv->Stats_SignalQuality = 0; 2461 - priv->RecvSignalPower = 0; /* in dBm. */ 2462 - priv->Stats_RecvSignalPower = 0; 2463 - priv->AdMainAntennaRxOkCnt = 0; 2464 - priv->AdAuxAntennaRxOkCnt = 0; 2465 - priv->bHWAdSwitched = false; 2466 - priv->bRegHighPowerMechanism = true; 2467 - priv->RegHiPwrUpperTh = 77; 2468 - priv->RegHiPwrLowerTh = 75; 2469 - priv->RegRSSIHiPwrUpperTh = 70; 2470 - priv->RegRSSIHiPwrLowerTh = 20; 2471 - priv->bCurCCKPkt = false; 2472 - priv->UndecoratedSmoothedSS = -1; 2473 - priv->bToUpdateTxPwr = false; 2474 - priv->CurCCKRSSI = 0; 2475 - priv->RxPower = 0; 2476 - priv->RSSI = 0; 2477 - priv->NumTxOkTotal = 0; 2478 - priv->NumTxUnicast = 0; 2479 - priv->keepAliveLevel = DEFAULT_KEEP_ALIVE_LEVEL; 2480 - priv->CurrRetryCnt = 0; 2481 - priv->LastRetryCnt = 0; 2482 - priv->LastTxokCnt = 0; 2483 - priv->LastRxokCnt = 0; 2484 - priv->LastRetryRate = 0; 2485 - priv->bTryuping = 0; 2486 - priv->CurrTxRate = 0; 2487 - priv->CurrRetryRate = 0; 2488 - priv->TryupingCount = 0; 2489 - priv->TryupingCountNoData = 0; 2490 - priv->TryDownCountLowData = 0; 2491 - priv->LastTxOKBytes = 0; 2492 - priv->LastFailTxRate = 0; 2493 - priv->LastFailTxRateSS = 0; 2494 - priv->FailTxRateCount = 0; 2495 - priv->LastTxThroughput = 0; 2496 - priv->NumTxOkBytesTotal = 0; 2497 - priv->ForcedDataRate = 0; 2498 - priv->RegBModeGainStage = 1; 2499 - 2500 - priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0; 2501 - spin_lock_init(&priv->irq_th_lock); 2502 - spin_lock_init(&priv->tx_lock); 2503 - spin_lock_init(&priv->ps_lock); 2504 - spin_lock_init(&priv->rf_ps_lock); 2505 - sema_init(&priv->wx_sem, 1); 2506 - INIT_WORK(&priv->reset_wq, (void *)rtl8180_restart_wq); 2507 - INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq, 2508 - (void *)rtl8180_hw_wakeup_wq); 2509 - INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq, 2510 - (void *)rtl8180_hw_sleep_wq); 2511 - INIT_WORK(&priv->ieee80211->wmm_param_update_wq, 2512 - (void *)rtl8180_wmm_param_update); 2513 - INIT_DELAYED_WORK(&priv->ieee80211->rate_adapter_wq, 2514 - (void *)rtl8180_rate_adapter); 2515 - INIT_DELAYED_WORK(&priv->ieee80211->hw_dig_wq, 2516 - (void *)rtl8180_hw_dig_wq); 2517 - INIT_DELAYED_WORK(&priv->ieee80211->tx_pw_wq, 2518 - (void *)rtl8180_tx_pw_wq); 2519 - INIT_DELAYED_WORK(&priv->ieee80211->GPIOChangeRFWorkItem, 2520 - (void *) GPIOChangeRFWorkItemCallBack); 2521 - tasklet_init(&priv->irq_rx_tasklet, 2522 - (void(*)(unsigned long)) rtl8180_irq_rx_tasklet, 2523 - (unsigned long)priv); 2524 - 2525 - init_timer(&priv->watch_dog_timer); 2526 - priv->watch_dog_timer.data = (unsigned long)dev; 2527 - priv->watch_dog_timer.function = watch_dog_adaptive; 2528 - 2529 - init_timer(&priv->rateadapter_timer); 2530 - priv->rateadapter_timer.data = (unsigned long)dev; 2531 - priv->rateadapter_timer.function = timer_rate_adaptive; 2532 - priv->RateAdaptivePeriod = RATE_ADAPTIVE_TIMER_PERIOD; 2533 - priv->bEnhanceTxPwr = false; 2534 - 2535 - priv->ieee80211->softmac_hard_start_xmit = rtl8180_hard_start_xmit; 2536 - priv->ieee80211->set_chan = rtl8180_set_chan; 2537 - priv->ieee80211->link_change = rtl8180_link_change; 2538 - priv->ieee80211->softmac_data_hard_start_xmit = rtl8180_hard_data_xmit; 2539 - priv->ieee80211->data_hard_stop = rtl8180_data_hard_stop; 2540 - priv->ieee80211->data_hard_resume = rtl8180_data_hard_resume; 2541 - 2542 - priv->ieee80211->init_wmmparam_flag = 0; 2543 - 2544 - priv->ieee80211->start_send_beacons = rtl8180_start_tx_beacon; 2545 - priv->ieee80211->stop_send_beacons = rtl8180_beacon_tx_disable; 2546 - priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD; 2547 - 2548 - priv->ShortRetryLimit = 7; 2549 - priv->LongRetryLimit = 7; 2550 - priv->EarlyRxThreshold = 7; 2551 - 2552 - priv->TransmitConfig = (1<<TCR_DurProcMode_OFFSET) | 2553 - (7<<TCR_MXDMA_OFFSET) | 2554 - (priv->ShortRetryLimit<<TCR_SRL_OFFSET) | 2555 - (priv->LongRetryLimit<<TCR_LRL_OFFSET); 2556 - 2557 - priv->ReceiveConfig = RCR_AMF | RCR_ADF | RCR_ACF | 2558 - RCR_AB | RCR_AM | RCR_APM | 2559 - (7<<RCR_MXDMA_OFFSET) | 2560 - (priv->EarlyRxThreshold<<RCR_FIFO_OFFSET) | 2561 - (priv->EarlyRxThreshold == 7 ? 2562 - RCR_ONLYERLPKT : 0); 2563 - 2564 - priv->IntrMask = IMR_TMGDOK | IMR_TBDER | 2565 - IMR_THPDER | IMR_THPDOK | 2566 - IMR_TVODER | IMR_TVODOK | 2567 - IMR_TVIDER | IMR_TVIDOK | 2568 - IMR_TBEDER | IMR_TBEDOK | 2569 - IMR_TBKDER | IMR_TBKDOK | 2570 - IMR_RDU | 2571 - IMR_RER | IMR_ROK | 2572 - IMR_RQoSOK; 2573 - 2574 - priv->InitialGain = 6; 2575 - 2576 - DMESG("MAC controller is a RTL8187SE b/g"); 2577 - 2578 - priv->ieee80211->modulation |= IEEE80211_OFDM_MODULATION; 2579 - priv->ieee80211->short_slot = 1; 2580 - 2581 - eeprom_93cx6_read(&eeprom, EEPROM_SW_REVD_OFFSET, &usValue); 2582 - DMESG("usValue is %#hx\n", usValue); 2583 - /* 3Read AntennaDiversity */ 2584 - 2585 - /* SW Antenna Diversity. */ 2586 - priv->EEPROMSwAntennaDiversity = (usValue & EEPROM_SW_AD_MASK) == 2587 - EEPROM_SW_AD_ENABLE; 2588 - 2589 - /* Default Antenna to use. */ 2590 - priv->EEPROMDefaultAntenna1 = (usValue & EEPROM_DEF_ANT_MASK) == 2591 - EEPROM_DEF_ANT_1; 2592 - 2593 - if (priv->RegSwAntennaDiversityMechanism == 0) /* Auto */ 2594 - /* 0: default from EEPROM. */ 2595 - priv->bSwAntennaDiverity = priv->EEPROMSwAntennaDiversity; 2596 - else 2597 - /* 1:disable antenna diversity, 2: enable antenna diversity. */ 2598 - priv->bSwAntennaDiverity = 2599 - priv->RegSwAntennaDiversityMechanism == 2; 2600 - 2601 - if (priv->RegDefaultAntenna == 0) 2602 - /* 0: default from EEPROM. */ 2603 - priv->bDefaultAntenna1 = priv->EEPROMDefaultAntenna1; 2604 - else 2605 - /* 1: main, 2: aux. */ 2606 - priv->bDefaultAntenna1 = priv->RegDefaultAntenna == 2; 2607 - 2608 - priv->plcp_preamble_mode = 2; 2609 - /* the eeprom type is stored in RCR register bit #6 */ 2610 - if (RCR_9356SEL & read_nic_dword(dev, RCR)) 2611 - priv->epromtype = EPROM_93c56; 2612 - else 2613 - priv->epromtype = EPROM_93c46; 2614 - 2615 - eeprom_93cx6_multiread(&eeprom, 0x7, (__le16 *) 2616 - dev->dev_addr, 3); 2617 - 2618 - for (i = 1, j = 0; i < 14; i += 2, j++) { 2619 - eeprom_93cx6_read(&eeprom, EPROM_TXPW_CH1_2 + j, &word); 2620 - priv->chtxpwr[i] = word & 0xff; 2621 - priv->chtxpwr[i+1] = (word & 0xff00)>>8; 2622 - } 2623 - for (i = 1, j = 0; i < 14; i += 2, j++) { 2624 - eeprom_93cx6_read(&eeprom, EPROM_TXPW_OFDM_CH1_2 + j, &word); 2625 - priv->chtxpwr_ofdm[i] = word & 0xff; 2626 - priv->chtxpwr_ofdm[i+1] = (word & 0xff00) >> 8; 2627 - } 2628 - 2629 - /* 3Read crystal calibration and thermal meter indication on 87SE. */ 2630 - eeprom_93cx6_read(&eeprom, EEPROM_RSV>>1, &tmpu16); 2631 - 2632 - /* Crystal calibration for Xin and Xout resp. */ 2633 - priv->XtalCal_Xout = tmpu16 & EEPROM_XTAL_CAL_XOUT_MASK; 2634 - priv->XtalCal_Xin = (tmpu16 & EEPROM_XTAL_CAL_XIN_MASK) >> 4; 2635 - if ((tmpu16 & EEPROM_XTAL_CAL_ENABLE) >> 12) 2636 - priv->bXtalCalibration = true; 2637 - 2638 - /* Thermal meter reference indication. */ 2639 - priv->ThermalMeter = (u8)((tmpu16 & EEPROM_THERMAL_METER_MASK) >> 8); 2640 - if ((tmpu16 & EEPROM_THERMAL_METER_ENABLE) >> 13) 2641 - priv->bTxPowerTrack = true; 2642 - 2643 - priv->rf_sleep = rtl8225z4_rf_sleep; 2644 - priv->rf_wakeup = rtl8225z4_rf_wakeup; 2645 - DMESGW("**PLEASE** REPORT SUCCESSFUL/UNSUCCESSFUL TO Realtek!"); 2646 - 2647 - priv->rf_close = rtl8225z2_rf_close; 2648 - priv->rf_init = rtl8225z2_rf_init; 2649 - priv->rf_set_chan = rtl8225z2_rf_set_chan; 2650 - priv->rf_set_sens = NULL; 2651 - 2652 - if (0 != alloc_rx_desc_ring(dev, priv->rxbuffersize, priv->rxringcount)) 2653 - return -ENOMEM; 2654 - 2655 - if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount, 2656 - TX_MANAGEPRIORITY_RING_ADDR)) 2657 - return -ENOMEM; 2658 - 2659 - if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount, 2660 - TX_BKPRIORITY_RING_ADDR)) 2661 - return -ENOMEM; 2662 - 2663 - if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount, 2664 - TX_BEPRIORITY_RING_ADDR)) 2665 - return -ENOMEM; 2666 - 2667 - if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount, 2668 - TX_VIPRIORITY_RING_ADDR)) 2669 - return -ENOMEM; 2670 - 2671 - if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount, 2672 - TX_VOPRIORITY_RING_ADDR)) 2673 - return -ENOMEM; 2674 - 2675 - if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount, 2676 - TX_HIGHPRIORITY_RING_ADDR)) 2677 - return -ENOMEM; 2678 - 2679 - if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txbeaconcount, 2680 - TX_BEACON_RING_ADDR)) 2681 - return -ENOMEM; 2682 - 2683 - if (request_irq(dev->irq, rtl8180_interrupt, 2684 - IRQF_SHARED, dev->name, dev)) { 2685 - DMESGE("Error allocating IRQ %d", dev->irq); 2686 - return -1; 2687 - } else { 2688 - priv->irq = dev->irq; 2689 - DMESG("IRQ %d", dev->irq); 2690 - } 2691 - 2692 - return 0; 2693 - } 2694 - 2695 - void rtl8180_no_hw_wep(struct net_device *dev) 2696 - { 2697 - } 2698 - 2699 - void rtl8180_set_hw_wep(struct net_device *dev) 2700 - { 2701 - struct r8180_priv *priv = ieee80211_priv(dev); 2702 - u8 pgreg; 2703 - u8 security; 2704 - u32 key0_word4; 2705 - 2706 - pgreg = read_nic_byte(dev, PGSELECT); 2707 - write_nic_byte(dev, PGSELECT, pgreg & ~(1<<PGSELECT_PG_SHIFT)); 2708 - 2709 - key0_word4 = read_nic_dword(dev, KEY0+4+4+4); 2710 - key0_word4 &= ~0xff; 2711 - key0_word4 |= priv->key0[3] & 0xff; 2712 - write_nic_dword(dev, KEY0, (priv->key0[0])); 2713 - write_nic_dword(dev, KEY0+4, (priv->key0[1])); 2714 - write_nic_dword(dev, KEY0+4+4, (priv->key0[2])); 2715 - write_nic_dword(dev, KEY0+4+4+4, (key0_word4)); 2716 - 2717 - security = read_nic_byte(dev, SECURITY); 2718 - security |= (1<<SECURITY_WEP_TX_ENABLE_SHIFT); 2719 - security |= (1<<SECURITY_WEP_RX_ENABLE_SHIFT); 2720 - security &= ~SECURITY_ENCRYP_MASK; 2721 - security |= (SECURITY_ENCRYP_104<<SECURITY_ENCRYP_SHIFT); 2722 - 2723 - write_nic_byte(dev, SECURITY, security); 2724 - 2725 - DMESG("key %x %x %x %x", read_nic_dword(dev, KEY0+4+4+4), 2726 - read_nic_dword(dev, KEY0+4+4), read_nic_dword(dev, KEY0+4), 2727 - read_nic_dword(dev, KEY0)); 2728 - } 2729 - 2730 - 2731 - void rtl8185_rf_pins_enable(struct net_device *dev) 2732 - { 2733 - write_nic_word(dev, RFPinsEnable, 0x1fff); /* | tmp); */ 2734 - } 2735 - 2736 - void rtl8185_set_anaparam2(struct net_device *dev, u32 a) 2737 - { 2738 - u8 conf3; 2739 - 2740 - rtl8180_set_mode(dev, EPROM_CMD_CONFIG); 2741 - 2742 - conf3 = read_nic_byte(dev, CONFIG3); 2743 - write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT)); 2744 - write_nic_dword(dev, ANAPARAM2, a); 2745 - 2746 - conf3 = read_nic_byte(dev, CONFIG3); 2747 - write_nic_byte(dev, CONFIG3, conf3 & ~(1<<CONFIG3_ANAPARAM_W_SHIFT)); 2748 - rtl8180_set_mode(dev, EPROM_CMD_NORMAL); 2749 - } 2750 - 2751 - void rtl8180_set_anaparam(struct net_device *dev, u32 a) 2752 - { 2753 - u8 conf3; 2754 - 2755 - rtl8180_set_mode(dev, EPROM_CMD_CONFIG); 2756 - 2757 - conf3 = read_nic_byte(dev, CONFIG3); 2758 - write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT)); 2759 - write_nic_dword(dev, ANAPARAM, a); 2760 - 2761 - conf3 = read_nic_byte(dev, CONFIG3); 2762 - write_nic_byte(dev, CONFIG3, conf3 & ~(1<<CONFIG3_ANAPARAM_W_SHIFT)); 2763 - rtl8180_set_mode(dev, EPROM_CMD_NORMAL); 2764 - } 2765 - 2766 - void rtl8185_tx_antenna(struct net_device *dev, u8 ant) 2767 - { 2768 - write_nic_byte(dev, TX_ANTENNA, ant); 2769 - force_pci_posting(dev); 2770 - mdelay(1); 2771 - } 2772 - 2773 - static void rtl8185_write_phy(struct net_device *dev, u8 adr, u32 data) 2774 - { 2775 - u32 phyw; 2776 - 2777 - adr |= 0x80; 2778 - 2779 - phyw = ((data<<8) | adr); 2780 - 2781 - /* Note: we must write 0xff7c after 0x7d-0x7f to write BB register. */ 2782 - write_nic_byte(dev, 0x7f, ((phyw & 0xff000000) >> 24)); 2783 - write_nic_byte(dev, 0x7e, ((phyw & 0x00ff0000) >> 16)); 2784 - write_nic_byte(dev, 0x7d, ((phyw & 0x0000ff00) >> 8)); 2785 - write_nic_byte(dev, 0x7c, ((phyw & 0x000000ff))); 2786 - } 2787 - 2788 - inline void write_phy_ofdm(struct net_device *dev, u8 adr, u32 data) 2789 - { 2790 - data = data & 0xff; 2791 - rtl8185_write_phy(dev, adr, data); 2792 - } 2793 - 2794 - void write_phy_cck(struct net_device *dev, u8 adr, u32 data) 2795 - { 2796 - data = data & 0xff; 2797 - rtl8185_write_phy(dev, adr, data | 0x10000); 2798 - } 2799 - 2800 - /* 2801 - * This configures registers for beacon tx and enables it via 2802 - * rtl8180_beacon_tx_enable(). rtl8180_beacon_tx_disable() might 2803 - * be used to stop beacon transmission 2804 - */ 2805 - void rtl8180_start_tx_beacon(struct net_device *dev) 2806 - { 2807 - u16 word; 2808 - 2809 - DMESG("Enabling beacon TX"); 2810 - rtl8180_prepare_beacon(dev); 2811 - rtl8180_irq_disable(dev); 2812 - rtl8180_beacon_tx_enable(dev); 2813 - 2814 - word = read_nic_word(dev, AtimWnd) & ~AtimWnd_AtimWnd; 2815 - write_nic_word(dev, AtimWnd, word); /* word |= */ 2816 - 2817 - word = read_nic_word(dev, BintrItv); 2818 - word &= ~BintrItv_BintrItv; 2819 - word |= 1000; /* priv->ieee80211->current_network.beacon_interval * 2820 - * ((priv->txbeaconcount > 1)?(priv->txbeaconcount-1):1); 2821 - * FIXME: check if correct ^^ worked with 0x3e8; 2822 - */ 2823 - write_nic_word(dev, BintrItv, word); 2824 - 2825 - rtl8180_set_mode(dev, EPROM_CMD_NORMAL); 2826 - 2827 - rtl8185b_irq_enable(dev); 2828 - } 2829 - 2830 - static struct net_device_stats *rtl8180_stats(struct net_device *dev) 2831 - { 2832 - struct r8180_priv *priv = ieee80211_priv(dev); 2833 - 2834 - return &priv->ieee80211->stats; 2835 - } 2836 - 2837 - /* 2838 - * Change current and default preamble mode. 2839 - */ 2840 - static bool MgntActSet_802_11_PowerSaveMode(struct r8180_priv *priv, 2841 - enum rt_ps_mode rtPsMode) 2842 - { 2843 - /* Currently, we do not change power save mode on IBSS mode. */ 2844 - if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) 2845 - return false; 2846 - 2847 - priv->ieee80211->ps = rtPsMode; 2848 - 2849 - return true; 2850 - } 2851 - 2852 - static void LeisurePSEnter(struct r8180_priv *priv) 2853 - { 2854 - if (priv->bLeisurePs) 2855 - if (priv->ieee80211->ps == IEEE80211_PS_DISABLED) 2856 - /* IEEE80211_PS_ENABLE */ 2857 - MgntActSet_802_11_PowerSaveMode(priv, 2858 - IEEE80211_PS_MBCAST | IEEE80211_PS_UNICAST); 2859 - } 2860 - 2861 - static void LeisurePSLeave(struct r8180_priv *priv) 2862 - { 2863 - if (priv->bLeisurePs) 2864 - if (priv->ieee80211->ps != IEEE80211_PS_DISABLED) 2865 - MgntActSet_802_11_PowerSaveMode( 2866 - priv, IEEE80211_PS_DISABLED); 2867 - } 2868 - 2869 - void rtl8180_hw_wakeup_wq(struct work_struct *work) 2870 - { 2871 - struct delayed_work *dwork = to_delayed_work(work); 2872 - struct ieee80211_device *ieee = container_of( 2873 - dwork, struct ieee80211_device, hw_wakeup_wq); 2874 - struct net_device *dev = ieee->dev; 2875 - 2876 - rtl8180_hw_wakeup(dev); 2877 - } 2878 - 2879 - void rtl8180_hw_sleep_wq(struct work_struct *work) 2880 - { 2881 - struct delayed_work *dwork = to_delayed_work(work); 2882 - struct ieee80211_device *ieee = container_of( 2883 - dwork, struct ieee80211_device, hw_sleep_wq); 2884 - struct net_device *dev = ieee->dev; 2885 - 2886 - rtl8180_hw_sleep_down(dev); 2887 - } 2888 - 2889 - static void MgntLinkKeepAlive(struct r8180_priv *priv) 2890 - { 2891 - if (priv->keepAliveLevel == 0) 2892 - return; 2893 - 2894 - if (priv->ieee80211->state == IEEE80211_LINKED) { 2895 - /* 2896 - * Keep-Alive. 2897 - */ 2898 - 2899 - if ((priv->keepAliveLevel == 2) || 2900 - (priv->link_detect.last_num_tx_unicast == 2901 - priv->NumTxUnicast && 2902 - priv->link_detect.last_num_rx_unicast == 2903 - priv->ieee80211->NumRxUnicast) 2904 - ) { 2905 - priv->link_detect.idle_count++; 2906 - 2907 - /* 2908 - * Send a Keep-Alive packet packet to AP if we had 2909 - * been idle for a while. 2910 - */ 2911 - if (priv->link_detect.idle_count >= 2912 - KEEP_ALIVE_INTERVAL / 2913 - CHECK_FOR_HANG_PERIOD - 1) { 2914 - priv->link_detect.idle_count = 0; 2915 - ieee80211_sta_ps_send_null_frame( 2916 - priv->ieee80211, false); 2917 - } 2918 - } else { 2919 - priv->link_detect.idle_count = 0; 2920 - } 2921 - priv->link_detect.last_num_tx_unicast = priv->NumTxUnicast; 2922 - priv->link_detect.last_num_rx_unicast = 2923 - priv->ieee80211->NumRxUnicast; 2924 - } 2925 - } 2926 - 2927 - void rtl8180_watch_dog(struct net_device *dev) 2928 - { 2929 - struct r8180_priv *priv = ieee80211_priv(dev); 2930 - bool bEnterPS = false; 2931 - bool bBusyTraffic = false; 2932 - u32 TotalRxNum = 0; 2933 - u16 SlotIndex = 0; 2934 - u16 i = 0; 2935 - if (priv->ieee80211->actscanning == false) { 2936 - if ((priv->ieee80211->iw_mode != IW_MODE_ADHOC) && 2937 - (priv->ieee80211->state == IEEE80211_NOLINK) && 2938 - (priv->ieee80211->beinretry == false) && 2939 - (priv->eRFPowerState == RF_ON)) 2940 - IPSEnter(dev); 2941 - } 2942 - if ((priv->ieee80211->state == IEEE80211_LINKED) && 2943 - (priv->ieee80211->iw_mode == IW_MODE_INFRA)) { 2944 - SlotIndex = (priv->link_detect.slot_index++) % 2945 - priv->link_detect.slot_num; 2946 - 2947 - priv->link_detect.rx_frame_num[SlotIndex] = 2948 - priv->ieee80211->NumRxDataInPeriod + 2949 - priv->ieee80211->NumRxBcnInPeriod; 2950 - 2951 - for (i = 0; i < priv->link_detect.slot_num; i++) 2952 - TotalRxNum += priv->link_detect.rx_frame_num[i]; 2953 - 2954 - if (TotalRxNum == 0) { 2955 - priv->ieee80211->state = IEEE80211_ASSOCIATING; 2956 - queue_work(priv->ieee80211->wq, 2957 - &priv->ieee80211->associate_procedure_wq); 2958 - } 2959 - } 2960 - 2961 - MgntLinkKeepAlive(priv); 2962 - 2963 - LeisurePSLeave(priv); 2964 - 2965 - if (priv->ieee80211->state == IEEE80211_LINKED) { 2966 - priv->link_detect.num_rx_ok_in_period = 2967 - priv->ieee80211->NumRxDataInPeriod; 2968 - if (priv->link_detect.num_rx_ok_in_period > 666 || 2969 - priv->link_detect.num_tx_ok_in_period > 666) { 2970 - bBusyTraffic = true; 2971 - } 2972 - if ((priv->link_detect.num_rx_ok_in_period + 2973 - priv->link_detect.num_tx_ok_in_period > 8) 2974 - || (priv->link_detect.num_rx_ok_in_period > 2)) { 2975 - bEnterPS = false; 2976 - } else 2977 - bEnterPS = true; 2978 - 2979 - if (bEnterPS) 2980 - LeisurePSEnter(priv); 2981 - else 2982 - LeisurePSLeave(priv); 2983 - } else 2984 - LeisurePSLeave(priv); 2985 - priv->link_detect.b_busy_traffic = bBusyTraffic; 2986 - priv->link_detect.num_rx_ok_in_period = 0; 2987 - priv->link_detect.num_tx_ok_in_period = 0; 2988 - priv->ieee80211->NumRxDataInPeriod = 0; 2989 - priv->ieee80211->NumRxBcnInPeriod = 0; 2990 - } 2991 - 2992 - static int _rtl8180_up(struct net_device *dev) 2993 - { 2994 - struct r8180_priv *priv = ieee80211_priv(dev); 2995 - 2996 - priv->up = 1; 2997 - 2998 - DMESG("Bringing up iface"); 2999 - rtl8185b_adapter_start(dev); 3000 - rtl8185b_rx_enable(dev); 3001 - rtl8185b_tx_enable(dev); 3002 - if (priv->bInactivePs) { 3003 - if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) 3004 - IPSLeave(dev); 3005 - } 3006 - timer_rate_adaptive((unsigned long)dev); 3007 - watch_dog_adaptive((unsigned long)dev); 3008 - if (priv->bSwAntennaDiverity) 3009 - SwAntennaDiversityTimerCallback(dev); 3010 - ieee80211_softmac_start_protocol(priv->ieee80211); 3011 - return 0; 3012 - } 3013 - 3014 - static int rtl8180_open(struct net_device *dev) 3015 - { 3016 - struct r8180_priv *priv = ieee80211_priv(dev); 3017 - int ret; 3018 - 3019 - down(&priv->wx_sem); 3020 - ret = rtl8180_up(dev); 3021 - up(&priv->wx_sem); 3022 - return ret; 3023 - } 3024 - 3025 - int rtl8180_up(struct net_device *dev) 3026 - { 3027 - struct r8180_priv *priv = ieee80211_priv(dev); 3028 - 3029 - if (priv->up == 1) 3030 - return -1; 3031 - 3032 - return _rtl8180_up(dev); 3033 - } 3034 - 3035 - static int rtl8180_close(struct net_device *dev) 3036 - { 3037 - struct r8180_priv *priv = ieee80211_priv(dev); 3038 - int ret; 3039 - 3040 - down(&priv->wx_sem); 3041 - ret = rtl8180_down(dev); 3042 - up(&priv->wx_sem); 3043 - 3044 - return ret; 3045 - } 3046 - 3047 - int rtl8180_down(struct net_device *dev) 3048 - { 3049 - struct r8180_priv *priv = ieee80211_priv(dev); 3050 - 3051 - if (priv->up == 0) 3052 - return -1; 3053 - 3054 - priv->up = 0; 3055 - 3056 - ieee80211_softmac_stop_protocol(priv->ieee80211); 3057 - /* FIXME */ 3058 - if (!netif_queue_stopped(dev)) 3059 - netif_stop_queue(dev); 3060 - rtl8180_rtx_disable(dev); 3061 - rtl8180_irq_disable(dev); 3062 - del_timer_sync(&priv->watch_dog_timer); 3063 - del_timer_sync(&priv->rateadapter_timer); 3064 - cancel_delayed_work(&priv->ieee80211->rate_adapter_wq); 3065 - cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq); 3066 - cancel_delayed_work(&priv->ieee80211->hw_sleep_wq); 3067 - cancel_delayed_work(&priv->ieee80211->hw_dig_wq); 3068 - cancel_delayed_work(&priv->ieee80211->tx_pw_wq); 3069 - del_timer_sync(&priv->SwAntennaDiversityTimer); 3070 - SetZebraRFPowerState8185(dev, RF_OFF); 3071 - memset(&priv->ieee80211->current_network, 3072 - 0, sizeof(struct ieee80211_network)); 3073 - priv->ieee80211->state = IEEE80211_NOLINK; 3074 - return 0; 3075 - } 3076 - 3077 - void rtl8180_restart_wq(struct work_struct *work) 3078 - { 3079 - struct r8180_priv *priv = container_of( 3080 - work, struct r8180_priv, reset_wq); 3081 - struct net_device *dev = priv->dev; 3082 - 3083 - down(&priv->wx_sem); 3084 - 3085 - rtl8180_commit(dev); 3086 - 3087 - up(&priv->wx_sem); 3088 - } 3089 - 3090 - static void rtl8180_restart(struct net_device *dev) 3091 - { 3092 - struct r8180_priv *priv = ieee80211_priv(dev); 3093 - 3094 - schedule_work(&priv->reset_wq); 3095 - } 3096 - 3097 - void rtl8180_commit(struct net_device *dev) 3098 - { 3099 - struct r8180_priv *priv = ieee80211_priv(dev); 3100 - 3101 - if (priv->up == 0) 3102 - return; 3103 - 3104 - del_timer_sync(&priv->watch_dog_timer); 3105 - del_timer_sync(&priv->rateadapter_timer); 3106 - cancel_delayed_work(&priv->ieee80211->rate_adapter_wq); 3107 - cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq); 3108 - cancel_delayed_work(&priv->ieee80211->hw_sleep_wq); 3109 - cancel_delayed_work(&priv->ieee80211->hw_dig_wq); 3110 - cancel_delayed_work(&priv->ieee80211->tx_pw_wq); 3111 - del_timer_sync(&priv->SwAntennaDiversityTimer); 3112 - ieee80211_softmac_stop_protocol(priv->ieee80211); 3113 - rtl8180_irq_disable(dev); 3114 - rtl8180_rtx_disable(dev); 3115 - _rtl8180_up(dev); 3116 - } 3117 - 3118 - static void r8180_set_multicast(struct net_device *dev) 3119 - { 3120 - struct r8180_priv *priv = ieee80211_priv(dev); 3121 - short promisc; 3122 - 3123 - promisc = (dev->flags & IFF_PROMISC) ? 1 : 0; 3124 - 3125 - if (promisc != priv->promisc) 3126 - rtl8180_restart(dev); 3127 - 3128 - priv->promisc = promisc; 3129 - } 3130 - 3131 - static int r8180_set_mac_adr(struct net_device *dev, void *mac) 3132 - { 3133 - struct r8180_priv *priv = ieee80211_priv(dev); 3134 - struct sockaddr *addr = mac; 3135 - 3136 - down(&priv->wx_sem); 3137 - 3138 - memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); 3139 - 3140 - if (priv->ieee80211->iw_mode == IW_MODE_MASTER) 3141 - memcpy(priv->ieee80211->current_network.bssid, 3142 - dev->dev_addr, ETH_ALEN); 3143 - 3144 - if (priv->up) { 3145 - rtl8180_down(dev); 3146 - rtl8180_up(dev); 3147 - } 3148 - 3149 - up(&priv->wx_sem); 3150 - 3151 - return 0; 3152 - } 3153 - 3154 - /* based on ipw2200 driver */ 3155 - static int rtl8180_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 3156 - { 3157 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 3158 - struct iwreq *wrq = (struct iwreq *) rq; 3159 - int ret = -1; 3160 - 3161 - switch (cmd) { 3162 - case RTL_IOCTL_WPA_SUPPLICANT: 3163 - ret = ieee80211_wpa_supplicant_ioctl( 3164 - priv->ieee80211, &wrq->u.data); 3165 - return ret; 3166 - default: 3167 - return -EOPNOTSUPP; 3168 - } 3169 - 3170 - return -EOPNOTSUPP; 3171 - } 3172 - 3173 - static const struct net_device_ops rtl8180_netdev_ops = { 3174 - .ndo_open = rtl8180_open, 3175 - .ndo_stop = rtl8180_close, 3176 - .ndo_get_stats = rtl8180_stats, 3177 - .ndo_tx_timeout = rtl8180_restart, 3178 - .ndo_do_ioctl = rtl8180_ioctl, 3179 - .ndo_set_rx_mode = r8180_set_multicast, 3180 - .ndo_set_mac_address = r8180_set_mac_adr, 3181 - .ndo_validate_addr = eth_validate_addr, 3182 - .ndo_change_mtu = eth_change_mtu, 3183 - .ndo_start_xmit = ieee80211_rtl_xmit, 3184 - }; 3185 - 3186 - static int rtl8180_pci_probe(struct pci_dev *pdev, 3187 - const struct pci_device_id *id) 3188 - { 3189 - unsigned long ioaddr = 0; 3190 - struct net_device *dev = NULL; 3191 - struct r8180_priv *priv = NULL; 3192 - u8 unit = 0; 3193 - int ret = -ENODEV; 3194 - 3195 - unsigned long pmem_start, pmem_len, pmem_flags; 3196 - 3197 - DMESG("Configuring chip resources"); 3198 - 3199 - if (pci_enable_device(pdev)) { 3200 - DMESG("Failed to enable PCI device"); 3201 - return -EIO; 3202 - } 3203 - 3204 - pci_set_master(pdev); 3205 - pci_set_dma_mask(pdev, 0xffffff00ULL); 3206 - pci_set_consistent_dma_mask(pdev, 0xffffff00ULL); 3207 - dev = alloc_ieee80211(sizeof(struct r8180_priv)); 3208 - if (!dev) { 3209 - ret = -ENOMEM; 3210 - goto fail_free; 3211 - } 3212 - priv = ieee80211_priv(dev); 3213 - priv->ieee80211 = netdev_priv(dev); 3214 - 3215 - pci_set_drvdata(pdev, dev); 3216 - SET_NETDEV_DEV(dev, &pdev->dev); 3217 - 3218 - priv = ieee80211_priv(dev); 3219 - priv->pdev = pdev; 3220 - 3221 - pmem_start = pci_resource_start(pdev, 1); 3222 - pmem_len = pci_resource_len(pdev, 1); 3223 - pmem_flags = pci_resource_flags(pdev, 1); 3224 - 3225 - if (!(pmem_flags & IORESOURCE_MEM)) { 3226 - DMESG("region #1 not a MMIO resource, aborting"); 3227 - goto fail; 3228 - } 3229 - 3230 - if (!request_mem_region(pmem_start, pmem_len, RTL8180_MODULE_NAME)) { 3231 - DMESG("request_mem_region failed!"); 3232 - goto fail; 3233 - } 3234 - 3235 - ioaddr = (unsigned long)ioremap_nocache(pmem_start, pmem_len); 3236 - if (ioaddr == (unsigned long)NULL) { 3237 - DMESG("ioremap failed!"); 3238 - goto fail1; 3239 - } 3240 - 3241 - dev->mem_start = ioaddr; /* shared mem start */ 3242 - dev->mem_end = ioaddr + pci_resource_len(pdev, 0); /* shared mem end */ 3243 - 3244 - pci_read_config_byte(pdev, 0x05, &unit); 3245 - pci_write_config_byte(pdev, 0x05, unit & (~0x04)); 3246 - 3247 - dev->irq = pdev->irq; 3248 - priv->irq = 0; 3249 - 3250 - dev->netdev_ops = &rtl8180_netdev_ops; 3251 - dev->wireless_handlers = &r8180_wx_handlers_def; 3252 - 3253 - dev->type = ARPHRD_ETHER; 3254 - dev->watchdog_timeo = HZ*3; 3255 - 3256 - if (dev_alloc_name(dev, ifname) < 0) { 3257 - DMESG("Oops: devname already taken! Trying wlan%%d...\n"); 3258 - strcpy(ifname, "wlan%d"); 3259 - dev_alloc_name(dev, ifname); 3260 - } 3261 - 3262 - if (rtl8180_init(dev) != 0) { 3263 - DMESG("Initialization failed"); 3264 - goto fail1; 3265 - } 3266 - 3267 - netif_carrier_off(dev); 3268 - 3269 - if (register_netdev(dev)) 3270 - goto fail1; 3271 - 3272 - rtl8180_proc_init_one(dev); 3273 - 3274 - DMESG("Driver probe completed\n"); 3275 - return 0; 3276 - fail1: 3277 - if (dev->mem_start != (unsigned long)NULL) { 3278 - iounmap((void __iomem *)dev->mem_start); 3279 - release_mem_region(pci_resource_start(pdev, 1), 3280 - pci_resource_len(pdev, 1)); 3281 - } 3282 - fail: 3283 - if (dev) { 3284 - if (priv->irq) { 3285 - free_irq(dev->irq, dev); 3286 - dev->irq = 0; 3287 - } 3288 - free_ieee80211(dev); 3289 - } 3290 - 3291 - fail_free: 3292 - pci_disable_device(pdev); 3293 - 3294 - DMESG("wlan driver load failed\n"); 3295 - return ret; 3296 - } 3297 - 3298 - static void rtl8180_pci_remove(struct pci_dev *pdev) 3299 - { 3300 - struct r8180_priv *priv; 3301 - struct net_device *dev = pci_get_drvdata(pdev); 3302 - 3303 - if (dev) { 3304 - unregister_netdev(dev); 3305 - 3306 - priv = ieee80211_priv(dev); 3307 - 3308 - rtl8180_proc_remove_one(dev); 3309 - rtl8180_down(dev); 3310 - priv->rf_close(dev); 3311 - rtl8180_reset(dev); 3312 - mdelay(10); 3313 - 3314 - if (priv->irq) { 3315 - DMESG("Freeing irq %d", dev->irq); 3316 - free_irq(dev->irq, dev); 3317 - priv->irq = 0; 3318 - } 3319 - 3320 - free_rx_desc_ring(dev); 3321 - free_tx_desc_rings(dev); 3322 - 3323 - if (dev->mem_start != (unsigned long)NULL) { 3324 - iounmap((void __iomem *)dev->mem_start); 3325 - release_mem_region(pci_resource_start(pdev, 1), 3326 - pci_resource_len(pdev, 1)); 3327 - } 3328 - 3329 - free_ieee80211(dev); 3330 - } 3331 - pci_disable_device(pdev); 3332 - 3333 - DMESG("wlan driver removed\n"); 3334 - } 3335 - 3336 - static int __init rtl8180_pci_module_init(void) 3337 - { 3338 - int ret; 3339 - 3340 - ret = ieee80211_crypto_init(); 3341 - if (ret) { 3342 - pr_err("ieee80211_crypto_init() failed %d\n", ret); 3343 - return ret; 3344 - } 3345 - ret = ieee80211_crypto_tkip_init(); 3346 - if (ret) { 3347 - pr_err("ieee80211_crypto_tkip_init() failed %d\n", ret); 3348 - return ret; 3349 - } 3350 - ret = ieee80211_crypto_ccmp_init(); 3351 - if (ret) { 3352 - pr_err("ieee80211_crypto_ccmp_init() failed %d\n", ret); 3353 - return ret; 3354 - } 3355 - ret = ieee80211_crypto_wep_init(); 3356 - if (ret) { 3357 - pr_err("ieee80211_crypto_wep_init() failed %d\n", ret); 3358 - return ret; 3359 - } 3360 - 3361 - pr_info("\nLinux kernel driver for RTL8180 / RTL8185 based WLAN cards\n"); 3362 - pr_info("Copyright (c) 2004-2005, Andrea Merello\n"); 3363 - DMESG("Initializing module"); 3364 - DMESG("Wireless extensions version %d", WIRELESS_EXT); 3365 - rtl8180_proc_module_init(); 3366 - 3367 - if (pci_register_driver(&rtl8180_pci_driver)) { 3368 - DMESG("No device found"); 3369 - return -ENODEV; 3370 - } 3371 - return 0; 3372 - } 3373 - 3374 - static void __exit rtl8180_pci_module_exit(void) 3375 - { 3376 - pci_unregister_driver(&rtl8180_pci_driver); 3377 - rtl8180_proc_module_remove(); 3378 - ieee80211_crypto_tkip_exit(); 3379 - ieee80211_crypto_ccmp_exit(); 3380 - ieee80211_crypto_wep_exit(); 3381 - ieee80211_crypto_deinit(); 3382 - DMESG("Exiting"); 3383 - } 3384 - 3385 - static void rtl8180_try_wake_queue(struct net_device *dev, int pri) 3386 - { 3387 - unsigned long flags; 3388 - short enough_desc; 3389 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 3390 - 3391 - spin_lock_irqsave(&priv->tx_lock, flags); 3392 - enough_desc = check_nic_enought_desc(dev, pri); 3393 - spin_unlock_irqrestore(&priv->tx_lock, flags); 3394 - 3395 - if (enough_desc) 3396 - ieee80211_rtl_wake_queue(priv->ieee80211); 3397 - } 3398 - 3399 - static void rtl8180_tx_isr(struct net_device *dev, int pri, short error) 3400 - { 3401 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 3402 - u32 *tail; /* tail virtual addr */ 3403 - u32 *head; /* head virtual addr */ 3404 - u32 *begin; /* start of ring virtual addr */ 3405 - u32 *nicv; /* nic pointer virtual addr */ 3406 - u32 nic; /* nic pointer physical addr */ 3407 - u32 nicbegin; /* start of ring physical addr */ 3408 - unsigned long flag; 3409 - /* physical addr are ok on 32 bits since we set DMA mask */ 3410 - int offs; 3411 - int j, i; 3412 - int hd; 3413 - if (error) 3414 - priv->stats.txretry++; 3415 - spin_lock_irqsave(&priv->tx_lock, flag); 3416 - switch (pri) { 3417 - case MANAGE_PRIORITY: 3418 - tail = priv->txmapringtail; 3419 - begin = priv->txmapring; 3420 - head = priv->txmapringhead; 3421 - nic = read_nic_dword(dev, TX_MANAGEPRIORITY_RING_ADDR); 3422 - nicbegin = priv->txmapringdma; 3423 - break; 3424 - case BK_PRIORITY: 3425 - tail = priv->txbkpringtail; 3426 - begin = priv->txbkpring; 3427 - head = priv->txbkpringhead; 3428 - nic = read_nic_dword(dev, TX_BKPRIORITY_RING_ADDR); 3429 - nicbegin = priv->txbkpringdma; 3430 - break; 3431 - case BE_PRIORITY: 3432 - tail = priv->txbepringtail; 3433 - begin = priv->txbepring; 3434 - head = priv->txbepringhead; 3435 - nic = read_nic_dword(dev, TX_BEPRIORITY_RING_ADDR); 3436 - nicbegin = priv->txbepringdma; 3437 - break; 3438 - case VI_PRIORITY: 3439 - tail = priv->txvipringtail; 3440 - begin = priv->txvipring; 3441 - head = priv->txvipringhead; 3442 - nic = read_nic_dword(dev, TX_VIPRIORITY_RING_ADDR); 3443 - nicbegin = priv->txvipringdma; 3444 - break; 3445 - case VO_PRIORITY: 3446 - tail = priv->txvopringtail; 3447 - begin = priv->txvopring; 3448 - head = priv->txvopringhead; 3449 - nic = read_nic_dword(dev, TX_VOPRIORITY_RING_ADDR); 3450 - nicbegin = priv->txvopringdma; 3451 - break; 3452 - case HI_PRIORITY: 3453 - tail = priv->txhpringtail; 3454 - begin = priv->txhpring; 3455 - head = priv->txhpringhead; 3456 - nic = read_nic_dword(dev, TX_HIGHPRIORITY_RING_ADDR); 3457 - nicbegin = priv->txhpringdma; 3458 - break; 3459 - 3460 - default: 3461 - spin_unlock_irqrestore(&priv->tx_lock, flag); 3462 - return; 3463 - } 3464 - 3465 - nicv = (u32 *)((nic - nicbegin) + (u8 *)begin); 3466 - if ((head <= tail && (nicv > tail || nicv < head)) || 3467 - (head > tail && (nicv > tail && nicv < head))) { 3468 - DMESGW("nic has lost pointer"); 3469 - spin_unlock_irqrestore(&priv->tx_lock, flag); 3470 - rtl8180_restart(dev); 3471 - return; 3472 - } 3473 - 3474 - /* 3475 - * We check all the descriptors between the head and the nic, 3476 - * but not the currently pointed by the nic (the next to be txed) 3477 - * and the previous of the pointed (might be in process ??) 3478 - */ 3479 - offs = (nic - nicbegin); 3480 - offs = offs / 8 / 4; 3481 - hd = (head - begin) / 8; 3482 - 3483 - if (offs >= hd) 3484 - j = offs - hd; 3485 - else 3486 - j = offs + (priv->txringcount-1-hd); 3487 - 3488 - j -= 2; 3489 - if (j < 0) 3490 - j = 0; 3491 - 3492 - for (i = 0; i < j; i++) { 3493 - if ((*head) & (1<<31)) 3494 - break; 3495 - if (((*head)&(0x10000000)) != 0) { 3496 - priv->CurrRetryCnt += (u16)((*head) & (0x000000ff)); 3497 - if (!error) 3498 - priv->NumTxOkTotal++; 3499 - } 3500 - 3501 - if (!error) 3502 - priv->NumTxOkBytesTotal += (*(head+3)) & (0x00000fff); 3503 - 3504 - *head = *head & ~(1<<31); 3505 - 3506 - if ((head - begin)/8 == priv->txringcount-1) 3507 - head = begin; 3508 - else 3509 - head += 8; 3510 - } 3511 - 3512 - /* 3513 - * The head has been moved to the last certainly TXed 3514 - * (or at least processed by the nic) packet. 3515 - * The driver take forcefully owning of all these packets 3516 - * If the packet previous of the nic pointer has been 3517 - * processed this doesn't matter: it will be checked 3518 - * here at the next round. Anyway if no more packet are 3519 - * TXed no memory leak occur at all. 3520 - */ 3521 - 3522 - switch (pri) { 3523 - case MANAGE_PRIORITY: 3524 - priv->txmapringhead = head; 3525 - 3526 - if (priv->ack_tx_to_ieee) { 3527 - if (rtl8180_is_tx_queue_empty(dev)) { 3528 - priv->ack_tx_to_ieee = 0; 3529 - ieee80211_ps_tx_ack(priv->ieee80211, !error); 3530 - } 3531 - } 3532 - break; 3533 - case BK_PRIORITY: 3534 - priv->txbkpringhead = head; 3535 - break; 3536 - case BE_PRIORITY: 3537 - priv->txbepringhead = head; 3538 - break; 3539 - case VI_PRIORITY: 3540 - priv->txvipringhead = head; 3541 - break; 3542 - case VO_PRIORITY: 3543 - priv->txvopringhead = head; 3544 - break; 3545 - case HI_PRIORITY: 3546 - priv->txhpringhead = head; 3547 - break; 3548 - } 3549 - 3550 - spin_unlock_irqrestore(&priv->tx_lock, flag); 3551 - } 3552 - 3553 - static irqreturn_t rtl8180_interrupt(int irq, void *netdev) 3554 - { 3555 - struct net_device *dev = (struct net_device *) netdev; 3556 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 3557 - unsigned long flags; 3558 - u32 inta; 3559 - 3560 - /* We should return IRQ_NONE, but for now let me keep this */ 3561 - if (priv->irq_enabled == 0) 3562 - return IRQ_HANDLED; 3563 - 3564 - spin_lock_irqsave(&priv->irq_th_lock, flags); 3565 - 3566 - /* ISR: 4bytes */ 3567 - inta = read_nic_dword(dev, ISR); 3568 - write_nic_dword(dev, ISR, inta); /* reset int situation */ 3569 - 3570 - priv->stats.shints++; 3571 - 3572 - if (!inta) { 3573 - spin_unlock_irqrestore(&priv->irq_th_lock, flags); 3574 - return IRQ_HANDLED; 3575 - /* 3576 - * most probably we can safely return IRQ_NONE, 3577 - * but for now is better to avoid problems 3578 - */ 3579 - } 3580 - 3581 - if (inta == 0xffff) { 3582 - /* HW disappeared */ 3583 - spin_unlock_irqrestore(&priv->irq_th_lock, flags); 3584 - return IRQ_HANDLED; 3585 - } 3586 - 3587 - priv->stats.ints++; 3588 - 3589 - if (!netif_running(dev)) { 3590 - spin_unlock_irqrestore(&priv->irq_th_lock, flags); 3591 - return IRQ_HANDLED; 3592 - } 3593 - 3594 - if (inta & ISR_TimeOut) 3595 - write_nic_dword(dev, TimerInt, 0); 3596 - 3597 - if (inta & ISR_TBDOK) 3598 - priv->stats.txbeacon++; 3599 - 3600 - if (inta & ISR_TBDER) 3601 - priv->stats.txbeaconerr++; 3602 - 3603 - if (inta & IMR_TMGDOK) 3604 - rtl8180_tx_isr(dev, MANAGE_PRIORITY, 0); 3605 - 3606 - if (inta & ISR_THPDER) { 3607 - priv->stats.txhperr++; 3608 - rtl8180_tx_isr(dev, HI_PRIORITY, 1); 3609 - priv->ieee80211->stats.tx_errors++; 3610 - } 3611 - 3612 - if (inta & ISR_THPDOK) { /* High priority tx ok */ 3613 - priv->link_detect.num_tx_ok_in_period++; 3614 - priv->stats.txhpokint++; 3615 - rtl8180_tx_isr(dev, HI_PRIORITY, 0); 3616 - } 3617 - 3618 - if (inta & ISR_RER) 3619 - priv->stats.rxerr++; 3620 - 3621 - if (inta & ISR_TBKDER) { /* corresponding to BK_PRIORITY */ 3622 - priv->stats.txbkperr++; 3623 - priv->ieee80211->stats.tx_errors++; 3624 - rtl8180_tx_isr(dev, BK_PRIORITY, 1); 3625 - rtl8180_try_wake_queue(dev, BK_PRIORITY); 3626 - } 3627 - 3628 - if (inta & ISR_TBEDER) { /* corresponding to BE_PRIORITY */ 3629 - priv->stats.txbeperr++; 3630 - priv->ieee80211->stats.tx_errors++; 3631 - rtl8180_tx_isr(dev, BE_PRIORITY, 1); 3632 - rtl8180_try_wake_queue(dev, BE_PRIORITY); 3633 - } 3634 - if (inta & ISR_TNPDER) { /* corresponding to VO_PRIORITY */ 3635 - priv->stats.txnperr++; 3636 - priv->ieee80211->stats.tx_errors++; 3637 - rtl8180_tx_isr(dev, NORM_PRIORITY, 1); 3638 - rtl8180_try_wake_queue(dev, NORM_PRIORITY); 3639 - } 3640 - 3641 - if (inta & ISR_TLPDER) { /* corresponding to VI_PRIORITY */ 3642 - priv->stats.txlperr++; 3643 - priv->ieee80211->stats.tx_errors++; 3644 - rtl8180_tx_isr(dev, LOW_PRIORITY, 1); 3645 - rtl8180_try_wake_queue(dev, LOW_PRIORITY); 3646 - } 3647 - 3648 - if (inta & ISR_ROK) { 3649 - priv->stats.rxint++; 3650 - tasklet_schedule(&priv->irq_rx_tasklet); 3651 - } 3652 - 3653 - if (inta & ISR_RQoSOK) { 3654 - priv->stats.rxint++; 3655 - tasklet_schedule(&priv->irq_rx_tasklet); 3656 - } 3657 - 3658 - if (inta & ISR_BcnInt) 3659 - rtl8180_prepare_beacon(dev); 3660 - 3661 - if (inta & ISR_RDU) { 3662 - DMESGW("No RX descriptor available"); 3663 - priv->stats.rxrdu++; 3664 - tasklet_schedule(&priv->irq_rx_tasklet); 3665 - } 3666 - 3667 - if (inta & ISR_RXFOVW) { 3668 - priv->stats.rxoverflow++; 3669 - tasklet_schedule(&priv->irq_rx_tasklet); 3670 - } 3671 - 3672 - if (inta & ISR_TXFOVW) 3673 - priv->stats.txoverflow++; 3674 - 3675 - if (inta & ISR_TNPDOK) { /* Normal priority tx ok */ 3676 - priv->link_detect.num_tx_ok_in_period++; 3677 - priv->stats.txnpokint++; 3678 - rtl8180_tx_isr(dev, NORM_PRIORITY, 0); 3679 - rtl8180_try_wake_queue(dev, NORM_PRIORITY); 3680 - } 3681 - 3682 - if (inta & ISR_TLPDOK) { /* Low priority tx ok */ 3683 - priv->link_detect.num_tx_ok_in_period++; 3684 - priv->stats.txlpokint++; 3685 - rtl8180_tx_isr(dev, LOW_PRIORITY, 0); 3686 - rtl8180_try_wake_queue(dev, LOW_PRIORITY); 3687 - } 3688 - 3689 - if (inta & ISR_TBKDOK) { /* corresponding to BK_PRIORITY */ 3690 - priv->stats.txbkpokint++; 3691 - priv->link_detect.num_tx_ok_in_period++; 3692 - rtl8180_tx_isr(dev, BK_PRIORITY, 0); 3693 - rtl8180_try_wake_queue(dev, BE_PRIORITY); 3694 - } 3695 - 3696 - if (inta & ISR_TBEDOK) { /* corresponding to BE_PRIORITY */ 3697 - priv->stats.txbeperr++; 3698 - priv->link_detect.num_tx_ok_in_period++; 3699 - rtl8180_tx_isr(dev, BE_PRIORITY, 0); 3700 - rtl8180_try_wake_queue(dev, BE_PRIORITY); 3701 - } 3702 - force_pci_posting(dev); 3703 - spin_unlock_irqrestore(&priv->irq_th_lock, flags); 3704 - 3705 - return IRQ_HANDLED; 3706 - } 3707 - 3708 - void rtl8180_irq_rx_tasklet(struct r8180_priv *priv) 3709 - { 3710 - rtl8180_rx(priv->dev); 3711 - } 3712 - 3713 - void GPIOChangeRFWorkItemCallBack(struct work_struct *work) 3714 - { 3715 - struct ieee80211_device *ieee = container_of( 3716 - work, struct ieee80211_device, GPIOChangeRFWorkItem.work); 3717 - struct net_device *dev = ieee->dev; 3718 - struct r8180_priv *priv = ieee80211_priv(dev); 3719 - u8 btPSR; 3720 - u8 btConfig0; 3721 - enum rt_rf_power_state eRfPowerStateToSet; 3722 - bool bActuallySet = false; 3723 - 3724 - char *argv[3]; 3725 - static char *RadioPowerPath = "/etc/acpi/events/RadioPower.sh"; 3726 - static char *envp[] = {"HOME=/", "TERM=linux", 3727 - "PATH=/usr/bin:/bin", NULL}; 3728 - static int readf_count; 3729 - 3730 - readf_count = (readf_count+1)%0xffff; 3731 - /* We should turn off LED before polling FF51[4]. */ 3732 - 3733 - /* Turn off LED. */ 3734 - btPSR = read_nic_byte(dev, PSR); 3735 - write_nic_byte(dev, PSR, (btPSR & ~BIT3)); 3736 - 3737 - /* It need to delay 4us suggested */ 3738 - udelay(4); 3739 - 3740 - /* HW radio On/Off according to the value of FF51[4](config0) */ 3741 - btConfig0 = btPSR = read_nic_byte(dev, CONFIG0); 3742 - 3743 - eRfPowerStateToSet = (btConfig0 & BIT4) ? RF_ON : RF_OFF; 3744 - 3745 - /* Turn LED back on when radio enabled */ 3746 - if (eRfPowerStateToSet == RF_ON) 3747 - write_nic_byte(dev, PSR, btPSR | BIT3); 3748 - 3749 - if ((priv->ieee80211->bHwRadioOff == true) && 3750 - (eRfPowerStateToSet == RF_ON)) { 3751 - priv->ieee80211->bHwRadioOff = false; 3752 - bActuallySet = true; 3753 - } else if ((priv->ieee80211->bHwRadioOff == false) && 3754 - (eRfPowerStateToSet == RF_OFF)) { 3755 - priv->ieee80211->bHwRadioOff = true; 3756 - bActuallySet = true; 3757 - } 3758 - 3759 - if (bActuallySet) { 3760 - MgntActSet_RF_State(dev, eRfPowerStateToSet, RF_CHANGE_BY_HW); 3761 - 3762 - /* To update the UI status for Power status changed */ 3763 - if (priv->ieee80211->bHwRadioOff == true) 3764 - argv[1] = "RFOFF"; 3765 - else 3766 - argv[1] = "RFON"; 3767 - argv[0] = RadioPowerPath; 3768 - argv[2] = NULL; 3769 - 3770 - call_usermodehelper(RadioPowerPath, argv, envp, UMH_WAIT_PROC); 3771 - } 3772 - } 3773 - 3774 - module_init(rtl8180_pci_module_init); 3775 - module_exit(rtl8180_pci_module_exit);
-1139
drivers/staging/rtl8187se/r8180_dm.c
··· 1 - #include "r8180_dm.h" 2 - #include "r8180_hw.h" 3 - #include "r8180_93cx6.h" 4 - 5 - /* Return TRUE if we shall perform High Power Mechanism, FALSE otherwise. */ 6 - #define RATE_ADAPTIVE_TIMER_PERIOD 300 7 - 8 - bool CheckHighPower(struct net_device *dev) 9 - { 10 - struct r8180_priv *priv = ieee80211_priv(dev); 11 - struct ieee80211_device *ieee = priv->ieee80211; 12 - 13 - if (!priv->bRegHighPowerMechanism) 14 - return false; 15 - 16 - if (ieee->state == IEEE80211_LINKED_SCANNING) 17 - return false; 18 - 19 - return true; 20 - } 21 - 22 - /* 23 - * Description: 24 - * Update Tx power level if necessary. 25 - * See also DoRxHighPower() and SetTxPowerLevel8185() for reference. 26 - * 27 - * Note: 28 - * The reason why we udpate Tx power level here instead of DoRxHighPower() 29 - * is the number of IO to change Tx power is much more than channel TR switch 30 - * and they are related to OFDM and MAC registers. 31 - * So, we don't want to update it so frequently in per-Rx packet base. 32 - */ 33 - static void DoTxHighPower(struct net_device *dev) 34 - { 35 - struct r8180_priv *priv = ieee80211_priv(dev); 36 - u16 HiPwrUpperTh = 0; 37 - u16 HiPwrLowerTh = 0; 38 - u8 RSSIHiPwrUpperTh; 39 - u8 RSSIHiPwrLowerTh; 40 - u8 u1bTmp; 41 - char OfdmTxPwrIdx, CckTxPwrIdx; 42 - 43 - HiPwrUpperTh = priv->RegHiPwrUpperTh; 44 - HiPwrLowerTh = priv->RegHiPwrLowerTh; 45 - 46 - HiPwrUpperTh = HiPwrUpperTh * 10; 47 - HiPwrLowerTh = HiPwrLowerTh * 10; 48 - RSSIHiPwrUpperTh = priv->RegRSSIHiPwrUpperTh; 49 - RSSIHiPwrLowerTh = priv->RegRSSIHiPwrLowerTh; 50 - 51 - /* lzm add 080826 */ 52 - OfdmTxPwrIdx = priv->chtxpwr_ofdm[priv->ieee80211->current_network.channel]; 53 - CckTxPwrIdx = priv->chtxpwr[priv->ieee80211->current_network.channel]; 54 - 55 - if ((priv->UndecoratedSmoothedSS > HiPwrUpperTh) || 56 - (priv->bCurCCKPkt && (priv->CurCCKRSSI > RSSIHiPwrUpperTh))) { 57 - /* Stevenl suggested that degrade 8dbm in high power sate. 2007-12-04 Isaiah */ 58 - 59 - priv->bToUpdateTxPwr = true; 60 - u1bTmp = read_nic_byte(dev, CCK_TXAGC); 61 - 62 - /* If it never enter High Power. */ 63 - if (CckTxPwrIdx == u1bTmp) { 64 - u1bTmp = (u1bTmp > 16) ? (u1bTmp - 16) : 0; /* 8dbm */ 65 - write_nic_byte(dev, CCK_TXAGC, u1bTmp); 66 - 67 - u1bTmp = read_nic_byte(dev, OFDM_TXAGC); 68 - u1bTmp = (u1bTmp > 16) ? (u1bTmp - 16) : 0; /* 8dbm */ 69 - write_nic_byte(dev, OFDM_TXAGC, u1bTmp); 70 - } 71 - 72 - } else if ((priv->UndecoratedSmoothedSS < HiPwrLowerTh) && 73 - (!priv->bCurCCKPkt || priv->CurCCKRSSI < RSSIHiPwrLowerTh)) { 74 - if (priv->bToUpdateTxPwr) { 75 - priv->bToUpdateTxPwr = false; 76 - /* SD3 required. */ 77 - u1bTmp = read_nic_byte(dev, CCK_TXAGC); 78 - if (u1bTmp < CckTxPwrIdx) { 79 - write_nic_byte(dev, CCK_TXAGC, CckTxPwrIdx); 80 - } 81 - 82 - u1bTmp = read_nic_byte(dev, OFDM_TXAGC); 83 - if (u1bTmp < OfdmTxPwrIdx) { 84 - write_nic_byte(dev, OFDM_TXAGC, OfdmTxPwrIdx); 85 - } 86 - } 87 - } 88 - } 89 - 90 - 91 - /* 92 - * Description: 93 - * Callback function of UpdateTxPowerWorkItem. 94 - * Because of some event happened, e.g. CCX TPC, High Power Mechanism, 95 - * We update Tx power of current channel again. 96 - */ 97 - void rtl8180_tx_pw_wq(struct work_struct *work) 98 - { 99 - struct delayed_work *dwork = to_delayed_work(work); 100 - struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, tx_pw_wq); 101 - struct net_device *dev = ieee->dev; 102 - 103 - DoTxHighPower(dev); 104 - } 105 - 106 - 107 - /* 108 - * Return TRUE if we shall perform DIG Mechanism, FALSE otherwise. 109 - */ 110 - bool CheckDig(struct net_device *dev) 111 - { 112 - struct r8180_priv *priv = ieee80211_priv(dev); 113 - struct ieee80211_device *ieee = priv->ieee80211; 114 - 115 - if (!priv->bDigMechanism) 116 - return false; 117 - 118 - if (ieee->state != IEEE80211_LINKED) 119 - return false; 120 - 121 - if ((priv->ieee80211->rate / 5) < 36) /* Schedule Dig under all OFDM rates. By Bruce, 2007-06-01. */ 122 - return false; 123 - return true; 124 - } 125 - /* 126 - * Implementation of DIG for Zebra and Zebra2. 127 - */ 128 - static void DIG_Zebra(struct net_device *dev) 129 - { 130 - struct r8180_priv *priv = ieee80211_priv(dev); 131 - u16 CCKFalseAlarm, OFDMFalseAlarm; 132 - u16 OfdmFA1, OfdmFA2; 133 - int InitialGainStep = 7; /* The number of initial gain stages. */ 134 - int LowestGainStage = 4; /* The capable lowest stage of performing dig workitem. */ 135 - u32 AwakePeriodIn2Sec = 0; 136 - 137 - CCKFalseAlarm = (u16)(priv->FalseAlarmRegValue & 0x0000ffff); 138 - OFDMFalseAlarm = (u16)((priv->FalseAlarmRegValue >> 16) & 0x0000ffff); 139 - OfdmFA1 = 0x15; 140 - OfdmFA2 = ((u16)(priv->RegDigOfdmFaUpTh)) << 8; 141 - 142 - /* The number of initial gain steps is different, by Bruce, 2007-04-13. */ 143 - if (priv->InitialGain == 0) { /* autoDIG */ 144 - /* Advised from SD3 DZ */ 145 - priv->InitialGain = 4; /* In 87B, m74dBm means State 4 (m82dBm) */ 146 - } 147 - /* Advised from SD3 DZ */ 148 - OfdmFA1 = 0x20; 149 - 150 - #if 1 /* lzm reserved 080826 */ 151 - AwakePeriodIn2Sec = (2000 - priv->DozePeriodInPast2Sec); 152 - priv->DozePeriodInPast2Sec = 0; 153 - 154 - if (AwakePeriodIn2Sec) { 155 - OfdmFA1 = (u16)((OfdmFA1 * AwakePeriodIn2Sec) / 2000); 156 - OfdmFA2 = (u16)((OfdmFA2 * AwakePeriodIn2Sec) / 2000); 157 - } else { 158 - ; 159 - } 160 - #endif 161 - 162 - InitialGainStep = 8; 163 - LowestGainStage = priv->RegBModeGainStage; /* Lowest gain stage. */ 164 - 165 - if (OFDMFalseAlarm > OfdmFA1) { 166 - if (OFDMFalseAlarm > OfdmFA2) { 167 - priv->DIG_NumberFallbackVote++; 168 - if (priv->DIG_NumberFallbackVote > 1) { 169 - /* serious OFDM False Alarm, need fallback */ 170 - if (priv->InitialGain < InitialGainStep) { 171 - priv->InitialGainBackUp = priv->InitialGain; 172 - 173 - priv->InitialGain = (priv->InitialGain + 1); 174 - UpdateInitialGain(dev); 175 - } 176 - priv->DIG_NumberFallbackVote = 0; 177 - priv->DIG_NumberUpgradeVote = 0; 178 - } 179 - } else { 180 - if (priv->DIG_NumberFallbackVote) 181 - priv->DIG_NumberFallbackVote--; 182 - } 183 - priv->DIG_NumberUpgradeVote = 0; 184 - } else { 185 - if (priv->DIG_NumberFallbackVote) 186 - priv->DIG_NumberFallbackVote--; 187 - priv->DIG_NumberUpgradeVote++; 188 - 189 - if (priv->DIG_NumberUpgradeVote > 9) { 190 - if (priv->InitialGain > LowestGainStage) { /* In 87B, m78dBm means State 4 (m864dBm) */ 191 - priv->InitialGainBackUp = priv->InitialGain; 192 - 193 - priv->InitialGain = (priv->InitialGain - 1); 194 - UpdateInitialGain(dev); 195 - } 196 - priv->DIG_NumberFallbackVote = 0; 197 - priv->DIG_NumberUpgradeVote = 0; 198 - } 199 - } 200 - } 201 - 202 - /* 203 - * Dispatch DIG implementation according to RF. 204 - */ 205 - static void DynamicInitGain(struct net_device *dev) 206 - { 207 - DIG_Zebra(dev); 208 - } 209 - 210 - void rtl8180_hw_dig_wq(struct work_struct *work) 211 - { 212 - struct delayed_work *dwork = to_delayed_work(work); 213 - struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, hw_dig_wq); 214 - struct net_device *dev = ieee->dev; 215 - struct r8180_priv *priv = ieee80211_priv(dev); 216 - 217 - /* Read CCK and OFDM False Alarm. */ 218 - priv->FalseAlarmRegValue = read_nic_dword(dev, CCK_FALSE_ALARM); 219 - 220 - 221 - /* Adjust Initial Gain dynamically. */ 222 - DynamicInitGain(dev); 223 - 224 - } 225 - 226 - static int IncludedInSupportedRates(struct r8180_priv *priv, u8 TxRate) 227 - { 228 - u8 rate_len; 229 - u8 rate_ex_len; 230 - u8 RateMask = 0x7F; 231 - u8 idx; 232 - unsigned short Found = 0; 233 - u8 NaiveTxRate = TxRate&RateMask; 234 - 235 - rate_len = priv->ieee80211->current_network.rates_len; 236 - rate_ex_len = priv->ieee80211->current_network.rates_ex_len; 237 - for (idx = 0; idx < rate_len; idx++) { 238 - if ((priv->ieee80211->current_network.rates[idx] & RateMask) == NaiveTxRate) { 239 - Found = 1; 240 - goto found_rate; 241 - } 242 - } 243 - for (idx = 0; idx < rate_ex_len; idx++) { 244 - if ((priv->ieee80211->current_network.rates_ex[idx] & RateMask) == NaiveTxRate) { 245 - Found = 1; 246 - goto found_rate; 247 - } 248 - } 249 - return Found; 250 - found_rate: 251 - return Found; 252 - } 253 - 254 - /* 255 - * Get the Tx rate one degree up form the input rate in the supported rates. 256 - * Return the upgrade rate if it is successed, otherwise return the input rate. 257 - */ 258 - static u8 GetUpgradeTxRate(struct net_device *dev, u8 rate) 259 - { 260 - struct r8180_priv *priv = ieee80211_priv(dev); 261 - u8 UpRate; 262 - 263 - /* Upgrade 1 degree. */ 264 - switch (rate) { 265 - case 108: /* Up to 54Mbps. */ 266 - UpRate = 108; 267 - break; 268 - 269 - case 96: /* Up to 54Mbps. */ 270 - UpRate = 108; 271 - break; 272 - 273 - case 72: /* Up to 48Mbps. */ 274 - UpRate = 96; 275 - break; 276 - 277 - case 48: /* Up to 36Mbps. */ 278 - UpRate = 72; 279 - break; 280 - 281 - case 36: /* Up to 24Mbps. */ 282 - UpRate = 48; 283 - break; 284 - 285 - case 22: /* Up to 18Mbps. */ 286 - UpRate = 36; 287 - break; 288 - 289 - case 11: /* Up to 11Mbps. */ 290 - UpRate = 22; 291 - break; 292 - 293 - case 4: /* Up to 5.5Mbps. */ 294 - UpRate = 11; 295 - break; 296 - 297 - case 2: /* Up to 2Mbps. */ 298 - UpRate = 4; 299 - break; 300 - 301 - default: 302 - printk("GetUpgradeTxRate(): Input Tx Rate(%d) is undefined!\n", rate); 303 - return rate; 304 - } 305 - /* Check if the rate is valid. */ 306 - if (IncludedInSupportedRates(priv, UpRate)) { 307 - return UpRate; 308 - } else { 309 - return rate; 310 - } 311 - return rate; 312 - } 313 - /* 314 - * Get the Tx rate one degree down form the input rate in the supported rates. 315 - * Return the degrade rate if it is successed, otherwise return the input rate. 316 - */ 317 - 318 - static u8 GetDegradeTxRate(struct net_device *dev, u8 rate) 319 - { 320 - struct r8180_priv *priv = ieee80211_priv(dev); 321 - u8 DownRate; 322 - 323 - /* Upgrade 1 degree. */ 324 - switch (rate) { 325 - case 108: /* Down to 48Mbps. */ 326 - DownRate = 96; 327 - break; 328 - 329 - case 96: /* Down to 36Mbps. */ 330 - DownRate = 72; 331 - break; 332 - 333 - case 72: /* Down to 24Mbps. */ 334 - DownRate = 48; 335 - break; 336 - 337 - case 48: /* Down to 18Mbps. */ 338 - DownRate = 36; 339 - break; 340 - 341 - case 36: /* Down to 11Mbps. */ 342 - DownRate = 22; 343 - break; 344 - 345 - case 22: /* Down to 5.5Mbps. */ 346 - DownRate = 11; 347 - break; 348 - 349 - case 11: /* Down to 2Mbps. */ 350 - DownRate = 4; 351 - break; 352 - 353 - case 4: /* Down to 1Mbps. */ 354 - DownRate = 2; 355 - break; 356 - 357 - case 2: /* Down to 1Mbps. */ 358 - DownRate = 2; 359 - break; 360 - 361 - default: 362 - printk("GetDegradeTxRate(): Input Tx Rate(%d) is undefined!\n", rate); 363 - return rate; 364 - } 365 - /* Check if the rate is valid. */ 366 - if (IncludedInSupportedRates(priv, DownRate)) { 367 - return DownRate; 368 - } else { 369 - return rate; 370 - } 371 - return rate; 372 - } 373 - /* 374 - * Helper function to determine if specified data rate is 375 - * CCK rate. 376 - */ 377 - 378 - static bool MgntIsCckRate(u16 rate) 379 - { 380 - bool bReturn = false; 381 - 382 - if ((rate <= 22) && (rate != 12) && (rate != 18)) { 383 - bReturn = true; 384 - } 385 - 386 - return bReturn; 387 - } 388 - /* 389 - * Description: 390 - * Tx Power tracking mechanism routine on 87SE. 391 - */ 392 - void TxPwrTracking87SE(struct net_device *dev) 393 - { 394 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 395 - u8 tmpu1Byte, CurrentThermal, Idx; 396 - char CckTxPwrIdx, OfdmTxPwrIdx; 397 - 398 - tmpu1Byte = read_nic_byte(dev, EN_LPF_CAL); 399 - CurrentThermal = (tmpu1Byte & 0xf0) >> 4; /*[ 7:4]: thermal meter indication. */ 400 - CurrentThermal = (CurrentThermal > 0x0c) ? 0x0c : CurrentThermal;/* lzm add 080826 */ 401 - 402 - if (CurrentThermal != priv->ThermalMeter) { 403 - /* Update Tx Power level on each channel. */ 404 - for (Idx = 1; Idx < 15; Idx++) { 405 - CckTxPwrIdx = priv->chtxpwr[Idx]; 406 - OfdmTxPwrIdx = priv->chtxpwr_ofdm[Idx]; 407 - 408 - if (CurrentThermal > priv->ThermalMeter) { 409 - /* higher thermal meter. */ 410 - CckTxPwrIdx += (CurrentThermal - priv->ThermalMeter) * 2; 411 - OfdmTxPwrIdx += (CurrentThermal - priv->ThermalMeter) * 2; 412 - 413 - if (CckTxPwrIdx > 35) 414 - CckTxPwrIdx = 35; /* Force TxPower to maximal index. */ 415 - if (OfdmTxPwrIdx > 35) 416 - OfdmTxPwrIdx = 35; 417 - } else { 418 - /* lower thermal meter. */ 419 - CckTxPwrIdx -= (priv->ThermalMeter - CurrentThermal) * 2; 420 - OfdmTxPwrIdx -= (priv->ThermalMeter - CurrentThermal) * 2; 421 - 422 - if (CckTxPwrIdx < 0) 423 - CckTxPwrIdx = 0; 424 - if (OfdmTxPwrIdx < 0) 425 - OfdmTxPwrIdx = 0; 426 - } 427 - 428 - /* Update TxPower level on CCK and OFDM resp. */ 429 - priv->chtxpwr[Idx] = CckTxPwrIdx; 430 - priv->chtxpwr_ofdm[Idx] = OfdmTxPwrIdx; 431 - } 432 - 433 - /* Update TxPower level immediately. */ 434 - rtl8225z2_SetTXPowerLevel(dev, priv->ieee80211->current_network.channel); 435 - } 436 - priv->ThermalMeter = CurrentThermal; 437 - } 438 - static void StaRateAdaptive87SE(struct net_device *dev) 439 - { 440 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 441 - unsigned long CurrTxokCnt; 442 - u16 CurrRetryCnt; 443 - u16 CurrRetryRate; 444 - unsigned long CurrRxokCnt; 445 - bool bTryUp = false; 446 - bool bTryDown = false; 447 - u8 TryUpTh = 1; 448 - u8 TryDownTh = 2; 449 - u32 TxThroughput; 450 - long CurrSignalStrength; 451 - bool bUpdateInitialGain = false; 452 - u8 u1bOfdm = 0, u1bCck = 0; 453 - char OfdmTxPwrIdx, CckTxPwrIdx; 454 - 455 - priv->RateAdaptivePeriod = RATE_ADAPTIVE_TIMER_PERIOD; 456 - 457 - 458 - CurrRetryCnt = priv->CurrRetryCnt; 459 - CurrTxokCnt = priv->NumTxOkTotal - priv->LastTxokCnt; 460 - CurrRxokCnt = priv->ieee80211->NumRxOkTotal - priv->LastRxokCnt; 461 - CurrSignalStrength = priv->Stats_RecvSignalPower; 462 - TxThroughput = (u32)(priv->NumTxOkBytesTotal - priv->LastTxOKBytes); 463 - priv->LastTxOKBytes = priv->NumTxOkBytesTotal; 464 - priv->CurrentOperaRate = priv->ieee80211->rate / 5; 465 - /* 2 Compute retry ratio. */ 466 - if (CurrTxokCnt > 0) { 467 - CurrRetryRate = (u16)(CurrRetryCnt * 100 / CurrTxokCnt); 468 - } else { 469 - /* It may be serious retry. To distinguish serious retry or no packets modified by Bruce */ 470 - CurrRetryRate = (u16)(CurrRetryCnt * 100 / 1); 471 - } 472 - 473 - priv->LastRetryCnt = priv->CurrRetryCnt; 474 - priv->LastTxokCnt = priv->NumTxOkTotal; 475 - priv->LastRxokCnt = priv->ieee80211->NumRxOkTotal; 476 - priv->CurrRetryCnt = 0; 477 - 478 - /* 2No Tx packets, return to init_rate or not? */ 479 - if (CurrRetryRate == 0 && CurrTxokCnt == 0) { 480 - /* 481 - * After 9 (30*300ms) seconds in this condition, we try to raise rate. 482 - */ 483 - priv->TryupingCountNoData++; 484 - 485 - /* [TRC Dell Lab] Extend raised period from 4.5sec to 9sec, Isaiah 2008-02-15 18:00 */ 486 - if (priv->TryupingCountNoData > 30) { 487 - priv->TryupingCountNoData = 0; 488 - priv->CurrentOperaRate = GetUpgradeTxRate(dev, priv->CurrentOperaRate); 489 - /* Reset Fail Record */ 490 - priv->LastFailTxRate = 0; 491 - priv->LastFailTxRateSS = -200; 492 - priv->FailTxRateCount = 0; 493 - } 494 - goto SetInitialGain; 495 - } else { 496 - priv->TryupingCountNoData = 0; /*Reset trying up times. */ 497 - } 498 - 499 - 500 - /* 501 - * For Netgear case, I comment out the following signal strength estimation, 502 - * which can results in lower rate to transmit when sample is NOT enough (e.g. PING request). 503 - * 504 - * Restructure rate adaptive as the following main stages: 505 - * (1) Add retry threshold in 54M upgrading condition with signal strength. 506 - * (2) Add the mechanism to degrade to CCK rate according to signal strength 507 - * and retry rate. 508 - * (3) Remove all Initial Gain Updates over OFDM rate. To avoid the complicated 509 - * situation, Initial Gain Update is upon on DIG mechanism except CCK rate. 510 - * (4) Add the mechanism of trying to upgrade tx rate. 511 - * (5) Record the information of upping tx rate to avoid trying upping tx rate constantly. 512 - * 513 - */ 514 - 515 - /* 516 - * 11Mbps or 36Mbps 517 - * Check more times in these rate(key rates). 518 - */ 519 - if (priv->CurrentOperaRate == 22 || priv->CurrentOperaRate == 72) 520 - TryUpTh += 9; 521 - /* 522 - * Let these rates down more difficult. 523 - */ 524 - if (MgntIsCckRate(priv->CurrentOperaRate) || priv->CurrentOperaRate == 36) 525 - TryDownTh += 1; 526 - 527 - /* 1 Adjust Rate. */ 528 - if (priv->bTryuping == true) { 529 - /* 2 For Test Upgrading mechanism 530 - * Note: 531 - * Sometimes the throughput is upon on the capability between the AP and NIC, 532 - * thus the low data rate does not improve the performance. 533 - * We randomly upgrade the data rate and check if the retry rate is improved. 534 - */ 535 - 536 - /* Upgrading rate did not improve the retry rate, fallback to the original rate. */ 537 - if ((CurrRetryRate > 25) && TxThroughput < priv->LastTxThroughput) { 538 - /*Not necessary raising rate, fall back rate. */ 539 - bTryDown = true; 540 - } else { 541 - priv->bTryuping = false; 542 - } 543 - } else if (CurrSignalStrength > -47 && (CurrRetryRate < 50)) { 544 - /* 545 - * 2For High Power 546 - * 547 - * Return to highest data rate, if signal strength is good enough. 548 - * SignalStrength threshold(-50dbm) is for RTL8186. 549 - * Revise SignalStrength threshold to -51dbm. 550 - */ 551 - /* Also need to check retry rate for safety, by Bruce, 2007-06-05. */ 552 - if (priv->CurrentOperaRate != priv->ieee80211->current_network.HighestOperaRate) { 553 - bTryUp = true; 554 - /* Upgrade Tx Rate directly. */ 555 - priv->TryupingCount += TryUpTh; 556 - } 557 - 558 - } else if (CurrTxokCnt > 9 && CurrTxokCnt < 100 && CurrRetryRate >= 600) { 559 - /* 560 - *2 For Serious Retry 561 - * 562 - * Traffic is not busy but our Tx retry is serious. 563 - */ 564 - bTryDown = true; 565 - /* Let Rate Mechanism to degrade tx rate directly. */ 566 - priv->TryDownCountLowData += TryDownTh; 567 - } else if (priv->CurrentOperaRate == 108) { 568 - /* 2For 54Mbps */ 569 - /* Air Link */ 570 - if ((CurrRetryRate > 26) && (priv->LastRetryRate > 25)) { 571 - bTryDown = true; 572 - } 573 - /* Cable Link */ 574 - else if ((CurrRetryRate > 17) && (priv->LastRetryRate > 16) && (CurrSignalStrength > -72)) { 575 - bTryDown = true; 576 - } 577 - 578 - if (bTryDown && (CurrSignalStrength < -75)) /* cable link */ 579 - priv->TryDownCountLowData += TryDownTh; 580 - } else if (priv->CurrentOperaRate == 96) { 581 - /* 2For 48Mbps */ 582 - /* Air Link */ 583 - if (((CurrRetryRate > 48) && (priv->LastRetryRate > 47))) { 584 - bTryDown = true; 585 - } else if (((CurrRetryRate > 21) && (priv->LastRetryRate > 20)) && (CurrSignalStrength > -74)) { /* Cable Link */ 586 - /* Down to rate 36Mbps. */ 587 - bTryDown = true; 588 - } else if ((CurrRetryRate > (priv->LastRetryRate + 50)) && (priv->FailTxRateCount > 2)) { 589 - bTryDown = true; 590 - priv->TryDownCountLowData += TryDownTh; 591 - } else if ((CurrRetryRate < 8) && (priv->LastRetryRate < 8)) { /* TO DO: need to consider (RSSI) */ 592 - bTryUp = true; 593 - } 594 - 595 - if (bTryDown && (CurrSignalStrength < -75)) { 596 - priv->TryDownCountLowData += TryDownTh; 597 - } 598 - } else if (priv->CurrentOperaRate == 72) { 599 - /* 2For 36Mbps */ 600 - if ((CurrRetryRate > 43) && (priv->LastRetryRate > 41)) { 601 - /* Down to rate 24Mbps. */ 602 - bTryDown = true; 603 - } else if ((CurrRetryRate > (priv->LastRetryRate + 50)) && (priv->FailTxRateCount > 2)) { 604 - bTryDown = true; 605 - priv->TryDownCountLowData += TryDownTh; 606 - } else if ((CurrRetryRate < 15) && (priv->LastRetryRate < 16)) { /* TO DO: need to consider (RSSI) */ 607 - bTryUp = true; 608 - } 609 - 610 - if (bTryDown && (CurrSignalStrength < -80)) 611 - priv->TryDownCountLowData += TryDownTh; 612 - 613 - } else if (priv->CurrentOperaRate == 48) { 614 - /* 2For 24Mbps */ 615 - /* Air Link */ 616 - if (((CurrRetryRate > 63) && (priv->LastRetryRate > 62))) { 617 - bTryDown = true; 618 - } else if (((CurrRetryRate > 33) && (priv->LastRetryRate > 32)) && (CurrSignalStrength > -82)) { /* Cable Link */ 619 - bTryDown = true; 620 - } else if ((CurrRetryRate > (priv->LastRetryRate + 50)) && (priv->FailTxRateCount > 2)) { 621 - bTryDown = true; 622 - priv->TryDownCountLowData += TryDownTh; 623 - } else if ((CurrRetryRate < 20) && (priv->LastRetryRate < 21)) { /* TO DO: need to consider (RSSI) */ 624 - bTryUp = true; 625 - } 626 - 627 - if (bTryDown && (CurrSignalStrength < -82)) 628 - priv->TryDownCountLowData += TryDownTh; 629 - 630 - } else if (priv->CurrentOperaRate == 36) { 631 - if (((CurrRetryRate > 85) && (priv->LastRetryRate > 86))) { 632 - bTryDown = true; 633 - } else if ((CurrRetryRate > (priv->LastRetryRate + 50)) && (priv->FailTxRateCount > 2)) { 634 - bTryDown = true; 635 - priv->TryDownCountLowData += TryDownTh; 636 - } else if ((CurrRetryRate < 22) && (priv->LastRetryRate < 23)) { /* TO DO: need to consider (RSSI) */ 637 - bTryUp = true; 638 - } 639 - } else if (priv->CurrentOperaRate == 22) { 640 - /* 2For 11Mbps */ 641 - if (CurrRetryRate > 95) { 642 - bTryDown = true; 643 - } else if ((CurrRetryRate < 29) && (priv->LastRetryRate < 30)) { /*TO DO: need to consider (RSSI) */ 644 - bTryUp = true; 645 - } 646 - } else if (priv->CurrentOperaRate == 11) { 647 - /* 2For 5.5Mbps */ 648 - if (CurrRetryRate > 149) { 649 - bTryDown = true; 650 - } else if ((CurrRetryRate < 60) && (priv->LastRetryRate < 65)) { 651 - bTryUp = true; 652 - } 653 - } else if (priv->CurrentOperaRate == 4) { 654 - /* 2For 2 Mbps */ 655 - if ((CurrRetryRate > 99) && (priv->LastRetryRate > 99)) { 656 - bTryDown = true; 657 - } else if ((CurrRetryRate < 65) && (priv->LastRetryRate < 70)) { 658 - bTryUp = true; 659 - } 660 - } else if (priv->CurrentOperaRate == 2) { 661 - /* 2For 1 Mbps */ 662 - if ((CurrRetryRate < 70) && (priv->LastRetryRate < 75)) { 663 - bTryUp = true; 664 - } 665 - } 666 - 667 - if (bTryUp && bTryDown) 668 - printk("StaRateAdaptive87B(): Tx Rate tried upping and downing simultaneously!\n"); 669 - 670 - /* 1 Test Upgrading Tx Rate 671 - * Sometimes the cause of the low throughput (high retry rate) is the compatibility between the AP and NIC. 672 - * To test if the upper rate may cause lower retry rate, this mechanism randomly occurs to test upgrading tx rate. 673 - */ 674 - if (!bTryUp && !bTryDown && (priv->TryupingCount == 0) && (priv->TryDownCountLowData == 0) 675 - && priv->CurrentOperaRate != priv->ieee80211->current_network.HighestOperaRate && priv->FailTxRateCount < 2) { 676 - if (jiffies % (CurrRetryRate + 101) == 0) { 677 - bTryUp = true; 678 - priv->bTryuping = true; 679 - } 680 - } 681 - 682 - /* 1 Rate Mechanism */ 683 - if (bTryUp) { 684 - priv->TryupingCount++; 685 - priv->TryDownCountLowData = 0; 686 - 687 - /* 688 - * Check more times if we need to upgrade indeed. 689 - * Because the largest value of pHalData->TryupingCount is 0xFFFF and 690 - * the largest value of pHalData->FailTxRateCount is 0x14, 691 - * this condition will be satisfied at most every 2 min. 692 - */ 693 - 694 - if ((priv->TryupingCount > (TryUpTh + priv->FailTxRateCount * priv->FailTxRateCount)) || 695 - (CurrSignalStrength > priv->LastFailTxRateSS) || priv->bTryuping) { 696 - priv->TryupingCount = 0; 697 - /* 698 - * When transferring from CCK to OFDM, DIG is an important issue. 699 - */ 700 - if (priv->CurrentOperaRate == 22) 701 - bUpdateInitialGain = true; 702 - 703 - /* 704 - * The difference in throughput between 48Mbps and 36Mbps is 8M. 705 - * So, we must be careful in this rate scale. Isaiah 2008-02-15. 706 - */ 707 - if (((priv->CurrentOperaRate == 72) || (priv->CurrentOperaRate == 48) || (priv->CurrentOperaRate == 36)) && 708 - (priv->FailTxRateCount > 2)) 709 - priv->RateAdaptivePeriod = (RATE_ADAPTIVE_TIMER_PERIOD / 2); 710 - 711 - /* (1)To avoid upgrade frequently to the fail tx rate, add the FailTxRateCount into the threshold. */ 712 - /* (2)If the signal strength is increased, it may be able to upgrade. */ 713 - 714 - priv->CurrentOperaRate = GetUpgradeTxRate(dev, priv->CurrentOperaRate); 715 - 716 - if (priv->CurrentOperaRate == 36) { 717 - priv->bUpdateARFR = true; 718 - write_nic_word(dev, ARFR, 0x0F8F); /* bypass 12/9/6 */ 719 - } else if (priv->bUpdateARFR) { 720 - priv->bUpdateARFR = false; 721 - write_nic_word(dev, ARFR, 0x0FFF); /* set 1M ~ 54Mbps. */ 722 - } 723 - 724 - /* Update Fail Tx rate and count. */ 725 - if (priv->LastFailTxRate != priv->CurrentOperaRate) { 726 - priv->LastFailTxRate = priv->CurrentOperaRate; 727 - priv->FailTxRateCount = 0; 728 - priv->LastFailTxRateSS = -200; /* Set lowest power. */ 729 - } 730 - } 731 - } else { 732 - if (priv->TryupingCount > 0) 733 - priv->TryupingCount--; 734 - } 735 - 736 - if (bTryDown) { 737 - priv->TryDownCountLowData++; 738 - priv->TryupingCount = 0; 739 - 740 - /* Check if Tx rate can be degraded or Test trying upgrading should fallback. */ 741 - if (priv->TryDownCountLowData > TryDownTh || priv->bTryuping) { 742 - priv->TryDownCountLowData = 0; 743 - priv->bTryuping = false; 744 - /* Update fail information. */ 745 - if (priv->LastFailTxRate == priv->CurrentOperaRate) { 746 - priv->FailTxRateCount++; 747 - /* Record the Tx fail rate signal strength. */ 748 - if (CurrSignalStrength > priv->LastFailTxRateSS) 749 - priv->LastFailTxRateSS = CurrSignalStrength; 750 - } else { 751 - priv->LastFailTxRate = priv->CurrentOperaRate; 752 - priv->FailTxRateCount = 1; 753 - priv->LastFailTxRateSS = CurrSignalStrength; 754 - } 755 - priv->CurrentOperaRate = GetDegradeTxRate(dev, priv->CurrentOperaRate); 756 - 757 - /* Reduce chariot training time at weak signal strength situation. SD3 ED demand. */ 758 - if ((CurrSignalStrength < -80) && (priv->CurrentOperaRate > 72)) { 759 - priv->CurrentOperaRate = 72; 760 - } 761 - 762 - if (priv->CurrentOperaRate == 36) { 763 - priv->bUpdateARFR = true; 764 - write_nic_word(dev, ARFR, 0x0F8F); /* bypass 12/9/6 */ 765 - } else if (priv->bUpdateARFR) { 766 - priv->bUpdateARFR = false; 767 - write_nic_word(dev, ARFR, 0x0FFF); /* set 1M ~ 54Mbps. */ 768 - } 769 - 770 - /* 771 - * When it is CCK rate, it may need to update initial gain to receive lower power packets. 772 - */ 773 - if (MgntIsCckRate(priv->CurrentOperaRate)) { 774 - bUpdateInitialGain = true; 775 - } 776 - } 777 - } else { 778 - if (priv->TryDownCountLowData > 0) 779 - priv->TryDownCountLowData--; 780 - } 781 - 782 - /* 783 - * Keep the Tx fail rate count to equal to 0x15 at most. 784 - * Reduce the fail count at least to 10 sec if tx rate is tending stable. 785 - */ 786 - if (priv->FailTxRateCount >= 0x15 || 787 - (!bTryUp && !bTryDown && priv->TryDownCountLowData == 0 && priv->TryupingCount && priv->FailTxRateCount > 0x6)) { 788 - priv->FailTxRateCount--; 789 - } 790 - 791 - 792 - OfdmTxPwrIdx = priv->chtxpwr_ofdm[priv->ieee80211->current_network.channel]; 793 - CckTxPwrIdx = priv->chtxpwr[priv->ieee80211->current_network.channel]; 794 - 795 - /* Mac0x9e increase 2 level in 36M~18M situation */ 796 - if ((priv->CurrentOperaRate < 96) && (priv->CurrentOperaRate > 22)) { 797 - u1bCck = read_nic_byte(dev, CCK_TXAGC); 798 - u1bOfdm = read_nic_byte(dev, OFDM_TXAGC); 799 - 800 - /* case 1: Never enter High power */ 801 - if (u1bCck == CckTxPwrIdx) { 802 - if (u1bOfdm != (OfdmTxPwrIdx + 2)) { 803 - priv->bEnhanceTxPwr = true; 804 - u1bOfdm = ((u1bOfdm + 2) > 35) ? 35 : (u1bOfdm + 2); 805 - write_nic_byte(dev, OFDM_TXAGC, u1bOfdm); 806 - } 807 - } else if (u1bCck < CckTxPwrIdx) { 808 - /* case 2: enter high power */ 809 - if (!priv->bEnhanceTxPwr) { 810 - priv->bEnhanceTxPwr = true; 811 - u1bOfdm = ((u1bOfdm + 2) > 35) ? 35 : (u1bOfdm + 2); 812 - write_nic_byte(dev, OFDM_TXAGC, u1bOfdm); 813 - } 814 - } 815 - } else if (priv->bEnhanceTxPwr) { /* 54/48/11/5.5/2/1 */ 816 - u1bCck = read_nic_byte(dev, CCK_TXAGC); 817 - u1bOfdm = read_nic_byte(dev, OFDM_TXAGC); 818 - 819 - /* case 1: Never enter High power */ 820 - if (u1bCck == CckTxPwrIdx) { 821 - priv->bEnhanceTxPwr = false; 822 - write_nic_byte(dev, OFDM_TXAGC, OfdmTxPwrIdx); 823 - } 824 - /* case 2: enter high power */ 825 - else if (u1bCck < CckTxPwrIdx) { 826 - priv->bEnhanceTxPwr = false; 827 - u1bOfdm = ((u1bOfdm - 2) > 0) ? (u1bOfdm - 2) : 0; 828 - write_nic_byte(dev, OFDM_TXAGC, u1bOfdm); 829 - } 830 - } 831 - 832 - /* 833 - * We need update initial gain when we set tx rate "from OFDM to CCK" or 834 - * "from CCK to OFDM". 835 - */ 836 - SetInitialGain: 837 - if (bUpdateInitialGain) { 838 - if (MgntIsCckRate(priv->CurrentOperaRate)) { /* CCK */ 839 - if (priv->InitialGain > priv->RegBModeGainStage) { 840 - priv->InitialGainBackUp = priv->InitialGain; 841 - 842 - if (CurrSignalStrength < -85) /* Low power, OFDM [0x17] = 26. */ 843 - /* SD3 SYs suggest that CurrSignalStrength < -65, ofdm 0x17=26. */ 844 - priv->InitialGain = priv->RegBModeGainStage; 845 - 846 - else if (priv->InitialGain > priv->RegBModeGainStage + 1) 847 - priv->InitialGain -= 2; 848 - 849 - else 850 - priv->InitialGain--; 851 - 852 - printk("StaRateAdaptive87SE(): update init_gain to index %d for date rate %d\n", priv->InitialGain, priv->CurrentOperaRate); 853 - UpdateInitialGain(dev); 854 - } 855 - } else { /* OFDM */ 856 - if (priv->InitialGain < 4) { 857 - priv->InitialGainBackUp = priv->InitialGain; 858 - 859 - priv->InitialGain++; 860 - printk("StaRateAdaptive87SE(): update init_gain to index %d for date rate %d\n", priv->InitialGain, priv->CurrentOperaRate); 861 - UpdateInitialGain(dev); 862 - } 863 - } 864 - } 865 - 866 - /* Record the related info */ 867 - priv->LastRetryRate = CurrRetryRate; 868 - priv->LastTxThroughput = TxThroughput; 869 - priv->ieee80211->rate = priv->CurrentOperaRate * 5; 870 - } 871 - 872 - void rtl8180_rate_adapter(struct work_struct *work) 873 - { 874 - struct delayed_work *dwork = to_delayed_work(work); 875 - struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, rate_adapter_wq); 876 - struct net_device *dev = ieee->dev; 877 - StaRateAdaptive87SE(dev); 878 - } 879 - void timer_rate_adaptive(unsigned long data) 880 - { 881 - struct r8180_priv *priv = ieee80211_priv((struct net_device *)data); 882 - if (!priv->up) { 883 - return; 884 - } 885 - if ((priv->ieee80211->iw_mode != IW_MODE_MASTER) 886 - && (priv->ieee80211->state == IEEE80211_LINKED) && 887 - (priv->ForcedDataRate == 0)) { 888 - queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->rate_adapter_wq); 889 - } 890 - priv->rateadapter_timer.expires = jiffies + MSECS(priv->RateAdaptivePeriod); 891 - add_timer(&priv->rateadapter_timer); 892 - } 893 - 894 - void SwAntennaDiversityRxOk8185(struct net_device *dev, u8 SignalStrength) 895 - { 896 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 897 - 898 - priv->AdRxOkCnt++; 899 - 900 - if (priv->AdRxSignalStrength != -1) { 901 - priv->AdRxSignalStrength = ((priv->AdRxSignalStrength * 7) + (SignalStrength * 3)) / 10; 902 - } else { /* Initialization case. */ 903 - priv->AdRxSignalStrength = SignalStrength; 904 - } 905 - 906 - if (priv->LastRxPktAntenna) /* Main antenna. */ 907 - priv->AdMainAntennaRxOkCnt++; 908 - else /* Aux antenna. */ 909 - priv->AdAuxAntennaRxOkCnt++; 910 - } 911 - /* Change Antenna Switch. */ 912 - bool SetAntenna8185(struct net_device *dev, u8 u1bAntennaIndex) 913 - { 914 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 915 - bool bAntennaSwitched = false; 916 - 917 - switch (u1bAntennaIndex) { 918 - case 0: 919 - /* Mac register, main antenna */ 920 - write_nic_byte(dev, ANTSEL, 0x03); 921 - /* base band */ 922 - write_phy_cck(dev, 0x11, 0x9b); /* Config CCK RX antenna. */ 923 - write_phy_ofdm(dev, 0x0d, 0x5c); /* Config OFDM RX antenna. */ 924 - 925 - bAntennaSwitched = true; 926 - break; 927 - 928 - case 1: 929 - /* Mac register, aux antenna */ 930 - write_nic_byte(dev, ANTSEL, 0x00); 931 - /* base band */ 932 - write_phy_cck(dev, 0x11, 0xbb); /* Config CCK RX antenna. */ 933 - write_phy_ofdm(dev, 0x0d, 0x54); /* Config OFDM RX antenna. */ 934 - 935 - bAntennaSwitched = true; 936 - 937 - break; 938 - 939 - default: 940 - printk("SetAntenna8185: unknown u1bAntennaIndex(%d)\n", u1bAntennaIndex); 941 - break; 942 - } 943 - 944 - if (bAntennaSwitched) 945 - priv->CurrAntennaIndex = u1bAntennaIndex; 946 - 947 - return bAntennaSwitched; 948 - } 949 - /* Toggle Antenna switch. */ 950 - bool SwitchAntenna(struct net_device *dev) 951 - { 952 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 953 - 954 - bool bResult; 955 - 956 - if (priv->CurrAntennaIndex == 0) { 957 - bResult = SetAntenna8185(dev, 1); 958 - } else { 959 - bResult = SetAntenna8185(dev, 0); 960 - } 961 - 962 - return bResult; 963 - } 964 - /* 965 - * Engine of SW Antenna Diversity mechanism. 966 - * Since 8187 has no Tx part information, 967 - * this implementation is only dependend on Rx part information. 968 - */ 969 - void SwAntennaDiversity(struct net_device *dev) 970 - { 971 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 972 - bool bSwCheckSS = false; 973 - if (bSwCheckSS) { 974 - priv->AdTickCount++; 975 - 976 - printk("(1) AdTickCount: %d, AdCheckPeriod: %d\n", 977 - priv->AdTickCount, priv->AdCheckPeriod); 978 - printk("(2) AdRxSignalStrength: %ld, AdRxSsThreshold: %ld\n", 979 - priv->AdRxSignalStrength, priv->AdRxSsThreshold); 980 - } 981 - 982 - /* Case 1. No Link. */ 983 - if (priv->ieee80211->state != IEEE80211_LINKED) { 984 - priv->bAdSwitchedChecking = false; 985 - /* I switch antenna here to prevent any one of antenna is broken before link established, 2006.04.18, by rcnjko.. */ 986 - SwitchAntenna(dev); 987 - 988 - /* Case 2. Linked but no packet receive.d */ 989 - } else if (priv->AdRxOkCnt == 0) { 990 - priv->bAdSwitchedChecking = false; 991 - SwitchAntenna(dev); 992 - 993 - /* Case 3. Evaluate last antenna switch action and undo it if necessary. */ 994 - } else if (priv->bAdSwitchedChecking == true) { 995 - priv->bAdSwitchedChecking = false; 996 - 997 - /* Adjust Rx signal strength threshold. */ 998 - priv->AdRxSsThreshold = (priv->AdRxSignalStrength + priv->AdRxSsBeforeSwitched) / 2; 999 - 1000 - priv->AdRxSsThreshold = (priv->AdRxSsThreshold > priv->AdMaxRxSsThreshold) ? 1001 - priv->AdMaxRxSsThreshold : priv->AdRxSsThreshold; 1002 - if (priv->AdRxSignalStrength < priv->AdRxSsBeforeSwitched) { 1003 - /* Rx signal strength is not improved after we swtiched antenna. => Swich back. */ 1004 - /* Increase Antenna Diversity checking period due to bad decision. */ 1005 - priv->AdCheckPeriod *= 2; 1006 - /* Increase Antenna Diversity checking period. */ 1007 - if (priv->AdCheckPeriod > priv->AdMaxCheckPeriod) 1008 - priv->AdCheckPeriod = priv->AdMaxCheckPeriod; 1009 - 1010 - /* Wrong decision => switch back. */ 1011 - SwitchAntenna(dev); 1012 - } else { 1013 - /* Rx Signal Strength is improved. */ 1014 - 1015 - /* Reset Antenna Diversity checking period to its min value. */ 1016 - priv->AdCheckPeriod = priv->AdMinCheckPeriod; 1017 - } 1018 - 1019 - } 1020 - /* Case 4. Evaluate if we shall switch antenna now. */ 1021 - /* Cause Table Speed is very fast in TRC Dell Lab, we check it every time. */ 1022 - else { 1023 - priv->AdTickCount = 0; 1024 - 1025 - /* 1026 - * <Roger_Notes> We evaluate RxOk counts for each antenna first and than 1027 - * evaluate signal strength. 1028 - * The following operation can overcome the disability of CCA on both two antennas 1029 - * When signal strength was extremely low or high. 1030 - * 2008.01.30. 1031 - */ 1032 - 1033 - /* 1034 - * Evaluate RxOk count from each antenna if we shall switch default antenna now. 1035 - */ 1036 - if ((priv->AdMainAntennaRxOkCnt < priv->AdAuxAntennaRxOkCnt) 1037 - && (priv->CurrAntennaIndex == 0)) { 1038 - /* We set Main antenna as default but RxOk count was less than Aux ones. */ 1039 - 1040 - /* Switch to Aux antenna. */ 1041 - SwitchAntenna(dev); 1042 - priv->bHWAdSwitched = true; 1043 - } else if ((priv->AdAuxAntennaRxOkCnt < priv->AdMainAntennaRxOkCnt) 1044 - && (priv->CurrAntennaIndex == 1)) { 1045 - /* We set Aux antenna as default but RxOk count was less than Main ones. */ 1046 - 1047 - /* Switch to Main antenna. */ 1048 - SwitchAntenna(dev); 1049 - priv->bHWAdSwitched = true; 1050 - } else { 1051 - /* Default antenna is better. */ 1052 - 1053 - /* Still need to check current signal strength. */ 1054 - priv->bHWAdSwitched = false; 1055 - } 1056 - /* 1057 - * <Roger_Notes> We evaluate Rx signal strength ONLY when default antenna 1058 - * didn't change by HW evaluation. 1059 - * 2008.02.27. 1060 - * 1061 - * [TRC Dell Lab] SignalStrength is inaccuracy. Isaiah 2008-03-05 1062 - * For example, Throughput of aux is better than main antenna(about 10M v.s 2M), 1063 - * but AdRxSignalStrength is less than main. 1064 - * Our guess is that main antenna have lower throughput and get many change 1065 - * to receive more CCK packets(ex.Beacon) which have stronger SignalStrength. 1066 - */ 1067 - if ((!priv->bHWAdSwitched) && (bSwCheckSS)) { 1068 - /* Evaluate Rx signal strength if we shall switch antenna now. */ 1069 - if (priv->AdRxSignalStrength < priv->AdRxSsThreshold) { 1070 - /* Rx signal strength is weak => Switch Antenna. */ 1071 - priv->AdRxSsBeforeSwitched = priv->AdRxSignalStrength; 1072 - priv->bAdSwitchedChecking = true; 1073 - 1074 - SwitchAntenna(dev); 1075 - } else { 1076 - /* Rx signal strength is OK. */ 1077 - priv->bAdSwitchedChecking = false; 1078 - /* Increase Rx signal strength threshold if necessary. */ 1079 - if ((priv->AdRxSignalStrength > (priv->AdRxSsThreshold + 10)) && /* Signal is much stronger than current threshold */ 1080 - priv->AdRxSsThreshold <= priv->AdMaxRxSsThreshold) { /* Current threhold is not yet reach upper limit. */ 1081 - 1082 - priv->AdRxSsThreshold = (priv->AdRxSsThreshold + priv->AdRxSignalStrength) / 2; 1083 - priv->AdRxSsThreshold = (priv->AdRxSsThreshold > priv->AdMaxRxSsThreshold) ? 1084 - priv->AdMaxRxSsThreshold : priv->AdRxSsThreshold;/* +by amy 080312 */ 1085 - } 1086 - 1087 - /* Reduce Antenna Diversity checking period if possible. */ 1088 - if (priv->AdCheckPeriod > priv->AdMinCheckPeriod) 1089 - priv->AdCheckPeriod /= 2; 1090 - } 1091 - } 1092 - } 1093 - /* Reset antenna diversity Rx related statistics. */ 1094 - priv->AdRxOkCnt = 0; 1095 - priv->AdMainAntennaRxOkCnt = 0; 1096 - priv->AdAuxAntennaRxOkCnt = 0; 1097 - } 1098 - 1099 - /* Return TRUE if we shall perform Tx Power Tracking Mechanism, FALSE otherwise. */ 1100 - bool CheckTxPwrTracking(struct net_device *dev) 1101 - { 1102 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1103 - 1104 - if (!priv->bTxPowerTrack) 1105 - return false; 1106 - 1107 - /* if 87SE is in High Power , don't do Tx Power Tracking. asked by SD3 ED. 2008-08-08 Isaiah */ 1108 - if (priv->bToUpdateTxPwr) 1109 - return false; 1110 - 1111 - return true; 1112 - } 1113 - 1114 - 1115 - /* Timer callback function of SW Antenna Diversity. */ 1116 - void SwAntennaDiversityTimerCallback(struct net_device *dev) 1117 - { 1118 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1119 - enum rt_rf_power_state rtState; 1120 - 1121 - /* We do NOT need to switch antenna while RF is off. */ 1122 - rtState = priv->eRFPowerState; 1123 - do { 1124 - if (rtState == RF_OFF) { 1125 - break; 1126 - } else if (rtState == RF_SLEEP) { 1127 - /* Don't access BB/RF under Disable PLL situation. */ 1128 - break; 1129 - } 1130 - SwAntennaDiversity(dev); 1131 - 1132 - } while (false); 1133 - 1134 - if (priv->up) { 1135 - priv->SwAntennaDiversityTimer.expires = jiffies + MSECS(ANTENNA_DIVERSITY_TIMER_PERIOD); 1136 - add_timer(&priv->SwAntennaDiversityTimer); 1137 - } 1138 - } 1139 -
-23
drivers/staging/rtl8187se/r8180_dm.h
··· 1 - #ifndef R8180_DM_H 2 - #define R8180_DM_H 3 - 4 - #include "r8180.h" 5 - /* #include "r8180_hw.h" */ 6 - /* #include "r8180_93cx6.h" */ 7 - void SwAntennaDiversityRxOk8185(struct net_device *dev, u8 SignalStrength); 8 - bool SetAntenna8185(struct net_device *dev, u8 u1bAntennaIndex); 9 - bool SwitchAntenna(struct net_device *dev); 10 - void SwAntennaDiversity(struct net_device *dev); 11 - void SwAntennaDiversityTimerCallback(struct net_device *dev); 12 - bool CheckDig(struct net_device *dev); 13 - bool CheckHighPower(struct net_device *dev); 14 - void rtl8180_hw_dig_wq(struct work_struct *work); 15 - void rtl8180_tx_pw_wq(struct work_struct *work); 16 - void rtl8180_rate_adapter(struct work_struct *work); 17 - void TxPwrTracking87SE(struct net_device *dev); 18 - bool CheckTxPwrTracking(struct net_device *dev); 19 - void rtl8180_rate_adapter(struct work_struct *work); 20 - void timer_rate_adaptive(unsigned long data); 21 - 22 - 23 - #endif
-588
drivers/staging/rtl8187se/r8180_hw.h
··· 1 - /* 2 - This is part of rtl8180 OpenSource driver. 3 - Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com> 4 - Released under the terms of GPL (General Public Licence) 5 - 6 - Parts of this driver are based on the GPL part of the 7 - official Realtek driver. 8 - Parts of this driver are based on the rtl8180 driver skeleton 9 - from Patric Schenke & Andres Salomon. 10 - Parts of this driver are based on the Intel Pro Wireless 11 - 2100 GPL driver. 12 - 13 - We want to tanks the Authors of those projects 14 - and the Ndiswrapper project Authors. 15 - */ 16 - 17 - /* Mariusz Matuszek added full registers definition with Realtek's name */ 18 - 19 - /* this file contains register definitions for the rtl8180 MAC controller */ 20 - #ifndef R8180_HW 21 - #define R8180_HW 22 - 23 - 24 - #define BIT0 0x00000001 25 - #define BIT1 0x00000002 26 - #define BIT2 0x00000004 27 - #define BIT3 0x00000008 28 - #define BIT4 0x00000010 29 - #define BIT5 0x00000020 30 - #define BIT6 0x00000040 31 - #define BIT7 0x00000080 32 - #define BIT9 0x00000200 33 - #define BIT11 0x00000800 34 - #define BIT13 0x00002000 35 - #define BIT15 0x00008000 36 - #define BIT20 0x00100000 37 - #define BIT21 0x00200000 38 - #define BIT22 0x00400000 39 - #define BIT23 0x00800000 40 - #define BIT24 0x01000000 41 - #define BIT25 0x02000000 42 - #define BIT26 0x04000000 43 - #define BIT27 0x08000000 44 - #define BIT28 0x10000000 45 - #define BIT29 0x20000000 46 - #define BIT30 0x40000000 47 - #define BIT31 0x80000000 48 - 49 - #define MAX_SLEEP_TIME (10000) 50 - #define MIN_SLEEP_TIME (50) 51 - 52 - #define BB_HOST_BANG_EN (1<<2) 53 - #define BB_HOST_BANG_CLK (1<<1) 54 - 55 - #define MAC0 0 56 - #define MAC4 4 57 - 58 - #define CMD 0x37 59 - #define CMD_RST_SHIFT 4 60 - #define CMD_RX_ENABLE_SHIFT 3 61 - #define CMD_TX_ENABLE_SHIFT 2 62 - 63 - #define EPROM_CMD 0x50 64 - #define EPROM_CMD_RESERVED_MASK ((1<<5)|(1<<4)) 65 - #define EPROM_CMD_OPERATING_MODE_SHIFT 6 66 - #define EPROM_CMD_OPERATING_MODE_MASK ((1<<7)|(1<<6)) 67 - #define EPROM_CMD_CONFIG 0x3 68 - #define EPROM_CMD_NORMAL 0 69 - #define EPROM_CMD_LOAD 1 70 - #define EPROM_CMD_PROGRAM 2 71 - #define EPROM_CS_SHIFT 3 72 - #define EPROM_CK_SHIFT 2 73 - #define EPROM_W_SHIFT 1 74 - #define EPROM_R_SHIFT 0 75 - #define CONFIG2_DMA_POLLING_MODE_SHIFT 3 76 - 77 - #define INTA_TXOVERFLOW (1<<15) 78 - #define INTA_TIMEOUT (1<<14) 79 - #define INTA_HIPRIORITYDESCERR (1<<9) 80 - #define INTA_HIPRIORITYDESCOK (1<<8) 81 - #define INTA_NORMPRIORITYDESCERR (1<<7) 82 - #define INTA_NORMPRIORITYDESCOK (1<<6) 83 - #define INTA_RXOVERFLOW (1<<5) 84 - #define INTA_RXDESCERR (1<<4) 85 - #define INTA_LOWPRIORITYDESCERR (1<<3) 86 - #define INTA_LOWPRIORITYDESCOK (1<<2) 87 - #define INTA_RXOK (1) 88 - #define INTA_MASK 0x3c 89 - 90 - #define RXRING_ADDR 0xe4 /* page 0 */ 91 - #define PGSELECT 0x5e 92 - #define PGSELECT_PG_SHIFT 0 93 - #define RX_CONF 0x44 94 - #define MAC_FILTER_MASK ((1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<5) | \ 95 - (1<<12) | (1<<18) | (1<<19) | (1<<20) | (1<<21) | (1<<22) | (1<<23)) 96 - #define RX_CHECK_BSSID_SHIFT 23 97 - #define ACCEPT_PWR_FRAME_SHIFT 22 98 - #define ACCEPT_MNG_FRAME_SHIFT 20 99 - #define ACCEPT_CTL_FRAME_SHIFT 19 100 - #define ACCEPT_DATA_FRAME_SHIFT 18 101 - #define ACCEPT_ICVERR_FRAME_SHIFT 12 102 - #define ACCEPT_CRCERR_FRAME_SHIFT 5 103 - #define ACCEPT_BCAST_FRAME_SHIFT 3 104 - #define ACCEPT_MCAST_FRAME_SHIFT 2 105 - #define ACCEPT_ALLMAC_FRAME_SHIFT 0 106 - #define ACCEPT_NICMAC_FRAME_SHIFT 1 107 - 108 - #define RX_FIFO_THRESHOLD_MASK ((1<<13) | (1<<14) | (1<<15)) 109 - #define RX_FIFO_THRESHOLD_SHIFT 13 110 - #define RX_FIFO_THRESHOLD_NONE 7 111 - #define RX_AUTORESETPHY_SHIFT 28 112 - 113 - #define TX_CONF 0x40 114 - #define TX_CONF_HEADER_AUTOICREMENT_SHIFT 30 115 - #define TX_LOOPBACK_SHIFT 17 116 - #define TX_LOOPBACK_NONE 0 117 - #define TX_LOOPBACK_CONTINUE 3 118 - #define TX_LOOPBACK_MASK ((1<<17)|(1<<18)) 119 - #define TX_DPRETRY_SHIFT 0 120 - #define R8180_MAX_RETRY 255 121 - #define TX_RTSRETRY_SHIFT 8 122 - #define TX_NOICV_SHIFT 19 123 - #define TX_NOCRC_SHIFT 16 124 - #define TX_DMA_POLLING 0xd9 125 - #define TX_DMA_POLLING_BEACON_SHIFT 7 126 - #define TX_DMA_POLLING_HIPRIORITY_SHIFT 6 127 - #define TX_DMA_POLLING_NORMPRIORITY_SHIFT 5 128 - #define TX_DMA_POLLING_LOWPRIORITY_SHIFT 4 129 - #define TX_MANAGEPRIORITY_RING_ADDR 0x0C 130 - #define TX_BKPRIORITY_RING_ADDR 0x10 131 - #define TX_BEPRIORITY_RING_ADDR 0x14 132 - #define TX_VIPRIORITY_RING_ADDR 0x20 133 - #define TX_VOPRIORITY_RING_ADDR 0x24 134 - #define TX_HIGHPRIORITY_RING_ADDR 0x28 135 - #define MAX_RX_DMA_MASK ((1<<8) | (1<<9) | (1<<10)) 136 - #define MAX_RX_DMA_2048 7 137 - #define MAX_RX_DMA_1024 6 138 - #define MAX_RX_DMA_SHIFT 10 139 - #define INT_TIMEOUT 0x48 140 - #define CONFIG3_CLKRUN_SHIFT 2 141 - #define CONFIG3_ANAPARAM_W_SHIFT 6 142 - #define ANAPARAM 0x54 143 - #define BEACON_INTERVAL 0x70 144 - #define BEACON_INTERVAL_MASK ((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)| \ 145 - (1<<6)|(1<<7)|(1<<8)|(1<<9)) 146 - #define ATIM_MASK ((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)| \ 147 - (1<<8)|(1<<9)) 148 - #define ATIM 0x72 149 - #define EPROM_CS_SHIFT 3 150 - #define EPROM_CK_SHIFT 2 151 - #define PHY_ADR 0x7c 152 - #define SECURITY 0x5f /* 1209 this is sth wrong */ 153 - #define SECURITY_WEP_TX_ENABLE_SHIFT 1 154 - #define SECURITY_WEP_RX_ENABLE_SHIFT 0 155 - #define SECURITY_ENCRYP_104 1 156 - #define SECURITY_ENCRYP_SHIFT 4 157 - #define SECURITY_ENCRYP_MASK ((1<<4)|(1<<5)) 158 - #define KEY0 0x90 /* 1209 this is sth wrong */ 159 - #define CONFIG2_ANTENNA_SHIFT 6 160 - #define TX_BEACON_RING_ADDR 0x4c 161 - #define CONFIG0_WEP40_SHIFT 7 162 - #define CONFIG0_WEP104_SHIFT 6 163 - #define AGCRESET_SHIFT 5 164 - 165 - 166 - 167 - /* 168 - * Operational registers offsets in PCI (I/O) space. 169 - * RealTek names are used. 170 - */ 171 - 172 - #define TSFTR 0x0018 173 - 174 - #define TLPDA 0x0020 175 - 176 - #define BSSID 0x002E 177 - 178 - #define CR 0x0037 179 - 180 - #define RF_SW_CONFIG 0x8 /* store data which is transmitted to RF for driver */ 181 - #define RF_SW_CFG_SI BIT1 182 - #define EIFS 0x2D /* Extended InterFrame Space Timer, in unit of 4 us. */ 183 - 184 - #define BRSR 0x34 /* Basic rate set */ 185 - 186 - #define IMR 0x006C 187 - #define ISR 0x003C 188 - 189 - #define TCR 0x0040 190 - 191 - #define RCR 0x0044 192 - 193 - #define TimerInt 0x0048 194 - 195 - #define CR9346 0x0050 196 - 197 - #define CONFIG0 0x0051 198 - #define CONFIG2 0x0053 199 - 200 - #define MSR 0x0058 201 - 202 - #define CONFIG3 0x0059 203 - #define CONFIG4 0x005A 204 - /* SD3 szuyitasi: Mac0x57= CC -> B0 Mac0x60= D1 -> C6 */ 205 - /* Mac0x60 = 0x000004C6 power save parameters */ 206 - #define ANAPARM_ASIC_ON 0xB0054D00 207 - #define ANAPARM2_ASIC_ON 0x000004C6 208 - 209 - #define ANAPARM_ON ANAPARM_ASIC_ON 210 - #define ANAPARM2_ON ANAPARM2_ASIC_ON 211 - 212 - #define TESTR 0x005B 213 - 214 - #define PSR 0x005E 215 - 216 - #define BcnItv 0x0070 217 - 218 - #define AtimWnd 0x0072 219 - 220 - #define BintrItv 0x0074 221 - 222 - #define PhyAddr 0x007C 223 - #define PhyDataR 0x007E 224 - 225 - /* following are for rtl8185 */ 226 - #define RFPinsOutput 0x80 227 - #define RFPinsEnable 0x82 228 - #define RF_TIMING 0x8c 229 - #define RFPinsSelect 0x84 230 - #define ANAPARAM2 0x60 231 - #define RF_PARA 0x88 232 - #define RFPinsInput 0x86 233 - #define GP_ENABLE 0x90 234 - #define GPIO 0x91 235 - #define SW_CONTROL_GPIO 0x400 236 - #define TX_ANTENNA 0x9f 237 - #define TX_GAIN_OFDM 0x9e 238 - #define TX_GAIN_CCK 0x9d 239 - #define WPA_CONFIG 0xb0 240 - #define TX_AGC_CTL 0x9c 241 - #define TX_AGC_CTL_PERPACKET_GAIN_SHIFT 0 242 - #define TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT 1 243 - #define TX_AGC_CTL_FEEDBACK_ANT 2 244 - #define RESP_RATE 0x34 245 - #define SIFS 0xb4 246 - #define DIFS 0xb5 247 - 248 - #define SLOT 0xb6 249 - #define CW_CONF 0xbc 250 - #define CW_CONF_PERPACKET_RETRY_SHIFT 1 251 - #define CW_CONF_PERPACKET_CW_SHIFT 0 252 - #define CW_VAL 0xbd 253 - #define MAX_RESP_RATE_SHIFT 4 254 - #define MIN_RESP_RATE_SHIFT 0 255 - #define RATE_FALLBACK 0xbe 256 - 257 - #define CONFIG5 0x00D8 258 - 259 - #define PHYPR 0xDA /* 0xDA - 0x0B PHY Parameter Register. */ 260 - 261 - #define FEMR 0x1D4 /* Function Event Mask register */ 262 - 263 - #define FFER 0x00FC 264 - #define FFER_END 0x00FF 265 - 266 - 267 - 268 - /* 269 - * Bitmasks for specific register functions. 270 - * Names are derived from the register name and function name. 271 - * 272 - * <REGISTER>_<FUNCTION>[<bit>] 273 - * 274 - * this leads to some awkward names... 275 - */ 276 - 277 - #define BRSR_BPLCP ((1 << 8)) 278 - #define BRSR_MBR ((1 << 1)|(1 << 0)) 279 - #define BRSR_MBR_8185 ((1 << 11)|(1 << 10)|(1 << 9)|(1 << 8)|(1 << 7)|(1 << 6)|(1 << 5)|(1 << 4)|(1 << 3)|(1 << 2)|(1 << 1)|(1 << 0)) 280 - #define BRSR_MBR0 ((1 << 0)) 281 - #define BRSR_MBR1 ((1 << 1)) 282 - 283 - #define CR_RST ((1 << 4)) 284 - #define CR_RE ((1 << 3)) 285 - #define CR_TE ((1 << 2)) 286 - #define CR_MulRW ((1 << 0)) 287 - 288 - #define IMR_Dot11hInt ((1 << 25)) /*802.11h Measurement Interrupt */ 289 - #define IMR_BcnDmaInt ((1 << 24)) /*Beacon DMA Interrupt */ /*What differenct between BcnDmaInt and BcnInt??? */ 290 - #define IMR_WakeInt ((1 << 23)) /*Wake Up Interrupt */ 291 - #define IMR_TXFOVW ((1 << 22)) /*Tx FIFO Overflow Interrupt */ 292 - #define IMR_TimeOut1 ((1 << 21)) /*Time Out Interrupt 1 */ 293 - #define IMR_BcnInt ((1 << 20)) /*Beacon Time out Interrupt */ 294 - #define IMR_ATIMInt ((1 << 19)) /*ATIM Time Out Interrupt */ 295 - #define IMR_TBDER ((1 << 18)) /*Tx Beacon Descriptor Error Interrupt */ 296 - #define IMR_TBDOK ((1 << 17)) /*Tx Beacon Descriptor OK Interrupt */ 297 - #define IMR_THPDER ((1 << 16)) /*Tx High Priority Descriptor Error Interrupt */ 298 - #define IMR_THPDOK ((1 << 15)) /*Tx High Priority Descriptor OK Interrupt */ 299 - #define IMR_TVODER ((1 << 14)) /*Tx AC_VO Descriptor Error Interrupt */ 300 - #define IMR_TVODOK ((1 << 13)) /*Tx AC_VO Descriptor OK Interrupt */ 301 - #define IMR_FOVW ((1 << 12)) /*Rx FIFO Overflow Interrupt */ 302 - #define IMR_RDU ((1 << 11)) /*Rx Descriptor Unavailable Interrupt */ 303 - #define IMR_TVIDER ((1 << 10)) /*Tx AC_VI Descriptor Error Interrupt */ 304 - #define IMR_TVIDOK ((1 << 9)) /*Tx AC_VI Descriptor OK Interrupt */ 305 - #define IMR_RER ((1 << 8)) /*Rx Error Interrupt */ 306 - #define IMR_ROK ((1 << 7)) /*Receive OK Interrupt */ 307 - #define IMR_TBEDER ((1 << 6)) /*Tx AC_BE Descriptor Error Interrupt */ 308 - #define IMR_TBEDOK ((1 << 5)) /*Tx AC_BE Descriptor OK Interrupt */ 309 - #define IMR_TBKDER ((1 << 4)) /*Tx AC_BK Descriptor Error Interrupt */ 310 - #define IMR_TBKDOK ((1 << 3)) /*Tx AC_BK Descriptor OK Interrupt */ 311 - #define IMR_RQoSOK ((1 << 2)) /*Rx QoS OK Interrupt */ 312 - #define IMR_TimeOut2 ((1 << 1)) /*Time Out Interrupt 2 */ 313 - #define IMR_TimeOut3 ((1 << 0)) /*Time Out Interrupt 3 */ 314 - #define IMR_TMGDOK ((1 << 30)) 315 - #define ISR_Dot11hInt ((1 << 25)) /*802.11h Measurement Interrupt */ 316 - #define ISR_BcnDmaInt ((1 << 24)) /*Beacon DMA Interrupt */ /*What differenct between BcnDmaInt and BcnInt??? */ 317 - #define ISR_WakeInt ((1 << 23)) /*Wake Up Interrupt */ 318 - #define ISR_TXFOVW ((1 << 22)) /*Tx FIFO Overflow Interrupt */ 319 - #define ISR_TimeOut1 ((1 << 21)) /*Time Out Interrupt 1 */ 320 - #define ISR_BcnInt ((1 << 20)) /*Beacon Time out Interrupt */ 321 - #define ISR_ATIMInt ((1 << 19)) /*ATIM Time Out Interrupt */ 322 - #define ISR_TBDER ((1 << 18)) /*Tx Beacon Descriptor Error Interrupt */ 323 - #define ISR_TBDOK ((1 << 17)) /*Tx Beacon Descriptor OK Interrupt */ 324 - #define ISR_THPDER ((1 << 16)) /*Tx High Priority Descriptor Error Interrupt */ 325 - #define ISR_THPDOK ((1 << 15)) /*Tx High Priority Descriptor OK Interrupt */ 326 - #define ISR_TVODER ((1 << 14)) /*Tx AC_VO Descriptor Error Interrupt */ 327 - #define ISR_TVODOK ((1 << 13)) /*Tx AC_VO Descriptor OK Interrupt */ 328 - #define ISR_FOVW ((1 << 12)) /*Rx FIFO Overflow Interrupt */ 329 - #define ISR_RDU ((1 << 11)) /*Rx Descriptor Unavailable Interrupt */ 330 - #define ISR_TVIDER ((1 << 10)) /*Tx AC_VI Descriptor Error Interrupt */ 331 - #define ISR_TVIDOK ((1 << 9)) /*Tx AC_VI Descriptor OK Interrupt */ 332 - #define ISR_RER ((1 << 8)) /*Rx Error Interrupt */ 333 - #define ISR_ROK ((1 << 7)) /*Receive OK Interrupt */ 334 - #define ISR_TBEDER ((1 << 6)) /*Tx AC_BE Descriptor Error Interrupt */ 335 - #define ISR_TBEDOK ((1 << 5)) /*Tx AC_BE Descriptor OK Interrupt */ 336 - #define ISR_TBKDER ((1 << 4)) /*Tx AC_BK Descriptor Error Interrupt */ 337 - #define ISR_TBKDOK ((1 << 3)) /*Tx AC_BK Descriptor OK Interrupt */ 338 - #define ISR_RQoSOK ((1 << 2)) /*Rx QoS OK Interrupt */ 339 - #define ISR_TimeOut2 ((1 << 1)) /*Time Out Interrupt 2 */ 340 - #define ISR_TimeOut3 ((1 << 0)) /*Time Out Interrupt 3 */ 341 - 342 - /* these definition is used for Tx/Rx test temporarily */ 343 - #define ISR_TLPDER ISR_TVIDER 344 - #define ISR_TLPDOK ISR_TVIDOK 345 - #define ISR_TNPDER ISR_TVODER 346 - #define ISR_TNPDOK ISR_TVODOK 347 - #define ISR_TimeOut ISR_TimeOut1 348 - #define ISR_RXFOVW ISR_FOVW 349 - 350 - 351 - #define HW_VERID_R8180_F 3 352 - #define HW_VERID_R8180_ABCD 2 353 - #define HW_VERID_R8185_ABC 4 354 - #define HW_VERID_R8185_D 5 355 - #define HW_VERID_R8185B_B 6 356 - 357 - #define TCR_CWMIN ((1 << 31)) 358 - #define TCR_SWSEQ ((1 << 30)) 359 - #define TCR_HWVERID_MASK ((1 << 27)|(1 << 26)|(1 << 25)) 360 - #define TCR_HWVERID_SHIFT 25 361 - #define TCR_SAT ((1 << 24)) 362 - #define TCR_PLCP_LEN TCR_SAT /* rtl8180 */ 363 - #define TCR_MXDMA_MASK ((1 << 23)|(1 << 22)|(1 << 21)) 364 - #define TCR_MXDMA_1024 6 365 - #define TCR_MXDMA_2048 7 366 - #define TCR_MXDMA_SHIFT 21 367 - #define TCR_DISCW ((1 << 20)) 368 - #define TCR_ICV ((1 << 19)) 369 - #define TCR_LBK ((1 << 18)|(1 << 17)) 370 - #define TCR_LBK1 ((1 << 18)) 371 - #define TCR_LBK0 ((1 << 17)) 372 - #define TCR_CRC ((1 << 16)) 373 - #define TCR_DPRETRY_MASK ((1 << 15)|(1 << 14)|(1 << 13)|(1 << 12)|(1 << 11)|(1 << 10)|(1 << 9)|(1 << 8)) 374 - #define TCR_RTSRETRY_MASK ((1 << 0)|(1 << 1)|(1 << 2)|(1 << 3)|(1 << 4)|(1 << 5)|(1 << 6)|(1 << 7)) 375 - #define TCR_PROBE_NOTIMESTAMP_SHIFT 29 /* rtl8185 */ 376 - 377 - #define RCR_ONLYERLPKT ((1 << 31)) 378 - #define RCR_CS_SHIFT 29 379 - #define RCR_CS_MASK ((1 << 30) | (1 << 29)) 380 - #define RCR_ENMARP ((1 << 28)) 381 - #define RCR_CBSSID ((1 << 23)) 382 - #define RCR_APWRMGT ((1 << 22)) 383 - #define RCR_ADD3 ((1 << 21)) 384 - #define RCR_AMF ((1 << 20)) 385 - #define RCR_ACF ((1 << 19)) 386 - #define RCR_ADF ((1 << 18)) 387 - #define RCR_RXFTH ((1 << 15)|(1 << 14)|(1 << 13)) 388 - #define RCR_RXFTH2 ((1 << 15)) 389 - #define RCR_RXFTH1 ((1 << 14)) 390 - #define RCR_RXFTH0 ((1 << 13)) 391 - #define RCR_AICV ((1 << 12)) 392 - #define RCR_MXDMA ((1 << 10)|(1 << 9)|(1 << 8)) 393 - #define RCR_MXDMA2 ((1 << 10)) 394 - #define RCR_MXDMA1 ((1 << 9)) 395 - #define RCR_MXDMA0 ((1 << 8)) 396 - #define RCR_9356SEL ((1 << 6)) 397 - #define RCR_ACRC32 ((1 << 5)) 398 - #define RCR_AB ((1 << 3)) 399 - #define RCR_AM ((1 << 2)) 400 - #define RCR_APM ((1 << 1)) 401 - #define RCR_AAP ((1 << 0)) 402 - 403 - #define CR9346_EEM ((1 << 7)|(1 << 6)) 404 - #define CR9346_EEM1 ((1 << 7)) 405 - #define CR9346_EEM0 ((1 << 6)) 406 - #define CR9346_EECS ((1 << 3)) 407 - #define CR9346_EESK ((1 << 2)) 408 - #define CR9346_EED1 ((1 << 1)) 409 - #define CR9346_EED0 ((1 << 0)) 410 - 411 - #define CONFIG3_PARM_En ((1 << 6)) 412 - #define CONFIG3_FuncRegEn ((1 << 1)) 413 - 414 - #define CONFIG4_PWRMGT ((1 << 5)) 415 - 416 - #define MSR_LINK_MASK ((1 << 2)|(1 << 3)) 417 - #define MSR_LINK_MANAGED 2 418 - #define MSR_LINK_NONE 0 419 - #define MSR_LINK_SHIFT 2 420 - #define MSR_LINK_ADHOC 1 421 - #define MSR_LINK_MASTER 3 422 - 423 - #define BcnItv_BcnItv (0x01FF) 424 - 425 - #define AtimWnd_AtimWnd (0x01FF) 426 - 427 - #define BintrItv_BintrItv (0x01FF) 428 - 429 - #define FEMR_INTR ((1 << 15)) 430 - #define FEMR_WKUP ((1 << 14)) 431 - #define FEMR_GWAKE ((1 << 4)) 432 - 433 - #define FFER_INTR ((1 << 15)) 434 - #define FFER_GWAKE ((1 << 4)) 435 - 436 - /* Three wire mode. */ 437 - #define SW_THREE_WIRE 0 438 - #define HW_THREE_WIRE 2 439 - /* RTL8187S by amy */ 440 - #define HW_THREE_WIRE_PI 5 441 - #define HW_THREE_WIRE_SI 6 442 - /* by amy */ 443 - #define TCR_LRL_OFFSET 0 444 - #define TCR_SRL_OFFSET 8 445 - #define TCR_MXDMA_OFFSET 21 446 - #define TCR_DISReqQsize_OFFSET 28 447 - #define TCR_DurProcMode_OFFSET 30 448 - 449 - #define RCR_MXDMA_OFFSET 8 450 - #define RCR_FIFO_OFFSET 13 451 - 452 - #define AckTimeOutReg 0x79 /* ACK timeout register, in unit of 4 us. */ 453 - 454 - #define RFTiming 0x8C 455 - 456 - #define TPPollStop 0x93 457 - 458 - #define TXAGC_CTL 0x9C /*< RJ_TODO_8185B> TX_AGC_CONTROL (0x9C seems be removed at 8185B, see p37). */ 459 - #define CCK_TXAGC 0x9D 460 - #define OFDM_TXAGC 0x9E 461 - #define ANTSEL 0x9F 462 - 463 - #define ACM_CONTROL 0x00BF /* ACM Control Registe */ 464 - 465 - #define IntMig 0xE2 /* Interrupt Migration (0xE2 ~ 0xE3) */ 466 - 467 - #define TID_AC_MAP 0xE8 /* TID to AC Mapping Register */ 468 - 469 - #define ANAPARAM3 0xEE /* <RJ_TODO_8185B> How to use it? */ 470 - 471 - #define AC_VO_PARAM 0xF0 /* AC_VO Parameters Record */ 472 - #define AC_VI_PARAM 0xF4 /* AC_VI Parameters Record */ 473 - #define AC_BE_PARAM 0xF8 /* AC_BE Parameters Record */ 474 - #define AC_BK_PARAM 0xFC /* AC_BK Parameters Record */ 475 - 476 - #define GPIOCtrl 0x16B /*GPIO Control Register. */ 477 - #define ARFR 0x1E0 /* Auto Rate Fallback Register (0x1e0 ~ 0x1e2) */ 478 - 479 - #define RFSW_CTRL 0x272 /* 0x272-0x273. */ 480 - #define SW_3W_DB0 0x274 /* Software 3-wire data buffer bit 31~0. */ 481 - #define SW_3W_DB1 0x278 /* Software 3-wire data buffer bit 63~32. */ 482 - #define SW_3W_CMD0 0x27C /* Software 3-wire Control/Status Register. */ 483 - #define SW_3W_CMD1 0x27D /* Software 3-wire Control/Status Register. */ 484 - 485 - #define PI_DATA_READ 0X360 /* 0x360 - 0x361 Parallel Interface Data Register. */ 486 - #define SI_DATA_READ 0x362 /* 0x362 - 0x363 Serial Interface Data Register. */ 487 - 488 - /* 489 - ---------------------------------------------------------------------------- 490 - 8185B TPPollStop bits (offset 0x93, 1 byte) 491 - ---------------------------------------------------------------------------- 492 - */ 493 - #define TPPOLLSTOP_BQ (0x01 << 7) 494 - #define TPPOLLSTOP_AC_VIQ (0x01 << 4) 495 - 496 - #define MSR_LINK_ENEDCA (1<<4) 497 - 498 - /* 499 - ---------------------------------------------------------------------------- 500 - 8187B AC_XX_PARAM bits 501 - ---------------------------------------------------------------------------- 502 - */ 503 - #define AC_PARAM_TXOP_LIMIT_OFFSET 16 504 - #define AC_PARAM_ECW_MAX_OFFSET 12 505 - #define AC_PARAM_ECW_MIN_OFFSET 8 506 - #define AC_PARAM_AIFS_OFFSET 0 507 - 508 - /* 509 - ---------------------------------------------------------------------------- 510 - 8187B ACM_CONTROL bits (Offset 0xBF, 1 Byte) 511 - ---------------------------------------------------------------------------- 512 - */ 513 - #define VOQ_ACM_EN (0x01 << 7) /*BIT7 */ 514 - #define VIQ_ACM_EN (0x01 << 6) /*BIT6 */ 515 - #define BEQ_ACM_EN (0x01 << 5) /*BIT5 */ 516 - #define ACM_HW_EN (0x01 << 4) /*BIT4 */ 517 - #define VOQ_ACM_CTL (0x01 << 2) /*BIT2 */ /* Set to 1 when AC_VO used time reaches or exceeds the admitted time */ 518 - #define VIQ_ACM_CTL (0x01 << 1) /*BIT1 */ /* Set to 1 when AC_VI used time reaches or exceeds the admitted time */ 519 - #define BEQ_ACM_CTL (0x01 << 0) /*BIT0 */ /* Set to 1 when AC_BE used time reaches or exceeds the admitted time */ 520 - 521 - 522 - /* 523 - ---------------------------------------------------------------------------- 524 - 8185B SW_3W_CMD bits (Offset 0x27C-0x27D, 16bit) 525 - ---------------------------------------------------------------------------- 526 - */ 527 - #define SW_3W_CMD0_HOLD ((1 << 7)) 528 - #define SW_3W_CMD1_RE ((1 << 0)) /* BIT8 */ 529 - #define SW_3W_CMD1_WE ((1 << 1)) /* BIT9 */ 530 - #define SW_3W_CMD1_DONE ((1 << 2)) /* BIT10 */ 531 - 532 - #define BB_HOST_BANG_RW (1 << 3) 533 - 534 - /* 535 - ---------------------------------------------------------------------------- 536 - 8185B RATE_FALLBACK_CTL bits (Offset 0xBE, 8bit) 537 - ---------------------------------------------------------------------------- 538 - */ 539 - #define RATE_FALLBACK_CTL_ENABLE ((1 << 7)) 540 - #define RATE_FALLBACK_CTL_ENABLE_RTSCTS ((1 << 6)) 541 - /* Auto rate fallback per 2^n retry. */ 542 - #define RATE_FALLBACK_CTL_AUTO_STEP0 0x00 543 - #define RATE_FALLBACK_CTL_AUTO_STEP1 0x01 544 - #define RATE_FALLBACK_CTL_AUTO_STEP2 0x02 545 - #define RATE_FALLBACK_CTL_AUTO_STEP3 0x03 546 - 547 - 548 - #define RTL8225z2_ANAPARAM_OFF 0x55480658 549 - #define RTL8225z2_ANAPARAM2_OFF 0x72003f70 550 - /* by amy for power save */ 551 - #define RF_CHANGE_BY_HW BIT30 552 - #define RF_CHANGE_BY_PS BIT29 553 - #define RF_CHANGE_BY_IPS BIT28 554 - /* by amy for power save */ 555 - /* by amy for antenna */ 556 - #define EEPROM_SW_REVD_OFFSET 0x3f 557 - 558 - /* BIT[8-9] is for SW Antenna Diversity. 559 - * Only the value EEPROM_SW_AD_ENABLE means enable, other values are disable. 560 - */ 561 - #define EEPROM_SW_AD_MASK 0x0300 562 - #define EEPROM_SW_AD_ENABLE 0x0100 563 - 564 - /* BIT[10-11] determine if Antenna 1 is the Default Antenna. 565 - * Only the value EEPROM_DEF_ANT_1 means TRUE, other values are FALSE. 566 - */ 567 - #define EEPROM_DEF_ANT_MASK 0x0C00 568 - #define EEPROM_DEF_ANT_1 0x0400 569 - /*by amy for antenna */ 570 - /* {by amy 080312 */ 571 - /* 0x7C, 0x7D Crystal calibration and Tx Power tracking mechanism. Added by Roger. 2007.12.10. */ 572 - #define EEPROM_RSV 0x7C 573 - #define EEPROM_XTAL_CAL_XOUT_MASK 0x0F /* 0x7C[3:0], Crystal calibration for Xout. */ 574 - #define EEPROM_XTAL_CAL_XIN_MASK 0xF0 /* 0x7C[7:4], Crystal calibration for Xin. */ 575 - #define EEPROM_THERMAL_METER_MASK 0x0F00 /* 0x7D[3:0], Thermal meter reference level. */ 576 - #define EEPROM_XTAL_CAL_ENABLE 0x1000 /* 0x7D[4], Crystal calibration enabled/disabled BIT. */ 577 - #define EEPROM_THERMAL_METER_ENABLE 0x2000 /* 0x7D[5], Thermal meter enabled/disabled BIT. */ 578 - #define EN_LPF_CAL 0x238 /* Enable LPF Calibration. */ 579 - #define PWR_METER_EN BIT1 580 - /* <RJ_TODO_8185B> where are false alarm counters in 8185B? */ 581 - #define CCK_FALSE_ALARM 0xD0 582 - /* by amy 080312} */ 583 - 584 - /* YJ,add for Country IE, 080630 */ 585 - #define EEPROM_COUNTRY_CODE 0x2E 586 - /* YJ,add,080630,end */ 587 - 588 - #endif
-34
drivers/staging/rtl8187se/r8180_rtl8225.h
··· 1 - /* 2 - * This is part of the rtl8180-sa2400 driver released under the GPL (See file 3 - * COPYING for details). 4 - * 5 - * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com> 6 - * 7 - * This files contains programming code for the rtl8225 radio frontend. 8 - * 9 - * *Many* thanks to Realtek Corp. for their great support! 10 - */ 11 - 12 - #include "r8180.h" 13 - 14 - #define RTL8225_ANAPARAM_ON 0xa0000b59 15 - #define RTL8225_ANAPARAM_OFF 0xa00beb59 16 - #define RTL8225_ANAPARAM2_OFF 0x840dec11 17 - #define RTL8225_ANAPARAM2_ON 0x860dec11 18 - #define RTL8225_ANAPARAM_SLEEP 0xa00bab59 19 - #define RTL8225_ANAPARAM2_SLEEP 0x840dec11 20 - 21 - void rtl8225z2_rf_init(struct net_device *dev); 22 - void rtl8225z2_rf_set_chan(struct net_device *dev, short ch); 23 - void rtl8225z2_rf_close(struct net_device *dev); 24 - 25 - void RF_WriteReg(struct net_device *dev, u8 offset, u16 data); 26 - u16 RF_ReadReg(struct net_device *dev, u8 offset); 27 - 28 - void rtl8180_set_mode(struct net_device *dev, int mode); 29 - void rtl8180_set_mode(struct net_device *dev, int mode); 30 - bool SetZebraRFPowerState8185(struct net_device *dev, 31 - enum rt_rf_power_state eRFPowerState); 32 - void rtl8225z4_rf_sleep(struct net_device *dev); 33 - void rtl8225z4_rf_wakeup(struct net_device *dev); 34 -
-811
drivers/staging/rtl8187se/r8180_rtl8225z2.c
··· 1 - /* 2 - * This is part of the rtl8180-sa2400 driver 3 - * released under the GPL (See file COPYING for details). 4 - * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com> 5 - * 6 - * This files contains programming code for the rtl8225 7 - * radio frontend. 8 - * 9 - * *Many* thanks to Realtek Corp. for their great support! 10 - */ 11 - 12 - #include "r8180_hw.h" 13 - #include "r8180_rtl8225.h" 14 - #include "r8180_93cx6.h" 15 - 16 - #include "ieee80211/dot11d.h" 17 - 18 - static void write_rtl8225(struct net_device *dev, u8 adr, u16 data) 19 - { 20 - int i; 21 - u16 out, select; 22 - u8 bit; 23 - u32 bangdata = (data << 4) | (adr & 0xf); 24 - 25 - out = read_nic_word(dev, RFPinsOutput) & 0xfff3; 26 - 27 - write_nic_word(dev, RFPinsEnable, 28 - (read_nic_word(dev, RFPinsEnable) | 0x7)); 29 - 30 - select = read_nic_word(dev, RFPinsSelect); 31 - 32 - write_nic_word(dev, RFPinsSelect, select | 0x7 | 33 - SW_CONTROL_GPIO); 34 - 35 - force_pci_posting(dev); 36 - udelay(10); 37 - 38 - write_nic_word(dev, RFPinsOutput, out | BB_HOST_BANG_EN); 39 - 40 - force_pci_posting(dev); 41 - udelay(2); 42 - 43 - write_nic_word(dev, RFPinsOutput, out); 44 - 45 - force_pci_posting(dev); 46 - udelay(10); 47 - 48 - for (i = 15; i >= 0; i--) { 49 - bit = (bangdata & (1 << i)) >> i; 50 - 51 - write_nic_word(dev, RFPinsOutput, bit | out); 52 - 53 - write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK); 54 - write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK); 55 - 56 - i--; 57 - bit = (bangdata & (1 << i)) >> i; 58 - 59 - write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK); 60 - write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK); 61 - 62 - write_nic_word(dev, RFPinsOutput, bit | out); 63 - 64 - } 65 - 66 - write_nic_word(dev, RFPinsOutput, out | BB_HOST_BANG_EN); 67 - 68 - force_pci_posting(dev); 69 - udelay(10); 70 - 71 - write_nic_word(dev, RFPinsOutput, out | BB_HOST_BANG_EN); 72 - 73 - write_nic_word(dev, RFPinsSelect, select | SW_CONTROL_GPIO); 74 - 75 - rtl8185_rf_pins_enable(dev); 76 - } 77 - 78 - static const u8 rtl8225_agc[] = { 79 - 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 80 - 0x9d, 0x9c, 0x9b, 0x9a, 0x99, 0x98, 0x97, 0x96, 81 - 0x95, 0x94, 0x93, 0x92, 0x91, 0x90, 0x8f, 0x8e, 82 - 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86, 83 - 0x85, 0x84, 0x83, 0x82, 0x81, 0x80, 0x3f, 0x3e, 84 - 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x37, 0x36, 85 - 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, 0x2f, 0x2e, 86 - 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26, 87 - 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, 0x1f, 0x1e, 88 - 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x16, 89 - 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 90 - 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06, 91 - 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01, 92 - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 93 - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 94 - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 95 - }; 96 - 97 - static const u32 rtl8225_chan[] = { 98 - 0, 99 - 0x0080, 0x0100, 0x0180, 0x0200, 0x0280, 0x0300, 0x0380, 100 - 0x0400, 0x0480, 0x0500, 0x0580, 0x0600, 0x0680, 0x074A, 101 - }; 102 - 103 - static const u8 rtl8225z2_gain_bg[] = { 104 - 0x23, 0x15, 0xa5, /* -82-1dBm */ 105 - 0x23, 0x15, 0xb5, /* -82-2dBm */ 106 - 0x23, 0x15, 0xc5, /* -82-3dBm */ 107 - 0x33, 0x15, 0xc5, /* -78dBm */ 108 - 0x43, 0x15, 0xc5, /* -74dBm */ 109 - 0x53, 0x15, 0xc5, /* -70dBm */ 110 - 0x63, 0x15, 0xc5, /* -66dBm */ 111 - }; 112 - 113 - static const u8 rtl8225z2_gain_a[] = { 114 - 0x13, 0x27, 0x5a, /* -82dBm */ 115 - 0x23, 0x23, 0x58, /* -82dBm */ 116 - 0x33, 0x1f, 0x56, /* -82dBm */ 117 - 0x43, 0x1b, 0x54, /* -78dBm */ 118 - 0x53, 0x17, 0x51, /* -74dBm */ 119 - 0x63, 0x24, 0x4f, /* -70dBm */ 120 - 0x73, 0x0f, 0x4c, /* -66dBm */ 121 - }; 122 - 123 - static const u16 rtl8225z2_rxgain[] = { 124 - 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0408, 0x0409, 125 - 0x040a, 0x040b, 0x0502, 0x0503, 0x0504, 0x0505, 0x0540, 0x0541, 126 - 0x0542, 0x0543, 0x0544, 0x0545, 0x0580, 0x0581, 0x0582, 0x0583, 127 - 0x0584, 0x0585, 0x0588, 0x0589, 0x058a, 0x058b, 0x0643, 0x0644, 128 - 0x0645, 0x0680, 0x0681, 0x0682, 0x0683, 0x0684, 0x0685, 0x0688, 129 - 0x0689, 0x068a, 0x068b, 0x068c, 0x0742, 0x0743, 0x0744, 0x0745, 130 - 0x0780, 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0788, 0x0789, 131 - 0x078a, 0x078b, 0x078c, 0x078d, 0x0790, 0x0791, 0x0792, 0x0793, 132 - 0x0794, 0x0795, 0x0798, 0x0799, 0x079a, 0x079b, 0x079c, 0x079d, 133 - 0x07a0, 0x07a1, 0x07a2, 0x07a3, 0x07a4, 0x07a5, 0x07a8, 0x07a9, 134 - 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03b0, 0x03b1, 0x03b2, 0x03b3, 135 - 0x03b4, 0x03b5, 0x03b8, 0x03b9, 0x03ba, 0x03bb 136 - 137 - }; 138 - 139 - static void rtl8225z2_set_gain(struct net_device *dev, short gain) 140 - { 141 - const u8 *rtl8225_gain; 142 - struct r8180_priv *priv = ieee80211_priv(dev); 143 - u8 mode = priv->ieee80211->mode; 144 - 145 - if (mode == IEEE_B || mode == IEEE_G) 146 - rtl8225_gain = rtl8225z2_gain_bg; 147 - else 148 - rtl8225_gain = rtl8225z2_gain_a; 149 - 150 - write_phy_ofdm(dev, 0x0b, rtl8225_gain[gain * 3]); 151 - write_phy_ofdm(dev, 0x1b, rtl8225_gain[gain * 3 + 1]); 152 - write_phy_ofdm(dev, 0x1d, rtl8225_gain[gain * 3 + 2]); 153 - write_phy_ofdm(dev, 0x21, 0x37); 154 - } 155 - 156 - static u32 read_rtl8225(struct net_device *dev, u8 adr) 157 - { 158 - u32 data2Write = ((u32)(adr & 0x1f)) << 27; 159 - u32 dataRead; 160 - u32 mask; 161 - u16 oval, oval2, oval3, tmp; 162 - int i; 163 - short bit, rw; 164 - u8 wLength = 6; 165 - u8 rLength = 12; 166 - u8 low2high = 0; 167 - 168 - oval = read_nic_word(dev, RFPinsOutput); 169 - oval2 = read_nic_word(dev, RFPinsEnable); 170 - oval3 = read_nic_word(dev, RFPinsSelect); 171 - 172 - write_nic_word(dev, RFPinsEnable, (oval2|0xf)); 173 - write_nic_word(dev, RFPinsSelect, (oval3|0xf)); 174 - 175 - dataRead = 0; 176 - 177 - oval &= ~0xf; 178 - 179 - write_nic_word(dev, RFPinsOutput, oval | BB_HOST_BANG_EN); 180 - udelay(4); 181 - 182 - write_nic_word(dev, RFPinsOutput, oval); 183 - udelay(5); 184 - 185 - rw = 0; 186 - 187 - mask = (low2high) ? 0x01 : (((u32)0x01)<<(32-1)); 188 - 189 - for (i = 0; i < wLength/2; i++) { 190 - bit = ((data2Write&mask) != 0) ? 1 : 0; 191 - write_nic_word(dev, RFPinsOutput, bit | oval | rw); 192 - udelay(1); 193 - 194 - write_nic_word(dev, RFPinsOutput, 195 - bit | oval | BB_HOST_BANG_CLK | rw); 196 - udelay(2); 197 - write_nic_word(dev, RFPinsOutput, 198 - bit | oval | BB_HOST_BANG_CLK | rw); 199 - udelay(2); 200 - 201 - mask = (low2high) ? (mask<<1) : (mask>>1); 202 - 203 - if (i == 2) { 204 - rw = BB_HOST_BANG_RW; 205 - write_nic_word(dev, RFPinsOutput, 206 - bit | oval | BB_HOST_BANG_CLK | rw); 207 - udelay(2); 208 - write_nic_word(dev, RFPinsOutput, bit | oval | rw); 209 - udelay(2); 210 - break; 211 - } 212 - 213 - bit = ((data2Write&mask) != 0) ? 1 : 0; 214 - 215 - write_nic_word(dev, RFPinsOutput, 216 - oval | bit | rw | BB_HOST_BANG_CLK); 217 - udelay(2); 218 - write_nic_word(dev, RFPinsOutput, 219 - oval | bit | rw | BB_HOST_BANG_CLK); 220 - udelay(2); 221 - 222 - write_nic_word(dev, RFPinsOutput, oval | bit | rw); 223 - udelay(1); 224 - 225 - mask = (low2high) ? (mask<<1) : (mask>>1); 226 - } 227 - 228 - write_nic_word(dev, RFPinsOutput, rw|oval); 229 - udelay(2); 230 - mask = (low2high) ? 0x01 : (((u32)0x01) << (12-1)); 231 - 232 - /* 233 - * We must set data pin to HW controlled, otherwise RF can't driver it 234 - * and value RF register won't be able to read back properly. 235 - */ 236 - write_nic_word(dev, RFPinsEnable, (oval2 & (~0x01))); 237 - 238 - for (i = 0; i < rLength; i++) { 239 - write_nic_word(dev, RFPinsOutput, rw|oval); udelay(1); 240 - 241 - write_nic_word(dev, RFPinsOutput, rw|oval|BB_HOST_BANG_CLK); 242 - udelay(2); 243 - write_nic_word(dev, RFPinsOutput, rw|oval|BB_HOST_BANG_CLK); 244 - udelay(2); 245 - write_nic_word(dev, RFPinsOutput, rw|oval|BB_HOST_BANG_CLK); 246 - udelay(2); 247 - tmp = read_nic_word(dev, RFPinsInput); 248 - 249 - dataRead |= (tmp & BB_HOST_BANG_CLK ? mask : 0); 250 - 251 - write_nic_word(dev, RFPinsOutput, (rw|oval)); udelay(2); 252 - 253 - mask = (low2high) ? (mask<<1) : (mask>>1); 254 - } 255 - 256 - write_nic_word(dev, RFPinsOutput, 257 - BB_HOST_BANG_EN | BB_HOST_BANG_RW | oval); 258 - udelay(2); 259 - 260 - write_nic_word(dev, RFPinsEnable, oval2); 261 - write_nic_word(dev, RFPinsSelect, oval3); /* Set To SW Switch */ 262 - write_nic_word(dev, RFPinsOutput, 0x3a0); 263 - 264 - return dataRead; 265 - } 266 - 267 - void rtl8225z2_rf_close(struct net_device *dev) 268 - { 269 - RF_WriteReg(dev, 0x4, 0x1f); 270 - 271 - force_pci_posting(dev); 272 - mdelay(1); 273 - 274 - rtl8180_set_anaparam(dev, RTL8225z2_ANAPARAM_OFF); 275 - rtl8185_set_anaparam2(dev, RTL8225z2_ANAPARAM2_OFF); 276 - } 277 - 278 - /* 279 - * Map dBm into Tx power index according to current HW model, for example, 280 - * RF and PA, and current wireless mode. 281 - */ 282 - static s8 DbmToTxPwrIdx(struct r8180_priv *priv, 283 - enum wireless_mode mode, s32 PowerInDbm) 284 - { 285 - bool bUseDefault = true; 286 - s8 TxPwrIdx = 0; 287 - 288 - /* 289 - * OFDM Power in dBm = Index * 0.5 + 0 290 - * CCK Power in dBm = Index * 0.25 + 13 291 - */ 292 - s32 tmp = 0; 293 - 294 - if (mode == WIRELESS_MODE_G) { 295 - bUseDefault = false; 296 - tmp = (2 * PowerInDbm); 297 - 298 - if (tmp < 0) 299 - TxPwrIdx = 0; 300 - else if (tmp > 40) /* 40 means 20 dBm. */ 301 - TxPwrIdx = 40; 302 - else 303 - TxPwrIdx = (s8)tmp; 304 - } else if (mode == WIRELESS_MODE_B) { 305 - bUseDefault = false; 306 - tmp = (4 * PowerInDbm) - 52; 307 - 308 - if (tmp < 0) 309 - TxPwrIdx = 0; 310 - else if (tmp > 28) /* 28 means 20 dBm. */ 311 - TxPwrIdx = 28; 312 - else 313 - TxPwrIdx = (s8)tmp; 314 - } 315 - 316 - /* 317 - * TRUE if we want to use a default implementation. 318 - * We shall set it to FALSE when we have exact translation formula 319 - * for target IC. 070622, by rcnjko. 320 - */ 321 - if (bUseDefault) { 322 - if (PowerInDbm < 0) 323 - TxPwrIdx = 0; 324 - else if (PowerInDbm > 35) 325 - TxPwrIdx = 35; 326 - else 327 - TxPwrIdx = (u8)PowerInDbm; 328 - } 329 - 330 - return TxPwrIdx; 331 - } 332 - 333 - void rtl8225z2_SetTXPowerLevel(struct net_device *dev, short ch) 334 - { 335 - struct r8180_priv *priv = ieee80211_priv(dev); 336 - u8 max_cck_power_level; 337 - u8 max_ofdm_power_level; 338 - u8 min_ofdm_power_level; 339 - char cck_power_level = (char)(0xff & priv->chtxpwr[ch]); 340 - char ofdm_power_level = (char)(0xff & priv->chtxpwr_ofdm[ch]); 341 - 342 - if (IS_DOT11D_ENABLE(priv->ieee80211) && 343 - IS_DOT11D_STATE_DONE(priv->ieee80211)) { 344 - u8 MaxTxPwrInDbm = DOT11D_GetMaxTxPwrInDbm(priv->ieee80211, ch); 345 - u8 CckMaxPwrIdx = DbmToTxPwrIdx(priv, WIRELESS_MODE_B, 346 - MaxTxPwrInDbm); 347 - u8 OfdmMaxPwrIdx = DbmToTxPwrIdx(priv, WIRELESS_MODE_G, 348 - MaxTxPwrInDbm); 349 - 350 - if (cck_power_level > CckMaxPwrIdx) 351 - cck_power_level = CckMaxPwrIdx; 352 - if (ofdm_power_level > OfdmMaxPwrIdx) 353 - ofdm_power_level = OfdmMaxPwrIdx; 354 - } 355 - 356 - max_cck_power_level = 15; 357 - max_ofdm_power_level = 25; 358 - min_ofdm_power_level = 10; 359 - 360 - if (cck_power_level > 35) 361 - cck_power_level = 35; 362 - 363 - write_nic_byte(dev, CCK_TXAGC, cck_power_level); 364 - force_pci_posting(dev); 365 - mdelay(1); 366 - 367 - if (ofdm_power_level > 35) 368 - ofdm_power_level = 35; 369 - 370 - if (priv->up == 0) { 371 - write_phy_ofdm(dev, 2, 0x42); 372 - write_phy_ofdm(dev, 5, 0x00); 373 - write_phy_ofdm(dev, 6, 0x40); 374 - write_phy_ofdm(dev, 7, 0x00); 375 - write_phy_ofdm(dev, 8, 0x40); 376 - } 377 - 378 - write_nic_byte(dev, OFDM_TXAGC, ofdm_power_level); 379 - 380 - if (ofdm_power_level <= 11) { 381 - write_phy_ofdm(dev, 0x07, 0x5c); 382 - write_phy_ofdm(dev, 0x09, 0x5c); 383 - } 384 - 385 - if (ofdm_power_level <= 17) { 386 - write_phy_ofdm(dev, 0x07, 0x54); 387 - write_phy_ofdm(dev, 0x09, 0x54); 388 - } else { 389 - write_phy_ofdm(dev, 0x07, 0x50); 390 - write_phy_ofdm(dev, 0x09, 0x50); 391 - } 392 - 393 - force_pci_posting(dev); 394 - mdelay(1); 395 - } 396 - 397 - void rtl8225z2_rf_set_chan(struct net_device *dev, short ch) 398 - { 399 - rtl8225z2_SetTXPowerLevel(dev, ch); 400 - 401 - RF_WriteReg(dev, 0x7, rtl8225_chan[ch]); 402 - 403 - if ((RF_ReadReg(dev, 0x7) & 0x0F80) != rtl8225_chan[ch]) 404 - RF_WriteReg(dev, 0x7, rtl8225_chan[ch]); 405 - 406 - mdelay(1); 407 - 408 - force_pci_posting(dev); 409 - mdelay(10); 410 - } 411 - 412 - static void rtl8225_host_pci_init(struct net_device *dev) 413 - { 414 - write_nic_word(dev, RFPinsOutput, 0x480); 415 - 416 - rtl8185_rf_pins_enable(dev); 417 - 418 - write_nic_word(dev, RFPinsSelect, 0x88 | SW_CONTROL_GPIO); 419 - 420 - write_nic_byte(dev, GP_ENABLE, 0); 421 - 422 - force_pci_posting(dev); 423 - mdelay(200); 424 - 425 - /* bit 6 is for RF on/off detection */ 426 - write_nic_word(dev, GP_ENABLE, 0xff & (~(1 << 6))); 427 - } 428 - 429 - void rtl8225z2_rf_init(struct net_device *dev) 430 - { 431 - struct r8180_priv *priv = ieee80211_priv(dev); 432 - int i; 433 - short channel = 1; 434 - u16 brsr; 435 - u32 data; 436 - 437 - priv->chan = channel; 438 - 439 - rtl8225_host_pci_init(dev); 440 - 441 - write_nic_dword(dev, RF_TIMING, 0x000a8008); 442 - 443 - brsr = read_nic_word(dev, BRSR); 444 - 445 - write_nic_word(dev, BRSR, 0xffff); 446 - 447 - write_nic_dword(dev, RF_PARA, 0x100044); 448 - 449 - rtl8180_set_mode(dev, EPROM_CMD_CONFIG); 450 - write_nic_byte(dev, CONFIG3, 0x44); 451 - rtl8180_set_mode(dev, EPROM_CMD_NORMAL); 452 - 453 - rtl8185_rf_pins_enable(dev); 454 - 455 - write_rtl8225(dev, 0x0, 0x2bf); mdelay(1); 456 - write_rtl8225(dev, 0x1, 0xee0); mdelay(1); 457 - write_rtl8225(dev, 0x2, 0x44d); mdelay(1); 458 - write_rtl8225(dev, 0x3, 0x441); mdelay(1); 459 - write_rtl8225(dev, 0x4, 0x8c3); mdelay(1); 460 - write_rtl8225(dev, 0x5, 0xc72); mdelay(1); 461 - write_rtl8225(dev, 0x6, 0xe6); mdelay(1); 462 - write_rtl8225(dev, 0x7, rtl8225_chan[channel]); mdelay(1); 463 - write_rtl8225(dev, 0x8, 0x3f); mdelay(1); 464 - write_rtl8225(dev, 0x9, 0x335); mdelay(1); 465 - write_rtl8225(dev, 0xa, 0x9d4); mdelay(1); 466 - write_rtl8225(dev, 0xb, 0x7bb); mdelay(1); 467 - write_rtl8225(dev, 0xc, 0x850); mdelay(1); 468 - write_rtl8225(dev, 0xd, 0xcdf); mdelay(1); 469 - write_rtl8225(dev, 0xe, 0x2b); mdelay(1); 470 - write_rtl8225(dev, 0xf, 0x114); 471 - 472 - mdelay(100); 473 - 474 - write_rtl8225(dev, 0x0, 0x1b7); 475 - 476 - for (i = 0; i < ARRAY_SIZE(rtl8225z2_rxgain); i++) { 477 - write_rtl8225(dev, 0x1, i + 1); 478 - write_rtl8225(dev, 0x2, rtl8225z2_rxgain[i]); 479 - } 480 - 481 - write_rtl8225(dev, 0x3, 0x80); 482 - write_rtl8225(dev, 0x5, 0x4); 483 - 484 - write_rtl8225(dev, 0x0, 0xb7); 485 - 486 - write_rtl8225(dev, 0x2, 0xc4d); 487 - 488 - /* FIXME!! rtl8187 we have to check if calibrarion 489 - * is successful and eventually cal. again (repeat 490 - * the two write on reg 2) 491 - */ 492 - data = read_rtl8225(dev, 6); 493 - if (!(data & 0x00000080)) { 494 - write_rtl8225(dev, 0x02, 0x0c4d); 495 - force_pci_posting(dev); mdelay(200); 496 - write_rtl8225(dev, 0x02, 0x044d); 497 - force_pci_posting(dev); mdelay(100); 498 - data = read_rtl8225(dev, 6); 499 - if (!(data & 0x00000080)) 500 - DMESGW("RF Calibration Failed!!!!\n"); 501 - } 502 - 503 - mdelay(200); 504 - 505 - write_rtl8225(dev, 0x0, 0x2bf); 506 - 507 - for (i = 0; i < ARRAY_SIZE(rtl8225_agc); i++) { 508 - write_phy_ofdm(dev, 0xb, rtl8225_agc[i]); 509 - mdelay(1); 510 - 511 - /* enable writing AGC table */ 512 - write_phy_ofdm(dev, 0xa, i + 0x80); 513 - mdelay(1); 514 - } 515 - 516 - force_pci_posting(dev); 517 - mdelay(1); 518 - 519 - write_phy_ofdm(dev, 0x00, 0x01); mdelay(1); 520 - write_phy_ofdm(dev, 0x01, 0x02); mdelay(1); 521 - write_phy_ofdm(dev, 0x02, 0x62); mdelay(1); 522 - write_phy_ofdm(dev, 0x03, 0x00); mdelay(1); 523 - write_phy_ofdm(dev, 0x04, 0x00); mdelay(1); 524 - write_phy_ofdm(dev, 0x05, 0x00); mdelay(1); 525 - write_phy_ofdm(dev, 0x06, 0x40); mdelay(1); 526 - write_phy_ofdm(dev, 0x07, 0x00); mdelay(1); 527 - write_phy_ofdm(dev, 0x08, 0x40); mdelay(1); 528 - write_phy_ofdm(dev, 0x09, 0xfe); mdelay(1); 529 - write_phy_ofdm(dev, 0x0a, 0x08); mdelay(1); 530 - write_phy_ofdm(dev, 0x0b, 0x80); mdelay(1); 531 - write_phy_ofdm(dev, 0x0c, 0x01); mdelay(1); 532 - write_phy_ofdm(dev, 0x0d, 0x43); 533 - write_phy_ofdm(dev, 0x0e, 0xd3); mdelay(1); 534 - write_phy_ofdm(dev, 0x0f, 0x38); mdelay(1); 535 - write_phy_ofdm(dev, 0x10, 0x84); mdelay(1); 536 - write_phy_ofdm(dev, 0x11, 0x07); mdelay(1); 537 - write_phy_ofdm(dev, 0x12, 0x20); mdelay(1); 538 - write_phy_ofdm(dev, 0x13, 0x20); mdelay(1); 539 - write_phy_ofdm(dev, 0x14, 0x00); mdelay(1); 540 - write_phy_ofdm(dev, 0x15, 0x40); mdelay(1); 541 - write_phy_ofdm(dev, 0x16, 0x00); mdelay(1); 542 - write_phy_ofdm(dev, 0x17, 0x40); mdelay(1); 543 - write_phy_ofdm(dev, 0x18, 0xef); mdelay(1); 544 - write_phy_ofdm(dev, 0x19, 0x19); mdelay(1); 545 - write_phy_ofdm(dev, 0x1a, 0x20); mdelay(1); 546 - write_phy_ofdm(dev, 0x1b, 0x15); mdelay(1); 547 - write_phy_ofdm(dev, 0x1c, 0x04); mdelay(1); 548 - write_phy_ofdm(dev, 0x1d, 0xc5); mdelay(1); 549 - write_phy_ofdm(dev, 0x1e, 0x95); mdelay(1); 550 - write_phy_ofdm(dev, 0x1f, 0x75); mdelay(1); 551 - write_phy_ofdm(dev, 0x20, 0x1f); mdelay(1); 552 - write_phy_ofdm(dev, 0x21, 0x17); mdelay(1); 553 - write_phy_ofdm(dev, 0x22, 0x16); mdelay(1); 554 - write_phy_ofdm(dev, 0x23, 0x80); mdelay(1); /* FIXME maybe not needed */ 555 - write_phy_ofdm(dev, 0x24, 0x46); mdelay(1); 556 - write_phy_ofdm(dev, 0x25, 0x00); mdelay(1); 557 - write_phy_ofdm(dev, 0x26, 0x90); mdelay(1); 558 - write_phy_ofdm(dev, 0x27, 0x88); mdelay(1); 559 - 560 - rtl8225z2_set_gain(dev, 4); 561 - 562 - write_phy_cck(dev, 0x0, 0x98); mdelay(1); 563 - write_phy_cck(dev, 0x3, 0x20); mdelay(1); 564 - write_phy_cck(dev, 0x4, 0x7e); mdelay(1); 565 - write_phy_cck(dev, 0x5, 0x12); mdelay(1); 566 - write_phy_cck(dev, 0x6, 0xfc); mdelay(1); 567 - write_phy_cck(dev, 0x7, 0x78); mdelay(1); 568 - write_phy_cck(dev, 0x8, 0x2e); mdelay(1); 569 - write_phy_cck(dev, 0x10, 0x93); mdelay(1); 570 - write_phy_cck(dev, 0x11, 0x88); mdelay(1); 571 - write_phy_cck(dev, 0x12, 0x47); mdelay(1); 572 - write_phy_cck(dev, 0x13, 0xd0); 573 - write_phy_cck(dev, 0x19, 0x00); 574 - write_phy_cck(dev, 0x1a, 0xa0); 575 - write_phy_cck(dev, 0x1b, 0x08); 576 - write_phy_cck(dev, 0x40, 0x86); /* CCK Carrier Sense Threshold */ 577 - write_phy_cck(dev, 0x41, 0x8d); mdelay(1); 578 - write_phy_cck(dev, 0x42, 0x15); mdelay(1); 579 - write_phy_cck(dev, 0x43, 0x18); mdelay(1); 580 - write_phy_cck(dev, 0x44, 0x36); mdelay(1); 581 - write_phy_cck(dev, 0x45, 0x35); mdelay(1); 582 - write_phy_cck(dev, 0x46, 0x2e); mdelay(1); 583 - write_phy_cck(dev, 0x47, 0x25); mdelay(1); 584 - write_phy_cck(dev, 0x48, 0x1c); mdelay(1); 585 - write_phy_cck(dev, 0x49, 0x12); mdelay(1); 586 - write_phy_cck(dev, 0x4a, 0x09); mdelay(1); 587 - write_phy_cck(dev, 0x4b, 0x04); mdelay(1); 588 - write_phy_cck(dev, 0x4c, 0x05); mdelay(1); 589 - 590 - write_nic_byte(dev, 0x5b, 0x0d); mdelay(1); 591 - 592 - rtl8225z2_SetTXPowerLevel(dev, channel); 593 - 594 - /* RX antenna default to A */ 595 - write_phy_cck(dev, 0x11, 0x9b); mdelay(1); /* B: 0xDB */ 596 - write_phy_ofdm(dev, 0x26, 0x90); mdelay(1); /* B: 0x10 */ 597 - 598 - rtl8185_tx_antenna(dev, 0x03); /* B: 0x00 */ 599 - 600 - /* switch to high-speed 3-wire 601 - * last digit. 2 for both cck and ofdm 602 - */ 603 - write_nic_dword(dev, 0x94, 0x15c00002); 604 - rtl8185_rf_pins_enable(dev); 605 - 606 - rtl8225z2_rf_set_chan(dev, priv->chan); 607 - } 608 - 609 - #define MAX_DOZE_WAITING_TIMES_85B 20 610 - #define MAX_POLLING_24F_TIMES_87SE 10 611 - #define LPS_MAX_SLEEP_WAITING_TIMES_87SE 5 612 - 613 - bool SetZebraRFPowerState8185(struct net_device *dev, 614 - enum rt_rf_power_state eRFPowerState) 615 - { 616 - struct r8180_priv *priv = ieee80211_priv(dev); 617 - u8 btCR9346, btConfig3; 618 - bool bActionAllowed = true, bTurnOffBB = true; 619 - u8 u1bTmp; 620 - int i; 621 - bool bResult = true; 622 - u8 QueueID; 623 - 624 - if (priv->SetRFPowerStateInProgress == true) 625 - return false; 626 - 627 - priv->SetRFPowerStateInProgress = true; 628 - 629 - btCR9346 = read_nic_byte(dev, CR9346); 630 - write_nic_byte(dev, CR9346, (btCR9346 | 0xC0)); 631 - 632 - btConfig3 = read_nic_byte(dev, CONFIG3); 633 - write_nic_byte(dev, CONFIG3, (btConfig3 | CONFIG3_PARM_En)); 634 - 635 - switch (eRFPowerState) { 636 - case RF_ON: 637 - write_nic_word(dev, 0x37C, 0x00EC); 638 - 639 - /* turn on AFE */ 640 - write_nic_byte(dev, 0x54, 0x00); 641 - write_nic_byte(dev, 0x62, 0x00); 642 - 643 - /* turn on RF */ 644 - RF_WriteReg(dev, 0x0, 0x009f); udelay(500); 645 - RF_WriteReg(dev, 0x4, 0x0972); udelay(500); 646 - 647 - /* turn on RF again */ 648 - RF_WriteReg(dev, 0x0, 0x009f); udelay(500); 649 - RF_WriteReg(dev, 0x4, 0x0972); udelay(500); 650 - 651 - /* turn on BB */ 652 - write_phy_ofdm(dev, 0x10, 0x40); 653 - write_phy_ofdm(dev, 0x12, 0x40); 654 - 655 - /* Avoid power down at init time. */ 656 - write_nic_byte(dev, CONFIG4, priv->RFProgType); 657 - 658 - u1bTmp = read_nic_byte(dev, 0x24E); 659 - write_nic_byte(dev, 0x24E, (u1bTmp & (~(BIT5 | BIT6)))); 660 - break; 661 - case RF_SLEEP: 662 - for (QueueID = 0, i = 0; QueueID < 6;) { 663 - if (get_curr_tx_free_desc(dev, QueueID) == 664 - priv->txringcount) { 665 - QueueID++; 666 - continue; 667 - } else { 668 - priv->TxPollingTimes++; 669 - if (priv->TxPollingTimes >= 670 - LPS_MAX_SLEEP_WAITING_TIMES_87SE) { 671 - bActionAllowed = false; 672 - break; 673 - } else 674 - udelay(10); 675 - } 676 - } 677 - 678 - if (bActionAllowed) { 679 - /* turn off BB RXIQ matrix to cut off rx signal */ 680 - write_phy_ofdm(dev, 0x10, 0x00); 681 - write_phy_ofdm(dev, 0x12, 0x00); 682 - 683 - /* turn off RF */ 684 - RF_WriteReg(dev, 0x4, 0x0000); 685 - RF_WriteReg(dev, 0x0, 0x0000); 686 - 687 - /* turn off AFE except PLL */ 688 - write_nic_byte(dev, 0x62, 0xff); 689 - write_nic_byte(dev, 0x54, 0xec); 690 - 691 - mdelay(1); 692 - 693 - { 694 - int i = 0; 695 - while (true) { 696 - u8 tmp24F = read_nic_byte(dev, 0x24f); 697 - 698 - if ((tmp24F == 0x01) || 699 - (tmp24F == 0x09)) { 700 - bTurnOffBB = true; 701 - break; 702 - } else { 703 - udelay(10); 704 - i++; 705 - priv->TxPollingTimes++; 706 - 707 - if (priv->TxPollingTimes >= LPS_MAX_SLEEP_WAITING_TIMES_87SE) { 708 - bTurnOffBB = false; 709 - break; 710 - } else 711 - udelay(10); 712 - } 713 - } 714 - } 715 - 716 - if (bTurnOffBB) { 717 - /* turn off BB */ 718 - u1bTmp = read_nic_byte(dev, 0x24E); 719 - write_nic_byte(dev, 0x24E, 720 - (u1bTmp | BIT5 | BIT6)); 721 - 722 - /* turn off AFE PLL */ 723 - write_nic_byte(dev, 0x54, 0xFC); 724 - write_nic_word(dev, 0x37C, 0x00FC); 725 - } 726 - } 727 - break; 728 - case RF_OFF: 729 - for (QueueID = 0, i = 0; QueueID < 6;) { 730 - if (get_curr_tx_free_desc(dev, QueueID) == 731 - priv->txringcount) { 732 - QueueID++; 733 - continue; 734 - } else { 735 - udelay(10); 736 - i++; 737 - } 738 - 739 - if (i >= MAX_DOZE_WAITING_TIMES_85B) 740 - break; 741 - } 742 - 743 - /* turn off BB RXIQ matrix to cut off rx signal */ 744 - write_phy_ofdm(dev, 0x10, 0x00); 745 - write_phy_ofdm(dev, 0x12, 0x00); 746 - 747 - /* turn off RF */ 748 - RF_WriteReg(dev, 0x4, 0x0000); 749 - RF_WriteReg(dev, 0x0, 0x0000); 750 - 751 - /* turn off AFE except PLL */ 752 - write_nic_byte(dev, 0x62, 0xff); 753 - write_nic_byte(dev, 0x54, 0xec); 754 - 755 - mdelay(1); 756 - 757 - { 758 - int i = 0; 759 - 760 - while (true) { 761 - u8 tmp24F = read_nic_byte(dev, 0x24f); 762 - 763 - if ((tmp24F == 0x01) || (tmp24F == 0x09)) { 764 - bTurnOffBB = true; 765 - break; 766 - } else { 767 - bTurnOffBB = false; 768 - udelay(10); 769 - i++; 770 - } 771 - 772 - if (i > MAX_POLLING_24F_TIMES_87SE) 773 - break; 774 - } 775 - } 776 - 777 - if (bTurnOffBB) { 778 - /* turn off BB */ 779 - u1bTmp = read_nic_byte(dev, 0x24E); 780 - write_nic_byte(dev, 0x24E, (u1bTmp | BIT5 | BIT6)); 781 - 782 - /* turn off AFE PLL (80M) */ 783 - write_nic_byte(dev, 0x54, 0xFC); 784 - write_nic_word(dev, 0x37C, 0x00FC); 785 - } 786 - break; 787 - } 788 - 789 - btConfig3 &= ~(CONFIG3_PARM_En); 790 - write_nic_byte(dev, CONFIG3, btConfig3); 791 - 792 - btCR9346 &= ~(0xC0); 793 - write_nic_byte(dev, CR9346, btCR9346); 794 - 795 - if (bResult && bActionAllowed) 796 - priv->eRFPowerState = eRFPowerState; 797 - 798 - priv->SetRFPowerStateInProgress = false; 799 - 800 - return bResult && bActionAllowed; 801 - } 802 - 803 - void rtl8225z4_rf_sleep(struct net_device *dev) 804 - { 805 - MgntActSet_RF_State(dev, RF_SLEEP, RF_CHANGE_BY_PS); 806 - } 807 - 808 - void rtl8225z4_rf_wakeup(struct net_device *dev) 809 - { 810 - MgntActSet_RF_State(dev, RF_ON, RF_CHANGE_BY_PS); 811 - }
-1409
drivers/staging/rtl8187se/r8180_wx.c
··· 1 - /* 2 - This file contains wireless extension handlers. 3 - 4 - This is part of rtl8180 OpenSource driver. 5 - Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com> 6 - Released under the terms of GPL (General Public Licence) 7 - 8 - Parts of this driver are based on the GPL part 9 - of the official realtek driver. 10 - 11 - Parts of this driver are based on the rtl8180 driver skeleton 12 - from Patric Schenke & Andres Salomon. 13 - 14 - Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver. 15 - 16 - We want to thanks the Authors of those projects and the Ndiswrapper 17 - project Authors. 18 - */ 19 - 20 - 21 - #include "r8180.h" 22 - #include "r8180_hw.h" 23 - 24 - #include <net/iw_handler.h> 25 - #include "ieee80211/dot11d.h" 26 - 27 - static u32 rtl8180_rates[] = {1000000, 2000000, 5500000, 11000000, 28 - 6000000, 9000000, 12000000, 18000000, 24000000, 36000000, 48000000, 54000000}; 29 - 30 - #define RATE_COUNT ARRAY_SIZE(rtl8180_rates) 31 - 32 - static struct rtl8187se_channel_list default_channel_plan[] = { 33 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64}, 19}, /* FCC */ 34 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11}, /* IC */ 35 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64}, 21}, /* ETSI */ 36 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64}, 21}, /* Spain. Change to ETSI. */ 37 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64}, 21}, /* France. Change to ETSI. */ 38 - {{14, 36, 40, 44, 48, 52, 56, 60, 64}, 9}, /* MKK */ 39 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22}, /* MKK1 */ 40 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64}, 21}, /* Israel */ 41 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 34, 38, 42, 46}, 17}, /* For 11a , TELEC */ 42 - {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14} /* For Global Domain. 1-11:active scan, 12-14 passive scan.*/ /* +YJ, 080626 */ 43 - }; 44 - static int r8180_wx_get_freq(struct net_device *dev, 45 - struct iw_request_info *a, 46 - union iwreq_data *wrqu, char *b) 47 - { 48 - struct r8180_priv *priv = ieee80211_priv(dev); 49 - 50 - return ieee80211_wx_get_freq(priv->ieee80211, a, wrqu, b); 51 - } 52 - 53 - 54 - static int r8180_wx_set_key(struct net_device *dev, 55 - struct iw_request_info *info, 56 - union iwreq_data *wrqu, char *key) 57 - { 58 - struct r8180_priv *priv = ieee80211_priv(dev); 59 - struct iw_point *erq = &(wrqu->encoding); 60 - 61 - if (priv->ieee80211->bHwRadioOff) 62 - return 0; 63 - 64 - if (erq->length > 0) { 65 - u32 *tkey = (u32 *) key; 66 - priv->key0[0] = tkey[0]; 67 - priv->key0[1] = tkey[1]; 68 - priv->key0[2] = tkey[2]; 69 - priv->key0[3] = tkey[3] & 0xff; 70 - DMESG("Setting wep key to %x %x %x %x", 71 - tkey[0], tkey[1], tkey[2], tkey[3]); 72 - rtl8180_set_hw_wep(dev); 73 - } 74 - return 0; 75 - } 76 - 77 - 78 - static int r8180_wx_set_beaconinterval(struct net_device *dev, 79 - struct iw_request_info *aa, 80 - union iwreq_data *wrqu, char *b) 81 - { 82 - int *parms = (int *)b; 83 - int bi = parms[0]; 84 - 85 - struct r8180_priv *priv = ieee80211_priv(dev); 86 - 87 - if (priv->ieee80211->bHwRadioOff) 88 - return 0; 89 - 90 - down(&priv->wx_sem); 91 - DMESG("setting beacon interval to %x", bi); 92 - 93 - priv->ieee80211->current_network.beacon_interval = bi; 94 - rtl8180_commit(dev); 95 - up(&priv->wx_sem); 96 - 97 - return 0; 98 - } 99 - 100 - 101 - 102 - static int r8180_wx_get_mode(struct net_device *dev, struct iw_request_info *a, 103 - union iwreq_data *wrqu, char *b) 104 - { 105 - struct r8180_priv *priv = ieee80211_priv(dev); 106 - return ieee80211_wx_get_mode(priv->ieee80211, a, wrqu, b); 107 - } 108 - 109 - 110 - 111 - static int r8180_wx_get_rate(struct net_device *dev, 112 - struct iw_request_info *info, 113 - union iwreq_data *wrqu, char *extra) 114 - { 115 - struct r8180_priv *priv = ieee80211_priv(dev); 116 - return ieee80211_wx_get_rate(priv->ieee80211, info, wrqu, extra); 117 - } 118 - 119 - 120 - 121 - static int r8180_wx_set_rate(struct net_device *dev, 122 - struct iw_request_info *info, 123 - union iwreq_data *wrqu, char *extra) 124 - { 125 - int ret; 126 - struct r8180_priv *priv = ieee80211_priv(dev); 127 - 128 - 129 - if (priv->ieee80211->bHwRadioOff) 130 - return 0; 131 - 132 - down(&priv->wx_sem); 133 - 134 - ret = ieee80211_wx_set_rate(priv->ieee80211, info, wrqu, extra); 135 - 136 - up(&priv->wx_sem); 137 - 138 - return ret; 139 - } 140 - 141 - 142 - static int r8180_wx_set_crcmon(struct net_device *dev, 143 - struct iw_request_info *info, 144 - union iwreq_data *wrqu, char *extra) 145 - { 146 - struct r8180_priv *priv = ieee80211_priv(dev); 147 - int *parms = (int *)extra; 148 - int enable = (parms[0] > 0); 149 - short prev = priv->crcmon; 150 - 151 - 152 - if (priv->ieee80211->bHwRadioOff) 153 - return 0; 154 - 155 - down(&priv->wx_sem); 156 - 157 - if (enable) 158 - priv->crcmon = 1; 159 - else 160 - priv->crcmon = 0; 161 - 162 - DMESG("bad CRC in monitor mode are %s", 163 - priv->crcmon ? "accepted" : "rejected"); 164 - 165 - if (prev != priv->crcmon && priv->up) { 166 - rtl8180_down(dev); 167 - rtl8180_up(dev); 168 - } 169 - 170 - up(&priv->wx_sem); 171 - 172 - return 0; 173 - } 174 - 175 - 176 - static int r8180_wx_set_mode(struct net_device *dev, struct iw_request_info *a, 177 - union iwreq_data *wrqu, char *b) 178 - { 179 - struct r8180_priv *priv = ieee80211_priv(dev); 180 - int ret; 181 - 182 - 183 - if (priv->ieee80211->bHwRadioOff) 184 - return 0; 185 - 186 - down(&priv->wx_sem); 187 - if (priv->bInactivePs) { 188 - if (wrqu->mode == IW_MODE_ADHOC) 189 - IPSLeave(dev); 190 - } 191 - ret = ieee80211_wx_set_mode(priv->ieee80211, a, wrqu, b); 192 - 193 - up(&priv->wx_sem); 194 - return ret; 195 - } 196 - 197 - /* YJ,add,080819,for hidden ap */ 198 - struct iw_range_with_scan_capa { 199 - /* Informative stuff (to choose between different interface) */ 200 - 201 - __u32 throughput; /* To give an idea... */ 202 - 203 - /* In theory this value should be the maximum benchmarked 204 - * TCP/IP throughput, because with most of these devices the 205 - * bit rate is meaningless (overhead an co) to estimate how 206 - * fast the connection will go and pick the fastest one. 207 - * I suggest people to play with Netperf or any benchmark... 208 - */ 209 - 210 - /* NWID (or domain id) */ 211 - __u32 min_nwid; /* Minimal NWID we are able to set */ 212 - __u32 max_nwid; /* Maximal NWID we are able to set */ 213 - 214 - /* Old Frequency (backward compat - moved lower ) */ 215 - __u16 old_num_channels; 216 - __u8 old_num_frequency; 217 - 218 - /* Scan capabilities */ 219 - __u8 scan_capa; 220 - }; 221 - /* YJ,add,080819,for hidden ap */ 222 - 223 - 224 - static int rtl8180_wx_get_range(struct net_device *dev, 225 - struct iw_request_info *info, 226 - union iwreq_data *wrqu, char *extra) 227 - { 228 - struct iw_range *range = (struct iw_range *)extra; 229 - struct r8180_priv *priv = ieee80211_priv(dev); 230 - u16 val; 231 - int i; 232 - 233 - wrqu->data.length = sizeof(*range); 234 - memset(range, 0, sizeof(*range)); 235 - 236 - /* Let's try to keep this struct in the same order as in 237 - * linux/include/wireless.h 238 - */ 239 - 240 - /* TODO: See what values we can set, and remove the ones we can't 241 - * set, or fill them with some default data. 242 - */ 243 - 244 - /* ~5 Mb/s real (802.11b) */ 245 - range->throughput = 5 * 1000 * 1000; 246 - 247 - /* TODO: Not used in 802.11b? */ 248 - /* range->min_nwid; */ /* Minimal NWID we are able to set */ 249 - /* TODO: Not used in 802.11b? */ 250 - /* range->max_nwid; */ /* Maximal NWID we are able to set */ 251 - 252 - /* Old Frequency (backward compat - moved lower ) */ 253 - /* range->old_num_channels; */ 254 - /* range->old_num_frequency; */ 255 - /* range->old_freq[6]; */ /* Filler to keep "version" at the same offset */ 256 - if (priv->rf_set_sens != NULL) 257 - range->sensitivity = priv->max_sens; /* signal level threshold range */ 258 - 259 - range->max_qual.qual = 100; 260 - /* TODO: Find real max RSSI and stick here */ 261 - range->max_qual.level = 0; 262 - range->max_qual.noise = -98; 263 - range->max_qual.updated = 7; /* Updated all three */ 264 - 265 - range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */ 266 - /* TODO: Find real 'good' to 'bad' threshold value for RSSI */ 267 - range->avg_qual.level = 20 + -98; 268 - range->avg_qual.noise = 0; 269 - range->avg_qual.updated = 7; /* Updated all three */ 270 - 271 - range->num_bitrates = RATE_COUNT; 272 - 273 - for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) 274 - range->bitrate[i] = rtl8180_rates[i]; 275 - 276 - range->min_frag = MIN_FRAG_THRESHOLD; 277 - range->max_frag = MAX_FRAG_THRESHOLD; 278 - 279 - range->pm_capa = 0; 280 - 281 - range->we_version_compiled = WIRELESS_EXT; 282 - range->we_version_source = 16; 283 - 284 - range->num_channels = 14; 285 - 286 - for (i = 0, val = 0; i < 14; i++) { 287 - 288 - /* Include only legal frequencies for some countries */ 289 - if ((GET_DOT11D_INFO(priv->ieee80211)->channel_map)[i+1]) { 290 - range->freq[val].i = i + 1; 291 - range->freq[val].m = ieee80211_wlan_frequencies[i] * 100000; 292 - range->freq[val].e = 1; 293 - val++; 294 - } else { 295 - /* FIXME: do we need to set anything for channels */ 296 - /* we don't use ? */ 297 - } 298 - 299 - if (val == IW_MAX_FREQUENCIES) 300 - break; 301 - } 302 - 303 - range->num_frequency = val; 304 - range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | 305 - IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; 306 - 307 - return 0; 308 - } 309 - 310 - 311 - static int r8180_wx_set_scan(struct net_device *dev, struct iw_request_info *a, 312 - union iwreq_data *wrqu, char *b) 313 - { 314 - struct r8180_priv *priv = ieee80211_priv(dev); 315 - int ret; 316 - struct ieee80211_device *ieee = priv->ieee80211; 317 - 318 - 319 - if (priv->ieee80211->bHwRadioOff) 320 - return 0; 321 - 322 - if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { 323 - struct iw_scan_req *req = (struct iw_scan_req *)b; 324 - if (req->essid_len) { 325 - ieee->current_network.ssid_len = req->essid_len; 326 - memcpy(ieee->current_network.ssid, req->essid, req->essid_len); 327 - } 328 - } 329 - 330 - down(&priv->wx_sem); 331 - if (priv->up) { 332 - priv->ieee80211->actscanning = true; 333 - if (priv->bInactivePs && (priv->ieee80211->state != IEEE80211_LINKED)) { 334 - IPSLeave(dev); 335 - ieee80211_softmac_ips_scan_syncro(priv->ieee80211); 336 - ret = 0; 337 - } else { 338 - /* prevent scan in BusyTraffic */ 339 - /* FIXME: Need to consider last scan time */ 340 - if ((priv->link_detect.b_busy_traffic) && (true)) { 341 - ret = 0; 342 - printk("Now traffic is busy, please try later!\n"); 343 - } else 344 - /* prevent scan in BusyTraffic,end */ 345 - ret = ieee80211_wx_set_scan(priv->ieee80211, a, wrqu, b); 346 - } 347 - } else 348 - ret = -1; 349 - 350 - up(&priv->wx_sem); 351 - 352 - return ret; 353 - } 354 - 355 - 356 - static int r8180_wx_get_scan(struct net_device *dev, struct iw_request_info *a, 357 - union iwreq_data *wrqu, char *b) 358 - { 359 - 360 - int ret; 361 - struct r8180_priv *priv = ieee80211_priv(dev); 362 - 363 - down(&priv->wx_sem); 364 - if (priv->up) 365 - ret = ieee80211_wx_get_scan(priv->ieee80211, a, wrqu, b); 366 - else 367 - ret = -1; 368 - 369 - up(&priv->wx_sem); 370 - return ret; 371 - } 372 - 373 - 374 - static int r8180_wx_set_essid(struct net_device *dev, 375 - struct iw_request_info *a, 376 - union iwreq_data *wrqu, char *b) 377 - { 378 - struct r8180_priv *priv = ieee80211_priv(dev); 379 - 380 - int ret; 381 - 382 - if (priv->ieee80211->bHwRadioOff) 383 - return 0; 384 - 385 - down(&priv->wx_sem); 386 - if (priv->bInactivePs) 387 - IPSLeave(dev); 388 - 389 - ret = ieee80211_wx_set_essid(priv->ieee80211, a, wrqu, b); 390 - 391 - up(&priv->wx_sem); 392 - return ret; 393 - } 394 - 395 - 396 - static int r8180_wx_get_essid(struct net_device *dev, 397 - struct iw_request_info *a, 398 - union iwreq_data *wrqu, char *b) 399 - { 400 - int ret; 401 - struct r8180_priv *priv = ieee80211_priv(dev); 402 - 403 - down(&priv->wx_sem); 404 - 405 - ret = ieee80211_wx_get_essid(priv->ieee80211, a, wrqu, b); 406 - 407 - up(&priv->wx_sem); 408 - 409 - return ret; 410 - } 411 - 412 - 413 - static int r8180_wx_set_freq(struct net_device *dev, struct iw_request_info *a, 414 - union iwreq_data *wrqu, char *b) 415 - { 416 - int ret; 417 - struct r8180_priv *priv = ieee80211_priv(dev); 418 - 419 - 420 - if (priv->ieee80211->bHwRadioOff) 421 - return 0; 422 - 423 - down(&priv->wx_sem); 424 - 425 - ret = ieee80211_wx_set_freq(priv->ieee80211, a, wrqu, b); 426 - 427 - up(&priv->wx_sem); 428 - return ret; 429 - } 430 - 431 - 432 - static int r8180_wx_get_name(struct net_device *dev, 433 - struct iw_request_info *info, 434 - union iwreq_data *wrqu, char *extra) 435 - { 436 - struct r8180_priv *priv = ieee80211_priv(dev); 437 - return ieee80211_wx_get_name(priv->ieee80211, info, wrqu, extra); 438 - } 439 - 440 - static int r8180_wx_set_frag(struct net_device *dev, 441 - struct iw_request_info *info, 442 - union iwreq_data *wrqu, char *extra) 443 - { 444 - struct r8180_priv *priv = ieee80211_priv(dev); 445 - 446 - if (priv->ieee80211->bHwRadioOff) 447 - return 0; 448 - 449 - if (wrqu->frag.disabled) 450 - priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD; 451 - else { 452 - if (wrqu->frag.value < MIN_FRAG_THRESHOLD || 453 - wrqu->frag.value > MAX_FRAG_THRESHOLD) 454 - return -EINVAL; 455 - 456 - priv->ieee80211->fts = wrqu->frag.value & ~0x1; 457 - } 458 - 459 - return 0; 460 - } 461 - 462 - 463 - static int r8180_wx_get_frag(struct net_device *dev, 464 - struct iw_request_info *info, 465 - union iwreq_data *wrqu, char *extra) 466 - { 467 - struct r8180_priv *priv = ieee80211_priv(dev); 468 - 469 - wrqu->frag.value = priv->ieee80211->fts; 470 - wrqu->frag.fixed = 0; /* no auto select */ 471 - wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FRAG_THRESHOLD); 472 - 473 - return 0; 474 - } 475 - 476 - 477 - static int r8180_wx_set_wap(struct net_device *dev, 478 - struct iw_request_info *info, 479 - union iwreq_data *awrq, char *extra) 480 - { 481 - int ret; 482 - struct r8180_priv *priv = ieee80211_priv(dev); 483 - 484 - if (priv->ieee80211->bHwRadioOff) 485 - return 0; 486 - 487 - down(&priv->wx_sem); 488 - 489 - ret = ieee80211_wx_set_wap(priv->ieee80211, info, awrq, extra); 490 - 491 - up(&priv->wx_sem); 492 - return ret; 493 - 494 - } 495 - 496 - 497 - static int r8180_wx_get_wap(struct net_device *dev, 498 - struct iw_request_info *info, 499 - union iwreq_data *wrqu, char *extra) 500 - { 501 - struct r8180_priv *priv = ieee80211_priv(dev); 502 - 503 - return ieee80211_wx_get_wap(priv->ieee80211, info, wrqu, extra); 504 - } 505 - 506 - 507 - static int r8180_wx_set_enc(struct net_device *dev, 508 - struct iw_request_info *info, 509 - union iwreq_data *wrqu, char *key) 510 - { 511 - struct r8180_priv *priv = ieee80211_priv(dev); 512 - int ret; 513 - 514 - if (priv->ieee80211->bHwRadioOff) 515 - return 0; 516 - 517 - 518 - down(&priv->wx_sem); 519 - 520 - if (priv->hw_wep) 521 - ret = r8180_wx_set_key(dev, info, wrqu, key); 522 - else { 523 - DMESG("Setting SW wep key"); 524 - ret = ieee80211_wx_set_encode(priv->ieee80211, info, wrqu, key); 525 - } 526 - 527 - up(&priv->wx_sem); 528 - return ret; 529 - } 530 - 531 - 532 - static int r8180_wx_get_enc(struct net_device *dev, 533 - struct iw_request_info *info, 534 - union iwreq_data *wrqu, char *key) 535 - { 536 - struct r8180_priv *priv = ieee80211_priv(dev); 537 - 538 - return ieee80211_wx_get_encode(priv->ieee80211, info, wrqu, key); 539 - } 540 - 541 - 542 - static int r8180_wx_set_scan_type(struct net_device *dev, 543 - struct iw_request_info *aa, 544 - union iwreq_data *wrqu, char *p) 545 - { 546 - 547 - struct r8180_priv *priv = ieee80211_priv(dev); 548 - int *parms = (int *)p; 549 - int mode = parms[0]; 550 - 551 - if (priv->ieee80211->bHwRadioOff) 552 - return 0; 553 - 554 - priv->ieee80211->active_scan = mode; 555 - 556 - return 1; 557 - } 558 - 559 - static int r8180_wx_set_retry(struct net_device *dev, 560 - struct iw_request_info *info, 561 - union iwreq_data *wrqu, char *extra) 562 - { 563 - struct r8180_priv *priv = ieee80211_priv(dev); 564 - int err = 0; 565 - 566 - if (priv->ieee80211->bHwRadioOff) 567 - return 0; 568 - 569 - down(&priv->wx_sem); 570 - 571 - if (wrqu->retry.flags & IW_RETRY_LIFETIME || 572 - wrqu->retry.disabled) { 573 - err = -EINVAL; 574 - goto exit; 575 - } 576 - if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) { 577 - err = -EINVAL; 578 - goto exit; 579 - } 580 - 581 - if (wrqu->retry.value > R8180_MAX_RETRY) { 582 - err = -EINVAL; 583 - goto exit; 584 - } 585 - if (wrqu->retry.flags & IW_RETRY_MAX) { 586 - priv->retry_rts = wrqu->retry.value; 587 - DMESG("Setting retry for RTS/CTS data to %d", wrqu->retry.value); 588 - 589 - } else { 590 - priv->retry_data = wrqu->retry.value; 591 - DMESG("Setting retry for non RTS/CTS data to %d", wrqu->retry.value); 592 - } 593 - 594 - /* FIXME ! 595 - * We might try to write directly the TX config register 596 - * or to restart just the (R)TX process. 597 - * I'm unsure if whole reset is really needed 598 - */ 599 - 600 - rtl8180_commit(dev); 601 - exit: 602 - up(&priv->wx_sem); 603 - 604 - return err; 605 - } 606 - 607 - static int r8180_wx_get_retry(struct net_device *dev, 608 - struct iw_request_info *info, 609 - union iwreq_data *wrqu, char *extra) 610 - { 611 - struct r8180_priv *priv = ieee80211_priv(dev); 612 - 613 - 614 - wrqu->retry.disabled = 0; /* can't be disabled */ 615 - 616 - if ((wrqu->retry.flags & IW_RETRY_TYPE) == 617 - IW_RETRY_LIFETIME) 618 - return -EINVAL; 619 - 620 - if (wrqu->retry.flags & IW_RETRY_MAX) { 621 - wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; 622 - wrqu->retry.value = priv->retry_rts; 623 - } else { 624 - wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN; 625 - wrqu->retry.value = priv->retry_data; 626 - } 627 - 628 - return 0; 629 - } 630 - 631 - static int r8180_wx_get_sens(struct net_device *dev, 632 - struct iw_request_info *info, 633 - union iwreq_data *wrqu, char *extra) 634 - { 635 - struct r8180_priv *priv = ieee80211_priv(dev); 636 - if (priv->rf_set_sens == NULL) 637 - return -1; /* we have not this support for this radio */ 638 - wrqu->sens.value = priv->sens; 639 - return 0; 640 - } 641 - 642 - 643 - static int r8180_wx_set_sens(struct net_device *dev, 644 - struct iw_request_info *info, 645 - union iwreq_data *wrqu, char *extra) 646 - { 647 - 648 - struct r8180_priv *priv = ieee80211_priv(dev); 649 - 650 - short err = 0; 651 - 652 - if (priv->ieee80211->bHwRadioOff) 653 - return 0; 654 - 655 - down(&priv->wx_sem); 656 - if (priv->rf_set_sens == NULL) { 657 - err = -1; /* we have not this support for this radio */ 658 - goto exit; 659 - } 660 - if (priv->rf_set_sens(dev, wrqu->sens.value) == 0) 661 - priv->sens = wrqu->sens.value; 662 - else 663 - err = -EINVAL; 664 - 665 - exit: 666 - up(&priv->wx_sem); 667 - 668 - return err; 669 - } 670 - 671 - 672 - static int r8180_wx_set_rawtx(struct net_device *dev, 673 - struct iw_request_info *info, 674 - union iwreq_data *wrqu, char *extra) 675 - { 676 - struct r8180_priv *priv = ieee80211_priv(dev); 677 - int ret; 678 - 679 - if (priv->ieee80211->bHwRadioOff) 680 - return 0; 681 - 682 - down(&priv->wx_sem); 683 - 684 - ret = ieee80211_wx_set_rawtx(priv->ieee80211, info, wrqu, extra); 685 - 686 - up(&priv->wx_sem); 687 - 688 - return ret; 689 - 690 - } 691 - 692 - static int r8180_wx_get_power(struct net_device *dev, 693 - struct iw_request_info *info, 694 - union iwreq_data *wrqu, char *extra) 695 - { 696 - int ret; 697 - struct r8180_priv *priv = ieee80211_priv(dev); 698 - 699 - down(&priv->wx_sem); 700 - 701 - ret = ieee80211_wx_get_power(priv->ieee80211, info, wrqu, extra); 702 - 703 - up(&priv->wx_sem); 704 - 705 - return ret; 706 - } 707 - 708 - static int r8180_wx_set_power(struct net_device *dev, 709 - struct iw_request_info *info, 710 - union iwreq_data *wrqu, char *extra) 711 - { 712 - int ret; 713 - struct r8180_priv *priv = ieee80211_priv(dev); 714 - 715 - 716 - if (priv->ieee80211->bHwRadioOff) 717 - return 0; 718 - 719 - down(&priv->wx_sem); 720 - printk("=>>>>>>>>>>=============================>set power:%d, %d!\n", wrqu->power.disabled, wrqu->power.flags); 721 - if (wrqu->power.disabled == 0) { 722 - wrqu->power.flags |= IW_POWER_ALL_R; 723 - wrqu->power.flags |= IW_POWER_TIMEOUT; 724 - wrqu->power.value = 1000; 725 - } 726 - 727 - ret = ieee80211_wx_set_power(priv->ieee80211, info, wrqu, extra); 728 - 729 - up(&priv->wx_sem); 730 - 731 - return ret; 732 - } 733 - 734 - static int r8180_wx_set_rts(struct net_device *dev, 735 - struct iw_request_info *info, 736 - union iwreq_data *wrqu, char *extra) 737 - { 738 - struct r8180_priv *priv = ieee80211_priv(dev); 739 - 740 - 741 - if (priv->ieee80211->bHwRadioOff) 742 - return 0; 743 - 744 - if (wrqu->rts.disabled) 745 - priv->rts = DEFAULT_RTS_THRESHOLD; 746 - else { 747 - if (wrqu->rts.value < MIN_RTS_THRESHOLD || 748 - wrqu->rts.value > MAX_RTS_THRESHOLD) 749 - return -EINVAL; 750 - 751 - priv->rts = wrqu->rts.value; 752 - } 753 - 754 - return 0; 755 - } 756 - static int r8180_wx_get_rts(struct net_device *dev, 757 - struct iw_request_info *info, 758 - union iwreq_data *wrqu, char *extra) 759 - { 760 - struct r8180_priv *priv = ieee80211_priv(dev); 761 - 762 - 763 - 764 - wrqu->rts.value = priv->rts; 765 - wrqu->rts.fixed = 0; /* no auto select */ 766 - wrqu->rts.disabled = (wrqu->rts.value == 0); 767 - 768 - return 0; 769 - } 770 - static int dummy(struct net_device *dev, struct iw_request_info *a, 771 - union iwreq_data *wrqu, char *b) 772 - { 773 - return -1; 774 - } 775 - 776 - static int r8180_wx_get_iwmode(struct net_device *dev, 777 - struct iw_request_info *info, 778 - union iwreq_data *wrqu, char *extra) 779 - { 780 - struct r8180_priv *priv = ieee80211_priv(dev); 781 - struct ieee80211_device *ieee; 782 - int ret = 0; 783 - 784 - 785 - 786 - down(&priv->wx_sem); 787 - 788 - ieee = priv->ieee80211; 789 - 790 - strcpy(extra, "802.11"); 791 - if (ieee->modulation & IEEE80211_CCK_MODULATION) { 792 - strcat(extra, "b"); 793 - if (ieee->modulation & IEEE80211_OFDM_MODULATION) 794 - strcat(extra, "/g"); 795 - } else if (ieee->modulation & IEEE80211_OFDM_MODULATION) 796 - strcat(extra, "g"); 797 - 798 - up(&priv->wx_sem); 799 - 800 - return ret; 801 - } 802 - static int r8180_wx_set_iwmode(struct net_device *dev, 803 - struct iw_request_info *info, 804 - union iwreq_data *wrqu, char *extra) 805 - { 806 - struct r8180_priv *priv = ieee80211_priv(dev); 807 - struct ieee80211_device *ieee = priv->ieee80211; 808 - int *param = (int *)extra; 809 - int ret = 0; 810 - int modulation = 0, mode = 0; 811 - 812 - 813 - if (priv->ieee80211->bHwRadioOff) 814 - return 0; 815 - 816 - down(&priv->wx_sem); 817 - 818 - if (*param == 1) { 819 - modulation |= IEEE80211_CCK_MODULATION; 820 - mode = IEEE_B; 821 - printk(KERN_INFO "B mode!\n"); 822 - } else if (*param == 2) { 823 - modulation |= IEEE80211_OFDM_MODULATION; 824 - mode = IEEE_G; 825 - printk(KERN_INFO "G mode!\n"); 826 - } else if (*param == 3) { 827 - modulation |= IEEE80211_CCK_MODULATION; 828 - modulation |= IEEE80211_OFDM_MODULATION; 829 - mode = IEEE_B|IEEE_G; 830 - printk(KERN_INFO "B/G mode!\n"); 831 - } 832 - 833 - if (ieee->proto_started) { 834 - ieee80211_stop_protocol(ieee); 835 - ieee->mode = mode; 836 - ieee->modulation = modulation; 837 - ieee80211_start_protocol(ieee); 838 - } else { 839 - ieee->mode = mode; 840 - ieee->modulation = modulation; 841 - } 842 - 843 - up(&priv->wx_sem); 844 - 845 - return ret; 846 - } 847 - static int r8180_wx_get_preamble(struct net_device *dev, 848 - struct iw_request_info *info, 849 - union iwreq_data *wrqu, char *extra) 850 - { 851 - struct r8180_priv *priv = ieee80211_priv(dev); 852 - 853 - 854 - 855 - down(&priv->wx_sem); 856 - 857 - 858 - 859 - *extra = (char) priv->plcp_preamble_mode; /* 0:auto 1:short 2:long */ 860 - up(&priv->wx_sem); 861 - 862 - return 0; 863 - } 864 - static int r8180_wx_set_preamble(struct net_device *dev, 865 - struct iw_request_info *info, 866 - union iwreq_data *wrqu, char *extra) 867 - { 868 - struct r8180_priv *priv = ieee80211_priv(dev); 869 - int ret = 0; 870 - 871 - 872 - if (priv->ieee80211->bHwRadioOff) 873 - return 0; 874 - 875 - down(&priv->wx_sem); 876 - if (*extra < 0 || *extra > 2) 877 - ret = -1; 878 - else 879 - priv->plcp_preamble_mode = *((short *)extra); 880 - 881 - 882 - 883 - up(&priv->wx_sem); 884 - 885 - return ret; 886 - } 887 - static int r8180_wx_get_siglevel(struct net_device *dev, 888 - struct iw_request_info *info, 889 - union iwreq_data *wrqu, char *extra) 890 - { 891 - struct r8180_priv *priv = ieee80211_priv(dev); 892 - int ret = 0; 893 - 894 - 895 - 896 - down(&priv->wx_sem); 897 - /* Modify by hikaru 6.5 */ 898 - *((int *)extra) = priv->wstats.qual.level;/*for interface test ,it should be the priv->wstats.qual.level; */ 899 - 900 - 901 - 902 - up(&priv->wx_sem); 903 - 904 - return ret; 905 - } 906 - static int r8180_wx_get_sigqual(struct net_device *dev, 907 - struct iw_request_info *info, 908 - union iwreq_data *wrqu, char *extra) 909 - { 910 - struct r8180_priv *priv = ieee80211_priv(dev); 911 - int ret = 0; 912 - 913 - 914 - 915 - down(&priv->wx_sem); 916 - /* Modify by hikaru 6.5 */ 917 - *((int *)extra) = priv->wstats.qual.qual;/* for interface test ,it should be the priv->wstats.qual.qual; */ 918 - 919 - 920 - 921 - up(&priv->wx_sem); 922 - 923 - return ret; 924 - } 925 - static int r8180_wx_reset_stats(struct net_device *dev, 926 - struct iw_request_info *info, 927 - union iwreq_data *wrqu, char *extra) 928 - { 929 - struct r8180_priv *priv = ieee80211_priv(dev); 930 - down(&priv->wx_sem); 931 - 932 - priv->stats.txrdu = 0; 933 - priv->stats.rxrdu = 0; 934 - priv->stats.rxnolast = 0; 935 - priv->stats.rxnodata = 0; 936 - priv->stats.rxnopointer = 0; 937 - priv->stats.txnperr = 0; 938 - priv->stats.txresumed = 0; 939 - priv->stats.rxerr = 0; 940 - priv->stats.rxoverflow = 0; 941 - priv->stats.rxint = 0; 942 - 943 - priv->stats.txnpokint = 0; 944 - priv->stats.txhpokint = 0; 945 - priv->stats.txhperr = 0; 946 - priv->stats.ints = 0; 947 - priv->stats.shints = 0; 948 - priv->stats.txoverflow = 0; 949 - priv->stats.rxdmafail = 0; 950 - priv->stats.txbeacon = 0; 951 - priv->stats.txbeaconerr = 0; 952 - priv->stats.txlpokint = 0; 953 - priv->stats.txlperr = 0; 954 - priv->stats.txretry = 0;/* 20060601 */ 955 - priv->stats.rxcrcerrmin = 0 ; 956 - priv->stats.rxcrcerrmid = 0; 957 - priv->stats.rxcrcerrmax = 0; 958 - priv->stats.rxicverr = 0; 959 - 960 - up(&priv->wx_sem); 961 - 962 - return 0; 963 - 964 - } 965 - static int r8180_wx_radio_on(struct net_device *dev, 966 - struct iw_request_info *info, 967 - union iwreq_data *wrqu, char *extra) 968 - { 969 - struct r8180_priv *priv = ieee80211_priv(dev); 970 - 971 - if (priv->ieee80211->bHwRadioOff) 972 - return 0; 973 - 974 - 975 - down(&priv->wx_sem); 976 - priv->rf_wakeup(dev); 977 - 978 - up(&priv->wx_sem); 979 - 980 - return 0; 981 - 982 - } 983 - 984 - static int r8180_wx_radio_off(struct net_device *dev, 985 - struct iw_request_info *info, 986 - union iwreq_data *wrqu, char *extra) 987 - { 988 - struct r8180_priv *priv = ieee80211_priv(dev); 989 - 990 - if (priv->ieee80211->bHwRadioOff) 991 - return 0; 992 - 993 - 994 - down(&priv->wx_sem); 995 - priv->rf_sleep(dev); 996 - 997 - up(&priv->wx_sem); 998 - 999 - return 0; 1000 - 1001 - } 1002 - static int r8180_wx_get_channelplan(struct net_device *dev, 1003 - struct iw_request_info *info, 1004 - union iwreq_data *wrqu, char *extra) 1005 - { 1006 - struct r8180_priv *priv = ieee80211_priv(dev); 1007 - 1008 - 1009 - 1010 - down(&priv->wx_sem); 1011 - *extra = priv->channel_plan; 1012 - 1013 - 1014 - 1015 - up(&priv->wx_sem); 1016 - 1017 - return 0; 1018 - } 1019 - static int r8180_wx_set_channelplan(struct net_device *dev, 1020 - struct iw_request_info *info, 1021 - union iwreq_data *wrqu, char *extra) 1022 - { 1023 - struct r8180_priv *priv = ieee80211_priv(dev); 1024 - int *val = (int *)extra; 1025 - int i; 1026 - printk("-----in fun %s\n", __func__); 1027 - 1028 - if (priv->ieee80211->bHwRadioOff) 1029 - return 0; 1030 - 1031 - /* unsigned long flags; */ 1032 - down(&priv->wx_sem); 1033 - if (default_channel_plan[*val].len != 0) { 1034 - priv->channel_plan = *val; 1035 - /* Clear old channel map 8 */ 1036 - for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) 1037 - GET_DOT11D_INFO(priv->ieee80211)->channel_map[i] = 0; 1038 - 1039 - /* Set new channel map */ 1040 - for (i = 1; i <= default_channel_plan[*val].len; i++) 1041 - GET_DOT11D_INFO(priv->ieee80211)->channel_map[default_channel_plan[*val].channel[i-1]] = 1; 1042 - 1043 - } 1044 - up(&priv->wx_sem); 1045 - 1046 - return 0; 1047 - } 1048 - 1049 - static int r8180_wx_get_version(struct net_device *dev, 1050 - struct iw_request_info *info, 1051 - union iwreq_data *wrqu, char *extra) 1052 - { 1053 - struct r8180_priv *priv = ieee80211_priv(dev); 1054 - /* struct ieee80211_device *ieee; */ 1055 - 1056 - down(&priv->wx_sem); 1057 - strcpy(extra, "1020.0808"); 1058 - up(&priv->wx_sem); 1059 - 1060 - return 0; 1061 - } 1062 - 1063 - /* added by amy 080818 */ 1064 - /*receive datarate from user typing valid rate is from 2 to 108 (1 - 54M), if input 0, return to normal rate adaptive. */ 1065 - static int r8180_wx_set_forcerate(struct net_device *dev, 1066 - struct iw_request_info *info, 1067 - union iwreq_data *wrqu, char *extra) 1068 - { 1069 - struct r8180_priv *priv = ieee80211_priv(dev); 1070 - u8 forcerate = *extra; 1071 - 1072 - down(&priv->wx_sem); 1073 - 1074 - printk("==============>%s(): forcerate is %d\n", __func__, forcerate); 1075 - if ((forcerate == 2) || (forcerate == 4) || (forcerate == 11) || (forcerate == 22) || (forcerate == 12) || 1076 - (forcerate == 18) || (forcerate == 24) || (forcerate == 36) || (forcerate == 48) || (forcerate == 72) || 1077 - (forcerate == 96) || (forcerate == 108)) { 1078 - priv->ForcedDataRate = 1; 1079 - priv->ieee80211->rate = forcerate * 5; 1080 - } else if (forcerate == 0) { 1081 - priv->ForcedDataRate = 0; 1082 - printk("OK! return rate adaptive\n"); 1083 - } else 1084 - printk("ERR: wrong rate\n"); 1085 - up(&priv->wx_sem); 1086 - return 0; 1087 - } 1088 - 1089 - static int r8180_wx_set_enc_ext(struct net_device *dev, 1090 - struct iw_request_info *info, 1091 - union iwreq_data *wrqu, char *extra) 1092 - { 1093 - 1094 - struct r8180_priv *priv = ieee80211_priv(dev); 1095 - 1096 - int ret = 0; 1097 - 1098 - if (priv->ieee80211->bHwRadioOff) 1099 - return 0; 1100 - 1101 - down(&priv->wx_sem); 1102 - ret = ieee80211_wx_set_encode_ext(priv->ieee80211, info, wrqu, extra); 1103 - up(&priv->wx_sem); 1104 - return ret; 1105 - 1106 - } 1107 - static int r8180_wx_set_auth(struct net_device *dev, 1108 - struct iw_request_info *info, 1109 - union iwreq_data *wrqu, char *extra) 1110 - { 1111 - struct r8180_priv *priv = ieee80211_priv(dev); 1112 - int ret = 0; 1113 - 1114 - if (priv->ieee80211->bHwRadioOff) 1115 - return 0; 1116 - 1117 - down(&priv->wx_sem); 1118 - ret = ieee80211_wx_set_auth(priv->ieee80211, info, &wrqu->param, extra); 1119 - up(&priv->wx_sem); 1120 - return ret; 1121 - } 1122 - 1123 - static int r8180_wx_set_mlme(struct net_device *dev, 1124 - struct iw_request_info *info, 1125 - union iwreq_data *wrqu, char *extra) 1126 - { 1127 - int ret = 0; 1128 - struct r8180_priv *priv = ieee80211_priv(dev); 1129 - 1130 - 1131 - if (priv->ieee80211->bHwRadioOff) 1132 - return 0; 1133 - 1134 - 1135 - down(&priv->wx_sem); 1136 - #if 1 1137 - ret = ieee80211_wx_set_mlme(priv->ieee80211, info, wrqu, extra); 1138 - #endif 1139 - up(&priv->wx_sem); 1140 - return ret; 1141 - } 1142 - static int r8180_wx_set_gen_ie(struct net_device *dev, 1143 - struct iw_request_info *info, 1144 - union iwreq_data *wrqu, char *extra) 1145 - { 1146 - int ret = 0; 1147 - struct r8180_priv *priv = ieee80211_priv(dev); 1148 - 1149 - 1150 - if (priv->ieee80211->bHwRadioOff) 1151 - return 0; 1152 - 1153 - down(&priv->wx_sem); 1154 - #if 1 1155 - ret = ieee80211_wx_set_gen_ie(priv->ieee80211, extra, wrqu->data.length); 1156 - #endif 1157 - up(&priv->wx_sem); 1158 - return ret; 1159 - 1160 - 1161 - } 1162 - 1163 - static const iw_handler r8180_wx_handlers[] = { 1164 - IW_HANDLER(SIOCGIWNAME, r8180_wx_get_name), 1165 - IW_HANDLER(SIOCSIWNWID, dummy), 1166 - IW_HANDLER(SIOCGIWNWID, dummy), 1167 - IW_HANDLER(SIOCSIWFREQ, r8180_wx_set_freq), 1168 - IW_HANDLER(SIOCGIWFREQ, r8180_wx_get_freq), 1169 - IW_HANDLER(SIOCSIWMODE, r8180_wx_set_mode), 1170 - IW_HANDLER(SIOCGIWMODE, r8180_wx_get_mode), 1171 - IW_HANDLER(SIOCSIWSENS, r8180_wx_set_sens), 1172 - IW_HANDLER(SIOCGIWSENS, r8180_wx_get_sens), 1173 - IW_HANDLER(SIOCGIWRANGE, rtl8180_wx_get_range), 1174 - IW_HANDLER(SIOCSIWSPY, dummy), 1175 - IW_HANDLER(SIOCGIWSPY, dummy), 1176 - IW_HANDLER(SIOCSIWAP, r8180_wx_set_wap), 1177 - IW_HANDLER(SIOCGIWAP, r8180_wx_get_wap), 1178 - IW_HANDLER(SIOCSIWMLME, r8180_wx_set_mlme), 1179 - IW_HANDLER(SIOCGIWAPLIST, dummy), /* deprecated */ 1180 - IW_HANDLER(SIOCSIWSCAN, r8180_wx_set_scan), 1181 - IW_HANDLER(SIOCGIWSCAN, r8180_wx_get_scan), 1182 - IW_HANDLER(SIOCSIWESSID, r8180_wx_set_essid), 1183 - IW_HANDLER(SIOCGIWESSID, r8180_wx_get_essid), 1184 - IW_HANDLER(SIOCSIWNICKN, dummy), 1185 - IW_HANDLER(SIOCGIWNICKN, dummy), 1186 - IW_HANDLER(SIOCSIWRATE, r8180_wx_set_rate), 1187 - IW_HANDLER(SIOCGIWRATE, r8180_wx_get_rate), 1188 - IW_HANDLER(SIOCSIWRTS, r8180_wx_set_rts), 1189 - IW_HANDLER(SIOCGIWRTS, r8180_wx_get_rts), 1190 - IW_HANDLER(SIOCSIWFRAG, r8180_wx_set_frag), 1191 - IW_HANDLER(SIOCGIWFRAG, r8180_wx_get_frag), 1192 - IW_HANDLER(SIOCSIWTXPOW, dummy), 1193 - IW_HANDLER(SIOCGIWTXPOW, dummy), 1194 - IW_HANDLER(SIOCSIWRETRY, r8180_wx_set_retry), 1195 - IW_HANDLER(SIOCGIWRETRY, r8180_wx_get_retry), 1196 - IW_HANDLER(SIOCSIWENCODE, r8180_wx_set_enc), 1197 - IW_HANDLER(SIOCGIWENCODE, r8180_wx_get_enc), 1198 - IW_HANDLER(SIOCSIWPOWER, r8180_wx_set_power), 1199 - IW_HANDLER(SIOCGIWPOWER, r8180_wx_get_power), 1200 - IW_HANDLER(SIOCSIWGENIE, r8180_wx_set_gen_ie), 1201 - IW_HANDLER(SIOCSIWAUTH, r8180_wx_set_auth), 1202 - IW_HANDLER(SIOCSIWENCODEEXT, r8180_wx_set_enc_ext), 1203 - }; 1204 - 1205 - static const struct iw_priv_args r8180_private_args[] = { 1206 - { 1207 - SIOCIWFIRSTPRIV + 0x0, 1208 - IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "badcrc" 1209 - }, 1210 - { SIOCIWFIRSTPRIV + 0x1, 1211 - 0, 0, "dummy" 1212 - 1213 - }, 1214 - { 1215 - SIOCIWFIRSTPRIV + 0x2, 1216 - IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beaconint" 1217 - }, 1218 - { SIOCIWFIRSTPRIV + 0x3, 1219 - 0, 0, "dummy" 1220 - 1221 - }, 1222 - { 1223 - SIOCIWFIRSTPRIV + 0x4, 1224 - IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "activescan" 1225 - 1226 - }, 1227 - { SIOCIWFIRSTPRIV + 0x5, 1228 - 0, 0, "dummy" 1229 - 1230 - }, 1231 - { 1232 - SIOCIWFIRSTPRIV + 0x6, 1233 - IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "rawtx" 1234 - 1235 - }, 1236 - { SIOCIWFIRSTPRIV + 0x7, 1237 - 0, 0, "dummy" 1238 - 1239 - }, 1240 - { 1241 - SIOCIWFIRSTPRIV + 0x8, 1242 - IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setiwmode" 1243 - }, 1244 - { 1245 - SIOCIWFIRSTPRIV + 0x9, 1246 - 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 32, "getiwmode" 1247 - }, 1248 - { 1249 - SIOCIWFIRSTPRIV + 0xA, 1250 - IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setpreamble" 1251 - }, 1252 - { 1253 - SIOCIWFIRSTPRIV + 0xB, 1254 - 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpreamble" 1255 - }, 1256 - { SIOCIWFIRSTPRIV + 0xC, 1257 - 0, 0, "dummy" 1258 - }, 1259 - { 1260 - SIOCIWFIRSTPRIV + 0xD, 1261 - 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getrssi" 1262 - }, 1263 - { SIOCIWFIRSTPRIV + 0xE, 1264 - 0, 0, "dummy" 1265 - }, 1266 - { 1267 - SIOCIWFIRSTPRIV + 0xF, 1268 - 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getlinkqual" 1269 - }, 1270 - { 1271 - SIOCIWFIRSTPRIV + 0x10, 1272 - 0, 0, "resetstats" 1273 - }, 1274 - { 1275 - SIOCIWFIRSTPRIV + 0x11, 1276 - 0, 0, "dummy" 1277 - }, 1278 - { 1279 - SIOCIWFIRSTPRIV + 0x12, 1280 - 0, 0, "radioon" 1281 - }, 1282 - { 1283 - SIOCIWFIRSTPRIV + 0x13, 1284 - 0, 0, "radiooff" 1285 - }, 1286 - { 1287 - SIOCIWFIRSTPRIV + 0x14, 1288 - IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setchannel" 1289 - }, 1290 - { 1291 - SIOCIWFIRSTPRIV + 0x15, 1292 - 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getchannel" 1293 - }, 1294 - { 1295 - SIOCIWFIRSTPRIV + 0x16, 1296 - 0, 0, "dummy" 1297 - }, 1298 - { 1299 - SIOCIWFIRSTPRIV + 0x17, 1300 - 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 32, "getversion" 1301 - }, 1302 - { 1303 - SIOCIWFIRSTPRIV + 0x18, 1304 - IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setrate" 1305 - }, 1306 - }; 1307 - 1308 - 1309 - static iw_handler r8180_private_handler[] = { 1310 - r8180_wx_set_crcmon, /*SIOCIWSECONDPRIV*/ 1311 - dummy, 1312 - r8180_wx_set_beaconinterval, 1313 - dummy, 1314 - /* r8180_wx_set_monitor_type, */ 1315 - r8180_wx_set_scan_type, 1316 - dummy, 1317 - r8180_wx_set_rawtx, 1318 - dummy, 1319 - r8180_wx_set_iwmode, 1320 - r8180_wx_get_iwmode, 1321 - r8180_wx_set_preamble, 1322 - r8180_wx_get_preamble, 1323 - dummy, 1324 - r8180_wx_get_siglevel, 1325 - dummy, 1326 - r8180_wx_get_sigqual, 1327 - r8180_wx_reset_stats, 1328 - dummy,/* r8180_wx_get_stats */ 1329 - r8180_wx_radio_on, 1330 - r8180_wx_radio_off, 1331 - r8180_wx_set_channelplan, 1332 - r8180_wx_get_channelplan, 1333 - dummy, 1334 - r8180_wx_get_version, 1335 - r8180_wx_set_forcerate, 1336 - }; 1337 - 1338 - static inline int is_same_network(struct ieee80211_network *src, 1339 - struct ieee80211_network *dst, 1340 - struct ieee80211_device *ieee) 1341 - { 1342 - /* A network is only a duplicate if the channel, BSSID, ESSID 1343 - * and the capability field (in particular IBSS and BSS) all match. 1344 - * We treat all <hidden> with the same BSSID and channel 1345 - * as one network 1346 - */ 1347 - if (src->channel != dst->channel) 1348 - return 0; 1349 - 1350 - if (memcmp(src->bssid, dst->bssid, ETH_ALEN) != 0) 1351 - return 0; 1352 - 1353 - if (ieee->iw_mode != IW_MODE_INFRA) { 1354 - if (src->ssid_len != dst->ssid_len) 1355 - return 0; 1356 - if (memcmp(src->ssid, dst->ssid, src->ssid_len) != 0) 1357 - return 0; 1358 - } 1359 - 1360 - if ((src->capability & WLAN_CAPABILITY_IBSS) != 1361 - (dst->capability & WLAN_CAPABILITY_IBSS)) 1362 - return 0; 1363 - if ((src->capability & WLAN_CAPABILITY_BSS) != 1364 - (dst->capability & WLAN_CAPABILITY_BSS)) 1365 - return 0; 1366 - 1367 - return 1; 1368 - } 1369 - 1370 - /* WB modified to show signal to GUI on 18-01-2008 */ 1371 - static struct iw_statistics *r8180_get_wireless_stats(struct net_device *dev) 1372 - { 1373 - struct r8180_priv *priv = ieee80211_priv(dev); 1374 - struct ieee80211_device *ieee = priv->ieee80211; 1375 - struct iw_statistics *wstats = &priv->wstats; 1376 - int tmp_level = 0; 1377 - int tmp_qual = 0; 1378 - int tmp_noise = 0; 1379 - 1380 - if (ieee->state < IEEE80211_LINKED) { 1381 - wstats->qual.qual = 0; 1382 - wstats->qual.level = 0; 1383 - wstats->qual.noise = 0; 1384 - wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; 1385 - return wstats; 1386 - } 1387 - 1388 - tmp_level = (&ieee->current_network)->stats.signal; 1389 - tmp_qual = (&ieee->current_network)->stats.signalstrength; 1390 - tmp_noise = (&ieee->current_network)->stats.noise; 1391 - 1392 - wstats->qual.level = tmp_level; 1393 - wstats->qual.qual = tmp_qual; 1394 - wstats->qual.noise = tmp_noise; 1395 - wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; 1396 - return wstats; 1397 - } 1398 - 1399 - struct iw_handler_def r8180_wx_handlers_def = { 1400 - .standard = r8180_wx_handlers, 1401 - .num_standard = ARRAY_SIZE(r8180_wx_handlers), 1402 - .private = r8180_private_handler, 1403 - .num_private = ARRAY_SIZE(r8180_private_handler), 1404 - .num_private_args = sizeof(r8180_private_args) / sizeof(struct iw_priv_args), 1405 - .get_wireless_stats = r8180_get_wireless_stats, 1406 - .private_args = (struct iw_priv_args *)r8180_private_args, 1407 - }; 1408 - 1409 -
-21
drivers/staging/rtl8187se/r8180_wx.h
··· 1 - /* 2 - This is part of rtl8180 OpenSource driver - v 0.3 3 - Copyright (C) Andrea Merello 2004 <andrea.merello@gmail.com> 4 - Released under the terms of GPL (General Public Licence) 5 - 6 - Parts of this driver are based on the GPL part of the official realtek driver 7 - Parts of this driver are based on the rtl8180 driver skeleton from Patric Schenke & Andres Salomon 8 - Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver 9 - 10 - We want to thanks the Authors of such projects and the Ndiswrapper project Authors. 11 - */ 12 - 13 - /* this file (will) contains wireless extension handlers*/ 14 - 15 - #ifndef R8180_WX_H 16 - #define R8180_WX_H 17 - #include <linux/wireless.h> 18 - #include "ieee80211/ieee80211.h" 19 - extern struct iw_handler_def r8180_wx_handlers_def; 20 - 21 - #endif
-1464
drivers/staging/rtl8187se/r8185b_init.c
··· 1 - /* 2 - * Copyright (c) Realtek Semiconductor Corp. All rights reserved. 3 - * 4 - * Module Name: 5 - * r8185b_init.c 6 - * 7 - * Abstract: 8 - * Hardware Initialization and Hardware IO for RTL8185B 9 - * 10 - * Major Change History: 11 - * When Who What 12 - * ---------- --------------- ------------------------------- 13 - * 2006-11-15 Xiong Created 14 - * 15 - * Notes: 16 - * This file is ported from RTL8185B Windows driver. 17 - * 18 - * 19 - */ 20 - 21 - /*--------------------------Include File------------------------------------*/ 22 - #include <linux/spinlock.h> 23 - #include "r8180_hw.h" 24 - #include "r8180.h" 25 - #include "r8180_rtl8225.h" /* RTL8225 Radio frontend */ 26 - #include "r8180_93cx6.h" /* Card EEPROM */ 27 - #include "r8180_wx.h" 28 - #include "ieee80211/dot11d.h" 29 - /* #define CONFIG_RTL8180_IO_MAP */ 30 - #define TC_3W_POLL_MAX_TRY_CNT 5 31 - 32 - static u8 MAC_REG_TABLE[][2] = { 33 - /* 34 - * PAGE 0: 35 - * 0x34(BRSR), 0xBE(RATE_FALLBACK_CTL), 0x1E0(ARFR) would set in 36 - * HwConfigureRTL8185() 37 - * 0x272(RFSW_CTRL), 0x1CE(AESMSK_QC) set in InitializeAdapter8185(). 38 - * 0x1F0~0x1F8 set in MacConfig_85BASIC() 39 - */ 40 - {0x08, 0xae}, {0x0a, 0x72}, {0x5b, 0x42}, 41 - {0x84, 0x88}, {0x85, 0x24}, {0x88, 0x54}, {0x8b, 0xb8}, {0x8c, 0x03}, 42 - {0x8d, 0x40}, {0x8e, 0x00}, {0x8f, 0x00}, {0x5b, 0x18}, {0x91, 0x03}, 43 - {0x94, 0x0F}, {0x95, 0x32}, 44 - {0x96, 0x00}, {0x97, 0x07}, {0xb4, 0x22}, {0xdb, 0x00}, 45 - {0xf0, 0x32}, {0xf1, 0x32}, {0xf2, 0x00}, {0xf3, 0x00}, {0xf4, 0x32}, 46 - {0xf5, 0x43}, {0xf6, 0x00}, {0xf7, 0x00}, {0xf8, 0x46}, {0xf9, 0xa4}, 47 - {0xfa, 0x00}, {0xfb, 0x00}, {0xfc, 0x96}, {0xfd, 0xa4}, {0xfe, 0x00}, 48 - {0xff, 0x00}, 49 - 50 - /* 51 - * PAGE 1: 52 - * For Flextronics system Logo PCIHCT failure: 53 - * 0x1C4~0x1CD set no-zero value to avoid PCI configuration 54 - * space 0x45[7]=1 55 - */ 56 - {0x5e, 0x01}, 57 - {0x58, 0x00}, {0x59, 0x00}, {0x5a, 0x04}, {0x5b, 0x00}, {0x60, 0x24}, 58 - {0x61, 0x97}, {0x62, 0xF0}, {0x63, 0x09}, {0x80, 0x0F}, {0x81, 0xFF}, 59 - {0x82, 0xFF}, {0x83, 0x03}, 60 - /* lzm add 080826 */ 61 - {0xC4, 0x22}, {0xC5, 0x22}, {0xC6, 0x22}, {0xC7, 0x22}, {0xC8, 0x22}, 62 - /* lzm add 080826 */ 63 - {0xC9, 0x22}, {0xCA, 0x22}, {0xCB, 0x22}, {0xCC, 0x22}, {0xCD, 0x22}, 64 - {0xe2, 0x00}, 65 - 66 - 67 - /* PAGE 2: */ 68 - {0x5e, 0x02}, 69 - {0x0c, 0x04}, {0x4c, 0x30}, {0x4d, 0x08}, {0x50, 0x05}, {0x51, 0xf5}, 70 - {0x52, 0x04}, {0x53, 0xa0}, {0x54, 0xff}, {0x55, 0xff}, {0x56, 0xff}, 71 - {0x57, 0xff}, {0x58, 0x08}, {0x59, 0x08}, {0x5a, 0x08}, {0x5b, 0x08}, 72 - {0x60, 0x08}, {0x61, 0x08}, {0x62, 0x08}, {0x63, 0x08}, {0x64, 0x2f}, 73 - {0x8c, 0x3f}, {0x8d, 0x3f}, {0x8e, 0x3f}, 74 - {0x8f, 0x3f}, {0xc4, 0xff}, {0xc5, 0xff}, {0xc6, 0xff}, {0xc7, 0xff}, 75 - {0xc8, 0x00}, {0xc9, 0x00}, {0xca, 0x80}, {0xcb, 0x00}, 76 - 77 - /* PAGE 0: */ 78 - {0x5e, 0x00}, {0x9f, 0x03} 79 - }; 80 - 81 - 82 - static u8 ZEBRA_AGC[] = { 83 - 0, 84 - 0x7E, 0x7E, 0x7E, 0x7E, 0x7D, 0x7C, 0x7B, 0x7A, 0x79, 0x78, 0x77, 0x76, 85 - 0x75, 0x74, 0x73, 0x72, 0x71, 0x70, 0x6F, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A, 86 - 0x69, 0x68, 0x67, 0x66, 0x65, 0x64, 0x63, 0x62, 0x48, 0x47, 0x46, 0x45, 87 - 0x44, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x08, 0x07, 88 - 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 89 - 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 90 - 0x0f, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x15, 0x16, 0x17, 0x17, 0x18, 0x18, 91 - 0x19, 0x1a, 0x1a, 0x1b, 0x1b, 0x1c, 0x1c, 0x1d, 0x1d, 0x1d, 0x1e, 0x1e, 92 - 0x1f, 0x1f, 0x1f, 0x20, 0x20, 0x20, 0x20, 0x21, 0x21, 0x21, 0x22, 0x22, 93 - 0x22, 0x23, 0x23, 0x24, 0x24, 0x25, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27, 94 - 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F, 0x2F 95 - }; 96 - 97 - static u32 ZEBRA_RF_RX_GAIN_TABLE[] = { 98 - 0x0096, 0x0076, 0x0056, 0x0036, 0x0016, 0x01f6, 0x01d6, 0x01b6, 99 - 0x0196, 0x0176, 0x00F7, 0x00D7, 0x00B7, 0x0097, 0x0077, 0x0057, 100 - 0x0037, 0x00FB, 0x00DB, 0x00BB, 0x00FF, 0x00E3, 0x00C3, 0x00A3, 101 - 0x0083, 0x0063, 0x0043, 0x0023, 0x0003, 0x01E3, 0x01C3, 0x01A3, 102 - 0x0183, 0x0163, 0x0143, 0x0123, 0x0103 103 - }; 104 - 105 - static u8 OFDM_CONFIG[] = { 106 - /* OFDM reg0x06[7:0]=0xFF: Enable power saving mode in RX */ 107 - /* OFDM reg0x3C[4]=1'b1: Enable RX power saving mode */ 108 - /* ofdm 0x3a = 0x7b ,(original : 0xfb) For ECS shielding room TP test */ 109 - /* 0x00 */ 110 - 0x10, 0x0F, 0x0A, 0x0C, 0x14, 0xFA, 0xFF, 0x50, 111 - 0x00, 0x50, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00, 112 - /* 0x10 */ 113 - 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0xA8, 0x26, 114 - 0x32, 0x33, 0x06, 0xA5, 0x6F, 0x55, 0xC8, 0xBB, 115 - /* 0x20 */ 116 - 0x0A, 0xE1, 0x2C, 0x4A, 0x86, 0x83, 0x34, 0x00, 117 - 0x4F, 0x24, 0x6F, 0xC2, 0x03, 0x40, 0x80, 0x00, 118 - /* 0x30 */ 119 - 0xC0, 0xC1, 0x58, 0xF1, 0x00, 0xC4, 0x90, 0x3e, 120 - 0xD8, 0x3C, 0x7B, 0x10, 0x10 121 - }; 122 - 123 - /*--------------------------------------------------------------- 124 - * Hardware IO 125 - * the code is ported from Windows source code 126 - *--------------------------------------------------------------- 127 - */ 128 - 129 - static u8 PlatformIORead1Byte(struct net_device *dev, u32 offset) 130 - { 131 - return read_nic_byte(dev, offset); 132 - } 133 - 134 - static void PlatformIOWrite1Byte(struct net_device *dev, u32 offset, u8 data) 135 - { 136 - write_nic_byte(dev, offset, data); 137 - /* 138 - * To make sure write operation is completed, 139 - * 2005.11.09, by rcnjko. 140 - */ 141 - read_nic_byte(dev, offset); 142 - } 143 - 144 - static void PlatformIOWrite2Byte(struct net_device *dev, u32 offset, u16 data) 145 - { 146 - write_nic_word(dev, offset, data); 147 - /* 148 - * To make sure write operation is completed, 149 - * 2005.11.09, by rcnjko. 150 - */ 151 - read_nic_word(dev, offset); 152 - } 153 - 154 - static void PlatformIOWrite4Byte(struct net_device *dev, u32 offset, u32 data) 155 - { 156 - if (offset == PhyAddr) { 157 - /* For Base Band configuration. */ 158 - unsigned char cmdByte; 159 - unsigned long dataBytes; 160 - unsigned char idx; 161 - u8 u1bTmp; 162 - 163 - cmdByte = (u8)(data & 0x000000ff); 164 - dataBytes = data>>8; 165 - 166 - /* 167 - * 071010, rcnjko: 168 - * The critical section is only BB read/write race 169 - * condition. Assumption: 170 - * 1. We assume NO one will access BB at DIRQL, otherwise, 171 - * system will crash for 172 - * acquiring the spinlock in such context. 173 - * 2. PlatformIOWrite4Byte() MUST NOT be recursive. 174 - */ 175 - /* NdisAcquireSpinLock( &(pDevice->IoSpinLock) ); */ 176 - 177 - for (idx = 0; idx < 30; idx++) { 178 - /* Make sure command bit is clear before access it. */ 179 - u1bTmp = PlatformIORead1Byte(dev, PhyAddr); 180 - if ((u1bTmp & BIT7) == 0) 181 - break; 182 - else 183 - mdelay(10); 184 - } 185 - 186 - for (idx = 0; idx < 3; idx++) 187 - PlatformIOWrite1Byte(dev, offset+1+idx, 188 - ((u8 *)&dataBytes)[idx]); 189 - 190 - write_nic_byte(dev, offset, cmdByte); 191 - 192 - /* NdisReleaseSpinLock( &(pDevice->IoSpinLock) ); */ 193 - } else { 194 - write_nic_dword(dev, offset, data); 195 - /* 196 - * To make sure write operation is completed, 2005.11.09, 197 - * by rcnjko. 198 - */ 199 - read_nic_dword(dev, offset); 200 - } 201 - } 202 - 203 - static void SetOutputEnableOfRfPins(struct net_device *dev) 204 - { 205 - write_nic_word(dev, RFPinsEnable, 0x1bff); 206 - } 207 - 208 - static bool HwHSSIThreeWire(struct net_device *dev, 209 - u8 *pDataBuf, 210 - bool write) 211 - { 212 - u8 TryCnt; 213 - u8 u1bTmp; 214 - 215 - /* Check if WE and RE are cleared. */ 216 - for (TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++) { 217 - u1bTmp = read_nic_byte(dev, SW_3W_CMD1); 218 - if ((u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0) 219 - break; 220 - 221 - udelay(10); 222 - } 223 - if (TryCnt == TC_3W_POLL_MAX_TRY_CNT) { 224 - netdev_err(dev, 225 - "HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", 226 - u1bTmp); 227 - return false; 228 - } 229 - 230 - /* RTL8187S HSSI Read/Write Function */ 231 - u1bTmp = read_nic_byte(dev, RF_SW_CONFIG); 232 - u1bTmp |= RF_SW_CFG_SI; /* reg08[1]=1 Serial Interface(SI) */ 233 - write_nic_byte(dev, RF_SW_CONFIG, u1bTmp); 234 - 235 - /* jong: HW SI read must set reg84[3]=0. */ 236 - u1bTmp = read_nic_byte(dev, RFPinsSelect); 237 - u1bTmp &= ~BIT3; 238 - write_nic_byte(dev, RFPinsSelect, u1bTmp); 239 - /* Fill up data buffer for write operation. */ 240 - 241 - /* SI - reg274[3:0] : RF register's Address */ 242 - if (write) 243 - write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf)); 244 - else 245 - write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf)); 246 - 247 - /* Set up command: WE or RE. */ 248 - if (write) 249 - write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE); 250 - else 251 - write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE); 252 - 253 - 254 - /* Check if DONE is set. */ 255 - for (TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++) { 256 - u1bTmp = read_nic_byte(dev, SW_3W_CMD1); 257 - if (u1bTmp & SW_3W_CMD1_DONE) 258 - break; 259 - 260 - udelay(10); 261 - } 262 - 263 - write_nic_byte(dev, SW_3W_CMD1, 0); 264 - 265 - /* Read back data for read operation. */ 266 - if (!write) { 267 - /* Serial Interface : reg363_362[11:0] */ 268 - *((u16 *)pDataBuf) = read_nic_word(dev, SI_DATA_READ); 269 - *((u16 *)pDataBuf) &= 0x0FFF; 270 - } 271 - 272 - return true; 273 - } 274 - 275 - void RF_WriteReg(struct net_device *dev, u8 offset, u16 data) 276 - { 277 - u16 reg = (data << 4) | (offset & 0x0f); 278 - HwHSSIThreeWire(dev, (u8 *)&reg, true); 279 - } 280 - 281 - u16 RF_ReadReg(struct net_device *dev, u8 offset) 282 - { 283 - u16 reg = offset & 0x0f; 284 - HwHSSIThreeWire(dev, (u8 *)&reg, false); 285 - return reg; 286 - } 287 - 288 - static u8 ReadBBPortUchar(struct net_device *dev, u32 addr) 289 - { 290 - PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f); 291 - return PlatformIORead1Byte(dev, PhyDataR); 292 - } 293 - 294 - /* by Owen on 04/07/14 for writing BB register successfully */ 295 - static void WriteBBPortUchar(struct net_device *dev, u32 Data) 296 - { 297 - PlatformIOWrite4Byte(dev, PhyAddr, Data); 298 - ReadBBPortUchar(dev, Data); 299 - } 300 - 301 - /* 302 - * Description: 303 - * Perform Antenna settings with antenna diversity on 87SE. 304 - * Created by Roger, 2008.01.25. 305 - */ 306 - bool SetAntennaConfig87SE(struct net_device *dev, 307 - u8 DefaultAnt, /* 0: Main, 1: Aux. */ 308 - bool bAntDiversity) /* 1:Enable, 0: Disable. */ 309 - { 310 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 311 - bool bAntennaSwitched = true; 312 - /* 0x00 = disabled, 0x80 = enabled */ 313 - u8 ant_diversity_offset = 0x00; 314 - 315 - /* 316 - * printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", 317 - * DefaultAnt, bAntDiversity); 318 - */ 319 - 320 - /* Threshold for antenna diversity. */ 321 - write_phy_cck(dev, 0x0c, 0x09); /* Reg0c : 09 */ 322 - 323 - if (bAntDiversity) /* Enable Antenna Diversity. */ 324 - ant_diversity_offset = 0x80; 325 - 326 - if (DefaultAnt == 1) { /* aux Antenna */ 327 - /* Mac register, aux antenna */ 328 - write_nic_byte(dev, ANTSEL, 0x00); 329 - 330 - /* Config CCK RX antenna. */ 331 - write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */ 332 - 333 - /* Reg01 : 47 | ant_diversity_offset */ 334 - write_phy_cck(dev, 0x01, 0x47|ant_diversity_offset); 335 - 336 - /* Config OFDM RX antenna. */ 337 - write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */ 338 - /* Reg18 : 32 */ 339 - write_phy_ofdm(dev, 0x18, 0x32|ant_diversity_offset); 340 - } else { /* main Antenna */ 341 - /* Mac register, main antenna */ 342 - write_nic_byte(dev, ANTSEL, 0x03); 343 - 344 - /* Config CCK RX antenna. */ 345 - write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */ 346 - /* Reg01 : 47 */ 347 - write_phy_cck(dev, 0x01, 0x47|ant_diversity_offset); 348 - 349 - /* Config OFDM RX antenna. */ 350 - write_phy_ofdm(dev, 0x0D, 0x5c); /* Reg0d : 5c */ 351 - /*Reg18 : 32 */ 352 - write_phy_ofdm(dev, 0x18, 0x32|ant_diversity_offset); 353 - } 354 - priv->CurrAntennaIndex = DefaultAnt; /* Update default settings. */ 355 - return bAntennaSwitched; 356 - } 357 - /* 358 - *-------------------------------------------------------------- 359 - * Hardware Initialization. 360 - * the code is ported from Windows source code 361 - *-------------------------------------------------------------- 362 - */ 363 - 364 - static void ZEBRA_Config_85BASIC_HardCode(struct net_device *dev) 365 - { 366 - 367 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 368 - u32 i; 369 - u32 addr, data; 370 - u32 u4bRegOffset, u4bRegValue; 371 - u16 u4bRF23, u4bRF24; 372 - u8 u1b24E; 373 - int d_cut = 0; 374 - 375 - 376 - /* 377 - *=========================================================================== 378 - * 87S_PCIE :: RADIOCFG.TXT 379 - *=========================================================================== 380 - */ 381 - 382 - 383 - /* Page1 : reg16-reg30 */ 384 - RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); /* switch to page1 */ 385 - u4bRF23 = RF_ReadReg(dev, 0x08); mdelay(1); 386 - u4bRF24 = RF_ReadReg(dev, 0x09); mdelay(1); 387 - 388 - if (u4bRF23 == 0x818 && u4bRF24 == 0x70C) { 389 - d_cut = 1; 390 - netdev_info(dev, "card type changed from C- to D-cut\n"); 391 - } 392 - 393 - /* Page0 : reg0-reg15 */ 394 - 395 - RF_WriteReg(dev, 0x00, 0x009f); mdelay(1);/* 1 */ 396 - RF_WriteReg(dev, 0x01, 0x06e0); mdelay(1); 397 - RF_WriteReg(dev, 0x02, 0x004d); mdelay(1);/* 2 */ 398 - RF_WriteReg(dev, 0x03, 0x07f1); mdelay(1);/* 3 */ 399 - RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); 400 - RF_WriteReg(dev, 0x05, 0x0c72); mdelay(1); 401 - RF_WriteReg(dev, 0x06, 0x0ae6); mdelay(1); 402 - RF_WriteReg(dev, 0x07, 0x00ca); mdelay(1); 403 - RF_WriteReg(dev, 0x08, 0x0e1c); mdelay(1); 404 - RF_WriteReg(dev, 0x09, 0x02f0); mdelay(1); 405 - RF_WriteReg(dev, 0x0a, 0x09d0); mdelay(1); 406 - RF_WriteReg(dev, 0x0b, 0x01ba); mdelay(1); 407 - RF_WriteReg(dev, 0x0c, 0x0640); mdelay(1); 408 - RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1); 409 - RF_WriteReg(dev, 0x0e, 0x0020); mdelay(1); 410 - RF_WriteReg(dev, 0x0f, 0x0990); mdelay(1); 411 - 412 - /* Page1 : reg16-reg30 */ 413 - RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); 414 - RF_WriteReg(dev, 0x03, 0x0806); mdelay(1); 415 - RF_WriteReg(dev, 0x04, 0x03a7); mdelay(1); 416 - RF_WriteReg(dev, 0x05, 0x059b); mdelay(1); 417 - RF_WriteReg(dev, 0x06, 0x0081); mdelay(1); 418 - RF_WriteReg(dev, 0x07, 0x01A0); mdelay(1); 419 - /* 420 - * Don't write RF23/RF24 to make a difference between 87S C cut and D cut. 421 - * asked by SD3 stevenl. 422 - */ 423 - RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1); 424 - RF_WriteReg(dev, 0x0b, 0x0418); mdelay(1); 425 - 426 - if (d_cut) { 427 - RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1); 428 - RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); 429 - /* RX LO buffer */ 430 - RF_WriteReg(dev, 0x0e, 0x0807); mdelay(1); 431 - } else { 432 - RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1); 433 - RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); 434 - /* RX LO buffer */ 435 - RF_WriteReg(dev, 0x0e, 0x0806); mdelay(1); 436 - } 437 - 438 - RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1); 439 - RF_WriteReg(dev, 0x00, 0x01d7); mdelay(1); /* 6 */ 440 - RF_WriteReg(dev, 0x03, 0x0e00); mdelay(1); 441 - RF_WriteReg(dev, 0x04, 0x0e50); mdelay(1); 442 - 443 - for (i = 0; i <= 36; i++) { 444 - RF_WriteReg(dev, 0x01, i); mdelay(1); 445 - RF_WriteReg(dev, 0x02, ZEBRA_RF_RX_GAIN_TABLE[i]); mdelay(1); 446 - } 447 - 448 - RF_WriteReg(dev, 0x05, 0x0203); mdelay(1); /* 203, 343 */ 449 - RF_WriteReg(dev, 0x06, 0x0200); mdelay(1); /* 400 */ 450 - /* switch to reg16-reg30, and HSSI disable 137 */ 451 - RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); 452 - mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 453 - 454 - /* Z4 synthesizer loop filter setting, 392 */ 455 - RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); 456 - mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 457 - 458 - /* switch to reg0-reg15, and HSSI disable */ 459 - RF_WriteReg(dev, 0x00, 0x0037); mdelay(1); 460 - mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 461 - 462 - /* CBC on, Tx Rx disable, High gain */ 463 - RF_WriteReg(dev, 0x04, 0x0160); mdelay(1); 464 - mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 465 - 466 - /* Z4 setted channel 1 */ 467 - RF_WriteReg(dev, 0x07, 0x0080); mdelay(1); 468 - mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 469 - 470 - RF_WriteReg(dev, 0x02, 0x088D); mdelay(1); /* LC calibration */ 471 - mdelay(200); /* Deay 200 ms. */ /* 0xfd */ 472 - mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 473 - mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 474 - 475 - /* switch to reg16-reg30 137, and HSSI disable 137 */ 476 - RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); 477 - mdelay(10); /* Deay 10 ms. */ /* 0xfd */ 478 - 479 - RF_WriteReg(dev, 0x07, 0x0000); mdelay(1); 480 - RF_WriteReg(dev, 0x07, 0x0180); mdelay(1); 481 - RF_WriteReg(dev, 0x07, 0x0220); mdelay(1); 482 - RF_WriteReg(dev, 0x07, 0x03E0); mdelay(1); 483 - 484 - /* DAC calibration off 20070702 */ 485 - RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1); 486 - RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1); 487 - /* For crystal calibration, added by Roger, 2007.12.11. */ 488 - if (priv->bXtalCalibration) { /* reg 30. */ 489 - /* 490 - * enable crystal calibration. 491 - * RF Reg[30], (1)Xin:[12:9], Xout:[8:5], addr[4:0]. 492 - * (2)PA Pwr delay timer[15:14], default: 2.4us, 493 - * set BIT15=0 494 - * (3)RF signal on/off when calibration[13], default: on, 495 - * set BIT13=0. 496 - * So we should minus 4 BITs offset. 497 - */ 498 - RF_WriteReg(dev, 0x0f, (priv->XtalCal_Xin<<5) | 499 - (priv->XtalCal_Xout<<1) | BIT11 | BIT9); mdelay(1); 500 - netdev_info(dev, "ZEBRA_Config_85BASIC_HardCode(): (%02x)\n", 501 - (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | 502 - BIT11 | BIT9); 503 - } else { 504 - /* using default value. Xin=6, Xout=6. */ 505 - RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1); 506 - } 507 - /* switch to reg0-reg15, and HSSI enable */ 508 - RF_WriteReg(dev, 0x00, 0x00bf); mdelay(1); 509 - /* Rx BB start calibration, 00c//+edward */ 510 - RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1); 511 - /* temperature meter off */ 512 - RF_WriteReg(dev, 0x02, 0x004d); mdelay(1); 513 - RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); /* Rx mode */ 514 - mdelay(10); /* Deay 10 ms.*/ /* 0xfe */ 515 - mdelay(10); /* Deay 10 ms.*/ /* 0xfe */ 516 - mdelay(10); /* Deay 10 ms.*/ /* 0xfe */ 517 - /* Rx mode*/ /*+edward */ 518 - RF_WriteReg(dev, 0x00, 0x0197); mdelay(1); 519 - /* Rx mode*/ /*+edward */ 520 - RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1); 521 - /* Rx mode*/ /*+edward */ 522 - RF_WriteReg(dev, 0x00, 0x009f); mdelay(1); 523 - /* Rx mode*/ /*+edward */ 524 - RF_WriteReg(dev, 0x01, 0x0000); mdelay(1); 525 - /* Rx mode*/ /*+edward */ 526 - RF_WriteReg(dev, 0x02, 0x0000); mdelay(1); 527 - /* power save parameters. */ 528 - u1b24E = read_nic_byte(dev, 0x24E); 529 - write_nic_byte(dev, 0x24E, (u1b24E & (~(BIT5|BIT6)))); 530 - 531 - /*====================================================================== 532 - * 533 - *====================================================================== 534 - * CCKCONF.TXT 535 - *====================================================================== 536 - * 537 - * [POWER SAVE] Power Saving Parameters by jong. 2007-11-27 538 - * CCK reg0x00[7]=1'b1 :power saving for TX (default) 539 - * CCK reg0x00[6]=1'b1: power saving for RX (default) 540 - * CCK reg0x06[4]=1'b1: turn off channel estimation related 541 - * circuits if not doing channel estimation. 542 - * CCK reg0x06[3]=1'b1: turn off unused circuits before cca = 1 543 - * CCK reg0x06[2]=1'b1: turn off cck's circuit if macrst =0 544 - */ 545 - 546 - write_phy_cck(dev, 0x00, 0xc8); 547 - write_phy_cck(dev, 0x06, 0x1c); 548 - write_phy_cck(dev, 0x10, 0x78); 549 - write_phy_cck(dev, 0x2e, 0xd0); 550 - write_phy_cck(dev, 0x2f, 0x06); 551 - write_phy_cck(dev, 0x01, 0x46); 552 - 553 - /* power control */ 554 - write_nic_byte(dev, CCK_TXAGC, 0x10); 555 - write_nic_byte(dev, OFDM_TXAGC, 0x1B); 556 - write_nic_byte(dev, ANTSEL, 0x03); 557 - 558 - 559 - 560 - /* 561 - *====================================================================== 562 - * AGC.txt 563 - *====================================================================== 564 - */ 565 - 566 - write_phy_ofdm(dev, 0x00, 0x12); 567 - 568 - for (i = 0; i < 128; i++) { 569 - 570 - data = ZEBRA_AGC[i+1]; 571 - data = data << 8; 572 - data = data | 0x0000008F; 573 - 574 - addr = i + 0x80; /* enable writing AGC table */ 575 - addr = addr << 8; 576 - addr = addr | 0x0000008E; 577 - 578 - WriteBBPortUchar(dev, data); 579 - WriteBBPortUchar(dev, addr); 580 - WriteBBPortUchar(dev, 0x0000008E); 581 - } 582 - 583 - PlatformIOWrite4Byte(dev, PhyAddr, 0x00001080); /* Annie, 2006-05-05 */ 584 - 585 - /* 586 - *====================================================================== 587 - * 588 - *====================================================================== 589 - * OFDMCONF.TXT 590 - *====================================================================== 591 - */ 592 - 593 - for (i = 0; i < 60; i++) { 594 - u4bRegOffset = i; 595 - u4bRegValue = OFDM_CONFIG[i]; 596 - 597 - WriteBBPortUchar(dev, 598 - (0x00000080 | 599 - (u4bRegOffset & 0x7f) | 600 - ((u4bRegValue & 0xff) << 8))); 601 - } 602 - 603 - /* 604 - *====================================================================== 605 - * by amy for antenna 606 - *====================================================================== 607 - */ 608 - /* 609 - * Config Sw/Hw Combinational Antenna Diversity. Added by Roger, 610 - * 2008.02.26. 611 - */ 612 - SetAntennaConfig87SE(dev, priv->bDefaultAntenna1, 613 - priv->bSwAntennaDiverity); 614 - } 615 - 616 - 617 - void UpdateInitialGain(struct net_device *dev) 618 - { 619 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 620 - 621 - /* lzm add 080826 */ 622 - if (priv->eRFPowerState != RF_ON) { 623 - /* Don't access BB/RF under disable PLL situation. 624 - * RT_TRACE(COMP_DIG, DBG_LOUD, ("UpdateInitialGain - 625 - * pHalData->eRFPowerState!=RF_ON\n")); 626 - * Back to the original state 627 - */ 628 - priv->InitialGain = priv->InitialGainBackUp; 629 - return; 630 - } 631 - 632 - switch (priv->InitialGain) { 633 - case 1: /* m861dBm */ 634 - write_phy_ofdm(dev, 0x17, 0x26); mdelay(1); 635 - write_phy_ofdm(dev, 0x24, 0x86); mdelay(1); 636 - write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1); 637 - break; 638 - 639 - case 2: /* m862dBm */ 640 - write_phy_ofdm(dev, 0x17, 0x36); mdelay(1); 641 - write_phy_ofdm(dev, 0x24, 0x86); mdelay(1); 642 - write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1); 643 - break; 644 - 645 - case 3: /* m863dBm */ 646 - write_phy_ofdm(dev, 0x17, 0x36); mdelay(1); 647 - write_phy_ofdm(dev, 0x24, 0x86); mdelay(1); 648 - write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1); 649 - break; 650 - 651 - case 4: /* m864dBm */ 652 - write_phy_ofdm(dev, 0x17, 0x46); mdelay(1); 653 - write_phy_ofdm(dev, 0x24, 0x86); mdelay(1); 654 - write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1); 655 - break; 656 - 657 - case 5: /* m82dBm */ 658 - write_phy_ofdm(dev, 0x17, 0x46); mdelay(1); 659 - write_phy_ofdm(dev, 0x24, 0x96); mdelay(1); 660 - write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1); 661 - break; 662 - 663 - case 6: /* m78dBm */ 664 - write_phy_ofdm(dev, 0x17, 0x56); mdelay(1); 665 - write_phy_ofdm(dev, 0x24, 0x96); mdelay(1); 666 - write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1); 667 - break; 668 - 669 - case 7: /* m74dBm */ 670 - write_phy_ofdm(dev, 0x17, 0x56); mdelay(1); 671 - write_phy_ofdm(dev, 0x24, 0xa6); mdelay(1); 672 - write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1); 673 - break; 674 - 675 - case 8: 676 - write_phy_ofdm(dev, 0x17, 0x66); mdelay(1); 677 - write_phy_ofdm(dev, 0x24, 0xb6); mdelay(1); 678 - write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1); 679 - break; 680 - 681 - default: /* MP */ 682 - write_phy_ofdm(dev, 0x17, 0x26); mdelay(1); 683 - write_phy_ofdm(dev, 0x24, 0x86); mdelay(1); 684 - write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1); 685 - break; 686 - } 687 - } 688 - /* 689 - * Description: 690 - * Tx Power tracking mechanism routine on 87SE. 691 - * Created by Roger, 2007.12.11. 692 - */ 693 - static void InitTxPwrTracking87SE(struct net_device *dev) 694 - { 695 - u32 u4bRfReg; 696 - 697 - u4bRfReg = RF_ReadReg(dev, 0x02); 698 - 699 - /* Enable Thermal meter indication. */ 700 - RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1); 701 - } 702 - 703 - static void PhyConfig8185(struct net_device *dev) 704 - { 705 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 706 - write_nic_dword(dev, RCR, priv->ReceiveConfig); 707 - priv->RFProgType = read_nic_byte(dev, CONFIG4) & 0x03; 708 - /* RF config */ 709 - ZEBRA_Config_85BASIC_HardCode(dev); 710 - /* Set default initial gain state to 4, approved by SD3 DZ, by Bruce, 711 - * 2007-06-06. 712 - */ 713 - if (priv->bDigMechanism) { 714 - if (priv->InitialGain == 0) 715 - priv->InitialGain = 4; 716 - } 717 - 718 - /* 719 - * Enable thermal meter indication to implement TxPower tracking 720 - * on 87SE. We initialize thermal meter here to avoid unsuccessful 721 - * configuration. Added by Roger, 2007.12.11. 722 - */ 723 - if (priv->bTxPowerTrack) 724 - InitTxPwrTracking87SE(dev); 725 - 726 - priv->InitialGainBackUp = priv->InitialGain; 727 - UpdateInitialGain(dev); 728 - 729 - return; 730 - } 731 - 732 - static void HwConfigureRTL8185(struct net_device *dev) 733 - { 734 - /* 735 - * RTL8185_TODO: Determine Retrylimit, TxAGC, 736 - * AutoRateFallback control. 737 - */ 738 - u8 bUNIVERSAL_CONTROL_RL = 0; 739 - u8 bUNIVERSAL_CONTROL_AGC = 1; 740 - u8 bUNIVERSAL_CONTROL_ANT = 1; 741 - u8 bAUTO_RATE_FALLBACK_CTL = 1; 742 - u8 val8; 743 - write_nic_word(dev, BRSR, 0x0fff); 744 - /* Retry limit */ 745 - val8 = read_nic_byte(dev, CW_CONF); 746 - 747 - if (bUNIVERSAL_CONTROL_RL) 748 - val8 = val8 & 0xfd; 749 - else 750 - val8 = val8 | 0x02; 751 - 752 - write_nic_byte(dev, CW_CONF, val8); 753 - 754 - /* Tx AGC */ 755 - val8 = read_nic_byte(dev, TXAGC_CTL); 756 - if (bUNIVERSAL_CONTROL_AGC) { 757 - write_nic_byte(dev, CCK_TXAGC, 128); 758 - write_nic_byte(dev, OFDM_TXAGC, 128); 759 - val8 = val8 & 0xfe; 760 - } else { 761 - val8 = val8 | 0x01; 762 - } 763 - 764 - 765 - write_nic_byte(dev, TXAGC_CTL, val8); 766 - 767 - /* Tx Antenna including Feedback control */ 768 - val8 = read_nic_byte(dev, TXAGC_CTL); 769 - 770 - if (bUNIVERSAL_CONTROL_ANT) { 771 - write_nic_byte(dev, ANTSEL, 0x00); 772 - val8 = val8 & 0xfd; 773 - } else { 774 - val8 = val8 & (val8|0x02); /* xiong-2006-11-15 */ 775 - } 776 - 777 - write_nic_byte(dev, TXAGC_CTL, val8); 778 - 779 - /* Auto Rate fallback control */ 780 - val8 = read_nic_byte(dev, RATE_FALLBACK); 781 - val8 &= 0x7c; 782 - if (bAUTO_RATE_FALLBACK_CTL) { 783 - val8 |= RATE_FALLBACK_CTL_ENABLE | RATE_FALLBACK_CTL_AUTO_STEP1; 784 - 785 - /* <RJ_TODO_8185B> We shall set up the ARFR according 786 - * to user's setting. 787 - */ 788 - PlatformIOWrite2Byte(dev, ARFR, 0x0fff); /* set 1M ~ 54Mbps. */ 789 - } 790 - write_nic_byte(dev, RATE_FALLBACK, val8); 791 - } 792 - 793 - static void MacConfig_85BASIC_HardCode(struct net_device *dev) 794 - { 795 - /* 796 - *====================================================================== 797 - * MACREG.TXT 798 - *====================================================================== 799 - */ 800 - int nLinesRead = 0; 801 - u32 u4bRegOffset, u4bRegValue, u4bPageIndex = 0; 802 - int i; 803 - 804 - nLinesRead = sizeof(MAC_REG_TABLE)/2; 805 - 806 - for (i = 0; i < nLinesRead; i++) { /* nLinesRead=101 */ 807 - u4bRegOffset = MAC_REG_TABLE[i][0]; 808 - u4bRegValue = MAC_REG_TABLE[i][1]; 809 - 810 - if (u4bRegOffset == 0x5e) 811 - u4bPageIndex = u4bRegValue; 812 - else 813 - u4bRegOffset |= (u4bPageIndex << 8); 814 - 815 - write_nic_byte(dev, u4bRegOffset, (u8)u4bRegValue); 816 - } 817 - /* ================================================================= */ 818 - } 819 - 820 - static void MacConfig_85BASIC(struct net_device *dev) 821 - { 822 - 823 - u8 u1DA; 824 - MacConfig_85BASIC_HardCode(dev); 825 - 826 - /* ================================================================= */ 827 - 828 - /* Follow TID_AC_MAP of WMac. */ 829 - write_nic_word(dev, TID_AC_MAP, 0xfa50); 830 - 831 - /* Interrupt Migration, Jong suggested we use set 0x0000 first, 832 - * 2005.12.14, by rcnjko. 833 - */ 834 - write_nic_word(dev, IntMig, 0x0000); 835 - 836 - /* Prevent TPC to cause CRC error. Added by Annie, 2006-06-10. */ 837 - PlatformIOWrite4Byte(dev, 0x1F0, 0x00000000); 838 - PlatformIOWrite4Byte(dev, 0x1F4, 0x00000000); 839 - PlatformIOWrite1Byte(dev, 0x1F8, 0x00); 840 - 841 - /* Asked for by SD3 CM Lin, 2006.06.27, by rcnjko. */ 842 - 843 - /* 844 - * power save parameter based on 845 - * "87SE power save parameters 20071127.doc", as follow. 846 - */ 847 - 848 - /* Enable DA10 TX power saving */ 849 - u1DA = read_nic_byte(dev, PHYPR); 850 - write_nic_byte(dev, PHYPR, (u1DA | BIT2)); 851 - 852 - /* POWER: */ 853 - write_nic_word(dev, 0x360, 0x1000); 854 - write_nic_word(dev, 0x362, 0x1000); 855 - 856 - /* AFE. */ 857 - write_nic_word(dev, 0x370, 0x0560); 858 - write_nic_word(dev, 0x372, 0x0560); 859 - write_nic_word(dev, 0x374, 0x0DA4); 860 - write_nic_word(dev, 0x376, 0x0DA4); 861 - write_nic_word(dev, 0x378, 0x0560); 862 - write_nic_word(dev, 0x37A, 0x0560); 863 - write_nic_word(dev, 0x37C, 0x00EC); 864 - write_nic_word(dev, 0x37E, 0x00EC); /* +edward */ 865 - write_nic_byte(dev, 0x24E, 0x01); 866 - } 867 - 868 - static u8 GetSupportedWirelessMode8185(struct net_device *dev) 869 - { 870 - return WIRELESS_MODE_B | WIRELESS_MODE_G; 871 - } 872 - 873 - static void 874 - ActUpdateChannelAccessSetting(struct net_device *dev, 875 - enum wireless_mode mode, 876 - struct chnl_access_setting *chnl_access_setting) 877 - { 878 - AC_CODING eACI; 879 - 880 - /* 881 - * <RJ_TODO_8185B> 882 - * TODO: We still don't know how to set up these registers, 883 - * just follow WMAC to verify 8185B FPAG. 884 - * 885 - * <RJ_TODO_8185B> 886 - * Jong said CWmin/CWmax register are not functional in 8185B, 887 - * so we shall fill channel access realted register into AC 888 - * parameter registers, 889 - * even in nQBss. 890 - */ 891 - 892 - /* Suggested by Jong, 2005.12.08. */ 893 - chnl_access_setting->sifs_timer = 0x22; 894 - chnl_access_setting->difs_timer = 0x1C; /* 2006.06.02, by rcnjko. */ 895 - chnl_access_setting->slot_time_timer = 9; /* 2006.06.02, by rcnjko. */ 896 - /* 897 - * Suggested by wcchu, it is the default value of EIFS register, 898 - * 2005.12.08. 899 - */ 900 - chnl_access_setting->eifs_timer = 0x5B; 901 - chnl_access_setting->cwmin_index = 3; /* 2006.06.02, by rcnjko. */ 902 - chnl_access_setting->cwmax_index = 7; /* 2006.06.02, by rcnjko. */ 903 - 904 - write_nic_byte(dev, SIFS, chnl_access_setting->sifs_timer); 905 - /* 906 - * Rewrited from directly use PlatformEFIOWrite1Byte(), 907 - * by Annie, 2006-03-29. 908 - */ 909 - write_nic_byte(dev, SLOT, chnl_access_setting->slot_time_timer); 910 - 911 - write_nic_byte(dev, EIFS, chnl_access_setting->eifs_timer); 912 - 913 - /* 914 - * <RJ_EXPR_QOS> Suggested by wcchu, it is the default value of EIFS 915 - * register, 2005.12.08. 916 - */ 917 - write_nic_byte(dev, AckTimeOutReg, 0x5B); 918 - 919 - for (eACI = 0; eACI < AC_MAX; eACI++) 920 - write_nic_byte(dev, ACM_CONTROL, 0); 921 - } 922 - 923 - static void ActSetWirelessMode8185(struct net_device *dev, u8 btWirelessMode) 924 - { 925 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 926 - struct ieee80211_device *ieee = priv->ieee80211; 927 - u8 btSupportedWirelessMode = GetSupportedWirelessMode8185(dev); 928 - 929 - if ((btWirelessMode & btSupportedWirelessMode) == 0) { 930 - /* 931 - * Don't switch to unsupported wireless mode, 2006.02.15, 932 - * by rcnjko. 933 - */ 934 - DMESGW("ActSetWirelessMode8185(): WirelessMode(%d) is not supported (%d)!\n", 935 - btWirelessMode, btSupportedWirelessMode); 936 - return; 937 - } 938 - 939 - /* 1. Assign wireless mode to switch if necessary. */ 940 - if (btWirelessMode == WIRELESS_MODE_AUTO) { 941 - if ((btSupportedWirelessMode & WIRELESS_MODE_A)) { 942 - btWirelessMode = WIRELESS_MODE_A; 943 - } else if (btSupportedWirelessMode & WIRELESS_MODE_G) { 944 - btWirelessMode = WIRELESS_MODE_G; 945 - 946 - } else if ((btSupportedWirelessMode & WIRELESS_MODE_B)) { 947 - btWirelessMode = WIRELESS_MODE_B; 948 - } else { 949 - DMESGW("ActSetWirelessMode8185(): No valid wireless mode supported, btSupportedWirelessMode(%x)!!!\n", 950 - btSupportedWirelessMode); 951 - btWirelessMode = WIRELESS_MODE_B; 952 - } 953 - } 954 - 955 - /* 956 - * 2. Swtich band: RF or BB specific actions, 957 - * for example, refresh tables in omc8255, or change initial gain if 958 - * necessary. Nothing to do for Zebra to switch band. Update current 959 - * wireless mode if we switch to specified band successfully. 960 - */ 961 - 962 - ieee->mode = (enum wireless_mode)btWirelessMode; 963 - 964 - /* 3. Change related setting. */ 965 - if (ieee->mode == WIRELESS_MODE_A) 966 - DMESG("WIRELESS_MODE_A\n"); 967 - else if (ieee->mode == WIRELESS_MODE_B) 968 - DMESG("WIRELESS_MODE_B\n"); 969 - else if (ieee->mode == WIRELESS_MODE_G) 970 - DMESG("WIRELESS_MODE_G\n"); 971 - 972 - ActUpdateChannelAccessSetting(dev, ieee->mode, 973 - &priv->ChannelAccessSetting); 974 - } 975 - 976 - void rtl8185b_irq_enable(struct net_device *dev) 977 - { 978 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 979 - 980 - priv->irq_enabled = 1; 981 - write_nic_dword(dev, IMR, priv->IntrMask); 982 - } 983 - 984 - static void MgntDisconnectIBSS(struct net_device *dev) 985 - { 986 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 987 - u8 i; 988 - 989 - for (i = 0; i < 6; i++) 990 - priv->ieee80211->current_network.bssid[i] = 0x55; 991 - 992 - 993 - 994 - priv->ieee80211->state = IEEE80211_NOLINK; 995 - /* 996 - * Stop Beacon. 997 - * 998 - * Vista add a Adhoc profile, HW radio off until 999 - * OID_DOT11_RESET_REQUEST Driver would set MSR=NO_LINK, 1000 - * then HW Radio ON, MgntQueue Stuck. Because Bcn DMA isn't 1001 - * complete, mgnt queue would stuck until Bcn packet send. 1002 - * 1003 - * Disable Beacon Queue Own bit, suggested by jong 1004 - */ 1005 - ieee80211_stop_send_beacons(priv->ieee80211); 1006 - 1007 - priv->ieee80211->link_change(dev); 1008 - notify_wx_assoc_event(priv->ieee80211); 1009 - } 1010 - 1011 - static void MlmeDisassociateRequest(struct net_device *dev, u8 *asSta, u8 asRsn) 1012 - { 1013 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1014 - u8 i; 1015 - 1016 - SendDisassociation(priv->ieee80211, asSta, asRsn); 1017 - 1018 - if (memcmp(priv->ieee80211->current_network.bssid, asSta, 6) == 0) { 1019 - /* ShuChen TODO: change media status. */ 1020 - 1021 - for (i = 0; i < 6; i++) 1022 - priv->ieee80211->current_network.bssid[i] = 0x22; 1023 - 1024 - ieee80211_disassociate(priv->ieee80211); 1025 - } 1026 - } 1027 - 1028 - static void MgntDisconnectAP(struct net_device *dev, u8 asRsn) 1029 - { 1030 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1031 - 1032 - /* 1033 - * Commented out by rcnjko, 2005.01.27: 1034 - * I move SecClearAllKeys() to MgntActSet_802_11_DISASSOCIATE(). 1035 - * 1036 - * 2004/09/15, kcwu, the key should be cleared, or the new 1037 - * handshaking will not success 1038 - * 1039 - * In WPA WPA2 need to Clear all key ... because new key will set 1040 - * after new handshaking. 2004.10.11, by rcnjko. 1041 - */ 1042 - MlmeDisassociateRequest(dev, priv->ieee80211->current_network.bssid, 1043 - asRsn); 1044 - 1045 - priv->ieee80211->state = IEEE80211_NOLINK; 1046 - } 1047 - 1048 - static bool MgntDisconnect(struct net_device *dev, u8 asRsn) 1049 - { 1050 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1051 - /* 1052 - * Schedule an workitem to wake up for ps mode, 070109, by rcnjko. 1053 - */ 1054 - 1055 - if (IS_DOT11D_ENABLE(priv->ieee80211)) 1056 - Dot11d_Reset(priv->ieee80211); 1057 - /* In adhoc mode, update beacon frame. */ 1058 - if (priv->ieee80211->state == IEEE80211_LINKED) { 1059 - if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) 1060 - MgntDisconnectIBSS(dev); 1061 - 1062 - if (priv->ieee80211->iw_mode == IW_MODE_INFRA) { 1063 - /* 1064 - * We clear key here instead of MgntDisconnectAP() 1065 - * because that MgntActSet_802_11_DISASSOCIATE() 1066 - * is an interface called by OS, e.g. 1067 - * OID_802_11_DISASSOCIATE in Windows while as 1068 - * MgntDisconnectAP() is used to handle 1069 - * disassociation related things to AP, e.g. send 1070 - * Disassoc frame to AP. 2005.01.27, by rcnjko. 1071 - */ 1072 - MgntDisconnectAP(dev, asRsn); 1073 - } 1074 - /* Indicate Disconnect, 2005.02.23, by rcnjko. */ 1075 - } 1076 - return true; 1077 - } 1078 - /* 1079 - * Description: 1080 - * Chang RF Power State. 1081 - * Note that, only MgntActSet_RF_State() is allowed to set 1082 - * HW_VAR_RF_STATE. 1083 - * 1084 - * Assumption: 1085 - * PASSIVE LEVEL. 1086 - */ 1087 - static bool SetRFPowerState(struct net_device *dev, 1088 - enum rt_rf_power_state eRFPowerState) 1089 - { 1090 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1091 - bool bResult = false; 1092 - 1093 - if (eRFPowerState == priv->eRFPowerState) 1094 - return bResult; 1095 - 1096 - bResult = SetZebraRFPowerState8185(dev, eRFPowerState); 1097 - 1098 - return bResult; 1099 - } 1100 - 1101 - bool MgntActSet_RF_State(struct net_device *dev, enum rt_rf_power_state StateToSet, 1102 - u32 ChangeSource) 1103 - { 1104 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1105 - bool bActionAllowed = false; 1106 - bool bConnectBySSID = false; 1107 - enum rt_rf_power_state rtState; 1108 - u16 RFWaitCounter = 0; 1109 - unsigned long flag; 1110 - /* 1111 - * Prevent the race condition of RF state change. By Bruce, 1112 - * 2007-11-28. Only one thread can change the RF state at one time, 1113 - * and others should wait to be executed. 1114 - */ 1115 - while (true) { 1116 - spin_lock_irqsave(&priv->rf_ps_lock, flag); 1117 - if (priv->RFChangeInProgress) { 1118 - spin_unlock_irqrestore(&priv->rf_ps_lock, flag); 1119 - /* Set RF after the previous action is done. */ 1120 - while (priv->RFChangeInProgress) { 1121 - RFWaitCounter++; 1122 - udelay(1000); /* 1 ms */ 1123 - 1124 - /* 1125 - * Wait too long, return FALSE to avoid 1126 - * to be stuck here. 1127 - */ 1128 - if (RFWaitCounter > 1000) { /* 1sec */ 1129 - netdev_info(dev, "MgntActSet_RF_State(): Wait too long to set RF\n"); 1130 - /* TODO: Reset RF state? */ 1131 - return false; 1132 - } 1133 - } 1134 - } else { 1135 - priv->RFChangeInProgress = true; 1136 - spin_unlock_irqrestore(&priv->rf_ps_lock, flag); 1137 - break; 1138 - } 1139 - } 1140 - rtState = priv->eRFPowerState; 1141 - 1142 - switch (StateToSet) { 1143 - case RF_ON: 1144 - /* 1145 - * Turn On RF no matter the IPS setting because we need to 1146 - * update the RF state to Ndis under Vista, or the Windows 1147 - * does not allow the driver to perform site survey any 1148 - * more. By Bruce, 2007-10-02. 1149 - */ 1150 - priv->RfOffReason &= (~ChangeSource); 1151 - 1152 - if (!priv->RfOffReason) { 1153 - priv->RfOffReason = 0; 1154 - bActionAllowed = true; 1155 - 1156 - if (rtState == RF_OFF && 1157 - ChangeSource >= RF_CHANGE_BY_HW) 1158 - bConnectBySSID = true; 1159 - } 1160 - break; 1161 - 1162 - case RF_OFF: 1163 - /* 070125, rcnjko: we always keep connected in AP mode. */ 1164 - 1165 - if (priv->RfOffReason > RF_CHANGE_BY_IPS) { 1166 - /* 1167 - * 060808, Annie: 1168 - * Disconnect to current BSS when radio off. 1169 - * Asked by QuanTa. 1170 - * 1171 - * Calling MgntDisconnect() instead of 1172 - * MgntActSet_802_11_DISASSOCIATE(), because 1173 - * we do NOT need to set ssid to dummy ones. 1174 - */ 1175 - MgntDisconnect(dev, disas_lv_ss); 1176 - /* 1177 - * Clear content of bssDesc[] and bssDesc4Query[] 1178 - * to avoid reporting old bss to UI. 1179 - */ 1180 - } 1181 - 1182 - priv->RfOffReason |= ChangeSource; 1183 - bActionAllowed = true; 1184 - break; 1185 - case RF_SLEEP: 1186 - priv->RfOffReason |= ChangeSource; 1187 - bActionAllowed = true; 1188 - break; 1189 - default: 1190 - break; 1191 - } 1192 - 1193 - if (bActionAllowed) { 1194 - /* Config HW to the specified mode. */ 1195 - SetRFPowerState(dev, StateToSet); 1196 - } 1197 - 1198 - /* Release RF spinlock */ 1199 - spin_lock_irqsave(&priv->rf_ps_lock, flag); 1200 - priv->RFChangeInProgress = false; 1201 - spin_unlock_irqrestore(&priv->rf_ps_lock, flag); 1202 - return bActionAllowed; 1203 - } 1204 - 1205 - static void InactivePowerSave(struct net_device *dev) 1206 - { 1207 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1208 - /* 1209 - * This flag "bSwRfProcessing", indicates the status of IPS 1210 - * procedure, should be set if the IPS workitem is really 1211 - * scheduled. The old code, sets this flag before scheduling the 1212 - * IPS workitem and however, at the same time the previous IPS 1213 - * workitem did not end yet, fails to schedule the current 1214 - * workitem. Thus, bSwRfProcessing blocks the IPS procedure of 1215 - * switching RF. 1216 - */ 1217 - priv->bSwRfProcessing = true; 1218 - 1219 - MgntActSet_RF_State(dev, priv->eInactivePowerState, RF_CHANGE_BY_IPS); 1220 - 1221 - /* 1222 - * To solve CAM values miss in RF OFF, rewrite CAM values after 1223 - * RF ON. By Bruce, 2007-09-20. 1224 - */ 1225 - 1226 - priv->bSwRfProcessing = false; 1227 - } 1228 - 1229 - /* 1230 - * Description: 1231 - * Enter the inactive power save mode. RF will be off 1232 - */ 1233 - void IPSEnter(struct net_device *dev) 1234 - { 1235 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1236 - enum rt_rf_power_state rtState; 1237 - if (priv->bInactivePs) { 1238 - rtState = priv->eRFPowerState; 1239 - 1240 - /* 1241 - * Do not enter IPS in the following conditions: 1242 - * (1) RF is already OFF or 1243 - * Sleep (2) bSwRfProcessing (indicates the IPS is still 1244 - * under going) (3) Connected (only disconnected can 1245 - * trigger IPS)(4) IBSS (send Beacon) 1246 - * (5) AP mode (send Beacon) 1247 - */ 1248 - if (rtState == RF_ON && !priv->bSwRfProcessing 1249 - && (priv->ieee80211->state != IEEE80211_LINKED)) { 1250 - priv->eInactivePowerState = RF_OFF; 1251 - InactivePowerSave(dev); 1252 - } 1253 - } 1254 - } 1255 - void IPSLeave(struct net_device *dev) 1256 - { 1257 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1258 - enum rt_rf_power_state rtState; 1259 - if (priv->bInactivePs) { 1260 - rtState = priv->eRFPowerState; 1261 - if ((rtState == RF_OFF || rtState == RF_SLEEP) && 1262 - !priv->bSwRfProcessing 1263 - && priv->RfOffReason <= RF_CHANGE_BY_IPS) { 1264 - priv->eInactivePowerState = RF_ON; 1265 - InactivePowerSave(dev); 1266 - } 1267 - } 1268 - } 1269 - 1270 - void rtl8185b_adapter_start(struct net_device *dev) 1271 - { 1272 - struct r8180_priv *priv = ieee80211_priv(dev); 1273 - struct ieee80211_device *ieee = priv->ieee80211; 1274 - 1275 - u8 SupportedWirelessMode; 1276 - u8 InitWirelessMode; 1277 - u8 bInvalidWirelessMode = 0; 1278 - u8 tmpu8; 1279 - u8 btCR9346; 1280 - u8 TmpU1b; 1281 - u8 btPSR; 1282 - 1283 - write_nic_byte(dev, 0x24e, (BIT5|BIT6|BIT0)); 1284 - rtl8180_reset(dev); 1285 - 1286 - priv->dma_poll_mask = 0; 1287 - priv->dma_poll_stop_mask = 0; 1288 - 1289 - HwConfigureRTL8185(dev); 1290 - write_nic_dword(dev, MAC0, ((u32 *)dev->dev_addr)[0]); 1291 - write_nic_word(dev, MAC4, ((u32 *)dev->dev_addr)[1] & 0xffff); 1292 - /* default network type to 'No Link' */ 1293 - write_nic_byte(dev, MSR, read_nic_byte(dev, MSR) & 0xf3); 1294 - write_nic_word(dev, BcnItv, 100); 1295 - write_nic_word(dev, AtimWnd, 2); 1296 - PlatformIOWrite2Byte(dev, FEMR, 0xFFFF); 1297 - write_nic_byte(dev, WPA_CONFIG, 0); 1298 - MacConfig_85BASIC(dev); 1299 - /* Override the RFSW_CTRL (MAC offset 0x272-0x273), 2006.06.07, 1300 - * by rcnjko. 1301 - */ 1302 - /* BT_DEMO_BOARD type */ 1303 - PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x569a); 1304 - 1305 - /* 1306 - *--------------------------------------------------------------------- 1307 - * Set up PHY related. 1308 - *--------------------------------------------------------------------- 1309 - */ 1310 - /* Enable Config3.PARAM_En to revise AnaaParm. */ 1311 - write_nic_byte(dev, CR9346, 0xc0); /* enable config register write */ 1312 - tmpu8 = read_nic_byte(dev, CONFIG3); 1313 - write_nic_byte(dev, CONFIG3, (tmpu8 | CONFIG3_PARM_En)); 1314 - /* Turn on Analog power. */ 1315 - /* Asked for by William, otherwise, MAC 3-wire can't work, 1316 - * 2006.06.27, by rcnjko. 1317 - */ 1318 - write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON); 1319 - write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON); 1320 - write_nic_word(dev, ANAPARAM3, 0x0010); 1321 - 1322 - write_nic_byte(dev, CONFIG3, tmpu8); 1323 - write_nic_byte(dev, CR9346, 0x00); 1324 - /* enable EEM0 and EEM1 in 9346CR */ 1325 - btCR9346 = read_nic_byte(dev, CR9346); 1326 - write_nic_byte(dev, CR9346, (btCR9346 | 0xC0)); 1327 - 1328 - /* B cut use LED1 to control HW RF on/off */ 1329 - TmpU1b = read_nic_byte(dev, CONFIG5); 1330 - TmpU1b = TmpU1b & ~BIT3; 1331 - write_nic_byte(dev, CONFIG5, TmpU1b); 1332 - 1333 - /* disable EEM0 and EEM1 in 9346CR */ 1334 - btCR9346 &= ~(0xC0); 1335 - write_nic_byte(dev, CR9346, btCR9346); 1336 - 1337 - /* Enable Led (suggested by Jong) */ 1338 - /* B-cut RF Radio on/off 5e[3]=0 */ 1339 - btPSR = read_nic_byte(dev, PSR); 1340 - write_nic_byte(dev, PSR, (btPSR | BIT3)); 1341 - /* setup initial timing for RFE. */ 1342 - write_nic_word(dev, RFPinsOutput, 0x0480); 1343 - SetOutputEnableOfRfPins(dev); 1344 - write_nic_word(dev, RFPinsSelect, 0x2488); 1345 - 1346 - /* PHY config. */ 1347 - PhyConfig8185(dev); 1348 - 1349 - /* 1350 - * We assume RegWirelessMode has already been initialized before, 1351 - * however, we has to validate the wireless mode here and provide a 1352 - * reasonable initialized value if necessary. 2005.01.13, 1353 - * by rcnjko. 1354 - */ 1355 - SupportedWirelessMode = GetSupportedWirelessMode8185(dev); 1356 - if ((ieee->mode != WIRELESS_MODE_B) && 1357 - (ieee->mode != WIRELESS_MODE_G) && 1358 - (ieee->mode != WIRELESS_MODE_A) && 1359 - (ieee->mode != WIRELESS_MODE_AUTO)) { 1360 - /* It should be one of B, G, A, or AUTO. */ 1361 - bInvalidWirelessMode = 1; 1362 - } else { 1363 - /* One of B, G, A, or AUTO. */ 1364 - /* Check if the wireless mode is supported by RF. */ 1365 - if ((ieee->mode != WIRELESS_MODE_AUTO) && 1366 - (ieee->mode & SupportedWirelessMode) == 0) { 1367 - bInvalidWirelessMode = 1; 1368 - } 1369 - } 1370 - 1371 - if (bInvalidWirelessMode || ieee->mode == WIRELESS_MODE_AUTO) { 1372 - /* Auto or other invalid value. */ 1373 - /* Assigne a wireless mode to initialize. */ 1374 - if ((SupportedWirelessMode & WIRELESS_MODE_A)) { 1375 - InitWirelessMode = WIRELESS_MODE_A; 1376 - } else if ((SupportedWirelessMode & WIRELESS_MODE_G)) { 1377 - InitWirelessMode = WIRELESS_MODE_G; 1378 - } else if ((SupportedWirelessMode & WIRELESS_MODE_B)) { 1379 - InitWirelessMode = WIRELESS_MODE_B; 1380 - } else { 1381 - DMESGW("InitializeAdapter8185(): No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", 1382 - SupportedWirelessMode); 1383 - InitWirelessMode = WIRELESS_MODE_B; 1384 - } 1385 - 1386 - /* Initialize RegWirelessMode if it is not a valid one. */ 1387 - if (bInvalidWirelessMode) 1388 - ieee->mode = (enum wireless_mode)InitWirelessMode; 1389 - 1390 - } else { 1391 - /* One of B, G, A. */ 1392 - InitWirelessMode = ieee->mode; 1393 - } 1394 - priv->eRFPowerState = RF_OFF; 1395 - priv->RfOffReason = 0; 1396 - { 1397 - MgntActSet_RF_State(dev, RF_ON, 0); 1398 - } 1399 - /* 1400 - * If inactive power mode is enabled, disable rf while in 1401 - * disconnected state. 1402 - */ 1403 - if (priv->bInactivePs) 1404 - MgntActSet_RF_State(dev , RF_OFF, RF_CHANGE_BY_IPS); 1405 - 1406 - ActSetWirelessMode8185(dev, (u8)(InitWirelessMode)); 1407 - 1408 - /* ----------------------------------------------------------------- */ 1409 - 1410 - rtl8185b_irq_enable(dev); 1411 - 1412 - netif_start_queue(dev); 1413 - } 1414 - 1415 - void rtl8185b_rx_enable(struct net_device *dev) 1416 - { 1417 - u8 cmd; 1418 - /* for now we accept data, management & ctl frame*/ 1419 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1420 - 1421 - 1422 - if (dev->flags & IFF_PROMISC) 1423 - DMESG("NIC in promisc mode"); 1424 - 1425 - if (priv->ieee80211->iw_mode == IW_MODE_MONITOR || dev->flags & 1426 - IFF_PROMISC) { 1427 - priv->ReceiveConfig = priv->ReceiveConfig & (~RCR_APM); 1428 - priv->ReceiveConfig = priv->ReceiveConfig | RCR_AAP; 1429 - } 1430 - 1431 - if (priv->ieee80211->iw_mode == IW_MODE_MONITOR) 1432 - priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACF | 1433 - RCR_APWRMGT | RCR_AICV; 1434 - 1435 - 1436 - if (priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR) 1437 - priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACRC32; 1438 - 1439 - write_nic_dword(dev, RCR, priv->ReceiveConfig); 1440 - 1441 - fix_rx_fifo(dev); 1442 - 1443 - cmd = read_nic_byte(dev, CMD); 1444 - write_nic_byte(dev, CMD, cmd | (1<<CMD_RX_ENABLE_SHIFT)); 1445 - 1446 - } 1447 - 1448 - void rtl8185b_tx_enable(struct net_device *dev) 1449 - { 1450 - u8 cmd; 1451 - u8 byte; 1452 - struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1453 - 1454 - write_nic_dword(dev, TCR, priv->TransmitConfig); 1455 - byte = read_nic_byte(dev, MSR); 1456 - byte |= MSR_LINK_ENEDCA; 1457 - write_nic_byte(dev, MSR, byte); 1458 - 1459 - fix_tx_fifo(dev); 1460 - 1461 - cmd = read_nic_byte(dev, CMD); 1462 - write_nic_byte(dev, CMD, cmd | (1<<CMD_TX_ENABLE_SHIFT)); 1463 - } 1464 -
+8 -11
drivers/staging/rtl8188eu/core/rtw_recv.c
··· 545 545 static struct recv_frame *portctrl(struct adapter *adapter, 546 546 struct recv_frame *precv_frame) 547 547 { 548 - u8 *psta_addr = NULL, *ptr; 548 + u8 *psta_addr, *ptr; 549 549 uint auth_alg; 550 550 struct recv_frame *pfhdr; 551 551 struct sta_info *psta; 552 552 struct sta_priv *pstapriv; 553 553 struct recv_frame *prtnframe; 554 - u16 ether_type = 0; 554 + u16 ether_type; 555 555 u16 eapol_type = 0x888e;/* for Funia BD's WPA issue */ 556 556 struct rx_pkt_attrib *pattrib; 557 - __be16 be_tmp; 558 557 559 558 560 559 pstapriv = &adapter->stapriv; 561 - psta = rtw_get_stainfo(pstapriv, psta_addr); 562 560 563 561 auth_alg = adapter->securitypriv.dot11AuthAlgrthm; 564 562 ··· 564 566 pfhdr = precv_frame; 565 567 pattrib = &pfhdr->attrib; 566 568 psta_addr = pattrib->ta; 569 + psta = rtw_get_stainfo(pstapriv, psta_addr); 567 570 568 571 prtnframe = NULL; 569 572 570 573 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:adapter->securitypriv.dot11AuthAlgrthm=%d\n", adapter->securitypriv.dot11AuthAlgrthm)); 571 574 572 575 if (auth_alg == 2) { 576 + /* get ether_type */ 577 + ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE; 578 + memcpy(&ether_type, ptr, 2); 579 + ether_type = ntohs((unsigned short)ether_type); 580 + 573 581 if ((psta != NULL) && (psta->ieee8021x_blocked)) { 574 582 /* blocked */ 575 583 /* only accept EAPOL frame */ 576 584 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("########portctrl:psta->ieee8021x_blocked==1\n")); 577 - 578 - prtnframe = precv_frame; 579 - 580 - /* get ether_type */ 581 - ptr = ptr+pfhdr->attrib.hdrlen+pfhdr->attrib.iv_len+LLC_HEADER_SIZE; 582 - memcpy(&be_tmp, ptr, 2); 583 - ether_type = ntohs(be_tmp); 584 585 585 586 if (ether_type == eapol_type) { 586 587 prtnframe = precv_frame;
+37 -37
drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
··· 359 359 if (wpa_len > 0) { 360 360 p = buf; 361 361 _rtw_memset(buf, 0, MAX_WPA_IE_LEN); 362 - p += sprintf(p, "wpa_ie ="); 362 + p += sprintf(p, "wpa_ie="); 363 363 for (i = 0; i < wpa_len; i++) 364 364 p += sprintf(p, "%02x", wpa_ie[i]); 365 365 ··· 376 376 if (rsn_len > 0) { 377 377 p = buf; 378 378 _rtw_memset(buf, 0, MAX_WPA_IE_LEN); 379 - p += sprintf(p, "rsn_ie ="); 379 + p += sprintf(p, "rsn_ie="); 380 380 for (i = 0; i < rsn_len; i++) 381 381 p += sprintf(p, "%02x", rsn_ie[i]); 382 382 _rtw_memset(&iwe, 0, sizeof(iwe)); ··· 2899 2899 /* Commented by Albert 2010/10/12 */ 2900 2900 /* Because of the output size limitation, I had removed the "Role" information. */ 2901 2901 /* About the "Role" information, we will use the new private IOCTL to get the "Role" information. */ 2902 - sprintf(extra, "\n\nStatus =%.2d\n", rtw_p2p_state(pwdinfo)); 2902 + sprintf(extra, "\n\nStatus=%.2d\n", rtw_p2p_state(pwdinfo)); 2903 2903 wrqu->data.length = strlen(extra); 2904 2904 2905 2905 return ret; ··· 2918 2918 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 2919 2919 struct wifidirect_info *pwdinfo = &(padapter->wdinfo); 2920 2920 2921 - sprintf(extra, "\n\nCM =%s\n", pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req); 2921 + sprintf(extra, "\n\nCM=%s\n", pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req); 2922 2922 wrqu->data.length = strlen(extra); 2923 2923 return ret; 2924 2924 } ··· 2935 2935 pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1], pwdinfo->p2p_peer_interface_addr[2], 2936 2936 pwdinfo->p2p_peer_interface_addr[3], pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]); 2937 2937 2938 - sprintf(extra, "\n\nRole =%.2d\n", rtw_p2p_role(pwdinfo)); 2938 + sprintf(extra, "\n\nRole=%.2d\n", rtw_p2p_role(pwdinfo)); 2939 2939 wrqu->data.length = strlen(extra); 2940 2940 return ret; 2941 2941 } ··· 3022 3022 3023 3023 DBG_88E("[%s] Op_ch = %02x\n", __func__, pwdinfo->operating_channel); 3024 3024 3025 - sprintf(extra, "\n\nOp_ch =%.2d\n", pwdinfo->operating_channel); 3025 + sprintf(extra, "\n\nOp_ch=%.2d\n", pwdinfo->operating_channel); 3026 3026 wrqu->data.length = strlen(extra); 3027 3027 return ret; 3028 3028 } ··· 3043 3043 u8 blnMatch = 0; 3044 3044 u16 attr_content = 0; 3045 3045 uint attr_contentlen = 0; 3046 - /* 6 is the string "wpsCM =", 17 is the MAC addr, we have to clear it at wrqu->data.pointer */ 3046 + /* 6 is the string "wpsCM=", 17 is the MAC addr, we have to clear it at wrqu->data.pointer */ 3047 3047 u8 attr_content_str[6 + 17] = {0x00}; 3048 3048 3049 3049 /* Commented by Albert 20110727 */ ··· 3079 3079 rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_CONF_METHOD, (u8 *) &be_tmp, &attr_contentlen); 3080 3080 if (attr_contentlen) { 3081 3081 attr_content = be16_to_cpu(be_tmp); 3082 - sprintf(attr_content_str, "\n\nM =%.4d", attr_content); 3082 + sprintf(attr_content_str, "\n\nM=%.4d", attr_content); 3083 3083 blnMatch = 1; 3084 3084 } 3085 3085 } ··· 3091 3091 spin_unlock_bh(&pmlmepriv->scanned_queue.lock); 3092 3092 3093 3093 if (!blnMatch) 3094 - sprintf(attr_content_str, "\n\nM = 0000"); 3094 + sprintf(attr_content_str, "\n\nM=0000"); 3095 3095 3096 3096 if (copy_to_user(wrqu->data.pointer, attr_content_str, 6 + 17)) 3097 3097 return -EFAULT; ··· 3172 3172 spin_unlock_bh(&pmlmepriv->scanned_queue.lock); 3173 3173 3174 3174 if (!blnMatch) 3175 - snprintf(go_devadd_str, sizeof(go_devadd_str), "\n\ndev_add = NULL"); 3175 + snprintf(go_devadd_str, sizeof(go_devadd_str), "\n\ndev_add=NULL"); 3176 3176 else 3177 - snprintf(go_devadd_str, sizeof(go_devadd_str), "\n\ndev_add =%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 3177 + snprintf(go_devadd_str, sizeof(go_devadd_str), "\n\ndev_add=%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 3178 3178 attr_content[0], attr_content[1], attr_content[2], attr_content[3], attr_content[4], attr_content[5]); 3179 3179 3180 3180 if (copy_to_user(wrqu->data.pointer, go_devadd_str, sizeof(go_devadd_str))) ··· 3198 3198 u8 blnMatch = 0; 3199 3199 u8 dev_type[8] = {0x00}; 3200 3200 uint dev_type_len = 0; 3201 - u8 dev_type_str[17 + 9] = {0x00}; /* +9 is for the str "dev_type =", we have to clear it at wrqu->data.pointer */ 3201 + u8 dev_type_str[17 + 9] = {0x00}; /* +9 is for the str "dev_type=", we have to clear it at wrqu->data.pointer */ 3202 3202 3203 3203 /* Commented by Albert 20121209 */ 3204 3204 /* The input data is the MAC address which the application wants to know its device type. */ ··· 3239 3239 3240 3240 memcpy(&be_tmp, dev_type, 2); 3241 3241 type = be16_to_cpu(be_tmp); 3242 - sprintf(dev_type_str, "\n\nN =%.2d", type); 3242 + sprintf(dev_type_str, "\n\nN=%.2d", type); 3243 3243 blnMatch = 1; 3244 3244 } 3245 3245 } ··· 3252 3252 spin_unlock_bh(&pmlmepriv->scanned_queue.lock); 3253 3253 3254 3254 if (!blnMatch) 3255 - sprintf(dev_type_str, "\n\nN = 00"); 3255 + sprintf(dev_type_str, "\n\nN=00"); 3256 3256 3257 3257 if (copy_to_user(wrqu->data.pointer, dev_type_str, 9 + 17)) { 3258 3258 return -EFAULT; ··· 3277 3277 u8 blnMatch = 0; 3278 3278 u8 dev_name[WPS_MAX_DEVICE_NAME_LEN] = {0x00}; 3279 3279 uint dev_len = 0; 3280 - u8 dev_name_str[WPS_MAX_DEVICE_NAME_LEN + 5] = {0x00}; /* +5 is for the str "devN =", we have to clear it at wrqu->data.pointer */ 3280 + u8 dev_name_str[WPS_MAX_DEVICE_NAME_LEN + 5] = {0x00}; /* +5 is for the str "devN=", we have to clear it at wrqu->data.pointer */ 3281 3281 3282 3282 /* Commented by Albert 20121225 */ 3283 3283 /* The input data is the MAC address which the application wants to know its device name. */ ··· 3310 3310 if (wpsie) { 3311 3311 rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_DEVICE_NAME, dev_name, &dev_len); 3312 3312 if (dev_len) { 3313 - sprintf(dev_name_str, "\n\nN =%s", dev_name); 3313 + sprintf(dev_name_str, "\n\nN=%s", dev_name); 3314 3314 blnMatch = 1; 3315 3315 } 3316 3316 } ··· 3323 3323 spin_unlock_bh(&pmlmepriv->scanned_queue.lock); 3324 3324 3325 3325 if (!blnMatch) 3326 - sprintf(dev_name_str, "\n\nN = 0000"); 3326 + sprintf(dev_name_str, "\n\nN=0000"); 3327 3327 3328 3328 if (copy_to_user(wrqu->data.pointer, dev_name_str, 5 + ((dev_len > 17) ? dev_len : 17))) 3329 3329 return -EFAULT; ··· 3349 3349 u8 attr_content[2] = {0x00}; 3350 3350 3351 3351 u8 inv_proc_str[17 + 8] = {0x00}; 3352 - /* +8 is for the str "InvProc =", we have to clear it at wrqu->data.pointer */ 3352 + /* +8 is for the str "InvProc=", we have to clear it at wrqu->data.pointer */ 3353 3353 3354 3354 /* Commented by Ouden 20121226 */ 3355 3355 /* The application wants to know P2P initiation procedure is supported or not. */ ··· 3397 3397 spin_unlock_bh(&pmlmepriv->scanned_queue.lock); 3398 3398 3399 3399 if (!blnMatch) { 3400 - sprintf(inv_proc_str, "\nIP =-1"); 3400 + sprintf(inv_proc_str, "\nIP=-1"); 3401 3401 } else { 3402 3402 if (attr_content[0] & 0x20) 3403 - sprintf(inv_proc_str, "\nIP = 1"); 3403 + sprintf(inv_proc_str, "\nIP=1"); 3404 3404 else 3405 - sprintf(inv_proc_str, "\nIP = 0"); 3405 + sprintf(inv_proc_str, "\nIP=0"); 3406 3406 } 3407 3407 if (copy_to_user(wrqu->data.pointer, inv_proc_str, 8 + 17)) 3408 3408 return -EFAULT; ··· 3512 3512 /* The input data contains two informations. */ 3513 3513 /* 1. First information is the P2P device address which you want to send to. */ 3514 3514 /* 2. Second information is the group id which combines with GO's mac address, space and GO's ssid. */ 3515 - /* Command line sample: iwpriv wlan0 p2p_set invite ="00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy" */ 3515 + /* Command line sample: iwpriv wlan0 p2p_set invite="00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy" */ 3516 3516 /* Format: 00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy */ 3517 3517 3518 3518 DBG_88E("[%s] data = %s\n", __func__, extra); ··· 3805 3805 3806 3806 #ifdef CONFIG_88EU_P2P 3807 3807 DBG_88E("[%s] extra = %s\n", __func__, extra); 3808 - if (!memcmp(extra, "enable =", 7)) { 3808 + if (!memcmp(extra, "enable=", 7)) { 3809 3809 rtw_wext_p2p_enable(dev, info, wrqu, &extra[7]); 3810 - } else if (!memcmp(extra, "setDN =", 6)) { 3810 + } else if (!memcmp(extra, "setDN=", 6)) { 3811 3811 wrqu->data.length -= 6; 3812 3812 rtw_p2p_setDN(dev, info, wrqu, &extra[6]); 3813 - } else if (!memcmp(extra, "profilefound =", 13)) { 3813 + } else if (!memcmp(extra, "profilefound=", 13)) { 3814 3814 wrqu->data.length -= 13; 3815 3815 rtw_p2p_profilefound(dev, info, wrqu, &extra[13]); 3816 - } else if (!memcmp(extra, "prov_disc =", 10)) { 3816 + } else if (!memcmp(extra, "prov_disc=", 10)) { 3817 3817 wrqu->data.length -= 10; 3818 3818 rtw_p2p_prov_disc(dev, info, wrqu, &extra[10]); 3819 - } else if (!memcmp(extra, "nego =", 5)) { 3819 + } else if (!memcmp(extra, "nego=", 5)) { 3820 3820 wrqu->data.length -= 5; 3821 3821 rtw_p2p_connect(dev, info, wrqu, &extra[5]); 3822 - } else if (!memcmp(extra, "intent =", 7)) { 3822 + } else if (!memcmp(extra, "intent=", 7)) { 3823 3823 /* Commented by Albert 2011/03/23 */ 3824 3824 /* The wrqu->data.length will include the null character */ 3825 3825 /* So, we will decrease 7 + 1 */ 3826 3826 wrqu->data.length -= 8; 3827 3827 rtw_p2p_set_intent(dev, info, wrqu, &extra[7]); 3828 - } else if (!memcmp(extra, "ssid =", 5)) { 3828 + } else if (!memcmp(extra, "ssid=", 5)) { 3829 3829 wrqu->data.length -= 5; 3830 3830 rtw_p2p_set_go_nego_ssid(dev, info, wrqu, &extra[5]); 3831 - } else if (!memcmp(extra, "got_wpsinfo =", 12)) { 3831 + } else if (!memcmp(extra, "got_wpsinfo=", 12)) { 3832 3832 wrqu->data.length -= 12; 3833 3833 rtw_p2p_got_wpsinfo(dev, info, wrqu, &extra[12]); 3834 - } else if (!memcmp(extra, "listen_ch =", 10)) { 3834 + } else if (!memcmp(extra, "listen_ch=", 10)) { 3835 3835 /* Commented by Albert 2011/05/24 */ 3836 3836 /* The wrqu->data.length will include the null character */ 3837 3837 /* So, we will decrease (10 + 1) */ 3838 3838 wrqu->data.length -= 11; 3839 3839 rtw_p2p_set_listen_ch(dev, info, wrqu, &extra[10]); 3840 - } else if (!memcmp(extra, "op_ch =", 6)) { 3840 + } else if (!memcmp(extra, "op_ch=", 6)) { 3841 3841 /* Commented by Albert 2011/05/24 */ 3842 3842 /* The wrqu->data.length will include the null character */ 3843 3843 /* So, we will decrease (6 + 1) */ 3844 3844 wrqu->data.length -= 7; 3845 3845 rtw_p2p_set_op_ch(dev, info, wrqu, &extra[6]); 3846 - } else if (!memcmp(extra, "invite =", 7)) { 3846 + } else if (!memcmp(extra, "invite=", 7)) { 3847 3847 wrqu->data.length -= 8; 3848 3848 rtw_p2p_invite_req(dev, info, wrqu, &extra[7]); 3849 - } else if (!memcmp(extra, "persistent =", 11)) { 3849 + } else if (!memcmp(extra, "persistent=", 11)) { 3850 3850 wrqu->data.length -= 11; 3851 3851 rtw_p2p_set_persistent(dev, info, wrqu, &extra[11]); 3852 3852 } ··· 3887 3887 "group_id", 8)) { 3888 3888 rtw_p2p_get_groupid(dev, info, wrqu, extra); 3889 3889 } else if (!memcmp((__force const char *)wrqu->data.pointer, 3890 - "peer_deva_inv", 9)) { 3890 + "peer_deva_inv", 13)) { 3891 3891 /* Get the P2P device address when receiving the P2P Invitation request frame. */ 3892 3892 rtw_p2p_get_peer_devaddr_by_invitation(dev, info, wrqu, extra); 3893 3893 } else if (!memcmp((__force const char *)wrqu->data.pointer, ··· 6920 6920 6921 6921 DBG_88E("%s: in =%s\n", __func__, extra); 6922 6922 6923 - countPkTx = strncmp(extra, "count =", 5); /* strncmp true is 0 */ 6923 + countPkTx = strncmp(extra, "count=", 6); /* strncmp true is 0 */ 6924 6924 cotuTx = strncmp(extra, "background", 20); 6925 6925 CarrSprTx = strncmp(extra, "background, cs", 20); 6926 6926 scTx = strncmp(extra, "background, sc", 20); ··· 7044 7044 DBG_88E("%s: %s\n", __func__, input); 7045 7045 7046 7046 bStartRx = (strncmp(input, "start", 5) == 0) ? 1 : 0; /* strncmp true is 0 */ 7047 - bStopRx = (strncmp(input, "stop", 5) == 0) ? 1 : 0; /* strncmp true is 0 */ 7047 + bStopRx = (strncmp(input, "stop", 4) == 0) ? 1 : 0; /* strncmp true is 0 */ 7048 7048 bQueryPhy = (strncmp(input, "phy", 3) == 0) ? 1 : 0; /* strncmp true is 0 */ 7049 7049 7050 7050 if (bStartRx) {
+6 -7
drivers/staging/rtl8712/rtl871x_recv.c
··· 254 254 struct sta_info *psta; 255 255 struct sta_priv *pstapriv; 256 256 union recv_frame *prtnframe; 257 - u16 ether_type = 0; 257 + u16 ether_type; 258 258 259 259 pstapriv = &adapter->stapriv; 260 260 ptr = get_recvframe_data(precv_frame); ··· 263 263 psta = r8712_get_stainfo(pstapriv, psta_addr); 264 264 auth_alg = adapter->securitypriv.AuthAlgrthm; 265 265 if (auth_alg == 2) { 266 + /* get ether_type */ 267 + ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE; 268 + memcpy(&ether_type, ptr, 2); 269 + ether_type = ntohs((unsigned short)ether_type); 270 + 266 271 if ((psta != NULL) && (psta->ieee8021x_blocked)) { 267 272 /* blocked 268 273 * only accept EAPOL frame */ 269 - prtnframe = precv_frame; 270 - /*get ether_type */ 271 - ptr = ptr + pfhdr->attrib.hdrlen + 272 - pfhdr->attrib.iv_len + LLC_HEADER_SIZE; 273 - memcpy(&ether_type, ptr, 2); 274 - ether_type = ntohs((unsigned short)ether_type); 275 274 if (ether_type == 0x888e) 276 275 prtnframe = precv_frame; 277 276 else {
+12 -34
drivers/staging/rtl8723au/core/rtw_ieee80211.c
··· 1496 1496 int rtw_get_wfd_ie(u8 *in_ie, int in_len, u8 *wfd_ie, uint *wfd_ielen) 1497 1497 { 1498 1498 int match; 1499 - uint cnt = 0; 1500 - u8 eid, wfd_oui[4] = {0x50, 0x6F, 0x9A, 0x0A}; 1499 + const u8 *ie; 1501 1500 1502 - match = false; 1501 + match = 0; 1503 1502 1504 - if (in_len < 0) { 1503 + if (in_len < 0) 1505 1504 return match; 1506 - } 1507 1505 1508 - while (cnt < in_len) 1509 - { 1510 - eid = in_ie[cnt]; 1506 + ie = cfg80211_find_vendor_ie(0x506F9A, 0x0A, in_ie, in_len); 1507 + if (ie && (ie[1] <= (MAX_WFD_IE_LEN - 2))) { 1508 + if (wfd_ie) { 1509 + *wfd_ielen = ie[1] + 2; 1510 + memcpy(wfd_ie, ie, ie[1] + 2); 1511 + } else 1512 + if (wfd_ielen) 1513 + *wfd_ielen = 0; 1511 1514 1512 - if ((eid == _VENDOR_SPECIFIC_IE_) && 1513 - !memcmp(&in_ie[cnt+2], wfd_oui, 4)) { 1514 - if (wfd_ie != NULL) { 1515 - memcpy(wfd_ie, &in_ie[cnt], in_ie[cnt + 1] + 2); 1516 - 1517 - } else { 1518 - if (wfd_ielen != NULL) { 1519 - *wfd_ielen = 0; 1520 - } 1521 - } 1522 - 1523 - if (wfd_ielen != NULL) { 1524 - *wfd_ielen = in_ie[cnt + 1] + 2; 1525 - } 1526 - 1527 - cnt += in_ie[cnt + 1] + 2; 1528 - 1529 - match = true; 1530 - break; 1531 - } else { 1532 - cnt += in_ie[cnt + 1] +2; /* goto next */ 1533 - } 1534 - } 1535 - 1536 - if (match == true) { 1537 - match = cnt; 1515 + match = 1; 1538 1516 } 1539 1517 1540 1518 return match;
+1 -1
drivers/staging/rtl8723au/core/rtw_mlme_ext.c
··· 1281 1281 u8 p2p_status_code = P2P_STATUS_SUCCESS; 1282 1282 u8 *p2pie; 1283 1283 u32 p2pielen = 0; 1284 - u8 wfd_ie[ 128 ] = { 0x00 }; 1284 + u8 wfd_ie[MAX_WFD_IE_LEN] = { 0x00 }; 1285 1285 u32 wfd_ielen = 0; 1286 1286 #endif /* CONFIG_8723AU_P2P */ 1287 1287
+2 -2
drivers/staging/rtl8723au/core/rtw_p2p.c
··· 2535 2535 u16 wps_devicepassword_id = 0x0000; 2536 2536 uint wps_devicepassword_id_len = 0; 2537 2537 #ifdef CONFIG_8723AU_P2P 2538 - u8 wfd_ie[ 128 ] = { 0x00 }; 2538 + u8 wfd_ie[MAX_WFD_IE_LEN] = { 0x00 }; 2539 2539 u32 wfd_ielen = 0; 2540 2540 #endif /* CONFIG_8723AU_P2P */ 2541 2541 ··· 2741 2741 u32 ies_len; 2742 2742 u8 * p2p_ie; 2743 2743 #ifdef CONFIG_8723AU_P2P 2744 - u8 wfd_ie[ 128 ] = { 0x00 }; 2744 + u8 wfd_ie[MAX_WFD_IE_LEN] = { 0x00 }; 2745 2745 u32 wfd_ielen = 0; 2746 2746 #endif /* CONFIG_8723AU_P2P */ 2747 2747
+2 -2
drivers/staging/rtl8723au/core/rtw_wlan_util.c
··· 570 570 int WFD_info_handler(struct rtw_adapter *padapter, struct ndis_802_11_var_ies * pIE) 571 571 { 572 572 struct wifidirect_info *pwdinfo; 573 - u8 wfd_ie[128] = {0x00}; 573 + u8 wfd_ie[MAX_WFD_IE_LEN] = {0x00}; 574 574 u32 wfd_ielen = 0; 575 575 576 576 pwdinfo = &padapter->wdinfo; ··· 681 681 inx[0] = 0; inx[1] = 1; inx[2] = 2; inx[3] = 3; 682 682 683 683 if (pregpriv->wifi_spec == 1) { 684 - u32 j, tmp, change_inx; 684 + u32 j, tmp, change_inx = false; 685 685 686 686 /* entry indx: 0->vo, 1->vi, 2->be, 3->bk. */ 687 687 for (i = 0; i < 4; i++) {
+8 -2
drivers/staging/rtl8821ae/base.c
··· 388 388 389 389 } 390 390 391 - static void _rtl_init_deferred_work(struct ieee80211_hw *hw) 391 + static int _rtl_init_deferred_work(struct ieee80211_hw *hw) 392 392 { 393 393 struct rtl_priv *rtlpriv = rtl_priv(hw); 394 394 ··· 410 410 rtlpriv->works.rtl_wq = create_workqueue(rtlpriv->cfg->name); 411 411 #endif 412 412 /*<delete in kernel end>*/ 413 + if (!rtlpriv->works.rtl_wq) 414 + return -ENOMEM; 415 + 413 416 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq, 414 417 (void *)rtl_watchdog_wq_callback); 415 418 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq, ··· 423 420 (void *)rtl_swlps_rfon_wq_callback); 424 421 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq, 425 422 (void *)rtl_fwevt_wq_callback); 423 + 424 + return 0; 426 425 427 426 } 428 427 ··· 524 519 INIT_LIST_HEAD(&rtlpriv->entry_list); 525 520 526 521 /* <6> init deferred work */ 527 - _rtl_init_deferred_work(hw); 522 + if (_rtl_init_deferred_work(hw)) 523 + return 1; 528 524 529 525 /* <7> */ 530 526 #ifdef VIF_TODO
+9 -9
drivers/staging/speakup/main.c
··· 1855 1855 { 1856 1856 static u_char goto_buf[8]; 1857 1857 static int num; 1858 - int maxlen, go_pos; 1858 + int maxlen; 1859 1859 char *cp; 1860 + 1860 1861 if (type == KT_SPKUP && ch == SPEAKUP_GOTO) 1861 1862 goto do_goto; 1862 1863 if (type == KT_LATIN && ch == '\n') ··· 1892 1891 spk_special_handler = NULL; 1893 1892 return 1; 1894 1893 } 1895 - go_pos = kstrtol(goto_buf, 10, (long *)&cp); 1896 - goto_pos = (u_long) go_pos; 1894 + 1895 + goto_pos = simple_strtoul(goto_buf, &cp, 10); 1896 + 1897 1897 if (*cp == 'x') { 1898 1898 if (*goto_buf < '0') 1899 1899 goto_pos += spk_x; 1900 - else 1900 + else if (goto_pos > 0) 1901 1901 goto_pos--; 1902 - if (goto_pos < 0) 1903 - goto_pos = 0; 1902 + 1904 1903 if (goto_pos >= vc->vc_cols) 1905 1904 goto_pos = vc->vc_cols - 1; 1906 1905 goto_x = 1; 1907 1906 } else { 1908 1907 if (*goto_buf < '0') 1909 1908 goto_pos += spk_y; 1910 - else 1909 + else if (goto_pos > 0) 1911 1910 goto_pos--; 1912 - if (goto_pos < 0) 1913 - goto_pos = 0; 1911 + 1914 1912 if (goto_pos >= vc->vc_rows) 1915 1913 goto_pos = vc->vc_rows - 1; 1916 1914 goto_x = 0;
+2 -2
drivers/staging/unisys/uislib/uislib.c
··· 381 381 cmd.add_vbus.busTypeGuid = msg->cmd.createBus.busDataTypeGuid; 382 382 cmd.add_vbus.busInstGuid = msg->cmd.createBus.busInstGuid; 383 383 if (!VirtControlChanFunc) { 384 - kfree(bus); 385 384 LOGERR("CONTROLVM_BUS_CREATE Failed: virtpci callback not registered."); 386 385 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus->busNo, 387 386 POSTCODE_SEVERITY_ERR); 387 + kfree(bus); 388 388 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE; 389 389 } 390 390 if (!VirtControlChanFunc(&cmd)) { 391 - kfree(bus); 392 391 LOGERR("CONTROLVM_BUS_CREATE Failed: virtpci GUEST_ADD_VBUS returned error."); 393 392 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus->busNo, 394 393 POSTCODE_SEVERITY_ERR); 394 + kfree(bus); 395 395 return 396 396 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR; 397 397 }
+2 -2
drivers/staging/unisys/visorchipset/visorchipset.h
··· 104 104 105 105 static inline void delbusdevices(struct list_head *list, U32 busNo) 106 106 { 107 - VISORCHIPSET_DEVICE_INFO *p; 107 + VISORCHIPSET_DEVICE_INFO *p, *tmp; 108 108 109 - list_for_each_entry(p, list, entry) { 109 + list_for_each_entry_safe(p, tmp, list, entry) { 110 110 if (p->busNo == busNo) { 111 111 list_del(&p->entry); 112 112 kfree(p);
+4 -4
drivers/staging/unisys/visorchipset/visorchipset_main.c
··· 605 605 static void 606 606 cleanup_controlvm_structures(void) 607 607 { 608 - VISORCHIPSET_BUS_INFO *bi; 609 - VISORCHIPSET_DEVICE_INFO *di; 608 + VISORCHIPSET_BUS_INFO *bi, *tmp_bi; 609 + VISORCHIPSET_DEVICE_INFO *di, *tmp_di; 610 610 611 - list_for_each_entry(bi, &BusInfoList, entry) { 611 + list_for_each_entry_safe(bi, tmp_bi, &BusInfoList, entry) { 612 612 busInfo_clear(bi); 613 613 list_del(&bi->entry); 614 614 kfree(bi); 615 615 } 616 616 617 - list_for_each_entry(di, &DevInfoList, entry) { 617 + list_for_each_entry_safe(di, tmp_di, &DevInfoList, entry) { 618 618 devInfo_clear(di); 619 619 list_del(&di->entry); 620 620 kfree(di);
+5 -2
drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
··· 118 118 struct udev_list_entry *devices, *dev_list_entry; 119 119 struct udev_device *dev; 120 120 const char *path; 121 + const char *driver; 121 122 122 123 enumerate = udev_enumerate_new(udev_context); 123 124 udev_enumerate_add_match_subsystem(enumerate, "usb"); ··· 129 128 udev_list_entry_foreach(dev_list_entry, devices) { 130 129 path = udev_list_entry_get_name(dev_list_entry); 131 130 dev = udev_device_new_from_syspath(udev_context, path); 131 + if (dev == NULL) 132 + continue; 132 133 133 134 /* Check whether device uses usbip-host driver. */ 134 - if (!strcmp(udev_device_get_driver(dev), 135 - USBIP_HOST_DRV_NAME)) { 135 + driver = udev_device_get_driver(dev); 136 + if (driver != NULL && !strcmp(driver, USBIP_HOST_DRV_NAME)) { 136 137 edev = usbip_exported_device_new(path); 137 138 if (!edev) { 138 139 dbg("usbip_exported_device_new failed");
+1 -1
drivers/staging/usbip/vhci_sysfs.c
··· 184 184 * @devid: unique device identifier in a remote host 185 185 * @speed: usb device speed in a remote host 186 186 */ 187 - if (sscanf(buf, "%u %u %u %u", &rhport, &sockfd, &devid, &speed) != 1) 187 + if (sscanf(buf, "%u %u %u %u", &rhport, &sockfd, &devid, &speed) != 4) 188 188 return -EINVAL; 189 189 190 190 usbip_dbg_vhci_sysfs("rhport(%u) sockfd(%u) devid(%u) speed(%u)\n",
+3 -6
drivers/staging/vme/devices/vme_user.c
··· 776 776 image[i].kern_buf = kmalloc(image[i].size_buf, GFP_KERNEL); 777 777 if (image[i].kern_buf == NULL) { 778 778 err = -ENOMEM; 779 - goto err_master_buf; 779 + vme_master_free(image[i].resource); 780 + goto err_master; 780 781 } 781 782 } 782 783 ··· 820 819 821 820 return 0; 822 821 823 - /* Ensure counter set correcty to destroy all sysfs devices */ 824 - i = VME_DEVS; 825 822 err_sysfs: 826 823 while (i > 0) { 827 824 i--; ··· 829 830 830 831 /* Ensure counter set correcty to unalloc all master windows */ 831 832 i = MASTER_MAX + 1; 832 - err_master_buf: 833 - for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++) 834 - kfree(image[i].kern_buf); 835 833 err_master: 836 834 while (i > MASTER_MINOR) { 837 835 i--; 836 + kfree(image[i].kern_buf); 838 837 vme_master_free(image[i].resource); 839 838 } 840 839