hostap_ap.c 85 KB

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