]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/winbond/wbusb.c
67847c8ad28c4c4e4cf679cff8dec3c20af6be2f
[linux-2.6-omap-h63xx.git] / drivers / staging / winbond / wbusb.c
1 /*
2  * Copyright 2008 Pavel Machek <pavel@suse.cz>
3  *
4  * Distribute under GPLv2.
5  */
6 #include <net/mac80211.h>
7 #include <linux/usb.h>
8
9 #include "core.h"
10 #include "mlmetxrx_f.h"
11 #include "wbhal_f.h"
12 #include "wblinux_f.h"
13
14 MODULE_AUTHOR("Original by: Jeff Lee<YY_Lee@issc.com.tw> Adapted to 2.6.x by Costantino Leandro (Rxart Desktop) <le_costantino@pixartargentina.com.ar>");
15 MODULE_DESCRIPTION("IS89C35 802.11bg WLAN USB Driver");
16 MODULE_LICENSE("GPL");
17 MODULE_VERSION("0.1");
18
19 static struct usb_device_id wb35_table[] __devinitdata = {
20         {USB_DEVICE(0x0416, 0x0035)},
21         {USB_DEVICE(0x18E8, 0x6201)},
22         {USB_DEVICE(0x18E8, 0x6206)},
23         {USB_DEVICE(0x18E8, 0x6217)},
24         {USB_DEVICE(0x18E8, 0x6230)},
25         {USB_DEVICE(0x18E8, 0x6233)},
26         {USB_DEVICE(0x1131, 0x2035)},
27         { 0, }
28 };
29
30 MODULE_DEVICE_TABLE(usb, wb35_table);
31
32 static struct ieee80211_rate wbsoft_rates[] = {
33         { .bitrate = 10, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
34 };
35
36 static struct ieee80211_channel wbsoft_channels[] = {
37         { .center_freq = 2412},
38 };
39
40 static struct ieee80211_supported_band wbsoft_band_2GHz = {
41         .channels       = wbsoft_channels,
42         .n_channels     = ARRAY_SIZE(wbsoft_channels),
43         .bitrates       = wbsoft_rates,
44         .n_bitrates     = ARRAY_SIZE(wbsoft_rates),
45 };
46
47 int wbsoft_enabled;
48
49 static int wbsoft_add_interface(struct ieee80211_hw *dev,
50                                  struct ieee80211_if_init_conf *conf)
51 {
52         printk("wbsoft_add interface called\n");
53         return 0;
54 }
55
56 static void wbsoft_remove_interface(struct ieee80211_hw *dev,
57                                      struct ieee80211_if_init_conf *conf)
58 {
59         printk("wbsoft_remove interface called\n");
60 }
61
62 static void wbsoft_stop(struct ieee80211_hw *hw)
63 {
64         printk(KERN_INFO "%s called\n", __func__);
65 }
66
67 static int wbsoft_get_stats(struct ieee80211_hw *hw,
68                             struct ieee80211_low_level_stats *stats)
69 {
70         printk(KERN_INFO "%s called\n", __func__);
71         return 0;
72 }
73
74 static int wbsoft_get_tx_stats(struct ieee80211_hw *hw,
75                                struct ieee80211_tx_queue_stats *stats)
76 {
77         printk(KERN_INFO "%s called\n", __func__);
78         return 0;
79 }
80
81 static void wbsoft_configure_filter(struct ieee80211_hw *dev,
82                                      unsigned int changed_flags,
83                                      unsigned int *total_flags,
84                                      int mc_count, struct dev_mc_list *mclist)
85 {
86         unsigned int bit_nr, new_flags;
87         u32 mc_filter[2];
88         int i;
89
90         new_flags = 0;
91
92         if (*total_flags & FIF_PROMISC_IN_BSS) {
93                 new_flags |= FIF_PROMISC_IN_BSS;
94                 mc_filter[1] = mc_filter[0] = ~0;
95         } else if ((*total_flags & FIF_ALLMULTI) || (mc_count > 32)) {
96                 new_flags |= FIF_ALLMULTI;
97                 mc_filter[1] = mc_filter[0] = ~0;
98         } else {
99                 mc_filter[1] = mc_filter[0] = 0;
100                 for (i = 0; i < mc_count; i++) {
101                         if (!mclist)
102                                 break;
103                         printk("Should call ether_crc here\n");
104                         //bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
105                         bit_nr = 0;
106
107                         bit_nr &= 0x3F;
108                         mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
109                         mclist = mclist->next;
110                 }
111         }
112
113         dev->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
114
115         *total_flags = new_flags;
116 }
117
118 static int wbsoft_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
119 {
120         struct wbsoft_priv *priv = dev->priv;
121
122         MLMESendFrame(priv, skb->data, skb->len, FRAME_TYPE_802_11_MANAGEMENT);
123
124         return NETDEV_TX_OK;
125 }
126
127
128 static int wbsoft_start(struct ieee80211_hw *dev)
129 {
130         wbsoft_enabled = 1;
131         printk("wbsoft_start called\n");
132         return 0;
133 }
134
135 static int wbsoft_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf)
136 {
137         struct wbsoft_priv *priv = dev->priv;
138
139         ChanInfo ch;
140         printk("wbsoft_config called\n");
141
142         ch.band = 1;
143         ch.ChanNo = 1;  /* Should use channel_num, or something, as that is already pre-translated */
144
145
146         hal_set_current_channel(&priv->sHwData, ch);
147         hal_set_beacon_period(&priv->sHwData, conf->beacon_int);
148 //      hal_set_cap_info(&priv->sHwData, ?? );
149 // hal_set_ssid(phw_data_t pHwData,  u8 * pssid,  u8 ssid_len); ??
150         hal_set_accept_broadcast(&priv->sHwData, 1);
151         hal_set_accept_promiscuous(&priv->sHwData,  1);
152         hal_set_accept_multicast(&priv->sHwData,  1);
153         hal_set_accept_beacon(&priv->sHwData,  1);
154         hal_set_radio_mode(&priv->sHwData,  0);
155         //hal_set_antenna_number(  phw_data_t pHwData, u8 number )
156         //hal_set_rf_power(phw_data_t pHwData, u8 PowerIndex)
157
158
159 //      hal_start_bss(&priv->sHwData, WLAN_BSSTYPE_INFRASTRUCTURE);     ??
160
161 //void hal_set_rates(phw_data_t pHwData, u8 * pbss_rates,
162 //                 u8 length, unsigned char basic_rate_set)
163
164         return 0;
165 }
166
167 static int wbsoft_config_interface(struct ieee80211_hw *dev,
168                                     struct ieee80211_vif *vif,
169                                     struct ieee80211_if_conf *conf)
170 {
171         printk("wbsoft_config_interface called\n");
172         return 0;
173 }
174
175 static u64 wbsoft_get_tsf(struct ieee80211_hw *dev)
176 {
177         printk("wbsoft_get_tsf called\n");
178         return 0;
179 }
180
181 static const struct ieee80211_ops wbsoft_ops = {
182         .tx                     = wbsoft_tx,
183         .start                  = wbsoft_start,         /* Start can be pretty much empty as we do WbWLanInitialize() during probe? */
184         .stop                   = wbsoft_stop,
185         .add_interface          = wbsoft_add_interface,
186         .remove_interface       = wbsoft_remove_interface,
187         .config                 = wbsoft_config,
188         .config_interface       = wbsoft_config_interface,
189         .configure_filter       = wbsoft_configure_filter,
190         .get_stats              = wbsoft_get_stats,
191         .get_tx_stats           = wbsoft_get_tx_stats,
192         .get_tsf                = wbsoft_get_tsf,
193 // conf_tx: hal_set_cwmin()/hal_set_cwmax;
194 };
195
196 static int wb35_probe(struct usb_interface *intf, const struct usb_device_id *id_table)
197 {
198         PWBUSB          pWbUsb;
199         struct usb_host_interface *interface;
200         struct usb_endpoint_descriptor *endpoint;
201         u32     ltmp;
202         struct usb_device *udev = interface_to_usbdev(intf);
203         struct wbsoft_priv *priv;
204         struct ieee80211_hw *dev;
205         int err;
206
207         usb_get_dev(udev);
208
209         // 20060630.2 Check the device if it already be opened
210         err = usb_control_msg(udev, usb_rcvctrlpipe( udev, 0 ),
211                               0x01, USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_DIR_IN,
212                               0x0, 0x400, &ltmp, 4, HZ*100 );
213         if (err)
214                 goto error;
215
216         ltmp = cpu_to_le32(ltmp);
217         if (ltmp) {  // Is already initialized?
218                 err = -EBUSY;
219                 goto error;
220         }
221
222         dev = ieee80211_alloc_hw(sizeof(*priv), &wbsoft_ops);
223         if (!dev)
224                 goto error;
225
226         priv = dev->priv;
227
228         pWbUsb = &priv->sHwData.WbUsb;
229         pWbUsb->udev = udev;
230
231         interface = intf->cur_altsetting;
232         endpoint = &interface->endpoint[0].desc;
233
234         if (endpoint[2].wMaxPacketSize == 512) {
235                 printk("[w35und] Working on USB 2.0\n");
236                 pWbUsb->IsUsb20 = 1;
237         }
238
239         if (!WbWLanInitialize(dev)) {
240                 err = -EINVAL;
241                 goto error_free_hw;
242         }
243
244         SET_IEEE80211_DEV(dev, &udev->dev);
245         {
246                 phw_data_t pHwData = &priv->sHwData;
247                 unsigned char           dev_addr[MAX_ADDR_LEN];
248                 hal_get_permanent_address(pHwData, dev_addr);
249                 SET_IEEE80211_PERM_ADDR(dev, dev_addr);
250         }
251
252         dev->extra_tx_headroom = 12;    /* FIXME */
253         dev->flags = 0;
254
255         dev->channel_change_time = 1000;
256         dev->queues = 1;
257
258         dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &wbsoft_band_2GHz;
259
260         err = ieee80211_register_hw(dev);
261         if (err)
262                 goto error_free_hw;
263
264         usb_set_intfdata(intf, priv);
265
266         return 0;
267
268 error_free_hw:
269         ieee80211_free_hw(dev);
270 error:
271         usb_put_dev(udev);
272         return err;
273 }
274
275 void packet_came(struct ieee80211_hw *hw, char *pRxBufferAddress, int PacketSize)
276 {
277         struct sk_buff *skb;
278         struct ieee80211_rx_status rx_status = {0};
279
280         if (!wbsoft_enabled)
281                 return;
282
283         skb = dev_alloc_skb(PacketSize);
284         if (!skb) {
285                 printk("Not enough memory for packet, FIXME\n");
286                 return;
287         }
288
289         memcpy(skb_put(skb, PacketSize),
290                pRxBufferAddress,
291                PacketSize);
292
293 /*
294         rx_status.rate = 10;
295         rx_status.channel = 1;
296         rx_status.freq = 12345;
297         rx_status.phymode = MODE_IEEE80211B;
298 */
299
300         ieee80211_rx_irqsafe(hw, skb, &rx_status);
301 }
302
303 static void wb35_disconnect(struct usb_interface *intf)
304 {
305         struct wbsoft_priv *priv = usb_get_intfdata(intf);
306
307         WbWlanHalt(priv);
308
309         usb_set_intfdata(intf, NULL);
310         usb_put_dev(interface_to_usbdev(intf));
311 }
312
313 static struct usb_driver wb35_driver = {
314         .name           = "w35und",
315         .id_table       = wb35_table,
316         .probe          = wb35_probe,
317         .disconnect     = wb35_disconnect,
318 };
319
320 static int __init wb35_init(void)
321 {
322         return usb_register(&wb35_driver);
323 }
324
325 static void __exit wb35_exit(void)
326 {
327         usb_deregister(&wb35_driver);
328 }
329
330 module_init(wb35_init);
331 module_exit(wb35_exit);