hostap_ioctl.c 104 KB

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