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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47#include <linux/types.h>
48#include <linux/etherdevice.h>
49#include <linux/mutex.h>
50#include <linux/semaphore.h>
51
52#include <linux/vmalloc.h>
53#include "csr_wifi_hip_unifi.h"
54#include "csr_wifi_hip_conversions.h"
55#include "unifi_priv.h"
56#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
57#include <net/iw_handler.h>
58#endif
59#include <net/pkt_sched.h>
60
61
62
63
64
65
66
67
68
69
70
71#define ALLOW_Q_PAUSE
72
73#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
74#ifdef UNIFI_NET_NAME
75#define UF_ALLOC_NETDEV(_dev, _size, _name, _setup, _num_of_queues) \
76 do { \
77 static char name[8]; \
78 sprintf(name, "%s%s", UNIFI_NET_NAME, _name); \
79 _dev = alloc_netdev_mq(_size, name, _setup, _num_of_queues); \
80 } while (0);
81#else
82#define UF_ALLOC_NETDEV(_dev, _size, _name, _setup, _num_of_queues) \
83 do { \
84 _dev = alloc_etherdev_mq(_size, _num_of_queues); \
85 } while (0);
86#endif
87#else
88#ifdef UNIFI_NET_NAME
89#define UF_ALLOC_NETDEV(_dev, _size, _name, _setup, _num_of_queues) \
90 do { \
91 static char name[8]; \
92 sprintf(name, "%s%s", UNIFI_NET_NAME, _name); \
93 _dev = alloc_netdev(_size, name, _setup); \
94 } while (0);
95#else
96#define UF_ALLOC_NETDEV(_dev, _size, _name, _setup, _num_of_queues) \
97 do { \
98 _dev = alloc_etherdev(_size); \
99 } while (0);
100#endif
101#endif
102
103
104
105#ifdef CSR_SUPPORT_WEXT
106extern struct iw_handler_def unifi_iw_handler_def;
107#endif
108static void check_ba_frame_age_timeout( unifi_priv_t *priv,
109 netInterface_priv_t *interfacePriv,
110 ba_session_rx_struct *ba_session);
111static void process_ba_frame(unifi_priv_t *priv,
112 netInterface_priv_t *interfacePriv,
113 ba_session_rx_struct *ba_session,
114 frame_desc_struct *frame_desc);
115static void process_ba_complete(unifi_priv_t *priv, netInterface_priv_t *interfacePriv);
116static void process_ma_packet_error_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata);
117static void process_amsdu(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata);
118static int uf_net_open(struct net_device *dev);
119static int uf_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
120static int uf_net_stop(struct net_device *dev);
121static struct net_device_stats *uf_net_get_stats(struct net_device *dev);
122#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
123static u16 uf_net_select_queue(struct net_device *dev, struct sk_buff *skb);
124#endif
125#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
126static netdev_tx_t uf_net_xmit(struct sk_buff *skb, struct net_device *dev);
127#else
128static int uf_net_xmit(struct sk_buff *skb, struct net_device *dev);
129#ifndef NETDEV_TX_OK
130#define NETDEV_TX_OK 0
131#endif
132#ifndef NETDEV_TX_BUSY
133#define NETDEV_TX_BUSY 1
134#endif
135#endif
136static void uf_set_multicast_list(struct net_device *dev);
137
138
139typedef int (*tx_signal_handler)(unifi_priv_t *priv, struct sk_buff *skb, const struct ethhdr *ehdr, CSR_PRIORITY priority);
140
141#ifdef CONFIG_NET_SCHED
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168struct uf_sched_data
169{
170
171 struct tcf_proto *filter_list;
172
173 struct Qdisc *queues[UNIFI_TRAFFIC_Q_MAX];
174};
175
176struct uf_tx_packet_data {
177
178 unifi_TrafficQueue queue;
179
180 CSR_PRIORITY priority;
181
182 unsigned long host_tag;
183};
184
185#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
186static int uf_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd);
187static int uf_qdiscop_requeue(struct sk_buff *skb, struct Qdisc* qd);
188static struct sk_buff *uf_qdiscop_dequeue(struct Qdisc* qd);
189static void uf_qdiscop_reset(struct Qdisc* qd);
190static void uf_qdiscop_destroy(struct Qdisc* qd);
191static int uf_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb);
192#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
193static int uf_qdiscop_tune(struct Qdisc *qd, struct nlattr *opt);
194static int uf_qdiscop_init(struct Qdisc *qd, struct nlattr *opt);
195#else
196static int uf_qdiscop_tune(struct Qdisc *qd, struct rtattr *opt);
197static int uf_qdiscop_init(struct Qdisc *qd, struct rtattr *opt);
198#endif
199#endif
200
201
202#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
203
204static struct Qdisc_ops uf_qdisc_ops =
205{
206 .next = NULL,
207 .cl_ops = NULL,
208 .id = "UniFi Qdisc",
209 .priv_size = sizeof(struct uf_sched_data),
210
211 .enqueue = uf_qdiscop_enqueue,
212 .dequeue = uf_qdiscop_dequeue,
213 .requeue = uf_qdiscop_requeue,
214 .drop = NULL,
215
216 .init = uf_qdiscop_init,
217 .reset = uf_qdiscop_reset,
218 .destroy = uf_qdiscop_destroy,
219 .change = uf_qdiscop_tune,
220
221 .dump = uf_qdiscop_dump,
222};
223#endif
224
225#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
226#define UF_QDISC_CREATE_DFLT(_dev, _ops, _root)
227#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
228#define UF_QDISC_CREATE_DFLT(_dev, _ops, _root) \
229 qdisc_create_dflt(dev, netdev_get_tx_queue(_dev, 0), _ops, _root)
230#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
231#define UF_QDISC_CREATE_DFLT(_dev, _ops, _root) \
232 qdisc_create_dflt(dev, _ops, _root)
233#else
234#define UF_QDISC_CREATE_DFLT(_dev, _ops, _root) \
235 qdisc_create_dflt(dev, _ops)
236#endif
237
238#endif
239
240#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
241static const struct net_device_ops uf_netdev_ops =
242{
243 .ndo_open = uf_net_open,
244 .ndo_stop = uf_net_stop,
245 .ndo_start_xmit = uf_net_xmit,
246 .ndo_do_ioctl = uf_net_ioctl,
247 .ndo_get_stats = uf_net_get_stats,
248 .ndo_set_rx_mode = uf_set_multicast_list,
249 .ndo_select_queue = uf_net_select_queue,
250};
251#endif
252
253static u8 oui_rfc1042[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
254static u8 oui_8021h[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
255
256
257
258static void netdev_mlme_event_handler(ul_client_t *client,
259 const u8 *sig_packed, int sig_len,
260 const bulk_data_param_t *bulkdata,
261 int dir);
262
263#ifdef CSR_SUPPORT_WEXT
264
265
266
267static struct notifier_block uf_netdev_notifier;
268#endif
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294unifi_priv_t *
295uf_alloc_netdevice(CsrSdioFunction *sdio_dev, int bus_id)
296{
297 struct net_device *dev;
298 unifi_priv_t *priv;
299 netInterface_priv_t *interfacePriv;
300#ifdef CSR_SUPPORT_WEXT
301 int rc;
302#endif
303 unsigned char i;
304
305
306
307
308
309
310
311
312
313 UF_ALLOC_NETDEV(dev, sizeof(unifi_priv_t)+sizeof(netInterface_priv_t), "%d", ether_setup, UNIFI_TRAFFIC_Q_MAX);
314
315 if (dev == NULL) {
316 return NULL;
317 }
318
319
320 interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
321 priv = (unifi_priv_t *)(interfacePriv + 1);
322 interfacePriv->privPtr = priv;
323 interfacePriv->InterfaceTag = 0;
324
325
326
327 for(i=0; i<CSR_WIFI_NUM_INTERFACES; i++) {
328 priv->netdev[i] = NULL;
329 priv->interfacePriv[i] = NULL;
330 }
331 priv->netdev[0] = dev;
332 priv->interfacePriv[0] = interfacePriv;
333
334
335#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
336 dev->netdev_ops = &uf_netdev_ops;
337#else
338 dev->open = uf_net_open;
339 dev->stop = uf_net_stop;
340 dev->hard_start_xmit = uf_net_xmit;
341 dev->do_ioctl = uf_net_ioctl;
342
343
344 dev->get_stats = uf_net_get_stats;
345
346 dev->set_multicast_list = uf_set_multicast_list;
347#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
348 dev->select_queue = uf_net_select_queue;
349#endif
350#endif
351
352#ifdef CSR_SUPPORT_WEXT
353 dev->wireless_handlers = &unifi_iw_handler_def;
354#if IW_HANDLER_VERSION < 6
355 dev->get_wireless_stats = unifi_get_wireless_stats;
356#endif
357#endif
358
359
360 dev->needed_headroom = 32;
361
362
363 priv->instance = bus_id;
364
365 priv->sdio = sdio_dev;
366
367 sdio_dev->driverData = (void*)priv;
368
369 priv->init_progress = UNIFI_INIT_NONE;
370
371 priv->prev_queue = 0;
372
373
374
375
376
377
378
379
380 ul_init_clients(priv);
381
382
383
384
385
386 priv->netdev_client = ul_register_client(priv,
387 0,
388 netdev_mlme_event_handler);
389 if (priv->netdev_client == NULL) {
390 unifi_error(priv,
391 "Failed to register a unifi client for background netdev processing\n");
392 free_netdev(priv->netdev[0]);
393 return NULL;
394 }
395 unifi_trace(priv, UDBG2, "Netdev %p client (id:%d s:0x%X) is registered\n",
396 dev, priv->netdev_client->client_id, priv->netdev_client->sender_id);
397
398 priv->sta_wmm_capabilities = 0;
399
400#if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_SUPPORT_SME))
401 priv->wapi_multicast_filter = 0;
402 priv->wapi_unicast_filter = 0;
403 priv->wapi_unicast_queued_pkt_filter = 0;
404#ifdef CSR_WIFI_SECURITY_WAPI_QOSCTRL_MIC_WORKAROUND
405 priv->isWapiConnection = FALSE;
406#endif
407#endif
408
409
410 interfacePriv->queueEnabled[0] = 1;
411 interfacePriv->queueEnabled[1] = 1;
412 interfacePriv->queueEnabled[2] = 1;
413 interfacePriv->queueEnabled[3] = 1;
414
415#ifdef CSR_SUPPORT_SME
416 priv->allPeerDozing = 0;
417#endif
418
419
420
421
422
423
424
425 if (use_5g) {
426 priv->if_index = CSR_INDEX_5G;
427 unifi_info(priv, "Using the 802.11a radio\n");
428 } else {
429 priv->if_index = CSR_INDEX_2G4;
430 }
431
432
433 priv->bh_thread.thread_task = NULL;
434 priv->bh_thread.block_thread = 1;
435 init_waitqueue_head(&priv->bh_thread.wakeup_q);
436 priv->bh_thread.wakeup_flag = 0;
437 sprintf(priv->bh_thread.name, "uf_bh_thread");
438
439
440 interfacePriv->connected = UnifiConnectedUnknown;
441
442#ifdef USE_DRIVER_LOCK
443#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)
444 sema_init(&priv->lock, 1);
445#else
446 init_MUTEX(&priv->lock);
447#endif
448#endif
449
450 spin_lock_init(&priv->send_signal_lock);
451
452 spin_lock_init(&priv->m4_lock);
453#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)
454 sema_init(&priv->ba_mutex, 1);
455#else
456 init_MUTEX(&priv->ba_mutex);
457#endif
458
459#if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_WIFI_SECURITY_WAPI_SW_ENCRYPTION))
460 spin_lock_init(&priv->wapi_lock);
461#endif
462
463#ifdef CSR_SUPPORT_SME
464 spin_lock_init(&priv->staRecord_lock);
465 spin_lock_init(&priv->tx_q_lock);
466#endif
467
468
469 priv->unifi_workqueue = create_singlethread_workqueue("unifi_workq");
470 if (priv->unifi_workqueue == NULL) {
471
472 ul_deregister_client(priv->netdev_client);
473 free_netdev(priv->netdev[0]);
474 return NULL;
475 }
476
477#ifdef CSR_SUPPORT_SME
478
479 INIT_WORK(&priv->multicast_list_task, uf_multicast_list_wq);
480
481
482 INIT_WORK(&interfacePriv->send_m4_ready_task, uf_send_m4_ready_wq);
483
484#if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_WIFI_SECURITY_WAPI_SW_ENCRYPTION))
485
486 INIT_WORK(&interfacePriv->send_pkt_to_encrypt, uf_send_pkt_to_encrypt);
487#endif
488#endif
489
490#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
491#ifdef CONFIG_NET_SCHED
492
493 register_qdisc(&uf_qdisc_ops);
494#endif
495#endif
496
497 priv->ref_count = 1;
498
499
500 priv->amp_client = NULL;
501 priv->coredump_mode = 0;
502 priv->ptest_mode = 0;
503 priv->wol_suspend = FALSE;
504 INIT_LIST_HEAD(&interfacePriv->rx_uncontrolled_list);
505 INIT_LIST_HEAD(&interfacePriv->rx_controlled_list);
506 sema_init(&priv->rx_q_sem, 1);
507
508#ifdef CSR_SUPPORT_WEXT
509 interfacePriv->netdev_callback_registered = FALSE;
510 interfacePriv->wait_netdev_change = FALSE;
511
512 if ((rc = register_netdevice_notifier(&uf_netdev_notifier)) == 0) {
513 interfacePriv->netdev_callback_registered = TRUE;
514 }
515 else {
516 unifi_warning(priv, "Failed to register netdevice notifier : %d %p\n", rc, dev);
517 }
518#endif
519
520#ifdef CSR_WIFI_SPLIT_PATCH
521
522 priv->pending_mode_set.common.destination = 0xaaaa;
523#endif
524
525 return priv;
526}
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555u8
556uf_alloc_netdevice_for_other_interfaces(unifi_priv_t *priv, u16 interfaceTag)
557{
558 struct net_device *dev;
559 netInterface_priv_t *interfacePriv;
560
561
562
563
564
565
566
567
568
569 UF_ALLOC_NETDEV(dev, sizeof(netInterface_priv_t), "%d", ether_setup, 1);
570 if (dev == NULL) {
571 return FALSE;
572 }
573
574 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
575 unifi_error(priv, "uf_alloc_netdevice_for_other_interfaces bad interfaceTag\n");
576 return FALSE;
577 }
578
579
580 interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
581 interfacePriv->privPtr = priv;
582 interfacePriv->InterfaceTag = interfaceTag;
583 priv->netdev[interfaceTag] = dev;
584 priv->interfacePriv[interfacePriv->InterfaceTag] = interfacePriv;
585
586
587 interfacePriv->connected = UnifiConnectedUnknown;
588 INIT_LIST_HEAD(&interfacePriv->rx_uncontrolled_list);
589 INIT_LIST_HEAD(&interfacePriv->rx_controlled_list);
590
591
592#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
593 dev->netdev_ops = &uf_netdev_ops;
594#else
595 dev->open = uf_net_open;
596 dev->stop = uf_net_stop;
597 dev->hard_start_xmit = uf_net_xmit;
598 dev->do_ioctl = uf_net_ioctl;
599
600
601 dev->get_stats = uf_net_get_stats;
602
603 dev->set_multicast_list = uf_set_multicast_list;
604#endif
605
606#ifdef CSR_SUPPORT_WEXT
607 dev->wireless_handlers = &unifi_iw_handler_def;
608#if IW_HANDLER_VERSION < 6
609 dev->get_wireless_stats = unifi_get_wireless_stats;
610#endif
611#endif
612 return TRUE;
613}
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631int
632uf_free_netdevice(unifi_priv_t *priv)
633{
634 int i;
635 unsigned long flags;
636
637 func_enter();
638
639 unifi_trace(priv, UDBG1, "uf_free_netdevice\n");
640
641 if (!priv) {
642 return -EINVAL;
643 }
644
645
646
647
648 uf_release_firmware_files(priv);
649
650#if (defined CSR_SUPPORT_SME) && (defined CSR_SUPPORT_WEXT)
651 if (priv->connection_config.mlmeAssociateReqInformationElements) {
652 kfree(priv->connection_config.mlmeAssociateReqInformationElements);
653 }
654 priv->connection_config.mlmeAssociateReqInformationElements = NULL;
655 priv->connection_config.mlmeAssociateReqInformationElementsLength = 0;
656
657 if (priv->mib_data.length) {
658 vfree(priv->mib_data.data);
659 }
660 priv->mib_data.data = NULL;
661 priv->mib_data.length = 0;
662
663#endif
664
665
666 spin_lock_irqsave(&priv->m4_lock, flags);
667 for (i = 0; i < CSR_WIFI_NUM_INTERFACES; i++) {
668 netInterface_priv_t *interfacePriv = priv->interfacePriv[i];
669 if (interfacePriv->m4_bulk_data.data_length > 0) {
670 unifi_trace(priv, UDBG5, "uf_free_netdevice: free M4 bulkdata %d\n", i);
671 unifi_net_data_free(priv, &interfacePriv->m4_bulk_data);
672 }
673 }
674 spin_unlock_irqrestore(&priv->m4_lock, flags);
675
676#if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_WIFI_SECURITY_WAPI_SW_ENCRYPTION))
677
678 spin_lock_irqsave(&priv->wapi_lock, flags);
679 for (i = 0; i < CSR_WIFI_NUM_INTERFACES; i++) {
680 netInterface_priv_t *interfacePriv = priv->interfacePriv[i];
681 if (interfacePriv->wapi_unicast_bulk_data.data_length > 0) {
682 unifi_trace(priv, UDBG5, "uf_free_netdevice: free WAPI PKT bulk data %d\n", i);
683 unifi_net_data_free(priv, &interfacePriv->wapi_unicast_bulk_data);
684 }
685 }
686 spin_unlock_irqrestore(&priv->wapi_lock, flags);
687#endif
688
689#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
690#ifdef CONFIG_NET_SCHED
691
692 unregister_qdisc(&uf_qdisc_ops);
693#endif
694#endif
695
696#ifdef CSR_SUPPORT_WEXT
697
698 unregister_netdevice_notifier(&uf_netdev_notifier);
699#endif
700
701#ifdef CSR_SUPPORT_SME
702
703#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
704 cancel_work_sync(&priv->multicast_list_task);
705#endif
706#endif
707
708 flush_workqueue(priv->unifi_workqueue);
709 destroy_workqueue(priv->unifi_workqueue);
710
711
712
713
714 for (i=CSR_WIFI_NUM_INTERFACES-1; i>=0; i--) {
715
716 if (priv->netdev[i]) {
717 unifi_error(priv, "uf_free_netdevice: netdev %d %p\n", i, priv->netdev[i]);
718 free_netdev(priv->netdev[i]);
719 }
720 }
721
722 func_exit();
723 return 0;
724}
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740static int
741uf_net_open(struct net_device *dev)
742{
743 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
744 unifi_priv_t *priv = interfacePriv->privPtr;
745
746 func_enter();
747
748
749 if (priv->init_progress != UNIFI_INIT_COMPLETED) {
750 unifi_warning(priv, "%s: unifi not ready, failing net_open\n", __FUNCTION__);
751 return -EINVAL;
752 }
753
754#if (defined CSR_NATIVE_LINUX) && (defined UNIFI_SNIFF_ARPHRD) && defined(CSR_SUPPORT_WEXT)
755
756
757
758
759
760
761
762 if (priv->wext_conf.mode == IW_MODE_MONITOR) {
763 int err;
764 err = uf_start_sniff(priv);
765 if (err) {
766 return err;
767 }
768 netif_carrier_on(dev);
769 }
770#endif
771
772#ifdef CSR_SUPPORT_WEXT
773 if (interfacePriv->wait_netdev_change) {
774 unifi_trace(priv, UDBG1, "%s: Waiting for NETDEV_CHANGE, assume connected\n",
775 __FUNCTION__);
776 interfacePriv->connected = UnifiConnected;
777 interfacePriv->wait_netdev_change = FALSE;
778 }
779#endif
780
781 UF_NETIF_TX_START_ALL_QUEUES(dev);
782
783 func_exit();
784 return 0;
785}
786
787
788static int
789uf_net_stop(struct net_device *dev)
790{
791#if defined(CSR_NATIVE_LINUX) && defined(UNIFI_SNIFF_ARPHRD) && defined(CSR_SUPPORT_WEXT)
792 netInterface_priv_t *interfacePriv = (netInterface_priv_t*)netdev_priv(dev);
793 unifi_priv_t *priv = interfacePriv->privPtr;
794
795 func_enter();
796
797
798 if (priv->wext_conf.mode == IW_MODE_MONITOR) {
799 if (priv->card) {
800 int err;
801 err = unifi_reset_state(priv, dev->dev_addr, 1);
802 if (err) {
803 return err;
804 }
805 }
806 }
807#else
808 func_enter();
809#endif
810
811 UF_NETIF_TX_STOP_ALL_QUEUES(dev);
812
813 func_exit();
814 return 0;
815}
816
817
818
819static int
820uf_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
821{
822 int rc;
823
824 rc = -EOPNOTSUPP;
825
826 return rc;
827}
828
829
830
831static struct net_device_stats *
832uf_net_get_stats(struct net_device *dev)
833{
834 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
835
836 return &interfacePriv->stats;
837}
838
839static CSR_PRIORITY uf_get_packet_priority(unifi_priv_t *priv, netInterface_priv_t *interfacePriv, struct sk_buff *skb, const int proto)
840{
841 CSR_PRIORITY priority = CSR_CONTENTION;
842
843 func_enter();
844 priority = (CSR_PRIORITY) (skb->priority >> 5);
845
846 if (priority == CSR_QOS_UP0) {
847
848 unifi_trace(priv, UDBG5, "uf_get_packet_priority: proto = 0x%.4X\n", proto);
849
850 switch (proto) {
851 case 0x0800:
852 case 0x814C:
853 case 0x880C:
854 priority = (CSR_PRIORITY) (skb->data[1 + ETH_HLEN] >> 5);
855 break;
856
857 case 0x8100:
858 priority = (CSR_PRIORITY) (skb->data[0 + ETH_HLEN] >> 5);
859 break;
860
861 case 0x86DD:
862 priority = (CSR_PRIORITY) ((skb->data[0 + ETH_HLEN] & 0x0E) >> 1);
863 break;
864
865 default:
866 priority = CSR_QOS_UP0;
867 break;
868 }
869 }
870
871
872
873 if (interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_STA ||
874 interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI) {
875 unifi_TrafficQueue queue;
876
877
878
879 queue = unifi_frame_priority_to_queue(priority);
880
881 while (queue > UNIFI_TRAFFIC_Q_BK && !interfacePriv->queueEnabled[queue]) {
882 queue--;
883 priority = unifi_get_default_downgrade_priority(queue);
884 }
885 }
886
887 unifi_trace(priv, UDBG5, "Packet priority = %d\n", priority);
888
889 func_exit();
890 return priority;
891}
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910CSR_PRIORITY
911get_packet_priority(unifi_priv_t *priv, struct sk_buff *skb, const struct ethhdr *ehdr, netInterface_priv_t *interfacePriv)
912{
913 CSR_PRIORITY priority = CSR_CONTENTION;
914 const int proto = ntohs(ehdr->h_proto);
915
916 u8 interfaceMode = interfacePriv->interfaceMode;
917
918 func_enter();
919
920
921 switch(interfaceMode)
922 {
923 case CSR_WIFI_ROUTER_CTRL_MODE_STA:
924 case CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI:
925 unifi_trace(priv, UDBG4, "mode is STA \n");
926 if ((priv->sta_wmm_capabilities & QOS_CAPABILITY_WMM_ENABLED) == 1) {
927 priority = uf_get_packet_priority(priv, interfacePriv, skb, proto);
928 } else {
929 priority = CSR_CONTENTION;
930 }
931 break;
932#ifdef CSR_SUPPORT_SME
933 case CSR_WIFI_ROUTER_CTRL_MODE_AP:
934 case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
935 case CSR_WIFI_ROUTER_CTRL_MODE_IBSS:
936 {
937 CsrWifiRouterCtrlStaInfo_t * dstStaInfo =
938 CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,ehdr->h_dest, interfacePriv->InterfaceTag);
939 unifi_trace(priv, UDBG4, "mode is AP \n");
940 if (!(ehdr->h_dest[0] & 0x01) && dstStaInfo && dstStaInfo->wmmOrQosEnabled) {
941
942 priority = uf_get_packet_priority(priv, interfacePriv, skb, proto);
943 } else {
944
945 unifi_trace(priv, UDBG4, "Destination is not QSTA or BroadCast/Multicast\n");
946 priority = CSR_CONTENTION;
947 }
948 }
949 break;
950#endif
951 default:
952 unifi_trace(priv, UDBG3, " mode unknown in %s func, mode=%x\n", __FUNCTION__, interfaceMode);
953 }
954 unifi_trace(priv, UDBG5, "priority = %x\n", priority);
955
956 func_exit();
957 return priority;
958}
959
960#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975static u16
976uf_net_select_queue(struct net_device *dev, struct sk_buff *skb)
977{
978 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
979 unifi_priv_t *priv = (unifi_priv_t *)interfacePriv->privPtr;
980 struct ethhdr ehdr;
981 unifi_TrafficQueue queue;
982 int proto;
983 CSR_PRIORITY priority;
984
985 func_enter();
986
987 memcpy(&ehdr, skb->data, ETH_HLEN);
988 proto = ntohs(ehdr.h_proto);
989
990
991 if ((proto != ETH_P_PAE)
992#ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
993 && (proto != ETH_P_WAI)
994#endif
995 ) {
996
997 priority = get_packet_priority(priv, skb, &ehdr, interfacePriv);
998 queue = unifi_frame_priority_to_queue(priority);
999 } else {
1000
1001 queue = UNIFI_TRAFFIC_Q_EAPOL;
1002 }
1003
1004
1005 func_exit();
1006 return (u16)queue;
1007}
1008#endif
1009
1010int
1011skb_add_llc_snap(struct net_device *dev, struct sk_buff *skb, int proto)
1012{
1013 llc_snap_hdr_t *snap;
1014 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1015 unifi_priv_t *priv = interfacePriv->privPtr;
1016 int headroom;
1017
1018
1019 headroom = skb_headroom(skb);
1020
1021
1022 if (proto < 0x600) {
1023
1024
1025 unifi_trace(priv, UDBG3, "802.3 len: %d\n", skb->len);
1026
1027
1028 skb_trim(skb, proto);
1029 } else if (proto == ETH_P_8021Q) {
1030
1031
1032 u16 vlan_snap = *(u16*)skb->data;
1033
1034 if (headroom < 14) {
1035 unifi_trace(priv, UDBG3, "cant append vlan snap: debug\n");
1036 return -1;
1037 }
1038
1039 snap = (llc_snap_hdr_t *)skb_push(skb, 4);
1040 snap->dsap = snap->ssap = 0xAA;
1041 snap->ctrl = 0x03;
1042 memcpy(snap->oui, oui_rfc1042, P80211_OUI_LEN);
1043
1044
1045 snap = (llc_snap_hdr_t *)skb_push(skb, 10);
1046 snap->dsap = snap->ssap = 0xAA;
1047 snap->ctrl = 0x03;
1048 memcpy(snap->oui, oui_rfc1042, P80211_OUI_LEN);
1049
1050
1051 snap->protocol = htons(proto);
1052 *(u16*)(snap + 1) = vlan_snap;
1053
1054 } else
1055 {
1056
1057 unifi_trace(priv, UDBG3, "DIXII len: %d\n", skb->len);
1058
1059
1060 if (headroom < sizeof(llc_snap_hdr_t)) {
1061 unifi_trace(priv, UDBG3, "cant append snap: debug\n");
1062 return -1;
1063 }
1064
1065 snap = (llc_snap_hdr_t *)skb_push(skb, sizeof(llc_snap_hdr_t));
1066 snap->dsap = snap->ssap = 0xAA;
1067 snap->ctrl = 0x03;
1068
1069 if ((proto == ETH_P_AARP) || (proto == ETH_P_IPX)) {
1070 memcpy(snap->oui, oui_8021h, P80211_OUI_LEN);
1071 } else {
1072 memcpy(snap->oui, oui_rfc1042, P80211_OUI_LEN);
1073 }
1074 snap->protocol = htons(proto);
1075 }
1076
1077 return 0;
1078}
1079
1080#ifdef CSR_SUPPORT_SME
1081static int
1082_identify_sme_ma_pkt_ind(unifi_priv_t *priv,
1083 const s8 *oui, u16 protocol,
1084 const CSR_SIGNAL *signal,
1085 bulk_data_param_t *bulkdata,
1086 const unsigned char *daddr,
1087 const unsigned char *saddr)
1088{
1089 CSR_MA_PACKET_INDICATION *pkt_ind = (CSR_MA_PACKET_INDICATION*)&signal->u.MaPacketIndication;
1090 int r;
1091 u8 i;
1092
1093 unifi_trace(priv, UDBG5,
1094 "_identify_sme_ma_pkt_ind -->\n");
1095 for (i = 0; i < MAX_MA_UNIDATA_IND_FILTERS; i++) {
1096 if (priv->sme_unidata_ind_filters[i].in_use) {
1097 if (!memcmp(oui, priv->sme_unidata_ind_filters[i].oui, 3) &&
1098 (protocol == priv->sme_unidata_ind_filters[i].protocol)) {
1099
1100
1101 if (priv->sme_cli) {
1102
1103
1104
1105
1106 unifi_trace(priv, UDBG1,
1107 "_identify_sme_ma_pkt_ind: handle=%d, encap=%d, proto=%x\n",
1108 i, priv->sme_unidata_ind_filters[i].encapsulation,
1109 priv->sme_unidata_ind_filters[i].protocol);
1110 if (priv->sme_unidata_ind_filters[i].encapsulation == CSR_WIFI_ROUTER_ENCAPSULATION_ETHERNET) {
1111 struct sk_buff *skb;
1112
1113 skb = (struct sk_buff*)bulkdata->d[0].os_net_buf_ptr;
1114 skb->len = bulkdata->d[0].data_length;
1115
1116 unifi_trace(priv, UDBG1,
1117 "_identify_sme_ma_pkt_ind: skb_80211_to_ether -->\n");
1118 r = skb_80211_to_ether(priv, skb, daddr, saddr,
1119 signal, bulkdata);
1120 unifi_trace(priv, UDBG1,
1121 "_identify_sme_ma_pkt_ind: skb_80211_to_ether <--\n");
1122 if (r) {
1123 return -EINVAL;
1124 }
1125
1126
1127 bulkdata->d[0].os_data_ptr = skb->data;
1128 bulkdata->d[0].data_length = skb->len;
1129 } else {
1130
1131 bulkdata->d[0].os_data_ptr -= 2*ETH_ALEN;
1132 bulkdata->d[0].data_length += 2*ETH_ALEN;
1133 memcpy((void*)bulkdata->d[0].os_data_ptr, daddr, ETH_ALEN);
1134 memcpy((void*)bulkdata->d[0].os_data_ptr + ETH_ALEN, saddr, ETH_ALEN);
1135 }
1136
1137 unifi_trace(priv, UDBG1,
1138 "_identify_sme_ma_pkt_ind: unifi_sys_ma_pkt_ind -->\n");
1139 CsrWifiRouterMaPacketIndSend(priv->sme_unidata_ind_filters[i].appHandle,
1140 (pkt_ind->VirtualInterfaceIdentifier & 0xff),
1141 i,
1142 pkt_ind->ReceptionStatus,
1143 bulkdata->d[0].data_length,
1144 (u8*)bulkdata->d[0].os_data_ptr,
1145 NULL,
1146 pkt_ind->Rssi,
1147 pkt_ind->Snr,
1148 pkt_ind->ReceivedRate);
1149
1150
1151 unifi_trace(priv, UDBG1,
1152 "_identify_sme_ma_pkt_ind: unifi_sys_ma_pkt_ind <--\n");
1153 }
1154
1155 return 1;
1156 }
1157 }
1158 }
1159
1160 return -1;
1161}
1162#endif
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183int
1184skb_80211_to_ether(unifi_priv_t *priv, struct sk_buff *skb,
1185 const unsigned char *daddr, const unsigned char *saddr,
1186 const CSR_SIGNAL *signal,
1187 bulk_data_param_t *bulkdata)
1188{
1189 unsigned char *payload;
1190 int payload_length;
1191 struct ethhdr *eth;
1192 llc_snap_hdr_t *snap;
1193 int headroom;
1194#define UF_VLAN_LLC_HEADER_SIZE 18
1195 static const u8 vlan_inner_snap[] = { 0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00 };
1196#if defined(CSR_NATIVE_SOFTMAC) && defined(CSR_SUPPORT_SME)
1197 const CSR_MA_PACKET_INDICATION *pkt_ind = &signal->u.MaPacketIndication;
1198#endif
1199
1200 if(skb== NULL || daddr == NULL || saddr == NULL){
1201 unifi_error(priv,"skb_80211_to_ether: PBC fail\n");
1202 return 1;
1203 }
1204
1205 payload = skb->data;
1206 payload_length = skb->len;
1207
1208 snap = (llc_snap_hdr_t *)payload;
1209 eth = (struct ethhdr *)payload;
1210
1211
1212 headroom = skb_headroom(skb);
1213
1214
1215
1216
1217 if ((payload_length >= sizeof(llc_snap_hdr_t)) &&
1218 (snap->dsap == 0xAA) &&
1219 (snap->ssap == 0xAA) &&
1220 (snap->ctrl == 0x03) &&
1221 (snap->oui[0] == 0) &&
1222 (snap->oui[1] == 0) &&
1223 ((snap->oui[2] == 0) || (snap->oui[2] == 0xF8)))
1224 {
1225
1226 if ((snap->oui[2] == 0) &&
1227 ((ntohs(snap->protocol) == ETH_P_AARP) || (ntohs(snap->protocol) == ETH_P_IPX)))
1228 {
1229 u16 len;
1230
1231 unifi_trace(priv, UDBG3, "%s len: %d\n",
1232 (ntohs(snap->protocol) == ETH_P_AARP) ? "ETH_P_AARP" : "ETH_P_IPX",
1233 payload_length);
1234
1235
1236 if (headroom < (2 * ETH_ALEN + 2)) {
1237 unifi_warning(priv, "headroom not available to skb_push ether header\n");
1238 return -1;
1239 }
1240
1241
1242 len = htons(skb->len);
1243 memcpy(skb_push(skb, 2), &len, 2);
1244 memcpy(skb_push(skb, ETH_ALEN), saddr, ETH_ALEN);
1245 memcpy(skb_push(skb, ETH_ALEN), daddr, ETH_ALEN);
1246
1247 return 0;
1248 }
1249
1250 if ((snap->oui[2] == 0) && (ntohs(snap->protocol) == ETH_P_8021Q))
1251 {
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261 u16 vlan_snap;
1262
1263 if (payload_length < UF_VLAN_LLC_HEADER_SIZE) {
1264 unifi_warning(priv, "VLAN SNAP header too short: %d bytes\n", payload_length);
1265 return -1;
1266 }
1267
1268 if (memcmp(payload + 10, vlan_inner_snap, 6)) {
1269 unifi_warning(priv, "VLAN malformatted SNAP header.\n");
1270 return -1;
1271 }
1272
1273 unifi_trace(priv, UDBG3, "VLAN SNAP: %02x-%02x\n", payload[8], payload[9]);
1274 unifi_trace(priv, UDBG3, "VLAN len: %d\n", payload_length);
1275
1276
1277
1278 vlan_snap = *((u16*)(payload + 8));
1279
1280
1281 eth->h_proto = snap->protocol;
1282
1283 memcpy(eth->h_dest, daddr, ETH_ALEN);
1284 memcpy(eth->h_source, saddr, ETH_ALEN);
1285 *(u16*)(eth + 1) = vlan_snap;
1286 return 0;
1287 }
1288
1289
1290 unifi_trace(priv, UDBG3, "SNAP+RFC1042 len: %d\n", payload_length);
1291
1292
1293 skb_pull(skb, sizeof(llc_snap_hdr_t));
1294
1295
1296
1297
1298
1299 eth = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1300 memcpy(eth->h_dest, daddr, ETH_ALEN);
1301 memcpy(eth->h_source, saddr, ETH_ALEN);
1302
1303 eth->h_proto = snap->protocol;
1304 } else {
1305 u16 len;
1306
1307
1308 if (headroom < (2 * ETH_ALEN + 2)) {
1309 unifi_warning(priv, "headroom not available to skb_push ether header\n");
1310 return -1;
1311 }
1312
1313 len = htons(skb->len);
1314 memcpy(skb_push(skb, 2), &len, 2);
1315 memcpy(skb_push(skb, ETH_ALEN), saddr, ETH_ALEN);
1316 memcpy(skb_push(skb, ETH_ALEN), daddr, ETH_ALEN);
1317
1318 return 1;
1319 }
1320
1321 return 0;
1322}
1323
1324
1325static CsrWifiRouterCtrlPortAction verify_port(unifi_priv_t *priv, unsigned char *address, int queue, u16 interfaceTag)
1326{
1327#ifdef CSR_NATIVE_LINUX
1328#ifdef CSR_SUPPORT_WEXT
1329 if (queue == UF_CONTROLLED_PORT_Q) {
1330 return priv->wext_conf.block_controlled_port;
1331 } else {
1332 return CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN;
1333 }
1334#else
1335 return CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN;
1336#endif
1337#else
1338 return uf_sme_port_state(priv, address, queue, interfaceTag);
1339#endif
1340}
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368int prepare_and_add_macheader(unifi_priv_t *priv, struct sk_buff *skb, struct sk_buff *newSkb,
1369 CSR_PRIORITY priority,
1370 bulk_data_param_t *bulkdata,
1371 u16 interfaceTag,
1372 const u8 *daddr,
1373 const u8 *saddr,
1374 u8 protection)
1375{
1376 u16 fc = 0;
1377 u8 qc = 0;
1378 u8 macHeaderLengthInBytes = MAC_HEADER_SIZE, *bufPtr = NULL;
1379 bulk_data_param_t data_ptrs;
1380 CsrResult csrResult;
1381 int headroom =0;
1382 u8 direction = 0;
1383 netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
1384 u8 *addressOne;
1385 u8 bQosNull = false;
1386
1387 if (skb == NULL) {
1388 unifi_error(priv,"prepare_and_add_macheader: Invalid SKB reference\n");
1389 return -1;
1390 }
1391
1392
1393 if (priority != CSR_CONTENTION) {
1394
1395 if (priority == CSR_MANAGEMENT) {
1396 fc |= cpu_to_le16(IEEE802_11_FC_TYPE_DATA);
1397 } else {
1398
1399 macHeaderLengthInBytes += QOS_CONTROL_HEADER_SIZE;
1400
1401 if (skb->len) {
1402
1403 fc |= cpu_to_le16(IEEE802_11_FC_TYPE_QOS_DATA);
1404 } else {
1405 fc |= cpu_to_le16(IEEE802_11_FC_TYPE_QOS_NULL);
1406 bQosNull = true;
1407 }
1408 }
1409 } else {
1410 if(skb->len == 0) {
1411 fc |= cpu_to_le16(IEEE802_11_FC_TYPE_NULL);
1412 } else {
1413 fc |= cpu_to_le16(IEEE802_11_FC_TYPE_DATA);
1414 }
1415 }
1416
1417 switch (interfacePriv->interfaceMode)
1418 {
1419 case CSR_WIFI_ROUTER_CTRL_MODE_STA:
1420 case CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI:
1421 direction = 2;
1422 fc |= cpu_to_le16(IEEE802_11_FC_TO_DS_MASK);
1423 break;
1424 case CSR_WIFI_ROUTER_CTRL_MODE_IBSS:
1425 direction = 0;
1426 break;
1427 case CSR_WIFI_ROUTER_CTRL_MODE_AP:
1428 case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
1429 direction = 1;
1430 fc |= cpu_to_le16(IEEE802_11_FC_FROM_DS_MASK);
1431 break;
1432 case CSR_WIFI_ROUTER_CTRL_MODE_AMP:
1433 if (priority == CSR_MANAGEMENT ) {
1434
1435 direction = 2;
1436 fc |= cpu_to_le16(IEEE802_11_FC_TO_DS_MASK);
1437 } else {
1438
1439 direction = 3;
1440 fc |= cpu_to_le16(IEEE802_11_FC_TO_DS_MASK | IEEE802_11_FC_FROM_DS_MASK);
1441 macHeaderLengthInBytes += 6;
1442 }
1443 break;
1444 default:
1445 unifi_warning(priv, "prepare_and_add_macheader: Unknown mode %d\n",
1446 interfacePriv->interfaceMode);
1447 }
1448
1449
1450
1451
1452
1453 if(protection) {
1454 fc |= cpu_to_le16(IEEE802_11_FC_PROTECTED_MASK);
1455 }
1456
1457
1458 headroom = skb_headroom(skb);
1459
1460 if (headroom < macHeaderLengthInBytes) {
1461 unifi_trace(priv, UDBG5,
1462 "prepare_and_add_macheader: Allocate headroom extra %d bytes\n",
1463 macHeaderLengthInBytes);
1464
1465 csrResult = unifi_net_data_malloc(priv, &data_ptrs.d[0], skb->len + macHeaderLengthInBytes);
1466
1467 if (csrResult != CSR_RESULT_SUCCESS) {
1468 unifi_error(priv, " failed to allocate request_data. in %s func\n", __FUNCTION__);
1469 return -1;
1470 }
1471 newSkb = (struct sk_buff *)(data_ptrs.d[0].os_net_buf_ptr);
1472 newSkb->len = skb->len + macHeaderLengthInBytes;
1473
1474 memcpy((void*)data_ptrs.d[0].os_data_ptr + macHeaderLengthInBytes,
1475 skb->data, skb->len);
1476
1477 bulkdata->d[0].os_data_ptr = newSkb->data;
1478 bulkdata->d[0].os_net_buf_ptr = (unsigned char*)newSkb;
1479 bulkdata->d[0].data_length = newSkb->len;
1480
1481 bufPtr = (u8*)data_ptrs.d[0].os_data_ptr;
1482
1483
1484 kfree_skb(skb);
1485 } else {
1486
1487
1488 bufPtr = (u8*)skb_push(skb, macHeaderLengthInBytes);
1489 bulkdata->d[0].os_data_ptr = skb->data;
1490 bulkdata->d[0].os_net_buf_ptr = (unsigned char*)skb;
1491 bulkdata->d[0].data_length = skb->len;
1492 }
1493
1494
1495
1496 memset(bufPtr, 0, macHeaderLengthInBytes);
1497
1498
1499 memcpy(bufPtr, &fc, sizeof(fc));
1500 bufPtr += sizeof(fc);
1501 macHeaderLengthInBytes -= sizeof(fc);
1502
1503
1504 bufPtr += 2;
1505 macHeaderLengthInBytes -= 2;
1506
1507 switch(direction)
1508 {
1509 case 0:
1510
1511
1512 memcpy(bufPtr, daddr, ETH_ALEN);
1513 bufPtr += ETH_ALEN;
1514 macHeaderLengthInBytes -= ETH_ALEN;
1515
1516
1517 memcpy(bufPtr, saddr, ETH_ALEN);
1518 bufPtr += ETH_ALEN;
1519 macHeaderLengthInBytes -= ETH_ALEN;
1520
1521
1522 memcpy(bufPtr, &interfacePriv->bssid, ETH_ALEN);
1523 bufPtr += ETH_ALEN;
1524 macHeaderLengthInBytes -= ETH_ALEN;
1525 break;
1526 case 1:
1527
1528 memcpy(bufPtr, daddr, ETH_ALEN);
1529 bufPtr += ETH_ALEN;
1530 macHeaderLengthInBytes -= ETH_ALEN;
1531
1532 memcpy(bufPtr, &interfacePriv->bssid, ETH_ALEN);
1533 bufPtr += ETH_ALEN;
1534 macHeaderLengthInBytes -= ETH_ALEN;
1535
1536
1537 memcpy(bufPtr, saddr, ETH_ALEN);
1538 bufPtr += ETH_ALEN;
1539 macHeaderLengthInBytes -= ETH_ALEN;
1540 break;
1541 case 2:
1542
1543 memcpy(bufPtr, &interfacePriv->bssid, ETH_ALEN);
1544 bufPtr += ETH_ALEN;
1545 macHeaderLengthInBytes -= ETH_ALEN;
1546
1547
1548 memcpy(bufPtr, saddr, ETH_ALEN);
1549 bufPtr += ETH_ALEN;
1550 macHeaderLengthInBytes -= ETH_ALEN;
1551
1552
1553 memcpy(bufPtr, daddr, ETH_ALEN);
1554 bufPtr += ETH_ALEN;
1555 macHeaderLengthInBytes -= ETH_ALEN;
1556 break;
1557 case 3:
1558 memcpy(bufPtr, &interfacePriv->bssid, ETH_ALEN);
1559 bufPtr += ETH_ALEN;
1560 macHeaderLengthInBytes -= ETH_ALEN;
1561
1562
1563 memcpy(bufPtr, saddr, ETH_ALEN);
1564 bufPtr += ETH_ALEN;
1565 macHeaderLengthInBytes -= ETH_ALEN;
1566
1567
1568 memcpy(bufPtr, daddr, ETH_ALEN);
1569 bufPtr += ETH_ALEN;
1570 macHeaderLengthInBytes -= ETH_ALEN;
1571 break;
1572 default:
1573 unifi_error(priv,"Unknown direction =%d : Not handled now\n",direction);
1574 return -1;
1575 }
1576
1577 bufPtr += 2;
1578 macHeaderLengthInBytes -= 2;
1579
1580 if (3 == direction) {
1581
1582 memcpy(bufPtr, saddr, ETH_ALEN);
1583 bufPtr += ETH_ALEN;
1584 macHeaderLengthInBytes -= ETH_ALEN;
1585 }
1586
1587
1588 if ((priority != CSR_CONTENTION) && (macHeaderLengthInBytes >= QOS_CONTROL_HEADER_SIZE)) {
1589
1590 if (priority > 7) {
1591 unifi_trace(priv, UDBG1, "data packets priority is more than 7, priority = %x\n", priority);
1592 qc |= 7;
1593 } else {
1594 qc |= priority;
1595 }
1596
1597
1598
1599
1600
1601 addressOne = bufPtr- ADDRESS_ONE_OFFSET;
1602
1603 if (addressOne[0] & 0x1) {
1604
1605 qc |= 1 << 5;
1606 }
1607
1608 if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_STA ||
1609 interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_IBSS ||
1610 interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI) {
1611
1612 } else {
1613 if(bQosNull) {
1614 qc |= 1 << 4;
1615 }
1616 }
1617
1618
1619 bufPtr[0] = qc;
1620
1621 bufPtr[1] = 0;
1622 macHeaderLengthInBytes -= QOS_CONTROL_HEADER_SIZE;
1623 }
1624 if (macHeaderLengthInBytes) {
1625 unifi_warning(priv, " Mac header not appended properly\n");
1626 return -1;
1627 }
1628 return 0;
1629}
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648static int
1649send_ma_pkt_request(unifi_priv_t *priv, struct sk_buff *skb, const struct ethhdr *ehdr, CSR_PRIORITY priority)
1650{
1651 int r;
1652 u16 i;
1653 u8 eapolStore = FALSE;
1654 struct sk_buff *newSkb = NULL;
1655 bulk_data_param_t bulkdata;
1656 const int proto = ntohs(ehdr->h_proto);
1657 u16 interfaceTag;
1658 CsrWifiMacAddress peerAddress;
1659 CSR_TRANSMISSION_CONTROL transmissionControl = CSR_NO_CONFIRM_REQUIRED;
1660 s8 protection;
1661 netInterface_priv_t *interfacePriv = NULL;
1662 CSR_RATE TransmitRate = (CSR_RATE)0;
1663
1664 unifi_trace(priv, UDBG5, "entering send_ma_pkt_request\n");
1665
1666
1667 for (i = 0; i < CSR_WIFI_NUM_INTERFACES; i++) {
1668 if (!memcmp(priv->netdev[i]->dev_addr, ehdr->h_source, ETH_ALEN)) {
1669 interfaceTag = i;
1670 interfacePriv = priv->interfacePriv[interfaceTag];
1671 break;
1672 }
1673 }
1674
1675 if (interfacePriv == NULL) {
1676
1677 interfaceTag = 0;
1678 interfacePriv = priv->interfacePriv[interfaceTag];
1679 unifi_warning(priv, "Mac address not matching ... debugging needed\n");
1680 interfacePriv->stats.tx_dropped++;
1681 kfree_skb(skb);
1682 return -1;
1683 }
1684
1685
1686 if (skb_add_llc_snap(priv->netdev[interfaceTag], skb, proto) != 0) {
1687
1688 unifi_error(priv, "skb_add_llc_snap failed.\n");
1689 kfree_skb(skb);
1690 return -1;
1691 }
1692
1693 bulkdata.d[0].os_data_ptr = skb->data;
1694 bulkdata.d[0].os_net_buf_ptr = (unsigned char*)skb;
1695 bulkdata.d[0].net_buf_length = bulkdata.d[0].data_length = skb->len;
1696 bulkdata.d[1].os_data_ptr = NULL;
1697 bulkdata.d[1].os_net_buf_ptr = NULL;
1698 bulkdata.d[1].net_buf_length = bulkdata.d[1].data_length = 0;
1699
1700#ifdef CSR_SUPPORT_SME
1701
1702 if ((interfacePriv->interfaceMode != CSR_WIFI_ROUTER_CTRL_MODE_AP) &&
1703 (interfacePriv->interfaceMode != CSR_WIFI_ROUTER_CTRL_MODE_P2PGO)) {
1704 unifi_ta_sample(priv->card, CSR_WIFI_ROUTER_CTRL_PROTOCOL_DIRECTION_TX,
1705 &bulkdata.d[0], ehdr->h_source,
1706 priv->netdev[interfaceTag]->dev_addr,
1707 jiffies_to_msecs(jiffies),
1708 0);
1709 }
1710#endif
1711
1712 if ((proto == ETH_P_PAE)
1713#ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
1714 || (proto == ETH_P_WAI)
1715#endif
1716 )
1717 {
1718
1719 if (0 == uf_verify_m4(priv, bulkdata.d[0].os_data_ptr, bulkdata.d[0].data_length)) {
1720 eapolStore = TRUE;
1721 }
1722 }
1723
1724#ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
1725 if (proto == ETH_P_WAI)
1726 {
1727 protection = 0;
1728 }
1729 else
1730 {
1731#endif
1732#ifdef CSR_SUPPORT_SME
1733 if ((protection = uf_get_protection_bit_from_interfacemode(priv, interfaceTag, ehdr->h_dest)) < 0) {
1734 unifi_warning(priv, "unicast address, but destination not in station record database\n");
1735 unifi_net_data_free(priv, &bulkdata.d[0]);
1736 return -1;
1737 }
1738#else
1739 protection = 0;
1740#endif
1741#ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
1742 }
1743#endif
1744
1745
1746 if (prepare_and_add_macheader(priv, skb, newSkb, priority, &bulkdata, interfaceTag, ehdr->h_dest, ehdr->h_source, protection)) {
1747 unifi_error(priv, "failed to create MAC header\n");
1748 unifi_net_data_free(priv, &bulkdata.d[0]);
1749 return -1;
1750 }
1751
1752
1753
1754
1755
1756 memcpy(peerAddress.a, ((u8 *) bulkdata.d[0].os_data_ptr) + 4, ETH_ALEN);
1757
1758 unifi_trace(priv, UDBG5, "RA[0]=%x, RA[1]=%x, RA[2]=%x, RA[3]=%x, RA[4]=%x, RA[5]=%x\n",
1759 peerAddress.a[0],peerAddress.a[1], peerAddress.a[2], peerAddress.a[3],
1760 peerAddress.a[4],peerAddress.a[5]);
1761
1762
1763 if ((proto == ETH_P_PAE)
1764#ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
1765 || (proto == ETH_P_WAI)
1766#endif
1767 )
1768 {
1769 CSR_SIGNAL signal;
1770 CSR_MA_PACKET_REQUEST *req = &signal.u.MaPacketRequest;
1771
1772
1773 memset(&signal, 0, sizeof(CSR_SIGNAL));
1774
1775
1776 signal.SignalPrimitiveHeader.SignalId = CSR_MA_PACKET_REQUEST_ID;
1777 signal.SignalPrimitiveHeader.ReceiverProcessId = 0;
1778 signal.SignalPrimitiveHeader.SenderProcessId = priv->netdev_client->sender_id;
1779
1780 transmissionControl = req->TransmissionControl = 0;
1781#ifdef CSR_SUPPORT_SME
1782 if (eapolStore)
1783 {
1784 netInterface_priv_t *netpriv = (netInterface_priv_t *)netdev_priv(priv->netdev[interfaceTag]);
1785
1786
1787
1788 req->Priority = priority;
1789 unifi_trace(priv, UDBG3, "Tx Frame with Priority: %x\n", req->Priority);
1790
1791
1792 req->TransmitRate = 0;
1793 req->HostTag = CSR_WIFI_EAPOL_M4_HOST_TAG;
1794
1795 memcpy(req->Ra.x, ((u8 *) bulkdata.d[0].os_data_ptr) + 4, ETH_ALEN);
1796
1797 spin_lock(&priv->m4_lock);
1798
1799 interfacePriv->m4_signal = signal;
1800 interfacePriv->m4_bulk_data.net_buf_length = bulkdata.d[0].net_buf_length;
1801 interfacePriv->m4_bulk_data.data_length = bulkdata.d[0].data_length;
1802 interfacePriv->m4_bulk_data.os_data_ptr = bulkdata.d[0].os_data_ptr;
1803 interfacePriv->m4_bulk_data.os_net_buf_ptr = bulkdata.d[0].os_net_buf_ptr;
1804 spin_unlock(&priv->m4_lock);
1805
1806
1807
1808
1809
1810 queue_work(priv->unifi_workqueue, &netpriv->send_m4_ready_task);
1811
1812 return 0;
1813 }
1814#endif
1815 }
1816
1817#if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_WIFI_SECURITY_WAPI_SW_ENCRYPTION))
1818 if ((CSR_WIFI_ROUTER_CTRL_MODE_STA == interfacePriv->interfaceMode) && \
1819 (priv->wapi_unicast_filter) && \
1820 (proto != ETH_P_PAE) && \
1821 (proto != ETH_P_WAI) && \
1822 (skb->len > 0))
1823 {
1824 CSR_SIGNAL signal;
1825 CSR_MA_PACKET_REQUEST *req = &signal.u.MaPacketRequest;
1826 netInterface_priv_t *netpriv = (netInterface_priv_t *)netdev_priv(priv->netdev[interfaceTag]);
1827
1828 unifi_trace(priv, UDBG4, "send_ma_pkt_request() - WAPI unicast data packet when USKID = 1 \n");
1829
1830
1831 memset(&signal, 0, sizeof(CSR_SIGNAL));
1832
1833 signal.SignalPrimitiveHeader.SignalId = CSR_MA_PACKET_REQUEST_ID;
1834 signal.SignalPrimitiveHeader.ReceiverProcessId = 0;
1835 signal.SignalPrimitiveHeader.SenderProcessId = priv->netdev_client->sender_id;
1836
1837
1838 req->TransmissionControl = 0;
1839 req->Priority = priority;
1840 unifi_trace(priv, UDBG3, "Tx Frame with Priority: %x\n", req->Priority);
1841 req->TransmitRate = (CSR_RATE) 0;
1842 req->HostTag = 0xffffffff;
1843
1844 memcpy(req->Ra.x, ((u8 *) bulkdata.d[0].os_data_ptr) + 4, ETH_ALEN);
1845
1846
1847 spin_lock(&priv->wapi_lock);
1848 interfacePriv->wapi_unicast_ma_pkt_sig = signal;
1849 interfacePriv->wapi_unicast_bulk_data.net_buf_length = bulkdata.d[0].net_buf_length;
1850 interfacePriv->wapi_unicast_bulk_data.data_length = bulkdata.d[0].data_length;
1851 interfacePriv->wapi_unicast_bulk_data.os_data_ptr = bulkdata.d[0].os_data_ptr;
1852 interfacePriv->wapi_unicast_bulk_data.os_net_buf_ptr = bulkdata.d[0].os_net_buf_ptr;
1853 spin_unlock(&priv->wapi_lock);
1854
1855
1856
1857
1858
1859 queue_work(priv->unifi_workqueue, &netpriv->send_pkt_to_encrypt);
1860
1861 return 0;
1862 }
1863#endif
1864
1865 if(priv->cmanrTestMode)
1866 {
1867 TransmitRate = priv->cmanrTestModeTransmitRate;
1868 unifi_trace(priv, UDBG2, "send_ma_pkt_request: cmanrTestModeTransmitRate = %d TransmitRate=%d\n",
1869 priv->cmanrTestModeTransmitRate,
1870 TransmitRate
1871 );
1872 }
1873
1874
1875
1876 r = uf_process_ma_packet_req(priv,
1877 peerAddress.a,
1878 0xffffffff,
1879 interfaceTag,
1880 transmissionControl,
1881 TransmitRate,
1882 priority,
1883 priv->netdev_client->sender_id,
1884 &bulkdata);
1885
1886 if (r) {
1887 unifi_trace(priv, UDBG1, "(HIP validation failure) r = %x\n", r);
1888 unifi_net_data_free(priv, &bulkdata.d[0]);
1889 return -1;
1890 }
1891
1892 unifi_trace(priv, UDBG3, "leaving send_ma_pkt_request, UNITDATA result code = %d\n", r);
1893
1894 return r;
1895}
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
1919static netdev_tx_t
1920#else
1921static int
1922#endif
1923uf_net_xmit(struct sk_buff *skb, struct net_device *dev)
1924{
1925 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1926 unifi_priv_t *priv = interfacePriv->privPtr;
1927 struct ethhdr ehdr;
1928 int proto, port;
1929 int result;
1930 static tx_signal_handler tx_handler;
1931 CSR_PRIORITY priority;
1932#if !defined (CONFIG_NET_SCHED) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
1933 CsrWifiRouterCtrlPortAction port_action;
1934#endif
1935
1936 func_enter();
1937
1938 unifi_trace(priv, UDBG5, "unifi_net_xmit: skb = %x\n", skb);
1939
1940 memcpy(&ehdr, skb->data, ETH_HLEN);
1941 proto = ntohs(ehdr.h_proto);
1942 priority = get_packet_priority(priv, skb, &ehdr, interfacePriv);
1943
1944
1945 tx_handler = send_ma_pkt_request;
1946
1947
1948 if ((proto != ETH_P_PAE)
1949#ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
1950 && (proto != ETH_P_WAI)
1951#endif
1952 ) {
1953 port = UF_CONTROLLED_PORT_Q;
1954 } else {
1955
1956 port = UF_UNCONTROLLED_PORT_Q;
1957 }
1958
1959#if defined (CONFIG_NET_SCHED) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28))
1960
1961 skb_pull(skb, ETH_HLEN);
1962 result = tx_handler(priv, skb, &ehdr, priority);
1963#else
1964
1965 port_action = verify_port(priv
1966 , (((CSR_WIFI_ROUTER_CTRL_MODE_STA == interfacePriv->interfaceMode)||(CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI== interfacePriv->interfaceMode))? interfacePriv->bssid.a: ehdr.h_dest)
1967 , port
1968 , interfacePriv->InterfaceTag);
1969
1970 if (port_action == CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN) {
1971 unifi_trace(priv, UDBG5,
1972 "uf_net_xmit: %s controlled port open\n",
1973 port ? "" : "un");
1974
1975 skb_pull(skb, ETH_HLEN);
1976 result = tx_handler(priv, skb, &ehdr, priority);
1977 } else {
1978
1979
1980 unifi_trace(priv, UDBG2,
1981 "uf_net_xmit: %s controlled port %s\n",
1982 port ? "" : "un", port_action==CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_BLOCK ? "blocked" : "closed");
1983 interfacePriv->stats.tx_dropped++;
1984 kfree_skb(skb);
1985
1986 func_exit();
1987 return NETDEV_TX_OK;
1988 }
1989#endif
1990
1991 if (result == NETDEV_TX_OK) {
1992#if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_WIFI_SECURITY_WAPI_SW_ENCRYPTION))
1993
1994 if (!((CSR_WIFI_ROUTER_CTRL_MODE_STA == interfacePriv->interfaceMode) &&
1995 (priv->wapi_unicast_filter == 1)))
1996 {
1997 dev->trans_start = jiffies;
1998
1999
2000
2001 interfacePriv->stats.tx_packets++;
2002
2003 interfacePriv->stats.tx_bytes += skb->len;
2004
2005 }
2006#else
2007 dev->trans_start = jiffies;
2008
2009
2010
2011
2012
2013 interfacePriv->stats.tx_packets++;
2014
2015 interfacePriv->stats.tx_bytes += skb->len;
2016#endif
2017 } else if (result < 0) {
2018
2019
2020
2021
2022
2023 interfacePriv->stats.tx_dropped++;
2024 unifi_trace(priv, UDBG1, "unifi_net_xmit: (Packet Drop), dropped count = %x\n", interfacePriv->stats.tx_dropped);
2025 result = NETDEV_TX_OK;
2026 }
2027
2028
2029
2030 func_exit();
2031 return result;
2032}
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053void
2054unifi_pause_xmit(void *ospriv, unifi_TrafficQueue queue)
2055{
2056 unifi_priv_t *priv = ospriv;
2057 int i;
2058
2059 func_enter();
2060 unifi_trace(priv, UDBG2, "Stopping queue %d\n", queue);
2061
2062#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
2063 for(i=0;i<CSR_WIFI_NUM_INTERFACES;i++)
2064 {
2065 if (netif_running(priv->netdev[i]))
2066 {
2067 netif_stop_subqueue(priv->netdev[i], (u16)queue);
2068 }
2069 }
2070#else
2071#ifdef ALLOW_Q_PAUSE
2072 unifi_trace(priv, UDBG2, "Stopping netif\n");
2073
2074 for(i=0;i<CSR_WIFI_NUM_INTERFACES;i++)
2075 {
2076 if (netif_running(priv->netdev[i])) {
2077 UF_NETIF_TX_STOP_ALL_QUEUES(priv->netdev[i]);
2078 }
2079 }
2080#else
2081 if (net_is_tx_q_paused(priv, queue)) {
2082 unifi_trace(priv, UDBG2, "Queue already stopped\n");
2083 return;
2084 }
2085 net_tx_q_pause(priv, queue);
2086#endif
2087#endif
2088
2089#ifdef CSR_SUPPORT_SME
2090 if(queue<=3) {
2091 routerStartBuffering(priv,queue);
2092 unifi_trace(priv,UDBG2,"Start buffering %d\n", queue);
2093 } else {
2094 routerStartBuffering(priv,0);
2095 unifi_error(priv, "Start buffering %d defaulting to 0\n", queue);
2096 }
2097#endif
2098 func_exit();
2099
2100}
2101
2102void
2103unifi_restart_xmit(void *ospriv, unifi_TrafficQueue queue)
2104{
2105 unifi_priv_t *priv = ospriv;
2106 int i=0;
2107
2108 func_enter();
2109 unifi_trace(priv, UDBG2, "Waking queue %d\n", queue);
2110
2111#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
2112 for(i=0;i<CSR_WIFI_NUM_INTERFACES;i++)
2113 {
2114 if (netif_running(priv->netdev[i]))
2115 {
2116 netif_wake_subqueue(priv->netdev[i], (u16)queue);
2117 }
2118 }
2119#else
2120#ifdef ALLOW_Q_PAUSE
2121
2122
2123 for(i=0;i<CSR_WIFI_NUM_INTERFACES;i++)
2124 {
2125 if (netif_running(priv->netdev[i])) {
2126 UF_NETIF_TX_WAKE_ALL_QUEUES(priv->netdev[i]);
2127 }
2128 }
2129#else
2130 if (!(net_is_tx_q_paused(priv, queue))) {
2131 unifi_trace(priv, UDBG2, "Queue already running\n");
2132 func_exit();
2133 return;
2134 }
2135 net_tx_q_unpause(priv, queue);
2136#endif
2137#endif
2138
2139#ifdef CSR_SUPPORT_SME
2140 if(queue <=3) {
2141 routerStopBuffering(priv,queue);
2142 uf_send_buffered_frames(priv,queue);
2143 } else {
2144 routerStopBuffering(priv,0);
2145 uf_send_buffered_frames(priv,0);
2146 }
2147#endif
2148 func_exit();
2149}
2150
2151
2152static void
2153indicate_rx_skb(unifi_priv_t *priv, u16 ifTag, u8* dst_a, u8* src_a, struct sk_buff *skb, CSR_SIGNAL *signal,
2154 bulk_data_param_t *bulkdata)
2155{
2156 int r, sr = 0;
2157 struct net_device *dev;
2158
2159#ifdef CSR_SUPPORT_SME
2160 llc_snap_hdr_t *snap;
2161
2162 snap = (llc_snap_hdr_t *)skb->data;
2163
2164 sr = _identify_sme_ma_pkt_ind(priv,
2165 snap->oui, ntohs(snap->protocol),
2166 signal,
2167 bulkdata,
2168 dst_a, src_a );
2169#endif
2170
2171
2172
2173
2174
2175
2176 r = skb_80211_to_ether(priv, skb, dst_a, src_a,
2177 signal, bulkdata);
2178 if (r == -1) {
2179
2180 priv->interfacePriv[ifTag]->stats.rx_errors++;
2181 priv->interfacePriv[ifTag]->stats.rx_frame_errors++;
2182 unifi_net_data_free(priv, &bulkdata->d[0]);
2183 unifi_notice(priv, "indicate_rx_skb: Discard unknown frame.\n");
2184 func_exit();
2185 return;
2186 }
2187
2188
2189
2190
2191
2192 if (r == 1 && sr == 1) {
2193 unifi_net_data_free(priv, &bulkdata->d[0]);
2194 unifi_trace(priv, UDBG5, "indicate_rx_skb: Data given to subscription"
2195 "API, not being given to kernel\n");
2196 func_exit();
2197 return;
2198 }
2199
2200 dev = priv->netdev[ifTag];
2201
2202
2203 skb->dev = dev;
2204 skb->protocol = eth_type_trans(skb, dev);
2205 skb->ip_summed = CHECKSUM_UNNECESSARY;
2206
2207
2208 if (skb->len > (dev->mtu + ETH_HLEN)) {
2209
2210
2211 unifi_error(priv, "%s: oversize frame (%d > %d)\n",
2212 dev->name,
2213 skb->len, dev->mtu + ETH_HLEN);
2214
2215
2216 priv->interfacePriv[ifTag]->stats.rx_errors++;
2217 priv->interfacePriv[ifTag]->stats.rx_length_errors++;
2218 unifi_net_data_free(priv, &bulkdata->d[0]);
2219 func_exit();
2220 return;
2221 }
2222
2223
2224 if(priv->cmanrTestMode)
2225 {
2226 const CSR_MA_PACKET_INDICATION *pkt_ind = &signal->u.MaPacketIndication;
2227 priv->cmanrTestModeTransmitRate = pkt_ind->ReceivedRate;
2228 unifi_trace(priv, UDBG2, "indicate_rx_skb: cmanrTestModeTransmitRate=%d\n", priv->cmanrTestModeTransmitRate);
2229 }
2230
2231
2232#ifdef CSR_WIFI_USE_NETIF_RX
2233 netif_rx(skb);
2234#else
2235 netif_rx_ni(skb);
2236#endif
2237
2238 if (dev != NULL) {
2239 dev->last_rx = jiffies;
2240 }
2241
2242
2243 priv->interfacePriv[ifTag]->stats.rx_packets++;
2244 priv->interfacePriv[ifTag]->stats.rx_bytes += bulkdata->d[0].data_length;
2245
2246 func_exit();
2247 return;
2248}
2249
2250void
2251uf_process_rx_pending_queue(unifi_priv_t *priv, int queue,
2252 CsrWifiMacAddress source_address,
2253 int indicate, u16 interfaceTag)
2254{
2255 rx_buffered_packets_t *rx_q_item;
2256 struct list_head *rx_list;
2257 struct list_head *n;
2258 struct list_head *l_h;
2259 static const CsrWifiMacAddress broadcast_address = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
2260 netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
2261
2262 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
2263 unifi_error(priv, "uf_process_rx_pending_queue bad interfaceTag\n");
2264 return;
2265 }
2266
2267 if (queue == UF_CONTROLLED_PORT_Q) {
2268 rx_list = &interfacePriv->rx_controlled_list;
2269 } else {
2270 rx_list = &interfacePriv->rx_uncontrolled_list;
2271 }
2272
2273 down(&priv->rx_q_sem);
2274 list_for_each_safe(l_h, n, rx_list) {
2275 rx_q_item = list_entry(l_h, rx_buffered_packets_t, q);
2276
2277
2278 if (memcmp(broadcast_address.a, source_address.a, ETH_ALEN) &&
2279 memcmp(rx_q_item->sa.a, source_address.a, ETH_ALEN)) {
2280
2281 unifi_trace(priv, UDBG2,
2282 "uf_process_rx_pending_queue: Skipping sa=%02X%02X%02X%02X%02X%02X skb=%p, bulkdata=%p\n",
2283 rx_q_item->sa.a[0], rx_q_item->sa.a[1],
2284 rx_q_item->sa.a[2], rx_q_item->sa.a[3],
2285 rx_q_item->sa.a[4], rx_q_item->sa.a[5],
2286 rx_q_item->skb, &rx_q_item->bulkdata.d[0]);
2287 continue;
2288 }
2289
2290 list_del(l_h);
2291
2292
2293 unifi_trace(priv, UDBG2,
2294 "uf_process_rx_pending_queue: Was Blocked skb=%p, bulkdata=%p\n",
2295 rx_q_item->skb, &rx_q_item->bulkdata);
2296
2297 if (indicate) {
2298 indicate_rx_skb(priv, interfaceTag, rx_q_item->da.a, rx_q_item->sa.a, rx_q_item->skb, &rx_q_item->signal, &rx_q_item->bulkdata);
2299 } else {
2300 interfacePriv->stats.rx_dropped++;
2301 unifi_net_data_free(priv, &rx_q_item->bulkdata.d[0]);
2302 }
2303
2304
2305 kfree(rx_q_item);
2306 }
2307 up(&priv->rx_q_sem);
2308}
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325void
2326uf_resume_data_plane(unifi_priv_t *priv, int queue,
2327 CsrWifiMacAddress peer_address,
2328 u16 interfaceTag)
2329{
2330#ifdef CSR_SUPPORT_WEXT
2331 netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
2332#endif
2333
2334 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
2335 unifi_error(priv, "uf_resume_data_plane bad interfaceTag\n");
2336 return;
2337 }
2338
2339 unifi_trace(priv, UDBG2, "Resuming netif\n");
2340
2341
2342
2343
2344
2345
2346#ifdef CSR_SUPPORT_WEXT
2347 if (!interfacePriv->wait_netdev_change)
2348#endif
2349 {
2350#ifdef CONFIG_NET_SCHED
2351 if (netif_running(priv->netdev[interfaceTag])) {
2352#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
2353 netif_tx_schedule_all(priv->netdev[interfaceTag]);
2354#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
2355 netif_schedule_queue(netdev_get_tx_queue(priv->netdev[interfaceTag], 0));
2356#else
2357 netif_schedule(priv->netdev[interfaceTag]);
2358#endif
2359 }
2360#endif
2361 uf_process_rx_pending_queue(priv, queue, peer_address, 1,interfaceTag);
2362 }
2363}
2364
2365
2366void uf_free_pending_rx_packets(unifi_priv_t *priv, int queue, CsrWifiMacAddress peer_address,u16 interfaceTag)
2367{
2368 uf_process_rx_pending_queue(priv, queue, peer_address, 0,interfaceTag);
2369
2370}
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387static void
2388unifi_rx(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata)
2389{
2390 u16 interfaceTag;
2391 bulk_data_desc_t *pData;
2392 const CSR_MA_PACKET_INDICATION *pkt_ind = &signal->u.MaPacketIndication;
2393 struct sk_buff *skb;
2394 CsrWifiRouterCtrlPortAction port_action;
2395 u8 dataFrameType;
2396 int proto;
2397 int queue;
2398
2399 u8 da[ETH_ALEN], sa[ETH_ALEN];
2400 u8 toDs, fromDs, frameType, macHeaderLengthInBytes = MAC_HEADER_SIZE;
2401 u16 frameControl;
2402 netInterface_priv_t *interfacePriv;
2403 struct ethhdr ehdr;
2404
2405 func_enter();
2406
2407 interfaceTag = (pkt_ind->VirtualInterfaceIdentifier & 0xff);
2408 interfacePriv = priv->interfacePriv[interfaceTag];
2409
2410
2411 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES)
2412 {
2413 unifi_error(priv, "%s: MA-PACKET indication with bad interfaceTag %d\n", __FUNCTION__, interfaceTag);
2414 unifi_net_data_free(priv,&bulkdata->d[0]);
2415 func_exit();
2416 return;
2417 }
2418
2419
2420 if (!interfacePriv->netdev_registered)
2421 {
2422 unifi_error(priv, "%s: MA-PACKET indication with unallocated interfaceTag %d\n", __FUNCTION__, interfaceTag);
2423 unifi_net_data_free(priv, &bulkdata->d[0]);
2424 func_exit();
2425 return;
2426 }
2427
2428 if (bulkdata->d[0].data_length == 0) {
2429 unifi_warning(priv, "%s: MA-PACKET indication with zero bulk data\n", __FUNCTION__);
2430 unifi_net_data_free(priv,&bulkdata->d[0]);
2431 func_exit();
2432 return;
2433 }
2434
2435
2436 skb = (struct sk_buff*)bulkdata->d[0].os_net_buf_ptr;
2437 skb->len = bulkdata->d[0].data_length;
2438
2439
2440 toDs = (skb->data[1] & 0x01) ? 1 : 0;
2441 fromDs = (skb->data[1] & 0x02) ? 1 : 0;
2442
2443 memcpy(da,(skb->data+4+toDs*12),ETH_ALEN);
2444 memcpy(sa,(skb->data+10+fromDs*(6+toDs*8)),ETH_ALEN);
2445
2446
2447 pData = &bulkdata->d[0];
2448 frameControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr);
2449 frameType = ((frameControl & 0x000C) >> 2);
2450
2451 dataFrameType =((frameControl & 0x00f0) >> 4);
2452 unifi_trace(priv, UDBG6,
2453 "%s: Receive Data Frame Type %d \n", __FUNCTION__,dataFrameType);
2454
2455 switch(dataFrameType)
2456 {
2457 case QOS_DATA:
2458 case QOS_DATA_NULL:
2459
2460 if (fromDs && toDs)
2461 {
2462
2463 macHeaderLengthInBytes += (QOS_CONTROL_HEADER_SIZE + 6);
2464 }
2465 else
2466 {
2467 macHeaderLengthInBytes += QOS_CONTROL_HEADER_SIZE;
2468 }
2469
2470
2471 if (frameControl & FRAME_CONTROL_ORDER_BIT)
2472 macHeaderLengthInBytes += HT_CONTROL_HEADER_SIZE;
2473 break;
2474 default:
2475 if (fromDs && toDs)
2476 macHeaderLengthInBytes += 6;
2477 }
2478
2479
2480 switch(dataFrameType)
2481 {
2482 case DATA_NULL:
2483 case QOS_DATA_NULL:
2484
2485
2486
2487 proto = 0x0;
2488 break;
2489 default:
2490 {
2491 llc_snap_hdr_t *snap;
2492
2493
2494
2495 snap = (llc_snap_hdr_t *) (skb->data + macHeaderLengthInBytes);
2496
2497
2498 ehdr.h_proto = snap->protocol;
2499 memcpy(ehdr.h_dest, da, ETH_ALEN);
2500 memcpy(ehdr.h_source, sa, ETH_ALEN);
2501 }
2502 proto = ntohs(ehdr.h_proto);
2503 }
2504 unifi_trace(priv, UDBG3, "in unifi_rx protocol from snap header = 0x%x\n", proto);
2505
2506 if ((proto != ETH_P_PAE)
2507#ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
2508 && (proto != ETH_P_WAI)
2509#endif
2510 ) {
2511 queue = UF_CONTROLLED_PORT_Q;
2512 } else {
2513 queue = UF_UNCONTROLLED_PORT_Q;
2514 }
2515
2516 port_action = verify_port(priv, (unsigned char*)sa, queue, interfaceTag);
2517 unifi_trace(priv, UDBG3, "in unifi_rx port action is = 0x%x & queue = %x\n", port_action, queue);
2518
2519#ifdef CSR_SUPPORT_SME
2520
2521 if((interfacePriv->interfaceMode != CSR_WIFI_ROUTER_CTRL_MODE_AP) &&
2522 (interfacePriv->interfaceMode != CSR_WIFI_ROUTER_CTRL_MODE_P2PGO))
2523 {
2524
2525 skb_pull(skb, macHeaderLengthInBytes);
2526 pData->os_data_ptr = skb->data;
2527 pData->data_length -= macHeaderLengthInBytes;
2528
2529 if (pData->data_length) {
2530 unifi_ta_sample(priv->card, CSR_WIFI_ROUTER_CTRL_PROTOCOL_DIRECTION_RX,
2531 &bulkdata->d[0],
2532 sa, priv->netdev[interfaceTag]->dev_addr,
2533 jiffies_to_msecs(jiffies),
2534 pkt_ind->ReceivedRate);
2535 }
2536 } else {
2537
2538
2539 CsrWifiRouterCtrlStaInfo_t * srcStaInfo =
2540 CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,sa,interfaceTag);
2541
2542
2543
2544
2545 if(srcStaInfo == NULL) {
2546 CsrWifiMacAddress peerMacAddress;
2547
2548 memcpy(peerMacAddress.a,sa,ETH_ALEN);
2549 unifi_trace(priv, UDBG1, "%s: Unexpected frame from peer = %x:%x:%x:%x:%x:%x\n", __FUNCTION__,
2550 sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]);
2551 CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress);
2552 unifi_net_data_free(priv, &bulkdata->d[0]);
2553 func_exit();
2554 return;
2555 }
2556
2557
2558 if (port_action != CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN) {
2559
2560 CsrWifiMacAddress peerMacAddress;
2561 memcpy(peerMacAddress.a,sa,ETH_ALEN);
2562 unifi_trace(priv, UDBG3, "%s: Port is not open: unexpected frame from peer = %x:%x:%x:%x:%x:%x\n",
2563 __FUNCTION__, sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]);
2564
2565 CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress);
2566 interfacePriv->stats.rx_dropped++;
2567 unifi_net_data_free(priv, &bulkdata->d[0]);
2568 unifi_notice(priv, "%s: Dropping packet, proto=0x%04x, %s port\n", __FUNCTION__,
2569 proto, queue ? "Controlled" : "Un-controlled");
2570 func_exit();
2571 return;
2572 }
2573
2574
2575 if((dataFrameType == QOS_DATA_NULL) || (dataFrameType == DATA_NULL)){
2576 unifi_trace(priv, UDBG5, "%s: Null Frame Received and Freed\n", __FUNCTION__);
2577 unifi_net_data_free(priv, &bulkdata->d[0]);
2578 func_exit();
2579 return;
2580 }
2581
2582
2583
2584
2585
2586
2587
2588 if(!(uf_ap_process_data_pdu(priv, skb, &ehdr, srcStaInfo,
2589 signal,
2590 bulkdata,
2591 macHeaderLengthInBytes)))
2592 {
2593 func_exit();
2594 return;
2595 }
2596 unifi_trace(priv, UDBG5, "unifi_rx: no specific AP handling process as normal frame, MAC Header len %d\n",macHeaderLengthInBytes);
2597
2598 skb_pull(skb, macHeaderLengthInBytes);
2599 pData->os_data_ptr = skb->data;
2600 pData->data_length -= macHeaderLengthInBytes;
2601 pData->os_net_buf_ptr = (unsigned char*)skb;
2602 pData->net_buf_length = skb->len;
2603 }
2604#endif
2605
2606
2607
2608
2609
2610 if (pData->data_length == 0) {
2611 if (((frameControl & 0x00f0) >> 4) != QOS_DATA_NULL &&
2612 ((frameControl & 0x00f0) >> 4) != DATA_NULL) {
2613 unifi_trace(priv, UDBG1, "Zero length frame, but not null-data %04x\n", frameControl);
2614 }
2615 unifi_net_data_free(priv, &bulkdata->d[0]);
2616 func_exit();
2617 return;
2618 }
2619
2620 if (port_action == CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_DISCARD) {
2621
2622 interfacePriv->stats.rx_dropped++;
2623 unifi_net_data_free(priv, &bulkdata->d[0]);
2624 unifi_notice(priv, "%s: Dropping packet, proto=0x%04x, %s port\n",
2625 __FUNCTION__, proto, queue ? "controlled" : "uncontrolled");
2626 func_exit();
2627 return;
2628 } else if ( (port_action == CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_BLOCK) ||
2629 (interfacePriv->connected != UnifiConnected) ) {
2630
2631
2632 rx_buffered_packets_t *rx_q_item;
2633 struct list_head *rx_list;
2634
2635 rx_q_item = (rx_buffered_packets_t *)kmalloc(sizeof(rx_buffered_packets_t),
2636 GFP_KERNEL);
2637 if (rx_q_item == NULL) {
2638 unifi_error(priv, "%s: Failed to allocate %d bytes for rx packet record\n",
2639 __FUNCTION__, sizeof(rx_buffered_packets_t));
2640 interfacePriv->stats.rx_dropped++;
2641 unifi_net_data_free(priv, &bulkdata->d[0]);
2642 func_exit();
2643 return;
2644 }
2645
2646 INIT_LIST_HEAD(&rx_q_item->q);
2647 rx_q_item->bulkdata = *bulkdata;
2648 rx_q_item->skb = skb;
2649 rx_q_item->signal = *signal;
2650 memcpy(rx_q_item->sa.a, sa, ETH_ALEN);
2651 memcpy(rx_q_item->da.a, da, ETH_ALEN);
2652 unifi_trace(priv, UDBG2, "%s: Blocked skb=%p, bulkdata=%p\n",
2653 __FUNCTION__, rx_q_item->skb, &rx_q_item->bulkdata);
2654
2655 if (queue == UF_CONTROLLED_PORT_Q) {
2656 rx_list = &interfacePriv->rx_controlled_list;
2657 } else {
2658 rx_list = &interfacePriv->rx_uncontrolled_list;
2659 }
2660
2661
2662 down(&priv->rx_q_sem);
2663 list_add_tail(&rx_q_item->q, rx_list);
2664 up(&priv->rx_q_sem);
2665
2666 func_exit();
2667 return;
2668
2669 }
2670
2671 indicate_rx_skb(priv, interfaceTag, da, sa, skb, signal, bulkdata);
2672
2673 func_exit();
2674
2675}
2676
2677static void process_ma_packet_cfm(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata)
2678{
2679 u16 interfaceTag;
2680 const CSR_MA_PACKET_CONFIRM *pkt_cfm = &signal->u.MaPacketConfirm;
2681 netInterface_priv_t *interfacePriv;
2682
2683 func_enter();
2684 interfaceTag = (pkt_cfm->VirtualInterfaceIdentifier & 0xff);
2685 interfacePriv = priv->interfacePriv[interfaceTag];
2686
2687
2688 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES)
2689 {
2690 unifi_error(priv, "%s: MA-PACKET confirm with bad interfaceTag %d\n", __FUNCTION__, interfaceTag);
2691 func_exit();
2692 return;
2693 }
2694#ifdef CSR_SUPPORT_SME
2695 if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2696 interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
2697
2698 uf_process_ma_pkt_cfm_for_ap(priv,interfaceTag,pkt_cfm);
2699 } else if (interfacePriv->m4_sent && (pkt_cfm->HostTag == interfacePriv->m4_hostTag)) {
2700
2701 CsrResult result = pkt_cfm->TransmissionStatus == CSR_TX_SUCCESSFUL?CSR_RESULT_SUCCESS:CSR_RESULT_FAILURE;
2702 CsrWifiMacAddress peerMacAddress;
2703 memcpy(peerMacAddress.a, interfacePriv->m4_signal.u.MaPacketRequest.Ra.x, ETH_ALEN);
2704
2705 unifi_trace(priv, UDBG1, "%s: Sending M4 Transmit CFM\n", __FUNCTION__);
2706 CsrWifiRouterCtrlM4TransmittedIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0,
2707 interfaceTag,
2708 peerMacAddress,
2709 result);
2710 interfacePriv->m4_sent = FALSE;
2711 interfacePriv->m4_hostTag = 0xffffffff;
2712 }
2713#endif
2714 func_exit();
2715 return;
2716}
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733static void process_ma_packet_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata)
2734{
2735 u16 interfaceTag;
2736 bulk_data_desc_t *pData;
2737 CSR_MA_PACKET_INDICATION *pkt_ind = (CSR_MA_PACKET_INDICATION*)&signal->u.MaPacketIndication;
2738 struct sk_buff *skb;
2739 u16 frameControl;
2740 netInterface_priv_t *interfacePriv;
2741 u8 da[ETH_ALEN], sa[ETH_ALEN];
2742 u8 *bssid = NULL, *ba_addr = NULL;
2743 u8 toDs, fromDs, frameType;
2744 u8 i =0;
2745
2746#ifdef CSR_SUPPORT_SME
2747 u8 dataFrameType = 0;
2748 u8 powerSaveChanged = FALSE;
2749 u8 pmBit = 0;
2750 CsrWifiRouterCtrlStaInfo_t *srcStaInfo = NULL;
2751 u16 qosControl;
2752
2753#endif
2754
2755 func_enter();
2756
2757 interfaceTag = (pkt_ind->VirtualInterfaceIdentifier & 0xff);
2758 interfacePriv = priv->interfacePriv[interfaceTag];
2759
2760
2761
2762 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES)
2763 {
2764 unifi_error(priv, "%s: MA-PACKET indication with bad interfaceTag %d\n", __FUNCTION__, interfaceTag);
2765 unifi_net_data_free(priv,&bulkdata->d[0]);
2766 func_exit();
2767 return;
2768 }
2769
2770
2771 if (!interfacePriv->netdev_registered)
2772 {
2773 unifi_error(priv, "%s: MA-PACKET indication with unallocated interfaceTag %d\n", __FUNCTION__, interfaceTag);
2774 unifi_net_data_free(priv, &bulkdata->d[0]);
2775 func_exit();
2776 return;
2777 }
2778
2779 if (bulkdata->d[0].data_length == 0) {
2780 unifi_warning(priv, "%s: MA-PACKET indication with zero bulk data\n", __FUNCTION__);
2781 unifi_net_data_free(priv,&bulkdata->d[0]);
2782 func_exit();
2783 return;
2784 }
2785
2786
2787
2788 if(pkt_ind->ReceptionStatus != CSR_RX_SUCCESS)
2789 {
2790 unifi_warning(priv, "%s: MA-PACKET indication with status = %d\n",__FUNCTION__, pkt_ind->ReceptionStatus);
2791 unifi_net_data_free(priv,&bulkdata->d[0]);
2792 func_exit();
2793 return;
2794 }
2795
2796
2797 skb = (struct sk_buff*)bulkdata->d[0].os_net_buf_ptr;
2798 skb->len = bulkdata->d[0].data_length;
2799
2800
2801 toDs = (skb->data[1] & 0x01) ? 1 : 0;
2802 fromDs = (skb->data[1] & 0x02) ? 1 : 0;
2803
2804 memcpy(da,(skb->data+4+toDs*12),ETH_ALEN);
2805 memcpy(sa,(skb->data+10+fromDs*(6+toDs*8)),ETH_ALEN);
2806
2807
2808 if (toDs && fromDs)
2809 {
2810 unifi_trace(priv, UDBG6, "4 address frame - don't try to find BSSID\n");
2811 bssid = NULL;
2812 }
2813 else
2814 {
2815 bssid = (u8 *) (skb->data + 4 + 12 - (fromDs * 6) - (toDs * 12));
2816 }
2817
2818 pData = &bulkdata->d[0];
2819 frameControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr);
2820 frameType = ((frameControl & 0x000C) >> 2);
2821
2822 unifi_trace(priv, UDBG3, "Rx Frame Type: %d sn: %d\n",frameType,
2823 (le16_to_cpu(*((u16*)(bulkdata->d[0].os_data_ptr + IEEE802_11_SEQUENCE_CONTROL_OFFSET))) >> 4) & 0xfff);
2824 if(frameType == IEEE802_11_FRAMETYPE_CONTROL){
2825#ifdef CSR_SUPPORT_SME
2826 unifi_trace(priv, UDBG6, "%s: Received Control Frame\n", __FUNCTION__);
2827
2828 if((frameControl & 0x00f0) == 0x00A0){
2829
2830 u8 pmBit = (frameControl & 0x1000)?0x01:0x00;
2831 unifi_trace(priv, UDBG6, "%s: Received PS-POLL Frame\n", __FUNCTION__);
2832
2833 uf_process_ps_poll(priv,sa,da,pmBit,interfaceTag);
2834 }
2835 else {
2836 unifi_warning(priv, "%s: Non PS-POLL control frame is received\n", __FUNCTION__);
2837 }
2838#endif
2839 unifi_net_data_free(priv,&bulkdata->d[0]);
2840 func_exit();
2841 return;
2842 }
2843 if(frameType != IEEE802_11_FRAMETYPE_DATA) {
2844 unifi_warning(priv, "%s: Non control Non Data frame is received\n",__FUNCTION__);
2845 unifi_net_data_free(priv,&bulkdata->d[0]);
2846 func_exit();
2847 return;
2848 }
2849
2850#ifdef CSR_SUPPORT_SME
2851 if((interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP) ||
2852 (interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO)){
2853
2854 srcStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,sa,interfaceTag);
2855
2856 if(srcStaInfo == NULL) {
2857 CsrWifiMacAddress peerMacAddress;
2858
2859 memcpy(peerMacAddress.a,sa,ETH_ALEN);
2860 unifi_trace(priv, UDBG1, "%s: Unexpected frame from peer = %x:%x:%x:%x:%x:%x\n", __FUNCTION__,
2861 sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]);
2862 CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress);
2863 unifi_net_data_free(priv, &bulkdata->d[0]);
2864 func_exit();
2865 return;
2866 }
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876 pmBit = (frameControl & 0x1000)?0x01:0x00;
2877 powerSaveChanged = uf_process_pm_bit_for_peer(priv,srcStaInfo,pmBit,interfaceTag);
2878
2879
2880 srcStaInfo->activity_flag = TRUE;
2881
2882
2883
2884
2885 dataFrameType = ((frameControl & 0x00f0) >> 4);
2886
2887 if((powerSaveChanged == FALSE)&&(srcStaInfo->wmmOrQosEnabled == TRUE)&&
2888 (srcStaInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE)){
2889
2890 if((dataFrameType == QOS_DATA) || (dataFrameType == QOS_DATA_NULL)){
2891
2892
2893
2894
2895
2896 if((frameControl & IEEE802_11_FC_TO_DS_MASK) && (frameControl & IEEE802_11_FC_FROM_DS_MASK)){
2897 qosControl= CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr + 30);
2898 }
2899 else{
2900 qosControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr + 24);
2901 }
2902 unifi_trace(priv, UDBG5, "%s: Check if U-APSD operations are triggered for qosControl: 0x%x\n",__FUNCTION__,qosControl);
2903 uf_process_wmm_deliver_ac_uapsd(priv,srcStaInfo,qosControl,interfaceTag);
2904 }
2905 }
2906 }
2907
2908#endif
2909
2910 if( ((frameControl & 0x00f0) >> 4) == QOS_DATA) {
2911 u8 *qos_control_ptr = (u8*)bulkdata->d[0].os_data_ptr + (((frameControl & IEEE802_11_FC_TO_DS_MASK) && (frameControl & IEEE802_11_FC_FROM_DS_MASK))?30: 24);
2912 int tID = *qos_control_ptr & IEEE802_11_QC_TID_MASK;
2913 ba_session_rx_struct *ba_session;
2914 u8 ba_session_idx = 0;
2915
2916 if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2917 interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO){
2918 ba_addr = sa;
2919 }else{
2920 ba_addr = bssid;
2921 }
2922
2923 down(&priv->ba_mutex);
2924 for (ba_session_idx=0; ba_session_idx < MAX_SUPPORTED_BA_SESSIONS_RX; ba_session_idx++){
2925 ba_session = interfacePriv->ba_session_rx[ba_session_idx];
2926 if (ba_session){
2927 unifi_trace(priv, UDBG6, "found ba_session=0x%x ba_session_idx=%d", ba_session, ba_session_idx);
2928 if ((!memcmp(ba_session->macAddress.a, ba_addr, ETH_ALEN)) && (ba_session->tID == tID)){
2929 frame_desc_struct frame_desc;
2930 frame_desc.bulkdata = *bulkdata;
2931 frame_desc.signal = *signal;
2932 frame_desc.sn = (le16_to_cpu(*((u16*)(bulkdata->d[0].os_data_ptr + IEEE802_11_SEQUENCE_CONTROL_OFFSET))) >> 4) & 0xfff;
2933 frame_desc.active = TRUE;
2934 unifi_trace(priv, UDBG6, "%s: calling process_ba_frame (session=%d)\n", __FUNCTION__, ba_session_idx);
2935 process_ba_frame(priv, interfacePriv, ba_session, &frame_desc);
2936 up(&priv->ba_mutex);
2937 process_ba_complete(priv, interfacePriv);
2938 break;
2939 }
2940 }
2941 }
2942 if (ba_session_idx == MAX_SUPPORTED_BA_SESSIONS_RX){
2943 up(&priv->ba_mutex);
2944 unifi_trace(priv, UDBG6, "%s: calling process_amsdu()", __FUNCTION__);
2945 process_amsdu(priv, signal, bulkdata);
2946 }
2947 } else {
2948 unifi_trace(priv, UDBG6, "calling unifi_rx()");
2949 unifi_rx(priv, signal, bulkdata);
2950 }
2951
2952
2953
2954
2955
2956
2957
2958
2959 down(&priv->ba_mutex);
2960 for (i=0; i < MAX_SUPPORTED_BA_SESSIONS_RX; i++){
2961 ba_session_rx_struct *ba_session;
2962 ba_session = interfacePriv->ba_session_rx[i];
2963 if (ba_session){
2964 check_ba_frame_age_timeout(priv, interfacePriv, ba_session);
2965 }
2966 }
2967 up(&priv->ba_mutex);
2968 process_ba_complete(priv, interfacePriv);
2969
2970 func_exit();
2971}
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989static void
2990uf_set_multicast_list(struct net_device *dev)
2991{
2992 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2993 unifi_priv_t *priv = interfacePriv->privPtr;
2994
2995#ifdef CSR_NATIVE_LINUX
2996 unifi_trace(priv, UDBG3, "uf_set_multicast_list unsupported\n");
2997 return;
2998#else
2999
3000 u8 *mc_list = interfacePriv->mc_list;
3001#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,34)
3002 struct netdev_hw_addr *mc_addr;
3003 int mc_addr_count;
3004#else
3005 struct dev_mc_list *p;
3006 int i;
3007#endif
3008
3009 if (priv->init_progress != UNIFI_INIT_COMPLETED) {
3010 return;
3011 }
3012
3013#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,34)
3014 mc_addr_count = netdev_mc_count(dev);
3015
3016 unifi_trace(priv, UDBG3,
3017 "uf_set_multicast_list (count=%d)\n", mc_addr_count);
3018
3019
3020
3021 if (mc_addr_count > UNIFI_MAX_MULTICAST_ADDRESSES) {
3022 return;
3023 }
3024
3025
3026 interfacePriv->mc_list_count = mc_addr_count;
3027 netdev_hw_addr_list_for_each(mc_addr, &dev->mc) {
3028 memcpy(mc_list, mc_addr->addr, ETH_ALEN);
3029 mc_list += ETH_ALEN;
3030 }
3031
3032#else
3033 unifi_trace(priv, UDBG3,
3034 "uf_set_multicast_list (count=%d)\n", dev->mc_count);
3035
3036
3037 if (dev->mc_count > UNIFI_MAX_MULTICAST_ADDRESSES) {
3038 return;
3039 }
3040
3041
3042 interfacePriv->mc_list_count = dev->mc_count;
3043 p = dev->mc_list;
3044 for (i = 0; i < dev->mc_count; i++) {
3045 memcpy(mc_list, p->dmi_addr, ETH_ALEN);
3046 p = p->next;
3047 mc_list += ETH_ALEN;
3048 }
3049#endif
3050
3051
3052 queue_work(priv->unifi_workqueue, &priv->multicast_list_task);
3053#endif
3054
3055}
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079static void
3080netdev_mlme_event_handler(ul_client_t *pcli, const u8 *sig_packed, int sig_len,
3081 const bulk_data_param_t *bulkdata_o, int dir)
3082{
3083 CSR_SIGNAL signal;
3084 unifi_priv_t *priv = uf_find_instance(pcli->instance);
3085 int id, r;
3086 bulk_data_param_t bulkdata;
3087
3088 func_enter();
3089
3090
3091 if (sig_packed == NULL) {
3092 return;
3093 }
3094
3095
3096
3097
3098
3099 bulkdata = *bulkdata_o;
3100
3101
3102 r = read_unpack_signal(sig_packed, &signal);
3103 if (r) {
3104
3105
3106
3107
3108 unifi_trace(priv, UDBG1,
3109 "Netdev - Received unknown signal 0x%.4X.\n",
3110 CSR_GET_UINT16_FROM_LITTLE_ENDIAN(sig_packed));
3111 return;
3112 }
3113
3114 id = signal.SignalPrimitiveHeader.SignalId;
3115 unifi_trace(priv, UDBG3, "Netdev - Process signal 0x%.4X\n", id);
3116
3117
3118
3119
3120 switch (id) {
3121 case CSR_MA_PACKET_ERROR_INDICATION_ID:
3122 process_ma_packet_error_ind(priv, &signal, &bulkdata);
3123 break;
3124 case CSR_MA_PACKET_INDICATION_ID:
3125 process_ma_packet_ind(priv, &signal, &bulkdata);
3126 break;
3127 case CSR_MA_PACKET_CONFIRM_ID:
3128 process_ma_packet_cfm(priv, &signal, &bulkdata);
3129 break;
3130#ifdef CSR_SUPPORT_SME
3131 case CSR_MLME_SET_TIM_CONFIRM_ID:
3132
3133
3134
3135 uf_handle_tim_cfm(priv, &signal.u.MlmeSetTimConfirm, signal.SignalPrimitiveHeader.ReceiverProcessId);
3136 break;
3137#endif
3138 case CSR_DEBUG_STRING_INDICATION_ID:
3139 debug_string_indication(priv, bulkdata.d[0].os_data_ptr, bulkdata.d[0].data_length);
3140 break;
3141
3142 case CSR_DEBUG_WORD16_INDICATION_ID:
3143 debug_word16_indication(priv, &signal);
3144 break;
3145
3146 case CSR_DEBUG_GENERIC_CONFIRM_ID:
3147 case CSR_DEBUG_GENERIC_INDICATION_ID:
3148 debug_generic_indication(priv, &signal);
3149 break;
3150 default:
3151 break;
3152 }
3153
3154 func_exit();
3155}
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175void uf_net_get_name(struct net_device *dev, char *name, int len)
3176{
3177 *name = '\0';
3178 if (dev) {
3179 strlcpy(name, dev->name, (len > IFNAMSIZ) ? IFNAMSIZ : len);
3180 }
3181
3182}
3183
3184
3185
3186
3187
3188#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
3189#ifdef CONFIG_NET_SCHED
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212int uf_install_qdisc(struct net_device *dev)
3213{
3214 struct Qdisc *qdisc;
3215#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
3216 struct netdev_queue *queue0;
3217#endif
3218
3219
3220 func_enter();
3221
3222#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
3223
3224
3225
3226
3227
3228 if (dev->qdisc_sleeping != &noop_qdisc) {
3229 func_exit_r(-EFAULT);
3230 return -EINVAL;
3231 }
3232#endif
3233
3234 qdisc = UF_QDISC_CREATE_DFLT(dev, &uf_qdisc_ops, TC_H_ROOT);
3235 if (!qdisc) {
3236 unifi_error(NULL, "%s: qdisc installation failed\n", dev->name);
3237 func_exit_r(-EFAULT);
3238 return -EFAULT;
3239 }
3240 unifi_trace(NULL, UDBG5, "%s: parent qdisc=0x%p\n",
3241 dev->name, qdisc);
3242
3243 qdisc->handle = 0x80020000;
3244 qdisc->flags = 0x0;
3245
3246#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
3247 queue0 = netdev_get_tx_queue(dev, 0);
3248 if (queue0 == NULL) {
3249 unifi_error(NULL, "%s: netdev_get_tx_queue returned no queue\n",
3250 dev->name);
3251 func_exit_r(-EFAULT);
3252 return -EFAULT;
3253 }
3254 queue0->qdisc = qdisc;
3255 queue0->qdisc_sleeping = qdisc;
3256#else
3257 qdisc_lock_tree(dev);
3258 list_add_tail(&qdisc->list, &dev->qdisc_list);
3259 dev->qdisc_sleeping = qdisc;
3260 qdisc_unlock_tree(dev);
3261#endif
3262
3263 func_exit_r(0);
3264 return 0;
3265
3266}
3267
3268static int uf_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
3269{
3270#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
3271 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(qd->dev_queue->dev);
3272#else
3273 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(qd->dev);
3274#endif
3275 unifi_priv_t *priv = interfacePriv->privPtr;
3276 struct uf_sched_data *q = qdisc_priv(qd);
3277 struct uf_tx_packet_data *pkt_data = (struct uf_tx_packet_data *) skb->cb;
3278 struct ethhdr ehdr;
3279 struct Qdisc *qdisc;
3280 int r, proto;
3281
3282 func_enter();
3283
3284 memcpy(&ehdr, skb->data, ETH_HLEN);
3285 proto = ntohs(ehdr.h_proto);
3286
3287
3288 if ((proto != ETH_P_PAE)
3289#ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
3290 && (proto != ETH_P_WAI)
3291#endif
3292 ) {
3293
3294 pkt_data->priority = get_packet_priority(priv, skb, &ehdr, interfacePriv);
3295 pkt_data->queue = unifi_frame_priority_to_queue(pkt_data->priority);
3296 } else {
3297 pkt_data->queue = UNIFI_TRAFFIC_Q_EAPOL;
3298 }
3299
3300 qdisc = q->queues[pkt_data->queue];
3301 r = qdisc->enqueue(skb, qdisc);
3302 if (r == NET_XMIT_SUCCESS) {
3303 qd->q.qlen++;
3304 qd->bstats.bytes += skb->len;
3305 qd->bstats.packets++;
3306 func_exit_r(NET_XMIT_SUCCESS);
3307 return NET_XMIT_SUCCESS;
3308 }
3309
3310 unifi_error(priv, "uf_qdiscop_enqueue: dropped\n");
3311 qd->qstats.drops++;
3312
3313 func_exit_r(r);
3314 return r;
3315
3316}
3317
3318
3319static int uf_qdiscop_requeue(struct sk_buff *skb, struct Qdisc* qd)
3320{
3321#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
3322 netInterface_priv_t *interfacePriv = (netInterface_priv_t*)netdev_priv(qd->dev_queue->dev);
3323#else
3324 netInterface_priv_t *interfacePriv = (netInterface_priv_t*)netdev_priv(qd->dev);
3325#endif
3326 unifi_priv_t *priv = interfacePriv->privPtr;
3327 struct uf_sched_data *q = qdisc_priv(qd);
3328 struct uf_tx_packet_data *pkt_data = (struct uf_tx_packet_data *) skb->cb;
3329 struct Qdisc *qdisc;
3330 int r;
3331
3332 func_enter();
3333
3334 unifi_trace(priv, UDBG5, "uf_qdiscop_requeue: (q=%d), tag=%u\n",
3335 pkt_data->queue, pkt_data->host_tag);
3336
3337
3338 qdisc = q->queues[pkt_data->queue];
3339
3340 if ((r = qdisc->ops->requeue(skb, qdisc)) == 0) {
3341 qd->q.qlen++;
3342 func_exit_r(0);
3343 return 0;
3344 }
3345
3346 unifi_error(priv, "uf_qdiscop_requeue: dropped\n");
3347 qd->qstats.drops++;
3348
3349 func_exit_r(r);
3350 return r;
3351}
3352
3353static struct sk_buff *uf_qdiscop_dequeue(struct Qdisc* qd)
3354{
3355#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
3356 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(qd->dev_queue->dev);
3357#else
3358 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(qd->dev);
3359#endif
3360 unifi_priv_t *priv = interfacePriv->privPtr;
3361 struct uf_sched_data *q = qdisc_priv(qd);
3362 struct sk_buff *skb;
3363 struct Qdisc *qdisc;
3364 int queue, i;
3365 struct ethhdr ehdr;
3366 struct uf_tx_packet_data *pkt_data;
3367 CsrWifiRouterCtrlPortAction port_action;
3368
3369 func_enter();
3370
3371
3372 for (i = UNIFI_TRAFFIC_Q_MAX - 1; i >= 0; i--) {
3373
3374 if (i != UNIFI_TRAFFIC_Q_EAPOL) {
3375 queue = priv->prev_queue;
3376 if (++priv->prev_queue >= UNIFI_TRAFFIC_Q_EAPOL) {
3377 priv->prev_queue = 0;
3378 }
3379 } else {
3380 queue = i;
3381 }
3382
3383#ifndef ALLOW_Q_PAUSE
3384
3385 if (net_is_tx_q_paused(priv, queue)) {
3386 unifi_trace(priv, UDBG5,
3387 "uf_qdiscop_dequeue: tx queue paused (q=%d)\n", queue);
3388 continue;
3389 }
3390#endif
3391
3392 qdisc = q->queues[queue];
3393 skb = qdisc->dequeue(qdisc);
3394 if (skb) {
3395
3396 qd->q.qlen--;
3397
3398 pkt_data = (struct uf_tx_packet_data *) skb->cb;
3399
3400
3401 memcpy(&ehdr, skb->data, ETH_HLEN);
3402
3403 port_action = verify_port(priv
3404 , (((CSR_WIFI_ROUTER_CTRL_MODE_STA == interfacePriv->interfaceMode) ||(CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI == interfacePriv->interfaceMode))? interfacePriv->bssid.a: ehdr.h_dest)
3405 , (UNIFI_TRAFFIC_Q_EAPOL == queue? UF_UNCONTROLLED_PORT_Q: UF_CONTROLLED_PORT_Q)
3406 , interfacePriv->InterfaceTag);
3407
3408
3409 if (port_action == CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN) {
3410 unifi_trace(priv, UDBG5,
3411 "uf_qdiscop_dequeue: new (q=%d), tag=%u\n",
3412 queue, pkt_data->host_tag);
3413
3414 func_exit();
3415 return skb;
3416 }
3417
3418
3419 if (port_action == CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_DISCARD) {
3420 unifi_trace(priv, UDBG5,
3421 "uf_qdiscop_dequeue: drop (q=%d), tag=%u\n",
3422 queue, pkt_data->host_tag);
3423 kfree_skb(skb);
3424 break;
3425 }
3426
3427
3428 if (qdisc->ops->requeue(skb, qdisc) != 0) {
3429 unifi_error(priv,
3430 "uf_qdiscop_dequeue: requeue (q=%d) failed, tag=%u, drop it\n",
3431 queue, pkt_data->host_tag);
3432
3433
3434 kfree_skb(skb);
3435 break;
3436 }
3437
3438 qd->q.qlen++;
3439
3440 unifi_trace(priv, UDBG5,
3441 "uf_qdiscop_dequeue: skip (q=%d), tag=%u\n",
3442 queue, pkt_data->host_tag);
3443 }
3444 }
3445
3446 func_exit();
3447 return NULL;
3448}
3449
3450
3451static void uf_qdiscop_reset(struct Qdisc* qd)
3452{
3453 struct uf_sched_data *q = qdisc_priv(qd);
3454 int queue;
3455 func_enter();
3456
3457 for (queue = 0; queue < UNIFI_TRAFFIC_Q_MAX; queue++) {
3458 qdisc_reset(q->queues[queue]);
3459 }
3460 qd->q.qlen = 0;
3461
3462 func_exit();
3463}
3464
3465
3466static void uf_qdiscop_destroy(struct Qdisc* qd)
3467{
3468 struct uf_sched_data *q = qdisc_priv(qd);
3469 int queue;
3470
3471 func_enter();
3472
3473 for (queue=0; queue < UNIFI_TRAFFIC_Q_MAX; queue++) {
3474 qdisc_destroy(q->queues[queue]);
3475 q->queues[queue] = &noop_qdisc;
3476 }
3477
3478 func_exit();
3479}
3480
3481
3482
3483#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
3484static int uf_qdiscop_tune(struct Qdisc *qd, struct nlattr *opt)
3485#else
3486static int uf_qdiscop_tune(struct Qdisc *qd, struct rtattr *opt)
3487#endif
3488{
3489 func_enter();
3490 func_exit();
3491 return 0;
3492}
3493
3494
3495
3496#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
3497static int uf_qdiscop_init(struct Qdisc *qd, struct nlattr *opt)
3498#else
3499static int uf_qdiscop_init(struct Qdisc *qd, struct rtattr *opt)
3500#endif
3501{
3502#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
3503 struct net_device *dev = qd->dev_queue->dev;
3504#else
3505 struct net_device *dev = qd->dev;
3506#endif
3507 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
3508 unifi_priv_t *priv = interfacePriv->privPtr;
3509 struct uf_sched_data *q = qdisc_priv(qd);
3510 int err = 0, i;
3511
3512 func_enter();
3513
3514
3515 if (qd->flags & TCQ_F_INGRESS) {
3516 func_exit();
3517 return -EINVAL;
3518 }
3519
3520
3521 if (opt) {
3522 err = uf_qdiscop_tune(qd, opt);
3523 }
3524
3525
3526 for (i = 0; i < UNIFI_TRAFFIC_Q_MAX; i++) {
3527 q->queues[i] = UF_QDISC_CREATE_DFLT(dev, &pfifo_qdisc_ops,
3528 qd->handle);
3529 if (!q->queues[i]) {
3530 q->queues[i] = &noop_qdisc;
3531 unifi_error(priv, "%s child qdisc %i creation failed\n");
3532 }
3533
3534 unifi_trace(priv, UDBG5, "%s: child qdisc=0x%p\n",
3535 dev->name, q->queues[i]);
3536 }
3537
3538 func_exit_r(err);
3539 return err;
3540}
3541
3542
3543static int uf_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb)
3544{
3545 func_enter();
3546 func_exit_r(skb->len);
3547 return skb->len;
3548}
3549
3550#endif
3551#endif
3552
3553#ifdef CSR_SUPPORT_WEXT
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573static int
3574uf_netdev_event(struct notifier_block *notif, unsigned long event, void* ptr) {
3575 struct net_device *netdev = ptr;
3576 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(netdev);
3577 unifi_priv_t *priv = NULL;
3578 static const CsrWifiMacAddress broadcast_address = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
3579
3580
3581
3582
3583 if (uf_find_netdev_priv(interfacePriv) == -1) {
3584 unifi_trace(NULL, UDBG1, "uf_netdev_event: ignore e=%d, ptr=%p, priv=%p %s\n",
3585 event, ptr, interfacePriv, netdev->name);
3586 return 0;
3587 }
3588
3589 switch(event) {
3590 case NETDEV_CHANGE:
3591 priv = interfacePriv->privPtr;
3592 unifi_trace(priv, UDBG1, "NETDEV_CHANGE: %p %s %s waiting for it\n",
3593 ptr,
3594 netdev->name,
3595 interfacePriv->wait_netdev_change ? "" : "not");
3596
3597 if (interfacePriv->wait_netdev_change) {
3598 UF_NETIF_TX_WAKE_ALL_QUEUES(priv->netdev[interfacePriv->InterfaceTag]);
3599 interfacePriv->connected = UnifiConnected;
3600 interfacePriv->wait_netdev_change = FALSE;
3601
3602 uf_process_rx_pending_queue(priv, UF_UNCONTROLLED_PORT_Q, broadcast_address, 1,interfacePriv->InterfaceTag);
3603 uf_process_rx_pending_queue(priv, UF_CONTROLLED_PORT_Q, broadcast_address, 1,interfacePriv->InterfaceTag);
3604 }
3605 break;
3606
3607 default:
3608 break;
3609 }
3610 return 0;
3611}
3612
3613static struct notifier_block uf_netdev_notifier = {
3614 .notifier_call = uf_netdev_event,
3615};
3616#endif
3617
3618
3619static void
3620 process_amsdu(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata)
3621{
3622 u32 offset;
3623 u32 length = bulkdata->d[0].data_length;
3624 u32 subframe_length, subframe_body_length, dot11_hdr_size;
3625 u8 *ptr;
3626 bulk_data_param_t subframe_bulkdata;
3627 u8 *dot11_hdr_ptr = (u8*)bulkdata->d[0].os_data_ptr;
3628 CsrResult csrResult;
3629 u16 frameControl;
3630 u8 *qos_control_ptr;
3631
3632 frameControl = le16_to_cpu(*((u16*)dot11_hdr_ptr));
3633 qos_control_ptr = dot11_hdr_ptr + (((frameControl & IEEE802_11_FC_TO_DS_MASK) && (frameControl & IEEE802_11_FC_FROM_DS_MASK))?30: 24);
3634 if(!(*qos_control_ptr & IEEE802_11_QC_A_MSDU_PRESENT)) {
3635 unifi_trace(priv, UDBG6, "%s: calling unifi_rx()", __FUNCTION__);
3636 unifi_rx(priv, signal, bulkdata);
3637 return;
3638 }
3639 *qos_control_ptr &= ~(IEEE802_11_QC_A_MSDU_PRESENT);
3640
3641 ptr = qos_control_ptr + 2;
3642 offset = dot11_hdr_size = ptr - dot11_hdr_ptr;
3643
3644 while(length > (offset + sizeof(struct ethhdr) + sizeof(llc_snap_hdr_t))) {
3645 subframe_body_length = ntohs(((struct ethhdr*)ptr)->h_proto);
3646 if(subframe_body_length > IEEE802_11_MAX_DATA_LEN) {
3647 unifi_error(priv, "%s: bad subframe_body_length = %d\n", __FUNCTION__, subframe_body_length);
3648 break;
3649 }
3650 subframe_length = sizeof(struct ethhdr) + subframe_body_length;
3651 memset(&subframe_bulkdata, 0, sizeof(bulk_data_param_t));
3652
3653 csrResult = unifi_net_data_malloc(priv, &subframe_bulkdata.d[0], dot11_hdr_size + subframe_body_length);
3654
3655 if (csrResult != CSR_RESULT_SUCCESS) {
3656 unifi_error(priv, "%s: unifi_net_data_malloc failed\n", __FUNCTION__);
3657 break;
3658 }
3659
3660 memcpy((u8*)subframe_bulkdata.d[0].os_data_ptr, dot11_hdr_ptr, dot11_hdr_size);
3661
3662
3663
3664 if ((frameControl & IEEE802_11_FC_TO_DS_MASK) && !(frameControl & IEEE802_11_FC_FROM_DS_MASK)){
3665 memcpy((u8*)subframe_bulkdata.d[0].os_data_ptr + IEEE802_11_ADDR3_OFFSET, ((struct ethhdr*)ptr)->h_dest, ETH_ALEN);
3666 }
3667 else if (!(frameControl & IEEE802_11_FC_TO_DS_MASK) && (frameControl & IEEE802_11_FC_FROM_DS_MASK)){
3668 memcpy((u8*)subframe_bulkdata.d[0].os_data_ptr + IEEE802_11_ADDR3_OFFSET,
3669 ((struct ethhdr*)ptr)->h_source,
3670 ETH_ALEN);
3671 }
3672
3673 memcpy((u8*)subframe_bulkdata.d[0].os_data_ptr + dot11_hdr_size,
3674 ptr + sizeof(struct ethhdr),
3675 subframe_body_length);
3676 unifi_trace(priv, UDBG6, "%s: calling unifi_rx. length = %d subframe_length = %d\n", __FUNCTION__, length, subframe_length);
3677 unifi_rx(priv, signal, &subframe_bulkdata);
3678
3679 subframe_length = (subframe_length + 3)&(~0x3);
3680 ptr += subframe_length;
3681 offset += subframe_length;
3682 }
3683 unifi_net_data_free(priv, &bulkdata->d[0]);
3684}
3685
3686
3687#define SN_TO_INDEX(__ba_session, __sn) (((__sn - __ba_session->start_sn) & 0xFFF) % __ba_session->wind_size)
3688
3689
3690#define ADVANCE_EXPECTED_SN(__ba_session) \
3691{ \
3692 __ba_session->expected_sn++; \
3693 __ba_session->expected_sn &= 0xFFF; \
3694}
3695
3696#define FREE_BUFFER_SLOT(__ba_session, __index) \
3697{ \
3698 __ba_session->occupied_slots--; \
3699 __ba_session->buffer[__index].active = FALSE; \
3700 ADVANCE_EXPECTED_SN(__ba_session); \
3701}
3702
3703static void add_frame_to_ba_complete(unifi_priv_t *priv,
3704 netInterface_priv_t *interfacePriv,
3705 frame_desc_struct *frame_desc)
3706{
3707 interfacePriv->ba_complete[interfacePriv->ba_complete_index] = *frame_desc;
3708 interfacePriv->ba_complete_index++;
3709}
3710
3711
3712static void update_expected_sn(unifi_priv_t *priv,
3713 netInterface_priv_t *interfacePriv,
3714 ba_session_rx_struct *ba_session,
3715 u16 sn)
3716{
3717 int i, j;
3718 u16 gap;
3719
3720 gap = (sn - ba_session->expected_sn) & 0xFFF;
3721 unifi_trace(priv, UDBG6, "%s: proccess the frames up to new_expected_sn = %d gap = %d\n", __FUNCTION__, sn, gap);
3722 for(j = 0; j < gap && j < ba_session->wind_size; j++) {
3723 i = SN_TO_INDEX(ba_session, ba_session->expected_sn);
3724 unifi_trace(priv, UDBG6, "%s: proccess the slot index = %d\n", __FUNCTION__, i);
3725 if(ba_session->buffer[i].active) {
3726 add_frame_to_ba_complete(priv, interfacePriv, &ba_session->buffer[i]);
3727 unifi_trace(priv, UDBG6, "%s: proccess the frame at index = %d expected_sn = %d\n", __FUNCTION__, i, ba_session->expected_sn);
3728 FREE_BUFFER_SLOT(ba_session, i);
3729 } else {
3730 unifi_trace(priv, UDBG6, "%s: empty slot at index = %d\n", __FUNCTION__, i);
3731 ADVANCE_EXPECTED_SN(ba_session);
3732 }
3733 }
3734 ba_session->expected_sn = sn;
3735}
3736
3737
3738static void complete_ready_sequence(unifi_priv_t *priv,
3739 netInterface_priv_t *interfacePriv,
3740 ba_session_rx_struct *ba_session)
3741{
3742 int i;
3743
3744 i = SN_TO_INDEX(ba_session, ba_session->expected_sn);
3745 while (ba_session->buffer[i].active) {
3746 add_frame_to_ba_complete(priv, interfacePriv, &ba_session->buffer[i]);
3747 unifi_trace(priv, UDBG6, "%s: completed stored frame(expected_sn=%d) at i = %d\n", __FUNCTION__, ba_session->expected_sn, i);
3748 FREE_BUFFER_SLOT(ba_session, i);
3749 i = SN_TO_INDEX(ba_session, ba_session->expected_sn);
3750 }
3751}
3752
3753
3754void scroll_ba_window(unifi_priv_t *priv,
3755 netInterface_priv_t *interfacePriv,
3756 ba_session_rx_struct *ba_session,
3757 u16 sn)
3758{
3759 if(((sn - ba_session->expected_sn) & 0xFFF) <= 2048) {
3760 update_expected_sn(priv, interfacePriv, ba_session, sn);
3761 complete_ready_sequence(priv, interfacePriv, ba_session);
3762 }
3763}
3764
3765
3766static int consume_frame_or_get_buffer_index(unifi_priv_t *priv,
3767 netInterface_priv_t *interfacePriv,
3768 ba_session_rx_struct *ba_session,
3769 u16 sn,
3770 frame_desc_struct *frame_desc) {
3771 int i;
3772 u16 sn_temp;
3773
3774 if(((sn - ba_session->expected_sn) & 0xFFF) <= 2048) {
3775
3776
3777 if(!ba_session->trigger_ba_after_ssn){
3778 ba_session->trigger_ba_after_ssn = TRUE;
3779 }
3780
3781 sn_temp = ba_session->expected_sn + ba_session->wind_size;
3782 unifi_trace(priv, UDBG6, "%s: new frame: sn=%d\n", __FUNCTION__, sn);
3783 if(!(((sn - sn_temp) & 0xFFF) > 2048)) {
3784 u16 new_expected_sn;
3785 unifi_trace(priv, UDBG6, "%s: frame is out of window\n", __FUNCTION__);
3786 sn_temp = (sn - ba_session->wind_size) & 0xFFF;
3787 new_expected_sn = (sn_temp + 1) & 0xFFF;
3788 update_expected_sn(priv, interfacePriv, ba_session, new_expected_sn);
3789 }
3790 i = -1;
3791 if (sn == ba_session->expected_sn) {
3792 unifi_trace(priv, UDBG6, "%s: sn = ba_session->expected_sn = %d\n", __FUNCTION__, sn);
3793 ADVANCE_EXPECTED_SN(ba_session);
3794 add_frame_to_ba_complete(priv, interfacePriv, frame_desc);
3795 } else {
3796 i = SN_TO_INDEX(ba_session, sn);
3797 unifi_trace(priv, UDBG6, "%s: sn(%d) != ba_session->expected_sn(%d), i = %d\n", __FUNCTION__, sn, ba_session->expected_sn, i);
3798 if (ba_session->buffer[i].active) {
3799 unifi_trace(priv, UDBG6, "%s: free frame at i = %d\n", __FUNCTION__, i);
3800 i = -1;
3801 unifi_net_data_free(priv, &frame_desc->bulkdata.d[0]);
3802 }
3803 }
3804 } else {
3805 i = -1;
3806 if(!ba_session->trigger_ba_after_ssn){
3807 unifi_trace(priv, UDBG6, "%s: frame before ssn, pass it up: sn=%d\n", __FUNCTION__, sn);
3808 add_frame_to_ba_complete(priv, interfacePriv, frame_desc);
3809 }else{
3810 unifi_trace(priv, UDBG6, "%s: old frame, drop: sn=%d, expected_sn=%d\n", __FUNCTION__, sn, ba_session->expected_sn);
3811 unifi_net_data_free(priv, &frame_desc->bulkdata.d[0]);
3812 }
3813 }
3814 return i;
3815}
3816
3817
3818
3819static void process_ba_frame(unifi_priv_t *priv,
3820 netInterface_priv_t *interfacePriv,
3821 ba_session_rx_struct *ba_session,
3822 frame_desc_struct *frame_desc)
3823{
3824 int i;
3825 u16 sn = frame_desc->sn;
3826
3827 if (ba_session->timeout) {
3828 mod_timer(&ba_session->timer, (jiffies + usecs_to_jiffies((ba_session->timeout) * 1024)));
3829 }
3830 unifi_trace(priv, UDBG6, "%s: got frame(sn=%d)\n", __FUNCTION__, sn);
3831
3832 i = consume_frame_or_get_buffer_index(priv, interfacePriv, ba_session, sn, frame_desc);
3833 if(i >= 0) {
3834 unifi_trace(priv, UDBG6, "%s: store frame(sn=%d) at i = %d\n", __FUNCTION__, sn, i);
3835 ba_session->buffer[i] = *frame_desc;
3836 ba_session->buffer[i].recv_time = CsrTimeGet(NULL);
3837 ba_session->occupied_slots++;
3838 } else {
3839 unifi_trace(priv, UDBG6, "%s: frame consumed - sn = %d\n", __FUNCTION__, sn);
3840 }
3841 complete_ready_sequence(priv, interfacePriv, ba_session);
3842}
3843
3844
3845static void process_ba_complete(unifi_priv_t *priv, netInterface_priv_t *interfacePriv)
3846{
3847 frame_desc_struct *frame_desc;
3848 u8 i;
3849
3850 for(i = 0; i < interfacePriv->ba_complete_index; i++) {
3851 frame_desc = &interfacePriv->ba_complete[i];
3852 unifi_trace(priv, UDBG6, "%s: calling process_amsdu()\n", __FUNCTION__);
3853 process_amsdu(priv, &frame_desc->signal, &frame_desc->bulkdata);
3854 }
3855 interfacePriv->ba_complete_index = 0;
3856
3857}
3858
3859
3860
3861
3862
3863
3864static void check_ba_frame_age_timeout( unifi_priv_t *priv,
3865 netInterface_priv_t *interfacePriv,
3866 ba_session_rx_struct *ba_session)
3867{
3868 CsrTime now;
3869 CsrTime age;
3870 u8 i, j;
3871 u16 sn_temp;
3872
3873
3874
3875
3876 u8 gap=1;
3877
3878 now = CsrTimeGet(NULL);
3879
3880 if (ba_session->occupied_slots)
3881 {
3882
3883
3884
3885
3886
3887 sn_temp = (ba_session->expected_sn + 1) & 0xFFF;
3888
3889 for(j = 0; j < ba_session->wind_size; j++)
3890 {
3891 i = SN_TO_INDEX(ba_session, sn_temp);
3892
3893 if(ba_session->buffer[i].active)
3894 {
3895 unifi_trace(priv, UDBG6, "check age at slot index = %d sn = %d recv_time = %u now = %u\n",
3896 i,
3897 ba_session->buffer[i].sn,
3898 ba_session->buffer[i].recv_time,
3899 now);
3900
3901 if (ba_session->buffer[i].recv_time > now)
3902 {
3903
3904 age = CsrTimeAdd((CsrTime)CsrTimeSub(CSR_SCHED_TIME_MAX, ba_session->buffer[i].recv_time), now);
3905 }
3906 else
3907 {
3908 age = (CsrTime)CsrTimeSub(now, ba_session->buffer[i].recv_time);
3909 }
3910
3911 if (age >= CSR_WIFI_BA_MPDU_FRAME_AGE_TIMEOUT)
3912 {
3913 unifi_trace(priv, UDBG2, "release the frame at index = %d gap = %d expected_sn = %d sn = %d\n",
3914 i,
3915 gap,
3916 ba_session->expected_sn,
3917 ba_session->buffer[i].sn);
3918
3919
3920 while (gap--)
3921 {
3922 ADVANCE_EXPECTED_SN(ba_session);
3923 }
3924 add_frame_to_ba_complete(priv, interfacePriv, &ba_session->buffer[i]);
3925 FREE_BUFFER_SLOT(ba_session, i);
3926 complete_ready_sequence(priv, interfacePriv, ba_session);
3927 }
3928 break;
3929
3930 }
3931 else
3932 {
3933
3934 sn_temp = (sn_temp + 1) & 0xFFF;
3935 gap++;
3936 }
3937 }
3938 }
3939}
3940
3941
3942static void process_ma_packet_error_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata)
3943{
3944 u16 interfaceTag;
3945 const CSR_MA_PACKET_ERROR_INDICATION *pkt_err_ind = &signal->u.MaPacketErrorIndication;
3946 netInterface_priv_t *interfacePriv;
3947 ba_session_rx_struct *ba_session;
3948 u8 ba_session_idx = 0;
3949 CSR_PRIORITY UserPriority;
3950 CSR_SEQUENCE_NUMBER sn;
3951
3952 func_enter();
3953
3954 interfaceTag = (pkt_err_ind->VirtualInterfaceIdentifier & 0xff);
3955
3956
3957
3958 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES)
3959 {
3960 unifi_error(priv, "%s: MaPacketErrorIndication indication with bad interfaceTag %d\n", __FUNCTION__, interfaceTag);
3961 func_exit();
3962 return;
3963 }
3964
3965 interfacePriv = priv->interfacePriv[interfaceTag];
3966 UserPriority = pkt_err_ind->UserPriority;
3967 if(UserPriority > 15) {
3968 unifi_error(priv, "%s: MaPacketErrorIndication indication with bad UserPriority=%d\n", __FUNCTION__, UserPriority);
3969 func_exit();
3970 }
3971 sn = pkt_err_ind->SequenceNumber;
3972
3973 down(&priv->ba_mutex);
3974
3975 for (ba_session_idx=0; ba_session_idx < MAX_SUPPORTED_BA_SESSIONS_RX; ba_session_idx++){
3976 ba_session = interfacePriv->ba_session_rx[ba_session_idx];
3977 if (ba_session){
3978 if ((!memcmp(ba_session->macAddress.a, pkt_err_ind->PeerQstaAddress.x, ETH_ALEN)) && (ba_session->tID == UserPriority)){
3979 if (ba_session->timeout) {
3980 mod_timer(&ba_session->timer, (jiffies + usecs_to_jiffies((ba_session->timeout) * 1024)));
3981 }
3982 scroll_ba_window(priv, interfacePriv, ba_session, sn);
3983 break;
3984 }
3985 }
3986 }
3987
3988 up(&priv->ba_mutex);
3989 process_ba_complete(priv, interfacePriv);
3990 func_exit();
3991}
3992
3993
3994