blob: 825a63a7c0e319c582c97b5182b501ff5f821054 [file] [log] [blame]
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001/* src/p80211/p80211knetdev.c
2*
3* Linux Kernel net device interface
4*
5* Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6* --------------------------------------------------------------------
7*
8* linux-wlan
9*
10* The contents of this file are subject to the Mozilla Public
11* License Version 1.1 (the "License"); you may not use this file
12* except in compliance with the License. You may obtain a copy of
13* the License at http://www.mozilla.org/MPL/
14*
15* Software distributed under the License is distributed on an "AS
16* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17* implied. See the License for the specific language governing
18* rights and limitations under the License.
19*
20* Alternatively, the contents of this file may be used under the
21* terms of the GNU Public License version 2 (the "GPL"), in which
22* case the provisions of the GPL are applicable instead of the
23* above. If you wish to allow the use of your version of this file
24* only under the terms of the GPL and not to allow others to use
25* your version of this file under the MPL, indicate your decision
26* by deleting the provisions above and replace them with the notice
27* and other provisions required by the GPL. If you do not delete
28* the provisions above, a recipient may use your version of this
29* file under either the MPL or the GPL.
30*
31* --------------------------------------------------------------------
32*
33* Inquiries regarding the linux-wlan Open Source project can be
34* made directly to:
35*
36* AbsoluteValue Systems Inc.
37* info@linux-wlan.com
38* http://www.linux-wlan.com
39*
40* --------------------------------------------------------------------
41*
42* Portions of the development of this software were funded by
43* Intersil Corporation as part of PRISM(R) chipset product development.
44*
45* --------------------------------------------------------------------
46*
47* The functions required for a Linux network device are defined here.
48*
49* --------------------------------------------------------------------
50*/
51
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070052#include <linux/module.h>
53#include <linux/kernel.h>
54#include <linux/sched.h>
55#include <linux/types.h>
56#include <linux/skbuff.h>
57#include <linux/slab.h>
58#include <linux/proc_fs.h>
59#include <linux/interrupt.h>
60#include <linux/netdevice.h>
61#include <linux/kmod.h>
62#include <linux/if_arp.h>
63#include <linux/wireless.h>
64#include <linux/sockios.h>
65#include <linux/etherdevice.h>
Moritz Muehlenhoff28b17a42009-01-21 22:00:41 +010066#include <linux/if_ether.h>
Moritz Muehlenhoffae262302009-01-21 22:00:45 +010067#include <linux/byteorder/generic.h>
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +010068#include <linux/bitops.h>
69#include <linux/uaccess.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070070#include <asm/byteorder.h>
71
72#ifdef SIOCETHTOOL
73#include <linux/ethtool.h>
74#endif
75
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070076#include <net/iw_handler.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070077#include <net/net_namespace.h>
Karl Reltoncb3126e2010-06-03 23:04:06 +010078#include <net/cfg80211.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070079
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070080#include "p80211types.h"
81#include "p80211hdr.h"
82#include "p80211conv.h"
83#include "p80211mgmt.h"
84#include "p80211msg.h"
85#include "p80211netdev.h"
86#include "p80211ioctl.h"
87#include "p80211req.h"
88#include "p80211metastruct.h"
89#include "p80211metadef.h"
90
Karl Reltoncb3126e2010-06-03 23:04:06 +010091#include "cfg80211.c"
92
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070093/* netdevice method functions */
Sergio Paracuellos19066982016-09-27 19:33:51 +020094static int p80211knetdev_init(struct net_device *netdev);
95static int p80211knetdev_open(struct net_device *netdev);
96static int p80211knetdev_stop(struct net_device *netdev);
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +010097static int p80211knetdev_hard_start_xmit(struct sk_buff *skb,
Sergio Paracuellos19066982016-09-27 19:33:51 +020098 struct net_device *netdev);
99static void p80211knetdev_set_multicast_list(struct net_device *dev);
100static int p80211knetdev_do_ioctl(struct net_device *dev, struct ifreq *ifr,
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100101 int cmd);
Sergio Paracuellos19066982016-09-27 19:33:51 +0200102static int p80211knetdev_set_mac_address(struct net_device *dev, void *addr);
103static void p80211knetdev_tx_timeout(struct net_device *netdev);
sayli karnikc9573a82016-09-18 15:11:14 +0530104static int p80211_rx_typedrop(struct wlandevice *wlandev, u16 fc);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700105
Solomon Peachye02c69b2008-10-29 10:42:59 -0400106int wlan_watchdog = 5000;
107module_param(wlan_watchdog, int, 0644);
108MODULE_PARM_DESC(wlan_watchdog, "transmit timeout in milliseconds");
109
110int wlan_wext_write = 1;
111module_param(wlan_wext_write, int, 0644);
112MODULE_PARM_DESC(wlan_wext_write, "enable write wireless extensions");
113
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700114/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700115* p80211knetdev_init
116*
117* Init method for a Linux netdevice. Called in response to
118* register_netdev.
119*
120* Arguments:
121* none
122*
123* Returns:
124* nothing
125----------------------------------------------------------------*/
Sergio Paracuellos19066982016-09-27 19:33:51 +0200126static int p80211knetdev_init(struct net_device *netdev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700127{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700128 /* Called in response to register_netdev */
129 /* This is usually the probe function, but the probe has */
130 /* already been done by the MSD and the create_kdev */
131 /* function. All we do here is return success */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700132 return 0;
133}
134
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700135/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700136* p80211knetdev_open
137*
138* Linux netdevice open method. Following a successful call here,
139* the device is supposed to be ready for tx and rx. In our
140* situation that may not be entirely true due to the state of the
141* MAC below.
142*
143* Arguments:
144* netdev Linux network device structure
145*
146* Returns:
147* zero on success, non-zero otherwise
148----------------------------------------------------------------*/
Sergio Paracuellos19066982016-09-27 19:33:51 +0200149static int p80211knetdev_open(struct net_device *netdev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700150{
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100151 int result = 0; /* success */
sayli karnikc9573a82016-09-18 15:11:14 +0530152 struct wlandevice *wlandev = netdev->ml_priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700153
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700154 /* Check to make sure the MSD is running */
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100155 if (wlandev->msdstate != WLAN_MSD_RUNNING)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700156 return -ENODEV;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700157
158 /* Tell the MSD to open */
Sandhya Bankarf3dbe302016-03-21 20:46:15 +0530159 if (wlandev->open) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700160 result = wlandev->open(wlandev);
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100161 if (result == 0) {
Solomon Peachycbec30c2008-10-29 10:42:57 -0400162 netif_start_queue(wlandev->netdev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700163 wlandev->state = WLAN_DEVICE_OPEN;
164 }
165 } else {
166 result = -EAGAIN;
167 }
168
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700169 return result;
170}
171
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700172/*----------------------------------------------------------------
173* p80211knetdev_stop
174*
175* Linux netdevice stop (close) method. Following this call,
176* no frames should go up or down through this interface.
177*
178* Arguments:
179* netdev Linux network device structure
180*
181* Returns:
182* zero on success, non-zero otherwise
183----------------------------------------------------------------*/
Sergio Paracuellos19066982016-09-27 19:33:51 +0200184static int p80211knetdev_stop(struct net_device *netdev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700185{
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100186 int result = 0;
sayli karnikc9573a82016-09-18 15:11:14 +0530187 struct wlandevice *wlandev = netdev->ml_priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700188
Sandhya Bankarf3dbe302016-03-21 20:46:15 +0530189 if (wlandev->close)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700190 result = wlandev->close(wlandev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700191
Solomon Peachycbec30c2008-10-29 10:42:57 -0400192 netif_stop_queue(wlandev->netdev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700193 wlandev->state = WLAN_DEVICE_CLOSED;
194
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700195 return result;
196}
197
198/*----------------------------------------------------------------
199* p80211netdev_rx
200*
201* Frame receive function called by the mac specific driver.
202*
203* Arguments:
204* wlandev WLAN network device structure
205* skb skbuff containing a full 802.11 frame.
206* Returns:
207* nothing
208* Side effects:
209*
210----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +0530211void p80211netdev_rx(struct wlandevice *wlandev, struct sk_buff *skb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700212{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700213 /* Enqueue for post-irq processing */
214 skb_queue_tail(&wlandev->nsd_rxq, skb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700215 tasklet_schedule(&wlandev->rx_bh);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700216}
217
Denis Pithonccc3a592014-05-12 17:22:46 +0200218#define CONV_TO_ETHER_SKIPPED 0x01
219#define CONV_TO_ETHER_FAILED 0x02
220
221/**
Denis Pithonae4af9a2014-05-17 00:30:16 +0200222 * p80211_convert_to_ether - conversion from 802.11 frame to ethernet frame
Denis Pithonccc3a592014-05-12 17:22:46 +0200223 * @wlandev: pointer to WLAN device
224 * @skb: pointer to socket buffer
225 *
226 * Returns: 0 if conversion succeeded
227 * CONV_TO_ETHER_FAILED if conversion failed
228 * CONV_TO_ETHER_SKIPPED if frame is ignored
229 */
sayli karnikc9573a82016-09-18 15:11:14 +0530230static int p80211_convert_to_ether(struct wlandevice *wlandev, struct sk_buff *skb)
Denis Pithonccc3a592014-05-12 17:22:46 +0200231{
232 struct p80211_hdr_a3 *hdr;
233
Jannik Becher0e21fa42016-09-23 01:02:10 +0200234 hdr = (struct p80211_hdr_a3 *)skb->data;
Denis Pithonccc3a592014-05-12 17:22:46 +0200235 if (p80211_rx_typedrop(wlandev, hdr->fc))
236 return CONV_TO_ETHER_SKIPPED;
237
Denis Pithon95c96682014-05-17 00:14:52 +0200238 /* perform mcast filtering: allow my local address through but reject
239 * anything else that isn't multicast
240 */
Denis Pithonccc3a592014-05-12 17:22:46 +0200241 if (wlandev->netdev->flags & IFF_ALLMULTI) {
Denis Pithon9b3ac7a2014-05-17 00:14:50 +0200242 if (!ether_addr_equal_unaligned(wlandev->netdev->dev_addr,
243 hdr->a1)) {
Denis Pithon02b3b532014-05-17 00:14:51 +0200244 if (!is_multicast_ether_addr(hdr->a1))
Denis Pithonccc3a592014-05-12 17:22:46 +0200245 return CONV_TO_ETHER_SKIPPED;
246 }
247 }
248
249 if (skb_p80211_to_ether(wlandev, wlandev->ethconv, skb) == 0) {
250 skb->dev->last_rx = jiffies;
Tobias Klauser9630f6b2014-07-08 08:37:00 +0200251 wlandev->netdev->stats.rx_packets++;
252 wlandev->netdev->stats.rx_bytes += skb->len;
Denis Pithonccc3a592014-05-12 17:22:46 +0200253 netif_rx_ni(skb);
254 return 0;
255 }
256
Denis Pithon79f9e632014-05-17 00:24:09 +0200257 netdev_dbg(wlandev->netdev, "p80211_convert_to_ether failed.\n");
Denis Pithonccc3a592014-05-12 17:22:46 +0200258 return CONV_TO_ETHER_FAILED;
259}
260
Denis Pithon67c4ded2014-05-12 17:22:44 +0200261/**
262 * p80211netdev_rx_bh - deferred processing of all received frames
263 *
264 * @arg: pointer to WLAN network device structure (cast to unsigned long)
265 */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700266static void p80211netdev_rx_bh(unsigned long arg)
267{
Jannik Becher0e21fa42016-09-23 01:02:10 +0200268 struct wlandevice *wlandev = (struct wlandevice *)arg;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700269 struct sk_buff *skb = NULL;
Sergio Paracuellos19066982016-09-27 19:33:51 +0200270 struct net_device *dev = wlandev->netdev;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700271
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700272 /* Let's empty our our queue */
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100273 while ((skb = skb_dequeue(&wlandev->nsd_rxq))) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700274 if (wlandev->state == WLAN_DEVICE_OPEN) {
275
276 if (dev->type != ARPHRD_ETHER) {
277 /* RAW frame; we shouldn't convert it */
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100278 /* XXX Append the Prism Header here instead. */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700279
280 /* set up various data fields */
281 skb->dev = dev;
282 skb_reset_mac_header(skb);
283 skb->ip_summed = CHECKSUM_NONE;
284 skb->pkt_type = PACKET_OTHERHOST;
285 skb->protocol = htons(ETH_P_80211_RAW);
286 dev->last_rx = jiffies;
287
Tobias Klauser9630f6b2014-07-08 08:37:00 +0200288 dev->stats.rx_packets++;
289 dev->stats.rx_bytes += skb->len;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700290 netif_rx_ni(skb);
291 continue;
292 } else {
Denis Pithonae4af9a2014-05-17 00:30:16 +0200293 if (!p80211_convert_to_ether(wlandev, skb))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700294 continue;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700295 }
296 }
297 dev_kfree_skb(skb);
298 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700299}
300
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700301/*----------------------------------------------------------------
302* p80211knetdev_hard_start_xmit
303*
304* Linux netdevice method for transmitting a frame.
305*
306* Arguments:
307* skb Linux sk_buff containing the frame.
308* netdev Linux netdevice.
309*
310* Side effects:
311* If the lower layers report that buffers are full. netdev->tbusy
312* will be set to prevent higher layers from sending more traffic.
313*
314* Note: If this function returns non-zero, higher layers retain
315* ownership of the skb.
316*
317* Returns:
318* zero on success, non-zero on failure.
319----------------------------------------------------------------*/
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100320static int p80211knetdev_hard_start_xmit(struct sk_buff *skb,
Sergio Paracuellos19066982016-09-27 19:33:51 +0200321 struct net_device *netdev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700322{
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100323 int result = 0;
324 int txresult = -1;
sayli karnikc9573a82016-09-18 15:11:14 +0530325 struct wlandevice *wlandev = netdev->ml_priv;
Edgardo Hames93df38e2010-07-30 22:51:55 -0300326 union p80211_hdr p80211_hdr;
Edgardo Hames51e48962010-07-31 13:06:52 -0300327 struct p80211_metawep p80211_wep;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700328
Peter Huewefae7e4d2013-02-14 03:37:10 +0100329 p80211_wep.data = NULL;
330
Fu Yong Quah1e613802016-02-20 10:23:14 +0000331 if (!skb)
Patrick McHardyec634fe2009-07-05 19:23:38 -0700332 return NETDEV_TX_OK;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700333
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100334 if (wlandev->state != WLAN_DEVICE_OPEN) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700335 result = 1;
336 goto failed;
337 }
338
Edgardo Hames93df38e2010-07-30 22:51:55 -0300339 memset(&p80211_hdr, 0, sizeof(union p80211_hdr));
Edgardo Hames51e48962010-07-31 13:06:52 -0300340 memset(&p80211_wep, 0, sizeof(struct p80211_metawep));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700341
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100342 if (netif_queue_stopped(netdev)) {
Denis Pithon79f9e632014-05-17 00:24:09 +0200343 netdev_dbg(netdev, "called when queue stopped.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700344 result = 1;
345 goto failed;
346 }
347
348 netif_stop_queue(netdev);
349
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700350 /* Check to see that a valid mode is set */
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100351 switch (wlandev->macmode) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700352 case WLAN_MACMODE_IBSS_STA:
353 case WLAN_MACMODE_ESS_STA:
354 case WLAN_MACMODE_ESS_AP:
355 break;
356 default:
357 /* Mode isn't set yet, just drop the frame
358 * and return success .
359 * TODO: we need a saner way to handle this
360 */
Ebru Akagunduzcb6c1ee2014-10-21 02:47:29 +0300361 if (be16_to_cpu(skb->protocol) != ETH_P_80211_RAW) {
Solomon Peachycbec30c2008-10-29 10:42:57 -0400362 netif_start_queue(wlandev->netdev);
Denis Pithon79f9e632014-05-17 00:24:09 +0200363 netdev_notice(netdev, "Tx attempt prior to association, frame dropped.\n");
Tobias Klauser9630f6b2014-07-08 08:37:00 +0200364 netdev->stats.tx_dropped++;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700365 result = 0;
366 goto failed;
367 }
368 break;
369 }
370
371 /* Check for raw transmits */
Ebru Akagunduzcb6c1ee2014-10-21 02:47:29 +0300372 if (be16_to_cpu(skb->protocol) == ETH_P_80211_RAW) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700373 if (!capable(CAP_NET_ADMIN)) {
374 result = 1;
375 goto failed;
376 }
377 /* move the header over */
Edgardo Hames93df38e2010-07-30 22:51:55 -0300378 memcpy(&p80211_hdr, skb->data, sizeof(union p80211_hdr));
379 skb_pull(skb, sizeof(union p80211_hdr));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700380 } else {
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100381 if (skb_ether_to_p80211
382 (wlandev, wlandev->ethconv, skb, &p80211_hdr,
383 &p80211_wep) != 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700384 /* convert failed */
Denis Pithon79f9e632014-05-17 00:24:09 +0200385 netdev_dbg(netdev, "ether_to_80211(%d) failed.\n",
386 wlandev->ethconv);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700387 result = 1;
388 goto failed;
389 }
390 }
Fu Yong Quah1e613802016-02-20 10:23:14 +0000391 if (!wlandev->txframe) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700392 result = 1;
393 goto failed;
394 }
395
Florian Westphal860e9532016-05-03 16:33:13 +0200396 netif_trans_update(netdev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700397
Tobias Klauser9630f6b2014-07-08 08:37:00 +0200398 netdev->stats.tx_packets++;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700399 /* count only the packet payload */
Tobias Klauser9630f6b2014-07-08 08:37:00 +0200400 netdev->stats.tx_bytes += skb->len;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700401
402 txresult = wlandev->txframe(wlandev, skb, &p80211_hdr, &p80211_wep);
403
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100404 if (txresult == 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700405 /* success and more buf */
406 /* avail, re: hw_txdata */
Solomon Peachycbec30c2008-10-29 10:42:57 -0400407 netif_wake_queue(wlandev->netdev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000408 result = NETDEV_TX_OK;
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100409 } else if (txresult == 1) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700410 /* success, no more avail */
Denis Pithon79f9e632014-05-17 00:24:09 +0200411 netdev_dbg(netdev, "txframe success, no more bufs\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700412 /* netdev->tbusy = 1; don't set here, irqhdlr */
413 /* may have already cleared it */
Patrick McHardy5b548142009-06-12 06:22:29 +0000414 result = NETDEV_TX_OK;
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100415 } else if (txresult == 2) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700416 /* alloc failure, drop frame */
Denis Pithon79f9e632014-05-17 00:24:09 +0200417 netdev_dbg(netdev, "txframe returned alloc_fail\n");
Patrick McHardy5b548142009-06-12 06:22:29 +0000418 result = NETDEV_TX_BUSY;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700419 } else {
420 /* buffer full or queue busy, drop frame. */
Denis Pithon79f9e632014-05-17 00:24:09 +0200421 netdev_dbg(netdev, "txframe returned full or busy\n");
Patrick McHardy5b548142009-06-12 06:22:29 +0000422 result = NETDEV_TX_BUSY;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700423 }
424
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100425failed:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700426 /* Free up the WEP buffer if it's not the same as the skb */
427 if ((p80211_wep.data) && (p80211_wep.data != skb->data))
Moritz Muehlenhoff2f585192009-06-21 22:43:45 +0200428 kzfree(p80211_wep.data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700429
430 /* we always free the skb here, never in a lower level. */
431 if (!result)
432 dev_kfree_skb(skb);
433
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700434 return result;
435}
436
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700437/*----------------------------------------------------------------
438* p80211knetdev_set_multicast_list
439*
Justin P. Mattockd34602d2012-09-24 09:16:57 -0700440* Called from higher layers whenever there's a need to set/clear
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700441* promiscuous mode or rewrite the multicast list.
442*
443* Arguments:
444* none
445*
446* Returns:
447* nothing
448----------------------------------------------------------------*/
Sergio Paracuellos19066982016-09-27 19:33:51 +0200449static void p80211knetdev_set_multicast_list(struct net_device *dev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700450{
sayli karnikc9573a82016-09-18 15:11:14 +0530451 struct wlandevice *wlandev = dev->ml_priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700452
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700453 /* TODO: real multicast support as well */
454
455 if (wlandev->set_multicast_list)
456 wlandev->set_multicast_list(wlandev, dev);
457
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700458}
459
460#ifdef SIOCETHTOOL
461
sayli karnikc9573a82016-09-18 15:11:14 +0530462static int p80211netdev_ethtool(struct wlandevice *wlandev, void __user *useraddr)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700463{
Solomon Peachyaaad4302008-10-29 10:42:53 -0400464 u32 ethcmd;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700465 struct ethtool_drvinfo info;
466 struct ethtool_value edata;
467
468 memset(&info, 0, sizeof(info));
469 memset(&edata, 0, sizeof(edata));
470
471 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
472 return -EFAULT;
473
474 switch (ethcmd) {
475 case ETHTOOL_GDRVINFO:
476 info.cmd = ethcmd;
477 snprintf(info.driver, sizeof(info.driver), "p80211_%s",
478 wlandev->nsdname);
479 snprintf(info.version, sizeof(info.version), "%s",
480 WLAN_RELEASE);
481
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700482 if (copy_to_user(useraddr, &info, sizeof(info)))
483 return -EFAULT;
484 return 0;
485#ifdef ETHTOOL_GLINK
486 case ETHTOOL_GLINK:
487 edata.cmd = ethcmd;
488
489 if (wlandev->linkstatus &&
490 (wlandev->macmode != WLAN_MACMODE_NONE)) {
491 edata.data = 1;
492 } else {
493 edata.data = 0;
494 }
495
496 if (copy_to_user(useraddr, &edata, sizeof(edata)))
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100497 return -EFAULT;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700498 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700499#endif
Maximiliano David Bustosc3444e52010-11-08 17:34:57 -0300500 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700501
502 return -EOPNOTSUPP;
503}
504
505#endif
506
507/*----------------------------------------------------------------
508* p80211knetdev_do_ioctl
509*
510* Handle an ioctl call on one of our devices. Everything Linux
511* ioctl specific is done here. Then we pass the contents of the
512* ifr->data to the request message handler.
513*
514* Arguments:
515* dev Linux kernel netdevice
516* ifr Our private ioctl request structure, typed for the
517* generic struct ifreq so we can use ptr to func
518* w/o cast.
519*
520* Returns:
521* zero on success, a negative errno on failure. Possible values:
522* -ENETDOWN Device isn't up.
523* -EBUSY cmd already in progress
524* -ETIME p80211 cmd timed out (MSD may have its own timers)
525* -EFAULT memory fault copying msg from user buffer
526* -ENOMEM unable to allocate kernel msg buffer
527* -ENOSYS bad magic, it the cmd really for us?
Solomon Peachyaaad4302008-10-29 10:42:53 -0400528* -EintR sleeping on cmd, awakened by signal, cmd cancelled.
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700529*
530* Call Context:
531* Process thread (ioctl caller). TODO: SMP support may require
532* locks.
533----------------------------------------------------------------*/
Sergio Paracuellos19066982016-09-27 19:33:51 +0200534static int p80211knetdev_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700535{
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100536 int result = 0;
Jannik Becher0e21fa42016-09-23 01:02:10 +0200537 struct p80211ioctl_req *req = (struct p80211ioctl_req *)ifr;
sayli karnikc9573a82016-09-18 15:11:14 +0530538 struct wlandevice *wlandev = dev->ml_priv;
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100539 u8 *msgbuf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700540
Denis Pithon79f9e632014-05-17 00:24:09 +0200541 netdev_dbg(dev, "rx'd ioctl, cmd=%d, len=%d\n", cmd, req->len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700542
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700543#ifdef SIOCETHTOOL
544 if (cmd == SIOCETHTOOL) {
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100545 result =
546 p80211netdev_ethtool(wlandev, (void __user *)ifr->ifr_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700547 goto bail;
548 }
549#endif
550
551 /* Test the magic, assume ifr is good if it's there */
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100552 if (req->magic != P80211_IOCTL_MAGIC) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700553 result = -ENOSYS;
554 goto bail;
555 }
556
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100557 if (cmd == P80211_IFTEST) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700558 result = 0;
559 goto bail;
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100560 } else if (cmd != P80211_IFREQ) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700561 result = -ENOSYS;
562 goto bail;
563 }
564
565 /* Allocate a buf of size req->len */
Svenne Krap5dd8acc2010-02-14 18:59:00 +0100566 msgbuf = kmalloc(req->len, GFP_KERNEL);
567 if (msgbuf) {
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100568 if (copy_from_user(msgbuf, (void __user *)req->data, req->len))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700569 result = -EFAULT;
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100570 else
571 result = p80211req_dorequest(wlandev, msgbuf);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700572
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100573 if (result == 0) {
574 if (copy_to_user
575 ((void __user *)req->data, msgbuf, req->len)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700576 result = -EFAULT;
577 }
578 }
579 kfree(msgbuf);
580 } else {
581 result = -ENOMEM;
582 }
583bail:
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300584 /* If allocate,copyfrom or copyto fails, return errno */
585 return result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700586}
587
588/*----------------------------------------------------------------
589* p80211knetdev_set_mac_address
590*
591* Handles the ioctl for changing the MACAddress of a netdevice
592*
593* references: linux/netdevice.h and drivers/net/net_init.c
594*
595* NOTE: [MSM] We only prevent address changes when the netdev is
596* up. We don't control anything based on dot11 state. If the
597* address is changed on a STA that's currently associated, you
598* will probably lose the ability to send and receive data frames.
599* Just be aware. Therefore, this should usually only be done
600* prior to scan/join/auth/assoc.
601*
602* Arguments:
603* dev netdevice struct
604* addr the new MACAddress (a struct)
605*
606* Returns:
607* zero on success, a negative errno on failure. Possible values:
608* -EBUSY device is bussy (cmd not possible)
609* -and errors returned by: p80211req_dorequest(..)
610*
611* by: Collin R. Mulliner <collin@mulliner.org>
612----------------------------------------------------------------*/
Sergio Paracuellos19066982016-09-27 19:33:51 +0200613static int p80211knetdev_set_mac_address(struct net_device *dev, void *addr)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700614{
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100615 struct sockaddr *new_addr = addr;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300616 struct p80211msg_dot11req_mibset dot11req;
Sergio Paracuellos37e48662016-09-25 15:35:05 +0200617 struct p80211item_unk392 *mibattr;
Sergio Paracuellos34aae052016-09-25 15:35:01 +0200618 struct p80211item_pstr6 *macaddr;
Sergio Paracuellosb26b2322016-09-25 15:35:00 +0200619 struct p80211item_uint32 *resultcode;
Devendra Naga909ff712012-09-09 18:41:02 +0530620 int result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700621
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700622 /* If we're running, we don't allow MAC address changes */
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100623 if (netif_running(dev))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700624 return -EBUSY;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700625
626 /* Set up some convenience pointers. */
627 mibattr = &dot11req.mibattribute;
Sergio Paracuellos34aae052016-09-25 15:35:01 +0200628 macaddr = (struct p80211item_pstr6 *)&mibattr->data;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700629 resultcode = &dot11req.resultcode;
630
631 /* Set up a dot11req_mibset */
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300632 memset(&dot11req, 0, sizeof(struct p80211msg_dot11req_mibset));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700633 dot11req.msgcode = DIDmsg_dot11req_mibset;
Edgardo Hamesb6bb56e2010-08-02 16:20:39 -0300634 dot11req.msglen = sizeof(struct p80211msg_dot11req_mibset);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700635 memcpy(dot11req.devname,
Jannik Becher0e21fa42016-09-23 01:02:10 +0200636 ((struct wlandevice *)dev->ml_priv)->name, WLAN_DEVNAMELEN_MAX - 1);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700637
638 /* Set up the mibattribute argument */
639 mibattr->did = DIDmsg_dot11req_mibset_mibattribute;
640 mibattr->status = P80211ENUM_msgitem_status_data_ok;
641 mibattr->len = sizeof(mibattr->data);
642
643 macaddr->did = DIDmib_dot11mac_dot11OperationTable_dot11MACAddress;
644 macaddr->status = P80211ENUM_msgitem_status_data_ok;
645 macaddr->len = sizeof(macaddr->data);
Moritz Muehlenhoff28b17a42009-01-21 22:00:41 +0100646 macaddr->data.len = ETH_ALEN;
647 memcpy(&macaddr->data.data, new_addr->sa_data, ETH_ALEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700648
649 /* Set up the resultcode argument */
650 resultcode->did = DIDmsg_dot11req_mibset_resultcode;
651 resultcode->status = P80211ENUM_msgitem_status_no_value;
652 resultcode->len = sizeof(resultcode->data);
653 resultcode->data = 0;
654
655 /* now fire the request */
Jannik Becher0e21fa42016-09-23 01:02:10 +0200656 result = p80211req_dorequest(dev->ml_priv, (u8 *)&dot11req);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700657
658 /* If the request wasn't successful, report an error and don't
659 * change the netdev address
660 */
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100661 if (result != 0 || resultcode->data != P80211ENUM_resultcode_success) {
Denis Pithon79f9e632014-05-17 00:24:09 +0200662 netdev_err(dev, "Low-level driver failed dot11req_mibset(dot11MACAddress).\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700663 result = -EADDRNOTAVAIL;
664 } else {
665 /* everything's ok, change the addr in netdev */
666 memcpy(dev->dev_addr, new_addr->sa_data, dev->addr_len);
667 }
668
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700669 return result;
670}
671
Sergio Paracuellos19066982016-09-27 19:33:51 +0200672static int wlan_change_mtu(struct net_device *dev, int new_mtu)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700673{
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100674 /* 2312 is max 802.11 payload, 20 is overhead, (ether + llc +snap)
675 and another 8 for wep. */
676 if ((new_mtu < 68) || (new_mtu > (2312 - 20 - 8)))
677 return -EINVAL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700678
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100679 dev->mtu = new_mtu;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700680
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100681 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700682}
683
Alexander Beregalovcea96772009-03-29 19:31:28 +0400684static const struct net_device_ops p80211_netdev_ops = {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530685 .ndo_init = p80211knetdev_init,
686 .ndo_open = p80211knetdev_open,
687 .ndo_stop = p80211knetdev_stop,
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530688 .ndo_start_xmit = p80211knetdev_hard_start_xmit,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000689 .ndo_set_rx_mode = p80211knetdev_set_multicast_list,
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530690 .ndo_do_ioctl = p80211knetdev_do_ioctl,
691 .ndo_set_mac_address = p80211knetdev_set_mac_address,
692 .ndo_tx_timeout = p80211knetdev_tx_timeout,
693 .ndo_change_mtu = wlan_change_mtu,
694 .ndo_validate_addr = eth_validate_addr,
Alexander Beregalovcea96772009-03-29 19:31:28 +0400695};
696
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700697/*----------------------------------------------------------------
698* wlan_setup
699*
700* Roughly matches the functionality of ether_setup. Here
701* we set up any members of the wlandevice structure that are common
702* to all devices. Additionally, we allocate a linux 'struct device'
703* and perform the same setup as ether_setup.
704*
705* Note: It's important that the caller have setup the wlandev->name
706* ptr prior to calling this function.
707*
708* Arguments:
709* wlandev ptr to the wlandev structure for the
710* interface.
Karl Reltoncb3126e2010-06-03 23:04:06 +0100711* physdev ptr to usb device
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700712* Returns:
713* zero on success, non-zero otherwise.
714* Call Context:
715* Should be process thread. We'll assume it might be
716* interrupt though. When we add support for statically
717* compiled drivers, this function will be called in the
718* context of the kernel startup code.
719----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +0530720int wlan_setup(struct wlandevice *wlandev, struct device *physdev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700721{
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100722 int result = 0;
Sergio Paracuellos19066982016-09-27 19:33:51 +0200723 struct net_device *netdev;
Karl Reltoncb3126e2010-06-03 23:04:06 +0100724 struct wiphy *wiphy;
725 struct wireless_dev *wdev;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700726
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700727 /* Set up the wlandev */
728 wlandev->state = WLAN_DEVICE_CLOSED;
729 wlandev->ethconv = WLAN_ETHCONV_8021h;
730 wlandev->macmode = WLAN_MACMODE_NONE;
731
732 /* Set up the rx queue */
733 skb_queue_head_init(&wlandev->nsd_rxq);
734 tasklet_init(&wlandev->rx_bh,
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100735 p80211netdev_rx_bh, (unsigned long)wlandev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700736
Karl Reltoncb3126e2010-06-03 23:04:06 +0100737 /* Allocate and initialize the wiphy struct */
738 wiphy = wlan_create_wiphy(physdev, wlandev);
Fu Yong Quah1e613802016-02-20 10:23:14 +0000739 if (!wiphy) {
Denis Pithon79f9e632014-05-17 00:24:09 +0200740 dev_err(physdev, "Failed to alloc wiphy.\n");
Karl Reltoncb3126e2010-06-03 23:04:06 +0100741 return 1;
742 }
743
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700744 /* Allocate and initialize the struct device */
Johan Meiring6f710902010-11-06 18:21:59 +0200745 netdev = alloc_netdev(sizeof(struct wireless_dev), "wlan%d",
Tom Gundersenc835a672014-07-14 16:37:24 +0200746 NET_NAME_UNKNOWN, ether_setup);
Fu Yong Quah1e613802016-02-20 10:23:14 +0000747 if (!netdev) {
Denis Pithon79f9e632014-05-17 00:24:09 +0200748 dev_err(physdev, "Failed to alloc netdev.\n");
Karl Reltoncb3126e2010-06-03 23:04:06 +0100749 wlan_free_wiphy(wiphy);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700750 result = 1;
751 } else {
Karl Reltoncb3126e2010-06-03 23:04:06 +0100752 wlandev->netdev = netdev;
753 netdev->ml_priv = wlandev;
754 netdev->netdev_ops = &p80211_netdev_ops;
755 wdev = netdev_priv(netdev);
756 wdev->wiphy = wiphy;
757 wdev->iftype = NL80211_IFTYPE_STATION;
758 netdev->ieee80211_ptr = wdev;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700759
Karl Reltoncb3126e2010-06-03 23:04:06 +0100760 netif_stop_queue(netdev);
761 netif_carrier_off(netdev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700762 }
763
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700764 return result;
765}
766
767/*----------------------------------------------------------------
768* wlan_unsetup
769*
770* This function is paired with the wlan_setup routine. It should
771* be called after unregister_wlandev. Basically, all it does is
772* free the 'struct device' that's associated with the wlandev.
773* We do it here because the 'struct device' isn't allocated
774* explicitly in the driver code, it's done in wlan_setup. To
775* do the free in the driver might seem like 'magic'.
776*
777* Arguments:
778* wlandev ptr to the wlandev structure for the
779* interface.
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700780* Call Context:
781* Should be process thread. We'll assume it might be
782* interrupt though. When we add support for statically
783* compiled drivers, this function will be called in the
784* context of the kernel startup code.
785----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +0530786void wlan_unsetup(struct wlandevice *wlandev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700787{
Karl Reltoncb3126e2010-06-03 23:04:06 +0100788 struct wireless_dev *wdev;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700789
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700790 tasklet_kill(&wlandev->rx_bh);
791
Karl Reltoncb3126e2010-06-03 23:04:06 +0100792 if (wlandev->netdev) {
793 wdev = netdev_priv(wlandev->netdev);
Edgardo Hamesf34e3e72010-07-21 22:31:55 -0300794 if (wdev->wiphy)
795 wlan_free_wiphy(wdev->wiphy);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700796 free_netdev(wlandev->netdev);
797 wlandev->netdev = NULL;
798 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700799}
800
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700801/*----------------------------------------------------------------
802* register_wlandev
803*
804* Roughly matches the functionality of register_netdev. This function
805* is called after the driver has successfully probed and set up the
806* resources for the device. It's now ready to become a named device
807* in the Linux system.
808*
809* First we allocate a name for the device (if not already set), then
810* we call the Linux function register_netdevice.
811*
812* Arguments:
813* wlandev ptr to the wlandev structure for the
814* interface.
815* Returns:
816* zero on success, non-zero otherwise.
817* Call Context:
818* Can be either interrupt or not.
819----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +0530820int register_wlandev(struct wlandevice *wlandev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700821{
Devendra Naga50d6b9b2012-09-09 18:41:01 +0530822 return register_netdev(wlandev->netdev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700823}
824
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700825/*----------------------------------------------------------------
826* unregister_wlandev
827*
828* Roughly matches the functionality of unregister_netdev. This
829* function is called to remove a named device from the system.
830*
831* First we tell linux that the device should no longer exist.
832* Then we remove it from the list of known wlan devices.
833*
834* Arguments:
835* wlandev ptr to the wlandev structure for the
836* interface.
837* Returns:
838* zero on success, non-zero otherwise.
839* Call Context:
840* Can be either interrupt or not.
841----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +0530842int unregister_wlandev(struct wlandevice *wlandev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700843{
844 struct sk_buff *skb;
845
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700846 unregister_netdev(wlandev->netdev);
847
848 /* Now to clean out the rx queue */
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100849 while ((skb = skb_dequeue(&wlandev->nsd_rxq)))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700850 dev_kfree_skb(skb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700851
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700852 return 0;
853}
854
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700855/*----------------------------------------------------------------
856* p80211netdev_hwremoved
857*
858* Hardware removed notification. This function should be called
859* immediately after an MSD has detected that the underlying hardware
860* has been yanked out from under us. The primary things we need
861* to do are:
862* - Mark the wlandev
863* - Prevent any further traffic from the knetdev i/f
864* - Prevent any further requests from mgmt i/f
865* - If there are any waitq'd mgmt requests or mgmt-frame exchanges,
866* shut them down.
867* - Call the MSD hwremoved function.
868*
869* The remainder of the cleanup will be handled by unregister().
870* Our primary goal here is to prevent as much tickling of the MSD
871* as possible since the MSD is already in a 'wounded' state.
872*
873* TODO: As new features are added, this function should be
874* updated.
875*
876* Arguments:
877* wlandev WLAN network device structure
878* Returns:
879* nothing
880* Side effects:
881*
882* Call context:
883* Usually interrupt.
884----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +0530885void p80211netdev_hwremoved(struct wlandevice *wlandev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700886{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700887 wlandev->hwremoved = 1;
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100888 if (wlandev->state == WLAN_DEVICE_OPEN)
Solomon Peachycbec30c2008-10-29 10:42:57 -0400889 netif_stop_queue(wlandev->netdev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700890
891 netif_device_detach(wlandev->netdev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700892}
893
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700894/*----------------------------------------------------------------
895* p80211_rx_typedrop
896*
897* Classifies the frame, increments the appropriate counter, and
898* returns 0|1|2 indicating whether the driver should handle, ignore, or
899* drop the frame
900*
901* Arguments:
902* wlandev wlan device structure
903* fc frame control field
904*
905* Returns:
906* zero if the frame should be handled by the driver,
907* one if the frame should be ignored
908* anything else means we drop it.
909*
910* Side effects:
911*
912* Call context:
913* interrupt
914----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +0530915static int p80211_rx_typedrop(struct wlandevice *wlandev, u16 fc)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700916{
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100917 u16 ftype;
918 u16 fstype;
919 int drop = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700920 /* Classify frame, increment counter */
921 ftype = WLAN_GET_FC_FTYPE(fc);
922 fstype = WLAN_GET_FC_FSTYPE(fc);
923#if 0
Denis Pithon79f9e632014-05-17 00:24:09 +0200924 netdev_dbg(wlandev->netdev, "rx_typedrop : ftype=%d fstype=%d.\n",
925 ftype, fstype);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700926#endif
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100927 switch (ftype) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700928 case WLAN_FTYPE_MGMT:
929 if ((wlandev->netdev->flags & IFF_PROMISC) ||
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100930 (wlandev->netdev->flags & IFF_ALLMULTI)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700931 drop = 1;
932 break;
933 }
Denis Pithon79f9e632014-05-17 00:24:09 +0200934 netdev_dbg(wlandev->netdev, "rx'd mgmt:\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700935 wlandev->rx.mgmt++;
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100936 switch (fstype) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700937 case WLAN_FSTYPE_ASSOCREQ:
938 /* printk("assocreq"); */
939 wlandev->rx.assocreq++;
940 break;
941 case WLAN_FSTYPE_ASSOCRESP:
942 /* printk("assocresp"); */
943 wlandev->rx.assocresp++;
944 break;
945 case WLAN_FSTYPE_REASSOCREQ:
946 /* printk("reassocreq"); */
947 wlandev->rx.reassocreq++;
948 break;
949 case WLAN_FSTYPE_REASSOCRESP:
950 /* printk("reassocresp"); */
951 wlandev->rx.reassocresp++;
952 break;
953 case WLAN_FSTYPE_PROBEREQ:
954 /* printk("probereq"); */
955 wlandev->rx.probereq++;
956 break;
957 case WLAN_FSTYPE_PROBERESP:
958 /* printk("proberesp"); */
959 wlandev->rx.proberesp++;
960 break;
961 case WLAN_FSTYPE_BEACON:
962 /* printk("beacon"); */
963 wlandev->rx.beacon++;
964 break;
965 case WLAN_FSTYPE_ATIM:
966 /* printk("atim"); */
967 wlandev->rx.atim++;
968 break;
969 case WLAN_FSTYPE_DISASSOC:
970 /* printk("disassoc"); */
971 wlandev->rx.disassoc++;
972 break;
973 case WLAN_FSTYPE_AUTHEN:
974 /* printk("authen"); */
975 wlandev->rx.authen++;
976 break;
977 case WLAN_FSTYPE_DEAUTHEN:
978 /* printk("deauthen"); */
979 wlandev->rx.deauthen++;
980 break;
981 default:
982 /* printk("unknown"); */
983 wlandev->rx.mgmt_unknown++;
984 break;
985 }
986 /* printk("\n"); */
987 drop = 2;
988 break;
989
990 case WLAN_FTYPE_CTL:
991 if ((wlandev->netdev->flags & IFF_PROMISC) ||
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100992 (wlandev->netdev->flags & IFF_ALLMULTI)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700993 drop = 1;
994 break;
995 }
Denis Pithon79f9e632014-05-17 00:24:09 +0200996 netdev_dbg(wlandev->netdev, "rx'd ctl:\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700997 wlandev->rx.ctl++;
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +0100998 switch (fstype) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700999 case WLAN_FSTYPE_PSPOLL:
1000 /* printk("pspoll"); */
1001 wlandev->rx.pspoll++;
1002 break;
1003 case WLAN_FSTYPE_RTS:
1004 /* printk("rts"); */
1005 wlandev->rx.rts++;
1006 break;
1007 case WLAN_FSTYPE_CTS:
1008 /* printk("cts"); */
1009 wlandev->rx.cts++;
1010 break;
1011 case WLAN_FSTYPE_ACK:
1012 /* printk("ack"); */
1013 wlandev->rx.ack++;
1014 break;
1015 case WLAN_FSTYPE_CFEND:
1016 /* printk("cfend"); */
1017 wlandev->rx.cfend++;
1018 break;
1019 case WLAN_FSTYPE_CFENDCFACK:
1020 /* printk("cfendcfack"); */
1021 wlandev->rx.cfendcfack++;
1022 break;
1023 default:
1024 /* printk("unknown"); */
1025 wlandev->rx.ctl_unknown++;
1026 break;
1027 }
1028 /* printk("\n"); */
1029 drop = 2;
1030 break;
1031
1032 case WLAN_FTYPE_DATA:
1033 wlandev->rx.data++;
Moritz Muehlenhoffb4b3f0d2009-02-08 02:21:01 +01001034 switch (fstype) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001035 case WLAN_FSTYPE_DATAONLY:
1036 wlandev->rx.dataonly++;
1037 break;
1038 case WLAN_FSTYPE_DATA_CFACK:
1039 wlandev->rx.data_cfack++;
1040 break;
1041 case WLAN_FSTYPE_DATA_CFPOLL:
1042 wlandev->rx.data_cfpoll++;
1043 break;
1044 case WLAN_FSTYPE_DATA_CFACK_CFPOLL:
1045 wlandev->rx.data__cfack_cfpoll++;
1046 break;
1047 case WLAN_FSTYPE_NULL:
Denis Pithon79f9e632014-05-17 00:24:09 +02001048 netdev_dbg(wlandev->netdev, "rx'd data:null\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001049 wlandev->rx.null++;
1050 break;
1051 case WLAN_FSTYPE_CFACK:
Denis Pithon79f9e632014-05-17 00:24:09 +02001052 netdev_dbg(wlandev->netdev, "rx'd data:cfack\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001053 wlandev->rx.cfack++;
1054 break;
1055 case WLAN_FSTYPE_CFPOLL:
Denis Pithon79f9e632014-05-17 00:24:09 +02001056 netdev_dbg(wlandev->netdev, "rx'd data:cfpoll\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001057 wlandev->rx.cfpoll++;
1058 break;
1059 case WLAN_FSTYPE_CFACK_CFPOLL:
Denis Pithon79f9e632014-05-17 00:24:09 +02001060 netdev_dbg(wlandev->netdev, "rx'd data:cfack_cfpoll\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001061 wlandev->rx.cfack_cfpoll++;
1062 break;
1063 default:
1064 /* printk("unknown"); */
1065 wlandev->rx.data_unknown++;
1066 break;
1067 }
1068
1069 break;
1070 }
1071 return drop;
1072}
1073
Sergio Paracuellos19066982016-09-27 19:33:51 +02001074static void p80211knetdev_tx_timeout(struct net_device *netdev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001075{
sayli karnikc9573a82016-09-18 15:11:14 +05301076 struct wlandevice *wlandev = netdev->ml_priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001077
1078 if (wlandev->tx_timeout) {
1079 wlandev->tx_timeout(wlandev);
1080 } else {
Denis Pithon79f9e632014-05-17 00:24:09 +02001081 netdev_warn(netdev, "Implement tx_timeout for %s\n",
1082 wlandev->nsdname);
Solomon Peachycbec30c2008-10-29 10:42:57 -04001083 netif_wake_queue(wlandev->netdev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001084 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001085}