2 * Copyright 2008 Pavel Machek <pavel@suse.cz>
4 * Distribute under GPLv2.
7 #include <net/mac80211.h>
10 MODULE_AUTHOR( DRIVER_AUTHOR );
11 MODULE_DESCRIPTION( DRIVER_DESC );
12 MODULE_LICENSE("GPL");
13 MODULE_VERSION("0.1");
16 //============================================================
17 // vendor ID and product ID can into here for others
18 //============================================================
19 static struct usb_device_id Id_Table[] =
21 {USB_DEVICE( 0x0416, 0x0035 )},
22 {USB_DEVICE( 0x18E8, 0x6201 )},
23 {USB_DEVICE( 0x18E8, 0x6206 )},
24 {USB_DEVICE( 0x18E8, 0x6217 )},
25 {USB_DEVICE( 0x18E8, 0x6230 )},
26 {USB_DEVICE( 0x18E8, 0x6233 )},
27 {USB_DEVICE( 0x1131, 0x2035 )},
31 MODULE_DEVICE_TABLE(usb, Id_Table);
33 static struct usb_driver wb35_driver = {
36 .disconnect = wb35_disconnect,
40 static const struct ieee80211_rate wbsoft_rates[] = {
41 { .bitrate = 10, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
44 static const struct ieee80211_channel wbsoft_channels[] = {
45 { .center_freq = 2412},
49 struct ieee80211_hw *my_dev;
52 static int wbsoft_add_interface(struct ieee80211_hw *dev,
53 struct ieee80211_if_init_conf *conf)
55 printk("wbsoft_add interface called\n");
59 static void wbsoft_remove_interface(struct ieee80211_hw *dev,
60 struct ieee80211_if_init_conf *conf)
62 printk("wbsoft_remove interface called\n");
65 static int wbsoft_nop(void)
67 printk("wbsoft_nop called\n");
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;
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;
89 mc_filter[1] = mc_filter[0] = 0;
90 for (i = 0; i < mc_count; i++) {
93 printk("Should call ether_crc here\n");
94 //bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
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,
109 struct ieee80211_tx_control *control)
111 char *buffer = kmalloc(skb->len, GFP_ATOMIC);
112 printk("Sending frame %d bytes\n", skb->len);
113 memcpy(buffer, skb->data, skb->len);
114 if (1 == MLMESendFrame(my_adapter, buffer, skb->len, FRAME_TYPE_802_11_MANAGEMENT))
115 printk("frame sent ok (%d bytes)?\n", skb->len);
120 static int wbsoft_start(struct ieee80211_hw *dev)
123 printk("wbsoft_start called\n");
127 static int wbsoft_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf)
130 printk("wbsoft_config called\n");
133 ch.ChanNo = 1; /* Should use channel_num, or something, as that is already pre-translated */
136 hal_set_current_channel(&my_adapter->sHwData, ch);
137 hal_set_beacon_period(&my_adapter->sHwData, conf->beacon_int);
138 // hal_set_cap_info(&my_adapter->sHwData, ?? );
139 // hal_set_ssid(phw_data_t pHwData, u8 * pssid, u8 ssid_len); ??
140 hal_set_accept_broadcast(&my_adapter->sHwData, 1);
141 hal_set_accept_promiscuous(&my_adapter->sHwData, 1);
142 hal_set_accept_multicast(&my_adapter->sHwData, 1);
143 hal_set_accept_beacon(&my_adapter->sHwData, 1);
144 hal_set_radio_mode(&my_adapter->sHwData, 0);
145 //hal_set_antenna_number( phw_data_t pHwData, u8 number )
146 //hal_set_rf_power(phw_data_t pHwData, u8 PowerIndex)
149 // hal_start_bss(&my_adapter->sHwData, WLAN_BSSTYPE_INFRASTRUCTURE); ??
151 //void hal_set_rates(phw_data_t pHwData, u8 * pbss_rates,
152 // u8 length, unsigned char basic_rate_set)
157 static int wbsoft_config_interface(struct ieee80211_hw *dev,
158 struct ieee80211_vif *vif,
159 struct ieee80211_if_conf *conf)
161 printk("wbsoft_config_interface called\n");
165 static u64 wbsoft_get_tsf(struct ieee80211_hw *dev)
167 printk("wbsoft_get_tsf called\n");
171 static const struct ieee80211_ops wbsoft_ops = {
173 .start = wbsoft_start, /* Start can be pretty much empty as we do WbWLanInitialize() during probe? */
175 .add_interface = wbsoft_add_interface,
176 .remove_interface = wbsoft_remove_interface,
177 .config = wbsoft_config,
178 .config_interface = wbsoft_config_interface,
179 .configure_filter = wbsoft_configure_filter,
180 .get_stats = wbsoft_nop,
181 .get_tx_stats = wbsoft_nop,
182 .get_tsf = wbsoft_get_tsf,
183 // conf_tx: hal_set_cwmin()/hal_set_cwmax;
190 int __init wb35_init(void)
192 printk("[w35und]driver init\n");
193 return usb_register(&wb35_driver);
196 void __exit wb35_exit(void)
198 printk("[w35und]driver exit\n");
199 usb_deregister( &wb35_driver );
202 module_init(wb35_init);
203 module_exit(wb35_exit);
205 // Usb kernel subsystem will call this function when a new device is plugged into.
206 int wb35_probe(struct usb_interface *intf, const struct usb_device_id *id_table)
211 struct usb_host_interface *interface;
212 struct usb_endpoint_descriptor *endpoint;
215 struct usb_device *udev = interface_to_usbdev(intf);
219 printk("[w35und]wb35_probe ->\n");
222 for (i=0; i<(sizeof(Id_Table)/sizeof(struct usb_device_id)); i++ ) {
223 if ((udev->descriptor.idVendor == Id_Table[i].idVendor) &&
224 (udev->descriptor.idProduct == Id_Table[i].idProduct)) {
225 printk("[w35und]Found supported hardware\n");
229 if ((i == (sizeof(Id_Table)/sizeof(struct usb_device_id)))) {
230 #ifdef _PE_USB_INI_DUMP_
231 WBDEBUG(("[w35und] This is not the one we are interested about\n"));
236 // 20060630.2 Check the device if it already be opened
237 ret = usb_control_msg(udev, usb_rcvctrlpipe( udev, 0 ),
238 0x01, USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_DIR_IN,
239 0x0, 0x400, <mp, 4, HZ*100 );
243 ltmp = cpu_to_le32(ltmp);
244 if (ltmp) // Is already initialized?
248 Adapter = kzalloc(sizeof(ADAPTER), GFP_KERNEL);
250 my_adapter = Adapter;
251 pWbLinux = &Adapter->WbLinux;
252 pWbUsb = &Adapter->sHwData.WbUsb;
255 interface = intf->cur_altsetting;
256 endpoint = &interface->endpoint[0].desc;
258 if (endpoint[2].wMaxPacketSize == 512) {
259 printk("[w35und] Working on USB 2.0\n");
263 if (!WbWLanInitialize(Adapter)) {
264 printk("[w35und]WbWLanInitialize fail\n");
269 struct wbsoft_priv *priv;
270 struct ieee80211_hw *dev;
273 dev = ieee80211_alloc_hw(sizeof(*priv), &wbsoft_ops);
276 printk("w35und: ieee80211 alloc failed\n" );
282 SET_IEEE80211_DEV(dev, &udev->dev);
284 phw_data_t pHwData = &Adapter->sHwData;
285 unsigned char dev_addr[MAX_ADDR_LEN];
286 hal_get_permanent_address(pHwData, dev_addr);
287 SET_IEEE80211_PERM_ADDR(dev, dev_addr);
291 dev->extra_tx_headroom = 12; /* FIXME */
294 dev->channel_change_time = 1000;
295 // dev->max_rssi = 100;
299 static struct ieee80211_supported_band band;
301 band.channels = wbsoft_channels;
302 band.n_channels = ARRAY_SIZE(wbsoft_channels);
303 band.bitrates = wbsoft_rates;
304 band.n_bitrates = ARRAY_SIZE(wbsoft_rates);
306 dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band;
308 wbsoft_modes[0].num_channels = 1;
309 wbsoft_modes[0].channels = wbsoft_channels;
310 wbsoft_modes[0].mode = MODE_IEEE80211B;
311 wbsoft_modes[0].num_rates = ARRAY_SIZE(wbsoft_rates);
312 wbsoft_modes[0].rates = wbsoft_rates;
314 res = ieee80211_register_hwmode(dev, &wbsoft_modes[0]);
318 res = ieee80211_register_hw(dev);
322 usb_set_intfdata( intf, Adapter );
324 printk("[w35und] _probe OK\n");
332 void packet_came(char *pRxBufferAddress, int PacketSize)
335 struct ieee80211_rx_status rx_status = {0};
340 skb = dev_alloc_skb(PacketSize);
342 printk("Not enough memory for packet, FIXME\n");
346 memcpy(skb_put(skb, PacketSize),
352 rx_status.channel = 1;
353 rx_status.freq = 12345;
354 rx_status.phymode = MODE_IEEE80211B;
357 ieee80211_rx_irqsafe(my_dev, skb, &rx_status);
361 WbUsb_initial(phw_data_t pHwData)
368 WbUsb_destroy(phw_data_t pHwData)
372 int wb35_open(struct net_device *netdev)
374 PADAPTER Adapter = (PADAPTER)netdev->priv;
375 phw_data_t pHwData = &Adapter->sHwData;
377 netif_start_queue(netdev);
379 //TODO : put here temporarily
380 hal_set_accept_broadcast(pHwData, 1); // open accept broadcast
385 int wb35_close(struct net_device *netdev)
387 netif_stop_queue(netdev);
391 void wb35_disconnect(struct usb_interface *intf)
394 PADAPTER Adapter = usb_get_intfdata(intf);
395 usb_set_intfdata(intf, NULL);
397 pWbLinux = &Adapter->WbLinux;