staging: csr: netdev.c: Clean up KERNEL_VERSION checks: 2.6.34
[deliverable/linux.git] / drivers / staging / csr / netdev.c
1 /*
2 * ---------------------------------------------------------------------------
3 * FILE: netdev.c
4 *
5 * PURPOSE:
6 * This file provides the upper edge interface to the linux netdevice
7 * and wireless extensions.
8 * It is part of the porting exercise.
9 *
10 * Copyright (C) 2005-2010 by Cambridge Silicon Radio Ltd.
11 *
12 * Refer to LICENSE.txt included with this source code for details on
13 * the license terms.
14 *
15 * ---------------------------------------------------------------------------
16 */
17
18 /*
19 * Porting Notes:
20 * This file implements the data plane of the UniFi linux driver.
21 *
22 * All the Tx packets are passed to the HIP core lib, using the
23 * unifi_send_signal() API. For EAPOL packets use the MLME-EAPOL.req
24 * signal, for all other use the MLME-UNITDATA.req. The unifi_send_signal()
25 * expects the wire-formatted (packed) signal. For convenience, in the OS
26 * layer we only use the native (unpacked) signal structures. The HIP core lib
27 * provides the write_pack() helper function to convert to the packed signal.
28 * The packet is stored in the bulk data of the signal. We do not need to
29 * allocate new memory to store the packet, because unifi_net_data_malloc()
30 * is implemented to return a skb, which is the format of packet in Linux.
31 * The HIP core lib frees the bulk data buffers, so we do not need to do
32 * this in the OS layer.
33 *
34 * All the Rx packets are MLME-UNITDATA.ind signals, passed by the HIP core lib
35 * in unifi_receive_event(). We do not need to allocate an skb and copy the
36 * received packet because the HIP core lib has stored in memory allocated by
37 * unifi_net_data_malloc(). Also, we can perform the 802.11 to Ethernet
38 * translation in-place because we allocate the extra memory allocated in
39 * unifi_net_data_malloc().
40 *
41 * If possible, the porting exercise should appropriately implement
42 * unifi_net_data_malloc() and unifi_net_data_free() to save copies between
43 * network and driver buffers.
44 */
45
46 #include <linux/types.h>
47 #include <linux/etherdevice.h>
48 #include <linux/mutex.h>
49 #include <linux/semaphore.h>
50 #include <linux/version.h>
51 #include <linux/vmalloc.h>
52 #include "csr_wifi_hip_unifi.h"
53 #include "csr_wifi_hip_conversions.h"
54 #include "unifi_priv.h"
55 #include <net/pkt_sched.h>
56
57
58 /* ALLOW_Q_PAUSE: Pre 2.6.28 kernels do not support multiple driver queues (required for QoS).
59 * In order to support QoS in these kernels, multiple queues are implemented in the driver. But since
60 * there is only a single queue in the kernel (leading to multiple queues in the driver) there is no possibility
61 * of stopping a particular queue in the kernel. Stopping the single kernel queue leads to undesirable starvation
62 * of driver queues. One of the proposals is to not stop the kernel queue but to prevent dequeuing from the
63 * 'stopped' driver queue. Allow q pause is an experimental implementation of this scheme for pre 2.6.28 kernels.
64 * When NOT defined, queues are paused locally in the driver and packets are dequeued for transmission only from the
65 * unpaused queues. When Allow q pause is defined the kernel queue is stopped whenever any driver queue is paused.
66 */
67 #define ALLOW_Q_PAUSE
68
69 #ifdef UNIFI_NET_NAME
70 #define UF_ALLOC_NETDEV(_dev, _size, _name, _setup, _num_of_queues) \
71 do { \
72 static char name[8]; \
73 sprintf(name, "%s%s", UNIFI_NET_NAME, _name); \
74 _dev = alloc_netdev_mq(_size, name, _setup, _num_of_queues); \
75 } while (0);
76 #else
77 #define UF_ALLOC_NETDEV(_dev, _size, _name, _setup, _num_of_queues) \
78 do { \
79 _dev = alloc_etherdev_mq(_size, _num_of_queues); \
80 } while (0);
81 #endif /* UNIFI_NET_NAME */
82
83
84 /* Wext handler is suported only if CSR_SUPPORT_WEXT is defined */
85 #ifdef CSR_SUPPORT_WEXT
86 extern struct iw_handler_def unifi_iw_handler_def;
87 #endif /* CSR_SUPPORT_WEXT */
88 static void check_ba_frame_age_timeout( unifi_priv_t *priv,
89 netInterface_priv_t *interfacePriv,
90 ba_session_rx_struct *ba_session);
91 static void process_ba_frame(unifi_priv_t *priv,
92 netInterface_priv_t *interfacePriv,
93 ba_session_rx_struct *ba_session,
94 frame_desc_struct *frame_desc);
95 static void process_ba_complete(unifi_priv_t *priv, netInterface_priv_t *interfacePriv);
96 static void process_ma_packet_error_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata);
97 static void process_amsdu(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata);
98 static int uf_net_open(struct net_device *dev);
99 static int uf_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
100 static int uf_net_stop(struct net_device *dev);
101 static struct net_device_stats *uf_net_get_stats(struct net_device *dev);
102 static u16 uf_net_select_queue(struct net_device *dev, struct sk_buff *skb);
103 static netdev_tx_t uf_net_xmit(struct sk_buff *skb, struct net_device *dev);
104 static void uf_set_multicast_list(struct net_device *dev);
105
106
107 typedef int (*tx_signal_handler)(unifi_priv_t *priv, struct sk_buff *skb, const struct ethhdr *ehdr, CSR_PRIORITY priority);
108
109 #ifdef CONFIG_NET_SCHED
110 /*
111 * Queueing Discipline Interface
112 * Only used if kernel is configured with CONFIG_NET_SCHED
113 */
114
115 /*
116 * The driver uses the qdisc interface to buffer and control all
117 * outgoing traffic. We create a root qdisc, register our qdisc operations
118 * and later we create two subsiduary pfifo queues for the uncontrolled
119 * and controlled ports.
120 *
121 * The network stack delivers all outgoing packets in our enqueue handler.
122 * There, we classify the packet and decide whether to store it or drop it
123 * (if the controlled port state is set to "discard").
124 * If the packet is enqueued, the network stack call our dequeue handler.
125 * There, we decide whether we can send the packet, delay it or drop it
126 * (the controlled port configuration might have changed meanwhile).
127 * If a packet is dequeued, then the network stack calls our hard_start_xmit
128 * handler where finally we send the packet.
129 *
130 * If the hard_start_xmit handler fails to send the packet, we return
131 * NETDEV_TX_BUSY and the network stack call our requeue handler where
132 * we put the packet back in the same queue in came from.
133 *
134 */
135
136 struct uf_sched_data
137 {
138 /* Traffic Classifier TBD */
139 struct tcf_proto *filter_list;
140 /* Our two queues */
141 struct Qdisc *queues[UNIFI_TRAFFIC_Q_MAX];
142 };
143
144 struct uf_tx_packet_data {
145 /* Queue the packet is stored in */
146 unifi_TrafficQueue queue;
147 /* QoS Priority determined when enqueing packet */
148 CSR_PRIORITY priority;
149 /* Debug */
150 unsigned long host_tag;
151 };
152
153 #endif /* CONFIG_NET_SCHED */
154
155 static const struct net_device_ops uf_netdev_ops =
156 {
157 .ndo_open = uf_net_open,
158 .ndo_stop = uf_net_stop,
159 .ndo_start_xmit = uf_net_xmit,
160 .ndo_do_ioctl = uf_net_ioctl,
161 .ndo_get_stats = uf_net_get_stats, /* called by /proc/net/dev */
162 .ndo_set_rx_mode = uf_set_multicast_list,
163 .ndo_select_queue = uf_net_select_queue,
164 };
165
166 static u8 oui_rfc1042[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
167 static u8 oui_8021h[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
168
169
170 /* Callback for event logging to blocking clients */
171 static void netdev_mlme_event_handler(ul_client_t *client,
172 const u8 *sig_packed, int sig_len,
173 const bulk_data_param_t *bulkdata,
174 int dir);
175
176 #ifdef CSR_SUPPORT_WEXT
177 /* Declare netdev_notifier block which will contain the state change
178 * handler callback function
179 */
180 static struct notifier_block uf_netdev_notifier;
181 #endif
182
183 /*
184 * ---------------------------------------------------------------------------
185 * uf_alloc_netdevice
186 *
187 * Allocate memory for the net_device and device private structs
188 * for this interface.
189 * Fill in the fields, but don't register the interface yet.
190 * We need to configure the UniFi first.
191 *
192 * Arguments:
193 * sdio_dev Pointer to SDIO context handle to use for all
194 * SDIO ops.
195 * bus_id A small number indicating the SDIO card position on the
196 * bus. Typically this is the slot number, e.g. 0, 1 etc.
197 * Valid values are 0 to MAX_UNIFI_DEVS-1.
198 *
199 * Returns:
200 * Pointer to device private struct.
201 *
202 * Notes:
203 * The net_device and device private structs are allocated together
204 * and should be freed by freeing the net_device pointer.
205 * ---------------------------------------------------------------------------
206 */
207 unifi_priv_t *
208 uf_alloc_netdevice(CsrSdioFunction *sdio_dev, int bus_id)
209 {
210 struct net_device *dev;
211 unifi_priv_t *priv;
212 netInterface_priv_t *interfacePriv;
213 #ifdef CSR_SUPPORT_WEXT
214 int rc;
215 #endif
216 unsigned char i; /* loop index */
217
218 /*
219 * Allocate netdevice struct, assign name template and
220 * setup as an ethernet device.
221 * The net_device and private structs are zeroed. Ether_setup() then
222 * sets up ethernet handlers and values.
223 * The RedHat 9 redhat-config-network tool doesn't recognise wlan* devices,
224 * so use "eth*" (like other wireless extns drivers).
225 */
226 UF_ALLOC_NETDEV(dev, sizeof(unifi_priv_t)+sizeof(netInterface_priv_t), "%d", ether_setup, UNIFI_TRAFFIC_Q_MAX);
227
228 if (dev == NULL) {
229 return NULL;
230 }
231
232 /* Set up back pointer from priv to netdev */
233 interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
234 priv = (unifi_priv_t *)(interfacePriv + 1);
235 interfacePriv->privPtr = priv;
236 interfacePriv->InterfaceTag = 0;
237
238
239 /* Initialize all supported netdev interface to be NULL */
240 for(i=0; i<CSR_WIFI_NUM_INTERFACES; i++) {
241 priv->netdev[i] = NULL;
242 priv->interfacePriv[i] = NULL;
243 }
244 priv->netdev[0] = dev;
245 priv->interfacePriv[0] = interfacePriv;
246
247 /* Setup / override net_device fields */
248 dev->netdev_ops = &uf_netdev_ops;
249
250 #ifdef CSR_SUPPORT_WEXT
251 dev->wireless_handlers = &unifi_iw_handler_def;
252 #if IW_HANDLER_VERSION < 6
253 dev->get_wireless_stats = unifi_get_wireless_stats;
254 #endif /* IW_HANDLER_VERSION */
255 #endif /* CSR_SUPPORT_WEXT */
256
257 /* This gives us enough headroom to add the 802.11 header */
258 dev->needed_headroom = 32;
259
260 /* Use bus_id as instance number */
261 priv->instance = bus_id;
262 /* Store SDIO pointer to pass in the core */
263 priv->sdio = sdio_dev;
264
265 sdio_dev->driverData = (void*)priv;
266 /* Consider UniFi to be uninitialised */
267 priv->init_progress = UNIFI_INIT_NONE;
268
269 priv->prev_queue = 0;
270
271 /*
272 * Initialise the clients structure array.
273 * We do not need protection around ul_init_clients() because
274 * the character device can not be used until uf_alloc_netdevice()
275 * returns and Unifi_instances[bus_id]=priv is set, since unifi_open()
276 * will return -ENODEV.
277 */
278 ul_init_clients(priv);
279
280 /*
281 * Register a new ul client to send the multicast list signals.
282 * Note: priv->instance must be set before calling this.
283 */
284 priv->netdev_client = ul_register_client(priv,
285 0,
286 netdev_mlme_event_handler);
287 if (priv->netdev_client == NULL) {
288 unifi_error(priv,
289 "Failed to register a unifi client for background netdev processing\n");
290 free_netdev(priv->netdev[0]);
291 return NULL;
292 }
293 unifi_trace(priv, UDBG2, "Netdev %p client (id:%d s:0x%X) is registered\n",
294 dev, priv->netdev_client->client_id, priv->netdev_client->sender_id);
295
296 priv->sta_wmm_capabilities = 0;
297
298 #if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_SUPPORT_SME))
299 priv->wapi_multicast_filter = 0;
300 priv->wapi_unicast_filter = 0;
301 priv->wapi_unicast_queued_pkt_filter = 0;
302 #ifdef CSR_WIFI_SECURITY_WAPI_QOSCTRL_MIC_WORKAROUND
303 priv->isWapiConnection = FALSE;
304 #endif
305 #endif
306
307 /* Enable all queues by default */
308 interfacePriv->queueEnabled[0] = 1;
309 interfacePriv->queueEnabled[1] = 1;
310 interfacePriv->queueEnabled[2] = 1;
311 interfacePriv->queueEnabled[3] = 1;
312
313 #ifdef CSR_SUPPORT_SME
314 priv->allPeerDozing = 0;
315 #endif
316 /*
317 * Initialise the OS private struct.
318 */
319 /*
320 * Instead of deciding in advance to use 11bg or 11a, we could do a more
321 * clever scan on both radios.
322 */
323 if (use_5g) {
324 priv->if_index = CSR_INDEX_5G;
325 unifi_info(priv, "Using the 802.11a radio\n");
326 } else {
327 priv->if_index = CSR_INDEX_2G4;
328 }
329
330 /* Initialise bh thread structure */
331 priv->bh_thread.thread_task = NULL;
332 priv->bh_thread.block_thread = 1;
333 init_waitqueue_head(&priv->bh_thread.wakeup_q);
334 priv->bh_thread.wakeup_flag = 0;
335 sprintf(priv->bh_thread.name, "uf_bh_thread");
336
337 /* reset the connected state for the interface */
338 interfacePriv->connected = UnifiConnectedUnknown; /* -1 unknown, 0 no, 1 yes */
339
340 #ifdef USE_DRIVER_LOCK
341 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)
342 sema_init(&priv->lock, 1);
343 #else
344 init_MUTEX(&priv->lock);
345 #endif
346 #endif /* USE_DRIVER_LOCK */
347
348 spin_lock_init(&priv->send_signal_lock);
349
350 spin_lock_init(&priv->m4_lock);
351 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)
352 sema_init(&priv->ba_mutex, 1);
353 #else
354 init_MUTEX(&priv->ba_mutex);
355 #endif
356
357 #if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_WIFI_SECURITY_WAPI_SW_ENCRYPTION))
358 spin_lock_init(&priv->wapi_lock);
359 #endif
360
361 #ifdef CSR_SUPPORT_SME
362 spin_lock_init(&priv->staRecord_lock);
363 spin_lock_init(&priv->tx_q_lock);
364 #endif
365
366 /* Create the Traffic Analysis workqueue */
367 priv->unifi_workqueue = create_singlethread_workqueue("unifi_workq");
368 if (priv->unifi_workqueue == NULL) {
369 /* Deregister priv->netdev_client */
370 ul_deregister_client(priv->netdev_client);
371 free_netdev(priv->netdev[0]);
372 return NULL;
373 }
374
375 #ifdef CSR_SUPPORT_SME
376 /* Create the Multicast Addresses list work structure */
377 INIT_WORK(&priv->multicast_list_task, uf_multicast_list_wq);
378
379 /* Create m4 buffering work structure */
380 INIT_WORK(&interfacePriv->send_m4_ready_task, uf_send_m4_ready_wq);
381
382 #if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_WIFI_SECURITY_WAPI_SW_ENCRYPTION))
383 /* Create work structure to buffer the WAPI data packets to be sent to SME for encryption */
384 INIT_WORK(&interfacePriv->send_pkt_to_encrypt, uf_send_pkt_to_encrypt);
385 #endif
386 #endif
387
388 priv->ref_count = 1;
389
390 priv->amp_client = NULL;
391 priv->coredump_mode = 0;
392 priv->ptest_mode = 0;
393 priv->wol_suspend = FALSE;
394 INIT_LIST_HEAD(&interfacePriv->rx_uncontrolled_list);
395 INIT_LIST_HEAD(&interfacePriv->rx_controlled_list);
396 sema_init(&priv->rx_q_sem, 1);
397
398 #ifdef CSR_SUPPORT_WEXT
399 interfacePriv->netdev_callback_registered = FALSE;
400 interfacePriv->wait_netdev_change = FALSE;
401 /* Register callback for netdevice state changes */
402 if ((rc = register_netdevice_notifier(&uf_netdev_notifier)) == 0) {
403 interfacePriv->netdev_callback_registered = TRUE;
404 }
405 else {
406 unifi_warning(priv, "Failed to register netdevice notifier : %d %p\n", rc, dev);
407 }
408 #endif /* CSR_SUPPORT_WEXT */
409
410 #ifdef CSR_WIFI_SPLIT_PATCH
411 /* set it to some invalid value */
412 priv->pending_mode_set.common.destination = 0xaaaa;
413 #endif
414
415 return priv;
416 } /* uf_alloc_netdevice() */
417
418 /*
419 *---------------------------------------------------------------------------
420 * uf_alloc_netdevice_for_other_interfaces
421 *
422 * Allocate memory for the net_device and device private structs
423 * for this interface.
424 * Fill in the fields, but don't register the interface yet.
425 * We need to configure the UniFi first.
426 *
427 * Arguments:
428 * interfaceTag Interface number.
429 * sdio_dev Pointer to SDIO context handle to use for all
430 * SDIO ops.
431 * bus_id A small number indicating the SDIO card position on the
432 * bus. Typically this is the slot number, e.g. 0, 1 etc.
433 * Valid values are 0 to MAX_UNIFI_DEVS-1.
434 *
435 * Returns:
436 * Pointer to device private struct.
437 *
438 * Notes:
439 * The device private structure contains the interfaceTag and pointer to the unifi_priv
440 * structure created allocated by net_device od interface0.
441 * The net_device and device private structs are allocated together
442 * and should be freed by freeing the net_device pointer.
443 * ---------------------------------------------------------------------------
444 */
445 u8
446 uf_alloc_netdevice_for_other_interfaces(unifi_priv_t *priv, u16 interfaceTag)
447 {
448 struct net_device *dev;
449 netInterface_priv_t *interfacePriv;
450
451 /*
452 * Allocate netdevice struct, assign name template and
453 * setup as an ethernet device.
454 * The net_device and private structs are zeroed. Ether_setup() then
455 * sets up ethernet handlers and values.
456 * The RedHat 9 redhat-config-network tool doesn't recognise wlan* devices,
457 * so use "eth*" (like other wireless extns drivers).
458 */
459 UF_ALLOC_NETDEV(dev, sizeof(netInterface_priv_t), "%d", ether_setup, 1);
460 if (dev == NULL) {
461 return FALSE;
462 }
463
464 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
465 unifi_error(priv, "uf_alloc_netdevice_for_other_interfaces bad interfaceTag\n");
466 return FALSE;
467 }
468
469 /* Set up back pointer from priv to netdev */
470 interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
471 interfacePriv->privPtr = priv;
472 interfacePriv->InterfaceTag = interfaceTag;
473 priv->netdev[interfaceTag] = dev;
474 priv->interfacePriv[interfacePriv->InterfaceTag] = interfacePriv;
475
476 /* reset the connected state for the interface */
477 interfacePriv->connected = UnifiConnectedUnknown; /* -1 unknown, 0 no, 1 yes */
478 INIT_LIST_HEAD(&interfacePriv->rx_uncontrolled_list);
479 INIT_LIST_HEAD(&interfacePriv->rx_controlled_list);
480
481 /* Setup / override net_device fields */
482 dev->netdev_ops = &uf_netdev_ops;
483
484 #ifdef CSR_SUPPORT_WEXT
485 dev->wireless_handlers = &unifi_iw_handler_def;
486 #if IW_HANDLER_VERSION < 6
487 dev->get_wireless_stats = unifi_get_wireless_stats;
488 #endif /* IW_HANDLER_VERSION */
489 #endif /* CSR_SUPPORT_WEXT */
490 return TRUE;
491 } /* uf_alloc_netdevice() */
492
493
494
495 /*
496 * ---------------------------------------------------------------------------
497 * uf_free_netdevice
498 *
499 * Unregister the network device and free the memory allocated for it.
500 * NB This includes the memory for the priv struct.
501 *
502 * Arguments:
503 * priv Device private pointer.
504 *
505 * Returns:
506 * None.
507 * ---------------------------------------------------------------------------
508 */
509 int
510 uf_free_netdevice(unifi_priv_t *priv)
511 {
512 int i;
513 unsigned long flags;
514
515 func_enter();
516
517 unifi_trace(priv, UDBG1, "uf_free_netdevice\n");
518
519 if (!priv) {
520 return -EINVAL;
521 }
522
523 /*
524 * Free any buffers used for holding firmware
525 */
526 uf_release_firmware_files(priv);
527
528 #if (defined CSR_SUPPORT_SME) && (defined CSR_SUPPORT_WEXT)
529 if (priv->connection_config.mlmeAssociateReqInformationElements) {
530 kfree(priv->connection_config.mlmeAssociateReqInformationElements);
531 }
532 priv->connection_config.mlmeAssociateReqInformationElements = NULL;
533 priv->connection_config.mlmeAssociateReqInformationElementsLength = 0;
534
535 if (priv->mib_data.length) {
536 vfree(priv->mib_data.data);
537 }
538 priv->mib_data.data = NULL;
539 priv->mib_data.length = 0;
540
541 #endif /* CSR_SUPPORT_SME && CSR_SUPPORT_WEXT*/
542
543 /* Free any bulkdata buffers allocated for M4 caching */
544 spin_lock_irqsave(&priv->m4_lock, flags);
545 for (i = 0; i < CSR_WIFI_NUM_INTERFACES; i++) {
546 netInterface_priv_t *interfacePriv = priv->interfacePriv[i];
547 if (interfacePriv->m4_bulk_data.data_length > 0) {
548 unifi_trace(priv, UDBG5, "uf_free_netdevice: free M4 bulkdata %d\n", i);
549 unifi_net_data_free(priv, &interfacePriv->m4_bulk_data);
550 }
551 }
552 spin_unlock_irqrestore(&priv->m4_lock, flags);
553
554 #if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_WIFI_SECURITY_WAPI_SW_ENCRYPTION))
555 /* Free any bulkdata buffers allocated for M4 caching */
556 spin_lock_irqsave(&priv->wapi_lock, flags);
557 for (i = 0; i < CSR_WIFI_NUM_INTERFACES; i++) {
558 netInterface_priv_t *interfacePriv = priv->interfacePriv[i];
559 if (interfacePriv->wapi_unicast_bulk_data.data_length > 0) {
560 unifi_trace(priv, UDBG5, "uf_free_netdevice: free WAPI PKT bulk data %d\n", i);
561 unifi_net_data_free(priv, &interfacePriv->wapi_unicast_bulk_data);
562 }
563 }
564 spin_unlock_irqrestore(&priv->wapi_lock, flags);
565 #endif
566
567 #ifdef CSR_SUPPORT_WEXT
568 /* Unregister callback for netdevice state changes */
569 unregister_netdevice_notifier(&uf_netdev_notifier);
570 #endif /* CSR_SUPPORT_WEXT */
571
572 #ifdef CSR_SUPPORT_SME
573 /* Cancel work items and destroy the workqueue */
574 cancel_work_sync(&priv->multicast_list_task);
575 #endif
576 /* Destroy the workqueues. */
577 flush_workqueue(priv->unifi_workqueue);
578 destroy_workqueue(priv->unifi_workqueue);
579
580 /* Free up netdev in reverse order: priv is allocated with netdev[0].
581 * So, netdev[0] should be freed after all other netdevs are freed up
582 */
583 for (i=CSR_WIFI_NUM_INTERFACES-1; i>=0; i--) {
584 /*Free the netdev struct and priv, which are all one lump*/
585 if (priv->netdev[i]) {
586 unifi_error(priv, "uf_free_netdevice: netdev %d %p\n", i, priv->netdev[i]);
587 free_netdev(priv->netdev[i]);
588 }
589 }
590
591 func_exit();
592 return 0;
593 } /* uf_free_netdevice() */
594
595
596 /*
597 * ---------------------------------------------------------------------------
598 * uf_net_open
599 *
600 * Called when userland does "ifconfig wlan0 up".
601 *
602 * Arguments:
603 * dev Device pointer.
604 *
605 * Returns:
606 * None.
607 * ---------------------------------------------------------------------------
608 */
609 static int
610 uf_net_open(struct net_device *dev)
611 {
612 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
613 unifi_priv_t *priv = interfacePriv->privPtr;
614
615 func_enter();
616
617 /* If we haven't finished UniFi initialisation, we can't start */
618 if (priv->init_progress != UNIFI_INIT_COMPLETED) {
619 unifi_warning(priv, "%s: unifi not ready, failing net_open\n", __FUNCTION__);
620 return -EINVAL;
621 }
622
623 #if (defined CSR_NATIVE_LINUX) && (defined UNIFI_SNIFF_ARPHRD) && defined(CSR_SUPPORT_WEXT)
624 /*
625 * To sniff, the user must do "iwconfig mode monitor", which sets
626 * priv->wext_conf.mode to IW_MODE_MONITOR.
627 * Then he/she must do "ifconfig ethn up", which calls this fn.
628 * There is no point in starting the sniff with SNIFFJOIN until
629 * this point.
630 */
631 if (priv->wext_conf.mode == IW_MODE_MONITOR) {
632 int err;
633 err = uf_start_sniff(priv);
634 if (err) {
635 return err;
636 }
637 netif_carrier_on(dev);
638 }
639 #endif
640
641 #ifdef CSR_SUPPORT_WEXT
642 if (interfacePriv->wait_netdev_change) {
643 unifi_trace(priv, UDBG1, "%s: Waiting for NETDEV_CHANGE, assume connected\n",
644 __FUNCTION__);
645 interfacePriv->connected = UnifiConnected;
646 interfacePriv->wait_netdev_change = FALSE;
647 }
648 #endif
649
650 UF_NETIF_TX_START_ALL_QUEUES(dev);
651
652 func_exit();
653 return 0;
654 } /* uf_net_open() */
655
656
657 static int
658 uf_net_stop(struct net_device *dev)
659 {
660 #if defined(CSR_NATIVE_LINUX) && defined(UNIFI_SNIFF_ARPHRD) && defined(CSR_SUPPORT_WEXT)
661 netInterface_priv_t *interfacePriv = (netInterface_priv_t*)netdev_priv(dev);
662 unifi_priv_t *priv = interfacePriv->privPtr;
663
664 func_enter();
665
666 /* Stop sniffing if in Monitor mode */
667 if (priv->wext_conf.mode == IW_MODE_MONITOR) {
668 if (priv->card) {
669 int err;
670 err = unifi_reset_state(priv, dev->dev_addr, 1);
671 if (err) {
672 return err;
673 }
674 }
675 }
676 #else
677 func_enter();
678 #endif
679
680 UF_NETIF_TX_STOP_ALL_QUEUES(dev);
681
682 func_exit();
683 return 0;
684 } /* uf_net_stop() */
685
686
687 /* This is called after the WE handlers */
688 static int
689 uf_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
690 {
691 int rc;
692
693 rc = -EOPNOTSUPP;
694
695 return rc;
696 } /* uf_net_ioctl() */
697
698
699
700 static struct net_device_stats *
701 uf_net_get_stats(struct net_device *dev)
702 {
703 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
704
705 return &interfacePriv->stats;
706 } /* uf_net_get_stats() */
707
708 static CSR_PRIORITY uf_get_packet_priority(unifi_priv_t *priv, netInterface_priv_t *interfacePriv, struct sk_buff *skb, const int proto)
709 {
710 CSR_PRIORITY priority = CSR_CONTENTION;
711
712 func_enter();
713 priority = (CSR_PRIORITY) (skb->priority >> 5);
714
715 if (priority == CSR_QOS_UP0) { /* 0 */
716
717 unifi_trace(priv, UDBG5, "uf_get_packet_priority: proto = 0x%.4X\n", proto);
718
719 switch (proto) {
720 case 0x0800: /* IPv4 */
721 case 0x814C: /* SNMP */
722 case 0x880C: /* GSMP */
723 priority = (CSR_PRIORITY) (skb->data[1 + ETH_HLEN] >> 5);
724 break;
725
726 case 0x8100: /* VLAN */
727 priority = (CSR_PRIORITY) (skb->data[0 + ETH_HLEN] >> 5);
728 break;
729
730 case 0x86DD: /* IPv6 */
731 priority = (CSR_PRIORITY) ((skb->data[0 + ETH_HLEN] & 0x0E) >> 1);
732 break;
733
734 default:
735 priority = CSR_QOS_UP0;
736 break;
737 }
738 }
739
740 /* Check if we are allowed to transmit on this AC. Because of ACM we may have to downgrade to a lower
741 * priority */
742 if (interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_STA ||
743 interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI) {
744 unifi_TrafficQueue queue;
745
746 /* Keep trying lower priorities until we find a queue
747 * Priority to queue mapping is 1,2 - BK, 0,3 - BE, 4,5 - VI, 6,7 - VO */
748 queue = unifi_frame_priority_to_queue(priority);
749
750 while (queue > UNIFI_TRAFFIC_Q_BK && !interfacePriv->queueEnabled[queue]) {
751 queue--;
752 priority = unifi_get_default_downgrade_priority(queue);
753 }
754 }
755
756 unifi_trace(priv, UDBG5, "Packet priority = %d\n", priority);
757
758 func_exit();
759 return priority;
760 }
761
762 /*
763 */
764 /*
765 * ---------------------------------------------------------------------------
766 * get_packet_priority
767 *
768 * Arguments:
769 * priv private data area of functional driver
770 * skb socket buffer
771 * ehdr ethernet header to fetch protocol
772 * interfacePriv For accessing station record database
773 *
774 *
775 * Returns:
776 * CSR_PRIORITY.
777 * ---------------------------------------------------------------------------
778 */
779 CSR_PRIORITY
780 get_packet_priority(unifi_priv_t *priv, struct sk_buff *skb, const struct ethhdr *ehdr, netInterface_priv_t *interfacePriv)
781 {
782 CSR_PRIORITY priority = CSR_CONTENTION;
783 const int proto = ntohs(ehdr->h_proto);
784
785 u8 interfaceMode = interfacePriv->interfaceMode;
786
787 func_enter();
788
789 /* Priority Mapping for all the Modes */
790 switch(interfaceMode)
791 {
792 case CSR_WIFI_ROUTER_CTRL_MODE_STA:
793 case CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI:
794 unifi_trace(priv, UDBG4, "mode is STA \n");
795 if ((priv->sta_wmm_capabilities & QOS_CAPABILITY_WMM_ENABLED) == 1) {
796 priority = uf_get_packet_priority(priv, interfacePriv, skb, proto);
797 } else {
798 priority = CSR_CONTENTION;
799 }
800 break;
801 #ifdef CSR_SUPPORT_SME
802 case CSR_WIFI_ROUTER_CTRL_MODE_AP:
803 case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
804 case CSR_WIFI_ROUTER_CTRL_MODE_IBSS:
805 {
806 CsrWifiRouterCtrlStaInfo_t * dstStaInfo =
807 CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,ehdr->h_dest, interfacePriv->InterfaceTag);
808 unifi_trace(priv, UDBG4, "mode is AP \n");
809 if (!(ehdr->h_dest[0] & 0x01) && dstStaInfo && dstStaInfo->wmmOrQosEnabled) {
810 /* If packet is not Broadcast/multicast */
811 priority = uf_get_packet_priority(priv, interfacePriv, skb, proto);
812 } else {
813 /* Since packet destination is not QSTA, set priority to CSR_CONTENTION */
814 unifi_trace(priv, UDBG4, "Destination is not QSTA or BroadCast/Multicast\n");
815 priority = CSR_CONTENTION;
816 }
817 }
818 break;
819 #endif
820 default:
821 unifi_trace(priv, UDBG3, " mode unknown in %s func, mode=%x\n", __FUNCTION__, interfaceMode);
822 }
823 unifi_trace(priv, UDBG5, "priority = %x\n", priority);
824
825 func_exit();
826 return priority;
827 }
828
829 /*
830 * ---------------------------------------------------------------------------
831 * uf_net_select_queue
832 *
833 * Called by the kernel to select which queue to put the packet in
834 *
835 * Arguments:
836 * dev Device pointer
837 * skb Packet
838 *
839 * Returns:
840 * Queue index
841 * ---------------------------------------------------------------------------
842 */
843 static u16
844 uf_net_select_queue(struct net_device *dev, struct sk_buff *skb)
845 {
846 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
847 unifi_priv_t *priv = (unifi_priv_t *)interfacePriv->privPtr;
848 struct ethhdr ehdr;
849 unifi_TrafficQueue queue;
850 int proto;
851 CSR_PRIORITY priority;
852
853 func_enter();
854
855 memcpy(&ehdr, skb->data, ETH_HLEN);
856 proto = ntohs(ehdr.h_proto);
857
858 /* 802.1x - apply controlled/uncontrolled port rules */
859 if ((proto != ETH_P_PAE)
860 #ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
861 && (proto != ETH_P_WAI)
862 #endif
863 ) {
864 /* queues 0 - 3 */
865 priority = get_packet_priority(priv, skb, &ehdr, interfacePriv);
866 queue = unifi_frame_priority_to_queue(priority);
867 } else {
868 /* queue 4 */
869 queue = UNIFI_TRAFFIC_Q_EAPOL;
870 }
871
872
873 func_exit();
874 return (u16)queue;
875 } /* uf_net_select_queue() */
876
877 int
878 skb_add_llc_snap(struct net_device *dev, struct sk_buff *skb, int proto)
879 {
880 llc_snap_hdr_t *snap;
881 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
882 unifi_priv_t *priv = interfacePriv->privPtr;
883 int headroom;
884
885 /* get the headroom available in skb */
886 headroom = skb_headroom(skb);
887 /* step 1: classify ether frame, DIX or 802.3? */
888
889 if (proto < 0x600) {
890 /* codes <= 1500 reserved for 802.3 lengths */
891 /* it's 802.3, pass ether payload unchanged, */
892 unifi_trace(priv, UDBG3, "802.3 len: %d\n", skb->len);
893
894 /* leave off any PAD octets. */
895 skb_trim(skb, proto);
896 } else if (proto == ETH_P_8021Q) {
897
898 /* Store the VLAN SNAP (should be 87-65). */
899 u16 vlan_snap = *(u16*)skb->data;
900 /* check for headroom availability before skb_push 14 = (4 + 10) */
901 if (headroom < 14) {
902 unifi_trace(priv, UDBG3, "cant append vlan snap: debug\n");
903 return -1;
904 }
905 /* Add AA-AA-03-00-00-00 */
906 snap = (llc_snap_hdr_t *)skb_push(skb, 4);
907 snap->dsap = snap->ssap = 0xAA;
908 snap->ctrl = 0x03;
909 memcpy(snap->oui, oui_rfc1042, P80211_OUI_LEN);
910
911 /* Add AA-AA-03-00-00-00 */
912 snap = (llc_snap_hdr_t *)skb_push(skb, 10);
913 snap->dsap = snap->ssap = 0xAA;
914 snap->ctrl = 0x03;
915 memcpy(snap->oui, oui_rfc1042, P80211_OUI_LEN);
916
917 /* Add the VLAN specific information */
918 snap->protocol = htons(proto);
919 *(u16*)(snap + 1) = vlan_snap;
920
921 } else
922 {
923 /* it's DIXII, time for some conversion */
924 unifi_trace(priv, UDBG3, "DIXII len: %d\n", skb->len);
925
926 /* check for headroom availability before skb_push */
927 if (headroom < sizeof(llc_snap_hdr_t)) {
928 unifi_trace(priv, UDBG3, "cant append snap: debug\n");
929 return -1;
930 }
931 /* tack on SNAP */
932 snap = (llc_snap_hdr_t *)skb_push(skb, sizeof(llc_snap_hdr_t));
933 snap->dsap = snap->ssap = 0xAA;
934 snap->ctrl = 0x03;
935 /* Use the appropriate OUI. */
936 if ((proto == ETH_P_AARP) || (proto == ETH_P_IPX)) {
937 memcpy(snap->oui, oui_8021h, P80211_OUI_LEN);
938 } else {
939 memcpy(snap->oui, oui_rfc1042, P80211_OUI_LEN);
940 }
941 snap->protocol = htons(proto);
942 }
943
944 return 0;
945 } /* skb_add_llc_snap() */
946
947 #ifdef CSR_SUPPORT_SME
948 static int
949 _identify_sme_ma_pkt_ind(unifi_priv_t *priv,
950 const s8 *oui, u16 protocol,
951 const CSR_SIGNAL *signal,
952 bulk_data_param_t *bulkdata,
953 const unsigned char *daddr,
954 const unsigned char *saddr)
955 {
956 CSR_MA_PACKET_INDICATION *pkt_ind = (CSR_MA_PACKET_INDICATION*)&signal->u.MaPacketIndication;
957 int r;
958 u8 i;
959
960 unifi_trace(priv, UDBG5,
961 "_identify_sme_ma_pkt_ind -->\n");
962 for (i = 0; i < MAX_MA_UNIDATA_IND_FILTERS; i++) {
963 if (priv->sme_unidata_ind_filters[i].in_use) {
964 if (!memcmp(oui, priv->sme_unidata_ind_filters[i].oui, 3) &&
965 (protocol == priv->sme_unidata_ind_filters[i].protocol)) {
966
967 /* Send to client */
968 if (priv->sme_cli) {
969 /*
970 * Pass the packet to the SME, using unifi_sys_ma_unitdata_ind().
971 * The frame needs to be converted according to the encapsulation.
972 */
973 unifi_trace(priv, UDBG1,
974 "_identify_sme_ma_pkt_ind: handle=%d, encap=%d, proto=%x\n",
975 i, priv->sme_unidata_ind_filters[i].encapsulation,
976 priv->sme_unidata_ind_filters[i].protocol);
977 if (priv->sme_unidata_ind_filters[i].encapsulation == CSR_WIFI_ROUTER_ENCAPSULATION_ETHERNET) {
978 struct sk_buff *skb;
979 /* The translation is performed on skb... */
980 skb = (struct sk_buff*)bulkdata->d[0].os_net_buf_ptr;
981 skb->len = bulkdata->d[0].data_length;
982
983 unifi_trace(priv, UDBG1,
984 "_identify_sme_ma_pkt_ind: skb_80211_to_ether -->\n");
985 r = skb_80211_to_ether(priv, skb, daddr, saddr,
986 signal, bulkdata);
987 unifi_trace(priv, UDBG1,
988 "_identify_sme_ma_pkt_ind: skb_80211_to_ether <--\n");
989 if (r) {
990 return -EINVAL;
991 }
992
993 /* ... but we indicate buffer and length */
994 bulkdata->d[0].os_data_ptr = skb->data;
995 bulkdata->d[0].data_length = skb->len;
996 } else {
997 /* Add the MAC addresses before the SNAP */
998 bulkdata->d[0].os_data_ptr -= 2*ETH_ALEN;
999 bulkdata->d[0].data_length += 2*ETH_ALEN;
1000 memcpy((void*)bulkdata->d[0].os_data_ptr, daddr, ETH_ALEN);
1001 memcpy((void*)bulkdata->d[0].os_data_ptr + ETH_ALEN, saddr, ETH_ALEN);
1002 }
1003
1004 unifi_trace(priv, UDBG1,
1005 "_identify_sme_ma_pkt_ind: unifi_sys_ma_pkt_ind -->\n");
1006 CsrWifiRouterMaPacketIndSend(priv->sme_unidata_ind_filters[i].appHandle,
1007 (pkt_ind->VirtualInterfaceIdentifier & 0xff),
1008 i,
1009 pkt_ind->ReceptionStatus,
1010 bulkdata->d[0].data_length,
1011 (u8*)bulkdata->d[0].os_data_ptr,
1012 NULL,
1013 pkt_ind->Rssi,
1014 pkt_ind->Snr,
1015 pkt_ind->ReceivedRate);
1016
1017
1018 unifi_trace(priv, UDBG1,
1019 "_identify_sme_ma_pkt_ind: unifi_sys_ma_pkt_ind <--\n");
1020 }
1021
1022 return 1;
1023 }
1024 }
1025 }
1026
1027 return -1;
1028 }
1029 #endif /* CSR_SUPPORT_SME */
1030
1031 /*
1032 * ---------------------------------------------------------------------------
1033 * skb_80211_to_ether
1034 *
1035 * Make sure the received frame is in Ethernet (802.3) form.
1036 * De-encapsulates SNAP if necessary, adds a ethernet header.
1037 * The source buffer should not contain an 802.11 MAC header
1038 *
1039 * Arguments:
1040 * payload Pointer to packet data received from UniFi.
1041 * payload_length Number of bytes of data received from UniFi.
1042 * daddr Destination MAC address.
1043 * saddr Source MAC address.
1044 *
1045 * Returns:
1046 * 0 on success, -1 if the packet is bad and should be dropped,
1047 * 1 if the packet was forwarded to the SME or AMP client.
1048 * ---------------------------------------------------------------------------
1049 */
1050 int
1051 skb_80211_to_ether(unifi_priv_t *priv, struct sk_buff *skb,
1052 const unsigned char *daddr, const unsigned char *saddr,
1053 const CSR_SIGNAL *signal,
1054 bulk_data_param_t *bulkdata)
1055 {
1056 unsigned char *payload;
1057 int payload_length;
1058 struct ethhdr *eth;
1059 llc_snap_hdr_t *snap;
1060 int headroom;
1061 #define UF_VLAN_LLC_HEADER_SIZE 18
1062 static const u8 vlan_inner_snap[] = { 0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00 };
1063 #if defined(CSR_NATIVE_SOFTMAC) && defined(CSR_SUPPORT_SME)
1064 const CSR_MA_PACKET_INDICATION *pkt_ind = &signal->u.MaPacketIndication;
1065 #endif
1066
1067 if(skb== NULL || daddr == NULL || saddr == NULL){
1068 unifi_error(priv,"skb_80211_to_ether: PBC fail\n");
1069 return 1;
1070 }
1071
1072 payload = skb->data;
1073 payload_length = skb->len;
1074
1075 snap = (llc_snap_hdr_t *)payload;
1076 eth = (struct ethhdr *)payload;
1077
1078 /* get the skb headroom size */
1079 headroom = skb_headroom(skb);
1080
1081 /*
1082 * Test for the various encodings
1083 */
1084 if ((payload_length >= sizeof(llc_snap_hdr_t)) &&
1085 (snap->dsap == 0xAA) &&
1086 (snap->ssap == 0xAA) &&
1087 (snap->ctrl == 0x03) &&
1088 (snap->oui[0] == 0) &&
1089 (snap->oui[1] == 0) &&
1090 ((snap->oui[2] == 0) || (snap->oui[2] == 0xF8)))
1091 {
1092 /* AppleTalk AARP (2) or IPX SNAP */
1093 if ((snap->oui[2] == 0) &&
1094 ((ntohs(snap->protocol) == ETH_P_AARP) || (ntohs(snap->protocol) == ETH_P_IPX)))
1095 {
1096 u16 len;
1097
1098 unifi_trace(priv, UDBG3, "%s len: %d\n",
1099 (ntohs(snap->protocol) == ETH_P_AARP) ? "ETH_P_AARP" : "ETH_P_IPX",
1100 payload_length);
1101
1102 /* check for headroom availability before skb_push */
1103 if (headroom < (2 * ETH_ALEN + 2)) {
1104 unifi_warning(priv, "headroom not available to skb_push ether header\n");
1105 return -1;
1106 }
1107
1108 /* Add 802.3 header and leave full payload */
1109 len = htons(skb->len);
1110 memcpy(skb_push(skb, 2), &len, 2);
1111 memcpy(skb_push(skb, ETH_ALEN), saddr, ETH_ALEN);
1112 memcpy(skb_push(skb, ETH_ALEN), daddr, ETH_ALEN);
1113
1114 return 0;
1115 }
1116 /* VLAN-tagged IP */
1117 if ((snap->oui[2] == 0) && (ntohs(snap->protocol) == ETH_P_8021Q))
1118 {
1119 /*
1120 * The translation doesn't change the packet length, so is done in-place.
1121 *
1122 * Example header (from Std 802.11-2007 Annex M):
1123 * AA-AA-03-00-00-00-81-00-87-65-AA-AA-03-00-00-00-08-06
1124 * -------SNAP-------p1-p1-ll-ll-------SNAP--------p2-p2
1125 * dd-dd-dd-dd-dd-dd-aa-aa-aa-aa-aa-aa-p1-p1-ll-ll-p2-p2
1126 * dd-dd-dd-dd-dd-dd-aa-aa-aa-aa-aa-aa-81-00-87-65-08-06
1127 */
1128 u16 vlan_snap;
1129
1130 if (payload_length < UF_VLAN_LLC_HEADER_SIZE) {
1131 unifi_warning(priv, "VLAN SNAP header too short: %d bytes\n", payload_length);
1132 return -1;
1133 }
1134
1135 if (memcmp(payload + 10, vlan_inner_snap, 6)) {
1136 unifi_warning(priv, "VLAN malformatted SNAP header.\n");
1137 return -1;
1138 }
1139
1140 unifi_trace(priv, UDBG3, "VLAN SNAP: %02x-%02x\n", payload[8], payload[9]);
1141 unifi_trace(priv, UDBG3, "VLAN len: %d\n", payload_length);
1142
1143 /* Create the 802.3 header */
1144
1145 vlan_snap = *((u16*)(payload + 8));
1146
1147 /* Create LLC header without byte-swapping */
1148 eth->h_proto = snap->protocol;
1149
1150 memcpy(eth->h_dest, daddr, ETH_ALEN);
1151 memcpy(eth->h_source, saddr, ETH_ALEN);
1152 *(u16*)(eth + 1) = vlan_snap;
1153 return 0;
1154 }
1155
1156 /* it's a SNAP + RFC1042 frame */
1157 unifi_trace(priv, UDBG3, "SNAP+RFC1042 len: %d\n", payload_length);
1158
1159 /* chop SNAP+llc header from skb. */
1160 skb_pull(skb, sizeof(llc_snap_hdr_t));
1161
1162 /* Since skb_pull called above to chop snap+llc, no need to check for headroom
1163 * availability before skb_push
1164 */
1165 /* create 802.3 header at beginning of skb. */
1166 eth = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1167 memcpy(eth->h_dest, daddr, ETH_ALEN);
1168 memcpy(eth->h_source, saddr, ETH_ALEN);
1169 /* Copy protocol field without byte-swapping */
1170 eth->h_proto = snap->protocol;
1171 } else {
1172 u16 len;
1173
1174 /* check for headroom availability before skb_push */
1175 if (headroom < (2 * ETH_ALEN + 2)) {
1176 unifi_warning(priv, "headroom not available to skb_push ether header\n");
1177 return -1;
1178 }
1179 /* Add 802.3 header and leave full payload */
1180 len = htons(skb->len);
1181 memcpy(skb_push(skb, 2), &len, 2);
1182 memcpy(skb_push(skb, ETH_ALEN), saddr, ETH_ALEN);
1183 memcpy(skb_push(skb, ETH_ALEN), daddr, ETH_ALEN);
1184
1185 return 1;
1186 }
1187
1188 return 0;
1189 } /* skb_80211_to_ether() */
1190
1191
1192 static CsrWifiRouterCtrlPortAction verify_port(unifi_priv_t *priv, unsigned char *address, int queue, u16 interfaceTag)
1193 {
1194 #ifdef CSR_NATIVE_LINUX
1195 #ifdef CSR_SUPPORT_WEXT
1196 if (queue == UF_CONTROLLED_PORT_Q) {
1197 return priv->wext_conf.block_controlled_port;
1198 } else {
1199 return CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN;
1200 }
1201 #else
1202 return CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN; /* default to open for softmac dev */
1203 #endif
1204 #else
1205 return uf_sme_port_state(priv, address, queue, interfaceTag);
1206 #endif
1207 }
1208
1209 /*
1210 * ---------------------------------------------------------------------------
1211 * prepare_and_add_macheader
1212 *
1213 *
1214 * These functions adds mac header for packet from netdev
1215 * to UniFi for transmission.
1216 * EAP protocol packets are also appended with Mac header &
1217 * sent using send_ma_pkt_request().
1218 *
1219 * Arguments:
1220 * priv Pointer to device private context struct
1221 * skb Socket buffer containing data packet to transmit
1222 * newSkb Socket buffer containing data packet + Mac header if no sufficient headroom in skb
1223 * serviceClass to append QOS control header in Mac header
1224 * bulkdata if newSkb allocated then bulkdata updated to send to unifi
1225 * interfaceTag the interfaceID on which activity going on
1226 * daddr destination address
1227 * saddr source address
1228 * protection protection bit set in framce control of mac header
1229 *
1230 * Returns:
1231 * Zero on success or error code.
1232 * ---------------------------------------------------------------------------
1233 */
1234
1235 int prepare_and_add_macheader(unifi_priv_t *priv, struct sk_buff *skb, struct sk_buff *newSkb,
1236 CSR_PRIORITY priority,
1237 bulk_data_param_t *bulkdata,
1238 u16 interfaceTag,
1239 const u8 *daddr,
1240 const u8 *saddr,
1241 u8 protection)
1242 {
1243 u16 fc = 0;
1244 u8 qc = 0;
1245 u8 macHeaderLengthInBytes = MAC_HEADER_SIZE, *bufPtr = NULL;
1246 bulk_data_param_t data_ptrs;
1247 CsrResult csrResult;
1248 int headroom =0;
1249 u8 direction = 0;
1250 netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
1251 u8 *addressOne;
1252 u8 bQosNull = false;
1253
1254 if (skb == NULL) {
1255 unifi_error(priv,"prepare_and_add_macheader: Invalid SKB reference\n");
1256 return -1;
1257 }
1258
1259 /* add a MAC header refer: 7.1.3.1 Frame Control field in P802.11REVmb.book */
1260 if (priority != CSR_CONTENTION) {
1261 /* EAPOL packets don't go as QOS_DATA */
1262 if (priority == CSR_MANAGEMENT) {
1263 fc |= cpu_to_le16(IEEE802_11_FC_TYPE_DATA);
1264 } else {
1265 /* Qos Control Field */
1266 macHeaderLengthInBytes += QOS_CONTROL_HEADER_SIZE;
1267
1268 if (skb->len) {
1269
1270 fc |= cpu_to_le16(IEEE802_11_FC_TYPE_QOS_DATA);
1271 } else {
1272 fc |= cpu_to_le16(IEEE802_11_FC_TYPE_QOS_NULL);
1273 bQosNull = true;
1274 }
1275 }
1276 } else {
1277 if(skb->len == 0) {
1278 fc |= cpu_to_le16(IEEE802_11_FC_TYPE_NULL);
1279 } else {
1280 fc |= cpu_to_le16(IEEE802_11_FC_TYPE_DATA);
1281 }
1282 }
1283
1284 switch (interfacePriv->interfaceMode)
1285 {
1286 case CSR_WIFI_ROUTER_CTRL_MODE_STA:
1287 case CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI:
1288 direction = 2;
1289 fc |= cpu_to_le16(IEEE802_11_FC_TO_DS_MASK);
1290 break;
1291 case CSR_WIFI_ROUTER_CTRL_MODE_IBSS:
1292 direction = 0;
1293 break;
1294 case CSR_WIFI_ROUTER_CTRL_MODE_AP:
1295 case CSR_WIFI_ROUTER_CTRL_MODE_P2PGO:
1296 direction = 1;
1297 fc |= cpu_to_le16(IEEE802_11_FC_FROM_DS_MASK);
1298 break;
1299 case CSR_WIFI_ROUTER_CTRL_MODE_AMP:
1300 if (priority == CSR_MANAGEMENT ) {
1301
1302 direction = 2;
1303 fc |= cpu_to_le16(IEEE802_11_FC_TO_DS_MASK);
1304 } else {
1305 /* Data frames have to use WDS 4 address frames */
1306 direction = 3;
1307 fc |= cpu_to_le16(IEEE802_11_FC_TO_DS_MASK | IEEE802_11_FC_FROM_DS_MASK);
1308 macHeaderLengthInBytes += 6;
1309 }
1310 break;
1311 default:
1312 unifi_warning(priv, "prepare_and_add_macheader: Unknown mode %d\n",
1313 interfacePriv->interfaceMode);
1314 }
1315
1316
1317 /* If Sta is QOS & HTC is supported then need to set 'order' bit */
1318 /* We don't support HT Control for now */
1319
1320 if(protection) {
1321 fc |= cpu_to_le16(IEEE802_11_FC_PROTECTED_MASK);
1322 }
1323
1324 /* check the skb headroom before pushing mac header */
1325 headroom = skb_headroom(skb);
1326
1327 if (headroom < macHeaderLengthInBytes) {
1328 unifi_trace(priv, UDBG5,
1329 "prepare_and_add_macheader: Allocate headroom extra %d bytes\n",
1330 macHeaderLengthInBytes);
1331
1332 csrResult = unifi_net_data_malloc(priv, &data_ptrs.d[0], skb->len + macHeaderLengthInBytes);
1333
1334 if (csrResult != CSR_RESULT_SUCCESS) {
1335 unifi_error(priv, " failed to allocate request_data. in %s func\n", __FUNCTION__);
1336 return -1;
1337 }
1338 newSkb = (struct sk_buff *)(data_ptrs.d[0].os_net_buf_ptr);
1339 newSkb->len = skb->len + macHeaderLengthInBytes;
1340
1341 memcpy((void*)data_ptrs.d[0].os_data_ptr + macHeaderLengthInBytes,
1342 skb->data, skb->len);
1343
1344 bulkdata->d[0].os_data_ptr = newSkb->data;
1345 bulkdata->d[0].os_net_buf_ptr = (unsigned char*)newSkb;
1346 bulkdata->d[0].data_length = newSkb->len;
1347
1348 bufPtr = (u8*)data_ptrs.d[0].os_data_ptr;
1349
1350 /* The old skb will not be used again */
1351 kfree_skb(skb);
1352 } else {
1353
1354 /* headroom has sufficient size, so will get proper pointer */
1355 bufPtr = (u8*)skb_push(skb, macHeaderLengthInBytes);
1356 bulkdata->d[0].os_data_ptr = skb->data;
1357 bulkdata->d[0].os_net_buf_ptr = (unsigned char*)skb;
1358 bulkdata->d[0].data_length = skb->len;
1359 }
1360
1361 /* Frame the actual MAC header */
1362
1363 memset(bufPtr, 0, macHeaderLengthInBytes);
1364
1365 /* copy frameControl field */
1366 memcpy(bufPtr, &fc, sizeof(fc));
1367 bufPtr += sizeof(fc);
1368 macHeaderLengthInBytes -= sizeof(fc);
1369
1370 /* Duration/ID field which is 2 bytes */
1371 bufPtr += 2;
1372 macHeaderLengthInBytes -= 2;
1373
1374 switch(direction)
1375 {
1376 case 0:
1377 /* Its an Ad-Hoc no need to route it through AP */
1378 /* Address1: MAC address of the destination from eth header */
1379 memcpy(bufPtr, daddr, ETH_ALEN);
1380 bufPtr += ETH_ALEN;
1381 macHeaderLengthInBytes -= ETH_ALEN;
1382
1383 /* Address2: MAC address of the source */
1384 memcpy(bufPtr, saddr, ETH_ALEN);
1385 bufPtr += ETH_ALEN;
1386 macHeaderLengthInBytes -= ETH_ALEN;
1387
1388 /* Address3: the BSSID (locally generated in AdHoc (creators Bssid)) */
1389 memcpy(bufPtr, &interfacePriv->bssid, ETH_ALEN);
1390 bufPtr += ETH_ALEN;
1391 macHeaderLengthInBytes -= ETH_ALEN;
1392 break;
1393 case 1:
1394 /* Address1: MAC address of the actual destination */
1395 memcpy(bufPtr, daddr, ETH_ALEN);
1396 bufPtr += ETH_ALEN;
1397 macHeaderLengthInBytes -= ETH_ALEN;
1398 /* Address2: The MAC address of the AP */
1399 memcpy(bufPtr, &interfacePriv->bssid, ETH_ALEN);
1400 bufPtr += ETH_ALEN;
1401 macHeaderLengthInBytes -= ETH_ALEN;
1402
1403 /* Address3: MAC address of the source from eth header */
1404 memcpy(bufPtr, saddr, ETH_ALEN);
1405 bufPtr += ETH_ALEN;
1406 macHeaderLengthInBytes -= ETH_ALEN;
1407 break;
1408 case 2:
1409 /* Address1: To AP is the MAC address of the AP to which its associated */
1410 memcpy(bufPtr, &interfacePriv->bssid, ETH_ALEN);
1411 bufPtr += ETH_ALEN;
1412 macHeaderLengthInBytes -= ETH_ALEN;
1413
1414 /* Address2: MAC address of the source from eth header */
1415 memcpy(bufPtr, saddr, ETH_ALEN);
1416 bufPtr += ETH_ALEN;
1417 macHeaderLengthInBytes -= ETH_ALEN;
1418
1419 /* Address3: MAC address of the actual destination on the distribution system */
1420 memcpy(bufPtr, daddr, ETH_ALEN);
1421 bufPtr += ETH_ALEN;
1422 macHeaderLengthInBytes -= ETH_ALEN;
1423 break;
1424 case 3:
1425 memcpy(bufPtr, &interfacePriv->bssid, ETH_ALEN);
1426 bufPtr += ETH_ALEN;
1427 macHeaderLengthInBytes -= ETH_ALEN;
1428
1429 /* Address2: MAC address of the source from eth header */
1430 memcpy(bufPtr, saddr, ETH_ALEN);
1431 bufPtr += ETH_ALEN;
1432 macHeaderLengthInBytes -= ETH_ALEN;
1433
1434 /* Address3: MAC address of the actual destination on the distribution system */
1435 memcpy(bufPtr, daddr, ETH_ALEN);
1436 bufPtr += ETH_ALEN;
1437 macHeaderLengthInBytes -= ETH_ALEN;
1438 break;
1439 default:
1440 unifi_error(priv,"Unknown direction =%d : Not handled now\n",direction);
1441 return -1;
1442 }
1443 /* 2 bytes of frame control field, appended by firmware */
1444 bufPtr += 2;
1445 macHeaderLengthInBytes -= 2;
1446
1447 if (3 == direction) {
1448 /* Address4: MAC address of the source */
1449 memcpy(bufPtr, saddr, ETH_ALEN);
1450 bufPtr += ETH_ALEN;
1451 macHeaderLengthInBytes -= ETH_ALEN;
1452 }
1453
1454 /* IF Qos Data or Qos Null Data then set QosControl field */
1455 if ((priority != CSR_CONTENTION) && (macHeaderLengthInBytes >= QOS_CONTROL_HEADER_SIZE)) {
1456
1457 if (priority > 7) {
1458 unifi_trace(priv, UDBG1, "data packets priority is more than 7, priority = %x\n", priority);
1459 qc |= 7;
1460 } else {
1461 qc |= priority;
1462 }
1463 /*assigning address1
1464 * Address1 offset taken fromm bufPtr(currently bufPtr pointing to Qos contorl) variable in reverse direction
1465 * Address4 don't exit
1466 */
1467
1468 addressOne = bufPtr- ADDRESS_ONE_OFFSET;
1469
1470 if (addressOne[0] & 0x1) {
1471 /* multicast/broadcast frames, no acknowledgement needed */
1472 qc |= 1 << 5;
1473 }
1474 /* non-AP mode only for now */
1475 if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_STA ||
1476 interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_IBSS ||
1477 interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI) {
1478 /* In case of STA and IBSS case eosp and txop limit is 0. */
1479 } else {
1480 if(bQosNull) {
1481 qc |= 1 << 4;
1482 }
1483 }
1484
1485 /* append Qos control field to mac header */
1486 bufPtr[0] = qc;
1487 /* txop limit is 0 */
1488 bufPtr[1] = 0;
1489 macHeaderLengthInBytes -= QOS_CONTROL_HEADER_SIZE;
1490 }
1491 if (macHeaderLengthInBytes) {
1492 unifi_warning(priv, " Mac header not appended properly\n");
1493 return -1;
1494 }
1495 return 0;
1496 }
1497
1498 /*
1499 * ---------------------------------------------------------------------------
1500 * send_ma_pkt_request
1501 *
1502 * These functions send a data packet to UniFi for transmission.
1503 * EAP protocol packets are also sent as send_ma_pkt_request().
1504 *
1505 * Arguments:
1506 * priv Pointer to device private context struct
1507 * skb Socket buffer containing data packet to transmit
1508 * ehdr Pointer to Ethernet header within skb.
1509 *
1510 * Returns:
1511 * Zero on success or error code.
1512 * ---------------------------------------------------------------------------
1513 */
1514
1515 static int
1516 send_ma_pkt_request(unifi_priv_t *priv, struct sk_buff *skb, const struct ethhdr *ehdr, CSR_PRIORITY priority)
1517 {
1518 int r;
1519 u16 i;
1520 u8 eapolStore = FALSE;
1521 struct sk_buff *newSkb = NULL;
1522 bulk_data_param_t bulkdata;
1523 const int proto = ntohs(ehdr->h_proto);
1524 u16 interfaceTag;
1525 CsrWifiMacAddress peerAddress;
1526 CSR_TRANSMISSION_CONTROL transmissionControl = CSR_NO_CONFIRM_REQUIRED;
1527 s8 protection;
1528 netInterface_priv_t *interfacePriv = NULL;
1529 CSR_RATE TransmitRate = (CSR_RATE)0;
1530
1531 unifi_trace(priv, UDBG5, "entering send_ma_pkt_request\n");
1532
1533 /* Get the interface Tag by means of source Mac address */
1534 for (i = 0; i < CSR_WIFI_NUM_INTERFACES; i++) {
1535 if (!memcmp(priv->netdev[i]->dev_addr, ehdr->h_source, ETH_ALEN)) {
1536 interfaceTag = i;
1537 interfacePriv = priv->interfacePriv[interfaceTag];
1538 break;
1539 }
1540 }
1541
1542 if (interfacePriv == NULL) {
1543 /* No match found - error */
1544 interfaceTag = 0;
1545 interfacePriv = priv->interfacePriv[interfaceTag];
1546 unifi_warning(priv, "Mac address not matching ... debugging needed\n");
1547 interfacePriv->stats.tx_dropped++;
1548 kfree_skb(skb);
1549 return -1;
1550 }
1551
1552 /* Add a SNAP header if necessary */
1553 if (skb_add_llc_snap(priv->netdev[interfaceTag], skb, proto) != 0) {
1554 /* convert failed */
1555 unifi_error(priv, "skb_add_llc_snap failed.\n");
1556 kfree_skb(skb);
1557 return -1;
1558 }
1559
1560 bulkdata.d[0].os_data_ptr = skb->data;
1561 bulkdata.d[0].os_net_buf_ptr = (unsigned char*)skb;
1562 bulkdata.d[0].net_buf_length = bulkdata.d[0].data_length = skb->len;
1563 bulkdata.d[1].os_data_ptr = NULL;
1564 bulkdata.d[1].os_net_buf_ptr = NULL;
1565 bulkdata.d[1].net_buf_length = bulkdata.d[1].data_length = 0;
1566
1567 #ifdef CSR_SUPPORT_SME
1568 /* Notify the TA module for the Tx frame for non AP/P2PGO mode*/
1569 if ((interfacePriv->interfaceMode != CSR_WIFI_ROUTER_CTRL_MODE_AP) &&
1570 (interfacePriv->interfaceMode != CSR_WIFI_ROUTER_CTRL_MODE_P2PGO)) {
1571 unifi_ta_sample(priv->card, CSR_WIFI_ROUTER_CTRL_PROTOCOL_DIRECTION_TX,
1572 &bulkdata.d[0], ehdr->h_source,
1573 priv->netdev[interfaceTag]->dev_addr,
1574 jiffies_to_msecs(jiffies),
1575 0); /* rate is unknown on tx */
1576 }
1577 #endif /* CSR_SUPPORT_SME */
1578
1579 if ((proto == ETH_P_PAE)
1580 #ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
1581 || (proto == ETH_P_WAI)
1582 #endif
1583 )
1584 {
1585 /* check for m4 detection */
1586 if (0 == uf_verify_m4(priv, bulkdata.d[0].os_data_ptr, bulkdata.d[0].data_length)) {
1587 eapolStore = TRUE;
1588 }
1589 }
1590
1591 #ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
1592 if (proto == ETH_P_WAI)
1593 {
1594 protection = 0; /*WAI packets always sent unencrypted*/
1595 }
1596 else
1597 {
1598 #endif
1599 #ifdef CSR_SUPPORT_SME
1600 if ((protection = uf_get_protection_bit_from_interfacemode(priv, interfaceTag, ehdr->h_dest)) < 0) {
1601 unifi_warning(priv, "unicast address, but destination not in station record database\n");
1602 unifi_net_data_free(priv, &bulkdata.d[0]);
1603 return -1;
1604 }
1605 #else
1606 protection = 0;
1607 #endif
1608 #ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
1609 }
1610 #endif
1611
1612 /* append Mac header for Eapol as well as data packet */
1613 if (prepare_and_add_macheader(priv, skb, newSkb, priority, &bulkdata, interfaceTag, ehdr->h_dest, ehdr->h_source, protection)) {
1614 unifi_error(priv, "failed to create MAC header\n");
1615 unifi_net_data_free(priv, &bulkdata.d[0]);
1616 return -1;
1617 }
1618
1619 /* RA adrress must contain the immediate destination MAC address that is similiar to
1620 * the Address 1 field of 802.11 Mac header here 4 is: (sizeof(framecontrol) + sizeof (durationID))
1621 * which is address 1 field
1622 */
1623 memcpy(peerAddress.a, ((u8 *) bulkdata.d[0].os_data_ptr) + 4, ETH_ALEN);
1624
1625 unifi_trace(priv, UDBG5, "RA[0]=%x, RA[1]=%x, RA[2]=%x, RA[3]=%x, RA[4]=%x, RA[5]=%x\n",
1626 peerAddress.a[0],peerAddress.a[1], peerAddress.a[2], peerAddress.a[3],
1627 peerAddress.a[4],peerAddress.a[5]);
1628
1629
1630 if ((proto == ETH_P_PAE)
1631 #ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
1632 || (proto == ETH_P_WAI)
1633 #endif
1634 )
1635 {
1636 CSR_SIGNAL signal;
1637 CSR_MA_PACKET_REQUEST *req = &signal.u.MaPacketRequest;
1638
1639 /* initialize signal to zero */
1640 memset(&signal, 0, sizeof(CSR_SIGNAL));
1641
1642 /* Frame MA_PACKET request */
1643 signal.SignalPrimitiveHeader.SignalId = CSR_MA_PACKET_REQUEST_ID;
1644 signal.SignalPrimitiveHeader.ReceiverProcessId = 0;
1645 signal.SignalPrimitiveHeader.SenderProcessId = priv->netdev_client->sender_id;
1646
1647 transmissionControl = req->TransmissionControl = 0;
1648 #ifdef CSR_SUPPORT_SME
1649 if (eapolStore)
1650 {
1651 netInterface_priv_t *netpriv = (netInterface_priv_t *)netdev_priv(priv->netdev[interfaceTag]);
1652
1653 /* Fill the MA-PACKET.req */
1654
1655 req->Priority = priority;
1656 unifi_trace(priv, UDBG3, "Tx Frame with Priority: %x\n", req->Priority);
1657
1658 /* rate selected by firmware */
1659 req->TransmitRate = 0;
1660 req->HostTag = CSR_WIFI_EAPOL_M4_HOST_TAG;
1661 /* RA address matching with address 1 of Mac header */
1662 memcpy(req->Ra.x, ((u8 *) bulkdata.d[0].os_data_ptr) + 4, ETH_ALEN);
1663
1664 spin_lock(&priv->m4_lock);
1665 /* Store the M4-PACKET.req for later */
1666 interfacePriv->m4_signal = signal;
1667 interfacePriv->m4_bulk_data.net_buf_length = bulkdata.d[0].net_buf_length;
1668 interfacePriv->m4_bulk_data.data_length = bulkdata.d[0].data_length;
1669 interfacePriv->m4_bulk_data.os_data_ptr = bulkdata.d[0].os_data_ptr;
1670 interfacePriv->m4_bulk_data.os_net_buf_ptr = bulkdata.d[0].os_net_buf_ptr;
1671 spin_unlock(&priv->m4_lock);
1672
1673 /* Signal the workqueue to call CsrWifiRouterCtrlM4ReadyToSendIndSend().
1674 * It cannot be called directly from the tx path because it
1675 * does a non-atomic kmalloc via the framework's CsrPmemAlloc().
1676 */
1677 queue_work(priv->unifi_workqueue, &netpriv->send_m4_ready_task);
1678
1679 return 0;
1680 }
1681 #endif
1682 }/*EAPOL or WAI packet*/
1683
1684 #if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_WIFI_SECURITY_WAPI_SW_ENCRYPTION))
1685 if ((CSR_WIFI_ROUTER_CTRL_MODE_STA == interfacePriv->interfaceMode) && \
1686 (priv->wapi_unicast_filter) && \
1687 (proto != ETH_P_PAE) && \
1688 (proto != ETH_P_WAI) && \
1689 (skb->len > 0))
1690 {
1691 CSR_SIGNAL signal;
1692 CSR_MA_PACKET_REQUEST *req = &signal.u.MaPacketRequest;
1693 netInterface_priv_t *netpriv = (netInterface_priv_t *)netdev_priv(priv->netdev[interfaceTag]);
1694
1695 unifi_trace(priv, UDBG4, "send_ma_pkt_request() - WAPI unicast data packet when USKID = 1 \n");
1696
1697 /* initialize signal to zero */
1698 memset(&signal, 0, sizeof(CSR_SIGNAL));
1699 /* Frame MA_PACKET request */
1700 signal.SignalPrimitiveHeader.SignalId = CSR_MA_PACKET_REQUEST_ID;
1701 signal.SignalPrimitiveHeader.ReceiverProcessId = 0;
1702 signal.SignalPrimitiveHeader.SenderProcessId = priv->netdev_client->sender_id;
1703
1704 /* Fill the MA-PACKET.req */
1705 req->TransmissionControl = 0;
1706 req->Priority = priority;
1707 unifi_trace(priv, UDBG3, "Tx Frame with Priority: %x\n", req->Priority);
1708 req->TransmitRate = (CSR_RATE) 0; /* rate selected by firmware */
1709 req->HostTag = 0xffffffff; /* Ask for a new HostTag */
1710 /* RA address matching with address 1 of Mac header */
1711 memcpy(req->Ra.x, ((u8 *) bulkdata.d[0].os_data_ptr) + 4, ETH_ALEN);
1712
1713 /* Store the M4-PACKET.req for later */
1714 spin_lock(&priv->wapi_lock);
1715 interfacePriv->wapi_unicast_ma_pkt_sig = signal;
1716 interfacePriv->wapi_unicast_bulk_data.net_buf_length = bulkdata.d[0].net_buf_length;
1717 interfacePriv->wapi_unicast_bulk_data.data_length = bulkdata.d[0].data_length;
1718 interfacePriv->wapi_unicast_bulk_data.os_data_ptr = bulkdata.d[0].os_data_ptr;
1719 interfacePriv->wapi_unicast_bulk_data.os_net_buf_ptr = bulkdata.d[0].os_net_buf_ptr;
1720 spin_unlock(&priv->wapi_lock);
1721
1722 /* Signal the workqueue to call CsrWifiRouterCtrlWapiUnicastTxEncryptIndSend().
1723 * It cannot be called directly from the tx path because it
1724 * does a non-atomic kmalloc via the framework's CsrPmemAlloc().
1725 */
1726 queue_work(priv->unifi_workqueue, &netpriv->send_pkt_to_encrypt);
1727
1728 return 0;
1729 }
1730 #endif
1731
1732 if(priv->cmanrTestMode)
1733 {
1734 TransmitRate = priv->cmanrTestModeTransmitRate;
1735 unifi_trace(priv, UDBG2, "send_ma_pkt_request: cmanrTestModeTransmitRate = %d TransmitRate=%d\n",
1736 priv->cmanrTestModeTransmitRate,
1737 TransmitRate
1738 );
1739 }
1740
1741 /* Send UniFi msg */
1742 /* Here hostTag is been sent as 0xffffffff, its been appended properly while framing MA-Packet request in pdu_processing.c file */
1743 r = uf_process_ma_packet_req(priv,
1744 peerAddress.a,
1745 0xffffffff, /* Ask for a new HostTag */
1746 interfaceTag,
1747 transmissionControl,
1748 TransmitRate,
1749 priority,
1750 priv->netdev_client->sender_id,
1751 &bulkdata);
1752
1753 if (r) {
1754 unifi_trace(priv, UDBG1, "(HIP validation failure) r = %x\n", r);
1755 unifi_net_data_free(priv, &bulkdata.d[0]);
1756 return -1;
1757 }
1758
1759 unifi_trace(priv, UDBG3, "leaving send_ma_pkt_request, UNITDATA result code = %d\n", r);
1760
1761 return r;
1762 } /* send_ma_pkt_request() */
1763
1764 /*
1765 * ---------------------------------------------------------------------------
1766 * uf_net_xmit
1767 *
1768 * This function is called by the higher level stack to transmit an
1769 * ethernet packet.
1770 *
1771 * Arguments:
1772 * skb Ethernet packet to send.
1773 * dev Pointer to the linux net device.
1774 *
1775 * Returns:
1776 * 0 on success (packet was consumed, not necessarily transmitted)
1777 * 1 if packet was requeued
1778 * -1 on error
1779 *
1780 *
1781 * Notes:
1782 * The controlled port is handled in the qdisc dequeue handler.
1783 * ---------------------------------------------------------------------------
1784 */
1785 static netdev_tx_t
1786 uf_net_xmit(struct sk_buff *skb, struct net_device *dev)
1787 {
1788 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
1789 unifi_priv_t *priv = interfacePriv->privPtr;
1790 struct ethhdr ehdr;
1791 int proto, port;
1792 int result;
1793 static tx_signal_handler tx_handler;
1794 CSR_PRIORITY priority;
1795 CsrWifiRouterCtrlPortAction port_action;
1796
1797 func_enter();
1798
1799 unifi_trace(priv, UDBG5, "unifi_net_xmit: skb = %x\n", skb);
1800
1801 memcpy(&ehdr, skb->data, ETH_HLEN);
1802 proto = ntohs(ehdr.h_proto);
1803 priority = get_packet_priority(priv, skb, &ehdr, interfacePriv);
1804
1805 /* All frames are sent as MA-PACKET.req (EAPOL also) */
1806 tx_handler = send_ma_pkt_request;
1807
1808 /* 802.1x - apply controlled/uncontrolled port rules */
1809 if ((proto != ETH_P_PAE)
1810 #ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
1811 && (proto != ETH_P_WAI)
1812 #endif
1813 ) {
1814 port = UF_CONTROLLED_PORT_Q;
1815 } else {
1816 /* queue 4 */
1817 port = UF_UNCONTROLLED_PORT_Q;
1818 }
1819
1820 /* Uncontrolled port rules apply */
1821 port_action = verify_port(priv
1822 , (((CSR_WIFI_ROUTER_CTRL_MODE_STA == interfacePriv->interfaceMode)||(CSR_WIFI_ROUTER_CTRL_MODE_P2PCLI== interfacePriv->interfaceMode))? interfacePriv->bssid.a: ehdr.h_dest)
1823 , port
1824 , interfacePriv->InterfaceTag);
1825
1826 if (port_action == CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN) {
1827 unifi_trace(priv, UDBG5,
1828 "uf_net_xmit: %s controlled port open\n",
1829 port ? "" : "un");
1830 /* Remove the ethernet header */
1831 skb_pull(skb, ETH_HLEN);
1832 result = tx_handler(priv, skb, &ehdr, priority);
1833 } else {
1834
1835 /* Discard the packet if necessary */
1836 unifi_trace(priv, UDBG2,
1837 "uf_net_xmit: %s controlled port %s\n",
1838 port ? "" : "un", port_action==CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_BLOCK ? "blocked" : "closed");
1839 interfacePriv->stats.tx_dropped++;
1840 kfree_skb(skb);
1841
1842 func_exit();
1843 return NETDEV_TX_OK;
1844 }
1845
1846 if (result == NETDEV_TX_OK) {
1847 #if (defined(CSR_WIFI_SECURITY_WAPI_ENABLE) && defined(CSR_WIFI_SECURITY_WAPI_SW_ENCRYPTION))
1848 /* Don't update the tx stats when the pkt is to be sent for sw encryption*/
1849 if (!((CSR_WIFI_ROUTER_CTRL_MODE_STA == interfacePriv->interfaceMode) &&
1850 (priv->wapi_unicast_filter == 1)))
1851 {
1852 dev->trans_start = jiffies;
1853 /* Should really count tx stats in the UNITDATA.status signal but
1854 * that doesn't have the length.
1855 */
1856 interfacePriv->stats.tx_packets++;
1857 /* count only the packet payload */
1858 interfacePriv->stats.tx_bytes += skb->len;
1859
1860 }
1861 #else
1862 dev->trans_start = jiffies;
1863
1864 /*
1865 * Should really count tx stats in the UNITDATA.status signal but
1866 * that doesn't have the length.
1867 */
1868 interfacePriv->stats.tx_packets++;
1869 /* count only the packet payload */
1870 interfacePriv->stats.tx_bytes += skb->len;
1871 #endif
1872 } else if (result < 0) {
1873
1874 /* Failed to send: fh queue was full, and the skb was discarded.
1875 * Return OK to indicate that the buffer was consumed, to stop the
1876 * kernel re-transmitting the freed buffer.
1877 */
1878 interfacePriv->stats.tx_dropped++;
1879 unifi_trace(priv, UDBG1, "unifi_net_xmit: (Packet Drop), dropped count = %x\n", interfacePriv->stats.tx_dropped);
1880 result = NETDEV_TX_OK;
1881 }
1882
1883 /* The skb will have been freed by send_XXX_request() */
1884
1885 func_exit();
1886 return result;
1887 } /* uf_net_xmit() */
1888
1889 /*
1890 * ---------------------------------------------------------------------------
1891 * unifi_pause_xmit
1892 * unifi_restart_xmit
1893 *
1894 * These functions are called from the UniFi core to control the flow
1895 * of packets from the upper layers.
1896 * unifi_pause_xmit() is called when the internal queue is full and
1897 * should take action to stop unifi_ma_unitdata() being called.
1898 * When the queue has drained, unifi_restart_xmit() will be called to
1899 * re-enable the flow of packets for transmission.
1900 *
1901 * Arguments:
1902 * ospriv OS private context pointer.
1903 *
1904 * Returns:
1905 * unifi_pause_xmit() is called from interrupt context.
1906 * ---------------------------------------------------------------------------
1907 */
1908 void
1909 unifi_pause_xmit(void *ospriv, unifi_TrafficQueue queue)
1910 {
1911 unifi_priv_t *priv = ospriv;
1912 int i; /* used as a loop counter */
1913
1914 func_enter();
1915 unifi_trace(priv, UDBG2, "Stopping queue %d\n", queue);
1916
1917 for(i=0;i<CSR_WIFI_NUM_INTERFACES;i++)
1918 {
1919 if (netif_running(priv->netdev[i]))
1920 {
1921 netif_stop_subqueue(priv->netdev[i], (u16)queue);
1922 }
1923 }
1924
1925 #ifdef CSR_SUPPORT_SME
1926 if(queue<=3) {
1927 routerStartBuffering(priv,queue);
1928 unifi_trace(priv,UDBG2,"Start buffering %d\n", queue);
1929 } else {
1930 routerStartBuffering(priv,0);
1931 unifi_error(priv, "Start buffering %d defaulting to 0\n", queue);
1932 }
1933 #endif
1934 func_exit();
1935
1936 } /* unifi_pause_xmit() */
1937
1938 void
1939 unifi_restart_xmit(void *ospriv, unifi_TrafficQueue queue)
1940 {
1941 unifi_priv_t *priv = ospriv;
1942 int i=0; /* used as a loop counter */
1943
1944 func_enter();
1945 unifi_trace(priv, UDBG2, "Waking queue %d\n", queue);
1946
1947 for(i=0;i<CSR_WIFI_NUM_INTERFACES;i++)
1948 {
1949 if (netif_running(priv->netdev[i]))
1950 {
1951 netif_wake_subqueue(priv->netdev[i], (u16)queue);
1952 }
1953 }
1954
1955 #ifdef CSR_SUPPORT_SME
1956 if(queue <=3) {
1957 routerStopBuffering(priv,queue);
1958 uf_send_buffered_frames(priv,queue);
1959 } else {
1960 routerStopBuffering(priv,0);
1961 uf_send_buffered_frames(priv,0);
1962 }
1963 #endif
1964 func_exit();
1965 } /* unifi_restart_xmit() */
1966
1967
1968 static void
1969 indicate_rx_skb(unifi_priv_t *priv, u16 ifTag, u8* dst_a, u8* src_a, struct sk_buff *skb, CSR_SIGNAL *signal,
1970 bulk_data_param_t *bulkdata)
1971 {
1972 int r, sr = 0;
1973 struct net_device *dev;
1974
1975 #ifdef CSR_SUPPORT_SME
1976 llc_snap_hdr_t *snap;
1977
1978 snap = (llc_snap_hdr_t *)skb->data;
1979
1980 sr = _identify_sme_ma_pkt_ind(priv,
1981 snap->oui, ntohs(snap->protocol),
1982 signal,
1983 bulkdata,
1984 dst_a, src_a );
1985 #endif
1986
1987 /*
1988 * Decapsulate any SNAP header and
1989 * prepend an ethernet header so that the skb manipulation and ARP
1990 * stuff works.
1991 */
1992 r = skb_80211_to_ether(priv, skb, dst_a, src_a,
1993 signal, bulkdata);
1994 if (r == -1) {
1995 /* Drop the packet and return */
1996 priv->interfacePriv[ifTag]->stats.rx_errors++;
1997 priv->interfacePriv[ifTag]->stats.rx_frame_errors++;
1998 unifi_net_data_free(priv, &bulkdata->d[0]);
1999 unifi_notice(priv, "indicate_rx_skb: Discard unknown frame.\n");
2000 func_exit();
2001 return;
2002 }
2003
2004 /* Handle the case where packet is sent up through the subscription
2005 * API but should not be given to the network stack (AMP PAL case)
2006 * LLC header is different from WiFi and the packet has been subscribed for
2007 */
2008 if (r == 1 && sr == 1) {
2009 unifi_net_data_free(priv, &bulkdata->d[0]);
2010 unifi_trace(priv, UDBG5, "indicate_rx_skb: Data given to subscription"
2011 "API, not being given to kernel\n");
2012 func_exit();
2013 return;
2014 }
2015
2016 dev = priv->netdev[ifTag];
2017 /* Now we look like a regular ethernet frame */
2018 /* Fill in SKB meta data */
2019 skb->dev = dev;
2020 skb->protocol = eth_type_trans(skb, dev);
2021 skb->ip_summed = CHECKSUM_UNNECESSARY;
2022
2023 /* Test for an overlength frame */
2024 if (skb->len > (dev->mtu + ETH_HLEN)) {
2025 /* A bogus length ethfrm has been encap'd. */
2026 /* Is someone trying an oflow attack? */
2027 unifi_error(priv, "%s: oversize frame (%d > %d)\n",
2028 dev->name,
2029 skb->len, dev->mtu + ETH_HLEN);
2030
2031 /* Drop the packet and return */
2032 priv->interfacePriv[ifTag]->stats.rx_errors++;
2033 priv->interfacePriv[ifTag]->stats.rx_length_errors++;
2034 unifi_net_data_free(priv, &bulkdata->d[0]);
2035 func_exit();
2036 return;
2037 }
2038
2039
2040 if(priv->cmanrTestMode)
2041 {
2042 const CSR_MA_PACKET_INDICATION *pkt_ind = &signal->u.MaPacketIndication;
2043 priv->cmanrTestModeTransmitRate = pkt_ind->ReceivedRate;
2044 unifi_trace(priv, UDBG2, "indicate_rx_skb: cmanrTestModeTransmitRate=%d\n", priv->cmanrTestModeTransmitRate);
2045 }
2046
2047 /* Pass SKB up the stack */
2048 #ifdef CSR_WIFI_USE_NETIF_RX
2049 netif_rx(skb);
2050 #else
2051 netif_rx_ni(skb);
2052 #endif
2053
2054 if (dev != NULL) {
2055 dev->last_rx = jiffies;
2056 }
2057
2058 /* Bump rx stats */
2059 priv->interfacePriv[ifTag]->stats.rx_packets++;
2060 priv->interfacePriv[ifTag]->stats.rx_bytes += bulkdata->d[0].data_length;
2061
2062 func_exit();
2063 return;
2064 }
2065
2066 void
2067 uf_process_rx_pending_queue(unifi_priv_t *priv, int queue,
2068 CsrWifiMacAddress source_address,
2069 int indicate, u16 interfaceTag)
2070 {
2071 rx_buffered_packets_t *rx_q_item;
2072 struct list_head *rx_list;
2073 struct list_head *n;
2074 struct list_head *l_h;
2075 static const CsrWifiMacAddress broadcast_address = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
2076 netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
2077
2078 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
2079 unifi_error(priv, "uf_process_rx_pending_queue bad interfaceTag\n");
2080 return;
2081 }
2082
2083 if (queue == UF_CONTROLLED_PORT_Q) {
2084 rx_list = &interfacePriv->rx_controlled_list;
2085 } else {
2086 rx_list = &interfacePriv->rx_uncontrolled_list;
2087 }
2088
2089 down(&priv->rx_q_sem);
2090 list_for_each_safe(l_h, n, rx_list) {
2091 rx_q_item = list_entry(l_h, rx_buffered_packets_t, q);
2092
2093 /* Validate against the source address */
2094 if (memcmp(broadcast_address.a, source_address.a, ETH_ALEN) &&
2095 memcmp(rx_q_item->sa.a, source_address.a, ETH_ALEN)) {
2096
2097 unifi_trace(priv, UDBG2,
2098 "uf_process_rx_pending_queue: Skipping sa=%02X%02X%02X%02X%02X%02X skb=%p, bulkdata=%p\n",
2099 rx_q_item->sa.a[0], rx_q_item->sa.a[1],
2100 rx_q_item->sa.a[2], rx_q_item->sa.a[3],
2101 rx_q_item->sa.a[4], rx_q_item->sa.a[5],
2102 rx_q_item->skb, &rx_q_item->bulkdata.d[0]);
2103 continue;
2104 }
2105
2106 list_del(l_h);
2107
2108
2109 unifi_trace(priv, UDBG2,
2110 "uf_process_rx_pending_queue: Was Blocked skb=%p, bulkdata=%p\n",
2111 rx_q_item->skb, &rx_q_item->bulkdata);
2112
2113 if (indicate) {
2114 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);
2115 } else {
2116 interfacePriv->stats.rx_dropped++;
2117 unifi_net_data_free(priv, &rx_q_item->bulkdata.d[0]);
2118 }
2119
2120 /* It is our resposibility to free the Rx structure object. */
2121 kfree(rx_q_item);
2122 }
2123 up(&priv->rx_q_sem);
2124 }
2125
2126 /*
2127 * ---------------------------------------------------------------------------
2128 * uf_resume_data_plane
2129 *
2130 * Is called when the (un)controlled port is set to open,
2131 * to notify the network stack to schedule for transmission
2132 * any packets queued in the qdisk while port was closed and
2133 * indicated to the stack any packets buffered in the Rx queues.
2134 *
2135 * Arguments:
2136 * priv Pointer to device private struct
2137 *
2138 * Returns:
2139 * ---------------------------------------------------------------------------
2140 */
2141 void
2142 uf_resume_data_plane(unifi_priv_t *priv, int queue,
2143 CsrWifiMacAddress peer_address,
2144 u16 interfaceTag)
2145 {
2146 #ifdef CSR_SUPPORT_WEXT
2147 netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
2148 #endif
2149
2150 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
2151 unifi_error(priv, "uf_resume_data_plane bad interfaceTag\n");
2152 return;
2153 }
2154
2155 unifi_trace(priv, UDBG2, "Resuming netif\n");
2156
2157 /*
2158 * If we are waiting for the net device to enter the up state, don't
2159 * process the rx queue yet as it will be done by the callback when
2160 * the device is ready.
2161 */
2162 #ifdef CSR_SUPPORT_WEXT
2163 if (!interfacePriv->wait_netdev_change)
2164 #endif
2165 {
2166 #ifdef CONFIG_NET_SCHED
2167 if (netif_running(priv->netdev[interfaceTag])) {
2168 netif_tx_schedule_all(priv->netdev[interfaceTag]);
2169 }
2170 #endif
2171 uf_process_rx_pending_queue(priv, queue, peer_address, 1,interfaceTag);
2172 }
2173 } /* uf_resume_data_plane() */
2174
2175
2176 void uf_free_pending_rx_packets(unifi_priv_t *priv, int queue, CsrWifiMacAddress peer_address,u16 interfaceTag)
2177 {
2178 uf_process_rx_pending_queue(priv, queue, peer_address, 0,interfaceTag);
2179
2180 } /* uf_free_pending_rx_packets() */
2181
2182
2183 /*
2184 * ---------------------------------------------------------------------------
2185 * unifi_rx
2186 *
2187 * Reformat a UniFi data received packet into a p80211 packet and
2188 * pass it up the protocol stack.
2189 *
2190 * Arguments:
2191 * None.
2192 *
2193 * Returns:
2194 * None.
2195 * ---------------------------------------------------------------------------
2196 */
2197 static void
2198 unifi_rx(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata)
2199 {
2200 u16 interfaceTag;
2201 bulk_data_desc_t *pData;
2202 const CSR_MA_PACKET_INDICATION *pkt_ind = &signal->u.MaPacketIndication;
2203 struct sk_buff *skb;
2204 CsrWifiRouterCtrlPortAction port_action;
2205 u8 dataFrameType;
2206 int proto;
2207 int queue;
2208
2209 u8 da[ETH_ALEN], sa[ETH_ALEN];
2210 u8 toDs, fromDs, frameType, macHeaderLengthInBytes = MAC_HEADER_SIZE;
2211 u16 frameControl;
2212 netInterface_priv_t *interfacePriv;
2213 struct ethhdr ehdr;
2214
2215 func_enter();
2216
2217 interfaceTag = (pkt_ind->VirtualInterfaceIdentifier & 0xff);
2218 interfacePriv = priv->interfacePriv[interfaceTag];
2219
2220 /* Sanity check that the VIF refers to a sensible interface */
2221 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES)
2222 {
2223 unifi_error(priv, "%s: MA-PACKET indication with bad interfaceTag %d\n", __FUNCTION__, interfaceTag);
2224 unifi_net_data_free(priv,&bulkdata->d[0]);
2225 func_exit();
2226 return;
2227 }
2228
2229 /* Sanity check that the VIF refers to an allocated netdev */
2230 if (!interfacePriv->netdev_registered)
2231 {
2232 unifi_error(priv, "%s: MA-PACKET indication with unallocated interfaceTag %d\n", __FUNCTION__, interfaceTag);
2233 unifi_net_data_free(priv, &bulkdata->d[0]);
2234 func_exit();
2235 return;
2236 }
2237
2238 if (bulkdata->d[0].data_length == 0) {
2239 unifi_warning(priv, "%s: MA-PACKET indication with zero bulk data\n", __FUNCTION__);
2240 unifi_net_data_free(priv,&bulkdata->d[0]);
2241 func_exit();
2242 return;
2243 }
2244
2245
2246 skb = (struct sk_buff*)bulkdata->d[0].os_net_buf_ptr;
2247 skb->len = bulkdata->d[0].data_length;
2248
2249 /* Point to the addresses */
2250 toDs = (skb->data[1] & 0x01) ? 1 : 0;
2251 fromDs = (skb->data[1] & 0x02) ? 1 : 0;
2252
2253 memcpy(da,(skb->data+4+toDs*12),ETH_ALEN);/* Address1 or 3 */
2254 memcpy(sa,(skb->data+10+fromDs*(6+toDs*8)),ETH_ALEN); /* Address2, 3 or 4 */
2255
2256
2257 pData = &bulkdata->d[0];
2258 frameControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr);
2259 frameType = ((frameControl & 0x000C) >> 2);
2260
2261 dataFrameType =((frameControl & 0x00f0) >> 4);
2262 unifi_trace(priv, UDBG6,
2263 "%s: Receive Data Frame Type %d \n", __FUNCTION__,dataFrameType);
2264
2265 switch(dataFrameType)
2266 {
2267 case QOS_DATA:
2268 case QOS_DATA_NULL:
2269 /* If both are set then the Address4 exists (only for AP) */
2270 if (fromDs && toDs)
2271 {
2272 /* 6 is the size of Address4 field */
2273 macHeaderLengthInBytes += (QOS_CONTROL_HEADER_SIZE + 6);
2274 }
2275 else
2276 {
2277 macHeaderLengthInBytes += QOS_CONTROL_HEADER_SIZE;
2278 }
2279
2280 /* If order bit set then HT control field is the part of MAC header */
2281 if (frameControl & FRAME_CONTROL_ORDER_BIT)
2282 macHeaderLengthInBytes += HT_CONTROL_HEADER_SIZE;
2283 break;
2284 default:
2285 if (fromDs && toDs)
2286 macHeaderLengthInBytes += 6;
2287 }
2288
2289 /* Prepare the ethernet header from snap header of skb data */
2290 switch(dataFrameType)
2291 {
2292 case DATA_NULL:
2293 case QOS_DATA_NULL:
2294 /* This is for only queue info fetching, EAPOL wont come as
2295 * null data so the proto is initialized as zero
2296 */
2297 proto = 0x0;
2298 break;
2299 default:
2300 {
2301 llc_snap_hdr_t *snap;
2302 /* Fetch a snap header to find protocol (for IPV4/IPV6 packets
2303 * the snap header fetching offset is same)
2304 */
2305 snap = (llc_snap_hdr_t *) (skb->data + macHeaderLengthInBytes);
2306
2307 /* prepare the ethernet header from the snap header & addresses */
2308 ehdr.h_proto = snap->protocol;
2309 memcpy(ehdr.h_dest, da, ETH_ALEN);
2310 memcpy(ehdr.h_source, sa, ETH_ALEN);
2311 }
2312 proto = ntohs(ehdr.h_proto);
2313 }
2314 unifi_trace(priv, UDBG3, "in unifi_rx protocol from snap header = 0x%x\n", proto);
2315
2316 if ((proto != ETH_P_PAE)
2317 #ifdef CSR_WIFI_SECURITY_WAPI_ENABLE
2318 && (proto != ETH_P_WAI)
2319 #endif
2320 ) {
2321 queue = UF_CONTROLLED_PORT_Q;
2322 } else {
2323 queue = UF_UNCONTROLLED_PORT_Q;
2324 }
2325
2326 port_action = verify_port(priv, (unsigned char*)sa, queue, interfaceTag);
2327 unifi_trace(priv, UDBG3, "in unifi_rx port action is = 0x%x & queue = %x\n", port_action, queue);
2328
2329 #ifdef CSR_SUPPORT_SME
2330 /* Notify the TA module for the Rx frame for non P2PGO and AP cases*/
2331 if((interfacePriv->interfaceMode != CSR_WIFI_ROUTER_CTRL_MODE_AP) &&
2332 (interfacePriv->interfaceMode != CSR_WIFI_ROUTER_CTRL_MODE_P2PGO))
2333 {
2334 /* Remove MAC header of length(macHeaderLengthInBytes) before sampling */
2335 skb_pull(skb, macHeaderLengthInBytes);
2336 pData->os_data_ptr = skb->data;
2337 pData->data_length -= macHeaderLengthInBytes;
2338
2339 if (pData->data_length) {
2340 unifi_ta_sample(priv->card, CSR_WIFI_ROUTER_CTRL_PROTOCOL_DIRECTION_RX,
2341 &bulkdata->d[0],
2342 sa, priv->netdev[interfaceTag]->dev_addr,
2343 jiffies_to_msecs(jiffies),
2344 pkt_ind->ReceivedRate);
2345 }
2346 } else {
2347
2348 /* AP/P2PGO specific handling here */
2349 CsrWifiRouterCtrlStaInfo_t * srcStaInfo =
2350 CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,sa,interfaceTag);
2351
2352 /* Defensive check only; Source address is already checked in
2353 process_ma_packet_ind and we should have a valid source address here */
2354
2355 if(srcStaInfo == NULL) {
2356 CsrWifiMacAddress peerMacAddress;
2357 /* Unknown data PDU */
2358 memcpy(peerMacAddress.a,sa,ETH_ALEN);
2359 unifi_trace(priv, UDBG1, "%s: Unexpected frame from peer = %x:%x:%x:%x:%x:%x\n", __FUNCTION__,
2360 sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]);
2361 CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress);
2362 unifi_net_data_free(priv, &bulkdata->d[0]);
2363 func_exit();
2364 return;
2365 }
2366
2367 /* For AP GO mode, don't store the PDUs */
2368 if (port_action != CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_OPEN) {
2369 /* Drop the packet and return */
2370 CsrWifiMacAddress peerMacAddress;
2371 memcpy(peerMacAddress.a,sa,ETH_ALEN);
2372 unifi_trace(priv, UDBG3, "%s: Port is not open: unexpected frame from peer = %x:%x:%x:%x:%x:%x\n",
2373 __FUNCTION__, sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]);
2374
2375 CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress);
2376 interfacePriv->stats.rx_dropped++;
2377 unifi_net_data_free(priv, &bulkdata->d[0]);
2378 unifi_notice(priv, "%s: Dropping packet, proto=0x%04x, %s port\n", __FUNCTION__,
2379 proto, queue ? "Controlled" : "Un-controlled");
2380 func_exit();
2381 return;
2382 }
2383
2384 /* Qos NULL/Data NULL are freed here and not processed further */
2385 if((dataFrameType == QOS_DATA_NULL) || (dataFrameType == DATA_NULL)){
2386 unifi_trace(priv, UDBG5, "%s: Null Frame Received and Freed\n", __FUNCTION__);
2387 unifi_net_data_free(priv, &bulkdata->d[0]);
2388 func_exit();
2389 return;
2390 }
2391
2392 /* Now we have done with MAC header so proceed with the real data part*/
2393 /* This function takes care of appropriate routing for AP/P2PGO case*/
2394 /* the function hadnles following things
2395 2. Routing the PDU to appropriate location
2396 3. Error case handling
2397 */
2398 if(!(uf_ap_process_data_pdu(priv, skb, &ehdr, srcStaInfo,
2399 signal,
2400 bulkdata,
2401 macHeaderLengthInBytes)))
2402 {
2403 func_exit();
2404 return;
2405 }
2406 unifi_trace(priv, UDBG5, "unifi_rx: no specific AP handling process as normal frame, MAC Header len %d\n",macHeaderLengthInBytes);
2407 /* Remove the MAC header for subsequent conversion */
2408 skb_pull(skb, macHeaderLengthInBytes);
2409 pData->os_data_ptr = skb->data;
2410 pData->data_length -= macHeaderLengthInBytes;
2411 pData->os_net_buf_ptr = (unsigned char*)skb;
2412 pData->net_buf_length = skb->len;
2413 }
2414 #endif /* CSR_SUPPORT_SME */
2415
2416
2417 /* Now that the MAC header is removed, null-data frames have zero length
2418 * and can be dropped
2419 */
2420 if (pData->data_length == 0) {
2421 if (((frameControl & 0x00f0) >> 4) != QOS_DATA_NULL &&
2422 ((frameControl & 0x00f0) >> 4) != DATA_NULL) {
2423 unifi_trace(priv, UDBG1, "Zero length frame, but not null-data %04x\n", frameControl);
2424 }
2425 unifi_net_data_free(priv, &bulkdata->d[0]);
2426 func_exit();
2427 return;
2428 }
2429
2430 if (port_action == CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_DISCARD) {
2431 /* Drop the packet and return */
2432 interfacePriv->stats.rx_dropped++;
2433 unifi_net_data_free(priv, &bulkdata->d[0]);
2434 unifi_notice(priv, "%s: Dropping packet, proto=0x%04x, %s port\n",
2435 __FUNCTION__, proto, queue ? "controlled" : "uncontrolled");
2436 func_exit();
2437 return;
2438 } else if ( (port_action == CSR_WIFI_ROUTER_CTRL_PORT_ACTION_8021X_PORT_CLOSED_BLOCK) ||
2439 (interfacePriv->connected != UnifiConnected) ) {
2440
2441 /* Buffer the packet into the Rx queues */
2442 rx_buffered_packets_t *rx_q_item;
2443 struct list_head *rx_list;
2444
2445 rx_q_item = (rx_buffered_packets_t *)kmalloc(sizeof(rx_buffered_packets_t),
2446 GFP_KERNEL);
2447 if (rx_q_item == NULL) {
2448 unifi_error(priv, "%s: Failed to allocate %d bytes for rx packet record\n",
2449 __FUNCTION__, sizeof(rx_buffered_packets_t));
2450 interfacePriv->stats.rx_dropped++;
2451 unifi_net_data_free(priv, &bulkdata->d[0]);
2452 func_exit();
2453 return;
2454 }
2455
2456 INIT_LIST_HEAD(&rx_q_item->q);
2457 rx_q_item->bulkdata = *bulkdata;
2458 rx_q_item->skb = skb;
2459 rx_q_item->signal = *signal;
2460 memcpy(rx_q_item->sa.a, sa, ETH_ALEN);
2461 memcpy(rx_q_item->da.a, da, ETH_ALEN);
2462 unifi_trace(priv, UDBG2, "%s: Blocked skb=%p, bulkdata=%p\n",
2463 __FUNCTION__, rx_q_item->skb, &rx_q_item->bulkdata);
2464
2465 if (queue == UF_CONTROLLED_PORT_Q) {
2466 rx_list = &interfacePriv->rx_controlled_list;
2467 } else {
2468 rx_list = &interfacePriv->rx_uncontrolled_list;
2469 }
2470
2471 /* Add to tail of packets queue */
2472 down(&priv->rx_q_sem);
2473 list_add_tail(&rx_q_item->q, rx_list);
2474 up(&priv->rx_q_sem);
2475
2476 func_exit();
2477 return;
2478
2479 }
2480
2481 indicate_rx_skb(priv, interfaceTag, da, sa, skb, signal, bulkdata);
2482
2483 func_exit();
2484
2485 } /* unifi_rx() */
2486
2487 static void process_ma_packet_cfm(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata)
2488 {
2489 u16 interfaceTag;
2490 const CSR_MA_PACKET_CONFIRM *pkt_cfm = &signal->u.MaPacketConfirm;
2491 netInterface_priv_t *interfacePriv;
2492
2493 func_enter();
2494 interfaceTag = (pkt_cfm->VirtualInterfaceIdentifier & 0xff);
2495 interfacePriv = priv->interfacePriv[interfaceTag];
2496
2497 /* Sanity check that the VIF refers to a sensible interface */
2498 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES)
2499 {
2500 unifi_error(priv, "%s: MA-PACKET confirm with bad interfaceTag %d\n", __FUNCTION__, interfaceTag);
2501 func_exit();
2502 return;
2503 }
2504 #ifdef CSR_SUPPORT_SME
2505 if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2506 interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO) {
2507
2508 uf_process_ma_pkt_cfm_for_ap(priv,interfaceTag,pkt_cfm);
2509 } else if (interfacePriv->m4_sent && (pkt_cfm->HostTag == interfacePriv->m4_hostTag)) {
2510 /* Check if this is a confirm for EAPOL M4 frame and we need to send transmistted ind*/
2511 CsrResult result = pkt_cfm->TransmissionStatus == CSR_TX_SUCCESSFUL?CSR_RESULT_SUCCESS:CSR_RESULT_FAILURE;
2512 CsrWifiMacAddress peerMacAddress;
2513 memcpy(peerMacAddress.a, interfacePriv->m4_signal.u.MaPacketRequest.Ra.x, ETH_ALEN);
2514
2515 unifi_trace(priv, UDBG1, "%s: Sending M4 Transmit CFM\n", __FUNCTION__);
2516 CsrWifiRouterCtrlM4TransmittedIndSend(priv->CSR_WIFI_SME_IFACEQUEUE, 0,
2517 interfaceTag,
2518 peerMacAddress,
2519 result);
2520 interfacePriv->m4_sent = FALSE;
2521 interfacePriv->m4_hostTag = 0xffffffff;
2522 }
2523 #endif
2524 func_exit();
2525 return;
2526 }
2527
2528
2529 /*
2530 * ---------------------------------------------------------------------------
2531 * unifi_rx
2532 *
2533 * Reformat a UniFi data received packet into a p80211 packet and
2534 * pass it up the protocol stack.
2535 *
2536 * Arguments:
2537 * None.
2538 *
2539 * Returns:
2540 * None.
2541 * ---------------------------------------------------------------------------
2542 */
2543 static void process_ma_packet_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata)
2544 {
2545 u16 interfaceTag;
2546 bulk_data_desc_t *pData;
2547 CSR_MA_PACKET_INDICATION *pkt_ind = (CSR_MA_PACKET_INDICATION*)&signal->u.MaPacketIndication;
2548 struct sk_buff *skb;
2549 u16 frameControl;
2550 netInterface_priv_t *interfacePriv;
2551 u8 da[ETH_ALEN], sa[ETH_ALEN];
2552 u8 *bssid = NULL, *ba_addr = NULL;
2553 u8 toDs, fromDs, frameType;
2554 u8 i =0;
2555
2556 #ifdef CSR_SUPPORT_SME
2557 u8 dataFrameType = 0;
2558 u8 powerSaveChanged = FALSE;
2559 u8 pmBit = 0;
2560 CsrWifiRouterCtrlStaInfo_t *srcStaInfo = NULL;
2561 u16 qosControl;
2562
2563 #endif
2564
2565 func_enter();
2566
2567 interfaceTag = (pkt_ind->VirtualInterfaceIdentifier & 0xff);
2568 interfacePriv = priv->interfacePriv[interfaceTag];
2569
2570
2571 /* Sanity check that the VIF refers to a sensible interface */
2572 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES)
2573 {
2574 unifi_error(priv, "%s: MA-PACKET indication with bad interfaceTag %d\n", __FUNCTION__, interfaceTag);
2575 unifi_net_data_free(priv,&bulkdata->d[0]);
2576 func_exit();
2577 return;
2578 }
2579
2580 /* Sanity check that the VIF refers to an allocated netdev */
2581 if (!interfacePriv->netdev_registered)
2582 {
2583 unifi_error(priv, "%s: MA-PACKET indication with unallocated interfaceTag %d\n", __FUNCTION__, interfaceTag);
2584 unifi_net_data_free(priv, &bulkdata->d[0]);
2585 func_exit();
2586 return;
2587 }
2588
2589 if (bulkdata->d[0].data_length == 0) {
2590 unifi_warning(priv, "%s: MA-PACKET indication with zero bulk data\n", __FUNCTION__);
2591 unifi_net_data_free(priv,&bulkdata->d[0]);
2592 func_exit();
2593 return;
2594 }
2595 /* For monitor mode we need to pass this indication to the registered application
2596 handle this seperately*/
2597 /* MIC failure is already taken care of so no need to send the PDUs which are not successfully received in non-monitor mode*/
2598 if(pkt_ind->ReceptionStatus != CSR_RX_SUCCESS)
2599 {
2600 unifi_warning(priv, "%s: MA-PACKET indication with status = %d\n",__FUNCTION__, pkt_ind->ReceptionStatus);
2601 unifi_net_data_free(priv,&bulkdata->d[0]);
2602 func_exit();
2603 return;
2604 }
2605
2606
2607 skb = (struct sk_buff*)bulkdata->d[0].os_net_buf_ptr;
2608 skb->len = bulkdata->d[0].data_length;
2609
2610 /* Point to the addresses */
2611 toDs = (skb->data[1] & 0x01) ? 1 : 0;
2612 fromDs = (skb->data[1] & 0x02) ? 1 : 0;
2613
2614 memcpy(da,(skb->data+4+toDs*12),ETH_ALEN);/* Address1 or 3 */
2615 memcpy(sa,(skb->data+10+fromDs*(6+toDs*8)),ETH_ALEN); /* Address2, 3 or 4 */
2616
2617 /* Find the BSSID, which will be used to match the BA session */
2618 if (toDs && fromDs)
2619 {
2620 unifi_trace(priv, UDBG6, "4 address frame - don't try to find BSSID\n");
2621 bssid = NULL;
2622 }
2623 else
2624 {
2625 bssid = (u8 *) (skb->data + 4 + 12 - (fromDs * 6) - (toDs * 12));
2626 }
2627
2628 pData = &bulkdata->d[0];
2629 frameControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr);
2630 frameType = ((frameControl & 0x000C) >> 2);
2631
2632 unifi_trace(priv, UDBG3, "Rx Frame Type: %d sn: %d\n",frameType,
2633 (le16_to_cpu(*((u16*)(bulkdata->d[0].os_data_ptr + IEEE802_11_SEQUENCE_CONTROL_OFFSET))) >> 4) & 0xfff);
2634 if(frameType == IEEE802_11_FRAMETYPE_CONTROL){
2635 #ifdef CSR_SUPPORT_SME
2636 unifi_trace(priv, UDBG6, "%s: Received Control Frame\n", __FUNCTION__);
2637
2638 if((frameControl & 0x00f0) == 0x00A0){
2639 /* This is a PS-POLL request */
2640 u8 pmBit = (frameControl & 0x1000)?0x01:0x00;
2641 unifi_trace(priv, UDBG6, "%s: Received PS-POLL Frame\n", __FUNCTION__);
2642
2643 uf_process_ps_poll(priv,sa,da,pmBit,interfaceTag);
2644 }
2645 else {
2646 unifi_warning(priv, "%s: Non PS-POLL control frame is received\n", __FUNCTION__);
2647 }
2648 #endif
2649 unifi_net_data_free(priv,&bulkdata->d[0]);
2650 func_exit();
2651 return;
2652 }
2653 if(frameType != IEEE802_11_FRAMETYPE_DATA) {
2654 unifi_warning(priv, "%s: Non control Non Data frame is received\n",__FUNCTION__);
2655 unifi_net_data_free(priv,&bulkdata->d[0]);
2656 func_exit();
2657 return;
2658 }
2659
2660 #ifdef CSR_SUPPORT_SME
2661 if((interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP) ||
2662 (interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO)){
2663
2664 srcStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv,sa,interfaceTag);
2665
2666 if(srcStaInfo == NULL) {
2667 CsrWifiMacAddress peerMacAddress;
2668 /* Unknown data PDU */
2669 memcpy(peerMacAddress.a,sa,ETH_ALEN);
2670 unifi_trace(priv, UDBG1, "%s: Unexpected frame from peer = %x:%x:%x:%x:%x:%x\n", __FUNCTION__,
2671 sa[0], sa[1],sa[2], sa[3], sa[4],sa[5]);
2672 CsrWifiRouterCtrlUnexpectedFrameIndSend(priv->CSR_WIFI_SME_IFACEQUEUE,0,interfaceTag,peerMacAddress);
2673 unifi_net_data_free(priv, &bulkdata->d[0]);
2674 func_exit();
2675 return;
2676 }
2677
2678 /*
2679 verify power management bit here so as to ensure host and unifi are always
2680 in sync with power management status of peer.
2681
2682 If we do it later, it may so happen we have stored the frame in BA re-ordering
2683 buffer and hence host and unifi are out of sync for power management status
2684 */
2685
2686 pmBit = (frameControl & 0x1000)?0x01:0x00;
2687 powerSaveChanged = uf_process_pm_bit_for_peer(priv,srcStaInfo,pmBit,interfaceTag);
2688
2689 /* Update station last activity time */
2690 srcStaInfo->activity_flag = TRUE;
2691
2692 /* For Qos Frame if PM bit is toggled to indicate the change in power save state then it shall not be
2693 considered as Trigger Frame. Enter only if WMM STA and peer is in Power save */
2694
2695 dataFrameType = ((frameControl & 0x00f0) >> 4);
2696
2697 if((powerSaveChanged == FALSE)&&(srcStaInfo->wmmOrQosEnabled == TRUE)&&
2698 (srcStaInfo->currentPeerState == CSR_WIFI_ROUTER_CTRL_PEER_CONNECTED_POWER_SAVE)){
2699
2700 if((dataFrameType == QOS_DATA) || (dataFrameType == QOS_DATA_NULL)){
2701
2702 /*
2703 * QoS control field is offset from frame control by 2 (frame control)
2704 * + 2 (duration/ID) + 2 (sequence control) + 3*ETH_ALEN or 4*ETH_ALEN
2705 */
2706 if((frameControl & IEEE802_11_FC_TO_DS_MASK) && (frameControl & IEEE802_11_FC_FROM_DS_MASK)){
2707 qosControl= CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr + 30);
2708 }
2709 else{
2710 qosControl = CSR_GET_UINT16_FROM_LITTLE_ENDIAN(pData->os_data_ptr + 24);
2711 }
2712 unifi_trace(priv, UDBG5, "%s: Check if U-APSD operations are triggered for qosControl: 0x%x\n",__FUNCTION__,qosControl);
2713 uf_process_wmm_deliver_ac_uapsd(priv,srcStaInfo,qosControl,interfaceTag);
2714 }
2715 }
2716 }
2717
2718 #endif
2719
2720 if( ((frameControl & 0x00f0) >> 4) == QOS_DATA) {
2721 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);
2722 int tID = *qos_control_ptr & IEEE802_11_QC_TID_MASK; /* using ls octet of qos control */
2723 ba_session_rx_struct *ba_session;
2724 u8 ba_session_idx = 0;
2725 /* Get the BA originator address */
2726 if(interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_AP ||
2727 interfacePriv->interfaceMode == CSR_WIFI_ROUTER_CTRL_MODE_P2PGO){
2728 ba_addr = sa;
2729 }else{
2730 ba_addr = bssid;
2731 }
2732
2733 down(&priv->ba_mutex);
2734 for (ba_session_idx=0; ba_session_idx < MAX_SUPPORTED_BA_SESSIONS_RX; ba_session_idx++){
2735 ba_session = interfacePriv->ba_session_rx[ba_session_idx];
2736 if (ba_session){
2737 unifi_trace(priv, UDBG6, "found ba_session=0x%x ba_session_idx=%d", ba_session, ba_session_idx);
2738 if ((!memcmp(ba_session->macAddress.a, ba_addr, ETH_ALEN)) && (ba_session->tID == tID)){
2739 frame_desc_struct frame_desc;
2740 frame_desc.bulkdata = *bulkdata;
2741 frame_desc.signal = *signal;
2742 frame_desc.sn = (le16_to_cpu(*((u16*)(bulkdata->d[0].os_data_ptr + IEEE802_11_SEQUENCE_CONTROL_OFFSET))) >> 4) & 0xfff;
2743 frame_desc.active = TRUE;
2744 unifi_trace(priv, UDBG6, "%s: calling process_ba_frame (session=%d)\n", __FUNCTION__, ba_session_idx);
2745 process_ba_frame(priv, interfacePriv, ba_session, &frame_desc);
2746 up(&priv->ba_mutex);
2747 process_ba_complete(priv, interfacePriv);
2748 break;
2749 }
2750 }
2751 }
2752 if (ba_session_idx == MAX_SUPPORTED_BA_SESSIONS_RX){
2753 up(&priv->ba_mutex);
2754 unifi_trace(priv, UDBG6, "%s: calling process_amsdu()", __FUNCTION__);
2755 process_amsdu(priv, signal, bulkdata);
2756 }
2757 } else {
2758 unifi_trace(priv, UDBG6, "calling unifi_rx()");
2759 unifi_rx(priv, signal, bulkdata);
2760 }
2761
2762 /* check if the frames in reorder buffer has aged, the check
2763 * is done after receive processing so that if the missing frame
2764 * has arrived in this receive process, then it is handled cleanly.
2765 *
2766 * And also this code here takes care that timeout check is made for all
2767 * the receive indications
2768 */
2769 down(&priv->ba_mutex);
2770 for (i=0; i < MAX_SUPPORTED_BA_SESSIONS_RX; i++){
2771 ba_session_rx_struct *ba_session;
2772 ba_session = interfacePriv->ba_session_rx[i];
2773 if (ba_session){
2774 check_ba_frame_age_timeout(priv, interfacePriv, ba_session);
2775 }
2776 }
2777 up(&priv->ba_mutex);
2778 process_ba_complete(priv, interfacePriv);
2779
2780 func_exit();
2781 }
2782 /*
2783 * ---------------------------------------------------------------------------
2784 * uf_set_multicast_list
2785 *
2786 * This function is called by the higher level stack to set
2787 * a list of multicast rx addresses.
2788 *
2789 * Arguments:
2790 * dev Network Device pointer.
2791 *
2792 * Returns:
2793 * None.
2794 *
2795 * Notes:
2796 * ---------------------------------------------------------------------------
2797 */
2798
2799 static void
2800 uf_set_multicast_list(struct net_device *dev)
2801 {
2802 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
2803 unifi_priv_t *priv = interfacePriv->privPtr;
2804
2805 #ifdef CSR_NATIVE_LINUX
2806 unifi_trace(priv, UDBG3, "uf_set_multicast_list unsupported\n");
2807 return;
2808 #else
2809
2810 u8 *mc_list = interfacePriv->mc_list;
2811 struct netdev_hw_addr *mc_addr;
2812 int mc_addr_count;
2813
2814 if (priv->init_progress != UNIFI_INIT_COMPLETED) {
2815 return;
2816 }
2817
2818 mc_addr_count = netdev_mc_count(dev);
2819
2820 unifi_trace(priv, UDBG3,
2821 "uf_set_multicast_list (count=%d)\n", mc_addr_count);
2822
2823
2824 /* Not enough space? */
2825 if (mc_addr_count > UNIFI_MAX_MULTICAST_ADDRESSES) {
2826 return;
2827 }
2828
2829 /* Store the list to be processed by the work item. */
2830 interfacePriv->mc_list_count = mc_addr_count;
2831 netdev_hw_addr_list_for_each(mc_addr, &dev->mc) {
2832 memcpy(mc_list, mc_addr->addr, ETH_ALEN);
2833 mc_list += ETH_ALEN;
2834 }
2835
2836 /* Send a message to the workqueue */
2837 queue_work(priv->unifi_workqueue, &priv->multicast_list_task);
2838 #endif
2839
2840 } /* uf_set_multicast_list() */
2841
2842 /*
2843 * ---------------------------------------------------------------------------
2844 * netdev_mlme_event_handler
2845 *
2846 * Callback function to be used as the udi_event_callback when registering
2847 * as a netdev client.
2848 * To use it, a client specifies this function as the udi_event_callback
2849 * to ul_register_client(). The signal dispatcher in
2850 * unifi_receive_event() will call this function to deliver a signal.
2851 *
2852 * Arguments:
2853 * pcli Pointer to the client instance.
2854 * signal Pointer to the received signal.
2855 * signal_len Size of the signal structure in bytes.
2856 * bulkdata Pointer to structure containing any associated bulk data.
2857 * dir Direction of the signal. Zero means from host,
2858 * non-zero means to host.
2859 *
2860 * Returns:
2861 * None.
2862 * ---------------------------------------------------------------------------
2863 */
2864 static void
2865 netdev_mlme_event_handler(ul_client_t *pcli, const u8 *sig_packed, int sig_len,
2866 const bulk_data_param_t *bulkdata_o, int dir)
2867 {
2868 CSR_SIGNAL signal;
2869 unifi_priv_t *priv = uf_find_instance(pcli->instance);
2870 int id, r;
2871 bulk_data_param_t bulkdata;
2872
2873 func_enter();
2874
2875 /* Just a sanity check */
2876 if (sig_packed == NULL) {
2877 return;
2878 }
2879
2880 /*
2881 * This copy is to silence a compiler warning about discarding the
2882 * const qualifier.
2883 */
2884 bulkdata = *bulkdata_o;
2885
2886 /* Get the unpacked signal */
2887 r = read_unpack_signal(sig_packed, &signal);
2888 if (r) {
2889 /*
2890 * The CSR_MLME_CONNECTED_INDICATION_ID has a receiverID=0 so will
2891 * fall through this case. It is safe to ignore this signal.
2892 */
2893 unifi_trace(priv, UDBG1,
2894 "Netdev - Received unknown signal 0x%.4X.\n",
2895 CSR_GET_UINT16_FROM_LITTLE_ENDIAN(sig_packed));
2896 return;
2897 }
2898
2899 id = signal.SignalPrimitiveHeader.SignalId;
2900 unifi_trace(priv, UDBG3, "Netdev - Process signal 0x%.4X\n", id);
2901
2902 /*
2903 * Take the appropriate action for the signal.
2904 */
2905 switch (id) {
2906 case CSR_MA_PACKET_ERROR_INDICATION_ID:
2907 process_ma_packet_error_ind(priv, &signal, &bulkdata);
2908 break;
2909 case CSR_MA_PACKET_INDICATION_ID:
2910 process_ma_packet_ind(priv, &signal, &bulkdata);
2911 break;
2912 case CSR_MA_PACKET_CONFIRM_ID:
2913 process_ma_packet_cfm(priv, &signal, &bulkdata);
2914 break;
2915 #ifdef CSR_SUPPORT_SME
2916 case CSR_MLME_SET_TIM_CONFIRM_ID:
2917 /* Handle TIM confirms from FW & set the station record's TIM state appropriately,
2918 * In case of failures, tries with max_retransmit limit
2919 */
2920 uf_handle_tim_cfm(priv, &signal.u.MlmeSetTimConfirm, signal.SignalPrimitiveHeader.ReceiverProcessId);
2921 break;
2922 #endif
2923 case CSR_DEBUG_STRING_INDICATION_ID:
2924 debug_string_indication(priv, bulkdata.d[0].os_data_ptr, bulkdata.d[0].data_length);
2925 break;
2926
2927 case CSR_DEBUG_WORD16_INDICATION_ID:
2928 debug_word16_indication(priv, &signal);
2929 break;
2930
2931 case CSR_DEBUG_GENERIC_CONFIRM_ID:
2932 case CSR_DEBUG_GENERIC_INDICATION_ID:
2933 debug_generic_indication(priv, &signal);
2934 break;
2935 default:
2936 break;
2937 }
2938
2939 func_exit();
2940 } /* netdev_mlme_event_handler() */
2941
2942
2943 /*
2944 * ---------------------------------------------------------------------------
2945 * uf_net_get_name
2946 *
2947 * Retrieve the name (e.g. eth1) associated with this network device
2948 *
2949 * Arguments:
2950 * dev Pointer to the network device.
2951 * name Buffer to write name
2952 * len Size of buffer in bytes
2953 *
2954 * Returns:
2955 * None
2956 *
2957 * Notes:
2958 * ---------------------------------------------------------------------------
2959 */
2960 void uf_net_get_name(struct net_device *dev, char *name, int len)
2961 {
2962 *name = '\0';
2963 if (dev) {
2964 strlcpy(name, dev->name, (len > IFNAMSIZ) ? IFNAMSIZ : len);
2965 }
2966
2967 } /* uf_net_get_name */
2968
2969 #ifdef CSR_SUPPORT_WEXT
2970
2971 /*
2972 * ---------------------------------------------------------------------------
2973 * uf_netdev_event
2974 *
2975 * Callback function to handle netdev state changes
2976 *
2977 * Arguments:
2978 * notif Pointer to a notifier_block.
2979 * event Event prompting notification
2980 * ptr net_device pointer
2981 *
2982 * Returns:
2983 * None
2984 *
2985 * Notes:
2986 * The event handler is global, and may occur on non-UniFi netdevs.
2987 * ---------------------------------------------------------------------------
2988 */
2989 static int
2990 uf_netdev_event(struct notifier_block *notif, unsigned long event, void* ptr) {
2991 struct net_device *netdev = ptr;
2992 netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(netdev);
2993 unifi_priv_t *priv = NULL;
2994 static const CsrWifiMacAddress broadcast_address = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
2995
2996 /* Check that the event is for a UniFi netdev. If it's not, the netdev_priv
2997 * structure is not safe to use.
2998 */
2999 if (uf_find_netdev_priv(interfacePriv) == -1) {
3000 unifi_trace(NULL, UDBG1, "uf_netdev_event: ignore e=%d, ptr=%p, priv=%p %s\n",
3001 event, ptr, interfacePriv, netdev->name);
3002 return 0;
3003 }
3004
3005 switch(event) {
3006 case NETDEV_CHANGE:
3007 priv = interfacePriv->privPtr;
3008 unifi_trace(priv, UDBG1, "NETDEV_CHANGE: %p %s %s waiting for it\n",
3009 ptr,
3010 netdev->name,
3011 interfacePriv->wait_netdev_change ? "" : "not");
3012
3013 if (interfacePriv->wait_netdev_change) {
3014 UF_NETIF_TX_WAKE_ALL_QUEUES(priv->netdev[interfacePriv->InterfaceTag]);
3015 interfacePriv->connected = UnifiConnected;
3016 interfacePriv->wait_netdev_change = FALSE;
3017 /* Note: passing the broadcast address here will allow anyone to attempt to join our adhoc network */
3018 uf_process_rx_pending_queue(priv, UF_UNCONTROLLED_PORT_Q, broadcast_address, 1,interfacePriv->InterfaceTag);
3019 uf_process_rx_pending_queue(priv, UF_CONTROLLED_PORT_Q, broadcast_address, 1,interfacePriv->InterfaceTag);
3020 }
3021 break;
3022
3023 default:
3024 break;
3025 }
3026 return 0;
3027 }
3028
3029 static struct notifier_block uf_netdev_notifier = {
3030 .notifier_call = uf_netdev_event,
3031 };
3032 #endif /* CSR_SUPPORT_WEXT */
3033
3034
3035 static void
3036 process_amsdu(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata)
3037 {
3038 u32 offset;
3039 u32 length = bulkdata->d[0].data_length;
3040 u32 subframe_length, subframe_body_length, dot11_hdr_size;
3041 u8 *ptr;
3042 bulk_data_param_t subframe_bulkdata;
3043 u8 *dot11_hdr_ptr = (u8*)bulkdata->d[0].os_data_ptr;
3044 CsrResult csrResult;
3045 u16 frameControl;
3046 u8 *qos_control_ptr;
3047
3048 frameControl = le16_to_cpu(*((u16*)dot11_hdr_ptr));
3049 qos_control_ptr = dot11_hdr_ptr + (((frameControl & IEEE802_11_FC_TO_DS_MASK) && (frameControl & IEEE802_11_FC_FROM_DS_MASK))?30: 24);
3050 if(!(*qos_control_ptr & IEEE802_11_QC_A_MSDU_PRESENT)) {
3051 unifi_trace(priv, UDBG6, "%s: calling unifi_rx()", __FUNCTION__);
3052 unifi_rx(priv, signal, bulkdata);
3053 return;
3054 }
3055 *qos_control_ptr &= ~(IEEE802_11_QC_A_MSDU_PRESENT);
3056
3057 ptr = qos_control_ptr + 2;
3058 offset = dot11_hdr_size = ptr - dot11_hdr_ptr;
3059
3060 while(length > (offset + sizeof(struct ethhdr) + sizeof(llc_snap_hdr_t))) {
3061 subframe_body_length = ntohs(((struct ethhdr*)ptr)->h_proto);
3062 if(subframe_body_length > IEEE802_11_MAX_DATA_LEN) {
3063 unifi_error(priv, "%s: bad subframe_body_length = %d\n", __FUNCTION__, subframe_body_length);
3064 break;
3065 }
3066 subframe_length = sizeof(struct ethhdr) + subframe_body_length;
3067 memset(&subframe_bulkdata, 0, sizeof(bulk_data_param_t));
3068
3069 csrResult = unifi_net_data_malloc(priv, &subframe_bulkdata.d[0], dot11_hdr_size + subframe_body_length);
3070
3071 if (csrResult != CSR_RESULT_SUCCESS) {
3072 unifi_error(priv, "%s: unifi_net_data_malloc failed\n", __FUNCTION__);
3073 break;
3074 }
3075
3076 memcpy((u8*)subframe_bulkdata.d[0].os_data_ptr, dot11_hdr_ptr, dot11_hdr_size);
3077
3078
3079 /* When to DS=0 and from DS=0, address 3 will already have BSSID so no need to re-program */
3080 if ((frameControl & IEEE802_11_FC_TO_DS_MASK) && !(frameControl & IEEE802_11_FC_FROM_DS_MASK)){
3081 memcpy((u8*)subframe_bulkdata.d[0].os_data_ptr + IEEE802_11_ADDR3_OFFSET, ((struct ethhdr*)ptr)->h_dest, ETH_ALEN);
3082 }
3083 else if (!(frameControl & IEEE802_11_FC_TO_DS_MASK) && (frameControl & IEEE802_11_FC_FROM_DS_MASK)){
3084 memcpy((u8*)subframe_bulkdata.d[0].os_data_ptr + IEEE802_11_ADDR3_OFFSET,
3085 ((struct ethhdr*)ptr)->h_source,
3086 ETH_ALEN);
3087 }
3088
3089 memcpy((u8*)subframe_bulkdata.d[0].os_data_ptr + dot11_hdr_size,
3090 ptr + sizeof(struct ethhdr),
3091 subframe_body_length);
3092 unifi_trace(priv, UDBG6, "%s: calling unifi_rx. length = %d subframe_length = %d\n", __FUNCTION__, length, subframe_length);
3093 unifi_rx(priv, signal, &subframe_bulkdata);
3094
3095 subframe_length = (subframe_length + 3)&(~0x3);
3096 ptr += subframe_length;
3097 offset += subframe_length;
3098 }
3099 unifi_net_data_free(priv, &bulkdata->d[0]);
3100 }
3101
3102
3103 #define SN_TO_INDEX(__ba_session, __sn) (((__sn - __ba_session->start_sn) & 0xFFF) % __ba_session->wind_size)
3104
3105
3106 #define ADVANCE_EXPECTED_SN(__ba_session) \
3107 { \
3108 __ba_session->expected_sn++; \
3109 __ba_session->expected_sn &= 0xFFF; \
3110 }
3111
3112 #define FREE_BUFFER_SLOT(__ba_session, __index) \
3113 { \
3114 __ba_session->occupied_slots--; \
3115 __ba_session->buffer[__index].active = FALSE; \
3116 ADVANCE_EXPECTED_SN(__ba_session); \
3117 }
3118
3119 static void add_frame_to_ba_complete(unifi_priv_t *priv,
3120 netInterface_priv_t *interfacePriv,
3121 frame_desc_struct *frame_desc)
3122 {
3123 interfacePriv->ba_complete[interfacePriv->ba_complete_index] = *frame_desc;
3124 interfacePriv->ba_complete_index++;
3125 }
3126
3127
3128 static void update_expected_sn(unifi_priv_t *priv,
3129 netInterface_priv_t *interfacePriv,
3130 ba_session_rx_struct *ba_session,
3131 u16 sn)
3132 {
3133 int i, j;
3134 u16 gap;
3135
3136 gap = (sn - ba_session->expected_sn) & 0xFFF;
3137 unifi_trace(priv, UDBG6, "%s: proccess the frames up to new_expected_sn = %d gap = %d\n", __FUNCTION__, sn, gap);
3138 for(j = 0; j < gap && j < ba_session->wind_size; j++) {
3139 i = SN_TO_INDEX(ba_session, ba_session->expected_sn);
3140 unifi_trace(priv, UDBG6, "%s: proccess the slot index = %d\n", __FUNCTION__, i);
3141 if(ba_session->buffer[i].active) {
3142 add_frame_to_ba_complete(priv, interfacePriv, &ba_session->buffer[i]);
3143 unifi_trace(priv, UDBG6, "%s: proccess the frame at index = %d expected_sn = %d\n", __FUNCTION__, i, ba_session->expected_sn);
3144 FREE_BUFFER_SLOT(ba_session, i);
3145 } else {
3146 unifi_trace(priv, UDBG6, "%s: empty slot at index = %d\n", __FUNCTION__, i);
3147 ADVANCE_EXPECTED_SN(ba_session);
3148 }
3149 }
3150 ba_session->expected_sn = sn;
3151 }
3152
3153
3154 static void complete_ready_sequence(unifi_priv_t *priv,
3155 netInterface_priv_t *interfacePriv,
3156 ba_session_rx_struct *ba_session)
3157 {
3158 int i;
3159
3160 i = SN_TO_INDEX(ba_session, ba_session->expected_sn);
3161 while (ba_session->buffer[i].active) {
3162 add_frame_to_ba_complete(priv, interfacePriv, &ba_session->buffer[i]);
3163 unifi_trace(priv, UDBG6, "%s: completed stored frame(expected_sn=%d) at i = %d\n", __FUNCTION__, ba_session->expected_sn, i);
3164 FREE_BUFFER_SLOT(ba_session, i);
3165 i = SN_TO_INDEX(ba_session, ba_session->expected_sn);
3166 }
3167 }
3168
3169
3170 void scroll_ba_window(unifi_priv_t *priv,
3171 netInterface_priv_t *interfacePriv,
3172 ba_session_rx_struct *ba_session,
3173 u16 sn)
3174 {
3175 if(((sn - ba_session->expected_sn) & 0xFFF) <= 2048) {
3176 update_expected_sn(priv, interfacePriv, ba_session, sn);
3177 complete_ready_sequence(priv, interfacePriv, ba_session);
3178 }
3179 }
3180
3181
3182 static int consume_frame_or_get_buffer_index(unifi_priv_t *priv,
3183 netInterface_priv_t *interfacePriv,
3184 ba_session_rx_struct *ba_session,
3185 u16 sn,
3186 frame_desc_struct *frame_desc) {
3187 int i;
3188 u16 sn_temp;
3189
3190 if(((sn - ba_session->expected_sn) & 0xFFF) <= 2048) {
3191
3192 /* once we are in BA window, set the flag for BA trigger */
3193 if(!ba_session->trigger_ba_after_ssn){
3194 ba_session->trigger_ba_after_ssn = TRUE;
3195 }
3196
3197 sn_temp = ba_session->expected_sn + ba_session->wind_size;
3198 unifi_trace(priv, UDBG6, "%s: new frame: sn=%d\n", __FUNCTION__, sn);
3199 if(!(((sn - sn_temp) & 0xFFF) > 2048)) {
3200 u16 new_expected_sn;
3201 unifi_trace(priv, UDBG6, "%s: frame is out of window\n", __FUNCTION__);
3202 sn_temp = (sn - ba_session->wind_size) & 0xFFF;
3203 new_expected_sn = (sn_temp + 1) & 0xFFF;
3204 update_expected_sn(priv, interfacePriv, ba_session, new_expected_sn);
3205 }
3206 i = -1;
3207 if (sn == ba_session->expected_sn) {
3208 unifi_trace(priv, UDBG6, "%s: sn = ba_session->expected_sn = %d\n", __FUNCTION__, sn);
3209 ADVANCE_EXPECTED_SN(ba_session);
3210 add_frame_to_ba_complete(priv, interfacePriv, frame_desc);
3211 } else {
3212 i = SN_TO_INDEX(ba_session, sn);
3213 unifi_trace(priv, UDBG6, "%s: sn(%d) != ba_session->expected_sn(%d), i = %d\n", __FUNCTION__, sn, ba_session->expected_sn, i);
3214 if (ba_session->buffer[i].active) {
3215 unifi_trace(priv, UDBG6, "%s: free frame at i = %d\n", __FUNCTION__, i);
3216 i = -1;
3217 unifi_net_data_free(priv, &frame_desc->bulkdata.d[0]);
3218 }
3219 }
3220 } else {
3221 i = -1;
3222 if(!ba_session->trigger_ba_after_ssn){
3223 unifi_trace(priv, UDBG6, "%s: frame before ssn, pass it up: sn=%d\n", __FUNCTION__, sn);
3224 add_frame_to_ba_complete(priv, interfacePriv, frame_desc);
3225 }else{
3226 unifi_trace(priv, UDBG6, "%s: old frame, drop: sn=%d, expected_sn=%d\n", __FUNCTION__, sn, ba_session->expected_sn);
3227 unifi_net_data_free(priv, &frame_desc->bulkdata.d[0]);
3228 }
3229 }
3230 return i;
3231 }
3232
3233
3234
3235 static void process_ba_frame(unifi_priv_t *priv,
3236 netInterface_priv_t *interfacePriv,
3237 ba_session_rx_struct *ba_session,
3238 frame_desc_struct *frame_desc)
3239 {
3240 int i;
3241 u16 sn = frame_desc->sn;
3242
3243 if (ba_session->timeout) {
3244 mod_timer(&ba_session->timer, (jiffies + usecs_to_jiffies((ba_session->timeout) * 1024)));
3245 }
3246 unifi_trace(priv, UDBG6, "%s: got frame(sn=%d)\n", __FUNCTION__, sn);
3247
3248 i = consume_frame_or_get_buffer_index(priv, interfacePriv, ba_session, sn, frame_desc);
3249 if(i >= 0) {
3250 unifi_trace(priv, UDBG6, "%s: store frame(sn=%d) at i = %d\n", __FUNCTION__, sn, i);
3251 ba_session->buffer[i] = *frame_desc;
3252 ba_session->buffer[i].recv_time = CsrTimeGet(NULL);
3253 ba_session->occupied_slots++;
3254 } else {
3255 unifi_trace(priv, UDBG6, "%s: frame consumed - sn = %d\n", __FUNCTION__, sn);
3256 }
3257 complete_ready_sequence(priv, interfacePriv, ba_session);
3258 }
3259
3260
3261 static void process_ba_complete(unifi_priv_t *priv, netInterface_priv_t *interfacePriv)
3262 {
3263 frame_desc_struct *frame_desc;
3264 u8 i;
3265
3266 for(i = 0; i < interfacePriv->ba_complete_index; i++) {
3267 frame_desc = &interfacePriv->ba_complete[i];
3268 unifi_trace(priv, UDBG6, "%s: calling process_amsdu()\n", __FUNCTION__);
3269 process_amsdu(priv, &frame_desc->signal, &frame_desc->bulkdata);
3270 }
3271 interfacePriv->ba_complete_index = 0;
3272
3273 }
3274
3275
3276 /* Check if the frames in BA reoder buffer has aged and
3277 * if so release the frames to upper processes and move
3278 * the window
3279 */
3280 static void check_ba_frame_age_timeout( unifi_priv_t *priv,
3281 netInterface_priv_t *interfacePriv,
3282 ba_session_rx_struct *ba_session)
3283 {
3284 CsrTime now;
3285 CsrTime age;
3286 u8 i, j;
3287 u16 sn_temp;
3288
3289 /* gap is started at 1 because we have buffered frames and
3290 * hence a minimum gap of 1 exists
3291 */
3292 u8 gap=1;
3293
3294 now = CsrTimeGet(NULL);
3295
3296 if (ba_session->occupied_slots)
3297 {
3298 /* expected sequence has not arrived so start searching from next
3299 * sequence number until a frame is available and determine the gap.
3300 * Check if the frame available has timedout, if so advance the
3301 * expected sequence number and release the frames
3302 */
3303 sn_temp = (ba_session->expected_sn + 1) & 0xFFF;
3304
3305 for(j = 0; j < ba_session->wind_size; j++)
3306 {
3307 i = SN_TO_INDEX(ba_session, sn_temp);
3308
3309 if(ba_session->buffer[i].active)
3310 {
3311 unifi_trace(priv, UDBG6, "check age at slot index = %d sn = %d recv_time = %u now = %u\n",
3312 i,
3313 ba_session->buffer[i].sn,
3314 ba_session->buffer[i].recv_time,
3315 now);
3316
3317 if (ba_session->buffer[i].recv_time > now)
3318 {
3319 /* timer wrap */
3320 age = CsrTimeAdd((CsrTime)CsrTimeSub(CSR_SCHED_TIME_MAX, ba_session->buffer[i].recv_time), now);
3321 }
3322 else
3323 {
3324 age = (CsrTime)CsrTimeSub(now, ba_session->buffer[i].recv_time);
3325 }
3326
3327 if (age >= CSR_WIFI_BA_MPDU_FRAME_AGE_TIMEOUT)
3328 {
3329 unifi_trace(priv, UDBG2, "release the frame at index = %d gap = %d expected_sn = %d sn = %d\n",
3330 i,
3331 gap,
3332 ba_session->expected_sn,
3333 ba_session->buffer[i].sn);
3334
3335 /* if it has timedout don't wait for missing frames, move the window */
3336 while (gap--)
3337 {
3338 ADVANCE_EXPECTED_SN(ba_session);
3339 }
3340 add_frame_to_ba_complete(priv, interfacePriv, &ba_session->buffer[i]);
3341 FREE_BUFFER_SLOT(ba_session, i);
3342 complete_ready_sequence(priv, interfacePriv, ba_session);
3343 }
3344 break;
3345
3346 }
3347 else
3348 {
3349 /* advance temp sequence number and frame gap */
3350 sn_temp = (sn_temp + 1) & 0xFFF;
3351 gap++;
3352 }
3353 }
3354 }
3355 }
3356
3357
3358 static void process_ma_packet_error_ind(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata)
3359 {
3360 u16 interfaceTag;
3361 const CSR_MA_PACKET_ERROR_INDICATION *pkt_err_ind = &signal->u.MaPacketErrorIndication;
3362 netInterface_priv_t *interfacePriv;
3363 ba_session_rx_struct *ba_session;
3364 u8 ba_session_idx = 0;
3365 CSR_PRIORITY UserPriority;
3366 CSR_SEQUENCE_NUMBER sn;
3367
3368 func_enter();
3369
3370 interfaceTag = (pkt_err_ind->VirtualInterfaceIdentifier & 0xff);
3371
3372
3373 /* Sanity check that the VIF refers to a sensible interface */
3374 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES)
3375 {
3376 unifi_error(priv, "%s: MaPacketErrorIndication indication with bad interfaceTag %d\n", __FUNCTION__, interfaceTag);
3377 func_exit();
3378 return;
3379 }
3380
3381 interfacePriv = priv->interfacePriv[interfaceTag];
3382 UserPriority = pkt_err_ind->UserPriority;
3383 if(UserPriority > 15) {
3384 unifi_error(priv, "%s: MaPacketErrorIndication indication with bad UserPriority=%d\n", __FUNCTION__, UserPriority);
3385 func_exit();
3386 }
3387 sn = pkt_err_ind->SequenceNumber;
3388
3389 down(&priv->ba_mutex);
3390 /* To find the right ba_session loop through the BA sessions, compare MAC address and tID */
3391 for (ba_session_idx=0; ba_session_idx < MAX_SUPPORTED_BA_SESSIONS_RX; ba_session_idx++){
3392 ba_session = interfacePriv->ba_session_rx[ba_session_idx];
3393 if (ba_session){
3394 if ((!memcmp(ba_session->macAddress.a, pkt_err_ind->PeerQstaAddress.x, ETH_ALEN)) && (ba_session->tID == UserPriority)){
3395 if (ba_session->timeout) {
3396 mod_timer(&ba_session->timer, (jiffies + usecs_to_jiffies((ba_session->timeout) * 1024)));
3397 }
3398 scroll_ba_window(priv, interfacePriv, ba_session, sn);
3399 break;
3400 }
3401 }
3402 }
3403
3404 up(&priv->ba_mutex);
3405 process_ba_complete(priv, interfacePriv);
3406 func_exit();
3407 }
3408
3409
This page took 0.160706 seconds and 5 git commands to generate.