Johannes Berg | 4855d25 | 2006-01-12 21:12:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Contains some basic softmac functions along with module registration code etc. |
| 3 | * |
Johannes Berg | 7985905 | 2006-01-31 19:31:41 +0100 | [diff] [blame] | 4 | * Copyright (c) 2005, 2006 Johannes Berg <johannes@sipsolutions.net> |
| 5 | * Joseph Jezak <josejx@gentoo.org> |
| 6 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 7 | * Danny van Dyk <kugelfang@gentoo.org> |
| 8 | * Michael Buesch <mbuesch@freenet.de> |
Johannes Berg | 4855d25 | 2006-01-12 21:12:59 +0100 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | * |
| 23 | * The full GNU General Public License is included in this distribution in the |
| 24 | * file called COPYING. |
| 25 | */ |
| 26 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 27 | #include "ieee80211softmac_priv.h" |
| 28 | #include <linux/sort.h> |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 29 | #include <linux/etherdevice.h> |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 30 | |
| 31 | struct net_device *alloc_ieee80211softmac(int sizeof_priv) |
| 32 | { |
| 33 | struct ieee80211softmac_device *softmac; |
| 34 | struct net_device *dev; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 35 | |
Akinobu Mita | ef7ab23 | 2007-05-27 23:26:31 +0900 | [diff] [blame] | 36 | dev = alloc_ieee80211(sizeof(*softmac) + sizeof_priv); |
| 37 | if (!dev) |
| 38 | return NULL; |
| 39 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 40 | softmac = ieee80211_priv(dev); |
| 41 | softmac->dev = dev; |
| 42 | softmac->ieee = netdev_priv(dev); |
| 43 | spin_lock_init(&softmac->lock); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 44 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 45 | softmac->ieee->handle_auth = ieee80211softmac_auth_resp; |
| 46 | softmac->ieee->handle_deauth = ieee80211softmac_deauth_resp; |
| 47 | softmac->ieee->handle_assoc_response = ieee80211softmac_handle_assoc_response; |
Johannes Berg | b6c7658 | 2006-01-31 19:49:42 +0100 | [diff] [blame] | 48 | softmac->ieee->handle_reassoc_request = ieee80211softmac_handle_reassoc_req; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 49 | softmac->ieee->handle_disassoc = ieee80211softmac_handle_disassoc; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 50 | softmac->ieee->handle_beacon = ieee80211softmac_handle_beacon; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 51 | softmac->scaninfo = NULL; |
| 52 | |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame] | 53 | softmac->associnfo.scan_retry = IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT; |
| 54 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 55 | /* TODO: initialise all the other callbacks in the ieee struct |
| 56 | * (once they're written) |
| 57 | */ |
| 58 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 59 | INIT_LIST_HEAD(&softmac->auth_queue); |
| 60 | INIT_LIST_HEAD(&softmac->network_list); |
| 61 | INIT_LIST_HEAD(&softmac->events); |
| 62 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 63 | mutex_init(&softmac->associnfo.mutex); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 64 | INIT_DELAYED_WORK(&softmac->associnfo.work, ieee80211softmac_assoc_work); |
| 65 | INIT_DELAYED_WORK(&softmac->associnfo.timeout, ieee80211softmac_assoc_timeout); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 66 | softmac->start_scan = ieee80211softmac_start_scan_implementation; |
| 67 | softmac->wait_for_scan = ieee80211softmac_wait_for_scan_implementation; |
| 68 | softmac->stop_scan = ieee80211softmac_stop_scan_implementation; |
| 69 | |
Johannes Berg | 2dd5080 | 2006-01-06 18:11:23 +0100 | [diff] [blame] | 70 | /* to start with, we can't send anything ... */ |
| 71 | netif_carrier_off(dev); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 72 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 73 | return dev; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 74 | } |
Johannes Berg | 4c718cf | 2006-01-12 21:19:48 +0100 | [diff] [blame] | 75 | EXPORT_SYMBOL_GPL(alloc_ieee80211softmac); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 76 | |
| 77 | /* Clears the pending work queue items, stops all scans, etc. */ |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 78 | void |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 79 | ieee80211softmac_clear_pending_work(struct ieee80211softmac_device *sm) |
| 80 | { |
| 81 | unsigned long flags; |
| 82 | struct ieee80211softmac_event *eventptr, *eventtmp; |
| 83 | struct ieee80211softmac_auth_queue_item *authptr, *authtmp; |
| 84 | struct ieee80211softmac_network *netptr, *nettmp; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 85 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 86 | ieee80211softmac_stop_scan(sm); |
| 87 | ieee80211softmac_wait_for_scan(sm); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 88 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 89 | spin_lock_irqsave(&sm->lock, flags); |
Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 90 | sm->running = 0; |
| 91 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 92 | /* Free all pending assoc work items */ |
| 93 | cancel_delayed_work(&sm->associnfo.work); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 94 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 95 | /* Free all pending scan work items */ |
| 96 | if(sm->scaninfo != NULL) |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 97 | cancel_delayed_work(&sm->scaninfo->softmac_scan); |
| 98 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 99 | /* Free all pending auth work items */ |
| 100 | list_for_each_entry(authptr, &sm->auth_queue, list) |
| 101 | cancel_delayed_work(&authptr->work); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 102 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 103 | /* delete all pending event calls and work items */ |
| 104 | list_for_each_entry_safe(eventptr, eventtmp, &sm->events, list) |
| 105 | cancel_delayed_work(&eventptr->work); |
| 106 | |
| 107 | spin_unlock_irqrestore(&sm->lock, flags); |
Johannes Berg | 5c4df6d | 2006-01-06 01:43:45 +0100 | [diff] [blame] | 108 | flush_scheduled_work(); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 109 | |
Johannes Berg | b2b9b651 | 2006-01-11 19:32:02 +0100 | [diff] [blame] | 110 | /* now we should be save and no longer need locking... */ |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 111 | spin_lock_irqsave(&sm->lock, flags); |
| 112 | /* Free all pending auth work items */ |
| 113 | list_for_each_entry_safe(authptr, authtmp, &sm->auth_queue, list) { |
| 114 | list_del(&authptr->list); |
| 115 | kfree(authptr); |
| 116 | } |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 117 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 118 | /* delete all pending event calls and work items */ |
| 119 | list_for_each_entry_safe(eventptr, eventtmp, &sm->events, list) { |
| 120 | list_del(&eventptr->list); |
| 121 | kfree(eventptr); |
| 122 | } |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 123 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 124 | /* Free all networks */ |
| 125 | list_for_each_entry_safe(netptr, nettmp, &sm->network_list, list) { |
| 126 | ieee80211softmac_del_network_locked(sm, netptr); |
| 127 | if(netptr->challenge != NULL) |
| 128 | kfree(netptr->challenge); |
| 129 | kfree(netptr); |
| 130 | } |
| 131 | |
| 132 | spin_unlock_irqrestore(&sm->lock, flags); |
| 133 | } |
Johannes Berg | 4c718cf | 2006-01-12 21:19:48 +0100 | [diff] [blame] | 134 | EXPORT_SYMBOL_GPL(ieee80211softmac_clear_pending_work); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 135 | |
| 136 | void free_ieee80211softmac(struct net_device *dev) |
| 137 | { |
| 138 | struct ieee80211softmac_device *sm = ieee80211_priv(dev); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 139 | ieee80211softmac_clear_pending_work(sm); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 140 | kfree(sm->scaninfo); |
| 141 | kfree(sm->wpa.IE); |
| 142 | free_ieee80211(dev); |
| 143 | } |
Johannes Berg | 4c718cf | 2006-01-12 21:19:48 +0100 | [diff] [blame] | 144 | EXPORT_SYMBOL_GPL(free_ieee80211softmac); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 145 | |
| 146 | static void ieee80211softmac_start_check_rates(struct ieee80211softmac_device *mac) |
| 147 | { |
| 148 | struct ieee80211softmac_ratesinfo *ri = &mac->ratesinfo; |
| 149 | /* I took out the sorting check, we're seperating by modulation now. */ |
| 150 | if (ri->count) |
| 151 | return; |
| 152 | /* otherwise assume we hav'em all! */ |
| 153 | if (mac->ieee->modulation & IEEE80211_CCK_MODULATION) { |
| 154 | ri->rates[ri->count++] = IEEE80211_CCK_RATE_1MB; |
| 155 | ri->rates[ri->count++] = IEEE80211_CCK_RATE_2MB; |
| 156 | ri->rates[ri->count++] = IEEE80211_CCK_RATE_5MB; |
| 157 | ri->rates[ri->count++] = IEEE80211_CCK_RATE_11MB; |
| 158 | } |
| 159 | if (mac->ieee->modulation & IEEE80211_OFDM_MODULATION) { |
| 160 | ri->rates[ri->count++] = IEEE80211_OFDM_RATE_6MB; |
| 161 | ri->rates[ri->count++] = IEEE80211_OFDM_RATE_9MB; |
| 162 | ri->rates[ri->count++] = IEEE80211_OFDM_RATE_12MB; |
| 163 | ri->rates[ri->count++] = IEEE80211_OFDM_RATE_18MB; |
| 164 | ri->rates[ri->count++] = IEEE80211_OFDM_RATE_24MB; |
| 165 | ri->rates[ri->count++] = IEEE80211_OFDM_RATE_36MB; |
| 166 | ri->rates[ri->count++] = IEEE80211_OFDM_RATE_48MB; |
| 167 | ri->rates[ri->count++] = IEEE80211_OFDM_RATE_54MB; |
| 168 | } |
| 169 | } |
| 170 | |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 171 | int ieee80211softmac_ratesinfo_rate_supported(struct ieee80211softmac_ratesinfo *ri, u8 rate) |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 172 | { |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 173 | int search; |
| 174 | u8 search_rate; |
| 175 | |
| 176 | for (search = 0; search < ri->count; search++) { |
| 177 | search_rate = ri->rates[search]; |
| 178 | search_rate &= ~IEEE80211_BASIC_RATE_MASK; |
| 179 | if (rate == search_rate) |
| 180 | return 1; |
| 181 | } |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
Daniel Drake | d7712ac | 2006-07-18 21:34:56 +0100 | [diff] [blame] | 186 | u8 ieee80211softmac_highest_supported_rate(struct ieee80211softmac_device *mac, |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 187 | struct ieee80211softmac_ratesinfo *ri, int basic_only) |
| 188 | { |
| 189 | u8 user_rate = mac->txrates.user_rate; |
| 190 | int i; |
| 191 | |
Daniel Drake | d7712ac | 2006-07-18 21:34:56 +0100 | [diff] [blame] | 192 | if (ri->count == 0) |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 193 | return IEEE80211_CCK_RATE_1MB; |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 194 | |
| 195 | for (i = ri->count - 1; i >= 0; i--) { |
| 196 | u8 rate = ri->rates[i]; |
| 197 | if (basic_only && !(rate & IEEE80211_BASIC_RATE_MASK)) |
| 198 | continue; |
| 199 | rate &= ~IEEE80211_BASIC_RATE_MASK; |
| 200 | if (rate > user_rate) |
| 201 | continue; |
| 202 | if (ieee80211softmac_ratesinfo_rate_supported(&mac->ratesinfo, rate)) |
| 203 | return rate; |
| 204 | } |
| 205 | |
| 206 | /* If we haven't found a suitable rate by now, just trust the user */ |
| 207 | return user_rate; |
| 208 | } |
Daniel Drake | d7712ac | 2006-07-18 21:34:56 +0100 | [diff] [blame] | 209 | EXPORT_SYMBOL_GPL(ieee80211softmac_highest_supported_rate); |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 210 | |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 211 | void ieee80211softmac_process_erp(struct ieee80211softmac_device *mac, |
| 212 | u8 erp_value) |
| 213 | { |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 214 | int use_protection; |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 215 | int short_preamble; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 216 | u32 changes = 0; |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 217 | |
| 218 | /* Barker preamble mode */ |
| 219 | short_preamble = ((erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0 |
| 220 | && mac->associnfo.short_preamble_available) ? 1 : 0; |
| 221 | |
| 222 | /* Protection needed? */ |
| 223 | use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0; |
| 224 | |
| 225 | if (mac->bssinfo.short_preamble != short_preamble) { |
| 226 | changes |= IEEE80211SOFTMAC_BSSINFOCHG_SHORT_PREAMBLE; |
| 227 | mac->bssinfo.short_preamble = short_preamble; |
| 228 | } |
| 229 | |
| 230 | if (mac->bssinfo.use_protection != use_protection) { |
| 231 | changes |= IEEE80211SOFTMAC_BSSINFOCHG_PROTECTION; |
| 232 | mac->bssinfo.use_protection = use_protection; |
| 233 | } |
| 234 | |
| 235 | if (mac->bssinfo_change && changes) |
| 236 | mac->bssinfo_change(mac->dev, changes); |
| 237 | } |
| 238 | |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 239 | void ieee80211softmac_recalc_txrates(struct ieee80211softmac_device *mac) |
| 240 | { |
| 241 | struct ieee80211softmac_txrates *txrates = &mac->txrates; |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 242 | u32 change = 0; |
| 243 | |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 244 | change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT; |
Daniel Drake | d7712ac | 2006-07-18 21:34:56 +0100 | [diff] [blame] | 245 | txrates->default_rate = ieee80211softmac_highest_supported_rate(mac, &mac->bssinfo.supported_rates, 0); |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 246 | |
| 247 | change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK; |
| 248 | txrates->default_fallback = lower_rate(mac, txrates->default_rate); |
| 249 | |
| 250 | change |= IEEE80211SOFTMAC_TXRATECHG_MCAST; |
Daniel Drake | d7712ac | 2006-07-18 21:34:56 +0100 | [diff] [blame] | 251 | txrates->mcast_rate = ieee80211softmac_highest_supported_rate(mac, &mac->bssinfo.supported_rates, 1); |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 252 | |
| 253 | if (mac->txrates_change) |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 254 | mac->txrates_change(mac->dev, change); |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 255 | |
| 256 | } |
| 257 | |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 258 | void ieee80211softmac_init_bss(struct ieee80211softmac_device *mac) |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 259 | { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 260 | struct ieee80211_device *ieee = mac->ieee; |
| 261 | u32 change = 0; |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 262 | struct ieee80211softmac_txrates *txrates = &mac->txrates; |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 263 | struct ieee80211softmac_bss_info *bssinfo = &mac->bssinfo; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 264 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 265 | /* TODO: We need some kind of state machine to lower the default rates |
| 266 | * if we loose too many packets. |
| 267 | */ |
| 268 | /* Change the default txrate to the highest possible value. |
| 269 | * The txrate machine will lower it, if it is too high. |
| 270 | */ |
Larry Finger | bb52a65 | 2007-02-13 18:58:03 -0600 | [diff] [blame] | 271 | if (ieee->modulation & IEEE80211_OFDM_MODULATION) |
| 272 | txrates->user_rate = IEEE80211_OFDM_RATE_24MB; |
| 273 | else |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 274 | txrates->user_rate = IEEE80211_CCK_RATE_11MB; |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 275 | |
| 276 | txrates->default_rate = IEEE80211_CCK_RATE_1MB; |
| 277 | change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT; |
| 278 | |
| 279 | txrates->default_fallback = IEEE80211_CCK_RATE_1MB; |
| 280 | change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK; |
| 281 | |
| 282 | txrates->mcast_rate = IEEE80211_CCK_RATE_1MB; |
| 283 | change |= IEEE80211SOFTMAC_TXRATECHG_MCAST; |
| 284 | |
| 285 | txrates->mgt_mcast_rate = IEEE80211_CCK_RATE_1MB; |
| 286 | change |= IEEE80211SOFTMAC_TXRATECHG_MGT_MCAST; |
| 287 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 288 | if (mac->txrates_change) |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 289 | mac->txrates_change(mac->dev, change); |
| 290 | |
| 291 | change = 0; |
| 292 | |
| 293 | bssinfo->supported_rates.count = 0; |
| 294 | memset(bssinfo->supported_rates.rates, 0, |
| 295 | sizeof(bssinfo->supported_rates.rates)); |
| 296 | change |= IEEE80211SOFTMAC_BSSINFOCHG_RATES; |
| 297 | |
| 298 | bssinfo->short_preamble = 0; |
| 299 | change |= IEEE80211SOFTMAC_BSSINFOCHG_SHORT_PREAMBLE; |
| 300 | |
| 301 | bssinfo->use_protection = 0; |
| 302 | change |= IEEE80211SOFTMAC_BSSINFOCHG_PROTECTION; |
| 303 | |
| 304 | if (mac->bssinfo_change) |
| 305 | mac->bssinfo_change(mac->dev, change); |
Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 306 | |
| 307 | mac->running = 1; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 308 | } |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 309 | |
| 310 | void ieee80211softmac_start(struct net_device *dev) |
| 311 | { |
| 312 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
| 313 | |
| 314 | ieee80211softmac_start_check_rates(mac); |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 315 | ieee80211softmac_init_bss(mac); |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 316 | } |
Johannes Berg | 4c718cf | 2006-01-12 21:19:48 +0100 | [diff] [blame] | 317 | EXPORT_SYMBOL_GPL(ieee80211softmac_start); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 318 | |
| 319 | void ieee80211softmac_stop(struct net_device *dev) |
| 320 | { |
| 321 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
| 322 | |
| 323 | ieee80211softmac_clear_pending_work(mac); |
| 324 | } |
Johannes Berg | 4c718cf | 2006-01-12 21:19:48 +0100 | [diff] [blame] | 325 | EXPORT_SYMBOL_GPL(ieee80211softmac_stop); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 326 | |
| 327 | void ieee80211softmac_set_rates(struct net_device *dev, u8 count, u8 *rates) |
| 328 | { |
| 329 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
| 330 | unsigned long flags; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 331 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 332 | spin_lock_irqsave(&mac->lock, flags); |
| 333 | memcpy(mac->ratesinfo.rates, rates, count); |
| 334 | mac->ratesinfo.count = count; |
| 335 | spin_unlock_irqrestore(&mac->lock, flags); |
| 336 | } |
Johannes Berg | 4c718cf | 2006-01-12 21:19:48 +0100 | [diff] [blame] | 337 | EXPORT_SYMBOL_GPL(ieee80211softmac_set_rates); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 338 | |
| 339 | static u8 raise_rate(struct ieee80211softmac_device *mac, u8 rate) |
| 340 | { |
| 341 | int i; |
| 342 | struct ieee80211softmac_ratesinfo *ri = &mac->ratesinfo; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 343 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 344 | for (i=0; i<ri->count-1; i++) { |
| 345 | if (ri->rates[i] == rate) |
| 346 | return ri->rates[i+1]; |
| 347 | } |
| 348 | /* I guess we can't go any higher... */ |
| 349 | return ri->rates[ri->count]; |
| 350 | } |
| 351 | |
| 352 | u8 ieee80211softmac_lower_rate_delta(struct ieee80211softmac_device *mac, u8 rate, int delta) |
| 353 | { |
| 354 | int i; |
| 355 | struct ieee80211softmac_ratesinfo *ri = &mac->ratesinfo; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 356 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 357 | for (i=delta; i<ri->count; i++) { |
| 358 | if (ri->rates[i] == rate) |
| 359 | return ri->rates[i-delta]; |
| 360 | } |
| 361 | /* I guess we can't go any lower... */ |
| 362 | return ri->rates[0]; |
| 363 | } |
| 364 | |
| 365 | static void ieee80211softmac_add_txrates_badness(struct ieee80211softmac_device *mac, |
| 366 | int amount) |
| 367 | { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 368 | u8 default_rate = mac->txrates.default_rate; |
| 369 | u8 default_fallback = mac->txrates.default_fallback; |
| 370 | u32 changes = 0; |
| 371 | |
| 372 | //TODO: This is highly experimental code. |
| 373 | // Maybe the dynamic rate selection does not work |
| 374 | // and it has to be removed again. |
| 375 | |
| 376 | printk("badness %d\n", mac->txrate_badness); |
| 377 | mac->txrate_badness += amount; |
| 378 | if (mac->txrate_badness <= -1000) { |
| 379 | /* Very small badness. Try a faster bitrate. */ |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 380 | default_rate = raise_rate(mac, default_rate); |
| 381 | changes |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT; |
| 382 | default_fallback = get_fallback_rate(mac, default_rate); |
| 383 | changes |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK; |
| 384 | mac->txrate_badness = 0; |
| 385 | printk("Bitrate raised to %u\n", default_rate); |
| 386 | } else if (mac->txrate_badness >= 10000) { |
| 387 | /* Very high badness. Try a slower bitrate. */ |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 388 | default_rate = lower_rate(mac, default_rate); |
| 389 | changes |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT; |
| 390 | default_fallback = get_fallback_rate(mac, default_rate); |
| 391 | changes |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK; |
| 392 | mac->txrate_badness = 0; |
| 393 | printk("Bitrate lowered to %u\n", default_rate); |
| 394 | } |
| 395 | |
| 396 | mac->txrates.default_rate = default_rate; |
| 397 | mac->txrates.default_fallback = default_fallback; |
| 398 | |
| 399 | if (changes && mac->txrates_change) |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 400 | mac->txrates_change(mac->dev, changes); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | void ieee80211softmac_fragment_lost(struct net_device *dev, |
| 404 | u16 wl_seq) |
| 405 | { |
| 406 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
| 407 | unsigned long flags; |
| 408 | |
| 409 | spin_lock_irqsave(&mac->lock, flags); |
| 410 | ieee80211softmac_add_txrates_badness(mac, 1000); |
| 411 | //TODO |
| 412 | |
| 413 | spin_unlock_irqrestore(&mac->lock, flags); |
| 414 | } |
Johannes Berg | 4c718cf | 2006-01-12 21:19:48 +0100 | [diff] [blame] | 415 | EXPORT_SYMBOL_GPL(ieee80211softmac_fragment_lost); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 416 | |
| 417 | static int rate_cmp(const void *a_, const void *b_) { |
| 418 | u8 *a, *b; |
| 419 | a = (u8*)a_; |
| 420 | b = (u8*)b_; |
| 421 | return ((*a & ~IEEE80211_BASIC_RATE_MASK) - (*b & ~IEEE80211_BASIC_RATE_MASK)); |
| 422 | } |
| 423 | |
| 424 | /* Allocate a softmac network struct and fill it from a network */ |
| 425 | struct ieee80211softmac_network * |
| 426 | ieee80211softmac_create_network(struct ieee80211softmac_device *mac, |
| 427 | struct ieee80211_network *net) |
| 428 | { |
| 429 | struct ieee80211softmac_network *softnet; |
| 430 | softnet = kzalloc(sizeof(struct ieee80211softmac_network), GFP_ATOMIC); |
| 431 | if(softnet == NULL) |
| 432 | return NULL; |
| 433 | memcpy(softnet->bssid, net->bssid, ETH_ALEN); |
| 434 | softnet->channel = net->channel; |
| 435 | softnet->essid.len = net->ssid_len; |
| 436 | memcpy(softnet->essid.data, net->ssid, softnet->essid.len); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 437 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 438 | /* copy rates over */ |
| 439 | softnet->supported_rates.count = net->rates_len; |
| 440 | memcpy(&softnet->supported_rates.rates[0], net->rates, net->rates_len); |
| 441 | memcpy(&softnet->supported_rates.rates[softnet->supported_rates.count], net->rates_ex, net->rates_ex_len); |
| 442 | softnet->supported_rates.count += net->rates_ex_len; |
| 443 | sort(softnet->supported_rates.rates, softnet->supported_rates.count, sizeof(softnet->supported_rates.rates[0]), rate_cmp, NULL); |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 444 | |
| 445 | /* we save the ERP value because it is needed at association time, and |
| 446 | * many AP's do not include an ERP IE in the association response. */ |
| 447 | softnet->erp_value = net->erp_value; |
| 448 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 449 | softnet->capabilities = net->capability; |
| 450 | return softnet; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | /* Add a network to the list, while locked */ |
| 455 | void |
| 456 | ieee80211softmac_add_network_locked(struct ieee80211softmac_device *mac, |
| 457 | struct ieee80211softmac_network *add_net) |
| 458 | { |
Akinobu Mita | 67c4f7a | 2007-05-27 23:27:40 +0900 | [diff] [blame] | 459 | struct ieee80211softmac_network *softmac_net; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 460 | |
Akinobu Mita | 67c4f7a | 2007-05-27 23:27:40 +0900 | [diff] [blame] | 461 | list_for_each_entry(softmac_net, &mac->network_list, list) { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 462 | if(!memcmp(softmac_net->bssid, add_net->bssid, ETH_ALEN)) |
Akinobu Mita | 67c4f7a | 2007-05-27 23:27:40 +0900 | [diff] [blame] | 463 | return; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 464 | } |
Akinobu Mita | 67c4f7a | 2007-05-27 23:27:40 +0900 | [diff] [blame] | 465 | list_add(&(add_net->list), &mac->network_list); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /* Add a network to the list, with locking */ |
| 469 | void |
| 470 | ieee80211softmac_add_network(struct ieee80211softmac_device *mac, |
| 471 | struct ieee80211softmac_network *add_net) |
| 472 | { |
| 473 | unsigned long flags; |
| 474 | spin_lock_irqsave(&mac->lock, flags); |
| 475 | ieee80211softmac_add_network_locked(mac, add_net); |
| 476 | spin_unlock_irqrestore(&mac->lock, flags); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | /* Delete a network from the list, while locked*/ |
| 481 | void |
| 482 | ieee80211softmac_del_network_locked(struct ieee80211softmac_device *mac, |
| 483 | struct ieee80211softmac_network *del_net) |
| 484 | { |
| 485 | list_del(&(del_net->list)); |
| 486 | } |
| 487 | |
| 488 | /* Delete a network from the list with locking */ |
| 489 | void |
| 490 | ieee80211softmac_del_network(struct ieee80211softmac_device *mac, |
| 491 | struct ieee80211softmac_network *del_net) |
| 492 | { |
| 493 | unsigned long flags; |
| 494 | spin_lock_irqsave(&mac->lock, flags); |
| 495 | ieee80211softmac_del_network_locked(mac, del_net); |
| 496 | spin_unlock_irqrestore(&mac->lock, flags); |
| 497 | } |
| 498 | |
| 499 | /* Get a network from the list by MAC while locked */ |
| 500 | struct ieee80211softmac_network * |
| 501 | ieee80211softmac_get_network_by_bssid_locked(struct ieee80211softmac_device *mac, |
| 502 | u8 *bssid) |
| 503 | { |
Akinobu Mita | 67c4f7a | 2007-05-27 23:27:40 +0900 | [diff] [blame] | 504 | struct ieee80211softmac_network *softmac_net; |
| 505 | |
| 506 | list_for_each_entry(softmac_net, &mac->network_list, list) { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 507 | if(!memcmp(softmac_net->bssid, bssid, ETH_ALEN)) |
Akinobu Mita | 67c4f7a | 2007-05-27 23:27:40 +0900 | [diff] [blame] | 508 | return softmac_net; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 509 | } |
Akinobu Mita | 67c4f7a | 2007-05-27 23:27:40 +0900 | [diff] [blame] | 510 | return NULL; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /* Get a network from the list by BSSID with locking */ |
| 514 | struct ieee80211softmac_network * |
| 515 | ieee80211softmac_get_network_by_bssid(struct ieee80211softmac_device *mac, |
| 516 | u8 *bssid) |
| 517 | { |
| 518 | unsigned long flags; |
| 519 | struct ieee80211softmac_network *softmac_net; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 520 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 521 | spin_lock_irqsave(&mac->lock, flags); |
| 522 | softmac_net = ieee80211softmac_get_network_by_bssid_locked(mac, bssid); |
| 523 | spin_unlock_irqrestore(&mac->lock, flags); |
| 524 | return softmac_net; |
| 525 | } |
| 526 | |
| 527 | /* Get a network from the list by ESSID while locked */ |
| 528 | struct ieee80211softmac_network * |
| 529 | ieee80211softmac_get_network_by_essid_locked(struct ieee80211softmac_device *mac, |
| 530 | struct ieee80211softmac_essid *essid) |
| 531 | { |
Akinobu Mita | 67c4f7a | 2007-05-27 23:27:40 +0900 | [diff] [blame] | 532 | struct ieee80211softmac_network *softmac_net; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 533 | |
Akinobu Mita | 67c4f7a | 2007-05-27 23:27:40 +0900 | [diff] [blame] | 534 | list_for_each_entry(softmac_net, &mac->network_list, list) { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 535 | if (softmac_net->essid.len == essid->len && |
| 536 | !memcmp(softmac_net->essid.data, essid->data, essid->len)) |
| 537 | return softmac_net; |
| 538 | } |
| 539 | return NULL; |
| 540 | } |
| 541 | |
| 542 | /* Get a network from the list by ESSID with locking */ |
| 543 | struct ieee80211softmac_network * |
| 544 | ieee80211softmac_get_network_by_essid(struct ieee80211softmac_device *mac, |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 545 | struct ieee80211softmac_essid *essid) |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 546 | { |
| 547 | unsigned long flags; |
| 548 | struct ieee80211softmac_network *softmac_net = NULL; |
| 549 | |
| 550 | spin_lock_irqsave(&mac->lock, flags); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 551 | softmac_net = ieee80211softmac_get_network_by_essid_locked(mac, essid); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 552 | spin_unlock_irqrestore(&mac->lock, flags); |
| 553 | return softmac_net; |
| 554 | } |
| 555 | |
| 556 | MODULE_LICENSE("GPL"); |
Johannes Berg | 9ebdd46 | 2006-01-12 21:18:25 +0100 | [diff] [blame] | 557 | MODULE_AUTHOR("Johannes Berg"); |
| 558 | MODULE_AUTHOR("Joseph Jezak"); |
| 559 | MODULE_AUTHOR("Larry Finger"); |
| 560 | MODULE_AUTHOR("Danny van Dyk"); |
| 561 | MODULE_AUTHOR("Michael Buesch"); |
| 562 | MODULE_DESCRIPTION("802.11 software MAC"); |