hostap_ap.c 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286
  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. * <jkmaline@cc.hut.fi>
  5. * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.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. static int other_ap_policy[MAX_PARM_DEVICES] = { AP_OTHER_AP_SKIP_ALL,
  19. DEF_INTS };
  20. module_param_array(other_ap_policy, int, NULL, 0444);
  21. MODULE_PARM_DESC(other_ap_policy, "Other AP beacon monitoring policy (0-3)");
  22. static int ap_max_inactivity[MAX_PARM_DEVICES] = { AP_MAX_INACTIVITY_SEC,
  23. DEF_INTS };
  24. module_param_array(ap_max_inactivity, int, NULL, 0444);
  25. MODULE_PARM_DESC(ap_max_inactivity, "AP timeout (in seconds) for station "
  26. "inactivity");
  27. static int ap_bridge_packets[MAX_PARM_DEVICES] = { 1, DEF_INTS };
  28. module_param_array(ap_bridge_packets, int, NULL, 0444);
  29. MODULE_PARM_DESC(ap_bridge_packets, "Bridge packets directly between "
  30. "stations");
  31. static int autom_ap_wds[MAX_PARM_DEVICES] = { 0, DEF_INTS };
  32. module_param_array(autom_ap_wds, int, NULL, 0444);
  33. MODULE_PARM_DESC(autom_ap_wds, "Add WDS connections to other APs "
  34. "automatically");
  35. static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta);
  36. static void hostap_event_expired_sta(struct net_device *dev,
  37. struct sta_info *sta);
  38. static void handle_add_proc_queue(void *data);
  39. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  40. static void handle_wds_oper_queue(void *data);
  41. static void prism2_send_mgmt(struct net_device *dev,
  42. int type, int subtype, char *body,
  43. int body_len, u8 *addr, u16 tx_cb_idx);
  44. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  45. #ifndef PRISM2_NO_PROCFS_DEBUG
  46. static int ap_debug_proc_read(char *page, char **start, off_t off,
  47. int count, int *eof, void *data)
  48. {
  49. char *p = page;
  50. struct ap_data *ap = (struct ap_data *) data;
  51. if (off != 0) {
  52. *eof = 1;
  53. return 0;
  54. }
  55. p += sprintf(p, "BridgedUnicastFrames=%u\n", ap->bridged_unicast);
  56. p += sprintf(p, "BridgedMulticastFrames=%u\n", ap->bridged_multicast);
  57. p += sprintf(p, "max_inactivity=%u\n", ap->max_inactivity / HZ);
  58. p += sprintf(p, "bridge_packets=%u\n", ap->bridge_packets);
  59. p += sprintf(p, "nullfunc_ack=%u\n", ap->nullfunc_ack);
  60. p += sprintf(p, "autom_ap_wds=%u\n", ap->autom_ap_wds);
  61. p += sprintf(p, "auth_algs=%u\n", ap->local->auth_algs);
  62. p += sprintf(p, "tx_drop_nonassoc=%u\n", ap->tx_drop_nonassoc);
  63. return (p - page);
  64. }
  65. #endif /* PRISM2_NO_PROCFS_DEBUG */
  66. static void ap_sta_hash_add(struct ap_data *ap, struct sta_info *sta)
  67. {
  68. sta->hnext = ap->sta_hash[STA_HASH(sta->addr)];
  69. ap->sta_hash[STA_HASH(sta->addr)] = sta;
  70. }
  71. static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
  72. {
  73. struct sta_info *s;
  74. s = ap->sta_hash[STA_HASH(sta->addr)];
  75. if (s == NULL) return;
  76. if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
  77. ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
  78. return;
  79. }
  80. while (s->hnext != NULL && memcmp(s->hnext->addr, sta->addr, ETH_ALEN)
  81. != 0)
  82. s = s->hnext;
  83. if (s->hnext != NULL)
  84. s->hnext = s->hnext->hnext;
  85. else
  86. printk("AP: could not remove STA " MACSTR " from hash table\n",
  87. MAC2STR(sta->addr));
  88. }
  89. static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
  90. {
  91. if (sta->ap && sta->local)
  92. hostap_event_expired_sta(sta->local->dev, sta);
  93. if (ap->proc != NULL) {
  94. char name[20];
  95. sprintf(name, MACSTR, MAC2STR(sta->addr));
  96. remove_proc_entry(name, ap->proc);
  97. }
  98. if (sta->crypt) {
  99. sta->crypt->ops->deinit(sta->crypt->priv);
  100. kfree(sta->crypt);
  101. sta->crypt = NULL;
  102. }
  103. skb_queue_purge(&sta->tx_buf);
  104. ap->num_sta--;
  105. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  106. if (sta->aid > 0)
  107. ap->sta_aid[sta->aid - 1] = NULL;
  108. if (!sta->ap && sta->u.sta.challenge)
  109. kfree(sta->u.sta.challenge);
  110. del_timer(&sta->timer);
  111. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  112. kfree(sta);
  113. }
  114. static void hostap_set_tim(local_info_t *local, int aid, int set)
  115. {
  116. if (local->func->set_tim)
  117. local->func->set_tim(local->dev, aid, set);
  118. }
  119. static void hostap_event_new_sta(struct net_device *dev, struct sta_info *sta)
  120. {
  121. union iwreq_data wrqu;
  122. memset(&wrqu, 0, sizeof(wrqu));
  123. memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
  124. wrqu.addr.sa_family = ARPHRD_ETHER;
  125. wireless_send_event(dev, IWEVREGISTERED, &wrqu, NULL);
  126. }
  127. static void hostap_event_expired_sta(struct net_device *dev,
  128. struct sta_info *sta)
  129. {
  130. union iwreq_data wrqu;
  131. memset(&wrqu, 0, sizeof(wrqu));
  132. memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
  133. wrqu.addr.sa_family = ARPHRD_ETHER;
  134. wireless_send_event(dev, IWEVEXPIRED, &wrqu, NULL);
  135. }
  136. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  137. static void ap_handle_timer(unsigned long data)
  138. {
  139. struct sta_info *sta = (struct sta_info *) data;
  140. local_info_t *local;
  141. struct ap_data *ap;
  142. unsigned long next_time = 0;
  143. int was_assoc;
  144. if (sta == NULL || sta->local == NULL || sta->local->ap == NULL) {
  145. PDEBUG(DEBUG_AP, "ap_handle_timer() called with NULL data\n");
  146. return;
  147. }
  148. local = sta->local;
  149. ap = local->ap;
  150. was_assoc = sta->flags & WLAN_STA_ASSOC;
  151. if (atomic_read(&sta->users) != 0)
  152. next_time = jiffies + HZ;
  153. else if ((sta->flags & WLAN_STA_PERM) && !(sta->flags & WLAN_STA_AUTH))
  154. next_time = jiffies + ap->max_inactivity;
  155. if (time_before(jiffies, sta->last_rx + ap->max_inactivity)) {
  156. /* station activity detected; reset timeout state */
  157. sta->timeout_next = STA_NULLFUNC;
  158. next_time = sta->last_rx + ap->max_inactivity;
  159. } else if (sta->timeout_next == STA_DISASSOC &&
  160. !(sta->flags & WLAN_STA_PENDING_POLL)) {
  161. /* STA ACKed data nullfunc frame poll */
  162. sta->timeout_next = STA_NULLFUNC;
  163. next_time = jiffies + ap->max_inactivity;
  164. }
  165. if (next_time) {
  166. sta->timer.expires = next_time;
  167. add_timer(&sta->timer);
  168. return;
  169. }
  170. if (sta->ap)
  171. sta->timeout_next = STA_DEAUTH;
  172. if (sta->timeout_next == STA_DEAUTH && !(sta->flags & WLAN_STA_PERM)) {
  173. spin_lock(&ap->sta_table_lock);
  174. ap_sta_hash_del(ap, sta);
  175. list_del(&sta->list);
  176. spin_unlock(&ap->sta_table_lock);
  177. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
  178. } else if (sta->timeout_next == STA_DISASSOC)
  179. sta->flags &= ~WLAN_STA_ASSOC;
  180. if (was_assoc && !(sta->flags & WLAN_STA_ASSOC) && !sta->ap)
  181. hostap_event_expired_sta(local->dev, sta);
  182. if (sta->timeout_next == STA_DEAUTH && sta->aid > 0 &&
  183. !skb_queue_empty(&sta->tx_buf)) {
  184. hostap_set_tim(local, sta->aid, 0);
  185. sta->flags &= ~WLAN_STA_TIM;
  186. }
  187. if (sta->ap) {
  188. if (ap->autom_ap_wds) {
  189. PDEBUG(DEBUG_AP, "%s: removing automatic WDS "
  190. "connection to AP " MACSTR "\n",
  191. local->dev->name, MAC2STR(sta->addr));
  192. hostap_wds_link_oper(local, sta->addr, WDS_DEL);
  193. }
  194. } else if (sta->timeout_next == STA_NULLFUNC) {
  195. /* send data frame to poll STA and check whether this frame
  196. * is ACKed */
  197. /* FIX: WLAN_FC_STYPE_NULLFUNC would be more appropriate, but
  198. * it is apparently not retried so TX Exc events are not
  199. * received for it */
  200. sta->flags |= WLAN_STA_PENDING_POLL;
  201. prism2_send_mgmt(local->dev, WLAN_FC_TYPE_DATA,
  202. WLAN_FC_STYPE_DATA, NULL, 0,
  203. sta->addr, ap->tx_callback_poll);
  204. } else {
  205. int deauth = sta->timeout_next == STA_DEAUTH;
  206. u16 resp;
  207. PDEBUG(DEBUG_AP, "%s: sending %s info to STA " MACSTR
  208. "(last=%lu, jiffies=%lu)\n",
  209. local->dev->name,
  210. deauth ? "deauthentication" : "disassociation",
  211. MAC2STR(sta->addr), sta->last_rx, jiffies);
  212. resp = cpu_to_le16(deauth ? WLAN_REASON_PREV_AUTH_NOT_VALID :
  213. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  214. prism2_send_mgmt(local->dev, WLAN_FC_TYPE_MGMT,
  215. (deauth ? WLAN_FC_STYPE_DEAUTH :
  216. WLAN_FC_STYPE_DISASSOC),
  217. (char *) &resp, 2, sta->addr, 0);
  218. }
  219. if (sta->timeout_next == STA_DEAUTH) {
  220. if (sta->flags & WLAN_STA_PERM) {
  221. PDEBUG(DEBUG_AP, "%s: STA " MACSTR " would have been "
  222. "removed, but it has 'perm' flag\n",
  223. local->dev->name, MAC2STR(sta->addr));
  224. } else
  225. ap_free_sta(ap, sta);
  226. return;
  227. }
  228. if (sta->timeout_next == STA_NULLFUNC) {
  229. sta->timeout_next = STA_DISASSOC;
  230. sta->timer.expires = jiffies + AP_DISASSOC_DELAY;
  231. } else {
  232. sta->timeout_next = STA_DEAUTH;
  233. sta->timer.expires = jiffies + AP_DEAUTH_DELAY;
  234. }
  235. add_timer(&sta->timer);
  236. }
  237. void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
  238. int resend)
  239. {
  240. u8 addr[ETH_ALEN];
  241. u16 resp;
  242. int i;
  243. PDEBUG(DEBUG_AP, "%s: Deauthenticate all stations\n", dev->name);
  244. memset(addr, 0xff, ETH_ALEN);
  245. resp = __constant_cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
  246. /* deauth message sent; try to resend it few times; the message is
  247. * broadcast, so it may be delayed until next DTIM; there is not much
  248. * else we can do at this point since the driver is going to be shut
  249. * down */
  250. for (i = 0; i < 5; i++) {
  251. prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH,
  252. (char *) &resp, 2, addr, 0);
  253. if (!resend || ap->num_sta <= 0)
  254. return;
  255. mdelay(50);
  256. }
  257. }
  258. static int ap_control_proc_read(char *page, char **start, off_t off,
  259. int count, int *eof, void *data)
  260. {
  261. char *p = page;
  262. struct ap_data *ap = (struct ap_data *) data;
  263. char *policy_txt;
  264. struct list_head *ptr;
  265. struct mac_entry *entry;
  266. if (off != 0) {
  267. *eof = 1;
  268. return 0;
  269. }
  270. switch (ap->mac_restrictions.policy) {
  271. case MAC_POLICY_OPEN:
  272. policy_txt = "open";
  273. break;
  274. case MAC_POLICY_ALLOW:
  275. policy_txt = "allow";
  276. break;
  277. case MAC_POLICY_DENY:
  278. policy_txt = "deny";
  279. break;
  280. default:
  281. policy_txt = "unknown";
  282. break;
  283. };
  284. p += sprintf(p, "MAC policy: %s\n", policy_txt);
  285. p += sprintf(p, "MAC entries: %u\n", ap->mac_restrictions.entries);
  286. p += sprintf(p, "MAC list:\n");
  287. spin_lock_bh(&ap->mac_restrictions.lock);
  288. for (ptr = ap->mac_restrictions.mac_list.next;
  289. ptr != &ap->mac_restrictions.mac_list; ptr = ptr->next) {
  290. if (p - page > PAGE_SIZE - 80) {
  291. p += sprintf(p, "All entries did not fit one page.\n");
  292. break;
  293. }
  294. entry = list_entry(ptr, struct mac_entry, list);
  295. p += sprintf(p, MACSTR "\n", MAC2STR(entry->addr));
  296. }
  297. spin_unlock_bh(&ap->mac_restrictions.lock);
  298. return (p - page);
  299. }
  300. static int ap_control_add_mac(struct mac_restrictions *mac_restrictions,
  301. u8 *mac)
  302. {
  303. struct mac_entry *entry;
  304. entry = kmalloc(sizeof(struct mac_entry), GFP_KERNEL);
  305. if (entry == NULL)
  306. return -1;
  307. memcpy(entry->addr, mac, ETH_ALEN);
  308. spin_lock_bh(&mac_restrictions->lock);
  309. list_add_tail(&entry->list, &mac_restrictions->mac_list);
  310. mac_restrictions->entries++;
  311. spin_unlock_bh(&mac_restrictions->lock);
  312. return 0;
  313. }
  314. static int ap_control_del_mac(struct mac_restrictions *mac_restrictions,
  315. u8 *mac)
  316. {
  317. struct list_head *ptr;
  318. struct mac_entry *entry;
  319. spin_lock_bh(&mac_restrictions->lock);
  320. for (ptr = mac_restrictions->mac_list.next;
  321. ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
  322. entry = list_entry(ptr, struct mac_entry, list);
  323. if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
  324. list_del(ptr);
  325. kfree(entry);
  326. mac_restrictions->entries--;
  327. spin_unlock_bh(&mac_restrictions->lock);
  328. return 0;
  329. }
  330. }
  331. spin_unlock_bh(&mac_restrictions->lock);
  332. return -1;
  333. }
  334. static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
  335. u8 *mac)
  336. {
  337. struct list_head *ptr;
  338. struct mac_entry *entry;
  339. int found = 0;
  340. if (mac_restrictions->policy == MAC_POLICY_OPEN)
  341. return 0;
  342. spin_lock_bh(&mac_restrictions->lock);
  343. for (ptr = mac_restrictions->mac_list.next;
  344. ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
  345. entry = list_entry(ptr, struct mac_entry, list);
  346. if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
  347. found = 1;
  348. break;
  349. }
  350. }
  351. spin_unlock_bh(&mac_restrictions->lock);
  352. if (mac_restrictions->policy == MAC_POLICY_ALLOW)
  353. return !found;
  354. else
  355. return found;
  356. }
  357. static void ap_control_flush_macs(struct mac_restrictions *mac_restrictions)
  358. {
  359. struct list_head *ptr, *n;
  360. struct mac_entry *entry;
  361. if (mac_restrictions->entries == 0)
  362. return;
  363. spin_lock_bh(&mac_restrictions->lock);
  364. for (ptr = mac_restrictions->mac_list.next, n = ptr->next;
  365. ptr != &mac_restrictions->mac_list;
  366. ptr = n, n = ptr->next) {
  367. entry = list_entry(ptr, struct mac_entry, list);
  368. list_del(ptr);
  369. kfree(entry);
  370. }
  371. mac_restrictions->entries = 0;
  372. spin_unlock_bh(&mac_restrictions->lock);
  373. }
  374. static int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev,
  375. u8 *mac)
  376. {
  377. struct sta_info *sta;
  378. u16 resp;
  379. spin_lock_bh(&ap->sta_table_lock);
  380. sta = ap_get_sta(ap, mac);
  381. if (sta) {
  382. ap_sta_hash_del(ap, sta);
  383. list_del(&sta->list);
  384. }
  385. spin_unlock_bh(&ap->sta_table_lock);
  386. if (!sta)
  387. return -EINVAL;
  388. resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
  389. prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH,
  390. (char *) &resp, 2, sta->addr, 0);
  391. if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
  392. hostap_event_expired_sta(dev, sta);
  393. ap_free_sta(ap, sta);
  394. return 0;
  395. }
  396. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  397. static void ap_control_kickall(struct ap_data *ap)
  398. {
  399. struct list_head *ptr, *n;
  400. struct sta_info *sta;
  401. spin_lock_bh(&ap->sta_table_lock);
  402. for (ptr = ap->sta_list.next, n = ptr->next; ptr != &ap->sta_list;
  403. ptr = n, n = ptr->next) {
  404. sta = list_entry(ptr, struct sta_info, list);
  405. ap_sta_hash_del(ap, sta);
  406. list_del(&sta->list);
  407. if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
  408. hostap_event_expired_sta(sta->local->dev, sta);
  409. ap_free_sta(ap, sta);
  410. }
  411. spin_unlock_bh(&ap->sta_table_lock);
  412. }
  413. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  414. #define PROC_LIMIT (PAGE_SIZE - 80)
  415. static int prism2_ap_proc_read(char *page, char **start, off_t off,
  416. int count, int *eof, void *data)
  417. {
  418. char *p = page;
  419. struct ap_data *ap = (struct ap_data *) data;
  420. struct list_head *ptr;
  421. int i;
  422. if (off > PROC_LIMIT) {
  423. *eof = 1;
  424. return 0;
  425. }
  426. p += sprintf(p, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
  427. spin_lock_bh(&ap->sta_table_lock);
  428. for (ptr = ap->sta_list.next; ptr != &ap->sta_list; ptr = ptr->next) {
  429. struct sta_info *sta = (struct sta_info *) ptr;
  430. if (!sta->ap)
  431. continue;
  432. p += sprintf(p, MACSTR " %d %d %d %d '", MAC2STR(sta->addr),
  433. sta->u.ap.channel, sta->last_rx_signal,
  434. sta->last_rx_silence, sta->last_rx_rate);
  435. for (i = 0; i < sta->u.ap.ssid_len; i++)
  436. p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
  437. sta->u.ap.ssid[i] < 127) ?
  438. "%c" : "<%02x>"),
  439. sta->u.ap.ssid[i]);
  440. p += sprintf(p, "'");
  441. if (sta->capability & WLAN_CAPABILITY_ESS)
  442. p += sprintf(p, " [ESS]");
  443. if (sta->capability & WLAN_CAPABILITY_IBSS)
  444. p += sprintf(p, " [IBSS]");
  445. if (sta->capability & WLAN_CAPABILITY_PRIVACY)
  446. p += sprintf(p, " [WEP]");
  447. p += sprintf(p, "\n");
  448. if ((p - page) > PROC_LIMIT) {
  449. printk(KERN_DEBUG "hostap: ap proc did not fit\n");
  450. break;
  451. }
  452. }
  453. spin_unlock_bh(&ap->sta_table_lock);
  454. if ((p - page) <= off) {
  455. *eof = 1;
  456. return 0;
  457. }
  458. *start = page + off;
  459. return (p - page - off);
  460. }
  461. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  462. void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver)
  463. {
  464. if (!ap)
  465. return;
  466. if (sta_fw_ver == PRISM2_FW_VER(0,8,0)) {
  467. PDEBUG(DEBUG_AP, "Using data::nullfunc ACK workaround - "
  468. "firmware upgrade recommended\n");
  469. ap->nullfunc_ack = 1;
  470. } else
  471. ap->nullfunc_ack = 0;
  472. if (sta_fw_ver == PRISM2_FW_VER(1,4,2)) {
  473. printk(KERN_WARNING "%s: Warning: secondary station firmware "
  474. "version 1.4.2 does not seem to work in Host AP mode\n",
  475. ap->local->dev->name);
  476. }
  477. }
  478. /* Called only as a tasklet (software IRQ) */
  479. static void hostap_ap_tx_cb(struct sk_buff *skb, int ok, void *data)
  480. {
  481. struct ap_data *ap = data;
  482. u16 fc;
  483. struct hostap_ieee80211_hdr *hdr;
  484. if (!ap->local->hostapd || !ap->local->apdev) {
  485. dev_kfree_skb(skb);
  486. return;
  487. }
  488. hdr = (struct hostap_ieee80211_hdr *) skb->data;
  489. fc = le16_to_cpu(hdr->frame_control);
  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. fc &= ~WLAN_FC_PVER;
  493. fc |= ok ? BIT(1) : BIT(0);
  494. hdr->frame_control = cpu_to_le16(fc);
  495. skb->dev = ap->local->apdev;
  496. skb_pull(skb, hostap_80211_get_hdrlen(fc));
  497. skb->pkt_type = PACKET_OTHERHOST;
  498. skb->protocol = __constant_htons(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 hostap_ieee80211_hdr *hdr;
  509. u16 fc, *pos, auth_alg, auth_transaction, status;
  510. struct sta_info *sta = NULL;
  511. char *txt = NULL;
  512. if (ap->local->hostapd) {
  513. dev_kfree_skb(skb);
  514. return;
  515. }
  516. hdr = (struct hostap_ieee80211_hdr *) skb->data;
  517. fc = le16_to_cpu(hdr->frame_control);
  518. if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
  519. WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_AUTH ||
  520. skb->len < IEEE80211_MGMT_HDR_LEN + 6) {
  521. printk(KERN_DEBUG "%s: hostap_ap_tx_cb_auth received invalid "
  522. "frame\n", dev->name);
  523. dev_kfree_skb(skb);
  524. return;
  525. }
  526. pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
  527. auth_alg = le16_to_cpu(*pos++);
  528. auth_transaction = le16_to_cpu(*pos++);
  529. status = le16_to_cpu(*pos++);
  530. if (!ok) {
  531. txt = "frame was not ACKed";
  532. goto done;
  533. }
  534. spin_lock(&ap->sta_table_lock);
  535. sta = ap_get_sta(ap, hdr->addr1);
  536. if (sta)
  537. atomic_inc(&sta->users);
  538. spin_unlock(&ap->sta_table_lock);
  539. if (!sta) {
  540. txt = "STA not found";
  541. goto done;
  542. }
  543. if (status == WLAN_STATUS_SUCCESS &&
  544. ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
  545. (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
  546. txt = "STA authenticated";
  547. sta->flags |= WLAN_STA_AUTH;
  548. sta->last_auth = jiffies;
  549. } else if (status != WLAN_STATUS_SUCCESS)
  550. txt = "authentication failed";
  551. done:
  552. if (sta)
  553. atomic_dec(&sta->users);
  554. if (txt) {
  555. PDEBUG(DEBUG_AP, "%s: " MACSTR " auth_cb - alg=%d trans#=%d "
  556. "status=%d - %s\n",
  557. dev->name, MAC2STR(hdr->addr1), auth_alg,
  558. auth_transaction, status, txt);
  559. }
  560. dev_kfree_skb(skb);
  561. }
  562. /* Called only as a tasklet (software IRQ) */
  563. static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
  564. {
  565. struct ap_data *ap = data;
  566. struct net_device *dev = ap->local->dev;
  567. struct hostap_ieee80211_hdr *hdr;
  568. u16 fc, *pos, status;
  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 hostap_ieee80211_hdr *) skb->data;
  576. fc = le16_to_cpu(hdr->frame_control);
  577. if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
  578. (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ASSOC_RESP &&
  579. WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_REASSOC_RESP) ||
  580. skb->len < IEEE80211_MGMT_HDR_LEN + 4) {
  581. printk(KERN_DEBUG "%s: hostap_ap_tx_cb_assoc received invalid "
  582. "frame\n", dev->name);
  583. dev_kfree_skb(skb);
  584. return;
  585. }
  586. if (!ok) {
  587. txt = "frame was not ACKed";
  588. goto done;
  589. }
  590. spin_lock(&ap->sta_table_lock);
  591. sta = ap_get_sta(ap, hdr->addr1);
  592. if (sta)
  593. atomic_inc(&sta->users);
  594. spin_unlock(&ap->sta_table_lock);
  595. if (!sta) {
  596. txt = "STA not found";
  597. goto done;
  598. }
  599. pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
  600. pos++;
  601. status = le16_to_cpu(*pos++);
  602. if (status == WLAN_STATUS_SUCCESS) {
  603. if (!(sta->flags & WLAN_STA_ASSOC))
  604. hostap_event_new_sta(dev, sta);
  605. txt = "STA associated";
  606. sta->flags |= WLAN_STA_ASSOC;
  607. sta->last_assoc = jiffies;
  608. } else
  609. txt = "association failed";
  610. done:
  611. if (sta)
  612. atomic_dec(&sta->users);
  613. if (txt) {
  614. PDEBUG(DEBUG_AP, "%s: " MACSTR " assoc_cb - %s\n",
  615. dev->name, MAC2STR(hdr->addr1), txt);
  616. }
  617. dev_kfree_skb(skb);
  618. }
  619. /* Called only as a tasklet (software IRQ); TX callback for poll frames used
  620. * in verifying whether the STA is still present. */
  621. static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data)
  622. {
  623. struct ap_data *ap = data;
  624. struct hostap_ieee80211_hdr *hdr;
  625. struct sta_info *sta;
  626. if (skb->len < 24)
  627. goto fail;
  628. hdr = (struct hostap_ieee80211_hdr *) skb->data;
  629. if (ok) {
  630. spin_lock(&ap->sta_table_lock);
  631. sta = ap_get_sta(ap, hdr->addr1);
  632. if (sta)
  633. sta->flags &= ~WLAN_STA_PENDING_POLL;
  634. spin_unlock(&ap->sta_table_lock);
  635. } else {
  636. PDEBUG(DEBUG_AP, "%s: STA " MACSTR " did not ACK activity "
  637. "poll frame\n", ap->local->dev->name,
  638. MAC2STR(hdr->addr1));
  639. }
  640. fail:
  641. dev_kfree_skb(skb);
  642. }
  643. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  644. void hostap_init_data(local_info_t *local)
  645. {
  646. struct ap_data *ap = local->ap;
  647. if (ap == NULL) {
  648. printk(KERN_WARNING "hostap_init_data: ap == NULL\n");
  649. return;
  650. }
  651. memset(ap, 0, sizeof(struct ap_data));
  652. ap->local = local;
  653. ap->ap_policy = GET_INT_PARM(other_ap_policy, local->card_idx);
  654. ap->bridge_packets = GET_INT_PARM(ap_bridge_packets, local->card_idx);
  655. ap->max_inactivity =
  656. GET_INT_PARM(ap_max_inactivity, local->card_idx) * HZ;
  657. ap->autom_ap_wds = GET_INT_PARM(autom_ap_wds, local->card_idx);
  658. spin_lock_init(&ap->sta_table_lock);
  659. INIT_LIST_HEAD(&ap->sta_list);
  660. /* Initialize task queue structure for AP management */
  661. INIT_WORK(&local->ap->add_sta_proc_queue, handle_add_proc_queue, ap);
  662. ap->tx_callback_idx =
  663. hostap_tx_callback_register(local, hostap_ap_tx_cb, ap);
  664. if (ap->tx_callback_idx == 0)
  665. printk(KERN_WARNING "%s: failed to register TX callback for "
  666. "AP\n", local->dev->name);
  667. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  668. INIT_WORK(&local->ap->wds_oper_queue, handle_wds_oper_queue, local);
  669. ap->tx_callback_auth =
  670. hostap_tx_callback_register(local, hostap_ap_tx_cb_auth, ap);
  671. ap->tx_callback_assoc =
  672. hostap_tx_callback_register(local, hostap_ap_tx_cb_assoc, ap);
  673. ap->tx_callback_poll =
  674. hostap_tx_callback_register(local, hostap_ap_tx_cb_poll, ap);
  675. if (ap->tx_callback_auth == 0 || ap->tx_callback_assoc == 0 ||
  676. ap->tx_callback_poll == 0)
  677. printk(KERN_WARNING "%s: failed to register TX callback for "
  678. "AP\n", local->dev->name);
  679. spin_lock_init(&ap->mac_restrictions.lock);
  680. INIT_LIST_HEAD(&ap->mac_restrictions.mac_list);
  681. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  682. ap->initialized = 1;
  683. }
  684. void hostap_init_ap_proc(local_info_t *local)
  685. {
  686. struct ap_data *ap = local->ap;
  687. ap->proc = local->proc;
  688. if (ap->proc == NULL)
  689. return;
  690. #ifndef PRISM2_NO_PROCFS_DEBUG
  691. create_proc_read_entry("ap_debug", 0, ap->proc,
  692. ap_debug_proc_read, ap);
  693. #endif /* PRISM2_NO_PROCFS_DEBUG */
  694. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  695. create_proc_read_entry("ap_control", 0, ap->proc,
  696. ap_control_proc_read, ap);
  697. create_proc_read_entry("ap", 0, ap->proc,
  698. prism2_ap_proc_read, ap);
  699. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  700. }
  701. void hostap_free_data(struct ap_data *ap)
  702. {
  703. struct list_head *n, *ptr;
  704. if (ap == NULL || !ap->initialized) {
  705. printk(KERN_DEBUG "hostap_free_data: ap has not yet been "
  706. "initialized - skip resource freeing\n");
  707. return;
  708. }
  709. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  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_safe(ptr, n, &ap->sta_list) {
  715. struct sta_info *sta = list_entry(ptr, struct sta_info, list);
  716. ap_sta_hash_del(ap, sta);
  717. list_del(&sta->list);
  718. if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
  719. hostap_event_expired_sta(sta->local->dev, sta);
  720. ap_free_sta(ap, sta);
  721. }
  722. #ifndef PRISM2_NO_PROCFS_DEBUG
  723. if (ap->proc != NULL) {
  724. remove_proc_entry("ap_debug", ap->proc);
  725. }
  726. #endif /* PRISM2_NO_PROCFS_DEBUG */
  727. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  728. if (ap->proc != NULL) {
  729. remove_proc_entry("ap", ap->proc);
  730. remove_proc_entry("ap_control", ap->proc);
  731. }
  732. ap_control_flush_macs(&ap->mac_restrictions);
  733. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  734. ap->initialized = 0;
  735. }
  736. /* caller should have mutex for AP STA list handling */
  737. static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta)
  738. {
  739. struct sta_info *s;
  740. s = ap->sta_hash[STA_HASH(sta)];
  741. while (s != NULL && memcmp(s->addr, sta, ETH_ALEN) != 0)
  742. s = s->hnext;
  743. return s;
  744. }
  745. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  746. /* Called from timer handler and from scheduled AP queue handlers */
  747. static void prism2_send_mgmt(struct net_device *dev,
  748. int type, int subtype, char *body,
  749. int body_len, u8 *addr, u16 tx_cb_idx)
  750. {
  751. struct hostap_interface *iface;
  752. local_info_t *local;
  753. struct hostap_ieee80211_hdr *hdr;
  754. u16 fc;
  755. struct sk_buff *skb;
  756. struct hostap_skb_tx_data *meta;
  757. int hdrlen;
  758. iface = netdev_priv(dev);
  759. local = iface->local;
  760. dev = local->dev; /* always use master radio device */
  761. iface = netdev_priv(dev);
  762. if (!(dev->flags & IFF_UP)) {
  763. PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt - device is not UP - "
  764. "cannot send frame\n", dev->name);
  765. return;
  766. }
  767. skb = dev_alloc_skb(sizeof(*hdr) + body_len);
  768. if (skb == NULL) {
  769. PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt failed to allocate "
  770. "skb\n", dev->name);
  771. return;
  772. }
  773. fc = (type << 2) | (subtype << 4);
  774. hdrlen = hostap_80211_get_hdrlen(fc);
  775. hdr = (struct hostap_ieee80211_hdr *) skb_put(skb, hdrlen);
  776. if (body)
  777. memcpy(skb_put(skb, body_len), body, body_len);
  778. memset(hdr, 0, hdrlen);
  779. /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
  780. * tx_control instead of using local->tx_control */
  781. memcpy(hdr->addr1, addr, ETH_ALEN); /* DA / RA */
  782. if (type == WLAN_FC_TYPE_DATA) {
  783. fc |= WLAN_FC_FROMDS;
  784. memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* BSSID */
  785. memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* SA */
  786. } else if (type == WLAN_FC_TYPE_CTRL) {
  787. /* control:ACK does not have addr2 or addr3 */
  788. memset(hdr->addr2, 0, ETH_ALEN);
  789. memset(hdr->addr3, 0, ETH_ALEN);
  790. } else {
  791. memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* SA */
  792. memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* BSSID */
  793. }
  794. hdr->frame_control = cpu_to_le16(fc);
  795. meta = (struct hostap_skb_tx_data *) skb->cb;
  796. memset(meta, 0, sizeof(*meta));
  797. meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
  798. meta->iface = iface;
  799. meta->tx_cb_idx = tx_cb_idx;
  800. skb->dev = dev;
  801. skb->mac.raw = skb->nh.raw = skb->data;
  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=" MACSTR "\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. MAC2STR(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(void *data)
  874. {
  875. struct ap_data *ap = (struct ap_data *) data;
  876. struct sta_info *sta;
  877. char name[20];
  878. struct add_sta_proc_data *entry, *prev;
  879. entry = ap->add_sta_proc_entries;
  880. ap->add_sta_proc_entries = NULL;
  881. while (entry) {
  882. spin_lock_bh(&ap->sta_table_lock);
  883. sta = ap_get_sta(ap, entry->addr);
  884. if (sta)
  885. atomic_inc(&sta->users);
  886. spin_unlock_bh(&ap->sta_table_lock);
  887. if (sta) {
  888. sprintf(name, MACSTR, MAC2STR(sta->addr));
  889. sta->proc = create_proc_read_entry(
  890. name, 0, ap->proc,
  891. prism2_sta_proc_read, sta);
  892. atomic_dec(&sta->users);
  893. }
  894. prev = entry;
  895. entry = entry->next;
  896. kfree(prev);
  897. }
  898. }
  899. static struct sta_info * ap_add_sta(struct ap_data *ap, u8 *addr)
  900. {
  901. struct sta_info *sta;
  902. sta = (struct sta_info *)
  903. kmalloc(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. memset(sta, 0, sizeof(struct sta_info));
  910. sta->local = ap->local;
  911. skb_queue_head_init(&sta->tx_buf);
  912. memcpy(sta->addr, addr, ETH_ALEN);
  913. atomic_inc(&sta->users);
  914. spin_lock_bh(&ap->sta_table_lock);
  915. list_add(&sta->list, &ap->sta_list);
  916. ap->num_sta++;
  917. ap_sta_hash_add(ap, sta);
  918. spin_unlock_bh(&ap->sta_table_lock);
  919. if (ap->proc) {
  920. struct add_sta_proc_data *entry;
  921. /* schedule a non-interrupt context process to add a procfs
  922. * entry for the STA since procfs code use GFP_KERNEL */
  923. entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
  924. if (entry) {
  925. memcpy(entry->addr, sta->addr, ETH_ALEN);
  926. entry->next = ap->add_sta_proc_entries;
  927. ap->add_sta_proc_entries = entry;
  928. schedule_work(&ap->add_sta_proc_queue);
  929. } else
  930. printk(KERN_DEBUG "Failed to add STA proc data\n");
  931. }
  932. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  933. init_timer(&sta->timer);
  934. sta->timer.expires = jiffies + ap->max_inactivity;
  935. sta->timer.data = (unsigned long) sta;
  936. sta->timer.function = ap_handle_timer;
  937. if (!ap->local->hostapd)
  938. add_timer(&sta->timer);
  939. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  940. return sta;
  941. }
  942. static int ap_tx_rate_ok(int rateidx, struct sta_info *sta,
  943. local_info_t *local)
  944. {
  945. if (rateidx > sta->tx_max_rate ||
  946. !(sta->tx_supp_rates & (1 << rateidx)))
  947. return 0;
  948. if (local->tx_rate_control != 0 &&
  949. !(local->tx_rate_control & (1 << rateidx)))
  950. return 0;
  951. return 1;
  952. }
  953. static void prism2_check_tx_rates(struct sta_info *sta)
  954. {
  955. int i;
  956. sta->tx_supp_rates = 0;
  957. for (i = 0; i < sizeof(sta->supported_rates); i++) {
  958. if ((sta->supported_rates[i] & 0x7f) == 2)
  959. sta->tx_supp_rates |= WLAN_RATE_1M;
  960. if ((sta->supported_rates[i] & 0x7f) == 4)
  961. sta->tx_supp_rates |= WLAN_RATE_2M;
  962. if ((sta->supported_rates[i] & 0x7f) == 11)
  963. sta->tx_supp_rates |= WLAN_RATE_5M5;
  964. if ((sta->supported_rates[i] & 0x7f) == 22)
  965. sta->tx_supp_rates |= WLAN_RATE_11M;
  966. }
  967. sta->tx_max_rate = sta->tx_rate = sta->tx_rate_idx = 0;
  968. if (sta->tx_supp_rates & WLAN_RATE_1M) {
  969. sta->tx_max_rate = 0;
  970. if (ap_tx_rate_ok(0, sta, sta->local)) {
  971. sta->tx_rate = 10;
  972. sta->tx_rate_idx = 0;
  973. }
  974. }
  975. if (sta->tx_supp_rates & WLAN_RATE_2M) {
  976. sta->tx_max_rate = 1;
  977. if (ap_tx_rate_ok(1, sta, sta->local)) {
  978. sta->tx_rate = 20;
  979. sta->tx_rate_idx = 1;
  980. }
  981. }
  982. if (sta->tx_supp_rates & WLAN_RATE_5M5) {
  983. sta->tx_max_rate = 2;
  984. if (ap_tx_rate_ok(2, sta, sta->local)) {
  985. sta->tx_rate = 55;
  986. sta->tx_rate_idx = 2;
  987. }
  988. }
  989. if (sta->tx_supp_rates & WLAN_RATE_11M) {
  990. sta->tx_max_rate = 3;
  991. if (ap_tx_rate_ok(3, sta, sta->local)) {
  992. sta->tx_rate = 110;
  993. sta->tx_rate_idx = 3;
  994. }
  995. }
  996. }
  997. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  998. static void ap_crypt_init(struct ap_data *ap)
  999. {
  1000. ap->crypt = hostap_get_crypto_ops("WEP");
  1001. if (ap->crypt) {
  1002. if (ap->crypt->init) {
  1003. ap->crypt_priv = ap->crypt->init(0);
  1004. if (ap->crypt_priv == NULL)
  1005. ap->crypt = NULL;
  1006. else {
  1007. u8 key[WEP_KEY_LEN];
  1008. get_random_bytes(key, WEP_KEY_LEN);
  1009. ap->crypt->set_key(key, WEP_KEY_LEN, NULL,
  1010. ap->crypt_priv);
  1011. }
  1012. }
  1013. }
  1014. if (ap->crypt == NULL) {
  1015. printk(KERN_WARNING "AP could not initialize WEP: load module "
  1016. "hostap_crypt_wep.o\n");
  1017. }
  1018. }
  1019. /* Generate challenge data for shared key authentication. IEEE 802.11 specifies
  1020. * that WEP algorithm is used for generating challange. This should be unique,
  1021. * but otherwise there is not really need for randomness etc. Initialize WEP
  1022. * with pseudo random key and then use increasing IV to get unique challenge
  1023. * streams.
  1024. *
  1025. * Called only as a scheduled task for pending AP frames.
  1026. */
  1027. static char * ap_auth_make_challenge(struct ap_data *ap)
  1028. {
  1029. char *tmpbuf;
  1030. struct sk_buff *skb;
  1031. if (ap->crypt == NULL) {
  1032. ap_crypt_init(ap);
  1033. if (ap->crypt == NULL)
  1034. return NULL;
  1035. }
  1036. tmpbuf = (char *) kmalloc(WLAN_AUTH_CHALLENGE_LEN, GFP_ATOMIC);
  1037. if (tmpbuf == NULL) {
  1038. PDEBUG(DEBUG_AP, "AP: kmalloc failed for challenge\n");
  1039. return NULL;
  1040. }
  1041. skb = dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN +
  1042. ap->crypt->extra_prefix_len +
  1043. ap->crypt->extra_postfix_len);
  1044. if (skb == NULL) {
  1045. kfree(tmpbuf);
  1046. return NULL;
  1047. }
  1048. skb_reserve(skb, ap->crypt->extra_prefix_len);
  1049. memset(skb_put(skb, WLAN_AUTH_CHALLENGE_LEN), 0,
  1050. WLAN_AUTH_CHALLENGE_LEN);
  1051. if (ap->crypt->encrypt_mpdu(skb, 0, ap->crypt_priv)) {
  1052. dev_kfree_skb(skb);
  1053. kfree(tmpbuf);
  1054. return NULL;
  1055. }
  1056. memcpy(tmpbuf, skb->data + ap->crypt->extra_prefix_len,
  1057. WLAN_AUTH_CHALLENGE_LEN);
  1058. dev_kfree_skb(skb);
  1059. return tmpbuf;
  1060. }
  1061. /* Called only as a scheduled task for pending AP frames. */
  1062. static void handle_authen(local_info_t *local, struct sk_buff *skb,
  1063. struct hostap_80211_rx_status *rx_stats)
  1064. {
  1065. struct net_device *dev = local->dev;
  1066. struct hostap_ieee80211_hdr *hdr =
  1067. (struct hostap_ieee80211_hdr *) skb->data;
  1068. size_t hdrlen;
  1069. struct ap_data *ap = local->ap;
  1070. char body[8 + WLAN_AUTH_CHALLENGE_LEN], *challenge = NULL;
  1071. int len, olen;
  1072. u16 auth_alg, auth_transaction, status_code, *pos;
  1073. u16 resp = WLAN_STATUS_SUCCESS, fc;
  1074. struct sta_info *sta = NULL;
  1075. struct prism2_crypt_data *crypt;
  1076. char *txt = "";
  1077. len = skb->len - IEEE80211_MGMT_HDR_LEN;
  1078. fc = le16_to_cpu(hdr->frame_control);
  1079. hdrlen = hostap_80211_get_hdrlen(fc);
  1080. if (len < 6) {
  1081. PDEBUG(DEBUG_AP, "%s: handle_authen - too short payload "
  1082. "(len=%d) from " MACSTR "\n", dev->name, len,
  1083. MAC2STR(hdr->addr2));
  1084. return;
  1085. }
  1086. spin_lock_bh(&local->ap->sta_table_lock);
  1087. sta = ap_get_sta(local->ap, hdr->addr2);
  1088. if (sta)
  1089. atomic_inc(&sta->users);
  1090. spin_unlock_bh(&local->ap->sta_table_lock);
  1091. if (sta && sta->crypt)
  1092. crypt = sta->crypt;
  1093. else {
  1094. int idx = 0;
  1095. if (skb->len >= hdrlen + 3)
  1096. idx = skb->data[hdrlen + 3] >> 6;
  1097. crypt = local->crypt[idx];
  1098. }
  1099. pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
  1100. auth_alg = __le16_to_cpu(*pos);
  1101. pos++;
  1102. auth_transaction = __le16_to_cpu(*pos);
  1103. pos++;
  1104. status_code = __le16_to_cpu(*pos);
  1105. pos++;
  1106. if (memcmp(dev->dev_addr, hdr->addr2, ETH_ALEN) == 0 ||
  1107. ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) {
  1108. txt = "authentication denied";
  1109. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1110. goto fail;
  1111. }
  1112. if (((local->auth_algs & PRISM2_AUTH_OPEN) &&
  1113. auth_alg == WLAN_AUTH_OPEN) ||
  1114. ((local->auth_algs & PRISM2_AUTH_SHARED_KEY) &&
  1115. crypt && auth_alg == WLAN_AUTH_SHARED_KEY)) {
  1116. } else {
  1117. txt = "unsupported algorithm";
  1118. resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
  1119. goto fail;
  1120. }
  1121. if (len >= 8) {
  1122. u8 *u = (u8 *) pos;
  1123. if (*u == WLAN_EID_CHALLENGE) {
  1124. if (*(u + 1) != WLAN_AUTH_CHALLENGE_LEN) {
  1125. txt = "invalid challenge len";
  1126. resp = WLAN_STATUS_CHALLENGE_FAIL;
  1127. goto fail;
  1128. }
  1129. if (len - 8 < WLAN_AUTH_CHALLENGE_LEN) {
  1130. txt = "challenge underflow";
  1131. resp = WLAN_STATUS_CHALLENGE_FAIL;
  1132. goto fail;
  1133. }
  1134. challenge = (char *) (u + 2);
  1135. }
  1136. }
  1137. if (sta && sta->ap) {
  1138. if (time_after(jiffies, sta->u.ap.last_beacon +
  1139. (10 * sta->listen_interval * HZ) / 1024)) {
  1140. PDEBUG(DEBUG_AP, "%s: no beacons received for a while,"
  1141. " assuming AP " MACSTR " is now STA\n",
  1142. dev->name, MAC2STR(sta->addr));
  1143. sta->ap = 0;
  1144. sta->flags = 0;
  1145. sta->u.sta.challenge = NULL;
  1146. } else {
  1147. txt = "AP trying to authenticate?";
  1148. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1149. goto fail;
  1150. }
  1151. }
  1152. if ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) ||
  1153. (auth_alg == WLAN_AUTH_SHARED_KEY &&
  1154. (auth_transaction == 1 ||
  1155. (auth_transaction == 3 && sta != NULL &&
  1156. sta->u.sta.challenge != NULL)))) {
  1157. } else {
  1158. txt = "unknown authentication transaction number";
  1159. resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
  1160. goto fail;
  1161. }
  1162. if (sta == NULL) {
  1163. txt = "new STA";
  1164. if (local->ap->num_sta >= MAX_STA_COUNT) {
  1165. /* FIX: might try to remove some old STAs first? */
  1166. txt = "no more room for new STAs";
  1167. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1168. goto fail;
  1169. }
  1170. sta = ap_add_sta(local->ap, hdr->addr2);
  1171. if (sta == NULL) {
  1172. txt = "ap_add_sta failed";
  1173. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1174. goto fail;
  1175. }
  1176. }
  1177. switch (auth_alg) {
  1178. case WLAN_AUTH_OPEN:
  1179. txt = "authOK";
  1180. /* IEEE 802.11 standard is not completely clear about
  1181. * whether STA is considered authenticated after
  1182. * authentication OK frame has been send or after it
  1183. * has been ACKed. In order to reduce interoperability
  1184. * issues, mark the STA authenticated before ACK. */
  1185. sta->flags |= WLAN_STA_AUTH;
  1186. break;
  1187. case WLAN_AUTH_SHARED_KEY:
  1188. if (auth_transaction == 1) {
  1189. if (sta->u.sta.challenge == NULL) {
  1190. sta->u.sta.challenge =
  1191. ap_auth_make_challenge(local->ap);
  1192. if (sta->u.sta.challenge == NULL) {
  1193. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1194. goto fail;
  1195. }
  1196. }
  1197. } else {
  1198. if (sta->u.sta.challenge == NULL ||
  1199. challenge == NULL ||
  1200. memcmp(sta->u.sta.challenge, challenge,
  1201. WLAN_AUTH_CHALLENGE_LEN) != 0 ||
  1202. !(fc & WLAN_FC_ISWEP)) {
  1203. txt = "challenge response incorrect";
  1204. resp = WLAN_STATUS_CHALLENGE_FAIL;
  1205. goto fail;
  1206. }
  1207. txt = "challenge OK - authOK";
  1208. /* IEEE 802.11 standard is not completely clear about
  1209. * whether STA is considered authenticated after
  1210. * authentication OK frame has been send or after it
  1211. * has been ACKed. In order to reduce interoperability
  1212. * issues, mark the STA authenticated before ACK. */
  1213. sta->flags |= WLAN_STA_AUTH;
  1214. kfree(sta->u.sta.challenge);
  1215. sta->u.sta.challenge = NULL;
  1216. }
  1217. break;
  1218. }
  1219. fail:
  1220. pos = (u16 *) body;
  1221. *pos = cpu_to_le16(auth_alg);
  1222. pos++;
  1223. *pos = cpu_to_le16(auth_transaction + 1);
  1224. pos++;
  1225. *pos = cpu_to_le16(resp); /* status_code */
  1226. pos++;
  1227. olen = 6;
  1228. if (resp == WLAN_STATUS_SUCCESS && sta != NULL &&
  1229. sta->u.sta.challenge != NULL &&
  1230. auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 1) {
  1231. u8 *tmp = (u8 *) pos;
  1232. *tmp++ = WLAN_EID_CHALLENGE;
  1233. *tmp++ = WLAN_AUTH_CHALLENGE_LEN;
  1234. pos++;
  1235. memcpy(pos, sta->u.sta.challenge, WLAN_AUTH_CHALLENGE_LEN);
  1236. olen += 2 + WLAN_AUTH_CHALLENGE_LEN;
  1237. }
  1238. prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_AUTH,
  1239. body, olen, hdr->addr2, ap->tx_callback_auth);
  1240. if (sta) {
  1241. sta->last_rx = jiffies;
  1242. atomic_dec(&sta->users);
  1243. }
  1244. if (resp) {
  1245. PDEBUG(DEBUG_AP, "%s: " MACSTR " auth (alg=%d trans#=%d "
  1246. "stat=%d len=%d fc=%04x) ==> %d (%s)\n",
  1247. dev->name, MAC2STR(hdr->addr2), auth_alg,
  1248. auth_transaction, status_code, len, fc, resp, txt);
  1249. }
  1250. }
  1251. /* Called only as a scheduled task for pending AP frames. */
  1252. static void handle_assoc(local_info_t *local, struct sk_buff *skb,
  1253. struct hostap_80211_rx_status *rx_stats, int reassoc)
  1254. {
  1255. struct net_device *dev = local->dev;
  1256. struct hostap_ieee80211_hdr *hdr =
  1257. (struct hostap_ieee80211_hdr *) skb->data;
  1258. char body[12], *p, *lpos;
  1259. int len, left;
  1260. u16 *pos;
  1261. u16 resp = WLAN_STATUS_SUCCESS;
  1262. struct sta_info *sta = NULL;
  1263. int send_deauth = 0;
  1264. char *txt = "";
  1265. u8 prev_ap[ETH_ALEN];
  1266. left = len = skb->len - IEEE80211_MGMT_HDR_LEN;
  1267. if (len < (reassoc ? 10 : 4)) {
  1268. PDEBUG(DEBUG_AP, "%s: handle_assoc - too short payload "
  1269. "(len=%d, reassoc=%d) from " MACSTR "\n",
  1270. dev->name, len, reassoc, MAC2STR(hdr->addr2));
  1271. return;
  1272. }
  1273. spin_lock_bh(&local->ap->sta_table_lock);
  1274. sta = ap_get_sta(local->ap, hdr->addr2);
  1275. if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
  1276. spin_unlock_bh(&local->ap->sta_table_lock);
  1277. txt = "trying to associate before authentication";
  1278. send_deauth = 1;
  1279. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1280. sta = NULL; /* do not decrement sta->users */
  1281. goto fail;
  1282. }
  1283. atomic_inc(&sta->users);
  1284. spin_unlock_bh(&local->ap->sta_table_lock);
  1285. pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
  1286. sta->capability = __le16_to_cpu(*pos);
  1287. pos++; left -= 2;
  1288. sta->listen_interval = __le16_to_cpu(*pos);
  1289. pos++; left -= 2;
  1290. if (reassoc) {
  1291. memcpy(prev_ap, pos, ETH_ALEN);
  1292. pos++; pos++; pos++; left -= 6;
  1293. } else
  1294. memset(prev_ap, 0, ETH_ALEN);
  1295. if (left >= 2) {
  1296. unsigned int ileft;
  1297. unsigned char *u = (unsigned char *) pos;
  1298. if (*u == WLAN_EID_SSID) {
  1299. u++; left--;
  1300. ileft = *u;
  1301. u++; left--;
  1302. if (ileft > left || ileft > MAX_SSID_LEN) {
  1303. txt = "SSID overflow";
  1304. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1305. goto fail;
  1306. }
  1307. if (ileft != strlen(local->essid) ||
  1308. memcmp(local->essid, u, ileft) != 0) {
  1309. txt = "not our SSID";
  1310. resp = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
  1311. goto fail;
  1312. }
  1313. u += ileft;
  1314. left -= ileft;
  1315. }
  1316. if (left >= 2 && *u == WLAN_EID_SUPP_RATES) {
  1317. u++; left--;
  1318. ileft = *u;
  1319. u++; left--;
  1320. if (ileft > left || ileft == 0 ||
  1321. ileft > WLAN_SUPP_RATES_MAX) {
  1322. txt = "SUPP_RATES len error";
  1323. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1324. goto fail;
  1325. }
  1326. memset(sta->supported_rates, 0,
  1327. sizeof(sta->supported_rates));
  1328. memcpy(sta->supported_rates, u, ileft);
  1329. prism2_check_tx_rates(sta);
  1330. u += ileft;
  1331. left -= ileft;
  1332. }
  1333. if (left > 0) {
  1334. PDEBUG(DEBUG_AP, "%s: assoc from " MACSTR " with extra"
  1335. " data (%d bytes) [",
  1336. dev->name, MAC2STR(hdr->addr2), left);
  1337. while (left > 0) {
  1338. PDEBUG2(DEBUG_AP, "<%02x>", *u);
  1339. u++; left--;
  1340. }
  1341. PDEBUG2(DEBUG_AP, "]\n");
  1342. }
  1343. } else {
  1344. txt = "frame underflow";
  1345. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  1346. goto fail;
  1347. }
  1348. /* get a unique AID */
  1349. if (sta->aid > 0)
  1350. txt = "OK, old AID";
  1351. else {
  1352. spin_lock_bh(&local->ap->sta_table_lock);
  1353. for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
  1354. if (local->ap->sta_aid[sta->aid - 1] == NULL)
  1355. break;
  1356. if (sta->aid > MAX_AID_TABLE_SIZE) {
  1357. sta->aid = 0;
  1358. spin_unlock_bh(&local->ap->sta_table_lock);
  1359. resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
  1360. txt = "no room for more AIDs";
  1361. } else {
  1362. local->ap->sta_aid[sta->aid - 1] = sta;
  1363. spin_unlock_bh(&local->ap->sta_table_lock);
  1364. txt = "OK, new AID";
  1365. }
  1366. }
  1367. fail:
  1368. pos = (u16 *) body;
  1369. if (send_deauth) {
  1370. *pos = __constant_cpu_to_le16(
  1371. WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH);
  1372. pos++;
  1373. } else {
  1374. /* FIX: CF-Pollable and CF-PollReq should be set to match the
  1375. * values in beacons/probe responses */
  1376. /* FIX: how about privacy and WEP? */
  1377. /* capability */
  1378. *pos = __constant_cpu_to_le16(WLAN_CAPABILITY_ESS);
  1379. pos++;
  1380. /* status_code */
  1381. *pos = __cpu_to_le16(resp);
  1382. pos++;
  1383. *pos = __cpu_to_le16((sta && sta->aid > 0 ? sta->aid : 0) |
  1384. BIT(14) | BIT(15)); /* AID */
  1385. pos++;
  1386. /* Supported rates (Information element) */
  1387. p = (char *) pos;
  1388. *p++ = WLAN_EID_SUPP_RATES;
  1389. lpos = p;
  1390. *p++ = 0; /* len */
  1391. if (local->tx_rate_control & WLAN_RATE_1M) {
  1392. *p++ = local->basic_rates & WLAN_RATE_1M ? 0x82 : 0x02;
  1393. (*lpos)++;
  1394. }
  1395. if (local->tx_rate_control & WLAN_RATE_2M) {
  1396. *p++ = local->basic_rates & WLAN_RATE_2M ? 0x84 : 0x04;
  1397. (*lpos)++;
  1398. }
  1399. if (local->tx_rate_control & WLAN_RATE_5M5) {
  1400. *p++ = local->basic_rates & WLAN_RATE_5M5 ?
  1401. 0x8b : 0x0b;
  1402. (*lpos)++;
  1403. }
  1404. if (local->tx_rate_control & WLAN_RATE_11M) {
  1405. *p++ = local->basic_rates & WLAN_RATE_11M ?
  1406. 0x96 : 0x16;
  1407. (*lpos)++;
  1408. }
  1409. pos = (u16 *) p;
  1410. }
  1411. prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT,
  1412. (send_deauth ? WLAN_FC_STYPE_DEAUTH :
  1413. (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
  1414. WLAN_FC_STYPE_ASSOC_RESP)),
  1415. body, (u8 *) pos - (u8 *) body,
  1416. hdr->addr2,
  1417. send_deauth ? 0 : local->ap->tx_callback_assoc);
  1418. if (sta) {
  1419. if (resp == WLAN_STATUS_SUCCESS) {
  1420. sta->last_rx = jiffies;
  1421. /* STA will be marked associated from TX callback, if
  1422. * AssocResp is ACKed */
  1423. }
  1424. atomic_dec(&sta->users);
  1425. }
  1426. #if 0
  1427. PDEBUG(DEBUG_AP, "%s: " MACSTR " %sassoc (len=%d prev_ap=" MACSTR
  1428. ") => %d(%d) (%s)\n",
  1429. dev->name, MAC2STR(hdr->addr2), reassoc ? "re" : "", len,
  1430. MAC2STR(prev_ap), resp, send_deauth, txt);
  1431. #endif
  1432. }
  1433. /* Called only as a scheduled task for pending AP frames. */
  1434. static void handle_deauth(local_info_t *local, struct sk_buff *skb,
  1435. struct hostap_80211_rx_status *rx_stats)
  1436. {
  1437. struct net_device *dev = local->dev;
  1438. struct hostap_ieee80211_hdr *hdr =
  1439. (struct hostap_ieee80211_hdr *) skb->data;
  1440. char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN);
  1441. int len;
  1442. u16 reason_code, *pos;
  1443. struct sta_info *sta = NULL;
  1444. len = skb->len - IEEE80211_MGMT_HDR_LEN;
  1445. if (len < 2) {
  1446. printk("handle_deauth - too short payload (len=%d)\n", len);
  1447. return;
  1448. }
  1449. pos = (u16 *) body;
  1450. reason_code = __le16_to_cpu(*pos);
  1451. PDEBUG(DEBUG_AP, "%s: deauthentication: " MACSTR " len=%d, "
  1452. "reason_code=%d\n", dev->name, MAC2STR(hdr->addr2), len,
  1453. reason_code);
  1454. spin_lock_bh(&local->ap->sta_table_lock);
  1455. sta = ap_get_sta(local->ap, hdr->addr2);
  1456. if (sta != NULL) {
  1457. if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
  1458. hostap_event_expired_sta(local->dev, sta);
  1459. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
  1460. }
  1461. spin_unlock_bh(&local->ap->sta_table_lock);
  1462. if (sta == NULL) {
  1463. printk("%s: deauthentication from " MACSTR ", "
  1464. "reason_code=%d, but STA not authenticated\n", dev->name,
  1465. MAC2STR(hdr->addr2), reason_code);
  1466. }
  1467. }
  1468. /* Called only as a scheduled task for pending AP frames. */
  1469. static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
  1470. struct hostap_80211_rx_status *rx_stats)
  1471. {
  1472. struct net_device *dev = local->dev;
  1473. struct hostap_ieee80211_hdr *hdr =
  1474. (struct hostap_ieee80211_hdr *) skb->data;
  1475. char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
  1476. int len;
  1477. u16 reason_code, *pos;
  1478. struct sta_info *sta = NULL;
  1479. len = skb->len - IEEE80211_MGMT_HDR_LEN;
  1480. if (len < 2) {
  1481. printk("handle_disassoc - too short payload (len=%d)\n", len);
  1482. return;
  1483. }
  1484. pos = (u16 *) body;
  1485. reason_code = __le16_to_cpu(*pos);
  1486. PDEBUG(DEBUG_AP, "%s: disassociation: " MACSTR " len=%d, "
  1487. "reason_code=%d\n", dev->name, MAC2STR(hdr->addr2), len,
  1488. reason_code);
  1489. spin_lock_bh(&local->ap->sta_table_lock);
  1490. sta = ap_get_sta(local->ap, hdr->addr2);
  1491. if (sta != NULL) {
  1492. if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
  1493. hostap_event_expired_sta(local->dev, sta);
  1494. sta->flags &= ~WLAN_STA_ASSOC;
  1495. }
  1496. spin_unlock_bh(&local->ap->sta_table_lock);
  1497. if (sta == NULL) {
  1498. printk("%s: disassociation from " MACSTR ", "
  1499. "reason_code=%d, but STA not authenticated\n",
  1500. dev->name, MAC2STR(hdr->addr2), reason_code);
  1501. }
  1502. }
  1503. /* Called only as a scheduled task for pending AP frames. */
  1504. static void ap_handle_data_nullfunc(local_info_t *local,
  1505. struct hostap_ieee80211_hdr *hdr)
  1506. {
  1507. struct net_device *dev = local->dev;
  1508. /* some STA f/w's seem to require control::ACK frame for
  1509. * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
  1510. * not send this..
  1511. * send control::ACK for the data::nullfunc */
  1512. printk(KERN_DEBUG "Sending control::ACK for data::nullfunc\n");
  1513. prism2_send_mgmt(dev, WLAN_FC_TYPE_CTRL, WLAN_FC_STYPE_ACK,
  1514. NULL, 0, hdr->addr2, 0);
  1515. }
  1516. /* Called only as a scheduled task for pending AP frames. */
  1517. static void ap_handle_dropped_data(local_info_t *local,
  1518. struct hostap_ieee80211_hdr *hdr)
  1519. {
  1520. struct net_device *dev = local->dev;
  1521. struct sta_info *sta;
  1522. u16 reason;
  1523. spin_lock_bh(&local->ap->sta_table_lock);
  1524. sta = ap_get_sta(local->ap, hdr->addr2);
  1525. if (sta)
  1526. atomic_inc(&sta->users);
  1527. spin_unlock_bh(&local->ap->sta_table_lock);
  1528. if (sta != NULL && (sta->flags & WLAN_STA_ASSOC)) {
  1529. PDEBUG(DEBUG_AP, "ap_handle_dropped_data: STA is now okay?\n");
  1530. atomic_dec(&sta->users);
  1531. return;
  1532. }
  1533. reason = __constant_cpu_to_le16(
  1534. WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
  1535. prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT,
  1536. ((sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) ?
  1537. WLAN_FC_STYPE_DEAUTH : WLAN_FC_STYPE_DISASSOC),
  1538. (char *) &reason, sizeof(reason), hdr->addr2, 0);
  1539. if (sta)
  1540. atomic_dec(&sta->users);
  1541. }
  1542. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  1543. /* Called only as a scheduled task for pending AP frames. */
  1544. static void pspoll_send_buffered(local_info_t *local, struct sta_info *sta,
  1545. struct sk_buff *skb)
  1546. {
  1547. if (!(sta->flags & WLAN_STA_PS)) {
  1548. /* Station has moved to non-PS mode, so send all buffered
  1549. * frames using normal device queue. */
  1550. dev_queue_xmit(skb);
  1551. return;
  1552. }
  1553. /* add a flag for hostap_handle_sta_tx() to know that this skb should
  1554. * be passed through even though STA is using PS */
  1555. memcpy(skb->cb, AP_SKB_CB_MAGIC, AP_SKB_CB_MAGIC_LEN);
  1556. skb->cb[AP_SKB_CB_MAGIC_LEN] = AP_SKB_CB_BUFFERED_FRAME;
  1557. if (!skb_queue_empty(&sta->tx_buf)) {
  1558. /* indicate to STA that more frames follow */
  1559. skb->cb[AP_SKB_CB_MAGIC_LEN] |= AP_SKB_CB_ADD_MOREDATA;
  1560. }
  1561. dev_queue_xmit(skb);
  1562. }
  1563. /* Called only as a scheduled task for pending AP frames. */
  1564. static void handle_pspoll(local_info_t *local,
  1565. struct hostap_ieee80211_hdr *hdr,
  1566. struct hostap_80211_rx_status *rx_stats)
  1567. {
  1568. struct net_device *dev = local->dev;
  1569. struct sta_info *sta;
  1570. u16 aid;
  1571. struct sk_buff *skb;
  1572. PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=" MACSTR ", TA=" MACSTR
  1573. " PWRMGT=%d\n",
  1574. MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  1575. !!(le16_to_cpu(hdr->frame_control) & WLAN_FC_PWRMGT));
  1576. if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
  1577. PDEBUG(DEBUG_AP, "handle_pspoll - addr1(BSSID)=" MACSTR
  1578. " not own MAC\n", MAC2STR(hdr->addr1));
  1579. return;
  1580. }
  1581. aid = __le16_to_cpu(hdr->duration_id);
  1582. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
  1583. PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n");
  1584. return;
  1585. }
  1586. aid &= ~BIT(15) & ~BIT(14);
  1587. if (aid == 0 || aid > MAX_AID_TABLE_SIZE) {
  1588. PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid);
  1589. return;
  1590. }
  1591. PDEBUG(DEBUG_PS2, " aid=%d\n", aid);
  1592. spin_lock_bh(&local->ap->sta_table_lock);
  1593. sta = ap_get_sta(local->ap, hdr->addr2);
  1594. if (sta)
  1595. atomic_inc(&sta->users);
  1596. spin_unlock_bh(&local->ap->sta_table_lock);
  1597. if (sta == NULL) {
  1598. PDEBUG(DEBUG_PS, " STA not found\n");
  1599. return;
  1600. }
  1601. if (sta->aid != aid) {
  1602. PDEBUG(DEBUG_PS, " received aid=%i does not match with "
  1603. "assoc.aid=%d\n", aid, sta->aid);
  1604. return;
  1605. }
  1606. /* FIX: todo:
  1607. * - add timeout for buffering (clear aid in TIM vector if buffer timed
  1608. * out (expiry time must be longer than ListenInterval for
  1609. * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
  1610. * - what to do, if buffered, pspolled, and sent frame is not ACKed by
  1611. * sta; store buffer for later use and leave TIM aid bit set? use
  1612. * TX event to check whether frame was ACKed?
  1613. */
  1614. while ((skb = skb_dequeue(&sta->tx_buf)) != NULL) {
  1615. /* send buffered frame .. */
  1616. PDEBUG(DEBUG_PS2, "Sending buffered frame to STA after PS POLL"
  1617. " (buffer_count=%d)\n", skb_queue_len(&sta->tx_buf));
  1618. pspoll_send_buffered(local, sta, skb);
  1619. if (sta->flags & WLAN_STA_PS) {
  1620. /* send only one buffered packet per PS Poll */
  1621. /* FIX: should ignore further PS Polls until the
  1622. * buffered packet that was just sent is acknowledged
  1623. * (Tx or TxExc event) */
  1624. break;
  1625. }
  1626. }
  1627. if (skb_queue_empty(&sta->tx_buf)) {
  1628. /* try to clear aid from TIM */
  1629. if (!(sta->flags & WLAN_STA_TIM))
  1630. PDEBUG(DEBUG_PS2, "Re-unsetting TIM for aid %d\n",
  1631. aid);
  1632. hostap_set_tim(local, aid, 0);
  1633. sta->flags &= ~WLAN_STA_TIM;
  1634. }
  1635. atomic_dec(&sta->users);
  1636. }
  1637. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  1638. static void handle_wds_oper_queue(void *data)
  1639. {
  1640. local_info_t *local = data;
  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 " MACSTR "\n",
  1649. local->dev->name,
  1650. entry->type == WDS_ADD ? "adding" : "removing",
  1651. MAC2STR(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 hostap_ieee80211_hdr *hdr =
  1666. (struct hostap_ieee80211_hdr *) skb->data;
  1667. char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
  1668. int len, left;
  1669. u16 *pos, beacon_int, capability;
  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 = (u16 *) 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 hostap_ieee80211_hdr *hdr;
  1796. /* FIX: should give skb->len to handler functions and check that the
  1797. * buffer is long enough */
  1798. hdr = (struct hostap_ieee80211_hdr *) skb->data;
  1799. fc = le16_to_cpu(hdr->frame_control);
  1800. type = WLAN_FC_GET_TYPE(fc);
  1801. stype = WLAN_FC_GET_STYPE(fc);
  1802. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  1803. if (!local->hostapd && type == WLAN_FC_TYPE_DATA) {
  1804. PDEBUG(DEBUG_AP, "handle_ap_item - data frame\n");
  1805. if (!(fc & WLAN_FC_TODS) || (fc & WLAN_FC_FROMDS)) {
  1806. if (stype == WLAN_FC_STYPE_NULLFUNC) {
  1807. /* no ToDS nullfunc seems to be used to check
  1808. * AP association; so send reject message to
  1809. * speed up re-association */
  1810. ap_handle_dropped_data(local, hdr);
  1811. goto done;
  1812. }
  1813. PDEBUG(DEBUG_AP, " not ToDS frame (fc=0x%04x)\n",
  1814. fc);
  1815. goto done;
  1816. }
  1817. if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
  1818. PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)="
  1819. MACSTR " not own MAC\n",
  1820. MAC2STR(hdr->addr1));
  1821. goto done;
  1822. }
  1823. if (local->ap->nullfunc_ack && stype == WLAN_FC_STYPE_NULLFUNC)
  1824. ap_handle_data_nullfunc(local, hdr);
  1825. else
  1826. ap_handle_dropped_data(local, hdr);
  1827. goto done;
  1828. }
  1829. if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_BEACON) {
  1830. handle_beacon(local, skb, rx_stats);
  1831. goto done;
  1832. }
  1833. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  1834. if (type == WLAN_FC_TYPE_CTRL && stype == WLAN_FC_STYPE_PSPOLL) {
  1835. handle_pspoll(local, hdr, rx_stats);
  1836. goto done;
  1837. }
  1838. if (local->hostapd) {
  1839. PDEBUG(DEBUG_AP, "Unknown frame in AP queue: type=0x%02x "
  1840. "subtype=0x%02x\n", type, stype);
  1841. goto done;
  1842. }
  1843. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  1844. if (type != WLAN_FC_TYPE_MGMT) {
  1845. PDEBUG(DEBUG_AP, "handle_ap_item - not a management frame?\n");
  1846. goto done;
  1847. }
  1848. if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
  1849. PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=" MACSTR
  1850. " not own MAC\n", MAC2STR(hdr->addr1));
  1851. goto done;
  1852. }
  1853. if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN)) {
  1854. PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=" MACSTR
  1855. " not own MAC\n", MAC2STR(hdr->addr3));
  1856. goto done;
  1857. }
  1858. switch (stype) {
  1859. case WLAN_FC_STYPE_ASSOC_REQ:
  1860. handle_assoc(local, skb, rx_stats, 0);
  1861. break;
  1862. case WLAN_FC_STYPE_ASSOC_RESP:
  1863. PDEBUG(DEBUG_AP, "==> ASSOC RESP (ignored)\n");
  1864. break;
  1865. case WLAN_FC_STYPE_REASSOC_REQ:
  1866. handle_assoc(local, skb, rx_stats, 1);
  1867. break;
  1868. case WLAN_FC_STYPE_REASSOC_RESP:
  1869. PDEBUG(DEBUG_AP, "==> REASSOC RESP (ignored)\n");
  1870. break;
  1871. case WLAN_FC_STYPE_ATIM:
  1872. PDEBUG(DEBUG_AP, "==> ATIM (ignored)\n");
  1873. break;
  1874. case WLAN_FC_STYPE_DISASSOC:
  1875. handle_disassoc(local, skb, rx_stats);
  1876. break;
  1877. case WLAN_FC_STYPE_AUTH:
  1878. handle_authen(local, skb, rx_stats);
  1879. break;
  1880. case WLAN_FC_STYPE_DEAUTH:
  1881. handle_deauth(local, skb, rx_stats);
  1882. break;
  1883. default:
  1884. PDEBUG(DEBUG_AP, "Unknown mgmt frame subtype 0x%02x\n", stype);
  1885. break;
  1886. }
  1887. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  1888. done:
  1889. dev_kfree_skb(skb);
  1890. }
  1891. /* Called only as a tasklet (software IRQ) */
  1892. void hostap_rx(struct net_device *dev, struct sk_buff *skb,
  1893. struct hostap_80211_rx_status *rx_stats)
  1894. {
  1895. struct hostap_interface *iface;
  1896. local_info_t *local;
  1897. u16 fc;
  1898. struct hostap_ieee80211_hdr *hdr;
  1899. iface = netdev_priv(dev);
  1900. local = iface->local;
  1901. if (skb->len < 16)
  1902. goto drop;
  1903. local->stats.rx_packets++;
  1904. hdr = (struct hostap_ieee80211_hdr *) skb->data;
  1905. fc = le16_to_cpu(hdr->frame_control);
  1906. if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL &&
  1907. WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  1908. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  1909. goto drop;
  1910. skb->protocol = __constant_htons(ETH_P_HOSTAP);
  1911. handle_ap_item(local, skb, rx_stats);
  1912. return;
  1913. drop:
  1914. dev_kfree_skb(skb);
  1915. }
  1916. /* Called only as a tasklet (software IRQ) */
  1917. static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
  1918. {
  1919. struct sk_buff *skb;
  1920. struct hostap_ieee80211_hdr *hdr;
  1921. struct hostap_80211_rx_status rx_stats;
  1922. if (skb_queue_empty(&sta->tx_buf))
  1923. return;
  1924. skb = dev_alloc_skb(16);
  1925. if (skb == NULL) {
  1926. printk(KERN_DEBUG "%s: schedule_packet_send: skb alloc "
  1927. "failed\n", local->dev->name);
  1928. return;
  1929. }
  1930. hdr = (struct hostap_ieee80211_hdr *) skb_put(skb, 16);
  1931. /* Generate a fake pspoll frame to start packet delivery */
  1932. hdr->frame_control = __constant_cpu_to_le16(
  1933. (WLAN_FC_TYPE_CTRL << 2) | (WLAN_FC_STYPE_PSPOLL << 4));
  1934. memcpy(hdr->addr1, local->dev->dev_addr, ETH_ALEN);
  1935. memcpy(hdr->addr2, sta->addr, ETH_ALEN);
  1936. hdr->duration_id = cpu_to_le16(sta->aid | BIT(15) | BIT(14));
  1937. PDEBUG(DEBUG_PS2, "%s: Scheduling buffered packet delivery for "
  1938. "STA " MACSTR "\n", local->dev->name, MAC2STR(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. static 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 = 0;
  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 independant
  1976. * format that the Wireless Tools will understand - Jean II */
  1977. static int prism2_ap_translate_scan(struct net_device *dev, char *buffer)
  1978. {
  1979. struct hostap_interface *iface;
  1980. local_info_t *local;
  1981. struct ap_data *ap;
  1982. struct list_head *ptr;
  1983. struct iw_event iwe;
  1984. char *current_ev = buffer;
  1985. char *end_buf = buffer + IW_SCAN_MAX_DATA;
  1986. #if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
  1987. char buf[64];
  1988. #endif
  1989. iface = netdev_priv(dev);
  1990. local = iface->local;
  1991. ap = local->ap;
  1992. spin_lock_bh(&ap->sta_table_lock);
  1993. for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
  1994. ptr = ptr->next) {
  1995. struct sta_info *sta = (struct sta_info *) ptr;
  1996. /* First entry *MUST* be the AP MAC address */
  1997. memset(&iwe, 0, sizeof(iwe));
  1998. iwe.cmd = SIOCGIWAP;
  1999. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  2000. memcpy(iwe.u.ap_addr.sa_data, sta->addr, ETH_ALEN);
  2001. iwe.len = IW_EV_ADDR_LEN;
  2002. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
  2003. IW_EV_ADDR_LEN);
  2004. /* Use the mode to indicate if it's a station or
  2005. * an Access Point */
  2006. memset(&iwe, 0, sizeof(iwe));
  2007. iwe.cmd = SIOCGIWMODE;
  2008. if (sta->ap)
  2009. iwe.u.mode = IW_MODE_MASTER;
  2010. else
  2011. iwe.u.mode = IW_MODE_INFRA;
  2012. iwe.len = IW_EV_UINT_LEN;
  2013. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
  2014. IW_EV_UINT_LEN);
  2015. /* Some quality */
  2016. memset(&iwe, 0, sizeof(iwe));
  2017. iwe.cmd = IWEVQUAL;
  2018. if (sta->last_rx_silence == 0)
  2019. iwe.u.qual.qual = sta->last_rx_signal < 27 ?
  2020. 0 : (sta->last_rx_signal - 27) * 92 / 127;
  2021. else
  2022. iwe.u.qual.qual = sta->last_rx_signal -
  2023. sta->last_rx_silence - 35;
  2024. iwe.u.qual.level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
  2025. iwe.u.qual.noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
  2026. iwe.u.qual.updated = sta->last_rx_updated;
  2027. iwe.len = IW_EV_QUAL_LEN;
  2028. current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
  2029. IW_EV_QUAL_LEN);
  2030. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  2031. if (sta->ap) {
  2032. memset(&iwe, 0, sizeof(iwe));
  2033. iwe.cmd = SIOCGIWESSID;
  2034. iwe.u.data.length = sta->u.ap.ssid_len;
  2035. iwe.u.data.flags = 1;
  2036. current_ev = iwe_stream_add_point(current_ev, end_buf,
  2037. &iwe,
  2038. sta->u.ap.ssid);
  2039. memset(&iwe, 0, sizeof(iwe));
  2040. iwe.cmd = SIOCGIWENCODE;
  2041. if (sta->capability & WLAN_CAPABILITY_PRIVACY)
  2042. iwe.u.data.flags =
  2043. IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  2044. else
  2045. iwe.u.data.flags = IW_ENCODE_DISABLED;
  2046. current_ev = iwe_stream_add_point(current_ev, end_buf,
  2047. &iwe,
  2048. sta->u.ap.ssid
  2049. /* 0 byte memcpy */);
  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. 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(current_ev, end_buf,
  2067. &iwe, buf);
  2068. }
  2069. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  2070. sta->last_rx_updated = 0;
  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. static int prism2_hostapd(struct ap_data *ap,
  2178. struct prism2_hostapd_param *param)
  2179. {
  2180. switch (param->cmd) {
  2181. case PRISM2_HOSTAPD_FLUSH:
  2182. ap_control_kickall(ap);
  2183. return 0;
  2184. case PRISM2_HOSTAPD_ADD_STA:
  2185. return prism2_hostapd_add_sta(ap, param);
  2186. case PRISM2_HOSTAPD_REMOVE_STA:
  2187. return prism2_hostapd_remove_sta(ap, param);
  2188. case PRISM2_HOSTAPD_GET_INFO_STA:
  2189. return prism2_hostapd_get_info_sta(ap, param);
  2190. case PRISM2_HOSTAPD_SET_FLAGS_STA:
  2191. return prism2_hostapd_set_flags_sta(ap, param);
  2192. case PRISM2_HOSTAPD_STA_CLEAR_STATS:
  2193. return prism2_hostapd_sta_clear_stats(ap, param);
  2194. default:
  2195. printk(KERN_WARNING "prism2_hostapd: unknown cmd=%d\n",
  2196. param->cmd);
  2197. return -EOPNOTSUPP;
  2198. }
  2199. }
  2200. /* Update station info for host-based TX rate control and return current
  2201. * TX rate */
  2202. static int ap_update_sta_tx_rate(struct sta_info *sta, struct net_device *dev)
  2203. {
  2204. int ret = sta->tx_rate;
  2205. struct hostap_interface *iface;
  2206. local_info_t *local;
  2207. iface = netdev_priv(dev);
  2208. local = iface->local;
  2209. sta->tx_count[sta->tx_rate_idx]++;
  2210. sta->tx_since_last_failure++;
  2211. sta->tx_consecutive_exc = 0;
  2212. if (sta->tx_since_last_failure >= WLAN_RATE_UPDATE_COUNT &&
  2213. sta->tx_rate_idx < sta->tx_max_rate) {
  2214. /* use next higher rate */
  2215. int old_rate, new_rate;
  2216. old_rate = new_rate = sta->tx_rate_idx;
  2217. while (new_rate < sta->tx_max_rate) {
  2218. new_rate++;
  2219. if (ap_tx_rate_ok(new_rate, sta, local)) {
  2220. sta->tx_rate_idx = new_rate;
  2221. break;
  2222. }
  2223. }
  2224. if (old_rate != sta->tx_rate_idx) {
  2225. switch (sta->tx_rate_idx) {
  2226. case 0: sta->tx_rate = 10; break;
  2227. case 1: sta->tx_rate = 20; break;
  2228. case 2: sta->tx_rate = 55; break;
  2229. case 3: sta->tx_rate = 110; break;
  2230. default: sta->tx_rate = 0; break;
  2231. }
  2232. PDEBUG(DEBUG_AP, "%s: STA " MACSTR " TX rate raised to"
  2233. " %d\n", dev->name, MAC2STR(sta->addr),
  2234. sta->tx_rate);
  2235. }
  2236. sta->tx_since_last_failure = 0;
  2237. }
  2238. return ret;
  2239. }
  2240. /* Called only from software IRQ. Called for each TX frame prior possible
  2241. * encryption and transmit. */
  2242. ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
  2243. {
  2244. struct sta_info *sta = NULL;
  2245. struct sk_buff *skb = tx->skb;
  2246. int set_tim, ret;
  2247. struct hostap_ieee80211_hdr *hdr;
  2248. struct hostap_skb_tx_data *meta;
  2249. meta = (struct hostap_skb_tx_data *) skb->cb;
  2250. ret = AP_TX_CONTINUE;
  2251. if (local->ap == NULL || skb->len < 10 ||
  2252. meta->iface->type == HOSTAP_INTERFACE_STA)
  2253. goto out;
  2254. hdr = (struct hostap_ieee80211_hdr *) skb->data;
  2255. if (hdr->addr1[0] & 0x01) {
  2256. /* broadcast/multicast frame - no AP related processing */
  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 && !meta->wds &&
  2266. meta->iface->type != HOSTAP_INTERFACE_MASTER &&
  2267. meta->iface->type != HOSTAP_INTERFACE_AP) {
  2268. #if 0
  2269. /* This can happen, e.g., when wlan0 is added to a bridge and
  2270. * bridging code does not know which port is the correct target
  2271. * for a unicast frame. In this case, the packet is send to all
  2272. * ports of the bridge. Since this is a valid scenario, do not
  2273. * print out any errors here. */
  2274. if (net_ratelimit()) {
  2275. printk(KERN_DEBUG "AP: drop packet to non-associated "
  2276. "STA " MACSTR "\n", MAC2STR(hdr->addr1));
  2277. }
  2278. #endif
  2279. local->ap->tx_drop_nonassoc++;
  2280. ret = AP_TX_DROP;
  2281. goto out;
  2282. }
  2283. if (sta == NULL)
  2284. goto out;
  2285. if (!(sta->flags & WLAN_STA_AUTHORIZED))
  2286. ret = AP_TX_CONTINUE_NOT_AUTHORIZED;
  2287. /* Set tx_rate if using host-based TX rate control */
  2288. if (!local->fw_tx_rate_control)
  2289. local->ap->last_tx_rate = meta->rate =
  2290. ap_update_sta_tx_rate(sta, local->dev);
  2291. if (local->iw_mode != IW_MODE_MASTER)
  2292. goto out;
  2293. if (!(sta->flags & WLAN_STA_PS))
  2294. goto out;
  2295. if (memcmp(skb->cb, AP_SKB_CB_MAGIC, AP_SKB_CB_MAGIC_LEN) == 0) {
  2296. if (skb->cb[AP_SKB_CB_MAGIC_LEN] & AP_SKB_CB_ADD_MOREDATA) {
  2297. /* indicate to STA that more frames follow */
  2298. hdr->frame_control |=
  2299. __constant_cpu_to_le16(WLAN_FC_MOREDATA);
  2300. }
  2301. if (skb->cb[AP_SKB_CB_MAGIC_LEN] & AP_SKB_CB_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. }
  2307. if (skb_queue_len(&sta->tx_buf) >= STA_MAX_TX_BUFFER) {
  2308. PDEBUG(DEBUG_PS, "%s: No more space in STA (" MACSTR ")'s PS "
  2309. "mode buffer\n", local->dev->name, MAC2STR(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 hostap_ieee80211_hdr *hdr;
  2362. struct hostap_skb_tx_data *meta;
  2363. hdr = (struct hostap_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 " MACSTR " for this "
  2370. "TX error (@%lu)\n",
  2371. local->dev->name, MAC2STR(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, "%s: STA " MACSTR " TX rate lowered "
  2397. "to %d\n", local->dev->name, MAC2STR(sta->addr),
  2398. 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 " MACSTR " changed to use PS "
  2410. "mode (type=0x%02X, stype=0x%02X)\n",
  2411. MAC2STR(sta->addr), type, stype);
  2412. } else if (!pwrmgt && (sta->flags & WLAN_STA_PS)) {
  2413. sta->flags &= ~WLAN_STA_PS;
  2414. PDEBUG(DEBUG_PS2, "STA " MACSTR " changed to not use "
  2415. "PS mode (type=0x%02X, stype=0x%02X)\n",
  2416. MAC2STR(sta->addr), type, stype);
  2417. if (type != WLAN_FC_TYPE_CTRL || stype != WLAN_FC_STYPE_PSPOLL)
  2418. schedule_packet_send(local, sta);
  2419. }
  2420. }
  2421. /* Called only as a tasklet (software IRQ). Called for each RX frame to update
  2422. * STA power saving state. pwrmgt is a flag from 802.11 frame_control field. */
  2423. int hostap_update_sta_ps(local_info_t *local, struct hostap_ieee80211_hdr *hdr)
  2424. {
  2425. struct sta_info *sta;
  2426. u16 fc;
  2427. spin_lock(&local->ap->sta_table_lock);
  2428. sta = ap_get_sta(local->ap, hdr->addr2);
  2429. if (sta)
  2430. atomic_inc(&sta->users);
  2431. spin_unlock(&local->ap->sta_table_lock);
  2432. if (!sta)
  2433. return -1;
  2434. fc = le16_to_cpu(hdr->frame_control);
  2435. hostap_update_sta_ps2(local, sta, fc & WLAN_FC_PWRMGT,
  2436. WLAN_FC_GET_TYPE(fc), WLAN_FC_GET_STYPE(fc));
  2437. atomic_dec(&sta->users);
  2438. return 0;
  2439. }
  2440. /* Called only as a tasklet (software IRQ). Called for each RX frame after
  2441. * getting RX header and payload from hardware. */
  2442. ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
  2443. struct sk_buff *skb,
  2444. struct hostap_80211_rx_status *rx_stats,
  2445. int wds)
  2446. {
  2447. int ret;
  2448. struct sta_info *sta;
  2449. u16 fc, type, stype;
  2450. struct hostap_ieee80211_hdr *hdr;
  2451. if (local->ap == NULL)
  2452. return AP_RX_CONTINUE;
  2453. hdr = (struct hostap_ieee80211_hdr *) skb->data;
  2454. fc = le16_to_cpu(hdr->frame_control);
  2455. type = WLAN_FC_GET_TYPE(fc);
  2456. stype = WLAN_FC_GET_STYPE(fc);
  2457. spin_lock(&local->ap->sta_table_lock);
  2458. sta = ap_get_sta(local->ap, hdr->addr2);
  2459. if (sta)
  2460. atomic_inc(&sta->users);
  2461. spin_unlock(&local->ap->sta_table_lock);
  2462. if (sta && !(sta->flags & WLAN_STA_AUTHORIZED))
  2463. ret = AP_RX_CONTINUE_NOT_AUTHORIZED;
  2464. else
  2465. ret = AP_RX_CONTINUE;
  2466. if (fc & WLAN_FC_TODS) {
  2467. if (!wds && (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
  2468. if (local->hostapd) {
  2469. prism2_rx_80211(local->apdev, skb, rx_stats,
  2470. PRISM2_RX_NON_ASSOC);
  2471. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  2472. } else {
  2473. printk(KERN_DEBUG "%s: dropped received packet"
  2474. " from non-associated STA " MACSTR
  2475. " (type=0x%02x, subtype=0x%02x)\n",
  2476. dev->name, MAC2STR(hdr->addr2), type,
  2477. stype);
  2478. hostap_rx(dev, skb, rx_stats);
  2479. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  2480. }
  2481. ret = AP_RX_EXIT;
  2482. goto out;
  2483. }
  2484. } else if (fc & WLAN_FC_FROMDS) {
  2485. if (!wds) {
  2486. /* FromDS frame - not for us; probably
  2487. * broadcast/multicast in another BSS - drop */
  2488. if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
  2489. printk(KERN_DEBUG "Odd.. FromDS packet "
  2490. "received with own BSSID\n");
  2491. hostap_dump_rx_80211(dev->name, skb, rx_stats);
  2492. }
  2493. ret = AP_RX_DROP;
  2494. goto out;
  2495. }
  2496. } else if (stype == WLAN_FC_STYPE_NULLFUNC && sta == NULL &&
  2497. memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
  2498. if (local->hostapd) {
  2499. prism2_rx_80211(local->apdev, skb, rx_stats,
  2500. PRISM2_RX_NON_ASSOC);
  2501. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  2502. } else {
  2503. /* At least Lucent f/w seems to send data::nullfunc
  2504. * frames with no ToDS flag when the current AP returns
  2505. * after being unavailable for some time. Speed up
  2506. * re-association by informing the station about it not
  2507. * being associated. */
  2508. printk(KERN_DEBUG "%s: rejected received nullfunc "
  2509. "frame without ToDS from not associated STA "
  2510. MACSTR "\n",
  2511. dev->name, MAC2STR(hdr->addr2));
  2512. hostap_rx(dev, skb, rx_stats);
  2513. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  2514. }
  2515. ret = AP_RX_EXIT;
  2516. goto out;
  2517. } else if (stype == WLAN_FC_STYPE_NULLFUNC) {
  2518. /* At least Lucent cards seem to send periodic nullfunc
  2519. * frames with ToDS. Let these through to update SQ
  2520. * stats and PS state. Nullfunc frames do not contain
  2521. * any data and they will be dropped below. */
  2522. } else {
  2523. /* If BSSID (Addr3) is foreign, this frame is a normal
  2524. * broadcast frame from an IBSS network. Drop it silently.
  2525. * If BSSID is own, report the dropping of this frame. */
  2526. if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
  2527. printk(KERN_DEBUG "%s: dropped received packet from "
  2528. MACSTR " with no ToDS flag (type=0x%02x, "
  2529. "subtype=0x%02x)\n", dev->name,
  2530. MAC2STR(hdr->addr2), type, stype);
  2531. hostap_dump_rx_80211(dev->name, skb, rx_stats);
  2532. }
  2533. ret = AP_RX_DROP;
  2534. goto out;
  2535. }
  2536. if (sta) {
  2537. hostap_update_sta_ps2(local, sta, fc & WLAN_FC_PWRMGT,
  2538. type, stype);
  2539. sta->rx_packets++;
  2540. sta->rx_bytes += skb->len;
  2541. sta->last_rx = jiffies;
  2542. }
  2543. if (local->ap->nullfunc_ack && stype == WLAN_FC_STYPE_NULLFUNC &&
  2544. fc & WLAN_FC_TODS) {
  2545. if (local->hostapd) {
  2546. prism2_rx_80211(local->apdev, skb, rx_stats,
  2547. PRISM2_RX_NULLFUNC_ACK);
  2548. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  2549. } else {
  2550. /* some STA f/w's seem to require control::ACK frame
  2551. * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
  2552. * from Compaq) does not send this.. Try to generate
  2553. * ACK for these frames from the host driver to make
  2554. * power saving work with, e.g., Lucent WaveLAN f/w */
  2555. hostap_rx(dev, skb, rx_stats);
  2556. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  2557. }
  2558. ret = AP_RX_EXIT;
  2559. goto out;
  2560. }
  2561. out:
  2562. if (sta)
  2563. atomic_dec(&sta->users);
  2564. return ret;
  2565. }
  2566. /* Called only as a tasklet (software IRQ) */
  2567. int hostap_handle_sta_crypto(local_info_t *local,
  2568. struct hostap_ieee80211_hdr *hdr,
  2569. struct prism2_crypt_data **crypt, void **sta_ptr)
  2570. {
  2571. struct sta_info *sta;
  2572. spin_lock(&local->ap->sta_table_lock);
  2573. sta = ap_get_sta(local->ap, hdr->addr2);
  2574. if (sta)
  2575. atomic_inc(&sta->users);
  2576. spin_unlock(&local->ap->sta_table_lock);
  2577. if (!sta)
  2578. return -1;
  2579. if (sta->crypt) {
  2580. *crypt = sta->crypt;
  2581. *sta_ptr = sta;
  2582. /* hostap_handle_sta_release() will be called to release STA
  2583. * info */
  2584. } else
  2585. atomic_dec(&sta->users);
  2586. return 0;
  2587. }
  2588. /* Called only as a tasklet (software IRQ) */
  2589. int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr)
  2590. {
  2591. struct sta_info *sta;
  2592. int ret = 0;
  2593. spin_lock(&ap->sta_table_lock);
  2594. sta = ap_get_sta(ap, sta_addr);
  2595. if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap)
  2596. ret = 1;
  2597. spin_unlock(&ap->sta_table_lock);
  2598. return ret;
  2599. }
  2600. /* Called only as a tasklet (software IRQ) */
  2601. int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr)
  2602. {
  2603. struct sta_info *sta;
  2604. int ret = 0;
  2605. spin_lock(&ap->sta_table_lock);
  2606. sta = ap_get_sta(ap, sta_addr);
  2607. if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap &&
  2608. ((sta->flags & WLAN_STA_AUTHORIZED) ||
  2609. ap->local->ieee_802_1x == 0))
  2610. ret = 1;
  2611. spin_unlock(&ap->sta_table_lock);
  2612. return ret;
  2613. }
  2614. /* Called only as a tasklet (software IRQ) */
  2615. int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
  2616. {
  2617. struct sta_info *sta;
  2618. int ret = 1;
  2619. if (!ap)
  2620. return -1;
  2621. spin_lock(&ap->sta_table_lock);
  2622. sta = ap_get_sta(ap, sta_addr);
  2623. if (sta)
  2624. ret = 0;
  2625. spin_unlock(&ap->sta_table_lock);
  2626. if (ret == 1) {
  2627. sta = ap_add_sta(ap, sta_addr);
  2628. if (!sta)
  2629. ret = -1;
  2630. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  2631. sta->ap = 1;
  2632. memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
  2633. /* No way of knowing which rates are supported since we did not
  2634. * get supported rates element from beacon/assoc req. Assume
  2635. * that remote end supports all 802.11b rates. */
  2636. sta->supported_rates[0] = 0x82;
  2637. sta->supported_rates[1] = 0x84;
  2638. sta->supported_rates[2] = 0x0b;
  2639. sta->supported_rates[3] = 0x16;
  2640. sta->tx_supp_rates = WLAN_RATE_1M | WLAN_RATE_2M |
  2641. WLAN_RATE_5M5 | WLAN_RATE_11M;
  2642. sta->tx_rate = 110;
  2643. sta->tx_max_rate = sta->tx_rate_idx = 3;
  2644. }
  2645. return ret;
  2646. }
  2647. /* Called only as a tasklet (software IRQ) */
  2648. int hostap_update_rx_stats(struct ap_data *ap,
  2649. struct hostap_ieee80211_hdr *hdr,
  2650. struct hostap_80211_rx_status *rx_stats)
  2651. {
  2652. struct sta_info *sta;
  2653. if (!ap)
  2654. return -1;
  2655. spin_lock(&ap->sta_table_lock);
  2656. sta = ap_get_sta(ap, hdr->addr2);
  2657. if (sta) {
  2658. sta->last_rx_silence = rx_stats->noise;
  2659. sta->last_rx_signal = rx_stats->signal;
  2660. sta->last_rx_rate = rx_stats->rate;
  2661. sta->last_rx_updated = 7;
  2662. if (rx_stats->rate == 10)
  2663. sta->rx_count[0]++;
  2664. else if (rx_stats->rate == 20)
  2665. sta->rx_count[1]++;
  2666. else if (rx_stats->rate == 55)
  2667. sta->rx_count[2]++;
  2668. else if (rx_stats->rate == 110)
  2669. sta->rx_count[3]++;
  2670. }
  2671. spin_unlock(&ap->sta_table_lock);
  2672. return sta ? 0 : -1;
  2673. }
  2674. void hostap_update_rates(local_info_t *local)
  2675. {
  2676. struct list_head *ptr;
  2677. struct ap_data *ap = local->ap;
  2678. if (!ap)
  2679. return;
  2680. spin_lock_bh(&ap->sta_table_lock);
  2681. for (ptr = ap->sta_list.next; ptr != &ap->sta_list; ptr = ptr->next) {
  2682. struct sta_info *sta = (struct sta_info *) ptr;
  2683. prism2_check_tx_rates(sta);
  2684. }
  2685. spin_unlock_bh(&ap->sta_table_lock);
  2686. }
  2687. static void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
  2688. struct prism2_crypt_data ***crypt)
  2689. {
  2690. struct sta_info *sta;
  2691. spin_lock_bh(&ap->sta_table_lock);
  2692. sta = ap_get_sta(ap, addr);
  2693. if (sta)
  2694. atomic_inc(&sta->users);
  2695. spin_unlock_bh(&ap->sta_table_lock);
  2696. if (!sta && permanent)
  2697. sta = ap_add_sta(ap, addr);
  2698. if (!sta)
  2699. return NULL;
  2700. if (permanent)
  2701. sta->flags |= WLAN_STA_PERM;
  2702. *crypt = &sta->crypt;
  2703. return sta;
  2704. }
  2705. void hostap_add_wds_links(local_info_t *local)
  2706. {
  2707. struct ap_data *ap = local->ap;
  2708. struct list_head *ptr;
  2709. spin_lock_bh(&ap->sta_table_lock);
  2710. list_for_each(ptr, &ap->sta_list) {
  2711. struct sta_info *sta = list_entry(ptr, struct sta_info, 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);
  2737. EXPORT_SYMBOL(hostap_handle_sta_release);
  2738. EXPORT_SYMBOL(hostap_handle_sta_tx_exc);
  2739. EXPORT_SYMBOL(hostap_update_sta_ps);
  2740. EXPORT_SYMBOL(hostap_handle_sta_rx);
  2741. EXPORT_SYMBOL(hostap_is_sta_assoc);
  2742. EXPORT_SYMBOL(hostap_is_sta_authorized);
  2743. EXPORT_SYMBOL(hostap_add_sta);
  2744. EXPORT_SYMBOL(hostap_update_rates);
  2745. EXPORT_SYMBOL(hostap_add_wds_links);
  2746. EXPORT_SYMBOL(hostap_wds_link_oper);
  2747. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  2748. EXPORT_SYMBOL(hostap_deauth_all_stas);
  2749. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */