main.c 143 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567
  1. /* main.c - (formerly known as dldwd_cs.c, orinoco_cs.c and orinoco.c)
  2. *
  3. * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
  4. * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
  5. *
  6. * Current maintainers (as of 29 September 2003) are:
  7. * Pavel Roskin <proski AT gnu.org>
  8. * and David Gibson <hermes AT gibson.dropbear.id.au>
  9. *
  10. * (C) Copyright David Gibson, IBM Corporation 2001-2003.
  11. * Copyright (C) 2000 David Gibson, Linuxcare Australia.
  12. * With some help from :
  13. * Copyright (C) 2001 Jean Tourrilhes, HP Labs
  14. * Copyright (C) 2001 Benjamin Herrenschmidt
  15. *
  16. * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
  17. *
  18. * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
  19. * AT fasta.fh-dortmund.de>
  20. * http://www.stud.fh-dortmund.de/~andy/wvlan/
  21. *
  22. * The contents of this file are subject to the Mozilla Public License
  23. * Version 1.1 (the "License"); you may not use this file except in
  24. * compliance with the License. You may obtain a copy of the License
  25. * at http://www.mozilla.org/MPL/
  26. *
  27. * Software distributed under the License is distributed on an "AS IS"
  28. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  29. * the License for the specific language governing rights and
  30. * limitations under the License.
  31. *
  32. * The initial developer of the original code is David A. Hinds
  33. * <dahinds AT users.sourceforge.net>. Portions created by David
  34. * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
  35. * Reserved.
  36. *
  37. * Alternatively, the contents of this file may be used under the
  38. * terms of the GNU General Public License version 2 (the "GPL"), in
  39. * which case the provisions of the GPL are applicable instead of the
  40. * above. If you wish to allow the use of your version of this file
  41. * only under the terms of the GPL and not to allow others to use your
  42. * version of this file under the MPL, indicate your decision by
  43. * deleting the provisions above and replace them with the notice and
  44. * other provisions required by the GPL. If you do not delete the
  45. * provisions above, a recipient may use your version of this file
  46. * under either the MPL or the GPL. */
  47. /*
  48. * TODO
  49. * o Handle de-encapsulation within network layer, provide 802.11
  50. * headers (patch from Thomas 'Dent' Mirlacher)
  51. * o Fix possible races in SPY handling.
  52. * o Disconnect wireless extensions from fundamental configuration.
  53. * o (maybe) Software WEP support (patch from Stano Meduna).
  54. * o (maybe) Use multiple Tx buffers - driver handling queue
  55. * rather than firmware.
  56. */
  57. /* Locking and synchronization:
  58. *
  59. * The basic principle is that everything is serialized through a
  60. * single spinlock, priv->lock. The lock is used in user, bh and irq
  61. * context, so when taken outside hardirq context it should always be
  62. * taken with interrupts disabled. The lock protects both the
  63. * hardware and the struct orinoco_private.
  64. *
  65. * Another flag, priv->hw_unavailable indicates that the hardware is
  66. * unavailable for an extended period of time (e.g. suspended, or in
  67. * the middle of a hard reset). This flag is protected by the
  68. * spinlock. All code which touches the hardware should check the
  69. * flag after taking the lock, and if it is set, give up on whatever
  70. * they are doing and drop the lock again. The orinoco_lock()
  71. * function handles this (it unlocks and returns -EBUSY if
  72. * hw_unavailable is non-zero).
  73. */
  74. #define DRIVER_NAME "orinoco"
  75. #include <linux/module.h>
  76. #include <linux/kernel.h>
  77. #include <linux/init.h>
  78. #include <linux/delay.h>
  79. #include <linux/netdevice.h>
  80. #include <linux/etherdevice.h>
  81. #include <linux/ethtool.h>
  82. #include <linux/suspend.h>
  83. #include <linux/if_arp.h>
  84. #include <linux/wireless.h>
  85. #include <linux/ieee80211.h>
  86. #include <net/iw_handler.h>
  87. #include "hermes_rid.h"
  88. #include "hermes_dld.h"
  89. #include "scan.h"
  90. #include "mic.h"
  91. #include "fw.h"
  92. #include "orinoco.h"
  93. /********************************************************************/
  94. /* Module information */
  95. /********************************************************************/
  96. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & "
  97. "David Gibson <hermes@gibson.dropbear.id.au>");
  98. MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based "
  99. "and similar wireless cards");
  100. MODULE_LICENSE("Dual MPL/GPL");
  101. /* Level of debugging. Used in the macros in orinoco.h */
  102. #ifdef ORINOCO_DEBUG
  103. int orinoco_debug = ORINOCO_DEBUG;
  104. EXPORT_SYMBOL(orinoco_debug);
  105. module_param(orinoco_debug, int, 0644);
  106. MODULE_PARM_DESC(orinoco_debug, "Debug level");
  107. #endif
  108. static int suppress_linkstatus; /* = 0 */
  109. module_param(suppress_linkstatus, bool, 0644);
  110. MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
  111. static int ignore_disconnect; /* = 0 */
  112. module_param(ignore_disconnect, int, 0644);
  113. MODULE_PARM_DESC(ignore_disconnect,
  114. "Don't report lost link to the network layer");
  115. static int force_monitor; /* = 0 */
  116. module_param(force_monitor, int, 0644);
  117. MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
  118. /********************************************************************/
  119. /* Compile time configuration and compatibility stuff */
  120. /********************************************************************/
  121. /* We do this this way to avoid ifdefs in the actual code */
  122. #ifdef WIRELESS_SPY
  123. #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
  124. #else
  125. #define SPY_NUMBER(priv) 0
  126. #endif /* WIRELESS_SPY */
  127. /********************************************************************/
  128. /* Internal constants */
  129. /********************************************************************/
  130. /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
  131. static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
  132. #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
  133. #define ORINOCO_MIN_MTU 256
  134. #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
  135. #define SYMBOL_MAX_VER_LEN (14)
  136. #define USER_BAP 0
  137. #define IRQ_BAP 1
  138. #define MAX_IRQLOOPS_PER_IRQ 10
  139. #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
  140. * how many events the
  141. * device could
  142. * legitimately generate */
  143. #define SMALL_KEY_SIZE 5
  144. #define LARGE_KEY_SIZE 13
  145. #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
  146. #define DUMMY_FID 0xFFFF
  147. /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
  148. HERMES_MAX_MULTICAST : 0)*/
  149. #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
  150. #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
  151. | HERMES_EV_TX | HERMES_EV_TXEXC \
  152. | HERMES_EV_WTERR | HERMES_EV_INFO \
  153. | HERMES_EV_INFDROP)
  154. #define MAX_RID_LEN 1024
  155. static const struct iw_handler_def orinoco_handler_def;
  156. static const struct ethtool_ops orinoco_ethtool_ops;
  157. /********************************************************************/
  158. /* Data tables */
  159. /********************************************************************/
  160. #define NUM_CHANNELS 14
  161. /* This tables gives the actual meanings of the bitrate IDs returned
  162. * by the firmware. */
  163. static struct {
  164. int bitrate; /* in 100s of kilobits */
  165. int automatic;
  166. u16 agere_txratectrl;
  167. u16 intersil_txratectrl;
  168. } bitrate_table[] = {
  169. {110, 1, 3, 15}, /* Entry 0 is the default */
  170. {10, 0, 1, 1},
  171. {10, 1, 1, 1},
  172. {20, 0, 2, 2},
  173. {20, 1, 6, 3},
  174. {55, 0, 4, 4},
  175. {55, 1, 7, 7},
  176. {110, 0, 5, 8},
  177. };
  178. #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
  179. /********************************************************************/
  180. /* Data types */
  181. /********************************************************************/
  182. /* Beginning of the Tx descriptor, used in TxExc handling */
  183. struct hermes_txexc_data {
  184. struct hermes_tx_descriptor desc;
  185. __le16 frame_ctl;
  186. __le16 duration_id;
  187. u8 addr1[ETH_ALEN];
  188. } __attribute__ ((packed));
  189. /* Rx frame header except compatibility 802.3 header */
  190. struct hermes_rx_descriptor {
  191. /* Control */
  192. __le16 status;
  193. __le32 time;
  194. u8 silence;
  195. u8 signal;
  196. u8 rate;
  197. u8 rxflow;
  198. __le32 reserved;
  199. /* 802.11 header */
  200. __le16 frame_ctl;
  201. __le16 duration_id;
  202. u8 addr1[ETH_ALEN];
  203. u8 addr2[ETH_ALEN];
  204. u8 addr3[ETH_ALEN];
  205. __le16 seq_ctl;
  206. u8 addr4[ETH_ALEN];
  207. /* Data length */
  208. __le16 data_len;
  209. } __attribute__ ((packed));
  210. struct orinoco_rx_data {
  211. struct hermes_rx_descriptor *desc;
  212. struct sk_buff *skb;
  213. struct list_head list;
  214. };
  215. /********************************************************************/
  216. /* Function prototypes */
  217. /********************************************************************/
  218. static int __orinoco_program_rids(struct net_device *dev);
  219. static void __orinoco_set_multicast_list(struct net_device *dev);
  220. /********************************************************************/
  221. /* Internal helper functions */
  222. /********************************************************************/
  223. static inline void set_port_type(struct orinoco_private *priv)
  224. {
  225. switch (priv->iw_mode) {
  226. case IW_MODE_INFRA:
  227. priv->port_type = 1;
  228. priv->createibss = 0;
  229. break;
  230. case IW_MODE_ADHOC:
  231. if (priv->prefer_port3) {
  232. priv->port_type = 3;
  233. priv->createibss = 0;
  234. } else {
  235. priv->port_type = priv->ibss_port;
  236. priv->createibss = 1;
  237. }
  238. break;
  239. case IW_MODE_MONITOR:
  240. priv->port_type = 3;
  241. priv->createibss = 0;
  242. break;
  243. default:
  244. printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
  245. priv->ndev->name);
  246. }
  247. }
  248. static int orinoco_get_bitratemode(int bitrate, int automatic)
  249. {
  250. int ratemode = -1;
  251. int i;
  252. if ((bitrate != 10) && (bitrate != 20) &&
  253. (bitrate != 55) && (bitrate != 110))
  254. return ratemode;
  255. for (i = 0; i < BITRATE_TABLE_SIZE; i++) {
  256. if ((bitrate_table[i].bitrate == bitrate) &&
  257. (bitrate_table[i].automatic == automatic)) {
  258. ratemode = i;
  259. break;
  260. }
  261. }
  262. return ratemode;
  263. }
  264. static void orinoco_get_ratemode_cfg(int ratemode, int *bitrate, int *automatic)
  265. {
  266. BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
  267. *bitrate = bitrate_table[ratemode].bitrate * 100000;
  268. *automatic = bitrate_table[ratemode].automatic;
  269. }
  270. static inline u8 *orinoco_get_ie(u8 *data, size_t len,
  271. enum ieee80211_eid eid)
  272. {
  273. u8 *p = data;
  274. while ((p + 2) < (data + len)) {
  275. if (p[0] == eid)
  276. return p;
  277. p += p[1] + 2;
  278. }
  279. return NULL;
  280. }
  281. #define WPA_OUI_TYPE "\x00\x50\xF2\x01"
  282. #define WPA_SELECTOR_LEN 4
  283. static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len)
  284. {
  285. u8 *p = data;
  286. while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) {
  287. if ((p[0] == WLAN_EID_GENERIC) &&
  288. (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0))
  289. return p;
  290. p += p[1] + 2;
  291. }
  292. return NULL;
  293. }
  294. /********************************************************************/
  295. /* Device methods */
  296. /********************************************************************/
  297. static int orinoco_open(struct net_device *dev)
  298. {
  299. struct orinoco_private *priv = netdev_priv(dev);
  300. unsigned long flags;
  301. int err;
  302. if (orinoco_lock(priv, &flags) != 0)
  303. return -EBUSY;
  304. err = __orinoco_up(dev);
  305. if (!err)
  306. priv->open = 1;
  307. orinoco_unlock(priv, &flags);
  308. return err;
  309. }
  310. static int orinoco_stop(struct net_device *dev)
  311. {
  312. struct orinoco_private *priv = netdev_priv(dev);
  313. int err = 0;
  314. /* We mustn't use orinoco_lock() here, because we need to be
  315. able to close the interface even if hw_unavailable is set
  316. (e.g. as we're released after a PC Card removal) */
  317. spin_lock_irq(&priv->lock);
  318. priv->open = 0;
  319. err = __orinoco_down(dev);
  320. spin_unlock_irq(&priv->lock);
  321. return err;
  322. }
  323. static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
  324. {
  325. struct orinoco_private *priv = netdev_priv(dev);
  326. return &priv->stats;
  327. }
  328. static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
  329. {
  330. struct orinoco_private *priv = netdev_priv(dev);
  331. hermes_t *hw = &priv->hw;
  332. struct iw_statistics *wstats = &priv->wstats;
  333. int err;
  334. unsigned long flags;
  335. if (!netif_device_present(dev)) {
  336. printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
  337. dev->name);
  338. return NULL; /* FIXME: Can we do better than this? */
  339. }
  340. /* If busy, return the old stats. Returning NULL may cause
  341. * the interface to disappear from /proc/net/wireless */
  342. if (orinoco_lock(priv, &flags) != 0)
  343. return wstats;
  344. /* We can't really wait for the tallies inquiry command to
  345. * complete, so we just use the previous results and trigger
  346. * a new tallies inquiry command for next time - Jean II */
  347. /* FIXME: Really we should wait for the inquiry to come back -
  348. * as it is the stats we give don't make a whole lot of sense.
  349. * Unfortunately, it's not clear how to do that within the
  350. * wireless extensions framework: I think we're in user
  351. * context, but a lock seems to be held by the time we get in
  352. * here so we're not safe to sleep here. */
  353. hermes_inquire(hw, HERMES_INQ_TALLIES);
  354. if (priv->iw_mode == IW_MODE_ADHOC) {
  355. memset(&wstats->qual, 0, sizeof(wstats->qual));
  356. /* If a spy address is defined, we report stats of the
  357. * first spy address - Jean II */
  358. if (SPY_NUMBER(priv)) {
  359. wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
  360. wstats->qual.level = priv->spy_data.spy_stat[0].level;
  361. wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
  362. wstats->qual.updated =
  363. priv->spy_data.spy_stat[0].updated;
  364. }
  365. } else {
  366. struct {
  367. __le16 qual, signal, noise, unused;
  368. } __attribute__ ((packed)) cq;
  369. err = HERMES_READ_RECORD(hw, USER_BAP,
  370. HERMES_RID_COMMSQUALITY, &cq);
  371. if (!err) {
  372. wstats->qual.qual = (int)le16_to_cpu(cq.qual);
  373. wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
  374. wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
  375. wstats->qual.updated =
  376. IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  377. }
  378. }
  379. orinoco_unlock(priv, &flags);
  380. return wstats;
  381. }
  382. static void orinoco_set_multicast_list(struct net_device *dev)
  383. {
  384. struct orinoco_private *priv = netdev_priv(dev);
  385. unsigned long flags;
  386. if (orinoco_lock(priv, &flags) != 0) {
  387. printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
  388. "called when hw_unavailable\n", dev->name);
  389. return;
  390. }
  391. __orinoco_set_multicast_list(dev);
  392. orinoco_unlock(priv, &flags);
  393. }
  394. static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
  395. {
  396. struct orinoco_private *priv = netdev_priv(dev);
  397. if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
  398. return -EINVAL;
  399. /* MTU + encapsulation + header length */
  400. if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
  401. (priv->nicbuf_size - ETH_HLEN))
  402. return -EINVAL;
  403. dev->mtu = new_mtu;
  404. return 0;
  405. }
  406. /********************************************************************/
  407. /* Tx path */
  408. /********************************************************************/
  409. static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
  410. {
  411. struct orinoco_private *priv = netdev_priv(dev);
  412. struct net_device_stats *stats = &priv->stats;
  413. hermes_t *hw = &priv->hw;
  414. int err = 0;
  415. u16 txfid = priv->txfid;
  416. struct ethhdr *eh;
  417. int tx_control;
  418. unsigned long flags;
  419. if (!netif_running(dev)) {
  420. printk(KERN_ERR "%s: Tx on stopped device!\n",
  421. dev->name);
  422. return NETDEV_TX_BUSY;
  423. }
  424. if (netif_queue_stopped(dev)) {
  425. printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
  426. dev->name);
  427. return NETDEV_TX_BUSY;
  428. }
  429. if (orinoco_lock(priv, &flags) != 0) {
  430. printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
  431. dev->name);
  432. return NETDEV_TX_BUSY;
  433. }
  434. if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
  435. /* Oops, the firmware hasn't established a connection,
  436. silently drop the packet (this seems to be the
  437. safest approach). */
  438. goto drop;
  439. }
  440. /* Check packet length */
  441. if (skb->len < ETH_HLEN)
  442. goto drop;
  443. tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
  444. if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
  445. tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
  446. HERMES_TXCTRL_MIC;
  447. if (priv->has_alt_txcntl) {
  448. /* WPA enabled firmwares have tx_cntl at the end of
  449. * the 802.11 header. So write zeroed descriptor and
  450. * 802.11 header at the same time
  451. */
  452. char desc[HERMES_802_3_OFFSET];
  453. __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
  454. memset(&desc, 0, sizeof(desc));
  455. *txcntl = cpu_to_le16(tx_control);
  456. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
  457. txfid, 0);
  458. if (err) {
  459. if (net_ratelimit())
  460. printk(KERN_ERR "%s: Error %d writing Tx "
  461. "descriptor to BAP\n", dev->name, err);
  462. goto busy;
  463. }
  464. } else {
  465. struct hermes_tx_descriptor desc;
  466. memset(&desc, 0, sizeof(desc));
  467. desc.tx_control = cpu_to_le16(tx_control);
  468. err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
  469. txfid, 0);
  470. if (err) {
  471. if (net_ratelimit())
  472. printk(KERN_ERR "%s: Error %d writing Tx "
  473. "descriptor to BAP\n", dev->name, err);
  474. goto busy;
  475. }
  476. /* Clear the 802.11 header and data length fields - some
  477. * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
  478. * if this isn't done. */
  479. hermes_clear_words(hw, HERMES_DATA0,
  480. HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
  481. }
  482. eh = (struct ethhdr *)skb->data;
  483. /* Encapsulate Ethernet-II frames */
  484. if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
  485. struct header_struct {
  486. struct ethhdr eth; /* 802.3 header */
  487. u8 encap[6]; /* 802.2 header */
  488. } __attribute__ ((packed)) hdr;
  489. /* Strip destination and source from the data */
  490. skb_pull(skb, 2 * ETH_ALEN);
  491. /* And move them to a separate header */
  492. memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
  493. hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
  494. memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
  495. /* Insert the SNAP header */
  496. if (skb_headroom(skb) < sizeof(hdr)) {
  497. printk(KERN_ERR
  498. "%s: Not enough headroom for 802.2 headers %d\n",
  499. dev->name, skb_headroom(skb));
  500. goto drop;
  501. }
  502. eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
  503. memcpy(eh, &hdr, sizeof(hdr));
  504. }
  505. err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
  506. txfid, HERMES_802_3_OFFSET);
  507. if (err) {
  508. printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
  509. dev->name, err);
  510. goto busy;
  511. }
  512. /* Calculate Michael MIC */
  513. if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
  514. u8 mic_buf[MICHAEL_MIC_LEN + 1];
  515. u8 *mic;
  516. size_t offset;
  517. size_t len;
  518. if (skb->len % 2) {
  519. /* MIC start is on an odd boundary */
  520. mic_buf[0] = skb->data[skb->len - 1];
  521. mic = &mic_buf[1];
  522. offset = skb->len - 1;
  523. len = MICHAEL_MIC_LEN + 1;
  524. } else {
  525. mic = &mic_buf[0];
  526. offset = skb->len;
  527. len = MICHAEL_MIC_LEN;
  528. }
  529. orinoco_mic(priv->tx_tfm_mic,
  530. priv->tkip_key[priv->tx_key].tx_mic,
  531. eh->h_dest, eh->h_source, 0 /* priority */,
  532. skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
  533. /* Write the MIC */
  534. err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
  535. txfid, HERMES_802_3_OFFSET + offset);
  536. if (err) {
  537. printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
  538. dev->name, err);
  539. goto busy;
  540. }
  541. }
  542. /* Finally, we actually initiate the send */
  543. netif_stop_queue(dev);
  544. err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
  545. txfid, NULL);
  546. if (err) {
  547. netif_start_queue(dev);
  548. if (net_ratelimit())
  549. printk(KERN_ERR "%s: Error %d transmitting packet\n",
  550. dev->name, err);
  551. goto busy;
  552. }
  553. dev->trans_start = jiffies;
  554. stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
  555. goto ok;
  556. drop:
  557. stats->tx_errors++;
  558. stats->tx_dropped++;
  559. ok:
  560. orinoco_unlock(priv, &flags);
  561. dev_kfree_skb(skb);
  562. return NETDEV_TX_OK;
  563. busy:
  564. if (err == -EIO)
  565. schedule_work(&priv->reset_work);
  566. orinoco_unlock(priv, &flags);
  567. return NETDEV_TX_BUSY;
  568. }
  569. static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
  570. {
  571. struct orinoco_private *priv = netdev_priv(dev);
  572. u16 fid = hermes_read_regn(hw, ALLOCFID);
  573. if (fid != priv->txfid) {
  574. if (fid != DUMMY_FID)
  575. printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
  576. dev->name, fid);
  577. return;
  578. }
  579. hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
  580. }
  581. static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
  582. {
  583. struct orinoco_private *priv = netdev_priv(dev);
  584. struct net_device_stats *stats = &priv->stats;
  585. stats->tx_packets++;
  586. netif_wake_queue(dev);
  587. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  588. }
  589. static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
  590. {
  591. struct orinoco_private *priv = netdev_priv(dev);
  592. struct net_device_stats *stats = &priv->stats;
  593. u16 fid = hermes_read_regn(hw, TXCOMPLFID);
  594. u16 status;
  595. struct hermes_txexc_data hdr;
  596. int err = 0;
  597. if (fid == DUMMY_FID)
  598. return; /* Nothing's really happened */
  599. /* Read part of the frame header - we need status and addr1 */
  600. err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
  601. sizeof(struct hermes_txexc_data),
  602. fid, 0);
  603. hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
  604. stats->tx_errors++;
  605. if (err) {
  606. printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
  607. "(FID=%04X error %d)\n",
  608. dev->name, fid, err);
  609. return;
  610. }
  611. DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
  612. err, fid);
  613. /* We produce a TXDROP event only for retry or lifetime
  614. * exceeded, because that's the only status that really mean
  615. * that this particular node went away.
  616. * Other errors means that *we* screwed up. - Jean II */
  617. status = le16_to_cpu(hdr.desc.status);
  618. if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
  619. union iwreq_data wrqu;
  620. /* Copy 802.11 dest address.
  621. * We use the 802.11 header because the frame may
  622. * not be 802.3 or may be mangled...
  623. * In Ad-Hoc mode, it will be the node address.
  624. * In managed mode, it will be most likely the AP addr
  625. * User space will figure out how to convert it to
  626. * whatever it needs (IP address or else).
  627. * - Jean II */
  628. memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
  629. wrqu.addr.sa_family = ARPHRD_ETHER;
  630. /* Send event to user space */
  631. wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
  632. }
  633. netif_wake_queue(dev);
  634. }
  635. static void orinoco_tx_timeout(struct net_device *dev)
  636. {
  637. struct orinoco_private *priv = netdev_priv(dev);
  638. struct net_device_stats *stats = &priv->stats;
  639. struct hermes *hw = &priv->hw;
  640. printk(KERN_WARNING "%s: Tx timeout! "
  641. "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
  642. dev->name, hermes_read_regn(hw, ALLOCFID),
  643. hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
  644. stats->tx_errors++;
  645. schedule_work(&priv->reset_work);
  646. }
  647. /********************************************************************/
  648. /* Rx path (data frames) */
  649. /********************************************************************/
  650. /* Does the frame have a SNAP header indicating it should be
  651. * de-encapsulated to Ethernet-II? */
  652. static inline int is_ethersnap(void *_hdr)
  653. {
  654. u8 *hdr = _hdr;
  655. /* We de-encapsulate all packets which, a) have SNAP headers
  656. * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
  657. * and where b) the OUI of the SNAP header is 00:00:00 or
  658. * 00:00:f8 - we need both because different APs appear to use
  659. * different OUIs for some reason */
  660. return (memcmp(hdr, &encaps_hdr, 5) == 0)
  661. && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
  662. }
  663. static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
  664. int level, int noise)
  665. {
  666. struct iw_quality wstats;
  667. wstats.level = level - 0x95;
  668. wstats.noise = noise - 0x95;
  669. wstats.qual = (level > noise) ? (level - noise) : 0;
  670. wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  671. /* Update spy records */
  672. wireless_spy_update(dev, mac, &wstats);
  673. }
  674. static void orinoco_stat_gather(struct net_device *dev,
  675. struct sk_buff *skb,
  676. struct hermes_rx_descriptor *desc)
  677. {
  678. struct orinoco_private *priv = netdev_priv(dev);
  679. /* Using spy support with lots of Rx packets, like in an
  680. * infrastructure (AP), will really slow down everything, because
  681. * the MAC address must be compared to each entry of the spy list.
  682. * If the user really asks for it (set some address in the
  683. * spy list), we do it, but he will pay the price.
  684. * Note that to get here, you need both WIRELESS_SPY
  685. * compiled in AND some addresses in the list !!!
  686. */
  687. /* Note : gcc will optimise the whole section away if
  688. * WIRELESS_SPY is not defined... - Jean II */
  689. if (SPY_NUMBER(priv)) {
  690. orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
  691. desc->signal, desc->silence);
  692. }
  693. }
  694. /*
  695. * orinoco_rx_monitor - handle received monitor frames.
  696. *
  697. * Arguments:
  698. * dev network device
  699. * rxfid received FID
  700. * desc rx descriptor of the frame
  701. *
  702. * Call context: interrupt
  703. */
  704. static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
  705. struct hermes_rx_descriptor *desc)
  706. {
  707. u32 hdrlen = 30; /* return full header by default */
  708. u32 datalen = 0;
  709. u16 fc;
  710. int err;
  711. int len;
  712. struct sk_buff *skb;
  713. struct orinoco_private *priv = netdev_priv(dev);
  714. struct net_device_stats *stats = &priv->stats;
  715. hermes_t *hw = &priv->hw;
  716. len = le16_to_cpu(desc->data_len);
  717. /* Determine the size of the header and the data */
  718. fc = le16_to_cpu(desc->frame_ctl);
  719. switch (fc & IEEE80211_FCTL_FTYPE) {
  720. case IEEE80211_FTYPE_DATA:
  721. if ((fc & IEEE80211_FCTL_TODS)
  722. && (fc & IEEE80211_FCTL_FROMDS))
  723. hdrlen = 30;
  724. else
  725. hdrlen = 24;
  726. datalen = len;
  727. break;
  728. case IEEE80211_FTYPE_MGMT:
  729. hdrlen = 24;
  730. datalen = len;
  731. break;
  732. case IEEE80211_FTYPE_CTL:
  733. switch (fc & IEEE80211_FCTL_STYPE) {
  734. case IEEE80211_STYPE_PSPOLL:
  735. case IEEE80211_STYPE_RTS:
  736. case IEEE80211_STYPE_CFEND:
  737. case IEEE80211_STYPE_CFENDACK:
  738. hdrlen = 16;
  739. break;
  740. case IEEE80211_STYPE_CTS:
  741. case IEEE80211_STYPE_ACK:
  742. hdrlen = 10;
  743. break;
  744. }
  745. break;
  746. default:
  747. /* Unknown frame type */
  748. break;
  749. }
  750. /* sanity check the length */
  751. if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
  752. printk(KERN_DEBUG "%s: oversized monitor frame, "
  753. "data length = %d\n", dev->name, datalen);
  754. stats->rx_length_errors++;
  755. goto update_stats;
  756. }
  757. skb = dev_alloc_skb(hdrlen + datalen);
  758. if (!skb) {
  759. printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
  760. dev->name);
  761. goto update_stats;
  762. }
  763. /* Copy the 802.11 header to the skb */
  764. memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
  765. skb_reset_mac_header(skb);
  766. /* If any, copy the data from the card to the skb */
  767. if (datalen > 0) {
  768. err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
  769. ALIGN(datalen, 2), rxfid,
  770. HERMES_802_2_OFFSET);
  771. if (err) {
  772. printk(KERN_ERR "%s: error %d reading monitor frame\n",
  773. dev->name, err);
  774. goto drop;
  775. }
  776. }
  777. skb->dev = dev;
  778. skb->ip_summed = CHECKSUM_NONE;
  779. skb->pkt_type = PACKET_OTHERHOST;
  780. skb->protocol = cpu_to_be16(ETH_P_802_2);
  781. stats->rx_packets++;
  782. stats->rx_bytes += skb->len;
  783. netif_rx(skb);
  784. return;
  785. drop:
  786. dev_kfree_skb_irq(skb);
  787. update_stats:
  788. stats->rx_errors++;
  789. stats->rx_dropped++;
  790. }
  791. /* Get tsc from the firmware */
  792. static int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key,
  793. u8 *tsc)
  794. {
  795. hermes_t *hw = &priv->hw;
  796. int err = 0;
  797. u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE];
  798. if ((key < 0) || (key > 4))
  799. return -EINVAL;
  800. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
  801. sizeof(tsc_arr), NULL, &tsc_arr);
  802. if (!err)
  803. memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
  804. return err;
  805. }
  806. static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
  807. {
  808. struct orinoco_private *priv = netdev_priv(dev);
  809. struct net_device_stats *stats = &priv->stats;
  810. struct iw_statistics *wstats = &priv->wstats;
  811. struct sk_buff *skb = NULL;
  812. u16 rxfid, status;
  813. int length;
  814. struct hermes_rx_descriptor *desc;
  815. struct orinoco_rx_data *rx_data;
  816. int err;
  817. desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
  818. if (!desc) {
  819. printk(KERN_WARNING
  820. "%s: Can't allocate space for RX descriptor\n",
  821. dev->name);
  822. goto update_stats;
  823. }
  824. rxfid = hermes_read_regn(hw, RXFID);
  825. err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
  826. rxfid, 0);
  827. if (err) {
  828. printk(KERN_ERR "%s: error %d reading Rx descriptor. "
  829. "Frame dropped.\n", dev->name, err);
  830. goto update_stats;
  831. }
  832. status = le16_to_cpu(desc->status);
  833. if (status & HERMES_RXSTAT_BADCRC) {
  834. DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
  835. dev->name);
  836. stats->rx_crc_errors++;
  837. goto update_stats;
  838. }
  839. /* Handle frames in monitor mode */
  840. if (priv->iw_mode == IW_MODE_MONITOR) {
  841. orinoco_rx_monitor(dev, rxfid, desc);
  842. goto out;
  843. }
  844. if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
  845. DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
  846. dev->name);
  847. wstats->discard.code++;
  848. goto update_stats;
  849. }
  850. length = le16_to_cpu(desc->data_len);
  851. /* Sanity checks */
  852. if (length < 3) { /* No for even an 802.2 LLC header */
  853. /* At least on Symbol firmware with PCF we get quite a
  854. lot of these legitimately - Poll frames with no
  855. data. */
  856. goto out;
  857. }
  858. if (length > IEEE80211_MAX_DATA_LEN) {
  859. printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
  860. dev->name, length);
  861. stats->rx_length_errors++;
  862. goto update_stats;
  863. }
  864. /* Payload size does not include Michael MIC. Increase payload
  865. * size to read it together with the data. */
  866. if (status & HERMES_RXSTAT_MIC)
  867. length += MICHAEL_MIC_LEN;
  868. /* We need space for the packet data itself, plus an ethernet
  869. header, plus 2 bytes so we can align the IP header on a
  870. 32bit boundary, plus 1 byte so we can read in odd length
  871. packets from the card, which has an IO granularity of 16
  872. bits */
  873. skb = dev_alloc_skb(length+ETH_HLEN+2+1);
  874. if (!skb) {
  875. printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
  876. dev->name);
  877. goto update_stats;
  878. }
  879. /* We'll prepend the header, so reserve space for it. The worst
  880. case is no decapsulation, when 802.3 header is prepended and
  881. nothing is removed. 2 is for aligning the IP header. */
  882. skb_reserve(skb, ETH_HLEN + 2);
  883. err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
  884. ALIGN(length, 2), rxfid,
  885. HERMES_802_2_OFFSET);
  886. if (err) {
  887. printk(KERN_ERR "%s: error %d reading frame. "
  888. "Frame dropped.\n", dev->name, err);
  889. goto drop;
  890. }
  891. /* Add desc and skb to rx queue */
  892. rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
  893. if (!rx_data) {
  894. printk(KERN_WARNING "%s: Can't allocate RX packet\n",
  895. dev->name);
  896. goto drop;
  897. }
  898. rx_data->desc = desc;
  899. rx_data->skb = skb;
  900. list_add_tail(&rx_data->list, &priv->rx_list);
  901. tasklet_schedule(&priv->rx_tasklet);
  902. return;
  903. drop:
  904. dev_kfree_skb_irq(skb);
  905. update_stats:
  906. stats->rx_errors++;
  907. stats->rx_dropped++;
  908. out:
  909. kfree(desc);
  910. }
  911. static void orinoco_rx(struct net_device *dev,
  912. struct hermes_rx_descriptor *desc,
  913. struct sk_buff *skb)
  914. {
  915. struct orinoco_private *priv = netdev_priv(dev);
  916. struct net_device_stats *stats = &priv->stats;
  917. u16 status, fc;
  918. int length;
  919. struct ethhdr *hdr;
  920. status = le16_to_cpu(desc->status);
  921. length = le16_to_cpu(desc->data_len);
  922. fc = le16_to_cpu(desc->frame_ctl);
  923. /* Calculate and check MIC */
  924. if (status & HERMES_RXSTAT_MIC) {
  925. int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
  926. HERMES_MIC_KEY_ID_SHIFT);
  927. u8 mic[MICHAEL_MIC_LEN];
  928. u8 *rxmic;
  929. u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
  930. desc->addr3 : desc->addr2;
  931. /* Extract Michael MIC from payload */
  932. rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
  933. skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
  934. length -= MICHAEL_MIC_LEN;
  935. orinoco_mic(priv->rx_tfm_mic,
  936. priv->tkip_key[key_id].rx_mic,
  937. desc->addr1,
  938. src,
  939. 0, /* priority or QoS? */
  940. skb->data,
  941. skb->len,
  942. &mic[0]);
  943. if (memcmp(mic, rxmic,
  944. MICHAEL_MIC_LEN)) {
  945. union iwreq_data wrqu;
  946. struct iw_michaelmicfailure wxmic;
  947. printk(KERN_WARNING "%s: "
  948. "Invalid Michael MIC in data frame from %pM, "
  949. "using key %i\n",
  950. dev->name, src, key_id);
  951. /* TODO: update stats */
  952. /* Notify userspace */
  953. memset(&wxmic, 0, sizeof(wxmic));
  954. wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
  955. wxmic.flags |= (desc->addr1[0] & 1) ?
  956. IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
  957. wxmic.src_addr.sa_family = ARPHRD_ETHER;
  958. memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
  959. (void) orinoco_hw_get_tkip_iv(priv, key_id,
  960. &wxmic.tsc[0]);
  961. memset(&wrqu, 0, sizeof(wrqu));
  962. wrqu.data.length = sizeof(wxmic);
  963. wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
  964. (char *) &wxmic);
  965. goto drop;
  966. }
  967. }
  968. /* Handle decapsulation
  969. * In most cases, the firmware tell us about SNAP frames.
  970. * For some reason, the SNAP frames sent by LinkSys APs
  971. * are not properly recognised by most firmwares.
  972. * So, check ourselves */
  973. if (length >= ENCAPS_OVERHEAD &&
  974. (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
  975. ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
  976. is_ethersnap(skb->data))) {
  977. /* These indicate a SNAP within 802.2 LLC within
  978. 802.11 frame which we'll need to de-encapsulate to
  979. the original EthernetII frame. */
  980. hdr = (struct ethhdr *)skb_push(skb,
  981. ETH_HLEN - ENCAPS_OVERHEAD);
  982. } else {
  983. /* 802.3 frame - prepend 802.3 header as is */
  984. hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
  985. hdr->h_proto = htons(length);
  986. }
  987. memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
  988. if (fc & IEEE80211_FCTL_FROMDS)
  989. memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
  990. else
  991. memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
  992. skb->protocol = eth_type_trans(skb, dev);
  993. skb->ip_summed = CHECKSUM_NONE;
  994. if (fc & IEEE80211_FCTL_TODS)
  995. skb->pkt_type = PACKET_OTHERHOST;
  996. /* Process the wireless stats if needed */
  997. orinoco_stat_gather(dev, skb, desc);
  998. /* Pass the packet to the networking stack */
  999. netif_rx(skb);
  1000. stats->rx_packets++;
  1001. stats->rx_bytes += length;
  1002. return;
  1003. drop:
  1004. dev_kfree_skb(skb);
  1005. stats->rx_errors++;
  1006. stats->rx_dropped++;
  1007. }
  1008. static void orinoco_rx_isr_tasklet(unsigned long data)
  1009. {
  1010. struct net_device *dev = (struct net_device *) data;
  1011. struct orinoco_private *priv = netdev_priv(dev);
  1012. struct orinoco_rx_data *rx_data, *temp;
  1013. struct hermes_rx_descriptor *desc;
  1014. struct sk_buff *skb;
  1015. unsigned long flags;
  1016. /* orinoco_rx requires the driver lock, and we also need to
  1017. * protect priv->rx_list, so just hold the lock over the
  1018. * lot.
  1019. *
  1020. * If orinoco_lock fails, we've unplugged the card. In this
  1021. * case just abort. */
  1022. if (orinoco_lock(priv, &flags) != 0)
  1023. return;
  1024. /* extract desc and skb from queue */
  1025. list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
  1026. desc = rx_data->desc;
  1027. skb = rx_data->skb;
  1028. list_del(&rx_data->list);
  1029. kfree(rx_data);
  1030. orinoco_rx(dev, desc, skb);
  1031. kfree(desc);
  1032. }
  1033. orinoco_unlock(priv, &flags);
  1034. }
  1035. /********************************************************************/
  1036. /* Rx path (info frames) */
  1037. /********************************************************************/
  1038. static void print_linkstatus(struct net_device *dev, u16 status)
  1039. {
  1040. char *s;
  1041. if (suppress_linkstatus)
  1042. return;
  1043. switch (status) {
  1044. case HERMES_LINKSTATUS_NOT_CONNECTED:
  1045. s = "Not Connected";
  1046. break;
  1047. case HERMES_LINKSTATUS_CONNECTED:
  1048. s = "Connected";
  1049. break;
  1050. case HERMES_LINKSTATUS_DISCONNECTED:
  1051. s = "Disconnected";
  1052. break;
  1053. case HERMES_LINKSTATUS_AP_CHANGE:
  1054. s = "AP Changed";
  1055. break;
  1056. case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
  1057. s = "AP Out of Range";
  1058. break;
  1059. case HERMES_LINKSTATUS_AP_IN_RANGE:
  1060. s = "AP In Range";
  1061. break;
  1062. case HERMES_LINKSTATUS_ASSOC_FAILED:
  1063. s = "Association Failed";
  1064. break;
  1065. default:
  1066. s = "UNKNOWN";
  1067. }
  1068. printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
  1069. dev->name, s, status);
  1070. }
  1071. /* Search scan results for requested BSSID, join it if found */
  1072. static void orinoco_join_ap(struct work_struct *work)
  1073. {
  1074. struct orinoco_private *priv =
  1075. container_of(work, struct orinoco_private, join_work);
  1076. struct net_device *dev = priv->ndev;
  1077. struct hermes *hw = &priv->hw;
  1078. int err;
  1079. unsigned long flags;
  1080. struct join_req {
  1081. u8 bssid[ETH_ALEN];
  1082. __le16 channel;
  1083. } __attribute__ ((packed)) req;
  1084. const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
  1085. struct prism2_scan_apinfo *atom = NULL;
  1086. int offset = 4;
  1087. int found = 0;
  1088. u8 *buf;
  1089. u16 len;
  1090. /* Allocate buffer for scan results */
  1091. buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
  1092. if (!buf)
  1093. return;
  1094. if (orinoco_lock(priv, &flags) != 0)
  1095. goto fail_lock;
  1096. /* Sanity checks in case user changed something in the meantime */
  1097. if (!priv->bssid_fixed)
  1098. goto out;
  1099. if (strlen(priv->desired_essid) == 0)
  1100. goto out;
  1101. /* Read scan results from the firmware */
  1102. err = hermes_read_ltv(hw, USER_BAP,
  1103. HERMES_RID_SCANRESULTSTABLE,
  1104. MAX_SCAN_LEN, &len, buf);
  1105. if (err) {
  1106. printk(KERN_ERR "%s: Cannot read scan results\n",
  1107. dev->name);
  1108. goto out;
  1109. }
  1110. len = HERMES_RECLEN_TO_BYTES(len);
  1111. /* Go through the scan results looking for the channel of the AP
  1112. * we were requested to join */
  1113. for (; offset + atom_len <= len; offset += atom_len) {
  1114. atom = (struct prism2_scan_apinfo *) (buf + offset);
  1115. if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
  1116. found = 1;
  1117. break;
  1118. }
  1119. }
  1120. if (!found) {
  1121. DEBUG(1, "%s: Requested AP not found in scan results\n",
  1122. dev->name);
  1123. goto out;
  1124. }
  1125. memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
  1126. req.channel = atom->channel; /* both are little-endian */
  1127. err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
  1128. &req);
  1129. if (err)
  1130. printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
  1131. out:
  1132. orinoco_unlock(priv, &flags);
  1133. fail_lock:
  1134. kfree(buf);
  1135. }
  1136. /* Send new BSSID to userspace */
  1137. static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
  1138. {
  1139. struct net_device *dev = priv->ndev;
  1140. struct hermes *hw = &priv->hw;
  1141. union iwreq_data wrqu;
  1142. int err;
  1143. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  1144. ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
  1145. if (err != 0)
  1146. return;
  1147. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  1148. /* Send event to user space */
  1149. wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
  1150. }
  1151. static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
  1152. {
  1153. struct net_device *dev = priv->ndev;
  1154. struct hermes *hw = &priv->hw;
  1155. union iwreq_data wrqu;
  1156. int err;
  1157. u8 buf[88];
  1158. u8 *ie;
  1159. if (!priv->has_wpa)
  1160. return;
  1161. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
  1162. sizeof(buf), NULL, &buf);
  1163. if (err != 0)
  1164. return;
  1165. ie = orinoco_get_wpa_ie(buf, sizeof(buf));
  1166. if (ie) {
  1167. int rem = sizeof(buf) - (ie - &buf[0]);
  1168. wrqu.data.length = ie[1] + 2;
  1169. if (wrqu.data.length > rem)
  1170. wrqu.data.length = rem;
  1171. if (wrqu.data.length)
  1172. /* Send event to user space */
  1173. wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
  1174. }
  1175. }
  1176. static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
  1177. {
  1178. struct net_device *dev = priv->ndev;
  1179. struct hermes *hw = &priv->hw;
  1180. union iwreq_data wrqu;
  1181. int err;
  1182. u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
  1183. u8 *ie;
  1184. if (!priv->has_wpa)
  1185. return;
  1186. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
  1187. sizeof(buf), NULL, &buf);
  1188. if (err != 0)
  1189. return;
  1190. ie = orinoco_get_wpa_ie(buf, sizeof(buf));
  1191. if (ie) {
  1192. int rem = sizeof(buf) - (ie - &buf[0]);
  1193. wrqu.data.length = ie[1] + 2;
  1194. if (wrqu.data.length > rem)
  1195. wrqu.data.length = rem;
  1196. if (wrqu.data.length)
  1197. /* Send event to user space */
  1198. wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
  1199. }
  1200. }
  1201. static void orinoco_send_wevents(struct work_struct *work)
  1202. {
  1203. struct orinoco_private *priv =
  1204. container_of(work, struct orinoco_private, wevent_work);
  1205. unsigned long flags;
  1206. if (orinoco_lock(priv, &flags) != 0)
  1207. return;
  1208. orinoco_send_assocreqie_wevent(priv);
  1209. orinoco_send_assocrespie_wevent(priv);
  1210. orinoco_send_bssid_wevent(priv);
  1211. orinoco_unlock(priv, &flags);
  1212. }
  1213. static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
  1214. {
  1215. struct orinoco_private *priv = netdev_priv(dev);
  1216. u16 infofid;
  1217. struct {
  1218. __le16 len;
  1219. __le16 type;
  1220. } __attribute__ ((packed)) info;
  1221. int len, type;
  1222. int err;
  1223. /* This is an answer to an INQUIRE command that we did earlier,
  1224. * or an information "event" generated by the card
  1225. * The controller return to us a pseudo frame containing
  1226. * the information in question - Jean II */
  1227. infofid = hermes_read_regn(hw, INFOFID);
  1228. /* Read the info frame header - don't try too hard */
  1229. err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
  1230. infofid, 0);
  1231. if (err) {
  1232. printk(KERN_ERR "%s: error %d reading info frame. "
  1233. "Frame dropped.\n", dev->name, err);
  1234. return;
  1235. }
  1236. len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
  1237. type = le16_to_cpu(info.type);
  1238. switch (type) {
  1239. case HERMES_INQ_TALLIES: {
  1240. struct hermes_tallies_frame tallies;
  1241. struct iw_statistics *wstats = &priv->wstats;
  1242. if (len > sizeof(tallies)) {
  1243. printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
  1244. dev->name, len);
  1245. len = sizeof(tallies);
  1246. }
  1247. err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
  1248. infofid, sizeof(info));
  1249. if (err)
  1250. break;
  1251. /* Increment our various counters */
  1252. /* wstats->discard.nwid - no wrong BSSID stuff */
  1253. wstats->discard.code +=
  1254. le16_to_cpu(tallies.RxWEPUndecryptable);
  1255. if (len == sizeof(tallies))
  1256. wstats->discard.code +=
  1257. le16_to_cpu(tallies.RxDiscards_WEPICVError) +
  1258. le16_to_cpu(tallies.RxDiscards_WEPExcluded);
  1259. wstats->discard.misc +=
  1260. le16_to_cpu(tallies.TxDiscardsWrongSA);
  1261. wstats->discard.fragment +=
  1262. le16_to_cpu(tallies.RxMsgInBadMsgFragments);
  1263. wstats->discard.retries +=
  1264. le16_to_cpu(tallies.TxRetryLimitExceeded);
  1265. /* wstats->miss.beacon - no match */
  1266. }
  1267. break;
  1268. case HERMES_INQ_LINKSTATUS: {
  1269. struct hermes_linkstatus linkstatus;
  1270. u16 newstatus;
  1271. int connected;
  1272. if (priv->iw_mode == IW_MODE_MONITOR)
  1273. break;
  1274. if (len != sizeof(linkstatus)) {
  1275. printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
  1276. dev->name, len);
  1277. break;
  1278. }
  1279. err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
  1280. infofid, sizeof(info));
  1281. if (err)
  1282. break;
  1283. newstatus = le16_to_cpu(linkstatus.linkstatus);
  1284. /* Symbol firmware uses "out of range" to signal that
  1285. * the hostscan frame can be requested. */
  1286. if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
  1287. priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
  1288. priv->has_hostscan && priv->scan_inprogress) {
  1289. hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
  1290. break;
  1291. }
  1292. connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
  1293. || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
  1294. || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
  1295. if (connected)
  1296. netif_carrier_on(dev);
  1297. else if (!ignore_disconnect)
  1298. netif_carrier_off(dev);
  1299. if (newstatus != priv->last_linkstatus) {
  1300. priv->last_linkstatus = newstatus;
  1301. print_linkstatus(dev, newstatus);
  1302. /* The info frame contains only one word which is the
  1303. * status (see hermes.h). The status is pretty boring
  1304. * in itself, that's why we export the new BSSID...
  1305. * Jean II */
  1306. schedule_work(&priv->wevent_work);
  1307. }
  1308. }
  1309. break;
  1310. case HERMES_INQ_SCAN:
  1311. if (!priv->scan_inprogress && priv->bssid_fixed &&
  1312. priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
  1313. schedule_work(&priv->join_work);
  1314. break;
  1315. }
  1316. /* fall through */
  1317. case HERMES_INQ_HOSTSCAN:
  1318. case HERMES_INQ_HOSTSCAN_SYMBOL: {
  1319. /* Result of a scanning. Contains information about
  1320. * cells in the vicinity - Jean II */
  1321. union iwreq_data wrqu;
  1322. unsigned char *buf;
  1323. /* Scan is no longer in progress */
  1324. priv->scan_inprogress = 0;
  1325. /* Sanity check */
  1326. if (len > 4096) {
  1327. printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
  1328. dev->name, len);
  1329. break;
  1330. }
  1331. /* Allocate buffer for results */
  1332. buf = kmalloc(len, GFP_ATOMIC);
  1333. if (buf == NULL)
  1334. /* No memory, so can't printk()... */
  1335. break;
  1336. /* Read scan data */
  1337. err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
  1338. infofid, sizeof(info));
  1339. if (err) {
  1340. kfree(buf);
  1341. break;
  1342. }
  1343. #ifdef ORINOCO_DEBUG
  1344. {
  1345. int i;
  1346. printk(KERN_DEBUG "Scan result [%02X", buf[0]);
  1347. for (i = 1; i < (len * 2); i++)
  1348. printk(":%02X", buf[i]);
  1349. printk("]\n");
  1350. }
  1351. #endif /* ORINOCO_DEBUG */
  1352. if (orinoco_process_scan_results(priv, buf, len) == 0) {
  1353. /* Send an empty event to user space.
  1354. * We don't send the received data on the event because
  1355. * it would require us to do complex transcoding, and
  1356. * we want to minimise the work done in the irq handler
  1357. * Use a request to extract the data - Jean II */
  1358. wrqu.data.length = 0;
  1359. wrqu.data.flags = 0;
  1360. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1361. }
  1362. kfree(buf);
  1363. }
  1364. break;
  1365. case HERMES_INQ_CHANNELINFO:
  1366. {
  1367. struct agere_ext_scan_info *bss;
  1368. if (!priv->scan_inprogress) {
  1369. printk(KERN_DEBUG "%s: Got chaninfo without scan, "
  1370. "len=%d\n", dev->name, len);
  1371. break;
  1372. }
  1373. /* An empty result indicates that the scan is complete */
  1374. if (len == 0) {
  1375. union iwreq_data wrqu;
  1376. /* Scan is no longer in progress */
  1377. priv->scan_inprogress = 0;
  1378. wrqu.data.length = 0;
  1379. wrqu.data.flags = 0;
  1380. wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
  1381. break;
  1382. }
  1383. /* Sanity check */
  1384. else if (len > sizeof(*bss)) {
  1385. printk(KERN_WARNING
  1386. "%s: Ext scan results too large (%d bytes). "
  1387. "Truncating results to %zd bytes.\n",
  1388. dev->name, len, sizeof(*bss));
  1389. len = sizeof(*bss);
  1390. } else if (len < (offsetof(struct agere_ext_scan_info,
  1391. data) + 2)) {
  1392. /* Drop this result now so we don't have to
  1393. * keep checking later */
  1394. printk(KERN_WARNING
  1395. "%s: Ext scan results too short (%d bytes)\n",
  1396. dev->name, len);
  1397. break;
  1398. }
  1399. bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
  1400. if (bss == NULL)
  1401. break;
  1402. /* Read scan data */
  1403. err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
  1404. infofid, sizeof(info));
  1405. if (err) {
  1406. kfree(bss);
  1407. break;
  1408. }
  1409. orinoco_add_ext_scan_result(priv, bss);
  1410. kfree(bss);
  1411. break;
  1412. }
  1413. case HERMES_INQ_SEC_STAT_AGERE:
  1414. /* Security status (Agere specific) */
  1415. /* Ignore this frame for now */
  1416. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  1417. break;
  1418. /* fall through */
  1419. default:
  1420. printk(KERN_DEBUG "%s: Unknown information frame received: "
  1421. "type 0x%04x, length %d\n", dev->name, type, len);
  1422. /* We don't actually do anything about it */
  1423. break;
  1424. }
  1425. }
  1426. static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
  1427. {
  1428. if (net_ratelimit())
  1429. printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
  1430. }
  1431. /********************************************************************/
  1432. /* Internal hardware control routines */
  1433. /********************************************************************/
  1434. int __orinoco_up(struct net_device *dev)
  1435. {
  1436. struct orinoco_private *priv = netdev_priv(dev);
  1437. struct hermes *hw = &priv->hw;
  1438. int err;
  1439. netif_carrier_off(dev); /* just to make sure */
  1440. err = __orinoco_program_rids(dev);
  1441. if (err) {
  1442. printk(KERN_ERR "%s: Error %d configuring card\n",
  1443. dev->name, err);
  1444. return err;
  1445. }
  1446. /* Fire things up again */
  1447. hermes_set_irqmask(hw, ORINOCO_INTEN);
  1448. err = hermes_enable_port(hw, 0);
  1449. if (err) {
  1450. printk(KERN_ERR "%s: Error %d enabling MAC port\n",
  1451. dev->name, err);
  1452. return err;
  1453. }
  1454. netif_start_queue(dev);
  1455. return 0;
  1456. }
  1457. EXPORT_SYMBOL(__orinoco_up);
  1458. int __orinoco_down(struct net_device *dev)
  1459. {
  1460. struct orinoco_private *priv = netdev_priv(dev);
  1461. struct hermes *hw = &priv->hw;
  1462. int err;
  1463. netif_stop_queue(dev);
  1464. if (!priv->hw_unavailable) {
  1465. if (!priv->broken_disableport) {
  1466. err = hermes_disable_port(hw, 0);
  1467. if (err) {
  1468. /* Some firmwares (e.g. Intersil 1.3.x) seem
  1469. * to have problems disabling the port, oh
  1470. * well, too bad. */
  1471. printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
  1472. dev->name, err);
  1473. priv->broken_disableport = 1;
  1474. }
  1475. }
  1476. hermes_set_irqmask(hw, 0);
  1477. hermes_write_regn(hw, EVACK, 0xffff);
  1478. }
  1479. /* firmware will have to reassociate */
  1480. netif_carrier_off(dev);
  1481. priv->last_linkstatus = 0xffff;
  1482. return 0;
  1483. }
  1484. EXPORT_SYMBOL(__orinoco_down);
  1485. static int orinoco_allocate_fid(struct net_device *dev)
  1486. {
  1487. struct orinoco_private *priv = netdev_priv(dev);
  1488. struct hermes *hw = &priv->hw;
  1489. int err;
  1490. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1491. if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
  1492. /* Try workaround for old Symbol firmware bug */
  1493. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  1494. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  1495. printk(KERN_WARNING "%s: firmware ALLOC bug detected "
  1496. "(old Symbol firmware?). Work around %s\n",
  1497. dev->name, err ? "failed!" : "ok.");
  1498. }
  1499. return err;
  1500. }
  1501. int orinoco_reinit_firmware(struct net_device *dev)
  1502. {
  1503. struct orinoco_private *priv = netdev_priv(dev);
  1504. struct hermes *hw = &priv->hw;
  1505. int err;
  1506. err = hermes_init(hw);
  1507. if (priv->do_fw_download && !err) {
  1508. err = orinoco_download(priv);
  1509. if (err)
  1510. priv->do_fw_download = 0;
  1511. }
  1512. if (!err)
  1513. err = orinoco_allocate_fid(dev);
  1514. return err;
  1515. }
  1516. EXPORT_SYMBOL(orinoco_reinit_firmware);
  1517. static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
  1518. {
  1519. hermes_t *hw = &priv->hw;
  1520. int ratemode = priv->bitratemode;
  1521. int err = 0;
  1522. if (ratemode >= BITRATE_TABLE_SIZE) {
  1523. printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
  1524. priv->ndev->name, ratemode);
  1525. return -EINVAL;
  1526. }
  1527. switch (priv->firmware_type) {
  1528. case FIRMWARE_TYPE_AGERE:
  1529. err = hermes_write_wordrec(hw, USER_BAP,
  1530. HERMES_RID_CNFTXRATECONTROL,
  1531. bitrate_table[ratemode].agere_txratectrl);
  1532. break;
  1533. case FIRMWARE_TYPE_INTERSIL:
  1534. case FIRMWARE_TYPE_SYMBOL:
  1535. err = hermes_write_wordrec(hw, USER_BAP,
  1536. HERMES_RID_CNFTXRATECONTROL,
  1537. bitrate_table[ratemode].intersil_txratectrl);
  1538. break;
  1539. default:
  1540. BUG();
  1541. }
  1542. return err;
  1543. }
  1544. static int orinoco_hw_get_act_bitrate(struct orinoco_private *priv,
  1545. int *bitrate)
  1546. {
  1547. hermes_t *hw = &priv->hw;
  1548. int i;
  1549. int err = 0;
  1550. u16 val;
  1551. err = hermes_read_wordrec(hw, USER_BAP,
  1552. HERMES_RID_CURRENTTXRATE, &val);
  1553. if (err)
  1554. return err;
  1555. switch (priv->firmware_type) {
  1556. case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
  1557. /* Note : in Lucent firmware, the return value of
  1558. * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
  1559. * and therefore is totally different from the
  1560. * encoding of HERMES_RID_CNFTXRATECONTROL.
  1561. * Don't forget that 6Mb/s is really 5.5Mb/s */
  1562. if (val == 6)
  1563. *bitrate = 5500000;
  1564. else
  1565. *bitrate = val * 1000000;
  1566. break;
  1567. case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
  1568. case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
  1569. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  1570. if (bitrate_table[i].intersil_txratectrl == val)
  1571. break;
  1572. if (i >= BITRATE_TABLE_SIZE)
  1573. printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
  1574. priv->ndev->name, val);
  1575. *bitrate = bitrate_table[i].bitrate * 100000;
  1576. break;
  1577. default:
  1578. BUG();
  1579. }
  1580. return err;
  1581. }
  1582. /* Set fixed AP address */
  1583. static int __orinoco_hw_set_wap(struct orinoco_private *priv)
  1584. {
  1585. int roaming_flag;
  1586. int err = 0;
  1587. hermes_t *hw = &priv->hw;
  1588. switch (priv->firmware_type) {
  1589. case FIRMWARE_TYPE_AGERE:
  1590. /* not supported */
  1591. break;
  1592. case FIRMWARE_TYPE_INTERSIL:
  1593. if (priv->bssid_fixed)
  1594. roaming_flag = 2;
  1595. else
  1596. roaming_flag = 1;
  1597. err = hermes_write_wordrec(hw, USER_BAP,
  1598. HERMES_RID_CNFROAMINGMODE,
  1599. roaming_flag);
  1600. break;
  1601. case FIRMWARE_TYPE_SYMBOL:
  1602. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1603. HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
  1604. &priv->desired_bssid);
  1605. break;
  1606. }
  1607. return err;
  1608. }
  1609. /* Change the WEP keys and/or the current keys. Can be called
  1610. * either from __orinoco_hw_setup_enc() or directly from
  1611. * orinoco_ioctl_setiwencode(). In the later case the association
  1612. * with the AP is not broken (if the firmware can handle it),
  1613. * which is needed for 802.1x implementations. */
  1614. static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
  1615. {
  1616. hermes_t *hw = &priv->hw;
  1617. int err = 0;
  1618. switch (priv->firmware_type) {
  1619. case FIRMWARE_TYPE_AGERE:
  1620. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1621. HERMES_RID_CNFWEPKEYS_AGERE,
  1622. &priv->keys);
  1623. if (err)
  1624. return err;
  1625. err = hermes_write_wordrec(hw, USER_BAP,
  1626. HERMES_RID_CNFTXKEY_AGERE,
  1627. priv->tx_key);
  1628. if (err)
  1629. return err;
  1630. break;
  1631. case FIRMWARE_TYPE_INTERSIL:
  1632. case FIRMWARE_TYPE_SYMBOL:
  1633. {
  1634. int keylen;
  1635. int i;
  1636. /* Force uniform key length to work around
  1637. * firmware bugs */
  1638. keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
  1639. if (keylen > LARGE_KEY_SIZE) {
  1640. printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
  1641. priv->ndev->name, priv->tx_key, keylen);
  1642. return -E2BIG;
  1643. }
  1644. /* Write all 4 keys */
  1645. for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
  1646. err = hermes_write_ltv(hw, USER_BAP,
  1647. HERMES_RID_CNFDEFAULTKEY0 + i,
  1648. HERMES_BYTES_TO_RECLEN(keylen),
  1649. priv->keys[i].data);
  1650. if (err)
  1651. return err;
  1652. }
  1653. /* Write the index of the key used in transmission */
  1654. err = hermes_write_wordrec(hw, USER_BAP,
  1655. HERMES_RID_CNFWEPDEFAULTKEYID,
  1656. priv->tx_key);
  1657. if (err)
  1658. return err;
  1659. }
  1660. break;
  1661. }
  1662. return 0;
  1663. }
  1664. static int __orinoco_hw_setup_enc(struct orinoco_private *priv)
  1665. {
  1666. hermes_t *hw = &priv->hw;
  1667. int err = 0;
  1668. int master_wep_flag;
  1669. int auth_flag;
  1670. int enc_flag;
  1671. /* Setup WEP keys for WEP and WPA */
  1672. if (priv->encode_alg)
  1673. __orinoco_hw_setup_wepkeys(priv);
  1674. if (priv->wep_restrict)
  1675. auth_flag = HERMES_AUTH_SHARED_KEY;
  1676. else
  1677. auth_flag = HERMES_AUTH_OPEN;
  1678. if (priv->wpa_enabled)
  1679. enc_flag = 2;
  1680. else if (priv->encode_alg == IW_ENCODE_ALG_WEP)
  1681. enc_flag = 1;
  1682. else
  1683. enc_flag = 0;
  1684. switch (priv->firmware_type) {
  1685. case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
  1686. if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
  1687. /* Enable the shared-key authentication. */
  1688. err = hermes_write_wordrec(hw, USER_BAP,
  1689. HERMES_RID_CNFAUTHENTICATION_AGERE,
  1690. auth_flag);
  1691. }
  1692. err = hermes_write_wordrec(hw, USER_BAP,
  1693. HERMES_RID_CNFWEPENABLED_AGERE,
  1694. enc_flag);
  1695. if (err)
  1696. return err;
  1697. if (priv->has_wpa) {
  1698. /* Set WPA key management */
  1699. err = hermes_write_wordrec(hw, USER_BAP,
  1700. HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
  1701. priv->key_mgmt);
  1702. if (err)
  1703. return err;
  1704. }
  1705. break;
  1706. case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
  1707. case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
  1708. if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
  1709. if (priv->wep_restrict ||
  1710. (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
  1711. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
  1712. HERMES_WEP_EXCL_UNENCRYPTED;
  1713. else
  1714. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
  1715. err = hermes_write_wordrec(hw, USER_BAP,
  1716. HERMES_RID_CNFAUTHENTICATION,
  1717. auth_flag);
  1718. if (err)
  1719. return err;
  1720. } else
  1721. master_wep_flag = 0;
  1722. if (priv->iw_mode == IW_MODE_MONITOR)
  1723. master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
  1724. /* Master WEP setting : on/off */
  1725. err = hermes_write_wordrec(hw, USER_BAP,
  1726. HERMES_RID_CNFWEPFLAGS_INTERSIL,
  1727. master_wep_flag);
  1728. if (err)
  1729. return err;
  1730. break;
  1731. }
  1732. return 0;
  1733. }
  1734. /* key must be 32 bytes, including the tx and rx MIC keys.
  1735. * rsc must be 8 bytes
  1736. * tsc must be 8 bytes or NULL
  1737. */
  1738. static int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx,
  1739. u8 *key, u8 *rsc, u8 *tsc)
  1740. {
  1741. struct {
  1742. __le16 idx;
  1743. u8 rsc[IW_ENCODE_SEQ_MAX_SIZE];
  1744. u8 key[TKIP_KEYLEN];
  1745. u8 tx_mic[MIC_KEYLEN];
  1746. u8 rx_mic[MIC_KEYLEN];
  1747. u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
  1748. } __attribute__ ((packed)) buf;
  1749. int ret;
  1750. int err;
  1751. int k;
  1752. u16 xmitting;
  1753. key_idx &= 0x3;
  1754. if (set_tx)
  1755. key_idx |= 0x8000;
  1756. buf.idx = cpu_to_le16(key_idx);
  1757. memcpy(buf.key, key,
  1758. sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
  1759. if (rsc == NULL)
  1760. memset(buf.rsc, 0, sizeof(buf.rsc));
  1761. else
  1762. memcpy(buf.rsc, rsc, sizeof(buf.rsc));
  1763. if (tsc == NULL) {
  1764. memset(buf.tsc, 0, sizeof(buf.tsc));
  1765. buf.tsc[4] = 0x10;
  1766. } else {
  1767. memcpy(buf.tsc, tsc, sizeof(buf.tsc));
  1768. }
  1769. /* Wait upto 100ms for tx queue to empty */
  1770. k = 100;
  1771. do {
  1772. k--;
  1773. udelay(1000);
  1774. ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
  1775. &xmitting);
  1776. if (ret)
  1777. break;
  1778. } while ((k > 0) && xmitting);
  1779. if (k == 0)
  1780. ret = -ETIMEDOUT;
  1781. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1782. HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
  1783. &buf);
  1784. return ret ? ret : err;
  1785. }
  1786. static int orinoco_clear_tkip_key(struct orinoco_private *priv,
  1787. int key_idx)
  1788. {
  1789. hermes_t *hw = &priv->hw;
  1790. int err;
  1791. memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
  1792. err = hermes_write_wordrec(hw, USER_BAP,
  1793. HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
  1794. key_idx);
  1795. if (err)
  1796. printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
  1797. priv->ndev->name, err, key_idx);
  1798. return err;
  1799. }
  1800. static int __orinoco_program_rids(struct net_device *dev)
  1801. {
  1802. struct orinoco_private *priv = netdev_priv(dev);
  1803. hermes_t *hw = &priv->hw;
  1804. int err;
  1805. struct hermes_idstring idbuf;
  1806. /* Set the MAC address */
  1807. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  1808. HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
  1809. if (err) {
  1810. printk(KERN_ERR "%s: Error %d setting MAC address\n",
  1811. dev->name, err);
  1812. return err;
  1813. }
  1814. /* Set up the link mode */
  1815. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
  1816. priv->port_type);
  1817. if (err) {
  1818. printk(KERN_ERR "%s: Error %d setting port type\n",
  1819. dev->name, err);
  1820. return err;
  1821. }
  1822. /* Set the channel/frequency */
  1823. if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
  1824. err = hermes_write_wordrec(hw, USER_BAP,
  1825. HERMES_RID_CNFOWNCHANNEL,
  1826. priv->channel);
  1827. if (err) {
  1828. printk(KERN_ERR "%s: Error %d setting channel %d\n",
  1829. dev->name, err, priv->channel);
  1830. return err;
  1831. }
  1832. }
  1833. if (priv->has_ibss) {
  1834. u16 createibss;
  1835. if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
  1836. printk(KERN_WARNING "%s: This firmware requires an "
  1837. "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
  1838. /* With wvlan_cs, in this case, we would crash.
  1839. * hopefully, this driver will behave better...
  1840. * Jean II */
  1841. createibss = 0;
  1842. } else {
  1843. createibss = priv->createibss;
  1844. }
  1845. err = hermes_write_wordrec(hw, USER_BAP,
  1846. HERMES_RID_CNFCREATEIBSS,
  1847. createibss);
  1848. if (err) {
  1849. printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
  1850. dev->name, err);
  1851. return err;
  1852. }
  1853. }
  1854. /* Set the desired BSSID */
  1855. err = __orinoco_hw_set_wap(priv);
  1856. if (err) {
  1857. printk(KERN_ERR "%s: Error %d setting AP address\n",
  1858. dev->name, err);
  1859. return err;
  1860. }
  1861. /* Set the desired ESSID */
  1862. idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
  1863. memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
  1864. /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
  1865. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
  1866. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1867. &idbuf);
  1868. if (err) {
  1869. printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
  1870. dev->name, err);
  1871. return err;
  1872. }
  1873. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
  1874. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
  1875. &idbuf);
  1876. if (err) {
  1877. printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
  1878. dev->name, err);
  1879. return err;
  1880. }
  1881. /* Set the station name */
  1882. idbuf.len = cpu_to_le16(strlen(priv->nick));
  1883. memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
  1884. err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  1885. HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
  1886. &idbuf);
  1887. if (err) {
  1888. printk(KERN_ERR "%s: Error %d setting nickname\n",
  1889. dev->name, err);
  1890. return err;
  1891. }
  1892. /* Set AP density */
  1893. if (priv->has_sensitivity) {
  1894. err = hermes_write_wordrec(hw, USER_BAP,
  1895. HERMES_RID_CNFSYSTEMSCALE,
  1896. priv->ap_density);
  1897. if (err) {
  1898. printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
  1899. "Disabling sensitivity control\n",
  1900. dev->name, err);
  1901. priv->has_sensitivity = 0;
  1902. }
  1903. }
  1904. /* Set RTS threshold */
  1905. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  1906. priv->rts_thresh);
  1907. if (err) {
  1908. printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
  1909. dev->name, err);
  1910. return err;
  1911. }
  1912. /* Set fragmentation threshold or MWO robustness */
  1913. if (priv->has_mwo)
  1914. err = hermes_write_wordrec(hw, USER_BAP,
  1915. HERMES_RID_CNFMWOROBUST_AGERE,
  1916. priv->mwo_robust);
  1917. else
  1918. err = hermes_write_wordrec(hw, USER_BAP,
  1919. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  1920. priv->frag_thresh);
  1921. if (err) {
  1922. printk(KERN_ERR "%s: Error %d setting fragmentation\n",
  1923. dev->name, err);
  1924. return err;
  1925. }
  1926. /* Set bitrate */
  1927. err = __orinoco_hw_set_bitrate(priv);
  1928. if (err) {
  1929. printk(KERN_ERR "%s: Error %d setting bitrate\n",
  1930. dev->name, err);
  1931. return err;
  1932. }
  1933. /* Set power management */
  1934. if (priv->has_pm) {
  1935. err = hermes_write_wordrec(hw, USER_BAP,
  1936. HERMES_RID_CNFPMENABLED,
  1937. priv->pm_on);
  1938. if (err) {
  1939. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1940. dev->name, err);
  1941. return err;
  1942. }
  1943. err = hermes_write_wordrec(hw, USER_BAP,
  1944. HERMES_RID_CNFMULTICASTRECEIVE,
  1945. priv->pm_mcast);
  1946. if (err) {
  1947. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1948. dev->name, err);
  1949. return err;
  1950. }
  1951. err = hermes_write_wordrec(hw, USER_BAP,
  1952. HERMES_RID_CNFMAXSLEEPDURATION,
  1953. priv->pm_period);
  1954. if (err) {
  1955. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1956. dev->name, err);
  1957. return err;
  1958. }
  1959. err = hermes_write_wordrec(hw, USER_BAP,
  1960. HERMES_RID_CNFPMHOLDOVERDURATION,
  1961. priv->pm_timeout);
  1962. if (err) {
  1963. printk(KERN_ERR "%s: Error %d setting up PM\n",
  1964. dev->name, err);
  1965. return err;
  1966. }
  1967. }
  1968. /* Set preamble - only for Symbol so far... */
  1969. if (priv->has_preamble) {
  1970. err = hermes_write_wordrec(hw, USER_BAP,
  1971. HERMES_RID_CNFPREAMBLE_SYMBOL,
  1972. priv->preamble);
  1973. if (err) {
  1974. printk(KERN_ERR "%s: Error %d setting preamble\n",
  1975. dev->name, err);
  1976. return err;
  1977. }
  1978. }
  1979. /* Set up encryption */
  1980. if (priv->has_wep || priv->has_wpa) {
  1981. err = __orinoco_hw_setup_enc(priv);
  1982. if (err) {
  1983. printk(KERN_ERR "%s: Error %d activating encryption\n",
  1984. dev->name, err);
  1985. return err;
  1986. }
  1987. }
  1988. if (priv->iw_mode == IW_MODE_MONITOR) {
  1989. /* Enable monitor mode */
  1990. dev->type = ARPHRD_IEEE80211;
  1991. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  1992. HERMES_TEST_MONITOR, 0, NULL);
  1993. } else {
  1994. /* Disable monitor mode */
  1995. dev->type = ARPHRD_ETHER;
  1996. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  1997. HERMES_TEST_STOP, 0, NULL);
  1998. }
  1999. if (err)
  2000. return err;
  2001. /* Set promiscuity / multicast*/
  2002. priv->promiscuous = 0;
  2003. priv->mc_count = 0;
  2004. /* FIXME: what about netif_tx_lock */
  2005. __orinoco_set_multicast_list(dev);
  2006. return 0;
  2007. }
  2008. /* FIXME: return int? */
  2009. static void
  2010. __orinoco_set_multicast_list(struct net_device *dev)
  2011. {
  2012. struct orinoco_private *priv = netdev_priv(dev);
  2013. hermes_t *hw = &priv->hw;
  2014. int err = 0;
  2015. int promisc, mc_count;
  2016. /* The Hermes doesn't seem to have an allmulti mode, so we go
  2017. * into promiscuous mode and let the upper levels deal. */
  2018. if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
  2019. (dev->mc_count > MAX_MULTICAST(priv))) {
  2020. promisc = 1;
  2021. mc_count = 0;
  2022. } else {
  2023. promisc = 0;
  2024. mc_count = dev->mc_count;
  2025. }
  2026. if (promisc != priv->promiscuous) {
  2027. err = hermes_write_wordrec(hw, USER_BAP,
  2028. HERMES_RID_CNFPROMISCUOUSMODE,
  2029. promisc);
  2030. if (err) {
  2031. printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
  2032. dev->name, err);
  2033. } else
  2034. priv->promiscuous = promisc;
  2035. }
  2036. /* If we're not in promiscuous mode, then we need to set the
  2037. * group address if either we want to multicast, or if we were
  2038. * multicasting and want to stop */
  2039. if (!promisc && (mc_count || priv->mc_count)) {
  2040. struct dev_mc_list *p = dev->mc_list;
  2041. struct hermes_multicast mclist;
  2042. int i;
  2043. for (i = 0; i < mc_count; i++) {
  2044. /* paranoia: is list shorter than mc_count? */
  2045. BUG_ON(!p);
  2046. /* paranoia: bad address size in list? */
  2047. BUG_ON(p->dmi_addrlen != ETH_ALEN);
  2048. memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
  2049. p = p->next;
  2050. }
  2051. if (p)
  2052. printk(KERN_WARNING "%s: Multicast list is "
  2053. "longer than mc_count\n", dev->name);
  2054. err = hermes_write_ltv(hw, USER_BAP,
  2055. HERMES_RID_CNFGROUPADDRESSES,
  2056. HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
  2057. &mclist);
  2058. if (err)
  2059. printk(KERN_ERR "%s: Error %d setting multicast list.\n",
  2060. dev->name, err);
  2061. else
  2062. priv->mc_count = mc_count;
  2063. }
  2064. }
  2065. /* This must be called from user context, without locks held - use
  2066. * schedule_work() */
  2067. static void orinoco_reset(struct work_struct *work)
  2068. {
  2069. struct orinoco_private *priv =
  2070. container_of(work, struct orinoco_private, reset_work);
  2071. struct net_device *dev = priv->ndev;
  2072. struct hermes *hw = &priv->hw;
  2073. int err;
  2074. unsigned long flags;
  2075. if (orinoco_lock(priv, &flags) != 0)
  2076. /* When the hardware becomes available again, whatever
  2077. * detects that is responsible for re-initializing
  2078. * it. So no need for anything further */
  2079. return;
  2080. netif_stop_queue(dev);
  2081. /* Shut off interrupts. Depending on what state the hardware
  2082. * is in, this might not work, but we'll try anyway */
  2083. hermes_set_irqmask(hw, 0);
  2084. hermes_write_regn(hw, EVACK, 0xffff);
  2085. priv->hw_unavailable++;
  2086. priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
  2087. netif_carrier_off(dev);
  2088. orinoco_unlock(priv, &flags);
  2089. /* Scanning support: Cleanup of driver struct */
  2090. orinoco_clear_scan_results(priv, 0);
  2091. priv->scan_inprogress = 0;
  2092. if (priv->hard_reset) {
  2093. err = (*priv->hard_reset)(priv);
  2094. if (err) {
  2095. printk(KERN_ERR "%s: orinoco_reset: Error %d "
  2096. "performing hard reset\n", dev->name, err);
  2097. goto disable;
  2098. }
  2099. }
  2100. err = orinoco_reinit_firmware(dev);
  2101. if (err) {
  2102. printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
  2103. dev->name, err);
  2104. goto disable;
  2105. }
  2106. /* This has to be called from user context */
  2107. spin_lock_irq(&priv->lock);
  2108. priv->hw_unavailable--;
  2109. /* priv->open or priv->hw_unavailable might have changed while
  2110. * we dropped the lock */
  2111. if (priv->open && (!priv->hw_unavailable)) {
  2112. err = __orinoco_up(dev);
  2113. if (err) {
  2114. printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
  2115. dev->name, err);
  2116. } else
  2117. dev->trans_start = jiffies;
  2118. }
  2119. spin_unlock_irq(&priv->lock);
  2120. return;
  2121. disable:
  2122. hermes_set_irqmask(hw, 0);
  2123. netif_device_detach(dev);
  2124. printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
  2125. }
  2126. /********************************************************************/
  2127. /* Interrupt handler */
  2128. /********************************************************************/
  2129. static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
  2130. {
  2131. printk(KERN_DEBUG "%s: TICK\n", dev->name);
  2132. }
  2133. static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
  2134. {
  2135. /* This seems to happen a fair bit under load, but ignoring it
  2136. seems to work fine...*/
  2137. printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
  2138. dev->name);
  2139. }
  2140. irqreturn_t orinoco_interrupt(int irq, void *dev_id)
  2141. {
  2142. struct net_device *dev = dev_id;
  2143. struct orinoco_private *priv = netdev_priv(dev);
  2144. hermes_t *hw = &priv->hw;
  2145. int count = MAX_IRQLOOPS_PER_IRQ;
  2146. u16 evstat, events;
  2147. /* These are used to detect a runaway interrupt situation.
  2148. *
  2149. * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
  2150. * we panic and shut down the hardware
  2151. */
  2152. /* jiffies value the last time we were called */
  2153. static int last_irq_jiffy; /* = 0 */
  2154. static int loops_this_jiffy; /* = 0 */
  2155. unsigned long flags;
  2156. if (orinoco_lock(priv, &flags) != 0) {
  2157. /* If hw is unavailable - we don't know if the irq was
  2158. * for us or not */
  2159. return IRQ_HANDLED;
  2160. }
  2161. evstat = hermes_read_regn(hw, EVSTAT);
  2162. events = evstat & hw->inten;
  2163. if (!events) {
  2164. orinoco_unlock(priv, &flags);
  2165. return IRQ_NONE;
  2166. }
  2167. if (jiffies != last_irq_jiffy)
  2168. loops_this_jiffy = 0;
  2169. last_irq_jiffy = jiffies;
  2170. while (events && count--) {
  2171. if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
  2172. printk(KERN_WARNING "%s: IRQ handler is looping too "
  2173. "much! Resetting.\n", dev->name);
  2174. /* Disable interrupts for now */
  2175. hermes_set_irqmask(hw, 0);
  2176. schedule_work(&priv->reset_work);
  2177. break;
  2178. }
  2179. /* Check the card hasn't been removed */
  2180. if (!hermes_present(hw)) {
  2181. DEBUG(0, "orinoco_interrupt(): card removed\n");
  2182. break;
  2183. }
  2184. if (events & HERMES_EV_TICK)
  2185. __orinoco_ev_tick(dev, hw);
  2186. if (events & HERMES_EV_WTERR)
  2187. __orinoco_ev_wterr(dev, hw);
  2188. if (events & HERMES_EV_INFDROP)
  2189. __orinoco_ev_infdrop(dev, hw);
  2190. if (events & HERMES_EV_INFO)
  2191. __orinoco_ev_info(dev, hw);
  2192. if (events & HERMES_EV_RX)
  2193. __orinoco_ev_rx(dev, hw);
  2194. if (events & HERMES_EV_TXEXC)
  2195. __orinoco_ev_txexc(dev, hw);
  2196. if (events & HERMES_EV_TX)
  2197. __orinoco_ev_tx(dev, hw);
  2198. if (events & HERMES_EV_ALLOC)
  2199. __orinoco_ev_alloc(dev, hw);
  2200. hermes_write_regn(hw, EVACK, evstat);
  2201. evstat = hermes_read_regn(hw, EVSTAT);
  2202. events = evstat & hw->inten;
  2203. };
  2204. orinoco_unlock(priv, &flags);
  2205. return IRQ_HANDLED;
  2206. }
  2207. EXPORT_SYMBOL(orinoco_interrupt);
  2208. /********************************************************************/
  2209. /* Power management */
  2210. /********************************************************************/
  2211. #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
  2212. static int orinoco_pm_notifier(struct notifier_block *notifier,
  2213. unsigned long pm_event,
  2214. void *unused)
  2215. {
  2216. struct orinoco_private *priv = container_of(notifier,
  2217. struct orinoco_private,
  2218. pm_notifier);
  2219. /* All we need to do is cache the firmware before suspend, and
  2220. * release it when we come out.
  2221. *
  2222. * Only need to do this if we're downloading firmware. */
  2223. if (!priv->do_fw_download)
  2224. return NOTIFY_DONE;
  2225. switch (pm_event) {
  2226. case PM_HIBERNATION_PREPARE:
  2227. case PM_SUSPEND_PREPARE:
  2228. orinoco_cache_fw(priv, 0);
  2229. break;
  2230. case PM_POST_RESTORE:
  2231. /* Restore from hibernation failed. We need to clean
  2232. * up in exactly the same way, so fall through. */
  2233. case PM_POST_HIBERNATION:
  2234. case PM_POST_SUSPEND:
  2235. orinoco_uncache_fw(priv);
  2236. break;
  2237. case PM_RESTORE_PREPARE:
  2238. default:
  2239. break;
  2240. }
  2241. return NOTIFY_DONE;
  2242. }
  2243. #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
  2244. #define orinoco_pm_notifier NULL
  2245. #endif
  2246. /********************************************************************/
  2247. /* Initialization */
  2248. /********************************************************************/
  2249. struct comp_id {
  2250. u16 id, variant, major, minor;
  2251. } __attribute__ ((packed));
  2252. static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
  2253. {
  2254. if (nic_id->id < 0x8000)
  2255. return FIRMWARE_TYPE_AGERE;
  2256. else if (nic_id->id == 0x8000 && nic_id->major == 0)
  2257. return FIRMWARE_TYPE_SYMBOL;
  2258. else
  2259. return FIRMWARE_TYPE_INTERSIL;
  2260. }
  2261. /* Set priv->firmware type, determine firmware properties */
  2262. static int determine_firmware(struct net_device *dev)
  2263. {
  2264. struct orinoco_private *priv = netdev_priv(dev);
  2265. hermes_t *hw = &priv->hw;
  2266. int err;
  2267. struct comp_id nic_id, sta_id;
  2268. unsigned int firmver;
  2269. char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
  2270. /* Get the hardware version */
  2271. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
  2272. if (err) {
  2273. printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
  2274. dev->name, err);
  2275. return err;
  2276. }
  2277. le16_to_cpus(&nic_id.id);
  2278. le16_to_cpus(&nic_id.variant);
  2279. le16_to_cpus(&nic_id.major);
  2280. le16_to_cpus(&nic_id.minor);
  2281. printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
  2282. dev->name, nic_id.id, nic_id.variant,
  2283. nic_id.major, nic_id.minor);
  2284. priv->firmware_type = determine_firmware_type(&nic_id);
  2285. /* Get the firmware version */
  2286. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
  2287. if (err) {
  2288. printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
  2289. dev->name, err);
  2290. return err;
  2291. }
  2292. le16_to_cpus(&sta_id.id);
  2293. le16_to_cpus(&sta_id.variant);
  2294. le16_to_cpus(&sta_id.major);
  2295. le16_to_cpus(&sta_id.minor);
  2296. printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
  2297. dev->name, sta_id.id, sta_id.variant,
  2298. sta_id.major, sta_id.minor);
  2299. switch (sta_id.id) {
  2300. case 0x15:
  2301. printk(KERN_ERR "%s: Primary firmware is active\n",
  2302. dev->name);
  2303. return -ENODEV;
  2304. case 0x14b:
  2305. printk(KERN_ERR "%s: Tertiary firmware is active\n",
  2306. dev->name);
  2307. return -ENODEV;
  2308. case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
  2309. case 0x21: /* Symbol Spectrum24 Trilogy */
  2310. break;
  2311. default:
  2312. printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
  2313. dev->name);
  2314. break;
  2315. }
  2316. /* Default capabilities */
  2317. priv->has_sensitivity = 1;
  2318. priv->has_mwo = 0;
  2319. priv->has_preamble = 0;
  2320. priv->has_port3 = 1;
  2321. priv->has_ibss = 1;
  2322. priv->has_wep = 0;
  2323. priv->has_big_wep = 0;
  2324. priv->has_alt_txcntl = 0;
  2325. priv->has_ext_scan = 0;
  2326. priv->has_wpa = 0;
  2327. priv->do_fw_download = 0;
  2328. /* Determine capabilities from the firmware version */
  2329. switch (priv->firmware_type) {
  2330. case FIRMWARE_TYPE_AGERE:
  2331. /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
  2332. ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
  2333. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2334. "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
  2335. firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
  2336. priv->has_ibss = (firmver >= 0x60006);
  2337. priv->has_wep = (firmver >= 0x40020);
  2338. priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
  2339. Gold cards from the others? */
  2340. priv->has_mwo = (firmver >= 0x60000);
  2341. priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
  2342. priv->ibss_port = 1;
  2343. priv->has_hostscan = (firmver >= 0x8000a);
  2344. priv->do_fw_download = 1;
  2345. priv->broken_monitor = (firmver >= 0x80000);
  2346. priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
  2347. priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
  2348. priv->has_wpa = (firmver >= 0x9002a);
  2349. /* Tested with Agere firmware :
  2350. * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
  2351. * Tested CableTron firmware : 4.32 => Anton */
  2352. break;
  2353. case FIRMWARE_TYPE_SYMBOL:
  2354. /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
  2355. /* Intel MAC : 00:02:B3:* */
  2356. /* 3Com MAC : 00:50:DA:* */
  2357. memset(tmp, 0, sizeof(tmp));
  2358. /* Get the Symbol firmware version */
  2359. err = hermes_read_ltv(hw, USER_BAP,
  2360. HERMES_RID_SECONDARYVERSION_SYMBOL,
  2361. SYMBOL_MAX_VER_LEN, NULL, &tmp);
  2362. if (err) {
  2363. printk(KERN_WARNING
  2364. "%s: Error %d reading Symbol firmware info. "
  2365. "Wildly guessing capabilities...\n",
  2366. dev->name, err);
  2367. firmver = 0;
  2368. tmp[0] = '\0';
  2369. } else {
  2370. /* The firmware revision is a string, the format is
  2371. * something like : "V2.20-01".
  2372. * Quick and dirty parsing... - Jean II
  2373. */
  2374. firmver = ((tmp[1] - '0') << 16)
  2375. | ((tmp[3] - '0') << 12)
  2376. | ((tmp[4] - '0') << 8)
  2377. | ((tmp[6] - '0') << 4)
  2378. | (tmp[7] - '0');
  2379. tmp[SYMBOL_MAX_VER_LEN] = '\0';
  2380. }
  2381. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2382. "Symbol %s", tmp);
  2383. priv->has_ibss = (firmver >= 0x20000);
  2384. priv->has_wep = (firmver >= 0x15012);
  2385. priv->has_big_wep = (firmver >= 0x20000);
  2386. priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
  2387. (firmver >= 0x29000 && firmver < 0x30000) ||
  2388. firmver >= 0x31000;
  2389. priv->has_preamble = (firmver >= 0x20000);
  2390. priv->ibss_port = 4;
  2391. /* Symbol firmware is found on various cards, but
  2392. * there has been no attempt to check firmware
  2393. * download on non-spectrum_cs based cards.
  2394. *
  2395. * Given that the Agere firmware download works
  2396. * differently, we should avoid doing a firmware
  2397. * download with the Symbol algorithm on non-spectrum
  2398. * cards.
  2399. *
  2400. * For now we can identify a spectrum_cs based card
  2401. * because it has a firmware reset function.
  2402. */
  2403. priv->do_fw_download = (priv->stop_fw != NULL);
  2404. priv->broken_disableport = (firmver == 0x25013) ||
  2405. (firmver >= 0x30000 && firmver <= 0x31000);
  2406. priv->has_hostscan = (firmver >= 0x31001) ||
  2407. (firmver >= 0x29057 && firmver < 0x30000);
  2408. /* Tested with Intel firmware : 0x20015 => Jean II */
  2409. /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
  2410. break;
  2411. case FIRMWARE_TYPE_INTERSIL:
  2412. /* D-Link, Linksys, Adtron, ZoomAir, and many others...
  2413. * Samsung, Compaq 100/200 and Proxim are slightly
  2414. * different and less well tested */
  2415. /* D-Link MAC : 00:40:05:* */
  2416. /* Addtron MAC : 00:90:D1:* */
  2417. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  2418. "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
  2419. sta_id.variant);
  2420. firmver = ((unsigned long)sta_id.major << 16) |
  2421. ((unsigned long)sta_id.minor << 8) | sta_id.variant;
  2422. priv->has_ibss = (firmver >= 0x000700); /* FIXME */
  2423. priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
  2424. priv->has_pm = (firmver >= 0x000700);
  2425. priv->has_hostscan = (firmver >= 0x010301);
  2426. if (firmver >= 0x000800)
  2427. priv->ibss_port = 0;
  2428. else {
  2429. printk(KERN_NOTICE "%s: Intersil firmware earlier "
  2430. "than v0.8.x - several features not supported\n",
  2431. dev->name);
  2432. priv->ibss_port = 1;
  2433. }
  2434. break;
  2435. }
  2436. printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
  2437. priv->fw_name);
  2438. return 0;
  2439. }
  2440. static int orinoco_init(struct net_device *dev)
  2441. {
  2442. struct orinoco_private *priv = netdev_priv(dev);
  2443. hermes_t *hw = &priv->hw;
  2444. int err = 0;
  2445. struct hermes_idstring nickbuf;
  2446. u16 reclen;
  2447. int len;
  2448. /* No need to lock, the hw_unavailable flag is already set in
  2449. * alloc_orinocodev() */
  2450. priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
  2451. /* Initialize the firmware */
  2452. err = hermes_init(hw);
  2453. if (err != 0) {
  2454. printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
  2455. dev->name, err);
  2456. goto out;
  2457. }
  2458. err = determine_firmware(dev);
  2459. if (err != 0) {
  2460. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2461. dev->name);
  2462. goto out;
  2463. }
  2464. if (priv->do_fw_download) {
  2465. #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
  2466. orinoco_cache_fw(priv, 0);
  2467. #endif
  2468. err = orinoco_download(priv);
  2469. if (err)
  2470. priv->do_fw_download = 0;
  2471. /* Check firmware version again */
  2472. err = determine_firmware(dev);
  2473. if (err != 0) {
  2474. printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
  2475. dev->name);
  2476. goto out;
  2477. }
  2478. }
  2479. if (priv->has_port3)
  2480. printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n",
  2481. dev->name);
  2482. if (priv->has_ibss)
  2483. printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
  2484. dev->name);
  2485. if (priv->has_wep) {
  2486. printk(KERN_DEBUG "%s: WEP supported, %s-bit key\n", dev->name,
  2487. priv->has_big_wep ? "104" : "40");
  2488. }
  2489. if (priv->has_wpa) {
  2490. printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
  2491. if (orinoco_mic_init(priv)) {
  2492. printk(KERN_ERR "%s: Failed to setup MIC crypto "
  2493. "algorithm. Disabling WPA support\n", dev->name);
  2494. priv->has_wpa = 0;
  2495. }
  2496. }
  2497. /* Now we have the firmware capabilities, allocate appropiate
  2498. * sized scan buffers */
  2499. if (orinoco_bss_data_allocate(priv))
  2500. goto out;
  2501. orinoco_bss_data_init(priv);
  2502. /* Get the MAC address */
  2503. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  2504. ETH_ALEN, NULL, dev->dev_addr);
  2505. if (err) {
  2506. printk(KERN_WARNING "%s: failed to read MAC address!\n",
  2507. dev->name);
  2508. goto out;
  2509. }
  2510. printk(KERN_DEBUG "%s: MAC address %pM\n",
  2511. dev->name, dev->dev_addr);
  2512. /* Get the station name */
  2513. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  2514. sizeof(nickbuf), &reclen, &nickbuf);
  2515. if (err) {
  2516. printk(KERN_ERR "%s: failed to read station name\n",
  2517. dev->name);
  2518. goto out;
  2519. }
  2520. if (nickbuf.len)
  2521. len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
  2522. else
  2523. len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
  2524. memcpy(priv->nick, &nickbuf.val, len);
  2525. priv->nick[len] = '\0';
  2526. printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
  2527. err = orinoco_allocate_fid(dev);
  2528. if (err) {
  2529. printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
  2530. dev->name);
  2531. goto out;
  2532. }
  2533. /* Get allowed channels */
  2534. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
  2535. &priv->channel_mask);
  2536. if (err) {
  2537. printk(KERN_ERR "%s: failed to read channel list!\n",
  2538. dev->name);
  2539. goto out;
  2540. }
  2541. /* Get initial AP density */
  2542. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
  2543. &priv->ap_density);
  2544. if (err || priv->ap_density < 1 || priv->ap_density > 3)
  2545. priv->has_sensitivity = 0;
  2546. /* Get initial RTS threshold */
  2547. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  2548. &priv->rts_thresh);
  2549. if (err) {
  2550. printk(KERN_ERR "%s: failed to read RTS threshold!\n",
  2551. dev->name);
  2552. goto out;
  2553. }
  2554. /* Get initial fragmentation settings */
  2555. if (priv->has_mwo)
  2556. err = hermes_read_wordrec(hw, USER_BAP,
  2557. HERMES_RID_CNFMWOROBUST_AGERE,
  2558. &priv->mwo_robust);
  2559. else
  2560. err = hermes_read_wordrec(hw, USER_BAP,
  2561. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  2562. &priv->frag_thresh);
  2563. if (err) {
  2564. printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
  2565. dev->name);
  2566. goto out;
  2567. }
  2568. /* Power management setup */
  2569. if (priv->has_pm) {
  2570. priv->pm_on = 0;
  2571. priv->pm_mcast = 1;
  2572. err = hermes_read_wordrec(hw, USER_BAP,
  2573. HERMES_RID_CNFMAXSLEEPDURATION,
  2574. &priv->pm_period);
  2575. if (err) {
  2576. printk(KERN_ERR "%s: failed to read power management period!\n",
  2577. dev->name);
  2578. goto out;
  2579. }
  2580. err = hermes_read_wordrec(hw, USER_BAP,
  2581. HERMES_RID_CNFPMHOLDOVERDURATION,
  2582. &priv->pm_timeout);
  2583. if (err) {
  2584. printk(KERN_ERR "%s: failed to read power management timeout!\n",
  2585. dev->name);
  2586. goto out;
  2587. }
  2588. }
  2589. /* Preamble setup */
  2590. if (priv->has_preamble) {
  2591. err = hermes_read_wordrec(hw, USER_BAP,
  2592. HERMES_RID_CNFPREAMBLE_SYMBOL,
  2593. &priv->preamble);
  2594. if (err)
  2595. goto out;
  2596. }
  2597. /* Set up the default configuration */
  2598. priv->iw_mode = IW_MODE_INFRA;
  2599. /* By default use IEEE/IBSS ad-hoc mode if we have it */
  2600. priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
  2601. set_port_type(priv);
  2602. priv->channel = 0; /* use firmware default */
  2603. priv->promiscuous = 0;
  2604. priv->encode_alg = IW_ENCODE_ALG_NONE;
  2605. priv->tx_key = 0;
  2606. priv->wpa_enabled = 0;
  2607. priv->tkip_cm_active = 0;
  2608. priv->key_mgmt = 0;
  2609. priv->wpa_ie_len = 0;
  2610. priv->wpa_ie = NULL;
  2611. /* Make the hardware available, as long as it hasn't been
  2612. * removed elsewhere (e.g. by PCMCIA hot unplug) */
  2613. spin_lock_irq(&priv->lock);
  2614. priv->hw_unavailable--;
  2615. spin_unlock_irq(&priv->lock);
  2616. printk(KERN_DEBUG "%s: ready\n", dev->name);
  2617. out:
  2618. return err;
  2619. }
  2620. static const struct net_device_ops orinoco_netdev_ops = {
  2621. .ndo_init = orinoco_init,
  2622. .ndo_open = orinoco_open,
  2623. .ndo_stop = orinoco_stop,
  2624. .ndo_start_xmit = orinoco_xmit,
  2625. .ndo_set_multicast_list = orinoco_set_multicast_list,
  2626. .ndo_change_mtu = orinoco_change_mtu,
  2627. .ndo_tx_timeout = orinoco_tx_timeout,
  2628. .ndo_get_stats = orinoco_get_stats,
  2629. };
  2630. struct net_device
  2631. *alloc_orinocodev(int sizeof_card,
  2632. struct device *device,
  2633. int (*hard_reset)(struct orinoco_private *),
  2634. int (*stop_fw)(struct orinoco_private *, int))
  2635. {
  2636. struct net_device *dev;
  2637. struct orinoco_private *priv;
  2638. dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
  2639. if (!dev)
  2640. return NULL;
  2641. priv = netdev_priv(dev);
  2642. priv->ndev = dev;
  2643. if (sizeof_card)
  2644. priv->card = (void *)((unsigned long)priv
  2645. + sizeof(struct orinoco_private));
  2646. else
  2647. priv->card = NULL;
  2648. priv->dev = device;
  2649. /* Setup / override net_device fields */
  2650. dev->netdev_ops = &orinoco_netdev_ops;
  2651. dev->watchdog_timeo = HZ; /* 1 second timeout */
  2652. dev->ethtool_ops = &orinoco_ethtool_ops;
  2653. dev->wireless_handlers = &orinoco_handler_def;
  2654. #ifdef WIRELESS_SPY
  2655. priv->wireless_data.spy_data = &priv->spy_data;
  2656. dev->wireless_data = &priv->wireless_data;
  2657. #endif
  2658. /* we use the default eth_mac_addr for setting the MAC addr */
  2659. /* Reserve space in skb for the SNAP header */
  2660. dev->hard_header_len += ENCAPS_OVERHEAD;
  2661. /* Set up default callbacks */
  2662. priv->hard_reset = hard_reset;
  2663. priv->stop_fw = stop_fw;
  2664. spin_lock_init(&priv->lock);
  2665. priv->open = 0;
  2666. priv->hw_unavailable = 1; /* orinoco_init() must clear this
  2667. * before anything else touches the
  2668. * hardware */
  2669. INIT_WORK(&priv->reset_work, orinoco_reset);
  2670. INIT_WORK(&priv->join_work, orinoco_join_ap);
  2671. INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
  2672. INIT_LIST_HEAD(&priv->rx_list);
  2673. tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
  2674. (unsigned long) dev);
  2675. netif_carrier_off(dev);
  2676. priv->last_linkstatus = 0xffff;
  2677. priv->cached_pri_fw = NULL;
  2678. priv->cached_fw = NULL;
  2679. /* Register PM notifiers */
  2680. priv->pm_notifier.notifier_call = orinoco_pm_notifier;
  2681. register_pm_notifier(&priv->pm_notifier);
  2682. return dev;
  2683. }
  2684. EXPORT_SYMBOL(alloc_orinocodev);
  2685. void free_orinocodev(struct net_device *dev)
  2686. {
  2687. struct orinoco_private *priv = netdev_priv(dev);
  2688. struct orinoco_rx_data *rx_data, *temp;
  2689. /* If the tasklet is scheduled when we call tasklet_kill it
  2690. * will run one final time. However the tasklet will only
  2691. * drain priv->rx_list if the hw is still available. */
  2692. tasklet_kill(&priv->rx_tasklet);
  2693. /* Explicitly drain priv->rx_list */
  2694. list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
  2695. list_del(&rx_data->list);
  2696. dev_kfree_skb(rx_data->skb);
  2697. kfree(rx_data->desc);
  2698. kfree(rx_data);
  2699. }
  2700. unregister_pm_notifier(&priv->pm_notifier);
  2701. orinoco_uncache_fw(priv);
  2702. priv->wpa_ie_len = 0;
  2703. kfree(priv->wpa_ie);
  2704. orinoco_mic_free(priv);
  2705. orinoco_bss_data_free(priv);
  2706. free_netdev(dev);
  2707. }
  2708. EXPORT_SYMBOL(free_orinocodev);
  2709. /********************************************************************/
  2710. /* Wireless extensions */
  2711. /********************************************************************/
  2712. /* Return : < 0 -> error code ; >= 0 -> length */
  2713. static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
  2714. char buf[IW_ESSID_MAX_SIZE+1])
  2715. {
  2716. hermes_t *hw = &priv->hw;
  2717. int err = 0;
  2718. struct hermes_idstring essidbuf;
  2719. char *p = (char *)(&essidbuf.val);
  2720. int len;
  2721. unsigned long flags;
  2722. if (orinoco_lock(priv, &flags) != 0)
  2723. return -EBUSY;
  2724. if (strlen(priv->desired_essid) > 0) {
  2725. /* We read the desired SSID from the hardware rather
  2726. than from priv->desired_essid, just in case the
  2727. firmware is allowed to change it on us. I'm not
  2728. sure about this */
  2729. /* My guess is that the OWNSSID should always be whatever
  2730. * we set to the card, whereas CURRENT_SSID is the one that
  2731. * may change... - Jean II */
  2732. u16 rid;
  2733. *active = 1;
  2734. rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
  2735. HERMES_RID_CNFDESIREDSSID;
  2736. err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
  2737. NULL, &essidbuf);
  2738. if (err)
  2739. goto fail_unlock;
  2740. } else {
  2741. *active = 0;
  2742. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
  2743. sizeof(essidbuf), NULL, &essidbuf);
  2744. if (err)
  2745. goto fail_unlock;
  2746. }
  2747. len = le16_to_cpu(essidbuf.len);
  2748. BUG_ON(len > IW_ESSID_MAX_SIZE);
  2749. memset(buf, 0, IW_ESSID_MAX_SIZE);
  2750. memcpy(buf, p, len);
  2751. err = len;
  2752. fail_unlock:
  2753. orinoco_unlock(priv, &flags);
  2754. return err;
  2755. }
  2756. static int orinoco_hw_get_freq(struct orinoco_private *priv)
  2757. {
  2758. hermes_t *hw = &priv->hw;
  2759. int err = 0;
  2760. u16 channel;
  2761. int freq = 0;
  2762. unsigned long flags;
  2763. if (orinoco_lock(priv, &flags) != 0)
  2764. return -EBUSY;
  2765. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL,
  2766. &channel);
  2767. if (err)
  2768. goto out;
  2769. /* Intersil firmware 1.3.5 returns 0 when the interface is down */
  2770. if (channel == 0) {
  2771. err = -EBUSY;
  2772. goto out;
  2773. }
  2774. if ((channel < 1) || (channel > NUM_CHANNELS)) {
  2775. printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
  2776. priv->ndev->name, channel);
  2777. err = -EBUSY;
  2778. goto out;
  2779. }
  2780. freq = ieee80211_dsss_chan_to_freq(channel);
  2781. out:
  2782. orinoco_unlock(priv, &flags);
  2783. if (err > 0)
  2784. err = -EBUSY;
  2785. return err ? err : freq;
  2786. }
  2787. static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
  2788. int *numrates, s32 *rates, int max)
  2789. {
  2790. hermes_t *hw = &priv->hw;
  2791. struct hermes_idstring list;
  2792. unsigned char *p = (unsigned char *)&list.val;
  2793. int err = 0;
  2794. int num;
  2795. int i;
  2796. unsigned long flags;
  2797. if (orinoco_lock(priv, &flags) != 0)
  2798. return -EBUSY;
  2799. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
  2800. sizeof(list), NULL, &list);
  2801. orinoco_unlock(priv, &flags);
  2802. if (err)
  2803. return err;
  2804. num = le16_to_cpu(list.len);
  2805. *numrates = num;
  2806. num = min(num, max);
  2807. for (i = 0; i < num; i++)
  2808. rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
  2809. return 0;
  2810. }
  2811. static int orinoco_ioctl_getname(struct net_device *dev,
  2812. struct iw_request_info *info,
  2813. char *name,
  2814. char *extra)
  2815. {
  2816. struct orinoco_private *priv = netdev_priv(dev);
  2817. int numrates;
  2818. int err;
  2819. err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
  2820. if (!err && (numrates > 2))
  2821. strcpy(name, "IEEE 802.11b");
  2822. else
  2823. strcpy(name, "IEEE 802.11-DS");
  2824. return 0;
  2825. }
  2826. static int orinoco_ioctl_setwap(struct net_device *dev,
  2827. struct iw_request_info *info,
  2828. struct sockaddr *ap_addr,
  2829. char *extra)
  2830. {
  2831. struct orinoco_private *priv = netdev_priv(dev);
  2832. int err = -EINPROGRESS; /* Call commit handler */
  2833. unsigned long flags;
  2834. static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2835. static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  2836. if (orinoco_lock(priv, &flags) != 0)
  2837. return -EBUSY;
  2838. /* Enable automatic roaming - no sanity checks are needed */
  2839. if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
  2840. memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
  2841. priv->bssid_fixed = 0;
  2842. memset(priv->desired_bssid, 0, ETH_ALEN);
  2843. /* "off" means keep existing connection */
  2844. if (ap_addr->sa_data[0] == 0) {
  2845. __orinoco_hw_set_wap(priv);
  2846. err = 0;
  2847. }
  2848. goto out;
  2849. }
  2850. if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
  2851. printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
  2852. "support manual roaming\n",
  2853. dev->name);
  2854. err = -EOPNOTSUPP;
  2855. goto out;
  2856. }
  2857. if (priv->iw_mode != IW_MODE_INFRA) {
  2858. printk(KERN_WARNING "%s: Manual roaming supported only in "
  2859. "managed mode\n", dev->name);
  2860. err = -EOPNOTSUPP;
  2861. goto out;
  2862. }
  2863. /* Intersil firmware hangs without Desired ESSID */
  2864. if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
  2865. strlen(priv->desired_essid) == 0) {
  2866. printk(KERN_WARNING "%s: Desired ESSID must be set for "
  2867. "manual roaming\n", dev->name);
  2868. err = -EOPNOTSUPP;
  2869. goto out;
  2870. }
  2871. /* Finally, enable manual roaming */
  2872. priv->bssid_fixed = 1;
  2873. memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
  2874. out:
  2875. orinoco_unlock(priv, &flags);
  2876. return err;
  2877. }
  2878. static int orinoco_ioctl_getwap(struct net_device *dev,
  2879. struct iw_request_info *info,
  2880. struct sockaddr *ap_addr,
  2881. char *extra)
  2882. {
  2883. struct orinoco_private *priv = netdev_priv(dev);
  2884. hermes_t *hw = &priv->hw;
  2885. int err = 0;
  2886. unsigned long flags;
  2887. if (orinoco_lock(priv, &flags) != 0)
  2888. return -EBUSY;
  2889. ap_addr->sa_family = ARPHRD_ETHER;
  2890. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  2891. ETH_ALEN, NULL, ap_addr->sa_data);
  2892. orinoco_unlock(priv, &flags);
  2893. return err;
  2894. }
  2895. static int orinoco_ioctl_setmode(struct net_device *dev,
  2896. struct iw_request_info *info,
  2897. u32 *mode,
  2898. char *extra)
  2899. {
  2900. struct orinoco_private *priv = netdev_priv(dev);
  2901. int err = -EINPROGRESS; /* Call commit handler */
  2902. unsigned long flags;
  2903. if (priv->iw_mode == *mode)
  2904. return 0;
  2905. if (orinoco_lock(priv, &flags) != 0)
  2906. return -EBUSY;
  2907. switch (*mode) {
  2908. case IW_MODE_ADHOC:
  2909. if (!priv->has_ibss && !priv->has_port3)
  2910. err = -EOPNOTSUPP;
  2911. break;
  2912. case IW_MODE_INFRA:
  2913. break;
  2914. case IW_MODE_MONITOR:
  2915. if (priv->broken_monitor && !force_monitor) {
  2916. printk(KERN_WARNING "%s: Monitor mode support is "
  2917. "buggy in this firmware, not enabling\n",
  2918. dev->name);
  2919. err = -EOPNOTSUPP;
  2920. }
  2921. break;
  2922. default:
  2923. err = -EOPNOTSUPP;
  2924. break;
  2925. }
  2926. if (err == -EINPROGRESS) {
  2927. priv->iw_mode = *mode;
  2928. set_port_type(priv);
  2929. }
  2930. orinoco_unlock(priv, &flags);
  2931. return err;
  2932. }
  2933. static int orinoco_ioctl_getmode(struct net_device *dev,
  2934. struct iw_request_info *info,
  2935. u32 *mode,
  2936. char *extra)
  2937. {
  2938. struct orinoco_private *priv = netdev_priv(dev);
  2939. *mode = priv->iw_mode;
  2940. return 0;
  2941. }
  2942. static int orinoco_ioctl_getiwrange(struct net_device *dev,
  2943. struct iw_request_info *info,
  2944. struct iw_point *rrq,
  2945. char *extra)
  2946. {
  2947. struct orinoco_private *priv = netdev_priv(dev);
  2948. int err = 0;
  2949. struct iw_range *range = (struct iw_range *) extra;
  2950. int numrates;
  2951. int i, k;
  2952. rrq->length = sizeof(struct iw_range);
  2953. memset(range, 0, sizeof(struct iw_range));
  2954. range->we_version_compiled = WIRELESS_EXT;
  2955. range->we_version_source = 22;
  2956. /* Set available channels/frequencies */
  2957. range->num_channels = NUM_CHANNELS;
  2958. k = 0;
  2959. for (i = 0; i < NUM_CHANNELS; i++) {
  2960. if (priv->channel_mask & (1 << i)) {
  2961. range->freq[k].i = i + 1;
  2962. range->freq[k].m = (ieee80211_dsss_chan_to_freq(i + 1) *
  2963. 100000);
  2964. range->freq[k].e = 1;
  2965. k++;
  2966. }
  2967. if (k >= IW_MAX_FREQUENCIES)
  2968. break;
  2969. }
  2970. range->num_frequency = k;
  2971. range->sensitivity = 3;
  2972. if (priv->has_wep) {
  2973. range->max_encoding_tokens = ORINOCO_MAX_KEYS;
  2974. range->encoding_size[0] = SMALL_KEY_SIZE;
  2975. range->num_encoding_sizes = 1;
  2976. if (priv->has_big_wep) {
  2977. range->encoding_size[1] = LARGE_KEY_SIZE;
  2978. range->num_encoding_sizes = 2;
  2979. }
  2980. }
  2981. if (priv->has_wpa)
  2982. range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
  2983. if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))) {
  2984. /* Quality stats meaningless in ad-hoc mode */
  2985. } else {
  2986. range->max_qual.qual = 0x8b - 0x2f;
  2987. range->max_qual.level = 0x2f - 0x95 - 1;
  2988. range->max_qual.noise = 0x2f - 0x95 - 1;
  2989. /* Need to get better values */
  2990. range->avg_qual.qual = 0x24;
  2991. range->avg_qual.level = 0xC2;
  2992. range->avg_qual.noise = 0x9E;
  2993. }
  2994. err = orinoco_hw_get_bitratelist(priv, &numrates,
  2995. range->bitrate, IW_MAX_BITRATES);
  2996. if (err)
  2997. return err;
  2998. range->num_bitrates = numrates;
  2999. /* Set an indication of the max TCP throughput in bit/s that we can
  3000. * expect using this interface. May be use for QoS stuff...
  3001. * Jean II */
  3002. if (numrates > 2)
  3003. range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
  3004. else
  3005. range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
  3006. range->min_rts = 0;
  3007. range->max_rts = 2347;
  3008. range->min_frag = 256;
  3009. range->max_frag = 2346;
  3010. range->min_pmp = 0;
  3011. range->max_pmp = 65535000;
  3012. range->min_pmt = 0;
  3013. range->max_pmt = 65535 * 1000; /* ??? */
  3014. range->pmp_flags = IW_POWER_PERIOD;
  3015. range->pmt_flags = IW_POWER_TIMEOUT;
  3016. range->pm_capa = (IW_POWER_PERIOD | IW_POWER_TIMEOUT |
  3017. IW_POWER_UNICAST_R);
  3018. range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  3019. range->retry_flags = IW_RETRY_LIMIT;
  3020. range->r_time_flags = IW_RETRY_LIFETIME;
  3021. range->min_retry = 0;
  3022. range->max_retry = 65535; /* ??? */
  3023. range->min_r_time = 0;
  3024. range->max_r_time = 65535 * 1000; /* ??? */
  3025. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  3026. range->scan_capa = IW_SCAN_CAPA_ESSID;
  3027. else
  3028. range->scan_capa = IW_SCAN_CAPA_NONE;
  3029. /* Event capability (kernel) */
  3030. IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
  3031. /* Event capability (driver) */
  3032. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
  3033. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
  3034. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
  3035. IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
  3036. return 0;
  3037. }
  3038. static int orinoco_ioctl_setiwencode(struct net_device *dev,
  3039. struct iw_request_info *info,
  3040. struct iw_point *erq,
  3041. char *keybuf)
  3042. {
  3043. struct orinoco_private *priv = netdev_priv(dev);
  3044. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  3045. int setindex = priv->tx_key;
  3046. int encode_alg = priv->encode_alg;
  3047. int restricted = priv->wep_restrict;
  3048. u16 xlen = 0;
  3049. int err = -EINPROGRESS; /* Call commit handler */
  3050. unsigned long flags;
  3051. if (!priv->has_wep)
  3052. return -EOPNOTSUPP;
  3053. if (erq->pointer) {
  3054. /* We actually have a key to set - check its length */
  3055. if (erq->length > LARGE_KEY_SIZE)
  3056. return -E2BIG;
  3057. if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep)
  3058. return -E2BIG;
  3059. }
  3060. if (orinoco_lock(priv, &flags) != 0)
  3061. return -EBUSY;
  3062. /* Clear any TKIP key we have */
  3063. if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
  3064. (void) orinoco_clear_tkip_key(priv, setindex);
  3065. if (erq->length > 0) {
  3066. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  3067. index = priv->tx_key;
  3068. /* Adjust key length to a supported value */
  3069. if (erq->length > SMALL_KEY_SIZE)
  3070. xlen = LARGE_KEY_SIZE;
  3071. else if (erq->length > 0)
  3072. xlen = SMALL_KEY_SIZE;
  3073. else
  3074. xlen = 0;
  3075. /* Switch on WEP if off */
  3076. if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
  3077. setindex = index;
  3078. encode_alg = IW_ENCODE_ALG_WEP;
  3079. }
  3080. } else {
  3081. /* Important note : if the user do "iwconfig eth0 enc off",
  3082. * we will arrive there with an index of -1. This is valid
  3083. * but need to be taken care off... Jean II */
  3084. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  3085. if ((index != -1) || (erq->flags == 0)) {
  3086. err = -EINVAL;
  3087. goto out;
  3088. }
  3089. } else {
  3090. /* Set the index : Check that the key is valid */
  3091. if (priv->keys[index].len == 0) {
  3092. err = -EINVAL;
  3093. goto out;
  3094. }
  3095. setindex = index;
  3096. }
  3097. }
  3098. if (erq->flags & IW_ENCODE_DISABLED)
  3099. encode_alg = IW_ENCODE_ALG_NONE;
  3100. if (erq->flags & IW_ENCODE_OPEN)
  3101. restricted = 0;
  3102. if (erq->flags & IW_ENCODE_RESTRICTED)
  3103. restricted = 1;
  3104. if (erq->pointer && erq->length > 0) {
  3105. priv->keys[index].len = cpu_to_le16(xlen);
  3106. memset(priv->keys[index].data, 0,
  3107. sizeof(priv->keys[index].data));
  3108. memcpy(priv->keys[index].data, keybuf, erq->length);
  3109. }
  3110. priv->tx_key = setindex;
  3111. /* Try fast key change if connected and only keys are changed */
  3112. if ((priv->encode_alg == encode_alg) &&
  3113. (priv->wep_restrict == restricted) &&
  3114. netif_carrier_ok(dev)) {
  3115. err = __orinoco_hw_setup_wepkeys(priv);
  3116. /* No need to commit if successful */
  3117. goto out;
  3118. }
  3119. priv->encode_alg = encode_alg;
  3120. priv->wep_restrict = restricted;
  3121. out:
  3122. orinoco_unlock(priv, &flags);
  3123. return err;
  3124. }
  3125. static int orinoco_ioctl_getiwencode(struct net_device *dev,
  3126. struct iw_request_info *info,
  3127. struct iw_point *erq,
  3128. char *keybuf)
  3129. {
  3130. struct orinoco_private *priv = netdev_priv(dev);
  3131. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  3132. u16 xlen = 0;
  3133. unsigned long flags;
  3134. if (!priv->has_wep)
  3135. return -EOPNOTSUPP;
  3136. if (orinoco_lock(priv, &flags) != 0)
  3137. return -EBUSY;
  3138. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  3139. index = priv->tx_key;
  3140. erq->flags = 0;
  3141. if (!priv->encode_alg)
  3142. erq->flags |= IW_ENCODE_DISABLED;
  3143. erq->flags |= index + 1;
  3144. if (priv->wep_restrict)
  3145. erq->flags |= IW_ENCODE_RESTRICTED;
  3146. else
  3147. erq->flags |= IW_ENCODE_OPEN;
  3148. xlen = le16_to_cpu(priv->keys[index].len);
  3149. erq->length = xlen;
  3150. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  3151. orinoco_unlock(priv, &flags);
  3152. return 0;
  3153. }
  3154. static int orinoco_ioctl_setessid(struct net_device *dev,
  3155. struct iw_request_info *info,
  3156. struct iw_point *erq,
  3157. char *essidbuf)
  3158. {
  3159. struct orinoco_private *priv = netdev_priv(dev);
  3160. unsigned long flags;
  3161. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  3162. * anyway... - Jean II */
  3163. /* Hum... Should not use Wireless Extension constant (may change),
  3164. * should use our own... - Jean II */
  3165. if (erq->length > IW_ESSID_MAX_SIZE)
  3166. return -E2BIG;
  3167. if (orinoco_lock(priv, &flags) != 0)
  3168. return -EBUSY;
  3169. /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
  3170. memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
  3171. /* If not ANY, get the new ESSID */
  3172. if (erq->flags)
  3173. memcpy(priv->desired_essid, essidbuf, erq->length);
  3174. orinoco_unlock(priv, &flags);
  3175. return -EINPROGRESS; /* Call commit handler */
  3176. }
  3177. static int orinoco_ioctl_getessid(struct net_device *dev,
  3178. struct iw_request_info *info,
  3179. struct iw_point *erq,
  3180. char *essidbuf)
  3181. {
  3182. struct orinoco_private *priv = netdev_priv(dev);
  3183. int active;
  3184. int err = 0;
  3185. unsigned long flags;
  3186. if (netif_running(dev)) {
  3187. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  3188. if (err < 0)
  3189. return err;
  3190. erq->length = err;
  3191. } else {
  3192. if (orinoco_lock(priv, &flags) != 0)
  3193. return -EBUSY;
  3194. memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
  3195. erq->length = strlen(priv->desired_essid);
  3196. orinoco_unlock(priv, &flags);
  3197. }
  3198. erq->flags = 1;
  3199. return 0;
  3200. }
  3201. static int orinoco_ioctl_setnick(struct net_device *dev,
  3202. struct iw_request_info *info,
  3203. struct iw_point *nrq,
  3204. char *nickbuf)
  3205. {
  3206. struct orinoco_private *priv = netdev_priv(dev);
  3207. unsigned long flags;
  3208. if (nrq->length > IW_ESSID_MAX_SIZE)
  3209. return -E2BIG;
  3210. if (orinoco_lock(priv, &flags) != 0)
  3211. return -EBUSY;
  3212. memset(priv->nick, 0, sizeof(priv->nick));
  3213. memcpy(priv->nick, nickbuf, nrq->length);
  3214. orinoco_unlock(priv, &flags);
  3215. return -EINPROGRESS; /* Call commit handler */
  3216. }
  3217. static int orinoco_ioctl_getnick(struct net_device *dev,
  3218. struct iw_request_info *info,
  3219. struct iw_point *nrq,
  3220. char *nickbuf)
  3221. {
  3222. struct orinoco_private *priv = netdev_priv(dev);
  3223. unsigned long flags;
  3224. if (orinoco_lock(priv, &flags) != 0)
  3225. return -EBUSY;
  3226. memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
  3227. orinoco_unlock(priv, &flags);
  3228. nrq->length = strlen(priv->nick);
  3229. return 0;
  3230. }
  3231. static int orinoco_ioctl_setfreq(struct net_device *dev,
  3232. struct iw_request_info *info,
  3233. struct iw_freq *frq,
  3234. char *extra)
  3235. {
  3236. struct orinoco_private *priv = netdev_priv(dev);
  3237. int chan = -1;
  3238. unsigned long flags;
  3239. int err = -EINPROGRESS; /* Call commit handler */
  3240. /* In infrastructure mode the AP sets the channel */
  3241. if (priv->iw_mode == IW_MODE_INFRA)
  3242. return -EBUSY;
  3243. if ((frq->e == 0) && (frq->m <= 1000)) {
  3244. /* Setting by channel number */
  3245. chan = frq->m;
  3246. } else {
  3247. /* Setting by frequency */
  3248. int denom = 1;
  3249. int i;
  3250. /* Calculate denominator to rescale to MHz */
  3251. for (i = 0; i < (6 - frq->e); i++)
  3252. denom *= 10;
  3253. chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
  3254. }
  3255. if ((chan < 1) || (chan > NUM_CHANNELS) ||
  3256. !(priv->channel_mask & (1 << (chan-1))))
  3257. return -EINVAL;
  3258. if (orinoco_lock(priv, &flags) != 0)
  3259. return -EBUSY;
  3260. priv->channel = chan;
  3261. if (priv->iw_mode == IW_MODE_MONITOR) {
  3262. /* Fast channel change - no commit if successful */
  3263. hermes_t *hw = &priv->hw;
  3264. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  3265. HERMES_TEST_SET_CHANNEL,
  3266. chan, NULL);
  3267. }
  3268. orinoco_unlock(priv, &flags);
  3269. return err;
  3270. }
  3271. static int orinoco_ioctl_getfreq(struct net_device *dev,
  3272. struct iw_request_info *info,
  3273. struct iw_freq *frq,
  3274. char *extra)
  3275. {
  3276. struct orinoco_private *priv = netdev_priv(dev);
  3277. int tmp;
  3278. /* Locking done in there */
  3279. tmp = orinoco_hw_get_freq(priv);
  3280. if (tmp < 0)
  3281. return tmp;
  3282. frq->m = tmp * 100000;
  3283. frq->e = 1;
  3284. return 0;
  3285. }
  3286. static int orinoco_ioctl_getsens(struct net_device *dev,
  3287. struct iw_request_info *info,
  3288. struct iw_param *srq,
  3289. char *extra)
  3290. {
  3291. struct orinoco_private *priv = netdev_priv(dev);
  3292. hermes_t *hw = &priv->hw;
  3293. u16 val;
  3294. int err;
  3295. unsigned long flags;
  3296. if (!priv->has_sensitivity)
  3297. return -EOPNOTSUPP;
  3298. if (orinoco_lock(priv, &flags) != 0)
  3299. return -EBUSY;
  3300. err = hermes_read_wordrec(hw, USER_BAP,
  3301. HERMES_RID_CNFSYSTEMSCALE, &val);
  3302. orinoco_unlock(priv, &flags);
  3303. if (err)
  3304. return err;
  3305. srq->value = val;
  3306. srq->fixed = 0; /* auto */
  3307. return 0;
  3308. }
  3309. static int orinoco_ioctl_setsens(struct net_device *dev,
  3310. struct iw_request_info *info,
  3311. struct iw_param *srq,
  3312. char *extra)
  3313. {
  3314. struct orinoco_private *priv = netdev_priv(dev);
  3315. int val = srq->value;
  3316. unsigned long flags;
  3317. if (!priv->has_sensitivity)
  3318. return -EOPNOTSUPP;
  3319. if ((val < 1) || (val > 3))
  3320. return -EINVAL;
  3321. if (orinoco_lock(priv, &flags) != 0)
  3322. return -EBUSY;
  3323. priv->ap_density = val;
  3324. orinoco_unlock(priv, &flags);
  3325. return -EINPROGRESS; /* Call commit handler */
  3326. }
  3327. static int orinoco_ioctl_setrts(struct net_device *dev,
  3328. struct iw_request_info *info,
  3329. struct iw_param *rrq,
  3330. char *extra)
  3331. {
  3332. struct orinoco_private *priv = netdev_priv(dev);
  3333. int val = rrq->value;
  3334. unsigned long flags;
  3335. if (rrq->disabled)
  3336. val = 2347;
  3337. if ((val < 0) || (val > 2347))
  3338. return -EINVAL;
  3339. if (orinoco_lock(priv, &flags) != 0)
  3340. return -EBUSY;
  3341. priv->rts_thresh = val;
  3342. orinoco_unlock(priv, &flags);
  3343. return -EINPROGRESS; /* Call commit handler */
  3344. }
  3345. static int orinoco_ioctl_getrts(struct net_device *dev,
  3346. struct iw_request_info *info,
  3347. struct iw_param *rrq,
  3348. char *extra)
  3349. {
  3350. struct orinoco_private *priv = netdev_priv(dev);
  3351. rrq->value = priv->rts_thresh;
  3352. rrq->disabled = (rrq->value == 2347);
  3353. rrq->fixed = 1;
  3354. return 0;
  3355. }
  3356. static int orinoco_ioctl_setfrag(struct net_device *dev,
  3357. struct iw_request_info *info,
  3358. struct iw_param *frq,
  3359. char *extra)
  3360. {
  3361. struct orinoco_private *priv = netdev_priv(dev);
  3362. int err = -EINPROGRESS; /* Call commit handler */
  3363. unsigned long flags;
  3364. if (orinoco_lock(priv, &flags) != 0)
  3365. return -EBUSY;
  3366. if (priv->has_mwo) {
  3367. if (frq->disabled)
  3368. priv->mwo_robust = 0;
  3369. else {
  3370. if (frq->fixed)
  3371. printk(KERN_WARNING "%s: Fixed fragmentation "
  3372. "is not supported on this firmware. "
  3373. "Using MWO robust instead.\n",
  3374. dev->name);
  3375. priv->mwo_robust = 1;
  3376. }
  3377. } else {
  3378. if (frq->disabled)
  3379. priv->frag_thresh = 2346;
  3380. else {
  3381. if ((frq->value < 256) || (frq->value > 2346))
  3382. err = -EINVAL;
  3383. else
  3384. /* must be even */
  3385. priv->frag_thresh = frq->value & ~0x1;
  3386. }
  3387. }
  3388. orinoco_unlock(priv, &flags);
  3389. return err;
  3390. }
  3391. static int orinoco_ioctl_getfrag(struct net_device *dev,
  3392. struct iw_request_info *info,
  3393. struct iw_param *frq,
  3394. char *extra)
  3395. {
  3396. struct orinoco_private *priv = netdev_priv(dev);
  3397. hermes_t *hw = &priv->hw;
  3398. int err;
  3399. u16 val;
  3400. unsigned long flags;
  3401. if (orinoco_lock(priv, &flags) != 0)
  3402. return -EBUSY;
  3403. if (priv->has_mwo) {
  3404. err = hermes_read_wordrec(hw, USER_BAP,
  3405. HERMES_RID_CNFMWOROBUST_AGERE,
  3406. &val);
  3407. if (err)
  3408. val = 0;
  3409. frq->value = val ? 2347 : 0;
  3410. frq->disabled = !val;
  3411. frq->fixed = 0;
  3412. } else {
  3413. err = hermes_read_wordrec(hw, USER_BAP,
  3414. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  3415. &val);
  3416. if (err)
  3417. val = 0;
  3418. frq->value = val;
  3419. frq->disabled = (val >= 2346);
  3420. frq->fixed = 1;
  3421. }
  3422. orinoco_unlock(priv, &flags);
  3423. return err;
  3424. }
  3425. static int orinoco_ioctl_setrate(struct net_device *dev,
  3426. struct iw_request_info *info,
  3427. struct iw_param *rrq,
  3428. char *extra)
  3429. {
  3430. struct orinoco_private *priv = netdev_priv(dev);
  3431. int ratemode;
  3432. int bitrate; /* 100s of kilobits */
  3433. unsigned long flags;
  3434. /* As the user space doesn't know our highest rate, it uses -1
  3435. * to ask us to set the highest rate. Test it using "iwconfig
  3436. * ethX rate auto" - Jean II */
  3437. if (rrq->value == -1)
  3438. bitrate = 110;
  3439. else {
  3440. if (rrq->value % 100000)
  3441. return -EINVAL;
  3442. bitrate = rrq->value / 100000;
  3443. }
  3444. ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed);
  3445. if (ratemode == -1)
  3446. return -EINVAL;
  3447. if (orinoco_lock(priv, &flags) != 0)
  3448. return -EBUSY;
  3449. priv->bitratemode = ratemode;
  3450. orinoco_unlock(priv, &flags);
  3451. return -EINPROGRESS;
  3452. }
  3453. static int orinoco_ioctl_getrate(struct net_device *dev,
  3454. struct iw_request_info *info,
  3455. struct iw_param *rrq,
  3456. char *extra)
  3457. {
  3458. struct orinoco_private *priv = netdev_priv(dev);
  3459. int err = 0;
  3460. int bitrate, automatic;
  3461. unsigned long flags;
  3462. if (orinoco_lock(priv, &flags) != 0)
  3463. return -EBUSY;
  3464. orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic);
  3465. /* If the interface is running we try to find more about the
  3466. current mode */
  3467. if (netif_running(dev))
  3468. err = orinoco_hw_get_act_bitrate(priv, &bitrate);
  3469. orinoco_unlock(priv, &flags);
  3470. rrq->value = bitrate;
  3471. rrq->fixed = !automatic;
  3472. rrq->disabled = 0;
  3473. return err;
  3474. }
  3475. static int orinoco_ioctl_setpower(struct net_device *dev,
  3476. struct iw_request_info *info,
  3477. struct iw_param *prq,
  3478. char *extra)
  3479. {
  3480. struct orinoco_private *priv = netdev_priv(dev);
  3481. int err = -EINPROGRESS; /* Call commit handler */
  3482. unsigned long flags;
  3483. if (orinoco_lock(priv, &flags) != 0)
  3484. return -EBUSY;
  3485. if (prq->disabled) {
  3486. priv->pm_on = 0;
  3487. } else {
  3488. switch (prq->flags & IW_POWER_MODE) {
  3489. case IW_POWER_UNICAST_R:
  3490. priv->pm_mcast = 0;
  3491. priv->pm_on = 1;
  3492. break;
  3493. case IW_POWER_ALL_R:
  3494. priv->pm_mcast = 1;
  3495. priv->pm_on = 1;
  3496. break;
  3497. case IW_POWER_ON:
  3498. /* No flags : but we may have a value - Jean II */
  3499. break;
  3500. default:
  3501. err = -EINVAL;
  3502. goto out;
  3503. }
  3504. if (prq->flags & IW_POWER_TIMEOUT) {
  3505. priv->pm_on = 1;
  3506. priv->pm_timeout = prq->value / 1000;
  3507. }
  3508. if (prq->flags & IW_POWER_PERIOD) {
  3509. priv->pm_on = 1;
  3510. priv->pm_period = prq->value / 1000;
  3511. }
  3512. /* It's valid to not have a value if we are just toggling
  3513. * the flags... Jean II */
  3514. if (!priv->pm_on) {
  3515. err = -EINVAL;
  3516. goto out;
  3517. }
  3518. }
  3519. out:
  3520. orinoco_unlock(priv, &flags);
  3521. return err;
  3522. }
  3523. static int orinoco_ioctl_getpower(struct net_device *dev,
  3524. struct iw_request_info *info,
  3525. struct iw_param *prq,
  3526. char *extra)
  3527. {
  3528. struct orinoco_private *priv = netdev_priv(dev);
  3529. hermes_t *hw = &priv->hw;
  3530. int err = 0;
  3531. u16 enable, period, timeout, mcast;
  3532. unsigned long flags;
  3533. if (orinoco_lock(priv, &flags) != 0)
  3534. return -EBUSY;
  3535. err = hermes_read_wordrec(hw, USER_BAP,
  3536. HERMES_RID_CNFPMENABLED, &enable);
  3537. if (err)
  3538. goto out;
  3539. err = hermes_read_wordrec(hw, USER_BAP,
  3540. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  3541. if (err)
  3542. goto out;
  3543. err = hermes_read_wordrec(hw, USER_BAP,
  3544. HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  3545. if (err)
  3546. goto out;
  3547. err = hermes_read_wordrec(hw, USER_BAP,
  3548. HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  3549. if (err)
  3550. goto out;
  3551. prq->disabled = !enable;
  3552. /* Note : by default, display the period */
  3553. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  3554. prq->flags = IW_POWER_TIMEOUT;
  3555. prq->value = timeout * 1000;
  3556. } else {
  3557. prq->flags = IW_POWER_PERIOD;
  3558. prq->value = period * 1000;
  3559. }
  3560. if (mcast)
  3561. prq->flags |= IW_POWER_ALL_R;
  3562. else
  3563. prq->flags |= IW_POWER_UNICAST_R;
  3564. out:
  3565. orinoco_unlock(priv, &flags);
  3566. return err;
  3567. }
  3568. static int orinoco_ioctl_set_encodeext(struct net_device *dev,
  3569. struct iw_request_info *info,
  3570. union iwreq_data *wrqu,
  3571. char *extra)
  3572. {
  3573. struct orinoco_private *priv = netdev_priv(dev);
  3574. struct iw_point *encoding = &wrqu->encoding;
  3575. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  3576. int idx, alg = ext->alg, set_key = 1;
  3577. unsigned long flags;
  3578. int err = -EINVAL;
  3579. u16 key_len;
  3580. if (orinoco_lock(priv, &flags) != 0)
  3581. return -EBUSY;
  3582. /* Determine and validate the key index */
  3583. idx = encoding->flags & IW_ENCODE_INDEX;
  3584. if (idx) {
  3585. if ((idx < 1) || (idx > 4))
  3586. goto out;
  3587. idx--;
  3588. } else
  3589. idx = priv->tx_key;
  3590. if (encoding->flags & IW_ENCODE_DISABLED)
  3591. alg = IW_ENCODE_ALG_NONE;
  3592. if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
  3593. /* Clear any TKIP TX key we had */
  3594. (void) orinoco_clear_tkip_key(priv, priv->tx_key);
  3595. }
  3596. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  3597. priv->tx_key = idx;
  3598. set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
  3599. (ext->key_len > 0)) ? 1 : 0;
  3600. }
  3601. if (set_key) {
  3602. /* Set the requested key first */
  3603. switch (alg) {
  3604. case IW_ENCODE_ALG_NONE:
  3605. priv->encode_alg = alg;
  3606. priv->keys[idx].len = 0;
  3607. break;
  3608. case IW_ENCODE_ALG_WEP:
  3609. if (ext->key_len > SMALL_KEY_SIZE)
  3610. key_len = LARGE_KEY_SIZE;
  3611. else if (ext->key_len > 0)
  3612. key_len = SMALL_KEY_SIZE;
  3613. else
  3614. goto out;
  3615. priv->encode_alg = alg;
  3616. priv->keys[idx].len = cpu_to_le16(key_len);
  3617. key_len = min(ext->key_len, key_len);
  3618. memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
  3619. memcpy(priv->keys[idx].data, ext->key, key_len);
  3620. break;
  3621. case IW_ENCODE_ALG_TKIP:
  3622. {
  3623. hermes_t *hw = &priv->hw;
  3624. u8 *tkip_iv = NULL;
  3625. if (!priv->has_wpa ||
  3626. (ext->key_len > sizeof(priv->tkip_key[0])))
  3627. goto out;
  3628. priv->encode_alg = alg;
  3629. memset(&priv->tkip_key[idx], 0,
  3630. sizeof(priv->tkip_key[idx]));
  3631. memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
  3632. if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
  3633. tkip_iv = &ext->rx_seq[0];
  3634. err = __orinoco_hw_set_tkip_key(hw, idx,
  3635. ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
  3636. (u8 *) &priv->tkip_key[idx],
  3637. tkip_iv, NULL);
  3638. if (err)
  3639. printk(KERN_ERR "%s: Error %d setting TKIP key"
  3640. "\n", dev->name, err);
  3641. goto out;
  3642. }
  3643. default:
  3644. goto out;
  3645. }
  3646. }
  3647. err = -EINPROGRESS;
  3648. out:
  3649. orinoco_unlock(priv, &flags);
  3650. return err;
  3651. }
  3652. static int orinoco_ioctl_get_encodeext(struct net_device *dev,
  3653. struct iw_request_info *info,
  3654. union iwreq_data *wrqu,
  3655. char *extra)
  3656. {
  3657. struct orinoco_private *priv = netdev_priv(dev);
  3658. struct iw_point *encoding = &wrqu->encoding;
  3659. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  3660. int idx, max_key_len;
  3661. unsigned long flags;
  3662. int err;
  3663. if (orinoco_lock(priv, &flags) != 0)
  3664. return -EBUSY;
  3665. err = -EINVAL;
  3666. max_key_len = encoding->length - sizeof(*ext);
  3667. if (max_key_len < 0)
  3668. goto out;
  3669. idx = encoding->flags & IW_ENCODE_INDEX;
  3670. if (idx) {
  3671. if ((idx < 1) || (idx > 4))
  3672. goto out;
  3673. idx--;
  3674. } else
  3675. idx = priv->tx_key;
  3676. encoding->flags = idx + 1;
  3677. memset(ext, 0, sizeof(*ext));
  3678. ext->alg = priv->encode_alg;
  3679. switch (priv->encode_alg) {
  3680. case IW_ENCODE_ALG_NONE:
  3681. ext->key_len = 0;
  3682. encoding->flags |= IW_ENCODE_DISABLED;
  3683. break;
  3684. case IW_ENCODE_ALG_WEP:
  3685. ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
  3686. max_key_len);
  3687. memcpy(ext->key, priv->keys[idx].data, ext->key_len);
  3688. encoding->flags |= IW_ENCODE_ENABLED;
  3689. break;
  3690. case IW_ENCODE_ALG_TKIP:
  3691. ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
  3692. max_key_len);
  3693. memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
  3694. encoding->flags |= IW_ENCODE_ENABLED;
  3695. break;
  3696. }
  3697. err = 0;
  3698. out:
  3699. orinoco_unlock(priv, &flags);
  3700. return err;
  3701. }
  3702. static int orinoco_ioctl_set_auth(struct net_device *dev,
  3703. struct iw_request_info *info,
  3704. union iwreq_data *wrqu, char *extra)
  3705. {
  3706. struct orinoco_private *priv = netdev_priv(dev);
  3707. hermes_t *hw = &priv->hw;
  3708. struct iw_param *param = &wrqu->param;
  3709. unsigned long flags;
  3710. int ret = -EINPROGRESS;
  3711. if (orinoco_lock(priv, &flags) != 0)
  3712. return -EBUSY;
  3713. switch (param->flags & IW_AUTH_INDEX) {
  3714. case IW_AUTH_WPA_VERSION:
  3715. case IW_AUTH_CIPHER_PAIRWISE:
  3716. case IW_AUTH_CIPHER_GROUP:
  3717. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  3718. case IW_AUTH_PRIVACY_INVOKED:
  3719. case IW_AUTH_DROP_UNENCRYPTED:
  3720. /*
  3721. * orinoco does not use these parameters
  3722. */
  3723. break;
  3724. case IW_AUTH_KEY_MGMT:
  3725. /* wl_lkm implies value 2 == PSK for Hermes I
  3726. * which ties in with WEXT
  3727. * no other hints tho :(
  3728. */
  3729. priv->key_mgmt = param->value;
  3730. break;
  3731. case IW_AUTH_TKIP_COUNTERMEASURES:
  3732. /* When countermeasures are enabled, shut down the
  3733. * card; when disabled, re-enable the card. This must
  3734. * take effect immediately.
  3735. *
  3736. * TODO: Make sure that the EAPOL message is getting
  3737. * out before card disabled
  3738. */
  3739. if (param->value) {
  3740. priv->tkip_cm_active = 1;
  3741. ret = hermes_enable_port(hw, 0);
  3742. } else {
  3743. priv->tkip_cm_active = 0;
  3744. ret = hermes_disable_port(hw, 0);
  3745. }
  3746. break;
  3747. case IW_AUTH_80211_AUTH_ALG:
  3748. if (param->value & IW_AUTH_ALG_SHARED_KEY)
  3749. priv->wep_restrict = 1;
  3750. else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
  3751. priv->wep_restrict = 0;
  3752. else
  3753. ret = -EINVAL;
  3754. break;
  3755. case IW_AUTH_WPA_ENABLED:
  3756. if (priv->has_wpa) {
  3757. priv->wpa_enabled = param->value ? 1 : 0;
  3758. } else {
  3759. if (param->value)
  3760. ret = -EOPNOTSUPP;
  3761. /* else silently accept disable of WPA */
  3762. priv->wpa_enabled = 0;
  3763. }
  3764. break;
  3765. default:
  3766. ret = -EOPNOTSUPP;
  3767. }
  3768. orinoco_unlock(priv, &flags);
  3769. return ret;
  3770. }
  3771. static int orinoco_ioctl_get_auth(struct net_device *dev,
  3772. struct iw_request_info *info,
  3773. union iwreq_data *wrqu, char *extra)
  3774. {
  3775. struct orinoco_private *priv = netdev_priv(dev);
  3776. struct iw_param *param = &wrqu->param;
  3777. unsigned long flags;
  3778. int ret = 0;
  3779. if (orinoco_lock(priv, &flags) != 0)
  3780. return -EBUSY;
  3781. switch (param->flags & IW_AUTH_INDEX) {
  3782. case IW_AUTH_KEY_MGMT:
  3783. param->value = priv->key_mgmt;
  3784. break;
  3785. case IW_AUTH_TKIP_COUNTERMEASURES:
  3786. param->value = priv->tkip_cm_active;
  3787. break;
  3788. case IW_AUTH_80211_AUTH_ALG:
  3789. if (priv->wep_restrict)
  3790. param->value = IW_AUTH_ALG_SHARED_KEY;
  3791. else
  3792. param->value = IW_AUTH_ALG_OPEN_SYSTEM;
  3793. break;
  3794. case IW_AUTH_WPA_ENABLED:
  3795. param->value = priv->wpa_enabled;
  3796. break;
  3797. default:
  3798. ret = -EOPNOTSUPP;
  3799. }
  3800. orinoco_unlock(priv, &flags);
  3801. return ret;
  3802. }
  3803. static int orinoco_ioctl_set_genie(struct net_device *dev,
  3804. struct iw_request_info *info,
  3805. union iwreq_data *wrqu, char *extra)
  3806. {
  3807. struct orinoco_private *priv = netdev_priv(dev);
  3808. u8 *buf;
  3809. unsigned long flags;
  3810. /* cut off at IEEE80211_MAX_DATA_LEN */
  3811. if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
  3812. (wrqu->data.length && (extra == NULL)))
  3813. return -EINVAL;
  3814. if (wrqu->data.length) {
  3815. buf = kmalloc(wrqu->data.length, GFP_KERNEL);
  3816. if (buf == NULL)
  3817. return -ENOMEM;
  3818. memcpy(buf, extra, wrqu->data.length);
  3819. } else
  3820. buf = NULL;
  3821. if (orinoco_lock(priv, &flags) != 0) {
  3822. kfree(buf);
  3823. return -EBUSY;
  3824. }
  3825. kfree(priv->wpa_ie);
  3826. priv->wpa_ie = buf;
  3827. priv->wpa_ie_len = wrqu->data.length;
  3828. if (priv->wpa_ie) {
  3829. /* Looks like wl_lkm wants to check the auth alg, and
  3830. * somehow pass it to the firmware.
  3831. * Instead it just calls the key mgmt rid
  3832. * - we do this in set auth.
  3833. */
  3834. }
  3835. orinoco_unlock(priv, &flags);
  3836. return 0;
  3837. }
  3838. static int orinoco_ioctl_get_genie(struct net_device *dev,
  3839. struct iw_request_info *info,
  3840. union iwreq_data *wrqu, char *extra)
  3841. {
  3842. struct orinoco_private *priv = netdev_priv(dev);
  3843. unsigned long flags;
  3844. int err = 0;
  3845. if (orinoco_lock(priv, &flags) != 0)
  3846. return -EBUSY;
  3847. if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
  3848. wrqu->data.length = 0;
  3849. goto out;
  3850. }
  3851. if (wrqu->data.length < priv->wpa_ie_len) {
  3852. err = -E2BIG;
  3853. goto out;
  3854. }
  3855. wrqu->data.length = priv->wpa_ie_len;
  3856. memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
  3857. out:
  3858. orinoco_unlock(priv, &flags);
  3859. return err;
  3860. }
  3861. static int orinoco_ioctl_set_mlme(struct net_device *dev,
  3862. struct iw_request_info *info,
  3863. union iwreq_data *wrqu, char *extra)
  3864. {
  3865. struct orinoco_private *priv = netdev_priv(dev);
  3866. hermes_t *hw = &priv->hw;
  3867. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  3868. unsigned long flags;
  3869. int ret = 0;
  3870. if (orinoco_lock(priv, &flags) != 0)
  3871. return -EBUSY;
  3872. switch (mlme->cmd) {
  3873. case IW_MLME_DEAUTH:
  3874. /* silently ignore */
  3875. break;
  3876. case IW_MLME_DISASSOC:
  3877. {
  3878. struct {
  3879. u8 addr[ETH_ALEN];
  3880. __le16 reason_code;
  3881. } __attribute__ ((packed)) buf;
  3882. memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
  3883. buf.reason_code = cpu_to_le16(mlme->reason_code);
  3884. ret = HERMES_WRITE_RECORD(hw, USER_BAP,
  3885. HERMES_RID_CNFDISASSOCIATE,
  3886. &buf);
  3887. break;
  3888. }
  3889. default:
  3890. ret = -EOPNOTSUPP;
  3891. }
  3892. orinoco_unlock(priv, &flags);
  3893. return ret;
  3894. }
  3895. static int orinoco_ioctl_getretry(struct net_device *dev,
  3896. struct iw_request_info *info,
  3897. struct iw_param *rrq,
  3898. char *extra)
  3899. {
  3900. struct orinoco_private *priv = netdev_priv(dev);
  3901. hermes_t *hw = &priv->hw;
  3902. int err = 0;
  3903. u16 short_limit, long_limit, lifetime;
  3904. unsigned long flags;
  3905. if (orinoco_lock(priv, &flags) != 0)
  3906. return -EBUSY;
  3907. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  3908. &short_limit);
  3909. if (err)
  3910. goto out;
  3911. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  3912. &long_limit);
  3913. if (err)
  3914. goto out;
  3915. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  3916. &lifetime);
  3917. if (err)
  3918. goto out;
  3919. rrq->disabled = 0; /* Can't be disabled */
  3920. /* Note : by default, display the retry number */
  3921. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  3922. rrq->flags = IW_RETRY_LIFETIME;
  3923. rrq->value = lifetime * 1000; /* ??? */
  3924. } else {
  3925. /* By default, display the min number */
  3926. if ((rrq->flags & IW_RETRY_LONG)) {
  3927. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
  3928. rrq->value = long_limit;
  3929. } else {
  3930. rrq->flags = IW_RETRY_LIMIT;
  3931. rrq->value = short_limit;
  3932. if (short_limit != long_limit)
  3933. rrq->flags |= IW_RETRY_SHORT;
  3934. }
  3935. }
  3936. out:
  3937. orinoco_unlock(priv, &flags);
  3938. return err;
  3939. }
  3940. static int orinoco_ioctl_reset(struct net_device *dev,
  3941. struct iw_request_info *info,
  3942. void *wrqu,
  3943. char *extra)
  3944. {
  3945. struct orinoco_private *priv = netdev_priv(dev);
  3946. if (!capable(CAP_NET_ADMIN))
  3947. return -EPERM;
  3948. if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
  3949. printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
  3950. /* Firmware reset */
  3951. orinoco_reset(&priv->reset_work);
  3952. } else {
  3953. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  3954. schedule_work(&priv->reset_work);
  3955. }
  3956. return 0;
  3957. }
  3958. static int orinoco_ioctl_setibssport(struct net_device *dev,
  3959. struct iw_request_info *info,
  3960. void *wrqu,
  3961. char *extra)
  3962. {
  3963. struct orinoco_private *priv = netdev_priv(dev);
  3964. int val = *((int *) extra);
  3965. unsigned long flags;
  3966. if (orinoco_lock(priv, &flags) != 0)
  3967. return -EBUSY;
  3968. priv->ibss_port = val ;
  3969. /* Actually update the mode we are using */
  3970. set_port_type(priv);
  3971. orinoco_unlock(priv, &flags);
  3972. return -EINPROGRESS; /* Call commit handler */
  3973. }
  3974. static int orinoco_ioctl_getibssport(struct net_device *dev,
  3975. struct iw_request_info *info,
  3976. void *wrqu,
  3977. char *extra)
  3978. {
  3979. struct orinoco_private *priv = netdev_priv(dev);
  3980. int *val = (int *) extra;
  3981. *val = priv->ibss_port;
  3982. return 0;
  3983. }
  3984. static int orinoco_ioctl_setport3(struct net_device *dev,
  3985. struct iw_request_info *info,
  3986. void *wrqu,
  3987. char *extra)
  3988. {
  3989. struct orinoco_private *priv = netdev_priv(dev);
  3990. int val = *((int *) extra);
  3991. int err = 0;
  3992. unsigned long flags;
  3993. if (orinoco_lock(priv, &flags) != 0)
  3994. return -EBUSY;
  3995. switch (val) {
  3996. case 0: /* Try to do IEEE ad-hoc mode */
  3997. if (!priv->has_ibss) {
  3998. err = -EINVAL;
  3999. break;
  4000. }
  4001. priv->prefer_port3 = 0;
  4002. break;
  4003. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  4004. if (!priv->has_port3) {
  4005. err = -EINVAL;
  4006. break;
  4007. }
  4008. priv->prefer_port3 = 1;
  4009. break;
  4010. default:
  4011. err = -EINVAL;
  4012. }
  4013. if (!err) {
  4014. /* Actually update the mode we are using */
  4015. set_port_type(priv);
  4016. err = -EINPROGRESS;
  4017. }
  4018. orinoco_unlock(priv, &flags);
  4019. return err;
  4020. }
  4021. static int orinoco_ioctl_getport3(struct net_device *dev,
  4022. struct iw_request_info *info,
  4023. void *wrqu,
  4024. char *extra)
  4025. {
  4026. struct orinoco_private *priv = netdev_priv(dev);
  4027. int *val = (int *) extra;
  4028. *val = priv->prefer_port3;
  4029. return 0;
  4030. }
  4031. static int orinoco_ioctl_setpreamble(struct net_device *dev,
  4032. struct iw_request_info *info,
  4033. void *wrqu,
  4034. char *extra)
  4035. {
  4036. struct orinoco_private *priv = netdev_priv(dev);
  4037. unsigned long flags;
  4038. int val;
  4039. if (!priv->has_preamble)
  4040. return -EOPNOTSUPP;
  4041. /* 802.11b has recently defined some short preamble.
  4042. * Basically, the Phy header has been reduced in size.
  4043. * This increase performance, especially at high rates
  4044. * (the preamble is transmitted at 1Mb/s), unfortunately
  4045. * this give compatibility troubles... - Jean II */
  4046. val = *((int *) extra);
  4047. if (orinoco_lock(priv, &flags) != 0)
  4048. return -EBUSY;
  4049. if (val)
  4050. priv->preamble = 1;
  4051. else
  4052. priv->preamble = 0;
  4053. orinoco_unlock(priv, &flags);
  4054. return -EINPROGRESS; /* Call commit handler */
  4055. }
  4056. static int orinoco_ioctl_getpreamble(struct net_device *dev,
  4057. struct iw_request_info *info,
  4058. void *wrqu,
  4059. char *extra)
  4060. {
  4061. struct orinoco_private *priv = netdev_priv(dev);
  4062. int *val = (int *) extra;
  4063. if (!priv->has_preamble)
  4064. return -EOPNOTSUPP;
  4065. *val = priv->preamble;
  4066. return 0;
  4067. }
  4068. /* ioctl interface to hermes_read_ltv()
  4069. * To use with iwpriv, pass the RID as the token argument, e.g.
  4070. * iwpriv get_rid [0xfc00]
  4071. * At least Wireless Tools 25 is required to use iwpriv.
  4072. * For Wireless Tools 25 and 26 append "dummy" are the end. */
  4073. static int orinoco_ioctl_getrid(struct net_device *dev,
  4074. struct iw_request_info *info,
  4075. struct iw_point *data,
  4076. char *extra)
  4077. {
  4078. struct orinoco_private *priv = netdev_priv(dev);
  4079. hermes_t *hw = &priv->hw;
  4080. int rid = data->flags;
  4081. u16 length;
  4082. int err;
  4083. unsigned long flags;
  4084. /* It's a "get" function, but we don't want users to access the
  4085. * WEP key and other raw firmware data */
  4086. if (!capable(CAP_NET_ADMIN))
  4087. return -EPERM;
  4088. if (rid < 0xfc00 || rid > 0xffff)
  4089. return -EINVAL;
  4090. if (orinoco_lock(priv, &flags) != 0)
  4091. return -EBUSY;
  4092. err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
  4093. extra);
  4094. if (err)
  4095. goto out;
  4096. data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
  4097. MAX_RID_LEN);
  4098. out:
  4099. orinoco_unlock(priv, &flags);
  4100. return err;
  4101. }
  4102. /* Trigger a scan (look for other cells in the vicinity) */
  4103. static int orinoco_ioctl_setscan(struct net_device *dev,
  4104. struct iw_request_info *info,
  4105. struct iw_point *srq,
  4106. char *extra)
  4107. {
  4108. struct orinoco_private *priv = netdev_priv(dev);
  4109. hermes_t *hw = &priv->hw;
  4110. struct iw_scan_req *si = (struct iw_scan_req *) extra;
  4111. int err = 0;
  4112. unsigned long flags;
  4113. /* Note : you may have realised that, as this is a SET operation,
  4114. * this is privileged and therefore a normal user can't
  4115. * perform scanning.
  4116. * This is not an error, while the device perform scanning,
  4117. * traffic doesn't flow, so it's a perfect DoS...
  4118. * Jean II */
  4119. if (orinoco_lock(priv, &flags) != 0)
  4120. return -EBUSY;
  4121. /* Scanning with port 0 disabled would fail */
  4122. if (!netif_running(dev)) {
  4123. err = -ENETDOWN;
  4124. goto out;
  4125. }
  4126. /* In monitor mode, the scan results are always empty.
  4127. * Probe responses are passed to the driver as received
  4128. * frames and could be processed in software. */
  4129. if (priv->iw_mode == IW_MODE_MONITOR) {
  4130. err = -EOPNOTSUPP;
  4131. goto out;
  4132. }
  4133. /* Note : because we don't lock out the irq handler, the way
  4134. * we access scan variables in priv is critical.
  4135. * o scan_inprogress : not touched by irq handler
  4136. * o scan_mode : not touched by irq handler
  4137. * Before modifying anything on those variables, please think hard !
  4138. * Jean II */
  4139. /* Save flags */
  4140. priv->scan_mode = srq->flags;
  4141. /* Always trigger scanning, even if it's in progress.
  4142. * This way, if the info frame get lost, we will recover somewhat
  4143. * gracefully - Jean II */
  4144. if (priv->has_hostscan) {
  4145. switch (priv->firmware_type) {
  4146. case FIRMWARE_TYPE_SYMBOL:
  4147. err = hermes_write_wordrec(hw, USER_BAP,
  4148. HERMES_RID_CNFHOSTSCAN_SYMBOL,
  4149. HERMES_HOSTSCAN_SYMBOL_ONCE |
  4150. HERMES_HOSTSCAN_SYMBOL_BCAST);
  4151. break;
  4152. case FIRMWARE_TYPE_INTERSIL: {
  4153. __le16 req[3];
  4154. req[0] = cpu_to_le16(0x3fff); /* All channels */
  4155. req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
  4156. req[2] = 0; /* Any ESSID */
  4157. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  4158. HERMES_RID_CNFHOSTSCAN, &req);
  4159. }
  4160. break;
  4161. case FIRMWARE_TYPE_AGERE:
  4162. if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
  4163. struct hermes_idstring idbuf;
  4164. size_t len = min(sizeof(idbuf.val),
  4165. (size_t) si->essid_len);
  4166. idbuf.len = cpu_to_le16(len);
  4167. memcpy(idbuf.val, si->essid, len);
  4168. err = hermes_write_ltv(hw, USER_BAP,
  4169. HERMES_RID_CNFSCANSSID_AGERE,
  4170. HERMES_BYTES_TO_RECLEN(len + 2),
  4171. &idbuf);
  4172. } else
  4173. err = hermes_write_wordrec(hw, USER_BAP,
  4174. HERMES_RID_CNFSCANSSID_AGERE,
  4175. 0); /* Any ESSID */
  4176. if (err)
  4177. break;
  4178. if (priv->has_ext_scan) {
  4179. /* Clear scan results at the start of
  4180. * an extended scan */
  4181. orinoco_clear_scan_results(priv,
  4182. msecs_to_jiffies(15000));
  4183. /* TODO: Is this available on older firmware?
  4184. * Can we use it to scan specific channels
  4185. * for IW_SCAN_THIS_FREQ? */
  4186. err = hermes_write_wordrec(hw, USER_BAP,
  4187. HERMES_RID_CNFSCANCHANNELS2GHZ,
  4188. 0x7FFF);
  4189. if (err)
  4190. goto out;
  4191. err = hermes_inquire(hw,
  4192. HERMES_INQ_CHANNELINFO);
  4193. } else
  4194. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  4195. break;
  4196. }
  4197. } else
  4198. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  4199. /* One more client */
  4200. if (!err)
  4201. priv->scan_inprogress = 1;
  4202. out:
  4203. orinoco_unlock(priv, &flags);
  4204. return err;
  4205. }
  4206. #define MAX_CUSTOM_LEN 64
  4207. /* Translate scan data returned from the card to a card independant
  4208. * format that the Wireless Tools will understand - Jean II */
  4209. static inline char *orinoco_translate_scan(struct net_device *dev,
  4210. struct iw_request_info *info,
  4211. char *current_ev,
  4212. char *end_buf,
  4213. union hermes_scan_info *bss,
  4214. unsigned long last_scanned)
  4215. {
  4216. struct orinoco_private *priv = netdev_priv(dev);
  4217. u16 capabilities;
  4218. u16 channel;
  4219. struct iw_event iwe; /* Temporary buffer */
  4220. char custom[MAX_CUSTOM_LEN];
  4221. memset(&iwe, 0, sizeof(iwe));
  4222. /* First entry *MUST* be the AP MAC address */
  4223. iwe.cmd = SIOCGIWAP;
  4224. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  4225. memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
  4226. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4227. &iwe, IW_EV_ADDR_LEN);
  4228. /* Other entries will be displayed in the order we give them */
  4229. /* Add the ESSID */
  4230. iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
  4231. if (iwe.u.data.length > 32)
  4232. iwe.u.data.length = 32;
  4233. iwe.cmd = SIOCGIWESSID;
  4234. iwe.u.data.flags = 1;
  4235. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4236. &iwe, bss->a.essid);
  4237. /* Add mode */
  4238. iwe.cmd = SIOCGIWMODE;
  4239. capabilities = le16_to_cpu(bss->a.capabilities);
  4240. if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  4241. if (capabilities & WLAN_CAPABILITY_ESS)
  4242. iwe.u.mode = IW_MODE_MASTER;
  4243. else
  4244. iwe.u.mode = IW_MODE_ADHOC;
  4245. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4246. &iwe, IW_EV_UINT_LEN);
  4247. }
  4248. channel = bss->s.channel;
  4249. if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
  4250. /* Add channel and frequency */
  4251. iwe.cmd = SIOCGIWFREQ;
  4252. iwe.u.freq.m = channel;
  4253. iwe.u.freq.e = 0;
  4254. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4255. &iwe, IW_EV_FREQ_LEN);
  4256. iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
  4257. iwe.u.freq.e = 1;
  4258. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4259. &iwe, IW_EV_FREQ_LEN);
  4260. }
  4261. /* Add quality statistics. level and noise in dB. No link quality */
  4262. iwe.cmd = IWEVQUAL;
  4263. iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
  4264. iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
  4265. iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
  4266. /* Wireless tools prior to 27.pre22 will show link quality
  4267. * anyway, so we provide a reasonable value. */
  4268. if (iwe.u.qual.level > iwe.u.qual.noise)
  4269. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  4270. else
  4271. iwe.u.qual.qual = 0;
  4272. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4273. &iwe, IW_EV_QUAL_LEN);
  4274. /* Add encryption capability */
  4275. iwe.cmd = SIOCGIWENCODE;
  4276. if (capabilities & WLAN_CAPABILITY_PRIVACY)
  4277. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  4278. else
  4279. iwe.u.data.flags = IW_ENCODE_DISABLED;
  4280. iwe.u.data.length = 0;
  4281. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4282. &iwe, NULL);
  4283. /* Bit rate is not available in Lucent/Agere firmwares */
  4284. if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
  4285. char *current_val = current_ev + iwe_stream_lcp_len(info);
  4286. int i;
  4287. int step;
  4288. if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
  4289. step = 2;
  4290. else
  4291. step = 1;
  4292. iwe.cmd = SIOCGIWRATE;
  4293. /* Those two flags are ignored... */
  4294. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  4295. /* Max 10 values */
  4296. for (i = 0; i < 10; i += step) {
  4297. /* NULL terminated */
  4298. if (bss->p.rates[i] == 0x0)
  4299. break;
  4300. /* Bit rate given in 500 kb/s units (+ 0x80) */
  4301. iwe.u.bitrate.value =
  4302. ((bss->p.rates[i] & 0x7f) * 500000);
  4303. current_val = iwe_stream_add_value(info, current_ev,
  4304. current_val,
  4305. end_buf, &iwe,
  4306. IW_EV_PARAM_LEN);
  4307. }
  4308. /* Check if we added any event */
  4309. if ((current_val - current_ev) > iwe_stream_lcp_len(info))
  4310. current_ev = current_val;
  4311. }
  4312. /* Beacon interval */
  4313. iwe.cmd = IWEVCUSTOM;
  4314. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4315. "bcn_int=%d",
  4316. le16_to_cpu(bss->a.beacon_interv));
  4317. if (iwe.u.data.length)
  4318. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4319. &iwe, custom);
  4320. /* Capabilites */
  4321. iwe.cmd = IWEVCUSTOM;
  4322. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4323. "capab=0x%04x",
  4324. capabilities);
  4325. if (iwe.u.data.length)
  4326. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4327. &iwe, custom);
  4328. /* Add EXTRA: Age to display seconds since last beacon/probe response
  4329. * for given network. */
  4330. iwe.cmd = IWEVCUSTOM;
  4331. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4332. " Last beacon: %dms ago",
  4333. jiffies_to_msecs(jiffies - last_scanned));
  4334. if (iwe.u.data.length)
  4335. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4336. &iwe, custom);
  4337. return current_ev;
  4338. }
  4339. static inline char *orinoco_translate_ext_scan(struct net_device *dev,
  4340. struct iw_request_info *info,
  4341. char *current_ev,
  4342. char *end_buf,
  4343. struct agere_ext_scan_info *bss,
  4344. unsigned long last_scanned)
  4345. {
  4346. u16 capabilities;
  4347. u16 channel;
  4348. struct iw_event iwe; /* Temporary buffer */
  4349. char custom[MAX_CUSTOM_LEN];
  4350. u8 *ie;
  4351. memset(&iwe, 0, sizeof(iwe));
  4352. /* First entry *MUST* be the AP MAC address */
  4353. iwe.cmd = SIOCGIWAP;
  4354. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  4355. memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
  4356. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4357. &iwe, IW_EV_ADDR_LEN);
  4358. /* Other entries will be displayed in the order we give them */
  4359. /* Add the ESSID */
  4360. ie = bss->data;
  4361. iwe.u.data.length = ie[1];
  4362. if (iwe.u.data.length) {
  4363. if (iwe.u.data.length > 32)
  4364. iwe.u.data.length = 32;
  4365. iwe.cmd = SIOCGIWESSID;
  4366. iwe.u.data.flags = 1;
  4367. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4368. &iwe, &ie[2]);
  4369. }
  4370. /* Add mode */
  4371. capabilities = le16_to_cpu(bss->capabilities);
  4372. if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  4373. iwe.cmd = SIOCGIWMODE;
  4374. if (capabilities & WLAN_CAPABILITY_ESS)
  4375. iwe.u.mode = IW_MODE_MASTER;
  4376. else
  4377. iwe.u.mode = IW_MODE_ADHOC;
  4378. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4379. &iwe, IW_EV_UINT_LEN);
  4380. }
  4381. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
  4382. channel = ie ? ie[2] : 0;
  4383. if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
  4384. /* Add channel and frequency */
  4385. iwe.cmd = SIOCGIWFREQ;
  4386. iwe.u.freq.m = channel;
  4387. iwe.u.freq.e = 0;
  4388. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4389. &iwe, IW_EV_FREQ_LEN);
  4390. iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
  4391. iwe.u.freq.e = 1;
  4392. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4393. &iwe, IW_EV_FREQ_LEN);
  4394. }
  4395. /* Add quality statistics. level and noise in dB. No link quality */
  4396. iwe.cmd = IWEVQUAL;
  4397. iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
  4398. iwe.u.qual.level = bss->level - 0x95;
  4399. iwe.u.qual.noise = bss->noise - 0x95;
  4400. /* Wireless tools prior to 27.pre22 will show link quality
  4401. * anyway, so we provide a reasonable value. */
  4402. if (iwe.u.qual.level > iwe.u.qual.noise)
  4403. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  4404. else
  4405. iwe.u.qual.qual = 0;
  4406. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  4407. &iwe, IW_EV_QUAL_LEN);
  4408. /* Add encryption capability */
  4409. iwe.cmd = SIOCGIWENCODE;
  4410. if (capabilities & WLAN_CAPABILITY_PRIVACY)
  4411. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  4412. else
  4413. iwe.u.data.flags = IW_ENCODE_DISABLED;
  4414. iwe.u.data.length = 0;
  4415. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4416. &iwe, NULL);
  4417. /* WPA IE */
  4418. ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
  4419. if (ie) {
  4420. iwe.cmd = IWEVGENIE;
  4421. iwe.u.data.length = ie[1] + 2;
  4422. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4423. &iwe, ie);
  4424. }
  4425. /* RSN IE */
  4426. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
  4427. if (ie) {
  4428. iwe.cmd = IWEVGENIE;
  4429. iwe.u.data.length = ie[1] + 2;
  4430. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4431. &iwe, ie);
  4432. }
  4433. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
  4434. if (ie) {
  4435. char *p = current_ev + iwe_stream_lcp_len(info);
  4436. int i;
  4437. iwe.cmd = SIOCGIWRATE;
  4438. /* Those two flags are ignored... */
  4439. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  4440. for (i = 2; i < (ie[1] + 2); i++) {
  4441. iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
  4442. p = iwe_stream_add_value(info, current_ev, p, end_buf,
  4443. &iwe, IW_EV_PARAM_LEN);
  4444. }
  4445. /* Check if we added any event */
  4446. if (p > (current_ev + iwe_stream_lcp_len(info)))
  4447. current_ev = p;
  4448. }
  4449. /* Timestamp */
  4450. iwe.cmd = IWEVCUSTOM;
  4451. iwe.u.data.length =
  4452. snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
  4453. (unsigned long long) le64_to_cpu(bss->timestamp));
  4454. if (iwe.u.data.length)
  4455. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4456. &iwe, custom);
  4457. /* Beacon interval */
  4458. iwe.cmd = IWEVCUSTOM;
  4459. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4460. "bcn_int=%d",
  4461. le16_to_cpu(bss->beacon_interval));
  4462. if (iwe.u.data.length)
  4463. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4464. &iwe, custom);
  4465. /* Capabilites */
  4466. iwe.cmd = IWEVCUSTOM;
  4467. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4468. "capab=0x%04x",
  4469. capabilities);
  4470. if (iwe.u.data.length)
  4471. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4472. &iwe, custom);
  4473. /* Add EXTRA: Age to display seconds since last beacon/probe response
  4474. * for given network. */
  4475. iwe.cmd = IWEVCUSTOM;
  4476. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  4477. " Last beacon: %dms ago",
  4478. jiffies_to_msecs(jiffies - last_scanned));
  4479. if (iwe.u.data.length)
  4480. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  4481. &iwe, custom);
  4482. return current_ev;
  4483. }
  4484. /* Return results of a scan */
  4485. static int orinoco_ioctl_getscan(struct net_device *dev,
  4486. struct iw_request_info *info,
  4487. struct iw_point *srq,
  4488. char *extra)
  4489. {
  4490. struct orinoco_private *priv = netdev_priv(dev);
  4491. int err = 0;
  4492. unsigned long flags;
  4493. char *current_ev = extra;
  4494. if (orinoco_lock(priv, &flags) != 0)
  4495. return -EBUSY;
  4496. if (priv->scan_inprogress) {
  4497. /* Important note : we don't want to block the caller
  4498. * until results are ready for various reasons.
  4499. * First, managing wait queues is complex and racy.
  4500. * Second, we grab some rtnetlink lock before comming
  4501. * here (in dev_ioctl()).
  4502. * Third, we generate an Wireless Event, so the
  4503. * caller can wait itself on that - Jean II */
  4504. err = -EAGAIN;
  4505. goto out;
  4506. }
  4507. if (priv->has_ext_scan) {
  4508. struct xbss_element *bss;
  4509. list_for_each_entry(bss, &priv->bss_list, list) {
  4510. /* Translate this entry to WE format */
  4511. current_ev =
  4512. orinoco_translate_ext_scan(dev, info,
  4513. current_ev,
  4514. extra + srq->length,
  4515. &bss->bss,
  4516. bss->last_scanned);
  4517. /* Check if there is space for one more entry */
  4518. if ((extra + srq->length - current_ev)
  4519. <= IW_EV_ADDR_LEN) {
  4520. /* Ask user space to try again with a
  4521. * bigger buffer */
  4522. err = -E2BIG;
  4523. goto out;
  4524. }
  4525. }
  4526. } else {
  4527. struct bss_element *bss;
  4528. list_for_each_entry(bss, &priv->bss_list, list) {
  4529. /* Translate this entry to WE format */
  4530. current_ev = orinoco_translate_scan(dev, info,
  4531. current_ev,
  4532. extra + srq->length,
  4533. &bss->bss,
  4534. bss->last_scanned);
  4535. /* Check if there is space for one more entry */
  4536. if ((extra + srq->length - current_ev)
  4537. <= IW_EV_ADDR_LEN) {
  4538. /* Ask user space to try again with a
  4539. * bigger buffer */
  4540. err = -E2BIG;
  4541. goto out;
  4542. }
  4543. }
  4544. }
  4545. srq->length = (current_ev - extra);
  4546. srq->flags = (__u16) priv->scan_mode;
  4547. out:
  4548. orinoco_unlock(priv, &flags);
  4549. return err;
  4550. }
  4551. /* Commit handler, called after set operations */
  4552. static int orinoco_ioctl_commit(struct net_device *dev,
  4553. struct iw_request_info *info,
  4554. void *wrqu,
  4555. char *extra)
  4556. {
  4557. struct orinoco_private *priv = netdev_priv(dev);
  4558. struct hermes *hw = &priv->hw;
  4559. unsigned long flags;
  4560. int err = 0;
  4561. if (!priv->open)
  4562. return 0;
  4563. if (priv->broken_disableport) {
  4564. orinoco_reset(&priv->reset_work);
  4565. return 0;
  4566. }
  4567. if (orinoco_lock(priv, &flags) != 0)
  4568. return err;
  4569. err = hermes_disable_port(hw, 0);
  4570. if (err) {
  4571. printk(KERN_WARNING "%s: Unable to disable port "
  4572. "while reconfiguring card\n", dev->name);
  4573. priv->broken_disableport = 1;
  4574. goto out;
  4575. }
  4576. err = __orinoco_program_rids(dev);
  4577. if (err) {
  4578. printk(KERN_WARNING "%s: Unable to reconfigure card\n",
  4579. dev->name);
  4580. goto out;
  4581. }
  4582. err = hermes_enable_port(hw, 0);
  4583. if (err) {
  4584. printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
  4585. dev->name);
  4586. goto out;
  4587. }
  4588. out:
  4589. if (err) {
  4590. printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
  4591. schedule_work(&priv->reset_work);
  4592. err = 0;
  4593. }
  4594. orinoco_unlock(priv, &flags);
  4595. return err;
  4596. }
  4597. static const struct iw_priv_args orinoco_privtab[] = {
  4598. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  4599. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  4600. { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4601. 0, "set_port3" },
  4602. { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4603. "get_port3" },
  4604. { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4605. 0, "set_preamble" },
  4606. { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4607. "get_preamble" },
  4608. { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4609. 0, "set_ibssport" },
  4610. { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  4611. "get_ibssport" },
  4612. { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
  4613. "get_rid" },
  4614. };
  4615. /*
  4616. * Structures to export the Wireless Handlers
  4617. */
  4618. #define STD_IW_HANDLER(id, func) \
  4619. [IW_IOCTL_IDX(id)] = (iw_handler) func
  4620. static const iw_handler orinoco_handler[] = {
  4621. STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
  4622. STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
  4623. STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
  4624. STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
  4625. STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
  4626. STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
  4627. STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
  4628. STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
  4629. STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
  4630. STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
  4631. STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
  4632. STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
  4633. STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
  4634. STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
  4635. STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
  4636. STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
  4637. STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
  4638. STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
  4639. STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
  4640. STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
  4641. STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
  4642. STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
  4643. STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
  4644. STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
  4645. STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
  4646. STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
  4647. STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
  4648. STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
  4649. STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
  4650. STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
  4651. STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
  4652. STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
  4653. STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
  4654. STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
  4655. STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
  4656. STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
  4657. STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
  4658. STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
  4659. STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
  4660. };
  4661. /*
  4662. Added typecasting since we no longer use iwreq_data -- Moustafa
  4663. */
  4664. static const iw_handler orinoco_private_handler[] = {
  4665. [0] = (iw_handler) orinoco_ioctl_reset,
  4666. [1] = (iw_handler) orinoco_ioctl_reset,
  4667. [2] = (iw_handler) orinoco_ioctl_setport3,
  4668. [3] = (iw_handler) orinoco_ioctl_getport3,
  4669. [4] = (iw_handler) orinoco_ioctl_setpreamble,
  4670. [5] = (iw_handler) orinoco_ioctl_getpreamble,
  4671. [6] = (iw_handler) orinoco_ioctl_setibssport,
  4672. [7] = (iw_handler) orinoco_ioctl_getibssport,
  4673. [9] = (iw_handler) orinoco_ioctl_getrid,
  4674. };
  4675. static const struct iw_handler_def orinoco_handler_def = {
  4676. .num_standard = ARRAY_SIZE(orinoco_handler),
  4677. .num_private = ARRAY_SIZE(orinoco_private_handler),
  4678. .num_private_args = ARRAY_SIZE(orinoco_privtab),
  4679. .standard = orinoco_handler,
  4680. .private = orinoco_private_handler,
  4681. .private_args = orinoco_privtab,
  4682. .get_wireless_stats = orinoco_get_wireless_stats,
  4683. };
  4684. static void orinoco_get_drvinfo(struct net_device *dev,
  4685. struct ethtool_drvinfo *info)
  4686. {
  4687. struct orinoco_private *priv = netdev_priv(dev);
  4688. strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
  4689. strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
  4690. strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
  4691. if (dev->dev.parent)
  4692. strncpy(info->bus_info, dev_name(dev->dev.parent),
  4693. sizeof(info->bus_info) - 1);
  4694. else
  4695. snprintf(info->bus_info, sizeof(info->bus_info) - 1,
  4696. "PCMCIA %p", priv->hw.iobase);
  4697. }
  4698. static const struct ethtool_ops orinoco_ethtool_ops = {
  4699. .get_drvinfo = orinoco_get_drvinfo,
  4700. .get_link = ethtool_op_get_link,
  4701. };
  4702. /********************************************************************/
  4703. /* Module initialization */
  4704. /********************************************************************/
  4705. /* Can't be declared "const" or the whole __initdata section will
  4706. * become const */
  4707. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  4708. " (David Gibson <hermes@gibson.dropbear.id.au>, "
  4709. "Pavel Roskin <proski@gnu.org>, et al)";
  4710. static int __init init_orinoco(void)
  4711. {
  4712. printk(KERN_DEBUG "%s\n", version);
  4713. return 0;
  4714. }
  4715. static void __exit exit_orinoco(void)
  4716. {
  4717. }
  4718. module_init(init_orinoco);
  4719. module_exit(exit_orinoco);