2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
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.
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.
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
28 * s_vGenerateTxParameter - Generate tx dma required parameter.
29 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
34 * s_uGetRTSCTSDuration- get rtx/cts required duration
35 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
38 * s_vFillFragParameter- Set fragment ctl parameter.
39 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
63 static int msglevel = MSG_LEVEL_INFO;
65 static const u16 wTimeStampOff[2][MAX_RATE] = {
66 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
67 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 static const u16 wFB_Opt0[2][5] = {
71 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
72 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
74 static const u16 wFB_Opt1[2][5] = {
75 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
76 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
83 #define RTSDUR_BA_F0 4
84 #define RTSDUR_AA_F0 5
85 #define RTSDUR_BA_F1 6
86 #define RTSDUR_AA_F1 7
87 #define CTSDUR_BA_F0 8
88 #define CTSDUR_BA_F1 9
91 #define DATADUR_A_F0 12
92 #define DATADUR_A_F1 13
94 static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
95 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
97 static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
99 static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
100 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
101 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
102 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts);
104 static void s_vGenerateMACHeader(struct vnt_private *pDevice,
105 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
106 int bNeedEncrypt, u16 wFragType, u32 uFragIdx);
108 static void s_vFillTxKey(struct vnt_private *pDevice,
109 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
110 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
111 struct vnt_mic_hdr *mic_hdr);
113 static void s_vSWencryption(struct vnt_private *pDevice,
114 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
116 static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
117 u32 cbFrameLength, u16 wRate, int bNeedAck);
119 static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
120 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate);
122 static u16 s_vFillCTSHead(struct vnt_private *pDevice,
123 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
124 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
126 static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
127 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
128 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
130 static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
131 u8 byPktType, int bNeedAck);
133 static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
134 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
135 int bNeedAck, u8 byFBOption);
137 static struct vnt_usb_send_context
138 *s_vGetFreeContext(struct vnt_private *priv)
140 struct vnt_usb_send_context *context = NULL;
143 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
145 for (ii = 0; ii < priv->cbTD; ii++) {
149 context = priv->apTD[ii];
150 if (context->in_use == false) {
151 context->in_use = true;
152 memset(context->data, 0,
153 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
158 if (ii == priv->cbTD)
159 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
164 static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
165 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
167 struct net_device_stats *stats = &pDevice->stats;
168 struct vnt_tx_pkt_info *pkt_info = pDevice->pkt_info;
170 pkt_info[byPktNum].fifo_ctl = wFIFOCtl;
171 memcpy(pkt_info[byPktNum].dest_addr, pbyDestAddr, ETH_ALEN);
173 stats->tx_bytes += wPktLength;
176 static void s_vFillTxKey(struct vnt_private *pDevice,
177 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
178 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
179 struct vnt_mic_hdr *mic_hdr)
181 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
182 __le32 *pdwIV = (__le32 *)pbyIVHead;
183 __le32 *pdwExtIV = (__le32 *)((u8 *)pbyIVHead + 4);
184 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
185 __le32 rev_iv_counter;
188 if (pTransmitKey == NULL)
191 rev_iv_counter = cpu_to_le32(pDevice->dwIVCounter);
192 *pdwIV = cpu_to_le32(pDevice->dwIVCounter);
193 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
195 switch (pTransmitKey->byCipherSuite) {
197 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
198 memcpy(pDevice->abyPRNG, (u8 *)&rev_iv_counter, 3);
199 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
200 pTransmitKey->uKeyLength);
202 memcpy(pbyBuf, (u8 *)&rev_iv_counter, 3);
203 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
204 pTransmitKey->uKeyLength);
205 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
206 memcpy(pbyBuf+8, (u8 *)&rev_iv_counter, 3);
207 memcpy(pbyBuf+11, pTransmitKey->abyKey,
208 pTransmitKey->uKeyLength);
211 memcpy(pDevice->abyPRNG, pbyBuf, 16);
213 /* Append IV after Mac Header */
214 *pdwIV &= cpu_to_le32(WEP_IV_MASK);
215 *pdwIV |= cpu_to_le32((u32)pDevice->byKeyIndex << 30);
217 pDevice->dwIVCounter++;
218 if (pDevice->dwIVCounter > WEP_IV_MASK)
219 pDevice->dwIVCounter = 0;
223 pTransmitKey->wTSC15_0++;
224 if (pTransmitKey->wTSC15_0 == 0)
225 pTransmitKey->dwTSC47_16++;
227 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
228 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
230 memcpy(pbyBuf, pDevice->abyPRNG, 16);
233 memcpy(pdwIV, pDevice->abyPRNG, 3);
235 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
237 /* Append IV&ExtIV after Mac Header */
238 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
241 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
245 pTransmitKey->wTSC15_0++;
246 if (pTransmitKey->wTSC15_0 == 0)
247 pTransmitKey->dwTSC47_16++;
249 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
253 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
256 *pdwIV |= cpu_to_le32((u32)(pTransmitKey->wTSC15_0));
258 /* Append IV&ExtIV after Mac Header */
259 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
266 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
267 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
269 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
270 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
273 if (ieee80211_has_a4(pMACHeader->frame_control))
274 mic_hdr->hlen = cpu_to_be16(28);
276 mic_hdr->hlen = cpu_to_be16(22);
278 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
279 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
282 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
283 mic_hdr->frame_control = cpu_to_le16(
284 le16_to_cpu(pMACHeader->frame_control) & 0xc78f);
285 mic_hdr->seq_ctrl = cpu_to_le16(
286 le16_to_cpu(pMACHeader->seq_ctrl) & 0xf);
288 if (ieee80211_has_a4(pMACHeader->frame_control))
289 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
293 static void s_vSWencryption(struct vnt_private *pDevice,
294 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
297 u32 dwICV = 0xffffffff;
300 if (pTransmitKey == NULL)
303 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
304 //=======================================================================
305 // Append ICV after payload
306 dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead);
307 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
308 // finally, we must invert dwCRC to get the correct answer
309 *pdwICV = cpu_to_le32(~dwICV);
311 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
312 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
313 //=======================================================================
314 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
315 //=======================================================================
316 //Append ICV after payload
317 dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead);
318 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
319 // finally, we must invert dwCRC to get the correct answer
320 *pdwICV = cpu_to_le32(~dwICV);
322 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
323 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
324 //=======================================================================
328 static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
330 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
334 /*byPktType : PK_TYPE_11A 0
339 static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
340 u32 frame_length, u16 rate, int need_ack)
342 u32 data_time, ack_time;
344 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
347 if (pkt_type == PK_TYPE_11B)
348 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
349 (u16)priv->byTopCCKBasicRate);
351 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
352 (u16)priv->byTopOFDMBasicRate);
355 return data_time + priv->uSIFS + ack_time;
360 static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
361 u32 frame_length, u16 rate, int need_ack)
363 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
364 frame_length, rate, need_ack));
367 //byFreqType: 0=>5GHZ 1=>2.4GHZ
368 static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
369 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
371 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
373 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
375 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
376 frame_length, current_rate);
379 rts_time = BBuGetFrameTime(priv->byPreambleType,
380 pkt_type, 20, priv->byTopCCKBasicRate);
381 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
382 pkt_type, 14, priv->byTopCCKBasicRate);
383 } else if (rsv_type == 1) {
384 rts_time = BBuGetFrameTime(priv->byPreambleType,
385 pkt_type, 20, priv->byTopCCKBasicRate);
386 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
387 14, priv->byTopCCKBasicRate);
388 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
389 14, priv->byTopOFDMBasicRate);
390 } else if (rsv_type == 2) {
391 rts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
392 20, priv->byTopOFDMBasicRate);
393 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
394 pkt_type, 14, priv->byTopOFDMBasicRate);
395 } else if (rsv_type == 3) {
396 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
397 14, priv->byTopCCKBasicRate);
398 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
399 14, priv->byTopOFDMBasicRate);
401 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
403 return cpu_to_le16((u16)rrv_time);
406 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
408 return cpu_to_le16((u16)rrv_time);
411 //byFreqType 0: 5GHz, 1:2.4Ghz
412 static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
413 u8 byPktType, int bNeedAck)
418 if (byPktType == PK_TYPE_11B)
419 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
420 byPktType, 14, pDevice->byTopCCKBasicRate);
422 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
423 byPktType, 14, pDevice->byTopOFDMBasicRate);
424 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
430 //byFreqType: 0=>5GHZ 1=>2.4GHZ
431 static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
432 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
435 u32 uCTSTime = 0, uDurTime = 0;
442 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
443 14, pDevice->byTopCCKBasicRate);
444 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
445 s_uGetTxRsvTime(pDevice, byPktType,
446 cbFrameLength, wRate, bNeedAck);
452 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
453 14, pDevice->byTopOFDMBasicRate);
454 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
455 s_uGetTxRsvTime(pDevice, byPktType,
456 cbFrameLength, wRate, bNeedAck);
462 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
463 byPktType, cbFrameLength, wRate, bNeedAck);
470 return cpu_to_le16((u16)uDurTime);
473 static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
474 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
476 /* Get SignalField,ServiceField,Length */
477 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
478 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
479 PK_TYPE_11B, &buf->b);
481 /* Get Duration and TimeStamp */
482 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
483 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
485 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
486 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
487 priv->byTopCCKBasicRate);
489 return le16_to_cpu(buf->duration_a);
492 static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
493 u16 rate, struct vnt_tx_datahead_g_fb *buf,
494 u32 frame_len, int need_ack)
496 /* Get SignalField,ServiceField,Length */
497 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
499 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
500 PK_TYPE_11B, &buf->b);
502 /* Get Duration and TimeStamp */
503 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
504 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
506 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
507 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
509 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
510 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
511 priv->byTopCCKBasicRate);
513 return le16_to_cpu(buf->duration_a);
516 static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
517 u16 rate, struct vnt_tx_datahead_a_fb *buf,
518 u32 frame_len, int need_ack)
520 /* Get SignalField,ServiceField,Length */
521 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
522 /* Get Duration and TimeStampOff */
523 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
525 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
526 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
528 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
530 return le16_to_cpu(buf->duration);
533 static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
534 u16 rate, struct vnt_tx_datahead_ab *buf,
535 u32 frame_len, int need_ack)
537 /* Get SignalField,ServiceField,Length */
538 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
539 /* Get Duration and TimeStampOff */
540 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
542 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
544 return le16_to_cpu(buf->duration);
547 static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
548 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
551 rts->duration = duration;
553 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
555 if (priv->op_mode == NL80211_IFTYPE_ADHOC ||
556 priv->op_mode == NL80211_IFTYPE_AP)
557 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
559 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
561 if (priv->op_mode == NL80211_IFTYPE_AP)
562 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
564 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
569 static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
570 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
571 u8 pkt_type, u32 frame_len, int need_ack,
572 u16 current_rate, u8 fb_option)
574 u16 rts_frame_len = 20;
576 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
577 PK_TYPE_11B, &buf->b);
578 BBvCalculateParameter(priv, rts_frame_len,
579 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
581 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
582 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
583 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
584 pkt_type, current_rate, need_ack, fb_option);
585 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
586 pkt_type, current_rate, need_ack, fb_option);
588 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
590 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
591 &buf->data_head, frame_len, need_ack);
594 static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
595 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
596 u8 pkt_type, u32 frame_len, int need_ack,
597 u16 current_rate, u8 fb_option)
599 u16 rts_frame_len = 20;
601 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
602 PK_TYPE_11B, &buf->b);
603 BBvCalculateParameter(priv, rts_frame_len,
604 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
607 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
608 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
609 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
610 pkt_type, current_rate, need_ack, fb_option);
611 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
612 pkt_type, current_rate, need_ack, fb_option);
615 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
616 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
617 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
618 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
619 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
620 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
621 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
622 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
624 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
626 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
627 &buf->data_head, frame_len, need_ack);
630 static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
631 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
632 u8 pkt_type, u32 frame_len, int need_ack,
633 u16 current_rate, u8 fb_option)
635 u16 rts_frame_len = 20;
637 BBvCalculateParameter(priv, rts_frame_len,
638 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
640 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
641 pkt_type, current_rate, need_ack, fb_option);
643 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
645 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
646 &buf->data_head, frame_len, need_ack);
649 static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
650 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
651 u8 pkt_type, u32 frame_len, int need_ack,
652 u16 current_rate, u8 fb_option)
654 u16 rts_frame_len = 20;
656 BBvCalculateParameter(priv, rts_frame_len,
657 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
659 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
660 pkt_type, current_rate, need_ack, fb_option);
662 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
663 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
665 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
666 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
668 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
670 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
671 &buf->data_head, frame_len, need_ack);
674 static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
675 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
676 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
682 /* Note: So far RTSHead doesn't appear in ATIM
683 * & Beacom DMA, so we don't need to take them
685 * Otherwise, we need to modified codes for them.
690 if (byFBOption == AUTO_FB_NONE)
691 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
692 psEthHeader, byPktType, cbFrameLength,
693 bNeedAck, wCurrentRate, byFBOption);
695 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
696 psEthHeader, byPktType, cbFrameLength,
697 bNeedAck, wCurrentRate, byFBOption);
701 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
702 psEthHeader, byPktType, cbFrameLength,
703 bNeedAck, wCurrentRate, byFBOption);
707 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
708 psEthHeader, byPktType, cbFrameLength,
709 bNeedAck, wCurrentRate, byFBOption);
715 static u16 s_vFillCTSHead(struct vnt_private *pDevice,
716 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
717 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
719 u32 uCTSFrameLen = 14;
724 if (byFBOption != AUTO_FB_NONE) {
726 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
727 /* Get SignalField,ServiceField,Length */
728 BBvCalculateParameter(pDevice, uCTSFrameLen,
729 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
730 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
731 cbFrameLength, byPktType,
732 wCurrentRate, bNeedAck, byFBOption);
733 /* Get CTSDuration_ba_f0 */
734 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
735 CTSDUR_BA_F0, cbFrameLength, byPktType,
736 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
737 /* Get CTSDuration_ba_f1 */
738 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
739 CTSDUR_BA_F1, cbFrameLength, byPktType,
740 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
741 /* Get CTS Frame body */
742 pBuf->data.duration = pBuf->duration_ba;
743 pBuf->data.frame_control =
744 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
746 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
748 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
749 &pBuf->data_head, cbFrameLength, bNeedAck);
751 struct vnt_cts *pBuf = &head->cts_g;
752 /* Get SignalField,ServiceField,Length */
753 BBvCalculateParameter(pDevice, uCTSFrameLen,
754 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
755 /* Get CTSDuration_ba */
756 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
757 CTSDUR_BA, cbFrameLength, byPktType,
758 wCurrentRate, bNeedAck, byFBOption);
759 /*Get CTS Frame body*/
760 pBuf->data.duration = pBuf->duration_ba;
761 pBuf->data.frame_control =
762 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
764 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
766 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
767 &pBuf->data_head, cbFrameLength, bNeedAck);
776 * Generate FIFO control for MAC & Baseband controller
780 * pDevice - Pointer to adpater
781 * pTxDataHead - Transmit Data Buffer
782 * pTxBufHead - pTxBufHead
783 * pvRrvTime - pvRrvTime
786 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
787 * bNeedACK - If need ACK
795 static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
796 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
797 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
798 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts)
800 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
801 union vnt_tx_data_head *head = NULL;
803 u8 byFBOption = AUTO_FB_NONE;
805 pFifoHead->current_rate = cpu_to_le16(wCurrentRate);
806 wFifoCtl = pFifoHead->wFIFOCtl;
808 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
809 byFBOption = AUTO_FB_0;
810 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
811 byFBOption = AUTO_FB_1;
813 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
815 struct vnt_rrv_time_rts *pBuf =
816 &tx_buffer->tx_head.tx_rts.rts;
818 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
819 byPktType, cbFrameSize, wCurrentRate);
820 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
821 byPktType, cbFrameSize, wCurrentRate);
822 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
823 byPktType, cbFrameSize, wCurrentRate);
825 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
826 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
827 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
828 PK_TYPE_11B, cbFrameSize,
829 pDevice->byTopCCKBasicRate, bNeedACK);
832 *mic_hdr = &tx_buffer->
833 tx_head.tx_rts.tx.mic.hdr;
834 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
836 head = &tx_buffer->tx_head.tx_rts.tx.head;
840 return s_vFillRTSHead(pDevice, byPktType, head,
841 cbFrameSize, bNeedACK, psEthHeader,
842 wCurrentRate, byFBOption);
845 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
848 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
849 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
850 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
851 PK_TYPE_11B, cbFrameSize,
852 pDevice->byTopCCKBasicRate, bNeedACK);
854 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
855 byPktType, cbFrameSize, wCurrentRate);
858 *mic_hdr = &tx_buffer->
859 tx_head.tx_cts.tx.mic.hdr;
860 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
862 head = &tx_buffer->tx_head.tx_cts.tx.head;
866 return s_vFillCTSHead(pDevice, byPktType,
867 head, cbFrameSize, bNeedACK, wCurrentRate,
870 } else if (byPktType == PK_TYPE_11A) {
872 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
873 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
875 head = &tx_buffer->tx_head.tx_ab.tx.head;
879 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
882 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
883 byPktType, cbFrameSize, wCurrentRate);
885 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
886 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
889 return s_vFillRTSHead(pDevice, byPktType, head,
890 cbFrameSize, bNeedACK, psEthHeader,
891 wCurrentRate, byFBOption);
893 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
896 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
897 PK_TYPE_11A, cbFrameSize,
898 wCurrentRate, bNeedACK);
900 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
901 wCurrentRate, &head->data_head_a_fb,
902 cbFrameSize, bNeedACK);
904 } else if (byPktType == PK_TYPE_11B) {
906 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
907 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
909 head = &tx_buffer->tx_head.tx_ab.tx.head;
913 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
916 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
917 byPktType, cbFrameSize, wCurrentRate);
919 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
920 PK_TYPE_11B, cbFrameSize, wCurrentRate,
924 return s_vFillRTSHead(pDevice, byPktType, head,
926 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
928 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
931 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
932 PK_TYPE_11B, cbFrameSize,
933 wCurrentRate, bNeedACK);
935 return vnt_rxtx_datahead_ab(pDevice, byPktType,
936 wCurrentRate, &head->data_head_ab,
937 cbFrameSize, bNeedACK);
944 u8 * pbyBuffer,//point to pTxBufHead
945 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
946 unsigned int cbFragmentSize,//Hdr+payoad+FCS
949 static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
950 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
951 u32 uSkbPacketLen, struct ethhdr *psEthHeader,
952 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
953 u32 *pcbHeaderLen, u32 *pcbTotalLen)
955 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
956 u32 cbFrameSize, cbFrameBodySize;
958 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
959 u32 cbFCSlen = 4, cbMICHDR = 0;
962 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
963 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
964 u8 abySNAP_Bridgetunnel[ETH_ALEN]
965 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
967 u32 cbHeaderLength = 0, uPadding = 0;
968 struct vnt_mic_hdr *pMICHDR;
969 u8 byFBOption = AUTO_FB_NONE, byFragType;
971 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
972 u32 *pdwMIC_L, *pdwMIC_R;
973 int bSoftWEP = false;
977 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
978 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
979 bSoftWEP = true; /* WEP 256 */
983 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
988 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
991 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
993 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC ||
994 pDevice->op_mode == NL80211_IFTYPE_AP) {
995 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
997 pTxBufHead->wFIFOCtl =
998 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1001 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1004 /* MSDUs in Infra mode always need ACK */
1006 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1009 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
1011 //Set FRAGCTL_MACHDCNT
1012 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1014 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
1016 //Set FIFOCTL_GrpAckPolicy
1017 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
1018 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1021 /* Set Auto Fallback Ctl */
1022 if (wCurrentRate >= RATE_18M) {
1023 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1024 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1026 pDevice->tx_rate_fb0 =
1027 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1028 pDevice->tx_rate_fb1 =
1029 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1031 byFBOption = AUTO_FB_0;
1032 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1033 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1034 pDevice->tx_rate_fb0 =
1035 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1036 pDevice->tx_rate_fb1 =
1037 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1039 byFBOption = AUTO_FB_1;
1043 if (bSoftWEP != true) {
1044 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1045 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1046 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1048 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1049 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1050 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1052 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1053 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1058 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1059 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1063 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1064 cbIVlen = 8;//IV+ExtIV
1068 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1069 cbIVlen = 8;//RSN Header
1071 cbMICHDR = sizeof(struct vnt_mic_hdr);
1073 if (bSoftWEP == false) {
1074 //MAC Header should be padding 0 to DW alignment.
1075 uPadding = 4 - (cbMACHdLen%4);
1080 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1082 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1086 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1089 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
1090 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1092 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1093 if (byFBOption == AUTO_FB_NONE) {
1094 if (bRTS == true) {//RTS_need
1095 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1096 cbMICHDR + sizeof(struct vnt_rts_g);
1098 else { //RTS_needless
1099 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1100 cbMICHDR + sizeof(struct vnt_cts);
1104 if (bRTS == true) {//RTS_need
1105 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1106 cbMICHDR + sizeof(struct vnt_rts_g_fb);
1108 else if (bRTS == false) { //RTS_needless
1109 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1110 cbMICHDR + sizeof(struct vnt_cts_fb);
1114 else {//802.11a/b packet
1115 if (byFBOption == AUTO_FB_NONE) {
1116 if (bRTS == true) {//RTS_need
1117 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1118 cbMICHDR + sizeof(struct vnt_rts_ab);
1120 else if (bRTS == false) { //RTS_needless, no MICHDR
1121 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1122 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
1126 if (bRTS == true) {//RTS_need
1127 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1128 cbMICHDR + sizeof(struct vnt_rts_a_fb);
1130 else if (bRTS == false) { //RTS_needless
1131 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1132 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
1137 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1138 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1139 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1141 //=========================
1143 //=========================
1144 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1145 byFragType = FRAGCTL_NONFRAG;
1146 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1148 /* Fill FIFO, RrvTime, RTS and CTS */
1149 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1150 tx_buffer, &pMICHDR, cbMICHDR,
1151 cbFrameSize, bNeedACK, psEthHeader, bRTS);
1153 // Generate TX MAC Header
1154 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
1157 if (bNeedEncryption == true) {
1159 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
1160 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
1164 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
1165 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1166 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
1167 memcpy((u8 *) (pbyPayloadHead),
1168 abySNAP_Bridgetunnel, 6);
1170 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
1172 pbyType = (u8 *) (pbyPayloadHead + 6);
1174 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1177 if (pPacket != NULL) {
1178 // Copy the Packet into a tx Buffer
1179 memcpy((pbyPayloadHead + cb802_1_H_len),
1180 (pPacket + ETH_HLEN),
1181 uSkbPacketLen - ETH_HLEN
1185 // while bRelayPacketSend psEthHeader is point to header+payload
1186 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
1189 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1191 ///////////////////////////////////////////////////////////////////
1193 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1194 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1195 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1197 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1198 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1199 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1202 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1203 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
1205 // DO Software Michael
1206 MIC_vInit(dwMICKey0, dwMICKey1);
1207 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
1209 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
1210 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1211 dwMICKey0, dwMICKey1);
1213 ///////////////////////////////////////////////////////////////////
1215 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1216 //for (ii = 0; ii < cbFrameBodySize; ii++) {
1217 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
1219 //DBG_PRN_GRP12(("\n\n\n"));
1221 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1223 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1224 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
1226 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1229 if (pDevice->bTxMICFail == true) {
1232 pDevice->bTxMICFail = false;
1234 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1235 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1236 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1239 if (bSoftWEP == true) {
1241 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
1243 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1244 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1245 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
1246 cbFrameSize -= cbICVlen;
1249 cbFrameSize -= cbFCSlen;
1251 *pcbHeaderLen = cbHeaderLength;
1252 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1254 //Set FragCtl in TxBufferHead
1255 pTxBufHead->wFragCtl |= (u16)byFragType;
1264 * Translate 802.3 to 802.11 header
1268 * pDevice - Pointer to adapter
1269 * dwTxBufferAddr - Transmit Buffer
1270 * pPacket - Packet from upper layer
1271 * cbPacketSize - Transmit Data Length
1273 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1274 * pcbAppendPayload - size of append payload for 802.1H translation
1276 * Return Value: none
1280 static void s_vGenerateMACHeader(struct vnt_private *pDevice,
1281 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
1282 int bNeedEncrypt, u16 wFragType, u32 uFragIdx)
1284 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
1286 pMACHeader->frame_control = TYPE_802_11_DATA;
1288 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
1289 memcpy(&(pMACHeader->addr1[0]),
1290 &(psEthHeader->h_dest[0]),
1292 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1293 memcpy(&(pMACHeader->addr3[0]),
1294 &(psEthHeader->h_source[0]),
1296 pMACHeader->frame_control |= FC_FROMDS;
1298 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
1299 memcpy(&(pMACHeader->addr1[0]),
1300 &(psEthHeader->h_dest[0]),
1302 memcpy(&(pMACHeader->addr2[0]),
1303 &(psEthHeader->h_source[0]),
1305 memcpy(&(pMACHeader->addr3[0]),
1306 &(pDevice->abyBSSID[0]),
1309 memcpy(&(pMACHeader->addr3[0]),
1310 &(psEthHeader->h_dest[0]),
1312 memcpy(&(pMACHeader->addr2[0]),
1313 &(psEthHeader->h_source[0]),
1315 memcpy(&(pMACHeader->addr1[0]),
1316 &(pDevice->abyBSSID[0]),
1318 pMACHeader->frame_control |= FC_TODS;
1323 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
1325 pMACHeader->duration_id = cpu_to_le16(wDuration);
1327 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1329 //Set FragNumber in Sequence Control
1330 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
1332 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1333 pDevice->wSeqCounter++;
1334 if (pDevice->wSeqCounter > 0x0fff)
1335 pDevice->wSeqCounter = 0;
1338 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
1339 pMACHeader->frame_control |= FC_MOREFRAG;
1346 * Request instructs a MAC to transmit a 802.11 management packet through
1347 * the adapter onto the medium.
1351 * hDeviceContext - Pointer to the adapter
1352 * pPacket - A pointer to a descriptor for the packet to transmit
1356 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
1360 CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1361 struct vnt_tx_mgmt *pPacket)
1363 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1364 struct vnt_tx_buffer *pTX_Buffer;
1365 struct vnt_usb_send_context *pContext;
1366 struct vnt_tx_fifo_head *pTxBufHead;
1367 struct ieee80211_hdr *pMACHeader;
1368 struct ethhdr sEthHeader;
1369 u8 byPktType, *pbyTxBufferAddr;
1370 struct vnt_mic_hdr *pMICHDR = NULL;
1371 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
1372 int bNeedACK, bIsPSPOLL = false;
1373 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1377 u16 wCurrentRate = RATE_1M;
1378 unsigned long flags;
1380 if (pDevice->byBBType == BB_TYPE_11A) {
1381 wCurrentRate = RATE_6M;
1382 byPktType = PK_TYPE_11A;
1384 wCurrentRate = RATE_1M;
1385 byPktType = PK_TYPE_11B;
1388 if (pMgmt->eScanState != WMAC_NO_SCANNING)
1389 vnt_rf_setpower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1391 vnt_rf_setpower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1393 pDevice->wCurrentRate = wCurrentRate;
1395 spin_lock_irqsave(&pDevice->lock, flags);
1397 pContext = s_vGetFreeContext(pDevice);
1399 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1400 "ManagementSend TX...NO CONTEXT!\n");
1401 spin_unlock_irqrestore(&pDevice->lock, flags);
1402 return CMD_STATUS_RESOURCES;
1405 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
1406 cbFrameBodySize = pPacket->cbPayloadLen;
1407 pTxBufHead = &pTX_Buffer->fifo_head;
1408 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1409 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1413 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1414 pTxBufHead->wFIFOCtl = 0;
1416 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1417 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1419 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1420 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1422 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1423 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1426 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1427 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1429 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
1434 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1437 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1438 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1440 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1441 //Set Preamble type always long
1442 //pDevice->byPreambleType = PREAMBLE_LONG;
1443 // probe-response don't retry
1444 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
1445 // bNeedACK = false;
1446 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1450 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1452 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
1454 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1456 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1459 //Set FRAGCTL_MACHDCNT
1460 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
1463 // Although spec says MMPDU can be fragmented; In most case,
1464 // no one will send a MMPDU under fragmentation. With RTS may occur.
1466 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1467 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1470 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1472 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1473 cbIVlen = 8;//IV+ExtIV
1476 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1477 //We need to get seed here for filling TxKey entry.
1478 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1479 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1481 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1482 cbIVlen = 8;//RSN Header
1484 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1486 //MAC Header should be padding 0 to DW alignment.
1487 uPadding = 4 - (cbMacHdLen%4);
1491 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1493 //Set FIFOCTL_GrpAckPolicy
1494 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
1495 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1497 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1499 //Set RrvTime/RTS/CTS Buffer
1500 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1501 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1502 sizeof(struct vnt_cts);
1504 else { // 802.11a/b packet
1505 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1506 sizeof(struct vnt_tx_datahead_ab);
1509 memcpy(&(sEthHeader.h_dest[0]),
1510 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1512 memcpy(&(sEthHeader.h_source[0]),
1513 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1515 //=========================
1517 //=========================
1518 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
1520 /* Fill FIFO,RrvTime,RTS,and CTS */
1521 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1522 pTX_Buffer, &pMICHDR, 0,
1523 cbFrameSize, bNeedACK, &sEthHeader, false);
1525 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
1527 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1529 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1531 u8 * pbyPayloadHead;
1533 PSKeyItem pTransmitKey = NULL;
1535 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1536 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
1538 if (pDevice->op_mode == NL80211_IFTYPE_STATION &&
1539 pDevice->bLinkPass == true) {
1540 pbyBSSID = pDevice->abyBSSID;
1542 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
1544 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1549 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1554 pbyBSSID = pDevice->abyBroadcastAddr;
1555 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
1556 pTransmitKey = NULL;
1557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->op_mode);
1559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1563 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
1564 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
1566 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
1567 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
1571 // Copy the Packet into a tx Buffer
1572 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1575 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1576 pDevice->wSeqCounter++ ;
1577 if (pDevice->wSeqCounter > 0x0fff)
1578 pDevice->wSeqCounter = 0;
1581 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
1582 // of FIFO control header.
1583 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1584 // in the same place of other packet's Duration-field).
1585 // And it will cause Cisco-AP to issue Disassociation-packet
1586 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1587 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1588 tx_cts.tx.head.cts_g.data_head;
1589 data_head->duration_a =
1590 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1591 data_head->duration_b =
1592 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1594 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1595 tx_ab.tx.head.data_head_ab;
1596 data_head->duration =
1597 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1601 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount));
1602 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
1603 pTX_Buffer->byType = 0x00;
1605 pContext->skb = NULL;
1606 pContext->type = CONTEXT_MGMT_PACKET;
1607 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
1609 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1610 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1611 &pMACHeader->addr1[0], (u16)cbFrameSize,
1612 pTxBufHead->wFIFOCtl);
1615 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1616 &pMACHeader->addr3[0], (u16)cbFrameSize,
1617 pTxBufHead->wFIFOCtl);
1620 PIPEnsSendBulkOut(pDevice,pContext);
1622 spin_unlock_irqrestore(&pDevice->lock, flags);
1624 return CMD_STATUS_PENDING;
1627 CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1628 struct vnt_tx_mgmt *pPacket)
1630 struct vnt_beacon_buffer *pTX_Buffer;
1631 struct vnt_tx_short_buf_head *short_head;
1632 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1633 u32 cbHeaderSize = 0;
1634 struct ieee80211_hdr *pMACHeader;
1636 u32 cbFrameBodySize;
1638 struct vnt_usb_send_context *pContext;
1641 pContext = s_vGetFreeContext(pDevice);
1642 if (NULL == pContext) {
1643 status = CMD_STATUS_RESOURCES;
1644 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1648 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->data[0];
1649 short_head = &pTX_Buffer->short_head;
1651 cbFrameBodySize = pPacket->cbPayloadLen;
1653 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
1655 if (pDevice->byBBType == BB_TYPE_11A) {
1656 wCurrentRate = RATE_6M;
1658 /* Get SignalField,ServiceField,Length */
1659 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1660 PK_TYPE_11A, &short_head->ab);
1662 /* Get Duration and TimeStampOff */
1663 short_head->duration = s_uGetDataDuration(pDevice,
1664 PK_TYPE_11A, false);
1665 short_head->time_stamp_off =
1666 vnt_time_stamp_off(pDevice, wCurrentRate);
1668 wCurrentRate = RATE_1M;
1669 short_head->fifo_ctl |= FIFOCTL_11B;
1671 /* Get SignalField,ServiceField,Length */
1672 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1673 PK_TYPE_11B, &short_head->ab);
1675 /* Get Duration and TimeStampOff */
1676 short_head->duration = s_uGetDataDuration(pDevice,
1677 PK_TYPE_11B, false);
1678 short_head->time_stamp_off =
1679 vnt_time_stamp_off(pDevice, wCurrentRate);
1683 /* Generate Beacon Header */
1684 pMACHeader = &pTX_Buffer->hdr;
1686 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1688 pMACHeader->duration_id = 0;
1689 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1690 pDevice->wSeqCounter++;
1691 if (pDevice->wSeqCounter > 0x0fff)
1692 pDevice->wSeqCounter = 0;
1694 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1696 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)cbReqCount);
1697 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
1698 pTX_Buffer->byType = 0x01;
1700 pContext->skb = NULL;
1701 pContext->type = CONTEXT_MGMT_PACKET;
1702 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
1704 PIPEnsSendBulkOut(pDevice,pContext);
1705 return CMD_STATUS_PENDING;
1709 //TYPE_AC0DMA data tx
1712 * Tx packet via AC0DMA(DMA1)
1716 * pDevice - Pointer to the adapter
1717 * skb - Pointer to tx skb packet
1721 * Return Value: NULL
1724 int nsDMA_tx_packet(struct vnt_private *pDevice, struct sk_buff *skb)
1726 struct net_device_stats *pStats = &pDevice->stats;
1727 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1728 struct vnt_tx_buffer *pTX_Buffer;
1729 u32 BytesToWrite = 0, uHeaderLen = 0;
1731 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1734 int bNeedEncryption = false;
1735 PSKeyItem pTransmitKey = NULL;
1737 int bTKIP_UseGTK = false;
1738 int bNeedDeAuth = false;
1740 int bNodeExist = false;
1741 struct vnt_usb_send_context *pContext;
1742 bool fConvertedPacket;
1744 u16 wKeepRate = pDevice->wCurrentRate;
1745 int bTxeapol_key = false;
1747 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1749 if (pDevice->uAssocCount == 0) {
1750 dev_kfree_skb_irq(skb);
1754 if (is_multicast_ether_addr((u8 *)(skb->data))) {
1757 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1759 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1760 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1762 pMgmt->abyPSTxMap[0] |= byMask[0];
1765 // multicast/broadcast data rate
1767 if (pDevice->byBBType != BB_TYPE_11A)
1768 pDevice->wCurrentRate = RATE_2M;
1770 pDevice->wCurrentRate = RATE_24M;
1771 // long preamble type
1772 pDevice->byPreambleType = PREAMBLE_SHORT;
1776 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
1778 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1780 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1782 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1784 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1785 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1786 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
1787 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1791 // AP rate decided from node
1792 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1793 // tx preamble decided from node
1795 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1796 pDevice->byPreambleType = pDevice->byShortPreamble;
1799 pDevice->byPreambleType = PREAMBLE_LONG;
1805 if (bNodeExist == false) {
1806 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
1807 dev_kfree_skb_irq(skb);
1812 memcpy(&pDevice->sTxEthHeader, skb->data, ETH_HLEN);
1814 //mike add:station mode check eapol-key challenge--->
1816 u8 Protocol_Version; //802.1x Authentication
1817 u8 Packet_Type; //802.1x Authentication
1821 Protocol_Version = skb->data[ETH_HLEN];
1822 Packet_Type = skb->data[ETH_HLEN+1];
1823 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
1824 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
1825 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
1826 /* 802.1x OR eapol-key challenge frame transfer */
1827 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
1828 (Packet_Type == 3)) {
1829 bTxeapol_key = true;
1830 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
1831 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
1832 if(Descriptor_type==254) {
1833 pDevice->fWPA_Authened = true;
1837 pDevice->fWPA_Authened = true;
1838 PRINT_K("WPA2(re-keying) ");
1840 PRINT_K("Authentication completed!!\n");
1842 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
1843 (Key_info & BIT8) && (Key_info & BIT9)) {
1844 pDevice->fWPA_Authened = true;
1845 PRINT_K("WPA2 Authentication completed!!\n");
1850 //mike add:station mode check eapol-key challenge<---
1852 if (pDevice->bEncryptionEnable == true) {
1853 bNeedEncryption = true;
1856 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1857 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1858 pbyBSSID = pDevice->abyBSSID;
1860 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
1862 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1863 bTKIP_UseGTK = true;
1864 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1868 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
1871 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1872 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
1873 pbyBSSID = pDevice->sTxEthHeader.h_dest;
1874 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
1875 for (ii = 0; ii< 6; ii++)
1876 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
1877 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
1880 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
1884 pbyBSSID = pDevice->abyBroadcastAddr;
1885 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
1886 pTransmitKey = NULL;
1887 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1888 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1891 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1893 bTKIP_UseGTK = true;
1894 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1899 byPktType = (u8)pDevice->byPacketType;
1901 if (pDevice->bFixRate) {
1902 if (pDevice->byBBType == BB_TYPE_11B) {
1903 if (pDevice->uConnectionRate >= RATE_11M) {
1904 pDevice->wCurrentRate = RATE_11M;
1906 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
1909 if ((pDevice->byBBType == BB_TYPE_11A) &&
1910 (pDevice->uConnectionRate <= RATE_6M)) {
1911 pDevice->wCurrentRate = RATE_6M;
1913 if (pDevice->uConnectionRate >= RATE_54M)
1914 pDevice->wCurrentRate = RATE_54M;
1916 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
1921 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
1922 // Adhoc Tx rate decided from node DB
1923 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
1924 // Multicast use highest data rate
1925 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1927 pDevice->byPreambleType = pDevice->byShortPreamble;
1930 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
1931 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1932 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1933 pDevice->byPreambleType = pDevice->byShortPreamble;
1937 pDevice->byPreambleType = PREAMBLE_LONG;
1939 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
1942 if (pDevice->byBBType != BB_TYPE_11A)
1943 pDevice->wCurrentRate = RATE_2M;
1945 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
1946 // abyCurrExtSuppRates[]
1947 pDevice->byPreambleType = PREAMBLE_SHORT;
1948 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
1952 if (pDevice->op_mode == NL80211_IFTYPE_STATION) {
1953 // Infra STA rate decided from AP Node, index = 0
1954 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1958 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
1959 if (pDevice->byBBType != BB_TYPE_11A) {
1960 pDevice->wCurrentRate = RATE_1M;
1961 pDevice->byTopCCKBasicRate = RATE_1M;
1962 pDevice->byTopOFDMBasicRate = RATE_6M;
1964 pDevice->wCurrentRate = RATE_6M;
1965 pDevice->byTopCCKBasicRate = RATE_1M;
1966 pDevice->byTopOFDMBasicRate = RATE_6M;
1970 DBG_PRT(MSG_LEVEL_DEBUG,
1971 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
1972 pDevice->wCurrentRate);
1974 if (wKeepRate != pDevice->wCurrentRate) {
1975 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
1978 if (pDevice->wCurrentRate <= RATE_11M) {
1979 byPktType = PK_TYPE_11B;
1982 if (bNeedEncryption == true) {
1983 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
1984 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
1985 bNeedEncryption = false;
1986 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
1987 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1988 if (pTransmitKey == NULL) {
1989 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
1992 if (bTKIP_UseGTK == true) {
1993 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
1996 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
1997 pTransmitKey->dwKeyIndex);
1998 bNeedEncryption = true;
2005 if (pTransmitKey == NULL) {
2006 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2007 dev_kfree_skb_irq(skb);
2008 pStats->tx_dropped++;
2009 return STATUS_FAILURE;
2014 pContext = s_vGetFreeContext(pDevice);
2016 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2017 dev_kfree_skb_irq(skb);
2018 return STATUS_RESOURCES;
2021 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
2023 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
2024 pTX_Buffer, bNeedEncryption,
2025 skb->len, &pDevice->sTxEthHeader,
2026 (u8 *)skb->data, pTransmitKey, uNodeIndex,
2027 pDevice->wCurrentRate,
2028 &uHeaderLen, &BytesToWrite
2031 if (fConvertedPacket == false) {
2032 pContext->in_use = false;
2033 dev_kfree_skb_irq(skb);
2034 return STATUS_FAILURE;
2037 if ( pDevice->bEnablePSMode == true ) {
2038 if ( !pDevice->bPSModeTxBurst ) {
2039 bScheduleCommand((void *) pDevice,
2040 WLAN_CMD_MAC_DISPOWERSAVING,
2042 pDevice->bPSModeTxBurst = true;
2046 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2047 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite);
2049 pContext->skb = skb;
2050 pContext->type = CONTEXT_DATA_PACKET;
2051 pContext->buf_len = (u16)BytesToWrite + 4 ; /* USB header */
2053 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2054 &pDevice->sTxEthHeader.h_dest[0],
2055 (u16)(BytesToWrite-uHeaderLen),
2056 pTX_Buffer->fifo_head.wFIFOCtl);
2058 status = PIPEnsSendBulkOut(pDevice,pContext);
2060 if (bNeedDeAuth == true) {
2061 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
2063 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
2066 if (status != STATUS_PENDING) {
2067 pContext->in_use = false;
2068 dev_kfree_skb_irq(skb);
2069 return STATUS_FAILURE;