hostap_ap.c 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358
  1. /*
  2. * Intersil Prism2 driver with Host AP (software access point) support
  3. * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  4. * <j@w1.fi>
  5. * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
  6. *
  7. * This file is to be included into hostap.c when S/W AP functionality is
  8. * compiled.
  9. *
  10. * AP: FIX:
  11. * - if unicast Class 2 (assoc,reassoc,disassoc) frame received from
  12. * unauthenticated STA, send deauth. frame (8802.11: 5.5)
  13. * - if unicast Class 3 (data with to/from DS,deauth,pspoll) frame received
  14. * from authenticated, but unassoc STA, send disassoc frame (8802.11: 5.5)
  15. * - if unicast Class 3 received from unauthenticated STA, send deauth. frame
  16. * (8802.11: 5.5)
  17. */
  18. #include <linux/proc_fs.h>
  19. #include <linux/delay.h>
  20. #include <linux/random.h>
  21. #include "hostap_wlan.h"
  22. #include "hostap.h"
  23. #include "hostap_ap.h"
  24. static int other_ap_policy[MAX_PARM_DEVICES] = { AP_OTHER_AP_SKIP_ALL,
  25. DEF_INTS };
  26. module_param_array(other_ap_policy, int, NULL, 0444);
  27. MODULE_PARM_DESC(other_ap_policy, "Other AP beacon monitoring policy (0-3)");
  28. static int ap_max_inactivity[MAX_PARM_DEVICES] = { AP_MAX_INACTIVITY_SEC,
  29. DEF_INTS };
  30. module_param_array(ap_max_inactivity, int, NULL, 0444);
  31. MODULE_PARM_DESC(ap_max_inactivity, "AP timeout (in seconds) for station "
  32. "inactivity");
  33. static int ap_bridge_packets[MAX_PARM_DEVICES] = { 1, DEF_INTS };
  34. module_param_array(ap_bridge_packets, int, NULL, 0444);
  35. MODULE_PARM_DESC(ap_bridge_packets, "Bridge packets directly between "
  36. "stations");
  37. static int autom_ap_wds[MAX_PARM_DEVICES] = { 0, DEF_INTS };
  38. module_param_array(autom_ap_wds, int, NULL, 0444);
  39. MODULE_PARM_DESC(autom_ap_wds, "Add WDS connections to other APs "
  40. "automatically");
  41. static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta);
  42. static void hostap_event_expired_sta(struct net_device *dev,
  43. struct sta_info *sta);
  44. static void handle_add_proc_queue(struct work_struct *work);
  45. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  46. static void handle_wds_oper_queue(struct work_struct *work);
  47. static void prism2_send_mgmt(struct net_device *dev,
  48. u16 type_subtype, char *body,
  49. int body_len, u8 *addr, u16 tx_cb_idx);
  50. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  51. #ifndef PRISM2_NO_PROCFS_DEBUG
  52. static int ap_debug_proc_read(char *page, char **start, off_t off,
  53. int count, int *eof, void *data)
  54. {
  55. char *p = page;
  56. struct ap_data *ap = (struct ap_data *) data;
  57. if (off != 0) {
  58. *eof = 1;
  59. return 0;
  60. }
  61. p += sprintf(p, "BridgedUnicastFrames=%u\n", ap->bridged_unicast);
  62. p += sprintf(p, "BridgedMulticastFrames=%u\n", ap->bridged_multicast);
  63. p += sprintf(p, "max_inactivity=%u\n", ap->max_inactivity / HZ);
  64. p += sprintf(p, "bridge_packets=%u\n", ap->bridge_packets);
  65. p += sprintf(p, "nullfunc_ack=%u\n", ap->nullfunc_ack);
  66. p += sprintf(p, "autom_ap_wds=%u\n", ap->autom_ap_wds);
  67. p += sprintf(p, "auth_algs=%u\n", ap->local->auth_algs);
  68. p += sprintf(p, "tx_drop_nonassoc=%u\n", ap->tx_drop_nonassoc);
  69. return (p - page);
  70. }
  71. #endif /* PRISM2_NO_PROCFS_DEBUG */
  72. static void ap_sta_hash_add(struct ap_data *ap, struct sta_info *sta)
  73. {
  74. sta->hnext = ap->sta_hash[STA_HASH(sta->addr)];
  75. ap->sta_hash[STA_HASH(sta->addr)] = sta;
  76. }
  77. static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
  78. {
  79. struct sta_info *s;
  80. DECLARE_MAC_BUF(mac);
  81. s = ap->sta_hash[STA_HASH(sta->addr)];
  82. if (s == NULL) return;
  83. if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
  84. ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
  85. return;
  86. }
  87. while (s->hnext != NULL && memcmp(s->hnext->addr, sta->addr, ETH_ALEN)
  88. != 0)
  89. s = s->hnext;
  90. if (s->hnext != NULL)
  91. s->hnext = s->hnext->hnext;
  92. else
  93. printk("AP: could not remove STA %s"
  94. " from hash table\n",
  95. print_mac(mac, sta->addr));
  96. }
  97. static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
  98. {
  99. DECLARE_MAC_BUF(mac);
  100. if (sta->ap && sta->local)
  101. hostap_event_expired_sta(sta->local->dev, sta);
  102. if (ap->proc != NULL) {
  103. char name[20];
  104. sprintf(name, "%s", print_mac(mac, sta->addr));
  105. remove_proc_entry(name, ap->proc);
  106. }
  107. if (sta->crypt) {
  108. sta->crypt->ops->deinit(sta->crypt->priv);
  109. kfree(sta->crypt);
  110. sta->crypt = NULL;
  111. }
  112. skb_queue_purge(&sta->tx_buf);
  113. ap->num_sta--;
  114. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  115. if (sta->aid > 0)
  116. ap->sta_aid[sta->aid - 1] = NULL;
  117. if (!sta->ap && sta->u.sta.challenge)
  118. kfree(sta->u.sta.challenge);
  119. del_timer(&sta->timer);
  120. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  121. kfree(sta);
  122. }
  123. static void hostap_set_tim(local_info_t *local, int aid, int set)
  124. {
  125. if (local->func->set_tim)
  126. local->func->set_tim(local->dev, aid, set);
  127. }
  128. static void hostap_event_new_sta(struct net_device *dev, struct sta_info *sta)
  129. {
  130. union iwreq_data wrqu;
  131. memset(&wrqu, 0, sizeof(wrqu));
  132. memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
  133. wrqu.addr.sa_family = ARPHRD_ETHER;
  134. wireless_send_event(dev, IWEVREGISTERED, &wrqu, NULL);
  135. }
  136. static void hostap_event_expired_sta(struct net_device *dev,
  137. struct sta_info *sta)
  138. {
  139. union iwreq_data wrqu;
  140. memset(&wrqu, 0, sizeof(wrqu));
  141. memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
  142. wrqu.addr.sa_family = ARPHRD_ETHER;
  143. wireless_send_event(dev, IWEVEXPIRED, &wrqu, NULL);
  144. }
  145. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  146. static void ap_handle_timer(unsigned long data)
  147. {
  148. struct sta_info *sta = (struct sta_info *) data;
  149. local_info_t *local;
  150. struct ap_data *ap;
  151. unsigned long next_time = 0;
  152. int was_assoc;
  153. DECLARE_MAC_BUF(mac);
  154. if (sta == NULL || sta->local == NULL || sta->local->ap == NULL) {
  155. PDEBUG(DEBUG_AP, "ap_handle_timer() called with NULL data\n");
  156. return;
  157. }
  158. local = sta->local;
  159. ap = local->ap;
  160. was_assoc = sta->flags & WLAN_STA_ASSOC;
  161. if (atomic_read(&sta->users) != 0)
  162. next_time = jiffies + HZ;
  163. else if ((sta->flags & WLAN_STA_PERM) && !(sta->flags & WLAN_STA_AUTH))
  164. next_time = jiffies + ap->max_inactivity;
  165. if (time_before(jiffies, sta->last_rx + ap->max_inactivity)) {
  166. /* station activity detected; reset timeout state */
  167. sta->timeout_next = STA_NULLFUNC;
  168. next_time = sta->last_rx + ap->max_inactivity;
  169. } else if (sta->timeout_next == STA_DISASSOC &&
  170. !(sta->flags & WLAN_STA_PENDING_POLL)) {
  171. /* STA ACKed data nullfunc frame poll */
  172. sta->timeout_next = STA_NULLFUNC;
  173. next_time = jiffies + ap->max_inactivity;
  174. }
  175. if (next_time) {
  176. sta->timer.expires = next_time;
  177. add_timer(&sta->timer);
  178. return;
  179. }
  180. if (sta->ap)
  181. sta->timeout_next = STA_DEAUTH;
  182. if (sta->timeout_next == STA_DEAUTH && !(sta->flags & WLAN_STA_PERM)) {
  183. spin_lock(&ap->sta_table_lock);
  184. ap_sta_hash_del(ap, sta);
  185. list_del(&sta->list);
  186. spin_unlock(&ap->sta_table_lock);
  187. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
  188. } else if (sta->timeout_next == STA_DISASSOC)
  189. sta->flags &= ~WLAN_STA_ASSOC;
  190. if (was_assoc && !(sta->flags & WLAN_STA_ASSOC) && !sta->ap)
  191. hostap_event_expired_sta(local->dev, sta);
  192. if (sta->timeout_next == STA_DEAUTH && sta->aid > 0 &&
  193. !skb_queue_empty(&sta->tx_buf)) {
  194. hostap_set_tim(local, sta->aid, 0);
  195. sta->flags &= ~WLAN_STA_TIM;
  196. }
  197. if (sta->ap) {
  198. if (ap->autom_ap_wds) {
  199. PDEBUG(DEBUG_AP, "%s: removing automatic WDS "
  200. "connection to AP %s\n",
  201. local->dev->name, print_mac(mac, sta->addr));
  202. hostap_wds_link_oper(local, sta->addr, WDS_DEL);
  203. }
  204. } else if (sta->timeout_next == STA_NULLFUNC) {
  205. /* send data frame to poll STA and check whether this frame
  206. * is ACKed */
  207. /* FIX: IEEE80211_STYPE_NULLFUNC would be more appropriate, but
  208. * it is apparently not retried so TX Exc events are not
  209. * received for it */
  210. sta->flags |= WLAN_STA_PENDING_POLL;
  211. prism2_send_mgmt(local->dev, IEEE80211_FTYPE_DATA |
  212. IEEE80211_STYPE_DATA, NULL, 0,
  213. sta->addr, ap->tx_callback_poll);
  214. } else {
  215. int deauth = sta->timeout_next == STA_DEAUTH;
  216. __le16 resp;
  217. PDEBUG(DEBUG_AP, "%s: sending %s info to STA %s"
  218. "(last=%lu, jiffies=%lu)\n",
  219. local->dev->name,
  220. deauth ? "deauthentication" : "disassociation",
  221. print_mac(mac, sta->addr), sta->last_rx, jiffies);
  222. resp = cpu_to_le16(deauth ? WLAN_REASON_PREV_AUTH_NOT_VALID :
  223. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  224. prism2_send_mgmt(local->dev, IEEE80211_FTYPE_MGMT |
  225. (deauth ? IEEE80211_STYPE_DEAUTH :
  226. IEEE80211_STYPE_DISASSOC),
  227. (char *) &resp, 2, sta->addr, 0);
  228. }
  229. if (sta->timeout_next == STA_DEAUTH) {
  230. if (sta->flags & WLAN_STA_PERM) {
  231. PDEBUG(DEBUG_AP, "%s: STA %s"
  232. " would have been removed, "
  233. "but it has 'perm' flag\n",
  234. local->dev->name, print_mac(mac, sta->addr));
  235. } else
  236. ap_free_sta(ap, sta);
  237. return;
  238. }
  239. if (sta->timeout_next == STA_NULLFUNC) {
  240. sta->timeout_next = STA_DISASSOC;
  241. sta->timer.expires = jiffies + AP_DISASSOC_DELAY;
  242. } else {
  243. sta->timeout_next = STA_DEAUTH;
  244. sta->timer.expires = jiffies + AP_DEAUTH_DELAY;
  245. }
  246. add_timer(&sta->timer);
  247. }
  248. void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
  249. int resend)
  250. {
  251. u8 addr[ETH_ALEN];
  252. __le16 resp;
  253. int i;
  254. PDEBUG(DEBUG_AP, "%s: Deauthenticate all stations\n", dev->name);
  255. memset(addr, 0xff, ETH_ALEN);
  256. resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
  257. /* deauth message sent; try to resend it few times; the message is
  258. * broadcast, so it may be delayed until next DTIM; there is not much
  259. * else we can do at this point since the driver is going to be shut
  260. * down */
  261. for (i = 0; i < 5; i++) {
  262. prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
  263. IEEE80211_STYPE_DEAUTH,
  264. (char *) &resp, 2, addr, 0);
  265. if (!resend || ap->num_sta <= 0)
  266. return;
  267. mdelay(50);
  268. }
  269. }
  270. static int ap_control_proc_read(char *page, char **start, off_t off,
  271. int count, int *eof, void *data)
  272. {
  273. char *p = page;
  274. struct ap_data *ap = (struct ap_data *) data;
  275. char *policy_txt;
  276. struct mac_entry *entry;
  277. DECLARE_MAC_BUF(mac);
  278. if (off != 0) {
  279. *eof = 1;
  280. return 0;
  281. }
  282. switch (ap->mac_restrictions.policy) {
  283. case MAC_POLICY_OPEN:
  284. policy_txt = "open";
  285. break;
  286. case MAC_POLICY_ALLOW:
  287. policy_txt = "allow";
  288. break;
  289. case MAC_POLICY_DENY:
  290. policy_txt = "deny";
  291. break;
  292. default:
  293. policy_txt = "unknown";
  294. break;
  295. };
  296. p += sprintf(p, "MAC policy: %s\n", policy_txt);
  297. p += sprintf(p, "MAC entries: %u\n", ap->mac_restrictions.entries);
  298. p += sprintf(p, "MAC list:\n");
  299. spin_lock_bh(&ap->mac_restrictions.lock);
  300. list_for_each_entry(entry, &ap->mac_restrictions.mac_list, list) {
  301. if (p - page > PAGE_SIZE - 80) {
  302. p += sprintf(p, "All entries did not fit one page.\n");
  303. break;
  304. }
  305. p += sprintf(p, "%s\n", print_mac(mac, entry->addr));
  306. }
  307. spin_unlock_bh(&ap->mac_restrictions.lock);
  308. return (p - page);
  309. }
  310. int ap_control_add_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
  311. {
  312. struct mac_entry *entry;
  313. entry = kmalloc(sizeof(struct mac_entry), GFP_KERNEL);
  314. if (entry == NULL)
  315. return -1;
  316. memcpy(entry->addr, mac, ETH_ALEN);
  317. spin_lock_bh(&mac_restrictions->lock);
  318. list_add_tail(&entry->list, &mac_restrictions->mac_list);
  319. mac_restrictions->entries++;
  320. spin_unlock_bh(&mac_restrictions->lock);
  321. return 0;
  322. }
  323. int ap_control_del_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
  324. {
  325. struct list_head *ptr;
  326. struct mac_entry *entry;
  327. spin_lock_bh(&mac_restrictions->lock);
  328. for (ptr = mac_restrictions->mac_list.next;
  329. ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
  330. entry = list_entry(ptr, struct mac_entry, list);
  331. if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
  332. list_del(ptr);
  333. kfree(entry);
  334. mac_restrictions->entries--;
  335. spin_unlock_bh(&mac_restrictions->lock);
  336. return 0;
  337. }
  338. }
  339. spin_unlock_bh(&mac_restrictions->lock);
  340. return -1;
  341. }
  342. static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
  343. u8 *mac)
  344. {
  345. struct mac_entry *entry;
  346. int found = 0;
  347. if (mac_restrictions->policy == MAC_POLICY_OPEN)
  348. return 0;
  349. spin_lock_bh(&mac_restrictions->lock);
  350. list_for_each_entry(entry, &mac_restrictions->mac_list, list) {
  351. if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
  352. found = 1;
  353. break;
  354. }
  355. }
  356. spin_unlock_bh(&mac_restrictions->lock);
  357. if (mac_restrictions->policy == MAC_POLICY_ALLOW)
  358. return !found;
  359. else
  360. return found;
  361. }
  362. void ap_control_flush_macs(struct mac_restrictions *mac_restrictions)
  363. {
  364. struct list_head *ptr, *n;
  365. struct mac_entry *entry;
  366. if (mac_restrictions->entries == 0)
  367. return;
  368. spin_lock_bh(&mac_restrictions->lock);
  369. for (ptr = mac_restrictions->mac_list.next, n = ptr->next;
  370. ptr != &mac_restrictions->mac_list;
  371. ptr = n, n = ptr->next) {
  372. entry = list_entry(ptr, struct mac_entry, list);
  373. list_del(ptr);
  374. kfree(entry);
  375. }
  376. mac_restrictions->entries = 0;
  377. spin_unlock_bh(&mac_restrictions->lock);
  378. }
  379. int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev, u8 *mac)
  380. {
  381. struct sta_info *sta;
  382. __le16 resp;
  383. spin_lock_bh(&ap->sta_table_lock);
  384. sta = ap_get_sta(ap, mac);
  385. if (sta) {
  386. ap_sta_hash_del(ap, sta);
  387. list_del(&sta->list);
  388. }
  389. spin_unlock_bh(&ap->sta_table_lock);
  390. if (!sta)
  391. return -EINVAL;
  392. resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
  393. prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH,
  394. (char *) &resp, 2, sta->addr, 0);
  395. if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
  396. hostap_event_expired_sta(dev, sta);
  397. ap_free_sta(ap, sta);
  398. return 0;
  399. }
  400. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  401. void ap_control_kickall(struct ap_data *ap)
  402. {
  403. struct list_head *ptr, *n;
  404. struct sta_info *sta;
  405. spin_lock_bh(&ap->sta_table_lock);
  406. for (ptr = ap->sta_list.next, n = ptr->next; ptr != &ap->sta_list;
  407. ptr = n, n = ptr->next) {
  408. sta = list_entry(ptr, struct sta_info, list);
  409. ap_sta_hash_del(ap, sta);
  410. list_del(&sta->list);
  411. if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
  412. hostap_event_expired_sta(sta->local->dev, sta);
  413. ap_free_sta(ap, sta);
  414. }
  415. spin_unlock_bh(&ap->sta_table_lock);
  416. }
  417. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  418. #define PROC_LIMIT (PAGE_SIZE - 80)
  419. static int prism2_ap_proc_read(char *page, char **start, off_t off,
  420. int count, int *eof, void *data)
  421. {
  422. char *p = page;
  423. struct ap_data *ap = (struct ap_data *) data;
  424. struct sta_info *sta;
  425. int i;
  426. DECLARE_MAC_BUF(mac);
  427. if (off > PROC_LIMIT) {
  428. *eof = 1;
  429. return 0;
  430. }
  431. p += sprintf(p, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
  432. spin_lock_bh(&ap->sta_table_lock);
  433. list_for_each_entry(sta, &ap->sta_list, list) {
  434. if (!sta->ap)
  435. continue;
  436. p += sprintf(p, "%s %d %d %d %d '",
  437. print_mac(mac, sta->addr),
  438. sta->u.ap.channel, sta->last_rx_signal,
  439. sta->last_rx_silence, sta->last_rx_rate);
  440. for (i = 0; i < sta->u.ap.ssid_len; i++)
  441. p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
  442. sta->u.ap.ssid[i] < 127) ?
  443. "%c" : "<%02x>"),
  444. sta->u.ap.ssid[i]);
  445. p += sprintf(p, "'");
  446. if (sta->capability & WLAN_CAPABILITY_ESS)
  447. p += sprintf(p, " [ESS]");
  448. if (sta->capability & WLAN_CAPABILITY_IBSS)
  449. p += sprintf(p, " [IBSS]");
  450. if (sta->capability & WLAN_CAPABILITY_PRIVACY)
  451. p += sprintf(p, " [WEP]");
  452. p += sprintf(p, "\n");
  453. if ((p - page) > PROC_LIMIT) {
  454. printk(KERN_DEBUG "hostap: ap proc did not fit\n");
  455. break;
  456. }
  457. }
  458. spin_unlock_bh(&ap->sta_table_lock);
  459. if ((p - page) <= off) {
  460. *eof = 1;
  461. return 0;
  462. }
  463. *start = page + off;
  464. return (p - page - off);
  465. }
  466. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  467. void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver)
  468. {
  469. if (!ap)
  470. return;
  471. if (sta_fw_ver == PRISM2_FW_VER(0,8,0)) {
  472. PDEBUG(DEBUG_AP, "Using data::nullfunc ACK workaround - "
  473. "firmware upgrade recommended\n");
  474. ap->nullfunc_ack = 1;
  475. } else
  476. ap->nullfunc_ack = 0;
  477. if (sta_fw_ver == PRISM2_FW_VER(1,4,2)) {
  478. printk(KERN_WARNING "%s: Warning: secondary station firmware "
  479. "version 1.4.2 does not seem to work in Host AP mode\n",
  480. ap->local->dev->name);
  481. }
  482. }
  483. /* Called only as a tasklet (software IRQ) */
  484. static void hostap_ap_tx_cb(struct sk_buff *skb, int ok, void *data)
  485. {
  486. struct ap_data *ap = data;
  487. u16 fc;
  488. struct ieee80211_hdr_4addr *hdr;
  489. if (!ap->local->hostapd || !ap->local->apdev) {
  490. dev_kfree_skb(skb);
  491. return;
  492. }
  493. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  494. fc = le16_to_cpu(hdr->frame_ctl);
  495. /* Pass the TX callback frame to the hostapd; use 802.11 header version
  496. * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
  497. fc &= ~IEEE80211_FCTL_VERS;
  498. fc |= ok ? BIT(1) : BIT(0);
  499. hdr->frame_ctl = cpu_to_le16(fc);
  500. skb->dev = ap->local->apdev;
  501. skb_pull(skb, hostap_80211_get_hdrlen(fc));
  502. skb->pkt_type = PACKET_OTHERHOST;
  503. skb->protocol = __constant_htons(ETH_P_802_2);
  504. memset(skb->cb, 0, sizeof(skb->cb));
  505. netif_rx(skb);
  506. }
  507. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  508. /* Called only as a tasklet (software IRQ) */
  509. static void hostap_ap_tx_cb_auth(struct sk_buff *skb, int ok, void *data)
  510. {
  511. struct ap_data *ap = data;
  512. struct net_device *dev = ap->local->dev;
  513. struct ieee80211_hdr_4addr *hdr;
  514. u16 fc, auth_alg, auth_transaction, status;
  515. __le16 *pos;
  516. struct sta_info *sta = NULL;
  517. char *txt = NULL;
  518. if (ap->local->hostapd) {
  519. dev_kfree_skb(skb);
  520. return;
  521. }
  522. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  523. fc = le16_to_cpu(hdr->frame_ctl);
  524. if (WLAN_FC_GET_TYPE(fc) != IEEE80211_FTYPE_MGMT ||
  525. WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_AUTH ||
  526. skb->len < IEEE80211_MGMT_HDR_LEN + 6) {
  527. printk(KERN_DEBUG "%s: hostap_ap_tx_cb_auth received invalid "
  528. "frame\n", dev->name);
  529. dev_kfree_skb(skb);
  530. return;
  531. }
  532. pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
  533. auth_alg = le16_to_cpu(*pos++);
  534. auth_transaction = le16_to_cpu(*pos++);
  535. status = le16_to_cpu(*pos++);
  536. if (!ok) {
  537. txt = "frame was not ACKed";
  538. goto done;
  539. }
  540. spin_lock(&ap->sta_table_lock);
  541. sta = ap_get_sta(ap, hdr->addr1);
  542. if (sta)
  543. atomic_inc(&sta->users);
  544. spin_unlock(&ap->sta_table_lock);
  545. if (!sta) {
  546. txt = "STA not found";
  547. goto done;
  548. }
  549. if (status == WLAN_STATUS_SUCCESS &&
  550. ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
  551. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
  552. txt = "STA authenticated";
  553. sta->flags |= WLAN_STA_AUTH;
  554. sta->last_auth = jiffies;
  555. } else if (status != WLAN_STATUS_SUCCESS)
  556. txt = "authentication failed";
  557. done:
  558. if (sta)
  559. atomic_dec(&sta->users);
  560. if (txt) {
  561. PDEBUG(DEBUG_AP, "%s: " MAC_FMT " auth_cb - alg=%d "
  562. "trans#=%d status=%d - %s\n",
  563. dev->name,
  564. hdr->addr1[0], hdr->addr1[1], hdr->addr1[2],
  565. hdr->addr1[3], hdr->addr1[4], hdr->addr1[5],
  566. auth_alg, auth_transaction, status, txt);
  567. }
  568. dev_kfree_skb(skb);
  569. }
  570. /* Called only as a tasklet (software IRQ) */
  571. static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
  572. {
  573. struct ap_data *ap = data;
  574. struct net_device *dev = ap->local->dev;
  575. struct ieee80211_hdr_4addr *hdr;
  576. u16 fc, status;
  577. __le16 *pos;
  578. struct sta_info *sta = NULL;
  579. char *txt = NULL;
  580. if (ap->local->hostapd) {
  581. dev_kfree_skb(skb);
  582. return;
  583. }
  584. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  585. fc = le16_to_cpu(hdr->frame_ctl);
  586. if (WLAN_FC_GET_TYPE(fc) != IEEE80211_FTYPE_MGMT ||
  587. (WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_ASSOC_RESP &&
  588. WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_REASSOC_RESP) ||
  589. skb->len < IEEE80211_MGMT_HDR_LEN + 4) {
  590. printk(KERN_DEBUG "%s: hostap_ap_tx_cb_assoc received invalid "
  591. "frame\n", dev->name);
  592. dev_kfree_skb(skb);
  593. return;
  594. }
  595. if (!ok) {
  596. txt = "frame was not ACKed";
  597. goto done;
  598. }
  599. spin_lock(&ap->sta_table_lock);
  600. sta = ap_get_sta(ap, hdr->addr1);
  601. if (sta)
  602. atomic_inc(&sta->users);
  603. spin_unlock(&ap->sta_table_lock);
  604. if (!sta) {
  605. txt = "STA not found";
  606. goto done;
  607. }
  608. pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
  609. pos++;
  610. status = le16_to_cpu(*pos++);
  611. if (status == WLAN_STATUS_SUCCESS) {
  612. if (!(sta->flags & WLAN_STA_ASSOC))
  613. hostap_event_new_sta(dev, sta);
  614. txt = "STA associated";
  615. sta->flags |= WLAN_STA_ASSOC;
  616. sta->last_assoc = jiffies;
  617. } else
  618. txt = "association failed";
  619. done:
  620. if (sta)
  621. atomic_dec(&sta->users);
  622. if (txt) {
  623. PDEBUG(DEBUG_AP, "%s: " MAC_FMT " assoc_cb - %s\n",
  624. dev->name,
  625. hdr->addr1[0], hdr->addr1[1], hdr->addr1[2],
  626. hdr->addr1[3], hdr->addr1[4], hdr->addr1[5],
  627. txt);
  628. }
  629. dev_kfree_skb(skb);
  630. }
  631. /* Called only as a tasklet (software IRQ); TX callback for poll frames used
  632. * in verifying whether the STA is still present. */
  633. static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data)
  634. {
  635. struct ap_data *ap = data;
  636. struct ieee80211_hdr_4addr *hdr;
  637. struct sta_info *sta;
  638. if (skb->len < 24)
  639. goto fail;
  640. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  641. if (ok) {
  642. spin_lock(&ap->sta_table_lock);
  643. sta = ap_get_sta(ap, hdr->addr1);
  644. if (sta)
  645. sta->flags &= ~WLAN_STA_PENDING_POLL;
  646. spin_unlock(&ap->sta_table_lock);
  647. } else {
  648. PDEBUG(DEBUG_AP, "%s: STA " MAC_FMT
  649. " did not ACK activity poll frame\n",
  650. ap->local->dev->name,
  651. hdr->addr1[0], hdr->addr1[1], hdr->addr1[2],
  652. hdr->addr1[3], hdr->addr1[4], hdr->addr1[5]);
  653. }
  654. fail:
  655. dev_kfree_skb(skb);
  656. }
  657. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  658. void hostap_init_data(local_info_t *local)
  659. {
  660. struct ap_data *ap = local->ap;
  661. if (ap == NULL) {
  662. printk(KERN_WARNING "hostap_init_data: ap == NULL\n");
  663. return;
  664. }
  665. memset(ap, 0, sizeof(struct ap_data));
  666. ap->local = local;
  667. ap->ap_policy = GET_INT_PARM(other_ap_policy, local->card_idx);
  668. ap->bridge_packets = GET_INT_PARM(ap_bridge_packets, local->card_idx);
  669. ap->max_inactivity =
  670. GET_INT_PARM(ap_max_inactivity, local->card_idx) * HZ;
  671. ap->autom_ap_wds = GET_INT_PARM(autom_ap_wds, local->card_idx);
  672. spin_lock_init(&ap->sta_table_lock);
  673. INIT_LIST_HEAD(&ap->sta_list);
  674. /* Initialize task queue structure for AP management */
  675. INIT_WORK(&local->ap->add_sta_proc_queue, handle_add_proc_queue);
  676. ap->tx_callback_idx =
  677. hostap_tx_callback_register(local, hostap_ap_tx_cb, ap);
  678. if (ap->tx_callback_idx == 0)
  679. printk(KERN_WARNING "%s: failed to register TX callback for "
  680. "AP\n", local->dev->name);
  681. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  682. INIT_WORK(&local->ap->wds_oper_queue, handle_wds_oper_queue);
  683. ap->tx_callback_auth =
  684. hostap_tx_callback_register(local, hostap_ap_tx_cb_auth, ap);
  685. ap->tx_callback_assoc =
  686. hostap_tx_callback_register(local, hostap_ap_tx_cb_assoc, ap);
  687. ap->tx_callback_poll =
  688. hostap_tx_callback_register(local, hostap_ap_tx_cb_poll, ap);
  689. if (ap->tx_callback_auth == 0 || ap->tx_callback_assoc == 0 ||
  690. ap->tx_callback_poll == 0)
  691. printk(KERN_WARNING "%s: failed to register TX callback for "
  692. "AP\n", local->dev->name);
  693. spin_lock_init(&ap->mac_restrictions.lock);
  694. INIT_LIST_HEAD(&ap->mac_restrictions.mac_list);
  695. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  696. ap->initialized = 1;
  697. }
  698. void hostap_init_ap_proc(local_info_t *local)
  699. {
  700. struct ap_data *ap = local->ap;
  701. ap->proc = local->proc;
  702. if (ap->proc == NULL)
  703. return;
  704. #ifndef PRISM2_NO_PROCFS_DEBUG
  705. create_proc_read_entry("ap_debug", 0, ap->proc,
  706. ap_debug_proc_read, ap);
  707. #endif /* PRISM2_NO_PROCFS_DEBUG */
  708. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  709. create_proc_read_entry("ap_control", 0, ap->proc,
  710. ap_control_proc_read, ap);
  711. create_proc_read_entry("ap", 0, ap->proc,
  712. prism2_ap_proc_read, ap);
  713. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  714. }
  715. void hostap_free_data(struct ap_data *ap)
  716. {
  717. struct sta_info *n, *sta;
  718. if (ap == NULL || !ap->initialized) {
  719. printk(KERN_DEBUG "hostap_free_data: ap has not yet been "
  720. "initialized - skip resource freeing\n");
  721. return;
  722. }
  723. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  724. if (ap->crypt)
  725. ap->crypt->deinit(ap->crypt_priv);
  726. ap->crypt = ap->crypt_priv = NULL;
  727. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  728. list_for_each_entry_safe(sta, n, &ap->sta_list, list) {
  729. ap_sta_hash_del(ap, sta);
  730. list_del(&sta->list);
  731. if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
  732. hostap_event_expired_sta(sta->local->dev, sta);
  733. ap_free_sta(ap, sta);
  734. }
  735. #ifndef PRISM2_NO_PROCFS_DEBUG
  736. if (ap->proc != NULL) {
  737. remove_proc_entry("ap_debug", ap->proc);
  738. }
  739. #endif /* PRISM2_NO_PROCFS_DEBUG */
  740. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  741. if (ap->proc != NULL) {
  742. remove_proc_entry("ap", ap->proc);
  743. remove_proc_entry("ap_control", ap->proc);
  744. }
  745. ap_control_flush_macs(&ap->mac_restrictions);
  746. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  747. ap->initialized = 0;
  748. }
  749. /* caller should have mutex for AP STA list handling */
  750. static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta)
  751. {
  752. struct sta_info *s;
  753. s = ap->sta_hash[STA_HASH(sta)];
  754. while (s != NULL && memcmp(s->addr, sta, ETH_ALEN) != 0)
  755. s = s->hnext;
  756. return s;
  757. }
  758. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  759. /* Called from timer handler and from scheduled AP queue handlers */
  760. static void prism2_send_mgmt(struct net_device *dev,
  761. u16 type_subtype, char *body,
  762. int body_len, u8 *addr, u16 tx_cb_idx)
  763. {
  764. struct hostap_interface *iface;
  765. local_info_t *local;
  766. struct ieee80211_hdr_4addr *hdr;
  767. u16 fc;
  768. struct sk_buff *skb;
  769. struct hostap_skb_tx_data *meta;
  770. int hdrlen;
  771. iface = netdev_priv(dev);
  772. local = iface->local;
  773. dev = local->dev; /* always use master radio device */
  774. iface = netdev_priv(dev);
  775. if (!(dev->flags & IFF_UP)) {
  776. PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt - device is not UP - "
  777. "cannot send frame\n", dev->name);
  778. return;
  779. }
  780. skb = dev_alloc_skb(sizeof(*hdr) + body_len);
  781. if (skb == NULL) {
  782. PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt failed to allocate "
  783. "skb\n", dev->name);
  784. return;
  785. }
  786. fc = type_subtype;
  787. hdrlen = hostap_80211_get_hdrlen(fc);
  788. hdr = (struct ieee80211_hdr_4addr *) skb_put(skb, hdrlen);
  789. if (body)
  790. memcpy(skb_put(skb, body_len), body, body_len);
  791. memset(hdr, 0, hdrlen);
  792. /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
  793. * tx_control instead of using local->tx_control */
  794. memcpy(hdr->addr1, addr, ETH_ALEN); /* DA / RA */
  795. if (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA) {
  796. fc |= IEEE80211_FCTL_FROMDS;
  797. memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* BSSID */
  798. memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* SA */
  799. } else if (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_CTL) {
  800. /* control:ACK does not have addr2 or addr3 */
  801. memset(hdr->addr2, 0, ETH_ALEN);
  802. memset(hdr->addr3, 0, ETH_ALEN);
  803. } else {
  804. memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* SA */
  805. memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* BSSID */
  806. }
  807. hdr->frame_ctl = cpu_to_le16(fc);
  808. meta = (struct hostap_skb_tx_data *) skb->cb;
  809. memset(meta, 0, sizeof(*meta));
  810. meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
  811. meta->iface = iface;
  812. meta->tx_cb_idx = tx_cb_idx;
  813. skb->dev = dev;
  814. skb_reset_mac_header(skb);
  815. skb_reset_network_header(skb);
  816. dev_queue_xmit(skb);
  817. }
  818. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  819. static int prism2_sta_proc_read(char *page, char **start, off_t off,
  820. int count, int *eof, void *data)
  821. {
  822. char *p = page;
  823. struct sta_info *sta = (struct sta_info *) data;
  824. int i;
  825. DECLARE_MAC_BUF(mac);
  826. /* FIX: possible race condition.. the STA data could have just expired,
  827. * but proc entry was still here so that the read could have started;
  828. * some locking should be done here.. */
  829. if (off != 0) {
  830. *eof = 1;
  831. return 0;
  832. }
  833. p += sprintf(p, "%s=%s\nusers=%d\naid=%d\n"
  834. "flags=0x%04x%s%s%s%s%s%s%s\n"
  835. "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
  836. sta->ap ? "AP" : "STA",
  837. print_mac(mac, sta->addr), atomic_read(&sta->users), sta->aid,
  838. sta->flags,
  839. sta->flags & WLAN_STA_AUTH ? " AUTH" : "",
  840. sta->flags & WLAN_STA_ASSOC ? " ASSOC" : "",
  841. sta->flags & WLAN_STA_PS ? " PS" : "",
  842. sta->flags & WLAN_STA_TIM ? " TIM" : "",
  843. sta->flags & WLAN_STA_PERM ? " PERM" : "",
  844. sta->flags & WLAN_STA_AUTHORIZED ? " AUTHORIZED" : "",
  845. sta->flags & WLAN_STA_PENDING_POLL ? " POLL" : "",
  846. sta->capability, sta->listen_interval);
  847. /* supported_rates: 500 kbit/s units with msb ignored */
  848. for (i = 0; i < sizeof(sta->supported_rates); i++)
  849. if (sta->supported_rates[i] != 0)
  850. p += sprintf(p, "%d%sMbps ",
  851. (sta->supported_rates[i] & 0x7f) / 2,
  852. sta->supported_rates[i] & 1 ? ".5" : "");
  853. p += sprintf(p, "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
  854. "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
  855. "tx_packets=%lu\n"
  856. "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
  857. "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
  858. "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
  859. "tx[11M]=%d\n"
  860. "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
  861. jiffies, sta->last_auth, sta->last_assoc, sta->last_rx,
  862. sta->last_tx,
  863. sta->rx_packets, sta->tx_packets, sta->rx_bytes,
  864. sta->tx_bytes, skb_queue_len(&sta->tx_buf),
  865. sta->last_rx_silence,
  866. sta->last_rx_signal, sta->last_rx_rate / 10,
  867. sta->last_rx_rate % 10 ? ".5" : "",
  868. sta->tx_rate, sta->tx_count[0], sta->tx_count[1],
  869. sta->tx_count[2], sta->tx_count[3], sta->rx_count[0],
  870. sta->rx_count[1], sta->rx_count[2], sta->rx_count[3]);
  871. if (sta->crypt && sta->crypt->ops && sta->crypt->ops->print_stats)
  872. p = sta->crypt->ops->print_stats(p, sta->crypt->priv);
  873. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  874. if (sta->ap) {
  875. if (sta->u.ap.channel >= 0)
  876. p += sprintf(p, "channel=%d\n", sta->u.ap.channel);
  877. p += sprintf(p, "ssid=");
  878. for (i = 0; i < sta->u.ap.ssid_len; i++)
  879. p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
  880. sta->u.ap.ssid[i] < 127) ?
  881. "%c" : "<%02x>"),
  882. sta->u.ap.ssid[i]);
  883. p += sprintf(p, "\n");
  884. }
  885. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  886. return (p - page);
  887. }
  888. static void handle_add_proc_queue(struct work_struct *work)
  889. {
  890. struct ap_data *ap = container_of(work, struct ap_data,
  891. add_sta_proc_queue);
  892. struct sta_info *sta;
  893. char name[20];
  894. struct add_sta_proc_data *entry, *prev;
  895. DECLARE_MAC_BUF(mac);
  896. entry = ap->add_sta_proc_entries;
  897. ap->add_sta_proc_entries = NULL;
  898. while (entry) {
  899. spin_lock_bh(&ap->sta_table_lock);
  900. sta = ap_get_sta(ap, entry->addr);
  901. if (sta)
  902. atomic_inc(&sta->users);
  903. spin_unlock_bh(&ap->sta_table_lock);
  904. if (sta) {
  905. sprintf(name, "%s", print_mac(mac, sta->addr));
  906. sta->proc = create_proc_read_entry(
  907. name, 0, ap->proc,
  908. prism2_sta_proc_read, sta);
  909. atomic_dec(&sta->users);
  910. }
  911. prev = entry;
  912. entry = entry->next;
  913. kfree(prev);
  914. }
  915. }
  916. static struct sta_info * ap_add_sta(struct ap_data *ap, u8 *addr)
  917. {
  918. struct sta_info *sta;
  919. sta = kzalloc(sizeof(struct sta_info), GFP_ATOMIC);
  920. if (sta == NULL) {
  921. PDEBUG(DEBUG_AP, "AP: kmalloc failed\n");
  922. return NULL;
  923. }
  924. /* initialize STA info data */
  925. sta->local = ap->local;
  926. skb_queue_head_init(&sta->tx_buf);
  927. memcpy(sta->addr, addr, ETH_ALEN);
  928. atomic_inc(&sta->users);
  929. spin_lock_bh(&ap->sta_table_lock);
  930. list_add(&sta->list, &ap->sta_list);
  931. ap->num_sta++;
  932. ap_sta_hash_add(ap, sta);
  933. spin_unlock_bh(&ap->sta_table_lock);
  934. if (ap->proc) {
  935. struct add_sta_proc_data *entry;
  936. /* schedule a non-interrupt context process to add a procfs
  937. * entry for the STA since procfs code use GFP_KERNEL */
  938. entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
  939. if (entry) {
  940. memcpy(entry->addr, sta->addr, ETH_ALEN);
  941. entry->next = ap->add_sta_proc_entries;
  942. ap->add_sta_proc_entries = entry;
  943. schedule_work(&ap->add_sta_proc_queue);
  944. } else
  945. printk(KERN_DEBUG "Failed to add STA proc data\n");
  946. }
  947. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  948. init_timer(&sta->timer);
  949. sta->timer.expires = jiffies + ap->max_inactivity;
  950. sta->timer.data = (unsigned long) sta;
  951. sta->timer.function = ap_handle_timer;
  952. if (!ap->local->hostapd)
  953. add_timer(&sta->timer);
  954. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  955. return sta;
  956. }
  957. static int ap_tx_rate_ok(int rateidx, struct sta_info *sta,
  958. local_info_t *local)
  959. {
  960. if (rateidx > sta->tx_max_rate ||
  961. !(sta->tx_supp_rates & (1 << rateidx)))
  962. return 0;
  963. if (local->tx_rate_control != 0 &&
  964. !(local->tx_rate_control & (1 << rateidx)))
  965. return 0;
  966. return 1;
  967. }
  968. static void prism2_check_tx_rates(struct sta_info *sta)
  969. {
  970. int i;
  971. sta->tx_supp_rates = 0;
  972. for (i = 0; i < sizeof(sta->supported_rates); i++) {
  973. if ((sta->supported_rates[i] & 0x7f) == 2)
  974. sta->tx_supp_rates |= WLAN_RATE_1M;
  975. if ((sta->supported_rates[i] & 0x7f) == 4)
  976. sta->tx_supp_rates |= WLAN_RATE_2M;
  977. if ((sta->supported_rates[i] & 0x7f) == 11)
  978. sta->tx_supp_rates |= WLAN_RATE_5M5;
  979. if ((sta->supported_rates[i] & 0x7f) == 22)
  980. sta->tx_supp_rates |= WLAN_RATE_11M;
  981. }
  982. sta->tx_max_rate = sta->tx_rate = sta->tx_rate_idx = 0;
  983. if (sta->tx_supp_rates & WLAN_RATE_1M) {
  984. sta->tx_max_rate = 0;
  985. if (ap_tx_rate_ok(0, sta, sta->local)) {
  986. sta->tx_rate = 10;
  987. sta->tx_rate_idx = 0;
  988. }
  989. }
  990. if (sta->tx_supp_rates & WLAN_RATE_2M) {
  991. sta->tx_max_rate = 1;
  992. if (ap_tx_rate_ok(1, sta, sta->local)) {
  993. sta->tx_rate = 20;
  994. sta->tx_rate_idx = 1;
  995. }
  996. }
  997. if (sta->tx_supp_rates & WLAN_RATE_5M5) {
  998. sta->tx_max_rate = 2;
  999. if (ap_tx_rate_ok(2, sta, sta->local)) {
  1000. sta->tx_rate = 55;
  1001. sta->tx_rate_idx = 2;
  1002. }
  1003. }
  1004. if (sta->tx_supp_rates & WLAN_RATE_11M) {
  1005. sta->tx_max_rate = 3;
  1006. if (ap_tx_rate_ok(3, sta, sta->local)) {
  1007. sta->tx_rate = 110;
  1008. sta->tx_rate_idx = 3;
  1009. }
  1010. }
  1011. }
  1012. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  1013. static void ap_crypt_init(struct ap_data *ap)
  1014. {
  1015. ap->crypt = ieee80211_get_crypto_ops("WEP");
  1016. if (ap->crypt) {
  1017. if (ap->crypt->init) {
  1018. ap->crypt_priv = ap->crypt->init(0);
  1019. if (ap->crypt_priv == NULL)
  1020. ap->crypt = NULL;
  1021. else {
  1022. u8 key[WEP_KEY_LEN];
  1023. get_random_bytes(key, WEP_KEY_LEN);
  1024. ap->crypt->set_key(key, WEP_KEY_LEN, NULL,
  1025. ap->crypt_priv);
  1026. }
  1027. }
  1028. }
  1029. if (ap->crypt == NULL) {
  1030. printk(KERN_WARNING "AP could not initialize WEP: load module "
  1031. "ieee80211_crypt_wep.ko\n");
  1032. }
  1033. }
  1034. /* Generate challenge data for shared key authentication. IEEE 802.11 specifies
  1035. * that WEP algorithm is used for generating challange. This should be unique,
  1036. * but otherwise there is not really need for randomness etc. Initialize WEP
  1037. * with pseudo random key and then use increasing IV to get unique challenge
  1038. * streams.
  1039. *
  1040. * Called only as a scheduled task for pending AP frames.
  1041. */
  1042. static char * ap_auth_make_challenge(struct ap_data *ap)
  1043. {
  1044. char *tmpbuf;
  1045. struct sk_buff *skb;
  1046. if (ap->crypt == NULL) {
  1047. ap_crypt_init(ap);
  1048. if (ap->crypt == NULL)
  1049. return NULL;
  1050. }
  1051. tmpbuf = kmalloc(WLAN_AUTH_CHALLENGE_LEN, GFP_ATOMIC);
  1052. if (tmpbuf == NULL) {
  1053. PDEBUG(DEBUG_AP, "AP: kmalloc failed for challenge\n");
  1054. return NULL;
  1055. }
  1056. skb = dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN +
  1057. ap->crypt->extra_mpdu_prefix_len +
  1058. ap->crypt->extra_mpdu_postfix_len);
  1059. if (skb == NULL) {
  1060. kfree(tmpbuf);
  1061. return NULL;
  1062. }
  1063. skb_reserve(skb, ap->crypt->extra_mpdu_prefix_len);
  1064. memset(skb_put(skb, WLAN_AUTH_CHALLENGE_LEN), 0,
  1065. WLAN_AUTH_CHALLENGE_LEN);
  1066. if (ap->crypt->encrypt_mpdu(skb, 0, ap->crypt_priv)) {
  1067. dev_kfree_skb(skb);
  1068. kfree(tmpbuf);
  1069. return NULL;
  1070. }
  1071. skb_copy_from_linear_data_offset(skb, ap->crypt->extra_mpdu_prefix_len,
  1072. tmpbuf, WLAN_AUTH_CHALLENGE_LEN);
  1073. dev_kfree_skb(skb);
  1074. return tmpbuf;
  1075. }
  1076. /* Called only as a scheduled task for pending AP frames. */
  1077. static void handle_authen(local_info_t *local, struct sk_buff *skb,
  1078. struct hostap_80211_rx_status *rx_stats)
  1079. {
  1080. struct net_device *dev = local->dev;
  1081. struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
  1082. size_t hdrlen;
  1083. struct ap_data *ap = local->ap;
  1084. char body[8 + WLAN_AUTH_CHALLENGE_LEN], *challenge = NULL;
  1085. int len, olen;
  1086. u16 auth_alg, auth_transaction, status_code;
  1087. __le16 *pos;
  1088. u16 resp = WLAN_STATUS_SUCCESS, fc;
  1089. struct sta_info *sta = NULL;
  1090. struct ieee80211_crypt_data *crypt;
  1091. char *txt = "";
  1092. len = skb->len - IEEE80211_MGMT_HDR_LEN;
  1093. fc = le16_to_cpu(hdr->frame_ctl);
  1094. hdrlen = hostap_80211_get_hdrlen(fc);
  1095. if (len < 6) {
  1096. PDEBUG(DEBUG_AP, "%s: handle_authen - too short payload "
  1097. "(len=%d) from " MAC_FMT "\n", dev->name, len,
  1098. hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
  1099. hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
  1100. return;
  1101. }
  1102. spin_lock_bh(&local->ap->sta_table_lock);
  1103. sta = ap_get_sta(local->ap, hdr->addr2);
  1104. if (sta)
  1105. atomic_inc(&sta->users);
  1106. spin_unlock_bh(&local->ap->sta_table_lock);
  1107. if (sta && sta->crypt)
  1108. crypt = sta->crypt;
  1109. else {
  1110. int idx = 0;
  1111. if (skb->len >= hdrlen + 3)
  1112. idx = skb->data[hdrlen + 3] >> 6;
  1113. crypt = local->crypt[idx];
  1114. }
  1115. pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
  1116. auth_alg = __le16_to_cpu(*pos);
  1117. pos++;
  1118. auth_transaction = __le16_to_cpu(*pos);
  1119. pos++;
  1120. status_code = __le16_to_cpu(*pos);
  1121. pos++;
  1122. if (memcmp(dev->dev_addr, hdr->addr2, ETH_ALEN) == 0 ||
  1123. ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) {
  1124. txt = "authentication denied";
  1125. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1126. goto fail;
  1127. }
  1128. if (((local->auth_algs & PRISM2_AUTH_OPEN) &&
  1129. auth_alg == WLAN_AUTH_OPEN) ||
  1130. ((local->auth_algs & PRISM2_AUTH_SHARED_KEY) &&
  1131. crypt && auth_alg == WLAN_AUTH_SHARED_KEY)) {
  1132. } else {
  1133. txt = "unsupported algorithm";
  1134. resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  1135. goto fail;
  1136. }
  1137. if (len >= 8) {
  1138. u8 *u = (u8 *) pos;
  1139. if (*u == WLAN_EID_CHALLENGE) {
  1140. if (*(u + 1) != WLAN_AUTH_CHALLENGE_LEN) {
  1141. txt = "invalid challenge len";
  1142. resp = WLAN_STATUS_CHALLENGE_FAIL;
  1143. goto fail;
  1144. }
  1145. if (len - 8 < WLAN_AUTH_CHALLENGE_LEN) {
  1146. txt = "challenge underflow";
  1147. resp = WLAN_STATUS_CHALLENGE_FAIL;
  1148. goto fail;
  1149. }
  1150. challenge = (char *) (u + 2);
  1151. }
  1152. }
  1153. if (sta && sta->ap) {
  1154. if (time_after(jiffies, sta->u.ap.last_beacon +
  1155. (10 * sta->listen_interval * HZ) / 1024)) {
  1156. PDEBUG(DEBUG_AP, "%s: no beacons received for a while,"
  1157. " assuming AP " MAC_FMT " is now STA\n",
  1158. dev->name,
  1159. sta->addr[0], sta->addr[1], sta->addr[2],
  1160. sta->addr[3], sta->addr[4], sta->addr[5]);
  1161. sta->ap = 0;
  1162. sta->flags = 0;
  1163. sta->u.sta.challenge = NULL;
  1164. } else {
  1165. txt = "AP trying to authenticate?";
  1166. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1167. goto fail;
  1168. }
  1169. }
  1170. if ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) ||
  1171. (auth_alg == WLAN_AUTH_SHARED_KEY &&
  1172. (auth_transaction == 1 ||
  1173. (auth_transaction == 3 && sta != NULL &&
  1174. sta->u.sta.challenge != NULL)))) {
  1175. } else {
  1176. txt = "unknown authentication transaction number";
  1177. resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
  1178. goto fail;
  1179. }
  1180. if (sta == NULL) {
  1181. txt = "new STA";
  1182. if (local->ap->num_sta >= MAX_STA_COUNT) {
  1183. /* FIX: might try to remove some old STAs first? */
  1184. txt = "no more room for new STAs";
  1185. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1186. goto fail;
  1187. }
  1188. sta = ap_add_sta(local->ap, hdr->addr2);
  1189. if (sta == NULL) {
  1190. txt = "ap_add_sta failed";
  1191. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1192. goto fail;
  1193. }
  1194. }
  1195. switch (auth_alg) {
  1196. case WLAN_AUTH_OPEN:
  1197. txt = "authOK";
  1198. /* IEEE 802.11 standard is not completely clear about
  1199. * whether STA is considered authenticated after
  1200. * authentication OK frame has been send or after it
  1201. * has been ACKed. In order to reduce interoperability
  1202. * issues, mark the STA authenticated before ACK. */
  1203. sta->flags |= WLAN_STA_AUTH;
  1204. break;
  1205. case WLAN_AUTH_SHARED_KEY:
  1206. if (auth_transaction == 1) {
  1207. if (sta->u.sta.challenge == NULL) {
  1208. sta->u.sta.challenge =
  1209. ap_auth_make_challenge(local->ap);
  1210. if (sta->u.sta.challenge == NULL) {
  1211. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1212. goto fail;
  1213. }
  1214. }
  1215. } else {
  1216. if (sta->u.sta.challenge == NULL ||
  1217. challenge == NULL ||
  1218. memcmp(sta->u.sta.challenge, challenge,
  1219. WLAN_AUTH_CHALLENGE_LEN) != 0 ||
  1220. !(fc & IEEE80211_FCTL_PROTECTED)) {
  1221. txt = "challenge response incorrect";
  1222. resp = WLAN_STATUS_CHALLENGE_FAIL;
  1223. goto fail;
  1224. }
  1225. txt = "challenge OK - authOK";
  1226. /* IEEE 802.11 standard is not completely clear about
  1227. * whether STA is considered authenticated after
  1228. * authentication OK frame has been send or after it
  1229. * has been ACKed. In order to reduce interoperability
  1230. * issues, mark the STA authenticated before ACK. */
  1231. sta->flags |= WLAN_STA_AUTH;
  1232. kfree(sta->u.sta.challenge);
  1233. sta->u.sta.challenge = NULL;
  1234. }
  1235. break;
  1236. }
  1237. fail:
  1238. pos = (__le16 *) body;
  1239. *pos = cpu_to_le16(auth_alg);
  1240. pos++;
  1241. *pos = cpu_to_le16(auth_transaction + 1);
  1242. pos++;
  1243. *pos = cpu_to_le16(resp); /* status_code */
  1244. pos++;
  1245. olen = 6;
  1246. if (resp == WLAN_STATUS_SUCCESS && sta != NULL &&
  1247. sta->u.sta.challenge != NULL &&
  1248. auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 1) {
  1249. u8 *tmp = (u8 *) pos;
  1250. *tmp++ = WLAN_EID_CHALLENGE;
  1251. *tmp++ = WLAN_AUTH_CHALLENGE_LEN;
  1252. pos++;
  1253. memcpy(pos, sta->u.sta.challenge, WLAN_AUTH_CHALLENGE_LEN);
  1254. olen += 2 + WLAN_AUTH_CHALLENGE_LEN;
  1255. }
  1256. prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH,
  1257. body, olen, hdr->addr2, ap->tx_callback_auth);
  1258. if (sta) {
  1259. sta->last_rx = jiffies;
  1260. atomic_dec(&sta->users);
  1261. }
  1262. if (resp) {
  1263. PDEBUG(DEBUG_AP, "%s: " MAC_FMT " auth (alg=%d "
  1264. "trans#=%d stat=%d len=%d fc=%04x) ==> %d (%s)\n",
  1265. dev->name,
  1266. hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
  1267. hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
  1268. auth_alg, auth_transaction, status_code, len,
  1269. fc, resp, txt);
  1270. }
  1271. }
  1272. /* Called only as a scheduled task for pending AP frames. */
  1273. static void handle_assoc(local_info_t *local, struct sk_buff *skb,
  1274. struct hostap_80211_rx_status *rx_stats, int reassoc)
  1275. {
  1276. struct net_device *dev = local->dev;
  1277. struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
  1278. char body[12], *p, *lpos;
  1279. int len, left;
  1280. __le16 *pos;
  1281. u16 resp = WLAN_STATUS_SUCCESS;
  1282. struct sta_info *sta = NULL;
  1283. int send_deauth = 0;
  1284. char *txt = "";
  1285. u8 prev_ap[ETH_ALEN];
  1286. left = len = skb->len - IEEE80211_MGMT_HDR_LEN;
  1287. if (len < (reassoc ? 10 : 4)) {
  1288. PDEBUG(DEBUG_AP, "%s: handle_assoc - too short payload "
  1289. "(len=%d, reassoc=%d) from " MAC_FMT "\n",
  1290. dev->name, len, reassoc,
  1291. hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
  1292. hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
  1293. return;
  1294. }
  1295. spin_lock_bh(&local->ap->sta_table_lock);
  1296. sta = ap_get_sta(local->ap, hdr->addr2);
  1297. if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
  1298. spin_unlock_bh(&local->ap->sta_table_lock);
  1299. txt = "trying to associate before authentication";
  1300. send_deauth = 1;
  1301. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1302. sta = NULL; /* do not decrement sta->users */
  1303. goto fail;
  1304. }
  1305. atomic_inc(&sta->users);
  1306. spin_unlock_bh(&local->ap->sta_table_lock);
  1307. pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
  1308. sta->capability = __le16_to_cpu(*pos);
  1309. pos++; left -= 2;
  1310. sta->listen_interval = __le16_to_cpu(*pos);
  1311. pos++; left -= 2;
  1312. if (reassoc) {
  1313. memcpy(prev_ap, pos, ETH_ALEN);
  1314. pos++; pos++; pos++; left -= 6;
  1315. } else
  1316. memset(prev_ap, 0, ETH_ALEN);
  1317. if (left >= 2) {
  1318. unsigned int ileft;
  1319. unsigned char *u = (unsigned char *) pos;
  1320. if (*u == WLAN_EID_SSID) {
  1321. u++; left--;
  1322. ileft = *u;
  1323. u++; left--;
  1324. if (ileft > left || ileft > MAX_SSID_LEN) {
  1325. txt = "SSID overflow";
  1326. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1327. goto fail;
  1328. }
  1329. if (ileft != strlen(local->essid) ||
  1330. memcmp(local->essid, u, ileft) != 0) {
  1331. txt = "not our SSID";
  1332. resp = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
  1333. goto fail;
  1334. }
  1335. u += ileft;
  1336. left -= ileft;
  1337. }
  1338. if (left >= 2 && *u == WLAN_EID_SUPP_RATES) {
  1339. u++; left--;
  1340. ileft = *u;
  1341. u++; left--;
  1342. if (ileft > left || ileft == 0 ||
  1343. ileft > WLAN_SUPP_RATES_MAX) {
  1344. txt = "SUPP_RATES len error";
  1345. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1346. goto fail;
  1347. }
  1348. memset(sta->supported_rates, 0,
  1349. sizeof(sta->supported_rates));
  1350. memcpy(sta->supported_rates, u, ileft);
  1351. prism2_check_tx_rates(sta);
  1352. u += ileft;
  1353. left -= ileft;
  1354. }
  1355. if (left > 0) {
  1356. PDEBUG(DEBUG_AP, "%s: assoc from " MAC_FMT
  1357. " with extra data (%d bytes) [",
  1358. dev->name,
  1359. hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
  1360. hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
  1361. left);
  1362. while (left > 0) {
  1363. PDEBUG2(DEBUG_AP, "<%02x>", *u);
  1364. u++; left--;
  1365. }
  1366. PDEBUG2(DEBUG_AP, "]\n");
  1367. }
  1368. } else {
  1369. txt = "frame underflow";
  1370. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1371. goto fail;
  1372. }
  1373. /* get a unique AID */
  1374. if (sta->aid > 0)
  1375. txt = "OK, old AID";
  1376. else {
  1377. spin_lock_bh(&local->ap->sta_table_lock);
  1378. for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
  1379. if (local->ap->sta_aid[sta->aid - 1] == NULL)
  1380. break;
  1381. if (sta->aid > MAX_AID_TABLE_SIZE) {
  1382. sta->aid = 0;
  1383. spin_unlock_bh(&local->ap->sta_table_lock);
  1384. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  1385. txt = "no room for more AIDs";
  1386. } else {
  1387. local->ap->sta_aid[sta->aid - 1] = sta;
  1388. spin_unlock_bh(&local->ap->sta_table_lock);
  1389. txt = "OK, new AID";
  1390. }
  1391. }
  1392. fail:
  1393. pos = (__le16 *) body;
  1394. if (send_deauth) {
  1395. *pos = cpu_to_le16(WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH);
  1396. pos++;
  1397. } else {
  1398. /* FIX: CF-Pollable and CF-PollReq should be set to match the
  1399. * values in beacons/probe responses */
  1400. /* FIX: how about privacy and WEP? */
  1401. /* capability */
  1402. *pos = cpu_to_le16(WLAN_CAPABILITY_ESS);
  1403. pos++;
  1404. /* status_code */
  1405. *pos = cpu_to_le16(resp);
  1406. pos++;
  1407. *pos = cpu_to_le16((sta && sta->aid > 0 ? sta->aid : 0) |
  1408. BIT(14) | BIT(15)); /* AID */
  1409. pos++;
  1410. /* Supported rates (Information element) */
  1411. p = (char *) pos;
  1412. *p++ = WLAN_EID_SUPP_RATES;
  1413. lpos = p;
  1414. *p++ = 0; /* len */
  1415. if (local->tx_rate_control & WLAN_RATE_1M) {
  1416. *p++ = local->basic_rates & WLAN_RATE_1M ? 0x82 : 0x02;
  1417. (*lpos)++;
  1418. }
  1419. if (local->tx_rate_control & WLAN_RATE_2M) {
  1420. *p++ = local->basic_rates & WLAN_RATE_2M ? 0x84 : 0x04;
  1421. (*lpos)++;
  1422. }
  1423. if (local->tx_rate_control & WLAN_RATE_5M5) {
  1424. *p++ = local->basic_rates & WLAN_RATE_5M5 ?
  1425. 0x8b : 0x0b;
  1426. (*lpos)++;
  1427. }
  1428. if (local->tx_rate_control & WLAN_RATE_11M) {
  1429. *p++ = local->basic_rates & WLAN_RATE_11M ?
  1430. 0x96 : 0x16;
  1431. (*lpos)++;
  1432. }
  1433. pos = (__le16 *) p;
  1434. }
  1435. prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
  1436. (send_deauth ? IEEE80211_STYPE_DEAUTH :
  1437. (reassoc ? IEEE80211_STYPE_REASSOC_RESP :
  1438. IEEE80211_STYPE_ASSOC_RESP)),
  1439. body, (u8 *) pos - (u8 *) body,
  1440. hdr->addr2,
  1441. send_deauth ? 0 : local->ap->tx_callback_assoc);
  1442. if (sta) {
  1443. if (resp == WLAN_STATUS_SUCCESS) {
  1444. sta->last_rx = jiffies;
  1445. /* STA will be marked associated from TX callback, if
  1446. * AssocResp is ACKed */
  1447. }
  1448. atomic_dec(&sta->users);
  1449. }
  1450. #if 0
  1451. PDEBUG(DEBUG_AP, "%s: " MAC_FMT" %sassoc (len=%d "
  1452. "prev_ap=" MAC_FMT") => %d(%d) (%s)\n",
  1453. dev->name,
  1454. hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
  1455. hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
  1456. reassoc ? "re" : "", len,
  1457. prev_ap[0], prev_ap[1], prev_ap[2],
  1458. prev_ap[3], prev_ap[4], prev_ap[5],
  1459. resp, send_deauth, txt);
  1460. #endif
  1461. }
  1462. /* Called only as a scheduled task for pending AP frames. */
  1463. static void handle_deauth(local_info_t *local, struct sk_buff *skb,
  1464. struct hostap_80211_rx_status *rx_stats)
  1465. {
  1466. struct net_device *dev = local->dev;
  1467. struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
  1468. char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN);
  1469. int len;
  1470. u16 reason_code;
  1471. __le16 *pos;
  1472. struct sta_info *sta = NULL;
  1473. DECLARE_MAC_BUF(mac);
  1474. len = skb->len - IEEE80211_MGMT_HDR_LEN;
  1475. if (len < 2) {
  1476. printk("handle_deauth - too short payload (len=%d)\n", len);
  1477. return;
  1478. }
  1479. pos = (__le16 *) body;
  1480. reason_code = le16_to_cpu(*pos);
  1481. PDEBUG(DEBUG_AP, "%s: deauthentication: " MAC_FMT " len=%d, "
  1482. "reason_code=%d\n", dev->name,
  1483. hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
  1484. hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
  1485. len, reason_code);
  1486. spin_lock_bh(&local->ap->sta_table_lock);
  1487. sta = ap_get_sta(local->ap, hdr->addr2);
  1488. if (sta != NULL) {
  1489. if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
  1490. hostap_event_expired_sta(local->dev, sta);
  1491. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
  1492. }
  1493. spin_unlock_bh(&local->ap->sta_table_lock);
  1494. if (sta == NULL) {
  1495. printk("%s: deauthentication from " MAC_FMT ", "
  1496. "reason_code=%d, but STA not authenticated\n", dev->name,
  1497. hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
  1498. hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
  1499. reason_code);
  1500. }
  1501. }
  1502. /* Called only as a scheduled task for pending AP frames. */
  1503. static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
  1504. struct hostap_80211_rx_status *rx_stats)
  1505. {
  1506. struct net_device *dev = local->dev;
  1507. struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
  1508. char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
  1509. int len;
  1510. u16 reason_code;
  1511. __le16 *pos;
  1512. struct sta_info *sta = NULL;
  1513. len = skb->len - IEEE80211_MGMT_HDR_LEN;
  1514. if (len < 2) {
  1515. printk("handle_disassoc - too short payload (len=%d)\n", len);
  1516. return;
  1517. }
  1518. pos = (__le16 *) body;
  1519. reason_code = le16_to_cpu(*pos);
  1520. PDEBUG(DEBUG_AP, "%s: disassociation: " MAC_FMT " len=%d, "
  1521. "reason_code=%d\n", dev->name,
  1522. hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
  1523. hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
  1524. len, reason_code);
  1525. spin_lock_bh(&local->ap->sta_table_lock);
  1526. sta = ap_get_sta(local->ap, hdr->addr2);
  1527. if (sta != NULL) {
  1528. if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
  1529. hostap_event_expired_sta(local->dev, sta);
  1530. sta->flags &= ~WLAN_STA_ASSOC;
  1531. }
  1532. spin_unlock_bh(&local->ap->sta_table_lock);
  1533. if (sta == NULL) {
  1534. printk("%s: disassociation from " MAC_FMT ", "
  1535. "reason_code=%d, but STA not authenticated\n",
  1536. dev->name,
  1537. hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
  1538. hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
  1539. reason_code);
  1540. }
  1541. }
  1542. /* Called only as a scheduled task for pending AP frames. */
  1543. static void ap_handle_data_nullfunc(local_info_t *local,
  1544. struct ieee80211_hdr_4addr *hdr)
  1545. {
  1546. struct net_device *dev = local->dev;
  1547. /* some STA f/w's seem to require control::ACK frame for
  1548. * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
  1549. * not send this..
  1550. * send control::ACK for the data::nullfunc */
  1551. printk(KERN_DEBUG "Sending control::ACK for data::nullfunc\n");
  1552. prism2_send_mgmt(dev, IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK,
  1553. NULL, 0, hdr->addr2, 0);
  1554. }
  1555. /* Called only as a scheduled task for pending AP frames. */
  1556. static void ap_handle_dropped_data(local_info_t *local,
  1557. struct ieee80211_hdr_4addr *hdr)
  1558. {
  1559. struct net_device *dev = local->dev;
  1560. struct sta_info *sta;
  1561. __le16 reason;
  1562. spin_lock_bh(&local->ap->sta_table_lock);
  1563. sta = ap_get_sta(local->ap, hdr->addr2);
  1564. if (sta)
  1565. atomic_inc(&sta->users);
  1566. spin_unlock_bh(&local->ap->sta_table_lock);
  1567. if (sta != NULL && (sta->flags & WLAN_STA_ASSOC)) {
  1568. PDEBUG(DEBUG_AP, "ap_handle_dropped_data: STA is now okay?\n");
  1569. atomic_dec(&sta->users);
  1570. return;
  1571. }
  1572. reason = cpu_to_le16(WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1573. prism2_send_mgmt(dev, IEEE80211_FTYPE_MGMT |
  1574. ((sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) ?
  1575. IEEE80211_STYPE_DEAUTH : IEEE80211_STYPE_DISASSOC),
  1576. (char *) &reason, sizeof(reason), hdr->addr2, 0);
  1577. if (sta)
  1578. atomic_dec(&sta->users);
  1579. }
  1580. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  1581. /* Called only as a scheduled task for pending AP frames. */
  1582. static void pspoll_send_buffered(local_info_t *local, struct sta_info *sta,
  1583. struct sk_buff *skb)
  1584. {
  1585. struct hostap_skb_tx_data *meta;
  1586. if (!(sta->flags & WLAN_STA_PS)) {
  1587. /* Station has moved to non-PS mode, so send all buffered
  1588. * frames using normal device queue. */
  1589. dev_queue_xmit(skb);
  1590. return;
  1591. }
  1592. /* add a flag for hostap_handle_sta_tx() to know that this skb should
  1593. * be passed through even though STA is using PS */
  1594. meta = (struct hostap_skb_tx_data *) skb->cb;
  1595. meta->flags |= HOSTAP_TX_FLAGS_BUFFERED_FRAME;
  1596. if (!skb_queue_empty(&sta->tx_buf)) {
  1597. /* indicate to STA that more frames follow */
  1598. meta->flags |= HOSTAP_TX_FLAGS_ADD_MOREDATA;
  1599. }
  1600. dev_queue_xmit(skb);
  1601. }
  1602. /* Called only as a scheduled task for pending AP frames. */
  1603. static void handle_pspoll(local_info_t *local,
  1604. struct ieee80211_hdr_4addr *hdr,
  1605. struct hostap_80211_rx_status *rx_stats)
  1606. {
  1607. struct net_device *dev = local->dev;
  1608. struct sta_info *sta;
  1609. u16 aid;
  1610. struct sk_buff *skb;
  1611. PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=" MAC_FMT
  1612. ", TA=" MAC_FMT " PWRMGT=%d\n",
  1613. hdr->addr1[0], hdr->addr1[1], hdr->addr1[2],
  1614. hdr->addr1[3], hdr->addr1[4], hdr->addr1[5],
  1615. hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
  1616. hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
  1617. !!(le16_to_cpu(hdr->frame_ctl) & IEEE80211_FCTL_PM));
  1618. if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
  1619. PDEBUG(DEBUG_AP, "handle_pspoll - addr1(BSSID)=" MAC_FMT
  1620. " not own MAC\n",
  1621. hdr->addr1[0], hdr->addr1[1], hdr->addr1[2],
  1622. hdr->addr1[3], hdr->addr1[4], hdr->addr1[5]);
  1623. return;
  1624. }
  1625. aid = le16_to_cpu(hdr->duration_id);
  1626. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
  1627. PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n");
  1628. return;
  1629. }
  1630. aid &= ~BIT(15) & ~BIT(14);
  1631. if (aid == 0 || aid > MAX_AID_TABLE_SIZE) {
  1632. PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid);
  1633. return;
  1634. }
  1635. PDEBUG(DEBUG_PS2, " aid=%d\n", aid);
  1636. spin_lock_bh(&local->ap->sta_table_lock);
  1637. sta = ap_get_sta(local->ap, hdr->addr2);
  1638. if (sta)
  1639. atomic_inc(&sta->users);
  1640. spin_unlock_bh(&local->ap->sta_table_lock);
  1641. if (sta == NULL) {
  1642. PDEBUG(DEBUG_PS, " STA not found\n");
  1643. return;
  1644. }
  1645. if (sta->aid != aid) {
  1646. PDEBUG(DEBUG_PS, " received aid=%i does not match with "
  1647. "assoc.aid=%d\n", aid, sta->aid);
  1648. return;
  1649. }
  1650. /* FIX: todo:
  1651. * - add timeout for buffering (clear aid in TIM vector if buffer timed
  1652. * out (expiry time must be longer than ListenInterval for
  1653. * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
  1654. * - what to do, if buffered, pspolled, and sent frame is not ACKed by
  1655. * sta; store buffer for later use and leave TIM aid bit set? use
  1656. * TX event to check whether frame was ACKed?
  1657. */
  1658. while ((skb = skb_dequeue(&sta->tx_buf)) != NULL) {
  1659. /* send buffered frame .. */
  1660. PDEBUG(DEBUG_PS2, "Sending buffered frame to STA after PS POLL"
  1661. " (buffer_count=%d)\n", skb_queue_len(&sta->tx_buf));
  1662. pspoll_send_buffered(local, sta, skb);
  1663. if (sta->flags & WLAN_STA_PS) {
  1664. /* send only one buffered packet per PS Poll */
  1665. /* FIX: should ignore further PS Polls until the
  1666. * buffered packet that was just sent is acknowledged
  1667. * (Tx or TxExc event) */
  1668. break;
  1669. }
  1670. }
  1671. if (skb_queue_empty(&sta->tx_buf)) {
  1672. /* try to clear aid from TIM */
  1673. if (!(sta->flags & WLAN_STA_TIM))
  1674. PDEBUG(DEBUG_PS2, "Re-unsetting TIM for aid %d\n",
  1675. aid);
  1676. hostap_set_tim(local, aid, 0);
  1677. sta->flags &= ~WLAN_STA_TIM;
  1678. }
  1679. atomic_dec(&sta->users);
  1680. }
  1681. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  1682. static void handle_wds_oper_queue(struct work_struct *work)
  1683. {
  1684. struct ap_data *ap = container_of(work, struct ap_data,
  1685. wds_oper_queue);
  1686. local_info_t *local = ap->local;
  1687. struct wds_oper_data *entry, *prev;
  1688. spin_lock_bh(&local->lock);
  1689. entry = local->ap->wds_oper_entries;
  1690. local->ap->wds_oper_entries = NULL;
  1691. spin_unlock_bh(&local->lock);
  1692. while (entry) {
  1693. PDEBUG(DEBUG_AP, "%s: %s automatic WDS connection "
  1694. "to AP " MAC_FMT "\n",
  1695. local->dev->name,
  1696. entry->type == WDS_ADD ? "adding" : "removing",
  1697. entry->addr[0], entry->addr[1], entry->addr[2],
  1698. entry->addr[3], entry->addr[4], entry->addr[5]);
  1699. if (entry->type == WDS_ADD)
  1700. prism2_wds_add(local, entry->addr, 0);
  1701. else if (entry->type == WDS_DEL)
  1702. prism2_wds_del(local, entry->addr, 0, 1);
  1703. prev = entry;
  1704. entry = entry->next;
  1705. kfree(prev);
  1706. }
  1707. }
  1708. /* Called only as a scheduled task for pending AP frames. */
  1709. static void handle_beacon(local_info_t *local, struct sk_buff *skb,
  1710. struct hostap_80211_rx_status *rx_stats)
  1711. {
  1712. struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
  1713. char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
  1714. int len, left;
  1715. u16 beacon_int, capability;
  1716. __le16 *pos;
  1717. char *ssid = NULL;
  1718. unsigned char *supp_rates = NULL;
  1719. int ssid_len = 0, supp_rates_len = 0;
  1720. struct sta_info *sta = NULL;
  1721. int new_sta = 0, channel = -1;
  1722. len = skb->len - IEEE80211_MGMT_HDR_LEN;
  1723. if (len < 8 + 2 + 2) {
  1724. printk(KERN_DEBUG "handle_beacon - too short payload "
  1725. "(len=%d)\n", len);
  1726. return;
  1727. }
  1728. pos = (__le16 *) body;
  1729. left = len;
  1730. /* Timestamp (8 octets) */
  1731. pos += 4; left -= 8;
  1732. /* Beacon interval (2 octets) */
  1733. beacon_int = le16_to_cpu(*pos);
  1734. pos++; left -= 2;
  1735. /* Capability information (2 octets) */
  1736. capability = le16_to_cpu(*pos);
  1737. pos++; left -= 2;
  1738. if (local->ap->ap_policy != AP_OTHER_AP_EVEN_IBSS &&
  1739. capability & WLAN_CAPABILITY_IBSS)
  1740. return;
  1741. if (left >= 2) {
  1742. unsigned int ileft;
  1743. unsigned char *u = (unsigned char *) pos;
  1744. if (*u == WLAN_EID_SSID) {
  1745. u++; left--;
  1746. ileft = *u;
  1747. u++; left--;
  1748. if (ileft > left || ileft > MAX_SSID_LEN) {
  1749. PDEBUG(DEBUG_AP, "SSID: overflow\n");
  1750. return;
  1751. }
  1752. if (local->ap->ap_policy == AP_OTHER_AP_SAME_SSID &&
  1753. (ileft != strlen(local->essid) ||
  1754. memcmp(local->essid, u, ileft) != 0)) {
  1755. /* not our SSID */
  1756. return;
  1757. }
  1758. ssid = u;
  1759. ssid_len = ileft;
  1760. u += ileft;
  1761. left -= ileft;
  1762. }
  1763. if (*u == WLAN_EID_SUPP_RATES) {
  1764. u++; left--;
  1765. ileft = *u;
  1766. u++; left--;
  1767. if (ileft > left || ileft == 0 || ileft > 8) {
  1768. PDEBUG(DEBUG_AP, " - SUPP_RATES len error\n");
  1769. return;
  1770. }
  1771. supp_rates = u;
  1772. supp_rates_len = ileft;
  1773. u += ileft;
  1774. left -= ileft;
  1775. }
  1776. if (*u == WLAN_EID_DS_PARAMS) {
  1777. u++; left--;
  1778. ileft = *u;
  1779. u++; left--;
  1780. if (ileft > left || ileft != 1) {
  1781. PDEBUG(DEBUG_AP, " - DS_PARAMS len error\n");
  1782. return;
  1783. }
  1784. channel = *u;
  1785. u += ileft;
  1786. left -= ileft;
  1787. }
  1788. }
  1789. spin_lock_bh(&local->ap->sta_table_lock);
  1790. sta = ap_get_sta(local->ap, hdr->addr2);
  1791. if (sta != NULL)
  1792. atomic_inc(&sta->users);
  1793. spin_unlock_bh(&local->ap->sta_table_lock);
  1794. if (sta == NULL) {
  1795. /* add new AP */
  1796. new_sta = 1;
  1797. sta = ap_add_sta(local->ap, hdr->addr2);
  1798. if (sta == NULL) {
  1799. printk(KERN_INFO "prism2: kmalloc failed for AP "
  1800. "data structure\n");
  1801. return;
  1802. }
  1803. hostap_event_new_sta(local->dev, sta);
  1804. /* mark APs authentication and associated for pseudo ad-hoc
  1805. * style communication */
  1806. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  1807. if (local->ap->autom_ap_wds) {
  1808. hostap_wds_link_oper(local, sta->addr, WDS_ADD);
  1809. }
  1810. }
  1811. sta->ap = 1;
  1812. if (ssid) {
  1813. sta->u.ap.ssid_len = ssid_len;
  1814. memcpy(sta->u.ap.ssid, ssid, ssid_len);
  1815. sta->u.ap.ssid[ssid_len] = '\0';
  1816. } else {
  1817. sta->u.ap.ssid_len = 0;
  1818. sta->u.ap.ssid[0] = '\0';
  1819. }
  1820. sta->u.ap.channel = channel;
  1821. sta->rx_packets++;
  1822. sta->rx_bytes += len;
  1823. sta->u.ap.last_beacon = sta->last_rx = jiffies;
  1824. sta->capability = capability;
  1825. sta->listen_interval = beacon_int;
  1826. atomic_dec(&sta->users);
  1827. if (new_sta) {
  1828. memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
  1829. memcpy(sta->supported_rates, supp_rates, supp_rates_len);
  1830. prism2_check_tx_rates(sta);
  1831. }
  1832. }
  1833. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  1834. /* Called only as a tasklet. */
  1835. static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
  1836. struct hostap_80211_rx_status *rx_stats)
  1837. {
  1838. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  1839. struct net_device *dev = local->dev;
  1840. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  1841. u16 fc, type, stype;
  1842. struct ieee80211_hdr_4addr *hdr;
  1843. /* FIX: should give skb->len to handler functions and check that the
  1844. * buffer is long enough */
  1845. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  1846. fc = le16_to_cpu(hdr->frame_ctl);
  1847. type = WLAN_FC_GET_TYPE(fc);
  1848. stype = WLAN_FC_GET_STYPE(fc);
  1849. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  1850. if (!local->hostapd && type == IEEE80211_FTYPE_DATA) {
  1851. PDEBUG(DEBUG_AP, "handle_ap_item - data frame\n");
  1852. if (!(fc & IEEE80211_FCTL_TODS) ||
  1853. (fc & IEEE80211_FCTL_FROMDS)) {
  1854. if (stype == IEEE80211_STYPE_NULLFUNC) {
  1855. /* no ToDS nullfunc seems to be used to check
  1856. * AP association; so send reject message to
  1857. * speed up re-association */
  1858. ap_handle_dropped_data(local, hdr);
  1859. goto done;
  1860. }
  1861. PDEBUG(DEBUG_AP, " not ToDS frame (fc=0x%04x)\n",
  1862. fc);
  1863. goto done;
  1864. }
  1865. if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
  1866. PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)="
  1867. MAC_FMT " not own MAC\n",
  1868. hdr->addr1[0], hdr->addr1[1], hdr->addr1[2],
  1869. hdr->addr1[3], hdr->addr1[4], hdr->addr1[5]);
  1870. goto done;
  1871. }
  1872. if (local->ap->nullfunc_ack &&
  1873. stype == IEEE80211_STYPE_NULLFUNC)
  1874. ap_handle_data_nullfunc(local, hdr);
  1875. else
  1876. ap_handle_dropped_data(local, hdr);
  1877. goto done;
  1878. }
  1879. if (type == IEEE80211_FTYPE_MGMT && stype == IEEE80211_STYPE_BEACON) {
  1880. handle_beacon(local, skb, rx_stats);
  1881. goto done;
  1882. }
  1883. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  1884. if (type == IEEE80211_FTYPE_CTL && stype == IEEE80211_STYPE_PSPOLL) {
  1885. handle_pspoll(local, hdr, rx_stats);
  1886. goto done;
  1887. }
  1888. if (local->hostapd) {
  1889. PDEBUG(DEBUG_AP, "Unknown frame in AP queue: type=0x%02x "
  1890. "subtype=0x%02x\n", type, stype);
  1891. goto done;
  1892. }
  1893. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  1894. if (type != IEEE80211_FTYPE_MGMT) {
  1895. PDEBUG(DEBUG_AP, "handle_ap_item - not a management frame?\n");
  1896. goto done;
  1897. }
  1898. if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
  1899. PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=" MAC_FMT
  1900. " not own MAC\n",
  1901. hdr->addr1[0], hdr->addr1[1], hdr->addr1[2],
  1902. hdr->addr1[3], hdr->addr1[4], hdr->addr1[5]);
  1903. goto done;
  1904. }
  1905. if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN)) {
  1906. PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=" MAC_FMT
  1907. " not own MAC\n",
  1908. hdr->addr3[0], hdr->addr3[1], hdr->addr3[2],
  1909. hdr->addr3[3], hdr->addr3[4], hdr->addr3[5]);
  1910. goto done;
  1911. }
  1912. switch (stype) {
  1913. case IEEE80211_STYPE_ASSOC_REQ:
  1914. handle_assoc(local, skb, rx_stats, 0);
  1915. break;
  1916. case IEEE80211_STYPE_ASSOC_RESP:
  1917. PDEBUG(DEBUG_AP, "==> ASSOC RESP (ignored)\n");
  1918. break;
  1919. case IEEE80211_STYPE_REASSOC_REQ:
  1920. handle_assoc(local, skb, rx_stats, 1);
  1921. break;
  1922. case IEEE80211_STYPE_REASSOC_RESP:
  1923. PDEBUG(DEBUG_AP, "==> REASSOC RESP (ignored)\n");
  1924. break;
  1925. case IEEE80211_STYPE_ATIM:
  1926. PDEBUG(DEBUG_AP, "==> ATIM (ignored)\n");
  1927. break;
  1928. case IEEE80211_STYPE_DISASSOC:
  1929. handle_disassoc(local, skb, rx_stats);
  1930. break;
  1931. case IEEE80211_STYPE_AUTH:
  1932. handle_authen(local, skb, rx_stats);
  1933. break;
  1934. case IEEE80211_STYPE_DEAUTH:
  1935. handle_deauth(local, skb, rx_stats);
  1936. break;
  1937. default:
  1938. PDEBUG(DEBUG_AP, "Unknown mgmt frame subtype 0x%02x\n",
  1939. stype >> 4);
  1940. break;
  1941. }
  1942. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  1943. done:
  1944. dev_kfree_skb(skb);
  1945. }
  1946. /* Called only as a tasklet (software IRQ) */
  1947. void hostap_rx(struct net_device *dev, struct sk_buff *skb,
  1948. struct hostap_80211_rx_status *rx_stats)
  1949. {
  1950. struct hostap_interface *iface;
  1951. local_info_t *local;
  1952. u16 fc;
  1953. struct ieee80211_hdr_4addr *hdr;
  1954. iface = netdev_priv(dev);
  1955. local = iface->local;
  1956. if (skb->len < 16)
  1957. goto drop;
  1958. local->stats.rx_packets++;
  1959. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  1960. fc = le16_to_cpu(hdr->frame_ctl);
  1961. if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL &&
  1962. WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_MGMT &&
  1963. WLAN_FC_GET_STYPE(fc) == IEEE80211_STYPE_BEACON)
  1964. goto drop;
  1965. skb->protocol = __constant_htons(ETH_P_HOSTAP);
  1966. handle_ap_item(local, skb, rx_stats);
  1967. return;
  1968. drop:
  1969. dev_kfree_skb(skb);
  1970. }
  1971. /* Called only as a tasklet (software IRQ) */
  1972. static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
  1973. {
  1974. struct sk_buff *skb;
  1975. struct ieee80211_hdr_4addr *hdr;
  1976. struct hostap_80211_rx_status rx_stats;
  1977. if (skb_queue_empty(&sta->tx_buf))
  1978. return;
  1979. skb = dev_alloc_skb(16);
  1980. if (skb == NULL) {
  1981. printk(KERN_DEBUG "%s: schedule_packet_send: skb alloc "
  1982. "failed\n", local->dev->name);
  1983. return;
  1984. }
  1985. hdr = (struct ieee80211_hdr_4addr *) skb_put(skb, 16);
  1986. /* Generate a fake pspoll frame to start packet delivery */
  1987. hdr->frame_ctl = __constant_cpu_to_le16(
  1988. IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
  1989. memcpy(hdr->addr1, local->dev->dev_addr, ETH_ALEN);
  1990. memcpy(hdr->addr2, sta->addr, ETH_ALEN);
  1991. hdr->duration_id = cpu_to_le16(sta->aid | BIT(15) | BIT(14));
  1992. PDEBUG(DEBUG_PS2, "%s: Scheduling buffered packet delivery for STA "
  1993. MAC_FMT "\n", local->dev->name,
  1994. sta->addr[0], sta->addr[1], sta->addr[2],
  1995. sta->addr[3], sta->addr[4], sta->addr[5]);
  1996. skb->dev = local->dev;
  1997. memset(&rx_stats, 0, sizeof(rx_stats));
  1998. hostap_rx(local->dev, skb, &rx_stats);
  1999. }
  2000. int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
  2001. struct iw_quality qual[], int buf_size,
  2002. int aplist)
  2003. {
  2004. struct ap_data *ap = local->ap;
  2005. struct list_head *ptr;
  2006. int count = 0;
  2007. spin_lock_bh(&ap->sta_table_lock);
  2008. for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
  2009. ptr = ptr->next) {
  2010. struct sta_info *sta = (struct sta_info *) ptr;
  2011. if (aplist && !sta->ap)
  2012. continue;
  2013. addr[count].sa_family = ARPHRD_ETHER;
  2014. memcpy(addr[count].sa_data, sta->addr, ETH_ALEN);
  2015. if (sta->last_rx_silence == 0)
  2016. qual[count].qual = sta->last_rx_signal < 27 ?
  2017. 0 : (sta->last_rx_signal - 27) * 92 / 127;
  2018. else
  2019. qual[count].qual = sta->last_rx_signal -
  2020. sta->last_rx_silence - 35;
  2021. qual[count].level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
  2022. qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
  2023. qual[count].updated = sta->last_rx_updated;
  2024. sta->last_rx_updated = IW_QUAL_DBM;
  2025. count++;
  2026. if (count >= buf_size)
  2027. break;
  2028. }
  2029. spin_unlock_bh(&ap->sta_table_lock);
  2030. return count;
  2031. }
  2032. /* Translate our list of Access Points & Stations to a card independant
  2033. * format that the Wireless Tools will understand - Jean II */
  2034. int prism2_ap_translate_scan(struct net_device *dev, char *buffer)
  2035. {
  2036. struct hostap_interface *iface;
  2037. local_info_t *local;
  2038. struct ap_data *ap;
  2039. struct list_head *ptr;
  2040. struct iw_event iwe;
  2041. char *current_ev = buffer;
  2042. char *end_buf = buffer + IW_SCAN_MAX_DATA;
  2043. #if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
  2044. char buf[64];
  2045. #endif
  2046. iface = netdev_priv(dev);
  2047. local = iface->local;
  2048. ap = local->ap;
  2049. spin_lock_bh(&ap->sta_table_lock);
  2050. for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
  2051. ptr = ptr->next) {
  2052. struct sta_info *sta = (struct sta_info *) ptr;
  2053. /* First entry *MUST* be the AP MAC address */
  2054. memset(&iwe, 0, sizeof(iwe));
  2055. iwe.cmd = SIOCGIWAP;
  2056. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  2057. memcpy(iwe.u.ap_addr.sa_data, sta->addr, ETH_ALEN);
  2058. iwe.len = IW_EV_ADDR_LEN;
  2059. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
  2060. IW_EV_ADDR_LEN);
  2061. /* Use the mode to indicate if it's a station or
  2062. * an Access Point */
  2063. memset(&iwe, 0, sizeof(iwe));
  2064. iwe.cmd = SIOCGIWMODE;
  2065. if (sta->ap)
  2066. iwe.u.mode = IW_MODE_MASTER;
  2067. else
  2068. iwe.u.mode = IW_MODE_INFRA;
  2069. iwe.len = IW_EV_UINT_LEN;
  2070. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
  2071. IW_EV_UINT_LEN);
  2072. /* Some quality */
  2073. memset(&iwe, 0, sizeof(iwe));
  2074. iwe.cmd = IWEVQUAL;
  2075. if (sta->last_rx_silence == 0)
  2076. iwe.u.qual.qual = sta->last_rx_signal < 27 ?
  2077. 0 : (sta->last_rx_signal - 27) * 92 / 127;
  2078. else
  2079. iwe.u.qual.qual = sta->last_rx_signal -
  2080. sta->last_rx_silence - 35;
  2081. iwe.u.qual.level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
  2082. iwe.u.qual.noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
  2083. iwe.u.qual.updated = sta->last_rx_updated;
  2084. iwe.len = IW_EV_QUAL_LEN;
  2085. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
  2086. IW_EV_QUAL_LEN);
  2087. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  2088. if (sta->ap) {
  2089. memset(&iwe, 0, sizeof(iwe));
  2090. iwe.cmd = SIOCGIWESSID;
  2091. iwe.u.data.length = sta->u.ap.ssid_len;
  2092. iwe.u.data.flags = 1;
  2093. current_ev = iwe_stream_add_point(current_ev, end_buf,
  2094. &iwe,
  2095. sta->u.ap.ssid);
  2096. memset(&iwe, 0, sizeof(iwe));
  2097. iwe.cmd = SIOCGIWENCODE;
  2098. if (sta->capability & WLAN_CAPABILITY_PRIVACY)
  2099. iwe.u.data.flags =
  2100. IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  2101. else
  2102. iwe.u.data.flags = IW_ENCODE_DISABLED;
  2103. current_ev = iwe_stream_add_point(current_ev, end_buf,
  2104. &iwe,
  2105. sta->u.ap.ssid
  2106. /* 0 byte memcpy */);
  2107. if (sta->u.ap.channel > 0 &&
  2108. sta->u.ap.channel <= FREQ_COUNT) {
  2109. memset(&iwe, 0, sizeof(iwe));
  2110. iwe.cmd = SIOCGIWFREQ;
  2111. iwe.u.freq.m = freq_list[sta->u.ap.channel - 1]
  2112. * 100000;
  2113. iwe.u.freq.e = 1;
  2114. current_ev = iwe_stream_add_event(
  2115. current_ev, end_buf, &iwe,
  2116. IW_EV_FREQ_LEN);
  2117. }
  2118. memset(&iwe, 0, sizeof(iwe));
  2119. iwe.cmd = IWEVCUSTOM;
  2120. sprintf(buf, "beacon_interval=%d",
  2121. sta->listen_interval);
  2122. iwe.u.data.length = strlen(buf);
  2123. current_ev = iwe_stream_add_point(current_ev, end_buf,
  2124. &iwe, buf);
  2125. }
  2126. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  2127. sta->last_rx_updated = IW_QUAL_DBM;
  2128. /* To be continued, we should make good use of IWEVCUSTOM */
  2129. }
  2130. spin_unlock_bh(&ap->sta_table_lock);
  2131. return current_ev - buffer;
  2132. }
  2133. static int prism2_hostapd_add_sta(struct ap_data *ap,
  2134. struct prism2_hostapd_param *param)
  2135. {
  2136. struct sta_info *sta;
  2137. spin_lock_bh(&ap->sta_table_lock);
  2138. sta = ap_get_sta(ap, param->sta_addr);
  2139. if (sta)
  2140. atomic_inc(&sta->users);
  2141. spin_unlock_bh(&ap->sta_table_lock);
  2142. if (sta == NULL) {
  2143. sta = ap_add_sta(ap, param->sta_addr);
  2144. if (sta == NULL)
  2145. return -1;
  2146. }
  2147. if (!(sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
  2148. hostap_event_new_sta(sta->local->dev, sta);
  2149. sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
  2150. sta->last_rx = jiffies;
  2151. sta->aid = param->u.add_sta.aid;
  2152. sta->capability = param->u.add_sta.capability;
  2153. sta->tx_supp_rates = param->u.add_sta.tx_supp_rates;
  2154. if (sta->tx_supp_rates & WLAN_RATE_1M)
  2155. sta->supported_rates[0] = 2;
  2156. if (sta->tx_supp_rates & WLAN_RATE_2M)
  2157. sta->supported_rates[1] = 4;
  2158. if (sta->tx_supp_rates & WLAN_RATE_5M5)
  2159. sta->supported_rates[2] = 11;
  2160. if (sta->tx_supp_rates & WLAN_RATE_11M)
  2161. sta->supported_rates[3] = 22;
  2162. prism2_check_tx_rates(sta);
  2163. atomic_dec(&sta->users);
  2164. return 0;
  2165. }
  2166. static int prism2_hostapd_remove_sta(struct ap_data *ap,
  2167. struct prism2_hostapd_param *param)
  2168. {
  2169. struct sta_info *sta;
  2170. spin_lock_bh(&ap->sta_table_lock);
  2171. sta = ap_get_sta(ap, param->sta_addr);
  2172. if (sta) {
  2173. ap_sta_hash_del(ap, sta);
  2174. list_del(&sta->list);
  2175. }
  2176. spin_unlock_bh(&ap->sta_table_lock);
  2177. if (!sta)
  2178. return -ENOENT;
  2179. if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
  2180. hostap_event_expired_sta(sta->local->dev, sta);
  2181. ap_free_sta(ap, sta);
  2182. return 0;
  2183. }
  2184. static int prism2_hostapd_get_info_sta(struct ap_data *ap,
  2185. struct prism2_hostapd_param *param)
  2186. {
  2187. struct sta_info *sta;
  2188. spin_lock_bh(&ap->sta_table_lock);
  2189. sta = ap_get_sta(ap, param->sta_addr);
  2190. if (sta)
  2191. atomic_inc(&sta->users);
  2192. spin_unlock_bh(&ap->sta_table_lock);
  2193. if (!sta)
  2194. return -ENOENT;
  2195. param->u.get_info_sta.inactive_sec = (jiffies - sta->last_rx) / HZ;
  2196. atomic_dec(&sta->users);
  2197. return 1;
  2198. }
  2199. static int prism2_hostapd_set_flags_sta(struct ap_data *ap,
  2200. struct prism2_hostapd_param *param)
  2201. {
  2202. struct sta_info *sta;
  2203. spin_lock_bh(&ap->sta_table_lock);
  2204. sta = ap_get_sta(ap, param->sta_addr);
  2205. if (sta) {
  2206. sta->flags |= param->u.set_flags_sta.flags_or;
  2207. sta->flags &= param->u.set_flags_sta.flags_and;
  2208. }
  2209. spin_unlock_bh(&ap->sta_table_lock);
  2210. if (!sta)
  2211. return -ENOENT;
  2212. return 0;
  2213. }
  2214. static int prism2_hostapd_sta_clear_stats(struct ap_data *ap,
  2215. struct prism2_hostapd_param *param)
  2216. {
  2217. struct sta_info *sta;
  2218. int rate;
  2219. spin_lock_bh(&ap->sta_table_lock);
  2220. sta = ap_get_sta(ap, param->sta_addr);
  2221. if (sta) {
  2222. sta->rx_packets = sta->tx_packets = 0;
  2223. sta->rx_bytes = sta->tx_bytes = 0;
  2224. for (rate = 0; rate < WLAN_RATE_COUNT; rate++) {
  2225. sta->tx_count[rate] = 0;
  2226. sta->rx_count[rate] = 0;
  2227. }
  2228. }
  2229. spin_unlock_bh(&ap->sta_table_lock);
  2230. if (!sta)
  2231. return -ENOENT;
  2232. return 0;
  2233. }
  2234. int prism2_hostapd(struct ap_data *ap, struct prism2_hostapd_param *param)
  2235. {
  2236. switch (param->cmd) {
  2237. case PRISM2_HOSTAPD_FLUSH:
  2238. ap_control_kickall(ap);
  2239. return 0;
  2240. case PRISM2_HOSTAPD_ADD_STA:
  2241. return prism2_hostapd_add_sta(ap, param);
  2242. case PRISM2_HOSTAPD_REMOVE_STA:
  2243. return prism2_hostapd_remove_sta(ap, param);
  2244. case PRISM2_HOSTAPD_GET_INFO_STA:
  2245. return prism2_hostapd_get_info_sta(ap, param);
  2246. case PRISM2_HOSTAPD_SET_FLAGS_STA:
  2247. return prism2_hostapd_set_flags_sta(ap, param);
  2248. case PRISM2_HOSTAPD_STA_CLEAR_STATS:
  2249. return prism2_hostapd_sta_clear_stats(ap, param);
  2250. default:
  2251. printk(KERN_WARNING "prism2_hostapd: unknown cmd=%d\n",
  2252. param->cmd);
  2253. return -EOPNOTSUPP;
  2254. }
  2255. }
  2256. /* Update station info for host-based TX rate control and return current
  2257. * TX rate */
  2258. static int ap_update_sta_tx_rate(struct sta_info *sta, struct net_device *dev)
  2259. {
  2260. int ret = sta->tx_rate;
  2261. struct hostap_interface *iface;
  2262. local_info_t *local;
  2263. iface = netdev_priv(dev);
  2264. local = iface->local;
  2265. sta->tx_count[sta->tx_rate_idx]++;
  2266. sta->tx_since_last_failure++;
  2267. sta->tx_consecutive_exc = 0;
  2268. if (sta->tx_since_last_failure >= WLAN_RATE_UPDATE_COUNT &&
  2269. sta->tx_rate_idx < sta->tx_max_rate) {
  2270. /* use next higher rate */
  2271. int old_rate, new_rate;
  2272. old_rate = new_rate = sta->tx_rate_idx;
  2273. while (new_rate < sta->tx_max_rate) {
  2274. new_rate++;
  2275. if (ap_tx_rate_ok(new_rate, sta, local)) {
  2276. sta->tx_rate_idx = new_rate;
  2277. break;
  2278. }
  2279. }
  2280. if (old_rate != sta->tx_rate_idx) {
  2281. switch (sta->tx_rate_idx) {
  2282. case 0: sta->tx_rate = 10; break;
  2283. case 1: sta->tx_rate = 20; break;
  2284. case 2: sta->tx_rate = 55; break;
  2285. case 3: sta->tx_rate = 110; break;
  2286. default: sta->tx_rate = 0; break;
  2287. }
  2288. PDEBUG(DEBUG_AP, "%s: STA " MAC_FMT
  2289. " TX rate raised to %d\n",
  2290. dev->name,
  2291. sta->addr[0], sta->addr[1], sta->addr[2],
  2292. sta->addr[3], sta->addr[4], sta->addr[5],
  2293. sta->tx_rate);
  2294. }
  2295. sta->tx_since_last_failure = 0;
  2296. }
  2297. return ret;
  2298. }
  2299. /* Called only from software IRQ. Called for each TX frame prior possible
  2300. * encryption and transmit. */
  2301. ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
  2302. {
  2303. struct sta_info *sta = NULL;
  2304. struct sk_buff *skb = tx->skb;
  2305. int set_tim, ret;
  2306. struct ieee80211_hdr_4addr *hdr;
  2307. struct hostap_skb_tx_data *meta;
  2308. meta = (struct hostap_skb_tx_data *) skb->cb;
  2309. ret = AP_TX_CONTINUE;
  2310. if (local->ap == NULL || skb->len < 10 ||
  2311. meta->iface->type == HOSTAP_INTERFACE_STA)
  2312. goto out;
  2313. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  2314. if (hdr->addr1[0] & 0x01) {
  2315. /* broadcast/multicast frame - no AP related processing */
  2316. if (local->ap->num_sta <= 0)
  2317. ret = AP_TX_DROP;
  2318. goto out;
  2319. }
  2320. /* unicast packet - check whether destination STA is associated */
  2321. spin_lock(&local->ap->sta_table_lock);
  2322. sta = ap_get_sta(local->ap, hdr->addr1);
  2323. if (sta)
  2324. atomic_inc(&sta->users);
  2325. spin_unlock(&local->ap->sta_table_lock);
  2326. if (local->iw_mode == IW_MODE_MASTER && sta == NULL &&
  2327. !(meta->flags & HOSTAP_TX_FLAGS_WDS) &&
  2328. meta->iface->type != HOSTAP_INTERFACE_MASTER &&
  2329. meta->iface->type != HOSTAP_INTERFACE_AP) {
  2330. #if 0
  2331. /* This can happen, e.g., when wlan0 is added to a bridge and
  2332. * bridging code does not know which port is the correct target
  2333. * for a unicast frame. In this case, the packet is send to all
  2334. * ports of the bridge. Since this is a valid scenario, do not
  2335. * print out any errors here. */
  2336. if (net_ratelimit()) {
  2337. printk(KERN_DEBUG "AP: drop packet to non-associated "
  2338. "STA " MAC_FMT "\n",
  2339. hdr->addr1[0], hdr->addr1[1], hdr->addr1[2],
  2340. hdr->addr1[3], hdr->addr1[4], hdr->addr1[5]);
  2341. }
  2342. #endif
  2343. local->ap->tx_drop_nonassoc++;
  2344. ret = AP_TX_DROP;
  2345. goto out;
  2346. }
  2347. if (sta == NULL)
  2348. goto out;
  2349. if (!(sta->flags & WLAN_STA_AUTHORIZED))
  2350. ret = AP_TX_CONTINUE_NOT_AUTHORIZED;
  2351. /* Set tx_rate if using host-based TX rate control */
  2352. if (!local->fw_tx_rate_control)
  2353. local->ap->last_tx_rate = meta->rate =
  2354. ap_update_sta_tx_rate(sta, local->dev);
  2355. if (local->iw_mode != IW_MODE_MASTER)
  2356. goto out;
  2357. if (!(sta->flags & WLAN_STA_PS))
  2358. goto out;
  2359. if (meta->flags & HOSTAP_TX_FLAGS_ADD_MOREDATA) {
  2360. /* indicate to STA that more frames follow */
  2361. hdr->frame_ctl |=
  2362. __constant_cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  2363. }
  2364. if (meta->flags & HOSTAP_TX_FLAGS_BUFFERED_FRAME) {
  2365. /* packet was already buffered and now send due to
  2366. * PS poll, so do not rebuffer it */
  2367. goto out;
  2368. }
  2369. if (skb_queue_len(&sta->tx_buf) >= STA_MAX_TX_BUFFER) {
  2370. PDEBUG(DEBUG_PS, "%s: No more space in STA (" MAC_FMT
  2371. ")'s PS mode buffer\n",
  2372. local->dev->name,
  2373. sta->addr[0], sta->addr[1], sta->addr[2],
  2374. sta->addr[3], sta->addr[4], sta->addr[5]);
  2375. /* Make sure that TIM is set for the station (it might not be
  2376. * after AP wlan hw reset). */
  2377. /* FIX: should fix hw reset to restore bits based on STA
  2378. * buffer state.. */
  2379. hostap_set_tim(local, sta->aid, 1);
  2380. sta->flags |= WLAN_STA_TIM;
  2381. ret = AP_TX_DROP;
  2382. goto out;
  2383. }
  2384. /* STA in PS mode, buffer frame for later delivery */
  2385. set_tim = skb_queue_empty(&sta->tx_buf);
  2386. skb_queue_tail(&sta->tx_buf, skb);
  2387. /* FIX: could save RX time to skb and expire buffered frames after
  2388. * some time if STA does not poll for them */
  2389. if (set_tim) {
  2390. if (sta->flags & WLAN_STA_TIM)
  2391. PDEBUG(DEBUG_PS2, "Re-setting TIM for aid %d\n",
  2392. sta->aid);
  2393. hostap_set_tim(local, sta->aid, 1);
  2394. sta->flags |= WLAN_STA_TIM;
  2395. }
  2396. ret = AP_TX_BUFFERED;
  2397. out:
  2398. if (sta != NULL) {
  2399. if (ret == AP_TX_CONTINUE ||
  2400. ret == AP_TX_CONTINUE_NOT_AUTHORIZED) {
  2401. sta->tx_packets++;
  2402. sta->tx_bytes += skb->len;
  2403. sta->last_tx = jiffies;
  2404. }
  2405. if ((ret == AP_TX_CONTINUE ||
  2406. ret == AP_TX_CONTINUE_NOT_AUTHORIZED) &&
  2407. sta->crypt && tx->host_encrypt) {
  2408. tx->crypt = sta->crypt;
  2409. tx->sta_ptr = sta; /* hostap_handle_sta_release() will
  2410. * be called to release sta info
  2411. * later */
  2412. } else
  2413. atomic_dec(&sta->users);
  2414. }
  2415. return ret;
  2416. }
  2417. void hostap_handle_sta_release(void *ptr)
  2418. {
  2419. struct sta_info *sta = ptr;
  2420. atomic_dec(&sta->users);
  2421. }
  2422. /* Called only as a tasklet (software IRQ) */
  2423. void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb)
  2424. {
  2425. struct sta_info *sta;
  2426. struct ieee80211_hdr_4addr *hdr;
  2427. struct hostap_skb_tx_data *meta;
  2428. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  2429. meta = (struct hostap_skb_tx_data *) skb->cb;
  2430. spin_lock(&local->ap->sta_table_lock);
  2431. sta = ap_get_sta(local->ap, hdr->addr1);
  2432. if (!sta) {
  2433. spin_unlock(&local->ap->sta_table_lock);
  2434. PDEBUG(DEBUG_AP, "%s: Could not find STA " MAC_FMT
  2435. " for this TX error (@%lu)\n",
  2436. local->dev->name,
  2437. hdr->addr1[0], hdr->addr1[1], hdr->addr1[2],
  2438. hdr->addr1[3], hdr->addr1[4], hdr->addr1[5],
  2439. jiffies);
  2440. return;
  2441. }
  2442. sta->tx_since_last_failure = 0;
  2443. sta->tx_consecutive_exc++;
  2444. if (sta->tx_consecutive_exc >= WLAN_RATE_DECREASE_THRESHOLD &&
  2445. sta->tx_rate_idx > 0 && meta->rate <= sta->tx_rate) {
  2446. /* use next lower rate */
  2447. int old, rate;
  2448. old = rate = sta->tx_rate_idx;
  2449. while (rate > 0) {
  2450. rate--;
  2451. if (ap_tx_rate_ok(rate, sta, local)) {
  2452. sta->tx_rate_idx = rate;
  2453. break;
  2454. }
  2455. }
  2456. if (old != sta->tx_rate_idx) {
  2457. switch (sta->tx_rate_idx) {
  2458. case 0: sta->tx_rate = 10; break;
  2459. case 1: sta->tx_rate = 20; break;
  2460. case 2: sta->tx_rate = 55; break;
  2461. case 3: sta->tx_rate = 110; break;
  2462. default: sta->tx_rate = 0; break;
  2463. }
  2464. PDEBUG(DEBUG_AP, "%s: STA " MAC_FMT
  2465. " TX rate lowered to %d\n",
  2466. local->dev->name,
  2467. sta->addr[0], sta->addr[1], sta->addr[2],
  2468. sta->addr[3], sta->addr[4], sta->addr[5],
  2469. sta->tx_rate);
  2470. }
  2471. sta->tx_consecutive_exc = 0;
  2472. }
  2473. spin_unlock(&local->ap->sta_table_lock);
  2474. }
  2475. static void hostap_update_sta_ps2(local_info_t *local, struct sta_info *sta,
  2476. int pwrmgt, int type, int stype)
  2477. {
  2478. DECLARE_MAC_BUF(mac);
  2479. if (pwrmgt && !(sta->flags & WLAN_STA_PS)) {
  2480. sta->flags |= WLAN_STA_PS;
  2481. PDEBUG(DEBUG_PS2, "STA %s changed to use PS "
  2482. "mode (type=0x%02X, stype=0x%02X)\n",
  2483. print_mac(mac, sta->addr), type >> 2, stype >> 4);
  2484. } else if (!pwrmgt && (sta->flags & WLAN_STA_PS)) {
  2485. sta->flags &= ~WLAN_STA_PS;
  2486. PDEBUG(DEBUG_PS2, "STA %s changed to not use "
  2487. "PS mode (type=0x%02X, stype=0x%02X)\n",
  2488. print_mac(mac, sta->addr), type >> 2, stype >> 4);
  2489. if (type != IEEE80211_FTYPE_CTL ||
  2490. stype != IEEE80211_STYPE_PSPOLL)
  2491. schedule_packet_send(local, sta);
  2492. }
  2493. }
  2494. /* Called only as a tasklet (software IRQ). Called for each RX frame to update
  2495. * STA power saving state. pwrmgt is a flag from 802.11 frame_ctl field. */
  2496. int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr_4addr *hdr)
  2497. {
  2498. struct sta_info *sta;
  2499. u16 fc;
  2500. spin_lock(&local->ap->sta_table_lock);
  2501. sta = ap_get_sta(local->ap, hdr->addr2);
  2502. if (sta)
  2503. atomic_inc(&sta->users);
  2504. spin_unlock(&local->ap->sta_table_lock);
  2505. if (!sta)
  2506. return -1;
  2507. fc = le16_to_cpu(hdr->frame_ctl);
  2508. hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
  2509. WLAN_FC_GET_TYPE(fc), WLAN_FC_GET_STYPE(fc));
  2510. atomic_dec(&sta->users);
  2511. return 0;
  2512. }
  2513. /* Called only as a tasklet (software IRQ). Called for each RX frame after
  2514. * getting RX header and payload from hardware. */
  2515. ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
  2516. struct sk_buff *skb,
  2517. struct hostap_80211_rx_status *rx_stats,
  2518. int wds)
  2519. {
  2520. int ret;
  2521. struct sta_info *sta;
  2522. u16 fc, type, stype;
  2523. struct ieee80211_hdr_4addr *hdr;
  2524. if (local->ap == NULL)
  2525. return AP_RX_CONTINUE;
  2526. hdr = (struct ieee80211_hdr_4addr *) skb->data;
  2527. fc = le16_to_cpu(hdr->frame_ctl);
  2528. type = WLAN_FC_GET_TYPE(fc);
  2529. stype = WLAN_FC_GET_STYPE(fc);
  2530. spin_lock(&local->ap->sta_table_lock);
  2531. sta = ap_get_sta(local->ap, hdr->addr2);
  2532. if (sta)
  2533. atomic_inc(&sta->users);
  2534. spin_unlock(&local->ap->sta_table_lock);
  2535. if (sta && !(sta->flags & WLAN_STA_AUTHORIZED))
  2536. ret = AP_RX_CONTINUE_NOT_AUTHORIZED;
  2537. else
  2538. ret = AP_RX_CONTINUE;
  2539. if (fc & IEEE80211_FCTL_TODS) {
  2540. if (!wds && (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
  2541. if (local->hostapd) {
  2542. prism2_rx_80211(local->apdev, skb, rx_stats,
  2543. PRISM2_RX_NON_ASSOC);
  2544. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  2545. } else {
  2546. printk(KERN_DEBUG "%s: dropped received packet"
  2547. " from non-associated STA "
  2548. MAC_FMT
  2549. " (type=0x%02x, subtype=0x%02x)\n",
  2550. dev->name,
  2551. hdr->addr2[0], hdr->addr2[1],
  2552. hdr->addr2[2], hdr->addr2[3],
  2553. hdr->addr2[4], hdr->addr2[5],
  2554. type >> 2, stype >> 4);
  2555. hostap_rx(dev, skb, rx_stats);
  2556. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  2557. }
  2558. ret = AP_RX_EXIT;
  2559. goto out;
  2560. }
  2561. } else if (fc & IEEE80211_FCTL_FROMDS) {
  2562. if (!wds) {
  2563. /* FromDS frame - not for us; probably
  2564. * broadcast/multicast in another BSS - drop */
  2565. if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
  2566. printk(KERN_DEBUG "Odd.. FromDS packet "
  2567. "received with own BSSID\n");
  2568. hostap_dump_rx_80211(dev->name, skb, rx_stats);
  2569. }
  2570. ret = AP_RX_DROP;
  2571. goto out;
  2572. }
  2573. } else if (stype == IEEE80211_STYPE_NULLFUNC && sta == NULL &&
  2574. memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
  2575. if (local->hostapd) {
  2576. prism2_rx_80211(local->apdev, skb, rx_stats,
  2577. PRISM2_RX_NON_ASSOC);
  2578. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  2579. } else {
  2580. /* At least Lucent f/w seems to send data::nullfunc
  2581. * frames with no ToDS flag when the current AP returns
  2582. * after being unavailable for some time. Speed up
  2583. * re-association by informing the station about it not
  2584. * being associated. */
  2585. printk(KERN_DEBUG "%s: rejected received nullfunc "
  2586. "frame without ToDS from not associated STA "
  2587. MAC_FMT "\n",
  2588. dev->name,
  2589. hdr->addr2[0], hdr->addr2[1],
  2590. hdr->addr2[2], hdr->addr2[3],
  2591. hdr->addr2[4], hdr->addr2[5]);
  2592. hostap_rx(dev, skb, rx_stats);
  2593. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  2594. }
  2595. ret = AP_RX_EXIT;
  2596. goto out;
  2597. } else if (stype == IEEE80211_STYPE_NULLFUNC) {
  2598. /* At least Lucent cards seem to send periodic nullfunc
  2599. * frames with ToDS. Let these through to update SQ
  2600. * stats and PS state. Nullfunc frames do not contain
  2601. * any data and they will be dropped below. */
  2602. } else {
  2603. /* If BSSID (Addr3) is foreign, this frame is a normal
  2604. * broadcast frame from an IBSS network. Drop it silently.
  2605. * If BSSID is own, report the dropping of this frame. */
  2606. if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
  2607. printk(KERN_DEBUG "%s: dropped received packet from "
  2608. MAC_FMT " with no ToDS flag "
  2609. "(type=0x%02x, subtype=0x%02x)\n", dev->name,
  2610. hdr->addr2[0], hdr->addr2[1],
  2611. hdr->addr2[2], hdr->addr2[3],
  2612. hdr->addr2[4], hdr->addr2[5],
  2613. type >> 2, stype >> 4);
  2614. hostap_dump_rx_80211(dev->name, skb, rx_stats);
  2615. }
  2616. ret = AP_RX_DROP;
  2617. goto out;
  2618. }
  2619. if (sta) {
  2620. hostap_update_sta_ps2(local, sta, fc & IEEE80211_FCTL_PM,
  2621. type, stype);
  2622. sta->rx_packets++;
  2623. sta->rx_bytes += skb->len;
  2624. sta->last_rx = jiffies;
  2625. }
  2626. if (local->ap->nullfunc_ack && stype == IEEE80211_STYPE_NULLFUNC &&
  2627. fc & IEEE80211_FCTL_TODS) {
  2628. if (local->hostapd) {
  2629. prism2_rx_80211(local->apdev, skb, rx_stats,
  2630. PRISM2_RX_NULLFUNC_ACK);
  2631. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  2632. } else {
  2633. /* some STA f/w's seem to require control::ACK frame
  2634. * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
  2635. * from Compaq) does not send this.. Try to generate
  2636. * ACK for these frames from the host driver to make
  2637. * power saving work with, e.g., Lucent WaveLAN f/w */
  2638. hostap_rx(dev, skb, rx_stats);
  2639. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  2640. }
  2641. ret = AP_RX_EXIT;
  2642. goto out;
  2643. }
  2644. out:
  2645. if (sta)
  2646. atomic_dec(&sta->users);
  2647. return ret;
  2648. }
  2649. /* Called only as a tasklet (software IRQ) */
  2650. int hostap_handle_sta_crypto(local_info_t *local,
  2651. struct ieee80211_hdr_4addr *hdr,
  2652. struct ieee80211_crypt_data **crypt,
  2653. void **sta_ptr)
  2654. {
  2655. struct sta_info *sta;
  2656. spin_lock(&local->ap->sta_table_lock);
  2657. sta = ap_get_sta(local->ap, hdr->addr2);
  2658. if (sta)
  2659. atomic_inc(&sta->users);
  2660. spin_unlock(&local->ap->sta_table_lock);
  2661. if (!sta)
  2662. return -1;
  2663. if (sta->crypt) {
  2664. *crypt = sta->crypt;
  2665. *sta_ptr = sta;
  2666. /* hostap_handle_sta_release() will be called to release STA
  2667. * info */
  2668. } else
  2669. atomic_dec(&sta->users);
  2670. return 0;
  2671. }
  2672. /* Called only as a tasklet (software IRQ) */
  2673. int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr)
  2674. {
  2675. struct sta_info *sta;
  2676. int ret = 0;
  2677. spin_lock(&ap->sta_table_lock);
  2678. sta = ap_get_sta(ap, sta_addr);
  2679. if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap)
  2680. ret = 1;
  2681. spin_unlock(&ap->sta_table_lock);
  2682. return ret;
  2683. }
  2684. /* Called only as a tasklet (software IRQ) */
  2685. int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr)
  2686. {
  2687. struct sta_info *sta;
  2688. int ret = 0;
  2689. spin_lock(&ap->sta_table_lock);
  2690. sta = ap_get_sta(ap, sta_addr);
  2691. if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap &&
  2692. ((sta->flags & WLAN_STA_AUTHORIZED) ||
  2693. ap->local->ieee_802_1x == 0))
  2694. ret = 1;
  2695. spin_unlock(&ap->sta_table_lock);
  2696. return ret;
  2697. }
  2698. /* Called only as a tasklet (software IRQ) */
  2699. int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
  2700. {
  2701. struct sta_info *sta;
  2702. int ret = 1;
  2703. if (!ap)
  2704. return -1;
  2705. spin_lock(&ap->sta_table_lock);
  2706. sta = ap_get_sta(ap, sta_addr);
  2707. if (sta)
  2708. ret = 0;
  2709. spin_unlock(&ap->sta_table_lock);
  2710. if (ret == 1) {
  2711. sta = ap_add_sta(ap, sta_addr);
  2712. if (!sta)
  2713. return -1;
  2714. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  2715. sta->ap = 1;
  2716. memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
  2717. /* No way of knowing which rates are supported since we did not
  2718. * get supported rates element from beacon/assoc req. Assume
  2719. * that remote end supports all 802.11b rates. */
  2720. sta->supported_rates[0] = 0x82;
  2721. sta->supported_rates[1] = 0x84;
  2722. sta->supported_rates[2] = 0x0b;
  2723. sta->supported_rates[3] = 0x16;
  2724. sta->tx_supp_rates = WLAN_RATE_1M | WLAN_RATE_2M |
  2725. WLAN_RATE_5M5 | WLAN_RATE_11M;
  2726. sta->tx_rate = 110;
  2727. sta->tx_max_rate = sta->tx_rate_idx = 3;
  2728. }
  2729. return ret;
  2730. }
  2731. /* Called only as a tasklet (software IRQ) */
  2732. int hostap_update_rx_stats(struct ap_data *ap,
  2733. struct ieee80211_hdr_4addr *hdr,
  2734. struct hostap_80211_rx_status *rx_stats)
  2735. {
  2736. struct sta_info *sta;
  2737. if (!ap)
  2738. return -1;
  2739. spin_lock(&ap->sta_table_lock);
  2740. sta = ap_get_sta(ap, hdr->addr2);
  2741. if (sta) {
  2742. sta->last_rx_silence = rx_stats->noise;
  2743. sta->last_rx_signal = rx_stats->signal;
  2744. sta->last_rx_rate = rx_stats->rate;
  2745. sta->last_rx_updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  2746. if (rx_stats->rate == 10)
  2747. sta->rx_count[0]++;
  2748. else if (rx_stats->rate == 20)
  2749. sta->rx_count[1]++;
  2750. else if (rx_stats->rate == 55)
  2751. sta->rx_count[2]++;
  2752. else if (rx_stats->rate == 110)
  2753. sta->rx_count[3]++;
  2754. }
  2755. spin_unlock(&ap->sta_table_lock);
  2756. return sta ? 0 : -1;
  2757. }
  2758. void hostap_update_rates(local_info_t *local)
  2759. {
  2760. struct sta_info *sta;
  2761. struct ap_data *ap = local->ap;
  2762. if (!ap)
  2763. return;
  2764. spin_lock_bh(&ap->sta_table_lock);
  2765. list_for_each_entry(sta, &ap->sta_list, list) {
  2766. prism2_check_tx_rates(sta);
  2767. }
  2768. spin_unlock_bh(&ap->sta_table_lock);
  2769. }
  2770. void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
  2771. struct ieee80211_crypt_data ***crypt)
  2772. {
  2773. struct sta_info *sta;
  2774. spin_lock_bh(&ap->sta_table_lock);
  2775. sta = ap_get_sta(ap, addr);
  2776. if (sta)
  2777. atomic_inc(&sta->users);
  2778. spin_unlock_bh(&ap->sta_table_lock);
  2779. if (!sta && permanent)
  2780. sta = ap_add_sta(ap, addr);
  2781. if (!sta)
  2782. return NULL;
  2783. if (permanent)
  2784. sta->flags |= WLAN_STA_PERM;
  2785. *crypt = &sta->crypt;
  2786. return sta;
  2787. }
  2788. void hostap_add_wds_links(local_info_t *local)
  2789. {
  2790. struct ap_data *ap = local->ap;
  2791. struct sta_info *sta;
  2792. spin_lock_bh(&ap->sta_table_lock);
  2793. list_for_each_entry(sta, &ap->sta_list, list) {
  2794. if (sta->ap)
  2795. hostap_wds_link_oper(local, sta->addr, WDS_ADD);
  2796. }
  2797. spin_unlock_bh(&ap->sta_table_lock);
  2798. schedule_work(&local->ap->wds_oper_queue);
  2799. }
  2800. void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type)
  2801. {
  2802. struct wds_oper_data *entry;
  2803. entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
  2804. if (!entry)
  2805. return;
  2806. memcpy(entry->addr, addr, ETH_ALEN);
  2807. entry->type = type;
  2808. spin_lock_bh(&local->lock);
  2809. entry->next = local->ap->wds_oper_entries;
  2810. local->ap->wds_oper_entries = entry;
  2811. spin_unlock_bh(&local->lock);
  2812. schedule_work(&local->ap->wds_oper_queue);
  2813. }
  2814. EXPORT_SYMBOL(hostap_init_data);
  2815. EXPORT_SYMBOL(hostap_init_ap_proc);
  2816. EXPORT_SYMBOL(hostap_free_data);
  2817. EXPORT_SYMBOL(hostap_check_sta_fw_version);
  2818. EXPORT_SYMBOL(hostap_handle_sta_tx_exc);
  2819. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  2820. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */