Staging: w35und: plug memory leak in wbsoft_tx()
[linux-2.6/verdex.git] / drivers / staging / winbond / linux / wbusb.c
blob75213b53a49f2bf999b2dd361c096e41b9da5213
1 /*
2 * Copyright 2008 Pavel Machek <pavel@suse.cz>
4 * Distribute under GPLv2.
5 */
6 #include "sysdef.h"
7 #include <net/mac80211.h>
9 MODULE_AUTHOR(DRIVER_AUTHOR);
10 MODULE_DESCRIPTION(DRIVER_DESC);
11 MODULE_LICENSE("GPL");
12 MODULE_VERSION("0.1");
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, }
25 MODULE_DEVICE_TABLE(usb, wb35_table);
27 static struct ieee80211_rate wbsoft_rates[] = {
28 { .bitrate = 10, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
31 static struct ieee80211_channel wbsoft_channels[] = {
32 { .center_freq = 2412},
35 int wbsoft_enabled;
36 struct ieee80211_hw *my_dev;
37 struct wb35_adapter * my_adapter;
39 static int wbsoft_add_interface(struct ieee80211_hw *dev,
40 struct ieee80211_if_init_conf *conf)
42 printk("wbsoft_add interface called\n");
43 return 0;
46 static void wbsoft_remove_interface(struct ieee80211_hw *dev,
47 struct ieee80211_if_init_conf *conf)
49 printk("wbsoft_remove interface called\n");
52 static void wbsoft_stop(struct ieee80211_hw *hw)
54 printk(KERN_INFO "%s called\n", __func__);
57 static int wbsoft_get_stats(struct ieee80211_hw *hw,
58 struct ieee80211_low_level_stats *stats)
60 printk(KERN_INFO "%s called\n", __func__);
61 return 0;
64 static int wbsoft_get_tx_stats(struct ieee80211_hw *hw,
65 struct ieee80211_tx_queue_stats *stats)
67 printk(KERN_INFO "%s called\n", __func__);
68 return 0;
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)
76 unsigned int bit_nr, new_flags;
77 u32 mc_filter[2];
78 int i;
80 new_flags = 0;
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;
97 bit_nr &= 0x3F;
98 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
99 mclist = mclist->next;
103 dev->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
105 *total_flags = new_flags;
108 static int wbsoft_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
110 MLMESendFrame(my_adapter, skb->data, skb->len, FRAME_TYPE_802_11_MANAGEMENT);
112 return NETDEV_TX_OK;
116 static int wbsoft_start(struct ieee80211_hw *dev)
118 wbsoft_enabled = 1;
119 printk("wbsoft_start called\n");
120 return 0;
123 static int wbsoft_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf)
125 ChanInfo ch;
126 printk("wbsoft_config called\n");
128 ch.band = 1;
129 ch.ChanNo = 1; /* Should use channel_num, or something, as that is already pre-translated */
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)
145 // hal_start_bss(&my_adapter->sHwData, WLAN_BSSTYPE_INFRASTRUCTURE); ??
147 //void hal_set_rates(phw_data_t pHwData, u8 * pbss_rates,
148 // u8 length, unsigned char basic_rate_set)
150 return 0;
153 static int wbsoft_config_interface(struct ieee80211_hw *dev,
154 struct ieee80211_vif *vif,
155 struct ieee80211_if_conf *conf)
157 printk("wbsoft_config_interface called\n");
158 return 0;
161 static u64 wbsoft_get_tsf(struct ieee80211_hw *dev)
163 printk("wbsoft_get_tsf called\n");
164 return 0;
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;
182 struct wbsoft_priv {
185 static int wb35_probe(struct usb_interface *intf, const struct usb_device_id *id_table)
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;
198 usb_get_dev(udev);
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;
207 ltmp = cpu_to_le32(ltmp);
208 if (ltmp) { // Is already initialized?
209 err = -EBUSY;
210 goto error;
213 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
214 if (!adapter) {
215 err = -ENOMEM;
216 goto error;
219 my_adapter = adapter;
220 pWbUsb = &adapter->sHwData.WbUsb;
221 pWbUsb->udev = udev;
223 interface = intf->cur_altsetting;
224 endpoint = &interface->endpoint[0].desc;
226 if (endpoint[2].wMaxPacketSize == 512) {
227 printk("[w35und] Working on USB 2.0\n");
228 pWbUsb->IsUsb20 = 1;
231 if (!WbWLanInitialize(adapter)) {
232 err = -EINVAL;
233 goto error_free_adapter;
236 dev = ieee80211_alloc_hw(sizeof(*priv), &wbsoft_ops);
237 if (!dev)
238 goto error_free_adapter;
240 my_dev = dev;
242 SET_IEEE80211_DEV(dev, &udev->dev);
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);
250 dev->extra_tx_headroom = 12; /* FIXME */
251 dev->flags = 0;
253 dev->channel_change_time = 1000;
254 dev->queues = 1;
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);
261 dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band;
262 err = ieee80211_register_hw(dev);
263 if (err)
264 goto error_free_hw;
266 usb_set_intfdata(intf, adapter);
268 return 0;
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;
279 void packet_came(char *pRxBufferAddress, int PacketSize)
281 struct sk_buff *skb;
282 struct ieee80211_rx_status rx_status = {0};
284 if (!wbsoft_enabled)
285 return;
287 skb = dev_alloc_skb(PacketSize);
288 if (!skb) {
289 printk("Not enough memory for packet, FIXME\n");
290 return;
293 memcpy(skb_put(skb, PacketSize),
294 pRxBufferAddress,
295 PacketSize);
298 rx_status.rate = 10;
299 rx_status.channel = 1;
300 rx_status.freq = 12345;
301 rx_status.phymode = MODE_IEEE80211B;
304 ieee80211_rx_irqsafe(my_dev, skb, &rx_status);
307 static void wb35_disconnect(struct usb_interface *intf)
309 struct wb35_adapter *adapter = usb_get_intfdata(intf);
311 WbWlanHalt(adapter);
313 usb_set_intfdata(intf, NULL);
314 usb_put_dev(interface_to_usbdev(intf));
317 static struct usb_driver wb35_driver = {
318 .name = "w35und",
319 .id_table = wb35_table,
320 .probe = wb35_probe,
321 .disconnect = wb35_disconnect,
324 static int __init wb35_init(void)
326 return usb_register(&wb35_driver);
329 static void __exit wb35_exit(void)
331 usb_deregister(&wb35_driver);
334 module_init(wb35_init);
335 module_exit(wb35_exit);