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