rxtx.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * File: rxtx.c
  20. *
  21. * Purpose: handle WMAC/802.3/802.11 rx & tx functions
  22. *
  23. * Author: Lyndon Chen
  24. *
  25. * Date: May 20, 2003
  26. *
  27. * Functions:
  28. * vnt_generate_tx_parameter - Generate tx dma required parameter.
  29. * vnt_get_duration_le - get tx data required duration
  30. * vnt_get_rtscts_duration_le- get rtx/cts required duration
  31. * vnt_get_rtscts_rsvtime_le- get rts/cts reserved time
  32. * vnt_get_rsvtime- get frame reserved time
  33. * vnt_fill_cts_head- fulfill CTS ctl header
  34. *
  35. * Revision History:
  36. *
  37. */
  38. #include <linux/etherdevice.h>
  39. #include "device.h"
  40. #include "rxtx.h"
  41. #include "card.h"
  42. #include "mac.h"
  43. #include "rf.h"
  44. #include "usbpipe.h"
  45. static const u16 vnt_time_stampoff[2][MAX_RATE] = {
  46. /* Long Preamble */
  47. {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23},
  48. /* Short Preamble */
  49. {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23},
  50. };
  51. static const u16 vnt_fb_opt0[2][5] = {
  52. {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, /* fallback_rate0 */
  53. {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, /* fallback_rate1 */
  54. };
  55. static const u16 vnt_fb_opt1[2][5] = {
  56. {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, /* fallback_rate0 */
  57. {RATE_6M, RATE_6M, RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */
  58. };
  59. #define RTSDUR_BB 0
  60. #define RTSDUR_BA 1
  61. #define RTSDUR_AA 2
  62. #define CTSDUR_BA 3
  63. #define RTSDUR_BA_F0 4
  64. #define RTSDUR_AA_F0 5
  65. #define RTSDUR_BA_F1 6
  66. #define RTSDUR_AA_F1 7
  67. #define CTSDUR_BA_F0 8
  68. #define CTSDUR_BA_F1 9
  69. #define DATADUR_B 10
  70. #define DATADUR_A 11
  71. #define DATADUR_A_F0 12
  72. #define DATADUR_A_F1 13
  73. static struct vnt_usb_send_context
  74. *vnt_get_free_context(struct vnt_private *priv)
  75. {
  76. struct vnt_usb_send_context *context = NULL;
  77. int ii;
  78. dev_dbg(&priv->usb->dev, "%s\n", __func__);
  79. for (ii = 0; ii < priv->num_tx_context; ii++) {
  80. if (!priv->tx_context[ii])
  81. return NULL;
  82. context = priv->tx_context[ii];
  83. if (!context->in_use) {
  84. context->in_use = true;
  85. memset(context->data, 0,
  86. MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
  87. context->hdr = NULL;
  88. return context;
  89. }
  90. }
  91. if (ii == priv->num_tx_context) {
  92. dev_dbg(&priv->usb->dev, "%s No Free Tx Context\n", __func__);
  93. ieee80211_stop_queues(priv->hw);
  94. }
  95. return NULL;
  96. }
  97. static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
  98. {
  99. return cpu_to_le16(vnt_time_stampoff[priv->preamble_type % 2]
  100. [rate % MAX_RATE]);
  101. }
  102. static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type,
  103. u32 frame_length, u16 rate, int need_ack)
  104. {
  105. u32 data_time, ack_time;
  106. data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  107. frame_length, rate);
  108. if (pkt_type == PK_TYPE_11B)
  109. ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  110. 14, (u16)priv->top_cck_basic_rate);
  111. else
  112. ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  113. 14, (u16)priv->top_ofdm_basic_rate);
  114. if (need_ack)
  115. return data_time + priv->sifs + ack_time;
  116. return data_time;
  117. }
  118. static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
  119. u32 frame_length, u16 rate, int need_ack)
  120. {
  121. return cpu_to_le16((u16)vnt_get_rsvtime(priv, pkt_type,
  122. frame_length, rate, need_ack));
  123. }
  124. static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv,
  125. u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
  126. {
  127. u32 rrv_time, rts_time, cts_time, ack_time, data_time;
  128. rrv_time = rts_time = cts_time = ack_time = data_time = 0;
  129. data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  130. frame_length, current_rate);
  131. if (rsv_type == 0) {
  132. rts_time = vnt_get_frame_time(priv->preamble_type,
  133. pkt_type, 20, priv->top_cck_basic_rate);
  134. cts_time = ack_time = vnt_get_frame_time(priv->preamble_type,
  135. pkt_type, 14, priv->top_cck_basic_rate);
  136. } else if (rsv_type == 1) {
  137. rts_time = vnt_get_frame_time(priv->preamble_type,
  138. pkt_type, 20, priv->top_cck_basic_rate);
  139. cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  140. 14, priv->top_cck_basic_rate);
  141. ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  142. 14, priv->top_ofdm_basic_rate);
  143. } else if (rsv_type == 2) {
  144. rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  145. 20, priv->top_ofdm_basic_rate);
  146. cts_time = ack_time = vnt_get_frame_time(priv->preamble_type,
  147. pkt_type, 14, priv->top_ofdm_basic_rate);
  148. } else if (rsv_type == 3) {
  149. cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  150. 14, priv->top_cck_basic_rate);
  151. ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  152. 14, priv->top_ofdm_basic_rate);
  153. rrv_time = cts_time + ack_time + data_time + 2 * priv->sifs;
  154. return cpu_to_le16((u16)rrv_time);
  155. }
  156. rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->sifs;
  157. return cpu_to_le16((u16)rrv_time);
  158. }
  159. static __le16 vnt_get_duration_le(struct vnt_private *priv,
  160. u8 pkt_type, int need_ack)
  161. {
  162. u32 ack_time = 0;
  163. if (need_ack) {
  164. if (pkt_type == PK_TYPE_11B)
  165. ack_time = vnt_get_frame_time(priv->preamble_type,
  166. pkt_type, 14, priv->top_cck_basic_rate);
  167. else
  168. ack_time = vnt_get_frame_time(priv->preamble_type,
  169. pkt_type, 14, priv->top_ofdm_basic_rate);
  170. return cpu_to_le16((u16)(priv->sifs + ack_time));
  171. }
  172. return 0;
  173. }
  174. static __le16 vnt_get_rtscts_duration_le(struct vnt_usb_send_context *context,
  175. u8 dur_type, u8 pkt_type, u16 rate)
  176. {
  177. struct vnt_private *priv = context->priv;
  178. u32 cts_time = 0, dur_time = 0;
  179. u32 frame_length = context->frame_len;
  180. u8 need_ack = context->need_ack;
  181. switch (dur_type) {
  182. case RTSDUR_BB:
  183. case RTSDUR_BA:
  184. case RTSDUR_BA_F0:
  185. case RTSDUR_BA_F1:
  186. cts_time = vnt_get_frame_time(priv->preamble_type,
  187. pkt_type, 14, priv->top_cck_basic_rate);
  188. dur_time = cts_time + 2 * priv->sifs +
  189. vnt_get_rsvtime(priv, pkt_type,
  190. frame_length, rate, need_ack);
  191. break;
  192. case RTSDUR_AA:
  193. case RTSDUR_AA_F0:
  194. case RTSDUR_AA_F1:
  195. cts_time = vnt_get_frame_time(priv->preamble_type,
  196. pkt_type, 14, priv->top_ofdm_basic_rate);
  197. dur_time = cts_time + 2 * priv->sifs +
  198. vnt_get_rsvtime(priv, pkt_type,
  199. frame_length, rate, need_ack);
  200. break;
  201. case CTSDUR_BA:
  202. case CTSDUR_BA_F0:
  203. case CTSDUR_BA_F1:
  204. dur_time = priv->sifs + vnt_get_rsvtime(priv,
  205. pkt_type, frame_length, rate, need_ack);
  206. break;
  207. default:
  208. break;
  209. }
  210. return cpu_to_le16((u16)dur_time);
  211. }
  212. static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
  213. struct ieee80211_hdr *hdr)
  214. {
  215. u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
  216. u8 *hdr_pos = (u8 *)hdr;
  217. tx_context->hdr = hdr;
  218. if (!tx_context->hdr)
  219. return 0;
  220. return (u16)(hdr_pos - head);
  221. }
  222. static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
  223. struct vnt_tx_datahead_g *buf)
  224. {
  225. struct vnt_private *priv = tx_context->priv;
  226. struct ieee80211_hdr *hdr =
  227. (struct ieee80211_hdr *)tx_context->skb->data;
  228. u32 frame_len = tx_context->frame_len;
  229. u16 rate = tx_context->tx_rate;
  230. u8 need_ack = tx_context->need_ack;
  231. /* Get SignalField,ServiceField,Length */
  232. vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a);
  233. vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate,
  234. PK_TYPE_11B, &buf->b);
  235. /* Get Duration and TimeStamp */
  236. if (ieee80211_is_pspoll(hdr->frame_control)) {
  237. __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
  238. buf->duration_a = dur;
  239. buf->duration_b = dur;
  240. } else {
  241. buf->duration_a = vnt_get_duration_le(priv,
  242. tx_context->pkt_type, need_ack);
  243. buf->duration_b = vnt_get_duration_le(priv,
  244. PK_TYPE_11B, need_ack);
  245. }
  246. buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
  247. buf->time_stamp_off_b = vnt_time_stamp_off(priv,
  248. priv->top_cck_basic_rate);
  249. tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
  250. return le16_to_cpu(buf->duration_a);
  251. }
  252. static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
  253. struct vnt_tx_datahead_g_fb *buf)
  254. {
  255. struct vnt_private *priv = tx_context->priv;
  256. u32 frame_len = tx_context->frame_len;
  257. u16 rate = tx_context->tx_rate;
  258. u8 need_ack = tx_context->need_ack;
  259. /* Get SignalField,ServiceField,Length */
  260. vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a);
  261. vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate,
  262. PK_TYPE_11B, &buf->b);
  263. /* Get Duration and TimeStamp */
  264. buf->duration_a = vnt_get_duration_le(priv, tx_context->pkt_type,
  265. need_ack);
  266. buf->duration_b = vnt_get_duration_le(priv, PK_TYPE_11B, need_ack);
  267. buf->duration_a_f0 = vnt_get_duration_le(priv, tx_context->pkt_type,
  268. need_ack);
  269. buf->duration_a_f1 = vnt_get_duration_le(priv, tx_context->pkt_type,
  270. need_ack);
  271. buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
  272. buf->time_stamp_off_b = vnt_time_stamp_off(priv,
  273. priv->top_cck_basic_rate);
  274. tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
  275. return le16_to_cpu(buf->duration_a);
  276. }
  277. static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
  278. struct vnt_tx_datahead_a_fb *buf)
  279. {
  280. struct vnt_private *priv = tx_context->priv;
  281. u16 rate = tx_context->tx_rate;
  282. u8 pkt_type = tx_context->pkt_type;
  283. u8 need_ack = tx_context->need_ack;
  284. u32 frame_len = tx_context->frame_len;
  285. /* Get SignalField,ServiceField,Length */
  286. vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
  287. /* Get Duration and TimeStampOff */
  288. buf->duration = vnt_get_duration_le(priv, pkt_type, need_ack);
  289. buf->duration_f0 = vnt_get_duration_le(priv, pkt_type, need_ack);
  290. buf->duration_f1 = vnt_get_duration_le(priv, pkt_type, need_ack);
  291. buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
  292. tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
  293. return le16_to_cpu(buf->duration);
  294. }
  295. static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
  296. struct vnt_tx_datahead_ab *buf)
  297. {
  298. struct vnt_private *priv = tx_context->priv;
  299. struct ieee80211_hdr *hdr =
  300. (struct ieee80211_hdr *)tx_context->skb->data;
  301. u32 frame_len = tx_context->frame_len;
  302. u16 rate = tx_context->tx_rate;
  303. u8 need_ack = tx_context->need_ack;
  304. /* Get SignalField,ServiceField,Length */
  305. vnt_get_phy_field(priv, frame_len, rate,
  306. tx_context->pkt_type, &buf->ab);
  307. /* Get Duration and TimeStampOff */
  308. if (ieee80211_is_pspoll(hdr->frame_control)) {
  309. __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
  310. buf->duration = dur;
  311. } else {
  312. buf->duration = vnt_get_duration_le(priv, tx_context->pkt_type,
  313. need_ack);
  314. }
  315. buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
  316. tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
  317. return le16_to_cpu(buf->duration);
  318. }
  319. static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
  320. struct ieee80211_rts *rts, __le16 duration)
  321. {
  322. struct ieee80211_hdr *hdr =
  323. (struct ieee80211_hdr *)tx_context->skb->data;
  324. rts->duration = duration;
  325. rts->frame_control =
  326. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
  327. ether_addr_copy(rts->ra, hdr->addr1);
  328. ether_addr_copy(rts->ta, hdr->addr2);
  329. return 0;
  330. }
  331. static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
  332. struct vnt_rts_g *buf)
  333. {
  334. struct vnt_private *priv = tx_context->priv;
  335. u16 rts_frame_len = 20;
  336. u16 current_rate = tx_context->tx_rate;
  337. vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate,
  338. PK_TYPE_11B, &buf->b);
  339. vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
  340. tx_context->pkt_type, &buf->a);
  341. buf->duration_bb = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BB,
  342. PK_TYPE_11B,
  343. priv->top_cck_basic_rate);
  344. buf->duration_aa = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
  345. tx_context->pkt_type,
  346. current_rate);
  347. buf->duration_ba = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA,
  348. tx_context->pkt_type,
  349. current_rate);
  350. vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
  351. return vnt_rxtx_datahead_g(tx_context, &buf->data_head);
  352. }
  353. static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
  354. struct vnt_rts_g_fb *buf)
  355. {
  356. struct vnt_private *priv = tx_context->priv;
  357. u16 current_rate = tx_context->tx_rate;
  358. u16 rts_frame_len = 20;
  359. vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate,
  360. PK_TYPE_11B, &buf->b);
  361. vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
  362. tx_context->pkt_type, &buf->a);
  363. buf->duration_bb = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BB,
  364. PK_TYPE_11B,
  365. priv->top_cck_basic_rate);
  366. buf->duration_aa = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
  367. tx_context->pkt_type,
  368. current_rate);
  369. buf->duration_ba = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA,
  370. tx_context->pkt_type,
  371. current_rate);
  372. buf->rts_duration_ba_f0 =
  373. vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA_F0,
  374. tx_context->pkt_type,
  375. priv->tx_rate_fb0);
  376. buf->rts_duration_aa_f0 =
  377. vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F0,
  378. tx_context->pkt_type,
  379. priv->tx_rate_fb0);
  380. buf->rts_duration_ba_f1 =
  381. vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA_F1,
  382. tx_context->pkt_type,
  383. priv->tx_rate_fb1);
  384. buf->rts_duration_aa_f1 =
  385. vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F1,
  386. tx_context->pkt_type,
  387. priv->tx_rate_fb1);
  388. vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
  389. return vnt_rxtx_datahead_g_fb(tx_context, &buf->data_head);
  390. }
  391. static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
  392. struct vnt_rts_ab *buf)
  393. {
  394. struct vnt_private *priv = tx_context->priv;
  395. u16 current_rate = tx_context->tx_rate;
  396. u16 rts_frame_len = 20;
  397. vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
  398. tx_context->pkt_type, &buf->ab);
  399. buf->duration = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
  400. tx_context->pkt_type,
  401. current_rate);
  402. vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
  403. return vnt_rxtx_datahead_ab(tx_context, &buf->data_head);
  404. }
  405. static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
  406. struct vnt_rts_a_fb *buf)
  407. {
  408. struct vnt_private *priv = tx_context->priv;
  409. u16 current_rate = tx_context->tx_rate;
  410. u16 rts_frame_len = 20;
  411. vnt_get_phy_field(priv, rts_frame_len,
  412. priv->top_ofdm_basic_rate, tx_context->pkt_type, &buf->a);
  413. buf->duration = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
  414. tx_context->pkt_type,
  415. current_rate);
  416. buf->rts_duration_f0 =
  417. vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F0,
  418. tx_context->pkt_type,
  419. priv->tx_rate_fb0);
  420. buf->rts_duration_f1 =
  421. vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F1,
  422. tx_context->pkt_type,
  423. priv->tx_rate_fb1);
  424. vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
  425. return vnt_rxtx_datahead_a_fb(tx_context, &buf->data_head);
  426. }
  427. static u16 vnt_fill_cts_fb_head(struct vnt_usb_send_context *tx_context,
  428. union vnt_tx_data_head *head)
  429. {
  430. struct vnt_private *priv = tx_context->priv;
  431. struct vnt_cts_fb *buf = &head->cts_g_fb;
  432. u32 cts_frame_len = 14;
  433. u16 current_rate = tx_context->tx_rate;
  434. /* Get SignalField,ServiceField,Length */
  435. vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate,
  436. PK_TYPE_11B, &buf->b);
  437. buf->duration_ba =
  438. vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA,
  439. tx_context->pkt_type,
  440. current_rate);
  441. /* Get CTSDuration_ba_f0 */
  442. buf->cts_duration_ba_f0 =
  443. vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F0,
  444. tx_context->pkt_type,
  445. priv->tx_rate_fb0);
  446. /* Get CTSDuration_ba_f1 */
  447. buf->cts_duration_ba_f1 =
  448. vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F1,
  449. tx_context->pkt_type,
  450. priv->tx_rate_fb1);
  451. /* Get CTS Frame body */
  452. buf->data.duration = buf->duration_ba;
  453. buf->data.frame_control =
  454. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
  455. ether_addr_copy(buf->data.ra, priv->current_net_addr);
  456. return vnt_rxtx_datahead_g_fb(tx_context, &buf->data_head);
  457. }
  458. static u16 vnt_fill_cts_head(struct vnt_usb_send_context *tx_context,
  459. union vnt_tx_data_head *head)
  460. {
  461. struct vnt_private *priv = tx_context->priv;
  462. struct vnt_cts *buf = &head->cts_g;
  463. u32 cts_frame_len = 14;
  464. u16 current_rate = tx_context->tx_rate;
  465. /* Get SignalField,ServiceField,Length */
  466. vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate,
  467. PK_TYPE_11B, &buf->b);
  468. /* Get CTSDuration_ba */
  469. buf->duration_ba =
  470. vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA,
  471. tx_context->pkt_type,
  472. current_rate);
  473. /*Get CTS Frame body*/
  474. buf->data.duration = buf->duration_ba;
  475. buf->data.frame_control =
  476. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
  477. ether_addr_copy(buf->data.ra, priv->current_net_addr);
  478. return vnt_rxtx_datahead_g(tx_context, &buf->data_head);
  479. }
  480. static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context,
  481. union vnt_tx_head *tx_head, bool need_mic)
  482. {
  483. struct vnt_private *priv = tx_context->priv;
  484. struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts;
  485. union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head;
  486. u32 frame_len = tx_context->frame_len;
  487. u16 current_rate = tx_context->tx_rate;
  488. u8 need_ack = tx_context->need_ack;
  489. buf->rts_rrv_time_aa = vnt_get_rtscts_rsvtime_le(priv, 2,
  490. tx_context->pkt_type, frame_len, current_rate);
  491. buf->rts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 1,
  492. tx_context->pkt_type, frame_len, current_rate);
  493. buf->rts_rrv_time_bb = vnt_get_rtscts_rsvtime_le(priv, 0,
  494. tx_context->pkt_type, frame_len, current_rate);
  495. buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
  496. frame_len, current_rate,
  497. need_ack);
  498. buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, frame_len,
  499. priv->top_cck_basic_rate, need_ack);
  500. if (need_mic)
  501. head = &tx_head->tx_rts.tx.mic.head;
  502. if (tx_context->fb_option)
  503. return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb);
  504. return vnt_rxtx_rts_g_head(tx_context, &head->rts_g);
  505. }
  506. static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context,
  507. union vnt_tx_head *tx_head, bool need_mic)
  508. {
  509. struct vnt_private *priv = tx_context->priv;
  510. struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts;
  511. union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head;
  512. u32 frame_len = tx_context->frame_len;
  513. u16 current_rate = tx_context->tx_rate;
  514. u8 need_ack = tx_context->need_ack;
  515. buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
  516. frame_len, current_rate, need_ack);
  517. buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B,
  518. frame_len, priv->top_cck_basic_rate, need_ack);
  519. buf->cts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 3,
  520. tx_context->pkt_type, frame_len, current_rate);
  521. if (need_mic)
  522. head = &tx_head->tx_cts.tx.mic.head;
  523. /* Fill CTS */
  524. if (tx_context->fb_option)
  525. return vnt_fill_cts_fb_head(tx_context, head);
  526. return vnt_fill_cts_head(tx_context, head);
  527. }
  528. static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
  529. union vnt_tx_head *tx_head, bool need_rts, bool need_mic)
  530. {
  531. struct vnt_private *priv = tx_context->priv;
  532. struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab;
  533. union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head;
  534. u32 frame_len = tx_context->frame_len;
  535. u16 current_rate = tx_context->tx_rate;
  536. u8 need_ack = tx_context->need_ack;
  537. buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
  538. frame_len, current_rate, need_ack);
  539. if (need_mic)
  540. head = &tx_head->tx_ab.tx.mic.head;
  541. if (need_rts) {
  542. if (tx_context->pkt_type == PK_TYPE_11B)
  543. buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 0,
  544. tx_context->pkt_type, frame_len, current_rate);
  545. else /* PK_TYPE_11A */
  546. buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 2,
  547. tx_context->pkt_type, frame_len, current_rate);
  548. if (tx_context->fb_option &&
  549. tx_context->pkt_type == PK_TYPE_11A)
  550. return vnt_rxtx_rts_a_fb_head(tx_context,
  551. &head->rts_a_fb);
  552. return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab);
  553. }
  554. if (tx_context->pkt_type == PK_TYPE_11A)
  555. return vnt_rxtx_datahead_a_fb(tx_context,
  556. &head->data_head_a_fb);
  557. return vnt_rxtx_datahead_ab(tx_context, &head->data_head_ab);
  558. }
  559. static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context,
  560. struct vnt_tx_buffer *tx_buffer,
  561. struct vnt_mic_hdr **mic_hdr, u32 need_mic,
  562. bool need_rts)
  563. {
  564. if (tx_context->pkt_type == PK_TYPE_11GB ||
  565. tx_context->pkt_type == PK_TYPE_11GA) {
  566. if (need_rts) {
  567. if (need_mic)
  568. *mic_hdr = &tx_buffer->
  569. tx_head.tx_rts.tx.mic.hdr;
  570. return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
  571. need_mic);
  572. }
  573. if (need_mic)
  574. *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
  575. return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head, need_mic);
  576. }
  577. if (need_mic)
  578. *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
  579. return vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, need_rts, need_mic);
  580. }
  581. static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
  582. u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
  583. u16 payload_len, struct vnt_mic_hdr *mic_hdr)
  584. {
  585. struct ieee80211_hdr *hdr = tx_context->hdr;
  586. struct ieee80211_key_seq seq;
  587. u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
  588. /* strip header and icv len from payload */
  589. payload_len -= ieee80211_get_hdrlen_from_skb(skb);
  590. payload_len -= tx_key->icv_len;
  591. switch (tx_key->cipher) {
  592. case WLAN_CIPHER_SUITE_WEP40:
  593. case WLAN_CIPHER_SUITE_WEP104:
  594. memcpy(key_buffer, iv, 3);
  595. memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
  596. if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
  597. memcpy(key_buffer + 8, iv, 3);
  598. memcpy(key_buffer + 11,
  599. tx_key->key, WLAN_KEY_LEN_WEP40);
  600. }
  601. break;
  602. case WLAN_CIPHER_SUITE_TKIP:
  603. ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
  604. break;
  605. case WLAN_CIPHER_SUITE_CCMP:
  606. if (!mic_hdr)
  607. return;
  608. mic_hdr->id = 0x59;
  609. mic_hdr->payload_len = cpu_to_be16(payload_len);
  610. ether_addr_copy(mic_hdr->mic_addr2, hdr->addr2);
  611. ieee80211_get_key_tx_seq(tx_key, &seq);
  612. memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
  613. if (ieee80211_has_a4(hdr->frame_control))
  614. mic_hdr->hlen = cpu_to_be16(28);
  615. else
  616. mic_hdr->hlen = cpu_to_be16(22);
  617. ether_addr_copy(mic_hdr->addr1, hdr->addr1);
  618. ether_addr_copy(mic_hdr->addr2, hdr->addr2);
  619. ether_addr_copy(mic_hdr->addr3, hdr->addr3);
  620. mic_hdr->frame_control = cpu_to_le16(
  621. le16_to_cpu(hdr->frame_control) & 0xc78f);
  622. mic_hdr->seq_ctrl = cpu_to_le16(
  623. le16_to_cpu(hdr->seq_ctrl) & 0xf);
  624. if (ieee80211_has_a4(hdr->frame_control))
  625. ether_addr_copy(mic_hdr->addr4, hdr->addr4);
  626. memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
  627. break;
  628. default:
  629. break;
  630. }
  631. }
  632. int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
  633. {
  634. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  635. struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
  636. struct ieee80211_rate *rate;
  637. struct ieee80211_key_conf *tx_key;
  638. struct ieee80211_hdr *hdr;
  639. struct vnt_mic_hdr *mic_hdr = NULL;
  640. struct vnt_tx_buffer *tx_buffer;
  641. struct vnt_tx_fifo_head *tx_buffer_head;
  642. struct vnt_usb_send_context *tx_context;
  643. unsigned long flags;
  644. u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
  645. u8 pkt_type, fb_option = AUTO_FB_NONE;
  646. bool need_rts = false, is_pspoll = false;
  647. bool need_mic = false;
  648. hdr = (struct ieee80211_hdr *)(skb->data);
  649. rate = ieee80211_get_tx_rate(priv->hw, info);
  650. current_rate = rate->hw_value;
  651. if (priv->current_rate != current_rate &&
  652. !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
  653. priv->current_rate = current_rate;
  654. vnt_schedule_command(priv, WLAN_CMD_SETPOWER);
  655. }
  656. if (current_rate > RATE_11M) {
  657. if (info->band == IEEE80211_BAND_5GHZ) {
  658. pkt_type = PK_TYPE_11A;
  659. } else {
  660. if (tx_rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  661. pkt_type = PK_TYPE_11GB;
  662. else
  663. pkt_type = PK_TYPE_11GA;
  664. }
  665. } else {
  666. pkt_type = PK_TYPE_11B;
  667. }
  668. spin_lock_irqsave(&priv->lock, flags);
  669. tx_context = vnt_get_free_context(priv);
  670. if (!tx_context) {
  671. dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
  672. spin_unlock_irqrestore(&priv->lock, flags);
  673. return -ENOMEM;
  674. }
  675. tx_context->skb = skb;
  676. tx_context->pkt_type = pkt_type;
  677. tx_context->need_ack = false;
  678. tx_context->frame_len = skb->len + 4;
  679. tx_context->tx_rate = current_rate;
  680. spin_unlock_irqrestore(&priv->lock, flags);
  681. tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
  682. tx_buffer_head = &tx_buffer->fifo_head;
  683. tx_body_size = skb->len;
  684. /*Set fifo controls */
  685. if (pkt_type == PK_TYPE_11A)
  686. tx_buffer_head->fifo_ctl = 0;
  687. else if (pkt_type == PK_TYPE_11B)
  688. tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11B);
  689. else if (pkt_type == PK_TYPE_11GB)
  690. tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GB);
  691. else if (pkt_type == PK_TYPE_11GA)
  692. tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GA);
  693. if (!ieee80211_is_data(hdr->frame_control)) {
  694. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT |
  695. FIFOCTL_ISDMA0);
  696. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_TMOEN);
  697. tx_buffer_head->time_stamp =
  698. cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
  699. } else {
  700. tx_buffer_head->time_stamp =
  701. cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
  702. }
  703. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  704. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_NEEDACK);
  705. tx_context->need_ack = true;
  706. }
  707. if (ieee80211_has_retry(hdr->frame_control))
  708. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LRETRY);
  709. if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  710. priv->preamble_type = PREAMBLE_SHORT;
  711. else
  712. priv->preamble_type = PREAMBLE_LONG;
  713. if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  714. need_rts = true;
  715. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_RTS);
  716. }
  717. if (ieee80211_has_a4(hdr->frame_control))
  718. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LHEAD);
  719. if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
  720. is_pspoll = true;
  721. tx_buffer_head->frag_ctl =
  722. cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
  723. if (info->control.hw_key) {
  724. tx_key = info->control.hw_key;
  725. switch (info->control.hw_key->cipher) {
  726. case WLAN_CIPHER_SUITE_WEP40:
  727. case WLAN_CIPHER_SUITE_WEP104:
  728. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
  729. break;
  730. case WLAN_CIPHER_SUITE_TKIP:
  731. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
  732. break;
  733. case WLAN_CIPHER_SUITE_CCMP:
  734. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
  735. need_mic = true;
  736. default:
  737. break;
  738. }
  739. tx_context->frame_len += tx_key->icv_len;
  740. }
  741. tx_buffer_head->current_rate = cpu_to_le16(current_rate);
  742. /* legacy rates TODO use ieee80211_tx_rate */
  743. if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
  744. if (priv->auto_fb_ctrl == AUTO_FB_0) {
  745. tx_buffer_head->fifo_ctl |=
  746. cpu_to_le16(FIFOCTL_AUTO_FB_0);
  747. priv->tx_rate_fb0 =
  748. vnt_fb_opt0[FB_RATE0][current_rate - RATE_18M];
  749. priv->tx_rate_fb1 =
  750. vnt_fb_opt0[FB_RATE1][current_rate - RATE_18M];
  751. fb_option = AUTO_FB_0;
  752. } else if (priv->auto_fb_ctrl == AUTO_FB_1) {
  753. tx_buffer_head->fifo_ctl |=
  754. cpu_to_le16(FIFOCTL_AUTO_FB_1);
  755. priv->tx_rate_fb0 =
  756. vnt_fb_opt1[FB_RATE0][current_rate - RATE_18M];
  757. priv->tx_rate_fb1 =
  758. vnt_fb_opt1[FB_RATE1][current_rate - RATE_18M];
  759. fb_option = AUTO_FB_1;
  760. }
  761. }
  762. tx_context->fb_option = fb_option;
  763. duration_id = vnt_generate_tx_parameter(tx_context, tx_buffer, &mic_hdr,
  764. need_mic, need_rts);
  765. tx_header_size = tx_context->tx_hdr_size;
  766. if (!tx_header_size) {
  767. tx_context->in_use = false;
  768. return -ENOMEM;
  769. }
  770. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
  771. tx_bytes = tx_header_size + tx_body_size;
  772. memcpy(tx_context->hdr, skb->data, tx_body_size);
  773. hdr->duration_id = cpu_to_le16(duration_id);
  774. if (info->control.hw_key) {
  775. tx_key = info->control.hw_key;
  776. if (tx_key->keylen > 0)
  777. vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
  778. tx_key, skb, tx_body_size, mic_hdr);
  779. }
  780. priv->seq_counter = (le16_to_cpu(hdr->seq_ctrl) &
  781. IEEE80211_SCTL_SEQ) >> 4;
  782. tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
  783. tx_buffer->pkt_no = tx_context->pkt_no;
  784. tx_buffer->type = 0x00;
  785. tx_bytes += 4;
  786. tx_context->type = CONTEXT_DATA_PACKET;
  787. tx_context->buf_len = tx_bytes;
  788. spin_lock_irqsave(&priv->lock, flags);
  789. if (vnt_tx_context(priv, tx_context) != STATUS_PENDING) {
  790. spin_unlock_irqrestore(&priv->lock, flags);
  791. return -EIO;
  792. }
  793. spin_unlock_irqrestore(&priv->lock, flags);
  794. return 0;
  795. }
  796. static int vnt_beacon_xmit(struct vnt_private *priv,
  797. struct sk_buff *skb)
  798. {
  799. struct vnt_beacon_buffer *beacon_buffer;
  800. struct vnt_tx_short_buf_head *short_head;
  801. struct ieee80211_tx_info *info;
  802. struct vnt_usb_send_context *context;
  803. struct ieee80211_mgmt *mgmt_hdr;
  804. unsigned long flags;
  805. u32 frame_size = skb->len + 4;
  806. u16 current_rate, count;
  807. spin_lock_irqsave(&priv->lock, flags);
  808. context = vnt_get_free_context(priv);
  809. if (!context) {
  810. dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
  811. spin_unlock_irqrestore(&priv->lock, flags);
  812. return -ENOMEM;
  813. }
  814. context->skb = skb;
  815. spin_unlock_irqrestore(&priv->lock, flags);
  816. beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
  817. short_head = &beacon_buffer->short_head;
  818. if (priv->bb_type == BB_TYPE_11A) {
  819. current_rate = RATE_6M;
  820. /* Get SignalField,ServiceField,Length */
  821. vnt_get_phy_field(priv, frame_size, current_rate,
  822. PK_TYPE_11A, &short_head->ab);
  823. /* Get Duration and TimeStampOff */
  824. short_head->duration = vnt_get_duration_le(priv,
  825. PK_TYPE_11A, false);
  826. short_head->time_stamp_off =
  827. vnt_time_stamp_off(priv, current_rate);
  828. } else {
  829. current_rate = RATE_1M;
  830. short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B);
  831. /* Get SignalField,ServiceField,Length */
  832. vnt_get_phy_field(priv, frame_size, current_rate,
  833. PK_TYPE_11B, &short_head->ab);
  834. /* Get Duration and TimeStampOff */
  835. short_head->duration = vnt_get_duration_le(priv,
  836. PK_TYPE_11B, false);
  837. short_head->time_stamp_off =
  838. vnt_time_stamp_off(priv, current_rate);
  839. }
  840. /* Generate Beacon Header */
  841. mgmt_hdr = &beacon_buffer->mgmt_hdr;
  842. memcpy(mgmt_hdr, skb->data, skb->len);
  843. /* time stamp always 0 */
  844. mgmt_hdr->u.beacon.timestamp = 0;
  845. info = IEEE80211_SKB_CB(skb);
  846. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  847. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
  848. hdr->duration_id = 0;
  849. hdr->seq_ctrl = cpu_to_le16(priv->seq_counter << 4);
  850. }
  851. priv->seq_counter++;
  852. if (priv->seq_counter > 0x0fff)
  853. priv->seq_counter = 0;
  854. count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
  855. beacon_buffer->tx_byte_count = cpu_to_le16(count);
  856. beacon_buffer->pkt_no = context->pkt_no;
  857. beacon_buffer->type = 0x01;
  858. context->type = CONTEXT_BEACON_PACKET;
  859. context->buf_len = count + 4; /* USB header */
  860. spin_lock_irqsave(&priv->lock, flags);
  861. if (vnt_tx_context(priv, context) != STATUS_PENDING)
  862. ieee80211_free_txskb(priv->hw, context->skb);
  863. spin_unlock_irqrestore(&priv->lock, flags);
  864. return 0;
  865. }
  866. int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
  867. {
  868. struct sk_buff *beacon;
  869. beacon = ieee80211_beacon_get(priv->hw, vif);
  870. if (!beacon)
  871. return -ENOMEM;
  872. if (vnt_beacon_xmit(priv, beacon)) {
  873. ieee80211_free_txskb(priv->hw, beacon);
  874. return -ENODEV;
  875. }
  876. return 0;
  877. }
  878. int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
  879. struct ieee80211_bss_conf *conf)
  880. {
  881. vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
  882. vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
  883. vnt_mac_set_beacon_interval(priv, conf->beacon_int);
  884. vnt_clear_current_tsf(priv);
  885. vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
  886. vnt_reset_next_tbtt(priv, conf->beacon_int);
  887. return vnt_beacon_make(priv, vif);
  888. }