| @@ -1,2282 +1,2282 @@ | | | @@ -1,2282 +1,2282 @@ |
1 | /* $NetBSD: if_atu.c,v 1.57 2018/05/01 16:18:13 maya Exp $ */ | | 1 | /* $NetBSD: if_atu.c,v 1.58 2018/06/03 10:59:35 maxv Exp $ */ |
2 | /* $OpenBSD: if_atu.c,v 1.48 2004/12/30 01:53:21 dlg Exp $ */ | | 2 | /* $OpenBSD: if_atu.c,v 1.48 2004/12/30 01:53:21 dlg Exp $ */ |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2003, 2004 | | 4 | * Copyright (c) 2003, 2004 |
5 | * Daan Vreeken <Danovitsch@Vitsch.net>. All rights reserved. | | 5 | * Daan Vreeken <Danovitsch@Vitsch.net>. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. All advertising materials mentioning features or use of this software | | 15 | * 3. All advertising materials mentioning features or use of this software |
16 | * must display the following acknowledgement: | | 16 | * must display the following acknowledgement: |
17 | * This product includes software developed by Daan Vreeken. | | 17 | * This product includes software developed by Daan Vreeken. |
18 | * 4. Neither the name of the author nor the names of any co-contributors | | 18 | * 4. Neither the name of the author nor the names of any co-contributors |
19 | * may be used to endorse or promote products derived from this software | | 19 | * may be used to endorse or promote products derived from this software |
20 | * without specific prior written permission. | | 20 | * without specific prior written permission. |
21 | * | | 21 | * |
22 | * THIS SOFTWARE IS PROVIDED BY Daan Vreeken AND CONTRIBUTORS ``AS IS'' AND | | 22 | * THIS SOFTWARE IS PROVIDED BY Daan Vreeken AND CONTRIBUTORS ``AS IS'' AND |
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL Daan Vreeken OR THE VOICES IN HIS HEAD | | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL Daan Vreeken OR THE VOICES IN HIS HEAD |
26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
32 | * THE POSSIBILITY OF SUCH DAMAGE. | | 32 | * THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | /* | | 35 | /* |
36 | * Atmel AT76c503 / AT76c503a / AT76c505 / AT76c505a USB WLAN driver | | 36 | * Atmel AT76c503 / AT76c503a / AT76c505 / AT76c505a USB WLAN driver |
37 | * version 0.5 - 2004-08-03 | | 37 | * version 0.5 - 2004-08-03 |
38 | * | | 38 | * |
39 | * Originally written by Daan Vreeken <Danovitsch @ Vitsch . net> | | 39 | * Originally written by Daan Vreeken <Danovitsch @ Vitsch . net> |
40 | * http://vitsch.net/bsd/atuwi | | 40 | * http://vitsch.net/bsd/atuwi |
41 | * | | 41 | * |
42 | * Contributed to by : | | 42 | * Contributed to by : |
43 | * Chris Whitehouse, Alistair Phillips, Peter Pilka, Martijn van Buul, | | 43 | * Chris Whitehouse, Alistair Phillips, Peter Pilka, Martijn van Buul, |
44 | * Suihong Liang, Arjan van Leeuwen, Stuart Walsh | | 44 | * Suihong Liang, Arjan van Leeuwen, Stuart Walsh |
45 | * | | 45 | * |
46 | * Ported to OpenBSD by Theo de Raadt and David Gwynne. | | 46 | * Ported to OpenBSD by Theo de Raadt and David Gwynne. |
47 | * Ported to NetBSD by Jesse Off | | 47 | * Ported to NetBSD by Jesse Off |
48 | */ | | 48 | */ |
49 | | | 49 | |
50 | #include <sys/cdefs.h> | | 50 | #include <sys/cdefs.h> |
51 | __KERNEL_RCSID(0, "$NetBSD: if_atu.c,v 1.57 2018/05/01 16:18:13 maya Exp $"); | | 51 | __KERNEL_RCSID(0, "$NetBSD: if_atu.c,v 1.58 2018/06/03 10:59:35 maxv Exp $"); |
52 | | | 52 | |
53 | #ifdef _KERNEL_OPT | | 53 | #ifdef _KERNEL_OPT |
54 | #include "opt_usb.h" | | 54 | #include "opt_usb.h" |
55 | #endif | | 55 | #endif |
56 | | | 56 | |
57 | #include <sys/param.h> | | 57 | #include <sys/param.h> |
58 | #include <sys/sockio.h> | | 58 | #include <sys/sockio.h> |
59 | #include <sys/mbuf.h> | | 59 | #include <sys/mbuf.h> |
60 | #include <sys/kernel.h> | | 60 | #include <sys/kernel.h> |
61 | #include <sys/socket.h> | | 61 | #include <sys/socket.h> |
62 | #include <sys/systm.h> | | 62 | #include <sys/systm.h> |
63 | #include <sys/kthread.h> | | 63 | #include <sys/kthread.h> |
64 | #include <sys/queue.h> | | 64 | #include <sys/queue.h> |
65 | #include <sys/device.h> | | 65 | #include <sys/device.h> |
66 | | | 66 | |
67 | #include <sys/bus.h> | | 67 | #include <sys/bus.h> |
68 | | | 68 | |
69 | #include <dev/usb/usb.h> | | 69 | #include <dev/usb/usb.h> |
70 | #include <dev/usb/usbdi.h> | | 70 | #include <dev/usb/usbdi.h> |
71 | #include <dev/usb/usbdi_util.h> | | 71 | #include <dev/usb/usbdi_util.h> |
72 | #include <dev/usb/usbdivar.h> | | 72 | #include <dev/usb/usbdivar.h> |
73 | | | 73 | |
74 | #include <dev/usb/usbdevs.h> | | 74 | #include <dev/usb/usbdevs.h> |
75 | | | 75 | |
76 | #include <dev/microcode/atmel/atmel_intersil_fw.h> | | 76 | #include <dev/microcode/atmel/atmel_intersil_fw.h> |
77 | #include <dev/microcode/atmel/atmel_rfmd2958-smc_fw.h> | | 77 | #include <dev/microcode/atmel/atmel_rfmd2958-smc_fw.h> |
78 | #include <dev/microcode/atmel/atmel_rfmd2958_fw.h> | | 78 | #include <dev/microcode/atmel/atmel_rfmd2958_fw.h> |
79 | #include <dev/microcode/atmel/atmel_rfmd_fw.h> | | 79 | #include <dev/microcode/atmel/atmel_rfmd_fw.h> |
80 | | | 80 | |
81 | #include <net/bpf.h> | | 81 | #include <net/bpf.h> |
82 | #include <net/bpfdesc.h> | | 82 | #include <net/bpfdesc.h> |
83 | | | 83 | |
84 | #include <net/if.h> | | 84 | #include <net/if.h> |
85 | #include <net/if_dl.h> | | 85 | #include <net/if_dl.h> |
86 | #include <net/if_media.h> | | 86 | #include <net/if_media.h> |
87 | #include <net/if_ether.h> | | 87 | #include <net/if_ether.h> |
88 | | | 88 | |
89 | #ifdef INET | | 89 | #ifdef INET |
90 | #include <netinet/in.h> | | 90 | #include <netinet/in.h> |
91 | #include <netinet/if_ether.h> | | 91 | #include <netinet/if_ether.h> |
92 | #endif | | 92 | #endif |
93 | | | 93 | |
94 | #include <net80211/ieee80211_var.h> | | 94 | #include <net80211/ieee80211_var.h> |
95 | #include <net80211/ieee80211_radiotap.h> | | 95 | #include <net80211/ieee80211_radiotap.h> |
96 | | | 96 | |
97 | #include <dev/usb/if_atureg.h> | | 97 | #include <dev/usb/if_atureg.h> |
98 | | | 98 | |
99 | #ifdef ATU_DEBUG | | 99 | #ifdef ATU_DEBUG |
100 | #define DPRINTF(x) do { if (atudebug) printf x; } while (0) | | 100 | #define DPRINTF(x) do { if (atudebug) printf x; } while (0) |
101 | #define DPRINTFN(n,x) do { if (atudebug>(n)) printf x; } while (0) | | 101 | #define DPRINTFN(n,x) do { if (atudebug>(n)) printf x; } while (0) |
102 | int atudebug = 1; | | 102 | int atudebug = 1; |
103 | #else | | 103 | #else |
104 | #define DPRINTF(x) | | 104 | #define DPRINTF(x) |
105 | #define DPRINTFN(n,x) | | 105 | #define DPRINTFN(n,x) |
106 | #endif | | 106 | #endif |
107 | | | 107 | |
108 | /* | | 108 | /* |
109 | * Various supported device vendors/products/radio type. | | 109 | * Various supported device vendors/products/radio type. |
110 | */ | | 110 | */ |
111 | struct atu_type atu_devs[] = { | | 111 | static const struct atu_type atu_devs[] = { |
112 | { USB_VENDOR_3COM, USB_PRODUCT_3COM_3CRSHEW696, | | 112 | { USB_VENDOR_3COM, USB_PRODUCT_3COM_3CRSHEW696, |
113 | RadioRFMD, ATU_NO_QUIRK }, | | 113 | RadioRFMD, ATU_NO_QUIRK }, |
114 | { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_BWU613, | | 114 | { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_BWU613, |
115 | RadioRFMD, ATU_NO_QUIRK }, | | 115 | RadioRFMD, ATU_NO_QUIRK }, |
116 | { USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_2664W, | | 116 | { USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_2664W, |
117 | AT76C503_rfmd_acc, ATU_NO_QUIRK }, | | 117 | AT76C503_rfmd_acc, ATU_NO_QUIRK }, |
118 | { USB_VENDOR_ACERP, USB_PRODUCT_ACERP_AWL300, | | 118 | { USB_VENDOR_ACERP, USB_PRODUCT_ACERP_AWL300, |
119 | RadioIntersil, ATU_NO_QUIRK }, | | 119 | RadioIntersil, ATU_NO_QUIRK }, |
120 | { USB_VENDOR_ACERP, USB_PRODUCT_ACERP_AWL400, | | 120 | { USB_VENDOR_ACERP, USB_PRODUCT_ACERP_AWL400, |
121 | RadioRFMD, ATU_NO_QUIRK }, | | 121 | RadioRFMD, ATU_NO_QUIRK }, |
122 | { USB_VENDOR_ACTIONTEC, USB_PRODUCT_ACTIONTEC_UAT1, | | 122 | { USB_VENDOR_ACTIONTEC, USB_PRODUCT_ACTIONTEC_UAT1, |
123 | RadioRFMD, ATU_NO_QUIRK }, | | 123 | RadioRFMD, ATU_NO_QUIRK }, |
124 | { USB_VENDOR_ADDTRON, USB_PRODUCT_ADDTRON_AWU120, | | 124 | { USB_VENDOR_ADDTRON, USB_PRODUCT_ADDTRON_AWU120, |
125 | RadioIntersil, ATU_NO_QUIRK }, | | 125 | RadioIntersil, ATU_NO_QUIRK }, |
126 | { USB_VENDOR_AINCOMM, USB_PRODUCT_AINCOMM_AWU2000B, | | 126 | { USB_VENDOR_AINCOMM, USB_PRODUCT_AINCOMM_AWU2000B, |
127 | RadioRFMD2958, ATU_NO_QUIRK }, | | 127 | RadioRFMD2958, ATU_NO_QUIRK }, |
128 | { USB_VENDOR_ASKEY, USB_PRODUCT_ASKEY_VOYAGER1010, | | 128 | { USB_VENDOR_ASKEY, USB_PRODUCT_ASKEY_VOYAGER1010, |
129 | RadioIntersil, ATU_NO_QUIRK }, | | 129 | RadioIntersil, ATU_NO_QUIRK }, |
130 | { USB_VENDOR_ASKEY, USB_PRODUCT_ASKEY_WLL013I, | | 130 | { USB_VENDOR_ASKEY, USB_PRODUCT_ASKEY_WLL013I, |
131 | RadioIntersil, ATU_NO_QUIRK }, | | 131 | RadioIntersil, ATU_NO_QUIRK }, |
132 | { USB_VENDOR_ASKEY, USB_PRODUCT_ASKEY_WLL013, | | 132 | { USB_VENDOR_ASKEY, USB_PRODUCT_ASKEY_WLL013, |
133 | RadioRFMD, ATU_NO_QUIRK }, | | 133 | RadioRFMD, ATU_NO_QUIRK }, |
134 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C503I1, | | 134 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C503I1, |
135 | RadioIntersil, ATU_NO_QUIRK }, | | 135 | RadioIntersil, ATU_NO_QUIRK }, |
136 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C503I2, | | 136 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C503I2, |
137 | AT76C503_i3863, ATU_NO_QUIRK }, | | 137 | AT76C503_i3863, ATU_NO_QUIRK }, |
138 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C503RFMD, | | 138 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C503RFMD, |
139 | RadioRFMD, ATU_NO_QUIRK }, | | 139 | RadioRFMD, ATU_NO_QUIRK }, |
140 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C505RFMD, | | 140 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C505RFMD, |
141 | AT76C505_rfmd, ATU_NO_QUIRK }, | | 141 | AT76C505_rfmd, ATU_NO_QUIRK }, |
142 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C505RFMD2958, | | 142 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C505RFMD2958, |
143 | RadioRFMD2958, ATU_NO_QUIRK }, | | 143 | RadioRFMD2958, ATU_NO_QUIRK }, |
144 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C505A, /* SMC2662 V.4 */ | | 144 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C505A, /* SMC2662 V.4 */ |
145 | RadioRFMD2958_SMC, ATU_QUIRK_NO_REMAP | ATU_QUIRK_FW_DELAY }, | | 145 | RadioRFMD2958_SMC, ATU_QUIRK_NO_REMAP | ATU_QUIRK_FW_DELAY }, |
146 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C505AS, /* quirk? */ | | 146 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_AT76C505AS, /* quirk? */ |
147 | RadioRFMD2958_SMC, ATU_QUIRK_NO_REMAP | ATU_QUIRK_FW_DELAY }, | | 147 | RadioRFMD2958_SMC, ATU_QUIRK_NO_REMAP | ATU_QUIRK_FW_DELAY }, |
148 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_WN210, | | 148 | { USB_VENDOR_ATMEL, USB_PRODUCT_ATMEL_WN210, |
149 | RadioRFMD, ATU_NO_QUIRK }, | | 149 | RadioRFMD, ATU_NO_QUIRK }, |
150 | { USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5D6050, | | 150 | { USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5D6050, |
151 | RadioRFMD, ATU_NO_QUIRK }, | | 151 | RadioRFMD, ATU_NO_QUIRK }, |
152 | { USB_VENDOR_CONCEPTRONIC, USB_PRODUCT_CONCEPTRONIC_C11U, | | 152 | { USB_VENDOR_CONCEPTRONIC, USB_PRODUCT_CONCEPTRONIC_C11U, |
153 | RadioIntersil, ATU_NO_QUIRK }, | | 153 | RadioIntersil, ATU_NO_QUIRK }, |
154 | { USB_VENDOR_CONCEPTRONIC, USB_PRODUCT_CONCEPTRONIC_WL210, | | 154 | { USB_VENDOR_CONCEPTRONIC, USB_PRODUCT_CONCEPTRONIC_WL210, |
155 | RadioIntersil, ATU_NO_QUIRK }, | | 155 | RadioIntersil, ATU_NO_QUIRK }, |
156 | { USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_IPAQWLAN, | | 156 | { USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_IPAQWLAN, |
157 | RadioRFMD, ATU_NO_QUIRK }, | | 157 | RadioRFMD, ATU_NO_QUIRK }, |
158 | { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_WLUSB_11_STICK, | | 158 | { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_WLUSB_11_STICK, |
159 | RadioRFMD2958, ATU_NO_QUIRK }, | | 159 | RadioRFMD2958, ATU_NO_QUIRK }, |
160 | { USB_VENDOR_DICKSMITH, USB_PRODUCT_DICKSMITH_CHUSB611G, | | 160 | { USB_VENDOR_DICKSMITH, USB_PRODUCT_DICKSMITH_CHUSB611G, |
161 | RadioRFMD2958, ATU_NO_QUIRK }, | | 161 | RadioRFMD2958, ATU_NO_QUIRK }, |
162 | { USB_VENDOR_DICKSMITH, USB_PRODUCT_DICKSMITH_WL200U, | | 162 | { USB_VENDOR_DICKSMITH, USB_PRODUCT_DICKSMITH_WL200U, |
163 | RadioRFMD, ATU_NO_QUIRK }, | | 163 | RadioRFMD, ATU_NO_QUIRK }, |
164 | { USB_VENDOR_DICKSMITH, USB_PRODUCT_DICKSMITH_WL240U, | | 164 | { USB_VENDOR_DICKSMITH, USB_PRODUCT_DICKSMITH_WL240U, |
165 | RadioRFMD2958, ATU_NO_QUIRK }, | | 165 | RadioRFMD2958, ATU_NO_QUIRK }, |
166 | { USB_VENDOR_DICKSMITH, USB_PRODUCT_DICKSMITH_XH1153, | | 166 | { USB_VENDOR_DICKSMITH, USB_PRODUCT_DICKSMITH_XH1153, |
167 | RadioRFMD, ATU_NO_QUIRK }, | | 167 | RadioRFMD, ATU_NO_QUIRK }, |
168 | { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DWL120E, | | 168 | { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DWL120E, |
169 | RadioRFMD, ATU_NO_QUIRK }, | | 169 | RadioRFMD, ATU_NO_QUIRK }, |
170 | { USB_VENDOR_GIGABYTE, USB_PRODUCT_GIGABYTE_GNWLBM101, | | 170 | { USB_VENDOR_GIGABYTE, USB_PRODUCT_GIGABYTE_GNWLBM101, |
171 | RadioRFMD, ATU_NO_QUIRK }, | | 171 | RadioRFMD, ATU_NO_QUIRK }, |
172 | { USB_VENDOR_GIGASET, USB_PRODUCT_GIGASET_WLAN, /* quirk? */ | | 172 | { USB_VENDOR_GIGASET, USB_PRODUCT_GIGASET_WLAN, /* quirk? */ |
173 | RadioRFMD2958_SMC, ATU_QUIRK_NO_REMAP | ATU_QUIRK_FW_DELAY }, | | 173 | RadioRFMD2958_SMC, ATU_QUIRK_NO_REMAP | ATU_QUIRK_FW_DELAY }, |
174 | { USB_VENDOR_HP, USB_PRODUCT_HP_HN210W, | | 174 | { USB_VENDOR_HP, USB_PRODUCT_HP_HN210W, |
175 | RadioIntersil, ATU_NO_QUIRK }, | | 175 | RadioIntersil, ATU_NO_QUIRK }, |
176 | { USB_VENDOR_INTEL, USB_PRODUCT_INTEL_AP310, | | 176 | { USB_VENDOR_INTEL, USB_PRODUCT_INTEL_AP310, |
177 | RadioIntersil, ATU_NO_QUIRK }, | | 177 | RadioIntersil, ATU_NO_QUIRK }, |
178 | { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBWNB11A, | | 178 | { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBWNB11A, |
179 | RadioIntersil, ATU_NO_QUIRK }, | | 179 | RadioIntersil, ATU_NO_QUIRK }, |
180 | { USB_VENDOR_LEXAR, USB_PRODUCT_LEXAR_2662WAR, | | 180 | { USB_VENDOR_LEXAR, USB_PRODUCT_LEXAR_2662WAR, |
181 | RadioRFMD, ATU_NO_QUIRK }, | | 181 | RadioRFMD, ATU_NO_QUIRK }, |
182 | { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_WUSB11, | | 182 | { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_WUSB11, |
183 | RadioIntersil, ATU_NO_QUIRK }, | | 183 | RadioIntersil, ATU_NO_QUIRK }, |
184 | { USB_VENDOR_LINKSYS2, USB_PRODUCT_LINKSYS2_WUSB11, | | 184 | { USB_VENDOR_LINKSYS2, USB_PRODUCT_LINKSYS2_WUSB11, |
185 | RadioRFMD, ATU_NO_QUIRK }, | | 185 | RadioRFMD, ATU_NO_QUIRK }, |
186 | { USB_VENDOR_LINKSYS2, USB_PRODUCT_LINKSYS2_NWU11B, | | 186 | { USB_VENDOR_LINKSYS2, USB_PRODUCT_LINKSYS2_NWU11B, |
187 | RadioRFMD, ATU_NO_QUIRK }, | | 187 | RadioRFMD, ATU_NO_QUIRK }, |
188 | { USB_VENDOR_LINKSYS3, USB_PRODUCT_LINKSYS3_WUSB11V28, | | 188 | { USB_VENDOR_LINKSYS3, USB_PRODUCT_LINKSYS3_WUSB11V28, |
189 | RadioRFMD2958, ATU_NO_QUIRK }, | | 189 | RadioRFMD2958, ATU_NO_QUIRK }, |
190 | { USB_VENDOR_MSI, USB_PRODUCT_MSI_WLAN, | | 190 | { USB_VENDOR_MSI, USB_PRODUCT_MSI_WLAN, |
191 | RadioRFMD2958, ATU_NO_QUIRK }, | | 191 | RadioRFMD2958, ATU_NO_QUIRK }, |
192 | { USB_VENDOR_NETGEAR2, USB_PRODUCT_NETGEAR2_MA101, | | 192 | { USB_VENDOR_NETGEAR2, USB_PRODUCT_NETGEAR2_MA101, |
193 | RadioIntersil, ATU_NO_QUIRK }, | | 193 | RadioIntersil, ATU_NO_QUIRK }, |
194 | { USB_VENDOR_NETGEAR2, USB_PRODUCT_NETGEAR2_MA101B, | | 194 | { USB_VENDOR_NETGEAR2, USB_PRODUCT_NETGEAR2_MA101B, |
195 | RadioRFMD, ATU_NO_QUIRK }, | | 195 | RadioRFMD, ATU_NO_QUIRK }, |
196 | { USB_VENDOR_OQO, USB_PRODUCT_OQO_WIFI01, | | 196 | { USB_VENDOR_OQO, USB_PRODUCT_OQO_WIFI01, |
197 | RadioRFMD2958_SMC, ATU_QUIRK_NO_REMAP | ATU_QUIRK_FW_DELAY }, | | 197 | RadioRFMD2958_SMC, ATU_QUIRK_NO_REMAP | ATU_QUIRK_FW_DELAY }, |
198 | { USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GW_US11S, | | 198 | { USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GW_US11S, |
199 | RadioRFMD, ATU_NO_QUIRK }, | | 199 | RadioRFMD, ATU_NO_QUIRK }, |
200 | { USB_VENDOR_SAMSUNG, USB_PRODUCT_SAMSUNG_SWL2100W, | | 200 | { USB_VENDOR_SAMSUNG, USB_PRODUCT_SAMSUNG_SWL2100W, |
201 | AT76C503_i3863, ATU_NO_QUIRK }, | | 201 | AT76C503_i3863, ATU_NO_QUIRK }, |
202 | { USB_VENDOR_SIEMENS2, USB_PRODUCT_SIEMENS2_WLL013, | | 202 | { USB_VENDOR_SIEMENS2, USB_PRODUCT_SIEMENS2_WLL013, |
203 | RadioRFMD, ATU_NO_QUIRK }, | | 203 | RadioRFMD, ATU_NO_QUIRK }, |
204 | { USB_VENDOR_SMC3, USB_PRODUCT_SMC3_2662WV1, | | 204 | { USB_VENDOR_SMC3, USB_PRODUCT_SMC3_2662WV1, |
205 | RadioIntersil, ATU_NO_QUIRK }, | | 205 | RadioIntersil, ATU_NO_QUIRK }, |
206 | { USB_VENDOR_SMC3, USB_PRODUCT_SMC3_2662WV2, | | 206 | { USB_VENDOR_SMC3, USB_PRODUCT_SMC3_2662WV2, |
207 | AT76C503_rfmd_acc, ATU_NO_QUIRK }, | | 207 | AT76C503_rfmd_acc, ATU_NO_QUIRK }, |
208 | { USB_VENDOR_TEKRAM, USB_PRODUCT_TEKRAM_U300C, | | 208 | { USB_VENDOR_TEKRAM, USB_PRODUCT_TEKRAM_U300C, |
209 | RadioIntersil, ATU_NO_QUIRK }, | | 209 | RadioIntersil, ATU_NO_QUIRK }, |
210 | { USB_VENDOR_ZCOM, USB_PRODUCT_ZCOM_M4Y750, | | 210 | { USB_VENDOR_ZCOM, USB_PRODUCT_ZCOM_M4Y750, |
211 | RadioIntersil, ATU_NO_QUIRK }, | | 211 | RadioIntersil, ATU_NO_QUIRK }, |
212 | }; | | 212 | }; |
213 | | | 213 | |
214 | struct atu_radfirm { | | 214 | struct atu_radfirm { |
215 | enum atu_radio_type atur_type; | | 215 | enum atu_radio_type atur_type; |
216 | unsigned char *atur_internal; | | 216 | unsigned char *atur_internal; |
217 | size_t atur_internal_sz; | | 217 | size_t atur_internal_sz; |
218 | unsigned char *atur_external; | | 218 | unsigned char *atur_external; |
219 | size_t atur_external_sz; | | 219 | size_t atur_external_sz; |
220 | } atu_radfirm[] = { | | 220 | } atu_radfirm[] = { |
221 | { RadioRFMD, | | 221 | { RadioRFMD, |
222 | atmel_fw_rfmd_int, sizeof(atmel_fw_rfmd_int), | | 222 | atmel_fw_rfmd_int, sizeof(atmel_fw_rfmd_int), |
223 | atmel_fw_rfmd_ext, sizeof(atmel_fw_rfmd_ext) }, | | 223 | atmel_fw_rfmd_ext, sizeof(atmel_fw_rfmd_ext) }, |
224 | { RadioRFMD2958, | | 224 | { RadioRFMD2958, |
225 | atmel_fw_rfmd2958_int, sizeof(atmel_fw_rfmd2958_int), | | 225 | atmel_fw_rfmd2958_int, sizeof(atmel_fw_rfmd2958_int), |
226 | atmel_fw_rfmd2958_ext, sizeof(atmel_fw_rfmd2958_ext) }, | | 226 | atmel_fw_rfmd2958_ext, sizeof(atmel_fw_rfmd2958_ext) }, |
227 | { RadioRFMD2958_SMC, | | 227 | { RadioRFMD2958_SMC, |
228 | atmel_fw_rfmd2958_smc_int, sizeof(atmel_fw_rfmd2958_smc_int), | | 228 | atmel_fw_rfmd2958_smc_int, sizeof(atmel_fw_rfmd2958_smc_int), |
229 | atmel_fw_rfmd2958_smc_ext, sizeof(atmel_fw_rfmd2958_smc_ext) }, | | 229 | atmel_fw_rfmd2958_smc_ext, sizeof(atmel_fw_rfmd2958_smc_ext) }, |
230 | { RadioIntersil, | | 230 | { RadioIntersil, |
231 | atmel_fw_intersil_int, sizeof(atmel_fw_intersil_int), | | 231 | atmel_fw_intersil_int, sizeof(atmel_fw_intersil_int), |
232 | atmel_fw_intersil_ext, sizeof(atmel_fw_intersil_ext) } | | 232 | atmel_fw_intersil_ext, sizeof(atmel_fw_intersil_ext) } |
233 | }; | | 233 | }; |
234 | | | 234 | |
235 | int atu_newbuf(struct atu_softc *, struct atu_chain *, struct mbuf *); | | 235 | int atu_newbuf(struct atu_softc *, struct atu_chain *, struct mbuf *); |
236 | void atu_rxeof(struct usbd_xfer *, void *, usbd_status); | | 236 | void atu_rxeof(struct usbd_xfer *, void *, usbd_status); |
237 | void atu_txeof(struct usbd_xfer *, void *, usbd_status); | | 237 | void atu_txeof(struct usbd_xfer *, void *, usbd_status); |
238 | void atu_start(struct ifnet *); | | 238 | void atu_start(struct ifnet *); |
239 | int atu_ioctl(struct ifnet *, u_long, void *); | | 239 | int atu_ioctl(struct ifnet *, u_long, void *); |
240 | int atu_init(struct ifnet *); | | 240 | int atu_init(struct ifnet *); |
241 | void atu_stop(struct ifnet *, int); | | 241 | void atu_stop(struct ifnet *, int); |
242 | void atu_watchdog(struct ifnet *); | | 242 | void atu_watchdog(struct ifnet *); |
243 | usbd_status atu_usb_request(struct atu_softc *, uint8_t, | | 243 | usbd_status atu_usb_request(struct atu_softc *, uint8_t, |
244 | uint8_t, uint16_t, uint16_t, | | 244 | uint8_t, uint16_t, uint16_t, |
245 | uint16_t, uint8_t *); | | 245 | uint16_t, uint8_t *); |
246 | int atu_send_command(struct atu_softc *, uint8_t *, int); | | 246 | int atu_send_command(struct atu_softc *, uint8_t *, int); |
247 | int atu_get_cmd_status(struct atu_softc *, uint8_t, | | 247 | int atu_get_cmd_status(struct atu_softc *, uint8_t, |
248 | uint8_t *); | | 248 | uint8_t *); |
249 | int atu_wait_completion(struct atu_softc *, uint8_t, | | 249 | int atu_wait_completion(struct atu_softc *, uint8_t, |
250 | uint8_t *); | | 250 | uint8_t *); |
251 | int atu_send_mib(struct atu_softc *, uint8_t, | | 251 | int atu_send_mib(struct atu_softc *, uint8_t, |
252 | uint8_t, uint8_t, void *); | | 252 | uint8_t, uint8_t, void *); |
253 | int atu_get_mib(struct atu_softc *, uint8_t, | | 253 | int atu_get_mib(struct atu_softc *, uint8_t, |
254 | uint8_t, uint8_t, uint8_t *); | | 254 | uint8_t, uint8_t, uint8_t *); |
255 | #if 0 | | 255 | #if 0 |
256 | int atu_start_ibss(struct atu_softc *); | | 256 | int atu_start_ibss(struct atu_softc *); |
257 | #endif | | 257 | #endif |
258 | int atu_start_scan(struct atu_softc *); | | 258 | int atu_start_scan(struct atu_softc *); |
259 | int atu_switch_radio(struct atu_softc *, int); | | 259 | int atu_switch_radio(struct atu_softc *, int); |
260 | int atu_initial_config(struct atu_softc *); | | 260 | int atu_initial_config(struct atu_softc *); |
261 | int atu_join(struct atu_softc *, struct ieee80211_node *); | | 261 | int atu_join(struct atu_softc *, struct ieee80211_node *); |
262 | int8_t atu_get_dfu_state(struct atu_softc *); | | 262 | int8_t atu_get_dfu_state(struct atu_softc *); |
263 | uint8_t atu_get_opmode(struct atu_softc *, uint8_t *); | | 263 | uint8_t atu_get_opmode(struct atu_softc *, uint8_t *); |
264 | void atu_internal_firmware(device_t); | | 264 | void atu_internal_firmware(device_t); |
265 | void atu_external_firmware(device_t); | | 265 | void atu_external_firmware(device_t); |
266 | int atu_get_card_config(struct atu_softc *); | | 266 | int atu_get_card_config(struct atu_softc *); |
267 | int atu_media_change(struct ifnet *); | | 267 | int atu_media_change(struct ifnet *); |
268 | void atu_media_status(struct ifnet *, struct ifmediareq *); | | 268 | void atu_media_status(struct ifnet *, struct ifmediareq *); |
269 | int atu_tx_list_init(struct atu_softc *); | | 269 | int atu_tx_list_init(struct atu_softc *); |
270 | int atu_rx_list_init(struct atu_softc *); | | 270 | int atu_rx_list_init(struct atu_softc *); |
271 | void atu_xfer_list_free(struct atu_softc *, struct atu_chain *, | | 271 | void atu_xfer_list_free(struct atu_softc *, struct atu_chain *, |
272 | int); | | 272 | int); |
273 | | | 273 | |
274 | #ifdef ATU_DEBUG | | 274 | #ifdef ATU_DEBUG |
275 | void atu_debug_print(struct atu_softc *); | | 275 | void atu_debug_print(struct atu_softc *); |
276 | #endif | | 276 | #endif |
277 | | | 277 | |
278 | void atu_task(void *); | | 278 | void atu_task(void *); |
279 | int atu_newstate(struct ieee80211com *, enum ieee80211_state, int); | | 279 | int atu_newstate(struct ieee80211com *, enum ieee80211_state, int); |
280 | int atu_tx_start(struct atu_softc *, struct ieee80211_node *, | | 280 | int atu_tx_start(struct atu_softc *, struct ieee80211_node *, |
281 | struct atu_chain *, struct mbuf *); | | 281 | struct atu_chain *, struct mbuf *); |
282 | void atu_complete_attach(struct atu_softc *); | | 282 | void atu_complete_attach(struct atu_softc *); |
283 | uint8_t atu_calculate_padding(int); | | 283 | uint8_t atu_calculate_padding(int); |
284 | | | 284 | |
285 | int atu_match(device_t, cfdata_t, void *); | | 285 | int atu_match(device_t, cfdata_t, void *); |
286 | void atu_attach(device_t, device_t, void *); | | 286 | void atu_attach(device_t, device_t, void *); |
287 | int atu_detach(device_t, int); | | 287 | int atu_detach(device_t, int); |
288 | int atu_activate(device_t, enum devact); | | 288 | int atu_activate(device_t, enum devact); |
289 | extern struct cfdriver atu_cd; | | 289 | extern struct cfdriver atu_cd; |
290 | CFATTACH_DECL_NEW(atu, sizeof(struct atu_softc), atu_match, atu_attach, | | 290 | CFATTACH_DECL_NEW(atu, sizeof(struct atu_softc), atu_match, atu_attach, |
291 | atu_detach, atu_activate); | | 291 | atu_detach, atu_activate); |
292 | | | 292 | |
293 | usbd_status | | 293 | usbd_status |
294 | atu_usb_request(struct atu_softc *sc, uint8_t type, | | 294 | atu_usb_request(struct atu_softc *sc, uint8_t type, |
295 | uint8_t request, uint16_t value, uint16_t index, uint16_t length, | | 295 | uint8_t request, uint16_t value, uint16_t index, uint16_t length, |
296 | uint8_t *data) | | 296 | uint8_t *data) |
297 | { | | 297 | { |
298 | usb_device_request_t req; | | 298 | usb_device_request_t req; |
299 | struct usbd_xfer *xfer; | | 299 | struct usbd_xfer *xfer; |
300 | usbd_status err; | | 300 | usbd_status err; |
301 | int total_len = 0, s; | | 301 | int total_len = 0, s; |
302 | | | 302 | |
303 | req.bmRequestType = type; | | 303 | req.bmRequestType = type; |
304 | req.bRequest = request; | | 304 | req.bRequest = request; |
305 | USETW(req.wValue, value); | | 305 | USETW(req.wValue, value); |
306 | USETW(req.wIndex, index); | | 306 | USETW(req.wIndex, index); |
307 | USETW(req.wLength, length); | | 307 | USETW(req.wLength, length); |
308 | | | 308 | |
309 | #ifdef ATU_DEBUG | | 309 | #ifdef ATU_DEBUG |
310 | if (atudebug) { | | 310 | if (atudebug) { |
311 | DPRINTFN(20, ("%s: req=%02x val=%02x ind=%02x " | | 311 | DPRINTFN(20, ("%s: req=%02x val=%02x ind=%02x " |
312 | "len=%02x\n", device_xname(sc->atu_dev), request, | | 312 | "len=%02x\n", device_xname(sc->atu_dev), request, |
313 | value, index, length)); | | 313 | value, index, length)); |
314 | } | | 314 | } |
315 | #endif /* ATU_DEBUG */ | | 315 | #endif /* ATU_DEBUG */ |
316 | | | 316 | |
317 | s = splnet(); | | 317 | s = splnet(); |
318 | | | 318 | |
319 | struct usbd_pipe *pipe0 = usbd_get_pipe0(sc->atu_udev); | | 319 | struct usbd_pipe *pipe0 = usbd_get_pipe0(sc->atu_udev); |
320 | int error = usbd_create_xfer(pipe0, length, 0, 0, | | 320 | int error = usbd_create_xfer(pipe0, length, 0, 0, |
321 | &xfer); | | 321 | &xfer); |
322 | if (error) { | | 322 | if (error) { |
323 | splx(s); | | 323 | splx(s); |
324 | return USBD_IOERROR; | | 324 | return USBD_IOERROR; |
325 | } | | 325 | } |
326 | usbd_setup_default_xfer(xfer, sc->atu_udev, 0, 500000, &req, data, | | 326 | usbd_setup_default_xfer(xfer, sc->atu_udev, 0, 500000, &req, data, |
327 | length, USBD_SHORT_XFER_OK, NULL); | | 327 | length, USBD_SHORT_XFER_OK, NULL); |
328 | | | 328 | |
329 | err = usbd_sync_transfer(xfer); | | 329 | err = usbd_sync_transfer(xfer); |
330 | | | 330 | |
331 | usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); | | 331 | usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); |
332 | | | 332 | |
333 | #ifdef ATU_DEBUG | | 333 | #ifdef ATU_DEBUG |
334 | if (atudebug) { | | 334 | if (atudebug) { |
335 | if (type & UT_READ) { | | 335 | if (type & UT_READ) { |
336 | DPRINTFN(20, ("%s: transfered 0x%x bytes in\n", | | 336 | DPRINTFN(20, ("%s: transfered 0x%x bytes in\n", |
337 | device_xname(sc->atu_dev), total_len)); | | 337 | device_xname(sc->atu_dev), total_len)); |
338 | } else { | | 338 | } else { |
339 | if (total_len != length) | | 339 | if (total_len != length) |
340 | DPRINTF(("%s: wrote only %x bytes\n", | | 340 | DPRINTF(("%s: wrote only %x bytes\n", |
341 | device_xname(sc->atu_dev), total_len)); | | 341 | device_xname(sc->atu_dev), total_len)); |
342 | } | | 342 | } |
343 | } | | 343 | } |
344 | #endif /* ATU_DEBUG */ | | 344 | #endif /* ATU_DEBUG */ |
345 | | | 345 | |
346 | usbd_destroy_xfer(xfer); | | 346 | usbd_destroy_xfer(xfer); |
347 | | | 347 | |
348 | splx(s); | | 348 | splx(s); |
349 | return(err); | | 349 | return(err); |
350 | } | | 350 | } |
351 | | | 351 | |
352 | int | | 352 | int |
353 | atu_send_command(struct atu_softc *sc, uint8_t *command, int size) | | 353 | atu_send_command(struct atu_softc *sc, uint8_t *command, int size) |
354 | { | | 354 | { |
355 | return atu_usb_request(sc, UT_WRITE_VENDOR_DEVICE, 0x0e, 0x0000, | | 355 | return atu_usb_request(sc, UT_WRITE_VENDOR_DEVICE, 0x0e, 0x0000, |
356 | 0x0000, size, command); | | 356 | 0x0000, size, command); |
357 | } | | 357 | } |
358 | | | 358 | |
359 | int | | 359 | int |
360 | atu_get_cmd_status(struct atu_softc *sc, uint8_t cmd, uint8_t *status) | | 360 | atu_get_cmd_status(struct atu_softc *sc, uint8_t cmd, uint8_t *status) |
361 | { | | 361 | { |
362 | /* | | 362 | /* |
363 | * all other drivers (including Windoze) request 40 bytes of status | | 363 | * all other drivers (including Windoze) request 40 bytes of status |
364 | * and get a short-xfer of just 6 bytes. we can save 34 bytes of | | 364 | * and get a short-xfer of just 6 bytes. we can save 34 bytes of |
365 | * buffer if we just request those 6 bytes in the first place :) | | 365 | * buffer if we just request those 6 bytes in the first place :) |
366 | */ | | 366 | */ |
367 | /* | | 367 | /* |
368 | return atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x22, cmd, | | 368 | return atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x22, cmd, |
369 | 0x0000, 40, status); | | 369 | 0x0000, 40, status); |
370 | */ | | 370 | */ |
371 | return atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x22, cmd, | | 371 | return atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x22, cmd, |
372 | 0x0000, 6, status); | | 372 | 0x0000, 6, status); |
373 | } | | 373 | } |
374 | | | 374 | |
375 | int | | 375 | int |
376 | atu_wait_completion(struct atu_softc *sc, uint8_t cmd, uint8_t *status) | | 376 | atu_wait_completion(struct atu_softc *sc, uint8_t cmd, uint8_t *status) |
377 | { | | 377 | { |
378 | int idle_count = 0, err; | | 378 | int idle_count = 0, err; |
379 | uint8_t statusreq[6]; | | 379 | uint8_t statusreq[6]; |
380 | | | 380 | |
381 | DPRINTFN(15, ("%s: wait-completion: cmd=%02x\n", | | 381 | DPRINTFN(15, ("%s: wait-completion: cmd=%02x\n", |
382 | device_xname(sc->atu_dev), cmd)); | | 382 | device_xname(sc->atu_dev), cmd)); |
383 | | | 383 | |
384 | while (1) { | | 384 | while (1) { |
385 | err = atu_get_cmd_status(sc, cmd, statusreq); | | 385 | err = atu_get_cmd_status(sc, cmd, statusreq); |
386 | if (err) | | 386 | if (err) |
387 | return err; | | 387 | return err; |
388 | | | 388 | |
389 | #ifdef ATU_DEBUG | | 389 | #ifdef ATU_DEBUG |
390 | if (atudebug) { | | 390 | if (atudebug) { |
391 | DPRINTFN(20, ("%s: status=%s cmd=%02x\n", | | 391 | DPRINTFN(20, ("%s: status=%s cmd=%02x\n", |
392 | device_xname(sc->atu_dev), | | 392 | device_xname(sc->atu_dev), |
393 | ether_sprintf(statusreq), cmd)); | | 393 | ether_sprintf(statusreq), cmd)); |
394 | } | | 394 | } |
395 | #endif /* ATU_DEBUG */ | | 395 | #endif /* ATU_DEBUG */ |
396 | | | 396 | |
397 | /* | | 397 | /* |
398 | * during normal operations waiting on STATUS_IDLE | | 398 | * during normal operations waiting on STATUS_IDLE |
399 | * will never happen more than once | | 399 | * will never happen more than once |
400 | */ | | 400 | */ |
401 | if ((statusreq[5] == STATUS_IDLE) && (idle_count++ > 20)) { | | 401 | if ((statusreq[5] == STATUS_IDLE) && (idle_count++ > 20)) { |
402 | DPRINTF(("%s: idle_count > 20!\n", | | 402 | DPRINTF(("%s: idle_count > 20!\n", |
403 | device_xname(sc->atu_dev))); | | 403 | device_xname(sc->atu_dev))); |
404 | return 0; | | 404 | return 0; |
405 | } | | 405 | } |
406 | | | 406 | |
407 | if ((statusreq[5] != STATUS_IN_PROGRESS) && | | 407 | if ((statusreq[5] != STATUS_IN_PROGRESS) && |
408 | (statusreq[5] != STATUS_IDLE)) { | | 408 | (statusreq[5] != STATUS_IDLE)) { |
409 | if (status != NULL) | | 409 | if (status != NULL) |
410 | *status = statusreq[5]; | | 410 | *status = statusreq[5]; |
411 | return 0; | | 411 | return 0; |
412 | } | | 412 | } |
413 | usbd_delay_ms(sc->atu_udev, 25); | | 413 | usbd_delay_ms(sc->atu_udev, 25); |
414 | } | | 414 | } |
415 | } | | 415 | } |
416 | | | 416 | |
417 | int | | 417 | int |
418 | atu_send_mib(struct atu_softc *sc, uint8_t type, uint8_t size, | | 418 | atu_send_mib(struct atu_softc *sc, uint8_t type, uint8_t size, |
419 | uint8_t index, void *data) | | 419 | uint8_t index, void *data) |
420 | { | | 420 | { |
421 | int err; | | 421 | int err; |
422 | struct atu_cmd_set_mib request; | | 422 | struct atu_cmd_set_mib request; |
423 | | | 423 | |
424 | /* | | 424 | /* |
425 | * We don't construct a MIB packet first and then memcpy it into an | | 425 | * We don't construct a MIB packet first and then memcpy it into an |
426 | * Atmel-command-packet, we just construct it the right way at once :) | | 426 | * Atmel-command-packet, we just construct it the right way at once :) |
427 | */ | | 427 | */ |
428 | | | 428 | |
429 | memset(&request, 0, sizeof(request)); | | 429 | memset(&request, 0, sizeof(request)); |
430 | | | 430 | |
431 | request.AtCmd = CMD_SET_MIB; | | 431 | request.AtCmd = CMD_SET_MIB; |
432 | USETW(request.AtSize, size + 4); | | 432 | USETW(request.AtSize, size + 4); |
433 | | | 433 | |
434 | request.MIBType = type; | | 434 | request.MIBType = type; |
435 | request.MIBSize = size; | | 435 | request.MIBSize = size; |
436 | request.MIBIndex = index; | | 436 | request.MIBIndex = index; |
437 | request.MIBReserved = 0; | | 437 | request.MIBReserved = 0; |
438 | | | 438 | |
439 | /* | | 439 | /* |
440 | * For 1 and 2 byte requests we assume a direct value, | | 440 | * For 1 and 2 byte requests we assume a direct value, |
441 | * everything bigger than 2 bytes we assume a pointer to the data | | 441 | * everything bigger than 2 bytes we assume a pointer to the data |
442 | */ | | 442 | */ |
443 | switch (size) { | | 443 | switch (size) { |
444 | case 0: | | 444 | case 0: |
445 | break; | | 445 | break; |
446 | case 1: | | 446 | case 1: |
447 | request.data[0]=(long)data & 0x000000ff; | | 447 | request.data[0]=(long)data & 0x000000ff; |
448 | break; | | 448 | break; |
449 | case 2: | | 449 | case 2: |
450 | request.data[0]=(long)data & 0x000000ff; | | 450 | request.data[0]=(long)data & 0x000000ff; |
451 | request.data[1]=(long)data >> 8; | | 451 | request.data[1]=(long)data >> 8; |
452 | break; | | 452 | break; |
453 | default: | | 453 | default: |
454 | memcpy(request.data, data, size); | | 454 | memcpy(request.data, data, size); |
455 | break; | | 455 | break; |
456 | } | | 456 | } |
457 | | | 457 | |
458 | err = atu_usb_request(sc, UT_WRITE_VENDOR_DEVICE, 0x0e, 0x0000, | | 458 | err = atu_usb_request(sc, UT_WRITE_VENDOR_DEVICE, 0x0e, 0x0000, |
459 | 0x0000, size+8, (uByte *)&request); | | 459 | 0x0000, size+8, (uByte *)&request); |
460 | if (err) | | 460 | if (err) |
461 | return err; | | 461 | return err; |
462 | | | 462 | |
463 | DPRINTFN(15, ("%s: sendmib : waitcompletion...\n", | | 463 | DPRINTFN(15, ("%s: sendmib : waitcompletion...\n", |
464 | device_xname(sc->atu_dev))); | | 464 | device_xname(sc->atu_dev))); |
465 | return atu_wait_completion(sc, CMD_SET_MIB, NULL); | | 465 | return atu_wait_completion(sc, CMD_SET_MIB, NULL); |
466 | } | | 466 | } |
467 | | | 467 | |
468 | int | | 468 | int |
469 | atu_get_mib(struct atu_softc *sc, uint8_t type, uint8_t size, | | 469 | atu_get_mib(struct atu_softc *sc, uint8_t type, uint8_t size, |
470 | uint8_t index, uint8_t *buf) | | 470 | uint8_t index, uint8_t *buf) |
471 | { | | 471 | { |
472 | | | 472 | |
473 | /* linux/at76c503.c - 478 */ | | 473 | /* linux/at76c503.c - 478 */ |
474 | return atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x033, | | 474 | return atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x033, |
475 | type << 8, index, size, buf); | | 475 | type << 8, index, size, buf); |
476 | } | | 476 | } |
477 | | | 477 | |
478 | #if 0 | | 478 | #if 0 |
479 | int | | 479 | int |
480 | atu_start_ibss(struct atu_softc *sc) | | 480 | atu_start_ibss(struct atu_softc *sc) |
481 | { | | 481 | { |
482 | struct ieee80211com *ic = &sc->sc_ic; | | 482 | struct ieee80211com *ic = &sc->sc_ic; |
483 | int err; | | 483 | int err; |
484 | struct atu_cmd_start_ibss Request; | | 484 | struct atu_cmd_start_ibss Request; |
485 | | | 485 | |
486 | Request.Cmd = CMD_START_IBSS; | | 486 | Request.Cmd = CMD_START_IBSS; |
487 | Request.Reserved = 0; | | 487 | Request.Reserved = 0; |
488 | Request.Size = sizeof(Request) - 4; | | 488 | Request.Size = sizeof(Request) - 4; |
489 | | | 489 | |
490 | memset(Request.BSSID, 0x00, sizeof(Request.BSSID)); | | 490 | memset(Request.BSSID, 0x00, sizeof(Request.BSSID)); |
491 | memset(Request.SSID, 0x00, sizeof(Request.SSID)); | | 491 | memset(Request.SSID, 0x00, sizeof(Request.SSID)); |
492 | memcpy(Request.SSID, ic->ic_des_ssid, ic->ic_des_ssidlen); | | 492 | memcpy(Request.SSID, ic->ic_des_ssid, ic->ic_des_ssidlen); |
493 | Request.SSIDSize = ic->ic_des_ssidlen; | | 493 | Request.SSIDSize = ic->ic_des_ssidlen; |
494 | if (sc->atu_desired_channel != IEEE80211_CHAN_ANY) | | 494 | if (sc->atu_desired_channel != IEEE80211_CHAN_ANY) |
495 | Request.Channel = (uint8_t)sc->atu_desired_channel; | | 495 | Request.Channel = (uint8_t)sc->atu_desired_channel; |
496 | else | | 496 | else |
497 | Request.Channel = ATU_DEFAULT_CHANNEL; | | 497 | Request.Channel = ATU_DEFAULT_CHANNEL; |
498 | Request.BSSType = AD_HOC_MODE; | | 498 | Request.BSSType = AD_HOC_MODE; |
499 | memset(Request.Res, 0x00, sizeof(Request.Res)); | | 499 | memset(Request.Res, 0x00, sizeof(Request.Res)); |
500 | | | 500 | |
501 | /* Write config to adapter */ | | 501 | /* Write config to adapter */ |
502 | err = atu_send_command(sc, (uint8_t *)&Request, sizeof(Request)); | | 502 | err = atu_send_command(sc, (uint8_t *)&Request, sizeof(Request)); |
503 | if (err) { | | 503 | if (err) { |
504 | DPRINTF(("%s: start ibss failed!\n", | | 504 | DPRINTF(("%s: start ibss failed!\n", |
505 | device_xname(sc->atu_dev))); | | 505 | device_xname(sc->atu_dev))); |
506 | return err; | | 506 | return err; |
507 | } | | 507 | } |
508 | | | 508 | |
509 | /* Wait for the adapter to do its thing */ | | 509 | /* Wait for the adapter to do its thing */ |
510 | err = atu_wait_completion(sc, CMD_START_IBSS, NULL); | | 510 | err = atu_wait_completion(sc, CMD_START_IBSS, NULL); |
511 | if (err) { | | 511 | if (err) { |
512 | DPRINTF(("%s: error waiting for start_ibss\n", | | 512 | DPRINTF(("%s: error waiting for start_ibss\n", |
513 | device_xname(sc->atu_dev))); | | 513 | device_xname(sc->atu_dev))); |
514 | return err; | | 514 | return err; |
515 | } | | 515 | } |
516 | | | 516 | |
517 | /* Get the current BSSID */ | | 517 | /* Get the current BSSID */ |
518 | err = atu_get_mib(sc, MIB_MAC_MGMT__CURRENT_BSSID, sc->atu_bssid); | | 518 | err = atu_get_mib(sc, MIB_MAC_MGMT__CURRENT_BSSID, sc->atu_bssid); |
519 | if (err) { | | 519 | if (err) { |
520 | DPRINTF(("%s: could not get BSSID!\n", | | 520 | DPRINTF(("%s: could not get BSSID!\n", |
521 | device_xname(sc->atu_dev))); | | 521 | device_xname(sc->atu_dev))); |
522 | return err; | | 522 | return err; |
523 | } | | 523 | } |
524 | | | 524 | |
525 | DPRINTF(("%s: started a new IBSS (BSSID=%s)\n", | | 525 | DPRINTF(("%s: started a new IBSS (BSSID=%s)\n", |
526 | device_xname(sc->atu_dev), ether_sprintf(sc->atu_bssid))); | | 526 | device_xname(sc->atu_dev), ether_sprintf(sc->atu_bssid))); |
527 | return 0; | | 527 | return 0; |
528 | } | | 528 | } |
529 | #endif | | 529 | #endif |
530 | | | 530 | |
531 | int | | 531 | int |
532 | atu_start_scan(struct atu_softc *sc) | | 532 | atu_start_scan(struct atu_softc *sc) |
533 | { | | 533 | { |
534 | struct ieee80211com *ic = &sc->sc_ic; | | 534 | struct ieee80211com *ic = &sc->sc_ic; |
535 | struct atu_cmd_do_scan Scan; | | 535 | struct atu_cmd_do_scan Scan; |
536 | usbd_status err; | | 536 | usbd_status err; |
537 | int Cnt; | | 537 | int Cnt; |
538 | | | 538 | |
539 | memset(&Scan, 0, sizeof(Scan)); | | 539 | memset(&Scan, 0, sizeof(Scan)); |
540 | | | 540 | |
541 | Scan.Cmd = CMD_START_SCAN; | | 541 | Scan.Cmd = CMD_START_SCAN; |
542 | Scan.Reserved = 0; | | 542 | Scan.Reserved = 0; |
543 | USETW(Scan.Size, sizeof(Scan) - 4); | | 543 | USETW(Scan.Size, sizeof(Scan) - 4); |
544 | | | 544 | |
545 | /* use the broadcast BSSID (in active scan) */ | | 545 | /* use the broadcast BSSID (in active scan) */ |
546 | for (Cnt=0; Cnt<6; Cnt++) | | 546 | for (Cnt=0; Cnt<6; Cnt++) |
547 | Scan.BSSID[Cnt] = 0xff; | | 547 | Scan.BSSID[Cnt] = 0xff; |
548 | | | 548 | |
549 | memset(Scan.SSID, 0x00, sizeof(Scan.SSID)); | | 549 | memset(Scan.SSID, 0x00, sizeof(Scan.SSID)); |
550 | memcpy(Scan.SSID, ic->ic_des_essid, ic->ic_des_esslen); | | 550 | memcpy(Scan.SSID, ic->ic_des_essid, ic->ic_des_esslen); |
551 | Scan.SSID_Len = ic->ic_des_esslen; | | 551 | Scan.SSID_Len = ic->ic_des_esslen; |
552 | | | 552 | |
553 | /* default values for scan */ | | 553 | /* default values for scan */ |
554 | Scan.ScanType = ATU_SCAN_ACTIVE; | | 554 | Scan.ScanType = ATU_SCAN_ACTIVE; |
555 | if (sc->atu_desired_channel != IEEE80211_CHAN_ANY) | | 555 | if (sc->atu_desired_channel != IEEE80211_CHAN_ANY) |
556 | Scan.Channel = (uint8_t)sc->atu_desired_channel; | | 556 | Scan.Channel = (uint8_t)sc->atu_desired_channel; |
557 | else | | 557 | else |
558 | Scan.Channel = sc->atu_channel; | | 558 | Scan.Channel = sc->atu_channel; |
559 | | | 559 | |
560 | ic->ic_curchan = &ic->ic_channels[Scan.Channel]; | | 560 | ic->ic_curchan = &ic->ic_channels[Scan.Channel]; |
561 | | | 561 | |
562 | /* we like scans to be quick :) */ | | 562 | /* we like scans to be quick :) */ |
563 | /* the time we wait before sending probe's */ | | 563 | /* the time we wait before sending probe's */ |
564 | USETW(Scan.ProbeDelay, 0); | | 564 | USETW(Scan.ProbeDelay, 0); |
565 | /* the time we stay on one channel */ | | 565 | /* the time we stay on one channel */ |
566 | USETW(Scan.MinChannelTime, 100); | | 566 | USETW(Scan.MinChannelTime, 100); |
567 | USETW(Scan.MaxChannelTime, 200); | | 567 | USETW(Scan.MaxChannelTime, 200); |
568 | /* whether or not we scan all channels */ | | 568 | /* whether or not we scan all channels */ |
569 | Scan.InternationalScan = 0xc1; | | 569 | Scan.InternationalScan = 0xc1; |
570 | | | 570 | |
571 | #ifdef ATU_DEBUG | | 571 | #ifdef ATU_DEBUG |
572 | if (atudebug) { | | 572 | if (atudebug) { |
573 | DPRINTFN(20, ("%s: scan cmd len=%02zx\n", | | 573 | DPRINTFN(20, ("%s: scan cmd len=%02zx\n", |
574 | device_xname(sc->atu_dev), sizeof(Scan))); | | 574 | device_xname(sc->atu_dev), sizeof(Scan))); |
575 | } | | 575 | } |
576 | #endif /* ATU_DEBUG */ | | 576 | #endif /* ATU_DEBUG */ |
577 | | | 577 | |
578 | /* Write config to adapter */ | | 578 | /* Write config to adapter */ |
579 | err = atu_send_command(sc, (uint8_t *)&Scan, sizeof(Scan)); | | 579 | err = atu_send_command(sc, (uint8_t *)&Scan, sizeof(Scan)); |
580 | if (err) | | 580 | if (err) |
581 | return err; | | 581 | return err; |
582 | | | 582 | |
583 | /* | | 583 | /* |
584 | * We don't wait for the command to finish... the mgmt-thread will do | | 584 | * We don't wait for the command to finish... the mgmt-thread will do |
585 | * that for us | | 585 | * that for us |
586 | */ | | 586 | */ |
587 | /* | | 587 | /* |
588 | err = atu_wait_completion(sc, CMD_START_SCAN, NULL); | | 588 | err = atu_wait_completion(sc, CMD_START_SCAN, NULL); |
589 | if (err) | | 589 | if (err) |
590 | return err; | | 590 | return err; |
591 | */ | | 591 | */ |
592 | return 0; | | 592 | return 0; |
593 | } | | 593 | } |
594 | | | 594 | |
595 | int | | 595 | int |
596 | atu_switch_radio(struct atu_softc *sc, int state) | | 596 | atu_switch_radio(struct atu_softc *sc, int state) |
597 | { | | 597 | { |
598 | usbd_status err; | | 598 | usbd_status err; |
599 | struct atu_cmd CmdRadio; | | 599 | struct atu_cmd CmdRadio; |
600 | | | 600 | |
601 | if (sc->atu_radio == RadioIntersil) { | | 601 | if (sc->atu_radio == RadioIntersil) { |
602 | /* | | 602 | /* |
603 | * Intersil doesn't seem to need/support switching the radio | | 603 | * Intersil doesn't seem to need/support switching the radio |
604 | * on/off | | 604 | * on/off |
605 | */ | | 605 | */ |
606 | return 0; | | 606 | return 0; |
607 | } | | 607 | } |
608 | | | 608 | |
609 | memset(&CmdRadio, 0, sizeof(CmdRadio)); | | 609 | memset(&CmdRadio, 0, sizeof(CmdRadio)); |
610 | CmdRadio.Cmd = CMD_RADIO_ON; | | 610 | CmdRadio.Cmd = CMD_RADIO_ON; |
611 | | | 611 | |
612 | if (sc->atu_radio_on != state) { | | 612 | if (sc->atu_radio_on != state) { |
613 | if (state == 0) | | 613 | if (state == 0) |
614 | CmdRadio.Cmd = CMD_RADIO_OFF; | | 614 | CmdRadio.Cmd = CMD_RADIO_OFF; |
615 | | | 615 | |
616 | err = atu_send_command(sc, (uint8_t *)&CmdRadio, | | 616 | err = atu_send_command(sc, (uint8_t *)&CmdRadio, |
617 | sizeof(CmdRadio)); | | 617 | sizeof(CmdRadio)); |
618 | if (err) | | 618 | if (err) |
619 | return err; | | 619 | return err; |
620 | | | 620 | |
621 | err = atu_wait_completion(sc, CmdRadio.Cmd, NULL); | | 621 | err = atu_wait_completion(sc, CmdRadio.Cmd, NULL); |
622 | if (err) | | 622 | if (err) |
623 | return err; | | 623 | return err; |
624 | | | 624 | |
625 | DPRINTFN(10, ("%s: radio turned %s\n", | | 625 | DPRINTFN(10, ("%s: radio turned %s\n", |
626 | device_xname(sc->atu_dev), state ? "on" : "off")); | | 626 | device_xname(sc->atu_dev), state ? "on" : "off")); |
627 | sc->atu_radio_on = state; | | 627 | sc->atu_radio_on = state; |
628 | } | | 628 | } |
629 | return 0; | | 629 | return 0; |
630 | } | | 630 | } |
631 | | | 631 | |
632 | int | | 632 | int |
633 | atu_initial_config(struct atu_softc *sc) | | 633 | atu_initial_config(struct atu_softc *sc) |
634 | { | | 634 | { |
635 | struct ieee80211com *ic = &sc->sc_ic; | | 635 | struct ieee80211com *ic = &sc->sc_ic; |
636 | uint32_t i; | | 636 | uint32_t i; |
637 | usbd_status err; | | 637 | usbd_status err; |
638 | /* uint8_t rates[4] = {0x82, 0x84, 0x8B, 0x96};*/ | | 638 | /* uint8_t rates[4] = {0x82, 0x84, 0x8B, 0x96};*/ |
639 | uint8_t rates[4] = {0x82, 0x04, 0x0B, 0x16}; | | 639 | uint8_t rates[4] = {0x82, 0x04, 0x0B, 0x16}; |
640 | struct atu_cmd_card_config cmd; | | 640 | struct atu_cmd_card_config cmd; |
641 | uint8_t reg_domain; | | 641 | uint8_t reg_domain; |
642 | | | 642 | |
643 | DPRINTFN(10, ("%s: sending mac-addr\n", device_xname(sc->atu_dev))); | | 643 | DPRINTFN(10, ("%s: sending mac-addr\n", device_xname(sc->atu_dev))); |
644 | err = atu_send_mib(sc, MIB_MAC_ADDR__ADDR, ic->ic_myaddr); | | 644 | err = atu_send_mib(sc, MIB_MAC_ADDR__ADDR, ic->ic_myaddr); |
645 | if (err) { | | 645 | if (err) { |
646 | DPRINTF(("%s: error setting mac-addr\n", | | 646 | DPRINTF(("%s: error setting mac-addr\n", |
647 | device_xname(sc->atu_dev))); | | 647 | device_xname(sc->atu_dev))); |
648 | return err; | | 648 | return err; |
649 | } | | 649 | } |
650 | | | 650 | |
651 | /* | | 651 | /* |
652 | DPRINTF(("%s: sending reg-domain\n", device_xname(sc->atu_dev))); | | 652 | DPRINTF(("%s: sending reg-domain\n", device_xname(sc->atu_dev))); |
653 | err = atu_send_mib(sc, MIB_PHY__REG_DOMAIN, NR(0x30)); | | 653 | err = atu_send_mib(sc, MIB_PHY__REG_DOMAIN, NR(0x30)); |
654 | if (err) { | | 654 | if (err) { |
655 | DPRINTF(("%s: error setting mac-addr\n", | | 655 | DPRINTF(("%s: error setting mac-addr\n", |
656 | device_xname(sc->atu_dev))); | | 656 | device_xname(sc->atu_dev))); |
657 | return err; | | 657 | return err; |
658 | } | | 658 | } |
659 | */ | | 659 | */ |
660 | | | 660 | |
661 | memset(&cmd, 0, sizeof(cmd)); | | 661 | memset(&cmd, 0, sizeof(cmd)); |
662 | cmd.Cmd = CMD_STARTUP; | | 662 | cmd.Cmd = CMD_STARTUP; |
663 | cmd.Reserved = 0; | | 663 | cmd.Reserved = 0; |
664 | USETW(cmd.Size, sizeof(cmd) - 4); | | 664 | USETW(cmd.Size, sizeof(cmd) - 4); |
665 | | | 665 | |
666 | if (sc->atu_desired_channel != IEEE80211_CHAN_ANY) | | 666 | if (sc->atu_desired_channel != IEEE80211_CHAN_ANY) |
667 | cmd.Channel = (uint8_t)sc->atu_desired_channel; | | 667 | cmd.Channel = (uint8_t)sc->atu_desired_channel; |
668 | else | | 668 | else |
669 | cmd.Channel = sc->atu_channel; | | 669 | cmd.Channel = sc->atu_channel; |
670 | cmd.AutoRateFallback = 1; | | 670 | cmd.AutoRateFallback = 1; |
671 | memcpy(cmd.BasicRateSet, rates, 4); | | 671 | memcpy(cmd.BasicRateSet, rates, 4); |
672 | | | 672 | |
673 | /* ShortRetryLimit should be 7 according to 802.11 spec */ | | 673 | /* ShortRetryLimit should be 7 according to 802.11 spec */ |
674 | cmd.ShortRetryLimit = 7; | | 674 | cmd.ShortRetryLimit = 7; |
675 | USETW(cmd.RTS_Threshold, 2347); | | 675 | USETW(cmd.RTS_Threshold, 2347); |
676 | USETW(cmd.FragThreshold, 2346); | | 676 | USETW(cmd.FragThreshold, 2346); |
677 | | | 677 | |
678 | /* Doesn't seem to work, but we'll set it to 1 anyway */ | | 678 | /* Doesn't seem to work, but we'll set it to 1 anyway */ |
679 | cmd.PromiscuousMode = 1; | | 679 | cmd.PromiscuousMode = 1; |
680 | | | 680 | |
681 | /* this goes into the beacon we transmit */ | | 681 | /* this goes into the beacon we transmit */ |
682 | if (ic->ic_flags & IEEE80211_F_PRIVACY) | | 682 | if (ic->ic_flags & IEEE80211_F_PRIVACY) |
683 | cmd.PrivacyInvoked = 1; | | 683 | cmd.PrivacyInvoked = 1; |
684 | else | | 684 | else |
685 | cmd.PrivacyInvoked = 0; | | 685 | cmd.PrivacyInvoked = 0; |
686 | | | 686 | |
687 | cmd.ExcludeUnencrypted = 0; | | 687 | cmd.ExcludeUnencrypted = 0; |
688 | | | 688 | |
689 | if (ic->ic_flags & IEEE80211_F_PRIVACY) { | | 689 | if (ic->ic_flags & IEEE80211_F_PRIVACY) { |
690 | switch (ic->ic_nw_keys[ic->ic_def_txkey].wk_keylen) { | | 690 | switch (ic->ic_nw_keys[ic->ic_def_txkey].wk_keylen) { |
691 | case 5: | | 691 | case 5: |
692 | cmd.EncryptionType = ATU_WEP_40BITS; | | 692 | cmd.EncryptionType = ATU_WEP_40BITS; |
693 | break; | | 693 | break; |
694 | case 13: | | 694 | case 13: |
695 | cmd.EncryptionType = ATU_WEP_104BITS; | | 695 | cmd.EncryptionType = ATU_WEP_104BITS; |
696 | break; | | 696 | break; |
697 | default: | | 697 | default: |
698 | cmd.EncryptionType = ATU_WEP_OFF; | | 698 | cmd.EncryptionType = ATU_WEP_OFF; |
699 | break; | | 699 | break; |
700 | } | | 700 | } |
701 | | | 701 | |
702 | | | 702 | |
703 | cmd.WEP_DefaultKeyID = ic->ic_def_txkey; | | 703 | cmd.WEP_DefaultKeyID = ic->ic_def_txkey; |
704 | for (i = 0; i < IEEE80211_WEP_NKID; i++) { | | 704 | for (i = 0; i < IEEE80211_WEP_NKID; i++) { |
705 | memcpy(cmd.WEP_DefaultKey[i], ic->ic_nw_keys[i].wk_key, | | 705 | memcpy(cmd.WEP_DefaultKey[i], ic->ic_nw_keys[i].wk_key, |
706 | ic->ic_nw_keys[i].wk_keylen); | | 706 | ic->ic_nw_keys[i].wk_keylen); |
707 | } | | 707 | } |
708 | } | | 708 | } |
709 | | | 709 | |
710 | /* Setting the SSID here doesn't seem to do anything */ | | 710 | /* Setting the SSID here doesn't seem to do anything */ |
711 | memset(cmd.SSID, 0x00, sizeof(cmd.SSID)); | | 711 | memset(cmd.SSID, 0x00, sizeof(cmd.SSID)); |
712 | memcpy(cmd.SSID, ic->ic_des_essid, ic->ic_des_esslen); | | 712 | memcpy(cmd.SSID, ic->ic_des_essid, ic->ic_des_esslen); |
713 | cmd.SSID_Len = ic->ic_des_esslen; | | 713 | cmd.SSID_Len = ic->ic_des_esslen; |
714 | | | 714 | |
715 | cmd.ShortPreamble = 0; | | 715 | cmd.ShortPreamble = 0; |
716 | USETW(cmd.BeaconPeriod, 100); | | 716 | USETW(cmd.BeaconPeriod, 100); |
717 | /* cmd.BeaconPeriod = 65535; */ | | 717 | /* cmd.BeaconPeriod = 65535; */ |
718 | | | 718 | |
719 | /* | | 719 | /* |
720 | * TODO: | | 720 | * TODO: |
721 | * read reg domain MIB_PHY @ 0x17 (1 byte), (reply = 0x30) | | 721 | * read reg domain MIB_PHY @ 0x17 (1 byte), (reply = 0x30) |
722 | * we should do something useful with this info. right now it's just | | 722 | * we should do something useful with this info. right now it's just |
723 | * ignored | | 723 | * ignored |
724 | */ | | 724 | */ |
725 | err = atu_get_mib(sc, MIB_PHY__REG_DOMAIN, ®_domain); | | 725 | err = atu_get_mib(sc, MIB_PHY__REG_DOMAIN, ®_domain); |
726 | if (err) { | | 726 | if (err) { |
727 | DPRINTF(("%s: could not get regdomain!\n", | | 727 | DPRINTF(("%s: could not get regdomain!\n", |
728 | device_xname(sc->atu_dev))); | | 728 | device_xname(sc->atu_dev))); |
729 | } else { | | 729 | } else { |
730 | DPRINTF(("%s: in reg domain 0x%x according to the " | | 730 | DPRINTF(("%s: in reg domain 0x%x according to the " |
731 | "adapter\n", device_xname(sc->atu_dev), reg_domain)); | | 731 | "adapter\n", device_xname(sc->atu_dev), reg_domain)); |
732 | } | | 732 | } |
733 | | | 733 | |
734 | #ifdef ATU_DEBUG | | 734 | #ifdef ATU_DEBUG |
735 | if (atudebug) { | | 735 | if (atudebug) { |
736 | DPRINTFN(20, ("%s: configlen=%02zx\n", device_xname(sc->atu_dev), | | 736 | DPRINTFN(20, ("%s: configlen=%02zx\n", device_xname(sc->atu_dev), |
737 | sizeof(cmd))); | | 737 | sizeof(cmd))); |
738 | } | | 738 | } |
739 | #endif /* ATU_DEBUG */ | | 739 | #endif /* ATU_DEBUG */ |
740 | | | 740 | |
741 | /* Windoze : driver says exclude-unencrypted=1 & encr-type=1 */ | | 741 | /* Windoze : driver says exclude-unencrypted=1 & encr-type=1 */ |
742 | | | 742 | |
743 | err = atu_send_command(sc, (uint8_t *)&cmd, sizeof(cmd)); | | 743 | err = atu_send_command(sc, (uint8_t *)&cmd, sizeof(cmd)); |
744 | if (err) | | 744 | if (err) |
745 | return err; | | 745 | return err; |
746 | err = atu_wait_completion(sc, CMD_STARTUP, NULL); | | 746 | err = atu_wait_completion(sc, CMD_STARTUP, NULL); |
747 | if (err) | | 747 | if (err) |
748 | return err; | | 748 | return err; |
749 | | | 749 | |
750 | /* Turn on radio now */ | | 750 | /* Turn on radio now */ |
751 | err = atu_switch_radio(sc, 1); | | 751 | err = atu_switch_radio(sc, 1); |
752 | if (err) | | 752 | if (err) |
753 | return err; | | 753 | return err; |
754 | | | 754 | |
755 | /* preamble type = short */ | | 755 | /* preamble type = short */ |
756 | err = atu_send_mib(sc, MIB_LOCAL__PREAMBLE, NR(PREAMBLE_SHORT)); | | 756 | err = atu_send_mib(sc, MIB_LOCAL__PREAMBLE, NR(PREAMBLE_SHORT)); |
757 | if (err) | | 757 | if (err) |
758 | return err; | | 758 | return err; |
759 | | | 759 | |
760 | /* frag = 1536 */ | | 760 | /* frag = 1536 */ |
761 | err = atu_send_mib(sc, MIB_MAC__FRAG, NR(2346)); | | 761 | err = atu_send_mib(sc, MIB_MAC__FRAG, NR(2346)); |
762 | if (err) | | 762 | if (err) |
763 | return err; | | 763 | return err; |
764 | | | 764 | |
765 | /* rts = 1536 */ | | 765 | /* rts = 1536 */ |
766 | err = atu_send_mib(sc, MIB_MAC__RTS, NR(2347)); | | 766 | err = atu_send_mib(sc, MIB_MAC__RTS, NR(2347)); |
767 | if (err) | | 767 | if (err) |
768 | return err; | | 768 | return err; |
769 | | | 769 | |
770 | /* auto rate fallback = 1 */ | | 770 | /* auto rate fallback = 1 */ |
771 | err = atu_send_mib(sc, MIB_LOCAL__AUTO_RATE_FALLBACK, NR(1)); | | 771 | err = atu_send_mib(sc, MIB_LOCAL__AUTO_RATE_FALLBACK, NR(1)); |
772 | if (err) | | 772 | if (err) |
773 | return err; | | 773 | return err; |
774 | | | 774 | |
775 | /* power mode = full on, no power saving */ | | 775 | /* power mode = full on, no power saving */ |
776 | err = atu_send_mib(sc, MIB_MAC_MGMT__POWER_MODE, | | 776 | err = atu_send_mib(sc, MIB_MAC_MGMT__POWER_MODE, |
777 | NR(POWER_MODE_ACTIVE)); | | 777 | NR(POWER_MODE_ACTIVE)); |
778 | if (err) | | 778 | if (err) |
779 | return err; | | 779 | return err; |
780 | | | 780 | |
781 | DPRINTFN(10, ("%s: completed initial config\n", | | 781 | DPRINTFN(10, ("%s: completed initial config\n", |
782 | device_xname(sc->atu_dev))); | | 782 | device_xname(sc->atu_dev))); |
783 | return 0; | | 783 | return 0; |
784 | } | | 784 | } |
785 | | | 785 | |
786 | int | | 786 | int |
787 | atu_join(struct atu_softc *sc, struct ieee80211_node *node) | | 787 | atu_join(struct atu_softc *sc, struct ieee80211_node *node) |
788 | { | | 788 | { |
789 | struct atu_cmd_join join; | | 789 | struct atu_cmd_join join; |
790 | uint8_t status = 0; /* XXX: GCC */ | | 790 | uint8_t status = 0; /* XXX: GCC */ |
791 | usbd_status err; | | 791 | usbd_status err; |
792 | | | 792 | |
793 | memset(&join, 0, sizeof(join)); | | 793 | memset(&join, 0, sizeof(join)); |
794 | | | 794 | |
795 | join.Cmd = CMD_JOIN; | | 795 | join.Cmd = CMD_JOIN; |
796 | join.Reserved = 0x00; | | 796 | join.Reserved = 0x00; |
797 | USETW(join.Size, sizeof(join) - 4); | | 797 | USETW(join.Size, sizeof(join) - 4); |
798 | | | 798 | |
799 | DPRINTFN(15, ("%s: pre-join sc->atu_bssid=%s\n", | | 799 | DPRINTFN(15, ("%s: pre-join sc->atu_bssid=%s\n", |
800 | device_xname(sc->atu_dev), ether_sprintf(sc->atu_bssid))); | | 800 | device_xname(sc->atu_dev), ether_sprintf(sc->atu_bssid))); |
801 | DPRINTFN(15, ("%s: mode=%d\n", device_xname(sc->atu_dev), | | 801 | DPRINTFN(15, ("%s: mode=%d\n", device_xname(sc->atu_dev), |
802 | sc->atu_mode)); | | 802 | sc->atu_mode)); |
803 | memcpy(join.bssid, node->ni_bssid, IEEE80211_ADDR_LEN); | | 803 | memcpy(join.bssid, node->ni_bssid, IEEE80211_ADDR_LEN); |
804 | memset(join.essid, 0x00, 32); | | 804 | memset(join.essid, 0x00, 32); |
805 | memcpy(join.essid, node->ni_essid, node->ni_esslen); | | 805 | memcpy(join.essid, node->ni_essid, node->ni_esslen); |
806 | join.essid_size = node->ni_esslen; | | 806 | join.essid_size = node->ni_esslen; |
807 | if (node->ni_capinfo & IEEE80211_CAPINFO_IBSS) | | 807 | if (node->ni_capinfo & IEEE80211_CAPINFO_IBSS) |
808 | join.bss_type = AD_HOC_MODE; | | 808 | join.bss_type = AD_HOC_MODE; |
809 | else | | 809 | else |
810 | join.bss_type = INFRASTRUCTURE_MODE; | | 810 | join.bss_type = INFRASTRUCTURE_MODE; |
811 | join.channel = ieee80211_chan2ieee(&sc->sc_ic, node->ni_chan); | | 811 | join.channel = ieee80211_chan2ieee(&sc->sc_ic, node->ni_chan); |
812 | | | 812 | |
813 | USETW(join.timeout, ATU_JOIN_TIMEOUT); | | 813 | USETW(join.timeout, ATU_JOIN_TIMEOUT); |
814 | join.reserved = 0x00; | | 814 | join.reserved = 0x00; |
815 | | | 815 | |
816 | DPRINTFN(10, ("%s: trying to join BSSID=%s\n", | | 816 | DPRINTFN(10, ("%s: trying to join BSSID=%s\n", |
817 | device_xname(sc->atu_dev), ether_sprintf(join.bssid))); | | 817 | device_xname(sc->atu_dev), ether_sprintf(join.bssid))); |
818 | err = atu_send_command(sc, (uint8_t *)&join, sizeof(join)); | | 818 | err = atu_send_command(sc, (uint8_t *)&join, sizeof(join)); |
819 | if (err) { | | 819 | if (err) { |
820 | DPRINTF(("%s: ERROR trying to join IBSS\n", | | 820 | DPRINTF(("%s: ERROR trying to join IBSS\n", |
821 | device_xname(sc->atu_dev))); | | 821 | device_xname(sc->atu_dev))); |
822 | return err; | | 822 | return err; |
823 | } | | 823 | } |
824 | err = atu_wait_completion(sc, CMD_JOIN, &status); | | 824 | err = atu_wait_completion(sc, CMD_JOIN, &status); |
825 | if (err) { | | 825 | if (err) { |
826 | DPRINTF(("%s: error joining BSS!\n", | | 826 | DPRINTF(("%s: error joining BSS!\n", |
827 | device_xname(sc->atu_dev))); | | 827 | device_xname(sc->atu_dev))); |
828 | return err; | | 828 | return err; |
829 | } | | 829 | } |
830 | if (status != STATUS_COMPLETE) { | | 830 | if (status != STATUS_COMPLETE) { |
831 | DPRINTF(("%s: error joining... [status=%02x]\n", | | 831 | DPRINTF(("%s: error joining... [status=%02x]\n", |
832 | device_xname(sc->atu_dev), status)); | | 832 | device_xname(sc->atu_dev), status)); |
833 | return status; | | 833 | return status; |
834 | } else { | | 834 | } else { |
835 | DPRINTFN(10, ("%s: joined BSS\n", device_xname(sc->atu_dev))); | | 835 | DPRINTFN(10, ("%s: joined BSS\n", device_xname(sc->atu_dev))); |
836 | } | | 836 | } |
837 | return err; | | 837 | return err; |
838 | } | | 838 | } |
839 | | | 839 | |
840 | /* | | 840 | /* |
841 | * Get the state of the DFU unit | | 841 | * Get the state of the DFU unit |
842 | */ | | 842 | */ |
843 | int8_t | | 843 | int8_t |
844 | atu_get_dfu_state(struct atu_softc *sc) | | 844 | atu_get_dfu_state(struct atu_softc *sc) |
845 | { | | 845 | { |
846 | uint8_t state; | | 846 | uint8_t state; |
847 | | | 847 | |
848 | if (atu_usb_request(sc, DFU_GETSTATE, 0, 0, 1, &state)) | | 848 | if (atu_usb_request(sc, DFU_GETSTATE, 0, 0, 1, &state)) |
849 | return -1; | | 849 | return -1; |
850 | return state; | | 850 | return state; |
851 | } | | 851 | } |
852 | | | 852 | |
853 | /* | | 853 | /* |
854 | * Get MAC opmode | | 854 | * Get MAC opmode |
855 | */ | | 855 | */ |
856 | uint8_t | | 856 | uint8_t |
857 | atu_get_opmode(struct atu_softc *sc, uint8_t *mode) | | 857 | atu_get_opmode(struct atu_softc *sc, uint8_t *mode) |
858 | { | | 858 | { |
859 | | | 859 | |
860 | return atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x33, 0x0001, | | 860 | return atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x33, 0x0001, |
861 | 0x0000, 1, mode); | | 861 | 0x0000, 1, mode); |
862 | } | | 862 | } |
863 | | | 863 | |
864 | /* | | 864 | /* |
865 | * Upload the internal firmware into the device | | 865 | * Upload the internal firmware into the device |
866 | */ | | 866 | */ |
867 | void | | 867 | void |
868 | atu_internal_firmware(device_t arg) | | 868 | atu_internal_firmware(device_t arg) |
869 | { | | 869 | { |
870 | struct atu_softc *sc = device_private(arg); | | 870 | struct atu_softc *sc = device_private(arg); |
871 | u_char state, *ptr = NULL, *firm = NULL, status[6]; | | 871 | u_char state, *ptr = NULL, *firm = NULL, status[6]; |
872 | int block_size, block = 0, err, i; | | 872 | int block_size, block = 0, err, i; |
873 | size_t bytes_left = 0; | | 873 | size_t bytes_left = 0; |
874 | | | 874 | |
875 | /* | | 875 | /* |
876 | * Uploading firmware is done with the DFU (Device Firmware Upgrade) | | 876 | * Uploading firmware is done with the DFU (Device Firmware Upgrade) |
877 | * interface. See "Universal Serial Bus - Device Class Specification | | 877 | * interface. See "Universal Serial Bus - Device Class Specification |
878 | * for Device Firmware Upgrade" pdf for details of the protocol. | | 878 | * for Device Firmware Upgrade" pdf for details of the protocol. |
879 | * Maybe this could be moved to a separate 'firmware driver' once more | | 879 | * Maybe this could be moved to a separate 'firmware driver' once more |
880 | * device drivers need it... For now we'll just do it here. | | 880 | * device drivers need it... For now we'll just do it here. |
881 | * | | 881 | * |
882 | * Just for your information, the Atmel's DFU descriptor looks like | | 882 | * Just for your information, the Atmel's DFU descriptor looks like |
883 | * this: | | 883 | * this: |
884 | * | | 884 | * |
885 | * 07 size | | 885 | * 07 size |
886 | * 21 type | | 886 | * 21 type |
887 | * 01 capabilities : only firmware download, need reset | | 887 | * 01 capabilities : only firmware download, need reset |
888 | * after download | | 888 | * after download |
889 | * 13 05 detach timeout : max 1299ms between DFU_DETACH and | | 889 | * 13 05 detach timeout : max 1299ms between DFU_DETACH and |
890 | * reset | | 890 | * reset |
891 | * 00 04 max bytes of firmware per transaction : 1024 | | 891 | * 00 04 max bytes of firmware per transaction : 1024 |
892 | */ | | 892 | */ |
893 | | | 893 | |
894 | /* Choose the right firmware for the device */ | | 894 | /* Choose the right firmware for the device */ |
895 | for (i = 0; i < __arraycount(atu_radfirm); i++) | | 895 | for (i = 0; i < __arraycount(atu_radfirm); i++) |
896 | if (sc->atu_radio == atu_radfirm[i].atur_type) { | | 896 | if (sc->atu_radio == atu_radfirm[i].atur_type) { |
897 | firm = atu_radfirm[i].atur_internal; | | 897 | firm = atu_radfirm[i].atur_internal; |
898 | bytes_left = atu_radfirm[i].atur_internal_sz; | | 898 | bytes_left = atu_radfirm[i].atur_internal_sz; |
899 | } | | 899 | } |
900 | | | 900 | |
901 | if (firm == NULL) { | | 901 | if (firm == NULL) { |
902 | aprint_error_dev(arg, "no firmware found\n"); | | 902 | aprint_error_dev(arg, "no firmware found\n"); |
903 | return; | | 903 | return; |
904 | } | | 904 | } |
905 | | | 905 | |
906 | ptr = firm; | | 906 | ptr = firm; |
907 | state = atu_get_dfu_state(sc); | | 907 | state = atu_get_dfu_state(sc); |
908 | | | 908 | |
909 | while (block >= 0 && state > 0) { | | 909 | while (block >= 0 && state > 0) { |
910 | switch (state) { | | 910 | switch (state) { |
911 | case DFUState_DnLoadSync: | | 911 | case DFUState_DnLoadSync: |
912 | /* get DFU status */ | | 912 | /* get DFU status */ |
913 | err = atu_usb_request(sc, DFU_GETSTATUS, 0, 0 , 6, | | 913 | err = atu_usb_request(sc, DFU_GETSTATUS, 0, 0 , 6, |
914 | status); | | 914 | status); |
915 | if (err) { | | 915 | if (err) { |
916 | DPRINTF(("%s: dfu_getstatus failed!\n", | | 916 | DPRINTF(("%s: dfu_getstatus failed!\n", |
917 | device_xname(sc->atu_dev))); | | 917 | device_xname(sc->atu_dev))); |
918 | return; | | 918 | return; |
919 | } | | 919 | } |
920 | /* success means state => DnLoadIdle */ | | 920 | /* success means state => DnLoadIdle */ |
921 | state = DFUState_DnLoadIdle; | | 921 | state = DFUState_DnLoadIdle; |
922 | continue; | | 922 | continue; |
923 | break; | | 923 | break; |
924 | | | 924 | |
925 | case DFUState_DFUIdle: | | 925 | case DFUState_DFUIdle: |
926 | case DFUState_DnLoadIdle: | | 926 | case DFUState_DnLoadIdle: |
927 | if (bytes_left>=DFU_MaxBlockSize) | | 927 | if (bytes_left>=DFU_MaxBlockSize) |
928 | block_size = DFU_MaxBlockSize; | | 928 | block_size = DFU_MaxBlockSize; |
929 | else | | 929 | else |
930 | block_size = bytes_left; | | 930 | block_size = bytes_left; |
931 | DPRINTFN(15, ("%s: firmware block %d\n", | | 931 | DPRINTFN(15, ("%s: firmware block %d\n", |
932 | device_xname(sc->atu_dev), block)); | | 932 | device_xname(sc->atu_dev), block)); |
933 | | | 933 | |
934 | err = atu_usb_request(sc, DFU_DNLOAD, block++, 0, | | 934 | err = atu_usb_request(sc, DFU_DNLOAD, block++, 0, |
935 | block_size, ptr); | | 935 | block_size, ptr); |
936 | if (err) { | | 936 | if (err) { |
937 | DPRINTF(("%s: dfu_dnload failed\n", | | 937 | DPRINTF(("%s: dfu_dnload failed\n", |
938 | device_xname(sc->atu_dev))); | | 938 | device_xname(sc->atu_dev))); |
939 | return; | | 939 | return; |
940 | } | | 940 | } |
941 | | | 941 | |
942 | ptr += block_size; | | 942 | ptr += block_size; |
943 | bytes_left -= block_size; | | 943 | bytes_left -= block_size; |
944 | if (block_size == 0) | | 944 | if (block_size == 0) |
945 | block = -1; | | 945 | block = -1; |
946 | break; | | 946 | break; |
947 | | | 947 | |
948 | default: | | 948 | default: |
949 | usbd_delay_ms(sc->atu_udev, 100); | | 949 | usbd_delay_ms(sc->atu_udev, 100); |
950 | DPRINTFN(20, ("%s: sleeping for a while\n", | | 950 | DPRINTFN(20, ("%s: sleeping for a while\n", |
951 | device_xname(sc->atu_dev))); | | 951 | device_xname(sc->atu_dev))); |
952 | break; | | 952 | break; |
953 | } | | 953 | } |
954 | | | 954 | |
955 | state = atu_get_dfu_state(sc); | | 955 | state = atu_get_dfu_state(sc); |
956 | } | | 956 | } |
957 | | | 957 | |
958 | if (state != DFUState_ManifestSync) { | | 958 | if (state != DFUState_ManifestSync) { |
959 | DPRINTF(("%s: state != manifestsync... eek!\n", | | 959 | DPRINTF(("%s: state != manifestsync... eek!\n", |
960 | device_xname(sc->atu_dev))); | | 960 | device_xname(sc->atu_dev))); |
961 | } | | 961 | } |
962 | | | 962 | |
963 | err = atu_usb_request(sc, DFU_GETSTATUS, 0, 0, 6, status); | | 963 | err = atu_usb_request(sc, DFU_GETSTATUS, 0, 0, 6, status); |
964 | if (err) { | | 964 | if (err) { |
965 | DPRINTF(("%s: dfu_getstatus failed!\n", | | 965 | DPRINTF(("%s: dfu_getstatus failed!\n", |
966 | device_xname(sc->atu_dev))); | | 966 | device_xname(sc->atu_dev))); |
967 | return; | | 967 | return; |
968 | } | | 968 | } |
969 | | | 969 | |
970 | DPRINTFN(15, ("%s: sending remap\n", device_xname(sc->atu_dev))); | | 970 | DPRINTFN(15, ("%s: sending remap\n", device_xname(sc->atu_dev))); |
971 | err = atu_usb_request(sc, DFU_REMAP, 0, 0, 0, NULL); | | 971 | err = atu_usb_request(sc, DFU_REMAP, 0, 0, 0, NULL); |
972 | if ((err) && !(sc->atu_quirk & ATU_QUIRK_NO_REMAP)) { | | 972 | if ((err) && !(sc->atu_quirk & ATU_QUIRK_NO_REMAP)) { |
973 | DPRINTF(("%s: remap failed!\n", device_xname(sc->atu_dev))); | | 973 | DPRINTF(("%s: remap failed!\n", device_xname(sc->atu_dev))); |
974 | return; | | 974 | return; |
975 | } | | 975 | } |
976 | | | 976 | |
977 | /* after a lot of trying and measuring I found out the device needs | | 977 | /* after a lot of trying and measuring I found out the device needs |
978 | * about 56 miliseconds after sending the remap command before | | 978 | * about 56 miliseconds after sending the remap command before |
979 | * it's ready to communicate again. So we'll wait just a little bit | | 979 | * it's ready to communicate again. So we'll wait just a little bit |
980 | * longer than that to be sure... | | 980 | * longer than that to be sure... |
981 | */ | | 981 | */ |
982 | usbd_delay_ms(sc->atu_udev, 56+100); | | 982 | usbd_delay_ms(sc->atu_udev, 56+100); |
983 | | | 983 | |
984 | aprint_error_dev(arg, "reattaching after firmware upload\n"); | | 984 | aprint_error_dev(arg, "reattaching after firmware upload\n"); |
985 | usb_needs_reattach(sc->atu_udev); | | 985 | usb_needs_reattach(sc->atu_udev); |
986 | } | | 986 | } |
987 | | | 987 | |
988 | void | | 988 | void |
989 | atu_external_firmware(device_t arg) | | 989 | atu_external_firmware(device_t arg) |
990 | { | | 990 | { |
991 | struct atu_softc *sc = device_private(arg); | | 991 | struct atu_softc *sc = device_private(arg); |
992 | u_char *ptr = NULL, *firm = NULL; | | 992 | u_char *ptr = NULL, *firm = NULL; |
993 | int block_size, block = 0, err, i; | | 993 | int block_size, block = 0, err, i; |
994 | size_t bytes_left = 0; | | 994 | size_t bytes_left = 0; |
995 | | | 995 | |
996 | for (i = 0; i < __arraycount(atu_radfirm); i++) | | 996 | for (i = 0; i < __arraycount(atu_radfirm); i++) |
997 | if (sc->atu_radio == atu_radfirm[i].atur_type) { | | 997 | if (sc->atu_radio == atu_radfirm[i].atur_type) { |
998 | firm = atu_radfirm[i].atur_external; | | 998 | firm = atu_radfirm[i].atur_external; |
999 | bytes_left = atu_radfirm[i].atur_external_sz; | | 999 | bytes_left = atu_radfirm[i].atur_external_sz; |
1000 | } | | 1000 | } |
1001 | | | 1001 | |
1002 | if (firm == NULL) { | | 1002 | if (firm == NULL) { |
1003 | aprint_error_dev(arg, "no firmware found\n"); | | 1003 | aprint_error_dev(arg, "no firmware found\n"); |
1004 | return; | | 1004 | return; |
1005 | } | | 1005 | } |
1006 | ptr = firm; | | 1006 | ptr = firm; |
1007 | | | 1007 | |
1008 | while (bytes_left) { | | 1008 | while (bytes_left) { |
1009 | if (bytes_left > 1024) | | 1009 | if (bytes_left > 1024) |
1010 | block_size = 1024; | | 1010 | block_size = 1024; |
1011 | else | | 1011 | else |
1012 | block_size = bytes_left; | | 1012 | block_size = bytes_left; |
1013 | | | 1013 | |
1014 | DPRINTFN(15, ("%s: block:%d size:%d\n", | | 1014 | DPRINTFN(15, ("%s: block:%d size:%d\n", |
1015 | device_xname(sc->atu_dev), block, block_size)); | | 1015 | device_xname(sc->atu_dev), block, block_size)); |
1016 | err = atu_usb_request(sc, UT_WRITE_VENDOR_DEVICE, 0x0e, | | 1016 | err = atu_usb_request(sc, UT_WRITE_VENDOR_DEVICE, 0x0e, |
1017 | 0x0802, block, block_size, ptr); | | 1017 | 0x0802, block, block_size, ptr); |
1018 | if (err) { | | 1018 | if (err) { |
1019 | DPRINTF(("%s: could not load external firmware " | | 1019 | DPRINTF(("%s: could not load external firmware " |
1020 | "block\n", device_xname(sc->atu_dev))); | | 1020 | "block\n", device_xname(sc->atu_dev))); |
1021 | return; | | 1021 | return; |
1022 | } | | 1022 | } |
1023 | | | 1023 | |
1024 | ptr += block_size; | | 1024 | ptr += block_size; |
1025 | block++; | | 1025 | block++; |
1026 | bytes_left -= block_size; | | 1026 | bytes_left -= block_size; |
1027 | } | | 1027 | } |
1028 | | | 1028 | |
1029 | err = atu_usb_request(sc, UT_WRITE_VENDOR_DEVICE, 0x0e, 0x0802, | | 1029 | err = atu_usb_request(sc, UT_WRITE_VENDOR_DEVICE, 0x0e, 0x0802, |
1030 | block, 0, NULL); | | 1030 | block, 0, NULL); |
1031 | if (err) { | | 1031 | if (err) { |
1032 | DPRINTF(("%s: could not load last zero-length firmware " | | 1032 | DPRINTF(("%s: could not load last zero-length firmware " |
1033 | "block\n", device_xname(sc->atu_dev))); | | 1033 | "block\n", device_xname(sc->atu_dev))); |
1034 | return; | | 1034 | return; |
1035 | } | | 1035 | } |
1036 | | | 1036 | |
1037 | /* | | 1037 | /* |
1038 | * The SMC2662w V.4 seems to require some time to do its thing with | | 1038 | * The SMC2662w V.4 seems to require some time to do its thing with |
1039 | * the external firmware... 20 ms isn't enough, but 21 ms works 100 | | 1039 | * the external firmware... 20 ms isn't enough, but 21 ms works 100 |
1040 | * times out of 100 tries. We'll wait a bit longer just to be sure | | 1040 | * times out of 100 tries. We'll wait a bit longer just to be sure |
1041 | */ | | 1041 | */ |
1042 | if (sc->atu_quirk & ATU_QUIRK_FW_DELAY) | | 1042 | if (sc->atu_quirk & ATU_QUIRK_FW_DELAY) |
1043 | usbd_delay_ms(sc->atu_udev, 21 + 100); | | 1043 | usbd_delay_ms(sc->atu_udev, 21 + 100); |
1044 | | | 1044 | |
1045 | DPRINTFN(10, ("%s: external firmware upload done\n", | | 1045 | DPRINTFN(10, ("%s: external firmware upload done\n", |
1046 | device_xname(sc->atu_dev))); | | 1046 | device_xname(sc->atu_dev))); |
1047 | /* complete configuration after the firmwares have been uploaded */ | | 1047 | /* complete configuration after the firmwares have been uploaded */ |
1048 | atu_complete_attach(sc); | | 1048 | atu_complete_attach(sc); |
1049 | } | | 1049 | } |
1050 | | | 1050 | |
1051 | int | | 1051 | int |
1052 | atu_get_card_config(struct atu_softc *sc) | | 1052 | atu_get_card_config(struct atu_softc *sc) |
1053 | { | | 1053 | { |
1054 | struct ieee80211com *ic = &sc->sc_ic; | | 1054 | struct ieee80211com *ic = &sc->sc_ic; |
1055 | struct atu_rfmd_conf rfmd_conf; | | 1055 | struct atu_rfmd_conf rfmd_conf; |
1056 | struct atu_intersil_conf intersil_conf; | | 1056 | struct atu_intersil_conf intersil_conf; |
1057 | int err; | | 1057 | int err; |
1058 | | | 1058 | |
1059 | switch (sc->atu_radio) { | | 1059 | switch (sc->atu_radio) { |
1060 | | | 1060 | |
1061 | case RadioRFMD: | | 1061 | case RadioRFMD: |
1062 | case RadioRFMD2958: | | 1062 | case RadioRFMD2958: |
1063 | case RadioRFMD2958_SMC: | | 1063 | case RadioRFMD2958_SMC: |
1064 | case AT76C503_rfmd_acc: | | 1064 | case AT76C503_rfmd_acc: |
1065 | case AT76C505_rfmd: | | 1065 | case AT76C505_rfmd: |
1066 | err = atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x33, | | 1066 | err = atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x33, |
1067 | 0x0a02, 0x0000, sizeof(rfmd_conf), | | 1067 | 0x0a02, 0x0000, sizeof(rfmd_conf), |
1068 | (uint8_t *)&rfmd_conf); | | 1068 | (uint8_t *)&rfmd_conf); |
1069 | if (err) { | | 1069 | if (err) { |
1070 | DPRINTF(("%s: could not get rfmd config!\n", | | 1070 | DPRINTF(("%s: could not get rfmd config!\n", |
1071 | device_xname(sc->atu_dev))); | | 1071 | device_xname(sc->atu_dev))); |
1072 | return err; | | 1072 | return err; |
1073 | } | | 1073 | } |
1074 | memcpy(ic->ic_myaddr, rfmd_conf.MACAddr, IEEE80211_ADDR_LEN); | | 1074 | memcpy(ic->ic_myaddr, rfmd_conf.MACAddr, IEEE80211_ADDR_LEN); |
1075 | break; | | 1075 | break; |
1076 | | | 1076 | |
1077 | case RadioIntersil: | | 1077 | case RadioIntersil: |
1078 | case AT76C503_i3863: | | 1078 | case AT76C503_i3863: |
1079 | err = atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x33, | | 1079 | err = atu_usb_request(sc, UT_READ_VENDOR_INTERFACE, 0x33, |
1080 | 0x0902, 0x0000, sizeof(intersil_conf), | | 1080 | 0x0902, 0x0000, sizeof(intersil_conf), |
1081 | (uint8_t *)&intersil_conf); | | 1081 | (uint8_t *)&intersil_conf); |
1082 | if (err) { | | 1082 | if (err) { |
1083 | DPRINTF(("%s: could not get intersil config!\n", | | 1083 | DPRINTF(("%s: could not get intersil config!\n", |
1084 | device_xname(sc->atu_dev))); | | 1084 | device_xname(sc->atu_dev))); |
1085 | return err; | | 1085 | return err; |
1086 | } | | 1086 | } |
1087 | memcpy(ic->ic_myaddr, intersil_conf.MACAddr, | | 1087 | memcpy(ic->ic_myaddr, intersil_conf.MACAddr, |
1088 | IEEE80211_ADDR_LEN); | | 1088 | IEEE80211_ADDR_LEN); |
1089 | break; | | 1089 | break; |
1090 | } | | 1090 | } |
1091 | return 0; | | 1091 | return 0; |
1092 | } | | 1092 | } |
1093 | | | 1093 | |
1094 | /* | | 1094 | /* |
1095 | * Probe for an AT76c503 chip. | | 1095 | * Probe for an AT76c503 chip. |
1096 | */ | | 1096 | */ |
1097 | int | | 1097 | int |
1098 | atu_match(device_t parent, cfdata_t match, void *aux) | | 1098 | atu_match(device_t parent, cfdata_t match, void *aux) |
1099 | { | | 1099 | { |
1100 | struct usb_attach_arg *uaa = aux; | | 1100 | struct usb_attach_arg *uaa = aux; |
1101 | int i; | | 1101 | int i; |
1102 | | | 1102 | |
1103 | for (i = 0; i < __arraycount(atu_devs); i++) { | | 1103 | for (i = 0; i < __arraycount(atu_devs); i++) { |
1104 | struct atu_type *t = &atu_devs[i]; | | 1104 | const struct atu_type *t = &atu_devs[i]; |
1105 | | | 1105 | |
1106 | if (uaa->uaa_vendor == t->atu_vid && | | 1106 | if (uaa->uaa_vendor == t->atu_vid && |
1107 | uaa->uaa_product == t->atu_pid) { | | 1107 | uaa->uaa_product == t->atu_pid) { |
1108 | return(UMATCH_VENDOR_PRODUCT); | | 1108 | return(UMATCH_VENDOR_PRODUCT); |
1109 | } | | 1109 | } |
1110 | } | | 1110 | } |
1111 | return(UMATCH_NONE); | | 1111 | return(UMATCH_NONE); |
1112 | } | | 1112 | } |
1113 | | | 1113 | |
1114 | int | | 1114 | int |
1115 | atu_media_change(struct ifnet *ifp) | | 1115 | atu_media_change(struct ifnet *ifp) |
1116 | { | | 1116 | { |
1117 | struct atu_softc *sc = ifp->if_softc; | | 1117 | struct atu_softc *sc = ifp->if_softc; |
1118 | struct ieee80211com *ic = &sc->sc_ic; | | 1118 | struct ieee80211com *ic = &sc->sc_ic; |
1119 | int err, s; | | 1119 | int err, s; |
1120 | | | 1120 | |
1121 | DPRINTFN(10, ("%s: atu_media_change\n", device_xname(sc->atu_dev))); | | 1121 | DPRINTFN(10, ("%s: atu_media_change\n", device_xname(sc->atu_dev))); |
1122 | | | 1122 | |
1123 | err = ieee80211_media_change(ifp); | | 1123 | err = ieee80211_media_change(ifp); |
1124 | if (err == ENETRESET) { | | 1124 | if (err == ENETRESET) { |
1125 | if ((ifp->if_flags & (IFF_RUNNING|IFF_UP)) == | | 1125 | if ((ifp->if_flags & (IFF_RUNNING|IFF_UP)) == |
1126 | (IFF_RUNNING|IFF_UP)) { | | 1126 | (IFF_RUNNING|IFF_UP)) { |
1127 | s = splnet(); | | 1127 | s = splnet(); |
1128 | ieee80211_new_state(ic, IEEE80211_S_INIT, -1); | | 1128 | ieee80211_new_state(ic, IEEE80211_S_INIT, -1); |
1129 | atu_initial_config(sc); | | 1129 | atu_initial_config(sc); |
1130 | ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); | | 1130 | ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); |
1131 | splx(s); | | 1131 | splx(s); |
1132 | } | | 1132 | } |
1133 | err = 0; | | 1133 | err = 0; |
1134 | } | | 1134 | } |
1135 | | | 1135 | |
1136 | return err; | | 1136 | return err; |
1137 | } | | 1137 | } |
1138 | | | 1138 | |
1139 | void | | 1139 | void |
1140 | atu_media_status(struct ifnet *ifp, struct ifmediareq *req) | | 1140 | atu_media_status(struct ifnet *ifp, struct ifmediareq *req) |
1141 | { | | 1141 | { |
1142 | #ifdef ATU_DEBUG | | 1142 | #ifdef ATU_DEBUG |
1143 | struct atu_softc *sc = ifp->if_softc; | | 1143 | struct atu_softc *sc = ifp->if_softc; |
1144 | #endif /* ATU_DEBUG */ | | 1144 | #endif /* ATU_DEBUG */ |
1145 | | | 1145 | |
1146 | DPRINTFN(10, ("%s: atu_media_status\n", device_xname(sc->atu_dev))); | | 1146 | DPRINTFN(10, ("%s: atu_media_status\n", device_xname(sc->atu_dev))); |
1147 | | | 1147 | |
1148 | ieee80211_media_status(ifp, req); | | 1148 | ieee80211_media_status(ifp, req); |
1149 | } | | 1149 | } |
1150 | | | 1150 | |
1151 | void | | 1151 | void |
1152 | atu_task(void *arg) | | 1152 | atu_task(void *arg) |
1153 | { | | 1153 | { |
1154 | struct atu_softc *sc = (struct atu_softc *)arg; | | 1154 | struct atu_softc *sc = (struct atu_softc *)arg; |
1155 | struct ieee80211com *ic = &sc->sc_ic; | | 1155 | struct ieee80211com *ic = &sc->sc_ic; |
1156 | usbd_status err; | | 1156 | usbd_status err; |
1157 | int s; | | 1157 | int s; |
1158 | | | 1158 | |
1159 | DPRINTFN(10, ("%s: atu_task\n", device_xname(sc->atu_dev))); | | 1159 | DPRINTFN(10, ("%s: atu_task\n", device_xname(sc->atu_dev))); |
1160 | | | 1160 | |
1161 | if (sc->sc_state != ATU_S_OK) | | 1161 | if (sc->sc_state != ATU_S_OK) |
1162 | return; | | 1162 | return; |
1163 | | | 1163 | |
1164 | switch (sc->sc_cmd) { | | 1164 | switch (sc->sc_cmd) { |
1165 | case ATU_C_SCAN: | | 1165 | case ATU_C_SCAN: |
1166 | | | 1166 | |
1167 | err = atu_start_scan(sc); | | 1167 | err = atu_start_scan(sc); |
1168 | if (err) { | | 1168 | if (err) { |
1169 | DPRINTFN(1, ("%s: atu_task: couldn't start scan!\n", | | 1169 | DPRINTFN(1, ("%s: atu_task: couldn't start scan!\n", |
1170 | device_xname(sc->atu_dev))); | | 1170 | device_xname(sc->atu_dev))); |
1171 | return; | | 1171 | return; |
1172 | } | | 1172 | } |
1173 | | | 1173 | |
1174 | err = atu_wait_completion(sc, CMD_START_SCAN, NULL); | | 1174 | err = atu_wait_completion(sc, CMD_START_SCAN, NULL); |
1175 | if (err) { | | 1175 | if (err) { |
1176 | DPRINTF(("%s: atu_task: error waiting for scan\n", | | 1176 | DPRINTF(("%s: atu_task: error waiting for scan\n", |
1177 | device_xname(sc->atu_dev))); | | 1177 | device_xname(sc->atu_dev))); |
1178 | return; | | 1178 | return; |
1179 | } | | 1179 | } |
1180 | | | 1180 | |
1181 | DPRINTF(("%s: ==========================> END OF SCAN!\n", | | 1181 | DPRINTF(("%s: ==========================> END OF SCAN!\n", |
1182 | device_xname(sc->atu_dev))); | | 1182 | device_xname(sc->atu_dev))); |
1183 | | | 1183 | |
1184 | s = splnet(); | | 1184 | s = splnet(); |
1185 | ieee80211_next_scan(ic); | | 1185 | ieee80211_next_scan(ic); |
1186 | splx(s); | | 1186 | splx(s); |
1187 | | | 1187 | |
1188 | DPRINTF(("%s: ----------------------======> END OF SCAN2!\n", | | 1188 | DPRINTF(("%s: ----------------------======> END OF SCAN2!\n", |
1189 | device_xname(sc->atu_dev))); | | 1189 | device_xname(sc->atu_dev))); |
1190 | break; | | 1190 | break; |
1191 | | | 1191 | |
1192 | case ATU_C_JOIN: | | 1192 | case ATU_C_JOIN: |
1193 | atu_join(sc, ic->ic_bss); | | 1193 | atu_join(sc, ic->ic_bss); |
1194 | } | | 1194 | } |
1195 | } | | 1195 | } |
1196 | | | 1196 | |
1197 | int | | 1197 | int |
1198 | atu_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg) | | 1198 | atu_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg) |
1199 | { | | 1199 | { |
1200 | struct ifnet *ifp = ic->ic_ifp; | | 1200 | struct ifnet *ifp = ic->ic_ifp; |
1201 | struct atu_softc *sc = ifp->if_softc; | | 1201 | struct atu_softc *sc = ifp->if_softc; |
1202 | enum ieee80211_state ostate = ic->ic_state; | | 1202 | enum ieee80211_state ostate = ic->ic_state; |
1203 | | | 1203 | |
1204 | DPRINTFN(10, ("%s: atu_newstate: %s -> %s\n", device_xname(sc->atu_dev), | | 1204 | DPRINTFN(10, ("%s: atu_newstate: %s -> %s\n", device_xname(sc->atu_dev), |
1205 | ieee80211_state_name[ostate], ieee80211_state_name[nstate])); | | 1205 | ieee80211_state_name[ostate], ieee80211_state_name[nstate])); |
1206 | | | 1206 | |
1207 | switch (nstate) { | | 1207 | switch (nstate) { |
1208 | case IEEE80211_S_SCAN: | | 1208 | case IEEE80211_S_SCAN: |
1209 | memcpy(ic->ic_chan_scan, ic->ic_chan_active, | | 1209 | memcpy(ic->ic_chan_scan, ic->ic_chan_active, |
1210 | sizeof(ic->ic_chan_active)); | | 1210 | sizeof(ic->ic_chan_active)); |
1211 | ieee80211_node_table_reset(&ic->ic_scan); | | 1211 | ieee80211_node_table_reset(&ic->ic_scan); |
1212 | | | 1212 | |
1213 | /* tell the event thread that we want a scan */ | | 1213 | /* tell the event thread that we want a scan */ |
1214 | sc->sc_cmd = ATU_C_SCAN; | | 1214 | sc->sc_cmd = ATU_C_SCAN; |
1215 | usb_add_task(sc->atu_udev, &sc->sc_task, USB_TASKQ_DRIVER); | | 1215 | usb_add_task(sc->atu_udev, &sc->sc_task, USB_TASKQ_DRIVER); |
1216 | | | 1216 | |
1217 | /* handle this ourselves */ | | 1217 | /* handle this ourselves */ |
1218 | ic->ic_state = nstate; | | 1218 | ic->ic_state = nstate; |
1219 | return 0; | | 1219 | return 0; |
1220 | | | 1220 | |
1221 | case IEEE80211_S_AUTH: | | 1221 | case IEEE80211_S_AUTH: |
1222 | case IEEE80211_S_RUN: | | 1222 | case IEEE80211_S_RUN: |
1223 | if (ostate == IEEE80211_S_SCAN) { | | 1223 | if (ostate == IEEE80211_S_SCAN) { |
1224 | sc->sc_cmd = ATU_C_JOIN; | | 1224 | sc->sc_cmd = ATU_C_JOIN; |
1225 | usb_add_task(sc->atu_udev, &sc->sc_task, | | 1225 | usb_add_task(sc->atu_udev, &sc->sc_task, |
1226 | USB_TASKQ_DRIVER); | | 1226 | USB_TASKQ_DRIVER); |
1227 | } | | 1227 | } |
1228 | break; | | 1228 | break; |
1229 | default: | | 1229 | default: |
1230 | /* nothing to do */ | | 1230 | /* nothing to do */ |
1231 | break; | | 1231 | break; |
1232 | } | | 1232 | } |
1233 | | | 1233 | |
1234 | return (*sc->sc_newstate)(ic, nstate, arg); | | 1234 | return (*sc->sc_newstate)(ic, nstate, arg); |
1235 | } | | 1235 | } |
1236 | | | 1236 | |
1237 | /* | | 1237 | /* |
1238 | * Attach the interface. Allocate softc structures, do | | 1238 | * Attach the interface. Allocate softc structures, do |
1239 | * setup and ethernet/BPF attach. | | 1239 | * setup and ethernet/BPF attach. |
1240 | */ | | 1240 | */ |
1241 | void | | 1241 | void |
1242 | atu_attach(device_t parent, device_t self, void *aux) | | 1242 | atu_attach(device_t parent, device_t self, void *aux) |
1243 | { | | 1243 | { |
1244 | struct atu_softc *sc = device_private(self); | | 1244 | struct atu_softc *sc = device_private(self); |
1245 | struct usb_attach_arg *uaa = aux; | | 1245 | struct usb_attach_arg *uaa = aux; |
1246 | char *devinfop; | | 1246 | char *devinfop; |
1247 | usbd_status err; | | 1247 | usbd_status err; |
1248 | struct usbd_device *dev = uaa->uaa_device; | | 1248 | struct usbd_device *dev = uaa->uaa_device; |
1249 | uint8_t mode, channel; | | 1249 | uint8_t mode, channel; |
1250 | int i; | | 1250 | int i; |
1251 | | | 1251 | |
1252 | sc->atu_dev = self; | | 1252 | sc->atu_dev = self; |
1253 | sc->sc_state = ATU_S_UNCONFIG; | | 1253 | sc->sc_state = ATU_S_UNCONFIG; |
1254 | | | 1254 | |
1255 | aprint_naive("\n"); | | 1255 | aprint_naive("\n"); |
1256 | aprint_normal("\n"); | | 1256 | aprint_normal("\n"); |
1257 | | | 1257 | |
1258 | devinfop = usbd_devinfo_alloc(dev, 0); | | 1258 | devinfop = usbd_devinfo_alloc(dev, 0); |
1259 | aprint_normal_dev(self, "%s\n", devinfop); | | 1259 | aprint_normal_dev(self, "%s\n", devinfop); |
1260 | usbd_devinfo_free(devinfop); | | 1260 | usbd_devinfo_free(devinfop); |
1261 | | | 1261 | |
1262 | err = usbd_set_config_no(dev, ATU_CONFIG_NO, 1); | | 1262 | err = usbd_set_config_no(dev, ATU_CONFIG_NO, 1); |
1263 | if (err) { | | 1263 | if (err) { |
1264 | aprint_error_dev(self, "failed to set configuration" | | 1264 | aprint_error_dev(self, "failed to set configuration" |
1265 | ", err=%s\n", usbd_errstr(err)); | | 1265 | ", err=%s\n", usbd_errstr(err)); |
1266 | return; | | 1266 | return; |
1267 | } | | 1267 | } |
1268 | | | 1268 | |
1269 | err = usbd_device2interface_handle(dev, ATU_IFACE_IDX, &sc->atu_iface); | | 1269 | err = usbd_device2interface_handle(dev, ATU_IFACE_IDX, &sc->atu_iface); |
1270 | if (err) { | | 1270 | if (err) { |
1271 | aprint_error_dev(self, "getting interface handle failed\n"); | | 1271 | aprint_error_dev(self, "getting interface handle failed\n"); |
1272 | return; | | 1272 | return; |
1273 | } | | 1273 | } |
1274 | | | 1274 | |
1275 | sc->atu_unit = device_unit(self); | | 1275 | sc->atu_unit = device_unit(self); |
1276 | sc->atu_udev = dev; | | 1276 | sc->atu_udev = dev; |
1277 | | | 1277 | |
1278 | /* | | 1278 | /* |
1279 | * look up the radio_type for the device | | 1279 | * look up the radio_type for the device |
1280 | * basically does the same as atu_match | | 1280 | * basically does the same as atu_match |
1281 | */ | | 1281 | */ |
1282 | for (i = 0; i < __arraycount(atu_devs); i++) { | | 1282 | for (i = 0; i < __arraycount(atu_devs); i++) { |
1283 | struct atu_type *t = &atu_devs[i]; | | 1283 | const struct atu_type *t = &atu_devs[i]; |
1284 | | | 1284 | |
1285 | if (uaa->uaa_vendor == t->atu_vid && | | 1285 | if (uaa->uaa_vendor == t->atu_vid && |
1286 | uaa->uaa_product == t->atu_pid) { | | 1286 | uaa->uaa_product == t->atu_pid) { |
1287 | sc->atu_radio = t->atu_radio; | | 1287 | sc->atu_radio = t->atu_radio; |
1288 | sc->atu_quirk = t->atu_quirk; | | 1288 | sc->atu_quirk = t->atu_quirk; |
1289 | } | | 1289 | } |
1290 | } | | 1290 | } |
1291 | | | 1291 | |
1292 | /* | | 1292 | /* |
1293 | * Check in the interface descriptor if we're in DFU mode | | 1293 | * Check in the interface descriptor if we're in DFU mode |
1294 | * If we're in DFU mode, we upload the external firmware | | 1294 | * If we're in DFU mode, we upload the external firmware |
1295 | * If we're not, the PC must have rebooted without power-cycling | | 1295 | * If we're not, the PC must have rebooted without power-cycling |
1296 | * the device.. I've tried this out, a reboot only requeres the | | 1296 | * the device.. I've tried this out, a reboot only requeres the |
1297 | * external firmware to be reloaded :) | | 1297 | * external firmware to be reloaded :) |
1298 | * | | 1298 | * |
1299 | * Hmm. The at76c505a doesn't report a DFU descriptor when it's | | 1299 | * Hmm. The at76c505a doesn't report a DFU descriptor when it's |
1300 | * in DFU mode... Let's just try to get the opmode | | 1300 | * in DFU mode... Let's just try to get the opmode |
1301 | */ | | 1301 | */ |
1302 | err = atu_get_opmode(sc, &mode); | | 1302 | err = atu_get_opmode(sc, &mode); |
1303 | DPRINTFN(20, ("%s: opmode: %d\n", device_xname(sc->atu_dev), mode)); | | 1303 | DPRINTFN(20, ("%s: opmode: %d\n", device_xname(sc->atu_dev), mode)); |
1304 | if (err || (mode != MODE_NETCARD && mode != MODE_NOFLASHNETCARD)) { | | 1304 | if (err || (mode != MODE_NETCARD && mode != MODE_NOFLASHNETCARD)) { |
1305 | DPRINTF(("%s: starting internal firmware download\n", | | 1305 | DPRINTF(("%s: starting internal firmware download\n", |
1306 | device_xname(sc->atu_dev))); | | 1306 | device_xname(sc->atu_dev))); |
1307 | | | 1307 | |
1308 | atu_internal_firmware(sc->atu_dev); | | 1308 | atu_internal_firmware(sc->atu_dev); |
1309 | /* | | 1309 | /* |
1310 | * atu_internal_firmware will cause a reset of the device | | 1310 | * atu_internal_firmware will cause a reset of the device |
1311 | * so we don't want to do any more configuration after this | | 1311 | * so we don't want to do any more configuration after this |
1312 | * point. | | 1312 | * point. |
1313 | */ | | 1313 | */ |
1314 | return; | | 1314 | return; |
1315 | } | | 1315 | } |
1316 | | | 1316 | |
1317 | if (mode != MODE_NETCARD) { | | 1317 | if (mode != MODE_NETCARD) { |
1318 | DPRINTFN(15, ("%s: device needs external firmware\n", | | 1318 | DPRINTFN(15, ("%s: device needs external firmware\n", |
1319 | device_xname(sc->atu_dev))); | | 1319 | device_xname(sc->atu_dev))); |
1320 | | | 1320 | |
1321 | if (mode != MODE_NOFLASHNETCARD) { | | 1321 | if (mode != MODE_NOFLASHNETCARD) { |
1322 | DPRINTF(("%s: unexpected opmode=%d\n", | | 1322 | DPRINTF(("%s: unexpected opmode=%d\n", |
1323 | device_xname(sc->atu_dev), mode)); | | 1323 | device_xname(sc->atu_dev), mode)); |
1324 | } | | 1324 | } |
1325 | | | 1325 | |
1326 | /* | | 1326 | /* |
1327 | * There is no difference in opmode before and after external | | 1327 | * There is no difference in opmode before and after external |
1328 | * firmware upload with the SMC2662 V.4 . So instead we'll try | | 1328 | * firmware upload with the SMC2662 V.4 . So instead we'll try |
1329 | * to read the channel number. If we succeed, external | | 1329 | * to read the channel number. If we succeed, external |
1330 | * firmwaremust have been already uploaded... | | 1330 | * firmwaremust have been already uploaded... |
1331 | */ | | 1331 | */ |
1332 | if (sc->atu_radio != RadioIntersil) { | | 1332 | if (sc->atu_radio != RadioIntersil) { |
1333 | err = atu_get_mib(sc, MIB_PHY__CHANNEL, &channel); | | 1333 | err = atu_get_mib(sc, MIB_PHY__CHANNEL, &channel); |
1334 | if (!err) { | | 1334 | if (!err) { |
1335 | DPRINTF(("%s: external firmware has already" | | 1335 | DPRINTF(("%s: external firmware has already" |
1336 | " been downloaded\n", | | 1336 | " been downloaded\n", |
1337 | device_xname(sc->atu_dev))); | | 1337 | device_xname(sc->atu_dev))); |
1338 | atu_complete_attach(sc); | | 1338 | atu_complete_attach(sc); |
1339 | return; | | 1339 | return; |
1340 | } | | 1340 | } |
1341 | } | | 1341 | } |
1342 | | | 1342 | |
1343 | atu_external_firmware(sc->atu_dev); | | 1343 | atu_external_firmware(sc->atu_dev); |
1344 | | | 1344 | |
1345 | /* | | 1345 | /* |
1346 | * atu_external_firmware will call atu_complete_attach after | | 1346 | * atu_external_firmware will call atu_complete_attach after |
1347 | * it's finished so we can just return. | | 1347 | * it's finished so we can just return. |
1348 | */ | | 1348 | */ |
1349 | } else { | | 1349 | } else { |
1350 | /* all the firmwares are in place, so complete the attach */ | | 1350 | /* all the firmwares are in place, so complete the attach */ |
1351 | atu_complete_attach(sc); | | 1351 | atu_complete_attach(sc); |
1352 | } | | 1352 | } |
1353 | | | 1353 | |
1354 | return; | | 1354 | return; |
1355 | } | | 1355 | } |
1356 | | | 1356 | |
1357 | void | | 1357 | void |
1358 | atu_complete_attach(struct atu_softc *sc) | | 1358 | atu_complete_attach(struct atu_softc *sc) |
1359 | { | | 1359 | { |
1360 | struct ieee80211com *ic = &sc->sc_ic; | | 1360 | struct ieee80211com *ic = &sc->sc_ic; |
1361 | struct ifnet *ifp = &sc->sc_if; | | 1361 | struct ifnet *ifp = &sc->sc_if; |
1362 | usb_interface_descriptor_t *id; | | 1362 | usb_interface_descriptor_t *id; |
1363 | usb_endpoint_descriptor_t *ed; | | 1363 | usb_endpoint_descriptor_t *ed; |
1364 | usbd_status err; | | 1364 | usbd_status err; |
1365 | int i; | | 1365 | int i; |
1366 | #ifdef ATU_DEBUG | | 1366 | #ifdef ATU_DEBUG |
1367 | struct atu_fw fw; | | 1367 | struct atu_fw fw; |
1368 | #endif | | 1368 | #endif |
1369 | | | 1369 | |
1370 | id = usbd_get_interface_descriptor(sc->atu_iface); | | 1370 | id = usbd_get_interface_descriptor(sc->atu_iface); |
1371 | | | 1371 | |
1372 | /* Find endpoints. */ | | 1372 | /* Find endpoints. */ |
1373 | for (i = 0; i < id->bNumEndpoints; i++) { | | 1373 | for (i = 0; i < id->bNumEndpoints; i++) { |
1374 | ed = usbd_interface2endpoint_descriptor(sc->atu_iface, i); | | 1374 | ed = usbd_interface2endpoint_descriptor(sc->atu_iface, i); |
1375 | if (!ed) { | | 1375 | if (!ed) { |
1376 | DPRINTF(("%s: num_endp:%d\n", device_xname(sc->atu_dev), | | 1376 | DPRINTF(("%s: num_endp:%d\n", device_xname(sc->atu_dev), |
1377 | sc->atu_iface->ui_idesc->bNumEndpoints)); | | 1377 | sc->atu_iface->ui_idesc->bNumEndpoints)); |
1378 | DPRINTF(("%s: couldn't get ep %d\n", | | 1378 | DPRINTF(("%s: couldn't get ep %d\n", |
1379 | device_xname(sc->atu_dev), i)); | | 1379 | device_xname(sc->atu_dev), i)); |
1380 | return; | | 1380 | return; |
1381 | } | | 1381 | } |
1382 | if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && | | 1382 | if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && |
1383 | UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { | | 1383 | UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { |
1384 | sc->atu_ed[ATU_ENDPT_RX] = ed->bEndpointAddress; | | 1384 | sc->atu_ed[ATU_ENDPT_RX] = ed->bEndpointAddress; |
1385 | } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && | | 1385 | } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && |
1386 | UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { | | 1386 | UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { |
1387 | sc->atu_ed[ATU_ENDPT_TX] = ed->bEndpointAddress; | | 1387 | sc->atu_ed[ATU_ENDPT_TX] = ed->bEndpointAddress; |
1388 | } | | 1388 | } |
1389 | } | | 1389 | } |
1390 | | | 1390 | |
1391 | /* read device config & get MAC address */ | | 1391 | /* read device config & get MAC address */ |
1392 | err = atu_get_card_config(sc); | | 1392 | err = atu_get_card_config(sc); |
1393 | if (err) { | | 1393 | if (err) { |
1394 | aprint_error("\n%s: could not get card cfg!\n", | | 1394 | aprint_error("\n%s: could not get card cfg!\n", |
1395 | device_xname(sc->atu_dev)); | | 1395 | device_xname(sc->atu_dev)); |
1396 | return; | | 1396 | return; |
1397 | } | | 1397 | } |
1398 | | | 1398 | |
1399 | #ifdef ATU_DEBUG | | 1399 | #ifdef ATU_DEBUG |
1400 | /* DEBUG : try to get firmware version */ | | 1400 | /* DEBUG : try to get firmware version */ |
1401 | err = atu_get_mib(sc, MIB_FW_VERSION, sizeof(fw), 0, (uint8_t *)&fw); | | 1401 | err = atu_get_mib(sc, MIB_FW_VERSION, sizeof(fw), 0, (uint8_t *)&fw); |
1402 | if (!err) { | | 1402 | if (!err) { |
1403 | DPRINTFN(15, ("%s: firmware: maj:%d min:%d patch:%d " | | 1403 | DPRINTFN(15, ("%s: firmware: maj:%d min:%d patch:%d " |
1404 | "build:%d\n", device_xname(sc->atu_dev), fw.major, fw.minor, | | 1404 | "build:%d\n", device_xname(sc->atu_dev), fw.major, fw.minor, |
1405 | fw.patch, fw.build)); | | 1405 | fw.patch, fw.build)); |
1406 | } else { | | 1406 | } else { |
1407 | DPRINTF(("%s: get firmware version failed\n", | | 1407 | DPRINTF(("%s: get firmware version failed\n", |
1408 | device_xname(sc->atu_dev))); | | 1408 | device_xname(sc->atu_dev))); |
1409 | } | | 1409 | } |
1410 | #endif /* ATU_DEBUG */ | | 1410 | #endif /* ATU_DEBUG */ |
1411 | | | 1411 | |
1412 | /* Show the world our MAC address */ | | 1412 | /* Show the world our MAC address */ |
1413 | aprint_normal_dev(sc->atu_dev, "MAC address %s\n", | | 1413 | aprint_normal_dev(sc->atu_dev, "MAC address %s\n", |
1414 | ether_sprintf(ic->ic_myaddr)); | | 1414 | ether_sprintf(ic->ic_myaddr)); |
1415 | | | 1415 | |
1416 | sc->atu_cdata.atu_tx_inuse = 0; | | 1416 | sc->atu_cdata.atu_tx_inuse = 0; |
1417 | sc->atu_encrypt = ATU_WEP_OFF; | | 1417 | sc->atu_encrypt = ATU_WEP_OFF; |
1418 | sc->atu_wepkeylen = ATU_WEP_104BITS; | | 1418 | sc->atu_wepkeylen = ATU_WEP_104BITS; |
1419 | sc->atu_wepkey = 0; | | 1419 | sc->atu_wepkey = 0; |
1420 | | | 1420 | |
1421 | memset(sc->atu_bssid, 0, ETHER_ADDR_LEN); | | 1421 | memset(sc->atu_bssid, 0, ETHER_ADDR_LEN); |
1422 | sc->atu_channel = ATU_DEFAULT_CHANNEL; | | 1422 | sc->atu_channel = ATU_DEFAULT_CHANNEL; |
1423 | sc->atu_desired_channel = IEEE80211_CHAN_ANY; | | 1423 | sc->atu_desired_channel = IEEE80211_CHAN_ANY; |
1424 | sc->atu_mode = INFRASTRUCTURE_MODE; | | 1424 | sc->atu_mode = INFRASTRUCTURE_MODE; |
1425 | | | 1425 | |
1426 | ic->ic_ifp = ifp; | | 1426 | ic->ic_ifp = ifp; |
1427 | ic->ic_phytype = IEEE80211_T_DS; | | 1427 | ic->ic_phytype = IEEE80211_T_DS; |
1428 | ic->ic_opmode = IEEE80211_M_STA; | | 1428 | ic->ic_opmode = IEEE80211_M_STA; |
1429 | ic->ic_state = IEEE80211_S_INIT; | | 1429 | ic->ic_state = IEEE80211_S_INIT; |
1430 | #ifdef FIXME | | 1430 | #ifdef FIXME |
1431 | ic->ic_caps = IEEE80211_C_IBSS | IEEE80211_C_WEP | IEEE80211_C_SCANALL; | | 1431 | ic->ic_caps = IEEE80211_C_IBSS | IEEE80211_C_WEP | IEEE80211_C_SCANALL; |
1432 | #else | | 1432 | #else |
1433 | ic->ic_caps = IEEE80211_C_IBSS | IEEE80211_C_WEP; | | 1433 | ic->ic_caps = IEEE80211_C_IBSS | IEEE80211_C_WEP; |
1434 | #endif | | 1434 | #endif |
1435 | | | 1435 | |
1436 | i = 0; | | 1436 | i = 0; |
1437 | ic->ic_sup_rates[IEEE80211_MODE_11B] = ieee80211_std_rateset_11b; | | 1437 | ic->ic_sup_rates[IEEE80211_MODE_11B] = ieee80211_std_rateset_11b; |
1438 | | | 1438 | |
1439 | for (i = 1; i <= 14; i++) { | | 1439 | for (i = 1; i <= 14; i++) { |
1440 | ic->ic_channels[i].ic_flags = IEEE80211_CHAN_B | | | 1440 | ic->ic_channels[i].ic_flags = IEEE80211_CHAN_B | |
1441 | IEEE80211_CHAN_PASSIVE; | | 1441 | IEEE80211_CHAN_PASSIVE; |
1442 | ic->ic_channels[i].ic_freq = ieee80211_ieee2mhz(i, | | 1442 | ic->ic_channels[i].ic_freq = ieee80211_ieee2mhz(i, |
1443 | ic->ic_channels[i].ic_flags); | | 1443 | ic->ic_channels[i].ic_flags); |
1444 | } | | 1444 | } |
1445 | | | 1445 | |
1446 | ic->ic_ibss_chan = &ic->ic_channels[0]; | | 1446 | ic->ic_ibss_chan = &ic->ic_channels[0]; |
1447 | | | 1447 | |
1448 | ifp->if_softc = sc; | | 1448 | ifp->if_softc = sc; |
1449 | memcpy(ifp->if_xname, device_xname(sc->atu_dev), IFNAMSIZ); | | 1449 | memcpy(ifp->if_xname, device_xname(sc->atu_dev), IFNAMSIZ); |
1450 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | | 1450 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; |
1451 | ifp->if_init = atu_init; | | 1451 | ifp->if_init = atu_init; |
1452 | ifp->if_stop = atu_stop; | | 1452 | ifp->if_stop = atu_stop; |
1453 | ifp->if_start = atu_start; | | 1453 | ifp->if_start = atu_start; |
1454 | ifp->if_ioctl = atu_ioctl; | | 1454 | ifp->if_ioctl = atu_ioctl; |
1455 | ifp->if_watchdog = atu_watchdog; | | 1455 | ifp->if_watchdog = atu_watchdog; |
1456 | ifp->if_mtu = ATU_DEFAULT_MTU; | | 1456 | ifp->if_mtu = ATU_DEFAULT_MTU; |
1457 | IFQ_SET_READY(&ifp->if_snd); | | 1457 | IFQ_SET_READY(&ifp->if_snd); |
1458 | | | 1458 | |
1459 | /* Call MI attach routine. */ | | 1459 | /* Call MI attach routine. */ |
1460 | if_attach(ifp); | | 1460 | if_attach(ifp); |
1461 | ieee80211_ifattach(ic); | | 1461 | ieee80211_ifattach(ic); |
1462 | | | 1462 | |
1463 | sc->sc_newstate = ic->ic_newstate; | | 1463 | sc->sc_newstate = ic->ic_newstate; |
1464 | ic->ic_newstate = atu_newstate; | | 1464 | ic->ic_newstate = atu_newstate; |
1465 | | | 1465 | |
1466 | /* setup ifmedia interface */ | | 1466 | /* setup ifmedia interface */ |
1467 | ieee80211_media_init(ic, atu_media_change, atu_media_status); | | 1467 | ieee80211_media_init(ic, atu_media_change, atu_media_status); |
1468 | | | 1468 | |
1469 | usb_init_task(&sc->sc_task, atu_task, sc, 0); | | 1469 | usb_init_task(&sc->sc_task, atu_task, sc, 0); |
1470 | | | 1470 | |
1471 | sc->sc_state = ATU_S_OK; | | 1471 | sc->sc_state = ATU_S_OK; |
1472 | } | | 1472 | } |
1473 | | | 1473 | |
1474 | int | | 1474 | int |
1475 | atu_detach(device_t self, int flags) | | 1475 | atu_detach(device_t self, int flags) |
1476 | { | | 1476 | { |
1477 | struct atu_softc *sc = device_private(self); | | 1477 | struct atu_softc *sc = device_private(self); |
1478 | struct ifnet *ifp = &sc->sc_if; | | 1478 | struct ifnet *ifp = &sc->sc_if; |
1479 | | | 1479 | |
1480 | DPRINTFN(10, ("%s: atu_detach state=%d\n", device_xname(sc->atu_dev), | | 1480 | DPRINTFN(10, ("%s: atu_detach state=%d\n", device_xname(sc->atu_dev), |
1481 | sc->sc_state)); | | 1481 | sc->sc_state)); |
1482 | | | 1482 | |
1483 | if (sc->sc_state != ATU_S_UNCONFIG) { | | 1483 | if (sc->sc_state != ATU_S_UNCONFIG) { |
1484 | atu_stop(ifp, 1); | | 1484 | atu_stop(ifp, 1); |
1485 | | | 1485 | |
1486 | ieee80211_ifdetach(&sc->sc_ic); | | 1486 | ieee80211_ifdetach(&sc->sc_ic); |
1487 | if_detach(ifp); | | 1487 | if_detach(ifp); |
1488 | } | | 1488 | } |
1489 | | | 1489 | |
1490 | return(0); | | 1490 | return(0); |
1491 | } | | 1491 | } |
1492 | | | 1492 | |
1493 | int | | 1493 | int |
1494 | atu_activate(device_t self, enum devact act) | | 1494 | atu_activate(device_t self, enum devact act) |
1495 | { | | 1495 | { |
1496 | struct atu_softc *sc = device_private(self); | | 1496 | struct atu_softc *sc = device_private(self); |
1497 | | | 1497 | |
1498 | switch (act) { | | 1498 | switch (act) { |
1499 | case DVACT_DEACTIVATE: | | 1499 | case DVACT_DEACTIVATE: |
1500 | if (sc->sc_state != ATU_S_UNCONFIG) { | | 1500 | if (sc->sc_state != ATU_S_UNCONFIG) { |
1501 | if_deactivate(&sc->atu_ec.ec_if); | | 1501 | if_deactivate(&sc->atu_ec.ec_if); |
1502 | sc->sc_state = ATU_S_DEAD; | | 1502 | sc->sc_state = ATU_S_DEAD; |
1503 | } | | 1503 | } |
1504 | return 0; | | 1504 | return 0; |
1505 | default: | | 1505 | default: |
1506 | return EOPNOTSUPP; | | 1506 | return EOPNOTSUPP; |
1507 | } | | 1507 | } |
1508 | } | | 1508 | } |
1509 | | | 1509 | |
1510 | /* | | 1510 | /* |
1511 | * Initialize an RX descriptor and attach an MBUF cluster. | | 1511 | * Initialize an RX descriptor and attach an MBUF cluster. |
1512 | */ | | 1512 | */ |
1513 | int | | 1513 | int |
1514 | atu_newbuf(struct atu_softc *sc, struct atu_chain *c, struct mbuf *m) | | 1514 | atu_newbuf(struct atu_softc *sc, struct atu_chain *c, struct mbuf *m) |
1515 | { | | 1515 | { |
1516 | struct mbuf *m_new = NULL; | | 1516 | struct mbuf *m_new = NULL; |
1517 | | | 1517 | |
1518 | if (m == NULL) { | | 1518 | if (m == NULL) { |
1519 | MGETHDR(m_new, M_DONTWAIT, MT_DATA); | | 1519 | MGETHDR(m_new, M_DONTWAIT, MT_DATA); |
1520 | if (m_new == NULL) { | | 1520 | if (m_new == NULL) { |
1521 | DPRINTF(("%s: no memory for rx list\n", | | 1521 | DPRINTF(("%s: no memory for rx list\n", |
1522 | device_xname(sc->atu_dev))); | | 1522 | device_xname(sc->atu_dev))); |
1523 | return(ENOBUFS); | | 1523 | return(ENOBUFS); |
1524 | } | | 1524 | } |
1525 | | | 1525 | |
1526 | MCLGET(m_new, M_DONTWAIT); | | 1526 | MCLGET(m_new, M_DONTWAIT); |
1527 | if (!(m_new->m_flags & M_EXT)) { | | 1527 | if (!(m_new->m_flags & M_EXT)) { |
1528 | DPRINTF(("%s: no memory for rx list\n", | | 1528 | DPRINTF(("%s: no memory for rx list\n", |
1529 | device_xname(sc->atu_dev))); | | 1529 | device_xname(sc->atu_dev))); |
1530 | m_freem(m_new); | | 1530 | m_freem(m_new); |
1531 | return(ENOBUFS); | | 1531 | return(ENOBUFS); |
1532 | } | | 1532 | } |
1533 | m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; | | 1533 | m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; |
1534 | } else { | | 1534 | } else { |
1535 | m_new = m; | | 1535 | m_new = m; |
1536 | m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; | | 1536 | m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; |
1537 | m_new->m_data = m_new->m_ext.ext_buf; | | 1537 | m_new->m_data = m_new->m_ext.ext_buf; |
1538 | } | | 1538 | } |
1539 | c->atu_mbuf = m_new; | | 1539 | c->atu_mbuf = m_new; |
1540 | return(0); | | 1540 | return(0); |
1541 | } | | 1541 | } |
1542 | | | 1542 | |
1543 | int | | 1543 | int |
1544 | atu_rx_list_init(struct atu_softc *sc) | | 1544 | atu_rx_list_init(struct atu_softc *sc) |
1545 | { | | 1545 | { |
1546 | struct atu_cdata *cd = &sc->atu_cdata; | | 1546 | struct atu_cdata *cd = &sc->atu_cdata; |
1547 | struct atu_chain *c; | | 1547 | struct atu_chain *c; |
1548 | int i; | | 1548 | int i; |
1549 | | | 1549 | |
1550 | DPRINTFN(15, ("%s: atu_rx_list_init: enter\n", | | 1550 | DPRINTFN(15, ("%s: atu_rx_list_init: enter\n", |
1551 | device_xname(sc->atu_dev))); | | 1551 | device_xname(sc->atu_dev))); |
1552 | | | 1552 | |
1553 | for (i = 0; i < ATU_RX_LIST_CNT; i++) { | | 1553 | for (i = 0; i < ATU_RX_LIST_CNT; i++) { |
1554 | c = &cd->atu_rx_chain[i]; | | 1554 | c = &cd->atu_rx_chain[i]; |
1555 | c->atu_sc = sc; | | 1555 | c->atu_sc = sc; |
1556 | c->atu_idx = i; | | 1556 | c->atu_idx = i; |
1557 | if (c->atu_xfer == NULL) { | | 1557 | if (c->atu_xfer == NULL) { |
1558 | int err = usbd_create_xfer(sc->atu_ep[ATU_ENDPT_RX], | | 1558 | int err = usbd_create_xfer(sc->atu_ep[ATU_ENDPT_RX], |
1559 | ATU_RX_BUFSZ, 0, 0, &c->atu_xfer); | | 1559 | ATU_RX_BUFSZ, 0, 0, &c->atu_xfer); |
1560 | if (err) | | 1560 | if (err) |
1561 | return err; | | 1561 | return err; |
1562 | c->atu_buf = usbd_get_buffer(c->atu_xfer); | | 1562 | c->atu_buf = usbd_get_buffer(c->atu_xfer); |
1563 | if (atu_newbuf(sc, c, NULL) == ENOBUFS) /* XXX free? */ | | 1563 | if (atu_newbuf(sc, c, NULL) == ENOBUFS) /* XXX free? */ |
1564 | return(ENOBUFS); | | 1564 | return(ENOBUFS); |
1565 | } | | 1565 | } |
1566 | } | | 1566 | } |
1567 | return 0; | | 1567 | return 0; |
1568 | } | | 1568 | } |
1569 | | | 1569 | |
1570 | int | | 1570 | int |
1571 | atu_tx_list_init(struct atu_softc *sc) | | 1571 | atu_tx_list_init(struct atu_softc *sc) |
1572 | { | | 1572 | { |
1573 | struct atu_cdata *cd = &sc->atu_cdata; | | 1573 | struct atu_cdata *cd = &sc->atu_cdata; |
1574 | struct atu_chain *c; | | 1574 | struct atu_chain *c; |
1575 | int i; | | 1575 | int i; |
1576 | | | 1576 | |
1577 | DPRINTFN(15, ("%s: atu_tx_list_init\n", | | 1577 | DPRINTFN(15, ("%s: atu_tx_list_init\n", |
1578 | device_xname(sc->atu_dev))); | | 1578 | device_xname(sc->atu_dev))); |
1579 | | | 1579 | |
1580 | SLIST_INIT(&cd->atu_tx_free); | | 1580 | SLIST_INIT(&cd->atu_tx_free); |
1581 | sc->atu_cdata.atu_tx_inuse = 0; | | 1581 | sc->atu_cdata.atu_tx_inuse = 0; |
1582 | | | 1582 | |
1583 | for (i = 0; i < ATU_TX_LIST_CNT; i++) { | | 1583 | for (i = 0; i < ATU_TX_LIST_CNT; i++) { |
1584 | c = &cd->atu_tx_chain[i]; | | 1584 | c = &cd->atu_tx_chain[i]; |
1585 | c->atu_sc = sc; | | 1585 | c->atu_sc = sc; |
1586 | c->atu_idx = i; | | 1586 | c->atu_idx = i; |
1587 | if (c->atu_xfer == NULL) { | | 1587 | if (c->atu_xfer == NULL) { |
1588 | int err = usbd_create_xfer(sc->atu_ep[ATU_ENDPT_TX], | | 1588 | int err = usbd_create_xfer(sc->atu_ep[ATU_ENDPT_TX], |
1589 | ATU_TX_BUFSZ, 0, 0, &c->atu_xfer); | | 1589 | ATU_TX_BUFSZ, 0, 0, &c->atu_xfer); |
1590 | if (err) { | | 1590 | if (err) { |
1591 | return err; | | 1591 | return err; |
1592 | } | | 1592 | } |
1593 | c->atu_buf = usbd_get_buffer(c->atu_xfer); | | 1593 | c->atu_buf = usbd_get_buffer(c->atu_xfer); |
1594 | SLIST_INSERT_HEAD(&cd->atu_tx_free, c, atu_list); | | 1594 | SLIST_INSERT_HEAD(&cd->atu_tx_free, c, atu_list); |
1595 | } | | 1595 | } |
1596 | } | | 1596 | } |
1597 | return(0); | | 1597 | return(0); |
1598 | } | | 1598 | } |
1599 | | | 1599 | |
1600 | void | | 1600 | void |
1601 | atu_xfer_list_free(struct atu_softc *sc, struct atu_chain *ch, | | 1601 | atu_xfer_list_free(struct atu_softc *sc, struct atu_chain *ch, |
1602 | int listlen) | | 1602 | int listlen) |
1603 | { | | 1603 | { |
1604 | int i; | | 1604 | int i; |
1605 | | | 1605 | |
1606 | /* Free resources. */ | | 1606 | /* Free resources. */ |
1607 | for (i = 0; i < listlen; i++) { | | 1607 | for (i = 0; i < listlen; i++) { |
1608 | if (ch[i].atu_buf != NULL) | | 1608 | if (ch[i].atu_buf != NULL) |
1609 | ch[i].atu_buf = NULL; | | 1609 | ch[i].atu_buf = NULL; |
1610 | if (ch[i].atu_mbuf != NULL) { | | 1610 | if (ch[i].atu_mbuf != NULL) { |
1611 | m_freem(ch[i].atu_mbuf); | | 1611 | m_freem(ch[i].atu_mbuf); |
1612 | ch[i].atu_mbuf = NULL; | | 1612 | ch[i].atu_mbuf = NULL; |
1613 | } | | 1613 | } |
1614 | if (ch[i].atu_xfer != NULL) { | | 1614 | if (ch[i].atu_xfer != NULL) { |
1615 | usbd_destroy_xfer(ch[i].atu_xfer); | | 1615 | usbd_destroy_xfer(ch[i].atu_xfer); |
1616 | ch[i].atu_xfer = NULL; | | 1616 | ch[i].atu_xfer = NULL; |
1617 | } | | 1617 | } |
1618 | } | | 1618 | } |
1619 | } | | 1619 | } |
1620 | | | 1620 | |
1621 | /* | | 1621 | /* |
1622 | * A frame has been uploaded: pass the resulting mbuf chain up to | | 1622 | * A frame has been uploaded: pass the resulting mbuf chain up to |
1623 | * the higher level protocols. | | 1623 | * the higher level protocols. |
1624 | */ | | 1624 | */ |
1625 | void | | 1625 | void |
1626 | atu_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status) | | 1626 | atu_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status) |
1627 | { | | 1627 | { |
1628 | struct atu_chain *c = (struct atu_chain *)priv; | | 1628 | struct atu_chain *c = (struct atu_chain *)priv; |
1629 | struct atu_softc *sc = c->atu_sc; | | 1629 | struct atu_softc *sc = c->atu_sc; |
1630 | struct ieee80211com *ic = &sc->sc_ic; | | 1630 | struct ieee80211com *ic = &sc->sc_ic; |
1631 | struct ifnet *ifp = &sc->sc_if; | | 1631 | struct ifnet *ifp = &sc->sc_if; |
1632 | struct atu_rx_hdr *h; | | 1632 | struct atu_rx_hdr *h; |
1633 | struct ieee80211_frame_min *wh; | | 1633 | struct ieee80211_frame_min *wh; |
1634 | struct ieee80211_node *ni; | | 1634 | struct ieee80211_node *ni; |
1635 | struct mbuf *m; | | 1635 | struct mbuf *m; |
1636 | uint32_t len; | | 1636 | uint32_t len; |
1637 | int s; | | 1637 | int s; |
1638 | | | 1638 | |
1639 | DPRINTFN(25, ("%s: atu_rxeof\n", device_xname(sc->atu_dev))); | | 1639 | DPRINTFN(25, ("%s: atu_rxeof\n", device_xname(sc->atu_dev))); |
1640 | | | 1640 | |
1641 | if (sc->sc_state != ATU_S_OK) | | 1641 | if (sc->sc_state != ATU_S_OK) |
1642 | return; | | 1642 | return; |
1643 | | | 1643 | |
1644 | if ((ifp->if_flags & (IFF_RUNNING|IFF_UP)) != (IFF_RUNNING|IFF_UP)) | | 1644 | if ((ifp->if_flags & (IFF_RUNNING|IFF_UP)) != (IFF_RUNNING|IFF_UP)) |
1645 | goto done; | | 1645 | goto done; |
1646 | | | 1646 | |
1647 | if (status != USBD_NORMAL_COMPLETION) { | | 1647 | if (status != USBD_NORMAL_COMPLETION) { |
1648 | DPRINTF(("%s: status != USBD_NORMAL_COMPLETION\n", | | 1648 | DPRINTF(("%s: status != USBD_NORMAL_COMPLETION\n", |
1649 | device_xname(sc->atu_dev))); | | 1649 | device_xname(sc->atu_dev))); |
1650 | if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { | | 1650 | if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { |
1651 | return; | | 1651 | return; |
1652 | } | | 1652 | } |
1653 | #if 0 | | 1653 | #if 0 |
1654 | if (status == USBD_IOERROR) { | | 1654 | if (status == USBD_IOERROR) { |
1655 | DPRINTF(("%s: rx: EEK! lost device?\n", | | 1655 | DPRINTF(("%s: rx: EEK! lost device?\n", |
1656 | device_xname(sc->atu_dev))); | | 1656 | device_xname(sc->atu_dev))); |
1657 | | | 1657 | |
1658 | /* | | 1658 | /* |
1659 | * My experience with USBD_IOERROR is that trying to | | 1659 | * My experience with USBD_IOERROR is that trying to |
1660 | * restart the transfer will always fail and we'll | | 1660 | * restart the transfer will always fail and we'll |
1661 | * keep on looping restarting transfers untill someone | | 1661 | * keep on looping restarting transfers untill someone |
1662 | * pulls the plug of the device. | | 1662 | * pulls the plug of the device. |
1663 | * So we don't restart the transfer, but just let it | | 1663 | * So we don't restart the transfer, but just let it |
1664 | * die... If someone knows of a situation where we can | | 1664 | * die... If someone knows of a situation where we can |
1665 | * recover from USBD_IOERROR, let me know. | | 1665 | * recover from USBD_IOERROR, let me know. |
1666 | */ | | 1666 | */ |
1667 | splx(s); | | 1667 | splx(s); |
1668 | return; | | 1668 | return; |
1669 | } | | 1669 | } |
1670 | #endif /* 0 */ | | 1670 | #endif /* 0 */ |
1671 | | | 1671 | |
1672 | if (usbd_ratecheck(&sc->atu_rx_notice)) { | | 1672 | if (usbd_ratecheck(&sc->atu_rx_notice)) { |
1673 | DPRINTF(("%s: usb error on rx: %s\n", | | 1673 | DPRINTF(("%s: usb error on rx: %s\n", |
1674 | device_xname(sc->atu_dev), usbd_errstr(status))); | | 1674 | device_xname(sc->atu_dev), usbd_errstr(status))); |
1675 | } | | 1675 | } |
1676 | if (status == USBD_STALLED) | | 1676 | if (status == USBD_STALLED) |
1677 | usbd_clear_endpoint_stall_async( | | 1677 | usbd_clear_endpoint_stall_async( |
1678 | sc->atu_ep[ATU_ENDPT_RX]); | | 1678 | sc->atu_ep[ATU_ENDPT_RX]); |
1679 | goto done; | | 1679 | goto done; |
1680 | } | | 1680 | } |
1681 | | | 1681 | |
1682 | usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL); | | 1682 | usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL); |
1683 | | | 1683 | |
1684 | if (len <= 1) { | | 1684 | if (len <= 1) { |
1685 | DPRINTF(("%s: atu_rxeof: too short\n", | | 1685 | DPRINTF(("%s: atu_rxeof: too short\n", |
1686 | device_xname(sc->atu_dev))); | | 1686 | device_xname(sc->atu_dev))); |
1687 | goto done; | | 1687 | goto done; |
1688 | } | | 1688 | } |
1689 | | | 1689 | |
1690 | h = (struct atu_rx_hdr *)c->atu_buf; | | 1690 | h = (struct atu_rx_hdr *)c->atu_buf; |
1691 | len = UGETW(h->length) - 4; /* XXX magic number */ | | 1691 | len = UGETW(h->length) - 4; /* XXX magic number */ |
1692 | | | 1692 | |
1693 | m = c->atu_mbuf; | | 1693 | m = c->atu_mbuf; |
1694 | memcpy(mtod(m, char *), c->atu_buf + ATU_RX_HDRLEN, len); | | 1694 | memcpy(mtod(m, char *), c->atu_buf + ATU_RX_HDRLEN, len); |
1695 | m_set_rcvif(m, ifp); | | 1695 | m_set_rcvif(m, ifp); |
1696 | m->m_pkthdr.len = m->m_len = len; | | 1696 | m->m_pkthdr.len = m->m_len = len; |
1697 | | | 1697 | |
1698 | wh = mtod(m, struct ieee80211_frame_min *); | | 1698 | wh = mtod(m, struct ieee80211_frame_min *); |
1699 | ni = ieee80211_find_rxnode(ic, wh); | | 1699 | ni = ieee80211_find_rxnode(ic, wh); |
1700 | | | 1700 | |
1701 | ifp->if_ipackets++; | | 1701 | ifp->if_ipackets++; |
1702 | | | 1702 | |
1703 | s = splnet(); | | 1703 | s = splnet(); |
1704 | | | 1704 | |
1705 | if (atu_newbuf(sc, c, NULL) == ENOBUFS) { | | 1705 | if (atu_newbuf(sc, c, NULL) == ENOBUFS) { |
1706 | ifp->if_ierrors++; | | 1706 | ifp->if_ierrors++; |
1707 | goto done1; /* XXX if we can't allocate, why restart it? */ | | 1707 | goto done1; /* XXX if we can't allocate, why restart it? */ |
1708 | } | | 1708 | } |
1709 | | | 1709 | |
1710 | if (wh->i_fc[1] & IEEE80211_FC1_WEP) { | | 1710 | if (wh->i_fc[1] & IEEE80211_FC1_WEP) { |
1711 | /* | | 1711 | /* |
1712 | * WEP is decrypted by hardware. Clear WEP bit | | 1712 | * WEP is decrypted by hardware. Clear WEP bit |
1713 | * header for ieee80211_input(). | | 1713 | * header for ieee80211_input(). |
1714 | */ | | 1714 | */ |
1715 | wh->i_fc[1] &= ~IEEE80211_FC1_WEP; | | 1715 | wh->i_fc[1] &= ~IEEE80211_FC1_WEP; |
1716 | } | | 1716 | } |
1717 | | | 1717 | |
1718 | ieee80211_input(ic, m, ni, h->rssi, UGETDW(h->rx_time)); | | 1718 | ieee80211_input(ic, m, ni, h->rssi, UGETDW(h->rx_time)); |
1719 | | | 1719 | |
1720 | ieee80211_free_node(ni); | | 1720 | ieee80211_free_node(ni); |
1721 | done1: | | 1721 | done1: |
1722 | splx(s); | | 1722 | splx(s); |
1723 | done: | | 1723 | done: |
1724 | /* Setup new transfer. */ | | 1724 | /* Setup new transfer. */ |
1725 | usbd_setup_xfer(c->atu_xfer, c, c->atu_buf, ATU_RX_BUFSZ, | | 1725 | usbd_setup_xfer(c->atu_xfer, c, c->atu_buf, ATU_RX_BUFSZ, |
1726 | USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, atu_rxeof); | | 1726 | USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, atu_rxeof); |
1727 | usbd_transfer(c->atu_xfer); | | 1727 | usbd_transfer(c->atu_xfer); |
1728 | } | | 1728 | } |
1729 | | | 1729 | |
1730 | /* | | 1730 | /* |
1731 | * A frame was downloaded to the chip. It's safe for us to clean up | | 1731 | * A frame was downloaded to the chip. It's safe for us to clean up |
1732 | * the list buffers. | | 1732 | * the list buffers. |
1733 | */ | | 1733 | */ |
1734 | void | | 1734 | void |
1735 | atu_txeof(struct usbd_xfer *xfer, void *priv, | | 1735 | atu_txeof(struct usbd_xfer *xfer, void *priv, |
1736 | usbd_status status) | | 1736 | usbd_status status) |
1737 | { | | 1737 | { |
1738 | struct atu_chain *c = (struct atu_chain *)priv; | | 1738 | struct atu_chain *c = (struct atu_chain *)priv; |
1739 | struct atu_softc *sc = c->atu_sc; | | 1739 | struct atu_softc *sc = c->atu_sc; |
1740 | struct ifnet *ifp = &sc->sc_if; | | 1740 | struct ifnet *ifp = &sc->sc_if; |
1741 | usbd_status err; | | 1741 | usbd_status err; |
1742 | int s; | | 1742 | int s; |
1743 | | | 1743 | |
1744 | DPRINTFN(25, ("%s: atu_txeof status=%d\n", device_xname(sc->atu_dev), | | 1744 | DPRINTFN(25, ("%s: atu_txeof status=%d\n", device_xname(sc->atu_dev), |
1745 | status)); | | 1745 | status)); |
1746 | | | 1746 | |
1747 | if (c->atu_mbuf) { | | 1747 | if (c->atu_mbuf) { |
1748 | m_freem(c->atu_mbuf); | | 1748 | m_freem(c->atu_mbuf); |
1749 | c->atu_mbuf = NULL; | | 1749 | c->atu_mbuf = NULL; |
1750 | } | | 1750 | } |
1751 | | | 1751 | |
1752 | if (status != USBD_NORMAL_COMPLETION) { | | 1752 | if (status != USBD_NORMAL_COMPLETION) { |
1753 | if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) | | 1753 | if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) |
1754 | return; | | 1754 | return; |
1755 | | | 1755 | |
1756 | DPRINTF(("%s: usb error on tx: %s\n", device_xname(sc->atu_dev), | | 1756 | DPRINTF(("%s: usb error on tx: %s\n", device_xname(sc->atu_dev), |
1757 | usbd_errstr(status))); | | 1757 | usbd_errstr(status))); |
1758 | if (status == USBD_STALLED) | | 1758 | if (status == USBD_STALLED) |
1759 | usbd_clear_endpoint_stall_async(sc->atu_ep[ATU_ENDPT_TX]); | | 1759 | usbd_clear_endpoint_stall_async(sc->atu_ep[ATU_ENDPT_TX]); |
1760 | return; | | 1760 | return; |
1761 | } | | 1761 | } |
1762 | | | 1762 | |
1763 | usbd_get_xfer_status(c->atu_xfer, NULL, NULL, NULL, &err); | | 1763 | usbd_get_xfer_status(c->atu_xfer, NULL, NULL, NULL, &err); |
1764 | | | 1764 | |
1765 | if (err) | | 1765 | if (err) |
1766 | ifp->if_oerrors++; | | 1766 | ifp->if_oerrors++; |
1767 | else | | 1767 | else |
1768 | ifp->if_opackets++; | | 1768 | ifp->if_opackets++; |
1769 | | | 1769 | |
1770 | s = splnet(); | | 1770 | s = splnet(); |
1771 | SLIST_INSERT_HEAD(&sc->atu_cdata.atu_tx_free, c, atu_list); | | 1771 | SLIST_INSERT_HEAD(&sc->atu_cdata.atu_tx_free, c, atu_list); |
1772 | sc->atu_cdata.atu_tx_inuse--; | | 1772 | sc->atu_cdata.atu_tx_inuse--; |
1773 | if (sc->atu_cdata.atu_tx_inuse == 0) | | 1773 | if (sc->atu_cdata.atu_tx_inuse == 0) |
1774 | ifp->if_timer = 0; | | 1774 | ifp->if_timer = 0; |
1775 | ifp->if_flags &= ~IFF_OACTIVE; | | 1775 | ifp->if_flags &= ~IFF_OACTIVE; |
1776 | splx(s); | | 1776 | splx(s); |
1777 | | | 1777 | |
1778 | atu_start(ifp); | | 1778 | atu_start(ifp); |
1779 | } | | 1779 | } |
1780 | | | 1780 | |
1781 | uint8_t | | 1781 | uint8_t |
1782 | atu_calculate_padding(int size) | | 1782 | atu_calculate_padding(int size) |
1783 | { | | 1783 | { |
1784 | size %= 64; | | 1784 | size %= 64; |
1785 | | | 1785 | |
1786 | if (size < 50) | | 1786 | if (size < 50) |
1787 | return 50 - size; | | 1787 | return 50 - size; |
1788 | if (size >=61) | | 1788 | if (size >=61) |
1789 | return 64 + 50 - size; | | 1789 | return 64 + 50 - size; |
1790 | return 0; | | 1790 | return 0; |
1791 | } | | 1791 | } |
1792 | | | 1792 | |
1793 | int | | 1793 | int |
1794 | atu_tx_start(struct atu_softc *sc, struct ieee80211_node *ni, | | 1794 | atu_tx_start(struct atu_softc *sc, struct ieee80211_node *ni, |
1795 | struct atu_chain *c, struct mbuf *m) | | 1795 | struct atu_chain *c, struct mbuf *m) |
1796 | { | | 1796 | { |
1797 | int len; | | 1797 | int len; |
1798 | struct atu_tx_hdr *h; | | 1798 | struct atu_tx_hdr *h; |
1799 | usbd_status err; | | 1799 | usbd_status err; |
1800 | uint8_t pad; | | 1800 | uint8_t pad; |
1801 | | | 1801 | |
1802 | DPRINTFN(25, ("%s: atu_tx_start\n", device_xname(sc->atu_dev))); | | 1802 | DPRINTFN(25, ("%s: atu_tx_start\n", device_xname(sc->atu_dev))); |
1803 | | | 1803 | |
1804 | /* Don't try to send when we're shutting down the driver */ | | 1804 | /* Don't try to send when we're shutting down the driver */ |
1805 | if (sc->sc_state != ATU_S_OK) { | | 1805 | if (sc->sc_state != ATU_S_OK) { |
1806 | m_freem(m); | | 1806 | m_freem(m); |
1807 | return(EIO); | | 1807 | return(EIO); |
1808 | } | | 1808 | } |
1809 | | | 1809 | |
1810 | /* | | 1810 | /* |
1811 | * Copy the mbuf data into a contiguous buffer, leaving | | 1811 | * Copy the mbuf data into a contiguous buffer, leaving |
1812 | * enough room for the atmel headers | | 1812 | * enough room for the atmel headers |
1813 | */ | | 1813 | */ |
1814 | len = m->m_pkthdr.len; | | 1814 | len = m->m_pkthdr.len; |
1815 | | | 1815 | |
1816 | m_copydata(m, 0, m->m_pkthdr.len, c->atu_buf + ATU_TX_HDRLEN); | | 1816 | m_copydata(m, 0, m->m_pkthdr.len, c->atu_buf + ATU_TX_HDRLEN); |
1817 | | | 1817 | |
1818 | h = (struct atu_tx_hdr *)c->atu_buf; | | 1818 | h = (struct atu_tx_hdr *)c->atu_buf; |
1819 | memset(h, 0, ATU_TX_HDRLEN); | | 1819 | memset(h, 0, ATU_TX_HDRLEN); |
1820 | USETW(h->length, len); | | 1820 | USETW(h->length, len); |
1821 | h->tx_rate = 4; /* XXX rate = auto */ | | 1821 | h->tx_rate = 4; /* XXX rate = auto */ |
1822 | len += ATU_TX_HDRLEN; | | 1822 | len += ATU_TX_HDRLEN; |
1823 | | | 1823 | |
1824 | pad = atu_calculate_padding(len); | | 1824 | pad = atu_calculate_padding(len); |
1825 | len += pad; | | 1825 | len += pad; |
1826 | h->padding = pad; | | 1826 | h->padding = pad; |
1827 | | | 1827 | |
1828 | c->atu_length = len; | | 1828 | c->atu_length = len; |
1829 | c->atu_mbuf = m; | | 1829 | c->atu_mbuf = m; |
1830 | | | 1830 | |
1831 | usbd_setup_xfer(c->atu_xfer, c, c->atu_buf, c->atu_length, 0, | | 1831 | usbd_setup_xfer(c->atu_xfer, c, c->atu_buf, c->atu_length, 0, |
1832 | ATU_TX_TIMEOUT, atu_txeof); | | 1832 | ATU_TX_TIMEOUT, atu_txeof); |
1833 | | | 1833 | |
1834 | /* Let's get this thing into the air! */ | | 1834 | /* Let's get this thing into the air! */ |
1835 | c->atu_in_xfer = 1; | | 1835 | c->atu_in_xfer = 1; |
1836 | err = usbd_transfer(c->atu_xfer); | | 1836 | err = usbd_transfer(c->atu_xfer); |
1837 | if (err != USBD_IN_PROGRESS) { | | 1837 | if (err != USBD_IN_PROGRESS) { |
1838 | DPRINTFN(25, ("%s: atu_tx_start, err=%d", | | 1838 | DPRINTFN(25, ("%s: atu_tx_start, err=%d", |
1839 | device_xname(sc->atu_dev), err)); | | 1839 | device_xname(sc->atu_dev), err)); |
1840 | c->atu_mbuf = NULL; | | 1840 | c->atu_mbuf = NULL; |
1841 | m_freem(m); | | 1841 | m_freem(m); |
1842 | return(EIO); | | 1842 | return(EIO); |
1843 | } | | 1843 | } |
1844 | | | 1844 | |
1845 | return 0; | | 1845 | return 0; |
1846 | } | | 1846 | } |
1847 | | | 1847 | |
1848 | void | | 1848 | void |
1849 | atu_start(struct ifnet *ifp) | | 1849 | atu_start(struct ifnet *ifp) |
1850 | { | | 1850 | { |
1851 | struct atu_softc *sc = ifp->if_softc; | | 1851 | struct atu_softc *sc = ifp->if_softc; |
1852 | struct ieee80211com *ic = &sc->sc_ic; | | 1852 | struct ieee80211com *ic = &sc->sc_ic; |
1853 | struct atu_cdata *cd = &sc->atu_cdata; | | 1853 | struct atu_cdata *cd = &sc->atu_cdata; |
1854 | struct ieee80211_node *ni; | | 1854 | struct ieee80211_node *ni; |
1855 | struct atu_chain *c; | | 1855 | struct atu_chain *c; |
1856 | struct mbuf *m = NULL; | | 1856 | struct mbuf *m = NULL; |
1857 | int s; | | 1857 | int s; |
1858 | | | 1858 | |
1859 | DPRINTFN(25, ("%s: atu_start: enter\n", device_xname(sc->atu_dev))); | | 1859 | DPRINTFN(25, ("%s: atu_start: enter\n", device_xname(sc->atu_dev))); |
1860 | | | 1860 | |
1861 | if ((ifp->if_flags & IFF_RUNNING) == 0) { | | 1861 | if ((ifp->if_flags & IFF_RUNNING) == 0) { |
1862 | return; | | 1862 | return; |
1863 | } | | 1863 | } |
1864 | if (ifp->if_flags & IFF_OACTIVE) { | | 1864 | if (ifp->if_flags & IFF_OACTIVE) { |
1865 | DPRINTFN(30, ("%s: atu_start: IFF_OACTIVE\n", | | 1865 | DPRINTFN(30, ("%s: atu_start: IFF_OACTIVE\n", |
1866 | device_xname(sc->atu_dev))); | | 1866 | device_xname(sc->atu_dev))); |
1867 | return; | | 1867 | return; |
1868 | } | | 1868 | } |
1869 | | | 1869 | |
1870 | for (;;) { | | 1870 | for (;;) { |
1871 | /* grab a TX buffer */ | | 1871 | /* grab a TX buffer */ |
1872 | s = splnet(); | | 1872 | s = splnet(); |
1873 | c = SLIST_FIRST(&cd->atu_tx_free); | | 1873 | c = SLIST_FIRST(&cd->atu_tx_free); |
1874 | if (c != NULL) { | | 1874 | if (c != NULL) { |
1875 | SLIST_REMOVE_HEAD(&cd->atu_tx_free, atu_list); | | 1875 | SLIST_REMOVE_HEAD(&cd->atu_tx_free, atu_list); |
1876 | cd->atu_tx_inuse++; | | 1876 | cd->atu_tx_inuse++; |
1877 | if (cd->atu_tx_inuse == ATU_TX_LIST_CNT) | | 1877 | if (cd->atu_tx_inuse == ATU_TX_LIST_CNT) |
1878 | ifp->if_flags |= IFF_OACTIVE; | | 1878 | ifp->if_flags |= IFF_OACTIVE; |
1879 | } | | 1879 | } |
1880 | splx(s); | | 1880 | splx(s); |
1881 | if (c == NULL) { | | 1881 | if (c == NULL) { |
1882 | DPRINTFN(10, ("%s: out of tx xfers\n", | | 1882 | DPRINTFN(10, ("%s: out of tx xfers\n", |
1883 | device_xname(sc->atu_dev))); | | 1883 | device_xname(sc->atu_dev))); |
1884 | ifp->if_flags |= IFF_OACTIVE; | | 1884 | ifp->if_flags |= IFF_OACTIVE; |
1885 | break; | | 1885 | break; |
1886 | } | | 1886 | } |
1887 | | | 1887 | |
1888 | /* | | 1888 | /* |
1889 | * Poll the management queue for frames, it has priority over | | 1889 | * Poll the management queue for frames, it has priority over |
1890 | * normal data frames. | | 1890 | * normal data frames. |
1891 | */ | | 1891 | */ |
1892 | IF_DEQUEUE(&ic->ic_mgtq, m); | | 1892 | IF_DEQUEUE(&ic->ic_mgtq, m); |
1893 | if (m == NULL) { | | 1893 | if (m == NULL) { |
1894 | DPRINTFN(10, ("%s: atu_start: data packet\n", | | 1894 | DPRINTFN(10, ("%s: atu_start: data packet\n", |
1895 | device_xname(sc->atu_dev))); | | 1895 | device_xname(sc->atu_dev))); |
1896 | if (ic->ic_state != IEEE80211_S_RUN) { | | 1896 | if (ic->ic_state != IEEE80211_S_RUN) { |
1897 | DPRINTFN(25, ("%s: no data till running\n", | | 1897 | DPRINTFN(25, ("%s: no data till running\n", |
1898 | device_xname(sc->atu_dev))); | | 1898 | device_xname(sc->atu_dev))); |
1899 | /* put the xfer back on the list */ | | 1899 | /* put the xfer back on the list */ |
1900 | s = splnet(); | | 1900 | s = splnet(); |
1901 | SLIST_INSERT_HEAD(&cd->atu_tx_free, c, | | 1901 | SLIST_INSERT_HEAD(&cd->atu_tx_free, c, |
1902 | atu_list); | | 1902 | atu_list); |
1903 | cd->atu_tx_inuse--; | | 1903 | cd->atu_tx_inuse--; |
1904 | splx(s); | | 1904 | splx(s); |
1905 | break; | | 1905 | break; |
1906 | } | | 1906 | } |
1907 | | | 1907 | |
1908 | IFQ_DEQUEUE(&ifp->if_snd, m); | | 1908 | IFQ_DEQUEUE(&ifp->if_snd, m); |
1909 | if (m == NULL) { | | 1909 | if (m == NULL) { |
1910 | DPRINTFN(25, ("%s: nothing to send\n", | | 1910 | DPRINTFN(25, ("%s: nothing to send\n", |
1911 | device_xname(sc->atu_dev))); | | 1911 | device_xname(sc->atu_dev))); |
1912 | s = splnet(); | | 1912 | s = splnet(); |
1913 | SLIST_INSERT_HEAD(&cd->atu_tx_free, c, | | 1913 | SLIST_INSERT_HEAD(&cd->atu_tx_free, c, |
1914 | atu_list); | | 1914 | atu_list); |
1915 | cd->atu_tx_inuse--; | | 1915 | cd->atu_tx_inuse--; |
1916 | splx(s); | | 1916 | splx(s); |
1917 | break; | | 1917 | break; |
1918 | } | | 1918 | } |
1919 | bpf_mtap(ifp, m); | | 1919 | bpf_mtap(ifp, m); |
1920 | ni = ieee80211_find_txnode(ic, | | 1920 | ni = ieee80211_find_txnode(ic, |
1921 | mtod(m, struct ether_header *)->ether_dhost); | | 1921 | mtod(m, struct ether_header *)->ether_dhost); |
1922 | if (ni == NULL) { | | 1922 | if (ni == NULL) { |
1923 | m_freem(m); | | 1923 | m_freem(m); |
1924 | goto bad; | | 1924 | goto bad; |
1925 | } | | 1925 | } |
1926 | m = ieee80211_encap(ic, m, ni); | | 1926 | m = ieee80211_encap(ic, m, ni); |
1927 | if (m == NULL) | | 1927 | if (m == NULL) |
1928 | goto bad; | | 1928 | goto bad; |
1929 | } else { | | 1929 | } else { |
1930 | DPRINTFN(25, ("%s: atu_start: mgmt packet\n", | | 1930 | DPRINTFN(25, ("%s: atu_start: mgmt packet\n", |
1931 | device_xname(sc->atu_dev))); | | 1931 | device_xname(sc->atu_dev))); |
1932 | | | 1932 | |
1933 | /* | | 1933 | /* |
1934 | * Hack! The referenced node pointer is in the | | 1934 | * Hack! The referenced node pointer is in the |
1935 | * rcvif field of the packet header. This is | | 1935 | * rcvif field of the packet header. This is |
1936 | * placed there by ieee80211_mgmt_output because | | 1936 | * placed there by ieee80211_mgmt_output because |
1937 | * we need to hold the reference with the frame | | 1937 | * we need to hold the reference with the frame |
1938 | * and there's no other way (other than packet | | 1938 | * and there's no other way (other than packet |
1939 | * tags which we consider too expensive to use) | | 1939 | * tags which we consider too expensive to use) |
1940 | * to pass it along. | | 1940 | * to pass it along. |
1941 | */ | | 1941 | */ |
1942 | ni = M_GETCTX(m, struct ieee80211_node *); | | 1942 | ni = M_GETCTX(m, struct ieee80211_node *); |
1943 | M_CLEARCTX(m); | | 1943 | M_CLEARCTX(m); |
1944 | | | 1944 | |
1945 | /* sc->sc_stats.ast_tx_mgmt++; */ | | 1945 | /* sc->sc_stats.ast_tx_mgmt++; */ |
1946 | } | | 1946 | } |
1947 | | | 1947 | |
1948 | bpf_mtap3(ic->ic_rawbpf, m); | | 1948 | bpf_mtap3(ic->ic_rawbpf, m); |
1949 | | | 1949 | |
1950 | if (atu_tx_start(sc, ni, c, m)) { | | 1950 | if (atu_tx_start(sc, ni, c, m)) { |
1951 | bad: | | 1951 | bad: |
1952 | s = splnet(); | | 1952 | s = splnet(); |
1953 | SLIST_INSERT_HEAD(&cd->atu_tx_free, c, | | 1953 | SLIST_INSERT_HEAD(&cd->atu_tx_free, c, |
1954 | atu_list); | | 1954 | atu_list); |
1955 | cd->atu_tx_inuse--; | | 1955 | cd->atu_tx_inuse--; |
1956 | splx(s); | | 1956 | splx(s); |
1957 | /* ifp_if_oerrors++; */ | | 1957 | /* ifp_if_oerrors++; */ |
1958 | if (ni != NULL) | | 1958 | if (ni != NULL) |
1959 | ieee80211_free_node(ni); | | 1959 | ieee80211_free_node(ni); |
1960 | continue; | | 1960 | continue; |
1961 | } | | 1961 | } |
1962 | ifp->if_timer = 5; | | 1962 | ifp->if_timer = 5; |
1963 | } | | 1963 | } |
1964 | } | | 1964 | } |
1965 | | | 1965 | |
1966 | int | | 1966 | int |
1967 | atu_init(struct ifnet *ifp) | | 1967 | atu_init(struct ifnet *ifp) |
1968 | { | | 1968 | { |
1969 | struct atu_softc *sc = ifp->if_softc; | | 1969 | struct atu_softc *sc = ifp->if_softc; |
1970 | struct ieee80211com *ic = &sc->sc_ic; | | 1970 | struct ieee80211com *ic = &sc->sc_ic; |
1971 | struct atu_chain *c; | | 1971 | struct atu_chain *c; |
1972 | usbd_status err; | | 1972 | usbd_status err; |
1973 | int i, s; | | 1973 | int i, s; |
1974 | | | 1974 | |
1975 | s = splnet(); | | 1975 | s = splnet(); |
1976 | | | 1976 | |
1977 | DPRINTFN(10, ("%s: atu_init\n", device_xname(sc->atu_dev))); | | 1977 | DPRINTFN(10, ("%s: atu_init\n", device_xname(sc->atu_dev))); |
1978 | | | 1978 | |
1979 | if (ifp->if_flags & IFF_RUNNING) { | | 1979 | if (ifp->if_flags & IFF_RUNNING) { |
1980 | splx(s); | | 1980 | splx(s); |
1981 | return(0); | | 1981 | return(0); |
1982 | } | | 1982 | } |
1983 | | | 1983 | |
1984 | /* Load the multicast filter. */ | | 1984 | /* Load the multicast filter. */ |
1985 | /*atu_setmulti(sc); */ | | 1985 | /*atu_setmulti(sc); */ |
1986 | | | 1986 | |
1987 | /* Open RX and TX pipes. */ | | 1987 | /* Open RX and TX pipes. */ |
1988 | err = usbd_open_pipe(sc->atu_iface, sc->atu_ed[ATU_ENDPT_RX], | | 1988 | err = usbd_open_pipe(sc->atu_iface, sc->atu_ed[ATU_ENDPT_RX], |
1989 | USBD_EXCLUSIVE_USE, &sc->atu_ep[ATU_ENDPT_RX]); | | 1989 | USBD_EXCLUSIVE_USE, &sc->atu_ep[ATU_ENDPT_RX]); |
1990 | if (err) { | | 1990 | if (err) { |
1991 | DPRINTF(("%s: open rx pipe failed: %s\n", | | 1991 | DPRINTF(("%s: open rx pipe failed: %s\n", |
1992 | device_xname(sc->atu_dev), usbd_errstr(err))); | | 1992 | device_xname(sc->atu_dev), usbd_errstr(err))); |
1993 | splx(s); | | 1993 | splx(s); |
1994 | return(EIO); | | 1994 | return(EIO); |
1995 | } | | 1995 | } |
1996 | | | 1996 | |
1997 | err = usbd_open_pipe(sc->atu_iface, sc->atu_ed[ATU_ENDPT_TX], | | 1997 | err = usbd_open_pipe(sc->atu_iface, sc->atu_ed[ATU_ENDPT_TX], |
1998 | USBD_EXCLUSIVE_USE, &sc->atu_ep[ATU_ENDPT_TX]); | | 1998 | USBD_EXCLUSIVE_USE, &sc->atu_ep[ATU_ENDPT_TX]); |
1999 | if (err) { | | 1999 | if (err) { |
2000 | DPRINTF(("%s: open tx pipe failed: %s\n", | | 2000 | DPRINTF(("%s: open tx pipe failed: %s\n", |
2001 | device_xname(sc->atu_dev), usbd_errstr(err))); | | 2001 | device_xname(sc->atu_dev), usbd_errstr(err))); |
2002 | splx(s); | | 2002 | splx(s); |
2003 | return(EIO); | | 2003 | return(EIO); |
2004 | } | | 2004 | } |
2005 | | | 2005 | |
2006 | /* Init TX ring */ | | 2006 | /* Init TX ring */ |
2007 | if (atu_tx_list_init(sc)) | | 2007 | if (atu_tx_list_init(sc)) |
2008 | printf("%s: tx list init failed\n", device_xname(sc->atu_dev)); | | 2008 | printf("%s: tx list init failed\n", device_xname(sc->atu_dev)); |
2009 | | | 2009 | |
2010 | /* Init RX ring */ | | 2010 | /* Init RX ring */ |
2011 | if (atu_rx_list_init(sc)) | | 2011 | if (atu_rx_list_init(sc)) |
2012 | printf("%s: rx list init failed\n", device_xname(sc->atu_dev)); | | 2012 | printf("%s: rx list init failed\n", device_xname(sc->atu_dev)); |
2013 | | | 2013 | |
2014 | /* Start up the receive pipe. */ | | 2014 | /* Start up the receive pipe. */ |
2015 | for (i = 0; i < ATU_RX_LIST_CNT; i++) { | | 2015 | for (i = 0; i < ATU_RX_LIST_CNT; i++) { |
2016 | c = &sc->atu_cdata.atu_rx_chain[i]; | | 2016 | c = &sc->atu_cdata.atu_rx_chain[i]; |
2017 | | | 2017 | |
2018 | usbd_setup_xfer(c->atu_xfer, c, c->atu_buf, ATU_RX_BUFSZ, | | 2018 | usbd_setup_xfer(c->atu_xfer, c, c->atu_buf, ATU_RX_BUFSZ, |
2019 | USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, atu_rxeof); | | 2019 | USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, atu_rxeof); |
2020 | usbd_transfer(c->atu_xfer); | | 2020 | usbd_transfer(c->atu_xfer); |
2021 | } | | 2021 | } |
2022 | | | 2022 | |
2023 | DPRINTFN(10, ("%s: starting up using MAC=%s\n", | | 2023 | DPRINTFN(10, ("%s: starting up using MAC=%s\n", |
2024 | device_xname(sc->atu_dev), ether_sprintf(ic->ic_myaddr))); | | 2024 | device_xname(sc->atu_dev), ether_sprintf(ic->ic_myaddr))); |
2025 | | | 2025 | |
2026 | /* Do initial setup */ | | 2026 | /* Do initial setup */ |
2027 | err = atu_initial_config(sc); | | 2027 | err = atu_initial_config(sc); |
2028 | if (err) { | | 2028 | if (err) { |
2029 | DPRINTF(("%s: initial config failed!\n", | | 2029 | DPRINTF(("%s: initial config failed!\n", |
2030 | device_xname(sc->atu_dev))); | | 2030 | device_xname(sc->atu_dev))); |
2031 | splx(s); | | 2031 | splx(s); |
2032 | return(EIO); | | 2032 | return(EIO); |
2033 | } | | 2033 | } |
2034 | DPRINTFN(10, ("%s: initialised transceiver\n", | | 2034 | DPRINTFN(10, ("%s: initialised transceiver\n", |
2035 | device_xname(sc->atu_dev))); | | 2035 | device_xname(sc->atu_dev))); |
2036 | | | 2036 | |
2037 | /* sc->atu_rxfilt = ATU_RXFILT_UNICAST|ATU_RXFILT_BROADCAST; */ | | 2037 | /* sc->atu_rxfilt = ATU_RXFILT_UNICAST|ATU_RXFILT_BROADCAST; */ |
2038 | | | 2038 | |
2039 | /* If we want promiscuous mode, set the allframes bit. */ | | 2039 | /* If we want promiscuous mode, set the allframes bit. */ |
2040 | /* | | 2040 | /* |
2041 | if (ifp->if_flags & IFF_PROMISC) | | 2041 | if (ifp->if_flags & IFF_PROMISC) |
2042 | sc->atu_rxfilt |= ATU_RXFILT_PROMISC; | | 2042 | sc->atu_rxfilt |= ATU_RXFILT_PROMISC; |
2043 | */ | | 2043 | */ |
2044 | | | 2044 | |
2045 | ifp->if_flags |= IFF_RUNNING; | | 2045 | ifp->if_flags |= IFF_RUNNING; |
2046 | ifp->if_flags &= ~IFF_OACTIVE; | | 2046 | ifp->if_flags &= ~IFF_OACTIVE; |
2047 | splx(s); | | 2047 | splx(s); |
2048 | | | 2048 | |
2049 | /* XXX the following HAS to be replaced */ | | 2049 | /* XXX the following HAS to be replaced */ |
2050 | s = splnet(); | | 2050 | s = splnet(); |
2051 | err = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); | | 2051 | err = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); |
2052 | if (err) { | | 2052 | if (err) { |
2053 | DPRINTFN(1, ("%s: atu_init: error calling " | | 2053 | DPRINTFN(1, ("%s: atu_init: error calling " |
2054 | "ieee80211_net_state", device_xname(sc->atu_dev))); | | 2054 | "ieee80211_net_state", device_xname(sc->atu_dev))); |
2055 | } | | 2055 | } |
2056 | splx(s); | | 2056 | splx(s); |
2057 | | | 2057 | |
2058 | return 0; | | 2058 | return 0; |
2059 | } | | 2059 | } |
2060 | | | 2060 | |
2061 | #ifdef ATU_DEBUG | | 2061 | #ifdef ATU_DEBUG |
2062 | void | | 2062 | void |
2063 | atu_debug_print(struct atu_softc *sc) | | 2063 | atu_debug_print(struct atu_softc *sc) |
2064 | { | | 2064 | { |
2065 | usbd_status err; | | 2065 | usbd_status err; |
2066 | uint8_t tmp[32]; | | 2066 | uint8_t tmp[32]; |
2067 | | | 2067 | |
2068 | /* DEBUG */ | | 2068 | /* DEBUG */ |
2069 | if ((err = atu_get_mib(sc, MIB_MAC_MGMT__CURRENT_BSSID, tmp))) | | 2069 | if ((err = atu_get_mib(sc, MIB_MAC_MGMT__CURRENT_BSSID, tmp))) |
2070 | return; | | 2070 | return; |
2071 | DPRINTF(("%s: DEBUG: current BSSID=%s\n", device_xname(sc->atu_dev), | | 2071 | DPRINTF(("%s: DEBUG: current BSSID=%s\n", device_xname(sc->atu_dev), |
2072 | ether_sprintf(tmp))); | | 2072 | ether_sprintf(tmp))); |
2073 | | | 2073 | |
2074 | if ((err = atu_get_mib(sc, MIB_MAC_MGMT__BEACON_PERIOD, tmp))) | | 2074 | if ((err = atu_get_mib(sc, MIB_MAC_MGMT__BEACON_PERIOD, tmp))) |
2075 | return; | | 2075 | return; |
2076 | DPRINTF(("%s: DEBUG: beacon period=%d\n", device_xname(sc->atu_dev), | | 2076 | DPRINTF(("%s: DEBUG: beacon period=%d\n", device_xname(sc->atu_dev), |
2077 | tmp[0])); | | 2077 | tmp[0])); |
2078 | | | 2078 | |
2079 | if ((err = atu_get_mib(sc, MIB_MAC_WEP__PRIVACY_INVOKED, tmp))) | | 2079 | if ((err = atu_get_mib(sc, MIB_MAC_WEP__PRIVACY_INVOKED, tmp))) |
2080 | return; | | 2080 | return; |
2081 | DPRINTF(("%s: DEBUG: privacy invoked=%d\n", device_xname(sc->atu_dev), | | 2081 | DPRINTF(("%s: DEBUG: privacy invoked=%d\n", device_xname(sc->atu_dev), |
2082 | tmp[0])); | | 2082 | tmp[0])); |
2083 | | | 2083 | |
2084 | if ((err = atu_get_mib(sc, MIB_MAC_WEP__ENCR_LEVEL, tmp))) | | 2084 | if ((err = atu_get_mib(sc, MIB_MAC_WEP__ENCR_LEVEL, tmp))) |
2085 | return; | | 2085 | return; |
2086 | DPRINTF(("%s: DEBUG: encr_level=%d\n", device_xname(sc->atu_dev), | | 2086 | DPRINTF(("%s: DEBUG: encr_level=%d\n", device_xname(sc->atu_dev), |
2087 | tmp[0])); | | 2087 | tmp[0])); |
2088 | | | 2088 | |
2089 | if ((err = atu_get_mib(sc, MIB_MAC_WEP__ICV_ERROR_COUNT, tmp))) | | 2089 | if ((err = atu_get_mib(sc, MIB_MAC_WEP__ICV_ERROR_COUNT, tmp))) |
2090 | return; | | 2090 | return; |
2091 | DPRINTF(("%s: DEBUG: icv error count=%d\n", device_xname(sc->atu_dev), | | 2091 | DPRINTF(("%s: DEBUG: icv error count=%d\n", device_xname(sc->atu_dev), |
2092 | *(short *)tmp)); | | 2092 | *(short *)tmp)); |
2093 | | | 2093 | |
2094 | if ((err = atu_get_mib(sc, MIB_MAC_WEP__EXCLUDED_COUNT, tmp))) | | 2094 | if ((err = atu_get_mib(sc, MIB_MAC_WEP__EXCLUDED_COUNT, tmp))) |
2095 | return; | | 2095 | return; |
2096 | DPRINTF(("%s: DEBUG: wep excluded count=%d\n", | | 2096 | DPRINTF(("%s: DEBUG: wep excluded count=%d\n", |
2097 | device_xname(sc->atu_dev), *(short *)tmp)); | | 2097 | device_xname(sc->atu_dev), *(short *)tmp)); |
2098 | | | 2098 | |
2099 | if ((err = atu_get_mib(sc, MIB_MAC_MGMT__POWER_MODE, tmp))) | | 2099 | if ((err = atu_get_mib(sc, MIB_MAC_MGMT__POWER_MODE, tmp))) |
2100 | return; | | 2100 | return; |
2101 | DPRINTF(("%s: DEBUG: power mode=%d\n", device_xname(sc->atu_dev), | | 2101 | DPRINTF(("%s: DEBUG: power mode=%d\n", device_xname(sc->atu_dev), |
2102 | tmp[0])); | | 2102 | tmp[0])); |
2103 | | | 2103 | |
2104 | if ((err = atu_get_mib(sc, MIB_PHY__CHANNEL, tmp))) | | 2104 | if ((err = atu_get_mib(sc, MIB_PHY__CHANNEL, tmp))) |
2105 | return; | | 2105 | return; |
2106 | DPRINTF(("%s: DEBUG: channel=%d\n", device_xname(sc->atu_dev), tmp[0])); | | 2106 | DPRINTF(("%s: DEBUG: channel=%d\n", device_xname(sc->atu_dev), tmp[0])); |
2107 | | | 2107 | |
2108 | if ((err = atu_get_mib(sc, MIB_PHY__REG_DOMAIN, tmp))) | | 2108 | if ((err = atu_get_mib(sc, MIB_PHY__REG_DOMAIN, tmp))) |
2109 | return; | | 2109 | return; |
2110 | DPRINTF(("%s: DEBUG: reg domain=%d\n", device_xname(sc->atu_dev), | | 2110 | DPRINTF(("%s: DEBUG: reg domain=%d\n", device_xname(sc->atu_dev), |
2111 | tmp[0])); | | 2111 | tmp[0])); |
2112 | | | 2112 | |
2113 | if ((err = atu_get_mib(sc, MIB_LOCAL__SSID_SIZE, tmp))) | | 2113 | if ((err = atu_get_mib(sc, MIB_LOCAL__SSID_SIZE, tmp))) |
2114 | return; | | 2114 | return; |
2115 | DPRINTF(("%s: DEBUG: ssid size=%d\n", device_xname(sc->atu_dev), | | 2115 | DPRINTF(("%s: DEBUG: ssid size=%d\n", device_xname(sc->atu_dev), |
2116 | tmp[0])); | | 2116 | tmp[0])); |
2117 | | | 2117 | |
2118 | if ((err = atu_get_mib(sc, MIB_LOCAL__BEACON_ENABLE, tmp))) | | 2118 | if ((err = atu_get_mib(sc, MIB_LOCAL__BEACON_ENABLE, tmp))) |
2119 | return; | | 2119 | return; |
2120 | DPRINTF(("%s: DEBUG: beacon enable=%d\n", device_xname(sc->atu_dev), | | 2120 | DPRINTF(("%s: DEBUG: beacon enable=%d\n", device_xname(sc->atu_dev), |
2121 | tmp[0])); | | 2121 | tmp[0])); |
2122 | | | 2122 | |
2123 | if ((err = atu_get_mib(sc, MIB_LOCAL__AUTO_RATE_FALLBACK, tmp))) | | 2123 | if ((err = atu_get_mib(sc, MIB_LOCAL__AUTO_RATE_FALLBACK, tmp))) |
2124 | return; | | 2124 | return; |
2125 | DPRINTF(("%s: DEBUG: auto rate fallback=%d\n", | | 2125 | DPRINTF(("%s: DEBUG: auto rate fallback=%d\n", |
2126 | device_xname(sc->atu_dev), tmp[0])); | | 2126 | device_xname(sc->atu_dev), tmp[0])); |
2127 | | | 2127 | |
2128 | if ((err = atu_get_mib(sc, MIB_MAC_ADDR__ADDR, tmp))) | | 2128 | if ((err = atu_get_mib(sc, MIB_MAC_ADDR__ADDR, tmp))) |
2129 | return; | | 2129 | return; |
2130 | DPRINTF(("%s: DEBUG: mac addr=%s\n", device_xname(sc->atu_dev), | | 2130 | DPRINTF(("%s: DEBUG: mac addr=%s\n", device_xname(sc->atu_dev), |
2131 | ether_sprintf(tmp))); | | 2131 | ether_sprintf(tmp))); |
2132 | | | 2132 | |
2133 | if ((err = atu_get_mib(sc, MIB_MAC__DESIRED_SSID, tmp))) | | 2133 | if ((err = atu_get_mib(sc, MIB_MAC__DESIRED_SSID, tmp))) |
2134 | return; | | 2134 | return; |
2135 | DPRINTF(("%s: DEBUG: desired ssid=%s\n", device_xname(sc->atu_dev), | | 2135 | DPRINTF(("%s: DEBUG: desired ssid=%s\n", device_xname(sc->atu_dev), |
2136 | tmp)); | | 2136 | tmp)); |
2137 | | | 2137 | |
2138 | if ((err = atu_get_mib(sc, MIB_MAC_MGMT__CURRENT_ESSID, tmp))) | | 2138 | if ((err = atu_get_mib(sc, MIB_MAC_MGMT__CURRENT_ESSID, tmp))) |
2139 | return; | | 2139 | return; |
2140 | DPRINTF(("%s: DEBUG: current ESSID=%s\n", device_xname(sc->atu_dev), | | 2140 | DPRINTF(("%s: DEBUG: current ESSID=%s\n", device_xname(sc->atu_dev), |
2141 | tmp)); | | 2141 | tmp)); |
2142 | } | | 2142 | } |
2143 | #endif /* ATU_DEBUG */ | | 2143 | #endif /* ATU_DEBUG */ |
2144 | | | 2144 | |
2145 | int | | 2145 | int |
2146 | atu_ioctl(struct ifnet *ifp, u_long command, void *data) | | 2146 | atu_ioctl(struct ifnet *ifp, u_long command, void *data) |
2147 | { | | 2147 | { |
2148 | struct atu_softc *sc = ifp->if_softc; | | 2148 | struct atu_softc *sc = ifp->if_softc; |
2149 | struct ifreq *ifr = (struct ifreq *)data; | | 2149 | struct ifreq *ifr = (struct ifreq *)data; |
2150 | struct ieee80211com *ic = &sc->sc_ic; | | 2150 | struct ieee80211com *ic = &sc->sc_ic; |
2151 | int err = 0, s; | | 2151 | int err = 0, s; |
2152 | | | 2152 | |
2153 | s = splnet(); | | 2153 | s = splnet(); |
2154 | switch (command) { | | 2154 | switch (command) { |
2155 | case SIOCSIFMEDIA: | | 2155 | case SIOCSIFMEDIA: |
2156 | case SIOCGIFMEDIA: | | 2156 | case SIOCGIFMEDIA: |
2157 | err = ifmedia_ioctl(ifp, ifr, &ic->ic_media, command); | | 2157 | err = ifmedia_ioctl(ifp, ifr, &ic->ic_media, command); |
2158 | break; | | 2158 | break; |
2159 | | | 2159 | |
2160 | default: | | 2160 | default: |
2161 | DPRINTFN(15, ("%s: ieee80211_ioctl (%lu)\n", | | 2161 | DPRINTFN(15, ("%s: ieee80211_ioctl (%lu)\n", |
2162 | device_xname(sc->atu_dev), command)); | | 2162 | device_xname(sc->atu_dev), command)); |
2163 | err = ieee80211_ioctl(ic, command, data); | | 2163 | err = ieee80211_ioctl(ic, command, data); |
2164 | break; | | 2164 | break; |
2165 | } | | 2165 | } |
2166 | | | 2166 | |
2167 | if (err == ENETRESET) { | | 2167 | if (err == ENETRESET) { |
2168 | if ((ifp->if_flags & (IFF_RUNNING|IFF_UP)) == | | 2168 | if ((ifp->if_flags & (IFF_RUNNING|IFF_UP)) == |
2169 | (IFF_RUNNING|IFF_UP)) { | | 2169 | (IFF_RUNNING|IFF_UP)) { |
2170 | DPRINTF(("%s: atu_ioctl(): netreset %lu\n", | | 2170 | DPRINTF(("%s: atu_ioctl(): netreset %lu\n", |
2171 | device_xname(sc->atu_dev), command)); | | 2171 | device_xname(sc->atu_dev), command)); |
2172 | ieee80211_new_state(ic, IEEE80211_S_INIT, -1); | | 2172 | ieee80211_new_state(ic, IEEE80211_S_INIT, -1); |
2173 | atu_initial_config(sc); | | 2173 | atu_initial_config(sc); |
2174 | ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); | | 2174 | ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); |
2175 | } | | 2175 | } |
2176 | err = 0; | | 2176 | err = 0; |
2177 | } | | 2177 | } |
2178 | | | 2178 | |
2179 | splx(s); | | 2179 | splx(s); |
2180 | return err; | | 2180 | return err; |
2181 | } | | 2181 | } |
2182 | | | 2182 | |
2183 | void | | 2183 | void |
2184 | atu_watchdog(struct ifnet *ifp) | | 2184 | atu_watchdog(struct ifnet *ifp) |
2185 | { | | 2185 | { |
2186 | struct atu_softc *sc = ifp->if_softc; | | 2186 | struct atu_softc *sc = ifp->if_softc; |
2187 | struct atu_chain *c; | | 2187 | struct atu_chain *c; |
2188 | usbd_status stat; | | 2188 | usbd_status stat; |
2189 | int cnt, s; | | 2189 | int cnt, s; |
2190 | | | 2190 | |
2191 | DPRINTF(("%s: atu_watchdog\n", device_xname(sc->atu_dev))); | | 2191 | DPRINTF(("%s: atu_watchdog\n", device_xname(sc->atu_dev))); |
2192 | | | 2192 | |
2193 | ifp->if_timer = 0; | | 2193 | ifp->if_timer = 0; |
2194 | | | 2194 | |
2195 | if (sc->sc_state != ATU_S_OK || (ifp->if_flags & IFF_RUNNING) == 0) | | 2195 | if (sc->sc_state != ATU_S_OK || (ifp->if_flags & IFF_RUNNING) == 0) |
2196 | return; | | 2196 | return; |
2197 | | | 2197 | |
2198 | sc = ifp->if_softc; | | 2198 | sc = ifp->if_softc; |
2199 | s = splnet(); | | 2199 | s = splnet(); |
2200 | ifp->if_oerrors++; | | 2200 | ifp->if_oerrors++; |
2201 | DPRINTF(("%s: watchdog timeout\n", device_xname(sc->atu_dev))); | | 2201 | DPRINTF(("%s: watchdog timeout\n", device_xname(sc->atu_dev))); |
2202 | | | 2202 | |
2203 | /* | | 2203 | /* |
2204 | * TODO: | | 2204 | * TODO: |
2205 | * we should change this since we have multiple TX tranfers... | | 2205 | * we should change this since we have multiple TX tranfers... |
2206 | */ | | 2206 | */ |
2207 | for (cnt = 0; cnt < ATU_TX_LIST_CNT; cnt++) { | | 2207 | for (cnt = 0; cnt < ATU_TX_LIST_CNT; cnt++) { |
2208 | c = &sc->atu_cdata.atu_tx_chain[cnt]; | | 2208 | c = &sc->atu_cdata.atu_tx_chain[cnt]; |
2209 | if (c->atu_in_xfer) { | | 2209 | if (c->atu_in_xfer) { |
2210 | usbd_get_xfer_status(c->atu_xfer, NULL, NULL, NULL, | | 2210 | usbd_get_xfer_status(c->atu_xfer, NULL, NULL, NULL, |
2211 | &stat); | | 2211 | &stat); |
2212 | atu_txeof(c->atu_xfer, c, stat); | | 2212 | atu_txeof(c->atu_xfer, c, stat); |
2213 | } | | 2213 | } |
2214 | } | | 2214 | } |
2215 | | | 2215 | |
2216 | if (!IFQ_IS_EMPTY(&ifp->if_snd)) | | 2216 | if (!IFQ_IS_EMPTY(&ifp->if_snd)) |
2217 | atu_start(ifp); | | 2217 | atu_start(ifp); |
2218 | splx(s); | | 2218 | splx(s); |
2219 | | | 2219 | |
2220 | ieee80211_watchdog(&sc->sc_ic); | | 2220 | ieee80211_watchdog(&sc->sc_ic); |
2221 | } | | 2221 | } |
2222 | | | 2222 | |
2223 | /* | | 2223 | /* |
2224 | * Stop the adapter and free any mbufs allocated to the | | 2224 | * Stop the adapter and free any mbufs allocated to the |
2225 | * RX and TX lists. | | 2225 | * RX and TX lists. |
2226 | */ | | 2226 | */ |
2227 | void | | 2227 | void |
2228 | atu_stop(struct ifnet *ifp, int disable) | | 2228 | atu_stop(struct ifnet *ifp, int disable) |
2229 | { | | 2229 | { |
2230 | struct atu_softc *sc = ifp->if_softc; | | 2230 | struct atu_softc *sc = ifp->if_softc; |
2231 | struct ieee80211com *ic = &sc->sc_ic; | | 2231 | struct ieee80211com *ic = &sc->sc_ic; |
2232 | struct atu_cdata *cd; | | 2232 | struct atu_cdata *cd; |
2233 | usbd_status err; | | 2233 | usbd_status err; |
2234 | int s; | | 2234 | int s; |
2235 | | | 2235 | |
2236 | s = splnet(); | | 2236 | s = splnet(); |
2237 | ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); | | 2237 | ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); |
2238 | ifp->if_timer = 0; | | 2238 | ifp->if_timer = 0; |
2239 | | | 2239 | |
2240 | usb_rem_task(sc->atu_udev, &sc->sc_task); | | 2240 | usb_rem_task(sc->atu_udev, &sc->sc_task); |
2241 | ieee80211_new_state(ic, IEEE80211_S_INIT, -1); | | 2241 | ieee80211_new_state(ic, IEEE80211_S_INIT, -1); |
2242 | | | 2242 | |
2243 | /* Stop transfers. */ | | 2243 | /* Stop transfers. */ |
2244 | if (sc->atu_ep[ATU_ENDPT_RX] != NULL) { | | 2244 | if (sc->atu_ep[ATU_ENDPT_RX] != NULL) { |
2245 | err = usbd_abort_pipe(sc->atu_ep[ATU_ENDPT_RX]); | | 2245 | err = usbd_abort_pipe(sc->atu_ep[ATU_ENDPT_RX]); |
2246 | if (err) { | | 2246 | if (err) { |
2247 | DPRINTF(("%s: abort rx pipe failed: %s\n", | | 2247 | DPRINTF(("%s: abort rx pipe failed: %s\n", |
2248 | device_xname(sc->atu_dev), usbd_errstr(err))); | | 2248 | device_xname(sc->atu_dev), usbd_errstr(err))); |
2249 | } | | 2249 | } |
2250 | } | | 2250 | } |
2251 | | | 2251 | |
2252 | if (sc->atu_ep[ATU_ENDPT_TX] != NULL) { | | 2252 | if (sc->atu_ep[ATU_ENDPT_TX] != NULL) { |
2253 | err = usbd_abort_pipe(sc->atu_ep[ATU_ENDPT_TX]); | | 2253 | err = usbd_abort_pipe(sc->atu_ep[ATU_ENDPT_TX]); |
2254 | if (err) { | | 2254 | if (err) { |
2255 | DPRINTF(("%s: abort tx pipe failed: %s\n", | | 2255 | DPRINTF(("%s: abort tx pipe failed: %s\n", |
2256 | device_xname(sc->atu_dev), usbd_errstr(err))); | | 2256 | device_xname(sc->atu_dev), usbd_errstr(err))); |
2257 | } | | 2257 | } |
2258 | } | | 2258 | } |
2259 | | | 2259 | |
2260 | /* Free RX/TX/MGMT list resources. */ | | 2260 | /* Free RX/TX/MGMT list resources. */ |
2261 | cd = &sc->atu_cdata; | | 2261 | cd = &sc->atu_cdata; |
2262 | atu_xfer_list_free(sc, cd->atu_rx_chain, ATU_RX_LIST_CNT); | | 2262 | atu_xfer_list_free(sc, cd->atu_rx_chain, ATU_RX_LIST_CNT); |
2263 | atu_xfer_list_free(sc, cd->atu_tx_chain, ATU_TX_LIST_CNT); | | 2263 | atu_xfer_list_free(sc, cd->atu_tx_chain, ATU_TX_LIST_CNT); |
2264 | | | 2264 | |
2265 | /* Close pipes */ | | 2265 | /* Close pipes */ |
2266 | if (sc->atu_ep[ATU_ENDPT_RX] != NULL) { | | 2266 | if (sc->atu_ep[ATU_ENDPT_RX] != NULL) { |
2267 | err = usbd_close_pipe(sc->atu_ep[ATU_ENDPT_RX]); | | 2267 | err = usbd_close_pipe(sc->atu_ep[ATU_ENDPT_RX]); |
2268 | if (err) { | | 2268 | if (err) { |
2269 | DPRINTF(("%s: close rx pipe failed: %s\n", | | 2269 | DPRINTF(("%s: close rx pipe failed: %s\n", |
2270 | device_xname(sc->atu_dev), usbd_errstr(err))); | | 2270 | device_xname(sc->atu_dev), usbd_errstr(err))); |
2271 | } | | 2271 | } |
2272 | sc->atu_ep[ATU_ENDPT_RX] = NULL; | | 2272 | sc->atu_ep[ATU_ENDPT_RX] = NULL; |
2273 | } | | 2273 | } |
2274 | | | 2274 | |
2275 | if (sc->atu_ep[ATU_ENDPT_TX] != NULL) { | | 2275 | if (sc->atu_ep[ATU_ENDPT_TX] != NULL) { |
2276 | err = usbd_close_pipe(sc->atu_ep[ATU_ENDPT_TX]); | | 2276 | err = usbd_close_pipe(sc->atu_ep[ATU_ENDPT_TX]); |
2277 | if (err) { | | 2277 | if (err) { |
2278 | DPRINTF(("%s: close tx pipe failed: %s\n", | | 2278 | DPRINTF(("%s: close tx pipe failed: %s\n", |
2279 | device_xname(sc->atu_dev), usbd_errstr(err))); | | 2279 | device_xname(sc->atu_dev), usbd_errstr(err))); |
2280 | } | | 2280 | } |
2281 | sc->atu_ep[ATU_ENDPT_TX] = NULL; | | 2281 | sc->atu_ep[ATU_ENDPT_TX] = NULL; |
2282 | } | | 2282 | } |