hostap_ap.c 85 KB

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