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