rxtx.c 32 KB

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