ieee80211softmac_module.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /*
  2. * Contains some basic softmac functions along with module registration code etc.
  3. *
  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>
  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. #include "ieee80211softmac_priv.h"
  27. #include <linux/sort.h>
  28. #include <linux/etherdevice.h>
  29. struct net_device *alloc_ieee80211softmac(int sizeof_priv)
  30. {
  31. struct ieee80211softmac_device *softmac;
  32. struct net_device *dev;
  33. dev = alloc_ieee80211(sizeof(struct ieee80211softmac_device) + sizeof_priv);
  34. softmac = ieee80211_priv(dev);
  35. softmac->dev = dev;
  36. softmac->ieee = netdev_priv(dev);
  37. spin_lock_init(&softmac->lock);
  38. softmac->ieee->handle_auth = ieee80211softmac_auth_resp;
  39. softmac->ieee->handle_deauth = ieee80211softmac_deauth_resp;
  40. softmac->ieee->handle_assoc_response = ieee80211softmac_handle_assoc_response;
  41. softmac->ieee->handle_reassoc_request = ieee80211softmac_handle_reassoc_req;
  42. softmac->ieee->handle_disassoc = ieee80211softmac_handle_disassoc;
  43. softmac->ieee->handle_beacon = ieee80211softmac_handle_beacon;
  44. softmac->scaninfo = NULL;
  45. softmac->associnfo.scan_retry = IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT;
  46. /* TODO: initialise all the other callbacks in the ieee struct
  47. * (once they're written)
  48. */
  49. INIT_LIST_HEAD(&softmac->auth_queue);
  50. INIT_LIST_HEAD(&softmac->network_list);
  51. INIT_LIST_HEAD(&softmac->events);
  52. INIT_WORK(&softmac->associnfo.work, ieee80211softmac_assoc_work, softmac);
  53. INIT_WORK(&softmac->associnfo.timeout, ieee80211softmac_assoc_timeout, softmac);
  54. softmac->start_scan = ieee80211softmac_start_scan_implementation;
  55. softmac->wait_for_scan = ieee80211softmac_wait_for_scan_implementation;
  56. softmac->stop_scan = ieee80211softmac_stop_scan_implementation;
  57. /* to start with, we can't send anything ... */
  58. netif_carrier_off(dev);
  59. return dev;
  60. }
  61. EXPORT_SYMBOL_GPL(alloc_ieee80211softmac);
  62. /* Clears the pending work queue items, stops all scans, etc. */
  63. void
  64. ieee80211softmac_clear_pending_work(struct ieee80211softmac_device *sm)
  65. {
  66. unsigned long flags;
  67. struct ieee80211softmac_event *eventptr, *eventtmp;
  68. struct ieee80211softmac_auth_queue_item *authptr, *authtmp;
  69. struct ieee80211softmac_network *netptr, *nettmp;
  70. ieee80211softmac_stop_scan(sm);
  71. ieee80211softmac_wait_for_scan(sm);
  72. spin_lock_irqsave(&sm->lock, flags);
  73. sm->running = 0;
  74. /* Free all pending assoc work items */
  75. cancel_delayed_work(&sm->associnfo.work);
  76. /* Free all pending scan work items */
  77. if(sm->scaninfo != NULL)
  78. cancel_delayed_work(&sm->scaninfo->softmac_scan);
  79. /* Free all pending auth work items */
  80. list_for_each_entry(authptr, &sm->auth_queue, list)
  81. cancel_delayed_work(&authptr->work);
  82. /* delete all pending event calls and work items */
  83. list_for_each_entry_safe(eventptr, eventtmp, &sm->events, list)
  84. cancel_delayed_work(&eventptr->work);
  85. spin_unlock_irqrestore(&sm->lock, flags);
  86. flush_scheduled_work();
  87. /* now we should be save and no longer need locking... */
  88. spin_lock_irqsave(&sm->lock, flags);
  89. /* Free all pending auth work items */
  90. list_for_each_entry_safe(authptr, authtmp, &sm->auth_queue, list) {
  91. list_del(&authptr->list);
  92. kfree(authptr);
  93. }
  94. /* delete all pending event calls and work items */
  95. list_for_each_entry_safe(eventptr, eventtmp, &sm->events, list) {
  96. list_del(&eventptr->list);
  97. kfree(eventptr);
  98. }
  99. /* Free all networks */
  100. list_for_each_entry_safe(netptr, nettmp, &sm->network_list, list) {
  101. ieee80211softmac_del_network_locked(sm, netptr);
  102. if(netptr->challenge != NULL)
  103. kfree(netptr->challenge);
  104. kfree(netptr);
  105. }
  106. spin_unlock_irqrestore(&sm->lock, flags);
  107. }
  108. EXPORT_SYMBOL_GPL(ieee80211softmac_clear_pending_work);
  109. void free_ieee80211softmac(struct net_device *dev)
  110. {
  111. struct ieee80211softmac_device *sm = ieee80211_priv(dev);
  112. ieee80211softmac_clear_pending_work(sm);
  113. kfree(sm->scaninfo);
  114. kfree(sm->wpa.IE);
  115. free_ieee80211(dev);
  116. }
  117. EXPORT_SYMBOL_GPL(free_ieee80211softmac);
  118. static void ieee80211softmac_start_check_rates(struct ieee80211softmac_device *mac)
  119. {
  120. struct ieee80211softmac_ratesinfo *ri = &mac->ratesinfo;
  121. /* I took out the sorting check, we're seperating by modulation now. */
  122. if (ri->count)
  123. return;
  124. /* otherwise assume we hav'em all! */
  125. if (mac->ieee->modulation & IEEE80211_CCK_MODULATION) {
  126. ri->rates[ri->count++] = IEEE80211_CCK_RATE_1MB;
  127. ri->rates[ri->count++] = IEEE80211_CCK_RATE_2MB;
  128. ri->rates[ri->count++] = IEEE80211_CCK_RATE_5MB;
  129. ri->rates[ri->count++] = IEEE80211_CCK_RATE_11MB;
  130. }
  131. if (mac->ieee->modulation & IEEE80211_OFDM_MODULATION) {
  132. ri->rates[ri->count++] = IEEE80211_OFDM_RATE_6MB;
  133. ri->rates[ri->count++] = IEEE80211_OFDM_RATE_9MB;
  134. ri->rates[ri->count++] = IEEE80211_OFDM_RATE_12MB;
  135. ri->rates[ri->count++] = IEEE80211_OFDM_RATE_18MB;
  136. ri->rates[ri->count++] = IEEE80211_OFDM_RATE_24MB;
  137. ri->rates[ri->count++] = IEEE80211_OFDM_RATE_36MB;
  138. ri->rates[ri->count++] = IEEE80211_OFDM_RATE_48MB;
  139. ri->rates[ri->count++] = IEEE80211_OFDM_RATE_54MB;
  140. }
  141. }
  142. int ieee80211softmac_ratesinfo_rate_supported(struct ieee80211softmac_ratesinfo *ri, u8 rate)
  143. {
  144. int search;
  145. u8 search_rate;
  146. for (search = 0; search < ri->count; search++) {
  147. search_rate = ri->rates[search];
  148. search_rate &= ~IEEE80211_BASIC_RATE_MASK;
  149. if (rate == search_rate)
  150. return 1;
  151. }
  152. return 0;
  153. }
  154. u8 ieee80211softmac_highest_supported_rate(struct ieee80211softmac_device *mac,
  155. struct ieee80211softmac_ratesinfo *ri, int basic_only)
  156. {
  157. u8 user_rate = mac->txrates.user_rate;
  158. int i;
  159. if (ri->count == 0)
  160. return IEEE80211_CCK_RATE_1MB;
  161. for (i = ri->count - 1; i >= 0; i--) {
  162. u8 rate = ri->rates[i];
  163. if (basic_only && !(rate & IEEE80211_BASIC_RATE_MASK))
  164. continue;
  165. rate &= ~IEEE80211_BASIC_RATE_MASK;
  166. if (rate > user_rate)
  167. continue;
  168. if (ieee80211softmac_ratesinfo_rate_supported(&mac->ratesinfo, rate))
  169. return rate;
  170. }
  171. /* If we haven't found a suitable rate by now, just trust the user */
  172. return user_rate;
  173. }
  174. EXPORT_SYMBOL_GPL(ieee80211softmac_highest_supported_rate);
  175. void ieee80211softmac_process_erp(struct ieee80211softmac_device *mac,
  176. u8 erp_value)
  177. {
  178. int use_protection;
  179. int short_preamble;
  180. u32 changes = 0;
  181. /* Barker preamble mode */
  182. short_preamble = ((erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0
  183. && mac->associnfo.short_preamble_available) ? 1 : 0;
  184. /* Protection needed? */
  185. use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
  186. if (mac->bssinfo.short_preamble != short_preamble) {
  187. changes |= IEEE80211SOFTMAC_BSSINFOCHG_SHORT_PREAMBLE;
  188. mac->bssinfo.short_preamble = short_preamble;
  189. }
  190. if (mac->bssinfo.use_protection != use_protection) {
  191. changes |= IEEE80211SOFTMAC_BSSINFOCHG_PROTECTION;
  192. mac->bssinfo.use_protection = use_protection;
  193. }
  194. if (mac->bssinfo_change && changes)
  195. mac->bssinfo_change(mac->dev, changes);
  196. }
  197. void ieee80211softmac_recalc_txrates(struct ieee80211softmac_device *mac)
  198. {
  199. struct ieee80211softmac_txrates *txrates = &mac->txrates;
  200. u32 change = 0;
  201. change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT;
  202. txrates->default_rate = ieee80211softmac_highest_supported_rate(mac, &mac->bssinfo.supported_rates, 0);
  203. change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK;
  204. txrates->default_fallback = lower_rate(mac, txrates->default_rate);
  205. change |= IEEE80211SOFTMAC_TXRATECHG_MCAST;
  206. txrates->mcast_rate = ieee80211softmac_highest_supported_rate(mac, &mac->bssinfo.supported_rates, 1);
  207. if (mac->txrates_change)
  208. mac->txrates_change(mac->dev, change);
  209. }
  210. void ieee80211softmac_init_bss(struct ieee80211softmac_device *mac)
  211. {
  212. struct ieee80211_device *ieee = mac->ieee;
  213. u32 change = 0;
  214. struct ieee80211softmac_txrates *txrates = &mac->txrates;
  215. struct ieee80211softmac_bss_info *bssinfo = &mac->bssinfo;
  216. /* TODO: We need some kind of state machine to lower the default rates
  217. * if we loose too many packets.
  218. */
  219. /* Change the default txrate to the highest possible value.
  220. * The txrate machine will lower it, if it is too high.
  221. */
  222. /* FIXME: We don't correctly handle backing down to lower
  223. rates, so 801.11g devices start off at 11M for now. People
  224. can manually change it if they really need to, but 11M is
  225. more reliable. Note similar logic in
  226. ieee80211softmac_wx_set_rate() */
  227. if (ieee->modulation & IEEE80211_CCK_MODULATION) {
  228. txrates->user_rate = IEEE80211_CCK_RATE_11MB;
  229. } else if (ieee->modulation & IEEE80211_OFDM_MODULATION) {
  230. txrates->user_rate = IEEE80211_OFDM_RATE_54MB;
  231. } else
  232. assert(0);
  233. txrates->default_rate = IEEE80211_CCK_RATE_1MB;
  234. change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT;
  235. txrates->default_fallback = IEEE80211_CCK_RATE_1MB;
  236. change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK;
  237. txrates->mcast_rate = IEEE80211_CCK_RATE_1MB;
  238. change |= IEEE80211SOFTMAC_TXRATECHG_MCAST;
  239. txrates->mgt_mcast_rate = IEEE80211_CCK_RATE_1MB;
  240. change |= IEEE80211SOFTMAC_TXRATECHG_MGT_MCAST;
  241. if (mac->txrates_change)
  242. mac->txrates_change(mac->dev, change);
  243. change = 0;
  244. bssinfo->supported_rates.count = 0;
  245. memset(bssinfo->supported_rates.rates, 0,
  246. sizeof(bssinfo->supported_rates.rates));
  247. change |= IEEE80211SOFTMAC_BSSINFOCHG_RATES;
  248. bssinfo->short_preamble = 0;
  249. change |= IEEE80211SOFTMAC_BSSINFOCHG_SHORT_PREAMBLE;
  250. bssinfo->use_protection = 0;
  251. change |= IEEE80211SOFTMAC_BSSINFOCHG_PROTECTION;
  252. if (mac->bssinfo_change)
  253. mac->bssinfo_change(mac->dev, change);
  254. mac->running = 1;
  255. }
  256. void ieee80211softmac_start(struct net_device *dev)
  257. {
  258. struct ieee80211softmac_device *mac = ieee80211_priv(dev);
  259. ieee80211softmac_start_check_rates(mac);
  260. ieee80211softmac_init_bss(mac);
  261. }
  262. EXPORT_SYMBOL_GPL(ieee80211softmac_start);
  263. void ieee80211softmac_stop(struct net_device *dev)
  264. {
  265. struct ieee80211softmac_device *mac = ieee80211_priv(dev);
  266. ieee80211softmac_clear_pending_work(mac);
  267. }
  268. EXPORT_SYMBOL_GPL(ieee80211softmac_stop);
  269. void ieee80211softmac_set_rates(struct net_device *dev, u8 count, u8 *rates)
  270. {
  271. struct ieee80211softmac_device *mac = ieee80211_priv(dev);
  272. unsigned long flags;
  273. spin_lock_irqsave(&mac->lock, flags);
  274. memcpy(mac->ratesinfo.rates, rates, count);
  275. mac->ratesinfo.count = count;
  276. spin_unlock_irqrestore(&mac->lock, flags);
  277. }
  278. EXPORT_SYMBOL_GPL(ieee80211softmac_set_rates);
  279. static u8 raise_rate(struct ieee80211softmac_device *mac, u8 rate)
  280. {
  281. int i;
  282. struct ieee80211softmac_ratesinfo *ri = &mac->ratesinfo;
  283. for (i=0; i<ri->count-1; i++) {
  284. if (ri->rates[i] == rate)
  285. return ri->rates[i+1];
  286. }
  287. /* I guess we can't go any higher... */
  288. return ri->rates[ri->count];
  289. }
  290. u8 ieee80211softmac_lower_rate_delta(struct ieee80211softmac_device *mac, u8 rate, int delta)
  291. {
  292. int i;
  293. struct ieee80211softmac_ratesinfo *ri = &mac->ratesinfo;
  294. for (i=delta; i<ri->count; i++) {
  295. if (ri->rates[i] == rate)
  296. return ri->rates[i-delta];
  297. }
  298. /* I guess we can't go any lower... */
  299. return ri->rates[0];
  300. }
  301. static void ieee80211softmac_add_txrates_badness(struct ieee80211softmac_device *mac,
  302. int amount)
  303. {
  304. u8 default_rate = mac->txrates.default_rate;
  305. u8 default_fallback = mac->txrates.default_fallback;
  306. u32 changes = 0;
  307. //TODO: This is highly experimental code.
  308. // Maybe the dynamic rate selection does not work
  309. // and it has to be removed again.
  310. printk("badness %d\n", mac->txrate_badness);
  311. mac->txrate_badness += amount;
  312. if (mac->txrate_badness <= -1000) {
  313. /* Very small badness. Try a faster bitrate. */
  314. default_rate = raise_rate(mac, default_rate);
  315. changes |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT;
  316. default_fallback = get_fallback_rate(mac, default_rate);
  317. changes |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK;
  318. mac->txrate_badness = 0;
  319. printk("Bitrate raised to %u\n", default_rate);
  320. } else if (mac->txrate_badness >= 10000) {
  321. /* Very high badness. Try a slower bitrate. */
  322. default_rate = lower_rate(mac, default_rate);
  323. changes |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT;
  324. default_fallback = get_fallback_rate(mac, default_rate);
  325. changes |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK;
  326. mac->txrate_badness = 0;
  327. printk("Bitrate lowered to %u\n", default_rate);
  328. }
  329. mac->txrates.default_rate = default_rate;
  330. mac->txrates.default_fallback = default_fallback;
  331. if (changes && mac->txrates_change)
  332. mac->txrates_change(mac->dev, changes);
  333. }
  334. void ieee80211softmac_fragment_lost(struct net_device *dev,
  335. u16 wl_seq)
  336. {
  337. struct ieee80211softmac_device *mac = ieee80211_priv(dev);
  338. unsigned long flags;
  339. spin_lock_irqsave(&mac->lock, flags);
  340. ieee80211softmac_add_txrates_badness(mac, 1000);
  341. //TODO
  342. spin_unlock_irqrestore(&mac->lock, flags);
  343. }
  344. EXPORT_SYMBOL_GPL(ieee80211softmac_fragment_lost);
  345. static int rate_cmp(const void *a_, const void *b_) {
  346. u8 *a, *b;
  347. a = (u8*)a_;
  348. b = (u8*)b_;
  349. return ((*a & ~IEEE80211_BASIC_RATE_MASK) - (*b & ~IEEE80211_BASIC_RATE_MASK));
  350. }
  351. /* Allocate a softmac network struct and fill it from a network */
  352. struct ieee80211softmac_network *
  353. ieee80211softmac_create_network(struct ieee80211softmac_device *mac,
  354. struct ieee80211_network *net)
  355. {
  356. struct ieee80211softmac_network *softnet;
  357. softnet = kzalloc(sizeof(struct ieee80211softmac_network), GFP_ATOMIC);
  358. if(softnet == NULL)
  359. return NULL;
  360. memcpy(softnet->bssid, net->bssid, ETH_ALEN);
  361. softnet->channel = net->channel;
  362. softnet->essid.len = net->ssid_len;
  363. memcpy(softnet->essid.data, net->ssid, softnet->essid.len);
  364. /* copy rates over */
  365. softnet->supported_rates.count = net->rates_len;
  366. memcpy(&softnet->supported_rates.rates[0], net->rates, net->rates_len);
  367. memcpy(&softnet->supported_rates.rates[softnet->supported_rates.count], net->rates_ex, net->rates_ex_len);
  368. softnet->supported_rates.count += net->rates_ex_len;
  369. sort(softnet->supported_rates.rates, softnet->supported_rates.count, sizeof(softnet->supported_rates.rates[0]), rate_cmp, NULL);
  370. /* we save the ERP value because it is needed at association time, and
  371. * many AP's do not include an ERP IE in the association response. */
  372. softnet->erp_value = net->erp_value;
  373. softnet->capabilities = net->capability;
  374. return softnet;
  375. }
  376. /* Add a network to the list, while locked */
  377. void
  378. ieee80211softmac_add_network_locked(struct ieee80211softmac_device *mac,
  379. struct ieee80211softmac_network *add_net)
  380. {
  381. struct list_head *list_ptr;
  382. struct ieee80211softmac_network *softmac_net = NULL;
  383. list_for_each(list_ptr, &mac->network_list) {
  384. softmac_net = list_entry(list_ptr, struct ieee80211softmac_network, list);
  385. if(!memcmp(softmac_net->bssid, add_net->bssid, ETH_ALEN))
  386. break;
  387. else
  388. softmac_net = NULL;
  389. }
  390. if(softmac_net == NULL)
  391. list_add(&(add_net->list), &mac->network_list);
  392. }
  393. /* Add a network to the list, with locking */
  394. void
  395. ieee80211softmac_add_network(struct ieee80211softmac_device *mac,
  396. struct ieee80211softmac_network *add_net)
  397. {
  398. unsigned long flags;
  399. spin_lock_irqsave(&mac->lock, flags);
  400. ieee80211softmac_add_network_locked(mac, add_net);
  401. spin_unlock_irqrestore(&mac->lock, flags);
  402. }
  403. /* Delete a network from the list, while locked*/
  404. void
  405. ieee80211softmac_del_network_locked(struct ieee80211softmac_device *mac,
  406. struct ieee80211softmac_network *del_net)
  407. {
  408. list_del(&(del_net->list));
  409. }
  410. /* Delete a network from the list with locking */
  411. void
  412. ieee80211softmac_del_network(struct ieee80211softmac_device *mac,
  413. struct ieee80211softmac_network *del_net)
  414. {
  415. unsigned long flags;
  416. spin_lock_irqsave(&mac->lock, flags);
  417. ieee80211softmac_del_network_locked(mac, del_net);
  418. spin_unlock_irqrestore(&mac->lock, flags);
  419. }
  420. /* Get a network from the list by MAC while locked */
  421. struct ieee80211softmac_network *
  422. ieee80211softmac_get_network_by_bssid_locked(struct ieee80211softmac_device *mac,
  423. u8 *bssid)
  424. {
  425. struct list_head *list_ptr;
  426. struct ieee80211softmac_network *softmac_net = NULL;
  427. list_for_each(list_ptr, &mac->network_list) {
  428. softmac_net = list_entry(list_ptr, struct ieee80211softmac_network, list);
  429. if(!memcmp(softmac_net->bssid, bssid, ETH_ALEN))
  430. break;
  431. else
  432. softmac_net = NULL;
  433. }
  434. return softmac_net;
  435. }
  436. /* Get a network from the list by BSSID with locking */
  437. struct ieee80211softmac_network *
  438. ieee80211softmac_get_network_by_bssid(struct ieee80211softmac_device *mac,
  439. u8 *bssid)
  440. {
  441. unsigned long flags;
  442. struct ieee80211softmac_network *softmac_net;
  443. spin_lock_irqsave(&mac->lock, flags);
  444. softmac_net = ieee80211softmac_get_network_by_bssid_locked(mac, bssid);
  445. spin_unlock_irqrestore(&mac->lock, flags);
  446. return softmac_net;
  447. }
  448. /* Get a network from the list by ESSID while locked */
  449. struct ieee80211softmac_network *
  450. ieee80211softmac_get_network_by_essid_locked(struct ieee80211softmac_device *mac,
  451. struct ieee80211softmac_essid *essid)
  452. {
  453. struct list_head *list_ptr;
  454. struct ieee80211softmac_network *softmac_net = NULL;
  455. list_for_each(list_ptr, &mac->network_list) {
  456. softmac_net = list_entry(list_ptr, struct ieee80211softmac_network, list);
  457. if (softmac_net->essid.len == essid->len &&
  458. !memcmp(softmac_net->essid.data, essid->data, essid->len))
  459. return softmac_net;
  460. }
  461. return NULL;
  462. }
  463. /* Get a network from the list by ESSID with locking */
  464. struct ieee80211softmac_network *
  465. ieee80211softmac_get_network_by_essid(struct ieee80211softmac_device *mac,
  466. struct ieee80211softmac_essid *essid)
  467. {
  468. unsigned long flags;
  469. struct ieee80211softmac_network *softmac_net = NULL;
  470. spin_lock_irqsave(&mac->lock, flags);
  471. softmac_net = ieee80211softmac_get_network_by_essid_locked(mac, essid);
  472. spin_unlock_irqrestore(&mac->lock, flags);
  473. return softmac_net;
  474. }
  475. MODULE_LICENSE("GPL");
  476. MODULE_AUTHOR("Johannes Berg");
  477. MODULE_AUTHOR("Joseph Jezak");
  478. MODULE_AUTHOR("Larry Finger");
  479. MODULE_AUTHOR("Danny van Dyk");
  480. MODULE_AUTHOR("Michael Buesch");
  481. MODULE_DESCRIPTION("802.11 software MAC");