^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for ZyDAS zd1201 based wireless USB devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2004, 2005 Jeroen Vreeken (pe1rxq@amsat.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Parts of this driver have been derived from a wlan-ng version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * modified by ZyDAS. They also made documentation available, thanks!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/wireless.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/cfg80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <net/iw_handler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "zd1201.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static const struct usb_device_id zd1201_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {USB_DEVICE(0x0586, 0x3400)}, /* Peabird Wireless USB Adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {USB_DEVICE(0x0ace, 0x1201)}, /* ZyDAS ZD1201 Wireless USB Adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {USB_DEVICE(0x050d, 0x6051)}, /* Belkin F5D6051 usb adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {USB_DEVICE(0x0db0, 0x6823)}, /* MSI UB11B usb adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {USB_DEVICE(0x1044, 0x8004)}, /* Gigabyte GN-WLBZ101 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {USB_DEVICE(0x1044, 0x8005)}, /* GIGABYTE GN-WLBZ201 usb adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int ap; /* Are we an AP or a normal station? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define ZD1201_VERSION "0.15"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) MODULE_AUTHOR("Jeroen Vreeken <pe1rxq@amsat.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) MODULE_DESCRIPTION("Driver for ZyDAS ZD1201 based USB Wireless adapters");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) MODULE_VERSION(ZD1201_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) module_param(ap, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) MODULE_PARM_DESC(ap, "If non-zero Access Point firmware will be loaded");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) MODULE_DEVICE_TABLE(usb, zd1201_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static int zd1201_fw_upload(struct usb_device *dev, int apfw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) const struct firmware *fw_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) const char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned long len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) unsigned char ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) char *fwfile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (apfw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) fwfile = "zd1201-ap.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) fwfile = "zd1201.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) err = request_firmware(&fw_entry, fwfile, &dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) dev_err(&dev->dev, "Failed to load %s firmware file!\n", fwfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) dev_err(&dev->dev, "Make sure the hotplug firmware loader is installed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) dev_err(&dev->dev, "Goto http://linux-lc100020.sourceforge.net for more info.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) data = fw_entry->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) len = fw_entry->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) buf = kmalloc(1024, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) while (len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int translen = (len > 1024) ? 1024 : len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) memcpy(buf, data, translen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) USB_DIR_OUT | 0x40, 0, 0, buf, translen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ZD1201_FW_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) len -= translen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) data += translen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 0x2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) USB_DIR_OUT | 0x40, 0, 0, NULL, 0, ZD1201_FW_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) err = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 0x4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) USB_DIR_IN | 0x40, 0, 0, buf, sizeof(ret), ZD1201_FW_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) memcpy(&ret, buf, sizeof(ret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (ret & 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) release_firmware(fw_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) MODULE_FIRMWARE("zd1201-ap.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) MODULE_FIRMWARE("zd1201.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static void zd1201_usbfree(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct zd1201 *zd = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) switch(urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) case -EILSEQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) case -ENODEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) case -ETIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) case -EPIPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) case -EOVERFLOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) dev_warn(&zd->usb->dev, "%s: urb failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) zd->dev->name, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) kfree(urb->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* cmdreq message:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) u32 type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u16 cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) u16 parm0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) u16 parm1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) u16 parm2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) u8 pad[4]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) total: 4 + 2 + 2 + 2 + 2 + 4 = 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int zd1201_docmd(struct zd1201 *zd, int cmd, int parm0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int parm1, int parm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) unsigned char *command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) command = kmalloc(16, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (!command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) *((__le32*)command) = cpu_to_le32(ZD1201_USB_CMDREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) *((__le16*)&command[4]) = cpu_to_le16(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) *((__le16*)&command[6]) = cpu_to_le16(parm0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) *((__le16*)&command[8]) = cpu_to_le16(parm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) *((__le16*)&command[10])= cpu_to_le16(parm2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) urb = usb_alloc_urb(0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (!urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) kfree(command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) usb_fill_bulk_urb(urb, zd->usb, usb_sndbulkpipe(zd->usb, zd->endp_out2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) command, 16, zd1201_usbfree, zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ret = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) kfree(command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* Callback after sending out a packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static void zd1201_usbtx(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct zd1201 *zd = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) netif_wake_queue(zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* Incoming data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static void zd1201_usbrx(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct zd1201 *zd = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int free = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) unsigned char *data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) unsigned char type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (!zd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) switch(urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) case -EILSEQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) case -ENODEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) case -ETIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) case -EPIPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) case -EOVERFLOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) dev_warn(&zd->usb->dev, "%s: rx urb failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) zd->dev->name, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) free = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (urb->status != 0 || urb->actual_length == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) type = data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (type == ZD1201_PACKET_EVENTSTAT || type == ZD1201_PACKET_RESOURCE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) memcpy(zd->rxdata, data, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) zd->rxlen = urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) zd->rxdatas = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) wake_up(&zd->rxdataq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* Info frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (type == ZD1201_PACKET_INQUIRE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) unsigned short infotype, copylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) infotype = le16_to_cpu(*(__le16*)&data[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (infotype == ZD1201_INF_LINKSTATUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) short linkstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) linkstatus = le16_to_cpu(*(__le16*)&data[8]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) switch(linkstatus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) netif_carrier_on(zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) netif_carrier_off(zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) netif_carrier_off(zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) netif_carrier_on(zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) netif_carrier_off(zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (infotype == ZD1201_INF_ASSOCSTATUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) short status = le16_to_cpu(*(__le16*)(data+8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) union iwreq_data wrqu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) case ZD1201_ASSOCSTATUS_STAASSOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) case ZD1201_ASSOCSTATUS_REASSOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) event = IWEVREGISTERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) case ZD1201_ASSOCSTATUS_DISASSOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) case ZD1201_ASSOCSTATUS_ASSOCFAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) case ZD1201_ASSOCSTATUS_AUTHFAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) event = IWEVEXPIRED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) memcpy(wrqu.addr.sa_data, data+10, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) wrqu.addr.sa_family = ARPHRD_ETHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /* Send event to user space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) wireless_send_event(zd->dev, event, &wrqu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (infotype == ZD1201_INF_AUTHREQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) union iwreq_data wrqu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) memcpy(wrqu.addr.sa_data, data+8, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) wrqu.addr.sa_family = ARPHRD_ETHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* There isn't a event that trully fits this request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) We assume that userspace will be smart enough to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) see a new station being expired and sends back a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) authstation ioctl to authorize it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) wireless_send_event(zd->dev, IWEVEXPIRED, &wrqu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* Other infotypes are handled outside this handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) zd->rxlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) while (i < urb->actual_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) copylen = le16_to_cpu(*(__le16*)&data[i+2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* Sanity check, sometimes we get junk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (copylen+zd->rxlen > sizeof(zd->rxdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) memcpy(zd->rxdata+zd->rxlen, data+i+4, copylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) zd->rxlen += copylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) i += 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (i >= urb->actual_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) zd->rxdatas = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) wake_up(&zd->rxdataq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /* Actual data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (data[urb->actual_length-1] == ZD1201_PACKET_RXDATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int datalen = urb->actual_length-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) unsigned short len, fc, seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) len = ntohs(*(__be16 *)&data[datalen-2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (len>datalen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) len=datalen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) fc = le16_to_cpu(*(__le16 *)&data[datalen-16]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) seq = le16_to_cpu(*(__le16 *)&data[datalen-24]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (zd->monitor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (datalen < 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (!(skb = dev_alloc_skb(datalen+24)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) skb_put_data(skb, &data[datalen - 16], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) skb_put_data(skb, &data[datalen - 2], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) skb_put_data(skb, &data[datalen - 14], 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) skb_put_data(skb, &data[datalen - 22], 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) skb_put_data(skb, &data[datalen - 8], 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) skb_put_data(skb, &data[datalen - 24], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) skb_put_data(skb, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) skb->protocol = eth_type_trans(skb, zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) zd->dev->stats.rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) zd->dev->stats.rx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) netif_rx(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if ((seq & IEEE80211_SCTL_FRAG) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) (fc & IEEE80211_FCTL_MOREFRAGS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct zd1201_frag *frag = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (datalen<14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if ((seq & IEEE80211_SCTL_FRAG) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) frag = kmalloc(sizeof(*frag), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (!frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) skb = dev_alloc_skb(IEEE80211_MAX_DATA_LEN +14+2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) kfree(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) frag->skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) frag->seq = seq & IEEE80211_SCTL_SEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) skb_reserve(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) skb_put_data(skb, &data[datalen - 14], 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) skb_put_data(skb, &data[6], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) skb_put_data(skb, data + 8, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) hlist_add_head(&frag->fnode, &zd->fraglist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) hlist_for_each_entry(frag, &zd->fraglist, fnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) if (frag->seq == (seq&IEEE80211_SCTL_SEQ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (!frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) skb = frag->skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ptr = skb_put(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) memcpy(ptr, data+8, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (fc & IEEE80211_FCTL_MOREFRAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) hlist_del_init(&frag->fnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) kfree(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (datalen<14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) skb = dev_alloc_skb(len + 14 + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) skb_reserve(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) skb_put_data(skb, &data[datalen - 14], 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) skb_put_data(skb, &data[6], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) skb_put_data(skb, data + 8, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) skb->protocol = eth_type_trans(skb, zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) zd->dev->stats.rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) zd->dev->stats.rx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) netif_rx(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) resubmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) memset(data, 0, ZD1201_RXSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) urb->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) urb->dev = zd->usb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if(usb_submit_urb(urb, GFP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) free = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (free) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) zd->rxlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) zd->rxdatas = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) wake_up(&zd->rxdataq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) kfree(urb->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static int zd1201_getconfig(struct zd1201 *zd, int rid, void *riddata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) unsigned int riddatalen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) int code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int rid_fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) unsigned char *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) zd->rxdatas = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) err = zd1201_docmd(zd, ZD1201_CMDCODE_ACCESS, rid, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) wait_event_interruptible(zd->rxdataq, zd->rxdatas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (!zd->rxlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) code = le16_to_cpu(*(__le16*)(&zd->rxdata[4]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) rid_fid = le16_to_cpu(*(__le16*)(&zd->rxdata[6]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) length = le16_to_cpu(*(__le16*)(&zd->rxdata[8]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (length > zd->rxlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) length = zd->rxlen-6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /* If access bit is not on, then error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if ((code & ZD1201_ACCESSBIT) != ZD1201_ACCESSBIT || rid_fid != rid )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) /* Not enough buffer for allocating data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (riddatalen != (length - 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) dev_dbg(&zd->usb->dev, "riddatalen mismatches, expected=%u, (packet=%u) length=%u, rid=0x%04X, rid_fid=0x%04X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) riddatalen, zd->rxlen, length, rid, rid_fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) zd->rxdatas = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) /* Issue SetRxRid commnd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) err = zd1201_docmd(zd, ZD1201_CMDCODE_SETRXRID, rid, 0, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* Receive RID record from resource packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) wait_event_interruptible(zd->rxdataq, zd->rxdatas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (!zd->rxlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (zd->rxdata[zd->rxlen - 1] != ZD1201_PACKET_RESOURCE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) dev_dbg(&zd->usb->dev, "Packet type mismatch: 0x%x not 0x3\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) zd->rxdata[zd->rxlen-1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /* Set the data pointer and received data length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) pdata = zd->rxdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) length = zd->rxlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) int actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) actual_length = (length > 64) ? 64 : length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (pdata[0] != 0x3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) dev_dbg(&zd->usb->dev, "Rx Resource packet type error: %02X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) pdata[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (actual_length != 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /* Trim the last packet type byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) actual_length--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /* Skip the 4 bytes header (RID length and RID) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (i == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) pdata += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) actual_length -= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) pdata += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) actual_length -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) memcpy(riddata, pdata, actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) riddata += actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) pdata += actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) length -= 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) } while (length > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * resreq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * byte type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * byte sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * u16 reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * byte data[12]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * total: 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static int zd1201_setconfig(struct zd1201 *zd, int rid, void *buf, int len, int wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) unsigned char *request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) int reqlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) char seq=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) gfp_t gfp_mask = wait ? GFP_NOIO : GFP_ATOMIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) len += 4; /* first 4 are for header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) zd->rxdatas = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) zd->rxlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) for (seq=0; len > 0; seq++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) request = kmalloc(16, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (!request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) urb = usb_alloc_urb(0, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (!urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) kfree(request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) memset(request, 0, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) reqlen = len>12 ? 12 : len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) request[0] = ZD1201_USB_RESREQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) request[1] = seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) request[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) request[3] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (request[1] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /* add header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) *(__le16*)&request[4] = cpu_to_le16((len-2+1)/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) *(__le16*)&request[6] = cpu_to_le16(rid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) memcpy(request+8, buf, reqlen-4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) buf += reqlen-4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) memcpy(request+4, buf, reqlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) buf += reqlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) len -= reqlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) usb_fill_bulk_urb(urb, zd->usb, usb_sndbulkpipe(zd->usb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) zd->endp_out2), request, 16, zd1201_usbfree, zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) err = usb_submit_urb(urb, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) request = kmalloc(16, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (!request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) urb = usb_alloc_urb(0, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (!urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) kfree(request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) *((__le32*)request) = cpu_to_le32(ZD1201_USB_CMDREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) *((__le16*)&request[4]) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) cpu_to_le16(ZD1201_CMDCODE_ACCESS|ZD1201_ACCESSBIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) *((__le16*)&request[6]) = cpu_to_le16(rid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) *((__le16*)&request[8]) = cpu_to_le16(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) *((__le16*)&request[10]) = cpu_to_le16(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) usb_fill_bulk_urb(urb, zd->usb, usb_sndbulkpipe(zd->usb, zd->endp_out2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) request, 16, zd1201_usbfree, zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) err = usb_submit_urb(urb, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (wait) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) wait_event_interruptible(zd->rxdataq, zd->rxdatas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (!zd->rxlen || le16_to_cpu(*(__le16*)&zd->rxdata[6]) != rid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) dev_dbg(&zd->usb->dev, "wrong or no RID received\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) kfree(request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) static inline int zd1201_getconfig16(struct zd1201 *zd, int rid, short *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) __le16 zdval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) err = zd1201_getconfig(zd, rid, &zdval, sizeof(__le16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) *val = le16_to_cpu(zdval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) static inline int zd1201_setconfig16(struct zd1201 *zd, int rid, short val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) __le16 zdval = cpu_to_le16(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) return (zd1201_setconfig(zd, rid, &zdval, sizeof(__le16), 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) static int zd1201_drvr_start(struct zd1201 *zd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) short max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) __le16 zdmax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) unsigned char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) buffer = kzalloc(ZD1201_RXSIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) usb_fill_bulk_urb(zd->rx_urb, zd->usb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) usb_rcvbulkpipe(zd->usb, zd->endp_in), buffer, ZD1201_RXSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) zd1201_usbrx, zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) err = usb_submit_urb(zd->rx_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) goto err_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) err = zd1201_docmd(zd, ZD1201_CMDCODE_INIT, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) goto err_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) err = zd1201_getconfig(zd, ZD1201_RID_CNFMAXTXBUFFERNUMBER, &zdmax,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) sizeof(__le16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) goto err_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) max = le16_to_cpu(zdmax);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) for (i=0; i<max; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) err = zd1201_docmd(zd, ZD1201_CMDCODE_ALLOC, 1514, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) goto err_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) err_urb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) usb_kill_urb(zd->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) err_buffer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) /* Magic alert: The firmware doesn't seem to like the MAC state being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) * toggled in promisc (aka monitor) mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * (It works a number of times, but will halt eventually)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) * So we turn it of before disabling and on after enabling if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) static int zd1201_enable(struct zd1201 *zd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (zd->mac_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) err = zd1201_docmd(zd, ZD1201_CMDCODE_ENABLE, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) zd->mac_enabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (zd->monitor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) err = zd1201_setconfig16(zd, ZD1201_RID_PROMISCUOUSMODE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) static int zd1201_disable(struct zd1201 *zd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) if (!zd->mac_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (zd->monitor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) err = zd1201_setconfig16(zd, ZD1201_RID_PROMISCUOUSMODE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) err = zd1201_docmd(zd, ZD1201_CMDCODE_DISABLE, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) zd->mac_enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) static int zd1201_mac_reset(struct zd1201 *zd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) if (!zd->mac_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) zd1201_disable(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) return zd1201_enable(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) static int zd1201_join(struct zd1201 *zd, char *essid, int essidlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) int err, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) char buf[IW_ESSID_MAX_SIZE+2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) err = zd1201_disable(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) val = ZD1201_CNFAUTHENTICATION_OPENSYSTEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) val |= ZD1201_CNFAUTHENTICATION_SHAREDKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) err = zd1201_setconfig16(zd, ZD1201_RID_CNFAUTHENTICATION, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) *(__le16 *)buf = cpu_to_le16(essidlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) memcpy(buf+2, essid, essidlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (!zd->ap) { /* Normal station */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) err = zd1201_setconfig(zd, ZD1201_RID_CNFDESIREDSSID, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) IW_ESSID_MAX_SIZE+2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) } else { /* AP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) err = zd1201_setconfig(zd, ZD1201_RID_CNFOWNSSID, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) IW_ESSID_MAX_SIZE+2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) err = zd1201_setconfig(zd, ZD1201_RID_CNFOWNMACADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) zd->dev->dev_addr, zd->dev->addr_len, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) err = zd1201_enable(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) static int zd1201_net_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) /* Start MAC with wildcard if no essid set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) if (!zd->mac_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) zd1201_join(zd, zd->essid, zd->essidlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) netif_start_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) static int zd1201_net_stop(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) RFC 1042 encapsulates Ethernet frames in 802.11 frames
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) by prefixing them with 0xaa, 0xaa, 0x03) followed by a SNAP OID of 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) (0x00, 0x00, 0x00). Zd requires an additional padding, copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) of ethernet addresses, length of the standard RFC 1042 packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) and a command byte (which is nul for tx).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) tx frame (from Wlan NG):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) RFC 1042:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) llc 0xAA 0xAA 0x03 (802.2 LLC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) snap 0x00 0x00 0x00 (Ethernet encapsulated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) type 2 bytes, Ethernet type field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) payload (minus eth header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) Zydas specific:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) padding 1B if (skb->len+8+1)%64==0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) Eth MAC addr 12 bytes, Ethernet MAC addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) length 2 bytes, RFC 1042 packet length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) (llc+snap+type+payload)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) zd 1 null byte, zd1201 packet type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) static netdev_tx_t zd1201_hard_start_xmit(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) unsigned char *txbuf = zd->txdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) int txbuflen, pad = 0, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) struct urb *urb = zd->tx_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (!zd->mac_enabled || zd->monitor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) dev->stats.tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) txbuflen = skb->len + 8 + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) if (txbuflen%64 == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) pad = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) txbuflen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) txbuf[0] = 0xAA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) txbuf[1] = 0xAA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) txbuf[2] = 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) txbuf[3] = 0x00; /* rfc1042 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) txbuf[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) txbuf[5] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) skb_copy_from_linear_data_offset(skb, 12, txbuf + 6, skb->len - 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) if (pad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) txbuf[skb->len-12+6]=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) skb_copy_from_linear_data(skb, txbuf + skb->len - 12 + 6 + pad, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) *(__be16*)&txbuf[skb->len+6+pad] = htons(skb->len-12+6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) txbuf[txbuflen-1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) usb_fill_bulk_urb(urb, zd->usb, usb_sndbulkpipe(zd->usb, zd->endp_out),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) txbuf, txbuflen, zd1201_usbtx, zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) err = usb_submit_urb(zd->tx_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) dev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) netif_start_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) dev->stats.tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) dev->stats.tx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) static void zd1201_tx_timeout(struct net_device *dev, unsigned int txqueue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (!zd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) dev_warn(&zd->usb->dev, "%s: TX timeout, shooting down urb\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) usb_unlink_urb(zd->tx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) dev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) /* Restart the timeout to quiet the watchdog: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) netif_trans_update(dev); /* prevent tx timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) static int zd1201_set_mac_address(struct net_device *dev, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) struct sockaddr *addr = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) if (!zd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) err = zd1201_setconfig(zd, ZD1201_RID_CNFOWNMACADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) addr->sa_data, dev->addr_len, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) return zd1201_mac_reset(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) static struct iw_statistics *zd1201_get_wireless_stats(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) return &zd->iwstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) static void zd1201_set_multicast(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) struct netdev_hw_addr *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) unsigned char reqbuf[ETH_ALEN*ZD1201_MAXMULTI];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if (netdev_mc_count(dev) > ZD1201_MAXMULTI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) netdev_for_each_mc_addr(ha, dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) memcpy(reqbuf + i++ * ETH_ALEN, ha->addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) zd1201_setconfig(zd, ZD1201_RID_CNFGROUPADDRESS, reqbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) netdev_mc_count(dev) * ETH_ALEN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) static int zd1201_config_commit(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) struct iw_request_info *info, struct iw_point *data, char *essid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) return zd1201_mac_reset(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) static int zd1201_get_name(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) struct iw_request_info *info, char *name, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) strcpy(name, "IEEE 802.11b");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) static int zd1201_set_freq(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) struct iw_request_info *info, struct iw_freq *freq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) short channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) if (freq->e == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) channel = freq->m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) channel = ieee80211_frequency_to_channel(freq->m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) err = zd1201_setconfig16(zd, ZD1201_RID_CNFOWNCHANNEL, channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) zd1201_mac_reset(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) static int zd1201_get_freq(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) struct iw_request_info *info, struct iw_freq *freq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) short channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) err = zd1201_getconfig16(zd, ZD1201_RID_CNFOWNCHANNEL, &channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) freq->e = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) freq->m = channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) static int zd1201_set_mode(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) struct iw_request_info *info, __u32 *mode, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) short porttype, monitor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) unsigned char buffer[IW_ESSID_MAX_SIZE+2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) if (zd->ap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) if (*mode != IW_MODE_MASTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) err = zd1201_setconfig16(zd, ZD1201_RID_PROMISCUOUSMODE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) zd->dev->type = ARPHRD_ETHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) switch(*mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) case IW_MODE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) monitor = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) zd->dev->type = ARPHRD_IEEE80211;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) /* Make sure we are no longer associated with by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) setting an 'impossible' essid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) (otherwise we mess up firmware)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) zd1201_join(zd, "\0-*#\0", 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) /* Put port in pIBSS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) /* Fall through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) case 8: /* No pseudo-IBSS in wireless extensions (yet) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) porttype = ZD1201_PORTTYPE_PSEUDOIBSS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) case IW_MODE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) porttype = ZD1201_PORTTYPE_IBSS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) case IW_MODE_INFRA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) porttype = ZD1201_PORTTYPE_BSS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) err = zd1201_setconfig16(zd, ZD1201_RID_CNFPORTTYPE, porttype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) if (zd->monitor && !monitor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) zd1201_disable(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) *(__le16 *)buffer = cpu_to_le16(zd->essidlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) memcpy(buffer+2, zd->essid, zd->essidlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) err = zd1201_setconfig(zd, ZD1201_RID_CNFDESIREDSSID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) buffer, IW_ESSID_MAX_SIZE+2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) zd->monitor = monitor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) /* If monitor mode is set we don't actually turn it on here since it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) * is done during mac reset anyway (see zd1201_mac_enable).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) zd1201_mac_reset(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) static int zd1201_get_mode(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) struct iw_request_info *info, __u32 *mode, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) short porttype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) err = zd1201_getconfig16(zd, ZD1201_RID_CNFPORTTYPE, &porttype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) switch(porttype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) case ZD1201_PORTTYPE_IBSS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) *mode = IW_MODE_ADHOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) case ZD1201_PORTTYPE_BSS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) *mode = IW_MODE_INFRA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) case ZD1201_PORTTYPE_WDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) *mode = IW_MODE_REPEAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) case ZD1201_PORTTYPE_PSEUDOIBSS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) *mode = 8;/* No Pseudo-IBSS... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) case ZD1201_PORTTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) *mode = IW_MODE_MASTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) dev_dbg(&zd->usb->dev, "Unknown porttype: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) porttype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) *mode = IW_MODE_AUTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) if (zd->monitor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) *mode = IW_MODE_MONITOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) static int zd1201_get_range(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) struct iw_request_info *info, struct iw_point *wrq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) struct iw_range *range = (struct iw_range *)extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) wrq->length = sizeof(struct iw_range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) memset(range, 0, sizeof(struct iw_range));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) range->we_version_compiled = WIRELESS_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) range->we_version_source = WIRELESS_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) range->max_qual.qual = 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) range->max_qual.level = 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) range->max_qual.noise = 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) range->max_qual.updated = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) range->encoding_size[0] = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) range->encoding_size[1] = 13;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) range->num_encoding_sizes = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) range->max_encoding_tokens = ZD1201_NUMKEYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) range->num_bitrates = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) range->bitrate[0] = 1000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) range->bitrate[1] = 2000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) range->bitrate[2] = 5500000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) range->bitrate[3] = 11000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) range->min_rts = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) range->min_frag = ZD1201_FRAGMIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) range->max_rts = ZD1201_RTSMAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) range->min_frag = ZD1201_FRAGMAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) /* Little bit of magic here: we only get the quality if we poll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) * for it, and we never get an actual request to trigger such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) * a poll. Therefore we 'assume' that the user will soon ask for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) * the stats after asking the bssid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) static int zd1201_get_wap(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) struct iw_request_info *info, struct sockaddr *ap_addr, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) unsigned char buffer[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) if (!zd1201_getconfig(zd, ZD1201_RID_COMMSQUALITY, buffer, 6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) /* Unfortunately the quality and noise reported is useless.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) they seem to be accumulators that increase until you
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) read them, unless we poll on a fixed interval we can't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) use them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) /*zd->iwstats.qual.qual = le16_to_cpu(((__le16 *)buffer)[0]);*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) zd->iwstats.qual.level = le16_to_cpu(((__le16 *)buffer)[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) /*zd->iwstats.qual.noise = le16_to_cpu(((__le16 *)buffer)[2]);*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) zd->iwstats.qual.updated = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) return zd1201_getconfig(zd, ZD1201_RID_CURRENTBSSID, ap_addr->sa_data, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) static int zd1201_set_scan(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) struct iw_request_info *info, struct iw_point *srq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) /* We do everything in get_scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) static int zd1201_get_scan(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) struct iw_request_info *info, struct iw_point *srq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) int err, i, j, enabled_save;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) struct iw_event iwe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) char *cev = extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) char *end_buf = extra + IW_SCAN_MAX_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) /* No scanning in AP mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) if (zd->ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) /* Scan doesn't seem to work if disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) enabled_save = zd->mac_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) zd1201_enable(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) zd->rxdatas = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) err = zd1201_docmd(zd, ZD1201_CMDCODE_INQUIRE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) ZD1201_INQ_SCANRESULTS, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) wait_event_interruptible(zd->rxdataq, zd->rxdatas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (!zd->rxlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) if (le16_to_cpu(*(__le16*)&zd->rxdata[2]) != ZD1201_INQ_SCANRESULTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) for(i=8; i<zd->rxlen; i+=62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) iwe.cmd = SIOCGIWAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) memcpy(iwe.u.ap_addr.sa_data, zd->rxdata+i+6, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) cev = iwe_stream_add_event(info, cev, end_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) &iwe, IW_EV_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) iwe.cmd = SIOCGIWESSID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) iwe.u.data.length = zd->rxdata[i+16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) iwe.u.data.flags = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) cev = iwe_stream_add_point(info, cev, end_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) &iwe, zd->rxdata+i+18);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) iwe.cmd = SIOCGIWMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) if (zd->rxdata[i+14]&0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) iwe.u.mode = IW_MODE_MASTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) iwe.u.mode = IW_MODE_ADHOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) cev = iwe_stream_add_event(info, cev, end_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) &iwe, IW_EV_UINT_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) iwe.cmd = SIOCGIWFREQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) iwe.u.freq.m = zd->rxdata[i+0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) iwe.u.freq.e = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) cev = iwe_stream_add_event(info, cev, end_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) &iwe, IW_EV_FREQ_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) iwe.cmd = SIOCGIWRATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) iwe.u.bitrate.fixed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) iwe.u.bitrate.disabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) for (j=0; j<10; j++) if (zd->rxdata[i+50+j]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) iwe.u.bitrate.value = (zd->rxdata[i+50+j]&0x7f)*500000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) cev = iwe_stream_add_event(info, cev, end_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) &iwe, IW_EV_PARAM_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) iwe.cmd = SIOCGIWENCODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) iwe.u.data.length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) if (zd->rxdata[i+14]&0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) iwe.u.data.flags = IW_ENCODE_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) iwe.u.data.flags = IW_ENCODE_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) cev = iwe_stream_add_point(info, cev, end_buf, &iwe, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) iwe.cmd = IWEVQUAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) iwe.u.qual.qual = zd->rxdata[i+4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) iwe.u.qual.noise= zd->rxdata[i+2]/10-100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) iwe.u.qual.level = (256+zd->rxdata[i+4]*100)/255-100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) iwe.u.qual.updated = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) cev = iwe_stream_add_event(info, cev, end_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) &iwe, IW_EV_QUAL_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) if (!enabled_save)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) zd1201_disable(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) srq->length = cev - extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) srq->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) static int zd1201_set_essid(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) struct iw_request_info *info, struct iw_point *data, char *essid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) if (data->length > IW_ESSID_MAX_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) if (data->length < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) data->length = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) zd->essidlen = data->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) memset(zd->essid, 0, IW_ESSID_MAX_SIZE+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) memcpy(zd->essid, essid, data->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) return zd1201_join(zd, zd->essid, zd->essidlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) static int zd1201_get_essid(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) struct iw_request_info *info, struct iw_point *data, char *essid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) memcpy(essid, zd->essid, zd->essidlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) data->flags = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) data->length = zd->essidlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) static int zd1201_get_nick(struct net_device *dev, struct iw_request_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) struct iw_point *data, char *nick)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) strcpy(nick, "zd1201");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) data->flags = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) data->length = strlen(nick);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) static int zd1201_set_rate(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) struct iw_request_info *info, struct iw_param *rrq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) short rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) switch (rrq->value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) case 1000000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) rate = ZD1201_RATEB1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) case 2000000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) rate = ZD1201_RATEB2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) case 5500000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) rate = ZD1201_RATEB5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) case 11000000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) rate = ZD1201_RATEB11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) if (!rrq->fixed) { /* Also enable all lower bitrates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) rate |= rate-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) err = zd1201_setconfig16(zd, ZD1201_RID_TXRATECNTL, rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) return zd1201_mac_reset(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) static int zd1201_get_rate(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) struct iw_request_info *info, struct iw_param *rrq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) short rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) err = zd1201_getconfig16(zd, ZD1201_RID_CURRENTTXRATE, &rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) switch(rate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) rrq->value = 1000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) rrq->value = 2000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) rrq->value = 5500000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) case 11:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) rrq->value = 11000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) rrq->value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) rrq->fixed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) rrq->disabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) static int zd1201_set_rts(struct net_device *dev, struct iw_request_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) struct iw_param *rts, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) short val = rts->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) if (rts->disabled || !rts->fixed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) val = ZD1201_RTSMAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) if (val > ZD1201_RTSMAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) if (val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) err = zd1201_setconfig16(zd, ZD1201_RID_CNFRTSTHRESHOLD, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) return zd1201_mac_reset(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) static int zd1201_get_rts(struct net_device *dev, struct iw_request_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) struct iw_param *rts, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) short rtst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) err = zd1201_getconfig16(zd, ZD1201_RID_CNFRTSTHRESHOLD, &rtst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) rts->value = rtst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) rts->disabled = (rts->value == ZD1201_RTSMAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) rts->fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) static int zd1201_set_frag(struct net_device *dev, struct iw_request_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) struct iw_param *frag, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) short val = frag->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) if (frag->disabled || !frag->fixed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) val = ZD1201_FRAGMAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) if (val > ZD1201_FRAGMAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) if (val < ZD1201_FRAGMIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) if (val & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) err = zd1201_setconfig16(zd, ZD1201_RID_CNFFRAGTHRESHOLD, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) return zd1201_mac_reset(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) static int zd1201_get_frag(struct net_device *dev, struct iw_request_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) struct iw_param *frag, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) short fragt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) err = zd1201_getconfig16(zd, ZD1201_RID_CNFFRAGTHRESHOLD, &fragt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) frag->value = fragt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) frag->disabled = (frag->value == ZD1201_FRAGMAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) frag->fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) static int zd1201_set_retry(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) struct iw_request_info *info, struct iw_param *rrq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) static int zd1201_get_retry(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) struct iw_request_info *info, struct iw_param *rrq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) static int zd1201_set_encode(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) struct iw_request_info *info, struct iw_point *erq, char *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) short i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) int err, rid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) if (erq->length > ZD1201_MAXKEYLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) i = (erq->flags & IW_ENCODE_INDEX)-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) if (i == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) err = zd1201_getconfig16(zd,ZD1201_RID_CNFDEFAULTKEYID,&i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) err = zd1201_setconfig16(zd, ZD1201_RID_CNFDEFAULTKEYID, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) if (i < 0 || i >= ZD1201_NUMKEYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) rid = ZD1201_RID_CNFDEFAULTKEY0 + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) err = zd1201_setconfig(zd, rid, key, erq->length, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) zd->encode_keylen[i] = erq->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) memcpy(zd->encode_keys[i], key, erq->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) i=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) if (!(erq->flags & IW_ENCODE_DISABLED & IW_ENCODE_MODE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) i |= 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) zd->encode_enabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) zd->encode_enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) if (erq->flags & IW_ENCODE_RESTRICTED & IW_ENCODE_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) i |= 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) zd->encode_restricted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) zd->encode_restricted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) err = zd1201_setconfig16(zd, ZD1201_RID_CNFWEBFLAGS, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) if (zd->encode_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) i = ZD1201_CNFAUTHENTICATION_SHAREDKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) i = ZD1201_CNFAUTHENTICATION_OPENSYSTEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) err = zd1201_setconfig16(zd, ZD1201_RID_CNFAUTHENTICATION, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) return zd1201_mac_reset(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) static int zd1201_get_encode(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) struct iw_request_info *info, struct iw_point *erq, char *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) short i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) if (zd->encode_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) erq->flags = IW_ENCODE_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) erq->flags = IW_ENCODE_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) if (zd->encode_restricted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) erq->flags |= IW_ENCODE_RESTRICTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) erq->flags |= IW_ENCODE_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) i = (erq->flags & IW_ENCODE_INDEX) -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) if (i == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) err = zd1201_getconfig16(zd, ZD1201_RID_CNFDEFAULTKEYID, &i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) if (i<0 || i>= ZD1201_NUMKEYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) erq->flags |= i+1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) erq->length = zd->encode_keylen[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) memcpy(key, zd->encode_keys[i], erq->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) static int zd1201_set_power(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) struct iw_request_info *info, struct iw_param *vwrq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) short enabled, duration, level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) enabled = vwrq->disabled ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) if (enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) if (vwrq->flags & IW_POWER_PERIOD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) duration = vwrq->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) err = zd1201_setconfig16(zd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) ZD1201_RID_CNFMAXSLEEPDURATION, duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) if (vwrq->flags & IW_POWER_TIMEOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) err = zd1201_getconfig16(zd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) ZD1201_RID_CNFMAXSLEEPDURATION, &duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) level = vwrq->value * 4 / duration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) if (level > 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) level = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) if (level < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) level = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) err = zd1201_setconfig16(zd, ZD1201_RID_CNFPMEPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) return zd1201_setconfig16(zd, ZD1201_RID_CNFPMENABLED, enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) static int zd1201_get_power(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) struct iw_request_info *info, struct iw_param *vwrq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) short enabled, level, duration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) err = zd1201_getconfig16(zd, ZD1201_RID_CNFPMENABLED, &enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) err = zd1201_getconfig16(zd, ZD1201_RID_CNFPMEPS, &level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) err = zd1201_getconfig16(zd, ZD1201_RID_CNFMAXSLEEPDURATION, &duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) vwrq->disabled = enabled ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) if (vwrq->flags & IW_POWER_TYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) if (vwrq->flags & IW_POWER_PERIOD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) vwrq->value = duration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) vwrq->flags = IW_POWER_PERIOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) vwrq->value = duration * level / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) vwrq->flags = IW_POWER_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) if (vwrq->flags & IW_POWER_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) if (enabled && level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) vwrq->flags = IW_POWER_UNICAST_R;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) vwrq->flags = IW_POWER_ALL_R;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) static const iw_handler zd1201_iw_handler[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) (iw_handler) zd1201_config_commit, /* SIOCSIWCOMMIT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) (iw_handler) zd1201_get_name, /* SIOCGIWNAME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) (iw_handler) NULL, /* SIOCSIWNWID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) (iw_handler) NULL, /* SIOCGIWNWID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) (iw_handler) zd1201_set_freq, /* SIOCSIWFREQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) (iw_handler) zd1201_get_freq, /* SIOCGIWFREQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) (iw_handler) zd1201_set_mode, /* SIOCSIWMODE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) (iw_handler) zd1201_get_mode, /* SIOCGIWMODE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) (iw_handler) NULL, /* SIOCSIWSENS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) (iw_handler) NULL, /* SIOCGIWSENS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) (iw_handler) NULL, /* SIOCSIWRANGE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) (iw_handler) zd1201_get_range, /* SIOCGIWRANGE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) (iw_handler) NULL, /* SIOCSIWPRIV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) (iw_handler) NULL, /* SIOCGIWPRIV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) (iw_handler) NULL, /* SIOCSIWSTATS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) (iw_handler) NULL, /* SIOCGIWSTATS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) (iw_handler) NULL, /* SIOCSIWSPY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) (iw_handler) NULL, /* SIOCGIWSPY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) (iw_handler) NULL, /* -- hole -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) (iw_handler) NULL, /* -- hole -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) (iw_handler) NULL/*zd1201_set_wap*/, /* SIOCSIWAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) (iw_handler) zd1201_get_wap, /* SIOCGIWAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) (iw_handler) NULL, /* -- hole -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) (iw_handler) NULL, /* SIOCGIWAPLIST */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) (iw_handler) zd1201_set_scan, /* SIOCSIWSCAN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) (iw_handler) zd1201_get_scan, /* SIOCGIWSCAN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) (iw_handler) zd1201_set_essid, /* SIOCSIWESSID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) (iw_handler) zd1201_get_essid, /* SIOCGIWESSID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) (iw_handler) NULL, /* SIOCSIWNICKN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) (iw_handler) zd1201_get_nick, /* SIOCGIWNICKN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) (iw_handler) NULL, /* -- hole -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) (iw_handler) NULL, /* -- hole -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) (iw_handler) zd1201_set_rate, /* SIOCSIWRATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) (iw_handler) zd1201_get_rate, /* SIOCGIWRATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) (iw_handler) zd1201_set_rts, /* SIOCSIWRTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) (iw_handler) zd1201_get_rts, /* SIOCGIWRTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) (iw_handler) zd1201_set_frag, /* SIOCSIWFRAG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) (iw_handler) zd1201_get_frag, /* SIOCGIWFRAG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) (iw_handler) NULL, /* SIOCSIWTXPOW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) (iw_handler) NULL, /* SIOCGIWTXPOW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) (iw_handler) zd1201_set_retry, /* SIOCSIWRETRY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) (iw_handler) zd1201_get_retry, /* SIOCGIWRETRY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) (iw_handler) zd1201_set_encode, /* SIOCSIWENCODE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) (iw_handler) zd1201_get_encode, /* SIOCGIWENCODE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) (iw_handler) zd1201_set_power, /* SIOCSIWPOWER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) (iw_handler) zd1201_get_power, /* SIOCGIWPOWER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) static int zd1201_set_hostauth(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) struct iw_request_info *info, struct iw_param *rrq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) if (!zd->ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) return zd1201_setconfig16(zd, ZD1201_RID_CNFHOSTAUTH, rrq->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) static int zd1201_get_hostauth(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) struct iw_request_info *info, struct iw_param *rrq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) short hostauth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) if (!zd->ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) err = zd1201_getconfig16(zd, ZD1201_RID_CNFHOSTAUTH, &hostauth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) rrq->value = hostauth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) rrq->fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) static int zd1201_auth_sta(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) struct iw_request_info *info, struct sockaddr *sta, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) unsigned char buffer[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) if (!zd->ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) memcpy(buffer, sta->sa_data, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) *(short*)(buffer+6) = 0; /* 0==success, 1==failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) *(short*)(buffer+8) = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) return zd1201_setconfig(zd, ZD1201_RID_AUTHENTICATESTA, buffer, 10, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) static int zd1201_set_maxassoc(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) struct iw_request_info *info, struct iw_param *rrq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) if (!zd->ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) return zd1201_setconfig16(zd, ZD1201_RID_CNFMAXASSOCSTATIONS, rrq->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) static int zd1201_get_maxassoc(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) struct iw_request_info *info, struct iw_param *rrq, char *extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) struct zd1201 *zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) short maxassoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) if (!zd->ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) err = zd1201_getconfig16(zd, ZD1201_RID_CNFMAXASSOCSTATIONS, &maxassoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) rrq->value = maxassoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) rrq->fixed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) static const iw_handler zd1201_private_handler[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) (iw_handler) zd1201_set_hostauth, /* ZD1201SIWHOSTAUTH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) (iw_handler) zd1201_get_hostauth, /* ZD1201GIWHOSTAUTH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) (iw_handler) zd1201_auth_sta, /* ZD1201SIWAUTHSTA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) (iw_handler) NULL, /* nothing to get */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) (iw_handler) zd1201_set_maxassoc, /* ZD1201SIMAXASSOC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) (iw_handler) zd1201_get_maxassoc, /* ZD1201GIMAXASSOC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) static const struct iw_priv_args zd1201_private_args[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) { ZD1201SIWHOSTAUTH, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) IW_PRIV_TYPE_NONE, "sethostauth" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) { ZD1201GIWHOSTAUTH, IW_PRIV_TYPE_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostauth" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) { ZD1201SIWAUTHSTA, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) IW_PRIV_TYPE_NONE, "authstation" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) { ZD1201SIWMAXASSOC, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) IW_PRIV_TYPE_NONE, "setmaxassoc" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) { ZD1201GIWMAXASSOC, IW_PRIV_TYPE_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmaxassoc" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) static const struct iw_handler_def zd1201_iw_handlers = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) .num_standard = ARRAY_SIZE(zd1201_iw_handler),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) .num_private = ARRAY_SIZE(zd1201_private_handler),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) .num_private_args = ARRAY_SIZE(zd1201_private_args),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) .standard = (iw_handler *)zd1201_iw_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) .private = (iw_handler *)zd1201_private_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) .private_args = (struct iw_priv_args *) zd1201_private_args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) .get_wireless_stats = zd1201_get_wireless_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) static const struct net_device_ops zd1201_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) .ndo_open = zd1201_net_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) .ndo_stop = zd1201_net_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) .ndo_start_xmit = zd1201_hard_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) .ndo_tx_timeout = zd1201_tx_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) .ndo_set_rx_mode = zd1201_set_multicast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) .ndo_set_mac_address = zd1201_set_mac_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) .ndo_validate_addr = eth_validate_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) static int zd1201_probe(struct usb_interface *interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) struct zd1201 *zd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) struct usb_device *usb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) short porttype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) char buf[IW_ESSID_MAX_SIZE+2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) usb = interface_to_usbdev(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) dev = alloc_etherdev(sizeof(*zd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) zd = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) zd->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) zd->ap = ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) zd->usb = usb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) zd->removed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) init_waitqueue_head(&zd->rxdataq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) INIT_HLIST_HEAD(&zd->fraglist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) err = zd1201_fw_upload(usb, zd->ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) dev_err(&usb->dev, "zd1201 firmware upload failed: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) goto err_zd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) zd->endp_in = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) zd->endp_out = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) zd->endp_out2 = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) zd->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) zd->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) if (!zd->rx_urb || !zd->tx_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) goto err_zd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) mdelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) err = zd1201_drvr_start(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) goto err_zd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) err = zd1201_setconfig16(zd, ZD1201_RID_CNFMAXDATALEN, 2312);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) goto err_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) err = zd1201_setconfig16(zd, ZD1201_RID_TXRATECNTL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) ZD1201_RATEB1 | ZD1201_RATEB2 | ZD1201_RATEB5 | ZD1201_RATEB11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) goto err_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) dev->netdev_ops = &zd1201_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) dev->wireless_handlers = &zd1201_iw_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) dev->watchdog_timeo = ZD1201_TX_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) strcpy(dev->name, "wlan%d");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) err = zd1201_getconfig(zd, ZD1201_RID_CNFOWNMACADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) dev->dev_addr, dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) goto err_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) /* Set wildcard essid to match zd->essid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) *(__le16 *)buf = cpu_to_le16(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) err = zd1201_setconfig(zd, ZD1201_RID_CNFDESIREDSSID, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) IW_ESSID_MAX_SIZE+2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) goto err_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) if (zd->ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) porttype = ZD1201_PORTTYPE_AP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) porttype = ZD1201_PORTTYPE_BSS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) err = zd1201_setconfig16(zd, ZD1201_RID_CNFPORTTYPE, porttype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) goto err_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) SET_NETDEV_DEV(dev, &usb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) err = register_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) goto err_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) dev_info(&usb->dev, "%s: ZD1201 USB Wireless interface\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) usb_set_intfdata(interface, zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) zd1201_enable(zd); /* zd1201 likes to startup enabled, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) zd1201_disable(zd); /* interfering with all the wifis in range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) err_start:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) /* Leave the device in reset state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) zd1201_docmd(zd, ZD1201_CMDCODE_INIT, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) err_zd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) usb_free_urb(zd->tx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) usb_free_urb(zd->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) static void zd1201_disconnect(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) struct zd1201 *zd = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) struct hlist_node *node2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) struct zd1201_frag *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) if (!zd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) usb_set_intfdata(interface, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) hlist_for_each_entry_safe(frag, node2, &zd->fraglist, fnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) hlist_del_init(&frag->fnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) kfree_skb(frag->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) kfree(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) if (zd->tx_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) usb_kill_urb(zd->tx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) usb_free_urb(zd->tx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) if (zd->rx_urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) usb_kill_urb(zd->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) usb_free_urb(zd->rx_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) if (zd->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) unregister_netdev(zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) free_netdev(zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) static int zd1201_suspend(struct usb_interface *interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) struct zd1201 *zd = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) netif_device_detach(zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) zd->was_enabled = zd->mac_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) if (zd->was_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) return zd1201_disable(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) static int zd1201_resume(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) struct zd1201 *zd = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) if (!zd || !zd->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) netif_device_attach(zd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) if (zd->was_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) return zd1201_enable(zd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) #define zd1201_suspend NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) #define zd1201_resume NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) static struct usb_driver zd1201_usb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) .name = "zd1201",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) .probe = zd1201_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) .disconnect = zd1201_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) .id_table = zd1201_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) .suspend = zd1201_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) .resume = zd1201_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) .disable_hub_initiated_lpm = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) module_usb_driver(zd1201_usb);