hostap_wlan.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  1. #ifndef HOSTAP_WLAN_H
  2. #define HOSTAP_WLAN_H
  3. #include <linux/wireless.h>
  4. #include <linux/netdevice.h>
  5. #include <net/iw_handler.h>
  6. #include "hostap_config.h"
  7. #include "hostap_common.h"
  8. #define MAX_PARM_DEVICES 8
  9. #define PARM_MIN_MAX "1-" __MODULE_STRING(MAX_PARM_DEVICES)
  10. #define DEF_INTS -1, -1, -1, -1, -1, -1, -1
  11. #define GET_INT_PARM(var,idx) var[var[idx] < 0 ? 0 : idx]
  12. /* Specific skb->protocol value that indicates that the packet already contains
  13. * txdesc header.
  14. * FIX: This might need own value that would be allocated especially for Prism2
  15. * txdesc; ETH_P_CONTROL is commented as "Card specific control frames".
  16. * However, these skb's should have only minimal path in the kernel side since
  17. * prism2_send_mgmt() sends these with dev_queue_xmit() to prism2_tx(). */
  18. #define ETH_P_HOSTAP ETH_P_CONTROL
  19. /* ARPHRD_IEEE80211_PRISM uses a bloated version of Prism2 RX frame header
  20. * (from linux-wlan-ng) */
  21. struct linux_wlan_ng_val {
  22. u32 did;
  23. u16 status, len;
  24. u32 data;
  25. } __attribute__ ((packed));
  26. struct linux_wlan_ng_prism_hdr {
  27. u32 msgcode, msglen;
  28. char devname[16];
  29. struct linux_wlan_ng_val hosttime, mactime, channel, rssi, sq, signal,
  30. noise, rate, istx, frmlen;
  31. } __attribute__ ((packed));
  32. struct linux_wlan_ng_cap_hdr {
  33. u32 version;
  34. u32 length;
  35. u64 mactime;
  36. u64 hosttime;
  37. u32 phytype;
  38. u32 channel;
  39. u32 datarate;
  40. u32 antenna;
  41. u32 priority;
  42. u32 ssi_type;
  43. s32 ssi_signal;
  44. s32 ssi_noise;
  45. u32 preamble;
  46. u32 encoding;
  47. } __attribute__ ((packed));
  48. #define LWNG_CAP_DID_BASE (4 | (1 << 6)) /* section 4, group 1 */
  49. #define LWNG_CAPHDR_VERSION 0x80211001
  50. struct hfa384x_rx_frame {
  51. /* HFA384X RX frame descriptor */
  52. u16 status; /* HFA384X_RX_STATUS_ flags */
  53. u32 time; /* timestamp, 1 microsecond resolution */
  54. u8 silence; /* 27 .. 154; seems to be 0 */
  55. u8 signal; /* 27 .. 154 */
  56. u8 rate; /* 10, 20, 55, or 110 */
  57. u8 rxflow;
  58. u32 reserved;
  59. /* 802.11 */
  60. u16 frame_control;
  61. u16 duration_id;
  62. u8 addr1[6];
  63. u8 addr2[6];
  64. u8 addr3[6];
  65. u16 seq_ctrl;
  66. u8 addr4[6];
  67. u16 data_len;
  68. /* 802.3 */
  69. u8 dst_addr[6];
  70. u8 src_addr[6];
  71. u16 len;
  72. /* followed by frame data; max 2304 bytes */
  73. } __attribute__ ((packed));
  74. struct hfa384x_tx_frame {
  75. /* HFA384X TX frame descriptor */
  76. u16 status; /* HFA384X_TX_STATUS_ flags */
  77. u16 reserved1;
  78. u16 reserved2;
  79. u32 sw_support;
  80. u8 retry_count; /* not yet implemented */
  81. u8 tx_rate; /* Host AP only; 0 = firmware, or 10, 20, 55, 110 */
  82. u16 tx_control; /* HFA384X_TX_CTRL_ flags */
  83. /* 802.11 */
  84. u16 frame_control; /* parts not used */
  85. u16 duration_id;
  86. u8 addr1[6];
  87. u8 addr2[6]; /* filled by firmware */
  88. u8 addr3[6];
  89. u16 seq_ctrl; /* filled by firmware */
  90. u8 addr4[6];
  91. u16 data_len;
  92. /* 802.3 */
  93. u8 dst_addr[6];
  94. u8 src_addr[6];
  95. u16 len;
  96. /* followed by frame data; max 2304 bytes */
  97. } __attribute__ ((packed));
  98. struct hfa384x_rid_hdr
  99. {
  100. u16 len;
  101. u16 rid;
  102. } __attribute__ ((packed));
  103. /* Macro for converting signal levels (range 27 .. 154) to wireless ext
  104. * dBm value with some accuracy */
  105. #define HFA384X_LEVEL_TO_dBm(v) 0x100 + (v) * 100 / 255 - 100
  106. #define HFA384X_LEVEL_TO_dBm_sign(v) (v) * 100 / 255 - 100
  107. struct hfa384x_scan_request {
  108. u16 channel_list;
  109. u16 txrate; /* HFA384X_RATES_* */
  110. } __attribute__ ((packed));
  111. struct hfa384x_hostscan_request {
  112. u16 channel_list;
  113. u16 txrate;
  114. u16 target_ssid_len;
  115. u8 target_ssid[32];
  116. } __attribute__ ((packed));
  117. struct hfa384x_join_request {
  118. u8 bssid[6];
  119. u16 channel;
  120. } __attribute__ ((packed));
  121. struct hfa384x_info_frame {
  122. u16 len;
  123. u16 type;
  124. } __attribute__ ((packed));
  125. struct hfa384x_comm_tallies {
  126. u16 tx_unicast_frames;
  127. u16 tx_multicast_frames;
  128. u16 tx_fragments;
  129. u16 tx_unicast_octets;
  130. u16 tx_multicast_octets;
  131. u16 tx_deferred_transmissions;
  132. u16 tx_single_retry_frames;
  133. u16 tx_multiple_retry_frames;
  134. u16 tx_retry_limit_exceeded;
  135. u16 tx_discards;
  136. u16 rx_unicast_frames;
  137. u16 rx_multicast_frames;
  138. u16 rx_fragments;
  139. u16 rx_unicast_octets;
  140. u16 rx_multicast_octets;
  141. u16 rx_fcs_errors;
  142. u16 rx_discards_no_buffer;
  143. u16 tx_discards_wrong_sa;
  144. u16 rx_discards_wep_undecryptable;
  145. u16 rx_message_in_msg_fragments;
  146. u16 rx_message_in_bad_msg_fragments;
  147. } __attribute__ ((packed));
  148. struct hfa384x_comm_tallies32 {
  149. u32 tx_unicast_frames;
  150. u32 tx_multicast_frames;
  151. u32 tx_fragments;
  152. u32 tx_unicast_octets;
  153. u32 tx_multicast_octets;
  154. u32 tx_deferred_transmissions;
  155. u32 tx_single_retry_frames;
  156. u32 tx_multiple_retry_frames;
  157. u32 tx_retry_limit_exceeded;
  158. u32 tx_discards;
  159. u32 rx_unicast_frames;
  160. u32 rx_multicast_frames;
  161. u32 rx_fragments;
  162. u32 rx_unicast_octets;
  163. u32 rx_multicast_octets;
  164. u32 rx_fcs_errors;
  165. u32 rx_discards_no_buffer;
  166. u32 tx_discards_wrong_sa;
  167. u32 rx_discards_wep_undecryptable;
  168. u32 rx_message_in_msg_fragments;
  169. u32 rx_message_in_bad_msg_fragments;
  170. } __attribute__ ((packed));
  171. struct hfa384x_scan_result_hdr {
  172. u16 reserved;
  173. u16 scan_reason;
  174. #define HFA384X_SCAN_IN_PROGRESS 0 /* no results available yet */
  175. #define HFA384X_SCAN_HOST_INITIATED 1
  176. #define HFA384X_SCAN_FIRMWARE_INITIATED 2
  177. #define HFA384X_SCAN_INQUIRY_FROM_HOST 3
  178. } __attribute__ ((packed));
  179. #define HFA384X_SCAN_MAX_RESULTS 32
  180. struct hfa384x_scan_result {
  181. u16 chid;
  182. u16 anl;
  183. u16 sl;
  184. u8 bssid[6];
  185. u16 beacon_interval;
  186. u16 capability;
  187. u16 ssid_len;
  188. u8 ssid[32];
  189. u8 sup_rates[10];
  190. u16 rate;
  191. } __attribute__ ((packed));
  192. struct hfa384x_hostscan_result {
  193. u16 chid;
  194. u16 anl;
  195. u16 sl;
  196. u8 bssid[6];
  197. u16 beacon_interval;
  198. u16 capability;
  199. u16 ssid_len;
  200. u8 ssid[32];
  201. u8 sup_rates[10];
  202. u16 rate;
  203. u16 atim;
  204. } __attribute__ ((packed));
  205. struct comm_tallies_sums {
  206. unsigned int tx_unicast_frames;
  207. unsigned int tx_multicast_frames;
  208. unsigned int tx_fragments;
  209. unsigned int tx_unicast_octets;
  210. unsigned int tx_multicast_octets;
  211. unsigned int tx_deferred_transmissions;
  212. unsigned int tx_single_retry_frames;
  213. unsigned int tx_multiple_retry_frames;
  214. unsigned int tx_retry_limit_exceeded;
  215. unsigned int tx_discards;
  216. unsigned int rx_unicast_frames;
  217. unsigned int rx_multicast_frames;
  218. unsigned int rx_fragments;
  219. unsigned int rx_unicast_octets;
  220. unsigned int rx_multicast_octets;
  221. unsigned int rx_fcs_errors;
  222. unsigned int rx_discards_no_buffer;
  223. unsigned int tx_discards_wrong_sa;
  224. unsigned int rx_discards_wep_undecryptable;
  225. unsigned int rx_message_in_msg_fragments;
  226. unsigned int rx_message_in_bad_msg_fragments;
  227. };
  228. struct hfa384x_regs {
  229. u16 cmd;
  230. u16 evstat;
  231. u16 offset0;
  232. u16 offset1;
  233. u16 swsupport0;
  234. };
  235. #if defined(PRISM2_PCCARD) || defined(PRISM2_PLX)
  236. /* I/O ports for HFA384X Controller access */
  237. #define HFA384X_CMD_OFF 0x00
  238. #define HFA384X_PARAM0_OFF 0x02
  239. #define HFA384X_PARAM1_OFF 0x04
  240. #define HFA384X_PARAM2_OFF 0x06
  241. #define HFA384X_STATUS_OFF 0x08
  242. #define HFA384X_RESP0_OFF 0x0A
  243. #define HFA384X_RESP1_OFF 0x0C
  244. #define HFA384X_RESP2_OFF 0x0E
  245. #define HFA384X_INFOFID_OFF 0x10
  246. #define HFA384X_CONTROL_OFF 0x14
  247. #define HFA384X_SELECT0_OFF 0x18
  248. #define HFA384X_SELECT1_OFF 0x1A
  249. #define HFA384X_OFFSET0_OFF 0x1C
  250. #define HFA384X_OFFSET1_OFF 0x1E
  251. #define HFA384X_RXFID_OFF 0x20
  252. #define HFA384X_ALLOCFID_OFF 0x22
  253. #define HFA384X_TXCOMPLFID_OFF 0x24
  254. #define HFA384X_SWSUPPORT0_OFF 0x28
  255. #define HFA384X_SWSUPPORT1_OFF 0x2A
  256. #define HFA384X_SWSUPPORT2_OFF 0x2C
  257. #define HFA384X_EVSTAT_OFF 0x30
  258. #define HFA384X_INTEN_OFF 0x32
  259. #define HFA384X_EVACK_OFF 0x34
  260. #define HFA384X_DATA0_OFF 0x36
  261. #define HFA384X_DATA1_OFF 0x38
  262. #define HFA384X_AUXPAGE_OFF 0x3A
  263. #define HFA384X_AUXOFFSET_OFF 0x3C
  264. #define HFA384X_AUXDATA_OFF 0x3E
  265. #endif /* PRISM2_PCCARD || PRISM2_PLX */
  266. #ifdef PRISM2_PCI
  267. /* Memory addresses for ISL3874 controller access */
  268. #define HFA384X_CMD_OFF 0x00
  269. #define HFA384X_PARAM0_OFF 0x04
  270. #define HFA384X_PARAM1_OFF 0x08
  271. #define HFA384X_PARAM2_OFF 0x0C
  272. #define HFA384X_STATUS_OFF 0x10
  273. #define HFA384X_RESP0_OFF 0x14
  274. #define HFA384X_RESP1_OFF 0x18
  275. #define HFA384X_RESP2_OFF 0x1C
  276. #define HFA384X_INFOFID_OFF 0x20
  277. #define HFA384X_CONTROL_OFF 0x28
  278. #define HFA384X_SELECT0_OFF 0x30
  279. #define HFA384X_SELECT1_OFF 0x34
  280. #define HFA384X_OFFSET0_OFF 0x38
  281. #define HFA384X_OFFSET1_OFF 0x3C
  282. #define HFA384X_RXFID_OFF 0x40
  283. #define HFA384X_ALLOCFID_OFF 0x44
  284. #define HFA384X_TXCOMPLFID_OFF 0x48
  285. #define HFA384X_PCICOR_OFF 0x4C
  286. #define HFA384X_SWSUPPORT0_OFF 0x50
  287. #define HFA384X_SWSUPPORT1_OFF 0x54
  288. #define HFA384X_SWSUPPORT2_OFF 0x58
  289. #define HFA384X_PCIHCR_OFF 0x5C
  290. #define HFA384X_EVSTAT_OFF 0x60
  291. #define HFA384X_INTEN_OFF 0x64
  292. #define HFA384X_EVACK_OFF 0x68
  293. #define HFA384X_DATA0_OFF 0x6C
  294. #define HFA384X_DATA1_OFF 0x70
  295. #define HFA384X_AUXPAGE_OFF 0x74
  296. #define HFA384X_AUXOFFSET_OFF 0x78
  297. #define HFA384X_AUXDATA_OFF 0x7C
  298. #define HFA384X_PCI_M0_ADDRH_OFF 0x80
  299. #define HFA384X_PCI_M0_ADDRL_OFF 0x84
  300. #define HFA384X_PCI_M0_LEN_OFF 0x88
  301. #define HFA384X_PCI_M0_CTL_OFF 0x8C
  302. #define HFA384X_PCI_STATUS_OFF 0x98
  303. #define HFA384X_PCI_M1_ADDRH_OFF 0xA0
  304. #define HFA384X_PCI_M1_ADDRL_OFF 0xA4
  305. #define HFA384X_PCI_M1_LEN_OFF 0xA8
  306. #define HFA384X_PCI_M1_CTL_OFF 0xAC
  307. /* PCI bus master control bits (these are undocumented; based on guessing and
  308. * experimenting..) */
  309. #define HFA384X_PCI_CTL_FROM_BAP (BIT(5) | BIT(1) | BIT(0))
  310. #define HFA384X_PCI_CTL_TO_BAP (BIT(5) | BIT(0))
  311. #endif /* PRISM2_PCI */
  312. /* Command codes for CMD reg. */
  313. #define HFA384X_CMDCODE_INIT 0x00
  314. #define HFA384X_CMDCODE_ENABLE 0x01
  315. #define HFA384X_CMDCODE_DISABLE 0x02
  316. #define HFA384X_CMDCODE_ALLOC 0x0A
  317. #define HFA384X_CMDCODE_TRANSMIT 0x0B
  318. #define HFA384X_CMDCODE_INQUIRE 0x11
  319. #define HFA384X_CMDCODE_ACCESS 0x21
  320. #define HFA384X_CMDCODE_ACCESS_WRITE (0x21 | BIT(8))
  321. #define HFA384X_CMDCODE_DOWNLOAD 0x22
  322. #define HFA384X_CMDCODE_READMIF 0x30
  323. #define HFA384X_CMDCODE_WRITEMIF 0x31
  324. #define HFA384X_CMDCODE_TEST 0x38
  325. #define HFA384X_CMDCODE_MASK 0x3F
  326. /* Test mode operations */
  327. #define HFA384X_TEST_CHANGE_CHANNEL 0x08
  328. #define HFA384X_TEST_MONITOR 0x0B
  329. #define HFA384X_TEST_STOP 0x0F
  330. #define HFA384X_TEST_CFG_BITS 0x15
  331. #define HFA384X_TEST_CFG_BIT_ALC BIT(3)
  332. #define HFA384X_CMD_BUSY BIT(15)
  333. #define HFA384X_CMD_TX_RECLAIM BIT(8)
  334. #define HFA384X_OFFSET_ERR BIT(14)
  335. #define HFA384X_OFFSET_BUSY BIT(15)
  336. /* ProgMode for download command */
  337. #define HFA384X_PROGMODE_DISABLE 0
  338. #define HFA384X_PROGMODE_ENABLE_VOLATILE 1
  339. #define HFA384X_PROGMODE_ENABLE_NON_VOLATILE 2
  340. #define HFA384X_PROGMODE_PROGRAM_NON_VOLATILE 3
  341. #define HFA384X_AUX_MAGIC0 0xfe01
  342. #define HFA384X_AUX_MAGIC1 0xdc23
  343. #define HFA384X_AUX_MAGIC2 0xba45
  344. #define HFA384X_AUX_PORT_DISABLED 0
  345. #define HFA384X_AUX_PORT_DISABLE BIT(14)
  346. #define HFA384X_AUX_PORT_ENABLE BIT(15)
  347. #define HFA384X_AUX_PORT_ENABLED (BIT(14) | BIT(15))
  348. #define HFA384X_AUX_PORT_MASK (BIT(14) | BIT(15))
  349. #define PRISM2_PDA_SIZE 1024
  350. /* Events; EvStat, Interrupt mask (IntEn), and acknowledge bits (EvAck) */
  351. #define HFA384X_EV_TICK BIT(15)
  352. #define HFA384X_EV_WTERR BIT(14)
  353. #define HFA384X_EV_INFDROP BIT(13)
  354. #ifdef PRISM2_PCI
  355. #define HFA384X_EV_PCI_M1 BIT(9)
  356. #define HFA384X_EV_PCI_M0 BIT(8)
  357. #endif /* PRISM2_PCI */
  358. #define HFA384X_EV_INFO BIT(7)
  359. #define HFA384X_EV_DTIM BIT(5)
  360. #define HFA384X_EV_CMD BIT(4)
  361. #define HFA384X_EV_ALLOC BIT(3)
  362. #define HFA384X_EV_TXEXC BIT(2)
  363. #define HFA384X_EV_TX BIT(1)
  364. #define HFA384X_EV_RX BIT(0)
  365. /* HFA384X Information frames */
  366. #define HFA384X_INFO_HANDOVERADDR 0xF000 /* AP f/w ? */
  367. #define HFA384X_INFO_HANDOVERDEAUTHADDR 0xF001 /* AP f/w 1.3.7 */
  368. #define HFA384X_INFO_COMMTALLIES 0xF100
  369. #define HFA384X_INFO_SCANRESULTS 0xF101
  370. #define HFA384X_INFO_CHANNELINFORESULTS 0xF102 /* AP f/w only */
  371. #define HFA384X_INFO_HOSTSCANRESULTS 0xF103
  372. #define HFA384X_INFO_LINKSTATUS 0xF200
  373. #define HFA384X_INFO_ASSOCSTATUS 0xF201 /* ? */
  374. #define HFA384X_INFO_AUTHREQ 0xF202 /* ? */
  375. #define HFA384X_INFO_PSUSERCNT 0xF203 /* ? */
  376. #define HFA384X_INFO_KEYIDCHANGED 0xF204 /* ? */
  377. enum { HFA384X_LINKSTATUS_CONNECTED = 1,
  378. HFA384X_LINKSTATUS_DISCONNECTED = 2,
  379. HFA384X_LINKSTATUS_AP_CHANGE = 3,
  380. HFA384X_LINKSTATUS_AP_OUT_OF_RANGE = 4,
  381. HFA384X_LINKSTATUS_AP_IN_RANGE = 5,
  382. HFA384X_LINKSTATUS_ASSOC_FAILED = 6 };
  383. enum { HFA384X_PORTTYPE_BSS = 1, HFA384X_PORTTYPE_WDS = 2,
  384. HFA384X_PORTTYPE_PSEUDO_IBSS = 3, HFA384X_PORTTYPE_IBSS = 0,
  385. HFA384X_PORTTYPE_HOSTAP = 6 };
  386. #define HFA384X_RATES_1MBPS BIT(0)
  387. #define HFA384X_RATES_2MBPS BIT(1)
  388. #define HFA384X_RATES_5MBPS BIT(2)
  389. #define HFA384X_RATES_11MBPS BIT(3)
  390. #define HFA384X_ROAMING_FIRMWARE 1
  391. #define HFA384X_ROAMING_HOST 2
  392. #define HFA384X_ROAMING_DISABLED 3
  393. #define HFA384X_WEPFLAGS_PRIVACYINVOKED BIT(0)
  394. #define HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED BIT(1)
  395. #define HFA384X_WEPFLAGS_HOSTENCRYPT BIT(4)
  396. #define HFA384X_WEPFLAGS_HOSTDECRYPT BIT(7)
  397. #define HFA384X_RX_STATUS_MSGTYPE (BIT(15) | BIT(14) | BIT(13))
  398. #define HFA384X_RX_STATUS_PCF BIT(12)
  399. #define HFA384X_RX_STATUS_MACPORT (BIT(10) | BIT(9) | BIT(8))
  400. #define HFA384X_RX_STATUS_UNDECR BIT(1)
  401. #define HFA384X_RX_STATUS_FCSERR BIT(0)
  402. #define HFA384X_RX_STATUS_GET_MSGTYPE(s) \
  403. (((s) & HFA384X_RX_STATUS_MSGTYPE) >> 13)
  404. #define HFA384X_RX_STATUS_GET_MACPORT(s) \
  405. (((s) & HFA384X_RX_STATUS_MACPORT) >> 8)
  406. enum { HFA384X_RX_MSGTYPE_NORMAL = 0, HFA384X_RX_MSGTYPE_RFC1042 = 1,
  407. HFA384X_RX_MSGTYPE_BRIDGETUNNEL = 2, HFA384X_RX_MSGTYPE_MGMT = 4 };
  408. #define HFA384X_TX_CTRL_ALT_RTRY BIT(5)
  409. #define HFA384X_TX_CTRL_802_11 BIT(3)
  410. #define HFA384X_TX_CTRL_802_3 0
  411. #define HFA384X_TX_CTRL_TX_EX BIT(2)
  412. #define HFA384X_TX_CTRL_TX_OK BIT(1)
  413. #define HFA384X_TX_STATUS_RETRYERR BIT(0)
  414. #define HFA384X_TX_STATUS_AGEDERR BIT(1)
  415. #define HFA384X_TX_STATUS_DISCON BIT(2)
  416. #define HFA384X_TX_STATUS_FORMERR BIT(3)
  417. /* HFA3861/3863 (BBP) Control Registers */
  418. #define HFA386X_CR_TX_CONFIGURE 0x12 /* CR9 */
  419. #define HFA386X_CR_RX_CONFIGURE 0x14 /* CR10 */
  420. #define HFA386X_CR_A_D_TEST_MODES2 0x1A /* CR13 */
  421. #define HFA386X_CR_MANUAL_TX_POWER 0x3E /* CR31 */
  422. #define HFA386X_CR_MEASURED_TX_POWER 0x74 /* CR58 */
  423. #ifdef __KERNEL__
  424. #define PRISM2_TXFID_COUNT 8
  425. #define PRISM2_DATA_MAXLEN 2304
  426. #define PRISM2_TXFID_LEN (PRISM2_DATA_MAXLEN + sizeof(struct hfa384x_tx_frame))
  427. #define PRISM2_TXFID_EMPTY 0xffff
  428. #define PRISM2_TXFID_RESERVED 0xfffe
  429. #define PRISM2_DUMMY_FID 0xffff
  430. #define MAX_SSID_LEN 32
  431. #define MAX_NAME_LEN 32 /* this is assumed to be equal to MAX_SSID_LEN */
  432. #define PRISM2_DUMP_RX_HDR BIT(0)
  433. #define PRISM2_DUMP_TX_HDR BIT(1)
  434. #define PRISM2_DUMP_TXEXC_HDR BIT(2)
  435. struct hostap_tx_callback_info {
  436. u16 idx;
  437. void (*func)(struct sk_buff *, int ok, void *);
  438. void *data;
  439. struct hostap_tx_callback_info *next;
  440. };
  441. /* IEEE 802.11 requires that STA supports concurrent reception of at least
  442. * three fragmented frames. This define can be increased to support more
  443. * concurrent frames, but it should be noted that each entry can consume about
  444. * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
  445. #define PRISM2_FRAG_CACHE_LEN 4
  446. struct prism2_frag_entry {
  447. unsigned long first_frag_time;
  448. unsigned int seq;
  449. unsigned int last_frag;
  450. struct sk_buff *skb;
  451. u8 src_addr[ETH_ALEN];
  452. u8 dst_addr[ETH_ALEN];
  453. };
  454. struct hostap_cmd_queue {
  455. struct list_head list;
  456. wait_queue_head_t compl;
  457. volatile enum { CMD_SLEEP, CMD_CALLBACK, CMD_COMPLETED } type;
  458. void (*callback)(struct net_device *dev, long context, u16 resp0,
  459. u16 res);
  460. long context;
  461. u16 cmd, param0, param1;
  462. u16 resp0, res;
  463. volatile int issued, issuing;
  464. atomic_t usecnt;
  465. int del_req;
  466. };
  467. /* options for hw_shutdown */
  468. #define HOSTAP_HW_NO_DISABLE BIT(0)
  469. #define HOSTAP_HW_ENABLE_CMDCOMPL BIT(1)
  470. typedef struct local_info local_info_t;
  471. struct prism2_helper_functions {
  472. /* these functions are defined in hardware model specific files
  473. * (hostap_{cs,plx,pci}.c */
  474. int (*card_present)(local_info_t *local);
  475. void (*cor_sreset)(local_info_t *local);
  476. void (*genesis_reset)(local_info_t *local, int hcr);
  477. /* the following functions are from hostap_hw.c, but they may have some
  478. * hardware model specific code */
  479. /* FIX: low-level commands like cmd might disappear at some point to
  480. * make it easier to change them if needed (e.g., cmd would be replaced
  481. * with write_mif/read_mif/testcmd/inquire); at least get_rid and
  482. * set_rid might move to hostap_{cs,plx,pci}.c */
  483. int (*cmd)(struct net_device *dev, u16 cmd, u16 param0, u16 *param1,
  484. u16 *resp0);
  485. void (*read_regs)(struct net_device *dev, struct hfa384x_regs *regs);
  486. int (*get_rid)(struct net_device *dev, u16 rid, void *buf, int len,
  487. int exact_len);
  488. int (*set_rid)(struct net_device *dev, u16 rid, void *buf, int len);
  489. int (*hw_enable)(struct net_device *dev, int initial);
  490. int (*hw_config)(struct net_device *dev, int initial);
  491. void (*hw_reset)(struct net_device *dev);
  492. void (*hw_shutdown)(struct net_device *dev, int no_disable);
  493. int (*reset_port)(struct net_device *dev);
  494. void (*schedule_reset)(local_info_t *local);
  495. int (*download)(local_info_t *local,
  496. struct prism2_download_param *param);
  497. int (*tx)(struct sk_buff *skb, struct net_device *dev);
  498. int (*set_tim)(struct net_device *dev, int aid, int set);
  499. int (*read_aux)(struct net_device *dev, unsigned addr, int len,
  500. u8 *buf);
  501. int need_tx_headroom; /* number of bytes of headroom needed before
  502. * IEEE 802.11 header */
  503. enum { HOSTAP_HW_PCCARD, HOSTAP_HW_PLX, HOSTAP_HW_PCI } hw_type;
  504. };
  505. struct prism2_download_data {
  506. u32 dl_cmd;
  507. u32 start_addr;
  508. u32 num_areas;
  509. struct prism2_download_data_area {
  510. u32 addr; /* wlan card address */
  511. u32 len;
  512. u8 *data; /* allocated data */
  513. } data[0];
  514. };
  515. #define HOSTAP_MAX_BSS_COUNT 64
  516. #define MAX_WPA_IE_LEN 64
  517. struct hostap_bss_info {
  518. struct list_head list;
  519. unsigned long last_update;
  520. unsigned int count;
  521. u8 bssid[ETH_ALEN];
  522. u16 capab_info;
  523. u8 ssid[32];
  524. size_t ssid_len;
  525. u8 wpa_ie[MAX_WPA_IE_LEN];
  526. size_t wpa_ie_len;
  527. u8 rsn_ie[MAX_WPA_IE_LEN];
  528. size_t rsn_ie_len;
  529. int chan;
  530. int included;
  531. };
  532. /* Per radio private Host AP data - shared by all net devices interfaces used
  533. * by each radio (wlan#, wlan#ap, wlan#sta, WDS).
  534. * ((struct hostap_interface *) netdev_priv(dev))->local points to this
  535. * structure. */
  536. struct local_info {
  537. struct module *hw_module;
  538. int card_idx;
  539. int dev_enabled;
  540. int master_dev_auto_open; /* was master device opened automatically */
  541. int num_dev_open; /* number of open devices */
  542. struct net_device *dev; /* master radio device */
  543. struct net_device *ddev; /* main data device */
  544. struct list_head hostap_interfaces; /* Host AP interface list (contains
  545. * struct hostap_interface entries)
  546. */
  547. rwlock_t iface_lock; /* hostap_interfaces read lock; use write lock
  548. * when removing entries from the list.
  549. * TX and RX paths can use read lock. */
  550. spinlock_t cmdlock, baplock, lock;
  551. struct semaphore rid_bap_sem;
  552. u16 infofid; /* MAC buffer id for info frame */
  553. /* txfid, intransmitfid, next_txtid, and next_alloc are protected by
  554. * txfidlock */
  555. spinlock_t txfidlock;
  556. int txfid_len; /* length of allocated TX buffers */
  557. u16 txfid[PRISM2_TXFID_COUNT]; /* buffer IDs for TX frames */
  558. /* buffer IDs for intransmit frames or PRISM2_TXFID_EMPTY if
  559. * corresponding txfid is free for next TX frame */
  560. u16 intransmitfid[PRISM2_TXFID_COUNT];
  561. int next_txfid; /* index to the next txfid to be checked for
  562. * availability */
  563. int next_alloc; /* index to the next intransmitfid to be checked for
  564. * allocation events */
  565. /* bitfield for atomic bitops */
  566. #define HOSTAP_BITS_TRANSMIT 0
  567. #define HOSTAP_BITS_BAP_TASKLET 1
  568. #define HOSTAP_BITS_BAP_TASKLET2 2
  569. long bits;
  570. struct ap_data *ap;
  571. char essid[MAX_SSID_LEN + 1];
  572. char name[MAX_NAME_LEN + 1];
  573. int name_set;
  574. u16 channel_mask; /* mask of allowed channels */
  575. u16 scan_channel_mask; /* mask of channels to be scanned */
  576. struct comm_tallies_sums comm_tallies;
  577. struct net_device_stats stats;
  578. struct proc_dir_entry *proc;
  579. int iw_mode; /* operating mode (IW_MODE_*) */
  580. int pseudo_adhoc; /* 0: IW_MODE_ADHOC is real 802.11 compliant IBSS
  581. * 1: IW_MODE_ADHOC is "pseudo IBSS" */
  582. char bssid[ETH_ALEN];
  583. int channel;
  584. int beacon_int;
  585. int dtim_period;
  586. int mtu;
  587. int frame_dump; /* dump RX/TX frame headers, PRISM2_DUMP_ flags */
  588. int fw_tx_rate_control;
  589. u16 tx_rate_control;
  590. u16 basic_rates;
  591. int hw_resetting;
  592. int hw_ready;
  593. int hw_reset_tries; /* how many times reset has been tried */
  594. int hw_downloading;
  595. int shutdown;
  596. int pri_only;
  597. int no_pri; /* no PRI f/w present */
  598. int sram_type; /* 8 = x8 SRAM, 16 = x16 SRAM, -1 = unknown */
  599. enum {
  600. PRISM2_TXPOWER_AUTO = 0, PRISM2_TXPOWER_OFF,
  601. PRISM2_TXPOWER_FIXED, PRISM2_TXPOWER_UNKNOWN
  602. } txpower_type;
  603. int txpower; /* if txpower_type == PRISM2_TXPOWER_FIXED */
  604. /* command queue for hfa384x_cmd(); protected with cmdlock */
  605. struct list_head cmd_queue;
  606. /* max_len for cmd_queue; in addition, cmd_callback can use two
  607. * additional entries to prevent sleeping commands from stopping
  608. * transmits */
  609. #define HOSTAP_CMD_QUEUE_MAX_LEN 16
  610. int cmd_queue_len; /* number of entries in cmd_queue */
  611. /* if card timeout is detected in interrupt context, reset_queue is
  612. * used to schedule card reseting to be done in user context */
  613. struct work_struct reset_queue;
  614. /* For scheduling a change of the promiscuous mode RID */
  615. int is_promisc;
  616. struct work_struct set_multicast_list_queue;
  617. struct work_struct set_tim_queue;
  618. struct list_head set_tim_list;
  619. spinlock_t set_tim_lock;
  620. int wds_max_connections;
  621. int wds_connections;
  622. #define HOSTAP_WDS_BROADCAST_RA BIT(0)
  623. #define HOSTAP_WDS_AP_CLIENT BIT(1)
  624. #define HOSTAP_WDS_STANDARD_FRAME BIT(2)
  625. u32 wds_type;
  626. u16 tx_control; /* flags to be used in TX description */
  627. int manual_retry_count; /* -1 = use f/w default; otherwise retry count
  628. * to be used with all frames */
  629. struct iw_statistics wstats;
  630. unsigned long scan_timestamp; /* Time started to scan */
  631. enum {
  632. PRISM2_MONITOR_80211 = 0, PRISM2_MONITOR_PRISM = 1,
  633. PRISM2_MONITOR_CAPHDR = 2
  634. } monitor_type;
  635. int (*saved_eth_header_parse)(struct sk_buff *skb,
  636. unsigned char *haddr);
  637. int monitor_allow_fcserr;
  638. int hostapd; /* whether user space daemon, hostapd, is used for AP
  639. * management */
  640. int hostapd_sta; /* whether hostapd is used with an extra STA interface
  641. */
  642. struct net_device *apdev;
  643. struct net_device_stats apdevstats;
  644. char assoc_ap_addr[ETH_ALEN];
  645. struct net_device *stadev;
  646. struct net_device_stats stadevstats;
  647. #define WEP_KEYS 4
  648. #define WEP_KEY_LEN 13
  649. struct ieee80211_crypt_data *crypt[WEP_KEYS];
  650. int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
  651. struct timer_list crypt_deinit_timer;
  652. struct list_head crypt_deinit_list;
  653. int open_wep; /* allow unencrypted frames */
  654. int host_encrypt;
  655. int host_decrypt;
  656. int privacy_invoked; /* force privacy invoked flag even if no keys are
  657. * configured */
  658. int fw_encrypt_ok; /* whether firmware-based WEP encrypt is working
  659. * in Host AP mode (STA f/w 1.4.9 or newer) */
  660. int bcrx_sta_key; /* use individual keys to override default keys even
  661. * with RX of broad/multicast frames */
  662. struct prism2_frag_entry frag_cache[PRISM2_FRAG_CACHE_LEN];
  663. unsigned int frag_next_idx;
  664. int ieee_802_1x; /* is IEEE 802.1X used */
  665. int antsel_tx, antsel_rx;
  666. int rts_threshold; /* dot11RTSThreshold */
  667. int fragm_threshold; /* dot11FragmentationThreshold */
  668. int auth_algs; /* PRISM2_AUTH_ flags */
  669. int enh_sec; /* cnfEnhSecurity options (broadcast SSID hide/ignore) */
  670. int tallies32; /* 32-bit tallies in use */
  671. struct prism2_helper_functions *func;
  672. u8 *pda;
  673. int fw_ap;
  674. #define PRISM2_FW_VER(major, minor, variant) \
  675. (((major) << 16) | ((minor) << 8) | variant)
  676. u32 sta_fw_ver;
  677. /* Tasklets for handling hardware IRQ related operations outside hw IRQ
  678. * handler */
  679. struct tasklet_struct bap_tasklet;
  680. struct tasklet_struct info_tasklet;
  681. struct sk_buff_head info_list; /* info frames as skb's for
  682. * info_tasklet */
  683. struct hostap_tx_callback_info *tx_callback; /* registered TX callbacks
  684. */
  685. struct tasklet_struct rx_tasklet;
  686. struct sk_buff_head rx_list;
  687. struct tasklet_struct sta_tx_exc_tasklet;
  688. struct sk_buff_head sta_tx_exc_list;
  689. int host_roaming;
  690. unsigned long last_join_time; /* time of last JoinRequest */
  691. struct hfa384x_hostscan_result *last_scan_results;
  692. int last_scan_results_count;
  693. enum { PRISM2_SCAN, PRISM2_HOSTSCAN } last_scan_type;
  694. struct work_struct info_queue;
  695. long pending_info; /* bit field of pending info_queue items */
  696. #define PRISM2_INFO_PENDING_LINKSTATUS 0
  697. #define PRISM2_INFO_PENDING_SCANRESULTS 1
  698. int prev_link_status; /* previous received LinkStatus info */
  699. int prev_linkstatus_connected;
  700. u8 preferred_ap[6]; /* use this AP if possible */
  701. #ifdef PRISM2_CALLBACK
  702. void *callback_data; /* Can be used in callbacks; e.g., allocate
  703. * on enable event and free on disable event.
  704. * Host AP driver code does not touch this. */
  705. #endif /* PRISM2_CALLBACK */
  706. wait_queue_head_t hostscan_wq;
  707. /* Passive scan in Host AP mode */
  708. struct timer_list passive_scan_timer;
  709. int passive_scan_interval; /* in seconds, 0 = disabled */
  710. int passive_scan_channel;
  711. enum { PASSIVE_SCAN_WAIT, PASSIVE_SCAN_LISTEN } passive_scan_state;
  712. struct timer_list tick_timer;
  713. unsigned long last_tick_timer;
  714. unsigned int sw_tick_stuck;
  715. /* commsQuality / dBmCommsQuality data from periodic polling; only
  716. * valid for Managed and Ad-hoc modes */
  717. unsigned long last_comms_qual_update;
  718. int comms_qual; /* in some odd unit.. */
  719. int avg_signal; /* in dB (note: negative) */
  720. int avg_noise; /* in dB (note: negative) */
  721. struct work_struct comms_qual_update;
  722. /* RSSI to dBm adjustment (for RX descriptor fields) */
  723. int rssi_to_dBm; /* substract from RSSI to get approximate dBm value */
  724. /* BSS list / protected by local->lock */
  725. struct list_head bss_list;
  726. int num_bss_info;
  727. int wpa; /* WPA support enabled */
  728. int tkip_countermeasures;
  729. int drop_unencrypted;
  730. /* Generic IEEE 802.11 info element to be added to
  731. * ProbeResp/Beacon/(Re)AssocReq */
  732. u8 *generic_elem;
  733. size_t generic_elem_len;
  734. #ifdef PRISM2_DOWNLOAD_SUPPORT
  735. /* Persistent volatile download data */
  736. struct prism2_download_data *dl_pri;
  737. struct prism2_download_data *dl_sec;
  738. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  739. #ifdef PRISM2_IO_DEBUG
  740. #define PRISM2_IO_DEBUG_SIZE 10000
  741. u32 io_debug[PRISM2_IO_DEBUG_SIZE];
  742. int io_debug_head;
  743. int io_debug_enabled;
  744. #endif /* PRISM2_IO_DEBUG */
  745. /* Pointer to hardware model specific (cs,pci,plx) private data. */
  746. void *hw_priv;
  747. };
  748. /* Per interface private Host AP data
  749. * Allocated for each net device that Host AP uses (wlan#, wlan#ap, wlan#sta,
  750. * WDS) and netdev_priv(dev) points to this structure. */
  751. struct hostap_interface {
  752. struct list_head list; /* list entry in Host AP interface list */
  753. struct net_device *dev; /* pointer to this device */
  754. struct local_info *local; /* pointer to shared private data */
  755. struct net_device_stats stats;
  756. struct iw_spy_data spy_data; /* iwspy support */
  757. struct iw_public_data wireless_data;
  758. enum {
  759. HOSTAP_INTERFACE_MASTER,
  760. HOSTAP_INTERFACE_MAIN,
  761. HOSTAP_INTERFACE_AP,
  762. HOSTAP_INTERFACE_STA,
  763. HOSTAP_INTERFACE_WDS,
  764. } type;
  765. union {
  766. struct hostap_interface_wds {
  767. u8 remote_addr[ETH_ALEN];
  768. } wds;
  769. } u;
  770. };
  771. #define HOSTAP_SKB_TX_DATA_MAGIC 0xf08a36a2
  772. /*
  773. * TX meta data - stored in skb->cb buffer, so this must not be increased over
  774. * the 40-byte limit
  775. */
  776. struct hostap_skb_tx_data {
  777. u32 magic; /* HOSTAP_SKB_TX_DATA_MAGIC */
  778. u8 rate; /* transmit rate */
  779. #define HOSTAP_TX_FLAGS_WDS BIT(0)
  780. #define HOSTAP_TX_FLAGS_BUFFERED_FRAME BIT(1)
  781. #define HOSTAP_TX_FLAGS_ADD_MOREDATA BIT(2)
  782. u8 flags; /* HOSTAP_TX_FLAGS_* */
  783. u16 tx_cb_idx;
  784. struct hostap_interface *iface;
  785. unsigned long jiffies; /* queueing timestamp */
  786. unsigned short ethertype;
  787. };
  788. #ifndef PRISM2_NO_DEBUG
  789. #define DEBUG_FID BIT(0)
  790. #define DEBUG_PS BIT(1)
  791. #define DEBUG_FLOW BIT(2)
  792. #define DEBUG_AP BIT(3)
  793. #define DEBUG_HW BIT(4)
  794. #define DEBUG_EXTRA BIT(5)
  795. #define DEBUG_EXTRA2 BIT(6)
  796. #define DEBUG_PS2 BIT(7)
  797. #define DEBUG_MASK (DEBUG_PS | DEBUG_AP | DEBUG_HW | DEBUG_EXTRA)
  798. #define PDEBUG(n, args...) \
  799. do { if ((n) & DEBUG_MASK) printk(KERN_DEBUG args); } while (0)
  800. #define PDEBUG2(n, args...) \
  801. do { if ((n) & DEBUG_MASK) printk(args); } while (0)
  802. #else /* PRISM2_NO_DEBUG */
  803. #define PDEBUG(n, args...)
  804. #define PDEBUG2(n, args...)
  805. #endif /* PRISM2_NO_DEBUG */
  806. enum { BAP0 = 0, BAP1 = 1 };
  807. #define PRISM2_IO_DEBUG_CMD_INB 0
  808. #define PRISM2_IO_DEBUG_CMD_INW 1
  809. #define PRISM2_IO_DEBUG_CMD_INSW 2
  810. #define PRISM2_IO_DEBUG_CMD_OUTB 3
  811. #define PRISM2_IO_DEBUG_CMD_OUTW 4
  812. #define PRISM2_IO_DEBUG_CMD_OUTSW 5
  813. #define PRISM2_IO_DEBUG_CMD_ERROR 6
  814. #define PRISM2_IO_DEBUG_CMD_INTERRUPT 7
  815. #ifdef PRISM2_IO_DEBUG
  816. #define PRISM2_IO_DEBUG_ENTRY(cmd, reg, value) \
  817. (((cmd) << 24) | ((reg) << 16) | value)
  818. static inline void prism2_io_debug_add(struct net_device *dev, int cmd,
  819. int reg, int value)
  820. {
  821. struct hostap_interface *iface = netdev_priv(dev);
  822. local_info_t *local = iface->local;
  823. if (!local->io_debug_enabled)
  824. return;
  825. local->io_debug[local->io_debug_head] = jiffies & 0xffffffff;
  826. if (++local->io_debug_head >= PRISM2_IO_DEBUG_SIZE)
  827. local->io_debug_head = 0;
  828. local->io_debug[local->io_debug_head] =
  829. PRISM2_IO_DEBUG_ENTRY(cmd, reg, value);
  830. if (++local->io_debug_head >= PRISM2_IO_DEBUG_SIZE)
  831. local->io_debug_head = 0;
  832. }
  833. static inline void prism2_io_debug_error(struct net_device *dev, int err)
  834. {
  835. struct hostap_interface *iface = netdev_priv(dev);
  836. local_info_t *local = iface->local;
  837. unsigned long flags;
  838. if (!local->io_debug_enabled)
  839. return;
  840. spin_lock_irqsave(&local->lock, flags);
  841. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_ERROR, 0, err);
  842. if (local->io_debug_enabled == 1) {
  843. local->io_debug_enabled = 0;
  844. printk(KERN_DEBUG "%s: I/O debug stopped\n", dev->name);
  845. }
  846. spin_unlock_irqrestore(&local->lock, flags);
  847. }
  848. #else /* PRISM2_IO_DEBUG */
  849. static inline void prism2_io_debug_add(struct net_device *dev, int cmd,
  850. int reg, int value)
  851. {
  852. }
  853. static inline void prism2_io_debug_error(struct net_device *dev, int err)
  854. {
  855. }
  856. #endif /* PRISM2_IO_DEBUG */
  857. #ifdef PRISM2_CALLBACK
  858. enum {
  859. /* Called when card is enabled */
  860. PRISM2_CALLBACK_ENABLE,
  861. /* Called when card is disabled */
  862. PRISM2_CALLBACK_DISABLE,
  863. /* Called when RX/TX starts/ends */
  864. PRISM2_CALLBACK_RX_START, PRISM2_CALLBACK_RX_END,
  865. PRISM2_CALLBACK_TX_START, PRISM2_CALLBACK_TX_END
  866. };
  867. void prism2_callback(local_info_t *local, int event);
  868. #else /* PRISM2_CALLBACK */
  869. #define prism2_callback(d, e) do { } while (0)
  870. #endif /* PRISM2_CALLBACK */
  871. #endif /* __KERNEL__ */
  872. #endif /* HOSTAP_WLAN_H */