Newer
Older
at76_dbg(DBG_MAC80211, "%s(): changed_flags=0x%08x "
"total_flags=0x%08x",
__func__, changed_flags, *total_flags);
flags = changed_flags & AT76_SUPPORTED_FILTERS;
*total_flags = AT76_SUPPORTED_FILTERS;
/* Bail out after updating flags to prevent a WARN_ON in mac80211. */
if (priv->device_unplugged)
return;
/* FIXME: access to priv->promisc should be protected with
* priv->mtx, but it's impossible because this function needs to be
* atomic */
if (flags && !priv->promisc) {
/* mac80211 wants us to enable promiscuous mode */
priv->promisc = 1;
} else if (!flags && priv->promisc) {
/* we need to disable promiscuous mode */
priv->promisc = 0;
} else
return;
ieee80211_queue_work(hw, &priv->work_set_promisc);
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
}
static int at76_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
struct ieee80211_vif *vif, struct ieee80211_sta *sta,
struct ieee80211_key_conf *key)
{
struct at76_priv *priv = hw->priv;
int i;
at76_dbg(DBG_MAC80211, "%s(): cmd %d key->alg %d key->keyidx %d "
"key->keylen %d",
__func__, cmd, key->alg, key->keyidx, key->keylen);
if (key->alg != ALG_WEP)
return -EOPNOTSUPP;
key->hw_key_idx = key->keyidx;
mutex_lock(&priv->mtx);
switch (cmd) {
case SET_KEY:
memcpy(priv->wep_keys[key->keyidx], key->key, key->keylen);
priv->wep_keys_len[key->keyidx] = key->keylen;
/* FIXME: find out how to do this properly */
priv->wep_key_id = key->keyidx;
break;
case DISABLE_KEY:
default:
priv->wep_keys_len[key->keyidx] = 0;
break;
}
priv->wep_enabled = 0;
for (i = 0; i < WEP_KEYS; i++) {
if (priv->wep_keys_len[i] != 0)
priv->wep_enabled = 1;
}
at76_startup_device(priv);
mutex_unlock(&priv->mtx);
return 0;
}
static const struct ieee80211_ops at76_ops = {
.tx = at76_mac80211_tx,
.add_interface = at76_add_interface,
.remove_interface = at76_remove_interface,
.config = at76_config,
.bss_info_changed = at76_bss_info_changed,
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
.configure_filter = at76_configure_filter,
.start = at76_mac80211_start,
.stop = at76_mac80211_stop,
.hw_scan = at76_hw_scan,
.set_key = at76_set_key,
};
/* Allocate network device and initialize private data */
static struct at76_priv *at76_alloc_new_device(struct usb_device *udev)
{
struct ieee80211_hw *hw;
struct at76_priv *priv;
hw = ieee80211_alloc_hw(sizeof(struct at76_priv), &at76_ops);
if (!hw) {
printk(KERN_ERR DRIVER_NAME ": could not register"
" ieee80211_hw\n");
return NULL;
}
priv = hw->priv;
priv->hw = hw;
priv->udev = udev;
mutex_init(&priv->mtx);
INIT_WORK(&priv->work_set_promisc, at76_work_set_promisc);
INIT_WORK(&priv->work_submit_rx, at76_work_submit_rx);
INIT_DELAYED_WORK(&priv->dwork_hw_scan, at76_dwork_hw_scan);
tasklet_init(&priv->rx_tasklet, at76_rx_tasklet, 0);
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
priv->pm_mode = AT76_PM_OFF;
priv->pm_period = 0;
/* unit us */
priv->hw->channel_change_time = 100000;
return priv;
}
static int at76_alloc_urbs(struct at76_priv *priv,
struct usb_interface *interface)
{
struct usb_endpoint_descriptor *endpoint, *ep_in, *ep_out;
int i;
int buffer_size;
struct usb_host_interface *iface_desc;
at76_dbg(DBG_PROC_ENTRY, "%s: ENTER", __func__);
at76_dbg(DBG_URB, "%s: NumEndpoints %d ", __func__,
interface->altsetting[0].desc.bNumEndpoints);
ep_in = NULL;
ep_out = NULL;
iface_desc = interface->cur_altsetting;
for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
endpoint = &iface_desc->endpoint[i].desc;
at76_dbg(DBG_URB, "%s: %d. endpoint: addr 0x%x attr 0x%x",
__func__, i, endpoint->bEndpointAddress,
endpoint->bmAttributes);
if (!ep_in && usb_endpoint_is_bulk_in(endpoint))
ep_in = endpoint;
if (!ep_out && usb_endpoint_is_bulk_out(endpoint))
ep_out = endpoint;
}
if (!ep_in || !ep_out) {
dev_printk(KERN_ERR, &interface->dev,
"bulk endpoints missing\n");
return -ENXIO;
}
priv->rx_pipe = usb_rcvbulkpipe(priv->udev, ep_in->bEndpointAddress);
priv->tx_pipe = usb_sndbulkpipe(priv->udev, ep_out->bEndpointAddress);
priv->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
priv->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!priv->rx_urb || !priv->tx_urb) {
dev_printk(KERN_ERR, &interface->dev, "cannot allocate URB\n");
return -ENOMEM;
}
buffer_size = sizeof(struct at76_tx_buffer) + MAX_PADDING_SIZE;
priv->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
if (!priv->bulk_out_buffer) {
dev_printk(KERN_ERR, &interface->dev,
"cannot allocate output buffer\n");
return -ENOMEM;
}
at76_dbg(DBG_PROC_ENTRY, "%s: EXIT", __func__);
return 0;
}
static struct ieee80211_rate at76_rates[] = {
{ .bitrate = 10, .hw_value = TX_RATE_1MBIT, },
{ .bitrate = 20, .hw_value = TX_RATE_2MBIT, },
{ .bitrate = 55, .hw_value = TX_RATE_5_5MBIT, },
{ .bitrate = 110, .hw_value = TX_RATE_11MBIT, },
};
static struct ieee80211_channel at76_channels[] = {
{ .center_freq = 2412, .hw_value = 1 },
{ .center_freq = 2417, .hw_value = 2 },
{ .center_freq = 2422, .hw_value = 3 },
{ .center_freq = 2427, .hw_value = 4 },
{ .center_freq = 2432, .hw_value = 5 },
{ .center_freq = 2437, .hw_value = 6 },
{ .center_freq = 2442, .hw_value = 7 },
{ .center_freq = 2447, .hw_value = 8 },
{ .center_freq = 2452, .hw_value = 9 },
{ .center_freq = 2457, .hw_value = 10 },
{ .center_freq = 2462, .hw_value = 11 },
{ .center_freq = 2467, .hw_value = 12 },
{ .center_freq = 2472, .hw_value = 13 },
{ .center_freq = 2484, .hw_value = 14 }
};
static struct ieee80211_supported_band at76_supported_band = {
.channels = at76_channels,
.n_channels = ARRAY_SIZE(at76_channels),
.bitrates = at76_rates,
.n_bitrates = ARRAY_SIZE(at76_rates),
};
/* Register network device and initialize the hardware */
static int at76_init_new_device(struct at76_priv *priv,
struct usb_interface *interface)
{
struct wiphy *wiphy;
size_t len;
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
int ret;
/* set up the endpoint information */
/* check out the endpoints */
at76_dbg(DBG_DEVSTART, "USB interface: %d endpoints",
interface->cur_altsetting->desc.bNumEndpoints);
ret = at76_alloc_urbs(priv, interface);
if (ret < 0)
goto exit;
/* MAC address */
ret = at76_get_hw_config(priv);
if (ret < 0) {
dev_printk(KERN_ERR, &interface->dev,
"cannot get MAC address\n");
goto exit;
}
priv->domain = at76_get_reg_domain(priv->regulatory_domain);
priv->channel = DEF_CHANNEL;
priv->iw_mode = IW_MODE_INFRA;
priv->rts_threshold = DEF_RTS_THRESHOLD;
priv->frag_threshold = DEF_FRAG_THRESHOLD;
priv->short_retry_limit = DEF_SHORT_RETRY_LIMIT;
priv->txrate = TX_RATE_AUTO;
priv->preamble_type = PREAMBLE_TYPE_LONG;
priv->beacon_period = 100;
priv->auth_mode = WLAN_AUTH_OPEN;
priv->scan_min_time = DEF_SCAN_MIN_TIME;
priv->scan_max_time = DEF_SCAN_MAX_TIME;
priv->scan_mode = SCAN_TYPE_ACTIVE;
wiphy = priv->hw->wiphy;
priv->hw->wiphy->max_scan_ssids = 1;
priv->hw->wiphy->max_scan_ie_len = 0;
priv->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &at76_supported_band;
priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
IEEE80211_HW_SIGNAL_UNSPEC;
priv->hw->max_signal = 100;
SET_IEEE80211_DEV(priv->hw, &interface->dev);
SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
len = sizeof(wiphy->fw_version);
snprintf(wiphy->fw_version, len, "%d.%d.%d-%d",
priv->fw_version.major, priv->fw_version.minor,
priv->fw_version.patch, priv->fw_version.build);
wiphy->hw_version = priv->board_type;
ret = ieee80211_register_hw(priv->hw);
if (ret) {
printk(KERN_ERR "cannot register mac80211 hw (status %d)!\n",
ret);
goto exit;
}
priv->mac80211_registered = 1;
printk(KERN_INFO "%s: USB %s, MAC %pM, firmware %d.%d.%d-%d\n",
dev_name(&interface->dev), priv->mac_addr,
priv->fw_version.major, priv->fw_version.minor,
priv->fw_version.patch, priv->fw_version.build);
printk(KERN_INFO "%s: regulatory domain 0x%02x: %s\n",
wiphy_name(priv->hw->wiphy),
priv->regulatory_domain, priv->domain->name);
exit:
return ret;
}
static void at76_delete_device(struct at76_priv *priv)
{
at76_dbg(DBG_PROC_ENTRY, "%s: ENTER", __func__);
/* The device is gone, don't bother turning it off */
priv->device_unplugged = 1;
if (priv->mac80211_registered)
ieee80211_unregister_hw(priv->hw);
if (priv->tx_urb) {
usb_kill_urb(priv->tx_urb);
usb_free_urb(priv->tx_urb);
}
if (priv->rx_urb) {
usb_kill_urb(priv->rx_urb);
usb_free_urb(priv->rx_urb);
}
at76_dbg(DBG_PROC_ENTRY, "%s: unlinked urbs", __func__);
kfree(priv->bulk_out_buffer);
del_timer_sync(&ledtrig_tx_timer);
kfree_skb(priv->rx_skb);
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
usb_put_dev(priv->udev);
at76_dbg(DBG_PROC_ENTRY, "%s: before freeing priv/ieee80211_hw",
__func__);
ieee80211_free_hw(priv->hw);
at76_dbg(DBG_PROC_ENTRY, "%s: EXIT", __func__);
}
static int at76_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
int ret;
struct at76_priv *priv;
struct fwentry *fwe;
struct usb_device *udev;
int op_mode;
int need_ext_fw = 0;
struct mib_fw_version fwv;
int board_type = (int)id->driver_info;
udev = usb_get_dev(interface_to_usbdev(interface));
/* Load firmware into kernel memory */
fwe = at76_load_firmware(udev, board_type);
if (!fwe) {
ret = -ENOENT;
goto error;
}
op_mode = at76_get_op_mode(udev);
at76_dbg(DBG_DEVSTART, "opmode %d", op_mode);
/* we get OPMODE_NONE with 2.4.23, SMC2662W-AR ???
we get 204 with 2.4.23, Fiberline FL-WL240u (505A+RFMD2958) ??? */
if (op_mode == OPMODE_HW_CONFIG_MODE) {
dev_printk(KERN_ERR, &interface->dev,
"cannot handle a device in HW_CONFIG_MODE\n");
ret = -EBUSY;
goto error;
}
if (op_mode != OPMODE_NORMAL_NIC_WITH_FLASH
&& op_mode != OPMODE_NORMAL_NIC_WITHOUT_FLASH) {
/* download internal firmware part */
dev_printk(KERN_DEBUG, &interface->dev,
"downloading internal firmware\n");
ret = at76_load_internal_fw(udev, fwe);
if (ret < 0) {
dev_printk(KERN_ERR, &interface->dev,
"error %d downloading internal firmware\n",
ret);
goto error;
}
usb_put_dev(udev);
return ret;
}
/* Internal firmware already inside the device. Get firmware
* version to test if external firmware is loaded.
* This works only for newer firmware, e.g. the Intersil 0.90.x
* says "control timeout on ep0in" and subsequent
* at76_get_op_mode() fail too :-( */
/* if version >= 0.100.x.y or device with built-in flash we can
* query the device for the fw version */
if ((fwe->fw_version.major > 0 || fwe->fw_version.minor >= 100)
|| (op_mode == OPMODE_NORMAL_NIC_WITH_FLASH)) {
ret = at76_get_mib(udev, MIB_FW_VERSION, &fwv, sizeof(fwv));
if (ret < 0 || (fwv.major | fwv.minor) == 0)
need_ext_fw = 1;
} else
/* No way to check firmware version, reload to be sure */
need_ext_fw = 1;
if (need_ext_fw) {
dev_printk(KERN_DEBUG, &interface->dev,
"downloading external firmware\n");
ret = at76_load_external_fw(udev, fwe);
if (ret)
goto error;
/* Re-check firmware version */
ret = at76_get_mib(udev, MIB_FW_VERSION, &fwv, sizeof(fwv));
if (ret < 0) {
dev_printk(KERN_ERR, &interface->dev,
"error %d getting firmware version\n", ret);
goto error;
}
}
priv = at76_alloc_new_device(udev);
if (!priv) {
ret = -ENOMEM;
goto error;
}
usb_set_intfdata(interface, priv);
memcpy(&priv->fw_version, &fwv, sizeof(struct mib_fw_version));
priv->board_type = board_type;
ret = at76_init_new_device(priv, interface);
if (ret < 0)
at76_delete_device(priv);
return ret;
error:
usb_put_dev(udev);
return ret;
}
static void at76_disconnect(struct usb_interface *interface)
{
struct at76_priv *priv;
priv = usb_get_intfdata(interface);
usb_set_intfdata(interface, NULL);
/* Disconnect after loading internal firmware */
if (!priv)
return;
printk(KERN_INFO "%s: disconnecting\n", wiphy_name(priv->hw->wiphy));
at76_delete_device(priv);
dev_printk(KERN_INFO, &interface->dev, "disconnected\n");
}
/* Structure for registering this driver with the USB subsystem */
static struct usb_driver at76_driver = {
.name = DRIVER_NAME,
.probe = at76_probe,
.disconnect = at76_disconnect,
.id_table = dev_table,
};
static int __init at76_mod_init(void)
{
int result;
printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION " loading\n");
mutex_init(&fw_mutex);
/* register this driver with the USB subsystem */
result = usb_register(&at76_driver);
if (result < 0)
printk(KERN_ERR DRIVER_NAME
": usb_register failed (status %d)\n", result);
led_trigger_register_simple("at76_usb-tx", &ledtrig_tx);
return result;
}
static void __exit at76_mod_exit(void)
{
int i;
printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION " unloading\n");
usb_deregister(&at76_driver);
for (i = 0; i < ARRAY_SIZE(firmwares); i++) {
if (firmwares[i].fw)
release_firmware(firmwares[i].fw);
}
led_trigger_unregister_simple(ledtrig_tx);
}
module_param_named(debug, at76_debug, uint, 0600);
MODULE_PARM_DESC(debug, "Debugging level");
module_init(at76_mod_init);
module_exit(at76_mod_exit);
MODULE_AUTHOR("Oliver Kurth <oku@masqmail.cx>");
MODULE_AUTHOR("Joerg Albert <joerg.albert@gmx.de>");
MODULE_AUTHOR("Alex <alex@foogod.com>");
MODULE_AUTHOR("Nick Jones");
MODULE_AUTHOR("Balint Seeber <n0_5p4m_p13453@hotmail.com>");
MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>");
MODULE_AUTHOR("Guido Guenther <agx@sigxcpu.org>");
MODULE_AUTHOR("Kalle Valo <kalle.valo@iki.fi>");
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");