rxtx.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  4. * All rights reserved.
  5. *
  6. * File: rxtx.c
  7. *
  8. * Purpose: handle WMAC/802.3/802.11 rx & tx functions
  9. *
  10. * Author: Lyndon Chen
  11. *
  12. * Date: May 20, 2003
  13. *
  14. * Functions:
  15. * vnt_generate_tx_parameter - Generate tx dma required parameter.
  16. * vnt_get_duration_le - get tx data required duration
  17. * vnt_get_rtscts_duration_le- get rtx/cts required duration
  18. * vnt_get_rtscts_rsvtime_le- get rts/cts reserved time
  19. * vnt_get_rsvtime- get frame reserved time
  20. * vnt_fill_cts_head- fulfill CTS ctl header
  21. *
  22. * Revision History:
  23. *
  24. */
  25. #include <linux/etherdevice.h>
  26. #include "device.h"
  27. #include "rxtx.h"
  28. #include "card.h"
  29. #include "mac.h"
  30. #include "rf.h"
  31. #include "usbpipe.h"
  32. static const u16 vnt_time_stampoff[2][MAX_RATE] = {
  33. /* Long Preamble */
  34. {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23},
  35. /* Short Preamble */
  36. {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23},
  37. };
  38. static const u16 vnt_fb_opt0[2][5] = {
  39. {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, /* fallback_rate0 */
  40. {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, /* fallback_rate1 */
  41. };
  42. static const u16 vnt_fb_opt1[2][5] = {
  43. {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, /* fallback_rate0 */
  44. {RATE_6M, RATE_6M, RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */
  45. };
  46. #define RTSDUR_BB 0
  47. #define RTSDUR_BA 1
  48. #define RTSDUR_AA 2
  49. #define CTSDUR_BA 3
  50. #define RTSDUR_BA_F0 4
  51. #define RTSDUR_AA_F0 5
  52. #define RTSDUR_BA_F1 6
  53. #define RTSDUR_AA_F1 7
  54. #define CTSDUR_BA_F0 8
  55. #define CTSDUR_BA_F1 9
  56. #define DATADUR_B 10
  57. #define DATADUR_A 11
  58. #define DATADUR_A_F0 12
  59. #define DATADUR_A_F1 13
  60. static struct vnt_usb_send_context
  61. *vnt_get_free_context(struct vnt_private *priv)
  62. {
  63. struct vnt_usb_send_context *context = NULL;
  64. int ii;
  65. dev_dbg(&priv->usb->dev, "%s\n", __func__);
  66. for (ii = 0; ii < priv->num_tx_context; ii++) {
  67. if (!priv->tx_context[ii])
  68. return NULL;
  69. context = priv->tx_context[ii];
  70. if (!context->in_use) {
  71. context->in_use = true;
  72. memset(context->data, 0,
  73. MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
  74. context->hdr = NULL;
  75. return context;
  76. }
  77. }
  78. if (ii == priv->num_tx_context) {
  79. dev_dbg(&priv->usb->dev, "%s No Free Tx Context\n", __func__);
  80. ieee80211_stop_queues(priv->hw);
  81. }
  82. return NULL;
  83. }
  84. static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
  85. {
  86. return cpu_to_le16(vnt_time_stampoff[priv->preamble_type % 2]
  87. [rate % MAX_RATE]);
  88. }
  89. static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type,
  90. u32 frame_length, u16 rate, int need_ack)
  91. {
  92. u32 data_time, ack_time;
  93. data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  94. frame_length, rate);
  95. if (pkt_type == PK_TYPE_11B)
  96. ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  97. 14, (u16)priv->top_cck_basic_rate);
  98. else
  99. ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  100. 14, (u16)priv->top_ofdm_basic_rate);
  101. if (need_ack)
  102. return data_time + priv->sifs + ack_time;
  103. return data_time;
  104. }
  105. static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
  106. u32 frame_length, u16 rate, int need_ack)
  107. {
  108. return cpu_to_le16((u16)vnt_get_rsvtime(priv, pkt_type,
  109. frame_length, rate, need_ack));
  110. }
  111. static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv, u8 rsv_type,
  112. u8 pkt_type, u32 frame_length,
  113. u16 current_rate)
  114. {
  115. u32 rrv_time, rts_time, cts_time, ack_time, data_time;
  116. rrv_time = 0;
  117. rts_time = 0;
  118. cts_time = 0;
  119. ack_time = 0;
  120. data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  121. frame_length, current_rate);
  122. if (rsv_type == 0) {
  123. rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  124. 20, priv->top_cck_basic_rate);
  125. ack_time = vnt_get_frame_time(priv->preamble_type,
  126. pkt_type, 14,
  127. priv->top_cck_basic_rate);
  128. cts_time = ack_time;
  129. } else if (rsv_type == 1) {
  130. rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  131. 20, priv->top_cck_basic_rate);
  132. cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  133. 14, priv->top_cck_basic_rate);
  134. ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  135. 14, priv->top_ofdm_basic_rate);
  136. } else if (rsv_type == 2) {
  137. rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  138. 20, priv->top_ofdm_basic_rate);
  139. ack_time = vnt_get_frame_time(priv->preamble_type,
  140. pkt_type, 14,
  141. priv->top_ofdm_basic_rate);
  142. cts_time = ack_time;
  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, u8 pkt_type,
  155. 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,
  162. priv->top_cck_basic_rate);
  163. else
  164. ack_time = vnt_get_frame_time(priv->preamble_type,
  165. pkt_type, 14,
  166. priv->top_ofdm_basic_rate);
  167. return cpu_to_le16((u16)(priv->sifs + ack_time));
  168. }
  169. return 0;
  170. }
  171. static __le16 vnt_get_rtscts_duration_le(struct vnt_usb_send_context *context,
  172. u8 dur_type, u8 pkt_type, u16 rate)
  173. {
  174. struct vnt_private *priv = context->priv;
  175. u32 cts_time = 0, dur_time = 0;
  176. u32 frame_length = context->frame_len;
  177. u8 need_ack = context->need_ack;
  178. switch (dur_type) {
  179. case RTSDUR_BB:
  180. case RTSDUR_BA:
  181. case RTSDUR_BA_F0:
  182. case RTSDUR_BA_F1:
  183. cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  184. 14, priv->top_cck_basic_rate);
  185. dur_time = cts_time + 2 * priv->sifs +
  186. vnt_get_rsvtime(priv, pkt_type,
  187. frame_length, rate, need_ack);
  188. break;
  189. case RTSDUR_AA:
  190. case RTSDUR_AA_F0:
  191. case RTSDUR_AA_F1:
  192. cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
  193. 14, priv->top_ofdm_basic_rate);
  194. dur_time = cts_time + 2 * priv->sifs +
  195. vnt_get_rsvtime(priv, pkt_type,
  196. frame_length, rate, need_ack);
  197. break;
  198. case CTSDUR_BA:
  199. case CTSDUR_BA_F0:
  200. case CTSDUR_BA_F1:
  201. dur_time = priv->sifs + vnt_get_rsvtime(priv,
  202. pkt_type, frame_length, rate, need_ack);
  203. break;
  204. default:
  205. break;
  206. }
  207. return cpu_to_le16((u16)dur_time);
  208. }
  209. static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
  210. struct ieee80211_hdr *hdr)
  211. {
  212. u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
  213. u8 *hdr_pos = (u8 *)hdr;
  214. tx_context->hdr = hdr;
  215. if (!tx_context->hdr)
  216. return 0;
  217. return (u16)(hdr_pos - head);
  218. }
  219. static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
  220. struct vnt_tx_datahead_g *buf)
  221. {
  222. struct vnt_private *priv = tx_context->priv;
  223. struct ieee80211_hdr *hdr =
  224. (struct ieee80211_hdr *)tx_context->skb->data;
  225. u32 frame_len = tx_context->frame_len;
  226. u16 rate = tx_context->tx_rate;
  227. u8 need_ack = tx_context->need_ack;
  228. /* Get SignalField,ServiceField,Length */
  229. vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a);
  230. vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate,
  231. PK_TYPE_11B, &buf->b);
  232. /* Get Duration and TimeStamp */
  233. if (ieee80211_is_nullfunc(hdr->frame_control)) {
  234. buf->duration_a = hdr->duration_id;
  235. buf->duration_b = hdr->duration_id;
  236. } else {
  237. buf->duration_a = vnt_get_duration_le(priv,
  238. tx_context->pkt_type, need_ack);
  239. buf->duration_b = vnt_get_duration_le(priv,
  240. PK_TYPE_11B, need_ack);
  241. }
  242. buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
  243. buf->time_stamp_off_b = vnt_time_stamp_off(priv,
  244. priv->top_cck_basic_rate);
  245. tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
  246. return le16_to_cpu(buf->duration_a);
  247. }
  248. static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
  249. struct vnt_tx_datahead_g_fb *buf)
  250. {
  251. struct vnt_private *priv = tx_context->priv;
  252. u32 frame_len = tx_context->frame_len;
  253. u16 rate = tx_context->tx_rate;
  254. u8 need_ack = tx_context->need_ack;
  255. /* Get SignalField,ServiceField,Length */
  256. vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a);
  257. vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate,
  258. PK_TYPE_11B, &buf->b);
  259. /* Get Duration and TimeStamp */
  260. buf->duration_a = vnt_get_duration_le(priv, tx_context->pkt_type,
  261. need_ack);
  262. buf->duration_b = vnt_get_duration_le(priv, PK_TYPE_11B, need_ack);
  263. buf->duration_a_f0 = vnt_get_duration_le(priv, tx_context->pkt_type,
  264. need_ack);
  265. buf->duration_a_f1 = vnt_get_duration_le(priv, tx_context->pkt_type,
  266. need_ack);
  267. buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
  268. buf->time_stamp_off_b = vnt_time_stamp_off(priv,
  269. priv->top_cck_basic_rate);
  270. tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
  271. return le16_to_cpu(buf->duration_a);
  272. }
  273. static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
  274. struct vnt_tx_datahead_a_fb *buf)
  275. {
  276. struct vnt_private *priv = tx_context->priv;
  277. u16 rate = tx_context->tx_rate;
  278. u8 pkt_type = tx_context->pkt_type;
  279. u8 need_ack = tx_context->need_ack;
  280. u32 frame_len = tx_context->frame_len;
  281. /* Get SignalField,ServiceField,Length */
  282. vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
  283. /* Get Duration and TimeStampOff */
  284. buf->duration = vnt_get_duration_le(priv, pkt_type, need_ack);
  285. buf->duration_f0 = vnt_get_duration_le(priv, pkt_type, need_ack);
  286. buf->duration_f1 = vnt_get_duration_le(priv, pkt_type, need_ack);
  287. buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
  288. tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
  289. return le16_to_cpu(buf->duration);
  290. }
  291. static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
  292. struct vnt_tx_datahead_ab *buf)
  293. {
  294. struct vnt_private *priv = tx_context->priv;
  295. struct ieee80211_hdr *hdr =
  296. (struct ieee80211_hdr *)tx_context->skb->data;
  297. u32 frame_len = tx_context->frame_len;
  298. u16 rate = tx_context->tx_rate;
  299. u8 need_ack = tx_context->need_ack;
  300. /* Get SignalField,ServiceField,Length */
  301. vnt_get_phy_field(priv, frame_len, rate,
  302. tx_context->pkt_type, &buf->ab);
  303. /* Get Duration and TimeStampOff */
  304. if (ieee80211_is_nullfunc(hdr->frame_control)) {
  305. buf->duration = hdr->duration_id;
  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. ether_addr_copy(rts->ra, hdr->addr1);
  323. ether_addr_copy(rts->ta, hdr->addr2);
  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, priv->top_ofdm_basic_rate,
  407. 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_fb_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. struct vnt_cts_fb *buf = &head->cts_g_fb;
  427. u32 cts_frame_len = 14;
  428. u16 current_rate = tx_context->tx_rate;
  429. /* Get SignalField,ServiceField,Length */
  430. vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate,
  431. PK_TYPE_11B, &buf->b);
  432. buf->duration_ba =
  433. vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA,
  434. tx_context->pkt_type,
  435. current_rate);
  436. /* Get CTSDuration_ba_f0 */
  437. buf->cts_duration_ba_f0 =
  438. vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F0,
  439. tx_context->pkt_type,
  440. priv->tx_rate_fb0);
  441. /* Get CTSDuration_ba_f1 */
  442. buf->cts_duration_ba_f1 =
  443. vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F1,
  444. tx_context->pkt_type,
  445. priv->tx_rate_fb1);
  446. /* Get CTS Frame body */
  447. buf->data.duration = buf->duration_ba;
  448. buf->data.frame_control =
  449. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
  450. ether_addr_copy(buf->data.ra, priv->current_net_addr);
  451. return vnt_rxtx_datahead_g_fb(tx_context, &buf->data_head);
  452. }
  453. static u16 vnt_fill_cts_head(struct vnt_usb_send_context *tx_context,
  454. union vnt_tx_data_head *head)
  455. {
  456. struct vnt_private *priv = tx_context->priv;
  457. struct vnt_cts *buf = &head->cts_g;
  458. u32 cts_frame_len = 14;
  459. u16 current_rate = tx_context->tx_rate;
  460. /* Get SignalField,ServiceField,Length */
  461. vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate,
  462. PK_TYPE_11B, &buf->b);
  463. /* Get CTSDuration_ba */
  464. buf->duration_ba =
  465. vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA,
  466. tx_context->pkt_type,
  467. current_rate);
  468. /*Get CTS Frame body*/
  469. buf->data.duration = buf->duration_ba;
  470. buf->data.frame_control =
  471. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
  472. ether_addr_copy(buf->data.ra, priv->current_net_addr);
  473. return vnt_rxtx_datahead_g(tx_context, &buf->data_head);
  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. if (tx_context->fb_option)
  520. return vnt_fill_cts_fb_head(tx_context, head);
  521. return vnt_fill_cts_head(tx_context, head);
  522. }
  523. static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
  524. union vnt_tx_head *tx_head, bool need_rts, bool need_mic)
  525. {
  526. struct vnt_private *priv = tx_context->priv;
  527. struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab;
  528. union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head;
  529. u32 frame_len = tx_context->frame_len;
  530. u16 current_rate = tx_context->tx_rate;
  531. u8 need_ack = tx_context->need_ack;
  532. buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
  533. frame_len, current_rate, need_ack);
  534. if (need_mic)
  535. head = &tx_head->tx_ab.tx.mic.head;
  536. if (need_rts) {
  537. if (tx_context->pkt_type == PK_TYPE_11B)
  538. buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 0,
  539. tx_context->pkt_type, frame_len, current_rate);
  540. else /* PK_TYPE_11A */
  541. buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 2,
  542. tx_context->pkt_type, frame_len, current_rate);
  543. if (tx_context->fb_option &&
  544. tx_context->pkt_type == PK_TYPE_11A)
  545. return vnt_rxtx_rts_a_fb_head(tx_context,
  546. &head->rts_a_fb);
  547. return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab);
  548. }
  549. if (tx_context->pkt_type == PK_TYPE_11A)
  550. return vnt_rxtx_datahead_a_fb(tx_context,
  551. &head->data_head_a_fb);
  552. return vnt_rxtx_datahead_ab(tx_context, &head->data_head_ab);
  553. }
  554. static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context,
  555. struct vnt_tx_buffer *tx_buffer,
  556. struct vnt_mic_hdr **mic_hdr, u32 need_mic,
  557. bool need_rts)
  558. {
  559. if (tx_context->pkt_type == PK_TYPE_11GB ||
  560. tx_context->pkt_type == PK_TYPE_11GA) {
  561. if (need_rts) {
  562. if (need_mic)
  563. *mic_hdr =
  564. &tx_buffer->tx_head.tx_rts.tx.mic.hdr;
  565. return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
  566. need_mic);
  567. }
  568. if (need_mic)
  569. *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
  570. return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head, need_mic);
  571. }
  572. if (need_mic)
  573. *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
  574. return vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, need_rts, need_mic);
  575. }
  576. static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
  577. u8 *key_buffer, struct ieee80211_key_conf *tx_key,
  578. struct sk_buff *skb, u16 payload_len,
  579. struct vnt_mic_hdr *mic_hdr)
  580. {
  581. struct ieee80211_hdr *hdr = tx_context->hdr;
  582. u64 pn64;
  583. u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
  584. /* strip header and icv len from payload */
  585. payload_len -= ieee80211_get_hdrlen_from_skb(skb);
  586. payload_len -= tx_key->icv_len;
  587. switch (tx_key->cipher) {
  588. case WLAN_CIPHER_SUITE_WEP40:
  589. case WLAN_CIPHER_SUITE_WEP104:
  590. memcpy(key_buffer, iv, 3);
  591. memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
  592. if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
  593. memcpy(key_buffer + 8, iv, 3);
  594. memcpy(key_buffer + 11,
  595. tx_key->key, WLAN_KEY_LEN_WEP40);
  596. }
  597. break;
  598. case WLAN_CIPHER_SUITE_TKIP:
  599. ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
  600. break;
  601. case WLAN_CIPHER_SUITE_CCMP:
  602. if (!mic_hdr)
  603. return;
  604. mic_hdr->id = 0x59;
  605. mic_hdr->payload_len = cpu_to_be16(payload_len);
  606. ether_addr_copy(mic_hdr->mic_addr2, hdr->addr2);
  607. pn64 = atomic64_read(&tx_key->tx_pn);
  608. mic_hdr->ccmp_pn[5] = pn64;
  609. mic_hdr->ccmp_pn[4] = pn64 >> 8;
  610. mic_hdr->ccmp_pn[3] = pn64 >> 16;
  611. mic_hdr->ccmp_pn[2] = pn64 >> 24;
  612. mic_hdr->ccmp_pn[1] = pn64 >> 32;
  613. mic_hdr->ccmp_pn[0] = pn64 >> 40;
  614. if (ieee80211_has_a4(hdr->frame_control))
  615. mic_hdr->hlen = cpu_to_be16(28);
  616. else
  617. mic_hdr->hlen = cpu_to_be16(22);
  618. ether_addr_copy(mic_hdr->addr1, hdr->addr1);
  619. ether_addr_copy(mic_hdr->addr2, hdr->addr2);
  620. ether_addr_copy(mic_hdr->addr3, hdr->addr3);
  621. mic_hdr->frame_control = cpu_to_le16(
  622. le16_to_cpu(hdr->frame_control) & 0xc78f);
  623. mic_hdr->seq_ctrl = cpu_to_le16(
  624. le16_to_cpu(hdr->seq_ctrl) & 0xf);
  625. if (ieee80211_has_a4(hdr->frame_control))
  626. ether_addr_copy(mic_hdr->addr4, hdr->addr4);
  627. memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
  628. break;
  629. default:
  630. break;
  631. }
  632. }
  633. int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
  634. {
  635. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  636. struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
  637. struct ieee80211_rate *rate;
  638. struct ieee80211_key_conf *tx_key;
  639. struct ieee80211_hdr *hdr;
  640. struct vnt_mic_hdr *mic_hdr = NULL;
  641. struct vnt_tx_buffer *tx_buffer;
  642. struct vnt_tx_fifo_head *tx_buffer_head;
  643. struct vnt_usb_send_context *tx_context;
  644. unsigned long flags;
  645. u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
  646. u8 pkt_type, fb_option = AUTO_FB_NONE;
  647. bool need_rts = false;
  648. bool need_mic = false;
  649. hdr = (struct ieee80211_hdr *)(skb->data);
  650. rate = ieee80211_get_tx_rate(priv->hw, info);
  651. current_rate = rate->hw_value;
  652. if (priv->current_rate != current_rate &&
  653. !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
  654. priv->current_rate = current_rate;
  655. vnt_schedule_command(priv, WLAN_CMD_SETPOWER);
  656. }
  657. if (current_rate > RATE_11M) {
  658. if (info->band == NL80211_BAND_5GHZ) {
  659. pkt_type = PK_TYPE_11A;
  660. } else {
  661. if (tx_rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  662. if (priv->basic_rates & VNT_B_RATES)
  663. pkt_type = PK_TYPE_11GB;
  664. else
  665. pkt_type = PK_TYPE_11GA;
  666. } else {
  667. pkt_type = PK_TYPE_11A;
  668. }
  669. }
  670. } else {
  671. pkt_type = PK_TYPE_11B;
  672. }
  673. spin_lock_irqsave(&priv->lock, flags);
  674. tx_context = vnt_get_free_context(priv);
  675. if (!tx_context) {
  676. dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
  677. spin_unlock_irqrestore(&priv->lock, flags);
  678. return -ENOMEM;
  679. }
  680. tx_context->skb = skb;
  681. tx_context->pkt_type = pkt_type;
  682. tx_context->need_ack = false;
  683. tx_context->frame_len = skb->len + 4;
  684. tx_context->tx_rate = current_rate;
  685. spin_unlock_irqrestore(&priv->lock, flags);
  686. tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
  687. tx_buffer_head = &tx_buffer->fifo_head;
  688. tx_body_size = skb->len;
  689. /*Set fifo controls */
  690. if (pkt_type == PK_TYPE_11A)
  691. tx_buffer_head->fifo_ctl = 0;
  692. else if (pkt_type == PK_TYPE_11B)
  693. tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11B);
  694. else if (pkt_type == PK_TYPE_11GB)
  695. tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GB);
  696. else if (pkt_type == PK_TYPE_11GA)
  697. tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GA);
  698. if (!ieee80211_is_data(hdr->frame_control)) {
  699. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT |
  700. FIFOCTL_ISDMA0);
  701. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_TMOEN);
  702. tx_buffer_head->time_stamp =
  703. cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
  704. } else {
  705. tx_buffer_head->time_stamp =
  706. cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
  707. }
  708. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  709. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_NEEDACK);
  710. tx_context->need_ack = true;
  711. }
  712. if (ieee80211_has_retry(hdr->frame_control))
  713. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LRETRY);
  714. if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  715. priv->preamble_type = PREAMBLE_SHORT;
  716. else
  717. priv->preamble_type = PREAMBLE_LONG;
  718. if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  719. need_rts = true;
  720. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_RTS);
  721. }
  722. if (ieee80211_has_a4(hdr->frame_control))
  723. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LHEAD);
  724. tx_buffer_head->frag_ctl =
  725. cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
  726. if (info->control.hw_key) {
  727. tx_key = info->control.hw_key;
  728. switch (info->control.hw_key->cipher) {
  729. case WLAN_CIPHER_SUITE_WEP40:
  730. case WLAN_CIPHER_SUITE_WEP104:
  731. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
  732. break;
  733. case WLAN_CIPHER_SUITE_TKIP:
  734. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
  735. break;
  736. case WLAN_CIPHER_SUITE_CCMP:
  737. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
  738. need_mic = true;
  739. default:
  740. break;
  741. }
  742. tx_context->frame_len += tx_key->icv_len;
  743. }
  744. tx_buffer_head->current_rate = cpu_to_le16(current_rate);
  745. /* legacy rates TODO use ieee80211_tx_rate */
  746. if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
  747. if (priv->auto_fb_ctrl == AUTO_FB_0) {
  748. tx_buffer_head->fifo_ctl |=
  749. cpu_to_le16(FIFOCTL_AUTO_FB_0);
  750. priv->tx_rate_fb0 =
  751. vnt_fb_opt0[FB_RATE0][current_rate - RATE_18M];
  752. priv->tx_rate_fb1 =
  753. vnt_fb_opt0[FB_RATE1][current_rate - RATE_18M];
  754. fb_option = AUTO_FB_0;
  755. } else if (priv->auto_fb_ctrl == AUTO_FB_1) {
  756. tx_buffer_head->fifo_ctl |=
  757. cpu_to_le16(FIFOCTL_AUTO_FB_1);
  758. priv->tx_rate_fb0 =
  759. vnt_fb_opt1[FB_RATE0][current_rate - RATE_18M];
  760. priv->tx_rate_fb1 =
  761. vnt_fb_opt1[FB_RATE1][current_rate - RATE_18M];
  762. fb_option = AUTO_FB_1;
  763. }
  764. }
  765. tx_context->fb_option = fb_option;
  766. duration_id = vnt_generate_tx_parameter(tx_context, tx_buffer, &mic_hdr,
  767. need_mic, need_rts);
  768. tx_header_size = tx_context->tx_hdr_size;
  769. if (!tx_header_size) {
  770. tx_context->in_use = false;
  771. return -ENOMEM;
  772. }
  773. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
  774. tx_bytes = tx_header_size + tx_body_size;
  775. memcpy(tx_context->hdr, skb->data, tx_body_size);
  776. hdr->duration_id = cpu_to_le16(duration_id);
  777. if (info->control.hw_key) {
  778. tx_key = info->control.hw_key;
  779. if (tx_key->keylen > 0)
  780. vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
  781. tx_key, skb, tx_body_size, mic_hdr);
  782. }
  783. priv->seq_counter = (le16_to_cpu(hdr->seq_ctrl) &
  784. IEEE80211_SCTL_SEQ) >> 4;
  785. tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
  786. tx_buffer->pkt_no = tx_context->pkt_no;
  787. tx_buffer->type = 0x00;
  788. tx_bytes += 4;
  789. tx_context->type = CONTEXT_DATA_PACKET;
  790. tx_context->buf_len = tx_bytes;
  791. spin_lock_irqsave(&priv->lock, flags);
  792. if (vnt_tx_context(priv, tx_context) != STATUS_PENDING) {
  793. spin_unlock_irqrestore(&priv->lock, flags);
  794. return -EIO;
  795. }
  796. spin_unlock_irqrestore(&priv->lock, flags);
  797. return 0;
  798. }
  799. static int vnt_beacon_xmit(struct vnt_private *priv, struct sk_buff *skb)
  800. {
  801. struct vnt_beacon_buffer *beacon_buffer;
  802. struct vnt_tx_short_buf_head *short_head;
  803. struct ieee80211_tx_info *info;
  804. struct vnt_usb_send_context *context;
  805. struct ieee80211_mgmt *mgmt_hdr;
  806. unsigned long flags;
  807. u32 frame_size = skb->len + 4;
  808. u16 current_rate, count;
  809. spin_lock_irqsave(&priv->lock, flags);
  810. context = vnt_get_free_context(priv);
  811. if (!context) {
  812. dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
  813. spin_unlock_irqrestore(&priv->lock, flags);
  814. return -ENOMEM;
  815. }
  816. context->skb = skb;
  817. spin_unlock_irqrestore(&priv->lock, flags);
  818. beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
  819. short_head = &beacon_buffer->short_head;
  820. if (priv->bb_type == BB_TYPE_11A) {
  821. current_rate = RATE_6M;
  822. /* Get SignalField,ServiceField,Length */
  823. vnt_get_phy_field(priv, frame_size, current_rate,
  824. PK_TYPE_11A, &short_head->ab);
  825. /* Get Duration and TimeStampOff */
  826. short_head->duration = vnt_get_duration_le(priv,
  827. PK_TYPE_11A, false);
  828. short_head->time_stamp_off =
  829. vnt_time_stamp_off(priv, current_rate);
  830. } else {
  831. current_rate = RATE_1M;
  832. short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B);
  833. /* Get SignalField,ServiceField,Length */
  834. vnt_get_phy_field(priv, frame_size, current_rate,
  835. PK_TYPE_11B, &short_head->ab);
  836. /* Get Duration and TimeStampOff */
  837. short_head->duration = vnt_get_duration_le(priv,
  838. PK_TYPE_11B, false);
  839. short_head->time_stamp_off =
  840. vnt_time_stamp_off(priv, current_rate);
  841. }
  842. /* Generate Beacon Header */
  843. mgmt_hdr = &beacon_buffer->mgmt_hdr;
  844. memcpy(mgmt_hdr, skb->data, skb->len);
  845. /* time stamp always 0 */
  846. mgmt_hdr->u.beacon.timestamp = 0;
  847. info = IEEE80211_SKB_CB(skb);
  848. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  849. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
  850. hdr->duration_id = 0;
  851. hdr->seq_ctrl = cpu_to_le16(priv->seq_counter << 4);
  852. }
  853. priv->seq_counter++;
  854. if (priv->seq_counter > 0x0fff)
  855. priv->seq_counter = 0;
  856. count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
  857. beacon_buffer->tx_byte_count = cpu_to_le16(count);
  858. beacon_buffer->pkt_no = context->pkt_no;
  859. beacon_buffer->type = 0x01;
  860. context->type = CONTEXT_BEACON_PACKET;
  861. context->buf_len = count + 4; /* USB header */
  862. spin_lock_irqsave(&priv->lock, flags);
  863. if (vnt_tx_context(priv, context) != STATUS_PENDING)
  864. ieee80211_free_txskb(priv->hw, context->skb);
  865. spin_unlock_irqrestore(&priv->lock, flags);
  866. return 0;
  867. }
  868. int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
  869. {
  870. struct sk_buff *beacon;
  871. beacon = ieee80211_beacon_get(priv->hw, vif);
  872. if (!beacon)
  873. return -ENOMEM;
  874. if (vnt_beacon_xmit(priv, beacon)) {
  875. ieee80211_free_txskb(priv->hw, beacon);
  876. return -ENODEV;
  877. }
  878. return 0;
  879. }
  880. int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
  881. struct ieee80211_bss_conf *conf)
  882. {
  883. vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
  884. vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
  885. vnt_mac_set_beacon_interval(priv, conf->beacon_int);
  886. vnt_clear_current_tsf(priv);
  887. vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
  888. vnt_reset_next_tbtt(priv, conf->beacon_int);
  889. return vnt_beacon_make(priv, vif);
  890. }