hostap_ioctl.c 104 KB

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