Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 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 | |
Pekka Enberg | dd38da4 | 2008-10-21 13:01:42 +0300 | [diff] [blame] | 9 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 10 | MODULE_DESCRIPTION(DRIVER_DESC); |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 11 | MODULE_LICENSE("GPL"); |
| 12 | MODULE_VERSION("0.1"); |
| 13 | |
Pekka Enberg | dd38da4 | 2008-10-21 13:01:42 +0300 | [diff] [blame] | 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)}, |
Greg Kroah-Hartman | 68ab0c9 | 2008-10-21 10:41:45 -0700 | [diff] [blame] | 22 | { 0, } |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 23 | }; |
| 24 | |
Pekka Enberg | dd38da4 | 2008-10-21 13:01:42 +0300 | [diff] [blame] | 25 | MODULE_DEVICE_TABLE(usb, wb35_table); |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 26 | |
Greg Kroah-Hartman | 68ab0c9 | 2008-10-21 10:41:45 -0700 | [diff] [blame] | 27 | static struct ieee80211_rate wbsoft_rates[] = { |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 28 | { .bitrate = 10, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 29 | }; |
| 30 | |
Greg Kroah-Hartman | 68ab0c9 | 2008-10-21 10:41:45 -0700 | [diff] [blame] | 31 | static struct ieee80211_channel wbsoft_channels[] = { |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 32 | { .center_freq = 2412}, |
| 33 | }; |
| 34 | |
| 35 | int wbsoft_enabled; |
| 36 | struct ieee80211_hw *my_dev; |
| 37 | PADAPTER 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 | |
Greg Kroah-Hartman | 68ab0c9 | 2008-10-21 10:41:45 -0700 | [diff] [blame] | 52 | static void wbsoft_stop(struct ieee80211_hw *hw) |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 53 | { |
Greg Kroah-Hartman | 68ab0c9 | 2008-10-21 10:41:45 -0700 | [diff] [blame] | 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__); |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 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 | |
Greg Kroah-Hartman | 68ab0c9 | 2008-10-21 10:41:45 -0700 | [diff] [blame] | 108 | static int wbsoft_tx(struct ieee80211_hw *dev, struct sk_buff *skb) |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 109 | { |
| 110 | char *buffer = kmalloc(skb->len, GFP_ATOMIC); |
| 111 | printk("Sending frame %d bytes\n", skb->len); |
| 112 | memcpy(buffer, skb->data, skb->len); |
| 113 | if (1 == MLMESendFrame(my_adapter, buffer, skb->len, FRAME_TYPE_802_11_MANAGEMENT)) |
| 114 | printk("frame sent ok (%d bytes)?\n", skb->len); |
| 115 | return NETDEV_TX_OK; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | static int wbsoft_start(struct ieee80211_hw *dev) |
| 120 | { |
| 121 | wbsoft_enabled = 1; |
| 122 | printk("wbsoft_start called\n"); |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static int wbsoft_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf) |
| 127 | { |
| 128 | ChanInfo ch; |
| 129 | printk("wbsoft_config called\n"); |
| 130 | |
| 131 | ch.band = 1; |
| 132 | ch.ChanNo = 1; /* Should use channel_num, or something, as that is already pre-translated */ |
| 133 | |
| 134 | |
| 135 | hal_set_current_channel(&my_adapter->sHwData, ch); |
| 136 | hal_set_beacon_period(&my_adapter->sHwData, conf->beacon_int); |
| 137 | // hal_set_cap_info(&my_adapter->sHwData, ?? ); |
Pekka Enberg | 8b384e0 | 2008-10-21 00:03:41 +0300 | [diff] [blame] | 138 | // hal_set_ssid(phw_data_t pHwData, u8 * pssid, u8 ssid_len); ?? |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 139 | hal_set_accept_broadcast(&my_adapter->sHwData, 1); |
| 140 | hal_set_accept_promiscuous(&my_adapter->sHwData, 1); |
| 141 | hal_set_accept_multicast(&my_adapter->sHwData, 1); |
| 142 | hal_set_accept_beacon(&my_adapter->sHwData, 1); |
| 143 | hal_set_radio_mode(&my_adapter->sHwData, 0); |
| 144 | //hal_set_antenna_number( phw_data_t pHwData, u8 number ) |
| 145 | //hal_set_rf_power(phw_data_t pHwData, u8 PowerIndex) |
| 146 | |
| 147 | |
| 148 | // hal_start_bss(&my_adapter->sHwData, WLAN_BSSTYPE_INFRASTRUCTURE); ?? |
| 149 | |
Pekka Enberg | 8b384e0 | 2008-10-21 00:03:41 +0300 | [diff] [blame] | 150 | //void hal_set_rates(phw_data_t pHwData, u8 * pbss_rates, |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 151 | // u8 length, unsigned char basic_rate_set) |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static int wbsoft_config_interface(struct ieee80211_hw *dev, |
| 157 | struct ieee80211_vif *vif, |
| 158 | struct ieee80211_if_conf *conf) |
| 159 | { |
| 160 | printk("wbsoft_config_interface called\n"); |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | static u64 wbsoft_get_tsf(struct ieee80211_hw *dev) |
| 165 | { |
| 166 | printk("wbsoft_get_tsf called\n"); |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static const struct ieee80211_ops wbsoft_ops = { |
| 171 | .tx = wbsoft_tx, |
| 172 | .start = wbsoft_start, /* Start can be pretty much empty as we do WbWLanInitialize() during probe? */ |
Greg Kroah-Hartman | 68ab0c9 | 2008-10-21 10:41:45 -0700 | [diff] [blame] | 173 | .stop = wbsoft_stop, |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 174 | .add_interface = wbsoft_add_interface, |
| 175 | .remove_interface = wbsoft_remove_interface, |
| 176 | .config = wbsoft_config, |
| 177 | .config_interface = wbsoft_config_interface, |
| 178 | .configure_filter = wbsoft_configure_filter, |
Greg Kroah-Hartman | 68ab0c9 | 2008-10-21 10:41:45 -0700 | [diff] [blame] | 179 | .get_stats = wbsoft_get_stats, |
| 180 | .get_tx_stats = wbsoft_get_tx_stats, |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 181 | .get_tsf = wbsoft_get_tsf, |
| 182 | // conf_tx: hal_set_cwmin()/hal_set_cwmax; |
| 183 | }; |
| 184 | |
| 185 | struct wbsoft_priv { |
| 186 | }; |
| 187 | |
Pekka Enberg | 302bae8 | 2008-10-22 19:05:54 +0300 | [diff] [blame^] | 188 | static int wb35_probe(struct usb_interface *intf, const struct usb_device_id *id_table) |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 189 | { |
| 190 | PADAPTER Adapter; |
| 191 | PWBLINUX pWbLinux; |
| 192 | PWBUSB pWbUsb; |
| 193 | struct usb_host_interface *interface; |
| 194 | struct usb_endpoint_descriptor *endpoint; |
Pekka Enberg | dd38da4 | 2008-10-21 13:01:42 +0300 | [diff] [blame] | 195 | int ret = -1; |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 196 | u32 ltmp; |
| 197 | struct usb_device *udev = interface_to_usbdev(intf); |
| 198 | |
| 199 | usb_get_dev(udev); |
| 200 | |
| 201 | printk("[w35und]wb35_probe ->\n"); |
| 202 | |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 203 | // 20060630.2 Check the device if it already be opened |
| 204 | ret = usb_control_msg(udev, usb_rcvctrlpipe( udev, 0 ), |
| 205 | 0x01, USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_DIR_IN, |
| 206 | 0x0, 0x400, <mp, 4, HZ*100 ); |
| 207 | if (ret < 0) |
| 208 | goto error; |
| 209 | |
| 210 | ltmp = cpu_to_le32(ltmp); |
| 211 | if (ltmp) // Is already initialized? |
| 212 | goto error; |
| 213 | |
| 214 | Adapter = kzalloc(sizeof(ADAPTER), GFP_KERNEL); |
| 215 | |
| 216 | my_adapter = Adapter; |
| 217 | pWbLinux = &Adapter->WbLinux; |
| 218 | pWbUsb = &Adapter->sHwData.WbUsb; |
| 219 | pWbUsb->udev = udev; |
| 220 | |
| 221 | interface = intf->cur_altsetting; |
| 222 | endpoint = &interface->endpoint[0].desc; |
| 223 | |
| 224 | if (endpoint[2].wMaxPacketSize == 512) { |
| 225 | printk("[w35und] Working on USB 2.0\n"); |
| 226 | pWbUsb->IsUsb20 = 1; |
| 227 | } |
| 228 | |
| 229 | if (!WbWLanInitialize(Adapter)) { |
| 230 | printk("[w35und]WbWLanInitialize fail\n"); |
| 231 | goto error; |
| 232 | } |
| 233 | |
| 234 | { |
| 235 | struct wbsoft_priv *priv; |
| 236 | struct ieee80211_hw *dev; |
Greg Kroah-Hartman | 68ab0c9 | 2008-10-21 10:41:45 -0700 | [diff] [blame] | 237 | static struct ieee80211_supported_band band; |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 238 | int res; |
| 239 | |
| 240 | dev = ieee80211_alloc_hw(sizeof(*priv), &wbsoft_ops); |
| 241 | |
| 242 | if (!dev) { |
| 243 | printk("w35und: ieee80211 alloc failed\n" ); |
| 244 | BUG(); |
| 245 | } |
| 246 | |
| 247 | my_dev = dev; |
| 248 | |
| 249 | SET_IEEE80211_DEV(dev, &udev->dev); |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 250 | { |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 251 | phw_data_t pHwData = &Adapter->sHwData; |
| 252 | unsigned char dev_addr[MAX_ADDR_LEN]; |
| 253 | hal_get_permanent_address(pHwData, dev_addr); |
| 254 | SET_IEEE80211_PERM_ADDR(dev, dev_addr); |
| 255 | } |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 256 | |
| 257 | |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 258 | dev->extra_tx_headroom = 12; /* FIXME */ |
| 259 | dev->flags = 0; |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 260 | |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 261 | dev->channel_change_time = 1000; |
| 262 | // dev->max_rssi = 100; |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 263 | |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 264 | dev->queues = 1; |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 265 | |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 266 | band.channels = wbsoft_channels; |
| 267 | band.n_channels = ARRAY_SIZE(wbsoft_channels); |
| 268 | band.bitrates = wbsoft_rates; |
| 269 | band.n_bitrates = ARRAY_SIZE(wbsoft_rates); |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 270 | |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 271 | dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band; |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 272 | #if 0 |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 273 | wbsoft_modes[0].num_channels = 1; |
| 274 | wbsoft_modes[0].channels = wbsoft_channels; |
| 275 | wbsoft_modes[0].mode = MODE_IEEE80211B; |
| 276 | wbsoft_modes[0].num_rates = ARRAY_SIZE(wbsoft_rates); |
| 277 | wbsoft_modes[0].rates = wbsoft_rates; |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 278 | |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 279 | res = ieee80211_register_hwmode(dev, &wbsoft_modes[0]); |
| 280 | BUG_ON(res); |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 281 | #endif |
| 282 | |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 283 | res = ieee80211_register_hw(dev); |
| 284 | BUG_ON(res); |
| 285 | } |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 286 | |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 287 | usb_set_intfdata( intf, Adapter ); |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 288 | |
Pekka Enberg | dc7e04f | 2008-10-21 12:14:58 +0300 | [diff] [blame] | 289 | printk("[w35und] _probe OK\n"); |
| 290 | return 0; |
| 291 | error: |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 292 | return -ENOMEM; |
| 293 | } |
| 294 | |
| 295 | void packet_came(char *pRxBufferAddress, int PacketSize) |
| 296 | { |
| 297 | struct sk_buff *skb; |
| 298 | struct ieee80211_rx_status rx_status = {0}; |
| 299 | |
| 300 | if (!wbsoft_enabled) |
| 301 | return; |
| 302 | |
| 303 | skb = dev_alloc_skb(PacketSize); |
| 304 | if (!skb) { |
| 305 | printk("Not enough memory for packet, FIXME\n"); |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | memcpy(skb_put(skb, PacketSize), |
| 310 | pRxBufferAddress, |
| 311 | PacketSize); |
| 312 | |
| 313 | /* |
| 314 | rx_status.rate = 10; |
| 315 | rx_status.channel = 1; |
| 316 | rx_status.freq = 12345; |
| 317 | rx_status.phymode = MODE_IEEE80211B; |
| 318 | */ |
| 319 | |
| 320 | ieee80211_rx_irqsafe(my_dev, skb, &rx_status); |
| 321 | } |
| 322 | |
| 323 | unsigned char |
| 324 | WbUsb_initial(phw_data_t pHwData) |
| 325 | { |
| 326 | return 1; |
| 327 | } |
| 328 | |
| 329 | |
| 330 | void |
| 331 | WbUsb_destroy(phw_data_t pHwData) |
| 332 | { |
| 333 | } |
| 334 | |
Pekka Enberg | 302bae8 | 2008-10-22 19:05:54 +0300 | [diff] [blame^] | 335 | static void wb35_disconnect(struct usb_interface *intf) |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 336 | { |
| 337 | PWBLINUX pWbLinux; |
| 338 | PADAPTER Adapter = usb_get_intfdata(intf); |
| 339 | usb_set_intfdata(intf, NULL); |
| 340 | |
| 341 | pWbLinux = &Adapter->WbLinux; |
| 342 | |
| 343 | // Card remove |
| 344 | WbWlanHalt(Adapter); |
| 345 | |
| 346 | } |
| 347 | |
Pekka Enberg | dd38da4 | 2008-10-21 13:01:42 +0300 | [diff] [blame] | 348 | static struct usb_driver wb35_driver = { |
| 349 | .name = "w35und", |
| 350 | .id_table = wb35_table, |
| 351 | .probe = wb35_probe, |
| 352 | .disconnect = wb35_disconnect, |
| 353 | }; |
Pavel Machek | 66101de | 2008-10-01 14:36:56 +0200 | [diff] [blame] | 354 | |
Pekka Enberg | dd38da4 | 2008-10-21 13:01:42 +0300 | [diff] [blame] | 355 | static int __init wb35_init(void) |
| 356 | { |
| 357 | return usb_register(&wb35_driver); |
| 358 | } |
| 359 | |
| 360 | static void __exit wb35_exit(void) |
| 361 | { |
| 362 | usb_deregister(&wb35_driver); |
| 363 | } |
| 364 | |
| 365 | module_init(wb35_init); |
| 366 | module_exit(wb35_exit); |