1 /* 2 * Merged with mainline rtllib.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 RTLLIB_H 25 #define RTLLIB_H 26 #include <linux/if_ether.h> /* ETH_ALEN */ 27 #include <linux/kernel.h> /* ARRAY_SIZE */ 28 #include <linux/module.h> 29 #include <linux/interrupt.h> 30 #include <linux/jiffies.h> 31 #include <linux/timer.h> 32 #include <linux/sched.h> 33 #include <linux/mutex.h> 34 35 #include <linux/delay.h> 36 #include <linux/wireless.h> 37 38 #include "rtllib_debug.h" 39 #include "rtl819x_HT.h" 40 #include "rtl819x_BA.h" 41 #include "rtl819x_TS.h" 42 43 #include <linux/netdevice.h> 44 #include <linux/if_arp.h> /* ARPHRD_ETHER */ 45 #include <net/lib80211.h> 46 47 #define MAX_PRECMD_CNT 16 48 #define MAX_RFDEPENDCMD_CNT 16 49 #define MAX_POSTCMD_CNT 16 50 51 #ifndef WIRELESS_SPY 52 #define WIRELESS_SPY 53 #endif 54 #include <net/iw_handler.h> 55 56 #ifndef IW_MODE_MONITOR 57 #define IW_MODE_MONITOR 6 58 #endif 59 60 #ifndef IWEVCUSTOM 61 #define IWEVCUSTOM 0x8c02 62 #endif 63 64 #ifndef IW_CUSTOM_MAX 65 /* Max number of char in custom event - use multiple of them if needed */ 66 #define IW_CUSTOM_MAX 256 /* In bytes */ 67 #endif 68 69 #define skb_tail_pointer_rsl(skb) skb_tail_pointer(skb) 70 71 #define queue_delayed_work_rsl(x, y, z) queue_delayed_work(x, y, z) 72 #define INIT_DELAYED_WORK_RSL(x, y, z) INIT_DELAYED_WORK(x, y) 73 74 #define queue_work_rsl(x, y) queue_work(x, y) 75 #define INIT_WORK_RSL(x, y, z) INIT_WORK(x, y) 76 77 #define container_of_work_rsl(x, y, z) container_of(x, y, z) 78 #define container_of_dwork_rsl(x, y, z) \ 79 container_of(to_delayed_work(x), y, z) 80 81 #define iwe_stream_add_event_rsl(info, start, stop, iwe, len) \ 82 iwe_stream_add_event(info, start, stop, iwe, len) 83 84 #define iwe_stream_add_point_rsl(info, start, stop, iwe, p) \ 85 iwe_stream_add_point(info, start, stop, iwe, p) 86 87 static inline void *netdev_priv_rsl(struct net_device *dev) 88 { 89 return netdev_priv(dev); 90 } 91 92 #define KEY_TYPE_NA 0x0 93 #define KEY_TYPE_WEP40 0x1 94 #define KEY_TYPE_TKIP 0x2 95 #define KEY_TYPE_CCMP 0x4 96 #define KEY_TYPE_WEP104 0x5 97 /* added for rtl819x tx procedure */ 98 #define MAX_QUEUE_SIZE 0x10 99 100 #define BK_QUEUE 0 101 #define BE_QUEUE 1 102 #define VI_QUEUE 2 103 #define VO_QUEUE 3 104 #define HCCA_QUEUE 4 105 #define TXCMD_QUEUE 5 106 #define MGNT_QUEUE 6 107 #define HIGH_QUEUE 7 108 #define BEACON_QUEUE 8 109 110 #ifndef IW_MODE_MESH 111 #define IW_MODE_MESH 7 112 #endif 113 114 #define IE_CISCO_FLAG_POSITION 0x08 115 #define SUPPORT_CKIP_MIC 0x08 116 #define SUPPORT_CKIP_PK 0x10 117 #define RT_RF_OFF_LEVL_HALT_NIC BIT3 118 #define RT_IN_PS_LEVEL(pPSC, _PS_FLAG) \ 119 ((pPSC->CurPsLevel & _PS_FLAG) ? true : false) 120 #define RT_CLEAR_PS_LEVEL(pPSC, _PS_FLAG) \ 121 (pPSC->CurPsLevel &= (~(_PS_FLAG))) 122 #define RT_SET_PS_LEVEL(pPSC, _PS_FLAG) (pPSC->CurPsLevel |= _PS_FLAG) 123 124 /* defined for skb cb field */ 125 /* At most 28 byte */ 126 struct cb_desc { 127 /* Tx Desc Related flags (8-9) */ 128 u8 bLastIniPkt:1; 129 u8 bCmdOrInit:1; 130 u8 bFirstSeg:1; 131 u8 bLastSeg:1; 132 u8 bEncrypt:1; 133 u8 bTxDisableRateFallBack:1; 134 u8 bTxUseDriverAssingedRate:1; 135 u8 bHwSec:1; 136 137 u8 nStuckCount; 138 139 /* Tx Firmware Related flags (10-11)*/ 140 u8 bCTSEnable:1; 141 u8 bRTSEnable:1; 142 u8 bUseShortGI:1; 143 u8 bUseShortPreamble:1; 144 u8 bTxEnableFwCalcDur:1; 145 u8 bAMPDUEnable:1; 146 u8 bRTSSTBC:1; 147 u8 RTSSC:1; 148 149 u8 bRTSBW:1; 150 u8 bPacketBW:1; 151 u8 bRTSUseShortPreamble:1; 152 u8 bRTSUseShortGI:1; 153 u8 bMulticast:1; 154 u8 bBroadcast:1; 155 u8 drv_agg_enable:1; 156 u8 reserved2:1; 157 158 /* Tx Desc related element(12-19) */ 159 u8 rata_index; 160 u8 queue_index; 161 u16 txbuf_size; 162 u8 RATRIndex; 163 u8 bAMSDU:1; 164 u8 bFromAggrQ:1; 165 u8 reserved6:6; 166 u8 macId; 167 u8 priority; 168 169 /* Tx firmware related element(20-27) */ 170 u8 data_rate; 171 u8 rts_rate; 172 u8 ampdu_factor; 173 u8 ampdu_density; 174 u8 DrvAggrNum; 175 u8 bdhcp; 176 u16 pkt_size; 177 u8 bIsSpecialDataFrame; 178 179 u8 bBTTxPacket; 180 u8 bIsBTProbRsp; 181 }; 182 183 enum sw_chnl_cmd_id { 184 CmdID_End, 185 CmdID_SetTxPowerLevel, 186 CmdID_BBRegWrite10, 187 CmdID_WritePortUlong, 188 CmdID_WritePortUshort, 189 CmdID_WritePortUchar, 190 CmdID_RF_WriteReg, 191 }; 192 193 struct sw_chnl_cmd { 194 enum sw_chnl_cmd_id CmdID; 195 u32 Para1; 196 u32 Para2; 197 u32 msDelay; 198 } __packed; 199 200 /*--------------------------Define -------------------------------------------*/ 201 #define MGN_1M 0x02 202 #define MGN_2M 0x04 203 #define MGN_5_5M 0x0b 204 #define MGN_11M 0x16 205 206 #define MGN_6M 0x0c 207 #define MGN_9M 0x12 208 #define MGN_12M 0x18 209 #define MGN_18M 0x24 210 #define MGN_24M 0x30 211 #define MGN_36M 0x48 212 #define MGN_48M 0x60 213 #define MGN_54M 0x6c 214 215 #define MGN_MCS0 0x80 216 #define MGN_MCS1 0x81 217 #define MGN_MCS2 0x82 218 #define MGN_MCS3 0x83 219 #define MGN_MCS4 0x84 220 #define MGN_MCS5 0x85 221 #define MGN_MCS6 0x86 222 #define MGN_MCS7 0x87 223 #define MGN_MCS8 0x88 224 #define MGN_MCS9 0x89 225 #define MGN_MCS10 0x8a 226 #define MGN_MCS11 0x8b 227 #define MGN_MCS12 0x8c 228 #define MGN_MCS13 0x8d 229 #define MGN_MCS14 0x8e 230 #define MGN_MCS15 0x8f 231 232 enum hw_variables { 233 HW_VAR_ETHER_ADDR, 234 HW_VAR_MULTICAST_REG, 235 HW_VAR_BASIC_RATE, 236 HW_VAR_BSSID, 237 HW_VAR_MEDIA_STATUS, 238 HW_VAR_SECURITY_CONF, 239 HW_VAR_BEACON_INTERVAL, 240 HW_VAR_ATIM_WINDOW, 241 HW_VAR_LISTEN_INTERVAL, 242 HW_VAR_CS_COUNTER, 243 HW_VAR_DEFAULTKEY0, 244 HW_VAR_DEFAULTKEY1, 245 HW_VAR_DEFAULTKEY2, 246 HW_VAR_DEFAULTKEY3, 247 HW_VAR_SIFS, 248 HW_VAR_DIFS, 249 HW_VAR_EIFS, 250 HW_VAR_SLOT_TIME, 251 HW_VAR_ACK_PREAMBLE, 252 HW_VAR_CW_CONFIG, 253 HW_VAR_CW_VALUES, 254 HW_VAR_RATE_FALLBACK_CONTROL, 255 HW_VAR_CONTENTION_WINDOW, 256 HW_VAR_RETRY_COUNT, 257 HW_VAR_TR_SWITCH, 258 HW_VAR_COMMAND, 259 HW_VAR_WPA_CONFIG, 260 HW_VAR_AMPDU_MIN_SPACE, 261 HW_VAR_SHORTGI_DENSITY, 262 HW_VAR_AMPDU_FACTOR, 263 HW_VAR_MCS_RATE_AVAILABLE, 264 HW_VAR_AC_PARAM, 265 HW_VAR_ACM_CTRL, 266 HW_VAR_DIS_Req_Qsize, 267 HW_VAR_CCX_CHNL_LOAD, 268 HW_VAR_CCX_NOISE_HISTOGRAM, 269 HW_VAR_CCX_CLM_NHM, 270 HW_VAR_TxOPLimit, 271 HW_VAR_TURBO_MODE, 272 HW_VAR_RF_STATE, 273 HW_VAR_RF_OFF_BY_HW, 274 HW_VAR_BUS_SPEED, 275 HW_VAR_SET_DEV_POWER, 276 277 HW_VAR_RCR, 278 HW_VAR_RATR_0, 279 HW_VAR_RRSR, 280 HW_VAR_CPU_RST, 281 HW_VAR_CECHK_BSSID, 282 HW_VAR_LBK_MODE, 283 HW_VAR_AES_11N_FIX, 284 HW_VAR_USB_RX_AGGR, 285 HW_VAR_USER_CONTROL_TURBO_MODE, 286 HW_VAR_RETRY_LIMIT, 287 HW_VAR_INIT_TX_RATE, 288 HW_VAR_TX_RATE_REG, 289 HW_VAR_EFUSE_USAGE, 290 HW_VAR_EFUSE_BYTES, 291 HW_VAR_AUTOLOAD_STATUS, 292 HW_VAR_RF_2R_DISABLE, 293 HW_VAR_SET_RPWM, 294 HW_VAR_H2C_FW_PWRMODE, 295 HW_VAR_H2C_FW_JOINBSSRPT, 296 HW_VAR_1X1_RECV_COMBINE, 297 HW_VAR_STOP_SEND_BEACON, 298 HW_VAR_TSF_TIMER, 299 HW_VAR_IO_CMD, 300 301 HW_VAR_RF_RECOVERY, 302 HW_VAR_H2C_FW_UPDATE_GTK, 303 HW_VAR_WF_MASK, 304 HW_VAR_WF_CRC, 305 HW_VAR_WF_IS_MAC_ADDR, 306 HW_VAR_H2C_FW_OFFLOAD, 307 HW_VAR_RESET_WFCRC, 308 309 HW_VAR_HANDLE_FW_C2H, 310 HW_VAR_DL_FW_RSVD_PAGE, 311 HW_VAR_AID, 312 HW_VAR_HW_SEQ_ENABLE, 313 HW_VAR_CORRECT_TSF, 314 HW_VAR_BCN_VALID, 315 HW_VAR_FWLPS_RF_ON, 316 HW_VAR_DUAL_TSF_RST, 317 HW_VAR_SWITCH_EPHY_WoWLAN, 318 HW_VAR_INT_MIGRATION, 319 HW_VAR_INT_AC, 320 HW_VAR_RF_TIMING, 321 }; 322 323 enum rt_op_mode { 324 RT_OP_MODE_AP, 325 RT_OP_MODE_INFRASTRUCTURE, 326 RT_OP_MODE_IBSS, 327 RT_OP_MODE_NO_LINK, 328 }; 329 330 331 #define aSifsTime \ 332 (((priv->rtllib->current_network.mode == IEEE_A) \ 333 || (priv->rtllib->current_network.mode == IEEE_N_24G) \ 334 || (priv->rtllib->current_network.mode == IEEE_N_5G)) ? 16 : 10) 335 336 #define MGMT_QUEUE_NUM 5 337 338 #define MAX_IE_LEN 0xff 339 340 #define msleep_interruptible_rsl msleep_interruptible 341 342 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section 343 * 6.2.1.1.2. 344 * 345 * The figure in section 7.1.2 suggests a body size of up to 2312 346 * bytes is allowed, which is a bit confusing, I suspect this 347 * represents the 2304 bytes of real data, plus a possible 8 bytes of 348 * WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) 349 */ 350 #define RTLLIB_1ADDR_LEN 10 351 #define RTLLIB_2ADDR_LEN 16 352 #define RTLLIB_3ADDR_LEN 24 353 #define RTLLIB_4ADDR_LEN 30 354 #define RTLLIB_FCS_LEN 4 355 356 #define RTLLIB_SKBBUFFER_SIZE 2500 357 358 #define MIN_FRAG_THRESHOLD 256U 359 #define MAX_FRAG_THRESHOLD 2346U 360 361 /* Frame control field constants */ 362 #define RTLLIB_FCTL_FTYPE 0x000c 363 #define RTLLIB_FCTL_STYPE 0x00f0 364 #define RTLLIB_FCTL_FRAMETYPE 0x00fc 365 #define RTLLIB_FCTL_TODS 0x0100 366 #define RTLLIB_FCTL_FROMDS 0x0200 367 #define RTLLIB_FCTL_DSTODS 0x0300 368 #define RTLLIB_FCTL_MOREFRAGS 0x0400 369 #define RTLLIB_FCTL_RETRY 0x0800 370 #define RTLLIB_FCTL_PM 0x1000 371 #define RTLLIB_FCTL_MOREDATA 0x2000 372 #define RTLLIB_FCTL_WEP 0x4000 373 #define RTLLIB_FCTL_ORDER 0x8000 374 375 #define RTLLIB_FTYPE_MGMT 0x0000 376 #define RTLLIB_FTYPE_CTL 0x0004 377 #define RTLLIB_FTYPE_DATA 0x0008 378 379 /* management */ 380 #define RTLLIB_STYPE_ASSOC_REQ 0x0000 381 #define RTLLIB_STYPE_ASSOC_RESP 0x0010 382 #define RTLLIB_STYPE_REASSOC_REQ 0x0020 383 #define RTLLIB_STYPE_REASSOC_RESP 0x0030 384 #define RTLLIB_STYPE_PROBE_REQ 0x0040 385 #define RTLLIB_STYPE_PROBE_RESP 0x0050 386 #define RTLLIB_STYPE_BEACON 0x0080 387 #define RTLLIB_STYPE_ATIM 0x0090 388 #define RTLLIB_STYPE_DISASSOC 0x00A0 389 #define RTLLIB_STYPE_AUTH 0x00B0 390 #define RTLLIB_STYPE_DEAUTH 0x00C0 391 #define RTLLIB_STYPE_MANAGE_ACT 0x00D0 392 393 /* control */ 394 #define RTLLIB_STYPE_PSPOLL 0x00A0 395 #define RTLLIB_STYPE_RTS 0x00B0 396 #define RTLLIB_STYPE_CTS 0x00C0 397 #define RTLLIB_STYPE_ACK 0x00D0 398 399 /* data */ 400 #define RTLLIB_STYPE_DATA 0x0000 401 #define RTLLIB_STYPE_DATA_CFACK 0x0010 402 #define RTLLIB_STYPE_DATA_CFPOLL 0x0020 403 #define RTLLIB_STYPE_DATA_CFACKPOLL 0x0030 404 #define RTLLIB_STYPE_NULLFUNC 0x0040 405 #define RTLLIB_STYPE_QOS_DATA 0x0080 406 #define RTLLIB_STYPE_QOS_NULL 0x00C0 407 408 #define RTLLIB_SCTL_FRAG 0x000F 409 #define RTLLIB_SCTL_SEQ 0xFFF0 410 411 /* QOS control */ 412 #define RTLLIB_QCTL_TID 0x000F 413 414 #define FC_QOS_BIT BIT7 415 #define IsDataFrame(pdu) (((pdu[0] & 0x0C) == 0x08) ? true : false) 416 #define IsLegacyDataFrame(pdu) (IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT))) 417 #define IsQoSDataFrame(pframe) \ 418 ((*(u16 *)pframe&(RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) == \ 419 (RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) 420 #define Frame_Order(pframe) (*(u16 *)pframe&RTLLIB_FCTL_ORDER) 421 #define SN_LESS(a, b) (((a-b)&0x800) != 0) 422 #define SN_EQUAL(a, b) (a == b) 423 #define MAX_DEV_ADDR_SIZE 8 424 425 enum act_category { 426 ACT_CAT_QOS = 1, 427 ACT_CAT_DLS = 2, 428 ACT_CAT_BA = 3, 429 ACT_CAT_HT = 7, 430 ACT_CAT_WMM = 17, 431 }; 432 433 enum ba_action { 434 ACT_ADDBAREQ = 0, 435 ACT_ADDBARSP = 1, 436 ACT_DELBA = 2, 437 }; 438 439 enum init_gain_op_type { 440 IG_Backup = 0, 441 IG_Restore, 442 IG_Max 443 }; 444 445 enum led_ctl_mode { 446 LED_CTL_POWER_ON = 1, 447 LED_CTL_LINK = 2, 448 LED_CTL_NO_LINK = 3, 449 LED_CTL_TX = 4, 450 LED_CTL_RX = 5, 451 LED_CTL_SITE_SURVEY = 6, 452 LED_CTL_POWER_OFF = 7, 453 LED_CTL_START_TO_LINK = 8, 454 }; 455 456 enum rt_rf_type_def { 457 RF_1T2R = 0, 458 RF_2T4R, 459 }; 460 461 enum wireless_mode { 462 WIRELESS_MODE_UNKNOWN = 0x00, 463 WIRELESS_MODE_A = 0x01, 464 WIRELESS_MODE_B = 0x02, 465 WIRELESS_MODE_G = 0x04, 466 WIRELESS_MODE_AUTO = 0x08, 467 WIRELESS_MODE_N_24G = 0x10, 468 WIRELESS_MODE_N_5G = 0x20 469 }; 470 471 #ifndef ETH_P_PAE 472 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */ 473 #define ETH_P_IP 0x0800 /* Internet Protocol packet */ 474 #define ETH_P_ARP 0x0806 /* Address Resolution packet */ 475 #endif /* ETH_P_PAE */ 476 477 #ifndef ETH_P_80211_RAW 478 #define ETH_P_80211_RAW (ETH_P_ECONET + 1) 479 #endif 480 481 /* IEEE 802.11 defines */ 482 483 #define P80211_OUI_LEN 3 484 485 struct rtllib_snap_hdr { 486 487 u8 dsap; /* always 0xAA */ 488 u8 ssap; /* always 0xAA */ 489 u8 ctrl; /* always 0x03 */ 490 u8 oui[P80211_OUI_LEN]; /* organizational universal id */ 491 492 } __packed; 493 494 enum _REG_PREAMBLE_MODE { 495 PREAMBLE_LONG = 1, 496 PREAMBLE_AUTO = 2, 497 PREAMBLE_SHORT = 3, 498 }; 499 500 #define SNAP_SIZE sizeof(struct rtllib_snap_hdr) 501 502 #define WLAN_FC_GET_TYPE(fc) ((fc) & RTLLIB_FCTL_FTYPE) 503 #define WLAN_FC_GET_STYPE(fc) ((fc) & RTLLIB_FCTL_STYPE) 504 #define WLAN_FC_MORE_DATA(fc) ((fc) & RTLLIB_FCTL_MOREDATA) 505 506 #define WLAN_FC_GET_FRAMETYPE(fc) ((fc) & RTLLIB_FCTL_FRAMETYPE) 507 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTLLIB_SCTL_FRAG) 508 #define WLAN_GET_SEQ_SEQ(seq) (((seq) & RTLLIB_SCTL_SEQ) >> 4) 509 510 /* Authentication algorithms */ 511 #define WLAN_AUTH_OPEN 0 512 #define WLAN_AUTH_SHARED_KEY 1 513 #define WLAN_AUTH_LEAP 128 514 515 #define WLAN_CAPABILITY_ESS (1<<0) 516 #define WLAN_CAPABILITY_IBSS (1<<1) 517 #define WLAN_CAPABILITY_PRIVACY (1<<4) 518 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5) 519 #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10) 520 521 #define RTLLIB_STATMASK_SIGNAL (1<<0) 522 #define RTLLIB_STATMASK_RSSI (1<<1) 523 #define RTLLIB_STATMASK_NOISE (1<<2) 524 #define RTLLIB_STATMASK_WEMASK 0x7 525 526 #define RTLLIB_CCK_MODULATION (1<<0) 527 #define RTLLIB_OFDM_MODULATION (1<<1) 528 529 #define RTLLIB_24GHZ_BAND (1<<0) 530 #define RTLLIB_52GHZ_BAND (1<<1) 531 532 #define RTLLIB_CCK_RATE_LEN 4 533 #define RTLLIB_CCK_RATE_1MB 0x02 534 #define RTLLIB_CCK_RATE_2MB 0x04 535 #define RTLLIB_CCK_RATE_5MB 0x0B 536 #define RTLLIB_CCK_RATE_11MB 0x16 537 #define RTLLIB_OFDM_RATE_LEN 8 538 #define RTLLIB_OFDM_RATE_6MB 0x0C 539 #define RTLLIB_OFDM_RATE_9MB 0x12 540 #define RTLLIB_OFDM_RATE_12MB 0x18 541 #define RTLLIB_OFDM_RATE_18MB 0x24 542 #define RTLLIB_OFDM_RATE_24MB 0x30 543 #define RTLLIB_OFDM_RATE_36MB 0x48 544 #define RTLLIB_OFDM_RATE_48MB 0x60 545 #define RTLLIB_OFDM_RATE_54MB 0x6C 546 #define RTLLIB_BASIC_RATE_MASK 0x80 547 548 /* this is stolen and modified from the madwifi driver*/ 549 #define RTLLIB_FC0_TYPE_MASK 0x0c 550 #define RTLLIB_FC0_TYPE_DATA 0x08 551 #define RTLLIB_FC0_SUBTYPE_MASK 0xB0 552 #define RTLLIB_FC0_SUBTYPE_QOS 0x80 553 554 #define RTLLIB_QOS_HAS_SEQ(fc) \ 555 (((fc) & (RTLLIB_FC0_TYPE_MASK | RTLLIB_FC0_SUBTYPE_MASK)) == \ 556 (RTLLIB_FC0_TYPE_DATA | RTLLIB_FC0_SUBTYPE_QOS)) 557 558 /* this is stolen from ipw2200 driver */ 559 #define IEEE_IBSS_MAC_HASH_SIZE 31 560 struct ieee_ibss_seq { 561 u8 mac[ETH_ALEN]; 562 u16 seq_num[17]; 563 u16 frag_num[17]; 564 unsigned long packet_time[17]; 565 struct list_head list; 566 }; 567 568 /* NOTE: This data is for statistical purposes; not all hardware provides this 569 * information for frames received. Not setting these will not cause 570 * any adverse affects. 571 */ 572 struct rtllib_rx_stats { 573 u64 mac_time; 574 s8 rssi; 575 u8 signal; 576 u8 noise; 577 u16 rate; /* in 100 kbps */ 578 u8 received_channel; 579 u8 control; 580 u8 mask; 581 u8 freq; 582 u16 len; 583 u64 tsf; 584 u32 beacon_time; 585 u8 nic_type; 586 u16 Length; 587 u8 SignalQuality; 588 s32 RecvSignalPower; 589 s8 RxPower; 590 u8 SignalStrength; 591 u16 bHwError:1; 592 u16 bCRC:1; 593 u16 bICV:1; 594 u16 bShortPreamble:1; 595 u16 Antenna:1; 596 u16 Decrypted:1; 597 u16 Wakeup:1; 598 u16 Reserved0:1; 599 u8 AGC; 600 u32 TimeStampLow; 601 u32 TimeStampHigh; 602 bool bShift; 603 bool bIsQosData; 604 605 u8 RxDrvInfoSize; 606 u8 RxBufShift; 607 bool bIsAMPDU; 608 bool bFirstMPDU; 609 bool bContainHTC; 610 bool RxIs40MHzPacket; 611 u32 RxPWDBAll; 612 u8 RxMIMOSignalStrength[4]; 613 s8 RxMIMOSignalQuality[2]; 614 bool bPacketMatchBSSID; 615 bool bIsCCK; 616 bool bPacketToSelf; 617 u16 packetlength; 618 u16 fraglength; 619 u16 fragoffset; 620 u16 ntotalfrag; 621 bool bPacketBeacon; 622 bool bToSelfBA; 623 u16 Seq_Num; 624 }; 625 626 /* IEEE 802.11 requires that STA supports concurrent reception of at least 627 * three fragmented frames. This define can be increased to support more 628 * concurrent frames, but it should be noted that each entry can consume about 629 * 2 kB of RAM and increasing cache size will slow down frame reassembly. 630 */ 631 #define RTLLIB_FRAG_CACHE_LEN 4 632 633 struct rtllib_frag_entry { 634 unsigned long first_frag_time; 635 unsigned int seq; 636 unsigned int last_frag; 637 struct sk_buff *skb; 638 u8 src_addr[ETH_ALEN]; 639 u8 dst_addr[ETH_ALEN]; 640 }; 641 642 struct rtllib_device; 643 644 #define SEC_ACTIVE_KEY (1<<4) 645 #define SEC_AUTH_MODE (1<<5) 646 #define SEC_UNICAST_GROUP (1<<6) 647 #define SEC_LEVEL (1<<7) 648 #define SEC_ENABLED (1<<8) 649 650 #define SEC_LEVEL_0 0 /* None */ 651 #define SEC_LEVEL_1 1 /* WEP 40 and 104 bit */ 652 #define SEC_LEVEL_2 2 /* Level 1 + TKIP */ 653 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */ 654 #define SEC_LEVEL_3 4 /* Level 2 + CCMP */ 655 656 #define SEC_ALG_NONE 0 657 #define SEC_ALG_WEP 1 658 #define SEC_ALG_TKIP 2 659 #define SEC_ALG_CCMP 4 660 661 #define WEP_KEY_LEN 13 662 #define SCM_KEY_LEN 32 663 664 struct rtllib_security { 665 u16 active_key:2, 666 enabled:1, 667 auth_mode:2, 668 auth_algo:4, 669 unicast_uses_group:1, 670 encrypt:1; 671 u8 key_sizes[NUM_WEP_KEYS]; 672 u8 keys[NUM_WEP_KEYS][SCM_KEY_LEN]; 673 u8 level; 674 u16 flags; 675 } __packed; 676 677 678 /* 802.11 data frame from AP 679 * ,-------------------------------------------------------------------. 680 * Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 | 681 * |------|------|---------|---------|---------|------|---------|------| 682 * Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | frame | fcs | 683 * | | tion | (BSSID) | | | ence | data | | 684 * `-------------------------------------------------------------------' 685 * Total: 28-2340 bytes 686 */ 687 688 /* Management Frame Information Element Types */ 689 enum rtllib_mfie { 690 MFIE_TYPE_SSID = 0, 691 MFIE_TYPE_RATES = 1, 692 MFIE_TYPE_FH_SET = 2, 693 MFIE_TYPE_DS_SET = 3, 694 MFIE_TYPE_CF_SET = 4, 695 MFIE_TYPE_TIM = 5, 696 MFIE_TYPE_IBSS_SET = 6, 697 MFIE_TYPE_COUNTRY = 7, 698 MFIE_TYPE_HOP_PARAMS = 8, 699 MFIE_TYPE_HOP_TABLE = 9, 700 MFIE_TYPE_REQUEST = 10, 701 MFIE_TYPE_CHALLENGE = 16, 702 MFIE_TYPE_POWER_CONSTRAINT = 32, 703 MFIE_TYPE_POWER_CAPABILITY = 33, 704 MFIE_TYPE_TPC_REQUEST = 34, 705 MFIE_TYPE_TPC_REPORT = 35, 706 MFIE_TYPE_SUPP_CHANNELS = 36, 707 MFIE_TYPE_CSA = 37, 708 MFIE_TYPE_MEASURE_REQUEST = 38, 709 MFIE_TYPE_MEASURE_REPORT = 39, 710 MFIE_TYPE_QUIET = 40, 711 MFIE_TYPE_IBSS_DFS = 41, 712 MFIE_TYPE_ERP = 42, 713 MFIE_TYPE_HT_CAP = 45, 714 MFIE_TYPE_RSN = 48, 715 MFIE_TYPE_RATES_EX = 50, 716 MFIE_TYPE_HT_INFO = 61, 717 MFIE_TYPE_AIRONET = 133, 718 MFIE_TYPE_GENERIC = 221, 719 MFIE_TYPE_QOS_PARAMETER = 222, 720 }; 721 722 /* Minimal header; can be used for passing 802.11 frames with sufficient 723 * information to determine what type of underlying data type is actually 724 * stored in the data. 725 */ 726 struct rtllib_pspoll_hdr { 727 __le16 frame_ctl; 728 __le16 aid; 729 u8 bssid[ETH_ALEN]; 730 u8 ta[ETH_ALEN]; 731 } __packed; 732 733 struct rtllib_hdr { 734 __le16 frame_ctl; 735 __le16 duration_id; 736 u8 payload[0]; 737 } __packed; 738 739 struct rtllib_hdr_1addr { 740 __le16 frame_ctl; 741 __le16 duration_id; 742 u8 addr1[ETH_ALEN]; 743 u8 payload[0]; 744 } __packed; 745 746 struct rtllib_hdr_2addr { 747 __le16 frame_ctl; 748 __le16 duration_id; 749 u8 addr1[ETH_ALEN]; 750 u8 addr2[ETH_ALEN]; 751 u8 payload[0]; 752 } __packed; 753 754 struct rtllib_hdr_3addr { 755 __le16 frame_ctl; 756 __le16 duration_id; 757 u8 addr1[ETH_ALEN]; 758 u8 addr2[ETH_ALEN]; 759 u8 addr3[ETH_ALEN]; 760 __le16 seq_ctl; 761 u8 payload[0]; 762 } __packed; 763 764 struct rtllib_hdr_4addr { 765 __le16 frame_ctl; 766 __le16 duration_id; 767 u8 addr1[ETH_ALEN]; 768 u8 addr2[ETH_ALEN]; 769 u8 addr3[ETH_ALEN]; 770 __le16 seq_ctl; 771 u8 addr4[ETH_ALEN]; 772 u8 payload[0]; 773 } __packed; 774 775 struct rtllib_hdr_3addrqos { 776 __le16 frame_ctl; 777 __le16 duration_id; 778 u8 addr1[ETH_ALEN]; 779 u8 addr2[ETH_ALEN]; 780 u8 addr3[ETH_ALEN]; 781 __le16 seq_ctl; 782 __le16 qos_ctl; 783 u8 payload[0]; 784 } __packed; 785 786 struct rtllib_hdr_4addrqos { 787 __le16 frame_ctl; 788 __le16 duration_id; 789 u8 addr1[ETH_ALEN]; 790 u8 addr2[ETH_ALEN]; 791 u8 addr3[ETH_ALEN]; 792 __le16 seq_ctl; 793 u8 addr4[ETH_ALEN]; 794 __le16 qos_ctl; 795 u8 payload[0]; 796 } __packed; 797 798 struct rtllib_info_element { 799 u8 id; 800 u8 len; 801 u8 data[0]; 802 } __packed; 803 804 struct rtllib_authentication { 805 struct rtllib_hdr_3addr header; 806 __le16 algorithm; 807 __le16 transaction; 808 __le16 status; 809 /*challenge*/ 810 struct rtllib_info_element info_element[0]; 811 } __packed; 812 813 struct rtllib_disauth { 814 struct rtllib_hdr_3addr header; 815 __le16 reason; 816 } __packed; 817 818 struct rtllib_disassoc { 819 struct rtllib_hdr_3addr header; 820 __le16 reason; 821 } __packed; 822 823 struct rtllib_probe_request { 824 struct rtllib_hdr_3addr header; 825 /* SSID, supported rates */ 826 struct rtllib_info_element info_element[0]; 827 } __packed; 828 829 struct rtllib_probe_response { 830 struct rtllib_hdr_3addr header; 831 u32 time_stamp[2]; 832 __le16 beacon_interval; 833 __le16 capability; 834 /* SSID, supported rates, FH params, DS params, 835 * CF params, IBSS params, TIM (if beacon), RSN 836 */ 837 struct rtllib_info_element info_element[0]; 838 } __packed; 839 840 /* Alias beacon for probe_response */ 841 #define rtllib_beacon rtllib_probe_response 842 843 struct rtllib_assoc_request_frame { 844 struct rtllib_hdr_3addr header; 845 __le16 capability; 846 __le16 listen_interval; 847 /* SSID, supported rates, RSN */ 848 struct rtllib_info_element info_element[0]; 849 } __packed; 850 851 struct rtllib_assoc_response_frame { 852 struct rtllib_hdr_3addr header; 853 __le16 capability; 854 __le16 status; 855 __le16 aid; 856 struct rtllib_info_element info_element[0]; /* supported rates */ 857 } __packed; 858 859 struct rtllib_txb { 860 u8 nr_frags; 861 u8 encrypted; 862 u8 queue_index; 863 u8 rts_included; 864 u16 reserved; 865 __le16 frag_size; 866 __le16 payload_size; 867 struct sk_buff *fragments[0]; 868 }; 869 870 #define MAX_SUBFRAME_COUNT 64 871 struct rtllib_rxb { 872 u8 nr_subframes; 873 struct sk_buff *subframes[MAX_SUBFRAME_COUNT]; 874 u8 dst[ETH_ALEN]; 875 u8 src[ETH_ALEN]; 876 } __packed; 877 878 union frameqos { 879 u16 shortdata; 880 u8 chardata[2]; 881 struct { 882 u16 tid:4; 883 u16 eosp:1; 884 u16 ack_policy:2; 885 u16 reserved:1; 886 u16 txop:8; 887 } field; 888 }; 889 890 /* MAX_RATES_LENGTH needs to be 12. The spec says 8, and many APs 891 * only use 8, and then use extended rates for the remaining supported 892 * rates. Other APs, however, stick all of their supported rates on the 893 * main rates information element... 894 */ 895 #define MAX_RATES_LENGTH ((u8)12) 896 #define MAX_RATES_EX_LENGTH ((u8)16) 897 #define MAX_NETWORK_COUNT 96 898 899 #define MAX_CHANNEL_NUMBER 161 900 #define RTLLIB_SOFTMAC_SCAN_TIME 100 901 #define RTLLIB_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2) 902 903 #define MAX_WPA_IE_LEN 64 904 #define MAX_WZC_IE_LEN 256 905 906 #define NETWORK_EMPTY_ESSID (1<<0) 907 #define NETWORK_HAS_OFDM (1<<1) 908 #define NETWORK_HAS_CCK (1<<2) 909 910 /* QoS structure */ 911 #define NETWORK_HAS_QOS_PARAMETERS (1<<3) 912 #define NETWORK_HAS_QOS_INFORMATION (1<<4) 913 #define NETWORK_HAS_QOS_MASK (NETWORK_HAS_QOS_PARAMETERS | \ 914 NETWORK_HAS_QOS_INFORMATION) 915 /* 802.11h */ 916 #define NETWORK_HAS_ERP_VALUE (1<<10) 917 918 #define QOS_QUEUE_NUM 4 919 #define QOS_OUI_LEN 3 920 #define QOS_OUI_TYPE 2 921 #define QOS_ELEMENT_ID 221 922 #define QOS_OUI_INFO_SUB_TYPE 0 923 #define QOS_OUI_PARAM_SUB_TYPE 1 924 #define QOS_VERSION_1 1 925 926 struct rtllib_qos_information_element { 927 u8 elementID; 928 u8 length; 929 u8 qui[QOS_OUI_LEN]; 930 u8 qui_type; 931 u8 qui_subtype; 932 u8 version; 933 u8 ac_info; 934 } __packed; 935 936 struct rtllib_qos_ac_parameter { 937 u8 aci_aifsn; 938 u8 ecw_min_max; 939 __le16 tx_op_limit; 940 } __packed; 941 942 struct rtllib_qos_parameter_info { 943 struct rtllib_qos_information_element info_element; 944 u8 reserved; 945 struct rtllib_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM]; 946 } __packed; 947 948 struct rtllib_qos_parameters { 949 __le16 cw_min[QOS_QUEUE_NUM]; 950 __le16 cw_max[QOS_QUEUE_NUM]; 951 u8 aifs[QOS_QUEUE_NUM]; 952 u8 flag[QOS_QUEUE_NUM]; 953 __le16 tx_op_limit[QOS_QUEUE_NUM]; 954 } __packed; 955 956 struct rtllib_qos_data { 957 struct rtllib_qos_parameters parameters; 958 unsigned int wmm_acm; 959 int active; 960 int supported; 961 u8 param_count; 962 u8 old_param_count; 963 }; 964 965 struct rtllib_tim_parameters { 966 u8 tim_count; 967 u8 tim_period; 968 } __packed; 969 970 struct rtllib_wmm_ac_param { 971 u8 ac_aci_acm_aifsn; 972 u8 ac_ecwmin_ecwmax; 973 u16 ac_txop_limit; 974 }; 975 976 enum eap_type { 977 EAP_PACKET = 0, 978 EAPOL_START, 979 EAPOL_LOGOFF, 980 EAPOL_KEY, 981 EAPOL_ENCAP_ASF_ALERT 982 }; 983 984 static const char * const eap_types[] = { 985 [EAP_PACKET] = "EAP-Packet", 986 [EAPOL_START] = "EAPOL-Start", 987 [EAPOL_LOGOFF] = "EAPOL-Logoff", 988 [EAPOL_KEY] = "EAPOL-Key", 989 [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert" 990 }; 991 992 static inline const char *eap_get_type(int type) 993 { 994 return ((u32)type >= ARRAY_SIZE(eap_types)) ? "Unknown" : 995 eap_types[type]; 996 } 997 static inline u8 Frame_QoSTID(u8 *buf) 998 { 999 struct rtllib_hdr_3addr *hdr; 1000 u16 fc; 1001 1002 hdr = (struct rtllib_hdr_3addr *)buf; 1003 fc = le16_to_cpu(hdr->frame_ctl); 1004 return (u8)((union frameqos *)(buf + (((fc & RTLLIB_FCTL_TODS) && 1005 (fc & RTLLIB_FCTL_FROMDS)) ? 30 : 24)))->field.tid; 1006 } 1007 1008 1009 struct eapol { 1010 u8 snap[6]; 1011 u16 ethertype; 1012 u8 version; 1013 u8 type; 1014 u16 length; 1015 } __packed; 1016 1017 struct rtllib_softmac_stats { 1018 unsigned int rx_ass_ok; 1019 unsigned int rx_ass_err; 1020 unsigned int rx_probe_rq; 1021 unsigned int tx_probe_rs; 1022 unsigned int tx_beacons; 1023 unsigned int rx_auth_rq; 1024 unsigned int rx_auth_rs_ok; 1025 unsigned int rx_auth_rs_err; 1026 unsigned int tx_auth_rq; 1027 unsigned int no_auth_rs; 1028 unsigned int no_ass_rs; 1029 unsigned int tx_ass_rq; 1030 unsigned int rx_ass_rq; 1031 unsigned int tx_probe_rq; 1032 unsigned int reassoc; 1033 unsigned int swtxstop; 1034 unsigned int swtxawake; 1035 unsigned char CurrentShowTxate; 1036 unsigned char last_packet_rate; 1037 unsigned int txretrycount; 1038 }; 1039 1040 /* These are the data types that can make up management packets 1041 * 1042 * u16 auth_algorithm; 1043 * u16 auth_sequence; 1044 * u16 beacon_interval; 1045 * u16 capability; 1046 * u8 current_ap[ETH_ALEN]; 1047 * u16 listen_interval; 1048 * struct { 1049 * u16 association_id:14, reserved:2; 1050 * } __packed; 1051 * u32 time_stamp[2]; 1052 * u16 reason; 1053 * u16 status; 1054 */ 1055 1056 #define RTLLIB_DEFAULT_TX_ESSID "Penguin" 1057 #define RTLLIB_DEFAULT_BASIC_RATE 2 1058 1059 enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame}; 1060 #define MAX_SP_Len (WMM_all_frame << 4) 1061 #define RTLLIB_QOS_TID 0x0f 1062 #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5) 1063 1064 #define RTLLIB_DTIM_MBCAST 4 1065 #define RTLLIB_DTIM_UCAST 2 1066 #define RTLLIB_DTIM_VALID 1 1067 #define RTLLIB_DTIM_INVALID 0 1068 1069 #define RTLLIB_PS_DISABLED 0 1070 #define RTLLIB_PS_UNICAST RTLLIB_DTIM_UCAST 1071 #define RTLLIB_PS_MBCAST RTLLIB_DTIM_MBCAST 1072 1073 #define WME_AC_BK 0x00 1074 #define WME_AC_BE 0x01 1075 #define WME_AC_VI 0x02 1076 #define WME_AC_VO 0x03 1077 #define WME_AC_PRAM_LEN 16 1078 1079 #define MAX_RECEIVE_BUFFER_SIZE 9100 1080 1081 #define UP2AC(up) ( \ 1082 ((up) < 1) ? WME_AC_BE : \ 1083 ((up) < 3) ? WME_AC_BK : \ 1084 ((up) < 4) ? WME_AC_BE : \ 1085 ((up) < 6) ? WME_AC_VI : \ 1086 WME_AC_VO) 1087 1088 #define ETHER_ADDR_LEN 6 /* length of an Ethernet address */ 1089 #define ETHERNET_HEADER_SIZE 14 /* length of two Ethernet address 1090 * plus ether type 1091 */ 1092 1093 enum erp_t { 1094 ERP_NonERPpresent = 0x01, 1095 ERP_UseProtection = 0x02, 1096 ERP_BarkerPreambleMode = 0x04, 1097 }; 1098 1099 struct rtllib_network { 1100 /* These entries are used to identify a unique network */ 1101 u8 bssid[ETH_ALEN]; 1102 u8 channel; 1103 /* Ensure null-terminated for any debug msgs */ 1104 u8 ssid[IW_ESSID_MAX_SIZE + 1]; 1105 u8 ssid_len; 1106 u8 hidden_ssid[IW_ESSID_MAX_SIZE + 1]; 1107 u8 hidden_ssid_len; 1108 struct rtllib_qos_data qos_data; 1109 1110 bool bWithAironetIE; 1111 bool bCkipSupported; 1112 bool bCcxRmEnable; 1113 u16 CcxRmState[2]; 1114 bool bMBssidValid; 1115 u8 MBssidMask; 1116 u8 MBssid[ETH_ALEN]; 1117 bool bWithCcxVerNum; 1118 u8 BssCcxVerNumber; 1119 /* These are network statistics */ 1120 struct rtllib_rx_stats stats; 1121 u16 capability; 1122 u8 rates[MAX_RATES_LENGTH]; 1123 u8 rates_len; 1124 u8 rates_ex[MAX_RATES_EX_LENGTH]; 1125 u8 rates_ex_len; 1126 unsigned long last_scanned; 1127 u8 mode; 1128 u32 flags; 1129 u32 time_stamp[2]; 1130 u16 beacon_interval; 1131 u16 listen_interval; 1132 u16 atim_window; 1133 u8 erp_value; 1134 u8 wpa_ie[MAX_WPA_IE_LEN]; 1135 size_t wpa_ie_len; 1136 u8 rsn_ie[MAX_WPA_IE_LEN]; 1137 size_t rsn_ie_len; 1138 u8 wzc_ie[MAX_WZC_IE_LEN]; 1139 size_t wzc_ie_len; 1140 1141 struct rtllib_tim_parameters tim; 1142 u8 dtim_period; 1143 u8 dtim_data; 1144 u64 last_dtim_sta_time; 1145 1146 u8 wmm_info; 1147 struct rtllib_wmm_ac_param wmm_param[4]; 1148 u8 Turbo_Enable; 1149 u16 CountryIeLen; 1150 u8 CountryIeBuf[MAX_IE_LEN]; 1151 struct bss_ht bssht; 1152 bool broadcom_cap_exist; 1153 bool realtek_cap_exit; 1154 bool marvell_cap_exist; 1155 bool ralink_cap_exist; 1156 bool atheros_cap_exist; 1157 bool cisco_cap_exist; 1158 bool airgo_cap_exist; 1159 bool unknown_cap_exist; 1160 bool berp_info_valid; 1161 bool buseprotection; 1162 u8 SignalStrength; 1163 u8 RSSI; 1164 struct list_head list; 1165 }; 1166 1167 enum rtllib_state { 1168 1169 /* the card is not linked at all */ 1170 RTLLIB_NOLINK = 0, 1171 1172 /* RTLLIB_ASSOCIATING* are for BSS client mode 1173 * the driver shall not perform RX filtering unless 1174 * the state is LINKED. 1175 * The driver shall just check for the state LINKED and 1176 * defaults to NOLINK for ALL the other states (including 1177 * LINKED_SCANNING) 1178 */ 1179 1180 /* the association procedure will start (wq scheduling)*/ 1181 RTLLIB_ASSOCIATING, 1182 RTLLIB_ASSOCIATING_RETRY, 1183 1184 /* the association procedure is sending AUTH request*/ 1185 RTLLIB_ASSOCIATING_AUTHENTICATING, 1186 1187 /* the association procedure has successfully authenticated 1188 * and is sending association request 1189 */ 1190 RTLLIB_ASSOCIATING_AUTHENTICATED, 1191 1192 /* the link is ok. the card associated to a BSS or linked 1193 * to a ibss cell or acting as an AP and creating the bss 1194 */ 1195 RTLLIB_LINKED, 1196 1197 /* same as LINKED, but the driver shall apply RX filter 1198 * rules as we are in NO_LINK mode. As the card is still 1199 * logically linked, but it is doing a syncro site survey 1200 * then it will be back to LINKED state. 1201 */ 1202 RTLLIB_LINKED_SCANNING, 1203 }; 1204 1205 #define DEFAULT_MAX_SCAN_AGE (15 * HZ) 1206 #define DEFAULT_FTS 2346 1207 1208 #define CFG_RTLLIB_RESERVE_FCS (1<<0) 1209 #define CFG_RTLLIB_COMPUTE_FCS (1<<1) 1210 1211 struct tx_pending { 1212 int frag; 1213 struct rtllib_txb *txb; 1214 }; 1215 1216 struct bandwidth_autoswitch { 1217 long threshold_20Mhzto40Mhz; 1218 long threshold_40Mhzto20Mhz; 1219 bool bforced_tx20Mhz; 1220 bool bautoswitch_enable; 1221 }; 1222 1223 1224 1225 #define REORDER_WIN_SIZE 128 1226 #define REORDER_ENTRY_NUM 128 1227 struct rx_reorder_entry { 1228 struct list_head List; 1229 u16 SeqNum; 1230 struct rtllib_rxb *prxb; 1231 }; 1232 enum fsync_state { 1233 Default_Fsync, 1234 HW_Fsync, 1235 SW_Fsync 1236 }; 1237 1238 enum rt_ps_mode { 1239 eActive, 1240 eMaxPs, 1241 eFastPs, 1242 eAutoPs, 1243 }; 1244 1245 enum ips_callback_function { 1246 IPS_CALLBACK_NONE = 0, 1247 IPS_CALLBACK_MGNT_LINK_REQUEST = 1, 1248 IPS_CALLBACK_JOIN_REQUEST = 2, 1249 }; 1250 1251 enum rt_rf_power_state { 1252 eRfOn, 1253 eRfSleep, 1254 eRfOff 1255 }; 1256 1257 struct rt_pwr_save_ctrl { 1258 1259 bool bInactivePs; 1260 bool bIPSModeBackup; 1261 bool bSwRfProcessing; 1262 enum rt_rf_power_state eInactivePowerState; 1263 enum ips_callback_function ReturnPoint; 1264 1265 bool bLeisurePs; 1266 u8 LpsIdleCount; 1267 u8 RegMaxLPSAwakeIntvl; 1268 u8 LPSAwakeIntvl; 1269 1270 u32 CurPsLevel; 1271 u32 RegRfPsLevel; 1272 1273 bool bFwCtrlLPS; 1274 1275 }; 1276 1277 #define RT_RF_CHANGE_SOURCE u32 1278 1279 #define RF_CHANGE_BY_SW BIT31 1280 #define RF_CHANGE_BY_HW BIT30 1281 #define RF_CHANGE_BY_PS BIT29 1282 #define RF_CHANGE_BY_IPS BIT28 1283 #define RF_CHANGE_BY_INIT 0 1284 1285 enum country_code_type { 1286 COUNTRY_CODE_FCC = 0, 1287 COUNTRY_CODE_IC = 1, 1288 COUNTRY_CODE_ETSI = 2, 1289 COUNTRY_CODE_SPAIN = 3, 1290 COUNTRY_CODE_FRANCE = 4, 1291 COUNTRY_CODE_MKK = 5, 1292 COUNTRY_CODE_MKK1 = 6, 1293 COUNTRY_CODE_ISRAEL = 7, 1294 COUNTRY_CODE_TELEC = 8, 1295 COUNTRY_CODE_MIC = 9, 1296 COUNTRY_CODE_GLOBAL_DOMAIN = 10, 1297 COUNTRY_CODE_WORLD_WIDE_13 = 11, 1298 COUNTRY_CODE_TELEC_NETGEAR = 12, 1299 COUNTRY_CODE_MAX 1300 }; 1301 1302 enum scan_op_backup_opt { 1303 SCAN_OPT_BACKUP = 0, 1304 SCAN_OPT_RESTORE, 1305 SCAN_OPT_MAX 1306 }; 1307 1308 enum fw_cmd_io_type { 1309 FW_CMD_DIG_ENABLE = 0, 1310 FW_CMD_DIG_DISABLE = 1, 1311 FW_CMD_DIG_HALT = 2, 1312 FW_CMD_DIG_RESUME = 3, 1313 FW_CMD_HIGH_PWR_ENABLE = 4, 1314 FW_CMD_HIGH_PWR_DISABLE = 5, 1315 FW_CMD_RA_RESET = 6, 1316 FW_CMD_RA_ACTIVE = 7, 1317 FW_CMD_RA_REFRESH_N = 8, 1318 FW_CMD_RA_REFRESH_BG = 9, 1319 FW_CMD_RA_INIT = 10, 1320 FW_CMD_IQK_ENABLE = 11, 1321 FW_CMD_TXPWR_TRACK_ENABLE = 12, 1322 FW_CMD_TXPWR_TRACK_DISABLE = 13, 1323 FW_CMD_TXPWR_TRACK_THERMAL = 14, 1324 FW_CMD_PAUSE_DM_BY_SCAN = 15, 1325 FW_CMD_RESUME_DM_BY_SCAN = 16, 1326 FW_CMD_RA_REFRESH_N_COMB = 17, 1327 FW_CMD_RA_REFRESH_BG_COMB = 18, 1328 FW_CMD_ANTENNA_SW_ENABLE = 19, 1329 FW_CMD_ANTENNA_SW_DISABLE = 20, 1330 FW_CMD_TX_FEEDBACK_CCX_ENABLE = 21, 1331 FW_CMD_LPS_ENTER = 22, 1332 FW_CMD_LPS_LEAVE = 23, 1333 }; 1334 1335 #define RT_MAX_LD_SLOT_NUM 10 1336 struct rt_link_detect { 1337 1338 u32 NumRecvBcnInPeriod; 1339 u32 NumRecvDataInPeriod; 1340 1341 u32 RxBcnNum[RT_MAX_LD_SLOT_NUM]; 1342 u32 RxDataNum[RT_MAX_LD_SLOT_NUM]; 1343 u16 SlotNum; 1344 u16 SlotIndex; 1345 1346 u32 NumTxOkInPeriod; 1347 u32 NumRxOkInPeriod; 1348 u32 NumRxUnicastOkInPeriod; 1349 bool bBusyTraffic; 1350 bool bHigherBusyTraffic; 1351 bool bHigherBusyRxTraffic; 1352 }; 1353 1354 struct sw_cam_table { 1355 1356 u8 macaddr[ETH_ALEN]; 1357 bool bused; 1358 u8 key_buf[16]; 1359 u16 key_type; 1360 u8 useDK; 1361 u8 key_index; 1362 1363 }; 1364 #define TOTAL_CAM_ENTRY 32 1365 struct rate_adaptive { 1366 u8 rate_adaptive_disabled; 1367 u8 ratr_state; 1368 u16 reserve; 1369 1370 u32 high_rssi_thresh_for_ra; 1371 u32 high2low_rssi_thresh_for_ra; 1372 u8 low2high_rssi_thresh_for_ra40M; 1373 u32 low_rssi_thresh_for_ra40M; 1374 u8 low2high_rssi_thresh_for_ra20M; 1375 u32 low_rssi_thresh_for_ra20M; 1376 u32 upper_rssi_threshold_ratr; 1377 u32 middle_rssi_threshold_ratr; 1378 u32 low_rssi_threshold_ratr; 1379 u32 low_rssi_threshold_ratr_40M; 1380 u32 low_rssi_threshold_ratr_20M; 1381 u8 ping_rssi_enable; 1382 u32 ping_rssi_ratr; 1383 u32 ping_rssi_thresh_for_ra; 1384 u32 last_ratr; 1385 u8 PreRATRState; 1386 1387 }; 1388 1389 #define NUM_PMKID_CACHE 16 1390 struct rt_pmkid_list { 1391 u8 Bssid[ETH_ALEN]; 1392 u8 PMKID[16]; 1393 u8 SsidBuf[33]; 1394 u8 bUsed; 1395 }; 1396 1397 struct rt_intel_promisc_mode { 1398 bool bPromiscuousOn; 1399 bool bFilterSourceStationFrame; 1400 }; 1401 1402 1403 /*************** DRIVER STATUS *****/ 1404 #define STATUS_SCANNING 0 1405 /*************** DRIVER STATUS *****/ 1406 1407 enum { 1408 LPS_IS_WAKE = 0, 1409 LPS_IS_SLEEP = 1, 1410 LPS_WAIT_NULL_DATA_SEND = 2, 1411 }; 1412 1413 struct rtllib_device { 1414 struct pci_dev *pdev; 1415 struct net_device *dev; 1416 struct rtllib_security sec; 1417 1418 bool disable_mgnt_queue; 1419 1420 unsigned long status; 1421 u8 CntAfterLink; 1422 1423 enum rt_op_mode OpMode; 1424 1425 /* The last AssocReq/Resp IEs */ 1426 u8 *assocreq_ies, *assocresp_ies; 1427 size_t assocreq_ies_len, assocresp_ies_len; 1428 1429 bool bForcedBgMode; 1430 u8 RF_Type; 1431 1432 u8 hwsec_active; 1433 bool is_silent_reset; 1434 bool is_roaming; 1435 bool ieee_up; 1436 bool cannot_notify; 1437 bool bSupportRemoteWakeUp; 1438 bool actscanning; 1439 bool FirstIe_InScan; 1440 bool be_scan_inprogress; 1441 bool beinretry; 1442 enum rt_rf_power_state eRFPowerState; 1443 RT_RF_CHANGE_SOURCE RfOffReason; 1444 bool is_set_key; 1445 bool wx_set_enc; 1446 struct rt_hi_throughput *pHTInfo; 1447 1448 spinlock_t reorder_spinlock; 1449 u8 Regdot11HTOperationalRateSet[16]; 1450 u8 Regdot11TxHTOperationalRateSet[16]; 1451 u8 dot11HTOperationalRateSet[16]; 1452 u8 RegHTSuppRateSet[16]; 1453 u8 HTCurrentOperaRate; 1454 u8 HTHighestOperaRate; 1455 u8 bTxDisableRateFallBack; 1456 u8 bTxUseDriverAssingedRate; 1457 u8 bTxEnableFwCalcDur; 1458 atomic_t atm_swbw; 1459 1460 struct list_head Tx_TS_Admit_List; 1461 struct list_head Tx_TS_Pending_List; 1462 struct list_head Tx_TS_Unused_List; 1463 struct tx_ts_record TxTsRecord[TOTAL_TS_NUM]; 1464 struct list_head Rx_TS_Admit_List; 1465 struct list_head Rx_TS_Pending_List; 1466 struct list_head Rx_TS_Unused_List; 1467 struct rx_ts_record RxTsRecord[TOTAL_TS_NUM]; 1468 struct rx_reorder_entry RxReorderEntry[128]; 1469 struct list_head RxReorder_Unused_List; 1470 1471 1472 /* Bookkeeping structures */ 1473 struct net_device_stats stats; 1474 struct rtllib_softmac_stats softmac_stats; 1475 1476 /* Probe / Beacon management */ 1477 struct list_head network_free_list; 1478 struct list_head network_list; 1479 struct rtllib_network *networks; 1480 int scans; 1481 int scan_age; 1482 1483 int iw_mode; /* operating mode (IW_MODE_*) */ 1484 bool bNetPromiscuousMode; 1485 struct rt_intel_promisc_mode IntelPromiscuousModeInfo; 1486 1487 spinlock_t lock; 1488 spinlock_t wpax_suitlist_lock; 1489 1490 int tx_headroom; /* Set to size of any additional room needed at front 1491 * of allocated Tx SKBs 1492 */ 1493 u32 config; 1494 1495 /* WEP and other encryption related settings at the device level */ 1496 int open_wep; /* Set to 1 to allow unencrypted frames */ 1497 int auth_mode; 1498 int reset_on_keychange; /* Set to 1 if the HW needs to be reset on 1499 * WEP key changes 1500 */ 1501 1502 /* If the host performs {en,de}cryption, then set to 1 */ 1503 int host_encrypt; 1504 int host_decrypt; 1505 1506 int ieee802_1x; /* is IEEE 802.1X used */ 1507 1508 /* WPA data */ 1509 bool bHalfWirelessN24GMode; 1510 int wpa_enabled; 1511 int drop_unencrypted; 1512 int tkip_countermeasures; 1513 int privacy_invoked; 1514 size_t wpa_ie_len; 1515 u8 *wpa_ie; 1516 size_t wps_ie_len; 1517 u8 *wps_ie; 1518 u8 ap_mac_addr[ETH_ALEN]; 1519 u16 pairwise_key_type; 1520 u16 group_key_type; 1521 1522 struct lib80211_crypt_info crypt_info; 1523 1524 struct sw_cam_table swcamtable[TOTAL_CAM_ENTRY]; 1525 1526 struct rt_pmkid_list PMKIDList[NUM_PMKID_CACHE]; 1527 1528 /* Fragmentation structures */ 1529 struct rtllib_frag_entry frag_cache[17][RTLLIB_FRAG_CACHE_LEN]; 1530 unsigned int frag_next_idx[17]; 1531 u16 fts; /* Fragmentation Threshold */ 1532 #define DEFAULT_RTS_THRESHOLD 2346U 1533 #define MIN_RTS_THRESHOLD 1 1534 #define MAX_RTS_THRESHOLD 2346U 1535 u16 rts; /* RTS threshold */ 1536 1537 /* Association info */ 1538 u8 bssid[ETH_ALEN]; 1539 1540 /* This stores infos for the current network. 1541 * Either the network we are associated in INFRASTRUCTURE 1542 * or the network that we are creating in MASTER mode. 1543 * ad-hoc is a mixture ;-). 1544 * Note that in infrastructure mode, even when not associated, 1545 * fields bssid and essid may be valid (if wpa_set and essid_set 1546 * are true) as thy carry the value set by the user via iwconfig 1547 */ 1548 struct rtllib_network current_network; 1549 1550 enum rtllib_state state; 1551 1552 int short_slot; 1553 int mode; /* A, B, G */ 1554 int modulation; /* CCK, OFDM */ 1555 1556 /* used for forcing the ibss workqueue to terminate 1557 * without wait for the syncro scan to terminate 1558 */ 1559 short sync_scan_hurryup; 1560 u16 scan_watch_dog; 1561 1562 /* map of allowed channels. 0 is dummy */ 1563 void *pDot11dInfo; 1564 bool bGlobalDomain; 1565 u8 active_channel_map[MAX_CHANNEL_NUMBER+1]; 1566 1567 u8 IbssStartChnl; 1568 u8 ibss_maxjoin_chal; 1569 1570 int rate; /* current rate */ 1571 int basic_rate; 1572 1573 short active_scan; 1574 1575 /* this contains flags for selectively enable softmac support */ 1576 u16 softmac_features; 1577 1578 /* if the sequence control field is not filled by HW */ 1579 u16 seq_ctrl[5]; 1580 1581 /* association procedure transaction sequence number */ 1582 u16 associate_seq; 1583 1584 /* AID for RTXed association responses */ 1585 u16 assoc_id; 1586 1587 /* power save mode related*/ 1588 u8 ack_tx_to_ieee; 1589 short ps; 1590 short sta_sleep; 1591 int ps_timeout; 1592 int ps_period; 1593 struct tasklet_struct ps_task; 1594 u64 ps_time; 1595 bool polling; 1596 1597 short raw_tx; 1598 /* used if IEEE_SOFTMAC_TX_QUEUE is set */ 1599 short queue_stop; 1600 short scanning_continue; 1601 short proto_started; 1602 short proto_stoppping; 1603 1604 struct mutex wx_mutex; 1605 struct mutex scan_mutex; 1606 struct mutex ips_mutex; 1607 1608 spinlock_t mgmt_tx_lock; 1609 spinlock_t beacon_lock; 1610 1611 short beacon_txing; 1612 1613 short wap_set; 1614 short ssid_set; 1615 1616 /* set on initialization */ 1617 unsigned int wmm_acm; 1618 1619 /* for discarding duplicated packets in IBSS */ 1620 struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE]; 1621 1622 /* for discarding duplicated packets in BSS */ 1623 u16 last_rxseq_num[17]; /* rx seq previous per-tid */ 1624 u16 last_rxfrag_num[17];/* tx frag previous per-tid */ 1625 unsigned long last_packet_time[17]; 1626 1627 /* for PS mode */ 1628 unsigned long last_rx_ps_time; 1629 bool bAwakePktSent; 1630 u8 LPSDelayCnt; 1631 1632 /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */ 1633 struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM]; 1634 int mgmt_queue_head; 1635 int mgmt_queue_tail; 1636 u8 AsocRetryCount; 1637 struct sk_buff_head skb_waitQ[MAX_QUEUE_SIZE]; 1638 struct sk_buff_head skb_aggQ[MAX_QUEUE_SIZE]; 1639 1640 bool bdynamic_txpower_enable; 1641 1642 bool bCTSToSelfEnable; 1643 1644 u32 fsync_time_interval; 1645 u32 fsync_rate_bitmap; 1646 u8 fsync_rssi_threshold; 1647 bool bfsync_enable; 1648 1649 u8 fsync_multiple_timeinterval; 1650 u32 fsync_firstdiff_ratethreshold; 1651 u32 fsync_seconddiff_ratethreshold; 1652 enum fsync_state fsync_state; 1653 bool bis_any_nonbepkts; 1654 struct bandwidth_autoswitch bandwidth_auto_switch; 1655 bool FwRWRF; 1656 1657 struct rt_link_detect LinkDetectInfo; 1658 bool bIsAggregateFrame; 1659 struct rt_pwr_save_ctrl PowerSaveControl; 1660 1661 /* used if IEEE_SOFTMAC_TX_QUEUE is set */ 1662 struct tx_pending tx_pending; 1663 1664 /* used if IEEE_SOFTMAC_ASSOCIATE is set */ 1665 struct timer_list associate_timer; 1666 1667 /* used if IEEE_SOFTMAC_BEACONS is set */ 1668 struct timer_list beacon_timer; 1669 u8 need_sw_enc; 1670 struct work_struct associate_complete_wq; 1671 struct work_struct ips_leave_wq; 1672 struct delayed_work associate_procedure_wq; 1673 struct delayed_work softmac_scan_wq; 1674 struct delayed_work associate_retry_wq; 1675 struct delayed_work start_ibss_wq; 1676 struct delayed_work hw_wakeup_wq; 1677 struct delayed_work hw_sleep_wq; 1678 struct delayed_work link_change_wq; 1679 struct work_struct wx_sync_scan_wq; 1680 1681 union { 1682 struct rtllib_rxb *RfdArray[REORDER_WIN_SIZE]; 1683 struct rtllib_rxb *stats_IndicateArray[REORDER_WIN_SIZE]; 1684 struct rtllib_rxb *prxbIndicateArray[REORDER_WIN_SIZE]; 1685 struct { 1686 struct sw_chnl_cmd PreCommonCmd[MAX_PRECMD_CNT]; 1687 struct sw_chnl_cmd PostCommonCmd[MAX_POSTCMD_CNT]; 1688 struct sw_chnl_cmd RfDependCmd[MAX_RFDEPENDCMD_CNT]; 1689 }; 1690 }; 1691 1692 /* Callback functions */ 1693 void (*set_security)(struct net_device *dev, 1694 struct rtllib_security *sec); 1695 1696 /* Used to TX data frame by using txb structs. 1697 * this is not used if in the softmac_features 1698 * is set the flag IEEE_SOFTMAC_TX_QUEUE 1699 */ 1700 int (*hard_start_xmit)(struct rtllib_txb *txb, 1701 struct net_device *dev); 1702 1703 int (*reset_port)(struct net_device *dev); 1704 1705 /* Softmac-generated frames (management) are TXed via this 1706 * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is 1707 * not set. As some cards may have different HW queues that 1708 * one might want to use for data and management frames 1709 * the option to have two callbacks might be useful. 1710 * This function can't sleep. 1711 */ 1712 int (*softmac_hard_start_xmit)(struct sk_buff *skb, 1713 struct net_device *dev); 1714 1715 /* used instead of hard_start_xmit (not softmac_hard_start_xmit) 1716 * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data 1717 * frames. If the option IEEE_SOFTMAC_SINGLE_QUEUE is also set 1718 * then also management frames are sent via this callback. 1719 * This function can't sleep. 1720 */ 1721 void (*softmac_data_hard_start_xmit)(struct sk_buff *skb, 1722 struct net_device *dev, int rate); 1723 1724 /* stops the HW queue for DATA frames. Useful to avoid 1725 * waste time to TX data frame when we are reassociating 1726 * This function can sleep. 1727 */ 1728 void (*data_hard_stop)(struct net_device *dev); 1729 1730 /* OK this is complementing to data_poll_hard_stop */ 1731 void (*data_hard_resume)(struct net_device *dev); 1732 1733 /* ask to the driver to retune the radio. 1734 * This function can sleep. the driver should ensure 1735 * the radio has been switched before return. 1736 */ 1737 void (*set_chan)(struct net_device *dev, short ch); 1738 1739 void (*rtllib_start_hw_scan)(struct net_device *dev); 1740 void (*rtllib_stop_hw_scan)(struct net_device *dev); 1741 1742 /* indicate the driver that the link state is changed 1743 * for example it may indicate the card is associated now. 1744 * Driver might be interested in this to apply RX filter 1745 * rules or simply light the LINK led 1746 */ 1747 void (*link_change)(struct net_device *dev); 1748 1749 /* these two function indicates to the HW when to start 1750 * and stop to send beacons. This is used when the 1751 * IEEE_SOFTMAC_BEACONS is not set. For now the 1752 * stop_send_bacons is NOT guaranteed to be called only 1753 * after start_send_beacons. 1754 */ 1755 void (*start_send_beacons)(struct net_device *dev); 1756 void (*stop_send_beacons)(struct net_device *dev); 1757 1758 /* power save mode related */ 1759 void (*sta_wake_up)(struct net_device *dev); 1760 void (*enter_sleep_state)(struct net_device *dev, u64 time); 1761 short (*ps_is_queue_empty)(struct net_device *dev); 1762 int (*handle_beacon)(struct net_device *dev, 1763 struct rtllib_beacon *beacon, 1764 struct rtllib_network *network); 1765 int (*handle_assoc_response)(struct net_device *dev, 1766 struct rtllib_assoc_response_frame *resp, 1767 struct rtllib_network *network); 1768 1769 1770 /* check whether Tx hw resource available */ 1771 short (*check_nic_enough_desc)(struct net_device *dev, int queue_index); 1772 void (*SetBWModeHandler)(struct net_device *dev, 1773 enum ht_channel_width Bandwidth, 1774 enum ht_extchnl_offset Offset); 1775 bool (*GetNmodeSupportBySecCfg)(struct net_device *dev); 1776 void (*SetWirelessMode)(struct net_device *dev, u8 wireless_mode); 1777 bool (*GetHalfNmodeSupportByAPsHandler)(struct net_device *dev); 1778 u8 (*rtllib_ap_sec_type)(struct rtllib_device *ieee); 1779 void (*InitialGainHandler)(struct net_device *dev, u8 Operation); 1780 bool (*SetFwCmdHandler)(struct net_device *dev, 1781 enum fw_cmd_io_type FwCmdIO); 1782 void (*UpdateBeaconInterruptHandler)(struct net_device *dev, 1783 bool start); 1784 void (*ScanOperationBackupHandler)(struct net_device *dev, 1785 u8 Operation); 1786 void (*LedControlHandler)(struct net_device *dev, 1787 enum led_ctl_mode LedAction); 1788 void (*SetHwRegHandler)(struct net_device *dev, u8 variable, u8 *val); 1789 1790 void (*AllowAllDestAddrHandler)(struct net_device *dev, 1791 bool bAllowAllDA, bool WriteIntoReg); 1792 1793 void (*rtllib_ips_leave_wq)(struct net_device *dev); 1794 void (*rtllib_ips_leave)(struct net_device *dev); 1795 void (*LeisurePSLeave)(struct net_device *dev); 1796 1797 /* This must be the last item so that it points to the data 1798 * allocated beyond this structure by alloc_rtllib 1799 */ 1800 u8 priv[0]; 1801 }; 1802 1803 #define IEEE_A (1<<0) 1804 #define IEEE_B (1<<1) 1805 #define IEEE_G (1<<2) 1806 #define IEEE_N_24G (1<<4) 1807 #define IEEE_N_5G (1<<5) 1808 #define IEEE_MODE_MASK (IEEE_A|IEEE_B|IEEE_G) 1809 1810 /* Generate a 802.11 header */ 1811 1812 /* Uses the channel change callback directly 1813 * instead of [start/stop] scan callbacks 1814 */ 1815 #define IEEE_SOFTMAC_SCAN (1<<2) 1816 1817 /* Perform authentication and association handshake */ 1818 #define IEEE_SOFTMAC_ASSOCIATE (1<<3) 1819 1820 /* Generate probe requests */ 1821 #define IEEE_SOFTMAC_PROBERQ (1<<4) 1822 1823 /* Generate response to probe requests */ 1824 #define IEEE_SOFTMAC_PROBERS (1<<5) 1825 1826 /* The ieee802.11 stack will manage the netif queue 1827 * wake/stop for the driver, taking care of 802.11 1828 * fragmentation. See softmac.c for details. 1829 */ 1830 #define IEEE_SOFTMAC_TX_QUEUE (1<<7) 1831 1832 /* Uses only the softmac_data_hard_start_xmit 1833 * even for TX management frames. 1834 */ 1835 #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8) 1836 1837 /* Generate beacons. The stack will enqueue beacons 1838 * to the card 1839 */ 1840 #define IEEE_SOFTMAC_BEACONS (1<<6) 1841 1842 1843 static inline void *rtllib_priv(struct net_device *dev) 1844 { 1845 return ((struct rtllib_device *)netdev_priv(dev))->priv; 1846 } 1847 1848 static inline int rtllib_is_empty_essid(const char *essid, int essid_len) 1849 { 1850 /* Single white space is for Linksys APs */ 1851 if (essid_len == 1 && essid[0] == ' ') 1852 return 1; 1853 1854 /* Otherwise, if the entire essid is 0, we assume it is hidden */ 1855 while (essid_len) { 1856 essid_len--; 1857 if (essid[essid_len] != '\0') 1858 return 0; 1859 } 1860 1861 return 1; 1862 } 1863 1864 static inline int rtllib_get_hdrlen(u16 fc) 1865 { 1866 int hdrlen = RTLLIB_3ADDR_LEN; 1867 1868 switch (WLAN_FC_GET_TYPE(fc)) { 1869 case RTLLIB_FTYPE_DATA: 1870 if ((fc & RTLLIB_FCTL_FROMDS) && (fc & RTLLIB_FCTL_TODS)) 1871 hdrlen = RTLLIB_4ADDR_LEN; /* Addr4 */ 1872 if (RTLLIB_QOS_HAS_SEQ(fc)) 1873 hdrlen += 2; /* QOS ctrl*/ 1874 break; 1875 case RTLLIB_FTYPE_CTL: 1876 switch (WLAN_FC_GET_STYPE(fc)) { 1877 case RTLLIB_STYPE_CTS: 1878 case RTLLIB_STYPE_ACK: 1879 hdrlen = RTLLIB_1ADDR_LEN; 1880 break; 1881 default: 1882 hdrlen = RTLLIB_2ADDR_LEN; 1883 break; 1884 } 1885 break; 1886 } 1887 1888 return hdrlen; 1889 } 1890 1891 static inline u8 *rtllib_get_payload(struct rtllib_hdr *hdr) 1892 { 1893 switch (rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) { 1894 case RTLLIB_1ADDR_LEN: 1895 return ((struct rtllib_hdr_1addr *)hdr)->payload; 1896 case RTLLIB_2ADDR_LEN: 1897 return ((struct rtllib_hdr_2addr *)hdr)->payload; 1898 case RTLLIB_3ADDR_LEN: 1899 return ((struct rtllib_hdr_3addr *)hdr)->payload; 1900 case RTLLIB_4ADDR_LEN: 1901 return ((struct rtllib_hdr_4addr *)hdr)->payload; 1902 } 1903 return NULL; 1904 } 1905 1906 static inline int rtllib_is_ofdm_rate(u8 rate) 1907 { 1908 switch (rate & ~RTLLIB_BASIC_RATE_MASK) { 1909 case RTLLIB_OFDM_RATE_6MB: 1910 case RTLLIB_OFDM_RATE_9MB: 1911 case RTLLIB_OFDM_RATE_12MB: 1912 case RTLLIB_OFDM_RATE_18MB: 1913 case RTLLIB_OFDM_RATE_24MB: 1914 case RTLLIB_OFDM_RATE_36MB: 1915 case RTLLIB_OFDM_RATE_48MB: 1916 case RTLLIB_OFDM_RATE_54MB: 1917 return 1; 1918 } 1919 return 0; 1920 } 1921 1922 static inline int rtllib_is_cck_rate(u8 rate) 1923 { 1924 switch (rate & ~RTLLIB_BASIC_RATE_MASK) { 1925 case RTLLIB_CCK_RATE_1MB: 1926 case RTLLIB_CCK_RATE_2MB: 1927 case RTLLIB_CCK_RATE_5MB: 1928 case RTLLIB_CCK_RATE_11MB: 1929 return 1; 1930 } 1931 return 0; 1932 } 1933 1934 1935 /* rtllib.c */ 1936 void free_rtllib(struct net_device *dev); 1937 struct net_device *alloc_rtllib(int sizeof_priv); 1938 1939 /* rtllib_tx.c */ 1940 1941 int rtllib_encrypt_fragment( 1942 struct rtllib_device *ieee, 1943 struct sk_buff *frag, 1944 int hdr_len); 1945 1946 int rtllib_xmit(struct sk_buff *skb, struct net_device *dev); 1947 void rtllib_txb_free(struct rtllib_txb *); 1948 1949 /* rtllib_rx.c */ 1950 int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb, 1951 struct rtllib_rx_stats *rx_stats); 1952 void rtllib_rx_probe_rq(struct rtllib_device *ieee, 1953 struct sk_buff *skb); 1954 int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel); 1955 1956 /* rtllib_wx.c */ 1957 int rtllib_wx_get_scan(struct rtllib_device *ieee, 1958 struct iw_request_info *info, 1959 union iwreq_data *wrqu, char *key); 1960 int rtllib_wx_set_encode(struct rtllib_device *ieee, 1961 struct iw_request_info *info, 1962 union iwreq_data *wrqu, char *key); 1963 int rtllib_wx_get_encode(struct rtllib_device *ieee, 1964 struct iw_request_info *info, 1965 union iwreq_data *wrqu, char *key); 1966 int rtllib_wx_set_encode_ext(struct rtllib_device *ieee, 1967 struct iw_request_info *info, 1968 union iwreq_data *wrqu, char *extra); 1969 int rtllib_wx_set_auth(struct rtllib_device *ieee, 1970 struct iw_request_info *info, 1971 struct iw_param *data, char *extra); 1972 int rtllib_wx_set_mlme(struct rtllib_device *ieee, 1973 struct iw_request_info *info, 1974 union iwreq_data *wrqu, char *extra); 1975 int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len); 1976 1977 /* rtllib_softmac.c */ 1978 int rtllib_rx_frame_softmac(struct rtllib_device *ieee, struct sk_buff *skb, 1979 struct rtllib_rx_stats *rx_stats, u16 type, 1980 u16 stype); 1981 void rtllib_softmac_new_net(struct rtllib_device *ieee, 1982 struct rtllib_network *net); 1983 1984 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn); 1985 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee); 1986 1987 void rtllib_stop_send_beacons(struct rtllib_device *ieee); 1988 void notify_wx_assoc_event(struct rtllib_device *ieee); 1989 void rtllib_start_ibss(struct rtllib_device *ieee); 1990 void rtllib_softmac_init(struct rtllib_device *ieee); 1991 void rtllib_softmac_free(struct rtllib_device *ieee); 1992 void rtllib_disassociate(struct rtllib_device *ieee); 1993 void rtllib_stop_scan(struct rtllib_device *ieee); 1994 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan); 1995 void rtllib_stop_scan_syncro(struct rtllib_device *ieee); 1996 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh); 1997 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr); 1998 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee); 1999 void rtllib_start_protocol(struct rtllib_device *ieee); 2000 void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown); 2001 2002 void rtllib_EnableNetMonitorMode(struct net_device *dev, bool bInitState); 2003 void rtllib_DisableNetMonitorMode(struct net_device *dev, bool bInitState); 2004 void rtllib_EnableIntelPromiscuousMode(struct net_device *dev, bool bInitState); 2005 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev, 2006 bool bInitState); 2007 void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, 2008 u8 mesh_flag, u8 shutdown); 2009 void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag); 2010 2011 void rtllib_reset_queue(struct rtllib_device *ieee); 2012 void rtllib_wake_all_queues(struct rtllib_device *ieee); 2013 void rtllib_stop_all_queues(struct rtllib_device *ieee); 2014 struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee); 2015 void rtllib_start_send_beacons(struct rtllib_device *ieee); 2016 void rtllib_stop_send_beacons(struct rtllib_device *ieee); 2017 2018 void notify_wx_assoc_event(struct rtllib_device *ieee); 2019 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success); 2020 2021 void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee); 2022 u8 rtllib_ap_sec_type(struct rtllib_device *ieee); 2023 2024 /* rtllib_softmac_wx.c */ 2025 2026 int rtllib_wx_get_wap(struct rtllib_device *ieee, struct iw_request_info *info, 2027 union iwreq_data *wrqu, char *ext); 2028 2029 int rtllib_wx_set_wap(struct rtllib_device *ieee, struct iw_request_info *info, 2030 union iwreq_data *awrq, char *extra); 2031 2032 int rtllib_wx_get_essid(struct rtllib_device *ieee, struct iw_request_info *a, 2033 union iwreq_data *wrqu, char *b); 2034 2035 int rtllib_wx_set_rate(struct rtllib_device *ieee, struct iw_request_info *info, 2036 union iwreq_data *wrqu, char *extra); 2037 2038 int rtllib_wx_get_rate(struct rtllib_device *ieee, struct iw_request_info *info, 2039 union iwreq_data *wrqu, char *extra); 2040 2041 int rtllib_wx_set_mode(struct rtllib_device *ieee, struct iw_request_info *a, 2042 union iwreq_data *wrqu, char *b); 2043 2044 int rtllib_wx_set_scan(struct rtllib_device *ieee, struct iw_request_info *a, 2045 union iwreq_data *wrqu, char *b); 2046 2047 int rtllib_wx_set_essid(struct rtllib_device *ieee, struct iw_request_info *a, 2048 union iwreq_data *wrqu, char *extra); 2049 2050 int rtllib_wx_get_mode(struct rtllib_device *ieee, struct iw_request_info *a, 2051 union iwreq_data *wrqu, char *b); 2052 2053 int rtllib_wx_set_freq(struct rtllib_device *ieee, struct iw_request_info *a, 2054 union iwreq_data *wrqu, char *b); 2055 2056 int rtllib_wx_get_freq(struct rtllib_device *ieee, struct iw_request_info *a, 2057 union iwreq_data *wrqu, char *b); 2058 void rtllib_wx_sync_scan_wq(void *data); 2059 2060 int rtllib_wx_set_rawtx(struct rtllib_device *ieee, 2061 struct iw_request_info *info, 2062 union iwreq_data *wrqu, char *extra); 2063 2064 int rtllib_wx_get_name(struct rtllib_device *ieee, struct iw_request_info *info, 2065 union iwreq_data *wrqu, char *extra); 2066 2067 int rtllib_wx_set_power(struct rtllib_device *ieee, 2068 struct iw_request_info *info, 2069 union iwreq_data *wrqu, char *extra); 2070 2071 int rtllib_wx_get_power(struct rtllib_device *ieee, 2072 struct iw_request_info *info, 2073 union iwreq_data *wrqu, char *extra); 2074 2075 int rtllib_wx_set_rts(struct rtllib_device *ieee, struct iw_request_info *info, 2076 union iwreq_data *wrqu, char *extra); 2077 2078 int rtllib_wx_get_rts(struct rtllib_device *ieee, struct iw_request_info *info, 2079 union iwreq_data *wrqu, char *extra); 2080 #define MAX_RECEIVE_BUFFER_SIZE 9100 2081 2082 void HTSetConnectBwMode(struct rtllib_device *ieee, 2083 enum ht_channel_width Bandwidth, 2084 enum ht_extchnl_offset Offset); 2085 void HTUpdateDefaultSetting(struct rtllib_device *ieee); 2086 void HTConstructCapabilityElement(struct rtllib_device *ieee, 2087 u8 *posHTCap, u8 *len, 2088 u8 isEncrypt, bool bAssoc); 2089 void HTConstructInfoElement(struct rtllib_device *ieee, 2090 u8 *posHTInfo, u8 *len, u8 isEncrypt); 2091 void HTConstructRT2RTAggElement(struct rtllib_device *ieee, 2092 u8 *posRT2RTAgg, u8 *len); 2093 void HTOnAssocRsp(struct rtllib_device *ieee); 2094 void HTInitializeHTInfo(struct rtllib_device *ieee); 2095 void HTInitializeBssDesc(struct bss_ht *pBssHT); 2096 void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee, 2097 struct rtllib_network *pNetwork); 2098 void HT_update_self_and_peer_setting(struct rtllib_device *ieee, 2099 struct rtllib_network *pNetwork); 2100 u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet, 2101 u8 *pMCSFilter); 2102 extern u8 MCS_FILTER_ALL[]; 2103 extern u16 MCS_DATA_RATE[2][2][77]; 2104 u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame); 2105 void HTResetIOTSetting(struct rt_hi_throughput *pHTInfo); 2106 bool IsHTHalfNmodeAPs(struct rtllib_device *ieee); 2107 u16 TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate); 2108 int rtllib_rx_ADDBAReq(struct rtllib_device *ieee, struct sk_buff *skb); 2109 int rtllib_rx_ADDBARsp(struct rtllib_device *ieee, struct sk_buff *skb); 2110 int rtllib_rx_DELBA(struct rtllib_device *ieee, struct sk_buff *skb); 2111 void TsInitAddBA(struct rtllib_device *ieee, struct tx_ts_record *pTS, 2112 u8 Policy, u8 bOverwritePending); 2113 void TsInitDelBA(struct rtllib_device *ieee, 2114 struct ts_common_info *pTsCommonInfo, 2115 enum tr_select TxRxSelect); 2116 void BaSetupTimeOut(struct timer_list *t); 2117 void TxBaInactTimeout(struct timer_list *t); 2118 void RxBaInactTimeout(struct timer_list *t); 2119 void ResetBaEntry(struct ba_record *pBA); 2120 bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS, u8 *Addr, 2121 u8 TID, enum tr_select TxRxSelect, bool bAddNewTs); 2122 void TSInitialize(struct rtllib_device *ieee); 2123 void TsStartAddBaProcess(struct rtllib_device *ieee, 2124 struct tx_ts_record *pTxTS); 2125 void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr); 2126 void RemoveAllTS(struct rtllib_device *ieee); 2127 2128 extern const long rtllib_wlan_frequencies[]; 2129 2130 static inline const char *escape_essid(const char *essid, u8 essid_len) 2131 { 2132 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; 2133 2134 if (rtllib_is_empty_essid(essid, essid_len)) { 2135 memcpy(escaped, "<hidden>", sizeof("<hidden>")); 2136 return escaped; 2137 } 2138 2139 snprintf(escaped, sizeof(escaped), "%*pEn", essid_len, essid); 2140 return escaped; 2141 } 2142 2143 /* fun with the built-in rtllib stack... */ 2144 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn); 2145 2146 2147 /* For the function is more related to hardware setting, it's better to use the 2148 * ieee handler to refer to it. 2149 */ 2150 void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee, 2151 struct rx_ts_record *pTS); 2152 int rtllib_parse_info_param(struct rtllib_device *ieee, 2153 struct rtllib_info_element *info_element, 2154 u16 length, 2155 struct rtllib_network *network, 2156 struct rtllib_rx_stats *stats); 2157 2158 void rtllib_indicate_packets(struct rtllib_device *ieee, 2159 struct rtllib_rxb **prxbIndicateArray, u8 index); 2160 void HTUseDefaultSetting(struct rtllib_device *ieee); 2161 #define RT_ASOC_RETRY_LIMIT 5 2162 u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee); 2163 2164 #endif /* RTLLIB_H */ 2165