hostap_ioctl.c 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */
  3. #include <linux/slab.h>
  4. #include <linux/types.h>
  5. #include <linux/sched/signal.h>
  6. #include <linux/ethtool.h>
  7. #include <linux/if_arp.h>
  8. #include <linux/module.h>
  9. #include <linux/etherdevice.h>
  10. #include <net/lib80211.h>
  11. #include "hostap_wlan.h"
  12. #include "hostap.h"
  13. #include "hostap_ap.h"
  14. static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev)
  15. {
  16. struct hostap_interface *iface;
  17. local_info_t *local;
  18. struct iw_statistics *wstats;
  19. iface = netdev_priv(dev);
  20. local = iface->local;
  21. /* Why are we doing that ? Jean II */
  22. if (iface->type != HOSTAP_INTERFACE_MAIN)
  23. return NULL;
  24. wstats = &local->wstats;
  25. wstats->status = 0;
  26. wstats->discard.code =
  27. local->comm_tallies.rx_discards_wep_undecryptable;
  28. wstats->discard.misc =
  29. local->comm_tallies.rx_fcs_errors +
  30. local->comm_tallies.rx_discards_no_buffer +
  31. local->comm_tallies.tx_discards_wrong_sa;
  32. wstats->discard.retries =
  33. local->comm_tallies.tx_retry_limit_exceeded;
  34. wstats->discard.fragment =
  35. local->comm_tallies.rx_message_in_bad_msg_fragments;
  36. if (local->iw_mode != IW_MODE_MASTER &&
  37. local->iw_mode != IW_MODE_REPEAT) {
  38. int update = 1;
  39. #ifdef in_atomic
  40. /* RID reading might sleep and it must not be called in
  41. * interrupt context or while atomic. However, this
  42. * function seems to be called while atomic (at least in Linux
  43. * 2.5.59). Update signal quality values only if in suitable
  44. * context. Otherwise, previous values read from tick timer
  45. * will be used. */
  46. if (in_atomic())
  47. update = 0;
  48. #endif /* in_atomic */
  49. if (update && prism2_update_comms_qual(dev) == 0)
  50. wstats->qual.updated = IW_QUAL_ALL_UPDATED |
  51. IW_QUAL_DBM;
  52. wstats->qual.qual = local->comms_qual;
  53. wstats->qual.level = local->avg_signal;
  54. wstats->qual.noise = local->avg_noise;
  55. } else {
  56. wstats->qual.qual = 0;
  57. wstats->qual.level = 0;
  58. wstats->qual.noise = 0;
  59. wstats->qual.updated = IW_QUAL_ALL_INVALID;
  60. }
  61. return wstats;
  62. }
  63. static int prism2_get_datarates(struct net_device *dev, u8 *rates)
  64. {
  65. struct hostap_interface *iface;
  66. local_info_t *local;
  67. u8 buf[12];
  68. int len;
  69. u16 val;
  70. iface = netdev_priv(dev);
  71. local = iface->local;
  72. len = local->func->get_rid(dev, HFA384X_RID_SUPPORTEDDATARATES, buf,
  73. sizeof(buf), 0);
  74. if (len < 2)
  75. return 0;
  76. val = le16_to_cpu(*(__le16 *) buf); /* string length */
  77. if (len - 2 < val || val > 10)
  78. return 0;
  79. memcpy(rates, buf + 2, val);
  80. return val;
  81. }
  82. static int prism2_get_name(struct net_device *dev,
  83. struct iw_request_info *info,
  84. char *name, char *extra)
  85. {
  86. u8 rates[10];
  87. int len, i, over2 = 0;
  88. len = prism2_get_datarates(dev, rates);
  89. for (i = 0; i < len; i++) {
  90. if (rates[i] == 0x0b || rates[i] == 0x16) {
  91. over2 = 1;
  92. break;
  93. }
  94. }
  95. strcpy(name, over2 ? "IEEE 802.11b" : "IEEE 802.11-DS");
  96. return 0;
  97. }
  98. static int prism2_ioctl_siwencode(struct net_device *dev,
  99. struct iw_request_info *info,
  100. struct iw_point *erq, char *keybuf)
  101. {
  102. struct hostap_interface *iface;
  103. local_info_t *local;
  104. int i;
  105. struct lib80211_crypt_data **crypt;
  106. iface = netdev_priv(dev);
  107. local = iface->local;
  108. i = erq->flags & IW_ENCODE_INDEX;
  109. if (i < 1 || i > 4)
  110. i = local->crypt_info.tx_keyidx;
  111. else
  112. i--;
  113. if (i < 0 || i >= WEP_KEYS)
  114. return -EINVAL;
  115. crypt = &local->crypt_info.crypt[i];
  116. if (erq->flags & IW_ENCODE_DISABLED) {
  117. if (*crypt)
  118. lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
  119. goto done;
  120. }
  121. if (*crypt != NULL && (*crypt)->ops != NULL &&
  122. strcmp((*crypt)->ops->name, "WEP") != 0) {
  123. /* changing to use WEP; deinit previously used algorithm */
  124. lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
  125. }
  126. if (*crypt == NULL) {
  127. struct lib80211_crypt_data *new_crypt;
  128. /* take WEP into use */
  129. new_crypt = kzalloc(sizeof(struct lib80211_crypt_data),
  130. GFP_KERNEL);
  131. if (new_crypt == NULL)
  132. return -ENOMEM;
  133. new_crypt->ops = lib80211_get_crypto_ops("WEP");
  134. if (!new_crypt->ops) {
  135. request_module("lib80211_crypt_wep");
  136. new_crypt->ops = lib80211_get_crypto_ops("WEP");
  137. }
  138. if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
  139. new_crypt->priv = new_crypt->ops->init(i);
  140. if (!new_crypt->ops || !new_crypt->priv) {
  141. kfree(new_crypt);
  142. new_crypt = NULL;
  143. printk(KERN_WARNING "%s: could not initialize WEP: "
  144. "load module hostap_crypt_wep.o\n",
  145. dev->name);
  146. return -EOPNOTSUPP;
  147. }
  148. *crypt = new_crypt;
  149. }
  150. if (erq->length > 0) {
  151. int len = erq->length <= 5 ? 5 : 13;
  152. int first = 1, j;
  153. if (len > erq->length)
  154. memset(keybuf + erq->length, 0, len - erq->length);
  155. (*crypt)->ops->set_key(keybuf, len, NULL, (*crypt)->priv);
  156. for (j = 0; j < WEP_KEYS; j++) {
  157. if (j != i && local->crypt_info.crypt[j]) {
  158. first = 0;
  159. break;
  160. }
  161. }
  162. if (first)
  163. local->crypt_info.tx_keyidx = i;
  164. } else {
  165. /* No key data - just set the default TX key index */
  166. local->crypt_info.tx_keyidx = i;
  167. }
  168. done:
  169. local->open_wep = erq->flags & IW_ENCODE_OPEN;
  170. if (hostap_set_encryption(local)) {
  171. printk(KERN_DEBUG "%s: set_encryption failed\n", dev->name);
  172. return -EINVAL;
  173. }
  174. /* Do not reset port0 if card is in Managed mode since resetting will
  175. * generate new IEEE 802.11 authentication which may end up in looping
  176. * with IEEE 802.1X. Prism2 documentation seem to require port reset
  177. * after WEP configuration. However, keys are apparently changed at
  178. * least in Managed mode. */
  179. if (local->iw_mode != IW_MODE_INFRA && local->func->reset_port(dev)) {
  180. printk(KERN_DEBUG "%s: reset_port failed\n", dev->name);
  181. return -EINVAL;
  182. }
  183. return 0;
  184. }
  185. static int prism2_ioctl_giwencode(struct net_device *dev,
  186. struct iw_request_info *info,
  187. struct iw_point *erq, char *key)
  188. {
  189. struct hostap_interface *iface;
  190. local_info_t *local;
  191. int i, len;
  192. u16 val;
  193. struct lib80211_crypt_data *crypt;
  194. iface = netdev_priv(dev);
  195. local = iface->local;
  196. i = erq->flags & IW_ENCODE_INDEX;
  197. if (i < 1 || i > 4)
  198. i = local->crypt_info.tx_keyidx;
  199. else
  200. i--;
  201. if (i < 0 || i >= WEP_KEYS)
  202. return -EINVAL;
  203. crypt = local->crypt_info.crypt[i];
  204. erq->flags = i + 1;
  205. if (crypt == NULL || crypt->ops == NULL) {
  206. erq->length = 0;
  207. erq->flags |= IW_ENCODE_DISABLED;
  208. return 0;
  209. }
  210. if (strcmp(crypt->ops->name, "WEP") != 0) {
  211. /* only WEP is supported with wireless extensions, so just
  212. * report that encryption is used */
  213. erq->length = 0;
  214. erq->flags |= IW_ENCODE_ENABLED;
  215. return 0;
  216. }
  217. /* Reads from HFA384X_RID_CNFDEFAULTKEY* return bogus values, so show
  218. * the keys from driver buffer */
  219. len = crypt->ops->get_key(key, WEP_KEY_LEN, NULL, crypt->priv);
  220. erq->length = (len >= 0 ? len : 0);
  221. if (local->func->get_rid(dev, HFA384X_RID_CNFWEPFLAGS, &val, 2, 1) < 0)
  222. {
  223. printk("CNFWEPFLAGS reading failed\n");
  224. return -EOPNOTSUPP;
  225. }
  226. le16_to_cpus(&val);
  227. if (val & HFA384X_WEPFLAGS_PRIVACYINVOKED)
  228. erq->flags |= IW_ENCODE_ENABLED;
  229. else
  230. erq->flags |= IW_ENCODE_DISABLED;
  231. if (val & HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED)
  232. erq->flags |= IW_ENCODE_RESTRICTED;
  233. else
  234. erq->flags |= IW_ENCODE_OPEN;
  235. return 0;
  236. }
  237. static int hostap_set_rate(struct net_device *dev)
  238. {
  239. struct hostap_interface *iface;
  240. local_info_t *local;
  241. int ret, basic_rates;
  242. iface = netdev_priv(dev);
  243. local = iface->local;
  244. basic_rates = local->basic_rates & local->tx_rate_control;
  245. if (!basic_rates || basic_rates != local->basic_rates) {
  246. printk(KERN_INFO "%s: updating basic rate set automatically "
  247. "to match with the new supported rate set\n",
  248. dev->name);
  249. if (!basic_rates)
  250. basic_rates = local->tx_rate_control;
  251. local->basic_rates = basic_rates;
  252. if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
  253. basic_rates))
  254. printk(KERN_WARNING "%s: failed to set "
  255. "cnfBasicRates\n", dev->name);
  256. }
  257. ret = (hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
  258. local->tx_rate_control) ||
  259. hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
  260. local->tx_rate_control) ||
  261. local->func->reset_port(dev));
  262. if (ret) {
  263. printk(KERN_WARNING "%s: TXRateControl/cnfSupportedRates "
  264. "setting to 0x%x failed\n",
  265. dev->name, local->tx_rate_control);
  266. }
  267. /* Update TX rate configuration for all STAs based on new operational
  268. * rate set. */
  269. hostap_update_rates(local);
  270. return ret;
  271. }
  272. static int prism2_ioctl_siwrate(struct net_device *dev,
  273. struct iw_request_info *info,
  274. struct iw_param *rrq, char *extra)
  275. {
  276. struct hostap_interface *iface;
  277. local_info_t *local;
  278. iface = netdev_priv(dev);
  279. local = iface->local;
  280. if (rrq->fixed) {
  281. switch (rrq->value) {
  282. case 11000000:
  283. local->tx_rate_control = HFA384X_RATES_11MBPS;
  284. break;
  285. case 5500000:
  286. local->tx_rate_control = HFA384X_RATES_5MBPS;
  287. break;
  288. case 2000000:
  289. local->tx_rate_control = HFA384X_RATES_2MBPS;
  290. break;
  291. case 1000000:
  292. local->tx_rate_control = HFA384X_RATES_1MBPS;
  293. break;
  294. default:
  295. local->tx_rate_control = HFA384X_RATES_1MBPS |
  296. HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
  297. HFA384X_RATES_11MBPS;
  298. break;
  299. }
  300. } else {
  301. switch (rrq->value) {
  302. case 11000000:
  303. local->tx_rate_control = HFA384X_RATES_1MBPS |
  304. HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
  305. HFA384X_RATES_11MBPS;
  306. break;
  307. case 5500000:
  308. local->tx_rate_control = HFA384X_RATES_1MBPS |
  309. HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS;
  310. break;
  311. case 2000000:
  312. local->tx_rate_control = HFA384X_RATES_1MBPS |
  313. HFA384X_RATES_2MBPS;
  314. break;
  315. case 1000000:
  316. local->tx_rate_control = HFA384X_RATES_1MBPS;
  317. break;
  318. default:
  319. local->tx_rate_control = HFA384X_RATES_1MBPS |
  320. HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
  321. HFA384X_RATES_11MBPS;
  322. break;
  323. }
  324. }
  325. return hostap_set_rate(dev);
  326. }
  327. static int prism2_ioctl_giwrate(struct net_device *dev,
  328. struct iw_request_info *info,
  329. struct iw_param *rrq, char *extra)
  330. {
  331. u16 val;
  332. struct hostap_interface *iface;
  333. local_info_t *local;
  334. int ret = 0;
  335. iface = netdev_priv(dev);
  336. local = iface->local;
  337. if (local->func->get_rid(dev, HFA384X_RID_TXRATECONTROL, &val, 2, 1) <
  338. 0)
  339. return -EINVAL;
  340. if ((val & 0x1) && (val > 1))
  341. rrq->fixed = 0;
  342. else
  343. rrq->fixed = 1;
  344. if (local->iw_mode == IW_MODE_MASTER && local->ap != NULL &&
  345. !local->fw_tx_rate_control) {
  346. /* HFA384X_RID_CURRENTTXRATE seems to always be 2 Mbps in
  347. * Host AP mode, so use the recorded TX rate of the last sent
  348. * frame */
  349. rrq->value = local->ap->last_tx_rate > 0 ?
  350. local->ap->last_tx_rate * 100000 : 11000000;
  351. return 0;
  352. }
  353. if (local->func->get_rid(dev, HFA384X_RID_CURRENTTXRATE, &val, 2, 1) <
  354. 0)
  355. return -EINVAL;
  356. switch (val) {
  357. case HFA384X_RATES_1MBPS:
  358. rrq->value = 1000000;
  359. break;
  360. case HFA384X_RATES_2MBPS:
  361. rrq->value = 2000000;
  362. break;
  363. case HFA384X_RATES_5MBPS:
  364. rrq->value = 5500000;
  365. break;
  366. case HFA384X_RATES_11MBPS:
  367. rrq->value = 11000000;
  368. break;
  369. default:
  370. /* should not happen */
  371. rrq->value = 11000000;
  372. ret = -EINVAL;
  373. break;
  374. }
  375. return ret;
  376. }
  377. static int prism2_ioctl_siwsens(struct net_device *dev,
  378. struct iw_request_info *info,
  379. struct iw_param *sens, char *extra)
  380. {
  381. struct hostap_interface *iface;
  382. local_info_t *local;
  383. iface = netdev_priv(dev);
  384. local = iface->local;
  385. /* Set the desired AP density */
  386. if (sens->value < 1 || sens->value > 3)
  387. return -EINVAL;
  388. if (hostap_set_word(dev, HFA384X_RID_CNFSYSTEMSCALE, sens->value) ||
  389. local->func->reset_port(dev))
  390. return -EINVAL;
  391. return 0;
  392. }
  393. static int prism2_ioctl_giwsens(struct net_device *dev,
  394. struct iw_request_info *info,
  395. struct iw_param *sens, char *extra)
  396. {
  397. struct hostap_interface *iface;
  398. local_info_t *local;
  399. __le16 val;
  400. iface = netdev_priv(dev);
  401. local = iface->local;
  402. /* Get the current AP density */
  403. if (local->func->get_rid(dev, HFA384X_RID_CNFSYSTEMSCALE, &val, 2, 1) <
  404. 0)
  405. return -EINVAL;
  406. sens->value = le16_to_cpu(val);
  407. sens->fixed = 1;
  408. return 0;
  409. }
  410. /* Deprecated in new wireless extension API */
  411. static int prism2_ioctl_giwaplist(struct net_device *dev,
  412. struct iw_request_info *info,
  413. struct iw_point *data, char *extra)
  414. {
  415. struct hostap_interface *iface;
  416. local_info_t *local;
  417. struct sockaddr *addr;
  418. struct iw_quality *qual;
  419. iface = netdev_priv(dev);
  420. local = iface->local;
  421. if (local->iw_mode != IW_MODE_MASTER) {
  422. printk(KERN_DEBUG "SIOCGIWAPLIST is currently only supported "
  423. "in Host AP mode\n");
  424. data->length = 0;
  425. return -EOPNOTSUPP;
  426. }
  427. addr = kmalloc_array(IW_MAX_AP, sizeof(struct sockaddr), GFP_KERNEL);
  428. qual = kmalloc_array(IW_MAX_AP, sizeof(struct iw_quality), GFP_KERNEL);
  429. if (addr == NULL || qual == NULL) {
  430. kfree(addr);
  431. kfree(qual);
  432. data->length = 0;
  433. return -ENOMEM;
  434. }
  435. data->length = prism2_ap_get_sta_qual(local, addr, qual, IW_MAX_AP, 1);
  436. memcpy(extra, addr, sizeof(struct sockaddr) * data->length);
  437. data->flags = 1; /* has quality information */
  438. memcpy(extra + sizeof(struct sockaddr) * data->length, qual,
  439. sizeof(struct iw_quality) * data->length);
  440. kfree(addr);
  441. kfree(qual);
  442. return 0;
  443. }
  444. static int prism2_ioctl_siwrts(struct net_device *dev,
  445. struct iw_request_info *info,
  446. struct iw_param *rts, char *extra)
  447. {
  448. struct hostap_interface *iface;
  449. local_info_t *local;
  450. __le16 val;
  451. iface = netdev_priv(dev);
  452. local = iface->local;
  453. if (rts->disabled)
  454. val = cpu_to_le16(2347);
  455. else if (rts->value < 0 || rts->value > 2347)
  456. return -EINVAL;
  457. else
  458. val = cpu_to_le16(rts->value);
  459. if (local->func->set_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2) ||
  460. local->func->reset_port(dev))
  461. return -EINVAL;
  462. local->rts_threshold = rts->value;
  463. return 0;
  464. }
  465. static int prism2_ioctl_giwrts(struct net_device *dev,
  466. struct iw_request_info *info,
  467. struct iw_param *rts, char *extra)
  468. {
  469. struct hostap_interface *iface;
  470. local_info_t *local;
  471. __le16 val;
  472. iface = netdev_priv(dev);
  473. local = iface->local;
  474. if (local->func->get_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2, 1) <
  475. 0)
  476. return -EINVAL;
  477. rts->value = le16_to_cpu(val);
  478. rts->disabled = (rts->value == 2347);
  479. rts->fixed = 1;
  480. return 0;
  481. }
  482. static int prism2_ioctl_siwfrag(struct net_device *dev,
  483. struct iw_request_info *info,
  484. struct iw_param *rts, char *extra)
  485. {
  486. struct hostap_interface *iface;
  487. local_info_t *local;
  488. __le16 val;
  489. iface = netdev_priv(dev);
  490. local = iface->local;
  491. if (rts->disabled)
  492. val = cpu_to_le16(2346);
  493. else if (rts->value < 256 || rts->value > 2346)
  494. return -EINVAL;
  495. else
  496. val = cpu_to_le16(rts->value & ~0x1); /* even numbers only */
  497. local->fragm_threshold = rts->value & ~0x1;
  498. if (local->func->set_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, &val,
  499. 2)
  500. || local->func->reset_port(dev))
  501. return -EINVAL;
  502. return 0;
  503. }
  504. static int prism2_ioctl_giwfrag(struct net_device *dev,
  505. struct iw_request_info *info,
  506. struct iw_param *rts, char *extra)
  507. {
  508. struct hostap_interface *iface;
  509. local_info_t *local;
  510. __le16 val;
  511. iface = netdev_priv(dev);
  512. local = iface->local;
  513. if (local->func->get_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
  514. &val, 2, 1) < 0)
  515. return -EINVAL;
  516. rts->value = le16_to_cpu(val);
  517. rts->disabled = (rts->value == 2346);
  518. rts->fixed = 1;
  519. return 0;
  520. }
  521. #ifndef PRISM2_NO_STATION_MODES
  522. static int hostap_join_ap(struct net_device *dev)
  523. {
  524. struct hostap_interface *iface;
  525. local_info_t *local;
  526. struct hfa384x_join_request req;
  527. unsigned long flags;
  528. int i;
  529. struct hfa384x_hostscan_result *entry;
  530. iface = netdev_priv(dev);
  531. local = iface->local;
  532. memcpy(req.bssid, local->preferred_ap, ETH_ALEN);
  533. req.channel = 0;
  534. spin_lock_irqsave(&local->lock, flags);
  535. for (i = 0; i < local->last_scan_results_count; i++) {
  536. if (!local->last_scan_results)
  537. break;
  538. entry = &local->last_scan_results[i];
  539. if (ether_addr_equal(local->preferred_ap, entry->bssid)) {
  540. req.channel = entry->chid;
  541. break;
  542. }
  543. }
  544. spin_unlock_irqrestore(&local->lock, flags);
  545. if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req,
  546. sizeof(req))) {
  547. printk(KERN_DEBUG "%s: JoinRequest %pM failed\n",
  548. dev->name, local->preferred_ap);
  549. return -1;
  550. }
  551. printk(KERN_DEBUG "%s: Trying to join BSSID %pM\n",
  552. dev->name, local->preferred_ap);
  553. return 0;
  554. }
  555. #endif /* PRISM2_NO_STATION_MODES */
  556. static int prism2_ioctl_siwap(struct net_device *dev,
  557. struct iw_request_info *info,
  558. struct sockaddr *ap_addr, char *extra)
  559. {
  560. #ifdef PRISM2_NO_STATION_MODES
  561. return -EOPNOTSUPP;
  562. #else /* PRISM2_NO_STATION_MODES */
  563. struct hostap_interface *iface;
  564. local_info_t *local;
  565. iface = netdev_priv(dev);
  566. local = iface->local;
  567. memcpy(local->preferred_ap, &ap_addr->sa_data, ETH_ALEN);
  568. if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA) {
  569. struct hfa384x_scan_request scan_req;
  570. memset(&scan_req, 0, sizeof(scan_req));
  571. scan_req.channel_list = cpu_to_le16(0x3fff);
  572. scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS);
  573. if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST,
  574. &scan_req, sizeof(scan_req))) {
  575. printk(KERN_DEBUG "%s: ScanResults request failed - "
  576. "preferred AP delayed to next unsolicited "
  577. "scan\n", dev->name);
  578. }
  579. } else if (local->host_roaming == 2 &&
  580. local->iw_mode == IW_MODE_INFRA) {
  581. if (hostap_join_ap(dev))
  582. return -EINVAL;
  583. } else {
  584. printk(KERN_DEBUG "%s: Preferred AP (SIOCSIWAP) is used only "
  585. "in Managed mode when host_roaming is enabled\n",
  586. dev->name);
  587. }
  588. return 0;
  589. #endif /* PRISM2_NO_STATION_MODES */
  590. }
  591. static int prism2_ioctl_giwap(struct net_device *dev,
  592. struct iw_request_info *info,
  593. struct sockaddr *ap_addr, char *extra)
  594. {
  595. struct hostap_interface *iface;
  596. local_info_t *local;
  597. iface = netdev_priv(dev);
  598. local = iface->local;
  599. ap_addr->sa_family = ARPHRD_ETHER;
  600. switch (iface->type) {
  601. case HOSTAP_INTERFACE_AP:
  602. memcpy(&ap_addr->sa_data, dev->dev_addr, ETH_ALEN);
  603. break;
  604. case HOSTAP_INTERFACE_STA:
  605. memcpy(&ap_addr->sa_data, local->assoc_ap_addr, ETH_ALEN);
  606. break;
  607. case HOSTAP_INTERFACE_WDS:
  608. memcpy(&ap_addr->sa_data, iface->u.wds.remote_addr, ETH_ALEN);
  609. break;
  610. default:
  611. if (local->func->get_rid(dev, HFA384X_RID_CURRENTBSSID,
  612. &ap_addr->sa_data, ETH_ALEN, 1) < 0)
  613. return -EOPNOTSUPP;
  614. /* local->bssid is also updated in LinkStatus handler when in
  615. * station mode */
  616. memcpy(local->bssid, &ap_addr->sa_data, ETH_ALEN);
  617. break;
  618. }
  619. return 0;
  620. }
  621. static int prism2_ioctl_siwnickn(struct net_device *dev,
  622. struct iw_request_info *info,
  623. struct iw_point *data, char *nickname)
  624. {
  625. struct hostap_interface *iface;
  626. local_info_t *local;
  627. iface = netdev_priv(dev);
  628. local = iface->local;
  629. memset(local->name, 0, sizeof(local->name));
  630. memcpy(local->name, nickname, data->length);
  631. local->name_set = 1;
  632. if (hostap_set_string(dev, HFA384X_RID_CNFOWNNAME, local->name) ||
  633. local->func->reset_port(dev))
  634. return -EINVAL;
  635. return 0;
  636. }
  637. static int prism2_ioctl_giwnickn(struct net_device *dev,
  638. struct iw_request_info *info,
  639. struct iw_point *data, char *nickname)
  640. {
  641. struct hostap_interface *iface;
  642. local_info_t *local;
  643. int len;
  644. char name[MAX_NAME_LEN + 3];
  645. u16 val;
  646. iface = netdev_priv(dev);
  647. local = iface->local;
  648. len = local->func->get_rid(dev, HFA384X_RID_CNFOWNNAME,
  649. &name, MAX_NAME_LEN + 2, 0);
  650. val = le16_to_cpu(*(__le16 *) name);
  651. if (len > MAX_NAME_LEN + 2 || len < 0 || val > MAX_NAME_LEN)
  652. return -EOPNOTSUPP;
  653. name[val + 2] = '\0';
  654. data->length = val + 1;
  655. memcpy(nickname, name + 2, val + 1);
  656. return 0;
  657. }
  658. static int prism2_ioctl_siwfreq(struct net_device *dev,
  659. struct iw_request_info *info,
  660. struct iw_freq *freq, char *extra)
  661. {
  662. struct hostap_interface *iface;
  663. local_info_t *local;
  664. iface = netdev_priv(dev);
  665. local = iface->local;
  666. /* freq => chan. */
  667. if (freq->e == 1 &&
  668. freq->m / 100000 >= freq_list[0] &&
  669. freq->m / 100000 <= freq_list[FREQ_COUNT - 1]) {
  670. int ch;
  671. int fr = freq->m / 100000;
  672. for (ch = 0; ch < FREQ_COUNT; ch++) {
  673. if (fr == freq_list[ch]) {
  674. freq->e = 0;
  675. freq->m = ch + 1;
  676. break;
  677. }
  678. }
  679. }
  680. if (freq->e != 0 || freq->m < 1 || freq->m > FREQ_COUNT ||
  681. !(local->channel_mask & (1 << (freq->m - 1))))
  682. return -EINVAL;
  683. local->channel = freq->m; /* channel is used in prism2_setup_rids() */
  684. if (hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel) ||
  685. local->func->reset_port(dev))
  686. return -EINVAL;
  687. return 0;
  688. }
  689. static int prism2_ioctl_giwfreq(struct net_device *dev,
  690. struct iw_request_info *info,
  691. struct iw_freq *freq, char *extra)
  692. {
  693. struct hostap_interface *iface;
  694. local_info_t *local;
  695. u16 val;
  696. iface = netdev_priv(dev);
  697. local = iface->local;
  698. if (local->func->get_rid(dev, HFA384X_RID_CURRENTCHANNEL, &val, 2, 1) <
  699. 0)
  700. return -EINVAL;
  701. le16_to_cpus(&val);
  702. if (val < 1 || val > FREQ_COUNT)
  703. return -EINVAL;
  704. freq->m = freq_list[val - 1] * 100000;
  705. freq->e = 1;
  706. return 0;
  707. }
  708. static void hostap_monitor_set_type(local_info_t *local)
  709. {
  710. struct net_device *dev = local->ddev;
  711. if (dev == NULL)
  712. return;
  713. if (local->monitor_type == PRISM2_MONITOR_PRISM ||
  714. local->monitor_type == PRISM2_MONITOR_CAPHDR) {
  715. dev->type = ARPHRD_IEEE80211_PRISM;
  716. } else if (local->monitor_type == PRISM2_MONITOR_RADIOTAP) {
  717. dev->type = ARPHRD_IEEE80211_RADIOTAP;
  718. } else {
  719. dev->type = ARPHRD_IEEE80211;
  720. }
  721. }
  722. static int prism2_ioctl_siwessid(struct net_device *dev,
  723. struct iw_request_info *info,
  724. struct iw_point *data, char *ssid)
  725. {
  726. struct hostap_interface *iface;
  727. local_info_t *local;
  728. iface = netdev_priv(dev);
  729. local = iface->local;
  730. if (iface->type == HOSTAP_INTERFACE_WDS)
  731. return -EOPNOTSUPP;
  732. if (data->flags == 0)
  733. ssid[0] = '\0'; /* ANY */
  734. if (local->iw_mode == IW_MODE_MASTER && ssid[0] == '\0') {
  735. /* Setting SSID to empty string seems to kill the card in
  736. * Host AP mode */
  737. printk(KERN_DEBUG "%s: Host AP mode does not support "
  738. "'Any' essid\n", dev->name);
  739. return -EINVAL;
  740. }
  741. memcpy(local->essid, ssid, data->length);
  742. local->essid[data->length] = '\0';
  743. if ((!local->fw_ap &&
  744. hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID, local->essid))
  745. || hostap_set_string(dev, HFA384X_RID_CNFOWNSSID, local->essid) ||
  746. local->func->reset_port(dev))
  747. return -EINVAL;
  748. return 0;
  749. }
  750. static int prism2_ioctl_giwessid(struct net_device *dev,
  751. struct iw_request_info *info,
  752. struct iw_point *data, char *essid)
  753. {
  754. struct hostap_interface *iface;
  755. local_info_t *local;
  756. u16 val;
  757. iface = netdev_priv(dev);
  758. local = iface->local;
  759. if (iface->type == HOSTAP_INTERFACE_WDS)
  760. return -EOPNOTSUPP;
  761. data->flags = 1; /* active */
  762. if (local->iw_mode == IW_MODE_MASTER) {
  763. data->length = strlen(local->essid);
  764. memcpy(essid, local->essid, IW_ESSID_MAX_SIZE);
  765. } else {
  766. int len;
  767. char ssid[MAX_SSID_LEN + 2];
  768. memset(ssid, 0, sizeof(ssid));
  769. len = local->func->get_rid(dev, HFA384X_RID_CURRENTSSID,
  770. &ssid, MAX_SSID_LEN + 2, 0);
  771. val = le16_to_cpu(*(__le16 *) ssid);
  772. if (len > MAX_SSID_LEN + 2 || len < 0 || val > MAX_SSID_LEN) {
  773. return -EOPNOTSUPP;
  774. }
  775. data->length = val;
  776. memcpy(essid, ssid + 2, IW_ESSID_MAX_SIZE);
  777. }
  778. return 0;
  779. }
  780. static int prism2_ioctl_giwrange(struct net_device *dev,
  781. struct iw_request_info *info,
  782. struct iw_point *data, char *extra)
  783. {
  784. struct hostap_interface *iface;
  785. local_info_t *local;
  786. struct iw_range *range = (struct iw_range *) extra;
  787. u8 rates[10];
  788. u16 val;
  789. int i, len, over2;
  790. iface = netdev_priv(dev);
  791. local = iface->local;
  792. data->length = sizeof(struct iw_range);
  793. memset(range, 0, sizeof(struct iw_range));
  794. /* TODO: could fill num_txpower and txpower array with
  795. * something; however, there are 128 different values.. */
  796. range->txpower_capa = IW_TXPOW_DBM;
  797. if (local->iw_mode == IW_MODE_INFRA || local->iw_mode == IW_MODE_ADHOC)
  798. {
  799. range->min_pmp = 1 * 1024;
  800. range->max_pmp = 65535 * 1024;
  801. range->min_pmt = 1 * 1024;
  802. range->max_pmt = 1000 * 1024;
  803. range->pmp_flags = IW_POWER_PERIOD;
  804. range->pmt_flags = IW_POWER_TIMEOUT;
  805. range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
  806. IW_POWER_UNICAST_R | IW_POWER_ALL_R;
  807. }
  808. range->we_version_compiled = WIRELESS_EXT;
  809. range->we_version_source = 18;
  810. range->retry_capa = IW_RETRY_LIMIT;
  811. range->retry_flags = IW_RETRY_LIMIT;
  812. range->min_retry = 0;
  813. range->max_retry = 255;
  814. range->num_channels = FREQ_COUNT;
  815. val = 0;
  816. for (i = 0; i < FREQ_COUNT; i++) {
  817. if (local->channel_mask & (1 << i)) {
  818. range->freq[val].i = i + 1;
  819. range->freq[val].m = freq_list[i] * 100000;
  820. range->freq[val].e = 1;
  821. val++;
  822. }
  823. if (val == IW_MAX_FREQUENCIES)
  824. break;
  825. }
  826. range->num_frequency = val;
  827. if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
  828. range->max_qual.qual = 70; /* what is correct max? This was not
  829. * documented exactly. At least
  830. * 69 has been observed. */
  831. range->max_qual.level = 0; /* dB */
  832. range->max_qual.noise = 0; /* dB */
  833. /* What would be suitable values for "average/typical" qual? */
  834. range->avg_qual.qual = 20;
  835. range->avg_qual.level = -60;
  836. range->avg_qual.noise = -95;
  837. } else {
  838. range->max_qual.qual = 92; /* 0 .. 92 */
  839. range->max_qual.level = 154; /* 27 .. 154 */
  840. range->max_qual.noise = 154; /* 27 .. 154 */
  841. }
  842. range->sensitivity = 3;
  843. range->max_encoding_tokens = WEP_KEYS;
  844. range->num_encoding_sizes = 2;
  845. range->encoding_size[0] = 5;
  846. range->encoding_size[1] = 13;
  847. over2 = 0;
  848. len = prism2_get_datarates(dev, rates);
  849. range->num_bitrates = 0;
  850. for (i = 0; i < len; i++) {
  851. if (range->num_bitrates < IW_MAX_BITRATES) {
  852. range->bitrate[range->num_bitrates] =
  853. rates[i] * 500000;
  854. range->num_bitrates++;
  855. }
  856. if (rates[i] == 0x0b || rates[i] == 0x16)
  857. over2 = 1;
  858. }
  859. /* estimated maximum TCP throughput values (bps) */
  860. range->throughput = over2 ? 5500000 : 1500000;
  861. range->min_rts = 0;
  862. range->max_rts = 2347;
  863. range->min_frag = 256;
  864. range->max_frag = 2346;
  865. /* Event capability (kernel + driver) */
  866. range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
  867. IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
  868. IW_EVENT_CAPA_MASK(SIOCGIWAP) |
  869. IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
  870. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  871. range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVTXDROP) |
  872. IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
  873. IW_EVENT_CAPA_MASK(IWEVREGISTERED) |
  874. IW_EVENT_CAPA_MASK(IWEVEXPIRED));
  875. range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
  876. IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
  877. if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
  878. range->scan_capa = IW_SCAN_CAPA_ESSID;
  879. return 0;
  880. }
  881. static int hostap_monitor_mode_enable(local_info_t *local)
  882. {
  883. struct net_device *dev = local->dev;
  884. printk(KERN_DEBUG "Enabling monitor mode\n");
  885. hostap_monitor_set_type(local);
  886. if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
  887. HFA384X_PORTTYPE_PSEUDO_IBSS)) {
  888. printk(KERN_DEBUG "Port type setting for monitor mode "
  889. "failed\n");
  890. return -EOPNOTSUPP;
  891. }
  892. /* Host decrypt is needed to get the IV and ICV fields;
  893. * however, monitor mode seems to remove WEP flag from frame
  894. * control field */
  895. if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS,
  896. HFA384X_WEPFLAGS_HOSTENCRYPT |
  897. HFA384X_WEPFLAGS_HOSTDECRYPT)) {
  898. printk(KERN_DEBUG "WEP flags setting failed\n");
  899. return -EOPNOTSUPP;
  900. }
  901. if (local->func->reset_port(dev) ||
  902. local->func->cmd(dev, HFA384X_CMDCODE_TEST |
  903. (HFA384X_TEST_MONITOR << 8),
  904. 0, NULL, NULL)) {
  905. printk(KERN_DEBUG "Setting monitor mode failed\n");
  906. return -EOPNOTSUPP;
  907. }
  908. return 0;
  909. }
  910. static int hostap_monitor_mode_disable(local_info_t *local)
  911. {
  912. struct net_device *dev = local->ddev;
  913. if (dev == NULL)
  914. return -1;
  915. printk(KERN_DEBUG "%s: Disabling monitor mode\n", dev->name);
  916. dev->type = ARPHRD_ETHER;
  917. if (local->func->cmd(dev, HFA384X_CMDCODE_TEST |
  918. (HFA384X_TEST_STOP << 8),
  919. 0, NULL, NULL))
  920. return -1;
  921. return hostap_set_encryption(local);
  922. }
  923. static int prism2_ioctl_siwmode(struct net_device *dev,
  924. struct iw_request_info *info,
  925. __u32 *mode, char *extra)
  926. {
  927. struct hostap_interface *iface;
  928. local_info_t *local;
  929. int double_reset = 0;
  930. iface = netdev_priv(dev);
  931. local = iface->local;
  932. if (*mode != IW_MODE_ADHOC && *mode != IW_MODE_INFRA &&
  933. *mode != IW_MODE_MASTER && *mode != IW_MODE_REPEAT &&
  934. *mode != IW_MODE_MONITOR)
  935. return -EOPNOTSUPP;
  936. #ifdef PRISM2_NO_STATION_MODES
  937. if (*mode == IW_MODE_ADHOC || *mode == IW_MODE_INFRA)
  938. return -EOPNOTSUPP;
  939. #endif /* PRISM2_NO_STATION_MODES */
  940. if (*mode == local->iw_mode)
  941. return 0;
  942. if (*mode == IW_MODE_MASTER && local->essid[0] == '\0') {
  943. printk(KERN_WARNING "%s: empty SSID not allowed in Master "
  944. "mode\n", dev->name);
  945. return -EINVAL;
  946. }
  947. if (local->iw_mode == IW_MODE_MONITOR)
  948. hostap_monitor_mode_disable(local);
  949. if ((local->iw_mode == IW_MODE_ADHOC ||
  950. local->iw_mode == IW_MODE_MONITOR) && *mode == IW_MODE_MASTER) {
  951. /* There seems to be a firmware bug in at least STA f/w v1.5.6
  952. * that leaves beacon frames to use IBSS type when moving from
  953. * IBSS to Host AP mode. Doing double Port0 reset seems to be
  954. * enough to workaround this. */
  955. double_reset = 1;
  956. }
  957. printk(KERN_DEBUG "prism2: %s: operating mode changed "
  958. "%d -> %d\n", dev->name, local->iw_mode, *mode);
  959. local->iw_mode = *mode;
  960. if (local->iw_mode == IW_MODE_MONITOR)
  961. hostap_monitor_mode_enable(local);
  962. else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
  963. !local->fw_encrypt_ok) {
  964. printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
  965. "a workaround for firmware bug in Host AP mode WEP\n",
  966. dev->name);
  967. local->host_encrypt = 1;
  968. }
  969. if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
  970. hostap_get_porttype(local)))
  971. return -EOPNOTSUPP;
  972. if (local->func->reset_port(dev))
  973. return -EINVAL;
  974. if (double_reset && local->func->reset_port(dev))
  975. return -EINVAL;
  976. if (local->iw_mode != IW_MODE_INFRA && local->iw_mode != IW_MODE_ADHOC)
  977. {
  978. /* netif_carrier is used only in client modes for now, so make
  979. * sure carrier is on when moving to non-client modes. */
  980. netif_carrier_on(local->dev);
  981. netif_carrier_on(local->ddev);
  982. }
  983. return 0;
  984. }
  985. static int prism2_ioctl_giwmode(struct net_device *dev,
  986. struct iw_request_info *info,
  987. __u32 *mode, char *extra)
  988. {
  989. struct hostap_interface *iface;
  990. local_info_t *local;
  991. iface = netdev_priv(dev);
  992. local = iface->local;
  993. switch (iface->type) {
  994. case HOSTAP_INTERFACE_STA:
  995. *mode = IW_MODE_INFRA;
  996. break;
  997. case HOSTAP_INTERFACE_WDS:
  998. *mode = IW_MODE_REPEAT;
  999. break;
  1000. default:
  1001. *mode = local->iw_mode;
  1002. break;
  1003. }
  1004. return 0;
  1005. }
  1006. static int prism2_ioctl_siwpower(struct net_device *dev,
  1007. struct iw_request_info *info,
  1008. struct iw_param *wrq, char *extra)
  1009. {
  1010. #ifdef PRISM2_NO_STATION_MODES
  1011. return -EOPNOTSUPP;
  1012. #else /* PRISM2_NO_STATION_MODES */
  1013. int ret = 0;
  1014. if (wrq->disabled)
  1015. return hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 0);
  1016. switch (wrq->flags & IW_POWER_MODE) {
  1017. case IW_POWER_UNICAST_R:
  1018. ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 0);
  1019. if (ret)
  1020. return ret;
  1021. ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
  1022. if (ret)
  1023. return ret;
  1024. break;
  1025. case IW_POWER_ALL_R:
  1026. ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 1);
  1027. if (ret)
  1028. return ret;
  1029. ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
  1030. if (ret)
  1031. return ret;
  1032. break;
  1033. case IW_POWER_ON:
  1034. break;
  1035. default:
  1036. return -EINVAL;
  1037. }
  1038. if (wrq->flags & IW_POWER_TIMEOUT) {
  1039. ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
  1040. if (ret)
  1041. return ret;
  1042. ret = hostap_set_word(dev, HFA384X_RID_CNFPMHOLDOVERDURATION,
  1043. wrq->value / 1024);
  1044. if (ret)
  1045. return ret;
  1046. }
  1047. if (wrq->flags & IW_POWER_PERIOD) {
  1048. ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
  1049. if (ret)
  1050. return ret;
  1051. ret = hostap_set_word(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
  1052. wrq->value / 1024);
  1053. if (ret)
  1054. return ret;
  1055. }
  1056. return ret;
  1057. #endif /* PRISM2_NO_STATION_MODES */
  1058. }
  1059. static int prism2_ioctl_giwpower(struct net_device *dev,
  1060. struct iw_request_info *info,
  1061. struct iw_param *rrq, char *extra)
  1062. {
  1063. #ifdef PRISM2_NO_STATION_MODES
  1064. return -EOPNOTSUPP;
  1065. #else /* PRISM2_NO_STATION_MODES */
  1066. struct hostap_interface *iface;
  1067. local_info_t *local;
  1068. __le16 enable, mcast;
  1069. iface = netdev_priv(dev);
  1070. local = iface->local;
  1071. if (local->func->get_rid(dev, HFA384X_RID_CNFPMENABLED, &enable, 2, 1)
  1072. < 0)
  1073. return -EINVAL;
  1074. if (!le16_to_cpu(enable)) {
  1075. rrq->disabled = 1;
  1076. return 0;
  1077. }
  1078. rrq->disabled = 0;
  1079. if ((rrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  1080. __le16 timeout;
  1081. if (local->func->get_rid(dev,
  1082. HFA384X_RID_CNFPMHOLDOVERDURATION,
  1083. &timeout, 2, 1) < 0)
  1084. return -EINVAL;
  1085. rrq->flags = IW_POWER_TIMEOUT;
  1086. rrq->value = le16_to_cpu(timeout) * 1024;
  1087. } else {
  1088. __le16 period;
  1089. if (local->func->get_rid(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
  1090. &period, 2, 1) < 0)
  1091. return -EINVAL;
  1092. rrq->flags = IW_POWER_PERIOD;
  1093. rrq->value = le16_to_cpu(period) * 1024;
  1094. }
  1095. if (local->func->get_rid(dev, HFA384X_RID_CNFMULTICASTRECEIVE, &mcast,
  1096. 2, 1) < 0)
  1097. return -EINVAL;
  1098. if (le16_to_cpu(mcast))
  1099. rrq->flags |= IW_POWER_ALL_R;
  1100. else
  1101. rrq->flags |= IW_POWER_UNICAST_R;
  1102. return 0;
  1103. #endif /* PRISM2_NO_STATION_MODES */
  1104. }
  1105. static int prism2_ioctl_siwretry(struct net_device *dev,
  1106. struct iw_request_info *info,
  1107. struct iw_param *rrq, char *extra)
  1108. {
  1109. struct hostap_interface *iface;
  1110. local_info_t *local;
  1111. iface = netdev_priv(dev);
  1112. local = iface->local;
  1113. if (rrq->disabled)
  1114. return -EINVAL;
  1115. /* setting retry limits is not supported with the current station
  1116. * firmware code; simulate this with alternative retry count for now */
  1117. if (rrq->flags == IW_RETRY_LIMIT) {
  1118. if (rrq->value < 0) {
  1119. /* disable manual retry count setting and use firmware
  1120. * defaults */
  1121. local->manual_retry_count = -1;
  1122. local->tx_control &= ~HFA384X_TX_CTRL_ALT_RTRY;
  1123. } else {
  1124. if (hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
  1125. rrq->value)) {
  1126. printk(KERN_DEBUG "%s: Alternate retry count "
  1127. "setting to %d failed\n",
  1128. dev->name, rrq->value);
  1129. return -EOPNOTSUPP;
  1130. }
  1131. local->manual_retry_count = rrq->value;
  1132. local->tx_control |= HFA384X_TX_CTRL_ALT_RTRY;
  1133. }
  1134. return 0;
  1135. }
  1136. return -EOPNOTSUPP;
  1137. #if 0
  1138. /* what could be done, if firmware would support this.. */
  1139. if (rrq->flags & IW_RETRY_LIMIT) {
  1140. if (rrq->flags & IW_RETRY_LONG)
  1141. HFA384X_RID_LONGRETRYLIMIT = rrq->value;
  1142. else if (rrq->flags & IW_RETRY_SHORT)
  1143. HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
  1144. else {
  1145. HFA384X_RID_LONGRETRYLIMIT = rrq->value;
  1146. HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
  1147. }
  1148. }
  1149. if (rrq->flags & IW_RETRY_LIFETIME) {
  1150. HFA384X_RID_MAXTRANSMITLIFETIME = rrq->value / 1024;
  1151. }
  1152. return 0;
  1153. #endif /* 0 */
  1154. }
  1155. static int prism2_ioctl_giwretry(struct net_device *dev,
  1156. struct iw_request_info *info,
  1157. struct iw_param *rrq, char *extra)
  1158. {
  1159. struct hostap_interface *iface;
  1160. local_info_t *local;
  1161. __le16 shortretry, longretry, lifetime, altretry;
  1162. iface = netdev_priv(dev);
  1163. local = iface->local;
  1164. if (local->func->get_rid(dev, HFA384X_RID_SHORTRETRYLIMIT, &shortretry,
  1165. 2, 1) < 0 ||
  1166. local->func->get_rid(dev, HFA384X_RID_LONGRETRYLIMIT, &longretry,
  1167. 2, 1) < 0 ||
  1168. local->func->get_rid(dev, HFA384X_RID_MAXTRANSMITLIFETIME,
  1169. &lifetime, 2, 1) < 0)
  1170. return -EINVAL;
  1171. rrq->disabled = 0;
  1172. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  1173. rrq->flags = IW_RETRY_LIFETIME;
  1174. rrq->value = le16_to_cpu(lifetime) * 1024;
  1175. } else {
  1176. if (local->manual_retry_count >= 0) {
  1177. rrq->flags = IW_RETRY_LIMIT;
  1178. if (local->func->get_rid(dev,
  1179. HFA384X_RID_CNFALTRETRYCOUNT,
  1180. &altretry, 2, 1) >= 0)
  1181. rrq->value = le16_to_cpu(altretry);
  1182. else
  1183. rrq->value = local->manual_retry_count;
  1184. } else if ((rrq->flags & IW_RETRY_LONG)) {
  1185. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
  1186. rrq->value = le16_to_cpu(longretry);
  1187. } else {
  1188. rrq->flags = IW_RETRY_LIMIT;
  1189. rrq->value = le16_to_cpu(shortretry);
  1190. if (shortretry != longretry)
  1191. rrq->flags |= IW_RETRY_SHORT;
  1192. }
  1193. }
  1194. return 0;
  1195. }
  1196. /* Note! This TX power controlling is experimental and should not be used in
  1197. * production use. It just sets raw power register and does not use any kind of
  1198. * feedback information from the measured TX power (CR58). This is now
  1199. * commented out to make sure that it is not used by accident. TX power
  1200. * configuration will be enabled again after proper algorithm using feedback
  1201. * has been implemented. */
  1202. #ifdef RAW_TXPOWER_SETTING
  1203. /* Map HFA386x's CR31 to and from dBm with some sort of ad hoc mapping..
  1204. * This version assumes following mapping:
  1205. * CR31 is 7-bit value with -64 to +63 range.
  1206. * -64 is mapped into +20dBm and +63 into -43dBm.
  1207. * This is certainly not an exact mapping for every card, but at least
  1208. * increasing dBm value should correspond to increasing TX power.
  1209. */
  1210. static int prism2_txpower_hfa386x_to_dBm(u16 val)
  1211. {
  1212. signed char tmp;
  1213. if (val > 255)
  1214. val = 255;
  1215. tmp = val;
  1216. tmp >>= 2;
  1217. return -12 - tmp;
  1218. }
  1219. static u16 prism2_txpower_dBm_to_hfa386x(int val)
  1220. {
  1221. signed char tmp;
  1222. if (val > 20)
  1223. return 128;
  1224. else if (val < -43)
  1225. return 127;
  1226. tmp = val;
  1227. tmp = -12 - tmp;
  1228. tmp <<= 2;
  1229. return (unsigned char) tmp;
  1230. }
  1231. #endif /* RAW_TXPOWER_SETTING */
  1232. static int prism2_ioctl_siwtxpow(struct net_device *dev,
  1233. struct iw_request_info *info,
  1234. struct iw_param *rrq, char *extra)
  1235. {
  1236. struct hostap_interface *iface;
  1237. local_info_t *local;
  1238. #ifdef RAW_TXPOWER_SETTING
  1239. char *tmp;
  1240. #endif
  1241. u16 val;
  1242. int ret = 0;
  1243. iface = netdev_priv(dev);
  1244. local = iface->local;
  1245. if (rrq->disabled) {
  1246. if (local->txpower_type != PRISM2_TXPOWER_OFF) {
  1247. val = 0xff; /* use all standby and sleep modes */
  1248. ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
  1249. HFA386X_CR_A_D_TEST_MODES2,
  1250. &val, NULL);
  1251. printk(KERN_DEBUG "%s: Turning radio off: %s\n",
  1252. dev->name, ret ? "failed" : "OK");
  1253. local->txpower_type = PRISM2_TXPOWER_OFF;
  1254. }
  1255. return (ret ? -EOPNOTSUPP : 0);
  1256. }
  1257. if (local->txpower_type == PRISM2_TXPOWER_OFF) {
  1258. val = 0; /* disable all standby and sleep modes */
  1259. ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
  1260. HFA386X_CR_A_D_TEST_MODES2, &val, NULL);
  1261. printk(KERN_DEBUG "%s: Turning radio on: %s\n",
  1262. dev->name, ret ? "failed" : "OK");
  1263. local->txpower_type = PRISM2_TXPOWER_UNKNOWN;
  1264. }
  1265. #ifdef RAW_TXPOWER_SETTING
  1266. if (!rrq->fixed && local->txpower_type != PRISM2_TXPOWER_AUTO) {
  1267. printk(KERN_DEBUG "Setting ALC on\n");
  1268. val = HFA384X_TEST_CFG_BIT_ALC;
  1269. local->func->cmd(dev, HFA384X_CMDCODE_TEST |
  1270. (HFA384X_TEST_CFG_BITS << 8), 1, &val, NULL);
  1271. local->txpower_type = PRISM2_TXPOWER_AUTO;
  1272. return 0;
  1273. }
  1274. if (local->txpower_type != PRISM2_TXPOWER_FIXED) {
  1275. printk(KERN_DEBUG "Setting ALC off\n");
  1276. val = HFA384X_TEST_CFG_BIT_ALC;
  1277. local->func->cmd(dev, HFA384X_CMDCODE_TEST |
  1278. (HFA384X_TEST_CFG_BITS << 8), 0, &val, NULL);
  1279. local->txpower_type = PRISM2_TXPOWER_FIXED;
  1280. }
  1281. if (rrq->flags == IW_TXPOW_DBM)
  1282. tmp = "dBm";
  1283. else if (rrq->flags == IW_TXPOW_MWATT)
  1284. tmp = "mW";
  1285. else
  1286. tmp = "UNKNOWN";
  1287. printk(KERN_DEBUG "Setting TX power to %d %s\n", rrq->value, tmp);
  1288. if (rrq->flags != IW_TXPOW_DBM) {
  1289. printk("SIOCSIWTXPOW with mW is not supported; use dBm\n");
  1290. return -EOPNOTSUPP;
  1291. }
  1292. local->txpower = rrq->value;
  1293. val = prism2_txpower_dBm_to_hfa386x(local->txpower);
  1294. if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
  1295. HFA386X_CR_MANUAL_TX_POWER, &val, NULL))
  1296. ret = -EOPNOTSUPP;
  1297. #else /* RAW_TXPOWER_SETTING */
  1298. if (rrq->fixed)
  1299. ret = -EOPNOTSUPP;
  1300. #endif /* RAW_TXPOWER_SETTING */
  1301. return ret;
  1302. }
  1303. static int prism2_ioctl_giwtxpow(struct net_device *dev,
  1304. struct iw_request_info *info,
  1305. struct iw_param *rrq, char *extra)
  1306. {
  1307. #ifdef RAW_TXPOWER_SETTING
  1308. struct hostap_interface *iface;
  1309. local_info_t *local;
  1310. u16 resp0;
  1311. iface = netdev_priv(dev);
  1312. local = iface->local;
  1313. rrq->flags = IW_TXPOW_DBM;
  1314. rrq->disabled = 0;
  1315. rrq->fixed = 0;
  1316. if (local->txpower_type == PRISM2_TXPOWER_AUTO) {
  1317. if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
  1318. HFA386X_CR_MANUAL_TX_POWER,
  1319. NULL, &resp0) == 0) {
  1320. rrq->value = prism2_txpower_hfa386x_to_dBm(resp0);
  1321. } else {
  1322. /* Could not get real txpower; guess 15 dBm */
  1323. rrq->value = 15;
  1324. }
  1325. } else if (local->txpower_type == PRISM2_TXPOWER_OFF) {
  1326. rrq->value = 0;
  1327. rrq->disabled = 1;
  1328. } else if (local->txpower_type == PRISM2_TXPOWER_FIXED) {
  1329. rrq->value = local->txpower;
  1330. rrq->fixed = 1;
  1331. } else {
  1332. printk("SIOCGIWTXPOW - unknown txpower_type=%d\n",
  1333. local->txpower_type);
  1334. }
  1335. return 0;
  1336. #else /* RAW_TXPOWER_SETTING */
  1337. return -EOPNOTSUPP;
  1338. #endif /* RAW_TXPOWER_SETTING */
  1339. }
  1340. #ifndef PRISM2_NO_STATION_MODES
  1341. /* HostScan request works with and without host_roaming mode. In addition, it
  1342. * does not break current association. However, it requires newer station
  1343. * firmware version (>= 1.3.1) than scan request. */
  1344. static int prism2_request_hostscan(struct net_device *dev,
  1345. u8 *ssid, u8 ssid_len)
  1346. {
  1347. struct hostap_interface *iface;
  1348. local_info_t *local;
  1349. struct hfa384x_hostscan_request scan_req;
  1350. iface = netdev_priv(dev);
  1351. local = iface->local;
  1352. memset(&scan_req, 0, sizeof(scan_req));
  1353. scan_req.channel_list = cpu_to_le16(local->channel_mask &
  1354. local->scan_channel_mask);
  1355. scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS);
  1356. if (ssid) {
  1357. if (ssid_len > 32)
  1358. return -EINVAL;
  1359. scan_req.target_ssid_len = cpu_to_le16(ssid_len);
  1360. memcpy(scan_req.target_ssid, ssid, ssid_len);
  1361. }
  1362. if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
  1363. sizeof(scan_req))) {
  1364. printk(KERN_DEBUG "%s: HOSTSCAN failed\n", dev->name);
  1365. return -EINVAL;
  1366. }
  1367. return 0;
  1368. }
  1369. static int prism2_request_scan(struct net_device *dev)
  1370. {
  1371. struct hostap_interface *iface;
  1372. local_info_t *local;
  1373. struct hfa384x_scan_request scan_req;
  1374. int ret = 0;
  1375. iface = netdev_priv(dev);
  1376. local = iface->local;
  1377. memset(&scan_req, 0, sizeof(scan_req));
  1378. scan_req.channel_list = cpu_to_le16(local->channel_mask &
  1379. local->scan_channel_mask);
  1380. scan_req.txrate = cpu_to_le16(HFA384X_RATES_1MBPS);
  1381. /* FIX:
  1382. * It seems to be enough to set roaming mode for a short moment to
  1383. * host-based and then setup scanrequest data and return the mode to
  1384. * firmware-based.
  1385. *
  1386. * Master mode would need to drop to Managed mode for a short while
  1387. * to make scanning work.. Or sweep through the different channels and
  1388. * use passive scan based on beacons. */
  1389. if (!local->host_roaming)
  1390. hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
  1391. HFA384X_ROAMING_HOST);
  1392. if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, &scan_req,
  1393. sizeof(scan_req))) {
  1394. printk(KERN_DEBUG "SCANREQUEST failed\n");
  1395. ret = -EINVAL;
  1396. }
  1397. if (!local->host_roaming)
  1398. hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
  1399. HFA384X_ROAMING_FIRMWARE);
  1400. return ret;
  1401. }
  1402. #else /* !PRISM2_NO_STATION_MODES */
  1403. static inline int prism2_request_hostscan(struct net_device *dev,
  1404. u8 *ssid, u8 ssid_len)
  1405. {
  1406. return -EOPNOTSUPP;
  1407. }
  1408. static inline int prism2_request_scan(struct net_device *dev)
  1409. {
  1410. return -EOPNOTSUPP;
  1411. }
  1412. #endif /* !PRISM2_NO_STATION_MODES */
  1413. static int prism2_ioctl_siwscan(struct net_device *dev,
  1414. struct iw_request_info *info,
  1415. struct iw_point *data, char *extra)
  1416. {
  1417. struct hostap_interface *iface;
  1418. local_info_t *local;
  1419. int ret;
  1420. u8 *ssid = NULL, ssid_len = 0;
  1421. struct iw_scan_req *req = (struct iw_scan_req *) extra;
  1422. iface = netdev_priv(dev);
  1423. local = iface->local;
  1424. if (data->length < sizeof(struct iw_scan_req))
  1425. req = NULL;
  1426. if (local->iw_mode == IW_MODE_MASTER) {
  1427. /* In master mode, we just return the results of our local
  1428. * tables, so we don't need to start anything...
  1429. * Jean II */
  1430. data->length = 0;
  1431. return 0;
  1432. }
  1433. if (!local->dev_enabled)
  1434. return -ENETDOWN;
  1435. if (req && data->flags & IW_SCAN_THIS_ESSID) {
  1436. ssid = req->essid;
  1437. ssid_len = req->essid_len;
  1438. if (ssid_len &&
  1439. ((local->iw_mode != IW_MODE_INFRA &&
  1440. local->iw_mode != IW_MODE_ADHOC) ||
  1441. (local->sta_fw_ver < PRISM2_FW_VER(1,3,1))))
  1442. return -EOPNOTSUPP;
  1443. }
  1444. if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
  1445. ret = prism2_request_hostscan(dev, ssid, ssid_len);
  1446. else
  1447. ret = prism2_request_scan(dev);
  1448. if (ret == 0)
  1449. local->scan_timestamp = jiffies;
  1450. /* Could inquire F101, F103 or wait for SIOCGIWSCAN and read RID */
  1451. return ret;
  1452. }
  1453. #ifndef PRISM2_NO_STATION_MODES
  1454. static char * __prism2_translate_scan(local_info_t *local,
  1455. struct iw_request_info *info,
  1456. struct hfa384x_hostscan_result *scan,
  1457. struct hostap_bss_info *bss,
  1458. char *current_ev, char *end_buf)
  1459. {
  1460. int i, chan;
  1461. struct iw_event iwe;
  1462. char *current_val;
  1463. u16 capabilities;
  1464. u8 *pos;
  1465. u8 *ssid, *bssid;
  1466. size_t ssid_len;
  1467. char *buf;
  1468. if (bss) {
  1469. ssid = bss->ssid;
  1470. ssid_len = bss->ssid_len;
  1471. bssid = bss->bssid;
  1472. } else {
  1473. ssid = scan->ssid;
  1474. ssid_len = le16_to_cpu(scan->ssid_len);
  1475. bssid = scan->bssid;
  1476. }
  1477. if (ssid_len > 32)
  1478. ssid_len = 32;
  1479. /* First entry *MUST* be the AP MAC address */
  1480. memset(&iwe, 0, sizeof(iwe));
  1481. iwe.cmd = SIOCGIWAP;
  1482. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  1483. memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN);
  1484. current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
  1485. IW_EV_ADDR_LEN);
  1486. /* Other entries will be displayed in the order we give them */
  1487. memset(&iwe, 0, sizeof(iwe));
  1488. iwe.cmd = SIOCGIWESSID;
  1489. iwe.u.data.length = ssid_len;
  1490. iwe.u.data.flags = 1;
  1491. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1492. &iwe, ssid);
  1493. memset(&iwe, 0, sizeof(iwe));
  1494. iwe.cmd = SIOCGIWMODE;
  1495. if (bss) {
  1496. capabilities = bss->capab_info;
  1497. } else {
  1498. capabilities = le16_to_cpu(scan->capability);
  1499. }
  1500. if (capabilities & (WLAN_CAPABILITY_ESS |
  1501. WLAN_CAPABILITY_IBSS)) {
  1502. if (capabilities & WLAN_CAPABILITY_ESS)
  1503. iwe.u.mode = IW_MODE_MASTER;
  1504. else
  1505. iwe.u.mode = IW_MODE_ADHOC;
  1506. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1507. &iwe, IW_EV_UINT_LEN);
  1508. }
  1509. memset(&iwe, 0, sizeof(iwe));
  1510. iwe.cmd = SIOCGIWFREQ;
  1511. if (scan) {
  1512. chan = le16_to_cpu(scan->chid);
  1513. } else if (bss) {
  1514. chan = bss->chan;
  1515. } else {
  1516. chan = 0;
  1517. }
  1518. if (chan > 0) {
  1519. iwe.u.freq.m = freq_list[chan - 1] * 100000;
  1520. iwe.u.freq.e = 1;
  1521. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1522. &iwe, IW_EV_FREQ_LEN);
  1523. }
  1524. if (scan) {
  1525. memset(&iwe, 0, sizeof(iwe));
  1526. iwe.cmd = IWEVQUAL;
  1527. if (local->last_scan_type == PRISM2_HOSTSCAN) {
  1528. iwe.u.qual.level = le16_to_cpu(scan->sl);
  1529. iwe.u.qual.noise = le16_to_cpu(scan->anl);
  1530. } else {
  1531. iwe.u.qual.level =
  1532. HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->sl));
  1533. iwe.u.qual.noise =
  1534. HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl));
  1535. }
  1536. iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED
  1537. | IW_QUAL_NOISE_UPDATED
  1538. | IW_QUAL_QUAL_INVALID
  1539. | IW_QUAL_DBM;
  1540. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1541. &iwe, IW_EV_QUAL_LEN);
  1542. }
  1543. memset(&iwe, 0, sizeof(iwe));
  1544. iwe.cmd = SIOCGIWENCODE;
  1545. if (capabilities & WLAN_CAPABILITY_PRIVACY)
  1546. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  1547. else
  1548. iwe.u.data.flags = IW_ENCODE_DISABLED;
  1549. iwe.u.data.length = 0;
  1550. current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, "");
  1551. /* TODO: add SuppRates into BSS table */
  1552. if (scan) {
  1553. memset(&iwe, 0, sizeof(iwe));
  1554. iwe.cmd = SIOCGIWRATE;
  1555. current_val = current_ev + iwe_stream_lcp_len(info);
  1556. pos = scan->sup_rates;
  1557. for (i = 0; i < sizeof(scan->sup_rates); i++) {
  1558. if (pos[i] == 0)
  1559. break;
  1560. /* Bit rate given in 500 kb/s units (+ 0x80) */
  1561. iwe.u.bitrate.value = ((pos[i] & 0x7f) * 500000);
  1562. current_val = iwe_stream_add_value(
  1563. info, current_ev, current_val, end_buf, &iwe,
  1564. IW_EV_PARAM_LEN);
  1565. }
  1566. /* Check if we added any event */
  1567. if ((current_val - current_ev) > iwe_stream_lcp_len(info))
  1568. current_ev = current_val;
  1569. }
  1570. /* TODO: add BeaconInt,resp_rate,atim into BSS table */
  1571. buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_ATOMIC);
  1572. if (buf && scan) {
  1573. memset(&iwe, 0, sizeof(iwe));
  1574. iwe.cmd = IWEVCUSTOM;
  1575. sprintf(buf, "bcn_int=%d", le16_to_cpu(scan->beacon_interval));
  1576. iwe.u.data.length = strlen(buf);
  1577. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1578. &iwe, buf);
  1579. memset(&iwe, 0, sizeof(iwe));
  1580. iwe.cmd = IWEVCUSTOM;
  1581. sprintf(buf, "resp_rate=%d", le16_to_cpu(scan->rate));
  1582. iwe.u.data.length = strlen(buf);
  1583. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1584. &iwe, buf);
  1585. if (local->last_scan_type == PRISM2_HOSTSCAN &&
  1586. (capabilities & WLAN_CAPABILITY_IBSS)) {
  1587. memset(&iwe, 0, sizeof(iwe));
  1588. iwe.cmd = IWEVCUSTOM;
  1589. sprintf(buf, "atim=%d", le16_to_cpu(scan->atim));
  1590. iwe.u.data.length = strlen(buf);
  1591. current_ev = iwe_stream_add_point(info, current_ev,
  1592. end_buf, &iwe, buf);
  1593. }
  1594. }
  1595. kfree(buf);
  1596. if (bss && bss->wpa_ie_len > 0 && bss->wpa_ie_len <= MAX_WPA_IE_LEN) {
  1597. memset(&iwe, 0, sizeof(iwe));
  1598. iwe.cmd = IWEVGENIE;
  1599. iwe.u.data.length = bss->wpa_ie_len;
  1600. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1601. &iwe, bss->wpa_ie);
  1602. }
  1603. if (bss && bss->rsn_ie_len > 0 && bss->rsn_ie_len <= MAX_WPA_IE_LEN) {
  1604. memset(&iwe, 0, sizeof(iwe));
  1605. iwe.cmd = IWEVGENIE;
  1606. iwe.u.data.length = bss->rsn_ie_len;
  1607. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1608. &iwe, bss->rsn_ie);
  1609. }
  1610. return current_ev;
  1611. }
  1612. /* Translate scan data returned from the card to a card independent
  1613. * format that the Wireless Tools will understand - Jean II */
  1614. static inline int prism2_translate_scan(local_info_t *local,
  1615. struct iw_request_info *info,
  1616. char *buffer, int buflen)
  1617. {
  1618. struct hfa384x_hostscan_result *scan;
  1619. int entry, hostscan;
  1620. char *current_ev = buffer;
  1621. char *end_buf = buffer + buflen;
  1622. struct list_head *ptr;
  1623. spin_lock_bh(&local->lock);
  1624. list_for_each(ptr, &local->bss_list) {
  1625. struct hostap_bss_info *bss;
  1626. bss = list_entry(ptr, struct hostap_bss_info, list);
  1627. bss->included = 0;
  1628. }
  1629. hostscan = local->last_scan_type == PRISM2_HOSTSCAN;
  1630. for (entry = 0; entry < local->last_scan_results_count; entry++) {
  1631. int found = 0;
  1632. scan = &local->last_scan_results[entry];
  1633. /* Report every SSID if the AP is using multiple SSIDs. If no
  1634. * BSS record is found (e.g., when WPA mode is disabled),
  1635. * report the AP once. */
  1636. list_for_each(ptr, &local->bss_list) {
  1637. struct hostap_bss_info *bss;
  1638. bss = list_entry(ptr, struct hostap_bss_info, list);
  1639. if (ether_addr_equal(bss->bssid, scan->bssid)) {
  1640. bss->included = 1;
  1641. current_ev = __prism2_translate_scan(
  1642. local, info, scan, bss, current_ev,
  1643. end_buf);
  1644. found++;
  1645. }
  1646. }
  1647. if (!found) {
  1648. current_ev = __prism2_translate_scan(
  1649. local, info, scan, NULL, current_ev, end_buf);
  1650. }
  1651. /* Check if there is space for one more entry */
  1652. if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
  1653. /* Ask user space to try again with a bigger buffer */
  1654. spin_unlock_bh(&local->lock);
  1655. return -E2BIG;
  1656. }
  1657. }
  1658. /* Prism2 firmware has limits (32 at least in some versions) for number
  1659. * of BSSes in scan results. Extend this limit by using local BSS list.
  1660. */
  1661. list_for_each(ptr, &local->bss_list) {
  1662. struct hostap_bss_info *bss;
  1663. bss = list_entry(ptr, struct hostap_bss_info, list);
  1664. if (bss->included)
  1665. continue;
  1666. current_ev = __prism2_translate_scan(local, info, NULL, bss,
  1667. current_ev, end_buf);
  1668. /* Check if there is space for one more entry */
  1669. if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
  1670. /* Ask user space to try again with a bigger buffer */
  1671. spin_unlock_bh(&local->lock);
  1672. return -E2BIG;
  1673. }
  1674. }
  1675. spin_unlock_bh(&local->lock);
  1676. return current_ev - buffer;
  1677. }
  1678. #endif /* PRISM2_NO_STATION_MODES */
  1679. static inline int prism2_ioctl_giwscan_sta(struct net_device *dev,
  1680. struct iw_request_info *info,
  1681. struct iw_point *data, char *extra)
  1682. {
  1683. #ifdef PRISM2_NO_STATION_MODES
  1684. return -EOPNOTSUPP;
  1685. #else /* PRISM2_NO_STATION_MODES */
  1686. struct hostap_interface *iface;
  1687. local_info_t *local;
  1688. int res;
  1689. iface = netdev_priv(dev);
  1690. local = iface->local;
  1691. /* Wait until the scan is finished. We can probably do better
  1692. * than that - Jean II */
  1693. if (local->scan_timestamp &&
  1694. time_before(jiffies, local->scan_timestamp + 3 * HZ)) {
  1695. /* Important note : we don't want to block the caller
  1696. * until results are ready for various reasons.
  1697. * First, managing wait queues is complex and racy
  1698. * (there may be multiple simultaneous callers).
  1699. * Second, we grab some rtnetlink lock before coming
  1700. * here (in dev_ioctl()).
  1701. * Third, the caller can wait on the Wireless Event
  1702. * - Jean II */
  1703. return -EAGAIN;
  1704. }
  1705. local->scan_timestamp = 0;
  1706. res = prism2_translate_scan(local, info, extra, data->length);
  1707. if (res >= 0) {
  1708. data->length = res;
  1709. return 0;
  1710. } else {
  1711. data->length = 0;
  1712. return res;
  1713. }
  1714. #endif /* PRISM2_NO_STATION_MODES */
  1715. }
  1716. static int prism2_ioctl_giwscan(struct net_device *dev,
  1717. struct iw_request_info *info,
  1718. struct iw_point *data, char *extra)
  1719. {
  1720. struct hostap_interface *iface;
  1721. local_info_t *local;
  1722. int res;
  1723. iface = netdev_priv(dev);
  1724. local = iface->local;
  1725. if (local->iw_mode == IW_MODE_MASTER) {
  1726. /* In MASTER mode, it doesn't make sense to go around
  1727. * scanning the frequencies and make the stations we serve
  1728. * wait when what the user is really interested about is the
  1729. * list of stations and access points we are talking to.
  1730. * So, just extract results from our cache...
  1731. * Jean II */
  1732. /* Translate to WE format */
  1733. res = prism2_ap_translate_scan(dev, info, extra);
  1734. if (res >= 0) {
  1735. printk(KERN_DEBUG "Scan result translation succeeded "
  1736. "(length=%d)\n", res);
  1737. data->length = res;
  1738. return 0;
  1739. } else {
  1740. printk(KERN_DEBUG
  1741. "Scan result translation failed (res=%d)\n",
  1742. res);
  1743. data->length = 0;
  1744. return res;
  1745. }
  1746. } else {
  1747. /* Station mode */
  1748. return prism2_ioctl_giwscan_sta(dev, info, data, extra);
  1749. }
  1750. }
  1751. static const struct iw_priv_args prism2_priv[] = {
  1752. { PRISM2_IOCTL_MONITOR,
  1753. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor" },
  1754. { PRISM2_IOCTL_READMIF,
  1755. IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
  1756. IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "readmif" },
  1757. { PRISM2_IOCTL_WRITEMIF,
  1758. IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 2, 0, "writemif" },
  1759. { PRISM2_IOCTL_RESET,
  1760. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "reset" },
  1761. { PRISM2_IOCTL_INQUIRE,
  1762. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "inquire" },
  1763. { PRISM2_IOCTL_SET_RID_WORD,
  1764. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_rid_word" },
  1765. { PRISM2_IOCTL_MACCMD,
  1766. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maccmd" },
  1767. { PRISM2_IOCTL_WDS_ADD,
  1768. IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_add" },
  1769. { PRISM2_IOCTL_WDS_DEL,
  1770. IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_del" },
  1771. { PRISM2_IOCTL_ADDMAC,
  1772. IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "addmac" },
  1773. { PRISM2_IOCTL_DELMAC,
  1774. IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "delmac" },
  1775. { PRISM2_IOCTL_KICKMAC,
  1776. IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac" },
  1777. /* --- raw access to sub-ioctls --- */
  1778. { PRISM2_IOCTL_PRISM2_PARAM,
  1779. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "prism2_param" },
  1780. { PRISM2_IOCTL_GET_PRISM2_PARAM,
  1781. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1782. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprism2_param" },
  1783. /* --- sub-ioctls handlers --- */
  1784. { PRISM2_IOCTL_PRISM2_PARAM,
  1785. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" },
  1786. { PRISM2_IOCTL_GET_PRISM2_PARAM,
  1787. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" },
  1788. /* --- sub-ioctls definitions --- */
  1789. { PRISM2_PARAM_TXRATECTRL,
  1790. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "txratectrl" },
  1791. { PRISM2_PARAM_TXRATECTRL,
  1792. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettxratectrl" },
  1793. { PRISM2_PARAM_BEACON_INT,
  1794. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beacon_int" },
  1795. { PRISM2_PARAM_BEACON_INT,
  1796. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbeacon_int" },
  1797. #ifndef PRISM2_NO_STATION_MODES
  1798. { PRISM2_PARAM_PSEUDO_IBSS,
  1799. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "pseudo_ibss" },
  1800. { PRISM2_PARAM_PSEUDO_IBSS,
  1801. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpseudo_ibss" },
  1802. #endif /* PRISM2_NO_STATION_MODES */
  1803. { PRISM2_PARAM_ALC,
  1804. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "alc" },
  1805. { PRISM2_PARAM_ALC,
  1806. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getalc" },
  1807. { PRISM2_PARAM_DUMP,
  1808. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dump" },
  1809. { PRISM2_PARAM_DUMP,
  1810. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdump" },
  1811. { PRISM2_PARAM_OTHER_AP_POLICY,
  1812. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "other_ap_policy" },
  1813. { PRISM2_PARAM_OTHER_AP_POLICY,
  1814. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getother_ap_pol" },
  1815. { PRISM2_PARAM_AP_MAX_INACTIVITY,
  1816. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_inactivity" },
  1817. { PRISM2_PARAM_AP_MAX_INACTIVITY,
  1818. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_inactivi" },
  1819. { PRISM2_PARAM_AP_BRIDGE_PACKETS,
  1820. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bridge_packets" },
  1821. { PRISM2_PARAM_AP_BRIDGE_PACKETS,
  1822. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbridge_packe" },
  1823. { PRISM2_PARAM_DTIM_PERIOD,
  1824. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dtim_period" },
  1825. { PRISM2_PARAM_DTIM_PERIOD,
  1826. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdtim_period" },
  1827. { PRISM2_PARAM_AP_NULLFUNC_ACK,
  1828. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "nullfunc_ack" },
  1829. { PRISM2_PARAM_AP_NULLFUNC_ACK,
  1830. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getnullfunc_ack" },
  1831. { PRISM2_PARAM_MAX_WDS,
  1832. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_wds" },
  1833. { PRISM2_PARAM_MAX_WDS,
  1834. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_wds" },
  1835. { PRISM2_PARAM_AP_AUTOM_AP_WDS,
  1836. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "autom_ap_wds" },
  1837. { PRISM2_PARAM_AP_AUTOM_AP_WDS,
  1838. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getautom_ap_wds" },
  1839. { PRISM2_PARAM_AP_AUTH_ALGS,
  1840. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_auth_algs" },
  1841. { PRISM2_PARAM_AP_AUTH_ALGS,
  1842. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_auth_algs" },
  1843. { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
  1844. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "allow_fcserr" },
  1845. { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
  1846. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getallow_fcserr" },
  1847. { PRISM2_PARAM_HOST_ENCRYPT,
  1848. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_encrypt" },
  1849. { PRISM2_PARAM_HOST_ENCRYPT,
  1850. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_encrypt" },
  1851. { PRISM2_PARAM_HOST_DECRYPT,
  1852. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_decrypt" },
  1853. { PRISM2_PARAM_HOST_DECRYPT,
  1854. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_decrypt" },
  1855. #ifndef PRISM2_NO_STATION_MODES
  1856. { PRISM2_PARAM_HOST_ROAMING,
  1857. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_roaming" },
  1858. { PRISM2_PARAM_HOST_ROAMING,
  1859. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_roaming" },
  1860. #endif /* PRISM2_NO_STATION_MODES */
  1861. { PRISM2_PARAM_BCRX_STA_KEY,
  1862. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bcrx_sta_key" },
  1863. { PRISM2_PARAM_BCRX_STA_KEY,
  1864. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbcrx_sta_key" },
  1865. { PRISM2_PARAM_IEEE_802_1X,
  1866. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ieee_802_1x" },
  1867. { PRISM2_PARAM_IEEE_802_1X,
  1868. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getieee_802_1x" },
  1869. { PRISM2_PARAM_ANTSEL_TX,
  1870. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_tx" },
  1871. { PRISM2_PARAM_ANTSEL_TX,
  1872. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_tx" },
  1873. { PRISM2_PARAM_ANTSEL_RX,
  1874. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_rx" },
  1875. { PRISM2_PARAM_ANTSEL_RX,
  1876. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_rx" },
  1877. { PRISM2_PARAM_MONITOR_TYPE,
  1878. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor_type" },
  1879. { PRISM2_PARAM_MONITOR_TYPE,
  1880. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmonitor_type" },
  1881. { PRISM2_PARAM_WDS_TYPE,
  1882. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wds_type" },
  1883. { PRISM2_PARAM_WDS_TYPE,
  1884. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwds_type" },
  1885. { PRISM2_PARAM_HOSTSCAN,
  1886. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostscan" },
  1887. { PRISM2_PARAM_HOSTSCAN,
  1888. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostscan" },
  1889. { PRISM2_PARAM_AP_SCAN,
  1890. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_scan" },
  1891. { PRISM2_PARAM_AP_SCAN,
  1892. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_scan" },
  1893. { PRISM2_PARAM_ENH_SEC,
  1894. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enh_sec" },
  1895. { PRISM2_PARAM_ENH_SEC,
  1896. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getenh_sec" },
  1897. #ifdef PRISM2_IO_DEBUG
  1898. { PRISM2_PARAM_IO_DEBUG,
  1899. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "io_debug" },
  1900. { PRISM2_PARAM_IO_DEBUG,
  1901. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getio_debug" },
  1902. #endif /* PRISM2_IO_DEBUG */
  1903. { PRISM2_PARAM_BASIC_RATES,
  1904. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "basic_rates" },
  1905. { PRISM2_PARAM_BASIC_RATES,
  1906. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbasic_rates" },
  1907. { PRISM2_PARAM_OPER_RATES,
  1908. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oper_rates" },
  1909. { PRISM2_PARAM_OPER_RATES,
  1910. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getoper_rates" },
  1911. { PRISM2_PARAM_HOSTAPD,
  1912. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd" },
  1913. { PRISM2_PARAM_HOSTAPD,
  1914. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd" },
  1915. { PRISM2_PARAM_HOSTAPD_STA,
  1916. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd_sta" },
  1917. { PRISM2_PARAM_HOSTAPD_STA,
  1918. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd_sta" },
  1919. { PRISM2_PARAM_WPA,
  1920. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wpa" },
  1921. { PRISM2_PARAM_WPA,
  1922. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwpa" },
  1923. { PRISM2_PARAM_PRIVACY_INVOKED,
  1924. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "privacy_invoked" },
  1925. { PRISM2_PARAM_PRIVACY_INVOKED,
  1926. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprivacy_invo" },
  1927. { PRISM2_PARAM_TKIP_COUNTERMEASURES,
  1928. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "tkip_countermea" },
  1929. { PRISM2_PARAM_TKIP_COUNTERMEASURES,
  1930. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettkip_counter" },
  1931. { PRISM2_PARAM_DROP_UNENCRYPTED,
  1932. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "drop_unencrypte" },
  1933. { PRISM2_PARAM_DROP_UNENCRYPTED,
  1934. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdrop_unencry" },
  1935. { PRISM2_PARAM_SCAN_CHANNEL_MASK,
  1936. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "scan_channels" },
  1937. { PRISM2_PARAM_SCAN_CHANNEL_MASK,
  1938. 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getscan_channel" },
  1939. };
  1940. static int prism2_ioctl_priv_inquire(struct net_device *dev, int *i)
  1941. {
  1942. struct hostap_interface *iface;
  1943. local_info_t *local;
  1944. iface = netdev_priv(dev);
  1945. local = iface->local;
  1946. if (local->func->cmd(dev, HFA384X_CMDCODE_INQUIRE, *i, NULL, NULL))
  1947. return -EOPNOTSUPP;
  1948. return 0;
  1949. }
  1950. static int prism2_ioctl_priv_prism2_param(struct net_device *dev,
  1951. struct iw_request_info *info,
  1952. void *wrqu, char *extra)
  1953. {
  1954. struct hostap_interface *iface;
  1955. local_info_t *local;
  1956. int *i = (int *) extra;
  1957. int param = *i;
  1958. int value = *(i + 1);
  1959. int ret = 0;
  1960. u16 val;
  1961. iface = netdev_priv(dev);
  1962. local = iface->local;
  1963. switch (param) {
  1964. case PRISM2_PARAM_TXRATECTRL:
  1965. local->fw_tx_rate_control = value;
  1966. break;
  1967. case PRISM2_PARAM_BEACON_INT:
  1968. if (hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, value) ||
  1969. local->func->reset_port(dev))
  1970. ret = -EINVAL;
  1971. else
  1972. local->beacon_int = value;
  1973. break;
  1974. #ifndef PRISM2_NO_STATION_MODES
  1975. case PRISM2_PARAM_PSEUDO_IBSS:
  1976. if (value == local->pseudo_adhoc)
  1977. break;
  1978. if (value != 0 && value != 1) {
  1979. ret = -EINVAL;
  1980. break;
  1981. }
  1982. printk(KERN_DEBUG "prism2: %s: pseudo IBSS change %d -> %d\n",
  1983. dev->name, local->pseudo_adhoc, value);
  1984. local->pseudo_adhoc = value;
  1985. if (local->iw_mode != IW_MODE_ADHOC)
  1986. break;
  1987. if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
  1988. hostap_get_porttype(local))) {
  1989. ret = -EOPNOTSUPP;
  1990. break;
  1991. }
  1992. if (local->func->reset_port(dev))
  1993. ret = -EINVAL;
  1994. break;
  1995. #endif /* PRISM2_NO_STATION_MODES */
  1996. case PRISM2_PARAM_ALC:
  1997. printk(KERN_DEBUG "%s: %s ALC\n", dev->name,
  1998. value == 0 ? "Disabling" : "Enabling");
  1999. val = HFA384X_TEST_CFG_BIT_ALC;
  2000. local->func->cmd(dev, HFA384X_CMDCODE_TEST |
  2001. (HFA384X_TEST_CFG_BITS << 8),
  2002. value == 0 ? 0 : 1, &val, NULL);
  2003. break;
  2004. case PRISM2_PARAM_DUMP:
  2005. local->frame_dump = value;
  2006. break;
  2007. case PRISM2_PARAM_OTHER_AP_POLICY:
  2008. if (value < 0 || value > 3) {
  2009. ret = -EINVAL;
  2010. break;
  2011. }
  2012. if (local->ap != NULL)
  2013. local->ap->ap_policy = value;
  2014. break;
  2015. case PRISM2_PARAM_AP_MAX_INACTIVITY:
  2016. if (value < 0 || value > 7 * 24 * 60 * 60) {
  2017. ret = -EINVAL;
  2018. break;
  2019. }
  2020. if (local->ap != NULL)
  2021. local->ap->max_inactivity = value * HZ;
  2022. break;
  2023. case PRISM2_PARAM_AP_BRIDGE_PACKETS:
  2024. if (local->ap != NULL)
  2025. local->ap->bridge_packets = value;
  2026. break;
  2027. case PRISM2_PARAM_DTIM_PERIOD:
  2028. if (value < 0 || value > 65535) {
  2029. ret = -EINVAL;
  2030. break;
  2031. }
  2032. if (hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, value)
  2033. || local->func->reset_port(dev))
  2034. ret = -EINVAL;
  2035. else
  2036. local->dtim_period = value;
  2037. break;
  2038. case PRISM2_PARAM_AP_NULLFUNC_ACK:
  2039. if (local->ap != NULL)
  2040. local->ap->nullfunc_ack = value;
  2041. break;
  2042. case PRISM2_PARAM_MAX_WDS:
  2043. local->wds_max_connections = value;
  2044. break;
  2045. case PRISM2_PARAM_AP_AUTOM_AP_WDS:
  2046. if (local->ap != NULL) {
  2047. if (!local->ap->autom_ap_wds && value) {
  2048. /* add WDS link to all APs in STA table */
  2049. hostap_add_wds_links(local);
  2050. }
  2051. local->ap->autom_ap_wds = value;
  2052. }
  2053. break;
  2054. case PRISM2_PARAM_AP_AUTH_ALGS:
  2055. local->auth_algs = value;
  2056. if (hostap_set_auth_algs(local))
  2057. ret = -EINVAL;
  2058. break;
  2059. case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
  2060. local->monitor_allow_fcserr = value;
  2061. break;
  2062. case PRISM2_PARAM_HOST_ENCRYPT:
  2063. local->host_encrypt = value;
  2064. if (hostap_set_encryption(local) ||
  2065. local->func->reset_port(dev))
  2066. ret = -EINVAL;
  2067. break;
  2068. case PRISM2_PARAM_HOST_DECRYPT:
  2069. local->host_decrypt = value;
  2070. if (hostap_set_encryption(local) ||
  2071. local->func->reset_port(dev))
  2072. ret = -EINVAL;
  2073. break;
  2074. #ifndef PRISM2_NO_STATION_MODES
  2075. case PRISM2_PARAM_HOST_ROAMING:
  2076. if (value < 0 || value > 2) {
  2077. ret = -EINVAL;
  2078. break;
  2079. }
  2080. local->host_roaming = value;
  2081. if (hostap_set_roaming(local) || local->func->reset_port(dev))
  2082. ret = -EINVAL;
  2083. break;
  2084. #endif /* PRISM2_NO_STATION_MODES */
  2085. case PRISM2_PARAM_BCRX_STA_KEY:
  2086. local->bcrx_sta_key = value;
  2087. break;
  2088. case PRISM2_PARAM_IEEE_802_1X:
  2089. local->ieee_802_1x = value;
  2090. break;
  2091. case PRISM2_PARAM_ANTSEL_TX:
  2092. if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
  2093. ret = -EINVAL;
  2094. break;
  2095. }
  2096. local->antsel_tx = value;
  2097. hostap_set_antsel(local);
  2098. break;
  2099. case PRISM2_PARAM_ANTSEL_RX:
  2100. if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
  2101. ret = -EINVAL;
  2102. break;
  2103. }
  2104. local->antsel_rx = value;
  2105. hostap_set_antsel(local);
  2106. break;
  2107. case PRISM2_PARAM_MONITOR_TYPE:
  2108. if (value != PRISM2_MONITOR_80211 &&
  2109. value != PRISM2_MONITOR_CAPHDR &&
  2110. value != PRISM2_MONITOR_PRISM &&
  2111. value != PRISM2_MONITOR_RADIOTAP) {
  2112. ret = -EINVAL;
  2113. break;
  2114. }
  2115. local->monitor_type = value;
  2116. if (local->iw_mode == IW_MODE_MONITOR)
  2117. hostap_monitor_set_type(local);
  2118. break;
  2119. case PRISM2_PARAM_WDS_TYPE:
  2120. local->wds_type = value;
  2121. break;
  2122. case PRISM2_PARAM_HOSTSCAN:
  2123. {
  2124. struct hfa384x_hostscan_request scan_req;
  2125. u16 rate;
  2126. memset(&scan_req, 0, sizeof(scan_req));
  2127. scan_req.channel_list = cpu_to_le16(0x3fff);
  2128. switch (value) {
  2129. case 1: rate = HFA384X_RATES_1MBPS; break;
  2130. case 2: rate = HFA384X_RATES_2MBPS; break;
  2131. case 3: rate = HFA384X_RATES_5MBPS; break;
  2132. case 4: rate = HFA384X_RATES_11MBPS; break;
  2133. default: rate = HFA384X_RATES_1MBPS; break;
  2134. }
  2135. scan_req.txrate = cpu_to_le16(rate);
  2136. /* leave SSID empty to accept all SSIDs */
  2137. if (local->iw_mode == IW_MODE_MASTER) {
  2138. if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
  2139. HFA384X_PORTTYPE_BSS) ||
  2140. local->func->reset_port(dev))
  2141. printk(KERN_DEBUG "Leaving Host AP mode "
  2142. "for HostScan failed\n");
  2143. }
  2144. if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
  2145. sizeof(scan_req))) {
  2146. printk(KERN_DEBUG "HOSTSCAN failed\n");
  2147. ret = -EINVAL;
  2148. }
  2149. if (local->iw_mode == IW_MODE_MASTER) {
  2150. wait_queue_entry_t __wait;
  2151. init_waitqueue_entry(&__wait, current);
  2152. add_wait_queue(&local->hostscan_wq, &__wait);
  2153. set_current_state(TASK_INTERRUPTIBLE);
  2154. schedule_timeout(HZ);
  2155. if (signal_pending(current))
  2156. ret = -EINTR;
  2157. set_current_state(TASK_RUNNING);
  2158. remove_wait_queue(&local->hostscan_wq, &__wait);
  2159. if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
  2160. HFA384X_PORTTYPE_HOSTAP) ||
  2161. local->func->reset_port(dev))
  2162. printk(KERN_DEBUG "Returning to Host AP mode "
  2163. "after HostScan failed\n");
  2164. }
  2165. break;
  2166. }
  2167. case PRISM2_PARAM_AP_SCAN:
  2168. local->passive_scan_interval = value;
  2169. if (timer_pending(&local->passive_scan_timer))
  2170. del_timer(&local->passive_scan_timer);
  2171. if (value > 0 && value < INT_MAX / HZ) {
  2172. local->passive_scan_timer.expires = jiffies +
  2173. local->passive_scan_interval * HZ;
  2174. add_timer(&local->passive_scan_timer);
  2175. }
  2176. break;
  2177. case PRISM2_PARAM_ENH_SEC:
  2178. if (value < 0 || value > 3) {
  2179. ret = -EINVAL;
  2180. break;
  2181. }
  2182. local->enh_sec = value;
  2183. if (hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY,
  2184. local->enh_sec) ||
  2185. local->func->reset_port(dev)) {
  2186. printk(KERN_INFO "%s: cnfEnhSecurity requires STA f/w "
  2187. "1.6.3 or newer\n", dev->name);
  2188. ret = -EOPNOTSUPP;
  2189. }
  2190. break;
  2191. #ifdef PRISM2_IO_DEBUG
  2192. case PRISM2_PARAM_IO_DEBUG:
  2193. local->io_debug_enabled = value;
  2194. break;
  2195. #endif /* PRISM2_IO_DEBUG */
  2196. case PRISM2_PARAM_BASIC_RATES:
  2197. if ((value & local->tx_rate_control) != value || value == 0) {
  2198. printk(KERN_INFO "%s: invalid basic rate set - basic "
  2199. "rates must be in supported rate set\n",
  2200. dev->name);
  2201. ret = -EINVAL;
  2202. break;
  2203. }
  2204. local->basic_rates = value;
  2205. if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
  2206. local->basic_rates) ||
  2207. local->func->reset_port(dev))
  2208. ret = -EINVAL;
  2209. break;
  2210. case PRISM2_PARAM_OPER_RATES:
  2211. local->tx_rate_control = value;
  2212. if (hostap_set_rate(dev))
  2213. ret = -EINVAL;
  2214. break;
  2215. case PRISM2_PARAM_HOSTAPD:
  2216. ret = hostap_set_hostapd(local, value, 1);
  2217. break;
  2218. case PRISM2_PARAM_HOSTAPD_STA:
  2219. ret = hostap_set_hostapd_sta(local, value, 1);
  2220. break;
  2221. case PRISM2_PARAM_WPA:
  2222. local->wpa = value;
  2223. if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
  2224. ret = -EOPNOTSUPP;
  2225. else if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
  2226. value ? 1 : 0))
  2227. ret = -EINVAL;
  2228. break;
  2229. case PRISM2_PARAM_PRIVACY_INVOKED:
  2230. local->privacy_invoked = value;
  2231. if (hostap_set_encryption(local) ||
  2232. local->func->reset_port(dev))
  2233. ret = -EINVAL;
  2234. break;
  2235. case PRISM2_PARAM_TKIP_COUNTERMEASURES:
  2236. local->tkip_countermeasures = value;
  2237. break;
  2238. case PRISM2_PARAM_DROP_UNENCRYPTED:
  2239. local->drop_unencrypted = value;
  2240. break;
  2241. case PRISM2_PARAM_SCAN_CHANNEL_MASK:
  2242. local->scan_channel_mask = value;
  2243. break;
  2244. default:
  2245. printk(KERN_DEBUG "%s: prism2_param: unknown param %d\n",
  2246. dev->name, param);
  2247. ret = -EOPNOTSUPP;
  2248. break;
  2249. }
  2250. return ret;
  2251. }
  2252. static int prism2_ioctl_priv_get_prism2_param(struct net_device *dev,
  2253. struct iw_request_info *info,
  2254. void *wrqu, char *extra)
  2255. {
  2256. struct hostap_interface *iface;
  2257. local_info_t *local;
  2258. int *param = (int *) extra;
  2259. int ret = 0;
  2260. iface = netdev_priv(dev);
  2261. local = iface->local;
  2262. switch (*param) {
  2263. case PRISM2_PARAM_TXRATECTRL:
  2264. *param = local->fw_tx_rate_control;
  2265. break;
  2266. case PRISM2_PARAM_BEACON_INT:
  2267. *param = local->beacon_int;
  2268. break;
  2269. case PRISM2_PARAM_PSEUDO_IBSS:
  2270. *param = local->pseudo_adhoc;
  2271. break;
  2272. case PRISM2_PARAM_ALC:
  2273. ret = -EOPNOTSUPP; /* FIX */
  2274. break;
  2275. case PRISM2_PARAM_DUMP:
  2276. *param = local->frame_dump;
  2277. break;
  2278. case PRISM2_PARAM_OTHER_AP_POLICY:
  2279. if (local->ap != NULL)
  2280. *param = local->ap->ap_policy;
  2281. else
  2282. ret = -EOPNOTSUPP;
  2283. break;
  2284. case PRISM2_PARAM_AP_MAX_INACTIVITY:
  2285. if (local->ap != NULL)
  2286. *param = local->ap->max_inactivity / HZ;
  2287. else
  2288. ret = -EOPNOTSUPP;
  2289. break;
  2290. case PRISM2_PARAM_AP_BRIDGE_PACKETS:
  2291. if (local->ap != NULL)
  2292. *param = local->ap->bridge_packets;
  2293. else
  2294. ret = -EOPNOTSUPP;
  2295. break;
  2296. case PRISM2_PARAM_DTIM_PERIOD:
  2297. *param = local->dtim_period;
  2298. break;
  2299. case PRISM2_PARAM_AP_NULLFUNC_ACK:
  2300. if (local->ap != NULL)
  2301. *param = local->ap->nullfunc_ack;
  2302. else
  2303. ret = -EOPNOTSUPP;
  2304. break;
  2305. case PRISM2_PARAM_MAX_WDS:
  2306. *param = local->wds_max_connections;
  2307. break;
  2308. case PRISM2_PARAM_AP_AUTOM_AP_WDS:
  2309. if (local->ap != NULL)
  2310. *param = local->ap->autom_ap_wds;
  2311. else
  2312. ret = -EOPNOTSUPP;
  2313. break;
  2314. case PRISM2_PARAM_AP_AUTH_ALGS:
  2315. *param = local->auth_algs;
  2316. break;
  2317. case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
  2318. *param = local->monitor_allow_fcserr;
  2319. break;
  2320. case PRISM2_PARAM_HOST_ENCRYPT:
  2321. *param = local->host_encrypt;
  2322. break;
  2323. case PRISM2_PARAM_HOST_DECRYPT:
  2324. *param = local->host_decrypt;
  2325. break;
  2326. case PRISM2_PARAM_HOST_ROAMING:
  2327. *param = local->host_roaming;
  2328. break;
  2329. case PRISM2_PARAM_BCRX_STA_KEY:
  2330. *param = local->bcrx_sta_key;
  2331. break;
  2332. case PRISM2_PARAM_IEEE_802_1X:
  2333. *param = local->ieee_802_1x;
  2334. break;
  2335. case PRISM2_PARAM_ANTSEL_TX:
  2336. *param = local->antsel_tx;
  2337. break;
  2338. case PRISM2_PARAM_ANTSEL_RX:
  2339. *param = local->antsel_rx;
  2340. break;
  2341. case PRISM2_PARAM_MONITOR_TYPE:
  2342. *param = local->monitor_type;
  2343. break;
  2344. case PRISM2_PARAM_WDS_TYPE:
  2345. *param = local->wds_type;
  2346. break;
  2347. case PRISM2_PARAM_HOSTSCAN:
  2348. ret = -EOPNOTSUPP;
  2349. break;
  2350. case PRISM2_PARAM_AP_SCAN:
  2351. *param = local->passive_scan_interval;
  2352. break;
  2353. case PRISM2_PARAM_ENH_SEC:
  2354. *param = local->enh_sec;
  2355. break;
  2356. #ifdef PRISM2_IO_DEBUG
  2357. case PRISM2_PARAM_IO_DEBUG:
  2358. *param = local->io_debug_enabled;
  2359. break;
  2360. #endif /* PRISM2_IO_DEBUG */
  2361. case PRISM2_PARAM_BASIC_RATES:
  2362. *param = local->basic_rates;
  2363. break;
  2364. case PRISM2_PARAM_OPER_RATES:
  2365. *param = local->tx_rate_control;
  2366. break;
  2367. case PRISM2_PARAM_HOSTAPD:
  2368. *param = local->hostapd;
  2369. break;
  2370. case PRISM2_PARAM_HOSTAPD_STA:
  2371. *param = local->hostapd_sta;
  2372. break;
  2373. case PRISM2_PARAM_WPA:
  2374. if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
  2375. ret = -EOPNOTSUPP;
  2376. *param = local->wpa;
  2377. break;
  2378. case PRISM2_PARAM_PRIVACY_INVOKED:
  2379. *param = local->privacy_invoked;
  2380. break;
  2381. case PRISM2_PARAM_TKIP_COUNTERMEASURES:
  2382. *param = local->tkip_countermeasures;
  2383. break;
  2384. case PRISM2_PARAM_DROP_UNENCRYPTED:
  2385. *param = local->drop_unencrypted;
  2386. break;
  2387. case PRISM2_PARAM_SCAN_CHANNEL_MASK:
  2388. *param = local->scan_channel_mask;
  2389. break;
  2390. default:
  2391. printk(KERN_DEBUG "%s: get_prism2_param: unknown param %d\n",
  2392. dev->name, *param);
  2393. ret = -EOPNOTSUPP;
  2394. break;
  2395. }
  2396. return ret;
  2397. }
  2398. static int prism2_ioctl_priv_readmif(struct net_device *dev,
  2399. struct iw_request_info *info,
  2400. void *wrqu, char *extra)
  2401. {
  2402. struct hostap_interface *iface;
  2403. local_info_t *local;
  2404. u16 resp0;
  2405. iface = netdev_priv(dev);
  2406. local = iface->local;
  2407. if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, *extra, NULL,
  2408. &resp0))
  2409. return -EOPNOTSUPP;
  2410. else
  2411. *extra = resp0;
  2412. return 0;
  2413. }
  2414. static int prism2_ioctl_priv_writemif(struct net_device *dev,
  2415. struct iw_request_info *info,
  2416. void *wrqu, char *extra)
  2417. {
  2418. struct hostap_interface *iface;
  2419. local_info_t *local;
  2420. u16 cr, val;
  2421. iface = netdev_priv(dev);
  2422. local = iface->local;
  2423. cr = *extra;
  2424. val = *(extra + 1);
  2425. if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, cr, &val, NULL))
  2426. return -EOPNOTSUPP;
  2427. return 0;
  2428. }
  2429. static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i)
  2430. {
  2431. struct hostap_interface *iface;
  2432. local_info_t *local;
  2433. int ret = 0;
  2434. u32 mode;
  2435. iface = netdev_priv(dev);
  2436. local = iface->local;
  2437. printk(KERN_DEBUG "%s: process %d (%s) used deprecated iwpriv monitor "
  2438. "- update software to use iwconfig mode monitor\n",
  2439. dev->name, task_pid_nr(current), current->comm);
  2440. /* Backward compatibility code - this can be removed at some point */
  2441. if (*i == 0) {
  2442. /* Disable monitor mode - old mode was not saved, so go to
  2443. * Master mode */
  2444. mode = IW_MODE_MASTER;
  2445. ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
  2446. } else if (*i == 1) {
  2447. /* netlink socket mode is not supported anymore since it did
  2448. * not separate different devices from each other and was not
  2449. * best method for delivering large amount of packets to
  2450. * user space */
  2451. ret = -EOPNOTSUPP;
  2452. } else if (*i == 2 || *i == 3) {
  2453. switch (*i) {
  2454. case 2:
  2455. local->monitor_type = PRISM2_MONITOR_80211;
  2456. break;
  2457. case 3:
  2458. local->monitor_type = PRISM2_MONITOR_PRISM;
  2459. break;
  2460. }
  2461. mode = IW_MODE_MONITOR;
  2462. ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
  2463. hostap_monitor_mode_enable(local);
  2464. } else
  2465. ret = -EINVAL;
  2466. return ret;
  2467. }
  2468. static int prism2_ioctl_priv_reset(struct net_device *dev, int *i)
  2469. {
  2470. struct hostap_interface *iface;
  2471. local_info_t *local;
  2472. iface = netdev_priv(dev);
  2473. local = iface->local;
  2474. printk(KERN_DEBUG "%s: manual reset request(%d)\n", dev->name, *i);
  2475. switch (*i) {
  2476. case 0:
  2477. /* Disable and enable card */
  2478. local->func->hw_shutdown(dev, 1);
  2479. local->func->hw_config(dev, 0);
  2480. break;
  2481. case 1:
  2482. /* COR sreset */
  2483. local->func->hw_reset(dev);
  2484. break;
  2485. case 2:
  2486. /* Disable and enable port 0 */
  2487. local->func->reset_port(dev);
  2488. break;
  2489. case 3:
  2490. prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
  2491. if (local->func->cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL,
  2492. NULL))
  2493. return -EINVAL;
  2494. break;
  2495. case 4:
  2496. if (local->func->cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL,
  2497. NULL))
  2498. return -EINVAL;
  2499. break;
  2500. default:
  2501. printk(KERN_DEBUG "Unknown reset request %d\n", *i);
  2502. return -EOPNOTSUPP;
  2503. }
  2504. return 0;
  2505. }
  2506. static int prism2_ioctl_priv_set_rid_word(struct net_device *dev, int *i)
  2507. {
  2508. int rid = *i;
  2509. int value = *(i + 1);
  2510. printk(KERN_DEBUG "%s: Set RID[0x%X] = %d\n", dev->name, rid, value);
  2511. if (hostap_set_word(dev, rid, value))
  2512. return -EINVAL;
  2513. return 0;
  2514. }
  2515. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  2516. static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd)
  2517. {
  2518. int ret = 0;
  2519. switch (*cmd) {
  2520. case AP_MAC_CMD_POLICY_OPEN:
  2521. local->ap->mac_restrictions.policy = MAC_POLICY_OPEN;
  2522. break;
  2523. case AP_MAC_CMD_POLICY_ALLOW:
  2524. local->ap->mac_restrictions.policy = MAC_POLICY_ALLOW;
  2525. break;
  2526. case AP_MAC_CMD_POLICY_DENY:
  2527. local->ap->mac_restrictions.policy = MAC_POLICY_DENY;
  2528. break;
  2529. case AP_MAC_CMD_FLUSH:
  2530. ap_control_flush_macs(&local->ap->mac_restrictions);
  2531. break;
  2532. case AP_MAC_CMD_KICKALL:
  2533. ap_control_kickall(local->ap);
  2534. hostap_deauth_all_stas(local->dev, local->ap, 0);
  2535. break;
  2536. default:
  2537. ret = -EOPNOTSUPP;
  2538. break;
  2539. }
  2540. return ret;
  2541. }
  2542. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  2543. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2544. static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
  2545. {
  2546. struct prism2_download_param *param;
  2547. int ret = 0;
  2548. if (p->length < sizeof(struct prism2_download_param) ||
  2549. p->length > 1024 || !p->pointer)
  2550. return -EINVAL;
  2551. param = memdup_user(p->pointer, p->length);
  2552. if (IS_ERR(param)) {
  2553. return PTR_ERR(param);
  2554. }
  2555. if (p->length < sizeof(struct prism2_download_param) +
  2556. param->num_areas * sizeof(struct prism2_download_area)) {
  2557. ret = -EINVAL;
  2558. goto out;
  2559. }
  2560. ret = local->func->download(local, param);
  2561. out:
  2562. kfree(param);
  2563. return ret;
  2564. }
  2565. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2566. static int prism2_set_genericelement(struct net_device *dev, u8 *elem,
  2567. size_t len)
  2568. {
  2569. struct hostap_interface *iface = netdev_priv(dev);
  2570. local_info_t *local = iface->local;
  2571. u8 *buf;
  2572. /*
  2573. * Add 16-bit length in the beginning of the buffer because Prism2 RID
  2574. * includes it.
  2575. */
  2576. buf = kmalloc(len + 2, GFP_KERNEL);
  2577. if (buf == NULL)
  2578. return -ENOMEM;
  2579. *((__le16 *) buf) = cpu_to_le16(len);
  2580. memcpy(buf + 2, elem, len);
  2581. kfree(local->generic_elem);
  2582. local->generic_elem = buf;
  2583. local->generic_elem_len = len + 2;
  2584. return local->func->set_rid(local->dev, HFA384X_RID_GENERICELEMENT,
  2585. buf, len + 2);
  2586. }
  2587. static int prism2_ioctl_siwauth(struct net_device *dev,
  2588. struct iw_request_info *info,
  2589. struct iw_param *data, char *extra)
  2590. {
  2591. struct hostap_interface *iface = netdev_priv(dev);
  2592. local_info_t *local = iface->local;
  2593. switch (data->flags & IW_AUTH_INDEX) {
  2594. case IW_AUTH_WPA_VERSION:
  2595. case IW_AUTH_CIPHER_PAIRWISE:
  2596. case IW_AUTH_CIPHER_GROUP:
  2597. case IW_AUTH_KEY_MGMT:
  2598. /*
  2599. * Host AP driver does not use these parameters and allows
  2600. * wpa_supplicant to control them internally.
  2601. */
  2602. break;
  2603. case IW_AUTH_TKIP_COUNTERMEASURES:
  2604. local->tkip_countermeasures = data->value;
  2605. break;
  2606. case IW_AUTH_DROP_UNENCRYPTED:
  2607. local->drop_unencrypted = data->value;
  2608. break;
  2609. case IW_AUTH_80211_AUTH_ALG:
  2610. local->auth_algs = data->value;
  2611. break;
  2612. case IW_AUTH_WPA_ENABLED:
  2613. if (data->value == 0) {
  2614. local->wpa = 0;
  2615. if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
  2616. break;
  2617. prism2_set_genericelement(dev, "", 0);
  2618. local->host_roaming = 0;
  2619. local->privacy_invoked = 0;
  2620. if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
  2621. 0) ||
  2622. hostap_set_roaming(local) ||
  2623. hostap_set_encryption(local) ||
  2624. local->func->reset_port(dev))
  2625. return -EINVAL;
  2626. break;
  2627. }
  2628. if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
  2629. return -EOPNOTSUPP;
  2630. local->host_roaming = 2;
  2631. local->privacy_invoked = 1;
  2632. local->wpa = 1;
  2633. if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1) ||
  2634. hostap_set_roaming(local) ||
  2635. hostap_set_encryption(local) ||
  2636. local->func->reset_port(dev))
  2637. return -EINVAL;
  2638. break;
  2639. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  2640. local->ieee_802_1x = data->value;
  2641. break;
  2642. case IW_AUTH_PRIVACY_INVOKED:
  2643. local->privacy_invoked = data->value;
  2644. break;
  2645. default:
  2646. return -EOPNOTSUPP;
  2647. }
  2648. return 0;
  2649. }
  2650. static int prism2_ioctl_giwauth(struct net_device *dev,
  2651. struct iw_request_info *info,
  2652. struct iw_param *data, char *extra)
  2653. {
  2654. struct hostap_interface *iface = netdev_priv(dev);
  2655. local_info_t *local = iface->local;
  2656. switch (data->flags & IW_AUTH_INDEX) {
  2657. case IW_AUTH_WPA_VERSION:
  2658. case IW_AUTH_CIPHER_PAIRWISE:
  2659. case IW_AUTH_CIPHER_GROUP:
  2660. case IW_AUTH_KEY_MGMT:
  2661. /*
  2662. * Host AP driver does not use these parameters and allows
  2663. * wpa_supplicant to control them internally.
  2664. */
  2665. return -EOPNOTSUPP;
  2666. case IW_AUTH_TKIP_COUNTERMEASURES:
  2667. data->value = local->tkip_countermeasures;
  2668. break;
  2669. case IW_AUTH_DROP_UNENCRYPTED:
  2670. data->value = local->drop_unencrypted;
  2671. break;
  2672. case IW_AUTH_80211_AUTH_ALG:
  2673. data->value = local->auth_algs;
  2674. break;
  2675. case IW_AUTH_WPA_ENABLED:
  2676. data->value = local->wpa;
  2677. break;
  2678. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  2679. data->value = local->ieee_802_1x;
  2680. break;
  2681. default:
  2682. return -EOPNOTSUPP;
  2683. }
  2684. return 0;
  2685. }
  2686. static int prism2_ioctl_siwencodeext(struct net_device *dev,
  2687. struct iw_request_info *info,
  2688. struct iw_point *erq, char *extra)
  2689. {
  2690. struct hostap_interface *iface = netdev_priv(dev);
  2691. local_info_t *local = iface->local;
  2692. struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
  2693. int i, ret = 0;
  2694. struct lib80211_crypto_ops *ops;
  2695. struct lib80211_crypt_data **crypt;
  2696. void *sta_ptr;
  2697. u8 *addr;
  2698. const char *alg, *module;
  2699. i = erq->flags & IW_ENCODE_INDEX;
  2700. if (i > WEP_KEYS)
  2701. return -EINVAL;
  2702. if (i < 1 || i > WEP_KEYS)
  2703. i = local->crypt_info.tx_keyidx;
  2704. else
  2705. i--;
  2706. if (i < 0 || i >= WEP_KEYS)
  2707. return -EINVAL;
  2708. addr = ext->addr.sa_data;
  2709. if (is_broadcast_ether_addr(addr)) {
  2710. sta_ptr = NULL;
  2711. crypt = &local->crypt_info.crypt[i];
  2712. } else {
  2713. if (i != 0)
  2714. return -EINVAL;
  2715. sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
  2716. if (sta_ptr == NULL) {
  2717. if (local->iw_mode == IW_MODE_INFRA) {
  2718. /*
  2719. * TODO: add STA entry for the current AP so
  2720. * that unicast key can be used. For now, this
  2721. * is emulated by using default key idx 0.
  2722. */
  2723. i = 0;
  2724. crypt = &local->crypt_info.crypt[i];
  2725. } else
  2726. return -EINVAL;
  2727. }
  2728. }
  2729. if ((erq->flags & IW_ENCODE_DISABLED) ||
  2730. ext->alg == IW_ENCODE_ALG_NONE) {
  2731. if (*crypt)
  2732. lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
  2733. goto done;
  2734. }
  2735. switch (ext->alg) {
  2736. case IW_ENCODE_ALG_WEP:
  2737. alg = "WEP";
  2738. module = "lib80211_crypt_wep";
  2739. break;
  2740. case IW_ENCODE_ALG_TKIP:
  2741. alg = "TKIP";
  2742. module = "lib80211_crypt_tkip";
  2743. break;
  2744. case IW_ENCODE_ALG_CCMP:
  2745. alg = "CCMP";
  2746. module = "lib80211_crypt_ccmp";
  2747. break;
  2748. default:
  2749. printk(KERN_DEBUG "%s: unsupported algorithm %d\n",
  2750. local->dev->name, ext->alg);
  2751. ret = -EOPNOTSUPP;
  2752. goto done;
  2753. }
  2754. ops = lib80211_get_crypto_ops(alg);
  2755. if (ops == NULL) {
  2756. request_module(module);
  2757. ops = lib80211_get_crypto_ops(alg);
  2758. }
  2759. if (ops == NULL) {
  2760. printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
  2761. local->dev->name, alg);
  2762. ret = -EOPNOTSUPP;
  2763. goto done;
  2764. }
  2765. if (sta_ptr || ext->alg != IW_ENCODE_ALG_WEP) {
  2766. /*
  2767. * Per station encryption and other than WEP algorithms
  2768. * require host-based encryption, so force them on
  2769. * automatically.
  2770. */
  2771. local->host_decrypt = local->host_encrypt = 1;
  2772. }
  2773. if (*crypt == NULL || (*crypt)->ops != ops) {
  2774. struct lib80211_crypt_data *new_crypt;
  2775. lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
  2776. new_crypt = kzalloc(sizeof(struct lib80211_crypt_data),
  2777. GFP_KERNEL);
  2778. if (new_crypt == NULL) {
  2779. ret = -ENOMEM;
  2780. goto done;
  2781. }
  2782. new_crypt->ops = ops;
  2783. if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
  2784. new_crypt->priv = new_crypt->ops->init(i);
  2785. if (new_crypt->priv == NULL) {
  2786. kfree(new_crypt);
  2787. ret = -EINVAL;
  2788. goto done;
  2789. }
  2790. *crypt = new_crypt;
  2791. }
  2792. /*
  2793. * TODO: if ext_flags does not have IW_ENCODE_EXT_RX_SEQ_VALID, the
  2794. * existing seq# should not be changed.
  2795. * TODO: if ext_flags has IW_ENCODE_EXT_TX_SEQ_VALID, next TX seq#
  2796. * should be changed to something else than zero.
  2797. */
  2798. if ((!(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) || ext->key_len > 0)
  2799. && (*crypt)->ops->set_key &&
  2800. (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
  2801. (*crypt)->priv) < 0) {
  2802. printk(KERN_DEBUG "%s: key setting failed\n",
  2803. local->dev->name);
  2804. ret = -EINVAL;
  2805. goto done;
  2806. }
  2807. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  2808. if (!sta_ptr)
  2809. local->crypt_info.tx_keyidx = i;
  2810. }
  2811. if (sta_ptr == NULL && ext->key_len > 0) {
  2812. int first = 1, j;
  2813. for (j = 0; j < WEP_KEYS; j++) {
  2814. if (j != i && local->crypt_info.crypt[j]) {
  2815. first = 0;
  2816. break;
  2817. }
  2818. }
  2819. if (first)
  2820. local->crypt_info.tx_keyidx = i;
  2821. }
  2822. done:
  2823. if (sta_ptr)
  2824. hostap_handle_sta_release(sta_ptr);
  2825. local->open_wep = erq->flags & IW_ENCODE_OPEN;
  2826. /*
  2827. * Do not reset port0 if card is in Managed mode since resetting will
  2828. * generate new IEEE 802.11 authentication which may end up in looping
  2829. * with IEEE 802.1X. Prism2 documentation seem to require port reset
  2830. * after WEP configuration. However, keys are apparently changed at
  2831. * least in Managed mode.
  2832. */
  2833. if (ret == 0 &&
  2834. (hostap_set_encryption(local) ||
  2835. (local->iw_mode != IW_MODE_INFRA &&
  2836. local->func->reset_port(local->dev))))
  2837. ret = -EINVAL;
  2838. return ret;
  2839. }
  2840. static int prism2_ioctl_giwencodeext(struct net_device *dev,
  2841. struct iw_request_info *info,
  2842. struct iw_point *erq, char *extra)
  2843. {
  2844. struct hostap_interface *iface = netdev_priv(dev);
  2845. local_info_t *local = iface->local;
  2846. struct lib80211_crypt_data **crypt;
  2847. void *sta_ptr;
  2848. int max_key_len, i;
  2849. struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
  2850. u8 *addr;
  2851. max_key_len = erq->length - sizeof(*ext);
  2852. if (max_key_len < 0)
  2853. return -EINVAL;
  2854. i = erq->flags & IW_ENCODE_INDEX;
  2855. if (i < 1 || i > WEP_KEYS)
  2856. i = local->crypt_info.tx_keyidx;
  2857. else
  2858. i--;
  2859. addr = ext->addr.sa_data;
  2860. if (is_broadcast_ether_addr(addr)) {
  2861. sta_ptr = NULL;
  2862. crypt = &local->crypt_info.crypt[i];
  2863. } else {
  2864. i = 0;
  2865. sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
  2866. if (sta_ptr == NULL)
  2867. return -EINVAL;
  2868. }
  2869. erq->flags = i + 1;
  2870. memset(ext, 0, sizeof(*ext));
  2871. if (*crypt == NULL || (*crypt)->ops == NULL) {
  2872. ext->alg = IW_ENCODE_ALG_NONE;
  2873. ext->key_len = 0;
  2874. erq->flags |= IW_ENCODE_DISABLED;
  2875. } else {
  2876. if (strcmp((*crypt)->ops->name, "WEP") == 0)
  2877. ext->alg = IW_ENCODE_ALG_WEP;
  2878. else if (strcmp((*crypt)->ops->name, "TKIP") == 0)
  2879. ext->alg = IW_ENCODE_ALG_TKIP;
  2880. else if (strcmp((*crypt)->ops->name, "CCMP") == 0)
  2881. ext->alg = IW_ENCODE_ALG_CCMP;
  2882. else
  2883. return -EINVAL;
  2884. if ((*crypt)->ops->get_key) {
  2885. ext->key_len =
  2886. (*crypt)->ops->get_key(ext->key,
  2887. max_key_len,
  2888. ext->tx_seq,
  2889. (*crypt)->priv);
  2890. if (ext->key_len &&
  2891. (ext->alg == IW_ENCODE_ALG_TKIP ||
  2892. ext->alg == IW_ENCODE_ALG_CCMP))
  2893. ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID;
  2894. }
  2895. }
  2896. if (sta_ptr)
  2897. hostap_handle_sta_release(sta_ptr);
  2898. return 0;
  2899. }
  2900. static int prism2_ioctl_set_encryption(local_info_t *local,
  2901. struct prism2_hostapd_param *param,
  2902. int param_len)
  2903. {
  2904. int ret = 0;
  2905. struct lib80211_crypto_ops *ops;
  2906. struct lib80211_crypt_data **crypt;
  2907. void *sta_ptr;
  2908. param->u.crypt.err = 0;
  2909. param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
  2910. if (param_len !=
  2911. (int) ((char *) param->u.crypt.key - (char *) param) +
  2912. param->u.crypt.key_len)
  2913. return -EINVAL;
  2914. if (is_broadcast_ether_addr(param->sta_addr)) {
  2915. if (param->u.crypt.idx >= WEP_KEYS)
  2916. return -EINVAL;
  2917. sta_ptr = NULL;
  2918. crypt = &local->crypt_info.crypt[param->u.crypt.idx];
  2919. } else {
  2920. if (param->u.crypt.idx)
  2921. return -EINVAL;
  2922. sta_ptr = ap_crypt_get_ptrs(
  2923. local->ap, param->sta_addr,
  2924. (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_PERMANENT),
  2925. &crypt);
  2926. if (sta_ptr == NULL) {
  2927. param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
  2928. return -EINVAL;
  2929. }
  2930. }
  2931. if (strcmp(param->u.crypt.alg, "none") == 0) {
  2932. if (crypt)
  2933. lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
  2934. goto done;
  2935. }
  2936. ops = lib80211_get_crypto_ops(param->u.crypt.alg);
  2937. if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
  2938. request_module("lib80211_crypt_wep");
  2939. ops = lib80211_get_crypto_ops(param->u.crypt.alg);
  2940. } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
  2941. request_module("lib80211_crypt_tkip");
  2942. ops = lib80211_get_crypto_ops(param->u.crypt.alg);
  2943. } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
  2944. request_module("lib80211_crypt_ccmp");
  2945. ops = lib80211_get_crypto_ops(param->u.crypt.alg);
  2946. }
  2947. if (ops == NULL) {
  2948. printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
  2949. local->dev->name, param->u.crypt.alg);
  2950. param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
  2951. ret = -EINVAL;
  2952. goto done;
  2953. }
  2954. /* station based encryption and other than WEP algorithms require
  2955. * host-based encryption, so force them on automatically */
  2956. local->host_decrypt = local->host_encrypt = 1;
  2957. if (*crypt == NULL || (*crypt)->ops != ops) {
  2958. struct lib80211_crypt_data *new_crypt;
  2959. lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
  2960. new_crypt = kzalloc(sizeof(struct lib80211_crypt_data),
  2961. GFP_KERNEL);
  2962. if (new_crypt == NULL) {
  2963. ret = -ENOMEM;
  2964. goto done;
  2965. }
  2966. new_crypt->ops = ops;
  2967. new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
  2968. if (new_crypt->priv == NULL) {
  2969. kfree(new_crypt);
  2970. param->u.crypt.err =
  2971. HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED;
  2972. ret = -EINVAL;
  2973. goto done;
  2974. }
  2975. *crypt = new_crypt;
  2976. }
  2977. if ((!(param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) ||
  2978. param->u.crypt.key_len > 0) && (*crypt)->ops->set_key &&
  2979. (*crypt)->ops->set_key(param->u.crypt.key,
  2980. param->u.crypt.key_len, param->u.crypt.seq,
  2981. (*crypt)->priv) < 0) {
  2982. printk(KERN_DEBUG "%s: key setting failed\n",
  2983. local->dev->name);
  2984. param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
  2985. ret = -EINVAL;
  2986. goto done;
  2987. }
  2988. if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
  2989. if (!sta_ptr)
  2990. local->crypt_info.tx_keyidx = param->u.crypt.idx;
  2991. else if (param->u.crypt.idx) {
  2992. printk(KERN_DEBUG "%s: TX key idx setting failed\n",
  2993. local->dev->name);
  2994. param->u.crypt.err =
  2995. HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED;
  2996. ret = -EINVAL;
  2997. goto done;
  2998. }
  2999. }
  3000. done:
  3001. if (sta_ptr)
  3002. hostap_handle_sta_release(sta_ptr);
  3003. /* Do not reset port0 if card is in Managed mode since resetting will
  3004. * generate new IEEE 802.11 authentication which may end up in looping
  3005. * with IEEE 802.1X. Prism2 documentation seem to require port reset
  3006. * after WEP configuration. However, keys are apparently changed at
  3007. * least in Managed mode. */
  3008. if (ret == 0 &&
  3009. (hostap_set_encryption(local) ||
  3010. (local->iw_mode != IW_MODE_INFRA &&
  3011. local->func->reset_port(local->dev)))) {
  3012. param->u.crypt.err = HOSTAP_CRYPT_ERR_CARD_CONF_FAILED;
  3013. return -EINVAL;
  3014. }
  3015. return ret;
  3016. }
  3017. static int prism2_ioctl_get_encryption(local_info_t *local,
  3018. struct prism2_hostapd_param *param,
  3019. int param_len)
  3020. {
  3021. struct lib80211_crypt_data **crypt;
  3022. void *sta_ptr;
  3023. int max_key_len;
  3024. param->u.crypt.err = 0;
  3025. max_key_len = param_len -
  3026. (int) ((char *) param->u.crypt.key - (char *) param);
  3027. if (max_key_len < 0)
  3028. return -EINVAL;
  3029. if (is_broadcast_ether_addr(param->sta_addr)) {
  3030. sta_ptr = NULL;
  3031. if (param->u.crypt.idx >= WEP_KEYS)
  3032. param->u.crypt.idx = local->crypt_info.tx_keyidx;
  3033. crypt = &local->crypt_info.crypt[param->u.crypt.idx];
  3034. } else {
  3035. param->u.crypt.idx = 0;
  3036. sta_ptr = ap_crypt_get_ptrs(local->ap, param->sta_addr, 0,
  3037. &crypt);
  3038. if (sta_ptr == NULL) {
  3039. param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
  3040. return -EINVAL;
  3041. }
  3042. }
  3043. if (*crypt == NULL || (*crypt)->ops == NULL) {
  3044. memcpy(param->u.crypt.alg, "none", 5);
  3045. param->u.crypt.key_len = 0;
  3046. param->u.crypt.idx = 0xff;
  3047. } else {
  3048. strncpy(param->u.crypt.alg, (*crypt)->ops->name,
  3049. HOSTAP_CRYPT_ALG_NAME_LEN);
  3050. param->u.crypt.key_len = 0;
  3051. memset(param->u.crypt.seq, 0, 8);
  3052. if ((*crypt)->ops->get_key) {
  3053. param->u.crypt.key_len =
  3054. (*crypt)->ops->get_key(param->u.crypt.key,
  3055. max_key_len,
  3056. param->u.crypt.seq,
  3057. (*crypt)->priv);
  3058. }
  3059. }
  3060. if (sta_ptr)
  3061. hostap_handle_sta_release(sta_ptr);
  3062. return 0;
  3063. }
  3064. static int prism2_ioctl_get_rid(local_info_t *local,
  3065. struct prism2_hostapd_param *param,
  3066. int param_len)
  3067. {
  3068. int max_len, res;
  3069. max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
  3070. if (max_len < 0)
  3071. return -EINVAL;
  3072. res = local->func->get_rid(local->dev, param->u.rid.rid,
  3073. param->u.rid.data, param->u.rid.len, 0);
  3074. if (res >= 0) {
  3075. param->u.rid.len = res;
  3076. return 0;
  3077. }
  3078. return res;
  3079. }
  3080. static int prism2_ioctl_set_rid(local_info_t *local,
  3081. struct prism2_hostapd_param *param,
  3082. int param_len)
  3083. {
  3084. int max_len;
  3085. max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
  3086. if (max_len < 0 || max_len < param->u.rid.len)
  3087. return -EINVAL;
  3088. return local->func->set_rid(local->dev, param->u.rid.rid,
  3089. param->u.rid.data, param->u.rid.len);
  3090. }
  3091. static int prism2_ioctl_set_assoc_ap_addr(local_info_t *local,
  3092. struct prism2_hostapd_param *param,
  3093. int param_len)
  3094. {
  3095. printk(KERN_DEBUG "%ssta: associated as client with AP %pM\n",
  3096. local->dev->name, param->sta_addr);
  3097. memcpy(local->assoc_ap_addr, param->sta_addr, ETH_ALEN);
  3098. return 0;
  3099. }
  3100. static int prism2_ioctl_siwgenie(struct net_device *dev,
  3101. struct iw_request_info *info,
  3102. struct iw_point *data, char *extra)
  3103. {
  3104. return prism2_set_genericelement(dev, extra, data->length);
  3105. }
  3106. static int prism2_ioctl_giwgenie(struct net_device *dev,
  3107. struct iw_request_info *info,
  3108. struct iw_point *data, char *extra)
  3109. {
  3110. struct hostap_interface *iface = netdev_priv(dev);
  3111. local_info_t *local = iface->local;
  3112. int len = local->generic_elem_len - 2;
  3113. if (len <= 0 || local->generic_elem == NULL) {
  3114. data->length = 0;
  3115. return 0;
  3116. }
  3117. if (data->length < len)
  3118. return -E2BIG;
  3119. data->length = len;
  3120. memcpy(extra, local->generic_elem + 2, len);
  3121. return 0;
  3122. }
  3123. static int prism2_ioctl_set_generic_element(local_info_t *local,
  3124. struct prism2_hostapd_param *param,
  3125. int param_len)
  3126. {
  3127. int max_len, len;
  3128. len = param->u.generic_elem.len;
  3129. max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
  3130. if (max_len < 0 || max_len < len)
  3131. return -EINVAL;
  3132. return prism2_set_genericelement(local->dev,
  3133. param->u.generic_elem.data, len);
  3134. }
  3135. static int prism2_ioctl_siwmlme(struct net_device *dev,
  3136. struct iw_request_info *info,
  3137. struct iw_point *data, char *extra)
  3138. {
  3139. struct hostap_interface *iface = netdev_priv(dev);
  3140. local_info_t *local = iface->local;
  3141. struct iw_mlme *mlme = (struct iw_mlme *) extra;
  3142. __le16 reason;
  3143. reason = cpu_to_le16(mlme->reason_code);
  3144. switch (mlme->cmd) {
  3145. case IW_MLME_DEAUTH:
  3146. return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
  3147. IEEE80211_STYPE_DEAUTH,
  3148. (u8 *) &reason, 2);
  3149. case IW_MLME_DISASSOC:
  3150. return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
  3151. IEEE80211_STYPE_DISASSOC,
  3152. (u8 *) &reason, 2);
  3153. default:
  3154. return -EOPNOTSUPP;
  3155. }
  3156. }
  3157. static int prism2_ioctl_mlme(local_info_t *local,
  3158. struct prism2_hostapd_param *param)
  3159. {
  3160. __le16 reason;
  3161. reason = cpu_to_le16(param->u.mlme.reason_code);
  3162. switch (param->u.mlme.cmd) {
  3163. case MLME_STA_DEAUTH:
  3164. return prism2_sta_send_mgmt(local, param->sta_addr,
  3165. IEEE80211_STYPE_DEAUTH,
  3166. (u8 *) &reason, 2);
  3167. case MLME_STA_DISASSOC:
  3168. return prism2_sta_send_mgmt(local, param->sta_addr,
  3169. IEEE80211_STYPE_DISASSOC,
  3170. (u8 *) &reason, 2);
  3171. default:
  3172. return -EOPNOTSUPP;
  3173. }
  3174. }
  3175. static int prism2_ioctl_scan_req(local_info_t *local,
  3176. struct prism2_hostapd_param *param)
  3177. {
  3178. #ifndef PRISM2_NO_STATION_MODES
  3179. if ((local->iw_mode != IW_MODE_INFRA &&
  3180. local->iw_mode != IW_MODE_ADHOC) ||
  3181. (local->sta_fw_ver < PRISM2_FW_VER(1,3,1)))
  3182. return -EOPNOTSUPP;
  3183. if (!local->dev_enabled)
  3184. return -ENETDOWN;
  3185. return prism2_request_hostscan(local->dev, param->u.scan_req.ssid,
  3186. param->u.scan_req.ssid_len);
  3187. #else /* PRISM2_NO_STATION_MODES */
  3188. return -EOPNOTSUPP;
  3189. #endif /* PRISM2_NO_STATION_MODES */
  3190. }
  3191. static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p)
  3192. {
  3193. struct prism2_hostapd_param *param;
  3194. int ret = 0;
  3195. int ap_ioctl = 0;
  3196. if (p->length < sizeof(struct prism2_hostapd_param) ||
  3197. p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
  3198. return -EINVAL;
  3199. param = memdup_user(p->pointer, p->length);
  3200. if (IS_ERR(param)) {
  3201. return PTR_ERR(param);
  3202. }
  3203. switch (param->cmd) {
  3204. case PRISM2_SET_ENCRYPTION:
  3205. ret = prism2_ioctl_set_encryption(local, param, p->length);
  3206. break;
  3207. case PRISM2_GET_ENCRYPTION:
  3208. ret = prism2_ioctl_get_encryption(local, param, p->length);
  3209. break;
  3210. case PRISM2_HOSTAPD_GET_RID:
  3211. ret = prism2_ioctl_get_rid(local, param, p->length);
  3212. break;
  3213. case PRISM2_HOSTAPD_SET_RID:
  3214. ret = prism2_ioctl_set_rid(local, param, p->length);
  3215. break;
  3216. case PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR:
  3217. ret = prism2_ioctl_set_assoc_ap_addr(local, param, p->length);
  3218. break;
  3219. case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
  3220. ret = prism2_ioctl_set_generic_element(local, param,
  3221. p->length);
  3222. break;
  3223. case PRISM2_HOSTAPD_MLME:
  3224. ret = prism2_ioctl_mlme(local, param);
  3225. break;
  3226. case PRISM2_HOSTAPD_SCAN_REQ:
  3227. ret = prism2_ioctl_scan_req(local, param);
  3228. break;
  3229. default:
  3230. ret = prism2_hostapd(local->ap, param);
  3231. ap_ioctl = 1;
  3232. break;
  3233. }
  3234. if (ret == 1 || !ap_ioctl) {
  3235. if (copy_to_user(p->pointer, param, p->length)) {
  3236. ret = -EFAULT;
  3237. goto out;
  3238. } else if (ap_ioctl)
  3239. ret = 0;
  3240. }
  3241. out:
  3242. kfree(param);
  3243. return ret;
  3244. }
  3245. static void prism2_get_drvinfo(struct net_device *dev,
  3246. struct ethtool_drvinfo *info)
  3247. {
  3248. struct hostap_interface *iface;
  3249. local_info_t *local;
  3250. iface = netdev_priv(dev);
  3251. local = iface->local;
  3252. strlcpy(info->driver, "hostap", sizeof(info->driver));
  3253. snprintf(info->fw_version, sizeof(info->fw_version),
  3254. "%d.%d.%d", (local->sta_fw_ver >> 16) & 0xff,
  3255. (local->sta_fw_ver >> 8) & 0xff,
  3256. local->sta_fw_ver & 0xff);
  3257. }
  3258. const struct ethtool_ops prism2_ethtool_ops = {
  3259. .get_drvinfo = prism2_get_drvinfo
  3260. };
  3261. /* Structures to export the Wireless Handlers */
  3262. static const iw_handler prism2_handler[] =
  3263. {
  3264. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  3265. (iw_handler) prism2_get_name, /* SIOCGIWNAME */
  3266. (iw_handler) NULL, /* SIOCSIWNWID */
  3267. (iw_handler) NULL, /* SIOCGIWNWID */
  3268. (iw_handler) prism2_ioctl_siwfreq, /* SIOCSIWFREQ */
  3269. (iw_handler) prism2_ioctl_giwfreq, /* SIOCGIWFREQ */
  3270. (iw_handler) prism2_ioctl_siwmode, /* SIOCSIWMODE */
  3271. (iw_handler) prism2_ioctl_giwmode, /* SIOCGIWMODE */
  3272. (iw_handler) prism2_ioctl_siwsens, /* SIOCSIWSENS */
  3273. (iw_handler) prism2_ioctl_giwsens, /* SIOCGIWSENS */
  3274. (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
  3275. (iw_handler) prism2_ioctl_giwrange, /* SIOCGIWRANGE */
  3276. (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
  3277. (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
  3278. (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
  3279. (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
  3280. iw_handler_set_spy, /* SIOCSIWSPY */
  3281. iw_handler_get_spy, /* SIOCGIWSPY */
  3282. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  3283. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  3284. (iw_handler) prism2_ioctl_siwap, /* SIOCSIWAP */
  3285. (iw_handler) prism2_ioctl_giwap, /* SIOCGIWAP */
  3286. (iw_handler) prism2_ioctl_siwmlme, /* SIOCSIWMLME */
  3287. (iw_handler) prism2_ioctl_giwaplist, /* SIOCGIWAPLIST */
  3288. (iw_handler) prism2_ioctl_siwscan, /* SIOCSIWSCAN */
  3289. (iw_handler) prism2_ioctl_giwscan, /* SIOCGIWSCAN */
  3290. (iw_handler) prism2_ioctl_siwessid, /* SIOCSIWESSID */
  3291. (iw_handler) prism2_ioctl_giwessid, /* SIOCGIWESSID */
  3292. (iw_handler) prism2_ioctl_siwnickn, /* SIOCSIWNICKN */
  3293. (iw_handler) prism2_ioctl_giwnickn, /* SIOCGIWNICKN */
  3294. (iw_handler) NULL, /* -- hole -- */
  3295. (iw_handler) NULL, /* -- hole -- */
  3296. (iw_handler) prism2_ioctl_siwrate, /* SIOCSIWRATE */
  3297. (iw_handler) prism2_ioctl_giwrate, /* SIOCGIWRATE */
  3298. (iw_handler) prism2_ioctl_siwrts, /* SIOCSIWRTS */
  3299. (iw_handler) prism2_ioctl_giwrts, /* SIOCGIWRTS */
  3300. (iw_handler) prism2_ioctl_siwfrag, /* SIOCSIWFRAG */
  3301. (iw_handler) prism2_ioctl_giwfrag, /* SIOCGIWFRAG */
  3302. (iw_handler) prism2_ioctl_siwtxpow, /* SIOCSIWTXPOW */
  3303. (iw_handler) prism2_ioctl_giwtxpow, /* SIOCGIWTXPOW */
  3304. (iw_handler) prism2_ioctl_siwretry, /* SIOCSIWRETRY */
  3305. (iw_handler) prism2_ioctl_giwretry, /* SIOCGIWRETRY */
  3306. (iw_handler) prism2_ioctl_siwencode, /* SIOCSIWENCODE */
  3307. (iw_handler) prism2_ioctl_giwencode, /* SIOCGIWENCODE */
  3308. (iw_handler) prism2_ioctl_siwpower, /* SIOCSIWPOWER */
  3309. (iw_handler) prism2_ioctl_giwpower, /* SIOCGIWPOWER */
  3310. (iw_handler) NULL, /* -- hole -- */
  3311. (iw_handler) NULL, /* -- hole -- */
  3312. (iw_handler) prism2_ioctl_siwgenie, /* SIOCSIWGENIE */
  3313. (iw_handler) prism2_ioctl_giwgenie, /* SIOCGIWGENIE */
  3314. (iw_handler) prism2_ioctl_siwauth, /* SIOCSIWAUTH */
  3315. (iw_handler) prism2_ioctl_giwauth, /* SIOCGIWAUTH */
  3316. (iw_handler) prism2_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
  3317. (iw_handler) prism2_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
  3318. (iw_handler) NULL, /* SIOCSIWPMKSA */
  3319. (iw_handler) NULL, /* -- hole -- */
  3320. };
  3321. static const iw_handler prism2_private_handler[] =
  3322. { /* SIOCIWFIRSTPRIV + */
  3323. (iw_handler) prism2_ioctl_priv_prism2_param, /* 0 */
  3324. (iw_handler) prism2_ioctl_priv_get_prism2_param, /* 1 */
  3325. (iw_handler) prism2_ioctl_priv_writemif, /* 2 */
  3326. (iw_handler) prism2_ioctl_priv_readmif, /* 3 */
  3327. };
  3328. const struct iw_handler_def hostap_iw_handler_def =
  3329. {
  3330. .num_standard = ARRAY_SIZE(prism2_handler),
  3331. .num_private = ARRAY_SIZE(prism2_private_handler),
  3332. .num_private_args = ARRAY_SIZE(prism2_priv),
  3333. .standard = (iw_handler *) prism2_handler,
  3334. .private = (iw_handler *) prism2_private_handler,
  3335. .private_args = (struct iw_priv_args *) prism2_priv,
  3336. .get_wireless_stats = hostap_get_wireless_stats,
  3337. };
  3338. int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  3339. {
  3340. struct iwreq *wrq = (struct iwreq *) ifr;
  3341. struct hostap_interface *iface;
  3342. local_info_t *local;
  3343. int ret = 0;
  3344. iface = netdev_priv(dev);
  3345. local = iface->local;
  3346. switch (cmd) {
  3347. /* Private ioctls (iwpriv) that have not yet been converted
  3348. * into new wireless extensions API */
  3349. case PRISM2_IOCTL_INQUIRE:
  3350. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3351. else ret = prism2_ioctl_priv_inquire(dev, (int *) wrq->u.name);
  3352. break;
  3353. case PRISM2_IOCTL_MONITOR:
  3354. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3355. else ret = prism2_ioctl_priv_monitor(dev, (int *) wrq->u.name);
  3356. break;
  3357. case PRISM2_IOCTL_RESET:
  3358. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3359. else ret = prism2_ioctl_priv_reset(dev, (int *) wrq->u.name);
  3360. break;
  3361. case PRISM2_IOCTL_WDS_ADD:
  3362. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3363. else ret = prism2_wds_add(local, wrq->u.ap_addr.sa_data, 1);
  3364. break;
  3365. case PRISM2_IOCTL_WDS_DEL:
  3366. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3367. else ret = prism2_wds_del(local, wrq->u.ap_addr.sa_data, 1, 0);
  3368. break;
  3369. case PRISM2_IOCTL_SET_RID_WORD:
  3370. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3371. else ret = prism2_ioctl_priv_set_rid_word(dev,
  3372. (int *) wrq->u.name);
  3373. break;
  3374. #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
  3375. case PRISM2_IOCTL_MACCMD:
  3376. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3377. else ret = ap_mac_cmd_ioctl(local, (int *) wrq->u.name);
  3378. break;
  3379. case PRISM2_IOCTL_ADDMAC:
  3380. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3381. else ret = ap_control_add_mac(&local->ap->mac_restrictions,
  3382. wrq->u.ap_addr.sa_data);
  3383. break;
  3384. case PRISM2_IOCTL_DELMAC:
  3385. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3386. else ret = ap_control_del_mac(&local->ap->mac_restrictions,
  3387. wrq->u.ap_addr.sa_data);
  3388. break;
  3389. case PRISM2_IOCTL_KICKMAC:
  3390. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3391. else ret = ap_control_kick_mac(local->ap, local->dev,
  3392. wrq->u.ap_addr.sa_data);
  3393. break;
  3394. #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
  3395. /* Private ioctls that are not used with iwpriv;
  3396. * in SIOCDEVPRIVATE range */
  3397. #ifdef PRISM2_DOWNLOAD_SUPPORT
  3398. case PRISM2_IOCTL_DOWNLOAD:
  3399. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3400. else ret = prism2_ioctl_priv_download(local, &wrq->u.data);
  3401. break;
  3402. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  3403. case PRISM2_IOCTL_HOSTAPD:
  3404. if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
  3405. else ret = prism2_ioctl_priv_hostapd(local, &wrq->u.data);
  3406. break;
  3407. default:
  3408. ret = -EOPNOTSUPP;
  3409. break;
  3410. }
  3411. return ret;
  3412. }