1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "r8192U.h"
28#include "r819xU_cmdpkt.h"
29
30rt_status SendTxCommandPacket(struct net_device *dev, void *pData, u32 DataLen)
31{
32 struct r8192_priv *priv = ieee80211_priv(dev);
33 struct sk_buff *skb;
34 struct cb_desc *tcb_desc;
35
36
37
38
39 skb = dev_alloc_skb(USB_HWDESC_HEADER_LEN + DataLen + 4);
40 if (!skb)
41 return RT_STATUS_FAILURE;
42 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
43 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
44 tcb_desc->queue_index = TXCMD_QUEUE;
45 tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_NORMAL;
46 tcb_desc->bLastIniPkt = 0;
47 skb_reserve(skb, USB_HWDESC_HEADER_LEN);
48 skb_put_data(skb, pData, DataLen);
49 tcb_desc->txbuf_size = (u16)DataLen;
50
51 if (!priv->ieee80211->check_nic_enough_desc(dev, tcb_desc->queue_index) ||
52 (!skb_queue_empty(&priv->ieee80211->skb_waitQ[tcb_desc->queue_index])) ||
53 (priv->ieee80211->queue_stop)) {
54 RT_TRACE(COMP_FIRMWARE, "=== NULL packet ======> tx full!\n");
55 skb_queue_tail(&priv->ieee80211->skb_waitQ[tcb_desc->queue_index], skb);
56 } else {
57 priv->ieee80211->softmac_hard_start_xmit(skb, dev);
58 }
59
60 return RT_STATUS_SUCCESS;
61}
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81static void cmpk_count_txstatistic(struct net_device *dev, cmpk_txfb_t *pstx_fb)
82{
83 struct r8192_priv *priv = ieee80211_priv(dev);
84#ifdef ENABLE_PS
85 RT_RF_POWER_STATE rtState;
86
87 pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_RF_STATE,
88 (pu1Byte)(&rtState));
89
90
91
92
93
94 if (rtState == eRfOff)
95 return;
96#endif
97
98#ifdef TODO
99 if (pAdapter->bInHctTest)
100 return;
101#endif
102
103
104
105
106 if (pstx_fb->tok) {
107 priv->stats.txfeedbackok++;
108 priv->stats.txoktotal++;
109 priv->stats.txokbytestotal += pstx_fb->pkt_length;
110 priv->stats.txokinperiod++;
111
112
113 if (pstx_fb->pkt_type == PACKET_MULTICAST) {
114 priv->stats.txmulticast++;
115 priv->stats.txbytesmulticast += pstx_fb->pkt_length;
116 } else if (pstx_fb->pkt_type == PACKET_BROADCAST) {
117 priv->stats.txbroadcast++;
118 priv->stats.txbytesbroadcast += pstx_fb->pkt_length;
119 } else {
120 priv->stats.txunicast++;
121 priv->stats.txbytesunicast += pstx_fb->pkt_length;
122 }
123 } else {
124 priv->stats.txfeedbackfail++;
125 priv->stats.txerrtotal++;
126 priv->stats.txerrbytestotal += pstx_fb->pkt_length;
127
128
129 if (pstx_fb->pkt_type == PACKET_MULTICAST)
130 priv->stats.txerrmulticast++;
131 else if (pstx_fb->pkt_type == PACKET_BROADCAST)
132 priv->stats.txerrbroadcast++;
133 else
134 priv->stats.txerrunicast++;
135 }
136
137 priv->stats.txretrycount += pstx_fb->retry_cnt;
138 priv->stats.txfeedbackretry += pstx_fb->retry_cnt;
139}
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163static void cmpk_handle_tx_feedback(struct net_device *dev, u8 *pmsg)
164{
165 struct r8192_priv *priv = ieee80211_priv(dev);
166 cmpk_txfb_t rx_tx_fb;
167
168 priv->stats.txfeedback++;
169
170
171
172
173
174
175
176 memcpy((u8 *)&rx_tx_fb, pmsg, sizeof(cmpk_txfb_t));
177
178 cmpk_count_txstatistic(dev, &rx_tx_fb);
179
180
181
182
183
184}
185
186static void cmdpkt_beacontimerinterrupt_819xusb(struct net_device *dev)
187{
188 struct r8192_priv *priv = ieee80211_priv(dev);
189 u16 tx_rate;
190
191 if (priv->ieee80211->current_network.mode == IEEE_A ||
192 priv->ieee80211->current_network.mode == IEEE_N_5G ||
193 (priv->ieee80211->current_network.mode == IEEE_N_24G &&
194 (!priv->ieee80211->pHTInfo->bCurSuppCCK))) {
195 tx_rate = 60;
196 DMESG("send beacon frame tx rate is 6Mbpm\n");
197 } else {
198 tx_rate = 10;
199 DMESG("send beacon frame tx rate is 1Mbpm\n");
200 }
201
202 rtl819xusb_beacon_tx(dev, tx_rate);
203}
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226static void cmpk_handle_interrupt_status(struct net_device *dev, u8 *pmsg)
227{
228 cmpk_intr_sta_t rx_intr_status;
229 struct r8192_priv *priv = ieee80211_priv(dev);
230
231 DMESG("---> cmpk_Handle_Interrupt_Status()\n");
232
233
234
235
236
237
238 rx_intr_status.length = pmsg[1];
239 if (rx_intr_status.length != (sizeof(cmpk_intr_sta_t) - 2)) {
240 DMESG("cmpk_Handle_Interrupt_Status: wrong length!\n");
241 return;
242 }
243
244
245 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) {
246
247 rx_intr_status.interrupt_status = *((u32 *)(pmsg + 4));
248
249 DMESG("interrupt status = 0x%x\n",
250 rx_intr_status.interrupt_status);
251
252 if (rx_intr_status.interrupt_status & ISR_TxBcnOk) {
253 priv->ieee80211->bibsscoordinator = true;
254 priv->stats.txbeaconokint++;
255 } else if (rx_intr_status.interrupt_status & ISR_TxBcnErr) {
256 priv->ieee80211->bibsscoordinator = false;
257 priv->stats.txbeaconerr++;
258 }
259
260 if (rx_intr_status.interrupt_status & ISR_BcnTimerIntr)
261 cmdpkt_beacontimerinterrupt_819xusb(dev);
262 }
263
264
265
266 DMESG("<---- cmpk_handle_interrupt_status()\n");
267}
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289static void cmpk_handle_query_config_rx(struct net_device *dev, u8 *pmsg)
290{
291 cmpk_query_cfg_t rx_query_cfg;
292
293
294
295
296
297
298 rx_query_cfg.cfg_action = (pmsg[4] & 0x80) >> 7;
299 rx_query_cfg.cfg_type = (pmsg[4] & 0x60) >> 5;
300 rx_query_cfg.cfg_size = (pmsg[4] & 0x18) >> 3;
301 rx_query_cfg.cfg_page = (pmsg[6] & 0x0F) >> 0;
302 rx_query_cfg.cfg_offset = pmsg[7];
303 rx_query_cfg.value = (pmsg[8] << 24) | (pmsg[9] << 16) |
304 (pmsg[10] << 8) | (pmsg[11] << 0);
305 rx_query_cfg.mask = (pmsg[12] << 24) | (pmsg[13] << 16) |
306 (pmsg[14] << 8) | (pmsg[15] << 0);
307}
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327static void cmpk_count_tx_status(struct net_device *dev,
328 cmpk_tx_status_t *pstx_status)
329{
330 struct r8192_priv *priv = ieee80211_priv(dev);
331
332#ifdef ENABLE_PS
333
334 RT_RF_POWER_STATE rtstate;
335
336 pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_RF_STATE,
337 (pu1Byte)(&rtState));
338
339
340
341
342
343 if (rtState == eRfOff)
344 return;
345#endif
346
347 priv->stats.txfeedbackok += pstx_status->txok;
348 priv->stats.txoktotal += pstx_status->txok;
349
350 priv->stats.txfeedbackfail += pstx_status->txfail;
351 priv->stats.txerrtotal += pstx_status->txfail;
352
353 priv->stats.txretrycount += pstx_status->txretry;
354 priv->stats.txfeedbackretry += pstx_status->txretry;
355
356
357 priv->stats.txmulticast += pstx_status->txmcok;
358 priv->stats.txbroadcast += pstx_status->txbcok;
359 priv->stats.txunicast += pstx_status->txucok;
360
361 priv->stats.txerrmulticast += pstx_status->txmcfail;
362 priv->stats.txerrbroadcast += pstx_status->txbcfail;
363 priv->stats.txerrunicast += pstx_status->txucfail;
364
365 priv->stats.txbytesmulticast += pstx_status->txmclength;
366 priv->stats.txbytesbroadcast += pstx_status->txbclength;
367 priv->stats.txbytesunicast += pstx_status->txuclength;
368
369 priv->stats.last_packet_rate = pstx_status->rate;
370}
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390static void cmpk_handle_tx_status(struct net_device *dev, u8 *pmsg)
391{
392 cmpk_tx_status_t rx_tx_sts;
393
394 memcpy((void *)&rx_tx_sts, (void *)pmsg, sizeof(cmpk_tx_status_t));
395
396 cmpk_count_tx_status(dev, &rx_tx_sts);
397}
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416static void cmpk_handle_tx_rate_history(struct net_device *dev, u8 *pmsg)
417{
418 cmpk_tx_rahis_t *ptxrate;
419 u8 i, j;
420 u16 length = sizeof(cmpk_tx_rahis_t);
421 u32 *ptemp;
422 struct r8192_priv *priv = ieee80211_priv(dev);
423
424#ifdef ENABLE_PS
425 pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_RF_STATE,
426 (pu1Byte)(&rtState));
427
428
429
430
431
432 if (rtState == eRfOff)
433 return;
434#endif
435
436 ptemp = (u32 *)pmsg;
437
438
439
440
441 for (i = 0; i < (length/4); i++) {
442 u16 temp1, temp2;
443
444 temp1 = ptemp[i] & 0x0000FFFF;
445 temp2 = ptemp[i] >> 16;
446 ptemp[i] = (temp1 << 16) | temp2;
447 }
448
449 ptxrate = (cmpk_tx_rahis_t *)pmsg;
450
451 if (ptxrate == NULL)
452 return;
453
454 for (i = 0; i < 16; i++) {
455
456 if (i < 4)
457 priv->stats.txrate.cck[i] += ptxrate->cck[i];
458
459
460 if (i < 8)
461 priv->stats.txrate.ofdm[i] += ptxrate->ofdm[i];
462
463 for (j = 0; j < 4; j++)
464 priv->stats.txrate.ht_mcs[j][i] += ptxrate->ht_mcs[j][i];
465 }
466}
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489u32 cmpk_message_handle_rx(struct net_device *dev,
490 struct ieee80211_rx_stats *pstats)
491{
492 int total_length;
493 u8 cmd_length, exe_cnt = 0;
494 u8 element_id;
495 u8 *pcmd_buff;
496
497
498
499
500 if (pstats == NULL)
501 return 0;
502
503
504 total_length = pstats->Length;
505
506
507 pcmd_buff = pstats->virtual_address;
508
509
510 element_id = pcmd_buff[0];
511
512
513
514
515
516
517
518
519 while (total_length > 0 && exe_cnt++ < 100) {
520
521 element_id = pcmd_buff[0];
522
523 switch (element_id) {
524 case RX_TX_FEEDBACK:
525 cmpk_handle_tx_feedback(dev, pcmd_buff);
526 cmd_length = CMPK_RX_TX_FB_SIZE;
527 break;
528
529 case RX_INTERRUPT_STATUS:
530 cmpk_handle_interrupt_status(dev, pcmd_buff);
531 cmd_length = sizeof(cmpk_intr_sta_t);
532 break;
533
534 case BOTH_QUERY_CONFIG:
535 cmpk_handle_query_config_rx(dev, pcmd_buff);
536 cmd_length = CMPK_BOTH_QUERY_CONFIG_SIZE;
537 break;
538
539 case RX_TX_STATUS:
540 cmpk_handle_tx_status(dev, pcmd_buff);
541 cmd_length = CMPK_RX_TX_STS_SIZE;
542 break;
543
544 case RX_TX_PER_PKT_FEEDBACK:
545
546
547
548 cmd_length = CMPK_RX_TX_FB_SIZE;
549 break;
550
551 case RX_TX_RATE_HISTORY:
552 cmpk_handle_tx_rate_history(dev, pcmd_buff);
553 cmd_length = CMPK_TX_RAHIS_SIZE;
554 break;
555
556 default:
557
558 RT_TRACE(COMP_ERR, "---->%s():unknown CMD Element\n",
559 __func__);
560 return 1;
561 }
562
563 total_length -= cmd_length;
564 pcmd_buff += cmd_length;
565 }
566 return 1;
567}
568