Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2007-2008 Atheros Communications Inc. |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | /* */ |
| 17 | /* Module Name : wrap_pkt.c */ |
| 18 | /* */ |
| 19 | /* Abstract */ |
| 20 | /* This module contains wrapper functions for packet handling */ |
| 21 | /* */ |
| 22 | /* NOTES */ |
| 23 | /* Platform dependent. */ |
| 24 | /* */ |
| 25 | /************************************************************************/ |
| 26 | |
| 27 | #include "oal_dt.h" |
| 28 | #include "usbdrv.h" |
| 29 | |
| 30 | #include <linux/netlink.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/gfp.h> |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 32 | #include <net/iw_handler.h> |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 33 | |
| 34 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 35 | /* extern struct zsWdsStruct wds[ZM_WDS_PORT_NUMBER]; */ |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 36 | extern struct zsVapStruct vap[ZM_VAP_PORT_NUMBER]; |
| 37 | |
| 38 | |
| 39 | /***** Rx *****/ |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 40 | void zfLnxRecv80211(zdev_t *dev, zbuf_t *buf, struct zsAdditionInfo *addInfo) |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 41 | { |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 42 | u16_t frameType; |
| 43 | u16_t frameCtrl; |
| 44 | u16_t frameSubtype; |
| 45 | zbuf_t *skb1; |
| 46 | struct usbdrv_private *macp = dev->ml_priv; |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 47 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 48 | /* frameCtrl = zmw_buf_readb(dev, buf, 0); */ |
| 49 | frameCtrl = *(u8_t *)((u8_t *)buf->data); |
| 50 | frameType = frameCtrl & 0xf; |
| 51 | frameSubtype = frameCtrl & 0xf0; |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 52 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 53 | if ((frameType == 0x0) && (macp->forwardMgmt)) { |
| 54 | switch (frameSubtype) { |
| 55 | /* Beacon */ |
| 56 | case 0x80: |
| 57 | /* Probe response */ |
| 58 | case 0x50: |
| 59 | skb1 = skb_copy(buf, GFP_ATOMIC); |
| 60 | if (skb1 != NULL) { |
| 61 | skb1->dev = dev; |
Jeff Mahoney | 2363912 | 2010-01-11 10:54:30 -0500 | [diff] [blame] | 62 | skb_reset_mac_header(skb1); |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 63 | skb1->ip_summed = CHECKSUM_NONE; |
| 64 | skb1->pkt_type = PACKET_OTHERHOST; |
| 65 | /* ETH_P_80211_RAW */ |
| 66 | skb1->protocol = __constant_htons(0x0019); |
| 67 | netif_rx(skb1); |
| 68 | } |
| 69 | break; |
| 70 | default: |
| 71 | break; |
| 72 | } |
| 73 | } |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 74 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 75 | zfiRecv80211(dev, buf, addInfo); |
| 76 | return; |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | #define ZM_AVOID_UDP_LARGE_PACKET_FAIL |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 80 | void zfLnxRecvEth(zdev_t *dev, zbuf_t *buf, u16_t port) |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 81 | { |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 82 | struct usbdrv_private *macp = dev->ml_priv; |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 83 | #ifdef ZM_AVOID_UDP_LARGE_PACKET_FAIL |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 84 | zbuf_t *new_buf; |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 85 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 86 | /* new_buf = dev_alloc_skb(2048); */ |
| 87 | new_buf = dev_alloc_skb(buf->len); |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 88 | |
Jeff Mahoney | 2363912 | 2010-01-11 10:54:30 -0500 | [diff] [blame] | 89 | skb_reset_tail_pointer(new_buf); |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 90 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 91 | skb_put(new_buf, buf->len); |
| 92 | memcpy(new_buf->data, buf->data, buf->len); |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 93 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 94 | /* Free buffer */ |
| 95 | dev_kfree_skb_any(buf); |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 96 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 97 | if (port == 0) { |
| 98 | new_buf->dev = dev; |
| 99 | new_buf->protocol = eth_type_trans(new_buf, dev); |
| 100 | } else { |
| 101 | /* VAP */ |
| 102 | if (vap[0].dev != NULL) { |
| 103 | new_buf->dev = vap[0].dev; |
| 104 | new_buf->protocol = eth_type_trans(new_buf, vap[0].dev); |
| 105 | } else { |
| 106 | new_buf->dev = dev; |
| 107 | new_buf->protocol = eth_type_trans(new_buf, dev); |
| 108 | } |
| 109 | } |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 110 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 111 | new_buf->ip_summed = CHECKSUM_NONE; |
| 112 | dev->last_rx = jiffies; |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 113 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 114 | switch (netif_rx(new_buf)) |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 115 | #else |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 116 | if (port == 0) { |
| 117 | buf->dev = dev; |
| 118 | buf->protocol = eth_type_trans(buf, dev); |
| 119 | } else { |
| 120 | /* VAP */ |
| 121 | if (vap[0].dev != NULL) { |
| 122 | buf->dev = vap[0].dev; |
| 123 | buf->protocol = eth_type_trans(buf, vap[0].dev); |
| 124 | } else { |
| 125 | buf->dev = dev; |
| 126 | buf->protocol = eth_type_trans(buf, dev); |
| 127 | } |
| 128 | } |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 129 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 130 | buf->ip_summed = CHECKSUM_NONE; |
| 131 | dev->last_rx = jiffies; |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 132 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 133 | switch (netif_rx(buf)) |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 134 | #endif |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 135 | { |
| 136 | case NET_RX_DROP: |
| 137 | break; |
| 138 | default: |
| 139 | macp->drv_stats.net_stats.rx_packets++; |
| 140 | macp->drv_stats.net_stats.rx_bytes += buf->len; |
| 141 | break; |
| 142 | } |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 143 | |
Mithlesh Thukral | 2bef7a0 | 2009-10-26 21:22:55 -0700 | [diff] [blame] | 144 | return; |
Luis R. Rodriguez | 4bd43f5 | 2008-10-27 22:44:22 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* Leave an empty line below to remove warning message on some compiler */ |